console::wait_char could wake-up by spurious wake-ups and thus crash as input_buffer was empty sometimes

This commit is contained in:
folkert van heusden 2022-04-11 23:40:30 +02:00
parent ab268f5ca6
commit f6c1c1440e
5 changed files with 34 additions and 38 deletions

8
ESP32/esp32.h Normal file
View file

@ -0,0 +1,8 @@
#pragma once
#if defined(ESP32)
#include <SPI.h>
#define USE_SDFAT
#define SD_FAT_TYPE 1
#include <SdFat.h>
#endif

View file

@ -9,16 +9,10 @@
#include <sys/socket.h>
#include <sys/types.h>
#if defined(ESP32)
#include <SPI.h>
#define USE_SDFAT
#define SD_FAT_TYPE 1
#include <SdFat.h>
#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<console *>(c);
cnsl->panel_update_thread();
}
void console_thread_wrapper_io(void *const c)
{
console *const cnsl = reinterpret_cast<console *>(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++;

View file

@ -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

View file

@ -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,12 +71,14 @@ 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) {
if (input_buffer.empty() == false) {
int c = input_buffer.at(0);
input_buffer.erase(input_buffer.begin() + 0);
return c;
}
}
return -1;
}

6
rk05.h
View file

@ -9,12 +9,10 @@
#include <vector>
#if defined(ESP32)
#include <SPI.h>
#define USE_SDFAT
#define SD_FAT_TYPE 1
#include <SdFat.h>
#include "esp32.h"
#endif
// FIXME namen van defines
#define RK05_DS 0177400 // drive status
#define RK05_ERROR 0177402 // error