xref: /btstack/src/btstack_slip.h (revision 4d6feae01abb3f02c3052ca92c208de5fb2f5929)
1ab67bfbbSMatthias Ringwald /*
2ab67bfbbSMatthias Ringwald  * Copyright (C) 2014 BlueKitchen GmbH
3ab67bfbbSMatthias Ringwald  *
4ab67bfbbSMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
5ab67bfbbSMatthias Ringwald  * modification, are permitted provided that the following conditions
6ab67bfbbSMatthias Ringwald  * are met:
7ab67bfbbSMatthias Ringwald  *
8ab67bfbbSMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
9ab67bfbbSMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
10ab67bfbbSMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11ab67bfbbSMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
12ab67bfbbSMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
13ab67bfbbSMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
14ab67bfbbSMatthias Ringwald  *    contributors may be used to endorse or promote products derived
15ab67bfbbSMatthias Ringwald  *    from this software without specific prior written permission.
16ab67bfbbSMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
17ab67bfbbSMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
18ab67bfbbSMatthias Ringwald  *    monetary gain.
19ab67bfbbSMatthias Ringwald  *
20ab67bfbbSMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21ab67bfbbSMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22ab67bfbbSMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23ab67bfbbSMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
24ab67bfbbSMatthias Ringwald  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25ab67bfbbSMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26ab67bfbbSMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27ab67bfbbSMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28ab67bfbbSMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29ab67bfbbSMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30ab67bfbbSMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31ab67bfbbSMatthias Ringwald  * SUCH DAMAGE.
32ab67bfbbSMatthias Ringwald  *
33ab67bfbbSMatthias Ringwald  * Please inquire about commercial licensing options at
34ab67bfbbSMatthias Ringwald  * [email protected]
35ab67bfbbSMatthias Ringwald  *
36ab67bfbbSMatthias Ringwald  */
37ab67bfbbSMatthias Ringwald 
38ab67bfbbSMatthias Ringwald /*
39ab67bfbbSMatthias Ringwald  *  btstack_slip.h
40ab67bfbbSMatthias Ringwald  *  SLIP encoder/decoder
41ab67bfbbSMatthias Ringwald  */
42ab67bfbbSMatthias Ringwald 
43ab67bfbbSMatthias Ringwald #ifndef __BTSTACK_SLIP_H
44ab67bfbbSMatthias Ringwald #define __BTSTACK_SLIP_H
45ab67bfbbSMatthias Ringwald 
46ab67bfbbSMatthias Ringwald #include <stdint.h>
47ab67bfbbSMatthias Ringwald 
48ab67bfbbSMatthias Ringwald #if defined __cplusplus
49ab67bfbbSMatthias Ringwald extern "C" {
50ab67bfbbSMatthias Ringwald #endif
51ab67bfbbSMatthias Ringwald 
52ab67bfbbSMatthias Ringwald #define BTSTACK_SLIP_SOF 0xc0
53ab67bfbbSMatthias Ringwald 
54ab67bfbbSMatthias Ringwald // ENCODER
55ab67bfbbSMatthias Ringwald 
56ab67bfbbSMatthias Ringwald /**
57ab67bfbbSMatthias Ringwald  * @brief Initialise SLIP encoder with data
58ab67bfbbSMatthias Ringwald  * @param data
59ab67bfbbSMatthias Ringwald  * @param len
60ab67bfbbSMatthias Ringwald  */
61ab67bfbbSMatthias Ringwald void btstack_slip_encoder_start(const uint8_t * data, uint16_t len);
62ab67bfbbSMatthias Ringwald 
63ab67bfbbSMatthias Ringwald /**
64ab67bfbbSMatthias Ringwald  * @brief Check if encoder has data ready
65ab67bfbbSMatthias Ringwald  * @return True if data ready
66ab67bfbbSMatthias Ringwald  */
67ab67bfbbSMatthias Ringwald int  btstack_slip_encoder_has_data(void);
68ab67bfbbSMatthias Ringwald 
69ab67bfbbSMatthias Ringwald /**
70ab67bfbbSMatthias Ringwald  * @brief Get next byte from encoder
71ab67bfbbSMatthias Ringwald  * @return Next bytes from encoder
72ab67bfbbSMatthias Ringwald  */
73ab67bfbbSMatthias Ringwald uint8_t btstack_slip_encoder_get_byte(void);
74ab67bfbbSMatthias Ringwald 
75*4d6feae0SMatthias Ringwald // DECODER
76*4d6feae0SMatthias Ringwald 
77*4d6feae0SMatthias Ringwald /**
78*4d6feae0SMatthias Ringwald  * @brief Initialise SLIP decoder with buffer
79*4d6feae0SMatthias Ringwald  * @param buffer to store received data
80*4d6feae0SMatthias Ringwald  * @param max_size of buffer
81*4d6feae0SMatthias Ringwald  */
82*4d6feae0SMatthias Ringwald void btstack_slip_decoder_init(uint8_t * buffer, uint16_t max_size);
83*4d6feae0SMatthias Ringwald 
84*4d6feae0SMatthias Ringwald /**
85*4d6feae0SMatthias Ringwald  * @brief Process received byte
86*4d6feae0SMatthias Ringwald  * @param input
87*4d6feae0SMatthias Ringwald  */
88*4d6feae0SMatthias Ringwald 
89*4d6feae0SMatthias Ringwald void btstack_slip_decoder_process(uint8_t input);
90*4d6feae0SMatthias Ringwald 
91*4d6feae0SMatthias Ringwald /**
92*4d6feae0SMatthias Ringwald  * @brief Get size of decoded frame
93*4d6feae0SMatthias Ringwald  * @return size of frame. Size = 0 => frame not complete
94*4d6feae0SMatthias Ringwald  */
95*4d6feae0SMatthias Ringwald 
96*4d6feae0SMatthias Ringwald uint16_t btstack_slip_decoder_frame_size(void);
97*4d6feae0SMatthias Ringwald 
98ab67bfbbSMatthias Ringwald #if defined __cplusplus
99ab67bfbbSMatthias Ringwald }
100ab67bfbbSMatthias Ringwald #endif
101ab67bfbbSMatthias Ringwald 
102ab67bfbbSMatthias Ringwald #endif
103