SYS/BIOS  7.00
HeapBuf.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  */
117 /*
118  * ======== HeapBuf.h ========
119  */
120 
121 #ifndef ti_sysbios_heaps_HeapBuf__include
122 #define ti_sysbios_heaps_HeapBuf__include
123 
124 #include <stdbool.h>
125 #include <stddef.h>
126 #include <stdint.h>
127 
128 #include <ti/sysbios/knl/Queue.h>
129 
133 
135 /* BIOS 6.x compatibility, use -Dxdc_std__include to disable */
136 #include <xdc/std.h>
137 
138 #define ti_sysbios_heaps_HeapBuf_long_names
139 #include "HeapBuf_defs.h"
142 #ifdef __cplusplus
143 extern "C" {
144 #endif
145 
146 /*
147  * Error and Assert Ids
148  */
149 
156 #define HeapBuf_A_nullBuf "buf parameter cannot be null"
157 
164 #define HeapBuf_A_bufAlign "buf not properly aligned"
165 
172 #define HeapBuf_A_invalidAlign "align parameter must be 0 or a power of 2 >= the value of Memory_getMaxDefaultTypeAlign()"
173 
181 #define HeapBuf_A_invalidRequestedAlign "align parameter 1) must be 0 or a power of 2 and 2) not greater than the heaps alignment"
182 
187 #define HeapBuf_A_invalidBlockSize "blockSize must be large enough to hold at least two pointers"
188 
192 #define HeapBuf_A_zeroBlocks "numBlocks cannot be zero"
193 
197 #define HeapBuf_A_zeroBufSize "bufSize cannot be zero"
198 
205 #define HeapBuf_A_invalidBufSize "HeapBuf_create's bufSize parameter is invalid (too small)"
206 
212 #define HeapBuf_A_noBlocksToFree "Cannot call HeapBuf_free when no blocks have been allocated"
213 
227 #define HeapBuf_A_invalidFree "Invalid free"
228 
232 #define HeapBuf_E_size "requested size is too big: handle=0x%x, size=%u"
233 
237 typedef struct {
245  unsigned int maxAllocatedBlocks;
250  unsigned int numAllocatedBlocks;
252 
253 typedef struct {
273  size_t align;
281  unsigned int numBlocks;
294  size_t blockSize;
311  size_t bufSize;
326  void * buf;
328 
329 typedef struct {
330  IHeap_Object iheap;
344  size_t blockSize;
364  size_t align;
372  unsigned int numBlocks;
389  size_t bufSize;
404  char *buf;
405  unsigned int numFreeBlocks;
406  unsigned int minFreeBlocks;
409 
411 
413 typedef struct {
414  Queue_Struct objQ;
415 } HeapBuf_Module_State;
425 #define ti_sysbios_heaps_HeapBuf_Handle_upCast(handle) ((IHeap_Handle)(handle))
426 
442 extern void * HeapBuf_alloc(HeapBuf_Handle heap, size_t size, size_t align, Error_Block *eb);
443 
444 /*
445  * @brief Free a block of allocated memory.
446  *
447  * @param heap heap handle
448  * @param buf address of allocated block
449  * @param size size
450  */
451 extern void HeapBuf_free(HeapBuf_Handle heap, void * buf, size_t size);
452 
461 extern bool HeapBuf_isBlocking(HeapBuf_Handle heap);
462 
469 extern void HeapBuf_getStats(HeapBuf_Handle heap, Memory_Stats *statBuf);
470 
480 extern void HeapBuf_getExtendedStats(HeapBuf_Handle heap, HeapBuf_ExtendedStats *statBuf);
481 
490 extern HeapBuf_Handle HeapBuf_create(const HeapBuf_Params *params, Error_Block *eb);
491 
492 
505 extern HeapBuf_Handle HeapBuf_construct(HeapBuf_Struct *obj, const HeapBuf_Params *params, Error_Block *eb);
506 
515 extern void HeapBuf_delete(HeapBuf_Handle *heap);
516 
522 extern void HeapBuf_destruct(HeapBuf_Struct *obj);
523 
535 extern void HeapBuf_Params_init(HeapBuf_Params *prms);
536 
545 extern HeapBuf_Handle HeapBuf_Object_first(void);
546 
557 extern HeapBuf_Handle HeapBuf_Object_next(HeapBuf_Handle heap);
558 
560 extern size_t HeapBuf_getBlockSize(HeapBuf_Handle heap);
561 
562 extern void HeapBuf_mergeHeapBufs(HeapBuf_Handle h1, HeapBuf_Handle h2);
563 
564 static inline HeapBuf_Handle HeapBuf_handle(HeapBuf_Struct *str)
565 {
566  return ((HeapBuf_Handle)str);
567 }
568 
569 static inline HeapBuf_Struct * HeapBuf_struct(HeapBuf_Handle h)
570 {
571  return ((HeapBuf_Struct *)h);
572 }
573 
574 #define HeapBuf_module ((HeapBuf_Module_State *) &(HeapBuf_Module_state))
575 
577 #ifdef __cplusplus
578 }
579 #endif
580 
581 #endif
582 
584 #undef ti_sysbios_heaps_HeapBuf_long_names
585 #include "HeapBuf_defs.h"
HeapBuf_Handle HeapBuf_Object_next(HeapBuf_Handle heap)
return handle of the next HeapBuf on HeapBuf list
unsigned int minFreeBlocks
Definition: HeapBuf.h:406
Queue_Struct freeList
Definition: HeapBuf.h:407
bool HeapBuf_isBlocking(HeapBuf_Handle heap)
This function always returns false since the alloc/free never block on a resource.
size_t blockSize
Size (in MAUs) of each block.
Definition: HeapBuf.h:344
char * buf
User supplied buffer; for dynamic creates only.
Definition: HeapBuf.h:404
void * HeapBuf_alloc(HeapBuf_Handle heap, size_t size, size_t align, Error_Block *eb)
All alignment is handled in the create, therefore the align argument in alloc is ignored.
Static and run-time memory manager.
unsigned int numBlocks
Number of fixed-size blocks.
Definition: HeapBuf.h:281
size_t bufSize
Size (in MAUs) of the entire buffer; for dynamic creates only.
Definition: HeapBuf.h:389
void HeapBuf_free(HeapBuf_Handle heap, void *buf, size_t size)
Opaque queue element.
Definition: Queue.h:204
unsigned int numFreeBlocks
Definition: HeapBuf.h:405
Runtime error manager.
HeapBuf_Handle HeapBuf_Object_first(void)
return handle of the first HeapBuf on HeapBuf list
Queue Manager.
unsigned int numAllocatedBlocks
The total number of blocks currently allocated in this HeapBuf instance.
Definition: HeapBuf.h:250
Queue_Elem objElem
Definition: HeapBuf.h:331
size_t align
Alignment (in MAUs) of each block.
Definition: HeapBuf.h:273
Definition: HeapBuf.h:329
unsigned int numBlocks
Number of fixed-size blocks.
Definition: HeapBuf.h:372
Error block.
Definition: Error.h:152
unsigned int maxAllocatedBlocks
The maximum number of blocks allocated from this heap at any single point in time, during the lifetime of this HeapBuf instance. The configuration parameter HeapBuf.trackMaxAllocs must be set to true for this field to have any meaning. Otherwise, this field will be set to &#39;0&#39;.
Definition: HeapBuf.h:245
struct HeapBuf_Struct * HeapBuf_Handle
size_t bufSize
Size (in MAUs) of the entire buffer; for dynamic creates only.
Definition: HeapBuf.h:311
void HeapBuf_getExtendedStats(HeapBuf_Handle heap, HeapBuf_ExtendedStats *statBuf)
Retrieves the extended statistics for a HeapBuf instance.
void HeapBuf_delete(HeapBuf_Handle *heap)
Delete a HeapBuf heap.
size_t blockSize
Size (in MAUs) of each block.
Definition: HeapBuf.h:294
void * buf
User supplied buffer; for dynamic creates only.
Definition: HeapBuf.h:326
HeapBuf_Struct HeapBuf_Object
Definition: HeapBuf.h:410
Interface to heap functions.
void HeapBuf_Params_init(HeapBuf_Params *prms)
Initialize the HeapBuf_Params structure with default values.
HeapBuf_Handle HeapBuf_construct(HeapBuf_Struct *obj, const HeapBuf_Params *params, Error_Block *eb)
Construct a HeapBuf heap.
Memory heap statistics.
Definition: Memory.h:94
IHeap_Object iheap
Definition: HeapBuf.h:330
size_t align
Alignment (in MAUs) of each block.
Definition: HeapBuf.h:364
void HeapBuf_destruct(HeapBuf_Struct *obj)
Destruct a HeapBuf heap.
HeapBuf_Handle HeapBuf_create(const HeapBuf_Params *params, Error_Block *eb)
Create a HeapBuf heap.
Stat structure for the HeapBuf_getExtendedStats function.
Definition: HeapBuf.h:237
void HeapBuf_getStats(HeapBuf_Handle heap, Memory_Stats *statBuf)
This function returns state information for a HeapBuf.
Definition: HeapBuf.h:253
© Copyright 1995-2022, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale