CMSIS-RTOS: Using a CMSIS-RTOS Implementation

| CMSIS-RTOS Version 1.02 CMSIS-RTOS API: Generic RTOS interface for Cortex-M processor-based devices.

- Main Page
- Usage and Description
- Reference

Using a CMSIS-RTOS Implementation

A CMSIS-RTOS implementation is typically provided as a library. To add the RTOS functionality to an existing CMSIS-based application, the RTOS library (and typically a configuration file) needs to be added. The available functionality of the RTOS library is defined in the header file cmsis_os.h that is specific for each CMSIS-RTOS implementation.

CMSIS-RTOS File Structure

Depending on the CMSIS-RTOS implementation, execution may start with the main function as the first thread. This has the benefit that an application programmer may use other middleware libraries that create threads internally, but the remaining part of the user application just uses the main thread. Therefore, the usage of the RTOS can be invisible to the application programmer, but libraries can use CMSIS-RTOS features.

Once the files are added to a project, the user can start working with the CMSIS-RTOS functions. A code example is provided below:

Code Example

#include "cmsis_os.h" // CMSIS-RTOS header file
void job1 (void const *argument) { // thread function 'job1'
while (1) {
: // execute some code
osDelay (10); // delay execution for 10 milliseconds
}
}
osThreadDef(job1, osPriorityAboveNormal, 1, 0); // define job1 as thread function
void job2 (void const *argument) { // thread function 'job2'
osThreadCreate(osThread(job1),NULL); // create job1 thread
while (1) {
: // execute some code
}
}
osThreadDef(job2, osPriorityNormal, 1, 0); // define job2 as thread function
void job3 (void const *argument) { // thread function 'job3'
while (1) {
: // execute some code
osDelay (20); // delay execution for 20 milliseconds
}
}
osThreadDef(job3, osPriorityNormal, 1, 0); // define job3 as thread function
int main (void) { // program execution starts here
osKernelInitialize (); // initialize RTOS kernel
: // setup and initialize peripherals
osThreadCreate (osThread(job2));
osThreadCreate (osThread(job3));
osKernelStart (); // start kernel with job2 execution
}