Skip to content

Commit

Permalink
rtos: Improve CMSIS-RTOSv2 app compatibility
Browse files Browse the repository at this point in the history
Some non-Mbed-OS, pre-existing CMSIS-RTOSv2 applications depend on
CMSIS-RTOSv2 Automatic Dynamic Allocation, also known as Object-specific
memory pools. Mbed OS doesn't by default provide any memory to the
CMSIS-RTOSv2 Automatic Dynamic Allocation pool, as doing so would waste
memory if the feature is not used; even if the feature is used, as a
platform, Mbed OS can't know how many objects of which types will be
created by an application and therefore will either waste memory or not
provide enough memory in a hard to debug manner. Portable CMSIS-RTOSv2
applications depending on CMSIS-RTOSv2 Automatic Dynamic Allocation
should instead configure the memory pools themselves, as applications
know best their memory requirements.

Add Mbed configuration options which can be used by applications to
control the amounts of memory available to the CMSIS-RTOSv2 Automatic
Dynamic Allocation subsystem. This enables portable CMSIS-RTOSv2
applications, which can run on any CMSIS-RTOSv2 OS, to be able to run on
Mbed OS as well.

RTX's configuration options for CMSIS-RTOSv2 memory are documented at
http://www.keil.com/pack/doc/CMSIS_Dev/RTOS2/html/config_rtx5.html

Signed-off-by: Devaraj Ranganna <devaraj.ranganna@arm.com>
Signed-off-by: Jaeden Amero <jaeden.amero@arm.com>
  • Loading branch information
urutva authored and Patater committed Apr 15, 2020
1 parent b090065 commit fa5a954
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
32 changes: 32 additions & 0 deletions rtos/source/TARGET_CORTEX/mbed_lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,38 @@
"idle-thread-stack-size-debug-extra": {
"help": "Additional size to add to the idle thread when code compilation optimisation is disabled",
"value": 0
},
"thread-num": {
"help": "Maximum number of CMSIS-RTOSv2 object-pool threads that can be active at the same time",
"value": 0
},
"thread-user-stack-size": {
"help": "The total memory available for all CMSIS-RTOSv2 object-pool thread stacks combined",
"value": 0
},
"timer-num": {
"help": "Maximum number of CMSIS-RTOSv2 object-pool timers that can be active at the same time",
"value": 0
},
"evflags-num": {
"help": "Maximum number of CMSIS-RTOSv2 object-pool event flag objects that can be active at the same time",
"value": 0
},
"mutex-num": {
"help": "Maximum number of CMSIS-RTOSv2 object-pool mutexes that can be active at the same time",
"value": 0
},
"semaphore-num": {
"help": "Maximum number of CMSIS-RTOSv2 object-pool semaphores that can be active at the same time",
"value": 0
},
"msgqueue-num": {
"help": "Maximum number of CMSIS-RTOSv2 object-pool message queues that can be active at the same time",
"value": 0
},
"msgqueue-data-size": {
"help": "The total memory available for all CMSIS-RTOSv2 object-pool message queues combined",
"value": 0
}
},
"macros": ["_RTE_"],
Expand Down
56 changes: 56 additions & 0 deletions rtos/source/TARGET_CORTEX/mbed_rtx_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,62 @@
#define OS_IDLE_THREAD_STACK_SIZE (MBED_CONF_RTOS_IDLE_THREAD_STACK_SIZE + EXTRA_IDLE_STACK + EXTRA_IDLE_STACK_DEBUG)
#endif

// The number of threads available to applications that need to use
// CMSIS-RTOSv2 Object-specific Memory Pools
#if MBED_CONF_RTOS_THREAD_NUM > 0
#define OS_THREAD_OBJ_MEM 1
#define OS_THREAD_NUM MBED_CONF_RTOS_THREAD_NUM
#endif

// The total amount of memory for all thread stacks combined available to
// applications that need to use CMSIS-RTOSv2 Object-specific Memory Pools for
// threads
#if MBED_CONF_RTOS_THREAD_USER_STACK_SIZE > 0
#define OS_THREAD_USER_STACK_SIZE MBED_CONF_RTOS_THREAD_USER_STACK_SIZE
#endif

// The number of timers available to applications that need to use CMSIS-RTOSv2
// Object-specific Memory Pools
#if MBED_CONF_RTOS_TIMER_NUM > 0
#define OS_TIMER_OBJ_MEM 1
#define OS_TIMER_NUM MBED_CONF_RTOS_TIMER_NUM
#endif

// The number of event flag objects available to applications that need to use
// CMSIS-RTOSv2 Object-specific Memory Pools
#if MBED_CONF_RTOS_EVFLAGS_NUM > 0
#define OS_EVFLAGS_OBJ_MEM 1
#define OS_EVFLAGS_NUM MBED_CONF_RTOS_EVFLAGS_NUM
#endif

// The number of mutexes available to applications that need to use
// CMSIS-RTOSv2 Object-specific Memory Pools
#if MBED_CONF_RTOS_MUTEX_NUM > 0
#define OS_MUTEX_OBJ_MEM 1
#define OS_MUTEX_NUM MBED_CONF_RTOS_MUTEX_NUM
#endif

// The number of semaphores available to applications that need to use
// CMSIS-RTOSv2 Object-specific Memory Pools
#if MBED_CONF_RTOS_SEMAPHORE_NUM > 0
#define OS_SEMAPHORE_OBJ_MEM 1
#define OS_SEMAPHORE_NUM MBED_CONF_RTOS_SEMAPHORE_NUM
#endif

// The number of message queues available to applications that need to use
// CMSIS-RTOSv2 Object-specific Memory Pools
#if MBED_CONF_RTOS_MSGQUEUE_NUM > 0
#define OS_MSGQUEUE_OBJ_MEM 1
#define OS_MSGQUEUE_NUM MBED_CONF_RTOS_MSGQUEUE_NUM
#endif

// The total amount of memory for all message queues combined available to
// applications that need to use CMSIS-RTOSv2 Object-specific Memory Pools for
// message queues
#if MBED_CONF_RTOS_MSGQUEUE_DATA_SIZE > 0
#define OS_MSGQUEUE_DATA_SIZE MBED_CONF_RTOS_MSGQUEUE_DATA_SIZE
#endif

#define OS_DYNAMIC_MEM_SIZE 0

#if defined(OS_TICK_FREQ) && (OS_TICK_FREQ != 1000)
Expand Down

0 comments on commit fa5a954

Please sign in to comment.