From c9d1f9613e3ac18d5dd3b9432646e289bb88cec9 Mon Sep 17 00:00:00 2001 From: xmarvla Date: Wed, 15 Jun 2011 14:03:08 +0200 Subject: 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 Tested-by: Vlatko PISTOLOV --- Android.mk | 19 +- lcmodule/Makefile | 10 + lcmodule/source/LCM.rc | 6 +- lcmodule/source/LCM.vcproj | 34 +- .../include/t_a2_network.h | 5 +- .../include/t_protrom_network.h | 11 +- .../include/t_r15_network_layer.h | 5 +- .../include/t_z_network.h | 5 +- .../source/a2_network.c | 13 +- .../source/protrom_network.c | 58 +- .../source/r15_network_layer.c | 13 +- .../source/z_network.c | 12 +- .../critical_section/critical_section.c | 126 ++ .../critical_section/critical_section_linux.c | 121 ++ .../critical_section/critical_section_win32.c | 111 ++ .../critical_section/r_critical_section.h | 79 + .../critical_section/t_critical_section.h | 27 + .../config/commands.xml | 28 +- .../config/error_codes.xml | 8 + .../include/r_communication_service.h | 24 +- lcmodule/source/resource.h | 10 +- lcmodule/win_binaries/LCM.dll | Bin 81920 -> 0 bytes source/CEH/ProtromRpcInterface.cpp | 11 - source/CEH/ProtromRpcInterface.h | 3 - source/CEH/ZRpcInterface.cpp | 13 +- source/CEH/ZRpcInterface.h | 3 +- source/CEH/commands_impl.cpp | 7 + source/LCDriver.cpp | 7 + source/LCDriver.h | 9 + source/LCDriver.rc | 6 +- source/LCDriverMethods.cpp | 85 +- source/LCDriverMethods.h | 3 +- source/LCM/include/c_compiler.h | 19 +- source/LCM/include/c_system.h | 4 +- source/LCM/include/t_basicdefinitions.h | 2 +- source/LCM/include/t_communication_service.h | 14 +- source/LCM/include/t_critical_section.h | 27 + source/LCM/include/t_protrom_network.h | 18 +- source/LCM/include/t_r15_header.h | 3 +- source/LCM/include/t_r15_network_layer.h | 16 +- source/LCM/include/t_time_utilities.h | 2 + source/LcmInterface.cpp | 4 +- source/LcmInterface.h | 4 +- source/config/commands.xml | 27 + source/resource.h | 10 +- source/security_algorithms/SecurityAlgorithms.cpp | 10 +- source/security_algorithms/sha/sha2.cpp | 1538 ++++++++++---------- source/security_algorithms/sha/sha2.h | 222 +-- source/utilities/MemMappedFile.cpp | 9 +- win_binaries/LCDriver_CNH1606432.dll | Bin 172032 -> 0 bytes win_binaries/LCM.dll | Bin 81920 -> 0 bytes 51 files changed, 1754 insertions(+), 1047 deletions(-) create mode 100755 lcmodule/source/cnh1605551_ldr_utilities/critical_section/critical_section.c create mode 100755 lcmodule/source/cnh1605551_ldr_utilities/critical_section/critical_section_linux.c create mode 100755 lcmodule/source/cnh1605551_ldr_utilities/critical_section/critical_section_win32.c create mode 100755 lcmodule/source/cnh1605551_ldr_utilities/critical_section/r_critical_section.h create mode 100755 lcmodule/source/cnh1605551_ldr_utilities/critical_section/t_critical_section.h delete mode 100755 lcmodule/win_binaries/LCM.dll create mode 100755 source/LCM/include/t_critical_section.h delete mode 100755 win_binaries/LCDriver_CNH1606432.dll delete mode 100755 win_binaries/LCM.dll diff --git a/Android.mk b/Android.mk index 939b038..a7dd294 100644 --- a/Android.mk +++ b/Android.mk @@ -99,13 +99,6 @@ XSL_LOCAL_PATH := $(LOCAL_PATH) # Path for the tool used for automatic code generation PRIVATE_CLASSPATH := $(LOCAL_PATH)/lcmodule/tools/xalan-j_2_7_1/xalan.jar org.apache.xalan.xslt.Process -include $(CLEAR_VARS) -LOCAL_MODULE_NAME := libSecurityAlgorithms.a -LOCAL_MODULE_TAGS := optional -LOCAL_MODULE_CLASS := STATIC_LIBRARY -LOCAL_PREBUILT_LIBS:= \ - source/security_algorithms/ARM/$(LOCAL_MODULE_NAME) -include $(BUILD_MULTI_PREBUILT) include $(CLEAR_VARS) LOCAL_MODULE := liblcdriver @@ -160,7 +153,7 @@ LOCAL_SRC_FILES := \ source/utilities/Logger.cpp\ source/utilities/MemMappedFile.cpp\ source/utilities/CaptiveThreadObject.cpp\ - source/utilities/BulkHandler.cpp\ + source/utilities/BulkHandler.cpp\ source/CEH/ProtromRpcInterface.cpp\ source/CEH/commands_impl.cpp\ source/CEH/a2_commands_impl.cpp\ @@ -182,7 +175,9 @@ LOCAL_SRC_FILES := \ source/api_wrappers/linux/CEventObject.cpp\ source/api_wrappers/linux/CWaitableObjectCollection.cpp\ source/api_wrappers/linux/OS.cpp\ - source/LCDriverInterface.cpp + source/LCDriverInterface.cpp\ + source/security_algorithms/SecurityAlgorithms.cpp\ + source/security_algorithms/sha/sha2.cpp LOCAL_C_INCLUDES := \ $(TOP)/external/stlport/stlport\ @@ -195,13 +190,13 @@ LOCAL_C_INCLUDES := \ $(LOCAL_PATH)/source/LCM/include\ $(LOCAL_PATH)/source/security_algorithms\ $(LOCAL_PATH)/source/CEH\ + $(LOCAL_PATH)/source/security_algorithms/sha\ $(LOCAL_AUTO_DIR) -LOCAL_CFLAGS := -Wall -fPIC -fvisibility=hidden -fno-strict-aliasing -DLCDRIVER_EXPORTS +LOCAL_CFLAGS := -Wall -fPIC -fvisibility=hidden -fno-strict-aliasing -DLCDRIVER_EXPORTS -DLITTLE_ENDIAN=1234 -DBIG_ENDIAN=4321 -DBYTE_ORDER=LITTLE_ENDIAN LOCAL_SHARED_LIBRARIES := libc libdl libstlport -LOCAL_WHOLE_STATIC_LIBRARIES := libSecurityAlgorithms LOCAL_PRELINK_MODULE := false include $(BUILD_SHARED_LIBRARY) @@ -263,6 +258,7 @@ LOCAL_SRC_FILES := \ lcmodule/source/cnh1606344_ldr_communication_module/source/z_family.c\ lcmodule/source/cnh1606344_ldr_communication_module/source/r15_family.c\ lcmodule/source/cnh1606344_ldr_communication_module/source/a2_family.c\ + lcmodule/source/cnh1605551_ldr_utilities/critical_section/critical_section_linux.c\ lcmodule/source/serialization.c LOCAL_C_INCLUDES := \ @@ -272,6 +268,7 @@ LOCAL_C_INCLUDES := \ $(LOCAL_PATH)/lcmodule/source/cnh1606344_ldr_communication_module/include/\ $(LOCAL_PATH)/lcmodule/source/cnh1605720_ldr_time_utilities/include/\ $(LOCAL_PATH)/lcmodule/source/cnh1605551_ldr_utilities/include/\ + $(LOCAL_PATH)/lcmodule/source/cnh1605551_ldr_utilities/critical_section/\ $(LOCAL_PATH)/lcmodule/source/cnh1605551_ldr_utilities/communication_abstraction/\ $(LOCAL_PATH)/lcmodule/source/cnh1605203_ldr_communication_buffer/include/\ $(LOCAL_PATH)/lcmodule/source/cnh1605721_ldr_security_algorithms/include/\ diff --git a/lcmodule/Makefile b/lcmodule/Makefile index 2c057e2..d612a1f 100644 --- a/lcmodule/Makefile +++ b/lcmodule/Makefile @@ -59,6 +59,7 @@ LIBSRC :=${TRANSPORT_PATH}/source/bulk_protocol.c\ ${LCM_CNH_PATH}/source/z_family.c\ ${LCM_CNH_PATH}/source/r15_family.c\ ${LCM_CNH_PATH}/source/a2_family.c\ + ${LCM_PATH}/source/cnh1605551_ldr_utilities/critical_section/critical_section_linux.c\ ${LCM_PATH}/source/serialization.c LIBOBJ_x32 := $(addprefix $(BUILDFOLDER)/$(LIB_x32_OBJ_DIR)/, $(notdir $(LIBSRC:.c=.o))) @@ -75,6 +76,7 @@ INCLUDES := -I. \ -I ${LCM_CNH_PATH}/include/\ -I ${TIME_UTILITIES_PATH}/include/\ -I ${UTILITIES_PATH}/include/\ + -I ${LCM_PATH}/source/cnh1605551_ldr_utilities/critical_section/\ -I ${UTILITIES_PATH}/communication_abstraction/\ -I ${BUFFERS_PATH}/include/\ -I ${SECURITY_ALGORITHMS_PATH}/include/\ @@ -114,6 +116,10 @@ $(BUILDFOLDER)/$(LIB_x32_OBJ_DIR)/%.o: ${LCM_CNH_PATH}/source/%.c $(AUTOGEN_FIL @mkdir -p $(dir $@) $(CC) $(INCLUDES) $(CFLAGS) -c -m32 $< -o $(BUILDFOLDER)/$(LIB_x32_OBJ_DIR)/$(@F) +$(BUILDFOLDER)/$(LIB_x32_OBJ_DIR)/%.o: ${LCM_PATH}/source/cnh1605551_ldr_utilities/critical_section/%.c $(AUTOGEN_FILES) + @mkdir -p $(dir $@) + $(CC) $(INCLUDES) $(CFLAGS) -c -m32 $< -o $(BUILDFOLDER)/$(LIB_x32_OBJ_DIR)/$(@F) + $(BUILDFOLDER)/$(LIB_x32_OBJ_DIR)/%.o: ${LCM_PATH}/source/%.c $(AUTOGEN_FILES) @mkdir -p $(dir $@) $(CC) $(INCLUDES) $(CFLAGS) -c -m32 $< -o $(BUILDFOLDER)/$(LIB_x32_OBJ_DIR)/$(@F) @@ -130,6 +136,10 @@ $(BUILDFOLDER)/$(LIB_x64_OBJ_DIR)/%.o: ${LCM_CNH_PATH}/source/%.c $(AUTOGEN_FIL @mkdir -p $(dir $@) $(CC) $(INCLUDES) $(CFLAGS) -c $< -o $(BUILDFOLDER)/$(LIB_x64_OBJ_DIR)/$(@F) +$(BUILDFOLDER)/$(LIB_x64_OBJ_DIR)/%.o: ${LCM_PATH}/source/cnh1605551_ldr_utilities/critical_section/%.c $(AUTOGEN_FILES) + @mkdir -p $(dir $@) + $(CC) $(INCLUDES) $(CFLAGS) -c $< -o $(BUILDFOLDER)/$(LIB_x64_OBJ_DIR)/$(@F) + $(BUILDFOLDER)/$(LIB_x64_OBJ_DIR)/%.o: ${LCM_PATH}/source/%.c $(AUTOGEN_FILES) @mkdir -p $(dir $@) $(CC) $(INCLUDES) $(CFLAGS) -c $< -o $(BUILDFOLDER)/$(LIB_x64_OBJ_DIR)/$(@F) 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 @@ + + + + + + @@ -521,6 +533,18 @@ > + + + + + + @@ -646,7 +670,7 @@ 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 @@ -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 @@ -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 @@ -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 +#include +#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 +#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 @@ Data buffer with all SIMLock keys. + + + + + The Loader shuts down the global communication and enters in a Relay working mode. + + + Communication device number of the relay input (host device). + Communication device number of the relay ouptut (target device). + Communication device number for the loader commands (control device). + + + + + + + + + + + + + + + + @@ -739,7 +765,7 @@ - + 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 @@ -562,6 +562,14 @@ Reset loader.Report if problem still exist. Reset loader.Report if problem still exist. + + Wrong value passed as state for the communication relay and hence it can't be used. Try setting some of predifined communication relay states. + 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. +