6 #include <satcat5/cfgbus_hdlc.h>
14 static const unsigned REGADDR_IRQ = 0;
15 static const unsigned REGADDR_CFG = 1;
16 static const unsigned REGADDR_STATUS = 2;
17 static const unsigned REGADDR_DATA = 3;
20 static const u32 CMD_EOF = 0x0100u;
23 static const u32 MS_DVALID = (1u << 8);
24 static const u32 MS_RD_READY = (1u << 0);
25 static const u32 MS_CMD_FULL = (1u << 1);
28 : BufferedIO(m_txbuff, SATCAT5_HDLC_BUFFSIZE, SATCAT5_HDLC_MAXPKT,
29 m_rxbuff, SATCAT5_HDLC_BUFFSIZE, 0)
31 , m_ctrl(cfg->get_register(devaddr))
43 u32 clkdiv = div_round_u32(clkref_hz, baud_hz);
44 m_ctrl[REGADDR_CFG] = (frame_bytes << 16) | (clkdiv);
50 while (m_tx_eof || rdy) {
52 u32 status = m_ctrl[REGADDR_STATUS];
53 if (status & MS_CMD_FULL)
break;
55 m_ctrl[REGADDR_DATA] = CMD_EOF;
58 m_ctrl[REGADDR_DATA] = src->
read_u8();
59 if (--rdy == 0) { m_tx_eof =
true; }
74 u32 data = m_ctrl[REGADDR_DATA];
75 if (data & MS_DVALID) {
76 u8
byte = (u8)(data & 0xFF);
Interface driver for the cfgbus_hdlc block.
void irq_event()
Interrupt service routine.
void configure(unsigned clkref_hz, unsigned baud_hz, unsigned frame_bytes=0)
Configure the HDLC driver.
void timer_event()
Child class MUST override this method.
void data_rcvd(satcat5::io::Readable *src)
The data_rcvd() callback is polled whenever data is available.
Event-handler for individual ConfigBus interrupts.
satcat5::io::PacketBuffer m_rx
Receive data (user reads, child writes)
bool write_finalize() override
Mark end of frame and release temporary working data.
Abstract API for reading byte-streams and packets.
u8 read_u8()
One of many functions for reading integer/floating point values, see details.
virtual void read_finalize()
Consume any remaining bytes in this frame, if applicable.
virtual unsigned get_read_ready() const =0
How many bytes can be read without blocking?
void write_u8(u8 data)
One of many functions for writing integer/floating point values, see details.
void timer_stop()
Stop all future notifications.
void timer_every(unsigned msec)
Configure a repeating notification every X milliseconds.
Core event-processing loop for SatCat5 software.
Miscellaneous mathematical utility functions.
constexpr u32 div_round_u32(u32 a, u32 b)
Integer division functions with various rounding options: