From f52d1de3b558ebb54669af5bf8fc85b804ab278b Mon Sep 17 00:00:00 2001 From: lyon Date: Mon, 15 Nov 2021 00:10:38 +0800 Subject: [PATCH] bitmap set get is ok --- port/linux/api-make-linux.sh | 0 port/linux/api-make-win10.sh | 0 port/linux/api-make.sh | 0 port/linux/gtest.sh | 0 port/linux/init.sh | 0 port/linux/make.sh | 0 .../package/pikascript/rust-msc-latest-linux | Bin port/linux/pull-core.sh | 0 port/linux/push-core.sh | 0 port/linux/test-banchmark.sh | 0 port/linux/update-compiler.sh | 0 src/dataMemory.c | 38 +++++++++++++++++- src/dataMemory.h | 6 +++ 13 files changed, 43 insertions(+), 1 deletion(-) mode change 100644 => 100755 port/linux/api-make-linux.sh mode change 100644 => 100755 port/linux/api-make-win10.sh mode change 100644 => 100755 port/linux/api-make.sh mode change 100644 => 100755 port/linux/gtest.sh mode change 100644 => 100755 port/linux/init.sh mode change 100644 => 100755 port/linux/make.sh mode change 100644 => 100755 port/linux/package/pikascript/rust-msc-latest-linux mode change 100644 => 100755 port/linux/pull-core.sh mode change 100644 => 100755 port/linux/push-core.sh mode change 100644 => 100755 port/linux/test-banchmark.sh mode change 100644 => 100755 port/linux/update-compiler.sh diff --git a/port/linux/api-make-linux.sh b/port/linux/api-make-linux.sh old mode 100644 new mode 100755 diff --git a/port/linux/api-make-win10.sh b/port/linux/api-make-win10.sh old mode 100644 new mode 100755 diff --git a/port/linux/api-make.sh b/port/linux/api-make.sh old mode 100644 new mode 100755 diff --git a/port/linux/gtest.sh b/port/linux/gtest.sh old mode 100644 new mode 100755 diff --git a/port/linux/init.sh b/port/linux/init.sh old mode 100644 new mode 100755 diff --git a/port/linux/make.sh b/port/linux/make.sh old mode 100644 new mode 100755 diff --git a/port/linux/package/pikascript/rust-msc-latest-linux b/port/linux/package/pikascript/rust-msc-latest-linux old mode 100644 new mode 100755 diff --git a/port/linux/pull-core.sh b/port/linux/pull-core.sh old mode 100644 new mode 100755 diff --git a/port/linux/push-core.sh b/port/linux/push-core.sh old mode 100644 new mode 100755 diff --git a/port/linux/test-banchmark.sh b/port/linux/test-banchmark.sh old mode 100644 new mode 100755 diff --git a/port/linux/update-compiler.sh b/port/linux/update-compiler.sh old mode 100644 new mode 100755 diff --git a/src/dataMemory.c b/src/dataMemory.c index 343c8dac6..6b7449349 100644 --- a/src/dataMemory.c +++ b/src/dataMemory.c @@ -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); +} \ No newline at end of file diff --git a/src/dataMemory.h b/src/dataMemory.h index 4a8fdce33..b8e351b3a 100644 --- a/src/dataMemory.h +++ b/src/dataMemory.h @@ -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