Tiny protocol  0.7.0
Tiny communication protocol for microcontrollers
Functions
Tiny simple API functions

Functions

int tiny_init (STinyData *handle, write_block_cb_t write_func, read_block_cb_t read_func, void *pdata)
 
int tiny_close (STinyData *handle)
 
int tiny_send (STinyData *handle, uint16_t *uid, uint8_t *pbuf, int len, uint8_t flags)
 sends frame with user payload to communication channel More...
 
int tiny_read (STinyData *handle, uint16_t *uid, uint8_t *pbuf, int len, uint8_t flags)
 
int tiny_simple_send (STinyData *handle, uint8_t *pbuf, int len)
 sends frame with user payload to communication channel in blocking mode More...
 
int tiny_simple_read (STinyData *handle, uint8_t *pbuf, int len)
 reads frame from the channel in blocking mode. More...
 

Detailed Description

Function Documentation

◆ tiny_close()

int tiny_close ( STinyData handle)

The function closes channel.

Parameters
handle- pointer to Tiny data.
See also
tiny_init()
Returns
TINY_ERR_INVALID_DATA, TINY_NO_ERROR.
Remarks
This function is not thread safe.

◆ tiny_init()

int tiny_init ( STinyData handle,
write_block_cb_t  write_func,
read_block_cb_t  read_func,
void *  pdata 
)

The function initializes internal structures for Tiny channel and return handle to be used with all Tiny and IPC functions.

Parameters
handle- pointer to Tiny data
write_func- pointer to write data function (to communication channel).
read_func- pointer to read function (from communication channel). read_func is not required and should be NULL, if event-based API of Tiny Protocol is used. For event-based API please, refer to tiny_on_rx_byte().
pdata- pointer to a user private data. This pointer is passed to write_func/read_func.
See also
write_block_cb_t
read_block_cb_t
Returns
TINY_NO_ERROR or error code.
Remarks
This function is not thread safe.

◆ tiny_read()

int tiny_read ( STinyData handle,
uint16_t *  uid,
uint8_t *  pbuf,
int  len,
uint8_t  flags 
)

The function reads data from communication channel frame format: 0x7E, data..., FCS, 0x7E.

Parameters
handle- pointer to Tiny data.
uid- pointer to 16-bit uid variable to fill with packet info, can be NULL.
pbufa const pointer to unsigned char - buffer with data to send
lenan integer argument - length of data to send
flags- TINY_FLAG_NO_WAIT
See also
TINY_ERR_FAILED
TINY_ERR_DATA_TOO_LARGE
TINY_ERR_OUT_OF_SYNC
TINY_ERR_BUSY
Returns
TINY_ERR_OUT_OF_SYNC - if first byte received from the channel is not packet marker. You may ignore this error. TINY_ERR_DATA_TOO_LARGE - if incoming packet is too large to fit the buffer TINY_ERR_FAILED - if something wrong with received data TINY_BUSY - if another receive operation is in progress. TINY_NO_ERROR - if nothing is received in non-blocking mode greater 0 - number of received bytes in pbuf buffer. If uid is used result includes length of uid field, but actual payload should be considered as result - sizeof(uint16_t);
Remarks
This function is not thread safe.

◆ tiny_send()

int tiny_send ( STinyData handle,
uint16_t *  uid,
uint8_t *  pbuf,
int  len,
uint8_t  flags 
)

sends frame with user payload to communication channel

The function sends data to communication channel in the following frame format: 0x7E, data..., FCS, 0x7E.

Note
if flags field is set to TINY_FLAG_NO_WAIT, then this function may remember pbuf pointer and return immediately. So, it is responsibility of the caller to make pbuf data to be available all the time until frame is sent.
Parameters
handle- pointer to Tiny data.
uid- pointer to 16-bit variable containing packet uid, can be NULL. uid value must be spelled in network order bytes.
pbuf- a const pointer to unsigned char - buffer with data to send
len- an integer argument - length of data to send
flags- TINY_FLAG_NO_WAIT, TINY_FLAG_WAIT_FOREVER, TINY_FLAG_LOCK_SEND
See also
TINY_ERR_INVALID_DATA
TINY_ERR_FAILED
TINY_FLAG_NO_WAIT
TINY_FLAG_WAIT_FOREVER
Returns
TINY_ERR_INVALID_DATA, TINY_ERR_FAILED or number of sent bytes.
Note
- if you need to start send operation in non-blocking mode, call function with TINY_FLAG_LOCK_SEND flag for the first time. Subsequent calls should be done without TINY_FLAG_LOCK_SEND flag until tiny_send returns length of send data or error code.
Remarks
This function is thread safe.

Returns negative value in case of error length of sent data

◆ tiny_simple_read()

int tiny_simple_read ( STinyData handle,
uint8_t *  pbuf,
int  len 
)

reads frame from the channel in blocking mode.

The function reads user data from communication channel

Parameters
handle- pointer to Tiny data.
pbufa const pointer to unsigned char - buffer with data to send
lenan integer argument - length of data to send
See also
TINY_ERR_INVALID_DATA
TINY_ERR_FAILED
TINY_ERR_DATA_TOO_LARGE
TINY_ERR_OUT_OF_SYNC
TINY_ERR_BUSY
Returns
TINY_ERR_INVALID_DATA, TINY_ERR_FAILED, TINY_ERR_OUT_OF_SYNC, TINY_ERR_BUSY, TINY_ERR_DATA_TOO_LARGE or number of sent bytes.
Note
TINY_ERR_DATA_TOO_LARGE can be returned in successful case. If frame is received, but passed buffer to the function is too small to fit all.
Remarks
This function is not thread safe.

◆ tiny_simple_send()

int tiny_simple_send ( STinyData handle,
uint8_t *  pbuf,
int  len 
)

sends frame with user payload to communication channel in blocking mode

The function sends data to communication channel. Unlike tiny_send(), the function works in blocking mode, i.e. it returns control only if user data are successfully sent, or in case of error.

Parameters
handle- pointer to Tiny data.
pbuf- a const pointer to unsigned char - buffer with data to send
len- an integer argument - length of data to send
See also
TINY_ERR_INVALID_DATA
TINY_ERR_FAILED
Returns
TINY_ERR_INVALID_DATA, TINY_ERR_FAILED or number of sent bytes.
Remarks
This function is thread safe.