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

Task Scheduling

     CooCox CoOS supports two kinds of scheduling mode, preemptive priority and round-robin. The former is used among tasks of different priority, while the latter among tasks of the same priority.

     CooCox CoOS will start a task scheduling in the following three situations:
  • 1) A task whose priority is higher than the current running one is converting to the ready state
  • 2) The current running task is changing from the running state to the waiting or dormant state
  • 3) A task sharing the same priority with the current running task is in the ready state, and meanwhile the time slice of the current task runs out

     When a system tick interrupt exits or some tasks’ states have changed, CooCox CoOS will call the task scheduling function to determine whether it is essential to start a task scheduling or not.

     For the scheduling of tasks sharing the same priority, the system starts the rotation scheduling according to the time slice of each task. When the system has run out the time slice of the current task, it will give the right of control to the next task with the same priority. Figure 2.5.1 shows the system running state of the three tasks (A, B, C with their respective time slices 1, 2, 3) with the same priority when they are entering the ready state in turn.

     In CooCox CoOS source codes, the implementing of task scheduling is shown as follows:

Code 4 Task with a higher priority is ready
  • /* Is higher PRI task coming in? */
    if(RdyPrio < RunPrio )
    {
          TCBNext           = pRdyTcb;           /* Yes, set TCBNext and reorder ready list*/
          pCurTcb->state = TASK_READY;
          pRdyTcb->state = TASK_RUNNING;
          InsertToTCBRdyList(pCurTcb);
          RemoveFromTCBRdyList(pRdyTcb);
    }
Code 5 The state of the current task changes
  • /* Does Running task status change */
    else if(pCurTcb->state != TASK_RUNNING)
    {
          TCBNext           = pRdyTcb;         /* Yes, set TCBNext and reorder ready list*/
          pRdyTcb->state = TASK_RUNNING;
          RemoveFromTCBRdyList(pRdyTcb);
    }
Code 6 The task scheduling among the same priority tasks
  • /* Is it the time for robinning */
    else if((RunPrio == RdyPrio) && (OSCheckTime == OSTickCnt))
    {
          TCBNext           = pRdyTcb;       /* Yes, set TCBNext and reorder ready list*/
          pCurTcb->state = TASK_READY;
          pRdyTcb->state = TASK_RUNNING;
          InsertToTCBRdyList(pCurTcb);
          RemoveFromTCBRdyList(pRdyTcb);
    }

CooCox CoOS

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