Ucos task priority from 64 to 256, change of Task readiness table

Source: Internet
Author: User

Ucos the technology used in task scheduling is a task-ready table, the example used in the previous article is less than 64 priority task-ready table lookup method, now ucos to expand the task to 256 priority, the task-ready table of the lookup also made some changes, today speaking

First we look at the setup of the task-ready table, when the task is created, we need to set a task-ready table, so we first look at Oscreatetask, in the inside find this code

Err = Os_tcbinit (Prio, PSP, (OS_STK *) 0, 0u, 0u, (void *) 0, 0u);//And then initialize the TCB task area

Remember that there are four variables in the TCB that are used to quickly find the task-ready table, respectively,

Ptcb->ostcby

Ptcb->ostcbx

Ptcb->ostcbbity

Ptcb->ostcbbitx

The process flow in Os_tcbinit is as follows

#if Os_lowest_prio <= 63u

Ptcb->ostcby = (int8u) (Prio >> 3u);

PTCB->OSTCBX = (int8u) (Prio & 0x07u);

#else

Ptcb->ostcby = (int8u) ((int8u) (Prio >> 4u) & 0xFFu);

PTCB->OSTCBX = (int8u) (Prio & 0x0fu);

#endif

Ptcb->ostcbbity = (Os_prio) (1uL << ptcb->ostcby);

PTCB->OSTCBBITX = (Os_prio) (1uL << PTCB->OSTCBX);

As you can see, the assignment of Ostcby and OSTCBX has changed after the system-defined priority is greater than 63, before the 3,453-bit is used for the task-ready grouping, 012 for the ready-to-use task state, with 8 groupings and eight tasks per group, and a total of 64 tasks, and now

Put 1234 bits in the Ready task status value, 45,674 bits hold the value of the Ready task group, so there are 16 groupings and 16 bits to store, altogether there will be 256 tasks.

After this change you need to reset the OSRDYGRP and osrdytbl[] bit width, see the code has the following

Os_ext Os_prio osrdygrp;

Os_ext Os_prio Osrdytbl[os_rdy_tbl_size];

The bit width is specified by Os_prio, then the definition of Os_prio, as follows

#if Os_lowest_prio <= 63u

typedef int8u Os_prio;

#else

typedef int16u Os_prio;

#endif

#define OS_RDY_TBL_SIZE ((Os_lowest_prio)/16u + 1u)

When the priority changes, the width of the packet becomes 16 bits, and the array length becomes the priority/16+1, that is, there are up to 16 elements, and we are not bad, similarly, when we from the Task Readiness table to find the current highest priority of the ready task, the search method has also changed, as follows

Int8u y;

Os_prio *ptbl;

if ((Osrdygrp & 0xFFu)! = 0u) {

y = osunmaptbl[osrdygrp & 0xFFu];

} else {

y = osunmaptbl[(Os_prio) (Osrdygrp >> 8u) & 0xFFu] + 8u;

}

PTBL = &OSRdyTbl[y];

if ((*ptbl & 0xFFu)! = 0u) {

Ospriohighrdy = (int8u) ((y << 4u) + osunmaptbl[(*ptbl & 0xFFu)]);

} else {

Ospriohighrdy = (int8u) ((y << 4u) + osunmaptbl[(Os_prio) (*ptbl >> 8u) & 0xFFu] + 8u);

}

And the way it was found was quite simple.

y = osunmaptbl[osrdygrp];

Ospriohighrdy = (int8u) ((y << 3u) + osunmaptbl[osrdytbl[y]);

What is the difference between these two ways?

First of all, OSUNMAPTBL this array is unchanged, but Osrdygrp becomes 16 bit, can not go directly to the table to find, where the face has made an adjustment, when the low eight bit has any one not 0, Note that the highest priority readiness tasks at this time priority in the first eight OSRDYTBL elements, 0-7 This can be directly to the table, that is, when 0, the highest priority element is at least the eighth element, then the high eight-bit represents the value of the number, plus 8, you can get greater than 8 of the group priority.

OK, at this time the group priority is obtained, to find the sub-priority, can be found directly in the array, but the resulting data when the 16 binary BCD code, also need to convert to hex, and find the highest priority, then use OSUNMAPTBL once, The principle of processing or low eight-bit effective directly through the low eight-bit lookup, high eight-bit effective through the high eight-bit lookup and add 8, two have been obtained after

Y move the four-bit left and sub-group four bits to get the priority of the current highest priority task.

Summary: The Ucos extension task priority is to convert the Ostcby and OSTCBX original three-bit identity priority to four-bit and the priority from 64 to 256.

Ucos task priority from 64 to 256, change of Task readiness table

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.