CMSIS-RTOS RTX  Version 4.51
CMSIS-RTOS RTX: Real-Time Operating System for Cortex-M processor-based devices
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
System Configuration

The CMSIS-RTOS RTX provides system-wide settings for:

Settings for Round-Robin Thread Switching

CMSIS-RTOS RTX may be configured to use Round-Robin Multitasking thread switching. Round-Robin allows quasi-parallel execution of several threads. Threads are not really executed concurrently but are time-sliced where the available CPU time is divided into time slices and CMSIS-RTOS RTX assigns a time slice to each thread. Because the time slice is typically short (only a few milliseconds) it appears as though threads execute simultaneously.

Threads execute for the duration of their time-slice (unless the thread's time slice is given up). Then, CMSIS-RTOS RTX switches to the next thread that is ready to run and has the same priority. If no other task with the same priority is ready to run, the current running task resumes it execution.

Round-Robin Multitasking is controlled with the #define OS_ROBIN. The time-slice period is configured (in RTX Timer Ticks) with the #define OS_ROBINTOUT.

Example:

The following example shows a simple CMSIS-RTOS RTX program that uses Round-Robin Multitasking. The two threads in this program are counter loops. RTX starts executing job 1, which is the function named job1. This function creates another task called job2. After job1 executes for its time slice, RTX switches to job2. After job2 executes for its time slice, RTX switches back to job1. This process repeats indefinitely.

#include "cmsis_os.h" // CMSIS-RTOS header file
int counter1;
int counter2;
void job1 (void const *arg) {
while (1) { // loop forever
counter1++; // update the counter
}
}
void job2 (void const *arg) {
while (1) { // loop forever
counter2++; // update the counter
}
}
int main (void) {
osKernelInitialize (); // setup kernel
osThreadCreate (osThread(job1), NULL); // create threads
osThreadCreate (osThread(job2), NULL);
osKernelStart (); // start kernel
}
Note
Rather than waiting for a thread time slice to expire, use CMSIS-RTOS functions to signal to the RTX kernel that it can switch to another task. The function osThreadYield passes control to other threads without Round-Robin Multitasking.

Settings for CMSIS-RTOS Timer Management

CMSIS-RTOS RTX supports Timer Management which provides timer callback functions. The Timer Management is configured with the following #defines:

  • #define OS_TIMERS 1 enables the Timer Management. When disable the osTimerThread is not created.
  • #define OS_TIMERPRIO specifies the priority of the osTimerThread that executes the timer callback functions.
  • #define OS_TIMERSTKSZ specifies the stack size (in words) for the the osTimerThread.
  • #define OS_TIMERCBQS specifies the number of timer callback functions that are concurrently created with osTimerCreate.
Note
Refer to CMSIS-RTOS RTX Threads for more information about the osTimerThread.