2015-04-23 18:56:43 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 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 tests
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Test application for AT86RF2xx network device driver
|
|
|
|
*
|
|
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2017-02-15 13:07:34 +01:00
|
|
|
#include "net/netdev.h"
|
2015-04-23 18:56:43 +02:00
|
|
|
#include "shell.h"
|
|
|
|
#include "shell_commands.h"
|
2016-01-25 00:17:49 +01:00
|
|
|
#include "thread.h"
|
|
|
|
#include "xtimer.h"
|
2015-04-23 18:56:43 +02:00
|
|
|
|
2016-01-25 00:17:49 +01:00
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
#define _STACKSIZE (THREAD_STACKSIZE_DEFAULT + THREAD_EXTRA_STACKSIZE_PRINTF)
|
|
|
|
#define MSG_TYPE_ISR (0x3456)
|
|
|
|
|
|
|
|
static char stack[_STACKSIZE];
|
|
|
|
static kernel_pid_t _recv_pid;
|
|
|
|
|
|
|
|
at86rf2xx_t devs[AT86RF2XX_NUM];
|
|
|
|
|
|
|
|
static const shell_command_t shell_commands[] = {
|
2017-02-15 13:07:34 +01:00
|
|
|
{ "ifconfig", "Configure netdev", ifconfig },
|
2016-01-25 00:17:49 +01:00
|
|
|
{ "txtsnd", "Send IEEE 802.15.4 packet", txtsnd },
|
|
|
|
{ NULL, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2017-02-15 13:07:34 +01:00
|
|
|
static void _event_cb(netdev_t *dev, netdev_event_t event)
|
2015-04-23 18:56:43 +02:00
|
|
|
{
|
2017-02-15 13:07:34 +01:00
|
|
|
if (event == NETDEV_EVENT_ISR) {
|
2016-01-25 00:17:49 +01:00
|
|
|
msg_t msg;
|
|
|
|
|
|
|
|
msg.type = MSG_TYPE_ISR;
|
2016-06-02 20:40:15 +02:00
|
|
|
msg.content.ptr = dev;
|
2016-01-25 00:17:49 +01:00
|
|
|
|
|
|
|
if (msg_send(&msg, _recv_pid) <= 0) {
|
2017-02-15 13:07:34 +01:00
|
|
|
puts("gnrc_netdev: possibly lost interrupt.");
|
2016-01-25 00:17:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (event) {
|
2017-02-15 13:07:34 +01:00
|
|
|
case NETDEV_EVENT_RX_COMPLETE:
|
2016-01-25 00:17:49 +01:00
|
|
|
{
|
|
|
|
recv(dev);
|
2015-04-23 18:56:43 +02:00
|
|
|
|
2016-01-25 00:17:49 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
puts("Unexpected event received");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void *_recv_thread(void *arg)
|
|
|
|
{
|
2017-10-26 00:26:48 +02:00
|
|
|
(void)arg;
|
2016-01-25 00:17:49 +01:00
|
|
|
while (1) {
|
|
|
|
msg_t msg;
|
|
|
|
msg_receive(&msg);
|
|
|
|
if (msg.type == MSG_TYPE_ISR) {
|
2017-02-15 13:07:34 +01:00
|
|
|
netdev_t *dev = msg.content.ptr;
|
2016-01-25 00:17:49 +01:00
|
|
|
dev->driver->isr(dev);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
puts("unexpected message type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
2015-04-23 18:56:43 +02:00
|
|
|
puts("AT86RF2xx device driver test");
|
2016-01-25 00:17:49 +01:00
|
|
|
xtimer_init();
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < AT86RF2XX_NUM; i++) {
|
2019-04-23 11:14:05 +02:00
|
|
|
netopt_enable_t en = NETOPT_ENABLE;
|
2016-01-25 00:17:49 +01:00
|
|
|
const at86rf2xx_params_t *p = &at86rf2xx_params[i];
|
2017-02-15 13:07:34 +01:00
|
|
|
netdev_t *dev = (netdev_t *)(&devs[i]);
|
2016-01-25 00:17:49 +01:00
|
|
|
|
|
|
|
printf("Initializing AT86RF2xx radio at SPI_%d\n", p->spi);
|
2019-01-03 22:56:15 +01:00
|
|
|
at86rf2xx_setup(&devs[i], p);
|
2016-01-25 00:17:49 +01:00
|
|
|
dev->event_callback = _event_cb;
|
|
|
|
dev->driver->init(dev);
|
2019-04-23 11:14:05 +02:00
|
|
|
dev->driver->set(dev, NETOPT_RX_END_IRQ, &en, sizeof(en));
|
2016-01-25 00:17:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_recv_pid = thread_create(stack, sizeof(stack), THREAD_PRIORITY_MAIN - 1,
|
|
|
|
THREAD_CREATE_STACKTEST, _recv_thread, NULL,
|
|
|
|
"recv_thread");
|
2015-04-23 18:56:43 +02:00
|
|
|
|
2016-01-25 00:17:49 +01:00
|
|
|
if (_recv_pid <= KERNEL_PID_UNDEF) {
|
|
|
|
puts("Creation of receiver thread failed");
|
|
|
|
return 1;
|
|
|
|
}
|
2015-04-23 18:56:43 +02:00
|
|
|
|
|
|
|
/* start the shell */
|
|
|
|
puts("Initialization successful - starting the shell now");
|
2015-07-14 18:42:46 +02:00
|
|
|
|
|
|
|
char line_buf[SHELL_DEFAULT_BUFSIZE];
|
2016-01-25 00:17:49 +01:00
|
|
|
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
|
2015-04-23 18:56:43 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|