LP-381 - Adds circular buffer and run writes within a separate callback
[librepilot.git] / flight / pios / common / pios_mem.c
blobbf0166baed31a07483f3eb5ea5bdc9b9b08ea13e
1 /**
2 ******************************************************************************
4 * @file pios_mem.c
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2014.
6 * @addtogroup PiOS
7 * @{
8 * @addtogroup PiOS
9 * @{
10 * @brief PiOS memory allocation API
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <pios.h>
28 #include <pios_mem.h>
30 #ifdef PIOS_TARGET_PROVIDES_FAST_HEAP
31 // relies on pios_general_malloc to perform the allocation (i.e. pios_msheap.c)
32 extern void *pios_general_malloc(void *ptr, size_t size, bool fastheap);
34 void *pios_fastheapmalloc(size_t size)
36 return pios_general_malloc(NULL, size, true);
40 void *pios_malloc(size_t size)
42 return pios_general_malloc(NULL, size, false);
45 void *pios_realloc(__attribute__((unused)) void *ptr, __attribute__((unused)) size_t size)
47 #ifdef PIOS_INCLUDE_REALLOC
48 return pios_general_malloc(ptr, size, false);
50 #else
51 // Not allowed to use realloc without the proper define PIOS_INCLUDE_REALLOC set
52 while (1) {
55 return NULL;
57 #endif
60 void pios_free(void *p)
62 vPortFree(p);
65 #else /* ifdef PIOS_TARGET_PROVIDES_FAST_HEAP */
66 // demand to pvPortMalloc implementation
67 void *pios_fastheapmalloc(size_t size)
69 return pvPortMalloc(size);
73 void *pios_malloc(size_t size)
75 return pvPortMalloc(size);
78 void *pios_realloc(__attribute__((unused)) void *ptr, __attribute__((unused)) size_t size)
80 #ifdef PIOS_INCLUDE_REALLOC
81 return pvPortMalloc(size);
83 #else
84 // Not allowed to use realloc without the proper define PIOS_INCLUDE_REALLOC set
85 while (1) {
88 return NULL;
90 #endif
93 void pios_free(void *p)
95 vPortFree(p);
98 #endif /* ifdef PIOS_TARGET_PROVIDES_FAST_HEAP */