low level HDLC protocol function - only framing
More...
|
hdlc_handle_t | hdlc_init (hdlc_struct_t *hdlc_info) |
|
int | hdlc_close (hdlc_handle_t handle) |
|
void | hdlc_reset (hdlc_handle_t handle) |
|
int | hdlc_run_rx (hdlc_handle_t handle, const void *data, int len, int *error) |
|
int | hdlc_run_rx_until_read (hdlc_handle_t handle, read_block_cb_t readcb, void *user_data, uint16_t timeout) |
|
void | hdlc_set_rx_buffer (hdlc_handle_t handle, void *data, int size) |
|
int | hdlc_run_tx (hdlc_handle_t handle) |
|
int | hdlc_send (hdlc_handle_t handle, const void *data, int len, uint32_t timeout) |
|
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).
◆ hdlc_struct_t
Structure describes configuration of lowest HDLC level Initialize this structure by 0 before passing to hdlc_init() function.
◆ hdlc_crc_t
HDLC CRC options, available
Enumerator |
---|
HDLC_CRC_DEFAULT | If default is specified HDLC will auto select CRC option.
|
HDLC_CRC_8 | Simple sum of all bytes in user payload.
|
HDLC_CRC_16 | CCITT-16.
|
HDLC_CRC_32 | CCITT-32.
|
HDLC_CRC_OFF | Disable CRC field.
|
◆ hdlc_close()
Shutdowns all hdlc activity
- Parameters
-
handle | handle to hdlc instance |
◆ hdlc_init()
Initializes hdlc level and returns hdlc handle or NULL in case of error.
- Parameters
-
hdlc_info | pointer to hdlc_struct_t structure, which defines user-specific configuration |
- Returns
- handle to hdlc instance or NULL.
- Warning
- hdlc_info structure passed to the function must be allocated all the time.
◆ hdlc_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 | handle to hdlc instance |
◆ hdlc_run_rx()
int hdlc_run_rx |
( |
hdlc_handle_t |
handle, |
|
|
const void * |
data, |
|
|
int |
len, |
|
|
int * |
error |
|
) |
| |
Processes incoming data. Implementation of reading data from hw is user responsibility. If hdlc_run_rx() returns value less than size of data passed to the function, then hdlc_run_rx() must be called later second time with the pointer to and size of not processed bytes.
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 | handle to hdlc instance |
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.
◆ hdlc_run_rx_until_read()
Runs rx cycle until full frame received.
- Parameters
-
handle | handle to hdlc instance |
readcb | callback to read bytes from channel function |
user_data | user data to pass to readcb callback function |
timeout | timeout in milliseconds to wait for new frame. |
- Returns
- TINY_SUCCESS if operation completed successfully
- TINY_ERR_FAILED if generic failure happened
- TINY_ERR_TIMEOUT if operation cannot be completed in specified time.
◆ hdlc_run_tx()
Runs transmission at hdlc level. If there is frame to send, or send is in progress, this function will call send_tx() callback multiple times. If send_tx() callback reports 0, that means that hw device is busy and in this case hdlc_run_tx() will return immediately.
- Warning
- this function must be called from one thread only.
- Parameters
-
handle | handle to hdlc instance |
- Returns
- negative value in case of error 0 if hw is busy, or no data is waiting for sending positive number of bytes passed to hw channel.
◆ hdlc_send()
int hdlc_send |
( |
hdlc_handle_t |
handle, |
|
|
const void * |
data, |
|
|
int |
len, |
|
|
uint32_t |
timeout |
|
) |
| |
Puts next frame for sending. This function is thread-safe. You may call it from parallel threads.
If multithread_mode is specificed for hdlc protocol, then hdlc_send() function will wait for specified timeout until some tx thread, implemented by application, completes sending of the frame. If timeout happens, but the frame is not sent still, hdlc level rejects sending of the frame. In this case the frame will be set partially, causing RX errors on other side. Please use reasonable timeout.
If multithread_mode is disabled for hdlc protocol, then hdlc_send() function will start frame sending immediately by itself if TX line is not busy. hdlc_send() will block until frame is sent or timeout. If timeout happens, but the frame is not sent still, hdlc level rejects sending of the frame. In this case the frame will be set partially, causing RX errors on other side. Please use reasonable timeout.
If timeout is specified as 0, hdlc_send() 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_run_tx().
- Parameters
-
handle | handle to hdlc instance |
data | pointer to new data to send (can be NULL is you need to retry sending) |
len | size of data to send in bytes |
timeout | time in milliseconds to wait for data to be sent |
- Returns
- TINY_ERR_FAILED if generic error happens TINY_ERR_BUSY if TX queue is busy with another frame. TINY_ERR_TIMEOUT if send operation cannot be completed in specified time. 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 if you use zero timeout, you need to use callback to understand, when buffer is not longer needed at hdlc level.
- Note
- TINY_ERR_BUSY and TINY_ERR_INVALID_DATA refer to putting new frame to TX hdlc queue.
◆ hdlc_set_rx_buffer()
void hdlc_set_rx_buffer |
( |
hdlc_handle_t |
handle, |
|
|
void * |
data, |
|
|
int |
size |
|
) |
| |
Sets new RX buffer for hdlc protocol. This function is not thread-safe.
- Parameters
-
handle | handle to hdlc instance |
data | pointer to rx buffer |
size | size of rx buffer in bytes |