tinyproto
Classes | Macros | Typedefs | Enumerations | Functions
Tiny Full Duplex API functions

Classes

struct  tiny_fd_init_t_
 This structure is used for initialization of Tiny Full Duplex protocol. More...
 
class  tinyproto::IFd
 IFd class incapsulates Full Duplex Protocol functionality. More...
 

Macros

#define TINY_FD_PRIMARY_ADDR   (0)
 Address of primary stations to use with the protocol. More...
 

Typedefs

typedef struct tiny_fd_data_ttiny_fd_handle_t
 This handle points to service data, required for full-duplex functioning.
 
typedef void(* tiny_fd_log_frame_cb_t) (void *udata, tiny_fd_handle_t handle, tiny_fd_frame_direction_t direction, tiny_fd_frame_type_t frame_type, tiny_fd_frame_subtype_t frame_subtype, uint8_t ns, uint8_t nr, const uint8_t *data, int len)
 tiny_fd_log_frame_cb_t is a callback function, which is called every time frame is sent or received. More...
 
typedef struct tiny_fd_init_t_ tiny_fd_init_t
 This structure is used for initialization of Tiny Full Duplex protocol.
 

Enumerations

enum  { TINY_FD_MODE_ABM = 0x00, TINY_FD_MODE_NRM = 0x01, TINY_FD_MODE_ARM = 0x02 }
 
enum  tiny_fd_frame_type_t { TINY_FD_FRAME_TYPE_I = 0x00, TINY_FD_FRAME_TYPE_S = 0x01, TINY_FD_FRAME_TYPE_U = 0x02 }
 Enumeration of frame types used in Tiny Full Duplex protocol. More...
 
enum  tiny_fd_frame_subtype_t {
  TINY_FD_FRAME_SUBTYPE_RR = 0x00, TINY_FD_FRAME_SUBTYPE_REJ = 0x08, TINY_FD_FRAME_SUBTYPE_UA = 0x60, TINY_FD_FRAME_SUBTYPE_FRMR = 0x84,
  TINY_FD_FRAME_SUBTYPE_RSET = 0x8C, TINY_FD_FRAME_SUBTYPE_SABM = 0x2C, TINY_FD_FRAME_SUBTYPE_SNRM = 0x80, TINY_FD_FRAME_SUBTYPE_DISC = 0x40
}
 Enumeration of frame subtypes used in Tiny Full Duplex protocol. More...
 
enum  tiny_fd_frame_direction_t { TINY_FD_FRAME_DIRECTION_IN = 0x00, TINY_FD_FRAME_DIRECTION_OUT = 0x01 }
 Enumeration of frame directions used in Tiny Full Duplex protocol. More...
 

Functions

int tiny_fd_init (tiny_fd_handle_t *handle, tiny_fd_init_t *init)
 Initialized communication for Tiny Full Duplex protocol. More...
 
int tiny_fd_get_status (tiny_fd_handle_t handle)
 Returns status of the connection. More...
 
int tiny_fd_disconnect (tiny_fd_handle_t handle)
 Sends DISC command to remote side. More...
 
void tiny_fd_close (tiny_fd_handle_t handle)
 stops Tiny Full Duplex state machine More...
 
int tiny_fd_get_tx_data (tiny_fd_handle_t handle, void *data, int len, uint32_t timeout)
 runs tx processing to fill specified buffer with data. More...
 
int tiny_fd_run_tx (tiny_fd_handle_t handle, write_block_cb_t write_func)
 sends tx data to the communication channel via user callback write_func(). More...
 
int tiny_fd_on_rx_data (tiny_fd_handle_t handle, const void *data, int len)
 runs rx bytes processing for specified buffer. More...
 
int tiny_fd_run_rx (tiny_fd_handle_t handle, read_block_cb_t read_func)
 reads rx data from the communication channel via user callback read_func() More...
 
int tiny_fd_send_packet_to (tiny_fd_handle_t handle, uint8_t address, const void *buf, int len, uint32_t timeout)
 Sends userdata over full-duplex protocol. More...
 
int tiny_fd_buffer_size_by_mtu (int mtu, int window)
 Returns minimum required buffer size for specified parameters. More...
 
int tiny_fd_buffer_size_by_mtu_ex (uint8_t peers_count, int mtu, int tx_window, hdlc_crc_t crc_type, int rx_window)
 Returns minimum required buffer size for specified parameters. More...
 
int tiny_fd_get_mtu (tiny_fd_handle_t handle)
 returns max packet size in bytes. More...
 
int tiny_fd_send_to (tiny_fd_handle_t handle, uint8_t address, const void *buf, int len, uint32_t timeout)
 Sends userdata over full-duplex protocol. More...
 
void tiny_fd_set_ka_timeout (tiny_fd_handle_t handle, uint32_t keep_alive)
 Sets keep alive timeout in milliseconds. More...
 
int tiny_fd_register_peer (tiny_fd_handle_t handle, uint8_t address)
 Registers remote peer with specified address. More...
 
int tiny_fd_send (tiny_fd_handle_t handle, const void *buf, int len, uint32_t timeout)
 Sends userdata over full-duplex protocol to primary station. More...
 
int tiny_fd_send_packet (tiny_fd_handle_t handle, const void *buf, int len, uint32_t timeout)
 Sends packet to primary station. More...
 

Detailed Description

Macro Definition Documentation

◆ TINY_FD_PRIMARY_ADDR

#define TINY_FD_PRIMARY_ADDR   (0)

Address of primary stations to use with the protocol.

See RFC.

Typedef Documentation

◆ tiny_fd_log_frame_cb_t

typedef void(* tiny_fd_log_frame_cb_t) (void *udata, tiny_fd_handle_t handle, tiny_fd_frame_direction_t direction, tiny_fd_frame_type_t frame_type, tiny_fd_frame_subtype_t frame_subtype, uint8_t ns, uint8_t nr, const uint8_t *data, int len)

tiny_fd_log_frame_cb_t is a callback function, which is called every time frame is sent or received.

This callback is useful for debugging purposes.

The main difference between this callback and on_frame_read_cb_t / on_frame_send_cb_t is that this callback is called for every frame, regardless of whether it is sent or received: I-frames, S-frames or U-frames. It provides detailed information about the frame, including its type, subtype, sequence numbers and data.

Parameters
udatauser data, passed during Tiny Full Duplex initialization.
handlehandle of Tiny.
directiondirection of the frame, can be TINY_FD_FRAME_DIRECTION_IN or TINY_FD_FRAME_DIRECTION_OUT.
frame_typetype of the frame, can be TINY_FD_FRAME_TYPE_I, TINY_FD_FRAME_TYPE_S or TINY_FD_FRAME_TYPE_U.
frame_subtypesubtype of the frame, can be TINY_FD_FRAME_SUBTYPE_RR, TINY_FD_FRAME_SUBTYPE_REJ, TINY_FD_FRAME_SUBTYPE_UA, TINY_FD_FRAME_SUBTYPE_FRMR, TINY_FD_FRAME_SUBTYPE_RSET, TINY_FD_FRAME_SUBTYPE_SABM, TINY_FD_FRAME_SUBTYPE_SNRM or TINY_FD_FRAME_SUBTYPE_DISC.
nsN(S) sequence number of the frame.
nrN(R) sequence number of the frame.
datapointer to the frame data.
lenlength of the frame data.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
TINY_FD_MODE_ABM 

Asynchronous balanced mode - the default mode of HDLC protocol.

ABM adds combined terminal which can act as both a primary and a secondary.

TINY_FD_MODE_NRM 

Normal response mode allows the secondary-to-primary link to be shared without contention, because it has the primary give the secondaries permission to transmit one at a time.

Warning
This mode is still in development
TINY_FD_MODE_ARM 

Asynchronous response mode.

NOT IMPLEMENTED.

◆ tiny_fd_frame_direction_t

Enumeration of frame directions used in Tiny Full Duplex protocol.

Enumerator
TINY_FD_FRAME_DIRECTION_IN 

Frame is incoming.

TINY_FD_FRAME_DIRECTION_OUT 

Frame is outgoing.

◆ tiny_fd_frame_subtype_t

Enumeration of frame subtypes used in Tiny Full Duplex protocol.

These subtypes are used for S-frames and U-frames. The I-frames do not have subtypes, so this enumeration is not used for I-frames.

Enumerator
TINY_FD_FRAME_SUBTYPE_RR 

S-frame subtype RR.

TINY_FD_FRAME_SUBTYPE_REJ 

S-frame subtype REJ.

TINY_FD_FRAME_SUBTYPE_UA 

U-frame subtype UA.

TINY_FD_FRAME_SUBTYPE_FRMR 

U-frame subtype FRMR.

TINY_FD_FRAME_SUBTYPE_RSET 

U-frame subtype RSET.

TINY_FD_FRAME_SUBTYPE_SABM 

U-frame subtype SABM.

TINY_FD_FRAME_SUBTYPE_SNRM 

U-frame subtype SNRM.

TINY_FD_FRAME_SUBTYPE_DISC 

U-frame subtype DISC.

◆ tiny_fd_frame_type_t

Enumeration of frame types used in Tiny Full Duplex protocol.

Enumerator
TINY_FD_FRAME_TYPE_I 

I-frame.

TINY_FD_FRAME_TYPE_S 

S-frame.

TINY_FD_FRAME_TYPE_U 

U-frame.

Function Documentation

◆ tiny_fd_buffer_size_by_mtu()

int tiny_fd_buffer_size_by_mtu ( int  mtu,
int  window 
)

Returns minimum required buffer size for specified parameters.

Note
This function calculates buffer requirements based on HDLC_CRC_16.
Parameters
mtusize of desired user payload in bytes.
windowmaximum tx queue size of I-frames.

◆ tiny_fd_buffer_size_by_mtu_ex()

int tiny_fd_buffer_size_by_mtu_ex ( uint8_t  peers_count,
int  mtu,
int  tx_window,
hdlc_crc_t  crc_type,
int  rx_window 
)

Returns minimum required buffer size for specified parameters.

Parameters
peers_countmaximum number of peers supported by the primary. Use 0 or 1 for secondary devices
mtusize of desired user payload in bytes.
tx_windowmaximum tx queue size of I-frames.
crc_typecrc type to be used with FD protocol
rx_windownumber of RX ring buffer in frames

◆ tiny_fd_close()

void tiny_fd_close ( tiny_fd_handle_t  handle)

stops Tiny Full Duplex state machine

stops Tiny Full Duplex state machine.

Parameters
handlehandle of full-duplex protocol

◆ tiny_fd_disconnect()

int tiny_fd_disconnect ( tiny_fd_handle_t  handle)

Sends DISC command to remote side.

The function sends DISC command to remote side and exits. It doesn't wait for UA answer back.

Parameters
handlepointer to Tiny Full Duplex data
Returns
TINY_ERR_INVALID_DATA in case of error TINY_SUCCESS if DISC command is put to tx queue successfully TINY_ERR_FAILED if DISC command cannot be put to tx queue since it is full.

◆ tiny_fd_get_mtu()

int tiny_fd_get_mtu ( tiny_fd_handle_t  handle)

returns max packet size in bytes.

Returns max packet size in bytes.

Parameters
handletiny_fd_handle_t handle
Returns
mtu size in bytes
See also
tiny_fd_send_packet

◆ tiny_fd_get_status()

int tiny_fd_get_status ( tiny_fd_handle_t  handle)

Returns status of the connection.

The function returns status of the connection

Parameters
handlepointer to Tiny Full Duplex data
Returns
TINY_ERR_INVALID_DATA in case of error TINY_SUCCESS if connection is established TINY_ERR_FAILED if protocol is in disconnected state

◆ tiny_fd_get_tx_data()

int tiny_fd_get_tx_data ( tiny_fd_handle_t  handle,
void *  data,
int  len,
uint32_t  timeout 
)

runs tx processing to fill specified buffer with data.

Runs tx processing to fill specified buffer with data.

Parameters
handlehandle of full-duplex protocol
datapointer to buffer to fill with tx data
lenmaximum size of specified buffer
timeoutin milliseconds to wait for the data to be ready for sending
Returns
number of bytes written to specified buffer

◆ tiny_fd_init()

int tiny_fd_init ( tiny_fd_handle_t handle,
tiny_fd_init_t init 
)

Initialized communication for Tiny Full Duplex protocol.

The function initializes internal structures for Tiny Full Duplex state machine.

Parameters
handle- pointer to Tiny Full Duplex data
init- pointer to tiny_fd_init_t data.
Returns
TINY_NO_ERROR in case of success. TINY_ERR_FAILED if init parameters are incorrect.
Remarks
This function is not thread safe.

◆ tiny_fd_on_rx_data()

int tiny_fd_on_rx_data ( tiny_fd_handle_t  handle,
const void *  data,
int  len 
)

runs rx bytes processing for specified buffer.

Runs rx bytes processing for specified buffer. This is alternative method to run Full-duplex protocol for rx data. Use it, when you wish to control reading from hardware by yourself.

Parameters
handlehandle of full-duplex protocol
datapointer to data to process
lenlength of data to process
Returns
TINY_SUCCESS

◆ tiny_fd_register_peer()

int tiny_fd_register_peer ( tiny_fd_handle_t  handle,
uint8_t  address 
)

Registers remote peer with specified address.

This API can be used only in NRM mode on primary station. The allowable range of the addresses is 1 - 62. The addresses 0, 63 cannot be used as they are dedicated to primary station and legacy support. After secondary station is registered, the primary will send establish connection to remote station. If remote station is not yet ready, this can cause reducing of the primary station performance.

Parameters
handlepointer to tiny_fd_handle_t
addressaddress in range 1 - 62.
Returns
TINY_SUCCESS in case of success or TINY_ERR_FAILED if there is no free slots for new peer, wrong address is specified, or peer is already registered.

◆ tiny_fd_run_rx()

int tiny_fd_run_rx ( tiny_fd_handle_t  handle,
read_block_cb_t  read_func 
)

reads rx data from the communication channel via user callback read_func()

Reads rx data from the communication channel via user callback read_func(). Internally this function has 4-byte buffer, and tries to read 4 bytes from the channel. Then received bytes are processed by the protocol. If FD protocol detects new incoming message then it calls on_send_callback. If no data available in the channel, the function returns immediately after read_func() callback returns control.

Parameters
handlehandle of full-duplex protocol
read_funccallback to the function to read data from the physical channel.
Returns
number of bytes received

◆ tiny_fd_run_tx()

int tiny_fd_run_tx ( tiny_fd_handle_t  handle,
write_block_cb_t  write_func 
)

sends tx data to the communication channel via user callback write_func().

Sends tx data to the communication channel via user callback write_func(). Internally this function generates next 4 bytes to send (or less if nothing to send), and calls user callback write_func() until all generated bytes are sent, or error happens. This function helps to simplify application code.

Parameters
handlehandle of full-duplex protocol
write_funccallback to the function to write data to the physical channel.
Returns
number of bytes sent

◆ tiny_fd_send()

int tiny_fd_send ( tiny_fd_handle_t  handle,
const void *  buf,
int  len,
uint32_t  timeout 
)

Sends userdata over full-duplex protocol to primary station.

Sends userdata over full-duplex protocol to primary station. For details, please, refer to tiny_fd_send_to().

Parameters
handletiny_fd_handle_t handle
bufdata to send
lenlength of data to send
timeouttimeout in milliseconds, will be used for each block sending
Returns
Number of bytes sent

◆ tiny_fd_send_packet()

int tiny_fd_send_packet ( tiny_fd_handle_t  handle,
const void *  buf,
int  len,
uint32_t  timeout 
)

Sends packet to primary station.

For details, please, refer to tiny_fd_send_packet_to().

Parameters
handletiny_fd_handle_t handle
bufdata to send
lenlength of data to send
timeouttimeout in milliseconds to wait until data are placed to outgoing queue
Returns
Success result or error code
Note
This function doesn't return number of bytes sent, but rather returns TINY_SUCCESS in case of success, or error code in case of failure.

◆ tiny_fd_send_packet_to()

int tiny_fd_send_packet_to ( tiny_fd_handle_t  handle,
uint8_t  address,
const void *  buf,
int  len,
uint32_t  timeout 
)

Sends userdata over full-duplex protocol.

Sends userdata over full-duplex protocol. Note, that this command will return success, when data are copied to internal queue. That doesn't mean that data are physically sent, but they are enqueued for sending.

Note
the maximum size of the allowed buffer to send is equal to mtu size set for the protocol. If you want to send data larger than mtu size, please, use tiny_fd_send() function.

When timeout happens, the data were not actually enqueued. Call this function once again. If TINY_ERR_DATA_TOO_LARGE is returned, try to send less data. If you don't want to care about mtu size, please, use different function tiny_fd_send()..

Parameters
handletiny_fd_handle_t handle
addressaddress of remote peer. For primary device, please use TINY_FD_PRIMARY_ADDR
bufdata to send
lenlength of data to send
timeouttimeout in milliseconds to wait until data are placed to outgoing queue
Returns
Success result or error code:
  • TINY_SUCCESS if user data are put to internal queue.
  • TINY_ERR_TIMEOUT if no room in internal queue to put data. Retry operation once again.
  • TINY_ERR_FAILED if request was cancelled, by tiny_fd_close() or other error happened.
  • TINY_ERR_UNKNOWN_PEER if peer is not known to the system.
  • TINY_ERR_DATA_TOO_LARGE if user data are too big to fit in tx buffer.

◆ tiny_fd_send_to()

int tiny_fd_send_to ( tiny_fd_handle_t  handle,
uint8_t  address,
const void *  buf,
int  len,
uint32_t  timeout 
)

Sends userdata over full-duplex protocol.

Sends userdata over full-duplex protocol. Note, that this function will try to send all data from buf. In success case it will return number of bytes sent, equal to len input parameter. But if timeout happens, it returns number of bytes actually enqueued.

If you constantly get number of sent bytes less than expected, try to increase timeout value of the speed of used communication channel.

Parameters
handletiny_fd_handle_t handle
addressaddress of remote peer. For primary device, please use TINY_FD_PRIMARY_ADDR
bufdata to send
lenlength of data to send
timeouttimeout in milliseconds, will be used for each block sending
Returns
Number of bytes sent

◆ tiny_fd_set_ka_timeout()

void tiny_fd_set_ka_timeout ( tiny_fd_handle_t  handle,
uint32_t  keep_alive 
)

Sets keep alive timeout in milliseconds.

This timeout is used to send special RR frames, when no user data queued for sending.

Parameters
handlepointer to tiny_fd_handle_t
keep_alivetimeout in milliseconds