Introduction to the uCOS-II Task readiness table

Source: Internet
Author: User
Tags bit set

I have never understood the meaning of these two programs, especially the second one:

Osrdygrp | = osmaptbl [PRIO> 3]; (1) osrdytbl [PRIO> 3] | = osmaptbl [PRIO & 0x07]; (2) I always thought, osrdygrp represents rows, and osrdytbl represents columns. After a period of reading data, it is a bit eye-catching. In my understanding, we think of the eight rows in the ready table as eight elements of the array osrdytbl []. Each element is 8 bits and each bit is a priority, in this way, there are a total of 64 priorities. For example, osrdytbl [0] indicates the first element in the array, that is, the first line, with the priority 0-7. The other is similar. UCOS defines another variable osrdgrp, which is 8 bits. Each bit corresponds to each row and corresponds to an element in the array, for example, The 0th bits of osrdygrp represent the first element of the array, that is, the first row of the ready table. To move a task to the ready state, you must set priority in the ready table to 1, 1, and 0 to indicate that the task is not ready. Now let's look at the first program. We will write the PRIO as binary, the highest priority is 63, the binary is 00111111, combined with the ready table and binary form can be seen: the lower three digits (0th-2nd bits) indicate the priority of each row in the ready table. Because each row has eight bits, every 8 bits are directed to 3rd bits, therefore, when each row has a priority set to 1, you can jump to the next row and enter 1 to the 3rd bits. Therefore, from the third row to the fifth row represents the row with the highest priority. Osmaptbl is an array defined, as shown in:

We shift PRIO three places to the right, add 0 to the upper position, and lose three places to the lower position. Prio> 3 indicates the row with the priority. The osmaptbl [PRIO> 3] Table can get the corresponding value, which indicates a row. Then, osrdygrp | = osmaptbl [PRIO> 3] indicates that osrdygrp corresponds to location 1, indicating that the row indicated by the bit set by 1 has the task ready. Let's look at the second program.
Osrdytbl [PRIO> 3] | = osmaptbl [PRIO & 0x07]. PRIO & 0x07 indicates the position where the priority is in a row, bring it into osmaptbl [] to find the specific value. osrdytbl [PRIO> 3] indicates the row with the priority and matches it with the detected value, that is, set the corresponding position of the corresponding row to 1. so far, the task is put into the ready table to make it ready...If not, please correct.

Find the task with the highest priority in the ready state, and use the osunmaptbl [16*16] table. The method for generating the positive table is to find the one with the highest priority, that is, the number of digits where the lowest Bit in 8 bits is not 0. For example, osrdygrp = 01101000, the fourth digit is 1 and the lowest digit is not 0. Therefore, through the Table query, osunmaptbl [0x01101000] = 3. Similarly, we can find that the value of osrdytbl = 11100100 in osunmaptbl is 2. To better understand this table, I wrote a small program to generate the osunmaptbl table, in which osunmaptbl uses a two-dimensional array osunmaptbl [16] [16].
unsigned char OSUnMapTbl[16][16];     unsigned char count = 0;      for (int i = 0; i < 16; i++)     {         for (int j = 0; j < 16; j++)         {             unsigned char temp = count;             int           bit = 0;             while ((temp & 0x01) == 0 && bit <8)             {                 temp >>= 1;                 bit++;             }             if(bit == 8)                 bit = 0;             OSUnMapTbl[i][j] = bit;             count++;         }     }      for (int i = 0; i < 16; i++)     {         for (int j = 0; j < 16; j++)         {             printf("%d,",(int)OSUnMapTbl[i][j]);         }         printf("\n");     }

Then, the task y = osunmaptbl [osrdygrp] with the highest priority in the ready state can be obtained through the following calculation;
X = osunmaptbl [osrdytbl [y];
Prio = y
<3
+ X;

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.