Advertisement
Guest User

Untitled

a guest
May 25th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. #include "half_fit.h"
  2. #include <lpc17xx.h>
  3. #include <stdio.h>
  4. #include <stdbool.h>
  5. #include <limits.h>
  6. #include "uart.h"
  7. #define MAX_SIZE 32768
  8.  
  9. unsigned char array[MAX_SIZE] __attribute__((section(" .ARM.__at_0x100000000"), zero_init));
  10.  
  11. char* cptr = array;
  12. int* iptr = (int*)array;
  13. void* vptr = (void*)array;
  14. //int Start = ptr; // Set a variable for address of Start of the memory pool
  15. //Initializers
  16. //Block Header
  17. typedef struct {
  18. unsigned int prev: 10;
  19. unsigned int next:10;
  20. unsigned int size:10;
  21. unsigned int alloc:1;
  22. unsigned int ten24:1;
  23. }Header;
  24.  
  25. //Bitfield
  26. short BitVector = 0; //16bits
  27.  
  28. //Bucket List
  29. unsigned int BucketList[11] = {0};
  30.  
  31. //Bucket Header
  32. typedef struct{
  33. unsigned int prev_bucket:10;
  34. unsigned int next_bucket:10;
  35. unsigned int space:12;
  36. }BucketHeader;
  37.  
  38. //Functions
  39.  
  40. void initializeHeader(Header *header_init){
  41. header_init->prev_block = 0;
  42. header_init->next_block = 0;
  43. header_init->size = 1023;
  44. header_init->allocated = 0;
  45. header_init->ten24 = 1;
  46. }
  47.  
  48. void initializeBucket(Header *bucket_init){
  49. bucket_init->prev_block = 0;
  50. bucket_init->next_block = 0;
  51. bucket_init->space = 0;
  52. }
  53.  
  54. //Returns the actual address using the BitAddress as a parameter
  55. void* ReturnAddress(unsigned int BitAddress){
  56. //Address in 10bits is represented by the nth chunk it is from the start of the address.
  57. //Each chunk is 32 bytes
  58. //printf("PointerAddress: %x\n", vptr);
  59. unsigned int nBytes = 32*BitAddress;
  60. //printf("nBytes: %d\n", nBytes);
  61. void* Address = nBytes + vptr;
  62. //printf("PointerAddress: %x\n", Address);
  63. return Address;
  64. }
  65.  
  66. bool coalescePrev{
  67. return
  68. }
  69.  
  70. bool coalesceNext{
  71. return
  72. }
  73.  
  74. bool coalesceBoth{
  75. return
  76. }
  77.  
  78. bool BucketCheck{
  79. return
  80. }
  81.  
  82.  
  83. //Mandatory Functions
  84. void half_init(void){
  85. Header* header_init;
  86. BucketHeader* bucket_header;
  87. header_init= (Header*) array; //Point a Header Pointer to the start of the memory pool
  88. bucket_header = (BucketHeader*)(header_init+1);//Point a Bucket Pointer to the start of the memory pool + 4 bytes
  89. initializeHeader(header_init);//initialize the Block
  90. initializeBucket(bucket_header);//initialize the BucketHeader
  91.  
  92.  
  93.  
  94.  
  95. header_bucket.prev_bucket = header_bucket.prev_bucket;
  96. header_bucket.next_bucket = header_bucket.next_bucket;
  97. BucketList[10].pointer = Start;
  98. BucketList[10].full = 1;
  99.  
  100. }
  101.  
  102. void *half_alloc(unsigned int size){
  103.  
  104.  
  105.  
  106.  
  107.  
  108. }
  109.  
  110. void half_free(void * address){
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement