* initial revision, PIC16 C Library headers
[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 ** $Id$
10 */
11
12 /*
13  * Structure of memory block header:
14  * bit 7 (MSB): allocated flag
15  * bits 0-6: pointer to next block (max length: 126)
16  *
17  */
18
19
20 #ifndef __MALLOC_H__
21 #define __MALLOC_H__
22
23 #define EMULATION       0
24
25 #if EMULATION
26 #define malloc  pic16_malloc
27 #define free    pic16_free
28 #define realloc pic16_realloc
29 #define calloc  pic16_calloc
30 #endif
31
32
33 #define MAX_BLOCK_SIZE  0x7f            /* 126 bytes */
34 #define MAX_HEAP_SIZE   0x200           /* 512 bytes */
35 #define _MAX_HEAP_SIZE  (MAX_HEAP_SIZE-1)
36
37 #define ALLOC_FLAG              0x80
38 #define HEADER_SIZE             1
39
40
41 typedef union {
42         unsigned char datum;
43         struct {
44                 unsigned count: 7;
45                 unsigned alloc: 1;
46         } bits;
47 } _malloc_rec;
48
49
50 unsigned char *malloc(unsigned char);
51 void free(unsigned char *);
52 unsigned char *calloc(unsigned char num);               //, unsigned char len);
53 unsigned char *realloc(unsigned char *mblock, unsigned char len);
54
55
56 #endif /* __MALLOC_H__ */
57
58