21 #include "pedigree/kernel/machine/Machine.h" 22 #include "pedigree/kernel/processor/PhysicalMemoryManager.h" 23 #include "pedigree/kernel/processor/VirtualAddressSpace.h" 25 ArmBeagleSerial::ArmBeagleSerial() : m_Base(0), m_BaseRegion(
"beagle-uart")
29 ArmBeagleSerial::~ArmBeagleSerial()
47 reinterpret_cast<volatile uint8_t *
>(m_BaseRegion.virtualAddress());
53 if (!setFifoDefaults())
60 if (!configureProtocol())
67 if (!disableFlowControl())
80 uint8_t intStatus = m_Base[IIR_REG];
81 switch ((intStatus >> 1) & 0x1F)
86 uint8_t c = m_Base[MSR_REG];
97 while (m_Base[LSR_REG] & 0x1)
112 uint8_t c = m_Base[RHR_REG];
130 char ArmBeagleSerial::read()
135 while (!(m_Base[LSR_REG] & 0x1))
137 return m_Base[RHR_REG];
143 char ArmBeagleSerial::readNonBlock()
148 if (!(m_Base[LSR_REG] & 0x1))
150 return m_Base[RHR_REG];
156 void ArmBeagleSerial::write(
char c)
161 while (!(m_Base[LSR_REG] & 0x20))
178 m_Base[SYSC_REG] |= 0x2;
181 while (!(m_Base[SYSS_REG] & 0x1))
193 unsigned char old_lcr_reg = m_Base[LCR_REG];
194 m_Base[LCR_REG] = 0xBF;
197 unsigned char efr_reg = m_Base[EFR_REG];
198 unsigned char old_enhanced_en = efr_reg & 0x8;
199 if (!(efr_reg & 0x8))
201 m_Base[EFR_REG] = efr_reg;
204 m_Base[LCR_REG] = 0x80;
207 unsigned char mcr_reg = m_Base[MCR_REG];
208 unsigned char old_tcl_tlr = mcr_reg & 0x20;
209 if (!(mcr_reg & 0x20))
211 m_Base[MCR_REG] = mcr_reg;
219 m_Base[LCR_REG] = 0xBF;
229 if (!old_enhanced_en)
230 m_Base[EFR_REG] = m_Base[EFR_REG] ^ 0x8;
233 m_Base[LCR_REG] = 0x80;
237 m_Base[MCR_REG] = m_Base[MCR_REG] ^ 0x20;
240 m_Base[LCR_REG] = old_lcr_reg;
253 m_Base[MDR1_REG] = (m_Base[MDR1_REG] & ~0x7) | 0x7;
256 m_Base[LCR_REG] = 0xBF;
259 unsigned char efr_reg = m_Base[EFR_REG];
260 unsigned char old_enhanced_en = efr_reg & 0x8;
261 if (!(efr_reg & 0x8))
263 m_Base[EFR_REG] = efr_reg;
272 m_Base[LCR_REG] = 0xBF;
286 m_Base[LCR_REG] = 0xBF;
290 m_Base[EFR_REG] = m_Base[EFR_REG] ^ 0x8;
294 m_Base[LCR_REG] = 0x3;
297 m_Base[MDR1_REG] = 0;
310 unsigned char old_lcr_reg = m_Base[LCR_REG];
311 m_Base[LCR_REG] = 0x80;
314 unsigned char mcr_reg = m_Base[MCR_REG];
315 unsigned char old_tcl_tlr = mcr_reg & 0x20;
316 if (!(mcr_reg & 0x20))
318 m_Base[MCR_REG] = mcr_reg;
321 m_Base[LCR_REG] = 0xBF;
324 unsigned char efr_reg = m_Base[EFR_REG];
325 unsigned char old_enhanced_en = efr_reg & 0x8;
326 if (!(efr_reg & 0x8))
328 m_Base[EFR_REG] = efr_reg;
338 m_Base[LCR_REG] = 0x80;
342 m_Base[MCR_REG] = m_Base[MCR_REG] ^ 0x20;
345 m_Base[LCR_REG] = old_lcr_reg;
virtual bool registerInterruptHandler(size_t nInterruptNumber, InterruptHandler *pHandler)=0
static PhysicalMemoryManager & instance()
static const size_t continuous
void softReset()
Perform a software reset of this UART.
virtual void interrupt(size_t nInterruptNumber, InterruptState &state)
bool setFifoDefaults()
Reset the FIFOs and DMA to default values.
static const size_t Write
static const size_t KernelMode
virtual void setBase(uintptr_t nBaseAddr)
bool disableFlowControl()
Disables hardware flow control on the UART.
static InterruptManager & instance()