diff options
Diffstat (limited to 'os/kernel/include')
-rw-r--r-- | os/kernel/include/ch.h | 1 | ||||
-rw-r--r-- | os/kernel/include/heap.h | 47 | ||||
-rw-r--r-- | os/kernel/include/memcore.h (renamed from os/kernel/include/mem.h) | 37 | ||||
-rw-r--r-- | os/kernel/include/threads.h | 4 |
4 files changed, 73 insertions, 16 deletions
diff --git a/os/kernel/include/ch.h b/os/kernel/include/ch.h index 46d917e29..fa30c0eaf 100644 --- a/os/kernel/include/ch.h +++ b/os/kernel/include/ch.h @@ -75,6 +75,7 @@ #include "events.h"
#include "messages.h"
#include "mailboxes.h"
+#include "memcore.h"
#include "heap.h"
#include "mempools.h"
#include "threads.h"
diff --git a/os/kernel/include/heap.h b/os/kernel/include/heap.h index 4fbd48225..1f07faa91 100644 --- a/os/kernel/include/heap.h +++ b/os/kernel/include/heap.h @@ -27,17 +27,60 @@ #ifndef _HEAP_H_
#define _HEAP_H_
+#if CH_USE_HEAP
+
+/*
+ * Module dependancies check.
+ */
+#if !CH_USE_MEMCORE && !CH_USE_MALLOC_HEAP
+#error "CH_USE_HEAP requires CH_USE_MEM"
+#endif
+
+#if !CH_USE_MUTEXES && !CH_USE_SEMAPHORES
+#error "CH_USE_HEAP requires CH_USE_MUTEXES and/or CH_USE_SEMAPHORES"
+#endif
+
+typedef struct memory_heap MemoryHeap;
+
+/**
+ * @brief Memory heap block header.
+ */
+struct heap_header {
+ union {
+ struct heap_header *h_next; /**< @brief Next block in free list. */
+ MemoryHeap *h_heap; /**< @brief Block owner heap. */
+ };
+ size_t h_size; /**< @brief Size of the memory block. */
+};
+
+/**
+ * @brief Structure describing a memory heap.
+ */
+struct memory_heap {
+ memgetfunc_t h_provider; /**< @brief Memory blocks provider for
+ this heap. */
+ struct heap_header h_free; /**< @brief Free blocks list header. */
+#if CH_USE_MUTEXES
+ Mutex h_mtx; /**< @brief Heap access mutex. */
+#else
+ Semaphore h_sem; /**< @brief Heap access semaphore. */
+#endif
+};
+
#ifdef __cplusplus
extern "C" {
#endif
void heap_init(void);
- void *chHeapAlloc(size_t size);
+ void chHeapInit(MemoryHeap *heapp, void *buf, size_t size);
+ void *chHeapAlloc(MemoryHeap *heapp, size_t size);
void chHeapFree(void *p);
- size_t chHeapStatus(size_t *sizep);
+ size_t chHeapStatus(MemoryHeap *heapp, size_t *sizep);
#ifdef __cplusplus
}
#endif
+#endif /* CH_USE_HEAP */
+
#endif /* _HEAP_H_ */
/** @} */
diff --git a/os/kernel/include/mem.h b/os/kernel/include/memcore.h index c7f5ba07a..8f3fe4671 100644 --- a/os/kernel/include/mem.h +++ b/os/kernel/include/memcore.h @@ -18,16 +18,16 @@ */
/**
- * @file mem.h
- * @brief Low level memory manager macros and structures.
- * @addtogroup coremem
+ * @file memcore.h
+ * @brief Core memory manager macros and structures.
+ * @addtogroup memcore
* @{
*/
-#ifndef _MEM_H_
-#define _MEM_H_
+#ifndef _MEMCORE_H_
+#define _MEMCORE_H_
-#if CH_USE_COREMEM
+#if CH_USE_MEMCORE
/**
* @brief Memory alignment type. @@ -35,6 +35,13 @@ typedef void *align_t;
/**
+ * @brief Memory get function.
+ * @note This type must be assignment compatible with the @p chMemAlloc()
+ * function.
+ */
+typedef void *(*memgetfunc_t)(size_t size);
+
+/**
* @brief Alignment mask constant. */
#define MEM_ALIGN_MASK (sizeof(align_t) - 1)
@@ -42,20 +49,26 @@ typedef void *align_t; /**
* @brief Alignment helper macro. */
-#define MEM_ALIGN_SIZE(p) (((size_t)(p) + ALIGN_MASK) & ~ALIGN_MASK)
+#define MEM_ALIGN_SIZE(p) (((size_t)(p) + MEM_ALIGN_MASK) & ~MEM_ALIGN_MASK)
+
+/**
+ * @brief Returns whatever a pointer or memory size is aligned to
+ * the type @p align_t. + */
+#define MEM_IS_ALIGNED(p) (((size_t)(p) & MEM_ALIGN_MASK) == 0)
#ifdef __cplusplus
extern "C" {
#endif
- void mem_init(void);
- void *chMemAlloc(size_t size);
- void *chMemAllocI(size_t size);
+ void core_init(void);
+ void *chCoreAlloc(size_t size);
+ void *chCoreAllocI(size_t size);
#ifdef __cplusplus
}
#endif
-#endif /* CH_USE_COREMEM */
+#endif /* CH_USE_MEMCORE */
-#endif /* _MEM_H_ */
+#endif /* _MEMCORE_H_ */
/** @} */
diff --git a/os/kernel/include/threads.h b/os/kernel/include/threads.h index 1b9850435..ccafc3e96 100644 --- a/os/kernel/include/threads.h +++ b/os/kernel/include/threads.h @@ -167,8 +167,8 @@ extern "C" { Thread *chThdCreateStatic(void *wsp, size_t size, tprio_t prio, tfunc_t pf, void *arg); #if CH_USE_DYNAMIC && CH_USE_WAITEXIT && CH_USE_HEAP - Thread *chThdCreateFromHeap(size_t size, tprio_t prio, - tfunc_t pf, void *arg); + Thread *chThdCreateFromHeap(MemoryHeap *heapp, size_t size, + tprio_t prio, tfunc_t pf, void *arg); #endif #if CH_USE_DYNAMIC && CH_USE_WAITEXIT && CH_USE_MEMPOOLS Thread *chThdCreateFromMemoryPool(MemoryPool *mp, tprio_t prio, |