CMSIS-RTOS
Version 1.03
Real-Time Operating System: API and RTX Reference Implementation.
|
This section describes the functions that are specific to CMSIS-RTOS RTX. More...
Functions | |
__NO_RETURN void | os_idle_demon (void) |
OS idle demon (running when no other thread is ready to run). More... | |
int | os_tick_init (void) |
Initializes an alternative hardware timer as RTX kernel timer. More... | |
uint32_t | os_tick_val (void) |
Get alternative hardware timer's current value (0 .. OS_TRV) More... | |
uint32_t | os_tick_ovf (void) |
Get alternative hardware timer's overflow flag. More... | |
void | os_tick_irqack (void) |
Acknowledge alternative hardware timer interrupt. More... | |
__NO_RETURN void | os_error (uint32_t error_code) |
OS error callback (called when a runtime error is detected). More... | |
uint32_t | os_suspend (void) |
Suspend the RTX task scheduler. More... | |
void | os_resume (uint32_t sleep_time) |
Resume the RTX task scheduler. More... | |
The RTX kernel can be customized for different application requirements:
void os_error | ( | uint32_t | error_code | ) |
[in] | error_code | actual error code that has been detected. |
Some system error conditions can be detected during runtime. If the RTX kernel detects a runtime error, it calls the runtime error function os_error.
The argument error_code passes the actual error code to this function:
Error Code | Description |
---|---|
OS_ERROR_STACK_OVF | The stack checking has detected a stack overflow for the currently running thread. |
OS_ERROR_FIFO_OVF | The ISR FIFO Queue buffer overflow is detected. |
OS_ERROR_MBX_OVF | A mailbox overflow is detected for the function osMessagePut or osMailPut. |
OS_ERROR_TIMER_OVF | The User Timer Callback Queue overflow is detected. |
The function os_error must contain an infinite loop to prevent further program execution. You can use an emulator to step over infinite loop and trace into the code introducing a runtime error. For the overflow errors this means you need to increase the size of the object causing an overflow.
Code Example
OS error callback (called when a runtime error is detected).
[in] | error_code | actual error code that has been detected |
void os_idle_demon | ( | void | ) |
The function os_idle_demon is executed by the RTX kernel, when no other threads are ready to run. By default, this task is an empty end-less loop that does nothing. It only waits until another task becomes ready to run. You may change the code of the os_idle_demon function to put the CPU into a power-saving or idle mode.
The default stack size for this task is defined in the file #RTX_Conf_CM.c. Refer to Thread Configuration entry Default Thread stack size [bytes].
Code Example
OS idle demon (running when no other thread is ready to run).
void os_resume | ( | uint32_t | sleep_time | ) |
[in] | sleep_time | specifies how long the system was in sleep or power-down mode. |
The function os_resume resumes the RTX task scheduler. You must call this function after you have called os_suspend to re-enable the task scheduler.
The argument sleep_time specifies how long the system was in sleep or power-down mode. It is measured in number of system intervals.
See os_suspend for a Code Example.
uint32_t os_suspend | ( | void | ) |
The function os_suspend suspends the RTX task scheduler. The function calculates the time, for how long the system is allowed to power-down, and locks the task scheduler. When the function returns, the task switches are disabled. For normal RTX operation, after calling os_suspend, you must call the os_resume function to re-enable the OS task scheduler.
Code Example
The low power RTX is controlled from the os_idle_demon. The peripheral wake-up timer must be initialized before the system enters an endless loop. os_suspend calculates the timeout until the first suspended task becomes ready, and returns the timeout to the user:
The user sets-up a peripheral timer to sleep timeout and starts the timer. The timeout is measured in system ticks.
When the wake-up timer is set-up and running, the user puts the system in power-down mode. The wake-up timer must run also in power-down mode. All other peripherals and the CPU may power-down to reduce power.
The wake-up timer, when expired, generates the interrupt and wakes-up the system. Hence, it must run also in power-down mode. The system resumes operation and needs to call the function os_resume. This function restores the RTX and re-enables the scheduler.
If, for any reason, the system does not wake up immediately after the wake-up interrupt, the actual sleep time is checked and adjusted.
int os_tick_init | ( | void | ) |
The function os_tick_init initializes an alternate hardware timer as the system tick timer and starts it. If you setup OS_SYSTICK to 0, this function will be available for adding the alternate timer. It returns the interrupt number of the alternative hardware timer.
Code Example
void os_tick_irqack | ( | void | ) |
The function os_tick_irqack acknowledges the peripheral timer interrupt.
Code Example
uint32_t os_tick_ovf | ( | void | ) |
The function os_tick_ovf returns the overflow flag of the alternate hardware timer specified by os_tick_init.
Code Example
uint32_t os_tick_val | ( | void | ) |
The function os_tick_val returns the current value of the alternate hardware timer specified by os_tick_init.
Code Example