Loading...
Searching...
No Matches
slipdev.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2015-2017 Freie Universität Berlin
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
26
46
60
61#include <stdint.h>
62
63#include "cib.h"
64#include "event.h"
65#include "net/netdev.h"
66#include "periph/uart.h"
67#include "chunked_ringbuffer.h"
68#include "sched.h"
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73
85#ifdef CONFIG_SLIPDEV_BUFSIZE_EXP
86#define CONFIG_SLIPDEV_BUFSIZE (1 << CONFIG_SLIPDEV_BUFSIZE_EXP)
87#endif
88
89#ifndef CONFIG_SLIPDEV_BUFSIZE
90#define CONFIG_SLIPDEV_BUFSIZE (2048U)
91#endif
93
148
152typedef struct {
154 uint32_t baudrate;
156
162typedef struct {
163#if IS_USED(MODULE_SLIPDEV_NET)
165 chunk_ringbuf_t rb;
166 /* Written to from interrupts (with irq_disable */
167 /* to prevent any simultaneous writes), */
168 /* consumed exclusively in the network stack's */
169 /* loop at _isr. */
170
171 uint8_t rxmem[CONFIG_SLIPDEV_BUFSIZE];
172#endif
173
174#if IS_USED(MODULE_SLIPDEV_CONFIG)
175 chunk_ringbuf_t rb_config;
176 uint8_t rxmem_config[CONFIG_SLIPDEV_BUFSIZE];
177 event_t rxevent;
178#endif
179
186} slipdev_t;
187
196void slipdev_setup(slipdev_t *dev, const slipdev_params_t *params, uint8_t index);
197
204
209
216
217
232int slipdev_coap_recv(uint8_t *buf, size_t buf_size, slipdev_t *dev);
233
244
245#ifdef __cplusplus
246}
247#endif
248
Chunked Ringbuffer.
Circular integer buffer interface.
Definitions low-level network driver interface.
struct netdev netdev_t
Forward declaration for netdev struct.
Definition netdev.h:285
uint_fast8_t uart_t
Define default UART type identifier.
Definition uart.h:109
#define CONFIG_SLIPDEV_BUFSIZE
UART buffer size used for TX and RX buffers.
Definition slipdev.h:90
void slipdev_coap_unset_event_queue(void)
Teardown the event queue.
int slipdev_coap_recv(uint8_t *buf, size_t buf_size, slipdev_t *dev)
Receive a CoAP packet into the given buffer.
void slipdev_coap_send(const iolist_t *iolist, const slipdev_t *dev)
Send a CoAP message as a configuration frame.
void slipdev_setup(slipdev_t *dev, const slipdev_params_t *params, uint8_t index)
Setup a slipdev device state.
void unicoap_slipdev_recv_handler(event_t *event)
Callback to inform unicoap that a new configuration frame is available.
slipdev_state_t
States for the slipdev and its parser.
Definition slipdev.h:97
void slipdev_coap_set_event_queue(event_queue_t *q)
Setup the event queue that will be notified when a config frame arrives.
@ SLIPDEV_STATE_SLEEP
Device is in sleep mode.
Definition slipdev.h:146
@ SLIPDEV_STATE_UNKNOWN
Device discards incoming data.
Definition slipdev.h:114
@ SLIPDEV_STATE_NONE
Device is in no mode (currently not receiving any frame), this is the idle state.
Definition slipdev.h:107
@ SLIPDEV_STATE_STDIN
Device writes received data to stdin.
Definition slipdev.h:126
@ SLIPDEV_STATE_NET
Device writes handles data as network device.
Definition slipdev.h:118
@ SLIPDEV_STATE_STANDBY
Device is in standby, will wake up when sending data.
Definition slipdev.h:142
@ SLIPDEV_STATE_CONFIG
Device writes received data as CoAP message.
Definition slipdev.h:134
@ SLIPDEV_STATE_NET_ESC
Device writes handles data as network device, next byte is escaped.
Definition slipdev.h:122
@ SLIPDEV_STATE_STDIN_ESC
Device writes received data to stdin, next byte is escaped.
Definition slipdev.h:130
@ SLIPDEV_STATE_CONFIG_ESC
Device writes received data as CoAP message, next byte is escaped.
Definition slipdev.h:138
struct PTRTAG event_queue_t
event queue structure
struct event event_t
event structure forward declaration
Definition event.h:132
struct iolist iolist_t
iolist forward declaration
Definition iolist.h:30
A chunked ringbuffer.
event structure
Definition event.h:142
iolist structure definition
Definition iolist.h:35
Structure to hold driver state.
Definition netdev.h:363
Configuration parameters for a slipdev.
Definition slipdev.h:152
uint32_t baudrate
baudrate to use with slipdev_params_t::uart
Definition slipdev.h:154
uart_t uart
UART interface the device is connected to.
Definition slipdev.h:153
Device descriptor for slipdev.
Definition slipdev.h:162
slipdev_params_t config
configuration parameters
Definition slipdev.h:180
slipdev_state_t state
Device state.
Definition slipdev.h:185
Low-level UART peripheral driver interface definition.