SYS/BIOS  7.00
Memory.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, Texas Instruments Incorporated - https://www.ti.com
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  */
51 /*
52  * ======== Memory.h ========
53  */
54 
55 #ifndef ti_sysbios_runtime_Memory__include
56 #define ti_sysbios_runtime_Memory__include
57 
58 #include <stdbool.h>
59 #include <stddef.h>
60 #include <stdint.h>
61 
64 
66 /* BIOS 6.x compatibility, use -Dxdc_std__include to disable */
67 #include <xdc/std.h>
68 
69 #define ti_sysbios_runtime_Memory_long_names
70 #include "Memory_defs.h"
71 
72 #define Memory_Size size_t /* for BIOS 6.x compatibility */
73 
75 #ifdef __cplusplus
76 extern "C" {
77 #endif
78 
86 #define Memory_Q_BLOCKING (1)
87 
94 typedef struct {
98  size_t totalSize;
107 } Memory_Stats;
108 
109 typedef void * (*IHeap_AllocFxn) (void *, size_t, size_t, Error_Block *);
110 typedef void (*IHeap_FreeFxn) (void *, void *, size_t);
111 typedef bool (*IHeap_IsBlockingFxn) (void *);
112 typedef void (*IHeap_GetStatsFxn) (void *, Memory_Stats *);
113 
115 /*
116  * TODO -- should be in IHeap.h -- break the circular dependency
117  * between Memory.h and IHeap.h
118  */
119 typedef struct IHeap_Object {
120  IHeap_AllocFxn alloc;
121  IHeap_FreeFxn free;
122  IHeap_IsBlockingFxn isBlocking;
123  IHeap_GetStatsFxn getStats;
124 } IHeap_Object, *IHeap_Handle;
133 extern IHeap_Handle Memory_defaultHeapInstance;
134 
155 extern void * Memory_alloc(IHeap_Handle heap, size_t size, size_t align, Error_Block *eb);
156 
177 extern void * Memory_calloc(IHeap_Handle heap, size_t size, size_t align, Error_Block *eb);
178 
190 extern void Memory_free(IHeap_Handle heap, void * block, size_t size);
191 
200 extern size_t Memory_getMaxDefaultTypeAlign(void);
201 
212 extern void Memory_getStats(IHeap_Handle heap, Memory_Stats *stats);
213 
233 extern bool Memory_query(IHeap_Handle heap, int qual);
234 
241 extern IHeap_Handle Memory_getDefaultHeap(void);
242 
251 extern void Memory_setDefaultHeap(IHeap_Handle heap);
252 
275 extern void * Memory_valloc(IHeap_Handle heap, size_t size, size_t align, char value, Error_Block *eb);
276 
277 #ifdef __cplusplus
278 }
279 #endif
280 
281 #endif /* ti_sysbios_runtime_Memory__include */
282 
284 #undef ti_sysbios_runtime_Memory_long_names
285 #include "Memory_defs.h"
size_t totalSize
total size (in MADUs) of heap.
Definition: Memory.h:98
void(* IHeap_FreeFxn)(void *, void *, size_t)
Definition: Memory.h:110
void Memory_free(IHeap_Handle heap, void *block, size_t size)
Frees the space if the heap manager offers such functionality.
size_t largestFreeSize
current largest contiguous free block (in MADUs)
Definition: Memory.h:106
IHeap_Handle Memory_defaultHeapInstance
The default heap.
IHeap_Handle Memory_getDefaultHeap(void)
Get the default heap handle.
void *(* IHeap_AllocFxn)(void *, size_t, size_t, Error_Block *)
Definition: Memory.h:109
void * Memory_alloc(IHeap_Handle heap, size_t size, size_t align, Error_Block *eb)
Allocate a block of memory from a heap.
size_t Memory_getMaxDefaultTypeAlign(void)
Return the largest alignment required by the target.
bool(* IHeap_IsBlockingFxn)(void *)
Definition: Memory.h:111
Runtime error manager.
void Memory_setDefaultHeap(IHeap_Handle heap)
Set the default heap handle.
void * Memory_valloc(IHeap_Handle heap, size_t size, size_t align, char value, Error_Block *eb)
Allocate a block of memory from a heap and initialize the contents to the value specified.
void * Memory_calloc(IHeap_Handle heap, size_t size, size_t align, Error_Block *eb)
Allocate a block of memory from a heap and zero out the contents.
Error block.
Definition: Error.h:152
Interface to heap functions.
void Memory_getStats(IHeap_Handle heap, Memory_Stats *stats)
Obtain statistics from a heap.
Memory heap statistics.
Definition: Memory.h:94
size_t totalFreeSize
current size (in MADUs) of free memory in the heap
Definition: Memory.h:102
void(* IHeap_GetStatsFxn)(void *, Memory_Stats *)
Definition: Memory.h:112
bool Memory_query(IHeap_Handle heap, int qual)
Test for a particular heap quality.
© Copyright 1995-2021, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale