Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cc110x: port to gnrc_netif2 #7414

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
35 changes: 35 additions & 0 deletions drivers/cc110x/include/gnrc_netif2_cc110x.h
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
*/
#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 */
/** @} */
17 changes: 6 additions & 11 deletions sys/auto_init/netif/auto_init_cc110x.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -35,16 +35,14 @@
*/
#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]))

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++) {
Expand All @@ -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]);
}
}
}
Expand Down