diff options
Diffstat (limited to 'lcmodule/source/cnh1605205_ldr_network_layer/source')
4 files changed, 57 insertions, 39 deletions
diff --git a/lcmodule/source/cnh1605205_ldr_network_layer/source/a2_network.c b/lcmodule/source/cnh1605205_ldr_network_layer/source/a2_network.c index 19d7800..886ee46 100644 --- a/lcmodule/source/cnh1605205_ldr_network_layer/source/a2_network.c +++ b/lcmodule/source/cnh1605205_ldr_network_layer/source/a2_network.c @@ -27,6 +27,7 @@ #include "r_communication_service.h" #include "r_debug.h" #include "r_debug_macro.h" +#include "r_critical_section.h" #ifdef WIN32 #include <windows.h> @@ -70,7 +71,7 @@ ErrorCode_e A2_Network_Initialize(Communication_t *Communication_p) /* Simulate a finished read to get the inbound state-machine going. */ A2_Network_ReadCallback(NULL, 0, Communication_p); - A2_NETWORK(Communication_p)->Outbound.InLoad = FALSE; + A2_NETWORK(Communication_p)->Outbound.TxCriticalSection = Do_CriticalSection_Create(); #ifdef CFG_ENABLE_LOADER_TYPE (void)QUEUE(Communication_p, Fifo_SetCallback_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Outbound_p, QUEUE_NONEMPTY, A2_QueueCallback, Communication_p); @@ -114,6 +115,8 @@ ErrorCode_e A2_Network_Shutdown(const Communication_t *const Communication_p) ReturnValue = A2_Network_PacketRelease(Communication_p, (A2_PacketMeta_t *)QUEUE(Communication_p, FifoDequeue_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Inbound_p)); } + Do_CriticalSection_Destroy(&(A2_NETWORK(Communication_p)->Outbound.TxCriticalSection)); + ErrorExit: return ReturnValue; } @@ -476,12 +479,10 @@ ErrorCode_e A2_Network_TransmiterHandler(Communication_t *Communication_p) ErrorCode_e ReturnValue = E_SUCCESS; A2_Outbound_t *Out_p = &(A2_NETWORK(Communication_p)->Outbound); - if (Out_p->InLoad) { - return E_SUCCESS; + if(!Do_CriticalSection_Enter(Out_p->TxCriticalSection)) { + return ReturnValue; } - Out_p->InLoad = TRUE; - switch (Out_p->State) { case A2_SEND_IDLE: /* check retransmission count before send */ @@ -541,7 +542,7 @@ ErrorCode_e A2_Network_TransmiterHandler(Communication_t *Communication_p) break; } - Out_p->InLoad = FALSE; + Do_CriticalSection_Leave(Out_p->TxCriticalSection); return ReturnValue; } diff --git a/lcmodule/source/cnh1605205_ldr_network_layer/source/protrom_network.c b/lcmodule/source/cnh1605205_ldr_network_layer/source/protrom_network.c index cce7a65..0e52519 100644 --- a/lcmodule/source/cnh1605205_ldr_network_layer/source/protrom_network.c +++ b/lcmodule/source/cnh1605205_ldr_network_layer/source/protrom_network.c @@ -26,6 +26,7 @@ #include "r_communication_service.h" #include "r_debug.h" #include "r_debug_macro.h" +#include "r_critical_section.h" #ifdef WIN32 #include <windows.h> @@ -63,6 +64,7 @@ static void Protrom_QueueCallback(const void *const Queue_p, void *Param_p); ErrorCode_e Protrom_Network_Initialize(Communication_t *Communication_p) { memset(PROTROM_NETWORK(Communication_p), 0, sizeof(Protrom_NetworkContext_t)); + PROTROM_NETWORK(Communication_p)->Outbound.TxCriticalSection = Do_CriticalSection_Create(); /* Simulate a finished read to get the inbound state-machine going. */ Protrom_Network_ReadCallback(NULL, 0, Communication_p); @@ -97,6 +99,8 @@ ErrorCode_e Protrom_Network_Shutdown(const Communication_t *const Communication_ (void)QUEUE(Communication_p, Fifo_SetCallback_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Inbound_p, QUEUE_NONEMPTY, NULL, NULL); (void)QUEUE(Communication_p, Fifo_SetCallback_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Inbound_p, QUEUE_EMPTY, NULL, NULL); + Do_CriticalSection_Destroy(&(PROTROM_NETWORK(Communication_p)->Outbound.TxCriticalSection)); + return E_SUCCESS; } @@ -141,6 +145,9 @@ void Protrom_Network_ReadCallback(const void *Data_p, const uint32 Length, void case PROTROM_RECEIVE_PAYLOAD: ReturnValue = Protrom_Network_ReceivePayload(Communication_p); + if((PROTROM_NETWORK(Communication_p)->Inbound.StopTransfer) && (0 == PROTROM_NETWORK(Communication_p)->Inbound.PacketsBeforeReceiverStop)) { + PROTROM_NETWORK(Communication_p)->Inbound.ReqData = 0; + } break; default: @@ -231,18 +238,20 @@ void Protrom_Network_WriteCallback(const void *Data_p, const uint32 Length, void { Communication_t *Communication_p = (Communication_t *)Param_p; Protrom_Outbound_t *Out_p = &(PROTROM_NETWORK(Communication_p)->Outbound); + if (Out_p->State == PROTROM_SENDING_PAYLOAD) { + if (NULL != Out_p->Packet_p) { + if (NULL != Out_p->Packet_p->Buffer_p) { + free(Out_p->Packet_p->Buffer_p); + } - if (NULL != Out_p->Packet_p) { - if (NULL != Out_p->Packet_p->Buffer_p) { - free(Out_p->Packet_p->Buffer_p); + free(Out_p->Packet_p); + Out_p->Packet_p = NULL; } - - free(Out_p->Packet_p); - Out_p->Packet_p = NULL; + Out_p->State = PROTROM_SEND_IDLE; + } + else if (Out_p->State == PROTROM_SENDING_HEADER) { + Out_p->State = PROTROM_SEND_PAYLOAD; } - - Out_p->State = PROTROM_SEND_IDLE; - /* check for more stuff to send. */ (void)Protrom_Network_TransmiterHandler(Communication_p); } @@ -314,45 +323,52 @@ static ErrorCode_e Protrom_Network_ReceivePayload(Communication_t *Communication static ErrorCode_e Protrom_Network_TransmiterHandler(Communication_t *Communication_p) { - Protrom_Outbound_t *Out_p = &(PROTROM_NETWORK(Communication_p)->Outbound); + volatile Protrom_Outbound_t *Out_p = &(PROTROM_NETWORK(Communication_p)->Outbound); - if (Out_p->InLoad) { + if (!Do_CriticalSection_Enter(Out_p->TxCriticalSection)) { return E_SUCCESS; } - Out_p->InLoad = TRUE; - switch (Out_p->State) { case PROTROM_SEND_IDLE: Out_p->Packet_p = (Protrom_Packet_t *)QUEUE(Communication_p, FifoDequeue_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Outbound_p); if (NULL != Out_p->Packet_p) { /* get next packet for transmiting */ - Out_p->State = PROTROM_SEND_PACKET; + Out_p->State = PROTROM_SEND_HEADER; } else { break; } /* FALLTHROUGH */ - case PROTROM_SEND_PACKET: - Out_p->State = PROTROM_SENDING_PACKET; + case PROTROM_SEND_HEADER: + Out_p->State = PROTROM_SENDING_HEADER; if (E_SUCCESS != Communication_p->CommunicationDevice_p->Write(Out_p->Packet_p->Buffer_p, - PROTROM_HEADER_LENGTH + Out_p->Packet_p->Header.PayloadLength + PROTROM_CRC_LENGTH, + PROTROM_HEADER_LENGTH, Protrom_Network_WriteCallback, Communication_p)) { + Out_p->State = PROTROM_SEND_HEADER; + break; + } + + case PROTROM_SENDING_HEADER: + break; + case PROTROM_SEND_PAYLOAD: + Out_p->State = PROTROM_SENDING_PAYLOAD; + if (E_SUCCESS != Communication_p->CommunicationDevice_p->Write(Out_p->Packet_p->Buffer_p + PROTROM_HEADER_LENGTH, + Out_p->Packet_p->Header.PayloadLength + PROTROM_CRC_LENGTH, Protrom_Network_WriteCallback, Communication_p)) { - Out_p->State = PROTROM_SEND_PACKET; + Out_p->State = PROTROM_SEND_PAYLOAD; break; } /* FALLTHROUGH */ - - case PROTROM_SENDING_PACKET: + case PROTROM_SENDING_PAYLOAD: break; } - Out_p->InLoad = FALSE; + Do_CriticalSection_Leave(Out_p->TxCriticalSection); return E_SUCCESS; } 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 bc18821..85be0a2 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 @@ -27,6 +27,7 @@ #include "r_r15_header.h" #include "r_bulk_protocol.h" #include "r_command_protocol.h" +#include "r_critical_section.h" #ifdef CFG_ENABLE_MEASUREMENT_TOOL #include "r_measurement_tool.h" @@ -82,10 +83,10 @@ static PacketMeta_t *R15_Network_GetAvailableMetaPacket(void); ErrorCode_e R15_Network_Initialize(Communication_t *Communication_p) { memset(R15_NETWORK(Communication_p), 0, sizeof(R15_NetworkContext_t)); + R15_NETWORK(Communication_p)->Outbound.TxCriticalSection = Do_CriticalSection_Create(); /* Simulate a finished read to get the inbound state-machine going. */ R15_Network_ReadCallback(NULL, 0, Communication_p); - R15_NETWORK(Communication_p)->Outbound.InLoad = FALSE; #ifdef CFG_ENABLE_LOADER_TYPE (void)QUEUE(Communication_p, Fifo_SetCallback_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Outbound_p, QUEUE_NONEMPTY, R15_QueueOutCallback, Communication_p); (void)QUEUE(Communication_p, Fifo_SetCallback_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Inbound_p, QUEUE_NONEMPTY, R15_QueueInCallback, Communication_p); @@ -131,6 +132,8 @@ ErrorCode_e R15_Network_Shutdown(const Communication_t *const Communication_p) ReturnValue = R15_Network_PacketRelease(Communication_p, (PacketMeta_t *)QUEUE(Communication_p, FifoDequeue_Fn)(OBJECT_QUEUE(Communication_p), Communication_p->Inbound_p)); } + Do_CriticalSection_Destroy(&(R15_NETWORK(Communication_p)->Outbound.TxCriticalSection)); + ErrorExit: return ReturnValue; } @@ -266,12 +269,10 @@ ErrorCode_e R15_Network_TransmiterHandler(Communication_t *Communication_p) uint32 ExtHdrLen = 0; uint32 Aligned_Length = 0; - if (Out_p->InLoad) { - return E_SUCCESS; + if (!Do_CriticalSection_Enter(Out_p->TxCriticalSection)) { + return ReturnValue; } - Out_p->InLoad = TRUE; - switch (Out_p->State) { case SEND_IDLE: /* check retransmission count before send */ @@ -362,7 +363,7 @@ ErrorCode_e R15_Network_TransmiterHandler(Communication_t *Communication_p) } } - Out_p->InLoad = FALSE; + Do_CriticalSection_Leave(Out_p->TxCriticalSection); return ReturnValue; } diff --git a/lcmodule/source/cnh1605205_ldr_network_layer/source/z_network.c b/lcmodule/source/cnh1605205_ldr_network_layer/source/z_network.c index 54abf46..8d7ef09 100644 --- a/lcmodule/source/cnh1605205_ldr_network_layer/source/z_network.c +++ b/lcmodule/source/cnh1605205_ldr_network_layer/source/z_network.c @@ -23,9 +23,8 @@ #include "r_z_network.h" #include "r_z_protocol.h" #include "r_debug.h" -//#include "r_debug_macro.h" #include "r_communication_service.h" -#include "t_z_protocol.h" +#include "r_critical_section.h" #ifdef WIN32 #include <windows.h> @@ -54,6 +53,8 @@ ErrorCode_e Z_Network_Initialize(Communication_t *Communication_p) memset(Z_NETWORK(Communication_p), 0, sizeof(Z_NetworkContext_t)); + Z_NETWORK(Communication_p)->Outbound.TxCriticalSection = Do_CriticalSection_Create(); + /* Simulate a finished read to get the inbound state-machine going. */ Z_Network_ReadCallback(NULL, 0, Communication_p); @@ -62,6 +63,7 @@ ErrorCode_e Z_Network_Initialize(Communication_t *Communication_p) ErrorCode_e Z_Network_Shutdown(const Communication_t *const Communication_p) { + Do_CriticalSection_Destroy(&(Z_NETWORK(Communication_p)->Outbound.TxCriticalSection)); return E_SUCCESS; } @@ -122,12 +124,10 @@ ErrorCode_e Z_Network_TransmiterHandler(Communication_t *Communication_p, Z_Send uint8 Size = SendingContent_p->Size; Z_Outbound_t *Out_p = &(Z_NETWORK(Communication_p)->Outbound); - if (Out_p->InLoad) { + if (!Do_CriticalSection_Enter(Out_p->TxCriticalSection)) { return E_SUCCESS; } - Out_p->InLoad = TRUE; - switch (Out_p->State) { case Z_SEND_IDLE: /* get next packet for transmiting */ @@ -151,7 +151,7 @@ ErrorCode_e Z_Network_TransmiterHandler(Communication_t *Communication_p, Z_Send } - Out_p->InLoad = FALSE; + Do_CriticalSection_Leave(Out_p->TxCriticalSection); return E_SUCCESS; } |