|
ether2ser 0.1.0
Ethernet <-> synchronous V.24 bridge firmware for RP2040 + W5500
|
#include "hdlc_sync.h"#include <stdbool.h>#include <stdint.h>#include <string.h>#include "hdlc_common.h"#include "system/error.h"
Go to the source code of this file.
Macros | |
| #define | HDLC_BITS_PER_BYTE 8U |
| #define | HDLC_SYNC_MIN_FRAME_SIZE_BYTES 4U |
| #define | HDLC_SYNC_MAX_REASONABLE_FRAME_SIZE_BYTES 2048U |
| #define | HDLC_SYNC_SHORT_BUFFER_SEARCH_LIMIT 64U |
Enumerations | |
| enum | HDLC_SYNC_POLL_STEP_RESULT_T { HDLC_SYNC_POLL_STEP_PROGRESS , HDLC_SYNC_POLL_STEP_STOP , HDLC_SYNC_POLL_STEP_FRAME_READY , HDLC_SYNC_POLL_STEP_ERROR } |
Functions | |
| static void | hdlc_sync_drop_prefix (HDLC_SYNC_ACCUMULATOR_T *accumulator, size_t drop_count) |
| static void | hdlc_sync_reset_hunting_state (HDLC_SYNC_ACCUMULATOR_T *accumulator) |
| static void | hdlc_sync_reject_oversized_candidate (HDLC_SYNC_ACCUMULATOR_T *accumulator, HDLC_FRAME_T *out_frame, size_t *scan_index) |
| static bool | hdlc_sync_get_aligned_byte (const HDLC_SYNC_ACCUMULATOR_T *accumulator, size_t raw_index, uint8_t bit_offset, bool shift_right, uint8_t *out_byte) |
| static bool | hdlc_sync_find_opening_candidate (const HDLC_SYNC_ACCUMULATOR_T *accumulator, size_t scan_index, bool allow_left_shift, size_t *out_start_index, uint8_t *out_bit_pos, bool *out_shift_right) |
| static bool | hdlc_sync_find_complete_candidate_short (const HDLC_SYNC_ACCUMULATOR_T *accumulator, size_t scan_index, size_t *out_start_index, uint8_t *out_bit_pos, bool *out_shift_right) |
| static HDLC_SYNC_POLL_STEP_RESULT_T | hdlc_sync_step_hunting (HDLC_SYNC_ACCUMULATOR_T *accumulator, HDLC_FRAME_T *out_frame, size_t *scan_index) |
| static HDLC_SYNC_POLL_STEP_RESULT_T | hdlc_sync_step_syncing (HDLC_SYNC_ACCUMULATOR_T *accumulator, HDLC_FRAME_T *out_frame, size_t *scan_index, e2s_error_t *out_error) |
| static HDLC_SYNC_POLL_STEP_RESULT_T | hdlc_sync_step_synced (HDLC_SYNC_ACCUMULATOR_T *accumulator, HDLC_FRAME_T *out_frame, size_t *scan_index, e2s_error_t *out_error) |
| static void | hdlc_sync_finalize_poll_no_frame (HDLC_SYNC_ACCUMULATOR_T *accumulator, size_t scan_index) |
| 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. | |
| #define HDLC_BITS_PER_BYTE 8U |
Definition at line 26 of file hdlc_sync.c.
| #define HDLC_SYNC_MAX_REASONABLE_FRAME_SIZE_BYTES 2048U |
Definition at line 28 of file hdlc_sync.c.
| #define HDLC_SYNC_MIN_FRAME_SIZE_BYTES 4U |
Definition at line 27 of file hdlc_sync.c.
| #define HDLC_SYNC_SHORT_BUFFER_SEARCH_LIMIT 64U |
Definition at line 29 of file hdlc_sync.c.
| Enumerator | |
|---|---|
| HDLC_SYNC_POLL_STEP_PROGRESS | |
| HDLC_SYNC_POLL_STEP_STOP | |
| HDLC_SYNC_POLL_STEP_FRAME_READY | |
| HDLC_SYNC_POLL_STEP_ERROR | |
Definition at line 57 of file hdlc_sync.c.
| void hdlc_sync_acc_consume_candidate | ( | HDLC_SYNC_ACCUMULATOR_T * | accumulator, |
| bool | accept | ||
| ) |
Consume current candidate and advance accumulator window.
| accumulator | Accumulator instance. |
| accept | Acceptance 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().


| void hdlc_sync_acc_init | ( | HDLC_SYNC_ACCUMULATOR_T * | accumulator, |
| uint8_t | sync_byte | ||
| ) |
Initialize HDLC sync accumulator state.
| accumulator | Accumulator instance. |
| sync_byte | Sync/flag byte to detect. |
Definition at line 507 of file hdlc_sync.c.
References HDLC_SYNC_ACCUMULATOR_T::align_shift_right, HDLC_SYNC_ACCUMULATOR_T::bit_offset, 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::frame_ready_count, HDLC_SYNC_ACCUMULATOR_T::hardcap_drop_bytes, HDLC_SYNC_ACCUMULATOR_T::hardcap_drop_events, HDLC_SYNC_STATE_HUNTING, HDLC_SYNC_ACCUMULATOR_T::lookahead_wait_synced, HDLC_SYNC_ACCUMULATOR_T::lookahead_wait_syncing, HDLC_SYNC_ACCUMULATOR_T::position, HDLC_SYNC_ACCUMULATOR_T::processed, HDLC_SYNC_ACCUMULATOR_T::state, and HDLC_SYNC_ACCUMULATOR_T::sync_byte.
Referenced by decode_hdlc_to_udp_tx(), drain_hdlc_frames_to_udp(), event_dispatch(), init_app(), poll_hdlc_idle_timeout(), and poll_hdlc_no_progress().

| 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.
| accumulator | Accumulator instance. |
| out_frame | Output aligned frame buffer. |
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().


| bool hdlc_sync_acc_process_byte | ( | HDLC_SYNC_ACCUMULATOR_T * | accumulator, |
| uint8_t | byte | ||
| ) |
Append one received raw byte to the accumulator.
| accumulator | Accumulator instance. |
| byte | Received raw byte. |
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().

|
static |
Definition at line 70 of file hdlc_sync.c.
References HDLC_SYNC_ACCUMULATOR_T::buffer, HDLC_SYNC_ACCUMULATOR_T::position, and HDLC_SYNC_ACCUMULATOR_T::processed.
Referenced by hdlc_sync_acc_consume_candidate(), hdlc_sync_finalize_poll_no_frame(), and hdlc_sync_reject_oversized_candidate().

|
static |
Definition at line 483 of file hdlc_sync.c.
References hdlc_sync_drop_prefix(), HDLC_SYNC_STATE_HUNTING, HDLC_SYNC_ACCUMULATOR_T::position, HDLC_SYNC_ACCUMULATOR_T::processed, and HDLC_SYNC_ACCUMULATOR_T::state.
Referenced by hdlc_sync_acc_poll().


|
static |
Definition at line 248 of file hdlc_sync.c.
References HDLC_BITS_PER_BYTE, hdlc_sync_get_aligned_byte(), HDLC_SYNC_MIN_FRAME_SIZE_BYTES, HDLC_SYNC_SHORT_BUFFER_SEARCH_LIMIT, HDLC_SYNC_ACCUMULATOR_T::position, and HDLC_SYNC_ACCUMULATOR_T::sync_byte.
Referenced by hdlc_sync_step_hunting().


|
static |
Definition at line 177 of file hdlc_sync.c.
References HDLC_BITS_PER_BYTE, hdlc_sync_get_aligned_byte(), HDLC_SYNC_ACCUMULATOR_T::position, and HDLC_SYNC_ACCUMULATOR_T::sync_byte.
Referenced by hdlc_sync_step_hunting().


|
static |
Definition at line 136 of file hdlc_sync.c.
References HDLC_SYNC_ACCUMULATOR_T::buffer, HDLC_BITS_PER_BYTE, and HDLC_SYNC_ACCUMULATOR_T::position.
Referenced by hdlc_sync_find_complete_candidate_short(), hdlc_sync_find_opening_candidate(), hdlc_sync_step_synced(), and hdlc_sync_step_syncing().

|
static |
Definition at line 108 of file hdlc_sync.c.
References HDLC_SYNC_ACCUMULATOR_T::candidate_start, hdlc_sync_drop_prefix(), hdlc_sync_reset_hunting_state(), HDLC_FRAME_T::length, and HDLC_SYNC_ACCUMULATOR_T::position.
Referenced by hdlc_sync_step_synced(), and hdlc_sync_step_syncing().


|
static |
Definition at line 90 of file hdlc_sync.c.
References HDLC_SYNC_ACCUMULATOR_T::align_shift_right, HDLC_SYNC_ACCUMULATOR_T::bit_offset, HDLC_SYNC_ACCUMULATOR_T::candidate_end, HDLC_SYNC_ACCUMULATOR_T::candidate_start, HDLC_SYNC_ACCUMULATOR_T::candidate_valid, HDLC_SYNC_STATE_HUNTING, HDLC_SYNC_ACCUMULATOR_T::processed, and HDLC_SYNC_ACCUMULATOR_T::state.
Referenced by hdlc_sync_acc_consume_candidate(), and hdlc_sync_reject_oversized_candidate().

|
static |
Definition at line 343 of file hdlc_sync.c.
References HDLC_SYNC_ACCUMULATOR_T::align_shift_right, HDLC_SYNC_ACCUMULATOR_T::bit_offset, HDLC_SYNC_ACCUMULATOR_T::candidate_start, HDLC_SYNC_ACCUMULATOR_T::candidate_valid, hdlc_sync_find_complete_candidate_short(), hdlc_sync_find_opening_candidate(), HDLC_SYNC_POLL_STEP_PROGRESS, HDLC_SYNC_POLL_STEP_STOP, HDLC_SYNC_STATE_SYNCING, HDLC_FRAME_T::length, HDLC_FRAME_T::payload, HDLC_SYNC_ACCUMULATOR_T::position, HDLC_SYNC_ACCUMULATOR_T::state, and HDLC_SYNC_ACCUMULATOR_T::sync_byte.
Referenced by hdlc_sync_acc_poll().


|
static |
Definition at line 420 of file hdlc_sync.c.
References HDLC_SYNC_ACCUMULATOR_T::align_shift_right, HDLC_SYNC_ACCUMULATOR_T::bit_offset, HDLC_SYNC_ACCUMULATOR_T::candidate_end, HDLC_SYNC_ACCUMULATOR_T::candidate_valid, HDLC_FRAME_T::capacity, E2S_ERR_HDLC_DECODE_PAYLOAD_TOO_LONG, HDLC_SYNC_ACCUMULATOR_T::frame_ready_count, HDLC_BITS_PER_BYTE, hdlc_sync_get_aligned_byte(), HDLC_SYNC_MAX_REASONABLE_FRAME_SIZE_BYTES, HDLC_SYNC_POLL_STEP_ERROR, HDLC_SYNC_POLL_STEP_FRAME_READY, HDLC_SYNC_POLL_STEP_PROGRESS, HDLC_SYNC_POLL_STEP_STOP, hdlc_sync_reject_oversized_candidate(), HDLC_SYNC_STATE_HUNTING, HDLC_FRAME_T::length, HDLC_SYNC_ACCUMULATOR_T::lookahead_wait_synced, HDLC_FRAME_T::payload, HDLC_SYNC_ACCUMULATOR_T::state, and HDLC_SYNC_ACCUMULATOR_T::sync_byte.
Referenced by hdlc_sync_acc_poll().


|
static |
Definition at line 379 of file hdlc_sync.c.
References HDLC_SYNC_ACCUMULATOR_T::align_shift_right, HDLC_SYNC_ACCUMULATOR_T::bit_offset, HDLC_FRAME_T::capacity, E2S_ERR_HDLC_DECODE_PAYLOAD_TOO_LONG, hdlc_sync_get_aligned_byte(), HDLC_SYNC_MAX_REASONABLE_FRAME_SIZE_BYTES, HDLC_SYNC_POLL_STEP_ERROR, HDLC_SYNC_POLL_STEP_PROGRESS, HDLC_SYNC_POLL_STEP_STOP, hdlc_sync_reject_oversized_candidate(), HDLC_SYNC_STATE_HUNTING, HDLC_SYNC_STATE_SYNCED, HDLC_FRAME_T::length, HDLC_SYNC_ACCUMULATOR_T::lookahead_wait_syncing, HDLC_FRAME_T::payload, and HDLC_SYNC_ACCUMULATOR_T::state.
Referenced by hdlc_sync_acc_poll().

