From 682f6b9fbd2f7296b53896b0d534627e7bcf255d Mon Sep 17 00:00:00 2001 From: xmarvla Date: Mon, 19 Mar 2012 10:07:32 +0100 Subject: Fix flashing hang when wolverine is used. LCM adjustment for new USB RAM based driver in DBDT environment. ST-Ericsson ID: 421630 ST-Ericsson FOSS-OUT ID: STETL-FOSS-OUT-10204 Change-Id: I2f2835b56857eb9640501ff681400517600ccdef Depends-On: I6112822704abd420e9a68d4b542234245a734773 Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/52545 Tested-by: Vlatko STENKOSKI Reviewed-by: QABUILD Reviewed-by: QATEST Reviewed-by: Zoran ANCEVSKI --- lcmodule/source/LCM.rc | 6 +- .../include/t_protrom_transport.h | 1 + .../source/bulk_protocol.c | 14 +- .../source/command_protocol.c | 25 ++- .../source/r15_transport_layer.c | 38 ++--- .../include/t_r15_header.h | 6 - .../include/t_r15_network_layer.h | 7 +- .../source/r15_network_layer.c | 133 +++++++++------- .../config/command_marshal.xsl | 16 +- .../config/common.xsl | 8 +- .../config/error_codes.xml | 2 + .../source/communication_service.c | 6 +- .../source/lcm_version.c | 2 +- .../legacy_compatibility/t_basicdefinitions.h | 8 +- source/CEH/ProtromRpcInterface.cpp | 1 + source/LCDriver.rc | 6 +- source/LCM/Buffers.cpp | 2 +- source/LCM/include/error_codes.h | 170 ++++++++++++++++----- source/LCM/include/t_bulk_protocol.h | 4 +- source/LCM/include/t_command_protocol.h | 8 +- source/LCM/include/t_communication_service.h | 28 ++-- source/LCM/include/t_protrom_header.h | 2 +- source/LCM/include/t_protrom_network.h | 20 +-- source/LCM/include/t_protrom_transport.h | 2 +- source/LCM/include/t_r15_header.h | 8 +- source/LCM/include/t_r15_network_layer.h | 48 +++--- source/LcdVersion.cpp | 2 +- 27 files changed, 335 insertions(+), 238 deletions(-) diff --git a/lcmodule/source/LCM.rc b/lcmodule/source/LCM.rc index 180fe54..61bc97a 100644 --- a/lcmodule/source/LCM.rc +++ b/lcmodule/source/LCM.rc @@ -69,15 +69,15 @@ BEGIN BEGIN BLOCK "040904b0" BEGIN - VALUE "Comments", "Build date: 2012-02-07" + VALUE "Comments", "Build date: 2012-03-14" VALUE "CompanyName", "STEricsson AB" VALUE "FileDescription", "LCM Dynamic Link Library" VALUE "FileVersion", "1, 0, 0, 1" VALUE "InternalName", "Loader Communication Module" VALUE "LegalCopyright", "Copyright (C) STEricsson AB 2012" - VALUE "PrivateBuild", "Change-Id: I70835353a592d1f1ad40743640a1d0827e56fd2e" + VALUE "PrivateBuild", "Change-Id: I2f2835b56857eb9640501ff681400517600ccdef" VALUE "ProductName", "CXA1104507 Loader Communication Module" - VALUE "ProductVersion", "P4Y" + VALUE "ProductVersion", "P5Y" END END BLOCK "VarFileInfo" diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_protrom_transport.h b/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_protrom_transport.h index 25ef644..7399c2f 100644 --- a/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_protrom_transport.h +++ b/lcmodule/source/cnh1605204_ldr_transport_layer/include/t_protrom_transport.h @@ -17,6 +17,7 @@ * Includes ******************************************************************************/ #include "t_basicdefinitions.h" +#include "t_protrom_header.h" /******************************************************************************* * Types, constants and external variables diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/source/bulk_protocol.c b/lcmodule/source/cnh1605204_ldr_transport_layer/source/bulk_protocol.c index 4e4a1fb..9905069 100644 --- a/lcmodule/source/cnh1605204_ldr_transport_layer/source/bulk_protocol.c +++ b/lcmodule/source/cnh1605204_ldr_transport_layer/source/bulk_protocol.c @@ -204,7 +204,7 @@ TL_BulkVectorList_t *Do_R15_Bulk_CreateVector(const Communication_t *const Commu return NULL; } - Packet_p->ExtendedHeader_p = Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER + ALIGNED_HEADER_LENGTH; + Packet_p->ExtendedHeader_p = Packet_p->Buffer_p + ALIGNED_HEADER_LENGTH; Packet_p->Payload_p = Packet_p->ExtendedHeader_p + ALIGNED_BULK_EXTENDED_HEADER_LENGTH; #else /* packet meta info allocate */ @@ -220,8 +220,8 @@ TL_BulkVectorList_t *Do_R15_Bulk_CreateVector(const Communication_t *const Commu Packet_p->Buffer_p = NULL; Packet_p->BufferSize = BULK_BUFFER_SIZE; SET_PACKET_FLAGS(Packet_p, PACKET_ALLOCATION_STATE_MASK, BUF_ALLOCATED); - Packet_p->Payload_p = (uint8 *)(HEADER_OFFSET_IN_BUFFER + ALIGNED_HEADER_LENGTH + ALIGNED_BULK_EXTENDED_HEADER_LENGTH); - Packet_p->ExtendedHeader_p = Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER + ALIGNED_HEADER_LENGTH; + Packet_p->Payload_p = (uint8 *)(ALIGNED_HEADER_LENGTH + ALIGNED_BULK_EXTENDED_HEADER_LENGTH); + Packet_p->ExtendedHeader_p = Packet_p->Buffer_p + ALIGNED_HEADER_LENGTH; BuffersNr = 0; do { @@ -1124,7 +1124,7 @@ static void R15_Bulk_SerializeChunk(Communication_t *Communication_p, PacketMeta TL_BulkVectorList_t *BulkVector_p = R15_TRANSPORT(Communication_p)->BulkHandle.BulkVector_p; uint32 DeltaLength = 0; - Packet_p->Timer_p = NULL; + memset(&(Packet_p->Timer), 0, sizeof(Timer_t)); Packet_p->Resend = 0; /* set call back function */ Packet_p->CallBack_p = NULL; @@ -1157,7 +1157,7 @@ static void R15_Bulk_SerializeChunk(Communication_t *Communication_p, PacketMeta ExtendedHeader.TypeFlags = CMD_BULK_DATA; /* serialize and calculate extended header */ - Packet_p->ExtendedHeader_p = Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER + ALIGNED_HEADER_LENGTH; + Packet_p->ExtendedHeader_p = Packet_p->Buffer_p + ALIGNED_HEADER_LENGTH; R15_SerializeExtendedHeader(Packet_p->ExtendedHeader_p, Header.Protocol, &ExtendedHeader, &(Header.ExtendedHeaderChecksum)); /* setup header for serialization and calculation */ memcpy(&Packet_p->Header, &Header, HEADER_LENGTH); @@ -1174,7 +1174,7 @@ static void R15_Bulk_SerializeChunk(Communication_t *Communication_p, PacketMeta (void *)Packet_p); } else { memset(&Packet_p->Header.PayloadChecksum, 0x0, sizeof(uint32)); - R15_SerializeHeader(Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER, &Packet_p->Header); + R15_SerializeHeader(Packet_p->Buffer_p, &Packet_p->Header); SET_PACKET_FLAGS(Packet_p, PACKET_CRC_STATE_MASK, BUF_PAYLOAD_CRC_CALCULATED); } } @@ -1190,7 +1190,7 @@ static void R15_Bulk_OutHashCallback(const void *const Data_p, uint32 Length, co PacketMeta_t *Packet_p = (PacketMeta_t *)Param_p; memcpy(&Packet_p->Header.PayloadChecksum, Hash_p, sizeof(uint32)); - R15_SerializeHeader(Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER, &Packet_p->Header); + R15_SerializeHeader(Packet_p->Buffer_p, &Packet_p->Header); SET_PACKET_FLAGS(Packet_p, PACKET_CRC_STATE_MASK, BUF_PAYLOAD_CRC_CALCULATED); } diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/source/command_protocol.c b/lcmodule/source/cnh1605204_ldr_transport_layer/source/command_protocol.c index 311ca2b..6041965 100644 --- a/lcmodule/source/cnh1605204_ldr_transport_layer/source/command_protocol.c +++ b/lcmodule/source/cnh1605204_ldr_transport_layer/source/command_protocol.c @@ -259,25 +259,18 @@ static ErrorCode_e DispatchCommand(Communication_t *Communication_p, PacketMeta_ CmdData.ApplicationNr = ExtendedHeader.CommandGroup; CmdData.SessionNr = ExtendedHeader.SessionState >> 2; CmdData.Payload.Size = Packet_p->Header.PayloadLength; - CmdData.Payload.Data_p = NULL; - - if (0 != CmdData.Payload.Size) { - CmdData.Payload.Data_p = (uint8 *)malloc(Packet_p->Header.PayloadLength); - - if (NULL == CmdData.Payload.Data_p) { - return E_ALLOCATE_FAILED; - } - - memcpy(CmdData.Payload.Data_p, Packet_p->Payload_p, Packet_p->Header.PayloadLength); - } - - ReturnValue = R15_Network_PacketRelease(Communication_p, Packet_p); + CmdData.Payload.Data_p = Packet_p->Payload_p; ReturnValue = Communication_p->Do_CEH_Call_Fn(OBJECT_CEH_CALL(Communication_p), &CmdData); - if (NULL != CmdData.Payload.Data_p) { - free(CmdData.Payload.Data_p); - CmdData.Payload.Data_p = NULL; + if (E_SUCCESS == ReturnValue) { + ReturnValue = R15_Network_PacketRelease(Communication_p, Packet_p); + } else { + ErrorCode_e PacketReleaseRet = R15_Network_PacketRelease(Communication_p, Packet_p); + + if (E_SUCCESS != PacketReleaseRet) { + A_(printf("command_protocol.c (%d): Failed to release Network packet! Error: %d\n", __LINE__, PacketReleaseRet);) + } } return ReturnValue; diff --git a/lcmodule/source/cnh1605204_ldr_transport_layer/source/r15_transport_layer.c b/lcmodule/source/cnh1605204_ldr_transport_layer/source/r15_transport_layer.c index dcc5a3a..220ccec 100644 --- a/lcmodule/source/cnh1605204_ldr_transport_layer/source/r15_transport_layer.c +++ b/lcmodule/source/cnh1605204_ldr_transport_layer/source/r15_transport_layer.c @@ -35,7 +35,7 @@ /******************************************************************************* * Declaration of file local functions ******************************************************************************/ -static Timer_t *TimerSet(PacketMeta_t *Packet_p, const SendData_LP_t *const InputData_p, Communication_t *Communication_p); +static void TimerSet(PacketMeta_t *Packet_p, const SendData_LP_t *const InputData_p, Communication_t *Communication_p); static void R15_Transport_OutHashCallback(const void *const Data_p, uint32 Length, const uint8 *const Hash_p, void *Param_p); #ifdef CFG_ENABLE_LOADER_TYPE static ErrorCode_e ConfigureDeviceTimeouts(Communication_t *Communication_p); @@ -187,16 +187,16 @@ ErrorCode_e R15_Transport_Send(Communication_t *Communication_p, void *InputData Packet_p->Resend = 0; Packet_p->CallBack_p = NULL; - Packet_p->Timer_p = TimerSet(Packet_p, InputData_p, Communication_p); + TimerSet(Packet_p, InputData_p, Communication_p); Packet_p->Header = *InputData_p->Header_p; /* serialize and calculate extended header */ - Packet_p->ExtendedHeader_p = Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER + ALIGNED_HEADER_LENGTH; + Packet_p->ExtendedHeader_p = Packet_p->Buffer_p + ALIGNED_HEADER_LENGTH; R15_SerializeExtendedHeader(Packet_p->ExtendedHeader_p, InputData_p->Header_p->Protocol, InputData_p->ExtendedHeader_p, &(Packet_p->Header.ExtendedHeaderChecksum)); if (Packet_p->Header.ExtendedHeaderLength == COMMAND_EXTENDED_HEADER_LENGTH) { - Packet_p->Payload_p = Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER + ALIGNED_HEADER_LENGTH + ALIGNED_COMMAND_EXTENDED_HEADER_LENGTH; + Packet_p->Payload_p = Packet_p->Buffer_p + ALIGNED_HEADER_LENGTH + ALIGNED_COMMAND_EXTENDED_HEADER_LENGTH; } else { - Packet_p->Payload_p = Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER + ALIGNED_HEADER_LENGTH + ALIGNED_BULK_EXTENDED_HEADER_LENGTH; + Packet_p->Payload_p = Packet_p->Buffer_p + ALIGNED_HEADER_LENGTH + ALIGNED_BULK_EXTENDED_HEADER_LENGTH; } if (NULL != InputData_p->Payload_p) { @@ -215,12 +215,12 @@ ErrorCode_e R15_Transport_Send(Communication_t *Communication_p, void *InputData } else { SET_PACKET_FLAGS(Packet_p, PACKET_CRC_STATE_MASK, BUF_PAYLOAD_CRC_CALCULATED); memset(&Packet_p->Header.PayloadChecksum, 0x0, sizeof(uint32)); - R15_SerializeHeader(Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER, &Packet_p->Header); + R15_SerializeHeader(Packet_p->Buffer_p, &Packet_p->Header); (void)QUEUE(Packet_p->Communication_p, FifoEnqueue_Fn)(OBJECT_QUEUE(Packet_p->Communication_p), Packet_p->Communication_p->Outbound_p, Packet_p); } } else { - R15_SerializeHeader(Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER, &Packet_p->Header); + R15_SerializeHeader(Packet_p->Buffer_p, &Packet_p->Header); (void)QUEUE(Communication_p, FifoEnqueue_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Outbound_p, Packet_p); } @@ -290,7 +290,7 @@ static void R15_Transport_OutHashCallback(const void *const Data_p, uint32 Lengt SET_PACKET_FLAGS(Packet_p, PACKET_CRC_STATE_MASK, BUF_PAYLOAD_CRC_CALCULATED); memcpy(&Packet_p->Header.PayloadChecksum, Hash_p, sizeof(uint32)); - R15_SerializeHeader(Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER, &Packet_p->Header); + R15_SerializeHeader(Packet_p->Buffer_p, &Packet_p->Header); (void)QUEUE(Packet_p->Communication_p, FifoEnqueue_Fn)(OBJECT_QUEUE(Packet_p->Communication_p), Packet_p->Communication_p->Outbound_p, Packet_p); } @@ -304,26 +304,16 @@ static void R15_Transport_OutHashCallback(const void *const Data_p, uint32 Lengt * * @return none. */ -static Timer_t *TimerSet(PacketMeta_t *Packet_p, const SendData_LP_t *const InputData_p, Communication_t *Communication_p) +static void TimerSet(PacketMeta_t *Packet_p, const SendData_LP_t *const InputData_p, Communication_t *Communication_p) { - Timer_t *Timer_p = NULL; - if (InputData_p->Time > 0) { - Timer_p = (Timer_t *)malloc(sizeof(Timer_t)); - - if (NULL == Timer_p) { - return NULL; - } - /* timer data */ - Timer_p->Time = InputData_p->Time; - Timer_p->PeriodicalTime = 0; - Timer_p->HandleFunction_p = (HandleFunction_t)(InputData_p->TimerCallBackFn_p); - Timer_p->Data_p = (void *)Packet_p; - Timer_p->Param_p = (void *)Communication_p; + Packet_p->Timer.Time = InputData_p->Time; + Packet_p->Timer.PeriodicalTime = 0; + Packet_p->Timer.HandleFunction_p = (HandleFunction_t)(InputData_p->TimerCallBackFn_p); + Packet_p->Timer.Data_p = (void *)Packet_p; + Packet_p->Timer.Param_p = (void *)Communication_p; } - - return Timer_p; } #ifdef CFG_ENABLE_LOADER_TYPE diff --git a/lcmodule/source/cnh1605205_ldr_network_layer/include/t_r15_header.h b/lcmodule/source/cnh1605205_ldr_network_layer/include/t_r15_header.h index 4b5cc70..a5ed3eb 100644 --- a/lcmodule/source/cnh1605205_ldr_network_layer/include/t_r15_header.h +++ b/lcmodule/source/cnh1605205_ldr_network_layer/include/t_r15_header.h @@ -40,12 +40,6 @@ #define COMMAND_EXTENDED_HEADER_LENGTH 4 /** The length of the bulk extended header. */ #define BULK_EXTENDED_HEADER_LENGTH 20 -/** Offset of the header in the buffer. */ -#ifndef CFG_ENABLE_LOADER_TYPE -#define HEADER_OFFSET_IN_BUFFER 0 -#else -#define HEADER_OFFSET_IN_BUFFER 8 -#endif #define ALIGNED_HEADER_LENGTH ALIGN_SIZE #define ALIGNED_COMMAND_EXTENDED_HEADER_LENGTH ALIGN_SIZE diff --git a/lcmodule/source/cnh1605205_ldr_network_layer/include/t_r15_network_layer.h b/lcmodule/source/cnh1605205_ldr_network_layer/include/t_r15_network_layer.h index 408fdf9..9b1f09e 100644 --- a/lcmodule/source/cnh1605205_ldr_network_layer/include/t_r15_network_layer.h +++ b/lcmodule/source/cnh1605205_ldr_network_layer/include/t_r15_network_layer.h @@ -210,7 +210,7 @@ typedef struct PacketMeta { the packet. */ R15_Header_t Header; /**< Structure of the header. */ uint32 Resend; /**< Resent counter. */ - Timer_t *Timer_p; /**< Timer data used for + Timer_t Timer; /**< Timer data used for sending/receiving packet. */ uint8 *ExtendedHeader_p; /**< Pointer to the extended header located in the packet. */ @@ -236,6 +236,7 @@ typedef struct { uint32 Key; /**< Generated unique key, used for marking packet for retransmission or removing from retransmission list. */ PacketMeta_t *Packet_p; /**< Pointer to the packet for retransmission. */ + boolean InUse; /**< Determine if the entry in retransmission list is currently allocated. */ } RetransmissionContext_t; @@ -284,9 +285,9 @@ typedef struct { /** R15 Network context */ typedef struct { - PacketMeta_t *MetaInfoList[COMMAND_BUFFER_COUNT + BULK_BUFFER_COUNT]; + PacketMeta_t *MetaInfoList[COMMAND_BUFFER_COUNT + BULK_BUFFER_COUNT]; /**< List of meta data for used packets. */ - RetransmissionContext_t *RetransmissionList[MAX_SIZE_RETRANSMISSION_LIST]; + RetransmissionContext_t RetransmissionList[MAX_SIZE_RETRANSMISSION_LIST]; /**< List of packet for retransmission */ uint32 RetransmissionListCount; /**< Counter for packets retransmission */ diff --git a/lcmodule/source/cnh1605205_ldr_network_layer/source/r15_network_layer.c b/lcmodule/source/cnh1605205_ldr_network_layer/source/r15_network_layer.c index 509e8cf..b74cb4a 100644 --- a/lcmodule/source/cnh1605205_ldr_network_layer/source/r15_network_layer.c +++ b/lcmodule/source/cnh1605205_ldr_network_layer/source/r15_network_layer.c @@ -318,14 +318,27 @@ ErrorCode_e R15_Network_TransmiterHandler(Communication_t *Communication_p) #ifdef CFG_ENABLE_LOADER_TYPE uint8 *HeaderStartInBuffer_p = NULL; boolean IsBufferContinuous = FALSE; -#endif + static R15_OutboundState_t SavedState = SEND_IDLE; + static boolean ReRun = FALSE; +#endif // CFG_ENABLE_LOADER_TYPE uint32 ContinuousBufferLength = 0; boolean RegisterRetransmission = FALSE; uint32 ExtHdrLen = 0; uint32 Aligned_Length = 0; +#ifdef CFG_ENABLE_LOADER_TYPE +StartTramsmitter: +#endif // CFG_ENABLE_LOADER_TYPE + if (!Do_CriticalSection_Enter(Out_p->TxCriticalSection)) { +#ifdef CFG_ENABLE_LOADER_TYPE + ReRun = TRUE; + SavedState = Out_p->State; + A_(printf("r15_network_layer.c (%d) Failed to lock CriticalSection code! \n", __LINE__);) + return E_CS_LOCK_FAILED; +#else return ReturnValue; +#endif // CFG_ENABLE_LOADER_TYPE } switch (Out_p->State) { @@ -341,13 +354,14 @@ ErrorCode_e R15_Network_TransmiterHandler(Communication_t *Communication_p) Out_p->State = SEND_HEADER; } else { //Do_CommunicationInternalErrorHandler(E_RETRANSMITION_FAILED); - return E_RETRANSMITION_FAILED; + ReturnValue = E_RETRANSMITION_FAILED; + break; } /* FALLTHROUGH */ case SEND_HEADER: #ifdef CFG_ENABLE_LOADER_TYPE - HeaderStartInBuffer_p = Out_p->Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER; + HeaderStartInBuffer_p = Out_p->Packet_p->Buffer_p; if (Out_p->Packet_p->Header.ExtendedHeaderLength == COMMAND_EXTENDED_HEADER_LENGTH) { ExtHdrLen = ALIGNED_COMMAND_EXTENDED_HEADER_LENGTH; @@ -381,7 +395,7 @@ ErrorCode_e R15_Network_TransmiterHandler(Communication_t *Communication_p) #endif - if (E_SUCCESS == Communication_p->CommunicationDevice_p->Write((Out_p->Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER), + if (E_SUCCESS == Communication_p->CommunicationDevice_p->Write((Out_p->Packet_p->Buffer_p), ContinuousBufferLength, R15_Network_WriteCallback, Communication_p->CommunicationDevice_p)) { C_(printf("r15_network_layer.c (%d) Header Sent to comm device! \n", __LINE__);) } else { @@ -397,7 +411,7 @@ ErrorCode_e R15_Network_TransmiterHandler(Communication_t *Communication_p) break; case SEND_EX_HEADER: - ExHeaderStartInBuffer_p = Out_p->Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER + ALIGNED_HEADER_LENGTH; + ExHeaderStartInBuffer_p = Out_p->Packet_p->Buffer_p + ALIGNED_HEADER_LENGTH; if (Out_p->Packet_p->Header.ExtendedHeaderLength == COMMAND_EXTENDED_HEADER_LENGTH) { ExtHdrLen = ALIGNED_COMMAND_EXTENDED_HEADER_LENGTH; @@ -451,7 +465,7 @@ ErrorCode_e R15_Network_TransmiterHandler(Communication_t *Communication_p) } if (RegisterRetransmission) { - if (NULL != Out_p->Packet_p->Timer_p) { + if (0 != Out_p->Packet_p->Timer.Time) { C_(printf("r15_network_layer.c (%d) Register retransmission\n", __LINE__);) (void)R15_Network_RegisterRetransmission(Communication_p, Out_p->Packet_p); } @@ -459,6 +473,25 @@ ErrorCode_e R15_Network_TransmiterHandler(Communication_t *Communication_p) Do_CriticalSection_Leave(Out_p->TxCriticalSection); +#ifdef CFG_ENABLE_LOADER_TYPE + + if (TRUE == ReRun) { + ReRun = FALSE; + Out_p->State = SavedState; + + ExHeaderStartInBuffer_p = NULL; + HeaderStartInBuffer_p = NULL; + IsBufferContinuous = FALSE; + ContinuousBufferLength = 0; + RegisterRetransmission = FALSE; + ExtHdrLen = 0; + Aligned_Length = 0; + + goto StartTramsmitter; + } + +#endif // CFG_ENABLE_LOADER_TYPE + return ReturnValue; } @@ -477,27 +510,26 @@ ErrorCode_e R15_Network_CancelRetransmission(const Communication_t *const Commun uint32 Index = 0; do { - if ((R15_NETWORK(Communication_p)->RetransmissionList[Index] != NULL) && (R15_NETWORK(Communication_p)->RetransmissionList[Index]->Key == UniqueKey)) { - (void)TIMER(Communication_p, TimerRelease_Fn)(OBJECT_TIMER(Communication_p), R15_NETWORK(Communication_p)->RetransmissionList[Index]->TimerKey); + if ((TRUE == R15_NETWORK(Communication_p)->RetransmissionList[Index].InUse) && (R15_NETWORK(Communication_p)->RetransmissionList[Index].Key == UniqueKey)) { + R15_NETWORK(Communication_p)->RetransmissionList[Index].InUse = FALSE; + + (void)TIMER(Communication_p, TimerRelease_Fn)(OBJECT_TIMER(Communication_p), R15_NETWORK(Communication_p)->RetransmissionList[Index].TimerKey); - free(R15_NETWORK(Communication_p)->RetransmissionList[Index]->Packet_p->Timer_p); - R15_NETWORK(Communication_p)->RetransmissionList[Index]->Packet_p->Timer_p = NULL; - ReturnValue = R15_Network_PacketRelease(Communication_p, R15_NETWORK(Communication_p)->RetransmissionList[Index]->Packet_p); + memset(&(R15_NETWORK(Communication_p)->RetransmissionList[Index].Packet_p->Timer), 0, sizeof(Timer_t)); + + ReturnValue = R15_Network_PacketRelease(Communication_p, R15_NETWORK(Communication_p)->RetransmissionList[Index].Packet_p); if (E_SUCCESS != ReturnValue) { A_(printf("r15_network_layer.c(%d): Packet release failed!\n", __LINE__);) return ReturnValue; } - free(R15_NETWORK(Communication_p)->RetransmissionList[Index]); - R15_NETWORK(Communication_p)->RetransmissionList[Index] = NULL; R15_NETWORK(Communication_p)->RetransmissionListCount--; for (; Index < R15_NETWORK(Communication_p)->RetransmissionListCount; Index++) { R15_NETWORK(Communication_p)->RetransmissionList[Index] = R15_NETWORK(Communication_p)->RetransmissionList[Index + 1]; } - R15_NETWORK(Communication_p)->RetransmissionList[Index] = NULL; ReturnValue = E_SUCCESS; break; } @@ -661,6 +693,10 @@ void R15_Network_WriteCallback(const void *Data_p, const uint32 Length, void *Pa Communication_t *Communication_p = (Communication_t *)(((CommunicationDevice_t *)Param_p)->Object_p); R15_Outbound_t *Out_p = &(R15_NETWORK(Communication_p)->Outbound); BulkExtendedHeader_t ExtendedHeader = {0}; +#ifdef CFG_ENABLE_LOADER_TYPE + ErrorCode_e ReturnValue = E_GENERAL_COMMUNICATION_ERROR; + R15_OutboundState_t SavedState = Out_p->State; +#endif // CFG_ENABLE_LOADER_TYPE B_(printf("r15_network_layer.c (%d): Device write finished!! \n", __LINE__);) if (SENDING_HEADER == Out_p->State) { @@ -668,7 +704,7 @@ void R15_Network_WriteCallback(const void *Data_p, const uint32 Length, void *Pa } else if (SENDING_EX_HEADER == Out_p->State) { Out_p->State = SEND_PAYLOAD; } else if (SENDING_PAYLOAD == Out_p->State) { - if (NULL == Out_p->Packet_p->Timer_p) { + if (0 == Out_p->Packet_p->Timer.Time) { if (Out_p->Packet_p->Header.Protocol == BULK_PROTOCOL) { R15_DeserializeBulkExtendedHeader(&ExtendedHeader, Out_p->Packet_p->ExtendedHeader_p); } @@ -684,7 +720,11 @@ void R15_Network_WriteCallback(const void *Data_p, const uint32 Length, void *Pa #ifdef CFG_ENABLE_LOADER_TYPE - if (E_SUCCESS != R15_Network_TransmiterHandler(Communication_p)) { + ReturnValue = R15_Network_TransmiterHandler(Communication_p); + + if (E_CS_LOCK_FAILED == ReturnValue) { + Out_p->State = SavedState; + } else if (E_SUCCESS != ReturnValue) { R15_NETWORK(Communication_p)->Outbound.LCM_Error = E_GENERAL_COMMUNICATION_ERROR; } @@ -773,7 +813,7 @@ static ErrorCode_e R15_Network_ReceiveExtendedHeader(Communication_t *Communicat VERIFY(NULL != In_p->Packet_p, E_FAILED_TO_FIND_COMM_BUFFER); In_p->Packet_p->Header = R15Header; - In_p->Packet_p->ExtendedHeader_p = In_p->Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER + ALIGNED_HEADER_LENGTH; + In_p->Packet_p->ExtendedHeader_p = In_p->Packet_p->Buffer_p + ALIGNED_HEADER_LENGTH; SET_PACKET_FLAGS(In_p->Packet_p, PACKET_RX_STATE_MASK, BUF_HDR_CRC_OK); if (In_p->Packet_p->Header.ExtendedHeaderLength == COMMAND_EXTENDED_HEADER_LENGTH) { @@ -782,7 +822,7 @@ static ErrorCode_e R15_Network_ReceiveExtendedHeader(Communication_t *Communicat In_p->Packet_p->Payload_p = In_p->Packet_p->ExtendedHeader_p + ALIGNED_BULK_EXTENDED_HEADER_LENGTH; } - memcpy(In_p->Packet_p->Buffer_p + HEADER_OFFSET_IN_BUFFER, &In_p->Packet_p->Header, HEADER_LENGTH); + memcpy(In_p->Packet_p->Buffer_p, &In_p->Packet_p->Header, HEADER_LENGTH); memcpy(In_p->Packet_p->ExtendedHeader_p, In_p->Target_p, In_p->Header.ExtendedHeaderLength); In_p->Target_p = In_p->Packet_p->Payload_p; @@ -877,54 +917,46 @@ static ErrorCode_e R15_Network_ReceivePayload(Communication_t *Communication_p) static ErrorCode_e R15_Network_RegisterRetransmission(Communication_t *Communication_p, PacketMeta_t *Packet_p) { - int i; - int Index; - ErrorCode_e ReturnValue = E_SUCCESS; - static RetransmissionContext_t *R_Ctx_p = NULL; + int i = 0; + int Index = 0; + ErrorCode_e ReturnValue = E_RETRANSMISSION_LIST_FULL; if (R15_NETWORK(Communication_p)->RetransmissionListCount < MAX_SIZE_RETRANSMISSION_LIST) { - if (NULL == Packet_p->Timer_p->HandleFunction_p) { - Packet_p->Timer_p->HandleFunction_p = (HandleFunction_t)R15_Network_RetransmissionCallback; - Packet_p->Timer_p->Param_p = Communication_p; - } - - R_Ctx_p = (RetransmissionContext_t *)malloc(sizeof(RetransmissionContext_t)); - - if (NULL == R_Ctx_p) { - return E_ALLOCATE_FAILED; + if (NULL == Packet_p->Timer.HandleFunction_p) { + Packet_p->Timer.HandleFunction_p = (HandleFunction_t)R15_Network_RetransmissionCallback; + Packet_p->Timer.Param_p = Communication_p; } - R_Ctx_p->TimerKey = TIMER(Communication_p, TimerGet_Fn)(OBJECT_TIMER(Communication_p), Packet_p->Timer_p); - R_Ctx_p->Timeout = Packet_p->Timer_p->Time; - R_Ctx_p->Packet_p = Packet_p; - R_Ctx_p->Key = R15_Network_CreateUniqueKey(Packet_p, (uint8)(*(R_Ctx_p->Packet_p->ExtendedHeader_p + sizeof(uint16)))); - - Index = 0; - C_(printf("r15_network_layer.c (%d) Key(%d) TKey(%d) \n", __LINE__, R_Ctx_p->Key, R_Ctx_p->TimerKey);) - do { - if (NULL != R15_NETWORK(Communication_p)->RetransmissionList[Index]) { - if (R_Ctx_p->Timeout < TIMER(Communication_p, ReadTime_Fn)(OBJECT_TIMER(Communication_p), R15_NETWORK(Communication_p)->RetransmissionList[Index]->TimerKey)) { + if (TRUE == R15_NETWORK(Communication_p)->RetransmissionList[Index].InUse) { + if (Packet_p->Timer.Time < TIMER(Communication_p, ReadTime_Fn)(OBJECT_TIMER(Communication_p), R15_NETWORK(Communication_p)->RetransmissionList[Index].TimerKey)) { i = R15_NETWORK(Communication_p)->RetransmissionListCount; for (; Index < i; i--) { R15_NETWORK(Communication_p)->RetransmissionList[i] = R15_NETWORK(Communication_p)->RetransmissionList[i - 1]; } - R15_NETWORK(Communication_p)->RetransmissionList[Index] = R_Ctx_p; - R_Ctx_p = NULL; - R15_NETWORK(Communication_p)->RetransmissionListCount++; break; } Index++; } else { - R15_NETWORK(Communication_p)->RetransmissionList[Index] = R_Ctx_p; - R_Ctx_p = NULL; - R15_NETWORK(Communication_p)->RetransmissionListCount++; break; } } while (Index < MAX_SIZE_RETRANSMISSION_LIST); + + if (Index != MAX_SIZE_RETRANSMISSION_LIST) { + R15_NETWORK(Communication_p)->RetransmissionList[Index].TimerKey = TIMER(Communication_p, TimerGet_Fn)(OBJECT_TIMER(Communication_p), &(Packet_p->Timer)); + R15_NETWORK(Communication_p)->RetransmissionList[Index].Timeout = Packet_p->Timer.Time; + R15_NETWORK(Communication_p)->RetransmissionList[Index].Packet_p = Packet_p; + R15_NETWORK(Communication_p)->RetransmissionList[Index].Key = R15_Network_CreateUniqueKey(Packet_p, (uint8)(*(Packet_p->ExtendedHeader_p + sizeof(uint16)))); + R15_NETWORK(Communication_p)->RetransmissionList[Index].InUse = TRUE; + R15_NETWORK(Communication_p)->RetransmissionListCount++; + C_(printf("r15_network_layer.c (%d) Key(%d) TKey(%d) \n", __LINE__, (R15_NETWORK(Communication_p)->RetransmissionList[Index].Key), (R15_NETWORK(Communication_p)->RetransmissionList[Index].TimerKey));) + } + + ReturnValue = E_SUCCESS; + } else { A_(printf("r15_network_layer.c (%d) ** Err: Retransmission List is full! ** \n", __LINE__);) } @@ -938,9 +970,8 @@ static void R15_Network_RetransmissionCallback(Communication_t *Communication_p, uint32 Index = 0; /* get first in list of packets for retransmission and remove */ - if (NULL != R15_NETWORK(Communication_p)->RetransmissionList[Index]) { - free(R15_NETWORK(Communication_p)->RetransmissionList[Index]); - R15_NETWORK(Communication_p)->RetransmissionList[Index] = NULL; + if (TRUE == R15_NETWORK(Communication_p)->RetransmissionList[Index].InUse) { + R15_NETWORK(Communication_p)->RetransmissionList[Index].InUse = FALSE; } if (R15_NETWORK(Communication_p)->RetransmissionListCount > 0) { @@ -951,7 +982,7 @@ static void R15_Network_RetransmissionCallback(Communication_t *Communication_p, R15_NETWORK(Communication_p)->RetransmissionList[Index] = R15_NETWORK(Communication_p)->RetransmissionList[Index + 1]; } - R15_NETWORK(Communication_p)->RetransmissionList[Index] = NULL; + R15_NETWORK(Communication_p)->RetransmissionList[Index].InUse = FALSE; /* enqueue the packet for retransmission */ (void)QUEUE(Communication_p, FifoEnqueue_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Outbound_p, Packet_p); diff --git a/lcmodule/source/cnh1606344_ldr_communication_module/config/command_marshal.xsl b/lcmodule/source/cnh1606344_ldr_communication_module/config/command_marshal.xsl index d4a8672..e0a2302 100644 --- a/lcmodule/source/cnh1606344_ldr_communication_module/config/command_marshal.xsl +++ b/lcmodule/source/cnh1606344_ldr_communication_module/config/command_marshal.xsl @@ -197,6 +197,7 @@ ErrorCode_e Do_CEH_Call(void *Object_p, CommandData_t *CmdData_p) ErrorCode_e AuditResponse = CommandAudit(CmdData_p); CommandData_t CmdData = {0}; uint32 PLSize = sizeof(ErrorCode_e); + uint8 AuditResponseData[PLSize]; if (E_SUCCESS != AuditResponse) { @@ -207,31 +208,18 @@ ErrorCode_e Do_CEH_Call(void *Object_p, CommandData_t *CmdData_p) CmdData.ApplicationNr = CmdData_p->ApplicationNr; CmdData.SessionNr = CmdData_p->SessionNr; CmdData.Payload.Size = PLSize; - CmdData.Payload.Data_p = NULL; - CmdData.Payload.Data_p = (uint8 *)malloc(PLSize); - - if (NULL == CmdData.Payload.Data_p) { - A_(printf("command_marshal.c (%d): ** memory allocation failed! **\n", __LINE__);) - return E_ALLOCATE_FAILED; - } + CmdData.Payload.Data_p = AuditResponseData; Data_p = CmdData.Payload.Data_p; put_uint32(&Data_p, AuditResponse); Status = Do_R15_Command_Send(GlobalCommunication_p, &CmdData); - if (NULL != CmdData.Payload.Data_p) { - - free(CmdData.Payload.Data_p); - } - if (E_SUCCESS != Status) { - return Status; } if (E_UNSUPPORTED_CMD == AuditResponse) { - Status = Do_System_ShutDownImpl(CmdData.SessionNr); } diff --git a/lcmodule/source/cnh1606344_ldr_communication_module/config/common.xsl b/lcmodule/source/cnh1606344_ldr_communication_module/config/common.xsl index 9919b3d..a0b879a 100644 --- a/lcmodule/source/cnh1606344_ldr_communication_module/config/common.xsl +++ b/lcmodule/source/cnh1606344_ldr_communication_module/config/common.xsl @@ -81,9 +81,9 @@ put_block(&Data_p, , ); - if ( != NULL) { - put_block(&Data_p, , PLSize); - } + if ( != NULL) { + put_block(&Data_p, , PLSize); + } serialize_device_entries(&Data_p, , ); @@ -106,7 +106,7 @@ PLSize += ; - PLSize += PLSize = * sizeof(SupportedCommand_t); + PLSize += PLSize = * sizeof(SupportedCommand_t); PLSize += get_device_entries_len(, ); diff --git a/lcmodule/source/cnh1606344_ldr_communication_module/config/error_codes.xml b/lcmodule/source/cnh1606344_ldr_communication_module/config/error_codes.xml index 22251d4..459edac 100644 --- a/lcmodule/source/cnh1606344_ldr_communication_module/config/error_codes.xml +++ b/lcmodule/source/cnh1606344_ldr_communication_module/config/error_codes.xml @@ -17,6 +17,7 @@ Try to reset the loader and if problem still exist, report this error. Try to reset the loader and if still exist the problem, report this error. Try to reset the loader and if still exist the problem, report this error. + Loader internal error which should be handled in place where code is executed. Try to reset the loader and if still exist the problem, report this error.