6 #include <hal_freertos/message_buffer.h>
10 #ifndef SATCAT5_FREERTOS_MSG_BUF_SEMPHR_TIMEOUT_MS
11 #define SATCAT5_FREERTOS_MSG_BUF_SEMPHR_TIMEOUT_MS 1
14 #ifndef SATCAT5_FREERTOS_MSG_BUFF_SEND_TIMEOUT_MS
15 #define SATCAT5_FREERTOS_MSG_BUFF_SEND_TIMEOUT_MS 1
18 #ifndef SATCAT5_MESSAGEBUFFER_BUFFSIZE
19 #define SATCAT5_MESSAGEBUFFER_BUFFSIZE 1600
27 MessageCopy::MessageCopy(
29 MessageBufferHandle_t* msg_buff_handle,
30 SemaphoreHandle_t* msg_buff_mutex)
32 , m_handle(msg_buff_handle)
33 , m_mutex(msg_buff_mutex)
35 if (m_src) m_src->set_callback(
this);
38 #if SATCAT5_ALLOW_DELETION
39 MessageCopy::~MessageCopy() {
50 u8 tmp[SATCAT5_MESSAGEBUFFER_BUFFSIZE];
53 rx_bytes = min_unsigned(rx_bytes, SATCAT5_MESSAGEBUFFER_BUFFSIZE);
58 BaseType_t status = xSemaphoreTake(
60 pdMS_TO_TICKS(SATCAT5_FREERTOS_MSG_BUF_SEMPHR_TIMEOUT_MS));
64 status = xMessageBufferSend(
68 pdMS_TO_TICKS(SATCAT5_FREERTOS_MSG_BUFF_SEND_TIMEOUT_MS));
71 xSemaphoreGive(*m_mutex);
77 u8* txbuff,
unsigned txbytes,
78 MessageBufferHandle_t* msg_buff_handle,
79 SemaphoreHandle_t* msg_buff_mutex)
80 : satcat5::io::WriteableRedirect(&m_tx)
81 , m_tx(txbuff, txbytes, 32)
82 , m_copy(&m_tx, msg_buff_handle, msg_buff_mutex)
87 MessageBufferPort::MessageBufferPort(
89 MessageBufferHandle_t* msg_buff_handle,
90 SemaphoreHandle_t* msg_buff_mutex)
91 : SwitchPort(sw, this)
92 , m_copy(&m_egress, msg_buff_handle, msg_buff_mutex)
A shared-memory Ethernet switch based on the MultiBuffer class.
PacketBuffer to MessageBuffer adapter.
MessageBuffer(u8 *txbuff, unsigned txbytes, MessageBufferHandle_t *msg_buff_handle, SemaphoreHandle_t *msg_buff_semphr)
Constructor requires a working buffer, plus handles for the FreeRTOS MessageBuffer and Semaphore.
SwitchPort to FreeRTOS MessageBuffer adapter.
Copy data from a Readable source to a FreeRTOS MessageBuffer.
void data_rcvd(satcat5::io::Readable *src) override
The data_rcvd() callback is polled whenever data is available.
void data_unlink(satcat5::io::Readable *src) override
Unlink this EventListener from the designated source, because the designated Readable object is being...
Abstract API for reading byte-streams and packets.
virtual bool read_bytes(unsigned nbytes, void *dst)
Read 0 or more bytes into a buffer.
virtual void read_finalize()
Consume any remaining bytes in this frame, if applicable.
virtual void set_callback(satcat5::io::EventListener *callback)
Update registered callback for data_rcvd() events.
virtual unsigned get_read_ready() const =0
How many bytes can be read without blocking?
Miscellaneous mathematical utility functions.
constexpr unsigned min_unsigned(unsigned a, unsigned b)
Min and max functions.