更换语言:
   Contact us
  • Follow CooCox
  •         
  • CooCox Market
  •         
  • Tech Support
  •     
Home  ›  CoOS › Time Management

Software Timer

     Software timer is a high precision timer that CooCox CoOS takes the system tick as the benchmark clock source. CooCox CoOS software supports up to 32 software timers, the operation mode of each timer can be set to the periodic mode or the one-shot mode.

     You can create a software timer by calling CoCreateTmr(). When creating a software timer, the system will assign a corresponding timer control block to describe the current state of the timer. After being created successfully, the timer’s default state is stopping. It won’t work normally until you call CoStartTmr(). To the timer which works normally, CooCox CoOS manages them through the timer list. The same as the delayed list, the timer list is also sorted by the length of the time that is due: the task whose time is due earlier will be in front of the list, and subtract expiration time of the previous timer in the list from expiration time of all the timers, and then save the result into the timer control block. For example, Task A, B, C are set to 10,18,5 respectively, then they will be sequenced as follows in the timer list:


Figure 3.3.1 Timer list

     Once the software timer starts, it will be independent to other modules completely, and only be related to the system tick interrupt. CooCox CoOS takes all the timers into the timer list by the length of the time that is due. Decrease the first item of the timer list by 1(until it becomes 0) in every sysytem tick interrupt.

     When the waiting time of the timer is due, towards the periodic timer CooCox CoOS will reset the next timing according to the tmrReload that you set and then put it into the timer list. However, to the one-shot timer, it will be moved out of the list, and its state will be set to stop.

     From the above, we know that the expiration time of the timer is only determined by the number of system ticks, but has no relation to whether there is a higher priority task running or whether the task which created the timer is in the ready state.

    Software timer provides a function entrance (software timer callback function) for your operation inside the systick interrupt. But some of the APIs which will cause some errors can't be called. Many APIs can not be called in the following situation:
1.Should not call the APIs whose functions do not match, such as CoEnterISR()\CoExitISR(), because the software timer callback function is not a ISR.
2.Software timer callback function is not a task but a function may be called in all tasks, so the APIs which will change the state of the current task (running task) should not be called, such as CoExitTask() \ CoEnterMutexSection() \ CoLeaveMutexSection() \ CoAcceptSem() \ CoPendSem() \ CoAcceptMail() \ CoPendMail() \ CoAcceptQueueMail() \ CoPendQueueMail() \ CoAcceptSingleFlag() \ CoAcceptMultipleFlags() \ CoWaitForSingleFlag() \ CoWaitForMultipleFlags().
3.Each timer’s callback function is implemented inside the systick interrupt when it is due, which requires the code of the software timer must be simplified and should not run a long time to affect the precision of the systick interrupt. So users should not call CoTimeDelay() and CoTickDelay() which will not only affect the precision of the systick interrupt but also cause the kernel error.


CooCox CoOS

© 2009 -2011 CooCox - Terms of Use         Business Model         Market             About us