diff --git a/doxyfile_options b/doxyfile_options index cab5340..33eb3a2 100644 --- a/doxyfile_options +++ b/doxyfile_options @@ -840,7 +840,7 @@ */TESTS/* \ */targets/* \ */BUILD/* \ - */rtos/rtx* \ + */rtos/TARGET_CORTEX/rtx* \ */cmsis/* \ */FEATURE_* \ */features/mbedtls/* \ diff --git a/doxygen_options.json b/doxygen_options.json index b55f601..37433da 100644 --- a/doxygen_options.json +++ b/doxygen_options.json @@ -8,5 +8,5 @@ "PREDEFINED": "DOXYGEN_ONLY DEVICE_ANALOGIN DEVICE_ANALOGOUT DEVICE_CAN DEVICE_ETHERNET DEVICE_EMAC DEVICE_FLASH DEVICE_I2C DEVICE_I2CSLAVE DEVICE_I2C_ASYNCH DEVICE_INTERRUPTIN DEVICE_LOWPOWERTIMER DEVICE_PORTIN DEVICE_PORTINOUT DEVICE_PORTOUT DEVICE_PWMOUT DEVICE_RTC DEVICE_TRNG DEVICE_SERIAL DEVICE_SERIAL_ASYNCH DEVICE_SERIAL_FC DEVICE_SLEEP DEVICE_SPI DEVICE_SPI_ASYNCH DEVICE_SPISLAVE DEVICE_STORAGE \"MBED_DEPRECATED_SINCE(f, g)=\" \"MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, M)=\"", "EXPAND_AS_DEFINED": "", "SKIP_FUNCTION_MACROS": "NO", - "EXCLUDE_PATTERNS": "*/tools/* */TESTS/* */targets/* */FEATURE_*/* */features/mbedtls/* */features/storage/* */features/unsupported/* */features/filesystem/* */BUILD/* */rtos/rtx*/* */cmsis/* */features/FEATURES_*" + "EXCLUDE_PATTERNS": "*/tools/* */TESTS/* */targets/* */FEATURE_*/* */features/mbedtls/* */features/storage/* */features/unsupported/* */features/filesystem/* */BUILD/* */rtos/TARGET_CORTEX/rtx*/* */cmsis/* */features/FEATURES_*" } diff --git a/rtos/TARGET_CORTEX/mbed_boot.c b/rtos/TARGET_CORTEX/mbed_boot.c new file mode 100644 index 0000000..7be1bad --- /dev/null +++ b/rtos/TARGET_CORTEX/mbed_boot.c @@ -0,0 +1,691 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* mbed OS boot sequence + * + * Most of mbed supported targets use default ARM Cortex M boot approach, where the core starts executing reset vector + * after power up. Reset ISR is defined for each target by the vendor (basing on CMSIS template). Reset vector is + * responsible for low level platform init and then calling in libc (__main). Depending on compiler and version of C + * library, predefined function will be called which is implemented by mbed OS. + * + * There's number of functions, vendor and users can provide to setup the platform and/or inject a code to be executed + * before main(): + * * Reset vector and SystemInit: Reset vector should do low level core and board initialization. + * * mbed_sdk_init: Higher level board init and making sure the board is ready for the mbed OS. + * * mbed_main: User's code to be executed before main(). + * * main: Standard application code. + * + * Detailed boot procedures: + * + * For ARMCC: + * ========== + * + * Reset (TARGET) + * -> SystemInit (TARGET) + * -> __main (LIBC) + * -> __rt_entry (MBED: rtos/mbed_boot.c) + * -> __user_setup_stackheap (LIBC) + * -> mbed_set_stack_heap (MBED: rtos/mbed_boot.c) + * -> mbed_cpy_nvic (MBED: rtos/mbed_boot.c) + * -> mbed_sdk_init (TARGET) + * -> _platform_post_stackheap_init (RTX) + * -> osKernelInitialize (RTX) + * -> mbed_start_main (MBED: rtos/mbed_boot.c) + * -> osThreadNew (RTX) + * -> pre_main(MBED: rtos/mbed_boot.c) + * -> __rt_lib_init (LIBC) + * -> $Sub$$main (MBED: rtos/mbed_boot.c) + * -> mbed_main (MBED: rtos/mbed_boot.c) + * -> main (APP) + * -> osKernelStart (RTX) + * + * In addition to the above, libc will use functions defined by RTX: __user_perthread_libspace, _mutex_initialize, + * _mutex_acquire, _mutex_release, _mutex_free for details consult: ARM C and C++ Libraries and Floating-Point + * Support User Guide. + * + * For MICROLIB: + * ========== + * + * Reset (TARGET) + * -> SystemInit (TARGET) + * -> __main (LIBC) + * -> _main_init (MBED: rtos/mbed_boot.c) + * -> mbed_set_stack_heap (MBED: rtos/mbed_boot.c) + * -> mbed_cpy_nvic (MBED: rtos/mbed_boot.c) + * -> mbed_sdk_init (TARGET) + * -> osKernelInitialize (RTX) + * -> mbed_start_main (MBED: rtos/mbed_boot.c) + * -> osThreadNew (RTX) + * -> pre_main(MBED: rtos/mbed_boot.c) + * -> __cpp_initialize__aeabi_ (LIBC) + * -> $Sub$$main (MBED: rtos/mbed_boot.c) + * -> mbed_main (MBED: rtos/mbed_boot.c) + * -> main (APP) + * -> osKernelStart (RTX) + * + * For GCC: + * ======== + * + * Reset (TARGET) + * -> SystemInit (TARGET) + * -> __main (LIBC) + * -> software_init_hook (MBED: rtos/mbed_boot.c) + * -> mbed_set_stack_heap (MBED: rtos/mbed_boot.c) + * -> mbed_cpy_nvic (MBED: rtos/mbed_boot.c) + * -> mbed_sdk_init (TARGET) + * -> osKernelInitialize (RTX) + * -> mbed_start_main (MBED: rtos/mbed_boot.c) + * -> osThreadNew (RTX) + * -> pre_main(MBED: rtos/mbed_boot.c) + * -> __libc_init_array (LIBC) + * -> __wrap_main (MBED: rtos/mbed_boot.c) + * -> mbed_main (MBED: rtos/mbed_boot.c) + * -> __real_main (APP) + * -> osKernelStart (RTX) + * + * For IAR: + * ======== + * + * Reset (TARGET) + * -> SystemInit (TARGET) + * -> __iar_program_start + * -> __iar_init_core + * -> __iar_init_core + * -> __iar_init_vfp + * -> __low_level_init + * -> __iar_data_init3 + * -> mbed_cpy_nvic (MBED: rtos/mbed_boot.c) + * -> mbed_sdk_init (TARGET) + * -> mbed_set_stack_heap (MBED: rtos/mbed_boot.c) + * -> osKernelInitialize (RTX) + * -> mbed_start_main (MBED: rtos/mbed_boot.c) + * -> osThreadNew (RTX) + * -> pre_main(MBED: rtos/mbed_boot.c) + * -> __iar_dynamic_initialization +* -> main + * -> osKernelStart (RTX) + * + * Other notes: + * + * * In addition to the above, libc will use functions defined in mbed_boot.c: __rtos_malloc_lock/unlock, + * __rtos_env_lock/unlock. + * + * * First step after the execution is passed to mbed, software_init_hook for GCC and __rt_entry for ARMC is to + * initialize heap. + * + * Memory layout notes: + * ==================== + * + * IAR Default Memory layout notes: + * -Heap defined by "HEAP" region in .icf file + * -Interrupt stack defined by "CSTACK" region in .icf file + * -Value INITIAL_SP is ignored + * + * IAR Custom Memory layout notes: + * -There is no custom layout available for IAR - everything must be defined in + * the .icf file and use the default layout + * + * + * GCC Default Memory layout notes: + * -Block of memory from symbol __end__ to define INITIAL_SP used to setup interrupt + * stack and heap in the function set_stack_heap() + * -ISR_STACK_SIZE can be overridden to be larger or smaller + * + * GCC Custom Memory layout notes: + * -Heap can be explicitly placed by defining both HEAP_START and HEAP_SIZE + * -Interrupt stack can be explicitly placed by defining both ISR_STACK_START and ISR_STACK_SIZE + * + * + * ARM Memory layout + * -Block of memory from end of region "RW_IRAM1" to define INITIAL_SP used to setup interrupt + * stack and heap in the function set_stack_heap() + * -ISR_STACK_SIZE can be overridden to be larger or smaller + * + * ARM Custom Memory layout notes: + * -Heap can be explicitly placed by defining both HEAP_START and HEAP_SIZE + * -Interrupt stack can be explicitly placed by defining both ISR_STACK_START and ISR_STACK_SIZE + * + */ + +#include + +#include "cmsis.h" +#include "mbed_rtx.h" +#include "mbed_rtos_storage.h" +#include "cmsis_os2.h" +#include "mbed_toolchain.h" +#include "mbed_error.h" + +/* Heap limits - only used if set */ +extern unsigned char *mbed_heap_start; +extern uint32_t mbed_heap_size; + +unsigned char *mbed_stack_isr_start = 0; +uint32_t mbed_stack_isr_size = 0; + +WEAK void mbed_main(void); +void pre_main (void); + +osThreadAttr_t _main_thread_attr; + +/** The main thread's stack size can be configured by the application, if not explicitly specified it'll default to 4K */ +#ifndef MBED_CONF_APP_MAIN_STACK_SIZE +#define MBED_CONF_APP_MAIN_STACK_SIZE 4096 +#endif +MBED_ALIGN(8) char _main_stack[MBED_CONF_APP_MAIN_STACK_SIZE]; +mbed_rtos_storage_thread_t _main_obj; + +osMutexId_t singleton_mutex_id; +mbed_rtos_storage_mutex_t singleton_mutex_obj; +osMutexAttr_t singleton_mutex_attr; + +/* + * Sanity check values + */ +#if defined(__ICCARM__) && \ + (defined(HEAP_START) || defined(HEAP_SIZE) || \ + defined(ISR_STACK_START) && defined(ISR_STACK_SIZE)) + #error "No custom layout allowed for IAR. Use .icf file instead" +#endif +#if defined(HEAP_START) && !defined(HEAP_SIZE) + #error "HEAP_SIZE must be defined if HEAP_START is defined" +#endif +#if defined(ISR_STACK_START) && !defined(ISR_STACK_SIZE) + #error "ISR_STACK_SIZE must be defined if ISR_STACK_START is defined" +#endif +#if defined(HEAP_SIZE) && !defined(HEAP_START) + #error "HEAP_START must be defined if HEAP_SIZE is defined" +#endif + +/* IAR - INITIAL_SP and HEAP_START ignored as described in Memory layout notes above + */ +#if !defined(__ICCARM__) && !defined(INITIAL_SP) && !defined(HEAP_START) + #error "no target defined" +#endif + +/* Interrupt stack and heap always defined for IAR + * Main thread defined here + */ +#if defined(__ICCARM__) + #pragma section="CSTACK" + #pragma section="HEAP" + #define HEAP_START ((unsigned char*)__section_begin("HEAP")) + #define HEAP_SIZE ((uint32_t)__section_size("HEAP")) + #define ISR_STACK_START ((unsigned char*)__section_begin("CSTACK")) + #define ISR_STACK_SIZE ((uint32_t)__section_size("CSTACK")) +#endif + +/* Define heap region if it has not been defined already */ +#if !defined(HEAP_START) + #if defined(__ICCARM__) + #error "Heap should already be defined for IAR" + #elif defined(__CC_ARM) + extern uint32_t Image$$RW_IRAM1$$ZI$$Limit[]; + #define HEAP_START ((unsigned char*)Image$$RW_IRAM1$$ZI$$Limit) + #define HEAP_SIZE ((uint32_t)((uint32_t)INITIAL_SP - (uint32_t)HEAP_START)) + #elif defined(__GNUC__) + extern uint32_t __end__[]; + #define HEAP_START ((unsigned char*)__end__) + #define HEAP_SIZE ((uint32_t)((uint32_t)INITIAL_SP - (uint32_t)HEAP_START)) + #endif +#endif + +/* Define stack sizes if they haven't been set already */ +#if !defined(ISR_STACK_SIZE) + #define ISR_STACK_SIZE ((uint32_t)1024) +#endif + +/* + * mbed_set_stack_heap purpose is to set the following variables: + * -mbed_heap_start + * -mbed_heap_size + * -mbed_stack_isr_start + * -mbed_stack_isr_size + */ +void mbed_set_stack_heap(void) { + + unsigned char *free_start = HEAP_START; + uint32_t free_size = HEAP_SIZE; + +#ifdef ISR_STACK_START + /* Interrupt stack explicitly specified */ + mbed_stack_isr_size = ISR_STACK_SIZE; + mbed_stack_isr_start = ISR_STACK_START; +#else + /* Interrupt stack - reserve space at the end of the free block */ + mbed_stack_isr_size = ISR_STACK_SIZE < free_size ? ISR_STACK_SIZE : free_size; + mbed_stack_isr_start = free_start + free_size - mbed_stack_isr_size; + free_size -= mbed_stack_isr_size; +#endif + + /* Heap - everything else */ + mbed_heap_size = free_size; + mbed_heap_start = free_start; +} + +static void mbed_cpy_nvic(void) +{ + /* If vector address in RAM is defined, copy and switch to dynamic vectors. Exceptions for M0 which doesn't have + VTOR register and for A9 for which CMSIS doesn't define NVIC_SetVector; in both cases target code is + responsible for correctly handling the vectors. + */ +#if !defined(__CORTEX_M0) && !defined(__CORTEX_A9) +#ifdef NVIC_RAM_VECTOR_ADDRESS + uint32_t *old_vectors = (uint32_t *)SCB->VTOR; + uint32_t *vectors = (uint32_t*)NVIC_RAM_VECTOR_ADDRESS; + for (int i = 0; i < NVIC_NUM_VECTORS; i++) { + vectors[i] = old_vectors[i]; + } + SCB->VTOR = (uint32_t)NVIC_RAM_VECTOR_ADDRESS; +#endif /* NVIC_RAM_VECTOR_ADDRESS */ +#endif /* !defined(__CORTEX_M0) && !defined(__CORTEX_A9) */ +} + +/* mbed_main is a function that is called before main() + * mbed_sdk_init() is also a function that is called before main(), but unlike + * mbed_main(), it is not meant for user code, but for the SDK itself to perform + * initializations before main() is called. + */ +WEAK void mbed_main(void) { + +} + +/* This function can be implemented by the target to perform higher level target initialization, before the mbed OS or + * RTX is started. + */ +void mbed_sdk_init(void); +WEAK void mbed_sdk_init(void) { +} + +void mbed_start_main(void) +{ + _main_thread_attr.stack_mem = _main_stack; + _main_thread_attr.stack_size = sizeof(_main_stack); + _main_thread_attr.cb_size = sizeof(_main_obj); + _main_thread_attr.cb_mem = &_main_obj; + _main_thread_attr.priority = osPriorityNormal; + _main_thread_attr.name = "main_thread"; + osThreadId_t result = osThreadNew((osThreadFunc_t)pre_main, NULL, &_main_thread_attr); + if ((void *)result == NULL) { + error("Pre main thread not created"); + } + + osKernelStart(); +} + +/******************** Toolchain specific code ********************/ + +#if defined (__CC_ARM) + +/* Common for both ARMC and MICROLIB */ +int $Super$$main(void); +int $Sub$$main(void) { + mbed_main(); + return $Super$$main(); +} + +#if defined (__MICROLIB) /******************** MICROLIB ********************/ + +int main(void); +void _main_init (void) __attribute__((section(".ARM.Collect$$$$000000FF"))); +void $Super$$__cpp_initialize__aeabi_(void); + +void _main_init (void) { + mbed_set_stack_heap(); + /* Copy the vector table to RAM only if uVisor is not in use. */ +#if !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED)) + mbed_cpy_nvic(); +#endif + mbed_sdk_init(); + osKernelInitialize(); + mbed_start_main(); + for (;;); +} + +void $Sub$$__cpp_initialize__aeabi_(void) +{ + /* This should invoke C++ initializers prior _main_init, we keep this empty and + * invoke them after _main_init, when the RTX is already initilized. + */ +} + +void pre_main() +{ + singleton_mutex_attr.name = "singleton_mutex"; + singleton_mutex_attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust; + singleton_mutex_attr.cb_size = sizeof(singleton_mutex_obj); + singleton_mutex_attr.cb_mem = &singleton_mutex_obj; + singleton_mutex_id = osMutexNew(&singleton_mutex_attr); + + $Super$$__cpp_initialize__aeabi_(); + main(); +} + +#else /******************** ARMC ********************/ + +#include +extern __value_in_regs struct __argc_argv __rt_lib_init(unsigned heapbase, unsigned heaptop); +extern __value_in_regs struct __initial_stackheap __user_setup_stackheap(void); +extern void _platform_post_stackheap_init (void); +extern int main(int argc, char* argv[]); + +void pre_main (void) +{ + singleton_mutex_attr.name = "singleton_mutex"; + singleton_mutex_attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust; + singleton_mutex_attr.cb_size = sizeof(singleton_mutex_obj); + singleton_mutex_attr.cb_mem = &singleton_mutex_obj; + singleton_mutex_id = osMutexNew(&singleton_mutex_attr); + + __rt_lib_init((unsigned)mbed_heap_start, (unsigned)(mbed_heap_start + mbed_heap_size)); + + main(0, NULL); +} + +/* The single memory model is checking for stack collision at run time, verifing + that the heap pointer is underneath the stack pointer. + With the RTOS there is not only one stack above the heap, there are multiple + stacks and some of them are underneath the heap pointer. +*/ +#pragma import(__use_two_region_memory) + +/* Called by the C library */ +void __rt_entry (void) { + __user_setup_stackheap(); + mbed_set_stack_heap(); + /* Copy the vector table to RAM only if uVisor is not in use. */ +#if !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED)) + mbed_cpy_nvic(); +#endif + mbed_sdk_init(); + _platform_post_stackheap_init(); + mbed_start_main(); +} + +typedef void *mutex; + +/* ARM toolchain requires dynamically created mutexes to enforce thread safety. There's + up to 8 static mutexes, protecting atexit, signalinit, stdin, stdout, stderr, stream_list, + fp_trap_init and the heap. Additionally for each call to fopen one extra mutex will be + created. + mbed OS provides a RTX pool for 8 mutexes, to satisfy the static requirements. All + additional mutexes will be allocated on the heap. We can't use the heap allocation for + all the required mutexes, as the heap operations also require a mutex. We don't need to + worry about freeing the allocated memory as library mutexes are only freed when the + application finishes executing. + */ +int _mutex_initialize(mutex *m) +{ + osMutexAttr_t attr; + memset(&attr, 0, sizeof(attr)); + attr.name = "ARM toolchain mutex"; + attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust; + + *m = osMutexNew(&attr); + if (*m != NULL) { + return 1; + } + + /* Mutex pool exhausted, try using HEAP */ + attr.cb_size = sizeof(mbed_rtos_storage_mutex_t); + attr.cb_mem = (void*)malloc(attr.cb_size); + if (attr.cb_mem == NULL) { + osRtxErrorNotify(osRtxErrorClibSpace, m); + return 0; + } + + *m = osMutexNew(&attr); + if (*m == NULL) { + osRtxErrorNotify(osRtxErrorClibMutex, m); + return 0; + } + + return 1; +} + +#endif /* ARMC */ +#elif defined (__GNUC__) /******************** GCC ********************/ + +extern int main(int argc, char* argv[]); +extern void __libc_init_array (void); +extern int __real_main(void); + +osMutexId_t malloc_mutex_id; +mbed_rtos_storage_mutex_t malloc_mutex_obj; +osMutexAttr_t malloc_mutex_attr; + +osMutexId_t env_mutex_id; +mbed_rtos_storage_mutex_t env_mutex_obj; +osMutexAttr_t env_mutex_attr; + +#ifdef FEATURE_UVISOR +#include "uvisor-lib/uvisor-lib.h" +#endif/* FEATURE_UVISOR */ + +int __wrap_main(void) { + mbed_main(); + return __real_main(); +} + +void pre_main(void) +{ + singleton_mutex_attr.name = "singleton_mutex"; + singleton_mutex_attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust; + singleton_mutex_attr.cb_size = sizeof(singleton_mutex_obj); + singleton_mutex_attr.cb_mem = &singleton_mutex_obj; + singleton_mutex_id = osMutexNew(&singleton_mutex_attr); + + malloc_mutex_attr.name = "malloc_mutex"; + malloc_mutex_attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust; + malloc_mutex_attr.cb_size = sizeof(malloc_mutex_obj); + malloc_mutex_attr.cb_mem = &malloc_mutex_obj; + malloc_mutex_id = osMutexNew(&malloc_mutex_attr); + + env_mutex_attr.name = "env_mutex"; + env_mutex_attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust; + env_mutex_attr.cb_size = sizeof(env_mutex_obj); + env_mutex_attr.cb_mem = &env_mutex_obj; + env_mutex_id = osMutexNew(&env_mutex_attr); + + __libc_init_array(); + + main(0, NULL); +} + +void software_init_hook(void) +{ + mbed_set_stack_heap(); + /* Copy the vector table to RAM only if uVisor is not in use. */ +#if !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED)) + mbed_cpy_nvic(); +#endif + mbed_sdk_init(); + osKernelInitialize(); + /* uvisor_lib_init calls RTOS functions, so must be called after the RTOS has + * been initialized. */ +#ifdef FEATURE_UVISOR + int return_code; + + return_code = uvisor_lib_init(); + if (return_code) { + mbed_die(); + } +#endif/* FEATURE_UVISOR */ + mbed_start_main(); +} + +/* Opaque declaration of _reent structure */ +struct _reent; + +void __rtos_malloc_lock( struct _reent *_r ) +{ + osMutexAcquire(malloc_mutex_id, osWaitForever); +} + +void __rtos_malloc_unlock( struct _reent *_r ) +{ + osMutexRelease(malloc_mutex_id); +} + +void __rtos_env_lock( struct _reent *_r ) +{ + osMutexAcquire(env_mutex_id, osWaitForever); +} + +void __rtos_env_unlock( struct _reent *_r ) +{ + osMutexRelease(env_mutex_id); +} + +#endif + +#if defined(TOOLCHAIN_IAR) /******************** IAR ********************/ + +extern void* __vector_table; +extern int __low_level_init(void); +extern void __iar_data_init3(void); +extern __weak void __iar_init_core( void ); +extern __weak void __iar_init_vfp( void ); +extern void __iar_dynamic_initialization(void); +extern void mbed_sdk_init(void); +extern int main(void); +extern void exit(int arg); + +static uint8_t low_level_init_needed; + +void pre_main(void) +{ + singleton_mutex_attr.name = "singleton_mutex"; + singleton_mutex_attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust; + singleton_mutex_attr.cb_size = sizeof(singleton_mutex_obj); + singleton_mutex_attr.cb_mem = &singleton_mutex_obj; + singleton_mutex_id = osMutexNew(&singleton_mutex_attr); + + if (low_level_init_needed) { + __iar_dynamic_initialization(); + } + mbed_main(); + main(); +} + +#pragma required=__vector_table +void __iar_program_start( void ) +{ + __iar_init_core(); + __iar_init_vfp(); + + uint8_t low_level_init_needed_local; + + low_level_init_needed_local = __low_level_init(); + if (low_level_init_needed_local) { + __iar_data_init3(); + + /* Copy the vector table to RAM only if uVisor is not in use. */ +#if !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED)) + mbed_cpy_nvic(); +#endif + mbed_sdk_init(); + } + + mbed_set_stack_heap(); + + /* Store in a global variable after RAM has been initialized */ + low_level_init_needed = low_level_init_needed_local; + + osKernelInitialize(); + + mbed_start_main(); +} + +/* Thread safety */ +static osMutexId_t std_mutex_id_sys[_MAX_LOCK] = {0}; +static mbed_rtos_storage_mutex_t std_mutex_sys[_MAX_LOCK] = {0}; +#define _FOPEN_MAX 10 +static osMutexId_t std_mutex_id_file[_FOPEN_MAX] = {0}; +static mbed_rtos_storage_mutex_t std_mutex_file[_FOPEN_MAX] = {0}; + +void __iar_system_Mtxinit(__iar_Rmtx *mutex) /* Initialize a system lock */ +{ + osMutexAttr_t attr; + uint32_t index; + for (index = 0; index < _MAX_LOCK; index++) { + if (0 == std_mutex_id_sys[index]) { + attr.name = "system_mutex"; + attr.cb_mem = &std_mutex_sys[index]; + attr.cb_size = sizeof(std_mutex_sys[index]); + attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust; + std_mutex_id_sys[index] = osMutexNew(&attr); + *mutex = (__iar_Rmtx*)&std_mutex_id_sys[index]; + return; + } + } + + /* This should never happen */ + error("Not enough mutexes\n"); +} + +void __iar_system_Mtxdst(__iar_Rmtx *mutex) /* Destroy a system lock */ +{ + osMutexDelete(*(osMutexId_t*)*mutex); + *mutex = 0; +} + +void __iar_system_Mtxlock(__iar_Rmtx *mutex) /* Lock a system lock */ +{ + osMutexAcquire(*(osMutexId_t*)*mutex, osWaitForever); +} + +void __iar_system_Mtxunlock(__iar_Rmtx *mutex) /* Unlock a system lock */ +{ + osMutexRelease(*(osMutexId_t*)*mutex); +} + +void __iar_file_Mtxinit(__iar_Rmtx *mutex) /* Initialize a file lock */ +{ + osMutexAttr_t attr; + uint32_t index; + for (index = 0; index < _FOPEN_MAX; index++) { + if (0 == std_mutex_id_file[index]) { + attr.name = "file_mutex"; + attr.cb_mem = &std_mutex_file[index]; + attr.cb_size = sizeof(std_mutex_file[index]); + attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust; + std_mutex_id_file[index] = osMutexNew(&attr); + *mutex = (__iar_Rmtx*)&std_mutex_id_file[index]; + return; + } + } + /* The variable _FOPEN_MAX needs to be increased */ + error("Not enough mutexes\n"); +} + +void __iar_file_Mtxdst(__iar_Rmtx *mutex) /* Destroy a file lock */ +{ + osMutexDelete(*(osMutexId_t*)*mutex); + *mutex = 0; +} + +void __iar_file_Mtxlock(__iar_Rmtx *mutex) /* Lock a file lock */ +{ + osMutexAcquire(*(osMutexId_t*)*mutex, osWaitForever); +} + +void __iar_file_Mtxunlock(__iar_Rmtx *mutex) /* Unlock a file lock */ +{ + osMutexRelease(*(osMutexId_t*)*mutex); +} + +#endif diff --git a/rtos/TARGET_CORTEX/mbed_rtos1_types.h b/rtos/TARGET_CORTEX/mbed_rtos1_types.h new file mode 100644 index 0000000..73df37f --- /dev/null +++ b/rtos/TARGET_CORTEX/mbed_rtos1_types.h @@ -0,0 +1,27 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2017 ARM Limited + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef MBED_RTOS_RTX1_TYPES_H +#define MBED_RTOS_RTX1_TYPES_H + +#include "rtx4/cmsis_os.h" + +#endif diff --git a/rtos/TARGET_CORTEX/mbed_rtos_storage.h b/rtos/TARGET_CORTEX/mbed_rtos_storage.h new file mode 100644 index 0000000..50e9227 --- /dev/null +++ b/rtos/TARGET_CORTEX/mbed_rtos_storage.h @@ -0,0 +1,60 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2017 ARM Limited + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef MBED_RTOS_STORAGE_H +#define MBED_RTOS_STORAGE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** \addtogroup rtos */ +/** @{*/ + +/** @brief RTOS primitives storage types for RTX + + Types defined in this file should be utilized, when the direct RTOS C API usage is required, to provide backing memory + for internal RTX data. Allocated object should be wrapped in attribute struct and passed to os*New call, for details + see CMSIS-RTOS2 documentation. + + @note + This file breaks abstraction layers and uses RTX internal types, but it limits the contamination to single, RTOS + implementation specific, header file, therefore limiting scope of possible changes. + */ + +#include "rtx_lib.h" + +typedef os_mutex_t mbed_rtos_storage_mutex_t; +typedef os_semaphore_t mbed_rtos_storage_semaphore_t; +typedef os_thread_t mbed_rtos_storage_thread_t; +typedef os_memory_pool_t mbed_rtos_storage_mem_pool_t; +typedef os_message_queue_t mbed_rtos_storage_msg_queue_t; +typedef os_event_flags_t mbed_rtos_storage_event_flags_t; +typedef os_message_t mbed_rtos_storage_message_t; +typedef os_timer_t mbed_rtos_storage_timer_t; + +#ifdef __cplusplus +} +#endif + +#endif + +/** @}*/ diff --git a/rtos/TARGET_CORTEX/mbed_rtx_conf.h b/rtos/TARGET_CORTEX/mbed_rtx_conf.h new file mode 100644 index 0000000..b4fe1d4 --- /dev/null +++ b/rtos/TARGET_CORTEX/mbed_rtx_conf.h @@ -0,0 +1,56 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2012 ARM Limited + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef MBED_RTX_CONF_H +#define MBED_RTX_CONF_H + +#include "mbed_rtx.h" + +/** The thread's stack size can be configured by the application, if not explicitly specified it'll default to 4K */ +#ifndef MBED_CONF_APP_THREAD_STACK_SIZE +#define MBED_CONF_APP_THREAD_STACK_SIZE 4096 +#endif + +#define OS_STACK_SIZE MBED_CONF_APP_THREAD_STACK_SIZE + +#define OS_TIMER_THREAD_STACK_SIZE 768 +#ifndef OS_IDLE_THREAD_STACK_SIZE +#define OS_IDLE_THREAD_STACK_SIZE 256 +#endif + +#define OS_DYNAMIC_MEM_SIZE 0 + +#if defined(__CC_ARM) +/* ARM toolchain uses up to 8 static mutexes, any further mutexes will be allocated on the heap. */ +#define OS_MUTEX_OBJ_MEM 1 +#define OS_MUTEX_NUM 8 +#endif + +#if !defined(OS_STACK_WATERMARK) && (defined(MBED_STACK_STATS_ENABLED) && MBED_STACK_STATS_ENABLED) +#define OS_STACK_WATERMARK 1 +#endif + +/* Run threads unprivileged when uVisor is enabled. */ +#if defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED) +# define OS_PRIVILEGE_MODE 0 +#endif + +#endif /* MBED_RTX_CONF_H */ diff --git a/rtos/TARGET_CORTEX/mbed_rtx_handlers.c b/rtos/TARGET_CORTEX/mbed_rtx_handlers.c new file mode 100644 index 0000000..e5dcaba --- /dev/null +++ b/rtos/TARGET_CORTEX/mbed_rtx_handlers.c @@ -0,0 +1,138 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "cmsis_compiler.h" +#include "rtx_os.h" +#include "rtx_evr.h" +#include "mbed_rtx.h" +#include "mbed_error.h" + +extern void rtos_idle_loop(void); + +__NO_RETURN void osRtxIdleThread (void *argument) +{ + for (;;) { + rtos_idle_loop(); + } +} + +__NO_RETURN uint32_t osRtxErrorNotify (uint32_t code, void *object_id) +{ + osThreadId_t tid = osThreadGetId(); + + switch (code) { + case osRtxErrorStackUnderflow: + // Stack underflow detected for thread (thread_id=object_id) + error("CMSIS-RTOS error: Stack underflow (status: 0x%X, task ID: 0x%X, task name: %s)\n\r", + code, object_id, osThreadGetName(object_id)); + break; + case osRtxErrorISRQueueOverflow: + // ISR Queue overflow detected when inserting object (object_id) + error("CMSIS-RTOS error: ISR Queue overflow (status: 0x%X, task ID: 0x%X, object ID: 0x%X)\n\r", + code, tid, object_id); + break; + case osRtxErrorTimerQueueOverflow: + // User Timer Callback Queue overflow detected for timer (timer_id=object_id) + error("CMSIS-RTOS error: User Timer Callback Queue overflow (status: 0x%X, task ID: 0x%X, timer ID: 0x%X)\n\r", + code, tid, object_id); + break; + case osRtxErrorClibSpace: + // Standard C/C++ library libspace not available: increase OS_THREAD_LIBSPACE_NUM + error("CMSIS-RTOS error: STD C/C++ library libspace not available (status: 0x%X, task ID: 0x%X)\n\r", + code, tid); + break; + case osRtxErrorClibMutex: + // Standard C/C++ library mutex initialization failed + error("CMSIS-RTOS error: STD C/C++ library mutex initialization failed (status: 0x%X, task ID: 0x%X)\n\r", + code, tid); + break; + default: + error("CMSIS-RTOS error: Unknown (status: 0x%X, task ID: 0x%X)\n\r", code, tid); + break; + } + + /* That shouldn't be reached */ + for (;;) {} +} + +#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED + +static const char* error_msg(int32_t status) +{ + switch (status) { + case osError: + return "Unspecified RTOS error"; + case osErrorTimeout: + return "Operation not completed within the timeout period"; + case osErrorResource: + return "Resource not available"; + case osErrorParameter: + return "Parameter error"; + case osErrorNoMemory: + return "System is out of memory"; + case osErrorISR: + return "Not allowed in ISR context"; + default: + return "Unknown"; + } +} + +void EvrRtxKernelError (int32_t status) +{ + error("Kernel error %i: %s\r\n", status, error_msg(status)); +} + +void EvrRtxThreadError (osThreadId_t thread_id, int32_t status) +{ + error("Thread %p error %i: %s\r\n", thread_id, status, error_msg(status)); +} + +void EvrRtxTimerError (osTimerId_t timer_id, int32_t status) +{ + error("Timer %p error %i: %s\r\n", timer_id, status, error_msg(status)); +} + +void EvrRtxEventFlagsError (osEventFlagsId_t ef_id, int32_t status) +{ + error("Event %p error %i: %s\r\n", ef_id, status, error_msg(status)); +} + +void EvrRtxMutexError (osMutexId_t mutex_id, int32_t status) +{ + error("Mutex %p error %i: %s\r\n", mutex_id, status, error_msg(status)); +} + +void EvrRtxSemaphoreError (osSemaphoreId_t semaphore_id, int32_t status) +{ + // Ignore semaphore overflow, the count will saturate with a returned error + if (status == osRtxErrorSemaphoreCountLimit) { + return; + } + + error("Semaphore %p error %i\r\n", semaphore_id, status); +} + +void EvrRtxMemoryPoolError (osMemoryPoolId_t mp_id, int32_t status) +{ + error("Memory Pool %p error %i\r\n", mp_id, status); +} + +void EvrRtxMessageQueueError (osMessageQueueId_t mq_id, int32_t status) +{ + error("Message Queue %p error %i\r\n", mq_id, status); +} + +#endif diff --git a/rtos/TARGET_CORTEX/rtx4/cmsis_os.h b/rtos/TARGET_CORTEX/rtx4/cmsis_os.h new file mode 100644 index 0000000..4f7ba11 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx4/cmsis_os.h @@ -0,0 +1,898 @@ +/* + * Copyright (c) 2013-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ---------------------------------------------------------------------- + * + * $Date: 10. January 2017 + * $Revision: V2.1.0 + * + * Project: CMSIS-RTOS API + * Title: cmsis_os.h RTX header file + * + * Version 0.02 + * Initial Proposal Phase + * Version 0.03 + * osKernelStart added, optional feature: main started as thread + * osSemaphores have standard behavior + * osTimerCreate does not start the timer, added osTimerStart + * osThreadPass is renamed to osThreadYield + * Version 1.01 + * Support for C++ interface + * - const attribute removed from the osXxxxDef_t typedefs + * - const attribute added to the osXxxxDef macros + * Added: osTimerDelete, osMutexDelete, osSemaphoreDelete + * Added: osKernelInitialize + * Version 1.02 + * Control functions for short timeouts in microsecond resolution: + * Added: osKernelSysTick, osKernelSysTickFrequency, osKernelSysTickMicroSec + * Removed: osSignalGet + * Version 2.0.0 + * OS objects creation without macros (dynamic creation and resource allocation): + * - added: osXxxxNew functions which replace osXxxxCreate + * - added: osXxxxAttr_t structures + * - deprecated: osXxxxCreate functions, osXxxxDef_t structures + * - deprecated: osXxxxDef and osXxxx macros + * osStatus codes simplified and renamed to osStatus_t + * osEvent return structure deprecated + * Kernel: + * - added: osKernelInfo_t and osKernelGetInfo + * - added: osKernelState_t and osKernelGetState (replaces osKernelRunning) + * - added: osKernelLock, osKernelUnlock + * - added: osKernelSuspend, osKernelResume + * - added: osKernelGetTickCount, osKernelGetTickFreq + * - renamed osKernelSysTick to osKernelGetSysTimerCount + * - replaced osKernelSysTickFrequency with osKernelGetSysTimerFreq + * - deprecated osKernelSysTickMicroSec + * Thread: + * - extended number of thread priorities + * - renamed osPrioriry to osPrioriry_t + * - replaced osThreadCreate with osThreadNew + * - added: osThreadGetName + * - added: osThreadState_t and osThreadGetState + * - added: osThreadGetStackSize, osThreadGetStackSpace + * - added: osThreadSuspend, osThreadResume + * - added: osThreadJoin, osThreadDetach, osThreadExit + * - added: osThreadGetCount, osThreadEnumerate + * - added: Thread Flags (moved from Signals) + * Signals: + * - renamed osSignals to osThreadFlags (moved to Thread Flags) + * - changed return value of Set/Clear/Wait functions + * - Clear function limited to current running thread + * - extended Wait function (options) + * - added: osThreadFlagsGet + * Event Flags: + * - added new independent object for handling Event Flags + * Delay and Wait functions: + * - added: osDelayUntil + * - deprecated: osWait + * Timer: + * - replaced osTimerCreate with osTimerNew + * - added: osTimerGetName, osTimerIsRunning + * Mutex: + * - extended: attributes (Recursive, Priority Inherit, Robust) + * - replaced osMutexCreate with osMutexNew + * - renamed osMutexWait to osMutexAcquire + * - added: osMutexGetName, osMutexGetOwner + * Semaphore: + * - extended: maximum and initial token count + * - replaced osSemaphoreCreate with osSemaphoreNew + * - renamed osSemaphoreWait to osSemaphoreAcquire (changed return value) + * - added: osSemaphoreGetName, osSemaphoreGetCount + * Memory Pool: + * - using osMemoryPool prefix instead of osPool + * - replaced osPoolCreate with osMemoryPoolNew + * - extended osMemoryPoolAlloc (timeout) + * - added: osMemoryPoolGetName + * - added: osMemoryPoolGetCapacity, osMemoryPoolGetBlockSize + * - added: osMemoryPoolGetCount, osMemoryPoolGetSpace + * - added: osMemoryPoolDelete + * - deprecated: osPoolCAlloc + * Message Queue: + * - extended: fixed size message instead of a single 32-bit value + * - using osMessageQueue prefix instead of osMessage + * - replaced osMessageCreate with osMessageQueueNew + * - updated: osMessageQueuePut, osMessageQueueGet + * - added: osMessageQueueGetName + * - added: osMessageQueueGetCapacity, osMessageQueueGetMsgSize + * - added: osMessageQueueGetCount, osMessageQueueGetSpace + * - added: osMessageQueueReset, osMessageQueueDelete + * Mail Queue: + * - deprecated (superseded by extended Message Queue functionality) + * Version 2.1.0 + * Support for critical and uncritical sections (nesting safe): + * - updated: osKernelLock, osKernelUnlock + * - added: osKernelRestoreLock + * Updated Thread and Event Flags: + * - changed flags parameter and return type from int32_t to uint32_t + *---------------------------------------------------------------------------*/ + +#ifndef CMSIS_OS_H_ +#define CMSIS_OS_H_ + +#define osCMSIS 0x20001U ///< API version (main[31:16].sub[15:0]) + +#define osCMSIS_RTX 0x50001U ///< RTOS identification and version (main[31:16].sub[15:0]) + +#define osKernelSystemId "RTX V5.1" ///< RTOS identification string + +#define osFeature_MainThread 0 ///< main thread 1=main can be thread, 0=not available +#define osFeature_Signals 31U ///< maximum number of Signal Flags available per thread +#define osFeature_Semaphore 65535U ///< maximum count for \ref osSemaphoreCreate function +#define osFeature_Wait 0 ///< osWait function: 1=available, 0=not available +#define osFeature_SysTick 1 ///< osKernelSysTick functions: 1=available, 0=not available +#define osFeature_Pool 1 ///< Memory Pools: 1=available, 0=not available +#define osFeature_MessageQ 1 ///< Message Queues: 1=available, 0=not available +#define osFeature_MailQ 1 ///< Mail Queues: 1=available, 0=not available + +#if defined(__CC_ARM) +#define os_InRegs __value_in_regs +#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) +#define os_InRegs __attribute__((value_in_regs)) +#else +#define os_InRegs +#endif + +#if (osCMSIS >= 0x20000U) +#include "cmsis_os2.h" +#else +#include +#include +#endif +#include "rtx_os.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + + +// ==== Enumerations, structures, defines ==== + +/// Priority values. +#if (osCMSIS < 0x20000U) +typedef enum { + osPriorityIdle = -3, ///< Priority: idle (lowest) + osPriorityLow = -2, ///< Priority: low + osPriorityBelowNormal = -1, ///< Priority: below normal + osPriorityNormal = 0, ///< Priority: normal (default) + osPriorityAboveNormal = +1, ///< Priority: above normal + osPriorityHigh = +2, ///< Priority: high + osPriorityRealtime = +3, ///< Priority: realtime (highest) + osPriorityError = 0x84, ///< System cannot determine priority or illegal priority. + osPriorityReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization. +} osPriority; +#else +#define osPriority osPriority_t +#endif + +/// Entry point of a thread. +typedef void (*os_pthread) (void const *argument); + +/// Entry point of a timer call back function. +typedef void (*os_ptimer) (void const *argument); + +/// Timer type. +#if (osCMSIS < 0x20000U) +typedef enum { + osTimerOnce = 0, ///< One-shot timer. + osTimerPeriodic = 1 ///< Repeating timer. +} os_timer_type; +#else +#define os_timer_type osTimerType_t +#endif + +/// Timeout value. +#define osWaitForever 0xFFFFFFFFU ///< Wait forever timeout value. + +/// Status code values returned by CMSIS-RTOS functions. +#if (osCMSIS < 0x20000U) +typedef enum { + osOK = 0, ///< Function completed; no error or event occurred. + osEventSignal = 0x08, ///< Function completed; signal event occurred. + osEventMessage = 0x10, ///< Function completed; message event occurred. + osEventMail = 0x20, ///< Function completed; mail event occurred. + osEventTimeout = 0x40, ///< Function completed; timeout occurred. + osErrorParameter = 0x80, ///< Parameter error: a mandatory parameter was missing or specified an incorrect object. + osErrorResource = 0x81, ///< Resource not available: a specified resource was not available. + osErrorTimeoutResource = 0xC1, ///< Resource not available within given time: a specified resource was not available within the timeout period. + osErrorISR = 0x82, ///< Not allowed in ISR context: the function cannot be called from interrupt service routines. + osErrorISRRecursive = 0x83, ///< Function called multiple times from ISR with same object. + osErrorPriority = 0x84, ///< System cannot determine priority or thread has illegal priority. + osErrorNoMemory = 0x85, ///< System is out of memory: it was impossible to allocate or reserve memory for the operation. + osErrorValue = 0x86, ///< Value of a parameter is out of range. + osErrorOS = 0xFF, ///< Unspecified RTOS error: run-time error but no other error message fits. + osStatusReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization. +} osStatus; +#else +typedef int32_t osStatus; +#define osEventSignal (0x08) +#define osEventMessage (0x10) +#define osEventMail (0x20) +#define osEventTimeout (0x40) +#define osErrorOS osError +#define osErrorTimeoutResource osErrorTimeout +#define osErrorISRRecursive (-126) +#define osErrorValue (-127) +#define osErrorPriority (-128) +#endif + + +// >>> the following data type definitions may be adapted towards a specific RTOS + +/// Thread ID identifies the thread. +#if (osCMSIS < 0x20000U) +typedef void *osThreadId; +#else +#define osThreadId osThreadId_t +#endif + +/// Timer ID identifies the timer. +#if (osCMSIS < 0x20000U) +typedef void *osTimerId; +#else +#define osTimerId osTimerId_t +#endif + +/// Mutex ID identifies the mutex. +#if (osCMSIS < 0x20000U) +typedef void *osMutexId; +#else +#define osMutexId osMutexId_t +#endif + +/// Semaphore ID identifies the semaphore. +#if (osCMSIS < 0x20000U) +typedef void *osSemaphoreId; +#else +#define osSemaphoreId osSemaphoreId_t +#endif + +/// Pool ID identifies the memory pool. +typedef void *osPoolId; + +/// Message ID identifies the message queue. +typedef void *osMessageQId; + +/// Mail ID identifies the mail queue. +typedef void *osMailQId; + + +/// Thread Definition structure contains startup information of a thread. +#if (osCMSIS < 0x20000U) +typedef struct os_thread_def { + os_pthread pthread; ///< start address of thread function + osPriority tpriority; ///< initial thread priority + uint32_t instances; ///< maximum number of instances of that thread function + uint32_t stacksize; ///< stack size requirements in bytes; 0 is default stack size +} osThreadDef_t; +#else +typedef struct os_thread_def { + os_pthread pthread; ///< start address of thread function + osThreadAttr_t attr; ///< thread attributes +} osThreadDef_t; +#endif + +/// Timer Definition structure contains timer parameters. +#if (osCMSIS < 0x20000U) +typedef struct os_timer_def { + os_ptimer ptimer; ///< start address of a timer function +} osTimerDef_t; +#else +typedef struct os_timer_def { + os_ptimer ptimer; ///< start address of a timer function + osTimerAttr_t attr; ///< timer attributes +} osTimerDef_t; +#endif + +/// Mutex Definition structure contains setup information for a mutex. +#if (osCMSIS < 0x20000U) +typedef struct os_mutex_def { + uint32_t dummy; ///< dummy value +} osMutexDef_t; +#else +#define osMutexDef_t osMutexAttr_t +#endif + +/// Semaphore Definition structure contains setup information for a semaphore. +#if (osCMSIS < 0x20000U) +typedef struct os_semaphore_def { + uint32_t dummy; ///< dummy value +} osSemaphoreDef_t; +#else +#define osSemaphoreDef_t osSemaphoreAttr_t +#endif + +/// Definition structure for memory block allocation. +#if (osCMSIS < 0x20000U) +typedef struct os_pool_def { + uint32_t pool_sz; ///< number of items (elements) in the pool + uint32_t item_sz; ///< size of an item + void *pool; ///< pointer to memory for pool +} osPoolDef_t; +#else +typedef struct os_pool_def { + uint32_t pool_sz; ///< number of items (elements) in the pool + uint32_t item_sz; ///< size of an item + osMemoryPoolAttr_t attr; ///< memory pool attributes +} osPoolDef_t; +#endif + +/// Definition structure for message queue. +#if (osCMSIS < 0x20000U) +typedef struct os_messageQ_def { + uint32_t queue_sz; ///< number of elements in the queue + void *pool; ///< memory array for messages +} osMessageQDef_t; +#else +typedef struct os_messageQ_def { + uint32_t queue_sz; ///< number of elements in the queue + osMessageQueueAttr_t attr; ///< message queue attributes +} osMessageQDef_t; +#endif + +/// Definition structure for mail queue. +#if (osCMSIS < 0x20000U) +typedef struct os_mailQ_def { + uint32_t queue_sz; ///< number of elements in the queue + uint32_t item_sz; ///< size of an item + void *pool; ///< memory array for mail +} osMailQDef_t; +#else +typedef struct os_mailQ_def { + uint32_t queue_sz; ///< number of elements in the queue + uint32_t item_sz; ///< size of an item + void *mail; ///< pointer to mail + osMemoryPoolAttr_t mp_attr; ///< memory pool attributes + osMessageQueueAttr_t mq_attr; ///< message queue attributes +} osMailQDef_t; +#endif + + +/// Event structure contains detailed information about an event. +typedef struct { + osStatus status; ///< status code: event or error information + union { + uint32_t v; ///< message as 32-bit value + void *p; ///< message or mail as void pointer + int32_t signals; ///< signal flags + } value; ///< event value + union { + osMailQId mail_id; ///< mail id obtained by \ref osMailCreate + osMessageQId message_id; ///< message id obtained by \ref osMessageCreate + } def; ///< event definition +} osEvent; + + +// ==== Kernel Management Functions ==== + +/// Initialize the RTOS Kernel for creating objects. +/// \return status code that indicates the execution status of the function. +#if (osCMSIS < 0x20000U) +osStatus osKernelInitialize (void); +#endif + +/// Start the RTOS Kernel scheduler. +/// \return status code that indicates the execution status of the function. +#if (osCMSIS < 0x20000U) +osStatus osKernelStart (void); +#endif + +/// Check if the RTOS kernel is already started. +/// \return 0 RTOS is not started, 1 RTOS is started. +#if (osCMSIS < 0x20000U) +int32_t osKernelRunning(void); +#endif + +#if (defined(osFeature_SysTick) && (osFeature_SysTick != 0)) // System Timer available + +/// Get the RTOS kernel system timer counter. +/// \return RTOS kernel system timer as 32-bit value +#if (osCMSIS < 0x20000U) +uint32_t osKernelSysTick (void); +#else +#define osKernelSysTick osKernelGetSysTimerCount +#endif + +/// The RTOS kernel system timer frequency in Hz. +/// \note Reflects the system timer setting and is typically defined in a configuration file. +#if (osCMSIS < 0x20000U) +#define osKernelSysTickFrequency 100000000 +#endif + +/// Convert a microseconds value to a RTOS kernel system timer value. +/// \param microsec time value in microseconds. +/// \return time value normalized to the \ref osKernelSysTickFrequency +#if (osCMSIS < 0x20000U) +#define osKernelSysTickMicroSec(microsec) (((uint64_t)microsec * (osKernelSysTickFrequency)) / 1000000) +#else +#define osKernelSysTickMicroSec(microsec) (((uint64_t)microsec * osKernelGetSysTimerFreq()) / 1000000) +#endif + +#endif // System Timer available + + +// ==== Thread Management Functions ==== + +/// Create a Thread Definition with function, priority, and stack requirements. +/// \param name name of the thread function. +/// \param priority initial priority of the thread function. +/// \param instances number of possible thread instances. +/// \param stacksz stack size (in bytes) requirements for the thread function. +#if defined (osObjectsExternal) // object is external +#define osThreadDef(name, priority, stacksz) \ +extern const osThreadDef_t os_thread_def_##name +#else // define the object +#if (osCMSIS < 0x20000U) +#define osThreadDef(name, priority, stacksz) \ +const osThreadDef_t os_thread_def_##name = \ +{ (name), (priority), (1), (stacksz) } +#else +#define osThreadDef(name, priority, stacksz) \ +uint64_t os_thread_stack##name[(stacksz)?(((stacksz+7)/8)):1] __attribute__((section(".bss.os.thread.stack"))); \ +static osRtxThread_t os_thread_cb_##name __attribute__((section(".bss.os.thread.cb"))); \ +const osThreadDef_t os_thread_def_##name = \ +{ (name), \ + { NULL, osThreadDetached, \ + (&os_thread_cb_##name),\ + osRtxThreadCbSize, \ + (stacksz) ? (&os_thread_stack##name) : NULL, \ + 8*((stacksz+7)/8), \ + (priority), 0U, 0U } } +#endif +#endif + +/// Access a Thread definition. +/// \param name name of the thread definition object. +#define osThread(name) \ +&os_thread_def_##name + +/// Create a thread and add it to Active Threads and set it to state READY. +/// \param[in] thread_def thread definition referenced with \ref osThread. +/// \param[in] argument pointer that is passed to the thread function as start argument. +/// \return thread ID for reference by other functions or NULL in case of error. +osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument); + +/// Return the thread ID of the current running thread. +/// \return thread ID for reference by other functions or NULL in case of error. +#if (osCMSIS < 0x20000U) +osThreadId osThreadGetId (void); +#endif + +/// Change priority of a thread. +/// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. +/// \param[in] priority new priority value for the thread function. +/// \return status code that indicates the execution status of the function. +#if (osCMSIS < 0x20000U) +osStatus osThreadSetPriority (osThreadId thread_id, osPriority priority); +#endif + +/// Get current priority of a thread. +/// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. +/// \return current priority value of the specified thread. +#if (osCMSIS < 0x20000U) +osPriority osThreadGetPriority (osThreadId thread_id); +#endif + +/// Pass control to next thread that is in state \b READY. +/// \return status code that indicates the execution status of the function. +#if (osCMSIS < 0x20000U) +osStatus osThreadYield (void); +#endif + +/// Terminate execution of a thread. +/// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. +/// \return status code that indicates the execution status of the function. +#if (osCMSIS < 0x20000U) +osStatus osThreadTerminate (osThreadId thread_id); +#endif + + +// ==== Signal Management ==== + +/// Set the specified Signal Flags of an active thread. +/// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. +/// \param[in] signals specifies the signal flags of the thread that should be set. +/// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters. +int32_t osSignalSet (osThreadId thread_id, int32_t signals); + +/// Clear the specified Signal Flags of an active thread. +/// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. +/// \param[in] signals specifies the signal flags of the thread that shall be cleared. +/// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters or call from ISR. +int32_t osSignalClear (osThreadId thread_id, int32_t signals); + +/// Wait for one or more Signal Flags to become signaled for the current \b RUNNING thread. +/// \param[in] signals wait until all specified signal flags set or 0 for any single signal flag. +/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +/// \return event flag information or error code. +os_InRegs osEvent osSignalWait (int32_t signals, uint32_t millisec); + + +// ==== Generic Wait Functions ==== + +/// Wait for Timeout (Time Delay). +/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "time delay" value +/// \return status code that indicates the execution status of the function. +#if (osCMSIS < 0x20000U) +osStatus osDelay (uint32_t millisec); +#endif + +#if (defined (osFeature_Wait) && (osFeature_Wait != 0)) // Generic Wait available + +/// Wait for Signal, Message, Mail, or Timeout. +/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out +/// \return event that contains signal, message, or mail information or error code. +os_InRegs osEvent osWait (uint32_t millisec); + +#endif // Generic Wait available + + +// ==== Timer Management Functions ==== + +/// Define a Timer object. +/// \param name name of the timer object. +/// \param function name of the timer call back function. +#if defined (osObjectsExternal) // object is external +#define osTimerDef(name, function) \ +extern const osTimerDef_t os_timer_def_##name +#else // define the object +#if (osCMSIS < 0x20000U) +#define osTimerDef(name, function) \ +const osTimerDef_t os_timer_def_##name = { (function) } +#else +#define osTimerDef(name, function) \ +static osRtxTimer_t os_timer_cb_##name __attribute__((section(".bss.os.timer.cb"))); \ +const osTimerDef_t os_timer_def_##name = \ +{ (function), { NULL, 0U, (&os_timer_cb_##name), osRtxTimerCbSize } } +#endif +#endif + +/// Access a Timer definition. +/// \param name name of the timer object. +#define osTimer(name) \ +&os_timer_def_##name + +/// Create and Initialize a timer. +/// \param[in] timer_def timer object referenced with \ref osTimer. +/// \param[in] type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior. +/// \param[in] argument argument to the timer call back function. +/// \return timer ID for reference by other functions or NULL in case of error. +osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument); + +/// Start or restart a timer. +/// \param[in] timer_id timer ID obtained by \ref osTimerCreate. +/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "time delay" value of the timer. +/// \return status code that indicates the execution status of the function. +#if (osCMSIS < 0x20000U) +osStatus osTimerStart (osTimerId timer_id, uint32_t millisec); +#endif + +/// Stop a timer. +/// \param[in] timer_id timer ID obtained by \ref osTimerCreate. +/// \return status code that indicates the execution status of the function. +#if (osCMSIS < 0x20000U) +osStatus osTimerStop (osTimerId timer_id); +#endif + +/// Delete a timer. +/// \param[in] timer_id timer ID obtained by \ref osTimerCreate. +/// \return status code that indicates the execution status of the function. +#if (osCMSIS < 0x20000U) +osStatus osTimerDelete (osTimerId timer_id); +#endif + + +// ==== Mutex Management Functions ==== + +/// Define a Mutex. +/// \param name name of the mutex object. +#if defined (osObjectsExternal) // object is external +#define osMutexDef(name) \ +extern const osMutexDef_t os_mutex_def_##name +#else // define the object +#if (osCMSIS < 0x20000U) +#define osMutexDef(name) \ +const osMutexDef_t os_mutex_def_##name = { 0 } +#else +#define osMutexDef(name) \ +static osRtxMutex_t os_mutex_cb_##name __attribute__((section(".bss.os.mutex.cb"))); \ +const osMutexDef_t os_mutex_def_##name = \ +{ NULL, osMutexRecursive | osMutexPrioInherit | osMutexRobust, (&os_mutex_cb_##name), osRtxMutexCbSize } +#endif +#endif + +/// Access a Mutex definition. +/// \param name name of the mutex object. +#define osMutex(name) \ +&os_mutex_def_##name + +/// Create and Initialize a Mutex object. +/// \param[in] mutex_def mutex definition referenced with \ref osMutex. +/// \return mutex ID for reference by other functions or NULL in case of error. +osMutexId osMutexCreate (const osMutexDef_t *mutex_def); + +/// Wait until a Mutex becomes available. +/// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate. +/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +/// \return status code that indicates the execution status of the function. +#if (osCMSIS < 0x20000U) +osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec); +#else +#define osMutexWait osMutexAcquire +#endif + +/// Release a Mutex that was obtained by \ref osMutexWait. +/// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate. +/// \return status code that indicates the execution status of the function. +#if (osCMSIS < 0x20000U) +osStatus osMutexRelease (osMutexId mutex_id); +#endif + +/// Delete a Mutex object. +/// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate. +/// \return status code that indicates the execution status of the function. +#if (osCMSIS < 0x20000U) +osStatus osMutexDelete (osMutexId mutex_id); +#endif + + +// ==== Semaphore Management Functions ==== + +#if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0U)) // Semaphore available + +/// Define a Semaphore object. +/// \param name name of the semaphore object. +#if defined (osObjectsExternal) // object is external +#define osSemaphoreDef(name) \ +extern const osSemaphoreDef_t os_semaphore_def_##name +#else // define the object +#if (osCMSIS < 0x20000U) +#define osSemaphoreDef(name) \ +const osSemaphoreDef_t os_semaphore_def_##name = { 0 } +#else +#define osSemaphoreDef(name) \ +static osRtxSemaphore_t os_semaphore_cb_##name __attribute__((section(".bss.os.semaphore.cb"))); \ +const osSemaphoreDef_t os_semaphore_def_##name = \ +{ NULL, 0U, (&os_semaphore_cb_##name), osRtxSemaphoreCbSize } +#endif +#endif + +/// Access a Semaphore definition. +/// \param name name of the semaphore object. +#define osSemaphore(name) \ +&os_semaphore_def_##name + +/// Create and Initialize a Semaphore object. +/// \param[in] semaphore_def semaphore definition referenced with \ref osSemaphore. +/// \param[in] count maximum and initial number of available tokens. +/// \return semaphore ID for reference by other functions or NULL in case of error. +osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count); + +/// Wait until a Semaphore token becomes available. +/// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate. +/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +/// \return number of available tokens, or -1 in case of incorrect parameters. +int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec); + +/// Release a Semaphore token. +/// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate. +/// \return status code that indicates the execution status of the function. +#if (osCMSIS < 0x20000U) +osStatus osSemaphoreRelease (osSemaphoreId semaphore_id); +#endif + +/// Delete a Semaphore object. +/// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate. +/// \return status code that indicates the execution status of the function. +#if (osCMSIS < 0x20000U) +osStatus osSemaphoreDelete (osSemaphoreId semaphore_id); +#endif + +#endif // Semaphore available + + +// ==== Memory Pool Management Functions ==== + +#if (defined(osFeature_Pool) && (osFeature_Pool != 0)) // Memory Pool available + +/// \brief Define a Memory Pool. +/// \param name name of the memory pool. +/// \param no maximum number of blocks (objects) in the memory pool. +/// \param type data type of a single block (object). +#if defined (osObjectsExternal) // object is external +#define osPoolDef(name, no, type) \ +extern const osPoolDef_t os_pool_def_##name +#else // define the object +#if (osCMSIS < 0x20000U) +#define osPoolDef(name, no, type) \ +const osPoolDef_t os_pool_def_##name = \ +{ (no), sizeof(type), NULL } +#else +#define osPoolDef(name, no, type) \ +static osRtxMemoryPool_t os_mp_cb_##name __attribute__((section(".bss.os.mempool.cb"))); \ +static uint32_t os_mp_data_##name[osRtxMemoryPoolMemSize((no),sizeof(type))/4] __attribute__((section(".bss.os.mempool.mem"))); \ +const osPoolDef_t os_pool_def_##name = \ +{ (no), sizeof(type), \ + { NULL, 0U, (&os_mp_cb_##name), osRtxMemoryPoolCbSize, \ + (&os_mp_data_##name), sizeof(os_mp_data_##name) } } +#endif +#endif + +/// \brief Access a Memory Pool definition. +/// \param name name of the memory pool +#define osPool(name) \ +&os_pool_def_##name + +/// Create and Initialize a Memory Pool object. +/// \param[in] pool_def memory pool definition referenced with \ref osPool. +/// \return memory pool ID for reference by other functions or NULL in case of error. +osPoolId osPoolCreate (const osPoolDef_t *pool_def); + +/// Allocate a memory block from a Memory Pool. +/// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate. +/// \return address of the allocated memory block or NULL in case of no memory available. +void *osPoolAlloc (osPoolId pool_id); + +/// Allocate a memory block from a Memory Pool and set memory block to zero. +/// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate. +/// \return address of the allocated memory block or NULL in case of no memory available. +void *osPoolCAlloc (osPoolId pool_id); + +/// Return an allocated memory block back to a Memory Pool. +/// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate. +/// \param[in] block address of the allocated memory block to be returned to the memory pool. +/// \return status code that indicates the execution status of the function. +osStatus osPoolFree (osPoolId pool_id, void *block); + +#endif // Memory Pool available + + +// ==== Message Queue Management Functions ==== + +#if (defined(osFeature_MessageQ) && (osFeature_MessageQ != 0)) // Message Queue available + +/// \brief Create a Message Queue Definition. +/// \param name name of the queue. +/// \param queue_sz maximum number of messages in the queue. +/// \param type data type of a single message element (for debugger). +#if defined (osObjectsExternal) // object is external +#define osMessageQDef(name, queue_sz, type) \ +extern const osMessageQDef_t os_messageQ_def_##name +#else // define the object +#if (osCMSIS < 0x20000U) +#define osMessageQDef(name, queue_sz, type) \ +const osMessageQDef_t os_messageQ_def_##name = \ +{ (queue_sz), NULL } +#else +#define osMessageQDef(name, queue_sz, type) \ +static osRtxMessageQueue_t os_mq_cb_##name __attribute__((section(".bss.os.msgqueue.cb"))); \ +static uint32_t os_mq_data_##name[osRtxMessageQueueMemSize((queue_sz),sizeof(uint32_t))/4] __attribute__((section(".bss.os.msgqueue.mem"))); \ +const osMessageQDef_t os_messageQ_def_##name = \ +{ (queue_sz), \ + { NULL, 0U, (&os_mq_cb_##name), osRtxMessageQueueCbSize, \ + (&os_mq_data_##name), sizeof(os_mq_data_##name) } } +#endif +#endif + +/// \brief Access a Message Queue Definition. +/// \param name name of the queue +#define osMessageQ(name) \ +&os_messageQ_def_##name + +/// Create and Initialize a Message Queue object. +/// \param[in] queue_def message queue definition referenced with \ref osMessageQ. +/// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL. +/// \return message queue ID for reference by other functions or NULL in case of error. +osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId thread_id); + +/// Put a Message to a Queue. +/// \param[in] queue_id message queue ID obtained with \ref osMessageCreate. +/// \param[in] info message information. +/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +/// \return status code that indicates the execution status of the function. +osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec); + +/// Get a Message from a Queue or timeout if Queue is empty. +/// \param[in] queue_id message queue ID obtained with \ref osMessageCreate. +/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +/// \return event information that includes status code. +os_InRegs osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec); + +#endif // Message Queue available + + +// ==== Mail Queue Management Functions ==== + +#if (defined(osFeature_MailQ) && (osFeature_MailQ != 0)) // Mail Queue available + +/// \brief Create a Mail Queue Definition. +/// \param name name of the queue. +/// \param queue_sz maximum number of mails in the queue. +/// \param type data type of a single mail element. +#if defined (osObjectsExternal) // object is external +#define osMailQDef(name, queue_sz, type) \ +extern const osMailQDef_t os_mailQ_def_##name +#else // define the object +#if (osCMSIS < 0x20000U) +#define osMailQDef(name, queue_sz, type) \ +const osMailQDef_t os_mailQ_def_##name = \ +{ (queue_sz), sizeof(type), NULL } +#else +#define osMailQDef(name, queue_sz, type) \ +static void *os_mail_p_##name[2] __attribute__((section(".bss.os"))); \ +static osRtxMemoryPool_t os_mail_mp_cb_##name __attribute__((section(".bss.os.mempool.cb"))); \ +static osRtxMessageQueue_t os_mail_mq_cb_##name __attribute__((section(".bss.os.msgqueue.cb"))); \ +static uint32_t os_mail_mp_data_##name[osRtxMemoryPoolMemSize ((queue_sz),sizeof(type) )/4] __attribute__((section(".bss.os.mempool.mem"))); \ +static uint32_t os_mail_mq_data_##name[osRtxMessageQueueMemSize((queue_sz),sizeof(void*))/4] __attribute__((section(".bss.os.msgqueue.mem"))); \ +const osMailQDef_t os_mailQ_def_##name = \ +{ (queue_sz), sizeof(type), (&os_mail_p_##name), \ + { NULL, 0U, (&os_mail_mp_cb_##name), osRtxMemoryPoolCbSize, \ + (&os_mail_mp_data_##name), sizeof(os_mail_mp_data_##name) }, \ + { NULL, 0U, (&os_mail_mq_cb_##name), osRtxMessageQueueCbSize, \ + (&os_mail_mq_data_##name), sizeof(os_mail_mq_data_##name) } } +#endif +#endif + +/// \brief Access a Mail Queue Definition. +/// \param name name of the queue +#define osMailQ(name) \ +&os_mailQ_def_##name + +/// Create and Initialize a Mail Queue object. +/// \param[in] queue_def mail queue definition referenced with \ref osMailQ. +/// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL. +/// \return mail queue ID for reference by other functions or NULL in case of error. +osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id); + +/// Allocate a memory block for mail from a mail memory pool. +/// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. +/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out +/// \return pointer to memory block that can be filled with mail or NULL in case of error. +void *osMailAlloc (osMailQId queue_id, uint32_t millisec); + +/// Allocate a memory block for mail from a mail memory pool and set memory block to zero. +/// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. +/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out +/// \return pointer to memory block that can be filled with mail or NULL in case of error. +void *osMailCAlloc (osMailQId queue_id, uint32_t millisec); + +/// Put a Mail into a Queue. +/// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. +/// \param[in] mail pointer to memory with mail to put into a queue. +/// \return status code that indicates the execution status of the function. +osStatus osMailPut (osMailQId queue_id, const void *mail); + +/// Get a Mail from a Queue or timeout if Queue is empty. +/// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. +/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +/// \return event information that includes status code. +os_InRegs osEvent osMailGet (osMailQId queue_id, uint32_t millisec); + +/// Free a memory block by returning it to a mail memory pool. +/// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. +/// \param[in] mail pointer to memory block that was obtained with \ref osMailGet. +/// \return status code that indicates the execution status of the function. +osStatus osMailFree (osMailQId queue_id, void *mail); + +#endif // Mail Queue available + + +#ifdef __cplusplus +} +#endif + +#endif // CMSIS_OS_H_ diff --git a/rtos/TARGET_CORTEX/rtx4/cmsis_os1.c b/rtos/TARGET_CORTEX/rtx4/cmsis_os1.c new file mode 100644 index 0000000..a68eb0a --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx4/cmsis_os1.c @@ -0,0 +1,371 @@ +/* + * Copyright (c) 2013-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ---------------------------------------------------------------------- + * + * $Date: 10. January 2017 + * $Revision: V1.2 + * + * Project: CMSIS-RTOS API V1 + * Title: cmsis_os_v1.c V1 module file + *---------------------------------------------------------------------------*/ + +#include +#include "cmsis_os.h" + +#if (osCMSIS >= 0x20000U) && !defined(os1_Disable) + + +// Thread +#if !defined(os1_Disable_Thread) +osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument) { + + if (thread_def == NULL) { + return NULL; + } + return osThreadNew((osThreadFunc_t)thread_def->pthread, argument, &thread_def->attr); +} +#endif + + +// Signals + +#if !defined(os1_Disable_Signal) + +#define SignalMask ((1U< 0U) && (flags < 0x80000000U)) { + event.status = osEventSignal; + event.value.signals = (int32_t)flags; + } else { + switch ((int32_t)flags) { + case osErrorResource: + event.status = osOK; + break; + case osErrorTimeout: + event.status = osEventTimeout; + break; + case osErrorParameter: + event.status = osErrorValue; + break; + default: + event.status = (osStatus)flags; + break; + } + } + return event; +} + +#endif // Signal + + +// Timer +#if !defined(os1_Disable_Timer) +osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument) { + + if (timer_def == NULL) { + return NULL; + } + return osTimerNew((osTimerFunc_t)timer_def->ptimer, type, argument, &timer_def->attr); +} +#endif + + +// Mutex +#if !defined(os1_Disable_Mutex) +osMutexId osMutexCreate (const osMutexDef_t *mutex_def) { + + if (mutex_def == NULL) { + return NULL; + } + return osMutexNew(mutex_def); +} +#endif + + +// Semaphore + +#if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0U)) && !defined(os1_Disable_Semaphore) + +osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count) { + + if (semaphore_def == NULL) { + return NULL; + } + return osSemaphoreNew((uint32_t)count, (uint32_t)count, semaphore_def); +} + +int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec) { + osStatus_t status; + uint32_t count; + + status = osSemaphoreAcquire(semaphore_id, millisec); + switch (status) { + case osOK: + count = osSemaphoreGetCount(semaphore_id); + return ((int32_t)count + 1); + case osErrorResource: + case osErrorTimeout: + return 0; + default: + break; + } + return -1; +} + +#endif // Semaphore + + +// Memory Pool + +#if (defined(osFeature_Pool) && (osFeature_Pool != 0))&& !defined(os1_Disable_Pool) + +osPoolId osPoolCreate (const osPoolDef_t *pool_def) { + + if (pool_def == NULL) { + return NULL; + } + return osMemoryPoolNew(pool_def->pool_sz, pool_def->item_sz, &pool_def->attr); +} + +void *osPoolAlloc (osPoolId pool_id) { + return osMemoryPoolAlloc(pool_id, 0U); +} + +void *osPoolCAlloc (osPoolId pool_id) { + void *block; + uint32_t block_size; + + block_size = osMemoryPoolGetBlockSize((osMemoryPoolId_t)pool_id); + if (block_size == 0U) { + return NULL; + } + block = osMemoryPoolAlloc(pool_id, 0U); + if (block != NULL) { + memset(block, 0, block_size); + } + return block; +} + +osStatus osPoolFree (osPoolId pool_id, void *block) { + return osMemoryPoolFree(pool_id, block); +} + +#endif // Memory Pool + + +// Message Queue + +#if (defined(osFeature_MessageQ) && (osFeature_MessageQ != 0)) && !defined(os1_Disable_MessageQ) + +osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId thread_id) { + (void)thread_id; + + if (queue_def == NULL) { + return NULL; + } + return osMessageQueueNew(queue_def->queue_sz, sizeof(uint32_t), &queue_def->attr); +} + +osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec) { + return osMessageQueuePut(queue_id, &info, 0U, millisec); +} + +os_InRegs osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec) { + osStatus_t status; + osEvent event; + uint32_t message; + + status = osMessageQueueGet(queue_id, &message, NULL, millisec); + switch (status) { + case osOK: + event.status = osEventMessage; + event.value.v = message; + break; + case osErrorResource: + event.status = osOK; + break; + case osErrorTimeout: + event.status = osEventTimeout; + break; + default: + event.status = status; + break; + } + return event; +} + +#endif // Message Queue + + +// Mail Queue + +#if (defined(osFeature_MailQ) && (osFeature_MailQ != 0)) && !defined(os1_Disable_MailQ) + +typedef struct os_mail_queue_s { + osMemoryPoolId_t mp_id; + osMessageQueueId_t mq_id; +} os_mail_queue_t; + +osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id) { + os_mail_queue_t *ptr; + (void)thread_id; + + if (queue_def == NULL) { + return NULL; + } + + ptr = queue_def->mail; + if (ptr == NULL) { + return NULL; + } + + ptr->mp_id = osMemoryPoolNew (queue_def->queue_sz, queue_def->item_sz, &queue_def->mp_attr); + ptr->mq_id = osMessageQueueNew(queue_def->queue_sz, sizeof(void *), &queue_def->mq_attr); + if ((ptr->mp_id == NULL) || (ptr->mq_id == NULL)) { + if (ptr->mp_id != NULL) { + osMemoryPoolDelete(ptr->mp_id); + } + if (ptr->mq_id != NULL) { + osMessageQueueDelete(ptr->mq_id); + } + return NULL; + } + + return ptr; +} + +void *osMailAlloc (osMailQId queue_id, uint32_t millisec) { + os_mail_queue_t *ptr = (os_mail_queue_t *)queue_id; + + if (ptr == NULL) { + return NULL; + } + return osMemoryPoolAlloc(ptr->mp_id, millisec); +} + +void *osMailCAlloc (osMailQId queue_id, uint32_t millisec) { + os_mail_queue_t *ptr = (os_mail_queue_t *)queue_id; + void *block; + uint32_t block_size; + + if (ptr == NULL) { + return NULL; + } + block_size = osMemoryPoolGetBlockSize(ptr->mp_id); + if (block_size == 0U) { + return NULL; + } + block = osMemoryPoolAlloc(ptr->mp_id, millisec); + if (block != NULL) { + memset(block, 0, block_size); + } + + return block; + +} + +osStatus osMailPut (osMailQId queue_id, const void *mail) { + os_mail_queue_t *ptr = (os_mail_queue_t *)queue_id; + + if (ptr == NULL) { + return osErrorParameter; + } + if (mail == NULL) { + return osErrorValue; + } + return osMessageQueuePut(ptr->mq_id, &mail, 0U, 0U); +} + +os_InRegs osEvent osMailGet (osMailQId queue_id, uint32_t millisec) { + os_mail_queue_t *ptr = (os_mail_queue_t *)queue_id; + osStatus_t status; + osEvent event; + void *mail; + + if (ptr == NULL) { + event.status = osErrorParameter; + return event; + } + + status = osMessageQueueGet(ptr->mq_id, &mail, NULL, millisec); + switch (status) { + case osOK: + event.status = osEventMail; + event.value.p = mail; + break; + case osErrorResource: + event.status = osOK; + break; + case osErrorTimeout: + event.status = osEventTimeout; + break; + default: + event.status = status; + break; + } + return event; +} + +osStatus osMailFree (osMailQId queue_id, void *mail) { + os_mail_queue_t *ptr = (os_mail_queue_t *)queue_id; + + if (ptr == NULL) { + return osErrorParameter; + } + if (mail == NULL) { + return osErrorValue; + } + return osMemoryPoolFree(ptr->mp_id, mail); +} + +#endif // Mail Queue + + +#endif // osCMSIS diff --git a/rtos/TARGET_CORTEX/rtx5/RTX_Config.c b/rtos/TARGET_CORTEX/rtx5/RTX_Config.c new file mode 100644 index 0000000..6572cf0 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/RTX_Config.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2013-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * + * $Revision: V5.1.0 + * + * Project: CMSIS-RTOS RTX + * Title: RTX Configuration + * + * ----------------------------------------------------------------------------- + */ + +#include "cmsis_compiler.h" +#include "rtx_os.h" + +// OS Idle Thread +__WEAK __NO_RETURN void osRtxIdleThread (void *argument) { + (void)argument; + + for (;;) {} +} + +// OS Error Callback function +__WEAK uint32_t osRtxErrorNotify (uint32_t code, void *object_id) { + (void)object_id; + + switch (code) { + case osRtxErrorStackUnderflow: + // Stack underflow detected for thread (thread_id=object_id) + break; + case osRtxErrorISRQueueOverflow: + // ISR Queue overflow detected when inserting object (object_id) + break; + case osRtxErrorTimerQueueOverflow: + // User Timer Callback Queue overflow detected for timer (timer_id=object_id) + break; + case osRtxErrorClibSpace: + // Standard C/C++ library libspace not available: increase OS_THREAD_LIBSPACE_NUM + break; + case osRtxErrorClibMutex: + // Standard C/C++ library mutex initialization failed + break; + default: + break; + } + for (;;) {} +//return 0U; +} diff --git a/rtos/TARGET_CORTEX/rtx5/RTX_Config.h b/rtos/TARGET_CORTEX/rtx5/RTX_Config.h new file mode 100644 index 0000000..1a0ea44 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/RTX_Config.h @@ -0,0 +1,384 @@ +/** \addtogroup rtos */ +/** @{*/ +/* + * Copyright (c) 2013-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * + * $Revision: V5.1.0 + * + * Project: CMSIS-RTOS RTX + * Title: RTX Configuration definitions + * + * ----------------------------------------------------------------------------- + */ + +#ifndef RTX_CONFIG_H_ +#define RTX_CONFIG_H_ + +#include "mbed_rtx_conf.h" + +//-------- <<< Use Configuration Wizard in Context Menu >>> -------------------- + +// System Configuration +// ======================= + +// Global Dynamic Memory size [bytes] <0-1073741824:8> +// Defines the combined global dynamic memory size. +// Default: 4096 +#ifndef OS_DYNAMIC_MEM_SIZE +#define OS_DYNAMIC_MEM_SIZE 4096 +#endif + +// Kernel Tick Frequency [Hz] <1-1000000> +// Defines base time unit for delays and timeouts. +// Default: 1000 (1ms tick) +#ifndef OS_TICK_FREQ +#define OS_TICK_FREQ 1000 +#endif + +// Round-Robin Thread switching +// Enables Round-Robin Thread switching. +#ifndef OS_ROBIN_ENABLE +#define OS_ROBIN_ENABLE 1 +#endif + +// Round-Robin Timeout <1-1000> +// Defines how many ticks a thread will execute before a thread switch. +// Default: 5 +#ifndef OS_ROBIN_TIMEOUT +#define OS_ROBIN_TIMEOUT 5 +#endif + +// + +// Event Recording + +// Memory Management +// Enables Memory Management events recording. +#ifndef OS_EVR_MEMORY +#define OS_EVR_MEMORY 1 +#endif + +// Kernel +// Enables Kernel events recording. +#ifndef OS_EVR_KERNEL +#define OS_EVR_KERNEL 1 +#endif + +// Thread +// Enables Thread events recording. +#ifndef OS_EVR_THREAD +#define OS_EVR_THREAD 1 +#endif + +// Timer +// Enables Timer events recording. +#ifndef OS_EVR_TIMER +#define OS_EVR_TIMER 1 +#endif + +// Event Flags +// Enables Event Flags events recording. +#ifndef OS_EVR_EVFLAGS +#define OS_EVR_EVFLAGS 1 +#endif + +// Mutex +// Enables Mutex events recording. +#ifndef OS_EVR_MUTEX +#define OS_EVR_MUTEX 1 +#endif + +// Semaphore +// Enables Semaphore events recording. +#ifndef OS_EVR_SEMAPHORE +#define OS_EVR_SEMAPHORE 1 +#endif + +// Memory Pool +// Enables Memory Pool events recording. +#ifndef OS_EVR_MEMPOOL +#define OS_EVR_MEMPOOL 1 +#endif + +// Message Queue +// Enables Message Queue events recording. +#ifndef OS_EVR_MSGQUEUE +#define OS_EVR_MSGQUEUE 1 +#endif + +// + +// ISR FIFO Queue +// <4=> 4 entries <8=> 8 entries <12=> 12 entries <16=> 16 entries +// <24=> 24 entries <32=> 32 entries <48=> 48 entries <64=> 64 entries +// <96=> 96 entries <128=> 128 entries <196=> 196 entries <256=> 256 entries +// RTOS Functions called from ISR store requests to this buffer. +// Default: 16 entries +#ifndef OS_ISR_FIFO_QUEUE +#define OS_ISR_FIFO_QUEUE 16 +#endif + +// + +// Thread Configuration +// ======================= + +// Object specific Memory allocation +// Enables object specific memory allocation. +#ifndef OS_THREAD_OBJ_MEM +#define OS_THREAD_OBJ_MEM 0 +#endif + +// Number of user Threads <1-1000> +// Defines maximum number of user threads that can be active at the same time. +// Applies to user threads with system provided memory for control blocks. +#ifndef OS_THREAD_NUM +#define OS_THREAD_NUM 1 +#endif + +// Number of user Threads with default Stack size <0-1000> +// Defines maximum number of user threads with default stack size. +// Applies to user threads with zero stack size specified. +#ifndef OS_THREAD_DEF_STACK_NUM +#define OS_THREAD_DEF_STACK_NUM 0 +#endif + +// Total Stack size [bytes] for user Threads with user-provided Stack size <0-1073741824:8> +// Defines the combined stack size for user threads with user-provided stack size. +// Applies to user threads with user-provided stack size and system provided memory for stack. +// Default: 0 +#ifndef OS_THREAD_USER_STACK_SIZE +#define OS_THREAD_USER_STACK_SIZE 0 +#endif + +// + +// Default Thread Stack size [bytes] <96-1073741824:8> +// Defines stack size for threads with zero stack size specified. +// Default: 200 +#ifndef OS_STACK_SIZE +#define OS_STACK_SIZE 200 +#endif + +// Idle Thread Stack size [bytes] <72-1073741824:8> +// Defines stack size for Idle thread. +// Default: 200 +#ifndef OS_IDLE_THREAD_STACK_SIZE +#define OS_IDLE_THREAD_STACK_SIZE 200 +#endif + +// Stack overrun checking +// Enable stack overrun checks at thread switch. +// Enabling this option increases slightly the execution time of a thread switch. +#ifndef OS_STACK_CHECK +#define OS_STACK_CHECK 1 +#endif + +// Stack usage watermark +// Initialize thread stack with watermark pattern for analyzing stack usage. +// Enabling this option increases significantly the execution time of thread creation. +#ifndef OS_STACK_WATERMARK +#define OS_STACK_WATERMARK 0 +#endif + +// Processor mode for Thread execution +// <0=> Unprivileged mode +// <1=> Privileged mode +// Default: Privileged mode +#ifndef OS_PRIVILEGE_MODE +#define OS_PRIVILEGE_MODE 1 +#endif + +// + +// Timer Configuration +// ====================== + +// Object specific Memory allocation +// Enables object specific memory allocation. +#ifndef OS_TIMER_OBJ_MEM +#define OS_TIMER_OBJ_MEM 0 +#endif + +// Number of Timer objects <1-1000> +// Defines maximum number of objects that can be active at the same time. +// Applies to objects with system provided memory for control blocks. +#ifndef OS_TIMER_NUM +#define OS_TIMER_NUM 1 +#endif + +// + +// Timer Thread Priority +// <8=> Low +// <16=> Below Normal <24=> Normal <32=> Above Normal +// <40=> High +// <48=> Realtime +// Defines priority for timer thread +// Default: High +#ifndef OS_TIMER_THREAD_PRIO +#define OS_TIMER_THREAD_PRIO 40 +#endif + +// Timer Thread Stack size [bytes] <0-1073741824:8> +// Defines stack size for Timer thread. +// May be set to 0 when timers are not used. +// Default: 200 +#ifndef OS_TIMER_THREAD_STACK_SIZE +#define OS_TIMER_THREAD_STACK_SIZE 200 +#endif + +// Timer Callback Queue entries <0-256> +// Number of concurrent active timer callback functions. +// May be set to 0 when timers are not used. +// Default: 4 +#ifndef OS_TIMER_CB_QUEUE +#define OS_TIMER_CB_QUEUE 4 +#endif + +// + +// Event Flags Configuration +// ============================ + +// Object specific Memory allocation +// Enables object specific memory allocation. +#ifndef OS_EVFLAGS_OBJ_MEM +#define OS_EVFLAGS_OBJ_MEM 0 +#endif + +// Number of Event Flags objects <1-1000> +// Defines maximum number of objects that can be active at the same time. +// Applies to objects with system provided memory for control blocks. +#ifndef OS_EVFLAGS_NUM +#define OS_EVFLAGS_NUM 1 +#endif + +// + +// + +// Mutex Configuration +// ====================== + +// Object specific Memory allocation +// Enables object specific memory allocation. +#ifndef OS_MUTEX_OBJ_MEM +#define OS_MUTEX_OBJ_MEM 0 +#endif + +// Number of Mutex objects <1-1000> +// Defines maximum number of objects that can be active at the same time. +// Applies to objects with system provided memory for control blocks. +#ifndef OS_MUTEX_NUM +#define OS_MUTEX_NUM 1 +#endif + +// + +// + +// Semaphore Configuration +// ========================== + +// Object specific Memory allocation +// Enables object specific memory allocation. +#ifndef OS_SEMAPHORE_OBJ_MEM +#define OS_SEMAPHORE_OBJ_MEM 0 +#endif + +// Number of Semaphore objects <1-1000> +// Defines maximum number of objects that can be active at the same time. +// Applies to objects with system provided memory for control blocks. +#ifndef OS_SEMAPHORE_NUM +#define OS_SEMAPHORE_NUM 1 +#endif + +// + +// + +// Memory Pool Configuration +// ============================ + +// Object specific Memory allocation +// Enables object specific memory allocation. +#ifndef OS_MEMPOOL_OBJ_MEM +#define OS_MEMPOOL_OBJ_MEM 0 +#endif + +// Number of Memory Pool objects <1-1000> +// Defines maximum number of objects that can be active at the same time. +// Applies to objects with system provided memory for control blocks. +#ifndef OS_MEMPOOL_NUM +#define OS_MEMPOOL_NUM 1 +#endif + +// Data Storage Memory size [bytes] <0-1073741824:8> +// Defines the combined data storage memory size. +// Applies to objects with system provided memory for data storage. +// Default: 0 +#ifndef OS_MEMPOOL_DATA_SIZE +#define OS_MEMPOOL_DATA_SIZE 0 +#endif + +// + +// + +// Message Queue Configuration +// ============================== + +// Object specific Memory allocation +// Enables object specific memory allocation. +#ifndef OS_MSGQUEUE_OBJ_MEM +#define OS_MSGQUEUE_OBJ_MEM 0 +#endif + +// Number of Message Queue objects <1-1000> +// Defines maximum number of objects that can be active at the same time. +// Applies to objects with system provided memory for control blocks. +#ifndef OS_MSGQUEUE_NUM +#define OS_MSGQUEUE_NUM 1 +#endif + +// Data Storage Memory size [bytes] <0-1073741824:8> +// Defines the combined data storage memory size. +// Applies to objects with system provided memory for data storage. +// Default: 0 +#ifndef OS_MSGQUEUE_DATA_SIZE +#define OS_MSGQUEUE_DATA_SIZE 0 +#endif + +// + +// + +// Number of Threads which use standard C/C++ library libspace +// (when thread specific memory allocation is not used). +#if (OS_THREAD_OBJ_MEM == 0) +#define OS_THREAD_LIBSPACE_NUM 4 +#else +#define OS_THREAD_LIBSPACE_NUM OS_THREAD_NUM +#endif + +//------------- <<< end of configuration section >>> --------------------------- + +#endif // RTX_CONFIG_H_ +/** @}*/ diff --git a/rtos/TARGET_CORTEX/rtx5/TARGET_M0/TOOLCHAIN_ARM/irq_cm0.S b/rtos/TARGET_CORTEX/rtx5/TARGET_M0/TOOLCHAIN_ARM/irq_cm0.S new file mode 100644 index 0000000..74c8a84 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/TARGET_M0/TOOLCHAIN_ARM/irq_cm0.S @@ -0,0 +1,155 @@ +;/* +; * Copyright (c) 2013-2017 ARM Limited. All rights reserved. +; * +; * SPDX-License-Identifier: Apache-2.0 +; * +; * Licensed under the Apache License, Version 2.0 (the License); you may +; * not use this file except in compliance with the License. +; * You may obtain a copy of the License at +; * +; * www.apache.org/licenses/LICENSE-2.0 +; * +; * Unless required by applicable law or agreed to in writing, software +; * distributed under the License is distributed on an AS IS BASIS, WITHOUT +; * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +; * See the License for the specific language governing permissions and +; * limitations under the License. +; * +; * ----------------------------------------------------------------------------- +; * +; * Project: CMSIS-RTOS RTX +; * Title: Cortex-M0 Exception handlers +; * +; * ----------------------------------------------------------------------------- +; */ + + +I_T_RUN_OFS EQU 28 ; osRtxInfo.thread.run offset +TCB_SP_OFS EQU 56 ; TCB.SP offset + + + PRESERVE8 + THUMB + + + AREA |.constdata|, DATA, READONLY + EXPORT irqRtxLib +irqRtxLib DCB 0 ; Non weak library reference + + + AREA |.text|, CODE, READONLY + + +SVC_Handler PROC + EXPORT SVC_Handler + IMPORT osRtxUserSVC + IMPORT osRtxInfo + + MRS R0,PSP ; Get PSP + LDR R1,[R0,#24] ; Load saved PC from stack + SUBS R1,R1,#2 ; Point to SVC instruction + LDRB R1,[R1] ; Load SVC number + CMP R1,#0 + BNE SVC_User ; Branch if not SVC 0 + + PUSH {R0,LR} ; Save PSP and EXC_RETURN + LDMIA R0,{R0-R3} ; Load function parameters from stack + BLX R7 ; Call service function + POP {R2,R3} ; Restore PSP and EXC_RETURN + STMIA R2!,{R0-R1} ; Store function return values + MOV LR,R3 ; Set EXC_RETURN + +SVC_Context + LDR R3,=osRtxInfo+I_T_RUN_OFS; Load address of osRtxInfo.run + LDMIA R3!,{R1,R2} ; Load osRtxInfo.thread.run: curr & next + CMP R1,R2 ; Check if thread switch is required + BEQ SVC_Exit ; Branch when threads are the same + + CMP R1,#0 + BEQ SVC_ContextSwitch ; Branch if running thread is deleted + +SVC_ContextSave + MRS R0,PSP ; Get PSP + SUBS R0,R0,#32 ; Adjust address + STR R0,[R1,#TCB_SP_OFS] ; Store SP + STMIA R0!,{R4-R7} ; Save R4..R7 + MOV R4,R8 + MOV R5,R9 + MOV R6,R10 + MOV R7,R11 + STMIA R0!,{R4-R7} ; Save R8..R11 + +SVC_ContextSwitch + SUBS R3,R3,#8 + STR R2,[R3] ; osRtxInfo.thread.run: curr = next + +SVC_ContextRestore + LDR R0,[R2,#TCB_SP_OFS] ; Load SP + ADDS R0,R0,#16 ; Adjust address + LDMIA R0!,{R4-R7} ; Restore R8..R11 + MOV R8,R4 + MOV R9,R5 + MOV R10,R6 + MOV R11,R7 + MSR PSP,R0 ; Set PSP + SUBS R0,R0,#32 ; Adjust address + LDMIA R0!,{R4-R7} ; Restore R4..R7 + + MOVS R0,#~0xFFFFFFFD + MVNS R0,R0 ; Set EXC_RETURN value + BX R0 ; Exit from handler + +SVC_Exit + BX LR ; Exit from handler + +SVC_User + PUSH {R4,LR} ; Save registers + LDR R2,=osRtxUserSVC ; Load address of SVC table + LDR R3,[R2] ; Load SVC maximum number + CMP R1,R3 ; Check SVC number range + BHI SVC_Done ; Branch if out of range + + LSLS R1,R1,#2 + LDR R4,[R2,R1] ; Load address of SVC function + + LDMIA R0,{R0-R3} ; Load function parameters from stack + BLX R4 ; Call service function + MRS R4,PSP ; Get PSP + STMIA R4!,{R0-R3} ; Store function return values + +SVC_Done + POP {R4,PC} ; Return from handler + + ALIGN + ENDP + + +PendSV_Handler PROC + EXPORT PendSV_Handler + IMPORT osRtxPendSV_Handler + + PUSH {R0,LR} ; Save EXC_RETURN + BL osRtxPendSV_Handler ; Call osRtxPendSV_Handler + POP {R0,R1} ; Restore EXC_RETURN + MOV LR,R1 ; Set EXC_RETURN + B SVC_Context + + ALIGN + ENDP + + +SysTick_Handler PROC + EXPORT SysTick_Handler + IMPORT osRtxTick_Handler + + PUSH {R0,LR} ; Save EXC_RETURN + BL osRtxTick_Handler ; Call osRtxTick_Handler + POP {R0,R1} ; Restore EXC_RETURN + MOV LR,R1 ; Set EXC_RETURN + B SVC_Context + + ALIGN + ENDP + + + END diff --git a/rtos/TARGET_CORTEX/rtx5/TARGET_M0/TOOLCHAIN_GCC/irq_cm0.S b/rtos/TARGET_CORTEX/rtx5/TARGET_M0/TOOLCHAIN_GCC/irq_cm0.S new file mode 100644 index 0000000..5362c19 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/TARGET_M0/TOOLCHAIN_GCC/irq_cm0.S @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2013-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * + * Project: CMSIS-RTOS RTX + * Title: Cortex-M0 Exception handlers + * + * ----------------------------------------------------------------------------- + */ + + + .file "irq_cm0.S" + .syntax unified + + .equ I_T_RUN_OFS, 28 // osRtxInfo.thread.run offset + .equ TCB_SP_OFS, 56 // TCB.SP offset + + .section ".rodata" + .global irqRtxLib // Non weak library reference +irqRtxLib: + .byte 0 + + + .thumb + .section ".text" + .align 2 + + + .thumb_func + .type SVC_Handler, %function + .global SVC_Handler + .fnstart + .cantunwind +SVC_Handler: + + MRS R0,PSP // Get PSP + LDR R1,[R0,#24] // Load saved PC from stack + SUBS R1,R1,#2 // Point to SVC instruction + LDRB R1,[R1] // Load SVC number + CMP R1,#0 + BNE SVC_User // Branch if not SVC 0 + + PUSH {R0,LR} // Save PSP and EXC_RETURN + LDMIA R0,{R0-R3} // Load function parameters from stack + BLX R7 // Call service function + POP {R2,R3} // Restore PSP and EXC_RETURN + STMIA R2!,{R0-R1} // Store function return values + MOV LR,R3 // Set EXC_RETURN + +SVC_Context: + LDR R3,=osRtxInfo+I_T_RUN_OFS // Load address of osRtxInfo.run + LDMIA R3!,{R1,R2} // Load osRtxInfo.thread.run: curr & next + CMP R1,R2 // Check if thread switch is required + BEQ SVC_Exit // Branch when threads are the same + + CMP R1,#0 + BEQ SVC_ContextSwitch // Branch if running thread is deleted + +SVC_ContextSave: + MRS R0,PSP // Get PSP + SUBS R0,R0,#32 // Adjust address + STR R0,[R1,#TCB_SP_OFS]; // Store SP + STMIA R0!,{R4-R7} // Save R4..R7 + MOV R4,R8 + MOV R5,R9 + MOV R6,R10 + MOV R7,R11 + STMIA R0!,{R4-R7} // Save R8..R11 + +SVC_ContextSwitch: + SUBS R3,R3,#8 + STR R2,[R3] // osRtxInfo.thread.run: curr = next + +SVC_ContextRestore: + LDR R0,[R2,#TCB_SP_OFS] // Load SP + ADDS R0,R0,#16 // Adjust address + LDMIA R0!,{R4-R7} // Restore R8..R11 + MOV R8,R4 + MOV R9,R5 + MOV R10,R6 + MOV R11,R7 + MSR PSP,R0 // Set PSP + SUBS R0,R0,#32 // Adjust address + LDMIA R0!,{R4-R7} // Restore R4..R7 + + MOVS R0,#~0xFFFFFFFD + MVNS R0,R0 // Set EXC_RETURN value + BX R0 // Exit from handler + +SVC_Exit: + BX LR // Exit from handler + +SVC_User: + PUSH {R4,LR} // Save registers + LDR R2,=osRtxUserSVC // Load address of SVC table + LDR R3,[R2] // Load SVC maximum number + CMP R1,R3 // Check SVC number range + BHI SVC_Done // Branch if out of range + + LSLS R1,R1,#2 + LDR R4,[R2,R1] // Load address of SVC function + + LDMIA R0,{R0-R3} // Load function parameters from stack + BLX R4 // Call service function + MRS R4,PSP // Get PSP + STMIA R4!,{R0-R3} // Store function return values + +SVC_Done: + POP {R4,PC} // Return from handler + + .fnend + .size SVC_Handler, .-SVC_Handler + + + .thumb_func + .type PendSV_Handler, %function + .global PendSV_Handler + .fnstart + .cantunwind +PendSV_Handler: + + PUSH {R0,LR} // Save EXC_RETURN + BL osRtxPendSV_Handler // Call osRtxPendSV_Handler + POP {R0,R1} // Restore EXC_RETURN + MOV LR,R1 // Set EXC_RETURN + B SVC_Context + + .fnend + .size PendSV_Handler, .-PendSV_Handler + + + .thumb_func + .type SysTick_Handler, %function + .global SysTick_Handler + .fnstart + .cantunwind +SysTick_Handler: + + PUSH {R0,LR} // Save EXC_RETURN + BL osRtxTick_Handler // Call osRtxTick_Handler + POP {R0,R1} // Restore EXC_RETURN + MOV LR,R1 // Set EXC_RETURN + B SVC_Context + + .fnend + .size SysTick_Handler, .-SysTick_Handler + + + .end diff --git a/rtos/TARGET_CORTEX/rtx5/TARGET_M0/TOOLCHAIN_IAR/irq_cm0.S b/rtos/TARGET_CORTEX/rtx5/TARGET_M0/TOOLCHAIN_IAR/irq_cm0.S new file mode 100644 index 0000000..023aae3 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/TARGET_M0/TOOLCHAIN_IAR/irq_cm0.S @@ -0,0 +1,149 @@ +;/* +; * Copyright (c) 2013-2017 ARM Limited. All rights reserved. +; * +; * SPDX-License-Identifier: Apache-2.0 +; * +; * Licensed under the Apache License, Version 2.0 (the License); you may +; * not use this file except in compliance with the License. +; * You may obtain a copy of the License at +; * +; * www.apache.org/licenses/LICENSE-2.0 +; * +; * Unless required by applicable law or agreed to in writing, software +; * distributed under the License is distributed on an AS IS BASIS, WITHOUT +; * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +; * See the License for the specific language governing permissions and +; * limitations under the License. +; * +; * ----------------------------------------------------------------------------- +; * +; * Project: CMSIS-RTOS RTX +; * Title: Cortex-M0 Exception handlers +; * +; * ----------------------------------------------------------------------------- +; */ + + + NAME irq_cm0.s + + +I_T_RUN_OFS EQU 28 ; osRtxInfo.thread.run offset +TCB_SP_OFS EQU 56 ; TCB.SP offset + + + PRESERVE8 + SECTION .rodata:DATA:NOROOT(2) + + + EXPORT irqRtxLib +irqRtxLib DCB 0 ; Non weak library reference + + + THUMB + SECTION .text:CODE:NOROOT(2) + + +SVC_Handler + EXPORT SVC_Handler + IMPORT osRtxUserSVC + IMPORT osRtxInfo + + MRS R0,PSP ; Get PSP + LDR R1,[R0,#24] ; Load saved PC from stack + SUBS R1,R1,#2 ; Point to SVC instruction + LDRB R1,[R1] ; Load SVC number + CMP R1,#0 + BNE SVC_User ; Branch if not SVC 0 + + PUSH {R0,LR} ; Save PSP and EXC_RETURN + LDMIA R0,{R0-R3} ; Load function parameters from stack + BLX R7 ; Call service function + POP {R2,R3} ; Restore PSP and EXC_RETURN + STMIA R2!,{R0-R1} ; Store function return values + MOV LR,R3 ; Set EXC_RETURN + +SVC_Context + LDR R3,=osRtxInfo+I_T_RUN_OFS; Load address of osRtxInfo.run + LDMIA R3!,{R1,R2} ; Load osRtxInfo.thread.run: curr & next + CMP R1,R2 ; Check if thread switch is required + BEQ SVC_Exit ; Branch when threads are the same + + CMP R1,#0 + BEQ SVC_ContextSwitch ; Branch if running thread is deleted + +SVC_ContextSave + MRS R0,PSP ; Get PSP + SUBS R0,R0,#32 ; Adjust address + STR R0,[R1,#TCB_SP_OFS] ; Store SP + STMIA R0!,{R4-R7} ; Save R4..R7 + MOV R4,R8 + MOV R5,R9 + MOV R6,R10 + MOV R7,R11 + STMIA R0!,{R4-R7} ; Save R8..R11 + +SVC_ContextSwitch + SUBS R3,R3,#8 + STR R2,[R3] ; osRtxInfo.thread.run: curr = next + +SVC_ContextRestore + LDR R0,[R2,#TCB_SP_OFS] ; Load SP + ADDS R0,R0,#16 ; Adjust address + LDMIA R0!,{R4-R7} ; Restore R8..R11 + MOV R8,R4 + MOV R9,R5 + MOV R10,R6 + MOV R11,R7 + MSR PSP,R0 ; Set PSP + SUBS R0,R0,#32 ; Adjust address + LDMIA R0!,{R4-R7} ; Restore R4..R7 + + MOVS R0,#~0xFFFFFFFD + MVNS R0,R0 ; Set EXC_RETURN value + BX R0 ; Exit from handler + +SVC_Exit + BX LR ; Exit from handler + +SVC_User + PUSH {R4,LR} ; Save registers + LDR R2,=osRtxUserSVC ; Load address of SVC table + LDR R3,[R2] ; Load SVC maximum number + CMP R1,R3 ; Check SVC number range + BHI SVC_Done ; Branch if out of range + + LSLS R1,R1,#2 + LDR R4,[R2,R1] ; Load address of SVC function + + LDMIA R0,{R0-R3} ; Load function parameters from stack + BLX R4 ; Call service function + MRS R4,PSP ; Get PSP + STMIA R4!,{R0-R3} ; Store function return values + +SVC_Done + POP {R4,PC} ; Return from handler + + +PendSV_Handler + EXPORT PendSV_Handler + IMPORT osRtxPendSV_Handler + + PUSH {R0,LR} ; Save EXC_RETURN + BL osRtxPendSV_Handler ; Call osRtxPendSV_Handler + POP {R0,R1} ; Restore EXC_RETURN + MOV LR,R1 ; Set EXC_RETURN + B SVC_Context + + +SysTick_Handler + EXPORT SysTick_Handler + IMPORT osRtxTick_Handler + + PUSH {R0,LR} ; Save EXC_RETURN + BL osRtxTick_Handler ; Call osRtxTick_Handler + POP {R0,R1} ; Restore EXC_RETURN + MOV LR,R1 ; Set EXC_RETURN + B SVC_Context + + + END diff --git a/rtos/TARGET_CORTEX/rtx5/TARGET_M0P/TOOLCHAIN_ARM/irq_cm0.S b/rtos/TARGET_CORTEX/rtx5/TARGET_M0P/TOOLCHAIN_ARM/irq_cm0.S new file mode 100644 index 0000000..74c8a84 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/TARGET_M0P/TOOLCHAIN_ARM/irq_cm0.S @@ -0,0 +1,155 @@ +;/* +; * Copyright (c) 2013-2017 ARM Limited. All rights reserved. +; * +; * SPDX-License-Identifier: Apache-2.0 +; * +; * Licensed under the Apache License, Version 2.0 (the License); you may +; * not use this file except in compliance with the License. +; * You may obtain a copy of the License at +; * +; * www.apache.org/licenses/LICENSE-2.0 +; * +; * Unless required by applicable law or agreed to in writing, software +; * distributed under the License is distributed on an AS IS BASIS, WITHOUT +; * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +; * See the License for the specific language governing permissions and +; * limitations under the License. +; * +; * ----------------------------------------------------------------------------- +; * +; * Project: CMSIS-RTOS RTX +; * Title: Cortex-M0 Exception handlers +; * +; * ----------------------------------------------------------------------------- +; */ + + +I_T_RUN_OFS EQU 28 ; osRtxInfo.thread.run offset +TCB_SP_OFS EQU 56 ; TCB.SP offset + + + PRESERVE8 + THUMB + + + AREA |.constdata|, DATA, READONLY + EXPORT irqRtxLib +irqRtxLib DCB 0 ; Non weak library reference + + + AREA |.text|, CODE, READONLY + + +SVC_Handler PROC + EXPORT SVC_Handler + IMPORT osRtxUserSVC + IMPORT osRtxInfo + + MRS R0,PSP ; Get PSP + LDR R1,[R0,#24] ; Load saved PC from stack + SUBS R1,R1,#2 ; Point to SVC instruction + LDRB R1,[R1] ; Load SVC number + CMP R1,#0 + BNE SVC_User ; Branch if not SVC 0 + + PUSH {R0,LR} ; Save PSP and EXC_RETURN + LDMIA R0,{R0-R3} ; Load function parameters from stack + BLX R7 ; Call service function + POP {R2,R3} ; Restore PSP and EXC_RETURN + STMIA R2!,{R0-R1} ; Store function return values + MOV LR,R3 ; Set EXC_RETURN + +SVC_Context + LDR R3,=osRtxInfo+I_T_RUN_OFS; Load address of osRtxInfo.run + LDMIA R3!,{R1,R2} ; Load osRtxInfo.thread.run: curr & next + CMP R1,R2 ; Check if thread switch is required + BEQ SVC_Exit ; Branch when threads are the same + + CMP R1,#0 + BEQ SVC_ContextSwitch ; Branch if running thread is deleted + +SVC_ContextSave + MRS R0,PSP ; Get PSP + SUBS R0,R0,#32 ; Adjust address + STR R0,[R1,#TCB_SP_OFS] ; Store SP + STMIA R0!,{R4-R7} ; Save R4..R7 + MOV R4,R8 + MOV R5,R9 + MOV R6,R10 + MOV R7,R11 + STMIA R0!,{R4-R7} ; Save R8..R11 + +SVC_ContextSwitch + SUBS R3,R3,#8 + STR R2,[R3] ; osRtxInfo.thread.run: curr = next + +SVC_ContextRestore + LDR R0,[R2,#TCB_SP_OFS] ; Load SP + ADDS R0,R0,#16 ; Adjust address + LDMIA R0!,{R4-R7} ; Restore R8..R11 + MOV R8,R4 + MOV R9,R5 + MOV R10,R6 + MOV R11,R7 + MSR PSP,R0 ; Set PSP + SUBS R0,R0,#32 ; Adjust address + LDMIA R0!,{R4-R7} ; Restore R4..R7 + + MOVS R0,#~0xFFFFFFFD + MVNS R0,R0 ; Set EXC_RETURN value + BX R0 ; Exit from handler + +SVC_Exit + BX LR ; Exit from handler + +SVC_User + PUSH {R4,LR} ; Save registers + LDR R2,=osRtxUserSVC ; Load address of SVC table + LDR R3,[R2] ; Load SVC maximum number + CMP R1,R3 ; Check SVC number range + BHI SVC_Done ; Branch if out of range + + LSLS R1,R1,#2 + LDR R4,[R2,R1] ; Load address of SVC function + + LDMIA R0,{R0-R3} ; Load function parameters from stack + BLX R4 ; Call service function + MRS R4,PSP ; Get PSP + STMIA R4!,{R0-R3} ; Store function return values + +SVC_Done + POP {R4,PC} ; Return from handler + + ALIGN + ENDP + + +PendSV_Handler PROC + EXPORT PendSV_Handler + IMPORT osRtxPendSV_Handler + + PUSH {R0,LR} ; Save EXC_RETURN + BL osRtxPendSV_Handler ; Call osRtxPendSV_Handler + POP {R0,R1} ; Restore EXC_RETURN + MOV LR,R1 ; Set EXC_RETURN + B SVC_Context + + ALIGN + ENDP + + +SysTick_Handler PROC + EXPORT SysTick_Handler + IMPORT osRtxTick_Handler + + PUSH {R0,LR} ; Save EXC_RETURN + BL osRtxTick_Handler ; Call osRtxTick_Handler + POP {R0,R1} ; Restore EXC_RETURN + MOV LR,R1 ; Set EXC_RETURN + B SVC_Context + + ALIGN + ENDP + + + END diff --git a/rtos/TARGET_CORTEX/rtx5/TARGET_M0P/TOOLCHAIN_GCC/irq_cm0.S b/rtos/TARGET_CORTEX/rtx5/TARGET_M0P/TOOLCHAIN_GCC/irq_cm0.S new file mode 100644 index 0000000..5362c19 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/TARGET_M0P/TOOLCHAIN_GCC/irq_cm0.S @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2013-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * + * Project: CMSIS-RTOS RTX + * Title: Cortex-M0 Exception handlers + * + * ----------------------------------------------------------------------------- + */ + + + .file "irq_cm0.S" + .syntax unified + + .equ I_T_RUN_OFS, 28 // osRtxInfo.thread.run offset + .equ TCB_SP_OFS, 56 // TCB.SP offset + + .section ".rodata" + .global irqRtxLib // Non weak library reference +irqRtxLib: + .byte 0 + + + .thumb + .section ".text" + .align 2 + + + .thumb_func + .type SVC_Handler, %function + .global SVC_Handler + .fnstart + .cantunwind +SVC_Handler: + + MRS R0,PSP // Get PSP + LDR R1,[R0,#24] // Load saved PC from stack + SUBS R1,R1,#2 // Point to SVC instruction + LDRB R1,[R1] // Load SVC number + CMP R1,#0 + BNE SVC_User // Branch if not SVC 0 + + PUSH {R0,LR} // Save PSP and EXC_RETURN + LDMIA R0,{R0-R3} // Load function parameters from stack + BLX R7 // Call service function + POP {R2,R3} // Restore PSP and EXC_RETURN + STMIA R2!,{R0-R1} // Store function return values + MOV LR,R3 // Set EXC_RETURN + +SVC_Context: + LDR R3,=osRtxInfo+I_T_RUN_OFS // Load address of osRtxInfo.run + LDMIA R3!,{R1,R2} // Load osRtxInfo.thread.run: curr & next + CMP R1,R2 // Check if thread switch is required + BEQ SVC_Exit // Branch when threads are the same + + CMP R1,#0 + BEQ SVC_ContextSwitch // Branch if running thread is deleted + +SVC_ContextSave: + MRS R0,PSP // Get PSP + SUBS R0,R0,#32 // Adjust address + STR R0,[R1,#TCB_SP_OFS]; // Store SP + STMIA R0!,{R4-R7} // Save R4..R7 + MOV R4,R8 + MOV R5,R9 + MOV R6,R10 + MOV R7,R11 + STMIA R0!,{R4-R7} // Save R8..R11 + +SVC_ContextSwitch: + SUBS R3,R3,#8 + STR R2,[R3] // osRtxInfo.thread.run: curr = next + +SVC_ContextRestore: + LDR R0,[R2,#TCB_SP_OFS] // Load SP + ADDS R0,R0,#16 // Adjust address + LDMIA R0!,{R4-R7} // Restore R8..R11 + MOV R8,R4 + MOV R9,R5 + MOV R10,R6 + MOV R11,R7 + MSR PSP,R0 // Set PSP + SUBS R0,R0,#32 // Adjust address + LDMIA R0!,{R4-R7} // Restore R4..R7 + + MOVS R0,#~0xFFFFFFFD + MVNS R0,R0 // Set EXC_RETURN value + BX R0 // Exit from handler + +SVC_Exit: + BX LR // Exit from handler + +SVC_User: + PUSH {R4,LR} // Save registers + LDR R2,=osRtxUserSVC // Load address of SVC table + LDR R3,[R2] // Load SVC maximum number + CMP R1,R3 // Check SVC number range + BHI SVC_Done // Branch if out of range + + LSLS R1,R1,#2 + LDR R4,[R2,R1] // Load address of SVC function + + LDMIA R0,{R0-R3} // Load function parameters from stack + BLX R4 // Call service function + MRS R4,PSP // Get PSP + STMIA R4!,{R0-R3} // Store function return values + +SVC_Done: + POP {R4,PC} // Return from handler + + .fnend + .size SVC_Handler, .-SVC_Handler + + + .thumb_func + .type PendSV_Handler, %function + .global PendSV_Handler + .fnstart + .cantunwind +PendSV_Handler: + + PUSH {R0,LR} // Save EXC_RETURN + BL osRtxPendSV_Handler // Call osRtxPendSV_Handler + POP {R0,R1} // Restore EXC_RETURN + MOV LR,R1 // Set EXC_RETURN + B SVC_Context + + .fnend + .size PendSV_Handler, .-PendSV_Handler + + + .thumb_func + .type SysTick_Handler, %function + .global SysTick_Handler + .fnstart + .cantunwind +SysTick_Handler: + + PUSH {R0,LR} // Save EXC_RETURN + BL osRtxTick_Handler // Call osRtxTick_Handler + POP {R0,R1} // Restore EXC_RETURN + MOV LR,R1 // Set EXC_RETURN + B SVC_Context + + .fnend + .size SysTick_Handler, .-SysTick_Handler + + + .end diff --git a/rtos/TARGET_CORTEX/rtx5/TARGET_M0P/TOOLCHAIN_IAR/irq_cm0.S b/rtos/TARGET_CORTEX/rtx5/TARGET_M0P/TOOLCHAIN_IAR/irq_cm0.S new file mode 100644 index 0000000..023aae3 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/TARGET_M0P/TOOLCHAIN_IAR/irq_cm0.S @@ -0,0 +1,149 @@ +;/* +; * Copyright (c) 2013-2017 ARM Limited. All rights reserved. +; * +; * SPDX-License-Identifier: Apache-2.0 +; * +; * Licensed under the Apache License, Version 2.0 (the License); you may +; * not use this file except in compliance with the License. +; * You may obtain a copy of the License at +; * +; * www.apache.org/licenses/LICENSE-2.0 +; * +; * Unless required by applicable law or agreed to in writing, software +; * distributed under the License is distributed on an AS IS BASIS, WITHOUT +; * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +; * See the License for the specific language governing permissions and +; * limitations under the License. +; * +; * ----------------------------------------------------------------------------- +; * +; * Project: CMSIS-RTOS RTX +; * Title: Cortex-M0 Exception handlers +; * +; * ----------------------------------------------------------------------------- +; */ + + + NAME irq_cm0.s + + +I_T_RUN_OFS EQU 28 ; osRtxInfo.thread.run offset +TCB_SP_OFS EQU 56 ; TCB.SP offset + + + PRESERVE8 + SECTION .rodata:DATA:NOROOT(2) + + + EXPORT irqRtxLib +irqRtxLib DCB 0 ; Non weak library reference + + + THUMB + SECTION .text:CODE:NOROOT(2) + + +SVC_Handler + EXPORT SVC_Handler + IMPORT osRtxUserSVC + IMPORT osRtxInfo + + MRS R0,PSP ; Get PSP + LDR R1,[R0,#24] ; Load saved PC from stack + SUBS R1,R1,#2 ; Point to SVC instruction + LDRB R1,[R1] ; Load SVC number + CMP R1,#0 + BNE SVC_User ; Branch if not SVC 0 + + PUSH {R0,LR} ; Save PSP and EXC_RETURN + LDMIA R0,{R0-R3} ; Load function parameters from stack + BLX R7 ; Call service function + POP {R2,R3} ; Restore PSP and EXC_RETURN + STMIA R2!,{R0-R1} ; Store function return values + MOV LR,R3 ; Set EXC_RETURN + +SVC_Context + LDR R3,=osRtxInfo+I_T_RUN_OFS; Load address of osRtxInfo.run + LDMIA R3!,{R1,R2} ; Load osRtxInfo.thread.run: curr & next + CMP R1,R2 ; Check if thread switch is required + BEQ SVC_Exit ; Branch when threads are the same + + CMP R1,#0 + BEQ SVC_ContextSwitch ; Branch if running thread is deleted + +SVC_ContextSave + MRS R0,PSP ; Get PSP + SUBS R0,R0,#32 ; Adjust address + STR R0,[R1,#TCB_SP_OFS] ; Store SP + STMIA R0!,{R4-R7} ; Save R4..R7 + MOV R4,R8 + MOV R5,R9 + MOV R6,R10 + MOV R7,R11 + STMIA R0!,{R4-R7} ; Save R8..R11 + +SVC_ContextSwitch + SUBS R3,R3,#8 + STR R2,[R3] ; osRtxInfo.thread.run: curr = next + +SVC_ContextRestore + LDR R0,[R2,#TCB_SP_OFS] ; Load SP + ADDS R0,R0,#16 ; Adjust address + LDMIA R0!,{R4-R7} ; Restore R8..R11 + MOV R8,R4 + MOV R9,R5 + MOV R10,R6 + MOV R11,R7 + MSR PSP,R0 ; Set PSP + SUBS R0,R0,#32 ; Adjust address + LDMIA R0!,{R4-R7} ; Restore R4..R7 + + MOVS R0,#~0xFFFFFFFD + MVNS R0,R0 ; Set EXC_RETURN value + BX R0 ; Exit from handler + +SVC_Exit + BX LR ; Exit from handler + +SVC_User + PUSH {R4,LR} ; Save registers + LDR R2,=osRtxUserSVC ; Load address of SVC table + LDR R3,[R2] ; Load SVC maximum number + CMP R1,R3 ; Check SVC number range + BHI SVC_Done ; Branch if out of range + + LSLS R1,R1,#2 + LDR R4,[R2,R1] ; Load address of SVC function + + LDMIA R0,{R0-R3} ; Load function parameters from stack + BLX R4 ; Call service function + MRS R4,PSP ; Get PSP + STMIA R4!,{R0-R3} ; Store function return values + +SVC_Done + POP {R4,PC} ; Return from handler + + +PendSV_Handler + EXPORT PendSV_Handler + IMPORT osRtxPendSV_Handler + + PUSH {R0,LR} ; Save EXC_RETURN + BL osRtxPendSV_Handler ; Call osRtxPendSV_Handler + POP {R0,R1} ; Restore EXC_RETURN + MOV LR,R1 ; Set EXC_RETURN + B SVC_Context + + +SysTick_Handler + EXPORT SysTick_Handler + IMPORT osRtxTick_Handler + + PUSH {R0,LR} ; Save EXC_RETURN + BL osRtxTick_Handler ; Call osRtxTick_Handler + POP {R0,R1} ; Restore EXC_RETURN + MOV LR,R1 ; Set EXC_RETURN + B SVC_Context + + + END diff --git a/rtos/TARGET_CORTEX/rtx5/TARGET_M3/TOOLCHAIN_ARM/irq_cm3.S b/rtos/TARGET_CORTEX/rtx5/TARGET_M3/TOOLCHAIN_ARM/irq_cm3.S new file mode 100644 index 0000000..b951538 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/TARGET_M3/TOOLCHAIN_ARM/irq_cm3.S @@ -0,0 +1,133 @@ +;/* +; * Copyright (c) 2013-2017 ARM Limited. All rights reserved. +; * +; * SPDX-License-Identifier: Apache-2.0 +; * +; * Licensed under the Apache License, Version 2.0 (the License); you may +; * not use this file except in compliance with the License. +; * You may obtain a copy of the License at +; * +; * www.apache.org/licenses/LICENSE-2.0 +; * +; * Unless required by applicable law or agreed to in writing, software +; * distributed under the License is distributed on an AS IS BASIS, WITHOUT +; * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +; * See the License for the specific language governing permissions and +; * limitations under the License. +; * +; * ----------------------------------------------------------------------------- +; * +; * Project: CMSIS-RTOS RTX +; * Title: Cortex-M3 Exception handlers +; * +; * ----------------------------------------------------------------------------- +; */ + + +I_T_RUN_OFS EQU 28 ; osRtxInfo.thread.run offset +TCB_SP_OFS EQU 56 ; TCB.SP offset + + + PRESERVE8 + THUMB + + + AREA |.constdata|, DATA, READONLY + EXPORT irqRtxLib +irqRtxLib DCB 0 ; Non weak library reference + + + AREA |.text|, CODE, READONLY + + +SVC_Handler PROC + EXPORT SVC_Handler + IMPORT osRtxUserSVC + IMPORT osRtxInfo + + MRS R0,PSP ; Get PSP + LDR R1,[R0,#24] ; Load saved PC from stack + LDRB R1,[R1,#-2] ; Load SVC number + CBNZ R1,SVC_User ; Branch if not SVC 0 + + PUSH {R0,LR} ; Save PSP and EXC_RETURN + LDM R0,{R0-R3,R12} ; Load function parameters and address from stack + BLX R12 ; Call service function + POP {R12,LR} ; Restore PSP and EXC_RETURN + STM R12,{R0-R1} ; Store function return values + +SVC_Context + LDR R3,=osRtxInfo+I_T_RUN_OFS; Load address of osRtxInfo.run + LDM R3,{R1,R2} ; Load osRtxInfo.thread.run: curr & next + CMP R1,R2 ; Check if thread switch is required + BXEQ LR ; Exit when threads are the same + + CBZ R1,SVC_ContextSwitch ; Branch if running thread is deleted + +SVC_ContextSave + STMDB R12!,{R4-R11} ; Save R4..R11 + STR R12,[R1,#TCB_SP_OFS] ; Store SP + +SVC_ContextSwitch + STR R2,[R3] ; osRtxInfo.thread.run: curr = next + +SVC_ContextRestore + LDR R0,[R2,#TCB_SP_OFS] ; Load SP + LDMIA R0!,{R4-R11} ; Restore R4..R11 + MSR PSP,R0 ; Set PSP + + MVN LR,#~0xFFFFFFFD ; Set EXC_RETURN value + +SVC_Exit + BX LR ; Exit from handler + +SVC_User + PUSH {R4,LR} ; Save registers + LDR R2,=osRtxUserSVC ; Load address of SVC table + LDR R3,[R2] ; Load SVC maximum number + CMP R1,R3 ; Check SVC number range + BHI SVC_Done ; Branch if out of range + + LDR R4,[R2,R1,LSL #2] ; Load address of SVC function + + LDM R0,{R0-R3} ; Load function parameters from stack + BLX R4 ; Call service function + MRS R4,PSP ; Get PSP + STR R0,[R4] ; Store function return value + +SVC_Done + POP {R4,PC} ; Return from handler + + ALIGN + ENDP + + +PendSV_Handler PROC + EXPORT PendSV_Handler + IMPORT osRtxPendSV_Handler + + PUSH {R4,LR} ; Save EXC_RETURN + BL osRtxPendSV_Handler ; Call osRtxPendSV_Handler + POP {R4,LR} ; Restore EXC_RETURN + MRS R12,PSP + B SVC_Context + + ALIGN + ENDP + + +SysTick_Handler PROC + EXPORT SysTick_Handler + IMPORT osRtxTick_Handler + + PUSH {R4,LR} ; Save EXC_RETURN + BL osRtxTick_Handler ; Call osRtxTick_Handler + POP {R4,LR} ; Restore EXC_RETURN + MRS R12,PSP + B SVC_Context + + ALIGN + ENDP + + + END diff --git a/rtos/TARGET_CORTEX/rtx5/TARGET_M3/TOOLCHAIN_GCC/irq_cm3.S b/rtos/TARGET_CORTEX/rtx5/TARGET_M3/TOOLCHAIN_GCC/irq_cm3.S new file mode 100644 index 0000000..f8684da --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/TARGET_M3/TOOLCHAIN_GCC/irq_cm3.S @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2013-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * + * Project: CMSIS-RTOS RTX + * Title: Cortex-M3 Exception handlers + * + * ----------------------------------------------------------------------------- + */ + + + .file "irq_cm3.S" + .syntax unified + + .equ I_T_RUN_OFS, 28 // osRtxInfo.thread.run offset + .equ TCB_SP_OFS, 56 // TCB.SP offset + + .section ".rodata" + .global irqRtxLib // Non weak library reference +irqRtxLib: + .byte 0 + + + .thumb + .section ".text" + .align 2 + + + .thumb_func + .type SVC_Handler, %function + .global SVC_Handler + .fnstart + .cantunwind +SVC_Handler: + + MRS R0,PSP // Get PSP + LDR R1,[R0,#24] // Load saved PC from stack + LDRB R1,[R1,#-2] // Load SVC number + CBNZ R1,SVC_User // Branch if not SVC 0 + + PUSH {R0,LR} // Save PSP and EXC_RETURN + LDM R0,{R0-R3,R12} // Load function parameters and address from stack + BLX R12 // Call service function + POP {R12,LR} // Restore PSP and EXC_RETURN + STM R12,{R0-R1} // Store function return values + +SVC_Context: + LDR R3,=osRtxInfo+I_T_RUN_OFS // Load address of osRtxInfo.run + LDM R3,{R1,R2} // Load osRtxInfo.thread.run: curr & next + CMP R1,R2 // Check if thread switch is required + IT EQ + BXEQ LR // Exit when threads are the same + + CBZ R1,SVC_ContextSwitch // Branch if running thread is deleted + +SVC_ContextSave: + STMDB R12!,{R4-R11} // Save R4..R11 + STR R12,[R1,#TCB_SP_OFS] // Store SP + +SVC_ContextSwitch: +#ifdef FEATURE_UVISOR + CPSID I // The call to the thread switch helper and PSP loading must be atomic. +#endif + /* The call to thread_switch_helper can clobber R2 and R3, but we don't + * want to clobber R2 or R3. We can't save R2 and R3 to the stack (as + * the stack we save them onto is likely to be inaccessible after the + * call to thread_switch_helper). So, we just re-obtain the values from + * osRtxInfo again. */ + BL thread_switch_helper + LDR R3,=osRtxInfo+I_T_RUN_OFS // Load address of osRtxInfo.run + LDM R3,{R1,R2} // Load osRtxInfo.thread.run: curr & next + + STR R2,[R3] // osRtxInfo.thread.run: curr = next + +SVC_ContextRestore: + LDR R0,[R2,#TCB_SP_OFS] // Load SP + LDMIA R0!,{R4-R11} // Restore R4..R11 + MSR PSP,R0 // Set PSP +#ifdef FEATURE_UVISOR + CPSIE I // The PSP has been set. Re-enable interrupts. +#endif + MVN LR,#~0xFFFFFFFD // Set EXC_RETURN value + +SVC_Exit: + BX LR // Exit from handler + +SVC_User: + PUSH {R4,LR} // Save registers + LDR R2,=osRtxUserSVC // Load address of SVC table + LDR R3,[R2] // Load SVC maximum number + CMP R1,R3 // Check SVC number range + BHI SVC_Done // Branch if out of range + + LDR R4,[R2,R1,LSL #2] // Load address of SVC function + + LDM R0,{R0-R3} // Load function parameters from stack + BLX R4 // Call service function + MRS R4,PSP // Get PSP + STR R0,[R4] // Store function return value + +SVC_Done: + POP {R4,PC} // Return from handler + + .fnend + .size SVC_Handler, .-SVC_Handler + + + .thumb_func + .type PendSV_Handler, %function + .global PendSV_Handler + .fnstart + .cantunwind +PendSV_Handler: + + PUSH {R4,LR} // Save EXC_RETURN + BL osRtxPendSV_Handler // Call osRtxPendSV_Handler + POP {R4,LR} // Restore EXC_RETURN + MRS R12,PSP + B SVC_Context + + .fnend + .size PendSV_Handler, .-PendSV_Handler + + + .thumb_func + .type SysTick_Handler, %function + .global SysTick_Handler + .fnstart + .cantunwind +SysTick_Handler: + + PUSH {R4,LR} // Save EXC_RETURN + BL osRtxTick_Handler // Call osRtxTick_Handler + POP {R4,LR} // Restore EXC_RETURN + MRS R12,PSP + B SVC_Context + + .fnend + .size SysTick_Handler, .-SysTick_Handler + + + .end diff --git a/rtos/TARGET_CORTEX/rtx5/TARGET_M3/TOOLCHAIN_IAR/irq_cm3.S b/rtos/TARGET_CORTEX/rtx5/TARGET_M3/TOOLCHAIN_IAR/irq_cm3.S new file mode 100644 index 0000000..bfc3b33 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/TARGET_M3/TOOLCHAIN_IAR/irq_cm3.S @@ -0,0 +1,128 @@ +;/* +; * Copyright (c) 2013-2017 ARM Limited. All rights reserved. +; * +; * SPDX-License-Identifier: Apache-2.0 +; * +; * Licensed under the Apache License, Version 2.0 (the License); you may +; * not use this file except in compliance with the License. +; * You may obtain a copy of the License at +; * +; * www.apache.org/licenses/LICENSE-2.0 +; * +; * Unless required by applicable law or agreed to in writing, software +; * distributed under the License is distributed on an AS IS BASIS, WITHOUT +; * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +; * See the License for the specific language governing permissions and +; * limitations under the License. +; * +; * ----------------------------------------------------------------------------- +; * +; * Project: CMSIS-RTOS RTX +; * Title: Cortex-M3 Exception handlers +; * +; * ----------------------------------------------------------------------------- +; */ + + + NAME irq_cm3.s + + +I_T_RUN_OFS EQU 28 ; osRtxInfo.thread.run offset +TCB_SP_OFS EQU 56 ; TCB.SP offset + + + PRESERVE8 + SECTION .rodata:DATA:NOROOT(2) + + + EXPORT irqRtxLib +irqRtxLib DCB 0 ; Non weak library reference + + + THUMB + SECTION .text:CODE:NOROOT(2) + + +SVC_Handler + EXPORT SVC_Handler + IMPORT osRtxUserSVC + IMPORT osRtxInfo + + MRS R0,PSP ; Get PSP + LDR R1,[R0,#24] ; Load saved PC from stack + LDRB R1,[R1,#-2] ; Load SVC number + CBNZ R1,SVC_User ; Branch if not SVC 0 + + PUSH {R0,LR} ; Save PSP and EXC_RETURN + LDM R0,{R0-R3,R12} ; Load function parameters and address from stack + BLX R12 ; Call service function + POP {R12,LR} ; Restore PSP and EXC_RETURN + STM R12,{R0-R1} ; Store function return values + +SVC_Context + LDR R3,=osRtxInfo+I_T_RUN_OFS; Load address of osRtxInfo.run + LDM R3,{R1,R2} ; Load osRtxInfo.thread.run: curr & next + CMP R1,R2 ; Check if thread switch is required + IT EQ + BXEQ LR ; Exit when threads are the same + + CBZ R1,SVC_ContextSwitch ; Branch if running thread is deleted + +SVC_ContextSave + STMDB R12!,{R4-R11} ; Save R4..R11 + STR R12,[R1,#TCB_SP_OFS] ; Store SP + +SVC_ContextSwitch + STR R2,[R3] ; osRtxInfo.thread.run: curr = next + +SVC_ContextRestore + LDR R0,[R2,#TCB_SP_OFS] ; Load SP + LDMIA R0!,{R4-R11} ; Restore R4..R11 + MSR PSP,R0 ; Set PSP + + MVN LR,#~0xFFFFFFFD ; Set EXC_RETURN value + +SVC_Exit + BX LR ; Exit from handler + +SVC_User + PUSH {R4,LR} ; Save registers + LDR R2,=osRtxUserSVC ; Load address of SVC table + LDR R3,[R2] ; Load SVC maximum number + CMP R1,R3 ; Check SVC number range + BHI SVC_Done ; Branch if out of range + + LDR R4,[R2,R1,LSL #2] ; Load address of SVC function + + LDM R0,{R0-R3} ; Load function parameters from stack + BLX R4 ; Call service function + MRS R4,PSP ; Get PSP + STR R0,[R4] ; Store function return value + +SVC_Done + POP {R4,PC} ; Return from handler + + +PendSV_Handler + EXPORT PendSV_Handler + IMPORT osRtxPendSV_Handler + + PUSH {R4,LR} ; Save EXC_RETURN + BL osRtxPendSV_Handler ; Call osRtxPendSV_Handler + POP {R4,LR} ; Restore EXC_RETURN + MRS R12,PSP + B SVC_Context + + +SysTick_Handler + EXPORT SysTick_Handler + IMPORT osRtxTick_Handler + + PUSH {R4,LR} ; Save EXC_RETURN + BL osRtxTick_Handler ; Call osRtxTick_Handler + POP {R4,LR} ; Restore EXC_RETURN + MRS R12,PSP + B SVC_Context + + + END diff --git a/rtos/TARGET_CORTEX/rtx5/TARGET_RTOS_M4_M7/TOOLCHAIN_ARM/irq_cm4f.S b/rtos/TARGET_CORTEX/rtx5/TARGET_RTOS_M4_M7/TOOLCHAIN_ARM/irq_cm4f.S new file mode 100644 index 0000000..84ad0b5 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/TARGET_RTOS_M4_M7/TOOLCHAIN_ARM/irq_cm4f.S @@ -0,0 +1,154 @@ +;/* +; * Copyright (c) 2013-2017 ARM Limited. All rights reserved. +; * +; * SPDX-License-Identifier: Apache-2.0 +; * +; * Licensed under the Apache License, Version 2.0 (the License); you may +; * not use this file except in compliance with the License. +; * You may obtain a copy of the License at +; * +; * www.apache.org/licenses/LICENSE-2.0 +; * +; * Unless required by applicable law or agreed to in writing, software +; * distributed under the License is distributed on an AS IS BASIS, WITHOUT +; * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +; * See the License for the specific language governing permissions and +; * limitations under the License. +; * +; * ----------------------------------------------------------------------------- +; * +; * Project: CMSIS-RTOS RTX +; * Title: Cortex-M4F Exception handlers +; * +; * ----------------------------------------------------------------------------- +; */ + + +I_T_RUN_OFS EQU 28 ; osRtxInfo.thread.run offset +TCB_SP_OFS EQU 56 ; TCB.SP offset +TCB_SF_OFS EQU 34 ; TCB.stack_frame offset + + + PRESERVE8 + THUMB + + + AREA |.constdata|, DATA, READONLY + EXPORT irqRtxLib +irqRtxLib DCB 0 ; Non weak library reference + + + AREA |.text|, CODE, READONLY + + +SVC_Handler PROC + EXPORT SVC_Handler + IMPORT osRtxUserSVC + IMPORT osRtxInfo + + MRS R0,PSP ; Get PSP + LDR R1,[R0,#24] ; Load saved PC from stack + LDRB R1,[R1,#-2] ; Load SVC number + CBNZ R1,SVC_User ; Branch if not SVC 0 + + PUSH {R0,LR} ; Save PSP and EXC_RETURN + LDM R0,{R0-R3,R12} ; Load function parameters and address from stack + BLX R12 ; Call service function + POP {R12,LR} ; Restore PSP and EXC_RETURN + STM R12,{R0-R1} ; Store function return values + +SVC_Context + LDR R3,=osRtxInfo+I_T_RUN_OFS; Load address of osRtxInfo.run + LDM R3,{R1,R2} ; Load osRtxInfo.thread.run: curr & next + CMP R1,R2 ; Check if thread switch is required + BXEQ LR ; Exit when threads are the same + + CBNZ R1,SVC_ContextSave ; Branch if running thread is not deleted + TST LR,#0x10 ; Check if extended stack frame + BNE SVC_ContextSwitch +#ifdef __FPU_PRESENT + LDR R1,=0xE000EF34 ; FPCCR Address + LDR R0,[R1] ; Load FPCCR + BIC R0,#1 ; Clear LSPACT (Lazy state) + STR R0,[R1] ; Store FPCCR + B SVC_ContextSwitch +#endif + +SVC_ContextSave + STMDB R12!,{R4-R11} ; Save R4..R11 +#ifdef __FPU_PRESENT + TST LR,#0x10 ; Check if extended stack frame + VSTMDBEQ R12!,{S16-S31} ; Save VFP S16.S31 +#endif + + STR R12,[R1,#TCB_SP_OFS] ; Store SP + STRB LR, [R1,#TCB_SF_OFS] ; Store stack frame information + +SVC_ContextSwitch + STR R2,[R3] ; osRtxInfo.thread.run: curr = next + +SVC_ContextRestore + LDRB R1,[R2,#TCB_SF_OFS] ; Load stack frame information + LDR R0,[R2,#TCB_SP_OFS] ; Load SP + ORR LR,R1,#0xFFFFFF00 ; Set EXC_RETURN + +#ifdef __FPU_PRESENT + TST LR,#0x10 ; Check if extended stack frame + VLDMIAEQ R0!,{S16-S31} ; Restore VFP S16..S31 +#endif + LDMIA R0!,{R4-R11} ; Restore R4..R11 + MSR PSP,R0 ; Set PSP + +SVC_Exit + BX LR ; Exit from handler + +SVC_User + PUSH {R4,LR} ; Save registers + LDR R2,=osRtxUserSVC ; Load address of SVC table + LDR R3,[R2] ; Load SVC maximum number + CMP R1,R3 ; Check SVC number range + BHI SVC_Done ; Branch if out of range + + LDR R4,[R2,R1,LSL #2] ; Load address of SVC function + + LDM R0,{R0-R3} ; Load function parameters from stack + BLX R4 ; Call service function + MRS R4,PSP ; Get PSP + STR R0,[R4] ; Store function return value + +SVC_Done + POP {R4,PC} ; Return from handler + + ALIGN + ENDP + + +PendSV_Handler PROC + EXPORT PendSV_Handler + IMPORT osRtxPendSV_Handler + + PUSH {R4,LR} ; Save EXC_RETURN + BL osRtxPendSV_Handler ; Call osRtxPendSV_Handler + POP {R4,LR} ; Restore EXC_RETURN + MRS R12,PSP + B SVC_Context + + ALIGN + ENDP + + +SysTick_Handler PROC + EXPORT SysTick_Handler + IMPORT osRtxTick_Handler + + PUSH {R4,LR} ; Save EXC_RETURN + BL osRtxTick_Handler ; Call osRtxTick_Handler + POP {R4,LR} ; Restore EXC_RETURN + MRS R12,PSP + B SVC_Context + + ALIGN + ENDP + + + END diff --git a/rtos/TARGET_CORTEX/rtx5/TARGET_RTOS_M4_M7/TOOLCHAIN_GCC/irq_cm4f.S b/rtos/TARGET_CORTEX/rtx5/TARGET_RTOS_M4_M7/TOOLCHAIN_GCC/irq_cm4f.S new file mode 100644 index 0000000..fd57b7f --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/TARGET_RTOS_M4_M7/TOOLCHAIN_GCC/irq_cm4f.S @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2013-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * + * Project: CMSIS-RTOS RTX + * Title: Cortex-M4F Exception handlers + * + * ----------------------------------------------------------------------------- + */ + + + .file "irq_cm4f.S" + .syntax unified + + .equ I_T_RUN_OFS, 28 // osRtxInfo.thread.run offset + .equ TCB_SP_OFS, 56 // TCB.SP offset + .equ TCB_SF_OFS, 34 // TCB.stack_frame offset + + .section ".rodata" + .global irqRtxLib // Non weak library reference +irqRtxLib: + .byte 0 + + + .thumb + .section ".text" + .align 2 + + + .thumb_func + .type SVC_Handler, %function + .global SVC_Handler + .fnstart + .cantunwind +SVC_Handler: + + MRS R0,PSP // Get PSP + LDR R1,[R0,#24] // Load saved PC from stack + LDRB R1,[R1,#-2] // Load SVC number + CBNZ R1,SVC_User // Branch if not SVC 0 + + PUSH {R0,LR} // Save PSP and EXC_RETURN + LDM R0,{R0-R3,R12} // Load function parameters and address from stack + BLX R12 // Call service function + POP {R12,LR} // Restore PSP and EXC_RETURN + STM R12,{R0-R1} // Store function return values + +SVC_Context: + LDR R3,=osRtxInfo+I_T_RUN_OFS // Load address of osRtxInfo.run + LDM R3,{R1,R2} // Load osRtxInfo.thread.run: curr & next + CMP R1,R2 // Check if thread switch is required + IT EQ + BXEQ LR // Exit when threads are the same + + CBNZ R1,SVC_ContextSave // Branch if running thread is not deleted + TST LR,#0x10 // Check if extended stack frame + BNE SVC_ContextSwitch +#ifdef __FPU_PRESENT + LDR R1,=0xE000EF34 // FPCCR Address + LDR R0,[R1] // Load FPCCR + BIC R0,#1 // Clear LSPACT (Lazy state) + STR R0,[R1] // Store FPCCR + B SVC_ContextSwitch +#endif + +SVC_ContextSave: + STMDB R12!,{R4-R11} // Save R4..R11 + +#ifdef __FPU_PRESENT + TST LR,#0x10 // Check if extended stack frame + IT EQ + VSTMDBEQ R12!,{S16-S31} // Save VFP S16.S31 +#endif + + STR R12,[R1,#TCB_SP_OFS] // Store SP + STRB LR, [R1,#TCB_SF_OFS] // Store stack frame information + +SVC_ContextSwitch: +#ifdef FEATURE_UVISOR + CPSID I // The call to the thread switch helper and PSP loading must be atomic. +#endif + /* The call to thread_switch_helper can clobber R2 and R3, but we don't + * want to clobber R2 or R3. We can't save R2 and R3 to the stack (as + * the stack we save them onto is likely to be inaccessible after the + * call to thread_switch_helper). So, we just re-obtain the values from + * osRtxInfo again. */ + BL thread_switch_helper + LDR R3,=osRtxInfo+I_T_RUN_OFS // Load address of osRtxInfo.run + LDM R3,{R1,R2} // Load osRtxInfo.thread.run: curr & next + + STR R2,[R3] // osRtxInfo.thread.run: curr = next + +SVC_ContextRestore: + LDRB R1,[R2,#TCB_SF_OFS] // Load stack frame information + LDR R0,[R2,#TCB_SP_OFS] // Load SP + ORR LR,R1,#0xFFFFFF00 // Set EXC_RETURN + +#ifdef __FPU_PRESENT + TST LR,#0x10 // Check if extended stack frame + IT EQ + VLDMIAEQ R0!,{S16-S31} // Restore VFP S16..S31 +#endif + LDMIA R0!,{R4-R11} // Restore R4..R11 + MSR PSP,R0 // Set PSP +#ifdef FEATURE_UVISOR + CPSIE I // The PSP has been set. Re-enable interrupts. +#endif + +SVC_Exit: + BX LR // Exit from handler + +SVC_User: + PUSH {R4,LR} // Save registers + LDR R2,=osRtxUserSVC // Load address of SVC table + LDR R3,[R2] // Load SVC maximum number + CMP R1,R3 // Check SVC number range + BHI SVC_Done // Branch if out of range + + LDR R4,[R2,R1,LSL #2] // Load address of SVC function + + LDM R0,{R0-R3} // Load function parameters from stack + BLX R4 // Call service function + MRS R4,PSP // Get PSP + STR R0,[R4] // Store function return value + +SVC_Done: + POP {R4,PC} // Return from handler + + .fnend + .size SVC_Handler, .-SVC_Handler + + + .thumb_func + .type PendSV_Handler, %function + .global PendSV_Handler + .fnstart + .cantunwind +PendSV_Handler: + + PUSH {R4,LR} // Save EXC_RETURN + BL osRtxPendSV_Handler // Call osRtxPendSV_Handler + POP {R4,LR} // Restore EXC_RETURN + MRS R12,PSP + B SVC_Context + + .fnend + .size PendSV_Handler, .-PendSV_Handler + + + .thumb_func + .type SysTick_Handler, %function + .global SysTick_Handler + .fnstart + .cantunwind +SysTick_Handler: + + PUSH {R4,LR} // Save EXC_RETURN + BL osRtxTick_Handler // Call osRtxTick_Handler + POP {R4,LR} // Restore EXC_RETURN + MRS R12,PSP + B SVC_Context + + .fnend + .size SysTick_Handler, .-SysTick_Handler + + + .end diff --git a/rtos/TARGET_CORTEX/rtx5/TARGET_RTOS_M4_M7/TOOLCHAIN_IAR/irq_cm4f.S b/rtos/TARGET_CORTEX/rtx5/TARGET_RTOS_M4_M7/TOOLCHAIN_IAR/irq_cm4f.S new file mode 100644 index 0000000..e194af1 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/TARGET_RTOS_M4_M7/TOOLCHAIN_IAR/irq_cm4f.S @@ -0,0 +1,150 @@ +;/* +; * Copyright (c) 2013-2017 ARM Limited. All rights reserved. +; * +; * SPDX-License-Identifier: Apache-2.0 +; * +; * Licensed under the Apache License, Version 2.0 (the License); you may +; * not use this file except in compliance with the License. +; * You may obtain a copy of the License at +; * +; * www.apache.org/licenses/LICENSE-2.0 +; * +; * Unless required by applicable law or agreed to in writing, software +; * distributed under the License is distributed on an AS IS BASIS, WITHOUT +; * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +; * See the License for the specific language governing permissions and +; * limitations under the License. +; * +; * ----------------------------------------------------------------------------- +; * +; * Project: CMSIS-RTOS RTX +; * Title: Cortex-M4F Exception handlers +; * +; * ----------------------------------------------------------------------------- +; */ + + + NAME irq_cm4f.s + + +I_T_RUN_OFS EQU 28 ; osRtxInfo.thread.run offset +TCB_SP_OFS EQU 56 ; TCB.SP offset +TCB_SF_OFS EQU 34 ; TCB.stack_frame offset + + + PRESERVE8 + SECTION .rodata:DATA:NOROOT(2) + + + EXPORT irqRtxLib +irqRtxLib DCB 0 ; Non weak library reference + + + THUMB + SECTION .text:CODE:NOROOT(2) + +SVC_Handler + EXPORT SVC_Handler + IMPORT osRtxUserSVC + IMPORT osRtxInfo + + MRS R0,PSP ; Get PSP + LDR R1,[R0,#24] ; Load saved PC from stack + LDRB R1,[R1,#-2] ; Load SVC number + CBNZ R1,SVC_User ; Branch if not SVC 0 + + PUSH {R0,LR} ; Save PSP and EXC_RETURN + LDM R0,{R0-R3,R12} ; Load function parameters and address from stack + BLX R12 ; Call service function + POP {R12,LR} ; Restore PSP and EXC_RETURN + STM R12,{R0-R1} ; Store function return values + +SVC_Context + LDR R3,=osRtxInfo+I_T_RUN_OFS; Load address of osRtxInfo.run + LDM R3,{R1,R2} ; Load osRtxInfo.thread.run: curr & next + CMP R1,R2 ; Check if thread switch is required + IT EQ + BXEQ LR ; Exit when threads are the same + + CBNZ R1,SVC_ContextSave ; Branch if running thread is not deleted + TST LR,#0x10 ; Check if extended stack frame + BNE SVC_ContextSwitch +#ifdef __FPU_PRESENT + LDR R1,=0xE000EF34 ; FPCCR Address + LDR R0,[R1] ; Load FPCCR + BIC R0,R0,#1 ; Clear LSPACT (Lazy state) + STR R0,[R1] ; Store FPCCR + B SVC_ContextSwitch +#endif + +SVC_ContextSave + STMDB R12!,{R4-R11} ; Save R4..R11 +#ifdef __FPU_PRESENT + TST LR,#0x10 ; Check if extended stack frame + IT EQ + VSTMDBEQ R12!,{S16-S31} ; Save VFP S16.S31 +#endif + + STR R12,[R1,#TCB_SP_OFS] ; Store SP + STRB LR, [R1,#TCB_SF_OFS] ; Store stack frame information + +SVC_ContextSwitch + STR R2,[R3] ; osRtxInfo.thread.run: curr = next + +SVC_ContextRestore + LDRB R1,[R2,#TCB_SF_OFS] ; Load stack frame information + LDR R0,[R2,#TCB_SP_OFS] ; Load SP + ORR LR,R1,#0xFFFFFF00 ; Set EXC_RETURN + +#ifdef __FPU_PRESENT + TST LR,#0x10 ; Check if extended stack frame + IT EQ + VLDMIAEQ R0!,{S16-S31} ; Restore VFP S16..S31 +#endif + LDMIA R0!,{R4-R11} ; Restore R4..R11 + MSR PSP,R0 ; Set PSP + +SVC_Exit + BX LR ; Exit from handler + +SVC_User + PUSH {R4,LR} ; Save registers + LDR R2,=osRtxUserSVC ; Load address of SVC table + LDR R3,[R2] ; Load SVC maximum number + CMP R1,R3 ; Check SVC number range + BHI SVC_Done ; Branch if out of range + + LDR R4,[R2,R1,LSL #2] ; Load address of SVC function + + LDM R0,{R0-R3} ; Load function parameters from stack + BLX R4 ; Call service function + MRS R4,PSP ; Get PSP + STR R0,[R4] ; Store function return value + +SVC_Done + POP {R4,PC} ; Return from handler + + +PendSV_Handler + EXPORT PendSV_Handler + IMPORT osRtxPendSV_Handler + + PUSH {R4,LR} ; Save EXC_RETURN + BL osRtxPendSV_Handler ; Call osRtxPendSV_Handler + POP {R4,LR} ; Restore EXC_RETURN + MRS R12,PSP + B SVC_Context + + +SysTick_Handler + EXPORT SysTick_Handler + IMPORT osRtxTick_Handler + + PUSH {R4,LR} ; Save EXC_RETURN + BL osRtxTick_Handler ; Call osRtxTick_Handler + POP {R4,LR} ; Restore EXC_RETURN + MRS R12,PSP + B SVC_Context + + + END diff --git a/rtos/TARGET_CORTEX/rtx5/TESTS/memory/heap_and_stack/main.cpp b/rtos/TARGET_CORTEX/rtx5/TESTS/memory/heap_and_stack/main.cpp new file mode 100644 index 0000000..7e27350 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/TESTS/memory/heap_and_stack/main.cpp @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2016-2016, ARM Limited, All Rights Reserved + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include "greentea-client/test_env.h" +#include "cmsis.h" +#include "mbed.h" +#include "rtos.h" +#include "mbed_assert.h" + +// Amount to malloc for each iteration +#define MALLOC_TEST_SIZE 256 +// Malloc fill pattern +#define MALLOC_FILL 0x55 + +extern uint32_t mbed_heap_start; +extern uint32_t mbed_heap_size; +extern uint32_t mbed_stack_isr_start; +extern uint32_t mbed_stack_isr_size; + +static uint32_t max_allocation_size = 0; + +static bool inrange(uint32_t addr, uint32_t start, uint32_t size); +static bool rangeinrange(uint32_t addr, uint32_t size, uint32_t start, uint32_t len); +static bool valid_fill(uint8_t * data, uint32_t size, uint8_t fill); +static bool allocate_and_fill_heap(void); +static bool check_and_free_heap(void); + +int main (void) { + GREENTEA_SETUP(30, "default_auto"); + + char c; + char * initial_stack = &c; + char *initial_heap; + + // Sanity check malloc + initial_heap = (char*)malloc(1); + if (initial_heap == NULL) { + printf("Unable to malloc a single byte\n"); + GREENTEA_TESTSUITE_RESULT(false); + } + + if (!inrange((uint32_t)initial_heap, mbed_heap_start, mbed_heap_size)) { + printf("Heap in wrong location\n"); + GREENTEA_TESTSUITE_RESULT(false); + } + // MSP stack should be very near end (test using within 128 bytes) + uint32_t msp = __get_MSP(); + if (!inrange(msp, mbed_stack_isr_start + mbed_stack_isr_size - 128, 128)) { + printf("Interrupt stack in wrong location\n"); + GREENTEA_TESTSUITE_RESULT(false); + } + + // Fully allocate the heap and stack + bool ret = true; + ret = ret && allocate_and_fill_heap(); + ret = ret && check_and_free_heap(); + + // Force a task switch so a stack check is performed + Thread::wait(10); + + printf("Total size dynamically allocated: %lu\n", max_allocation_size); + + GREENTEA_TESTSUITE_RESULT(ret); +} + +/* + * Return true if addr is in range [start:start+size) + */ +static bool inrange(uint32_t addr, uint32_t start, uint32_t size) +{ + return (addr >= start) && (addr < start + size) ? true : false; +} + +/* + * Return true if [addr:addr+size] is inside [start:start+len] + */ +static bool rangeinrange(uint32_t addr, uint32_t size, uint32_t start, uint32_t len) +{ + if (addr + size > start + len) { + return false; + } + if (addr < start) { + return false; + } + return true; +} + +/* + * Return true of the region is filled only the the specified fill value + */ +static bool valid_fill(uint8_t * data, uint32_t size, uint8_t fill) +{ + for (uint32_t i = 0; i < size; i++) { + if (data[i] != fill) { + return false; + } + } + return true; +} + +struct linked_list { + linked_list * next; + uint8_t data[MALLOC_TEST_SIZE]; +}; + +static linked_list *head = NULL; +static bool allocate_and_fill_heap() +{ + + linked_list *current; + + current = (linked_list*)malloc(sizeof(linked_list)); + if (0 == current) { + return false; + } + current->next = NULL; + memset((void*)current->data, MALLOC_FILL, sizeof(current->data)); + + // Allocate until malloc returns NULL + bool pass = true; + head = current; + while (true) { + + // Allocate + linked_list *temp = (linked_list*)malloc(sizeof(linked_list)); + if (NULL == temp) { + break; + } + if (!rangeinrange((uint32_t)temp, sizeof(linked_list), mbed_heap_start, mbed_heap_size)) { + printf("Memory allocation out of range\n"); + pass = false; + break; + } + + // Init + temp->next = NULL; + memset((void*)temp->data, MALLOC_FILL, sizeof(current->data)); + + // Add to list + current->next = temp; + current = temp; + } + return pass; +} + +static bool check_and_free_heap() +{ + uint32_t total_size = 0; + linked_list * current = head; + bool pass = true; + while (current != NULL) { + total_size += sizeof(linked_list); + if (!valid_fill(current->data, sizeof(current->data), MALLOC_FILL)) { + pass = false; + } + linked_list * next = current->next; + free(current); + current = next; + } + + max_allocation_size = total_size; + return pass; +} diff --git a/rtos/TARGET_CORTEX/rtx5/cmsis_os2.h b/rtos/TARGET_CORTEX/rtx5/cmsis_os2.h new file mode 100644 index 0000000..6ae6513 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/cmsis_os2.h @@ -0,0 +1,750 @@ +/** \addtogroup rtos */ +/** @{*/ +/* + * Copyright (c) 2013-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ---------------------------------------------------------------------- + * + * $Date: 10. January 2017 + * $Revision: V2.1.0 + * + * Project: CMSIS-RTOS2 API + * Title: cmsis_os2.h header file + * + * Version 2.1.0 + * Support for critical and uncritical sections (nesting safe): + * - updated: osKernelLock, osKernelUnlock + * - added: osKernelRestoreLock + * Updated Thread and Event Flags: + * - changed flags parameter and return type from int32_t to uint32_t + * Version 2.0.0 + * Initial Release + *---------------------------------------------------------------------------*/ + +#ifndef CMSIS_OS2_H_ +#define CMSIS_OS2_H_ + +#ifndef __NO_RETURN +#if defined(__CC_ARM) +#define __NO_RETURN __declspec(noreturn) +#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) +#define __NO_RETURN __attribute__((noreturn)) +#elif defined(__GNUC__) +#define __NO_RETURN __attribute__((noreturn)) +#elif defined(__ICCARM__) +#define __NO_RETURN __noreturn +#else +#define __NO_RETURN +#endif +#endif + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + +// ==== Enumerations, structures, defines ==== + +/// Version information. +typedef struct { + uint32_t api; ///< API version (major.minor.rev: mmnnnrrrr dec). + uint32_t kernel; ///< Kernel version (major.minor.rev: mmnnnrrrr dec). +} osVersion_t; + +/// Kernel state. +typedef enum { + osKernelInactive = 0, ///< Inactive. + osKernelReady = 1, ///< Ready. + osKernelRunning = 2, ///< Running. + osKernelLocked = 3, ///< Locked. + osKernelSuspended = 4, ///< Suspended. + osKernelError = -1, ///< Error. + osKernelReserved = 0x7FFFFFFFU ///< Prevents enum down-size compiler optimization. +} osKernelState_t; + +/// Thread state. +typedef enum { + osThreadInactive = 0, ///< Inactive. + osThreadReady = 1, ///< Ready. + osThreadRunning = 2, ///< Running. + osThreadBlocked = 3, ///< Blocked. + osThreadTerminated = 4, ///< Terminated. + osThreadError = -1, ///< Error. + osThreadReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization. +} osThreadState_t; + +/// Priority values. +typedef enum { + osPriorityNone = 0, ///< No priority (not initialized). + osPriorityIdle = 1, ///< Reserved for Idle thread. + osPriorityLow = 8, ///< Priority: low + osPriorityLow1 = 8+1, ///< Priority: low + 1 + osPriorityLow2 = 8+2, ///< Priority: low + 2 + osPriorityLow3 = 8+3, ///< Priority: low + 3 + osPriorityLow4 = 8+4, ///< Priority: low + 4 + osPriorityLow5 = 8+5, ///< Priority: low + 5 + osPriorityLow6 = 8+6, ///< Priority: low + 6 + osPriorityLow7 = 8+7, ///< Priority: low + 7 + osPriorityBelowNormal = 16, ///< Priority: below normal + osPriorityBelowNormal1 = 16+1, ///< Priority: below normal + 1 + osPriorityBelowNormal2 = 16+2, ///< Priority: below normal + 2 + osPriorityBelowNormal3 = 16+3, ///< Priority: below normal + 3 + osPriorityBelowNormal4 = 16+4, ///< Priority: below normal + 4 + osPriorityBelowNormal5 = 16+5, ///< Priority: below normal + 5 + osPriorityBelowNormal6 = 16+6, ///< Priority: below normal + 6 + osPriorityBelowNormal7 = 16+7, ///< Priority: below normal + 7 + osPriorityNormal = 24, ///< Priority: normal + osPriorityNormal1 = 24+1, ///< Priority: normal + 1 + osPriorityNormal2 = 24+2, ///< Priority: normal + 2 + osPriorityNormal3 = 24+3, ///< Priority: normal + 3 + osPriorityNormal4 = 24+4, ///< Priority: normal + 4 + osPriorityNormal5 = 24+5, ///< Priority: normal + 5 + osPriorityNormal6 = 24+6, ///< Priority: normal + 6 + osPriorityNormal7 = 24+7, ///< Priority: normal + 7 + osPriorityAboveNormal = 32, ///< Priority: above normal + osPriorityAboveNormal1 = 32+1, ///< Priority: above normal + 1 + osPriorityAboveNormal2 = 32+2, ///< Priority: above normal + 2 + osPriorityAboveNormal3 = 32+3, ///< Priority: above normal + 3 + osPriorityAboveNormal4 = 32+4, ///< Priority: above normal + 4 + osPriorityAboveNormal5 = 32+5, ///< Priority: above normal + 5 + osPriorityAboveNormal6 = 32+6, ///< Priority: above normal + 6 + osPriorityAboveNormal7 = 32+7, ///< Priority: above normal + 7 + osPriorityHigh = 40, ///< Priority: high + osPriorityHigh1 = 40+1, ///< Priority: high + 1 + osPriorityHigh2 = 40+2, ///< Priority: high + 2 + osPriorityHigh3 = 40+3, ///< Priority: high + 3 + osPriorityHigh4 = 40+4, ///< Priority: high + 4 + osPriorityHigh5 = 40+5, ///< Priority: high + 5 + osPriorityHigh6 = 40+6, ///< Priority: high + 6 + osPriorityHigh7 = 40+7, ///< Priority: high + 7 + osPriorityRealtime = 48, ///< Priority: realtime + osPriorityRealtime1 = 48+1, ///< Priority: realtime + 1 + osPriorityRealtime2 = 48+2, ///< Priority: realtime + 2 + osPriorityRealtime3 = 48+3, ///< Priority: realtime + 3 + osPriorityRealtime4 = 48+4, ///< Priority: realtime + 4 + osPriorityRealtime5 = 48+5, ///< Priority: realtime + 5 + osPriorityRealtime6 = 48+6, ///< Priority: realtime + 6 + osPriorityRealtime7 = 48+7, ///< Priority: realtime + 7 + osPriorityISR = 56, ///< Reserved for ISR deferred thread. + osPriorityError = -1, ///< System cannot determine priority or illegal priority. + osPriorityReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization. +} osPriority_t; + +/// Entry point of a thread. +typedef void (*osThreadFunc_t) (void *argument); + +/// Entry point of a timer call back function. +typedef void (*osTimerFunc_t) (void *argument); + +/// Timer type. +typedef enum { + osTimerOnce = 0, ///< One-shot timer. + osTimerPeriodic = 1 ///< Repeating timer. +} osTimerType_t; + +/// Timeout value. +#define osWaitForever 0xFFFFFFFFU ///< Wait forever timeout value. + +/// Flags options (\ref osThreadFlagsWait and \ref osEventFlagsWait). +#define osFlagsWaitAny 0x00000000U ///< Wait for any flag (default). +#define osFlagsWaitAll 0x00000001U ///< Wait for all flags. +#define osFlagsNoClear 0x00000002U ///< Do not clear flags which have been specified to wait for. + +/// Flags errors (returned by osThreadFlagsXxxx and osEventFlagsXxxx). +#define osFlagsError 0x80000000U ///< Error indicator. +#define osFlagsErrorUnknown 0xFFFFFFFFU ///< osError (-1). +#define osFlagsErrorTimeout 0xFFFFFFFEU ///< osErrorTimeout (-2). +#define osFlagsErrorResource 0xFFFFFFFDU ///< osErrorResource (-3). +#define osFlagsErrorParameter 0xFFFFFFFCU ///< osErrorParameter (-4). +#define osFlagsErrorISR 0xFFFFFFFAU ///< osErrorISR (-6). + +/// Thread attributes (attr_bits in \ref osThreadAttr_t). +#define osThreadDetached 0x00000000U ///< Thread created in detached state (default) +#define osThreadJoinable 0x00000001U ///< Thread created in joinable state + +/// Mutex attributes (attr_bits in \ref osMutexAttr_t). +#define osMutexRecursive 0x00000001U ///< Recursive mutex. +#define osMutexPrioInherit 0x00000002U ///< Priority inherit protocol. +#define osMutexRobust 0x00000008U ///< Robust mutex. + +/// Status code values returned by CMSIS-RTOS functions. +typedef enum { + osOK = 0, ///< Operation completed successfully. + osError = -1, ///< Unspecified RTOS error: run-time error but no other error message fits. + osErrorTimeout = -2, ///< Operation not completed within the timeout period. + osErrorResource = -3, ///< Resource not available. + osErrorParameter = -4, ///< Parameter error. + osErrorNoMemory = -5, ///< System is out of memory: it was impossible to allocate or reserve memory for the operation. + osErrorISR = -6, ///< Not allowed in ISR context: the function cannot be called from interrupt service routines. + osStatusReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization. +} osStatus_t; + + +/// \details Thread ID identifies the thread. +typedef void *osThreadId_t; + +/// \details Timer ID identifies the timer. +typedef void *osTimerId_t; + +/// \details Event Flags ID identifies the event flags. +typedef void *osEventFlagsId_t; + +/// \details Mutex ID identifies the mutex. +typedef void *osMutexId_t; + +/// \details Semaphore ID identifies the semaphore. +typedef void *osSemaphoreId_t; + +/// \details Memory Pool ID identifies the memory pool. +typedef void *osMemoryPoolId_t; + +/// \details Message Queue ID identifies the message queue. +typedef void *osMessageQueueId_t; + + +#ifndef TZ_MODULEID_T +#define TZ_MODULEID_T +/// \details Data type that identifies secure software modules called by a process. +typedef uint32_t TZ_ModuleId_t; +#endif + + +/// Attributes structure for thread. +typedef struct { + const char *name; ///< name of the thread + uint32_t attr_bits; ///< attribute bits + void *cb_mem; ///< memory for control block + uint32_t cb_size; ///< size of provided memory for control block + void *stack_mem; ///< memory for stack + uint32_t stack_size; ///< size of stack + osPriority_t priority; ///< initial thread priority (default: osPriorityNormal) + TZ_ModuleId_t tz_module; ///< TrustZone module identifier + uint32_t reserved; ///< reserved (must be 0) +} osThreadAttr_t; + +/// Attributes structure for timer. +typedef struct { + const char *name; ///< name of the timer + uint32_t attr_bits; ///< attribute bits + void *cb_mem; ///< memory for control block + uint32_t cb_size; ///< size of provided memory for control block +} osTimerAttr_t; + +/// Attributes structure for event flags. +typedef struct { + const char *name; ///< name of the event flags + uint32_t attr_bits; ///< attribute bits + void *cb_mem; ///< memory for control block + uint32_t cb_size; ///< size of provided memory for control block +} osEventFlagsAttr_t; + +/// Attributes structure for mutex. +typedef struct { + const char *name; ///< name of the mutex + uint32_t attr_bits; ///< attribute bits + void *cb_mem; ///< memory for control block + uint32_t cb_size; ///< size of provided memory for control block +} osMutexAttr_t; + +/// Attributes structure for semaphore. +typedef struct { + const char *name; ///< name of the semaphore + uint32_t attr_bits; ///< attribute bits + void *cb_mem; ///< memory for control block + uint32_t cb_size; ///< size of provided memory for control block +} osSemaphoreAttr_t; + +/// Attributes structure for memory pool. +typedef struct { + const char *name; ///< name of the memory pool + uint32_t attr_bits; ///< attribute bits + void *cb_mem; ///< memory for control block + uint32_t cb_size; ///< size of provided memory for control block + void *mp_mem; ///< memory for data storage + uint32_t mp_size; ///< size of provided memory for data storage +} osMemoryPoolAttr_t; + +/// Attributes structure for message queue. +typedef struct { + const char *name; ///< name of the message queue + uint32_t attr_bits; ///< attribute bits + void *cb_mem; ///< memory for control block + uint32_t cb_size; ///< size of provided memory for control block + void *mq_mem; ///< memory for data storage + uint32_t mq_size; ///< size of provided memory for data storage +} osMessageQueueAttr_t; + + +// ==== Kernel Management Functions ==== + +/// Initialize the RTOS Kernel. +/// \return status code that indicates the execution status of the function. +osStatus_t osKernelInitialize (void); + +/// Get RTOS Kernel Information. +/// \param[out] version pointer to buffer for retrieving version information. +/// \param[out] id_buf pointer to buffer for retrieving kernel identification string. +/// \param[in] id_size size of buffer for kernel identification string. +/// \return status code that indicates the execution status of the function. +osStatus_t osKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size); + +/// Get the current RTOS Kernel state. +/// \return current RTOS Kernel state. +osKernelState_t osKernelGetState (void); + +/// Start the RTOS Kernel scheduler. +/// \return status code that indicates the execution status of the function. +osStatus_t osKernelStart (void); + +/// Lock the RTOS Kernel scheduler. +/// \return previous lock state (1 - locked, 0 - not locked, error code if negative). +int32_t osKernelLock (void); + +/// Unlock the RTOS Kernel scheduler. +/// \return previous lock state (1 - locked, 0 - not locked, error code if negative). +int32_t osKernelUnlock (void); + +/// Restore the RTOS Kernel scheduler lock state. +/// \param[in] lock lock state obtained by \ref osKernelLock or \ref osKernelUnlock. +/// \return new lock state (1 - locked, 0 - not locked, error code if negative). +int32_t osKernelRestoreLock (int32_t lock); + +/// Suspend the RTOS Kernel scheduler. +/// \return time in ticks, for how long the system can sleep or power-down. +uint32_t osKernelSuspend (void); + +/// Resume the RTOS Kernel scheduler. +/// \param[in] sleep_ticks time in ticks for how long the system was in sleep or power-down mode. +void osKernelResume (uint32_t sleep_ticks); + +/// Get the RTOS kernel tick count. +/// \return RTOS kernel current tick count. +uint64_t osKernelGetTickCount (void); + +/// Get the RTOS kernel tick frequency. +/// \return frequency of the kernel tick. +uint32_t osKernelGetTickFreq (void); + +/// Get the RTOS kernel system timer count. +/// \return RTOS kernel current system timer count as 32-bit value. +uint32_t osKernelGetSysTimerCount (void); + +/// Get the RTOS kernel system timer frequency. +/// \return frequency of the system timer. +uint32_t osKernelGetSysTimerFreq (void); + + +// ==== Thread Management Functions ==== + +/// Create a thread and add it to Active Threads. +/// \param[in] func thread function. +/// \param[in] argument pointer that is passed to the thread function as start argument. +/// \param[in] attr thread attributes; NULL: default values. +/// \return thread ID for reference by other functions or NULL in case of error. +osThreadId_t osThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr); +osThreadId_t osThreadContextNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr, void *context); + +/// Get name of a thread. +/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +/// \return name as NULL terminated string. +const char *osThreadGetName (osThreadId_t thread_id); + +/// Return the thread ID of the current running thread. +/// \return thread ID for reference by other functions or NULL in case of error. +osThreadId_t osThreadGetId (void); + +/// Get current thread state of a thread. +/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +/// \return current thread state of the specified thread. +osThreadState_t osThreadGetState (osThreadId_t thread_id); + +/// Get stack size of a thread. +/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +/// \return stack size in bytes. +uint32_t osThreadGetStackSize (osThreadId_t thread_id); + +/// Get available stack space of a thread based on stack watermark recording during execution. +/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +/// \return remaining stack space in bytes. +uint32_t osThreadGetStackSpace (osThreadId_t thread_id); + +/// Change priority of a thread. +/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +/// \param[in] priority new priority value for the thread function. +/// \return status code that indicates the execution status of the function. +osStatus_t osThreadSetPriority (osThreadId_t thread_id, osPriority_t priority); + +/// Get current priority of a thread. +/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +/// \return current priority value of the specified thread. +osPriority_t osThreadGetPriority (osThreadId_t thread_id); + +/// Pass control to next thread that is in state \b READY. +/// \return status code that indicates the execution status of the function. +osStatus_t osThreadYield (void); + +/// Suspend execution of a thread. +/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +/// \return status code that indicates the execution status of the function. +osStatus_t osThreadSuspend (osThreadId_t thread_id); + +/// Resume execution of a thread. +/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +/// \return status code that indicates the execution status of the function. +osStatus_t osThreadResume (osThreadId_t thread_id); + +/// Detach a thread (thread storage can be reclaimed when thread terminates). +/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +/// \return status code that indicates the execution status of the function. +osStatus_t osThreadDetach (osThreadId_t thread_id); + +/// Wait for specified thread to terminate. +/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +/// \return status code that indicates the execution status of the function. +osStatus_t osThreadJoin (osThreadId_t thread_id); + +/// Terminate execution of current running thread. +__NO_RETURN void osThreadExit (void); + +/// Terminate execution of a thread. +/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +/// \return status code that indicates the execution status of the function. +osStatus_t osThreadTerminate (osThreadId_t thread_id); + +/// Get number of active threads. +/// \return number of active threads. +uint32_t osThreadGetCount (void); + +/// Enumerate active threads. +/// \param[out] thread_array pointer to array for retrieving thread IDs. +/// \param[in] array_items maximum number of items in array for retrieving thread IDs. +/// \return number of enumerated threads. +uint32_t osThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items); + + +// ==== Thread Flags Functions ==== + +/// Set the specified Thread Flags of a thread. +/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +/// \param[in] flags specifies the flags of the thread that shall be set. +/// \return thread flags after setting or error code if highest bit set. +uint32_t osThreadFlagsSet (osThreadId_t thread_id, uint32_t flags); + +/// Clear the specified Thread Flags of current running thread. +/// \param[in] flags specifies the flags of the thread that shall be cleared. +/// \return thread flags before clearing or error code if highest bit set. +uint32_t osThreadFlagsClear (uint32_t flags); + +/// Get the current Thread Flags of current running thread. +/// \return current thread flags. +uint32_t osThreadFlagsGet (void); + +/// Wait for one or more Thread Flags of the current running thread to become signaled. +/// \param[in] flags specifies the flags to wait for. +/// \param[in] options specifies flags options (osFlagsXxxx). +/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +/// \return thread flags before clearing or error code if highest bit set. +uint32_t osThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout); + + +// ==== Generic Wait Functions ==== + +/// Wait for Timeout (Time Delay). +/// \param[in] ticks \ref CMSIS_RTOS_TimeOutValue "time ticks" value +/// \return status code that indicates the execution status of the function. +osStatus_t osDelay (uint32_t ticks); + +/// Wait until specified time. +/// \param[in] ticks absolute time in ticks +/// \return status code that indicates the execution status of the function. +osStatus_t osDelayUntil (uint64_t ticks); + + +// ==== Timer Management Functions ==== + +/// Create and Initialize a timer. +/// \param[in] func start address of a timer call back function. +/// \param[in] type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior. +/// \param[in] argument argument to the timer call back function. +/// \param[in] attr timer attributes; NULL: default values. +/// \return timer ID for reference by other functions or NULL in case of error. +osTimerId_t osTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr); + +/// Get name of a timer. +/// \param[in] timer_id timer ID obtained by \ref osTimerNew. +/// \return name as NULL terminated string. +const char *osTimerGetName (osTimerId_t timer_id); + +/// Start or restart a timer. +/// \param[in] timer_id timer ID obtained by \ref osTimerNew. +/// \param[in] ticks \ref CMSIS_RTOS_TimeOutValue "time ticks" value of the timer. +/// \return status code that indicates the execution status of the function. +osStatus_t osTimerStart (osTimerId_t timer_id, uint32_t ticks); + +/// Stop a timer. +/// \param[in] timer_id timer ID obtained by \ref osTimerNew. +/// \return status code that indicates the execution status of the function. +osStatus_t osTimerStop (osTimerId_t timer_id); + +/// Check if a timer is running. +/// \param[in] timer_id timer ID obtained by \ref osTimerNew. +/// \return 0 not running, 1 running. +uint32_t osTimerIsRunning (osTimerId_t timer_id); + +/// Delete a timer. +/// \param[in] timer_id timer ID obtained by \ref osTimerNew. +/// \return status code that indicates the execution status of the function. +osStatus_t osTimerDelete (osTimerId_t timer_id); + + +// ==== Event Flags Management Functions ==== + +/// Create and Initialize an Event Flags object. +/// \param[in] attr event flags attributes; NULL: default values. +/// \return event flags ID for reference by other functions or NULL in case of error. +osEventFlagsId_t osEventFlagsNew (const osEventFlagsAttr_t *attr); + +/// Get name of an Event Flags object. +/// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. +/// \return name as NULL terminated string. +const char *osEventFlagsGetName (osEventFlagsId_t ef_id); + +/// Set the specified Event Flags. +/// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. +/// \param[in] flags specifies the flags that shall be set. +/// \return event flags after setting or error code if highest bit set. +uint32_t osEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags); + +/// Clear the specified Event Flags. +/// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. +/// \param[in] flags specifies the flags that shall be cleared. +/// \return event flags before clearing or error code if highest bit set. +uint32_t osEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags); + +/// Get the current Event Flags. +/// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. +/// \return current event flags. +uint32_t osEventFlagsGet (osEventFlagsId_t ef_id); + +/// Wait for one or more Event Flags to become signaled. +/// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. +/// \param[in] flags specifies the flags to wait for. +/// \param[in] options specifies flags options (osFlagsXxxx). +/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +/// \return event flags before clearing or error code if highest bit set. +uint32_t osEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout); + +/// Delete an Event Flags object. +/// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. +/// \return status code that indicates the execution status of the function. +osStatus_t osEventFlagsDelete (osEventFlagsId_t ef_id); + + +// ==== Mutex Management Functions ==== + +/// Create and Initialize a Mutex object. +/// \param[in] attr mutex attributes; NULL: default values. +/// \return mutex ID for reference by other functions or NULL in case of error. +osMutexId_t osMutexNew (const osMutexAttr_t *attr); + +/// Get name of a Mutex object. +/// \param[in] mutex_id mutex ID obtained by \ref osMutexNew. +/// \return name as NULL terminated string. +const char *osMutexGetName (osMutexId_t mutex_id); + +/// Acquire a Mutex or timeout if it is locked. +/// \param[in] mutex_id mutex ID obtained by \ref osMutexNew. +/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +/// \return status code that indicates the execution status of the function. +osStatus_t osMutexAcquire (osMutexId_t mutex_id, uint32_t timeout); + +/// Release a Mutex that was acquired by \ref osMutexAcquire. +/// \param[in] mutex_id mutex ID obtained by \ref osMutexNew. +/// \return status code that indicates the execution status of the function. +osStatus_t osMutexRelease (osMutexId_t mutex_id); + +/// Get Thread which owns a Mutex object. +/// \param[in] mutex_id mutex ID obtained by \ref osMutexNew. +/// \return thread ID of owner thread or NULL when mutex was not acquired. +osThreadId_t osMutexGetOwner (osMutexId_t mutex_id); + +/// Delete a Mutex object. +/// \param[in] mutex_id mutex ID obtained by \ref osMutexNew. +/// \return status code that indicates the execution status of the function. +osStatus_t osMutexDelete (osMutexId_t mutex_id); + + +// ==== Semaphore Management Functions ==== + +/// Create and Initialize a Semaphore object. +/// \param[in] max_count maximum number of available tokens. +/// \param[in] initial_count initial number of available tokens. +/// \param[in] attr semaphore attributes; NULL: default values. +/// \return semaphore ID for reference by other functions or NULL in case of error. +osSemaphoreId_t osSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr); + +/// Get name of a Semaphore object. +/// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. +/// \return name as NULL terminated string. +const char *osSemaphoreGetName (osSemaphoreId_t semaphore_id); + +/// Acquire a Semaphore token or timeout if no tokens are available. +/// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. +/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +/// \return status code that indicates the execution status of the function. +osStatus_t osSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout); + +/// Release a Semaphore token that was acquired by \ref osSemaphoreAcquire. +/// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. +/// \return status code that indicates the execution status of the function. +osStatus_t osSemaphoreRelease (osSemaphoreId_t semaphore_id); + +/// Get current Semaphore token count. +/// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. +/// \return number of tokens available. +uint32_t osSemaphoreGetCount (osSemaphoreId_t semaphore_id); + +/// Delete a Semaphore object. +/// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. +/// \return status code that indicates the execution status of the function. +osStatus_t osSemaphoreDelete (osSemaphoreId_t semaphore_id); + + +// ==== Memory Pool Management Functions ==== + +/// Create and Initialize a Memory Pool object. +/// \param[in] block_count maximum number of memory blocks in memory pool. +/// \param[in] block_size memory block size in bytes. +/// \param[in] attr memory pool attributes; NULL: default values. +/// \return memory pool ID for reference by other functions or NULL in case of error. +osMemoryPoolId_t osMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr); + +/// Get name of a Memory Pool object. +/// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. +/// \return name as NULL terminated string. +const char *osMemoryPoolGetName (osMemoryPoolId_t mp_id); + +/// Allocate a memory block from a Memory Pool. +/// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. +/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +/// \return address of the allocated memory block or NULL in case of no memory is available. +void *osMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout); + +/// Return an allocated memory block back to a Memory Pool. +/// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. +/// \param[in] block address of the allocated memory block to be returned to the memory pool. +/// \return status code that indicates the execution status of the function. +osStatus_t osMemoryPoolFree (osMemoryPoolId_t mp_id, void *block); + +/// Get maximum number of memory blocks in a Memory Pool. +/// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. +/// \return maximum number of memory blocks. +uint32_t osMemoryPoolGetCapacity (osMemoryPoolId_t mp_id); + +/// Get memory block size in a Memory Pool. +/// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. +/// \return memory block size in bytes. +uint32_t osMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id); + +/// Get number of memory blocks used in a Memory Pool. +/// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. +/// \return number of memory blocks used. +uint32_t osMemoryPoolGetCount (osMemoryPoolId_t mp_id); + +/// Get number of memory blocks available in a Memory Pool. +/// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. +/// \return number of memory blocks available. +uint32_t osMemoryPoolGetSpace (osMemoryPoolId_t mp_id); + +/// Delete a Memory Pool object. +/// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. +/// \return status code that indicates the execution status of the function. +osStatus_t osMemoryPoolDelete (osMemoryPoolId_t mp_id); + + +// ==== Message Queue Management Functions ==== + +/// Create and Initialize a Message Queue object. +/// \param[in] msg_count maximum number of messages in queue. +/// \param[in] msg_size maximum message size in bytes. +/// \param[in] attr message queue attributes; NULL: default values. +/// \return message queue ID for reference by other functions or NULL in case of error. +osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr); + +/// Get name of a Message Queue object. +/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. +/// \return name as NULL terminated string. +const char *osMessageQueueGetName (osMessageQueueId_t mq_id); + +/// Put a Message into a Queue or timeout if Queue is full. +/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. +/// \param[in] msg_ptr pointer to buffer with message to put into a queue. +/// \param[in] msg_prio message priority. +/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +/// \return status code that indicates the execution status of the function. +osStatus_t osMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout); + +/// Get a Message from a Queue or timeout if Queue is empty. +/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. +/// \param[out] msg_ptr pointer to buffer for message to get from a queue. +/// \param[out] msg_prio pointer to buffer for message priority or NULL. +/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +/// \return status code that indicates the execution status of the function. +osStatus_t osMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout); + +/// Get maximum number of messages in a Message Queue. +/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. +/// \return maximum number of messages. +uint32_t osMessageQueueGetCapacity (osMessageQueueId_t mq_id); + +/// Get maximum message size in a Memory Pool. +/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. +/// \return maximum message size in bytes. +uint32_t osMessageQueueGetMsgSize (osMessageQueueId_t mq_id); + +/// Get number of queued messages in a Message Queue. +/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. +/// \return number of queued messages. +uint32_t osMessageQueueGetCount (osMessageQueueId_t mq_id); + +/// Get number of available slots for messages in a Message Queue. +/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. +/// \return number of available slots for messages. +uint32_t osMessageQueueGetSpace (osMessageQueueId_t mq_id); + +/// Reset a Message Queue to initial empty state. +/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. +/// \return status code that indicates the execution status of the function. +osStatus_t osMessageQueueReset (osMessageQueueId_t mq_id); + +/// Delete a Message Queue object. +/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. +/// \return status code that indicates the execution status of the function. +osStatus_t osMessageQueueDelete (osMessageQueueId_t mq_id); + + +#ifdef __cplusplus +} +#endif + +#endif // CMSIS_OS2_H_ + +/** @}*/ diff --git a/rtos/TARGET_CORTEX/rtx5/core_cm.h b/rtos/TARGET_CORTEX/rtx5/core_cm.h new file mode 100644 index 0000000..1590bd6 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/core_cm.h @@ -0,0 +1,1534 @@ +/** \addtogroup rtos */ +/** @{*/ +/* + * Copyright (c) 2013-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * + * Project: CMSIS-RTOS RTX + * Title: Cortex-M Core definitions + * + * ----------------------------------------------------------------------------- + */ + +#ifndef CORE_CM_H_ +#define CORE_CM_H_ + +#include +#include "cmsis.h" +#include "cmsis_compiler.h" +#include "arm_math.h" + +#ifndef __ARM_ARCH_6M__ +#define __ARM_ARCH_6M__ 0U +#endif +#ifndef __ARM_ARCH_7M__ +#define __ARM_ARCH_7M__ 0U +#endif +#ifndef __ARM_ARCH_7EM__ +#define __ARM_ARCH_7EM__ 0U +#endif +#ifndef __ARM_ARCH_8M_BASE__ +#define __ARM_ARCH_8M_BASE__ 0U +#endif +#ifndef __ARM_ARCH_8M_MAIN__ +#define __ARM_ARCH_8M_MAIN__ 0U +#endif + +#if ((__ARM_ARCH_6M__ + \ + __ARM_ARCH_7M__ + \ + __ARM_ARCH_7EM__ + \ + __ARM_ARCH_8M_BASE__ + \ + __ARM_ARCH_8M_MAIN__) != 1U) +#error "Unknown ARM Architecture!" +#endif + +#ifdef RTE_CMSIS_RTOS2_RTX5_ARMV8M_NS +#define __DOMAIN_NS 1U +#endif + +#ifndef __DOMAIN_NS +#define __DOMAIN_NS 0U +#elif ((__DOMAIN_NS == 1U) && \ + ((__ARM_ARCH_6M__ == 1U) || \ + (__ARM_ARCH_7M__ == 1U) || \ + (__ARM_ARCH_7EM__ == 1U))) +#error "Non-secure domain requires ARMv8-M Architecture!" +#endif + +#ifndef __EXCLUSIVE_ACCESS +#if ((__ARM_ARCH_7M__ == 1U) || \ + (__ARM_ARCH_7EM__ == 1U) || \ + (__ARM_ARCH_8M_BASE__ == 1U) || \ + (__ARM_ARCH_8M_MAIN__ == 1U)) +#define __EXCLUSIVE_ACCESS 1U +#else +#define __EXCLUSIVE_ACCESS 0U +#endif +#endif + + +#define IS_PRIVILEGED() ((__get_CONTROL() & 1U) == 0U) + +#define IS_IRQ_MODE() (__get_IPSR() != 0U) + +#if ((__ARM_ARCH_7M__ == 1U) || \ + (__ARM_ARCH_7EM__ == 1U) || \ + (__ARM_ARCH_8M_MAIN__ == 1U)) +#define IS_IRQ_MASKED() ((__get_PRIMASK() != 0U) || (__get_BASEPRI() != 0U)) +#else +#define IS_IRQ_MASKED() (__get_PRIMASK() != 0U) +#endif + +#define XPSR_INITIAL_VALUE 0x01000000U + +#if (__DOMAIN_NS == 1U) +#define STACK_FRAME_INIT 0xBCU +#else +#define STACK_FRAME_INIT 0xFDU +#endif + +#define IS_EXTENDED_STACK_FRAME(n) (((n) & 0x10U) == 0U) + + +// ==== Service Calls definitions ==== + +#if defined(__CC_ARM) + +#if ((__ARM_ARCH_7M__ == 1U) || \ + (__ARM_ARCH_7EM__ == 1U) || \ + (__ARM_ARCH_8M_MAIN__ == 1U)) +#define __SVC_INDIRECT(n) __svc_indirect(n) +#elif ((__ARM_ARCH_6M__ == 1U) || \ + (__ARM_ARCH_8M_BASE__ == 1U)) +#define __SVC_INDIRECT(n) __svc_indirect_r7(n) +#endif + +#if (__FPU_USED == 1U) +#define SVC_SETUP_PSP \ + uint32_t control = __get_CONTROL(); \ + if ((control & 2U) == 0U) { \ + __set_PSP((__get_MSP() - ((control & 4U) ? 104U : 32U)) & ~7U); \ + } +#else +#define SVC_SETUP_PSP \ + uint32_t control = __get_CONTROL(); \ + if ((control & 2U) == 0U) { \ + __set_PSP((__get_MSP() - 32U) & ~7U); \ + } +#endif + +#define SVC0_0N(f,t) \ +__SVC_INDIRECT(0) t svc##f (t(*)()); \ + t svcRtx##f (void); \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (void) { \ + svc##f(svcRtx##f); \ +} + +#define SVC0_0(f,t) \ +__SVC_INDIRECT(0) t svc##f (t(*)()); \ + t svcRtx##f (void); \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (void) { \ + return svc##f(svcRtx##f); \ +} + +#define SVC0_0M(f,t) \ +__SVC_INDIRECT(0) t svc##f (t(*)()); \ + t svcRtx##f (void); \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (void) { \ + SVC_SETUP_PSP \ + return svc##f(svcRtx##f); \ +} + +#define SVC0_0D SVC0_0 + +#define SVC0_1N(f,t,t1) \ +__SVC_INDIRECT(0) t svc##f (t(*)(t1),t1); \ + t svcRtx##f (t1 a1); \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1) { \ + svc##f(svcRtx##f,a1); \ +} + +#define SVC0_1(f,t,t1) \ +__SVC_INDIRECT(0) t svc##f (t(*)(t1),t1); \ + t svcRtx##f (t1 a1); \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1) { \ + return svc##f(svcRtx##f,a1); \ +} + +#define SVC0_1M(f,t,t1) \ +__SVC_INDIRECT(0) t svc##f (t(*)(t1),t1); \ + t svcRtx##f (t1 a1); \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1) { \ + SVC_SETUP_PSP \ + return svc##f(svcRtx##f,a1); \ +} + +#define SVC0_2(f,t,t1,t2) \ +__SVC_INDIRECT(0) t svc##f (t(*)(t1,t2),t1,t2); \ + t svcRtx##f (t1 a1, t2 a2); \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1, t2 a2) { \ + return svc##f(svcRtx##f,a1,a2); \ +} + +#define SVC0_2M(f,t,t1,t2) \ +__SVC_INDIRECT(0) t svc##f (t(*)(t1,t2),t1,t2); \ + t svcRtx##f (t1 a1, t2 a2); \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1, t2 a2) { \ + SVC_SETUP_PSP \ + return svc##f(svcRtx##f,a1,a2); \ +} + +#define SVC0_3(f,t,t1,t2,t3) \ +__SVC_INDIRECT(0) t svc##f (t(*)(t1,t2,t3),t1,t2,t3); \ + t svcRtx##f (t1 a1, t2 a2, t3 a3); \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1, t2 a2, t3 a3) { \ + return svc##f(svcRtx##f,a1,a2,a3); \ +} + +#define SVC0_3M(f,t,t1,t2,t3) \ +__SVC_INDIRECT(0) t svc##f (t(*)(t1,t2,t3),t1,t2,t3); \ + t svcRtx##f (t1 a1, t2 a2, t3 a3); \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1, t2 a2, t3 a3) { \ + SVC_SETUP_PSP \ + return svc##f(svcRtx##f,a1,a2,a3); \ +} + +#define SVC0_4(f,t,t1,t2,t3,t4) \ +__SVC_INDIRECT(0) t svc##f (t(*)(t1,t2,t3,t4),t1,t2,t3,t4); \ + t svcRtx##f (t1 a1, t2 a2, t3 a3, t4 a4); \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1, t2 a2, t3 a3, t4 a4) { \ + return svc##f(svcRtx##f,a1,a2,a3,a4); \ +} + +#define SVC0_4M(f,t,t1,t2,t3,t4) \ +__SVC_INDIRECT(0) t svc##f (t(*)(t1,t2,t3,t4),t1,t2,t3,t4); \ + t svcRtx##f (t1 a1, t2 a2, t3 a3, t4 a4); \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1, t2 a2, t3 a3, t4 a4) { \ + SVC_SETUP_PSP \ + return svc##f(svcRtx##f,a1,a2,a3,a4); \ +} + +#elif defined(__ICCARM__) + +#if ((__ARM_ARCH_7M__ == 1U) || \ + (__ARM_ARCH_7EM__ == 1U) || \ + (__ARM_ARCH_8M_MAIN__ == 1U)) +#define SVC_Setup(f) \ + __asm( \ + "mov r12,%0\n" \ + :: "r"(&f): "r12" \ + ); +#elif ((__ARM_ARCH_6M__ == 1U) || \ + (__ARM_ARCH_8M_BASE__ == 1U)) +#define SVC_Setup(f) \ + __asm( \ + "mov r7,%0\n" \ + :: "r"(&f): "r7" \ + ); +#endif + +#define STRINGIFY(a) #a +#define __SVC_INDIRECT(n) _Pragma(STRINGIFY(swi_number = n)) __swi + +#if (__FPU_USED == 1U) +#define SVC_SETUP_PSP \ + uint32_t control = __get_CONTROL(); \ + if ((control & 2U) == 0U) { \ + __set_PSP((__get_MSP() - ((control & 4U) ? 104U : 32U)) & ~7U); \ + } +#else +#define SVC_SETUP_PSP \ + uint32_t control = __get_CONTROL(); \ + if ((control & 2U) == 0U) { \ + __set_PSP((__get_MSP() - 32U) & ~7U); \ + } +#endif + +#define SVC0_0N(f,t) \ +__SVC_INDIRECT(0) t svc##f (); \ + t svcRtx##f (void); \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (void) { \ + SVC_Setup(svcRtx##f); \ + svc##f(); \ +} + +#define SVC0_0(f,t) \ +__SVC_INDIRECT(0) t svc##f (); \ + t svcRtx##f (void); \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (void) { \ + SVC_Setup(svcRtx##f); \ + return svc##f(); \ +} + +#define SVC0_0M(f,t) \ +__SVC_INDIRECT(0) t svc##f (); \ + t svcRtx##f (void); \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (void) { \ + SVC_SETUP_PSP \ + SVC_Setup(svcRtx##f); \ + return svc##f(); \ +} + +#define SVC0_0D SVC0_0 + +#define SVC0_1N(f,t,t1) \ +__SVC_INDIRECT(0) t svc##f (t1 a1); \ + t svcRtx##f (t1 a1); \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1) { \ + SVC_Setup(svcRtx##f); \ + svc##f(a1); \ +} + +#define SVC0_1(f,t,t1) \ +__SVC_INDIRECT(0) t svc##f (t1 a1); \ + t svcRtx##f (t1 a1); \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1) { \ + SVC_Setup(svcRtx##f); \ + return svc##f(a1); \ +} + +#define SVC0_1M(f,t,t1) \ +__SVC_INDIRECT(0) t svc##f (t1 a1); \ + t svcRtx##f (t1 a1); \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1) { \ + SVC_SETUP_PSP \ + SVC_Setup(svcRtx##f); \ + return svc##f(a1); \ +} + +#define SVC0_2(f,t,t1,t2) \ +__SVC_INDIRECT(0) t svc##f (t1 a1, t2 a2); \ + t svcRtx##f (t1 a1, t2 a2); \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1, t2 a2) { \ + SVC_Setup(svcRtx##f); \ + return svc##f(a1,a2); \ +} + +#define SVC0_2M(f,t,t1,t2) \ +__SVC_INDIRECT(0) t svc##f (t1 a1, t2 a2); \ + t svcRtx##f (t1 a1, t2 a2); \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1, t2 a2) { \ + SVC_SETUP_PSP \ + SVC_Setup(svcRtx##f); \ + return svc##f(a1,a2); \ +} + +#define SVC0_3(f,t,t1,t2,t3) \ +__SVC_INDIRECT(0) t svc##f (t1 a1, t2 a2, t3 a3); \ + t svcRtx##f (t1 a1, t2 a2, t3 a3); \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1, t2 a2, t3 a3) { \ + SVC_Setup(svcRtx##f); \ + return svc##f(a1,a2,a3); \ +} + +#define SVC0_3M(f,t,t1,t2,t3) \ +__SVC_INDIRECT(0) t svc##f (t1 a1, t2 a2, t3 a3); \ + t svcRtx##f (t1 a1, t2 a2, t3 a3); \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1, t2 a2, t3 a3) { \ + SVC_SETUP_PSP \ + SVC_Setup(svcRtx##f); \ + return svc##f(a1,a2,a3); \ +} + +#define SVC0_4(f,t,t1,t2,t3,t4) \ +__SVC_INDIRECT(0) t svc##f (t1 a1, t2 a2, t3 a3, t4 a4); \ + t svcRtx##f (t1 a1, t2 a2, t3 a3, t4 a4); \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1, t2 a2, t3 a3, t4 a4) { \ + SVC_Setup(svcRtx##f); \ + return svc##f(a1,a2,a3,a4); \ +} + +#define SVC0_4M(f,t,t1,t2,t3,t4) \ +__SVC_INDIRECT(0) t svc##f (t1 a1, t2 a2, t3 a3, t4 a4); \ + t svcRtx##f (t1 a1, t2 a2, t3 a3, t4 a4); \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1, t2 a2, t3 a3, t4 a4) { \ + SVC_SETUP_PSP \ + SVC_Setup(svcRtx##f); \ + return svc##f(a1,a2,a3,a4); \ +} + +#else // !(defined(__CC_ARM) || defined(__ICCARM__)) + +#if ((__ARM_ARCH_7M__ == 1U) || \ + (__ARM_ARCH_7EM__ == 1U) || \ + (__ARM_ARCH_8M_MAIN__ == 1U)) +#define SVC_RegF "r12" +#elif ((__ARM_ARCH_6M__ == 1U) || \ + (__ARM_ARCH_8M_BASE__ == 1U)) +#define SVC_RegF "r7" +#endif + +#define SVC_ArgN(n) \ +register uint32_t __r##n __ASM("r"#n) + +#define SVC_ArgR(n,a) \ +register uint32_t __r##n __ASM("r"#n) = (uint32_t)a + +#define SVC_ArgF(f) \ +register uint32_t __rf __ASM(SVC_RegF) = (uint32_t)f + +#define SVC_In0 "r"(__rf) +#define SVC_In1 "r"(__rf),"r"(__r0) +#define SVC_In2 "r"(__rf),"r"(__r0),"r"(__r1) +#define SVC_In3 "r"(__rf),"r"(__r0),"r"(__r1),"r"(__r2) +#define SVC_In4 "r"(__rf),"r"(__r0),"r"(__r1),"r"(__r2),"r"(__r3) + +#define SVC_Out0 +#define SVC_Out1 "=r"(__r0) +#define SVC_Out2 "=r"(__r0),"=r"(__r1) + +#define SVC_CL0 +#define SVC_CL1 "r1" +#define SVC_CL2 "r0","r1" + +#define SVC_Call0(in, out, cl) \ + __ASM volatile ("svc 0" : out : in : cl) + +#if ((__ARM_ARCH_7M__ == 1U) || \ + (__ARM_ARCH_7EM__ == 1U) || \ + (__ARM_ARCH_8M_MAIN__ == 1U)) +#if (__FPU_USED == 1U) +#define SVC_Call0M(in, out, cl) \ + register uint32_t val; \ + __ASM volatile ( \ + ".syntax unified\n\t" \ + "mrs %[val],control\n\t" \ + "tst %[val],#2\n\t" \ + "bne 0f\n\t" \ + "tst %[val],#4\n\t" \ + "mrs %[val],msp\n\t" \ + "ite eq\n\t" \ + "subeq %[val],#32\n\t" \ + "subne %[val],#104\n\t" \ + "bic %[val],#7\n\t" \ + "msr psp,%[val]\n\t" \ + "0:\n\t" \ + "svc 0" \ + : out, [val] "=&l" (val) : in : cl) +#else +#define SVC_Call0M(in, out, cl) \ + register uint32_t val; \ + __ASM volatile ( \ + ".syntax unified\n\t" \ + "mrs %[val],control\n\t" \ + "tst %[val],#2\n\t" \ + "bne 0f\n\t" \ + "mrs %[val],msp\n\t" \ + "subs %[val],#32\n\t" \ + "bic %[val],#7\n\t" \ + "msr psp,%[val]\n\t" \ + "0:\n\t" \ + "svc 0" \ + : out, [val] "=&l" (val) : in : cl) +#endif +#elif ((__ARM_ARCH_6M__ == 1U) || \ + (__ARM_ARCH_8M_BASE__ == 1U)) +#define SVC_Call0M(in, out, cl) \ + register uint32_t val; \ + __ASM volatile ( \ + ".syntax unified\n\t" \ + "mrs %[val],control\n\t" \ + "lsls %[val],#30\n\t" \ + "bmi 0f\n\t" \ + "mrs %[val],msp\n\t" \ + "subs %[val],#32\n\t" \ + "lsrs %[val],#3\n\t" \ + "lsls %[val],#3\n\t" \ + "msr psp,%[val]\n\t" \ + "0:\n\t" \ + "svc 0" \ + : out, [val] "=&l" (val) : in : cl) +#endif + +#define SVC0_0N(f,t) \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (void) { \ + SVC_ArgF(svcRtx##f); \ + SVC_Call0(SVC_In0, SVC_Out0, SVC_CL2); \ +} + +#define SVC0_0(f,t) \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (void) { \ + SVC_ArgN(0); \ + SVC_ArgF(svcRtx##f); \ + SVC_Call0(SVC_In0, SVC_Out1, SVC_CL1); \ + return (t) __r0; \ +} + +#define SVC0_0M(f,t) \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (void) { \ + SVC_ArgN(0); \ + SVC_ArgF(svcRtx##f); \ + SVC_Call0M(SVC_In0, SVC_Out1, SVC_CL1); \ + return (t) __r0; \ +} + +#define SVC0_0D(f,t) \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (void) { \ + SVC_ArgN(0); \ + SVC_ArgN(1); \ + SVC_ArgF(svcRtx##f); \ + SVC_Call0(SVC_In0, SVC_Out2, SVC_CL0); \ + return (((t) __r0) | (((t) __r1) << 32)); \ +} + +#define SVC0_1N(f,t,t1) \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1) { \ + SVC_ArgR(0,a1); \ + SVC_ArgF(svcRtx##f); \ + SVC_Call0(SVC_In1, SVC_Out0, SVC_CL1); \ +} + +#define SVC0_1(f,t,t1) \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1) { \ + SVC_ArgR(0,a1); \ + SVC_ArgF(svcRtx##f); \ + SVC_Call0(SVC_In1, SVC_Out1, SVC_CL1); \ + return (t) __r0; \ +} + +#define SVC0_1M(f,t,t1) \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1) { \ + SVC_ArgR(0,a1); \ + SVC_ArgF(svcRtx##f); \ + SVC_Call0M(SVC_In1, SVC_Out1, SVC_CL1); \ + return (t) __r0; \ +} + +#define SVC0_2(f,t,t1,t2) \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1, t2 a2) { \ + SVC_ArgR(0,a1); \ + SVC_ArgR(1,a2); \ + SVC_ArgF(svcRtx##f); \ + SVC_Call0(SVC_In2, SVC_Out1, SVC_CL0); \ + return (t) __r0; \ +} + +#define SVC0_2M(f,t,t1,t2) \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1, t2 a2) { \ + SVC_ArgR(0,a1); \ + SVC_ArgR(1,a2); \ + SVC_ArgF(svcRtx##f); \ + SVC_Call0M(SVC_In2, SVC_Out1, SVC_CL0); \ + return (t) __r0; \ +} + +#define SVC0_3(f,t,t1,t2,t3) \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1, t2 a2, t3 a3) { \ + SVC_ArgR(0,a1); \ + SVC_ArgR(1,a2); \ + SVC_ArgR(2,a3); \ + SVC_ArgF(svcRtx##f); \ + SVC_Call0(SVC_In3, SVC_Out1, SVC_CL0); \ + return (t) __r0; \ +} + +#define SVC0_3M(f,t,t1,t2,t3) \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1, t2 a2, t3 a3) { \ + SVC_ArgR(0,a1); \ + SVC_ArgR(1,a2); \ + SVC_ArgR(2,a3); \ + SVC_ArgF(svcRtx##f); \ + SVC_Call0M(SVC_In3, SVC_Out1, SVC_CL0); \ + return (t) __r0; \ +} + +#define SVC0_4(f,t,t1,t2,t3,t4) \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1, t2 a2, t3 a3, t4 a4) { \ + SVC_ArgR(0,a1); \ + SVC_ArgR(1,a2); \ + SVC_ArgR(2,a3); \ + SVC_ArgR(3,a4); \ + SVC_ArgF(svcRtx##f); \ + SVC_Call0(SVC_In4, SVC_Out1, SVC_CL0); \ + return (t) __r0; \ +} + +#define SVC0_4M(f,t,t1,t2,t3,t4) \ +__attribute__((always_inline)) \ +__STATIC_INLINE t __svc##f (t1 a1, t2 a2, t3 a3, t4 a4) { \ + SVC_ArgR(0,a1); \ + SVC_ArgR(1,a2); \ + SVC_ArgR(2,a3); \ + SVC_ArgR(3,a4); \ + SVC_ArgF(svcRtx##f); \ + SVC_Call0M(SVC_In4, SVC_Out1, SVC_CL0); \ + return (t) __r0; \ +} + +#endif + + +// ==== Core Peripherals functions ==== + +extern uint32_t SystemCoreClock; // System Clock Frequency (Core Clock) + + +/// Initialize SVC and PendSV System Service Calls +__STATIC_INLINE void SVC_Initialize (void) { +#if ((__ARM_ARCH_8M_MAIN__ == 1U) || (defined(__CORTEX_M) && (__CORTEX_M == 7U))) + uint32_t p, n; + + SCB->SHPR[10] = 0xFFU; + n = 32U - (uint32_t)__CLZ(~(SCB->SHPR[10] | 0xFFFFFF00U)); + p = NVIC_GetPriorityGrouping(); + if (p >= n) { + n = p + 1U; + } + SCB->SHPR[7] = (uint8_t)(0xFEU << n); +#elif (__ARM_ARCH_8M_BASE__ == 1U) + SCB->SHPR[1] |= 0x00FF0000U; + SCB->SHPR[0] |= (SCB->SHPR[1] << (8+1)) & 0xFC000000U; +#elif ((__ARM_ARCH_7M__ == 1U) || \ + (__ARM_ARCH_7EM__ == 1U)) + uint32_t p, n; + + SCB->SHP[10] = 0xFFU; + n = 32U - (uint32_t)__CLZ(~(SCB->SHP[10] | 0xFFFFFF00U)); + p = NVIC_GetPriorityGrouping(); + if (p >= n) { + n = p + 1U; + } + +/* Only change the SVCall priority if uVisor is not present. */ +#if !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED)) + SCB->SHP[7] = (uint8_t)(0xFEU << n); +#endif +#elif (__ARM_ARCH_6M__ == 1U) + SCB->SHP[1] |= 0x00FF0000U; + SCB->SHP[0] |= (SCB->SHP[1] << (8+1)) & 0xFC000000U; +#endif +} + +/// Setup SysTick Timer +/// \param[in] period Timer Load value +__STATIC_INLINE void SysTick_Setup (uint32_t period) { + SysTick->LOAD = period - 1U; + SysTick->VAL = 0U; +#if ((__ARM_ARCH_8M_MAIN__ == 1U) || (defined(__CORTEX_M) && (__CORTEX_M == 7U))) + SCB->SHPR[11] = 0xFFU; +#elif (__ARM_ARCH_8M_BASE__ == 1U) + SCB->SHPR[1] |= 0xFF000000U; +#elif ((__ARM_ARCH_7M__ == 1U) || \ + (__ARM_ARCH_7EM__ == 1U)) + SCB->SHP[11] = 0xFFU; +#elif (__ARM_ARCH_6M__ == 1U) + SCB->SHP[1] |= 0xFF000000U; +#endif +} + +/// Get SysTick Period +/// \return SysTick Period +__STATIC_INLINE uint32_t SysTick_GetPeriod (void) { + return (SysTick->LOAD + 1U); +} + +/// Get SysTick Value +/// \return SysTick Value +__STATIC_INLINE uint32_t SysTick_GetVal (void) { + uint32_t load = SysTick->LOAD; + return (load - SysTick->VAL); +} + +/// Get SysTick Overflow (Auto Clear) +/// \return SysTick Overflow flag +__STATIC_INLINE uint32_t SysTick_GetOvf (void) { + return ((SysTick->CTRL >> 16) & 1U); +} + +/// Enable SysTick Timer +__STATIC_INLINE void SysTick_Enable (void) { + SysTick->CTRL = SysTick_CTRL_ENABLE_Msk | + SysTick_CTRL_TICKINT_Msk | + SysTick_CTRL_CLKSOURCE_Msk; +} + +/// Disable SysTick Timer +__STATIC_INLINE void SysTick_Disable (void) { + SysTick->CTRL = 0U; +} + +/// Setup External Tick Timer Interrupt +/// \param[in] irqn Interrupt number +__STATIC_INLINE void ExtTick_SetupIRQ (int32_t irqn) { +#if (__ARM_ARCH_8M_MAIN__ == 1U) + NVIC->IPR[irqn] = 0xFFU; +#elif (__ARM_ARCH_8M_BASE__ == 1U) + NVIC->IPR[irqn >> 2] = (NVIC->IPR[irqn >> 2] & ~(0xFFU << ((irqn & 3) << 3))) | + (0xFFU << ((irqn & 3) << 3)); +#elif ((__ARM_ARCH_7M__ == 1U) || \ + (__ARM_ARCH_7EM__ == 1U)) + NVIC->IP[irqn] = 0xFFU; +#elif (__ARM_ARCH_6M__ == 1U) + NVIC->IP[irqn >> 2] = (NVIC->IP[irqn >> 2] & ~(0xFFU << ((irqn & 3) << 3))) | + (0xFFU << ((irqn & 3) << 3)); +#endif +} + +/// Enable External Tick Timer Interrupt +/// \param[in] irqn Interrupt number +__STATIC_INLINE void ExtTick_EnableIRQ (int32_t irqn) { + NVIC->ISER[irqn >> 5] = 1U << (irqn & 0x1F); +} + +/// Disable External Tick Timer Interrupt +/// \param[in] irqn Interrupt number +__STATIC_INLINE void ExtTick_DisableIRQ (int32_t irqn) { + NVIC->ICER[irqn >> 5] = 1U << (irqn & 0x1F); +} + +/// Get Pending SV (Service Call) and ST (SysTick) Flags +/// \return Pending SV&ST Flags +__STATIC_INLINE uint8_t GetPendSV_ST (void) { + return ((uint8_t)((SCB->ICSR & (SCB_ICSR_PENDSVSET_Msk | SCB_ICSR_PENDSTSET_Msk)) >> 24)); +} + +/// Get Pending SV (Service Call) Flag +/// \return Pending SV Flag +__STATIC_INLINE uint8_t GetPendSV (void) { + return ((uint8_t)((SCB->ICSR & (SCB_ICSR_PENDSVSET_Msk)) >> 24)); +} + +/// Clear Pending SV (Service Call) and ST (SysTick) Flags +__STATIC_INLINE void ClrPendSV_ST (void) { + SCB->ICSR = SCB_ICSR_PENDSVCLR_Msk | SCB_ICSR_PENDSTCLR_Msk; +} + +/// Clear Pending SV (Service Call) Flag +__STATIC_INLINE void ClrPendSV (void) { + SCB->ICSR = SCB_ICSR_PENDSVCLR_Msk; +} + +/// Set Pending SV (Service Call) Flag +__STATIC_INLINE void SetPendSV (void) { + SCB->ICSR = SCB_ICSR_PENDSVSET_Msk; +} + +/// Set Pending Flags +/// \param[in] flags Flags to set +__STATIC_INLINE void SetPendFlags (uint8_t flags) { + SCB->ICSR = ((uint32_t)flags << 24); +} + + +// ==== Exclusive Access Operation ==== + +#if (__EXCLUSIVE_ACCESS == 1U) + +/// Atomic Access Operation: Write (8-bit) +/// \param[in] mem Memory address +/// \param[in] val Value to write +/// \return Previous value +#if defined(__CC_ARM) +static __asm uint8_t atomic_wr8 (uint8_t *mem, uint8_t val) { + mov r2,r0 +1 + ldrexb r0,[r2] + strexb r3,r1,[r2] + cbz r3,%F2 + b %B1 +2 + bx lr +} +#else +__STATIC_INLINE uint8_t atomic_wr8 (uint8_t *mem, uint8_t val) { +#ifdef __ICCARM__ +#pragma diag_suppress=Pe550 +#endif + register uint32_t res; +#ifdef __ICCARM__ +#pragma diag_default=Pe550 +#endif + register uint8_t ret; + + __ASM volatile ( +#ifndef __ICCARM__ + ".syntax unified\n\t" +#endif + "1:\n\t" + "ldrexb %[ret],[%[mem]]\n\t" + "strexb %[res],%[val],[%[mem]]\n\t" + "cbz %[res],2f\n\t" + "b 1b\n" + "2:" + : [ret] "=&l" (ret), + [res] "=&l" (res) + : [mem] "l" (mem), + [val] "l" (val) + : "memory" + ); + + return ret; +} +#endif + +/// Atomic Access Operation: Set bits (32-bit) +/// \param[in] mem Memory address +/// \param[in] bits Bit mask +/// \return New value +#if defined(__CC_ARM) +static __asm uint32_t atomic_set32 (uint32_t *mem, uint32_t bits) { + mov r2,r0 +1 + ldrex r0,[r2] + orr r0,r0,r1 + strex r3,r0,[r2] + cbz r3,%F2 + b %B1 +2 + bx lr +} +#else +__STATIC_INLINE uint32_t atomic_set32 (uint32_t *mem, uint32_t bits) { +#ifdef __ICCARM__ +#pragma diag_suppress=Pe550 +#endif + register uint32_t val, res; +#ifdef __ICCARM__ +#pragma diag_default=Pe550 +#endif + register uint32_t ret; + + __ASM volatile ( +#ifndef __ICCARM__ + ".syntax unified\n\t" +#endif + "1:\n\t" + "ldrex %[val],[%[mem]]\n\t" +#if (__ARM_ARCH_8M_BASE__ == 1U) + "mov %[ret],%[val]\n\t" + "orrs %[ret],%[bits]\n\t" +#else + "orr %[ret],%[val],%[bits]\n\t" +#endif + "strex %[res],%[ret],[%[mem]]\n\t" + "cbz %[res],2f\n\t" + "b 1b\n" + "2:" + : [ret] "=&l" (ret), + [val] "=&l" (val), + [res] "=&l" (res) + : [mem] "l" (mem), + [bits] "l" (bits) +#if (__ARM_ARCH_8M_BASE__ == 1U) + : "memory", "cc" +#else + : "memory" +#endif + ); + + return ret; +} +#endif + +/// Atomic Access Operation: Clear bits (32-bit) +/// \param[in] mem Memory address +/// \param[in] bits Bit mask +/// \return Previous value +#if defined(__CC_ARM) +static __asm uint32_t atomic_clr32 (uint32_t *mem, uint32_t bits) { + push {r4,lr} + mov r2,r0 +1 + ldrex r0,[r2] + bic r4,r0,r1 + strex r3,r4,[r2] + cbz r3,%F2 + b %B1 +2 + pop {r4,pc} +} +#else +__STATIC_INLINE uint32_t atomic_clr32 (uint32_t *mem, uint32_t bits) { +#ifdef __ICCARM__ +#pragma diag_suppress=Pe550 +#endif + register uint32_t val, res; +#ifdef __ICCARM__ +#pragma diag_default=Pe550 +#endif + register uint32_t ret; + + __ASM volatile ( +#ifndef __ICCARM__ + ".syntax unified\n\t" +#endif + "1:\n\t" + "ldrex %[ret],[%[mem]]\n\t" +#if (__ARM_ARCH_8M_BASE__ == 1U) + "mov %[val],%[ret]\n\t" + "bics %[val],%[bits]\n\t" +#else + "bic %[val],%[ret],%[bits]\n\t" +#endif + "strex %[res],%[val],[%[mem]]\n\t" + "cbz %[res],2f\n\t" + "b 1b\n" + "2:" + : [ret] "=&l" (ret), + [val] "=&l" (val), + [res] "=&l" (res) + : [mem] "l" (mem), + [bits] "l" (bits) +#if (__ARM_ARCH_8M_BASE__ == 1U) + : "memory", "cc" +#else + : "memory" +#endif + ); + + return ret; +} +#endif + +/// Atomic Access Operation: Check if all specified bits (32-bit) are active and clear them +/// \param[in] mem Memory address +/// \param[in] bits Bit mask +/// \return Active bits before clearing or 0 if not active +#if defined(__CC_ARM) +static __asm uint32_t atomic_chk32_all (uint32_t *mem, uint32_t bits) { + push {r4,lr} + mov r2,r0 +1 + ldrex r0,[r2] + and r4,r0,r1 + cmp r4,r1 + beq %F2 + clrex + movs r0,#0 + pop {r4,pc} +2 + bic r4,r0,r1 + strex r3,r4,[r2] + cbz r3,%F3 + b %B1 +3 + pop {r4,pc} +} +#else +__STATIC_INLINE uint32_t atomic_chk32_all (uint32_t *mem, uint32_t bits) { +#ifdef __ICCARM__ +#pragma diag_suppress=Pe550 +#endif + register uint32_t val, res; +#ifdef __ICCARM__ +#pragma diag_default=Pe550 +#endif + register uint32_t ret; + + __ASM volatile ( +#ifndef __ICCARM__ + ".syntax unified\n\t" +#endif + "1:\n\t" + "ldrex %[ret],[%[mem]]\n\t" +#if (__ARM_ARCH_8M_BASE__ == 1U) + "mov %[val],%[ret]\n\t" + "ands %[val],%[bits]\n\t" +#else + "and %[val],%[ret],%[bits]\n\t" +#endif + "cmp %[val],%[bits]\n\t" + "beq 2f\n\t" + "clrex\n\t" + "movs %[ret],#0\n\t" + "b 3f\n" + "2:\n\t" +#if (__ARM_ARCH_8M_BASE__ == 1U) + "mov %[val],%[ret]\n\t" + "bics %[val],%[bits]\n\t" +#else + "bic %[val],%[ret],%[bits]\n\t" +#endif + "strex %[res],%[val],[%[mem]]\n\t" + "cbz %[res],3f\n\t" + "b 1b\n" + "3:" + : [ret] "=&l" (ret), + [val] "=&l" (val), + [res] "=&l" (res) + : [mem] "l" (mem), + [bits] "l" (bits) + : "cc", "memory" + ); + + return ret; +} +#endif + +/// Atomic Access Operation: Check if any specified bits (32-bit) are active and clear them +/// \param[in] mem Memory address +/// \param[in] bits Bit mask +/// \return Active bits before clearing or 0 if not active +#if defined(__CC_ARM) +static __asm uint32_t atomic_chk32_any (uint32_t *mem, uint32_t bits) { + push {r4,lr} + mov r2,r0 +1 + ldrex r0,[r2] + tst r0,r1 + bne %F2 + clrex + movs r0,#0 + pop {r4,pc} +2 + bic r4,r0,r1 + strex r3,r4,[r2] + cbz r3,%F3 + b %B1 +3 + pop {r4,pc} +} +#else +__STATIC_INLINE uint32_t atomic_chk32_any (uint32_t *mem, uint32_t bits) { +#ifdef __ICCARM__ +#pragma diag_suppress=Pe550 +#endif + register uint32_t val, res; +#ifdef __ICCARM__ +#pragma diag_default=Pe550 +#endif + register uint32_t ret; + + __ASM volatile ( +#ifndef __ICCARM__ + ".syntax unified\n\t" +#endif + "1:\n\t" + "ldrex %[ret],[%[mem]]\n\t" + "tst %[ret],%[bits]\n\t" + "bne 2f\n\t" + "clrex\n\t" + "movs %[ret],#0\n\t" + "b 3f\n" + "2:\n\t" +#if (__ARM_ARCH_8M_BASE__ == 1U) + "mov %[val],%[ret]\n\t" + "bics %[val],%[bits]\n\t" +#else + "bic %[val],%[ret],%[bits]\n\t" +#endif + "strex %[res],%[val],[%[mem]]\n\t" + "cbz %[res],3f\n\t" + "b 1b\n" + "3:" + : [ret] "=&l" (ret), + [val] "=&l" (val), + [res] "=&l" (res) + : [mem] "l" (mem), + [bits] "l" (bits) + : "cc", "memory" + ); + + return ret; +} +#endif + +/// Atomic Access Operation: Increment (32-bit) +/// \param[in] mem Memory address +/// \return Previous value +#if defined(__CC_ARM) +static __asm uint32_t atomic_inc32 (uint32_t *mem) { + mov r2,r0 +1 + ldrex r0,[r2] + adds r1,r0,#1 + strex r3,r1,[r2] + cbz r3,%F2 + b %B1 +2 + bx lr +} +#else +__STATIC_INLINE uint32_t atomic_inc32 (uint32_t *mem) { +#ifdef __ICCARM__ +#pragma diag_suppress=Pe550 +#endif + register uint32_t val, res; +#ifdef __ICCARM__ +#pragma diag_default=Pe550 +#endif + register uint32_t ret; + + __ASM volatile ( +#ifndef __ICCARM__ + ".syntax unified\n\t" +#endif + "1:\n\t" + "ldrex %[ret],[%[mem]]\n\t" + "adds %[val],%[ret],#1\n\t" + "strex %[res],%[val],[%[mem]]\n\t" + "cbz %[res],2f\n\t" + "b 1b\n" + "2:" + : [ret] "=&l" (ret), + [val] "=&l" (val), + [res] "=&l" (res) + : [mem] "l" (mem) + : "cc", "memory" + ); + + return ret; +} +#endif + +/// atomic Access Operation: Increment (32-bit) if Less Than +/// \param[in] mem Memory address +/// \param[in] max Maximum value +/// \return Previous value +#if defined(__CC_ARM) +static __asm uint32_t atomic_inc32_lt (uint32_t *mem, uint32_t max) { + push {r4,lr} + mov r2,r0 +1 + ldrex r0,[r2] + cmp r1,r0 + bhi %F2 + clrex + pop {r4,pc} +2 + adds r4,r0,#1 + strex r3,r4,[r2] + cbz r3,%F3 + b %B1 +3 + pop {r4,pc} +} +#else +__STATIC_INLINE uint32_t atomic_inc32_lt (uint32_t *mem, uint32_t max) { +#ifdef __ICCARM__ +#pragma diag_suppress=Pe550 +#endif + register uint32_t val, res; +#ifdef __ICCARM__ +#pragma diag_default=Pe550 +#endif + register uint32_t ret; + + __ASM volatile ( +#ifndef __ICCARM__ + ".syntax unified\n\t" +#endif + "1:\n\t" + "ldrex %[ret],[%[mem]]\n\t" + "cmp %[max],%[ret]\n\t" + "bhi 2f\n\t" + "clrex\n\t" + "b 3f\n" + "2:\n\t" + "adds %[val],%[ret],#1\n\t" + "strex %[res],%[val],[%[mem]]\n\t" + "cbz %[res],3f\n\t" + "b 1b\n" + "3:" + : [ret] "=&l" (ret), + [val] "=&l" (val), + [res] "=&l" (res) + : [mem] "l" (mem), + [max] "l" (max) + : "cc", "memory" + ); + + return ret; +} +#endif + +/// Atomic Access Operation: Increment (16-bit) if Less Than +/// \param[in] mem Memory address +/// \param[in] max Maximum value +/// \return Previous value +#if defined(__CC_ARM) +static __asm uint16_t atomic_inc16_lt (uint16_t *mem, uint16_t max) { + push {r4,lr} + mov r2,r0 +1 + ldrexh r0,[r2] + cmp r1,r0 + bhi %F2 + clrex + pop {r4,pc} +2 + adds r4,r0,#1 + strexh r3,r4,[r2] + cbz r3,%F3 + b %B1 +3 + pop {r4,pc} +} +#else +__STATIC_INLINE uint16_t atomic_inc16_lt (uint16_t *mem, uint16_t max) { +#ifdef __ICCARM__ +#pragma diag_suppress=Pe550 +#endif + register uint32_t val, res; +#ifdef __ICCARM__ +#pragma diag_default=Pe550 +#endif + register uint16_t ret; + + __ASM volatile ( +#ifndef __ICCARM__ + ".syntax unified\n\t" +#endif + "1:\n\t" + "ldrexh %[ret],[%[mem]]\n\t" + "cmp %[max],%[ret]\n\t" + "bhi 2f\n\t" + "clrex\n\t" + "b 3f\n" + "2:\n\t" + "adds %[val],%[ret],#1\n\t" + "strexh %[res],%[val],[%[mem]]\n\t" + "cbz %[res],3f\n\t" + "b 1b\n" + "3:" + : [ret] "=&l" (ret), + [val] "=&l" (val), + [res] "=&l" (res) + : [mem] "l" (mem), + [max] "l" (max) + : "cc", "memory" + ); + + return ret; +} +#endif + +/// Atomic Access Operation: Increment (16-bit) and clear on Limit +/// \param[in] mem Memory address +/// \param[in] max Maximum value +/// \return Previous value +#if defined(__CC_ARM) +static __asm uint16_t atomic_inc16_lim (uint16_t *mem, uint16_t lim) { + push {r4,lr} + mov r2,r0 +1 + ldrexh r0,[r2] + adds r4,r0,#1 + cmp r1,r4 + bhi %F2 + movs r4,#0 +2 + strexh r3,r4,[r2] + cbz r3,%F3 + b %B1 +3 + pop {r4,pc} +} +#else +__STATIC_INLINE uint16_t atomic_inc16_lim (uint16_t *mem, uint16_t lim) { +#ifdef __ICCARM__ +#pragma diag_suppress=Pe550 +#endif + register uint32_t val, res; +#ifdef __ICCARM__ +#pragma diag_default=Pe550 +#endif + register uint16_t ret; + + __ASM volatile ( +#ifndef __ICCARM__ + ".syntax unified\n\t" +#endif + "1:\n\t" + "ldrexh %[ret],[%[mem]]\n\t" + "adds %[val],%[ret],#1\n\t" + "cmp %[lim],%[val]\n\t" + "bhi 2f\n\t" + "movs %[val],#0\n" + "2:\n\t" + "strexh %[res],%[val],[%[mem]]\n\t" + "cbz %[res],3f\n\t" + "b 1b\n" + "3:" + : [ret] "=&l" (ret), + [val] "=&l" (val), + [res] "=&l" (res) + : [mem] "l" (mem), + [lim] "l" (lim) + : "cc", "memory" + ); + + return ret; +} +#endif + +/// Atomic Access Operation: Decrement (32-bit) if Not Zero +/// \param[in] mem Memory address +/// \return Previous value +#if defined(__CC_ARM) +static __asm uint32_t atomic_dec32_nz (uint32_t *mem) { + mov r2,r0 +1 + ldrex r0,[r2] + cbnz r0,%F2 + clrex + bx lr +2 + subs r1,r0,#1 + strex r3,r1,[r2] + cbz r3,%F3 + b %B1 +3 + bx lr +} +#else +__STATIC_INLINE uint32_t atomic_dec32_nz (uint32_t *mem) { +#ifdef __ICCARM__ +#pragma diag_suppress=Pe550 +#endif + register uint32_t val, res; +#ifdef __ICCARM__ +#pragma diag_default=Pe550 +#endif + register uint32_t ret; + + __ASM volatile ( +#ifndef __ICCARM__ + ".syntax unified\n\t" +#endif + "1:\n\t" + "ldrex %[ret],[%[mem]]\n\t" + "cbnz %[ret],2f\n\t" + "clrex\n\t" + "b 3f\n" + "2:\n\t" + "subs %[val],%[ret],#1\n\t" + "strex %[res],%[val],[%[mem]]\n\t" + "cbz %[res],3f\n\t" + "b 1b\n" + "3:" + : [ret] "=&l" (ret), + [val] "=&l" (val), + [res] "=&l" (res) + : [mem] "l" (mem) + : "cc", "memory" + ); + + return ret; +} +#endif + +/// Atomic Access Operation: Decrement (16-bit) if Not Zero +/// \param[in] mem Memory address +/// \return Previous value +#if defined(__CC_ARM) +static __asm uint16_t atomic_dec16_nz (uint16_t *mem) { + mov r2,r0 +1 + ldrexh r0,[r2] + cbnz r0,%F2 + clrex + bx lr +2 + subs r1,r0,#1 + strexh r3,r1,[r2] + cbz r3,%F3 + b %B1 +3 + bx lr +} +#else +__STATIC_INLINE uint16_t atomic_dec16_nz (uint16_t *mem) { +#ifdef __ICCARM__ +#pragma diag_suppress=Pe550 +#endif + register uint32_t val, res; +#ifdef __ICCARM__ +#pragma diag_default=Pe550 +#endif + register uint16_t ret; + + __ASM volatile ( +#ifndef __ICCARM__ + ".syntax unified\n\t" +#endif + "1:\n\t" + "ldrexh %[ret],[%[mem]]\n\t" + "cbnz %[ret],2f\n\t" + "clrex\n\t" + "b 3f\n" + "2:\n\t" + "subs %[val],%[ret],#1\n\t" + "strexh %[res],%[val],[%[mem]]\n\t" + "cbz %[res],3f\n\t" + "b 1b\n" + "3:" + : [ret] "=&l" (ret), + [val] "=&l" (val), + [res] "=&l" (res) + : [mem] "l" (mem) + : "cc", "memory" + ); + + return ret; +} +#endif + +/// Atomic Access Operation: Link Get +/// \param[in] root Root address +/// \return Link +#if defined(__CC_ARM) +static __asm void *atomic_link_get (void **root) { + mov r2,r0 +1 + ldrex r0,[r2] + cbnz r0,%F2 + clrex + bx lr +2 + ldr r1,[r0] + strex r3,r1,[r2] + cbz r3,%F3 + b %B1 +3 + bx lr +} +#else +__STATIC_INLINE void *atomic_link_get (void **root) { +#ifdef __ICCARM__ +#pragma diag_suppress=Pe550 +#endif + register uint32_t val, res; +#ifdef __ICCARM__ +#pragma diag_default=Pe550 +#endif + register void *ret; + + __ASM volatile ( +#ifndef __ICCARM__ + ".syntax unified\n\t" +#endif + "1:\n\t" + "ldrex %[ret],[%[root]]\n\t" + "cbnz %[ret],2f\n\t" + "clrex\n\t" + "b 3f\n" + "2:\n\t" + "ldr %[val],[%[ret]]\n\t" + "strex %[res],%[val],[%[root]]\n\t" + "cbz %[res],3f\n\t" + "b 1b\n" + "3:" + : [ret] "=&l" (ret), + [val] "=&l" (val), + [res] "=&l" (res) + : [root] "l" (root) + : "cc", "memory" + ); + + return ret; +} +#endif + +/// Atomic Access Operation: Link Put +/// \param[in] root Root address +/// \param[in] lnk Link +#if defined(__CC_ARM) +static __asm void atomic_link_put (void **root, void *link) { +1 + ldr r2,[r0] + str r2,[r1] + dmb + ldrex r2,[r0] + ldr r3,[r1] + cmp r3,r2 + bne %B1 + strex r3,r1,[r0] + cbz r3,%F2 + b %B1 +2 + bx lr +} +#else +__STATIC_INLINE void atomic_link_put (void **root, void *link) { +#ifdef __ICCARM__ +#pragma diag_suppress=Pe550 +#endif + register uint32_t val1, val2, res; +#ifdef __ICCARM__ +#pragma diag_default=Pe550 +#endif + + __ASM volatile ( +#ifndef __ICCARM__ + ".syntax unified\n\t" +#endif + "1:\n\t" + "ldr %[val1],[%[root]]\n\t" + "str %[val1],[%[link]]\n\t" + "dmb\n\t" + "ldrex %[val1],[%[root]]\n\t" + "ldr %[val2],[%[link]]\n\t" + "cmp %[val2],%[val1]\n\t" + "bne 1b\n\t" + "strex %[res],%[link],[%[root]]\n\t" + "cbz %[res],2f\n\t" + "b 1b\n" + "2:" + : [val1] "=&l" (val1), + [val2] "=&l" (val2), + [res] "=&l" (res) + : [root] "l" (root), + [link] "l" (link) + : "cc", "memory" + ); +} +#endif + +#endif // (__EXCLUSIVE_ACCESS == 1U) + + +#endif // CORE_CM_H_ + +/** @}*/ diff --git a/rtos/TARGET_CORTEX/rtx5/rt_OsEventObserver.c b/rtos/TARGET_CORTEX/rtx5/rt_OsEventObserver.c new file mode 100644 index 0000000..5fee0aa --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/rt_OsEventObserver.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * + * Project: CMSIS-RTOS RTX + * Title: OS Event Observer + * + * ----------------------------------------------------------------------------- + */ +#include "rt_OsEventObserver.h" + +/* + * _____ _____ ____ __ _____ + * | ___|_ _\ \/ / \/ | ____| + * | |_ | | \ /| |\/| | _| + * | _| | | / \| | | | |___ + * |_| |___/_/\_\_| |_|_____| + * + * FIXME: + * The osEventObs variable must be in protected memory. If not every box + * and box 0 can modify osEventObs to point to any handler to run code + * privileged. This issue is tracked at + * . + */ +const OsEventObserver *osEventObs; + +void osRegisterForOsEvents(const OsEventObserver *observer) +{ + static uint8_t has_been_called = 0; + if (has_been_called) { + return; + } + has_been_called = 1; + + osEventObs = observer; +} diff --git a/rtos/TARGET_CORTEX/rtx5/rt_OsEventObserver.h b/rtos/TARGET_CORTEX/rtx5/rt_OsEventObserver.h new file mode 100644 index 0000000..899f319 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/rt_OsEventObserver.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * + * Project: CMSIS-RTOS RTX + * Title: OS Event Observer + * + * ----------------------------------------------------------------------------- + */ +#ifndef _RT_OS_EVENT_OBSERVER_H +#define _RT_OS_EVENT_OBSERVER_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + uint32_t version; + void (*pre_start)(void); + void *(*thread_create)(int thread_id, void *context); + void (*thread_destroy)(void *context); + void (*thread_switch)(void *context); +} OsEventObserver; +extern const OsEventObserver *osEventObs; + +void osRegisterForOsEvents(const OsEventObserver *observer); + +#ifdef __cplusplus +}; +#endif + +#endif + +/** @}*/ diff --git a/rtos/TARGET_CORTEX/rtx5/rtx_delay.c b/rtos/TARGET_CORTEX/rtx5/rtx_delay.c new file mode 100644 index 0000000..a7e71b7 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/rtx_delay.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2013-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * + * Project: CMSIS-RTOS RTX + * Title: Delay functions + * + * ----------------------------------------------------------------------------- + */ + +#include "rtx_lib.h" + + +// ==== Service Calls ==== + +// Service Calls definitions +SVC0_1(Delay, osStatus_t, uint32_t) +SVC0_2(DelayUntil, osStatus_t, uint32_t, uint32_t) + +/// Wait for Timeout (Time Delay). +/// \note API identical to osDelay +osStatus_t svcRtxDelay (uint32_t ticks) { + + if (ticks == 0U) { + return osOK; + } + + osRtxThreadWaitEnter(osRtxThreadWaitingDelay, ticks); + + return osOK; +} + +/// Wait until specified time. +/// \note API identical to osDelayUntil +osStatus_t svcRtxDelayUntil (uint32_t ticks_l, uint32_t ticks_h) { + uint64_t ticks = ((uint64_t)ticks_l) | ((uint64_t)ticks_h << 32); + + ticks -= osRtxInfo.kernel.tick; + if (ticks >= 0xFFFFFFFFU) { + EvrRtxThreadError(NULL, osErrorParameter); + return osErrorParameter; + } + if (ticks == 0U) { + return osOK; + } + + osRtxThreadWaitEnter(osRtxThreadWaitingDelay, (uint32_t)ticks); + + return osOK; +} + + +// ==== Public API ==== + +/// Wait for Timeout (Time Delay). +osStatus_t osDelay (uint32_t ticks) { + EvrRtxThreadDelay(ticks); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxThreadError(NULL, osErrorISR); + return osErrorISR; + } + return __svcDelay(ticks); +} + +/// Wait until specified time. +osStatus_t osDelayUntil (uint64_t ticks) { + EvrRtxThreadDelayUntil(ticks); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxThreadError(NULL, osErrorISR); + return osErrorISR; + } + return __svcDelayUntil((uint32_t)ticks, (uint32_t)(ticks >> 32)); +} diff --git a/rtos/TARGET_CORTEX/rtx5/rtx_evflags.c b/rtos/TARGET_CORTEX/rtx5/rtx_evflags.c new file mode 100644 index 0000000..1c534d5 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/rtx_evflags.c @@ -0,0 +1,576 @@ +/* + * Copyright (c) 2013-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * + * Project: CMSIS-RTOS RTX + * Title: Event Flags functions + * + * ----------------------------------------------------------------------------- + */ + +#include "rtx_lib.h" + + +// ==== Helper functions ==== + +/// Set Event Flags. +/// \param[in] ef event flags object. +/// \param[in] flags specifies the flags to set. +/// \return event flags after setting. +static uint32_t EventFlagsSet (os_event_flags_t *ef, uint32_t flags) { +#if (__EXCLUSIVE_ACCESS == 0U) + uint32_t primask = __get_PRIMASK(); +#endif + uint32_t event_flags; + +#if (__EXCLUSIVE_ACCESS == 0U) + __disable_irq(); + + ef->event_flags |= flags; + event_flags = ef->event_flags; + + if (primask == 0U) { + __enable_irq(); + } +#else + event_flags = atomic_set32(&ef->event_flags, flags); +#endif + + return event_flags; +} + +/// Clear Event Flags. +/// \param[in] ef event flags object. +/// \param[in] flags specifies the flags to clear. +/// \return event flags before clearing. +static uint32_t EventFlagsClear (os_event_flags_t *ef, uint32_t flags) { +#if (__EXCLUSIVE_ACCESS == 0U) + uint32_t primask = __get_PRIMASK(); +#endif + uint32_t event_flags; + +#if (__EXCLUSIVE_ACCESS == 0U) + __disable_irq(); + + event_flags = ef->event_flags; + ef->event_flags &= ~flags; + + if (primask == 0U) { + __enable_irq(); + } +#else + event_flags = atomic_clr32(&ef->event_flags, flags); +#endif + + return event_flags; +} + +/// Check Event Flags. +/// \param[in] ef event flags object. +/// \param[in] flags specifies the flags to check. +/// \param[in] options specifies flags options (osFlagsXxxx). +/// \return event flags before clearing or 0 if specified flags have not been set. +static uint32_t EventFlagsCheck (os_event_flags_t *ef, uint32_t flags, uint32_t options) { +#if (__EXCLUSIVE_ACCESS == 0U) + uint32_t primask; +#endif + uint32_t event_flags; + + if ((options & osFlagsNoClear) == 0U) { +#if (__EXCLUSIVE_ACCESS == 0U) + primask = __get_PRIMASK(); + __disable_irq(); + + event_flags = ef->event_flags; + if ((((options & osFlagsWaitAll) != 0U) && ((event_flags & flags) != flags)) || + (((options & osFlagsWaitAll) == 0U) && ((event_flags & flags) == 0U))) { + event_flags = 0U; + } else { + ef->event_flags &= ~flags; + } + + if (primask == 0U) { + __enable_irq(); + } +#else + if ((options & osFlagsWaitAll) != 0U) { + event_flags = atomic_chk32_all(&ef->event_flags, flags); + } else { + event_flags = atomic_chk32_any(&ef->event_flags, flags); + } +#endif + } else { + event_flags = ef->event_flags; + if ((((options & osFlagsWaitAll) != 0U) && ((event_flags & flags) != flags)) || + (((options & osFlagsWaitAll) == 0U) && ((event_flags & flags) == 0U))) { + event_flags = 0U; + } + } + + return event_flags; +} + + +// ==== Library functions ==== + +/// Event Flags post ISR processing. +/// \param[in] ef event flags object. +void osRtxEventFlagsPostProcess (os_event_flags_t *ef) { + os_thread_t *thread; + os_thread_t *thread_next; + uint32_t event_flags; + + if (ef->state == osRtxObjectInactive) { + return; + } + + // Check if Threads are waiting for Event Flags + thread = ef->thread_list; + while (thread != NULL) { + thread_next = thread->thread_next; + event_flags = EventFlagsCheck(ef, thread->wait_flags, thread->flags_options); + if (event_flags != 0U) { + osRtxThreadListRemove(thread); + osRtxThreadWaitExit(thread, event_flags, false); + EvrRtxEventFlagsWaitCompleted(ef, thread->wait_flags, thread->flags_options, event_flags); + } + thread = thread_next; + } +} + + +// ==== Service Calls ==== + +// Service Calls definitions +SVC0_1M(EventFlagsNew, osEventFlagsId_t, const osEventFlagsAttr_t *) +SVC0_1 (EventFlagsGetName, const char *, osEventFlagsId_t) +SVC0_2 (EventFlagsSet, uint32_t, osEventFlagsId_t, uint32_t) +SVC0_2 (EventFlagsClear, uint32_t, osEventFlagsId_t, uint32_t) +SVC0_1 (EventFlagsGet, uint32_t, osEventFlagsId_t) +SVC0_4 (EventFlagsWait, uint32_t, osEventFlagsId_t, uint32_t, uint32_t, uint32_t) +SVC0_1 (EventFlagsDelete, osStatus_t, osEventFlagsId_t) + +/// Create and Initialize an Event Flags object. +/// \note API identical to osEventFlagsNew +osEventFlagsId_t svcRtxEventFlagsNew (const osEventFlagsAttr_t *attr) { + os_event_flags_t *ef; + uint8_t flags; + const char *name; + + // Process attributes + if (attr != NULL) { + name = attr->name; + ef = attr->cb_mem; + if (ef != NULL) { + if (((uint32_t)ef & 3U) || (attr->cb_size < sizeof(os_event_flags_t))) { + EvrRtxEventFlagsError(NULL, osRtxErrorInvalidControlBlock); + return NULL; + } + } else { + if (attr->cb_size != 0U) { + EvrRtxEventFlagsError(NULL, osRtxErrorInvalidControlBlock); + return NULL; + } + } + } else { + name = NULL; + ef = NULL; + } + + // Allocate object memory if not provided + if (ef == NULL) { + if (osRtxInfo.mpi.event_flags != NULL) { + ef = osRtxMemoryPoolAlloc(osRtxInfo.mpi.event_flags); + } else { + ef = osRtxMemoryAlloc(osRtxInfo.mem.common, sizeof(os_event_flags_t), 1U); + } + if (ef == NULL) { + EvrRtxEventFlagsError(NULL, osErrorNoMemory); + return NULL; + } + flags = osRtxFlagSystemObject; + } else { + flags = 0U; + } + + // Initialize control block + ef->id = osRtxIdEventFlags; + ef->state = osRtxObjectActive; + ef->flags = flags; + ef->name = name; + ef->thread_list = NULL; + ef->event_flags = 0U; + + // Register post ISR processing function + osRtxInfo.post_process.event_flags = osRtxEventFlagsPostProcess; + + EvrRtxEventFlagsCreated(ef); + + return ef; +} + +/// Get name of an Event Flags object. +/// \note API identical to osEventFlagsGetName +const char *svcRtxEventFlagsGetName (osEventFlagsId_t ef_id) { + os_event_flags_t *ef = (os_event_flags_t *)ef_id; + + // Check parameters + if ((ef == NULL) || (ef->id != osRtxIdEventFlags)) { + EvrRtxEventFlagsGetName(ef, NULL); + return NULL; + } + + // Check object state + if (ef->state == osRtxObjectInactive) { + EvrRtxEventFlagsGetName(ef, NULL); + return NULL; + } + + EvrRtxEventFlagsGetName(ef, ef->name); + + return ef->name; +} + +/// Set the specified Event Flags. +/// \note API identical to osEventFlagsSet +uint32_t svcRtxEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags) { + os_event_flags_t *ef = (os_event_flags_t *)ef_id; + os_thread_t *thread; + os_thread_t *thread_next; + uint32_t event_flags; + uint32_t event_flags0; + + // Check parameters + if ((ef == NULL) || (ef->id != osRtxIdEventFlags) || + (flags & ~((1U << osRtxEventFlagsLimit) - 1U))) { + EvrRtxEventFlagsError(ef, osErrorParameter); + return ((uint32_t)osErrorParameter); + } + + // Check object state + if (ef->state == osRtxObjectInactive) { + EvrRtxEventFlagsError(ef, osErrorResource); + return ((uint32_t)osErrorResource); + } + + // Set Event Flags + event_flags = EventFlagsSet(ef, flags); + + // Check if Threads are waiting for Event Flags + thread = ef->thread_list; + while (thread != NULL) { + thread_next = thread->thread_next; + event_flags0 = EventFlagsCheck(ef, thread->wait_flags, thread->flags_options); + if (event_flags0 != 0U) { + if ((thread->flags_options & osFlagsNoClear) == 0U) { + event_flags = event_flags0 & ~thread->wait_flags; + } else { + event_flags = event_flags0; + } + osRtxThreadListRemove(thread); + osRtxThreadWaitExit(thread, event_flags0, false); + EvrRtxEventFlagsWaitCompleted(ef, thread->wait_flags, thread->flags_options, event_flags0); + } + thread = thread_next; + } + osRtxThreadDispatch(NULL); + + EvrRtxEventFlagsSetDone(ef, event_flags); + + return event_flags; +} + +/// Clear the specified Event Flags. +/// \note API identical to osEventFlagsClear +uint32_t svcRtxEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags) { + os_event_flags_t *ef = (os_event_flags_t *)ef_id; + uint32_t event_flags; + + // Check parameters + if ((ef == NULL) || (ef->id != osRtxIdEventFlags) || + (flags & ~((1U << osRtxEventFlagsLimit) - 1U))) { + EvrRtxEventFlagsError(ef, osErrorParameter); + return ((uint32_t)osErrorParameter); + } + + // Check object state + if (ef->state == osRtxObjectInactive) { + EvrRtxEventFlagsError(ef, osErrorResource); + return ((uint32_t)osErrorResource); + } + + // Clear Event Flags + event_flags = EventFlagsClear(ef, flags); + + EvrRtxEventFlagsClearDone(ef, event_flags); + + return event_flags; +} + +/// Get the current Event Flags. +/// \note API identical to osEventFlagsGet +uint32_t svcRtxEventFlagsGet (osEventFlagsId_t ef_id) { + os_event_flags_t *ef = (os_event_flags_t *)ef_id; + + // Check parameters + if ((ef == NULL) || (ef->id != osRtxIdEventFlags)) { + EvrRtxEventFlagsGet(ef, 0U); + return 0U; + } + + // Check object state + if (ef->state == osRtxObjectInactive) { + EvrRtxEventFlagsGet(ef, 0U); + return 0U; + } + + EvrRtxEventFlagsGet(ef, ef->event_flags); + + return ef->event_flags; +} + +/// Wait for one or more Event Flags to become signaled. +/// \note API identical to osEventFlagsWait +uint32_t svcRtxEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout) { + os_event_flags_t *ef = (os_event_flags_t *)ef_id; + os_thread_t *running_thread; + uint32_t event_flags; + + running_thread = osRtxThreadGetRunning(); + if (running_thread == NULL) { + EvrRtxEventFlagsError(ef, osRtxErrorKernelNotRunning); + return ((uint32_t)osError); + } + + // Check parameters + if ((ef == NULL) || (ef->id != osRtxIdEventFlags) || + (flags & ~((1U << osRtxEventFlagsLimit) - 1U))) { + EvrRtxEventFlagsError(ef, osErrorParameter); + return ((uint32_t)osErrorParameter); + } + + // Check object state + if (ef->state == osRtxObjectInactive) { + EvrRtxEventFlagsError(ef, osErrorResource); + return ((uint32_t)osErrorResource); + } + + // Check Event Flags + event_flags = EventFlagsCheck(ef, flags, options); + if (event_flags != 0U) { + EvrRtxEventFlagsWaitCompleted(ef, flags, options, event_flags); + return event_flags; + } + + // Check if timeout is specified + if (timeout != 0U) { + EvrRtxEventFlagsWaitPending(ef, flags, options, timeout); + // Store waiting flags and options + running_thread->wait_flags = flags; + running_thread->flags_options = (uint8_t)options; + // Suspend current Thread + osRtxThreadListPut((os_object_t*)ef, running_thread); + osRtxThreadWaitEnter(osRtxThreadWaitingEventFlags, timeout); + return ((uint32_t)osErrorTimeout); + } + + EvrRtxEventFlagsWaitNotCompleted(ef, flags, options); + + return ((uint32_t)osErrorResource); +} + +/// Delete an Event Flags object. +/// \note API identical to osEventFlagsDelete +osStatus_t svcRtxEventFlagsDelete (osEventFlagsId_t ef_id) { + os_event_flags_t *ef = (os_event_flags_t *)ef_id; + os_thread_t *thread; + + // Check parameters + if ((ef == NULL) || (ef->id != osRtxIdEventFlags)) { + EvrRtxEventFlagsError(ef, osErrorParameter); + return osErrorParameter; + } + + // Check object state + if (ef->state == osRtxObjectInactive) { + EvrRtxEventFlagsError(ef, osErrorResource); + return osErrorResource; + } + + // Mark object as inactive + ef->state = osRtxObjectInactive; + + // Unblock waiting threads + if (ef->thread_list != NULL) { + do { + thread = osRtxThreadListGet((os_object_t*)ef); + osRtxThreadWaitExit(thread, (uint32_t)osErrorResource, false); + } while (ef->thread_list != NULL); + osRtxThreadDispatch(NULL); + } + + // Free object memory + if (ef->flags & osRtxFlagSystemObject) { + if (osRtxInfo.mpi.event_flags != NULL) { + osRtxMemoryPoolFree(osRtxInfo.mpi.event_flags, ef); + } else { + osRtxMemoryFree(osRtxInfo.mem.common, ef); + } + } + + EvrRtxEventFlagsDestroyed(ef); + + return osOK; +} + + +// ==== ISR Calls ==== + +/// Set the specified Event Flags. +/// \note API identical to osEventFlagsSet +__STATIC_INLINE +uint32_t isrRtxEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags) { + os_event_flags_t *ef = (os_event_flags_t *)ef_id; + uint32_t event_flags; + + // Check parameters + if ((ef == NULL) || (ef->id != osRtxIdEventFlags) || + (flags & ~((1U << osRtxEventFlagsLimit) - 1U))) { + EvrRtxEventFlagsError(ef, osErrorParameter); + return ((uint32_t)osErrorParameter); + } + + // Check object state + if (ef->state == osRtxObjectInactive) { + EvrRtxEventFlagsError(ef, osErrorResource); + return ((uint32_t)osErrorResource); + } + + // Set Event Flags + event_flags = EventFlagsSet(ef, flags); + + // Register post ISR processing + osRtxPostProcess((os_object_t *)ef); + + EvrRtxEventFlagsSetDone(ef, event_flags); + + return event_flags; +} + +/// Wait for one or more Event Flags to become signaled. +/// \note API identical to osEventFlagsWait +__STATIC_INLINE +uint32_t isrRtxEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout) { + os_event_flags_t *ef = (os_event_flags_t *)ef_id; + uint32_t event_flags; + + // Check parameters + if ((ef == NULL) || (ef->id != osRtxIdEventFlags) || (timeout != 0U) || + (flags & ~((1U << osRtxEventFlagsLimit) - 1U))) { + EvrRtxEventFlagsError(ef, osErrorParameter); + return ((uint32_t)osErrorParameter); + } + + // Check object state + if (ef->state == osRtxObjectInactive) { + EvrRtxEventFlagsError(ef, osErrorResource); + return ((uint32_t)osErrorResource); + } + + // Check Event Flags + event_flags = EventFlagsCheck(ef, flags, options); + if (event_flags != 0U) { + EvrRtxEventFlagsWaitCompleted(ef, flags, options, event_flags); + return ((uint32_t)event_flags); + } + + EvrRtxEventFlagsWaitNotCompleted(ef, flags, options); + + return ((uint32_t)osErrorResource); +} + + +// ==== Public API ==== + +/// Create and Initialize an Event Flags object. +osEventFlagsId_t osEventFlagsNew (const osEventFlagsAttr_t *attr) { + EvrRtxEventFlagsNew(attr); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxEventFlagsError(NULL, osErrorISR); + return NULL; + } + return __svcEventFlagsNew(attr); +} + +/// Get name of an Event Flags object. +const char *osEventFlagsGetName (osEventFlagsId_t ef_id) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxEventFlagsGetName(ef_id, NULL); + return NULL; + } + return __svcEventFlagsGetName(ef_id); +} + +/// Set the specified Event Flags. +uint32_t osEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags) { + EvrRtxEventFlagsSet(ef_id, flags); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + return isrRtxEventFlagsSet(ef_id, flags); + } else { + return __svcEventFlagsSet(ef_id, flags); + } +} + +/// Clear the specified Event Flags. +uint32_t osEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags) { + EvrRtxEventFlagsClear(ef_id, flags); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + return svcRtxEventFlagsClear(ef_id, flags); + } else { + return __svcEventFlagsClear(ef_id, flags); + } +} + +/// Get the current Event Flags. +uint32_t osEventFlagsGet (osEventFlagsId_t ef_id) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + return svcRtxEventFlagsGet(ef_id); + } else { + return __svcEventFlagsGet(ef_id); + } +} + +/// Wait for one or more Event Flags to become signaled. +uint32_t osEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout) { + EvrRtxEventFlagsWait(ef_id, flags, options, timeout); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + return isrRtxEventFlagsWait(ef_id, flags, options, timeout); + } else { + return __svcEventFlagsWait(ef_id, flags, options, timeout); + } +} + +/// Delete an Event Flags object. +osStatus_t osEventFlagsDelete (osEventFlagsId_t ef_id) { + EvrRtxEventFlagsDelete(ef_id); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxEventFlagsError(ef_id, osErrorISR); + return osErrorISR; + } + return __svcEventFlagsDelete(ef_id); +} diff --git a/rtos/TARGET_CORTEX/rtx5/rtx_evr.c b/rtos/TARGET_CORTEX/rtx5/rtx_evr.c new file mode 100644 index 0000000..f368df8 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/rtx_evr.c @@ -0,0 +1,2077 @@ +/* + * Copyright (c) 2013-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * + * Project: CMSIS-RTOS RTX + * Title: RTX Event Recorder + * + * ----------------------------------------------------------------------------- + */ + +#include +#include "cmsis_compiler.h" +#include "rtx_evr.h" // RTX Event Recorder definitions + +#ifdef RTE_Compiler_EventRecorder + +#include "EventRecorder.h" // Keil::Compiler:Event Recorder + +/// RTOS component number +#define EvtRtxMemoryNo (0xF0U) +#define EvtRtxKernelNo (0xF1U) +#define EvtRtxThreadNo (0xF2U) +#define EvtRtxTimerNo (0xF3U) +#define EvtRtxEventFlagsNo (0xF4U) +#define EvtRtxMutexNo (0xF5U) +#define EvtRtxSemaphoreNo (0xF6U) +#define EvtRtxMemoryPoolNo (0xF7U) +#define EvtRtxMessageQueueNo (0xF8U) + +/// Event IDs for "RTX Memory Management" +#define EvtRtxMemoryInit EventID(EventLevelOp, EvtRtxMemoryNo, 0x00U) +#define EvtRtxMemoryAlloc EventID(EventLevelOp, EvtRtxMemoryNo, 0x01U) +#define EvtRtxMemoryFree EventID(EventLevelOp, EvtRtxMemoryNo, 0x02U) +#define EvtRtxMemoryBlockInit EventID(EventLevelOp, EvtRtxMemoryNo, 0x03U) +#define EvtRtxMemoryBlockAlloc EventID(EventLevelOp, EvtRtxMemoryNo, 0x04U) +#define EvtRtxMemoryBlockFree EventID(EventLevelOp, EvtRtxMemoryNo, 0x05U) + +/// Event IDs for "RTX Kernel" +#define EvtRtxKernelError EventID(EventLevelError, EvtRtxKernelNo, 0x00U) +#define EvtRtxKernelInitialize EventID(EventLevelAPI, EvtRtxKernelNo, 0x01U) +#define EvtRtxKernelInitializeCompleted EventID(EventLevelOp, EvtRtxKernelNo, 0x02U) +#define EvtRtxKernelGetInfo EventID(EventLevelAPI, EvtRtxKernelNo, 0x03U) +#define EvtRtxKernelInfoRetrieved EventID(EventLevelOp, EvtRtxKernelNo, 0x04U) +#define EvtRtxKernelInfoRetrieved_Detail EventID(EventLevelDetail, EvtRtxKernelNo, 0x05U) +#define EvtRtxKernelGetState EventID(EventLevelAPI, EvtRtxKernelNo, 0x06U) +#define EvtRtxKernelStart EventID(EventLevelAPI, EvtRtxKernelNo, 0x07U) +#define EvtRtxKernelStarted EventID(EventLevelOp, EvtRtxKernelNo, 0x08U) +#define EvtRtxKernelLock EventID(EventLevelAPI, EvtRtxKernelNo, 0x09U) +#define EvtRtxKernelLocked EventID(EventLevelOp, EvtRtxKernelNo, 0x0AU) +#define EvtRtxKernelUnlock EventID(EventLevelAPI, EvtRtxKernelNo, 0x0BU) +#define EvtRtxKernelUnlocked EventID(EventLevelOp, EvtRtxKernelNo, 0x0CU) +#define EvtRtxKernelRestoreLock EventID(EventLevelAPI, EvtRtxKernelNo, 0x0DU) +#define EvtRtxKernelLockRestored EventID(EventLevelOp, EvtRtxKernelNo, 0x0EU) +#define EvtRtxKernelSuspend EventID(EventLevelAPI, EvtRtxKernelNo, 0x0FU) +#define EvtRtxKernelSuspended EventID(EventLevelOp, EvtRtxKernelNo, 0x10U) +#define EvtRtxKernelResume EventID(EventLevelAPI, EvtRtxKernelNo, 0x11U) +#define EvtRtxKernelResumed EventID(EventLevelOp, EvtRtxKernelNo, 0x12U) +#define EvtRtxKernelGetTickCount EventID(EventLevelAPI, EvtRtxKernelNo, 0x13U) +#define EvtRtxKernelGetTickFreq EventID(EventLevelAPI, EvtRtxKernelNo, 0x14U) +#define EvtRtxKernelGetSysTimerCount EventID(EventLevelAPI, EvtRtxKernelNo, 0x15U) +#define EvtRtxKernelGetSysTimerFreq EventID(EventLevelAPI, EvtRtxKernelNo, 0x16U) + +/// Event IDs for "RTX Thread" +#define EvtRtxThreadError EventID(EventLevelError, EvtRtxThreadNo, 0x00U) +#define EvtRtxThreadNew EventID(EventLevelAPI, EvtRtxThreadNo, 0x01U) +#define EvtRtxThreadNew_Detail EventID(EventLevelDetail, EvtRtxThreadNo, 0x02U) +#define EvtRtxThreadCreated EventID(EventLevelOp, EvtRtxThreadNo, 0x03U) +#define EvtRtxThreadGetName EventID(EventLevelAPI, EvtRtxThreadNo, 0x04U) +#define EvtRtxThreadGetName_Detail EventID(EventLevelDetail, EvtRtxThreadNo, 0x05U) +#define EvtRtxThreadGetId EventID(EventLevelAPI, EvtRtxThreadNo, 0x06U) +#define EvtRtxThreadGetState EventID(EventLevelAPI, EvtRtxThreadNo, 0x07U) +#define EvtRtxThreadGetStackSize EventID(EventLevelAPI, EvtRtxThreadNo, 0x08U) +#define EvtRtxThreadGetStackSpace EventID(EventLevelAPI, EvtRtxThreadNo, 0x09U) +#define EvtRtxThreadSetPriority EventID(EventLevelAPI, EvtRtxThreadNo, 0x0AU) +#define EvtRtxThreadGetPriority EventID(EventLevelAPI, EvtRtxThreadNo, 0x0BU) +#define EvtRtxThreadYield EventID(EventLevelAPI, EvtRtxThreadNo, 0x0CU) +#define EvtRtxThreadSuspend EventID(EventLevelAPI, EvtRtxThreadNo, 0x0DU) +#define EvtRtxThreadSuspended EventID(EventLevelOp, EvtRtxThreadNo, 0x0EU) +#define EvtRtxThreadResume EventID(EventLevelAPI, EvtRtxThreadNo, 0x0FU) +#define EvtRtxThreadResumed EventID(EventLevelOp, EvtRtxThreadNo, 0x10U) +#define EvtRtxThreadDetach EventID(EventLevelAPI, EvtRtxThreadNo, 0x11U) +#define EvtRtxThreadDetached EventID(EventLevelOp, EvtRtxThreadNo, 0x12U) +#define EvtRtxThreadJoin EventID(EventLevelAPI, EvtRtxThreadNo, 0x13U) +#define EvtRtxThreadJoinPending EventID(EventLevelOp, EvtRtxThreadNo, 0x14U) +#define EvtRtxThreadJoined EventID(EventLevelOp, EvtRtxThreadNo, 0x15U) +#define EvtRtxThreadBlocked EventID(EventLevelOp, EvtRtxThreadNo, 0x16U) +#define EvtRtxThreadUnblocked EventID(EventLevelOp, EvtRtxThreadNo, 0x17U) +#define EvtRtxThreadSwitch EventID(EventLevelOp, EvtRtxThreadNo, 0x18U) +#define EvtRtxThreadExit EventID(EventLevelAPI, EvtRtxThreadNo, 0x19U) +#define EvtRtxThreadTerminate EventID(EventLevelAPI, EvtRtxThreadNo, 0x1AU) +#define EvtRtxThreadDestroyed EventID(EventLevelOp, EvtRtxThreadNo, 0x1BU) +#define EvtRtxThreadGetCount EventID(EventLevelAPI, EvtRtxThreadNo, 0x1CU) +#define EvtRtxThreadEnumerate EventID(EventLevelAPI, EvtRtxThreadNo, 0x1DU) +#define EvtRtxThreadFlagsSet EventID(EventLevelAPI, EvtRtxThreadNo, 0x1EU) +#define EvtRtxThreadFlagsSetDone EventID(EventLevelOp, EvtRtxThreadNo, 0x1FU) +#define EvtRtxThreadFlagsClear EventID(EventLevelAPI, EvtRtxThreadNo, 0x20U) +#define EvtRtxThreadFlagsClearDone EventID(EventLevelOp, EvtRtxThreadNo, 0x21U) +#define EvtRtxThreadFlagsGet EventID(EventLevelAPI, EvtRtxThreadNo, 0x22U) +#define EvtRtxThreadFlagsWait EventID(EventLevelAPI, EvtRtxThreadNo, 0x23U) +#define EvtRtxThreadFlagsWaitPending EventID(EventLevelOp, EvtRtxThreadNo, 0x24U) +#define EvtRtxThreadFlagsWaitTimeout EventID(EventLevelOp, EvtRtxThreadNo, 0x25U) +#define EvtRtxThreadFlagsWaitCompleted EventID(EventLevelOp, EvtRtxThreadNo, 0x26U) +#define EvtRtxThreadFlagsWaitNotCompleted EventID(EventLevelOp, EvtRtxThreadNo, 0x27U) +#define EvtRtxThreadDelay EventID(EventLevelAPI, EvtRtxThreadNo, 0x28U) +#define EvtRtxThreadDelayUntil EventID(EventLevelAPI, EvtRtxThreadNo, 0x29U) +#define EvtRtxThreadDelayCompleted EventID(EventLevelOp, EvtRtxThreadNo, 0x2AU) + +/// Event IDs for "RTX Timer" +#define EvtRtxTimerError EventID(EventLevelError, EvtRtxTimerNo, 0x00U) +#define EvtRtxTimerCallback EventID(EventLevelOp, EvtRtxTimerNo, 0x01U) +#define EvtRtxTimerNew EventID(EventLevelAPI, EvtRtxTimerNo, 0x02U) +#define EvtRtxTimerNew_Detail EventID(EventLevelDetail, EvtRtxTimerNo, 0x03U) +#define EvtRtxTimerCreated EventID(EventLevelOp, EvtRtxTimerNo, 0x04U) +#define EvtRtxTimerGetName EventID(EventLevelAPI, EvtRtxTimerNo, 0x05U) +#define EvtRtxTimerGetName_Detail EventID(EventLevelDetail, EvtRtxTimerNo, 0x06U) +#define EvtRtxTimerStart EventID(EventLevelAPI, EvtRtxTimerNo, 0x07U) +#define EvtRtxTimerStarted EventID(EventLevelOp, EvtRtxTimerNo, 0x08U) +#define EvtRtxTimerStop EventID(EventLevelAPI, EvtRtxTimerNo, 0x09U) +#define EvtRtxTimerStopped EventID(EventLevelOp, EvtRtxTimerNo, 0x0AU) +#define EvtRtxTimerIsRunning EventID(EventLevelAPI, EvtRtxTimerNo, 0x0BU) +#define EvtRtxTimerDelete EventID(EventLevelAPI, EvtRtxTimerNo, 0x0CU) +#define EvtRtxTimerDestroyed EventID(EventLevelOp, EvtRtxTimerNo, 0x0DU) + +/// Event IDs for "RTX Event Flags" +#define EvtRtxEventFlagsError EventID(EventLevelError, EvtRtxEventFlagsNo, 0x00U) +#define EvtRtxEventFlagsNew EventID(EventLevelAPI, EvtRtxEventFlagsNo, 0x01U) +#define EvtRtxEventFlagsNew_Detail EventID(EventLevelDetail, EvtRtxEventFlagsNo, 0x02U) +#define EvtRtxEventFlagsCreated EventID(EventLevelOp, EvtRtxEventFlagsNo, 0x03U) +#define EvtRtxEventFlagsGetName EventID(EventLevelAPI, EvtRtxEventFlagsNo, 0x04U) +#define EvtRtxEventFlagsGetName_Detail EventID(EventLevelDetail, EvtRtxEventFlagsNo, 0x05U) +#define EvtRtxEventFlagsSet EventID(EventLevelAPI, EvtRtxEventFlagsNo, 0x06U) +#define EvtRtxEventFlagsSetDone EventID(EventLevelOp, EvtRtxEventFlagsNo, 0x07U) +#define EvtRtxEventFlagsClear EventID(EventLevelAPI, EvtRtxEventFlagsNo, 0x08U) +#define EvtRtxEventFlagsClearDone EventID(EventLevelOp, EvtRtxEventFlagsNo, 0x09U) +#define EvtRtxEventFlagsGet EventID(EventLevelAPI, EvtRtxEventFlagsNo, 0x0AU) +#define EvtRtxEventFlagsWait EventID(EventLevelAPI, EvtRtxEventFlagsNo, 0x0BU) +#define EvtRtxEventFlagsWaitPending EventID(EventLevelOp, EvtRtxEventFlagsNo, 0x0CU) +#define EvtRtxEventFlagsWaitTimeout EventID(EventLevelOp, EvtRtxEventFlagsNo, 0x0DU) +#define EvtRtxEventFlagsWaitCompleted EventID(EventLevelOp, EvtRtxEventFlagsNo, 0x0EU) +#define EvtRtxEventFlagsWaitNotCompleted EventID(EventLevelOp, EvtRtxEventFlagsNo, 0x0FU) +#define EvtRtxEventFlagsDelete EventID(EventLevelAPI, EvtRtxEventFlagsNo, 0x10U) +#define EvtRtxEventFlagsDestroyed EventID(EventLevelOp, EvtRtxEventFlagsNo, 0x11U) + +/// Event IDs for "RTX Mutex" +#define EvtRtxMutexError EventID(EventLevelError, EvtRtxMutexNo, 0x00U) +#define EvtRtxMutexNew EventID(EventLevelAPI, EvtRtxMutexNo, 0x01U) +#define EvtRtxMutexNew_Detail EventID(EventLevelDetail, EvtRtxMutexNo, 0x02U) +#define EvtRtxMutexCreated EventID(EventLevelOp, EvtRtxMutexNo, 0x03U) +#define EvtRtxMutexGetName EventID(EventLevelAPI, EvtRtxMutexNo, 0x04U) +#define EvtRtxMutexGetName_Detail EventID(EventLevelDetail, EvtRtxMutexNo, 0x05U) +#define EvtRtxMutexAcquire EventID(EventLevelAPI, EvtRtxMutexNo, 0x06U) +#define EvtRtxMutexAcquirePending EventID(EventLevelError, EvtRtxMutexNo, 0x07U) +#define EvtRtxMutexAcquireTimeout EventID(EventLevelError, EvtRtxMutexNo, 0x08U) +#define EvtRtxMutexAcquired EventID(EventLevelOp, EvtRtxMutexNo, 0x09U) +#define EvtRtxMutexNotAcquired EventID(EventLevelOp, EvtRtxMutexNo, 0x0AU) +#define EvtRtxMutexRelease EventID(EventLevelAPI, EvtRtxMutexNo, 0x0BU) +#define EvtRtxMutexReleased EventID(EventLevelOp, EvtRtxMutexNo, 0x0CU) +#define EvtRtxMutexGetOwner EventID(EventLevelAPI, EvtRtxMutexNo, 0x0DU) +#define EvtRtxMutexDelete EventID(EventLevelAPI, EvtRtxMutexNo, 0x0EU) +#define EvtRtxMutexDestroyed EventID(EventLevelOp, EvtRtxMutexNo, 0x0FU) + +/// Event IDs for "RTX Semaphore" +#define EvtRtxSemaphoreError EventID(EventLevelError, EvtRtxSemaphoreNo, 0x00U) +#define EvtRtxSemaphoreNew EventID(EventLevelAPI, EvtRtxSemaphoreNo, 0x01U) +#define EvtRtxSemaphoreNew_Detail EventID(EventLevelDetail, EvtRtxSemaphoreNo, 0x02U) +#define EvtRtxSemaphoreCreated EventID(EventLevelOp, EvtRtxSemaphoreNo, 0x03U) +#define EvtRtxSemaphoreGetName EventID(EventLevelAPI, EvtRtxSemaphoreNo, 0x04U) +#define EvtRtxSemaphoreGetName_Detail EventID(EventLevelDetail, EvtRtxSemaphoreNo, 0x05U) +#define EvtRtxSemaphoreAcquire EventID(EventLevelAPI, EvtRtxSemaphoreNo, 0x06U) +#define EvtRtxSemaphoreAcquirePending EventID(EventLevelOp, EvtRtxSemaphoreNo, 0x07U) +#define EvtRtxSemaphoreAcquireTimeout EventID(EventLevelOp, EvtRtxSemaphoreNo, 0x08U) +#define EvtRtxSemaphoreAcquired EventID(EventLevelOp, EvtRtxSemaphoreNo, 0x09U) +#define EvtRtxSemaphoreNotAcquired EventID(EventLevelOp, EvtRtxSemaphoreNo, 0x0AU) +#define EvtRtxSemaphoreRelease EventID(EventLevelAPI, EvtRtxSemaphoreNo, 0x0BU) +#define EvtRtxSemaphoreReleased EventID(EventLevelOp, EvtRtxSemaphoreNo, 0x0CU) +#define EvtRtxSemaphoreGetCount EventID(EventLevelAPI, EvtRtxSemaphoreNo, 0x0DU) +#define EvtRtxSemaphoreDelete EventID(EventLevelAPI, EvtRtxSemaphoreNo, 0x0EU) +#define EvtRtxSemaphoreDestroyed EventID(EventLevelOp, EvtRtxSemaphoreNo, 0x0FU) + +/// Event IDs for "RTX Memory Pool" +#define EvtRtxMemoryPoolError EventID(EventLevelError, EvtRtxMemoryPoolNo, 0x00U) +#define EvtRtxMemoryPoolNew EventID(EventLevelAPI, EvtRtxMemoryPoolNo, 0x01U) +#define EvtRtxMemoryPoolNew_Detail EventID(EventLevelDetail, EvtRtxMemoryPoolNo, 0x02U) +#define EvtRtxMemoryPoolCreated EventID(EventLevelOp, EvtRtxMemoryPoolNo, 0x03U) +#define EvtRtxMemoryPoolGetName EventID(EventLevelAPI, EvtRtxMemoryPoolNo, 0x04U) +#define EvtRtxMemoryPoolGetName_Detail EventID(EventLevelDetail, EvtRtxMemoryPoolNo, 0x05U) +#define EvtRtxMemoryPoolAlloc EventID(EventLevelAPI, EvtRtxMemoryPoolNo, 0x06U) +#define EvtRtxMemoryPoolAllocPending EventID(EventLevelOp, EvtRtxMemoryPoolNo, 0x07U) +#define EvtRtxMemoryPoolAllocTimeout EventID(EventLevelOp, EvtRtxMemoryPoolNo, 0x08U) +#define EvtRtxMemoryPoolAllocated EventID(EventLevelOp, EvtRtxMemoryPoolNo, 0x09U) +#define EvtRtxMemoryPoolAllocFailed EventID(EventLevelOp, EvtRtxMemoryPoolNo, 0x0AU) +#define EvtRtxMemoryPoolFree EventID(EventLevelAPI, EvtRtxMemoryPoolNo, 0x0BU) +#define EvtRtxMemoryPoolDeallocated EventID(EventLevelOp, EvtRtxMemoryPoolNo, 0x0CU) +#define EvtRtxMemoryPoolFreeFailed EventID(EventLevelOp, EvtRtxMemoryPoolNo, 0x0DU) +#define EvtRtxMemoryPoolGetCapacity EventID(EventLevelAPI, EvtRtxMemoryPoolNo, 0x0EU) +#define EvtRtxMemoryPoolGetBlockSize EventID(EventLevelAPI, EvtRtxMemoryPoolNo, 0x0FU) +#define EvtRtxMemoryPoolGetCount EventID(EventLevelAPI, EvtRtxMemoryPoolNo, 0x10U) +#define EvtRtxMemoryPoolGetSpace EventID(EventLevelAPI, EvtRtxMemoryPoolNo, 0x11U) +#define EvtRtxMemoryPoolDelete EventID(EventLevelAPI, EvtRtxMemoryPoolNo, 0x12U) +#define EvtRtxMemoryPoolDestroyed EventID(EventLevelOp, EvtRtxMemoryPoolNo, 0x13U) + +/// Event IDs for "RTX Message Queue" +#define EvtRtxMessageQueueError EventID(EventLevelError, EvtRtxMessageQueueNo, 0x00U) +#define EvtRtxMessageQueueNew EventID(EventLevelAPI, EvtRtxMessageQueueNo, 0x01U) +#define EvtRtxMessageQueueNew_Detail EventID(EventLevelDetail, EvtRtxMessageQueueNo, 0x02U) +#define EvtRtxMessageQueueCreated EventID(EventLevelOp, EvtRtxMessageQueueNo, 0x03U) +#define EvtRtxMessageQueueGetName EventID(EventLevelAPI, EvtRtxMessageQueueNo, 0x04U) +#define EvtRtxMessageQueueGetName_Detail EventID(EventLevelDetail, EvtRtxMessageQueueNo, 0x05U) +#define EvtRtxMessageQueuePut EventID(EventLevelAPI, EvtRtxMessageQueueNo, 0x06U) +#define EvtRtxMessageQueuePutPending EventID(EventLevelOp, EvtRtxMessageQueueNo, 0x07U) +#define EvtRtxMessageQueuePutTimeout EventID(EventLevelOp, EvtRtxMessageQueueNo, 0x08U) +#define EvtRtxMessageQueueInsertPending EventID(EventLevelOp, EvtRtxMessageQueueNo, 0x09U) +#define EvtRtxMessageQueueInserted EventID(EventLevelOp, EvtRtxMessageQueueNo, 0x0AU) +#define EvtRtxMessageQueueNotInserted EventID(EventLevelOp, EvtRtxMessageQueueNo, 0x0BU) +#define EvtRtxMessageQueueGet EventID(EventLevelAPI, EvtRtxMessageQueueNo, 0x0CU) +#define EvtRtxMessageQueueGetPending EventID(EventLevelOp, EvtRtxMessageQueueNo, 0x0DU) +#define EvtRtxMessageQueueGetTimeout EventID(EventLevelOp, EvtRtxMessageQueueNo, 0x0EU) +#define EvtRtxMessageQueueRetrieved EventID(EventLevelOp, EvtRtxMessageQueueNo, 0x0FU) +#define EvtRtxMessageQueueNotRetrieved EventID(EventLevelOp, EvtRtxMessageQueueNo, 0x10U) +#define EvtRtxMessageQueueGetCapacity EventID(EventLevelAPI, EvtRtxMessageQueueNo, 0x11U) +#define EvtRtxMessageQueueGetMsgSize EventID(EventLevelAPI, EvtRtxMessageQueueNo, 0x12U) +#define EvtRtxMessageQueueGetCount EventID(EventLevelAPI, EvtRtxMessageQueueNo, 0x13U) +#define EvtRtxMessageQueueGetSpace EventID(EventLevelAPI, EvtRtxMessageQueueNo, 0x14U) +#define EvtRtxMessageQueueReset EventID(EventLevelAPI, EvtRtxMessageQueueNo, 0x15U) +#define EvtRtxMessageQueueResetDone EventID(EventLevelOp, EvtRtxMessageQueueNo, 0x16U) +#define EvtRtxMessageQueueDelete EventID(EventLevelAPI, EvtRtxMessageQueueNo, 0x17U) +#define EvtRtxMessageQueueDestroyed EventID(EventLevelOp, EvtRtxMessageQueueNo, 0x18U) + +#endif // RTE_Compiler_EventRecorder + + +// ==== Memory Events ==== + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMORY != 0) && !defined(EVR_RTX_MEMORY_INIT_DISABLE)) +__WEAK void EvrRtxMemoryInit (void *mem, uint32_t size, uint32_t result) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord4(EvtRtxMemoryInit, (uint32_t)mem, size, result, 0U); +#else + (void)mem; + (void)size; + (void)result; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMORY != 0) && !defined(EVR_RTX_MEMORY_ALLOC_DISABLE)) +__WEAK void EvrRtxMemoryAlloc (void *mem, uint32_t size, uint32_t type, void *block) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord4(EvtRtxMemoryAlloc, (uint32_t)mem, size, type, (uint32_t)block); +#else + (void)mem; + (void)size; + (void)type; + (void)block; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMORY != 0) && !defined(EVR_RTX_MEMORY_FREE_DISABLE)) +__WEAK void EvrRtxMemoryFree (void *mem, void *block, uint32_t result) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord4(EvtRtxMemoryFree, (uint32_t)mem, (uint32_t)block, result, 0U); +#else + (void)mem; + (void)block; + (void)result; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMORY != 0) && !defined(EVR_RTX_MEMORY_BLOCK_INIT_DISABLE)) +__WEAK void EvrRtxMemoryBlockInit (osRtxMpInfo_t *mp_info, uint32_t block_count, uint32_t block_size, void *block_mem) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord4(EvtRtxMemoryBlockInit, (uint32_t)mp_info, block_count, block_size, (uint32_t)block_mem); +#else + (void)mp_info; + (void)block_count; + (void)block_size; + (void)block_mem; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMORY != 0) && !defined(EVR_RTX_MEMORY_BLOCK_ALLOC_DISABLE)) +__WEAK void EvrRtxMemoryBlockAlloc (osRtxMpInfo_t *mp_info, void *block) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMemoryBlockAlloc, (uint32_t)mp_info, (uint32_t)block); +#else + (void)mp_info; + (void)block; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMORY != 0) && !defined(EVR_RTX_MEMORY_BLOCK_FREE_DISABLE)) +__WEAK void EvrRtxMemoryBlockFree (osRtxMpInfo_t *mp_info, void *block, int32_t status) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord4(EvtRtxMemoryBlockFree, (uint32_t)mp_info, (uint32_t)block, (uint32_t)status, 0U); +#else + (void)mp_info; + (void)block; + (void)status; +#endif +} +#endif + + +// ==== Kernel Events ==== + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_ERROR_DISABLE)) +__WEAK void EvrRtxKernelError (int32_t status) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxKernelError, (uint32_t)status, 0U); +#else + (void)status; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_INITIALIZE_DISABLE)) +__WEAK void EvrRtxKernelInitialize (void) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxKernelInitialize, 0U, 0U); +#else +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_INITIALIZE_COMPLETED_DISABLE)) +__WEAK void EvrRtxKernelInitializeCompleted (void) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxKernelInitializeCompleted, 0U, 0U); +#else +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_GET_INFO_DISABLE)) +__WEAK void EvrRtxKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord4(EvtRtxKernelGetInfo, (uint32_t)version, (uint32_t)id_buf, id_size, 0U); +#else + (void)version; + (void)id_buf; + (void)id_size; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_INFO_RETRIEVED_DISABLE)) +__WEAK void EvrRtxKernelInfoRetrieved (osVersion_t *version, char *id_buf) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxKernelInfoRetrieved, (uint32_t)version, (uint32_t)id_buf); + if (id_buf != NULL) { + EventRecordData(EvtRtxKernelInfoRetrieved_Detail, id_buf, strlen(id_buf)); + } +#else + (void)version; + (void)id_buf; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_GET_STATE_DISABLE)) +__WEAK void EvrRtxKernelGetState (osKernelState_t state) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxKernelGetState, (uint32_t)state, 0U); +#else + (void)state; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_START_DISABLE)) +__WEAK void EvrRtxKernelStart (void) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxKernelStart, 0U, 0U); +#else +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_STARTED_DISABLE)) +__WEAK void EvrRtxKernelStarted (void) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxKernelStarted, 0U, 0U); +#else +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_LOCK_DISABLE)) +__WEAK void EvrRtxKernelLock (void) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxKernelLock, 0U, 0U); +#else +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_LOCKED_DISABLE)) +__WEAK void EvrRtxKernelLocked (int32_t lock) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxKernelLocked, (uint32_t)lock, 0U); +#else + (void)lock; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_UNLOCK_DISABLE)) +__WEAK void EvrRtxKernelUnlock (void) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxKernelUnlock, 0U, 0U); +#else +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_UNLOCKED_DISABLE)) +__WEAK void EvrRtxKernelUnlocked (int32_t lock) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxKernelUnlocked, (uint32_t)lock, 0U); +#else + (void)lock; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_RESTORE_LOCK_DISABLE)) +__WEAK void EvrRtxKernelRestoreLock (int32_t lock) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxKernelRestoreLock, (uint32_t)lock, 0U); +#else + (void)lock; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_LOCK_RESTORED_DISABLE)) +__WEAK void EvrRtxKernelLockRestored (int32_t lock) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxKernelLockRestored, (uint32_t)lock, 0U); +#else + (void)lock; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_SUSPEND_DISABLE)) +__WEAK void EvrRtxKernelSuspend (void) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxKernelSuspend, 0U, 0U); +#else +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_SUSPENDED_DISABLE)) +__WEAK void EvrRtxKernelSuspended (uint32_t sleep_ticks) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxKernelSuspended, sleep_ticks, 0U); +#else + (void)sleep_ticks; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_RESUME_DISABLE)) +__WEAK void EvrRtxKernelResume (uint32_t sleep_ticks) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxKernelResume, sleep_ticks, 0U); +#else + (void)sleep_ticks; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_RESUMED_DISABLE)) +__WEAK void EvrRtxKernelResumed (void) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxKernelResumed, 0U, 0U); +#else +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_GET_TICK_COUNT_DISABLE)) +__WEAK void EvrRtxKernelGetTickCount (uint64_t count) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxKernelGetTickCount, (uint32_t)count, (uint32_t)(count>>32)); +#else + (void)count; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_GET_TICK_FREQ_DISABLE)) +__WEAK void EvrRtxKernelGetTickFreq (uint32_t freq) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxKernelGetTickFreq, freq, 0U); +#else + (void)freq; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_GET_SYS_TIMER_COUNT_DISABLE)) +__WEAK void EvrRtxKernelGetSysTimerCount (uint32_t count) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxKernelGetSysTimerCount, count, 0U); +#else + (void)count; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_GET_SYS_TIMER_FREQ_DISABLE)) +__WEAK void EvrRtxKernelGetSysTimerFreq (uint32_t freq) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxKernelGetSysTimerFreq, freq, 0U); +#else + (void)freq; +#endif +} +#endif + + +// ==== Thread Events ==== + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_ERROR_DISABLE)) +__WEAK void EvrRtxThreadError (osThreadId_t thread_id, int32_t status) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadError, (uint32_t)thread_id, (uint32_t)status); +#else + (void)thread_id; + (void)status; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_NEW_DISABLE)) +__WEAK void EvrRtxThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord4(EvtRtxThreadNew, (uint32_t)func, (uint32_t)argument, (uint32_t)attr, 0U); + if (attr != NULL) { + EventRecordData(EvtRtxThreadNew_Detail, attr, sizeof (osThreadAttr_t)); + } +#else + (void)func; + (void)argument; + (void)attr; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_CREATED_DISABLE)) +__WEAK void EvrRtxThreadCreated (osThreadId_t thread_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadCreated, (uint32_t)thread_id, 0U); +#else + (void)thread_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_NAME_DISABLE)) +__WEAK void EvrRtxThreadGetName (osThreadId_t thread_id, const char *name) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadGetName, (uint32_t)thread_id, (uint32_t)name); + if (name != NULL) { + EventRecordData(EvtRtxThreadGetName_Detail, name, strlen(name)); + } +#else + (void)thread_id; + (void)name; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_ID_DISABLE)) +__WEAK void EvrRtxThreadGetId (osThreadId_t thread_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadGetId, (uint32_t)thread_id, 0U); +#else + (void)thread_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_STATE_DISABLE)) +__WEAK void EvrRtxThreadGetState (osThreadId_t thread_id, osThreadState_t state) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadGetState, (uint32_t)thread_id, (uint32_t)state); +#else + (void)thread_id; + (void)state; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_STACK_SIZE_DISABLE)) +__WEAK void EvrRtxThreadGetStackSize (osThreadId_t thread_id, uint32_t stack_size) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadGetStackSize, (uint32_t)thread_id, stack_size); +#else + (void)thread_id; + (void)stack_size; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_STACK_SPACE_DISABLE)) +__WEAK void EvrRtxThreadGetStackSpace (osThreadId_t thread_id, uint32_t stack_space) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadGetStackSpace, (uint32_t)thread_id, stack_space); +#else + (void)thread_id; + (void)stack_space; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_SET_PRIORITY_DISABLE)) +__WEAK void EvrRtxThreadSetPriority (osThreadId_t thread_id, osPriority_t priority) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadSetPriority, (uint32_t)thread_id, (uint32_t)priority); +#else + (void)thread_id; + (void)priority; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_PRIORITY_DISABLE)) +__WEAK void EvrRtxThreadGetPriority (osThreadId_t thread_id, osPriority_t priority) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadGetPriority, (uint32_t)thread_id, (uint32_t)priority); +#else + (void)thread_id; + (void)priority; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_YIELD_DISABLE)) +__WEAK void EvrRtxThreadYield (void) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadYield, 0U, 0U); +#else +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_SUSPEND_DISABLE)) +__WEAK void EvrRtxThreadSuspend (osThreadId_t thread_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadSuspend, (uint32_t)thread_id, 0U); +#else + (void)thread_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_SUSPENDED_DISABLE)) +__WEAK void EvrRtxThreadSuspended (osThreadId_t thread_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadSuspended, (uint32_t)thread_id, 0U); +#else + (void)thread_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_RESUME_DISABLE)) +__WEAK void EvrRtxThreadResume (osThreadId_t thread_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadResume, (uint32_t)thread_id, 0U); +#else + (void)thread_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_RESUMED_DISABLE)) +__WEAK void EvrRtxThreadResumed (osThreadId_t thread_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadResumed, (uint32_t)thread_id, 0U); +#else + (void)thread_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_DETACH_DISABLE)) +__WEAK void EvrRtxThreadDetach (osThreadId_t thread_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadDetach, (uint32_t)thread_id, 0U); +#else + (void)thread_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_DETACHED_DISABLE)) +__WEAK void EvrRtxThreadDetached (osThreadId_t thread_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadDetached, (uint32_t)thread_id, 0U); +#else + (void)thread_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_JOIN_DISABLE)) +__WEAK void EvrRtxThreadJoin (osThreadId_t thread_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadJoin, (uint32_t)thread_id, 0U); +#else + (void)thread_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_JOIN_PENDING_DISABLE)) +__WEAK void EvrRtxThreadJoinPending (osThreadId_t thread_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadJoinPending, (uint32_t)thread_id, 0U); +#else + (void)thread_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_JOINED_DISABLE)) +__WEAK void EvrRtxThreadJoined (osThreadId_t thread_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadJoined, (uint32_t)thread_id, 0U); +#else + (void)thread_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_BLOCKED_DISABLE)) +__WEAK void EvrRtxThreadBlocked (osThreadId_t thread_id, uint32_t timeout) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadBlocked, (uint32_t)thread_id, timeout); +#else + (void)thread_id; + (void)timeout; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_UNBLOCKED_DISABLE)) +__WEAK void EvrRtxThreadUnblocked (osThreadId_t thread_id, uint32_t ret_val) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadUnblocked, (uint32_t)thread_id, ret_val); +#else + (void)thread_id; + (void)ret_val; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_SWITCH_DISABLE)) +__WEAK void EvrRtxThreadSwitch (osThreadId_t thread_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadSwitch, (uint32_t)thread_id, 0U); +#else + (void)thread_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_EXIT_DISABLE)) +__WEAK void EvrRtxThreadExit (void) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadExit, 0U, 0U); +#else +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_TERMINATE_DISABLE)) +__WEAK void EvrRtxThreadTerminate (osThreadId_t thread_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadTerminate, (uint32_t)thread_id, 0U); +#else + (void)thread_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_DESTROYED_DISABLE)) +__WEAK void EvrRtxThreadDestroyed (osThreadId_t thread_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadDestroyed, (uint32_t)thread_id, 0U); +#else + (void)thread_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_COUNT_DISABLE)) +__WEAK void EvrRtxThreadGetCount (uint32_t count) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadGetCount, count, 0U); +#else + (void)count; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_ENUMERATE_DISABLE)) +__WEAK void EvrRtxThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items, uint32_t count) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord4(EvtRtxThreadEnumerate, (uint32_t)thread_array, array_items, count, 0U); +#else + (void)thread_array; + (void)array_items; + (void)count; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_SET_DISABLE)) +__WEAK void EvrRtxThreadFlagsSet (osThreadId_t thread_id, uint32_t flags) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadFlagsSet, (uint32_t)thread_id, flags); +#else + (void)thread_id; + (void)flags; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_SET_DONE_DISABLE)) +__WEAK void EvrRtxThreadFlagsSetDone (osThreadId_t thread_id, uint32_t thread_flags) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadFlagsSetDone, (uint32_t)thread_id, thread_flags); +#else + (void)thread_id; + (void)thread_flags; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_CLEAR_DISABLE)) +__WEAK void EvrRtxThreadFlagsClear (uint32_t flags) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadFlagsClear, flags, 0U); +#else + (void)flags; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_CLEAR_DONE_DISABLE)) +__WEAK void EvrRtxThreadFlagsClearDone (uint32_t thread_flags) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadFlagsClearDone, thread_flags, 0U); +#else + (void)thread_flags; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_GET_DISABLE)) +__WEAK void EvrRtxThreadFlagsGet (uint32_t thread_flags) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadFlagsGet, thread_flags, 0U); +#else + (void)thread_flags; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_WAIT_DISABLE)) +__WEAK void EvrRtxThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord4(EvtRtxThreadFlagsWait, flags, options, timeout, 0U); +#else + (void)flags; + (void)options; + (void)timeout; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_WAIT_PENDING_DISABLE)) +__WEAK void EvrRtxThreadFlagsWaitPending (uint32_t flags, uint32_t options, uint32_t timeout) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord4(EvtRtxThreadFlagsWaitPending, flags, options, timeout, 0U); +#else + (void)flags; + (void)options; + (void)timeout; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_WAIT_TIMEOUT_DISABLE)) +__WEAK void EvrRtxThreadFlagsWaitTimeout (void) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadFlagsWaitTimeout, 0U, 0U); +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_WAIT_COMPLETED_DISABLE)) +__WEAK void EvrRtxThreadFlagsWaitCompleted (uint32_t flags, uint32_t options, uint32_t thread_flags) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord4(EvtRtxThreadFlagsWaitCompleted, flags, options, thread_flags, 0U); +#else + (void)flags; + (void)options; + (void)thread_flags; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_WAIT_NOT_COMPLETED_DISABLE)) +__WEAK void EvrRtxThreadFlagsWaitNotCompleted (uint32_t flags, uint32_t options) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadFlagsWaitNotCompleted, flags, options); +#else + (void)flags; + (void)options; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_DELAY_DISABLE)) +__WEAK void EvrRtxThreadDelay (uint32_t ticks) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadDelay, ticks, 0U); +#else + (void)ticks; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_DELAY_UNTIL_DISABLE)) +__WEAK void EvrRtxThreadDelayUntil (uint64_t ticks) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadDelayUntil, (uint32_t)ticks, (uint32_t)(ticks >> 32)); +#else + (void)ticks; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_DELAY_COMPLETED_DISABLE)) +__WEAK void EvrRtxThreadDelayCompleted (void) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxThreadDelayCompleted, 0U, 0U); +#endif +} +#endif + + +// ==== Timer Events ==== + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_ERROR_DISABLE)) +__WEAK void EvrRtxTimerError (osTimerId_t timer_id, int32_t status) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxTimerError, (uint32_t)timer_id, (uint32_t)status); +#else + (void)timer_id; + (void)status; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_CALLBACK_DISABLE)) +__WEAK void EvrRtxTimerCallback (osTimerFunc_t func, void *argument) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxTimerCallback, (uint32_t)func, (uint32_t)argument); +#else + (void)func; + (void)argument; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_NEW_DISABLE)) +__WEAK void EvrRtxTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord4(EvtRtxTimerNew, (uint32_t)func, (uint32_t)type, (uint32_t)argument, (uint32_t)attr); + if (attr != NULL) { + EventRecordData(EvtRtxTimerNew_Detail, attr, sizeof (osTimerAttr_t)); + } +#else + (void)func; + (void)type; + (void)argument; + (void)attr; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_CREATED_DISABLE)) +__WEAK void EvrRtxTimerCreated (osTimerId_t timer_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxTimerCreated, (uint32_t)timer_id, 0U); +#else + (void)timer_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_GET_NAME_DISABLE)) +__WEAK void EvrRtxTimerGetName (osTimerId_t timer_id, const char *name) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxTimerGetName, (uint32_t)timer_id, (uint32_t)name); + if (name != NULL) { + EventRecordData(EvtRtxTimerGetName_Detail, name, strlen(name)); + } +#else + (void)timer_id; + (void)name; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_START_DISABLE)) +__WEAK void EvrRtxTimerStart (osTimerId_t timer_id, uint32_t ticks) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxTimerStart, (uint32_t)timer_id, ticks); +#else + (void)timer_id; + (void)ticks; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_STARTED_DISABLE)) +__WEAK void EvrRtxTimerStarted (osTimerId_t timer_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxTimerStarted, (uint32_t)timer_id, 0U); +#else + (void)timer_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_STOP_DISABLE)) +__WEAK void EvrRtxTimerStop (osTimerId_t timer_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxTimerStop, (uint32_t)timer_id, 0U); +#else + (void)timer_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_STOPPED_DISABLE)) +__WEAK void EvrRtxTimerStopped (osTimerId_t timer_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxTimerStopped, (uint32_t)timer_id, 0U); +#else + (void)timer_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_IS_RUNNING_DISABLE)) +__WEAK void EvrRtxTimerIsRunning (osTimerId_t timer_id, uint32_t running) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxTimerIsRunning, (uint32_t)timer_id, running); +#else + (void)timer_id; + (void)running; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_DELETE_DISABLE)) +__WEAK void EvrRtxTimerDelete (osTimerId_t timer_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxTimerDelete, (uint32_t)timer_id, 0U); +#else + (void)timer_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_DESTROYED_DISABLE)) +__WEAK void EvrRtxTimerDestroyed (osTimerId_t timer_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxTimerDestroyed, (uint32_t)timer_id, 0U); +#else + (void)timer_id; +#endif +} +#endif + + +// ==== Event Flags Events ==== + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_ERROR_DISABLE)) +__WEAK void EvrRtxEventFlagsError (osEventFlagsId_t ef_id, int32_t status) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxEventFlagsError, (uint32_t)ef_id, (uint32_t)status); +#else + (void)ef_id; + (void)status; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_NEW_DISABLE)) +__WEAK void EvrRtxEventFlagsNew (const osEventFlagsAttr_t *attr) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxEventFlagsNew, (uint32_t)attr, 0U); + if (attr != NULL) { + EventRecordData(EvtRtxEventFlagsNew_Detail, attr, sizeof (osEventFlagsAttr_t)); + } +#else + (void)attr; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_CREATED_DISABLE)) +__WEAK void EvrRtxEventFlagsCreated (osEventFlagsId_t ef_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxEventFlagsCreated, (uint32_t)ef_id, 0U); +#else + (void)ef_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_GET_NAME_DISABLE)) +__WEAK void EvrRtxEventFlagsGetName (osEventFlagsId_t ef_id, const char *name) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxEventFlagsGetName, (uint32_t)ef_id, (uint32_t)name); + if (name != NULL) { + EventRecordData(EvtRtxEventFlagsGetName_Detail, name, strlen(name)); + } +#else + (void)ef_id; + (void)name; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_SET_DISABLE)) +__WEAK void EvrRtxEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxEventFlagsSet, (uint32_t)ef_id, flags); +#else + (void)ef_id; + (void)flags; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_SET_DONE_DISABLE)) +__WEAK void EvrRtxEventFlagsSetDone (osEventFlagsId_t ef_id, uint32_t event_flags) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxEventFlagsSetDone, (uint32_t)ef_id, event_flags); +#else + (void)ef_id; + (void)event_flags; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_CLEAR_DISABLE)) +__WEAK void EvrRtxEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxEventFlagsClear, (uint32_t)ef_id, flags); +#else + (void)ef_id; + (void)flags; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_CLEAR_DONE_DISABLE)) +__WEAK void EvrRtxEventFlagsClearDone (osEventFlagsId_t ef_id, uint32_t event_flags) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxEventFlagsClearDone, (uint32_t)ef_id, event_flags); +#else + (void)ef_id; + (void)event_flags; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_GET_DISABLE)) +__WEAK void EvrRtxEventFlagsGet (osEventFlagsId_t ef_id, uint32_t event_flags) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxEventFlagsGet, (uint32_t)ef_id, event_flags); +#else + (void)ef_id; + (void)event_flags; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_WAIT_DISABLE)) +__WEAK void EvrRtxEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord4(EvtRtxEventFlagsWait, (uint32_t)ef_id, flags, options, timeout); +#else + (void)ef_id; + (void)flags; + (void)options; + (void)timeout; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_WAIT_PENDING_DISABLE)) +__WEAK void EvrRtxEventFlagsWaitPending (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord4(EvtRtxEventFlagsWaitPending, (uint32_t)ef_id, flags, options, timeout); +#else + (void)ef_id; + (void)flags; + (void)options; + (void)timeout; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_WAIT_TIMEOUT_DISABLE)) +__WEAK void EvrRtxEventFlagsWaitTimeout (osEventFlagsId_t ef_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxEventFlagsWaitTimeout, (uint32_t)ef_id, 0U); +#else + (void)ef_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_WAIT_COMPLETED_DISABLE)) +__WEAK void EvrRtxEventFlagsWaitCompleted (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t event_flags) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord4(EvtRtxEventFlagsWaitCompleted, (uint32_t)ef_id, flags, options, event_flags); +#else + (void)ef_id; + (void)flags; + (void)options; + (void)event_flags; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_WAIT_NOT_COMPLETED_DISABLE)) +__WEAK void EvrRtxEventFlagsWaitNotCompleted (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord4(EvtRtxEventFlagsWaitNotCompleted, (uint32_t)ef_id, flags, options, 0U); +#else + (void)ef_id; + (void)flags; + (void)options; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_DELETE_DISABLE)) +__WEAK void EvrRtxEventFlagsDelete (osEventFlagsId_t ef_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxEventFlagsDelete, (uint32_t)ef_id, 0U); +#else + (void)ef_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_DESTROYED_DISABLE)) +__WEAK void EvrRtxEventFlagsDestroyed (osEventFlagsId_t ef_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxEventFlagsDestroyed, (uint32_t)ef_id, 0U); +#else + (void)ef_id; +#endif +} +#endif + + +// ==== Mutex Events ==== + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_ERROR_DISABLE)) +__WEAK void EvrRtxMutexError (osMutexId_t mutex_id, int32_t status) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMutexError, (uint32_t)mutex_id, (uint32_t)status); +#else + (void)mutex_id; + (void)status; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_NEW_DISABLE)) +__WEAK void EvrRtxMutexNew (const osMutexAttr_t *attr) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMutexNew, (uint32_t)attr, 0U); + if (attr != NULL) { + EventRecordData(EvtRtxMutexNew_Detail, attr, sizeof (osMutexAttr_t)); + } +#else + (void)attr; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_CREATED_DISABLE)) +__WEAK void EvrRtxMutexCreated (osMutexId_t mutex_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMutexCreated, (uint32_t)mutex_id, 0U); +#else + (void)mutex_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_GET_NAME_DISABLE)) +__WEAK void EvrRtxMutexGetName (osMutexId_t mutex_id, const char *name) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMutexGetName, (uint32_t)mutex_id, (uint32_t)name); + if (name != NULL) { + EventRecordData(EvtRtxMutexGetName_Detail, name, strlen(name)); + } +#else + (void)mutex_id; + (void)name; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_ACQUIRE_DISABLE)) +__WEAK void EvrRtxMutexAcquire (osMutexId_t mutex_id, uint32_t timeout) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMutexAcquire, (uint32_t)mutex_id, timeout); +#else + (void)mutex_id; + (void)timeout; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_ACQUIRE_PENDING_DISABLE)) +__WEAK void EvrRtxMutexAcquirePending (osMutexId_t mutex_id, uint32_t timeout) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMutexAcquirePending, (uint32_t)mutex_id, timeout); +#else + (void)mutex_id; + (void)timeout; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_ACQUIRE_TIMEOUT_DISABLE)) +__WEAK void EvrRtxMutexAcquireTimeout (osMutexId_t mutex_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMutexAcquireTimeout, (uint32_t)mutex_id, 0U); +#else + (void)mutex_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_ACQUIRED_DISABLE)) +__WEAK void EvrRtxMutexAcquired (osMutexId_t mutex_id, uint32_t lock) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMutexAcquired, (uint32_t)mutex_id, lock); +#else + (void)mutex_id; + (void)lock; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_NOT_ACQUIRED_DISABLE)) +__WEAK void EvrRtxMutexNotAcquired (osMutexId_t mutex_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMutexNotAcquired, (uint32_t)mutex_id, 0U); +#else + (void)mutex_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_RELEASE_DISABLE)) +__WEAK void EvrRtxMutexRelease (osMutexId_t mutex_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMutexRelease, (uint32_t)mutex_id, 0U); +#else + (void)mutex_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_RELEASED_DISABLE)) +__WEAK void EvrRtxMutexReleased (osMutexId_t mutex_id, uint32_t lock) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMutexReleased, (uint32_t)mutex_id, lock); +#else + (void)mutex_id; + (void)lock; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_GET_OWNER_DISABLE)) +__WEAK void EvrRtxMutexGetOwner (osMutexId_t mutex_id, osThreadId_t thread_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMutexGetOwner, (uint32_t)mutex_id, (uint32_t)thread_id); +#else + (void)mutex_id; + (void)thread_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_DELETE_DISABLE)) +__WEAK void EvrRtxMutexDelete (osMutexId_t mutex_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMutexDelete, (uint32_t)mutex_id, 0U); +#else + (void)mutex_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_DESTROYED_DISABLE)) +__WEAK void EvrRtxMutexDestroyed (osMutexId_t mutex_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMutexDestroyed, (uint32_t)mutex_id, 0U); +#else + (void)mutex_id; +#endif +} +#endif + + +// ==== Semaphore Events ==== + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_ERROR_DISABLE)) +__WEAK void EvrRtxSemaphoreError (osSemaphoreId_t semaphore_id, int32_t status) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxSemaphoreError, (uint32_t)semaphore_id, (uint32_t)status); +#else + (void)semaphore_id; + (void)status; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_NEW_DISABLE)) +__WEAK void EvrRtxSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord4(EvtRtxSemaphoreNew, max_count, initial_count, (uint32_t)attr, 0U); + if (attr != NULL) { + EventRecordData(EvtRtxSemaphoreNew_Detail, attr, sizeof (osSemaphoreAttr_t)); + } +#else + (void)max_count; + (void)initial_count; + (void)attr; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_CREATED_DISABLE)) +__WEAK void EvrRtxSemaphoreCreated (osSemaphoreId_t semaphore_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxSemaphoreCreated, (uint32_t)semaphore_id, 0U); +#else + (void)semaphore_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_GET_NAME_DISABLE)) +__WEAK void EvrRtxSemaphoreGetName (osSemaphoreId_t semaphore_id, const char *name) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxSemaphoreGetName, (uint32_t)semaphore_id, (uint32_t)name); + if (name != NULL) { + EventRecordData(EvtRtxSemaphoreGetName_Detail, name, strlen(name)); + } +#else +#endif + (void)semaphore_id; + (void)name; +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_ACQUIRE_DISABLE)) +__WEAK void EvrRtxSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxSemaphoreAcquire, (uint32_t)semaphore_id, timeout); +#else + (void)semaphore_id; + (void)timeout; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_ACQUIRE_PENDING_DISABLE)) +__WEAK void EvrRtxSemaphoreAcquirePending (osSemaphoreId_t semaphore_id, uint32_t timeout) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxSemaphoreAcquirePending, (uint32_t)semaphore_id, (uint32_t)timeout); +#else + (void)semaphore_id; + (void)timeout; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_ACQUIRE_TIMEOUT_DISABLE)) +__WEAK void EvrRtxSemaphoreAcquireTimeout (osSemaphoreId_t semaphore_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxSemaphoreAcquireTimeout, (uint32_t)semaphore_id, 0U); +#else + (void)semaphore_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_ACQUIRED_DISABLE)) +__WEAK void EvrRtxSemaphoreAcquired (osSemaphoreId_t semaphore_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxSemaphoreAcquired, (uint32_t)semaphore_id, 0U); +#else + (void)semaphore_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_NOT_ACQUIRED_DISABLE)) +__WEAK void EvrRtxSemaphoreNotAcquired (osSemaphoreId_t semaphore_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxSemaphoreNotAcquired, (uint32_t)semaphore_id, 0U); +#else + (void)semaphore_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_RELEASE_DISABLE)) +__WEAK void EvrRtxSemaphoreRelease (osSemaphoreId_t semaphore_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxSemaphoreRelease, (uint32_t)semaphore_id, 0U); +#else + (void)semaphore_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_RELEASED_DISABLE)) +__WEAK void EvrRtxSemaphoreReleased (osSemaphoreId_t semaphore_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxSemaphoreReleased, (uint32_t)semaphore_id, 0U); +#else + (void)semaphore_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_GET_COUNT_DISABLE)) +__WEAK void EvrRtxSemaphoreGetCount (osSemaphoreId_t semaphore_id, uint32_t count) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxSemaphoreGetCount, (uint32_t)semaphore_id, count); +#else + (void)semaphore_id; + (void)count; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_DELETE_DISABLE)) +__WEAK void EvrRtxSemaphoreDelete (osSemaphoreId_t semaphore_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxSemaphoreDelete, (uint32_t)semaphore_id, 0U); +#else + (void)semaphore_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_DESTROYED_DISABLE)) +__WEAK void EvrRtxSemaphoreDestroyed (osSemaphoreId_t semaphore_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxSemaphoreDestroyed, (uint32_t)semaphore_id, 0U); +#else + (void)semaphore_id; +#endif +} +#endif + + +// ==== Memory Pool Events ==== + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_ERROR_DISABLE)) +__WEAK void EvrRtxMemoryPoolError (osMemoryPoolId_t mp_id, int32_t status) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMemoryPoolError, (uint32_t)mp_id, (uint32_t)status); +#else + (void)mp_id; + (void)status; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_NEW_DISABLE)) +__WEAK void EvrRtxMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord4(EvtRtxMemoryPoolNew, block_count, block_size, (uint32_t)attr, 0U); + if (attr != NULL) { + EventRecordData(EvtRtxMemoryPoolNew_Detail, attr, sizeof (osMemoryPoolAttr_t)); + } +#else + (void)block_count; + (void)block_size; + (void)attr; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_CREATED_DISABLE)) +__WEAK void EvrRtxMemoryPoolCreated (osMemoryPoolId_t mp_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMemoryPoolCreated, (uint32_t)mp_id, 0U); +#else + (void)mp_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_GET_NAME_DISABLE)) +__WEAK void EvrRtxMemoryPoolGetName (osMemoryPoolId_t mp_id, const char *name) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMemoryPoolGetName, (uint32_t)mp_id, (uint32_t)name); + if (name != NULL) { + EventRecordData(EvtRtxMemoryPoolGetName_Detail, name, strlen(name)); + } +#else + (void)mp_id; + (void)name; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_ALLOC_DISABLE)) +__WEAK void EvrRtxMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMemoryPoolAlloc, (uint32_t)mp_id, timeout); +#else + (void)mp_id; + (void)timeout; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_ALLOC_PENDING_DISABLE)) +__WEAK void EvrRtxMemoryPoolAllocPending (osMemoryPoolId_t mp_id, uint32_t timeout) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMemoryPoolAllocPending, (uint32_t)mp_id, timeout); +#else + (void)mp_id; + (void)timeout; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_ALLOC_TIMEOUT_DISABLE)) +__WEAK void EvrRtxMemoryPoolAllocTimeout (osMemoryPoolId_t mp_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMemoryPoolAllocTimeout, (uint32_t)mp_id, 0U); +#else + (void)mp_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_ALLOCATED_DISABLE)) +__WEAK void EvrRtxMemoryPoolAllocated (osMemoryPoolId_t mp_id, void *block) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMemoryPoolAllocated, (uint32_t)mp_id, (uint32_t)block); +#else + (void)mp_id; + (void)block; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_ALLOC_FAILED_DISABLE)) +__WEAK void EvrRtxMemoryPoolAllocFailed (osMemoryPoolId_t mp_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMemoryPoolAllocFailed, (uint32_t)mp_id, 0U); +#else + (void)mp_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_FREE_DISABLE)) +__WEAK void EvrRtxMemoryPoolFree (osMemoryPoolId_t mp_id, void *block) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMemoryPoolFree, (uint32_t)mp_id, (uint32_t)block); +#else + (void)mp_id; + (void)block; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_DEALLOCATED_DISABLE)) +__WEAK void EvrRtxMemoryPoolDeallocated (osMemoryPoolId_t mp_id, void *block) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMemoryPoolDeallocated, (uint32_t)mp_id, (uint32_t)block); +#else + (void)mp_id; + (void)block; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_FREE_FAILED_DISABLE)) +__WEAK void EvrRtxMemoryPoolFreeFailed (osMemoryPoolId_t mp_id, void *block) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMemoryPoolFreeFailed, (uint32_t)mp_id, (uint32_t)block); +#else + (void)mp_id; + (void)block; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_GET_CAPACITY_DISABLE)) +__WEAK void EvrRtxMemoryPoolGetCapacity (osMemoryPoolId_t mp_id, uint32_t capacity) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMemoryPoolGetCapacity, (uint32_t)mp_id, capacity); +#else + (void)mp_id; + (void)capacity; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_GET_BLOCK_SZIE_DISABLE)) +__WEAK void EvrRtxMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id, uint32_t block_size) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMemoryPoolGetBlockSize, (uint32_t)mp_id, block_size); +#else + (void)mp_id; + (void)block_size; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_GET_COUNT_DISABLE)) +__WEAK void EvrRtxMemoryPoolGetCount (osMemoryPoolId_t mp_id, uint32_t count) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMemoryPoolGetCount, (uint32_t)mp_id, count); +#else + (void)mp_id; + (void)count; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_GET_SPACE_DISABLE)) +__WEAK void EvrRtxMemoryPoolGetSpace (osMemoryPoolId_t mp_id, uint32_t space) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMemoryPoolGetSpace, (uint32_t)mp_id, space); +#else + (void)mp_id; + (void)space; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_DELETE_DISABLE)) +__WEAK void EvrRtxMemoryPoolDelete (osMemoryPoolId_t mp_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMemoryPoolDelete, (uint32_t)mp_id, 0U); +#else + (void)mp_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_DESTROYED_DISABLE)) +__WEAK void EvrRtxMemoryPoolDestroyed (osMemoryPoolId_t mp_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMemoryPoolDestroyed, (uint32_t)mp_id, 0U); +#else + (void)mp_id; +#endif +} +#endif + + +// ==== Message Queue Events ==== + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_ERROR_DISABLE)) +__WEAK void EvrRtxMessageQueueError (osMessageQueueId_t mq_id, int32_t status) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2 (EvtRtxMessageQueueError, (uint32_t)mq_id, (uint32_t)status); +#else + (void)mq_id; + (void)status; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_NEW_DISABLE)) +__WEAK void EvrRtxMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord4(EvtRtxMessageQueueNew, msg_count, msg_size, (uint32_t)attr, 0U); + if (attr != NULL) { + EventRecordData(EvtRtxMessageQueueNew_Detail, attr, sizeof (osMemoryPoolAttr_t)); + } +#else + (void)msg_count; + (void)msg_size; + (void)attr; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_CREATED_DISABLE)) +__WEAK void EvrRtxMessageQueueCreated (osMessageQueueId_t mq_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMessageQueueCreated, (uint32_t)mq_id, 0U); +#else + (void)mq_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_NAME_DISABLE)) +__WEAK void EvrRtxMessageQueueGetName (osMessageQueueId_t mq_id, const char *name) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMessageQueueGetName, (uint32_t)mq_id, (uint32_t)name); + if (name != NULL) { + EventRecordData(EvtRtxMessageQueueGetName_Detail, name, strlen(name)); + } +#else + (void)mq_id; + (void)name; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_PUT_DISABLE)) +__WEAK void EvrRtxMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord4(EvtRtxMessageQueuePut, (uint32_t)mq_id, (uint32_t)msg_ptr, (uint32_t)msg_prio, timeout); +#else + (void)mq_id; + (void)msg_ptr; + (void)msg_prio; + (void)timeout; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_PUT_PENDING_DISABLE)) +__WEAK void EvrRtxMessageQueuePutPending (osMessageQueueId_t mq_id, const void *msg_ptr, uint32_t timeout) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord4(EvtRtxMessageQueuePutPending, (uint32_t)mq_id, (uint32_t)msg_ptr, timeout, 0U); +#else + (void)mq_id; + (void)msg_ptr; + (void)timeout; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_PUT_TIMEOUT_DISABLE)) +__WEAK void EvrRtxMessageQueuePutTimeout (osMessageQueueId_t mq_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMessageQueuePutTimeout, (uint32_t)mq_id, 0U); +#else + (void)mq_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_INSERT_PENDING_DISABLE)) +__WEAK void EvrRtxMessageQueueInsertPending (osMessageQueueId_t mq_id, const void *msg_ptr) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMessageQueueInsertPending, (uint32_t)mq_id, (uint32_t)msg_ptr); +#else + (void)mq_id; + (void)msg_ptr; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_INSERTED_DISABLE)) +__WEAK void EvrRtxMessageQueueInserted (osMessageQueueId_t mq_id, const void *msg_ptr) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMessageQueueInserted, (uint32_t)mq_id, (uint32_t)msg_ptr); +#else + (void)mq_id; + (void)msg_ptr; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_NOT_INSERTED_DISABLE)) +__WEAK void EvrRtxMessageQueueNotInserted (osMessageQueueId_t mq_id, const void *msg_ptr) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMessageQueueNotInserted, (uint32_t)mq_id, (uint32_t)msg_ptr); +#else + (void)mq_id; + (void)msg_ptr; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_DISABLE)) +__WEAK void EvrRtxMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord4(EvtRtxMessageQueueGet, (uint32_t)mq_id, (uint32_t)msg_ptr, (uint32_t)msg_prio, timeout); +#else + (void)mq_id; + (void)msg_ptr; + (void)msg_prio; + (void)timeout; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_PENDING_DISABLE)) +__WEAK void EvrRtxMessageQueueGetPending (osMessageQueueId_t mq_id, void *msg_ptr, uint32_t timeout) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord4(EvtRtxMessageQueueGetPending, (uint32_t)mq_id, (uint32_t)msg_ptr, timeout, 0U); +#else + (void)mq_id; + (void)msg_ptr; + (void)timeout; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_TIMEOUT_DISABLE)) +__WEAK void EvrRtxMessageQueueGetTimeout (osMessageQueueId_t mq_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMessageQueueGetTimeout, (uint32_t)mq_id, 0U); +#else + (void)mq_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_RETRIEVED_DISABLE)) +__WEAK void EvrRtxMessageQueueRetrieved (osMessageQueueId_t mq_id, void *msg_ptr) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMessageQueueRetrieved, (uint32_t)mq_id, (uint32_t)msg_ptr); +#else + (void)mq_id; + (void)msg_ptr; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_NOT_RETRIEVED_DISABLE)) +__WEAK void EvrRtxMessageQueueNotRetrieved (osMessageQueueId_t mq_id, void *msg_ptr) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMessageQueueNotRetrieved, (uint32_t)mq_id, (uint32_t)msg_ptr); +#else + (void)mq_id; + (void)msg_ptr; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_CAPACITY_DISABLE)) +__WEAK void EvrRtxMessageQueueGetCapacity (osMessageQueueId_t mq_id, uint32_t capacity) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMessageQueueGetCapacity, (uint32_t)mq_id, capacity); +#else + (void)mq_id; + (void)capacity; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_MSG_SIZE_DISABLE)) +__WEAK void EvrRtxMessageQueueGetMsgSize (osMessageQueueId_t mq_id, uint32_t msg_size) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMessageQueueGetMsgSize, (uint32_t)mq_id, msg_size); +#else + (void)mq_id; + (void)msg_size; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_COUNT_DISABLE)) +__WEAK void EvrRtxMessageQueueGetCount (osMessageQueueId_t mq_id, uint32_t count) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMessageQueueGetCount, (uint32_t)mq_id, count); +#else + (void)mq_id; + (void)count; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_SPACE_DISABLE)) +__WEAK void EvrRtxMessageQueueGetSpace (osMessageQueueId_t mq_id, uint32_t space) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMessageQueueGetSpace, (uint32_t)mq_id, space); +#else + (void)mq_id; + (void)space; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_RESET_DISABLE)) +__WEAK void EvrRtxMessageQueueReset (osMessageQueueId_t mq_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMessageQueueReset, (uint32_t)mq_id, 0U); +#else + (void)mq_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_RESET_DONE_DISABLE)) +__WEAK void EvrRtxMessageQueueResetDone (osMessageQueueId_t mq_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMessageQueueResetDone, (uint32_t)mq_id, 0U); +#else + (void)mq_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_DELETE_DISABLE)) +__WEAK void EvrRtxMessageQueueDelete (osMessageQueueId_t mq_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMessageQueueDelete, (uint32_t)mq_id, 0U); +#else + (void)mq_id; +#endif +} +#endif + +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_DESTROYED_DISABLE)) +__WEAK void EvrRtxMessageQueueDestroyed (osMessageQueueId_t mq_id) { +#if defined(RTE_Compiler_EventRecorder) + EventRecord2(EvtRtxMessageQueueDestroyed, (uint32_t)mq_id, 0U); +#else + (void)mq_id; +#endif +} +#endif diff --git a/rtos/TARGET_CORTEX/rtx5/rtx_evr.h b/rtos/TARGET_CORTEX/rtx5/rtx_evr.h new file mode 100644 index 0000000..5bc4baa --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/rtx_evr.h @@ -0,0 +1,1847 @@ +/** \addtogroup rtos */ +/** @{*/ +/* + * Copyright (c) 2013-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * + * Project: CMSIS-RTOS RTX + * Title: RTX Event Recorder definitions + * + * ----------------------------------------------------------------------------- + */ + +#ifndef RTX_EVR_H_ +#define RTX_EVR_H_ + +#include "cmsis_os2.h" // CMSIS RTOS API +#include "rtx_os.h" // RTX OS definitions +#include "RTX_Config.h" + + +/// Extended Status codes +#define osRtxErrorKernelNotReady (-7) +#define osRtxErrorKernelNotRunning (-8) +#define osRtxErrorInvalidControlBlock (-9) +#define osRtxErrorInvalidDataMemory (-10) +#define osRtxErrorInvalidThreadStack (-11) +#define osRtxErrorInvalidPriority (-12) +#define osRtxErrorThreadNotJoinable (-13) +#define osRtxErrorMutexNotOwned (-14) +#define osRtxErrorMutexNotLocked (-15) +#define osRtxErrorMutexLockLimit (-16) +#define osRtxErrorSemaphoreCountLimit (-17) +#define osRtxErrorTZ_InitContext_S (-18) +#define osRtxErrorTZ_AllocContext_S (-19) +#define osRtxErrorTZ_FreeContext_S (-20) +#define osRtxErrorTZ_LoadContext_S (-21) +#define osRtxErrorTZ_SaveContext_S (-22) + + +// ==== Memory Events ==== + +/** + \brief Event on memory initialization (Op) + \param[in] mem pointer to memory pool. + \param[in] size size of a memory pool in bytes. + \param[in] result execution status: 1 - success, 0 - failure. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMORY != 0) && !defined(EVR_RTX_MEMORY_INIT_DISABLE)) +extern void EvrRtxMemoryInit (void *mem, uint32_t size, uint32_t result); +#else +#define EvrRtxMemoryInit(mem, size, result) +#endif + +/** + \brief Event on memory allocate (Op) + \param[in] mem pointer to memory pool. + \param[in] size size of a memory block in bytes. + \param[in] type memory block type: 0 - generic, 1 - control block + \param[in] block pointer to allocated memory block or NULL in case of no memory is available. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMORY != 0) && !defined(EVR_RTX_MEMORY_ALLOC_DISABLE)) +extern void EvrRtxMemoryAlloc (void *mem, uint32_t size, uint32_t type, void *block); +#else +#define EvrRtxMemoryAlloc(mem, size, type, block) +#endif + +/** + \brief Event on memory free (Op) + \param[in] mem pointer to memory pool. + \param[in] block memory block to be returned to the memory pool. + \param[in] result execution status: 1 - success, 0 - failure. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMORY != 0) && !defined(EVR_RTX_MEMORY_FREE_DISABLE)) +extern void EvrRtxMemoryFree (void *mem, void *block, uint32_t result); +#else +#define EvrRtxMemoryFree(mem, block, result) +#endif + +/** + \brief Event on memory block initialization (Op) + \param[in] mp_info memory pool info. + \param[in] block_count maximum number of memory blocks in memory pool. + \param[in] block_size size of a memory block in bytes. + \param[in] block_mem pointer to memory for block storage. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMORY != 0) && !defined(EVR_RTX_MEMORY_BLOCK_INIT_DISABLE)) +extern void EvrRtxMemoryBlockInit (osRtxMpInfo_t *mp_info, uint32_t block_count, uint32_t block_size, void *block_mem); +#else +#define EvrRtxMemoryBlockInit(mp_info, block_count, block_size, block_mem) +#endif + +/** + \brief Event on memory block alloc (Op) + \param[in] mp_info memory pool info. + \param[in] block address of the allocated memory block or NULL in case of no memory is available. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMORY != 0) && !defined(EVR_RTX_MEMORY_BLOCK_ALLOC_DISABLE)) +extern void EvrRtxMemoryBlockAlloc (osRtxMpInfo_t *mp_info, void *block); +#else +#define EvrRtxMemoryBlockAlloc(mp_info, block) +#endif + +/** + \brief Event on memory block free (Op) + \param[in] mp_info memory pool info. + \param[in] block address of the allocated memory block to be returned to the memory pool. + \param[in] status extended execution status. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMORY != 0) && !defined(EVR_RTX_MEMORY_BLOCK_FREE_DISABLE)) +extern void EvrRtxMemoryBlockFree (osRtxMpInfo_t *mp_info, void *block, int32_t status); +#else +#define EvrRtxMemoryBlockFree(mp_info, block, status) +#endif + + +// ==== Kernel Events ==== + +/** + \brief Event on RTOS kernel error (Error) + \param[in] status extended execution status. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_ERROR_DISABLE)) +extern void EvrRtxKernelError (int32_t status); +#else +#define EvrRtxKernelError(status) +#endif + +/** + \brief Event on RTOS kernel initialize (API) +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_INITIALIZE_DISABLE)) +extern void EvrRtxKernelInitialize (void); +#else +#define EvrRtxKernelInitialize() +#endif + +/** + \brief Event on successful RTOS kernel initialize (Op) +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_INITIALIZE_COMPLETED_DISABLE)) +extern void EvrRtxKernelInitializeCompleted (void); +#else +#define EvrRtxKernelInitializeCompleted() +#endif + +/** + \brief Event on RTOS kernel information retrieve (API) + \param[in] version pointer to buffer for retrieving version information. + \param[in] id_buf pointer to buffer for retrieving kernel identification string. + \param[in] id_size size of buffer for kernel identification string. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_GET_INFO_DISABLE)) +extern void EvrRtxKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size); +#else +#define EvrRtxKernelGetInfo(version, id_buf, id_size) +#endif + +/** + \brief Event on successful RTOS kernel information retrieve (Op) + \param[in] version pointer to buffer for retrieving version information. + \param[in] id_buf pointer to buffer for retrieving kernel identification string. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_INFO_RETRIEVED_DISABLE)) +extern void EvrRtxKernelInfoRetrieved (osVersion_t *version, char *id_buf); +#else +#define EvrRtxKernelInfoRetrieved(version, id_buf) +#endif + +/** + \brief Event on current RTOS Kernel state retrieve (API) + \param[in] state current RTOS Kernel state. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_GET_STATE_DISABLE)) +extern void EvrRtxKernelGetState (osKernelState_t state); +#else +#define EvrRtxKernelGetState(state) +#endif + +/** + \brief Event on RTOS Kernel scheduler start (API) +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_START_DISABLE)) +extern void EvrRtxKernelStart (void); +#else +#define EvrRtxKernelStart() +#endif + +/** + \brief Event on successful RTOS Kernel scheduler start (Op) +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_STARTED_DISABLE)) +extern void EvrRtxKernelStarted (void); +#else +#define EvrRtxKernelStarted() +#endif + +/** + \brief Event on RTOS Kernel scheduler lock (API) +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_LOCK_DISABLE)) +extern void EvrRtxKernelLock (void); +#else +#define EvrRtxKernelLock() +#endif + +/** + \brief Event on successful RTOS Kernel scheduler lock (Op) + \param[in] lock previous lock state (1 - locked, 0 - not locked). +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_LOCKED_DISABLE)) +extern void EvrRtxKernelLocked (int32_t lock); +#else +#define EvrRtxKernelLocked(lock) +#endif + +/** + \brief Event on RTOS Kernel scheduler unlock (API) +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_UNLOCK_DISABLE)) +extern void EvrRtxKernelUnlock (void); +#else +#define EvrRtxKernelUnlock() +#endif + +/** + \brief Event on successful RTOS Kernel scheduler unlock (Op) + \param[in] lock previous lock state (1 - locked, 0 - not locked). +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_UNLOCKED_DISABLE)) +extern void EvrRtxKernelUnlocked (int32_t lock); +#else +#define EvrRtxKernelUnlocked(lock) +#endif + +/** + \brief Event on RTOS Kernel scheduler lock state restore (API) + \param[in] lock lock state obtained by \ref osKernelLock or \ref osKernelUnlock. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_RESTORE_LOCK_DISABLE)) +extern void EvrRtxKernelRestoreLock (int32_t lock); +#else +#define EvrRtxKernelRestoreLock(lock) +#endif + +/** + \brief Event on successful RTOS Kernel scheduler lock state restore (Op) + \param[in] lock new lock state (1 - locked, 0 - not locked). +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_LOCK_RESTORED_DISABLE)) +extern void EvrRtxKernelLockRestored (int32_t lock); +#else +#define EvrRtxKernelLockRestored(lock) +#endif + +/** + \brief Event on RTOS Kernel scheduler suspend (API) +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_SUSPEND_DISABLE)) +extern void EvrRtxKernelSuspend (void); +#else +#define EvrRtxKernelSuspend() +#endif + +/** + \brief Event on successful RTOS Kernel scheduler suspend (Op) + \param[in] sleep_ticks time in ticks, for how long the system can sleep or power-down. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_SUSPENDED_DISABLE)) +extern void EvrRtxKernelSuspended (uint32_t sleep_ticks); +#else +#define EvrRtxKernelSuspended(sleep_ticks) +#endif + +/** + \brief Event on RTOS Kernel scheduler resume (API) + \param[in] sleep_ticks time in ticks, for how long the system was in sleep or power-down mode. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_RESUME_DISABLE)) +extern void EvrRtxKernelResume (uint32_t sleep_ticks); +#else +#define EvrRtxKernelResume(sleep_ticks) +#endif + +/** + \brief Event on successful RTOS Kernel scheduler resume (Op) +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_RESUMED_DISABLE)) +extern void EvrRtxKernelResumed (void); +#else +#define EvrRtxKernelResumed() +#endif + +/** + \brief Event on RTOS kernel tick count retrieve (API) + \param[in] count RTOS kernel current tick count. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_GET_TICK_COUNT_DISABLE)) +extern void EvrRtxKernelGetTickCount (uint64_t count); +#else +#define EvrRtxKernelGetTickCount(count) +#endif + +/** + \brief Event on RTOS kernel tick frequency retrieve (API) + \param[in] freq frequency of the kernel tick. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_GET_TICK_FREQ_DISABLE)) +extern void EvrRtxKernelGetTickFreq (uint32_t freq); +#else +#define EvrRtxKernelGetTickFreq(freq) +#endif + +/** + \brief Event on RTOS kernel system timer count retrieve (API) + \param[in] count RTOS kernel current system timer count as 32-bit value. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_GET_SYS_TIMER_COUNT_DISABLE)) +extern void EvrRtxKernelGetSysTimerCount (uint32_t count); +#else +#define EvrRtxKernelGetSysTimerCount(count) +#endif + +/** + \brief Event on RTOS kernel system timer frequency retrieve (API) + \param[in] freq frequency of the system timer. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_GET_SYS_TIMER_FREQ_DISABLE)) +extern void EvrRtxKernelGetSysTimerFreq (uint32_t freq); +#else +#define EvrRtxKernelGetSysTimerFreq(freq) +#endif + + +// ==== Thread Events ==== + +/** + \brief Event on thread error (Error) + \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId or NULL when ID is unknown. + \param[in] status extended execution status. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_ERROR_DISABLE)) +extern void EvrRtxThreadError (osThreadId_t thread_id, int32_t status); +#else +#define EvrRtxThreadError(thread_id, status) +#endif + +/** + \brief Event on thread create and intialize (API) + \param[in] func thread function. + \param[in] argument pointer that is passed to the thread function as start argument. + \param[in] attr thread attributes. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_NEW_DISABLE)) +extern void EvrRtxThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr); +#else +#define EvrRtxThreadNew(func, argument, attr) +#endif + +/** + \brief Event on successful thread create (Op) + \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_CREATED_DISABLE)) +extern void EvrRtxThreadCreated (osThreadId_t thread_id); +#else +#define EvrRtxThreadCreated(thread_id) +#endif + +/** + \brief Event on thread name retrieve (API) + \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. + \param[in] name pointer to thread object name +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_NAME_DISABLE)) +extern void EvrRtxThreadGetName (osThreadId_t thread_id, const char *name); +#else +#define EvrRtxThreadGetName(thread_id, name) +#endif + +/** + \brief Event on current running thread ID retrieve (API) + \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_ID_DISABLE)) +extern void EvrRtxThreadGetId (osThreadId_t thread_id); +#else +#define EvrRtxThreadGetId(thread_id) +#endif + +/** + \brief Event on thread state retrieve (API) + \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. + \param[in] state current thread state of the specified thread. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_STATE_DISABLE)) +extern void EvrRtxThreadGetState (osThreadId_t thread_id, osThreadState_t state); +#else +#define EvrRtxThreadGetState(thread_id, state) +#endif + +/** + \brief Event on thread stack size retrieve (API) + \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. + \param[in] stack_size stack size in bytes. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_STACK_SIZE_DISABLE)) +extern void EvrRtxThreadGetStackSize (osThreadId_t thread_id, uint32_t stack_size); +#else +#define EvrRtxThreadGetStackSize(thread_id, stack_size) +#endif + +/** + \brief Event on available stack space retrieve (API) + \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. + \param[in] stack_space remaining stack space in bytes. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_STACK_SPACE_DISABLE)) +extern void EvrRtxThreadGetStackSpace (osThreadId_t thread_id, uint32_t stack_space); +#else +#define EvrRtxThreadGetStackSpace(thread_id, stack_space) +#endif + +/** + \brief Event on thread priority set (API) + \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. + \param[in] priority new priority value for the thread function. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_SET_PRIORITY_DISABLE)) +extern void EvrRtxThreadSetPriority (osThreadId_t thread_id, osPriority_t priority); +#else +#define EvrRtxThreadSetPriority(thread_id, priority) +#endif + +/** + \brief Event on thread priority retrieve (API) + \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. + \param[in] priority current priority value of the specified thread. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_PRIORITY_DISABLE)) +extern void EvrRtxThreadGetPriority (osThreadId_t thread_id, osPriority_t priority); +#else +#define EvrRtxThreadGetPriority(thread_id, priority) +#endif + +/** + \brief Event on thread yield (API) +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_YIELD_DISABLE)) +extern void EvrRtxThreadYield (void); +#else +#define EvrRtxThreadYield() +#endif + +/** + \brief Event on thread suspend (API) + \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_SUSPEND_DISABLE)) +extern void EvrRtxThreadSuspend (osThreadId_t thread_id); +#else +#define EvrRtxThreadSuspend(thread_id) +#endif + +/** + \brief Event on successful thread suspend (Op) + \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_SUSPENDED_DISABLE)) +extern void EvrRtxThreadSuspended (osThreadId_t thread_id); +#else +#define EvrRtxThreadSuspended(thread_id) +#endif + +/** + \brief Event on thread resume (API) + \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_RESUME_DISABLE)) +extern void EvrRtxThreadResume (osThreadId_t thread_id); +#else +#define EvrRtxThreadResume(thread_id) +#endif + +/** + \brief Event on successful thread resume (Op) + \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_RESUMED_DISABLE)) +extern void EvrRtxThreadResumed (osThreadId_t thread_id); +#else +#define EvrRtxThreadResumed(thread_id) +#endif + +/** + \brief Event on thread detach (API) + \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_DETACH_DISABLE)) +extern void EvrRtxThreadDetach (osThreadId_t thread_id); +#else +#define EvrRtxThreadDetach(thread_id) +#endif + +/** + \brief Event on successful thread detach (Op) + \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_DETACHED_DISABLE)) +extern void EvrRtxThreadDetached (osThreadId_t thread_id); +#else +#define EvrRtxThreadDetached(thread_id) +#endif + +/** + \brief Event on thread join (API) + \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_JOIN_DISABLE)) +extern void EvrRtxThreadJoin (osThreadId_t thread_id); +#else +#define EvrRtxThreadJoin(thread_id) +#endif + +/** + \brief Event on pending thread join (Op) + \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_JOIN_PENDING_DISABLE)) +extern void EvrRtxThreadJoinPending (osThreadId_t thread_id); +#else +#define EvrRtxThreadJoinPending(thread_id) +#endif + +/** + \brief Event on successful thread join (Op) + \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_JOINED_DISABLE)) +extern void EvrRtxThreadJoined (osThreadId_t thread_id); +#else +#define EvrRtxThreadJoined(thread_id) +#endif + +/** + \brief Event on thread execution block (Op) + \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. + \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_BLOCKED_DISABLE)) +extern void EvrRtxThreadBlocked (osThreadId_t thread_id, uint32_t timeout); +#else +#define EvrRtxThreadBlocked(thread_id, timeout) +#endif + +/** + \brief Event on blocked thread release (Op) + \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. + \param[in] ret_val extended execution status of the thread. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_UNBLOCKED_DISABLE)) +extern void EvrRtxThreadUnblocked (osThreadId_t thread_id, uint32_t ret_val); +#else +#define EvrRtxThreadUnblocked(thread_id, ret_val) +#endif + +/** + \brief Event on current running thread switch (Op) + \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_SWITCH_DISABLE)) +extern void EvrRtxThreadSwitch (osThreadId_t thread_id); +#else +#define EvrRtxThreadSwitch(thread_id) +#endif + +/** + \brief Event on thread exit (API) +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_EXIT_DISABLE)) +extern void EvrRtxThreadExit (void); +#else +#define EvrRtxThreadExit() +#endif + +/** + \brief Event on thread terminate (API) + \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_TERMINATE_DISABLE)) +extern void EvrRtxThreadTerminate (osThreadId_t thread_id); +#else +#define EvrRtxThreadTerminate(thread_id) +#endif + +/** + \brief Event on successful thread terminate (Op) + \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_DESTROYED_DISABLE)) +extern void EvrRtxThreadDestroyed (osThreadId_t thread_id); +#else +#define EvrRtxThreadDestroyed(thread_id) +#endif + +/** + \brief Event on active thread count retrieve (API) + \param[in] count number of active threads. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_COUNT_DISABLE)) +extern void EvrRtxThreadGetCount (uint32_t count); +#else +#define EvrRtxThreadGetCount(count) +#endif + +/** + \brief Event on active threads enumerate (API) + \param[in] thread_array pointer to array for retrieving thread IDs. + \param[in] array_items maximum number of items in array for retrieving thread IDs. + \param[in] count number of enumerated threads. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_ENUMERATE_DISABLE)) +extern void EvrRtxThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items, uint32_t count); +#else +#define EvrRtxThreadEnumerate(thread_array, array_items, count) +#endif + +/** + \brief Event on thread flags set (API) + \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. + \param[in] flags flags of the thread that shall be set. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_SET_DISABLE)) +extern void EvrRtxThreadFlagsSet (osThreadId_t thread_id, uint32_t flags); +#else +#define EvrRtxThreadFlagsSet(thread_id, flags) +#endif + +/** + \brief Event on successful thread flags set (Op) + \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. + \param[in] thread_flags thread flags after setting +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_SET_DONE_DISABLE)) +extern void EvrRtxThreadFlagsSetDone (osThreadId_t thread_id, uint32_t thread_flags); +#else +#define EvrRtxThreadFlagsSetDone(thread_id, thread_flags) +#endif + +/** + \brief Event on thread flags clear (API) + \param[in] flags flags of the thread that shall be cleared. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_CLEAR_DISABLE)) +extern void EvrRtxThreadFlagsClear (uint32_t flags); +#else +#define EvrRtxThreadFlagsClear(flags) +#endif + +/** + \brief Event on successful thread flags clear (Op) + \param[in] thread_flags thread flags before clearing +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_CLEAR_DONE_DISABLE)) +extern void EvrRtxThreadFlagsClearDone (uint32_t thread_flags); +#else +#define EvrRtxThreadFlagsClearDone(thread_flags) +#endif + +/** + \brief Event on thread flags retrieve (API) + \param[in] thread_flags current thread flags. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_GET_DISABLE)) +extern void EvrRtxThreadFlagsGet (uint32_t thread_flags); +#else +#define EvrRtxThreadFlagsGet(thread_flags) +#endif + +/** + \brief Event on wait for thread flags (API) + \param[in] flags flags to wait for. + \param[in] options flags options (osFlagsXxxx). + \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_WAIT_DISABLE)) +extern void EvrRtxThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout); +#else +#define EvrRtxThreadFlagsWait(flags, options, timeout) +#endif + +/** + \brief Event on pending wait for thread flags (Op) + \param[in] flags flags to wait for. + \param[in] options flags options (osFlagsXxxx). + \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_WAIT_PENDING_DISABLE)) +extern void EvrRtxThreadFlagsWaitPending (uint32_t flags, uint32_t options, uint32_t timeout); +#else +#define EvrRtxThreadFlagsWaitPending(flags, options, timeout) +#endif + +/** + \brief Event on wait timeout for thread flags (Op) +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_WAIT_TIMEOUT_DISABLE)) +extern void EvrRtxThreadFlagsWaitTimeout (void); +#else +#define EvrRtxThreadFlagsWaitTimeout() +#endif + +/** + \brief Event on successful wait for thread flags (Op) + \param[in] flags flags to wait for. + \param[in] options flags options (osFlagsXxxx). + \param[in] thread_flags thread flags before clearing +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_WAIT_COMPLETED_DISABLE)) +extern void EvrRtxThreadFlagsWaitCompleted (uint32_t flags, uint32_t options, uint32_t thread_flags); +#else +#define EvrRtxThreadFlagsWaitCompleted(flags, options, thread_flags) +#endif + +/** + \brief Event on unsuccessful wait for thread flags (Op) + \param[in] flags flags to wait for. + \param[in] options flags options (osFlagsXxxx). +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_WAIT_NOT_COMPLETED_DISABLE)) +extern void EvrRtxThreadFlagsWaitNotCompleted (uint32_t flags, uint32_t options); +#else +#define EvrRtxThreadFlagsWaitNotCompleted(flags, options) +#endif + +/** + \brief Event on wait for timeout (API) + \param[in] ticks \ref CMSIS_RTOS_TimeOutValue "time ticks" value +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_DELAY_DISABLE)) +extern void EvrRtxThreadDelay (uint32_t ticks); +#else +#define EvrRtxThreadDelay(ticks) +#endif + +/** + \brief Event on wait until specified time (API) + \param[in] ticks absolute time in ticks +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_DELAY_UNTIL_DISABLE)) +extern void EvrRtxThreadDelayUntil (uint64_t ticks); +#else +#define EvrRtxThreadDelayUntil(ticks) +#endif + +/** + \brief Event on completed wait (Op) +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_DELAY_COMPLETED_DISABLE)) +extern void EvrRtxThreadDelayCompleted (void); +#else +#define EvrRtxThreadDelayCompleted() +#endif + + + +// ==== Timer Events ==== + +/** + \brief Event on timer error (Error) + \param[in] timer_id timer ID obtained by \ref osTimerNew or NULL when ID is unknown. + \param[in] status extended execution status. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_ERROR_DISABLE)) +extern void EvrRtxTimerError (osTimerId_t timer_id, int32_t status); +#else +#define EvrRtxTimerError(timer_id, status); +#endif + +/** + \brief Event on timer callback call (Op) + \param[in] func start address of a timer call back function. + \param[in] argument argument to the timer call back function. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_CALLBACK_DISABLE)) +extern void EvrRtxTimerCallback (osTimerFunc_t func, void *argument); +#else +#define EvrRtxTimerCallback(func, argument); +#endif + +/** + \brief Event on timer create and initialize (API) + \param[in] func start address of a timer call back function. + \param[in] type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior. + \param[in] argument argument to the timer call back function. + \param[in] attr timer attributes. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_NEW_DISABLE)) +extern void EvrRtxTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr); +#else +#define EvrRtxTimerNew(func, type, argument, attr); +#endif + +/** + \brief Event on successful timer create (Op) + \param[in] timer_id timer ID obtained by \ref osTimerNew +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_CREATED_DISABLE)) +extern void EvrRtxTimerCreated (osTimerId_t timer_id); +#else +#define EvrRtxTimerCreated(timer_id); +#endif + +/** + \brief Event on timer name retrieve (API) + \param[in] timer_id timer ID obtained by \ref osTimerNew + \param[in] name pointer to timer object name. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_GET_NAME_DISABLE)) +extern void EvrRtxTimerGetName (osTimerId_t timer_id, const char *name); +#else +#define EvrRtxTimerGetName(timer_id, name); +#endif + +/** + \brief Event on timer start (API) + \param[in] timer_id timer ID obtained by \ref osTimerNew + \param[in] ticks \ref CMSIS_RTOS_TimeOutValue "time ticks" value of the timer. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_START_DISABLE)) +extern void EvrRtxTimerStart (osTimerId_t timer_id, uint32_t ticks); +#else +#define EvrRtxTimerStart(timer_id, ticks); +#endif + +/** + \brief Event on successful timer start (Op) + \param[in] timer_id timer ID obtained by \ref osTimerNew +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_STARTED_DISABLE)) +extern void EvrRtxTimerStarted (osTimerId_t timer_id); +#else +#define EvrRtxTimerStarted(timer_id); +#endif + +/** + \brief Event on timer stop (API) + \param[in] timer_id timer ID obtained by \ref osTimerNew +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_STOP_DISABLE)) +extern void EvrRtxTimerStop (osTimerId_t timer_id); +#else +#define EvrRtxTimerStop(timer_id); +#endif + +/** + \brief Event on successful timer stop (Op) + \param[in] timer_id timer ID obtained by \ref osTimerNew +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_STOPPED_DISABLE)) +extern void EvrRtxTimerStopped (osTimerId_t timer_id); +#else +#define EvrRtxTimerStopped(timer_id); +#endif + +/** + \brief Event on timer running state check (API) + \param[in] timer_id timer ID obtained by \ref osTimerNew + \param[in] running running state: 0 not running, 1 running +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_IS_RUNNING_DISABLE)) +extern void EvrRtxTimerIsRunning (osTimerId_t timer_id, uint32_t running); +#else +#define EvrRtxTimerIsRunning(timer_id, running); +#endif + +/** + \brief Event on timer delete (API) + \param[in] timer_id timer ID obtained by \ref osTimerNew +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_DELETE_DISABLE)) +extern void EvrRtxTimerDelete (osTimerId_t timer_id); +#else +#define EvrRtxTimerDelete(timer_id); +#endif + +/** + \brief Event on successful timer delete (Op) + \param[in] timer_id timer ID obtained by \ref osTimerNew +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_DESTROYED_DISABLE)) +extern void EvrRtxTimerDestroyed (osTimerId_t timer_id); +#else +#define EvrRtxTimerDestroyed(timer_id); +#endif + + +// ==== Event Flags Events ==== + +/** + \brief Event on event flags error (Error) + \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew or NULL when ID is unknown. + \param[in] status extended execution status. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_ERROR_DISABLE)) +extern void EvrRtxEventFlagsError (osEventFlagsId_t ef_id, int32_t status); +#else +#define EvrRtxEventFlagsError(ef_id, status) +#endif + +/** + \brief Event on event flags create and initialize (API) + \param[in] attr event flags attributes +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_NEW_DISABLE)) +extern void EvrRtxEventFlagsNew (const osEventFlagsAttr_t *attr); +#else +#define EvrRtxEventFlagsNew(attr) +#endif + +/** + \brief Event on successful event flags create (Op) + \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_CREATED_DISABLE)) +extern void EvrRtxEventFlagsCreated (osEventFlagsId_t ef_id); +#else +#define EvrRtxEventFlagsCreated(ef_id) +#endif + +/** + \brief Event on event flags name retrieve (API) + \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. + \param[in] name pointer to event flags object name. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_GET_NAME_DISABLE)) +extern void EvrRtxEventFlagsGetName (osEventFlagsId_t ef_id, const char *name); +#else +#define EvrRtxEventFlagsGetName(ef_id, name) +#endif + +/** + \brief Event on event flags set (API) + \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. + \param[in] flags flags that shall be set. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_SET_DISABLE)) +extern void EvrRtxEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags); +#else +#define EvrRtxEventFlagsSet(ef_id, flags) +#endif + +/** + \brief Event on successful event flags set (Op) + \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. + \param[in] event_flags event flags after setting +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_SET_DONE_DISABLE)) +extern void EvrRtxEventFlagsSetDone (osEventFlagsId_t ef_id, uint32_t event_flags); +#else +#define EvrRtxEventFlagsSetDone(ef_id, event_flags) +#endif + +/** + \brief Event on event flags clear (API) + \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. + \param[in] flags flags that shall be cleared. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_CLEAR_DISABLE)) +extern void EvrRtxEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags); +#else +#define EvrRtxEventFlagsClear(ef_id, flags) +#endif + +/** + \brief Event on successful event flags clear (Op) + \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. + \param[in] event_flags event flags before clearing +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_CLEAR_DONE_DISABLE)) +extern void EvrRtxEventFlagsClearDone (osEventFlagsId_t ef_id, uint32_t event_flags); +#else +#define EvrRtxEventFlagsClearDone(ef_id, event_flags) +#endif + +/** + \brief Event on event flags retrieve (API) + \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. + \param[in] event_flags current event flags. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_GET_DISABLE)) +extern void EvrRtxEventFlagsGet (osEventFlagsId_t ef_id, uint32_t event_flags); +#else +#define EvrRtxEventFlagsGet(ef_id, event_flags) +#endif + +/** + \brief Event on wait for event flags (API) + \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. + \param[in] flags flags to wait for. + \param[in] options flags options (osFlagsXxxx). + \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_WAIT_DISABLE)) +extern void EvrRtxEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout); +#else +#define EvrRtxEventFlagsWait(ef_id, flags, options, timeout) +#endif + +/** + \brief Event on pending wait for event flags (Op) + \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. + \param[in] flags flags to wait for. + \param[in] options flags options (osFlagsXxxx). + \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_WAIT_PENDING_DISABLE)) +extern void EvrRtxEventFlagsWaitPending (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout); +#else +#define EvrRtxEventFlagsWaitPending(ef_id, flags, options, timeout) +#endif + +/** + \brief Event on wait timeout for event flags (Op) + \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_WAIT_TIMEOUT_DISABLE)) +extern void EvrRtxEventFlagsWaitTimeout (osEventFlagsId_t ef_id); +#else +#define EvrRtxEventFlagsWaitTimeout(ef_id) +#endif + +/** + \brief Event on successful wait for event flags (Op) + \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. + \param[in] flags flags to wait for. + \param[in] options flags options (osFlagsXxxx). + \param[in] event_flags event flags before clearing or 0 if specified flags have not been set. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_WAIT_COMPLETED_DISABLE)) +extern void EvrRtxEventFlagsWaitCompleted (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t event_flags); +#else +#define EvrRtxEventFlagsWaitCompleted(ef_id, flags, options, event_flags) +#endif + +/** + \brief Event on unsuccessful wait for event flags (Op) + \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. + \param[in] flags flags to wait for. + \param[in] options flags options (osFlagsXxxx). +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_WAIT_NOT_COMPLETED_DISABLE)) +extern void EvrRtxEventFlagsWaitNotCompleted (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options); +#else +#define EvrRtxEventFlagsWaitNotCompleted(ef_id, flags, options) +#endif + +/** + \brief Event on event flags delete (API) + \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_DELETE_DISABLE)) +extern void EvrRtxEventFlagsDelete (osEventFlagsId_t ef_id); +#else +#define EvrRtxEventFlagsDelete(ef_id) +#endif + +/** + \brief Event on successful event flags delete (Op) + \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_DESTROYED_DISABLE)) +extern void EvrRtxEventFlagsDestroyed (osEventFlagsId_t ef_id); +#else +#define EvrRtxEventFlagsDestroyed(ef_id) +#endif + + +// ==== Mutex Events ==== + +/** + \brief Event on mutex error (Error) + \param[in] mutex_id mutex ID obtained by \ref osMutexNew or NULL when ID is unknown. + \param[in] status extended execution status. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_ERROR_DISABLE)) +extern void EvrRtxMutexError (osMutexId_t mutex_id, int32_t status); +#else +#define EvrRtxMutexError(mutex_id, status) +#endif + +/** + \brief Event on mutex create and initialize (API) + \param[in] attr mutex attributes +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_NEW_DISABLE)) +extern void EvrRtxMutexNew (const osMutexAttr_t *attr); +#else +#define EvrRtxMutexNew(attr) +#endif + +/** + \brief Event on successful mutex create (Op) + \param[in] mutex_id mutex ID obtained by \ref osMutexNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_CREATED_DISABLE)) +extern void EvrRtxMutexCreated (osMutexId_t mutex_id); +#else +#define EvrRtxMutexCreated(mutex_id) +#endif + +/** + \brief Event on mutex name retrieve (API) + \param[in] mutex_id mutex ID obtained by \ref osMutexNew. + \param[in] name pointer to mutex object name +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_GET_NAME_DISABLE)) +extern void EvrRtxMutexGetName (osMutexId_t mutex_id, const char *name); +#else +#define EvrRtxMutexGetName(mutex_id, name) +#endif + +/** + \brief Event on mutex acquire (API) + \param[in] mutex_id mutex ID obtained by \ref osMutexNew. + \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_ACQUIRE_DISABLE)) +extern void EvrRtxMutexAcquire (osMutexId_t mutex_id, uint32_t timeout); +#else +#define EvrRtxMutexAcquire(mutex_id, timeout) +#endif + +/** + \brief Event on pending mutex acquire (Op) + \param[in] mutex_id mutex ID obtained by \ref osMutexNew. + \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_ACQUIRE_PENDING_DISABLE)) +extern void EvrRtxMutexAcquirePending (osMutexId_t mutex_id, uint32_t timeout); +#else +#define EvrRtxMutexAcquirePending(mutex_id, timeout); +#endif + +/** + \brief Event on mutex acquire timeout (Op) + \param[in] mutex_id mutex ID obtained by \ref osMutexNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_ACQUIRE_TIMEOUT_DISABLE)) +extern void EvrRtxMutexAcquireTimeout (osMutexId_t mutex_id); +#else +#define EvrRtxMutexAcquireTimeout(mutex_id) +#endif + +/** + \brief Event on successful mutex acquire (Op) + \param[in] mutex_id mutex ID obtained by \ref osMutexNew. + \param[in] lock current number of times mutex object is locked +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_ACQUIRED_DISABLE)) +extern void EvrRtxMutexAcquired (osMutexId_t mutex_id, uint32_t lock); +#else +#define EvrRtxMutexAcquired(mutex_id, lock) +#endif + +/** + \brief Event on unsuccessful mutex acquire (Op) + \param[in] mutex_id mutex ID obtained by \ref osMutexNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_NOT_ACQUIRED_DISABLE)) +extern void EvrRtxMutexNotAcquired (osMutexId_t mutex_id); +#else +#define EvrRtxMutexNotAcquired(mutex_id) +#endif + +/** + \brief Event on mutex release (API) + \param[in] mutex_id mutex ID obtained by \ref osMutexNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_RELEASE_DISABLE)) +extern void EvrRtxMutexRelease (osMutexId_t mutex_id); +#else +#define EvrRtxMutexRelease(mutex_id) +#endif + +/** + \brief Event on successful mutex release (Op) + \param[in] mutex_id mutex ID obtained by \ref osMutexNew. + \param[in] lock current number of times mutex object is locked +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_RELEASED_DISABLE)) +extern void EvrRtxMutexReleased (osMutexId_t mutex_id, uint32_t lock); +#else +#define EvrRtxMutexReleased(mutex_id, lock) +#endif + +/** + \brief Event on mutex owner retrieve (API) + \param[in] mutex_id mutex ID obtained by \ref osMutexNew. + \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_GET_OWNER_DISABLE)) +extern void EvrRtxMutexGetOwner (osMutexId_t mutex_id, osThreadId_t thread_id); +#else +#define EvrRtxMutexGetOwner(mutex_id, thread_id) +#endif + +/** + \brief Event on mutex delete (API) + \param[in] mutex_id mutex ID obtained by \ref osMutexNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_DELETE_DISABLE)) +extern void EvrRtxMutexDelete (osMutexId_t mutex_id); +#else +#define EvrRtxMutexDelete(mutex_id) +#endif + +/** + \brief Event on successful mutex delete (Op) + \param[in] mutex_id mutex ID obtained by \ref osMutexNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_DESTROYED_DISABLE)) +extern void EvrRtxMutexDestroyed (osMutexId_t mutex_id); +#else +#define EvrRtxMutexDestroyed(mutex_id) +#endif + + +// ==== Semaphore Events ==== + +/** + \brief Event on semaphore error (Error) + \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew or NULL when ID is unknown. + \param[in] status extended execution status. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_ERROR_DISABLE)) +extern void EvrRtxSemaphoreError (osSemaphoreId_t semaphore_id, int32_t status); +#else +#define EvrRtxSemaphoreError(semaphore_id, status) +#endif + +/** + \brief Event on semaphore create and initialize (API) + \param[in] max_count maximum number of available tokens. + \param[in] initial_count initial number of available tokens. + \param[in] attr semaphore attributes. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_NEW_DISABLE)) +extern void EvrRtxSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr); +#else +#define EvrRtxSemaphoreNew(max_count, initial_count, attr) +#endif + +/** + \brief Event on successful semaphore create (Op) + \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_CREATED_DISABLE)) +extern void EvrRtxSemaphoreCreated (osSemaphoreId_t semaphore_id); +#else +#define EvrRtxSemaphoreCreated(semaphore_id) +#endif + +/** + \brief Event on semaphore name retrieve (API) + \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. + \param[in] name pointer to semaphore object name. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_GET_NAME_DISABLE)) +extern void EvrRtxSemaphoreGetName (osSemaphoreId_t semaphore_id, const char *name); +#else +#define EvrRtxSemaphoreGetName(semaphore_id, name) +#endif + +/** + \brief Event on semaphore acquire (API) + \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. + \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_ACQUIRE_DISABLE)) +extern void EvrRtxSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout); +#else +#define EvrRtxSemaphoreAcquire(semaphore_id, timeout) +#endif + +/** + \brief Event on pending semaphore acquire (Op) + \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. + \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_ACQUIRE_PENDING_DISABLE)) +extern void EvrRtxSemaphoreAcquirePending (osSemaphoreId_t semaphore_id, uint32_t timeout); +#else +#define EvrRtxSemaphoreAcquirePending(semaphore_id, timeout); +#endif + +/** + \brief Event on semaphore acquire timeout (Op) + \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_ACQUIRE_TIMEOUT_DISABLE)) +extern void EvrRtxSemaphoreAcquireTimeout (osSemaphoreId_t semaphore_id); +#else +#define EvrRtxSemaphoreAcquireTimeout(semaphore_id) +#endif + +/** + \brief Event on successful semaphore acquire (Op) + \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_ACQUIRED_DISABLE)) +extern void EvrRtxSemaphoreAcquired (osSemaphoreId_t semaphore_id); +#else +#define EvrRtxSemaphoreAcquired(semaphore_id) +#endif + +/** + \brief Event on unsuccessful semaphore acquire (Op) + \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_NOT_ACQUIRED_DISABLE)) +extern void EvrRtxSemaphoreNotAcquired (osSemaphoreId_t semaphore_id); +#else +#define EvrRtxSemaphoreNotAcquired(semaphore_id) +#endif + +/** + \brief Event on semaphore release (API) + \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_RELEASE_DISABLE)) +extern void EvrRtxSemaphoreRelease (osSemaphoreId_t semaphore_id); +#else +#define EvrRtxSemaphoreRelease(semaphore_id) +#endif + +/** + \brief Event on successful semaphore release (Op) + \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_RELEASED_DISABLE)) +extern void EvrRtxSemaphoreReleased (osSemaphoreId_t semaphore_id); +#else +#define EvrRtxSemaphoreReleased(semaphore_id) +#endif + +/** + \brief Event on semaphore token count retrieval (API) + \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. + \param[in] count current number of available tokens. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_GET_COUNT_DISABLE)) +extern void EvrRtxSemaphoreGetCount (osSemaphoreId_t semaphore_id, uint32_t count); +#else +#define EvrRtxSemaphoreGetCount(semaphore_id, count) +#endif + +/** + \brief Event on semaphore delete (API) + \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_DELETE_DISABLE)) +extern void EvrRtxSemaphoreDelete (osSemaphoreId_t semaphore_id); +#else +#define EvrRtxSemaphoreDelete(semaphore_id) +#endif + +/** + \brief Event on successful semaphore delete (Op) + \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_DESTROYED_DISABLE)) +extern void EvrRtxSemaphoreDestroyed (osSemaphoreId_t semaphore_id); +#else +#define EvrRtxSemaphoreDestroyed(semaphore_id) +#endif + + +// ==== Memory Pool Events ==== + +/** + \brief Event on memory pool error (Error) + \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew or NULL when ID is unknown. + \param[in] status extended execution status. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_ERROR_DISABLE)) +extern void EvrRtxMemoryPoolError (osMemoryPoolId_t mp_id, int32_t status); +#else +#define EvrRtxMemoryPoolError(mp_id, status) +#endif + +/** + \brief Event on memory pool create and initialize (API) + \param[in] block_count maximum number of memory blocks in memory pool. + \param[in] block_size memory block size in bytes. + \param[in] attr memory pool attributes; NULL: default values. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_NEW_DISABLE)) +extern void EvrRtxMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr); +#else +#define EvrRtxMemoryPoolNew(block_count, block_size, attr) +#endif + +/** + \brief Event on successful memory pool create (Op) + \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_CREATED_DISABLE)) +extern void EvrRtxMemoryPoolCreated (osMemoryPoolId_t mp_id); +#else +#define EvrRtxMemoryPoolCreated(mp_id) +#endif + +/** + \brief Event on memory pool name retrieve (API) + \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. + \param[in] name pointer to memory pool object name. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_GET_NAME_DISABLE)) +extern void EvrRtxMemoryPoolGetName (osMemoryPoolId_t mp_id, const char *name); +#else +#define EvrRtxMemoryPoolGetName(mp_id, name) +#endif + +/** + \brief Event on memory pool allocation (API) + \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. + \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_ALLOC_DISABLE)) +extern void EvrRtxMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout); +#else +#define EvrRtxMemoryPoolAlloc(mp_id, timeout) +#endif + +/** + \brief Event on pending memory pool allocation (Op) + \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. + \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_ALLOC_PENDING_DISABLE)) +extern void EvrRtxMemoryPoolAllocPending (osMemoryPoolId_t mp_id, uint32_t timeout); +#else +#define EvrRtxMemoryPoolAllocPending(mp_id, timeout) +#endif + +/** + \brief Event on memory pool allocation timeout (Op) + \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_ALLOC_TIMEOUT_DISABLE)) +extern void EvrRtxMemoryPoolAllocTimeout (osMemoryPoolId_t mp_id); +#else +#define EvrRtxMemoryPoolAllocTimeout(mp_id) +#endif + +/** + \brief Event on successful memory pool allocation (Op) + \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. + \param[in] block address of the allocated memory block. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_ALLOCATED_DISABLE)) +extern void EvrRtxMemoryPoolAllocated (osMemoryPoolId_t mp_id, void *block); +#else +#define EvrRtxMemoryPoolAllocated(mp_id, block) +#endif + +/** + \brief Event on unsuccessful memory pool allocation (Op) + \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_ALLOC_FAILED_DISABLE)) +extern void EvrRtxMemoryPoolAllocFailed (osMemoryPoolId_t mp_id); +#else +#define EvrRtxMemoryPoolAllocFailed(mp_id) +#endif + +/** + \brief Event on memory pool free (API) + \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. + \param[in] block address of the allocated memory block to be returned to the memory pool. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_FREE_DISABLE)) +extern void EvrRtxMemoryPoolFree (osMemoryPoolId_t mp_id, void *block); +#else +#define EvrRtxMemoryPoolFree(mp_id, block) +#endif + +/** + \brief Event on successful memory pool free (Op) + \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. + \param[in] block address of the allocated memory block to be returned to the memory pool. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_DEALLOCATED_DISABLE)) +extern void EvrRtxMemoryPoolDeallocated (osMemoryPoolId_t mp_id, void *block); +#else +#define EvrRtxMemoryPoolDeallocated(mp_id, block) +#endif + +/** + \brief Event on unsuccessful memory pool free (Op) + \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. + \param[in] block address of the allocated memory block to be returned to the memory pool. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_FREE_FAILED_DISABLE)) +extern void EvrRtxMemoryPoolFreeFailed (osMemoryPoolId_t mp_id, void *block); +#else +#define EvrRtxMemoryPoolFreeFailed(mp_id, block) +#endif + +/** + \brief Event on memory pool capacity retrieve (API) + \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. + \param[in] capacity maximum number of memory blocks. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_GET_CAPACITY_DISABLE)) +extern void EvrRtxMemoryPoolGetCapacity (osMemoryPoolId_t mp_id, uint32_t capacity); +#else +#define EvrRtxMemoryPoolGetCapacity(mp_id, capacity) +#endif + +/** + \brief Event on memory pool block size retrieve (API) + \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. + \param[in] block_size memory block size in bytes. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_GET_BLOCK_SZIE_DISABLE)) +extern void EvrRtxMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id, uint32_t block_size); +#else +#define EvrRtxMemoryPoolGetBlockSize(mp_id, block_size) +#endif + +/** + \brief Event on used memory pool blocks retrieve (API) + \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. + \param[in] count number of memory blocks used. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_GET_COUNT_DISABLE)) +extern void EvrRtxMemoryPoolGetCount (osMemoryPoolId_t mp_id, uint32_t count); +#else +#define EvrRtxMemoryPoolGetCount(mp_id, count) +#endif + +/** + \brief Event on available memory pool blocks retrieve (API) + \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. + \param[in] space number of memory blocks available. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_GET_SPACE_DISABLE)) +extern void EvrRtxMemoryPoolGetSpace (osMemoryPoolId_t mp_id, uint32_t space); +#else +#define EvrRtxMemoryPoolGetSpace(mp_id, space) +#endif + +/** + \brief Event on memory pool delete (API) + \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_DELETE_DISABLE)) +extern void EvrRtxMemoryPoolDelete (osMemoryPoolId_t mp_id); +#else +#define EvrRtxMemoryPoolDelete(mp_id) +#endif + +/** + \brief Event on successful memory pool delete (Op) + \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_DESTROYED_DISABLE)) +extern void EvrRtxMemoryPoolDestroyed (osMemoryPoolId_t mp_id); +#else +#define EvrRtxMemoryPoolDestroyed(mp_id) +#endif + + +// ==== Message Queue Events ==== + +/** + \brief Event on message queue error (Error) + \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew or NULL when ID is unknown. + \param[in] status extended execution status. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_ERROR_DISABLE)) +extern void EvrRtxMessageQueueError (osMessageQueueId_t mq_id, int32_t status); +#else +#define EvrRtxMessageQueueError(mq_id, status) +#endif + +/** + \brief Event on message queue create and initialization (API) + \param[in] msg_count maximum number of messages in queue. + \param[in] msg_size maximum message size in bytes. + \param[in] attr message queue attributes; NULL: default values. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_NEW_DISABLE)) +extern void EvrRtxMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr); +#else +#define EvrRtxMessageQueueNew(msg_count, msg_size, attr) +#endif + +/** + \brief Event on successful message queue create (Op) + \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_CREATED_DISABLE)) +extern void EvrRtxMessageQueueCreated (osMessageQueueId_t mq_id); +#else +#define EvrRtxMessageQueueCreated(mq_id) +#endif + +/** + \brief Event on message queue name retrieve(API) + \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. + \param[in] name pointer to message queue object name. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_NAME_DISABLE)) +extern void EvrRtxMessageQueueGetName (osMessageQueueId_t mq_id, const char *name); +#else +#define EvrRtxMessageQueueGetName(mq_id, name) +#endif + +/** + \brief Event on message put (API) + \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. + \param[in] msg_ptr pointer to buffer with message to put into a queue. + \param[in] msg_prio message priority. + \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_PUT_DISABLE)) +extern void EvrRtxMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout); +#else +#define EvrRtxMessageQueuePut(mq_id, msg_ptr, msg_prio, timeout) +#endif + +/** + \brief Event on pending message put (Op) + \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. + \param[in] msg_ptr pointer to buffer with message to put into a queue. + \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_PUT_PENDING_DISABLE)) +extern void EvrRtxMessageQueuePutPending (osMessageQueueId_t mq_id, const void *msg_ptr, uint32_t timeout); +#else +#define EvrRtxMessageQueuePutPending(mq_id, msg_ptr, timeout) +#endif + +/** + \brief Event on message put timeout (Op) + \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_PUT_TIMEOUT_DISABLE)) +extern void EvrRtxMessageQueuePutTimeout (osMessageQueueId_t mq_id); +#else +#define EvrRtxMessageQueuePutTimeout(mq_id) +#endif + +/** + \brief Event on pending message insert (Op) + \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. + \param[in] msg_ptr pointer to buffer with message to put into a queue. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_INSERT_PENDING_DISABLE)) +extern void EvrRtxMessageQueueInsertPending (osMessageQueueId_t mq_id, const void *msg_ptr); +#else +#define EvrRtxMessageQueueInsertPending(mq_id, msg_ptr) +#endif + +/** + \brief Event on successful message insert (Op) + \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. + \param[in] msg_ptr pointer to buffer with message to put into a queue. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_INSERTED_DISABLE)) +extern void EvrRtxMessageQueueInserted (osMessageQueueId_t mq_id, const void *msg_ptr); +#else +#define EvrRtxMessageQueueInserted(mq_id, msg_ptr) +#endif + +/** + \brief Event on unsuccessful message insert (Op) + \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. + \param[in] msg_ptr pointer to buffer with message to put into a queue. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_NOT_INSERTED_DISABLE)) +extern void EvrRtxMessageQueueNotInserted (osMessageQueueId_t mq_id, const void *msg_ptr); +#else +#define EvrRtxMessageQueueNotInserted(mq_id, msg_ptr) +#endif + +/** + \brief Event on message get (API) + \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. + \param[in] msg_ptr pointer to buffer for message to get from a queue. + \param[in] msg_prio message priority. + \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_DISABLE)) +extern void EvrRtxMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout); +#else +#define EvrRtxMessageQueueGet(mq_id, msg_ptr, msg_prio, timeout) +#endif + +/** + \brief Event on pending message get (Op) + \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. + \param[in] msg_ptr pointer to buffer for message to get from a queue. + \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_PENDING_DISABLE)) +extern void EvrRtxMessageQueueGetPending (osMessageQueueId_t mq_id, void *msg_ptr, uint32_t timeout); +#else +#define EvrRtxMessageQueueGetPending(mq_id, msg_ptr, timeout) +#endif + +/** + \brief Event on message get timeout (Op) + \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_TIMEOUT_DISABLE)) +extern void EvrRtxMessageQueueGetTimeout (osMessageQueueId_t mq_id); +#else +#define EvrRtxMessageQueueGetTimeout(mq_id) +#endif + +/** + \brief Event on successful message get (Op) + \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. + \param[in] msg_ptr pointer to buffer for message to get from a queue. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_RETRIEVED_DISABLE)) +extern void EvrRtxMessageQueueRetrieved (osMessageQueueId_t mq_id, void *msg_ptr); +#else +#define EvrRtxMessageQueueRetrieved(mq_id, msg_ptr) +#endif + +/** + \brief Event on unsuccessful message get (Op) + \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. + \param[in] msg_ptr pointer to buffer for message to get from a queue. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_NOT_RETRIEVED_DISABLE)) +extern void EvrRtxMessageQueueNotRetrieved (osMessageQueueId_t mq_id, void *msg_ptr); +#else +#define EvrRtxMessageQueueNotRetrieved(mq_id, msg_ptr) +#endif + +/** + \brief Event on message queue capacity retrieve (API) + \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. + \param[in] capacity maximum number of messages. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_CAPACITY_DISABLE)) +extern void EvrRtxMessageQueueGetCapacity (osMessageQueueId_t mq_id, uint32_t capacity); +#else +#define EvrRtxMessageQueueGetCapacity(mq_id, capacity) +#endif + +/** + \brief Event on message queue message size retrieve (API) + \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. + \param[in] msg_size maximum message size in bytes. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_MSG_SIZE_DISABLE)) +extern void EvrRtxMessageQueueGetMsgSize (osMessageQueueId_t mq_id, uint32_t msg_size); +#else +#define EvrRtxMessageQueueGetMsgSize(mq_id, msg_size) +#endif + +/** + \brief Event on message queue message count retrieve (API) + \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. + \param[in] count number of queued messages. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_COUNT_DISABLE)) +extern void EvrRtxMessageQueueGetCount (osMessageQueueId_t mq_id, uint32_t count); +#else +#define EvrRtxMessageQueueGetCount(mq_id, count) +#endif + +/** + \brief Event on message queue message slots retrieve (API) + \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. + \param[in] space number of available slots for messages. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_SPACE_DISABLE)) +extern void EvrRtxMessageQueueGetSpace (osMessageQueueId_t mq_id, uint32_t space); +#else +#define EvrRtxMessageQueueGetSpace(mq_id, space) +#endif + +/** + \brief Event on message queue reset (API) + \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_RESET_DISABLE)) +extern void EvrRtxMessageQueueReset (osMessageQueueId_t mq_id); +#else +#define EvrRtxMessageQueueReset(mq_id) +#endif + +/** + \brief Event on successful message queue reset (Op) + \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_RESET_DONE_DISABLE)) +extern void EvrRtxMessageQueueResetDone (osMessageQueueId_t mq_id); +#else +#define EvrRtxMessageQueueResetDone(mq_id) +#endif + +/** + \brief Event on message queue delete (API) + \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_DELETE_DISABLE)) +extern void EvrRtxMessageQueueDelete (osMessageQueueId_t mq_id); +#else +#define EvrRtxMessageQueueDelete(mq_id) +#endif + +/** + \brief Event on successful message queue delete (Op) + \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. +*/ +#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_DESTROYED_DISABLE)) +extern void EvrRtxMessageQueueDestroyed (osMessageQueueId_t mq_id); +#else +#define EvrRtxMessageQueueDestroyed(mq_id) +#endif + + +#endif // RTX_EVR_H_ +/** @}*/ diff --git a/rtos/TARGET_CORTEX/rtx5/rtx_kernel.c b/rtos/TARGET_CORTEX/rtx5/rtx_kernel.c new file mode 100644 index 0000000..d9b9a7a --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/rtx_kernel.c @@ -0,0 +1,643 @@ +/* + * Copyright (c) 2013-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * + * Project: CMSIS-RTOS RTX + * Title: Kernel functions + * + * ----------------------------------------------------------------------------- + */ + +#include "rtx_lib.h" +#include "rt_OsEventObserver.h" + + +// OS Runtime Information +osRtxInfo_t osRtxInfo __attribute__((section(".data.os"))) = +{ .os_id = osRtxKernelId, .version = osRtxVersionKernel, .kernel.state = osRtxKernelInactive }; + + +// ==== Helper functions ==== + +/// Block Kernel (disable: thread switching, time tick, post ISR processing). +static void KernelBlock (void) { + + if (osRtxInfo.tick_irqn >= 0) { + ExtTick_DisableIRQ(osRtxInfo.tick_irqn); + } + osRtxSysTimerDisable(); + osRtxInfo.kernel.blocked = 1U; + __DSB(); + if (osRtxInfo.tick_irqn < 0) { + osRtxInfo.kernel.pendISR = GetPendSV_ST(); + ClrPendSV_ST(); + } else { + osRtxInfo.kernel.pendISR = GetPendSV(); + ClrPendSV(); + } +} + +/// Unblock Kernel +static void KernelUnblock (void) { + + osRtxInfo.kernel.blocked = 0U; + __DSB(); + if (osRtxInfo.kernel.pendSV != 0U) { + osRtxInfo.kernel.pendSV = 0U; + SetPendSV(); + } + if (osRtxInfo.kernel.pendISR != 0U) { + SetPendFlags(osRtxInfo.kernel.pendISR); + } + if (osRtxInfo.tick_irqn >= 0) { + ExtTick_EnableIRQ(osRtxInfo.tick_irqn); + } + osRtxSysTimerEnable(); +} + + +// ==== Service Calls ==== + +// Service Calls definitions +SVC0_0M(KernelInitialize, osStatus_t) +SVC0_3 (KernelGetInfo, osStatus_t, osVersion_t *, char *, uint32_t) +SVC0_0M(KernelStart, osStatus_t) +SVC0_0 (KernelLock, int32_t) +SVC0_0 (KernelUnlock, int32_t) +SVC0_1 (KernelRestoreLock, int32_t, int32_t) +SVC0_0 (KernelSuspend, uint32_t) +SVC0_1N(KernelResume, void, uint32_t) +SVC0_0 (KernelGetState, osKernelState_t) +SVC0_0D(KernelGetTickCount, uint64_t) +SVC0_0 (KernelGetTickFreq, uint32_t) +SVC0_0 (KernelGetSysTimerCount, uint32_t) +SVC0_0 (KernelGetSysTimerFreq, uint32_t) + +/// Initialize the RTOS Kernel. +/// \note API identical to osKernelInitialize +osStatus_t svcRtxKernelInitialize (void) { + + if (osRtxInfo.kernel.state == osRtxKernelReady) { + EvrRtxKernelInitializeCompleted(); + return osOK; + } + if (osRtxInfo.kernel.state != osKernelInactive) { + EvrRtxKernelError(osError); + return osError; + } + + // Initialize osRtxInfo + memset(&osRtxInfo.kernel, 0, sizeof(osRtxInfo) - offsetof(osRtxInfo_t, kernel)); + + if (osRtxConfig.thread_stack_size < (64U + 8U)) { + EvrRtxKernelError(osRtxErrorInvalidThreadStack); + return osError; + } + + if ((osRtxConfig.isr_queue.data == NULL) || (osRtxConfig.isr_queue.max == 0U)) { + EvrRtxKernelError(osError); + return osError; + } + osRtxInfo.isr_queue.data = osRtxConfig.isr_queue.data; + osRtxInfo.isr_queue.max = osRtxConfig.isr_queue.max; + + osRtxInfo.thread.robin.timeout = osRtxConfig.robin_timeout; + + // Initialize Memory Pools (Variable Block Size) + if (osRtxMemoryInit(osRtxConfig.mem.common_addr, osRtxConfig.mem.common_size) != 0U) { + osRtxInfo.mem.common = osRtxConfig.mem.common_addr; + } + if (osRtxMemoryInit(osRtxConfig.mem.stack_addr, osRtxConfig.mem.stack_size) != 0U) { + osRtxInfo.mem.stack = osRtxConfig.mem.stack_addr; + } else { + osRtxInfo.mem.stack = osRtxInfo.mem.common; + } + if (osRtxMemoryInit(osRtxConfig.mem.mp_data_addr, osRtxConfig.mem.mp_data_size) != 0U) { + osRtxInfo.mem.mp_data = osRtxConfig.mem.mp_data_addr; + } else { + osRtxInfo.mem.mp_data = osRtxInfo.mem.common; + } + if (osRtxMemoryInit(osRtxConfig.mem.mq_data_addr, osRtxConfig.mem.mq_data_size) != 0U) { + osRtxInfo.mem.mq_data = osRtxConfig.mem.mq_data_addr; + } else { + osRtxInfo.mem.mq_data = osRtxInfo.mem.common; + } + + // Initialize Memory Pools (Fixed Block Size) + if ((osRtxConfig.mpi.stack != NULL) && + (osRtxMemoryPoolInit(osRtxConfig.mpi.stack, + osRtxConfig.mpi.stack->max_blocks, + osRtxConfig.mpi.stack->block_size, + osRtxConfig.mpi.stack->block_base) != 0U)) { + osRtxInfo.mpi.stack = osRtxConfig.mpi.stack; + } + if ((osRtxConfig.mpi.thread != NULL) && + (osRtxMemoryPoolInit(osRtxConfig.mpi.thread, + osRtxConfig.mpi.thread->max_blocks, + osRtxConfig.mpi.thread->block_size, + osRtxConfig.mpi.thread->block_base) != 0U)) { + osRtxInfo.mpi.thread = osRtxConfig.mpi.thread; + } + if ((osRtxConfig.mpi.timer != NULL) && + (osRtxMemoryPoolInit(osRtxConfig.mpi.timer, + osRtxConfig.mpi.timer->max_blocks, + osRtxConfig.mpi.timer->block_size, + osRtxConfig.mpi.timer->block_base) != 0U)) { + osRtxInfo.mpi.timer = osRtxConfig.mpi.timer; + } + if ((osRtxConfig.mpi.event_flags != NULL) && + (osRtxMemoryPoolInit(osRtxConfig.mpi.event_flags, + osRtxConfig.mpi.event_flags->max_blocks, + osRtxConfig.mpi.event_flags->block_size, + osRtxConfig.mpi.event_flags->block_base) != 0U)) { + osRtxInfo.mpi.event_flags = osRtxConfig.mpi.event_flags; + } + if ((osRtxConfig.mpi.mutex != NULL) && + (osRtxMemoryPoolInit(osRtxConfig.mpi.mutex, + osRtxConfig.mpi.mutex->max_blocks, + osRtxConfig.mpi.mutex->block_size, + osRtxConfig.mpi.mutex->block_base) != 0U)) { + osRtxInfo.mpi.mutex = osRtxConfig.mpi.mutex; + } + if ((osRtxConfig.mpi.semaphore != NULL) && + (osRtxMemoryPoolInit(osRtxConfig.mpi.semaphore, + osRtxConfig.mpi.semaphore->max_blocks, + osRtxConfig.mpi.semaphore->block_size, + osRtxConfig.mpi.semaphore->block_base) != 0U)) { + osRtxInfo.mpi.semaphore = osRtxConfig.mpi.semaphore; + } + if ((osRtxConfig.mpi.memory_pool != NULL) && + (osRtxMemoryPoolInit(osRtxConfig.mpi.memory_pool, + osRtxConfig.mpi.memory_pool->max_blocks, + osRtxConfig.mpi.memory_pool->block_size, + osRtxConfig.mpi.memory_pool->block_base) != 0U)) { + osRtxInfo.mpi.memory_pool = osRtxConfig.mpi.memory_pool; + } + if ((osRtxConfig.mpi.message_queue != NULL) && + (osRtxMemoryPoolInit(osRtxConfig.mpi.message_queue, + osRtxConfig.mpi.message_queue->max_blocks, + osRtxConfig.mpi.message_queue->block_size, + osRtxConfig.mpi.message_queue->block_base) != 0U)) { + osRtxInfo.mpi.message_queue = osRtxConfig.mpi.message_queue; + } + +#if (__DOMAIN_NS == 1U) + // Initialize Secure Process Stack + if (TZ_InitContextSystem_S() == 0U) { + EvrRtxKernelError(osRtxErrorTZ_InitContext_S); + return osError; + } +#endif + + // Initialize SVC and PendSV System Service Calls + SVC_Initialize(); + + osRtxInfo.kernel.state = osRtxKernelReady; + + EvrRtxKernelInitializeCompleted(); + + return osOK; +} + +/// Get RTOS Kernel Information. +/// \note API identical to osKernelGetInfo +osStatus_t svcRtxKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size) { + + if (version != NULL) { + version->api = osRtxVersionAPI; + version->kernel = osRtxVersionKernel; + } + + if ((id_buf != NULL) && (id_size != 0U)) { + if (id_size > sizeof(osRtxKernelId)) { + id_size = sizeof(osRtxKernelId); + } + memcpy(id_buf, osRtxKernelId, id_size); + } + + EvrRtxKernelInfoRetrieved(version, id_buf); + + return osOK; +} + +/// Get the current RTOS Kernel state. +/// \note API identical to osKernelGetState +osKernelState_t svcRtxKernelGetState (void) { + EvrRtxKernelGetState((osKernelState_t)(osRtxInfo.kernel.state)); + return ((osKernelState_t)(osRtxInfo.kernel.state)); +} + +/// Start the RTOS Kernel scheduler. +/// \note API identical to osKernelStart +osStatus_t svcRtxKernelStart (void) { + os_thread_t *thread; + + if (osRtxInfo.kernel.state != osRtxKernelReady) { + EvrRtxKernelError(osRtxErrorKernelNotReady); + return osError; + } + + // Create Idle Thread + if (osRtxInfo.thread.idle == NULL) { + osRtxInfo.thread.idle = svcRtxThreadNew(osRtxIdleThread, NULL, osRtxConfig.idle_thread_attr, NULL); + if (osRtxInfo.thread.idle == NULL) { + EvrRtxKernelError(osError); + return osError; + } + } + + // Create Timer Thread + if (osRtxConfig.timer_mq_mcnt != 0U) { + if (osRtxInfo.timer.thread == NULL) { + osRtxInfo.timer.thread = svcRtxThreadNew(osRtxTimerThread, NULL, osRtxConfig.timer_thread_attr, NULL); + if (osRtxInfo.timer.thread == NULL) { + EvrRtxKernelError(osError); + return osError; + } + } + } + + // Switch to Ready Thread with highest Priority + thread = osRtxThreadListGet(&osRtxInfo.thread.ready); + if (thread == NULL) { + EvrRtxKernelError(osError); + return osError; + } + osRtxThreadSwitch(thread); + + if ((osRtxConfig.flags & osRtxConfigPrivilegedMode) != 0U) { + // Privileged Thread mode & PSP + __set_CONTROL(0x02U); + } else { + // Unprivileged Thread mode & PSP + __set_CONTROL(0x03U); + } + + osRtxInfo.kernel.sys_freq = SystemCoreClock; + + // Setup and Enable System Timer + osRtxInfo.tick_irqn = osRtxSysTimerSetup(); + if (osRtxInfo.tick_irqn >= 0) { + ExtTick_SetupIRQ (osRtxInfo.tick_irqn); + ExtTick_EnableIRQ(osRtxInfo.tick_irqn); + } + osRtxSysTimerEnable(); + + osRtxInfo.kernel.state = osRtxKernelRunning; + + EvrRtxKernelStarted(); + + return osOK; +} + +/// Lock the RTOS Kernel scheduler. +/// \note API identical to osKernelLock +int32_t svcRtxKernelLock (void) { + + if (osRtxInfo.kernel.state == osRtxKernelLocked) { + EvrRtxKernelLocked(1); + return 1; + } + if (osRtxInfo.kernel.state == osRtxKernelRunning) { + osRtxInfo.kernel.state = osRtxKernelLocked; + EvrRtxKernelLocked(0); + return 0; + } + + EvrRtxKernelError(osError); + return osError; +} + +/// Unlock the RTOS Kernel scheduler. +/// \note API identical to osKernelUnlock +int32_t svcRtxKernelUnlock (void) { + + if (osRtxInfo.kernel.state == osRtxKernelLocked) { + osRtxInfo.kernel.state = osRtxKernelRunning; + EvrRtxKernelUnlocked(1); + return 1; + } + if (osRtxInfo.kernel.state == osRtxKernelRunning) { + EvrRtxKernelUnlocked(0); + return 0; + } + + EvrRtxKernelError(osError); + return osError; +} + +/// Restore the RTOS Kernel scheduler lock state. +/// \note API identical to osKernelRestoreLock +int32_t svcRtxKernelRestoreLock (int32_t lock) { + + if ((osRtxInfo.kernel.state == osRtxKernelRunning) || + (osRtxInfo.kernel.state == osRtxKernelLocked)) { + switch (lock) { + case 1: + osRtxInfo.kernel.state = osRtxKernelLocked; + EvrRtxKernelLockRestored(1); + return 1; + case 0: + osRtxInfo.kernel.state = osRtxKernelRunning; + EvrRtxKernelLockRestored(0); + return 0; + default: + break; + } + } + + EvrRtxKernelError(osError); + return osError; +} + +/// Suspend the RTOS Kernel scheduler. +/// \note API identical to osKernelSuspend +uint32_t svcRtxKernelSuspend (void) { + os_thread_t *thread; + os_timer_t *timer; + uint32_t delay; + + if (osRtxInfo.kernel.state != osRtxKernelRunning) { + EvrRtxKernelError(osRtxErrorKernelNotRunning); + return 0U; + } + + KernelBlock(); + + delay = osWaitForever; + + // Check Thread Delay list + thread = osRtxInfo.thread.delay_list; + if (thread != NULL) { + delay = thread->delay; + } + + // Check Active Timer list + timer = osRtxInfo.timer.list; + if (timer != NULL) { + if (timer->tick < delay) { + delay = timer->tick; + } + } + + osRtxInfo.kernel.state = osRtxKernelSuspended; + + EvrRtxKernelSuspended(delay); + + return delay; +} + +/// Resume the RTOS Kernel scheduler. +/// \note API identical to osKernelResume +void svcRtxKernelResume (uint32_t sleep_ticks) { + os_thread_t *thread; + os_timer_t *timer; + uint32_t delay; + + if (osRtxInfo.kernel.state != osRtxKernelSuspended) { + EvrRtxKernelResumed(); + return; + } + + // Process Thread Delay list + thread = osRtxInfo.thread.delay_list; + if (thread != NULL) { + delay = sleep_ticks; + if (delay >= thread->delay) { + delay -= thread->delay; + osRtxInfo.kernel.tick += thread->delay; + thread->delay = 1U; + do { + osRtxThreadDelayTick(); + if (delay == 0U) { + break; + } + delay--; + osRtxInfo.kernel.tick++; + } while (osRtxInfo.thread.delay_list != NULL); + } else { + thread->delay -= delay; + osRtxInfo.kernel.tick += delay; + } + } else { + osRtxInfo.kernel.tick += sleep_ticks; + } + + // Process Active Timer list + timer = osRtxInfo.timer.list; + if (timer != NULL) { + if (sleep_ticks >= timer->tick) { + sleep_ticks -= timer->tick; + timer->tick = 1U; + do { + osRtxInfo.timer.tick(); + if (sleep_ticks == 0U) { + break; + } + sleep_ticks--; + } while (osRtxInfo.timer.list != NULL); + } else { + timer->tick -= sleep_ticks; + } + } + + osRtxInfo.kernel.state = osRtxKernelRunning; + + osRtxThreadDispatch(NULL); + + KernelUnblock(); + + EvrRtxKernelResumed(); +} + +/// Get the RTOS kernel tick count. +/// \note API identical to osKernelGetTickCount +uint64_t svcRtxKernelGetTickCount (void) { + EvrRtxKernelGetTickCount(osRtxInfo.kernel.tick); + return osRtxInfo.kernel.tick; +} + +/// Get the RTOS kernel tick frequency. +/// \note API identical to osKernelGetTickFreq +uint32_t svcRtxKernelGetTickFreq (void) { + EvrRtxKernelGetTickFreq(osRtxConfig.tick_freq); + return osRtxConfig.tick_freq; +} + +/// Get the RTOS kernel system timer count. +/// \note API identical to osKernelGetSysTimerCount +uint32_t svcRtxKernelGetSysTimerCount (void) { + uint32_t count = osRtxSysTimerGetCount(); + EvrRtxKernelGetSysTimerCount(count); + return count; +} + +/// Get the RTOS kernel system timer frequency. +/// \note API identical to osKernelGetSysTimerFreq +uint32_t svcRtxKernelGetSysTimerFreq (void) { + uint32_t freq = osRtxSysTimerGetFreq(); + EvrRtxKernelGetSysTimerFreq(freq); + return freq; +} + + +// ==== Public API ==== + +/// Initialize the RTOS Kernel. +osStatus_t osKernelInitialize (void) { + EvrRtxKernelInitialize(); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxKernelError(osErrorISR); + return osErrorISR; + } + return __svcKernelInitialize(); +} + +/// Get RTOS Kernel Information. +osStatus_t osKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size) { + EvrRtxKernelGetInfo(version, id_buf, id_size); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxKernelError(osErrorISR); + return osErrorISR; + } + if (IS_PRIVILEGED()) { + return svcRtxKernelGetInfo(version, id_buf, id_size); + } else { + return __svcKernelGetInfo(version, id_buf, id_size); + } +} + +/// Get the current RTOS Kernel state. +osKernelState_t osKernelGetState (void) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxKernelGetState(osKernelError); + return osKernelError; + } + if (IS_PRIVILEGED()) { + return svcRtxKernelGetState(); + } else { + return __svcKernelGetState(); + } +} + +/// Start the RTOS Kernel scheduler. +osStatus_t osKernelStart (void) { + EvrRtxKernelStart(); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxKernelError(osErrorISR); + return osErrorISR; + } + + /* Call the pre-start event (from unprivileged mode) if the handler exists + * and the kernel is not running. */ + /* FIXME osEventObs needs to be readable but not writable from unprivileged + * code. */ + if (osKernelGetState() != osKernelRunning && osEventObs && osEventObs->pre_start) { + osEventObs->pre_start(); + } + + return __svcKernelStart(); +} + +/// Lock the RTOS Kernel scheduler. +int32_t osKernelLock (void) { + EvrRtxKernelLock(); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxKernelError(osErrorISR); + return osErrorISR; + } + return __svcKernelLock(); +} + +/// Unlock the RTOS Kernel scheduler. +int32_t osKernelUnlock (void) { + EvrRtxKernelUnlock(); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxKernelError(osErrorISR); + return osErrorISR; + } + return __svcKernelUnlock(); +} + +/// Restore the RTOS Kernel scheduler lock state. +int32_t osKernelRestoreLock (int32_t lock) { + EvrRtxKernelRestoreLock(lock); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxKernelError(osErrorISR); + return osErrorISR; + } + return __svcKernelRestoreLock(lock); +} + +/// Suspend the RTOS Kernel scheduler. +uint32_t osKernelSuspend (void) { + EvrRtxKernelSuspend(); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxKernelError(osErrorISR); + return 0U; + } + return __svcKernelSuspend(); +} + +/// Resume the RTOS Kernel scheduler. +void osKernelResume (uint32_t sleep_ticks) { + EvrRtxKernelResume(sleep_ticks); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxKernelError(osErrorISR); + return; + } + __svcKernelResume(sleep_ticks); +} + +/// Get the RTOS kernel tick count. +uint64_t osKernelGetTickCount (void) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxKernelGetTickCount(0U); + return 0U; + } else { + return __svcKernelGetTickCount(); + } +} + +/// Get the RTOS kernel tick frequency. +uint32_t osKernelGetTickFreq (void) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxKernelGetTickFreq(0U); + return 0U; + } else { + return __svcKernelGetTickFreq(); + } +} + +/// Get the RTOS kernel system timer count. +uint32_t osKernelGetSysTimerCount (void) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + return svcRtxKernelGetSysTimerCount(); + } else { + return __svcKernelGetSysTimerCount(); + } +} + +/// Get the RTOS kernel system timer frequency. +uint32_t osKernelGetSysTimerFreq (void) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + return svcRtxKernelGetSysTimerFreq(); + } else { + return __svcKernelGetSysTimerFreq(); + } +} diff --git a/rtos/TARGET_CORTEX/rtx5/rtx_lib.c b/rtos/TARGET_CORTEX/rtx5/rtx_lib.c new file mode 100644 index 0000000..4a157e9 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/rtx_lib.c @@ -0,0 +1,634 @@ +/* + * Copyright (c) 2013-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * + * Project: CMSIS-RTOS RTX + * Title: RTX Library Configuration + * + * ----------------------------------------------------------------------------- + */ + +#include "cmsis_compiler.h" +#include "rtx_os.h" +#include "RTX_Config.h" + + +// System Configuration +// ==================== + +// Dynamic Memory +#if (OS_DYNAMIC_MEM_SIZE != 0) +#if ((OS_DYNAMIC_MEM_SIZE & 7) != 0) +#error "Invalid Dynamic Memory size!" +#endif +static uint64_t os_mem[OS_DYNAMIC_MEM_SIZE/8] \ +__attribute__((section(".bss.os"))); +#endif + +// Kernel Tick Frequency +#if (OS_TICK_FREQ < 1) +#error "Invalid Kernel Tick Frequency!" +#endif + +// ISR FIFO Queue +static void *os_isr_queue[OS_ISR_FIFO_QUEUE] \ +__attribute__((section(".bss.os"))); + + +// Thread Configuration +// ==================== + +#if (((OS_STACK_SIZE & 7) != 0) || (OS_STACK_SIZE < 72)) +#error "Invalid default Thread Stack size!" +#endif + +#if (((OS_IDLE_THREAD_STACK_SIZE & 7) != 0) || (OS_IDLE_THREAD_STACK_SIZE < 72)) +#error "Invalid Idle Thread Stack size!" +#endif + + +#if (OS_THREAD_OBJ_MEM != 0) + +#if (OS_THREAD_NUM == 0) +#error "Invalid number of user Threads!" +#endif + +#if ((OS_THREAD_USER_STACK_SIZE != 0) && ((OS_THREAD_USER_STACK_SIZE & 7) != 0)) +#error "Invalid total Stack size!" +#endif + +// Thread Control Blocks +static osRtxThread_t os_thread_cb[OS_THREAD_NUM] \ +__attribute__((section(".bss.os.thread.cb"))); + +// Thread Default Stack +#if (OS_THREAD_DEF_STACK_NUM != 0) +static uint64_t os_thread_def_stack[OS_THREAD_DEF_STACK_NUM*(OS_STACK_SIZE/8)] \ +__attribute__((section(".bss.os.thread.stack"))); +#endif + +// Memory Pool for Thread Control Blocks +static osRtxMpInfo_t os_mpi_thread \ +__attribute__((section(".data.os.thread.mpi"))) = +{ (uint32_t)OS_THREAD_NUM, 0U, (uint32_t)osRtxThreadCbSize, &os_thread_cb, NULL, NULL }; + +// Memory Pool for Thread Default Stack +#if (OS_THREAD_DEF_STACK_NUM != 0) +static osRtxMpInfo_t os_mpi_def_stack \ +__attribute__((section(".data.os.thread.mpi"))) = +{ (uint32_t)OS_THREAD_DEF_STACK_NUM, 0U, (uint32_t)OS_STACK_SIZE, &os_thread_def_stack, NULL, NULL }; +#endif + +// Memory Pool for Thread Stack +#if (OS_THREAD_USER_STACK_SIZE != 0) +static uint64_t os_thread_stack[OS_THREAD_USER_STACK_SIZE/8] \ +__attribute__((section(".bss.os.thread.stack"))); +#endif + +#endif // (OS_THREAD_OBJ_MEM != 0) + + +// Stack overrun checking +#if (OS_STACK_CHECK == 0) +// Override library function +void osRtxThreadStackCheck (void); +void osRtxThreadStackCheck (void) {} +#endif + + +// Idle Thread Control Block +static osRtxThread_t os_idle_thread_cb \ +__attribute__((section(".bss.os.thread.cb"))); + +// Idle Thread Stack +static uint64_t os_idle_thread_stack[OS_IDLE_THREAD_STACK_SIZE/8] \ +__attribute__((section(".bss.os.thread.stack"))); + +// Idle Thread Attributes +static const osThreadAttr_t os_idle_thread_attr = { + NULL, + osThreadDetached, + &os_idle_thread_cb, + (uint32_t)sizeof(os_idle_thread_cb), + &os_idle_thread_stack, + (uint32_t)sizeof(os_idle_thread_stack), + osPriorityIdle, + 0U, 0U +}; + + +// Timer Configuration +// =================== + +#if (OS_TIMER_OBJ_MEM != 0) + +#if (OS_TIMER_NUM == 0) +#error "Invalid number of Timer objects!" +#endif + +// Timer Control Blocks +static osRtxTimer_t os_timer_cb[OS_TIMER_NUM] \ +__attribute__((section(".bss.os.timer.cb"))); + +// Memory Pool for Timer Control Blocks +static osRtxMpInfo_t os_mpi_timer \ +__attribute__((section(".data.os.timer.mpi"))) = +{ (uint32_t)OS_TIMER_NUM, 0U, (uint32_t)osRtxTimerCbSize, &os_timer_cb, NULL, NULL }; + +#endif // (OS_TIMER_OBJ_MEM != 0) + + +#if ((OS_TIMER_THREAD_STACK_SIZE != 0) && (OS_TIMER_CB_QUEUE != 0)) + +#if (((OS_TIMER_THREAD_STACK_SIZE & 7) != 0) || (OS_TIMER_THREAD_STACK_SIZE < 96)) +#error "Invalid Timer Thread Stack size!" +#endif + +// Timer Thread Control Block +static osRtxThread_t os_timer_thread_cb \ +__attribute__((section(".bss.os.thread.cb"))); + +// Timer Thread Stack +static uint64_t os_timer_thread_stack[OS_TIMER_THREAD_STACK_SIZE/8] \ +__attribute__((section(".bss.os.thread.stack"))); + +// Timer Thread Attributes +static const osThreadAttr_t os_timer_thread_attr = { + NULL, + osThreadDetached, + &os_timer_thread_cb, + (uint32_t)sizeof(os_timer_thread_cb), + &os_timer_thread_stack, + (uint32_t)sizeof(os_timer_thread_stack), + (osPriority_t)OS_TIMER_THREAD_PRIO, + 0U, 0U +}; + +// Timer Message Queue Control Block +static osRtxMessageQueue_t os_timer_mq_cb \ +__attribute__((section(".bss.os.msgqueue.cb"))); + +// Timer Message Queue Data +static uint32_t os_timer_mq_data[osRtxMessageQueueMemSize(OS_TIMER_CB_QUEUE,8)/4] \ +__attribute__((section(".bss.os.msgqueue.mem"))); + +// Timer Message Queue Attributes +static const osMessageQueueAttr_t os_timer_mq_attr = { + NULL, + 0U, + &os_timer_mq_cb, + (uint32_t)sizeof(os_timer_mq_cb), + &os_timer_mq_data, + (uint32_t)sizeof(os_timer_mq_data) +}; + +#else + +extern void osRtxTimerThread (void *argument); + void osRtxTimerThread (void *argument) {} + +#endif // ((OS_TIMER_THREAD_STACK_SIZE != 0) && (OS_TIMER_CB_QUEUE != 0)) + + +// Event Flags Configuration +// ========================= + +#if (OS_EVFLAGS_OBJ_MEM != 0) + +#if (OS_EVFLAGS_NUM == 0) +#error "Invalid number of Event Flags objects!" +#endif + +// Event Flags Control Blocks +static osRtxEventFlags_t os_ef_cb[OS_EVFLAGS_NUM] \ +__attribute__((section(".bss.os.evflags.cb"))); + +// Memory Pool for Event Flags Control Blocks +static osRtxMpInfo_t os_mpi_ef \ +__attribute__((section(".data.os.evflags.mpi"))) = +{ (uint32_t)OS_EVFLAGS_NUM, 0U, (uint32_t)osRtxEventFlagsCbSize, &os_ef_cb, NULL, NULL }; + +#endif // (OS_EVFLAGS_OBJ_MEM != 0) + + +// Mutex Configuration +// =================== + +#if (OS_MUTEX_OBJ_MEM != 0) + +#if (OS_MUTEX_NUM == 0) +#error "Invalid number of Mutex objects!" +#endif + +// Mutex Control Blocks +static osRtxMutex_t os_mutex_cb[OS_MUTEX_NUM] \ +__attribute__((section(".bss.os.mutex.cb"))); + +// Memory Pool for Mutex Control Blocks +static osRtxMpInfo_t os_mpi_mutex \ +__attribute__((section(".data.os.mutex.mpi"))) = +{ (uint32_t)OS_MUTEX_NUM, 0U, (uint32_t)osRtxMutexCbSize, &os_mutex_cb, NULL, NULL }; + +#endif // (OS_MUTEX_OBJ_MEM != 0) + + +// Semaphore Configuration +// ======================= + +#if (OS_SEMAPHORE_OBJ_MEM != 0) + +#if (OS_SEMAPHORE_NUM == 0) +#error "Invalid number of Semaphore objects!" +#endif + +// Semaphore Control Blocks +static osRtxSemaphore_t os_semaphore_cb[OS_SEMAPHORE_NUM] \ +__attribute__((section(".bss.os.semaphore.cb"))); + +// Memory Pool for Semaphore Control Blocks +static osRtxMpInfo_t os_mpi_semaphore \ +__attribute__((section(".data.os.semaphore.mpi"))) = +{ (uint32_t)OS_SEMAPHORE_NUM, 0U, (uint32_t)osRtxSemaphoreCbSize, &os_semaphore_cb, NULL, NULL }; + +#endif // (OS_SEMAPHORE_OBJ_MEM != 0) + + +// Memory Pool Configuration +// ========================= + +#if (OS_MEMPOOL_OBJ_MEM != 0) + +#if (OS_MEMPOOL_NUM == 0) +#error "Invalid number of Memory Pool objects!" +#endif + +// Memory Pool Control Blocks +static osRtxMemoryPool_t os_mp_cb[OS_MEMPOOL_NUM] \ +__attribute__((section(".bss.os.mempool.cb"))); + +// Memory Pool for Memory Pool Control Blocks +static osRtxMpInfo_t os_mpi_mp \ +__attribute__((section(".data.os.mempool.mpi"))) = +{ (uint32_t)OS_MEMPOOL_NUM, 0U, (uint32_t)osRtxMemoryPoolCbSize, &os_mp_cb, NULL, NULL }; + +// Memory Pool for Memory Pool Data Storage +#if (OS_MEMPOOL_DATA_SIZE != 0) +#if ((OS_MEMPOOL_DATA_SIZE & 7) != 0) +#error "Invalid Data Memory size for Memory Pools!" +#endif +static uint64_t os_mp_data[OS_MEMPOOL_DATA_SIZE/8] \ +__attribute__((section(".bss.os.mempool.mem"))); +#endif + +#endif // (OS_MEMPOOL_OBJ_MEM != 0) + + +// Message Queue Configuration +// =========================== + +#if (OS_MSGQUEUE_OBJ_MEM != 0) + +#if (OS_MSGQUEUE_NUM == 0) +#error "Invalid number of Message Queue objects!" +#endif + +// Message Queue Control Blocks +static osRtxMessageQueue_t os_mq_cb[OS_MSGQUEUE_NUM] \ +__attribute__((section(".bss.os.msgqueue.cb"))); + +// Memory Pool for Message Queue Control Blocks +static osRtxMpInfo_t os_mpi_mq \ +__attribute__((section(".data.os.msgqueue.mpi"))) = +{ (uint32_t)OS_MSGQUEUE_NUM, 0U, (uint32_t)osRtxMessageQueueCbSize, &os_mq_cb, NULL, NULL }; + +// Memory Pool for Message Queue Data Storage +#if (OS_MSGQUEUE_DATA_SIZE != 0) +#if ((OS_MSGQUEUE_DATA_SIZE & 7) != 0) +#error "Invalid Data Memory size for Message Queues!" +#endif +static uint64_t os_mq_data[OS_MSGQUEUE_DATA_SIZE/8] \ +__attribute__((section(".bss.os.msgqueue.mem"))); +#endif + +#endif // (OS_MSGQUEUE_OBJ_MEM != 0) + + +// OS Configuration +// ================ + +__USED +__attribute__((section(".rodata"))) +const osRtxConfig_t osRtxConfig = { + 0U // Flags +#if (OS_PRIVILEGE_MODE != 0) + | osRtxConfigPrivilegedMode +#endif +#if (OS_STACK_CHECK != 0) + | osRtxConfigStackCheck +#endif +#if (OS_STACK_WATERMARK != 0) + | osRtxConfigStackWatermark +#endif + , + (uint32_t)OS_TICK_FREQ, +#if (OS_ROBIN_ENABLE != 0) + (uint32_t)OS_ROBIN_TIMEOUT, +#else + 0U, +#endif + { &os_isr_queue[0], sizeof(os_isr_queue)/sizeof(void *), 0U }, + { + // Memory Pools (Variable Block Size) +#if ((OS_THREAD_OBJ_MEM != 0) && (OS_THREAD_USER_STACK_SIZE != 0)) + &os_thread_stack, (uint32_t)OS_THREAD_USER_STACK_SIZE, +#else + NULL, 0U, +#endif +#if ((OS_MEMPOOL_OBJ_MEM != 0) && (OS_MEMPOOL_DATA_SIZE != 0)) + &os_mp_data, (uint32_t)OS_MEMPOOL_DATA_SIZE, +#else + NULL, 0U, +#endif +#if ((OS_MSGQUEUE_OBJ_MEM != 0) && (OS_MSGQUEUE_DATA_SIZE != 0)) + &os_mq_data, (uint32_t)OS_MSGQUEUE_DATA_SIZE, +#else + NULL, 0U, +#endif +#if (OS_DYNAMIC_MEM_SIZE != 0) + &os_mem, (uint32_t)OS_DYNAMIC_MEM_SIZE, +#else + NULL, 0U +#endif + }, + { + // Memory Pools (Fixed Block Size) +#if (OS_THREAD_OBJ_MEM != 0) +#if (OS_THREAD_DEF_STACK_NUM != 0) + &os_mpi_def_stack, +#else + NULL, +#endif + &os_mpi_thread, +#else + NULL, + NULL, +#endif +#if (OS_TIMER_OBJ_MEM != 0) + &os_mpi_timer, +#else + NULL, +#endif +#if (OS_EVFLAGS_OBJ_MEM != 0) + &os_mpi_ef, +#else + NULL, +#endif +#if (OS_MUTEX_OBJ_MEM != 0) + &os_mpi_mutex, +#else + NULL, +#endif +#if (OS_SEMAPHORE_OBJ_MEM != 0) + &os_mpi_semaphore, +#else + NULL, +#endif +#if (OS_MEMPOOL_OBJ_MEM != 0) + &os_mpi_mp, +#else + NULL, +#endif +#if (OS_MSGQUEUE_OBJ_MEM != 0) + &os_mpi_mq, +#else + NULL, +#endif + }, + (uint32_t)OS_STACK_SIZE, + &os_idle_thread_attr, +#if ((OS_TIMER_THREAD_STACK_SIZE != 0) && (OS_TIMER_CB_QUEUE != 0)) + &os_timer_thread_attr, + &os_timer_mq_attr, + (uint32_t)OS_TIMER_CB_QUEUE +#else + NULL, + NULL, + 0U +#endif +}; + + +// Non weak reference to library irq module +extern uint8_t irqRtxLib; +extern const uint8_t *irqRtxLibRef; + const uint8_t *irqRtxLibRef = &irqRtxLib; + +// Default User SVC Table +extern void * const osRtxUserSVC[]; +__WEAK void * const osRtxUserSVC[1] = { (void *)0 }; + + +// OS Sections +// =========== + +#if (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) +__asm ( + ".weakref __os_thread_cb_start__, .bss.os.thread.cb$$Base\n\t" + ".weakref __os_thread_cb_end__, .bss.os.thread.cb$$Limit\n\t" + ".weakref __os_timer_cb_start__, .bss.os.timer.cb$$Base\n\t" + ".weakref __os_timer_cb_end__, .bss.os.timer.cb$$Limit\n\t" + ".weakref __os_evflags_cb_start__, .bss.os.evflags.cb$$Base\n\t" + ".weakref __os_evflags_cb_end__, .bss.os.evflags.cb$$Limit\n\t" + ".weakref __os_mutex_cb_start__, .bss.os.mutex.cb$$Base\n\t" + ".weakref __os_mutex_cb_end__, .bss.os.mutex.cb$$Limit\n\t" + ".weakref __os_semaphore_cb_start__, .bss.os.semaphore.cb$$Base\n\t" + ".weakref __os_semaphore_cb_end__, .bss.os.semaphore.cb$$Limit\n\t" + ".weakref __os_mempool_cb_start__, .bss.os.mempool.cb$$Base\n\t" + ".weakref __os_mempool_cb_end__, .bss.os.mempool.cb$$Limit\n\t" + ".weakref __os_msgqueue_cb_start__, .bss.os.msgqueue.cb$$Base\n\t" + ".weakref __os_msgqueue_cb_end__, .bss.os.msgqueue.cb$$Limit\n\t" +); +#endif + +#if (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) || \ + (defined(__GNUC__) && !defined(__CC_ARM)) + +extern __attribute__((weak)) uint32_t __os_thread_cb_start__; +extern __attribute__((weak)) uint32_t __os_thread_cb_end__; +extern __attribute__((weak)) uint32_t __os_timer_cb_start__; +extern __attribute__((weak)) uint32_t __os_timer_cb_end__; +extern __attribute__((weak)) uint32_t __os_evflags_cb_start__; +extern __attribute__((weak)) uint32_t __os_evflags_cb_end__; +extern __attribute__((weak)) uint32_t __os_mutex_cb_start__; +extern __attribute__((weak)) uint32_t __os_mutex_cb_end__; +extern __attribute__((weak)) uint32_t __os_semaphore_cb_start__; +extern __attribute__((weak)) uint32_t __os_semaphore_cb_end__; +extern __attribute__((weak)) uint32_t __os_mempool_cb_start__; +extern __attribute__((weak)) uint32_t __os_mempool_cb_end__; +extern __attribute__((weak)) uint32_t __os_msgqueue_cb_start__; +extern __attribute__((weak)) uint32_t __os_msgqueue_cb_end__; + +__asm (".global os_cb_sections"); + +extern const uint32_t os_cb_sections[]; + +__attribute__((section(".rodata"))) +const uint32_t os_cb_sections[] = { + (uint32_t)&__os_thread_cb_start__, + (uint32_t)&__os_thread_cb_end__, + (uint32_t)&__os_timer_cb_start__, + (uint32_t)&__os_timer_cb_end__, + (uint32_t)&__os_evflags_cb_start__, + (uint32_t)&__os_evflags_cb_end__, + (uint32_t)&__os_mutex_cb_start__, + (uint32_t)&__os_mutex_cb_end__, + (uint32_t)&__os_semaphore_cb_start__, + (uint32_t)&__os_semaphore_cb_end__, + (uint32_t)&__os_mempool_cb_start__, + (uint32_t)&__os_mempool_cb_end__, + (uint32_t)&__os_msgqueue_cb_start__, + (uint32_t)&__os_msgqueue_cb_end__ +}; + +#endif + + +// OS Initialization +// ================= + +#if defined(__CC_ARM) || \ + (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) + +#ifndef __MICROLIB +extern void _platform_post_stackheap_init (void); +__WEAK void _platform_post_stackheap_init (void) { + osKernelInitialize(); +} +#endif + +#elif defined(__GNUC__) + +extern void software_init_hook (void); +__WEAK void software_init_hook (void) { + osKernelInitialize(); +} + +#endif + + +// C/C++ Standard Library Multithreading Interface +// =============================================== + +#if (( defined(__CC_ARM) || \ + (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050))) && \ + !defined(__MICROLIB)) + +#define LIBSPACE_SIZE 96 + +// Memory for libspace +static uint32_t os_libspace[OS_THREAD_LIBSPACE_NUM+1][LIBSPACE_SIZE/sizeof(uint32_t)] \ +__attribute__((section(".bss.os"))); + +// Thread IDs for libspace +static osThreadId_t os_libspace_id[OS_THREAD_LIBSPACE_NUM] \ +__attribute__((section(".bss.os"))); + +// Check if Kernel has been started +static uint32_t os_kernel_is_active (void) { + static uint8_t os_kernel_active = 0U; + + if (os_kernel_active == 0U) { + if (osKernelGetState() > osKernelReady) { + os_kernel_active = 1U; + return 1U; + } + return 0U; + } else { + return 1U; + } +} + +// Provide libspace for current thread +void *__user_perthread_libspace (void); +void *__user_perthread_libspace (void) { + osThreadId_t id; + uint32_t n; + + if (!os_kernel_is_active()) { + return (void *)&os_libspace[OS_THREAD_LIBSPACE_NUM][0]; + } + + id = osThreadGetId(); + for (n = 0U; n < OS_THREAD_LIBSPACE_NUM; n++) { + if (os_libspace_id[n] == NULL) { + os_libspace_id[n] = id; + return (void *)&os_libspace[n][0]; + } + if (os_libspace_id[n] == id) { + return (void *)&os_libspace[n][0]; + } + } + + if (n == OS_THREAD_LIBSPACE_NUM) { + osRtxErrorNotify(osRtxErrorClibSpace, id); + } + + return (void *)&os_libspace[n][0]; +} + +// Mutex identifier +typedef void *mutex; + +// Initialize mutex +__USED +int _mutex_initialize(mutex *m); +__WEAK int _mutex_initialize(mutex *m) { + *m = osMutexNew(NULL); + if (*m == NULL) { + osRtxErrorNotify(osRtxErrorClibMutex, m); + return 0; + } + return 1; +} + +// Acquire mutex +__USED +void _mutex_acquire(mutex *m); +__WEAK void _mutex_acquire(mutex *m) { + if (os_kernel_is_active()) { + osMutexAcquire(*m, osWaitForever); + } +} + +// Release mutex +__USED +void _mutex_release(mutex *m); +__WEAK void _mutex_release(mutex *m) { + if (os_kernel_is_active()) { + osMutexRelease(*m); + } +} + +// Free mutex +__USED +void _mutex_free(mutex *m); +__WEAK void _mutex_free(mutex *m) { + osMutexDelete(*m); +} + +#endif diff --git a/rtos/TARGET_CORTEX/rtx5/rtx_lib.h b/rtos/TARGET_CORTEX/rtx5/rtx_lib.h new file mode 100644 index 0000000..fb7423d --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/rtx_lib.h @@ -0,0 +1,216 @@ +/** \addtogroup rtos */ +/** @{*/ +/* + * Copyright (c) 2013-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * + * Project: CMSIS-RTOS RTX + * Title: RTX Library definitions + * + * ----------------------------------------------------------------------------- + */ + +#ifndef RTX_LIB_H_ +#define RTX_LIB_H_ + +#include +#include +#include "core_cm.h" // Cortex-M definitions +#include "tz_context.h" // TrustZone Context API +#include "cmsis_os2.h" // CMSIS RTOS API +#include "rtx_os.h" // RTX OS definitions +#include "rtx_evr.h" // RTX Event Recorder definitions + + +// ==== Library defines ==== + +#define os_thread_t osRtxThread_t +#define os_timer_t osRtxTimer_t +#define os_timer_finfo_t osRtxTimerFinfo_t +#define os_event_flags_t osRtxEventFlags_t +#define os_mutex_t osRtxMutex_t +#define os_semaphore_t osRtxSemaphore_t +#define os_mp_info_t osRtxMpInfo_t +#define os_memory_pool_t osRtxMemoryPool_t +#define os_message_t osRtxMessage_t +#define os_message_queue_t osRtxMessageQueue_t +#define os_object_t osRtxObject_t + +// ==== Inline functions ==== + +// Kernel Inline functions +__STATIC_INLINE uint8_t osRtxKernelGetState (void) { return osRtxInfo.kernel.state; } + +// Thread Inline functions +__STATIC_INLINE os_thread_t *osRtxThreadGetRunning (void) { return osRtxInfo.thread.run.curr; } +__STATIC_INLINE void osRtxThreadSetRunning (os_thread_t *thread) { osRtxInfo.thread.run.curr = thread; } + + +// ==== Library functions ==== + +// Thread Library functions +extern void osRtxThreadListPut (volatile os_object_t *object, os_thread_t *thread); +extern os_thread_t *osRtxThreadListGet (volatile os_object_t *object); +extern void *osRtxThreadListRoot (os_thread_t *thread); +extern void osRtxThreadListSort (os_thread_t *thread); +extern void osRtxThreadListRemove (os_thread_t *thread); +extern void osRtxThreadListUnlink (os_thread_t **thread_list, os_thread_t *thread); +extern void osRtxThreadReadyPut (os_thread_t *thread); +extern void osRtxThreadDelayInsert (os_thread_t *thread, uint32_t delay); +extern void osRtxThreadDelayRemove (os_thread_t *thread); +extern void osRtxThreadDelayTick (void); +extern uint32_t *osRtxThreadRegPtr (os_thread_t *thread); +extern void osRtxThreadBlock (os_thread_t *thread); +extern void osRtxThreadSwitch (os_thread_t *thread); +extern void osRtxThreadDispatch (os_thread_t *thread); +extern void osRtxThreadWaitExit (os_thread_t *thread, uint32_t ret_val, bool dispatch); +extern bool osRtxThreadWaitEnter (uint8_t state, uint32_t timeout); +extern void osRtxThreadStackCheck (void); + +// Timer Library functions +extern void osRtxTimerTick (void); +extern void osRtxTimerThread (void *argument); + +// Mutex Library functions +extern void osRtxMutexOwnerRelease (os_mutex_t *mutex_list); + +// Memory Heap Library functions +extern uint32_t osRtxMemoryInit (void *mem, uint32_t size); +extern void *osRtxMemoryAlloc(void *mem, uint32_t size, uint32_t type); +extern uint32_t osRtxMemoryFree (void *mem, void *block); + +// Memory Pool Library functions +extern uint32_t osRtxMemoryPoolInit (os_mp_info_t *mp_info, uint32_t blocks, uint32_t block_size, void *block_mem); +extern void *osRtxMemoryPoolAlloc (os_mp_info_t *mp_info); +extern osStatus_t osRtxMemoryPoolFree (os_mp_info_t *mp_info, void *block); + +// System Library functions +extern void osRtxTick_Handler (void); +extern void osRtxPendSV_Handler (void); +extern void osRtxPostProcess (os_object_t *object); + +// Post ISR processing functions +extern void osRtxThreadPostProcess (os_thread_t *thread); +extern void osRtxEventFlagsPostProcess (os_event_flags_t *ef); +extern void osRtxSemaphorePostProcess (os_semaphore_t *semaphore); +extern void osRtxMemoryPoolPostProcess (os_memory_pool_t *mp); +extern void osRtxMessageQueuePostProcess (os_message_t *msg); + + +// ==== Service Calls ==== + +// Kernel Service Calls +extern osStatus_t svcRtxKernelInitialize (void); +extern osStatus_t svcRtxKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size); +extern osKernelState_t svcRtxKernelGetState (void); +extern osStatus_t svcRtxKernelStart (void); +extern int32_t svcRtxKernelLock (void); +extern int32_t svcRtxKernelUnlock (void); +extern int32_t svcRtxKernelRestoreLock (int32_t lock); +extern uint32_t svcRtxKernelSuspend (void); +extern void svcRtxKernelResume (uint32_t sleep_ticks); +extern uint64_t svcRtxKernelGetTickCount (void); +extern uint32_t svcRtxKernelGetTickFreq (void); +extern uint32_t svcRtxKernelGetSysTimerCount (void); +extern uint32_t svcRtxKernelGetSysTimerFreq (void); + +// Thread Service Calls +extern osThreadId_t svcRtxThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr, void *context); +extern const char * svcRtxThreadGetName (osThreadId_t thread_id); +extern osThreadId_t svcRtxThreadGetId (void); +extern osThreadState_t svcRtxThreadGetState (osThreadId_t thread_id); +extern uint32_t svcRtxThreadGetStackSize (osThreadId_t thread_id); +extern uint32_t svcRtxThreadGetStackSpace(osThreadId_t thread_id); +extern osStatus_t svcRtxThreadSetPriority (osThreadId_t thread_id, osPriority_t priority); +extern osPriority_t svcRtxThreadGetPriority (osThreadId_t thread_id); +extern osStatus_t svcRtxThreadYield (void); +extern osStatus_t svcRtxThreadSuspend (osThreadId_t thread_id); +extern osStatus_t svcRtxThreadResume (osThreadId_t thread_id); +extern osStatus_t svcRtxThreadDetach (osThreadId_t thread_id); +extern osStatus_t svcRtxThreadJoin (osThreadId_t thread_id); +extern void svcRtxThreadExit (void); +extern osStatus_t svcRtxThreadTerminate (osThreadId_t thread_id); +extern uint32_t svcRtxThreadGetCount (void); +extern uint32_t svcRtxThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items); +extern uint32_t svcRtxThreadFlagsSet (osThreadId_t thread_id, uint32_t flags); +extern uint32_t svcRtxThreadFlagsClear (uint32_t flags); +extern uint32_t svcRtxThreadFlagsGet (void); +extern uint32_t svcRtxThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout); + +// Delay Service Calls +extern osStatus_t svcRtxDelay (uint32_t ticks); +extern osStatus_t svcRtxDelayUntil (uint32_t ticks_l, uint32_t ticks_h); + +// Timer Service Calls +extern osTimerId_t svcRtxTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr); +extern const char * svcRtxTimerGetName (osTimerId_t timer_id); +extern osStatus_t svcRtxTimerStart (osTimerId_t timer_id, uint32_t ticks); +extern osStatus_t svcRtxTimerStop (osTimerId_t timer_id); +extern uint32_t svcRtxTimerIsRunning (osTimerId_t timer_id); +extern osStatus_t svcRtxTimerDelete (osTimerId_t timer_id); + +// Event Flags Service Calls +extern osEventFlagsId_t svcRtxEventFlagsNew (const osEventFlagsAttr_t *attr); +extern const char * svcRtxEventFlagsGetName (osEventFlagsId_t ef_id); +extern uint32_t svcRtxEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags); +extern uint32_t svcRtxEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags); +extern uint32_t svcRtxEventFlagsGet (osEventFlagsId_t ef_id); +extern uint32_t svcRtxEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout); +extern osStatus_t svcRtxEventFlagsDelete (osEventFlagsId_t ef_id); + +// Mutex Service Calls +extern osMutexId_t svcRtxMutexNew (const osMutexAttr_t *attr); +extern const char * svcRtxMutexGetName (osMutexId_t mutex_id); +extern osStatus_t svcRtxMutexAcquire (osMutexId_t mutex_id, uint32_t timeout); +extern osStatus_t svcRtxMutexRelease (osMutexId_t mutex_id); +extern osThreadId_t svcRtxMutexGetOwner (osMutexId_t mutex_id); +extern osStatus_t svcRtxMutexDelete (osMutexId_t mutex_id); + +// Semaphore Service Calls +extern osSemaphoreId_t svcRtxSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr); +extern const char * svcRtxSemaphoreGetName (osSemaphoreId_t semaphore_id); +extern osStatus_t svcRtxSemaphoreRelease (osSemaphoreId_t semaphore_id); +extern osStatus_t svcRtxSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout); +extern uint32_t svcRtxSemaphoreGetCount(osSemaphoreId_t semaphore_id); +extern osStatus_t svcRtxSemaphoreDelete (osSemaphoreId_t semaphore_id); + +// Memory Pool Service Calls +extern osMemoryPoolId_t svcRtxMemoryPoolNew (uint32_t blocks, uint32_t block_size, const osMemoryPoolAttr_t *attr); +extern const char * svcRtxMemoryPoolGetName (osMemoryPoolId_t mp_id); +extern void * svcRtxMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout); +extern osStatus_t svcRtxMemoryPoolFree (osMemoryPoolId_t mp_id, void *block); +extern uint32_t svcRtxMemoryPoolGetCapacity (osMemoryPoolId_t mp_id); +extern uint32_t svcRtxMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id); +extern uint32_t svcRtxMemoryPoolGetCount (osMemoryPoolId_t mp_id); +extern uint32_t svcRtxMemoryPoolGetSpace (osMemoryPoolId_t mp_id); +extern osStatus_t svcRtxMemoryPoolDelete (osMemoryPoolId_t mp_id); + +// Message Queue Service Calls +extern osMessageQueueId_t svcRtxMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr); +extern const char * svcRtxMessageQueueGetName (osMessageQueueId_t mq_id); +extern osStatus_t svcRtxMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout); +extern osStatus_t svcRtxMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout); +extern uint32_t svcRtxMessageQueueGetCapacity (osMessageQueueId_t mq_id); +extern uint32_t svcRtxMessageQueueGetMsgSize (osMessageQueueId_t mq_id); +extern uint32_t svcRtxMessageQueueGetCount (osMessageQueueId_t mq_id); +extern uint32_t svcRtxMessageQueueGetSpace (osMessageQueueId_t mq_id); +extern osStatus_t svcRtxMessageQueueReset (osMessageQueueId_t mq_id); +extern osStatus_t svcRtxMessageQueueDelete (osMessageQueueId_t mq_id); + +#endif // RTX_LIB_H_ +/** @}*/ diff --git a/rtos/TARGET_CORTEX/rtx5/rtx_memory.c b/rtos/TARGET_CORTEX/rtx5/rtx_memory.c new file mode 100644 index 0000000..f86e802 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/rtx_memory.c @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2013-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * + * Project: CMSIS-RTOS RTX + * Title: Memory functions + * + * ----------------------------------------------------------------------------- + */ + +#include "rtx_lib.h" + + +// Memory Pool Header structure +typedef struct mem_head_s { + uint32_t size; // Memory Pool size + uint32_t used; // Used Memory +} mem_head_t; + +// Memory Block Header structure +typedef struct mem_block_s { + struct mem_block_s *next; // Next Memory Block in list + uint32_t info; // Info: length = <31:2>:'00', type = <1:0> +} mem_block_t; + +#define MB_INFO_LEN_MASK 0xFFFFFFFCU +#define MB_INFO_TYPE_MASK 0x00000003U + + +// ==== Library functions ==== + +/// Initialize Memory Pool with variable block size. +/// \param[in] mem pointer to memory pool. +/// \param[in] size size of a memory pool in bytes. +/// \return 1 - success, 0 - failure. +__WEAK uint32_t osRtxMemoryInit (void *mem, uint32_t size) { + mem_head_t *head; + mem_block_t *ptr; + + if ((mem == NULL) || ((uint32_t)mem & 7U) || (size & 7U) || + (size < (sizeof(mem_head_t) + 2*sizeof(mem_block_t)))) { + EvrRtxMemoryInit(mem, size, 0U); + return 0U; + } + + head = (mem_head_t *)mem; + head->size = size; + head->used = sizeof(mem_head_t) + sizeof(mem_block_t); + + ptr = (mem_block_t *)((uint32_t)mem + sizeof(mem_head_t)); + ptr->next = (mem_block_t *)((uint32_t)mem + size - sizeof(mem_block_t)); + ptr->next->next = NULL; + ptr->info = 0U; + + EvrRtxMemoryInit(mem, size, 1U); + + return 1U; +} + +/// Allocate a memory block from a Memory Pool. +/// \param[in] mem pointer to memory pool. +/// \param[in] size size of a memory block in bytes. +/// \param[in] type memory block type: 0 - generic, 1 - control block +/// \return allocated memory block or NULL in case of no memory is available. +__WEAK void *osRtxMemoryAlloc (void *mem, uint32_t size, uint32_t type) { + mem_block_t *p, *p_new, *ptr; + uint32_t hole_size; + + if ((mem == NULL) || (size == 0U) || (type & ~MB_INFO_TYPE_MASK)) { + EvrRtxMemoryAlloc(mem, size, type, NULL); + return NULL; + } + + // Add header to size + size += sizeof(mem_block_t); + // Make sure that block is 8-byte aligned + size = (size + 7U) & ~((uint32_t)7U); + + // Search for hole big enough + p = (mem_block_t *)((uint32_t)mem + sizeof(mem_head_t)); + for (;;) { + hole_size = (uint32_t)p->next - (uint32_t)p; + hole_size -= p->info & MB_INFO_LEN_MASK; + if (hole_size >= size) { + // Hole found + break; + } + p = p->next; + if (p->next == NULL) { + // Failed (end of list) + EvrRtxMemoryAlloc(mem, size, type, NULL); + return NULL; + } + } + + ((mem_head_t *)mem)->used += size; + + if (p->info == 0U) { + // No block allocated, set info of first element + p->info = size | type; + ptr = (mem_block_t *)((uint32_t)p + sizeof(mem_block_t)); + } else { + // Insert new element into the list + p_new = (mem_block_t *)((uint32_t)p + (p->info & MB_INFO_LEN_MASK)); + p_new->next = p->next; + p_new->info = size | type; + p->next = p_new; + ptr = (mem_block_t *)((uint32_t)p_new + sizeof(mem_block_t)); + } + + EvrRtxMemoryAlloc(mem, size, type, ptr); + + return ptr; +} + +/// Return an allocated memory block back to a Memory Pool. +/// \param[in] mem pointer to memory pool. +/// \param[in] block memory block to be returned to the memory pool. +/// \return 1 - success, 0 - failure. +__WEAK uint32_t osRtxMemoryFree (void *mem, void *block) { + mem_block_t *p, *p_prev, *ptr; + + if ((mem == NULL) || (block == NULL)) { + EvrRtxMemoryFree(mem, block, 0U); + return 0U; + } + + ptr = (mem_block_t *)((uint32_t)block - sizeof(mem_block_t)); + + // Search for header + p_prev = NULL; + p = (mem_block_t *)((uint32_t)mem + sizeof(mem_head_t)); + while (p != ptr) { + p_prev = p; + p = p->next; + if (p == NULL) { + // Not found + EvrRtxMemoryFree(mem, block, 0U); + return 0U; + } + } + + ((mem_head_t *)mem)->used -= p->info & MB_INFO_LEN_MASK; + + if (p_prev == NULL) { + // Release first block, only set info to 0 + p->info = 0U; + } else { + // Discard block from chained list + p_prev->next = p->next; + } + + EvrRtxMemoryFree(mem, block, 1U); + + return 1U; +} diff --git a/rtos/TARGET_CORTEX/rtx5/rtx_mempool.c b/rtos/TARGET_CORTEX/rtx5/rtx_mempool.c new file mode 100644 index 0000000..63bb32a --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/rtx_mempool.c @@ -0,0 +1,685 @@ +/* + * Copyright (c) 2013-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * + * Project: CMSIS-RTOS RTX + * Title: Memory Pool functions + * + * ----------------------------------------------------------------------------- + */ + +#include "rtx_lib.h" + + +// ==== Library functions ==== + +/// Initialize Memory Pool. +/// \param[in] mp_info memory pool info. +/// \param[in] block_count maximum number of memory blocks in memory pool. +/// \param[in] block_size size of a memory block in bytes. +/// \param[in] block_mem pointer to memory for block storage. +/// \return 1 - success, 0 - failure. +uint32_t osRtxMemoryPoolInit (os_mp_info_t *mp_info, uint32_t block_count, uint32_t block_size, void *block_mem) { + void *block; + + // Check parameters + if ((mp_info == NULL) || (block_count == 0U) || (block_size == 0U) || (block_mem == NULL)) { + return 0U; + } + + // Initialize information structure + mp_info->max_blocks = block_count; + mp_info->used_blocks = 0U; + mp_info->block_size = block_size; + mp_info->block_base = block_mem; + mp_info->block_free = block_mem; + mp_info->block_lim = (uint8_t *)block_mem + (block_count * block_size); + + EvrRtxMemoryBlockInit(mp_info, block_count, block_size, block_mem); + + // Link all free blocks + while (--block_count) { + block = (uint8_t *)block_mem + block_size; + *((void **)block_mem) = block; + block_mem = block; + } + *((void **)block_mem) = NULL; + + return 1U; +} + +/// Allocate a memory block from a Memory Pool. +/// \param[in] mp_info memory pool info. +/// \return address of the allocated memory block or NULL in case of no memory is available. +void *osRtxMemoryPoolAlloc (os_mp_info_t *mp_info) { +#if (__EXCLUSIVE_ACCESS == 0U) + uint32_t primask = __get_PRIMASK(); +#endif + void *block; + + if (mp_info == NULL) { + EvrRtxMemoryBlockAlloc(NULL, NULL); + return NULL; + } + +#if (__EXCLUSIVE_ACCESS == 0U) + __disable_irq(); + + if (mp_info->used_blocks < mp_info->max_blocks) { + mp_info->used_blocks++; + block = mp_info->block_free; + if (block != NULL) { + mp_info->block_free = *((void **)block); + } + } else { + block = NULL; + } + + if (primask == 0U) { + __enable_irq(); + } +#else + if (atomic_inc32_lt(&mp_info->used_blocks, mp_info->max_blocks) < mp_info->max_blocks) { + block = atomic_link_get(&mp_info->block_free); + } else { + block = NULL; + } +#endif + + EvrRtxMemoryBlockAlloc(mp_info, block); + + return block; +} + +/// Return an allocated memory block back to a Memory Pool. +/// \param[in] mp_info memory pool info. +/// \param[in] block address of the allocated memory block to be returned to the memory pool. +/// \return status code that indicates the execution status of the function. +osStatus_t osRtxMemoryPoolFree (os_mp_info_t *mp_info, void *block) { +#if (__EXCLUSIVE_ACCESS == 0U) + uint32_t primask = __get_PRIMASK(); +#endif + osStatus_t status; + + if ((mp_info == NULL) || (block < mp_info->block_base) || (block >= mp_info->block_lim)) { + EvrRtxMemoryBlockFree(mp_info, block, osErrorParameter); + return osErrorParameter; + } + +#if (__EXCLUSIVE_ACCESS == 0U) + __disable_irq(); + + if (mp_info->used_blocks != 0U) { + mp_info->used_blocks--; + *((void **)block) = mp_info->block_free; + mp_info->block_free = block; + status = osOK; + } else { + status = osErrorResource; + } + + if (primask == 0U) { + __enable_irq(); + } +#else + if (atomic_dec32_nz(&mp_info->used_blocks) != 0U) { + atomic_link_put(&mp_info->block_free, block); + status = osOK; + } else { + status = osErrorResource; + } +#endif + + EvrRtxMemoryBlockFree(mp_info, block, status); + + return status; +} + +/// Memory Pool post ISR processing. +/// \param[in] mp memory pool object. +void osRtxMemoryPoolPostProcess (os_memory_pool_t *mp) { + void *block; + os_thread_t *thread; + + if (mp->state == osRtxObjectInactive) { + return; + } + + // Check if Thread is waiting to allocate memory + if (mp->thread_list != NULL) { + // Allocate memory + block = osRtxMemoryPoolAlloc(&mp->mp_info); + if (block != NULL) { + // Wakeup waiting Thread with highest Priority + thread = osRtxThreadListGet((os_object_t*)mp); + osRtxThreadWaitExit(thread, (uint32_t)block, false); + EvrRtxMemoryPoolAllocated(mp, block); + } + } +} + + +// ==== Service Calls ==== + +// Service Calls definitions +SVC0_3M(MemoryPoolNew, osMemoryPoolId_t, uint32_t, uint32_t, const osMemoryPoolAttr_t *) +SVC0_1 (MemoryPoolGetName, const char *, osMemoryPoolId_t) +SVC0_2 (MemoryPoolAlloc, void *, osMemoryPoolId_t, uint32_t) +SVC0_2 (MemoryPoolFree, osStatus_t, osMemoryPoolId_t, void *) +SVC0_1 (MemoryPoolGetCapacity, uint32_t, osMemoryPoolId_t) +SVC0_1 (MemoryPoolGetBlockSize, uint32_t, osMemoryPoolId_t) +SVC0_1 (MemoryPoolGetCount, uint32_t, osMemoryPoolId_t) +SVC0_1 (MemoryPoolGetSpace, uint32_t, osMemoryPoolId_t) +SVC0_1 (MemoryPoolDelete, osStatus_t, osMemoryPoolId_t) + +/// Create and Initialize a Memory Pool object. +/// \note API identical to osMemoryPoolNew +osMemoryPoolId_t svcRtxMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr) { + os_memory_pool_t *mp; + void *mp_mem; + uint32_t mp_size; + uint32_t size; + uint8_t flags; + const char *name; + + // Check parameters + if ((block_count == 0U) || (block_size == 0U)) { + EvrRtxMemoryPoolError(NULL, osErrorParameter); + return NULL; + } + block_size = (block_size + 3U) & ~3UL; + if ((__CLZ(block_count) + __CLZ(block_size)) < 32) { + EvrRtxMemoryPoolError(NULL, osErrorParameter); + return NULL; + } + + size = block_count * block_size; + + // Process attributes + if (attr != NULL) { + name = attr->name; + mp = attr->cb_mem; + mp_mem = attr->mp_mem; + mp_size = attr->mp_size; + if (mp != NULL) { + if (((uint32_t)mp & 3U) || (attr->cb_size < sizeof(os_memory_pool_t))) { + EvrRtxMemoryPoolError(NULL, osRtxErrorInvalidControlBlock); + return NULL; + } + } else { + if (attr->cb_size != 0U) { + EvrRtxMemoryPoolError(NULL, osRtxErrorInvalidControlBlock); + return NULL; + } + } + if (mp_mem != NULL) { + if (((uint32_t)mp_mem & 3U) || (mp_size < size)) { + EvrRtxMemoryPoolError(NULL, osRtxErrorInvalidDataMemory); + return NULL; + } + } else { + if (mp_size != 0U) { + EvrRtxMemoryPoolError(NULL, osRtxErrorInvalidDataMemory); + return NULL; + } + } + } else { + name = NULL; + mp = NULL; + mp_mem = NULL; + } + + // Allocate object memory if not provided + if (mp == NULL) { + if (osRtxInfo.mpi.memory_pool != NULL) { + mp = osRtxMemoryPoolAlloc(osRtxInfo.mpi.memory_pool); + } else { + mp = osRtxMemoryAlloc(osRtxInfo.mem.common, sizeof(os_memory_pool_t), 1U); + } + if (mp == NULL) { + EvrRtxMemoryPoolError(NULL, osErrorNoMemory); + return NULL; + } + flags = osRtxFlagSystemObject; + } else { + flags = 0U; + } + + // Allocate data memory if not provided + if (mp_mem == NULL) { + mp_mem = osRtxMemoryAlloc(osRtxInfo.mem.mp_data, size, 0U); + if (mp_mem == NULL) { + EvrRtxMemoryPoolError(NULL, osErrorNoMemory); + if (flags & osRtxFlagSystemObject) { + if (osRtxInfo.mpi.memory_pool != NULL) { + osRtxMemoryPoolFree(osRtxInfo.mpi.memory_pool, mp); + } else { + osRtxMemoryFree(osRtxInfo.mem.common, mp); + } + } + return NULL; + } + memset(mp_mem, 0, size); + flags |= osRtxFlagSystemMemory; + } + + // Initialize control block + mp->id = osRtxIdMemoryPool; + mp->state = osRtxObjectActive; + mp->flags = flags; + mp->name = name; + mp->thread_list = NULL; + osRtxMemoryPoolInit(&mp->mp_info, block_count, block_size, mp_mem); + + // Register post ISR processing function + osRtxInfo.post_process.memory_pool = osRtxMemoryPoolPostProcess; + + EvrRtxMemoryPoolCreated(mp); + + return mp; +} + +/// Get name of a Memory Pool object. +/// \note API identical to osMemoryPoolGetName +const char *svcRtxMemoryPoolGetName (osMemoryPoolId_t mp_id) { + os_memory_pool_t *mp = (os_memory_pool_t *)mp_id; + + // Check parameters + if ((mp == NULL) || (mp->id != osRtxIdMemoryPool)) { + EvrRtxMemoryPoolGetName(mp, NULL); + return NULL; + } + + // Check object state + if (mp->state == osRtxObjectInactive) { + EvrRtxMemoryPoolGetName(mp, NULL); + return NULL; + } + + EvrRtxMemoryPoolGetName(mp, mp->name); + + return mp->name; +} + +/// Allocate a memory block from a Memory Pool. +/// \note API identical to osMemoryPoolAlloc +void *svcRtxMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout) { + os_memory_pool_t *mp = (os_memory_pool_t *)mp_id; + void *block; + + // Check parameters + if ((mp == NULL) || (mp->id != osRtxIdMemoryPool)) { + EvrRtxMemoryPoolError(mp, osErrorParameter); + return NULL; + } + + // Check object state + if (mp->state == osRtxObjectInactive) { + EvrRtxMemoryPoolError(mp, osErrorResource); + return NULL; + } + + // Allocate memory + block = osRtxMemoryPoolAlloc(&mp->mp_info); + if (block == NULL) { + // No memory available + if (timeout != 0U) { + EvrRtxMemoryPoolAllocPending(mp, timeout); + // Suspend current Thread + osRtxThreadListPut((os_object_t*)mp, osRtxThreadGetRunning()); + osRtxThreadWaitEnter(osRtxThreadWaitingMemoryPool, timeout); + } else { + EvrRtxMemoryPoolAllocFailed(mp); + } + } else { + EvrRtxMemoryPoolAllocated(mp, block); + } + + return block; +} + +/// Return an allocated memory block back to a Memory Pool. +/// \note API identical to osMemoryPoolFree +osStatus_t svcRtxMemoryPoolFree (osMemoryPoolId_t mp_id, void *block) { + os_memory_pool_t *mp = (os_memory_pool_t *)mp_id; + os_thread_t *thread; + osStatus_t status; + + // Check parameters + if ((mp == NULL) || (mp->id != osRtxIdMemoryPool)) { + EvrRtxMemoryPoolError(mp, osErrorParameter); + return osErrorParameter; + } + + // Check object state + if (mp->state == osRtxObjectInactive) { + EvrRtxMemoryPoolError(mp, osErrorResource); + return osErrorResource; + } + + // Free memory + status = osRtxMemoryPoolFree(&mp->mp_info, block); + if (status == osOK) { + EvrRtxMemoryPoolDeallocated(mp, block); + // Check if Thread is waiting to allocate memory + if (mp->thread_list != NULL) { + // Allocate memory + block = osRtxMemoryPoolAlloc(&mp->mp_info); + if (block != NULL) { + // Wakeup waiting Thread with highest Priority + thread = osRtxThreadListGet((os_object_t*)mp); + osRtxThreadWaitExit(thread, (uint32_t)block, true); + EvrRtxMemoryPoolAllocated(mp, block); + } + } + } else { + EvrRtxMemoryPoolFreeFailed(mp, block); + } + + return status; +} + +/// Get maximum number of memory blocks in a Memory Pool. +/// \note API identical to osMemoryPoolGetCapacity +uint32_t svcRtxMemoryPoolGetCapacity (osMemoryPoolId_t mp_id) { + os_memory_pool_t *mp = (os_memory_pool_t *)mp_id; + + // Check parameters + if ((mp == NULL) || (mp->id != osRtxIdMemoryPool)) { + EvrRtxMemoryPoolGetCapacity(mp, 0U); + return 0U; + } + + // Check object state + if (mp->state == osRtxObjectInactive) { + EvrRtxMemoryPoolGetCapacity(mp, 0U); + return 0U; + } + + EvrRtxMemoryPoolGetCapacity(mp, mp->mp_info.max_blocks); + + return mp->mp_info.max_blocks; +} + +/// Get memory block size in a Memory Pool. +/// \note API identical to osMemoryPoolGetBlockSize +uint32_t svcRtxMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id) { + os_memory_pool_t *mp = (os_memory_pool_t *)mp_id; + + // Check parameters + if ((mp == NULL) || (mp->id != osRtxIdMemoryPool)) { + EvrRtxMemoryPoolGetBlockSize(mp, 0U); + return 0U; + } + + // Check object state + if (mp->state == osRtxObjectInactive) { + EvrRtxMemoryPoolGetBlockSize(mp, 0U); + return 0U; + } + + EvrRtxMemoryPoolGetBlockSize(mp, mp->mp_info.block_size); + + return mp->mp_info.block_size; +} + +/// Get number of memory blocks used in a Memory Pool. +/// \note API identical to osMemoryPoolGetCount +uint32_t svcRtxMemoryPoolGetCount (osMemoryPoolId_t mp_id) { + os_memory_pool_t *mp = (os_memory_pool_t *)mp_id; + + // Check parameters + if ((mp == NULL) || (mp->id != osRtxIdMemoryPool)) { + EvrRtxMemoryPoolGetCount(mp, 0U); + return 0U; + } + + // Check object state + if (mp->state == osRtxObjectInactive) { + EvrRtxMemoryPoolGetCount(mp, 0U); + return 0U; + } + + EvrRtxMemoryPoolGetCount(mp, mp->mp_info.used_blocks); + + return mp->mp_info.used_blocks; +} + +/// Get number of memory blocks available in a Memory Pool. +/// \note API identical to osMemoryPoolGetSpace +uint32_t svcRtxMemoryPoolGetSpace (osMemoryPoolId_t mp_id) { + os_memory_pool_t *mp = (os_memory_pool_t *)mp_id; + + // Check parameters + if ((mp == NULL) || (mp->id != osRtxIdMemoryPool)) { + EvrRtxMemoryPoolGetSpace(mp, 0U); + return 0U; + } + + // Check object state + if (mp->state == osRtxObjectInactive) { + EvrRtxMemoryPoolGetSpace(mp, 0U); + return 0U; + } + + EvrRtxMemoryPoolGetSpace(mp, mp->mp_info.max_blocks - mp->mp_info.used_blocks); + + return (mp->mp_info.max_blocks - mp->mp_info.used_blocks); +} + +/// Delete a Memory Pool object. +/// \note API identical to osMemoryPoolDelete +osStatus_t svcRtxMemoryPoolDelete (osMemoryPoolId_t mp_id) { + os_memory_pool_t *mp = (os_memory_pool_t *)mp_id; + os_thread_t *thread; + + // Check parameters + if ((mp == NULL) || (mp->id != osRtxIdMemoryPool)) { + EvrRtxMemoryPoolError(mp, osErrorParameter); + return osErrorParameter; + } + + // Check object state + if (mp->state == osRtxObjectInactive) { + EvrRtxMemoryPoolError(mp, osErrorResource); + return osErrorResource; + } + + // Mark object as inactive + mp->state = osRtxObjectInactive; + + // Unblock waiting threads + if (mp->thread_list != NULL) { + do { + thread = osRtxThreadListGet((os_object_t*)mp); + osRtxThreadWaitExit(thread, 0U, false); + } while (mp->thread_list != NULL); + osRtxThreadDispatch(NULL); + } + + // Free data memory + if (mp->flags & osRtxFlagSystemMemory) { + osRtxMemoryFree(osRtxInfo.mem.mp_data, mp->mp_info.block_base); + } + + // Free object memory + if (mp->flags & osRtxFlagSystemObject) { + if (osRtxInfo.mpi.memory_pool != NULL) { + osRtxMemoryPoolFree(osRtxInfo.mpi.memory_pool, mp); + } else { + osRtxMemoryFree(osRtxInfo.mem.common, mp); + } + } + + EvrRtxMemoryPoolDestroyed(mp); + + return osOK; +} + + +// ==== ISR Calls ==== + +/// Allocate a memory block from a Memory Pool. +/// \note API identical to osMemoryPoolAlloc +__STATIC_INLINE +void *isrRtxMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout) { + os_memory_pool_t *mp = (os_memory_pool_t *)mp_id; + void *block; + + // Check parameters + if ((mp == NULL) || (mp->id != osRtxIdMemoryPool) || (timeout != 0U)) { + EvrRtxMemoryPoolError(mp, osErrorParameter); + return NULL; + } + + // Check object state + if (mp->state == osRtxObjectInactive) { + EvrRtxMemoryPoolError(mp, osErrorResource); + return NULL; + } + + // Allocate memory + block = osRtxMemoryPoolAlloc(&mp->mp_info); + if (block == NULL) { + EvrRtxMemoryPoolAllocFailed(mp); + } else { + EvrRtxMemoryPoolAllocated(mp, block); + } + + return block; +} + +/// Return an allocated memory block back to a Memory Pool. +/// \note API identical to osMemoryPoolFree +__STATIC_INLINE +osStatus_t isrRtxMemoryPoolFree (osMemoryPoolId_t mp_id, void *block) { + os_memory_pool_t *mp = (os_memory_pool_t *)mp_id; + osStatus_t status; + + // Check parameters + if ((mp == NULL) || (mp->id != osRtxIdMemoryPool)) { + EvrRtxMemoryPoolError(mp, osErrorParameter); + return osErrorParameter; + } + + // Check object state + if (mp->state == osRtxObjectInactive) { + EvrRtxMemoryPoolError(mp, osErrorResource); + return osErrorResource; + } + + // Free memory + status = osRtxMemoryPoolFree(&mp->mp_info, block); + if (status == osOK) { + // Register post ISR processing + osRtxPostProcess((os_object_t *)mp); + EvrRtxMemoryPoolDeallocated(mp, block); + } else { + EvrRtxMemoryPoolFreeFailed(mp, block); + } + + return status; +} + + +// ==== Public API ==== + +/// Create and Initialize a Memory Pool object. +osMemoryPoolId_t osMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr) { + EvrRtxMemoryPoolNew(block_count, block_size, attr); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxMemoryPoolError(NULL, osErrorISR); + return NULL; + } + return __svcMemoryPoolNew(block_count, block_size, attr); +} + +/// Get name of a Memory Pool object. +const char *osMemoryPoolGetName (osMemoryPoolId_t mp_id) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxMemoryPoolGetName(mp_id, NULL); + return NULL; + } + return __svcMemoryPoolGetName(mp_id); +} + +/// Allocate a memory block from a Memory Pool. +void *osMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout) { + EvrRtxMemoryPoolAlloc(mp_id, timeout); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + return isrRtxMemoryPoolAlloc(mp_id, timeout); + } else { + return __svcMemoryPoolAlloc(mp_id, timeout); + } +} + +/// Return an allocated memory block back to a Memory Pool. +osStatus_t osMemoryPoolFree (osMemoryPoolId_t mp_id, void *block) { + EvrRtxMemoryPoolFree(mp_id, block); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + return isrRtxMemoryPoolFree(mp_id, block); + } else { + return __svcMemoryPoolFree(mp_id, block); + } +} + +/// Get maximum number of memory blocks in a Memory Pool. +uint32_t osMemoryPoolGetCapacity (osMemoryPoolId_t mp_id) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + return svcRtxMemoryPoolGetCapacity(mp_id); + } else { + return __svcMemoryPoolGetCapacity(mp_id); + } +} + +/// Get memory block size in a Memory Pool. +uint32_t osMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + return svcRtxMemoryPoolGetBlockSize(mp_id); + } else { + return __svcMemoryPoolGetBlockSize(mp_id); + } +} + +/// Get number of memory blocks used in a Memory Pool. +uint32_t osMemoryPoolGetCount (osMemoryPoolId_t mp_id) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + return svcRtxMemoryPoolGetCount(mp_id); + } else { + return __svcMemoryPoolGetCount(mp_id); + } +} + +/// Get number of memory blocks available in a Memory Pool. +uint32_t osMemoryPoolGetSpace (osMemoryPoolId_t mp_id) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + return svcRtxMemoryPoolGetSpace(mp_id); + } else { + return __svcMemoryPoolGetSpace(mp_id); + } +} + +/// Delete a Memory Pool object. +osStatus_t osMemoryPoolDelete (osMemoryPoolId_t mp_id) { + EvrRtxMemoryPoolDelete(mp_id); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxMemoryPoolError(mp_id, osErrorISR); + return osErrorISR; + } + return __svcMemoryPoolDelete(mp_id); +} diff --git a/rtos/TARGET_CORTEX/rtx5/rtx_msgqueue.c b/rtos/TARGET_CORTEX/rtx5/rtx_msgqueue.c new file mode 100644 index 0000000..d147e81 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/rtx_msgqueue.c @@ -0,0 +1,906 @@ +/* + * Copyright (c) 2013-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * + * Project: CMSIS-RTOS RTX + * Title: Message Queue functions + * + * ----------------------------------------------------------------------------- + */ + +#include "rtx_lib.h" + + +// ==== Helper functions ==== + +/// Put a Message into Queue sorted by Priority (Highest at Head). +/// \param[in] mq message queue object. +/// \param[in] msg message object. +static void MessageQueuePut (os_message_queue_t *mq, os_message_t *msg) { +#if (__EXCLUSIVE_ACCESS == 0U) + uint32_t primask = __get_PRIMASK(); +#endif + os_message_t *prev, *next; + + if (mq->msg_last != NULL) { + prev = mq->msg_last; + next = NULL; + while ((prev != NULL) && (prev->priority < msg->priority)) { + next = prev; + prev = prev->prev; + } + msg->prev = prev; + msg->next = next; + if (prev != NULL) { + prev->next = msg; + } else { + mq->msg_first = msg; + } + if (next != NULL) { + next->prev = msg; + } else { + mq->msg_last = msg; + } + } else { + msg->prev = NULL; + msg->next = NULL; + mq->msg_first= msg; + mq->msg_last = msg; + } + +#if (__EXCLUSIVE_ACCESS == 0U) + __disable_irq(); + + mq->msg_count++; + + if (primask == 0U) { + __enable_irq(); + } +#else + atomic_inc32(&mq->msg_count); +#endif +} + +/// Get a Message from Queue with Highest Priority. +/// \param[in] mq message queue object. +/// \return message object or NULL. +static os_message_t *MessageQueueGet (os_message_queue_t *mq) { +#if (__EXCLUSIVE_ACCESS == 0U) + uint32_t primask = __get_PRIMASK(); +#endif + os_message_t *msg; + uint32_t count; + uint8_t flags; + +#if (__EXCLUSIVE_ACCESS == 0U) + __disable_irq(); + + count = mq->msg_count; + if (count != 0U) { + mq->msg_count--; + } + + if (primask == 0U) { + __enable_irq(); + } +#else + count = atomic_dec32_nz(&mq->msg_count); +#endif + + if (count == 0U) { + return NULL; + } + + msg = mq->msg_first; + + while (msg != NULL) { +#if (__EXCLUSIVE_ACCESS == 0U) + __disable_irq(); + + flags = msg->flags; + msg->flags = 1U; + + if (primask == 0U) { + __enable_irq(); + } +#else + flags = atomic_wr8(&msg->flags, 1U); +#endif + if (flags == 0U) { + break; + } + msg = msg->next; + } + + return msg; +} + +/// Remove a Message from Queue +/// \param[in] mq message queue object. +/// \param[in] msg message object. +static void MessageQueueRemove (os_message_queue_t *mq, os_message_t *msg) { + + if (msg->prev != NULL) { + msg->prev->next = msg->next; + } else { + mq->msg_first = msg->next; + } + if (msg->next != NULL) { + msg->next->prev = msg->prev; + } else { + mq->msg_last = msg->prev; + } +} + + +// ==== Library functions ==== + +/// Message Queue post ISR processing. +/// \param[in] msg message object. +void osRtxMessageQueuePostProcess (os_message_t *msg) { + os_message_queue_t *mq; + os_thread_t *thread; + uint32_t *reg; + void **ptr; + + if (msg->state == osRtxObjectInactive) { + return; + } + + if (msg->flags != 0U) { + // Remove Message + ptr = (void *)((uint8_t *)msg + sizeof(os_message_t)); + mq = *ptr; + if (mq->state == osRtxObjectInactive) { + return; + } + MessageQueueRemove(mq, msg); + // Free memory + msg->state = osRtxObjectInactive; + osRtxMemoryPoolFree(&mq->mp_info, msg); + // Check if Thread is waiting to send a Message + if ((mq->thread_list != NULL) && (mq->thread_list->state == osRtxThreadWaitingMessagePut)) { + // Try to allocate memory + msg = osRtxMemoryPoolAlloc(&mq->mp_info); + if (msg != NULL) { + // Wakeup waiting Thread with highest Priority + thread = osRtxThreadListGet((os_object_t*)mq); + osRtxThreadWaitExit(thread, (uint32_t)osOK, false); + // Copy Message (R2: const void *msg_ptr, R3: uint8_t msg_prio) + reg = osRtxThreadRegPtr(thread); + memcpy((uint8_t *)msg + sizeof(os_message_t), (void *)reg[2], mq->msg_size); + // Store Message into Queue + msg->id = osRtxIdMessage; + msg->state = osRtxObjectActive; + msg->flags = 0U; + msg->priority = (uint8_t)reg[3]; + MessageQueuePut(mq, msg); + EvrRtxMessageQueueInserted(mq, (void *)reg[2]); + } + } + } else { + // New Message + mq = (void *)msg->next; + if (mq->state == osRtxObjectInactive) { + return; + } + // Check if Thread is waiting to receive a Message + if ((mq->thread_list != NULL) && (mq->thread_list->state == osRtxThreadWaitingMessageGet)) { + EvrRtxMessageQueueInserted(mq, (void *)msg->prev); + // Wakeup waiting Thread with highest Priority + thread = osRtxThreadListGet((os_object_t*)mq); + osRtxThreadWaitExit(thread, (uint32_t)osOK, false); + // Copy Message (R2: void *msg_ptr, R3: uint8_t *msg_prio) + reg = osRtxThreadRegPtr(thread); + memcpy((void *)reg[2], (uint8_t *)msg + sizeof(os_message_t), mq->msg_size); + if (reg[3] != 0U) { + *((uint8_t *)reg[3]) = msg->priority; + } + EvrRtxMessageQueueRetrieved(mq, (void *)reg[2]); + // Free memory + msg->state = osRtxObjectInactive; + osRtxMemoryPoolFree(&mq->mp_info, msg); + } else { + EvrRtxMessageQueueInserted(mq, (void *)msg->prev); + MessageQueuePut(mq, msg); + } + } +} + + +// ==== Service Calls ==== + +SVC0_3M(MessageQueueNew, osMessageQueueId_t, uint32_t, uint32_t, const osMessageQueueAttr_t *) +SVC0_1 (MessageQueueGetName, const char *, osMessageQueueId_t) +SVC0_4 (MessageQueuePut, osStatus_t, osMessageQueueId_t, const void *, uint8_t, uint32_t) +SVC0_4 (MessageQueueGet, osStatus_t, osMessageQueueId_t, void *, uint8_t *, uint32_t) +SVC0_1 (MessageQueueGetCapacity, uint32_t, osMessageQueueId_t) +SVC0_1 (MessageQueueGetMsgSize, uint32_t, osMessageQueueId_t) +SVC0_1 (MessageQueueGetCount, uint32_t, osMessageQueueId_t) +SVC0_1 (MessageQueueGetSpace, uint32_t, osMessageQueueId_t) +SVC0_1 (MessageQueueReset, osStatus_t, osMessageQueueId_t) +SVC0_1 (MessageQueueDelete, osStatus_t, osMessageQueueId_t) + +/// Create and Initialize a Message Queue object. +/// \note API identical to osMessageQueueNew +osMessageQueueId_t svcRtxMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr) { + os_message_queue_t *mq; + void *mq_mem; + uint32_t mq_size; + uint32_t block_size; + uint32_t size; + uint8_t flags; + const char *name; + + // Check parameters + if ((msg_count == 0U) || (msg_size == 0U)) { + EvrRtxMessageQueueError(NULL, osErrorParameter); + return NULL; + } + msg_size = (msg_size + 3U) & ~3UL; + block_size = msg_size + sizeof(os_message_t); + if ((__CLZ(msg_count) + __CLZ(block_size)) < 32) { + EvrRtxMessageQueueError(NULL, osErrorParameter); + return NULL; + } + + size = msg_count * block_size; + + // Process attributes + if (attr != NULL) { + name = attr->name; + mq = attr->cb_mem; + mq_mem = attr->mq_mem; + mq_size = attr->mq_size; + if (mq != NULL) { + if (((uint32_t)mq & 3U) || (attr->cb_size < sizeof(os_message_queue_t))) { + EvrRtxMessageQueueError(NULL, osRtxErrorInvalidControlBlock); + return NULL; + } + } else { + if (attr->cb_size != 0U) { + EvrRtxMessageQueueError(NULL, osRtxErrorInvalidControlBlock); + return NULL; + } + } + if (mq_mem != NULL) { + if (((uint32_t)mq_mem & 3U) || (mq_size < size)) { + EvrRtxMessageQueueError(NULL, osRtxErrorInvalidDataMemory); + return NULL; + } + } else { + if (mq_size != 0U) { + EvrRtxMessageQueueError(NULL, osRtxErrorInvalidDataMemory); + return NULL; + } + } + } else { + name = NULL; + mq = NULL; + mq_mem = NULL; + } + + // Allocate object memory if not provided + if (mq == NULL) { + if (osRtxInfo.mpi.message_queue != NULL) { + mq = osRtxMemoryPoolAlloc(osRtxInfo.mpi.message_queue); + } else { + mq = osRtxMemoryAlloc(osRtxInfo.mem.common, sizeof(os_message_queue_t), 1U); + } + if (mq == NULL) { + EvrRtxMessageQueueError(NULL, osErrorNoMemory); + return NULL; + } + flags = osRtxFlagSystemObject; + } else { + flags = 0U; + } + + // Allocate data memory if not provided + if (mq_mem == NULL) { + mq_mem = osRtxMemoryAlloc(osRtxInfo.mem.mq_data, size, 0U); + if (mq_mem == NULL) { + EvrRtxMessageQueueError(NULL, osErrorNoMemory); + if (flags & osRtxFlagSystemObject) { + if (osRtxInfo.mpi.message_queue != NULL) { + osRtxMemoryPoolFree(osRtxInfo.mpi.message_queue, mq); + } else { + osRtxMemoryFree(osRtxInfo.mem.common, mq); + } + } + return NULL; + } + memset(mq_mem, 0, size); + flags |= osRtxFlagSystemMemory; + } + + // Initialize control block + mq->id = osRtxIdMessageQueue; + mq->state = osRtxObjectActive; + mq->flags = flags; + mq->name = name; + mq->thread_list = NULL; + mq->msg_size = msg_size; + mq->msg_count = 0U; + mq->msg_first = NULL; + mq->msg_last = NULL; + osRtxMemoryPoolInit(&mq->mp_info, msg_count, block_size, mq_mem); + + // Register post ISR processing function + osRtxInfo.post_process.message_queue = osRtxMessageQueuePostProcess; + + EvrRtxMessageQueueCreated(mq); + + return mq; +} + +/// Get name of a Message Queue object. +/// \note API identical to osMessageQueueGetName +const char *svcRtxMessageQueueGetName (osMessageQueueId_t mq_id) { + os_message_queue_t *mq = (os_message_queue_t *)mq_id; + + // Check parameters + if ((mq == NULL) || (mq->id != osRtxIdMessageQueue)) { + EvrRtxMessageQueueGetName(mq, NULL); + return NULL; + } + + // Check object state + if (mq->state == osRtxObjectInactive) { + EvrRtxMessageQueueGetName(mq, NULL); + return NULL; + } + + EvrRtxMessageQueueGetName(mq, mq->name); + + return mq->name; +} + +/// Put a Message into a Queue or timeout if Queue is full. +/// \note API identical to osMessageQueuePut +osStatus_t svcRtxMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout) { + os_message_queue_t *mq = (os_message_queue_t *)mq_id; + os_message_t *msg; + os_thread_t *thread; + uint32_t *reg; + + // Check parameters + if ((mq == NULL) || (mq->id != osRtxIdMessageQueue) || (msg_ptr == NULL)) { + EvrRtxMessageQueueError(mq, osErrorParameter); + return osErrorParameter; + } + + // Check object state + if (mq->state == osRtxObjectInactive) { + EvrRtxMessageQueueError(mq, osErrorResource); + return osErrorResource; + } + + // Check if Thread is waiting to receive a Message + if ((mq->thread_list != NULL) && (mq->thread_list->state == osRtxThreadWaitingMessageGet)) { + EvrRtxMessageQueueInserted(mq, msg_ptr); + // Wakeup waiting Thread with highest Priority + thread = osRtxThreadListGet((os_object_t*)mq); + osRtxThreadWaitExit(thread, (uint32_t)osOK, true); + // Copy Message (R2: void *msg_ptr, R3: uint8_t *msg_prio) + reg = osRtxThreadRegPtr(thread); + memcpy((void *)reg[2], msg_ptr, mq->msg_size); + if (reg[3] != 0U) { + *((uint8_t *)reg[3]) = msg_prio; + } + EvrRtxMessageQueueRetrieved(mq, (void *)reg[2]); + return osOK; + } + + // Try to allocate memory + msg = osRtxMemoryPoolAlloc(&mq->mp_info); + if (msg != NULL) { + // Copy Message + memcpy((uint8_t *)msg + sizeof(os_message_t), msg_ptr, mq->msg_size); + // Put Message into Queue + msg->id = osRtxIdMessage; + msg->state = osRtxObjectActive; + msg->flags = 0U; + msg->priority = msg_prio; + MessageQueuePut(mq, msg); + } else { + // No memory available + if (timeout != 0U) { + EvrRtxMessageQueuePutPending(mq, msg_ptr, timeout); + // Suspend current Thread + osRtxThreadListPut((os_object_t*)mq, osRtxThreadGetRunning()); + osRtxThreadWaitEnter(osRtxThreadWaitingMessagePut, timeout); + // Save arguments (R2: const void *msg_ptr, R3: uint8_t msg_prio) + reg = (uint32_t *)(__get_PSP()); + reg[2] = (uint32_t)msg_ptr; + reg[3] = (uint32_t)msg_prio; + return osErrorTimeout; + } else { + EvrRtxMessageQueueNotInserted(mq, msg_ptr); + return osErrorResource; + } + } + + EvrRtxMessageQueueInserted(mq, msg_ptr); + + return osOK; +} + +/// Get a Message from a Queue or timeout if Queue is empty. +/// \note API identical to osMessageQueueGet +osStatus_t svcRtxMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout) { + os_message_queue_t *mq = (os_message_queue_t *)mq_id; + os_message_t *msg; + os_thread_t *thread; + uint32_t *reg; + + // Check parameters + if ((mq == NULL) || (mq->id != osRtxIdMessageQueue) || (msg_ptr == NULL)) { + EvrRtxMessageQueueError(mq, osErrorParameter); + return osErrorParameter; + } + + // Check object state + if (mq->state == osRtxObjectInactive) { + EvrRtxMessageQueueError(mq, osErrorResource); + return osErrorResource; + } + + // Get Message from Queue + msg = MessageQueueGet(mq); + if (msg != NULL) { + MessageQueueRemove(mq, msg); + // Copy Message + memcpy(msg_ptr, (uint8_t *)msg + sizeof(os_message_t), mq->msg_size); + if (msg_prio != NULL) { + *msg_prio = msg->priority; + } + EvrRtxMessageQueueRetrieved(mq, msg_ptr); + // Free memory + msg->state = osRtxObjectInactive; + osRtxMemoryPoolFree(&mq->mp_info, msg); + } else { + // No Message available + if (timeout != 0U) { + EvrRtxMessageQueueGetPending(mq, msg_ptr, timeout); + // Suspend current Thread + osRtxThreadListPut((os_object_t*)mq, osRtxThreadGetRunning()); + osRtxThreadWaitEnter(osRtxThreadWaitingMessageGet, timeout); + // Save arguments (R2: void *msg_ptr, R3: uint8_t *msg_prio) + reg = (uint32_t *)(__get_PSP()); + reg[2] = (uint32_t)msg_ptr; + reg[3] = (uint32_t)msg_prio; + return osErrorTimeout; + } else { + EvrRtxMessageQueueNotRetrieved(mq, msg_ptr); + return osErrorResource; + } + } + + // Check if Thread is waiting to send a Message + if ((mq->thread_list != NULL) && (mq->thread_list->state == osRtxThreadWaitingMessagePut)) { + // Try to allocate memory + msg = osRtxMemoryPoolAlloc(&mq->mp_info); + if (msg != NULL) { + // Wakeup waiting Thread with highest Priority + thread = osRtxThreadListGet((os_object_t*)mq); + osRtxThreadWaitExit(thread, (uint32_t)osOK, true); + // Copy Message (R2: const void *msg_ptr, R3: uint8_t msg_prio) + reg = osRtxThreadRegPtr(thread); + memcpy((uint8_t *)msg + sizeof(os_message_t), (void *)reg[2], mq->msg_size); + // Store Message into Queue + msg->id = osRtxIdMessage; + msg->state = osRtxObjectActive; + msg->flags = 0U; + msg->priority = (uint8_t)reg[3]; + MessageQueuePut(mq, msg); + EvrRtxMessageQueueInserted(mq, (void *)reg[2]); + } + } + + return osOK; +} + +/// Get maximum number of messages in a Message Queue. +/// \note API identical to osMessageGetCapacity +uint32_t svcRtxMessageQueueGetCapacity (osMessageQueueId_t mq_id) { + os_message_queue_t *mq = (os_message_queue_t *)mq_id; + + // Check parameters + if ((mq == NULL) || (mq->id != osRtxIdMessageQueue)) { + EvrRtxMessageQueueGetCapacity(mq, 0U); + return 0U; + } + + // Check object state + if (mq->state == osRtxObjectInactive) { + EvrRtxMessageQueueGetCapacity(mq, 0U); + return 0U; + } + + EvrRtxMessageQueueGetCapacity(mq, mq->mp_info.max_blocks); + + return mq->mp_info.max_blocks; +} + +/// Get maximum message size in a Memory Pool. +/// \note API identical to osMessageGetMsgSize +uint32_t svcRtxMessageQueueGetMsgSize (osMessageQueueId_t mq_id) { + os_message_queue_t *mq = (os_message_queue_t *)mq_id; + + // Check parameters + if ((mq == NULL) || (mq->id != osRtxIdMessageQueue)) { + EvrRtxMessageQueueGetMsgSize(mq, 0U); + return 0U; + } + + // Check object state + if (mq->state == osRtxObjectInactive) { + EvrRtxMessageQueueGetMsgSize(mq, 0U); + return 0U; + } + + EvrRtxMessageQueueGetMsgSize(mq, mq->msg_size); + + return mq->msg_size; +} + +/// Get number of queued messages in a Message Queue. +/// \note API identical to osMessageGetCount +uint32_t svcRtxMessageQueueGetCount (osMessageQueueId_t mq_id) { + os_message_queue_t *mq = (os_message_queue_t *)mq_id; + + // Check parameters + if ((mq == NULL) || (mq->id != osRtxIdMessageQueue)) { + EvrRtxMessageQueueGetCount(mq, 0U); + return 0U; + } + + // Check object state + if (mq->state == osRtxObjectInactive) { + EvrRtxMessageQueueGetCount(mq, 0U); + return 0U; + } + + EvrRtxMessageQueueGetCount(mq, mq->msg_count); + + return mq->msg_count; +} + +/// Get number of available slots for messages in a Message Queue. +/// \note API identical to osMessageGetSpace +uint32_t svcRtxMessageQueueGetSpace (osMessageQueueId_t mq_id) { + os_message_queue_t *mq = (os_message_queue_t *)mq_id; + + // Check parameters + if ((mq == NULL) || (mq->id != osRtxIdMessageQueue)) { + EvrRtxMessageQueueGetSpace(mq, 0U); + return 0U; + } + + // Check object state + if (mq->state == osRtxObjectInactive) { + EvrRtxMessageQueueGetSpace(mq, 0U); + return 0U; + } + + EvrRtxMessageQueueGetSpace(mq, mq->mp_info.max_blocks - mq->msg_count); + + return (mq->mp_info.max_blocks - mq->msg_count); +} + +/// Reset a Message Queue to initial empty state. +/// \note API identical to osMessageQueueReset +osStatus_t svcRtxMessageQueueReset (osMessageQueueId_t mq_id) { + os_message_queue_t *mq = (os_message_queue_t *)mq_id; + os_message_t *msg; + os_thread_t *thread; + uint32_t *reg; + + // Check parameters + if ((mq == NULL) || (mq->id != osRtxIdMessageQueue)) { + EvrRtxMessageQueueError(mq, osErrorParameter); + return osErrorParameter; + } + + // Check object state + if (mq->state == osRtxObjectInactive) { + EvrRtxMessageQueueError(mq, osErrorResource); + return osErrorResource; + } + + // Remove Messages from Queue + for (;;) { + // Get Message from Queue + msg = MessageQueueGet(mq); + if (msg == NULL) { + break; + } + MessageQueueRemove(mq, msg); + EvrRtxMessageQueueRetrieved(mq, NULL); + // Free memory + msg->state = osRtxObjectInactive; + osRtxMemoryPoolFree(&mq->mp_info, msg); + } + + // Check if Threads are waiting to send Messages + if ((mq->thread_list != NULL) && (mq->thread_list->state == osRtxThreadWaitingMessagePut)) { + do { + // Try to allocate memory + msg = osRtxMemoryPoolAlloc(&mq->mp_info); + if (msg != NULL) { + // Wakeup waiting Thread with highest Priority + thread = osRtxThreadListGet((os_object_t*)mq); + osRtxThreadWaitExit(thread, (uint32_t)osOK, false); + // Copy Message (R2: const void *msg_ptr, R3: uint8_t msg_prio) + reg = osRtxThreadRegPtr(thread); + memcpy((uint8_t *)msg + sizeof(os_message_t), (void *)reg[2], mq->msg_size); + // Store Message into Queue + msg->id = osRtxIdMessage; + msg->state = osRtxObjectActive; + msg->flags = 0U; + msg->priority = (uint8_t)reg[3]; + MessageQueuePut(mq, msg); + EvrRtxMessageQueueInserted(mq, (void *)reg[2]); + } + } while ((msg != NULL) && (mq->thread_list != NULL)); + osRtxThreadDispatch(NULL); + } + + EvrRtxMessageQueueResetDone(mq); + + return osOK; +} + +/// Delete a Message Queue object. +/// \note API identical to osMessageQueueDelete +osStatus_t svcRtxMessageQueueDelete (osMessageQueueId_t mq_id) { + os_message_queue_t *mq = (os_message_queue_t *)mq_id; + os_thread_t *thread; + + // Check parameters + if ((mq == NULL) || (mq->id != osRtxIdMessageQueue)) { + EvrRtxMessageQueueError(mq, osErrorParameter); + return osErrorParameter; + } + + // Check object state + if (mq->state == osRtxObjectInactive) { + EvrRtxMessageQueueError(mq, osErrorResource); + return osErrorResource; + } + + // Mark object as inactive + mq->state = osRtxObjectInactive; + + // Unblock waiting threads + if (mq->thread_list != NULL) { + do { + thread = osRtxThreadListGet((os_object_t*)mq); + osRtxThreadWaitExit(thread, (uint32_t)osErrorResource, false); + } while (mq->thread_list != NULL); + osRtxThreadDispatch(NULL); + } + + // Free data memory + if (mq->flags & osRtxFlagSystemMemory) { + osRtxMemoryFree(osRtxInfo.mem.mq_data, mq->mp_info.block_base); + } + + // Free object memory + if (mq->flags & osRtxFlagSystemObject) { + if (osRtxInfo.mpi.message_queue != NULL) { + osRtxMemoryPoolFree(osRtxInfo.mpi.message_queue, mq); + } else { + osRtxMemoryFree(osRtxInfo.mem.common, mq); + } + } + + EvrRtxMessageQueueDestroyed(mq); + + return osOK; +} + + +// ==== ISR Calls ==== + +/// Put a Message into a Queue or timeout if Queue is full. +/// \note API identical to osMessageQueuePut +__STATIC_INLINE +osStatus_t isrRtxMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout) { + os_message_queue_t *mq = (os_message_queue_t *)mq_id; + os_message_t *msg; + const void **ptr; + + // Check parameters + if ((mq == NULL) || (mq->id != osRtxIdMessageQueue) || (msg_ptr == NULL) || (timeout != 0U)) { + EvrRtxMessageQueueError(mq, osErrorParameter); + return osErrorParameter; + } + + // Check object state + if (mq->state == osRtxObjectInactive) { + EvrRtxMessageQueueError(mq, osErrorResource); + return osErrorResource; + } + + // Try to allocate memory + msg = osRtxMemoryPoolAlloc(&mq->mp_info); + if (msg != NULL) { + // Copy Message + memcpy((uint8_t *)msg + sizeof(os_message_t), msg_ptr, mq->msg_size); + msg->id = osRtxIdMessage; + msg->state = osRtxObjectActive; + msg->flags = 0U; + msg->priority = msg_prio; + // Register post ISR processing + ptr = (void *)&msg->prev; + *ptr = msg_ptr; + ptr = (void *)&msg->next; + *ptr = mq; + osRtxPostProcess((os_object_t *)msg); + } else { + // No memory available + EvrRtxMessageQueueNotInserted(mq, msg_ptr); + return osErrorResource; + } + + EvrRtxMessageQueueInsertPending(mq, msg_ptr); + + return osOK; +} + +/// Get a Message from a Queue or timeout if Queue is empty. +/// \note API identical to osMessageQueueGet +__STATIC_INLINE +osStatus_t isrRtxMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout) { + os_message_queue_t *mq = (os_message_queue_t *)mq_id; + os_message_t *msg; + void **ptr; + + // Check parameters + if ((mq == NULL) || (mq->id != osRtxIdMessageQueue) || (msg_ptr == NULL) || (timeout != 0U)) { + EvrRtxMessageQueueError(mq, osErrorParameter); + return osErrorParameter; + } + + // Check object state + if (mq->state == osRtxObjectInactive) { + EvrRtxMessageQueueError(mq, osErrorResource); + return osErrorResource; + } + + // Get Message from Queue + msg = MessageQueueGet(mq); + if (msg != NULL) { + // Copy Message + memcpy(msg_ptr, (uint8_t *)msg + sizeof(os_message_t), mq->msg_size); + if (msg_prio != NULL) { + *msg_prio = msg->priority; + } + EvrRtxMessageQueueRetrieved(mq, msg_ptr); + // Register post ISR processing + ptr = (void *)((uint8_t *)msg + sizeof(os_message_t)); + *ptr = mq; + osRtxPostProcess((os_object_t *)msg); + } else { + // No Message available + EvrRtxMessageQueueNotRetrieved(mq, msg_ptr); + return osErrorResource; + } + + return osOK; +} + + +// ==== Public API ==== + +/// Create and Initialize a Message Queue object. +osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr) { + EvrRtxMessageQueueNew(msg_count, msg_size, attr); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxMessageQueueError(NULL, osErrorISR); + return NULL; + } + return __svcMessageQueueNew(msg_count, msg_size, attr); +} + +/// Get name of a Message Queue object. +const char *osMessageQueueGetName (osMessageQueueId_t mq_id) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxMessageQueueGetName(mq_id, NULL); + return NULL; + } + return __svcMessageQueueGetName(mq_id); +} + +/// Put a Message into a Queue or timeout if Queue is full. +osStatus_t osMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout) { + EvrRtxMessageQueuePut(mq_id, msg_ptr, msg_prio, timeout); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + return isrRtxMessageQueuePut(mq_id, msg_ptr, msg_prio, timeout); + } else { + return __svcMessageQueuePut(mq_id, msg_ptr, msg_prio, timeout); + } +} + +/// Get a Message from a Queue or timeout if Queue is empty. +osStatus_t osMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout) { + EvrRtxMessageQueueGet(mq_id, msg_ptr, msg_prio, timeout); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + return isrRtxMessageQueueGet(mq_id, msg_ptr, msg_prio, timeout); + } else { + return __svcMessageQueueGet(mq_id, msg_ptr, msg_prio, timeout); + } +} + +/// Get maximum number of messages in a Message Queue. +uint32_t osMessageQueueGetCapacity (osMessageQueueId_t mq_id) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + return svcRtxMessageQueueGetCapacity(mq_id); + } else { + return __svcMessageQueueGetCapacity(mq_id); + } +} + +/// Get maximum message size in a Memory Pool. +uint32_t osMessageQueueGetMsgSize (osMessageQueueId_t mq_id) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + return svcRtxMessageQueueGetMsgSize(mq_id); + } else { + return __svcMessageQueueGetMsgSize(mq_id); + } +} + +/// Get number of queued messages in a Message Queue. +uint32_t osMessageQueueGetCount (osMessageQueueId_t mq_id) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + return svcRtxMessageQueueGetCount(mq_id); + } else { + return __svcMessageQueueGetCount(mq_id); + } +} + +/// Get number of available slots for messages in a Message Queue. +uint32_t osMessageQueueGetSpace (osMessageQueueId_t mq_id) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + return svcRtxMessageQueueGetSpace(mq_id); + } else { + return __svcMessageQueueGetSpace(mq_id); + } +} + +/// Reset a Message Queue to initial empty state. +osStatus_t osMessageQueueReset (osMessageQueueId_t mq_id) { + EvrRtxMessageQueueReset(mq_id); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxMessageQueueError(mq_id, osErrorISR); + return osErrorISR; + } + return __svcMessageQueueReset(mq_id); +} + +/// Delete a Message Queue object. +osStatus_t osMessageQueueDelete (osMessageQueueId_t mq_id) { + EvrRtxMessageQueueDelete(mq_id); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxMessageQueueError(mq_id, osErrorISR); + return osErrorISR; + } + return __svcMessageQueueDelete(mq_id); +} diff --git a/rtos/TARGET_CORTEX/rtx5/rtx_mutex.c b/rtos/TARGET_CORTEX/rtx5/rtx_mutex.c new file mode 100644 index 0000000..4a274f8 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/rtx_mutex.c @@ -0,0 +1,494 @@ +/* + * Copyright (c) 2013-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * + * Project: CMSIS-RTOS RTX + * Title: Mutex functions + * + * ----------------------------------------------------------------------------- + */ + +#include "rtx_lib.h" + + +// ==== Library functions ==== + +/// Release Mutex list when owner Thread terminates. +/// \param[in] mutex mutex object. +/// \return 1 - success, 0 - failure. +void osRtxMutexOwnerRelease (os_mutex_t *mutex_list) { + os_mutex_t *mutex; + os_thread_t *thread; + + mutex = mutex_list; + while (mutex) { + mutex_list = mutex->owner_next; + // Check if Mutex is Robust + if (mutex->attr & osMutexRobust) { + // Clear Lock counter + mutex->lock = 0U; + EvrRtxMutexReleased(mutex, 0U); + // Check if Thread is waiting for a Mutex + if (mutex->thread_list != NULL) { + // Wakeup waiting Thread with highest Priority + thread = osRtxThreadListGet((os_object_t*)mutex); + osRtxThreadWaitExit(thread, (uint32_t)osOK, false); + // Thread is the new Mutex owner + mutex->owner_thread = thread; + mutex->owner_next = thread->mutex_list; + mutex->owner_prev = NULL; + thread->mutex_list = mutex; + mutex->lock = 1U; + EvrRtxMutexAcquired(mutex, 1U); + } + } + mutex = mutex_list; + } +} + + +// ==== Service Calls ==== + +// Service Calls definitions +SVC0_1M(MutexNew, osMutexId_t, const osMutexAttr_t *) +SVC0_1 (MutexGetName, const char *, osMutexId_t) +SVC0_2 (MutexAcquire, osStatus_t, osMutexId_t, uint32_t) +SVC0_1 (MutexRelease, osStatus_t, osMutexId_t) +SVC0_1 (MutexGetOwner, osThreadId_t, osMutexId_t) +SVC0_1 (MutexDelete, osStatus_t, osMutexId_t) + +/// Create and Initialize a Mutex object. +/// \note API identical to osMutexNew +osMutexId_t svcRtxMutexNew (const osMutexAttr_t *attr) { + os_mutex_t *mutex; + uint32_t attr_bits; + uint8_t flags; + const char *name; + + // Process attributes + if (attr != NULL) { + name = attr->name; + attr_bits = attr->attr_bits; + mutex = attr->cb_mem; + if (mutex != NULL) { + if (((uint32_t)mutex & 3U) || (attr->cb_size < sizeof(os_mutex_t))) { + EvrRtxMutexError(NULL, osRtxErrorInvalidControlBlock); + return NULL; + } + } else { + if (attr->cb_size != 0U) { + EvrRtxMutexError(NULL, osRtxErrorInvalidControlBlock); + return NULL; + } + } + } else { + name = NULL; + attr_bits = 0U; + mutex = NULL; + } + + // Allocate object memory if not provided + if (mutex == NULL) { + if (osRtxInfo.mpi.mutex != NULL) { + mutex = osRtxMemoryPoolAlloc(osRtxInfo.mpi.mutex); + } else { + mutex = osRtxMemoryAlloc(osRtxInfo.mem.common, sizeof(os_mutex_t), 1U); + } + if (mutex == NULL) { + EvrRtxMutexError(NULL, osErrorNoMemory); + return NULL; + } + flags = osRtxFlagSystemObject; + } else { + flags = 0U; + } + + // Initialize control block + mutex->id = osRtxIdMutex; + mutex->state = osRtxObjectActive; + mutex->flags = flags; + mutex->attr = (uint8_t)attr_bits; + mutex->name = name; + mutex->thread_list = NULL; + mutex->owner_thread = NULL; + mutex->owner_prev = NULL; + mutex->owner_next = NULL; + mutex->lock = 0U; + + EvrRtxMutexCreated(mutex); + + return mutex; +} + +/// Get name of a Mutex object. +/// \note API identical to osMutexGetName +const char *svcRtxMutexGetName (osMutexId_t mutex_id) { + os_mutex_t *mutex = (os_mutex_t *)mutex_id; + + // Check parameters + if ((mutex == NULL) || (mutex->id != osRtxIdMutex)) { + EvrRtxMutexGetName(mutex, NULL); + return NULL; + } + + // Check object state + if (mutex->state == osRtxObjectInactive) { + EvrRtxMutexGetName(mutex, NULL); + return NULL; + } + + EvrRtxMutexGetName(mutex, mutex->name); + + return mutex->name; +} + +/// Acquire a Mutex or timeout if it is locked. +/// \note API identical to osMutexAcquire +osStatus_t svcRtxMutexAcquire (osMutexId_t mutex_id, uint32_t timeout) { + os_mutex_t *mutex = (os_mutex_t *)mutex_id; + os_thread_t *running_thread; + + running_thread = osRtxThreadGetRunning(); + if (running_thread == NULL) { + EvrRtxMutexError(mutex, osRtxErrorKernelNotRunning); + return osError; + } + + // Check parameters + if ((mutex == NULL) || (mutex->id != osRtxIdMutex)) { + EvrRtxMutexError(mutex, osErrorParameter); + return osErrorParameter; + } + + // Check object state + if (mutex->state == osRtxObjectInactive) { + EvrRtxMutexError(mutex, osErrorResource); + return osErrorResource; + } + + // Check if Mutex is not locked + if (mutex->lock == 0U) { + // Acquire Mutex + mutex->owner_thread = running_thread; + mutex->owner_next = running_thread->mutex_list; + mutex->owner_prev = NULL; + if (running_thread->mutex_list != NULL) { + running_thread->mutex_list->owner_prev = mutex; + } + running_thread->mutex_list = mutex; + mutex->lock = 1U; + EvrRtxMutexAcquired(mutex, mutex->lock); + return osOK; + } + + // Check if Mutex is recursive and running Thread is the owner + if ((mutex->attr & osMutexRecursive) && (mutex->owner_thread == running_thread)) { + // Increment lock counter + if (mutex->lock == osRtxMutexLockLimit) { + EvrRtxMutexError(mutex, osRtxErrorMutexLockLimit); + return osErrorResource; + } + mutex->lock++; + EvrRtxMutexAcquired(mutex, mutex->lock); + return osOK; + } + + // Check if timeout is specified + if (timeout != 0U) { + // Check if Priority inheritance protocol is enabled + if (mutex->attr & osMutexPrioInherit) { + // Raise priority of owner Thread if lower than priority of running Thread + if (mutex->owner_thread->priority < running_thread->priority) { + mutex->owner_thread->priority = running_thread->priority; + osRtxThreadListSort(mutex->owner_thread); + } + } + EvrRtxMutexAcquirePending(mutex, timeout); + // Suspend current Thread + osRtxThreadListPut((os_object_t*)mutex, running_thread); + osRtxThreadWaitEnter(osRtxThreadWaitingMutex, timeout); + return osErrorTimeout; + } + + // Mutex was not acquired + EvrRtxMutexNotAcquired(mutex); + + return osErrorResource; +} + +/// Release a Mutex that was acquired by osMutexAcquire. +/// \note API identical to osMutexRelease +osStatus_t svcRtxMutexRelease (osMutexId_t mutex_id) { + os_mutex_t *mutex = (os_mutex_t *)mutex_id; + os_mutex_t *mutex0; + os_thread_t *thread; + os_thread_t *running_thread; + int8_t priority; + + running_thread = osRtxThreadGetRunning(); + if (running_thread == NULL) { + EvrRtxMutexError(mutex, osRtxErrorKernelNotRunning); + return osError; + } + + // Check parameters + if ((mutex == NULL) || (mutex->id != osRtxIdMutex)) { + EvrRtxMutexError(mutex, osErrorParameter); + return osErrorParameter; + } + + // Check object state + if (mutex->state == osRtxObjectInactive) { + EvrRtxMutexError(mutex, osErrorResource); + return osErrorResource; + } + + // Check if running Thread is not the owner + if (mutex->owner_thread != running_thread) { + EvrRtxMutexError(mutex, osRtxErrorMutexNotOwned); + return osErrorResource; + } + + // Check if Mutex is not locked + if (mutex->lock == 0U) { + EvrRtxMutexError(mutex, osRtxErrorMutexNotLocked); + return osErrorResource; + } + + // Decrement Lock counter + mutex->lock--; + EvrRtxMutexReleased(mutex, mutex->lock); + + // Check Lock counter + if (mutex->lock != 0U) { + return osOK; + } + + // Remove Mutex from Thread owner list + if (mutex->owner_next != NULL) { + mutex->owner_next->owner_prev = mutex->owner_prev; + } + if (mutex->owner_prev != NULL) { + mutex->owner_prev->owner_next = mutex->owner_next; + } else { + running_thread->mutex_list = mutex->owner_next; + } + + // Restore running Thread priority + if (mutex->attr & osMutexPrioInherit) { + priority = running_thread->priority_base; + mutex0 = running_thread->mutex_list; + while (mutex0) { + // Mutexes owned by running Thread + if ((mutex0->thread_list != NULL) && (mutex0->thread_list->priority > priority)) { + // Higher priority Thread is waiting for Mutex + priority = mutex0->thread_list->priority; + } + mutex0 = mutex0->owner_next; + } + running_thread->priority = priority; + } + + // Check if Thread is waiting for a Mutex + if (mutex->thread_list != NULL) { + // Wakeup waiting Thread with highest Priority + thread = osRtxThreadListGet((os_object_t*)mutex); + osRtxThreadWaitExit(thread, (uint32_t)osOK, false); + // Thread is the new Mutex owner + mutex->owner_thread = thread; + mutex->owner_next = thread->mutex_list; + mutex->owner_prev = NULL; + thread->mutex_list = mutex; + mutex->lock = 1U; + EvrRtxMutexAcquired(mutex, 1U); + } + + osRtxThreadDispatch(NULL); + + return osOK; +} + +/// Get Thread which owns a Mutex object. +/// \note API identical to osMutexGetOwner +osThreadId_t svcRtxMutexGetOwner (osMutexId_t mutex_id) { + os_mutex_t *mutex = (os_mutex_t *)mutex_id; + + // Check parameters + if ((mutex == NULL) || (mutex->id != osRtxIdMutex)) { + EvrRtxMutexGetOwner(mutex, NULL); + return NULL; + } + + // Check object state + if (mutex->state == osRtxObjectInactive) { + EvrRtxMutexGetOwner(mutex, NULL); + return NULL; + } + + // Check if Mutex is not locked + if (mutex->lock == 0U) { + EvrRtxMutexGetOwner(mutex, NULL); + return NULL; + } + + EvrRtxMutexGetOwner(mutex, mutex->owner_thread); + + return mutex->owner_thread; +} + +/// Delete a Mutex object. +/// \note API identical to osMutexDelete +osStatus_t svcRtxMutexDelete (osMutexId_t mutex_id) { + os_mutex_t *mutex = (os_mutex_t *)mutex_id; + os_mutex_t *mutex0; + os_thread_t *thread; + int8_t priority; + + // Check parameters + if ((mutex == NULL) || (mutex->id != osRtxIdMutex)) { + EvrRtxMutexError(mutex, osErrorParameter); + return osErrorParameter; + } + + // Check object state + if (mutex->state == osRtxObjectInactive) { + EvrRtxMutexError(mutex, osErrorResource); + return osErrorResource; + } + + // Mark object as inactive + mutex->state = osRtxObjectInactive; + + // Check if Mutex is locked + if (mutex->lock != 0U) { + + thread = mutex->owner_thread; + + // Remove Mutex from Thread owner list + if (mutex->owner_next != NULL) { + mutex->owner_next->owner_prev = mutex->owner_prev; + } + if (mutex->owner_prev != NULL) { + mutex->owner_prev->owner_next = mutex->owner_next; + } else { + thread->mutex_list = mutex->owner_next; + } + + // Restore owner Thread priority + if (mutex->attr & osMutexPrioInherit) { + priority = thread->priority_base; + mutex0 = thread->mutex_list; + while (mutex0) { + // Mutexes owned by running Thread + if ((mutex0->thread_list != NULL) && (mutex0->thread_list->priority > priority)) { + // Higher priority Thread is waiting for Mutex + priority = mutex0->thread_list->priority; + } + mutex0 = mutex0->owner_next; + } + if (thread->priority != priority) { + thread->priority = priority; + osRtxThreadListSort(thread); + } + } + + // Unblock waiting threads + if (mutex->thread_list != NULL) { + do { + thread = osRtxThreadListGet((os_object_t*)mutex); + osRtxThreadWaitExit(thread, (uint32_t)osErrorResource, false); + } while (mutex->thread_list != NULL); + } + + osRtxThreadDispatch(NULL); + } + + // Free object memory + if (mutex->flags & osRtxFlagSystemObject) { + if (osRtxInfo.mpi.mutex != NULL) { + osRtxMemoryPoolFree(osRtxInfo.mpi.mutex, mutex); + } else { + osRtxMemoryFree(osRtxInfo.mem.common, mutex); + } + } + + EvrRtxMutexDestroyed(mutex); + + return osOK; +} + + +// ==== Public API ==== + +/// Create and Initialize a Mutex object. +osMutexId_t osMutexNew (const osMutexAttr_t *attr) { + EvrRtxMutexNew(attr); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxMutexError(NULL, osErrorISR); + return NULL; + } + return __svcMutexNew(attr); +} + +/// Get name of a Mutex object. +const char *osMutexGetName (osMutexId_t mutex_id) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxMutexGetName(mutex_id, NULL); + return NULL; + } + return __svcMutexGetName(mutex_id); +} + +/// Acquire a Mutex or timeout if it is locked. +osStatus_t osMutexAcquire (osMutexId_t mutex_id, uint32_t timeout) { + EvrRtxMutexAcquire(mutex_id, timeout); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxMutexError(mutex_id, osErrorISR); + return osErrorISR; + } + return __svcMutexAcquire(mutex_id, timeout); +} + +/// Release a Mutex that was acquired by \ref osMutexAcquire. +osStatus_t osMutexRelease (osMutexId_t mutex_id) { + EvrRtxMutexRelease(mutex_id); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxMutexError(mutex_id, osErrorISR); + return osErrorISR; + } + return __svcMutexRelease(mutex_id); +} + +/// Get Thread which owns a Mutex object. +osThreadId_t osMutexGetOwner (osMutexId_t mutex_id) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxMutexGetOwner(mutex_id, NULL); + return NULL; + } + return __svcMutexGetOwner(mutex_id); +} + +/// Delete a Mutex object. +osStatus_t osMutexDelete (osMutexId_t mutex_id) { + EvrRtxMutexDelete(mutex_id); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxMutexError(mutex_id, osErrorISR); + return osErrorISR; + } + return __svcMutexDelete(mutex_id); +} diff --git a/rtos/TARGET_CORTEX/rtx5/rtx_os.h b/rtos/TARGET_CORTEX/rtx5/rtx_os.h new file mode 100644 index 0000000..fbc243c --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/rtx_os.h @@ -0,0 +1,479 @@ +/* + * Copyright (c) 2013-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * + * Project: CMSIS-RTOS RTX + * Title: RTX OS definitions + * + * ----------------------------------------------------------------------------- + */ + +#ifndef RTX_OS_H_ +#define RTX_OS_H_ + +#include +#include +#include "cmsis_os2.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + + +/// Kernel Information +#define osRtxVersionAPI 20010000 ///< API version (2.1.0) +#define osRtxVersionKernel 50010001 ///< Kernel version (5.1.1) +#define osRtxKernelId "RTX V5.1.1" ///< Kernel identification string + + +// ==== Common definitions ==== + +/// Object Identifier definitions +#define osRtxIdInvalid 0x00U +#define osRtxIdThread 0x01U +#define osRtxIdTimer 0x02U +#define osRtxIdEventFlags 0x03U +#define osRtxIdMutex 0x04U +#define osRtxIdSemaphore 0x05U +#define osRtxIdMemoryPool 0x06U +#define osRtxIdMessage 0x07U +#define osRtxIdMessageQueue 0x08U + +/// Object State definitions (except for Threads and Timers) +#define osRtxObjectInactive 0x00U +#define osRtxObjectActive 0x01U + +/// Object Flags definitions +#define osRtxFlagSystemObject 0x01U +#define osRtxFlagSystemMemory 0x02U + + +// ==== Kernel definitions ==== + +/// Kernel State definitions +#define osRtxKernelInactive ((uint8_t)osKernelInactive) +#define osRtxKernelReady ((uint8_t)osKernelReady) +#define osRtxKernelRunning ((uint8_t)osKernelRunning) +#define osRtxKernelLocked ((uint8_t)osKernelLocked) +#define osRtxKernelSuspended ((uint8_t)osKernelSuspended) + + +// ==== Thread definitions ==== + +/// Thread State definitions (extending osThreadState) +#define osRtxThreadStateMask 0x0FU + +#define osRtxThreadInactive ((uint8_t)osThreadInactive) +#define osRtxThreadReady ((uint8_t)osThreadReady) +#define osRtxThreadRunning ((uint8_t)osThreadRunning) +#define osRtxThreadBlocked ((uint8_t)osThreadBlocked) +#define osRtxThreadTerminated ((uint8_t)osThreadTerminated) + +#define osRtxThreadWaitingDelay (osRtxThreadBlocked | 0x10U) +#define osRtxThreadWaitingJoin (osRtxThreadBlocked | 0x20U) +#define osRtxThreadWaitingThreadFlags (osRtxThreadBlocked | 0x30U) +#define osRtxThreadWaitingEventFlags (osRtxThreadBlocked | 0x40U) +#define osRtxThreadWaitingMutex (osRtxThreadBlocked | 0x50U) +#define osRtxThreadWaitingSemaphore (osRtxThreadBlocked | 0x60U) +#define osRtxThreadWaitingMemoryPool (osRtxThreadBlocked | 0x70U) +#define osRtxThreadWaitingMessageGet (osRtxThreadBlocked | 0x80U) +#define osRtxThreadWaitingMessagePut (osRtxThreadBlocked | 0x90U) + +/// Thread Flags definitions +#define osRtxThreadFlagDefStack 0x10U ///< Default Stack flag + +/// Stack Marker definitions +#define osRtxStackMagicWord 0xE25A2EA5U ///< Stack Magic Word (Stack Base) +#define osRtxStackFillPattern 0xCCCCCCCCU ///< Stack Fill Pattern + +/// Thread Control Block +typedef struct osRtxThread_s { + uint8_t id; ///< Object Identifier + uint8_t state; ///< Object State + uint8_t flags; ///< Object Flags + uint8_t attr; ///< Object Attributes + const char *name; ///< Object Name + struct osRtxThread_s *thread_next; ///< Link pointer to next Thread in Object list + struct osRtxThread_s *thread_prev; ///< Link pointer to previous Thread in Object list + struct osRtxThread_s *delay_next; ///< Link pointer to next Thread in Delay list + struct osRtxThread_s *delay_prev; ///< Link pointer to previous Thread in Delay list + struct osRtxThread_s *thread_join; ///< Thread waiting to Join + uint32_t delay; ///< Delay Time + int8_t priority; ///< Thread Priority + int8_t priority_base; ///< Base Priority + uint8_t stack_frame; ///< Stack Frame (EXC_RETURN[7..0]) + uint8_t flags_options; ///< Thread/Event Flags Options + uint32_t wait_flags; ///< Waiting Thread/Event Flags + uint32_t thread_flags; ///< Thread Flags + struct osRtxMutex_s *mutex_list; ///< Link pointer to list of owned Mutexes + void *stack_mem; ///< Stack Memory + uint32_t stack_size; ///< Stack Size + uint32_t sp; ///< Current Stack Pointer + uint32_t thread_addr; ///< Thread entry address + uint32_t tz_memory; ///< TrustZone Memory Identifier + void *context; ///< Context for OsEventObserver objects +} osRtxThread_t; + + +// ==== Timer definitions ==== + +/// Timer State definitions +#define osRtxTimerInactive 0x00U ///< Timer Inactive +#define osRtxTimerStopped 0x01U ///< Timer Stopped +#define osRtxTimerRunning 0x02U ///< Timer Running + +/// Timer Type definitions +#define osRtxTimerPeriodic ((uint8_t)osTimerPeriodic) + +/// Timer Function Information +typedef struct { + void *fp; ///< Function Pointer + void *arg; ///< Function Argument +} osRtxTimerFinfo_t; + +/// Timer Control Block +typedef struct osRtxTimer_s { + uint8_t id; ///< Object Identifier + uint8_t state; ///< Object State + uint8_t flags; ///< Object Flags + uint8_t type; ///< Timer Type (Periodic/One-shot) + const char *name; ///< Object Name + struct osRtxTimer_s *prev; ///< Pointer to previous active Timer + struct osRtxTimer_s *next; ///< Pointer to next active Timer + uint32_t tick; ///< Timer current Tick + uint32_t load; ///< Timer Load value + osRtxTimerFinfo_t finfo; ///< Timer Function Info +} osRtxTimer_t; + + +// ==== Event Flags definitions ==== + +/// Event Flags Control Block +typedef struct osRtxEventFlags_s { + uint8_t id; ///< Object Identifier + uint8_t state; ///< Object State + uint8_t flags; ///< Object Flags + uint8_t reserved; + const char *name; ///< Object Name + osRtxThread_t *thread_list; ///< Waiting Threads List + uint32_t event_flags; ///< Event Flags +} osRtxEventFlags_t; + + +// ==== Mutex definitions ==== + +/// Mutex Control Block +typedef struct osRtxMutex_s { + uint8_t id; ///< Object Identifier + uint8_t state; ///< Object State + uint8_t flags; ///< Object Flags + uint8_t attr; ///< Object Attributes + const char *name; ///< Object Name + osRtxThread_t *thread_list; ///< Waiting Threads List + osRtxThread_t *owner_thread; ///< Owner Thread + struct osRtxMutex_s *owner_prev; ///< Pointer to previous owned Mutex + struct osRtxMutex_s *owner_next; ///< Pointer to next owned Mutex + uint8_t lock; ///< Lock counter + uint8_t padding[3]; +} osRtxMutex_t; + + +// ==== Semaphore definitions ==== + +/// Semaphore Control Block +typedef struct osRtxSemaphore_s { + uint8_t id; ///< Object Identifier + uint8_t state; ///< Object State + uint8_t flags; ///< Object Flags + uint8_t reserved; + const char *name; ///< Object Name + osRtxThread_t *thread_list; ///< Waiting Threads List + uint16_t tokens; ///< Current number of tokens + uint16_t max_tokens; ///< Maximum number of tokens +} osRtxSemaphore_t; + + +// ==== Memory Pool definitions ==== + +/// Memory Pool Information +typedef struct osRtxMpInfo_s { + uint32_t max_blocks; ///< Maximum number of Blocks + uint32_t used_blocks; ///< Number of used Blocks + uint32_t block_size; ///< Block Size + void *block_base; ///< Block Memory Base Address + void *block_lim; ///< Block Memory Limit Address + void *block_free; ///< First free Block Address +} osRtxMpInfo_t; + +/// Memory Pool Control Block +typedef struct osRtxMemoryPool_s { + uint8_t id; ///< Object Identifier + uint8_t state; ///< Object State + uint8_t flags; ///< Object Flags + uint8_t reserved; + const char *name; ///< Object Name + osRtxThread_t *thread_list; ///< Waiting Threads List + osRtxMpInfo_t mp_info; ///< Memory Pool Info +} osRtxMemoryPool_t; + + +// ==== Message Queue definitions ==== + +/// Message Control Block +typedef struct osRtxMessage_s { + uint8_t id; ///< Object Identifier + uint8_t state; ///< Object State + uint8_t flags; ///< Object Flags + uint8_t priority; ///< Message Priority + struct osRtxMessage_s *prev; ///< Pointer to previous Message + struct osRtxMessage_s *next; ///< Pointer to next Message +} osRtxMessage_t; + +/// Message Queue Control Block +typedef struct osRtxMessageQueue_s { + uint8_t id; ///< Object Identifier + uint8_t state; ///< Object State + uint8_t flags; ///< Object Flags + uint8_t reserved; + const char *name; ///< Object Name + osRtxThread_t *thread_list; ///< Waiting Threads List + osRtxMpInfo_t mp_info; ///< Memory Pool Info + uint32_t msg_size; ///< Message Size + uint32_t msg_count; ///< Number of queued Messages + osRtxMessage_t *msg_first; ///< Pointer to first Message + osRtxMessage_t *msg_last; ///< Pointer to last Message +} osRtxMessageQueue_t; + + +// ==== Generic Object definitions ==== + +/// Generic Object Control Block +typedef struct osRtxObject_s { + uint8_t id; ///< Object Identifier + uint8_t state; ///< Object State + uint8_t flags; ///< Object Flags + uint8_t reserved; + const char *name; ///< Object Name + osRtxThread_t *thread_list; ///< Threads List +} osRtxObject_t; + + +// ==== OS Runtime Information definitions ==== + +/// OS Runtime Information structure +typedef struct { + const char *os_id; ///< OS Identification + uint32_t version; ///< OS Version + struct { ///< Kernel Info + uint8_t state; ///< State + volatile uint8_t blocked; ///< Blocked + uint8_t pendISR; ///< Pending ISR (SV and SysTick) + uint8_t pendSV; ///< Pending SV + uint32_t sys_freq; ///< System Frequency + uint64_t tick; ///< Tick counter + } kernel; + int32_t tick_irqn; ///< Tick Timer IRQ Number + struct { ///< Thread Info + struct { ///< Thread Run Info + osRtxThread_t *curr; ///< Current running Thread + osRtxThread_t *next; ///< Next Thread to Run + } run; + volatile osRtxObject_t ready; ///< Ready List Object + osRtxThread_t *idle; ///< Idle Thread + osRtxThread_t *delay_list; ///< Delay List + osRtxThread_t *wait_list; ///< Wait List (no Timeout) + osRtxThread_t *terminate_list; ///< Terminate Thread List + struct { ///< Thread Round Robin Info + osRtxThread_t *thread; ///< Round Robin Thread + uint32_t tick; ///< Round Robin Time Tick + uint32_t timeout; ///< Round Robin Timeout + } robin; + } thread; + struct { ///< Timer Info + osRtxTimer_t *list; ///< Active Timer List + osRtxThread_t *thread; ///< Timer Thread + osRtxMessageQueue_t *mq; ///< Timer Message Queue + void (*tick)(void); ///< Timer Tick Function + } timer; + struct { ///< ISR Post Processing Queue + uint16_t max; ///< Maximum Items + uint16_t cnt; ///< Item Count + uint16_t in; ///< Incoming Item Index + uint16_t out; ///< Outgoing Item Index + void **data; ///< Queue Data + } isr_queue; + struct { ///< ISR Post Processing functions + void (*thread)(osRtxThread_t*); ///< Thread Post Processing function + void (*event_flags)(osRtxEventFlags_t*); ///< Event Flags Post Processing function + void (*semaphore)(osRtxSemaphore_t*); ///< Semaphore Post Processing function + void (*memory_pool)(osRtxMemoryPool_t*); ///< Memory Pool Post Processing function + void (*message_queue)(osRtxMessage_t*); ///< Message Queue Post Processing function + } post_process; + struct { ///< Memory Pools (Variable Block Size) + void *stack; ///< Stack Memory + void *mp_data; ///< Memory Pool Data Memory + void *mq_data; ///< Message Queue Data Memory + void *common; ///< Common Memory + } mem; + struct { ///< Memory Pools (Fixed Block Size) + osRtxMpInfo_t *stack; ///< Stack for Threads + osRtxMpInfo_t *thread; ///< Thread Control Blocks + osRtxMpInfo_t *timer; ///< Timer Control Blocks + osRtxMpInfo_t *event_flags; ///< Event Flags Control Blocks + osRtxMpInfo_t *mutex; ///< Mutex Control Blocks + osRtxMpInfo_t *semaphore; ///< Semaphore Control Blocks + osRtxMpInfo_t *memory_pool; ///< Memory Pool Control Blocks + osRtxMpInfo_t *message_queue; ///< Message Queue Control Blocks + } mpi; + uint32_t padding; +} osRtxInfo_t; + +extern osRtxInfo_t osRtxInfo; ///< OS Runtime Information + + +// ==== OS API definitions ==== + +/// Object Limits definitions +#define osRtxThreadFlagsLimit 31U ///< number of Thread Flags available per thread +#define osRtxEventFlagsLimit 31U ///< number of Event Flags available per object +#define osRtxMutexLockLimit 255U ///< maximum number of recursive mutex locks +#define osRtxSemaphoreTokenLimit 65535U ///< maximum number of tokens per semaphore + +/// Control Block sizes +#define osRtxThreadCbSize sizeof(osRtxThread_t) +#define osRtxTimerCbSize sizeof(osRtxTimer_t) +#define osRtxEventFlagsCbSize sizeof(osRtxEventFlags_t) +#define osRtxMutexCbSize sizeof(osRtxMutex_t) +#define osRtxSemaphoreCbSize sizeof(osRtxSemaphore_t) +#define osRtxMemoryPoolCbSize sizeof(osRtxMemoryPool_t) +#define osRtxMessageQueueCbSize sizeof(osRtxMessageQueue_t) + +/// Memory size in bytes for Memory Pool storage. +/// \param block_count maximum number of memory blocks in memory pool. +/// \param block_size memory block size in bytes. +#define osRtxMemoryPoolMemSize(block_count, block_size) \ + (4*(block_count)*(((block_size)+3)/4)) + +/// Memory size in bytes for Message Queue storage. +/// \param msg_count maximum number of messages in queue. +/// \param msg_size maximum message size in bytes. +#define osRtxMessageQueueMemSize(msg_count, msg_size) \ + (4*(msg_count)*(3+(((msg_size)+3)/4))) + + +// ==== OS External Functions ==== + +/// OS Error Codes +#define osRtxErrorStackUnderflow 1U +#define osRtxErrorISRQueueOverflow 2U +#define osRtxErrorTimerQueueOverflow 3U +#define osRtxErrorClibSpace 4U +#define osRtxErrorClibMutex 5U + +/// OS Error Callback function +extern uint32_t osRtxErrorNotify (uint32_t code, void *object_id); + +/// OS Idle Thread +extern void osRtxIdleThread (void *argument); + +/// OS Exception handlers +extern void SVC_Handler (void); +extern void PendSV_Handler (void); +extern void SysTick_Handler (void); + + +/// OS System Timer functions (default implementation uses SysTick) + +/// Setup System Timer. +/// \return system timer IRQ number. +extern int32_t osRtxSysTimerSetup (void); + +/// Enable System Timer. +extern void osRtxSysTimerEnable (void); + +/// Disable System Timer. +extern void osRtxSysTimerDisable (void); + +/// Acknowledge System Timer IRQ. +extern void osRtxSysTimerAckIRQ (void); + +/// Get System Timer count. +/// \return system timer count. +extern uint32_t osRtxSysTimerGetCount (void); + +/// Get System Timer frequency. +/// \return system timer frequency. +extern uint32_t osRtxSysTimerGetFreq (void); + + +// ==== OS External Configuration ==== + +/// OS Configuration flags +#define osRtxConfigPrivilegedMode (1UL<<0) ///< Threads in Privileged mode +#define osRtxConfigStackCheck (1UL<<1) ///< Stack overrun checking +#define osRtxConfigStackWatermark (1UL<<2) ///< Stack usage Watermark + +/// OS Configuration structure +typedef struct { + uint32_t flags; ///< OS Configuration Flags + uint32_t tick_freq; ///< Kernel Tick Frequency + uint32_t robin_timeout; ///< Round Robin Timeout Tick + struct { ///< ISR Post Processing Queue + void **data; ///< Queue Data + uint16_t max; ///< Maximum Items + uint16_t padding; + } isr_queue; + struct { ///< Memory Pools (Variable Block Size) + void *stack_addr; ///< Stack Memory Address + uint32_t stack_size; ///< Stack Memory Size + void *mp_data_addr; ///< Memory Pool Memory Address + uint32_t mp_data_size; ///< Memory Pool Memory Size + void *mq_data_addr; ///< Message Queue Data Memory Address + uint32_t mq_data_size; ///< Message Queue Data Memory Size + void *common_addr; ///< Common Memory Address + uint32_t common_size; ///< Common Memory Size + } mem; + struct { ///< Memory Pools (Fixed Block Size) + osRtxMpInfo_t *stack; ///< Stack for Threads + osRtxMpInfo_t *thread; ///< Thread Control Blocks + osRtxMpInfo_t *timer; ///< Timer Control Blocks + osRtxMpInfo_t *event_flags; ///< Event Flags Control Blocks + osRtxMpInfo_t *mutex; ///< Mutex Control Blocks + osRtxMpInfo_t *semaphore; ///< Semaphore Control Blocks + osRtxMpInfo_t *memory_pool; ///< Memory Pool Control Blocks + osRtxMpInfo_t *message_queue; ///< Message Queue Control Blocks + } mpi; + uint32_t thread_stack_size; ///< Default Thread Stack Size + const + osThreadAttr_t *idle_thread_attr; ///< Idle Thread Attributes + const + osThreadAttr_t *timer_thread_attr; ///< Timer Thread Attributes + const + osMessageQueueAttr_t *timer_mq_attr; ///< Timer Message Queue Attributes + uint32_t timer_mq_mcnt; ///< Timer Message Queue maximum Messages +} osRtxConfig_t; + +extern const osRtxConfig_t osRtxConfig; ///< OS Configuration + + +#ifdef __cplusplus +} +#endif + +#endif // RTX_OS_H_ diff --git a/rtos/TARGET_CORTEX/rtx5/rtx_semaphore.c b/rtos/TARGET_CORTEX/rtx5/rtx_semaphore.c new file mode 100644 index 0000000..f0a3c40 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/rtx_semaphore.c @@ -0,0 +1,484 @@ +/* + * Copyright (c) 2013-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * + * Project: CMSIS-RTOS RTX + * Title: Semaphore functions + * + * ----------------------------------------------------------------------------- + */ + +#include "rtx_lib.h" + + +// ==== Helper functions ==== + +/// Decrement Semaphore tokens. +/// \param[in] semaphore semaphore object. +/// \return 1 - success, 0 - failure. +static uint32_t SemaphoreTokenDecrement (os_semaphore_t *semaphore) { +#if (__EXCLUSIVE_ACCESS == 0U) + uint32_t primask = __get_PRIMASK(); +#endif + uint32_t ret; + +#if (__EXCLUSIVE_ACCESS == 0U) + __disable_irq(); + + if (semaphore->tokens != 0U) { + semaphore->tokens--; + ret = 1U; + } else { + ret = 0U; + } + + if (primask == 0U) { + __enable_irq(); + } +#else + if (atomic_dec16_nz(&semaphore->tokens) != 0U) { + ret = 1U; + } else { + ret = 0U; + } +#endif + + return ret; +} + +/// Increment Semaphore tokens. +/// \param[in] semaphore semaphore object. +/// \return 1 - success, 0 - failure. +static uint32_t SemaphoreTokenIncrement (os_semaphore_t *semaphore) { +#if (__EXCLUSIVE_ACCESS == 0U) + uint32_t primask = __get_PRIMASK(); +#endif + uint32_t ret; + +#if (__EXCLUSIVE_ACCESS == 0U) + __disable_irq(); + + if (semaphore->tokens < semaphore->max_tokens) { + semaphore->tokens++; + ret = 1U; + } else { + ret = 0U; + } + + if (primask == 0U) { + __enable_irq(); + } +#else + if (atomic_inc16_lt(&semaphore->tokens, semaphore->max_tokens) < semaphore->max_tokens) { + ret = 1U; + } else { + ret = 0U; + } +#endif + + return ret; +} + + +// ==== Library functions ==== + +/// Semaphore post ISR processing. +/// \param[in] semaphore semaphore object. +void osRtxSemaphorePostProcess (os_semaphore_t *semaphore) { + os_thread_t *thread; + + if (semaphore->state == osRtxObjectInactive) { + return; + } + + // Check if Thread is waiting for a token + if (semaphore->thread_list != NULL) { + // Try to acquire token + if (SemaphoreTokenDecrement(semaphore) != 0U) { + // Wakeup waiting Thread with highest Priority + thread = osRtxThreadListGet((os_object_t*)semaphore); + osRtxThreadWaitExit(thread, (uint32_t)osOK, false); + EvrRtxSemaphoreAcquired(semaphore); + } + } +} + + +// ==== Service Calls ==== + +// Service Calls definitions +SVC0_3M(SemaphoreNew, osSemaphoreId_t, uint32_t, uint32_t, const osSemaphoreAttr_t *) +SVC0_1 (SemaphoreGetName, const char *, osSemaphoreId_t) +SVC0_2 (SemaphoreAcquire, osStatus_t, osSemaphoreId_t, uint32_t) +SVC0_1 (SemaphoreRelease, osStatus_t, osSemaphoreId_t) +SVC0_1 (SemaphoreGetCount, uint32_t, osSemaphoreId_t) +SVC0_1 (SemaphoreDelete, osStatus_t, osSemaphoreId_t) + +/// Create and Initialize a Semaphore object. +/// \note API identical to osSemaphoreNew +osSemaphoreId_t svcRtxSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr) { + os_semaphore_t *semaphore; + uint8_t flags; + const char *name; + + // Check parameters + if ((max_count == 0U) || (max_count > osRtxSemaphoreTokenLimit) || (initial_count > max_count)) { + EvrRtxSemaphoreError(NULL, osErrorParameter); + return NULL; + } + + // Process attributes + if (attr != NULL) { + name = attr->name; + semaphore = attr->cb_mem; + if (semaphore != NULL) { + if (((uint32_t)semaphore & 3U) || (attr->cb_size < sizeof(os_semaphore_t))) { + EvrRtxSemaphoreError(NULL, osRtxErrorInvalidControlBlock); + return NULL; + } + } else { + if (attr->cb_size != 0U) { + EvrRtxSemaphoreError(NULL, osRtxErrorInvalidControlBlock); + return NULL; + } + } + } else { + name = NULL; + semaphore = NULL; + } + + // Allocate object memory if not provided + if (semaphore == NULL) { + if (osRtxInfo.mpi.semaphore != NULL) { + semaphore = osRtxMemoryPoolAlloc(osRtxInfo.mpi.semaphore); + } else { + semaphore = osRtxMemoryAlloc(osRtxInfo.mem.common, sizeof(os_semaphore_t), 1U); + } + if (semaphore == NULL) { + EvrRtxSemaphoreError(NULL, osErrorNoMemory); + return NULL; + } + flags = osRtxFlagSystemObject; + } else { + flags = 0U; + } + + // Initialize control block + semaphore->id = osRtxIdSemaphore; + semaphore->state = osRtxObjectActive; + semaphore->flags = flags; + semaphore->name = name; + semaphore->thread_list = NULL; + semaphore->tokens = (uint16_t)initial_count; + semaphore->max_tokens = (uint16_t)max_count; + + // Register post ISR processing function + osRtxInfo.post_process.semaphore = osRtxSemaphorePostProcess; + + EvrRtxSemaphoreCreated(semaphore); + + return semaphore; +} + +/// Get name of a Semaphore object. +/// \note API identical to osSemaphoreGetName +const char *svcRtxSemaphoreGetName (osSemaphoreId_t semaphore_id) { + os_semaphore_t *semaphore = (os_semaphore_t *)semaphore_id; + + // Check parameters + if ((semaphore == NULL) || (semaphore->id != osRtxIdSemaphore)) { + EvrRtxSemaphoreGetName(semaphore, NULL); + return NULL; + } + + // Check object state + if (semaphore->state == osRtxObjectInactive) { + EvrRtxSemaphoreGetName(semaphore, NULL); + return NULL; + } + + EvrRtxSemaphoreGetName(semaphore, semaphore->name); + + return semaphore->name; +} + +/// Acquire a Semaphore token or timeout if no tokens are available. +/// \note API identical to osSemaphoreAcquire +osStatus_t svcRtxSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout) { + os_semaphore_t *semaphore = (os_semaphore_t *)semaphore_id; + + // Check parameters + if ((semaphore == NULL) || (semaphore->id != osRtxIdSemaphore)) { + EvrRtxSemaphoreError(semaphore, osErrorParameter); + return osErrorParameter; + } + + // Check object state + if (semaphore->state == osRtxObjectInactive) { + EvrRtxSemaphoreError(semaphore, osErrorResource); + return osErrorResource; + } + + // Try to acquire token + if (SemaphoreTokenDecrement(semaphore) == 0U) { + // No token available + if (timeout != 0U) { + EvrRtxSemaphoreAcquirePending(semaphore, timeout); + // Suspend current Thread + osRtxThreadListPut((os_object_t*)semaphore, osRtxThreadGetRunning()); + osRtxThreadWaitEnter(osRtxThreadWaitingSemaphore, timeout); + return osErrorTimeout; + } else { + EvrRtxSemaphoreNotAcquired(semaphore); + return osErrorResource; + } + } + + EvrRtxSemaphoreAcquired(semaphore); + + return osOK; +} + +/// Release a Semaphore token that was acquired by osSemaphoreAcquire. +/// \note API identical to osSemaphoreRelease +osStatus_t svcRtxSemaphoreRelease (osSemaphoreId_t semaphore_id) { + os_semaphore_t *semaphore = (os_semaphore_t *)semaphore_id; + os_thread_t *thread; + + // Check parameters + if ((semaphore == NULL) || (semaphore->id != osRtxIdSemaphore)) { + EvrRtxSemaphoreError(semaphore, osErrorParameter); + return osErrorParameter; + } + + // Check object state + if (semaphore->state == osRtxObjectInactive) { + EvrRtxSemaphoreError(semaphore, osErrorResource); + return osErrorResource; + } + + // Check if Thread is waiting for a token + if (semaphore->thread_list != NULL) { + EvrRtxSemaphoreReleased(semaphore); + // Wakeup waiting Thread with highest Priority + thread = osRtxThreadListGet((os_object_t*)semaphore); + osRtxThreadWaitExit(thread, (uint32_t)osOK, true); + EvrRtxSemaphoreAcquired(semaphore); + } else { + // Try to release token + if (SemaphoreTokenIncrement(semaphore) == 0U) { + EvrRtxSemaphoreError(semaphore, osRtxErrorSemaphoreCountLimit); + return osErrorResource; + } + EvrRtxSemaphoreReleased(semaphore); + } + + return osOK; +} + +/// Get current Semaphore token count. +/// \note API identical to osSemaphoreGetCount +uint32_t svcRtxSemaphoreGetCount (osSemaphoreId_t semaphore_id) { + os_semaphore_t *semaphore = (os_semaphore_t *)semaphore_id; + + // Check parameters + if ((semaphore == NULL) || (semaphore->id != osRtxIdSemaphore)) { + EvrRtxSemaphoreGetCount(semaphore, 0U); + return 0U; + } + + // Check object state + if (semaphore->state == osRtxObjectInactive) { + EvrRtxSemaphoreGetCount(semaphore, 0U); + return 0U; + } + + EvrRtxSemaphoreGetCount(semaphore, semaphore->tokens); + + return semaphore->tokens; +} + +/// Delete a Semaphore object. +/// \note API identical to osSemaphoreDelete +osStatus_t svcRtxSemaphoreDelete (osSemaphoreId_t semaphore_id) { + os_semaphore_t *semaphore = (os_semaphore_t *)semaphore_id; + os_thread_t *thread; + + // Check parameters + if ((semaphore == NULL) || (semaphore->id != osRtxIdSemaphore)) { + EvrRtxSemaphoreError(semaphore, osErrorParameter); + return osErrorParameter; + } + + // Check object state + if (semaphore->state == osRtxObjectInactive) { + EvrRtxSemaphoreError(semaphore, osErrorResource); + return osErrorResource; + } + + // Mark object as inactive + semaphore->state = osRtxObjectInactive; + + // Unblock waiting threads + if (semaphore->thread_list != NULL) { + do { + thread = osRtxThreadListGet((os_object_t*)semaphore); + osRtxThreadWaitExit(thread, (uint32_t)osErrorResource, false); + } while (semaphore->thread_list != NULL); + osRtxThreadDispatch(NULL); + } + + // Free object memory + if (semaphore->flags & osRtxFlagSystemObject) { + if (osRtxInfo.mpi.semaphore != NULL) { + osRtxMemoryPoolFree(osRtxInfo.mpi.semaphore, semaphore); + } else { + osRtxMemoryFree(osRtxInfo.mem.common, semaphore); + } + } + + EvrRtxSemaphoreDestroyed(semaphore); + + return osOK; +} + + +// ==== ISR Calls ==== + +/// Acquire a Semaphore token or timeout if no tokens are available. +/// \note API identical to osSemaphoreAcquire +__STATIC_INLINE +osStatus_t isrRtxSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout) { + os_semaphore_t *semaphore = (os_semaphore_t *)semaphore_id; + + // Check parameters + if ((semaphore == NULL) || (semaphore->id != osRtxIdSemaphore) || (timeout != 0U)) { + EvrRtxSemaphoreError(semaphore, osErrorParameter); + return osErrorParameter; + } + + // Check object state + if (semaphore->state == osRtxObjectInactive) { + EvrRtxSemaphoreError(semaphore, osErrorResource); + return osErrorResource; + } + + // Try to acquire token + if (SemaphoreTokenDecrement(semaphore) == 0U) { + // No token available + EvrRtxSemaphoreNotAcquired(semaphore); + return osErrorResource; + } + + EvrRtxSemaphoreAcquired(semaphore); + + return osOK; +} + +/// Release a Semaphore token that was acquired by osSemaphoreAcquire. +/// \note API identical to osSemaphoreRelease +__STATIC_INLINE +osStatus_t isrRtxSemaphoreRelease (osSemaphoreId_t semaphore_id) { + os_semaphore_t *semaphore = (os_semaphore_t *)semaphore_id; + + // Check parameters + if ((semaphore == NULL) || (semaphore->id != osRtxIdSemaphore)) { + EvrRtxSemaphoreError(semaphore, osErrorParameter); + return osErrorParameter; + } + + // Check object state + if (semaphore->state == osRtxObjectInactive) { + EvrRtxSemaphoreError(semaphore, osErrorResource); + return osErrorResource; + } + + // Try to release token + if (SemaphoreTokenIncrement(semaphore) != 0U) { + // Register post ISR processing + osRtxPostProcess((os_object_t *)semaphore); + } else { + EvrRtxSemaphoreError(semaphore, osRtxErrorSemaphoreCountLimit); + return osErrorResource; + } + + EvrRtxSemaphoreReleased(semaphore); + + return osOK; +} + + +// ==== Public API ==== + +/// Create and Initialize a Semaphore object. +osSemaphoreId_t osSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr) { + EvrRtxSemaphoreNew(max_count, initial_count, attr); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxSemaphoreError(NULL, osErrorISR); + return NULL; + } + return __svcSemaphoreNew(max_count, initial_count, attr); +} + +/// Get name of a Semaphore object. +const char *osSemaphoreGetName (osSemaphoreId_t semaphore_id) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxSemaphoreGetName(semaphore_id, NULL); + return NULL; + } + return __svcSemaphoreGetName(semaphore_id); +} + +/// Acquire a Semaphore token or timeout if no tokens are available. +osStatus_t osSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout) { + EvrRtxSemaphoreAcquire(semaphore_id, timeout); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + return isrRtxSemaphoreAcquire(semaphore_id, timeout); + } else { + return __svcSemaphoreAcquire(semaphore_id, timeout); + } +} + +/// Release a Semaphore token that was acquired by osSemaphoreAcquire. +osStatus_t osSemaphoreRelease (osSemaphoreId_t semaphore_id) { + EvrRtxSemaphoreRelease(semaphore_id); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + return isrRtxSemaphoreRelease(semaphore_id); + } else { + return __svcSemaphoreRelease(semaphore_id); + } +} + +/// Get current Semaphore token count. +uint32_t osSemaphoreGetCount (osSemaphoreId_t semaphore_id) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + return svcRtxSemaphoreGetCount(semaphore_id); + } else { + return __svcSemaphoreGetCount(semaphore_id); + } +} + +/// Delete a Semaphore object. +osStatus_t osSemaphoreDelete (osSemaphoreId_t semaphore_id) { + EvrRtxSemaphoreDelete(semaphore_id); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxSemaphoreError(semaphore_id, osErrorISR); + return osErrorISR; + } + return __svcSemaphoreDelete(semaphore_id); +} diff --git a/rtos/TARGET_CORTEX/rtx5/rtx_system.c b/rtos/TARGET_CORTEX/rtx5/rtx_system.c new file mode 100644 index 0000000..c8715cd --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/rtx_system.c @@ -0,0 +1,257 @@ +/* + * Copyright (c) 2013-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * + * Project: CMSIS-RTOS RTX + * Title: System functions + * + * ----------------------------------------------------------------------------- + */ + +#include "rtx_lib.h" + + +// ==== Helper functions ==== + +/// Put Object into ISR Queue. +/// \param[in] object object. +/// \return 1 - success, 0 - failure. +static uint32_t isr_queue_put (void *object) { +#if (__EXCLUSIVE_ACCESS == 0U) + uint32_t primask = __get_PRIMASK(); +#else + uint32_t n; +#endif + uint16_t max; + uint32_t ret; + + max = osRtxInfo.isr_queue.max; + +#if (__EXCLUSIVE_ACCESS == 0U) + __disable_irq(); + + if (osRtxInfo.isr_queue.cnt < max) { + osRtxInfo.isr_queue.cnt++; + osRtxInfo.isr_queue.data[osRtxInfo.isr_queue.in] = object; + if (++osRtxInfo.isr_queue.in == max) { + osRtxInfo.isr_queue.in = 0U; + } + ret = 1U; + } else { + ret = 0U; + } + + if (primask == 0U) { + __enable_irq(); + } +#else + if (atomic_inc16_lt(&osRtxInfo.isr_queue.cnt, max) < max) { + n = atomic_inc16_lim(&osRtxInfo.isr_queue.in, max); + osRtxInfo.isr_queue.data[n] = object; + ret = 1U; + } else { + ret = 0U; + } +#endif + + return ret; +} + +/// Get Object from ISR Queue. +/// \return object or NULL. +static void *isr_queue_get (void) { +#if (__EXCLUSIVE_ACCESS == 0U) + uint32_t primask = __get_PRIMASK(); +#else + uint32_t n; +#endif + uint16_t max; + void *ret; + + max = osRtxInfo.isr_queue.max; + +#if (__EXCLUSIVE_ACCESS == 0U) + __disable_irq(); + + if (osRtxInfo.isr_queue.cnt != 0U) { + osRtxInfo.isr_queue.cnt--; + ret = osRtxInfo.isr_queue.data[osRtxInfo.isr_queue.out]; + if (++osRtxInfo.isr_queue.out == max) { + osRtxInfo.isr_queue.out = 0U; + } + } else { + ret = NULL; + } + + if (primask == 0U) { + __enable_irq(); + } +#else + if (atomic_dec16_nz(&osRtxInfo.isr_queue.cnt) != 0U) { + n = atomic_inc16_lim(&osRtxInfo.isr_queue.out, max); + ret = osRtxInfo.isr_queue.data[n]; + } else { + ret = NULL; + } +#endif + + return ret; +} + + +// ==== Library Functions ==== + +/// Tick Handler. +void osRtxTick_Handler (void) { + os_thread_t *thread; + + osRtxSysTimerAckIRQ(); + osRtxInfo.kernel.tick++; + + // Process Timers + if (osRtxInfo.timer.tick != NULL) { + osRtxInfo.timer.tick(); + } + + // Process Thread Delays + osRtxThreadDelayTick(); + + osRtxThreadDispatch(NULL); + + // Check Round Robin timeout + if (osRtxInfo.thread.robin.timeout != 0U) { + if (osRtxInfo.thread.robin.thread != osRtxInfo.thread.run.next) { + // Reset Round Robin + osRtxInfo.thread.robin.thread = osRtxInfo.thread.run.next; + osRtxInfo.thread.robin.tick = osRtxInfo.thread.robin.timeout; + } else { + if (osRtxInfo.thread.robin.tick != 0U) { + osRtxInfo.thread.robin.tick--; + } + if (osRtxInfo.thread.robin.tick == 0U) { + // Round Robin Timeout + if (osRtxKernelGetState() == osRtxKernelRunning) { + thread = osRtxInfo.thread.ready.thread_list; + if ((thread != NULL) && (thread->priority == osRtxInfo.thread.robin.thread->priority)) { + osRtxThreadListRemove(thread); + osRtxThreadReadyPut(osRtxInfo.thread.robin.thread); + osRtxThreadSwitch(thread); + osRtxInfo.thread.robin.thread = thread; + osRtxInfo.thread.robin.tick = osRtxInfo.thread.robin.timeout; + } + } + } + } + } +} + +/// Pending Service Call Handler. +void osRtxPendSV_Handler (void) { + os_object_t *object; + + for (;;) { + object = isr_queue_get(); + if (object == NULL) { + break; + } + switch (object->id) { + case osRtxIdThread: + osRtxInfo.post_process.thread((os_thread_t *)object); + break; + case osRtxIdEventFlags: + osRtxInfo.post_process.event_flags((os_event_flags_t *)object); + break; + case osRtxIdSemaphore: + osRtxInfo.post_process.semaphore((os_semaphore_t *)object); + break; + case osRtxIdMemoryPool: + osRtxInfo.post_process.memory_pool((os_memory_pool_t *)object); + break; + case osRtxIdMessage: + osRtxInfo.post_process.message_queue((os_message_t *)object); + break; + default: + break; + } + } + + osRtxThreadDispatch(NULL); +} + +/// Register post ISR processing. +/// \param[in] object generic object. +void osRtxPostProcess (os_object_t *object) { + + if (isr_queue_put(object) != 0U) { + if (osRtxInfo.kernel.blocked == 0U) { + SetPendSV(); + } else { + osRtxInfo.kernel.pendSV = 1U; + } + } else { + osRtxErrorNotify(osRtxErrorISRQueueOverflow, object); + } +} + + +// ==== Public API ==== + +/// Setup System Timer. +__WEAK int32_t osRtxSysTimerSetup (void) { + + // Setup SysTick Timer + SysTick_Setup(osRtxInfo.kernel.sys_freq / osRtxConfig.tick_freq); + + return SysTick_IRQn; // Return IRQ number of SysTick +} + +/// Enable System Timer. +__WEAK void osRtxSysTimerEnable (void) { + SysTick_Enable(); +} + +/// Disable System Timer. +__WEAK void osRtxSysTimerDisable (void) { + SysTick_Disable(); +} + +/// Acknowledge System Timer IRQ. +__WEAK void osRtxSysTimerAckIRQ (void) { + SysTick_GetOvf(); +} + +/// Get System Timer count. +__WEAK uint32_t osRtxSysTimerGetCount (void) { + uint32_t tick; + uint32_t val; + + tick = (uint32_t)osRtxInfo.kernel.tick; + val = SysTick_GetVal(); + if (SysTick_GetOvf()) { + val = SysTick_GetVal(); + tick++; + } + val += tick * SysTick_GetPeriod(); + + return val; +} + +/// Get System Timer frequency. +__WEAK uint32_t osRtxSysTimerGetFreq (void) { + return osRtxInfo.kernel.sys_freq; +} diff --git a/rtos/TARGET_CORTEX/rtx5/rtx_thread.c b/rtos/TARGET_CORTEX/rtx5/rtx_thread.c new file mode 100644 index 0000000..aae22a0 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/rtx_thread.c @@ -0,0 +1,1722 @@ +/* + * Copyright (c) 2013-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * + * Project: CMSIS-RTOS RTX + * Title: Thread functions + * + * ----------------------------------------------------------------------------- + */ + +#include "rtx_lib.h" +#include "rt_OsEventObserver.h" + + +// ==== Helper functions ==== + +/// Set Thread Flags. +/// \param[in] thread thread object. +/// \param[in] flags specifies the flags to set. +/// \return thread flags after setting. +static uint32_t ThreadFlagsSet (os_thread_t *thread, uint32_t flags) { +#if (__EXCLUSIVE_ACCESS == 0U) + uint32_t primask = __get_PRIMASK(); +#endif + uint32_t thread_flags; + +#if (__EXCLUSIVE_ACCESS == 0U) + __disable_irq(); + + thread->thread_flags |= flags; + thread_flags = thread->thread_flags; + + if (primask == 0U) { + __enable_irq(); + } +#else + thread_flags = atomic_set32(&thread->thread_flags, flags); +#endif + + return thread_flags; +} + +/// Clear Thread Flags. +/// \param[in] thread thread object. +/// \param[in] flags specifies the flags to clear. +/// \return thread flags before clearing. +static uint32_t ThreadFlagsClear (os_thread_t *thread, uint32_t flags) { +#if (__EXCLUSIVE_ACCESS == 0U) + uint32_t primask = __get_PRIMASK(); +#endif + uint32_t thread_flags; + +#if (__EXCLUSIVE_ACCESS == 0U) + __disable_irq(); + + thread_flags = thread->thread_flags; + thread->thread_flags &= ~flags; + + if (primask == 0U) { + __enable_irq(); + } +#else + thread_flags = atomic_clr32(&thread->thread_flags, flags); +#endif + + return thread_flags; +} + +/// Check Thread Flags. +/// \param[in] thread thread object. +/// \param[in] flags specifies the flags to check. +/// \param[in] options specifies flags options (osFlagsXxxx). +/// \return thread flags before clearing or 0 if specified flags have not been set. +static uint32_t ThreadFlagsCheck (os_thread_t *thread, uint32_t flags, uint32_t options) { +#if (__EXCLUSIVE_ACCESS == 0U) + uint32_t primask; +#endif + uint32_t thread_flags; + + if ((options & osFlagsNoClear) == 0U) { +#if (__EXCLUSIVE_ACCESS == 0U) + primask = __get_PRIMASK(); + __disable_irq(); + + thread_flags = thread->thread_flags; + if ((((options & osFlagsWaitAll) != 0U) && ((thread_flags & flags) != flags)) || + (((options & osFlagsWaitAll) == 0U) && ((thread_flags & flags) == 0U))) { + thread_flags = 0U; + } else { + thread->thread_flags &= ~flags; + } + + if (primask == 0U) { + __enable_irq(); + } +#else + if ((options & osFlagsWaitAll) != 0U) { + thread_flags = atomic_chk32_all(&thread->thread_flags, flags); + } else { + thread_flags = atomic_chk32_any(&thread->thread_flags, flags); + } +#endif + } else { + thread_flags = thread->thread_flags; + if ((((options & osFlagsWaitAll) != 0U) && ((thread_flags & flags) != flags)) || + (((options & osFlagsWaitAll) == 0U) && ((thread_flags & flags) == 0U))) { + thread_flags = 0U; + } + } + + return thread_flags; +} + + +// ==== Library functions ==== + +/// Put a Thread into specified Object list sorted by Priority (Highest at Head). +/// \param[in] object generic object. +/// \param[in] thread thread object. +void osRtxThreadListPut (volatile os_object_t *object, os_thread_t *thread) { + os_thread_t *prev, *next; + int32_t priority; + + if (thread == NULL) { + return; + } + + priority = thread->priority; + + prev = (os_thread_t *)(uint32_t)object; + next = object->thread_list; + while ((next != NULL) && (next->priority >= priority)) { + prev = next; + next = next->thread_next; + } + thread->thread_prev = prev; + thread->thread_next = next; + prev->thread_next = thread; + if (next != NULL) { + next->thread_prev = thread; + } +} + +/// Get a Thread with Highest Priority from specified Object list and remove it. +/// \param[in] object generic object. +/// \return thread object. +os_thread_t *osRtxThreadListGet (volatile os_object_t *object) { + os_thread_t *thread; + + thread = object->thread_list; + if (thread != NULL) { + object->thread_list = thread->thread_next; + if (thread->thread_next != NULL) { + thread->thread_next->thread_prev = (os_thread_t *)(uint32_t)object; + } + thread->thread_prev = NULL; + } + + return thread; +} + +/// Retrieve Thread list root. +/// \param[in] thread thread object. +void *osRtxThreadListRoot (os_thread_t *thread) { + + while ((thread != NULL) && (thread->id == osRtxIdThread)) { + thread = thread->thread_prev; + } + return ((void *)thread); +} + +/// Re-sort a Thread in linked Object list by Priority (Highest at Head). +/// \param[in] thread thread object. +void osRtxThreadListSort (os_thread_t *thread) { + os_object_t *object; + os_thread_t *thread0; + + // Search for object + thread0 = thread; + while (thread0->id == osRtxIdThread) { + thread0 = thread0->thread_prev; + if (thread0 == NULL) { + return; + } + } + object = (os_object_t *)thread0; + + osRtxThreadListRemove(thread); + osRtxThreadListPut(object, thread); +} + +/// Remove a Thread from linked Object list. +/// \param[in] thread thread object. +void osRtxThreadListRemove (os_thread_t *thread) { + + if (thread->thread_prev != NULL) { + thread->thread_prev->thread_next = thread->thread_next; + if (thread->thread_next != NULL) { + thread->thread_next->thread_prev = thread->thread_prev; + } + thread->thread_prev = NULL; + } +} + +/// Unlink a Thread from specified linked list. +/// \param[in] thread thread object. +void osRtxThreadListUnlink (os_thread_t **thread_list, os_thread_t *thread) { + + if (thread->thread_next != NULL) { + thread->thread_next->thread_prev = thread->thread_prev; + } + if (thread->thread_prev != NULL) { + thread->thread_prev->thread_next = thread->thread_next; + thread->thread_prev = NULL; + } else { + *thread_list = thread->thread_next; + } +} + +/// Mark a Thread as Ready and put it into Ready list (sorted by Priority). +/// \param[in] thread thread object. +void osRtxThreadReadyPut (os_thread_t *thread) { + + thread->state = osRtxThreadReady; + osRtxThreadListPut(&osRtxInfo.thread.ready, thread); +} + +/// Insert a Thread into the Delay list sorted by Delay (Lowest at Head). +/// \param[in] thread thread object. +/// \param[in] delay delay value. +void osRtxThreadDelayInsert (os_thread_t *thread, uint32_t delay) { + os_thread_t *prev, *next; + + if (delay == osWaitForever) { + prev = NULL; + next = osRtxInfo.thread.wait_list; + while (next != NULL) { + prev = next; + next = next->delay_next; + } + thread->delay = delay; + thread->delay_prev = prev; + thread->delay_next = next; + if (prev != NULL) { + prev->delay_next = thread; + } else { + osRtxInfo.thread.wait_list = thread; + } + if (next != NULL) { + next->delay_prev = thread; + } + } else { + prev = NULL; + next = osRtxInfo.thread.delay_list; + while ((next != NULL) && (next->delay <= delay)) { + delay -= next->delay; + prev = next; + next = next->delay_next; + } + thread->delay = delay; + thread->delay_prev = prev; + thread->delay_next = next; + if (prev != NULL) { + prev->delay_next = thread; + } else { + osRtxInfo.thread.delay_list = thread; + } + if (next != NULL) { + next->delay -= delay; + next->delay_prev = thread; + } + } +} + +/// Remove a Thread from the Delay list. +/// \param[in] thread thread object. +void osRtxThreadDelayRemove (os_thread_t *thread) { + + if (thread->delay == osWaitForever) { + if ((thread->delay_prev == NULL) && (osRtxInfo.thread.wait_list != thread)) { + return; + } + if (thread->delay_next != NULL) { + thread->delay_next->delay_prev = thread->delay_prev; + } + if (thread->delay_prev != NULL) { + thread->delay_prev->delay_next = thread->delay_next; + thread->delay_prev = NULL; + } else { + osRtxInfo.thread.wait_list = thread->delay_next; + } + } else { + if ((thread->delay_prev == NULL) && (osRtxInfo.thread.delay_list != thread)) { + return; + } + if (thread->delay_next != NULL) { + thread->delay_next->delay += thread->delay; + thread->delay_next->delay_prev = thread->delay_prev; + } + if (thread->delay_prev != NULL) { + thread->delay_prev->delay_next = thread->delay_next; + thread->delay_prev = NULL; + } else { + osRtxInfo.thread.delay_list = thread->delay_next; + } + } +} + +/// Process Thread Delay Tick (executed each System Tick). +void osRtxThreadDelayTick (void) { + os_thread_t *thread; + + thread = osRtxInfo.thread.delay_list; + if (thread == NULL) { + return; + } + + thread->delay--; + + if (thread->delay == 0U) { + do { + switch (thread->state) { + case osRtxThreadWaitingDelay: + EvrRtxThreadDelayCompleted(); + break; + case osRtxThreadWaitingThreadFlags: + EvrRtxThreadFlagsWaitTimeout(); + break; + case osRtxThreadWaitingEventFlags: + EvrRtxEventFlagsWaitTimeout((osEventFlagsId_t)osRtxThreadListRoot(thread)); + break; + case osRtxThreadWaitingMutex: + EvrRtxMutexAcquireTimeout((osMutexId_t)osRtxThreadListRoot(thread)); + break; + case osRtxThreadWaitingSemaphore: + EvrRtxSemaphoreAcquireTimeout((osSemaphoreId_t)osRtxThreadListRoot(thread)); + break; + case osRtxThreadWaitingMemoryPool: + EvrRtxMemoryPoolAllocTimeout((osMemoryPoolId_t)osRtxThreadListRoot(thread)); + break; + case osRtxThreadWaitingMessageGet: + EvrRtxMessageQueueGetTimeout((osMessageQueueId_t)osRtxThreadListRoot(thread)); + break; + case osRtxThreadWaitingMessagePut: + EvrRtxMessageQueuePutTimeout((osMessageQueueId_t)osRtxThreadListRoot(thread)); + break; + default: + break; + } + EvrRtxThreadUnblocked(thread, (osRtxThreadRegPtr(thread))[0]); + osRtxThreadListRemove(thread); + osRtxThreadReadyPut(thread); + thread = thread->delay_next; + } while ((thread != NULL) && (thread->delay == 0U)); + if (thread != NULL) { + thread->delay_prev = NULL; + } + osRtxInfo.thread.delay_list = thread; + } +} + +/// Get pointer to Thread registers (R0..R3) +/// \param[in] thread thread object. +/// \return pointer to registers R0-R3. +uint32_t *osRtxThreadRegPtr (os_thread_t *thread) { + +#if (__FPU_USED == 1U) + if (IS_EXTENDED_STACK_FRAME(thread->stack_frame)) { + // Extended Stack Frame: S16-S31, R4-R11, R0-R3, R12, LR, PC, xPSR, S0-S15, FPSCR + return ((uint32_t *)(thread->sp + (16U+8U)*4U)); + } else { + // Basic Stack Frame: R4-R11, R0-R3, R12, LR, PC, xPSR + return ((uint32_t *)(thread->sp + 8U *4U)); + } +#else + // Stack Frame: R4-R11, R0-R3, R12, LR, PC, xPSR + return ((uint32_t *)(thread->sp + 8U*4U)); +#endif +} + +/// Block running Thread execution and register it as Ready to Run. +/// \param[in] thread running thread object. +void osRtxThreadBlock (os_thread_t *thread) { + os_thread_t *prev, *next; + int32_t priority; + + thread->state = osRtxThreadReady; + + priority = thread->priority; + + prev = (os_thread_t *)(uint32_t)&osRtxInfo.thread.ready; + next = prev->thread_next; + + while ((next != NULL) && (next->priority > priority)) { + prev = next; + next = next->thread_next; + } + thread->thread_prev = prev; + thread->thread_next = next; + prev->thread_next = thread; + if (next != NULL) { + next->thread_prev = thread; + } +} + +/// Switch to specified Thread. +/// \param[in] thread thread object. +void osRtxThreadSwitch (os_thread_t *thread) { + + thread->state = osRtxThreadRunning; + osRtxInfo.thread.run.next = thread; + osRtxThreadStackCheck(); + EvrRtxThreadSwitch(thread); +} + +/// Notify the OS event observer of an imminent thread switch. +void thread_switch_helper(void) { + if (osEventObs && osEventObs->thread_switch) { + osEventObs->thread_switch(osRtxInfo.thread.run.next->context); + } +} + +/// Dispatch specified Thread or Ready Thread with Highest Priority. +/// \param[in] thread thread object or NULL. +void osRtxThreadDispatch (os_thread_t *thread) { + uint8_t kernel_state; + os_thread_t *thread_running; + + kernel_state = osRtxKernelGetState(); + thread_running = osRtxThreadGetRunning(); + + if (thread == NULL) { + thread = osRtxInfo.thread.ready.thread_list; + if ((kernel_state == osRtxKernelRunning) && + (thread_running != NULL) && (thread != NULL) && + (thread->priority > thread_running->priority)) { + // Preempt running Thread + osRtxThreadListRemove(thread); + osRtxThreadBlock(thread_running); + osRtxThreadSwitch(thread); + } + } else { + if ((kernel_state == osRtxKernelRunning) && + (thread_running != NULL) && + (thread->priority > thread_running->priority)) { + // Preempt running Thread + osRtxThreadBlock(thread_running); + osRtxThreadSwitch(thread); + } else { + // Put Thread into Ready list + osRtxThreadReadyPut(thread); + } + } +} + +/// Exit Thread wait state. +/// \param[in] thread thread object. +/// \param[in] ret_val return value. +/// \param[in] dispatch dispatch flag. +void osRtxThreadWaitExit (os_thread_t *thread, uint32_t ret_val, bool dispatch) { + uint32_t *reg; + + EvrRtxThreadUnblocked(thread, ret_val); + + reg = osRtxThreadRegPtr(thread); + reg[0] = ret_val; + + osRtxThreadDelayRemove(thread); + if (dispatch) { + osRtxThreadDispatch(thread); + } else { + osRtxThreadReadyPut(thread); + } +} + +/// Enter Thread wait state. +/// \param[in] state new thread state. +/// \param[in] timeout timeout. +/// \return true - success, false - failure. +bool osRtxThreadWaitEnter (uint8_t state, uint32_t timeout) { + os_thread_t *thread; + + thread = osRtxThreadGetRunning(); + if (thread == NULL) { + return false; + } + + if (osRtxKernelGetState() != osRtxKernelRunning) { + osRtxThreadListRemove(thread); + return false; + } + + if (osRtxInfo.thread.ready.thread_list == NULL) { + return false; + } + + EvrRtxThreadBlocked(thread, timeout); + + thread->state = state; + osRtxThreadDelayInsert(thread, timeout); + thread = osRtxThreadListGet(&osRtxInfo.thread.ready); + osRtxThreadSwitch(thread); + + return true; +} + +/// Check current running Thread Stack. +__WEAK void osRtxThreadStackCheck (void) { + os_thread_t *thread; + + thread = osRtxThreadGetRunning(); + if (thread != NULL) { + if ((thread->sp <= (uint32_t)thread->stack_mem) || + (*((uint32_t *)thread->stack_mem) != osRtxStackMagicWord)) { + osRtxErrorNotify(osRtxErrorStackUnderflow, thread); + } + } +} + +/// Thread post ISR processing. +/// \param[in] thread thread object. +void osRtxThreadPostProcess (os_thread_t *thread) { + uint32_t thread_flags; + + if ((thread->state == osRtxThreadInactive) || + (thread->state == osRtxThreadTerminated)) { + return; + } + + // Check if Thread is waiting for Thread Flags + if (thread->state == osRtxThreadWaitingThreadFlags) { + thread_flags = ThreadFlagsCheck(thread, thread->wait_flags, thread->flags_options); + if (thread_flags != 0U) { + osRtxThreadWaitExit(thread, thread_flags, false); + EvrRtxThreadFlagsWaitCompleted(thread->wait_flags, thread->flags_options, thread_flags); + } + } +} + + +// ==== Service Calls ==== + +// Service Calls definitions +SVC0_4M(ThreadNew, osThreadId_t, osThreadFunc_t, void *, const osThreadAttr_t *, void *) +SVC0_1 (ThreadGetName, const char *, osThreadId_t) +SVC0_0 (ThreadGetId, osThreadId_t) +SVC0_1 (ThreadGetState, osThreadState_t, osThreadId_t) +SVC0_1 (ThreadGetStackSize, uint32_t, osThreadId_t) +SVC0_1 (ThreadGetStackSpace, uint32_t, osThreadId_t) +SVC0_2 (ThreadSetPriority, osStatus_t, osThreadId_t, osPriority_t) +SVC0_1 (ThreadGetPriority, osPriority_t, osThreadId_t) +SVC0_0 (ThreadYield, osStatus_t) +SVC0_1 (ThreadSuspend, osStatus_t, osThreadId_t) +SVC0_1 (ThreadResume, osStatus_t, osThreadId_t) +SVC0_1 (ThreadDetach, osStatus_t, osThreadId_t) +SVC0_1 (ThreadJoin, osStatus_t, osThreadId_t) +SVC0_0N(ThreadExit, void) +SVC0_1 (ThreadTerminate, osStatus_t, osThreadId_t) +SVC0_0 (ThreadGetCount, uint32_t) +SVC0_2 (ThreadEnumerate, uint32_t, osThreadId_t *, uint32_t) +SVC0_2 (ThreadFlagsSet, uint32_t, osThreadId_t, uint32_t) +SVC0_1 (ThreadFlagsClear, uint32_t, uint32_t) +SVC0_0 (ThreadFlagsGet, uint32_t) +SVC0_3 (ThreadFlagsWait, uint32_t, uint32_t, uint32_t, uint32_t) + +/// Create a thread and add it to Active Threads. +/// \note API identical to osThreadContextNew +osThreadId_t svcRtxThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr, void *context) { + os_thread_t *thread; + uint32_t attr_bits; + void *stack_mem; + uint32_t stack_size; + osPriority_t priority; + uint8_t flags; + const char *name; + uint32_t *ptr; + uint32_t n; +#if (__DOMAIN_NS == 1U) + TZ_ModuleId_t tz_module; + TZ_MemoryId_t tz_memory; +#endif + + // Check parameters + if (func == NULL) { + EvrRtxThreadError(NULL, osErrorParameter); + return NULL; + } + + // Process attributes + if (attr != NULL) { + name = attr->name; + attr_bits = attr->attr_bits; + thread = attr->cb_mem; + stack_mem = attr->stack_mem; + stack_size = attr->stack_size; + priority = attr->priority; +#if (__DOMAIN_NS == 1U) + tz_module = attr->tz_module; +#endif + if (thread != NULL) { + if (((uint32_t)thread & 3U) || (attr->cb_size < sizeof(os_thread_t))) { + EvrRtxThreadError(NULL, osRtxErrorInvalidControlBlock); + return NULL; + } + } else { + if (attr->cb_size != 0U) { + EvrRtxThreadError(NULL, osRtxErrorInvalidControlBlock); + return NULL; + } + } + if (stack_mem != NULL) { + if (((uint32_t)stack_mem & 7U) || (stack_size == 0U)) { + EvrRtxThreadError(NULL, osRtxErrorInvalidThreadStack); + return NULL; + } + } + if (priority == osPriorityNone) { + priority = osPriorityNormal; + } else { + if ((priority < osPriorityIdle) || (priority > osPriorityISR)) { + EvrRtxThreadError(NULL, osRtxErrorInvalidPriority); + return NULL; + } + } + } else { + name = NULL; + attr_bits = 0U; + thread = NULL; + stack_mem = NULL; + stack_size = 0U; + priority = osPriorityNormal; +#if (__DOMAIN_NS == 1U) + tz_module = 0U; +#endif + } + + // Check stack size + if ((stack_size != 0U) && ((stack_size & 7U) || (stack_size < (64U + 8U)))) { + EvrRtxThreadError(NULL, osRtxErrorInvalidThreadStack); + return NULL; + } + + // Allocate object memory if not provided + if (thread == NULL) { + if (osRtxInfo.mpi.thread != NULL) { + thread = osRtxMemoryPoolAlloc(osRtxInfo.mpi.thread); + } else { + thread = osRtxMemoryAlloc(osRtxInfo.mem.common, sizeof(os_thread_t), 1U); + } + if (thread == NULL) { + EvrRtxThreadError(NULL, osErrorNoMemory); + return NULL; + } + flags = osRtxFlagSystemObject; + } else { + flags = 0U; + } + + // Allocate stack memory if not provided + if (stack_mem == NULL) { + if (stack_size == 0U) { + stack_size = osRtxConfig.thread_stack_size; + if (osRtxInfo.mpi.stack != NULL) { + stack_mem = osRtxMemoryPoolAlloc(osRtxInfo.mpi.stack); + if (stack_mem != NULL) { + flags |= osRtxThreadFlagDefStack; + } + } else { + stack_mem = osRtxMemoryAlloc(osRtxInfo.mem.stack, stack_size, 0U); + } + } else { + stack_mem = osRtxMemoryAlloc(osRtxInfo.mem.stack, stack_size, 0U); + } + if (stack_mem == NULL) { + EvrRtxThreadError(NULL, osErrorNoMemory); + if (flags & osRtxFlagSystemObject) { + if (osRtxInfo.mpi.thread != NULL) { + osRtxMemoryPoolFree(osRtxInfo.mpi.thread, thread); + } else { + osRtxMemoryFree(osRtxInfo.mem.common, thread); + } + } + return NULL; + } + flags |= osRtxFlagSystemMemory; + } + +#if (__DOMAIN_NS == 1U) + // Allocate secure process stack + if (tz_module != 0U) { + tz_memory = TZ_AllocModuleContext_S(tz_module); + if (tz_memory == 0U) { + EvrRtxThreadError(NULL, osRtxErrorTZ_AllocContext_S); + if (flags & osRtxFlagSystemMemory) { + if (flags & osRtxThreadFlagDefStack) { + osRtxMemoryPoolFree(osRtxInfo.mpi.stack, thread->stack_mem); + } else { + osRtxMemoryFree(osRtxInfo.mem.stack, thread->stack_mem); + } + } + if (flags & osRtxFlagSystemObject) { + if (osRtxInfo.mpi.thread != NULL) { + osRtxMemoryPoolFree(osRtxInfo.mpi.thread, thread); + } else { + osRtxMemoryFree(osRtxInfo.mem.common, thread); + } + } + return NULL; + } + } else { + tz_memory = 0U; + } +#endif + + // Initialize control block + thread->id = osRtxIdThread; + thread->state = osRtxThreadReady; + thread->flags = flags; + thread->attr = (uint8_t)attr_bits; + thread->name = name; + thread->thread_next = NULL; + thread->thread_prev = NULL; + thread->delay_next = NULL; + thread->delay_prev = NULL; + thread->thread_join = NULL; + thread->delay = 0U; + thread->priority = (int8_t)priority; + thread->priority_base = (int8_t)priority; + thread->stack_frame = STACK_FRAME_INIT; + thread->flags_options = 0U; + thread->wait_flags = 0U; + thread->thread_flags = 0U; + thread->mutex_list = NULL; + thread->stack_mem = stack_mem; + thread->stack_size = stack_size; + thread->sp = (uint32_t)stack_mem + stack_size - 64U; + thread->thread_addr = (uint32_t)func; +#if (__DOMAIN_NS == 1U) + thread->tz_memory = tz_memory; +#endif + + // Initialize stack + ptr = (uint32_t *)stack_mem; + *ptr++ = osRtxStackMagicWord; + if (osRtxConfig.flags & osRtxConfigStackWatermark) { + for (n = (stack_size/4U) - (16U + 1U); n; n--) { + *ptr++ = osRtxStackFillPattern; + } + } else { + ptr = (uint32_t *)thread->sp; + } + for (n = 13U; n; n--) { + *ptr++ = 0U; // R4..R11, R0..R3, R12 + } + *ptr++ = (uint32_t)osThreadExit; // LR + *ptr++ = (uint32_t)func; // PC + *ptr++ = XPSR_INITIAL_VALUE; // xPSR + *(ptr-8) = (uint32_t)argument; // R0 + + // Register post ISR processing function + osRtxInfo.post_process.thread = osRtxThreadPostProcess; + + EvrRtxThreadCreated(thread); + + /* Notify the OS event observer of a new thread. */ + if (osEventObs && osEventObs->thread_create) { + thread->context = osEventObs->thread_create((int)thread, context); + } else { + thread->context = context; + } + + osRtxThreadDispatch(thread); + + return thread; +} + +/// Get name of a thread. +/// \note API identical to osThreadGetName +const char *svcRtxThreadGetName (osThreadId_t thread_id) { + os_thread_t *thread = (os_thread_t *)thread_id; + + // Check parameters + if ((thread == NULL) || (thread->id != osRtxIdThread)) { + EvrRtxThreadGetName(thread, NULL); + return NULL; + } + + // Check object state + if (thread->state == osRtxObjectInactive) { + EvrRtxThreadGetName(thread, NULL); + return NULL; + } + + EvrRtxThreadGetName(thread, thread->name); + + return thread->name; +} + +/// Return the thread ID of the current running thread. +/// \note API identical to osThreadGetId +osThreadId_t svcRtxThreadGetId (void) { + os_thread_t *thread; + + thread = osRtxThreadGetRunning(); + EvrRtxThreadGetId(thread); + return thread; +} + +/// Get current thread state of a thread. +/// \note API identical to osThreadGetState +osThreadState_t svcRtxThreadGetState (osThreadId_t thread_id) { + os_thread_t *thread = (os_thread_t *)thread_id; + + // Check parameters + if ((thread == NULL) || (thread->id != osRtxIdThread)) { + EvrRtxThreadGetState(thread, osThreadError); + return osThreadError; + } + + EvrRtxThreadGetState(thread, (osThreadState_t)(thread->state & osRtxThreadStateMask)); + + return ((osThreadState_t)(thread->state & osRtxThreadStateMask)); +} + +/// Get stack size of a thread. +/// \note API identical to osThreadGetStackSize +uint32_t svcRtxThreadGetStackSize (osThreadId_t thread_id) { + os_thread_t *thread = (os_thread_t *)thread_id; + + // Check parameters + if ((thread == NULL) || (thread->id != osRtxIdThread)) { + EvrRtxThreadGetStackSize(thread, 0U); + return 0U; + } + + // Check object state + if (thread->state == osRtxObjectInactive) { + EvrRtxThreadGetStackSize(thread, 0U); + return 0U; + } + + EvrRtxThreadGetStackSize(thread, thread->stack_size); + + return thread->stack_size; +} + +/// Get available stack space of a thread based on stack watermark recording during execution. +/// \note API identical to osThreadGetStackSpace +uint32_t svcRtxThreadGetStackSpace (osThreadId_t thread_id) { + os_thread_t *thread = (os_thread_t *)thread_id; + uint32_t *stack; + uint32_t space; + + // Check parameters + if ((thread == NULL) || (thread->id != osRtxIdThread)) { + EvrRtxThreadGetStackSpace(thread, 0U); + return 0U; + } + + // Check object state + if (thread->state == osRtxObjectInactive) { + EvrRtxThreadGetStackSpace(thread, 0U); + return 0U; + } + + if ((osRtxConfig.flags & osRtxConfigStackWatermark) == 0U) { + EvrRtxThreadGetStackSpace(thread, 0U); + return 0U; + } + + stack = thread->stack_mem; + if (*stack++ != osRtxStackMagicWord) { + EvrRtxThreadGetStackSpace(thread, 0U); + return 0U; + } + for (space = 4U; space < thread->stack_size; space += 4U) { + if (*stack++ != osRtxStackFillPattern) { + break; + } + } + + EvrRtxThreadGetStackSpace(thread, space); + + return space; +} + +/// Change priority of a thread. +/// \note API identical to osThreadSetPriority +osStatus_t svcRtxThreadSetPriority (osThreadId_t thread_id, osPriority_t priority) { + os_thread_t *thread = (os_thread_t *)thread_id; + + // Check parameters + if ((thread == NULL) || (thread->id != osRtxIdThread) || + (priority < osPriorityIdle) || (priority > osPriorityISR)) { + EvrRtxThreadError(thread, osErrorParameter); + return osErrorParameter; + } + + // Check object state + if ((thread->state == osRtxThreadInactive) || + (thread->state == osRtxThreadTerminated)) { + EvrRtxThreadError(thread, osErrorResource); + return osErrorResource; + } + + if (thread->priority != (int8_t)priority) { + thread->priority = (int8_t)priority; + thread->priority_base = (int8_t)priority; + osRtxThreadListSort(thread); + osRtxThreadDispatch(NULL); + } + + return osOK; +} + +/// Get current priority of a thread. +/// \note API identical to osThreadGetPriority +osPriority_t svcRtxThreadGetPriority (osThreadId_t thread_id) { + os_thread_t *thread = (os_thread_t *)thread_id; + + // Check parameters + if ((thread == NULL) || (thread->id != osRtxIdThread)) { + EvrRtxThreadGetPriority(thread, osPriorityError); + return osPriorityError; + } + + // Check object state + if ((thread->state == osRtxThreadInactive) || + (thread->state == osRtxThreadTerminated)) { + EvrRtxThreadGetPriority(thread, osPriorityError); + return osPriorityError; + } + + EvrRtxThreadGetPriority(thread, (osPriority_t)thread->priority); + + return ((osPriority_t)thread->priority); +} + +/// Pass control to next thread that is in state READY. +/// \note API identical to osThreadYield +osStatus_t svcRtxThreadYield (void) { + uint8_t kernel_state; + os_thread_t *thread_running; + os_thread_t *thread_ready; + + kernel_state = osRtxKernelGetState(); + thread_running = osRtxThreadGetRunning(); + thread_ready = osRtxInfo.thread.ready.thread_list; + if ((kernel_state == osRtxKernelRunning) && + (thread_ready != NULL) && (thread_running != NULL) && + (thread_ready->priority == thread_running->priority)) { + osRtxThreadListRemove(thread_ready); + osRtxThreadReadyPut(thread_running); + osRtxThreadSwitch(thread_ready); + } + + return osOK; +} + +/// Suspend execution of a thread. +/// \note API identical to osThreadSuspend +osStatus_t svcRtxThreadSuspend (osThreadId_t thread_id) { + os_thread_t *thread = (os_thread_t *)thread_id; + + // Check parameters + if ((thread == NULL) || (thread->id != osRtxIdThread)) { + EvrRtxThreadError(thread, osErrorParameter); + return osErrorParameter; + } + + // Check object state + switch (thread->state & osRtxThreadStateMask) { + case osRtxThreadRunning: + if ((osRtxKernelGetState() != osRtxKernelRunning) || + (osRtxInfo.thread.ready.thread_list == NULL)) { + EvrRtxThreadError(thread, osErrorResource); + return osErrorResource; + } + break; + case osRtxThreadReady: + osRtxThreadListRemove(thread); + break; + case osRtxThreadBlocked: + osRtxThreadListRemove(thread); + osRtxThreadDelayRemove(thread); + break; + case osRtxThreadInactive: + case osRtxThreadTerminated: + default: + EvrRtxThreadError(thread, osErrorResource); + return osErrorResource; + } + + EvrRtxThreadSuspended(thread); + + if (thread->state == osRtxThreadRunning) { + osRtxThreadSwitch(osRtxThreadListGet(&osRtxInfo.thread.ready)); + } + + // Update Thread State and put it into Delay list + thread->state = osRtxThreadBlocked; + thread->thread_prev = NULL; + thread->thread_next = NULL; + osRtxThreadDelayInsert(thread, osWaitForever); + + return osOK; +} + +/// Resume execution of a thread. +/// \note API identical to osThreadResume +osStatus_t svcRtxThreadResume (osThreadId_t thread_id) { + os_thread_t *thread = (os_thread_t *)thread_id; + + // Check parameters + if ((thread == NULL) || (thread->id != osRtxIdThread)) { + EvrRtxThreadError(thread, osErrorParameter); + return osErrorParameter; + } + + // Check object state + if ((thread->state & osRtxThreadStateMask) != osRtxThreadBlocked) { + EvrRtxThreadError(thread, osErrorResource); + return osErrorResource; + } + + EvrRtxThreadResumed(thread); + + // Wakeup Thread + osRtxThreadListRemove(thread); + osRtxThreadDelayRemove(thread); + osRtxThreadDispatch(thread); + + return osOK; +} + +/// Free Thread resources. +/// \param[in] thread thread object. +static void osRtxThreadFree (os_thread_t *thread) { + + // Mark object as inactive + thread->state = osRtxThreadInactive; + +#if (__DOMAIN_NS == 1U) + // Free secure process stack + if (thread->tz_memory != 0U) { + TZ_FreeModuleContext_S(thread->tz_memory); + } +#endif + + // Free stack memory + if (thread->flags & osRtxFlagSystemMemory) { + if (thread->flags & osRtxThreadFlagDefStack) { + osRtxMemoryPoolFree(osRtxInfo.mpi.stack, thread->stack_mem); + } else { + osRtxMemoryFree(osRtxInfo.mem.stack, thread->stack_mem); + } + } + + // Free object memory + if (thread->flags & osRtxFlagSystemObject) { + if (osRtxInfo.mpi.thread != NULL) { + osRtxMemoryPoolFree(osRtxInfo.mpi.thread, thread); + } else { + osRtxMemoryFree(osRtxInfo.mem.common, thread); + } + } +} + +/// Detach a thread (thread storage can be reclaimed when thread terminates). +/// \note API identical to osThreadDetach +osStatus_t svcRtxThreadDetach (osThreadId_t thread_id) { + os_thread_t *thread = (os_thread_t *)thread_id; + + // Check parameters + if ((thread == NULL) || (thread->id != osRtxIdThread)) { + EvrRtxThreadError(thread, osErrorParameter); + return osErrorParameter; + } + + // Check object attributes + if ((thread->attr & osThreadJoinable) == 0U) { + EvrRtxThreadError(thread, osRtxErrorThreadNotJoinable); + return osErrorResource; + } + + // Check object state + if (thread->state == osRtxThreadInactive) { + EvrRtxThreadError(thread, osErrorResource); + return osErrorResource; + } + + if (thread->state == osRtxThreadTerminated) { + osRtxThreadListUnlink(&osRtxInfo.thread.terminate_list, thread); + osRtxThreadFree(thread); + } else { + thread->attr &= ~osThreadJoinable; + } + + EvrRtxThreadDetached(thread); + + return osOK; +} + +/// Wait for specified thread to terminate. +/// \note API identical to osThreadJoin +osStatus_t svcRtxThreadJoin (osThreadId_t thread_id) { + os_thread_t *thread = (os_thread_t *)thread_id; + + // Check parameters + if ((thread == NULL) || (thread->id != osRtxIdThread)) { + EvrRtxThreadError(thread, osErrorParameter); + return osErrorParameter; + } + + // Check object attributes + if ((thread->attr & osThreadJoinable) == 0U) { + EvrRtxThreadError(thread, osRtxErrorThreadNotJoinable); + return osErrorResource; + } + + // Check object state + if ((thread->state == osRtxThreadInactive) || + (thread->state == osRtxThreadRunning)) { + EvrRtxThreadError(thread, osErrorResource); + return osErrorResource; + } + + if (thread->state == osRtxThreadTerminated) { + osRtxThreadListUnlink(&osRtxInfo.thread.terminate_list, thread); + osRtxThreadFree(thread); + } else { + EvrRtxThreadJoinPending(thread); + // Suspend current Thread + if (osRtxThreadWaitEnter(osRtxThreadWaitingJoin, osWaitForever)) { + thread->thread_join = osRtxThreadGetRunning(); + } + return osErrorResource; + } + + EvrRtxThreadJoined(thread); + + return osOK; +} + +/// Terminate execution of current running thread. +/// \note API identical to osThreadExit +void svcRtxThreadExit (void) { + os_thread_t *thread; + + thread = osRtxThreadGetRunning(); + if (thread == NULL) { + return; + } + + // Release owned Mutexes + osRtxMutexOwnerRelease(thread->mutex_list); + + // Wakeup Thread waiting to Join + if (thread->thread_join != NULL) { + osRtxThreadWaitExit(thread->thread_join, (uint32_t)osOK, false); + EvrRtxThreadJoined(thread->thread_join); + } + + // Switch to next Ready Thread + if ((osRtxKernelGetState() != osRtxKernelRunning) || + (osRtxInfo.thread.ready.thread_list == NULL)) { + return; + } + thread->sp = __get_PSP(); + osRtxThreadSwitch(osRtxThreadListGet(&osRtxInfo.thread.ready)); + osRtxThreadSetRunning(NULL); + + if (((thread->attr & osThreadJoinable) == 0U) || (thread->thread_join != NULL)) { + osRtxThreadFree(thread); + } else { + // Update Thread State and put it into Terminate Thread list + thread->state = osRtxThreadTerminated; + thread->thread_prev = NULL; + thread->thread_next = osRtxInfo.thread.terminate_list; + if (osRtxInfo.thread.terminate_list != NULL) { + osRtxInfo.thread.terminate_list->thread_prev = thread; + } + osRtxInfo.thread.terminate_list = thread; + } + + EvrRtxThreadDestroyed(thread); +} + +/// Terminate execution of a thread. +/// \note API identical to osThreadTerminate +osStatus_t svcRtxThreadTerminate (osThreadId_t thread_id) { + os_thread_t *thread = (os_thread_t *)thread_id; + + // Check parameters + if ((thread == NULL) || (thread->id != osRtxIdThread)) { + EvrRtxThreadError(thread, osErrorParameter); + return osErrorParameter; + } + + // Check object state + switch (thread->state & osRtxThreadStateMask) { + case osRtxThreadRunning: + break; + case osRtxThreadReady: + osRtxThreadListRemove(thread); + break; + case osRtxThreadBlocked: + osRtxThreadListRemove(thread); + osRtxThreadDelayRemove(thread); + break; + case osRtxThreadInactive: + case osRtxThreadTerminated: + default: + EvrRtxThreadError(thread, osErrorResource); + return osErrorResource; + } + + if (osEventObs && osEventObs->thread_destroy) { + osEventObs->thread_destroy(thread->context); + } + + // Release owned Mutexes + osRtxMutexOwnerRelease(thread->mutex_list); + + // Wakeup Thread waiting to Join + if (thread->thread_join != NULL) { + osRtxThreadWaitExit(thread->thread_join, (uint32_t)osOK, false); + EvrRtxThreadJoined(thread->thread_join); + } + + // Switch to next Ready Thread when terminating running Thread + if (thread->state == osRtxThreadRunning) { + if ((osRtxKernelGetState() != osRtxKernelRunning) || + (osRtxInfo.thread.ready.thread_list == NULL)) { + EvrRtxThreadError(thread, osErrorResource); + return osErrorResource; + } + thread->sp = __get_PSP(); + osRtxThreadSwitch(osRtxThreadListGet(&osRtxInfo.thread.ready)); + osRtxThreadSetRunning(NULL); + } else { + osRtxThreadDispatch(NULL); + } + + if (((thread->attr & osThreadJoinable) == 0U) || (thread->thread_join != NULL)) { + osRtxThreadFree(thread); + } else { + // Update Thread State and put it into Terminate Thread list + thread->state = osRtxThreadTerminated; + thread->thread_prev = NULL; + thread->thread_next = osRtxInfo.thread.terminate_list; + if (osRtxInfo.thread.terminate_list != NULL) { + osRtxInfo.thread.terminate_list->thread_prev = thread; + } + osRtxInfo.thread.terminate_list = thread; + } + + EvrRtxThreadDestroyed(thread); + + return osOK; +} + +/// Get number of active threads. +/// \note API identical to osThreadGetCount +uint32_t svcRtxThreadGetCount (void) { + os_thread_t *thread; + uint32_t count; + + // Running Thread + count = 1U; + + // Ready List + for (thread = osRtxInfo.thread.ready.thread_list; + (thread != NULL); thread = thread->thread_next, count++) {}; + + // Delay List + for (thread = osRtxInfo.thread.delay_list; + (thread != NULL); thread = thread->delay_next, count++) {}; + + // Wait List + for (thread = osRtxInfo.thread.wait_list; + (thread != NULL); thread = thread->delay_next, count++) {}; + + EvrRtxThreadGetCount(count); + + return count; +} + +/// Enumerate active threads. +/// \note API identical to osThreadEnumerate +uint32_t svcRtxThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items) { + os_thread_t *thread; + uint32_t count; + + // Check parameters + if ((thread_array == NULL) || (array_items == 0U)) { + EvrRtxThreadEnumerate(thread_array, array_items, 0U); + return 0U; + } + + // Running Thread + *thread_array++ = osRtxThreadGetRunning(); + count = 1U; + + // Ready List + for (thread = osRtxInfo.thread.ready.thread_list; + (thread != NULL) && (count < array_items); thread = thread->thread_next, count++) { + *thread_array++ = thread; + } + + // Delay List + for (thread = osRtxInfo.thread.delay_list; + (thread != NULL) && (count < array_items); thread = thread->delay_next, count++) { + *thread_array++ = thread; + } + + // Wait List + for (thread = osRtxInfo.thread.wait_list; + (thread != NULL) && (count < array_items); thread = thread->delay_next, count++) { + *thread_array++ = thread; + } + + EvrRtxThreadEnumerate(thread_array - count, array_items, count); + + return count; +} + +/// Set the specified Thread Flags of a thread. +/// \note API identical to osThreadFlagsSet +uint32_t svcRtxThreadFlagsSet (osThreadId_t thread_id, uint32_t flags) { + os_thread_t *thread = (os_thread_t *)thread_id; + uint32_t thread_flags; + uint32_t thread_flags0; + + // Check parameters + if ((thread == NULL) || (thread->id != osRtxIdThread) || + (flags & ~((1U << osRtxThreadFlagsLimit) - 1U))) { + EvrRtxThreadError(thread, osErrorParameter); + return ((uint32_t)osErrorParameter); + } + + // Check object state + if ((thread->state == osRtxThreadInactive) || + (thread->state == osRtxThreadTerminated)) { + EvrRtxThreadError(thread, osErrorResource); + return ((uint32_t)osErrorResource); + } + + // Set Thread Flags + thread_flags = ThreadFlagsSet(thread, flags); + + // Check if Thread is waiting for Thread Flags + if (thread->state == osRtxThreadWaitingThreadFlags) { + thread_flags0 = ThreadFlagsCheck(thread, thread->wait_flags, thread->flags_options); + if (thread_flags0 != 0U) { + if ((thread->flags_options & osFlagsNoClear) == 0U) { + thread_flags = thread_flags0 & ~thread->wait_flags; + } else { + thread_flags = thread_flags0; + } + osRtxThreadWaitExit(thread, thread_flags0, true); + EvrRtxThreadFlagsWaitCompleted(thread->wait_flags, thread->flags_options, thread_flags0); + } + } + + EvrRtxThreadFlagsSetDone(thread, thread_flags); + + return thread_flags; +} + +/// Clear the specified Thread Flags of current running thread. +/// \note API identical to osThreadFlagsClear +uint32_t svcRtxThreadFlagsClear (uint32_t flags) { + os_thread_t *thread; + uint32_t thread_flags; + + thread = osRtxThreadGetRunning(); + if (thread == NULL) { + EvrRtxThreadError(NULL, osRtxErrorKernelNotRunning); + return ((uint32_t)osError); + } + + // Check parameters + if (flags & ~((1U << osRtxThreadFlagsLimit) - 1U)) { + EvrRtxThreadError(thread, osErrorParameter); + return ((uint32_t)osErrorParameter); + } + + // Check object state + if ((thread->state == osRtxThreadInactive) || + (thread->state == osRtxThreadTerminated)) { + EvrRtxThreadError(thread, osErrorResource); + return ((uint32_t)osErrorResource); + } + + // Clear Thread Flags + thread_flags = ThreadFlagsClear(thread, flags); + + EvrRtxThreadFlagsClearDone(thread_flags); + + return thread_flags; +} + +/// Get the current Thread Flags of current running thread. +/// \note API identical to osThreadFlagsGet +uint32_t svcRtxThreadFlagsGet (void) { + os_thread_t *thread; + + thread = osRtxThreadGetRunning(); + if (thread == NULL) { + EvrRtxThreadFlagsGet(0U); + return 0U; + } + + // Check object state + if ((thread->state == osRtxThreadInactive) || + (thread->state == osRtxThreadTerminated)) { + EvrRtxThreadFlagsGet(0U); + return 0U; + } + + EvrRtxThreadFlagsGet(thread->thread_flags); + + return thread->thread_flags; +} + +/// Wait for one or more Thread Flags of the current running thread to become signaled. +/// \note API identical to osThreadFlagsWait +uint32_t svcRtxThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout) { + os_thread_t *thread; + uint32_t thread_flags; + + thread = osRtxThreadGetRunning(); + if (thread == NULL) { + EvrRtxThreadError(NULL, osRtxErrorKernelNotRunning); + return ((uint32_t)osError); + } + + // Check parameters + if (flags & ~((1U << osRtxThreadFlagsLimit) - 1U)) { + EvrRtxThreadError(thread, osErrorParameter); + return ((uint32_t)osErrorParameter); + } + + // Check Thread Flags + thread_flags = ThreadFlagsCheck(thread, flags, options); + if (thread_flags != 0U) { + EvrRtxThreadFlagsWaitCompleted(flags, options, thread_flags); + return thread_flags; + } + + // Check if timeout is specified + if (timeout != 0U) { + // Store waiting flags and options + EvrRtxThreadFlagsWaitPending(flags, options, timeout); + thread->wait_flags = flags; + thread->flags_options = (uint8_t)options; + // Suspend current Thread + osRtxThreadWaitEnter(osRtxThreadWaitingThreadFlags, timeout); + return ((uint32_t)osErrorTimeout); + } + + EvrRtxThreadFlagsWaitNotCompleted(flags, options); + + return ((uint32_t)osErrorResource); +} + + +// ==== ISR Calls ==== + +/// Set the specified Thread Flags of a thread. +/// \note API identical to osThreadFlagsSet +__STATIC_INLINE +uint32_t isrRtxThreadFlagsSet (osThreadId_t thread_id, uint32_t flags) { + os_thread_t *thread = (os_thread_t *)thread_id; + uint32_t thread_flags; + + // Check parameters + if ((thread == NULL) || (thread->id != osRtxIdThread) || + (flags & ~((1U << osRtxThreadFlagsLimit) - 1U))) { + EvrRtxThreadError(thread, osErrorParameter); + return ((uint32_t)osErrorParameter); + } + + // Check object state + if ((thread->state == osRtxThreadInactive) || + (thread->state == osRtxThreadTerminated)) { + EvrRtxThreadError(thread, osErrorResource); + return ((uint32_t)osErrorResource); + } + + // Set Thread Flags + thread_flags = ThreadFlagsSet(thread, flags); + + // Register post ISR processing + osRtxPostProcess((os_object_t *)thread); + + EvrRtxThreadFlagsSetDone(thread, thread_flags); + + return thread_flags; +} + + +// ==== Public API ==== + +/// Create a thread and add it to Active Threads. +osThreadId_t osThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr) { + return osThreadContextNew(func, argument, attr, NULL); +} + +osThreadId_t osThreadContextNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr, void *context) { + EvrRtxThreadNew(func, argument, attr); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxThreadError(NULL, osErrorISR); + return NULL; + } + return __svcThreadNew(func, argument, attr, context); +} + +/// Get name of a thread. +const char *osThreadGetName (osThreadId_t thread_id) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxThreadGetName(thread_id, NULL); + return NULL; + } + return __svcThreadGetName(thread_id); +} + +/// Return the thread ID of the current running thread. +osThreadId_t osThreadGetId (void) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxThreadGetId(NULL); + return NULL; + } + return __svcThreadGetId(); +} + +/// Get current thread state of a thread. +osThreadState_t osThreadGetState (osThreadId_t thread_id) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxThreadGetState(thread_id, osThreadError); + return osThreadError; + } + return __svcThreadGetState(thread_id); +} + +/// Get stack size of a thread. +uint32_t osThreadGetStackSize (osThreadId_t thread_id) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxThreadGetStackSize(thread_id, 0U); + return 0U; + } + return __svcThreadGetStackSize(thread_id); +} + +/// Get available stack space of a thread based on stack watermark recording during execution. +uint32_t osThreadGetStackSpace (osThreadId_t thread_id) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxThreadGetStackSpace(thread_id, 0U); + return 0U; + } + return __svcThreadGetStackSpace(thread_id); +} + +/// Change priority of a thread. +osStatus_t osThreadSetPriority (osThreadId_t thread_id, osPriority_t priority) { + EvrRtxThreadSetPriority(thread_id, priority); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxThreadError(thread_id, osErrorISR); + return osErrorISR; + } + return __svcThreadSetPriority(thread_id, priority); +} + +/// Get current priority of a thread. +osPriority_t osThreadGetPriority (osThreadId_t thread_id) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxThreadGetPriority(thread_id, osPriorityError); + return osPriorityError; + } + return __svcThreadGetPriority(thread_id); +} + +/// Pass control to next thread that is in state READY. +osStatus_t osThreadYield (void) { + EvrRtxThreadYield(); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxThreadError(NULL, osErrorISR); + return osErrorISR; + } + return __svcThreadYield(); +} + +/// Suspend execution of a thread. +osStatus_t osThreadSuspend (osThreadId_t thread_id) { + EvrRtxThreadSuspend(thread_id); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxThreadError(thread_id, osErrorISR); + return osErrorISR; + } + return __svcThreadSuspend(thread_id); +} + +/// Resume execution of a thread. +osStatus_t osThreadResume (osThreadId_t thread_id) { + EvrRtxThreadResume(thread_id); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxThreadError(thread_id, osErrorISR); + return osErrorISR; + } + return __svcThreadResume(thread_id); +} + +/// Detach a thread (thread storage can be reclaimed when thread terminates). +osStatus_t osThreadDetach (osThreadId_t thread_id) { + EvrRtxThreadDetach(thread_id); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxThreadError(thread_id, osErrorISR); + return osErrorISR; + } + return __svcThreadDetach(thread_id); +} + +/// Wait for specified thread to terminate. +osStatus_t osThreadJoin (osThreadId_t thread_id) { + EvrRtxThreadJoin(thread_id); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxThreadError(thread_id, osErrorISR); + return osErrorISR; + } + return __svcThreadJoin(thread_id); +} + +/// Terminate execution of current running thread. +__NO_RETURN void osThreadExit (void) { + EvrRtxThreadExit(); + __svcThreadExit(); + EvrRtxThreadError(NULL, osError); + for (;;); +} + +/// Terminate execution of a thread. +osStatus_t osThreadTerminate (osThreadId_t thread_id) { + EvrRtxThreadTerminate(thread_id); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxThreadError(thread_id, osErrorISR); + return osErrorISR; + } + return __svcThreadTerminate(thread_id); +} + +/// Get number of active threads. +uint32_t osThreadGetCount (void) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxThreadGetCount(0U); + return 0U; + } + return __svcThreadGetCount(); +} + +/// Enumerate active threads. +uint32_t osThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxThreadEnumerate(thread_array, array_items, 0U); + return 0U; + } + return __svcThreadEnumerate(thread_array, array_items); +} + +/// Set the specified Thread Flags of a thread. +uint32_t osThreadFlagsSet (osThreadId_t thread_id, uint32_t flags) { + EvrRtxThreadFlagsSet(thread_id, flags); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + return isrRtxThreadFlagsSet(thread_id, flags); + } else { + return __svcThreadFlagsSet(thread_id, flags); + } +} + +/// Clear the specified Thread Flags of current running thread. +uint32_t osThreadFlagsClear (uint32_t flags) { + EvrRtxThreadFlagsClear(flags); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxThreadError(NULL, osErrorISR); + return ((uint32_t)osErrorISR); + } + return __svcThreadFlagsClear(flags); +} + +/// Get the current Thread Flags of current running thread. +uint32_t osThreadFlagsGet (void) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxThreadFlagsGet(0U); + return 0U; + } + return __svcThreadFlagsGet(); +} + +/// Wait for one or more Thread Flags of the current running thread to become signaled. +uint32_t osThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout) { + EvrRtxThreadFlagsWait(flags, options, timeout); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxThreadError(NULL, osErrorISR); + return ((uint32_t)osErrorISR); + } + return __svcThreadFlagsWait(flags, options, timeout); +} diff --git a/rtos/TARGET_CORTEX/rtx5/rtx_timer.c b/rtos/TARGET_CORTEX/rtx5/rtx_timer.c new file mode 100644 index 0000000..90bd795 --- /dev/null +++ b/rtos/TARGET_CORTEX/rtx5/rtx_timer.c @@ -0,0 +1,415 @@ +/* + * Copyright (c) 2013-2017 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the License); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ----------------------------------------------------------------------------- + * + * Project: CMSIS-RTOS RTX + * Title: Timer functions + * + * ----------------------------------------------------------------------------- + */ + +#include "rtx_lib.h" + + +// ==== Helper functions ==== + +/// Insert Timer into the Timer List sorted by Time. +/// \param[in] timer timer object. +/// \param[in] tick timer tick. +static void TimerInsert (os_timer_t *timer, uint32_t tick) { + os_timer_t *prev, *next; + + prev = NULL; + next = osRtxInfo.timer.list; + while ((next != NULL) && (next->tick <= tick)) { + tick -= next->tick; + prev = next; + next = next->next; + } + timer->tick = tick; + timer->prev = prev; + timer->next = next; + if (next != NULL) { + next->tick -= timer->tick; + next->prev = timer; + } + if (prev != NULL) { + prev->next = timer; + } else { + osRtxInfo.timer.list = timer; + } +} + +/// Remove Timer from the Timer List. +/// \param[in] timer timer object. +static void TimerRemove (os_timer_t *timer) { + + if (timer->next != NULL) { + timer->next->tick += timer->tick; + timer->next->prev = timer->prev; + } + if (timer->prev != NULL) { + timer->prev->next = timer->next; + } else { + osRtxInfo.timer.list = timer->next; + } +} + +/// Unlink Timer from the Timer List Head. +/// \param[in] timer timer object. +static void TimerUnlink (os_timer_t *timer) { + + if (timer->next != NULL) { + timer->next->prev = timer->prev; + } + osRtxInfo.timer.list = timer->next; +} + + +// ==== Library functions ==== + +/// Timer Tick (called each SysTick). +void osRtxTimerTick (void) { + os_timer_t *timer; + osStatus_t status; + + timer = osRtxInfo.timer.list; + if (timer == NULL) { + return; + } + + timer->tick--; + while ((timer != NULL) && (timer->tick == 0U)) { + TimerUnlink(timer); + status = osMessageQueuePut(osRtxInfo.timer.mq, &timer->finfo, 0U, 0U); + if (status != osOK) { + osRtxErrorNotify(osRtxErrorTimerQueueOverflow, timer); + } + if (timer->type == osRtxTimerPeriodic) { + TimerInsert(timer, timer->load); + } else { + timer->state = osRtxTimerStopped; + } + timer = osRtxInfo.timer.list; + } +} + +/// Timer Thread +__WEAK void osRtxTimerThread (void *argument) { + os_timer_finfo_t finfo; + osStatus_t status; + (void) argument; + + osRtxInfo.timer.mq = osMessageQueueNew(osRtxConfig.timer_mq_mcnt, sizeof(os_timer_finfo_t), osRtxConfig.timer_mq_attr); + if (osRtxInfo.timer.mq == NULL) { + return; + } + osRtxInfo.timer.tick = osRtxTimerTick; + for (;;) { + status = osMessageQueueGet(osRtxInfo.timer.mq, &finfo, NULL, osWaitForever); + if (status == osOK) { + EvrRtxTimerCallback(*(osTimerFunc_t)finfo.fp, finfo.arg); + (*(osTimerFunc_t)finfo.fp)(finfo.arg); + } + } +} + +// ==== Service Calls ==== + +// Service Calls definitions +SVC0_4M(TimerNew, osTimerId_t, osTimerFunc_t, osTimerType_t, void *, const osTimerAttr_t *) +SVC0_1 (TimerGetName, const char *, osTimerId_t) +SVC0_2 (TimerStart, osStatus_t, osTimerId_t, uint32_t) +SVC0_1 (TimerStop, osStatus_t, osTimerId_t) +SVC0_1 (TimerIsRunning, uint32_t, osTimerId_t) +SVC0_1 (TimerDelete, osStatus_t, osTimerId_t) + +/// Create and Initialize a timer. +/// \note API identical to osTimerNew +osTimerId_t svcRtxTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr) { + os_timer_t *timer; + uint8_t flags; + const char *name; + + // Check parameters + if ((func == NULL) || ((type != osTimerOnce) && (type != osTimerPeriodic))) { + EvrRtxTimerError(NULL, osErrorParameter); + return NULL; + } + + // Process attributes + if (attr != NULL) { + name = attr->name; + timer = attr->cb_mem; + if (timer != NULL) { + if (((uint32_t)timer & 3U) || (attr->cb_size < sizeof(os_timer_t))) { + EvrRtxTimerError(NULL, osRtxErrorInvalidControlBlock); + return NULL; + } + } else { + if (attr->cb_size != 0U) { + EvrRtxTimerError(NULL, osRtxErrorInvalidControlBlock); + return NULL; + } + } + } else { + name = NULL; + timer = NULL; + } + + // Allocate object memory if not provided + if (timer == NULL) { + if (osRtxInfo.mpi.timer != NULL) { + timer = osRtxMemoryPoolAlloc(osRtxInfo.mpi.timer); + } else { + timer = osRtxMemoryAlloc(osRtxInfo.mem.common, sizeof(os_timer_t), 1U); + } + if (timer == NULL) { + EvrRtxTimerError(NULL, osErrorNoMemory); + return NULL; + } + flags = osRtxFlagSystemObject; + } else { + flags = 0U; + } + + // Initialize control block + timer->id = osRtxIdTimer; + timer->state = osRtxTimerStopped; + timer->flags = flags; + timer->type = (uint8_t)type; + timer->name = name; + timer->prev = NULL; + timer->next = NULL; + timer->tick = 0U; + timer->load = 0U; + timer->finfo.fp = (void *)func; + timer->finfo.arg = argument; + + EvrRtxTimerCreated(timer); + + return timer; +} + +/// Get name of a timer. +/// \note API identical to osTimerGetName +const char *svcRtxTimerGetName (osTimerId_t timer_id) { + os_timer_t *timer = (os_timer_t *)timer_id; + + // Check parameters + if ((timer == NULL) || (timer->id != osRtxIdTimer)) { + EvrRtxTimerGetName(timer, NULL); + return NULL; + } + + // Check object state + if (timer->state == osRtxObjectInactive) { + EvrRtxTimerGetName(timer, NULL); + return NULL; + } + + EvrRtxTimerGetName(timer, timer->name); + + return timer->name; +} + +/// Start or restart a timer. +/// \note API identical to osTimerStart +osStatus_t svcRtxTimerStart (osTimerId_t timer_id, uint32_t ticks) { + os_timer_t *timer = (os_timer_t *)timer_id; + + // Check parameters + if ((timer == NULL) || (timer->id != osRtxIdTimer) || (ticks == 0U)) { + EvrRtxTimerError(timer, osErrorParameter); + return osErrorParameter; + } + + // Check object state + switch (timer->state) { + case osRtxTimerStopped: + if (osRtxInfo.timer.tick == NULL) { + EvrRtxTimerError(timer, osErrorResource); + return osErrorResource; + } + timer->state = osRtxTimerRunning; + timer->load = ticks; + break; + case osRtxTimerRunning: + TimerRemove(timer); + break; + case osRtxTimerInactive: + default: + EvrRtxTimerError(timer, osErrorResource); + return osErrorResource; + } + + TimerInsert(timer, ticks); + + EvrRtxTimerStarted(timer); + + return osOK; +} + +/// Stop a timer. +/// \note API identical to osTimerStop +osStatus_t svcRtxTimerStop (osTimerId_t timer_id) { + os_timer_t *timer = (os_timer_t *)timer_id; + + // Check parameters + if ((timer == NULL) || (timer->id != osRtxIdTimer)) { + EvrRtxTimerError(timer, osErrorParameter); + return osErrorParameter; + } + + // Check object state + if (timer->state != osRtxTimerRunning) { + EvrRtxTimerError(timer, osErrorResource); + return osErrorResource; + } + + timer->state = osRtxTimerStopped; + + TimerRemove(timer); + + EvrRtxTimerStopped(timer); + + return osOK; +} + +/// Check if a timer is running. +/// \note API identical to osTimerIsRunning +uint32_t svcRtxTimerIsRunning (osTimerId_t timer_id) { + os_timer_t *timer = (os_timer_t *)timer_id; + + // Check parameters + if ((timer == NULL) || (timer->id != osRtxIdTimer)) { + EvrRtxTimerIsRunning(timer, 0U); + return 0U; + } + + // Check object state + if (timer->state == osRtxTimerRunning) { + EvrRtxTimerIsRunning(timer, 1U); + return 1U; + } + + EvrRtxTimerIsRunning(timer, 0U); + return 0U; +} + +/// Delete a timer. +/// \note API identical to osTimerDelete +osStatus_t svcRtxTimerDelete (osTimerId_t timer_id) { + os_timer_t *timer = (os_timer_t *)timer_id; + + // Check parameters + if ((timer == NULL) || (timer->id != osRtxIdTimer)) { + EvrRtxTimerError(timer, osErrorParameter); + return osErrorParameter; + } + + // Check object state + switch (timer->state) { + case osRtxTimerStopped: + break; + case osRtxTimerRunning: + TimerRemove(timer); + break; + case osRtxTimerInactive: + default: + EvrRtxTimerError(timer, osErrorResource); + return osErrorResource; + } + + // Mark object as inactive + timer->state = osRtxTimerInactive; + + // Free object memory + if (timer->flags & osRtxFlagSystemObject) { + if (osRtxInfo.mpi.timer != NULL) { + osRtxMemoryPoolFree(osRtxInfo.mpi.timer, timer); + } else { + osRtxMemoryFree(osRtxInfo.mem.common, timer); + } + } + + EvrRtxTimerDestroyed(timer); + + return osOK; +} + + +// ==== Public API ==== + +/// Create and Initialize a timer. +osTimerId_t osTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr) { + EvrRtxTimerNew(func, type, argument, attr); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxTimerError(NULL, osErrorISR); + return NULL; + } + return __svcTimerNew(func, type, argument, attr); +} + +/// Get name of a timer. +const char *osTimerGetName (osTimerId_t timer_id) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxTimerGetName(timer_id, NULL); + return NULL; + } + return __svcTimerGetName(timer_id); +} + +/// Start or restart a timer. +osStatus_t osTimerStart (osTimerId_t timer_id, uint32_t ticks) { + EvrRtxTimerStart(timer_id, ticks); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxTimerError(timer_id, osErrorISR); + return osErrorISR; + } + return __svcTimerStart(timer_id, ticks); +} + +/// Stop a timer. +osStatus_t osTimerStop (osTimerId_t timer_id) { + EvrRtxTimerStop(timer_id); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxTimerError(timer_id, osErrorISR); + return osErrorISR; + } + return __svcTimerStop(timer_id); +} + +/// Check if a timer is running. +uint32_t osTimerIsRunning (osTimerId_t timer_id) { + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxTimerIsRunning(timer_id, 0U); + return 0U; + } + return __svcTimerIsRunning(timer_id); +} + +/// Delete a timer. +osStatus_t osTimerDelete (osTimerId_t timer_id) { + EvrRtxTimerDelete(timer_id); + if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { + EvrRtxTimerError(timer_id, osErrorISR); + return osErrorISR; + } + return __svcTimerDelete(timer_id); +} diff --git a/rtos/mbed_boot.c b/rtos/mbed_boot.c deleted file mode 100644 index 7be1bad..0000000 --- a/rtos/mbed_boot.c +++ /dev/null @@ -1,691 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2006-2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* mbed OS boot sequence - * - * Most of mbed supported targets use default ARM Cortex M boot approach, where the core starts executing reset vector - * after power up. Reset ISR is defined for each target by the vendor (basing on CMSIS template). Reset vector is - * responsible for low level platform init and then calling in libc (__main). Depending on compiler and version of C - * library, predefined function will be called which is implemented by mbed OS. - * - * There's number of functions, vendor and users can provide to setup the platform and/or inject a code to be executed - * before main(): - * * Reset vector and SystemInit: Reset vector should do low level core and board initialization. - * * mbed_sdk_init: Higher level board init and making sure the board is ready for the mbed OS. - * * mbed_main: User's code to be executed before main(). - * * main: Standard application code. - * - * Detailed boot procedures: - * - * For ARMCC: - * ========== - * - * Reset (TARGET) - * -> SystemInit (TARGET) - * -> __main (LIBC) - * -> __rt_entry (MBED: rtos/mbed_boot.c) - * -> __user_setup_stackheap (LIBC) - * -> mbed_set_stack_heap (MBED: rtos/mbed_boot.c) - * -> mbed_cpy_nvic (MBED: rtos/mbed_boot.c) - * -> mbed_sdk_init (TARGET) - * -> _platform_post_stackheap_init (RTX) - * -> osKernelInitialize (RTX) - * -> mbed_start_main (MBED: rtos/mbed_boot.c) - * -> osThreadNew (RTX) - * -> pre_main(MBED: rtos/mbed_boot.c) - * -> __rt_lib_init (LIBC) - * -> $Sub$$main (MBED: rtos/mbed_boot.c) - * -> mbed_main (MBED: rtos/mbed_boot.c) - * -> main (APP) - * -> osKernelStart (RTX) - * - * In addition to the above, libc will use functions defined by RTX: __user_perthread_libspace, _mutex_initialize, - * _mutex_acquire, _mutex_release, _mutex_free for details consult: ARM C and C++ Libraries and Floating-Point - * Support User Guide. - * - * For MICROLIB: - * ========== - * - * Reset (TARGET) - * -> SystemInit (TARGET) - * -> __main (LIBC) - * -> _main_init (MBED: rtos/mbed_boot.c) - * -> mbed_set_stack_heap (MBED: rtos/mbed_boot.c) - * -> mbed_cpy_nvic (MBED: rtos/mbed_boot.c) - * -> mbed_sdk_init (TARGET) - * -> osKernelInitialize (RTX) - * -> mbed_start_main (MBED: rtos/mbed_boot.c) - * -> osThreadNew (RTX) - * -> pre_main(MBED: rtos/mbed_boot.c) - * -> __cpp_initialize__aeabi_ (LIBC) - * -> $Sub$$main (MBED: rtos/mbed_boot.c) - * -> mbed_main (MBED: rtos/mbed_boot.c) - * -> main (APP) - * -> osKernelStart (RTX) - * - * For GCC: - * ======== - * - * Reset (TARGET) - * -> SystemInit (TARGET) - * -> __main (LIBC) - * -> software_init_hook (MBED: rtos/mbed_boot.c) - * -> mbed_set_stack_heap (MBED: rtos/mbed_boot.c) - * -> mbed_cpy_nvic (MBED: rtos/mbed_boot.c) - * -> mbed_sdk_init (TARGET) - * -> osKernelInitialize (RTX) - * -> mbed_start_main (MBED: rtos/mbed_boot.c) - * -> osThreadNew (RTX) - * -> pre_main(MBED: rtos/mbed_boot.c) - * -> __libc_init_array (LIBC) - * -> __wrap_main (MBED: rtos/mbed_boot.c) - * -> mbed_main (MBED: rtos/mbed_boot.c) - * -> __real_main (APP) - * -> osKernelStart (RTX) - * - * For IAR: - * ======== - * - * Reset (TARGET) - * -> SystemInit (TARGET) - * -> __iar_program_start - * -> __iar_init_core - * -> __iar_init_core - * -> __iar_init_vfp - * -> __low_level_init - * -> __iar_data_init3 - * -> mbed_cpy_nvic (MBED: rtos/mbed_boot.c) - * -> mbed_sdk_init (TARGET) - * -> mbed_set_stack_heap (MBED: rtos/mbed_boot.c) - * -> osKernelInitialize (RTX) - * -> mbed_start_main (MBED: rtos/mbed_boot.c) - * -> osThreadNew (RTX) - * -> pre_main(MBED: rtos/mbed_boot.c) - * -> __iar_dynamic_initialization -* -> main - * -> osKernelStart (RTX) - * - * Other notes: - * - * * In addition to the above, libc will use functions defined in mbed_boot.c: __rtos_malloc_lock/unlock, - * __rtos_env_lock/unlock. - * - * * First step after the execution is passed to mbed, software_init_hook for GCC and __rt_entry for ARMC is to - * initialize heap. - * - * Memory layout notes: - * ==================== - * - * IAR Default Memory layout notes: - * -Heap defined by "HEAP" region in .icf file - * -Interrupt stack defined by "CSTACK" region in .icf file - * -Value INITIAL_SP is ignored - * - * IAR Custom Memory layout notes: - * -There is no custom layout available for IAR - everything must be defined in - * the .icf file and use the default layout - * - * - * GCC Default Memory layout notes: - * -Block of memory from symbol __end__ to define INITIAL_SP used to setup interrupt - * stack and heap in the function set_stack_heap() - * -ISR_STACK_SIZE can be overridden to be larger or smaller - * - * GCC Custom Memory layout notes: - * -Heap can be explicitly placed by defining both HEAP_START and HEAP_SIZE - * -Interrupt stack can be explicitly placed by defining both ISR_STACK_START and ISR_STACK_SIZE - * - * - * ARM Memory layout - * -Block of memory from end of region "RW_IRAM1" to define INITIAL_SP used to setup interrupt - * stack and heap in the function set_stack_heap() - * -ISR_STACK_SIZE can be overridden to be larger or smaller - * - * ARM Custom Memory layout notes: - * -Heap can be explicitly placed by defining both HEAP_START and HEAP_SIZE - * -Interrupt stack can be explicitly placed by defining both ISR_STACK_START and ISR_STACK_SIZE - * - */ - -#include - -#include "cmsis.h" -#include "mbed_rtx.h" -#include "mbed_rtos_storage.h" -#include "cmsis_os2.h" -#include "mbed_toolchain.h" -#include "mbed_error.h" - -/* Heap limits - only used if set */ -extern unsigned char *mbed_heap_start; -extern uint32_t mbed_heap_size; - -unsigned char *mbed_stack_isr_start = 0; -uint32_t mbed_stack_isr_size = 0; - -WEAK void mbed_main(void); -void pre_main (void); - -osThreadAttr_t _main_thread_attr; - -/** The main thread's stack size can be configured by the application, if not explicitly specified it'll default to 4K */ -#ifndef MBED_CONF_APP_MAIN_STACK_SIZE -#define MBED_CONF_APP_MAIN_STACK_SIZE 4096 -#endif -MBED_ALIGN(8) char _main_stack[MBED_CONF_APP_MAIN_STACK_SIZE]; -mbed_rtos_storage_thread_t _main_obj; - -osMutexId_t singleton_mutex_id; -mbed_rtos_storage_mutex_t singleton_mutex_obj; -osMutexAttr_t singleton_mutex_attr; - -/* - * Sanity check values - */ -#if defined(__ICCARM__) && \ - (defined(HEAP_START) || defined(HEAP_SIZE) || \ - defined(ISR_STACK_START) && defined(ISR_STACK_SIZE)) - #error "No custom layout allowed for IAR. Use .icf file instead" -#endif -#if defined(HEAP_START) && !defined(HEAP_SIZE) - #error "HEAP_SIZE must be defined if HEAP_START is defined" -#endif -#if defined(ISR_STACK_START) && !defined(ISR_STACK_SIZE) - #error "ISR_STACK_SIZE must be defined if ISR_STACK_START is defined" -#endif -#if defined(HEAP_SIZE) && !defined(HEAP_START) - #error "HEAP_START must be defined if HEAP_SIZE is defined" -#endif - -/* IAR - INITIAL_SP and HEAP_START ignored as described in Memory layout notes above - */ -#if !defined(__ICCARM__) && !defined(INITIAL_SP) && !defined(HEAP_START) - #error "no target defined" -#endif - -/* Interrupt stack and heap always defined for IAR - * Main thread defined here - */ -#if defined(__ICCARM__) - #pragma section="CSTACK" - #pragma section="HEAP" - #define HEAP_START ((unsigned char*)__section_begin("HEAP")) - #define HEAP_SIZE ((uint32_t)__section_size("HEAP")) - #define ISR_STACK_START ((unsigned char*)__section_begin("CSTACK")) - #define ISR_STACK_SIZE ((uint32_t)__section_size("CSTACK")) -#endif - -/* Define heap region if it has not been defined already */ -#if !defined(HEAP_START) - #if defined(__ICCARM__) - #error "Heap should already be defined for IAR" - #elif defined(__CC_ARM) - extern uint32_t Image$$RW_IRAM1$$ZI$$Limit[]; - #define HEAP_START ((unsigned char*)Image$$RW_IRAM1$$ZI$$Limit) - #define HEAP_SIZE ((uint32_t)((uint32_t)INITIAL_SP - (uint32_t)HEAP_START)) - #elif defined(__GNUC__) - extern uint32_t __end__[]; - #define HEAP_START ((unsigned char*)__end__) - #define HEAP_SIZE ((uint32_t)((uint32_t)INITIAL_SP - (uint32_t)HEAP_START)) - #endif -#endif - -/* Define stack sizes if they haven't been set already */ -#if !defined(ISR_STACK_SIZE) - #define ISR_STACK_SIZE ((uint32_t)1024) -#endif - -/* - * mbed_set_stack_heap purpose is to set the following variables: - * -mbed_heap_start - * -mbed_heap_size - * -mbed_stack_isr_start - * -mbed_stack_isr_size - */ -void mbed_set_stack_heap(void) { - - unsigned char *free_start = HEAP_START; - uint32_t free_size = HEAP_SIZE; - -#ifdef ISR_STACK_START - /* Interrupt stack explicitly specified */ - mbed_stack_isr_size = ISR_STACK_SIZE; - mbed_stack_isr_start = ISR_STACK_START; -#else - /* Interrupt stack - reserve space at the end of the free block */ - mbed_stack_isr_size = ISR_STACK_SIZE < free_size ? ISR_STACK_SIZE : free_size; - mbed_stack_isr_start = free_start + free_size - mbed_stack_isr_size; - free_size -= mbed_stack_isr_size; -#endif - - /* Heap - everything else */ - mbed_heap_size = free_size; - mbed_heap_start = free_start; -} - -static void mbed_cpy_nvic(void) -{ - /* If vector address in RAM is defined, copy and switch to dynamic vectors. Exceptions for M0 which doesn't have - VTOR register and for A9 for which CMSIS doesn't define NVIC_SetVector; in both cases target code is - responsible for correctly handling the vectors. - */ -#if !defined(__CORTEX_M0) && !defined(__CORTEX_A9) -#ifdef NVIC_RAM_VECTOR_ADDRESS - uint32_t *old_vectors = (uint32_t *)SCB->VTOR; - uint32_t *vectors = (uint32_t*)NVIC_RAM_VECTOR_ADDRESS; - for (int i = 0; i < NVIC_NUM_VECTORS; i++) { - vectors[i] = old_vectors[i]; - } - SCB->VTOR = (uint32_t)NVIC_RAM_VECTOR_ADDRESS; -#endif /* NVIC_RAM_VECTOR_ADDRESS */ -#endif /* !defined(__CORTEX_M0) && !defined(__CORTEX_A9) */ -} - -/* mbed_main is a function that is called before main() - * mbed_sdk_init() is also a function that is called before main(), but unlike - * mbed_main(), it is not meant for user code, but for the SDK itself to perform - * initializations before main() is called. - */ -WEAK void mbed_main(void) { - -} - -/* This function can be implemented by the target to perform higher level target initialization, before the mbed OS or - * RTX is started. - */ -void mbed_sdk_init(void); -WEAK void mbed_sdk_init(void) { -} - -void mbed_start_main(void) -{ - _main_thread_attr.stack_mem = _main_stack; - _main_thread_attr.stack_size = sizeof(_main_stack); - _main_thread_attr.cb_size = sizeof(_main_obj); - _main_thread_attr.cb_mem = &_main_obj; - _main_thread_attr.priority = osPriorityNormal; - _main_thread_attr.name = "main_thread"; - osThreadId_t result = osThreadNew((osThreadFunc_t)pre_main, NULL, &_main_thread_attr); - if ((void *)result == NULL) { - error("Pre main thread not created"); - } - - osKernelStart(); -} - -/******************** Toolchain specific code ********************/ - -#if defined (__CC_ARM) - -/* Common for both ARMC and MICROLIB */ -int $Super$$main(void); -int $Sub$$main(void) { - mbed_main(); - return $Super$$main(); -} - -#if defined (__MICROLIB) /******************** MICROLIB ********************/ - -int main(void); -void _main_init (void) __attribute__((section(".ARM.Collect$$$$000000FF"))); -void $Super$$__cpp_initialize__aeabi_(void); - -void _main_init (void) { - mbed_set_stack_heap(); - /* Copy the vector table to RAM only if uVisor is not in use. */ -#if !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED)) - mbed_cpy_nvic(); -#endif - mbed_sdk_init(); - osKernelInitialize(); - mbed_start_main(); - for (;;); -} - -void $Sub$$__cpp_initialize__aeabi_(void) -{ - /* This should invoke C++ initializers prior _main_init, we keep this empty and - * invoke them after _main_init, when the RTX is already initilized. - */ -} - -void pre_main() -{ - singleton_mutex_attr.name = "singleton_mutex"; - singleton_mutex_attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust; - singleton_mutex_attr.cb_size = sizeof(singleton_mutex_obj); - singleton_mutex_attr.cb_mem = &singleton_mutex_obj; - singleton_mutex_id = osMutexNew(&singleton_mutex_attr); - - $Super$$__cpp_initialize__aeabi_(); - main(); -} - -#else /******************** ARMC ********************/ - -#include -extern __value_in_regs struct __argc_argv __rt_lib_init(unsigned heapbase, unsigned heaptop); -extern __value_in_regs struct __initial_stackheap __user_setup_stackheap(void); -extern void _platform_post_stackheap_init (void); -extern int main(int argc, char* argv[]); - -void pre_main (void) -{ - singleton_mutex_attr.name = "singleton_mutex"; - singleton_mutex_attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust; - singleton_mutex_attr.cb_size = sizeof(singleton_mutex_obj); - singleton_mutex_attr.cb_mem = &singleton_mutex_obj; - singleton_mutex_id = osMutexNew(&singleton_mutex_attr); - - __rt_lib_init((unsigned)mbed_heap_start, (unsigned)(mbed_heap_start + mbed_heap_size)); - - main(0, NULL); -} - -/* The single memory model is checking for stack collision at run time, verifing - that the heap pointer is underneath the stack pointer. - With the RTOS there is not only one stack above the heap, there are multiple - stacks and some of them are underneath the heap pointer. -*/ -#pragma import(__use_two_region_memory) - -/* Called by the C library */ -void __rt_entry (void) { - __user_setup_stackheap(); - mbed_set_stack_heap(); - /* Copy the vector table to RAM only if uVisor is not in use. */ -#if !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED)) - mbed_cpy_nvic(); -#endif - mbed_sdk_init(); - _platform_post_stackheap_init(); - mbed_start_main(); -} - -typedef void *mutex; - -/* ARM toolchain requires dynamically created mutexes to enforce thread safety. There's - up to 8 static mutexes, protecting atexit, signalinit, stdin, stdout, stderr, stream_list, - fp_trap_init and the heap. Additionally for each call to fopen one extra mutex will be - created. - mbed OS provides a RTX pool for 8 mutexes, to satisfy the static requirements. All - additional mutexes will be allocated on the heap. We can't use the heap allocation for - all the required mutexes, as the heap operations also require a mutex. We don't need to - worry about freeing the allocated memory as library mutexes are only freed when the - application finishes executing. - */ -int _mutex_initialize(mutex *m) -{ - osMutexAttr_t attr; - memset(&attr, 0, sizeof(attr)); - attr.name = "ARM toolchain mutex"; - attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust; - - *m = osMutexNew(&attr); - if (*m != NULL) { - return 1; - } - - /* Mutex pool exhausted, try using HEAP */ - attr.cb_size = sizeof(mbed_rtos_storage_mutex_t); - attr.cb_mem = (void*)malloc(attr.cb_size); - if (attr.cb_mem == NULL) { - osRtxErrorNotify(osRtxErrorClibSpace, m); - return 0; - } - - *m = osMutexNew(&attr); - if (*m == NULL) { - osRtxErrorNotify(osRtxErrorClibMutex, m); - return 0; - } - - return 1; -} - -#endif /* ARMC */ -#elif defined (__GNUC__) /******************** GCC ********************/ - -extern int main(int argc, char* argv[]); -extern void __libc_init_array (void); -extern int __real_main(void); - -osMutexId_t malloc_mutex_id; -mbed_rtos_storage_mutex_t malloc_mutex_obj; -osMutexAttr_t malloc_mutex_attr; - -osMutexId_t env_mutex_id; -mbed_rtos_storage_mutex_t env_mutex_obj; -osMutexAttr_t env_mutex_attr; - -#ifdef FEATURE_UVISOR -#include "uvisor-lib/uvisor-lib.h" -#endif/* FEATURE_UVISOR */ - -int __wrap_main(void) { - mbed_main(); - return __real_main(); -} - -void pre_main(void) -{ - singleton_mutex_attr.name = "singleton_mutex"; - singleton_mutex_attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust; - singleton_mutex_attr.cb_size = sizeof(singleton_mutex_obj); - singleton_mutex_attr.cb_mem = &singleton_mutex_obj; - singleton_mutex_id = osMutexNew(&singleton_mutex_attr); - - malloc_mutex_attr.name = "malloc_mutex"; - malloc_mutex_attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust; - malloc_mutex_attr.cb_size = sizeof(malloc_mutex_obj); - malloc_mutex_attr.cb_mem = &malloc_mutex_obj; - malloc_mutex_id = osMutexNew(&malloc_mutex_attr); - - env_mutex_attr.name = "env_mutex"; - env_mutex_attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust; - env_mutex_attr.cb_size = sizeof(env_mutex_obj); - env_mutex_attr.cb_mem = &env_mutex_obj; - env_mutex_id = osMutexNew(&env_mutex_attr); - - __libc_init_array(); - - main(0, NULL); -} - -void software_init_hook(void) -{ - mbed_set_stack_heap(); - /* Copy the vector table to RAM only if uVisor is not in use. */ -#if !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED)) - mbed_cpy_nvic(); -#endif - mbed_sdk_init(); - osKernelInitialize(); - /* uvisor_lib_init calls RTOS functions, so must be called after the RTOS has - * been initialized. */ -#ifdef FEATURE_UVISOR - int return_code; - - return_code = uvisor_lib_init(); - if (return_code) { - mbed_die(); - } -#endif/* FEATURE_UVISOR */ - mbed_start_main(); -} - -/* Opaque declaration of _reent structure */ -struct _reent; - -void __rtos_malloc_lock( struct _reent *_r ) -{ - osMutexAcquire(malloc_mutex_id, osWaitForever); -} - -void __rtos_malloc_unlock( struct _reent *_r ) -{ - osMutexRelease(malloc_mutex_id); -} - -void __rtos_env_lock( struct _reent *_r ) -{ - osMutexAcquire(env_mutex_id, osWaitForever); -} - -void __rtos_env_unlock( struct _reent *_r ) -{ - osMutexRelease(env_mutex_id); -} - -#endif - -#if defined(TOOLCHAIN_IAR) /******************** IAR ********************/ - -extern void* __vector_table; -extern int __low_level_init(void); -extern void __iar_data_init3(void); -extern __weak void __iar_init_core( void ); -extern __weak void __iar_init_vfp( void ); -extern void __iar_dynamic_initialization(void); -extern void mbed_sdk_init(void); -extern int main(void); -extern void exit(int arg); - -static uint8_t low_level_init_needed; - -void pre_main(void) -{ - singleton_mutex_attr.name = "singleton_mutex"; - singleton_mutex_attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust; - singleton_mutex_attr.cb_size = sizeof(singleton_mutex_obj); - singleton_mutex_attr.cb_mem = &singleton_mutex_obj; - singleton_mutex_id = osMutexNew(&singleton_mutex_attr); - - if (low_level_init_needed) { - __iar_dynamic_initialization(); - } - mbed_main(); - main(); -} - -#pragma required=__vector_table -void __iar_program_start( void ) -{ - __iar_init_core(); - __iar_init_vfp(); - - uint8_t low_level_init_needed_local; - - low_level_init_needed_local = __low_level_init(); - if (low_level_init_needed_local) { - __iar_data_init3(); - - /* Copy the vector table to RAM only if uVisor is not in use. */ -#if !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED)) - mbed_cpy_nvic(); -#endif - mbed_sdk_init(); - } - - mbed_set_stack_heap(); - - /* Store in a global variable after RAM has been initialized */ - low_level_init_needed = low_level_init_needed_local; - - osKernelInitialize(); - - mbed_start_main(); -} - -/* Thread safety */ -static osMutexId_t std_mutex_id_sys[_MAX_LOCK] = {0}; -static mbed_rtos_storage_mutex_t std_mutex_sys[_MAX_LOCK] = {0}; -#define _FOPEN_MAX 10 -static osMutexId_t std_mutex_id_file[_FOPEN_MAX] = {0}; -static mbed_rtos_storage_mutex_t std_mutex_file[_FOPEN_MAX] = {0}; - -void __iar_system_Mtxinit(__iar_Rmtx *mutex) /* Initialize a system lock */ -{ - osMutexAttr_t attr; - uint32_t index; - for (index = 0; index < _MAX_LOCK; index++) { - if (0 == std_mutex_id_sys[index]) { - attr.name = "system_mutex"; - attr.cb_mem = &std_mutex_sys[index]; - attr.cb_size = sizeof(std_mutex_sys[index]); - attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust; - std_mutex_id_sys[index] = osMutexNew(&attr); - *mutex = (__iar_Rmtx*)&std_mutex_id_sys[index]; - return; - } - } - - /* This should never happen */ - error("Not enough mutexes\n"); -} - -void __iar_system_Mtxdst(__iar_Rmtx *mutex) /* Destroy a system lock */ -{ - osMutexDelete(*(osMutexId_t*)*mutex); - *mutex = 0; -} - -void __iar_system_Mtxlock(__iar_Rmtx *mutex) /* Lock a system lock */ -{ - osMutexAcquire(*(osMutexId_t*)*mutex, osWaitForever); -} - -void __iar_system_Mtxunlock(__iar_Rmtx *mutex) /* Unlock a system lock */ -{ - osMutexRelease(*(osMutexId_t*)*mutex); -} - -void __iar_file_Mtxinit(__iar_Rmtx *mutex) /* Initialize a file lock */ -{ - osMutexAttr_t attr; - uint32_t index; - for (index = 0; index < _FOPEN_MAX; index++) { - if (0 == std_mutex_id_file[index]) { - attr.name = "file_mutex"; - attr.cb_mem = &std_mutex_file[index]; - attr.cb_size = sizeof(std_mutex_file[index]); - attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust; - std_mutex_id_file[index] = osMutexNew(&attr); - *mutex = (__iar_Rmtx*)&std_mutex_id_file[index]; - return; - } - } - /* The variable _FOPEN_MAX needs to be increased */ - error("Not enough mutexes\n"); -} - -void __iar_file_Mtxdst(__iar_Rmtx *mutex) /* Destroy a file lock */ -{ - osMutexDelete(*(osMutexId_t*)*mutex); - *mutex = 0; -} - -void __iar_file_Mtxlock(__iar_Rmtx *mutex) /* Lock a file lock */ -{ - osMutexAcquire(*(osMutexId_t*)*mutex, osWaitForever); -} - -void __iar_file_Mtxunlock(__iar_Rmtx *mutex) /* Unlock a file lock */ -{ - osMutexRelease(*(osMutexId_t*)*mutex); -} - -#endif diff --git a/rtos/mbed_rtos1_types.h b/rtos/mbed_rtos1_types.h deleted file mode 100644 index 73df37f..0000000 --- a/rtos/mbed_rtos1_types.h +++ /dev/null @@ -1,27 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2006-2017 ARM Limited - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef MBED_RTOS_RTX1_TYPES_H -#define MBED_RTOS_RTX1_TYPES_H - -#include "rtx4/cmsis_os.h" - -#endif diff --git a/rtos/mbed_rtos_storage.h b/rtos/mbed_rtos_storage.h deleted file mode 100644 index 50e9227..0000000 --- a/rtos/mbed_rtos_storage.h +++ /dev/null @@ -1,60 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2006-2017 ARM Limited - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef MBED_RTOS_STORAGE_H -#define MBED_RTOS_STORAGE_H - -#ifdef __cplusplus -extern "C" { -#endif - -/** \addtogroup rtos */ -/** @{*/ - -/** @brief RTOS primitives storage types for RTX - - Types defined in this file should be utilized, when the direct RTOS C API usage is required, to provide backing memory - for internal RTX data. Allocated object should be wrapped in attribute struct and passed to os*New call, for details - see CMSIS-RTOS2 documentation. - - @note - This file breaks abstraction layers and uses RTX internal types, but it limits the contamination to single, RTOS - implementation specific, header file, therefore limiting scope of possible changes. - */ - -#include "rtx_lib.h" - -typedef os_mutex_t mbed_rtos_storage_mutex_t; -typedef os_semaphore_t mbed_rtos_storage_semaphore_t; -typedef os_thread_t mbed_rtos_storage_thread_t; -typedef os_memory_pool_t mbed_rtos_storage_mem_pool_t; -typedef os_message_queue_t mbed_rtos_storage_msg_queue_t; -typedef os_event_flags_t mbed_rtos_storage_event_flags_t; -typedef os_message_t mbed_rtos_storage_message_t; -typedef os_timer_t mbed_rtos_storage_timer_t; - -#ifdef __cplusplus -} -#endif - -#endif - -/** @}*/ diff --git a/rtos/rtx4/cmsis_os.h b/rtos/rtx4/cmsis_os.h deleted file mode 100644 index 4f7ba11..0000000 --- a/rtos/rtx4/cmsis_os.h +++ /dev/null @@ -1,898 +0,0 @@ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ---------------------------------------------------------------------- - * - * $Date: 10. January 2017 - * $Revision: V2.1.0 - * - * Project: CMSIS-RTOS API - * Title: cmsis_os.h RTX header file - * - * Version 0.02 - * Initial Proposal Phase - * Version 0.03 - * osKernelStart added, optional feature: main started as thread - * osSemaphores have standard behavior - * osTimerCreate does not start the timer, added osTimerStart - * osThreadPass is renamed to osThreadYield - * Version 1.01 - * Support for C++ interface - * - const attribute removed from the osXxxxDef_t typedefs - * - const attribute added to the osXxxxDef macros - * Added: osTimerDelete, osMutexDelete, osSemaphoreDelete - * Added: osKernelInitialize - * Version 1.02 - * Control functions for short timeouts in microsecond resolution: - * Added: osKernelSysTick, osKernelSysTickFrequency, osKernelSysTickMicroSec - * Removed: osSignalGet - * Version 2.0.0 - * OS objects creation without macros (dynamic creation and resource allocation): - * - added: osXxxxNew functions which replace osXxxxCreate - * - added: osXxxxAttr_t structures - * - deprecated: osXxxxCreate functions, osXxxxDef_t structures - * - deprecated: osXxxxDef and osXxxx macros - * osStatus codes simplified and renamed to osStatus_t - * osEvent return structure deprecated - * Kernel: - * - added: osKernelInfo_t and osKernelGetInfo - * - added: osKernelState_t and osKernelGetState (replaces osKernelRunning) - * - added: osKernelLock, osKernelUnlock - * - added: osKernelSuspend, osKernelResume - * - added: osKernelGetTickCount, osKernelGetTickFreq - * - renamed osKernelSysTick to osKernelGetSysTimerCount - * - replaced osKernelSysTickFrequency with osKernelGetSysTimerFreq - * - deprecated osKernelSysTickMicroSec - * Thread: - * - extended number of thread priorities - * - renamed osPrioriry to osPrioriry_t - * - replaced osThreadCreate with osThreadNew - * - added: osThreadGetName - * - added: osThreadState_t and osThreadGetState - * - added: osThreadGetStackSize, osThreadGetStackSpace - * - added: osThreadSuspend, osThreadResume - * - added: osThreadJoin, osThreadDetach, osThreadExit - * - added: osThreadGetCount, osThreadEnumerate - * - added: Thread Flags (moved from Signals) - * Signals: - * - renamed osSignals to osThreadFlags (moved to Thread Flags) - * - changed return value of Set/Clear/Wait functions - * - Clear function limited to current running thread - * - extended Wait function (options) - * - added: osThreadFlagsGet - * Event Flags: - * - added new independent object for handling Event Flags - * Delay and Wait functions: - * - added: osDelayUntil - * - deprecated: osWait - * Timer: - * - replaced osTimerCreate with osTimerNew - * - added: osTimerGetName, osTimerIsRunning - * Mutex: - * - extended: attributes (Recursive, Priority Inherit, Robust) - * - replaced osMutexCreate with osMutexNew - * - renamed osMutexWait to osMutexAcquire - * - added: osMutexGetName, osMutexGetOwner - * Semaphore: - * - extended: maximum and initial token count - * - replaced osSemaphoreCreate with osSemaphoreNew - * - renamed osSemaphoreWait to osSemaphoreAcquire (changed return value) - * - added: osSemaphoreGetName, osSemaphoreGetCount - * Memory Pool: - * - using osMemoryPool prefix instead of osPool - * - replaced osPoolCreate with osMemoryPoolNew - * - extended osMemoryPoolAlloc (timeout) - * - added: osMemoryPoolGetName - * - added: osMemoryPoolGetCapacity, osMemoryPoolGetBlockSize - * - added: osMemoryPoolGetCount, osMemoryPoolGetSpace - * - added: osMemoryPoolDelete - * - deprecated: osPoolCAlloc - * Message Queue: - * - extended: fixed size message instead of a single 32-bit value - * - using osMessageQueue prefix instead of osMessage - * - replaced osMessageCreate with osMessageQueueNew - * - updated: osMessageQueuePut, osMessageQueueGet - * - added: osMessageQueueGetName - * - added: osMessageQueueGetCapacity, osMessageQueueGetMsgSize - * - added: osMessageQueueGetCount, osMessageQueueGetSpace - * - added: osMessageQueueReset, osMessageQueueDelete - * Mail Queue: - * - deprecated (superseded by extended Message Queue functionality) - * Version 2.1.0 - * Support for critical and uncritical sections (nesting safe): - * - updated: osKernelLock, osKernelUnlock - * - added: osKernelRestoreLock - * Updated Thread and Event Flags: - * - changed flags parameter and return type from int32_t to uint32_t - *---------------------------------------------------------------------------*/ - -#ifndef CMSIS_OS_H_ -#define CMSIS_OS_H_ - -#define osCMSIS 0x20001U ///< API version (main[31:16].sub[15:0]) - -#define osCMSIS_RTX 0x50001U ///< RTOS identification and version (main[31:16].sub[15:0]) - -#define osKernelSystemId "RTX V5.1" ///< RTOS identification string - -#define osFeature_MainThread 0 ///< main thread 1=main can be thread, 0=not available -#define osFeature_Signals 31U ///< maximum number of Signal Flags available per thread -#define osFeature_Semaphore 65535U ///< maximum count for \ref osSemaphoreCreate function -#define osFeature_Wait 0 ///< osWait function: 1=available, 0=not available -#define osFeature_SysTick 1 ///< osKernelSysTick functions: 1=available, 0=not available -#define osFeature_Pool 1 ///< Memory Pools: 1=available, 0=not available -#define osFeature_MessageQ 1 ///< Message Queues: 1=available, 0=not available -#define osFeature_MailQ 1 ///< Mail Queues: 1=available, 0=not available - -#if defined(__CC_ARM) -#define os_InRegs __value_in_regs -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) -#define os_InRegs __attribute__((value_in_regs)) -#else -#define os_InRegs -#endif - -#if (osCMSIS >= 0x20000U) -#include "cmsis_os2.h" -#else -#include -#include -#endif -#include "rtx_os.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - -// ==== Enumerations, structures, defines ==== - -/// Priority values. -#if (osCMSIS < 0x20000U) -typedef enum { - osPriorityIdle = -3, ///< Priority: idle (lowest) - osPriorityLow = -2, ///< Priority: low - osPriorityBelowNormal = -1, ///< Priority: below normal - osPriorityNormal = 0, ///< Priority: normal (default) - osPriorityAboveNormal = +1, ///< Priority: above normal - osPriorityHigh = +2, ///< Priority: high - osPriorityRealtime = +3, ///< Priority: realtime (highest) - osPriorityError = 0x84, ///< System cannot determine priority or illegal priority. - osPriorityReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization. -} osPriority; -#else -#define osPriority osPriority_t -#endif - -/// Entry point of a thread. -typedef void (*os_pthread) (void const *argument); - -/// Entry point of a timer call back function. -typedef void (*os_ptimer) (void const *argument); - -/// Timer type. -#if (osCMSIS < 0x20000U) -typedef enum { - osTimerOnce = 0, ///< One-shot timer. - osTimerPeriodic = 1 ///< Repeating timer. -} os_timer_type; -#else -#define os_timer_type osTimerType_t -#endif - -/// Timeout value. -#define osWaitForever 0xFFFFFFFFU ///< Wait forever timeout value. - -/// Status code values returned by CMSIS-RTOS functions. -#if (osCMSIS < 0x20000U) -typedef enum { - osOK = 0, ///< Function completed; no error or event occurred. - osEventSignal = 0x08, ///< Function completed; signal event occurred. - osEventMessage = 0x10, ///< Function completed; message event occurred. - osEventMail = 0x20, ///< Function completed; mail event occurred. - osEventTimeout = 0x40, ///< Function completed; timeout occurred. - osErrorParameter = 0x80, ///< Parameter error: a mandatory parameter was missing or specified an incorrect object. - osErrorResource = 0x81, ///< Resource not available: a specified resource was not available. - osErrorTimeoutResource = 0xC1, ///< Resource not available within given time: a specified resource was not available within the timeout period. - osErrorISR = 0x82, ///< Not allowed in ISR context: the function cannot be called from interrupt service routines. - osErrorISRRecursive = 0x83, ///< Function called multiple times from ISR with same object. - osErrorPriority = 0x84, ///< System cannot determine priority or thread has illegal priority. - osErrorNoMemory = 0x85, ///< System is out of memory: it was impossible to allocate or reserve memory for the operation. - osErrorValue = 0x86, ///< Value of a parameter is out of range. - osErrorOS = 0xFF, ///< Unspecified RTOS error: run-time error but no other error message fits. - osStatusReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization. -} osStatus; -#else -typedef int32_t osStatus; -#define osEventSignal (0x08) -#define osEventMessage (0x10) -#define osEventMail (0x20) -#define osEventTimeout (0x40) -#define osErrorOS osError -#define osErrorTimeoutResource osErrorTimeout -#define osErrorISRRecursive (-126) -#define osErrorValue (-127) -#define osErrorPriority (-128) -#endif - - -// >>> the following data type definitions may be adapted towards a specific RTOS - -/// Thread ID identifies the thread. -#if (osCMSIS < 0x20000U) -typedef void *osThreadId; -#else -#define osThreadId osThreadId_t -#endif - -/// Timer ID identifies the timer. -#if (osCMSIS < 0x20000U) -typedef void *osTimerId; -#else -#define osTimerId osTimerId_t -#endif - -/// Mutex ID identifies the mutex. -#if (osCMSIS < 0x20000U) -typedef void *osMutexId; -#else -#define osMutexId osMutexId_t -#endif - -/// Semaphore ID identifies the semaphore. -#if (osCMSIS < 0x20000U) -typedef void *osSemaphoreId; -#else -#define osSemaphoreId osSemaphoreId_t -#endif - -/// Pool ID identifies the memory pool. -typedef void *osPoolId; - -/// Message ID identifies the message queue. -typedef void *osMessageQId; - -/// Mail ID identifies the mail queue. -typedef void *osMailQId; - - -/// Thread Definition structure contains startup information of a thread. -#if (osCMSIS < 0x20000U) -typedef struct os_thread_def { - os_pthread pthread; ///< start address of thread function - osPriority tpriority; ///< initial thread priority - uint32_t instances; ///< maximum number of instances of that thread function - uint32_t stacksize; ///< stack size requirements in bytes; 0 is default stack size -} osThreadDef_t; -#else -typedef struct os_thread_def { - os_pthread pthread; ///< start address of thread function - osThreadAttr_t attr; ///< thread attributes -} osThreadDef_t; -#endif - -/// Timer Definition structure contains timer parameters. -#if (osCMSIS < 0x20000U) -typedef struct os_timer_def { - os_ptimer ptimer; ///< start address of a timer function -} osTimerDef_t; -#else -typedef struct os_timer_def { - os_ptimer ptimer; ///< start address of a timer function - osTimerAttr_t attr; ///< timer attributes -} osTimerDef_t; -#endif - -/// Mutex Definition structure contains setup information for a mutex. -#if (osCMSIS < 0x20000U) -typedef struct os_mutex_def { - uint32_t dummy; ///< dummy value -} osMutexDef_t; -#else -#define osMutexDef_t osMutexAttr_t -#endif - -/// Semaphore Definition structure contains setup information for a semaphore. -#if (osCMSIS < 0x20000U) -typedef struct os_semaphore_def { - uint32_t dummy; ///< dummy value -} osSemaphoreDef_t; -#else -#define osSemaphoreDef_t osSemaphoreAttr_t -#endif - -/// Definition structure for memory block allocation. -#if (osCMSIS < 0x20000U) -typedef struct os_pool_def { - uint32_t pool_sz; ///< number of items (elements) in the pool - uint32_t item_sz; ///< size of an item - void *pool; ///< pointer to memory for pool -} osPoolDef_t; -#else -typedef struct os_pool_def { - uint32_t pool_sz; ///< number of items (elements) in the pool - uint32_t item_sz; ///< size of an item - osMemoryPoolAttr_t attr; ///< memory pool attributes -} osPoolDef_t; -#endif - -/// Definition structure for message queue. -#if (osCMSIS < 0x20000U) -typedef struct os_messageQ_def { - uint32_t queue_sz; ///< number of elements in the queue - void *pool; ///< memory array for messages -} osMessageQDef_t; -#else -typedef struct os_messageQ_def { - uint32_t queue_sz; ///< number of elements in the queue - osMessageQueueAttr_t attr; ///< message queue attributes -} osMessageQDef_t; -#endif - -/// Definition structure for mail queue. -#if (osCMSIS < 0x20000U) -typedef struct os_mailQ_def { - uint32_t queue_sz; ///< number of elements in the queue - uint32_t item_sz; ///< size of an item - void *pool; ///< memory array for mail -} osMailQDef_t; -#else -typedef struct os_mailQ_def { - uint32_t queue_sz; ///< number of elements in the queue - uint32_t item_sz; ///< size of an item - void *mail; ///< pointer to mail - osMemoryPoolAttr_t mp_attr; ///< memory pool attributes - osMessageQueueAttr_t mq_attr; ///< message queue attributes -} osMailQDef_t; -#endif - - -/// Event structure contains detailed information about an event. -typedef struct { - osStatus status; ///< status code: event or error information - union { - uint32_t v; ///< message as 32-bit value - void *p; ///< message or mail as void pointer - int32_t signals; ///< signal flags - } value; ///< event value - union { - osMailQId mail_id; ///< mail id obtained by \ref osMailCreate - osMessageQId message_id; ///< message id obtained by \ref osMessageCreate - } def; ///< event definition -} osEvent; - - -// ==== Kernel Management Functions ==== - -/// Initialize the RTOS Kernel for creating objects. -/// \return status code that indicates the execution status of the function. -#if (osCMSIS < 0x20000U) -osStatus osKernelInitialize (void); -#endif - -/// Start the RTOS Kernel scheduler. -/// \return status code that indicates the execution status of the function. -#if (osCMSIS < 0x20000U) -osStatus osKernelStart (void); -#endif - -/// Check if the RTOS kernel is already started. -/// \return 0 RTOS is not started, 1 RTOS is started. -#if (osCMSIS < 0x20000U) -int32_t osKernelRunning(void); -#endif - -#if (defined(osFeature_SysTick) && (osFeature_SysTick != 0)) // System Timer available - -/// Get the RTOS kernel system timer counter. -/// \return RTOS kernel system timer as 32-bit value -#if (osCMSIS < 0x20000U) -uint32_t osKernelSysTick (void); -#else -#define osKernelSysTick osKernelGetSysTimerCount -#endif - -/// The RTOS kernel system timer frequency in Hz. -/// \note Reflects the system timer setting and is typically defined in a configuration file. -#if (osCMSIS < 0x20000U) -#define osKernelSysTickFrequency 100000000 -#endif - -/// Convert a microseconds value to a RTOS kernel system timer value. -/// \param microsec time value in microseconds. -/// \return time value normalized to the \ref osKernelSysTickFrequency -#if (osCMSIS < 0x20000U) -#define osKernelSysTickMicroSec(microsec) (((uint64_t)microsec * (osKernelSysTickFrequency)) / 1000000) -#else -#define osKernelSysTickMicroSec(microsec) (((uint64_t)microsec * osKernelGetSysTimerFreq()) / 1000000) -#endif - -#endif // System Timer available - - -// ==== Thread Management Functions ==== - -/// Create a Thread Definition with function, priority, and stack requirements. -/// \param name name of the thread function. -/// \param priority initial priority of the thread function. -/// \param instances number of possible thread instances. -/// \param stacksz stack size (in bytes) requirements for the thread function. -#if defined (osObjectsExternal) // object is external -#define osThreadDef(name, priority, stacksz) \ -extern const osThreadDef_t os_thread_def_##name -#else // define the object -#if (osCMSIS < 0x20000U) -#define osThreadDef(name, priority, stacksz) \ -const osThreadDef_t os_thread_def_##name = \ -{ (name), (priority), (1), (stacksz) } -#else -#define osThreadDef(name, priority, stacksz) \ -uint64_t os_thread_stack##name[(stacksz)?(((stacksz+7)/8)):1] __attribute__((section(".bss.os.thread.stack"))); \ -static osRtxThread_t os_thread_cb_##name __attribute__((section(".bss.os.thread.cb"))); \ -const osThreadDef_t os_thread_def_##name = \ -{ (name), \ - { NULL, osThreadDetached, \ - (&os_thread_cb_##name),\ - osRtxThreadCbSize, \ - (stacksz) ? (&os_thread_stack##name) : NULL, \ - 8*((stacksz+7)/8), \ - (priority), 0U, 0U } } -#endif -#endif - -/// Access a Thread definition. -/// \param name name of the thread definition object. -#define osThread(name) \ -&os_thread_def_##name - -/// Create a thread and add it to Active Threads and set it to state READY. -/// \param[in] thread_def thread definition referenced with \ref osThread. -/// \param[in] argument pointer that is passed to the thread function as start argument. -/// \return thread ID for reference by other functions or NULL in case of error. -osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument); - -/// Return the thread ID of the current running thread. -/// \return thread ID for reference by other functions or NULL in case of error. -#if (osCMSIS < 0x20000U) -osThreadId osThreadGetId (void); -#endif - -/// Change priority of a thread. -/// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. -/// \param[in] priority new priority value for the thread function. -/// \return status code that indicates the execution status of the function. -#if (osCMSIS < 0x20000U) -osStatus osThreadSetPriority (osThreadId thread_id, osPriority priority); -#endif - -/// Get current priority of a thread. -/// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. -/// \return current priority value of the specified thread. -#if (osCMSIS < 0x20000U) -osPriority osThreadGetPriority (osThreadId thread_id); -#endif - -/// Pass control to next thread that is in state \b READY. -/// \return status code that indicates the execution status of the function. -#if (osCMSIS < 0x20000U) -osStatus osThreadYield (void); -#endif - -/// Terminate execution of a thread. -/// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. -/// \return status code that indicates the execution status of the function. -#if (osCMSIS < 0x20000U) -osStatus osThreadTerminate (osThreadId thread_id); -#endif - - -// ==== Signal Management ==== - -/// Set the specified Signal Flags of an active thread. -/// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. -/// \param[in] signals specifies the signal flags of the thread that should be set. -/// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters. -int32_t osSignalSet (osThreadId thread_id, int32_t signals); - -/// Clear the specified Signal Flags of an active thread. -/// \param[in] thread_id thread ID obtained by \ref osThreadCreate or \ref osThreadGetId. -/// \param[in] signals specifies the signal flags of the thread that shall be cleared. -/// \return previous signal flags of the specified thread or 0x80000000 in case of incorrect parameters or call from ISR. -int32_t osSignalClear (osThreadId thread_id, int32_t signals); - -/// Wait for one or more Signal Flags to become signaled for the current \b RUNNING thread. -/// \param[in] signals wait until all specified signal flags set or 0 for any single signal flag. -/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -/// \return event flag information or error code. -os_InRegs osEvent osSignalWait (int32_t signals, uint32_t millisec); - - -// ==== Generic Wait Functions ==== - -/// Wait for Timeout (Time Delay). -/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "time delay" value -/// \return status code that indicates the execution status of the function. -#if (osCMSIS < 0x20000U) -osStatus osDelay (uint32_t millisec); -#endif - -#if (defined (osFeature_Wait) && (osFeature_Wait != 0)) // Generic Wait available - -/// Wait for Signal, Message, Mail, or Timeout. -/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out -/// \return event that contains signal, message, or mail information or error code. -os_InRegs osEvent osWait (uint32_t millisec); - -#endif // Generic Wait available - - -// ==== Timer Management Functions ==== - -/// Define a Timer object. -/// \param name name of the timer object. -/// \param function name of the timer call back function. -#if defined (osObjectsExternal) // object is external -#define osTimerDef(name, function) \ -extern const osTimerDef_t os_timer_def_##name -#else // define the object -#if (osCMSIS < 0x20000U) -#define osTimerDef(name, function) \ -const osTimerDef_t os_timer_def_##name = { (function) } -#else -#define osTimerDef(name, function) \ -static osRtxTimer_t os_timer_cb_##name __attribute__((section(".bss.os.timer.cb"))); \ -const osTimerDef_t os_timer_def_##name = \ -{ (function), { NULL, 0U, (&os_timer_cb_##name), osRtxTimerCbSize } } -#endif -#endif - -/// Access a Timer definition. -/// \param name name of the timer object. -#define osTimer(name) \ -&os_timer_def_##name - -/// Create and Initialize a timer. -/// \param[in] timer_def timer object referenced with \ref osTimer. -/// \param[in] type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior. -/// \param[in] argument argument to the timer call back function. -/// \return timer ID for reference by other functions or NULL in case of error. -osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument); - -/// Start or restart a timer. -/// \param[in] timer_id timer ID obtained by \ref osTimerCreate. -/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue "time delay" value of the timer. -/// \return status code that indicates the execution status of the function. -#if (osCMSIS < 0x20000U) -osStatus osTimerStart (osTimerId timer_id, uint32_t millisec); -#endif - -/// Stop a timer. -/// \param[in] timer_id timer ID obtained by \ref osTimerCreate. -/// \return status code that indicates the execution status of the function. -#if (osCMSIS < 0x20000U) -osStatus osTimerStop (osTimerId timer_id); -#endif - -/// Delete a timer. -/// \param[in] timer_id timer ID obtained by \ref osTimerCreate. -/// \return status code that indicates the execution status of the function. -#if (osCMSIS < 0x20000U) -osStatus osTimerDelete (osTimerId timer_id); -#endif - - -// ==== Mutex Management Functions ==== - -/// Define a Mutex. -/// \param name name of the mutex object. -#if defined (osObjectsExternal) // object is external -#define osMutexDef(name) \ -extern const osMutexDef_t os_mutex_def_##name -#else // define the object -#if (osCMSIS < 0x20000U) -#define osMutexDef(name) \ -const osMutexDef_t os_mutex_def_##name = { 0 } -#else -#define osMutexDef(name) \ -static osRtxMutex_t os_mutex_cb_##name __attribute__((section(".bss.os.mutex.cb"))); \ -const osMutexDef_t os_mutex_def_##name = \ -{ NULL, osMutexRecursive | osMutexPrioInherit | osMutexRobust, (&os_mutex_cb_##name), osRtxMutexCbSize } -#endif -#endif - -/// Access a Mutex definition. -/// \param name name of the mutex object. -#define osMutex(name) \ -&os_mutex_def_##name - -/// Create and Initialize a Mutex object. -/// \param[in] mutex_def mutex definition referenced with \ref osMutex. -/// \return mutex ID for reference by other functions or NULL in case of error. -osMutexId osMutexCreate (const osMutexDef_t *mutex_def); - -/// Wait until a Mutex becomes available. -/// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate. -/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -/// \return status code that indicates the execution status of the function. -#if (osCMSIS < 0x20000U) -osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec); -#else -#define osMutexWait osMutexAcquire -#endif - -/// Release a Mutex that was obtained by \ref osMutexWait. -/// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate. -/// \return status code that indicates the execution status of the function. -#if (osCMSIS < 0x20000U) -osStatus osMutexRelease (osMutexId mutex_id); -#endif - -/// Delete a Mutex object. -/// \param[in] mutex_id mutex ID obtained by \ref osMutexCreate. -/// \return status code that indicates the execution status of the function. -#if (osCMSIS < 0x20000U) -osStatus osMutexDelete (osMutexId mutex_id); -#endif - - -// ==== Semaphore Management Functions ==== - -#if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0U)) // Semaphore available - -/// Define a Semaphore object. -/// \param name name of the semaphore object. -#if defined (osObjectsExternal) // object is external -#define osSemaphoreDef(name) \ -extern const osSemaphoreDef_t os_semaphore_def_##name -#else // define the object -#if (osCMSIS < 0x20000U) -#define osSemaphoreDef(name) \ -const osSemaphoreDef_t os_semaphore_def_##name = { 0 } -#else -#define osSemaphoreDef(name) \ -static osRtxSemaphore_t os_semaphore_cb_##name __attribute__((section(".bss.os.semaphore.cb"))); \ -const osSemaphoreDef_t os_semaphore_def_##name = \ -{ NULL, 0U, (&os_semaphore_cb_##name), osRtxSemaphoreCbSize } -#endif -#endif - -/// Access a Semaphore definition. -/// \param name name of the semaphore object. -#define osSemaphore(name) \ -&os_semaphore_def_##name - -/// Create and Initialize a Semaphore object. -/// \param[in] semaphore_def semaphore definition referenced with \ref osSemaphore. -/// \param[in] count maximum and initial number of available tokens. -/// \return semaphore ID for reference by other functions or NULL in case of error. -osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count); - -/// Wait until a Semaphore token becomes available. -/// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate. -/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -/// \return number of available tokens, or -1 in case of incorrect parameters. -int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec); - -/// Release a Semaphore token. -/// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate. -/// \return status code that indicates the execution status of the function. -#if (osCMSIS < 0x20000U) -osStatus osSemaphoreRelease (osSemaphoreId semaphore_id); -#endif - -/// Delete a Semaphore object. -/// \param[in] semaphore_id semaphore object referenced with \ref osSemaphoreCreate. -/// \return status code that indicates the execution status of the function. -#if (osCMSIS < 0x20000U) -osStatus osSemaphoreDelete (osSemaphoreId semaphore_id); -#endif - -#endif // Semaphore available - - -// ==== Memory Pool Management Functions ==== - -#if (defined(osFeature_Pool) && (osFeature_Pool != 0)) // Memory Pool available - -/// \brief Define a Memory Pool. -/// \param name name of the memory pool. -/// \param no maximum number of blocks (objects) in the memory pool. -/// \param type data type of a single block (object). -#if defined (osObjectsExternal) // object is external -#define osPoolDef(name, no, type) \ -extern const osPoolDef_t os_pool_def_##name -#else // define the object -#if (osCMSIS < 0x20000U) -#define osPoolDef(name, no, type) \ -const osPoolDef_t os_pool_def_##name = \ -{ (no), sizeof(type), NULL } -#else -#define osPoolDef(name, no, type) \ -static osRtxMemoryPool_t os_mp_cb_##name __attribute__((section(".bss.os.mempool.cb"))); \ -static uint32_t os_mp_data_##name[osRtxMemoryPoolMemSize((no),sizeof(type))/4] __attribute__((section(".bss.os.mempool.mem"))); \ -const osPoolDef_t os_pool_def_##name = \ -{ (no), sizeof(type), \ - { NULL, 0U, (&os_mp_cb_##name), osRtxMemoryPoolCbSize, \ - (&os_mp_data_##name), sizeof(os_mp_data_##name) } } -#endif -#endif - -/// \brief Access a Memory Pool definition. -/// \param name name of the memory pool -#define osPool(name) \ -&os_pool_def_##name - -/// Create and Initialize a Memory Pool object. -/// \param[in] pool_def memory pool definition referenced with \ref osPool. -/// \return memory pool ID for reference by other functions or NULL in case of error. -osPoolId osPoolCreate (const osPoolDef_t *pool_def); - -/// Allocate a memory block from a Memory Pool. -/// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate. -/// \return address of the allocated memory block or NULL in case of no memory available. -void *osPoolAlloc (osPoolId pool_id); - -/// Allocate a memory block from a Memory Pool and set memory block to zero. -/// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate. -/// \return address of the allocated memory block or NULL in case of no memory available. -void *osPoolCAlloc (osPoolId pool_id); - -/// Return an allocated memory block back to a Memory Pool. -/// \param[in] pool_id memory pool ID obtain referenced with \ref osPoolCreate. -/// \param[in] block address of the allocated memory block to be returned to the memory pool. -/// \return status code that indicates the execution status of the function. -osStatus osPoolFree (osPoolId pool_id, void *block); - -#endif // Memory Pool available - - -// ==== Message Queue Management Functions ==== - -#if (defined(osFeature_MessageQ) && (osFeature_MessageQ != 0)) // Message Queue available - -/// \brief Create a Message Queue Definition. -/// \param name name of the queue. -/// \param queue_sz maximum number of messages in the queue. -/// \param type data type of a single message element (for debugger). -#if defined (osObjectsExternal) // object is external -#define osMessageQDef(name, queue_sz, type) \ -extern const osMessageQDef_t os_messageQ_def_##name -#else // define the object -#if (osCMSIS < 0x20000U) -#define osMessageQDef(name, queue_sz, type) \ -const osMessageQDef_t os_messageQ_def_##name = \ -{ (queue_sz), NULL } -#else -#define osMessageQDef(name, queue_sz, type) \ -static osRtxMessageQueue_t os_mq_cb_##name __attribute__((section(".bss.os.msgqueue.cb"))); \ -static uint32_t os_mq_data_##name[osRtxMessageQueueMemSize((queue_sz),sizeof(uint32_t))/4] __attribute__((section(".bss.os.msgqueue.mem"))); \ -const osMessageQDef_t os_messageQ_def_##name = \ -{ (queue_sz), \ - { NULL, 0U, (&os_mq_cb_##name), osRtxMessageQueueCbSize, \ - (&os_mq_data_##name), sizeof(os_mq_data_##name) } } -#endif -#endif - -/// \brief Access a Message Queue Definition. -/// \param name name of the queue -#define osMessageQ(name) \ -&os_messageQ_def_##name - -/// Create and Initialize a Message Queue object. -/// \param[in] queue_def message queue definition referenced with \ref osMessageQ. -/// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL. -/// \return message queue ID for reference by other functions or NULL in case of error. -osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId thread_id); - -/// Put a Message to a Queue. -/// \param[in] queue_id message queue ID obtained with \ref osMessageCreate. -/// \param[in] info message information. -/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -/// \return status code that indicates the execution status of the function. -osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec); - -/// Get a Message from a Queue or timeout if Queue is empty. -/// \param[in] queue_id message queue ID obtained with \ref osMessageCreate. -/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -/// \return event information that includes status code. -os_InRegs osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec); - -#endif // Message Queue available - - -// ==== Mail Queue Management Functions ==== - -#if (defined(osFeature_MailQ) && (osFeature_MailQ != 0)) // Mail Queue available - -/// \brief Create a Mail Queue Definition. -/// \param name name of the queue. -/// \param queue_sz maximum number of mails in the queue. -/// \param type data type of a single mail element. -#if defined (osObjectsExternal) // object is external -#define osMailQDef(name, queue_sz, type) \ -extern const osMailQDef_t os_mailQ_def_##name -#else // define the object -#if (osCMSIS < 0x20000U) -#define osMailQDef(name, queue_sz, type) \ -const osMailQDef_t os_mailQ_def_##name = \ -{ (queue_sz), sizeof(type), NULL } -#else -#define osMailQDef(name, queue_sz, type) \ -static void *os_mail_p_##name[2] __attribute__((section(".bss.os"))); \ -static osRtxMemoryPool_t os_mail_mp_cb_##name __attribute__((section(".bss.os.mempool.cb"))); \ -static osRtxMessageQueue_t os_mail_mq_cb_##name __attribute__((section(".bss.os.msgqueue.cb"))); \ -static uint32_t os_mail_mp_data_##name[osRtxMemoryPoolMemSize ((queue_sz),sizeof(type) )/4] __attribute__((section(".bss.os.mempool.mem"))); \ -static uint32_t os_mail_mq_data_##name[osRtxMessageQueueMemSize((queue_sz),sizeof(void*))/4] __attribute__((section(".bss.os.msgqueue.mem"))); \ -const osMailQDef_t os_mailQ_def_##name = \ -{ (queue_sz), sizeof(type), (&os_mail_p_##name), \ - { NULL, 0U, (&os_mail_mp_cb_##name), osRtxMemoryPoolCbSize, \ - (&os_mail_mp_data_##name), sizeof(os_mail_mp_data_##name) }, \ - { NULL, 0U, (&os_mail_mq_cb_##name), osRtxMessageQueueCbSize, \ - (&os_mail_mq_data_##name), sizeof(os_mail_mq_data_##name) } } -#endif -#endif - -/// \brief Access a Mail Queue Definition. -/// \param name name of the queue -#define osMailQ(name) \ -&os_mailQ_def_##name - -/// Create and Initialize a Mail Queue object. -/// \param[in] queue_def mail queue definition referenced with \ref osMailQ. -/// \param[in] thread_id thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL. -/// \return mail queue ID for reference by other functions or NULL in case of error. -osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id); - -/// Allocate a memory block for mail from a mail memory pool. -/// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. -/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out -/// \return pointer to memory block that can be filled with mail or NULL in case of error. -void *osMailAlloc (osMailQId queue_id, uint32_t millisec); - -/// Allocate a memory block for mail from a mail memory pool and set memory block to zero. -/// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. -/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out -/// \return pointer to memory block that can be filled with mail or NULL in case of error. -void *osMailCAlloc (osMailQId queue_id, uint32_t millisec); - -/// Put a Mail into a Queue. -/// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. -/// \param[in] mail pointer to memory with mail to put into a queue. -/// \return status code that indicates the execution status of the function. -osStatus osMailPut (osMailQId queue_id, const void *mail); - -/// Get a Mail from a Queue or timeout if Queue is empty. -/// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. -/// \param[in] millisec \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -/// \return event information that includes status code. -os_InRegs osEvent osMailGet (osMailQId queue_id, uint32_t millisec); - -/// Free a memory block by returning it to a mail memory pool. -/// \param[in] queue_id mail queue ID obtained with \ref osMailCreate. -/// \param[in] mail pointer to memory block that was obtained with \ref osMailGet. -/// \return status code that indicates the execution status of the function. -osStatus osMailFree (osMailQId queue_id, void *mail); - -#endif // Mail Queue available - - -#ifdef __cplusplus -} -#endif - -#endif // CMSIS_OS_H_ diff --git a/rtos/rtx4/cmsis_os1.c b/rtos/rtx4/cmsis_os1.c deleted file mode 100644 index a68eb0a..0000000 --- a/rtos/rtx4/cmsis_os1.c +++ /dev/null @@ -1,371 +0,0 @@ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ---------------------------------------------------------------------- - * - * $Date: 10. January 2017 - * $Revision: V1.2 - * - * Project: CMSIS-RTOS API V1 - * Title: cmsis_os_v1.c V1 module file - *---------------------------------------------------------------------------*/ - -#include -#include "cmsis_os.h" - -#if (osCMSIS >= 0x20000U) && !defined(os1_Disable) - - -// Thread -#if !defined(os1_Disable_Thread) -osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument) { - - if (thread_def == NULL) { - return NULL; - } - return osThreadNew((osThreadFunc_t)thread_def->pthread, argument, &thread_def->attr); -} -#endif - - -// Signals - -#if !defined(os1_Disable_Signal) - -#define SignalMask ((1U< 0U) && (flags < 0x80000000U)) { - event.status = osEventSignal; - event.value.signals = (int32_t)flags; - } else { - switch ((int32_t)flags) { - case osErrorResource: - event.status = osOK; - break; - case osErrorTimeout: - event.status = osEventTimeout; - break; - case osErrorParameter: - event.status = osErrorValue; - break; - default: - event.status = (osStatus)flags; - break; - } - } - return event; -} - -#endif // Signal - - -// Timer -#if !defined(os1_Disable_Timer) -osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument) { - - if (timer_def == NULL) { - return NULL; - } - return osTimerNew((osTimerFunc_t)timer_def->ptimer, type, argument, &timer_def->attr); -} -#endif - - -// Mutex -#if !defined(os1_Disable_Mutex) -osMutexId osMutexCreate (const osMutexDef_t *mutex_def) { - - if (mutex_def == NULL) { - return NULL; - } - return osMutexNew(mutex_def); -} -#endif - - -// Semaphore - -#if (defined (osFeature_Semaphore) && (osFeature_Semaphore != 0U)) && !defined(os1_Disable_Semaphore) - -osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count) { - - if (semaphore_def == NULL) { - return NULL; - } - return osSemaphoreNew((uint32_t)count, (uint32_t)count, semaphore_def); -} - -int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec) { - osStatus_t status; - uint32_t count; - - status = osSemaphoreAcquire(semaphore_id, millisec); - switch (status) { - case osOK: - count = osSemaphoreGetCount(semaphore_id); - return ((int32_t)count + 1); - case osErrorResource: - case osErrorTimeout: - return 0; - default: - break; - } - return -1; -} - -#endif // Semaphore - - -// Memory Pool - -#if (defined(osFeature_Pool) && (osFeature_Pool != 0))&& !defined(os1_Disable_Pool) - -osPoolId osPoolCreate (const osPoolDef_t *pool_def) { - - if (pool_def == NULL) { - return NULL; - } - return osMemoryPoolNew(pool_def->pool_sz, pool_def->item_sz, &pool_def->attr); -} - -void *osPoolAlloc (osPoolId pool_id) { - return osMemoryPoolAlloc(pool_id, 0U); -} - -void *osPoolCAlloc (osPoolId pool_id) { - void *block; - uint32_t block_size; - - block_size = osMemoryPoolGetBlockSize((osMemoryPoolId_t)pool_id); - if (block_size == 0U) { - return NULL; - } - block = osMemoryPoolAlloc(pool_id, 0U); - if (block != NULL) { - memset(block, 0, block_size); - } - return block; -} - -osStatus osPoolFree (osPoolId pool_id, void *block) { - return osMemoryPoolFree(pool_id, block); -} - -#endif // Memory Pool - - -// Message Queue - -#if (defined(osFeature_MessageQ) && (osFeature_MessageQ != 0)) && !defined(os1_Disable_MessageQ) - -osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId thread_id) { - (void)thread_id; - - if (queue_def == NULL) { - return NULL; - } - return osMessageQueueNew(queue_def->queue_sz, sizeof(uint32_t), &queue_def->attr); -} - -osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec) { - return osMessageQueuePut(queue_id, &info, 0U, millisec); -} - -os_InRegs osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec) { - osStatus_t status; - osEvent event; - uint32_t message; - - status = osMessageQueueGet(queue_id, &message, NULL, millisec); - switch (status) { - case osOK: - event.status = osEventMessage; - event.value.v = message; - break; - case osErrorResource: - event.status = osOK; - break; - case osErrorTimeout: - event.status = osEventTimeout; - break; - default: - event.status = status; - break; - } - return event; -} - -#endif // Message Queue - - -// Mail Queue - -#if (defined(osFeature_MailQ) && (osFeature_MailQ != 0)) && !defined(os1_Disable_MailQ) - -typedef struct os_mail_queue_s { - osMemoryPoolId_t mp_id; - osMessageQueueId_t mq_id; -} os_mail_queue_t; - -osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id) { - os_mail_queue_t *ptr; - (void)thread_id; - - if (queue_def == NULL) { - return NULL; - } - - ptr = queue_def->mail; - if (ptr == NULL) { - return NULL; - } - - ptr->mp_id = osMemoryPoolNew (queue_def->queue_sz, queue_def->item_sz, &queue_def->mp_attr); - ptr->mq_id = osMessageQueueNew(queue_def->queue_sz, sizeof(void *), &queue_def->mq_attr); - if ((ptr->mp_id == NULL) || (ptr->mq_id == NULL)) { - if (ptr->mp_id != NULL) { - osMemoryPoolDelete(ptr->mp_id); - } - if (ptr->mq_id != NULL) { - osMessageQueueDelete(ptr->mq_id); - } - return NULL; - } - - return ptr; -} - -void *osMailAlloc (osMailQId queue_id, uint32_t millisec) { - os_mail_queue_t *ptr = (os_mail_queue_t *)queue_id; - - if (ptr == NULL) { - return NULL; - } - return osMemoryPoolAlloc(ptr->mp_id, millisec); -} - -void *osMailCAlloc (osMailQId queue_id, uint32_t millisec) { - os_mail_queue_t *ptr = (os_mail_queue_t *)queue_id; - void *block; - uint32_t block_size; - - if (ptr == NULL) { - return NULL; - } - block_size = osMemoryPoolGetBlockSize(ptr->mp_id); - if (block_size == 0U) { - return NULL; - } - block = osMemoryPoolAlloc(ptr->mp_id, millisec); - if (block != NULL) { - memset(block, 0, block_size); - } - - return block; - -} - -osStatus osMailPut (osMailQId queue_id, const void *mail) { - os_mail_queue_t *ptr = (os_mail_queue_t *)queue_id; - - if (ptr == NULL) { - return osErrorParameter; - } - if (mail == NULL) { - return osErrorValue; - } - return osMessageQueuePut(ptr->mq_id, &mail, 0U, 0U); -} - -os_InRegs osEvent osMailGet (osMailQId queue_id, uint32_t millisec) { - os_mail_queue_t *ptr = (os_mail_queue_t *)queue_id; - osStatus_t status; - osEvent event; - void *mail; - - if (ptr == NULL) { - event.status = osErrorParameter; - return event; - } - - status = osMessageQueueGet(ptr->mq_id, &mail, NULL, millisec); - switch (status) { - case osOK: - event.status = osEventMail; - event.value.p = mail; - break; - case osErrorResource: - event.status = osOK; - break; - case osErrorTimeout: - event.status = osEventTimeout; - break; - default: - event.status = status; - break; - } - return event; -} - -osStatus osMailFree (osMailQId queue_id, void *mail) { - os_mail_queue_t *ptr = (os_mail_queue_t *)queue_id; - - if (ptr == NULL) { - return osErrorParameter; - } - if (mail == NULL) { - return osErrorValue; - } - return osMemoryPoolFree(ptr->mp_id, mail); -} - -#endif // Mail Queue - - -#endif // osCMSIS diff --git a/rtos/rtx5/TARGET_CORTEX_M/RTX_Config.c b/rtos/rtx5/TARGET_CORTEX_M/RTX_Config.c deleted file mode 100644 index 6572cf0..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/RTX_Config.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ----------------------------------------------------------------------------- - * - * $Revision: V5.1.0 - * - * Project: CMSIS-RTOS RTX - * Title: RTX Configuration - * - * ----------------------------------------------------------------------------- - */ - -#include "cmsis_compiler.h" -#include "rtx_os.h" - -// OS Idle Thread -__WEAK __NO_RETURN void osRtxIdleThread (void *argument) { - (void)argument; - - for (;;) {} -} - -// OS Error Callback function -__WEAK uint32_t osRtxErrorNotify (uint32_t code, void *object_id) { - (void)object_id; - - switch (code) { - case osRtxErrorStackUnderflow: - // Stack underflow detected for thread (thread_id=object_id) - break; - case osRtxErrorISRQueueOverflow: - // ISR Queue overflow detected when inserting object (object_id) - break; - case osRtxErrorTimerQueueOverflow: - // User Timer Callback Queue overflow detected for timer (timer_id=object_id) - break; - case osRtxErrorClibSpace: - // Standard C/C++ library libspace not available: increase OS_THREAD_LIBSPACE_NUM - break; - case osRtxErrorClibMutex: - // Standard C/C++ library mutex initialization failed - break; - default: - break; - } - for (;;) {} -//return 0U; -} diff --git a/rtos/rtx5/TARGET_CORTEX_M/RTX_Config.h b/rtos/rtx5/TARGET_CORTEX_M/RTX_Config.h deleted file mode 100644 index e161b52..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/RTX_Config.h +++ /dev/null @@ -1,384 +0,0 @@ -/** \addtogroup rtos */ -/** @{*/ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ----------------------------------------------------------------------------- - * - * $Revision: V5.1.0 - * - * Project: CMSIS-RTOS RTX - * Title: RTX Configuration definitions - * - * ----------------------------------------------------------------------------- - */ - -#ifndef RTX_CONFIG_H_ -#define RTX_CONFIG_H_ - -#include "rtx5/mbed_rtx_conf.h" - -//-------- <<< Use Configuration Wizard in Context Menu >>> -------------------- - -// System Configuration -// ======================= - -// Global Dynamic Memory size [bytes] <0-1073741824:8> -// Defines the combined global dynamic memory size. -// Default: 4096 -#ifndef OS_DYNAMIC_MEM_SIZE -#define OS_DYNAMIC_MEM_SIZE 4096 -#endif - -// Kernel Tick Frequency [Hz] <1-1000000> -// Defines base time unit for delays and timeouts. -// Default: 1000 (1ms tick) -#ifndef OS_TICK_FREQ -#define OS_TICK_FREQ 1000 -#endif - -// Round-Robin Thread switching -// Enables Round-Robin Thread switching. -#ifndef OS_ROBIN_ENABLE -#define OS_ROBIN_ENABLE 1 -#endif - -// Round-Robin Timeout <1-1000> -// Defines how many ticks a thread will execute before a thread switch. -// Default: 5 -#ifndef OS_ROBIN_TIMEOUT -#define OS_ROBIN_TIMEOUT 5 -#endif - -// - -// Event Recording - -// Memory Management -// Enables Memory Management events recording. -#ifndef OS_EVR_MEMORY -#define OS_EVR_MEMORY 1 -#endif - -// Kernel -// Enables Kernel events recording. -#ifndef OS_EVR_KERNEL -#define OS_EVR_KERNEL 1 -#endif - -// Thread -// Enables Thread events recording. -#ifndef OS_EVR_THREAD -#define OS_EVR_THREAD 1 -#endif - -// Timer -// Enables Timer events recording. -#ifndef OS_EVR_TIMER -#define OS_EVR_TIMER 1 -#endif - -// Event Flags -// Enables Event Flags events recording. -#ifndef OS_EVR_EVFLAGS -#define OS_EVR_EVFLAGS 1 -#endif - -// Mutex -// Enables Mutex events recording. -#ifndef OS_EVR_MUTEX -#define OS_EVR_MUTEX 1 -#endif - -// Semaphore -// Enables Semaphore events recording. -#ifndef OS_EVR_SEMAPHORE -#define OS_EVR_SEMAPHORE 1 -#endif - -// Memory Pool -// Enables Memory Pool events recording. -#ifndef OS_EVR_MEMPOOL -#define OS_EVR_MEMPOOL 1 -#endif - -// Message Queue -// Enables Message Queue events recording. -#ifndef OS_EVR_MSGQUEUE -#define OS_EVR_MSGQUEUE 1 -#endif - -// - -// ISR FIFO Queue -// <4=> 4 entries <8=> 8 entries <12=> 12 entries <16=> 16 entries -// <24=> 24 entries <32=> 32 entries <48=> 48 entries <64=> 64 entries -// <96=> 96 entries <128=> 128 entries <196=> 196 entries <256=> 256 entries -// RTOS Functions called from ISR store requests to this buffer. -// Default: 16 entries -#ifndef OS_ISR_FIFO_QUEUE -#define OS_ISR_FIFO_QUEUE 16 -#endif - -// - -// Thread Configuration -// ======================= - -// Object specific Memory allocation -// Enables object specific memory allocation. -#ifndef OS_THREAD_OBJ_MEM -#define OS_THREAD_OBJ_MEM 0 -#endif - -// Number of user Threads <1-1000> -// Defines maximum number of user threads that can be active at the same time. -// Applies to user threads with system provided memory for control blocks. -#ifndef OS_THREAD_NUM -#define OS_THREAD_NUM 1 -#endif - -// Number of user Threads with default Stack size <0-1000> -// Defines maximum number of user threads with default stack size. -// Applies to user threads with zero stack size specified. -#ifndef OS_THREAD_DEF_STACK_NUM -#define OS_THREAD_DEF_STACK_NUM 0 -#endif - -// Total Stack size [bytes] for user Threads with user-provided Stack size <0-1073741824:8> -// Defines the combined stack size for user threads with user-provided stack size. -// Applies to user threads with user-provided stack size and system provided memory for stack. -// Default: 0 -#ifndef OS_THREAD_USER_STACK_SIZE -#define OS_THREAD_USER_STACK_SIZE 0 -#endif - -// - -// Default Thread Stack size [bytes] <96-1073741824:8> -// Defines stack size for threads with zero stack size specified. -// Default: 200 -#ifndef OS_STACK_SIZE -#define OS_STACK_SIZE 200 -#endif - -// Idle Thread Stack size [bytes] <72-1073741824:8> -// Defines stack size for Idle thread. -// Default: 200 -#ifndef OS_IDLE_THREAD_STACK_SIZE -#define OS_IDLE_THREAD_STACK_SIZE 200 -#endif - -// Stack overrun checking -// Enable stack overrun checks at thread switch. -// Enabling this option increases slightly the execution time of a thread switch. -#ifndef OS_STACK_CHECK -#define OS_STACK_CHECK 1 -#endif - -// Stack usage watermark -// Initialize thread stack with watermark pattern for analyzing stack usage. -// Enabling this option increases significantly the execution time of thread creation. -#ifndef OS_STACK_WATERMARK -#define OS_STACK_WATERMARK 0 -#endif - -// Processor mode for Thread execution -// <0=> Unprivileged mode -// <1=> Privileged mode -// Default: Privileged mode -#ifndef OS_PRIVILEGE_MODE -#define OS_PRIVILEGE_MODE 1 -#endif - -// - -// Timer Configuration -// ====================== - -// Object specific Memory allocation -// Enables object specific memory allocation. -#ifndef OS_TIMER_OBJ_MEM -#define OS_TIMER_OBJ_MEM 0 -#endif - -// Number of Timer objects <1-1000> -// Defines maximum number of objects that can be active at the same time. -// Applies to objects with system provided memory for control blocks. -#ifndef OS_TIMER_NUM -#define OS_TIMER_NUM 1 -#endif - -// - -// Timer Thread Priority -// <8=> Low -// <16=> Below Normal <24=> Normal <32=> Above Normal -// <40=> High -// <48=> Realtime -// Defines priority for timer thread -// Default: High -#ifndef OS_TIMER_THREAD_PRIO -#define OS_TIMER_THREAD_PRIO 40 -#endif - -// Timer Thread Stack size [bytes] <0-1073741824:8> -// Defines stack size for Timer thread. -// May be set to 0 when timers are not used. -// Default: 200 -#ifndef OS_TIMER_THREAD_STACK_SIZE -#define OS_TIMER_THREAD_STACK_SIZE 200 -#endif - -// Timer Callback Queue entries <0-256> -// Number of concurrent active timer callback functions. -// May be set to 0 when timers are not used. -// Default: 4 -#ifndef OS_TIMER_CB_QUEUE -#define OS_TIMER_CB_QUEUE 4 -#endif - -// - -// Event Flags Configuration -// ============================ - -// Object specific Memory allocation -// Enables object specific memory allocation. -#ifndef OS_EVFLAGS_OBJ_MEM -#define OS_EVFLAGS_OBJ_MEM 0 -#endif - -// Number of Event Flags objects <1-1000> -// Defines maximum number of objects that can be active at the same time. -// Applies to objects with system provided memory for control blocks. -#ifndef OS_EVFLAGS_NUM -#define OS_EVFLAGS_NUM 1 -#endif - -// - -// - -// Mutex Configuration -// ====================== - -// Object specific Memory allocation -// Enables object specific memory allocation. -#ifndef OS_MUTEX_OBJ_MEM -#define OS_MUTEX_OBJ_MEM 0 -#endif - -// Number of Mutex objects <1-1000> -// Defines maximum number of objects that can be active at the same time. -// Applies to objects with system provided memory for control blocks. -#ifndef OS_MUTEX_NUM -#define OS_MUTEX_NUM 1 -#endif - -// - -// - -// Semaphore Configuration -// ========================== - -// Object specific Memory allocation -// Enables object specific memory allocation. -#ifndef OS_SEMAPHORE_OBJ_MEM -#define OS_SEMAPHORE_OBJ_MEM 0 -#endif - -// Number of Semaphore objects <1-1000> -// Defines maximum number of objects that can be active at the same time. -// Applies to objects with system provided memory for control blocks. -#ifndef OS_SEMAPHORE_NUM -#define OS_SEMAPHORE_NUM 1 -#endif - -// - -// - -// Memory Pool Configuration -// ============================ - -// Object specific Memory allocation -// Enables object specific memory allocation. -#ifndef OS_MEMPOOL_OBJ_MEM -#define OS_MEMPOOL_OBJ_MEM 0 -#endif - -// Number of Memory Pool objects <1-1000> -// Defines maximum number of objects that can be active at the same time. -// Applies to objects with system provided memory for control blocks. -#ifndef OS_MEMPOOL_NUM -#define OS_MEMPOOL_NUM 1 -#endif - -// Data Storage Memory size [bytes] <0-1073741824:8> -// Defines the combined data storage memory size. -// Applies to objects with system provided memory for data storage. -// Default: 0 -#ifndef OS_MEMPOOL_DATA_SIZE -#define OS_MEMPOOL_DATA_SIZE 0 -#endif - -// - -// - -// Message Queue Configuration -// ============================== - -// Object specific Memory allocation -// Enables object specific memory allocation. -#ifndef OS_MSGQUEUE_OBJ_MEM -#define OS_MSGQUEUE_OBJ_MEM 0 -#endif - -// Number of Message Queue objects <1-1000> -// Defines maximum number of objects that can be active at the same time. -// Applies to objects with system provided memory for control blocks. -#ifndef OS_MSGQUEUE_NUM -#define OS_MSGQUEUE_NUM 1 -#endif - -// Data Storage Memory size [bytes] <0-1073741824:8> -// Defines the combined data storage memory size. -// Applies to objects with system provided memory for data storage. -// Default: 0 -#ifndef OS_MSGQUEUE_DATA_SIZE -#define OS_MSGQUEUE_DATA_SIZE 0 -#endif - -// - -// - -// Number of Threads which use standard C/C++ library libspace -// (when thread specific memory allocation is not used). -#if (OS_THREAD_OBJ_MEM == 0) -#define OS_THREAD_LIBSPACE_NUM 4 -#else -#define OS_THREAD_LIBSPACE_NUM OS_THREAD_NUM -#endif - -//------------- <<< end of configuration section >>> --------------------------- - -#endif // RTX_CONFIG_H_ -/** @}*/ diff --git a/rtos/rtx5/TARGET_CORTEX_M/TARGET_M0/TOOLCHAIN_ARM/irq_cm0.S b/rtos/rtx5/TARGET_CORTEX_M/TARGET_M0/TOOLCHAIN_ARM/irq_cm0.S deleted file mode 100644 index 74c8a84..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/TARGET_M0/TOOLCHAIN_ARM/irq_cm0.S +++ /dev/null @@ -1,155 +0,0 @@ -;/* -; * Copyright (c) 2013-2017 ARM Limited. All rights reserved. -; * -; * SPDX-License-Identifier: Apache-2.0 -; * -; * Licensed under the Apache License, Version 2.0 (the License); you may -; * not use this file except in compliance with the License. -; * You may obtain a copy of the License at -; * -; * www.apache.org/licenses/LICENSE-2.0 -; * -; * Unless required by applicable law or agreed to in writing, software -; * distributed under the License is distributed on an AS IS BASIS, WITHOUT -; * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -; * See the License for the specific language governing permissions and -; * limitations under the License. -; * -; * ----------------------------------------------------------------------------- -; * -; * Project: CMSIS-RTOS RTX -; * Title: Cortex-M0 Exception handlers -; * -; * ----------------------------------------------------------------------------- -; */ - - -I_T_RUN_OFS EQU 28 ; osRtxInfo.thread.run offset -TCB_SP_OFS EQU 56 ; TCB.SP offset - - - PRESERVE8 - THUMB - - - AREA |.constdata|, DATA, READONLY - EXPORT irqRtxLib -irqRtxLib DCB 0 ; Non weak library reference - - - AREA |.text|, CODE, READONLY - - -SVC_Handler PROC - EXPORT SVC_Handler - IMPORT osRtxUserSVC - IMPORT osRtxInfo - - MRS R0,PSP ; Get PSP - LDR R1,[R0,#24] ; Load saved PC from stack - SUBS R1,R1,#2 ; Point to SVC instruction - LDRB R1,[R1] ; Load SVC number - CMP R1,#0 - BNE SVC_User ; Branch if not SVC 0 - - PUSH {R0,LR} ; Save PSP and EXC_RETURN - LDMIA R0,{R0-R3} ; Load function parameters from stack - BLX R7 ; Call service function - POP {R2,R3} ; Restore PSP and EXC_RETURN - STMIA R2!,{R0-R1} ; Store function return values - MOV LR,R3 ; Set EXC_RETURN - -SVC_Context - LDR R3,=osRtxInfo+I_T_RUN_OFS; Load address of osRtxInfo.run - LDMIA R3!,{R1,R2} ; Load osRtxInfo.thread.run: curr & next - CMP R1,R2 ; Check if thread switch is required - BEQ SVC_Exit ; Branch when threads are the same - - CMP R1,#0 - BEQ SVC_ContextSwitch ; Branch if running thread is deleted - -SVC_ContextSave - MRS R0,PSP ; Get PSP - SUBS R0,R0,#32 ; Adjust address - STR R0,[R1,#TCB_SP_OFS] ; Store SP - STMIA R0!,{R4-R7} ; Save R4..R7 - MOV R4,R8 - MOV R5,R9 - MOV R6,R10 - MOV R7,R11 - STMIA R0!,{R4-R7} ; Save R8..R11 - -SVC_ContextSwitch - SUBS R3,R3,#8 - STR R2,[R3] ; osRtxInfo.thread.run: curr = next - -SVC_ContextRestore - LDR R0,[R2,#TCB_SP_OFS] ; Load SP - ADDS R0,R0,#16 ; Adjust address - LDMIA R0!,{R4-R7} ; Restore R8..R11 - MOV R8,R4 - MOV R9,R5 - MOV R10,R6 - MOV R11,R7 - MSR PSP,R0 ; Set PSP - SUBS R0,R0,#32 ; Adjust address - LDMIA R0!,{R4-R7} ; Restore R4..R7 - - MOVS R0,#~0xFFFFFFFD - MVNS R0,R0 ; Set EXC_RETURN value - BX R0 ; Exit from handler - -SVC_Exit - BX LR ; Exit from handler - -SVC_User - PUSH {R4,LR} ; Save registers - LDR R2,=osRtxUserSVC ; Load address of SVC table - LDR R3,[R2] ; Load SVC maximum number - CMP R1,R3 ; Check SVC number range - BHI SVC_Done ; Branch if out of range - - LSLS R1,R1,#2 - LDR R4,[R2,R1] ; Load address of SVC function - - LDMIA R0,{R0-R3} ; Load function parameters from stack - BLX R4 ; Call service function - MRS R4,PSP ; Get PSP - STMIA R4!,{R0-R3} ; Store function return values - -SVC_Done - POP {R4,PC} ; Return from handler - - ALIGN - ENDP - - -PendSV_Handler PROC - EXPORT PendSV_Handler - IMPORT osRtxPendSV_Handler - - PUSH {R0,LR} ; Save EXC_RETURN - BL osRtxPendSV_Handler ; Call osRtxPendSV_Handler - POP {R0,R1} ; Restore EXC_RETURN - MOV LR,R1 ; Set EXC_RETURN - B SVC_Context - - ALIGN - ENDP - - -SysTick_Handler PROC - EXPORT SysTick_Handler - IMPORT osRtxTick_Handler - - PUSH {R0,LR} ; Save EXC_RETURN - BL osRtxTick_Handler ; Call osRtxTick_Handler - POP {R0,R1} ; Restore EXC_RETURN - MOV LR,R1 ; Set EXC_RETURN - B SVC_Context - - ALIGN - ENDP - - - END diff --git a/rtos/rtx5/TARGET_CORTEX_M/TARGET_M0/TOOLCHAIN_GCC/irq_cm0.S b/rtos/rtx5/TARGET_CORTEX_M/TARGET_M0/TOOLCHAIN_GCC/irq_cm0.S deleted file mode 100644 index 5362c19..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/TARGET_M0/TOOLCHAIN_GCC/irq_cm0.S +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ----------------------------------------------------------------------------- - * - * Project: CMSIS-RTOS RTX - * Title: Cortex-M0 Exception handlers - * - * ----------------------------------------------------------------------------- - */ - - - .file "irq_cm0.S" - .syntax unified - - .equ I_T_RUN_OFS, 28 // osRtxInfo.thread.run offset - .equ TCB_SP_OFS, 56 // TCB.SP offset - - .section ".rodata" - .global irqRtxLib // Non weak library reference -irqRtxLib: - .byte 0 - - - .thumb - .section ".text" - .align 2 - - - .thumb_func - .type SVC_Handler, %function - .global SVC_Handler - .fnstart - .cantunwind -SVC_Handler: - - MRS R0,PSP // Get PSP - LDR R1,[R0,#24] // Load saved PC from stack - SUBS R1,R1,#2 // Point to SVC instruction - LDRB R1,[R1] // Load SVC number - CMP R1,#0 - BNE SVC_User // Branch if not SVC 0 - - PUSH {R0,LR} // Save PSP and EXC_RETURN - LDMIA R0,{R0-R3} // Load function parameters from stack - BLX R7 // Call service function - POP {R2,R3} // Restore PSP and EXC_RETURN - STMIA R2!,{R0-R1} // Store function return values - MOV LR,R3 // Set EXC_RETURN - -SVC_Context: - LDR R3,=osRtxInfo+I_T_RUN_OFS // Load address of osRtxInfo.run - LDMIA R3!,{R1,R2} // Load osRtxInfo.thread.run: curr & next - CMP R1,R2 // Check if thread switch is required - BEQ SVC_Exit // Branch when threads are the same - - CMP R1,#0 - BEQ SVC_ContextSwitch // Branch if running thread is deleted - -SVC_ContextSave: - MRS R0,PSP // Get PSP - SUBS R0,R0,#32 // Adjust address - STR R0,[R1,#TCB_SP_OFS]; // Store SP - STMIA R0!,{R4-R7} // Save R4..R7 - MOV R4,R8 - MOV R5,R9 - MOV R6,R10 - MOV R7,R11 - STMIA R0!,{R4-R7} // Save R8..R11 - -SVC_ContextSwitch: - SUBS R3,R3,#8 - STR R2,[R3] // osRtxInfo.thread.run: curr = next - -SVC_ContextRestore: - LDR R0,[R2,#TCB_SP_OFS] // Load SP - ADDS R0,R0,#16 // Adjust address - LDMIA R0!,{R4-R7} // Restore R8..R11 - MOV R8,R4 - MOV R9,R5 - MOV R10,R6 - MOV R11,R7 - MSR PSP,R0 // Set PSP - SUBS R0,R0,#32 // Adjust address - LDMIA R0!,{R4-R7} // Restore R4..R7 - - MOVS R0,#~0xFFFFFFFD - MVNS R0,R0 // Set EXC_RETURN value - BX R0 // Exit from handler - -SVC_Exit: - BX LR // Exit from handler - -SVC_User: - PUSH {R4,LR} // Save registers - LDR R2,=osRtxUserSVC // Load address of SVC table - LDR R3,[R2] // Load SVC maximum number - CMP R1,R3 // Check SVC number range - BHI SVC_Done // Branch if out of range - - LSLS R1,R1,#2 - LDR R4,[R2,R1] // Load address of SVC function - - LDMIA R0,{R0-R3} // Load function parameters from stack - BLX R4 // Call service function - MRS R4,PSP // Get PSP - STMIA R4!,{R0-R3} // Store function return values - -SVC_Done: - POP {R4,PC} // Return from handler - - .fnend - .size SVC_Handler, .-SVC_Handler - - - .thumb_func - .type PendSV_Handler, %function - .global PendSV_Handler - .fnstart - .cantunwind -PendSV_Handler: - - PUSH {R0,LR} // Save EXC_RETURN - BL osRtxPendSV_Handler // Call osRtxPendSV_Handler - POP {R0,R1} // Restore EXC_RETURN - MOV LR,R1 // Set EXC_RETURN - B SVC_Context - - .fnend - .size PendSV_Handler, .-PendSV_Handler - - - .thumb_func - .type SysTick_Handler, %function - .global SysTick_Handler - .fnstart - .cantunwind -SysTick_Handler: - - PUSH {R0,LR} // Save EXC_RETURN - BL osRtxTick_Handler // Call osRtxTick_Handler - POP {R0,R1} // Restore EXC_RETURN - MOV LR,R1 // Set EXC_RETURN - B SVC_Context - - .fnend - .size SysTick_Handler, .-SysTick_Handler - - - .end diff --git a/rtos/rtx5/TARGET_CORTEX_M/TARGET_M0/TOOLCHAIN_IAR/irq_cm0.S b/rtos/rtx5/TARGET_CORTEX_M/TARGET_M0/TOOLCHAIN_IAR/irq_cm0.S deleted file mode 100644 index 023aae3..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/TARGET_M0/TOOLCHAIN_IAR/irq_cm0.S +++ /dev/null @@ -1,149 +0,0 @@ -;/* -; * Copyright (c) 2013-2017 ARM Limited. All rights reserved. -; * -; * SPDX-License-Identifier: Apache-2.0 -; * -; * Licensed under the Apache License, Version 2.0 (the License); you may -; * not use this file except in compliance with the License. -; * You may obtain a copy of the License at -; * -; * www.apache.org/licenses/LICENSE-2.0 -; * -; * Unless required by applicable law or agreed to in writing, software -; * distributed under the License is distributed on an AS IS BASIS, WITHOUT -; * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -; * See the License for the specific language governing permissions and -; * limitations under the License. -; * -; * ----------------------------------------------------------------------------- -; * -; * Project: CMSIS-RTOS RTX -; * Title: Cortex-M0 Exception handlers -; * -; * ----------------------------------------------------------------------------- -; */ - - - NAME irq_cm0.s - - -I_T_RUN_OFS EQU 28 ; osRtxInfo.thread.run offset -TCB_SP_OFS EQU 56 ; TCB.SP offset - - - PRESERVE8 - SECTION .rodata:DATA:NOROOT(2) - - - EXPORT irqRtxLib -irqRtxLib DCB 0 ; Non weak library reference - - - THUMB - SECTION .text:CODE:NOROOT(2) - - -SVC_Handler - EXPORT SVC_Handler - IMPORT osRtxUserSVC - IMPORT osRtxInfo - - MRS R0,PSP ; Get PSP - LDR R1,[R0,#24] ; Load saved PC from stack - SUBS R1,R1,#2 ; Point to SVC instruction - LDRB R1,[R1] ; Load SVC number - CMP R1,#0 - BNE SVC_User ; Branch if not SVC 0 - - PUSH {R0,LR} ; Save PSP and EXC_RETURN - LDMIA R0,{R0-R3} ; Load function parameters from stack - BLX R7 ; Call service function - POP {R2,R3} ; Restore PSP and EXC_RETURN - STMIA R2!,{R0-R1} ; Store function return values - MOV LR,R3 ; Set EXC_RETURN - -SVC_Context - LDR R3,=osRtxInfo+I_T_RUN_OFS; Load address of osRtxInfo.run - LDMIA R3!,{R1,R2} ; Load osRtxInfo.thread.run: curr & next - CMP R1,R2 ; Check if thread switch is required - BEQ SVC_Exit ; Branch when threads are the same - - CMP R1,#0 - BEQ SVC_ContextSwitch ; Branch if running thread is deleted - -SVC_ContextSave - MRS R0,PSP ; Get PSP - SUBS R0,R0,#32 ; Adjust address - STR R0,[R1,#TCB_SP_OFS] ; Store SP - STMIA R0!,{R4-R7} ; Save R4..R7 - MOV R4,R8 - MOV R5,R9 - MOV R6,R10 - MOV R7,R11 - STMIA R0!,{R4-R7} ; Save R8..R11 - -SVC_ContextSwitch - SUBS R3,R3,#8 - STR R2,[R3] ; osRtxInfo.thread.run: curr = next - -SVC_ContextRestore - LDR R0,[R2,#TCB_SP_OFS] ; Load SP - ADDS R0,R0,#16 ; Adjust address - LDMIA R0!,{R4-R7} ; Restore R8..R11 - MOV R8,R4 - MOV R9,R5 - MOV R10,R6 - MOV R11,R7 - MSR PSP,R0 ; Set PSP - SUBS R0,R0,#32 ; Adjust address - LDMIA R0!,{R4-R7} ; Restore R4..R7 - - MOVS R0,#~0xFFFFFFFD - MVNS R0,R0 ; Set EXC_RETURN value - BX R0 ; Exit from handler - -SVC_Exit - BX LR ; Exit from handler - -SVC_User - PUSH {R4,LR} ; Save registers - LDR R2,=osRtxUserSVC ; Load address of SVC table - LDR R3,[R2] ; Load SVC maximum number - CMP R1,R3 ; Check SVC number range - BHI SVC_Done ; Branch if out of range - - LSLS R1,R1,#2 - LDR R4,[R2,R1] ; Load address of SVC function - - LDMIA R0,{R0-R3} ; Load function parameters from stack - BLX R4 ; Call service function - MRS R4,PSP ; Get PSP - STMIA R4!,{R0-R3} ; Store function return values - -SVC_Done - POP {R4,PC} ; Return from handler - - -PendSV_Handler - EXPORT PendSV_Handler - IMPORT osRtxPendSV_Handler - - PUSH {R0,LR} ; Save EXC_RETURN - BL osRtxPendSV_Handler ; Call osRtxPendSV_Handler - POP {R0,R1} ; Restore EXC_RETURN - MOV LR,R1 ; Set EXC_RETURN - B SVC_Context - - -SysTick_Handler - EXPORT SysTick_Handler - IMPORT osRtxTick_Handler - - PUSH {R0,LR} ; Save EXC_RETURN - BL osRtxTick_Handler ; Call osRtxTick_Handler - POP {R0,R1} ; Restore EXC_RETURN - MOV LR,R1 ; Set EXC_RETURN - B SVC_Context - - - END diff --git a/rtos/rtx5/TARGET_CORTEX_M/TARGET_M0P/TOOLCHAIN_ARM/irq_cm0.S b/rtos/rtx5/TARGET_CORTEX_M/TARGET_M0P/TOOLCHAIN_ARM/irq_cm0.S deleted file mode 100644 index 74c8a84..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/TARGET_M0P/TOOLCHAIN_ARM/irq_cm0.S +++ /dev/null @@ -1,155 +0,0 @@ -;/* -; * Copyright (c) 2013-2017 ARM Limited. All rights reserved. -; * -; * SPDX-License-Identifier: Apache-2.0 -; * -; * Licensed under the Apache License, Version 2.0 (the License); you may -; * not use this file except in compliance with the License. -; * You may obtain a copy of the License at -; * -; * www.apache.org/licenses/LICENSE-2.0 -; * -; * Unless required by applicable law or agreed to in writing, software -; * distributed under the License is distributed on an AS IS BASIS, WITHOUT -; * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -; * See the License for the specific language governing permissions and -; * limitations under the License. -; * -; * ----------------------------------------------------------------------------- -; * -; * Project: CMSIS-RTOS RTX -; * Title: Cortex-M0 Exception handlers -; * -; * ----------------------------------------------------------------------------- -; */ - - -I_T_RUN_OFS EQU 28 ; osRtxInfo.thread.run offset -TCB_SP_OFS EQU 56 ; TCB.SP offset - - - PRESERVE8 - THUMB - - - AREA |.constdata|, DATA, READONLY - EXPORT irqRtxLib -irqRtxLib DCB 0 ; Non weak library reference - - - AREA |.text|, CODE, READONLY - - -SVC_Handler PROC - EXPORT SVC_Handler - IMPORT osRtxUserSVC - IMPORT osRtxInfo - - MRS R0,PSP ; Get PSP - LDR R1,[R0,#24] ; Load saved PC from stack - SUBS R1,R1,#2 ; Point to SVC instruction - LDRB R1,[R1] ; Load SVC number - CMP R1,#0 - BNE SVC_User ; Branch if not SVC 0 - - PUSH {R0,LR} ; Save PSP and EXC_RETURN - LDMIA R0,{R0-R3} ; Load function parameters from stack - BLX R7 ; Call service function - POP {R2,R3} ; Restore PSP and EXC_RETURN - STMIA R2!,{R0-R1} ; Store function return values - MOV LR,R3 ; Set EXC_RETURN - -SVC_Context - LDR R3,=osRtxInfo+I_T_RUN_OFS; Load address of osRtxInfo.run - LDMIA R3!,{R1,R2} ; Load osRtxInfo.thread.run: curr & next - CMP R1,R2 ; Check if thread switch is required - BEQ SVC_Exit ; Branch when threads are the same - - CMP R1,#0 - BEQ SVC_ContextSwitch ; Branch if running thread is deleted - -SVC_ContextSave - MRS R0,PSP ; Get PSP - SUBS R0,R0,#32 ; Adjust address - STR R0,[R1,#TCB_SP_OFS] ; Store SP - STMIA R0!,{R4-R7} ; Save R4..R7 - MOV R4,R8 - MOV R5,R9 - MOV R6,R10 - MOV R7,R11 - STMIA R0!,{R4-R7} ; Save R8..R11 - -SVC_ContextSwitch - SUBS R3,R3,#8 - STR R2,[R3] ; osRtxInfo.thread.run: curr = next - -SVC_ContextRestore - LDR R0,[R2,#TCB_SP_OFS] ; Load SP - ADDS R0,R0,#16 ; Adjust address - LDMIA R0!,{R4-R7} ; Restore R8..R11 - MOV R8,R4 - MOV R9,R5 - MOV R10,R6 - MOV R11,R7 - MSR PSP,R0 ; Set PSP - SUBS R0,R0,#32 ; Adjust address - LDMIA R0!,{R4-R7} ; Restore R4..R7 - - MOVS R0,#~0xFFFFFFFD - MVNS R0,R0 ; Set EXC_RETURN value - BX R0 ; Exit from handler - -SVC_Exit - BX LR ; Exit from handler - -SVC_User - PUSH {R4,LR} ; Save registers - LDR R2,=osRtxUserSVC ; Load address of SVC table - LDR R3,[R2] ; Load SVC maximum number - CMP R1,R3 ; Check SVC number range - BHI SVC_Done ; Branch if out of range - - LSLS R1,R1,#2 - LDR R4,[R2,R1] ; Load address of SVC function - - LDMIA R0,{R0-R3} ; Load function parameters from stack - BLX R4 ; Call service function - MRS R4,PSP ; Get PSP - STMIA R4!,{R0-R3} ; Store function return values - -SVC_Done - POP {R4,PC} ; Return from handler - - ALIGN - ENDP - - -PendSV_Handler PROC - EXPORT PendSV_Handler - IMPORT osRtxPendSV_Handler - - PUSH {R0,LR} ; Save EXC_RETURN - BL osRtxPendSV_Handler ; Call osRtxPendSV_Handler - POP {R0,R1} ; Restore EXC_RETURN - MOV LR,R1 ; Set EXC_RETURN - B SVC_Context - - ALIGN - ENDP - - -SysTick_Handler PROC - EXPORT SysTick_Handler - IMPORT osRtxTick_Handler - - PUSH {R0,LR} ; Save EXC_RETURN - BL osRtxTick_Handler ; Call osRtxTick_Handler - POP {R0,R1} ; Restore EXC_RETURN - MOV LR,R1 ; Set EXC_RETURN - B SVC_Context - - ALIGN - ENDP - - - END diff --git a/rtos/rtx5/TARGET_CORTEX_M/TARGET_M0P/TOOLCHAIN_GCC/irq_cm0.S b/rtos/rtx5/TARGET_CORTEX_M/TARGET_M0P/TOOLCHAIN_GCC/irq_cm0.S deleted file mode 100644 index 5362c19..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/TARGET_M0P/TOOLCHAIN_GCC/irq_cm0.S +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ----------------------------------------------------------------------------- - * - * Project: CMSIS-RTOS RTX - * Title: Cortex-M0 Exception handlers - * - * ----------------------------------------------------------------------------- - */ - - - .file "irq_cm0.S" - .syntax unified - - .equ I_T_RUN_OFS, 28 // osRtxInfo.thread.run offset - .equ TCB_SP_OFS, 56 // TCB.SP offset - - .section ".rodata" - .global irqRtxLib // Non weak library reference -irqRtxLib: - .byte 0 - - - .thumb - .section ".text" - .align 2 - - - .thumb_func - .type SVC_Handler, %function - .global SVC_Handler - .fnstart - .cantunwind -SVC_Handler: - - MRS R0,PSP // Get PSP - LDR R1,[R0,#24] // Load saved PC from stack - SUBS R1,R1,#2 // Point to SVC instruction - LDRB R1,[R1] // Load SVC number - CMP R1,#0 - BNE SVC_User // Branch if not SVC 0 - - PUSH {R0,LR} // Save PSP and EXC_RETURN - LDMIA R0,{R0-R3} // Load function parameters from stack - BLX R7 // Call service function - POP {R2,R3} // Restore PSP and EXC_RETURN - STMIA R2!,{R0-R1} // Store function return values - MOV LR,R3 // Set EXC_RETURN - -SVC_Context: - LDR R3,=osRtxInfo+I_T_RUN_OFS // Load address of osRtxInfo.run - LDMIA R3!,{R1,R2} // Load osRtxInfo.thread.run: curr & next - CMP R1,R2 // Check if thread switch is required - BEQ SVC_Exit // Branch when threads are the same - - CMP R1,#0 - BEQ SVC_ContextSwitch // Branch if running thread is deleted - -SVC_ContextSave: - MRS R0,PSP // Get PSP - SUBS R0,R0,#32 // Adjust address - STR R0,[R1,#TCB_SP_OFS]; // Store SP - STMIA R0!,{R4-R7} // Save R4..R7 - MOV R4,R8 - MOV R5,R9 - MOV R6,R10 - MOV R7,R11 - STMIA R0!,{R4-R7} // Save R8..R11 - -SVC_ContextSwitch: - SUBS R3,R3,#8 - STR R2,[R3] // osRtxInfo.thread.run: curr = next - -SVC_ContextRestore: - LDR R0,[R2,#TCB_SP_OFS] // Load SP - ADDS R0,R0,#16 // Adjust address - LDMIA R0!,{R4-R7} // Restore R8..R11 - MOV R8,R4 - MOV R9,R5 - MOV R10,R6 - MOV R11,R7 - MSR PSP,R0 // Set PSP - SUBS R0,R0,#32 // Adjust address - LDMIA R0!,{R4-R7} // Restore R4..R7 - - MOVS R0,#~0xFFFFFFFD - MVNS R0,R0 // Set EXC_RETURN value - BX R0 // Exit from handler - -SVC_Exit: - BX LR // Exit from handler - -SVC_User: - PUSH {R4,LR} // Save registers - LDR R2,=osRtxUserSVC // Load address of SVC table - LDR R3,[R2] // Load SVC maximum number - CMP R1,R3 // Check SVC number range - BHI SVC_Done // Branch if out of range - - LSLS R1,R1,#2 - LDR R4,[R2,R1] // Load address of SVC function - - LDMIA R0,{R0-R3} // Load function parameters from stack - BLX R4 // Call service function - MRS R4,PSP // Get PSP - STMIA R4!,{R0-R3} // Store function return values - -SVC_Done: - POP {R4,PC} // Return from handler - - .fnend - .size SVC_Handler, .-SVC_Handler - - - .thumb_func - .type PendSV_Handler, %function - .global PendSV_Handler - .fnstart - .cantunwind -PendSV_Handler: - - PUSH {R0,LR} // Save EXC_RETURN - BL osRtxPendSV_Handler // Call osRtxPendSV_Handler - POP {R0,R1} // Restore EXC_RETURN - MOV LR,R1 // Set EXC_RETURN - B SVC_Context - - .fnend - .size PendSV_Handler, .-PendSV_Handler - - - .thumb_func - .type SysTick_Handler, %function - .global SysTick_Handler - .fnstart - .cantunwind -SysTick_Handler: - - PUSH {R0,LR} // Save EXC_RETURN - BL osRtxTick_Handler // Call osRtxTick_Handler - POP {R0,R1} // Restore EXC_RETURN - MOV LR,R1 // Set EXC_RETURN - B SVC_Context - - .fnend - .size SysTick_Handler, .-SysTick_Handler - - - .end diff --git a/rtos/rtx5/TARGET_CORTEX_M/TARGET_M0P/TOOLCHAIN_IAR/irq_cm0.S b/rtos/rtx5/TARGET_CORTEX_M/TARGET_M0P/TOOLCHAIN_IAR/irq_cm0.S deleted file mode 100644 index 023aae3..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/TARGET_M0P/TOOLCHAIN_IAR/irq_cm0.S +++ /dev/null @@ -1,149 +0,0 @@ -;/* -; * Copyright (c) 2013-2017 ARM Limited. All rights reserved. -; * -; * SPDX-License-Identifier: Apache-2.0 -; * -; * Licensed under the Apache License, Version 2.0 (the License); you may -; * not use this file except in compliance with the License. -; * You may obtain a copy of the License at -; * -; * www.apache.org/licenses/LICENSE-2.0 -; * -; * Unless required by applicable law or agreed to in writing, software -; * distributed under the License is distributed on an AS IS BASIS, WITHOUT -; * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -; * See the License for the specific language governing permissions and -; * limitations under the License. -; * -; * ----------------------------------------------------------------------------- -; * -; * Project: CMSIS-RTOS RTX -; * Title: Cortex-M0 Exception handlers -; * -; * ----------------------------------------------------------------------------- -; */ - - - NAME irq_cm0.s - - -I_T_RUN_OFS EQU 28 ; osRtxInfo.thread.run offset -TCB_SP_OFS EQU 56 ; TCB.SP offset - - - PRESERVE8 - SECTION .rodata:DATA:NOROOT(2) - - - EXPORT irqRtxLib -irqRtxLib DCB 0 ; Non weak library reference - - - THUMB - SECTION .text:CODE:NOROOT(2) - - -SVC_Handler - EXPORT SVC_Handler - IMPORT osRtxUserSVC - IMPORT osRtxInfo - - MRS R0,PSP ; Get PSP - LDR R1,[R0,#24] ; Load saved PC from stack - SUBS R1,R1,#2 ; Point to SVC instruction - LDRB R1,[R1] ; Load SVC number - CMP R1,#0 - BNE SVC_User ; Branch if not SVC 0 - - PUSH {R0,LR} ; Save PSP and EXC_RETURN - LDMIA R0,{R0-R3} ; Load function parameters from stack - BLX R7 ; Call service function - POP {R2,R3} ; Restore PSP and EXC_RETURN - STMIA R2!,{R0-R1} ; Store function return values - MOV LR,R3 ; Set EXC_RETURN - -SVC_Context - LDR R3,=osRtxInfo+I_T_RUN_OFS; Load address of osRtxInfo.run - LDMIA R3!,{R1,R2} ; Load osRtxInfo.thread.run: curr & next - CMP R1,R2 ; Check if thread switch is required - BEQ SVC_Exit ; Branch when threads are the same - - CMP R1,#0 - BEQ SVC_ContextSwitch ; Branch if running thread is deleted - -SVC_ContextSave - MRS R0,PSP ; Get PSP - SUBS R0,R0,#32 ; Adjust address - STR R0,[R1,#TCB_SP_OFS] ; Store SP - STMIA R0!,{R4-R7} ; Save R4..R7 - MOV R4,R8 - MOV R5,R9 - MOV R6,R10 - MOV R7,R11 - STMIA R0!,{R4-R7} ; Save R8..R11 - -SVC_ContextSwitch - SUBS R3,R3,#8 - STR R2,[R3] ; osRtxInfo.thread.run: curr = next - -SVC_ContextRestore - LDR R0,[R2,#TCB_SP_OFS] ; Load SP - ADDS R0,R0,#16 ; Adjust address - LDMIA R0!,{R4-R7} ; Restore R8..R11 - MOV R8,R4 - MOV R9,R5 - MOV R10,R6 - MOV R11,R7 - MSR PSP,R0 ; Set PSP - SUBS R0,R0,#32 ; Adjust address - LDMIA R0!,{R4-R7} ; Restore R4..R7 - - MOVS R0,#~0xFFFFFFFD - MVNS R0,R0 ; Set EXC_RETURN value - BX R0 ; Exit from handler - -SVC_Exit - BX LR ; Exit from handler - -SVC_User - PUSH {R4,LR} ; Save registers - LDR R2,=osRtxUserSVC ; Load address of SVC table - LDR R3,[R2] ; Load SVC maximum number - CMP R1,R3 ; Check SVC number range - BHI SVC_Done ; Branch if out of range - - LSLS R1,R1,#2 - LDR R4,[R2,R1] ; Load address of SVC function - - LDMIA R0,{R0-R3} ; Load function parameters from stack - BLX R4 ; Call service function - MRS R4,PSP ; Get PSP - STMIA R4!,{R0-R3} ; Store function return values - -SVC_Done - POP {R4,PC} ; Return from handler - - -PendSV_Handler - EXPORT PendSV_Handler - IMPORT osRtxPendSV_Handler - - PUSH {R0,LR} ; Save EXC_RETURN - BL osRtxPendSV_Handler ; Call osRtxPendSV_Handler - POP {R0,R1} ; Restore EXC_RETURN - MOV LR,R1 ; Set EXC_RETURN - B SVC_Context - - -SysTick_Handler - EXPORT SysTick_Handler - IMPORT osRtxTick_Handler - - PUSH {R0,LR} ; Save EXC_RETURN - BL osRtxTick_Handler ; Call osRtxTick_Handler - POP {R0,R1} ; Restore EXC_RETURN - MOV LR,R1 ; Set EXC_RETURN - B SVC_Context - - - END diff --git a/rtos/rtx5/TARGET_CORTEX_M/TARGET_M3/TOOLCHAIN_ARM/irq_cm3.S b/rtos/rtx5/TARGET_CORTEX_M/TARGET_M3/TOOLCHAIN_ARM/irq_cm3.S deleted file mode 100644 index b951538..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/TARGET_M3/TOOLCHAIN_ARM/irq_cm3.S +++ /dev/null @@ -1,133 +0,0 @@ -;/* -; * Copyright (c) 2013-2017 ARM Limited. All rights reserved. -; * -; * SPDX-License-Identifier: Apache-2.0 -; * -; * Licensed under the Apache License, Version 2.0 (the License); you may -; * not use this file except in compliance with the License. -; * You may obtain a copy of the License at -; * -; * www.apache.org/licenses/LICENSE-2.0 -; * -; * Unless required by applicable law or agreed to in writing, software -; * distributed under the License is distributed on an AS IS BASIS, WITHOUT -; * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -; * See the License for the specific language governing permissions and -; * limitations under the License. -; * -; * ----------------------------------------------------------------------------- -; * -; * Project: CMSIS-RTOS RTX -; * Title: Cortex-M3 Exception handlers -; * -; * ----------------------------------------------------------------------------- -; */ - - -I_T_RUN_OFS EQU 28 ; osRtxInfo.thread.run offset -TCB_SP_OFS EQU 56 ; TCB.SP offset - - - PRESERVE8 - THUMB - - - AREA |.constdata|, DATA, READONLY - EXPORT irqRtxLib -irqRtxLib DCB 0 ; Non weak library reference - - - AREA |.text|, CODE, READONLY - - -SVC_Handler PROC - EXPORT SVC_Handler - IMPORT osRtxUserSVC - IMPORT osRtxInfo - - MRS R0,PSP ; Get PSP - LDR R1,[R0,#24] ; Load saved PC from stack - LDRB R1,[R1,#-2] ; Load SVC number - CBNZ R1,SVC_User ; Branch if not SVC 0 - - PUSH {R0,LR} ; Save PSP and EXC_RETURN - LDM R0,{R0-R3,R12} ; Load function parameters and address from stack - BLX R12 ; Call service function - POP {R12,LR} ; Restore PSP and EXC_RETURN - STM R12,{R0-R1} ; Store function return values - -SVC_Context - LDR R3,=osRtxInfo+I_T_RUN_OFS; Load address of osRtxInfo.run - LDM R3,{R1,R2} ; Load osRtxInfo.thread.run: curr & next - CMP R1,R2 ; Check if thread switch is required - BXEQ LR ; Exit when threads are the same - - CBZ R1,SVC_ContextSwitch ; Branch if running thread is deleted - -SVC_ContextSave - STMDB R12!,{R4-R11} ; Save R4..R11 - STR R12,[R1,#TCB_SP_OFS] ; Store SP - -SVC_ContextSwitch - STR R2,[R3] ; osRtxInfo.thread.run: curr = next - -SVC_ContextRestore - LDR R0,[R2,#TCB_SP_OFS] ; Load SP - LDMIA R0!,{R4-R11} ; Restore R4..R11 - MSR PSP,R0 ; Set PSP - - MVN LR,#~0xFFFFFFFD ; Set EXC_RETURN value - -SVC_Exit - BX LR ; Exit from handler - -SVC_User - PUSH {R4,LR} ; Save registers - LDR R2,=osRtxUserSVC ; Load address of SVC table - LDR R3,[R2] ; Load SVC maximum number - CMP R1,R3 ; Check SVC number range - BHI SVC_Done ; Branch if out of range - - LDR R4,[R2,R1,LSL #2] ; Load address of SVC function - - LDM R0,{R0-R3} ; Load function parameters from stack - BLX R4 ; Call service function - MRS R4,PSP ; Get PSP - STR R0,[R4] ; Store function return value - -SVC_Done - POP {R4,PC} ; Return from handler - - ALIGN - ENDP - - -PendSV_Handler PROC - EXPORT PendSV_Handler - IMPORT osRtxPendSV_Handler - - PUSH {R4,LR} ; Save EXC_RETURN - BL osRtxPendSV_Handler ; Call osRtxPendSV_Handler - POP {R4,LR} ; Restore EXC_RETURN - MRS R12,PSP - B SVC_Context - - ALIGN - ENDP - - -SysTick_Handler PROC - EXPORT SysTick_Handler - IMPORT osRtxTick_Handler - - PUSH {R4,LR} ; Save EXC_RETURN - BL osRtxTick_Handler ; Call osRtxTick_Handler - POP {R4,LR} ; Restore EXC_RETURN - MRS R12,PSP - B SVC_Context - - ALIGN - ENDP - - - END diff --git a/rtos/rtx5/TARGET_CORTEX_M/TARGET_M3/TOOLCHAIN_GCC/irq_cm3.S b/rtos/rtx5/TARGET_CORTEX_M/TARGET_M3/TOOLCHAIN_GCC/irq_cm3.S deleted file mode 100644 index f8684da..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/TARGET_M3/TOOLCHAIN_GCC/irq_cm3.S +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ----------------------------------------------------------------------------- - * - * Project: CMSIS-RTOS RTX - * Title: Cortex-M3 Exception handlers - * - * ----------------------------------------------------------------------------- - */ - - - .file "irq_cm3.S" - .syntax unified - - .equ I_T_RUN_OFS, 28 // osRtxInfo.thread.run offset - .equ TCB_SP_OFS, 56 // TCB.SP offset - - .section ".rodata" - .global irqRtxLib // Non weak library reference -irqRtxLib: - .byte 0 - - - .thumb - .section ".text" - .align 2 - - - .thumb_func - .type SVC_Handler, %function - .global SVC_Handler - .fnstart - .cantunwind -SVC_Handler: - - MRS R0,PSP // Get PSP - LDR R1,[R0,#24] // Load saved PC from stack - LDRB R1,[R1,#-2] // Load SVC number - CBNZ R1,SVC_User // Branch if not SVC 0 - - PUSH {R0,LR} // Save PSP and EXC_RETURN - LDM R0,{R0-R3,R12} // Load function parameters and address from stack - BLX R12 // Call service function - POP {R12,LR} // Restore PSP and EXC_RETURN - STM R12,{R0-R1} // Store function return values - -SVC_Context: - LDR R3,=osRtxInfo+I_T_RUN_OFS // Load address of osRtxInfo.run - LDM R3,{R1,R2} // Load osRtxInfo.thread.run: curr & next - CMP R1,R2 // Check if thread switch is required - IT EQ - BXEQ LR // Exit when threads are the same - - CBZ R1,SVC_ContextSwitch // Branch if running thread is deleted - -SVC_ContextSave: - STMDB R12!,{R4-R11} // Save R4..R11 - STR R12,[R1,#TCB_SP_OFS] // Store SP - -SVC_ContextSwitch: -#ifdef FEATURE_UVISOR - CPSID I // The call to the thread switch helper and PSP loading must be atomic. -#endif - /* The call to thread_switch_helper can clobber R2 and R3, but we don't - * want to clobber R2 or R3. We can't save R2 and R3 to the stack (as - * the stack we save them onto is likely to be inaccessible after the - * call to thread_switch_helper). So, we just re-obtain the values from - * osRtxInfo again. */ - BL thread_switch_helper - LDR R3,=osRtxInfo+I_T_RUN_OFS // Load address of osRtxInfo.run - LDM R3,{R1,R2} // Load osRtxInfo.thread.run: curr & next - - STR R2,[R3] // osRtxInfo.thread.run: curr = next - -SVC_ContextRestore: - LDR R0,[R2,#TCB_SP_OFS] // Load SP - LDMIA R0!,{R4-R11} // Restore R4..R11 - MSR PSP,R0 // Set PSP -#ifdef FEATURE_UVISOR - CPSIE I // The PSP has been set. Re-enable interrupts. -#endif - MVN LR,#~0xFFFFFFFD // Set EXC_RETURN value - -SVC_Exit: - BX LR // Exit from handler - -SVC_User: - PUSH {R4,LR} // Save registers - LDR R2,=osRtxUserSVC // Load address of SVC table - LDR R3,[R2] // Load SVC maximum number - CMP R1,R3 // Check SVC number range - BHI SVC_Done // Branch if out of range - - LDR R4,[R2,R1,LSL #2] // Load address of SVC function - - LDM R0,{R0-R3} // Load function parameters from stack - BLX R4 // Call service function - MRS R4,PSP // Get PSP - STR R0,[R4] // Store function return value - -SVC_Done: - POP {R4,PC} // Return from handler - - .fnend - .size SVC_Handler, .-SVC_Handler - - - .thumb_func - .type PendSV_Handler, %function - .global PendSV_Handler - .fnstart - .cantunwind -PendSV_Handler: - - PUSH {R4,LR} // Save EXC_RETURN - BL osRtxPendSV_Handler // Call osRtxPendSV_Handler - POP {R4,LR} // Restore EXC_RETURN - MRS R12,PSP - B SVC_Context - - .fnend - .size PendSV_Handler, .-PendSV_Handler - - - .thumb_func - .type SysTick_Handler, %function - .global SysTick_Handler - .fnstart - .cantunwind -SysTick_Handler: - - PUSH {R4,LR} // Save EXC_RETURN - BL osRtxTick_Handler // Call osRtxTick_Handler - POP {R4,LR} // Restore EXC_RETURN - MRS R12,PSP - B SVC_Context - - .fnend - .size SysTick_Handler, .-SysTick_Handler - - - .end diff --git a/rtos/rtx5/TARGET_CORTEX_M/TARGET_M3/TOOLCHAIN_IAR/irq_cm3.S b/rtos/rtx5/TARGET_CORTEX_M/TARGET_M3/TOOLCHAIN_IAR/irq_cm3.S deleted file mode 100644 index bfc3b33..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/TARGET_M3/TOOLCHAIN_IAR/irq_cm3.S +++ /dev/null @@ -1,128 +0,0 @@ -;/* -; * Copyright (c) 2013-2017 ARM Limited. All rights reserved. -; * -; * SPDX-License-Identifier: Apache-2.0 -; * -; * Licensed under the Apache License, Version 2.0 (the License); you may -; * not use this file except in compliance with the License. -; * You may obtain a copy of the License at -; * -; * www.apache.org/licenses/LICENSE-2.0 -; * -; * Unless required by applicable law or agreed to in writing, software -; * distributed under the License is distributed on an AS IS BASIS, WITHOUT -; * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -; * See the License for the specific language governing permissions and -; * limitations under the License. -; * -; * ----------------------------------------------------------------------------- -; * -; * Project: CMSIS-RTOS RTX -; * Title: Cortex-M3 Exception handlers -; * -; * ----------------------------------------------------------------------------- -; */ - - - NAME irq_cm3.s - - -I_T_RUN_OFS EQU 28 ; osRtxInfo.thread.run offset -TCB_SP_OFS EQU 56 ; TCB.SP offset - - - PRESERVE8 - SECTION .rodata:DATA:NOROOT(2) - - - EXPORT irqRtxLib -irqRtxLib DCB 0 ; Non weak library reference - - - THUMB - SECTION .text:CODE:NOROOT(2) - - -SVC_Handler - EXPORT SVC_Handler - IMPORT osRtxUserSVC - IMPORT osRtxInfo - - MRS R0,PSP ; Get PSP - LDR R1,[R0,#24] ; Load saved PC from stack - LDRB R1,[R1,#-2] ; Load SVC number - CBNZ R1,SVC_User ; Branch if not SVC 0 - - PUSH {R0,LR} ; Save PSP and EXC_RETURN - LDM R0,{R0-R3,R12} ; Load function parameters and address from stack - BLX R12 ; Call service function - POP {R12,LR} ; Restore PSP and EXC_RETURN - STM R12,{R0-R1} ; Store function return values - -SVC_Context - LDR R3,=osRtxInfo+I_T_RUN_OFS; Load address of osRtxInfo.run - LDM R3,{R1,R2} ; Load osRtxInfo.thread.run: curr & next - CMP R1,R2 ; Check if thread switch is required - IT EQ - BXEQ LR ; Exit when threads are the same - - CBZ R1,SVC_ContextSwitch ; Branch if running thread is deleted - -SVC_ContextSave - STMDB R12!,{R4-R11} ; Save R4..R11 - STR R12,[R1,#TCB_SP_OFS] ; Store SP - -SVC_ContextSwitch - STR R2,[R3] ; osRtxInfo.thread.run: curr = next - -SVC_ContextRestore - LDR R0,[R2,#TCB_SP_OFS] ; Load SP - LDMIA R0!,{R4-R11} ; Restore R4..R11 - MSR PSP,R0 ; Set PSP - - MVN LR,#~0xFFFFFFFD ; Set EXC_RETURN value - -SVC_Exit - BX LR ; Exit from handler - -SVC_User - PUSH {R4,LR} ; Save registers - LDR R2,=osRtxUserSVC ; Load address of SVC table - LDR R3,[R2] ; Load SVC maximum number - CMP R1,R3 ; Check SVC number range - BHI SVC_Done ; Branch if out of range - - LDR R4,[R2,R1,LSL #2] ; Load address of SVC function - - LDM R0,{R0-R3} ; Load function parameters from stack - BLX R4 ; Call service function - MRS R4,PSP ; Get PSP - STR R0,[R4] ; Store function return value - -SVC_Done - POP {R4,PC} ; Return from handler - - -PendSV_Handler - EXPORT PendSV_Handler - IMPORT osRtxPendSV_Handler - - PUSH {R4,LR} ; Save EXC_RETURN - BL osRtxPendSV_Handler ; Call osRtxPendSV_Handler - POP {R4,LR} ; Restore EXC_RETURN - MRS R12,PSP - B SVC_Context - - -SysTick_Handler - EXPORT SysTick_Handler - IMPORT osRtxTick_Handler - - PUSH {R4,LR} ; Save EXC_RETURN - BL osRtxTick_Handler ; Call osRtxTick_Handler - POP {R4,LR} ; Restore EXC_RETURN - MRS R12,PSP - B SVC_Context - - - END diff --git a/rtos/rtx5/TARGET_CORTEX_M/TARGET_RTOS_M4_M7/TOOLCHAIN_ARM/irq_cm4f.S b/rtos/rtx5/TARGET_CORTEX_M/TARGET_RTOS_M4_M7/TOOLCHAIN_ARM/irq_cm4f.S deleted file mode 100644 index 84ad0b5..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/TARGET_RTOS_M4_M7/TOOLCHAIN_ARM/irq_cm4f.S +++ /dev/null @@ -1,154 +0,0 @@ -;/* -; * Copyright (c) 2013-2017 ARM Limited. All rights reserved. -; * -; * SPDX-License-Identifier: Apache-2.0 -; * -; * Licensed under the Apache License, Version 2.0 (the License); you may -; * not use this file except in compliance with the License. -; * You may obtain a copy of the License at -; * -; * www.apache.org/licenses/LICENSE-2.0 -; * -; * Unless required by applicable law or agreed to in writing, software -; * distributed under the License is distributed on an AS IS BASIS, WITHOUT -; * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -; * See the License for the specific language governing permissions and -; * limitations under the License. -; * -; * ----------------------------------------------------------------------------- -; * -; * Project: CMSIS-RTOS RTX -; * Title: Cortex-M4F Exception handlers -; * -; * ----------------------------------------------------------------------------- -; */ - - -I_T_RUN_OFS EQU 28 ; osRtxInfo.thread.run offset -TCB_SP_OFS EQU 56 ; TCB.SP offset -TCB_SF_OFS EQU 34 ; TCB.stack_frame offset - - - PRESERVE8 - THUMB - - - AREA |.constdata|, DATA, READONLY - EXPORT irqRtxLib -irqRtxLib DCB 0 ; Non weak library reference - - - AREA |.text|, CODE, READONLY - - -SVC_Handler PROC - EXPORT SVC_Handler - IMPORT osRtxUserSVC - IMPORT osRtxInfo - - MRS R0,PSP ; Get PSP - LDR R1,[R0,#24] ; Load saved PC from stack - LDRB R1,[R1,#-2] ; Load SVC number - CBNZ R1,SVC_User ; Branch if not SVC 0 - - PUSH {R0,LR} ; Save PSP and EXC_RETURN - LDM R0,{R0-R3,R12} ; Load function parameters and address from stack - BLX R12 ; Call service function - POP {R12,LR} ; Restore PSP and EXC_RETURN - STM R12,{R0-R1} ; Store function return values - -SVC_Context - LDR R3,=osRtxInfo+I_T_RUN_OFS; Load address of osRtxInfo.run - LDM R3,{R1,R2} ; Load osRtxInfo.thread.run: curr & next - CMP R1,R2 ; Check if thread switch is required - BXEQ LR ; Exit when threads are the same - - CBNZ R1,SVC_ContextSave ; Branch if running thread is not deleted - TST LR,#0x10 ; Check if extended stack frame - BNE SVC_ContextSwitch -#ifdef __FPU_PRESENT - LDR R1,=0xE000EF34 ; FPCCR Address - LDR R0,[R1] ; Load FPCCR - BIC R0,#1 ; Clear LSPACT (Lazy state) - STR R0,[R1] ; Store FPCCR - B SVC_ContextSwitch -#endif - -SVC_ContextSave - STMDB R12!,{R4-R11} ; Save R4..R11 -#ifdef __FPU_PRESENT - TST LR,#0x10 ; Check if extended stack frame - VSTMDBEQ R12!,{S16-S31} ; Save VFP S16.S31 -#endif - - STR R12,[R1,#TCB_SP_OFS] ; Store SP - STRB LR, [R1,#TCB_SF_OFS] ; Store stack frame information - -SVC_ContextSwitch - STR R2,[R3] ; osRtxInfo.thread.run: curr = next - -SVC_ContextRestore - LDRB R1,[R2,#TCB_SF_OFS] ; Load stack frame information - LDR R0,[R2,#TCB_SP_OFS] ; Load SP - ORR LR,R1,#0xFFFFFF00 ; Set EXC_RETURN - -#ifdef __FPU_PRESENT - TST LR,#0x10 ; Check if extended stack frame - VLDMIAEQ R0!,{S16-S31} ; Restore VFP S16..S31 -#endif - LDMIA R0!,{R4-R11} ; Restore R4..R11 - MSR PSP,R0 ; Set PSP - -SVC_Exit - BX LR ; Exit from handler - -SVC_User - PUSH {R4,LR} ; Save registers - LDR R2,=osRtxUserSVC ; Load address of SVC table - LDR R3,[R2] ; Load SVC maximum number - CMP R1,R3 ; Check SVC number range - BHI SVC_Done ; Branch if out of range - - LDR R4,[R2,R1,LSL #2] ; Load address of SVC function - - LDM R0,{R0-R3} ; Load function parameters from stack - BLX R4 ; Call service function - MRS R4,PSP ; Get PSP - STR R0,[R4] ; Store function return value - -SVC_Done - POP {R4,PC} ; Return from handler - - ALIGN - ENDP - - -PendSV_Handler PROC - EXPORT PendSV_Handler - IMPORT osRtxPendSV_Handler - - PUSH {R4,LR} ; Save EXC_RETURN - BL osRtxPendSV_Handler ; Call osRtxPendSV_Handler - POP {R4,LR} ; Restore EXC_RETURN - MRS R12,PSP - B SVC_Context - - ALIGN - ENDP - - -SysTick_Handler PROC - EXPORT SysTick_Handler - IMPORT osRtxTick_Handler - - PUSH {R4,LR} ; Save EXC_RETURN - BL osRtxTick_Handler ; Call osRtxTick_Handler - POP {R4,LR} ; Restore EXC_RETURN - MRS R12,PSP - B SVC_Context - - ALIGN - ENDP - - - END diff --git a/rtos/rtx5/TARGET_CORTEX_M/TARGET_RTOS_M4_M7/TOOLCHAIN_GCC/irq_cm4f.S b/rtos/rtx5/TARGET_CORTEX_M/TARGET_RTOS_M4_M7/TOOLCHAIN_GCC/irq_cm4f.S deleted file mode 100644 index fd57b7f..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/TARGET_RTOS_M4_M7/TOOLCHAIN_GCC/irq_cm4f.S +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ----------------------------------------------------------------------------- - * - * Project: CMSIS-RTOS RTX - * Title: Cortex-M4F Exception handlers - * - * ----------------------------------------------------------------------------- - */ - - - .file "irq_cm4f.S" - .syntax unified - - .equ I_T_RUN_OFS, 28 // osRtxInfo.thread.run offset - .equ TCB_SP_OFS, 56 // TCB.SP offset - .equ TCB_SF_OFS, 34 // TCB.stack_frame offset - - .section ".rodata" - .global irqRtxLib // Non weak library reference -irqRtxLib: - .byte 0 - - - .thumb - .section ".text" - .align 2 - - - .thumb_func - .type SVC_Handler, %function - .global SVC_Handler - .fnstart - .cantunwind -SVC_Handler: - - MRS R0,PSP // Get PSP - LDR R1,[R0,#24] // Load saved PC from stack - LDRB R1,[R1,#-2] // Load SVC number - CBNZ R1,SVC_User // Branch if not SVC 0 - - PUSH {R0,LR} // Save PSP and EXC_RETURN - LDM R0,{R0-R3,R12} // Load function parameters and address from stack - BLX R12 // Call service function - POP {R12,LR} // Restore PSP and EXC_RETURN - STM R12,{R0-R1} // Store function return values - -SVC_Context: - LDR R3,=osRtxInfo+I_T_RUN_OFS // Load address of osRtxInfo.run - LDM R3,{R1,R2} // Load osRtxInfo.thread.run: curr & next - CMP R1,R2 // Check if thread switch is required - IT EQ - BXEQ LR // Exit when threads are the same - - CBNZ R1,SVC_ContextSave // Branch if running thread is not deleted - TST LR,#0x10 // Check if extended stack frame - BNE SVC_ContextSwitch -#ifdef __FPU_PRESENT - LDR R1,=0xE000EF34 // FPCCR Address - LDR R0,[R1] // Load FPCCR - BIC R0,#1 // Clear LSPACT (Lazy state) - STR R0,[R1] // Store FPCCR - B SVC_ContextSwitch -#endif - -SVC_ContextSave: - STMDB R12!,{R4-R11} // Save R4..R11 - -#ifdef __FPU_PRESENT - TST LR,#0x10 // Check if extended stack frame - IT EQ - VSTMDBEQ R12!,{S16-S31} // Save VFP S16.S31 -#endif - - STR R12,[R1,#TCB_SP_OFS] // Store SP - STRB LR, [R1,#TCB_SF_OFS] // Store stack frame information - -SVC_ContextSwitch: -#ifdef FEATURE_UVISOR - CPSID I // The call to the thread switch helper and PSP loading must be atomic. -#endif - /* The call to thread_switch_helper can clobber R2 and R3, but we don't - * want to clobber R2 or R3. We can't save R2 and R3 to the stack (as - * the stack we save them onto is likely to be inaccessible after the - * call to thread_switch_helper). So, we just re-obtain the values from - * osRtxInfo again. */ - BL thread_switch_helper - LDR R3,=osRtxInfo+I_T_RUN_OFS // Load address of osRtxInfo.run - LDM R3,{R1,R2} // Load osRtxInfo.thread.run: curr & next - - STR R2,[R3] // osRtxInfo.thread.run: curr = next - -SVC_ContextRestore: - LDRB R1,[R2,#TCB_SF_OFS] // Load stack frame information - LDR R0,[R2,#TCB_SP_OFS] // Load SP - ORR LR,R1,#0xFFFFFF00 // Set EXC_RETURN - -#ifdef __FPU_PRESENT - TST LR,#0x10 // Check if extended stack frame - IT EQ - VLDMIAEQ R0!,{S16-S31} // Restore VFP S16..S31 -#endif - LDMIA R0!,{R4-R11} // Restore R4..R11 - MSR PSP,R0 // Set PSP -#ifdef FEATURE_UVISOR - CPSIE I // The PSP has been set. Re-enable interrupts. -#endif - -SVC_Exit: - BX LR // Exit from handler - -SVC_User: - PUSH {R4,LR} // Save registers - LDR R2,=osRtxUserSVC // Load address of SVC table - LDR R3,[R2] // Load SVC maximum number - CMP R1,R3 // Check SVC number range - BHI SVC_Done // Branch if out of range - - LDR R4,[R2,R1,LSL #2] // Load address of SVC function - - LDM R0,{R0-R3} // Load function parameters from stack - BLX R4 // Call service function - MRS R4,PSP // Get PSP - STR R0,[R4] // Store function return value - -SVC_Done: - POP {R4,PC} // Return from handler - - .fnend - .size SVC_Handler, .-SVC_Handler - - - .thumb_func - .type PendSV_Handler, %function - .global PendSV_Handler - .fnstart - .cantunwind -PendSV_Handler: - - PUSH {R4,LR} // Save EXC_RETURN - BL osRtxPendSV_Handler // Call osRtxPendSV_Handler - POP {R4,LR} // Restore EXC_RETURN - MRS R12,PSP - B SVC_Context - - .fnend - .size PendSV_Handler, .-PendSV_Handler - - - .thumb_func - .type SysTick_Handler, %function - .global SysTick_Handler - .fnstart - .cantunwind -SysTick_Handler: - - PUSH {R4,LR} // Save EXC_RETURN - BL osRtxTick_Handler // Call osRtxTick_Handler - POP {R4,LR} // Restore EXC_RETURN - MRS R12,PSP - B SVC_Context - - .fnend - .size SysTick_Handler, .-SysTick_Handler - - - .end diff --git a/rtos/rtx5/TARGET_CORTEX_M/TARGET_RTOS_M4_M7/TOOLCHAIN_IAR/irq_cm4f.S b/rtos/rtx5/TARGET_CORTEX_M/TARGET_RTOS_M4_M7/TOOLCHAIN_IAR/irq_cm4f.S deleted file mode 100644 index e194af1..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/TARGET_RTOS_M4_M7/TOOLCHAIN_IAR/irq_cm4f.S +++ /dev/null @@ -1,150 +0,0 @@ -;/* -; * Copyright (c) 2013-2017 ARM Limited. All rights reserved. -; * -; * SPDX-License-Identifier: Apache-2.0 -; * -; * Licensed under the Apache License, Version 2.0 (the License); you may -; * not use this file except in compliance with the License. -; * You may obtain a copy of the License at -; * -; * www.apache.org/licenses/LICENSE-2.0 -; * -; * Unless required by applicable law or agreed to in writing, software -; * distributed under the License is distributed on an AS IS BASIS, WITHOUT -; * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -; * See the License for the specific language governing permissions and -; * limitations under the License. -; * -; * ----------------------------------------------------------------------------- -; * -; * Project: CMSIS-RTOS RTX -; * Title: Cortex-M4F Exception handlers -; * -; * ----------------------------------------------------------------------------- -; */ - - - NAME irq_cm4f.s - - -I_T_RUN_OFS EQU 28 ; osRtxInfo.thread.run offset -TCB_SP_OFS EQU 56 ; TCB.SP offset -TCB_SF_OFS EQU 34 ; TCB.stack_frame offset - - - PRESERVE8 - SECTION .rodata:DATA:NOROOT(2) - - - EXPORT irqRtxLib -irqRtxLib DCB 0 ; Non weak library reference - - - THUMB - SECTION .text:CODE:NOROOT(2) - -SVC_Handler - EXPORT SVC_Handler - IMPORT osRtxUserSVC - IMPORT osRtxInfo - - MRS R0,PSP ; Get PSP - LDR R1,[R0,#24] ; Load saved PC from stack - LDRB R1,[R1,#-2] ; Load SVC number - CBNZ R1,SVC_User ; Branch if not SVC 0 - - PUSH {R0,LR} ; Save PSP and EXC_RETURN - LDM R0,{R0-R3,R12} ; Load function parameters and address from stack - BLX R12 ; Call service function - POP {R12,LR} ; Restore PSP and EXC_RETURN - STM R12,{R0-R1} ; Store function return values - -SVC_Context - LDR R3,=osRtxInfo+I_T_RUN_OFS; Load address of osRtxInfo.run - LDM R3,{R1,R2} ; Load osRtxInfo.thread.run: curr & next - CMP R1,R2 ; Check if thread switch is required - IT EQ - BXEQ LR ; Exit when threads are the same - - CBNZ R1,SVC_ContextSave ; Branch if running thread is not deleted - TST LR,#0x10 ; Check if extended stack frame - BNE SVC_ContextSwitch -#ifdef __FPU_PRESENT - LDR R1,=0xE000EF34 ; FPCCR Address - LDR R0,[R1] ; Load FPCCR - BIC R0,R0,#1 ; Clear LSPACT (Lazy state) - STR R0,[R1] ; Store FPCCR - B SVC_ContextSwitch -#endif - -SVC_ContextSave - STMDB R12!,{R4-R11} ; Save R4..R11 -#ifdef __FPU_PRESENT - TST LR,#0x10 ; Check if extended stack frame - IT EQ - VSTMDBEQ R12!,{S16-S31} ; Save VFP S16.S31 -#endif - - STR R12,[R1,#TCB_SP_OFS] ; Store SP - STRB LR, [R1,#TCB_SF_OFS] ; Store stack frame information - -SVC_ContextSwitch - STR R2,[R3] ; osRtxInfo.thread.run: curr = next - -SVC_ContextRestore - LDRB R1,[R2,#TCB_SF_OFS] ; Load stack frame information - LDR R0,[R2,#TCB_SP_OFS] ; Load SP - ORR LR,R1,#0xFFFFFF00 ; Set EXC_RETURN - -#ifdef __FPU_PRESENT - TST LR,#0x10 ; Check if extended stack frame - IT EQ - VLDMIAEQ R0!,{S16-S31} ; Restore VFP S16..S31 -#endif - LDMIA R0!,{R4-R11} ; Restore R4..R11 - MSR PSP,R0 ; Set PSP - -SVC_Exit - BX LR ; Exit from handler - -SVC_User - PUSH {R4,LR} ; Save registers - LDR R2,=osRtxUserSVC ; Load address of SVC table - LDR R3,[R2] ; Load SVC maximum number - CMP R1,R3 ; Check SVC number range - BHI SVC_Done ; Branch if out of range - - LDR R4,[R2,R1,LSL #2] ; Load address of SVC function - - LDM R0,{R0-R3} ; Load function parameters from stack - BLX R4 ; Call service function - MRS R4,PSP ; Get PSP - STR R0,[R4] ; Store function return value - -SVC_Done - POP {R4,PC} ; Return from handler - - -PendSV_Handler - EXPORT PendSV_Handler - IMPORT osRtxPendSV_Handler - - PUSH {R4,LR} ; Save EXC_RETURN - BL osRtxPendSV_Handler ; Call osRtxPendSV_Handler - POP {R4,LR} ; Restore EXC_RETURN - MRS R12,PSP - B SVC_Context - - -SysTick_Handler - EXPORT SysTick_Handler - IMPORT osRtxTick_Handler - - PUSH {R4,LR} ; Save EXC_RETURN - BL osRtxTick_Handler ; Call osRtxTick_Handler - POP {R4,LR} ; Restore EXC_RETURN - MRS R12,PSP - B SVC_Context - - - END diff --git a/rtos/rtx5/TARGET_CORTEX_M/TESTS/memory/heap_and_stack/main.cpp b/rtos/rtx5/TARGET_CORTEX_M/TESTS/memory/heap_and_stack/main.cpp deleted file mode 100644 index 7e27350..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/TESTS/memory/heap_and_stack/main.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright (c) 2016-2016, ARM Limited, All Rights Reserved - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include -#include -#include -#include "greentea-client/test_env.h" -#include "cmsis.h" -#include "mbed.h" -#include "rtos.h" -#include "mbed_assert.h" - -// Amount to malloc for each iteration -#define MALLOC_TEST_SIZE 256 -// Malloc fill pattern -#define MALLOC_FILL 0x55 - -extern uint32_t mbed_heap_start; -extern uint32_t mbed_heap_size; -extern uint32_t mbed_stack_isr_start; -extern uint32_t mbed_stack_isr_size; - -static uint32_t max_allocation_size = 0; - -static bool inrange(uint32_t addr, uint32_t start, uint32_t size); -static bool rangeinrange(uint32_t addr, uint32_t size, uint32_t start, uint32_t len); -static bool valid_fill(uint8_t * data, uint32_t size, uint8_t fill); -static bool allocate_and_fill_heap(void); -static bool check_and_free_heap(void); - -int main (void) { - GREENTEA_SETUP(30, "default_auto"); - - char c; - char * initial_stack = &c; - char *initial_heap; - - // Sanity check malloc - initial_heap = (char*)malloc(1); - if (initial_heap == NULL) { - printf("Unable to malloc a single byte\n"); - GREENTEA_TESTSUITE_RESULT(false); - } - - if (!inrange((uint32_t)initial_heap, mbed_heap_start, mbed_heap_size)) { - printf("Heap in wrong location\n"); - GREENTEA_TESTSUITE_RESULT(false); - } - // MSP stack should be very near end (test using within 128 bytes) - uint32_t msp = __get_MSP(); - if (!inrange(msp, mbed_stack_isr_start + mbed_stack_isr_size - 128, 128)) { - printf("Interrupt stack in wrong location\n"); - GREENTEA_TESTSUITE_RESULT(false); - } - - // Fully allocate the heap and stack - bool ret = true; - ret = ret && allocate_and_fill_heap(); - ret = ret && check_and_free_heap(); - - // Force a task switch so a stack check is performed - Thread::wait(10); - - printf("Total size dynamically allocated: %lu\n", max_allocation_size); - - GREENTEA_TESTSUITE_RESULT(ret); -} - -/* - * Return true if addr is in range [start:start+size) - */ -static bool inrange(uint32_t addr, uint32_t start, uint32_t size) -{ - return (addr >= start) && (addr < start + size) ? true : false; -} - -/* - * Return true if [addr:addr+size] is inside [start:start+len] - */ -static bool rangeinrange(uint32_t addr, uint32_t size, uint32_t start, uint32_t len) -{ - if (addr + size > start + len) { - return false; - } - if (addr < start) { - return false; - } - return true; -} - -/* - * Return true of the region is filled only the the specified fill value - */ -static bool valid_fill(uint8_t * data, uint32_t size, uint8_t fill) -{ - for (uint32_t i = 0; i < size; i++) { - if (data[i] != fill) { - return false; - } - } - return true; -} - -struct linked_list { - linked_list * next; - uint8_t data[MALLOC_TEST_SIZE]; -}; - -static linked_list *head = NULL; -static bool allocate_and_fill_heap() -{ - - linked_list *current; - - current = (linked_list*)malloc(sizeof(linked_list)); - if (0 == current) { - return false; - } - current->next = NULL; - memset((void*)current->data, MALLOC_FILL, sizeof(current->data)); - - // Allocate until malloc returns NULL - bool pass = true; - head = current; - while (true) { - - // Allocate - linked_list *temp = (linked_list*)malloc(sizeof(linked_list)); - if (NULL == temp) { - break; - } - if (!rangeinrange((uint32_t)temp, sizeof(linked_list), mbed_heap_start, mbed_heap_size)) { - printf("Memory allocation out of range\n"); - pass = false; - break; - } - - // Init - temp->next = NULL; - memset((void*)temp->data, MALLOC_FILL, sizeof(current->data)); - - // Add to list - current->next = temp; - current = temp; - } - return pass; -} - -static bool check_and_free_heap() -{ - uint32_t total_size = 0; - linked_list * current = head; - bool pass = true; - while (current != NULL) { - total_size += sizeof(linked_list); - if (!valid_fill(current->data, sizeof(current->data), MALLOC_FILL)) { - pass = false; - } - linked_list * next = current->next; - free(current); - current = next; - } - - max_allocation_size = total_size; - return pass; -} diff --git a/rtos/rtx5/TARGET_CORTEX_M/cmsis_os2.h b/rtos/rtx5/TARGET_CORTEX_M/cmsis_os2.h deleted file mode 100644 index 6ae6513..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/cmsis_os2.h +++ /dev/null @@ -1,750 +0,0 @@ -/** \addtogroup rtos */ -/** @{*/ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ---------------------------------------------------------------------- - * - * $Date: 10. January 2017 - * $Revision: V2.1.0 - * - * Project: CMSIS-RTOS2 API - * Title: cmsis_os2.h header file - * - * Version 2.1.0 - * Support for critical and uncritical sections (nesting safe): - * - updated: osKernelLock, osKernelUnlock - * - added: osKernelRestoreLock - * Updated Thread and Event Flags: - * - changed flags parameter and return type from int32_t to uint32_t - * Version 2.0.0 - * Initial Release - *---------------------------------------------------------------------------*/ - -#ifndef CMSIS_OS2_H_ -#define CMSIS_OS2_H_ - -#ifndef __NO_RETURN -#if defined(__CC_ARM) -#define __NO_RETURN __declspec(noreturn) -#elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) -#define __NO_RETURN __attribute__((noreturn)) -#elif defined(__GNUC__) -#define __NO_RETURN __attribute__((noreturn)) -#elif defined(__ICCARM__) -#define __NO_RETURN __noreturn -#else -#define __NO_RETURN -#endif -#endif - -#include -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - - -// ==== Enumerations, structures, defines ==== - -/// Version information. -typedef struct { - uint32_t api; ///< API version (major.minor.rev: mmnnnrrrr dec). - uint32_t kernel; ///< Kernel version (major.minor.rev: mmnnnrrrr dec). -} osVersion_t; - -/// Kernel state. -typedef enum { - osKernelInactive = 0, ///< Inactive. - osKernelReady = 1, ///< Ready. - osKernelRunning = 2, ///< Running. - osKernelLocked = 3, ///< Locked. - osKernelSuspended = 4, ///< Suspended. - osKernelError = -1, ///< Error. - osKernelReserved = 0x7FFFFFFFU ///< Prevents enum down-size compiler optimization. -} osKernelState_t; - -/// Thread state. -typedef enum { - osThreadInactive = 0, ///< Inactive. - osThreadReady = 1, ///< Ready. - osThreadRunning = 2, ///< Running. - osThreadBlocked = 3, ///< Blocked. - osThreadTerminated = 4, ///< Terminated. - osThreadError = -1, ///< Error. - osThreadReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization. -} osThreadState_t; - -/// Priority values. -typedef enum { - osPriorityNone = 0, ///< No priority (not initialized). - osPriorityIdle = 1, ///< Reserved for Idle thread. - osPriorityLow = 8, ///< Priority: low - osPriorityLow1 = 8+1, ///< Priority: low + 1 - osPriorityLow2 = 8+2, ///< Priority: low + 2 - osPriorityLow3 = 8+3, ///< Priority: low + 3 - osPriorityLow4 = 8+4, ///< Priority: low + 4 - osPriorityLow5 = 8+5, ///< Priority: low + 5 - osPriorityLow6 = 8+6, ///< Priority: low + 6 - osPriorityLow7 = 8+7, ///< Priority: low + 7 - osPriorityBelowNormal = 16, ///< Priority: below normal - osPriorityBelowNormal1 = 16+1, ///< Priority: below normal + 1 - osPriorityBelowNormal2 = 16+2, ///< Priority: below normal + 2 - osPriorityBelowNormal3 = 16+3, ///< Priority: below normal + 3 - osPriorityBelowNormal4 = 16+4, ///< Priority: below normal + 4 - osPriorityBelowNormal5 = 16+5, ///< Priority: below normal + 5 - osPriorityBelowNormal6 = 16+6, ///< Priority: below normal + 6 - osPriorityBelowNormal7 = 16+7, ///< Priority: below normal + 7 - osPriorityNormal = 24, ///< Priority: normal - osPriorityNormal1 = 24+1, ///< Priority: normal + 1 - osPriorityNormal2 = 24+2, ///< Priority: normal + 2 - osPriorityNormal3 = 24+3, ///< Priority: normal + 3 - osPriorityNormal4 = 24+4, ///< Priority: normal + 4 - osPriorityNormal5 = 24+5, ///< Priority: normal + 5 - osPriorityNormal6 = 24+6, ///< Priority: normal + 6 - osPriorityNormal7 = 24+7, ///< Priority: normal + 7 - osPriorityAboveNormal = 32, ///< Priority: above normal - osPriorityAboveNormal1 = 32+1, ///< Priority: above normal + 1 - osPriorityAboveNormal2 = 32+2, ///< Priority: above normal + 2 - osPriorityAboveNormal3 = 32+3, ///< Priority: above normal + 3 - osPriorityAboveNormal4 = 32+4, ///< Priority: above normal + 4 - osPriorityAboveNormal5 = 32+5, ///< Priority: above normal + 5 - osPriorityAboveNormal6 = 32+6, ///< Priority: above normal + 6 - osPriorityAboveNormal7 = 32+7, ///< Priority: above normal + 7 - osPriorityHigh = 40, ///< Priority: high - osPriorityHigh1 = 40+1, ///< Priority: high + 1 - osPriorityHigh2 = 40+2, ///< Priority: high + 2 - osPriorityHigh3 = 40+3, ///< Priority: high + 3 - osPriorityHigh4 = 40+4, ///< Priority: high + 4 - osPriorityHigh5 = 40+5, ///< Priority: high + 5 - osPriorityHigh6 = 40+6, ///< Priority: high + 6 - osPriorityHigh7 = 40+7, ///< Priority: high + 7 - osPriorityRealtime = 48, ///< Priority: realtime - osPriorityRealtime1 = 48+1, ///< Priority: realtime + 1 - osPriorityRealtime2 = 48+2, ///< Priority: realtime + 2 - osPriorityRealtime3 = 48+3, ///< Priority: realtime + 3 - osPriorityRealtime4 = 48+4, ///< Priority: realtime + 4 - osPriorityRealtime5 = 48+5, ///< Priority: realtime + 5 - osPriorityRealtime6 = 48+6, ///< Priority: realtime + 6 - osPriorityRealtime7 = 48+7, ///< Priority: realtime + 7 - osPriorityISR = 56, ///< Reserved for ISR deferred thread. - osPriorityError = -1, ///< System cannot determine priority or illegal priority. - osPriorityReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization. -} osPriority_t; - -/// Entry point of a thread. -typedef void (*osThreadFunc_t) (void *argument); - -/// Entry point of a timer call back function. -typedef void (*osTimerFunc_t) (void *argument); - -/// Timer type. -typedef enum { - osTimerOnce = 0, ///< One-shot timer. - osTimerPeriodic = 1 ///< Repeating timer. -} osTimerType_t; - -/// Timeout value. -#define osWaitForever 0xFFFFFFFFU ///< Wait forever timeout value. - -/// Flags options (\ref osThreadFlagsWait and \ref osEventFlagsWait). -#define osFlagsWaitAny 0x00000000U ///< Wait for any flag (default). -#define osFlagsWaitAll 0x00000001U ///< Wait for all flags. -#define osFlagsNoClear 0x00000002U ///< Do not clear flags which have been specified to wait for. - -/// Flags errors (returned by osThreadFlagsXxxx and osEventFlagsXxxx). -#define osFlagsError 0x80000000U ///< Error indicator. -#define osFlagsErrorUnknown 0xFFFFFFFFU ///< osError (-1). -#define osFlagsErrorTimeout 0xFFFFFFFEU ///< osErrorTimeout (-2). -#define osFlagsErrorResource 0xFFFFFFFDU ///< osErrorResource (-3). -#define osFlagsErrorParameter 0xFFFFFFFCU ///< osErrorParameter (-4). -#define osFlagsErrorISR 0xFFFFFFFAU ///< osErrorISR (-6). - -/// Thread attributes (attr_bits in \ref osThreadAttr_t). -#define osThreadDetached 0x00000000U ///< Thread created in detached state (default) -#define osThreadJoinable 0x00000001U ///< Thread created in joinable state - -/// Mutex attributes (attr_bits in \ref osMutexAttr_t). -#define osMutexRecursive 0x00000001U ///< Recursive mutex. -#define osMutexPrioInherit 0x00000002U ///< Priority inherit protocol. -#define osMutexRobust 0x00000008U ///< Robust mutex. - -/// Status code values returned by CMSIS-RTOS functions. -typedef enum { - osOK = 0, ///< Operation completed successfully. - osError = -1, ///< Unspecified RTOS error: run-time error but no other error message fits. - osErrorTimeout = -2, ///< Operation not completed within the timeout period. - osErrorResource = -3, ///< Resource not available. - osErrorParameter = -4, ///< Parameter error. - osErrorNoMemory = -5, ///< System is out of memory: it was impossible to allocate or reserve memory for the operation. - osErrorISR = -6, ///< Not allowed in ISR context: the function cannot be called from interrupt service routines. - osStatusReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization. -} osStatus_t; - - -/// \details Thread ID identifies the thread. -typedef void *osThreadId_t; - -/// \details Timer ID identifies the timer. -typedef void *osTimerId_t; - -/// \details Event Flags ID identifies the event flags. -typedef void *osEventFlagsId_t; - -/// \details Mutex ID identifies the mutex. -typedef void *osMutexId_t; - -/// \details Semaphore ID identifies the semaphore. -typedef void *osSemaphoreId_t; - -/// \details Memory Pool ID identifies the memory pool. -typedef void *osMemoryPoolId_t; - -/// \details Message Queue ID identifies the message queue. -typedef void *osMessageQueueId_t; - - -#ifndef TZ_MODULEID_T -#define TZ_MODULEID_T -/// \details Data type that identifies secure software modules called by a process. -typedef uint32_t TZ_ModuleId_t; -#endif - - -/// Attributes structure for thread. -typedef struct { - const char *name; ///< name of the thread - uint32_t attr_bits; ///< attribute bits - void *cb_mem; ///< memory for control block - uint32_t cb_size; ///< size of provided memory for control block - void *stack_mem; ///< memory for stack - uint32_t stack_size; ///< size of stack - osPriority_t priority; ///< initial thread priority (default: osPriorityNormal) - TZ_ModuleId_t tz_module; ///< TrustZone module identifier - uint32_t reserved; ///< reserved (must be 0) -} osThreadAttr_t; - -/// Attributes structure for timer. -typedef struct { - const char *name; ///< name of the timer - uint32_t attr_bits; ///< attribute bits - void *cb_mem; ///< memory for control block - uint32_t cb_size; ///< size of provided memory for control block -} osTimerAttr_t; - -/// Attributes structure for event flags. -typedef struct { - const char *name; ///< name of the event flags - uint32_t attr_bits; ///< attribute bits - void *cb_mem; ///< memory for control block - uint32_t cb_size; ///< size of provided memory for control block -} osEventFlagsAttr_t; - -/// Attributes structure for mutex. -typedef struct { - const char *name; ///< name of the mutex - uint32_t attr_bits; ///< attribute bits - void *cb_mem; ///< memory for control block - uint32_t cb_size; ///< size of provided memory for control block -} osMutexAttr_t; - -/// Attributes structure for semaphore. -typedef struct { - const char *name; ///< name of the semaphore - uint32_t attr_bits; ///< attribute bits - void *cb_mem; ///< memory for control block - uint32_t cb_size; ///< size of provided memory for control block -} osSemaphoreAttr_t; - -/// Attributes structure for memory pool. -typedef struct { - const char *name; ///< name of the memory pool - uint32_t attr_bits; ///< attribute bits - void *cb_mem; ///< memory for control block - uint32_t cb_size; ///< size of provided memory for control block - void *mp_mem; ///< memory for data storage - uint32_t mp_size; ///< size of provided memory for data storage -} osMemoryPoolAttr_t; - -/// Attributes structure for message queue. -typedef struct { - const char *name; ///< name of the message queue - uint32_t attr_bits; ///< attribute bits - void *cb_mem; ///< memory for control block - uint32_t cb_size; ///< size of provided memory for control block - void *mq_mem; ///< memory for data storage - uint32_t mq_size; ///< size of provided memory for data storage -} osMessageQueueAttr_t; - - -// ==== Kernel Management Functions ==== - -/// Initialize the RTOS Kernel. -/// \return status code that indicates the execution status of the function. -osStatus_t osKernelInitialize (void); - -/// Get RTOS Kernel Information. -/// \param[out] version pointer to buffer for retrieving version information. -/// \param[out] id_buf pointer to buffer for retrieving kernel identification string. -/// \param[in] id_size size of buffer for kernel identification string. -/// \return status code that indicates the execution status of the function. -osStatus_t osKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size); - -/// Get the current RTOS Kernel state. -/// \return current RTOS Kernel state. -osKernelState_t osKernelGetState (void); - -/// Start the RTOS Kernel scheduler. -/// \return status code that indicates the execution status of the function. -osStatus_t osKernelStart (void); - -/// Lock the RTOS Kernel scheduler. -/// \return previous lock state (1 - locked, 0 - not locked, error code if negative). -int32_t osKernelLock (void); - -/// Unlock the RTOS Kernel scheduler. -/// \return previous lock state (1 - locked, 0 - not locked, error code if negative). -int32_t osKernelUnlock (void); - -/// Restore the RTOS Kernel scheduler lock state. -/// \param[in] lock lock state obtained by \ref osKernelLock or \ref osKernelUnlock. -/// \return new lock state (1 - locked, 0 - not locked, error code if negative). -int32_t osKernelRestoreLock (int32_t lock); - -/// Suspend the RTOS Kernel scheduler. -/// \return time in ticks, for how long the system can sleep or power-down. -uint32_t osKernelSuspend (void); - -/// Resume the RTOS Kernel scheduler. -/// \param[in] sleep_ticks time in ticks for how long the system was in sleep or power-down mode. -void osKernelResume (uint32_t sleep_ticks); - -/// Get the RTOS kernel tick count. -/// \return RTOS kernel current tick count. -uint64_t osKernelGetTickCount (void); - -/// Get the RTOS kernel tick frequency. -/// \return frequency of the kernel tick. -uint32_t osKernelGetTickFreq (void); - -/// Get the RTOS kernel system timer count. -/// \return RTOS kernel current system timer count as 32-bit value. -uint32_t osKernelGetSysTimerCount (void); - -/// Get the RTOS kernel system timer frequency. -/// \return frequency of the system timer. -uint32_t osKernelGetSysTimerFreq (void); - - -// ==== Thread Management Functions ==== - -/// Create a thread and add it to Active Threads. -/// \param[in] func thread function. -/// \param[in] argument pointer that is passed to the thread function as start argument. -/// \param[in] attr thread attributes; NULL: default values. -/// \return thread ID for reference by other functions or NULL in case of error. -osThreadId_t osThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr); -osThreadId_t osThreadContextNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr, void *context); - -/// Get name of a thread. -/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -/// \return name as NULL terminated string. -const char *osThreadGetName (osThreadId_t thread_id); - -/// Return the thread ID of the current running thread. -/// \return thread ID for reference by other functions or NULL in case of error. -osThreadId_t osThreadGetId (void); - -/// Get current thread state of a thread. -/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -/// \return current thread state of the specified thread. -osThreadState_t osThreadGetState (osThreadId_t thread_id); - -/// Get stack size of a thread. -/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -/// \return stack size in bytes. -uint32_t osThreadGetStackSize (osThreadId_t thread_id); - -/// Get available stack space of a thread based on stack watermark recording during execution. -/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -/// \return remaining stack space in bytes. -uint32_t osThreadGetStackSpace (osThreadId_t thread_id); - -/// Change priority of a thread. -/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -/// \param[in] priority new priority value for the thread function. -/// \return status code that indicates the execution status of the function. -osStatus_t osThreadSetPriority (osThreadId_t thread_id, osPriority_t priority); - -/// Get current priority of a thread. -/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -/// \return current priority value of the specified thread. -osPriority_t osThreadGetPriority (osThreadId_t thread_id); - -/// Pass control to next thread that is in state \b READY. -/// \return status code that indicates the execution status of the function. -osStatus_t osThreadYield (void); - -/// Suspend execution of a thread. -/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -/// \return status code that indicates the execution status of the function. -osStatus_t osThreadSuspend (osThreadId_t thread_id); - -/// Resume execution of a thread. -/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -/// \return status code that indicates the execution status of the function. -osStatus_t osThreadResume (osThreadId_t thread_id); - -/// Detach a thread (thread storage can be reclaimed when thread terminates). -/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -/// \return status code that indicates the execution status of the function. -osStatus_t osThreadDetach (osThreadId_t thread_id); - -/// Wait for specified thread to terminate. -/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -/// \return status code that indicates the execution status of the function. -osStatus_t osThreadJoin (osThreadId_t thread_id); - -/// Terminate execution of current running thread. -__NO_RETURN void osThreadExit (void); - -/// Terminate execution of a thread. -/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -/// \return status code that indicates the execution status of the function. -osStatus_t osThreadTerminate (osThreadId_t thread_id); - -/// Get number of active threads. -/// \return number of active threads. -uint32_t osThreadGetCount (void); - -/// Enumerate active threads. -/// \param[out] thread_array pointer to array for retrieving thread IDs. -/// \param[in] array_items maximum number of items in array for retrieving thread IDs. -/// \return number of enumerated threads. -uint32_t osThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items); - - -// ==== Thread Flags Functions ==== - -/// Set the specified Thread Flags of a thread. -/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -/// \param[in] flags specifies the flags of the thread that shall be set. -/// \return thread flags after setting or error code if highest bit set. -uint32_t osThreadFlagsSet (osThreadId_t thread_id, uint32_t flags); - -/// Clear the specified Thread Flags of current running thread. -/// \param[in] flags specifies the flags of the thread that shall be cleared. -/// \return thread flags before clearing or error code if highest bit set. -uint32_t osThreadFlagsClear (uint32_t flags); - -/// Get the current Thread Flags of current running thread. -/// \return current thread flags. -uint32_t osThreadFlagsGet (void); - -/// Wait for one or more Thread Flags of the current running thread to become signaled. -/// \param[in] flags specifies the flags to wait for. -/// \param[in] options specifies flags options (osFlagsXxxx). -/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -/// \return thread flags before clearing or error code if highest bit set. -uint32_t osThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout); - - -// ==== Generic Wait Functions ==== - -/// Wait for Timeout (Time Delay). -/// \param[in] ticks \ref CMSIS_RTOS_TimeOutValue "time ticks" value -/// \return status code that indicates the execution status of the function. -osStatus_t osDelay (uint32_t ticks); - -/// Wait until specified time. -/// \param[in] ticks absolute time in ticks -/// \return status code that indicates the execution status of the function. -osStatus_t osDelayUntil (uint64_t ticks); - - -// ==== Timer Management Functions ==== - -/// Create and Initialize a timer. -/// \param[in] func start address of a timer call back function. -/// \param[in] type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior. -/// \param[in] argument argument to the timer call back function. -/// \param[in] attr timer attributes; NULL: default values. -/// \return timer ID for reference by other functions or NULL in case of error. -osTimerId_t osTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr); - -/// Get name of a timer. -/// \param[in] timer_id timer ID obtained by \ref osTimerNew. -/// \return name as NULL terminated string. -const char *osTimerGetName (osTimerId_t timer_id); - -/// Start or restart a timer. -/// \param[in] timer_id timer ID obtained by \ref osTimerNew. -/// \param[in] ticks \ref CMSIS_RTOS_TimeOutValue "time ticks" value of the timer. -/// \return status code that indicates the execution status of the function. -osStatus_t osTimerStart (osTimerId_t timer_id, uint32_t ticks); - -/// Stop a timer. -/// \param[in] timer_id timer ID obtained by \ref osTimerNew. -/// \return status code that indicates the execution status of the function. -osStatus_t osTimerStop (osTimerId_t timer_id); - -/// Check if a timer is running. -/// \param[in] timer_id timer ID obtained by \ref osTimerNew. -/// \return 0 not running, 1 running. -uint32_t osTimerIsRunning (osTimerId_t timer_id); - -/// Delete a timer. -/// \param[in] timer_id timer ID obtained by \ref osTimerNew. -/// \return status code that indicates the execution status of the function. -osStatus_t osTimerDelete (osTimerId_t timer_id); - - -// ==== Event Flags Management Functions ==== - -/// Create and Initialize an Event Flags object. -/// \param[in] attr event flags attributes; NULL: default values. -/// \return event flags ID for reference by other functions or NULL in case of error. -osEventFlagsId_t osEventFlagsNew (const osEventFlagsAttr_t *attr); - -/// Get name of an Event Flags object. -/// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. -/// \return name as NULL terminated string. -const char *osEventFlagsGetName (osEventFlagsId_t ef_id); - -/// Set the specified Event Flags. -/// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. -/// \param[in] flags specifies the flags that shall be set. -/// \return event flags after setting or error code if highest bit set. -uint32_t osEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags); - -/// Clear the specified Event Flags. -/// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. -/// \param[in] flags specifies the flags that shall be cleared. -/// \return event flags before clearing or error code if highest bit set. -uint32_t osEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags); - -/// Get the current Event Flags. -/// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. -/// \return current event flags. -uint32_t osEventFlagsGet (osEventFlagsId_t ef_id); - -/// Wait for one or more Event Flags to become signaled. -/// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. -/// \param[in] flags specifies the flags to wait for. -/// \param[in] options specifies flags options (osFlagsXxxx). -/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -/// \return event flags before clearing or error code if highest bit set. -uint32_t osEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout); - -/// Delete an Event Flags object. -/// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. -/// \return status code that indicates the execution status of the function. -osStatus_t osEventFlagsDelete (osEventFlagsId_t ef_id); - - -// ==== Mutex Management Functions ==== - -/// Create and Initialize a Mutex object. -/// \param[in] attr mutex attributes; NULL: default values. -/// \return mutex ID for reference by other functions or NULL in case of error. -osMutexId_t osMutexNew (const osMutexAttr_t *attr); - -/// Get name of a Mutex object. -/// \param[in] mutex_id mutex ID obtained by \ref osMutexNew. -/// \return name as NULL terminated string. -const char *osMutexGetName (osMutexId_t mutex_id); - -/// Acquire a Mutex or timeout if it is locked. -/// \param[in] mutex_id mutex ID obtained by \ref osMutexNew. -/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -/// \return status code that indicates the execution status of the function. -osStatus_t osMutexAcquire (osMutexId_t mutex_id, uint32_t timeout); - -/// Release a Mutex that was acquired by \ref osMutexAcquire. -/// \param[in] mutex_id mutex ID obtained by \ref osMutexNew. -/// \return status code that indicates the execution status of the function. -osStatus_t osMutexRelease (osMutexId_t mutex_id); - -/// Get Thread which owns a Mutex object. -/// \param[in] mutex_id mutex ID obtained by \ref osMutexNew. -/// \return thread ID of owner thread or NULL when mutex was not acquired. -osThreadId_t osMutexGetOwner (osMutexId_t mutex_id); - -/// Delete a Mutex object. -/// \param[in] mutex_id mutex ID obtained by \ref osMutexNew. -/// \return status code that indicates the execution status of the function. -osStatus_t osMutexDelete (osMutexId_t mutex_id); - - -// ==== Semaphore Management Functions ==== - -/// Create and Initialize a Semaphore object. -/// \param[in] max_count maximum number of available tokens. -/// \param[in] initial_count initial number of available tokens. -/// \param[in] attr semaphore attributes; NULL: default values. -/// \return semaphore ID for reference by other functions or NULL in case of error. -osSemaphoreId_t osSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr); - -/// Get name of a Semaphore object. -/// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. -/// \return name as NULL terminated string. -const char *osSemaphoreGetName (osSemaphoreId_t semaphore_id); - -/// Acquire a Semaphore token or timeout if no tokens are available. -/// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. -/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -/// \return status code that indicates the execution status of the function. -osStatus_t osSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout); - -/// Release a Semaphore token that was acquired by \ref osSemaphoreAcquire. -/// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. -/// \return status code that indicates the execution status of the function. -osStatus_t osSemaphoreRelease (osSemaphoreId_t semaphore_id); - -/// Get current Semaphore token count. -/// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. -/// \return number of tokens available. -uint32_t osSemaphoreGetCount (osSemaphoreId_t semaphore_id); - -/// Delete a Semaphore object. -/// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. -/// \return status code that indicates the execution status of the function. -osStatus_t osSemaphoreDelete (osSemaphoreId_t semaphore_id); - - -// ==== Memory Pool Management Functions ==== - -/// Create and Initialize a Memory Pool object. -/// \param[in] block_count maximum number of memory blocks in memory pool. -/// \param[in] block_size memory block size in bytes. -/// \param[in] attr memory pool attributes; NULL: default values. -/// \return memory pool ID for reference by other functions or NULL in case of error. -osMemoryPoolId_t osMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr); - -/// Get name of a Memory Pool object. -/// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. -/// \return name as NULL terminated string. -const char *osMemoryPoolGetName (osMemoryPoolId_t mp_id); - -/// Allocate a memory block from a Memory Pool. -/// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. -/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -/// \return address of the allocated memory block or NULL in case of no memory is available. -void *osMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout); - -/// Return an allocated memory block back to a Memory Pool. -/// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. -/// \param[in] block address of the allocated memory block to be returned to the memory pool. -/// \return status code that indicates the execution status of the function. -osStatus_t osMemoryPoolFree (osMemoryPoolId_t mp_id, void *block); - -/// Get maximum number of memory blocks in a Memory Pool. -/// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. -/// \return maximum number of memory blocks. -uint32_t osMemoryPoolGetCapacity (osMemoryPoolId_t mp_id); - -/// Get memory block size in a Memory Pool. -/// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. -/// \return memory block size in bytes. -uint32_t osMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id); - -/// Get number of memory blocks used in a Memory Pool. -/// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. -/// \return number of memory blocks used. -uint32_t osMemoryPoolGetCount (osMemoryPoolId_t mp_id); - -/// Get number of memory blocks available in a Memory Pool. -/// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. -/// \return number of memory blocks available. -uint32_t osMemoryPoolGetSpace (osMemoryPoolId_t mp_id); - -/// Delete a Memory Pool object. -/// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. -/// \return status code that indicates the execution status of the function. -osStatus_t osMemoryPoolDelete (osMemoryPoolId_t mp_id); - - -// ==== Message Queue Management Functions ==== - -/// Create and Initialize a Message Queue object. -/// \param[in] msg_count maximum number of messages in queue. -/// \param[in] msg_size maximum message size in bytes. -/// \param[in] attr message queue attributes; NULL: default values. -/// \return message queue ID for reference by other functions or NULL in case of error. -osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr); - -/// Get name of a Message Queue object. -/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. -/// \return name as NULL terminated string. -const char *osMessageQueueGetName (osMessageQueueId_t mq_id); - -/// Put a Message into a Queue or timeout if Queue is full. -/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. -/// \param[in] msg_ptr pointer to buffer with message to put into a queue. -/// \param[in] msg_prio message priority. -/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -/// \return status code that indicates the execution status of the function. -osStatus_t osMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout); - -/// Get a Message from a Queue or timeout if Queue is empty. -/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. -/// \param[out] msg_ptr pointer to buffer for message to get from a queue. -/// \param[out] msg_prio pointer to buffer for message priority or NULL. -/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -/// \return status code that indicates the execution status of the function. -osStatus_t osMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout); - -/// Get maximum number of messages in a Message Queue. -/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. -/// \return maximum number of messages. -uint32_t osMessageQueueGetCapacity (osMessageQueueId_t mq_id); - -/// Get maximum message size in a Memory Pool. -/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. -/// \return maximum message size in bytes. -uint32_t osMessageQueueGetMsgSize (osMessageQueueId_t mq_id); - -/// Get number of queued messages in a Message Queue. -/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. -/// \return number of queued messages. -uint32_t osMessageQueueGetCount (osMessageQueueId_t mq_id); - -/// Get number of available slots for messages in a Message Queue. -/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. -/// \return number of available slots for messages. -uint32_t osMessageQueueGetSpace (osMessageQueueId_t mq_id); - -/// Reset a Message Queue to initial empty state. -/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. -/// \return status code that indicates the execution status of the function. -osStatus_t osMessageQueueReset (osMessageQueueId_t mq_id); - -/// Delete a Message Queue object. -/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. -/// \return status code that indicates the execution status of the function. -osStatus_t osMessageQueueDelete (osMessageQueueId_t mq_id); - - -#ifdef __cplusplus -} -#endif - -#endif // CMSIS_OS2_H_ - -/** @}*/ diff --git a/rtos/rtx5/TARGET_CORTEX_M/core_cm.h b/rtos/rtx5/TARGET_CORTEX_M/core_cm.h deleted file mode 100644 index 1590bd6..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/core_cm.h +++ /dev/null @@ -1,1534 +0,0 @@ -/** \addtogroup rtos */ -/** @{*/ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ----------------------------------------------------------------------------- - * - * Project: CMSIS-RTOS RTX - * Title: Cortex-M Core definitions - * - * ----------------------------------------------------------------------------- - */ - -#ifndef CORE_CM_H_ -#define CORE_CM_H_ - -#include -#include "cmsis.h" -#include "cmsis_compiler.h" -#include "arm_math.h" - -#ifndef __ARM_ARCH_6M__ -#define __ARM_ARCH_6M__ 0U -#endif -#ifndef __ARM_ARCH_7M__ -#define __ARM_ARCH_7M__ 0U -#endif -#ifndef __ARM_ARCH_7EM__ -#define __ARM_ARCH_7EM__ 0U -#endif -#ifndef __ARM_ARCH_8M_BASE__ -#define __ARM_ARCH_8M_BASE__ 0U -#endif -#ifndef __ARM_ARCH_8M_MAIN__ -#define __ARM_ARCH_8M_MAIN__ 0U -#endif - -#if ((__ARM_ARCH_6M__ + \ - __ARM_ARCH_7M__ + \ - __ARM_ARCH_7EM__ + \ - __ARM_ARCH_8M_BASE__ + \ - __ARM_ARCH_8M_MAIN__) != 1U) -#error "Unknown ARM Architecture!" -#endif - -#ifdef RTE_CMSIS_RTOS2_RTX5_ARMV8M_NS -#define __DOMAIN_NS 1U -#endif - -#ifndef __DOMAIN_NS -#define __DOMAIN_NS 0U -#elif ((__DOMAIN_NS == 1U) && \ - ((__ARM_ARCH_6M__ == 1U) || \ - (__ARM_ARCH_7M__ == 1U) || \ - (__ARM_ARCH_7EM__ == 1U))) -#error "Non-secure domain requires ARMv8-M Architecture!" -#endif - -#ifndef __EXCLUSIVE_ACCESS -#if ((__ARM_ARCH_7M__ == 1U) || \ - (__ARM_ARCH_7EM__ == 1U) || \ - (__ARM_ARCH_8M_BASE__ == 1U) || \ - (__ARM_ARCH_8M_MAIN__ == 1U)) -#define __EXCLUSIVE_ACCESS 1U -#else -#define __EXCLUSIVE_ACCESS 0U -#endif -#endif - - -#define IS_PRIVILEGED() ((__get_CONTROL() & 1U) == 0U) - -#define IS_IRQ_MODE() (__get_IPSR() != 0U) - -#if ((__ARM_ARCH_7M__ == 1U) || \ - (__ARM_ARCH_7EM__ == 1U) || \ - (__ARM_ARCH_8M_MAIN__ == 1U)) -#define IS_IRQ_MASKED() ((__get_PRIMASK() != 0U) || (__get_BASEPRI() != 0U)) -#else -#define IS_IRQ_MASKED() (__get_PRIMASK() != 0U) -#endif - -#define XPSR_INITIAL_VALUE 0x01000000U - -#if (__DOMAIN_NS == 1U) -#define STACK_FRAME_INIT 0xBCU -#else -#define STACK_FRAME_INIT 0xFDU -#endif - -#define IS_EXTENDED_STACK_FRAME(n) (((n) & 0x10U) == 0U) - - -// ==== Service Calls definitions ==== - -#if defined(__CC_ARM) - -#if ((__ARM_ARCH_7M__ == 1U) || \ - (__ARM_ARCH_7EM__ == 1U) || \ - (__ARM_ARCH_8M_MAIN__ == 1U)) -#define __SVC_INDIRECT(n) __svc_indirect(n) -#elif ((__ARM_ARCH_6M__ == 1U) || \ - (__ARM_ARCH_8M_BASE__ == 1U)) -#define __SVC_INDIRECT(n) __svc_indirect_r7(n) -#endif - -#if (__FPU_USED == 1U) -#define SVC_SETUP_PSP \ - uint32_t control = __get_CONTROL(); \ - if ((control & 2U) == 0U) { \ - __set_PSP((__get_MSP() - ((control & 4U) ? 104U : 32U)) & ~7U); \ - } -#else -#define SVC_SETUP_PSP \ - uint32_t control = __get_CONTROL(); \ - if ((control & 2U) == 0U) { \ - __set_PSP((__get_MSP() - 32U) & ~7U); \ - } -#endif - -#define SVC0_0N(f,t) \ -__SVC_INDIRECT(0) t svc##f (t(*)()); \ - t svcRtx##f (void); \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (void) { \ - svc##f(svcRtx##f); \ -} - -#define SVC0_0(f,t) \ -__SVC_INDIRECT(0) t svc##f (t(*)()); \ - t svcRtx##f (void); \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (void) { \ - return svc##f(svcRtx##f); \ -} - -#define SVC0_0M(f,t) \ -__SVC_INDIRECT(0) t svc##f (t(*)()); \ - t svcRtx##f (void); \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (void) { \ - SVC_SETUP_PSP \ - return svc##f(svcRtx##f); \ -} - -#define SVC0_0D SVC0_0 - -#define SVC0_1N(f,t,t1) \ -__SVC_INDIRECT(0) t svc##f (t(*)(t1),t1); \ - t svcRtx##f (t1 a1); \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1) { \ - svc##f(svcRtx##f,a1); \ -} - -#define SVC0_1(f,t,t1) \ -__SVC_INDIRECT(0) t svc##f (t(*)(t1),t1); \ - t svcRtx##f (t1 a1); \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1) { \ - return svc##f(svcRtx##f,a1); \ -} - -#define SVC0_1M(f,t,t1) \ -__SVC_INDIRECT(0) t svc##f (t(*)(t1),t1); \ - t svcRtx##f (t1 a1); \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1) { \ - SVC_SETUP_PSP \ - return svc##f(svcRtx##f,a1); \ -} - -#define SVC0_2(f,t,t1,t2) \ -__SVC_INDIRECT(0) t svc##f (t(*)(t1,t2),t1,t2); \ - t svcRtx##f (t1 a1, t2 a2); \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1, t2 a2) { \ - return svc##f(svcRtx##f,a1,a2); \ -} - -#define SVC0_2M(f,t,t1,t2) \ -__SVC_INDIRECT(0) t svc##f (t(*)(t1,t2),t1,t2); \ - t svcRtx##f (t1 a1, t2 a2); \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1, t2 a2) { \ - SVC_SETUP_PSP \ - return svc##f(svcRtx##f,a1,a2); \ -} - -#define SVC0_3(f,t,t1,t2,t3) \ -__SVC_INDIRECT(0) t svc##f (t(*)(t1,t2,t3),t1,t2,t3); \ - t svcRtx##f (t1 a1, t2 a2, t3 a3); \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1, t2 a2, t3 a3) { \ - return svc##f(svcRtx##f,a1,a2,a3); \ -} - -#define SVC0_3M(f,t,t1,t2,t3) \ -__SVC_INDIRECT(0) t svc##f (t(*)(t1,t2,t3),t1,t2,t3); \ - t svcRtx##f (t1 a1, t2 a2, t3 a3); \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1, t2 a2, t3 a3) { \ - SVC_SETUP_PSP \ - return svc##f(svcRtx##f,a1,a2,a3); \ -} - -#define SVC0_4(f,t,t1,t2,t3,t4) \ -__SVC_INDIRECT(0) t svc##f (t(*)(t1,t2,t3,t4),t1,t2,t3,t4); \ - t svcRtx##f (t1 a1, t2 a2, t3 a3, t4 a4); \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1, t2 a2, t3 a3, t4 a4) { \ - return svc##f(svcRtx##f,a1,a2,a3,a4); \ -} - -#define SVC0_4M(f,t,t1,t2,t3,t4) \ -__SVC_INDIRECT(0) t svc##f (t(*)(t1,t2,t3,t4),t1,t2,t3,t4); \ - t svcRtx##f (t1 a1, t2 a2, t3 a3, t4 a4); \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1, t2 a2, t3 a3, t4 a4) { \ - SVC_SETUP_PSP \ - return svc##f(svcRtx##f,a1,a2,a3,a4); \ -} - -#elif defined(__ICCARM__) - -#if ((__ARM_ARCH_7M__ == 1U) || \ - (__ARM_ARCH_7EM__ == 1U) || \ - (__ARM_ARCH_8M_MAIN__ == 1U)) -#define SVC_Setup(f) \ - __asm( \ - "mov r12,%0\n" \ - :: "r"(&f): "r12" \ - ); -#elif ((__ARM_ARCH_6M__ == 1U) || \ - (__ARM_ARCH_8M_BASE__ == 1U)) -#define SVC_Setup(f) \ - __asm( \ - "mov r7,%0\n" \ - :: "r"(&f): "r7" \ - ); -#endif - -#define STRINGIFY(a) #a -#define __SVC_INDIRECT(n) _Pragma(STRINGIFY(swi_number = n)) __swi - -#if (__FPU_USED == 1U) -#define SVC_SETUP_PSP \ - uint32_t control = __get_CONTROL(); \ - if ((control & 2U) == 0U) { \ - __set_PSP((__get_MSP() - ((control & 4U) ? 104U : 32U)) & ~7U); \ - } -#else -#define SVC_SETUP_PSP \ - uint32_t control = __get_CONTROL(); \ - if ((control & 2U) == 0U) { \ - __set_PSP((__get_MSP() - 32U) & ~7U); \ - } -#endif - -#define SVC0_0N(f,t) \ -__SVC_INDIRECT(0) t svc##f (); \ - t svcRtx##f (void); \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (void) { \ - SVC_Setup(svcRtx##f); \ - svc##f(); \ -} - -#define SVC0_0(f,t) \ -__SVC_INDIRECT(0) t svc##f (); \ - t svcRtx##f (void); \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (void) { \ - SVC_Setup(svcRtx##f); \ - return svc##f(); \ -} - -#define SVC0_0M(f,t) \ -__SVC_INDIRECT(0) t svc##f (); \ - t svcRtx##f (void); \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (void) { \ - SVC_SETUP_PSP \ - SVC_Setup(svcRtx##f); \ - return svc##f(); \ -} - -#define SVC0_0D SVC0_0 - -#define SVC0_1N(f,t,t1) \ -__SVC_INDIRECT(0) t svc##f (t1 a1); \ - t svcRtx##f (t1 a1); \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1) { \ - SVC_Setup(svcRtx##f); \ - svc##f(a1); \ -} - -#define SVC0_1(f,t,t1) \ -__SVC_INDIRECT(0) t svc##f (t1 a1); \ - t svcRtx##f (t1 a1); \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1) { \ - SVC_Setup(svcRtx##f); \ - return svc##f(a1); \ -} - -#define SVC0_1M(f,t,t1) \ -__SVC_INDIRECT(0) t svc##f (t1 a1); \ - t svcRtx##f (t1 a1); \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1) { \ - SVC_SETUP_PSP \ - SVC_Setup(svcRtx##f); \ - return svc##f(a1); \ -} - -#define SVC0_2(f,t,t1,t2) \ -__SVC_INDIRECT(0) t svc##f (t1 a1, t2 a2); \ - t svcRtx##f (t1 a1, t2 a2); \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1, t2 a2) { \ - SVC_Setup(svcRtx##f); \ - return svc##f(a1,a2); \ -} - -#define SVC0_2M(f,t,t1,t2) \ -__SVC_INDIRECT(0) t svc##f (t1 a1, t2 a2); \ - t svcRtx##f (t1 a1, t2 a2); \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1, t2 a2) { \ - SVC_SETUP_PSP \ - SVC_Setup(svcRtx##f); \ - return svc##f(a1,a2); \ -} - -#define SVC0_3(f,t,t1,t2,t3) \ -__SVC_INDIRECT(0) t svc##f (t1 a1, t2 a2, t3 a3); \ - t svcRtx##f (t1 a1, t2 a2, t3 a3); \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1, t2 a2, t3 a3) { \ - SVC_Setup(svcRtx##f); \ - return svc##f(a1,a2,a3); \ -} - -#define SVC0_3M(f,t,t1,t2,t3) \ -__SVC_INDIRECT(0) t svc##f (t1 a1, t2 a2, t3 a3); \ - t svcRtx##f (t1 a1, t2 a2, t3 a3); \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1, t2 a2, t3 a3) { \ - SVC_SETUP_PSP \ - SVC_Setup(svcRtx##f); \ - return svc##f(a1,a2,a3); \ -} - -#define SVC0_4(f,t,t1,t2,t3,t4) \ -__SVC_INDIRECT(0) t svc##f (t1 a1, t2 a2, t3 a3, t4 a4); \ - t svcRtx##f (t1 a1, t2 a2, t3 a3, t4 a4); \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1, t2 a2, t3 a3, t4 a4) { \ - SVC_Setup(svcRtx##f); \ - return svc##f(a1,a2,a3,a4); \ -} - -#define SVC0_4M(f,t,t1,t2,t3,t4) \ -__SVC_INDIRECT(0) t svc##f (t1 a1, t2 a2, t3 a3, t4 a4); \ - t svcRtx##f (t1 a1, t2 a2, t3 a3, t4 a4); \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1, t2 a2, t3 a3, t4 a4) { \ - SVC_SETUP_PSP \ - SVC_Setup(svcRtx##f); \ - return svc##f(a1,a2,a3,a4); \ -} - -#else // !(defined(__CC_ARM) || defined(__ICCARM__)) - -#if ((__ARM_ARCH_7M__ == 1U) || \ - (__ARM_ARCH_7EM__ == 1U) || \ - (__ARM_ARCH_8M_MAIN__ == 1U)) -#define SVC_RegF "r12" -#elif ((__ARM_ARCH_6M__ == 1U) || \ - (__ARM_ARCH_8M_BASE__ == 1U)) -#define SVC_RegF "r7" -#endif - -#define SVC_ArgN(n) \ -register uint32_t __r##n __ASM("r"#n) - -#define SVC_ArgR(n,a) \ -register uint32_t __r##n __ASM("r"#n) = (uint32_t)a - -#define SVC_ArgF(f) \ -register uint32_t __rf __ASM(SVC_RegF) = (uint32_t)f - -#define SVC_In0 "r"(__rf) -#define SVC_In1 "r"(__rf),"r"(__r0) -#define SVC_In2 "r"(__rf),"r"(__r0),"r"(__r1) -#define SVC_In3 "r"(__rf),"r"(__r0),"r"(__r1),"r"(__r2) -#define SVC_In4 "r"(__rf),"r"(__r0),"r"(__r1),"r"(__r2),"r"(__r3) - -#define SVC_Out0 -#define SVC_Out1 "=r"(__r0) -#define SVC_Out2 "=r"(__r0),"=r"(__r1) - -#define SVC_CL0 -#define SVC_CL1 "r1" -#define SVC_CL2 "r0","r1" - -#define SVC_Call0(in, out, cl) \ - __ASM volatile ("svc 0" : out : in : cl) - -#if ((__ARM_ARCH_7M__ == 1U) || \ - (__ARM_ARCH_7EM__ == 1U) || \ - (__ARM_ARCH_8M_MAIN__ == 1U)) -#if (__FPU_USED == 1U) -#define SVC_Call0M(in, out, cl) \ - register uint32_t val; \ - __ASM volatile ( \ - ".syntax unified\n\t" \ - "mrs %[val],control\n\t" \ - "tst %[val],#2\n\t" \ - "bne 0f\n\t" \ - "tst %[val],#4\n\t" \ - "mrs %[val],msp\n\t" \ - "ite eq\n\t" \ - "subeq %[val],#32\n\t" \ - "subne %[val],#104\n\t" \ - "bic %[val],#7\n\t" \ - "msr psp,%[val]\n\t" \ - "0:\n\t" \ - "svc 0" \ - : out, [val] "=&l" (val) : in : cl) -#else -#define SVC_Call0M(in, out, cl) \ - register uint32_t val; \ - __ASM volatile ( \ - ".syntax unified\n\t" \ - "mrs %[val],control\n\t" \ - "tst %[val],#2\n\t" \ - "bne 0f\n\t" \ - "mrs %[val],msp\n\t" \ - "subs %[val],#32\n\t" \ - "bic %[val],#7\n\t" \ - "msr psp,%[val]\n\t" \ - "0:\n\t" \ - "svc 0" \ - : out, [val] "=&l" (val) : in : cl) -#endif -#elif ((__ARM_ARCH_6M__ == 1U) || \ - (__ARM_ARCH_8M_BASE__ == 1U)) -#define SVC_Call0M(in, out, cl) \ - register uint32_t val; \ - __ASM volatile ( \ - ".syntax unified\n\t" \ - "mrs %[val],control\n\t" \ - "lsls %[val],#30\n\t" \ - "bmi 0f\n\t" \ - "mrs %[val],msp\n\t" \ - "subs %[val],#32\n\t" \ - "lsrs %[val],#3\n\t" \ - "lsls %[val],#3\n\t" \ - "msr psp,%[val]\n\t" \ - "0:\n\t" \ - "svc 0" \ - : out, [val] "=&l" (val) : in : cl) -#endif - -#define SVC0_0N(f,t) \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (void) { \ - SVC_ArgF(svcRtx##f); \ - SVC_Call0(SVC_In0, SVC_Out0, SVC_CL2); \ -} - -#define SVC0_0(f,t) \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (void) { \ - SVC_ArgN(0); \ - SVC_ArgF(svcRtx##f); \ - SVC_Call0(SVC_In0, SVC_Out1, SVC_CL1); \ - return (t) __r0; \ -} - -#define SVC0_0M(f,t) \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (void) { \ - SVC_ArgN(0); \ - SVC_ArgF(svcRtx##f); \ - SVC_Call0M(SVC_In0, SVC_Out1, SVC_CL1); \ - return (t) __r0; \ -} - -#define SVC0_0D(f,t) \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (void) { \ - SVC_ArgN(0); \ - SVC_ArgN(1); \ - SVC_ArgF(svcRtx##f); \ - SVC_Call0(SVC_In0, SVC_Out2, SVC_CL0); \ - return (((t) __r0) | (((t) __r1) << 32)); \ -} - -#define SVC0_1N(f,t,t1) \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1) { \ - SVC_ArgR(0,a1); \ - SVC_ArgF(svcRtx##f); \ - SVC_Call0(SVC_In1, SVC_Out0, SVC_CL1); \ -} - -#define SVC0_1(f,t,t1) \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1) { \ - SVC_ArgR(0,a1); \ - SVC_ArgF(svcRtx##f); \ - SVC_Call0(SVC_In1, SVC_Out1, SVC_CL1); \ - return (t) __r0; \ -} - -#define SVC0_1M(f,t,t1) \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1) { \ - SVC_ArgR(0,a1); \ - SVC_ArgF(svcRtx##f); \ - SVC_Call0M(SVC_In1, SVC_Out1, SVC_CL1); \ - return (t) __r0; \ -} - -#define SVC0_2(f,t,t1,t2) \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1, t2 a2) { \ - SVC_ArgR(0,a1); \ - SVC_ArgR(1,a2); \ - SVC_ArgF(svcRtx##f); \ - SVC_Call0(SVC_In2, SVC_Out1, SVC_CL0); \ - return (t) __r0; \ -} - -#define SVC0_2M(f,t,t1,t2) \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1, t2 a2) { \ - SVC_ArgR(0,a1); \ - SVC_ArgR(1,a2); \ - SVC_ArgF(svcRtx##f); \ - SVC_Call0M(SVC_In2, SVC_Out1, SVC_CL0); \ - return (t) __r0; \ -} - -#define SVC0_3(f,t,t1,t2,t3) \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1, t2 a2, t3 a3) { \ - SVC_ArgR(0,a1); \ - SVC_ArgR(1,a2); \ - SVC_ArgR(2,a3); \ - SVC_ArgF(svcRtx##f); \ - SVC_Call0(SVC_In3, SVC_Out1, SVC_CL0); \ - return (t) __r0; \ -} - -#define SVC0_3M(f,t,t1,t2,t3) \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1, t2 a2, t3 a3) { \ - SVC_ArgR(0,a1); \ - SVC_ArgR(1,a2); \ - SVC_ArgR(2,a3); \ - SVC_ArgF(svcRtx##f); \ - SVC_Call0M(SVC_In3, SVC_Out1, SVC_CL0); \ - return (t) __r0; \ -} - -#define SVC0_4(f,t,t1,t2,t3,t4) \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1, t2 a2, t3 a3, t4 a4) { \ - SVC_ArgR(0,a1); \ - SVC_ArgR(1,a2); \ - SVC_ArgR(2,a3); \ - SVC_ArgR(3,a4); \ - SVC_ArgF(svcRtx##f); \ - SVC_Call0(SVC_In4, SVC_Out1, SVC_CL0); \ - return (t) __r0; \ -} - -#define SVC0_4M(f,t,t1,t2,t3,t4) \ -__attribute__((always_inline)) \ -__STATIC_INLINE t __svc##f (t1 a1, t2 a2, t3 a3, t4 a4) { \ - SVC_ArgR(0,a1); \ - SVC_ArgR(1,a2); \ - SVC_ArgR(2,a3); \ - SVC_ArgR(3,a4); \ - SVC_ArgF(svcRtx##f); \ - SVC_Call0M(SVC_In4, SVC_Out1, SVC_CL0); \ - return (t) __r0; \ -} - -#endif - - -// ==== Core Peripherals functions ==== - -extern uint32_t SystemCoreClock; // System Clock Frequency (Core Clock) - - -/// Initialize SVC and PendSV System Service Calls -__STATIC_INLINE void SVC_Initialize (void) { -#if ((__ARM_ARCH_8M_MAIN__ == 1U) || (defined(__CORTEX_M) && (__CORTEX_M == 7U))) - uint32_t p, n; - - SCB->SHPR[10] = 0xFFU; - n = 32U - (uint32_t)__CLZ(~(SCB->SHPR[10] | 0xFFFFFF00U)); - p = NVIC_GetPriorityGrouping(); - if (p >= n) { - n = p + 1U; - } - SCB->SHPR[7] = (uint8_t)(0xFEU << n); -#elif (__ARM_ARCH_8M_BASE__ == 1U) - SCB->SHPR[1] |= 0x00FF0000U; - SCB->SHPR[0] |= (SCB->SHPR[1] << (8+1)) & 0xFC000000U; -#elif ((__ARM_ARCH_7M__ == 1U) || \ - (__ARM_ARCH_7EM__ == 1U)) - uint32_t p, n; - - SCB->SHP[10] = 0xFFU; - n = 32U - (uint32_t)__CLZ(~(SCB->SHP[10] | 0xFFFFFF00U)); - p = NVIC_GetPriorityGrouping(); - if (p >= n) { - n = p + 1U; - } - -/* Only change the SVCall priority if uVisor is not present. */ -#if !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED)) - SCB->SHP[7] = (uint8_t)(0xFEU << n); -#endif -#elif (__ARM_ARCH_6M__ == 1U) - SCB->SHP[1] |= 0x00FF0000U; - SCB->SHP[0] |= (SCB->SHP[1] << (8+1)) & 0xFC000000U; -#endif -} - -/// Setup SysTick Timer -/// \param[in] period Timer Load value -__STATIC_INLINE void SysTick_Setup (uint32_t period) { - SysTick->LOAD = period - 1U; - SysTick->VAL = 0U; -#if ((__ARM_ARCH_8M_MAIN__ == 1U) || (defined(__CORTEX_M) && (__CORTEX_M == 7U))) - SCB->SHPR[11] = 0xFFU; -#elif (__ARM_ARCH_8M_BASE__ == 1U) - SCB->SHPR[1] |= 0xFF000000U; -#elif ((__ARM_ARCH_7M__ == 1U) || \ - (__ARM_ARCH_7EM__ == 1U)) - SCB->SHP[11] = 0xFFU; -#elif (__ARM_ARCH_6M__ == 1U) - SCB->SHP[1] |= 0xFF000000U; -#endif -} - -/// Get SysTick Period -/// \return SysTick Period -__STATIC_INLINE uint32_t SysTick_GetPeriod (void) { - return (SysTick->LOAD + 1U); -} - -/// Get SysTick Value -/// \return SysTick Value -__STATIC_INLINE uint32_t SysTick_GetVal (void) { - uint32_t load = SysTick->LOAD; - return (load - SysTick->VAL); -} - -/// Get SysTick Overflow (Auto Clear) -/// \return SysTick Overflow flag -__STATIC_INLINE uint32_t SysTick_GetOvf (void) { - return ((SysTick->CTRL >> 16) & 1U); -} - -/// Enable SysTick Timer -__STATIC_INLINE void SysTick_Enable (void) { - SysTick->CTRL = SysTick_CTRL_ENABLE_Msk | - SysTick_CTRL_TICKINT_Msk | - SysTick_CTRL_CLKSOURCE_Msk; -} - -/// Disable SysTick Timer -__STATIC_INLINE void SysTick_Disable (void) { - SysTick->CTRL = 0U; -} - -/// Setup External Tick Timer Interrupt -/// \param[in] irqn Interrupt number -__STATIC_INLINE void ExtTick_SetupIRQ (int32_t irqn) { -#if (__ARM_ARCH_8M_MAIN__ == 1U) - NVIC->IPR[irqn] = 0xFFU; -#elif (__ARM_ARCH_8M_BASE__ == 1U) - NVIC->IPR[irqn >> 2] = (NVIC->IPR[irqn >> 2] & ~(0xFFU << ((irqn & 3) << 3))) | - (0xFFU << ((irqn & 3) << 3)); -#elif ((__ARM_ARCH_7M__ == 1U) || \ - (__ARM_ARCH_7EM__ == 1U)) - NVIC->IP[irqn] = 0xFFU; -#elif (__ARM_ARCH_6M__ == 1U) - NVIC->IP[irqn >> 2] = (NVIC->IP[irqn >> 2] & ~(0xFFU << ((irqn & 3) << 3))) | - (0xFFU << ((irqn & 3) << 3)); -#endif -} - -/// Enable External Tick Timer Interrupt -/// \param[in] irqn Interrupt number -__STATIC_INLINE void ExtTick_EnableIRQ (int32_t irqn) { - NVIC->ISER[irqn >> 5] = 1U << (irqn & 0x1F); -} - -/// Disable External Tick Timer Interrupt -/// \param[in] irqn Interrupt number -__STATIC_INLINE void ExtTick_DisableIRQ (int32_t irqn) { - NVIC->ICER[irqn >> 5] = 1U << (irqn & 0x1F); -} - -/// Get Pending SV (Service Call) and ST (SysTick) Flags -/// \return Pending SV&ST Flags -__STATIC_INLINE uint8_t GetPendSV_ST (void) { - return ((uint8_t)((SCB->ICSR & (SCB_ICSR_PENDSVSET_Msk | SCB_ICSR_PENDSTSET_Msk)) >> 24)); -} - -/// Get Pending SV (Service Call) Flag -/// \return Pending SV Flag -__STATIC_INLINE uint8_t GetPendSV (void) { - return ((uint8_t)((SCB->ICSR & (SCB_ICSR_PENDSVSET_Msk)) >> 24)); -} - -/// Clear Pending SV (Service Call) and ST (SysTick) Flags -__STATIC_INLINE void ClrPendSV_ST (void) { - SCB->ICSR = SCB_ICSR_PENDSVCLR_Msk | SCB_ICSR_PENDSTCLR_Msk; -} - -/// Clear Pending SV (Service Call) Flag -__STATIC_INLINE void ClrPendSV (void) { - SCB->ICSR = SCB_ICSR_PENDSVCLR_Msk; -} - -/// Set Pending SV (Service Call) Flag -__STATIC_INLINE void SetPendSV (void) { - SCB->ICSR = SCB_ICSR_PENDSVSET_Msk; -} - -/// Set Pending Flags -/// \param[in] flags Flags to set -__STATIC_INLINE void SetPendFlags (uint8_t flags) { - SCB->ICSR = ((uint32_t)flags << 24); -} - - -// ==== Exclusive Access Operation ==== - -#if (__EXCLUSIVE_ACCESS == 1U) - -/// Atomic Access Operation: Write (8-bit) -/// \param[in] mem Memory address -/// \param[in] val Value to write -/// \return Previous value -#if defined(__CC_ARM) -static __asm uint8_t atomic_wr8 (uint8_t *mem, uint8_t val) { - mov r2,r0 -1 - ldrexb r0,[r2] - strexb r3,r1,[r2] - cbz r3,%F2 - b %B1 -2 - bx lr -} -#else -__STATIC_INLINE uint8_t atomic_wr8 (uint8_t *mem, uint8_t val) { -#ifdef __ICCARM__ -#pragma diag_suppress=Pe550 -#endif - register uint32_t res; -#ifdef __ICCARM__ -#pragma diag_default=Pe550 -#endif - register uint8_t ret; - - __ASM volatile ( -#ifndef __ICCARM__ - ".syntax unified\n\t" -#endif - "1:\n\t" - "ldrexb %[ret],[%[mem]]\n\t" - "strexb %[res],%[val],[%[mem]]\n\t" - "cbz %[res],2f\n\t" - "b 1b\n" - "2:" - : [ret] "=&l" (ret), - [res] "=&l" (res) - : [mem] "l" (mem), - [val] "l" (val) - : "memory" - ); - - return ret; -} -#endif - -/// Atomic Access Operation: Set bits (32-bit) -/// \param[in] mem Memory address -/// \param[in] bits Bit mask -/// \return New value -#if defined(__CC_ARM) -static __asm uint32_t atomic_set32 (uint32_t *mem, uint32_t bits) { - mov r2,r0 -1 - ldrex r0,[r2] - orr r0,r0,r1 - strex r3,r0,[r2] - cbz r3,%F2 - b %B1 -2 - bx lr -} -#else -__STATIC_INLINE uint32_t atomic_set32 (uint32_t *mem, uint32_t bits) { -#ifdef __ICCARM__ -#pragma diag_suppress=Pe550 -#endif - register uint32_t val, res; -#ifdef __ICCARM__ -#pragma diag_default=Pe550 -#endif - register uint32_t ret; - - __ASM volatile ( -#ifndef __ICCARM__ - ".syntax unified\n\t" -#endif - "1:\n\t" - "ldrex %[val],[%[mem]]\n\t" -#if (__ARM_ARCH_8M_BASE__ == 1U) - "mov %[ret],%[val]\n\t" - "orrs %[ret],%[bits]\n\t" -#else - "orr %[ret],%[val],%[bits]\n\t" -#endif - "strex %[res],%[ret],[%[mem]]\n\t" - "cbz %[res],2f\n\t" - "b 1b\n" - "2:" - : [ret] "=&l" (ret), - [val] "=&l" (val), - [res] "=&l" (res) - : [mem] "l" (mem), - [bits] "l" (bits) -#if (__ARM_ARCH_8M_BASE__ == 1U) - : "memory", "cc" -#else - : "memory" -#endif - ); - - return ret; -} -#endif - -/// Atomic Access Operation: Clear bits (32-bit) -/// \param[in] mem Memory address -/// \param[in] bits Bit mask -/// \return Previous value -#if defined(__CC_ARM) -static __asm uint32_t atomic_clr32 (uint32_t *mem, uint32_t bits) { - push {r4,lr} - mov r2,r0 -1 - ldrex r0,[r2] - bic r4,r0,r1 - strex r3,r4,[r2] - cbz r3,%F2 - b %B1 -2 - pop {r4,pc} -} -#else -__STATIC_INLINE uint32_t atomic_clr32 (uint32_t *mem, uint32_t bits) { -#ifdef __ICCARM__ -#pragma diag_suppress=Pe550 -#endif - register uint32_t val, res; -#ifdef __ICCARM__ -#pragma diag_default=Pe550 -#endif - register uint32_t ret; - - __ASM volatile ( -#ifndef __ICCARM__ - ".syntax unified\n\t" -#endif - "1:\n\t" - "ldrex %[ret],[%[mem]]\n\t" -#if (__ARM_ARCH_8M_BASE__ == 1U) - "mov %[val],%[ret]\n\t" - "bics %[val],%[bits]\n\t" -#else - "bic %[val],%[ret],%[bits]\n\t" -#endif - "strex %[res],%[val],[%[mem]]\n\t" - "cbz %[res],2f\n\t" - "b 1b\n" - "2:" - : [ret] "=&l" (ret), - [val] "=&l" (val), - [res] "=&l" (res) - : [mem] "l" (mem), - [bits] "l" (bits) -#if (__ARM_ARCH_8M_BASE__ == 1U) - : "memory", "cc" -#else - : "memory" -#endif - ); - - return ret; -} -#endif - -/// Atomic Access Operation: Check if all specified bits (32-bit) are active and clear them -/// \param[in] mem Memory address -/// \param[in] bits Bit mask -/// \return Active bits before clearing or 0 if not active -#if defined(__CC_ARM) -static __asm uint32_t atomic_chk32_all (uint32_t *mem, uint32_t bits) { - push {r4,lr} - mov r2,r0 -1 - ldrex r0,[r2] - and r4,r0,r1 - cmp r4,r1 - beq %F2 - clrex - movs r0,#0 - pop {r4,pc} -2 - bic r4,r0,r1 - strex r3,r4,[r2] - cbz r3,%F3 - b %B1 -3 - pop {r4,pc} -} -#else -__STATIC_INLINE uint32_t atomic_chk32_all (uint32_t *mem, uint32_t bits) { -#ifdef __ICCARM__ -#pragma diag_suppress=Pe550 -#endif - register uint32_t val, res; -#ifdef __ICCARM__ -#pragma diag_default=Pe550 -#endif - register uint32_t ret; - - __ASM volatile ( -#ifndef __ICCARM__ - ".syntax unified\n\t" -#endif - "1:\n\t" - "ldrex %[ret],[%[mem]]\n\t" -#if (__ARM_ARCH_8M_BASE__ == 1U) - "mov %[val],%[ret]\n\t" - "ands %[val],%[bits]\n\t" -#else - "and %[val],%[ret],%[bits]\n\t" -#endif - "cmp %[val],%[bits]\n\t" - "beq 2f\n\t" - "clrex\n\t" - "movs %[ret],#0\n\t" - "b 3f\n" - "2:\n\t" -#if (__ARM_ARCH_8M_BASE__ == 1U) - "mov %[val],%[ret]\n\t" - "bics %[val],%[bits]\n\t" -#else - "bic %[val],%[ret],%[bits]\n\t" -#endif - "strex %[res],%[val],[%[mem]]\n\t" - "cbz %[res],3f\n\t" - "b 1b\n" - "3:" - : [ret] "=&l" (ret), - [val] "=&l" (val), - [res] "=&l" (res) - : [mem] "l" (mem), - [bits] "l" (bits) - : "cc", "memory" - ); - - return ret; -} -#endif - -/// Atomic Access Operation: Check if any specified bits (32-bit) are active and clear them -/// \param[in] mem Memory address -/// \param[in] bits Bit mask -/// \return Active bits before clearing or 0 if not active -#if defined(__CC_ARM) -static __asm uint32_t atomic_chk32_any (uint32_t *mem, uint32_t bits) { - push {r4,lr} - mov r2,r0 -1 - ldrex r0,[r2] - tst r0,r1 - bne %F2 - clrex - movs r0,#0 - pop {r4,pc} -2 - bic r4,r0,r1 - strex r3,r4,[r2] - cbz r3,%F3 - b %B1 -3 - pop {r4,pc} -} -#else -__STATIC_INLINE uint32_t atomic_chk32_any (uint32_t *mem, uint32_t bits) { -#ifdef __ICCARM__ -#pragma diag_suppress=Pe550 -#endif - register uint32_t val, res; -#ifdef __ICCARM__ -#pragma diag_default=Pe550 -#endif - register uint32_t ret; - - __ASM volatile ( -#ifndef __ICCARM__ - ".syntax unified\n\t" -#endif - "1:\n\t" - "ldrex %[ret],[%[mem]]\n\t" - "tst %[ret],%[bits]\n\t" - "bne 2f\n\t" - "clrex\n\t" - "movs %[ret],#0\n\t" - "b 3f\n" - "2:\n\t" -#if (__ARM_ARCH_8M_BASE__ == 1U) - "mov %[val],%[ret]\n\t" - "bics %[val],%[bits]\n\t" -#else - "bic %[val],%[ret],%[bits]\n\t" -#endif - "strex %[res],%[val],[%[mem]]\n\t" - "cbz %[res],3f\n\t" - "b 1b\n" - "3:" - : [ret] "=&l" (ret), - [val] "=&l" (val), - [res] "=&l" (res) - : [mem] "l" (mem), - [bits] "l" (bits) - : "cc", "memory" - ); - - return ret; -} -#endif - -/// Atomic Access Operation: Increment (32-bit) -/// \param[in] mem Memory address -/// \return Previous value -#if defined(__CC_ARM) -static __asm uint32_t atomic_inc32 (uint32_t *mem) { - mov r2,r0 -1 - ldrex r0,[r2] - adds r1,r0,#1 - strex r3,r1,[r2] - cbz r3,%F2 - b %B1 -2 - bx lr -} -#else -__STATIC_INLINE uint32_t atomic_inc32 (uint32_t *mem) { -#ifdef __ICCARM__ -#pragma diag_suppress=Pe550 -#endif - register uint32_t val, res; -#ifdef __ICCARM__ -#pragma diag_default=Pe550 -#endif - register uint32_t ret; - - __ASM volatile ( -#ifndef __ICCARM__ - ".syntax unified\n\t" -#endif - "1:\n\t" - "ldrex %[ret],[%[mem]]\n\t" - "adds %[val],%[ret],#1\n\t" - "strex %[res],%[val],[%[mem]]\n\t" - "cbz %[res],2f\n\t" - "b 1b\n" - "2:" - : [ret] "=&l" (ret), - [val] "=&l" (val), - [res] "=&l" (res) - : [mem] "l" (mem) - : "cc", "memory" - ); - - return ret; -} -#endif - -/// atomic Access Operation: Increment (32-bit) if Less Than -/// \param[in] mem Memory address -/// \param[in] max Maximum value -/// \return Previous value -#if defined(__CC_ARM) -static __asm uint32_t atomic_inc32_lt (uint32_t *mem, uint32_t max) { - push {r4,lr} - mov r2,r0 -1 - ldrex r0,[r2] - cmp r1,r0 - bhi %F2 - clrex - pop {r4,pc} -2 - adds r4,r0,#1 - strex r3,r4,[r2] - cbz r3,%F3 - b %B1 -3 - pop {r4,pc} -} -#else -__STATIC_INLINE uint32_t atomic_inc32_lt (uint32_t *mem, uint32_t max) { -#ifdef __ICCARM__ -#pragma diag_suppress=Pe550 -#endif - register uint32_t val, res; -#ifdef __ICCARM__ -#pragma diag_default=Pe550 -#endif - register uint32_t ret; - - __ASM volatile ( -#ifndef __ICCARM__ - ".syntax unified\n\t" -#endif - "1:\n\t" - "ldrex %[ret],[%[mem]]\n\t" - "cmp %[max],%[ret]\n\t" - "bhi 2f\n\t" - "clrex\n\t" - "b 3f\n" - "2:\n\t" - "adds %[val],%[ret],#1\n\t" - "strex %[res],%[val],[%[mem]]\n\t" - "cbz %[res],3f\n\t" - "b 1b\n" - "3:" - : [ret] "=&l" (ret), - [val] "=&l" (val), - [res] "=&l" (res) - : [mem] "l" (mem), - [max] "l" (max) - : "cc", "memory" - ); - - return ret; -} -#endif - -/// Atomic Access Operation: Increment (16-bit) if Less Than -/// \param[in] mem Memory address -/// \param[in] max Maximum value -/// \return Previous value -#if defined(__CC_ARM) -static __asm uint16_t atomic_inc16_lt (uint16_t *mem, uint16_t max) { - push {r4,lr} - mov r2,r0 -1 - ldrexh r0,[r2] - cmp r1,r0 - bhi %F2 - clrex - pop {r4,pc} -2 - adds r4,r0,#1 - strexh r3,r4,[r2] - cbz r3,%F3 - b %B1 -3 - pop {r4,pc} -} -#else -__STATIC_INLINE uint16_t atomic_inc16_lt (uint16_t *mem, uint16_t max) { -#ifdef __ICCARM__ -#pragma diag_suppress=Pe550 -#endif - register uint32_t val, res; -#ifdef __ICCARM__ -#pragma diag_default=Pe550 -#endif - register uint16_t ret; - - __ASM volatile ( -#ifndef __ICCARM__ - ".syntax unified\n\t" -#endif - "1:\n\t" - "ldrexh %[ret],[%[mem]]\n\t" - "cmp %[max],%[ret]\n\t" - "bhi 2f\n\t" - "clrex\n\t" - "b 3f\n" - "2:\n\t" - "adds %[val],%[ret],#1\n\t" - "strexh %[res],%[val],[%[mem]]\n\t" - "cbz %[res],3f\n\t" - "b 1b\n" - "3:" - : [ret] "=&l" (ret), - [val] "=&l" (val), - [res] "=&l" (res) - : [mem] "l" (mem), - [max] "l" (max) - : "cc", "memory" - ); - - return ret; -} -#endif - -/// Atomic Access Operation: Increment (16-bit) and clear on Limit -/// \param[in] mem Memory address -/// \param[in] max Maximum value -/// \return Previous value -#if defined(__CC_ARM) -static __asm uint16_t atomic_inc16_lim (uint16_t *mem, uint16_t lim) { - push {r4,lr} - mov r2,r0 -1 - ldrexh r0,[r2] - adds r4,r0,#1 - cmp r1,r4 - bhi %F2 - movs r4,#0 -2 - strexh r3,r4,[r2] - cbz r3,%F3 - b %B1 -3 - pop {r4,pc} -} -#else -__STATIC_INLINE uint16_t atomic_inc16_lim (uint16_t *mem, uint16_t lim) { -#ifdef __ICCARM__ -#pragma diag_suppress=Pe550 -#endif - register uint32_t val, res; -#ifdef __ICCARM__ -#pragma diag_default=Pe550 -#endif - register uint16_t ret; - - __ASM volatile ( -#ifndef __ICCARM__ - ".syntax unified\n\t" -#endif - "1:\n\t" - "ldrexh %[ret],[%[mem]]\n\t" - "adds %[val],%[ret],#1\n\t" - "cmp %[lim],%[val]\n\t" - "bhi 2f\n\t" - "movs %[val],#0\n" - "2:\n\t" - "strexh %[res],%[val],[%[mem]]\n\t" - "cbz %[res],3f\n\t" - "b 1b\n" - "3:" - : [ret] "=&l" (ret), - [val] "=&l" (val), - [res] "=&l" (res) - : [mem] "l" (mem), - [lim] "l" (lim) - : "cc", "memory" - ); - - return ret; -} -#endif - -/// Atomic Access Operation: Decrement (32-bit) if Not Zero -/// \param[in] mem Memory address -/// \return Previous value -#if defined(__CC_ARM) -static __asm uint32_t atomic_dec32_nz (uint32_t *mem) { - mov r2,r0 -1 - ldrex r0,[r2] - cbnz r0,%F2 - clrex - bx lr -2 - subs r1,r0,#1 - strex r3,r1,[r2] - cbz r3,%F3 - b %B1 -3 - bx lr -} -#else -__STATIC_INLINE uint32_t atomic_dec32_nz (uint32_t *mem) { -#ifdef __ICCARM__ -#pragma diag_suppress=Pe550 -#endif - register uint32_t val, res; -#ifdef __ICCARM__ -#pragma diag_default=Pe550 -#endif - register uint32_t ret; - - __ASM volatile ( -#ifndef __ICCARM__ - ".syntax unified\n\t" -#endif - "1:\n\t" - "ldrex %[ret],[%[mem]]\n\t" - "cbnz %[ret],2f\n\t" - "clrex\n\t" - "b 3f\n" - "2:\n\t" - "subs %[val],%[ret],#1\n\t" - "strex %[res],%[val],[%[mem]]\n\t" - "cbz %[res],3f\n\t" - "b 1b\n" - "3:" - : [ret] "=&l" (ret), - [val] "=&l" (val), - [res] "=&l" (res) - : [mem] "l" (mem) - : "cc", "memory" - ); - - return ret; -} -#endif - -/// Atomic Access Operation: Decrement (16-bit) if Not Zero -/// \param[in] mem Memory address -/// \return Previous value -#if defined(__CC_ARM) -static __asm uint16_t atomic_dec16_nz (uint16_t *mem) { - mov r2,r0 -1 - ldrexh r0,[r2] - cbnz r0,%F2 - clrex - bx lr -2 - subs r1,r0,#1 - strexh r3,r1,[r2] - cbz r3,%F3 - b %B1 -3 - bx lr -} -#else -__STATIC_INLINE uint16_t atomic_dec16_nz (uint16_t *mem) { -#ifdef __ICCARM__ -#pragma diag_suppress=Pe550 -#endif - register uint32_t val, res; -#ifdef __ICCARM__ -#pragma diag_default=Pe550 -#endif - register uint16_t ret; - - __ASM volatile ( -#ifndef __ICCARM__ - ".syntax unified\n\t" -#endif - "1:\n\t" - "ldrexh %[ret],[%[mem]]\n\t" - "cbnz %[ret],2f\n\t" - "clrex\n\t" - "b 3f\n" - "2:\n\t" - "subs %[val],%[ret],#1\n\t" - "strexh %[res],%[val],[%[mem]]\n\t" - "cbz %[res],3f\n\t" - "b 1b\n" - "3:" - : [ret] "=&l" (ret), - [val] "=&l" (val), - [res] "=&l" (res) - : [mem] "l" (mem) - : "cc", "memory" - ); - - return ret; -} -#endif - -/// Atomic Access Operation: Link Get -/// \param[in] root Root address -/// \return Link -#if defined(__CC_ARM) -static __asm void *atomic_link_get (void **root) { - mov r2,r0 -1 - ldrex r0,[r2] - cbnz r0,%F2 - clrex - bx lr -2 - ldr r1,[r0] - strex r3,r1,[r2] - cbz r3,%F3 - b %B1 -3 - bx lr -} -#else -__STATIC_INLINE void *atomic_link_get (void **root) { -#ifdef __ICCARM__ -#pragma diag_suppress=Pe550 -#endif - register uint32_t val, res; -#ifdef __ICCARM__ -#pragma diag_default=Pe550 -#endif - register void *ret; - - __ASM volatile ( -#ifndef __ICCARM__ - ".syntax unified\n\t" -#endif - "1:\n\t" - "ldrex %[ret],[%[root]]\n\t" - "cbnz %[ret],2f\n\t" - "clrex\n\t" - "b 3f\n" - "2:\n\t" - "ldr %[val],[%[ret]]\n\t" - "strex %[res],%[val],[%[root]]\n\t" - "cbz %[res],3f\n\t" - "b 1b\n" - "3:" - : [ret] "=&l" (ret), - [val] "=&l" (val), - [res] "=&l" (res) - : [root] "l" (root) - : "cc", "memory" - ); - - return ret; -} -#endif - -/// Atomic Access Operation: Link Put -/// \param[in] root Root address -/// \param[in] lnk Link -#if defined(__CC_ARM) -static __asm void atomic_link_put (void **root, void *link) { -1 - ldr r2,[r0] - str r2,[r1] - dmb - ldrex r2,[r0] - ldr r3,[r1] - cmp r3,r2 - bne %B1 - strex r3,r1,[r0] - cbz r3,%F2 - b %B1 -2 - bx lr -} -#else -__STATIC_INLINE void atomic_link_put (void **root, void *link) { -#ifdef __ICCARM__ -#pragma diag_suppress=Pe550 -#endif - register uint32_t val1, val2, res; -#ifdef __ICCARM__ -#pragma diag_default=Pe550 -#endif - - __ASM volatile ( -#ifndef __ICCARM__ - ".syntax unified\n\t" -#endif - "1:\n\t" - "ldr %[val1],[%[root]]\n\t" - "str %[val1],[%[link]]\n\t" - "dmb\n\t" - "ldrex %[val1],[%[root]]\n\t" - "ldr %[val2],[%[link]]\n\t" - "cmp %[val2],%[val1]\n\t" - "bne 1b\n\t" - "strex %[res],%[link],[%[root]]\n\t" - "cbz %[res],2f\n\t" - "b 1b\n" - "2:" - : [val1] "=&l" (val1), - [val2] "=&l" (val2), - [res] "=&l" (res) - : [root] "l" (root), - [link] "l" (link) - : "cc", "memory" - ); -} -#endif - -#endif // (__EXCLUSIVE_ACCESS == 1U) - - -#endif // CORE_CM_H_ - -/** @}*/ diff --git a/rtos/rtx5/TARGET_CORTEX_M/rt_OsEventObserver.c b/rtos/rtx5/TARGET_CORTEX_M/rt_OsEventObserver.c deleted file mode 100644 index 5fee0aa..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/rt_OsEventObserver.c +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2013-2016 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ----------------------------------------------------------------------------- - * - * Project: CMSIS-RTOS RTX - * Title: OS Event Observer - * - * ----------------------------------------------------------------------------- - */ -#include "rt_OsEventObserver.h" - -/* - * _____ _____ ____ __ _____ - * | ___|_ _\ \/ / \/ | ____| - * | |_ | | \ /| |\/| | _| - * | _| | | / \| | | | |___ - * |_| |___/_/\_\_| |_|_____| - * - * FIXME: - * The osEventObs variable must be in protected memory. If not every box - * and box 0 can modify osEventObs to point to any handler to run code - * privileged. This issue is tracked at - * . - */ -const OsEventObserver *osEventObs; - -void osRegisterForOsEvents(const OsEventObserver *observer) -{ - static uint8_t has_been_called = 0; - if (has_been_called) { - return; - } - has_been_called = 1; - - osEventObs = observer; -} diff --git a/rtos/rtx5/TARGET_CORTEX_M/rt_OsEventObserver.h b/rtos/rtx5/TARGET_CORTEX_M/rt_OsEventObserver.h deleted file mode 100644 index 899f319..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/rt_OsEventObserver.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2013-2016 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ----------------------------------------------------------------------------- - * - * Project: CMSIS-RTOS RTX - * Title: OS Event Observer - * - * ----------------------------------------------------------------------------- - */ -#ifndef _RT_OS_EVENT_OBSERVER_H -#define _RT_OS_EVENT_OBSERVER_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - uint32_t version; - void (*pre_start)(void); - void *(*thread_create)(int thread_id, void *context); - void (*thread_destroy)(void *context); - void (*thread_switch)(void *context); -} OsEventObserver; -extern const OsEventObserver *osEventObs; - -void osRegisterForOsEvents(const OsEventObserver *observer); - -#ifdef __cplusplus -}; -#endif - -#endif - -/** @}*/ diff --git a/rtos/rtx5/TARGET_CORTEX_M/rtx_delay.c b/rtos/rtx5/TARGET_CORTEX_M/rtx_delay.c deleted file mode 100644 index a7e71b7..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/rtx_delay.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ----------------------------------------------------------------------------- - * - * Project: CMSIS-RTOS RTX - * Title: Delay functions - * - * ----------------------------------------------------------------------------- - */ - -#include "rtx_lib.h" - - -// ==== Service Calls ==== - -// Service Calls definitions -SVC0_1(Delay, osStatus_t, uint32_t) -SVC0_2(DelayUntil, osStatus_t, uint32_t, uint32_t) - -/// Wait for Timeout (Time Delay). -/// \note API identical to osDelay -osStatus_t svcRtxDelay (uint32_t ticks) { - - if (ticks == 0U) { - return osOK; - } - - osRtxThreadWaitEnter(osRtxThreadWaitingDelay, ticks); - - return osOK; -} - -/// Wait until specified time. -/// \note API identical to osDelayUntil -osStatus_t svcRtxDelayUntil (uint32_t ticks_l, uint32_t ticks_h) { - uint64_t ticks = ((uint64_t)ticks_l) | ((uint64_t)ticks_h << 32); - - ticks -= osRtxInfo.kernel.tick; - if (ticks >= 0xFFFFFFFFU) { - EvrRtxThreadError(NULL, osErrorParameter); - return osErrorParameter; - } - if (ticks == 0U) { - return osOK; - } - - osRtxThreadWaitEnter(osRtxThreadWaitingDelay, (uint32_t)ticks); - - return osOK; -} - - -// ==== Public API ==== - -/// Wait for Timeout (Time Delay). -osStatus_t osDelay (uint32_t ticks) { - EvrRtxThreadDelay(ticks); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxThreadError(NULL, osErrorISR); - return osErrorISR; - } - return __svcDelay(ticks); -} - -/// Wait until specified time. -osStatus_t osDelayUntil (uint64_t ticks) { - EvrRtxThreadDelayUntil(ticks); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxThreadError(NULL, osErrorISR); - return osErrorISR; - } - return __svcDelayUntil((uint32_t)ticks, (uint32_t)(ticks >> 32)); -} diff --git a/rtos/rtx5/TARGET_CORTEX_M/rtx_evflags.c b/rtos/rtx5/TARGET_CORTEX_M/rtx_evflags.c deleted file mode 100644 index 1c534d5..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/rtx_evflags.c +++ /dev/null @@ -1,576 +0,0 @@ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ----------------------------------------------------------------------------- - * - * Project: CMSIS-RTOS RTX - * Title: Event Flags functions - * - * ----------------------------------------------------------------------------- - */ - -#include "rtx_lib.h" - - -// ==== Helper functions ==== - -/// Set Event Flags. -/// \param[in] ef event flags object. -/// \param[in] flags specifies the flags to set. -/// \return event flags after setting. -static uint32_t EventFlagsSet (os_event_flags_t *ef, uint32_t flags) { -#if (__EXCLUSIVE_ACCESS == 0U) - uint32_t primask = __get_PRIMASK(); -#endif - uint32_t event_flags; - -#if (__EXCLUSIVE_ACCESS == 0U) - __disable_irq(); - - ef->event_flags |= flags; - event_flags = ef->event_flags; - - if (primask == 0U) { - __enable_irq(); - } -#else - event_flags = atomic_set32(&ef->event_flags, flags); -#endif - - return event_flags; -} - -/// Clear Event Flags. -/// \param[in] ef event flags object. -/// \param[in] flags specifies the flags to clear. -/// \return event flags before clearing. -static uint32_t EventFlagsClear (os_event_flags_t *ef, uint32_t flags) { -#if (__EXCLUSIVE_ACCESS == 0U) - uint32_t primask = __get_PRIMASK(); -#endif - uint32_t event_flags; - -#if (__EXCLUSIVE_ACCESS == 0U) - __disable_irq(); - - event_flags = ef->event_flags; - ef->event_flags &= ~flags; - - if (primask == 0U) { - __enable_irq(); - } -#else - event_flags = atomic_clr32(&ef->event_flags, flags); -#endif - - return event_flags; -} - -/// Check Event Flags. -/// \param[in] ef event flags object. -/// \param[in] flags specifies the flags to check. -/// \param[in] options specifies flags options (osFlagsXxxx). -/// \return event flags before clearing or 0 if specified flags have not been set. -static uint32_t EventFlagsCheck (os_event_flags_t *ef, uint32_t flags, uint32_t options) { -#if (__EXCLUSIVE_ACCESS == 0U) - uint32_t primask; -#endif - uint32_t event_flags; - - if ((options & osFlagsNoClear) == 0U) { -#if (__EXCLUSIVE_ACCESS == 0U) - primask = __get_PRIMASK(); - __disable_irq(); - - event_flags = ef->event_flags; - if ((((options & osFlagsWaitAll) != 0U) && ((event_flags & flags) != flags)) || - (((options & osFlagsWaitAll) == 0U) && ((event_flags & flags) == 0U))) { - event_flags = 0U; - } else { - ef->event_flags &= ~flags; - } - - if (primask == 0U) { - __enable_irq(); - } -#else - if ((options & osFlagsWaitAll) != 0U) { - event_flags = atomic_chk32_all(&ef->event_flags, flags); - } else { - event_flags = atomic_chk32_any(&ef->event_flags, flags); - } -#endif - } else { - event_flags = ef->event_flags; - if ((((options & osFlagsWaitAll) != 0U) && ((event_flags & flags) != flags)) || - (((options & osFlagsWaitAll) == 0U) && ((event_flags & flags) == 0U))) { - event_flags = 0U; - } - } - - return event_flags; -} - - -// ==== Library functions ==== - -/// Event Flags post ISR processing. -/// \param[in] ef event flags object. -void osRtxEventFlagsPostProcess (os_event_flags_t *ef) { - os_thread_t *thread; - os_thread_t *thread_next; - uint32_t event_flags; - - if (ef->state == osRtxObjectInactive) { - return; - } - - // Check if Threads are waiting for Event Flags - thread = ef->thread_list; - while (thread != NULL) { - thread_next = thread->thread_next; - event_flags = EventFlagsCheck(ef, thread->wait_flags, thread->flags_options); - if (event_flags != 0U) { - osRtxThreadListRemove(thread); - osRtxThreadWaitExit(thread, event_flags, false); - EvrRtxEventFlagsWaitCompleted(ef, thread->wait_flags, thread->flags_options, event_flags); - } - thread = thread_next; - } -} - - -// ==== Service Calls ==== - -// Service Calls definitions -SVC0_1M(EventFlagsNew, osEventFlagsId_t, const osEventFlagsAttr_t *) -SVC0_1 (EventFlagsGetName, const char *, osEventFlagsId_t) -SVC0_2 (EventFlagsSet, uint32_t, osEventFlagsId_t, uint32_t) -SVC0_2 (EventFlagsClear, uint32_t, osEventFlagsId_t, uint32_t) -SVC0_1 (EventFlagsGet, uint32_t, osEventFlagsId_t) -SVC0_4 (EventFlagsWait, uint32_t, osEventFlagsId_t, uint32_t, uint32_t, uint32_t) -SVC0_1 (EventFlagsDelete, osStatus_t, osEventFlagsId_t) - -/// Create and Initialize an Event Flags object. -/// \note API identical to osEventFlagsNew -osEventFlagsId_t svcRtxEventFlagsNew (const osEventFlagsAttr_t *attr) { - os_event_flags_t *ef; - uint8_t flags; - const char *name; - - // Process attributes - if (attr != NULL) { - name = attr->name; - ef = attr->cb_mem; - if (ef != NULL) { - if (((uint32_t)ef & 3U) || (attr->cb_size < sizeof(os_event_flags_t))) { - EvrRtxEventFlagsError(NULL, osRtxErrorInvalidControlBlock); - return NULL; - } - } else { - if (attr->cb_size != 0U) { - EvrRtxEventFlagsError(NULL, osRtxErrorInvalidControlBlock); - return NULL; - } - } - } else { - name = NULL; - ef = NULL; - } - - // Allocate object memory if not provided - if (ef == NULL) { - if (osRtxInfo.mpi.event_flags != NULL) { - ef = osRtxMemoryPoolAlloc(osRtxInfo.mpi.event_flags); - } else { - ef = osRtxMemoryAlloc(osRtxInfo.mem.common, sizeof(os_event_flags_t), 1U); - } - if (ef == NULL) { - EvrRtxEventFlagsError(NULL, osErrorNoMemory); - return NULL; - } - flags = osRtxFlagSystemObject; - } else { - flags = 0U; - } - - // Initialize control block - ef->id = osRtxIdEventFlags; - ef->state = osRtxObjectActive; - ef->flags = flags; - ef->name = name; - ef->thread_list = NULL; - ef->event_flags = 0U; - - // Register post ISR processing function - osRtxInfo.post_process.event_flags = osRtxEventFlagsPostProcess; - - EvrRtxEventFlagsCreated(ef); - - return ef; -} - -/// Get name of an Event Flags object. -/// \note API identical to osEventFlagsGetName -const char *svcRtxEventFlagsGetName (osEventFlagsId_t ef_id) { - os_event_flags_t *ef = (os_event_flags_t *)ef_id; - - // Check parameters - if ((ef == NULL) || (ef->id != osRtxIdEventFlags)) { - EvrRtxEventFlagsGetName(ef, NULL); - return NULL; - } - - // Check object state - if (ef->state == osRtxObjectInactive) { - EvrRtxEventFlagsGetName(ef, NULL); - return NULL; - } - - EvrRtxEventFlagsGetName(ef, ef->name); - - return ef->name; -} - -/// Set the specified Event Flags. -/// \note API identical to osEventFlagsSet -uint32_t svcRtxEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags) { - os_event_flags_t *ef = (os_event_flags_t *)ef_id; - os_thread_t *thread; - os_thread_t *thread_next; - uint32_t event_flags; - uint32_t event_flags0; - - // Check parameters - if ((ef == NULL) || (ef->id != osRtxIdEventFlags) || - (flags & ~((1U << osRtxEventFlagsLimit) - 1U))) { - EvrRtxEventFlagsError(ef, osErrorParameter); - return ((uint32_t)osErrorParameter); - } - - // Check object state - if (ef->state == osRtxObjectInactive) { - EvrRtxEventFlagsError(ef, osErrorResource); - return ((uint32_t)osErrorResource); - } - - // Set Event Flags - event_flags = EventFlagsSet(ef, flags); - - // Check if Threads are waiting for Event Flags - thread = ef->thread_list; - while (thread != NULL) { - thread_next = thread->thread_next; - event_flags0 = EventFlagsCheck(ef, thread->wait_flags, thread->flags_options); - if (event_flags0 != 0U) { - if ((thread->flags_options & osFlagsNoClear) == 0U) { - event_flags = event_flags0 & ~thread->wait_flags; - } else { - event_flags = event_flags0; - } - osRtxThreadListRemove(thread); - osRtxThreadWaitExit(thread, event_flags0, false); - EvrRtxEventFlagsWaitCompleted(ef, thread->wait_flags, thread->flags_options, event_flags0); - } - thread = thread_next; - } - osRtxThreadDispatch(NULL); - - EvrRtxEventFlagsSetDone(ef, event_flags); - - return event_flags; -} - -/// Clear the specified Event Flags. -/// \note API identical to osEventFlagsClear -uint32_t svcRtxEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags) { - os_event_flags_t *ef = (os_event_flags_t *)ef_id; - uint32_t event_flags; - - // Check parameters - if ((ef == NULL) || (ef->id != osRtxIdEventFlags) || - (flags & ~((1U << osRtxEventFlagsLimit) - 1U))) { - EvrRtxEventFlagsError(ef, osErrorParameter); - return ((uint32_t)osErrorParameter); - } - - // Check object state - if (ef->state == osRtxObjectInactive) { - EvrRtxEventFlagsError(ef, osErrorResource); - return ((uint32_t)osErrorResource); - } - - // Clear Event Flags - event_flags = EventFlagsClear(ef, flags); - - EvrRtxEventFlagsClearDone(ef, event_flags); - - return event_flags; -} - -/// Get the current Event Flags. -/// \note API identical to osEventFlagsGet -uint32_t svcRtxEventFlagsGet (osEventFlagsId_t ef_id) { - os_event_flags_t *ef = (os_event_flags_t *)ef_id; - - // Check parameters - if ((ef == NULL) || (ef->id != osRtxIdEventFlags)) { - EvrRtxEventFlagsGet(ef, 0U); - return 0U; - } - - // Check object state - if (ef->state == osRtxObjectInactive) { - EvrRtxEventFlagsGet(ef, 0U); - return 0U; - } - - EvrRtxEventFlagsGet(ef, ef->event_flags); - - return ef->event_flags; -} - -/// Wait for one or more Event Flags to become signaled. -/// \note API identical to osEventFlagsWait -uint32_t svcRtxEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout) { - os_event_flags_t *ef = (os_event_flags_t *)ef_id; - os_thread_t *running_thread; - uint32_t event_flags; - - running_thread = osRtxThreadGetRunning(); - if (running_thread == NULL) { - EvrRtxEventFlagsError(ef, osRtxErrorKernelNotRunning); - return ((uint32_t)osError); - } - - // Check parameters - if ((ef == NULL) || (ef->id != osRtxIdEventFlags) || - (flags & ~((1U << osRtxEventFlagsLimit) - 1U))) { - EvrRtxEventFlagsError(ef, osErrorParameter); - return ((uint32_t)osErrorParameter); - } - - // Check object state - if (ef->state == osRtxObjectInactive) { - EvrRtxEventFlagsError(ef, osErrorResource); - return ((uint32_t)osErrorResource); - } - - // Check Event Flags - event_flags = EventFlagsCheck(ef, flags, options); - if (event_flags != 0U) { - EvrRtxEventFlagsWaitCompleted(ef, flags, options, event_flags); - return event_flags; - } - - // Check if timeout is specified - if (timeout != 0U) { - EvrRtxEventFlagsWaitPending(ef, flags, options, timeout); - // Store waiting flags and options - running_thread->wait_flags = flags; - running_thread->flags_options = (uint8_t)options; - // Suspend current Thread - osRtxThreadListPut((os_object_t*)ef, running_thread); - osRtxThreadWaitEnter(osRtxThreadWaitingEventFlags, timeout); - return ((uint32_t)osErrorTimeout); - } - - EvrRtxEventFlagsWaitNotCompleted(ef, flags, options); - - return ((uint32_t)osErrorResource); -} - -/// Delete an Event Flags object. -/// \note API identical to osEventFlagsDelete -osStatus_t svcRtxEventFlagsDelete (osEventFlagsId_t ef_id) { - os_event_flags_t *ef = (os_event_flags_t *)ef_id; - os_thread_t *thread; - - // Check parameters - if ((ef == NULL) || (ef->id != osRtxIdEventFlags)) { - EvrRtxEventFlagsError(ef, osErrorParameter); - return osErrorParameter; - } - - // Check object state - if (ef->state == osRtxObjectInactive) { - EvrRtxEventFlagsError(ef, osErrorResource); - return osErrorResource; - } - - // Mark object as inactive - ef->state = osRtxObjectInactive; - - // Unblock waiting threads - if (ef->thread_list != NULL) { - do { - thread = osRtxThreadListGet((os_object_t*)ef); - osRtxThreadWaitExit(thread, (uint32_t)osErrorResource, false); - } while (ef->thread_list != NULL); - osRtxThreadDispatch(NULL); - } - - // Free object memory - if (ef->flags & osRtxFlagSystemObject) { - if (osRtxInfo.mpi.event_flags != NULL) { - osRtxMemoryPoolFree(osRtxInfo.mpi.event_flags, ef); - } else { - osRtxMemoryFree(osRtxInfo.mem.common, ef); - } - } - - EvrRtxEventFlagsDestroyed(ef); - - return osOK; -} - - -// ==== ISR Calls ==== - -/// Set the specified Event Flags. -/// \note API identical to osEventFlagsSet -__STATIC_INLINE -uint32_t isrRtxEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags) { - os_event_flags_t *ef = (os_event_flags_t *)ef_id; - uint32_t event_flags; - - // Check parameters - if ((ef == NULL) || (ef->id != osRtxIdEventFlags) || - (flags & ~((1U << osRtxEventFlagsLimit) - 1U))) { - EvrRtxEventFlagsError(ef, osErrorParameter); - return ((uint32_t)osErrorParameter); - } - - // Check object state - if (ef->state == osRtxObjectInactive) { - EvrRtxEventFlagsError(ef, osErrorResource); - return ((uint32_t)osErrorResource); - } - - // Set Event Flags - event_flags = EventFlagsSet(ef, flags); - - // Register post ISR processing - osRtxPostProcess((os_object_t *)ef); - - EvrRtxEventFlagsSetDone(ef, event_flags); - - return event_flags; -} - -/// Wait for one or more Event Flags to become signaled. -/// \note API identical to osEventFlagsWait -__STATIC_INLINE -uint32_t isrRtxEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout) { - os_event_flags_t *ef = (os_event_flags_t *)ef_id; - uint32_t event_flags; - - // Check parameters - if ((ef == NULL) || (ef->id != osRtxIdEventFlags) || (timeout != 0U) || - (flags & ~((1U << osRtxEventFlagsLimit) - 1U))) { - EvrRtxEventFlagsError(ef, osErrorParameter); - return ((uint32_t)osErrorParameter); - } - - // Check object state - if (ef->state == osRtxObjectInactive) { - EvrRtxEventFlagsError(ef, osErrorResource); - return ((uint32_t)osErrorResource); - } - - // Check Event Flags - event_flags = EventFlagsCheck(ef, flags, options); - if (event_flags != 0U) { - EvrRtxEventFlagsWaitCompleted(ef, flags, options, event_flags); - return ((uint32_t)event_flags); - } - - EvrRtxEventFlagsWaitNotCompleted(ef, flags, options); - - return ((uint32_t)osErrorResource); -} - - -// ==== Public API ==== - -/// Create and Initialize an Event Flags object. -osEventFlagsId_t osEventFlagsNew (const osEventFlagsAttr_t *attr) { - EvrRtxEventFlagsNew(attr); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxEventFlagsError(NULL, osErrorISR); - return NULL; - } - return __svcEventFlagsNew(attr); -} - -/// Get name of an Event Flags object. -const char *osEventFlagsGetName (osEventFlagsId_t ef_id) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxEventFlagsGetName(ef_id, NULL); - return NULL; - } - return __svcEventFlagsGetName(ef_id); -} - -/// Set the specified Event Flags. -uint32_t osEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags) { - EvrRtxEventFlagsSet(ef_id, flags); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - return isrRtxEventFlagsSet(ef_id, flags); - } else { - return __svcEventFlagsSet(ef_id, flags); - } -} - -/// Clear the specified Event Flags. -uint32_t osEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags) { - EvrRtxEventFlagsClear(ef_id, flags); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - return svcRtxEventFlagsClear(ef_id, flags); - } else { - return __svcEventFlagsClear(ef_id, flags); - } -} - -/// Get the current Event Flags. -uint32_t osEventFlagsGet (osEventFlagsId_t ef_id) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - return svcRtxEventFlagsGet(ef_id); - } else { - return __svcEventFlagsGet(ef_id); - } -} - -/// Wait for one or more Event Flags to become signaled. -uint32_t osEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout) { - EvrRtxEventFlagsWait(ef_id, flags, options, timeout); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - return isrRtxEventFlagsWait(ef_id, flags, options, timeout); - } else { - return __svcEventFlagsWait(ef_id, flags, options, timeout); - } -} - -/// Delete an Event Flags object. -osStatus_t osEventFlagsDelete (osEventFlagsId_t ef_id) { - EvrRtxEventFlagsDelete(ef_id); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxEventFlagsError(ef_id, osErrorISR); - return osErrorISR; - } - return __svcEventFlagsDelete(ef_id); -} diff --git a/rtos/rtx5/TARGET_CORTEX_M/rtx_evr.c b/rtos/rtx5/TARGET_CORTEX_M/rtx_evr.c deleted file mode 100644 index f368df8..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/rtx_evr.c +++ /dev/null @@ -1,2077 +0,0 @@ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ----------------------------------------------------------------------------- - * - * Project: CMSIS-RTOS RTX - * Title: RTX Event Recorder - * - * ----------------------------------------------------------------------------- - */ - -#include -#include "cmsis_compiler.h" -#include "rtx_evr.h" // RTX Event Recorder definitions - -#ifdef RTE_Compiler_EventRecorder - -#include "EventRecorder.h" // Keil::Compiler:Event Recorder - -/// RTOS component number -#define EvtRtxMemoryNo (0xF0U) -#define EvtRtxKernelNo (0xF1U) -#define EvtRtxThreadNo (0xF2U) -#define EvtRtxTimerNo (0xF3U) -#define EvtRtxEventFlagsNo (0xF4U) -#define EvtRtxMutexNo (0xF5U) -#define EvtRtxSemaphoreNo (0xF6U) -#define EvtRtxMemoryPoolNo (0xF7U) -#define EvtRtxMessageQueueNo (0xF8U) - -/// Event IDs for "RTX Memory Management" -#define EvtRtxMemoryInit EventID(EventLevelOp, EvtRtxMemoryNo, 0x00U) -#define EvtRtxMemoryAlloc EventID(EventLevelOp, EvtRtxMemoryNo, 0x01U) -#define EvtRtxMemoryFree EventID(EventLevelOp, EvtRtxMemoryNo, 0x02U) -#define EvtRtxMemoryBlockInit EventID(EventLevelOp, EvtRtxMemoryNo, 0x03U) -#define EvtRtxMemoryBlockAlloc EventID(EventLevelOp, EvtRtxMemoryNo, 0x04U) -#define EvtRtxMemoryBlockFree EventID(EventLevelOp, EvtRtxMemoryNo, 0x05U) - -/// Event IDs for "RTX Kernel" -#define EvtRtxKernelError EventID(EventLevelError, EvtRtxKernelNo, 0x00U) -#define EvtRtxKernelInitialize EventID(EventLevelAPI, EvtRtxKernelNo, 0x01U) -#define EvtRtxKernelInitializeCompleted EventID(EventLevelOp, EvtRtxKernelNo, 0x02U) -#define EvtRtxKernelGetInfo EventID(EventLevelAPI, EvtRtxKernelNo, 0x03U) -#define EvtRtxKernelInfoRetrieved EventID(EventLevelOp, EvtRtxKernelNo, 0x04U) -#define EvtRtxKernelInfoRetrieved_Detail EventID(EventLevelDetail, EvtRtxKernelNo, 0x05U) -#define EvtRtxKernelGetState EventID(EventLevelAPI, EvtRtxKernelNo, 0x06U) -#define EvtRtxKernelStart EventID(EventLevelAPI, EvtRtxKernelNo, 0x07U) -#define EvtRtxKernelStarted EventID(EventLevelOp, EvtRtxKernelNo, 0x08U) -#define EvtRtxKernelLock EventID(EventLevelAPI, EvtRtxKernelNo, 0x09U) -#define EvtRtxKernelLocked EventID(EventLevelOp, EvtRtxKernelNo, 0x0AU) -#define EvtRtxKernelUnlock EventID(EventLevelAPI, EvtRtxKernelNo, 0x0BU) -#define EvtRtxKernelUnlocked EventID(EventLevelOp, EvtRtxKernelNo, 0x0CU) -#define EvtRtxKernelRestoreLock EventID(EventLevelAPI, EvtRtxKernelNo, 0x0DU) -#define EvtRtxKernelLockRestored EventID(EventLevelOp, EvtRtxKernelNo, 0x0EU) -#define EvtRtxKernelSuspend EventID(EventLevelAPI, EvtRtxKernelNo, 0x0FU) -#define EvtRtxKernelSuspended EventID(EventLevelOp, EvtRtxKernelNo, 0x10U) -#define EvtRtxKernelResume EventID(EventLevelAPI, EvtRtxKernelNo, 0x11U) -#define EvtRtxKernelResumed EventID(EventLevelOp, EvtRtxKernelNo, 0x12U) -#define EvtRtxKernelGetTickCount EventID(EventLevelAPI, EvtRtxKernelNo, 0x13U) -#define EvtRtxKernelGetTickFreq EventID(EventLevelAPI, EvtRtxKernelNo, 0x14U) -#define EvtRtxKernelGetSysTimerCount EventID(EventLevelAPI, EvtRtxKernelNo, 0x15U) -#define EvtRtxKernelGetSysTimerFreq EventID(EventLevelAPI, EvtRtxKernelNo, 0x16U) - -/// Event IDs for "RTX Thread" -#define EvtRtxThreadError EventID(EventLevelError, EvtRtxThreadNo, 0x00U) -#define EvtRtxThreadNew EventID(EventLevelAPI, EvtRtxThreadNo, 0x01U) -#define EvtRtxThreadNew_Detail EventID(EventLevelDetail, EvtRtxThreadNo, 0x02U) -#define EvtRtxThreadCreated EventID(EventLevelOp, EvtRtxThreadNo, 0x03U) -#define EvtRtxThreadGetName EventID(EventLevelAPI, EvtRtxThreadNo, 0x04U) -#define EvtRtxThreadGetName_Detail EventID(EventLevelDetail, EvtRtxThreadNo, 0x05U) -#define EvtRtxThreadGetId EventID(EventLevelAPI, EvtRtxThreadNo, 0x06U) -#define EvtRtxThreadGetState EventID(EventLevelAPI, EvtRtxThreadNo, 0x07U) -#define EvtRtxThreadGetStackSize EventID(EventLevelAPI, EvtRtxThreadNo, 0x08U) -#define EvtRtxThreadGetStackSpace EventID(EventLevelAPI, EvtRtxThreadNo, 0x09U) -#define EvtRtxThreadSetPriority EventID(EventLevelAPI, EvtRtxThreadNo, 0x0AU) -#define EvtRtxThreadGetPriority EventID(EventLevelAPI, EvtRtxThreadNo, 0x0BU) -#define EvtRtxThreadYield EventID(EventLevelAPI, EvtRtxThreadNo, 0x0CU) -#define EvtRtxThreadSuspend EventID(EventLevelAPI, EvtRtxThreadNo, 0x0DU) -#define EvtRtxThreadSuspended EventID(EventLevelOp, EvtRtxThreadNo, 0x0EU) -#define EvtRtxThreadResume EventID(EventLevelAPI, EvtRtxThreadNo, 0x0FU) -#define EvtRtxThreadResumed EventID(EventLevelOp, EvtRtxThreadNo, 0x10U) -#define EvtRtxThreadDetach EventID(EventLevelAPI, EvtRtxThreadNo, 0x11U) -#define EvtRtxThreadDetached EventID(EventLevelOp, EvtRtxThreadNo, 0x12U) -#define EvtRtxThreadJoin EventID(EventLevelAPI, EvtRtxThreadNo, 0x13U) -#define EvtRtxThreadJoinPending EventID(EventLevelOp, EvtRtxThreadNo, 0x14U) -#define EvtRtxThreadJoined EventID(EventLevelOp, EvtRtxThreadNo, 0x15U) -#define EvtRtxThreadBlocked EventID(EventLevelOp, EvtRtxThreadNo, 0x16U) -#define EvtRtxThreadUnblocked EventID(EventLevelOp, EvtRtxThreadNo, 0x17U) -#define EvtRtxThreadSwitch EventID(EventLevelOp, EvtRtxThreadNo, 0x18U) -#define EvtRtxThreadExit EventID(EventLevelAPI, EvtRtxThreadNo, 0x19U) -#define EvtRtxThreadTerminate EventID(EventLevelAPI, EvtRtxThreadNo, 0x1AU) -#define EvtRtxThreadDestroyed EventID(EventLevelOp, EvtRtxThreadNo, 0x1BU) -#define EvtRtxThreadGetCount EventID(EventLevelAPI, EvtRtxThreadNo, 0x1CU) -#define EvtRtxThreadEnumerate EventID(EventLevelAPI, EvtRtxThreadNo, 0x1DU) -#define EvtRtxThreadFlagsSet EventID(EventLevelAPI, EvtRtxThreadNo, 0x1EU) -#define EvtRtxThreadFlagsSetDone EventID(EventLevelOp, EvtRtxThreadNo, 0x1FU) -#define EvtRtxThreadFlagsClear EventID(EventLevelAPI, EvtRtxThreadNo, 0x20U) -#define EvtRtxThreadFlagsClearDone EventID(EventLevelOp, EvtRtxThreadNo, 0x21U) -#define EvtRtxThreadFlagsGet EventID(EventLevelAPI, EvtRtxThreadNo, 0x22U) -#define EvtRtxThreadFlagsWait EventID(EventLevelAPI, EvtRtxThreadNo, 0x23U) -#define EvtRtxThreadFlagsWaitPending EventID(EventLevelOp, EvtRtxThreadNo, 0x24U) -#define EvtRtxThreadFlagsWaitTimeout EventID(EventLevelOp, EvtRtxThreadNo, 0x25U) -#define EvtRtxThreadFlagsWaitCompleted EventID(EventLevelOp, EvtRtxThreadNo, 0x26U) -#define EvtRtxThreadFlagsWaitNotCompleted EventID(EventLevelOp, EvtRtxThreadNo, 0x27U) -#define EvtRtxThreadDelay EventID(EventLevelAPI, EvtRtxThreadNo, 0x28U) -#define EvtRtxThreadDelayUntil EventID(EventLevelAPI, EvtRtxThreadNo, 0x29U) -#define EvtRtxThreadDelayCompleted EventID(EventLevelOp, EvtRtxThreadNo, 0x2AU) - -/// Event IDs for "RTX Timer" -#define EvtRtxTimerError EventID(EventLevelError, EvtRtxTimerNo, 0x00U) -#define EvtRtxTimerCallback EventID(EventLevelOp, EvtRtxTimerNo, 0x01U) -#define EvtRtxTimerNew EventID(EventLevelAPI, EvtRtxTimerNo, 0x02U) -#define EvtRtxTimerNew_Detail EventID(EventLevelDetail, EvtRtxTimerNo, 0x03U) -#define EvtRtxTimerCreated EventID(EventLevelOp, EvtRtxTimerNo, 0x04U) -#define EvtRtxTimerGetName EventID(EventLevelAPI, EvtRtxTimerNo, 0x05U) -#define EvtRtxTimerGetName_Detail EventID(EventLevelDetail, EvtRtxTimerNo, 0x06U) -#define EvtRtxTimerStart EventID(EventLevelAPI, EvtRtxTimerNo, 0x07U) -#define EvtRtxTimerStarted EventID(EventLevelOp, EvtRtxTimerNo, 0x08U) -#define EvtRtxTimerStop EventID(EventLevelAPI, EvtRtxTimerNo, 0x09U) -#define EvtRtxTimerStopped EventID(EventLevelOp, EvtRtxTimerNo, 0x0AU) -#define EvtRtxTimerIsRunning EventID(EventLevelAPI, EvtRtxTimerNo, 0x0BU) -#define EvtRtxTimerDelete EventID(EventLevelAPI, EvtRtxTimerNo, 0x0CU) -#define EvtRtxTimerDestroyed EventID(EventLevelOp, EvtRtxTimerNo, 0x0DU) - -/// Event IDs for "RTX Event Flags" -#define EvtRtxEventFlagsError EventID(EventLevelError, EvtRtxEventFlagsNo, 0x00U) -#define EvtRtxEventFlagsNew EventID(EventLevelAPI, EvtRtxEventFlagsNo, 0x01U) -#define EvtRtxEventFlagsNew_Detail EventID(EventLevelDetail, EvtRtxEventFlagsNo, 0x02U) -#define EvtRtxEventFlagsCreated EventID(EventLevelOp, EvtRtxEventFlagsNo, 0x03U) -#define EvtRtxEventFlagsGetName EventID(EventLevelAPI, EvtRtxEventFlagsNo, 0x04U) -#define EvtRtxEventFlagsGetName_Detail EventID(EventLevelDetail, EvtRtxEventFlagsNo, 0x05U) -#define EvtRtxEventFlagsSet EventID(EventLevelAPI, EvtRtxEventFlagsNo, 0x06U) -#define EvtRtxEventFlagsSetDone EventID(EventLevelOp, EvtRtxEventFlagsNo, 0x07U) -#define EvtRtxEventFlagsClear EventID(EventLevelAPI, EvtRtxEventFlagsNo, 0x08U) -#define EvtRtxEventFlagsClearDone EventID(EventLevelOp, EvtRtxEventFlagsNo, 0x09U) -#define EvtRtxEventFlagsGet EventID(EventLevelAPI, EvtRtxEventFlagsNo, 0x0AU) -#define EvtRtxEventFlagsWait EventID(EventLevelAPI, EvtRtxEventFlagsNo, 0x0BU) -#define EvtRtxEventFlagsWaitPending EventID(EventLevelOp, EvtRtxEventFlagsNo, 0x0CU) -#define EvtRtxEventFlagsWaitTimeout EventID(EventLevelOp, EvtRtxEventFlagsNo, 0x0DU) -#define EvtRtxEventFlagsWaitCompleted EventID(EventLevelOp, EvtRtxEventFlagsNo, 0x0EU) -#define EvtRtxEventFlagsWaitNotCompleted EventID(EventLevelOp, EvtRtxEventFlagsNo, 0x0FU) -#define EvtRtxEventFlagsDelete EventID(EventLevelAPI, EvtRtxEventFlagsNo, 0x10U) -#define EvtRtxEventFlagsDestroyed EventID(EventLevelOp, EvtRtxEventFlagsNo, 0x11U) - -/// Event IDs for "RTX Mutex" -#define EvtRtxMutexError EventID(EventLevelError, EvtRtxMutexNo, 0x00U) -#define EvtRtxMutexNew EventID(EventLevelAPI, EvtRtxMutexNo, 0x01U) -#define EvtRtxMutexNew_Detail EventID(EventLevelDetail, EvtRtxMutexNo, 0x02U) -#define EvtRtxMutexCreated EventID(EventLevelOp, EvtRtxMutexNo, 0x03U) -#define EvtRtxMutexGetName EventID(EventLevelAPI, EvtRtxMutexNo, 0x04U) -#define EvtRtxMutexGetName_Detail EventID(EventLevelDetail, EvtRtxMutexNo, 0x05U) -#define EvtRtxMutexAcquire EventID(EventLevelAPI, EvtRtxMutexNo, 0x06U) -#define EvtRtxMutexAcquirePending EventID(EventLevelError, EvtRtxMutexNo, 0x07U) -#define EvtRtxMutexAcquireTimeout EventID(EventLevelError, EvtRtxMutexNo, 0x08U) -#define EvtRtxMutexAcquired EventID(EventLevelOp, EvtRtxMutexNo, 0x09U) -#define EvtRtxMutexNotAcquired EventID(EventLevelOp, EvtRtxMutexNo, 0x0AU) -#define EvtRtxMutexRelease EventID(EventLevelAPI, EvtRtxMutexNo, 0x0BU) -#define EvtRtxMutexReleased EventID(EventLevelOp, EvtRtxMutexNo, 0x0CU) -#define EvtRtxMutexGetOwner EventID(EventLevelAPI, EvtRtxMutexNo, 0x0DU) -#define EvtRtxMutexDelete EventID(EventLevelAPI, EvtRtxMutexNo, 0x0EU) -#define EvtRtxMutexDestroyed EventID(EventLevelOp, EvtRtxMutexNo, 0x0FU) - -/// Event IDs for "RTX Semaphore" -#define EvtRtxSemaphoreError EventID(EventLevelError, EvtRtxSemaphoreNo, 0x00U) -#define EvtRtxSemaphoreNew EventID(EventLevelAPI, EvtRtxSemaphoreNo, 0x01U) -#define EvtRtxSemaphoreNew_Detail EventID(EventLevelDetail, EvtRtxSemaphoreNo, 0x02U) -#define EvtRtxSemaphoreCreated EventID(EventLevelOp, EvtRtxSemaphoreNo, 0x03U) -#define EvtRtxSemaphoreGetName EventID(EventLevelAPI, EvtRtxSemaphoreNo, 0x04U) -#define EvtRtxSemaphoreGetName_Detail EventID(EventLevelDetail, EvtRtxSemaphoreNo, 0x05U) -#define EvtRtxSemaphoreAcquire EventID(EventLevelAPI, EvtRtxSemaphoreNo, 0x06U) -#define EvtRtxSemaphoreAcquirePending EventID(EventLevelOp, EvtRtxSemaphoreNo, 0x07U) -#define EvtRtxSemaphoreAcquireTimeout EventID(EventLevelOp, EvtRtxSemaphoreNo, 0x08U) -#define EvtRtxSemaphoreAcquired EventID(EventLevelOp, EvtRtxSemaphoreNo, 0x09U) -#define EvtRtxSemaphoreNotAcquired EventID(EventLevelOp, EvtRtxSemaphoreNo, 0x0AU) -#define EvtRtxSemaphoreRelease EventID(EventLevelAPI, EvtRtxSemaphoreNo, 0x0BU) -#define EvtRtxSemaphoreReleased EventID(EventLevelOp, EvtRtxSemaphoreNo, 0x0CU) -#define EvtRtxSemaphoreGetCount EventID(EventLevelAPI, EvtRtxSemaphoreNo, 0x0DU) -#define EvtRtxSemaphoreDelete EventID(EventLevelAPI, EvtRtxSemaphoreNo, 0x0EU) -#define EvtRtxSemaphoreDestroyed EventID(EventLevelOp, EvtRtxSemaphoreNo, 0x0FU) - -/// Event IDs for "RTX Memory Pool" -#define EvtRtxMemoryPoolError EventID(EventLevelError, EvtRtxMemoryPoolNo, 0x00U) -#define EvtRtxMemoryPoolNew EventID(EventLevelAPI, EvtRtxMemoryPoolNo, 0x01U) -#define EvtRtxMemoryPoolNew_Detail EventID(EventLevelDetail, EvtRtxMemoryPoolNo, 0x02U) -#define EvtRtxMemoryPoolCreated EventID(EventLevelOp, EvtRtxMemoryPoolNo, 0x03U) -#define EvtRtxMemoryPoolGetName EventID(EventLevelAPI, EvtRtxMemoryPoolNo, 0x04U) -#define EvtRtxMemoryPoolGetName_Detail EventID(EventLevelDetail, EvtRtxMemoryPoolNo, 0x05U) -#define EvtRtxMemoryPoolAlloc EventID(EventLevelAPI, EvtRtxMemoryPoolNo, 0x06U) -#define EvtRtxMemoryPoolAllocPending EventID(EventLevelOp, EvtRtxMemoryPoolNo, 0x07U) -#define EvtRtxMemoryPoolAllocTimeout EventID(EventLevelOp, EvtRtxMemoryPoolNo, 0x08U) -#define EvtRtxMemoryPoolAllocated EventID(EventLevelOp, EvtRtxMemoryPoolNo, 0x09U) -#define EvtRtxMemoryPoolAllocFailed EventID(EventLevelOp, EvtRtxMemoryPoolNo, 0x0AU) -#define EvtRtxMemoryPoolFree EventID(EventLevelAPI, EvtRtxMemoryPoolNo, 0x0BU) -#define EvtRtxMemoryPoolDeallocated EventID(EventLevelOp, EvtRtxMemoryPoolNo, 0x0CU) -#define EvtRtxMemoryPoolFreeFailed EventID(EventLevelOp, EvtRtxMemoryPoolNo, 0x0DU) -#define EvtRtxMemoryPoolGetCapacity EventID(EventLevelAPI, EvtRtxMemoryPoolNo, 0x0EU) -#define EvtRtxMemoryPoolGetBlockSize EventID(EventLevelAPI, EvtRtxMemoryPoolNo, 0x0FU) -#define EvtRtxMemoryPoolGetCount EventID(EventLevelAPI, EvtRtxMemoryPoolNo, 0x10U) -#define EvtRtxMemoryPoolGetSpace EventID(EventLevelAPI, EvtRtxMemoryPoolNo, 0x11U) -#define EvtRtxMemoryPoolDelete EventID(EventLevelAPI, EvtRtxMemoryPoolNo, 0x12U) -#define EvtRtxMemoryPoolDestroyed EventID(EventLevelOp, EvtRtxMemoryPoolNo, 0x13U) - -/// Event IDs for "RTX Message Queue" -#define EvtRtxMessageQueueError EventID(EventLevelError, EvtRtxMessageQueueNo, 0x00U) -#define EvtRtxMessageQueueNew EventID(EventLevelAPI, EvtRtxMessageQueueNo, 0x01U) -#define EvtRtxMessageQueueNew_Detail EventID(EventLevelDetail, EvtRtxMessageQueueNo, 0x02U) -#define EvtRtxMessageQueueCreated EventID(EventLevelOp, EvtRtxMessageQueueNo, 0x03U) -#define EvtRtxMessageQueueGetName EventID(EventLevelAPI, EvtRtxMessageQueueNo, 0x04U) -#define EvtRtxMessageQueueGetName_Detail EventID(EventLevelDetail, EvtRtxMessageQueueNo, 0x05U) -#define EvtRtxMessageQueuePut EventID(EventLevelAPI, EvtRtxMessageQueueNo, 0x06U) -#define EvtRtxMessageQueuePutPending EventID(EventLevelOp, EvtRtxMessageQueueNo, 0x07U) -#define EvtRtxMessageQueuePutTimeout EventID(EventLevelOp, EvtRtxMessageQueueNo, 0x08U) -#define EvtRtxMessageQueueInsertPending EventID(EventLevelOp, EvtRtxMessageQueueNo, 0x09U) -#define EvtRtxMessageQueueInserted EventID(EventLevelOp, EvtRtxMessageQueueNo, 0x0AU) -#define EvtRtxMessageQueueNotInserted EventID(EventLevelOp, EvtRtxMessageQueueNo, 0x0BU) -#define EvtRtxMessageQueueGet EventID(EventLevelAPI, EvtRtxMessageQueueNo, 0x0CU) -#define EvtRtxMessageQueueGetPending EventID(EventLevelOp, EvtRtxMessageQueueNo, 0x0DU) -#define EvtRtxMessageQueueGetTimeout EventID(EventLevelOp, EvtRtxMessageQueueNo, 0x0EU) -#define EvtRtxMessageQueueRetrieved EventID(EventLevelOp, EvtRtxMessageQueueNo, 0x0FU) -#define EvtRtxMessageQueueNotRetrieved EventID(EventLevelOp, EvtRtxMessageQueueNo, 0x10U) -#define EvtRtxMessageQueueGetCapacity EventID(EventLevelAPI, EvtRtxMessageQueueNo, 0x11U) -#define EvtRtxMessageQueueGetMsgSize EventID(EventLevelAPI, EvtRtxMessageQueueNo, 0x12U) -#define EvtRtxMessageQueueGetCount EventID(EventLevelAPI, EvtRtxMessageQueueNo, 0x13U) -#define EvtRtxMessageQueueGetSpace EventID(EventLevelAPI, EvtRtxMessageQueueNo, 0x14U) -#define EvtRtxMessageQueueReset EventID(EventLevelAPI, EvtRtxMessageQueueNo, 0x15U) -#define EvtRtxMessageQueueResetDone EventID(EventLevelOp, EvtRtxMessageQueueNo, 0x16U) -#define EvtRtxMessageQueueDelete EventID(EventLevelAPI, EvtRtxMessageQueueNo, 0x17U) -#define EvtRtxMessageQueueDestroyed EventID(EventLevelOp, EvtRtxMessageQueueNo, 0x18U) - -#endif // RTE_Compiler_EventRecorder - - -// ==== Memory Events ==== - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMORY != 0) && !defined(EVR_RTX_MEMORY_INIT_DISABLE)) -__WEAK void EvrRtxMemoryInit (void *mem, uint32_t size, uint32_t result) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord4(EvtRtxMemoryInit, (uint32_t)mem, size, result, 0U); -#else - (void)mem; - (void)size; - (void)result; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMORY != 0) && !defined(EVR_RTX_MEMORY_ALLOC_DISABLE)) -__WEAK void EvrRtxMemoryAlloc (void *mem, uint32_t size, uint32_t type, void *block) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord4(EvtRtxMemoryAlloc, (uint32_t)mem, size, type, (uint32_t)block); -#else - (void)mem; - (void)size; - (void)type; - (void)block; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMORY != 0) && !defined(EVR_RTX_MEMORY_FREE_DISABLE)) -__WEAK void EvrRtxMemoryFree (void *mem, void *block, uint32_t result) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord4(EvtRtxMemoryFree, (uint32_t)mem, (uint32_t)block, result, 0U); -#else - (void)mem; - (void)block; - (void)result; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMORY != 0) && !defined(EVR_RTX_MEMORY_BLOCK_INIT_DISABLE)) -__WEAK void EvrRtxMemoryBlockInit (osRtxMpInfo_t *mp_info, uint32_t block_count, uint32_t block_size, void *block_mem) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord4(EvtRtxMemoryBlockInit, (uint32_t)mp_info, block_count, block_size, (uint32_t)block_mem); -#else - (void)mp_info; - (void)block_count; - (void)block_size; - (void)block_mem; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMORY != 0) && !defined(EVR_RTX_MEMORY_BLOCK_ALLOC_DISABLE)) -__WEAK void EvrRtxMemoryBlockAlloc (osRtxMpInfo_t *mp_info, void *block) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMemoryBlockAlloc, (uint32_t)mp_info, (uint32_t)block); -#else - (void)mp_info; - (void)block; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMORY != 0) && !defined(EVR_RTX_MEMORY_BLOCK_FREE_DISABLE)) -__WEAK void EvrRtxMemoryBlockFree (osRtxMpInfo_t *mp_info, void *block, int32_t status) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord4(EvtRtxMemoryBlockFree, (uint32_t)mp_info, (uint32_t)block, (uint32_t)status, 0U); -#else - (void)mp_info; - (void)block; - (void)status; -#endif -} -#endif - - -// ==== Kernel Events ==== - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_ERROR_DISABLE)) -__WEAK void EvrRtxKernelError (int32_t status) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxKernelError, (uint32_t)status, 0U); -#else - (void)status; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_INITIALIZE_DISABLE)) -__WEAK void EvrRtxKernelInitialize (void) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxKernelInitialize, 0U, 0U); -#else -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_INITIALIZE_COMPLETED_DISABLE)) -__WEAK void EvrRtxKernelInitializeCompleted (void) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxKernelInitializeCompleted, 0U, 0U); -#else -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_GET_INFO_DISABLE)) -__WEAK void EvrRtxKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord4(EvtRtxKernelGetInfo, (uint32_t)version, (uint32_t)id_buf, id_size, 0U); -#else - (void)version; - (void)id_buf; - (void)id_size; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_INFO_RETRIEVED_DISABLE)) -__WEAK void EvrRtxKernelInfoRetrieved (osVersion_t *version, char *id_buf) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxKernelInfoRetrieved, (uint32_t)version, (uint32_t)id_buf); - if (id_buf != NULL) { - EventRecordData(EvtRtxKernelInfoRetrieved_Detail, id_buf, strlen(id_buf)); - } -#else - (void)version; - (void)id_buf; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_GET_STATE_DISABLE)) -__WEAK void EvrRtxKernelGetState (osKernelState_t state) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxKernelGetState, (uint32_t)state, 0U); -#else - (void)state; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_START_DISABLE)) -__WEAK void EvrRtxKernelStart (void) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxKernelStart, 0U, 0U); -#else -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_STARTED_DISABLE)) -__WEAK void EvrRtxKernelStarted (void) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxKernelStarted, 0U, 0U); -#else -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_LOCK_DISABLE)) -__WEAK void EvrRtxKernelLock (void) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxKernelLock, 0U, 0U); -#else -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_LOCKED_DISABLE)) -__WEAK void EvrRtxKernelLocked (int32_t lock) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxKernelLocked, (uint32_t)lock, 0U); -#else - (void)lock; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_UNLOCK_DISABLE)) -__WEAK void EvrRtxKernelUnlock (void) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxKernelUnlock, 0U, 0U); -#else -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_UNLOCKED_DISABLE)) -__WEAK void EvrRtxKernelUnlocked (int32_t lock) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxKernelUnlocked, (uint32_t)lock, 0U); -#else - (void)lock; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_RESTORE_LOCK_DISABLE)) -__WEAK void EvrRtxKernelRestoreLock (int32_t lock) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxKernelRestoreLock, (uint32_t)lock, 0U); -#else - (void)lock; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_LOCK_RESTORED_DISABLE)) -__WEAK void EvrRtxKernelLockRestored (int32_t lock) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxKernelLockRestored, (uint32_t)lock, 0U); -#else - (void)lock; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_SUSPEND_DISABLE)) -__WEAK void EvrRtxKernelSuspend (void) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxKernelSuspend, 0U, 0U); -#else -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_SUSPENDED_DISABLE)) -__WEAK void EvrRtxKernelSuspended (uint32_t sleep_ticks) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxKernelSuspended, sleep_ticks, 0U); -#else - (void)sleep_ticks; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_RESUME_DISABLE)) -__WEAK void EvrRtxKernelResume (uint32_t sleep_ticks) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxKernelResume, sleep_ticks, 0U); -#else - (void)sleep_ticks; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_RESUMED_DISABLE)) -__WEAK void EvrRtxKernelResumed (void) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxKernelResumed, 0U, 0U); -#else -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_GET_TICK_COUNT_DISABLE)) -__WEAK void EvrRtxKernelGetTickCount (uint64_t count) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxKernelGetTickCount, (uint32_t)count, (uint32_t)(count>>32)); -#else - (void)count; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_GET_TICK_FREQ_DISABLE)) -__WEAK void EvrRtxKernelGetTickFreq (uint32_t freq) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxKernelGetTickFreq, freq, 0U); -#else - (void)freq; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_GET_SYS_TIMER_COUNT_DISABLE)) -__WEAK void EvrRtxKernelGetSysTimerCount (uint32_t count) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxKernelGetSysTimerCount, count, 0U); -#else - (void)count; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_GET_SYS_TIMER_FREQ_DISABLE)) -__WEAK void EvrRtxKernelGetSysTimerFreq (uint32_t freq) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxKernelGetSysTimerFreq, freq, 0U); -#else - (void)freq; -#endif -} -#endif - - -// ==== Thread Events ==== - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_ERROR_DISABLE)) -__WEAK void EvrRtxThreadError (osThreadId_t thread_id, int32_t status) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadError, (uint32_t)thread_id, (uint32_t)status); -#else - (void)thread_id; - (void)status; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_NEW_DISABLE)) -__WEAK void EvrRtxThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord4(EvtRtxThreadNew, (uint32_t)func, (uint32_t)argument, (uint32_t)attr, 0U); - if (attr != NULL) { - EventRecordData(EvtRtxThreadNew_Detail, attr, sizeof (osThreadAttr_t)); - } -#else - (void)func; - (void)argument; - (void)attr; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_CREATED_DISABLE)) -__WEAK void EvrRtxThreadCreated (osThreadId_t thread_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadCreated, (uint32_t)thread_id, 0U); -#else - (void)thread_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_NAME_DISABLE)) -__WEAK void EvrRtxThreadGetName (osThreadId_t thread_id, const char *name) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadGetName, (uint32_t)thread_id, (uint32_t)name); - if (name != NULL) { - EventRecordData(EvtRtxThreadGetName_Detail, name, strlen(name)); - } -#else - (void)thread_id; - (void)name; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_ID_DISABLE)) -__WEAK void EvrRtxThreadGetId (osThreadId_t thread_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadGetId, (uint32_t)thread_id, 0U); -#else - (void)thread_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_STATE_DISABLE)) -__WEAK void EvrRtxThreadGetState (osThreadId_t thread_id, osThreadState_t state) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadGetState, (uint32_t)thread_id, (uint32_t)state); -#else - (void)thread_id; - (void)state; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_STACK_SIZE_DISABLE)) -__WEAK void EvrRtxThreadGetStackSize (osThreadId_t thread_id, uint32_t stack_size) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadGetStackSize, (uint32_t)thread_id, stack_size); -#else - (void)thread_id; - (void)stack_size; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_STACK_SPACE_DISABLE)) -__WEAK void EvrRtxThreadGetStackSpace (osThreadId_t thread_id, uint32_t stack_space) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadGetStackSpace, (uint32_t)thread_id, stack_space); -#else - (void)thread_id; - (void)stack_space; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_SET_PRIORITY_DISABLE)) -__WEAK void EvrRtxThreadSetPriority (osThreadId_t thread_id, osPriority_t priority) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadSetPriority, (uint32_t)thread_id, (uint32_t)priority); -#else - (void)thread_id; - (void)priority; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_PRIORITY_DISABLE)) -__WEAK void EvrRtxThreadGetPriority (osThreadId_t thread_id, osPriority_t priority) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadGetPriority, (uint32_t)thread_id, (uint32_t)priority); -#else - (void)thread_id; - (void)priority; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_YIELD_DISABLE)) -__WEAK void EvrRtxThreadYield (void) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadYield, 0U, 0U); -#else -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_SUSPEND_DISABLE)) -__WEAK void EvrRtxThreadSuspend (osThreadId_t thread_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadSuspend, (uint32_t)thread_id, 0U); -#else - (void)thread_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_SUSPENDED_DISABLE)) -__WEAK void EvrRtxThreadSuspended (osThreadId_t thread_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadSuspended, (uint32_t)thread_id, 0U); -#else - (void)thread_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_RESUME_DISABLE)) -__WEAK void EvrRtxThreadResume (osThreadId_t thread_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadResume, (uint32_t)thread_id, 0U); -#else - (void)thread_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_RESUMED_DISABLE)) -__WEAK void EvrRtxThreadResumed (osThreadId_t thread_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadResumed, (uint32_t)thread_id, 0U); -#else - (void)thread_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_DETACH_DISABLE)) -__WEAK void EvrRtxThreadDetach (osThreadId_t thread_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadDetach, (uint32_t)thread_id, 0U); -#else - (void)thread_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_DETACHED_DISABLE)) -__WEAK void EvrRtxThreadDetached (osThreadId_t thread_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadDetached, (uint32_t)thread_id, 0U); -#else - (void)thread_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_JOIN_DISABLE)) -__WEAK void EvrRtxThreadJoin (osThreadId_t thread_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadJoin, (uint32_t)thread_id, 0U); -#else - (void)thread_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_JOIN_PENDING_DISABLE)) -__WEAK void EvrRtxThreadJoinPending (osThreadId_t thread_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadJoinPending, (uint32_t)thread_id, 0U); -#else - (void)thread_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_JOINED_DISABLE)) -__WEAK void EvrRtxThreadJoined (osThreadId_t thread_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadJoined, (uint32_t)thread_id, 0U); -#else - (void)thread_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_BLOCKED_DISABLE)) -__WEAK void EvrRtxThreadBlocked (osThreadId_t thread_id, uint32_t timeout) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadBlocked, (uint32_t)thread_id, timeout); -#else - (void)thread_id; - (void)timeout; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_UNBLOCKED_DISABLE)) -__WEAK void EvrRtxThreadUnblocked (osThreadId_t thread_id, uint32_t ret_val) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadUnblocked, (uint32_t)thread_id, ret_val); -#else - (void)thread_id; - (void)ret_val; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_SWITCH_DISABLE)) -__WEAK void EvrRtxThreadSwitch (osThreadId_t thread_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadSwitch, (uint32_t)thread_id, 0U); -#else - (void)thread_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_EXIT_DISABLE)) -__WEAK void EvrRtxThreadExit (void) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadExit, 0U, 0U); -#else -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_TERMINATE_DISABLE)) -__WEAK void EvrRtxThreadTerminate (osThreadId_t thread_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadTerminate, (uint32_t)thread_id, 0U); -#else - (void)thread_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_DESTROYED_DISABLE)) -__WEAK void EvrRtxThreadDestroyed (osThreadId_t thread_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadDestroyed, (uint32_t)thread_id, 0U); -#else - (void)thread_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_COUNT_DISABLE)) -__WEAK void EvrRtxThreadGetCount (uint32_t count) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadGetCount, count, 0U); -#else - (void)count; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_ENUMERATE_DISABLE)) -__WEAK void EvrRtxThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items, uint32_t count) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord4(EvtRtxThreadEnumerate, (uint32_t)thread_array, array_items, count, 0U); -#else - (void)thread_array; - (void)array_items; - (void)count; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_SET_DISABLE)) -__WEAK void EvrRtxThreadFlagsSet (osThreadId_t thread_id, uint32_t flags) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadFlagsSet, (uint32_t)thread_id, flags); -#else - (void)thread_id; - (void)flags; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_SET_DONE_DISABLE)) -__WEAK void EvrRtxThreadFlagsSetDone (osThreadId_t thread_id, uint32_t thread_flags) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadFlagsSetDone, (uint32_t)thread_id, thread_flags); -#else - (void)thread_id; - (void)thread_flags; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_CLEAR_DISABLE)) -__WEAK void EvrRtxThreadFlagsClear (uint32_t flags) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadFlagsClear, flags, 0U); -#else - (void)flags; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_CLEAR_DONE_DISABLE)) -__WEAK void EvrRtxThreadFlagsClearDone (uint32_t thread_flags) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadFlagsClearDone, thread_flags, 0U); -#else - (void)thread_flags; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_GET_DISABLE)) -__WEAK void EvrRtxThreadFlagsGet (uint32_t thread_flags) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadFlagsGet, thread_flags, 0U); -#else - (void)thread_flags; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_WAIT_DISABLE)) -__WEAK void EvrRtxThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord4(EvtRtxThreadFlagsWait, flags, options, timeout, 0U); -#else - (void)flags; - (void)options; - (void)timeout; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_WAIT_PENDING_DISABLE)) -__WEAK void EvrRtxThreadFlagsWaitPending (uint32_t flags, uint32_t options, uint32_t timeout) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord4(EvtRtxThreadFlagsWaitPending, flags, options, timeout, 0U); -#else - (void)flags; - (void)options; - (void)timeout; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_WAIT_TIMEOUT_DISABLE)) -__WEAK void EvrRtxThreadFlagsWaitTimeout (void) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadFlagsWaitTimeout, 0U, 0U); -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_WAIT_COMPLETED_DISABLE)) -__WEAK void EvrRtxThreadFlagsWaitCompleted (uint32_t flags, uint32_t options, uint32_t thread_flags) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord4(EvtRtxThreadFlagsWaitCompleted, flags, options, thread_flags, 0U); -#else - (void)flags; - (void)options; - (void)thread_flags; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_WAIT_NOT_COMPLETED_DISABLE)) -__WEAK void EvrRtxThreadFlagsWaitNotCompleted (uint32_t flags, uint32_t options) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadFlagsWaitNotCompleted, flags, options); -#else - (void)flags; - (void)options; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_DELAY_DISABLE)) -__WEAK void EvrRtxThreadDelay (uint32_t ticks) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadDelay, ticks, 0U); -#else - (void)ticks; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_DELAY_UNTIL_DISABLE)) -__WEAK void EvrRtxThreadDelayUntil (uint64_t ticks) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadDelayUntil, (uint32_t)ticks, (uint32_t)(ticks >> 32)); -#else - (void)ticks; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_DELAY_COMPLETED_DISABLE)) -__WEAK void EvrRtxThreadDelayCompleted (void) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxThreadDelayCompleted, 0U, 0U); -#endif -} -#endif - - -// ==== Timer Events ==== - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_ERROR_DISABLE)) -__WEAK void EvrRtxTimerError (osTimerId_t timer_id, int32_t status) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxTimerError, (uint32_t)timer_id, (uint32_t)status); -#else - (void)timer_id; - (void)status; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_CALLBACK_DISABLE)) -__WEAK void EvrRtxTimerCallback (osTimerFunc_t func, void *argument) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxTimerCallback, (uint32_t)func, (uint32_t)argument); -#else - (void)func; - (void)argument; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_NEW_DISABLE)) -__WEAK void EvrRtxTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord4(EvtRtxTimerNew, (uint32_t)func, (uint32_t)type, (uint32_t)argument, (uint32_t)attr); - if (attr != NULL) { - EventRecordData(EvtRtxTimerNew_Detail, attr, sizeof (osTimerAttr_t)); - } -#else - (void)func; - (void)type; - (void)argument; - (void)attr; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_CREATED_DISABLE)) -__WEAK void EvrRtxTimerCreated (osTimerId_t timer_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxTimerCreated, (uint32_t)timer_id, 0U); -#else - (void)timer_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_GET_NAME_DISABLE)) -__WEAK void EvrRtxTimerGetName (osTimerId_t timer_id, const char *name) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxTimerGetName, (uint32_t)timer_id, (uint32_t)name); - if (name != NULL) { - EventRecordData(EvtRtxTimerGetName_Detail, name, strlen(name)); - } -#else - (void)timer_id; - (void)name; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_START_DISABLE)) -__WEAK void EvrRtxTimerStart (osTimerId_t timer_id, uint32_t ticks) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxTimerStart, (uint32_t)timer_id, ticks); -#else - (void)timer_id; - (void)ticks; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_STARTED_DISABLE)) -__WEAK void EvrRtxTimerStarted (osTimerId_t timer_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxTimerStarted, (uint32_t)timer_id, 0U); -#else - (void)timer_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_STOP_DISABLE)) -__WEAK void EvrRtxTimerStop (osTimerId_t timer_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxTimerStop, (uint32_t)timer_id, 0U); -#else - (void)timer_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_STOPPED_DISABLE)) -__WEAK void EvrRtxTimerStopped (osTimerId_t timer_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxTimerStopped, (uint32_t)timer_id, 0U); -#else - (void)timer_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_IS_RUNNING_DISABLE)) -__WEAK void EvrRtxTimerIsRunning (osTimerId_t timer_id, uint32_t running) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxTimerIsRunning, (uint32_t)timer_id, running); -#else - (void)timer_id; - (void)running; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_DELETE_DISABLE)) -__WEAK void EvrRtxTimerDelete (osTimerId_t timer_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxTimerDelete, (uint32_t)timer_id, 0U); -#else - (void)timer_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_DESTROYED_DISABLE)) -__WEAK void EvrRtxTimerDestroyed (osTimerId_t timer_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxTimerDestroyed, (uint32_t)timer_id, 0U); -#else - (void)timer_id; -#endif -} -#endif - - -// ==== Event Flags Events ==== - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_ERROR_DISABLE)) -__WEAK void EvrRtxEventFlagsError (osEventFlagsId_t ef_id, int32_t status) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxEventFlagsError, (uint32_t)ef_id, (uint32_t)status); -#else - (void)ef_id; - (void)status; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_NEW_DISABLE)) -__WEAK void EvrRtxEventFlagsNew (const osEventFlagsAttr_t *attr) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxEventFlagsNew, (uint32_t)attr, 0U); - if (attr != NULL) { - EventRecordData(EvtRtxEventFlagsNew_Detail, attr, sizeof (osEventFlagsAttr_t)); - } -#else - (void)attr; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_CREATED_DISABLE)) -__WEAK void EvrRtxEventFlagsCreated (osEventFlagsId_t ef_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxEventFlagsCreated, (uint32_t)ef_id, 0U); -#else - (void)ef_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_GET_NAME_DISABLE)) -__WEAK void EvrRtxEventFlagsGetName (osEventFlagsId_t ef_id, const char *name) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxEventFlagsGetName, (uint32_t)ef_id, (uint32_t)name); - if (name != NULL) { - EventRecordData(EvtRtxEventFlagsGetName_Detail, name, strlen(name)); - } -#else - (void)ef_id; - (void)name; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_SET_DISABLE)) -__WEAK void EvrRtxEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxEventFlagsSet, (uint32_t)ef_id, flags); -#else - (void)ef_id; - (void)flags; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_SET_DONE_DISABLE)) -__WEAK void EvrRtxEventFlagsSetDone (osEventFlagsId_t ef_id, uint32_t event_flags) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxEventFlagsSetDone, (uint32_t)ef_id, event_flags); -#else - (void)ef_id; - (void)event_flags; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_CLEAR_DISABLE)) -__WEAK void EvrRtxEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxEventFlagsClear, (uint32_t)ef_id, flags); -#else - (void)ef_id; - (void)flags; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_CLEAR_DONE_DISABLE)) -__WEAK void EvrRtxEventFlagsClearDone (osEventFlagsId_t ef_id, uint32_t event_flags) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxEventFlagsClearDone, (uint32_t)ef_id, event_flags); -#else - (void)ef_id; - (void)event_flags; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_GET_DISABLE)) -__WEAK void EvrRtxEventFlagsGet (osEventFlagsId_t ef_id, uint32_t event_flags) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxEventFlagsGet, (uint32_t)ef_id, event_flags); -#else - (void)ef_id; - (void)event_flags; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_WAIT_DISABLE)) -__WEAK void EvrRtxEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord4(EvtRtxEventFlagsWait, (uint32_t)ef_id, flags, options, timeout); -#else - (void)ef_id; - (void)flags; - (void)options; - (void)timeout; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_WAIT_PENDING_DISABLE)) -__WEAK void EvrRtxEventFlagsWaitPending (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord4(EvtRtxEventFlagsWaitPending, (uint32_t)ef_id, flags, options, timeout); -#else - (void)ef_id; - (void)flags; - (void)options; - (void)timeout; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_WAIT_TIMEOUT_DISABLE)) -__WEAK void EvrRtxEventFlagsWaitTimeout (osEventFlagsId_t ef_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxEventFlagsWaitTimeout, (uint32_t)ef_id, 0U); -#else - (void)ef_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_WAIT_COMPLETED_DISABLE)) -__WEAK void EvrRtxEventFlagsWaitCompleted (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t event_flags) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord4(EvtRtxEventFlagsWaitCompleted, (uint32_t)ef_id, flags, options, event_flags); -#else - (void)ef_id; - (void)flags; - (void)options; - (void)event_flags; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_WAIT_NOT_COMPLETED_DISABLE)) -__WEAK void EvrRtxEventFlagsWaitNotCompleted (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord4(EvtRtxEventFlagsWaitNotCompleted, (uint32_t)ef_id, flags, options, 0U); -#else - (void)ef_id; - (void)flags; - (void)options; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_DELETE_DISABLE)) -__WEAK void EvrRtxEventFlagsDelete (osEventFlagsId_t ef_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxEventFlagsDelete, (uint32_t)ef_id, 0U); -#else - (void)ef_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_DESTROYED_DISABLE)) -__WEAK void EvrRtxEventFlagsDestroyed (osEventFlagsId_t ef_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxEventFlagsDestroyed, (uint32_t)ef_id, 0U); -#else - (void)ef_id; -#endif -} -#endif - - -// ==== Mutex Events ==== - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_ERROR_DISABLE)) -__WEAK void EvrRtxMutexError (osMutexId_t mutex_id, int32_t status) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMutexError, (uint32_t)mutex_id, (uint32_t)status); -#else - (void)mutex_id; - (void)status; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_NEW_DISABLE)) -__WEAK void EvrRtxMutexNew (const osMutexAttr_t *attr) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMutexNew, (uint32_t)attr, 0U); - if (attr != NULL) { - EventRecordData(EvtRtxMutexNew_Detail, attr, sizeof (osMutexAttr_t)); - } -#else - (void)attr; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_CREATED_DISABLE)) -__WEAK void EvrRtxMutexCreated (osMutexId_t mutex_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMutexCreated, (uint32_t)mutex_id, 0U); -#else - (void)mutex_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_GET_NAME_DISABLE)) -__WEAK void EvrRtxMutexGetName (osMutexId_t mutex_id, const char *name) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMutexGetName, (uint32_t)mutex_id, (uint32_t)name); - if (name != NULL) { - EventRecordData(EvtRtxMutexGetName_Detail, name, strlen(name)); - } -#else - (void)mutex_id; - (void)name; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_ACQUIRE_DISABLE)) -__WEAK void EvrRtxMutexAcquire (osMutexId_t mutex_id, uint32_t timeout) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMutexAcquire, (uint32_t)mutex_id, timeout); -#else - (void)mutex_id; - (void)timeout; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_ACQUIRE_PENDING_DISABLE)) -__WEAK void EvrRtxMutexAcquirePending (osMutexId_t mutex_id, uint32_t timeout) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMutexAcquirePending, (uint32_t)mutex_id, timeout); -#else - (void)mutex_id; - (void)timeout; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_ACQUIRE_TIMEOUT_DISABLE)) -__WEAK void EvrRtxMutexAcquireTimeout (osMutexId_t mutex_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMutexAcquireTimeout, (uint32_t)mutex_id, 0U); -#else - (void)mutex_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_ACQUIRED_DISABLE)) -__WEAK void EvrRtxMutexAcquired (osMutexId_t mutex_id, uint32_t lock) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMutexAcquired, (uint32_t)mutex_id, lock); -#else - (void)mutex_id; - (void)lock; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_NOT_ACQUIRED_DISABLE)) -__WEAK void EvrRtxMutexNotAcquired (osMutexId_t mutex_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMutexNotAcquired, (uint32_t)mutex_id, 0U); -#else - (void)mutex_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_RELEASE_DISABLE)) -__WEAK void EvrRtxMutexRelease (osMutexId_t mutex_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMutexRelease, (uint32_t)mutex_id, 0U); -#else - (void)mutex_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_RELEASED_DISABLE)) -__WEAK void EvrRtxMutexReleased (osMutexId_t mutex_id, uint32_t lock) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMutexReleased, (uint32_t)mutex_id, lock); -#else - (void)mutex_id; - (void)lock; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_GET_OWNER_DISABLE)) -__WEAK void EvrRtxMutexGetOwner (osMutexId_t mutex_id, osThreadId_t thread_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMutexGetOwner, (uint32_t)mutex_id, (uint32_t)thread_id); -#else - (void)mutex_id; - (void)thread_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_DELETE_DISABLE)) -__WEAK void EvrRtxMutexDelete (osMutexId_t mutex_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMutexDelete, (uint32_t)mutex_id, 0U); -#else - (void)mutex_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_DESTROYED_DISABLE)) -__WEAK void EvrRtxMutexDestroyed (osMutexId_t mutex_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMutexDestroyed, (uint32_t)mutex_id, 0U); -#else - (void)mutex_id; -#endif -} -#endif - - -// ==== Semaphore Events ==== - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_ERROR_DISABLE)) -__WEAK void EvrRtxSemaphoreError (osSemaphoreId_t semaphore_id, int32_t status) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxSemaphoreError, (uint32_t)semaphore_id, (uint32_t)status); -#else - (void)semaphore_id; - (void)status; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_NEW_DISABLE)) -__WEAK void EvrRtxSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord4(EvtRtxSemaphoreNew, max_count, initial_count, (uint32_t)attr, 0U); - if (attr != NULL) { - EventRecordData(EvtRtxSemaphoreNew_Detail, attr, sizeof (osSemaphoreAttr_t)); - } -#else - (void)max_count; - (void)initial_count; - (void)attr; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_CREATED_DISABLE)) -__WEAK void EvrRtxSemaphoreCreated (osSemaphoreId_t semaphore_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxSemaphoreCreated, (uint32_t)semaphore_id, 0U); -#else - (void)semaphore_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_GET_NAME_DISABLE)) -__WEAK void EvrRtxSemaphoreGetName (osSemaphoreId_t semaphore_id, const char *name) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxSemaphoreGetName, (uint32_t)semaphore_id, (uint32_t)name); - if (name != NULL) { - EventRecordData(EvtRtxSemaphoreGetName_Detail, name, strlen(name)); - } -#else -#endif - (void)semaphore_id; - (void)name; -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_ACQUIRE_DISABLE)) -__WEAK void EvrRtxSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxSemaphoreAcquire, (uint32_t)semaphore_id, timeout); -#else - (void)semaphore_id; - (void)timeout; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_ACQUIRE_PENDING_DISABLE)) -__WEAK void EvrRtxSemaphoreAcquirePending (osSemaphoreId_t semaphore_id, uint32_t timeout) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxSemaphoreAcquirePending, (uint32_t)semaphore_id, (uint32_t)timeout); -#else - (void)semaphore_id; - (void)timeout; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_ACQUIRE_TIMEOUT_DISABLE)) -__WEAK void EvrRtxSemaphoreAcquireTimeout (osSemaphoreId_t semaphore_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxSemaphoreAcquireTimeout, (uint32_t)semaphore_id, 0U); -#else - (void)semaphore_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_ACQUIRED_DISABLE)) -__WEAK void EvrRtxSemaphoreAcquired (osSemaphoreId_t semaphore_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxSemaphoreAcquired, (uint32_t)semaphore_id, 0U); -#else - (void)semaphore_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_NOT_ACQUIRED_DISABLE)) -__WEAK void EvrRtxSemaphoreNotAcquired (osSemaphoreId_t semaphore_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxSemaphoreNotAcquired, (uint32_t)semaphore_id, 0U); -#else - (void)semaphore_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_RELEASE_DISABLE)) -__WEAK void EvrRtxSemaphoreRelease (osSemaphoreId_t semaphore_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxSemaphoreRelease, (uint32_t)semaphore_id, 0U); -#else - (void)semaphore_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_RELEASED_DISABLE)) -__WEAK void EvrRtxSemaphoreReleased (osSemaphoreId_t semaphore_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxSemaphoreReleased, (uint32_t)semaphore_id, 0U); -#else - (void)semaphore_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_GET_COUNT_DISABLE)) -__WEAK void EvrRtxSemaphoreGetCount (osSemaphoreId_t semaphore_id, uint32_t count) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxSemaphoreGetCount, (uint32_t)semaphore_id, count); -#else - (void)semaphore_id; - (void)count; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_DELETE_DISABLE)) -__WEAK void EvrRtxSemaphoreDelete (osSemaphoreId_t semaphore_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxSemaphoreDelete, (uint32_t)semaphore_id, 0U); -#else - (void)semaphore_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_DESTROYED_DISABLE)) -__WEAK void EvrRtxSemaphoreDestroyed (osSemaphoreId_t semaphore_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxSemaphoreDestroyed, (uint32_t)semaphore_id, 0U); -#else - (void)semaphore_id; -#endif -} -#endif - - -// ==== Memory Pool Events ==== - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_ERROR_DISABLE)) -__WEAK void EvrRtxMemoryPoolError (osMemoryPoolId_t mp_id, int32_t status) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMemoryPoolError, (uint32_t)mp_id, (uint32_t)status); -#else - (void)mp_id; - (void)status; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_NEW_DISABLE)) -__WEAK void EvrRtxMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord4(EvtRtxMemoryPoolNew, block_count, block_size, (uint32_t)attr, 0U); - if (attr != NULL) { - EventRecordData(EvtRtxMemoryPoolNew_Detail, attr, sizeof (osMemoryPoolAttr_t)); - } -#else - (void)block_count; - (void)block_size; - (void)attr; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_CREATED_DISABLE)) -__WEAK void EvrRtxMemoryPoolCreated (osMemoryPoolId_t mp_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMemoryPoolCreated, (uint32_t)mp_id, 0U); -#else - (void)mp_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_GET_NAME_DISABLE)) -__WEAK void EvrRtxMemoryPoolGetName (osMemoryPoolId_t mp_id, const char *name) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMemoryPoolGetName, (uint32_t)mp_id, (uint32_t)name); - if (name != NULL) { - EventRecordData(EvtRtxMemoryPoolGetName_Detail, name, strlen(name)); - } -#else - (void)mp_id; - (void)name; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_ALLOC_DISABLE)) -__WEAK void EvrRtxMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMemoryPoolAlloc, (uint32_t)mp_id, timeout); -#else - (void)mp_id; - (void)timeout; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_ALLOC_PENDING_DISABLE)) -__WEAK void EvrRtxMemoryPoolAllocPending (osMemoryPoolId_t mp_id, uint32_t timeout) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMemoryPoolAllocPending, (uint32_t)mp_id, timeout); -#else - (void)mp_id; - (void)timeout; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_ALLOC_TIMEOUT_DISABLE)) -__WEAK void EvrRtxMemoryPoolAllocTimeout (osMemoryPoolId_t mp_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMemoryPoolAllocTimeout, (uint32_t)mp_id, 0U); -#else - (void)mp_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_ALLOCATED_DISABLE)) -__WEAK void EvrRtxMemoryPoolAllocated (osMemoryPoolId_t mp_id, void *block) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMemoryPoolAllocated, (uint32_t)mp_id, (uint32_t)block); -#else - (void)mp_id; - (void)block; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_ALLOC_FAILED_DISABLE)) -__WEAK void EvrRtxMemoryPoolAllocFailed (osMemoryPoolId_t mp_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMemoryPoolAllocFailed, (uint32_t)mp_id, 0U); -#else - (void)mp_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_FREE_DISABLE)) -__WEAK void EvrRtxMemoryPoolFree (osMemoryPoolId_t mp_id, void *block) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMemoryPoolFree, (uint32_t)mp_id, (uint32_t)block); -#else - (void)mp_id; - (void)block; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_DEALLOCATED_DISABLE)) -__WEAK void EvrRtxMemoryPoolDeallocated (osMemoryPoolId_t mp_id, void *block) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMemoryPoolDeallocated, (uint32_t)mp_id, (uint32_t)block); -#else - (void)mp_id; - (void)block; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_FREE_FAILED_DISABLE)) -__WEAK void EvrRtxMemoryPoolFreeFailed (osMemoryPoolId_t mp_id, void *block) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMemoryPoolFreeFailed, (uint32_t)mp_id, (uint32_t)block); -#else - (void)mp_id; - (void)block; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_GET_CAPACITY_DISABLE)) -__WEAK void EvrRtxMemoryPoolGetCapacity (osMemoryPoolId_t mp_id, uint32_t capacity) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMemoryPoolGetCapacity, (uint32_t)mp_id, capacity); -#else - (void)mp_id; - (void)capacity; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_GET_BLOCK_SZIE_DISABLE)) -__WEAK void EvrRtxMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id, uint32_t block_size) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMemoryPoolGetBlockSize, (uint32_t)mp_id, block_size); -#else - (void)mp_id; - (void)block_size; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_GET_COUNT_DISABLE)) -__WEAK void EvrRtxMemoryPoolGetCount (osMemoryPoolId_t mp_id, uint32_t count) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMemoryPoolGetCount, (uint32_t)mp_id, count); -#else - (void)mp_id; - (void)count; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_GET_SPACE_DISABLE)) -__WEAK void EvrRtxMemoryPoolGetSpace (osMemoryPoolId_t mp_id, uint32_t space) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMemoryPoolGetSpace, (uint32_t)mp_id, space); -#else - (void)mp_id; - (void)space; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_DELETE_DISABLE)) -__WEAK void EvrRtxMemoryPoolDelete (osMemoryPoolId_t mp_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMemoryPoolDelete, (uint32_t)mp_id, 0U); -#else - (void)mp_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_DESTROYED_DISABLE)) -__WEAK void EvrRtxMemoryPoolDestroyed (osMemoryPoolId_t mp_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMemoryPoolDestroyed, (uint32_t)mp_id, 0U); -#else - (void)mp_id; -#endif -} -#endif - - -// ==== Message Queue Events ==== - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_ERROR_DISABLE)) -__WEAK void EvrRtxMessageQueueError (osMessageQueueId_t mq_id, int32_t status) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2 (EvtRtxMessageQueueError, (uint32_t)mq_id, (uint32_t)status); -#else - (void)mq_id; - (void)status; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_NEW_DISABLE)) -__WEAK void EvrRtxMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord4(EvtRtxMessageQueueNew, msg_count, msg_size, (uint32_t)attr, 0U); - if (attr != NULL) { - EventRecordData(EvtRtxMessageQueueNew_Detail, attr, sizeof (osMemoryPoolAttr_t)); - } -#else - (void)msg_count; - (void)msg_size; - (void)attr; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_CREATED_DISABLE)) -__WEAK void EvrRtxMessageQueueCreated (osMessageQueueId_t mq_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMessageQueueCreated, (uint32_t)mq_id, 0U); -#else - (void)mq_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_NAME_DISABLE)) -__WEAK void EvrRtxMessageQueueGetName (osMessageQueueId_t mq_id, const char *name) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMessageQueueGetName, (uint32_t)mq_id, (uint32_t)name); - if (name != NULL) { - EventRecordData(EvtRtxMessageQueueGetName_Detail, name, strlen(name)); - } -#else - (void)mq_id; - (void)name; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_PUT_DISABLE)) -__WEAK void EvrRtxMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord4(EvtRtxMessageQueuePut, (uint32_t)mq_id, (uint32_t)msg_ptr, (uint32_t)msg_prio, timeout); -#else - (void)mq_id; - (void)msg_ptr; - (void)msg_prio; - (void)timeout; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_PUT_PENDING_DISABLE)) -__WEAK void EvrRtxMessageQueuePutPending (osMessageQueueId_t mq_id, const void *msg_ptr, uint32_t timeout) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord4(EvtRtxMessageQueuePutPending, (uint32_t)mq_id, (uint32_t)msg_ptr, timeout, 0U); -#else - (void)mq_id; - (void)msg_ptr; - (void)timeout; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_PUT_TIMEOUT_DISABLE)) -__WEAK void EvrRtxMessageQueuePutTimeout (osMessageQueueId_t mq_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMessageQueuePutTimeout, (uint32_t)mq_id, 0U); -#else - (void)mq_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_INSERT_PENDING_DISABLE)) -__WEAK void EvrRtxMessageQueueInsertPending (osMessageQueueId_t mq_id, const void *msg_ptr) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMessageQueueInsertPending, (uint32_t)mq_id, (uint32_t)msg_ptr); -#else - (void)mq_id; - (void)msg_ptr; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_INSERTED_DISABLE)) -__WEAK void EvrRtxMessageQueueInserted (osMessageQueueId_t mq_id, const void *msg_ptr) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMessageQueueInserted, (uint32_t)mq_id, (uint32_t)msg_ptr); -#else - (void)mq_id; - (void)msg_ptr; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_NOT_INSERTED_DISABLE)) -__WEAK void EvrRtxMessageQueueNotInserted (osMessageQueueId_t mq_id, const void *msg_ptr) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMessageQueueNotInserted, (uint32_t)mq_id, (uint32_t)msg_ptr); -#else - (void)mq_id; - (void)msg_ptr; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_DISABLE)) -__WEAK void EvrRtxMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord4(EvtRtxMessageQueueGet, (uint32_t)mq_id, (uint32_t)msg_ptr, (uint32_t)msg_prio, timeout); -#else - (void)mq_id; - (void)msg_ptr; - (void)msg_prio; - (void)timeout; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_PENDING_DISABLE)) -__WEAK void EvrRtxMessageQueueGetPending (osMessageQueueId_t mq_id, void *msg_ptr, uint32_t timeout) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord4(EvtRtxMessageQueueGetPending, (uint32_t)mq_id, (uint32_t)msg_ptr, timeout, 0U); -#else - (void)mq_id; - (void)msg_ptr; - (void)timeout; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_TIMEOUT_DISABLE)) -__WEAK void EvrRtxMessageQueueGetTimeout (osMessageQueueId_t mq_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMessageQueueGetTimeout, (uint32_t)mq_id, 0U); -#else - (void)mq_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_RETRIEVED_DISABLE)) -__WEAK void EvrRtxMessageQueueRetrieved (osMessageQueueId_t mq_id, void *msg_ptr) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMessageQueueRetrieved, (uint32_t)mq_id, (uint32_t)msg_ptr); -#else - (void)mq_id; - (void)msg_ptr; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_NOT_RETRIEVED_DISABLE)) -__WEAK void EvrRtxMessageQueueNotRetrieved (osMessageQueueId_t mq_id, void *msg_ptr) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMessageQueueNotRetrieved, (uint32_t)mq_id, (uint32_t)msg_ptr); -#else - (void)mq_id; - (void)msg_ptr; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_CAPACITY_DISABLE)) -__WEAK void EvrRtxMessageQueueGetCapacity (osMessageQueueId_t mq_id, uint32_t capacity) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMessageQueueGetCapacity, (uint32_t)mq_id, capacity); -#else - (void)mq_id; - (void)capacity; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_MSG_SIZE_DISABLE)) -__WEAK void EvrRtxMessageQueueGetMsgSize (osMessageQueueId_t mq_id, uint32_t msg_size) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMessageQueueGetMsgSize, (uint32_t)mq_id, msg_size); -#else - (void)mq_id; - (void)msg_size; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_COUNT_DISABLE)) -__WEAK void EvrRtxMessageQueueGetCount (osMessageQueueId_t mq_id, uint32_t count) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMessageQueueGetCount, (uint32_t)mq_id, count); -#else - (void)mq_id; - (void)count; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_SPACE_DISABLE)) -__WEAK void EvrRtxMessageQueueGetSpace (osMessageQueueId_t mq_id, uint32_t space) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMessageQueueGetSpace, (uint32_t)mq_id, space); -#else - (void)mq_id; - (void)space; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_RESET_DISABLE)) -__WEAK void EvrRtxMessageQueueReset (osMessageQueueId_t mq_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMessageQueueReset, (uint32_t)mq_id, 0U); -#else - (void)mq_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_RESET_DONE_DISABLE)) -__WEAK void EvrRtxMessageQueueResetDone (osMessageQueueId_t mq_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMessageQueueResetDone, (uint32_t)mq_id, 0U); -#else - (void)mq_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_DELETE_DISABLE)) -__WEAK void EvrRtxMessageQueueDelete (osMessageQueueId_t mq_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMessageQueueDelete, (uint32_t)mq_id, 0U); -#else - (void)mq_id; -#endif -} -#endif - -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_DESTROYED_DISABLE)) -__WEAK void EvrRtxMessageQueueDestroyed (osMessageQueueId_t mq_id) { -#if defined(RTE_Compiler_EventRecorder) - EventRecord2(EvtRtxMessageQueueDestroyed, (uint32_t)mq_id, 0U); -#else - (void)mq_id; -#endif -} -#endif diff --git a/rtos/rtx5/TARGET_CORTEX_M/rtx_evr.h b/rtos/rtx5/TARGET_CORTEX_M/rtx_evr.h deleted file mode 100644 index 5bc4baa..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/rtx_evr.h +++ /dev/null @@ -1,1847 +0,0 @@ -/** \addtogroup rtos */ -/** @{*/ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ----------------------------------------------------------------------------- - * - * Project: CMSIS-RTOS RTX - * Title: RTX Event Recorder definitions - * - * ----------------------------------------------------------------------------- - */ - -#ifndef RTX_EVR_H_ -#define RTX_EVR_H_ - -#include "cmsis_os2.h" // CMSIS RTOS API -#include "rtx_os.h" // RTX OS definitions -#include "RTX_Config.h" - - -/// Extended Status codes -#define osRtxErrorKernelNotReady (-7) -#define osRtxErrorKernelNotRunning (-8) -#define osRtxErrorInvalidControlBlock (-9) -#define osRtxErrorInvalidDataMemory (-10) -#define osRtxErrorInvalidThreadStack (-11) -#define osRtxErrorInvalidPriority (-12) -#define osRtxErrorThreadNotJoinable (-13) -#define osRtxErrorMutexNotOwned (-14) -#define osRtxErrorMutexNotLocked (-15) -#define osRtxErrorMutexLockLimit (-16) -#define osRtxErrorSemaphoreCountLimit (-17) -#define osRtxErrorTZ_InitContext_S (-18) -#define osRtxErrorTZ_AllocContext_S (-19) -#define osRtxErrorTZ_FreeContext_S (-20) -#define osRtxErrorTZ_LoadContext_S (-21) -#define osRtxErrorTZ_SaveContext_S (-22) - - -// ==== Memory Events ==== - -/** - \brief Event on memory initialization (Op) - \param[in] mem pointer to memory pool. - \param[in] size size of a memory pool in bytes. - \param[in] result execution status: 1 - success, 0 - failure. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMORY != 0) && !defined(EVR_RTX_MEMORY_INIT_DISABLE)) -extern void EvrRtxMemoryInit (void *mem, uint32_t size, uint32_t result); -#else -#define EvrRtxMemoryInit(mem, size, result) -#endif - -/** - \brief Event on memory allocate (Op) - \param[in] mem pointer to memory pool. - \param[in] size size of a memory block in bytes. - \param[in] type memory block type: 0 - generic, 1 - control block - \param[in] block pointer to allocated memory block or NULL in case of no memory is available. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMORY != 0) && !defined(EVR_RTX_MEMORY_ALLOC_DISABLE)) -extern void EvrRtxMemoryAlloc (void *mem, uint32_t size, uint32_t type, void *block); -#else -#define EvrRtxMemoryAlloc(mem, size, type, block) -#endif - -/** - \brief Event on memory free (Op) - \param[in] mem pointer to memory pool. - \param[in] block memory block to be returned to the memory pool. - \param[in] result execution status: 1 - success, 0 - failure. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMORY != 0) && !defined(EVR_RTX_MEMORY_FREE_DISABLE)) -extern void EvrRtxMemoryFree (void *mem, void *block, uint32_t result); -#else -#define EvrRtxMemoryFree(mem, block, result) -#endif - -/** - \brief Event on memory block initialization (Op) - \param[in] mp_info memory pool info. - \param[in] block_count maximum number of memory blocks in memory pool. - \param[in] block_size size of a memory block in bytes. - \param[in] block_mem pointer to memory for block storage. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMORY != 0) && !defined(EVR_RTX_MEMORY_BLOCK_INIT_DISABLE)) -extern void EvrRtxMemoryBlockInit (osRtxMpInfo_t *mp_info, uint32_t block_count, uint32_t block_size, void *block_mem); -#else -#define EvrRtxMemoryBlockInit(mp_info, block_count, block_size, block_mem) -#endif - -/** - \brief Event on memory block alloc (Op) - \param[in] mp_info memory pool info. - \param[in] block address of the allocated memory block or NULL in case of no memory is available. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMORY != 0) && !defined(EVR_RTX_MEMORY_BLOCK_ALLOC_DISABLE)) -extern void EvrRtxMemoryBlockAlloc (osRtxMpInfo_t *mp_info, void *block); -#else -#define EvrRtxMemoryBlockAlloc(mp_info, block) -#endif - -/** - \brief Event on memory block free (Op) - \param[in] mp_info memory pool info. - \param[in] block address of the allocated memory block to be returned to the memory pool. - \param[in] status extended execution status. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMORY != 0) && !defined(EVR_RTX_MEMORY_BLOCK_FREE_DISABLE)) -extern void EvrRtxMemoryBlockFree (osRtxMpInfo_t *mp_info, void *block, int32_t status); -#else -#define EvrRtxMemoryBlockFree(mp_info, block, status) -#endif - - -// ==== Kernel Events ==== - -/** - \brief Event on RTOS kernel error (Error) - \param[in] status extended execution status. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_ERROR_DISABLE)) -extern void EvrRtxKernelError (int32_t status); -#else -#define EvrRtxKernelError(status) -#endif - -/** - \brief Event on RTOS kernel initialize (API) -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_INITIALIZE_DISABLE)) -extern void EvrRtxKernelInitialize (void); -#else -#define EvrRtxKernelInitialize() -#endif - -/** - \brief Event on successful RTOS kernel initialize (Op) -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_INITIALIZE_COMPLETED_DISABLE)) -extern void EvrRtxKernelInitializeCompleted (void); -#else -#define EvrRtxKernelInitializeCompleted() -#endif - -/** - \brief Event on RTOS kernel information retrieve (API) - \param[in] version pointer to buffer for retrieving version information. - \param[in] id_buf pointer to buffer for retrieving kernel identification string. - \param[in] id_size size of buffer for kernel identification string. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_GET_INFO_DISABLE)) -extern void EvrRtxKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size); -#else -#define EvrRtxKernelGetInfo(version, id_buf, id_size) -#endif - -/** - \brief Event on successful RTOS kernel information retrieve (Op) - \param[in] version pointer to buffer for retrieving version information. - \param[in] id_buf pointer to buffer for retrieving kernel identification string. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_INFO_RETRIEVED_DISABLE)) -extern void EvrRtxKernelInfoRetrieved (osVersion_t *version, char *id_buf); -#else -#define EvrRtxKernelInfoRetrieved(version, id_buf) -#endif - -/** - \brief Event on current RTOS Kernel state retrieve (API) - \param[in] state current RTOS Kernel state. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_GET_STATE_DISABLE)) -extern void EvrRtxKernelGetState (osKernelState_t state); -#else -#define EvrRtxKernelGetState(state) -#endif - -/** - \brief Event on RTOS Kernel scheduler start (API) -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_START_DISABLE)) -extern void EvrRtxKernelStart (void); -#else -#define EvrRtxKernelStart() -#endif - -/** - \brief Event on successful RTOS Kernel scheduler start (Op) -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_STARTED_DISABLE)) -extern void EvrRtxKernelStarted (void); -#else -#define EvrRtxKernelStarted() -#endif - -/** - \brief Event on RTOS Kernel scheduler lock (API) -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_LOCK_DISABLE)) -extern void EvrRtxKernelLock (void); -#else -#define EvrRtxKernelLock() -#endif - -/** - \brief Event on successful RTOS Kernel scheduler lock (Op) - \param[in] lock previous lock state (1 - locked, 0 - not locked). -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_LOCKED_DISABLE)) -extern void EvrRtxKernelLocked (int32_t lock); -#else -#define EvrRtxKernelLocked(lock) -#endif - -/** - \brief Event on RTOS Kernel scheduler unlock (API) -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_UNLOCK_DISABLE)) -extern void EvrRtxKernelUnlock (void); -#else -#define EvrRtxKernelUnlock() -#endif - -/** - \brief Event on successful RTOS Kernel scheduler unlock (Op) - \param[in] lock previous lock state (1 - locked, 0 - not locked). -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_UNLOCKED_DISABLE)) -extern void EvrRtxKernelUnlocked (int32_t lock); -#else -#define EvrRtxKernelUnlocked(lock) -#endif - -/** - \brief Event on RTOS Kernel scheduler lock state restore (API) - \param[in] lock lock state obtained by \ref osKernelLock or \ref osKernelUnlock. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_RESTORE_LOCK_DISABLE)) -extern void EvrRtxKernelRestoreLock (int32_t lock); -#else -#define EvrRtxKernelRestoreLock(lock) -#endif - -/** - \brief Event on successful RTOS Kernel scheduler lock state restore (Op) - \param[in] lock new lock state (1 - locked, 0 - not locked). -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_LOCK_RESTORED_DISABLE)) -extern void EvrRtxKernelLockRestored (int32_t lock); -#else -#define EvrRtxKernelLockRestored(lock) -#endif - -/** - \brief Event on RTOS Kernel scheduler suspend (API) -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_SUSPEND_DISABLE)) -extern void EvrRtxKernelSuspend (void); -#else -#define EvrRtxKernelSuspend() -#endif - -/** - \brief Event on successful RTOS Kernel scheduler suspend (Op) - \param[in] sleep_ticks time in ticks, for how long the system can sleep or power-down. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_SUSPENDED_DISABLE)) -extern void EvrRtxKernelSuspended (uint32_t sleep_ticks); -#else -#define EvrRtxKernelSuspended(sleep_ticks) -#endif - -/** - \brief Event on RTOS Kernel scheduler resume (API) - \param[in] sleep_ticks time in ticks, for how long the system was in sleep or power-down mode. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_RESUME_DISABLE)) -extern void EvrRtxKernelResume (uint32_t sleep_ticks); -#else -#define EvrRtxKernelResume(sleep_ticks) -#endif - -/** - \brief Event on successful RTOS Kernel scheduler resume (Op) -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_RESUMED_DISABLE)) -extern void EvrRtxKernelResumed (void); -#else -#define EvrRtxKernelResumed() -#endif - -/** - \brief Event on RTOS kernel tick count retrieve (API) - \param[in] count RTOS kernel current tick count. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_GET_TICK_COUNT_DISABLE)) -extern void EvrRtxKernelGetTickCount (uint64_t count); -#else -#define EvrRtxKernelGetTickCount(count) -#endif - -/** - \brief Event on RTOS kernel tick frequency retrieve (API) - \param[in] freq frequency of the kernel tick. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_GET_TICK_FREQ_DISABLE)) -extern void EvrRtxKernelGetTickFreq (uint32_t freq); -#else -#define EvrRtxKernelGetTickFreq(freq) -#endif - -/** - \brief Event on RTOS kernel system timer count retrieve (API) - \param[in] count RTOS kernel current system timer count as 32-bit value. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_GET_SYS_TIMER_COUNT_DISABLE)) -extern void EvrRtxKernelGetSysTimerCount (uint32_t count); -#else -#define EvrRtxKernelGetSysTimerCount(count) -#endif - -/** - \brief Event on RTOS kernel system timer frequency retrieve (API) - \param[in] freq frequency of the system timer. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_KERNEL != 0) && !defined(EVR_RTX_KERNEL_GET_SYS_TIMER_FREQ_DISABLE)) -extern void EvrRtxKernelGetSysTimerFreq (uint32_t freq); -#else -#define EvrRtxKernelGetSysTimerFreq(freq) -#endif - - -// ==== Thread Events ==== - -/** - \brief Event on thread error (Error) - \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId or NULL when ID is unknown. - \param[in] status extended execution status. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_ERROR_DISABLE)) -extern void EvrRtxThreadError (osThreadId_t thread_id, int32_t status); -#else -#define EvrRtxThreadError(thread_id, status) -#endif - -/** - \brief Event on thread create and intialize (API) - \param[in] func thread function. - \param[in] argument pointer that is passed to the thread function as start argument. - \param[in] attr thread attributes. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_NEW_DISABLE)) -extern void EvrRtxThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr); -#else -#define EvrRtxThreadNew(func, argument, attr) -#endif - -/** - \brief Event on successful thread create (Op) - \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_CREATED_DISABLE)) -extern void EvrRtxThreadCreated (osThreadId_t thread_id); -#else -#define EvrRtxThreadCreated(thread_id) -#endif - -/** - \brief Event on thread name retrieve (API) - \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. - \param[in] name pointer to thread object name -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_NAME_DISABLE)) -extern void EvrRtxThreadGetName (osThreadId_t thread_id, const char *name); -#else -#define EvrRtxThreadGetName(thread_id, name) -#endif - -/** - \brief Event on current running thread ID retrieve (API) - \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_ID_DISABLE)) -extern void EvrRtxThreadGetId (osThreadId_t thread_id); -#else -#define EvrRtxThreadGetId(thread_id) -#endif - -/** - \brief Event on thread state retrieve (API) - \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. - \param[in] state current thread state of the specified thread. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_STATE_DISABLE)) -extern void EvrRtxThreadGetState (osThreadId_t thread_id, osThreadState_t state); -#else -#define EvrRtxThreadGetState(thread_id, state) -#endif - -/** - \brief Event on thread stack size retrieve (API) - \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. - \param[in] stack_size stack size in bytes. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_STACK_SIZE_DISABLE)) -extern void EvrRtxThreadGetStackSize (osThreadId_t thread_id, uint32_t stack_size); -#else -#define EvrRtxThreadGetStackSize(thread_id, stack_size) -#endif - -/** - \brief Event on available stack space retrieve (API) - \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. - \param[in] stack_space remaining stack space in bytes. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_STACK_SPACE_DISABLE)) -extern void EvrRtxThreadGetStackSpace (osThreadId_t thread_id, uint32_t stack_space); -#else -#define EvrRtxThreadGetStackSpace(thread_id, stack_space) -#endif - -/** - \brief Event on thread priority set (API) - \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. - \param[in] priority new priority value for the thread function. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_SET_PRIORITY_DISABLE)) -extern void EvrRtxThreadSetPriority (osThreadId_t thread_id, osPriority_t priority); -#else -#define EvrRtxThreadSetPriority(thread_id, priority) -#endif - -/** - \brief Event on thread priority retrieve (API) - \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. - \param[in] priority current priority value of the specified thread. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_PRIORITY_DISABLE)) -extern void EvrRtxThreadGetPriority (osThreadId_t thread_id, osPriority_t priority); -#else -#define EvrRtxThreadGetPriority(thread_id, priority) -#endif - -/** - \brief Event on thread yield (API) -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_YIELD_DISABLE)) -extern void EvrRtxThreadYield (void); -#else -#define EvrRtxThreadYield() -#endif - -/** - \brief Event on thread suspend (API) - \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_SUSPEND_DISABLE)) -extern void EvrRtxThreadSuspend (osThreadId_t thread_id); -#else -#define EvrRtxThreadSuspend(thread_id) -#endif - -/** - \brief Event on successful thread suspend (Op) - \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_SUSPENDED_DISABLE)) -extern void EvrRtxThreadSuspended (osThreadId_t thread_id); -#else -#define EvrRtxThreadSuspended(thread_id) -#endif - -/** - \brief Event on thread resume (API) - \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_RESUME_DISABLE)) -extern void EvrRtxThreadResume (osThreadId_t thread_id); -#else -#define EvrRtxThreadResume(thread_id) -#endif - -/** - \brief Event on successful thread resume (Op) - \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_RESUMED_DISABLE)) -extern void EvrRtxThreadResumed (osThreadId_t thread_id); -#else -#define EvrRtxThreadResumed(thread_id) -#endif - -/** - \brief Event on thread detach (API) - \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_DETACH_DISABLE)) -extern void EvrRtxThreadDetach (osThreadId_t thread_id); -#else -#define EvrRtxThreadDetach(thread_id) -#endif - -/** - \brief Event on successful thread detach (Op) - \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_DETACHED_DISABLE)) -extern void EvrRtxThreadDetached (osThreadId_t thread_id); -#else -#define EvrRtxThreadDetached(thread_id) -#endif - -/** - \brief Event on thread join (API) - \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_JOIN_DISABLE)) -extern void EvrRtxThreadJoin (osThreadId_t thread_id); -#else -#define EvrRtxThreadJoin(thread_id) -#endif - -/** - \brief Event on pending thread join (Op) - \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_JOIN_PENDING_DISABLE)) -extern void EvrRtxThreadJoinPending (osThreadId_t thread_id); -#else -#define EvrRtxThreadJoinPending(thread_id) -#endif - -/** - \brief Event on successful thread join (Op) - \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_JOINED_DISABLE)) -extern void EvrRtxThreadJoined (osThreadId_t thread_id); -#else -#define EvrRtxThreadJoined(thread_id) -#endif - -/** - \brief Event on thread execution block (Op) - \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. - \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_BLOCKED_DISABLE)) -extern void EvrRtxThreadBlocked (osThreadId_t thread_id, uint32_t timeout); -#else -#define EvrRtxThreadBlocked(thread_id, timeout) -#endif - -/** - \brief Event on blocked thread release (Op) - \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. - \param[in] ret_val extended execution status of the thread. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_UNBLOCKED_DISABLE)) -extern void EvrRtxThreadUnblocked (osThreadId_t thread_id, uint32_t ret_val); -#else -#define EvrRtxThreadUnblocked(thread_id, ret_val) -#endif - -/** - \brief Event on current running thread switch (Op) - \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_SWITCH_DISABLE)) -extern void EvrRtxThreadSwitch (osThreadId_t thread_id); -#else -#define EvrRtxThreadSwitch(thread_id) -#endif - -/** - \brief Event on thread exit (API) -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_EXIT_DISABLE)) -extern void EvrRtxThreadExit (void); -#else -#define EvrRtxThreadExit() -#endif - -/** - \brief Event on thread terminate (API) - \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_TERMINATE_DISABLE)) -extern void EvrRtxThreadTerminate (osThreadId_t thread_id); -#else -#define EvrRtxThreadTerminate(thread_id) -#endif - -/** - \brief Event on successful thread terminate (Op) - \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_DESTROYED_DISABLE)) -extern void EvrRtxThreadDestroyed (osThreadId_t thread_id); -#else -#define EvrRtxThreadDestroyed(thread_id) -#endif - -/** - \brief Event on active thread count retrieve (API) - \param[in] count number of active threads. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_GET_COUNT_DISABLE)) -extern void EvrRtxThreadGetCount (uint32_t count); -#else -#define EvrRtxThreadGetCount(count) -#endif - -/** - \brief Event on active threads enumerate (API) - \param[in] thread_array pointer to array for retrieving thread IDs. - \param[in] array_items maximum number of items in array for retrieving thread IDs. - \param[in] count number of enumerated threads. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_ENUMERATE_DISABLE)) -extern void EvrRtxThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items, uint32_t count); -#else -#define EvrRtxThreadEnumerate(thread_array, array_items, count) -#endif - -/** - \brief Event on thread flags set (API) - \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. - \param[in] flags flags of the thread that shall be set. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_SET_DISABLE)) -extern void EvrRtxThreadFlagsSet (osThreadId_t thread_id, uint32_t flags); -#else -#define EvrRtxThreadFlagsSet(thread_id, flags) -#endif - -/** - \brief Event on successful thread flags set (Op) - \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. - \param[in] thread_flags thread flags after setting -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_SET_DONE_DISABLE)) -extern void EvrRtxThreadFlagsSetDone (osThreadId_t thread_id, uint32_t thread_flags); -#else -#define EvrRtxThreadFlagsSetDone(thread_id, thread_flags) -#endif - -/** - \brief Event on thread flags clear (API) - \param[in] flags flags of the thread that shall be cleared. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_CLEAR_DISABLE)) -extern void EvrRtxThreadFlagsClear (uint32_t flags); -#else -#define EvrRtxThreadFlagsClear(flags) -#endif - -/** - \brief Event on successful thread flags clear (Op) - \param[in] thread_flags thread flags before clearing -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_CLEAR_DONE_DISABLE)) -extern void EvrRtxThreadFlagsClearDone (uint32_t thread_flags); -#else -#define EvrRtxThreadFlagsClearDone(thread_flags) -#endif - -/** - \brief Event on thread flags retrieve (API) - \param[in] thread_flags current thread flags. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_GET_DISABLE)) -extern void EvrRtxThreadFlagsGet (uint32_t thread_flags); -#else -#define EvrRtxThreadFlagsGet(thread_flags) -#endif - -/** - \brief Event on wait for thread flags (API) - \param[in] flags flags to wait for. - \param[in] options flags options (osFlagsXxxx). - \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_WAIT_DISABLE)) -extern void EvrRtxThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout); -#else -#define EvrRtxThreadFlagsWait(flags, options, timeout) -#endif - -/** - \brief Event on pending wait for thread flags (Op) - \param[in] flags flags to wait for. - \param[in] options flags options (osFlagsXxxx). - \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_WAIT_PENDING_DISABLE)) -extern void EvrRtxThreadFlagsWaitPending (uint32_t flags, uint32_t options, uint32_t timeout); -#else -#define EvrRtxThreadFlagsWaitPending(flags, options, timeout) -#endif - -/** - \brief Event on wait timeout for thread flags (Op) -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_WAIT_TIMEOUT_DISABLE)) -extern void EvrRtxThreadFlagsWaitTimeout (void); -#else -#define EvrRtxThreadFlagsWaitTimeout() -#endif - -/** - \brief Event on successful wait for thread flags (Op) - \param[in] flags flags to wait for. - \param[in] options flags options (osFlagsXxxx). - \param[in] thread_flags thread flags before clearing -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_WAIT_COMPLETED_DISABLE)) -extern void EvrRtxThreadFlagsWaitCompleted (uint32_t flags, uint32_t options, uint32_t thread_flags); -#else -#define EvrRtxThreadFlagsWaitCompleted(flags, options, thread_flags) -#endif - -/** - \brief Event on unsuccessful wait for thread flags (Op) - \param[in] flags flags to wait for. - \param[in] options flags options (osFlagsXxxx). -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_FLAGS_WAIT_NOT_COMPLETED_DISABLE)) -extern void EvrRtxThreadFlagsWaitNotCompleted (uint32_t flags, uint32_t options); -#else -#define EvrRtxThreadFlagsWaitNotCompleted(flags, options) -#endif - -/** - \brief Event on wait for timeout (API) - \param[in] ticks \ref CMSIS_RTOS_TimeOutValue "time ticks" value -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_DELAY_DISABLE)) -extern void EvrRtxThreadDelay (uint32_t ticks); -#else -#define EvrRtxThreadDelay(ticks) -#endif - -/** - \brief Event on wait until specified time (API) - \param[in] ticks absolute time in ticks -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_DELAY_UNTIL_DISABLE)) -extern void EvrRtxThreadDelayUntil (uint64_t ticks); -#else -#define EvrRtxThreadDelayUntil(ticks) -#endif - -/** - \brief Event on completed wait (Op) -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_THREAD != 0) && !defined(EVR_RTX_THREAD_DELAY_COMPLETED_DISABLE)) -extern void EvrRtxThreadDelayCompleted (void); -#else -#define EvrRtxThreadDelayCompleted() -#endif - - - -// ==== Timer Events ==== - -/** - \brief Event on timer error (Error) - \param[in] timer_id timer ID obtained by \ref osTimerNew or NULL when ID is unknown. - \param[in] status extended execution status. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_ERROR_DISABLE)) -extern void EvrRtxTimerError (osTimerId_t timer_id, int32_t status); -#else -#define EvrRtxTimerError(timer_id, status); -#endif - -/** - \brief Event on timer callback call (Op) - \param[in] func start address of a timer call back function. - \param[in] argument argument to the timer call back function. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_CALLBACK_DISABLE)) -extern void EvrRtxTimerCallback (osTimerFunc_t func, void *argument); -#else -#define EvrRtxTimerCallback(func, argument); -#endif - -/** - \brief Event on timer create and initialize (API) - \param[in] func start address of a timer call back function. - \param[in] type osTimerOnce for one-shot or osTimerPeriodic for periodic behavior. - \param[in] argument argument to the timer call back function. - \param[in] attr timer attributes. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_NEW_DISABLE)) -extern void EvrRtxTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr); -#else -#define EvrRtxTimerNew(func, type, argument, attr); -#endif - -/** - \brief Event on successful timer create (Op) - \param[in] timer_id timer ID obtained by \ref osTimerNew -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_CREATED_DISABLE)) -extern void EvrRtxTimerCreated (osTimerId_t timer_id); -#else -#define EvrRtxTimerCreated(timer_id); -#endif - -/** - \brief Event on timer name retrieve (API) - \param[in] timer_id timer ID obtained by \ref osTimerNew - \param[in] name pointer to timer object name. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_GET_NAME_DISABLE)) -extern void EvrRtxTimerGetName (osTimerId_t timer_id, const char *name); -#else -#define EvrRtxTimerGetName(timer_id, name); -#endif - -/** - \brief Event on timer start (API) - \param[in] timer_id timer ID obtained by \ref osTimerNew - \param[in] ticks \ref CMSIS_RTOS_TimeOutValue "time ticks" value of the timer. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_START_DISABLE)) -extern void EvrRtxTimerStart (osTimerId_t timer_id, uint32_t ticks); -#else -#define EvrRtxTimerStart(timer_id, ticks); -#endif - -/** - \brief Event on successful timer start (Op) - \param[in] timer_id timer ID obtained by \ref osTimerNew -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_STARTED_DISABLE)) -extern void EvrRtxTimerStarted (osTimerId_t timer_id); -#else -#define EvrRtxTimerStarted(timer_id); -#endif - -/** - \brief Event on timer stop (API) - \param[in] timer_id timer ID obtained by \ref osTimerNew -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_STOP_DISABLE)) -extern void EvrRtxTimerStop (osTimerId_t timer_id); -#else -#define EvrRtxTimerStop(timer_id); -#endif - -/** - \brief Event on successful timer stop (Op) - \param[in] timer_id timer ID obtained by \ref osTimerNew -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_STOPPED_DISABLE)) -extern void EvrRtxTimerStopped (osTimerId_t timer_id); -#else -#define EvrRtxTimerStopped(timer_id); -#endif - -/** - \brief Event on timer running state check (API) - \param[in] timer_id timer ID obtained by \ref osTimerNew - \param[in] running running state: 0 not running, 1 running -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_IS_RUNNING_DISABLE)) -extern void EvrRtxTimerIsRunning (osTimerId_t timer_id, uint32_t running); -#else -#define EvrRtxTimerIsRunning(timer_id, running); -#endif - -/** - \brief Event on timer delete (API) - \param[in] timer_id timer ID obtained by \ref osTimerNew -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_DELETE_DISABLE)) -extern void EvrRtxTimerDelete (osTimerId_t timer_id); -#else -#define EvrRtxTimerDelete(timer_id); -#endif - -/** - \brief Event on successful timer delete (Op) - \param[in] timer_id timer ID obtained by \ref osTimerNew -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_TIMER != 0) && !defined(EVR_RTX_TIMER_DESTROYED_DISABLE)) -extern void EvrRtxTimerDestroyed (osTimerId_t timer_id); -#else -#define EvrRtxTimerDestroyed(timer_id); -#endif - - -// ==== Event Flags Events ==== - -/** - \brief Event on event flags error (Error) - \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew or NULL when ID is unknown. - \param[in] status extended execution status. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_ERROR_DISABLE)) -extern void EvrRtxEventFlagsError (osEventFlagsId_t ef_id, int32_t status); -#else -#define EvrRtxEventFlagsError(ef_id, status) -#endif - -/** - \brief Event on event flags create and initialize (API) - \param[in] attr event flags attributes -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_NEW_DISABLE)) -extern void EvrRtxEventFlagsNew (const osEventFlagsAttr_t *attr); -#else -#define EvrRtxEventFlagsNew(attr) -#endif - -/** - \brief Event on successful event flags create (Op) - \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_CREATED_DISABLE)) -extern void EvrRtxEventFlagsCreated (osEventFlagsId_t ef_id); -#else -#define EvrRtxEventFlagsCreated(ef_id) -#endif - -/** - \brief Event on event flags name retrieve (API) - \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. - \param[in] name pointer to event flags object name. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_GET_NAME_DISABLE)) -extern void EvrRtxEventFlagsGetName (osEventFlagsId_t ef_id, const char *name); -#else -#define EvrRtxEventFlagsGetName(ef_id, name) -#endif - -/** - \brief Event on event flags set (API) - \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. - \param[in] flags flags that shall be set. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_SET_DISABLE)) -extern void EvrRtxEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags); -#else -#define EvrRtxEventFlagsSet(ef_id, flags) -#endif - -/** - \brief Event on successful event flags set (Op) - \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. - \param[in] event_flags event flags after setting -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_SET_DONE_DISABLE)) -extern void EvrRtxEventFlagsSetDone (osEventFlagsId_t ef_id, uint32_t event_flags); -#else -#define EvrRtxEventFlagsSetDone(ef_id, event_flags) -#endif - -/** - \brief Event on event flags clear (API) - \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. - \param[in] flags flags that shall be cleared. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_CLEAR_DISABLE)) -extern void EvrRtxEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags); -#else -#define EvrRtxEventFlagsClear(ef_id, flags) -#endif - -/** - \brief Event on successful event flags clear (Op) - \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. - \param[in] event_flags event flags before clearing -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_CLEAR_DONE_DISABLE)) -extern void EvrRtxEventFlagsClearDone (osEventFlagsId_t ef_id, uint32_t event_flags); -#else -#define EvrRtxEventFlagsClearDone(ef_id, event_flags) -#endif - -/** - \brief Event on event flags retrieve (API) - \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. - \param[in] event_flags current event flags. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_GET_DISABLE)) -extern void EvrRtxEventFlagsGet (osEventFlagsId_t ef_id, uint32_t event_flags); -#else -#define EvrRtxEventFlagsGet(ef_id, event_flags) -#endif - -/** - \brief Event on wait for event flags (API) - \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. - \param[in] flags flags to wait for. - \param[in] options flags options (osFlagsXxxx). - \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_WAIT_DISABLE)) -extern void EvrRtxEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout); -#else -#define EvrRtxEventFlagsWait(ef_id, flags, options, timeout) -#endif - -/** - \brief Event on pending wait for event flags (Op) - \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. - \param[in] flags flags to wait for. - \param[in] options flags options (osFlagsXxxx). - \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_WAIT_PENDING_DISABLE)) -extern void EvrRtxEventFlagsWaitPending (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout); -#else -#define EvrRtxEventFlagsWaitPending(ef_id, flags, options, timeout) -#endif - -/** - \brief Event on wait timeout for event flags (Op) - \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_WAIT_TIMEOUT_DISABLE)) -extern void EvrRtxEventFlagsWaitTimeout (osEventFlagsId_t ef_id); -#else -#define EvrRtxEventFlagsWaitTimeout(ef_id) -#endif - -/** - \brief Event on successful wait for event flags (Op) - \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. - \param[in] flags flags to wait for. - \param[in] options flags options (osFlagsXxxx). - \param[in] event_flags event flags before clearing or 0 if specified flags have not been set. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_WAIT_COMPLETED_DISABLE)) -extern void EvrRtxEventFlagsWaitCompleted (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t event_flags); -#else -#define EvrRtxEventFlagsWaitCompleted(ef_id, flags, options, event_flags) -#endif - -/** - \brief Event on unsuccessful wait for event flags (Op) - \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. - \param[in] flags flags to wait for. - \param[in] options flags options (osFlagsXxxx). -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_WAIT_NOT_COMPLETED_DISABLE)) -extern void EvrRtxEventFlagsWaitNotCompleted (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options); -#else -#define EvrRtxEventFlagsWaitNotCompleted(ef_id, flags, options) -#endif - -/** - \brief Event on event flags delete (API) - \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_DELETE_DISABLE)) -extern void EvrRtxEventFlagsDelete (osEventFlagsId_t ef_id); -#else -#define EvrRtxEventFlagsDelete(ef_id) -#endif - -/** - \brief Event on successful event flags delete (Op) - \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_EVFLAGS != 0) && !defined(EVR_RTX_EVENT_FLAGS_DESTROYED_DISABLE)) -extern void EvrRtxEventFlagsDestroyed (osEventFlagsId_t ef_id); -#else -#define EvrRtxEventFlagsDestroyed(ef_id) -#endif - - -// ==== Mutex Events ==== - -/** - \brief Event on mutex error (Error) - \param[in] mutex_id mutex ID obtained by \ref osMutexNew or NULL when ID is unknown. - \param[in] status extended execution status. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_ERROR_DISABLE)) -extern void EvrRtxMutexError (osMutexId_t mutex_id, int32_t status); -#else -#define EvrRtxMutexError(mutex_id, status) -#endif - -/** - \brief Event on mutex create and initialize (API) - \param[in] attr mutex attributes -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_NEW_DISABLE)) -extern void EvrRtxMutexNew (const osMutexAttr_t *attr); -#else -#define EvrRtxMutexNew(attr) -#endif - -/** - \brief Event on successful mutex create (Op) - \param[in] mutex_id mutex ID obtained by \ref osMutexNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_CREATED_DISABLE)) -extern void EvrRtxMutexCreated (osMutexId_t mutex_id); -#else -#define EvrRtxMutexCreated(mutex_id) -#endif - -/** - \brief Event on mutex name retrieve (API) - \param[in] mutex_id mutex ID obtained by \ref osMutexNew. - \param[in] name pointer to mutex object name -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_GET_NAME_DISABLE)) -extern void EvrRtxMutexGetName (osMutexId_t mutex_id, const char *name); -#else -#define EvrRtxMutexGetName(mutex_id, name) -#endif - -/** - \brief Event on mutex acquire (API) - \param[in] mutex_id mutex ID obtained by \ref osMutexNew. - \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_ACQUIRE_DISABLE)) -extern void EvrRtxMutexAcquire (osMutexId_t mutex_id, uint32_t timeout); -#else -#define EvrRtxMutexAcquire(mutex_id, timeout) -#endif - -/** - \brief Event on pending mutex acquire (Op) - \param[in] mutex_id mutex ID obtained by \ref osMutexNew. - \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_ACQUIRE_PENDING_DISABLE)) -extern void EvrRtxMutexAcquirePending (osMutexId_t mutex_id, uint32_t timeout); -#else -#define EvrRtxMutexAcquirePending(mutex_id, timeout); -#endif - -/** - \brief Event on mutex acquire timeout (Op) - \param[in] mutex_id mutex ID obtained by \ref osMutexNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_ACQUIRE_TIMEOUT_DISABLE)) -extern void EvrRtxMutexAcquireTimeout (osMutexId_t mutex_id); -#else -#define EvrRtxMutexAcquireTimeout(mutex_id) -#endif - -/** - \brief Event on successful mutex acquire (Op) - \param[in] mutex_id mutex ID obtained by \ref osMutexNew. - \param[in] lock current number of times mutex object is locked -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_ACQUIRED_DISABLE)) -extern void EvrRtxMutexAcquired (osMutexId_t mutex_id, uint32_t lock); -#else -#define EvrRtxMutexAcquired(mutex_id, lock) -#endif - -/** - \brief Event on unsuccessful mutex acquire (Op) - \param[in] mutex_id mutex ID obtained by \ref osMutexNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_NOT_ACQUIRED_DISABLE)) -extern void EvrRtxMutexNotAcquired (osMutexId_t mutex_id); -#else -#define EvrRtxMutexNotAcquired(mutex_id) -#endif - -/** - \brief Event on mutex release (API) - \param[in] mutex_id mutex ID obtained by \ref osMutexNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_RELEASE_DISABLE)) -extern void EvrRtxMutexRelease (osMutexId_t mutex_id); -#else -#define EvrRtxMutexRelease(mutex_id) -#endif - -/** - \brief Event on successful mutex release (Op) - \param[in] mutex_id mutex ID obtained by \ref osMutexNew. - \param[in] lock current number of times mutex object is locked -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_RELEASED_DISABLE)) -extern void EvrRtxMutexReleased (osMutexId_t mutex_id, uint32_t lock); -#else -#define EvrRtxMutexReleased(mutex_id, lock) -#endif - -/** - \brief Event on mutex owner retrieve (API) - \param[in] mutex_id mutex ID obtained by \ref osMutexNew. - \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_GET_OWNER_DISABLE)) -extern void EvrRtxMutexGetOwner (osMutexId_t mutex_id, osThreadId_t thread_id); -#else -#define EvrRtxMutexGetOwner(mutex_id, thread_id) -#endif - -/** - \brief Event on mutex delete (API) - \param[in] mutex_id mutex ID obtained by \ref osMutexNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_DELETE_DISABLE)) -extern void EvrRtxMutexDelete (osMutexId_t mutex_id); -#else -#define EvrRtxMutexDelete(mutex_id) -#endif - -/** - \brief Event on successful mutex delete (Op) - \param[in] mutex_id mutex ID obtained by \ref osMutexNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MUTEX != 0) && !defined(EVR_RTX_MUTEX_DESTROYED_DISABLE)) -extern void EvrRtxMutexDestroyed (osMutexId_t mutex_id); -#else -#define EvrRtxMutexDestroyed(mutex_id) -#endif - - -// ==== Semaphore Events ==== - -/** - \brief Event on semaphore error (Error) - \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew or NULL when ID is unknown. - \param[in] status extended execution status. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_ERROR_DISABLE)) -extern void EvrRtxSemaphoreError (osSemaphoreId_t semaphore_id, int32_t status); -#else -#define EvrRtxSemaphoreError(semaphore_id, status) -#endif - -/** - \brief Event on semaphore create and initialize (API) - \param[in] max_count maximum number of available tokens. - \param[in] initial_count initial number of available tokens. - \param[in] attr semaphore attributes. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_NEW_DISABLE)) -extern void EvrRtxSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr); -#else -#define EvrRtxSemaphoreNew(max_count, initial_count, attr) -#endif - -/** - \brief Event on successful semaphore create (Op) - \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_CREATED_DISABLE)) -extern void EvrRtxSemaphoreCreated (osSemaphoreId_t semaphore_id); -#else -#define EvrRtxSemaphoreCreated(semaphore_id) -#endif - -/** - \brief Event on semaphore name retrieve (API) - \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. - \param[in] name pointer to semaphore object name. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_GET_NAME_DISABLE)) -extern void EvrRtxSemaphoreGetName (osSemaphoreId_t semaphore_id, const char *name); -#else -#define EvrRtxSemaphoreGetName(semaphore_id, name) -#endif - -/** - \brief Event on semaphore acquire (API) - \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. - \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_ACQUIRE_DISABLE)) -extern void EvrRtxSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout); -#else -#define EvrRtxSemaphoreAcquire(semaphore_id, timeout) -#endif - -/** - \brief Event on pending semaphore acquire (Op) - \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. - \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_ACQUIRE_PENDING_DISABLE)) -extern void EvrRtxSemaphoreAcquirePending (osSemaphoreId_t semaphore_id, uint32_t timeout); -#else -#define EvrRtxSemaphoreAcquirePending(semaphore_id, timeout); -#endif - -/** - \brief Event on semaphore acquire timeout (Op) - \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_ACQUIRE_TIMEOUT_DISABLE)) -extern void EvrRtxSemaphoreAcquireTimeout (osSemaphoreId_t semaphore_id); -#else -#define EvrRtxSemaphoreAcquireTimeout(semaphore_id) -#endif - -/** - \brief Event on successful semaphore acquire (Op) - \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_ACQUIRED_DISABLE)) -extern void EvrRtxSemaphoreAcquired (osSemaphoreId_t semaphore_id); -#else -#define EvrRtxSemaphoreAcquired(semaphore_id) -#endif - -/** - \brief Event on unsuccessful semaphore acquire (Op) - \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_NOT_ACQUIRED_DISABLE)) -extern void EvrRtxSemaphoreNotAcquired (osSemaphoreId_t semaphore_id); -#else -#define EvrRtxSemaphoreNotAcquired(semaphore_id) -#endif - -/** - \brief Event on semaphore release (API) - \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_RELEASE_DISABLE)) -extern void EvrRtxSemaphoreRelease (osSemaphoreId_t semaphore_id); -#else -#define EvrRtxSemaphoreRelease(semaphore_id) -#endif - -/** - \brief Event on successful semaphore release (Op) - \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_RELEASED_DISABLE)) -extern void EvrRtxSemaphoreReleased (osSemaphoreId_t semaphore_id); -#else -#define EvrRtxSemaphoreReleased(semaphore_id) -#endif - -/** - \brief Event on semaphore token count retrieval (API) - \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. - \param[in] count current number of available tokens. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_GET_COUNT_DISABLE)) -extern void EvrRtxSemaphoreGetCount (osSemaphoreId_t semaphore_id, uint32_t count); -#else -#define EvrRtxSemaphoreGetCount(semaphore_id, count) -#endif - -/** - \brief Event on semaphore delete (API) - \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_DELETE_DISABLE)) -extern void EvrRtxSemaphoreDelete (osSemaphoreId_t semaphore_id); -#else -#define EvrRtxSemaphoreDelete(semaphore_id) -#endif - -/** - \brief Event on successful semaphore delete (Op) - \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_SEMAPHORE != 0) && !defined(EVR_RTX_SEMAPHORE_DESTROYED_DISABLE)) -extern void EvrRtxSemaphoreDestroyed (osSemaphoreId_t semaphore_id); -#else -#define EvrRtxSemaphoreDestroyed(semaphore_id) -#endif - - -// ==== Memory Pool Events ==== - -/** - \brief Event on memory pool error (Error) - \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew or NULL when ID is unknown. - \param[in] status extended execution status. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_ERROR_DISABLE)) -extern void EvrRtxMemoryPoolError (osMemoryPoolId_t mp_id, int32_t status); -#else -#define EvrRtxMemoryPoolError(mp_id, status) -#endif - -/** - \brief Event on memory pool create and initialize (API) - \param[in] block_count maximum number of memory blocks in memory pool. - \param[in] block_size memory block size in bytes. - \param[in] attr memory pool attributes; NULL: default values. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_NEW_DISABLE)) -extern void EvrRtxMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr); -#else -#define EvrRtxMemoryPoolNew(block_count, block_size, attr) -#endif - -/** - \brief Event on successful memory pool create (Op) - \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_CREATED_DISABLE)) -extern void EvrRtxMemoryPoolCreated (osMemoryPoolId_t mp_id); -#else -#define EvrRtxMemoryPoolCreated(mp_id) -#endif - -/** - \brief Event on memory pool name retrieve (API) - \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. - \param[in] name pointer to memory pool object name. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_GET_NAME_DISABLE)) -extern void EvrRtxMemoryPoolGetName (osMemoryPoolId_t mp_id, const char *name); -#else -#define EvrRtxMemoryPoolGetName(mp_id, name) -#endif - -/** - \brief Event on memory pool allocation (API) - \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. - \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_ALLOC_DISABLE)) -extern void EvrRtxMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout); -#else -#define EvrRtxMemoryPoolAlloc(mp_id, timeout) -#endif - -/** - \brief Event on pending memory pool allocation (Op) - \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. - \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_ALLOC_PENDING_DISABLE)) -extern void EvrRtxMemoryPoolAllocPending (osMemoryPoolId_t mp_id, uint32_t timeout); -#else -#define EvrRtxMemoryPoolAllocPending(mp_id, timeout) -#endif - -/** - \brief Event on memory pool allocation timeout (Op) - \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_ALLOC_TIMEOUT_DISABLE)) -extern void EvrRtxMemoryPoolAllocTimeout (osMemoryPoolId_t mp_id); -#else -#define EvrRtxMemoryPoolAllocTimeout(mp_id) -#endif - -/** - \brief Event on successful memory pool allocation (Op) - \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. - \param[in] block address of the allocated memory block. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_ALLOCATED_DISABLE)) -extern void EvrRtxMemoryPoolAllocated (osMemoryPoolId_t mp_id, void *block); -#else -#define EvrRtxMemoryPoolAllocated(mp_id, block) -#endif - -/** - \brief Event on unsuccessful memory pool allocation (Op) - \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_ALLOC_FAILED_DISABLE)) -extern void EvrRtxMemoryPoolAllocFailed (osMemoryPoolId_t mp_id); -#else -#define EvrRtxMemoryPoolAllocFailed(mp_id) -#endif - -/** - \brief Event on memory pool free (API) - \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. - \param[in] block address of the allocated memory block to be returned to the memory pool. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_FREE_DISABLE)) -extern void EvrRtxMemoryPoolFree (osMemoryPoolId_t mp_id, void *block); -#else -#define EvrRtxMemoryPoolFree(mp_id, block) -#endif - -/** - \brief Event on successful memory pool free (Op) - \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. - \param[in] block address of the allocated memory block to be returned to the memory pool. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_DEALLOCATED_DISABLE)) -extern void EvrRtxMemoryPoolDeallocated (osMemoryPoolId_t mp_id, void *block); -#else -#define EvrRtxMemoryPoolDeallocated(mp_id, block) -#endif - -/** - \brief Event on unsuccessful memory pool free (Op) - \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. - \param[in] block address of the allocated memory block to be returned to the memory pool. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_FREE_FAILED_DISABLE)) -extern void EvrRtxMemoryPoolFreeFailed (osMemoryPoolId_t mp_id, void *block); -#else -#define EvrRtxMemoryPoolFreeFailed(mp_id, block) -#endif - -/** - \brief Event on memory pool capacity retrieve (API) - \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. - \param[in] capacity maximum number of memory blocks. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_GET_CAPACITY_DISABLE)) -extern void EvrRtxMemoryPoolGetCapacity (osMemoryPoolId_t mp_id, uint32_t capacity); -#else -#define EvrRtxMemoryPoolGetCapacity(mp_id, capacity) -#endif - -/** - \brief Event on memory pool block size retrieve (API) - \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. - \param[in] block_size memory block size in bytes. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_GET_BLOCK_SZIE_DISABLE)) -extern void EvrRtxMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id, uint32_t block_size); -#else -#define EvrRtxMemoryPoolGetBlockSize(mp_id, block_size) -#endif - -/** - \brief Event on used memory pool blocks retrieve (API) - \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. - \param[in] count number of memory blocks used. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_GET_COUNT_DISABLE)) -extern void EvrRtxMemoryPoolGetCount (osMemoryPoolId_t mp_id, uint32_t count); -#else -#define EvrRtxMemoryPoolGetCount(mp_id, count) -#endif - -/** - \brief Event on available memory pool blocks retrieve (API) - \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. - \param[in] space number of memory blocks available. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_GET_SPACE_DISABLE)) -extern void EvrRtxMemoryPoolGetSpace (osMemoryPoolId_t mp_id, uint32_t space); -#else -#define EvrRtxMemoryPoolGetSpace(mp_id, space) -#endif - -/** - \brief Event on memory pool delete (API) - \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_DELETE_DISABLE)) -extern void EvrRtxMemoryPoolDelete (osMemoryPoolId_t mp_id); -#else -#define EvrRtxMemoryPoolDelete(mp_id) -#endif - -/** - \brief Event on successful memory pool delete (Op) - \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MEMPOOL != 0) && !defined(EVR_RTX_MEMORY_POOL_DESTROYED_DISABLE)) -extern void EvrRtxMemoryPoolDestroyed (osMemoryPoolId_t mp_id); -#else -#define EvrRtxMemoryPoolDestroyed(mp_id) -#endif - - -// ==== Message Queue Events ==== - -/** - \brief Event on message queue error (Error) - \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew or NULL when ID is unknown. - \param[in] status extended execution status. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_ERROR_DISABLE)) -extern void EvrRtxMessageQueueError (osMessageQueueId_t mq_id, int32_t status); -#else -#define EvrRtxMessageQueueError(mq_id, status) -#endif - -/** - \brief Event on message queue create and initialization (API) - \param[in] msg_count maximum number of messages in queue. - \param[in] msg_size maximum message size in bytes. - \param[in] attr message queue attributes; NULL: default values. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_NEW_DISABLE)) -extern void EvrRtxMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr); -#else -#define EvrRtxMessageQueueNew(msg_count, msg_size, attr) -#endif - -/** - \brief Event on successful message queue create (Op) - \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_CREATED_DISABLE)) -extern void EvrRtxMessageQueueCreated (osMessageQueueId_t mq_id); -#else -#define EvrRtxMessageQueueCreated(mq_id) -#endif - -/** - \brief Event on message queue name retrieve(API) - \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. - \param[in] name pointer to message queue object name. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_NAME_DISABLE)) -extern void EvrRtxMessageQueueGetName (osMessageQueueId_t mq_id, const char *name); -#else -#define EvrRtxMessageQueueGetName(mq_id, name) -#endif - -/** - \brief Event on message put (API) - \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. - \param[in] msg_ptr pointer to buffer with message to put into a queue. - \param[in] msg_prio message priority. - \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_PUT_DISABLE)) -extern void EvrRtxMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout); -#else -#define EvrRtxMessageQueuePut(mq_id, msg_ptr, msg_prio, timeout) -#endif - -/** - \brief Event on pending message put (Op) - \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. - \param[in] msg_ptr pointer to buffer with message to put into a queue. - \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_PUT_PENDING_DISABLE)) -extern void EvrRtxMessageQueuePutPending (osMessageQueueId_t mq_id, const void *msg_ptr, uint32_t timeout); -#else -#define EvrRtxMessageQueuePutPending(mq_id, msg_ptr, timeout) -#endif - -/** - \brief Event on message put timeout (Op) - \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_PUT_TIMEOUT_DISABLE)) -extern void EvrRtxMessageQueuePutTimeout (osMessageQueueId_t mq_id); -#else -#define EvrRtxMessageQueuePutTimeout(mq_id) -#endif - -/** - \brief Event on pending message insert (Op) - \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. - \param[in] msg_ptr pointer to buffer with message to put into a queue. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_INSERT_PENDING_DISABLE)) -extern void EvrRtxMessageQueueInsertPending (osMessageQueueId_t mq_id, const void *msg_ptr); -#else -#define EvrRtxMessageQueueInsertPending(mq_id, msg_ptr) -#endif - -/** - \brief Event on successful message insert (Op) - \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. - \param[in] msg_ptr pointer to buffer with message to put into a queue. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_INSERTED_DISABLE)) -extern void EvrRtxMessageQueueInserted (osMessageQueueId_t mq_id, const void *msg_ptr); -#else -#define EvrRtxMessageQueueInserted(mq_id, msg_ptr) -#endif - -/** - \brief Event on unsuccessful message insert (Op) - \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. - \param[in] msg_ptr pointer to buffer with message to put into a queue. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_NOT_INSERTED_DISABLE)) -extern void EvrRtxMessageQueueNotInserted (osMessageQueueId_t mq_id, const void *msg_ptr); -#else -#define EvrRtxMessageQueueNotInserted(mq_id, msg_ptr) -#endif - -/** - \brief Event on message get (API) - \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. - \param[in] msg_ptr pointer to buffer for message to get from a queue. - \param[in] msg_prio message priority. - \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_DISABLE)) -extern void EvrRtxMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout); -#else -#define EvrRtxMessageQueueGet(mq_id, msg_ptr, msg_prio, timeout) -#endif - -/** - \brief Event on pending message get (Op) - \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. - \param[in] msg_ptr pointer to buffer for message to get from a queue. - \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_PENDING_DISABLE)) -extern void EvrRtxMessageQueueGetPending (osMessageQueueId_t mq_id, void *msg_ptr, uint32_t timeout); -#else -#define EvrRtxMessageQueueGetPending(mq_id, msg_ptr, timeout) -#endif - -/** - \brief Event on message get timeout (Op) - \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_TIMEOUT_DISABLE)) -extern void EvrRtxMessageQueueGetTimeout (osMessageQueueId_t mq_id); -#else -#define EvrRtxMessageQueueGetTimeout(mq_id) -#endif - -/** - \brief Event on successful message get (Op) - \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. - \param[in] msg_ptr pointer to buffer for message to get from a queue. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_RETRIEVED_DISABLE)) -extern void EvrRtxMessageQueueRetrieved (osMessageQueueId_t mq_id, void *msg_ptr); -#else -#define EvrRtxMessageQueueRetrieved(mq_id, msg_ptr) -#endif - -/** - \brief Event on unsuccessful message get (Op) - \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. - \param[in] msg_ptr pointer to buffer for message to get from a queue. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_NOT_RETRIEVED_DISABLE)) -extern void EvrRtxMessageQueueNotRetrieved (osMessageQueueId_t mq_id, void *msg_ptr); -#else -#define EvrRtxMessageQueueNotRetrieved(mq_id, msg_ptr) -#endif - -/** - \brief Event on message queue capacity retrieve (API) - \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. - \param[in] capacity maximum number of messages. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_CAPACITY_DISABLE)) -extern void EvrRtxMessageQueueGetCapacity (osMessageQueueId_t mq_id, uint32_t capacity); -#else -#define EvrRtxMessageQueueGetCapacity(mq_id, capacity) -#endif - -/** - \brief Event on message queue message size retrieve (API) - \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. - \param[in] msg_size maximum message size in bytes. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_MSG_SIZE_DISABLE)) -extern void EvrRtxMessageQueueGetMsgSize (osMessageQueueId_t mq_id, uint32_t msg_size); -#else -#define EvrRtxMessageQueueGetMsgSize(mq_id, msg_size) -#endif - -/** - \brief Event on message queue message count retrieve (API) - \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. - \param[in] count number of queued messages. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_COUNT_DISABLE)) -extern void EvrRtxMessageQueueGetCount (osMessageQueueId_t mq_id, uint32_t count); -#else -#define EvrRtxMessageQueueGetCount(mq_id, count) -#endif - -/** - \brief Event on message queue message slots retrieve (API) - \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. - \param[in] space number of available slots for messages. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_GET_SPACE_DISABLE)) -extern void EvrRtxMessageQueueGetSpace (osMessageQueueId_t mq_id, uint32_t space); -#else -#define EvrRtxMessageQueueGetSpace(mq_id, space) -#endif - -/** - \brief Event on message queue reset (API) - \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_RESET_DISABLE)) -extern void EvrRtxMessageQueueReset (osMessageQueueId_t mq_id); -#else -#define EvrRtxMessageQueueReset(mq_id) -#endif - -/** - \brief Event on successful message queue reset (Op) - \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_RESET_DONE_DISABLE)) -extern void EvrRtxMessageQueueResetDone (osMessageQueueId_t mq_id); -#else -#define EvrRtxMessageQueueResetDone(mq_id) -#endif - -/** - \brief Event on message queue delete (API) - \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_DELETE_DISABLE)) -extern void EvrRtxMessageQueueDelete (osMessageQueueId_t mq_id); -#else -#define EvrRtxMessageQueueDelete(mq_id) -#endif - -/** - \brief Event on successful message queue delete (Op) - \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew. -*/ -#if (!defined(EVR_RTX_DISABLE) && (OS_EVR_MSGQUEUE != 0) && !defined(EVR_RTX_MESSAGE_QUEUE_DESTROYED_DISABLE)) -extern void EvrRtxMessageQueueDestroyed (osMessageQueueId_t mq_id); -#else -#define EvrRtxMessageQueueDestroyed(mq_id) -#endif - - -#endif // RTX_EVR_H_ -/** @}*/ diff --git a/rtos/rtx5/TARGET_CORTEX_M/rtx_kernel.c b/rtos/rtx5/TARGET_CORTEX_M/rtx_kernel.c deleted file mode 100644 index d9b9a7a..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/rtx_kernel.c +++ /dev/null @@ -1,643 +0,0 @@ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ----------------------------------------------------------------------------- - * - * Project: CMSIS-RTOS RTX - * Title: Kernel functions - * - * ----------------------------------------------------------------------------- - */ - -#include "rtx_lib.h" -#include "rt_OsEventObserver.h" - - -// OS Runtime Information -osRtxInfo_t osRtxInfo __attribute__((section(".data.os"))) = -{ .os_id = osRtxKernelId, .version = osRtxVersionKernel, .kernel.state = osRtxKernelInactive }; - - -// ==== Helper functions ==== - -/// Block Kernel (disable: thread switching, time tick, post ISR processing). -static void KernelBlock (void) { - - if (osRtxInfo.tick_irqn >= 0) { - ExtTick_DisableIRQ(osRtxInfo.tick_irqn); - } - osRtxSysTimerDisable(); - osRtxInfo.kernel.blocked = 1U; - __DSB(); - if (osRtxInfo.tick_irqn < 0) { - osRtxInfo.kernel.pendISR = GetPendSV_ST(); - ClrPendSV_ST(); - } else { - osRtxInfo.kernel.pendISR = GetPendSV(); - ClrPendSV(); - } -} - -/// Unblock Kernel -static void KernelUnblock (void) { - - osRtxInfo.kernel.blocked = 0U; - __DSB(); - if (osRtxInfo.kernel.pendSV != 0U) { - osRtxInfo.kernel.pendSV = 0U; - SetPendSV(); - } - if (osRtxInfo.kernel.pendISR != 0U) { - SetPendFlags(osRtxInfo.kernel.pendISR); - } - if (osRtxInfo.tick_irqn >= 0) { - ExtTick_EnableIRQ(osRtxInfo.tick_irqn); - } - osRtxSysTimerEnable(); -} - - -// ==== Service Calls ==== - -// Service Calls definitions -SVC0_0M(KernelInitialize, osStatus_t) -SVC0_3 (KernelGetInfo, osStatus_t, osVersion_t *, char *, uint32_t) -SVC0_0M(KernelStart, osStatus_t) -SVC0_0 (KernelLock, int32_t) -SVC0_0 (KernelUnlock, int32_t) -SVC0_1 (KernelRestoreLock, int32_t, int32_t) -SVC0_0 (KernelSuspend, uint32_t) -SVC0_1N(KernelResume, void, uint32_t) -SVC0_0 (KernelGetState, osKernelState_t) -SVC0_0D(KernelGetTickCount, uint64_t) -SVC0_0 (KernelGetTickFreq, uint32_t) -SVC0_0 (KernelGetSysTimerCount, uint32_t) -SVC0_0 (KernelGetSysTimerFreq, uint32_t) - -/// Initialize the RTOS Kernel. -/// \note API identical to osKernelInitialize -osStatus_t svcRtxKernelInitialize (void) { - - if (osRtxInfo.kernel.state == osRtxKernelReady) { - EvrRtxKernelInitializeCompleted(); - return osOK; - } - if (osRtxInfo.kernel.state != osKernelInactive) { - EvrRtxKernelError(osError); - return osError; - } - - // Initialize osRtxInfo - memset(&osRtxInfo.kernel, 0, sizeof(osRtxInfo) - offsetof(osRtxInfo_t, kernel)); - - if (osRtxConfig.thread_stack_size < (64U + 8U)) { - EvrRtxKernelError(osRtxErrorInvalidThreadStack); - return osError; - } - - if ((osRtxConfig.isr_queue.data == NULL) || (osRtxConfig.isr_queue.max == 0U)) { - EvrRtxKernelError(osError); - return osError; - } - osRtxInfo.isr_queue.data = osRtxConfig.isr_queue.data; - osRtxInfo.isr_queue.max = osRtxConfig.isr_queue.max; - - osRtxInfo.thread.robin.timeout = osRtxConfig.robin_timeout; - - // Initialize Memory Pools (Variable Block Size) - if (osRtxMemoryInit(osRtxConfig.mem.common_addr, osRtxConfig.mem.common_size) != 0U) { - osRtxInfo.mem.common = osRtxConfig.mem.common_addr; - } - if (osRtxMemoryInit(osRtxConfig.mem.stack_addr, osRtxConfig.mem.stack_size) != 0U) { - osRtxInfo.mem.stack = osRtxConfig.mem.stack_addr; - } else { - osRtxInfo.mem.stack = osRtxInfo.mem.common; - } - if (osRtxMemoryInit(osRtxConfig.mem.mp_data_addr, osRtxConfig.mem.mp_data_size) != 0U) { - osRtxInfo.mem.mp_data = osRtxConfig.mem.mp_data_addr; - } else { - osRtxInfo.mem.mp_data = osRtxInfo.mem.common; - } - if (osRtxMemoryInit(osRtxConfig.mem.mq_data_addr, osRtxConfig.mem.mq_data_size) != 0U) { - osRtxInfo.mem.mq_data = osRtxConfig.mem.mq_data_addr; - } else { - osRtxInfo.mem.mq_data = osRtxInfo.mem.common; - } - - // Initialize Memory Pools (Fixed Block Size) - if ((osRtxConfig.mpi.stack != NULL) && - (osRtxMemoryPoolInit(osRtxConfig.mpi.stack, - osRtxConfig.mpi.stack->max_blocks, - osRtxConfig.mpi.stack->block_size, - osRtxConfig.mpi.stack->block_base) != 0U)) { - osRtxInfo.mpi.stack = osRtxConfig.mpi.stack; - } - if ((osRtxConfig.mpi.thread != NULL) && - (osRtxMemoryPoolInit(osRtxConfig.mpi.thread, - osRtxConfig.mpi.thread->max_blocks, - osRtxConfig.mpi.thread->block_size, - osRtxConfig.mpi.thread->block_base) != 0U)) { - osRtxInfo.mpi.thread = osRtxConfig.mpi.thread; - } - if ((osRtxConfig.mpi.timer != NULL) && - (osRtxMemoryPoolInit(osRtxConfig.mpi.timer, - osRtxConfig.mpi.timer->max_blocks, - osRtxConfig.mpi.timer->block_size, - osRtxConfig.mpi.timer->block_base) != 0U)) { - osRtxInfo.mpi.timer = osRtxConfig.mpi.timer; - } - if ((osRtxConfig.mpi.event_flags != NULL) && - (osRtxMemoryPoolInit(osRtxConfig.mpi.event_flags, - osRtxConfig.mpi.event_flags->max_blocks, - osRtxConfig.mpi.event_flags->block_size, - osRtxConfig.mpi.event_flags->block_base) != 0U)) { - osRtxInfo.mpi.event_flags = osRtxConfig.mpi.event_flags; - } - if ((osRtxConfig.mpi.mutex != NULL) && - (osRtxMemoryPoolInit(osRtxConfig.mpi.mutex, - osRtxConfig.mpi.mutex->max_blocks, - osRtxConfig.mpi.mutex->block_size, - osRtxConfig.mpi.mutex->block_base) != 0U)) { - osRtxInfo.mpi.mutex = osRtxConfig.mpi.mutex; - } - if ((osRtxConfig.mpi.semaphore != NULL) && - (osRtxMemoryPoolInit(osRtxConfig.mpi.semaphore, - osRtxConfig.mpi.semaphore->max_blocks, - osRtxConfig.mpi.semaphore->block_size, - osRtxConfig.mpi.semaphore->block_base) != 0U)) { - osRtxInfo.mpi.semaphore = osRtxConfig.mpi.semaphore; - } - if ((osRtxConfig.mpi.memory_pool != NULL) && - (osRtxMemoryPoolInit(osRtxConfig.mpi.memory_pool, - osRtxConfig.mpi.memory_pool->max_blocks, - osRtxConfig.mpi.memory_pool->block_size, - osRtxConfig.mpi.memory_pool->block_base) != 0U)) { - osRtxInfo.mpi.memory_pool = osRtxConfig.mpi.memory_pool; - } - if ((osRtxConfig.mpi.message_queue != NULL) && - (osRtxMemoryPoolInit(osRtxConfig.mpi.message_queue, - osRtxConfig.mpi.message_queue->max_blocks, - osRtxConfig.mpi.message_queue->block_size, - osRtxConfig.mpi.message_queue->block_base) != 0U)) { - osRtxInfo.mpi.message_queue = osRtxConfig.mpi.message_queue; - } - -#if (__DOMAIN_NS == 1U) - // Initialize Secure Process Stack - if (TZ_InitContextSystem_S() == 0U) { - EvrRtxKernelError(osRtxErrorTZ_InitContext_S); - return osError; - } -#endif - - // Initialize SVC and PendSV System Service Calls - SVC_Initialize(); - - osRtxInfo.kernel.state = osRtxKernelReady; - - EvrRtxKernelInitializeCompleted(); - - return osOK; -} - -/// Get RTOS Kernel Information. -/// \note API identical to osKernelGetInfo -osStatus_t svcRtxKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size) { - - if (version != NULL) { - version->api = osRtxVersionAPI; - version->kernel = osRtxVersionKernel; - } - - if ((id_buf != NULL) && (id_size != 0U)) { - if (id_size > sizeof(osRtxKernelId)) { - id_size = sizeof(osRtxKernelId); - } - memcpy(id_buf, osRtxKernelId, id_size); - } - - EvrRtxKernelInfoRetrieved(version, id_buf); - - return osOK; -} - -/// Get the current RTOS Kernel state. -/// \note API identical to osKernelGetState -osKernelState_t svcRtxKernelGetState (void) { - EvrRtxKernelGetState((osKernelState_t)(osRtxInfo.kernel.state)); - return ((osKernelState_t)(osRtxInfo.kernel.state)); -} - -/// Start the RTOS Kernel scheduler. -/// \note API identical to osKernelStart -osStatus_t svcRtxKernelStart (void) { - os_thread_t *thread; - - if (osRtxInfo.kernel.state != osRtxKernelReady) { - EvrRtxKernelError(osRtxErrorKernelNotReady); - return osError; - } - - // Create Idle Thread - if (osRtxInfo.thread.idle == NULL) { - osRtxInfo.thread.idle = svcRtxThreadNew(osRtxIdleThread, NULL, osRtxConfig.idle_thread_attr, NULL); - if (osRtxInfo.thread.idle == NULL) { - EvrRtxKernelError(osError); - return osError; - } - } - - // Create Timer Thread - if (osRtxConfig.timer_mq_mcnt != 0U) { - if (osRtxInfo.timer.thread == NULL) { - osRtxInfo.timer.thread = svcRtxThreadNew(osRtxTimerThread, NULL, osRtxConfig.timer_thread_attr, NULL); - if (osRtxInfo.timer.thread == NULL) { - EvrRtxKernelError(osError); - return osError; - } - } - } - - // Switch to Ready Thread with highest Priority - thread = osRtxThreadListGet(&osRtxInfo.thread.ready); - if (thread == NULL) { - EvrRtxKernelError(osError); - return osError; - } - osRtxThreadSwitch(thread); - - if ((osRtxConfig.flags & osRtxConfigPrivilegedMode) != 0U) { - // Privileged Thread mode & PSP - __set_CONTROL(0x02U); - } else { - // Unprivileged Thread mode & PSP - __set_CONTROL(0x03U); - } - - osRtxInfo.kernel.sys_freq = SystemCoreClock; - - // Setup and Enable System Timer - osRtxInfo.tick_irqn = osRtxSysTimerSetup(); - if (osRtxInfo.tick_irqn >= 0) { - ExtTick_SetupIRQ (osRtxInfo.tick_irqn); - ExtTick_EnableIRQ(osRtxInfo.tick_irqn); - } - osRtxSysTimerEnable(); - - osRtxInfo.kernel.state = osRtxKernelRunning; - - EvrRtxKernelStarted(); - - return osOK; -} - -/// Lock the RTOS Kernel scheduler. -/// \note API identical to osKernelLock -int32_t svcRtxKernelLock (void) { - - if (osRtxInfo.kernel.state == osRtxKernelLocked) { - EvrRtxKernelLocked(1); - return 1; - } - if (osRtxInfo.kernel.state == osRtxKernelRunning) { - osRtxInfo.kernel.state = osRtxKernelLocked; - EvrRtxKernelLocked(0); - return 0; - } - - EvrRtxKernelError(osError); - return osError; -} - -/// Unlock the RTOS Kernel scheduler. -/// \note API identical to osKernelUnlock -int32_t svcRtxKernelUnlock (void) { - - if (osRtxInfo.kernel.state == osRtxKernelLocked) { - osRtxInfo.kernel.state = osRtxKernelRunning; - EvrRtxKernelUnlocked(1); - return 1; - } - if (osRtxInfo.kernel.state == osRtxKernelRunning) { - EvrRtxKernelUnlocked(0); - return 0; - } - - EvrRtxKernelError(osError); - return osError; -} - -/// Restore the RTOS Kernel scheduler lock state. -/// \note API identical to osKernelRestoreLock -int32_t svcRtxKernelRestoreLock (int32_t lock) { - - if ((osRtxInfo.kernel.state == osRtxKernelRunning) || - (osRtxInfo.kernel.state == osRtxKernelLocked)) { - switch (lock) { - case 1: - osRtxInfo.kernel.state = osRtxKernelLocked; - EvrRtxKernelLockRestored(1); - return 1; - case 0: - osRtxInfo.kernel.state = osRtxKernelRunning; - EvrRtxKernelLockRestored(0); - return 0; - default: - break; - } - } - - EvrRtxKernelError(osError); - return osError; -} - -/// Suspend the RTOS Kernel scheduler. -/// \note API identical to osKernelSuspend -uint32_t svcRtxKernelSuspend (void) { - os_thread_t *thread; - os_timer_t *timer; - uint32_t delay; - - if (osRtxInfo.kernel.state != osRtxKernelRunning) { - EvrRtxKernelError(osRtxErrorKernelNotRunning); - return 0U; - } - - KernelBlock(); - - delay = osWaitForever; - - // Check Thread Delay list - thread = osRtxInfo.thread.delay_list; - if (thread != NULL) { - delay = thread->delay; - } - - // Check Active Timer list - timer = osRtxInfo.timer.list; - if (timer != NULL) { - if (timer->tick < delay) { - delay = timer->tick; - } - } - - osRtxInfo.kernel.state = osRtxKernelSuspended; - - EvrRtxKernelSuspended(delay); - - return delay; -} - -/// Resume the RTOS Kernel scheduler. -/// \note API identical to osKernelResume -void svcRtxKernelResume (uint32_t sleep_ticks) { - os_thread_t *thread; - os_timer_t *timer; - uint32_t delay; - - if (osRtxInfo.kernel.state != osRtxKernelSuspended) { - EvrRtxKernelResumed(); - return; - } - - // Process Thread Delay list - thread = osRtxInfo.thread.delay_list; - if (thread != NULL) { - delay = sleep_ticks; - if (delay >= thread->delay) { - delay -= thread->delay; - osRtxInfo.kernel.tick += thread->delay; - thread->delay = 1U; - do { - osRtxThreadDelayTick(); - if (delay == 0U) { - break; - } - delay--; - osRtxInfo.kernel.tick++; - } while (osRtxInfo.thread.delay_list != NULL); - } else { - thread->delay -= delay; - osRtxInfo.kernel.tick += delay; - } - } else { - osRtxInfo.kernel.tick += sleep_ticks; - } - - // Process Active Timer list - timer = osRtxInfo.timer.list; - if (timer != NULL) { - if (sleep_ticks >= timer->tick) { - sleep_ticks -= timer->tick; - timer->tick = 1U; - do { - osRtxInfo.timer.tick(); - if (sleep_ticks == 0U) { - break; - } - sleep_ticks--; - } while (osRtxInfo.timer.list != NULL); - } else { - timer->tick -= sleep_ticks; - } - } - - osRtxInfo.kernel.state = osRtxKernelRunning; - - osRtxThreadDispatch(NULL); - - KernelUnblock(); - - EvrRtxKernelResumed(); -} - -/// Get the RTOS kernel tick count. -/// \note API identical to osKernelGetTickCount -uint64_t svcRtxKernelGetTickCount (void) { - EvrRtxKernelGetTickCount(osRtxInfo.kernel.tick); - return osRtxInfo.kernel.tick; -} - -/// Get the RTOS kernel tick frequency. -/// \note API identical to osKernelGetTickFreq -uint32_t svcRtxKernelGetTickFreq (void) { - EvrRtxKernelGetTickFreq(osRtxConfig.tick_freq); - return osRtxConfig.tick_freq; -} - -/// Get the RTOS kernel system timer count. -/// \note API identical to osKernelGetSysTimerCount -uint32_t svcRtxKernelGetSysTimerCount (void) { - uint32_t count = osRtxSysTimerGetCount(); - EvrRtxKernelGetSysTimerCount(count); - return count; -} - -/// Get the RTOS kernel system timer frequency. -/// \note API identical to osKernelGetSysTimerFreq -uint32_t svcRtxKernelGetSysTimerFreq (void) { - uint32_t freq = osRtxSysTimerGetFreq(); - EvrRtxKernelGetSysTimerFreq(freq); - return freq; -} - - -// ==== Public API ==== - -/// Initialize the RTOS Kernel. -osStatus_t osKernelInitialize (void) { - EvrRtxKernelInitialize(); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxKernelError(osErrorISR); - return osErrorISR; - } - return __svcKernelInitialize(); -} - -/// Get RTOS Kernel Information. -osStatus_t osKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size) { - EvrRtxKernelGetInfo(version, id_buf, id_size); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxKernelError(osErrorISR); - return osErrorISR; - } - if (IS_PRIVILEGED()) { - return svcRtxKernelGetInfo(version, id_buf, id_size); - } else { - return __svcKernelGetInfo(version, id_buf, id_size); - } -} - -/// Get the current RTOS Kernel state. -osKernelState_t osKernelGetState (void) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxKernelGetState(osKernelError); - return osKernelError; - } - if (IS_PRIVILEGED()) { - return svcRtxKernelGetState(); - } else { - return __svcKernelGetState(); - } -} - -/// Start the RTOS Kernel scheduler. -osStatus_t osKernelStart (void) { - EvrRtxKernelStart(); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxKernelError(osErrorISR); - return osErrorISR; - } - - /* Call the pre-start event (from unprivileged mode) if the handler exists - * and the kernel is not running. */ - /* FIXME osEventObs needs to be readable but not writable from unprivileged - * code. */ - if (osKernelGetState() != osKernelRunning && osEventObs && osEventObs->pre_start) { - osEventObs->pre_start(); - } - - return __svcKernelStart(); -} - -/// Lock the RTOS Kernel scheduler. -int32_t osKernelLock (void) { - EvrRtxKernelLock(); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxKernelError(osErrorISR); - return osErrorISR; - } - return __svcKernelLock(); -} - -/// Unlock the RTOS Kernel scheduler. -int32_t osKernelUnlock (void) { - EvrRtxKernelUnlock(); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxKernelError(osErrorISR); - return osErrorISR; - } - return __svcKernelUnlock(); -} - -/// Restore the RTOS Kernel scheduler lock state. -int32_t osKernelRestoreLock (int32_t lock) { - EvrRtxKernelRestoreLock(lock); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxKernelError(osErrorISR); - return osErrorISR; - } - return __svcKernelRestoreLock(lock); -} - -/// Suspend the RTOS Kernel scheduler. -uint32_t osKernelSuspend (void) { - EvrRtxKernelSuspend(); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxKernelError(osErrorISR); - return 0U; - } - return __svcKernelSuspend(); -} - -/// Resume the RTOS Kernel scheduler. -void osKernelResume (uint32_t sleep_ticks) { - EvrRtxKernelResume(sleep_ticks); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxKernelError(osErrorISR); - return; - } - __svcKernelResume(sleep_ticks); -} - -/// Get the RTOS kernel tick count. -uint64_t osKernelGetTickCount (void) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxKernelGetTickCount(0U); - return 0U; - } else { - return __svcKernelGetTickCount(); - } -} - -/// Get the RTOS kernel tick frequency. -uint32_t osKernelGetTickFreq (void) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxKernelGetTickFreq(0U); - return 0U; - } else { - return __svcKernelGetTickFreq(); - } -} - -/// Get the RTOS kernel system timer count. -uint32_t osKernelGetSysTimerCount (void) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - return svcRtxKernelGetSysTimerCount(); - } else { - return __svcKernelGetSysTimerCount(); - } -} - -/// Get the RTOS kernel system timer frequency. -uint32_t osKernelGetSysTimerFreq (void) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - return svcRtxKernelGetSysTimerFreq(); - } else { - return __svcKernelGetSysTimerFreq(); - } -} diff --git a/rtos/rtx5/TARGET_CORTEX_M/rtx_lib.c b/rtos/rtx5/TARGET_CORTEX_M/rtx_lib.c deleted file mode 100644 index 4a157e9..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/rtx_lib.c +++ /dev/null @@ -1,634 +0,0 @@ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ----------------------------------------------------------------------------- - * - * Project: CMSIS-RTOS RTX - * Title: RTX Library Configuration - * - * ----------------------------------------------------------------------------- - */ - -#include "cmsis_compiler.h" -#include "rtx_os.h" -#include "RTX_Config.h" - - -// System Configuration -// ==================== - -// Dynamic Memory -#if (OS_DYNAMIC_MEM_SIZE != 0) -#if ((OS_DYNAMIC_MEM_SIZE & 7) != 0) -#error "Invalid Dynamic Memory size!" -#endif -static uint64_t os_mem[OS_DYNAMIC_MEM_SIZE/8] \ -__attribute__((section(".bss.os"))); -#endif - -// Kernel Tick Frequency -#if (OS_TICK_FREQ < 1) -#error "Invalid Kernel Tick Frequency!" -#endif - -// ISR FIFO Queue -static void *os_isr_queue[OS_ISR_FIFO_QUEUE] \ -__attribute__((section(".bss.os"))); - - -// Thread Configuration -// ==================== - -#if (((OS_STACK_SIZE & 7) != 0) || (OS_STACK_SIZE < 72)) -#error "Invalid default Thread Stack size!" -#endif - -#if (((OS_IDLE_THREAD_STACK_SIZE & 7) != 0) || (OS_IDLE_THREAD_STACK_SIZE < 72)) -#error "Invalid Idle Thread Stack size!" -#endif - - -#if (OS_THREAD_OBJ_MEM != 0) - -#if (OS_THREAD_NUM == 0) -#error "Invalid number of user Threads!" -#endif - -#if ((OS_THREAD_USER_STACK_SIZE != 0) && ((OS_THREAD_USER_STACK_SIZE & 7) != 0)) -#error "Invalid total Stack size!" -#endif - -// Thread Control Blocks -static osRtxThread_t os_thread_cb[OS_THREAD_NUM] \ -__attribute__((section(".bss.os.thread.cb"))); - -// Thread Default Stack -#if (OS_THREAD_DEF_STACK_NUM != 0) -static uint64_t os_thread_def_stack[OS_THREAD_DEF_STACK_NUM*(OS_STACK_SIZE/8)] \ -__attribute__((section(".bss.os.thread.stack"))); -#endif - -// Memory Pool for Thread Control Blocks -static osRtxMpInfo_t os_mpi_thread \ -__attribute__((section(".data.os.thread.mpi"))) = -{ (uint32_t)OS_THREAD_NUM, 0U, (uint32_t)osRtxThreadCbSize, &os_thread_cb, NULL, NULL }; - -// Memory Pool for Thread Default Stack -#if (OS_THREAD_DEF_STACK_NUM != 0) -static osRtxMpInfo_t os_mpi_def_stack \ -__attribute__((section(".data.os.thread.mpi"))) = -{ (uint32_t)OS_THREAD_DEF_STACK_NUM, 0U, (uint32_t)OS_STACK_SIZE, &os_thread_def_stack, NULL, NULL }; -#endif - -// Memory Pool for Thread Stack -#if (OS_THREAD_USER_STACK_SIZE != 0) -static uint64_t os_thread_stack[OS_THREAD_USER_STACK_SIZE/8] \ -__attribute__((section(".bss.os.thread.stack"))); -#endif - -#endif // (OS_THREAD_OBJ_MEM != 0) - - -// Stack overrun checking -#if (OS_STACK_CHECK == 0) -// Override library function -void osRtxThreadStackCheck (void); -void osRtxThreadStackCheck (void) {} -#endif - - -// Idle Thread Control Block -static osRtxThread_t os_idle_thread_cb \ -__attribute__((section(".bss.os.thread.cb"))); - -// Idle Thread Stack -static uint64_t os_idle_thread_stack[OS_IDLE_THREAD_STACK_SIZE/8] \ -__attribute__((section(".bss.os.thread.stack"))); - -// Idle Thread Attributes -static const osThreadAttr_t os_idle_thread_attr = { - NULL, - osThreadDetached, - &os_idle_thread_cb, - (uint32_t)sizeof(os_idle_thread_cb), - &os_idle_thread_stack, - (uint32_t)sizeof(os_idle_thread_stack), - osPriorityIdle, - 0U, 0U -}; - - -// Timer Configuration -// =================== - -#if (OS_TIMER_OBJ_MEM != 0) - -#if (OS_TIMER_NUM == 0) -#error "Invalid number of Timer objects!" -#endif - -// Timer Control Blocks -static osRtxTimer_t os_timer_cb[OS_TIMER_NUM] \ -__attribute__((section(".bss.os.timer.cb"))); - -// Memory Pool for Timer Control Blocks -static osRtxMpInfo_t os_mpi_timer \ -__attribute__((section(".data.os.timer.mpi"))) = -{ (uint32_t)OS_TIMER_NUM, 0U, (uint32_t)osRtxTimerCbSize, &os_timer_cb, NULL, NULL }; - -#endif // (OS_TIMER_OBJ_MEM != 0) - - -#if ((OS_TIMER_THREAD_STACK_SIZE != 0) && (OS_TIMER_CB_QUEUE != 0)) - -#if (((OS_TIMER_THREAD_STACK_SIZE & 7) != 0) || (OS_TIMER_THREAD_STACK_SIZE < 96)) -#error "Invalid Timer Thread Stack size!" -#endif - -// Timer Thread Control Block -static osRtxThread_t os_timer_thread_cb \ -__attribute__((section(".bss.os.thread.cb"))); - -// Timer Thread Stack -static uint64_t os_timer_thread_stack[OS_TIMER_THREAD_STACK_SIZE/8] \ -__attribute__((section(".bss.os.thread.stack"))); - -// Timer Thread Attributes -static const osThreadAttr_t os_timer_thread_attr = { - NULL, - osThreadDetached, - &os_timer_thread_cb, - (uint32_t)sizeof(os_timer_thread_cb), - &os_timer_thread_stack, - (uint32_t)sizeof(os_timer_thread_stack), - (osPriority_t)OS_TIMER_THREAD_PRIO, - 0U, 0U -}; - -// Timer Message Queue Control Block -static osRtxMessageQueue_t os_timer_mq_cb \ -__attribute__((section(".bss.os.msgqueue.cb"))); - -// Timer Message Queue Data -static uint32_t os_timer_mq_data[osRtxMessageQueueMemSize(OS_TIMER_CB_QUEUE,8)/4] \ -__attribute__((section(".bss.os.msgqueue.mem"))); - -// Timer Message Queue Attributes -static const osMessageQueueAttr_t os_timer_mq_attr = { - NULL, - 0U, - &os_timer_mq_cb, - (uint32_t)sizeof(os_timer_mq_cb), - &os_timer_mq_data, - (uint32_t)sizeof(os_timer_mq_data) -}; - -#else - -extern void osRtxTimerThread (void *argument); - void osRtxTimerThread (void *argument) {} - -#endif // ((OS_TIMER_THREAD_STACK_SIZE != 0) && (OS_TIMER_CB_QUEUE != 0)) - - -// Event Flags Configuration -// ========================= - -#if (OS_EVFLAGS_OBJ_MEM != 0) - -#if (OS_EVFLAGS_NUM == 0) -#error "Invalid number of Event Flags objects!" -#endif - -// Event Flags Control Blocks -static osRtxEventFlags_t os_ef_cb[OS_EVFLAGS_NUM] \ -__attribute__((section(".bss.os.evflags.cb"))); - -// Memory Pool for Event Flags Control Blocks -static osRtxMpInfo_t os_mpi_ef \ -__attribute__((section(".data.os.evflags.mpi"))) = -{ (uint32_t)OS_EVFLAGS_NUM, 0U, (uint32_t)osRtxEventFlagsCbSize, &os_ef_cb, NULL, NULL }; - -#endif // (OS_EVFLAGS_OBJ_MEM != 0) - - -// Mutex Configuration -// =================== - -#if (OS_MUTEX_OBJ_MEM != 0) - -#if (OS_MUTEX_NUM == 0) -#error "Invalid number of Mutex objects!" -#endif - -// Mutex Control Blocks -static osRtxMutex_t os_mutex_cb[OS_MUTEX_NUM] \ -__attribute__((section(".bss.os.mutex.cb"))); - -// Memory Pool for Mutex Control Blocks -static osRtxMpInfo_t os_mpi_mutex \ -__attribute__((section(".data.os.mutex.mpi"))) = -{ (uint32_t)OS_MUTEX_NUM, 0U, (uint32_t)osRtxMutexCbSize, &os_mutex_cb, NULL, NULL }; - -#endif // (OS_MUTEX_OBJ_MEM != 0) - - -// Semaphore Configuration -// ======================= - -#if (OS_SEMAPHORE_OBJ_MEM != 0) - -#if (OS_SEMAPHORE_NUM == 0) -#error "Invalid number of Semaphore objects!" -#endif - -// Semaphore Control Blocks -static osRtxSemaphore_t os_semaphore_cb[OS_SEMAPHORE_NUM] \ -__attribute__((section(".bss.os.semaphore.cb"))); - -// Memory Pool for Semaphore Control Blocks -static osRtxMpInfo_t os_mpi_semaphore \ -__attribute__((section(".data.os.semaphore.mpi"))) = -{ (uint32_t)OS_SEMAPHORE_NUM, 0U, (uint32_t)osRtxSemaphoreCbSize, &os_semaphore_cb, NULL, NULL }; - -#endif // (OS_SEMAPHORE_OBJ_MEM != 0) - - -// Memory Pool Configuration -// ========================= - -#if (OS_MEMPOOL_OBJ_MEM != 0) - -#if (OS_MEMPOOL_NUM == 0) -#error "Invalid number of Memory Pool objects!" -#endif - -// Memory Pool Control Blocks -static osRtxMemoryPool_t os_mp_cb[OS_MEMPOOL_NUM] \ -__attribute__((section(".bss.os.mempool.cb"))); - -// Memory Pool for Memory Pool Control Blocks -static osRtxMpInfo_t os_mpi_mp \ -__attribute__((section(".data.os.mempool.mpi"))) = -{ (uint32_t)OS_MEMPOOL_NUM, 0U, (uint32_t)osRtxMemoryPoolCbSize, &os_mp_cb, NULL, NULL }; - -// Memory Pool for Memory Pool Data Storage -#if (OS_MEMPOOL_DATA_SIZE != 0) -#if ((OS_MEMPOOL_DATA_SIZE & 7) != 0) -#error "Invalid Data Memory size for Memory Pools!" -#endif -static uint64_t os_mp_data[OS_MEMPOOL_DATA_SIZE/8] \ -__attribute__((section(".bss.os.mempool.mem"))); -#endif - -#endif // (OS_MEMPOOL_OBJ_MEM != 0) - - -// Message Queue Configuration -// =========================== - -#if (OS_MSGQUEUE_OBJ_MEM != 0) - -#if (OS_MSGQUEUE_NUM == 0) -#error "Invalid number of Message Queue objects!" -#endif - -// Message Queue Control Blocks -static osRtxMessageQueue_t os_mq_cb[OS_MSGQUEUE_NUM] \ -__attribute__((section(".bss.os.msgqueue.cb"))); - -// Memory Pool for Message Queue Control Blocks -static osRtxMpInfo_t os_mpi_mq \ -__attribute__((section(".data.os.msgqueue.mpi"))) = -{ (uint32_t)OS_MSGQUEUE_NUM, 0U, (uint32_t)osRtxMessageQueueCbSize, &os_mq_cb, NULL, NULL }; - -// Memory Pool for Message Queue Data Storage -#if (OS_MSGQUEUE_DATA_SIZE != 0) -#if ((OS_MSGQUEUE_DATA_SIZE & 7) != 0) -#error "Invalid Data Memory size for Message Queues!" -#endif -static uint64_t os_mq_data[OS_MSGQUEUE_DATA_SIZE/8] \ -__attribute__((section(".bss.os.msgqueue.mem"))); -#endif - -#endif // (OS_MSGQUEUE_OBJ_MEM != 0) - - -// OS Configuration -// ================ - -__USED -__attribute__((section(".rodata"))) -const osRtxConfig_t osRtxConfig = { - 0U // Flags -#if (OS_PRIVILEGE_MODE != 0) - | osRtxConfigPrivilegedMode -#endif -#if (OS_STACK_CHECK != 0) - | osRtxConfigStackCheck -#endif -#if (OS_STACK_WATERMARK != 0) - | osRtxConfigStackWatermark -#endif - , - (uint32_t)OS_TICK_FREQ, -#if (OS_ROBIN_ENABLE != 0) - (uint32_t)OS_ROBIN_TIMEOUT, -#else - 0U, -#endif - { &os_isr_queue[0], sizeof(os_isr_queue)/sizeof(void *), 0U }, - { - // Memory Pools (Variable Block Size) -#if ((OS_THREAD_OBJ_MEM != 0) && (OS_THREAD_USER_STACK_SIZE != 0)) - &os_thread_stack, (uint32_t)OS_THREAD_USER_STACK_SIZE, -#else - NULL, 0U, -#endif -#if ((OS_MEMPOOL_OBJ_MEM != 0) && (OS_MEMPOOL_DATA_SIZE != 0)) - &os_mp_data, (uint32_t)OS_MEMPOOL_DATA_SIZE, -#else - NULL, 0U, -#endif -#if ((OS_MSGQUEUE_OBJ_MEM != 0) && (OS_MSGQUEUE_DATA_SIZE != 0)) - &os_mq_data, (uint32_t)OS_MSGQUEUE_DATA_SIZE, -#else - NULL, 0U, -#endif -#if (OS_DYNAMIC_MEM_SIZE != 0) - &os_mem, (uint32_t)OS_DYNAMIC_MEM_SIZE, -#else - NULL, 0U -#endif - }, - { - // Memory Pools (Fixed Block Size) -#if (OS_THREAD_OBJ_MEM != 0) -#if (OS_THREAD_DEF_STACK_NUM != 0) - &os_mpi_def_stack, -#else - NULL, -#endif - &os_mpi_thread, -#else - NULL, - NULL, -#endif -#if (OS_TIMER_OBJ_MEM != 0) - &os_mpi_timer, -#else - NULL, -#endif -#if (OS_EVFLAGS_OBJ_MEM != 0) - &os_mpi_ef, -#else - NULL, -#endif -#if (OS_MUTEX_OBJ_MEM != 0) - &os_mpi_mutex, -#else - NULL, -#endif -#if (OS_SEMAPHORE_OBJ_MEM != 0) - &os_mpi_semaphore, -#else - NULL, -#endif -#if (OS_MEMPOOL_OBJ_MEM != 0) - &os_mpi_mp, -#else - NULL, -#endif -#if (OS_MSGQUEUE_OBJ_MEM != 0) - &os_mpi_mq, -#else - NULL, -#endif - }, - (uint32_t)OS_STACK_SIZE, - &os_idle_thread_attr, -#if ((OS_TIMER_THREAD_STACK_SIZE != 0) && (OS_TIMER_CB_QUEUE != 0)) - &os_timer_thread_attr, - &os_timer_mq_attr, - (uint32_t)OS_TIMER_CB_QUEUE -#else - NULL, - NULL, - 0U -#endif -}; - - -// Non weak reference to library irq module -extern uint8_t irqRtxLib; -extern const uint8_t *irqRtxLibRef; - const uint8_t *irqRtxLibRef = &irqRtxLib; - -// Default User SVC Table -extern void * const osRtxUserSVC[]; -__WEAK void * const osRtxUserSVC[1] = { (void *)0 }; - - -// OS Sections -// =========== - -#if (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) -__asm ( - ".weakref __os_thread_cb_start__, .bss.os.thread.cb$$Base\n\t" - ".weakref __os_thread_cb_end__, .bss.os.thread.cb$$Limit\n\t" - ".weakref __os_timer_cb_start__, .bss.os.timer.cb$$Base\n\t" - ".weakref __os_timer_cb_end__, .bss.os.timer.cb$$Limit\n\t" - ".weakref __os_evflags_cb_start__, .bss.os.evflags.cb$$Base\n\t" - ".weakref __os_evflags_cb_end__, .bss.os.evflags.cb$$Limit\n\t" - ".weakref __os_mutex_cb_start__, .bss.os.mutex.cb$$Base\n\t" - ".weakref __os_mutex_cb_end__, .bss.os.mutex.cb$$Limit\n\t" - ".weakref __os_semaphore_cb_start__, .bss.os.semaphore.cb$$Base\n\t" - ".weakref __os_semaphore_cb_end__, .bss.os.semaphore.cb$$Limit\n\t" - ".weakref __os_mempool_cb_start__, .bss.os.mempool.cb$$Base\n\t" - ".weakref __os_mempool_cb_end__, .bss.os.mempool.cb$$Limit\n\t" - ".weakref __os_msgqueue_cb_start__, .bss.os.msgqueue.cb$$Base\n\t" - ".weakref __os_msgqueue_cb_end__, .bss.os.msgqueue.cb$$Limit\n\t" -); -#endif - -#if (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) || \ - (defined(__GNUC__) && !defined(__CC_ARM)) - -extern __attribute__((weak)) uint32_t __os_thread_cb_start__; -extern __attribute__((weak)) uint32_t __os_thread_cb_end__; -extern __attribute__((weak)) uint32_t __os_timer_cb_start__; -extern __attribute__((weak)) uint32_t __os_timer_cb_end__; -extern __attribute__((weak)) uint32_t __os_evflags_cb_start__; -extern __attribute__((weak)) uint32_t __os_evflags_cb_end__; -extern __attribute__((weak)) uint32_t __os_mutex_cb_start__; -extern __attribute__((weak)) uint32_t __os_mutex_cb_end__; -extern __attribute__((weak)) uint32_t __os_semaphore_cb_start__; -extern __attribute__((weak)) uint32_t __os_semaphore_cb_end__; -extern __attribute__((weak)) uint32_t __os_mempool_cb_start__; -extern __attribute__((weak)) uint32_t __os_mempool_cb_end__; -extern __attribute__((weak)) uint32_t __os_msgqueue_cb_start__; -extern __attribute__((weak)) uint32_t __os_msgqueue_cb_end__; - -__asm (".global os_cb_sections"); - -extern const uint32_t os_cb_sections[]; - -__attribute__((section(".rodata"))) -const uint32_t os_cb_sections[] = { - (uint32_t)&__os_thread_cb_start__, - (uint32_t)&__os_thread_cb_end__, - (uint32_t)&__os_timer_cb_start__, - (uint32_t)&__os_timer_cb_end__, - (uint32_t)&__os_evflags_cb_start__, - (uint32_t)&__os_evflags_cb_end__, - (uint32_t)&__os_mutex_cb_start__, - (uint32_t)&__os_mutex_cb_end__, - (uint32_t)&__os_semaphore_cb_start__, - (uint32_t)&__os_semaphore_cb_end__, - (uint32_t)&__os_mempool_cb_start__, - (uint32_t)&__os_mempool_cb_end__, - (uint32_t)&__os_msgqueue_cb_start__, - (uint32_t)&__os_msgqueue_cb_end__ -}; - -#endif - - -// OS Initialization -// ================= - -#if defined(__CC_ARM) || \ - (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) - -#ifndef __MICROLIB -extern void _platform_post_stackheap_init (void); -__WEAK void _platform_post_stackheap_init (void) { - osKernelInitialize(); -} -#endif - -#elif defined(__GNUC__) - -extern void software_init_hook (void); -__WEAK void software_init_hook (void) { - osKernelInitialize(); -} - -#endif - - -// C/C++ Standard Library Multithreading Interface -// =============================================== - -#if (( defined(__CC_ARM) || \ - (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050))) && \ - !defined(__MICROLIB)) - -#define LIBSPACE_SIZE 96 - -// Memory for libspace -static uint32_t os_libspace[OS_THREAD_LIBSPACE_NUM+1][LIBSPACE_SIZE/sizeof(uint32_t)] \ -__attribute__((section(".bss.os"))); - -// Thread IDs for libspace -static osThreadId_t os_libspace_id[OS_THREAD_LIBSPACE_NUM] \ -__attribute__((section(".bss.os"))); - -// Check if Kernel has been started -static uint32_t os_kernel_is_active (void) { - static uint8_t os_kernel_active = 0U; - - if (os_kernel_active == 0U) { - if (osKernelGetState() > osKernelReady) { - os_kernel_active = 1U; - return 1U; - } - return 0U; - } else { - return 1U; - } -} - -// Provide libspace for current thread -void *__user_perthread_libspace (void); -void *__user_perthread_libspace (void) { - osThreadId_t id; - uint32_t n; - - if (!os_kernel_is_active()) { - return (void *)&os_libspace[OS_THREAD_LIBSPACE_NUM][0]; - } - - id = osThreadGetId(); - for (n = 0U; n < OS_THREAD_LIBSPACE_NUM; n++) { - if (os_libspace_id[n] == NULL) { - os_libspace_id[n] = id; - return (void *)&os_libspace[n][0]; - } - if (os_libspace_id[n] == id) { - return (void *)&os_libspace[n][0]; - } - } - - if (n == OS_THREAD_LIBSPACE_NUM) { - osRtxErrorNotify(osRtxErrorClibSpace, id); - } - - return (void *)&os_libspace[n][0]; -} - -// Mutex identifier -typedef void *mutex; - -// Initialize mutex -__USED -int _mutex_initialize(mutex *m); -__WEAK int _mutex_initialize(mutex *m) { - *m = osMutexNew(NULL); - if (*m == NULL) { - osRtxErrorNotify(osRtxErrorClibMutex, m); - return 0; - } - return 1; -} - -// Acquire mutex -__USED -void _mutex_acquire(mutex *m); -__WEAK void _mutex_acquire(mutex *m) { - if (os_kernel_is_active()) { - osMutexAcquire(*m, osWaitForever); - } -} - -// Release mutex -__USED -void _mutex_release(mutex *m); -__WEAK void _mutex_release(mutex *m) { - if (os_kernel_is_active()) { - osMutexRelease(*m); - } -} - -// Free mutex -__USED -void _mutex_free(mutex *m); -__WEAK void _mutex_free(mutex *m) { - osMutexDelete(*m); -} - -#endif diff --git a/rtos/rtx5/TARGET_CORTEX_M/rtx_lib.h b/rtos/rtx5/TARGET_CORTEX_M/rtx_lib.h deleted file mode 100644 index fb7423d..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/rtx_lib.h +++ /dev/null @@ -1,216 +0,0 @@ -/** \addtogroup rtos */ -/** @{*/ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ----------------------------------------------------------------------------- - * - * Project: CMSIS-RTOS RTX - * Title: RTX Library definitions - * - * ----------------------------------------------------------------------------- - */ - -#ifndef RTX_LIB_H_ -#define RTX_LIB_H_ - -#include -#include -#include "core_cm.h" // Cortex-M definitions -#include "tz_context.h" // TrustZone Context API -#include "cmsis_os2.h" // CMSIS RTOS API -#include "rtx_os.h" // RTX OS definitions -#include "rtx_evr.h" // RTX Event Recorder definitions - - -// ==== Library defines ==== - -#define os_thread_t osRtxThread_t -#define os_timer_t osRtxTimer_t -#define os_timer_finfo_t osRtxTimerFinfo_t -#define os_event_flags_t osRtxEventFlags_t -#define os_mutex_t osRtxMutex_t -#define os_semaphore_t osRtxSemaphore_t -#define os_mp_info_t osRtxMpInfo_t -#define os_memory_pool_t osRtxMemoryPool_t -#define os_message_t osRtxMessage_t -#define os_message_queue_t osRtxMessageQueue_t -#define os_object_t osRtxObject_t - -// ==== Inline functions ==== - -// Kernel Inline functions -__STATIC_INLINE uint8_t osRtxKernelGetState (void) { return osRtxInfo.kernel.state; } - -// Thread Inline functions -__STATIC_INLINE os_thread_t *osRtxThreadGetRunning (void) { return osRtxInfo.thread.run.curr; } -__STATIC_INLINE void osRtxThreadSetRunning (os_thread_t *thread) { osRtxInfo.thread.run.curr = thread; } - - -// ==== Library functions ==== - -// Thread Library functions -extern void osRtxThreadListPut (volatile os_object_t *object, os_thread_t *thread); -extern os_thread_t *osRtxThreadListGet (volatile os_object_t *object); -extern void *osRtxThreadListRoot (os_thread_t *thread); -extern void osRtxThreadListSort (os_thread_t *thread); -extern void osRtxThreadListRemove (os_thread_t *thread); -extern void osRtxThreadListUnlink (os_thread_t **thread_list, os_thread_t *thread); -extern void osRtxThreadReadyPut (os_thread_t *thread); -extern void osRtxThreadDelayInsert (os_thread_t *thread, uint32_t delay); -extern void osRtxThreadDelayRemove (os_thread_t *thread); -extern void osRtxThreadDelayTick (void); -extern uint32_t *osRtxThreadRegPtr (os_thread_t *thread); -extern void osRtxThreadBlock (os_thread_t *thread); -extern void osRtxThreadSwitch (os_thread_t *thread); -extern void osRtxThreadDispatch (os_thread_t *thread); -extern void osRtxThreadWaitExit (os_thread_t *thread, uint32_t ret_val, bool dispatch); -extern bool osRtxThreadWaitEnter (uint8_t state, uint32_t timeout); -extern void osRtxThreadStackCheck (void); - -// Timer Library functions -extern void osRtxTimerTick (void); -extern void osRtxTimerThread (void *argument); - -// Mutex Library functions -extern void osRtxMutexOwnerRelease (os_mutex_t *mutex_list); - -// Memory Heap Library functions -extern uint32_t osRtxMemoryInit (void *mem, uint32_t size); -extern void *osRtxMemoryAlloc(void *mem, uint32_t size, uint32_t type); -extern uint32_t osRtxMemoryFree (void *mem, void *block); - -// Memory Pool Library functions -extern uint32_t osRtxMemoryPoolInit (os_mp_info_t *mp_info, uint32_t blocks, uint32_t block_size, void *block_mem); -extern void *osRtxMemoryPoolAlloc (os_mp_info_t *mp_info); -extern osStatus_t osRtxMemoryPoolFree (os_mp_info_t *mp_info, void *block); - -// System Library functions -extern void osRtxTick_Handler (void); -extern void osRtxPendSV_Handler (void); -extern void osRtxPostProcess (os_object_t *object); - -// Post ISR processing functions -extern void osRtxThreadPostProcess (os_thread_t *thread); -extern void osRtxEventFlagsPostProcess (os_event_flags_t *ef); -extern void osRtxSemaphorePostProcess (os_semaphore_t *semaphore); -extern void osRtxMemoryPoolPostProcess (os_memory_pool_t *mp); -extern void osRtxMessageQueuePostProcess (os_message_t *msg); - - -// ==== Service Calls ==== - -// Kernel Service Calls -extern osStatus_t svcRtxKernelInitialize (void); -extern osStatus_t svcRtxKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size); -extern osKernelState_t svcRtxKernelGetState (void); -extern osStatus_t svcRtxKernelStart (void); -extern int32_t svcRtxKernelLock (void); -extern int32_t svcRtxKernelUnlock (void); -extern int32_t svcRtxKernelRestoreLock (int32_t lock); -extern uint32_t svcRtxKernelSuspend (void); -extern void svcRtxKernelResume (uint32_t sleep_ticks); -extern uint64_t svcRtxKernelGetTickCount (void); -extern uint32_t svcRtxKernelGetTickFreq (void); -extern uint32_t svcRtxKernelGetSysTimerCount (void); -extern uint32_t svcRtxKernelGetSysTimerFreq (void); - -// Thread Service Calls -extern osThreadId_t svcRtxThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr, void *context); -extern const char * svcRtxThreadGetName (osThreadId_t thread_id); -extern osThreadId_t svcRtxThreadGetId (void); -extern osThreadState_t svcRtxThreadGetState (osThreadId_t thread_id); -extern uint32_t svcRtxThreadGetStackSize (osThreadId_t thread_id); -extern uint32_t svcRtxThreadGetStackSpace(osThreadId_t thread_id); -extern osStatus_t svcRtxThreadSetPriority (osThreadId_t thread_id, osPriority_t priority); -extern osPriority_t svcRtxThreadGetPriority (osThreadId_t thread_id); -extern osStatus_t svcRtxThreadYield (void); -extern osStatus_t svcRtxThreadSuspend (osThreadId_t thread_id); -extern osStatus_t svcRtxThreadResume (osThreadId_t thread_id); -extern osStatus_t svcRtxThreadDetach (osThreadId_t thread_id); -extern osStatus_t svcRtxThreadJoin (osThreadId_t thread_id); -extern void svcRtxThreadExit (void); -extern osStatus_t svcRtxThreadTerminate (osThreadId_t thread_id); -extern uint32_t svcRtxThreadGetCount (void); -extern uint32_t svcRtxThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items); -extern uint32_t svcRtxThreadFlagsSet (osThreadId_t thread_id, uint32_t flags); -extern uint32_t svcRtxThreadFlagsClear (uint32_t flags); -extern uint32_t svcRtxThreadFlagsGet (void); -extern uint32_t svcRtxThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout); - -// Delay Service Calls -extern osStatus_t svcRtxDelay (uint32_t ticks); -extern osStatus_t svcRtxDelayUntil (uint32_t ticks_l, uint32_t ticks_h); - -// Timer Service Calls -extern osTimerId_t svcRtxTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr); -extern const char * svcRtxTimerGetName (osTimerId_t timer_id); -extern osStatus_t svcRtxTimerStart (osTimerId_t timer_id, uint32_t ticks); -extern osStatus_t svcRtxTimerStop (osTimerId_t timer_id); -extern uint32_t svcRtxTimerIsRunning (osTimerId_t timer_id); -extern osStatus_t svcRtxTimerDelete (osTimerId_t timer_id); - -// Event Flags Service Calls -extern osEventFlagsId_t svcRtxEventFlagsNew (const osEventFlagsAttr_t *attr); -extern const char * svcRtxEventFlagsGetName (osEventFlagsId_t ef_id); -extern uint32_t svcRtxEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags); -extern uint32_t svcRtxEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags); -extern uint32_t svcRtxEventFlagsGet (osEventFlagsId_t ef_id); -extern uint32_t svcRtxEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout); -extern osStatus_t svcRtxEventFlagsDelete (osEventFlagsId_t ef_id); - -// Mutex Service Calls -extern osMutexId_t svcRtxMutexNew (const osMutexAttr_t *attr); -extern const char * svcRtxMutexGetName (osMutexId_t mutex_id); -extern osStatus_t svcRtxMutexAcquire (osMutexId_t mutex_id, uint32_t timeout); -extern osStatus_t svcRtxMutexRelease (osMutexId_t mutex_id); -extern osThreadId_t svcRtxMutexGetOwner (osMutexId_t mutex_id); -extern osStatus_t svcRtxMutexDelete (osMutexId_t mutex_id); - -// Semaphore Service Calls -extern osSemaphoreId_t svcRtxSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr); -extern const char * svcRtxSemaphoreGetName (osSemaphoreId_t semaphore_id); -extern osStatus_t svcRtxSemaphoreRelease (osSemaphoreId_t semaphore_id); -extern osStatus_t svcRtxSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout); -extern uint32_t svcRtxSemaphoreGetCount(osSemaphoreId_t semaphore_id); -extern osStatus_t svcRtxSemaphoreDelete (osSemaphoreId_t semaphore_id); - -// Memory Pool Service Calls -extern osMemoryPoolId_t svcRtxMemoryPoolNew (uint32_t blocks, uint32_t block_size, const osMemoryPoolAttr_t *attr); -extern const char * svcRtxMemoryPoolGetName (osMemoryPoolId_t mp_id); -extern void * svcRtxMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout); -extern osStatus_t svcRtxMemoryPoolFree (osMemoryPoolId_t mp_id, void *block); -extern uint32_t svcRtxMemoryPoolGetCapacity (osMemoryPoolId_t mp_id); -extern uint32_t svcRtxMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id); -extern uint32_t svcRtxMemoryPoolGetCount (osMemoryPoolId_t mp_id); -extern uint32_t svcRtxMemoryPoolGetSpace (osMemoryPoolId_t mp_id); -extern osStatus_t svcRtxMemoryPoolDelete (osMemoryPoolId_t mp_id); - -// Message Queue Service Calls -extern osMessageQueueId_t svcRtxMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr); -extern const char * svcRtxMessageQueueGetName (osMessageQueueId_t mq_id); -extern osStatus_t svcRtxMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout); -extern osStatus_t svcRtxMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout); -extern uint32_t svcRtxMessageQueueGetCapacity (osMessageQueueId_t mq_id); -extern uint32_t svcRtxMessageQueueGetMsgSize (osMessageQueueId_t mq_id); -extern uint32_t svcRtxMessageQueueGetCount (osMessageQueueId_t mq_id); -extern uint32_t svcRtxMessageQueueGetSpace (osMessageQueueId_t mq_id); -extern osStatus_t svcRtxMessageQueueReset (osMessageQueueId_t mq_id); -extern osStatus_t svcRtxMessageQueueDelete (osMessageQueueId_t mq_id); - -#endif // RTX_LIB_H_ -/** @}*/ diff --git a/rtos/rtx5/TARGET_CORTEX_M/rtx_memory.c b/rtos/rtx5/TARGET_CORTEX_M/rtx_memory.c deleted file mode 100644 index f86e802..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/rtx_memory.c +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ----------------------------------------------------------------------------- - * - * Project: CMSIS-RTOS RTX - * Title: Memory functions - * - * ----------------------------------------------------------------------------- - */ - -#include "rtx_lib.h" - - -// Memory Pool Header structure -typedef struct mem_head_s { - uint32_t size; // Memory Pool size - uint32_t used; // Used Memory -} mem_head_t; - -// Memory Block Header structure -typedef struct mem_block_s { - struct mem_block_s *next; // Next Memory Block in list - uint32_t info; // Info: length = <31:2>:'00', type = <1:0> -} mem_block_t; - -#define MB_INFO_LEN_MASK 0xFFFFFFFCU -#define MB_INFO_TYPE_MASK 0x00000003U - - -// ==== Library functions ==== - -/// Initialize Memory Pool with variable block size. -/// \param[in] mem pointer to memory pool. -/// \param[in] size size of a memory pool in bytes. -/// \return 1 - success, 0 - failure. -__WEAK uint32_t osRtxMemoryInit (void *mem, uint32_t size) { - mem_head_t *head; - mem_block_t *ptr; - - if ((mem == NULL) || ((uint32_t)mem & 7U) || (size & 7U) || - (size < (sizeof(mem_head_t) + 2*sizeof(mem_block_t)))) { - EvrRtxMemoryInit(mem, size, 0U); - return 0U; - } - - head = (mem_head_t *)mem; - head->size = size; - head->used = sizeof(mem_head_t) + sizeof(mem_block_t); - - ptr = (mem_block_t *)((uint32_t)mem + sizeof(mem_head_t)); - ptr->next = (mem_block_t *)((uint32_t)mem + size - sizeof(mem_block_t)); - ptr->next->next = NULL; - ptr->info = 0U; - - EvrRtxMemoryInit(mem, size, 1U); - - return 1U; -} - -/// Allocate a memory block from a Memory Pool. -/// \param[in] mem pointer to memory pool. -/// \param[in] size size of a memory block in bytes. -/// \param[in] type memory block type: 0 - generic, 1 - control block -/// \return allocated memory block or NULL in case of no memory is available. -__WEAK void *osRtxMemoryAlloc (void *mem, uint32_t size, uint32_t type) { - mem_block_t *p, *p_new, *ptr; - uint32_t hole_size; - - if ((mem == NULL) || (size == 0U) || (type & ~MB_INFO_TYPE_MASK)) { - EvrRtxMemoryAlloc(mem, size, type, NULL); - return NULL; - } - - // Add header to size - size += sizeof(mem_block_t); - // Make sure that block is 8-byte aligned - size = (size + 7U) & ~((uint32_t)7U); - - // Search for hole big enough - p = (mem_block_t *)((uint32_t)mem + sizeof(mem_head_t)); - for (;;) { - hole_size = (uint32_t)p->next - (uint32_t)p; - hole_size -= p->info & MB_INFO_LEN_MASK; - if (hole_size >= size) { - // Hole found - break; - } - p = p->next; - if (p->next == NULL) { - // Failed (end of list) - EvrRtxMemoryAlloc(mem, size, type, NULL); - return NULL; - } - } - - ((mem_head_t *)mem)->used += size; - - if (p->info == 0U) { - // No block allocated, set info of first element - p->info = size | type; - ptr = (mem_block_t *)((uint32_t)p + sizeof(mem_block_t)); - } else { - // Insert new element into the list - p_new = (mem_block_t *)((uint32_t)p + (p->info & MB_INFO_LEN_MASK)); - p_new->next = p->next; - p_new->info = size | type; - p->next = p_new; - ptr = (mem_block_t *)((uint32_t)p_new + sizeof(mem_block_t)); - } - - EvrRtxMemoryAlloc(mem, size, type, ptr); - - return ptr; -} - -/// Return an allocated memory block back to a Memory Pool. -/// \param[in] mem pointer to memory pool. -/// \param[in] block memory block to be returned to the memory pool. -/// \return 1 - success, 0 - failure. -__WEAK uint32_t osRtxMemoryFree (void *mem, void *block) { - mem_block_t *p, *p_prev, *ptr; - - if ((mem == NULL) || (block == NULL)) { - EvrRtxMemoryFree(mem, block, 0U); - return 0U; - } - - ptr = (mem_block_t *)((uint32_t)block - sizeof(mem_block_t)); - - // Search for header - p_prev = NULL; - p = (mem_block_t *)((uint32_t)mem + sizeof(mem_head_t)); - while (p != ptr) { - p_prev = p; - p = p->next; - if (p == NULL) { - // Not found - EvrRtxMemoryFree(mem, block, 0U); - return 0U; - } - } - - ((mem_head_t *)mem)->used -= p->info & MB_INFO_LEN_MASK; - - if (p_prev == NULL) { - // Release first block, only set info to 0 - p->info = 0U; - } else { - // Discard block from chained list - p_prev->next = p->next; - } - - EvrRtxMemoryFree(mem, block, 1U); - - return 1U; -} diff --git a/rtos/rtx5/TARGET_CORTEX_M/rtx_mempool.c b/rtos/rtx5/TARGET_CORTEX_M/rtx_mempool.c deleted file mode 100644 index 63bb32a..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/rtx_mempool.c +++ /dev/null @@ -1,685 +0,0 @@ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ----------------------------------------------------------------------------- - * - * Project: CMSIS-RTOS RTX - * Title: Memory Pool functions - * - * ----------------------------------------------------------------------------- - */ - -#include "rtx_lib.h" - - -// ==== Library functions ==== - -/// Initialize Memory Pool. -/// \param[in] mp_info memory pool info. -/// \param[in] block_count maximum number of memory blocks in memory pool. -/// \param[in] block_size size of a memory block in bytes. -/// \param[in] block_mem pointer to memory for block storage. -/// \return 1 - success, 0 - failure. -uint32_t osRtxMemoryPoolInit (os_mp_info_t *mp_info, uint32_t block_count, uint32_t block_size, void *block_mem) { - void *block; - - // Check parameters - if ((mp_info == NULL) || (block_count == 0U) || (block_size == 0U) || (block_mem == NULL)) { - return 0U; - } - - // Initialize information structure - mp_info->max_blocks = block_count; - mp_info->used_blocks = 0U; - mp_info->block_size = block_size; - mp_info->block_base = block_mem; - mp_info->block_free = block_mem; - mp_info->block_lim = (uint8_t *)block_mem + (block_count * block_size); - - EvrRtxMemoryBlockInit(mp_info, block_count, block_size, block_mem); - - // Link all free blocks - while (--block_count) { - block = (uint8_t *)block_mem + block_size; - *((void **)block_mem) = block; - block_mem = block; - } - *((void **)block_mem) = NULL; - - return 1U; -} - -/// Allocate a memory block from a Memory Pool. -/// \param[in] mp_info memory pool info. -/// \return address of the allocated memory block or NULL in case of no memory is available. -void *osRtxMemoryPoolAlloc (os_mp_info_t *mp_info) { -#if (__EXCLUSIVE_ACCESS == 0U) - uint32_t primask = __get_PRIMASK(); -#endif - void *block; - - if (mp_info == NULL) { - EvrRtxMemoryBlockAlloc(NULL, NULL); - return NULL; - } - -#if (__EXCLUSIVE_ACCESS == 0U) - __disable_irq(); - - if (mp_info->used_blocks < mp_info->max_blocks) { - mp_info->used_blocks++; - block = mp_info->block_free; - if (block != NULL) { - mp_info->block_free = *((void **)block); - } - } else { - block = NULL; - } - - if (primask == 0U) { - __enable_irq(); - } -#else - if (atomic_inc32_lt(&mp_info->used_blocks, mp_info->max_blocks) < mp_info->max_blocks) { - block = atomic_link_get(&mp_info->block_free); - } else { - block = NULL; - } -#endif - - EvrRtxMemoryBlockAlloc(mp_info, block); - - return block; -} - -/// Return an allocated memory block back to a Memory Pool. -/// \param[in] mp_info memory pool info. -/// \param[in] block address of the allocated memory block to be returned to the memory pool. -/// \return status code that indicates the execution status of the function. -osStatus_t osRtxMemoryPoolFree (os_mp_info_t *mp_info, void *block) { -#if (__EXCLUSIVE_ACCESS == 0U) - uint32_t primask = __get_PRIMASK(); -#endif - osStatus_t status; - - if ((mp_info == NULL) || (block < mp_info->block_base) || (block >= mp_info->block_lim)) { - EvrRtxMemoryBlockFree(mp_info, block, osErrorParameter); - return osErrorParameter; - } - -#if (__EXCLUSIVE_ACCESS == 0U) - __disable_irq(); - - if (mp_info->used_blocks != 0U) { - mp_info->used_blocks--; - *((void **)block) = mp_info->block_free; - mp_info->block_free = block; - status = osOK; - } else { - status = osErrorResource; - } - - if (primask == 0U) { - __enable_irq(); - } -#else - if (atomic_dec32_nz(&mp_info->used_blocks) != 0U) { - atomic_link_put(&mp_info->block_free, block); - status = osOK; - } else { - status = osErrorResource; - } -#endif - - EvrRtxMemoryBlockFree(mp_info, block, status); - - return status; -} - -/// Memory Pool post ISR processing. -/// \param[in] mp memory pool object. -void osRtxMemoryPoolPostProcess (os_memory_pool_t *mp) { - void *block; - os_thread_t *thread; - - if (mp->state == osRtxObjectInactive) { - return; - } - - // Check if Thread is waiting to allocate memory - if (mp->thread_list != NULL) { - // Allocate memory - block = osRtxMemoryPoolAlloc(&mp->mp_info); - if (block != NULL) { - // Wakeup waiting Thread with highest Priority - thread = osRtxThreadListGet((os_object_t*)mp); - osRtxThreadWaitExit(thread, (uint32_t)block, false); - EvrRtxMemoryPoolAllocated(mp, block); - } - } -} - - -// ==== Service Calls ==== - -// Service Calls definitions -SVC0_3M(MemoryPoolNew, osMemoryPoolId_t, uint32_t, uint32_t, const osMemoryPoolAttr_t *) -SVC0_1 (MemoryPoolGetName, const char *, osMemoryPoolId_t) -SVC0_2 (MemoryPoolAlloc, void *, osMemoryPoolId_t, uint32_t) -SVC0_2 (MemoryPoolFree, osStatus_t, osMemoryPoolId_t, void *) -SVC0_1 (MemoryPoolGetCapacity, uint32_t, osMemoryPoolId_t) -SVC0_1 (MemoryPoolGetBlockSize, uint32_t, osMemoryPoolId_t) -SVC0_1 (MemoryPoolGetCount, uint32_t, osMemoryPoolId_t) -SVC0_1 (MemoryPoolGetSpace, uint32_t, osMemoryPoolId_t) -SVC0_1 (MemoryPoolDelete, osStatus_t, osMemoryPoolId_t) - -/// Create and Initialize a Memory Pool object. -/// \note API identical to osMemoryPoolNew -osMemoryPoolId_t svcRtxMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr) { - os_memory_pool_t *mp; - void *mp_mem; - uint32_t mp_size; - uint32_t size; - uint8_t flags; - const char *name; - - // Check parameters - if ((block_count == 0U) || (block_size == 0U)) { - EvrRtxMemoryPoolError(NULL, osErrorParameter); - return NULL; - } - block_size = (block_size + 3U) & ~3UL; - if ((__CLZ(block_count) + __CLZ(block_size)) < 32) { - EvrRtxMemoryPoolError(NULL, osErrorParameter); - return NULL; - } - - size = block_count * block_size; - - // Process attributes - if (attr != NULL) { - name = attr->name; - mp = attr->cb_mem; - mp_mem = attr->mp_mem; - mp_size = attr->mp_size; - if (mp != NULL) { - if (((uint32_t)mp & 3U) || (attr->cb_size < sizeof(os_memory_pool_t))) { - EvrRtxMemoryPoolError(NULL, osRtxErrorInvalidControlBlock); - return NULL; - } - } else { - if (attr->cb_size != 0U) { - EvrRtxMemoryPoolError(NULL, osRtxErrorInvalidControlBlock); - return NULL; - } - } - if (mp_mem != NULL) { - if (((uint32_t)mp_mem & 3U) || (mp_size < size)) { - EvrRtxMemoryPoolError(NULL, osRtxErrorInvalidDataMemory); - return NULL; - } - } else { - if (mp_size != 0U) { - EvrRtxMemoryPoolError(NULL, osRtxErrorInvalidDataMemory); - return NULL; - } - } - } else { - name = NULL; - mp = NULL; - mp_mem = NULL; - } - - // Allocate object memory if not provided - if (mp == NULL) { - if (osRtxInfo.mpi.memory_pool != NULL) { - mp = osRtxMemoryPoolAlloc(osRtxInfo.mpi.memory_pool); - } else { - mp = osRtxMemoryAlloc(osRtxInfo.mem.common, sizeof(os_memory_pool_t), 1U); - } - if (mp == NULL) { - EvrRtxMemoryPoolError(NULL, osErrorNoMemory); - return NULL; - } - flags = osRtxFlagSystemObject; - } else { - flags = 0U; - } - - // Allocate data memory if not provided - if (mp_mem == NULL) { - mp_mem = osRtxMemoryAlloc(osRtxInfo.mem.mp_data, size, 0U); - if (mp_mem == NULL) { - EvrRtxMemoryPoolError(NULL, osErrorNoMemory); - if (flags & osRtxFlagSystemObject) { - if (osRtxInfo.mpi.memory_pool != NULL) { - osRtxMemoryPoolFree(osRtxInfo.mpi.memory_pool, mp); - } else { - osRtxMemoryFree(osRtxInfo.mem.common, mp); - } - } - return NULL; - } - memset(mp_mem, 0, size); - flags |= osRtxFlagSystemMemory; - } - - // Initialize control block - mp->id = osRtxIdMemoryPool; - mp->state = osRtxObjectActive; - mp->flags = flags; - mp->name = name; - mp->thread_list = NULL; - osRtxMemoryPoolInit(&mp->mp_info, block_count, block_size, mp_mem); - - // Register post ISR processing function - osRtxInfo.post_process.memory_pool = osRtxMemoryPoolPostProcess; - - EvrRtxMemoryPoolCreated(mp); - - return mp; -} - -/// Get name of a Memory Pool object. -/// \note API identical to osMemoryPoolGetName -const char *svcRtxMemoryPoolGetName (osMemoryPoolId_t mp_id) { - os_memory_pool_t *mp = (os_memory_pool_t *)mp_id; - - // Check parameters - if ((mp == NULL) || (mp->id != osRtxIdMemoryPool)) { - EvrRtxMemoryPoolGetName(mp, NULL); - return NULL; - } - - // Check object state - if (mp->state == osRtxObjectInactive) { - EvrRtxMemoryPoolGetName(mp, NULL); - return NULL; - } - - EvrRtxMemoryPoolGetName(mp, mp->name); - - return mp->name; -} - -/// Allocate a memory block from a Memory Pool. -/// \note API identical to osMemoryPoolAlloc -void *svcRtxMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout) { - os_memory_pool_t *mp = (os_memory_pool_t *)mp_id; - void *block; - - // Check parameters - if ((mp == NULL) || (mp->id != osRtxIdMemoryPool)) { - EvrRtxMemoryPoolError(mp, osErrorParameter); - return NULL; - } - - // Check object state - if (mp->state == osRtxObjectInactive) { - EvrRtxMemoryPoolError(mp, osErrorResource); - return NULL; - } - - // Allocate memory - block = osRtxMemoryPoolAlloc(&mp->mp_info); - if (block == NULL) { - // No memory available - if (timeout != 0U) { - EvrRtxMemoryPoolAllocPending(mp, timeout); - // Suspend current Thread - osRtxThreadListPut((os_object_t*)mp, osRtxThreadGetRunning()); - osRtxThreadWaitEnter(osRtxThreadWaitingMemoryPool, timeout); - } else { - EvrRtxMemoryPoolAllocFailed(mp); - } - } else { - EvrRtxMemoryPoolAllocated(mp, block); - } - - return block; -} - -/// Return an allocated memory block back to a Memory Pool. -/// \note API identical to osMemoryPoolFree -osStatus_t svcRtxMemoryPoolFree (osMemoryPoolId_t mp_id, void *block) { - os_memory_pool_t *mp = (os_memory_pool_t *)mp_id; - os_thread_t *thread; - osStatus_t status; - - // Check parameters - if ((mp == NULL) || (mp->id != osRtxIdMemoryPool)) { - EvrRtxMemoryPoolError(mp, osErrorParameter); - return osErrorParameter; - } - - // Check object state - if (mp->state == osRtxObjectInactive) { - EvrRtxMemoryPoolError(mp, osErrorResource); - return osErrorResource; - } - - // Free memory - status = osRtxMemoryPoolFree(&mp->mp_info, block); - if (status == osOK) { - EvrRtxMemoryPoolDeallocated(mp, block); - // Check if Thread is waiting to allocate memory - if (mp->thread_list != NULL) { - // Allocate memory - block = osRtxMemoryPoolAlloc(&mp->mp_info); - if (block != NULL) { - // Wakeup waiting Thread with highest Priority - thread = osRtxThreadListGet((os_object_t*)mp); - osRtxThreadWaitExit(thread, (uint32_t)block, true); - EvrRtxMemoryPoolAllocated(mp, block); - } - } - } else { - EvrRtxMemoryPoolFreeFailed(mp, block); - } - - return status; -} - -/// Get maximum number of memory blocks in a Memory Pool. -/// \note API identical to osMemoryPoolGetCapacity -uint32_t svcRtxMemoryPoolGetCapacity (osMemoryPoolId_t mp_id) { - os_memory_pool_t *mp = (os_memory_pool_t *)mp_id; - - // Check parameters - if ((mp == NULL) || (mp->id != osRtxIdMemoryPool)) { - EvrRtxMemoryPoolGetCapacity(mp, 0U); - return 0U; - } - - // Check object state - if (mp->state == osRtxObjectInactive) { - EvrRtxMemoryPoolGetCapacity(mp, 0U); - return 0U; - } - - EvrRtxMemoryPoolGetCapacity(mp, mp->mp_info.max_blocks); - - return mp->mp_info.max_blocks; -} - -/// Get memory block size in a Memory Pool. -/// \note API identical to osMemoryPoolGetBlockSize -uint32_t svcRtxMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id) { - os_memory_pool_t *mp = (os_memory_pool_t *)mp_id; - - // Check parameters - if ((mp == NULL) || (mp->id != osRtxIdMemoryPool)) { - EvrRtxMemoryPoolGetBlockSize(mp, 0U); - return 0U; - } - - // Check object state - if (mp->state == osRtxObjectInactive) { - EvrRtxMemoryPoolGetBlockSize(mp, 0U); - return 0U; - } - - EvrRtxMemoryPoolGetBlockSize(mp, mp->mp_info.block_size); - - return mp->mp_info.block_size; -} - -/// Get number of memory blocks used in a Memory Pool. -/// \note API identical to osMemoryPoolGetCount -uint32_t svcRtxMemoryPoolGetCount (osMemoryPoolId_t mp_id) { - os_memory_pool_t *mp = (os_memory_pool_t *)mp_id; - - // Check parameters - if ((mp == NULL) || (mp->id != osRtxIdMemoryPool)) { - EvrRtxMemoryPoolGetCount(mp, 0U); - return 0U; - } - - // Check object state - if (mp->state == osRtxObjectInactive) { - EvrRtxMemoryPoolGetCount(mp, 0U); - return 0U; - } - - EvrRtxMemoryPoolGetCount(mp, mp->mp_info.used_blocks); - - return mp->mp_info.used_blocks; -} - -/// Get number of memory blocks available in a Memory Pool. -/// \note API identical to osMemoryPoolGetSpace -uint32_t svcRtxMemoryPoolGetSpace (osMemoryPoolId_t mp_id) { - os_memory_pool_t *mp = (os_memory_pool_t *)mp_id; - - // Check parameters - if ((mp == NULL) || (mp->id != osRtxIdMemoryPool)) { - EvrRtxMemoryPoolGetSpace(mp, 0U); - return 0U; - } - - // Check object state - if (mp->state == osRtxObjectInactive) { - EvrRtxMemoryPoolGetSpace(mp, 0U); - return 0U; - } - - EvrRtxMemoryPoolGetSpace(mp, mp->mp_info.max_blocks - mp->mp_info.used_blocks); - - return (mp->mp_info.max_blocks - mp->mp_info.used_blocks); -} - -/// Delete a Memory Pool object. -/// \note API identical to osMemoryPoolDelete -osStatus_t svcRtxMemoryPoolDelete (osMemoryPoolId_t mp_id) { - os_memory_pool_t *mp = (os_memory_pool_t *)mp_id; - os_thread_t *thread; - - // Check parameters - if ((mp == NULL) || (mp->id != osRtxIdMemoryPool)) { - EvrRtxMemoryPoolError(mp, osErrorParameter); - return osErrorParameter; - } - - // Check object state - if (mp->state == osRtxObjectInactive) { - EvrRtxMemoryPoolError(mp, osErrorResource); - return osErrorResource; - } - - // Mark object as inactive - mp->state = osRtxObjectInactive; - - // Unblock waiting threads - if (mp->thread_list != NULL) { - do { - thread = osRtxThreadListGet((os_object_t*)mp); - osRtxThreadWaitExit(thread, 0U, false); - } while (mp->thread_list != NULL); - osRtxThreadDispatch(NULL); - } - - // Free data memory - if (mp->flags & osRtxFlagSystemMemory) { - osRtxMemoryFree(osRtxInfo.mem.mp_data, mp->mp_info.block_base); - } - - // Free object memory - if (mp->flags & osRtxFlagSystemObject) { - if (osRtxInfo.mpi.memory_pool != NULL) { - osRtxMemoryPoolFree(osRtxInfo.mpi.memory_pool, mp); - } else { - osRtxMemoryFree(osRtxInfo.mem.common, mp); - } - } - - EvrRtxMemoryPoolDestroyed(mp); - - return osOK; -} - - -// ==== ISR Calls ==== - -/// Allocate a memory block from a Memory Pool. -/// \note API identical to osMemoryPoolAlloc -__STATIC_INLINE -void *isrRtxMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout) { - os_memory_pool_t *mp = (os_memory_pool_t *)mp_id; - void *block; - - // Check parameters - if ((mp == NULL) || (mp->id != osRtxIdMemoryPool) || (timeout != 0U)) { - EvrRtxMemoryPoolError(mp, osErrorParameter); - return NULL; - } - - // Check object state - if (mp->state == osRtxObjectInactive) { - EvrRtxMemoryPoolError(mp, osErrorResource); - return NULL; - } - - // Allocate memory - block = osRtxMemoryPoolAlloc(&mp->mp_info); - if (block == NULL) { - EvrRtxMemoryPoolAllocFailed(mp); - } else { - EvrRtxMemoryPoolAllocated(mp, block); - } - - return block; -} - -/// Return an allocated memory block back to a Memory Pool. -/// \note API identical to osMemoryPoolFree -__STATIC_INLINE -osStatus_t isrRtxMemoryPoolFree (osMemoryPoolId_t mp_id, void *block) { - os_memory_pool_t *mp = (os_memory_pool_t *)mp_id; - osStatus_t status; - - // Check parameters - if ((mp == NULL) || (mp->id != osRtxIdMemoryPool)) { - EvrRtxMemoryPoolError(mp, osErrorParameter); - return osErrorParameter; - } - - // Check object state - if (mp->state == osRtxObjectInactive) { - EvrRtxMemoryPoolError(mp, osErrorResource); - return osErrorResource; - } - - // Free memory - status = osRtxMemoryPoolFree(&mp->mp_info, block); - if (status == osOK) { - // Register post ISR processing - osRtxPostProcess((os_object_t *)mp); - EvrRtxMemoryPoolDeallocated(mp, block); - } else { - EvrRtxMemoryPoolFreeFailed(mp, block); - } - - return status; -} - - -// ==== Public API ==== - -/// Create and Initialize a Memory Pool object. -osMemoryPoolId_t osMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr) { - EvrRtxMemoryPoolNew(block_count, block_size, attr); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxMemoryPoolError(NULL, osErrorISR); - return NULL; - } - return __svcMemoryPoolNew(block_count, block_size, attr); -} - -/// Get name of a Memory Pool object. -const char *osMemoryPoolGetName (osMemoryPoolId_t mp_id) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxMemoryPoolGetName(mp_id, NULL); - return NULL; - } - return __svcMemoryPoolGetName(mp_id); -} - -/// Allocate a memory block from a Memory Pool. -void *osMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout) { - EvrRtxMemoryPoolAlloc(mp_id, timeout); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - return isrRtxMemoryPoolAlloc(mp_id, timeout); - } else { - return __svcMemoryPoolAlloc(mp_id, timeout); - } -} - -/// Return an allocated memory block back to a Memory Pool. -osStatus_t osMemoryPoolFree (osMemoryPoolId_t mp_id, void *block) { - EvrRtxMemoryPoolFree(mp_id, block); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - return isrRtxMemoryPoolFree(mp_id, block); - } else { - return __svcMemoryPoolFree(mp_id, block); - } -} - -/// Get maximum number of memory blocks in a Memory Pool. -uint32_t osMemoryPoolGetCapacity (osMemoryPoolId_t mp_id) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - return svcRtxMemoryPoolGetCapacity(mp_id); - } else { - return __svcMemoryPoolGetCapacity(mp_id); - } -} - -/// Get memory block size in a Memory Pool. -uint32_t osMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - return svcRtxMemoryPoolGetBlockSize(mp_id); - } else { - return __svcMemoryPoolGetBlockSize(mp_id); - } -} - -/// Get number of memory blocks used in a Memory Pool. -uint32_t osMemoryPoolGetCount (osMemoryPoolId_t mp_id) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - return svcRtxMemoryPoolGetCount(mp_id); - } else { - return __svcMemoryPoolGetCount(mp_id); - } -} - -/// Get number of memory blocks available in a Memory Pool. -uint32_t osMemoryPoolGetSpace (osMemoryPoolId_t mp_id) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - return svcRtxMemoryPoolGetSpace(mp_id); - } else { - return __svcMemoryPoolGetSpace(mp_id); - } -} - -/// Delete a Memory Pool object. -osStatus_t osMemoryPoolDelete (osMemoryPoolId_t mp_id) { - EvrRtxMemoryPoolDelete(mp_id); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxMemoryPoolError(mp_id, osErrorISR); - return osErrorISR; - } - return __svcMemoryPoolDelete(mp_id); -} diff --git a/rtos/rtx5/TARGET_CORTEX_M/rtx_msgqueue.c b/rtos/rtx5/TARGET_CORTEX_M/rtx_msgqueue.c deleted file mode 100644 index d147e81..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/rtx_msgqueue.c +++ /dev/null @@ -1,906 +0,0 @@ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ----------------------------------------------------------------------------- - * - * Project: CMSIS-RTOS RTX - * Title: Message Queue functions - * - * ----------------------------------------------------------------------------- - */ - -#include "rtx_lib.h" - - -// ==== Helper functions ==== - -/// Put a Message into Queue sorted by Priority (Highest at Head). -/// \param[in] mq message queue object. -/// \param[in] msg message object. -static void MessageQueuePut (os_message_queue_t *mq, os_message_t *msg) { -#if (__EXCLUSIVE_ACCESS == 0U) - uint32_t primask = __get_PRIMASK(); -#endif - os_message_t *prev, *next; - - if (mq->msg_last != NULL) { - prev = mq->msg_last; - next = NULL; - while ((prev != NULL) && (prev->priority < msg->priority)) { - next = prev; - prev = prev->prev; - } - msg->prev = prev; - msg->next = next; - if (prev != NULL) { - prev->next = msg; - } else { - mq->msg_first = msg; - } - if (next != NULL) { - next->prev = msg; - } else { - mq->msg_last = msg; - } - } else { - msg->prev = NULL; - msg->next = NULL; - mq->msg_first= msg; - mq->msg_last = msg; - } - -#if (__EXCLUSIVE_ACCESS == 0U) - __disable_irq(); - - mq->msg_count++; - - if (primask == 0U) { - __enable_irq(); - } -#else - atomic_inc32(&mq->msg_count); -#endif -} - -/// Get a Message from Queue with Highest Priority. -/// \param[in] mq message queue object. -/// \return message object or NULL. -static os_message_t *MessageQueueGet (os_message_queue_t *mq) { -#if (__EXCLUSIVE_ACCESS == 0U) - uint32_t primask = __get_PRIMASK(); -#endif - os_message_t *msg; - uint32_t count; - uint8_t flags; - -#if (__EXCLUSIVE_ACCESS == 0U) - __disable_irq(); - - count = mq->msg_count; - if (count != 0U) { - mq->msg_count--; - } - - if (primask == 0U) { - __enable_irq(); - } -#else - count = atomic_dec32_nz(&mq->msg_count); -#endif - - if (count == 0U) { - return NULL; - } - - msg = mq->msg_first; - - while (msg != NULL) { -#if (__EXCLUSIVE_ACCESS == 0U) - __disable_irq(); - - flags = msg->flags; - msg->flags = 1U; - - if (primask == 0U) { - __enable_irq(); - } -#else - flags = atomic_wr8(&msg->flags, 1U); -#endif - if (flags == 0U) { - break; - } - msg = msg->next; - } - - return msg; -} - -/// Remove a Message from Queue -/// \param[in] mq message queue object. -/// \param[in] msg message object. -static void MessageQueueRemove (os_message_queue_t *mq, os_message_t *msg) { - - if (msg->prev != NULL) { - msg->prev->next = msg->next; - } else { - mq->msg_first = msg->next; - } - if (msg->next != NULL) { - msg->next->prev = msg->prev; - } else { - mq->msg_last = msg->prev; - } -} - - -// ==== Library functions ==== - -/// Message Queue post ISR processing. -/// \param[in] msg message object. -void osRtxMessageQueuePostProcess (os_message_t *msg) { - os_message_queue_t *mq; - os_thread_t *thread; - uint32_t *reg; - void **ptr; - - if (msg->state == osRtxObjectInactive) { - return; - } - - if (msg->flags != 0U) { - // Remove Message - ptr = (void *)((uint8_t *)msg + sizeof(os_message_t)); - mq = *ptr; - if (mq->state == osRtxObjectInactive) { - return; - } - MessageQueueRemove(mq, msg); - // Free memory - msg->state = osRtxObjectInactive; - osRtxMemoryPoolFree(&mq->mp_info, msg); - // Check if Thread is waiting to send a Message - if ((mq->thread_list != NULL) && (mq->thread_list->state == osRtxThreadWaitingMessagePut)) { - // Try to allocate memory - msg = osRtxMemoryPoolAlloc(&mq->mp_info); - if (msg != NULL) { - // Wakeup waiting Thread with highest Priority - thread = osRtxThreadListGet((os_object_t*)mq); - osRtxThreadWaitExit(thread, (uint32_t)osOK, false); - // Copy Message (R2: const void *msg_ptr, R3: uint8_t msg_prio) - reg = osRtxThreadRegPtr(thread); - memcpy((uint8_t *)msg + sizeof(os_message_t), (void *)reg[2], mq->msg_size); - // Store Message into Queue - msg->id = osRtxIdMessage; - msg->state = osRtxObjectActive; - msg->flags = 0U; - msg->priority = (uint8_t)reg[3]; - MessageQueuePut(mq, msg); - EvrRtxMessageQueueInserted(mq, (void *)reg[2]); - } - } - } else { - // New Message - mq = (void *)msg->next; - if (mq->state == osRtxObjectInactive) { - return; - } - // Check if Thread is waiting to receive a Message - if ((mq->thread_list != NULL) && (mq->thread_list->state == osRtxThreadWaitingMessageGet)) { - EvrRtxMessageQueueInserted(mq, (void *)msg->prev); - // Wakeup waiting Thread with highest Priority - thread = osRtxThreadListGet((os_object_t*)mq); - osRtxThreadWaitExit(thread, (uint32_t)osOK, false); - // Copy Message (R2: void *msg_ptr, R3: uint8_t *msg_prio) - reg = osRtxThreadRegPtr(thread); - memcpy((void *)reg[2], (uint8_t *)msg + sizeof(os_message_t), mq->msg_size); - if (reg[3] != 0U) { - *((uint8_t *)reg[3]) = msg->priority; - } - EvrRtxMessageQueueRetrieved(mq, (void *)reg[2]); - // Free memory - msg->state = osRtxObjectInactive; - osRtxMemoryPoolFree(&mq->mp_info, msg); - } else { - EvrRtxMessageQueueInserted(mq, (void *)msg->prev); - MessageQueuePut(mq, msg); - } - } -} - - -// ==== Service Calls ==== - -SVC0_3M(MessageQueueNew, osMessageQueueId_t, uint32_t, uint32_t, const osMessageQueueAttr_t *) -SVC0_1 (MessageQueueGetName, const char *, osMessageQueueId_t) -SVC0_4 (MessageQueuePut, osStatus_t, osMessageQueueId_t, const void *, uint8_t, uint32_t) -SVC0_4 (MessageQueueGet, osStatus_t, osMessageQueueId_t, void *, uint8_t *, uint32_t) -SVC0_1 (MessageQueueGetCapacity, uint32_t, osMessageQueueId_t) -SVC0_1 (MessageQueueGetMsgSize, uint32_t, osMessageQueueId_t) -SVC0_1 (MessageQueueGetCount, uint32_t, osMessageQueueId_t) -SVC0_1 (MessageQueueGetSpace, uint32_t, osMessageQueueId_t) -SVC0_1 (MessageQueueReset, osStatus_t, osMessageQueueId_t) -SVC0_1 (MessageQueueDelete, osStatus_t, osMessageQueueId_t) - -/// Create and Initialize a Message Queue object. -/// \note API identical to osMessageQueueNew -osMessageQueueId_t svcRtxMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr) { - os_message_queue_t *mq; - void *mq_mem; - uint32_t mq_size; - uint32_t block_size; - uint32_t size; - uint8_t flags; - const char *name; - - // Check parameters - if ((msg_count == 0U) || (msg_size == 0U)) { - EvrRtxMessageQueueError(NULL, osErrorParameter); - return NULL; - } - msg_size = (msg_size + 3U) & ~3UL; - block_size = msg_size + sizeof(os_message_t); - if ((__CLZ(msg_count) + __CLZ(block_size)) < 32) { - EvrRtxMessageQueueError(NULL, osErrorParameter); - return NULL; - } - - size = msg_count * block_size; - - // Process attributes - if (attr != NULL) { - name = attr->name; - mq = attr->cb_mem; - mq_mem = attr->mq_mem; - mq_size = attr->mq_size; - if (mq != NULL) { - if (((uint32_t)mq & 3U) || (attr->cb_size < sizeof(os_message_queue_t))) { - EvrRtxMessageQueueError(NULL, osRtxErrorInvalidControlBlock); - return NULL; - } - } else { - if (attr->cb_size != 0U) { - EvrRtxMessageQueueError(NULL, osRtxErrorInvalidControlBlock); - return NULL; - } - } - if (mq_mem != NULL) { - if (((uint32_t)mq_mem & 3U) || (mq_size < size)) { - EvrRtxMessageQueueError(NULL, osRtxErrorInvalidDataMemory); - return NULL; - } - } else { - if (mq_size != 0U) { - EvrRtxMessageQueueError(NULL, osRtxErrorInvalidDataMemory); - return NULL; - } - } - } else { - name = NULL; - mq = NULL; - mq_mem = NULL; - } - - // Allocate object memory if not provided - if (mq == NULL) { - if (osRtxInfo.mpi.message_queue != NULL) { - mq = osRtxMemoryPoolAlloc(osRtxInfo.mpi.message_queue); - } else { - mq = osRtxMemoryAlloc(osRtxInfo.mem.common, sizeof(os_message_queue_t), 1U); - } - if (mq == NULL) { - EvrRtxMessageQueueError(NULL, osErrorNoMemory); - return NULL; - } - flags = osRtxFlagSystemObject; - } else { - flags = 0U; - } - - // Allocate data memory if not provided - if (mq_mem == NULL) { - mq_mem = osRtxMemoryAlloc(osRtxInfo.mem.mq_data, size, 0U); - if (mq_mem == NULL) { - EvrRtxMessageQueueError(NULL, osErrorNoMemory); - if (flags & osRtxFlagSystemObject) { - if (osRtxInfo.mpi.message_queue != NULL) { - osRtxMemoryPoolFree(osRtxInfo.mpi.message_queue, mq); - } else { - osRtxMemoryFree(osRtxInfo.mem.common, mq); - } - } - return NULL; - } - memset(mq_mem, 0, size); - flags |= osRtxFlagSystemMemory; - } - - // Initialize control block - mq->id = osRtxIdMessageQueue; - mq->state = osRtxObjectActive; - mq->flags = flags; - mq->name = name; - mq->thread_list = NULL; - mq->msg_size = msg_size; - mq->msg_count = 0U; - mq->msg_first = NULL; - mq->msg_last = NULL; - osRtxMemoryPoolInit(&mq->mp_info, msg_count, block_size, mq_mem); - - // Register post ISR processing function - osRtxInfo.post_process.message_queue = osRtxMessageQueuePostProcess; - - EvrRtxMessageQueueCreated(mq); - - return mq; -} - -/// Get name of a Message Queue object. -/// \note API identical to osMessageQueueGetName -const char *svcRtxMessageQueueGetName (osMessageQueueId_t mq_id) { - os_message_queue_t *mq = (os_message_queue_t *)mq_id; - - // Check parameters - if ((mq == NULL) || (mq->id != osRtxIdMessageQueue)) { - EvrRtxMessageQueueGetName(mq, NULL); - return NULL; - } - - // Check object state - if (mq->state == osRtxObjectInactive) { - EvrRtxMessageQueueGetName(mq, NULL); - return NULL; - } - - EvrRtxMessageQueueGetName(mq, mq->name); - - return mq->name; -} - -/// Put a Message into a Queue or timeout if Queue is full. -/// \note API identical to osMessageQueuePut -osStatus_t svcRtxMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout) { - os_message_queue_t *mq = (os_message_queue_t *)mq_id; - os_message_t *msg; - os_thread_t *thread; - uint32_t *reg; - - // Check parameters - if ((mq == NULL) || (mq->id != osRtxIdMessageQueue) || (msg_ptr == NULL)) { - EvrRtxMessageQueueError(mq, osErrorParameter); - return osErrorParameter; - } - - // Check object state - if (mq->state == osRtxObjectInactive) { - EvrRtxMessageQueueError(mq, osErrorResource); - return osErrorResource; - } - - // Check if Thread is waiting to receive a Message - if ((mq->thread_list != NULL) && (mq->thread_list->state == osRtxThreadWaitingMessageGet)) { - EvrRtxMessageQueueInserted(mq, msg_ptr); - // Wakeup waiting Thread with highest Priority - thread = osRtxThreadListGet((os_object_t*)mq); - osRtxThreadWaitExit(thread, (uint32_t)osOK, true); - // Copy Message (R2: void *msg_ptr, R3: uint8_t *msg_prio) - reg = osRtxThreadRegPtr(thread); - memcpy((void *)reg[2], msg_ptr, mq->msg_size); - if (reg[3] != 0U) { - *((uint8_t *)reg[3]) = msg_prio; - } - EvrRtxMessageQueueRetrieved(mq, (void *)reg[2]); - return osOK; - } - - // Try to allocate memory - msg = osRtxMemoryPoolAlloc(&mq->mp_info); - if (msg != NULL) { - // Copy Message - memcpy((uint8_t *)msg + sizeof(os_message_t), msg_ptr, mq->msg_size); - // Put Message into Queue - msg->id = osRtxIdMessage; - msg->state = osRtxObjectActive; - msg->flags = 0U; - msg->priority = msg_prio; - MessageQueuePut(mq, msg); - } else { - // No memory available - if (timeout != 0U) { - EvrRtxMessageQueuePutPending(mq, msg_ptr, timeout); - // Suspend current Thread - osRtxThreadListPut((os_object_t*)mq, osRtxThreadGetRunning()); - osRtxThreadWaitEnter(osRtxThreadWaitingMessagePut, timeout); - // Save arguments (R2: const void *msg_ptr, R3: uint8_t msg_prio) - reg = (uint32_t *)(__get_PSP()); - reg[2] = (uint32_t)msg_ptr; - reg[3] = (uint32_t)msg_prio; - return osErrorTimeout; - } else { - EvrRtxMessageQueueNotInserted(mq, msg_ptr); - return osErrorResource; - } - } - - EvrRtxMessageQueueInserted(mq, msg_ptr); - - return osOK; -} - -/// Get a Message from a Queue or timeout if Queue is empty. -/// \note API identical to osMessageQueueGet -osStatus_t svcRtxMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout) { - os_message_queue_t *mq = (os_message_queue_t *)mq_id; - os_message_t *msg; - os_thread_t *thread; - uint32_t *reg; - - // Check parameters - if ((mq == NULL) || (mq->id != osRtxIdMessageQueue) || (msg_ptr == NULL)) { - EvrRtxMessageQueueError(mq, osErrorParameter); - return osErrorParameter; - } - - // Check object state - if (mq->state == osRtxObjectInactive) { - EvrRtxMessageQueueError(mq, osErrorResource); - return osErrorResource; - } - - // Get Message from Queue - msg = MessageQueueGet(mq); - if (msg != NULL) { - MessageQueueRemove(mq, msg); - // Copy Message - memcpy(msg_ptr, (uint8_t *)msg + sizeof(os_message_t), mq->msg_size); - if (msg_prio != NULL) { - *msg_prio = msg->priority; - } - EvrRtxMessageQueueRetrieved(mq, msg_ptr); - // Free memory - msg->state = osRtxObjectInactive; - osRtxMemoryPoolFree(&mq->mp_info, msg); - } else { - // No Message available - if (timeout != 0U) { - EvrRtxMessageQueueGetPending(mq, msg_ptr, timeout); - // Suspend current Thread - osRtxThreadListPut((os_object_t*)mq, osRtxThreadGetRunning()); - osRtxThreadWaitEnter(osRtxThreadWaitingMessageGet, timeout); - // Save arguments (R2: void *msg_ptr, R3: uint8_t *msg_prio) - reg = (uint32_t *)(__get_PSP()); - reg[2] = (uint32_t)msg_ptr; - reg[3] = (uint32_t)msg_prio; - return osErrorTimeout; - } else { - EvrRtxMessageQueueNotRetrieved(mq, msg_ptr); - return osErrorResource; - } - } - - // Check if Thread is waiting to send a Message - if ((mq->thread_list != NULL) && (mq->thread_list->state == osRtxThreadWaitingMessagePut)) { - // Try to allocate memory - msg = osRtxMemoryPoolAlloc(&mq->mp_info); - if (msg != NULL) { - // Wakeup waiting Thread with highest Priority - thread = osRtxThreadListGet((os_object_t*)mq); - osRtxThreadWaitExit(thread, (uint32_t)osOK, true); - // Copy Message (R2: const void *msg_ptr, R3: uint8_t msg_prio) - reg = osRtxThreadRegPtr(thread); - memcpy((uint8_t *)msg + sizeof(os_message_t), (void *)reg[2], mq->msg_size); - // Store Message into Queue - msg->id = osRtxIdMessage; - msg->state = osRtxObjectActive; - msg->flags = 0U; - msg->priority = (uint8_t)reg[3]; - MessageQueuePut(mq, msg); - EvrRtxMessageQueueInserted(mq, (void *)reg[2]); - } - } - - return osOK; -} - -/// Get maximum number of messages in a Message Queue. -/// \note API identical to osMessageGetCapacity -uint32_t svcRtxMessageQueueGetCapacity (osMessageQueueId_t mq_id) { - os_message_queue_t *mq = (os_message_queue_t *)mq_id; - - // Check parameters - if ((mq == NULL) || (mq->id != osRtxIdMessageQueue)) { - EvrRtxMessageQueueGetCapacity(mq, 0U); - return 0U; - } - - // Check object state - if (mq->state == osRtxObjectInactive) { - EvrRtxMessageQueueGetCapacity(mq, 0U); - return 0U; - } - - EvrRtxMessageQueueGetCapacity(mq, mq->mp_info.max_blocks); - - return mq->mp_info.max_blocks; -} - -/// Get maximum message size in a Memory Pool. -/// \note API identical to osMessageGetMsgSize -uint32_t svcRtxMessageQueueGetMsgSize (osMessageQueueId_t mq_id) { - os_message_queue_t *mq = (os_message_queue_t *)mq_id; - - // Check parameters - if ((mq == NULL) || (mq->id != osRtxIdMessageQueue)) { - EvrRtxMessageQueueGetMsgSize(mq, 0U); - return 0U; - } - - // Check object state - if (mq->state == osRtxObjectInactive) { - EvrRtxMessageQueueGetMsgSize(mq, 0U); - return 0U; - } - - EvrRtxMessageQueueGetMsgSize(mq, mq->msg_size); - - return mq->msg_size; -} - -/// Get number of queued messages in a Message Queue. -/// \note API identical to osMessageGetCount -uint32_t svcRtxMessageQueueGetCount (osMessageQueueId_t mq_id) { - os_message_queue_t *mq = (os_message_queue_t *)mq_id; - - // Check parameters - if ((mq == NULL) || (mq->id != osRtxIdMessageQueue)) { - EvrRtxMessageQueueGetCount(mq, 0U); - return 0U; - } - - // Check object state - if (mq->state == osRtxObjectInactive) { - EvrRtxMessageQueueGetCount(mq, 0U); - return 0U; - } - - EvrRtxMessageQueueGetCount(mq, mq->msg_count); - - return mq->msg_count; -} - -/// Get number of available slots for messages in a Message Queue. -/// \note API identical to osMessageGetSpace -uint32_t svcRtxMessageQueueGetSpace (osMessageQueueId_t mq_id) { - os_message_queue_t *mq = (os_message_queue_t *)mq_id; - - // Check parameters - if ((mq == NULL) || (mq->id != osRtxIdMessageQueue)) { - EvrRtxMessageQueueGetSpace(mq, 0U); - return 0U; - } - - // Check object state - if (mq->state == osRtxObjectInactive) { - EvrRtxMessageQueueGetSpace(mq, 0U); - return 0U; - } - - EvrRtxMessageQueueGetSpace(mq, mq->mp_info.max_blocks - mq->msg_count); - - return (mq->mp_info.max_blocks - mq->msg_count); -} - -/// Reset a Message Queue to initial empty state. -/// \note API identical to osMessageQueueReset -osStatus_t svcRtxMessageQueueReset (osMessageQueueId_t mq_id) { - os_message_queue_t *mq = (os_message_queue_t *)mq_id; - os_message_t *msg; - os_thread_t *thread; - uint32_t *reg; - - // Check parameters - if ((mq == NULL) || (mq->id != osRtxIdMessageQueue)) { - EvrRtxMessageQueueError(mq, osErrorParameter); - return osErrorParameter; - } - - // Check object state - if (mq->state == osRtxObjectInactive) { - EvrRtxMessageQueueError(mq, osErrorResource); - return osErrorResource; - } - - // Remove Messages from Queue - for (;;) { - // Get Message from Queue - msg = MessageQueueGet(mq); - if (msg == NULL) { - break; - } - MessageQueueRemove(mq, msg); - EvrRtxMessageQueueRetrieved(mq, NULL); - // Free memory - msg->state = osRtxObjectInactive; - osRtxMemoryPoolFree(&mq->mp_info, msg); - } - - // Check if Threads are waiting to send Messages - if ((mq->thread_list != NULL) && (mq->thread_list->state == osRtxThreadWaitingMessagePut)) { - do { - // Try to allocate memory - msg = osRtxMemoryPoolAlloc(&mq->mp_info); - if (msg != NULL) { - // Wakeup waiting Thread with highest Priority - thread = osRtxThreadListGet((os_object_t*)mq); - osRtxThreadWaitExit(thread, (uint32_t)osOK, false); - // Copy Message (R2: const void *msg_ptr, R3: uint8_t msg_prio) - reg = osRtxThreadRegPtr(thread); - memcpy((uint8_t *)msg + sizeof(os_message_t), (void *)reg[2], mq->msg_size); - // Store Message into Queue - msg->id = osRtxIdMessage; - msg->state = osRtxObjectActive; - msg->flags = 0U; - msg->priority = (uint8_t)reg[3]; - MessageQueuePut(mq, msg); - EvrRtxMessageQueueInserted(mq, (void *)reg[2]); - } - } while ((msg != NULL) && (mq->thread_list != NULL)); - osRtxThreadDispatch(NULL); - } - - EvrRtxMessageQueueResetDone(mq); - - return osOK; -} - -/// Delete a Message Queue object. -/// \note API identical to osMessageQueueDelete -osStatus_t svcRtxMessageQueueDelete (osMessageQueueId_t mq_id) { - os_message_queue_t *mq = (os_message_queue_t *)mq_id; - os_thread_t *thread; - - // Check parameters - if ((mq == NULL) || (mq->id != osRtxIdMessageQueue)) { - EvrRtxMessageQueueError(mq, osErrorParameter); - return osErrorParameter; - } - - // Check object state - if (mq->state == osRtxObjectInactive) { - EvrRtxMessageQueueError(mq, osErrorResource); - return osErrorResource; - } - - // Mark object as inactive - mq->state = osRtxObjectInactive; - - // Unblock waiting threads - if (mq->thread_list != NULL) { - do { - thread = osRtxThreadListGet((os_object_t*)mq); - osRtxThreadWaitExit(thread, (uint32_t)osErrorResource, false); - } while (mq->thread_list != NULL); - osRtxThreadDispatch(NULL); - } - - // Free data memory - if (mq->flags & osRtxFlagSystemMemory) { - osRtxMemoryFree(osRtxInfo.mem.mq_data, mq->mp_info.block_base); - } - - // Free object memory - if (mq->flags & osRtxFlagSystemObject) { - if (osRtxInfo.mpi.message_queue != NULL) { - osRtxMemoryPoolFree(osRtxInfo.mpi.message_queue, mq); - } else { - osRtxMemoryFree(osRtxInfo.mem.common, mq); - } - } - - EvrRtxMessageQueueDestroyed(mq); - - return osOK; -} - - -// ==== ISR Calls ==== - -/// Put a Message into a Queue or timeout if Queue is full. -/// \note API identical to osMessageQueuePut -__STATIC_INLINE -osStatus_t isrRtxMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout) { - os_message_queue_t *mq = (os_message_queue_t *)mq_id; - os_message_t *msg; - const void **ptr; - - // Check parameters - if ((mq == NULL) || (mq->id != osRtxIdMessageQueue) || (msg_ptr == NULL) || (timeout != 0U)) { - EvrRtxMessageQueueError(mq, osErrorParameter); - return osErrorParameter; - } - - // Check object state - if (mq->state == osRtxObjectInactive) { - EvrRtxMessageQueueError(mq, osErrorResource); - return osErrorResource; - } - - // Try to allocate memory - msg = osRtxMemoryPoolAlloc(&mq->mp_info); - if (msg != NULL) { - // Copy Message - memcpy((uint8_t *)msg + sizeof(os_message_t), msg_ptr, mq->msg_size); - msg->id = osRtxIdMessage; - msg->state = osRtxObjectActive; - msg->flags = 0U; - msg->priority = msg_prio; - // Register post ISR processing - ptr = (void *)&msg->prev; - *ptr = msg_ptr; - ptr = (void *)&msg->next; - *ptr = mq; - osRtxPostProcess((os_object_t *)msg); - } else { - // No memory available - EvrRtxMessageQueueNotInserted(mq, msg_ptr); - return osErrorResource; - } - - EvrRtxMessageQueueInsertPending(mq, msg_ptr); - - return osOK; -} - -/// Get a Message from a Queue or timeout if Queue is empty. -/// \note API identical to osMessageQueueGet -__STATIC_INLINE -osStatus_t isrRtxMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout) { - os_message_queue_t *mq = (os_message_queue_t *)mq_id; - os_message_t *msg; - void **ptr; - - // Check parameters - if ((mq == NULL) || (mq->id != osRtxIdMessageQueue) || (msg_ptr == NULL) || (timeout != 0U)) { - EvrRtxMessageQueueError(mq, osErrorParameter); - return osErrorParameter; - } - - // Check object state - if (mq->state == osRtxObjectInactive) { - EvrRtxMessageQueueError(mq, osErrorResource); - return osErrorResource; - } - - // Get Message from Queue - msg = MessageQueueGet(mq); - if (msg != NULL) { - // Copy Message - memcpy(msg_ptr, (uint8_t *)msg + sizeof(os_message_t), mq->msg_size); - if (msg_prio != NULL) { - *msg_prio = msg->priority; - } - EvrRtxMessageQueueRetrieved(mq, msg_ptr); - // Register post ISR processing - ptr = (void *)((uint8_t *)msg + sizeof(os_message_t)); - *ptr = mq; - osRtxPostProcess((os_object_t *)msg); - } else { - // No Message available - EvrRtxMessageQueueNotRetrieved(mq, msg_ptr); - return osErrorResource; - } - - return osOK; -} - - -// ==== Public API ==== - -/// Create and Initialize a Message Queue object. -osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr) { - EvrRtxMessageQueueNew(msg_count, msg_size, attr); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxMessageQueueError(NULL, osErrorISR); - return NULL; - } - return __svcMessageQueueNew(msg_count, msg_size, attr); -} - -/// Get name of a Message Queue object. -const char *osMessageQueueGetName (osMessageQueueId_t mq_id) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxMessageQueueGetName(mq_id, NULL); - return NULL; - } - return __svcMessageQueueGetName(mq_id); -} - -/// Put a Message into a Queue or timeout if Queue is full. -osStatus_t osMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout) { - EvrRtxMessageQueuePut(mq_id, msg_ptr, msg_prio, timeout); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - return isrRtxMessageQueuePut(mq_id, msg_ptr, msg_prio, timeout); - } else { - return __svcMessageQueuePut(mq_id, msg_ptr, msg_prio, timeout); - } -} - -/// Get a Message from a Queue or timeout if Queue is empty. -osStatus_t osMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout) { - EvrRtxMessageQueueGet(mq_id, msg_ptr, msg_prio, timeout); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - return isrRtxMessageQueueGet(mq_id, msg_ptr, msg_prio, timeout); - } else { - return __svcMessageQueueGet(mq_id, msg_ptr, msg_prio, timeout); - } -} - -/// Get maximum number of messages in a Message Queue. -uint32_t osMessageQueueGetCapacity (osMessageQueueId_t mq_id) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - return svcRtxMessageQueueGetCapacity(mq_id); - } else { - return __svcMessageQueueGetCapacity(mq_id); - } -} - -/// Get maximum message size in a Memory Pool. -uint32_t osMessageQueueGetMsgSize (osMessageQueueId_t mq_id) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - return svcRtxMessageQueueGetMsgSize(mq_id); - } else { - return __svcMessageQueueGetMsgSize(mq_id); - } -} - -/// Get number of queued messages in a Message Queue. -uint32_t osMessageQueueGetCount (osMessageQueueId_t mq_id) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - return svcRtxMessageQueueGetCount(mq_id); - } else { - return __svcMessageQueueGetCount(mq_id); - } -} - -/// Get number of available slots for messages in a Message Queue. -uint32_t osMessageQueueGetSpace (osMessageQueueId_t mq_id) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - return svcRtxMessageQueueGetSpace(mq_id); - } else { - return __svcMessageQueueGetSpace(mq_id); - } -} - -/// Reset a Message Queue to initial empty state. -osStatus_t osMessageQueueReset (osMessageQueueId_t mq_id) { - EvrRtxMessageQueueReset(mq_id); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxMessageQueueError(mq_id, osErrorISR); - return osErrorISR; - } - return __svcMessageQueueReset(mq_id); -} - -/// Delete a Message Queue object. -osStatus_t osMessageQueueDelete (osMessageQueueId_t mq_id) { - EvrRtxMessageQueueDelete(mq_id); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxMessageQueueError(mq_id, osErrorISR); - return osErrorISR; - } - return __svcMessageQueueDelete(mq_id); -} diff --git a/rtos/rtx5/TARGET_CORTEX_M/rtx_mutex.c b/rtos/rtx5/TARGET_CORTEX_M/rtx_mutex.c deleted file mode 100644 index 4a274f8..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/rtx_mutex.c +++ /dev/null @@ -1,494 +0,0 @@ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ----------------------------------------------------------------------------- - * - * Project: CMSIS-RTOS RTX - * Title: Mutex functions - * - * ----------------------------------------------------------------------------- - */ - -#include "rtx_lib.h" - - -// ==== Library functions ==== - -/// Release Mutex list when owner Thread terminates. -/// \param[in] mutex mutex object. -/// \return 1 - success, 0 - failure. -void osRtxMutexOwnerRelease (os_mutex_t *mutex_list) { - os_mutex_t *mutex; - os_thread_t *thread; - - mutex = mutex_list; - while (mutex) { - mutex_list = mutex->owner_next; - // Check if Mutex is Robust - if (mutex->attr & osMutexRobust) { - // Clear Lock counter - mutex->lock = 0U; - EvrRtxMutexReleased(mutex, 0U); - // Check if Thread is waiting for a Mutex - if (mutex->thread_list != NULL) { - // Wakeup waiting Thread with highest Priority - thread = osRtxThreadListGet((os_object_t*)mutex); - osRtxThreadWaitExit(thread, (uint32_t)osOK, false); - // Thread is the new Mutex owner - mutex->owner_thread = thread; - mutex->owner_next = thread->mutex_list; - mutex->owner_prev = NULL; - thread->mutex_list = mutex; - mutex->lock = 1U; - EvrRtxMutexAcquired(mutex, 1U); - } - } - mutex = mutex_list; - } -} - - -// ==== Service Calls ==== - -// Service Calls definitions -SVC0_1M(MutexNew, osMutexId_t, const osMutexAttr_t *) -SVC0_1 (MutexGetName, const char *, osMutexId_t) -SVC0_2 (MutexAcquire, osStatus_t, osMutexId_t, uint32_t) -SVC0_1 (MutexRelease, osStatus_t, osMutexId_t) -SVC0_1 (MutexGetOwner, osThreadId_t, osMutexId_t) -SVC0_1 (MutexDelete, osStatus_t, osMutexId_t) - -/// Create and Initialize a Mutex object. -/// \note API identical to osMutexNew -osMutexId_t svcRtxMutexNew (const osMutexAttr_t *attr) { - os_mutex_t *mutex; - uint32_t attr_bits; - uint8_t flags; - const char *name; - - // Process attributes - if (attr != NULL) { - name = attr->name; - attr_bits = attr->attr_bits; - mutex = attr->cb_mem; - if (mutex != NULL) { - if (((uint32_t)mutex & 3U) || (attr->cb_size < sizeof(os_mutex_t))) { - EvrRtxMutexError(NULL, osRtxErrorInvalidControlBlock); - return NULL; - } - } else { - if (attr->cb_size != 0U) { - EvrRtxMutexError(NULL, osRtxErrorInvalidControlBlock); - return NULL; - } - } - } else { - name = NULL; - attr_bits = 0U; - mutex = NULL; - } - - // Allocate object memory if not provided - if (mutex == NULL) { - if (osRtxInfo.mpi.mutex != NULL) { - mutex = osRtxMemoryPoolAlloc(osRtxInfo.mpi.mutex); - } else { - mutex = osRtxMemoryAlloc(osRtxInfo.mem.common, sizeof(os_mutex_t), 1U); - } - if (mutex == NULL) { - EvrRtxMutexError(NULL, osErrorNoMemory); - return NULL; - } - flags = osRtxFlagSystemObject; - } else { - flags = 0U; - } - - // Initialize control block - mutex->id = osRtxIdMutex; - mutex->state = osRtxObjectActive; - mutex->flags = flags; - mutex->attr = (uint8_t)attr_bits; - mutex->name = name; - mutex->thread_list = NULL; - mutex->owner_thread = NULL; - mutex->owner_prev = NULL; - mutex->owner_next = NULL; - mutex->lock = 0U; - - EvrRtxMutexCreated(mutex); - - return mutex; -} - -/// Get name of a Mutex object. -/// \note API identical to osMutexGetName -const char *svcRtxMutexGetName (osMutexId_t mutex_id) { - os_mutex_t *mutex = (os_mutex_t *)mutex_id; - - // Check parameters - if ((mutex == NULL) || (mutex->id != osRtxIdMutex)) { - EvrRtxMutexGetName(mutex, NULL); - return NULL; - } - - // Check object state - if (mutex->state == osRtxObjectInactive) { - EvrRtxMutexGetName(mutex, NULL); - return NULL; - } - - EvrRtxMutexGetName(mutex, mutex->name); - - return mutex->name; -} - -/// Acquire a Mutex or timeout if it is locked. -/// \note API identical to osMutexAcquire -osStatus_t svcRtxMutexAcquire (osMutexId_t mutex_id, uint32_t timeout) { - os_mutex_t *mutex = (os_mutex_t *)mutex_id; - os_thread_t *running_thread; - - running_thread = osRtxThreadGetRunning(); - if (running_thread == NULL) { - EvrRtxMutexError(mutex, osRtxErrorKernelNotRunning); - return osError; - } - - // Check parameters - if ((mutex == NULL) || (mutex->id != osRtxIdMutex)) { - EvrRtxMutexError(mutex, osErrorParameter); - return osErrorParameter; - } - - // Check object state - if (mutex->state == osRtxObjectInactive) { - EvrRtxMutexError(mutex, osErrorResource); - return osErrorResource; - } - - // Check if Mutex is not locked - if (mutex->lock == 0U) { - // Acquire Mutex - mutex->owner_thread = running_thread; - mutex->owner_next = running_thread->mutex_list; - mutex->owner_prev = NULL; - if (running_thread->mutex_list != NULL) { - running_thread->mutex_list->owner_prev = mutex; - } - running_thread->mutex_list = mutex; - mutex->lock = 1U; - EvrRtxMutexAcquired(mutex, mutex->lock); - return osOK; - } - - // Check if Mutex is recursive and running Thread is the owner - if ((mutex->attr & osMutexRecursive) && (mutex->owner_thread == running_thread)) { - // Increment lock counter - if (mutex->lock == osRtxMutexLockLimit) { - EvrRtxMutexError(mutex, osRtxErrorMutexLockLimit); - return osErrorResource; - } - mutex->lock++; - EvrRtxMutexAcquired(mutex, mutex->lock); - return osOK; - } - - // Check if timeout is specified - if (timeout != 0U) { - // Check if Priority inheritance protocol is enabled - if (mutex->attr & osMutexPrioInherit) { - // Raise priority of owner Thread if lower than priority of running Thread - if (mutex->owner_thread->priority < running_thread->priority) { - mutex->owner_thread->priority = running_thread->priority; - osRtxThreadListSort(mutex->owner_thread); - } - } - EvrRtxMutexAcquirePending(mutex, timeout); - // Suspend current Thread - osRtxThreadListPut((os_object_t*)mutex, running_thread); - osRtxThreadWaitEnter(osRtxThreadWaitingMutex, timeout); - return osErrorTimeout; - } - - // Mutex was not acquired - EvrRtxMutexNotAcquired(mutex); - - return osErrorResource; -} - -/// Release a Mutex that was acquired by osMutexAcquire. -/// \note API identical to osMutexRelease -osStatus_t svcRtxMutexRelease (osMutexId_t mutex_id) { - os_mutex_t *mutex = (os_mutex_t *)mutex_id; - os_mutex_t *mutex0; - os_thread_t *thread; - os_thread_t *running_thread; - int8_t priority; - - running_thread = osRtxThreadGetRunning(); - if (running_thread == NULL) { - EvrRtxMutexError(mutex, osRtxErrorKernelNotRunning); - return osError; - } - - // Check parameters - if ((mutex == NULL) || (mutex->id != osRtxIdMutex)) { - EvrRtxMutexError(mutex, osErrorParameter); - return osErrorParameter; - } - - // Check object state - if (mutex->state == osRtxObjectInactive) { - EvrRtxMutexError(mutex, osErrorResource); - return osErrorResource; - } - - // Check if running Thread is not the owner - if (mutex->owner_thread != running_thread) { - EvrRtxMutexError(mutex, osRtxErrorMutexNotOwned); - return osErrorResource; - } - - // Check if Mutex is not locked - if (mutex->lock == 0U) { - EvrRtxMutexError(mutex, osRtxErrorMutexNotLocked); - return osErrorResource; - } - - // Decrement Lock counter - mutex->lock--; - EvrRtxMutexReleased(mutex, mutex->lock); - - // Check Lock counter - if (mutex->lock != 0U) { - return osOK; - } - - // Remove Mutex from Thread owner list - if (mutex->owner_next != NULL) { - mutex->owner_next->owner_prev = mutex->owner_prev; - } - if (mutex->owner_prev != NULL) { - mutex->owner_prev->owner_next = mutex->owner_next; - } else { - running_thread->mutex_list = mutex->owner_next; - } - - // Restore running Thread priority - if (mutex->attr & osMutexPrioInherit) { - priority = running_thread->priority_base; - mutex0 = running_thread->mutex_list; - while (mutex0) { - // Mutexes owned by running Thread - if ((mutex0->thread_list != NULL) && (mutex0->thread_list->priority > priority)) { - // Higher priority Thread is waiting for Mutex - priority = mutex0->thread_list->priority; - } - mutex0 = mutex0->owner_next; - } - running_thread->priority = priority; - } - - // Check if Thread is waiting for a Mutex - if (mutex->thread_list != NULL) { - // Wakeup waiting Thread with highest Priority - thread = osRtxThreadListGet((os_object_t*)mutex); - osRtxThreadWaitExit(thread, (uint32_t)osOK, false); - // Thread is the new Mutex owner - mutex->owner_thread = thread; - mutex->owner_next = thread->mutex_list; - mutex->owner_prev = NULL; - thread->mutex_list = mutex; - mutex->lock = 1U; - EvrRtxMutexAcquired(mutex, 1U); - } - - osRtxThreadDispatch(NULL); - - return osOK; -} - -/// Get Thread which owns a Mutex object. -/// \note API identical to osMutexGetOwner -osThreadId_t svcRtxMutexGetOwner (osMutexId_t mutex_id) { - os_mutex_t *mutex = (os_mutex_t *)mutex_id; - - // Check parameters - if ((mutex == NULL) || (mutex->id != osRtxIdMutex)) { - EvrRtxMutexGetOwner(mutex, NULL); - return NULL; - } - - // Check object state - if (mutex->state == osRtxObjectInactive) { - EvrRtxMutexGetOwner(mutex, NULL); - return NULL; - } - - // Check if Mutex is not locked - if (mutex->lock == 0U) { - EvrRtxMutexGetOwner(mutex, NULL); - return NULL; - } - - EvrRtxMutexGetOwner(mutex, mutex->owner_thread); - - return mutex->owner_thread; -} - -/// Delete a Mutex object. -/// \note API identical to osMutexDelete -osStatus_t svcRtxMutexDelete (osMutexId_t mutex_id) { - os_mutex_t *mutex = (os_mutex_t *)mutex_id; - os_mutex_t *mutex0; - os_thread_t *thread; - int8_t priority; - - // Check parameters - if ((mutex == NULL) || (mutex->id != osRtxIdMutex)) { - EvrRtxMutexError(mutex, osErrorParameter); - return osErrorParameter; - } - - // Check object state - if (mutex->state == osRtxObjectInactive) { - EvrRtxMutexError(mutex, osErrorResource); - return osErrorResource; - } - - // Mark object as inactive - mutex->state = osRtxObjectInactive; - - // Check if Mutex is locked - if (mutex->lock != 0U) { - - thread = mutex->owner_thread; - - // Remove Mutex from Thread owner list - if (mutex->owner_next != NULL) { - mutex->owner_next->owner_prev = mutex->owner_prev; - } - if (mutex->owner_prev != NULL) { - mutex->owner_prev->owner_next = mutex->owner_next; - } else { - thread->mutex_list = mutex->owner_next; - } - - // Restore owner Thread priority - if (mutex->attr & osMutexPrioInherit) { - priority = thread->priority_base; - mutex0 = thread->mutex_list; - while (mutex0) { - // Mutexes owned by running Thread - if ((mutex0->thread_list != NULL) && (mutex0->thread_list->priority > priority)) { - // Higher priority Thread is waiting for Mutex - priority = mutex0->thread_list->priority; - } - mutex0 = mutex0->owner_next; - } - if (thread->priority != priority) { - thread->priority = priority; - osRtxThreadListSort(thread); - } - } - - // Unblock waiting threads - if (mutex->thread_list != NULL) { - do { - thread = osRtxThreadListGet((os_object_t*)mutex); - osRtxThreadWaitExit(thread, (uint32_t)osErrorResource, false); - } while (mutex->thread_list != NULL); - } - - osRtxThreadDispatch(NULL); - } - - // Free object memory - if (mutex->flags & osRtxFlagSystemObject) { - if (osRtxInfo.mpi.mutex != NULL) { - osRtxMemoryPoolFree(osRtxInfo.mpi.mutex, mutex); - } else { - osRtxMemoryFree(osRtxInfo.mem.common, mutex); - } - } - - EvrRtxMutexDestroyed(mutex); - - return osOK; -} - - -// ==== Public API ==== - -/// Create and Initialize a Mutex object. -osMutexId_t osMutexNew (const osMutexAttr_t *attr) { - EvrRtxMutexNew(attr); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxMutexError(NULL, osErrorISR); - return NULL; - } - return __svcMutexNew(attr); -} - -/// Get name of a Mutex object. -const char *osMutexGetName (osMutexId_t mutex_id) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxMutexGetName(mutex_id, NULL); - return NULL; - } - return __svcMutexGetName(mutex_id); -} - -/// Acquire a Mutex or timeout if it is locked. -osStatus_t osMutexAcquire (osMutexId_t mutex_id, uint32_t timeout) { - EvrRtxMutexAcquire(mutex_id, timeout); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxMutexError(mutex_id, osErrorISR); - return osErrorISR; - } - return __svcMutexAcquire(mutex_id, timeout); -} - -/// Release a Mutex that was acquired by \ref osMutexAcquire. -osStatus_t osMutexRelease (osMutexId_t mutex_id) { - EvrRtxMutexRelease(mutex_id); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxMutexError(mutex_id, osErrorISR); - return osErrorISR; - } - return __svcMutexRelease(mutex_id); -} - -/// Get Thread which owns a Mutex object. -osThreadId_t osMutexGetOwner (osMutexId_t mutex_id) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxMutexGetOwner(mutex_id, NULL); - return NULL; - } - return __svcMutexGetOwner(mutex_id); -} - -/// Delete a Mutex object. -osStatus_t osMutexDelete (osMutexId_t mutex_id) { - EvrRtxMutexDelete(mutex_id); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxMutexError(mutex_id, osErrorISR); - return osErrorISR; - } - return __svcMutexDelete(mutex_id); -} diff --git a/rtos/rtx5/TARGET_CORTEX_M/rtx_os.h b/rtos/rtx5/TARGET_CORTEX_M/rtx_os.h deleted file mode 100644 index fbc243c..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/rtx_os.h +++ /dev/null @@ -1,479 +0,0 @@ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ----------------------------------------------------------------------------- - * - * Project: CMSIS-RTOS RTX - * Title: RTX OS definitions - * - * ----------------------------------------------------------------------------- - */ - -#ifndef RTX_OS_H_ -#define RTX_OS_H_ - -#include -#include -#include "cmsis_os2.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - - -/// Kernel Information -#define osRtxVersionAPI 20010000 ///< API version (2.1.0) -#define osRtxVersionKernel 50010001 ///< Kernel version (5.1.1) -#define osRtxKernelId "RTX V5.1.1" ///< Kernel identification string - - -// ==== Common definitions ==== - -/// Object Identifier definitions -#define osRtxIdInvalid 0x00U -#define osRtxIdThread 0x01U -#define osRtxIdTimer 0x02U -#define osRtxIdEventFlags 0x03U -#define osRtxIdMutex 0x04U -#define osRtxIdSemaphore 0x05U -#define osRtxIdMemoryPool 0x06U -#define osRtxIdMessage 0x07U -#define osRtxIdMessageQueue 0x08U - -/// Object State definitions (except for Threads and Timers) -#define osRtxObjectInactive 0x00U -#define osRtxObjectActive 0x01U - -/// Object Flags definitions -#define osRtxFlagSystemObject 0x01U -#define osRtxFlagSystemMemory 0x02U - - -// ==== Kernel definitions ==== - -/// Kernel State definitions -#define osRtxKernelInactive ((uint8_t)osKernelInactive) -#define osRtxKernelReady ((uint8_t)osKernelReady) -#define osRtxKernelRunning ((uint8_t)osKernelRunning) -#define osRtxKernelLocked ((uint8_t)osKernelLocked) -#define osRtxKernelSuspended ((uint8_t)osKernelSuspended) - - -// ==== Thread definitions ==== - -/// Thread State definitions (extending osThreadState) -#define osRtxThreadStateMask 0x0FU - -#define osRtxThreadInactive ((uint8_t)osThreadInactive) -#define osRtxThreadReady ((uint8_t)osThreadReady) -#define osRtxThreadRunning ((uint8_t)osThreadRunning) -#define osRtxThreadBlocked ((uint8_t)osThreadBlocked) -#define osRtxThreadTerminated ((uint8_t)osThreadTerminated) - -#define osRtxThreadWaitingDelay (osRtxThreadBlocked | 0x10U) -#define osRtxThreadWaitingJoin (osRtxThreadBlocked | 0x20U) -#define osRtxThreadWaitingThreadFlags (osRtxThreadBlocked | 0x30U) -#define osRtxThreadWaitingEventFlags (osRtxThreadBlocked | 0x40U) -#define osRtxThreadWaitingMutex (osRtxThreadBlocked | 0x50U) -#define osRtxThreadWaitingSemaphore (osRtxThreadBlocked | 0x60U) -#define osRtxThreadWaitingMemoryPool (osRtxThreadBlocked | 0x70U) -#define osRtxThreadWaitingMessageGet (osRtxThreadBlocked | 0x80U) -#define osRtxThreadWaitingMessagePut (osRtxThreadBlocked | 0x90U) - -/// Thread Flags definitions -#define osRtxThreadFlagDefStack 0x10U ///< Default Stack flag - -/// Stack Marker definitions -#define osRtxStackMagicWord 0xE25A2EA5U ///< Stack Magic Word (Stack Base) -#define osRtxStackFillPattern 0xCCCCCCCCU ///< Stack Fill Pattern - -/// Thread Control Block -typedef struct osRtxThread_s { - uint8_t id; ///< Object Identifier - uint8_t state; ///< Object State - uint8_t flags; ///< Object Flags - uint8_t attr; ///< Object Attributes - const char *name; ///< Object Name - struct osRtxThread_s *thread_next; ///< Link pointer to next Thread in Object list - struct osRtxThread_s *thread_prev; ///< Link pointer to previous Thread in Object list - struct osRtxThread_s *delay_next; ///< Link pointer to next Thread in Delay list - struct osRtxThread_s *delay_prev; ///< Link pointer to previous Thread in Delay list - struct osRtxThread_s *thread_join; ///< Thread waiting to Join - uint32_t delay; ///< Delay Time - int8_t priority; ///< Thread Priority - int8_t priority_base; ///< Base Priority - uint8_t stack_frame; ///< Stack Frame (EXC_RETURN[7..0]) - uint8_t flags_options; ///< Thread/Event Flags Options - uint32_t wait_flags; ///< Waiting Thread/Event Flags - uint32_t thread_flags; ///< Thread Flags - struct osRtxMutex_s *mutex_list; ///< Link pointer to list of owned Mutexes - void *stack_mem; ///< Stack Memory - uint32_t stack_size; ///< Stack Size - uint32_t sp; ///< Current Stack Pointer - uint32_t thread_addr; ///< Thread entry address - uint32_t tz_memory; ///< TrustZone Memory Identifier - void *context; ///< Context for OsEventObserver objects -} osRtxThread_t; - - -// ==== Timer definitions ==== - -/// Timer State definitions -#define osRtxTimerInactive 0x00U ///< Timer Inactive -#define osRtxTimerStopped 0x01U ///< Timer Stopped -#define osRtxTimerRunning 0x02U ///< Timer Running - -/// Timer Type definitions -#define osRtxTimerPeriodic ((uint8_t)osTimerPeriodic) - -/// Timer Function Information -typedef struct { - void *fp; ///< Function Pointer - void *arg; ///< Function Argument -} osRtxTimerFinfo_t; - -/// Timer Control Block -typedef struct osRtxTimer_s { - uint8_t id; ///< Object Identifier - uint8_t state; ///< Object State - uint8_t flags; ///< Object Flags - uint8_t type; ///< Timer Type (Periodic/One-shot) - const char *name; ///< Object Name - struct osRtxTimer_s *prev; ///< Pointer to previous active Timer - struct osRtxTimer_s *next; ///< Pointer to next active Timer - uint32_t tick; ///< Timer current Tick - uint32_t load; ///< Timer Load value - osRtxTimerFinfo_t finfo; ///< Timer Function Info -} osRtxTimer_t; - - -// ==== Event Flags definitions ==== - -/// Event Flags Control Block -typedef struct osRtxEventFlags_s { - uint8_t id; ///< Object Identifier - uint8_t state; ///< Object State - uint8_t flags; ///< Object Flags - uint8_t reserved; - const char *name; ///< Object Name - osRtxThread_t *thread_list; ///< Waiting Threads List - uint32_t event_flags; ///< Event Flags -} osRtxEventFlags_t; - - -// ==== Mutex definitions ==== - -/// Mutex Control Block -typedef struct osRtxMutex_s { - uint8_t id; ///< Object Identifier - uint8_t state; ///< Object State - uint8_t flags; ///< Object Flags - uint8_t attr; ///< Object Attributes - const char *name; ///< Object Name - osRtxThread_t *thread_list; ///< Waiting Threads List - osRtxThread_t *owner_thread; ///< Owner Thread - struct osRtxMutex_s *owner_prev; ///< Pointer to previous owned Mutex - struct osRtxMutex_s *owner_next; ///< Pointer to next owned Mutex - uint8_t lock; ///< Lock counter - uint8_t padding[3]; -} osRtxMutex_t; - - -// ==== Semaphore definitions ==== - -/// Semaphore Control Block -typedef struct osRtxSemaphore_s { - uint8_t id; ///< Object Identifier - uint8_t state; ///< Object State - uint8_t flags; ///< Object Flags - uint8_t reserved; - const char *name; ///< Object Name - osRtxThread_t *thread_list; ///< Waiting Threads List - uint16_t tokens; ///< Current number of tokens - uint16_t max_tokens; ///< Maximum number of tokens -} osRtxSemaphore_t; - - -// ==== Memory Pool definitions ==== - -/// Memory Pool Information -typedef struct osRtxMpInfo_s { - uint32_t max_blocks; ///< Maximum number of Blocks - uint32_t used_blocks; ///< Number of used Blocks - uint32_t block_size; ///< Block Size - void *block_base; ///< Block Memory Base Address - void *block_lim; ///< Block Memory Limit Address - void *block_free; ///< First free Block Address -} osRtxMpInfo_t; - -/// Memory Pool Control Block -typedef struct osRtxMemoryPool_s { - uint8_t id; ///< Object Identifier - uint8_t state; ///< Object State - uint8_t flags; ///< Object Flags - uint8_t reserved; - const char *name; ///< Object Name - osRtxThread_t *thread_list; ///< Waiting Threads List - osRtxMpInfo_t mp_info; ///< Memory Pool Info -} osRtxMemoryPool_t; - - -// ==== Message Queue definitions ==== - -/// Message Control Block -typedef struct osRtxMessage_s { - uint8_t id; ///< Object Identifier - uint8_t state; ///< Object State - uint8_t flags; ///< Object Flags - uint8_t priority; ///< Message Priority - struct osRtxMessage_s *prev; ///< Pointer to previous Message - struct osRtxMessage_s *next; ///< Pointer to next Message -} osRtxMessage_t; - -/// Message Queue Control Block -typedef struct osRtxMessageQueue_s { - uint8_t id; ///< Object Identifier - uint8_t state; ///< Object State - uint8_t flags; ///< Object Flags - uint8_t reserved; - const char *name; ///< Object Name - osRtxThread_t *thread_list; ///< Waiting Threads List - osRtxMpInfo_t mp_info; ///< Memory Pool Info - uint32_t msg_size; ///< Message Size - uint32_t msg_count; ///< Number of queued Messages - osRtxMessage_t *msg_first; ///< Pointer to first Message - osRtxMessage_t *msg_last; ///< Pointer to last Message -} osRtxMessageQueue_t; - - -// ==== Generic Object definitions ==== - -/// Generic Object Control Block -typedef struct osRtxObject_s { - uint8_t id; ///< Object Identifier - uint8_t state; ///< Object State - uint8_t flags; ///< Object Flags - uint8_t reserved; - const char *name; ///< Object Name - osRtxThread_t *thread_list; ///< Threads List -} osRtxObject_t; - - -// ==== OS Runtime Information definitions ==== - -/// OS Runtime Information structure -typedef struct { - const char *os_id; ///< OS Identification - uint32_t version; ///< OS Version - struct { ///< Kernel Info - uint8_t state; ///< State - volatile uint8_t blocked; ///< Blocked - uint8_t pendISR; ///< Pending ISR (SV and SysTick) - uint8_t pendSV; ///< Pending SV - uint32_t sys_freq; ///< System Frequency - uint64_t tick; ///< Tick counter - } kernel; - int32_t tick_irqn; ///< Tick Timer IRQ Number - struct { ///< Thread Info - struct { ///< Thread Run Info - osRtxThread_t *curr; ///< Current running Thread - osRtxThread_t *next; ///< Next Thread to Run - } run; - volatile osRtxObject_t ready; ///< Ready List Object - osRtxThread_t *idle; ///< Idle Thread - osRtxThread_t *delay_list; ///< Delay List - osRtxThread_t *wait_list; ///< Wait List (no Timeout) - osRtxThread_t *terminate_list; ///< Terminate Thread List - struct { ///< Thread Round Robin Info - osRtxThread_t *thread; ///< Round Robin Thread - uint32_t tick; ///< Round Robin Time Tick - uint32_t timeout; ///< Round Robin Timeout - } robin; - } thread; - struct { ///< Timer Info - osRtxTimer_t *list; ///< Active Timer List - osRtxThread_t *thread; ///< Timer Thread - osRtxMessageQueue_t *mq; ///< Timer Message Queue - void (*tick)(void); ///< Timer Tick Function - } timer; - struct { ///< ISR Post Processing Queue - uint16_t max; ///< Maximum Items - uint16_t cnt; ///< Item Count - uint16_t in; ///< Incoming Item Index - uint16_t out; ///< Outgoing Item Index - void **data; ///< Queue Data - } isr_queue; - struct { ///< ISR Post Processing functions - void (*thread)(osRtxThread_t*); ///< Thread Post Processing function - void (*event_flags)(osRtxEventFlags_t*); ///< Event Flags Post Processing function - void (*semaphore)(osRtxSemaphore_t*); ///< Semaphore Post Processing function - void (*memory_pool)(osRtxMemoryPool_t*); ///< Memory Pool Post Processing function - void (*message_queue)(osRtxMessage_t*); ///< Message Queue Post Processing function - } post_process; - struct { ///< Memory Pools (Variable Block Size) - void *stack; ///< Stack Memory - void *mp_data; ///< Memory Pool Data Memory - void *mq_data; ///< Message Queue Data Memory - void *common; ///< Common Memory - } mem; - struct { ///< Memory Pools (Fixed Block Size) - osRtxMpInfo_t *stack; ///< Stack for Threads - osRtxMpInfo_t *thread; ///< Thread Control Blocks - osRtxMpInfo_t *timer; ///< Timer Control Blocks - osRtxMpInfo_t *event_flags; ///< Event Flags Control Blocks - osRtxMpInfo_t *mutex; ///< Mutex Control Blocks - osRtxMpInfo_t *semaphore; ///< Semaphore Control Blocks - osRtxMpInfo_t *memory_pool; ///< Memory Pool Control Blocks - osRtxMpInfo_t *message_queue; ///< Message Queue Control Blocks - } mpi; - uint32_t padding; -} osRtxInfo_t; - -extern osRtxInfo_t osRtxInfo; ///< OS Runtime Information - - -// ==== OS API definitions ==== - -/// Object Limits definitions -#define osRtxThreadFlagsLimit 31U ///< number of Thread Flags available per thread -#define osRtxEventFlagsLimit 31U ///< number of Event Flags available per object -#define osRtxMutexLockLimit 255U ///< maximum number of recursive mutex locks -#define osRtxSemaphoreTokenLimit 65535U ///< maximum number of tokens per semaphore - -/// Control Block sizes -#define osRtxThreadCbSize sizeof(osRtxThread_t) -#define osRtxTimerCbSize sizeof(osRtxTimer_t) -#define osRtxEventFlagsCbSize sizeof(osRtxEventFlags_t) -#define osRtxMutexCbSize sizeof(osRtxMutex_t) -#define osRtxSemaphoreCbSize sizeof(osRtxSemaphore_t) -#define osRtxMemoryPoolCbSize sizeof(osRtxMemoryPool_t) -#define osRtxMessageQueueCbSize sizeof(osRtxMessageQueue_t) - -/// Memory size in bytes for Memory Pool storage. -/// \param block_count maximum number of memory blocks in memory pool. -/// \param block_size memory block size in bytes. -#define osRtxMemoryPoolMemSize(block_count, block_size) \ - (4*(block_count)*(((block_size)+3)/4)) - -/// Memory size in bytes for Message Queue storage. -/// \param msg_count maximum number of messages in queue. -/// \param msg_size maximum message size in bytes. -#define osRtxMessageQueueMemSize(msg_count, msg_size) \ - (4*(msg_count)*(3+(((msg_size)+3)/4))) - - -// ==== OS External Functions ==== - -/// OS Error Codes -#define osRtxErrorStackUnderflow 1U -#define osRtxErrorISRQueueOverflow 2U -#define osRtxErrorTimerQueueOverflow 3U -#define osRtxErrorClibSpace 4U -#define osRtxErrorClibMutex 5U - -/// OS Error Callback function -extern uint32_t osRtxErrorNotify (uint32_t code, void *object_id); - -/// OS Idle Thread -extern void osRtxIdleThread (void *argument); - -/// OS Exception handlers -extern void SVC_Handler (void); -extern void PendSV_Handler (void); -extern void SysTick_Handler (void); - - -/// OS System Timer functions (default implementation uses SysTick) - -/// Setup System Timer. -/// \return system timer IRQ number. -extern int32_t osRtxSysTimerSetup (void); - -/// Enable System Timer. -extern void osRtxSysTimerEnable (void); - -/// Disable System Timer. -extern void osRtxSysTimerDisable (void); - -/// Acknowledge System Timer IRQ. -extern void osRtxSysTimerAckIRQ (void); - -/// Get System Timer count. -/// \return system timer count. -extern uint32_t osRtxSysTimerGetCount (void); - -/// Get System Timer frequency. -/// \return system timer frequency. -extern uint32_t osRtxSysTimerGetFreq (void); - - -// ==== OS External Configuration ==== - -/// OS Configuration flags -#define osRtxConfigPrivilegedMode (1UL<<0) ///< Threads in Privileged mode -#define osRtxConfigStackCheck (1UL<<1) ///< Stack overrun checking -#define osRtxConfigStackWatermark (1UL<<2) ///< Stack usage Watermark - -/// OS Configuration structure -typedef struct { - uint32_t flags; ///< OS Configuration Flags - uint32_t tick_freq; ///< Kernel Tick Frequency - uint32_t robin_timeout; ///< Round Robin Timeout Tick - struct { ///< ISR Post Processing Queue - void **data; ///< Queue Data - uint16_t max; ///< Maximum Items - uint16_t padding; - } isr_queue; - struct { ///< Memory Pools (Variable Block Size) - void *stack_addr; ///< Stack Memory Address - uint32_t stack_size; ///< Stack Memory Size - void *mp_data_addr; ///< Memory Pool Memory Address - uint32_t mp_data_size; ///< Memory Pool Memory Size - void *mq_data_addr; ///< Message Queue Data Memory Address - uint32_t mq_data_size; ///< Message Queue Data Memory Size - void *common_addr; ///< Common Memory Address - uint32_t common_size; ///< Common Memory Size - } mem; - struct { ///< Memory Pools (Fixed Block Size) - osRtxMpInfo_t *stack; ///< Stack for Threads - osRtxMpInfo_t *thread; ///< Thread Control Blocks - osRtxMpInfo_t *timer; ///< Timer Control Blocks - osRtxMpInfo_t *event_flags; ///< Event Flags Control Blocks - osRtxMpInfo_t *mutex; ///< Mutex Control Blocks - osRtxMpInfo_t *semaphore; ///< Semaphore Control Blocks - osRtxMpInfo_t *memory_pool; ///< Memory Pool Control Blocks - osRtxMpInfo_t *message_queue; ///< Message Queue Control Blocks - } mpi; - uint32_t thread_stack_size; ///< Default Thread Stack Size - const - osThreadAttr_t *idle_thread_attr; ///< Idle Thread Attributes - const - osThreadAttr_t *timer_thread_attr; ///< Timer Thread Attributes - const - osMessageQueueAttr_t *timer_mq_attr; ///< Timer Message Queue Attributes - uint32_t timer_mq_mcnt; ///< Timer Message Queue maximum Messages -} osRtxConfig_t; - -extern const osRtxConfig_t osRtxConfig; ///< OS Configuration - - -#ifdef __cplusplus -} -#endif - -#endif // RTX_OS_H_ diff --git a/rtos/rtx5/TARGET_CORTEX_M/rtx_semaphore.c b/rtos/rtx5/TARGET_CORTEX_M/rtx_semaphore.c deleted file mode 100644 index f0a3c40..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/rtx_semaphore.c +++ /dev/null @@ -1,484 +0,0 @@ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ----------------------------------------------------------------------------- - * - * Project: CMSIS-RTOS RTX - * Title: Semaphore functions - * - * ----------------------------------------------------------------------------- - */ - -#include "rtx_lib.h" - - -// ==== Helper functions ==== - -/// Decrement Semaphore tokens. -/// \param[in] semaphore semaphore object. -/// \return 1 - success, 0 - failure. -static uint32_t SemaphoreTokenDecrement (os_semaphore_t *semaphore) { -#if (__EXCLUSIVE_ACCESS == 0U) - uint32_t primask = __get_PRIMASK(); -#endif - uint32_t ret; - -#if (__EXCLUSIVE_ACCESS == 0U) - __disable_irq(); - - if (semaphore->tokens != 0U) { - semaphore->tokens--; - ret = 1U; - } else { - ret = 0U; - } - - if (primask == 0U) { - __enable_irq(); - } -#else - if (atomic_dec16_nz(&semaphore->tokens) != 0U) { - ret = 1U; - } else { - ret = 0U; - } -#endif - - return ret; -} - -/// Increment Semaphore tokens. -/// \param[in] semaphore semaphore object. -/// \return 1 - success, 0 - failure. -static uint32_t SemaphoreTokenIncrement (os_semaphore_t *semaphore) { -#if (__EXCLUSIVE_ACCESS == 0U) - uint32_t primask = __get_PRIMASK(); -#endif - uint32_t ret; - -#if (__EXCLUSIVE_ACCESS == 0U) - __disable_irq(); - - if (semaphore->tokens < semaphore->max_tokens) { - semaphore->tokens++; - ret = 1U; - } else { - ret = 0U; - } - - if (primask == 0U) { - __enable_irq(); - } -#else - if (atomic_inc16_lt(&semaphore->tokens, semaphore->max_tokens) < semaphore->max_tokens) { - ret = 1U; - } else { - ret = 0U; - } -#endif - - return ret; -} - - -// ==== Library functions ==== - -/// Semaphore post ISR processing. -/// \param[in] semaphore semaphore object. -void osRtxSemaphorePostProcess (os_semaphore_t *semaphore) { - os_thread_t *thread; - - if (semaphore->state == osRtxObjectInactive) { - return; - } - - // Check if Thread is waiting for a token - if (semaphore->thread_list != NULL) { - // Try to acquire token - if (SemaphoreTokenDecrement(semaphore) != 0U) { - // Wakeup waiting Thread with highest Priority - thread = osRtxThreadListGet((os_object_t*)semaphore); - osRtxThreadWaitExit(thread, (uint32_t)osOK, false); - EvrRtxSemaphoreAcquired(semaphore); - } - } -} - - -// ==== Service Calls ==== - -// Service Calls definitions -SVC0_3M(SemaphoreNew, osSemaphoreId_t, uint32_t, uint32_t, const osSemaphoreAttr_t *) -SVC0_1 (SemaphoreGetName, const char *, osSemaphoreId_t) -SVC0_2 (SemaphoreAcquire, osStatus_t, osSemaphoreId_t, uint32_t) -SVC0_1 (SemaphoreRelease, osStatus_t, osSemaphoreId_t) -SVC0_1 (SemaphoreGetCount, uint32_t, osSemaphoreId_t) -SVC0_1 (SemaphoreDelete, osStatus_t, osSemaphoreId_t) - -/// Create and Initialize a Semaphore object. -/// \note API identical to osSemaphoreNew -osSemaphoreId_t svcRtxSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr) { - os_semaphore_t *semaphore; - uint8_t flags; - const char *name; - - // Check parameters - if ((max_count == 0U) || (max_count > osRtxSemaphoreTokenLimit) || (initial_count > max_count)) { - EvrRtxSemaphoreError(NULL, osErrorParameter); - return NULL; - } - - // Process attributes - if (attr != NULL) { - name = attr->name; - semaphore = attr->cb_mem; - if (semaphore != NULL) { - if (((uint32_t)semaphore & 3U) || (attr->cb_size < sizeof(os_semaphore_t))) { - EvrRtxSemaphoreError(NULL, osRtxErrorInvalidControlBlock); - return NULL; - } - } else { - if (attr->cb_size != 0U) { - EvrRtxSemaphoreError(NULL, osRtxErrorInvalidControlBlock); - return NULL; - } - } - } else { - name = NULL; - semaphore = NULL; - } - - // Allocate object memory if not provided - if (semaphore == NULL) { - if (osRtxInfo.mpi.semaphore != NULL) { - semaphore = osRtxMemoryPoolAlloc(osRtxInfo.mpi.semaphore); - } else { - semaphore = osRtxMemoryAlloc(osRtxInfo.mem.common, sizeof(os_semaphore_t), 1U); - } - if (semaphore == NULL) { - EvrRtxSemaphoreError(NULL, osErrorNoMemory); - return NULL; - } - flags = osRtxFlagSystemObject; - } else { - flags = 0U; - } - - // Initialize control block - semaphore->id = osRtxIdSemaphore; - semaphore->state = osRtxObjectActive; - semaphore->flags = flags; - semaphore->name = name; - semaphore->thread_list = NULL; - semaphore->tokens = (uint16_t)initial_count; - semaphore->max_tokens = (uint16_t)max_count; - - // Register post ISR processing function - osRtxInfo.post_process.semaphore = osRtxSemaphorePostProcess; - - EvrRtxSemaphoreCreated(semaphore); - - return semaphore; -} - -/// Get name of a Semaphore object. -/// \note API identical to osSemaphoreGetName -const char *svcRtxSemaphoreGetName (osSemaphoreId_t semaphore_id) { - os_semaphore_t *semaphore = (os_semaphore_t *)semaphore_id; - - // Check parameters - if ((semaphore == NULL) || (semaphore->id != osRtxIdSemaphore)) { - EvrRtxSemaphoreGetName(semaphore, NULL); - return NULL; - } - - // Check object state - if (semaphore->state == osRtxObjectInactive) { - EvrRtxSemaphoreGetName(semaphore, NULL); - return NULL; - } - - EvrRtxSemaphoreGetName(semaphore, semaphore->name); - - return semaphore->name; -} - -/// Acquire a Semaphore token or timeout if no tokens are available. -/// \note API identical to osSemaphoreAcquire -osStatus_t svcRtxSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout) { - os_semaphore_t *semaphore = (os_semaphore_t *)semaphore_id; - - // Check parameters - if ((semaphore == NULL) || (semaphore->id != osRtxIdSemaphore)) { - EvrRtxSemaphoreError(semaphore, osErrorParameter); - return osErrorParameter; - } - - // Check object state - if (semaphore->state == osRtxObjectInactive) { - EvrRtxSemaphoreError(semaphore, osErrorResource); - return osErrorResource; - } - - // Try to acquire token - if (SemaphoreTokenDecrement(semaphore) == 0U) { - // No token available - if (timeout != 0U) { - EvrRtxSemaphoreAcquirePending(semaphore, timeout); - // Suspend current Thread - osRtxThreadListPut((os_object_t*)semaphore, osRtxThreadGetRunning()); - osRtxThreadWaitEnter(osRtxThreadWaitingSemaphore, timeout); - return osErrorTimeout; - } else { - EvrRtxSemaphoreNotAcquired(semaphore); - return osErrorResource; - } - } - - EvrRtxSemaphoreAcquired(semaphore); - - return osOK; -} - -/// Release a Semaphore token that was acquired by osSemaphoreAcquire. -/// \note API identical to osSemaphoreRelease -osStatus_t svcRtxSemaphoreRelease (osSemaphoreId_t semaphore_id) { - os_semaphore_t *semaphore = (os_semaphore_t *)semaphore_id; - os_thread_t *thread; - - // Check parameters - if ((semaphore == NULL) || (semaphore->id != osRtxIdSemaphore)) { - EvrRtxSemaphoreError(semaphore, osErrorParameter); - return osErrorParameter; - } - - // Check object state - if (semaphore->state == osRtxObjectInactive) { - EvrRtxSemaphoreError(semaphore, osErrorResource); - return osErrorResource; - } - - // Check if Thread is waiting for a token - if (semaphore->thread_list != NULL) { - EvrRtxSemaphoreReleased(semaphore); - // Wakeup waiting Thread with highest Priority - thread = osRtxThreadListGet((os_object_t*)semaphore); - osRtxThreadWaitExit(thread, (uint32_t)osOK, true); - EvrRtxSemaphoreAcquired(semaphore); - } else { - // Try to release token - if (SemaphoreTokenIncrement(semaphore) == 0U) { - EvrRtxSemaphoreError(semaphore, osRtxErrorSemaphoreCountLimit); - return osErrorResource; - } - EvrRtxSemaphoreReleased(semaphore); - } - - return osOK; -} - -/// Get current Semaphore token count. -/// \note API identical to osSemaphoreGetCount -uint32_t svcRtxSemaphoreGetCount (osSemaphoreId_t semaphore_id) { - os_semaphore_t *semaphore = (os_semaphore_t *)semaphore_id; - - // Check parameters - if ((semaphore == NULL) || (semaphore->id != osRtxIdSemaphore)) { - EvrRtxSemaphoreGetCount(semaphore, 0U); - return 0U; - } - - // Check object state - if (semaphore->state == osRtxObjectInactive) { - EvrRtxSemaphoreGetCount(semaphore, 0U); - return 0U; - } - - EvrRtxSemaphoreGetCount(semaphore, semaphore->tokens); - - return semaphore->tokens; -} - -/// Delete a Semaphore object. -/// \note API identical to osSemaphoreDelete -osStatus_t svcRtxSemaphoreDelete (osSemaphoreId_t semaphore_id) { - os_semaphore_t *semaphore = (os_semaphore_t *)semaphore_id; - os_thread_t *thread; - - // Check parameters - if ((semaphore == NULL) || (semaphore->id != osRtxIdSemaphore)) { - EvrRtxSemaphoreError(semaphore, osErrorParameter); - return osErrorParameter; - } - - // Check object state - if (semaphore->state == osRtxObjectInactive) { - EvrRtxSemaphoreError(semaphore, osErrorResource); - return osErrorResource; - } - - // Mark object as inactive - semaphore->state = osRtxObjectInactive; - - // Unblock waiting threads - if (semaphore->thread_list != NULL) { - do { - thread = osRtxThreadListGet((os_object_t*)semaphore); - osRtxThreadWaitExit(thread, (uint32_t)osErrorResource, false); - } while (semaphore->thread_list != NULL); - osRtxThreadDispatch(NULL); - } - - // Free object memory - if (semaphore->flags & osRtxFlagSystemObject) { - if (osRtxInfo.mpi.semaphore != NULL) { - osRtxMemoryPoolFree(osRtxInfo.mpi.semaphore, semaphore); - } else { - osRtxMemoryFree(osRtxInfo.mem.common, semaphore); - } - } - - EvrRtxSemaphoreDestroyed(semaphore); - - return osOK; -} - - -// ==== ISR Calls ==== - -/// Acquire a Semaphore token or timeout if no tokens are available. -/// \note API identical to osSemaphoreAcquire -__STATIC_INLINE -osStatus_t isrRtxSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout) { - os_semaphore_t *semaphore = (os_semaphore_t *)semaphore_id; - - // Check parameters - if ((semaphore == NULL) || (semaphore->id != osRtxIdSemaphore) || (timeout != 0U)) { - EvrRtxSemaphoreError(semaphore, osErrorParameter); - return osErrorParameter; - } - - // Check object state - if (semaphore->state == osRtxObjectInactive) { - EvrRtxSemaphoreError(semaphore, osErrorResource); - return osErrorResource; - } - - // Try to acquire token - if (SemaphoreTokenDecrement(semaphore) == 0U) { - // No token available - EvrRtxSemaphoreNotAcquired(semaphore); - return osErrorResource; - } - - EvrRtxSemaphoreAcquired(semaphore); - - return osOK; -} - -/// Release a Semaphore token that was acquired by osSemaphoreAcquire. -/// \note API identical to osSemaphoreRelease -__STATIC_INLINE -osStatus_t isrRtxSemaphoreRelease (osSemaphoreId_t semaphore_id) { - os_semaphore_t *semaphore = (os_semaphore_t *)semaphore_id; - - // Check parameters - if ((semaphore == NULL) || (semaphore->id != osRtxIdSemaphore)) { - EvrRtxSemaphoreError(semaphore, osErrorParameter); - return osErrorParameter; - } - - // Check object state - if (semaphore->state == osRtxObjectInactive) { - EvrRtxSemaphoreError(semaphore, osErrorResource); - return osErrorResource; - } - - // Try to release token - if (SemaphoreTokenIncrement(semaphore) != 0U) { - // Register post ISR processing - osRtxPostProcess((os_object_t *)semaphore); - } else { - EvrRtxSemaphoreError(semaphore, osRtxErrorSemaphoreCountLimit); - return osErrorResource; - } - - EvrRtxSemaphoreReleased(semaphore); - - return osOK; -} - - -// ==== Public API ==== - -/// Create and Initialize a Semaphore object. -osSemaphoreId_t osSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr) { - EvrRtxSemaphoreNew(max_count, initial_count, attr); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxSemaphoreError(NULL, osErrorISR); - return NULL; - } - return __svcSemaphoreNew(max_count, initial_count, attr); -} - -/// Get name of a Semaphore object. -const char *osSemaphoreGetName (osSemaphoreId_t semaphore_id) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxSemaphoreGetName(semaphore_id, NULL); - return NULL; - } - return __svcSemaphoreGetName(semaphore_id); -} - -/// Acquire a Semaphore token or timeout if no tokens are available. -osStatus_t osSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout) { - EvrRtxSemaphoreAcquire(semaphore_id, timeout); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - return isrRtxSemaphoreAcquire(semaphore_id, timeout); - } else { - return __svcSemaphoreAcquire(semaphore_id, timeout); - } -} - -/// Release a Semaphore token that was acquired by osSemaphoreAcquire. -osStatus_t osSemaphoreRelease (osSemaphoreId_t semaphore_id) { - EvrRtxSemaphoreRelease(semaphore_id); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - return isrRtxSemaphoreRelease(semaphore_id); - } else { - return __svcSemaphoreRelease(semaphore_id); - } -} - -/// Get current Semaphore token count. -uint32_t osSemaphoreGetCount (osSemaphoreId_t semaphore_id) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - return svcRtxSemaphoreGetCount(semaphore_id); - } else { - return __svcSemaphoreGetCount(semaphore_id); - } -} - -/// Delete a Semaphore object. -osStatus_t osSemaphoreDelete (osSemaphoreId_t semaphore_id) { - EvrRtxSemaphoreDelete(semaphore_id); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxSemaphoreError(semaphore_id, osErrorISR); - return osErrorISR; - } - return __svcSemaphoreDelete(semaphore_id); -} diff --git a/rtos/rtx5/TARGET_CORTEX_M/rtx_system.c b/rtos/rtx5/TARGET_CORTEX_M/rtx_system.c deleted file mode 100644 index c8715cd..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/rtx_system.c +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ----------------------------------------------------------------------------- - * - * Project: CMSIS-RTOS RTX - * Title: System functions - * - * ----------------------------------------------------------------------------- - */ - -#include "rtx_lib.h" - - -// ==== Helper functions ==== - -/// Put Object into ISR Queue. -/// \param[in] object object. -/// \return 1 - success, 0 - failure. -static uint32_t isr_queue_put (void *object) { -#if (__EXCLUSIVE_ACCESS == 0U) - uint32_t primask = __get_PRIMASK(); -#else - uint32_t n; -#endif - uint16_t max; - uint32_t ret; - - max = osRtxInfo.isr_queue.max; - -#if (__EXCLUSIVE_ACCESS == 0U) - __disable_irq(); - - if (osRtxInfo.isr_queue.cnt < max) { - osRtxInfo.isr_queue.cnt++; - osRtxInfo.isr_queue.data[osRtxInfo.isr_queue.in] = object; - if (++osRtxInfo.isr_queue.in == max) { - osRtxInfo.isr_queue.in = 0U; - } - ret = 1U; - } else { - ret = 0U; - } - - if (primask == 0U) { - __enable_irq(); - } -#else - if (atomic_inc16_lt(&osRtxInfo.isr_queue.cnt, max) < max) { - n = atomic_inc16_lim(&osRtxInfo.isr_queue.in, max); - osRtxInfo.isr_queue.data[n] = object; - ret = 1U; - } else { - ret = 0U; - } -#endif - - return ret; -} - -/// Get Object from ISR Queue. -/// \return object or NULL. -static void *isr_queue_get (void) { -#if (__EXCLUSIVE_ACCESS == 0U) - uint32_t primask = __get_PRIMASK(); -#else - uint32_t n; -#endif - uint16_t max; - void *ret; - - max = osRtxInfo.isr_queue.max; - -#if (__EXCLUSIVE_ACCESS == 0U) - __disable_irq(); - - if (osRtxInfo.isr_queue.cnt != 0U) { - osRtxInfo.isr_queue.cnt--; - ret = osRtxInfo.isr_queue.data[osRtxInfo.isr_queue.out]; - if (++osRtxInfo.isr_queue.out == max) { - osRtxInfo.isr_queue.out = 0U; - } - } else { - ret = NULL; - } - - if (primask == 0U) { - __enable_irq(); - } -#else - if (atomic_dec16_nz(&osRtxInfo.isr_queue.cnt) != 0U) { - n = atomic_inc16_lim(&osRtxInfo.isr_queue.out, max); - ret = osRtxInfo.isr_queue.data[n]; - } else { - ret = NULL; - } -#endif - - return ret; -} - - -// ==== Library Functions ==== - -/// Tick Handler. -void osRtxTick_Handler (void) { - os_thread_t *thread; - - osRtxSysTimerAckIRQ(); - osRtxInfo.kernel.tick++; - - // Process Timers - if (osRtxInfo.timer.tick != NULL) { - osRtxInfo.timer.tick(); - } - - // Process Thread Delays - osRtxThreadDelayTick(); - - osRtxThreadDispatch(NULL); - - // Check Round Robin timeout - if (osRtxInfo.thread.robin.timeout != 0U) { - if (osRtxInfo.thread.robin.thread != osRtxInfo.thread.run.next) { - // Reset Round Robin - osRtxInfo.thread.robin.thread = osRtxInfo.thread.run.next; - osRtxInfo.thread.robin.tick = osRtxInfo.thread.robin.timeout; - } else { - if (osRtxInfo.thread.robin.tick != 0U) { - osRtxInfo.thread.robin.tick--; - } - if (osRtxInfo.thread.robin.tick == 0U) { - // Round Robin Timeout - if (osRtxKernelGetState() == osRtxKernelRunning) { - thread = osRtxInfo.thread.ready.thread_list; - if ((thread != NULL) && (thread->priority == osRtxInfo.thread.robin.thread->priority)) { - osRtxThreadListRemove(thread); - osRtxThreadReadyPut(osRtxInfo.thread.robin.thread); - osRtxThreadSwitch(thread); - osRtxInfo.thread.robin.thread = thread; - osRtxInfo.thread.robin.tick = osRtxInfo.thread.robin.timeout; - } - } - } - } - } -} - -/// Pending Service Call Handler. -void osRtxPendSV_Handler (void) { - os_object_t *object; - - for (;;) { - object = isr_queue_get(); - if (object == NULL) { - break; - } - switch (object->id) { - case osRtxIdThread: - osRtxInfo.post_process.thread((os_thread_t *)object); - break; - case osRtxIdEventFlags: - osRtxInfo.post_process.event_flags((os_event_flags_t *)object); - break; - case osRtxIdSemaphore: - osRtxInfo.post_process.semaphore((os_semaphore_t *)object); - break; - case osRtxIdMemoryPool: - osRtxInfo.post_process.memory_pool((os_memory_pool_t *)object); - break; - case osRtxIdMessage: - osRtxInfo.post_process.message_queue((os_message_t *)object); - break; - default: - break; - } - } - - osRtxThreadDispatch(NULL); -} - -/// Register post ISR processing. -/// \param[in] object generic object. -void osRtxPostProcess (os_object_t *object) { - - if (isr_queue_put(object) != 0U) { - if (osRtxInfo.kernel.blocked == 0U) { - SetPendSV(); - } else { - osRtxInfo.kernel.pendSV = 1U; - } - } else { - osRtxErrorNotify(osRtxErrorISRQueueOverflow, object); - } -} - - -// ==== Public API ==== - -/// Setup System Timer. -__WEAK int32_t osRtxSysTimerSetup (void) { - - // Setup SysTick Timer - SysTick_Setup(osRtxInfo.kernel.sys_freq / osRtxConfig.tick_freq); - - return SysTick_IRQn; // Return IRQ number of SysTick -} - -/// Enable System Timer. -__WEAK void osRtxSysTimerEnable (void) { - SysTick_Enable(); -} - -/// Disable System Timer. -__WEAK void osRtxSysTimerDisable (void) { - SysTick_Disable(); -} - -/// Acknowledge System Timer IRQ. -__WEAK void osRtxSysTimerAckIRQ (void) { - SysTick_GetOvf(); -} - -/// Get System Timer count. -__WEAK uint32_t osRtxSysTimerGetCount (void) { - uint32_t tick; - uint32_t val; - - tick = (uint32_t)osRtxInfo.kernel.tick; - val = SysTick_GetVal(); - if (SysTick_GetOvf()) { - val = SysTick_GetVal(); - tick++; - } - val += tick * SysTick_GetPeriod(); - - return val; -} - -/// Get System Timer frequency. -__WEAK uint32_t osRtxSysTimerGetFreq (void) { - return osRtxInfo.kernel.sys_freq; -} diff --git a/rtos/rtx5/TARGET_CORTEX_M/rtx_thread.c b/rtos/rtx5/TARGET_CORTEX_M/rtx_thread.c deleted file mode 100644 index aae22a0..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/rtx_thread.c +++ /dev/null @@ -1,1722 +0,0 @@ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ----------------------------------------------------------------------------- - * - * Project: CMSIS-RTOS RTX - * Title: Thread functions - * - * ----------------------------------------------------------------------------- - */ - -#include "rtx_lib.h" -#include "rt_OsEventObserver.h" - - -// ==== Helper functions ==== - -/// Set Thread Flags. -/// \param[in] thread thread object. -/// \param[in] flags specifies the flags to set. -/// \return thread flags after setting. -static uint32_t ThreadFlagsSet (os_thread_t *thread, uint32_t flags) { -#if (__EXCLUSIVE_ACCESS == 0U) - uint32_t primask = __get_PRIMASK(); -#endif - uint32_t thread_flags; - -#if (__EXCLUSIVE_ACCESS == 0U) - __disable_irq(); - - thread->thread_flags |= flags; - thread_flags = thread->thread_flags; - - if (primask == 0U) { - __enable_irq(); - } -#else - thread_flags = atomic_set32(&thread->thread_flags, flags); -#endif - - return thread_flags; -} - -/// Clear Thread Flags. -/// \param[in] thread thread object. -/// \param[in] flags specifies the flags to clear. -/// \return thread flags before clearing. -static uint32_t ThreadFlagsClear (os_thread_t *thread, uint32_t flags) { -#if (__EXCLUSIVE_ACCESS == 0U) - uint32_t primask = __get_PRIMASK(); -#endif - uint32_t thread_flags; - -#if (__EXCLUSIVE_ACCESS == 0U) - __disable_irq(); - - thread_flags = thread->thread_flags; - thread->thread_flags &= ~flags; - - if (primask == 0U) { - __enable_irq(); - } -#else - thread_flags = atomic_clr32(&thread->thread_flags, flags); -#endif - - return thread_flags; -} - -/// Check Thread Flags. -/// \param[in] thread thread object. -/// \param[in] flags specifies the flags to check. -/// \param[in] options specifies flags options (osFlagsXxxx). -/// \return thread flags before clearing or 0 if specified flags have not been set. -static uint32_t ThreadFlagsCheck (os_thread_t *thread, uint32_t flags, uint32_t options) { -#if (__EXCLUSIVE_ACCESS == 0U) - uint32_t primask; -#endif - uint32_t thread_flags; - - if ((options & osFlagsNoClear) == 0U) { -#if (__EXCLUSIVE_ACCESS == 0U) - primask = __get_PRIMASK(); - __disable_irq(); - - thread_flags = thread->thread_flags; - if ((((options & osFlagsWaitAll) != 0U) && ((thread_flags & flags) != flags)) || - (((options & osFlagsWaitAll) == 0U) && ((thread_flags & flags) == 0U))) { - thread_flags = 0U; - } else { - thread->thread_flags &= ~flags; - } - - if (primask == 0U) { - __enable_irq(); - } -#else - if ((options & osFlagsWaitAll) != 0U) { - thread_flags = atomic_chk32_all(&thread->thread_flags, flags); - } else { - thread_flags = atomic_chk32_any(&thread->thread_flags, flags); - } -#endif - } else { - thread_flags = thread->thread_flags; - if ((((options & osFlagsWaitAll) != 0U) && ((thread_flags & flags) != flags)) || - (((options & osFlagsWaitAll) == 0U) && ((thread_flags & flags) == 0U))) { - thread_flags = 0U; - } - } - - return thread_flags; -} - - -// ==== Library functions ==== - -/// Put a Thread into specified Object list sorted by Priority (Highest at Head). -/// \param[in] object generic object. -/// \param[in] thread thread object. -void osRtxThreadListPut (volatile os_object_t *object, os_thread_t *thread) { - os_thread_t *prev, *next; - int32_t priority; - - if (thread == NULL) { - return; - } - - priority = thread->priority; - - prev = (os_thread_t *)(uint32_t)object; - next = object->thread_list; - while ((next != NULL) && (next->priority >= priority)) { - prev = next; - next = next->thread_next; - } - thread->thread_prev = prev; - thread->thread_next = next; - prev->thread_next = thread; - if (next != NULL) { - next->thread_prev = thread; - } -} - -/// Get a Thread with Highest Priority from specified Object list and remove it. -/// \param[in] object generic object. -/// \return thread object. -os_thread_t *osRtxThreadListGet (volatile os_object_t *object) { - os_thread_t *thread; - - thread = object->thread_list; - if (thread != NULL) { - object->thread_list = thread->thread_next; - if (thread->thread_next != NULL) { - thread->thread_next->thread_prev = (os_thread_t *)(uint32_t)object; - } - thread->thread_prev = NULL; - } - - return thread; -} - -/// Retrieve Thread list root. -/// \param[in] thread thread object. -void *osRtxThreadListRoot (os_thread_t *thread) { - - while ((thread != NULL) && (thread->id == osRtxIdThread)) { - thread = thread->thread_prev; - } - return ((void *)thread); -} - -/// Re-sort a Thread in linked Object list by Priority (Highest at Head). -/// \param[in] thread thread object. -void osRtxThreadListSort (os_thread_t *thread) { - os_object_t *object; - os_thread_t *thread0; - - // Search for object - thread0 = thread; - while (thread0->id == osRtxIdThread) { - thread0 = thread0->thread_prev; - if (thread0 == NULL) { - return; - } - } - object = (os_object_t *)thread0; - - osRtxThreadListRemove(thread); - osRtxThreadListPut(object, thread); -} - -/// Remove a Thread from linked Object list. -/// \param[in] thread thread object. -void osRtxThreadListRemove (os_thread_t *thread) { - - if (thread->thread_prev != NULL) { - thread->thread_prev->thread_next = thread->thread_next; - if (thread->thread_next != NULL) { - thread->thread_next->thread_prev = thread->thread_prev; - } - thread->thread_prev = NULL; - } -} - -/// Unlink a Thread from specified linked list. -/// \param[in] thread thread object. -void osRtxThreadListUnlink (os_thread_t **thread_list, os_thread_t *thread) { - - if (thread->thread_next != NULL) { - thread->thread_next->thread_prev = thread->thread_prev; - } - if (thread->thread_prev != NULL) { - thread->thread_prev->thread_next = thread->thread_next; - thread->thread_prev = NULL; - } else { - *thread_list = thread->thread_next; - } -} - -/// Mark a Thread as Ready and put it into Ready list (sorted by Priority). -/// \param[in] thread thread object. -void osRtxThreadReadyPut (os_thread_t *thread) { - - thread->state = osRtxThreadReady; - osRtxThreadListPut(&osRtxInfo.thread.ready, thread); -} - -/// Insert a Thread into the Delay list sorted by Delay (Lowest at Head). -/// \param[in] thread thread object. -/// \param[in] delay delay value. -void osRtxThreadDelayInsert (os_thread_t *thread, uint32_t delay) { - os_thread_t *prev, *next; - - if (delay == osWaitForever) { - prev = NULL; - next = osRtxInfo.thread.wait_list; - while (next != NULL) { - prev = next; - next = next->delay_next; - } - thread->delay = delay; - thread->delay_prev = prev; - thread->delay_next = next; - if (prev != NULL) { - prev->delay_next = thread; - } else { - osRtxInfo.thread.wait_list = thread; - } - if (next != NULL) { - next->delay_prev = thread; - } - } else { - prev = NULL; - next = osRtxInfo.thread.delay_list; - while ((next != NULL) && (next->delay <= delay)) { - delay -= next->delay; - prev = next; - next = next->delay_next; - } - thread->delay = delay; - thread->delay_prev = prev; - thread->delay_next = next; - if (prev != NULL) { - prev->delay_next = thread; - } else { - osRtxInfo.thread.delay_list = thread; - } - if (next != NULL) { - next->delay -= delay; - next->delay_prev = thread; - } - } -} - -/// Remove a Thread from the Delay list. -/// \param[in] thread thread object. -void osRtxThreadDelayRemove (os_thread_t *thread) { - - if (thread->delay == osWaitForever) { - if ((thread->delay_prev == NULL) && (osRtxInfo.thread.wait_list != thread)) { - return; - } - if (thread->delay_next != NULL) { - thread->delay_next->delay_prev = thread->delay_prev; - } - if (thread->delay_prev != NULL) { - thread->delay_prev->delay_next = thread->delay_next; - thread->delay_prev = NULL; - } else { - osRtxInfo.thread.wait_list = thread->delay_next; - } - } else { - if ((thread->delay_prev == NULL) && (osRtxInfo.thread.delay_list != thread)) { - return; - } - if (thread->delay_next != NULL) { - thread->delay_next->delay += thread->delay; - thread->delay_next->delay_prev = thread->delay_prev; - } - if (thread->delay_prev != NULL) { - thread->delay_prev->delay_next = thread->delay_next; - thread->delay_prev = NULL; - } else { - osRtxInfo.thread.delay_list = thread->delay_next; - } - } -} - -/// Process Thread Delay Tick (executed each System Tick). -void osRtxThreadDelayTick (void) { - os_thread_t *thread; - - thread = osRtxInfo.thread.delay_list; - if (thread == NULL) { - return; - } - - thread->delay--; - - if (thread->delay == 0U) { - do { - switch (thread->state) { - case osRtxThreadWaitingDelay: - EvrRtxThreadDelayCompleted(); - break; - case osRtxThreadWaitingThreadFlags: - EvrRtxThreadFlagsWaitTimeout(); - break; - case osRtxThreadWaitingEventFlags: - EvrRtxEventFlagsWaitTimeout((osEventFlagsId_t)osRtxThreadListRoot(thread)); - break; - case osRtxThreadWaitingMutex: - EvrRtxMutexAcquireTimeout((osMutexId_t)osRtxThreadListRoot(thread)); - break; - case osRtxThreadWaitingSemaphore: - EvrRtxSemaphoreAcquireTimeout((osSemaphoreId_t)osRtxThreadListRoot(thread)); - break; - case osRtxThreadWaitingMemoryPool: - EvrRtxMemoryPoolAllocTimeout((osMemoryPoolId_t)osRtxThreadListRoot(thread)); - break; - case osRtxThreadWaitingMessageGet: - EvrRtxMessageQueueGetTimeout((osMessageQueueId_t)osRtxThreadListRoot(thread)); - break; - case osRtxThreadWaitingMessagePut: - EvrRtxMessageQueuePutTimeout((osMessageQueueId_t)osRtxThreadListRoot(thread)); - break; - default: - break; - } - EvrRtxThreadUnblocked(thread, (osRtxThreadRegPtr(thread))[0]); - osRtxThreadListRemove(thread); - osRtxThreadReadyPut(thread); - thread = thread->delay_next; - } while ((thread != NULL) && (thread->delay == 0U)); - if (thread != NULL) { - thread->delay_prev = NULL; - } - osRtxInfo.thread.delay_list = thread; - } -} - -/// Get pointer to Thread registers (R0..R3) -/// \param[in] thread thread object. -/// \return pointer to registers R0-R3. -uint32_t *osRtxThreadRegPtr (os_thread_t *thread) { - -#if (__FPU_USED == 1U) - if (IS_EXTENDED_STACK_FRAME(thread->stack_frame)) { - // Extended Stack Frame: S16-S31, R4-R11, R0-R3, R12, LR, PC, xPSR, S0-S15, FPSCR - return ((uint32_t *)(thread->sp + (16U+8U)*4U)); - } else { - // Basic Stack Frame: R4-R11, R0-R3, R12, LR, PC, xPSR - return ((uint32_t *)(thread->sp + 8U *4U)); - } -#else - // Stack Frame: R4-R11, R0-R3, R12, LR, PC, xPSR - return ((uint32_t *)(thread->sp + 8U*4U)); -#endif -} - -/// Block running Thread execution and register it as Ready to Run. -/// \param[in] thread running thread object. -void osRtxThreadBlock (os_thread_t *thread) { - os_thread_t *prev, *next; - int32_t priority; - - thread->state = osRtxThreadReady; - - priority = thread->priority; - - prev = (os_thread_t *)(uint32_t)&osRtxInfo.thread.ready; - next = prev->thread_next; - - while ((next != NULL) && (next->priority > priority)) { - prev = next; - next = next->thread_next; - } - thread->thread_prev = prev; - thread->thread_next = next; - prev->thread_next = thread; - if (next != NULL) { - next->thread_prev = thread; - } -} - -/// Switch to specified Thread. -/// \param[in] thread thread object. -void osRtxThreadSwitch (os_thread_t *thread) { - - thread->state = osRtxThreadRunning; - osRtxInfo.thread.run.next = thread; - osRtxThreadStackCheck(); - EvrRtxThreadSwitch(thread); -} - -/// Notify the OS event observer of an imminent thread switch. -void thread_switch_helper(void) { - if (osEventObs && osEventObs->thread_switch) { - osEventObs->thread_switch(osRtxInfo.thread.run.next->context); - } -} - -/// Dispatch specified Thread or Ready Thread with Highest Priority. -/// \param[in] thread thread object or NULL. -void osRtxThreadDispatch (os_thread_t *thread) { - uint8_t kernel_state; - os_thread_t *thread_running; - - kernel_state = osRtxKernelGetState(); - thread_running = osRtxThreadGetRunning(); - - if (thread == NULL) { - thread = osRtxInfo.thread.ready.thread_list; - if ((kernel_state == osRtxKernelRunning) && - (thread_running != NULL) && (thread != NULL) && - (thread->priority > thread_running->priority)) { - // Preempt running Thread - osRtxThreadListRemove(thread); - osRtxThreadBlock(thread_running); - osRtxThreadSwitch(thread); - } - } else { - if ((kernel_state == osRtxKernelRunning) && - (thread_running != NULL) && - (thread->priority > thread_running->priority)) { - // Preempt running Thread - osRtxThreadBlock(thread_running); - osRtxThreadSwitch(thread); - } else { - // Put Thread into Ready list - osRtxThreadReadyPut(thread); - } - } -} - -/// Exit Thread wait state. -/// \param[in] thread thread object. -/// \param[in] ret_val return value. -/// \param[in] dispatch dispatch flag. -void osRtxThreadWaitExit (os_thread_t *thread, uint32_t ret_val, bool dispatch) { - uint32_t *reg; - - EvrRtxThreadUnblocked(thread, ret_val); - - reg = osRtxThreadRegPtr(thread); - reg[0] = ret_val; - - osRtxThreadDelayRemove(thread); - if (dispatch) { - osRtxThreadDispatch(thread); - } else { - osRtxThreadReadyPut(thread); - } -} - -/// Enter Thread wait state. -/// \param[in] state new thread state. -/// \param[in] timeout timeout. -/// \return true - success, false - failure. -bool osRtxThreadWaitEnter (uint8_t state, uint32_t timeout) { - os_thread_t *thread; - - thread = osRtxThreadGetRunning(); - if (thread == NULL) { - return false; - } - - if (osRtxKernelGetState() != osRtxKernelRunning) { - osRtxThreadListRemove(thread); - return false; - } - - if (osRtxInfo.thread.ready.thread_list == NULL) { - return false; - } - - EvrRtxThreadBlocked(thread, timeout); - - thread->state = state; - osRtxThreadDelayInsert(thread, timeout); - thread = osRtxThreadListGet(&osRtxInfo.thread.ready); - osRtxThreadSwitch(thread); - - return true; -} - -/// Check current running Thread Stack. -__WEAK void osRtxThreadStackCheck (void) { - os_thread_t *thread; - - thread = osRtxThreadGetRunning(); - if (thread != NULL) { - if ((thread->sp <= (uint32_t)thread->stack_mem) || - (*((uint32_t *)thread->stack_mem) != osRtxStackMagicWord)) { - osRtxErrorNotify(osRtxErrorStackUnderflow, thread); - } - } -} - -/// Thread post ISR processing. -/// \param[in] thread thread object. -void osRtxThreadPostProcess (os_thread_t *thread) { - uint32_t thread_flags; - - if ((thread->state == osRtxThreadInactive) || - (thread->state == osRtxThreadTerminated)) { - return; - } - - // Check if Thread is waiting for Thread Flags - if (thread->state == osRtxThreadWaitingThreadFlags) { - thread_flags = ThreadFlagsCheck(thread, thread->wait_flags, thread->flags_options); - if (thread_flags != 0U) { - osRtxThreadWaitExit(thread, thread_flags, false); - EvrRtxThreadFlagsWaitCompleted(thread->wait_flags, thread->flags_options, thread_flags); - } - } -} - - -// ==== Service Calls ==== - -// Service Calls definitions -SVC0_4M(ThreadNew, osThreadId_t, osThreadFunc_t, void *, const osThreadAttr_t *, void *) -SVC0_1 (ThreadGetName, const char *, osThreadId_t) -SVC0_0 (ThreadGetId, osThreadId_t) -SVC0_1 (ThreadGetState, osThreadState_t, osThreadId_t) -SVC0_1 (ThreadGetStackSize, uint32_t, osThreadId_t) -SVC0_1 (ThreadGetStackSpace, uint32_t, osThreadId_t) -SVC0_2 (ThreadSetPriority, osStatus_t, osThreadId_t, osPriority_t) -SVC0_1 (ThreadGetPriority, osPriority_t, osThreadId_t) -SVC0_0 (ThreadYield, osStatus_t) -SVC0_1 (ThreadSuspend, osStatus_t, osThreadId_t) -SVC0_1 (ThreadResume, osStatus_t, osThreadId_t) -SVC0_1 (ThreadDetach, osStatus_t, osThreadId_t) -SVC0_1 (ThreadJoin, osStatus_t, osThreadId_t) -SVC0_0N(ThreadExit, void) -SVC0_1 (ThreadTerminate, osStatus_t, osThreadId_t) -SVC0_0 (ThreadGetCount, uint32_t) -SVC0_2 (ThreadEnumerate, uint32_t, osThreadId_t *, uint32_t) -SVC0_2 (ThreadFlagsSet, uint32_t, osThreadId_t, uint32_t) -SVC0_1 (ThreadFlagsClear, uint32_t, uint32_t) -SVC0_0 (ThreadFlagsGet, uint32_t) -SVC0_3 (ThreadFlagsWait, uint32_t, uint32_t, uint32_t, uint32_t) - -/// Create a thread and add it to Active Threads. -/// \note API identical to osThreadContextNew -osThreadId_t svcRtxThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr, void *context) { - os_thread_t *thread; - uint32_t attr_bits; - void *stack_mem; - uint32_t stack_size; - osPriority_t priority; - uint8_t flags; - const char *name; - uint32_t *ptr; - uint32_t n; -#if (__DOMAIN_NS == 1U) - TZ_ModuleId_t tz_module; - TZ_MemoryId_t tz_memory; -#endif - - // Check parameters - if (func == NULL) { - EvrRtxThreadError(NULL, osErrorParameter); - return NULL; - } - - // Process attributes - if (attr != NULL) { - name = attr->name; - attr_bits = attr->attr_bits; - thread = attr->cb_mem; - stack_mem = attr->stack_mem; - stack_size = attr->stack_size; - priority = attr->priority; -#if (__DOMAIN_NS == 1U) - tz_module = attr->tz_module; -#endif - if (thread != NULL) { - if (((uint32_t)thread & 3U) || (attr->cb_size < sizeof(os_thread_t))) { - EvrRtxThreadError(NULL, osRtxErrorInvalidControlBlock); - return NULL; - } - } else { - if (attr->cb_size != 0U) { - EvrRtxThreadError(NULL, osRtxErrorInvalidControlBlock); - return NULL; - } - } - if (stack_mem != NULL) { - if (((uint32_t)stack_mem & 7U) || (stack_size == 0U)) { - EvrRtxThreadError(NULL, osRtxErrorInvalidThreadStack); - return NULL; - } - } - if (priority == osPriorityNone) { - priority = osPriorityNormal; - } else { - if ((priority < osPriorityIdle) || (priority > osPriorityISR)) { - EvrRtxThreadError(NULL, osRtxErrorInvalidPriority); - return NULL; - } - } - } else { - name = NULL; - attr_bits = 0U; - thread = NULL; - stack_mem = NULL; - stack_size = 0U; - priority = osPriorityNormal; -#if (__DOMAIN_NS == 1U) - tz_module = 0U; -#endif - } - - // Check stack size - if ((stack_size != 0U) && ((stack_size & 7U) || (stack_size < (64U + 8U)))) { - EvrRtxThreadError(NULL, osRtxErrorInvalidThreadStack); - return NULL; - } - - // Allocate object memory if not provided - if (thread == NULL) { - if (osRtxInfo.mpi.thread != NULL) { - thread = osRtxMemoryPoolAlloc(osRtxInfo.mpi.thread); - } else { - thread = osRtxMemoryAlloc(osRtxInfo.mem.common, sizeof(os_thread_t), 1U); - } - if (thread == NULL) { - EvrRtxThreadError(NULL, osErrorNoMemory); - return NULL; - } - flags = osRtxFlagSystemObject; - } else { - flags = 0U; - } - - // Allocate stack memory if not provided - if (stack_mem == NULL) { - if (stack_size == 0U) { - stack_size = osRtxConfig.thread_stack_size; - if (osRtxInfo.mpi.stack != NULL) { - stack_mem = osRtxMemoryPoolAlloc(osRtxInfo.mpi.stack); - if (stack_mem != NULL) { - flags |= osRtxThreadFlagDefStack; - } - } else { - stack_mem = osRtxMemoryAlloc(osRtxInfo.mem.stack, stack_size, 0U); - } - } else { - stack_mem = osRtxMemoryAlloc(osRtxInfo.mem.stack, stack_size, 0U); - } - if (stack_mem == NULL) { - EvrRtxThreadError(NULL, osErrorNoMemory); - if (flags & osRtxFlagSystemObject) { - if (osRtxInfo.mpi.thread != NULL) { - osRtxMemoryPoolFree(osRtxInfo.mpi.thread, thread); - } else { - osRtxMemoryFree(osRtxInfo.mem.common, thread); - } - } - return NULL; - } - flags |= osRtxFlagSystemMemory; - } - -#if (__DOMAIN_NS == 1U) - // Allocate secure process stack - if (tz_module != 0U) { - tz_memory = TZ_AllocModuleContext_S(tz_module); - if (tz_memory == 0U) { - EvrRtxThreadError(NULL, osRtxErrorTZ_AllocContext_S); - if (flags & osRtxFlagSystemMemory) { - if (flags & osRtxThreadFlagDefStack) { - osRtxMemoryPoolFree(osRtxInfo.mpi.stack, thread->stack_mem); - } else { - osRtxMemoryFree(osRtxInfo.mem.stack, thread->stack_mem); - } - } - if (flags & osRtxFlagSystemObject) { - if (osRtxInfo.mpi.thread != NULL) { - osRtxMemoryPoolFree(osRtxInfo.mpi.thread, thread); - } else { - osRtxMemoryFree(osRtxInfo.mem.common, thread); - } - } - return NULL; - } - } else { - tz_memory = 0U; - } -#endif - - // Initialize control block - thread->id = osRtxIdThread; - thread->state = osRtxThreadReady; - thread->flags = flags; - thread->attr = (uint8_t)attr_bits; - thread->name = name; - thread->thread_next = NULL; - thread->thread_prev = NULL; - thread->delay_next = NULL; - thread->delay_prev = NULL; - thread->thread_join = NULL; - thread->delay = 0U; - thread->priority = (int8_t)priority; - thread->priority_base = (int8_t)priority; - thread->stack_frame = STACK_FRAME_INIT; - thread->flags_options = 0U; - thread->wait_flags = 0U; - thread->thread_flags = 0U; - thread->mutex_list = NULL; - thread->stack_mem = stack_mem; - thread->stack_size = stack_size; - thread->sp = (uint32_t)stack_mem + stack_size - 64U; - thread->thread_addr = (uint32_t)func; -#if (__DOMAIN_NS == 1U) - thread->tz_memory = tz_memory; -#endif - - // Initialize stack - ptr = (uint32_t *)stack_mem; - *ptr++ = osRtxStackMagicWord; - if (osRtxConfig.flags & osRtxConfigStackWatermark) { - for (n = (stack_size/4U) - (16U + 1U); n; n--) { - *ptr++ = osRtxStackFillPattern; - } - } else { - ptr = (uint32_t *)thread->sp; - } - for (n = 13U; n; n--) { - *ptr++ = 0U; // R4..R11, R0..R3, R12 - } - *ptr++ = (uint32_t)osThreadExit; // LR - *ptr++ = (uint32_t)func; // PC - *ptr++ = XPSR_INITIAL_VALUE; // xPSR - *(ptr-8) = (uint32_t)argument; // R0 - - // Register post ISR processing function - osRtxInfo.post_process.thread = osRtxThreadPostProcess; - - EvrRtxThreadCreated(thread); - - /* Notify the OS event observer of a new thread. */ - if (osEventObs && osEventObs->thread_create) { - thread->context = osEventObs->thread_create((int)thread, context); - } else { - thread->context = context; - } - - osRtxThreadDispatch(thread); - - return thread; -} - -/// Get name of a thread. -/// \note API identical to osThreadGetName -const char *svcRtxThreadGetName (osThreadId_t thread_id) { - os_thread_t *thread = (os_thread_t *)thread_id; - - // Check parameters - if ((thread == NULL) || (thread->id != osRtxIdThread)) { - EvrRtxThreadGetName(thread, NULL); - return NULL; - } - - // Check object state - if (thread->state == osRtxObjectInactive) { - EvrRtxThreadGetName(thread, NULL); - return NULL; - } - - EvrRtxThreadGetName(thread, thread->name); - - return thread->name; -} - -/// Return the thread ID of the current running thread. -/// \note API identical to osThreadGetId -osThreadId_t svcRtxThreadGetId (void) { - os_thread_t *thread; - - thread = osRtxThreadGetRunning(); - EvrRtxThreadGetId(thread); - return thread; -} - -/// Get current thread state of a thread. -/// \note API identical to osThreadGetState -osThreadState_t svcRtxThreadGetState (osThreadId_t thread_id) { - os_thread_t *thread = (os_thread_t *)thread_id; - - // Check parameters - if ((thread == NULL) || (thread->id != osRtxIdThread)) { - EvrRtxThreadGetState(thread, osThreadError); - return osThreadError; - } - - EvrRtxThreadGetState(thread, (osThreadState_t)(thread->state & osRtxThreadStateMask)); - - return ((osThreadState_t)(thread->state & osRtxThreadStateMask)); -} - -/// Get stack size of a thread. -/// \note API identical to osThreadGetStackSize -uint32_t svcRtxThreadGetStackSize (osThreadId_t thread_id) { - os_thread_t *thread = (os_thread_t *)thread_id; - - // Check parameters - if ((thread == NULL) || (thread->id != osRtxIdThread)) { - EvrRtxThreadGetStackSize(thread, 0U); - return 0U; - } - - // Check object state - if (thread->state == osRtxObjectInactive) { - EvrRtxThreadGetStackSize(thread, 0U); - return 0U; - } - - EvrRtxThreadGetStackSize(thread, thread->stack_size); - - return thread->stack_size; -} - -/// Get available stack space of a thread based on stack watermark recording during execution. -/// \note API identical to osThreadGetStackSpace -uint32_t svcRtxThreadGetStackSpace (osThreadId_t thread_id) { - os_thread_t *thread = (os_thread_t *)thread_id; - uint32_t *stack; - uint32_t space; - - // Check parameters - if ((thread == NULL) || (thread->id != osRtxIdThread)) { - EvrRtxThreadGetStackSpace(thread, 0U); - return 0U; - } - - // Check object state - if (thread->state == osRtxObjectInactive) { - EvrRtxThreadGetStackSpace(thread, 0U); - return 0U; - } - - if ((osRtxConfig.flags & osRtxConfigStackWatermark) == 0U) { - EvrRtxThreadGetStackSpace(thread, 0U); - return 0U; - } - - stack = thread->stack_mem; - if (*stack++ != osRtxStackMagicWord) { - EvrRtxThreadGetStackSpace(thread, 0U); - return 0U; - } - for (space = 4U; space < thread->stack_size; space += 4U) { - if (*stack++ != osRtxStackFillPattern) { - break; - } - } - - EvrRtxThreadGetStackSpace(thread, space); - - return space; -} - -/// Change priority of a thread. -/// \note API identical to osThreadSetPriority -osStatus_t svcRtxThreadSetPriority (osThreadId_t thread_id, osPriority_t priority) { - os_thread_t *thread = (os_thread_t *)thread_id; - - // Check parameters - if ((thread == NULL) || (thread->id != osRtxIdThread) || - (priority < osPriorityIdle) || (priority > osPriorityISR)) { - EvrRtxThreadError(thread, osErrorParameter); - return osErrorParameter; - } - - // Check object state - if ((thread->state == osRtxThreadInactive) || - (thread->state == osRtxThreadTerminated)) { - EvrRtxThreadError(thread, osErrorResource); - return osErrorResource; - } - - if (thread->priority != (int8_t)priority) { - thread->priority = (int8_t)priority; - thread->priority_base = (int8_t)priority; - osRtxThreadListSort(thread); - osRtxThreadDispatch(NULL); - } - - return osOK; -} - -/// Get current priority of a thread. -/// \note API identical to osThreadGetPriority -osPriority_t svcRtxThreadGetPriority (osThreadId_t thread_id) { - os_thread_t *thread = (os_thread_t *)thread_id; - - // Check parameters - if ((thread == NULL) || (thread->id != osRtxIdThread)) { - EvrRtxThreadGetPriority(thread, osPriorityError); - return osPriorityError; - } - - // Check object state - if ((thread->state == osRtxThreadInactive) || - (thread->state == osRtxThreadTerminated)) { - EvrRtxThreadGetPriority(thread, osPriorityError); - return osPriorityError; - } - - EvrRtxThreadGetPriority(thread, (osPriority_t)thread->priority); - - return ((osPriority_t)thread->priority); -} - -/// Pass control to next thread that is in state READY. -/// \note API identical to osThreadYield -osStatus_t svcRtxThreadYield (void) { - uint8_t kernel_state; - os_thread_t *thread_running; - os_thread_t *thread_ready; - - kernel_state = osRtxKernelGetState(); - thread_running = osRtxThreadGetRunning(); - thread_ready = osRtxInfo.thread.ready.thread_list; - if ((kernel_state == osRtxKernelRunning) && - (thread_ready != NULL) && (thread_running != NULL) && - (thread_ready->priority == thread_running->priority)) { - osRtxThreadListRemove(thread_ready); - osRtxThreadReadyPut(thread_running); - osRtxThreadSwitch(thread_ready); - } - - return osOK; -} - -/// Suspend execution of a thread. -/// \note API identical to osThreadSuspend -osStatus_t svcRtxThreadSuspend (osThreadId_t thread_id) { - os_thread_t *thread = (os_thread_t *)thread_id; - - // Check parameters - if ((thread == NULL) || (thread->id != osRtxIdThread)) { - EvrRtxThreadError(thread, osErrorParameter); - return osErrorParameter; - } - - // Check object state - switch (thread->state & osRtxThreadStateMask) { - case osRtxThreadRunning: - if ((osRtxKernelGetState() != osRtxKernelRunning) || - (osRtxInfo.thread.ready.thread_list == NULL)) { - EvrRtxThreadError(thread, osErrorResource); - return osErrorResource; - } - break; - case osRtxThreadReady: - osRtxThreadListRemove(thread); - break; - case osRtxThreadBlocked: - osRtxThreadListRemove(thread); - osRtxThreadDelayRemove(thread); - break; - case osRtxThreadInactive: - case osRtxThreadTerminated: - default: - EvrRtxThreadError(thread, osErrorResource); - return osErrorResource; - } - - EvrRtxThreadSuspended(thread); - - if (thread->state == osRtxThreadRunning) { - osRtxThreadSwitch(osRtxThreadListGet(&osRtxInfo.thread.ready)); - } - - // Update Thread State and put it into Delay list - thread->state = osRtxThreadBlocked; - thread->thread_prev = NULL; - thread->thread_next = NULL; - osRtxThreadDelayInsert(thread, osWaitForever); - - return osOK; -} - -/// Resume execution of a thread. -/// \note API identical to osThreadResume -osStatus_t svcRtxThreadResume (osThreadId_t thread_id) { - os_thread_t *thread = (os_thread_t *)thread_id; - - // Check parameters - if ((thread == NULL) || (thread->id != osRtxIdThread)) { - EvrRtxThreadError(thread, osErrorParameter); - return osErrorParameter; - } - - // Check object state - if ((thread->state & osRtxThreadStateMask) != osRtxThreadBlocked) { - EvrRtxThreadError(thread, osErrorResource); - return osErrorResource; - } - - EvrRtxThreadResumed(thread); - - // Wakeup Thread - osRtxThreadListRemove(thread); - osRtxThreadDelayRemove(thread); - osRtxThreadDispatch(thread); - - return osOK; -} - -/// Free Thread resources. -/// \param[in] thread thread object. -static void osRtxThreadFree (os_thread_t *thread) { - - // Mark object as inactive - thread->state = osRtxThreadInactive; - -#if (__DOMAIN_NS == 1U) - // Free secure process stack - if (thread->tz_memory != 0U) { - TZ_FreeModuleContext_S(thread->tz_memory); - } -#endif - - // Free stack memory - if (thread->flags & osRtxFlagSystemMemory) { - if (thread->flags & osRtxThreadFlagDefStack) { - osRtxMemoryPoolFree(osRtxInfo.mpi.stack, thread->stack_mem); - } else { - osRtxMemoryFree(osRtxInfo.mem.stack, thread->stack_mem); - } - } - - // Free object memory - if (thread->flags & osRtxFlagSystemObject) { - if (osRtxInfo.mpi.thread != NULL) { - osRtxMemoryPoolFree(osRtxInfo.mpi.thread, thread); - } else { - osRtxMemoryFree(osRtxInfo.mem.common, thread); - } - } -} - -/// Detach a thread (thread storage can be reclaimed when thread terminates). -/// \note API identical to osThreadDetach -osStatus_t svcRtxThreadDetach (osThreadId_t thread_id) { - os_thread_t *thread = (os_thread_t *)thread_id; - - // Check parameters - if ((thread == NULL) || (thread->id != osRtxIdThread)) { - EvrRtxThreadError(thread, osErrorParameter); - return osErrorParameter; - } - - // Check object attributes - if ((thread->attr & osThreadJoinable) == 0U) { - EvrRtxThreadError(thread, osRtxErrorThreadNotJoinable); - return osErrorResource; - } - - // Check object state - if (thread->state == osRtxThreadInactive) { - EvrRtxThreadError(thread, osErrorResource); - return osErrorResource; - } - - if (thread->state == osRtxThreadTerminated) { - osRtxThreadListUnlink(&osRtxInfo.thread.terminate_list, thread); - osRtxThreadFree(thread); - } else { - thread->attr &= ~osThreadJoinable; - } - - EvrRtxThreadDetached(thread); - - return osOK; -} - -/// Wait for specified thread to terminate. -/// \note API identical to osThreadJoin -osStatus_t svcRtxThreadJoin (osThreadId_t thread_id) { - os_thread_t *thread = (os_thread_t *)thread_id; - - // Check parameters - if ((thread == NULL) || (thread->id != osRtxIdThread)) { - EvrRtxThreadError(thread, osErrorParameter); - return osErrorParameter; - } - - // Check object attributes - if ((thread->attr & osThreadJoinable) == 0U) { - EvrRtxThreadError(thread, osRtxErrorThreadNotJoinable); - return osErrorResource; - } - - // Check object state - if ((thread->state == osRtxThreadInactive) || - (thread->state == osRtxThreadRunning)) { - EvrRtxThreadError(thread, osErrorResource); - return osErrorResource; - } - - if (thread->state == osRtxThreadTerminated) { - osRtxThreadListUnlink(&osRtxInfo.thread.terminate_list, thread); - osRtxThreadFree(thread); - } else { - EvrRtxThreadJoinPending(thread); - // Suspend current Thread - if (osRtxThreadWaitEnter(osRtxThreadWaitingJoin, osWaitForever)) { - thread->thread_join = osRtxThreadGetRunning(); - } - return osErrorResource; - } - - EvrRtxThreadJoined(thread); - - return osOK; -} - -/// Terminate execution of current running thread. -/// \note API identical to osThreadExit -void svcRtxThreadExit (void) { - os_thread_t *thread; - - thread = osRtxThreadGetRunning(); - if (thread == NULL) { - return; - } - - // Release owned Mutexes - osRtxMutexOwnerRelease(thread->mutex_list); - - // Wakeup Thread waiting to Join - if (thread->thread_join != NULL) { - osRtxThreadWaitExit(thread->thread_join, (uint32_t)osOK, false); - EvrRtxThreadJoined(thread->thread_join); - } - - // Switch to next Ready Thread - if ((osRtxKernelGetState() != osRtxKernelRunning) || - (osRtxInfo.thread.ready.thread_list == NULL)) { - return; - } - thread->sp = __get_PSP(); - osRtxThreadSwitch(osRtxThreadListGet(&osRtxInfo.thread.ready)); - osRtxThreadSetRunning(NULL); - - if (((thread->attr & osThreadJoinable) == 0U) || (thread->thread_join != NULL)) { - osRtxThreadFree(thread); - } else { - // Update Thread State and put it into Terminate Thread list - thread->state = osRtxThreadTerminated; - thread->thread_prev = NULL; - thread->thread_next = osRtxInfo.thread.terminate_list; - if (osRtxInfo.thread.terminate_list != NULL) { - osRtxInfo.thread.terminate_list->thread_prev = thread; - } - osRtxInfo.thread.terminate_list = thread; - } - - EvrRtxThreadDestroyed(thread); -} - -/// Terminate execution of a thread. -/// \note API identical to osThreadTerminate -osStatus_t svcRtxThreadTerminate (osThreadId_t thread_id) { - os_thread_t *thread = (os_thread_t *)thread_id; - - // Check parameters - if ((thread == NULL) || (thread->id != osRtxIdThread)) { - EvrRtxThreadError(thread, osErrorParameter); - return osErrorParameter; - } - - // Check object state - switch (thread->state & osRtxThreadStateMask) { - case osRtxThreadRunning: - break; - case osRtxThreadReady: - osRtxThreadListRemove(thread); - break; - case osRtxThreadBlocked: - osRtxThreadListRemove(thread); - osRtxThreadDelayRemove(thread); - break; - case osRtxThreadInactive: - case osRtxThreadTerminated: - default: - EvrRtxThreadError(thread, osErrorResource); - return osErrorResource; - } - - if (osEventObs && osEventObs->thread_destroy) { - osEventObs->thread_destroy(thread->context); - } - - // Release owned Mutexes - osRtxMutexOwnerRelease(thread->mutex_list); - - // Wakeup Thread waiting to Join - if (thread->thread_join != NULL) { - osRtxThreadWaitExit(thread->thread_join, (uint32_t)osOK, false); - EvrRtxThreadJoined(thread->thread_join); - } - - // Switch to next Ready Thread when terminating running Thread - if (thread->state == osRtxThreadRunning) { - if ((osRtxKernelGetState() != osRtxKernelRunning) || - (osRtxInfo.thread.ready.thread_list == NULL)) { - EvrRtxThreadError(thread, osErrorResource); - return osErrorResource; - } - thread->sp = __get_PSP(); - osRtxThreadSwitch(osRtxThreadListGet(&osRtxInfo.thread.ready)); - osRtxThreadSetRunning(NULL); - } else { - osRtxThreadDispatch(NULL); - } - - if (((thread->attr & osThreadJoinable) == 0U) || (thread->thread_join != NULL)) { - osRtxThreadFree(thread); - } else { - // Update Thread State and put it into Terminate Thread list - thread->state = osRtxThreadTerminated; - thread->thread_prev = NULL; - thread->thread_next = osRtxInfo.thread.terminate_list; - if (osRtxInfo.thread.terminate_list != NULL) { - osRtxInfo.thread.terminate_list->thread_prev = thread; - } - osRtxInfo.thread.terminate_list = thread; - } - - EvrRtxThreadDestroyed(thread); - - return osOK; -} - -/// Get number of active threads. -/// \note API identical to osThreadGetCount -uint32_t svcRtxThreadGetCount (void) { - os_thread_t *thread; - uint32_t count; - - // Running Thread - count = 1U; - - // Ready List - for (thread = osRtxInfo.thread.ready.thread_list; - (thread != NULL); thread = thread->thread_next, count++) {}; - - // Delay List - for (thread = osRtxInfo.thread.delay_list; - (thread != NULL); thread = thread->delay_next, count++) {}; - - // Wait List - for (thread = osRtxInfo.thread.wait_list; - (thread != NULL); thread = thread->delay_next, count++) {}; - - EvrRtxThreadGetCount(count); - - return count; -} - -/// Enumerate active threads. -/// \note API identical to osThreadEnumerate -uint32_t svcRtxThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items) { - os_thread_t *thread; - uint32_t count; - - // Check parameters - if ((thread_array == NULL) || (array_items == 0U)) { - EvrRtxThreadEnumerate(thread_array, array_items, 0U); - return 0U; - } - - // Running Thread - *thread_array++ = osRtxThreadGetRunning(); - count = 1U; - - // Ready List - for (thread = osRtxInfo.thread.ready.thread_list; - (thread != NULL) && (count < array_items); thread = thread->thread_next, count++) { - *thread_array++ = thread; - } - - // Delay List - for (thread = osRtxInfo.thread.delay_list; - (thread != NULL) && (count < array_items); thread = thread->delay_next, count++) { - *thread_array++ = thread; - } - - // Wait List - for (thread = osRtxInfo.thread.wait_list; - (thread != NULL) && (count < array_items); thread = thread->delay_next, count++) { - *thread_array++ = thread; - } - - EvrRtxThreadEnumerate(thread_array - count, array_items, count); - - return count; -} - -/// Set the specified Thread Flags of a thread. -/// \note API identical to osThreadFlagsSet -uint32_t svcRtxThreadFlagsSet (osThreadId_t thread_id, uint32_t flags) { - os_thread_t *thread = (os_thread_t *)thread_id; - uint32_t thread_flags; - uint32_t thread_flags0; - - // Check parameters - if ((thread == NULL) || (thread->id != osRtxIdThread) || - (flags & ~((1U << osRtxThreadFlagsLimit) - 1U))) { - EvrRtxThreadError(thread, osErrorParameter); - return ((uint32_t)osErrorParameter); - } - - // Check object state - if ((thread->state == osRtxThreadInactive) || - (thread->state == osRtxThreadTerminated)) { - EvrRtxThreadError(thread, osErrorResource); - return ((uint32_t)osErrorResource); - } - - // Set Thread Flags - thread_flags = ThreadFlagsSet(thread, flags); - - // Check if Thread is waiting for Thread Flags - if (thread->state == osRtxThreadWaitingThreadFlags) { - thread_flags0 = ThreadFlagsCheck(thread, thread->wait_flags, thread->flags_options); - if (thread_flags0 != 0U) { - if ((thread->flags_options & osFlagsNoClear) == 0U) { - thread_flags = thread_flags0 & ~thread->wait_flags; - } else { - thread_flags = thread_flags0; - } - osRtxThreadWaitExit(thread, thread_flags0, true); - EvrRtxThreadFlagsWaitCompleted(thread->wait_flags, thread->flags_options, thread_flags0); - } - } - - EvrRtxThreadFlagsSetDone(thread, thread_flags); - - return thread_flags; -} - -/// Clear the specified Thread Flags of current running thread. -/// \note API identical to osThreadFlagsClear -uint32_t svcRtxThreadFlagsClear (uint32_t flags) { - os_thread_t *thread; - uint32_t thread_flags; - - thread = osRtxThreadGetRunning(); - if (thread == NULL) { - EvrRtxThreadError(NULL, osRtxErrorKernelNotRunning); - return ((uint32_t)osError); - } - - // Check parameters - if (flags & ~((1U << osRtxThreadFlagsLimit) - 1U)) { - EvrRtxThreadError(thread, osErrorParameter); - return ((uint32_t)osErrorParameter); - } - - // Check object state - if ((thread->state == osRtxThreadInactive) || - (thread->state == osRtxThreadTerminated)) { - EvrRtxThreadError(thread, osErrorResource); - return ((uint32_t)osErrorResource); - } - - // Clear Thread Flags - thread_flags = ThreadFlagsClear(thread, flags); - - EvrRtxThreadFlagsClearDone(thread_flags); - - return thread_flags; -} - -/// Get the current Thread Flags of current running thread. -/// \note API identical to osThreadFlagsGet -uint32_t svcRtxThreadFlagsGet (void) { - os_thread_t *thread; - - thread = osRtxThreadGetRunning(); - if (thread == NULL) { - EvrRtxThreadFlagsGet(0U); - return 0U; - } - - // Check object state - if ((thread->state == osRtxThreadInactive) || - (thread->state == osRtxThreadTerminated)) { - EvrRtxThreadFlagsGet(0U); - return 0U; - } - - EvrRtxThreadFlagsGet(thread->thread_flags); - - return thread->thread_flags; -} - -/// Wait for one or more Thread Flags of the current running thread to become signaled. -/// \note API identical to osThreadFlagsWait -uint32_t svcRtxThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout) { - os_thread_t *thread; - uint32_t thread_flags; - - thread = osRtxThreadGetRunning(); - if (thread == NULL) { - EvrRtxThreadError(NULL, osRtxErrorKernelNotRunning); - return ((uint32_t)osError); - } - - // Check parameters - if (flags & ~((1U << osRtxThreadFlagsLimit) - 1U)) { - EvrRtxThreadError(thread, osErrorParameter); - return ((uint32_t)osErrorParameter); - } - - // Check Thread Flags - thread_flags = ThreadFlagsCheck(thread, flags, options); - if (thread_flags != 0U) { - EvrRtxThreadFlagsWaitCompleted(flags, options, thread_flags); - return thread_flags; - } - - // Check if timeout is specified - if (timeout != 0U) { - // Store waiting flags and options - EvrRtxThreadFlagsWaitPending(flags, options, timeout); - thread->wait_flags = flags; - thread->flags_options = (uint8_t)options; - // Suspend current Thread - osRtxThreadWaitEnter(osRtxThreadWaitingThreadFlags, timeout); - return ((uint32_t)osErrorTimeout); - } - - EvrRtxThreadFlagsWaitNotCompleted(flags, options); - - return ((uint32_t)osErrorResource); -} - - -// ==== ISR Calls ==== - -/// Set the specified Thread Flags of a thread. -/// \note API identical to osThreadFlagsSet -__STATIC_INLINE -uint32_t isrRtxThreadFlagsSet (osThreadId_t thread_id, uint32_t flags) { - os_thread_t *thread = (os_thread_t *)thread_id; - uint32_t thread_flags; - - // Check parameters - if ((thread == NULL) || (thread->id != osRtxIdThread) || - (flags & ~((1U << osRtxThreadFlagsLimit) - 1U))) { - EvrRtxThreadError(thread, osErrorParameter); - return ((uint32_t)osErrorParameter); - } - - // Check object state - if ((thread->state == osRtxThreadInactive) || - (thread->state == osRtxThreadTerminated)) { - EvrRtxThreadError(thread, osErrorResource); - return ((uint32_t)osErrorResource); - } - - // Set Thread Flags - thread_flags = ThreadFlagsSet(thread, flags); - - // Register post ISR processing - osRtxPostProcess((os_object_t *)thread); - - EvrRtxThreadFlagsSetDone(thread, thread_flags); - - return thread_flags; -} - - -// ==== Public API ==== - -/// Create a thread and add it to Active Threads. -osThreadId_t osThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr) { - return osThreadContextNew(func, argument, attr, NULL); -} - -osThreadId_t osThreadContextNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr, void *context) { - EvrRtxThreadNew(func, argument, attr); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxThreadError(NULL, osErrorISR); - return NULL; - } - return __svcThreadNew(func, argument, attr, context); -} - -/// Get name of a thread. -const char *osThreadGetName (osThreadId_t thread_id) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxThreadGetName(thread_id, NULL); - return NULL; - } - return __svcThreadGetName(thread_id); -} - -/// Return the thread ID of the current running thread. -osThreadId_t osThreadGetId (void) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxThreadGetId(NULL); - return NULL; - } - return __svcThreadGetId(); -} - -/// Get current thread state of a thread. -osThreadState_t osThreadGetState (osThreadId_t thread_id) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxThreadGetState(thread_id, osThreadError); - return osThreadError; - } - return __svcThreadGetState(thread_id); -} - -/// Get stack size of a thread. -uint32_t osThreadGetStackSize (osThreadId_t thread_id) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxThreadGetStackSize(thread_id, 0U); - return 0U; - } - return __svcThreadGetStackSize(thread_id); -} - -/// Get available stack space of a thread based on stack watermark recording during execution. -uint32_t osThreadGetStackSpace (osThreadId_t thread_id) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxThreadGetStackSpace(thread_id, 0U); - return 0U; - } - return __svcThreadGetStackSpace(thread_id); -} - -/// Change priority of a thread. -osStatus_t osThreadSetPriority (osThreadId_t thread_id, osPriority_t priority) { - EvrRtxThreadSetPriority(thread_id, priority); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxThreadError(thread_id, osErrorISR); - return osErrorISR; - } - return __svcThreadSetPriority(thread_id, priority); -} - -/// Get current priority of a thread. -osPriority_t osThreadGetPriority (osThreadId_t thread_id) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxThreadGetPriority(thread_id, osPriorityError); - return osPriorityError; - } - return __svcThreadGetPriority(thread_id); -} - -/// Pass control to next thread that is in state READY. -osStatus_t osThreadYield (void) { - EvrRtxThreadYield(); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxThreadError(NULL, osErrorISR); - return osErrorISR; - } - return __svcThreadYield(); -} - -/// Suspend execution of a thread. -osStatus_t osThreadSuspend (osThreadId_t thread_id) { - EvrRtxThreadSuspend(thread_id); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxThreadError(thread_id, osErrorISR); - return osErrorISR; - } - return __svcThreadSuspend(thread_id); -} - -/// Resume execution of a thread. -osStatus_t osThreadResume (osThreadId_t thread_id) { - EvrRtxThreadResume(thread_id); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxThreadError(thread_id, osErrorISR); - return osErrorISR; - } - return __svcThreadResume(thread_id); -} - -/// Detach a thread (thread storage can be reclaimed when thread terminates). -osStatus_t osThreadDetach (osThreadId_t thread_id) { - EvrRtxThreadDetach(thread_id); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxThreadError(thread_id, osErrorISR); - return osErrorISR; - } - return __svcThreadDetach(thread_id); -} - -/// Wait for specified thread to terminate. -osStatus_t osThreadJoin (osThreadId_t thread_id) { - EvrRtxThreadJoin(thread_id); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxThreadError(thread_id, osErrorISR); - return osErrorISR; - } - return __svcThreadJoin(thread_id); -} - -/// Terminate execution of current running thread. -__NO_RETURN void osThreadExit (void) { - EvrRtxThreadExit(); - __svcThreadExit(); - EvrRtxThreadError(NULL, osError); - for (;;); -} - -/// Terminate execution of a thread. -osStatus_t osThreadTerminate (osThreadId_t thread_id) { - EvrRtxThreadTerminate(thread_id); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxThreadError(thread_id, osErrorISR); - return osErrorISR; - } - return __svcThreadTerminate(thread_id); -} - -/// Get number of active threads. -uint32_t osThreadGetCount (void) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxThreadGetCount(0U); - return 0U; - } - return __svcThreadGetCount(); -} - -/// Enumerate active threads. -uint32_t osThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxThreadEnumerate(thread_array, array_items, 0U); - return 0U; - } - return __svcThreadEnumerate(thread_array, array_items); -} - -/// Set the specified Thread Flags of a thread. -uint32_t osThreadFlagsSet (osThreadId_t thread_id, uint32_t flags) { - EvrRtxThreadFlagsSet(thread_id, flags); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - return isrRtxThreadFlagsSet(thread_id, flags); - } else { - return __svcThreadFlagsSet(thread_id, flags); - } -} - -/// Clear the specified Thread Flags of current running thread. -uint32_t osThreadFlagsClear (uint32_t flags) { - EvrRtxThreadFlagsClear(flags); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxThreadError(NULL, osErrorISR); - return ((uint32_t)osErrorISR); - } - return __svcThreadFlagsClear(flags); -} - -/// Get the current Thread Flags of current running thread. -uint32_t osThreadFlagsGet (void) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxThreadFlagsGet(0U); - return 0U; - } - return __svcThreadFlagsGet(); -} - -/// Wait for one or more Thread Flags of the current running thread to become signaled. -uint32_t osThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout) { - EvrRtxThreadFlagsWait(flags, options, timeout); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxThreadError(NULL, osErrorISR); - return ((uint32_t)osErrorISR); - } - return __svcThreadFlagsWait(flags, options, timeout); -} diff --git a/rtos/rtx5/TARGET_CORTEX_M/rtx_timer.c b/rtos/rtx5/TARGET_CORTEX_M/rtx_timer.c deleted file mode 100644 index 90bd795..0000000 --- a/rtos/rtx5/TARGET_CORTEX_M/rtx_timer.c +++ /dev/null @@ -1,415 +0,0 @@ -/* - * Copyright (c) 2013-2017 ARM Limited. All rights reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - * Licensed under the Apache License, Version 2.0 (the License); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ----------------------------------------------------------------------------- - * - * Project: CMSIS-RTOS RTX - * Title: Timer functions - * - * ----------------------------------------------------------------------------- - */ - -#include "rtx_lib.h" - - -// ==== Helper functions ==== - -/// Insert Timer into the Timer List sorted by Time. -/// \param[in] timer timer object. -/// \param[in] tick timer tick. -static void TimerInsert (os_timer_t *timer, uint32_t tick) { - os_timer_t *prev, *next; - - prev = NULL; - next = osRtxInfo.timer.list; - while ((next != NULL) && (next->tick <= tick)) { - tick -= next->tick; - prev = next; - next = next->next; - } - timer->tick = tick; - timer->prev = prev; - timer->next = next; - if (next != NULL) { - next->tick -= timer->tick; - next->prev = timer; - } - if (prev != NULL) { - prev->next = timer; - } else { - osRtxInfo.timer.list = timer; - } -} - -/// Remove Timer from the Timer List. -/// \param[in] timer timer object. -static void TimerRemove (os_timer_t *timer) { - - if (timer->next != NULL) { - timer->next->tick += timer->tick; - timer->next->prev = timer->prev; - } - if (timer->prev != NULL) { - timer->prev->next = timer->next; - } else { - osRtxInfo.timer.list = timer->next; - } -} - -/// Unlink Timer from the Timer List Head. -/// \param[in] timer timer object. -static void TimerUnlink (os_timer_t *timer) { - - if (timer->next != NULL) { - timer->next->prev = timer->prev; - } - osRtxInfo.timer.list = timer->next; -} - - -// ==== Library functions ==== - -/// Timer Tick (called each SysTick). -void osRtxTimerTick (void) { - os_timer_t *timer; - osStatus_t status; - - timer = osRtxInfo.timer.list; - if (timer == NULL) { - return; - } - - timer->tick--; - while ((timer != NULL) && (timer->tick == 0U)) { - TimerUnlink(timer); - status = osMessageQueuePut(osRtxInfo.timer.mq, &timer->finfo, 0U, 0U); - if (status != osOK) { - osRtxErrorNotify(osRtxErrorTimerQueueOverflow, timer); - } - if (timer->type == osRtxTimerPeriodic) { - TimerInsert(timer, timer->load); - } else { - timer->state = osRtxTimerStopped; - } - timer = osRtxInfo.timer.list; - } -} - -/// Timer Thread -__WEAK void osRtxTimerThread (void *argument) { - os_timer_finfo_t finfo; - osStatus_t status; - (void) argument; - - osRtxInfo.timer.mq = osMessageQueueNew(osRtxConfig.timer_mq_mcnt, sizeof(os_timer_finfo_t), osRtxConfig.timer_mq_attr); - if (osRtxInfo.timer.mq == NULL) { - return; - } - osRtxInfo.timer.tick = osRtxTimerTick; - for (;;) { - status = osMessageQueueGet(osRtxInfo.timer.mq, &finfo, NULL, osWaitForever); - if (status == osOK) { - EvrRtxTimerCallback(*(osTimerFunc_t)finfo.fp, finfo.arg); - (*(osTimerFunc_t)finfo.fp)(finfo.arg); - } - } -} - -// ==== Service Calls ==== - -// Service Calls definitions -SVC0_4M(TimerNew, osTimerId_t, osTimerFunc_t, osTimerType_t, void *, const osTimerAttr_t *) -SVC0_1 (TimerGetName, const char *, osTimerId_t) -SVC0_2 (TimerStart, osStatus_t, osTimerId_t, uint32_t) -SVC0_1 (TimerStop, osStatus_t, osTimerId_t) -SVC0_1 (TimerIsRunning, uint32_t, osTimerId_t) -SVC0_1 (TimerDelete, osStatus_t, osTimerId_t) - -/// Create and Initialize a timer. -/// \note API identical to osTimerNew -osTimerId_t svcRtxTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr) { - os_timer_t *timer; - uint8_t flags; - const char *name; - - // Check parameters - if ((func == NULL) || ((type != osTimerOnce) && (type != osTimerPeriodic))) { - EvrRtxTimerError(NULL, osErrorParameter); - return NULL; - } - - // Process attributes - if (attr != NULL) { - name = attr->name; - timer = attr->cb_mem; - if (timer != NULL) { - if (((uint32_t)timer & 3U) || (attr->cb_size < sizeof(os_timer_t))) { - EvrRtxTimerError(NULL, osRtxErrorInvalidControlBlock); - return NULL; - } - } else { - if (attr->cb_size != 0U) { - EvrRtxTimerError(NULL, osRtxErrorInvalidControlBlock); - return NULL; - } - } - } else { - name = NULL; - timer = NULL; - } - - // Allocate object memory if not provided - if (timer == NULL) { - if (osRtxInfo.mpi.timer != NULL) { - timer = osRtxMemoryPoolAlloc(osRtxInfo.mpi.timer); - } else { - timer = osRtxMemoryAlloc(osRtxInfo.mem.common, sizeof(os_timer_t), 1U); - } - if (timer == NULL) { - EvrRtxTimerError(NULL, osErrorNoMemory); - return NULL; - } - flags = osRtxFlagSystemObject; - } else { - flags = 0U; - } - - // Initialize control block - timer->id = osRtxIdTimer; - timer->state = osRtxTimerStopped; - timer->flags = flags; - timer->type = (uint8_t)type; - timer->name = name; - timer->prev = NULL; - timer->next = NULL; - timer->tick = 0U; - timer->load = 0U; - timer->finfo.fp = (void *)func; - timer->finfo.arg = argument; - - EvrRtxTimerCreated(timer); - - return timer; -} - -/// Get name of a timer. -/// \note API identical to osTimerGetName -const char *svcRtxTimerGetName (osTimerId_t timer_id) { - os_timer_t *timer = (os_timer_t *)timer_id; - - // Check parameters - if ((timer == NULL) || (timer->id != osRtxIdTimer)) { - EvrRtxTimerGetName(timer, NULL); - return NULL; - } - - // Check object state - if (timer->state == osRtxObjectInactive) { - EvrRtxTimerGetName(timer, NULL); - return NULL; - } - - EvrRtxTimerGetName(timer, timer->name); - - return timer->name; -} - -/// Start or restart a timer. -/// \note API identical to osTimerStart -osStatus_t svcRtxTimerStart (osTimerId_t timer_id, uint32_t ticks) { - os_timer_t *timer = (os_timer_t *)timer_id; - - // Check parameters - if ((timer == NULL) || (timer->id != osRtxIdTimer) || (ticks == 0U)) { - EvrRtxTimerError(timer, osErrorParameter); - return osErrorParameter; - } - - // Check object state - switch (timer->state) { - case osRtxTimerStopped: - if (osRtxInfo.timer.tick == NULL) { - EvrRtxTimerError(timer, osErrorResource); - return osErrorResource; - } - timer->state = osRtxTimerRunning; - timer->load = ticks; - break; - case osRtxTimerRunning: - TimerRemove(timer); - break; - case osRtxTimerInactive: - default: - EvrRtxTimerError(timer, osErrorResource); - return osErrorResource; - } - - TimerInsert(timer, ticks); - - EvrRtxTimerStarted(timer); - - return osOK; -} - -/// Stop a timer. -/// \note API identical to osTimerStop -osStatus_t svcRtxTimerStop (osTimerId_t timer_id) { - os_timer_t *timer = (os_timer_t *)timer_id; - - // Check parameters - if ((timer == NULL) || (timer->id != osRtxIdTimer)) { - EvrRtxTimerError(timer, osErrorParameter); - return osErrorParameter; - } - - // Check object state - if (timer->state != osRtxTimerRunning) { - EvrRtxTimerError(timer, osErrorResource); - return osErrorResource; - } - - timer->state = osRtxTimerStopped; - - TimerRemove(timer); - - EvrRtxTimerStopped(timer); - - return osOK; -} - -/// Check if a timer is running. -/// \note API identical to osTimerIsRunning -uint32_t svcRtxTimerIsRunning (osTimerId_t timer_id) { - os_timer_t *timer = (os_timer_t *)timer_id; - - // Check parameters - if ((timer == NULL) || (timer->id != osRtxIdTimer)) { - EvrRtxTimerIsRunning(timer, 0U); - return 0U; - } - - // Check object state - if (timer->state == osRtxTimerRunning) { - EvrRtxTimerIsRunning(timer, 1U); - return 1U; - } - - EvrRtxTimerIsRunning(timer, 0U); - return 0U; -} - -/// Delete a timer. -/// \note API identical to osTimerDelete -osStatus_t svcRtxTimerDelete (osTimerId_t timer_id) { - os_timer_t *timer = (os_timer_t *)timer_id; - - // Check parameters - if ((timer == NULL) || (timer->id != osRtxIdTimer)) { - EvrRtxTimerError(timer, osErrorParameter); - return osErrorParameter; - } - - // Check object state - switch (timer->state) { - case osRtxTimerStopped: - break; - case osRtxTimerRunning: - TimerRemove(timer); - break; - case osRtxTimerInactive: - default: - EvrRtxTimerError(timer, osErrorResource); - return osErrorResource; - } - - // Mark object as inactive - timer->state = osRtxTimerInactive; - - // Free object memory - if (timer->flags & osRtxFlagSystemObject) { - if (osRtxInfo.mpi.timer != NULL) { - osRtxMemoryPoolFree(osRtxInfo.mpi.timer, timer); - } else { - osRtxMemoryFree(osRtxInfo.mem.common, timer); - } - } - - EvrRtxTimerDestroyed(timer); - - return osOK; -} - - -// ==== Public API ==== - -/// Create and Initialize a timer. -osTimerId_t osTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr) { - EvrRtxTimerNew(func, type, argument, attr); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxTimerError(NULL, osErrorISR); - return NULL; - } - return __svcTimerNew(func, type, argument, attr); -} - -/// Get name of a timer. -const char *osTimerGetName (osTimerId_t timer_id) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxTimerGetName(timer_id, NULL); - return NULL; - } - return __svcTimerGetName(timer_id); -} - -/// Start or restart a timer. -osStatus_t osTimerStart (osTimerId_t timer_id, uint32_t ticks) { - EvrRtxTimerStart(timer_id, ticks); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxTimerError(timer_id, osErrorISR); - return osErrorISR; - } - return __svcTimerStart(timer_id, ticks); -} - -/// Stop a timer. -osStatus_t osTimerStop (osTimerId_t timer_id) { - EvrRtxTimerStop(timer_id); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxTimerError(timer_id, osErrorISR); - return osErrorISR; - } - return __svcTimerStop(timer_id); -} - -/// Check if a timer is running. -uint32_t osTimerIsRunning (osTimerId_t timer_id) { - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxTimerIsRunning(timer_id, 0U); - return 0U; - } - return __svcTimerIsRunning(timer_id); -} - -/// Delete a timer. -osStatus_t osTimerDelete (osTimerId_t timer_id) { - EvrRtxTimerDelete(timer_id); - if (IS_IRQ_MODE() || IS_IRQ_MASKED()) { - EvrRtxTimerError(timer_id, osErrorISR); - return osErrorISR; - } - return __svcTimerDelete(timer_id); -} diff --git a/rtos/rtx5/mbed_rtx_conf.h b/rtos/rtx5/mbed_rtx_conf.h deleted file mode 100644 index b4fe1d4..0000000 --- a/rtos/rtx5/mbed_rtx_conf.h +++ /dev/null @@ -1,56 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2006-2012 ARM Limited - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#ifndef MBED_RTX_CONF_H -#define MBED_RTX_CONF_H - -#include "mbed_rtx.h" - -/** The thread's stack size can be configured by the application, if not explicitly specified it'll default to 4K */ -#ifndef MBED_CONF_APP_THREAD_STACK_SIZE -#define MBED_CONF_APP_THREAD_STACK_SIZE 4096 -#endif - -#define OS_STACK_SIZE MBED_CONF_APP_THREAD_STACK_SIZE - -#define OS_TIMER_THREAD_STACK_SIZE 768 -#ifndef OS_IDLE_THREAD_STACK_SIZE -#define OS_IDLE_THREAD_STACK_SIZE 256 -#endif - -#define OS_DYNAMIC_MEM_SIZE 0 - -#if defined(__CC_ARM) -/* ARM toolchain uses up to 8 static mutexes, any further mutexes will be allocated on the heap. */ -#define OS_MUTEX_OBJ_MEM 1 -#define OS_MUTEX_NUM 8 -#endif - -#if !defined(OS_STACK_WATERMARK) && (defined(MBED_STACK_STATS_ENABLED) && MBED_STACK_STATS_ENABLED) -#define OS_STACK_WATERMARK 1 -#endif - -/* Run threads unprivileged when uVisor is enabled. */ -#if defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED) -# define OS_PRIVILEGE_MODE 0 -#endif - -#endif /* MBED_RTX_CONF_H */ diff --git a/rtos/rtx5/mbed_rtx_handlers.c b/rtos/rtx5/mbed_rtx_handlers.c deleted file mode 100644 index e5dcaba..0000000 --- a/rtos/rtx5/mbed_rtx_handlers.c +++ /dev/null @@ -1,138 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2006-2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "cmsis_compiler.h" -#include "rtx_os.h" -#include "rtx_evr.h" -#include "mbed_rtx.h" -#include "mbed_error.h" - -extern void rtos_idle_loop(void); - -__NO_RETURN void osRtxIdleThread (void *argument) -{ - for (;;) { - rtos_idle_loop(); - } -} - -__NO_RETURN uint32_t osRtxErrorNotify (uint32_t code, void *object_id) -{ - osThreadId_t tid = osThreadGetId(); - - switch (code) { - case osRtxErrorStackUnderflow: - // Stack underflow detected for thread (thread_id=object_id) - error("CMSIS-RTOS error: Stack underflow (status: 0x%X, task ID: 0x%X, task name: %s)\n\r", - code, object_id, osThreadGetName(object_id)); - break; - case osRtxErrorISRQueueOverflow: - // ISR Queue overflow detected when inserting object (object_id) - error("CMSIS-RTOS error: ISR Queue overflow (status: 0x%X, task ID: 0x%X, object ID: 0x%X)\n\r", - code, tid, object_id); - break; - case osRtxErrorTimerQueueOverflow: - // User Timer Callback Queue overflow detected for timer (timer_id=object_id) - error("CMSIS-RTOS error: User Timer Callback Queue overflow (status: 0x%X, task ID: 0x%X, timer ID: 0x%X)\n\r", - code, tid, object_id); - break; - case osRtxErrorClibSpace: - // Standard C/C++ library libspace not available: increase OS_THREAD_LIBSPACE_NUM - error("CMSIS-RTOS error: STD C/C++ library libspace not available (status: 0x%X, task ID: 0x%X)\n\r", - code, tid); - break; - case osRtxErrorClibMutex: - // Standard C/C++ library mutex initialization failed - error("CMSIS-RTOS error: STD C/C++ library mutex initialization failed (status: 0x%X, task ID: 0x%X)\n\r", - code, tid); - break; - default: - error("CMSIS-RTOS error: Unknown (status: 0x%X, task ID: 0x%X)\n\r", code, tid); - break; - } - - /* That shouldn't be reached */ - for (;;) {} -} - -#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED - -static const char* error_msg(int32_t status) -{ - switch (status) { - case osError: - return "Unspecified RTOS error"; - case osErrorTimeout: - return "Operation not completed within the timeout period"; - case osErrorResource: - return "Resource not available"; - case osErrorParameter: - return "Parameter error"; - case osErrorNoMemory: - return "System is out of memory"; - case osErrorISR: - return "Not allowed in ISR context"; - default: - return "Unknown"; - } -} - -void EvrRtxKernelError (int32_t status) -{ - error("Kernel error %i: %s\r\n", status, error_msg(status)); -} - -void EvrRtxThreadError (osThreadId_t thread_id, int32_t status) -{ - error("Thread %p error %i: %s\r\n", thread_id, status, error_msg(status)); -} - -void EvrRtxTimerError (osTimerId_t timer_id, int32_t status) -{ - error("Timer %p error %i: %s\r\n", timer_id, status, error_msg(status)); -} - -void EvrRtxEventFlagsError (osEventFlagsId_t ef_id, int32_t status) -{ - error("Event %p error %i: %s\r\n", ef_id, status, error_msg(status)); -} - -void EvrRtxMutexError (osMutexId_t mutex_id, int32_t status) -{ - error("Mutex %p error %i: %s\r\n", mutex_id, status, error_msg(status)); -} - -void EvrRtxSemaphoreError (osSemaphoreId_t semaphore_id, int32_t status) -{ - // Ignore semaphore overflow, the count will saturate with a returned error - if (status == osRtxErrorSemaphoreCountLimit) { - return; - } - - error("Semaphore %p error %i\r\n", semaphore_id, status); -} - -void EvrRtxMemoryPoolError (osMemoryPoolId_t mp_id, int32_t status) -{ - error("Memory Pool %p error %i\r\n", mp_id, status); -} - -void EvrRtxMessageQueueError (osMessageQueueId_t mq_id, int32_t status) -{ - error("Message Queue %p error %i\r\n", mq_id, status); -} - -#endif diff --git a/tools/targets/__init__.py b/tools/targets/__init__.py index 9d02174..6d551b3 100644 --- a/tools/targets/__init__.py +++ b/tools/targets/__init__.py @@ -32,16 +32,16 @@ "CUMULATIVE_ATTRIBUTES", "get_resolution_order"] CORE_LABELS = { - "Cortex-M0" : ["M0", "CORTEX_M", "LIKE_CORTEX_M0"], - "Cortex-M0+": ["M0P", "CORTEX_M", "LIKE_CORTEX_M0"], - "Cortex-M1" : ["M1", "CORTEX_M", "LIKE_CORTEX_M1"], - "Cortex-M3" : ["M3", "CORTEX_M", "LIKE_CORTEX_M3"], - "Cortex-M4" : ["M4", "CORTEX_M", "RTOS_M4_M7", "LIKE_CORTEX_M4"], - "Cortex-M4F" : ["M4", "CORTEX_M", "RTOS_M4_M7", "LIKE_CORTEX_M4"], - "Cortex-M7" : ["M7", "CORTEX_M", "RTOS_M4_M7", "LIKE_CORTEX_M7"], - "Cortex-M7F" : ["M7", "CORTEX_M", "RTOS_M4_M7", "LIKE_CORTEX_M7"], - "Cortex-M7FD" : ["M7", "CORTEX_M", "RTOS_M4_M7", "LIKE_CORTEX_M7"], - "Cortex-A9" : ["A9", "CORTEX_A", "LIKE_CORTEX_A9"] + "Cortex-M0" : ["M0", "CORTEX_M", "LIKE_CORTEX_M0", "CORTEX"], + "Cortex-M0+": ["M0P", "CORTEX_M", "LIKE_CORTEX_M0", "CORTEX"], + "Cortex-M1" : ["M1", "CORTEX_M", "LIKE_CORTEX_M1", "CORTEX"], + "Cortex-M3" : ["M3", "CORTEX_M", "LIKE_CORTEX_M3", "CORTEX"], + "Cortex-M4" : ["M4", "CORTEX_M", "RTOS_M4_M7", "LIKE_CORTEX_M4", "CORTEX"], + "Cortex-M4F" : ["M4", "CORTEX_M", "RTOS_M4_M7", "LIKE_CORTEX_M4", "CORTEX"], + "Cortex-M7" : ["M7", "CORTEX_M", "RTOS_M4_M7", "LIKE_CORTEX_M7", "CORTEX"], + "Cortex-M7F" : ["M7", "CORTEX_M", "RTOS_M4_M7", "LIKE_CORTEX_M7", "CORTEX"], + "Cortex-M7FD" : ["M7", "CORTEX_M", "RTOS_M4_M7", "LIKE_CORTEX_M7", "CORTEX"], + "Cortex-A9" : ["A9", "CORTEX_A", "LIKE_CORTEX_A9", "CORTEX"] } ################################################################################