更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
Bitmap
Bitmap 的协作图:

函数

VOID LOS_BitmapSet (UINT32 *bitmap, UINT16 pos)
 Set one bit. 更多...
 
VOID LOS_BitmapClr (UINT32 *bitmap, UINT16 pos)
 Clear one bit. 更多...
 
UINT16 LOS_LowBitGet (UINT32 bitmap)
 Find the lowest one bit that is set. 更多...
 
UINT16 LOS_HighBitGet (UINT32 bitmap)
 Find the highest one bit that is set. 更多...
 
int LOS_BitmapFfz (UINTPTR *bitmap, UINT32 numBits)
 Find the first zero bit starting from LSB. 更多...
 
VOID LOS_BitmapSetNBits (UINTPTR *bitmap, UINT32 start, UINT32 numsSet)
 Set the number of bit to 1 from start. 更多...
 
VOID LOS_BitmapClrNBits (UINTPTR *bitmap, UINT32 start, UINT32 numsClear)
 Clear the number of bit to zero from start. 更多...
 

详细描述

函数说明

◆ LOS_BitmapClr()

VOID LOS_BitmapClr ( UINT32 bitmap,
UINT16  pos 
)

Clear one bit.

Description:
This API is used to clear one bit of variable according to the parameter.
注意
  • When the value of pos is greater than 31, the bit (pos & 0x1f) of bitmap will be clear.
参数
bitmap[IN] The bitmap variable pointer.
pos[IN] The number bit to be cleared.
返回值
none.
Dependency:
  • los_bitmap.h: the header file that contains the API declaration.
参见
LOS_BitmapSet.

Clear one bit.

在文件 los_bitmap.c69 行定义.

70{
71 if (bitmap == NULL) {
72 return;
73 }
74
75 *bitmap &= ~(1U << (pos & OS_BITMAP_MASK));//在对应位上置0
76}
这是这个函数的调用关系图:

◆ LOS_BitmapClrNBits()

VOID LOS_BitmapClrNBits ( UINTPTR bitmap,
UINT32  start,
UINT32  numsClear 
)

Clear the number of bit to zero from start.

Description:
This API is used to set the number of bit to zero from start.
注意
  • None
参数
*bitmap[IN] The bitmap pointer.
start[IN] The start bit.
numsClear[IN] The number of clear bits
返回值
none.
Dependency:
  • los_bitmap.h: the header file that contains the API declaration.
参见
LOS_BitmapClrNBits

Clear the number of bit to zero from start.

在文件 los_bitmap.c126 行定义.

127{
128 UINTPTR *p = bitmap + BITMAP_WORD(start);
129 const UINT32 size = start + numsClear;
130 UINT16 bitsToClear = BITMAP_BITS_PER_WORD - (start % BITMAP_BITS_PER_WORD);
131 UINTPTR maskToClear = BITMAP_FIRST_WORD_MASK(start);
132
133 while (numsClear >= bitsToClear) {
134 *p &= ~maskToClear;
135 numsClear -= bitsToClear;
136 bitsToClear = BITMAP_BITS_PER_WORD;
137 maskToClear = OS_BITMAP_WORD_MASK;
138 p++;
139 }
140 if (numsClear) {
141 maskToClear &= BITMAP_LAST_WORD_MASK(size);
142 *p &= ~maskToClear;
143 }
144}
unsigned short UINT16
Definition: los_typedef.h:56
unsigned long UINTPTR
Definition: los_typedef.h:68
unsigned int UINT32
Definition: los_typedef.h:57
这是这个函数的调用关系图:

◆ LOS_BitmapFfz()

int LOS_BitmapFfz ( UINTPTR bitmap,
UINT32  numBits 
)

Find the first zero bit starting from LSB.

Description:
This API is used to find the first zero bit starting from LSB and return the bit index.
注意
  • None
参数
*bitmap[IN] The bitmap pointer.
返回值
intThe bit index of the first zero bit from LSB.
Dependency:
  • los_bitmap.h: the header file that contains the API declaration.
参见
LOS_BitmapFfz

Find the first zero bit starting from LSB.

在文件 los_bitmap.c146 行定义.

147{
148 INT32 bit, i;
149
150 for (i = 0; i < BITMAP_NUM_WORDS(numBits); i++) {
151 if (bitmap[i] == OS_BITMAP_WORD_MASK) {
152 continue;
153 }
154 bit = i * BITMAP_BITS_PER_WORD + Ffz(bitmap[i]);
155 if (bit < numBits) {
156 return bit;
157 }
158 return -1;
159 }
160 return -1;
161}
STATIC INLINE UINT16 Ffz(UINTPTR x)
Definition: los_bitmap.c:55
signed int INT32
Definition: los_typedef.h:60
函数调用图:
这是这个函数的调用关系图:

◆ LOS_BitmapSet()

VOID LOS_BitmapSet ( UINT32 bitmap,
UINT16  pos 
)

Set one bit.

Description:
This API is used to set one bit of variable according to the parameter.
注意
  • When the value of pos is greater than 31, the bit (pos & 0x1f) of bitmap will be set.
参数
bitmap[IN] The bitmap variable pointer.
pos[IN] The number bit to be set.
返回值
None
Dependency:
  • los_bitmap.h: the header file that contains the API declaration.
参见
LOS_BitmapClr

Set one bit.

在文件 los_bitmap.c60 行定义.

61{
62 if (bitmap == NULL) {
63 return;
64 }
65
66 *bitmap |= 1U << (pos & OS_BITMAP_MASK);//在对应位上置1
67}
这是这个函数的调用关系图:

◆ LOS_BitmapSetNBits()

VOID LOS_BitmapSetNBits ( UINTPTR bitmap,
UINT32  start,
UINT32  numsSet 
)

Set the number of bit to 1 from start.

Description:
This API is used to set the number of bit to 1 from start.
注意
  • None
参数
*bitmap[IN] The bitmap pointer.
start[IN] The start bit.
numsSet[IN] The number of set bits
返回值
none.
Dependency:
  • los_bitmap.h: the header file that contains the API declaration.
参见
LOS_BitmapSetNBits

Set the number of bit to 1 from start.

在文件 los_bitmap.c106 行定义.

107{
108 UINTPTR *p = bitmap + BITMAP_WORD(start);
109 const UINT32 size = start + numsSet;
110 UINT16 bitsToSet = BITMAP_BITS_PER_WORD - (start % BITMAP_BITS_PER_WORD);
111 UINTPTR maskToSet = BITMAP_FIRST_WORD_MASK(start);
112
113 while (numsSet > bitsToSet) {
114 *p |= maskToSet;
115 numsSet -= bitsToSet;
116 bitsToSet = BITMAP_BITS_PER_WORD;
117 maskToSet = OS_BITMAP_WORD_MASK;
118 p++;
119 }
120 if (numsSet) {
121 maskToSet &= BITMAP_LAST_WORD_MASK(size);
122 *p |= maskToSet;
123 }
124}
这是这个函数的调用关系图:

◆ LOS_HighBitGet()

UINT16 LOS_HighBitGet ( UINT32  bitmap)

Find the highest one bit that is set.

Description:
This API is used to find the highest one bit that is set and return the bit index.
注意
  • None
参数
bitmap[IN] The bitmap variable.
返回值
UINT16The bit index of the highest one bit that is set.
Dependency:
  • los_bitmap.h: the header file that contains the API declaration.
参见
LOS_LowBitGet

Find the highest one bit that is set.

   CLZ 用于计算操作数最高端0的个数,这条指令主要用于以下两个场合
     1.计算操作数规范化(使其最高位为1)时需要左移的位数
     2.确定一个优先级掩码中最高优先级
* 
参数
bitmap
返回
UINT16

在文件 los_bitmap.c88 行定义.

89{
90 if (bitmap == 0) {
91 return LOS_INVALID_BIT_INDEX;
92 }
93
94 return (OS_BITMAP_MASK - CLZ(bitmap));//CLZ = count leading zeros 用于计算整数的前导零
95}
这是这个函数的调用关系图:

◆ LOS_LowBitGet()

UINT16 LOS_LowBitGet ( UINT32  bitmap)

Find the lowest one bit that is set.

Description:
This API is used to find the lowest one bit that is set and return the bit index.
注意
  • None
参数
bitmap[IN] The bitmap variable.
返回值
UINT16The bit index of the lowest one bit that is set.
Dependency:
  • los_bitmap.h: the header file that contains the API declaration.
参见
LOS_HighBitGet

Find the lowest one bit that is set.

在文件 los_bitmap.c97 行定义.

98{
99 if (bitmap == 0) {
100 return LOS_INVALID_BIT_INDEX;
101 }
102
103 return CTZ(bitmap);// CTZ = count trailing zeros 用于计算给定整数的尾随零
104}
这是这个函数的调用关系图: