mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 05:32:45 +01:00
slipdev: expose marker byte definitions
This commit is contained in:
parent
23f6cf8a37
commit
79e80d4fec
@ -308,6 +308,10 @@ ifneq (,$(filter si70xx,$(USEMODULE)))
|
||||
USEMODULE_INCLUDES += $(RIOTBASE)/drivers/si70xx/include
|
||||
endif
|
||||
|
||||
ifneq (,$(filter slipdev,$(USEMODULE)))
|
||||
USEMODULE_INCLUDES += $(RIOTBASE)/drivers/slipdev/include
|
||||
endif
|
||||
|
||||
ifneq (,$(filter soft_spi,$(USEMODULE)))
|
||||
USEMODULE_INCLUDES += $(RIOTBASE)/drivers/soft_spi/include
|
||||
endif
|
||||
|
41
drivers/slipdev/include/slipdev_internal.h
Normal file
41
drivers/slipdev/include/slipdev_internal.h
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup drivers_slipdev
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @internal
|
||||
* @brief Internal SLIP device definitions
|
||||
*
|
||||
* @author Martine Lenders <m.lenders@fu-berlin.de>
|
||||
*/
|
||||
#ifndef SLIPDEV_INTERNAL_H
|
||||
#define SLIPDEV_INTERNAL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @name SLIP marker bytes
|
||||
* @{
|
||||
*/
|
||||
#define SLIPDEV_END (0xc0U)
|
||||
#define SLIPDEV_ESC (0xdbU)
|
||||
#define SLIPDEV_END_ESC (0xdcU)
|
||||
#define SLIPDEV_ESC_ESC (0xddU)
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SLIPDEV_INTERNAL_H */
|
||||
/** @} */
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Freie Universität Berlin
|
||||
* Copyright (C) 2018-2020 Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
@ -7,13 +7,11 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup
|
||||
* @ingroup
|
||||
* @brief
|
||||
* @ingroup drivers_slipdev
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief
|
||||
* @brief Default configuration for the SLIP device driver
|
||||
*
|
||||
* @author Martine Lenders <m.lenders@fu-berlin.de>
|
||||
*/
|
||||
@ -22,6 +20,9 @@
|
||||
|
||||
#include "board.h"
|
||||
#include "slipdev.h"
|
||||
#ifdef MODULE_SLIPDEV_STDIO
|
||||
#include "stdio_uart.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -32,11 +33,19 @@ extern "C" {
|
||||
* @{
|
||||
*/
|
||||
#ifndef SLIPDEV_PARAM_UART
|
||||
#define SLIPDEV_PARAM_UART (UART_DEV(0))
|
||||
#endif
|
||||
# ifndef MODULE_SLIPDEV_STDIO
|
||||
# define SLIPDEV_PARAM_UART (UART_DEV(0))
|
||||
# else /* MODULE_SLIPDEV_STDIO */
|
||||
# define SLIPDEV_PARAM_UART (STDIO_UART_DEV)
|
||||
# endif /* MODULE_SLIPDEV_STDIO */
|
||||
#endif /* SLIPDEV_PARAM_UART */
|
||||
#ifndef SLIPDEV_PARAM_BAUDRATE
|
||||
#define SLIPDEV_PARAM_BAUDRATE (115200U)
|
||||
#endif
|
||||
# ifndef MODULE_SLIPDEV_STDIO
|
||||
# define SLIPDEV_PARAM_BAUDRATE (115200U)
|
||||
# else /* MODULE_SLIPDEV_STDIO */
|
||||
# define SLIPDEV_PARAM_BAUDRATE (STDIO_UART_BAUDRATE)
|
||||
# endif /* MODULE_SLIPDEV_STDIO */
|
||||
#endif /* SLIPDEV_PARAM_BAUDRATE */
|
||||
|
||||
#ifndef SLIPDEV_PARAMS
|
||||
#define SLIPDEV_PARAMS { .uart = SLIPDEV_PARAM_UART, \
|
||||
@ -46,6 +55,9 @@ extern "C" {
|
||||
|
||||
/**
|
||||
* @brief slipdev configuration
|
||||
*
|
||||
* The first element in this array will be used to multiplex stdio if
|
||||
* `slipdev_stdio` is included.
|
||||
*/
|
||||
static const slipdev_params_t slipdev_params[] = {
|
||||
SLIPDEV_PARAMS
|
||||
|
@ -18,21 +18,17 @@
|
||||
|
||||
#include "log.h"
|
||||
#include "slipdev.h"
|
||||
#include "slipdev_internal.h"
|
||||
|
||||
#define ENABLE_DEBUG (0)
|
||||
#include "debug.h"
|
||||
|
||||
#define SLIP_END (0xc0U)
|
||||
#define SLIP_ESC (0xdbU)
|
||||
#define SLIP_END_ESC (0xdcU)
|
||||
#define SLIP_ESC_ESC (0xddU)
|
||||
|
||||
static void _slip_rx_cb(void *arg, uint8_t byte)
|
||||
{
|
||||
slipdev_t *dev = arg;
|
||||
|
||||
tsrb_add_one(&dev->inbuf, byte);
|
||||
if ((byte == SLIP_END) && (dev->netdev.event_callback != NULL)) {
|
||||
if ((byte == SLIPDEV_END) && (dev->netdev.event_callback != NULL)) {
|
||||
dev->netdev.event_callback((netdev_t *)dev, NETDEV_EVENT_ISR);
|
||||
}
|
||||
}
|
||||
@ -70,15 +66,15 @@ static int _send(netdev_t *netdev, const iolist_t *iolist)
|
||||
|
||||
for (unsigned j = 0; j < iol->iol_len; j++, data++) {
|
||||
switch(*data) {
|
||||
case SLIP_END:
|
||||
case SLIPDEV_END:
|
||||
/* escaping END byte*/
|
||||
_write_byte(dev, SLIP_ESC);
|
||||
_write_byte(dev, SLIP_END_ESC);
|
||||
_write_byte(dev, SLIPDEV_ESC);
|
||||
_write_byte(dev, SLIPDEV_END_ESC);
|
||||
break;
|
||||
case SLIP_ESC:
|
||||
case SLIPDEV_ESC:
|
||||
/* escaping ESC byte*/
|
||||
_write_byte(dev, SLIP_ESC);
|
||||
_write_byte(dev, SLIP_ESC_ESC);
|
||||
_write_byte(dev, SLIPDEV_ESC);
|
||||
_write_byte(dev, SLIPDEV_ESC_ESC);
|
||||
break;
|
||||
default:
|
||||
_write_byte(dev, *data);
|
||||
@ -86,7 +82,7 @@ static int _send(netdev_t *netdev, const iolist_t *iolist)
|
||||
bytes++;
|
||||
}
|
||||
}
|
||||
_write_byte(dev, SLIP_END);
|
||||
_write_byte(dev, SLIPDEV_END);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
@ -101,7 +97,7 @@ static int _recv(netdev_t *netdev, void *buf, size_t len, void *info)
|
||||
/* remove data */
|
||||
for (; len > 0; len--) {
|
||||
int byte = tsrb_get_one(&dev->inbuf);
|
||||
if ((byte == (int)SLIP_END) || (byte < 0)) {
|
||||
if ((byte == (int)SLIPDEV_END) || (byte < 0)) {
|
||||
/* end early if end of packet or ringbuffer is reached;
|
||||
* len might be larger than the actual packet */
|
||||
break;
|
||||
@ -122,23 +118,23 @@ static int _recv(netdev_t *netdev, void *buf, size_t len, void *info)
|
||||
return -EIO;
|
||||
}
|
||||
switch (byte) {
|
||||
case SLIP_END:
|
||||
case SLIPDEV_END:
|
||||
break;
|
||||
case SLIP_ESC:
|
||||
case SLIPDEV_ESC:
|
||||
dev->inesc = 1;
|
||||
break;
|
||||
case SLIP_END_ESC:
|
||||
case SLIPDEV_END_ESC:
|
||||
if (dev->inesc) {
|
||||
*(ptr++) = SLIP_END;
|
||||
*(ptr++) = SLIPDEV_END;
|
||||
res++;
|
||||
dev->inesc = 0;
|
||||
break;
|
||||
}
|
||||
/* Intentionally falls through */
|
||||
/* to default when !dev->inesc */
|
||||
case SLIP_ESC_ESC:
|
||||
case SLIPDEV_ESC_ESC:
|
||||
if (dev->inesc) {
|
||||
*(ptr++) = SLIP_ESC;
|
||||
*(ptr++) = SLIPDEV_ESC;
|
||||
res++;
|
||||
dev->inesc = 0;
|
||||
break;
|
||||
@ -151,13 +147,13 @@ static int _recv(netdev_t *netdev, void *buf, size_t len, void *info)
|
||||
break;
|
||||
}
|
||||
if ((unsigned)res > len) {
|
||||
while (byte != SLIP_END) {
|
||||
while (byte != SLIPDEV_END) {
|
||||
/* clear out unreceived packet */
|
||||
byte = tsrb_get_one(&dev->inbuf);
|
||||
}
|
||||
return -ENOBUFS;
|
||||
}
|
||||
} while (byte != SLIP_END);
|
||||
} while (byte != SLIPDEV_END);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user