/* * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 *//* ... */#pragmaonce#ifdefMULTI_HEAP_FREERTOS#include"freertos/FreeRTOS.h"#include"sdkconfig.h"#include"esp_rom_sys.h"#include<assert.h>typedefportMUX_TYPEmulti_heap_lock_t;/* Because malloc/free can happen inside an ISR context, we need to use portmux spinlocks here not RTOS mutexes *//* ... */#defineMULTI_HEAP_LOCK(PLOCK)do{\if((PLOCK)!=NULL){\portENTER_CRITICAL_SAFE((PLOCK));\}{...}\}{...}while(0)...#defineMULTI_HEAP_UNLOCK(PLOCK)do{\if((PLOCK)!=NULL){\portEXIT_CRITICAL_SAFE((PLOCK));\}{...}\}{...}while(0)...#defineMULTI_HEAP_LOCK_INIT(PLOCK)do{\portMUX_INITIALIZE((PLOCK));\}{...}while(0)...#defineMULTI_HEAP_LOCK_STATIC_INITIALIZERportMUX_INITIALIZER_UNLOCKED/* Not safe to use std i/o while in a portmux critical section, can deadlock, so we use the ROM equivalent functions. *//* ... */#defineMULTI_HEAP_PRINTFesp_rom_printf#defineMULTI_HEAP_STDERR_PRINTF(MSG,...)esp_rom_printf(MSG,__VA_ARGS__)6 definesinlinestaticvoidmulti_heap_assert(boolcondition,constchar*format,intline,intptr_taddress){/* Can't use libc assert() here as it calls printf() which can cause another malloc() for a newlib lock. Also, it's useful to be able to print the memory address where corruption was detected. *//* ... */#ifndefNDEBUGif(!condition){#ifndefCONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENTesp_rom_printf(format,line,address);#endif// CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_SILENTabort();}{...}#else/* ... */// NDEBUG(void)condition;#endif// NDEBUG}{ ... }#defineMULTI_HEAP_ASSERT(CONDITION,ADDRESS)\multi_heap_assert((CONDITION),"CORRUPT HEAP: multi_heap.c:%d detected at 0x%08x\n",\__LINE__,(intptr_t)(ADDRESS))...#ifdefCONFIG_HEAP_TASK_TRACKING#include<freertos/task.h>#defineMULTI_HEAP_SET_BLOCK_OWNER(HEAD)*((TaskHandle_t*)HEAD)=xTaskGetCurrentTaskHandle()#defineMULTI_HEAP_GET_BLOCK_OWNER(HEAD)*((TaskHandle_t*)HEAD)#defineMULTI_HEAP_ADD_BLOCK_OWNER_OFFSET(HEAD)((TaskHandle_t*)(HEAD)+1)#defineMULTI_HEAP_REMOVE_BLOCK_OWNER_OFFSET(HEAD)((TaskHandle_t*)(HEAD)-1)#defineMULTI_HEAP_ADD_BLOCK_OWNER_SIZE(SIZE)((SIZE)+sizeof(TaskHandle_t))#defineMULTI_HEAP_REMOVE_BLOCK_OWNER_SIZE(SIZE)((SIZE)-sizeof(TaskHandle_t))#defineMULTI_HEAP_BLOCK_OWNER_SIZE()sizeof(TaskHandle_t)7 defines/* ... */#else#defineMULTI_HEAP_SET_BLOCK_OWNER(HEAD)#defineMULTI_HEAP_GET_BLOCK_OWNER(HEAD)(NULL)#defineMULTI_HEAP_ADD_BLOCK_OWNER_OFFSET(HEAD)(HEAD)#defineMULTI_HEAP_REMOVE_BLOCK_OWNER_OFFSET(HEAD)(HEAD)#defineMULTI_HEAP_ADD_BLOCK_OWNER_SIZE(SIZE)(SIZE)#defineMULTI_HEAP_REMOVE_BLOCK_OWNER_SIZE(SIZE)(SIZE)#defineMULTI_HEAP_BLOCK_OWNER_SIZE()0/* ... */#endif// CONFIG_HEAP_TASK_TRACKING/* ... */#else// MULTI_HEAP_FREERTOS#include<assert.h>#defineMULTI_HEAP_PRINTFprintf#defineMULTI_HEAP_STDERR_PRINTF(MSG,...)fprintf(stderr,MSG,__VA_ARGS__)#defineMULTI_HEAP_LOCK(PLOCK)(void)(PLOCK)#defineMULTI_HEAP_UNLOCK(PLOCK)(void)(PLOCK)#defineMULTI_HEAP_LOCK_INIT(PLOCK)(void)(PLOCK)#defineMULTI_HEAP_LOCK_STATIC_INITIALIZER0#defineMULTI_HEAP_ASSERT(CONDITION,ADDRESS)assert((CONDITION)&&"Heap corrupt")#defineMULTI_HEAP_BLOCK_OWNER#defineMULTI_HEAP_SET_BLOCK_OWNER(HEAD)#defineMULTI_HEAP_GET_BLOCK_OWNER(HEAD)(NULL)10 defines/* ... */#endif// MULTI_HEAP_FREERTOS
Details
Show: from
Types: Columns:
All items filtered out
All items filtered out
This file uses the notable symbols shown below. Click anywhere in the file to view more details.