/************************************************************************* $Archive: /PACS/OnBoard/BPackEnc.c $ $Revision: 6 $ $Date: 11/27/06 6:49p $ $Author: Amazy $ $Log: /PACS/OnBoard/BPackEnc.c $ * * 6 11/27/06 6:49p Amazy * syntax errors corrected * * 5 27/11/06 9:39 Amazy * All error from packet encoders (blue and red) were signaled in the blue * packet encoder status. This is now solved (the * GenereSpectroPacketHeader function now takes an additional parameter * that is a pointer to the packet encoder were the error must be * signaled). * * 41 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 "params.h" #include "det.h" #include "error.h" #include "links.h" #include "u_res.h" //**************************************************************** // GLOBAL VARIABLES //**************************************************************** SpectroscopyPacket gaBlueSpectroPacketBuffer[2]; // two buffers shared between the PacketEncoder and the Detector Receiver PhotometryPacket gaBluePhotoPacketBuffer[2][4]; //**************************************************************** // MACRO //**************************************************************** //macro to signal an error in Blue Packet Encoder Task #define SetError(p_bluePacketEncoder, newError) \ {\ SetGlobalError(newError);\ LOCK_WRITE_RES_PARAMS;\ SET_BITS(p_bluePacketEncoder->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;\ }\ //**************************************************************** // FUNCTION DECLARATION //**************************************************************** void InitializeBluePacketEncoder(); void BluePackEnc(); void GenerateSpectroPacketHeader(PacketEncoderParams* p_packetEncoder, SpectroscopyPacket* p_spectroPacket, int apid, DecRecParams* p_decRec, DecControllerParams* p_decCtrl, BOOL bSimulateReadouts); void GeneratePhotoPacketHeader(PhotometryPacket* p_photoPacket, int apid); void SendPacketToSPU(int channel, PacketEncoderMessage msg); //**************************************************************** // FUNCTION IMPLEMENTATION //**************************************************************** /* FUNCTION : void InitializeBluePacketEncoder() ********************************************* AUTHOR : AMazy USE : initializes the Packet Encoder */ void InitializeBluePacketEncoder() { // initialize task status LOCK_WRITE_RES_PARAMS; gpBluePacketEncoder->TaskStatus = K_BMASK_TASK_STATUS_ALIVE | K_BMASK_TASK_STATUS_NO_ERROR_IN_TASK | K_BMASK_TASK_STATUS_LINK_NOT_CONNECTED; gpBluePacketEncoder->BufferToSend = 0; gParameters.BlueSpuTransmissionMode = 0x10; gParameters.BluePacketEncoderLink = CHANNEL_BLUE_SPU; UNLOCK_WRITE_RES_PARAMS; LOCK_READ_RES_PARAMS; // wait that the Link1355 is initialized by the other side do { UNLOCK_READ_RES_PARAMS; KS_TaskSleep(1000); LOCK_READ_RES_PARAMS; } while (!IS(gpBluePacketEncoder->TaskStatus, K_BMASK_TASK_STATUS_LINK_STATUS, K_BMASK_TASK_STATUS_LINK_CONNECTED)); UNLOCK_READ_RES_PARAMS; }; /* TASK_FUNCTION : void BluePackEnc() ********************************** AUTHOR : AMazy This function implements the Packet Encoder to Blue SPU. It waits for packets from DEC and BOL Receiver and forwards them to the SPU. */ void BluePackEnc() { PacketEncoderMessage msg; //used to store the message received on the FIFO InitializeBluePacketEncoder(); while (1) { // wait that a detector receiver sends a message KS_FIFOGetW(BLUE_PACKET_ENCODER_FIFO, &msg); SendPacketToSPU(CHANNEL_BLUE_SPU, msg); }; } /* FUNCTION : void SendPacketToSPU(int channel, PacketEncoderMessage msg) ********************************************************************** AUTHOR : AMazy Send the packet to the selected SPU. PARAMS: channel: the 1335 link on which the packet must be sent msg: information about the packet to send */ void SendPacketToSPU(int channel, PacketEncoderMessage msg) { switch (msg.Type) { case BLUE_SPEC : { // signal to the BlueDecReceiver to use the other buffer KS_EventSignal(EVENT_BLUE_DET_RECEIVER_TOGGLE_BUFFER); // send it to the SPU. Link1355Write(channel, SIZEOF(SpectroscopyPacket), &(gaBlueSpectroPacketBuffer[msg.BufferId])); gpBluePacketEncoder->PacketCounter++; };break; case RED_SPEC : { // signal to the RedDecReceiver to use the other buffer KS_EventSignal(EVENT_RED_DET_RECEIVER_TOGGLE_BUFFER); // send it to the SPU. Link1355Write(channel, SIZEOF(SpectroscopyPacket), &(gaRedSpectroPacketBuffer[msg.BufferId])); gpRedPacketEncoder->PacketCounter++; };break; case BOL_RED : { // signal to the RedDecReceiver to use the other buffer KS_EventSignal(EVENT_RED_DET_RECEIVER_TOGGLE_BUFFER); // send it to the SPU. Link1355Write(channel, SIZEOF(PhotometryPacket), &(gaRedPhotoPacketBuffer[msg.BufferId])); gpRedPacketEncoder->PacketCounter++; };break; case BOL_BLUE : { // signal to the BlueDecReceiver to use the other buffer KS_EventSignal(EVENT_BLUE_DET_RECEIVER_TOGGLE_BUFFER); // send it to the SPU. Link1355Write(channel, SIZEOF(PhotometryPacket), &(gaBluePhotoPacketBuffer[msg.BufferId][0])); gpBluePacketEncoder->PacketCounter++; #ifdef SIMULATOR KS_TaskSleep(5); #endif //SIMULATOR // send it to the SPU. Link1355Write(channel, SIZEOF(PhotometryPacket), &(gaBluePhotoPacketBuffer[msg.BufferId][1])); gpBluePacketEncoder->PacketCounter++; #ifdef SIMULATOR KS_TaskSleep(5); #endif //SIMULATOR // send it to the SPU. Link1355Write(channel, SIZEOF(PhotometryPacket), &(gaBluePhotoPacketBuffer[msg.BufferId][2])); gpBluePacketEncoder->PacketCounter++; #ifdef SIMULATOR KS_TaskSleep(5); #endif //SIMULATOR // send it to the SPU. Link1355Write(channel, SIZEOF(PhotometryPacket), &(gaBluePhotoPacketBuffer[msg.BufferId][3])); gpBluePacketEncoder->PacketCounter++; };break; } } /* FUNCTION : void GenerateSpectroPacketHeader(PacketEncoderParams* p_packetEncoder, SpectroscopyPacket* p_spectroPacket, int apid, DecRecParams* p_decRec, DecControllerParams* p_decCtrl, BOOL bSimulateReadouts) **************************************************************************************************************************************************************************************************************** AUTHOR : AMazy Create header for spectrocopy packets PARAMS: p_packetEncoder: a pointer to the packet encoder that called this function (used to signal errors) p_spectroPacket: the packet for which we must generate a header apid: the APID (Blue SPU or Red SPU) to put in the header p_decRec: the DEC Receiver that has received the packet p_decCtrl: the DEC Controller related to this packet bSimulateReadouts: Is this packet a simulated packet ? */ void GenerateSpectroPacketHeader(PacketEncoderParams* p_packetEncoder, SpectroscopyPacket* p_spectroPacket, int apid, DecRecParams* p_decRec, DecControllerParams* p_decCtrl, BOOL bSimulateReadouts) { DecHkReadback* p_decHk; // generate the header p_spectroPacket->APID = apid; p_spectroPacket->PacketId = 0x00000001; p_spectroPacket->OBSID = gpSequencer->OBSID; p_spectroPacket->BBID = gpSequencer->BBID; p_spectroPacket->Label = gpSequencer->Label; p_spectroPacket->Time[0] = gpSequencer->Time[0]; p_spectroPacket->Time[1] = gpSequencer->Time[1]; p_spectroPacket->ChopperPosition = GetHkValue(DMC_CHOP_CUR_POS); p_spectroPacket->GratingPosition = GetHkValue(DMC_GRAT_CUR_POS); p_spectroPacket->WheelPosition = GetHkValue(DMC_FWSP_CUR_POS); if (apid == BLUE_SPU_APID) { p_spectroPacket->CompressionParameters = gParameters.BlueSpuTransmissionMode; } else { p_spectroPacket->CompressionParameters = gParameters.RedSpuTransmissionMode; } // if we want to send simulated readouts if (bSimulateReadouts) { p_decHk = &(p_decRec->SimDecHk); } else { p_decHk = &(p_decRec->DecHk); } p_spectroPacket->Validity = p_decCtrl->DetectorParams.ReadoutValidity; p_spectroPacket->CurrentReadoutCount = p_decHk->ReadoutCounterFirst; p_spectroPacket->ReadoutsInRamp = p_decHk->ReadoutsPerRampFirst; p_spectroPacket->ReadoutCount = p_decRec->ReadoutCounter; p_spectroPacket->CreControlReadback = p_decHk->CreStatusRegFirst; if (p_spectroPacket->CurrentReadoutCount > p_spectroPacket->ReadoutsInRamp) { SetError(p_packetEncoder, ERR_PACKET_ENCODER_INVALID_READOUT_COUNTER); } } /* FUNCTION : void GeneratePhotoPacketHeader(PhotometryPacket* p_photoPacket, int apid) ************************************************************************************ AUTHOR : AMazy Create header for photometry packets PARAMS: p_photooPacket: the packet for which we must generate a header apid: the APID (Blue SPU or Red SPU) to put in the header */ void GeneratePhotoPacketHeader(PhotometryPacket* p_photoPacket, int apid) { // generate the header p_photoPacket->APID = apid; p_photoPacket->PacketId = 0x00000002; p_photoPacket->OBSID = gpSequencer->OBSID; p_photoPacket->BBID = gpSequencer->BBID; p_photoPacket->Label = gpSequencer->Label; p_photoPacket->Time[0] = gpSequencer->Time[0]; p_photoPacket->Time[1] = gpSequencer->Time[1]; if (apid == BLUE_SPU_APID) { p_photoPacket->Validity = gpBolController->ReadoutValidityBlue; } else { p_photoPacket->Validity = gpBolController->ReadoutValidityRed; } p_photoPacket->ChopperPosition = GetHkValue(DMC_CHOP_CUR_POS); p_photoPacket->WheelPosition = GetHkValue(DMC_FWPH_CUR_POS); p_photoPacket->BolcStatusWord = gpBolRec->BolcStatusWord; p_photoPacket->OBTCount = gpMim->PeriodCount; p_photoPacket->CurrentReadoutCountInChopperPosition = gpMim->ReadoutCountInChopperPosition; if (apid == BLUE_SPU_APID) { p_photoPacket->CompressionParameters = gParameters.BlueSpuTransmissionMode; } else { p_photoPacket->CompressionParameters = gParameters.RedSpuTransmissionMode; } }