The specific implementation is as follows:
Each bit of z corresponds to 1 y, which means there are 8 ys in total.
Each bit of y corresponds to one x, which means a total of 8*8 xs.
Each x corresponds to 8 task priority numbers. In this way, the priority can be set by x, y, and z.
Therefore, a structure can be defined in the following form:
#ifndef __HIGH_BITMAP_H_H__
#define __HIGH_BITMAP_H_H__
#define LENGTH_HIGHLAYER 8
#define LENGTH_BYTE 8
typedef unsigned char Byte;
typedef struct
{
Byte high_Layer;
Byte mid_Layer[LENGTH_HIGHLAYER];
Byte low_Layer[LENGTH_HIGHLAYER*LENGTH_BYTE];
}BitMaps;
#ifdef __cplusplus
extern "C"
{
#endif
void inital_bitmap(BitMaps *bitmap);
void set_bitmap(BitMaps *bitmap,int prio);
int calculate_high_prio(BitMaps *bitmap);
#ifdef __cplusplus
}
#endif
#endif
The basic operation functions are as follows:
#include"high_bitmap.h"
#include
int const OSUnMapTbl[256] = {
0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 0x00 to 0x0F */
4, 0 , 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 0x10 to 0x1F */
5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 0x20 to 0x2F */
4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2 , 0, 1, 0, /* 0x30 to 0x3F */
6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 0x40 to 0x4F */
4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 0x50 to 0x5F */
5, 0, 1, 0, 2, 0 , 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 0x60 to 0x6F */
4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 0x70 to 0x7F */
7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 0x80 to 0x8F */
4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 0x90 to 0x9F */
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 */
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 */
};
void inital_bitmap(BitMaps *bitmap)
{
int i = 0;
if(NULL == bitmap)
{
return;
}
bitmap->high_Layer = 0x00;
for(; i < sizeof(bitmap->mid_Layer); ++ i)
{
bitmap->mid_Layer[i] = 0x00;
}
for (i = 0; i < sizeof(bitmap->low_Layer); ++ i)
{
bitmap->low_Layer[i] = 0x00;
}
}
void set_bitmap(BitMaps *bitmap,int prio)
{
int x,y,z;
if(NULL == bitmap || prio >= 512)
{
return ;
}
z = (prio >> 6)& 0x7; x = prio & 0x7; int calculate_high_prio(BitMaps *bitmap) if(NULL == bitmap) z = OSUnMapTbl[bitmap->high_Layer]; z = (z << 6) + (y << 3) + x; return z; This layered implementation can easily solve the problem of multiple possibilities in the bitmap. Through layering, each variable x, y, and z can use the lookup table (256 possibilities), solving the problem of extremely large possibilities. Of course, this method is not the only one, but it is indeed a feasible solution to share the lookup table. The idea of the article query is the same as the query format in uC/OS-II, that is, when the corresponding task needs to be ready, you can set the corresponding x, y, z corresponding bit to 1.
bitmap->high_Layer |= 1<
y = (prio >> 3) & 0x7;
bitmap->mid_Layer[z] |= 1<
bitmap->low_Layer[z*8+y] |= 1<
{
int x,y,z;
{
return -1;
}
y = OSUnMapTbl[bitmap->mid_Layer[z]];
x = OSUnMapTbl[bitmap->low_Layer[(z << 3)+y]];
}
Previous article:Analysis of OS_CPU_IRQ_ISR transplantation process in UCOS-II
Next article:Representation and processing of information in computers
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Altium Designer 21.6.1 7 days of sharing
- Can such a demand be met?
- MS430G2755 Code transplantation process for MSPBoot
- Company products - rare problems with STM32 MCU ADC
- RT-Thread device framework learning I2C device
- Matrix-Vector Derivative Law
- What is the architecture diagram of Narrowband Internet of Things (NB-IoT) technology?
- My Electronic Games Sharing "Three Wars Electronic Games"
- Interaction issues between STM32F429 and AD7606
- Will Ultra-Wideband (UWB) really be popular in the future?