/************************************************************************* $Archive: /PACS/OnBoard/BolCtrl.c $ $Revision: 1.11 $ $Date: 2009/04/23 13:51:12 $ $Author: amazy $ $Log: BolCtrl.c,v $ Revision 1.11 2009/04/23 13:51:12 amazy 6.029 * * 31 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" //**************************************************************** // MACRO //**************************************************************** //macro to signal an error in BOL Controller Task #define SetError(newError) \ {\ SetGlobalError(newError);\ LOCK_WRITE_RES_PARAMS;\ SET_BITS(gpBolController->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(gpBolRec->TaskStatus, K_BMASK_SIMULATION_TIMING, K_BMASK_REAL_TIMING)) \ {\ UNLOCK_READ_RES_PARAMS;\ Link1355Write(a, b, c); \ gpBolController->PacketCounter++; \ }\ else\ {\ UNLOCK_READ_RES_PARAMS;\ } //**************************************************************** // FUNCTION DECLARATION //**************************************************************** void ValidateBolHK(int validity); void InitializeDolCtrl(); void BolCtrl(); // commands functions BOOL CommandSendCommandToBOLC(CommandParameter param); //**************************************************************** // FUNCTION IMPLEMENTATION //**************************************************************** /* FUNCTION : void InitializeBolCtrl() *********************************** AUTHOR : AMazy USE : Initialize Bol Controller task. */ void InitializeBolCtrl() { // initialize status LOCK_WRITE_RES_PARAMS; gpBolController->TaskStatus = K_BMASK_TASK_STATUS_ALIVE | K_BMASK_TASK_STATUS_NO_ERROR_IN_TASK | K_BMASK_TASK_STATUS_LINK_NOT_CONNECTED; gpBolController->PacketCounter = 0; gpBolController->ReadoutValidityBlue = INVALID; gpBolController->ReadoutValidityRed = INVALID; UNLOCK_WRITE_RES_PARAMS; LOCK_READ_RES_PARAMS; // wait that the BOLC initializes the connection on the other side // or that a detector simulator is started (when gpBolRec->TaskStatus have been modified) while (!IS(gpBolController->TaskStatus, K_BMASK_TASK_STATUS_LINK_STATUS, K_BMASK_TASK_STATUS_LINK_CONNECTED) && IS(gpBolRec->TaskStatus, K_BMASK_SIMULATION, K_BMASK_REAL_TIMING + K_BMASK_REAL_READOUTS)) { UNLOCK_READ_RES_PARAMS; KS_TaskSleep(1000); LOCK_READ_RES_PARAMS; } UNLOCK_READ_RES_PARAMS; } /* TASK_FUNCTION : void BolCtrl() ****************************** AUTHOR : AMazy This function implements the BOL controller task. It waits for message from the Sequencer (on a FIFO) and transmit the command to BOLC on the 1335 link. */ void BolCtrl() { BolControllerFifoMessage msg; //declare a structure used to receive message on the fifo InitializeBolCtrl(); while(1) { // wait for a message from the sequencer KS_FIFOGetW(BOL_CTRL_FIFO, &msg); switch (msg.Type) { case BOL_MSG_TRANSMIT_COMMAND : { LINK_1355_WRITE(CHANNEL_BOL, 1, &(msg.BolCommand)); };break; default : { SetError(ERR_BOL_CONTROLLER_UNKNOWN_FIFO_MSG); }; } } } /* CMD_FUNCTION : BOOL CommandSendCommandToBOLC(CommandParameter param) ******************************************************************** AUTHOR : Amazy USE : Transmit a command from the DPU to BOLC. PARAMS : int param is the command to be transmitted */ BOOL CommandSendCommandToBOLC(CommandParameter param) { BolControllerFifoMessage msg; msg.Type = BOL_MSG_TRANSMIT_COMMAND; msg.BolCommand = param.Uint; // if the link is not connected, reject the command if (!IS(gpBolController->TaskStatus, K_BMASK_TASK_STATUS_LINK_STATUS, K_BMASK_TASK_STATUS_LINK_CONNECTED)) { SequencerSendNack(0, COULD_NOT_EXECUTE_COMMAND); SetSequencerError(ERR_SEQUENCER_COULD_NOT_EXECUTE_COMMAND); SetError(ERR_BOL_CONTROLLER_LINK_NOT_CONNECTED); return FALSE; } KS_FIFOPut(BOL_CTRL_FIFO, &msg); SequencerSendAck(DMC_SEND_COMMAND_TO_BOLC); return FALSE; } /* CMD_FUNCTION : BOOL CommandResetBolReadoutCounter(CommandParameter paramNotUsed) ******************************************************************************** AUTHOR : Amazy USE : Resets the BOL readout counter */ BOOL CommandResetBolReadoutCounter(CommandParameter paramNotUsed) { gpBolRec->ReadoutCounter = 0; SequencerSendAck(DMC_RESET_BOL_READOUT_C); return FALSE; } /* FUNCTION : void ValidateBolHK(int validity) ******************************************* AUTHOR : AMazy USE : Validate or invalidate the BOLC housekeeping */ void ValidateBolHK(int validity) { int i=0; for (i = BOLC_HK_1; i <= BOLC_HK_196; ++i) { gaHkMeasure[i].Valid = validity; } for (i = BOLC_HK_197; i <= BOLC_HK_224; ++i) { gaHkMeasure[i].Valid = validity; } }