cc5f2462e9505e627ae35746eccbb8ae0989af73
[fw/sdcc] / device / include / pic16 / malloc.h
1 /*
2  * malloc.h - dynamic memory allocation header
3  *
4  * written by Vangelis Rokas, 2004 (vrokas@otenet.gr)
5  *
6  */
7
8
9 /*
10  * Structure of memory block header:
11  * bit 7 (MSB): allocated flag
12  * bits 0-6: pointer to next block (max length: 126)
13  *
14  */
15
16
17 #ifndef __MALLOC_H__
18 #define __MALLOC_H__
19
20 #include <../asm/pic16/features.h>
21
22 #define EMULATION       0
23
24 #if EMULATION
25 #define malloc  pic16_malloc
26 #define free    pic16_free
27 #define realloc pic16_realloc
28 #define calloc  pic16_calloc
29 #define _MALLOC_SPEC
30 #endif
31
32 #define _MALLOC_SPEC    data
33
34 #define MAX_BLOCK_SIZE  0x7f            /* 126 bytes */
35 #define MAX_HEAP_SIZE   0x200           /* 512 bytes */
36 #define _MAX_HEAP_SIZE  (MAX_HEAP_SIZE-1)
37
38 #define ALLOC_FLAG              0x80
39 #define HEADER_SIZE             1
40
41
42 typedef union {
43         unsigned char datum;
44         struct {
45                 unsigned count: 7;
46                 unsigned alloc: 1;
47         } bits;
48 } _malloc_rec;
49
50
51 unsigned char _MALLOC_SPEC *malloc(unsigned char);
52 void free(unsigned char _MALLOC_SPEC *);
53 unsigned char _MALLOC_SPEC *calloc(unsigned char num);          //, unsigned char len);
54 unsigned char _MALLOC_SPEC *realloc(unsigned char _MALLOC_SPEC *mblock, unsigned char len);
55
56
57 #endif /* __MALLOC_H__ */
58
59