ether2ser 0.1.0
Ethernet <-> synchronous V.24 bridge firmware for RP2040 + W5500
Loading...
Searching...
No Matches
tx_queue.h
Go to the documentation of this file.
1/*
2 * ether2ser - Ethernet <-> synchronous V.24 (RS-232/V.28) bridge
3 *
4 * File: src/drivers/tx_queue.h
5 * Purpose: TX queue API for buffered HDLC frames.
6 *
7 * SPDX-License-Identifier: Apache-2.0
8 *
9 * Copyright (c) 2026 Florian <f.leuze@outlook.de>
10 */
11
12#ifndef TX_QUEUE_H
13#define TX_QUEUE_H
14
15// Related headers
16
17// Standard library headers
18#include <stdbool.h>
19#include <stdint.h>
20
21// Project Headers
24#include "system/error.h"
25#include "system/ringbuffer.h"
26
27// Generated headers
28
32#define TX_FRAME_QUEUE_SIZE 64
33
42#define TX_FRAME_MAX_SIZE_BYTE 2048
43
48#define TX_QUEUE_DECLARE_AND_INIT(var_name) \
49 TX_QUEUE_T var_name; \
50 uint8_t var_name##_buffer_data[TX_FRAME_QUEUE_SIZE * sizeof(TX_QUEUE_ENTRY_T)]; \
51 Ringbuffer var_name##_ringbuf; \
52 RbInit(&var_name##_ringbuf, var_name##_buffer_data, TX_FRAME_QUEUE_SIZE, \
53 sizeof(TX_QUEUE_ENTRY_T)); \
54 tx_queue_init(&var_name, &var_name##_ringbuf)
55
59typedef struct
60{
62 uint8_t payload[TX_FRAME_MAX_SIZE_BYTE]; // TODO: This has to be tested on the target
66 size_t offset;
68
87
95
101bool tx_queue_is_empty(TX_QUEUE_T* queue);
102
110e2s_error_t tx_queue_drain(TX_QUEUE_T* queue, size_t bytes_to_drain, size_t* bytes_drained);
111
118
125e2s_error_t tx_queue_init(TX_QUEUE_T* queue, uint8_t* buffer_data);
126
132size_t tx_queue_get_count(const TX_QUEUE_T* queue);
133
134#endif /* TX_QUEUE_H */
e2s_error_t
Common error codes returned by ether2ser modules.
Definition error.h:27
Generic HDLC frame buffer descriptor.
Definition hdlc_common.h:38
Generic fixed-size ring buffer state.
Definition ringbuffer.h:28
One queued HDLC frame plus drain offset state.
Definition tx_queue.h:60
size_t offset
Definition tx_queue.h:66
HDLC_FRAME_T frame
Definition tx_queue.h:64
TX queue runtime state.
Definition tx_queue.h:73
TX_QUEUE_ENTRY_T current_entry
Definition tx_queue.h:75
uint64_t tx_wire_bytes
Definition tx_queue.h:81
bool current_frame_cts_seq_valid
Definition tx_queue.h:85
Ringbuffer queue_buffer
Definition tx_queue.h:77
bool queue_touched
Definition tx_queue.h:79
uint32_t current_frame_cts_seq_start
Definition tx_queue.h:83
UDP payload container.
#define TX_FRAME_MAX_SIZE_BYTE
The maximum size of a hdlc frame in the queue Max UDP size we accept is 1472 byte,...
Definition tx_queue.h:42
e2s_error_t poll_queue_stats(TX_QUEUE_T *queue)
Emit queue usage statistics when needed.
Definition tx_queue.c:49
bool tx_queue_is_empty(TX_QUEUE_T *queue)
Check whether queue and active entry are fully drained.
Definition tx_queue.c:122
size_t tx_queue_get_count(const TX_QUEUE_T *queue)
Get current number of queued entries.
Definition tx_queue.c:113
e2s_error_t tx_queue_init(TX_QUEUE_T *queue, uint8_t *buffer_data)
Initialize TX queue and ring buffer storage.
Definition tx_queue.c:38
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.
Definition tx_queue.c:201
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.
Definition tx_queue.c:129