From a982a3c9d920f5d66fb5517b17ed3e22ccca7ddf Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Tue, 30 Apr 2024 09:06:26 +0200 Subject: [PATCH] basic setup --- ESP32/dc11.cpp | 1 + ESP32/dc11.h | 1 + dc11.cpp | 106 ++++++++++++++++++++++++++++++++++++++++++++++++- dc11.h | 21 ++++++++-- main.cpp | 2 +- 5 files changed, 126 insertions(+), 5 deletions(-) create mode 120000 ESP32/dc11.cpp create mode 120000 ESP32/dc11.h diff --git a/ESP32/dc11.cpp b/ESP32/dc11.cpp new file mode 120000 index 0000000..0ccd621 --- /dev/null +++ b/ESP32/dc11.cpp @@ -0,0 +1 @@ +../dc11.cpp \ No newline at end of file diff --git a/ESP32/dc11.h b/ESP32/dc11.h new file mode 120000 index 0000000..78e0baa --- /dev/null +++ b/ESP32/dc11.h @@ -0,0 +1 @@ +../dc11.h \ No newline at end of file diff --git a/dc11.cpp b/dc11.cpp index 1a7dab0..ff8eacb 100644 --- a/dc11.cpp +++ b/dc11.cpp @@ -1,17 +1,121 @@ // (C) 2024 by Folkert van Heusden // Released under MIT license +#include +#include +#include +#include +#include + #include "bus.h" +#include "cpu.h" #include "dc11.h" +#include "log.h" -dc11::dc11(bus *const b): b(b) +dc11::dc11(const int base_port, bus *const b): + base_port(base_port), + b(b) { + th = new std::thread(std::ref(*this)); } dc11::~dc11() { stop_flag = true; + + if (th) { + th->join(); + delete th; + } +} + +void dc11::operator()() +{ + int fds[dc11_n_lines] = { }; + + pollfd pfds[8] = { }; + + for(int i=0; i(&listen_addr), sizeof(listen_addr)) == -1) { + close(pfds[i].fd); + fds[i] = -1; + + DOLOG(warning, true, "Cannot bind to port %d (DC11)", port); + } + + pfds[i].events = POLLIN; + + // client session + pfds[dc11_n_lines + i].fd = socket(AF_INET, SOCK_STREAM, 0); + pfds[dc11_n_lines + i].events = POLLIN; + } + + while(!stop_flag) { + int rc = poll(pfds, dc11_n_lines * 2, 100); + if (rc == 0) + continue; + + // accept any new session + for(int i=0; i lck(input_lock[line_nr]); + + for(int k=0; kgetCpu()->queue_interrupt(4, 0320 + line_nr * 4); + } + } + } + + for(int i=0; i +#include #include +#include +#include +#include #include "gen.h" #include "bus.h" @@ -15,16 +19,25 @@ class bus; +// 4 interfaces +constexpr const int dc11_n_lines = 4; + class dc11 { private: + int base_port { 1100 }; bus *const b { nullptr }; - // 4 interfaces - uint16_t registers[4 * 4] { }; + uint16_t registers[4 * dc11_n_lines] { }; std::atomic_bool stop_flag { false }; + std::thread *th { nullptr }; + + std::vector recv_buffers[dc11_n_lines]; + std::condition_variable have_data[dc11_n_lines]; + std::mutex input_lock[dc11_n_lines]; + public: - dc11(bus *const b); + dc11(const int base_port, bus *const b); virtual ~dc11(); #if IS_POSIX @@ -39,4 +52,6 @@ public: void write_byte(const uint16_t addr, const uint8_t v); void write_word(const uint16_t addr, uint16_t v); + + void operator()(); }; diff --git a/main.cpp b/main.cpp index f3fd5db..c085854 100644 --- a/main.cpp +++ b/main.cpp @@ -582,7 +582,7 @@ int main(int argc, char *argv[]) cnsl->begin(); // TODO - dc11 *dc11_ = new dc11(b); + dc11 *dc11_ = new dc11(1100, b); b->add_DC11(dc11_); running = cnsl->get_running_flag();