From f6c1c1440ed8059510f8d5ac4b2773f728df1f02 Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Mon, 11 Apr 2022 23:40:30 +0200 Subject: [PATCH] console::wait_char could wake-up by spurious wake-ups and thus crash as input_buffer was empty sometimes --- ESP32/esp32.h | 8 ++++++++ ESP32/main.ino | 46 +++++++++++++++----------------------------- ESP32/platformio.ini | 2 +- console.cpp | 10 +++++++--- rk05.h | 6 ++---- 5 files changed, 34 insertions(+), 38 deletions(-) create mode 100644 ESP32/esp32.h diff --git a/ESP32/esp32.h b/ESP32/esp32.h new file mode 100644 index 0000000..6d8dbf0 --- /dev/null +++ b/ESP32/esp32.h @@ -0,0 +1,8 @@ +#pragma once + +#if defined(ESP32) +#include +#define USE_SDFAT +#define SD_FAT_TYPE 1 +#include +#endif diff --git a/ESP32/main.ino b/ESP32/main.ino index dba9fa0..d3a30c4 100644 --- a/ESP32/main.ino +++ b/ESP32/main.ino @@ -9,16 +9,10 @@ #include #include -#if defined(ESP32) -#include -#define USE_SDFAT -#define SD_FAT_TYPE 1 -#include -#endif - #include "console_esp32.h" #include "cpu.h" #include "error.h" +#include "esp32.h" #include "memory.h" #include "tty.h" #include "utils.h" @@ -67,13 +61,20 @@ void setBootLoader(bus *const b) { c->setRegister(7, offset); } -void console_thread_wrapper(void *const c) +void console_thread_wrapper_panel(void *const c) { console *const cnsl = reinterpret_cast(c); cnsl->panel_update_thread(); } +void console_thread_wrapper_io(void *const c) +{ + console *const cnsl = reinterpret_cast(c); + + cnsl->operator()(); +} + void setup_wifi_stations() { #if 0 @@ -198,12 +199,17 @@ void setup() { Serial.print(F("Starting panel (on CPU 0, main emulator runs on CPU ")); Serial.print(xPortGetCoreID()); Serial.println(F(")")); - xTaskCreatePinnedToCore(&console_thread_wrapper, "panel", 2048, cnsl, 1, nullptr, 0); + xTaskCreatePinnedToCore(&console_thread_wrapper_panel, "panel", 2048, cnsl, 1, nullptr, 0); + + xTaskCreatePinnedToCore(&console_thread_wrapper_io, "c-io", 2048, cnsl, 1, nullptr, 0); // setup_wifi_stations(); Serial.println(F("Load RK05")); - b->add_rk05(new rk05(select_disk_files(cnsl), b, cnsl->get_disk_read_activity_flag(), cnsl->get_disk_write_activity_flag())); + auto disk_files = select_disk_files(cnsl); + + b->add_rk05(new rk05(disk_files, b, cnsl->get_disk_read_activity_flag(), cnsl->get_disk_write_activity_flag())); + setBootLoader(b); Serial.print(F("Free RAM after init: ")); @@ -260,26 +266,6 @@ void dump_state(bus *const b) { Serial.println(t_diff); } -bool poll_char() -{ - return Serial.available() > 0; -} - -char get_char() -{ - char c = Serial.read(); - - if (c == 5) - dump_state(b); - - return c; -} - -void put_char(char c) -{ - Serial.print(c); -} - void loop() { icount++; diff --git a/ESP32/platformio.ini b/ESP32/platformio.ini index 7fa928b..ff9526f 100644 --- a/ESP32/platformio.ini +++ b/ESP32/platformio.ini @@ -12,5 +12,5 @@ monitor_speed = 115200 upload_speed = 1000000 lib_deps = greiman/SdFat@^2.1.2 adafruit/Adafruit NeoPixel@^1.10.4 -build_flags = -std=gnu++17 -Ofast -DESP32=1 +build_flags = -std=gnu++17 -Ofast -DESP32=1 -ggdb3 build_unflags = -std=gnu++11 -Os diff --git a/console.cpp b/console.cpp index 1751ec4..c176c48 100644 --- a/console.cpp +++ b/console.cpp @@ -26,7 +26,9 @@ void console::start_thread() { stop_thread_flag = false; +#if !defined(ESP32) th = new std::thread(std::ref(*this)); +#endif } void console::stop_thread() @@ -69,11 +71,13 @@ int console::wait_char(const int timeout_ms) using namespace std::chrono_literals; if (input_buffer.empty() == false || have_data.wait_for(lck, timeout_ms * 1ms) == std::cv_status::no_timeout) { - int c = input_buffer.at(0); + if (input_buffer.empty() == false) { + int c = input_buffer.at(0); - input_buffer.erase(input_buffer.begin() + 0); + input_buffer.erase(input_buffer.begin() + 0); - return c; + return c; + } } return -1; diff --git a/rk05.h b/rk05.h index 90ffb78..d794580 100644 --- a/rk05.h +++ b/rk05.h @@ -9,12 +9,10 @@ #include #if defined(ESP32) -#include -#define USE_SDFAT -#define SD_FAT_TYPE 1 -#include +#include "esp32.h" #endif + // FIXME namen van defines #define RK05_DS 0177400 // drive status #define RK05_ERROR 0177402 // error