low level HDLC protocol implementation
More...
|
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.
|
|
|
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 protocol implementation
this group implements low level HDLC functions, which implement framing only according to RFC 1662: 0x7E, 0x7D, 0x20 (ISO Standard 3309-1979). hdlc_ll functions do not use any synchronization, mutexes, etc. Thus low level implementation is completely platform independent.
◆ HDLC_MIN_BUF_SIZE
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
◆ hdlc_ll_close()
Shutdowns all hdlc activity.
- Parameters
-
◆ hdlc_ll_get_buf_size()
int hdlc_ll_get_buf_size |
( |
int |
mtu | ) |
|
Returns minimum buffer size, required to hold hdlc low level data for desired payload size.
- Note
- This function calculates required buffer size based on CRC32
- Parameters
-
mtu | size of desired max payload in bytes |
- Returns
- size of the buffer required
◆ hdlc_ll_get_buf_size_ex()
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.
- Parameters
-
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 |
- Returns
- size of the buffer required
◆ hdlc_ll_init()
Initializes hdlc level and returns hdlc handle or NULL in case of error.
- Parameters
-
handle | pointer to hdlc handle variable |
init | pointer to hdlc_ll_struct_t structure, which defines user-specific configuration |
- Returns
- -1 if error 0 if success
◆ hdlc_ll_put()
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().
- Parameters
-
handle | hdlc handle |
data | pointer to new data to send |
len | size of data to send in bytes |
- Returns
- TINY_ERR_BUSY if TX queue is busy with another frame. TINY_ERR_INVALID_DATA if len is zero. TINY_SUCCESS if data is successfully sent
- Warning
- buffer with data must be available all the time until data are actually sent to tx hw channel. That is you need to use callback to understand, when buffer is not longer needed at hdlc low level. Or you can use hdlc_ll_reset() to reset hdlc tx state and to stop using passed buffer.
- Note
- TINY_ERR_BUSY and TINY_ERR_INVALID_DATA refer to putting new frame to TX hdlc queue.
◆ hdlc_ll_put_frame()
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().
- Parameters
-
handle | hdlc handle |
data | pointer to new data to send |
len | size of data to send in bytes |
- Returns
- TINY_ERR_BUSY if TX queue is busy with another frame. TINY_ERR_INVALID_DATA if len is zero. TINY_SUCCESS if data is successfully sent
- Warning
- buffer with data must be available all the time until data are actually sent to tx hw channel. That is you need to use callback to understand, when buffer is not longer needed at hdlc low level. Or you can use hdlc_ll_reset() to reset hdlc tx state and to stop using passed buffer.
- Note
- TINY_ERR_BUSY and TINY_ERR_INVALID_DATA refer to putting new frame to TX hdlc queue.
◆ hdlc_ll_reset()
Resets hdlc state.
Use this function, if hw error happened on tx or rx line, and this requires hardware change, and cancelling current operation.
- Parameters
-
handle | hdlc handle |
flags | HDLC_LL_RESET_TX_ONLY, HDLC_LL_RESET_RX_ONLY, HDLC_LL_RESET_BOTH |
◆ hdlc_ll_run_rx()
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.
- Note
- this API can be used in interrupt context, but please implement on_frame_read callback carefully.
This function will return the following codes in error field:
- TINY_ERR_DATA_TOO_LARGE if receiving data fails to fit incoming buffer
- TINY_ERR_FAILED if generic failure happened
- TINY_ERR_WRONG_CRC if crc field of incoming frame is incorrect
- TINY_SUCCESS if operation completed successfully
- Parameters
-
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. |
- Returns
- number of processed bytes from specified data buffer. Never returns negative value
◆ hdlc_ll_run_tx()
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.
- Parameters
-
handle | hdlc handle |
data | pointer to buffer to fill with data |
len | length of specified buffer |
- Returns
- number of bytes written to specified buffer