Morse Micro IoT SDK  2.9.7
slip.h
1/*
2 * Copyright 2023-2025 Morse Micro
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
17#pragma once
18
19#include <stdbool.h>
20#include <stdint.h>
21#include <stdio.h>
22#include <stdlib.h>
23
25#define SLIP_RX_BUFFER_SIZE (2000)
26
43{
44 uint8_t *buffer;
46 size_t length;
47 bool escape;
49};
50
59#define SLIP_RX_STATE_INIT(_buffer, _buffer_length) { _buffer, _buffer_length, 0, false, false }
60
70static inline void slip_rx_state_reinit(struct slip_rx_state *state,
71 uint8_t *buffer, size_t buffer_length)
72{
73 state->buffer = buffer;
74 state->buffer_length = buffer_length;
75 state->length = 0;
76 state->escape = false;
77 state->frame_started = false;
78}
79
82{
87};
88
100enum slip_rx_status slip_rx(struct slip_rx_state *state, uint8_t c);
101
110typedef int (*slip_transport_tx_fn)(uint8_t c, void *arg);
111
122int slip_tx(slip_transport_tx_fn transport_tx_fn, void *transport_tx_arg,
123 const uint8_t *packet, size_t packet_len);
124
enum slip_rx_status slip_rx(struct slip_rx_state *state, uint8_t c)
Handle reception of a character in a SLIP stream.
static void slip_rx_state_reinit(struct slip_rx_state *state, uint8_t *buffer, size_t buffer_length)
Dynamic (re)initializer for slip_rx_state.
Definition: slip.h:70
int slip_tx(slip_transport_tx_fn transport_tx_fn, void *transport_tx_arg, const uint8_t *packet, size_t packet_len)
Transmit a packet with SLIP framing.
slip_rx_status
Enumeration of SLIP status codes.
Definition: slip.h:82
int(* slip_transport_tx_fn)(uint8_t c, void *arg)
Function to send a character on the SLIP transport.
Definition: slip.h:110
@ SLIP_RX_ERROR
An erroneous packet has been received.
Definition: slip.h:86
@ SLIP_RX_COMPLETE
A complete packet with length > 0 has been received.
Definition: slip.h:83
@ SLIP_RX_BUFFER_LIMIT
Receive buffer limit has been reached.
Definition: slip.h:85
@ SLIP_RX_IN_PROGRESS
Receive is still in progress.
Definition: slip.h:84
Structure used to contain the current state for the SLIP receiver.
Definition: slip.h:43
bool escape
Escape state.
Definition: slip.h:47
uint8_t * buffer
Reference to buffer where processed bytes are received.
Definition: slip.h:44
bool frame_started
Escape state.
Definition: slip.h:48
size_t length
Length of the currently received frame, excluding escape bytes.
Definition: slip.h:46
size_t buffer_length
Length of the buffer.
Definition: slip.h:45