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

Go to the source code of this file.

Data Structures

struct  HDLC_SYNC_ACCUMULATOR_T
 Accumulator and state for HDLC bit-offset synchronization. More...
 

Macros

#define RX_HDLC_SYNC_MAX_BUFFER_SIZE   8192
 Maximum raw RX bytes retained in the HDLC sync accumulator.
 
#define HDLC_SYNC_DEFAULT_SYNC_BYTE   HDLC_FLAG_BYTE
 Default sync byte used for HDLC framing.
 

Enumerations

enum  HDLC_SYNC_STATE_T { HDLC_SYNC_STATE_HUNTING , HDLC_SYNC_STATE_SYNCING , HDLC_SYNC_STATE_SYNCED }
 HDLC synchronizer state machine states. More...
 

Functions

void hdlc_sync_acc_init (HDLC_SYNC_ACCUMULATOR_T *accumulator, uint8_t sync_byte)
 Initialize HDLC sync accumulator state.
 
bool hdlc_sync_acc_process_byte (HDLC_SYNC_ACCUMULATOR_T *accumulator, uint8_t byte)
 Append one received raw byte to the accumulator.
 
e2s_error_t hdlc_sync_acc_poll (HDLC_SYNC_ACCUMULATOR_T *accumulator, HDLC_FRAME_T *out_frame)
 Poll accumulator for an aligned HDLC frame candidate.
 
void hdlc_sync_acc_consume_candidate (HDLC_SYNC_ACCUMULATOR_T *accumulator, bool accept)
 Consume current candidate and advance accumulator window.
 

Macro Definition Documentation

◆ HDLC_SYNC_DEFAULT_SYNC_BYTE

#define HDLC_SYNC_DEFAULT_SYNC_BYTE   HDLC_FLAG_BYTE

Default sync byte used for HDLC framing.

Definition at line 35 of file hdlc_sync.h.

◆ RX_HDLC_SYNC_MAX_BUFFER_SIZE

#define RX_HDLC_SYNC_MAX_BUFFER_SIZE   8192

Maximum raw RX bytes retained in the HDLC sync accumulator.

Definition at line 30 of file hdlc_sync.h.

Enumeration Type Documentation

◆ HDLC_SYNC_STATE_T

HDLC synchronizer state machine states.

Enumerator
HDLC_SYNC_STATE_HUNTING 

Searching for first sync/flag pattern.

HDLC_SYNC_STATE_SYNCING 

Sync found, building candidate with known bit offset.

HDLC_SYNC_STATE_SYNCED 

Actively consuming aligned bytes until closing flag.

Definition at line 40 of file hdlc_sync.h.

Function Documentation

◆ hdlc_sync_acc_consume_candidate()

void hdlc_sync_acc_consume_candidate ( HDLC_SYNC_ACCUMULATOR_T accumulator,
bool  accept 
)

Consume current candidate and advance accumulator window.

Parameters
accumulatorAccumulator instance.
acceptAcceptance hint for candidate handling.

Definition at line 622 of file hdlc_sync.c.

References HDLC_SYNC_ACCUMULATOR_T::candidate_end, HDLC_SYNC_ACCUMULATOR_T::candidate_start, HDLC_SYNC_ACCUMULATOR_T::candidate_valid, HDLC_SYNC_ACCUMULATOR_T::consume_count, HDLC_SYNC_ACCUMULATOR_T::hardcap_drop_bytes, HDLC_SYNC_ACCUMULATOR_T::hardcap_drop_events, hdlc_sync_drop_prefix(), hdlc_sync_reset_hunting_state(), HDLC_SYNC_ACCUMULATOR_T::position, HDLC_SYNC_ACCUMULATOR_T::processed, and RX_HDLC_SYNC_MAX_BUFFER_SIZE.

Referenced by decode_hdlc_to_udp_tx().

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

◆ hdlc_sync_acc_init()

◆ hdlc_sync_acc_poll()

e2s_error_t hdlc_sync_acc_poll ( HDLC_SYNC_ACCUMULATOR_T accumulator,
HDLC_FRAME_T out_frame 
)

Poll accumulator for an aligned HDLC frame candidate.

Parameters
accumulatorAccumulator instance.
out_frameOutput aligned frame buffer.
Returns
E2S_ERR_HDLC_ACC_FRAME_READY when a candidate is available, otherwise status code.

Definition at line 549 of file hdlc_sync.c.

References HDLC_SYNC_ACCUMULATOR_T::bit_offset, HDLC_FRAME_T::capacity, E2S_ERR_HDLC_ACC_FRAME_READY, E2S_OK, hdlc_sync_finalize_poll_no_frame(), HDLC_SYNC_POLL_STEP_ERROR, HDLC_SYNC_POLL_STEP_FRAME_READY, HDLC_SYNC_POLL_STEP_PROGRESS, HDLC_SYNC_POLL_STEP_STOP, HDLC_SYNC_STATE_HUNTING, HDLC_SYNC_STATE_SYNCED, HDLC_SYNC_STATE_SYNCING, hdlc_sync_step_hunting(), hdlc_sync_step_synced(), hdlc_sync_step_syncing(), HDLC_FRAME_T::payload, HDLC_SYNC_ACCUMULATOR_T::position, HDLC_SYNC_ACCUMULATOR_T::processed, and HDLC_SYNC_ACCUMULATOR_T::state.

Referenced by drain_hdlc_frames_to_udp().

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

◆ hdlc_sync_acc_process_byte()

bool hdlc_sync_acc_process_byte ( HDLC_SYNC_ACCUMULATOR_T accumulator,
uint8_t  byte 
)

Append one received raw byte to the accumulator.

Parameters
accumulatorAccumulator instance.
byteReceived raw byte.
Returns
true if appended, false if buffer full or invalid args.

Definition at line 527 of file hdlc_sync.c.

References HDLC_SYNC_ACCUMULATOR_T::buffer, HDLC_SYNC_ACCUMULATOR_T::position, and RX_HDLC_SYNC_MAX_BUFFER_SIZE.

Referenced by drain_rx_until_empty().

Here is the caller graph for this function: