tinyproto
hdlc.h
1 /*
2  Copyright 2019-2024 (C) Alexey Dynda
3 
4  This file is part of Tiny Protocol Library.
5 
6  GNU General Public License Usage
7 
8  Protocol Library is free software: you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  Protocol Library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License
19  along with Protocol Library. If not, see <http://www.gnu.org/licenses/>.
20 
21  Commercial License Usage
22 
23  Licensees holding valid commercial Tiny Protocol licenses may use this file in
24  accordance with the commercial license agreement provided in accordance with
25  the terms contained in a written agreement between you and Alexey Dynda.
26  For further information contact via email on github account.
27 */
28 #pragma once
29 
30 #include "hal/tiny_types.h"
31 #include "proto/hdlc/low_level/hdlc.h"
32 #include "proto/crc/tiny_crc.h"
33 #include <stdint.h>
34 #include <stdbool.h>
35 
36 #ifdef __cplusplus
37 extern "C"
38 {
39 #endif
40 
60  typedef struct _hdlc_handle_t
61  {
73 
84  int (*on_frame_read)(void *user_data, void *data, int len);
85 
96  int (*on_frame_send)(void *user_data, const void *data, int len);
97 
101  void *rx_buf;
102 
107 
113  hdlc_crc_t crc_type;
114 
120 
122  void *user_data;
123 
124 #ifndef DOXYGEN_SHOULD_SKIP_THIS
125 
127 
128  hdlc_ll_handle_t handle;
129 
130  int rx_len;
131 #endif
133 
134  //------------------------ GENERIC FUNCIONS ------------------------------
135 
143  hdlc_handle_t hdlc_init(hdlc_struct_t *hdlc_info);
144 
150  int hdlc_close(hdlc_handle_t handle);
151 
158  void hdlc_reset(hdlc_handle_t handle);
159 
160  //------------------------ RX FUNCIONS ------------------------------
161 
188  int hdlc_run_rx(hdlc_handle_t handle, const void *data, int len, int *error);
189 
190  //------------------------ TX FUNCIONS ------------------------------
191 
205  int hdlc_run_tx(hdlc_handle_t handle);
206 
217  int hdlc_get_tx_data(hdlc_handle_t handle, void *data, int len);
218 
260  int hdlc_send(hdlc_handle_t handle, const void *data, int len, uint32_t timeout);
261 
266 #ifdef __cplusplus
267 }
268 #endif
int rx_buf_size
size of rx buffer
Definition: hdlc.h:106
write_block_cb_t send_tx
Send bytes callback user-defined function.
Definition: hdlc.h:72
struct _hdlc_handle_t * hdlc_handle_t
hdlc handle
int(* on_frame_read)(void *user_data, void *data, int len)
User-defined callback, which is called when new packet arrives from hw channel.
Definition: hdlc.h:84
bool multithread_mode
Set this to true, if you want to implements TX data transmission in separate thread from the threads...
Definition: hdlc.h:119
tiny_events_t events
Parameters in DOXYGEN_SHOULD_SKIP_THIS section should not be modified by a user.
Definition: hdlc.h:126
int hdlc_run_tx(hdlc_handle_t handle)
Runs transmission at hdlc level.
Definition: hdlc.c:136
hdlc_crc_t crc_type
crc field type to use on hdlc level.
Definition: hdlc.h:113
hdlc_handle_t hdlc_init(hdlc_struct_t *hdlc_info)
Initializes hdlc level and returns hdlc handle or NULL in case of error.
Definition: hdlc.c:64
void hdlc_reset(hdlc_handle_t handle)
Resets hdlc state.
Definition: hdlc.c:101
Structure describes configuration of lowest HDLC level Initialize this structure by 0 before passing ...
Definition: hdlc_int.h:65
void * rx_buf
Buffer to be used by hdlc level to receive data to.
Definition: hdlc.h:101
struct _hdlc_handle_t hdlc_struct_t
Structure describes configuration of lowest HDLC level Initialize this structure by 0 before passing ...
This is Tiny HAL implementation for microcontrollers.
int hdlc_send(hdlc_handle_t handle, const void *data, int len, uint32_t timeout)
Puts next frame for sending.
Definition: hdlc.c:254
Structure describes configuration of lowest HDLC level Initialize this structure by 0 before passing ...
Definition: hdlc.h:60
int hdlc_close(hdlc_handle_t handle)
Shutdowns all hdlc activity.
Definition: hdlc.c:88
int(* write_block_cb_t)(void *pdata, const void *buffer, int size)
The function writes data to communication channel port.
Definition: tiny_types.h:174
void * user_data
User data, which will be passed to user-defined callback as first argument.
Definition: hdlc.h:122
int hdlc_run_rx(hdlc_handle_t handle, const void *data, int len, int *error)
Processes incoming data.
Definition: hdlc.c:314
Events group type used by Tiny Protocol implementation.
Definition: cpp_hal.h:60
int(* on_frame_send)(void *user_data, const void *data, int len)
User-defined callback, which is called when the packet is sent to TX channel.
Definition: hdlc.h:96
int hdlc_get_tx_data(hdlc_handle_t handle, void *data, int len)
If hdlc protocol has some data to send it will full data with This function returns either if no more...
Definition: hdlc.c:171