Blame


1 6efd408f 2023-03-01 continue // uart_virt.cc
2 6efd408f 2023-03-01 continue // QEMU `virt` generic virtual platform
3 6efd408f 2023-03-01 continue
4 6efd408f 2023-03-01 continue
5 6efd408f 2023-03-01 continue #include <hw.h>
6 6efd408f 2023-03-01 continue #include <uart.h>
7 6efd408f 2023-03-01 continue #include <pl011.h>
8 6efd408f 2023-03-01 continue
9 6efd408f 2023-03-01 continue
10 6efd408f 2023-03-01 continue namespace Board {
11 6efd408f 2023-03-01 continue namespace Uart {
12 6efd408f 2023-03-01 continue
13 6efd408f 2023-03-01 continue
14 6efd408f 2023-03-01 continue namespace {
15 6efd408f 2023-03-01 continue
16 3be3b31b 2023-03-02 continue constexpr uintptr_t UART_BASE = 0x9000000;
17 6efd408f 2023-03-01 continue
18 6efd408f 2023-03-01 continue } // anonymous namespace
19 6efd408f 2023-03-01 continue
20 6efd408f 2023-03-01 continue
21 6efd408f 2023-03-01 continue void initialize()
22 6efd408f 2023-03-01 continue {
23 6efd408f 2023-03-01 continue Pl011::ControlRegister ControlRegister;
24 6efd408f 2023-03-01 continue ControlRegister.m_u.m_Bits.m_UartEnable = 1;
25 6efd408f 2023-03-01 continue ControlRegister.m_u.m_Bits.m_TransmitEnable = 1;
26 6efd408f 2023-03-01 continue Hw::write32(UART_BASE + Pl011::CONTROL_REGISTER, ControlRegister.m_u.m_nValue);
27 6efd408f 2023-03-01 continue }
28 6efd408f 2023-03-01 continue
29 6efd408f 2023-03-01 continue
30 6efd408f 2023-03-01 continue void send(uint8_t nValue)
31 6efd408f 2023-03-01 continue {
32 6efd408f 2023-03-01 continue // spin while fifo is full
33 6efd408f 2023-03-01 continue for (; ; )
34 6efd408f 2023-03-01 continue {
35 6efd408f 2023-03-01 continue Pl011::FlagRegister FlagRegister{Hw::read32(UART_BASE + Pl011::FLAG_REGISTER)};
36 6efd408f 2023-03-01 continue if (!FlagRegister.m_u.m_Bits.m_TransmitFifoFull)
37 6efd408f 2023-03-01 continue break;
38 6efd408f 2023-03-01 continue }
39 6efd408f 2023-03-01 continue Hw::write32(UART_BASE + Pl011::DATA_REGISTER, nValue);
40 6efd408f 2023-03-01 continue }
41 6efd408f 2023-03-01 continue
42 6efd408f 2023-03-01 continue
43 6efd408f 2023-03-01 continue uint8_t recv()
44 6efd408f 2023-03-01 continue {
45 6efd408f 2023-03-01 continue return 0;
46 6efd408f 2023-03-01 continue }
47 6efd408f 2023-03-01 continue
48 6efd408f 2023-03-01 continue
49 6efd408f 2023-03-01 continue } // namespace Uart
50 6efd408f 2023-03-01 continue } // namespace Board