From e3ef42842e8acae381178c6693d96a4ab5e5591b Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Wed, 26 Jul 2017 13:35:14 +0200 Subject: [PATCH] cc110x: port to gnrc_netif2 --- .../{gnrc_netdev_cc110x.c => gnrc_cc110x.c} | 33 +++++++++-------- drivers/cc110x/include/gnrc_netif2_cc110x.h | 35 +++++++++++++++++++ sys/auto_init/netif/auto_init_cc110x.c | 17 ++++----- 3 files changed, 60 insertions(+), 25 deletions(-) rename drivers/cc110x/gnrc_cc110x/{gnrc_netdev_cc110x.c => gnrc_cc110x.c} (85%) create mode 100644 drivers/cc110x/include/gnrc_netif2_cc110x.h diff --git a/drivers/cc110x/gnrc_cc110x/gnrc_netdev_cc110x.c b/drivers/cc110x/gnrc_cc110x/gnrc_cc110x.c similarity index 85% rename from drivers/cc110x/gnrc_cc110x/gnrc_netdev_cc110x.c rename to drivers/cc110x/gnrc_cc110x/gnrc_cc110x.c index cce2cf38d743..1e11d7351c7a 100644 --- a/drivers/cc110x/gnrc_cc110x/gnrc_netdev_cc110x.c +++ b/drivers/cc110x/gnrc_cc110x/gnrc_cc110x.c @@ -14,16 +14,16 @@ #include "net/gnrc.h" #include "cc110x.h" #include "cc110x-netdev.h" -#include "net/gnrc/netdev.h" +#include "net/gnrc/netif2.h" #include "od.h" #define ENABLE_DEBUG (0) #include "debug.h" -static int _send(gnrc_netdev_t *gnrc_netdev, gnrc_pktsnip_t *pkt) +static int _send(gnrc_netif2_t *netif, gnrc_pktsnip_t *pkt) { cc110x_pkt_t cc110x_pkt; - netdev_t *dev = gnrc_netdev->dev; + netdev_t *dev = netif->dev; netdev_cc110x_t *netdev_cc110x = (netdev_cc110x_t *) dev; cc110x_t *cc110x = &netdev_cc110x->cc110x; @@ -36,7 +36,7 @@ static int _send(gnrc_netdev_t *gnrc_netdev, gnrc_pktsnip_t *pkt) payload = pkt->next; if (pkt->type != GNRC_NETTYPE_NETIF) { - DEBUG("gnrc_netdev_cc110x: First header was not generic netif header\n"); + DEBUG("gnrc_cc110x: First header was not generic netif header\n"); gnrc_pktbuf_release(pkt); return -EBADMSG; } @@ -82,7 +82,7 @@ static int _send(gnrc_netdev_t *gnrc_netdev, gnrc_pktsnip_t *pkt) payload_len += payload->size; if (payload_len > CC110X_MAX_DATA_LENGTH) { - DEBUG("gnrc_netdev_cc110x: payload length exceeds maximum" + DEBUG("gnrc_cc110x: payload length exceeds maximum" "(%u>%u)\n", payload_len, CC110X_MAX_DATA_LENGTH); gnrc_pktbuf_release(pkt); return -EBADMSG; @@ -98,7 +98,7 @@ static int _send(gnrc_netdev_t *gnrc_netdev, gnrc_pktsnip_t *pkt) cc110x_pkt.length = (uint8_t) payload_len + CC110X_HEADER_LENGTH; - DEBUG("gnrc_netdev_cc110x: sending packet from %u to %u with payload " + DEBUG("gnrc_cc110x: sending packet from %u to %u with payload " "length %u\n", (unsigned)cc110x_pkt.phy_src, (unsigned)cc110x_pkt.address, @@ -107,9 +107,9 @@ static int _send(gnrc_netdev_t *gnrc_netdev, gnrc_pktsnip_t *pkt) return dev->driver->send(dev, &vector, 1); } -static gnrc_pktsnip_t *_recv(gnrc_netdev_t *gnrc_netdev) +static gnrc_pktsnip_t *_recv(gnrc_netif2_t *netif) { - netdev_t *dev = gnrc_netdev->dev; + netdev_t *dev = netif->dev; cc110x_t *cc110x = &((netdev_cc110x_t*) dev)->cc110x; cc110x_pkt_t *cc110x_pkt = &cc110x->pkt_buf.packet; @@ -182,11 +182,16 @@ static gnrc_pktsnip_t *_recv(gnrc_netdev_t *gnrc_netdev) return pkt; } -int gnrc_netdev_cc110x_init(gnrc_netdev_t *gnrc_netdev, netdev_t *dev) -{ - gnrc_netdev->send = _send; - gnrc_netdev->recv = _recv; - gnrc_netdev->dev = dev; +static const gnrc_netif2_ops_t _cc110x_ops = { + .send = _send, + .recv = _recv, + .get = gnrc_netif2_get_from_netdev, + .set = gnrc_netif2_set_from_netdev, +}; - return 0; +gnrc_netif2_t *gnrc_netif2_cc110x_create(char *stack, int stacksize, char priority, + char *name, netdev_t *dev) +{ + return gnrc_netif2_create(stack, stacksize, priority, name, dev, + &_cc110x_ops); } diff --git a/drivers/cc110x/include/gnrc_netif2_cc110x.h b/drivers/cc110x/include/gnrc_netif2_cc110x.h new file mode 100644 index 000000000000..a7be168c69a0 --- /dev/null +++ b/drivers/cc110x/include/gnrc_netif2_cc110x.h @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2017 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 net_gnrc_netif2 + * @{ + * + * @file + * @brief CC110x adaption for @ref net_gnrc_netif2 + * + * @author Martine Lenders + */ +#ifndef GNRC_NETIF2_CC110X_H +#define GNRC_NETIF2_CC110X_H + +#include "net/gnrc/netif2.h" + +#ifdef __cplusplus +extern "C" { +#endif + +gnrc_netif2_t *gnrc_netif2_cc110x_create(char *stack, int stacksize, char priority, + char *name, netdev_t *dev); + +#ifdef __cplusplus +} +#endif + +#endif /* GNRC_NETIF2_CC110X_H */ +/** @} */ diff --git a/sys/auto_init/netif/auto_init_cc110x.c b/sys/auto_init/netif/auto_init_cc110x.c index a5faba120f19..e8b66c517ec3 100644 --- a/sys/auto_init/netif/auto_init_cc110x.c +++ b/sys/auto_init/netif/auto_init_cc110x.c @@ -22,8 +22,8 @@ #include "log.h" #include "debug.h" #include "board.h" -#include "net/gnrc/netdev.h" -#include "gnrc_netdev_cc110x.h" +#include "gnrc_netif2_cc110x.h" +#include "cc110x-netdev.h" #include "net/gnrc.h" #include "cc110x.h" @@ -35,7 +35,7 @@ */ #define CC110X_MAC_STACKSIZE (THREAD_STACKSIZE_DEFAULT + DEBUG_EXTRA_STACKSIZE) #ifndef CC110X_MAC_PRIO -#define CC110X_MAC_PRIO (GNRC_NETDEV_MAC_PRIO) +#define CC110X_MAC_PRIO (GNRC_NETIF2_PRIO) #endif #define CC110X_NUM (sizeof(cc110x_params)/sizeof(cc110x_params[0])) @@ -43,8 +43,6 @@ static netdev_cc110x_t cc110x_devs[CC110X_NUM]; static char _stacks[CC110X_NUM][CC110X_MAC_STACKSIZE]; -static gnrc_netdev_t _gnrc_netdev_devs[CC110X_NUM]; - void auto_init_cc110x(void) { for (unsigned i = 0; i < CC110X_NUM; i++) { @@ -57,12 +55,9 @@ void auto_init_cc110x(void) LOG_ERROR("[auto_init_netif] error initializing cc110x #%u\n", i); } else { - gnrc_netdev_cc110x_init(&_gnrc_netdev_devs[i], &cc110x_devs[i]); - res = gnrc_netdev_init(_stacks[i], CC110X_MAC_STACKSIZE, - CC110X_MAC_PRIO, "cc110x", &_gnrc_netdev_devs[i]); - if (res < 0) { - LOG_ERROR("[auto_init_netif] error starting gnrc_cc110x thread\n"); - } + gnrc_netif2_cc110x_create(_stacks[i], CC110X_MAC_STACKSIZE, + CC110X_MAC_PRIO, "cc110x", + (netdev_t *)&cc110x_devs[i]); } } }