We have working runtime RAM detection - we shall use it for Lua #3970

This commit is contained in:
rusefillc 2022-03-27 19:39:28 -04:00
parent 0a0345b754
commit 3d8c40da58
1 changed files with 15 additions and 1 deletions

View File

@ -33,7 +33,7 @@ public:
memory_heap_t m_heap;
size_t m_memoryUsed = 0;
const size_t m_size;
size_t m_size;
void* alloc(size_t n) {
return chHeapAlloc(&m_heap, n);
@ -51,6 +51,12 @@ public:
chHeapObjectInit(&m_heap, buffer, TSize);
}
void reinit(char *buffer, size_t m_size) {
efiAssertVoid(OBD_PCM_Processor_Fault, m_memoryUsed == 0, "Too late to reinit Lua heap");
chHeapObjectInit(&m_heap, buffer, m_size);
this->m_size = m_size;
}
void* realloc(void* ptr, size_t osize, size_t nsize) {
if (nsize == 0) {
// requested size is zero, free if necessary and return nullptr
@ -363,6 +369,14 @@ static LuaThread luaThread;
#endif
void startLua() {
#if HW_MICRO_RUSEFI && defined(STM32F4)
// cute hack: let's check at runtime if you are a lucky owner of microRusEFI with extra RAM and use that extra RAM for extra Lua
if (isStm32F42x()) {
char *buffer = (char *)0x20020000;
heaps[0].reinit(buffer, 60000);
}
#endif
#if LUA_USER_HEAP > 1
#if EFI_CAN_SUPPORT
initLuaCanRx();