Tiny protocol  0.11.0
Tiny communication protocol for microcontrollers
tiny_fd.h
Go to the documentation of this file.
1 /*
2  Copyright 2019-2020 (C) Alexey Dynda
3 
4  This file is part of Tiny Protocol Library.
5 
6  Protocol Library is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Protocol Library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with Protocol Library. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
29 #pragma once
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #include <stdint.h>
36 #include "proto/hdlc/tiny_hdlc.h"
37 #include "proto/hal/tiny_types.h"
38 
44 struct tiny_fd_data_t;
45 
50 typedef struct tiny_fd_data_t *tiny_fd_handle_t;
51 
55 typedef struct tiny_fd_init_t_
56 {
62  void * pdata;
67 
72  void * buffer;
73 
75  uint16_t buffer_size;
76 
81  uint16_t send_timeout;
82 
87  uint16_t retry_timeout;
88 
92  uint8_t retries;
93 
100 
107  uint8_t window_frames;
109 
121 extern int tiny_fd_init(tiny_fd_handle_t *handle,
122  tiny_fd_init_t *init);
123 
131 extern void tiny_fd_close(tiny_fd_handle_t handle);
132 
147 extern int tiny_fd_run_tx(tiny_fd_handle_t handle, uint16_t timeout);
148 
159 extern int tiny_fd_get_tx_data(tiny_fd_handle_t handle, void *data, int len );
160 
171 extern int tiny_fd_run_rx(tiny_fd_handle_t handle, uint16_t timeout);
172 
186 extern int tiny_fd_on_rx_data(tiny_fd_handle_t handle, const void *data, int len);
187 
209 extern int tiny_fd_send(tiny_fd_handle_t handle, const void *buf, int len);
210 
216 extern int tiny_fd_buffer_size_by_mtu( int mtu, int max_tx_frames );
217 
224 extern void tiny_fd_set_ka_timeout( tiny_fd_handle_t handle, uint32_t keep_alive );
225 
230 #ifdef __cplusplus
231 }
232 #endif
hdlc_crc_t
Definition: tiny_hdlc.h:54
int tiny_fd_buffer_size_by_mtu(int mtu, int max_tx_frames)
Definition: tiny_fd.c:881
on_frame_cb_t on_sent_cb
Callback to get notification of sent frames. Callback is called from tiny_fd_run_tx() context...
Definition: tiny_fd.h:66
int tiny_fd_run_rx(tiny_fd_handle_t handle, uint16_t timeout)
runs rx processing for specified period of time.
Definition: tiny_fd.c:582
int tiny_fd_send(tiny_fd_handle_t handle, const void *buf, int len)
Sends userdata over full-duplex protocol.
Definition: tiny_fd.c:834
read_block_cb_t read_func
callback function to read bytes from the physical channel
Definition: tiny_fd.h:60
struct tiny_fd_init_t_ tiny_fd_init_t
struct tiny_fd_data_t * tiny_fd_handle_t
Definition: tiny_fd.h:50
uint16_t buffer_size
maximum input buffer size, see tiny_fd_buffer_size_by_mtu()
Definition: tiny_fd.h:75
uint8_t window_frames
Definition: tiny_fd.h:107
uint16_t retry_timeout
Definition: tiny_fd.h:87
int(* read_block_cb_t)(void *pdata, void *buffer, int size)
Definition: tiny_types.h:141
int tiny_fd_run_tx(tiny_fd_handle_t handle, uint16_t timeout)
runs tx processing for specified period of time.
Definition: tiny_fd.c:742
uint16_t send_timeout
Definition: tiny_fd.h:81
void(* on_frame_cb_t)(void *handle, uint16_t uid, uint8_t *pdata, int size)
Definition: tiny_types.h:154
Tiny protocol Types.
hdlc_crc_t crc_type
Definition: tiny_fd.h:99
void * buffer
Definition: tiny_fd.h:72
int tiny_fd_get_tx_data(tiny_fd_handle_t handle, void *data, int len)
runs tx processing to fill specified buffer with data.
Definition: tiny_fd.c:779
int(* write_block_cb_t)(void *pdata, const void *buffer, int size)
Definition: tiny_types.h:130
on_frame_cb_t on_frame_cb
callback function to process incoming frames. Callback is called from tiny_fd_run_rx() context...
Definition: tiny_fd.h:64
void tiny_fd_close(tiny_fd_handle_t handle)
stops Tiny Full Duplex state machine
Definition: tiny_fd.c:565
void * pdata
user data for block read/write functions
Definition: tiny_fd.h:62
int tiny_fd_init(tiny_fd_handle_t *handle, tiny_fd_init_t *init)
Initialized communication for Tiny Full Duplex protocol.
Definition: tiny_fd.c:483
void tiny_fd_set_ka_timeout(tiny_fd_handle_t handle, uint32_t keep_alive)
Definition: tiny_fd.c:888
int tiny_fd_on_rx_data(tiny_fd_handle_t handle, const void *data, int len)
runs rx bytes processing for specified buffer.
Definition: tiny_fd.c:614
uint8_t retries
Definition: tiny_fd.h:92
Definition: tiny_fd.h:55
write_block_cb_t write_func
callback function to write bytes to the physical channel
Definition: tiny_fd.h:58