Merge pull request #3137 from authmillenon/slip/fix/some-fixes
gnrc_slip: Fixes
This commit is contained in:
commit
293c5322de
@ -167,6 +167,11 @@ void auto_init(void)
|
|||||||
auto_init_at86rf2xx();
|
auto_init_at86rf2xx();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MODULE_NG_SLIP
|
||||||
|
extern void auto_init_slip(void);
|
||||||
|
auto_init_slip();
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef MODULE_XBEE
|
#ifdef MODULE_XBEE
|
||||||
extern void auto_init_xbee(void);
|
extern void auto_init_xbee(void);
|
||||||
auto_init_xbee();
|
auto_init_xbee();
|
||||||
|
|||||||
@ -23,7 +23,7 @@
|
|||||||
#include "net/gnrc/nomac.h"
|
#include "net/gnrc/nomac.h"
|
||||||
#include "net/gnrc.h"
|
#include "net/gnrc.h"
|
||||||
|
|
||||||
#include "slip.h"
|
#include "net/gnrc/slip.h"
|
||||||
#include "slip_params.h"
|
#include "slip_params.h"
|
||||||
|
|
||||||
#define ENABLE_DEBUG (0)
|
#define ENABLE_DEBUG (0)
|
||||||
@ -37,8 +37,8 @@ static gnrc_slip_dev_t slip_devs[SLIP_NUM];
|
|||||||
* @brief Define stack parameters for the MAC layer thread
|
* @brief Define stack parameters for the MAC layer thread
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
#define SLIP_STACKSIZE (KERNEL_CONF_STACKSIZE_DEFAULT)
|
#define SLIP_STACKSIZE (THREAD_STACKSIZE_DEFAULT)
|
||||||
#define SLIP_PRIO (PRIORITY_MAIN - 4)
|
#define SLIP_PRIO (THREAD_PRIORITY_MAIN - 4)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Stacks for the MAC layer threads
|
* @brief Stacks for the MAC layer threads
|
||||||
@ -55,7 +55,7 @@ void auto_init_slip(void)
|
|||||||
SLIP_PRIO);
|
SLIP_PRIO);
|
||||||
|
|
||||||
if (res <= KERNEL_PID_UNDEF) {
|
if (res <= KERNEL_PID_UNDEF) {
|
||||||
DEBUG("Error initializing XBee radio device!");
|
DEBUG("Error initializing SLIP radio device!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,8 +49,8 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uart_t uart; /**< the UART interface */
|
uart_t uart; /**< the UART interface */
|
||||||
ringbuffer_t *in_buf; /**< RX buffer */
|
ringbuffer_t in_buf; /**< RX buffer */
|
||||||
ringbuffer_t *out_buf; /**< TX buffer */
|
ringbuffer_t out_buf; /**< TX buffer */
|
||||||
char rx_mem[GNRC_SLIP_BUFSIZE]; /**< memory used by RX buffer */
|
char rx_mem[GNRC_SLIP_BUFSIZE]; /**< memory used by RX buffer */
|
||||||
char tx_mem[GNRC_SLIP_BUFSIZE]; /**< memory used by TX buffer */
|
char tx_mem[GNRC_SLIP_BUFSIZE]; /**< memory used by TX buffer */
|
||||||
uint32_t in_bytes; /**< the number of bytes received of a
|
uint32_t in_bytes; /**< the number of bytes received of a
|
||||||
|
|||||||
@ -29,6 +29,7 @@
|
|||||||
#include "msg.h"
|
#include "msg.h"
|
||||||
#include "net/gnrc.h"
|
#include "net/gnrc.h"
|
||||||
#include "periph/uart.h"
|
#include "periph/uart.h"
|
||||||
|
#include "od.h"
|
||||||
#include "ringbuffer.h"
|
#include "ringbuffer.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "net/ipv6/hdr.h"
|
#include "net/ipv6/hdr.h"
|
||||||
@ -62,20 +63,19 @@ static void _slip_rx_cb(void *arg, char data)
|
|||||||
|
|
||||||
_SLIP_DEV(arg)->in_bytes = 0;
|
_SLIP_DEV(arg)->in_bytes = 0;
|
||||||
}
|
}
|
||||||
|
else if (_SLIP_DEV(arg)->in_esc) {
|
||||||
if (_SLIP_DEV(arg)->in_esc) {
|
|
||||||
_SLIP_DEV(arg)->in_esc = 0;
|
_SLIP_DEV(arg)->in_esc = 0;
|
||||||
|
|
||||||
switch (data) {
|
switch (data) {
|
||||||
case (_SLIP_END_ESC):
|
case (_SLIP_END_ESC):
|
||||||
if (ringbuffer_add_one(_SLIP_DEV(arg)->in_buf, _SLIP_END) < 0) {
|
if (ringbuffer_add_one(&_SLIP_DEV(arg)->in_buf, _SLIP_END) < 0) {
|
||||||
_SLIP_DEV(arg)->in_bytes++;
|
_SLIP_DEV(arg)->in_bytes++;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case (_SLIP_ESC_ESC):
|
case (_SLIP_ESC_ESC):
|
||||||
if (ringbuffer_add_one(_SLIP_DEV(arg)->in_buf, _SLIP_ESC) < 0) {
|
if (ringbuffer_add_one(&_SLIP_DEV(arg)->in_buf, _SLIP_ESC) < 0) {
|
||||||
_SLIP_DEV(arg)->in_bytes++;
|
_SLIP_DEV(arg)->in_bytes++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ static void _slip_rx_cb(void *arg, char data)
|
|||||||
_SLIP_DEV(arg)->in_esc = 1;
|
_SLIP_DEV(arg)->in_esc = 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (ringbuffer_add_one(_SLIP_DEV(arg)->in_buf, data) < 0) {
|
if (ringbuffer_add_one(&_SLIP_DEV(arg)->in_buf, data) < 0) {
|
||||||
_SLIP_DEV(arg)->in_bytes++;
|
_SLIP_DEV(arg)->in_bytes++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,8 +97,8 @@ static void _slip_rx_cb(void *arg, char data)
|
|||||||
|
|
||||||
int _slip_tx_cb(void *arg)
|
int _slip_tx_cb(void *arg)
|
||||||
{
|
{
|
||||||
if (_SLIP_DEV(arg)->out_buf->avail > 0) {
|
if (_SLIP_DEV(arg)->out_buf.avail > 0) {
|
||||||
char c = (char)ringbuffer_get_one(_SLIP_DEV(arg)->out_buf);
|
char c = (char)ringbuffer_get_one(&_SLIP_DEV(arg)->out_buf);
|
||||||
uart_write((uart_t)(_SLIP_DEV(arg)->uart), c);
|
uart_write((uart_t)(_SLIP_DEV(arg)->uart), c);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -110,7 +110,6 @@ int _slip_tx_cb(void *arg)
|
|||||||
static void _slip_receive(gnrc_slip_dev_t *dev, size_t bytes)
|
static void _slip_receive(gnrc_slip_dev_t *dev, size_t bytes)
|
||||||
{
|
{
|
||||||
gnrc_netif_hdr_t *hdr;
|
gnrc_netif_hdr_t *hdr;
|
||||||
gnrc_netreg_entry_t *sendto;
|
|
||||||
gnrc_pktsnip_t *pkt, *netif_hdr;
|
gnrc_pktsnip_t *pkt, *netif_hdr;
|
||||||
|
|
||||||
pkt = gnrc_pktbuf_add(NULL, NULL, bytes, GNRC_NETTYPE_UNDEF);
|
pkt = gnrc_pktbuf_add(NULL, NULL, bytes, GNRC_NETTYPE_UNDEF);
|
||||||
@ -133,11 +132,17 @@ static void _slip_receive(gnrc_slip_dev_t *dev, size_t bytes)
|
|||||||
gnrc_netif_hdr_init(hdr, 0, 0);
|
gnrc_netif_hdr_init(hdr, 0, 0);
|
||||||
hdr->if_pid = thread_getpid();
|
hdr->if_pid = thread_getpid();
|
||||||
|
|
||||||
if (ringbuffer_get(dev->in_buf, pkt->data, bytes) != bytes) {
|
if (ringbuffer_get(&dev->in_buf, pkt->data, bytes) != bytes) {
|
||||||
DEBUG("slip: could not read %zu bytes from ringbuffer\n", bytes);
|
DEBUG("slip: could not read %u bytes from ringbuffer\n", (unsigned)bytes);
|
||||||
gnrc_pktbuf_release(pkt);
|
gnrc_pktbuf_release(pkt);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#if ENABLE_DEBUG && defined(MODULE_OD)
|
||||||
|
else {
|
||||||
|
DEBUG("slip: received data\n");
|
||||||
|
od_hex_dump(pkt->data, bytes, OD_WIDTH_DEFAULT);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef MODULE_GNRC_IPV6
|
#ifdef MODULE_GNRC_IPV6
|
||||||
if ((pkt->size >= sizeof(ipv6_hdr_t)) && ipv6_hdr_is(pkt->data)) {
|
if ((pkt->size >= sizeof(ipv6_hdr_t)) && ipv6_hdr_is(pkt->data)) {
|
||||||
@ -145,25 +150,15 @@ static void _slip_receive(gnrc_slip_dev_t *dev, size_t bytes)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sendto = gnrc_netreg_lookup(pkt->type, GNRC_NETREG_DEMUX_CTX_ALL);
|
if (gnrc_netapi_dispatch_receive(pkt->type, GNRC_NETREG_DEMUX_CTX_ALL, pkt) == 0) {
|
||||||
|
|
||||||
if (sendto == NULL) {
|
|
||||||
DEBUG("slip: unable to forward packet of type %i\n", pkt->type);
|
DEBUG("slip: unable to forward packet of type %i\n", pkt->type);
|
||||||
gnrc_pktbuf_release(pkt);
|
gnrc_pktbuf_release(pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
gnrc_pktbuf_hold(pkt, gnrc_netreg_num(pkt->type, GNRC_NETREG_DEMUX_CTX_ALL) - 1);
|
|
||||||
|
|
||||||
while (sendto != NULL) {
|
|
||||||
DEBUG("slip: sending pkt %p to PID %u\n", pkt, sendto->pid);
|
|
||||||
gnrc_netapi_receive(sendto->pid, pkt);
|
|
||||||
sendto = gnrc_netreg_getnext(sendto);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void _slip_send_char(gnrc_slip_dev_t *dev, char c)
|
static inline void _slip_send_char(gnrc_slip_dev_t *dev, char c)
|
||||||
{
|
{
|
||||||
ringbuffer_add_one(dev->out_buf, c);
|
ringbuffer_add_one(&dev->out_buf, c);
|
||||||
uart_tx_begin(dev->uart);
|
uart_tx_begin(dev->uart);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +170,7 @@ static void _slip_send(gnrc_slip_dev_t *dev, gnrc_pktsnip_t *pkt)
|
|||||||
ptr = pkt->next; /* ignore gnrc_netif_hdr_t, we don't need it */
|
ptr = pkt->next; /* ignore gnrc_netif_hdr_t, we don't need it */
|
||||||
|
|
||||||
while (ptr != NULL) {
|
while (ptr != NULL) {
|
||||||
DEBUG("slip: send pktsnip of length %zu over UART_%d\n", ptr->size, uart);
|
DEBUG("slip: send pktsnip of length %u over UART_%d\n", (unsigned)ptr->size, dev->uart);
|
||||||
char *data = ptr->data;
|
char *data = ptr->data;
|
||||||
|
|
||||||
for (size_t i = 0; i < ptr->size; i++) {
|
for (size_t i = 0; i < ptr->size; i++) {
|
||||||
@ -216,7 +211,7 @@ static void *_slip(void *args)
|
|||||||
dev->slip_pid = thread_getpid();
|
dev->slip_pid = thread_getpid();
|
||||||
gnrc_netif_add(dev->slip_pid);
|
gnrc_netif_add(dev->slip_pid);
|
||||||
|
|
||||||
DEBUG("slip: SLIP runs on UART_%d\n", uart);
|
DEBUG("slip: SLIP runs on UART_%d\n", dev->uart);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
DEBUG("slip: waiting for incoming messages\n");
|
DEBUG("slip: waiting for incoming messages\n");
|
||||||
@ -224,7 +219,8 @@ static void *_slip(void *args)
|
|||||||
|
|
||||||
switch (msg.type) {
|
switch (msg.type) {
|
||||||
case _SLIP_MSG_TYPE:
|
case _SLIP_MSG_TYPE:
|
||||||
DEBUG("slip: incoming message from UART in buffer\n");
|
DEBUG("slip: incoming message of size %" PRIu32 " from UART_%d in buffer\n",
|
||||||
|
msg.content.value, dev->uart);
|
||||||
_slip_receive(dev, (size_t)msg.content.value);
|
_slip_receive(dev, (size_t)msg.content.value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -251,23 +247,23 @@ static void *_slip(void *args)
|
|||||||
kernel_pid_t gnrc_slip_init(gnrc_slip_dev_t *dev, uart_t uart, uint32_t baudrate,
|
kernel_pid_t gnrc_slip_init(gnrc_slip_dev_t *dev, uart_t uart, uint32_t baudrate,
|
||||||
char *stack, size_t stack_size, char priority)
|
char *stack, size_t stack_size, char priority)
|
||||||
{
|
{
|
||||||
int res;
|
|
||||||
kernel_pid_t pid;
|
kernel_pid_t pid;
|
||||||
|
|
||||||
/* reset device descriptor fields */
|
/* reset device descriptor fields */
|
||||||
|
dev->uart = uart;
|
||||||
dev->in_bytes = 0;
|
dev->in_bytes = 0;
|
||||||
dev->in_esc = 0;
|
dev->in_esc = 0;
|
||||||
dev->slip_pid = KERNEL_PID_UNDEF;
|
dev->slip_pid = KERNEL_PID_UNDEF;
|
||||||
|
|
||||||
/* initialize buffers */
|
/* initialize buffers */
|
||||||
ringbuffer_init(dev->in_buf, dev->rx_mem, sizeof(dev->rx_mem));
|
ringbuffer_init(&dev->in_buf, dev->rx_mem, sizeof(dev->rx_mem));
|
||||||
ringbuffer_init(dev->out_buf, dev->tx_mem, sizeof(dev->tx_mem));
|
ringbuffer_init(&dev->out_buf, dev->tx_mem, sizeof(dev->tx_mem));
|
||||||
|
|
||||||
/* initialize UART */
|
/* initialize UART */
|
||||||
DEBUG("slip: initialize UART_%d\n", uart);
|
DEBUG("slip: initialize UART_%d with baudrate %" PRIu32 "\n", uart,
|
||||||
res = uart_init(uart, baudrate, _slip_rx_cb, _slip_tx_cb, dev);
|
baudrate);
|
||||||
if (res < 0) {
|
if (uart_init(uart, baudrate, _slip_rx_cb, _slip_tx_cb, dev) < 0) {
|
||||||
DEBUG("slip: error initializing UART_%i with baudrate %u\n",
|
DEBUG("slip: error initializing UART_%i with baudrate %" PRIu32 "\n",
|
||||||
uart, baudrate);
|
uart, baudrate);
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
@ -280,5 +276,5 @@ kernel_pid_t gnrc_slip_init(gnrc_slip_dev_t *dev, uart_t uart, uint32_t baudrate
|
|||||||
DEBUG("slip: unable to create SLIP thread\n");
|
DEBUG("slip: unable to create SLIP thread\n");
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
}
|
}
|
||||||
return res;
|
return pid;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,17 +3,20 @@ include ../Makefile.tests_common
|
|||||||
|
|
||||||
BOARD_INSUFFICIENT_RAM := stm32f0discovery
|
BOARD_INSUFFICIENT_RAM := stm32f0discovery
|
||||||
|
|
||||||
|
USEMODULE += auto_init_ng_netif
|
||||||
USEMODULE += gnrc
|
USEMODULE += gnrc
|
||||||
USEMODULE += gnrc_pktdump
|
USEMODULE += gnrc_pktdump
|
||||||
USEMODULE += gnrc_slip
|
USEMODULE += gnrc_slip
|
||||||
USEMODULE += shell
|
USEMODULE += shell
|
||||||
USEMODULE += shell_commands
|
USEMODULE += shell_commands
|
||||||
|
|
||||||
|
CFLAGS += -I$(CURDIR)
|
||||||
|
|
||||||
ifneq (,$(SLIP_UART))
|
ifneq (,$(SLIP_UART))
|
||||||
CFLAGS += -DSLIP_UART=$(SLIP_UART)
|
CFLAGS += -DSLIP_UART=$(SLIP_UART)
|
||||||
else
|
else
|
||||||
# set default
|
# set default
|
||||||
CFLAGS += -DSLIP_UART=UART_0
|
CFLAGS += -DSLIP_UART="(UART_NUMOF-1)"
|
||||||
endif
|
endif
|
||||||
ifneq (,$(SLIP_BAUDRATE))
|
ifneq (,$(SLIP_BAUDRATE))
|
||||||
CFLAGS += -DSLIP_BAUDRATE=$(SLIP_BAUDRATE)
|
CFLAGS += -DSLIP_BAUDRATE=$(SLIP_BAUDRATE)
|
||||||
|
|||||||
@ -25,7 +25,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static gnrc_slip_params_t xbee_params[] = {
|
static gnrc_slip_params_t gnrc_slip_params[] = {
|
||||||
{
|
{
|
||||||
.uart = SLIP_UART,
|
.uart = SLIP_UART,
|
||||||
.baudrate = SLIP_BAUDRATE,
|
.baudrate = SLIP_BAUDRATE,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user