POC works
This commit is contained in:
parent
803914cceb
commit
a15dcc47c0
8 changed files with 39 additions and 58 deletions
|
@ -100,20 +100,20 @@ void delete_first_line() {
|
|||
|
||||
void telnet_terminal(void *p) {
|
||||
bus *const b = reinterpret_cast<bus *>(p);
|
||||
tty *const tty_ = b->getTty();
|
||||
|
||||
Serial.println(F("telnet_terminal task started"));
|
||||
|
||||
if (!tty_)
|
||||
Serial.println(F(" *** NO TTY ***"));
|
||||
|
||||
for(;;) {
|
||||
char c { 0 };
|
||||
|
||||
xQueueReceive(b->getTerminalQueue(), &c, portMAX_DELAY);
|
||||
|
||||
Serial.println(F("queue recv"));
|
||||
xQueueReceive(tty_->getTerminalQueue(), &c, portMAX_DELAY);
|
||||
|
||||
xSemaphoreTake(terminal_mutex, portMAX_DELAY);
|
||||
|
||||
Serial.println(F("got mutex"));
|
||||
|
||||
if (c == 13 || c == 10) {
|
||||
tx = 0;
|
||||
|
||||
|
@ -141,8 +141,6 @@ void telnet_terminal(void *p) {
|
|||
|
||||
xSemaphoreGive(terminal_mutex);
|
||||
|
||||
Serial.println(F("notify task"));
|
||||
|
||||
xTaskNotify(wifi_task, 0, eNoAction);
|
||||
}
|
||||
}
|
||||
|
@ -181,14 +179,17 @@ void wifi(void *p) {
|
|||
if (xTaskNotifyWait(0, 0, &ulNotifiedValue, 100 / portMAX_DELAY) != pdTRUE)
|
||||
continue;
|
||||
|
||||
Serial.println(F("got notification"));
|
||||
|
||||
xSemaphoreTake(terminal_mutex, portMAX_DELAY);
|
||||
|
||||
Serial.println(F("send to clients"));
|
||||
std::string out = "\033[2J";
|
||||
|
||||
for(int y=0; y<25; y++)
|
||||
out += format("\033[%dH", y + 1) + std::string(&terminal[y][0], 80);
|
||||
|
||||
xSemaphoreGive(terminal_mutex);
|
||||
|
||||
for(size_t i=0; i<clients.size(); i++) {
|
||||
if (write(clients.at(i), terminal, 80 * 25) == -1) {
|
||||
if (write(clients.at(i), out.c_str(), out.size()) == -1) {
|
||||
close(clients.at(i));
|
||||
clients.erase(clients.begin() + i);
|
||||
}
|
||||
|
@ -196,10 +197,6 @@ void wifi(void *p) {
|
|||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
xSemaphoreGive(terminal_mutex);
|
||||
|
||||
Serial.println(F("send to clients"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -282,12 +279,12 @@ void setup() {
|
|||
Serial.print(F("Starting panel (on CPU 0, main emulator runs on CPU "));
|
||||
Serial.print(xPortGetCoreID());
|
||||
Serial.println(F(")"));
|
||||
xTaskCreatePinnedToCore(&panel, "panel", 2048, b, 5, nullptr, 0);
|
||||
xTaskCreatePinnedToCore(&panel, "panel", 2048, b, 1, nullptr, 0);
|
||||
|
||||
memset(terminal, ' ', sizeof(terminal));
|
||||
xTaskCreatePinnedToCore(&telnet_terminal, "telnet", 2048, b, 5, nullptr, 0);
|
||||
xTaskCreatePinnedToCore(&telnet_terminal, "telnet", 2048, b, 7, nullptr, 0);
|
||||
|
||||
xTaskCreatePinnedToCore(&wifi, "wifi", 2048, b, 5, &wifi_task, 0);
|
||||
xTaskCreatePinnedToCore(&wifi, "wifi", 2048, b, 7, &wifi_task, 0);
|
||||
|
||||
setup_wifi_stations();
|
||||
|
||||
|
|
26
bus.cpp
26
bus.cpp
|
@ -1,8 +1,5 @@
|
|||
// (C) 2018 by Folkert van Heusden
|
||||
// Released under Apache License v2.0
|
||||
#if defined(ESP32)
|
||||
#include <Arduino.h>
|
||||
#endif
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
@ -31,10 +28,6 @@ bus::bus() : c(nullptr), tm11(nullptr), rk05_(nullptr), rx02_(nullptr), tty_(nul
|
|||
}
|
||||
|
||||
CPUERR = MMR2 = MMR3 = PIR = CSR = 0;
|
||||
|
||||
#if defined(ESP32)
|
||||
queue = xQueueCreate(10, sizeof(char));
|
||||
#endif
|
||||
}
|
||||
|
||||
bus::~bus()
|
||||
|
@ -437,25 +430,6 @@ uint16_t bus::write(const uint16_t a, const bool word_mode, uint16_t value, cons
|
|||
return 128;
|
||||
}
|
||||
|
||||
if (a == 0177566) { // console tty buffer register
|
||||
D(fprintf(stderr, "bus::write TTY buffer %d / %c\n", value, value);)
|
||||
|
||||
if (value) {
|
||||
#if defined(ESP32)
|
||||
char c = value & 127;
|
||||
|
||||
Serial.print(c);
|
||||
|
||||
if (xQueueSend(queue, &c, portMAX_DELAY) != pdTRUE)
|
||||
Serial.println(F("queue fail"));
|
||||
#else
|
||||
printf("%c", value & 127);
|
||||
#endif
|
||||
}
|
||||
|
||||
return 128;
|
||||
}
|
||||
|
||||
if (a & 1)
|
||||
D(fprintf(stderr, "bus::writeWord: odd address UNHANDLED\n");)
|
||||
D(fprintf(stderr, "UNHANDLED write %o(%c): %o\n", a, word_mode ? 'B' : ' ', value);)
|
||||
|
|
10
bus.h
10
bus.h
|
@ -33,10 +33,6 @@ private:
|
|||
|
||||
uint16_t MMR2 { 0 }, MMR3 { 0 }, CPUERR { 0 }, PIR { 0 }, CSR { 0 };
|
||||
|
||||
#if defined(ESP32)
|
||||
QueueHandle_t queue { nullptr };
|
||||
#endif
|
||||
|
||||
public:
|
||||
bus();
|
||||
~bus();
|
||||
|
@ -49,11 +45,9 @@ public:
|
|||
void add_rx02(rx02 *rx02_) { this -> rx02_ = rx02_; }
|
||||
void add_tty(tty *tty_) { this -> tty_ = tty_; }
|
||||
|
||||
cpu *getCpu() { return this -> c; }
|
||||
cpu *getCpu() { return this->c; }
|
||||
|
||||
#if defined(ESP32)
|
||||
QueueHandle_t & getTerminalQueue() { return queue; }
|
||||
#endif
|
||||
tty *getTty() { return this->tty_; }
|
||||
|
||||
uint16_t read(const uint16_t a, const bool word_mode, const bool use_prev=false);
|
||||
uint16_t readByte(const uint16_t a) { return read(a, true); }
|
||||
|
|
14
tty.cpp
14
tty.cpp
|
@ -29,6 +29,13 @@ const char * const regnames[] = {
|
|||
tty::tty(const bool withUI) : withUI(withUI)
|
||||
{
|
||||
memset(registers, 0x00, sizeof registers);
|
||||
|
||||
#if defined(ESP32)
|
||||
queue = xQueueCreate(10, sizeof(char));
|
||||
|
||||
if (queue == nullptr)
|
||||
Serial.println(F("Problem creating TTY queue"));
|
||||
#endif
|
||||
}
|
||||
|
||||
tty::~tty()
|
||||
|
@ -103,7 +110,12 @@ void tty::writeWord(const uint16_t addr, uint16_t v)
|
|||
v &= 127;
|
||||
|
||||
#if defined(ESP32)
|
||||
Serial.print(char(v));
|
||||
char c = v & 127;
|
||||
|
||||
Serial.print(c);
|
||||
|
||||
if (xQueueSend(queue, &c, portMAX_DELAY) != pdTRUE)
|
||||
Serial.println(F("queue TTY character failed"));
|
||||
#else
|
||||
FILE *tf = fopen("tty.dat", "a+");
|
||||
if (tf) {
|
||||
|
|
BIN
tty.dat
Normal file
BIN
tty.dat
Normal file
Binary file not shown.
10
tty.h
10
tty.h
|
@ -1,4 +1,4 @@
|
|||
// (C) 2018 by Folkert van Heusden
|
||||
// (C) 2018-2022 by Folkert van Heusden
|
||||
// Released under Apache License v2.0
|
||||
#pragma once
|
||||
|
||||
|
@ -22,12 +22,20 @@ private:
|
|||
bool testMode { false }, withUI { false };
|
||||
char c { 0 };
|
||||
|
||||
#if defined(ESP32)
|
||||
QueueHandle_t queue { nullptr };
|
||||
#endif
|
||||
|
||||
public:
|
||||
tty(const bool withUI);
|
||||
virtual ~tty();
|
||||
|
||||
void setTest() { testMode = true; }
|
||||
|
||||
#if defined(ESP32)
|
||||
QueueHandle_t & getTerminalQueue() { return queue; }
|
||||
#endif
|
||||
|
||||
void sendChar(const char v);
|
||||
|
||||
uint8_t readByte(const uint16_t addr);
|
||||
|
|
|
@ -18,7 +18,6 @@ void setBit(uint16_t & v, const int bit, const bool vb)
|
|||
v |= mask;
|
||||
}
|
||||
|
||||
#if !defined(ESP32)
|
||||
std::string format(const char *const fmt, ...)
|
||||
{
|
||||
char *buffer = nullptr;
|
||||
|
@ -33,7 +32,6 @@ std::string format(const char *const fmt, ...)
|
|||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
unsigned long get_ms()
|
||||
{
|
||||
|
|
2
utils.h
2
utils.h
|
@ -8,7 +8,5 @@ int parity(int v);
|
|||
|
||||
#define sign(a) ( ( (a) < 0 ) ? -1 : ( (a) > 0 ) )
|
||||
|
||||
#if !defined(ESP32)
|
||||
std::string format(const char *const fmt, ...);
|
||||
#endif
|
||||
unsigned long get_ms();
|
||||
|
|
Loading…
Add table
Reference in a new issue