|
ChibiOS/RT
2.5.1 |
00001 /* 00002 ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, 00003 2011,2012 Giovanni Di Sirio. 00004 00005 This file is part of ChibiOS/RT. 00006 00007 ChibiOS/RT is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 ChibiOS/RT is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 /** 00022 * @file chheap.h 00023 * @brief Heaps macros and structures. 00024 * 00025 * @addtogroup heaps 00026 * @{ 00027 */ 00028 00029 #ifndef _CHHEAP_H_ 00030 #define _CHHEAP_H_ 00031 00032 #if CH_USE_HEAP || defined(__DOXYGEN__) 00033 00034 /* 00035 * Module dependencies check. 00036 */ 00037 #if !CH_USE_MEMCORE && !CH_USE_MALLOC_HEAP 00038 #error "CH_USE_HEAP requires CH_USE_MEMCORE or CH_USE_MALLOC_HEAP" 00039 #endif 00040 00041 #if !CH_USE_MUTEXES && !CH_USE_SEMAPHORES 00042 #error "CH_USE_HEAP requires CH_USE_MUTEXES and/or CH_USE_SEMAPHORES" 00043 #endif 00044 00045 typedef struct memory_heap MemoryHeap; 00046 00047 /** 00048 * @brief Memory heap block header. 00049 */ 00050 union heap_header { 00051 stkalign_t align; 00052 struct { 00053 union { 00054 union heap_header *next; /**< @brief Next block in free list. */ 00055 MemoryHeap *heap; /**< @brief Block owner heap. */ 00056 } u; /**< @brief Overlapped fields. */ 00057 size_t size; /**< @brief Size of the memory block. */ 00058 } h; 00059 }; 00060 00061 /** 00062 * @brief Structure describing a memory heap. 00063 */ 00064 struct memory_heap { 00065 memgetfunc_t h_provider; /**< @brief Memory blocks provider for 00066 this heap. */ 00067 union heap_header h_free; /**< @brief Free blocks list header. */ 00068 #if CH_USE_MUTEXES 00069 Mutex h_mtx; /**< @brief Heap access mutex. */ 00070 #else 00071 Semaphore h_sem; /**< @brief Heap access semaphore. */ 00072 #endif 00073 }; 00074 00075 #ifdef __cplusplus 00076 extern "C" { 00077 #endif 00078 void _heap_init(void); 00079 #if !CH_USE_MALLOC_HEAP 00080 void chHeapInit(MemoryHeap *heapp, void *buf, size_t size); 00081 #endif 00082 void *chHeapAlloc(MemoryHeap *heapp, size_t size); 00083 void chHeapFree(void *p); 00084 size_t chHeapStatus(MemoryHeap *heapp, size_t *sizep); 00085 #ifdef __cplusplus 00086 } 00087 #endif 00088 00089 #endif /* CH_USE_HEAP */ 00090 00091 #endif /* _CHHEAP_H_ */ 00092 00093 /** @} */