tinyproto
|
high level HDLC protocol implementation More...
Classes | |
struct | _hdlc_handle_t |
Structure describes configuration of lowest HDLC level Initialize this structure by 0 before passing to hdlc_init() function. More... | |
class | tinyproto::Hdlc |
Hdlc class incapsulates hdlc Protocol functionality. More... | |
Typedefs | |
typedef struct _hdlc_handle_t | hdlc_struct_t |
Structure describes configuration of lowest HDLC level Initialize this structure by 0 before passing to hdlc_init() function. | |
typedef struct _hdlc_handle_t * | hdlc_handle_t |
hdlc handle | |
Functions | |
hdlc_handle_t | hdlc_init (hdlc_struct_t *hdlc_info) |
Initializes hdlc level and returns hdlc handle or NULL in case of error. More... | |
int | hdlc_close (hdlc_handle_t handle) |
Shutdowns all hdlc activity. More... | |
void | hdlc_reset (hdlc_handle_t handle) |
Resets hdlc state. More... | |
int | hdlc_run_rx (hdlc_handle_t handle, const void *data, int len, int *error) |
Processes incoming data. More... | |
int | hdlc_run_tx (hdlc_handle_t handle) |
Runs transmission at hdlc level. More... | |
int | hdlc_get_tx_data (hdlc_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_send (hdlc_handle_t handle, const void *data, int len, uint32_t timeout) |
Puts next frame for sending. More... | |
high level HDLC protocol implementation
this group implements high level HDLC functions, which implement framing only according to RFC 1662: 0x7E, 0x7D, 0x20 (ISO Standard 3309-1979).
int hdlc_close | ( | hdlc_handle_t | handle | ) |
Shutdowns all hdlc activity.
handle | handle to hdlc instance |
int hdlc_get_tx_data | ( | hdlc_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 | handle to hdlc instance |
data | pointer to buffer to fill with data |
len | length of specified buffer |
hdlc_handle_t hdlc_init | ( | hdlc_struct_t * | hdlc_info | ) |
Initializes hdlc level and returns hdlc handle or NULL in case of error.
hdlc_info | pointer to hdlc_struct_t structure, which defines user-specific configuration |
void hdlc_reset | ( | hdlc_handle_t | handle | ) |
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 | handle to hdlc instance |
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.
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_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 | 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. |
int hdlc_run_tx | ( | hdlc_handle_t | handle | ) |
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.
handle | handle to hdlc instance |
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 sent 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 sent 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().
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 |