ether2ser 0.1.0
Ethernet <-> synchronous V.24 bridge firmware for RP2040 + W5500
Loading...
Searching...
No Matches
tx_queue.h File Reference
#include <stdbool.h>
#include <stdint.h>
#include "drivers/w5500_driver.h"
#include "protocol/hdlc_common.h"
#include "system/error.h"
#include "system/ringbuffer.h"
Include dependency graph for tx_queue.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  TX_QUEUE_ENTRY_T
 One queued HDLC frame plus drain offset state. More...
 
struct  TX_QUEUE_T
 TX queue runtime state. More...
 

Macros

#define TX_FRAME_QUEUE_SIZE   64
 Number of frame entries available in the TX queue ring buffer.
 
#define TX_FRAME_MAX_SIZE_BYTE   2048
 The maximum size of a hdlc frame in the queue Max UDP size we accept is 1472 byte, adding 2 CRC frames nd start/end Flags that gives 1476 byte. Worst case stuffing approximation would be 1 bit per 5 bits. Together that gives ~14150 bits per frame ~1769 bytes. To give conservative headroom we default to 2048.
 
#define TX_QUEUE_DECLARE_AND_INIT(var_name)
 Convenience macro to declare and initialize a TX queue and backing storage.
 

Functions

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.
 
bool tx_queue_is_empty (TX_QUEUE_T *queue)
 Check whether queue and active entry are fully drained.
 
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.
 
e2s_error_t poll_queue_stats (TX_QUEUE_T *queue)
 Emit queue usage statistics when needed.
 
e2s_error_t tx_queue_init (TX_QUEUE_T *queue, uint8_t *buffer_data)
 Initialize TX queue and ring buffer storage.
 
size_t tx_queue_get_count (const TX_QUEUE_T *queue)
 Get current number of queued entries.
 

Macro Definition Documentation

◆ TX_FRAME_MAX_SIZE_BYTE

#define TX_FRAME_MAX_SIZE_BYTE   2048

The maximum size of a hdlc frame in the queue Max UDP size we accept is 1472 byte, adding 2 CRC frames nd start/end Flags that gives 1476 byte. Worst case stuffing approximation would be 1 bit per 5 bits. Together that gives ~14150 bits per frame ~1769 bytes. To give conservative headroom we default to 2048.

Definition at line 42 of file tx_queue.h.

◆ TX_FRAME_QUEUE_SIZE

#define TX_FRAME_QUEUE_SIZE   64

Number of frame entries available in the TX queue ring buffer.

Definition at line 32 of file tx_queue.h.

◆ TX_QUEUE_DECLARE_AND_INIT

#define TX_QUEUE_DECLARE_AND_INIT (   var_name)
Value:
TX_QUEUE_T var_name; \
uint8_t var_name##_buffer_data[TX_FRAME_QUEUE_SIZE * sizeof(TX_QUEUE_ENTRY_T)]; \
Ringbuffer var_name##_ringbuf; \
RbInit(&var_name##_ringbuf, var_name##_buffer_data, TX_FRAME_QUEUE_SIZE, \
sizeof(TX_QUEUE_ENTRY_T)); \
tx_queue_init(&var_name, &var_name##_ringbuf)
Generic fixed-size ring buffer state.
Definition ringbuffer.h:28
One queued HDLC frame plus drain offset state.
Definition tx_queue.h:60
TX queue runtime state.
Definition tx_queue.h:73
#define TX_FRAME_QUEUE_SIZE
Number of frame entries available in the TX queue ring buffer.
Definition tx_queue.h:32

Convenience macro to declare and initialize a TX queue and backing storage.

Parameters
var_nameBase variable name for queue and storage symbols.

Definition at line 48 of file tx_queue.h.

Function Documentation

◆ poll_queue_stats()

e2s_error_t poll_queue_stats ( TX_QUEUE_T queue)

Emit queue usage statistics when needed.

Parameters
queueTX queue instance.
Returns
Error code.

Definition at line 49 of file tx_queue.c.

References Ringbuffer::capacity, Ringbuffer::count, E2S_ERR_TX_QUEUE_NOT_INITIALIZED, E2S_OK, LOG_INFO, LOG_TRACE, TX_QUEUE_T::queue_buffer, QUEUE_FILLING_UP_THRESHOLD, and TX_QUEUE_T::queue_touched.

Referenced by poll_tx_pipeline().

Here is the caller graph for this function:

◆ tx_queue_drain()

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.

Parameters
queueTX queue instance.
bytes_to_drainMaximum bytes to attempt.
bytes_drainedPointer to where the number of actually drained bytes is written.
Returns
Error code.

Restart only when CTS changed during this frame's transmission window. Stale edges from idle periods must not retrigger unrelated future frames.

Definition at line 129 of file tx_queue.c.

References HDLC_FRAME_T::capacity, TX_QUEUE_T::current_entry, TX_QUEUE_T::current_frame_cts_seq_start, TX_QUEUE_T::current_frame_cts_seq_valid, E2S_ERR_TX_QUEUE_NOT_INITIALIZED, E2S_OK, TX_QUEUE_ENTRY_T::frame, HDLC_FRAME_T::length, LOG_DEBUG, LOG_TRACE, TX_QUEUE_ENTRY_T::offset, TX_QUEUE_ENTRY_T::payload, HDLC_FRAME_T::payload, TX_QUEUE_T::queue_buffer, RbPopFront(), tx_clock_get_cts_toggle_seq(), tx_clock_hard_reset(), tx_queue_drain_bytes(), and TX_QUEUE_TX_INPROG_MS.

Referenced by poll_tx_pipeline().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tx_queue_enqueue_udp_frame()

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.

Parameters
queueTX queue instance.
frameUDP frame payload source.
Returns
Error code.

Definition at line 201 of file tx_queue.c.

References HDLC_FRAME_T::capacity, Ringbuffer::capacity, Ringbuffer::count, E2S_ERR_HDLC_ENCODE_FAILED, E2S_ERR_TX_QUEUE_FULL, E2S_ERR_TX_QUEUE_NOT_INITIALIZED, E2S_OK, TX_QUEUE_ENTRY_T::frame, hdlc_encode(), UDP_FRAME_T::length, HDLC_FRAME_T::length, LOG_DEBUG, TX_QUEUE_ENTRY_T::payload, UDP_FRAME_T::payload, HDLC_FRAME_T::payload, TX_QUEUE_T::queue_buffer, TX_QUEUE_T::queue_touched, and RbPushBack().

Referenced by event_dispatch(), and poll_and_enqueue_udp_rx().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tx_queue_get_count()

size_t tx_queue_get_count ( const TX_QUEUE_T queue)

Get current number of queued entries.

Parameters
queueTX queue instance.
Returns
Entry count.

Definition at line 113 of file tx_queue.c.

References Ringbuffer::count, and TX_QUEUE_T::queue_buffer.

Referenced by update_statistics(), and update_udp_rx_throttle_state().

Here is the caller graph for this function:

◆ tx_queue_init()

e2s_error_t tx_queue_init ( TX_QUEUE_T queue,
uint8_t *  buffer_data 
)

Initialize TX queue and ring buffer storage.

Parameters
queueTX queue instance.
buffer_dataBacking storage for ring buffer entries.
Returns
Error code.

Definition at line 38 of file tx_queue.c.

References TX_QUEUE_T::current_frame_cts_seq_start, TX_QUEUE_T::current_frame_cts_seq_valid, E2S_OK, TX_QUEUE_T::queue_buffer, TX_QUEUE_T::queue_touched, RbInit(), TX_FRAME_QUEUE_SIZE, and TX_QUEUE_T::tx_wire_bytes.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tx_queue_is_empty()

bool tx_queue_is_empty ( TX_QUEUE_T queue)

Check whether queue and active entry are fully drained.

Parameters
queueTX queue instance.
Returns
true if no pending or active bytes remain.

Definition at line 122 of file tx_queue.c.

References Ringbuffer::count, TX_QUEUE_T::current_entry, TX_QUEUE_ENTRY_T::frame, HDLC_FRAME_T::length, TX_QUEUE_ENTRY_T::offset, and TX_QUEUE_T::queue_buffer.

Referenced by ev_set_v24_settings(), poll_and_dispatch_events(), and poll_tx_pipeline().

Here is the caller graph for this function: