HALFRED  0.4.0
hal_heap.h
Go to the documentation of this file.
1 
10 #ifndef HAL_HEAP_H
11 #define HAL_HEAP_H
12 
13 #include <stdint.h>
14 #include <stddef.h>
15 #include "hal_config.h"
16 
17 
112 
113 #ifndef HAL_HEAP_MODE
114 #define HAL_HEAP_MODE 0
115 #endif
116 
117 #ifndef HAL_HEAP_DEBUG
118 #define HAL_HEAP_DEBUG 0
119 #endif
120 
121 #ifndef HAL_HEAP_ALIGNMENT
122 #define HAL_HEAP_ALIGNMENT 4
123 #endif
124 
125 #if defined HAL_HEAP_MODE && (HAL_HEAP_MODE == 0)
126 
127 // In this mode the heap is serviced by malloc() and free(), with exception to
128 // OS-specific heap management (such as FreeRTOS pvPortMalloc and vPortFree)
129 
130 #ifndef HAL_OS_FREERTOS
131 #include <stdlib.h>
132 
133 #define HEAP_Alloc malloc
134 
135 #define HEAP_Free free
136 
137 #define HEAP_Calloc calloc
138 
139 #define HEAP_Realloc realloc
140 
141 #else
142 
143 void* HEAP_PORT_Alloc(size_t size);
144 
145  void HEAP_PORT_Free(void* ptr);
146 
147 #define HEAP_Alloc HEAP_PORT_Alloc
148 
149 #define HEAP_Free HEAP_PORT_Free
150 
151 #endif
152 #endif
153 
154 #if defined HAL_HEAP_MODE && ((HAL_HEAP_MODE == 1) || (HAL_HEAP_MODE == 2))
155 
156 // In this mode the heap is serviced by simple internal HALFRED memory manager
157 
158 
165 void* HEAP_Alloc(size_t size);
166 
172 void HEAP_Free(void* ptr);
173 
174 
180 size_t HEAP_GetSpaceUsed(void);
181 
187 size_t HEAP_GetSpaceLeft(void);
188 
189 #endif
190 
191 #if defined HAL_HEAP_MODE && (HAL_HEAP_MODE == 3)
192 
193 // In this mode the the user is responsible for providing own implementation
194 // of HEAP_Alloc and HEAP_Free functions.
195 
196 extern void* HEAP_Alloc(size_t size);
197 
198 extern void HEAP_Free(void* ptr);
199 
200 #endif
201 
202 
210 #endif /* HAL_HEAP_H */