not working; sd becomes flaky
This commit is contained in:
parent
5ac576a0ac
commit
7c46665576
7 changed files with 236 additions and 27 deletions
28
ESP32/esp32.cpp
Normal file
28
ESP32/esp32.cpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
#include <Arduino.h>
|
||||
|
||||
std::string read_terminal_line(const std::string & prompt)
|
||||
{
|
||||
Serial.print(prompt.c_str());
|
||||
Serial.print(F(">"));
|
||||
|
||||
std::string str;
|
||||
|
||||
for(;;) {
|
||||
if (Serial.available()) {
|
||||
char c = Serial.read();
|
||||
|
||||
if (c == 13 || c == 10)
|
||||
break;
|
||||
|
||||
if (c >= 32 && c < 127) {
|
||||
str += c;
|
||||
|
||||
Serial.print(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Serial.println(F(""));
|
||||
|
||||
return str;
|
||||
}
|
3
ESP32/esp32.h
Normal file
3
ESP32/esp32.h
Normal file
|
@ -0,0 +1,3 @@
|
|||
#include <string>
|
||||
|
||||
std::string read_terminal_line(const std::string & prompt);
|
191
ESP32/main.ino
191
ESP32/main.ino
|
@ -1,14 +1,20 @@
|
|||
// (C) 2018-2022 by Folkert van Heusden
|
||||
// Released under Apache License v2.0
|
||||
#include <FastLED.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <WiFi.h>
|
||||
#include <sys/poll.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "memory.h"
|
||||
#include "cpu.h"
|
||||
#include "error.h"
|
||||
#include "esp32.h"
|
||||
#include "memory.h"
|
||||
#include "tty.h"
|
||||
#include "utils.h"
|
||||
#include "error.h"
|
||||
|
||||
|
||||
#define NEOPIXELS_PIN 25
|
||||
|
@ -44,6 +50,8 @@ void setBootLoader(bus *const b) {
|
|||
}
|
||||
|
||||
void panel(void *p) {
|
||||
Serial.println(F("panel task started"));
|
||||
|
||||
bus *const b = reinterpret_cast<bus *>(p);
|
||||
cpu *const c = b->getCpu();
|
||||
|
||||
|
@ -78,6 +86,168 @@ void panel(void *p) {
|
|||
}
|
||||
}
|
||||
|
||||
SemaphoreHandle_t terminal_mutex = xSemaphoreCreateMutex();
|
||||
|
||||
TaskHandle_t wifi_task { nullptr };
|
||||
|
||||
char terminal[25][80];
|
||||
uint8_t tx = 0, ty = 0;
|
||||
|
||||
void delete_first_line() {
|
||||
memmove(&terminal[0][0], &terminal[1][0], sizeof(terminal[1]));
|
||||
memset(&terminal[24][0], ' ', sizeof(terminal[24]));
|
||||
}
|
||||
|
||||
void telnet_terminal(void *p) {
|
||||
bus *const b = reinterpret_cast<bus *>(p);
|
||||
|
||||
Serial.println(F("telnet_terminal task started"));
|
||||
|
||||
for(;;) {
|
||||
char c { 0 };
|
||||
|
||||
xQueueReceive(b->getTerminalQueue(), &c, portMAX_DELAY);
|
||||
|
||||
Serial.println(F("queue recv"));
|
||||
|
||||
xSemaphoreTake(terminal_mutex, portMAX_DELAY);
|
||||
|
||||
Serial.println(F("got mutex"));
|
||||
|
||||
if (c == 13 || c == 10) {
|
||||
tx = 0;
|
||||
|
||||
ty++;
|
||||
if (ty == 25) {
|
||||
delete_first_line();
|
||||
ty--;
|
||||
}
|
||||
}
|
||||
else {
|
||||
terminal[ty][tx] = c;
|
||||
|
||||
tx++;
|
||||
|
||||
if (tx == 80) {
|
||||
tx = 0;
|
||||
|
||||
ty++;
|
||||
if (ty == 25) {
|
||||
delete_first_line();
|
||||
ty--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xSemaphoreGive(terminal_mutex);
|
||||
|
||||
Serial.println(F("notify task"));
|
||||
|
||||
xTaskNotify(wifi_task, 0, eNoAction);
|
||||
}
|
||||
}
|
||||
|
||||
void wifi(void *p) {
|
||||
Serial.println(F("wifi task started"));
|
||||
|
||||
uint32_t ulNotifiedValue = 0;
|
||||
|
||||
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<int> clients;
|
||||
|
||||
for(;;) {
|
||||
int rc = poll(fds, 1, 10);
|
||||
|
||||
if (rc == 1) {
|
||||
int client = accept(fd, nullptr, nullptr);
|
||||
if (client != -1)
|
||||
clients.push_back(client);
|
||||
}
|
||||
|
||||
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"));
|
||||
|
||||
for(size_t i=0; i<clients.size(); i++) {
|
||||
if (write(clients.at(i), terminal, 80 * 25) == -1) {
|
||||
close(clients.at(i));
|
||||
clients.erase(clients.begin() + i);
|
||||
}
|
||||
else {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
xSemaphoreGive(terminal_mutex);
|
||||
|
||||
Serial.println(F("send to clients"));
|
||||
}
|
||||
}
|
||||
|
||||
void setup_wifi_stations()
|
||||
{
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
WiFi.softAP("PDP-11 KEK", nullptr, 5, 0, 4);
|
||||
|
||||
#if 0
|
||||
Serial.println(F("Scanning for WiFi access points..."));
|
||||
|
||||
int n = WiFi.scanNetworks();
|
||||
|
||||
Serial.println(F("scan done"));
|
||||
|
||||
if (n == 0)
|
||||
Serial.println(F("no networks found"));
|
||||
else {
|
||||
for (int i = 0; i < n; ++i) {
|
||||
// Print SSID and RSSI for each network found
|
||||
Serial.print(i + 1);
|
||||
Serial.print(F(": "));
|
||||
Serial.print(WiFi.SSID(i));
|
||||
Serial.print(F(" ("));
|
||||
Serial.print(WiFi.RSSI(i));
|
||||
Serial.print(F(")"));
|
||||
Serial.println(WiFi.encryptionType(i) == WIFI_AUTH_OPEN ? " " : "*");
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
std::string ssid = read_terminal_line("SSID: ");
|
||||
std::string password = read_terminal_line("password: ");
|
||||
WiFi.begin(ssid.c_str(), password.c_str());
|
||||
#else
|
||||
WiFi.begin("www.vanheusden.com", "Ditiseentest31415926");
|
||||
#endif
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
Serial.print('.');
|
||||
|
||||
delay(250);
|
||||
}
|
||||
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
|
@ -108,6 +278,18 @@ void setup() {
|
|||
Serial.println(F("Connect TTY to bus"));
|
||||
b->add_tty(tty_);
|
||||
|
||||
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);
|
||||
|
||||
memset(terminal, ' ', sizeof(terminal));
|
||||
xTaskCreatePinnedToCore(&telnet_terminal, "telnet", 2048, b, 5, nullptr, 0);
|
||||
|
||||
xTaskCreatePinnedToCore(&wifi, "wifi", 2048, b, 5, &wifi_task, 0);
|
||||
|
||||
setup_wifi_stations();
|
||||
|
||||
Serial.println(F("Load RK05"));
|
||||
b->add_rk05(new rk05("", b));
|
||||
setBootLoader(b);
|
||||
|
@ -119,11 +301,6 @@ void setup() {
|
|||
|
||||
Serial.flush();
|
||||
|
||||
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);
|
||||
|
||||
Serial.println(F("Press <enter> to start"));
|
||||
|
||||
for(;;) {
|
||||
|
|
|
@ -16,5 +16,5 @@ monitor_speed = 115200
|
|||
upload_speed = 1000000
|
||||
lib_deps = greiman/SdFat@^2.1.2
|
||||
fastled/FastLED@^3.5.0
|
||||
build_flags = -std=c++14 -Ofast -DESP32=1
|
||||
build_flags = -std=gnu++17 -Ofast -DESP32=1
|
||||
build_unflags = -std=gnu++11 -Os
|
||||
|
|
11
bus.cpp
11
bus.cpp
|
@ -31,6 +31,10 @@ 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()
|
||||
|
@ -438,7 +442,12 @@ uint16_t bus::write(const uint16_t a, const bool word_mode, uint16_t value, cons
|
|||
|
||||
if (value) {
|
||||
#if defined(ESP32)
|
||||
Serial.print(char(value & 127));
|
||||
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
|
||||
|
|
8
bus.h
8
bus.h
|
@ -33,6 +33,10 @@ private:
|
|||
|
||||
uint16_t MMR2 { 0 }, MMR3 { 0 }, CPUERR { 0 }, PIR { 0 }, CSR { 0 };
|
||||
|
||||
#if defined(ESP32)
|
||||
QueueHandle_t queue { nullptr };
|
||||
#endif
|
||||
|
||||
public:
|
||||
bus();
|
||||
~bus();
|
||||
|
@ -47,6 +51,10 @@ public:
|
|||
|
||||
cpu *getCpu() { return this -> c; }
|
||||
|
||||
#if defined(ESP32)
|
||||
QueueHandle_t & getTerminalQueue() { return queue; }
|
||||
#endif
|
||||
|
||||
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); }
|
||||
uint16_t readWord(const uint16_t a);
|
||||
|
|
20
rk05.cpp
20
rk05.cpp
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "bus.h"
|
||||
#include "error.h"
|
||||
#include "esp32.h"
|
||||
#include "gen.h"
|
||||
#include "rk05.h"
|
||||
#include "utils.h"
|
||||
|
@ -42,27 +43,10 @@ rk05::rk05(const std::string & file, bus *const b) : b(b)
|
|||
|
||||
sd.ls("/", LS_DATE | LS_SIZE | LS_R);
|
||||
|
||||
std::string selected_file;
|
||||
|
||||
while(Serial.available())
|
||||
Serial.read();
|
||||
|
||||
Serial.print(F("Enter filename: "));
|
||||
|
||||
for(;;) {
|
||||
if (Serial.available()) {
|
||||
char c = Serial.read();
|
||||
|
||||
if (c == 13 || c == 10)
|
||||
break;
|
||||
|
||||
if (c >= 32 && c < 127) {
|
||||
selected_file += c;
|
||||
|
||||
Serial.print(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
std::string selected_file = read_terminal_line("Enter filename: ");
|
||||
|
||||
Serial.print(F("Opening file: "));
|
||||
Serial.println(selected_file.c_str());
|
||||
|
|
Loading…
Add table
Reference in a new issue