CooCox CoOS manages all the tasks’ delay and timeout through delayed list. When you call CoTickDelay ( )、CoTimeDelay ( )、CoResetTaskDelayTick ( ) or other API functions to apply for delay. CooCox CoOS will sort the delay time from short to long, and then insert them into the delayed list. The delayTick item in the task control block preserves the difference value of the delay time between the current task and the previous task. The first item in the list is the value of the delay time or the timeout value, while the subsequent item is the difference value with the former. For example, Task A, B, C delay 10,18,5 respectively, then they will be sequenced as follows in the delayed list:
System will decrease the first item of the delayed list by 1 in every system tick interrupt, and then move it from the delayed list to the ready list until it becomes 0. When moving the tasks whose time is due out of the list in system tick interrupt, system should determine whether the task is a delay operation or a timeout operation. Towards the tasks with a delay operation, CooCox CoOS moves it to the ready list after it being moved out from the delayed list. Towards the tasks with a timeout operation, CooCox CoOS will judge which event leads to the overtime first, and then move the task from the waiting list to the ready list.
CooCox CoOS’s system delay can’t guarantee the accuracy under the following conditions:
1) There is a higher priority task preempting to run when task A is delayed, the delay time will be determined by the running time of the higher priority task;
2) There is a task whose priority is the same to task A preempting to run when task A is delayed, the delay time will be determined by the number of the tasks whose priority are the same to task A in the ready list and the length of their timeslice, as well as the time that the delay time is due.