Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "half_fit.h"
- #include <lpc17xx.h>
- #include <stdio.h>
- #include <stdbool.h>
- #include <limits.h>
- #include "uart.h"
- #define MAX_SIZE 32768
- unsigned char array[MAX_SIZE] __attribute__((section(" .ARM.__at_0x100000000"), zero_init));
- char* cptr = array;
- int* iptr = (int*)array;
- void* vptr = (void*)array;
- //int Start = ptr; // Set a variable for address of Start of the memory pool
- //Initializers
- //Block Header
- typedef struct {
- unsigned int prev: 10;
- unsigned int next:10;
- unsigned int size:10;
- unsigned int alloc:1;
- unsigned int ten24:1;
- }Header;
- //Bitfield
- short BitVector = 0; //16bits
- //Bucket List
- unsigned int BucketList[11] = {0};
- //Bucket Header
- typedef struct{
- unsigned int prev_bucket:10;
- unsigned int next_bucket:10;
- unsigned int space:12;
- }BucketHeader;
- //Functions
- void initializeHeader(Header *header_init){
- header_init->prev_block = 0;
- header_init->next_block = 0;
- header_init->size = 1023;
- header_init->allocated = 0;
- header_init->ten24 = 1;
- }
- void initializeBucket(Header *bucket_init){
- bucket_init->prev_block = 0;
- bucket_init->next_block = 0;
- bucket_init->space = 0;
- }
- //Returns the actual address using the BitAddress as a parameter
- void* ReturnAddress(unsigned int BitAddress){
- //Address in 10bits is represented by the nth chunk it is from the start of the address.
- //Each chunk is 32 bytes
- //printf("PointerAddress: %x\n", vptr);
- unsigned int nBytes = 32*BitAddress;
- //printf("nBytes: %d\n", nBytes);
- void* Address = nBytes + vptr;
- //printf("PointerAddress: %x\n", Address);
- return Address;
- }
- bool coalescePrev{
- return
- }
- bool coalesceNext{
- return
- }
- bool coalesceBoth{
- return
- }
- bool BucketCheck{
- return
- }
- //Mandatory Functions
- void half_init(void){
- Header* header_init;
- BucketHeader* bucket_header;
- header_init= (Header*) array; //Point a Header Pointer to the start of the memory pool
- bucket_header = (BucketHeader*)(header_init+1);//Point a Bucket Pointer to the start of the memory pool + 4 bytes
- initializeHeader(header_init);//initialize the Block
- initializeBucket(bucket_header);//initialize the BucketHeader
- header_bucket.prev_bucket = header_bucket.prev_bucket;
- header_bucket.next_bucket = header_bucket.next_bucket;
- BucketList[10].pointer = Start;
- BucketList[10].full = 1;
- }
- void *half_alloc(unsigned int size){
- }
- void half_free(void * address){
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement