]> begriffs open source - cmsis/blob - CMSIS/DoxyGen/RTOS2/src/cmsis_os2_tick.txt
RTX5: Add Thread Entry wrapper to be compatible with GDB stack unwind (#1559)
[cmsis] / CMSIS / DoxyGen / RTOS2 / src / cmsis_os2_tick.txt
1 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
2 //  ==== OS Tick API ====
3 /** 
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>
6 \details 
7
8 The <b>OS Tick API</b> is an interface to a system timer that generates the Kernel Ticks.
9
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. 
12
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.
14
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)
20
21 \note The above OS Tick source files implement \c weak functions which may be overwritten by user-specific implementations.
22
23 @{
24 */
25
26 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
27 /**
28 \fn int32_t  OS_Tick_Setup (uint32_t freq, IRQHandler_t handler)
29 \details 
30
31 Setup OS Tick timer to generate periodic RTOS Kernel Ticks.
32
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.
35
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.
38
39 <b>Cortex-M SysTick implementation:</b>
40 \code
41 #ifndef SYSTICK_IRQ_PRIORITY
42 #define SYSTICK_IRQ_PRIORITY    0xFFU
43 #endif
44
45 static uint8_t PendST;
46
47 int32_t  OS_Tick_Setup (uint32_t freq, IRQHandler_t handler) {
48   (void)handler;
49   uint32_t load;
50
51   if (freq == 0U) {
52     return -1;
53   }
54
55   load = (SystemCoreClock / freq) - 1U;
56   if (load > 0x00FFFFFFU) {
57     return -1;
58   }
59
60   NVIC_SetPriority(SysTick_IRQn, SYSTICK_IRQ_PRIORITY);
61
62   SysTick->CTRL =  SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_TICKINT_Msk;
63   SysTick->LOAD =  load;
64   SysTick->VAL  =  0U;
65
66   PendST = 0U;
67
68   return 0;
69 }
70 \endcode
71 */
72
73 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
74 /**
75 \fn void  OS_Tick_Enable (void)
76 \details 
77 Enable OS Tick timer interrupt.
78
79 Enable and start the OS Tick timer to generate periodic RTOS Kernel Tick interrupts.
80
81 <b>Cortex-M SysTick implementation:</b>
82 \code
83 void  OS_Tick_Enable (void) {
84
85   if (PendST != 0U) {
86     PendST = 0U;
87     SCB->ICSR = SCB_ICSR_PENDSTSET_Msk;
88   }
89
90   SysTick->CTRL |=  SysTick_CTRL_ENABLE_Msk;
91
92 }
93 \endcode
94 */
95
96 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
97 /**
98 \fn void  OS_Tick_Disable (void)
99 \details 
100 Disable OS Tick timer interrupt.
101
102 Stop the OS Tick timer and disable generation of RTOS Kernel Tick interrupts.
103
104 <b>Cortex-M SysTick implementation:</b>
105 \code
106 void  OS_Tick_Disable (void) {
107
108   SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
109
110   if ((SCB->ICSR & SCB_ICSR_PENDSTSET_Msk) != 0U) {
111     SCB->ICSR = SCB_ICSR_PENDSTCLR_Msk;
112     PendST = 1U;
113   }
114
115 }
116 \endcode
117 */
118
119 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
120 /**
121 \fn void  OS_Tick_AcknowledgeIRQ (void)
122 \details 
123 Acknowledge execution of OS Tick timer interrupt.
124
125 Acknowledge the execution of the OS Tick timer interrupt function, for example clear the pending flag.
126
127 <b>Cortex-M SysTick implementation:</b>
128
129 \code
130 void  OS_Tick_AcknowledgeIRQ (void) {
131
132   (void)SysTick->CTRL;
133
134 }
135 \endcode
136 */
137
138 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
139 /**
140 \fn int32_t OS_Tick_GetIRQn (void)
141 \details 
142 Get OS Tick timer IRQ number.
143
144 Return the numeric value that identifies the interrupt called by the OS Tick timer.
145
146 <b>Cortex-M SysTick implementation:</b>
147
148 \code
149 int32_t  OS_Tick_GetIRQn (void) {
150   return SysTick_IRQn;
151 }
152 \endcode
153 */
154
155 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
156 /**
157 \fn uint32_t OS_Tick_GetClock (void)
158 \details 
159 Get OS Tick timer clock frequency.
160
161 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.
162 This function is used to by the function \ref osKernelGetSysTimerFreq.
163
164 <b>Cortex-M SysTick implementation:</b>
165
166 \code
167 uint32_t OS_Tick_GetClock (void) {
168   return SystemCoreClock;
169 }
170 \endcode
171 */
172
173 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
174 /**
175 \fn uint32_t OS_Tick_GetInterval (void)
176 \details 
177 Get OS Tick timer interval reload value. 
178
179 Return the number of counter ticks between to periodic OS Tick timer interrupts.
180
181 <b>Cortex-M SysTick implementation:</b>
182
183 \code
184 uint32_t OS_Tick_GetInterval (void) {
185   return SysTick->LOAD + 1U;
186 }
187 \endcode
188 */
189
190 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
191 /**
192 \fn uint32_t OS_Tick_GetCount (void)
193 \details 
194
195 Get OS Tick timer counter value.
196
197 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.
198 The OS Tick timer counter value is used to by the function \ref osKernelGetSysTimerCount.
199
200 <b>Cortex-M SysTick implementation:</b>
201
202 \code
203 uint32_t OS_Tick_GetCount (void) {
204   uint32_t load = SysTick->LOAD;
205   return load - SysTick->VAL;
206 }
207 \endcode
208 */
209
210 /*=======0=========1=========2=========3=========4=========5=========6=========7=========8=========9=========0=========1====*/
211 /**
212 \fn OS_Tick_GetOverflow (void)
213 \details 
214 Get OS Tick timer overflow status.
215
216 Return the state of OS Tick timer interrupt pending bit that indicates timer overflows to adjust SysTimer calculations.
217
218 <b>Cortex-M SysTick implementation:</b>
219
220 \code
221 uint32_t OS_Tick_GetOverflow (void) {
222   return (SCB->ICSR & SCB_ICSR_PENDSTSET_Msk) >> SCB_ICSR_PENDSTSET_Pos;
223 }
224 \endcode
225 */
226
227 /** @} */ /* group CMSIS_RTOS_TickAPI */