Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
tlsf_malloc_arch.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016 Alexandre Bustico, Gautier Hattenberger
3 *
4 * This file is part of paparazzi.
5 *
6 * paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
19 */
20
28#include <ch.h>
29#include <tlsf.h>
31
32
37
38
39#ifdef HEAP_CCM
40#define HEAP_CCM_BUFFER HEAP_CCM ## _buffer
41#define HEAP_CCM_MTX HEAP_CCM ## _mtx
45#endif
46
47#ifdef HEAP_SRAM
48#define HEAP_SRAM_BUFFER HEAP_SRAM ## _buffer
49#define HEAP_SRAM_MTX HEAP_SRAM ## _mtx
53#endif
54
55#ifdef HEAP_EXTERN
56#define HEAP_EXTERN_BUFFER HEAP_EXTERN ## _buffer
57#define HEAP_EXTERN_MTX HEAP_EXTERN ## _mtx
61#endif
62
63static void stat_tlsf_walker(void *ptr, size_t size, int used, void *user);
64
65#if defined RTOS_DEBUG && RTOS_DEBUG == 1
66static void error_cb(const char *msg)
67{
69}
70#else
71#define error_cb NULL
72#endif
73
75{
76#ifdef HEAP_CCM
79#endif
80#ifdef HEAP_SRAM
83#endif
84#ifdef HEAP_EXTERN
87#endif
88}
89
91{
92 return heap->tlsf;
93}
94
95void *tlsf_malloc_r(tlsf_memory_heap_t *heap, size_t bytes)
96{
97 chMtxLock(heap->mtx);
98 void *ret = tlsf_malloc(heap->tlsf, bytes);
99 chMtxUnlock(heap->mtx);
100 return ret;
101}
102
103void *tlsf_memalign_r(tlsf_memory_heap_t *heap, size_t align, size_t bytes)
104{
105 chMtxLock(heap->mtx);
106 void *ret = tlsf_memalign(heap->tlsf, align, bytes);
107 chMtxUnlock(heap->mtx);
108 return ret;
109}
110
111void *tlsf_realloc_r(tlsf_memory_heap_t *heap, void *ptr, size_t bytes)
112{
113 chMtxLock(heap->mtx);
114 void *ret = tlsf_realloc(heap->tlsf, ptr, bytes);
115 chMtxUnlock(heap->mtx);
116 return ret;
117}
118
120{
121 chMtxLock(heap->mtx);
122 tlsf_free(heap->tlsf, ptr);
123 chMtxUnlock(heap->mtx);
124}
125
126
128{
129 stat->mused = stat->mfree = 0;
130 chMtxLock(heap->mtx);
132 chMtxUnlock(heap->mtx);
133}
134
135
136/* Returns nonzero if any internal consistency check fails. */
138{
139 int ret = 0;
140 chMtxLock(heap->mtx);
141 ret = tlsf_check(heap->tlsf);
142 if (ret == 0) {
144 }
145
146 chMtxUnlock(heap->mtx);
147 return ret;
148}
149
150
151static void stat_tlsf_walker(void *ptr, size_t size, int used, void *user)
152{
153 (void) ptr;
154 struct tlsf_stat_t *tstat = (struct tlsf_stat_t *) user;
155 if (used) {
156 tstat->mused += size;
157 } else {
158 tstat->mfree += size;
159 }
160}
161
static MUTEX_DECL(sys_time_mtx)
uint8_t msg[10]
Buffer used for general comunication over SPI (out buffer)
uint16_t foo
Definition main_demo5.c:58
Dynamic memory allocation based on TLSF library.
size_t mused
used memory
Definition tlsf_malloc.h:57
void tlsf_free_r(tlsf_memory_heap_t *heap, void *ptr)
#define error_cb
void * tlsf_get_heap_addr(const tlsf_memory_heap_t *heap)
void * tlsf_malloc_r(tlsf_memory_heap_t *heap, size_t bytes)
void tlsf_init_heaps(void)
void tlsf_stat_r(tlsf_memory_heap_t *heap, struct tlsf_stat_t *stat)
static void stat_tlsf_walker(void *ptr, size_t size, int used, void *user)
int tlsf_check_r(tlsf_memory_heap_t *heap)
void * tlsf_memalign_r(tlsf_memory_heap_t *heap, size_t align, size_t bytes)
void * tlsf_realloc_r(tlsf_memory_heap_t *heap, void *ptr, size_t bytes)
#define HEAP_CCM_SECTION
#define HEAP_CCM_SIZE
#define HEAP_CCM
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.