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

System Ticks

     CooCox CoOS uses interrupt systick to implement system tick. You need to configure the frequency of system tick in config.h file. CFG_CPU_FREQ is used for CPU’s clock frequency. The system needs to determine the specific parameters through CPU’s clock frequency while configuring systick. CFG_SYSTICK_FREQ is used for the frequency of system tick that users need. CooCox CoOS supports the frequency from 1 to 1000Hz. The actual value is determined by the specific application while the default value is 100Hz (that is, the time interval is 10ms).

     CooCox CoOS increases the system time by 1 in every system tick interrupt service routine, you can get the current system time by calling CoGetOSTime().

     CooCox CoOS will also check whether the delayed list and the timer list is empty in system tick interrupt service routine except increasing the system time by 1.If the list is not empty, decrease the delayed time of the first item in the list by 1, and judge whether the waiting time of the first item in the list is due. If it is due, call the corresponding operation function, otherwise, skip to the next step.

     CooCox CoOS calls the task scheduling function to determine whether the current system needs to run a task scheduling when exits from the system tick interrupt service.

Code 1 System tick interrupt handling

void SysTick_Handler(void)
{
     OSSchedLock++;                             /* Lock the scheduler. */
     OSTickCnt++;                                 /* Increment system time. */
     if(DlyList != NULL)                            /* Have task in delayed list? */
     {
          DlyList->delayTick--;                  /* Decrease delay time of the list head. */
          if(DlyList->delayTick == 0)           /* Delay time == 0? */
          {
               isr_TimeDispose();                 /* Call hander for delay time list */
          }
     }
     #if CFG_TMR_EN > 0  
     if(TmrList != NULL)                           /* Have timer be in working? */
     {
          TmrList->tmrCnt--;                    /* Decrease timer time of the list head. */
          if(TmrList->tmrCnt == 0)             /* Timer time == 0? */
          {
               isr_TmrDispose();                  /* Call hander for timer list. */
          }
     }    
     #endif
     OSSchedLock--;                             /* Unlock scheduler. */
     if(OSSchedLock==0)
     {
          Schedule();                              /* Call task scheduler */
     }
}



CooCox CoOS

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