(1) A hardware timer is generally used and configured to generate an interrupt at a rate between 10 and 1000 Hz (see OS_CFG_TICK_RATE_HZ in os_cfg_app.h ). This timer is generally called the Tick Timer. The actual rate to use depends on such factors as: processor speed, desired time resolution, and amount of allowable overhead to handle the tick timer, etc. The tick interrupt does not have to be generated by a timer and, in fact, it can come from other regular time sources such as the power-line frequency (50 or 60 Hz), which are known to be fairly accurate over long periods of time. (2) Assuming CPU interrupts are enabled, the CPU accepts the tick interrupt, preempts the current task, and vectors to the tick ISR. The tick ISR must call OSTimeTick() (see os_time.c ), which accomplishes most of the work needed by µC/OS-III. The tick ISR then clears the timer interrupt (and possibly reloads the timer for the next interrupt). However, some timers may need to be taken care of prior to calling OSTimeTick() instead of after as shown below. Anchor |
---|
| Listing - Handle timer source after OSTimeTick() |
---|
| Listing - Handle timer source after OSTimeTick() |
---|
|
Code Block |
---|
language | cpp |
---|
title | Listing - Handle timer source after OSTimeTick() |
---|
linenumbers | true |
---|
| void TickISR (void)
{
OSTimeTick();
/* Clear tick interrupt source */
/* Reload the timer for the next interrupt */
} |
or, Anchor |
---|
| Listing - Handle timer source before OSTimeTick() |
---|
| Listing - Handle timer source before OSTimeTick() |
---|
|
Code Block |
---|
language | cpp |
---|
title | Listing - Handle timer source before OSTimeTick() |
---|
linenumbers | true |
---|
| void TickISR (void)
{
/* Clear tick interrupt source */
/* Reload the timer for the next interrupt */
OSTimeTick();
} |
(3) OSTimeTick() calls OSTimeTickHook() before any other function to give the opportunity to the µC/OS-III port developer to react as soon as possible upon servicing the tick interrupt. In other words, you may have your own code that needs to be serviced as soon as you get the tick interrupt. Afterwards, it calls a service, OS_TickUpdate() , provided by µC/OS-III to update the list of tasks that are waiting for time to expire or are waiting on a kernel object with a timeout. From this point forward, this will be called the tick list. (4) OS_TickUpdate() is the function responsible for updating the tick list whenever time has passed. It takes the number of ticks which have elapsed as its argument. In periodic tick mode, where each interrupt reflects a single tick of time, OSTimeTick() always passes an argument of 1 to OS_TickUpdate(). |