24#include "hardware/pio.h"
36#define TX_QUEUE_TX_INPROG_MS 1000U
51#define QUEUE_FILLING_UP_THRESHOLD 5U
56 bool queue_filling_up =
76 size_t bytes_to_drain,
size_t* bytes_drained)
80 if (!entry || !bytes_drained)
85 size_t effective_bytes_to_drain = bytes_to_drain >= entry->
frame.
length - entry->
offset
89 for (
size_t i = 0; i < effective_bytes_to_drain; i++)
91 if (pio_sm_is_tx_fifo_full(pio0, 0))
108 entry->
offset += *bytes_drained;
131 if (!queue || !bytes_drained)
164 LOG_DEBUG(
"TX FRAME COMPLETE: offset=%zu length=%zu\n", completed_offset, completed_length);
189 static uint32_t last_log = 0;
190 uint32_t now = to_ms_since_boot(get_absolute_time());
203 if (!queue || !frame)
e2s_error_t
Common error codes returned by ether2ser modules.
@ E2S_ERR_HDLC_ENCODE_FAILED
@ E2S_ERR_TX_QUEUE_NOT_INITIALIZED
bool hdlc_encode(const uint8_t *payload, const size_t payload_length, HDLC_FRAME_T *frame, bool lsb_first)
Encode payload into an HDLC bit-stuffed frame.
bool tx_put(uint8_t data)
Queue one byte to the TX PIO FIFO.
void tx_clock_hard_reset(void)
Hard-reset TX SM state to discard queued/in-flight bytes.
uint32_t tx_clock_get_cts_toggle_seq(void)
Read current CTS edge sequence counter.
int RbInit(Ringbuffer *bufferStruct, void *bufferPointer, size_t capacity, size_t itemSizeInByte)
Initialize ring buffer instance.
int RbPopFront(Ringbuffer *bufferStruct, void *element)
Pop one element from front.
int RbPushBack(Ringbuffer *bufferStruct, const void *element)
Push one element at tail/head end.
One queued HDLC frame plus drain offset state.
uint8_t payload[TX_FRAME_MAX_SIZE_BYTE]
TX_QUEUE_ENTRY_T current_entry
bool current_frame_cts_seq_valid
uint32_t current_frame_cts_seq_start
static e2s_error_t tx_queue_drain_bytes(TX_QUEUE_T *queue, TX_QUEUE_ENTRY_T *entry, size_t bytes_to_drain, size_t *bytes_drained)
#define QUEUE_FILLING_UP_THRESHOLD
e2s_error_t poll_queue_stats(TX_QUEUE_T *queue)
Emit queue usage statistics when needed.
bool tx_queue_is_empty(TX_QUEUE_T *queue)
Check whether queue and active entry are fully drained.
size_t tx_queue_get_count(const TX_QUEUE_T *queue)
Get current number of queued entries.
#define TX_QUEUE_TX_INPROG_MS
e2s_error_t tx_queue_init(TX_QUEUE_T *queue, uint8_t *buffer_data)
Initialize TX queue and ring buffer storage.
e2s_error_t tx_queue_enqueue_udp_frame(TX_QUEUE_T *queue, const UDP_FRAME_T *frame)
Encode UDP frame to HDLC and append it to TX queue.
e2s_error_t tx_queue_drain(TX_QUEUE_T *queue, size_t bytes_to_drain, size_t *bytes_drained)
Drain up to bytes_to_drain bytes from queue into TX FIFO.
#define TX_FRAME_QUEUE_SIZE
Number of frame entries available in the TX queue ring buffer.