10#if EFI_PROD_CODE || EFI_SIMULATOR
12#ifndef MCU_HAS_CCM_RAM
13 #define MCU_HAS_CCM_RAM FALSE
17 #define LUA_EXTRA_HEAP 0
20#if (LUA_EXTRA_HEAP > 0)
22 #ifdef EFI_HAS_EXT_SDRAM
33 uint8_t* m_buffer =
nullptr;
35 void* alloc(
size_t n) {
36 if (m_buffer && m_size) {
37 return chHeapAlloc(&m_heap, n);
43 void free(
void* obj) {
48 template<
size_t TSize>
49 Heap(uint8_t (&
buffer)[TSize])
60 criticalAssertVoid(used() == 0,
"Too late to init Lua heap: already in use");
78 size_t lagestFree = 0;
79 chHeapStatus(&m_heap, &heapFree, &lagestFree);
81 return m_size - heapFree;
86 if (m_buffer && m_size) {
87 chHeapObjectInit(&m_heap, m_buffer, m_size);
94#if (LUA_EXTRA_HEAP > 0)
114#if !defined(EFI_IS_F42x)
121 extern uint8_t __ram3_base__[];
122 extern uint8_t __ram3_end__[];
130 extern uint8_t __heap_ccm_base__[];
131 extern uint8_t __heap_ccm_end__[];
132 luaCcmHeap.init(__heap_ccm_base__, __heap_ccm_end__ - __heap_ccm_base__);
139 void *nptr =
nullptr;
144 #if (LUA_EXTRA_HEAP > 0)
145 if (nptr ==
nullptr) {
150 if (nptr ==
nullptr) {
155 if (nptr ==
nullptr) {
162 if (nptr ==
nullptr) {
163 nptr = chHeapAlloc(NULL, nsize);
173 if (nptr !=
nullptr) {
174 memcpy(nptr, optr, chHeapGetSize(optr) > nsize ? nsize : chHeapGetSize(optr));
195#if (LUA_EXTRA_HEAP > 0)
208#if CH_CFG_MEMCORE_SIZE == 0
216 #if CH_CFG_MEMCORE_SIZE == 0
223 #if (LUA_EXTRA_HEAP > 0)
236 float pct = 100.0f * memoryUsed / totalHeapSize;
237 efiPrintf(
"Lua total heap(s) usage: %d / %d bytes = %.1f%%", memoryUsed, totalHeapSize, pct);
239 efiPrintf(
"No heap available for Lua");
242 #if (LUA_EXTRA_HEAP > 0)
252 size_t chHeapFree = 0;
253 chHeapStatus(NULL, &chHeapFree, NULL);
255 size_t chMemCoreUsed = chMemTotal - chCoreGetStatusX() - chHeapFree;
256 efiPrintf(
"Common ChibiOS heap: %d bytes free", chHeapFree);
257 efiPrintf(
"ChibiOS memcore usage: %d / %d", chMemCoreUsed, chMemTotal);
262void*
luaHeapAlloc(
void* ,
void* ptr,
size_t ,
size_t nsize) {
272 return realloc(ptr, nsize);
TunerStudioOutputChannels outputChannels
static EngineAccessor engine
static constexpr engine_configuration_s * engineConfiguration
static Heap luaExtraHeap(luaExtraHeapArea)
CH_HEAP_AREA(luaExtraHeapArea, LUA_EXTRA_HEAP) SDRAM_OPTIONAL
static size_t luaMemoryUsed
void * luaHeapAlloc(void *, void *optr, size_t osize, size_t nsize)
static Heap luaOptionalHeap
static BigBufferHandle buffer