/************************************************************************* $Archive: /PACS/OnBoard/RPackEnc.c $ $Revision: 1.11 $ $Date: 2009/04/23 13:51:12 $ $Author: amazy $ $Log: RPackEnc.c,v $ Revision 1.11 2009/04/23 13:51:12 amazy 6.029 * * 24 3/14/06 4:32p 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 gaRedSpectroPacketBuffer[2]; // two buffers shared between the PacketEncoder and the Detector Receiver PhotometryPacket gaRedPhotoPacketBuffer[2]; //**************************************************************** // MACRO //**************************************************************** //macro to signal an error in Red Packet Encoder Task #define SetError(newError) \ {\ SetGlobalError(newError);\ LOCK_WRITE_RES_PARAMS;\ SET_BITS(gpRedPacketEncoder->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 InitializeRedPacketEncoder(); void RedPackEnc(); //**************************************************************** // FUNCTION IMPLEMENTATION //**************************************************************** /* FUNCTION : void InitializeRedPacketEncoder() ***************************************** AUTHOR : AMazy USE : initializes the Packet Encoder */ void InitializeRedPacketEncoder() { // initialize task status LOCK_WRITE_RES_PARAMS; gpRedPacketEncoder->TaskStatus = K_BMASK_TASK_STATUS_ALIVE | K_BMASK_TASK_STATUS_NO_ERROR_IN_TASK | K_BMASK_TASK_STATUS_LINK_NOT_CONNECTED; gpRedPacketEncoder->BufferToSend = 0; gParameters.RedSpuTransmissionMode = 0x10; gParameters.RedPacketEncoderLink = CHANNEL_RED_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(gpRedPacketEncoder->TaskStatus, K_BMASK_TASK_STATUS_LINK_STATUS, K_BMASK_TASK_STATUS_LINK_CONNECTED)); UNLOCK_READ_RES_PARAMS; }; /* TASK_FUNCTION : void RedPackEnc() ********************************* AUTHOR : AMazy This function implements the Packet Encoder to Red SPU. It waits for packets from DEC and BOL Receiver and forwards them to the SPU. */ void RedPackEnc() { PacketEncoderMessage msg; //used to store the message received on the FIFO InitializeRedPacketEncoder(); while (1) { // wait that a detector receiver sends a message KS_FIFOGetW(RED_PACKET_ENCODER_FIFO, &msg); SendPacketToSPU(CHANNEL_RED_SPU, msg); }; }