Official mbed Real Time Operating System based on the RTX implementation of the CMSIS-RTOS API open standard.
Dependents: denki-yohou_b TestY201 Network-RTOS NTPClient_HelloWorld ... more
Deprecated
This is the mbed 2 rtos library. mbed OS 5 integrates the mbed library with mbed-rtos. With this, we have provided thread safety for all mbed APIs. If you'd like to learn about using mbed OS 5, please see the docs.
Diff: rtx/TARGET_CORTEX_M/RTX_CM_lib.h
- Revision:
- 119:19af2d39a542
- Parent:
- 118:6635230e06ba
- Child:
- 120:4dc938e301cc
--- a/rtx/TARGET_CORTEX_M/RTX_CM_lib.h Mon Jul 25 14:12:24 2016 +0100 +++ b/rtx/TARGET_CORTEX_M/RTX_CM_lib.h Wed Aug 10 16:09:20 2016 +0100 @@ -34,6 +34,7 @@ #include "mbed_error.h" #if defined (__CC_ARM) +#include <rt_misc.h> #pragma O3 #define __USED __attribute__((used)) #elif defined (__GNUC__) @@ -186,6 +187,10 @@ uint32_t const *m_tmr = NULL; uint16_t const mp_tmr_size = 0U; +/* singleton mutex */ +osMutexId singleton_mutex_id; +osMutexDef(singleton_mutex); + #if defined (__CC_ARM) && !defined (__MICROLIB) /* A memory space for arm standard library. */ static uint32_t std_libspace[OS_TASK_CNT][96/4]; @@ -428,6 +433,9 @@ #elif defined(TARGET_STM32F411RE) #define INITIAL_SP (0x20020000UL) +#elif defined(TARGET_STM32F207ZG) +#define INITIAL_SP (0x20020000UL) + #elif defined(TARGET_STM32F410RB) #define INITIAL_SP (0x20008000UL) @@ -518,17 +526,44 @@ #elif defined(TARGET_MCU_NORDIC_16K) #define INITIAL_SP (0x20004000UL) +#elif defined(TARGET_MCU_NRF52832) +#define INITIAL_SP (0x20010000UL) + #elif (defined(TARGET_STM32F767ZI)) #define INITIAL_SP (0x20080000UL) +#elif defined(TARGET_NUMAKER_PFM_NUC472) +# if defined(__CC_ARM) +extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Limit[]; +extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Base[]; +#define INITIAL_SP ((uint32_t) Image$$ARM_LIB_STACK$$ZI$$Limit) +#define FINAL_SP ((uint32_t) Image$$ARM_LIB_STACK$$ZI$$Base) +# elif defined(__GNUC__) +extern uint32_t __StackTop[]; +extern uint32_t __StackLimit[]; +#define INITIAL_SP ((uint32_t) __StackTop) +#define FINAL_SP ((uint32_t) __StackLimit) +# elif defined(__ICCARM__) +#pragma section="CSTACK" +#define INITIAL_SP ((uint32_t) __section_end("CSTACK")) +#define FINAL_SP ((uint32_t) __section_begin("CSTACK")) +# else +#error "no toolchain defined" +# endif + #else #error "no target defined" #endif #ifdef __CC_ARM +#if defined(TARGET_NUMAKER_PFM_NUC472) +extern uint32_t Image$$ARM_LIB_HEAP$$Base[]; +#define HEAP_START ((uint32_t) Image$$ARM_LIB_HEAP$$Base) +#else extern uint32_t Image$$RW_IRAM1$$ZI$$Limit[]; #define HEAP_START (Image$$RW_IRAM1$$ZI$$Limit) +#endif #elif defined(__GNUC__) extern uint32_t __end__[]; #define HEAP_START (__end__) @@ -538,6 +573,12 @@ #endif void set_main_stack(void) { +#if defined(TARGET_NUMAKER_PFM_NUC472) + // Scheduler stack: OS_MAINSTKSIZE words + // Main thread stack: Reserved stack size - OS_MAINSTKSIZE words + os_thread_def_main.stack_pointer = (uint32_t *) FINAL_SP; + os_thread_def_main.stacksize = (uint32_t) INITIAL_SP - (uint32_t) FINAL_SP - OS_MAINSTKSIZE * 4; +#else uint32_t interrupt_stack_size = ((uint32_t)OS_MAINSTKSIZE * 4); #if defined(__ICCARM__) /* For IAR heap is defined .icf file */ @@ -556,6 +597,7 @@ // Leave OS_MAINSTKSIZE words for the scheduler and interrupts os_thread_def_main.stacksize = main_stack_size; +#endif } #if defined (__CC_ARM) @@ -584,6 +626,7 @@ void pre_main() { + singleton_mutex_id = osMutexCreate(osMutex(singleton_mutex)); $Super$$__cpp_initialize__aeabi_(); main(); } @@ -593,25 +636,13 @@ void * armcc_heap_base; void * armcc_heap_top; -__asm void pre_main (void) -{ - IMPORT __rt_lib_init - IMPORT main - IMPORT armcc_heap_base - IMPORT armcc_heap_top +int main(void); - LDR R0,=armcc_heap_base - LDR R1,=armcc_heap_top - LDR R0,[R0] - LDR R1,[R1] - /* Save link register (keep 8 byte alignment with dummy R4) */ - PUSH {R4, LR} - BL __rt_lib_init - BL main - /* Return to the thread destroy function. - */ - POP {R4, PC} - ALIGN +void pre_main (void) +{ + singleton_mutex_id = osMutexCreate(osMutex(singleton_mutex)); + __rt_lib_init((unsigned)armcc_heap_base, (unsigned)armcc_heap_top); + main(); } /* The single memory model is checking for stack collision at run time, verifing @@ -676,6 +707,7 @@ extern int main(int argc, char **argv); void pre_main(void) { + singleton_mutex_id = osMutexCreate(osMutex(singleton_mutex)); malloc_mutex_id = osMutexCreate(osMutex(malloc_mutex)); env_mutex_id = osMutexCreate(osMutex(env_mutex)); atexit(__libc_fini_array); @@ -737,6 +769,7 @@ static uint8_t low_level_init_needed; void pre_main(void) { + singleton_mutex_id = osMutexCreate(osMutex(singleton_mutex)); if (low_level_init_needed) { __iar_dynamic_initialization(); }