1 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2 // ==== OS Tick API ====
4 \addtogroup CMSIS_RTOS_TickAPI OS Tick API
5 \brief System tick timer interface for periodic RTOS Kernel Ticks defined in <b>%os_tick.h</b>
8 The <b>OS Tick API</b> is an interface to a system timer that generates the Kernel Ticks.
10 All Cortex-M processors provide an unified System Tick Timer that is typically used to generate the RTOS Kernel Tick.
11 The Cortex-A processors do not implement an unified system timer and required a device specific implementation.
13 CMSIS-RTOS2 provides in the directory \ref directory "CMSIS/RTOS2/Source" the several OS Tick implementations that can be used by any RTOS kernel.
15 Filename | OS Tick Implementation for...
16 :------------------------|:-----------------------------------------------------------------------
17 \b %os_systick.c | Cortex-M SysTick timer
18 \b %os_tick_gtim.c | Cortex-A Generic Timer (available in some devices)
19 \b %os_tick_ptim.c | Cortex-A Private Timer (available in some devices)
21 \note The above OS Tick source files implement \c weak functions which may be overwritten by user-specific implementations.
26 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
28 \fn int32_t OS_Tick_Setup (uint32_t freq, IRQHandler_t handler)
31 Setup OS Tick timer to generate periodic RTOS Kernel Ticks.
33 The timer should be configured to generate periodic interrupts at frequency specified by \em freq.
34 The parameter \em handler defines the interrupt handler function that is called.
36 The timer should only be initialized and configured but must not be started to create interrupts.
37 The RTOS kernel calls the function \ref OS_Tick_Enable to start the timer interrupts.
39 <b>Cortex-M SysTick implementation:</b>
41 #ifndef SYSTICK_IRQ_PRIORITY
42 #define SYSTICK_IRQ_PRIORITY 0xFFU
45 static uint8_t PendST;
47 int32_t OS_Tick_Setup (uint32_t freq, IRQHandler_t handler) {
55 load = (SystemCoreClock / freq) - 1U;
56 if (load > 0x00FFFFFFU) {
60 NVIC_SetPriority(SysTick_IRQn, SYSTICK_IRQ_PRIORITY);
62 SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_TICKINT_Msk;
73 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
75 \fn int32_t OS_Tick_Enable (void)
77 Enable OS Tick timer interrupt.
79 Enable and start the OS Tick timer to generate periodic RTOS Kernel Tick interrupts.
81 <b>Cortex-M SysTick implementation:</b>
83 int32_t OS_Tick_Enable (void) {
87 SCB->ICSR = SCB_ICSR_PENDSTSET_Msk;
90 SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
97 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
99 \fn int32_t OS_Tick_Disable (void)
101 Disable OS Tick timer interrupt.
103 Stop the OS Tick timer and disable generation of RTOS Kernel Tick interrupts.
105 <b>Cortex-M SysTick implementation:</b>
107 int32_t OS_Tick_Disable (void) {
109 SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
111 if ((SCB->ICSR & SCB_ICSR_PENDSTSET_Msk) != 0U) {
112 SCB->ICSR = SCB_ICSR_PENDSTCLR_Msk;
121 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
123 \fn int32_t OS_Tick_AcknowledgeIRQ (void)
125 Acknowledge execution of OS Tick timer interrupt.
127 Acknowledge the execution of the OS Tick timer interrupt function, for example clear the pending flag.
129 <b>Cortex-M SysTick implementation:</b>
132 int32_t OS_Tick_AcknowledgeIRQ (void) {
139 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
141 \fn int32_t OS_Tick_GetIRQn (void)
143 Get OS Tick timer IRQ number.
145 Return the numeric value that identifies the interrupt called by the OS Tick timer.
147 <b>Cortex-M SysTick implementation:</b>
150 int32_t OS_Tick_GetIRQn (void) {
151 return (SysTick_IRQn);
156 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
158 \fn uint32_t OS_Tick_GetClock (void)
160 Get OS Tick timer clock frequency.
162 Return the input clock frequency of the OS Tick timer. This is the increment rate of the counter value returned by the function \ref OS_Tick_GetCount.
163 This function is used to by the function \ref osKernelGetSysTimerFreq.
165 <b>Cortex-M SysTick implementation:</b>
168 uint32_t OS_Tick_GetClock (void) {
169 return (SystemCoreClock);
174 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
176 \fn uint32_t OS_Tick_GetInterval (void)
178 Get OS Tick timer interval reload value.
180 Return the number of counter ticks between to periodic OS Tick timer interrupts.
182 <b>Cortex-M SysTick implementation:</b>
185 uint32_t OS_Tick_GetInterval (void) {
186 return (SysTick->LOAD + 1U);
191 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
193 \fn uint32_t OS_Tick_GetCount (void)
196 Get OS Tick timer counter value.
198 Return the current value of the OS Tick counter: 0 ... (reload value -1). The reload value is returned by the function \ref OS_Tick_GetInterval.
199 The OS Tick timer counter value is used to by the function \ref osKernelGetSysTimerCount.
201 <b>Cortex-M SysTick implementation:</b>
204 uint32_t OS_Tick_GetCount (void) {
205 uint32_t load = SysTick->LOAD;
206 return (load - SysTick->VAL);
211 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
213 \fn OS_Tick_GetOverflow (void)
215 Get OS Tick timer overflow status.
217 Return the state of OS Tick timer interrupt pending bit that indicates timer overflows to adjust SysTimer calculations.
219 <b>Cortex-M SysTick implementation:</b>
222 uint32_t OS_Tick_GetOverflow (void) {
223 return ((SCB->ICSR & SCB_ICSR_PENDSTSET_Msk) >> SCB_ICSR_PENDSTSET_Pos);
228 /** @} */ /* group CMSIS_RTOS_TickAPI */