unsigned short block_size;
unsigned short free_blocks;
unsigned short blocks_init;
- uint32_t * SRAM_entry;
- uint32_t * m_next;
+ unsigned char * SRAM_entry;
+ unsigned char * m_next;
};
-extern void kpool_init(mem_pool_t *, size_t size_arg, unsigned int blocks_arg, uint32_t * entry_SRAM);
+extern void kpool_init(mem_pool_t *, size_t size_arg, unsigned int blocks_arg, unsigned char * entry_SRAM);
extern void * kalloc(mem_pool_t * );
extern void kfree(mem_pool_t *, void* p);
+extern void kheap_info(mem_pool_t *);
#include <stdint.h>
#include <lib/pool.h>
+#include <lib/tinyprintf.h>
#include <lib/string.h>
-void kpool_init(mem_pool_t * pool, size_t size_arg, unsigned int blocks_arg, uint32_t * entry_SRAM) {
+void kpool_init(mem_pool_t * pool, size_t size_arg, unsigned int blocks_arg, unsigned char* entry_SRAM) {
pool->blocks = blocks_arg;
pool->block_size = size_arg;
} */
/* Helper functions */
-uint32_t * AddrFromIndex(mem_pool_t * pool, unsigned int i) {
+unsigned char* AddrFromIndex(mem_pool_t * pool, unsigned int i) {
return pool->SRAM_entry + ( i * pool->block_size );
}
-unsigned int IndexFromAddr(mem_pool_t * pool, const uint32_t * p) {
+unsigned int IndexFromAddr(mem_pool_t * pool, const unsigned char* p) {
return (((unsigned int)(p - pool->SRAM_entry)) / pool->block_size);
}
void kfree(mem_pool_t * pool, void* p) {
if (pool->m_next != NULL) {
(*(unsigned int *)p) = IndexFromAddr(pool, pool->m_next );
- pool->m_next = (uint32_t *)p;
+ pool->m_next = (unsigned char*)p;
}
else {
*((unsigned int*)p) = pool->blocks;
- pool->m_next = (uint32_t *) p;
+ pool->m_next = (unsigned char*) p;
}
++pool->free_blocks;
- }
+}
+
+/* Heap info helper functions */
+
+void kheap_info(mem_pool_t * pool) {
+
+
+ printf("HEAP INFO:\n");
+ printf("BLOCKS FREE: %d\n", pool->free_blocks);
+
+ unsigned char* curr_addr = pool->SRAM_entry;
+
+ // Loop over heap blocks
+ for (int i = 0; i < pool->blocks; i++) {
+ printf("\nBLOCK %d", i+1);
+ for (int j = 0; j < (pool->block_size-1); j++) {
+
+ if (j % 10 == 0)
+ printf("\n%x ", curr_addr);
+ printf("%#x ", *curr_addr);
+ curr_addr++;
+ }
+ printf("\n");
+ curr_addr++;
+
+ }
+ printf("\n");
+
+}
+
+
+
#include <lib/regfunc.h>
#include <lib/pool.h>
#include <lib/stdio.h>
+#include <lib/string.h>
#include <lib/tinyprintf.h>
#include <drivers/uart.h>
extern uint32_t * _beginofheap;
//printf("%p", &_beginofheap);
- kpool_init(&kheap_pool, 512, 10, (uint32_t *) &_beginofheap);
+ kpool_init(&kheap_pool, 0x10, 10, (uint32_t *) &_beginofheap);
// printf("%p\n", &kheap_pool);
char * string3 = (char *) kalloc(&kheap_pool);
+ memset(string, 0xFF, 0x10);
+ memset(string2, 0xEE, 0x10);
+ memset(string3, 0xDD, 0x10);
+
printf("%p\n", string);
printf("%p\n", string2);
printf("%p\n", string3);
kfree(&kheap_pool, string);
char * string6 = (char *) kalloc(&kheap_pool);
- char * string7 = (char *) kalloc(&kheap_pool);
+
+
+ memset(string6, 0xCC, 0x10);
+// char * string7 = (char *) kalloc(&kheap_pool);
printf("%p\n", string6);
- printf("%p\n", string7);
+// printf("%p\n", string7);
+
+
+ kfree(&kheap_pool, string2);
+ char * string7 = (char *) kalloc(&kheap_pool);
+ memset(string7, 0xBB, 0x10);
+
+
+ char * string8 = (char *) kalloc(&kheap_pool);
+ memset(string8, 0xAA, 0x10);
+
+ char * string9 = (char *) kalloc(&kheap_pool);
+ memset(string9, 0x99, 0x10);
//free(string);
+ kfree(&kheap_pool, string3);
+
//char * string2 = (char *) alloc();
//string2 = "taalb";
struct cmd builtincmds[BUILTINCMDS];
int info(int argc, char ** argsv) {
- sysinfo();
+ extern mem_pool_t kheap_pool;
+ kheap_info(&kheap_pool);
return 0;
}
}
- extern mem_pool_t kheap_pool;
- int * a = kalloc(&kheap_pool);
- *a = argc;
- printf("%d\n", *a);
- printf("%p\n", a);
-
return 0;
}