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