tinyproto
hdlc_int.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 
53 #define HDLC_MIN_BUF_SIZE(mtu, crc) (sizeof(hdlc_ll_data_t) + (int)(crc) / 8 + (mtu) + TINY_ALIGN_STRUCT_VALUE - 1)
54 
58 #define HDLC_BUF_SIZE_EX(mtu, crc, window) (sizeof(hdlc_ll_data_t) + ((int)(crc) / 8 + (mtu)) * (window) + TINY_ALIGN_STRUCT_VALUE - 1)
59 
65  typedef struct hdlc_ll_data_t
66  {
76 
86 
90  uint8_t *rx_buf;
91 
96 
102  hdlc_crc_t crc_type;
103 
105  void *user_data;
106 
107 #ifndef DOXYGEN_SHOULD_SKIP_THIS
108 
109  int phys_mtu;
110  struct
111  {
112  int (*state)(hdlc_ll_handle_t handle, const uint8_t *data, int len);
113  // pointer to the next byte in frame buffer
114  uint8_t *ptr;
115  uint8_t escape;
116  // pointer to the start of the frame buffer
117  uint8_t *active_frame_buf;
118  } rx;
119 
120  struct
121  {
122  int (*state)(hdlc_ll_handle_t handle);
123  uint8_t *out_buffer;
124  int out_buffer_len;
125  const uint8_t *origin_data;
126  const uint8_t *data;
127  int len;
128  crc_t crc;
129  uint8_t escape;
130  } tx;
131 #endif
132  } hdlc_ll_data_t;
133 
138 #ifdef __cplusplus
139 }
140 #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
on_frame_cb_t on_frame_read
User-defined callback, which is called when new frame arrives from hw channel.
Definition: hdlc_int.h:75
int phys_mtu
Parameters in DOXYGEN_SHOULD_SKIP_THIS section should not be modified by a user.
Definition: hdlc_int.h:109
Structure describes configuration of lowest HDLC level Initialize this structure by 0 before passing ...
Definition: hdlc_int.h:65
This is Tiny HAL implementation for microcontrollers.
struct hdlc_ll_data_t hdlc_ll_data_t
Structure describes configuration of lowest HDLC level Initialize this structure by 0 before passing ...
int rx_buf_size
size of hdlc buffer
Definition: hdlc_int.h:95
hdlc_crc_t crc_type
crc field type to use on hdlc level.
Definition: hdlc_int.h:102
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
on_tx_frame_cb_t on_frame_send
User-defined callback, which is called when the frame is sent to TX channel.
Definition: hdlc_int.h:85
uint8_t * rx_buf
Buffer to be used by hdlc level to receive data to.
Definition: hdlc_int.h:90
void * user_data
User data, which will be passed to user-defined callback as first argument.
Definition: hdlc_int.h:105