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