cMicroOrp  1.0.0
C code for microcontrollers - provides ORP remote interface
hdlc.h
Go to the documentation of this file.
1 /*
2 Copyright <2020> <J Thompson>
3 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6 */
7 
8 #ifndef HDLC_H
9 #define HDLC_H
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 
16 typedef void (* txChar_cb) (uint8_t);
17 typedef void (* hdlc_decoder_callback_type)(const uint8_t *framebuffer, uint16_t framelength);
18 
19 
20 // public:
21 // note there is no rx_getchar() as the host sends in bytes via hdlc_frameDecode_char
22 
23 // app provides a delay function for wakeup function
24 typedef void (* hdlc_delay100ms_cb) (void);
25 
26 
27 void hdlc_hdlc (
28  txChar_cb put_char, // encoder - bind send a byte to UART
29  hdlc_decoder_callback_type hdlc_decoded_callback, // decoder - frame decoded callback with payload
30  uint8_t *rx_frame_buffer, // decoder - working buffer
31  uint16_t max_rxFrame_length // decoder - length of working buffer
32 );
33 
34 /*
35  Raw serial HDLC encoded bytes are sent into this function
36  If a frame is decoded the hdlc_decoded_callback() is called with the
37  decoded payload
38 */
39 void hdlc_frameDecode_char(uint8_t data);
40 
41 /*
42  This takes a payload_buffer payload in
43  HDLC encodes it
44  Then sends the HDLC encoded data using put_char()
45 */
46 void hdlc_frameEncode(const uint8_t *payload_buffer, uint8_t payload_length);
47 
48 /*
49  * This needs some work as most system will block during the 100ms delay
50  */
51 void hdlc_wakeup( hdlc_delay100ms_cb delay100ms);
52 
53 #ifdef __cplusplus
54 }
55 #endif
56 
57 #endif // HDLC_H
hdlc_hdlc
void hdlc_hdlc(txChar_cb put_char, hdlc_decoder_callback_type hdlc_decoded_callback, uint8_t *rx_frame_buffer, uint16_t max_rxFrame_length)
Definition: hdlc.c:53
hdlc_frameEncode
void hdlc_frameEncode(const uint8_t *payload_buffer, uint8_t payload_length)
Definition: hdlc.c:132
hdlc_wakeup
void hdlc_wakeup(hdlc_delay100ms_cb delay100ms)
Definition: hdlc.c:174
txChar_cb
void(* txChar_cb)(uint8_t)
Definition: hdlc.h:16
hdlc_delay100ms_cb
void(* hdlc_delay100ms_cb)(void)
Definition: hdlc.h:24
hdlc_decoder_callback_type
void(* hdlc_decoder_callback_type)(const uint8_t *framebuffer, uint16_t framelength)
Definition: hdlc.h:17
hdlc_frameDecode_char
void hdlc_frameDecode_char(uint8_t data)
Definition: hdlc.c:73