From d6e0d0033bdeb7cb25e910ac1147689e695da14b Mon Sep 17 00:00:00 2001 From: Brad Nelson Date: Sun, 6 Feb 2022 20:48:27 -0800 Subject: [PATCH] Add better status, fix bug on device. --- ueforth/Makefile | 2 +- ueforth/common/boot.fs | 9 ++++++--- ueforth/common/forth_namespace_tests.fs | 12 ++++++------ ueforth/common/vocabulary.fs | 2 +- ueforth/esp32/bindings.fs | 2 ++ ueforth/esp32/builtins.h | 2 +- ueforth/esp32/platform.fs | 15 ++++++++++++++- ueforth/esp32/sim_main.cpp | 21 +++++++++++++++++++++ 8 files changed, 52 insertions(+), 13 deletions(-) diff --git a/ueforth/Makefile b/ueforth/Makefile index 6bc62a7..d2ad86a 100644 --- a/ueforth/Makefile +++ b/ueforth/Makefile @@ -205,7 +205,7 @@ $(GEN)/windows_boot.h: common/source_to_string.js $(WINDOWS_BOOT) | $(GEN) ESP32_BOOT = $(COMMON_PHASE1) \ esp32/allocation.fs \ $(COMMON_PHASE2) \ - esp32/platform.fs esp32/bindings.fs \ + esp32/bindings.fs esp32/platform.fs \ posix/httpd.fs posix/web_interface.fs esp32/web_interface.fs \ esp32/registers.fs esp32/timers.fs \ esp32/bterm.fs posix/telnetd.fs \ diff --git a/ueforth/common/boot.fs b/ueforth/common/boot.fs index b6039bd..9e9eb2c 100644 --- a/ueforth/common/boot.fs +++ b/ueforth/common/boot.fs @@ -189,8 +189,11 @@ create input-buffer input-limit allot : quit begin ['] evaluate-buffer catch if 0 state ! sp0 sp! fp0 fp! rp0 rp! ." ERROR" cr then prompt refill drop again ; +variable boot-prompt +: free. ( nf nu -- ) 2dup swap . ." free + " . ." used = " 2dup + . ." total (" + over + 100 -rot */ n. ." % free)" ; : raw-ok ." v{{VERSION}} - rev {{REVISION}}" cr - remaining . ." bytes heap free " - used . ." bytes dictionary used " - 'stack-cells @ cells . ." bytes x 3 stacks" cr + boot-prompt @ if boot-prompt @ execute then + ." Forth dictionary: " remaining used free. cr + ." 3 x Forth stacks: " 'stack-cells @ cells . ." bytes" cr prompt refill drop quit ; diff --git a/ueforth/common/forth_namespace_tests.fs b/ueforth/common/forth_namespace_tests.fs index c5def76..cfe7bba 100644 --- a/ueforth/common/forth_namespace_tests.fs +++ b/ueforth/common/forth_namespace_tests.fs @@ -555,7 +555,8 @@ e: test-esp32-forth-namespace out: FORTH ;e -e: check-esp32-basics +e: check-esp32-platform + out: ok out: LED out: OUTPUT out: INPUT @@ -567,6 +568,9 @@ e: check-esp32-basics out: duty out: adc out: pin + out: default-key? + out: default-key + out: default-type ;e e: check-esp32-builtins @@ -597,6 +601,7 @@ e: test-esp32-forth-namespace out: out: web-interface out: httpd + check-esp32-platform out: oled out: bluetooth out: rtos @@ -612,11 +617,6 @@ e: test-esp32-forth-namespace out: WiFi out: Wire out: ESP - out: ok - check-esp32-basics - out: default-key? - out: default-key - out: default-type check-phase2 check-allocation check-phase1 diff --git a/ueforth/common/vocabulary.fs b/ueforth/common/vocabulary.fs index c313a7b..ccfe07e 100644 --- a/ueforth/common/vocabulary.fs +++ b/ueforth/common/vocabulary.fs @@ -56,7 +56,7 @@ transfer{ (do) (?do) (+loop) parse-quote digit $@ raw.s tib-setup input-limit - [SKIP] [SKIP]' raw-ok + [SKIP] [SKIP]' raw-ok boot-prompt free. $place zplace BUILTIN_MARK }transfer forth definitions diff --git a/ueforth/esp32/bindings.fs b/ueforth/esp32/bindings.fs index 9c3d627..a726907 100644 --- a/ueforth/esp32/bindings.fs +++ b/ueforth/esp32/bindings.fs @@ -16,6 +16,8 @@ vocabulary ESP ESP definitions transfer ESP-builtins +only forth definitions + forth definitions vocabulary Wire Wire definitions diff --git a/ueforth/esp32/builtins.h b/ueforth/esp32/builtins.h index ffb751d..20b17b1 100644 --- a/ueforth/esp32/builtins.h +++ b/ueforth/esp32/builtins.h @@ -74,7 +74,7 @@ static cell_t ResizeFile(cell_t fd, cell_t size); YV(ESP, getChipModel, PUSH ESP.getChipModel()) \ YV(ESP, getChipCores, PUSH ESP.getChipCores()) \ YV(ESP, getFlashChipSize, PUSH ESP.getFlashChipSize()) \ - YV(ESP, getCPUFreqMHz, PUSH ESP.getCPUFreqMHz()) \ + YV(ESP, getCpuFreqMHz, PUSH ESP.getCpuFreqMHz()) \ YV(ESP, getSketchSize, PUSH ESP.getSketchSize()) \ YV(ESP, deepSleep, ESP.deepSleep(tos); DROP) diff --git a/ueforth/esp32/platform.fs b/ueforth/esp32/platform.fs index 0012d09..de0bcfd 100644 --- a/ueforth/esp32/platform.fs +++ b/ueforth/esp32/platform.fs @@ -20,7 +20,7 @@ yield-task start-task forth definitions ( Set up Basic I/O ) -internals definitions +internals definitions also serial : esp32-bye 0 terminate ; : serial-type ( a n -- ) Serial.write drop ; : serial-key ( -- n ) @@ -36,6 +36,8 @@ also forth definitions ' esp32-bye is bye only forth definitions +also ledc also serial also SPIFFS + ( Map Arduino / ESP32 things to shorter names. ) : pin ( n pin# -- ) swap digitalWrite ; : adc ( n -- n ) analogRead ; @@ -61,5 +63,16 @@ only forth definitions led OUTPUT pinMode high led pin +internals definitions also ESP +: esp32-stats + getChipModel z>s type ." " + getCpuFreqMHz . ." MHz " + getChipCores . ." cores " + getFlashChipSize . ." bytes flash" cr + ." System Heap: " getFreeHeap getHeapSize free. cr + ." " getMaxAllocHeap . ." bytes max contiguous" cr ; +' esp32-stats internals boot-prompt ! +only forth definitions + ( Setup entry ) internals : ok ." ESP32forth" raw-ok ; forth diff --git a/ueforth/esp32/sim_main.cpp b/ueforth/esp32/sim_main.cpp index e13d682..7f89c1e 100644 --- a/ueforth/esp32/sim_main.cpp +++ b/ueforth/esp32/sim_main.cpp @@ -121,6 +121,27 @@ static cell_t *simulated(cell_t *sp, const char *op) { cell_t ret = close(*sp); *sp = ret ? errno : 0; return sp; + } else if (op == STR_getChipModel) { + *++sp = (cell_t) "FAKE-ESP32"; + return sp; + } else if (op == STR_getCpuFreqMHz) { + *++sp = 240; + return sp; + } else if (op == STR_getChipCores) { + *++sp = 2; + return sp; + } else if (op == STR_getFlashChipSize) { + *++sp = 4 * 1024 * 1024; + return sp; + } else if (op == STR_getFreeHeap) { + *++sp = 90000; + return sp; + } else if (op == STR_getHeapSize) { + *++sp = 320 * 1024; + return sp; + } else if (op == STR_getMaxAllocHeap) { + *++sp = 80 * 1024; + return sp; } else { fprintf(stderr, "MISSING SIM OPCODE: %s\n", op); exit(1);