/************************************************************************* $Archive: /pacs/OnBoard/BDecCtrl.c $ $Revision: 1.16 $ $Date: 2010/09/29 12:44:29 $ $Author: amazy $ $Log: BDecCtrl.c,v $ Revision 1.16 2010/09/29 12:44:29 amazy v6.034 * * 10 9/29/10 2:47p Pacs1 * v6.034 * * 9 9/23/10 4:37p Pacs1 * * 8 9/22/10 6:00p Pacs1 * * 7 9/21/10 5:55p Pacs1 * * 6 9/16/10 4:30p Pacs1 * * 5 16/09/10 14:36 Amazy * - Introduced EDAC test code * - Introduced code to reset the DEC FPGA in SET_PARAM_BOTH * * 67 3/14/06 4:31p Pacs Egse * Version 6.001 * Cleaned and commented *************************************************************************/ #ifdef SIMULATOR #include "virtuosoSim.h" #else // SIMULATOR #include "v_macro.h" #include "node1.h" #include "k_struct.h" #endif #include "seq_msg.h" #include "params.h" #include "links.h" #include "error.h" #include "det.h" #include "u_res.h" #include "m_smcsin.h" #include "m_smcsco.h" //**************************************************************** // MACRO //**************************************************************** //macro to signal an error in Blue Dec Controller Task #define SetError(newError) \ {\ SetGlobalError(newError);\ LOCK_WRITE_RES_PARAMS;\ SET_BITS(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_ERROR_STATUS | K_BMASK_TASK_STATUS_ERROR_CODE, K_BMASK_TASK_STATUS_TASK_IN_ERROR + newError); \ UNLOCK_WRITE_RES_PARAMS;\ }\ //macro to signal an error in Red Dec Controller Task #define SetErrorRedDEC(newError) \ {\ SetGlobalError(newError);\ LOCK_WRITE_RES_PARAMS;\ SET_BITS(gpRedDecController->TaskStatus, K_BMASK_TASK_STATUS_ERROR_STATUS | K_BMASK_TASK_STATUS_ERROR_CODE, K_BMASK_TASK_STATUS_TASK_IN_ERROR + newError); \ UNLOCK_WRITE_RES_PARAMS;\ }\ /* MACRO : LINK_1355_WRITE *********************** AUTHOR : AMazy This is a macro that replaces the call to Link1355Write. When we use a detector simulator with simulated timing, the detector is inactive so the dec controller can not write commands on the link 1355 so the call to this macro does nothing in this case. */ #define LINK_1355_WRITE(a, b, c) \ LOCK_READ_RES_PARAMS;\ if (IS(gpBlueDecRec->TaskStatus, K_BMASK_SIMULATION_TIMING, K_BMASK_REAL_TIMING)) \ {\ UNLOCK_READ_RES_PARAMS;\ Link1355Write(a, b, c); \ gpBlueDecController->PacketCounter++; \ }\ else\ {\ UNLOCK_READ_RES_PARAMS;\ } //**************************************************************** // FUNCTION DECLARATION //**************************************************************** // task functions void InitializeBlueDecCtrl(); void BlueDecCtrl(); // commands functions BOOL CommandSwitchOnBlueDEC(CommandParameter paramNotUsed); BOOL CommandSwitchOffBlueDEC(CommandParameter paramNotUsed); BOOL CommandSwitchOnBlueSpectroArray(CommandParameter paramNotUsed); BOOL CommandSwitchOffBlueSpectroArray(CommandParameter paramNotUsed); BOOL CommandValidateScienceDataBlue(CommandParameter paramNotUsed); BOOL CommandInvalidateScienceDataBlue(CommandParameter paramNotUsed); BOOL CommandValidateScienceDataBoth(CommandParameter paramNotUsed); BOOL CommandInvalidateScienceDataBoth(CommandParameter paramNotUsed); BOOL CommandSetBlueSpectroHeaterCurrent(CommandParameter param); BOOL CommandSetBlueSpectroFlasherCurrent(CommandParameter param); BOOL CommandSwOnBlueHeater(CommandParameter paramNotUsed); BOOL CommandSwOffBlueHeater(CommandParameter paramNotUsed); BOOL CommandSwOnBlueFlasher(CommandParameter paramNotUsed); BOOL CommandSwOffBlueFlasher(CommandParameter paramNotUsed); // we need these declaration for the CommandValidateScienceDataBoth and CommandInvalidateScienceDataBoth extern BOOL CommandValidateScienceDataRed(CommandParameter paramNotUsed); extern BOOL CommandInvalidateScienceDataRed(CommandParameter paramNotUsed); //**************************************************************** // FUNCTION IMPLEMENTATION //**************************************************************** /* FUNCTION : void InitializeBlueDecCtrl() *************************************** AUTHOR : AMazy Initialize Dec Controller task. */ void InitializeBlueDecCtrl() { LOCK_WRITE_RES_PARAMS; // initialize status gpBlueDecController->TaskStatus = K_BMASK_TASK_STATUS_ALIVE | K_BMASK_TASK_STATUS_NO_ERROR_IN_TASK | K_BMASK_TASK_STATUS_LINK_NOT_CONNECTED; gpBlueDecController->PacketCounter = 0; // initialize the parameters related to the DEC gpBlueDecController->DetectorParams.ClocksPerReadout = 32; gpBlueDecController->DetectorParams.ReadoutsPerRamp = 8; gpBlueDecController->DetectorParams.ReadoutValidity = INVALID; gpBlueDecController->DetectorParams.CreCtrlReg = 0x8C; gpBlueDecController->DetectorParams.CreCtrlRegCommand = 0x8C; gpBlueDecController->TemporaryDetectorParams.ClocksPerReadout = 32; gpBlueDecController->TemporaryDetectorParams.ReadoutsPerRamp = 8; gpBlueDecController->TemporaryDetectorParams.SimulReg = 60000; gpBlueDecController->TemporaryDetectorParams.BiasRCommand = 0; gpBlueDecController->TemporaryDetectorParams.BiasDCommand = 0; gpBlueDecController->TemporaryDetectorParams.CreCtrlReg = 0x8C; gpBlueDecController->TemporaryDetectorParams.CreCtrlRegCommand = 0x8C; UNLOCK_WRITE_RES_PARAMS; // signal event to allow first write command to execute KS_EventSignal(gaEventsSmcsTransmitCompleted[CHANNEL_BLUE_DEC_ID]); } /* TASK_FUNCTION : void BlueDecCtrl() ********************************** AUTHOR : AMazy This is the function implementing the Blue Dec Controller Task. It waits for messages on a FIFO and executes the requested commands by sending 1335 packets to the Blue DEC. The FIFO messages mainly come from the Sequencer */ void BlueDecCtrl() { //declare a structure used to receive message on the fifo DecControllerFifoMessage msg; int i=0; int waitCounter = 0; InitializeBlueDecCtrl(); while(1) { // wait for a message from the sequencer KS_FIFOGetW(BLUE_DEC_FIFO, &msg); // according to the message type, execute the related action switch (msg.Type) { case MSG_DEC_CTRL_SET_HEATER_CURRENT : { SendCommandToBlueDEC(DEC_HEATER_COMMAND, gpBlueDecController->DetectorParams.HeaterCurrent); };break; case MSG_DEC_CTRL_SET_FLASHER_CURRENT : { SendCommandToBlueDEC(DEC_FLASHER_COMMAND, gpBlueDecController->DetectorParams.FlasherCurrent); };break; case MSG_DEC_CTRL_SWITCH_FLASHER_ON : { SendCommandToBlueDEC(DEC_FLASHER_COMMAND, gpBlueDecController->DetectorParams.FlasherCurrent); SET_BITS(gpBlueDecController->DetectorParams.CreCtrlReg, K_BMASK_DEC_COMMAND_FLASHER_POWER, K_BMASK_DEC_COMMAND_FLASHER_POWER_ON); SendCommandToBlueDEC(DEC_CRE_CTRL_REG, gpBlueDecController->DetectorParams.CreCtrlReg); };break; case MSG_DEC_CTRL_SWITCH_FLASHER_OFF : { SET_BITS(gpBlueDecController->DetectorParams.CreCtrlReg, K_BMASK_DEC_COMMAND_FLASHER_POWER, K_BMASK_DEC_COMMAND_FLASHER_POWER_OFF); SendCommandToBlueDEC(DEC_CRE_CTRL_REG, gpBlueDecController->DetectorParams.CreCtrlReg); };break; case MSG_DEC_CTRL_SWITCH_HEATER_ON : { SendCommandToBlueDEC(DEC_HEATER_COMMAND, gpBlueDecController->DetectorParams.HeaterCurrent); SET_BITS(gpBlueDecController->DetectorParams.CreCtrlReg, K_BMASK_DEC_COMMAND_HEATER_POWER, K_BMASK_DEC_COMMAND_HEATER_POWER_ON); SendCommandToBlueDEC(DEC_CRE_CTRL_REG, gpBlueDecController->DetectorParams.CreCtrlReg); };break; case MSG_DEC_CTRL_SWITCH_HEATER_OFF : { SET_BITS(gpBlueDecController->DetectorParams.CreCtrlReg, K_BMASK_DEC_COMMAND_HEATER_POWER, K_BMASK_DEC_COMMAND_HEATER_POWER_OFF); SendCommandToBlueDEC(DEC_CRE_CTRL_REG, gpBlueDecController->DetectorParams.CreCtrlReg); };break; case MSG_DEC_CTRL_LOAD_PARAMETERS : { // not all the bits that have been written in the CreCtrlReg parameter during the write command must be transmitted to DEC SET_BITS(gpBlueDecController->DetectorParams.CreCtrlReg, K_BMASK_DEC_COMMAND_WRITABLE_BITS, gpBlueDecController->DetectorParams.CreCtrlRegCommand); // load the parameters into the DEC board SendCommandToBlueDEC(DEC_CLOCKS_PER_READOUT, gpBlueDecController->DetectorParams.ClocksPerReadout); SendCommandToBlueDEC(DEC_READOUTS_PER_RAMP, gpBlueDecController->DetectorParams.ReadoutsPerRamp); SendCommandToBlueDEC(DEC_CRE_CTRL_REG, gpBlueDecController->DetectorParams.CreCtrlReg); SendCommandToBlueDEC(DEC_BIAS_R_COMMAND, gpBlueDecController->DetectorParams.BiasRCommand); SendCommandToBlueDEC(DEC_ZERO_BIAS_COMMAND, gpBlueDecController->DetectorParams.BiasDCommand); SendCommandToBlueDEC(DEC_SIMUL_REG, gpBlueDecController->DetectorParams.SimulReg); };break; case MSG_DEC_CTRL_SWITCH_DEC_ON : { //switch it on SET_BITS(gpMim->ControlWord, K_BMASK_MIM_BLUE_DEC_POWER_CONTROL, K_BMASK_MIM_BLUE_DEC_POWER_ON); //validate the HK related to Blue DEC (without the hk related to detector array) for (i = DMC_DECB_HEAT_C; i <= DMC_DECB_RA_CO_3; ++i) { VALIDATE_HK(i); } for (i = DMC_DECB_FLASH_C; i <= DMC_DECB_RA_CO_4; ++i) { VALIDATE_HK(i); } //validate the diagnostic hk related to Blue DEC for (i = DMC_DB_TS12CBS_3; i <= DMC_DECB_R5V_4; ++i) { VALIDATE_HK(i); } //validate the hk related to the spectro array for (i = DMC_DECB_VDDD_3; i <= DMC_DECB_IGND_3; ++i) { VALIDATE_HK(i); } for (i = DMC_DECB_VDDD_4; i <= DMC_DECB_IGND_4; ++i) { VALIDATE_HK(i); } //wait that the switch on relay is activated KS_TaskSleep(200); //change the task status LOCK_WRITE_RES_PARAMS; SET_BIT(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_DEC_CTRL_POWERED_ON); UNLOCK_WRITE_RES_PARAMS; //wait 5 seconds that the dec initialize and detect if it is powered off in the meanwhile waitCounter = 5; while (TEST_ONE_BIT(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_DEC_CTRL_POWERED_ON) && (waitCounter >= 0)) { KS_TaskSleep(1000); waitCounter--; } // if the DEC has been powered off while we were waiting, exit if (!TEST_ONE_BIT(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_DEC_CTRL_POWERED_ON)) { continue; } #ifdef SIMULATOR LOCK_WRITE_RES_PARAMS; SET_BIT(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_DEC_CTRL_POWERED_ON | K_BMASK_TASK_STATUS_LINK_CONNECTED); UNLOCK_WRITE_RES_PARAMS; #else //SIMULATOR //reset the DEC Base FPGA SET_BIT(gpFPGA->ControlRegister, K_BMASK_TIMING_MASTER_RESET); WriteFpgaRegisters(); CLEAR_BIT(gpFPGA->ControlRegister, K_BMASK_TIMING_MASTER_RESET); WriteFpgaRegisters(); //wait the FPGA initializes KS_TaskSleep(100); //re-initialize the communication StartLink(CHANNEL_BLUE_DEC, RESET_SMCS); LOCK_READ_RES_PARAMS; // wait that the DEC initializes the connection on the other side // or that a detector simulator is started (when gpBlueDecRec->TaskStatus have been modified) while (IS(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_LINK_STATUS, K_BMASK_TASK_STATUS_LINK_NOT_CONNECTED) && IS(gpBlueDecRec->TaskStatus, K_BMASK_SIMULATION, K_BMASK_REAL_TIMING + K_BMASK_REAL_READOUTS) && TEST_ONE_BIT(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_DEC_CTRL_POWERED_ON)) { UNLOCK_READ_RES_PARAMS; KS_TaskSleep(1000); LOCK_READ_RES_PARAMS; } UNLOCK_READ_RES_PARAMS; #endif //SIMULATOR };break; case MSG_DEC_CTRL_LOAD_BOTH_PARAMETERS: { DecControllerFifoMessage msg; int retryCounter = 0; BOOL communicationHasRestarted = FALSE; do { int rampDetectorCounter = 0; BOOL hasReceivedBlueDecReadout0 = FALSE; BOOL hasReceivedBlueDecReadout7 = FALSE; BOOL hasReceivedRedDecReadout0 = FALSE; BOOL hasReceivedRedDecReadout7 = FALSE; //reset the DEC FPGAs SET_BIT(gpFPGA->ControlRegister, K_BMASK_TIMING_MASTER_RESET); WriteFpgaRegisters(); CLEAR_BIT(gpFPGA->ControlRegister, K_BMASK_TIMING_MASTER_RESET); WriteFpgaRegisters(); //wait the FPGA initializes KS_TaskSleep(25); //the 1355 communication should recover by itself thanks to the autoreconnect feature //However, we want to make sure this is the case. To test that the communication has restarted, //we can check the ReadoutCounter of the blue and red DEC do { if (gpBlueDecRec->DecHk.ReadoutCounterFirst == 7) hasReceivedBlueDecReadout7 = TRUE; if (gpBlueDecRec->DecHk.ReadoutCounterFirst == 0) hasReceivedBlueDecReadout0 = TRUE; if (gpRedDecRec->DecHk.ReadoutCounterFirst == 7) hasReceivedRedDecReadout7 = TRUE; if (gpRedDecRec->DecHk.ReadoutCounterFirst == 0) hasReceivedRedDecReadout0 = TRUE; communicationHasRestarted = hasReceivedBlueDecReadout7 && hasReceivedBlueDecReadout0 && hasReceivedRedDecReadout7 && hasReceivedRedDecReadout0; KS_TaskSleep(3); rampDetectorCounter++; } while (!communicationHasRestarted && rampDetectorCounter < 50); retryCounter++; } while (!communicationHasRestarted && retryCounter <= 3); if (retryCounter >= 4) { SetError(ERR_DEC_CONTROLLER_NO_RAMP_AFTER_RESET); continue; } //We want to insure that the parameters are not sent too close to the end of a ramp. //In that case, the Blue DEC could receive its parameters on the first ramp and the red DEC //on the second ramp and they would then be de-synchronized. retryCounter = 0; while (gpBlueDecRec->DecHk.ReadoutCounterFirst < 2 && retryCounter < 50) { KS_TaskSleep(4); retryCounter++; } if (retryCounter >= 50) { SetError(ERR_DEC_CONTROLLER_NO_RAMP_AFTER_RESET); continue; } //write the parameters msg.Type = MSG_DEC_CTRL_LOAD_PARAMETERS; //send the parameters to DECs if (!IS(gpBlueDecRec->TaskStatus, K_BMASK_SIMULATION_DATA, K_BMASK_SIMULATED_READOUTS)) { KS_FIFOPut(BLUE_DEC_FIFO, &msg); } if (!IS(gpRedDecRec->TaskStatus, K_BMASK_SIMULATION_DATA, K_BMASK_SIMULATED_READOUTS)) { KS_FIFOPut(RED_DEC_FIFO, &msg); } };break; case MSG_DEC_CTRL_SWITCH_DETECTOR_ON : { //update CRE Control Register and send the new value to the DEC BASE FPGA SET_BITS(gpBlueDecController->DetectorParams.CreCtrlReg, K_BMASK_DEC_COMMAND_DETECTOR_POWER, K_BMASK_DEC_COMMAND_DETECTOR_POWER_ON); SendCommandToBlueDEC(DEC_CRE_CTRL_REG, gpBlueDecController->DetectorParams.CreCtrlReg); };break; case MSG_DEC_CTRL_SWITCH_DETECTOR_OFF : { //update CRE Control Register and send the new value to the DEC BASE FPGA SET_BITS(gpBlueDecController->DetectorParams.CreCtrlReg, K_BMASK_DEC_COMMAND_DETECTOR_POWER, K_BMASK_DEC_COMMAND_DETECTOR_POWER_OFF); SendCommandToBlueDEC(DEC_CRE_CTRL_REG, gpBlueDecController->DetectorParams.CreCtrlReg); };break; default : { SetError(ERR_DEC_CONTROLLER_UNKNOWN_FIFO_MSG); } }; } } /* CMD_FUNCTION : BOOL CommandSwitchOnBlueDEC(CommandParameter paramNotUsed) ************************************************************************* AUTHOR : Amazy USE : Power On the Blue DEC */ BOOL CommandSwitchOnBlueDEC(CommandParameter paramNotUsed) { DecControllerFifoMessage msg; msg.Type = MSG_DEC_CTRL_SWITCH_DEC_ON; // if the red CREs are on, reject the command (the master reset would switch them off brutally. That is not good) if ((IS(gpRedDecController->TaskStatus, K_BMASK_TASK_STATUS_LINK_STATUS, K_BMASK_TASK_STATUS_LINK_CONNECTED) && TEST_ONE_BIT(gpRedDecRec->DecHk.CreStatusRegFirst, 1))) { SequencerSendNack(0, COULD_NOT_EXECUTE_COMMAND); SetSequencerError(ERR_SEQUENCER_COULD_NOT_EXECUTE_COMMAND); SetError(ERR_DEC_CONTROLLER_OTHER_CRE_ON); return FALSE; } KS_FIFOPut(BLUE_DEC_FIFO, &msg); SequencerSendAck(DMC_SWON_B_DEC); return FALSE; } /* CMD_FUNCTION : BOOL CommandSwitchOffBlueDEC(CommandParameter paramNotUsed) ************************************************************************** AUTHOR : Amazy USE : Power Off the Blue DEC */ BOOL CommandSwitchOffBlueDEC(CommandParameter paramNotUsed) { int i=0; //stop the 1355 link StopLink(CHANNEL_BLUE_DEC); // cut the power off SET_BITS(gpMim->ControlWord, K_BMASK_MIM_BLUE_DEC_POWER_CONTROL, K_BMASK_MIM_BLUE_DEC_POWER_OFF); //invalidate the HK related to Blue DEC (including the hk related to detector array) for (i = DMC_DECB_VDDD_3; i <= DMC_DECB_RA_CO_4; ++i) { INVALIDATE_HK(i); } //invalidate the diagnostic hk related to Blue DEC for (i = DMC_DB_TS12CBS_3; i <= DMC_DECB_R5V_4; ++i) { INVALIDATE_HK(i); } //update the status words LOCK_WRITE_RES_PARAMS; CLEAR_BIT(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_DEC_CTRL_POWERED_ON); SET_BITS(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_LINK_STATUS, K_BMASK_TASK_STATUS_LINK_NOT_CONNECTED); UNLOCK_WRITE_RES_PARAMS; SequencerSendAck(DMC_SWOF_B_DEC); return FALSE; } /* CMD_FUNCTION : BOOL CommandSwitchOnBlueSpectroArray(CommandParameter paramNotUsed) ********************************************************************************** AUTHOR : Amazy USE : Power On the Blue Spectro array */ BOOL CommandSwitchOnBlueSpectroArray(CommandParameter paramNotUsed) { DecControllerFifoMessage msg; msg.Type = MSG_DEC_CTRL_SWITCH_DETECTOR_ON; // if the link is not connected, reject the command if (!(IS(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_LINK_STATUS, K_BMASK_TASK_STATUS_LINK_CONNECTED) && TEST_ONE_BIT(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_DEC_CTRL_POWERED_ON))) { SequencerSendNack(0, COULD_NOT_EXECUTE_COMMAND); SetSequencerError(ERR_SEQUENCER_COULD_NOT_EXECUTE_COMMAND); SetError(ERR_DEC_CONTROLLER_LINK_NOT_CONNECTED); return FALSE; } KS_FIFOPut(BLUE_DEC_FIFO, &msg); SequencerSendAck(DMC_SWON_B_SPEC); return FALSE; } /* CMD_FUNCTION : BOOL CommandSwitchOffBlueSpectroArray(CommandParameter paramNotUsed) *********************************************************************************** AUTHOR : Amazy USE : Power Off the Blue Spectro array */ BOOL CommandSwitchOffBlueSpectroArray(CommandParameter paramNotUsed) { DecControllerFifoMessage msg; msg.Type = MSG_DEC_CTRL_SWITCH_DETECTOR_OFF; // send the command only if the DEC is powered on and connected if ((IS(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_LINK_STATUS, K_BMASK_TASK_STATUS_LINK_CONNECTED) && TEST_ONE_BIT(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_DEC_CTRL_POWERED_ON))) { KS_FIFOPut(BLUE_DEC_FIFO, &msg); } //send the PACK anyway SequencerSendAck(DMC_SWOF_B_SPEC); return FALSE; } /* CMD_FUNCTION : BOOL CommandValidateScienceDataBlue(CommandParameter paramNotUsed) ********************************************************************************* AUTHOR : Amazy USE : Validates the Blue Science Data */ BOOL CommandValidateScienceDataBlue(CommandParameter paramNotUsed) { gpBolController->ReadoutValidityBlue = VALID; gpBlueDecController->DetectorParams.ReadoutValidity = VALID; SequencerSendAck(DMC_VAL_SCI_DATA_B); return TRUE; } /* CMD_FUNCTION : BOOL CommandInvalidateScienceDataBlue(CommandParameter paramNotUsed) *********************************************************************************** AUTHOR : Amazy USE : Invalidates the Blue Science Data */ BOOL CommandInvalidateScienceDataBlue(CommandParameter paramNotUsed) { gpBolController->ReadoutValidityBlue = INVALID; gpBlueDecController->DetectorParams.ReadoutValidity = INVALID; SequencerSendAck(DMC_INVAL_SCI_DATA_B); return TRUE; } /* CMD_FUNCTION : BOOL CommandSetBlueSpectroParameters(CommandParameter paramNotUsed) ********************************************************************************** AUTHOR : Amazy USE : Load the parameters of the Blue Spectrometer Detector Array in the DEC board */ BOOL CommandSetBlueSpectroParameters(CommandParameter paramNotUsed) { DecControllerFifoMessage msg; msg.Type = MSG_DEC_CTRL_LOAD_PARAMETERS; if (gpBlueDecController->TemporaryDetectorParams.ReadoutsPerRamp < 2) { SequencerSendNack(0, INVALID_PARAMETER); SetSequencerError(ERR_SEQUENCER_COULD_NOT_EXECUTE_COMMAND); return FALSE; } // if we are in simulation mode if (IS(gpBlueDecRec->TaskStatus, K_BMASK_SIMULATION_DATA, K_BMASK_SIMULATED_READOUTS)) { // copy the parameters from the temporary buffer to the final one MEMCPY(&(gpBlueDecController->DetectorParams), &(gpBlueDecController->TemporaryDetectorParams), 6); SequencerSendAck(DMC_SET_PAR_B_SPEC); return FALSE; } else { // if the link is not connected, reject the command if (!(IS(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_LINK_STATUS, K_BMASK_TASK_STATUS_LINK_CONNECTED) && TEST_ONE_BIT(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_DEC_CTRL_POWERED_ON))) { SequencerSendNack(0, COULD_NOT_EXECUTE_COMMAND); SetSequencerError(ERR_SEQUENCER_COULD_NOT_EXECUTE_COMMAND); SetError(ERR_DEC_CONTROLLER_LINK_NOT_CONNECTED); return FALSE; } // copy the parameters from the temporary buffer to the final one MEMCPY(&(gpBlueDecController->DetectorParams), &(gpBlueDecController->TemporaryDetectorParams), 6); KS_FIFOPut(BLUE_DEC_FIFO, &msg); SequencerSendAck(DMC_SET_PAR_B_SPEC); return FALSE; } } /* CMD_FUNCTION : BOOL CommandSetBothSpectroParameters(CommandParameter paramNotUsed) ********************************************************************************** AUTHOR : Amazy USE : Load the parameters of the Blue and Red Spectrometer Detector Arrays in the DEC boards */ BOOL CommandSetBothSpectroParameters(CommandParameter paramNotUsed) { DecControllerFifoMessage msg; msg.Type = MSG_DEC_CTRL_LOAD_BOTH_PARAMETERS; //check that the readout per ramp is big enough if ((gpBlueDecController->TemporaryDetectorParams.ReadoutsPerRamp < 2) || (gpRedDecController->TemporaryDetectorParams.ReadoutsPerRamp < 2)) { SequencerSendNack(0, INVALID_PARAMETER); SetSequencerError(ERR_SEQUENCER_COULD_NOT_EXECUTE_COMMAND); return FALSE; } // if one of the link is not connected, reject the command if (!IS(gpBlueDecRec->TaskStatus, K_BMASK_SIMULATION_DATA, K_BMASK_SIMULATED_READOUTS) && !TEST_ALL_BITS(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_LINK_CONNECTED | K_BMASK_TASK_STATUS_DEC_CTRL_POWERED_ON)) { SequencerSendNack(0, COULD_NOT_EXECUTE_COMMAND); SetSequencerError(ERR_SEQUENCER_COULD_NOT_EXECUTE_COMMAND); SetError(ERR_DEC_CONTROLLER_LINK_NOT_CONNECTED); return FALSE; } if (!IS(gpRedDecRec->TaskStatus, K_BMASK_SIMULATION_DATA, K_BMASK_SIMULATED_READOUTS) && !TEST_ALL_BITS(gpRedDecController->TaskStatus, K_BMASK_TASK_STATUS_LINK_CONNECTED | K_BMASK_TASK_STATUS_DEC_CTRL_POWERED_ON)) { SequencerSendNack(0, COULD_NOT_EXECUTE_COMMAND); SetSequencerError(ERR_SEQUENCER_COULD_NOT_EXECUTE_COMMAND); SetErrorRedDEC(ERR_DEC_CONTROLLER_LINK_NOT_CONNECTED); return FALSE; } // copy the parameters from the temporary buffer to the final one MEMCPY(&(gpBlueDecController->DetectorParams), &(gpBlueDecController->TemporaryDetectorParams), 6); MEMCPY(&(gpRedDecController->DetectorParams), &(gpRedDecController->TemporaryDetectorParams), 6); KS_FIFOPut(BLUE_DEC_FIFO, &msg); SequencerSendAck(DMC_SET_PAR_BOTH_SPEC); return FALSE; } /* CMD_FUNCTION : BOOL CommandValidateScienceDataBoth(CommandParameter paramNotUsed) ********************************************************************************* AUTHOR : Amazy USE : Validates the Blue Science Data */ BOOL CommandValidateScienceDataBoth(CommandParameter paramNotUsed) { gpBolController->ReadoutValidityBlue = VALID; gpBolController->ReadoutValidityRed = VALID; gpBlueDecController->DetectorParams.ReadoutValidity = VALID; gpRedDecController->DetectorParams.ReadoutValidity = VALID; SequencerSendAck(DMC_VAL_SCI_DATA_BOTH); return TRUE; } /* CMD_FUNCTION : BOOL CommandInvalidateScienceDataBoth(CommandParameter paramNotUsed) *********************************************************************************** AUTHOR : Amazy USE : Invalidates the Blue Science Data */ BOOL CommandInvalidateScienceDataBoth(CommandParameter paramNotUsed) { gpBolController->ReadoutValidityBlue = INVALID; gpBolController->ReadoutValidityRed = INVALID; gpBlueDecController->DetectorParams.ReadoutValidity = INVALID; gpRedDecController->DetectorParams.ReadoutValidity = INVALID; SequencerSendAck(DMC_INVAL_SCI_DATA_BOTH); return TRUE; } /* CMD_FUNCTION : BOOL CommandSetBlueSpectroHeaterCurrent(CommandParameter param) ****************************************************************************** AUTHOR : Amazy USE : Set the heater current of blue DEC */ BOOL CommandSetBlueSpectroHeaterCurrent(CommandParameter param) { DecControllerFifoMessage msg; msg.Type= MSG_DEC_CTRL_SET_HEATER_CURRENT; gpBlueDecController->DetectorParams.HeaterCurrent = param.Int & 0x00000FFF; // only 12bits are used // if the link is not connected, reject the command if (!(IS(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_LINK_STATUS, K_BMASK_TASK_STATUS_LINK_CONNECTED) && TEST_ONE_BIT(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_DEC_CTRL_POWERED_ON))) { SequencerSendNack(0, COULD_NOT_EXECUTE_COMMAND); SetSequencerError(ERR_SEQUENCER_COULD_NOT_EXECUTE_COMMAND); SetError(ERR_DEC_CONTROLLER_LINK_NOT_CONNECTED); return FALSE; } KS_FIFOPut(BLUE_DEC_FIFO, &msg); SequencerSendAck(DMC_SET_B_SPEC_HEAT_C); return FALSE; } /* CMD_FUNCTION : BOOL CommandSetBlueSpectroFlasherCurrent(CommandParameter param) ******************************************************************************* AUTHOR : Amazy USE : Set the flasher current of blue DEC */ BOOL CommandSetBlueSpectroFlasherCurrent(CommandParameter param) { DecControllerFifoMessage msg; msg.Type= MSG_DEC_CTRL_SET_FLASHER_CURRENT; gpBlueDecController->DetectorParams.FlasherCurrent = param.Int & 0x00000FFF; // only 12bits are used // if the link is not connected, reject the command if (!(IS(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_LINK_STATUS, K_BMASK_TASK_STATUS_LINK_CONNECTED) && TEST_ONE_BIT(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_DEC_CTRL_POWERED_ON))) { SequencerSendNack(0, COULD_NOT_EXECUTE_COMMAND); SetSequencerError(ERR_SEQUENCER_COULD_NOT_EXECUTE_COMMAND); SetError(ERR_DEC_CONTROLLER_LINK_NOT_CONNECTED); return FALSE; } KS_FIFOPut(BLUE_DEC_FIFO, &msg); SequencerSendAck(DMC_SET_B_SPEC_FLASH_C); return FALSE; } /* FUNCTION : void SendCommandToBlueDEC(int address, int value) ************************************************************ AUTHOR : AMazy USE : Sends a command to the DEC (to set the value of one register). NOTE : if you change something to this function, apply the same changes to the SendCommandToRedDEC function in "RDecCtrl.c" */ void SendCommandToBlueDEC(int address, int value) { #ifndef SIMULATOR //PROTOCOL = //1 character ( corresponding to the most significant byte of the 32 bit word ) transports the parameter address, //1 character is unused //2 characters contain the value. int buffer = 0; buffer = address << 24; buffer |= value & 0x0000FFFF; LINK_1355_WRITE(CHANNEL_BLUE_DEC, 1, &buffer); #endif //SIMULATOR } /* CMD_FUNCTION : BOOL CommandSendCommandToBlueDEC(CommandParameter param) *********************************************************************** AUTHOR : Amazy USE : This is a 'debug' command to send a word directly to the DEC BASE FPGA */ BOOL CommandSendCommandToBlueDEC(CommandParameter param) { SendCommandToBlueDEC(param.Uint >> 24, param.Uint & 0x0000FFFF); SequencerSendAck(DMC_SEND_COMMAND_TO_BLUE_DEC); return FALSE; } /* CMD_FUNCTION : BOOL CommandSwOnBlueHeater(CommandParameter paramNotUsed) ************************************************************************ AUTHOR : Amazy USE : Switches on the Heater of blue DEC */ BOOL CommandSwOnBlueHeater(CommandParameter paramNotUsed) { DecControllerFifoMessage msg; msg.Type= MSG_DEC_CTRL_SWITCH_HEATER_ON; gpBlueDecController->DetectorParams.HeaterCurrent = 0; // if the link is not connected, reject the command if (!(IS(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_LINK_STATUS, K_BMASK_TASK_STATUS_LINK_CONNECTED) && TEST_ONE_BIT(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_DEC_CTRL_POWERED_ON))) { SequencerSendNack(0, COULD_NOT_EXECUTE_COMMAND); SetSequencerError(ERR_SEQUENCER_COULD_NOT_EXECUTE_COMMAND); SetError(ERR_DEC_CONTROLLER_LINK_NOT_CONNECTED); return FALSE; } KS_FIFOPut(BLUE_DEC_FIFO, &msg); SequencerSendAck(DMC_SWON_BD_HEATER); return FALSE; } /* CMD_FUNCTION : BOOL CommandSwOffBlueHeater(CommandParameter paramNotUsed) ************************************************************************* AUTHOR : Amazy USE : Switches off the Heater of blue DEC */ BOOL CommandSwOffBlueHeater(CommandParameter paramNotUsed) { DecControllerFifoMessage msg; msg.Type= MSG_DEC_CTRL_SWITCH_HEATER_OFF; // if the link is not connected, reject the command if (!(IS(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_LINK_STATUS, K_BMASK_TASK_STATUS_LINK_CONNECTED) && TEST_ONE_BIT(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_DEC_CTRL_POWERED_ON))) { SequencerSendNack(0, COULD_NOT_EXECUTE_COMMAND); SetSequencerError(ERR_SEQUENCER_COULD_NOT_EXECUTE_COMMAND); SetError(ERR_DEC_CONTROLLER_LINK_NOT_CONNECTED); return FALSE; } KS_FIFOPut(BLUE_DEC_FIFO, &msg); SequencerSendAck(DMC_SWOF_BD_HEATER); return FALSE; } /* CMD_FUNCTION : BOOL CommandSwOnBlueFlasher(CommandParameter paramNotUsed) ************************************************************************* AUTHOR : Amazy USE : Switches on the Flasher of blue DEC */ BOOL CommandSwOnBlueFlasher(CommandParameter paramNotUsed) { DecControllerFifoMessage msg; msg.Type= MSG_DEC_CTRL_SWITCH_FLASHER_ON; gpBlueDecController->DetectorParams.FlasherCurrent = 0; // if the link is not connected, reject the command if (!(IS(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_LINK_STATUS, K_BMASK_TASK_STATUS_LINK_CONNECTED) && TEST_ONE_BIT(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_DEC_CTRL_POWERED_ON))) { SequencerSendNack(0, COULD_NOT_EXECUTE_COMMAND); SetSequencerError(ERR_SEQUENCER_COULD_NOT_EXECUTE_COMMAND); SetError(ERR_DEC_CONTROLLER_LINK_NOT_CONNECTED); return FALSE; } KS_FIFOPut(BLUE_DEC_FIFO, &msg); SequencerSendAck(DMC_SWON_BD_FLASHER); return FALSE; } /* CMD_FUNCTION : BOOL CommandSwOffBlueFlasher(CommandParameter paramNotUsed) ************************************************************************** AUTHOR : Amazy USE : Switches off the Flasher of blue DEC */ BOOL CommandSwOffBlueFlasher(CommandParameter paramNotUsed) { DecControllerFifoMessage msg; msg.Type= MSG_DEC_CTRL_SWITCH_FLASHER_OFF; // if the link is not connected, reject the command if (!(IS(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_LINK_STATUS, K_BMASK_TASK_STATUS_LINK_CONNECTED) && TEST_ONE_BIT(gpBlueDecController->TaskStatus, K_BMASK_TASK_STATUS_DEC_CTRL_POWERED_ON))) { SequencerSendNack(0, COULD_NOT_EXECUTE_COMMAND); SetSequencerError(ERR_SEQUENCER_COULD_NOT_EXECUTE_COMMAND); SetError(ERR_DEC_CONTROLLER_LINK_NOT_CONNECTED); return FALSE; } KS_FIFOPut(BLUE_DEC_FIFO, &msg); SequencerSendAck(DMC_SWOF_BD_FLASHER); return FALSE; }