6 #include <satcat5/port_mailbox.h>
12 static const unsigned MAX_SEGMENT = 256;
15 static const u32 ETHCMD_NOOP = (0x00u << 24);
16 static const u32 ETHCMD_WRNEXT = (0x02u << 24);
17 static const u32 ETHCMD_WRFINAL = (0x03u << 24);
18 static const u32 ETHCMD_RESET = (0xFFu << 24);
20 static const u32 ETHREG_DVALID = (1u << 31);
21 static const u32 ETHREG_DFINAL = (1u << 30);
22 static const u32 ETHREG_ERROR = (1u << 29);
23 static const u32 ETHREG_DMASK = (0xFFu);
26 : satcat5::io::BufferedIO(
27 m_txbuff, SATCAT5_MAILBOX_BUFFSIZE, SATCAT5_MAILBOX_BUFFPKT,
28 m_rxbuff, SATCAT5_MAILBOX_BUFFSIZE, SATCAT5_MAILBOX_BUFFPKT)
29 , satcat5::cfg::Interrupt(cfg)
30 , m_hw_reg(cfg->get_register(devaddr, regaddr))
33 *m_hw_reg = ETHCMD_RESET;
39 while (copy_tx_segment()) {}
42 u32 Mailbox::copy_tx_segment()
55 if (seg > MAX_SEGMENT) seg = MAX_SEGMENT;
63 for (
unsigned a = 0 ; a < seg-1 ; ++a)
64 *m_hw_reg = ETHCMD_WRNEXT | src[a];
65 *m_hw_reg = ETHCMD_WRFINAL | src[seg-1];
69 for (
unsigned a = 0 ; a < seg ; ++a)
70 *m_hw_reg = ETHCMD_WRNEXT | src[a];
76 u32 Mailbox::copy_rx_segment()
85 if (!rem)
return ETHREG_ERROR;
88 if (rem > MAX_SEGMENT) rem = MAX_SEGMENT;
92 while ((rem) && (reg & ETHREG_DVALID)) {
94 *dst = (u8)(reg & ETHREG_DMASK);
97 if (reg & ETHREG_DFINAL)
break;
99 if (rem) reg = *m_hw_reg;
105 if (reg & ETHREG_DFINAL)
117 u32 reg = copy_rx_segment();
120 if (reg & ETHREG_ERROR) {
121 while (reg & (ETHREG_DVALID | ETHREG_ERROR))
satcat5::io::PacketBuffer m_tx
Transmit data (user writes, child reads)
satcat5::io::PacketBuffer m_rx
Receive data (user reads, child writes)
const u8 * peek(unsigned nbytes) const
Peek nbytes into the circular buffer.
unsigned get_peek_ready() const
Find the longest available contiguous segment that can be requested by peek().
bool write_finalize() override
Mark end of frame and release temporary working data.
void zcw_write(unsigned nbytes)
Zero-copy write (zcw) mode, required for UART interface.
unsigned get_read_ready() const override
How many bytes can be read without blocking?
bool read_consume(unsigned nbytes) override
Read and discard 0 or more bytes.
unsigned zcw_maxlen() const
Max contiguous write length (ZCW).
void write_abort() override
If possible, abort the current partially-written packet.
void read_finalize() override
Consume any remaining bytes in this frame, if applicable.
u8 * zcw_start()
Pointer to a contiguous buffer (ZCW).
Abstract API for reading byte-streams and packets.
Driver for the internal "MailBox" Ethernet port This class interfaces with "port_axi_mailbox" through...
void data_rcvd(satcat5::io::Readable *src) override
The data_rcvd() callback is polled whenever data is available.
void irq_event() override
Interrupt service routine.