aboutsummaryrefslogtreecommitdiff
path: root/include/08.heap/heap04.c
diff options
context:
space:
mode:
Diffstat (limited to 'include/08.heap/heap04.c')
-rw-r--r--include/08.heap/heap04.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/include/08.heap/heap04.c b/include/08.heap/heap04.c
new file mode 100644
index 0000000..be39951
--- /dev/null
+++ b/include/08.heap/heap04.c
@@ -0,0 +1,33 @@
+int k_heapBMAddBlock(KHEAPBM *heap, uintptr_t addr, uint32_t size, uint32_t bsize) {
+ KHEAPBLOCKBM *b;
+ uint32_t bcnt;
+ uint32_t x;
+ uint8_t *bm;
+
+ b = (KHEAPBLOCKBM*)addr;
+ b->size = size - sizeof(KHEAPBLOCKBM);
+ b->bsize = bsize;
+
+ b->next = heap->fblock;
+ heap->fblock = b;
+
+ bcnt = b->size / b->bsize;
+ bm = (uint8_t*)&b[1];
+
+ /* clear bitmap */
+ for (x = 0; x < bcnt; ++x) {
+ bm[x] = 0;
+ }
+
+ /* reserve room for bitmap */
+ bcnt = (bcnt / bsize) * bsize < bcnt ? bcnt / bsize + 1 : bcnt / bsize;
+ for (x = 0; x < bcnt; ++x) {
+ bm[x] = 5;
+ }
+
+ b->lfb = bcnt - 1;
+
+ b->used = bcnt;
+
+ return 1;
+}