tinyproto
tiny_light.h
Go to the documentation of this file.
1 /*
2  Copyright 2017-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 
35 #ifndef _TINY_LIGHT_H_
36 #define _TINY_LIGHT_H_
37 
38 #include "proto/hdlc/low_level/hdlc.h"
39 #include "hal/tiny_types.h"
40 
41 #ifdef __cplusplus
42 extern "C"
43 {
44 #endif
45 
51 /*************************************************************
52  *
53  * Tiny defines
54  *
55  *************************************************************/
56 
60 #define LIGHT_BUF_SIZE (sizeof(uintptr_t) * 18)
61 
66  typedef struct
67  {
72 #ifndef DOXYGEN_SHOULD_SKIP_THIS
73  hdlc_ll_handle_t _hdlc;
74  int rx_len;
75  TINY_ALIGNED_STRUCT uint8_t buffer[LIGHT_BUF_SIZE];
76 #endif
77  void *user_data;
80  hdlc_crc_t crc_type;
82 
96  extern int tiny_light_init(STinyLightData *handle, write_block_cb_t write_func, read_block_cb_t read_func,
97  void *pdata);
98 
106  extern int tiny_light_close(STinyLightData *handle);
107 
122  extern int tiny_light_send(STinyLightData *handle, const uint8_t *pbuf, int len);
123 
142  extern int tiny_light_read(STinyLightData *handle, uint8_t *pbuf, int len);
143 
155 
160 #ifdef __cplusplus
161 }
162 #endif
163 
164 #endif /* _TINY_PROTOCOL_H_ */
hdlc_ll_handle_t tiny_light_get_hdlc(STinyLightData *handle)
returns lower level hdlc handle.
Definition: tiny_light.c:201
int tiny_light_read(STinyLightData *handle, uint8_t *pbuf, int len)
reads frame from the channel in blocking mode.
Definition: tiny_light.c:158
#define TINY_ALIGNED_STRUCT
This macro is used internally for aligning the structures.
Definition: tiny_types.h:113
write_block_cb_t write_func
pointer to platform related write function
Definition: tiny_light.h:69
int tiny_light_close(STinyLightData *handle)
The function closes channel.
Definition: tiny_light.c:89
int(* read_block_cb_t)(void *pdata, void *buffer, int size)
The function reads data from communication channel.
Definition: tiny_types.h:185
read_block_cb_t read_func
pointer to platform related read function
Definition: tiny_light.h:71
hdlc_crc_t crc_type
CRC type to use.
Definition: tiny_light.h:80
int tiny_light_send(STinyLightData *handle, const uint8_t *pbuf, int len)
sends frame with user payload to communication channel in blocking mode
Definition: tiny_light.c:113
Structure describes configuration of lowest HDLC level Initialize this structure by 0 before passing ...
Definition: hdlc_int.h:65
This structure contains information about communication channel and its state.
Definition: tiny_light.h:66
This is Tiny HAL implementation for microcontrollers.
#define LIGHT_BUF_SIZE
This macro defines buffer size required for tiny light protocol.
Definition: tiny_light.h:60
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
int tiny_light_init(STinyLightData *handle, write_block_cb_t write_func, read_block_cb_t read_func, void *pdata)
The function initializes internal structures for Tiny channel and return handle to be used with all T...
Definition: tiny_light.c:66