|
ether2ser 0.1.0
Ethernet <-> synchronous V.24 bridge firmware for RP2040 + W5500
|
#include "hdlc_decoder.h"#include <limits.h>#include <stdbool.h>#include <stddef.h>#include <stdint.h>#include "hdlc_common.h"#include "system/common.h"
Go to the source code of this file.
Data Structures | |
| struct | hdlc_decoder_t |
Macros | |
| #define | HDLC_BIT_STUFF_ONES_LIMIT 5U |
| #define | HDLC_DEC_BYTE_IDX(raw_bit_index) (1 + ((raw_bit_index) / CHAR_BIT)) |
| #define | HDLC_DEC_BIT_IDX(raw_bit_index) ((raw_bit_index) % CHAR_BIT) |
| #define | HDLC_DEC_BIT_POS(decoder) |
| #define | HDLC_DEC_GET_OUT_BIT(decoder) (frame->payload[HDLC_DEC_BYTE_IDX((decoder)->raw_bit_index)] >> HDLC_DEC_BIT_POS((decoder)) & 1) |
Enumerations | |
| enum | hdlc_decoder_bit_type_t { HDLC_BIT_OK , HDLC_BIT_EOF , HDLC_BIT_ERR } |
Functions | |
| bool | hdlc_decode_byte (const HDLC_FRAME_T *frame, uint8_t *payload, const size_t out_capacity, size_t *payload_length) |
| Decode a byte-escaped HDLC frame compatibility path. | |
| static hdlc_decoder_bit_type_t | hdlc_get_bit (hdlc_decoder_t *decoder, const HDLC_FRAME_T *frame, uint8_t *out_bit) |
| static hdlc_decoder_bit_type_t | hdlc_get_byte (hdlc_decoder_t *decoder, const HDLC_FRAME_T *frame, uint8_t *byte) |
| bool | hdlc_decode (const HDLC_FRAME_T *frame, uint8_t *payload, const size_t out_capacity, size_t *payload_length, bool lsb_first) |
| Decode an HDLC bit-stuffed frame. | |
| void | hdlc_decode_stats_snapshot (hdlc_decode_stats_t *out_stats) |
| Copy cumulative HDLC decode statistics. | |
| void | hdlc_decode_stats_reset (void) |
| Reset cumulative HDLC decode statistics. | |
Variables | |
| static hdlc_decode_stats_t | hdlc_decode_stats = {0} |
| #define HDLC_BIT_STUFF_ONES_LIMIT 5U |
Definition at line 27 of file hdlc_decoder.c.
| #define HDLC_DEC_BIT_IDX | ( | raw_bit_index | ) | ((raw_bit_index) % CHAR_BIT) |
Definition at line 104 of file hdlc_decoder.c.
| #define HDLC_DEC_BIT_POS | ( | decoder | ) |
Definition at line 105 of file hdlc_decoder.c.
| #define HDLC_DEC_BYTE_IDX | ( | raw_bit_index | ) | (1 + ((raw_bit_index) / CHAR_BIT)) |
Definition at line 103 of file hdlc_decoder.c.
| #define HDLC_DEC_GET_OUT_BIT | ( | decoder | ) | (frame->payload[HDLC_DEC_BYTE_IDX((decoder)->raw_bit_index)] >> HDLC_DEC_BIT_POS((decoder)) & 1) |
Definition at line 108 of file hdlc_decoder.c.
| Enumerator | |
|---|---|
| HDLC_BIT_OK | |
| HDLC_BIT_EOF | |
| HDLC_BIT_ERR | |
Definition at line 36 of file hdlc_decoder.c.
| bool hdlc_decode | ( | const HDLC_FRAME_T * | frame, |
| uint8_t * | payload, | ||
| const size_t | out_capacity, | ||
| size_t * | payload_length, | ||
| bool | lsb_first | ||
| ) |
Decode an HDLC bit-stuffed frame.
| frame | Input HDLC frame. |
| payload | Output payload buffer. |
| out_capacity | Capacity of payload in bytes. |
| payload_length | Output payload length. |
| lsb_first | Bit order selector matching encoder/PIO path. |
Definition at line 171 of file hdlc_decoder.c.
References hdlc_decode_stats_t::crc_mismatch, HDLC_BIT_EOF, HDLC_BIT_ERR, hdlc_crc16(), hdlc_decode_stats, HDLC_FLAG_BYTE, hdlc_get_byte(), hdlc_decode_stats_t::invalid_frame, HDLC_FRAME_T::length, LOG_DEBUG, HDLC_FRAME_T::payload, hdlc_decode_stats_t::payload_too_long, hdlc_decoder_t::raw_bit_index, hdlc_decode_stats_t::too_short, and hdlc_decode_stats_t::unstuff_error.
Referenced by decode_hdlc_to_udp_tx(), and event_dispatch().


| bool hdlc_decode_byte | ( | const HDLC_FRAME_T * | frame, |
| uint8_t * | payload, | ||
| const size_t | out_capacity, | ||
| size_t * | payload_length | ||
| ) |
Decode a byte-escaped HDLC frame compatibility path.
| frame | Input HDLC frame. |
| payload | Output payload buffer. |
| out_capacity | Capacity of payload in bytes. |
| payload_length | Output payload length. |
Definition at line 45 of file hdlc_decoder.c.
References hdlc_decode_stats_t::crc_mismatch, hdlc_crc16(), hdlc_decode_stats, HDLC_ESCAPE_BYTE, HDLC_ESCAPE_XOR, HDLC_FLAG_BYTE, hdlc_decode_stats_t::invalid_frame, HDLC_FRAME_T::length, LOG_DEBUG, HDLC_FRAME_T::payload, hdlc_decode_stats_t::payload_too_long, and hdlc_decode_stats_t::too_short.

| void hdlc_decode_stats_reset | ( | void | ) |
Reset cumulative HDLC decode statistics.
Definition at line 246 of file hdlc_decoder.c.
References hdlc_decode_stats.
| void hdlc_decode_stats_snapshot | ( | hdlc_decode_stats_t * | out_stats | ) |
Copy cumulative HDLC decode statistics.
| out_stats | Destination pointer. |
Definition at line 237 of file hdlc_decoder.c.
References hdlc_decode_stats.
Referenced by update_statistics().

|
static |
Definition at line 111 of file hdlc_decoder.c.
References HDLC_BIT_EOF, HDLC_BIT_ERR, HDLC_BIT_OK, HDLC_BIT_STUFF_ONES_LIMIT, HDLC_DEC_GET_OUT_BIT, HDLC_FRAME_T::length, hdlc_decoder_t::ones_run, hdlc_decoder_t::raw_bit_index, and hdlc_decoder_t::skip_next_zero.
Referenced by hdlc_get_byte().

|
static |
Definition at line 152 of file hdlc_decoder.c.
References HDLC_BIT_OK, hdlc_get_bit(), and hdlc_decoder_t::lsb_first.
Referenced by hdlc_decode().


|
static |
Definition at line 43 of file hdlc_decoder.c.
Referenced by hdlc_decode(), hdlc_decode_byte(), hdlc_decode_stats_reset(), and hdlc_decode_stats_snapshot().