Blob


1 // uart_virt.cc
2 // QEMU `virt` generic virtual platform
5 #include <hw.h>
6 #include <uart.h>
7 #include <pl011.h>
10 namespace Board {
11 namespace Uart {
14 namespace {
16 constexpr uintptr_t UART_BASE = 0x9000000;
18 } // anonymous namespace
21 void initialize()
22 {
23 Pl011::ControlRegister ControlRegister;
24 ControlRegister.m_u.m_Bits.m_UartEnable = 1;
25 ControlRegister.m_u.m_Bits.m_TransmitEnable = 1;
26 ControlRegister.m_u.m_Bits.m_ReceiveEnable = 1;
27 Hw::write32(UART_BASE + Pl011::CONTROL_REGISTER, ControlRegister.m_u.m_nValue);
28 }
31 void send(uint8_t nValue)
32 {
33 // spin while fifo is full
34 for (; ; )
35 {
36 Pl011::FlagRegister FlagRegister{Hw::read32(UART_BASE + Pl011::FLAG_REGISTER)};
37 if (!FlagRegister.m_u.m_Bits.m_TransmitFifoFull)
38 break;
39 }
40 Hw::write32(UART_BASE + Pl011::DATA_REGISTER, nValue);
41 }
44 uint8_t recv()
45 {
46 for (; ; )
47 {
48 Pl011::FlagRegister FlagRegister{Hw::read32(UART_BASE + Pl011::FLAG_REGISTER)};
49 if (!FlagRegister.m_u.m_Bits.m_ReceiveFifoEmpty)
50 break;
51 }
52 return Hw::read32(UART_BASE + Pl011::DATA_REGISTER) & 0xff;
53 }
56 } // namespace Uart
57 } // namespace Board