6 #include <satcat5/cfgbus_uart.h>
9 namespace cfg = satcat5::cfg;
10 namespace util = satcat5::util;
13 static const unsigned REGADDR_IRQ = 0;
14 static const unsigned REGADDR_CFG = 1;
15 static const unsigned REGADDR_STATUS = 2;
16 static const unsigned REGADDR_DATA = 3;
19 static const u32 MS_DVALID = (1u << 8);
20 static const u32 MS_RD_READY = (1u << 0);
21 static const u32 MS_CMD_FULL = (1u << 1);
24 : io::BufferedIO(m_txbuff, SATCAT5_UART_BUFFSIZE, 0,
25 m_rxbuff, SATCAT5_UART_BUFFSIZE, 0)
26 , cfg::
Interrupt(cfg, devaddr, REGADDR_IRQ)
27 , m_ctrl(cfg->get_register(devaddr))
38 u32 clkdiv = util::div_round_u32(clkref_hz, baud_hz);
39 m_ctrl[REGADDR_CFG] = (ignore_cts << 31) | clkdiv;
45 while (m_tx.get_read_ready()) {
46 u32 status = m_ctrl[REGADDR_STATUS];
47 if (status & MS_CMD_FULL)
break;
48 m_ctrl[REGADDR_DATA] = m_tx.read_u8();
58 u32 data = m_ctrl[REGADDR_DATA];
59 if (data & MS_DVALID) {
60 u8
byte = (u8)(data & 0xFF);
69 if (nwrite) m_rx.write_finalize();
Event-handler for individual ConfigBus interrupts.
void irq_event()
Interrupt service routine.
void data_rcvd(satcat5::io::Readable *src)
The data_rcvd() callback is polled whenever data is available.
void configure(unsigned clkref_hz, unsigned baud_hz, bool ignore_cts=true)
Set baud rate and flow-control.
Uart(satcat5::cfg::ConfigBus *cfg, unsigned devaddr)
Initialize this UART and link to a specific register bank.
Abstract API for reading byte-streams and packets.
Miscellaneous mathematical utility functions.