xref: /btstack/src/btstack_slip.h (revision 2fca4dad957cd7b88f4657ed51e89c12615dda72)
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
23*2fca4dadSMilanka Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
24*2fca4dadSMilanka Ringwald  * GMBH 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 
38fe5a6c4eSMilanka Ringwald /**
39fe5a6c4eSMilanka Ringwald  * @title SLIP encoder/decoder
40fe5a6c4eSMilanka Ringwald  *
41ab67bfbbSMatthias Ringwald  */
42ab67bfbbSMatthias Ringwald 
4380e33422SMatthias Ringwald #ifndef BTSTACK_SLIP_H
4480e33422SMatthias 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 
54fe5a6c4eSMilanka Ringwald /* API_START */
55fe5a6c4eSMilanka Ringwald 
56ab67bfbbSMatthias Ringwald // ENCODER
57ab67bfbbSMatthias Ringwald 
58ab67bfbbSMatthias Ringwald /**
59ab67bfbbSMatthias Ringwald  * @brief Initialise SLIP encoder with data
60ab67bfbbSMatthias Ringwald  * @param data
61ab67bfbbSMatthias Ringwald  * @param len
62ab67bfbbSMatthias Ringwald  */
63ab67bfbbSMatthias Ringwald void btstack_slip_encoder_start(const uint8_t * data, uint16_t len);
64ab67bfbbSMatthias Ringwald 
65ab67bfbbSMatthias Ringwald /**
66ab67bfbbSMatthias Ringwald  * @brief Check if encoder has data ready
67ab67bfbbSMatthias Ringwald  * @return True if data ready
68ab67bfbbSMatthias Ringwald  */
69ab67bfbbSMatthias Ringwald int  btstack_slip_encoder_has_data(void);
70ab67bfbbSMatthias Ringwald 
71ab67bfbbSMatthias Ringwald /**
72ab67bfbbSMatthias Ringwald  * @brief Get next byte from encoder
73ab67bfbbSMatthias Ringwald  * @return Next bytes from encoder
74ab67bfbbSMatthias Ringwald  */
75ab67bfbbSMatthias Ringwald uint8_t btstack_slip_encoder_get_byte(void);
76ab67bfbbSMatthias Ringwald 
774d6feae0SMatthias Ringwald // DECODER
784d6feae0SMatthias Ringwald 
794d6feae0SMatthias Ringwald /**
804d6feae0SMatthias Ringwald  * @brief Initialise SLIP decoder with buffer
814d6feae0SMatthias Ringwald  * @param buffer to store received data
824d6feae0SMatthias Ringwald  * @param max_size of buffer
834d6feae0SMatthias Ringwald  */
844d6feae0SMatthias Ringwald void btstack_slip_decoder_init(uint8_t * buffer, uint16_t max_size);
854d6feae0SMatthias Ringwald 
864d6feae0SMatthias Ringwald /**
874d6feae0SMatthias Ringwald  * @brief Process received byte
884d6feae0SMatthias Ringwald  * @param input
894d6feae0SMatthias Ringwald  */
904d6feae0SMatthias Ringwald 
914d6feae0SMatthias Ringwald void btstack_slip_decoder_process(uint8_t input);
924d6feae0SMatthias Ringwald 
934d6feae0SMatthias Ringwald /**
944d6feae0SMatthias Ringwald  * @brief Get size of decoded frame
954d6feae0SMatthias Ringwald  * @return size of frame. Size = 0 => frame not complete
964d6feae0SMatthias Ringwald  */
974d6feae0SMatthias Ringwald 
984d6feae0SMatthias Ringwald uint16_t btstack_slip_decoder_frame_size(void);
994d6feae0SMatthias Ringwald 
100fe5a6c4eSMilanka Ringwald /* API_END */
101fe5a6c4eSMilanka Ringwald 
102ab67bfbbSMatthias Ringwald #if defined __cplusplus
103ab67bfbbSMatthias Ringwald }
104ab67bfbbSMatthias Ringwald #endif
105ab67bfbbSMatthias Ringwald 
106ab67bfbbSMatthias Ringwald #endif
107