Tiny protocol  0.9.3
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"
36 #include "proto/hal/tiny_types.h"
37 
47 typedef struct STinyHdData_
48 {
49 #ifndef DOXYGEN_SHOULD_SKIP_THIS
50  hdlc_struct_t _hdlc;
51  uint8_t _sent;
52 #endif
62  uint16_t timeout;
64  uint16_t uid;
72  void * user_data;
73 } STinyHdData;
74 
75 
79 typedef struct STinyHdInit_
80 {
86  void * pdata;
96  void * inbuf;
98  uint16_t inbuf_size;
100  uint16_t timeout;
109 } STinyHdInit;
110 
122 extern int tiny_hd_init(STinyHdData * handle,
123  STinyHdInit * init);
124 
132 extern void tiny_hd_close(STinyHdData * handle);
133 
157 extern int tiny_hd_run(STinyHdData * handle);
158 
166 extern int tiny_hd_run_tx(STinyHdData * handle);
167 
187 extern int tiny_send_wait_ack(STinyHdData *handle, void *buf, uint16_t len);
188 
189 #if 0
190 static inline STinyData * hd_to_tiny(STinyHdData * handle)
191 {
192  return &handle->handle;
193 }
194 
195 static inline STinyHdData * tiny_to_hd(STinyHdData * handle)
196 {
197  return (STinyHdData *)handle;
198 }
199 #endif
200 
205 #ifdef __cplusplus
206 }
207 #endif
208 
209 #endif /* _TINY_HALFDUPLEX_PROTOCOL_H_ */
hdlc_crc_t
Definition: tiny_hdlc.h:51
int tiny_hd_init(STinyHdData *handle, STinyHdInit *init)
Initialized communication for Tiny Half Duplex protocol.
Definition: tiny_hd.c:182
on_frame_cb_t on_sent_cb
Callback to get notification of sent frames.
Definition: tiny_hd.h:60
int tiny_hd_run_tx(STinyHdData *handle)
Definition: tiny_hd.c:238
read_block_cb_t read_func
callback function to read bytes from the physical channel
Definition: tiny_hd.h:84
uint16_t timeout
timeout. Can be set to 0 during initialization. In this case timeout will be set to default ...
Definition: tiny_hd.h:100
on_frame_cb_t on_sent_cb
Callback to get notification of sent frames.
Definition: tiny_hd.h:90
void tiny_hd_close(STinyHdData *handle)
stops Tiny Half Duplex state machine
Definition: tiny_hd.c:215
on_frame_cb_t on_frame_cb
Callback to process received frames.
Definition: tiny_hd.h:58
struct STinyHdData_ STinyHdData
read_block_cb_t read_func
callback function to read bytes from the physical channel
Definition: tiny_hd.h:56
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:81
int(* read_block_cb_t)(void *pdata, void *buffer, int size)
Definition: tiny_types.h:139
void(* on_frame_cb_t)(void *handle, uint16_t uid, uint8_t *pdata, int size)
Definition: tiny_types.h:152
on_frame_cb_t on_frame_cb
callback function to process incoming frames
Definition: tiny_hd.h:88
write_block_cb_t write_func
callback function to write bytes to the physical channel
Definition: tiny_hd.h:82
hdlc_crc_t crc_type
Definition: tiny_hd.h:108
uint16_t inbuf_size
maximum input buffer size
Definition: tiny_hd.h:98
Tiny protocol Types.
Definition: tiny_hd.h:47
void * inbuf
Definition: tiny_hd.h:96
Definition: tiny_hd.h:79
uint8_t multithread_mode
multithread mode. At present should be 0
Definition: tiny_hd.h:102
Definition: tiny_hdlc.h:65
uint16_t timeout
Timeout for operations with acknowledge.
Definition: tiny_hd.h:62
int(* write_block_cb_t)(void *pdata, const void *buffer, int size)
Definition: tiny_types.h:128
int tiny_hd_run(STinyHdData *handle)
runs receive functions of Tiny Half Duplex protocol.
Definition: tiny_hd.c:231
uint16_t uid
field used to store temporary uid
Definition: tiny_hd.h:64
void * user_data
user specific data
Definition: tiny_hd.h:72
struct STinyHdInit_ STinyHdInit
write_block_cb_t write_func
callback function to write bytes to the physical channel
Definition: tiny_hd.h:54
bool multithread_mode
Multithread mode. Should be zero.
Definition: tiny_hd.h:70
void * pdata
user data for block read/write functions
Definition: tiny_hd.h:86