#define MAX_MEMORY_POOL_SIZE 1000
char memory_pool[MEMORY_POOL_SIZE];
static const usedmask[] =
{
0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01
};
#define SHOW_POOL(x) (memory_pool[(x)/8] & usedmask[(x)%8])
#define SET_USED(x) (memory_pool[(x)/8] |= usedmask[(x)%8])
#define SET_UNUSED(x) (memory_pool[(x)/8] &= ~usedmask[(x)%8])
void *nvram_malloc(int size)
{
int i, j, k, is_free;
is_free = UNUSED;
for(i = 0 ; i < MAX_NVRAM_SIZE ; i++)
{
if(SHOW_POOL(i) == UNUSED)
{
for(j = 1 ; j < (size-1) ; j++)
{
if(SHOW_POOL(i+j) != UNUSED) {
i = i + j;
is_free = USED;
break;
}
else continue;
}
if(is_free == UNUSED) {
for(j = 0 ; j < size ; j++)
SET_USED(i+j);
return (void *)(i + BASE_NVRAM);
}
}
}
return NULL;
}
char memory_pool[MEMORY_POOL_SIZE];
static const usedmask[] =
{
0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01
};
#define SHOW_POOL(x) (memory_pool[(x)/8] & usedmask[(x)%8])
#define SET_USED(x) (memory_pool[(x)/8] |= usedmask[(x)%8])
#define SET_UNUSED(x) (memory_pool[(x)/8] &= ~usedmask[(x)%8])
void *nvram_malloc(int size)
{
int i, j, k, is_free;
is_free = UNUSED;
for(i = 0 ; i < MAX_NVRAM_SIZE ; i++)
{
if(SHOW_POOL(i) == UNUSED)
{
for(j = 1 ; j < (size-1) ; j++)
{
if(SHOW_POOL(i+j) != UNUSED) {
i = i + j;
is_free = USED;
break;
}
else continue;
}
if(is_free == UNUSED) {
for(j = 0 ; j < size ; j++)
SET_USED(i+j);
return (void *)(i + BASE_NVRAM);
}
}
}
return NULL;
}