Tiny protocol  0.7.0
Tiny communication protocol for microcontrollers
tiny_hdlc.h
1 #pragma once
2 
3 #include <stdint.h>
4 
5 #ifdef __cplusplus
6 extern "C"
7 {
8 #endif
9 
15 #ifdef CONFIG_ENABLE_FCS32
17  typedef uint32_t crc_t;
18 #else
19  typedef uint16_t crc_t;
20 #endif
21 
23 
24 typedef enum
25 {
26  HDLC_CRC_DEFAULT = 0,
27  HDLC_CRC_8 = 8,
28  HDLC_CRC_16 = 16,
29  HDLC_CRC_32 = 32,
30  HDLC_CRC_OFF = 0xFF,
31 } hdlc_crc_t;
32 
38 typedef struct _hdlc_handle_t
39 {
50  int (*send_tx)(void *user_data, const void *data, int len);
51 
62  int (*on_frame_read)(void *user_data, void *data, int len);
63 
64  int (*on_frame_sent)(void *user_data, const void *data, int len);
65 
69  void *rx_buf;
70 
75 
81  hdlc_crc_t crc_type;
82 
84  void *user_data;
85 
86 #ifndef DOXYGEN_SHOULD_SKIP_THIS
87 
88  struct
89  {
90  uint8_t *data;
91  int len;
92  int (*state)( struct _hdlc_handle_t *handle, uint8_t *data, int len );
93  uint8_t escape;
94  } rx;
95  struct
96  {
97  const uint8_t *origin_data;
98  const uint8_t *data;
99  int len;
100  crc_t crc;
101  uint8_t escape;
102  int (*state)( struct _hdlc_handle_t *handle );
103  } tx;
104 #endif
106 
114 hdlc_handle_t hdlc_init( hdlc_struct_t *hdlc_info );
115 
121 int hdlc_close( hdlc_handle_t handle );
122 
129 void hdlc_reset( hdlc_handle_t handle );
130 
142 int hdlc_run_rx( hdlc_handle_t handle, void *data, int len );
143 
156 int hdlc_run_tx( hdlc_handle_t handle );
157 
169 int hdlc_send( hdlc_handle_t handle, const void *data, int len );
170 
175 #ifdef __cplusplus
176 }
177 #endif
178 
int rx_buf_size
Definition: tiny_hdlc.h:74
int(* on_frame_read)(void *user_data, void *data, int len)
Definition: tiny_hdlc.h:62
int hdlc_run_tx(hdlc_handle_t handle)
Definition: tiny_hdlc.c:190
int hdlc_run_rx(hdlc_handle_t handle, void *data, int len)
Definition: tiny_hdlc.c:324
hdlc_crc_t crc_type
Definition: tiny_hdlc.h:81
hdlc_handle_t hdlc_init(hdlc_struct_t *hdlc_info)
Definition: tiny_hdlc.c:19
void hdlc_reset(hdlc_handle_t handle)
Definition: tiny_hdlc.c:52
void * rx_buf
Definition: tiny_hdlc.h:69
struct _hdlc_handle_t hdlc_struct_t
Definition: tiny_hdlc.h:38
int hdlc_close(hdlc_handle_t handle)
Definition: tiny_hdlc.c:39
void * user_data
Definition: tiny_hdlc.h:84
int(* send_tx)(void *user_data, const void *data, int len)
Definition: tiny_hdlc.h:50
int hdlc_send(hdlc_handle_t handle, const void *data, int len)
Definition: tiny_hdlc.c:206