I. Structure of the task-ready table
each task is assigned a different priority, from level 0 to lowest priority Os_lowest_prio, including 0 and Os_lowest_prio. When Uc/os-ii is initialized, the lowest-priority Os_lowest_prio is always assigned to the idle task Idle-task.
Note: The maximum number of tasks os_max_tasks and the lowest priority progression is not related. An application can have 10 tasks, but it can still have 32 priority levels (if the minimum number of priority levels is set to 31).
Each ready task is placed in the Ready table, with 2 variables osrdygrp and osrdytbl[] in the Ready table. In Osrdygrp, tasks are grouped by priority, with 8 tasks as a group. Each of the OSRDYGRP indicates whether each group in the 8-group task has a task to enter the ready state. When the task enters the ready state, the corresponding bit of the corresponding element in the Ready table osrdytbl[] is also set to 1.
Ready Table osrdytbl[] The size of the array depends on Os_lowest_prio.
#define Os_rdy_tbl_size ((Os_lowest_prio)/8 + 1)/ * SIZE of Ready table */os_ext int8u osrdygrp; / * ready list Group*/os_ext int8u osrdytbl[os_rdy_tbl_ SIZE]; /* Table of tasks which is ready to run */
To determine which of the next priority tasks to run, the scheduler in Uc/os-ii always places the lowest-priority task in the ready table in the appropriate position 1.
Ii. operation of the task-ready table
System-to-readiness tables have three main operations: registration, logoff, and identification of the highest priority tasks in readiness tasks from the Ready table.
1. Registration
Puts the task into a ready state, that is, the corresponding position of the task in the Ready table 1.
The lower 3 bits of the task priority are used to determine where the osrdytbl[] is located, and the next 3 bits are used to determine the position in the OSRDYGRP.
2. Logout
Leave a task out of the ready state, that is, the corresponding position of the task in the Ready table 0.
3. Find the highest priority readiness task
In order to find the highest priority task to enter the ready state, it is not necessary to scan the entire Ready task table from osrdytbl[0], just look for the priority decision table osunmaptbl[]. Osunmaptbl[] The value in the table represents a position where the lowest bit of 8bit data is 1, for example: 1000 0000 where the lowest bit of 1 is in the 7th position, then osunmaptbl[128] is 7;1000 0010 where the lowest bit is 1 and the 1th bit, Then the value of osunmaptbl[130] is 1.
1int8uConstOsunmaptbl[] = {2 0,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0x00 to 0x0F*/3 4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0x10 to 0x1F*/4 5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0x20 to 0x2F*/5 4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0x30 to 0x3F*/6 6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0x40 to 0x4f*/7 4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0x50 to 0x5f*/8 5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0x60 to 0x6F*/9 4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0x70 to 0x7F*/Ten 7,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0x80 to 0x8F*/ One 4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0x90 to 0x9F*/ A 5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0xA0 to 0xAF*/ - 4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0xb0 to 0xBF*/ - 6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0xC0 to 0xCF*/ the 4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0xD0 to 0xDF*/ - 5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,/*0xE0 to 0xEF*/ - 4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0 /*0xF0 to 0xFF*/ -};
1 y = osunmaptbl[osrdygrp]; /* Find Highest priority ' s task priority number */ 2 x = osunmaptbl[osrdytbl[y]]; 3 3) + x);
The structure and operation of the task-ready table (UC/OS-II)