mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-12-07 13:45:00 -05:00
I tried to adjust my heap to FreeRTOS. This is my very first commit to FreeRTOS, i don't even know how to compile the kernel. Maybe You get it running and let me know what You think about it. https://forums.freertos.org/t/real-time-memory-manager/19685
83 lines
1.3 KiB
C
83 lines
1.3 KiB
C
//==============
|
|
// heap_block.h
|
|
//==============
|
|
|
|
// Block of continuous memory on the heap.
|
|
// Size and flags are stored twice at the head and the foot.
|
|
|
|
// Copyright 2024, Sven Bieg (svenbieg@web.de)
|
|
// http://github.com/svenbieg/Heap
|
|
|
|
|
|
#ifndef _HEAP_BLOCK_H
|
|
#define _HEAP_BLOCK_H
|
|
|
|
|
|
//=======
|
|
// Using
|
|
//=======
|
|
|
|
#include "heap_internal.h"
|
|
|
|
|
|
//======
|
|
// Info
|
|
//======
|
|
|
|
typedef struct heap_block_info_t
|
|
{
|
|
size_t offset;
|
|
union
|
|
{
|
|
struct
|
|
{
|
|
size_t size: SIZE_BITS-1;
|
|
size_t free: 1;
|
|
};
|
|
size_t header;
|
|
};
|
|
}heap_block_info_t;
|
|
|
|
typedef struct
|
|
{
|
|
heap_block_info_t previous;
|
|
heap_block_info_t current;
|
|
heap_block_info_t next;
|
|
}heap_block_chain_t;
|
|
|
|
|
|
//==================
|
|
// Con-/Destructors
|
|
//==================
|
|
|
|
void* heap_block_init(heap_handle_t heap, heap_block_info_t const* info);
|
|
|
|
|
|
//========
|
|
// Common
|
|
//========
|
|
|
|
static inline size_t heap_block_calc_size(size_t size)
|
|
{
|
|
return align_up(size, sizeof(size_t))+2*sizeof(size_t);
|
|
}
|
|
|
|
static inline size_t heap_block_get_offset(void* ptr)
|
|
{
|
|
return (size_t)ptr-sizeof(size_t);
|
|
}
|
|
|
|
static inline void* heap_block_get_pointer(size_t offset)
|
|
{
|
|
return (void*)(offset+sizeof(size_t));
|
|
}
|
|
|
|
|
|
//========
|
|
// Access
|
|
//========
|
|
|
|
void heap_block_get_chain(heap_handle_t heap, void* ptr, heap_block_chain_t* info);
|
|
void heap_block_get_info(heap_handle_t heap, void* ptr, heap_block_info_t* info);
|
|
|
|
#endif // _HEAP_BLOCK_H
|