40 #if (CH_CFG_USE_HEAP == TRUE) || defined(__DOXYGEN__) 49 #if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__) 50 #define H_LOCK(h) chMtxLock(&(h)->mtx) 51 #define H_UNLOCK(h) chMtxUnlock(&(h)->mtx) 53 #define H_LOCK(h) (void) chSemWait(&(h)->sem) 54 #define H_UNLOCK(h) chSemSignal(&(h)->sem) 57 #define H_BLOCK(hp) ((hp) + 1U) 59 #define H_LIMIT(hp) (H_BLOCK(hp) + H_PAGES(hp)) 61 #define H_NEXT(hp) ((hp)->free.next) 63 #define H_PAGES(hp) ((hp)->free.pages) 65 #define H_HEAP(hp) ((hp)->used.heap) 67 #define H_SIZE(hp) ((hp)->used.size) 72 #define NPAGES(p1, p2) \ 74 ((size_t)((p1) - (p2))) \ 110 H_NEXT(&default_heap.
header) = NULL;
111 H_PAGES(&default_heap.
header) = 0;
112 #if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__) 139 size -= (size_t)((uint8_t *)hp - (uint8_t *)buf);
144 H_NEXT(&heapp->
header) = hp;
145 H_PAGES(&heapp->
header) = 0;
148 #if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__) 196 while (H_NEXT(qp) != NULL) {
204 if ((ahp < H_LIMIT(hp)) && (pages <= NPAGES(H_LIMIT(hp), ahp + 1U))) {
212 bpages = NPAGES(H_LIMIT(hp), H_BLOCK(ahp));
213 H_PAGES(hp) = NPAGES(ahp, H_BLOCK(hp));
214 if (bpages > pages) {
219 fp = H_BLOCK(ahp) + pages;
220 H_PAGES(fp) = (bpages - pages) - 1U;
223 H_NEXT(fp) = H_NEXT(hp);
232 if (H_PAGES(hp) == pages) {
234 H_NEXT(qp) = H_NEXT(hp);
240 fp = H_BLOCK(hp) + pages;
241 H_NEXT(fp) = H_NEXT(hp);
242 H_PAGES(fp) = NPAGES(H_LIMIT(hp), H_BLOCK(fp));
255 return (
void *)H_BLOCK(hp);
313 chDbgAssert((hp < qp) || (hp >= H_LIMIT(qp)),
"within free block");
315 if (((qp == &heapp->
header) || (hp > qp)) &&
316 ((H_NEXT(qp) == NULL) || (hp < H_NEXT(qp)))) {
318 H_NEXT(hp) = H_NEXT(qp);
321 if (H_LIMIT(hp) == H_NEXT(hp)) {
323 H_PAGES(hp) += H_PAGES(H_NEXT(hp)) + 1U;
324 H_NEXT(hp) = H_NEXT(H_NEXT(hp));
326 if ((H_LIMIT(qp) == hp)) {
328 H_PAGES(qp) += H_PAGES(hp) + 1U;
329 H_NEXT(qp) = H_NEXT(hp);
359 size_t n, tpages, lpages;
370 while (H_NEXT(qp) != NULL) {
371 size_t pages = H_PAGES(H_NEXT(qp));
376 if (pages > lpages) {
384 if (totalp != NULL) {
389 if (largestp != NULL) {
static memory_heap_t default_heap
Default heap descriptor.
memgetfunc2_t provider
Memory blocks provider for this heap.
heap_header_t header
Free blocks list header.
union heap_header heap_header_t
Type of a memory heap header.
#define MEM_IS_VALID_ALIGNMENT(a)
Returns whatever a constant is a valid alignment.
void chHeapFree(void *p)
Frees a previously allocated memory block.
#define CH_HEAP_ALIGNMENT
Minimum alignment used for heap.
#define MEM_IS_ALIGNED(p, a)
Returns whatever a pointer or memory size is aligned.
void chHeapObjectInit(memory_heap_t *heapp, void *buf, size_t size)
Initializes a memory heap from a static memory area.
mutex_t mtx
Heap access mutex.
size_t chHeapStatus(memory_heap_t *heapp, size_t *totalp, size_t *largestp)
Reports the heap status.
#define chDbgCheck(c)
Function parameters check.
#define chDbgAssert(c, r)
Condition assertion.
void chSemObjectInit(semaphore_t *sp, cnt_t n)
Initializes a semaphore with the specified counter value.
void * chHeapAllocAligned(memory_heap_t *heapp, size_t size, unsigned align)
Allocates a block of memory from the heap by using the first-fit algorithm.
void chMtxObjectInit(mutex_t *mp)
Initializes s mutex_t structure.
ChibiOS/RT main include file.
Structure describing a memory heap.
#define MEM_ALIGN_NEXT(p, a)
Aligns to the next aligned memory address.
void * chCoreAllocAlignedWithOffset(size_t size, unsigned align, size_t offset)
Allocates a memory block.
void _heap_init(void)
Initializes the default heap.