You are viewing an older revision! See the latest version
CMSIS RTOS
RTOS
- mbed RTOS
- CMSIS RTOS
The CMSIS-RTOS is a common API for Real-Time operating systems. It provides a standardized programming interface that is portable to many RTOS and enables therefore software templates, middleware, libraries, and other components that can work across supported the RTOS systems.
Import librarymbed-rtos
Official mbed Real Time Operating System based on the RTX implementation of the CMSIS-RTOS API open standard.
Thread¶
The Thread Management function group allow defining, creating, and controlling thread functions in the system. The function main is a special thread function that is started at system initialization and has the initial priority osPriorityNormal.
Import program
00001 #include "mbed.h" 00002 #include "cmsis_os.h" 00003 00004 DigitalOut led1(LED1); 00005 DigitalOut led2(LED2); 00006 00007 void led2_thread(void const *args) { 00008 while (true) { 00009 led2 = !led2; 00010 osDelay(1000); 00011 } 00012 } 00013 osThreadDef(led2_thread, osPriorityNormal, DEFAULT_STACK_SIZE); 00014 00015 int main() { 00016 osThreadCreate(osThread(led2_thread), NULL); 00017 00018 while (true) { 00019 led1 = !led1; 00020 osDelay(500); 00021 } 00022 }
main
The main
function is already the first thread scheduled by the rtos.
[Repository '/users/mbed_official/code/rtx/docs/tip/structos__thread__def.html' not found]
Mutex¶
The Mutex Management function group is used to synchronize the execution of threads. This is for example used to protect access to a shared resource, for example a shared memory image.
ISR
Mutex Management functions cannot be called from interrupt service routines (ISR).
[Not converted]
C standard library mutexes
The ARM C standard library has already mutexes in place to protect the access to stdio, therefore on the M3 mbed the above example is not necessary. On the contrary, ARM microlib (used on the M0 mbed) does not provide default stdio mutexes making the above example a necessity.
printf in ISR
Because of the mutexes in the ARM C standard library you can not use printf
in ISR!
Semaphore¶
The Semaphore Management function group is used to manage and protect access to shared resources. For example, with a Semaphore the access to a group of identical peripherals can be managed. The number of available resources is specified as parameter of the osSemaphoreCreate function.
[Not converted]
Signals¶
The Signal Management function group allow to control or wait signal flags. Each thread has assigned signal flags.
[Not converted]
Message Queue¶
The Message Queue Management function group allow to control, send, receive, or wait for messages. A message can be a integer or pointer value that is send to a thread or interrupt service routine.
[Not converted]
Memory Pool¶
[Not converted]
[Not converted]
Mail Queue¶
The Mail Queue Management function group allow to control, send, receive, or wait for mail. A mail is a memory block that is send to a thread or interrupt service routine.
[Not converted]
[Not converted]
Timer¶
The Timer Management function group allow creating and and controlling of timer functions in the system. A timer function is called when a time period expires whereby both on-shot and periodic timers are possible. A timer can be started, restarted, or stopped.
Timers are handled in the thread osTimerThread. Callback functions run under control of this thread and may use CMSIS-RTOS API calls.
[Not converted]
Interrupt Service Routines¶
The same CMSIS-RTOS can be used in ISR. The only two warnings are:
- Mutexes can not be used.
- Wait in ISR is not allowed: all the timeouts in method parameters have to be set to 0 (no wait).
[Not converted]
No wait in ISR
When calling an rtos object method in an ISR all the timeout parameters have to be set to 0 (no wait): waiting in ISR is not allowed.
Status and Error Codes¶
The Status and Error Codes section lists all the return values that the CMSIS-RTOS functions will return:
osOK
: function completed; no event occurred.osEventSignal
: function completed; signal event occurred.osEventMessage
: function completed; message event occurred.osEventMail
: function completed; mail event occurred.osEventTimeout
: function completed; timeout occurred.osErrorParameter
: parameter error: a mandatory parameter was missing or specified an incorrect object.osErrorResource
: resource not available: a specified resource was not available.osErrorTimeoutResource
: resource not available within given time: a specified resource was not available within the timeout period.osErrorISR
: not allowed in ISR context: the function cannot be called from interrupt service routines.osErrorISRRecursive
: function called multiple times from ISR with same object.osErrorPriority
: system cannot determine priority or thread has illegal priority.osErrorNoMemory
: system is out of memory: it was impossible to allocate or reserve memory for the operation.osErrorValue
: value of a parameter is out of range.osErrorOS
: unspecified RTOS error: run-time error but no other error message fits.
osEvent¶
The osEvent
data structure is returned by get
methods of Queue
and Mail
objects.
This data structure contains both an error code and a pointer to the actual data:
[Not converted]