From 01e0ce5b86e1cb8278edde7ae1d78523bb10994d Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Tue, 22 Mar 2022 11:34:32 +0100 Subject: [PATCH] removed console telnet interface & adapted ESP32 console --- ESP32/console.cpp | 1 + ESP32/console.h | 1 + ESP32/console_esp32.cpp | 36 ++++++++ ESP32/console_esp32.h | 18 ++++ ESP32/main.ino | 177 ++++++---------------------------------- ESP32/platformio.ini | 2 +- tty.cpp | 21 ----- tty.h | 8 -- 8 files changed, 80 insertions(+), 184 deletions(-) create mode 120000 ESP32/console.cpp create mode 120000 ESP32/console.h create mode 100644 ESP32/console_esp32.cpp create mode 100644 ESP32/console_esp32.h diff --git a/ESP32/console.cpp b/ESP32/console.cpp new file mode 120000 index 0000000..1e29138 --- /dev/null +++ b/ESP32/console.cpp @@ -0,0 +1 @@ +../console.cpp \ No newline at end of file diff --git a/ESP32/console.h b/ESP32/console.h new file mode 120000 index 0000000..e323210 --- /dev/null +++ b/ESP32/console.h @@ -0,0 +1 @@ +../console.h \ No newline at end of file diff --git a/ESP32/console_esp32.cpp b/ESP32/console_esp32.cpp new file mode 100644 index 0000000..27fd0e7 --- /dev/null +++ b/ESP32/console_esp32.cpp @@ -0,0 +1,36 @@ +#include +#include +#include + +#include "console_esp32.h" +#include "error.h" + + +console_esp32::console_esp32(std::atomic_bool *const terminate) : console(terminate) +{ +} + +console_esp32::~console_esp32() +{ +} + +int console_esp32::wait_for_char(const int timeout) +{ + for(int i=0; i + +#include "console.h" + + +class console_esp32 : public console +{ +protected: + int wait_for_char(const int timeout) override; + +public: + console_esp32(std::atomic_bool *const terminate); + virtual ~console_esp32(); + + void put_char(const char c) override; + + void resize_terminal() override; +}; diff --git a/ESP32/main.ino b/ESP32/main.ino index d500889..e4e665f 100644 --- a/ESP32/main.ino +++ b/ESP32/main.ino @@ -10,6 +10,7 @@ #include #include +#include "console_esp32.h" #include "cpu.h" #include "error.h" #include "esp32.h" @@ -20,9 +21,10 @@ #define NEOPIXELS_PIN 25 -bus *b = nullptr; -cpu *c = nullptr; -tty *tty_ = nullptr; +bus *b = nullptr; +cpu *c = nullptr; +tty *tty_ = nullptr; +console *cnsl = nullptr; uint32_t event = 0; @@ -30,11 +32,12 @@ uint16_t exec_addr = 0; uint32_t start_ts = 0; -std::atomic_bool running { false }; -std::atomic_bool on_wifi { false }; -std::atomic_bool console_telnet_clients { false }; -std::atomic_bool disk_read_activity { false }; -std::atomic_bool disk_write_activity { false }; +std::atomic_bool terminate { false }; + +std::atomic_bool running { false }; +std::atomic_bool on_wifi { false }; +std::atomic_bool disk_read_activity { false }; +std::atomic_bool disk_write_activity { false }; void setBootLoader(bus *const b) { cpu *const c = b->getCpu(); @@ -134,145 +137,9 @@ void panel(void *p) { } } -SemaphoreHandle_t terminal_mutex = xSemaphoreCreateMutex(); - -constexpr int terminal_columns = 80; -constexpr int terminal_rows = 25; -char terminal[terminal_columns * terminal_rows]; -uint8_t tx = 0, ty = terminal_rows - 1; -QueueHandle_t to_telnet_queue = xQueueCreate(10, sizeof(char)); - -void delete_first_line() { - memmove(&terminal[0], &terminal[terminal_columns], terminal_columns * (terminal_rows - 1)); - memset(&terminal[terminal_columns * (terminal_rows - 1)], ' ', terminal_columns); -} - -void telnet_terminal(void *p) { - bus *const b = reinterpret_cast(p); - tty *const tty_ = b->getTty(); - - Serial.println(F("telnet_terminal task started")); - - if (!tty_) - Serial.println(F(" *** NO TTY ***")); - - for(;;) { - char cc { 0 }; - - xQueueReceive(tty_->getTerminalQueue(), &cc, portMAX_DELAY); - - Serial.print(cc); - - // update terminal buffer - xSemaphoreTake(terminal_mutex, portMAX_DELAY); - - if (cc == 13) - tx = 0; - else if (cc == 10) - ty++; - else { - terminal[ty * terminal_columns + tx] = cc; - - tx++; - - if (tx == terminal_columns) - tx = 0, ty++; - } - - if (ty == terminal_rows) { - delete_first_line(); - ty--; - } - - xSemaphoreGive(terminal_mutex); - - // pass through to telnet clients - if (xQueueSend(to_telnet_queue, &cc, portMAX_DELAY) != pdTRUE) - Serial.println(F("queue TTY character failed")); - } -} - -void wifi(void *p) { - Serial.println(F("wifi task started")); - - int fd = socket(AF_INET, SOCK_STREAM, 0); - - struct sockaddr_in server { 0 }; - server.sin_family = AF_INET; - server.sin_addr.s_addr = INADDR_ANY; - server.sin_port = htons(23); - - if (bind(fd, (struct sockaddr *)&server, sizeof(server)) == -1) - Serial.println(F("bind failed")); - - if (listen(fd, 3) == -1) - Serial.println(F("listen failed")); - - struct pollfd fds[] = { { fd, POLLIN, 0 } }; - - std::vector clients; - - for(;;) { - on_wifi = WiFi.status() == WL_CONNECTED; - - int rc = poll(fds, 1, 10); - - if (rc == 1) { - int client = accept(fd, nullptr, nullptr); - if (client != -1) { - clients.push_back(client); - - constexpr const uint8_t dont_auth[] = { 0xff, 0xf4, 0x25, // don't auth - 0xff, 0xfb, 0x03, // suppress goahead - 0xff, 0xfe, 0x22, // don't line-mode - 0xff, 0xfe, 0x27, // don't new envt0 - 0xff, 0xfb, 0x01, // will echo - 0xff, 0xfe, 0x01, // don't echo - 0xff, 0xfd, 0x2d }; // no echo - - write(client, dont_auth, sizeof(dont_auth)); - - // send initial terminal stat - write(client, "\033[2J", 4); - - xSemaphoreTake(terminal_mutex, portMAX_DELAY); - - for(int y=0; ysetEmulateMFPT(true); + Serial.println(F("Init console")); + cnsl = new console_esp32(&terminate); + Serial.println(F("Init TTY")); - tty_ = new tty(poll_char, get_char, put_char); + tty_ = new tty(cnsl); Serial.println(F("Connect TTY to bus")); b->add_tty(tty_); @@ -356,12 +227,7 @@ void setup() { Serial.println(F(")")); xTaskCreatePinnedToCore(&panel, "panel", 2048, b, 1, nullptr, 0); - memset(terminal, ' ', sizeof(terminal)); - xTaskCreatePinnedToCore(&telnet_terminal, "telnet", 2048, b, 7, nullptr, 0); - - xTaskCreatePinnedToCore(&wifi, "wifi", 2048, b, 7, nullptr, 0); - - setup_wifi_stations(); + // setup_wifi_stations(); Serial.println(F("Load RK05")); b->add_rk05(new rk05("", b, &disk_read_activity, &disk_write_activity)); @@ -448,7 +314,7 @@ void loop() { c->step(); - if (event) { + if (event || terminate) { running = false; Serial.println(F("")); @@ -463,6 +329,9 @@ void loop() { start_ts = millis(); icount = 0; - running = true; + terminate = false; + event = 0; + + running = true; } } diff --git a/ESP32/platformio.ini b/ESP32/platformio.ini index fcc4e12..93ccaf2 100644 --- a/ESP32/platformio.ini +++ b/ESP32/platformio.ini @@ -16,5 +16,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=c++17 -Ofast -DESP32=1 build_unflags = -std=gnu++11 -Os diff --git a/tty.cpp b/tty.cpp index e028fbd..57efe8a 100644 --- a/tty.cpp +++ b/tty.cpp @@ -1,11 +1,6 @@ // (C) 2018 by Folkert van Heusden // // Released under Apache License v2.0 #include -#if defined(ESP32) -#include -#else -#include -#endif #include #include @@ -14,11 +9,6 @@ #include "memory.h" #include "utils.h" -#if !defined(ESP32) -#include "terminal.h" -extern NEWWIN *w_main; -#endif - const char * const regnames[] = { "reader status ", @@ -29,12 +19,6 @@ const char * const regnames[] = { tty::tty(console *const c) : c(c) { -#if defined(ESP32) - queue = xQueueCreate(10, sizeof(char)); - - if (queue == nullptr) - Serial.println(F("Problem creating TTY queue")); -#endif } tty::~tty() @@ -117,12 +101,7 @@ void tty::writeWord(const uint16_t addr, uint16_t v) D(fprintf(stderr, "PDP11TTY print '%c'\n", ch);) -#if defined(ESP32) - if (xQueueSend(queue, &ch, portMAX_DELAY) != pdTRUE) - Serial.println(F("queue TTY character failed")); -#else c->put_char(ch); -#endif } D(fprintf(stderr, "set register %o to %o\n", addr, v);) diff --git a/tty.h b/tty.h index 41a5902..20d3d6f 100644 --- a/tty.h +++ b/tty.h @@ -27,18 +27,10 @@ private: uint16_t registers[4] { 0 }; bool withUI { false }; -#if defined(ESP32) - QueueHandle_t queue { nullptr }; -#endif - public: tty(console *const c); virtual ~tty(); -#if defined(ESP32) - QueueHandle_t & getTerminalQueue() { return queue; } -#endif - uint8_t readByte(const uint16_t addr); uint16_t readWord(const uint16_t addr);