tinyproto
hdlc.h
1 /*
2  Copyright 2019-2025 (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/crc/tiny_crc.h"
32 #include <stdint.h>
33 #include <stdbool.h>
34 
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #endif
39 
41 #define TINY_HDLC_FILL_BYTE 0xFF
42 
58  typedef enum
59  {
60  HDLC_LL_RESET_BOTH = 0x00,
61  HDLC_LL_RESET_TX_ONLY = 0x01,
62  HDLC_LL_RESET_RX_ONLY = 0x02,
64 
65  struct hdlc_ll_data_t;
66 
69 
75  typedef struct
76  {
87 
97 
102  void *buf;
103 
107  int buf_size;
108 
114  hdlc_crc_t crc_type;
115 
117  void *user_data;
118 
120  int mtu;
121  } hdlc_ll_init_t;
122 
123  //------------------------ GENERIC FUNCIONS ------------------------------
124 
133  int hdlc_ll_init(hdlc_ll_handle_t *handle, hdlc_ll_init_t *init);
134 
140  int hdlc_ll_close(hdlc_ll_handle_t handle);
141 
149  void hdlc_ll_reset(hdlc_ll_handle_t handle, uint8_t flags);
150 
151  //------------------------ RX FUNCIONS ------------------------------
152 
182  int hdlc_ll_run_rx(hdlc_ll_handle_t handle, const void *data, int len, int *error);
183 
184  //------------------------ TX FUNCIONS ------------------------------
185 
196  int hdlc_ll_run_tx(hdlc_ll_handle_t handle, void *data, int len);
197 
221  int hdlc_ll_put(hdlc_ll_handle_t handle, const void *data, int len) __attribute__((deprecated));
222 
245  int hdlc_ll_put_frame(hdlc_ll_handle_t handle, const void *data, int len);
246 
255  int hdlc_ll_get_buf_size(int mtu);
256 
266  int hdlc_ll_get_buf_size_ex(int mtu, hdlc_crc_t crc_type, int rx_window);
267 
272 #ifdef __cplusplus
273 }
274 #endif
void(* on_frame_cb_t)(void *udata, uint8_t *pdata, int size)
on_frame_cb_t is a callback function, which is called every time new frame is received.
Definition: tiny_types.h:194
int hdlc_ll_put_frame(hdlc_ll_handle_t handle, const void *data, int len)
Puts next frame for sending.
Definition: hdlc.c:357
on_tx_frame_cb_t on_frame_send
User-defined callback, which is called when the packet is sent to TX channel.
Definition: hdlc.h:96
int hdlc_ll_run_tx(hdlc_ll_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:309
int hdlc_ll_close(hdlc_ll_handle_t handle)
Shutdowns all hdlc activity.
Definition: hdlc.c:106
int hdlc_ll_get_buf_size_ex(int mtu, hdlc_crc_t crc_type, int rx_window)
Returns minimum buffer size, required to hold hdlc low level data for desired payload size...
Definition: hdlc.c:567
hdlc_crc_t crc_type
crc field type to use on hdlc level.
Definition: hdlc.h:114
void * user_data
User data, which will be passed to user-defined callback as first argument.
Definition: hdlc.h:117
Structure describes configuration of lowest HDLC level Initialize this structure by 0 before passing ...
Definition: hdlc.h:75
Structure describes configuration of lowest HDLC level Initialize this structure by 0 before passing ...
Definition: hdlc_int.h:65
int hdlc_ll_init(hdlc_ll_handle_t *handle, hdlc_ll_init_t *init)
Initializes hdlc level and returns hdlc handle or NULL in case of error.
Definition: hdlc.c:71
void * buf
Buffer to be used by hdlc level to receive data to.
Definition: hdlc.h:102
This is Tiny HAL implementation for microcontrollers.
int mtu
mtu size, can be 0
Definition: hdlc.h:120
int hdlc_ll_run_rx(hdlc_ll_handle_t handle, const void *data, int len, int *error)
Processes incoming data.
Definition: hdlc.c:532
int hdlc_ll_get_buf_size(int mtu)
Returns minimum buffer size, required to hold hdlc low level data for desired payload size...
Definition: hdlc.c:559
struct hdlc_ll_data_t * hdlc_ll_handle_t
Handle for HDLC low level protocol.
Definition: hdlc.h:68
hdlc_crc_t crc_type
crc field type to use on hdlc level.
Definition: hdlc_int.h:102
void hdlc_ll_reset(hdlc_ll_handle_t handle, uint8_t flags)
Resets hdlc state.
Definition: hdlc.c:121
on_frame_cb_t on_frame_read
User-defined callback, which is called when new packet arrives from hw channel.
Definition: hdlc.h:86
int buf_size
size of hdlc buffer
Definition: hdlc.h:107
void(* on_tx_frame_cb_t)(void *udata, const uint8_t *pdata, int size)
on_frame_send_cb_t is a callback function, which is called every time new frame is sent...
Definition: tiny_types.h:203
hdlc_ll_reset_flags_t
Flags for hdlc_ll_reset function.
Definition: hdlc.h:58
int hdlc_ll_put(hdlc_ll_handle_t handle, const void *data, int len) __attribute__((deprecated))
Puts next frame for sending.
Definition: hdlc.c:352