bitmap set get is ok

This commit is contained in:
lyon 2021-11-15 00:10:38 +08:00
parent 08a6708cb6
commit f52d1de3b5
13 changed files with 43 additions and 1 deletions

0
port/linux/api-make-linux.sh Normal file → Executable file
View File

0
port/linux/api-make-win10.sh Normal file → Executable file
View File

0
port/linux/api-make.sh Normal file → Executable file
View File

0
port/linux/gtest.sh Normal file → Executable file
View File

0
port/linux/init.sh Normal file → Executable file
View File

0
port/linux/make.sh Normal file → Executable file
View File

0
port/linux/package/pikascript/rust-msc-latest-linux Normal file → Executable file
View File

0
port/linux/pull-core.sh Normal file → Executable file
View File

0
port/linux/push-core.sh Normal file → Executable file
View File

0
port/linux/test-banchmark.sh Normal file → Executable file
View File

0
port/linux/update-compiler.sh Normal file → Executable file
View File

View File

@ -17,7 +17,8 @@ void* pikaMalloc(uint32_t size) {
void* mem = __platformMalloc(size);
__platformEnableIrqHandle();
if (NULL == mem) {
__platformPrintf("[error]: No heap space! Please reset the device.\r\n");
__platformPrintf(
"[error]: No heap space! Please reset the device.\r\n");
while (1) {
}
}
@ -42,3 +43,38 @@ uint16_t pikaMemMax(void) {
void pikaMemMaxReset(void) {
pikaMemInfo.heapUsedMax = 0;
}
uint8_t* bitmap_init(uint32_t size) {
uint8_t* mem_bit_map =
(uint8_t*)__platformMalloc(((size - 1) / 8 + 1) * sizeof(char));
if (mem_bit_map == NULL)
NULL;
uint32_t size_mem_bit_map = (size - 1) / 8 + 1;
memset(mem_bit_map, 0x0, size_mem_bit_map);
return mem_bit_map;
}
void bitmap_set(uint8_t* bitmap, uint32_t index, uint8_t bit) {
uint32_t index_byte = index / 8;
uint8_t index_bit = index % 8;
uint8_t x = (0x1 << index_bit);
if (bit) {
bitmap[index_byte] |= x;
return;
}
bitmap[index_byte] &= ~x;
return;
}
uint8_t bitmap_get(uint8_t* bitmap, uint32_t index) {
uint32_t index_byte = (index) / 8;
uint8_t index_bit = (index) % 8;
uint8_t x = (0x1 << index_bit);
uint8_t bit;
bit = bitmap[index_byte] & x;
return bit > 0 ? 1 : 0;
}
void bitmap_deinit(uint8_t* bitmap) {
__platformFree(bitmap);
}

View File

@ -21,4 +21,10 @@ void* pikaMalloc(uint32_t size);
uint16_t pikaMemNow(void);
uint16_t pikaMemMax(void);
void pikaMemMaxReset(void);
uint8_t* bitmap_init(uint32_t size);
void bitmap_set(uint8_t* bitmap, uint32_t index, uint8_t bit);
uint8_t bitmap_get(uint8_t* bitmap, uint32_t index);
void bitmap_deinit(uint8_t* bitmap);
#endif