Tiny protocol  0.7.0
Tiny communication protocol for microcontrollers
tiny_hd.h
Go to the documentation of this file.
1 /*
2  Copyright 2017-2019 (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 
27 #ifndef _TINY_HALF_DUPLEX_H_
28 #define _TINY_HALF_DUPLEX_H_
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #include <stdint.h>
35 #include "proto/hdlc/tiny_hdlc.h"
37 
38 
43 typedef struct STinyHdData_
44 {
45 #ifndef DOXYGEN_SHOULD_SKIP_THIS
46  hdlc_struct_t _hdlc;
47  uint8_t _sent;
48 #endif
56  uint16_t timeout;
58  uint16_t uid;
66  void * user_data;
67 } STinyHdData;
68 
69 
73 typedef struct STinyHdInit_
74 {
80  void * pdata;
84  void * inbuf;
86  uint16_t inbuf_size;
88  uint16_t timeout;
96  hdlc_crc_t crc_type;
97 } STinyHdInit;
98 
115 extern int tiny_hd_init(STinyHdData * handle,
116  STinyHdInit * init);
117 
125 extern void tiny_hd_close(STinyHdData * handle);
126 
150 extern int tiny_hd_run(STinyHdData * handle);
151 
171 extern int tiny_send_wait_ack(STinyHdData *handle, void *buf, uint16_t len);
172 
173 #if 0
174 static inline STinyData * hd_to_tiny(STinyHdData * handle)
175 {
176  return &handle->handle;
177 }
178 
179 static inline STinyHdData * tiny_to_hd(STinyData * handle)
180 {
181  return (STinyHdData *)handle;
182 }
183 #endif
184 
189 #ifdef __cplusplus
190 }
191 #endif
192 
193 #endif /* _TINY_HALFDUPLEX_PROTOCOL_H_ */
int(* write_block_cb_t)(void *pdata, const void *buffer, int size)
Definition: tiny_proto_types.h:114
int tiny_hd_init(STinyHdData *handle, STinyHdInit *init)
Initialized communication for Tiny Half Duplex protocol.
Definition: tiny_hd.c:174
uint8_t multithread_mode
Multithread mode. Should be zero.
Definition: tiny_hd.h:64
read_block_cb_t read_func
callback function to read bytes from the physical channel
Definition: tiny_hd.h:78
uint16_t timeout
timeout. Can be set to 0 during initialization. In this case timeout will be set to default ...
Definition: tiny_hd.h:88
Tiny protocol Types.
void tiny_hd_close(STinyHdData *handle)
stops Tiny Half Duplex state machine
Definition: tiny_hd.c:204
Definition: tiny_layer2.h:110
on_frame_cb_t on_frame_cb
Callback to process received frames.
Definition: tiny_hd.h:54
read_block_cb_t read_func
callback function to read bytes from the physical channel
Definition: tiny_hd.h:52
int tiny_send_wait_ack(STinyHdData *handle, void *buf, uint16_t len)
Sends userdata and waits for acknowledgement from remote side.
Definition: tiny_hd.c:71
on_frame_cb_t on_frame_cb
callback function to process incoming frames
Definition: tiny_hd.h:82
write_block_cb_t write_func
callback function to write bytes to the physical channel
Definition: tiny_hd.h:76
hdlc_crc_t crc_type
Definition: tiny_hd.h:96
struct STinyHdInit_ STinyHdInit
uint16_t inbuf_size
maximum input buffer size
Definition: tiny_hd.h:86
Definition: tiny_hd.h:43
void * inbuf
buffer to store input bytes being received. Must be at least maximum packet size over communication c...
Definition: tiny_hd.h:84
struct STinyHdData_ STinyHdData
int(* read_block_cb_t)(void *pdata, void *buffer, int size)
Definition: tiny_proto_types.h:125
Definition: tiny_hd.h:73
uint8_t multithread_mode
multithread mode. At present should be 0
Definition: tiny_hd.h:90
Definition: tiny_hdlc.h:38
uint16_t timeout
Timeout for operations with acknowledge.
Definition: tiny_hd.h:56
int tiny_hd_run(STinyHdData *handle)
runs receive functions of Tiny Half Duplex protocol.
Definition: tiny_hd.c:218
void(* on_frame_cb_t)(void *handle, uint16_t uid, uint8_t *pdata, int size)
Definition: tiny_proto_types.h:138
uint16_t uid
field used to store temporary uid
Definition: tiny_hd.h:58
void * user_data
user specific data
Definition: tiny_hd.h:66
write_block_cb_t write_func
callback function to write bytes to the physical channel
Definition: tiny_hd.h:50
void * pdata
user data for block read/write functions
Definition: tiny_hd.h:80