diff options
author | xmarvla <vlatko.markovic@seavus.com> | 2011-06-15 14:03:08 +0200 |
---|---|---|
committer | Viktor Mladenovski <viktor.mladenovski@seavus.com> | 2011-08-17 22:06:38 +0200 |
commit | c9d1f9613e3ac18d5dd3b9432646e289bb88cec9 (patch) | |
tree | 086b18dc26d75f052b840d818877efb79f5791ca /lcmodule/source | |
parent | 12da7d3751c8b7bd088587c8323123019680efff (diff) |
Add support for M730 Platform
Added new command: System_StartCommRelay (For M730 platform).
New state machine in Protrom Network Transmitter Handler.
Small changes in Z protocol due to implementation of
Communication Relay in Hassium Loaders.
Add implementation for CriticalSection synchronization mechanism.
ST-Ericsson ID: 325251
ST-Ericsson FOSS-OUT ID: STETL-FOSS-OUT-10204
Depends-On: I0d34a2c4504a2b52ff5ab5efd2da36d8d1fa9816
Change-Id: I0d34a2c4504a2b52ff5ab5efd2da36d8d1fa9816
Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/20944
Reviewed-by: QATOOLS
Reviewed-by: Vlatko PISTOLOV <vlatko.pistolov@seavus.com>
Tested-by: Vlatko PISTOLOV <vlatko.pistolov@seavus.com>
Diffstat (limited to 'lcmodule/source')
19 files changed, 618 insertions, 78 deletions
diff --git a/lcmodule/source/LCM.rc b/lcmodule/source/LCM.rc index 0ec9c41..57344f6 100644 --- a/lcmodule/source/LCM.rc +++ b/lcmodule/source/LCM.rc @@ -69,16 +69,16 @@ BEGIN BEGIN
BLOCK "040904b0"
BEGIN
- VALUE "Comments", "Build date: 2011-05-30"
+ VALUE "Comments", "Build date: 2011-06-15"
VALUE "CompanyName", "ST Ericsson AB"
VALUE "FileDescription", "LCM Dynamic Link Library"
VALUE "FileVersion", "1,0,0,1"
VALUE "InternalName", "LCM"
VALUE "LegalCopyright", "Copyright (C) ST Ericsson 2011"
VALUE "OriginalFilename", "LCM.dll"
- VALUE "PrivateBuild", "http://gerrit.lud.stericsson.com/gerrit/21155"
+ VALUE "PrivateBuild", "http://gerrit.lud.stericsson.com/gerrit/20944"
VALUE "ProductName", "CXA1104507 Loader Communication Module"
- VALUE "ProductVersion", "P1L"
+ VALUE "ProductVersion", "P1N"
END
END
BLOCK "VarFileInfo"
diff --git a/lcmodule/source/LCM.vcproj b/lcmodule/source/LCM.vcproj index 77341b9..6e5714c 100644 --- a/lcmodule/source/LCM.vcproj +++ b/lcmodule/source/LCM.vcproj @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="Windows-1252"?> <VisualStudioProject ProjectType="Visual C++" - Version="8.00" + Version="8,00" Name="LCM" ProjectGUID="{E06F2763-9680-40F7-99CB-4065B1157B67}" RootNamespace="LCM" @@ -42,7 +42,7 @@ <Tool Name="VCCLCompilerTool" Optimization="0" - AdditionalIncludeDirectories=""$(ProjectDir)autogen";"$(ProjectDir)cnh1606344_ldr_communication_module\config";"$(ProjectDir)legacy_compatibility";"$(ProjectDir)cnh1606344_ldr_communication_module\include";"$(ProjectDir)cnh1605721_ldr_security_algorithms\include";"$(ProjectDir)cnh1605720_ldr_time_utilities\include";"$(ProjectDir)cnh1605551_ldr_utilities\include";"$(ProjectDir)cnh1605205_ldr_network_layer\include";"$(ProjectDir)cnh1605204_ldr_transport_layer\include";"$(ProjectDir)cnh1605203_ldr_communication_buffer\include"" + AdditionalIncludeDirectories=""$(ProjectDir)autogen";"$(ProjectDir)cnh1606344_ldr_communication_module\config";"$(ProjectDir)legacy_compatibility";"$(ProjectDir)cnh1606344_ldr_communication_module\include";"$(ProjectDir)cnh1605721_ldr_security_algorithms\include";"$(ProjectDir)cnh1605720_ldr_time_utilities\include";"$(ProjectDir)cnh1605551_ldr_utilities\include";"$(ProjectDir)cnh1605205_ldr_network_layer\include";"$(ProjectDir)cnh1605204_ldr_transport_layer\include";"$(ProjectDir)cnh1605203_ldr_communication_buffer\include";"$(ProjectDir)cnh1605551_ldr_utilities\critical_section"" PreprocessorDefinitions="WIN32;_DEBUG;LCM_EXPORTS;PRINT_A_" RuntimeLibrary="1" UsePrecompiledHeader="0" @@ -121,7 +121,7 @@ /> <Tool Name="VCCLCompilerTool" - AdditionalIncludeDirectories=""$(ProjectDir)autogen";"$(ProjectDir)cnh1606344_ldr_communication_module\config";"$(ProjectDir)legacy_compatibility";"$(ProjectDir)cnh1606344_ldr_communication_module\include";"$(ProjectDir)cnh1605721_ldr_security_algorithms\include";"$(ProjectDir)cnh1605720_ldr_time_utilities\include";"$(ProjectDir)cnh1605551_ldr_utilities\include";"$(ProjectDir)cnh1605205_ldr_network_layer\include";"$(ProjectDir)cnh1605204_ldr_transport_layer\include";"$(ProjectDir)cnh1605203_ldr_communication_buffer\include"" + AdditionalIncludeDirectories=""$(ProjectDir)autogen";"$(ProjectDir)cnh1606344_ldr_communication_module\config";"$(ProjectDir)legacy_compatibility";"$(ProjectDir)cnh1606344_ldr_communication_module\include";"$(ProjectDir)cnh1605721_ldr_security_algorithms\include";"$(ProjectDir)cnh1605720_ldr_time_utilities\include";"$(ProjectDir)cnh1605551_ldr_utilities\include";"$(ProjectDir)cnh1605205_ldr_network_layer\include";"$(ProjectDir)cnh1605204_ldr_transport_layer\include";"$(ProjectDir)cnh1605203_ldr_communication_buffer\include";"$(ProjectDir)cnh1605551_ldr_utilities\critical_section"" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;LCM_EXPORTS" RuntimeLibrary="0" UsePrecompiledHeader="0" @@ -295,6 +295,14 @@ RelativePath=".\cnh1605551_ldr_utilities\source\serialization.c" > </File> + <Filter + Name="critical_section" + > + <File + RelativePath=".\cnh1605551_ldr_utilities\critical_section\critical_section_win32.c" + > + </File> + </Filter> </Filter> </Filter> <Filter @@ -302,6 +310,10 @@ Filter="h;hpp;hxx;hm;inl;inc;xsd" UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" > + <File + RelativePath=".\resource.h" + > + </File> <Filter Name="cnh1606344_ldr_communication_module" > @@ -521,6 +533,18 @@ > </File> </Filter> + <Filter + Name="critical_section" + > + <File + RelativePath=".\cnh1605551_ldr_utilities\critical_section\r_critical_section.h" + > + </File> + <File + RelativePath=".\cnh1605551_ldr_utilities\critical_section\t_critical_section.h" + > + </File> + </Filter> </Filter> <Filter Name="cnh1605720_ldr_time_utilities" @@ -586,7 +610,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating command_ids.h..." - CommandLine="java -classpath ..\tools\xalan-j_2_7_1\xalan.jar org.apache.xalan.xslt.Process -in "$(InputDir)commands.xml" -xsl "$(InputPath)" -out "$(ProjectDir)autogen\command_ids.h" -PARAM target lcm
" + CommandLine="java -classpath ..\tools\xalan-j_2_7_1\xalan.jar org.apache.xalan.xslt.Process -in "$(InputDir)commands.xml" -xsl "$(InputPath)" -out "$(ProjectDir)autogen\command_ids.h" -PARAM target lcm" AdditionalDependencies=""$(InputDir)commands.xml"" Outputs="autogen\command_ids.h" /> @@ -646,7 +670,7 @@ <Tool Name="VCCustomBuildTool" Description="Generating error_codes.h..." - CommandLine="java -classpath "..\tools\xalan-j_2_7_1\xalan.jar" org.apache.xalan.xslt.Process -in "$(InputDir)error_codes.xml" -xsl "$(InputPath)" -out "$(ProjectDir)autogen\error_codes.h"
" + CommandLine="java -classpath "..\tools\xalan-j_2_7_1\xalan.jar" org.apache.xalan.xslt.Process -in "$(InputDir)error_codes.xml" -xsl "$(InputPath)" -out "$(ProjectDir)autogen\error_codes.h"" AdditionalDependencies="$(InputDir)error_codes.xml" Outputs="autogen\error_codes.h" /> diff --git a/lcmodule/source/cnh1605205_ldr_network_layer/include/t_a2_network.h b/lcmodule/source/cnh1605205_ldr_network_layer/include/t_a2_network.h index 6eb8ec5..cdc71d4 100644 --- a/lcmodule/source/cnh1605205_ldr_network_layer/include/t_a2_network.h +++ b/lcmodule/source/cnh1605205_ldr_network_layer/include/t_a2_network.h @@ -17,6 +17,7 @@ * Includes ******************************************************************************/ #include "t_communication_service.h" +#include "t_critical_section.h" #include "t_a2_header.h" /******************************************************************************* @@ -151,8 +152,8 @@ typedef struct { A2_OutboundState_t State; /** Temporary pointer for handling PROTROM packet.*/ A2_PacketMeta_t *Packet_p; - /**< Boolean value for controlling re-entry in transmitter function. */ - boolean InLoad; + /** Synchronization object to avoid parallel access in transmitter function. */ + CriticalSection_t TxCriticalSection; /** Error flag, purposed for error handling.*/ ErrorCode_e LCM_Error; } A2_Outbound_t; diff --git a/lcmodule/source/cnh1605205_ldr_network_layer/include/t_protrom_network.h b/lcmodule/source/cnh1605205_ldr_network_layer/include/t_protrom_network.h index fa5402f..955b589 100644 --- a/lcmodule/source/cnh1605205_ldr_network_layer/include/t_protrom_network.h +++ b/lcmodule/source/cnh1605205_ldr_network_layer/include/t_protrom_network.h @@ -17,6 +17,7 @@ * Includes ******************************************************************************/ #include "t_communication_service.h" +#include "t_critical_section.h" #include "t_protrom_header.h" /******************************************************************************* @@ -39,8 +40,10 @@ typedef enum { /** Defined state of the transmitter */ typedef enum { PROTROM_SEND_IDLE, /**< Transmiter idle state.*/ - PROTROM_SEND_PACKET, /**< Transmiter send packet. */ - PROTROM_SENDING_PACKET /**< Transmiter is in process sending packet.*/ + PROTROM_SEND_HEADER, /**< Transmiter send header. */ + PROTROM_SEND_PAYLOAD, /**< Transmiter send payload. */ + PROTROM_SENDING_HEADER, /**< Transmiter is in process sending header.*/ + PROTROM_SENDING_PAYLOAD /**< Transmiter is in process sending payload.*/ } Protrom_OutboundState_t; /** Structure for the packet meta data type. */ @@ -84,8 +87,8 @@ typedef struct { Protrom_OutboundState_t State; /** Temporary pointer for handling PROTROM packet.*/ Protrom_Packet_t *Packet_p; - /**< Boolean value for controling re-entry in transmiter fucntion. */ - boolean InLoad; + /**< Synchronization object to avoid parallel access in transmitter function. */ + CriticalSection_t TxCriticalSection; } Protrom_Outbound_t; 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 bff1930..5e78ddd 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 @@ -16,6 +16,7 @@ * Includes ******************************************************************************/ #include "t_communication_service.h" +#include "t_critical_section.h" #include "t_r15_header.h" #include "t_time_utilities.h" @@ -273,8 +274,8 @@ typedef struct { R15_OutboundState_t State; /** Temporary pointer for handling PROTROM packet.*/ PacketMeta_t *Packet_p; - /**< Boolean value for controling re-entry in transmiter fucntion. */ - boolean InLoad; + /**< Synchronization object to avoid parallel access in transmitter function. */ + CriticalSection_t TxCriticalSection; /** Error flag, purposed for error handling.*/ ErrorCode_e LCM_Error; } R15_Outbound_t; diff --git a/lcmodule/source/cnh1605205_ldr_network_layer/include/t_z_network.h b/lcmodule/source/cnh1605205_ldr_network_layer/include/t_z_network.h index 4135873..7f66e67 100644 --- a/lcmodule/source/cnh1605205_ldr_network_layer/include/t_z_network.h +++ b/lcmodule/source/cnh1605205_ldr_network_layer/include/t_z_network.h @@ -17,6 +17,7 @@ * Includes ******************************************************************************/ #include "t_communication_service.h" +#include "t_critical_section.h" #include "t_z_header.h" /******************************************************************************* @@ -60,8 +61,8 @@ typedef struct { typedef struct { /**< State of the state machine for handling outgoing Z packets. */ Z_OutboundState_t State; - /**< Boolean value for controling re-entry in transmiter fucntion. */ - boolean InLoad; + /**< Synchronization object to avoid parallel access in transmitter function. */ + CriticalSection_t TxCriticalSection; } Z_Outbound_t; 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; } diff --git a/lcmodule/source/cnh1605551_ldr_utilities/critical_section/critical_section.c b/lcmodule/source/cnh1605551_ldr_utilities/critical_section/critical_section.c new file mode 100755 index 0000000..126d3e7 --- /dev/null +++ b/lcmodule/source/cnh1605551_ldr_utilities/critical_section/critical_section.c @@ -0,0 +1,126 @@ +/******************************************************************************* + * $Copyright ST-Ericsson 2011 $ + ******************************************************************************/ + +/* + * @addtogroup critical_section + * @{ + */ + +/******************************************************************************* + * Includes + ******************************************************************************/ +#include "stdlib.h" +#include "t_basicdefinitions.h" +#include "r_critical_section.h" +#include "r_atomic_functions.h" + +/******************************************************************************* + * File scope types, constants and variables + ******************************************************************************/ +#define CS_LOCKED 1 +#define CS_UNLOCKED 0 +/******************************************************************************* + * Declaration of internal functions + ******************************************************************************/ + +/******************************************************************************* + * Definition of external functions + ******************************************************************************/ +/** + * Perform initialization of Critical Section. + * + * Creates a critical section object and returns pointer to it for later usage + * when it is needed to enter and leave the critical part of the code, + * and destroy the critical section object when not used anymore. + * + * @retval Pointer to initialized critical section object if initialization was + * successful, otherwise NULL. + */ +CriticalSection_t Do_CriticalSection_Create(void) +{ + uint32 *cs = (uint32*)malloc(sizeof(uint32)); + if (NULL != cs) { + *cs = CS_UNLOCKED; + } + return cs; +} + +/** + * Free resources used for Critical Section object. + * + * Free all resources and destroy the critical section object given as parameter + * to the function. + * + * @param [in] CriticalSectionObject Pointer to pointer at the object to be destroyed. + * + * @retval None. + */ +void Do_CriticalSection_Destroy(CriticalSection_t *CriticalSectionObject) +{ + uint32** cs = (uint32**)CriticalSectionObject; + + if (NULL != *cs) { + free(*cs); + *cs = NULL; + } +} + +/** + * Enter to the Critical Section code. + * + * Take ownership over critical section object and execute the part of the code + * covered by the Critical Section object passed as parameter to the function. + * + * @param [in] CriticalSectionObject Pointer to the object used to exclusively + * lock some critical part of the code. + * + * @retval TRUE if Critical Section code entered successfully, otherwise FALSE. + */ +boolean Do_CriticalSection_Enter(CriticalSection_t CriticalSectionObject) +{ + volatile uint32 *cs = (volatile uint32 *)CriticalSectionObject; + if (NULL != cs) { + uint32 cs_status = CS_LOCKED; + cs_status = Do_Atomic_CompareAndSwap(cs, CS_UNLOCKED, CS_LOCKED); + if (CS_UNLOCKED == cs_status) { + return TRUE; + } else { + return FALSE; + } + } + + return TRUE; +} + +/** + * Leave the Critical Section code. + * + * Release the Critical Section object when finished execution to allow someone + * else to execute the code covered by the Critical Section object passed as + * parameter to the function. + * + * @param [in] CriticalSectionObject Pointer to the object used to exclusively + * lock some critical part of the code. + * + * @retval None. + */ +void Do_CriticalSection_Leave(CriticalSection_t CriticalSectionObject) +{ + volatile uint32 *cs = (volatile uint32 *)CriticalSectionObject; + if (NULL != cs) { + uint32 cs_status = CS_UNLOCKED; + cs_status = Do_Atomic_CompareAndSwap(cs, CS_LOCKED, CS_UNLOCKED); + if (CS_LOCKED == cs_status) { + /* SUCCESS */ + } else { + /* FAILED */ + } + } +} + +/******************************************************************************* + * Definition of internal functions + ******************************************************************************/ + +/* @} */ diff --git a/lcmodule/source/cnh1605551_ldr_utilities/critical_section/critical_section_linux.c b/lcmodule/source/cnh1605551_ldr_utilities/critical_section/critical_section_linux.c new file mode 100755 index 0000000..0114a47 --- /dev/null +++ b/lcmodule/source/cnh1605551_ldr_utilities/critical_section/critical_section_linux.c @@ -0,0 +1,121 @@ +/******************************************************************************* + * $Copyright ST-Ericsson 2011 $ + ******************************************************************************/ + +/* + * @addtogroup critical_section + * @{ + */ + +/******************************************************************************* + * Includes + ******************************************************************************/ +#include <stdlib.h> +#include <pthread.h> +#include "t_basicdefinitions.h" +#include "r_critical_section.h" + +/******************************************************************************* + * File scope types, constants and variables + ******************************************************************************/ + +/******************************************************************************* + * Declaration of internal functions + ******************************************************************************/ + +/******************************************************************************* + * Definition of external functions + ******************************************************************************/ +/** + * Perform initialization of Critical Section. + * + * Creates a critical section object and returns pointer to it for later usage + * when it is needed to enter and leave the critical part of the code, + * and destroy the critical section object when not used anymore. + * + * @retval Pointer to initialized critical section object if initialization was + * successful, otherwise NULL. + */ +CriticalSection_t Do_CriticalSection_Create(void) +{ + int result = -1; + pthread_mutex_t* cs = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t)); + + if (NULL != cs) { + result = pthread_mutex_init(cs, NULL); + if (0 != result) { + free(cs); + cs = NULL; + } + } + + return (CriticalSection_t)cs; +} + +/** + * Free resources used for Critical Section object. + * + * Free all resources and destroy the critical section object given as parameter + * to the function. + * + * @param [in] CriticalSectionObject Pointer to pointer at the object to be destroyed. + * + * @retval None. + */ +void Do_CriticalSection_Destroy(CriticalSection_t *CriticalSectionObject) +{ + pthread_mutex_t** cs = (pthread_mutex_t**)CriticalSectionObject; + + if (NULL != *cs) { + while (0 != pthread_mutex_destroy(*cs)); + free(*cs); + *cs = NULL; + } +} + +/** + * Enter to the Critical Section code. + * + * Take ownership over critical section object and execute the part of the code + * covered by the Critical Section object passed as parameter to the function. + * + * @param [in] CriticalSectionObject Pointer to the object used to exclusively + * lock some critical part of the code. + * + * @retval TRUE if Critical Section code entered successfully, otherwise FALSE. + */ +boolean Do_CriticalSection_Enter(CriticalSection_t CriticalSectionObject) +{ + pthread_mutex_t* cs = (pthread_mutex_t*)CriticalSectionObject; + if (NULL != cs) { + while (0 != pthread_mutex_lock(cs)); + } + + return TRUE; +} + +/** + * Leave the Critical Section code. + * + * Release the Critical Section object when finished execution to allow someone + * else to execute the code covered by the Critical Section object passed as + * parameter to the function. + * + * @param [in] CriticalSectionObject Pointer to the object used to exclusively + * lock some critical part of the code. + * + * @retval None. + */ +void Do_CriticalSection_Leave(CriticalSection_t CriticalSectionObject) +{ + pthread_mutex_t* cs = (pthread_mutex_t*)CriticalSectionObject; + if (NULL != cs) { + while (0 != pthread_mutex_unlock(cs)); + } +} + +/******************************************************************************* + * Definition of internal functions + ******************************************************************************/ + +/* @} */ diff --git a/lcmodule/source/cnh1605551_ldr_utilities/critical_section/critical_section_win32.c b/lcmodule/source/cnh1605551_ldr_utilities/critical_section/critical_section_win32.c new file mode 100755 index 0000000..49e93fc --- /dev/null +++ b/lcmodule/source/cnh1605551_ldr_utilities/critical_section/critical_section_win32.c @@ -0,0 +1,111 @@ +/******************************************************************************* + * $Copyright ST-Ericsson 2011 $ + ******************************************************************************/ + +/* + * @addtogroup critical_section + * @{ + */ + +/******************************************************************************* + * Includes + ******************************************************************************/ +#include <windows.h> +#include "r_critical_section.h" + +/******************************************************************************* + * File scope types, constants and variables + ******************************************************************************/ + +/******************************************************************************* + * Declaration of internal functions + ******************************************************************************/ + +/******************************************************************************* + * Definition of external functions + ******************************************************************************/ +/** + * Perform initialization of Critical Section. + * + * Creates a critical section object and returns pointer to it for later usage + * when it is needed to enter and leave the critical part of the code, + * and destroy the critical section object when not used anymore. + * + * @retval Pointer to initialized critical section object if initialization was + * successful, otherwise NULL. + */ +CriticalSection_t Do_CriticalSection_Create(void) +{ + CRITICAL_SECTION* cs = (CRITICAL_SECTION*)malloc(sizeof(CRITICAL_SECTION)); + if (NULL != cs) { + InitializeCriticalSection(cs); + } + return (CriticalSection_t)cs; +} + +/** + * Free resources used for Critical Section object. + * + * Free all resources and destroy the critical section object given as parameter + * to the function. + * + * @param [in] CriticalSectionObject Pointer to pointer at the object to be destroyed. + * + * @retval None. + */ +void Do_CriticalSection_Destroy(CriticalSection_t *CriticalSectionObject) +{ + CRITICAL_SECTION** cs = (CRITICAL_SECTION**)CriticalSectionObject; + if (NULL != *cs) { + DeleteCriticalSection(*cs); + free(*cs); + *cs = NULL; + } +} + +/** + * Enter to the Critical Section code. + * + * Take ownership over critical section object and execute the part of the code + * covered by the Critical Section object passed as parameter to the function. + * + * @param [in] CriticalSectionObject Pointer to the object used to exclusively + * lock some critical part of the code. + * + * @retval TRUE if Critical Section code entered successfully, otherwise FALSE. + */ +boolean Do_CriticalSection_Enter(CriticalSection_t CriticalSectionObject) +{ + CRITICAL_SECTION* cs = (CRITICAL_SECTION*)CriticalSectionObject; + if (NULL != cs) { + EnterCriticalSection(cs); + } + + return TRUE; +} + +/** + * Leave the Critical Section code. + * + * Release the Critical Section object when finished execution to allow someone + * else to execute the code covered by the Critical Section object passed as + * parameter to the function. + * + * @param [in] CriticalSectionObject Pointer to the object used to exclusively + * lock some critical part of the code. + * + * @retval None. + */ +void Do_CriticalSection_Leave(CriticalSection_t CriticalSectionObject) +{ + CRITICAL_SECTION* cs = (CRITICAL_SECTION*)CriticalSectionObject; + if (NULL != cs) { + LeaveCriticalSection(cs); + } +} + +/******************************************************************************* + * Definition of internal functions + ******************************************************************************/ + +/* @} */ diff --git a/lcmodule/source/cnh1605551_ldr_utilities/critical_section/r_critical_section.h b/lcmodule/source/cnh1605551_ldr_utilities/critical_section/r_critical_section.h new file mode 100755 index 0000000..3a05af4 --- /dev/null +++ b/lcmodule/source/cnh1605551_ldr_utilities/critical_section/r_critical_section.h @@ -0,0 +1,79 @@ +/******************************************************************************* + * $Copyright ST-Ericsson 2011 $ + ******************************************************************************/ +#ifndef _R_CRITITCAL_SECTION_H_ +#define _R_CRITITCAL_SECTION_H_ + +/** + * @addtogroup ldr_utilities + * @{ + * @addtogroup critical_section + * @{ + */ + +/******************************************************************************* + * Includes + ******************************************************************************/ +#include "t_critical_section.h" + +/******************************************************************************* + * File scope types, constants and variables + ******************************************************************************/ + +/******************************************************************************* + * Declaration of functions + ******************************************************************************/ +/** + * Perform initialization of Critical Section. + * + * Creates a critical section object and returns pointer to it for later usage + * when it is needed to enter and leave the critical part of the code, + * and destroy the critical section object when not used anymore. + * + * @retval Pointer to initialized critical section object if initialization was + * successful, otherwise NULL. + */ +CriticalSection_t Do_CriticalSection_Create(void); + +/** + * Free resources used for Critical Section object. + * + * Free all resources and destroy the critical section object given as parameter + * to the function. + * + * @param [in] CriticalSectionObject Pointer to pointer at the object to be destroyed. + * + * @retval None. + */ +void Do_CriticalSection_Destroy(CriticalSection_t *CriticalSectionObject); + +/** + * Enter to the Critical Section code. + * + * Take ownership over critical section object and execute the part of the code + * covered by the Critical Section object passed as parameter to the function. + * + * @param [in] CriticalSectionObject Pointer to the object used to exclusively + * lock some critical part of the code. + * + * @retval TRUE if Critical Section code entered successfully, otherwise FALSE. + */ +boolean Do_CriticalSection_Enter(CriticalSection_t CriticalSectionObject); + +/** + * Leave the Critical Section code. + * + * Release the Critical Section object when finished execution to allow someone + * else to execute the code covered by the Critical Section object passed as + * parameter to the function. + * + * @param [in] CriticalSectionObject Pointer to the object used to exclusively + * lock some critical part of the code. + * + * @retval None. + */ +void Do_CriticalSection_Leave(CriticalSection_t CriticalSectionObject); + +/** @} */ +/** @} */ +#endif /*_R_CRITITCAL_SECTION_H_*/ diff --git a/lcmodule/source/cnh1605551_ldr_utilities/critical_section/t_critical_section.h b/lcmodule/source/cnh1605551_ldr_utilities/critical_section/t_critical_section.h new file mode 100755 index 0000000..17e4ff7 --- /dev/null +++ b/lcmodule/source/cnh1605551_ldr_utilities/critical_section/t_critical_section.h @@ -0,0 +1,27 @@ +/******************************************************************************* + * $Copyright ST-Ericsson 2011 $ + ******************************************************************************/ +#ifndef _T_CRITITCAL_SECTION_H_ +#define _T_CRITITCAL_SECTION_H_ + +/** + * @addtogroup ldr_utilities + * @{ + * @addtogroup critical_section + * @{ + */ + +/******************************************************************************* + * Includes + ******************************************************************************/ +#include "t_basicdefinitions.h" + +/******************************************************************************* + * Types, constants + ******************************************************************************/ +/** Critical Section abstract type definition */ +typedef void* CriticalSection_t; + +/** @} */ +/** @} */ +#endif /*_T_CRITITCAL_SECTION_H_*/ diff --git a/lcmodule/source/cnh1606344_ldr_communication_module/config/commands.xml b/lcmodule/source/cnh1606344_ldr_communication_module/config/commands.xml index 4274666..d37a13e 100644 --- a/lcmodule/source/cnh1606344_ldr_communication_module/config/commands.xml +++ b/lcmodule/source/cnh1606344_ldr_communication_module/config/commands.xml @@ -338,6 +338,32 @@ <value type="buffer" length="iDataSize" name="SIMLockKeysData_p">Data buffer with all SIMLock keys.</value> </output> </command> + + <command number="15" name="System Start Communication Relay" ADbg="false" source="PC" supportedcmdtype="longrunning"> + <interface type="loader" name="StartCommRelay"/> + <documentation> + The Loader shuts down the global communication and enters in a Relay working mode. + </documentation> + <input> + <value type="uint32" name="HostDeviceId">Communication device number of the relay input (host device).</value> + <value type="uint32" name="TargetDeviceId">Communication device number of the relay ouptut (target device).</value> + <value type="uint32" name="ControlDeviceId">Communication device number for the loader commands (control device).</value> + </input> + <output> + </output> + <authentication depandancy="or" factory="TRUE" rd="TRUE" product="TRUE" service="TRUE"> + <value ref="A1"/> + <value ref="CA"/> + </authentication> + <permissions> + <value ref="ServiceModeLevel"/> + <value ref="FlashModeLevel"/> + <value ref="AdvanceServiceModeLevel"/> + <value ref="ProductionModeLevel"/> + <value ref="LimitedProductionModeLevel"/> + <value ref="VeryLimitedProductionModeLevel"/> + </permissions> + </command> </group> <group number="02" name="Flash application" supportedcmdtype="longrunning,shortrunning"> @@ -739,7 +765,7 @@ <value ref="ProductionModeLevel"/> </permissions> </command> - + <command number="3" name="Write and Lock OTP" flagbitsset="trueset" ADbg="false" source="PC" supportedcmdtype="longrunning"> <documentation> Writes and locks the specified bits in the OTP 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 549b369..138c902 100644 --- a/lcmodule/source/cnh1606344_ldr_communication_module/config/error_codes.xml +++ b/lcmodule/source/cnh1606344_ldr_communication_module/config/error_codes.xml @@ -563,6 +563,14 @@ <value number="2755" name="E_HSI_BSC_ERROR_TRANSMIT" fatal="true" short="Transmit buffer is not provided.">Reset loader.Report if problem still exist.</value> <!-- + * Communication Relay Error Codes + * Communication Relay Fatal 2800-2849 + * Communication Relay Non-Fatal 2850-2899 + --> + <value number="2850" name="E_CR_INVALID_STATE" fatal="false" short="Invalid state for commnication relay detected.">Wrong value passed as state for the communication relay and hence it can't be used. Try setting some of predifined communication relay states.</value> + <value number="2851" name="E_CR_NOT_RUNNING" fatal="false" short="Communication Relay is not running.">Communication relay is set in error state or it is not configured properly. Check the relay state. If error occured restart the loader, otherwise try reconfiguring the relay.</value> + + <!-- * Security Library Fatal 4000-4050 * Security Library non-fatal 4051-4250 --> diff --git a/lcmodule/source/cnh1606344_ldr_communication_module/include/r_communication_service.h b/lcmodule/source/cnh1606344_ldr_communication_module/include/r_communication_service.h index 5b23f2d..75306a9 100644 --- a/lcmodule/source/cnh1606344_ldr_communication_module/include/r_communication_service.h +++ b/lcmodule/source/cnh1606344_ldr_communication_module/include/r_communication_service.h @@ -54,7 +54,7 @@ #define OBJECT_HASH(x) x->HashDevice_p->Object_p #define OBJECT_CEH_CALL(x) x->Object_p -extern Communication_t* GlobalCommunication_p; +extern Communication_t *GlobalCommunication_p; extern Communication_t DebugCommunication; @@ -184,7 +184,7 @@ extern "C" * @retval E_INVALID_INPUT_PARAMTERS In case when communicaiton is not Singleton * and Communication_p is NULL pointer. */ - LCM_API ErrorCode_e Do_Communication_GetCommunicationDevice(Communication_t *Communication_p, CommunicationDevice_t** CommunicationDevice_pp); + LCM_API ErrorCode_e Do_Communication_GetCommunicationDevice(Communication_t *Communication_p, CommunicationDevice_t **CommunicationDevice_pp); /** * Function for setting the communication device for the given LCM instance. @@ -200,17 +200,17 @@ extern "C" * @retval E_INVALID_INPUT_PARAMTERS In case when communicaiton is not Singleton * and Communication_p is NULL pointer. */ - LCM_API ErrorCode_e Do_Communication_SetCommunicationDevice(Communication_t *Communication_p, CommunicationDevice_t* CommunicationDevice_p); + LCM_API ErrorCode_e Do_Communication_SetCommunicationDevice(Communication_t *Communication_p, CommunicationDevice_t *CommunicationDevice_p); - /* - * Cancek Receiving new packets - * - * @param [in] Communication_p Communication module context. - * @param [in] PacketsBeforeReceiverStop Number of packets to be send before stopping the receiver. - * - * @retval E_SUCCESS If all packets are successfully handled. A - * protocol family dependant error code otherwise. - */ + /* + * Cancek Receiving new packets + * + * @param [in] Communication_p Communication module context. + * @param [in] PacketsBeforeReceiverStop Number of packets to be send before stopping the receiver. + * + * @retval E_SUCCESS If all packets are successfully handled. A + * protocol family dependant error code otherwise. + */ LCM_API ErrorCode_e Do_Communication_Cancel_Receiver(Communication_t *Communication_p, uint8 PacketsBeforeReceiverStop); #ifdef __cplusplus diff --git a/lcmodule/source/resource.h b/lcmodule/source/resource.h index e894c26..e7c0c12 100644 --- a/lcmodule/source/resource.h +++ b/lcmodule/source/resource.h @@ -1,16 +1,10 @@ -/****************************************************************************** -* -* Copyright (C) ST-Ericsson SA 2011 -* License terms: 3-clause BSD license -* -******************************************************************************/ - //{{NO_DEPENDENCIES}} // Microsoft Visual C++ generated include file. // Used by LCM.rc +// // Next default values for new objects -// +// #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 101 |