CMSIS-RTOS  Version 1.00
CMSIS-RTOS API: Generic RTOS interface for Cortex-M processor-based devices.
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 file cmsis_os.h that is specific for each RTOS implementation.

CMSIS_RTOS_Files.png
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 using the CMSIS-RTOS functions. A code example is provided below:

#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 milli seconds
  }
}
// define job1 as thread function
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


int main (void) {                               // program execution starts here
    :                                           // setup and initialize
  osKernelStart (osThread(job2), NULL);         // start kernel with job2 execution
  while (1);                                    // program will never reach this point
}