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 
56  typedef struct _hdlc_handle_t
57  {
69 
80  int (*on_frame_read)(void *user_data, void *data, int len);
81 
92  int (*on_frame_send)(void *user_data, const void *data, int len);
93 
97  void *rx_buf;
98 
103 
109  hdlc_crc_t crc_type;
110 
116 
118  void *user_data;
119 
120 #ifndef DOXYGEN_SHOULD_SKIP_THIS
121 
123 
124  hdlc_ll_handle_t handle;
125 
126  int rx_len;
127 #endif
129 
130  //------------------------ GENERIC FUNCIONS ------------------------------
131 
139  hdlc_handle_t hdlc_init(hdlc_struct_t *hdlc_info);
140 
146  int hdlc_close(hdlc_handle_t handle);
147 
154  void hdlc_reset(hdlc_handle_t handle);
155 
156  //------------------------ RX FUNCIONS ------------------------------
157 
184  int hdlc_run_rx(hdlc_handle_t handle, const void *data, int len, int *error);
185 
186  //------------------------ TX FUNCIONS ------------------------------
187 
201  int hdlc_run_tx(hdlc_handle_t handle);
202 
213  int hdlc_get_tx_data(hdlc_handle_t handle, void *data, int len);
214 
256  int hdlc_send(hdlc_handle_t handle, const void *data, int len, uint32_t timeout);
257 
262 #ifdef __cplusplus
263 }
264 #endif
int rx_buf_size
size of rx buffer
Definition: hdlc.h:102
write_block_cb_t send_tx
Send bytes callback user-defined function.
Definition: hdlc.h:68
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:80
bool multithread_mode
Set this to true, if you want to implements TX data transmission in separate thread from the threads...
Definition: hdlc.h:115
tiny_events_t events
Parameters in DOXYGEN_SHOULD_SKIP_THIS section should not be modified by a user.
Definition: hdlc.h:122
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:109
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:97
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:56
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:118
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:92
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