1 /*
2  * Copyright 2017, NXP
3  * All rights reserved.
4  *
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #include <FreeRTOS.h>
10 
11 #include "srtm_heap.h"
12 
13 /*******************************************************************************
14  * Definitions
15  ******************************************************************************/
16 #define SRTM_HEAP_STAT_COUNT_MASK (0x3FU)
17 
18 /*******************************************************************************
19  * Prototypes
20  ******************************************************************************/
21 
22 /*******************************************************************************
23  * Variables
24  ******************************************************************************/
25 #ifdef SRTM_DEBUG_MESSAGE_FUNC
26 static uint32_t count;
27 #endif
28 
29 /*******************************************************************************
30  * Code
31  ******************************************************************************/
SRTM_Heap_Malloc(uint32_t size)32 void *SRTM_Heap_Malloc(uint32_t size)
33 {
34 #ifdef SRTM_DEBUG_MESSAGE_FUNC
35     size_t freeSize, minFreeSize;
36 
37     if (((++count) & SRTM_HEAP_STAT_COUNT_MASK) == 0U)
38     {
39         freeSize    = xPortGetFreeHeapSize();
40         minFreeSize = xPortGetMinimumEverFreeHeapSize();
41         SRTM_DEBUG_MESSAGE(SRTM_DEBUG_VERBOSE_INFO, "#### Heap free space 0x%x, min 0x%x ####\r\n", freeSize,
42                            minFreeSize);
43     }
44 #endif
45     return pvPortMalloc(size);
46 }
47 
SRTM_Heap_Free(void * buf)48 void SRTM_Heap_Free(void *buf)
49 {
50     vPortFree(buf);
51 }
52