From 74125fc19e0ce05838c7766f4dfd2969cabbdd94 Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Mon, 7 Feb 2022 09:48:12 -0800 Subject: [PATCH] Take more RAM, but cap it. --- ueforth/Makefile | 2 -- ueforth/esp32/config.h | 16 ---------------- ueforth/esp32/main.cpp | 10 +++++++--- ueforth/esp32/options.h | 4 ++++ ueforth/esp32/sim_main.cpp | 10 +++++----- ueforth/esp32/template.ino | 1 - 6 files changed, 16 insertions(+), 27 deletions(-) delete mode 100644 ueforth/esp32/config.h diff --git a/ueforth/Makefile b/ueforth/Makefile index 9cf526f..bf0dfad 100644 --- a/ueforth/Makefile +++ b/ueforth/Makefile @@ -387,7 +387,6 @@ ESP32_PARTS = tools/replace.js \ common/calling.h \ common/core.h \ common/interp.h \ - esp32/config.h \ esp32/options.h \ esp32/builtins.h \ esp32/builtins.cpp \ @@ -398,7 +397,6 @@ $(ESP32)/ESP32forth/ESP32forth.ino: $(ESP32_PARTS) | $(ESP32)/ESP32forth cat esp32/template.ino | tools/replace.js \ VERSION=$(VERSION) \ REVISION=$(REVISION) \ - config=@esp32/config.h \ opcodes=@common/opcodes.h \ extra_opcodes=@common/extra_opcodes.h \ calling=@common/calling.h \ diff --git a/ueforth/esp32/config.h b/ueforth/esp32/config.h deleted file mode 100644 index bb6f8d9..0000000 --- a/ueforth/esp32/config.h +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2022 Bradley D. Nelson -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#define STACK_CELLS 512 -#define INTERRUPT_STACK_CELLS 64 diff --git a/ueforth/esp32/main.cpp b/ueforth/esp32/main.cpp index bde5894..a8a1656 100644 --- a/ueforth/esp32/main.cpp +++ b/ueforth/esp32/main.cpp @@ -13,9 +13,13 @@ // limitations under the License. void setup() { - cell_t hs = heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL); - cell_t *heap = (cell_t *) malloc(hs); - forth_init(0, 0, heap, hs, boot, sizeof(boot)); + cell_t fh = heap_caps_get_free_size(MALLOC_CAP_INTERNAL); + cell_t hc = heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL); + if (fh - hc < MINIMUM_FREE_SYSTEM_HEAP) { + hc = fh - MINIMUM_FREE_SYSTEM_HEAP; + } + cell_t *heap = (cell_t *) malloc(hc); + forth_init(0, 0, heap, hc, boot, sizeof(boot)); } void loop() { diff --git a/ueforth/esp32/options.h b/ueforth/esp32/options.h index 5fd5f76..ba324d0 100644 --- a/ueforth/esp32/options.h +++ b/ueforth/esp32/options.h @@ -12,6 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. +#define STACK_CELLS 512 +#define INTERRUPT_STACK_CELLS 64 +#define MINIMUM_FREE_SYSTEM_HEAP (64 * 1024) + // Default on several options. #define ENABLE_SPIFFS_SUPPORT #define ENABLE_WIFI_SUPPORT diff --git a/ueforth/esp32/sim_main.cpp b/ueforth/esp32/sim_main.cpp index 7f89c1e..099e9c0 100644 --- a/ueforth/esp32/sim_main.cpp +++ b/ueforth/esp32/sim_main.cpp @@ -12,15 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -#define SIM_HEAP_SIZE (100 * 1024 + 1024 * 1024) -#define STACK_CELLS 512 - #include "esp32/options.h" #include "common/opcodes.h" #include "common/extra_opcodes.h" #include "common/floats.h" #include "common/calling.h" +#define SIM_HEAP_SIZE (100 * 1024 + 1024 * 1024) + static cell_t *simulated(cell_t *sp, const char *op); #define PLATFORM_OPCODE_LIST \ @@ -33,8 +32,9 @@ static cell_t *simulated(cell_t *sp, const char *op); PLATFORM_SIMULATED_OPCODE_LIST #undef XV -#define MALLOC_CAP_INTERNAL SIM_HEAP_SIZE -#define heap_caps_get_largest_free_block(x) (x) +#define MALLOC_CAP_INTERNAL 0 +#define heap_caps_get_largest_free_block(x) SIM_HEAP_SIZE +#define heap_caps_get_free_size(x) SIM_HEAP_SIZE #include "common/core.h" #include "common/interp.h" diff --git a/ueforth/esp32/template.ino b/ueforth/esp32/template.ino index 090afa9..0a57b44 100644 --- a/ueforth/esp32/template.ino +++ b/ueforth/esp32/template.ino @@ -19,7 +19,6 @@ * Revision: {{REVISION}} */ -{{config}} {{options}} {{opcodes}} {{extra_opcodes}}