|
tinyproto
|
Low-level HDLC framing: flag bytes, byte stuffing, and CRC. More...
Classes | |
| struct | hdlc_ll_init_t |
| Structure describes configuration of lowest HDLC level Initialize this structure by 0 before passing to hdlc_ll_init() function. More... | |
Typedefs | |
| typedef struct hdlc_ll_data_t * | hdlc_ll_handle_t |
| Handle for HDLC low level protocol. | |
Enumerations | |
| enum | hdlc_ll_reset_flags_t { HDLC_LL_RESET_BOTH = 0x00, HDLC_LL_RESET_TX_ONLY = 0x01, HDLC_LL_RESET_RX_ONLY = 0x02 } |
| Flags for hdlc_ll_reset function. | |
Functions | |
| int | hdlc_ll_init (hdlc_ll_handle_t *handle, hdlc_ll_init_t *init) |
| Initializes hdlc level and returns hdlc handle or NULL in case of error. More... | |
| int | hdlc_ll_close (hdlc_ll_handle_t handle) |
| Shutdowns all hdlc activity. More... | |
| void | hdlc_ll_reset (hdlc_ll_handle_t handle, uint8_t flags) |
| Resets hdlc state. More... | |
| int | hdlc_ll_run_rx (hdlc_ll_handle_t handle, const void *data, int len, int *error) |
| Processes incoming data. More... | |
| int | hdlc_ll_run_tx (hdlc_ll_handle_t handle, void *data, int len) |
| If hdlc protocol has some data to send it will full data with This function returns either if no more data to send, or specified buffer is filled completely. More... | |
| int | hdlc_ll_put (hdlc_ll_handle_t handle, const void *data, int len) __attribute__((deprecated)) |
| Puts next frame for sending. More... | |
| int | hdlc_ll_put_frame (hdlc_ll_handle_t handle, const void *data, int len) |
| Puts next frame for sending. More... | |
| int | hdlc_ll_get_buf_size (int mtu) |
| Returns minimum buffer size, required to hold hdlc low level data for desired payload size. More... | |
| int | hdlc_ll_get_buf_size_ex (int mtu, hdlc_crc_t crc_type, int rx_window) |
| Returns minimum buffer size, required to hold hdlc low level data for desired payload size. More... | |
| typedef struct hdlc_ll_data_t | hdlc_ll_data_t |
| Structure describes configuration of lowest HDLC level Initialize this structure by 0 before passing to hdlc_ll_init() function. | |
| #define | HDLC_MIN_BUF_SIZE(mtu, crc) (sizeof(hdlc_ll_data_t) + (int)(crc) / 8 + (mtu) + TINY_ALIGN_STRUCT_VALUE - 1) |
| low level HDLC protocol function - only framing More... | |
| #define | HDLC_BUF_SIZE_EX(mtu, crc, window) (sizeof(hdlc_ll_data_t) + ((int)(crc) / 8 + (mtu)) * (window) + TINY_ALIGN_STRUCT_VALUE - 1) |
| Macro calculating buffer size required for specific packet size in bytes, and window. | |
Low-level HDLC framing: flag bytes, byte stuffing, and CRC.
This module implements low-level HDLC framing according to RFC 1662 and ISO 3309-1979. It handles:
This is a stateless framing layer — it does not implement acknowledgments, sequence numbers, or retransmission. For reliable delivery, use the Full-Duplex protocol (Tiny Full Duplex API functions).
The hdlc_ll functions do not use any synchronization primitives (mutexes, etc.), making them completely platform-independent and safe for use in interrupt context (with care).
| #define HDLC_MIN_BUF_SIZE | ( | mtu, | |
| crc | |||
| ) | (sizeof(hdlc_ll_data_t) + (int)(crc) / 8 + (mtu) + TINY_ALIGN_STRUCT_VALUE - 1) |
low level HDLC protocol function - only framing
this group implements low level HDLC functions, which implement framing only according to RFC 1662: 0x7E, 0x7D, 0x20 (ISO Standard 3309-1979). Macro calculating minimum buffer size required for specific packet size in bytes
| int hdlc_ll_close | ( | hdlc_ll_handle_t | handle | ) |
Shutdowns all hdlc activity.
| handle | hdlc handle |
| int hdlc_ll_get_buf_size | ( | int | mtu | ) |
Returns minimum buffer size, required to hold hdlc low level data for desired payload size.
| mtu | size of desired max payload in bytes |
| int hdlc_ll_get_buf_size_ex | ( | int | mtu, |
| hdlc_crc_t | crc_type, | ||
| int | rx_window | ||
| ) |
Returns minimum buffer size, required to hold hdlc low level data for desired payload size.
| mtu | size of desired max payload in bytes |
| crc_type | type of crc validation to use for the protocol |
| rx_window | number of RX frames in the RX ring buffer |
| int hdlc_ll_init | ( | hdlc_ll_handle_t * | handle, |
| hdlc_ll_init_t * | init | ||
| ) |
Initializes hdlc level and returns hdlc handle or NULL in case of error.
| handle | pointer to hdlc handle variable |
| init | pointer to hdlc_ll_struct_t structure, which defines user-specific configuration |
| int hdlc_ll_put | ( | hdlc_ll_handle_t | handle, |
| const void * | data, | ||
| int | len | ||
| ) |
Puts next frame for sending.
Deprecated: use hdlc_ll_put_frame() instead. hdlc_ll_put() function will not wait or perform send operation, but only pass data pointer to hdlc state machine. In this case, some other thread needs to or in the same thread you need to send data using hdlc_ll_get_tx_data().
| handle | hdlc handle |
| data | pointer to new data to send |
| len | size of data to send in bytes |
| int hdlc_ll_put_frame | ( | hdlc_ll_handle_t | handle, |
| const void * | data, | ||
| int | len | ||
| ) |
Puts next frame for sending.
hdlc_ll_put_frame() function will not wait or perform send operation, but only pass data pointer to hdlc state machine. In this case, some other thread needs to or in the same thread you need to send data using hdlc_ll_run_tx().
| handle | hdlc handle |
| data | pointer to new data to send |
| len | size of data to send in bytes |
| void hdlc_ll_reset | ( | hdlc_ll_handle_t | handle, |
| uint8_t | flags | ||
| ) |
Resets hdlc state.
Use this function, if hw error happened on tx or rx line, and this requires hardware change, and cancelling current operation.
| handle | hdlc handle |
| flags | HDLC_LL_RESET_TX_ONLY, HDLC_LL_RESET_RX_ONLY, HDLC_LL_RESET_BOTH |
| int hdlc_ll_run_rx | ( | hdlc_ll_handle_t | handle, |
| const void * | data, | ||
| int | len, | ||
| int * | error | ||
| ) |
Processes incoming data.
Implementation of reading data from hw is user responsibility. If hdlc_ll_run_rx() returns value less than size of data passed to the function, then hdlc_ll_run_rx() must be called later second time with the pointer to and size of not processed bytes.
If you don't care about errors on RX line, it is allowed to ignore all error codes except TINY_ERR_FAILED, which means general failure.
if hdlc_ll_run_rx() returns 0 bytes processed, just call it once again. It is guaranteed, that at least second call will process bytes.
This function will return the following codes in error field:
| handle | hdlc handle |
| data | pointer to incoming data to process |
| len | size of received data in bytes |
| error | pointer to store error code. If no error, 0 is returned. this argument can be NULL. |
| int hdlc_ll_run_tx | ( | hdlc_ll_handle_t | handle, |
| void * | data, | ||
| int | len | ||
| ) |
If hdlc protocol has some data to send it will full data with This function returns either if no more data to send, or specified buffer is filled completely.
| handle | hdlc handle |
| data | pointer to buffer to fill with data |
| len | length of specified buffer |
1.8.13