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/cnh1605551_ldr_utilities | |
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/cnh1605551_ldr_utilities')
5 files changed, 464 insertions, 0 deletions
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_*/ |