forked from tenstorrent/whisper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Uartsf.hpp
43 lines (30 loc) · 967 Bytes
/
Uartsf.hpp
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
#pragma once
#include <thread>
#include <atomic>
#include <mutex>
#include <vector>
#include "IoDevice.hpp"
namespace WdRiscv
{
class Uartsf : public IoDevice
{
public:
Uartsf(uint64_t addr, uint64_t size);
~Uartsf() override;
uint32_t read(uint64_t addr) override;
void write(uint64_t addr, uint32_t value) override;
private:
/// This runs in its own thread. It monitors the standard input and
/// marks interrupt pending when input is possible placing the input
/// character in byte_ for the Uart to consume.
void monitorStdin();
enum RegId { TX_FIFO, RX_FIFO, TX_CTRL, RX_CTRL, IE, IP, DIV, N };
const uint32_t RX_EMPTY = 0x80000000;
const uint32_t TX_EN = 1;
const uint32_t RX_EN = 1;
std::vector<uint32_t> regs_; // Indexed by RegId
std::thread stdinThread_;
std::atomic<bool> terminate_ = false;
std::mutex mutex_; // Synchronize access to byte_ with stdinThread_.
};
}