-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdc11.h
70 lines (51 loc) · 1.82 KB
/
dc11.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// (C) 2024 by Folkert van Heusden
// Released under MIT license
#pragma once
#include <atomic>
#include <condition_variable>
#include <cstdint>
#include <mutex>
#include <thread>
#include <vector>
#include "comm.h"
#include "device.h"
#include "gen.h"
#include "bus.h"
#include "log.h"
#define DC11_RCSR 0174000 // receiver status register
#define DC11_BASE DC11_RCSR
#define DC11_END (DC11_BASE + (4 * 4 + 1) * 2) // 4 interfaces, + 2 to point behind it
class bus;
// 4 interfaces
constexpr const int dc11_n_lines = 4;
class dc11: public device
{
private:
bus *const b { nullptr };
uint16_t registers[4 * dc11_n_lines] { 0 };
std::atomic_bool stop_flag { false };
std::thread *th { nullptr };
std::vector<comm *> comm_interfaces;
std::vector<bool > connected;
std::vector<char> recv_buffers[dc11_n_lines];
mutable std::mutex input_lock [dc11_n_lines];
void trigger_interrupt(const int line_nr, const bool is_tx);
bool is_rx_interrupt_enabled(const int line_nr) const;
bool is_tx_interrupt_enabled(const int line_nr) const;
public:
dc11(bus *const b, const std::vector<comm *> & comm_interfaces);
virtual ~dc11();
bool begin();
JsonDocument serialize() const;
static dc11 *deserialize(const JsonVariantConst j, bus *const b);
std::vector<comm *> *get_comm_interfaces() { return &comm_interfaces; }
void reset() override;
void show_state(console *const cnsl) const override;
void test_port(const size_t port_nr, const std::string & txt) const;
void test_ports(const std::string & txt) const;
uint8_t read_byte(const uint16_t addr) override;
uint16_t read_word(const uint16_t addr) override;
void write_byte(const uint16_t addr, const uint8_t v) override;
void write_word(const uint16_t addr, const uint16_t v) override;
void operator()();
};