CMSIS-RTOS  Version 1.03
Real-Time Operating System: API and RTX Reference Implementation.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
RTX Kernel Tick Timer Configuration

The CMSIS-RTOS RTX functions provide delays in units of milliseconds that are derived from the RTX Timer Tick. It is therefore recommended to configure the RTX Timer Tick to generate a 1 millisecond interval. Configuring a longer RTX Timer Tick may reduce energy consumption, but has impacts on the granularity of the timeouts.

Name #define Description
Use Cortex-M SysTick timer as RTX Kernel Timer OS_SYSTICK Selects the Cortex-M SysTick timer as RTX kernel timer. In this case, the RTX kernel configures the SysTick timer clock source as processor clock. Therefore the value OS_CLOCK should be identical with the value of the CMSIS variable SystemCoreClock.
RTOS Kernel Timer input clock frequency [Hz] OS_CLOCK Specifies the Cortex-M processor clock frequency in Hz. This value is used to calculate the RTX kernel timer reload value.
RTX Timer tick interval value [us] OS_TICK Specifies the RTX Timer Tick interval in microseconds (us). This value is used to calculate timeout values. When the SysTick core timer is enabled the value is also used to configure the SysTick timer. It is recommended to configure the RTX Timer tick to 1000 us which results in a timeout granularity of 1 millisecond.

Usage of an Alternate Timer as RTX Kernel Timer

With #define OS_SYSTICK 0 an alternative timer is selected as RTX kernel timer.

Four functions in the RTX_Conf_CM.c file need to be adapted for using an alternative hardware timer.

  • os_tick_init provides the initialization function for the alternative hardware timer.
  • os_tick_val returns the current value of the alternative hardware timer.
  • os_tick_ovf returns the overflow flag of the alternative hardware timer.
  • os_tick_irqack is an interrupt acknowledge function that is called to confirm the alternative hardware timer interrupt.
  • OS_Tick_Handler needs to be called as the hardware timer interrupt function; the startup code should be modified to this function.

Configuration Code:

#if (OS_SYSTICK == 0) // Functions for alternative timer as RTX kernel timer
/*--------------------------- os_tick_init ----------------------------------*/
/// \brief Initializes an alternative hardware timer as RTX kernel timer
/// \return IRQ number of the alternative hardware timer
int os_tick_init (void) {
return (-1); /* Return IRQ number of timer (0..239) */
}
/*--------------------------- os_tick_val -----------------------------------*/
/// \brief Get alternative hardware timer's current value (0 .. OS_TRV)
/// \return Current value of the alternative hardware timer
uint32_t os_tick_val (void) {
return (0);
}
/*--------------------------- os_tick_ovf -----------------------------------*/
/// \brief Get alternative hardware timer's overflow flag
/// \return Overflow flag\n
/// - 1 : overflow
/// - 0 : no overflow
uint32_t os_tick_ovf (void) {
return (0);
}
/*--------------------------- os_tick_irqack --------------------------------*/
/// \brief Acknowledge alternative hardware timer interrupt
void os_tick_irqack (void) {
/* ... */
}
#endif // (OS_SYSTICK == 0)

OS_Tick_Handler

The function OS_Tick_Handler handles the RTX tick interval interrupts. It is used if you are using an alternate timer as the RTX tick timer.

The OS_Tick_Handler is an interrupt handler function, which runs the OS task scheduler. It is called by the Nested Vectored Interrupt Controller (NVIC) on the alternate timer's interrupt, and cannot be called as a regular C-function. It must be entered into the Interrupt Table in startup file. The default Cortex-M interrupt vector must be replaced by OS_Tick_Handler.

; Vector Table Mapped to Address 0 at Reset
AREA RESET, DATA, READONLY
EXPORT __Vectors
IMPORT OS_Tick_Handler
__Vectors DCD __initial_sp ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
DCD MemManage_Handler ; MPU Fault Handler
DCD BusFault_Handler ; Bus Fault Handler
DCD UsageFault_Handler ; Usage Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SVC_Handler ; SVCall Handler
DCD DebugMon_Handler ; Debug Monitor Handler
DCD 0 ; Reserved
DCD PendSV_Handler ; PendSV Handler
DCD SysTick_Handler ; SysTick Handler
; External Interrupts
DCD WDT_IRQHandler ; 16: Watchdog Timer
DCD TIMER0_IRQHandler ; 17: Timer0
...
DCD I2S_IRQHandler ; 43: I2S
DCD ENET_IRQHandler ; 44: Ethernet
DCD OS_Tick_Handler ; 45: Repetitive Interrupt Timer
DCD MCPWM_IRQHandler ; 46: Motor Control PWM
...