47 #ifndef SATCAT5_MBUFF_CHUNK
48 #define SATCAT5_MBUFF_CHUNK (64 - sizeof(uintptr_t))
52 #ifndef SATCAT5_MBUFF_PKTLEN
53 #define SATCAT5_MBUFF_PKTLEN 2048
57 #ifndef SATCAT5_MBUFF_RXPKT
58 #define SATCAT5_MBUFF_RXPKT 32
62 #ifndef SATCAT5_MBUFF_TIMEOUT
63 #define SATCAT5_MBUFF_TIMEOUT 1500
67 #ifndef SATCAT5_MBUFF_USER
68 #define SATCAT5_MBUFF_USER 8
80 constexpr
MultiChunk() : m_next(0), m_data{0} {}
83 u8 m_data[SATCAT5_MBUFF_CHUNK];
144 bool read_bytes(
unsigned nbytes,
void* dst)
override;
177 void write_bytes(
unsigned nbytes,
const void* src)
override;
208 {
return m_free_bytes; }
245 unsigned m_free_bytes;
323 friend satcat5::util::ListCore;
344 {
return m_queue_count < SATCAT5_MBUFF_RXPKT; }
373 {
return m_heap_count < SATCAT5_MBUFF_RXPKT; }
376 bool consistency()
const;
387 u32 offset_priority(
unsigned idx)
const;
390 unsigned swap_index(
unsigned prev,
unsigned next);
414 { m_write_maxlen = max_bytes; }
420 void set_priority(u16 priority);
426 { m_write_timeout = timeout_msec; }
433 unsigned get_write_space()
const override;
434 void write_bytes(
unsigned nbytes,
const void* src)
override;
435 void write_abort()
override;
436 bool write_finalize()
override;
454 void write_next(u8 data)
override;
455 void write_overflow()
override;
459 unsigned write_prep();
491 bool write_finalize()
override;
Ephemeral Readable interface for a simple array.
A multi-source, multi-sink packet buffer.
void free_packet(satcat5::io::MultiPacket *packet)
Immediately free memory associated with this packet.
satcat5::io::MultiPacket * new_packet()
Memory allocation.
u16 get_pcount()
Current value of the packet counter.
satcat5::io::MultiChunk * new_chunk()
Memory allocation.
bool consistency() const
Internal consistency self-test (Optional).
MultiBuffer(u8 *buff, unsigned nbytes)
Configure this object and link to the working buffer.
void poll_demand() override
Deferred event handler, called after request().
virtual unsigned deliver(satcat5::io::MultiPacket *packet)
Deliver a complete packet to any number of output port(s).
satcat5::io::MultiPacket * dequeue()
Event handler for deferred packet delivery.
bool enqueue(satcat5::io::MultiPacket *packet)
Queue an incoming packet for deferred processing.
unsigned get_free_bytes() const
Query remaining buffer capacity.
Barebones class for overwriting contents of a MultiPacket.
void write_next(u8 data) override
Write the next byte to the underlying buffer or device.
satcat5::io::MultiChunk * m_write_chunk
Current write state.
void write_bytes(unsigned nbytes, const void *src) override
Write 0 or more bytes from a buffer.
unsigned m_write_rem
Current write state.
Overwriter(satcat5::io::MultiPacket *pkt)
Create a new Writer object.
unsigned write_count() const
Return total bytes written by this object.
unsigned m_write_pos
Current write state.
unsigned m_write_tot
Current write state.
unsigned get_write_space() const override
How many bytes can be written without blocking?
Barebones class for reading data from a MultiPacket.
unsigned m_read_pos
Current read state.
unsigned get_read_ready() const override
How many bytes can be read without blocking?
satcat5::io::MultiChunk * m_read_chunk
Current read state.
bool read_consume(unsigned nbytes) override
Read and discard 0 or more bytes.
Reader(const satcat5::io::MultiPacket *pkt=0)
Create a new Reader object.
u8 read_next() override
Read the next byte from the underlying buffer or device.
bool read_bytes(unsigned nbytes, void *dst) override
Read 0 or more bytes into a buffer.
void read_reset(const satcat5::io::MultiPacket *pkt)
Reset read state for the designated packet.
satcat5::io::MultiPacket * get_packet() const
Get a pointer to the current packet, if active.
unsigned m_read_rem
Current read state.
const satcat5::io::MultiPacket * m_read_pkt
Current read state.
void read_finalize() override
Consume any remaining bytes in this frame, if applicable.
A port for reading from a MultiBuffer object.
virtual bool accept(satcat5::io::MultiPacket *packet)
Accept a packet from the source buffer? Default accepts all packets unless this port is disabled or f...
bool m_port_enable
Internal state.
void timer_event() override
Timeouts help prevent resource-hogging.
unsigned m_read_timeout
Internal state.
void set_timeout(unsigned timeout_msec)
Update the watchdog timeout.
void read_finalize() override
Consume any remaining bytes in this frame, if applicable.
satcat5::io::MultiBuffer *const m_src
Pointer to the source buffer.
void set_port_enable(bool enable)
Enable or disable this port.
void flush()
Discard all queued packets.
MultiReader(satcat5::io::MultiBuffer *src)
Constructor and destructor are only accessible to children.
bool get_port_enable() const
Is this port currently enabled?
void pkt_init(satcat5::io::MultiPacket *packet)
Helper function for starting a new packet, or NULL to stop.
virtual satcat5::io::MultiPacket * pkt_pop()=0
Choose the next packet to start reading, or NULL to stop.
void pkt_free(satcat5::io::MultiPacket *packet)
Decrement reference count, free when it reaches zero.
virtual bool pkt_push(satcat5::io::MultiPacket *packet)=0
Push a packet onto the end of a queue or similar data structure.
A variant of MultiReader that follows priority ordering.
unsigned m_heap_count
Binary heap sorted by increasing priority.
bool can_accept() const
Can this object accept new packets? Required for testing.
A variant of MultiReader with a simple first-in, first-out queue.
unsigned m_queue_rdidx
Queue based on a circular buffer.
unsigned m_queue_count
Queue based on a circular buffer.
bool can_accept() const
Can this object accept new packets? Required for testing.
MultiWriter adapter for bypass mode.
A port for writing to a MultiBuffer object.
void set_timeout(unsigned timeout_msec)
Update the watchdog timeout.
unsigned m_write_pos
Current write state.
satcat5::io::MultiBuffer *const m_dst
Pointer to the destination buffer.
unsigned get_write_partial() const
Get current write length.
satcat5::io::MultiChunk * m_write_tail
Current write state.
unsigned m_write_maxlen
Current write state.
satcat5::io::MultiPacket * m_write_pkt
Current write state.
unsigned m_write_timeout
Current write state.
unsigned m_write_len
Current write state.
void set_max_packet(unsigned max_bytes)
Update the maximum allowed packet length.
Abstract API for reading byte-streams and packets.
Abstract API for writing byte-streams and packets.
An "OnDemand" object is polled only on request.
Timer objects are polled after a fixed delay or at a regular interval.
Helper functions for manipulating singly-linked lists.
bool is_empty() const
Is this list empty?
"Readable" I/O interface core definitions
"Writeable" I/O interface core definitions
Templated functions for manipulating singly-linked lists.
Data-structure representing a single fine-grained memory block.
A packet is a linked-list of memory blocks, plus metadata.
unsigned m_length
Packet length in bytes.
u16 m_priority
Packet priority.
u16 m_pcount
Packet counter.
u32 m_user[SATCAT5_MBUFF_USER]
Packet metadata.
bool is_deleted() const
Has this packet been deleted?
bool copy_to(satcat5::io::Writeable *wr) const
Copy the packet contents to the specified destination.
unsigned m_refct
Reference counter.
satcat5::io::ArrayRead peek() const
Peek at the first chunk, up to SATCAT5_MBUFF_CHUNK bytes.
Basic type aliases and prototypes used throughout SatCat5.