/************************************************************************* $Archive: /PACS/OnBoard/DpuSend.c $ $Revision: 1.11 $ $Date: 2009/04/23 13:51:12 $ $Author: amazy $ $Log: DpuSend.c,v $ Revision 1.11 2009/04/23 13:51:12 amazy 6.029 * * 39 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 "constant.h" #include "params.h" #include "error.h" #include "links.h" #include "u_res.h" //**************************************************************** // LOCAL VARIABLES //**************************************************************** static int EmissionBuffer[512]; //**************************************************************** // MACRO //**************************************************************** //macro to signal an error in DPU Sender Task #define SetError(newError) \ {\ SetGlobalError(newError);\ LOCK_WRITE_RES_PARAMS;\ SET_BITS(gpDpuSend->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 InitializeDpuSend(); void DpuSend(); //**************************************************************** // FUNCTION IMPLEMENTATION //**************************************************************** /* FUNCTION : void InitializeDpuSend() *********************************** AUTHOR : AMazy USE : Initialize the Dpu Sender Task */ void InitializeDpuSend() { // initialize task status LOCK_WRITE_RES_PARAMS; gpDpuSend->TaskStatus = K_BMASK_TASK_STATUS_ALIVE | K_BMASK_TASK_STATUS_NO_ERROR_IN_TASK | K_BMASK_TASK_STATUS_LINK_NOT_CONNECTED; gpDpuSend->PacketCounter = 0; 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(gpDpuSend->TaskStatus, K_BMASK_TASK_STATUS_LINK_STATUS, K_BMASK_TASK_STATUS_LINK_CONNECTED)); UNLOCK_READ_RES_PARAMS; // signal to HkController that its buffer is available KS_EventSignal(EVENT_HK_PACKET_BUFFER_AVAILABLE); KS_SemaSignal(SEMA_DUMP_BUFFER_AVAILABLE); } /* TASK_FUNCTION : void DpuSend() ****************************** AUTHOR : AMazy This function implements the DPU Sender task. It receives messages in its FIFO (mainly coming from DPU Receiver and Sequencer), formats the messages and send them to DPU. */ void DpuSend() { DpuSenderMsg msg; // temporary variable used to receive the message in the fifo InitializeDpuSend(); while (1) { // wait that another task writes something in the fifo. KS_FIFOGetW(DPUSENDER_FIFO, &msg); // react according to the message type switch(msg.Header & 0xFFFF0000) { case TRIGGER_ACK : { // format packet : EmissionBuffer[0] = msg.Header; // send it : Link1355Write(CHANNEL_DPU, 1, EmissionBuffer); gpDpuSend->PacketCounter++; };break; case TRIGGER_NACK : { // format packet : EmissionBuffer[0] = msg.Header; EmissionBuffer[0] |= msg.Field1.ErrorCode; EmissionBuffer[1] = msg.Field2.Parameter; // send it : Link1355Write(CHANNEL_DPU, 2, EmissionBuffer); gpDpuSend->PacketCounter++; };break; case WRITE_ACK : case LOAD_ACK : { // format packet : EmissionBuffer[0] = msg.Header; // send it : Link1355Write(CHANNEL_DPU, 1, EmissionBuffer); gpDpuSend->PacketCounter++; };break; case CHECK_ACK : { // format packet : EmissionBuffer[0] = msg.Header; EmissionBuffer[0] |= msg.Field1.MemId; EmissionBuffer[1] = msg.Field2.Address; EmissionBuffer[1] |= msg.Field3.LengthSAU; EmissionBuffer[2] = msg.Field4.Checksum << 16; // send it : Link1355Write(CHANNEL_DPU, 3, EmissionBuffer); gpDpuSend->PacketCounter++; };break; case DUMP_ACK : case DUMP_ACK_INTERMED : { int messageLength; // format packet (no need to check the length (DPU Receiver has already done it) : EmissionBuffer[0] = msg.Header; EmissionBuffer[0] |= msg.Field1.MemId; EmissionBuffer[1] = msg.Field2.Address; EmissionBuffer[1] |= msg.Field3.LengthSAU; MEMCPY(&(EmissionBuffer[2]), gDumpPacketBuffer, msg.Field5.LengthWords); if ((msg.Field5.LengthWords % 2) == 0) { // add the checksum on the MSB of a word appended after the data EmissionBuffer[2 + msg.Field5.LengthWords] = msg.Field4.Checksum << 16; messageLength = msg.Field5.LengthWords + 3; } else { // the LSB of the last word of data are not used, so, put the checksum in it EmissionBuffer[2 + msg.Field5.LengthWords] |= msg.Field4.Checksum; messageLength = msg.Field5.LengthWords + 2; } // signal to DPU receiver that it can copy the next packet KS_SemaSignal(SEMA_DUMP_BUFFER_AVAILABLE); // send it : Link1355Write(CHANNEL_DPU, messageLength, EmissionBuffer); gpDpuSend->PacketCounter++; };break; case LOAD_NACK : case DUMP_NACK : case CHECK_NACK : case WRITE_NACK : { // format packet : EmissionBuffer[0] = msg.Header; EmissionBuffer[0] |= msg.Field1.ErrorCode; EmissionBuffer[1] = msg.Field2.Parameter; // send it : Link1355Write(CHANNEL_DPU, 2, EmissionBuffer); gpDpuSend->PacketCounter++; };break; case HK_PACKET : { // format packet (no need to check the length (HK Controller has already done it) : EmissionBuffer[0] = msg.Header; EmissionBuffer[1] = msg.Field1.Length; // copy the buffer and signal to the HkController that it is now available MEMCPY(&(EmissionBuffer[2]), gHkPacketBuffer, msg.Field1.Length); KS_EventSignal(EVENT_HK_PACKET_BUFFER_AVAILABLE); // send it to the DPU : Link1355Write(CHANNEL_DPU, msg.Field1.Length + 2, EmissionBuffer); gpDpuSend->PacketCounter++; };break; case HK_DIAG_PACKET : { // format packet (no need to check the length (HK Diagnostic Controller has already done it) : EmissionBuffer[0] = msg.Header; EmissionBuffer[1] = msg.Field1.Length; // copy the appropriate buffer and signal to the HkController that it is now available MEMCPY(&(EmissionBuffer[2]), &(gaaHkDiagPacketBuffer[msg.Field2.BufferToSend][2]), msg.Field1.Length); // if the packet is not empty, send it to DPU if (msg.Field1.Length != 0) { Link1355Write(CHANNEL_DPU, msg.Field1.Length + 2, EmissionBuffer); gpDpuSend->PacketCounter++; } };break; default : SetError(ERR_DPU_SENDER_UNKNOWN_FIFO_MSG); } } }