forked from tenstorrent/whisper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUart8250.hpp
49 lines (36 loc) · 1.22 KB
/
Uart8250.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
44
45
46
47
48
49
#pragma once
#include <thread>
#include <atomic>
#include <mutex>
#include "IoDevice.hpp"
namespace WdRiscv
{
class Uart8250 : public IoDevice
{
public:
Uart8250(uint64_t addr, uint64_t size);
~Uart8250() 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 consme.
void monitorStdin();
uint32_t byte_ = 0; // Pending input byte.
uint8_t ier_ = 0; // Interrupt enable
uint8_t iir_ = 1; // Interrupt id
uint8_t lcr_ = 0; // Line control
uint8_t mcr_ = 0; // Modem control
uint8_t lsr_ = 0x60; // Line satus
uint8_t msr_ = 0; // Modem status
uint8_t scr_ = 0; // Scratch
uint8_t fcr_ = 0; // Fifo control
uint8_t dll_ = 0x1; // Divisor latch lsb
uint8_t dlm_ = 0x1; // Divisor latch msb
uint8_t psd_ = 0; // Pre-scaler division
std::thread stdinThread_;
std::atomic<bool> terminate_ = false;
std::mutex mutex_; // Synchronize access to byte_ with stdinThread_.
};
}