1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #9336 from jia200x/openthread_ftd

pkg/openthread: rework of FTD and MTD support
This commit is contained in:
Alexandre Abadie 2018-10-16 17:23:55 +02:00 committed by GitHub
commit 77d97a6fa2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 512 additions and 354 deletions

View File

@ -649,11 +649,6 @@ ifneq (,$(filter random,$(USEMODULE)))
USEMODULE += luid
endif
ifneq (,$(filter openthread_contrib,$(USEMODULE)))
USEMODULE += openthread_contrib_netdev
FEATURES_REQUIRED += cpp
endif
ifneq (,$(filter asymcute,$(USEMODULE)))
USEMODULE += sock_udp
USEMODULE += sock_util

View File

@ -0,0 +1,52 @@
APPLICATION = openthread
# If no BOARD is found in the environment, use this default:
BOARD ?= samr21-xpro
# These are the boards that OpenThread stack has been tested on
BOARD_WHITELIST := samr21-xpro iotlab-m3 fox iotlab-a8-m3
# This has to be the absolute path to the RIOT base directory:
RIOTBASE ?= $(CURDIR)/../..
# Change this to 0 show compiler invocation lines by default:
QUIET ?= 1
USEPKG += openthread
OPENTHREAD_TYPE ?= ftd
ifeq ($(OPENTHREAD_TYPE),mtd)
# MTD: A Minimal Thread Device does not have router functionality
# compiled in. As a result, it is not necessary to configure the
# routerrole on an MTD. At the same time, an MTD may or may not be sleepy.
USEMODULE += openthread-mtd
USEMODULE += openthread-cli-mtd
else
# ftd: A Full Thread Device has router functionality compiled in
USEMODULE += openthread-ftd
USEMODULE += openthread-cli-ftd
endif
#Define PANID, CHANNEL and UART_BAUDRATE used by default
OPENTHREAD_PANID ?= 0xbeef
OPENTHREAD_CHANNEL ?= 26
CFLAGS += -DOPENTHREAD_PANID=$(OPENTHREAD_PANID)
CFLAGS += -DOPENTHREAD_CHANNEL=$(OPENTHREAD_CHANNEL)
ifneq (,$(filter samr21-xpro,$(BOARD)))
DRIVER := at86rf233
endif
ifneq (,$(filter iotlab-m3 fox iotlab-a8-m3,$(BOARD)))
DRIVER := at86rf231
endif
USEMODULE += $(DRIVER)
USEMODULE += random
USEMODULE += ps
#required for C++ compiling
CXXEXFLAGS += -fno-rtti
USEMODULE += cpp11-compat
include $(RIOTBASE)/Makefile.include

View File

@ -0,0 +1,70 @@
## OpenThread on RIOT
This example demonstrates how to use the [OpenThread](https://github.com/openthread/openthread)
open source implementation of [Thread](https://threadgroup.org/) on RIOT.
The [Command Line Interface](https://github.com/openthread/openthread/blob/master/examples/apps/cli/README.md) of
OpenThread was ported. Please check the
[full documentation](https://github.com/openthread/openthread/blob/master/src/cli/README.md)
of the CLI for usage information.
You can either build a FTD or MTD firmware:
- MTD: A Minimal Thread Device does not have router functionality compiled in.
An MTD may or may not be sleepy.
- FTD: A Full Thread Device has router functionality compiled in.
## Quick usage
With RIOT port, a node is auto-setup and ready to communicate with
this configuration:
```
OPENTHREAD_PANID=0xbeef
OPENTHREAD_CHANNEL=26
```
You can pass the panid/channel independently when building the firmware:
```
make BOARD=<target> OPENTHREAD_PANID=0xaaaa OPENTHREAD_TYPE=ftd flash term
```
```
make BOARD=<target> OPENTHREAD_CHANNEL=20 OPENTHREAD_TYPE=ftd flash term
```
To try OpenThread in RIOT, you can do the following:
1. Flash nodes with MTD or FTD functionality:
```
make BOARD=<target> clean all flash OPENTHREAD_TYPE=mtd
```
```
make BOARD=<target> clean all flash OPENTHREAD_TYPE=ftd
```
2. Check the state of the node with `state`. In the beginning, it should be
`detached`, but after some seconds it should become `leader`
3. Start another node and check that it becomes `router`. There is only one
leader in a Thread network.
4. Get the mesh IP address of a node with `ipaddr`.
```
ipaddr
fdde:ad00:beef::ff:fe00:8000
fe80::ff:fe00:8000
fdde:ad00:beef:0:946a:c722:a5d9:8481
fe80::3984:f4eb:d182:5dae
```
5. Ping from another node with
```
ping fdde:ad00:beef:0:946a:c722:a5d9:848
```
6. You can try IEEE802.15.4 scan with `scan` command
7. You can also check other commands with `help`
## OpenThread port on RIOT status
OpenThread port on RIOT is stable. In case of any bug, please report via
[GitHub issue](https://github.com/RIOT-OS/RIOT/issues/new?template=bug_report.md&title=Bug).

View File

@ -10,25 +10,21 @@
* @file
* @brief OpenThread test application
*
* @author Baptiste Clenet <baptiste.clenet@xsoen.com>
* @author Baptiste Clenet <bapclenet@gmail.com>
*/
#include <stdio.h>
#include "net/ipv6/addr.h"
#include "openthread/ip6.h"
#include "openthread/thread.h"
#include "openthread/udp.h"
#include "ot.h"
#include "shell.h"
#include "shell_commands.h"
int main(void)
{
printf("Get PANID\n");
puts("This a test for OpenThread");
/* Example of how to call OpenThread stack functions */
puts("Get PANID ");
uint16_t panid = 0;
uint8_t res = ot_call_command("panid", NULL, (void*)&panid);
printf("Current panid: 0x%x (res:%x)\n", panid, res);
openthread_uart_run();
return 0;
}

View File

@ -1,24 +1,31 @@
PKG_NAME=openthread
PKG_URL=https://github.com/openthread/openthread.git
PKG_VERSION=fbfd76a990b81f007957e1bd774e51bce742e53e
PKG_VERSION=thread-reference-20170716
PKG_BUILDDIR ?= $(PKGDIRBASE)/$(PKG_NAME)
$(info Compile OpenThread for FTD device)
OPENTHREAD_ARGS+= --enable-cli-app=ftd --enable-application-coap
$(info $$OPENTHREAD_ARGS is [$(OPENTHREAD_ARGS)])
ifneq (,$(filter openthread-cli-ftd,$(USEMODULE)))
$(info Compile OpenThread for FTD device)
OPENTHREAD_ARGS += --enable-cli-app=ftd
endif
ifneq (,$(filter openthread-cli-mtd,$(USEMODULE)))
$(info Compile OpenThread for MTD device)
OPENTHREAD_ARGS += --enable-cli-app=mtd --enable-joiner
endif
OPENTHREAD_ARGS += --enable-application-coap
CONFIG_FILE = OPENTHREAD_PROJECT_CORE_CONFIG_FILE='\"platform_config.h\"'
$(info $$OPENTHREAD_ARGS is [${OPENTHREAD_ARGS}])
.PHONY: all
OPENTHREAD_COMMON_FLAGS = -fdata-sections -ffunction-sections -Os
OPENTHREAD_COMMON_FLAGS += -Wno-implicit-fallthrough
OPENTHREAD_COMMON_FLAGS += -Wno-implicit-fallthrough -Wno-unused-parameter
all: git-download
cd $(PKG_BUILDDIR) && PREFIX="/" ./bootstrap
cd $(PKG_BUILDDIR) && CPP="$(CPP)" CC="$(CC)" CXX="$(CXX)"\
OBJC="" OBJCXX="" AR="$(AR)" RANLIB="$(RANLIB)" NM="$(NM)" \
STRIP="$(STRIP)" \
CPPFLAGS="$(OPENTHREAD_COMMON_FLAGS) $(CFLAGS_CPU) " \
CPPFLAGS="$(OPENTHREAD_COMMON_FLAGS) $(CFLAGS_CPU) -D$(CONFIG_FILE)" \
CFLAGS="$(OPENTHREAD_COMMON_FLAGS) $(CFLAGS_CPU) " \
CXXFLAGS="$(OPENTHREAD_COMMON_FLAGS) $(CFLAGS_CPU) -fno-exceptions -fno-rtti " \
LDFLAGS="$(OPENTHREAD_COMMON_FLAGS) $(CFLAGS_CPU) -nostartfiles -specs=nano.specs \
@ -27,9 +34,14 @@ all: git-download
--prefix=/ --enable-default-logging $(OPENTHREAD_ARGS)
cd $(PKG_BUILDDIR) && DESTDIR=$(PKG_BUILDDIR)/output PREFIX=/ make -j4 --no-print-directory install
cp $(PKG_BUILDDIR)/output/lib/libmbedcrypto.a $(BINDIR)/libmbedcrypto.a
cp $(PKG_BUILDDIR)/output/lib/libopenthread-ftd.a $(BINDIR)/libopenthread.a
cp $(PKG_BUILDDIR)/output/lib/libopenthread-cli-ftd.a $(BINDIR)/libopenthread-cli.a
sed -ie 's/BASE/_BASE/g' $(PKG_BUILDDIR)/output/include/openthread/types.h
cp $(PKG_BUILDDIR)/output/lib/libmbedcrypto.a ${BINDIR}/mbedcrypto.a
ifneq (,$(filter openthread-cli-ftd,$(USEMODULE)))
cp $(PKG_BUILDDIR)/output/lib/libopenthread-ftd.a ${BINDIR}/openthread-ftd.a
cp $(PKG_BUILDDIR)/output/lib/libopenthread-cli-ftd.a ${BINDIR}/openthread-cli-ftd.a
endif
ifneq (,$(filter openthread-cli-mtd,$(USEMODULE)))
cp $(PKG_BUILDDIR)/output/lib/libopenthread-mtd.a ${BINDIR}/openthread-mtd.a
cp $(PKG_BUILDDIR)/output/lib/libopenthread-cli-mtd.a ${BINDIR}/openthread-cli-mtd.a
endif
include $(RIOTBASE)/pkg/pkg.mk

View File

@ -0,0 +1,10 @@
ifneq (,$(filter openthread,$(USEPKG)))
USEMODULE += openthread_contrib
USEMODULE += mbedcrypto
endif
ifneq (,$(filter openthread_contrib,$(USEMODULE)))
USEMODULE += openthread_contrib_netdev
USEMODULE += xtimer
FEATURES_REQUIRED += cpp
endif

View File

@ -1,8 +1,7 @@
OPENTHREAD_DIR = $(RIOTBASE)/pkg/openthread
INCLUDES += -I$(OPENTHREAD_DIR)/include \
-I$(PKGDIRBASE)/openthread/output/include \
-I$(PKGDIRBASE)/openthread/include/openthread \
-I$(PKGDIRBASE)/openthread/include
ifneq (,$(filter openthread_contrib,$(USEMODULE)))
DIRS += $(OPENTHREAD_DIR)/contrib

78
pkg/openthread/contrib/netdev/openthread_netdev.c Normal file → Executable file
View File

@ -13,6 +13,7 @@
* @brief Netdev adoption for OpenThread
*
* @author Jose Ignacio Alamos <jialamos@uc.cl>
* @author Baptiste Clenet <bapclenet@gmail.com>
* @}
*/
@ -23,7 +24,7 @@
#include "openthread/cli.h"
#include "openthread/instance.h"
#include "openthread/ip6.h"
#include "openthread/platform/alarm.h"
#include "openthread/platform/alarm-milli.h"
#include "openthread/platform/uart.h"
#include "openthread/tasklet.h"
#include "openthread/thread.h"
@ -39,18 +40,6 @@ static msg_t _queue[OPENTHREAD_QUEUE_LEN];
static kernel_pid_t _pid;
static otInstance *sInstance;
/**
* @name Default configuration for OpenThread network
* @{
*/
#ifndef OPENTHREAD_PANID
#define OPENTHREAD_PANID 0x1234
#endif
#ifndef OPENTHREAD_CHANNEL
#define OPENTHREAD_CHANNEL (26U)
#endif
/** @} */
uint8_t ot_call_command(char* command, void *arg, void* answer) {
ot_job_t job;
@ -67,7 +56,7 @@ uint8_t ot_call_command(char* command, void *arg, void* answer) {
/* OpenThread will call this when switching state from empty tasklet to non-empty tasklet. */
void otTaskletsSignalPending(otInstance *aInstance) {
otTaskletsProcess(aInstance);
(void) aInstance;
}
static void *_openthread_event_loop(void *arg) {
@ -78,18 +67,14 @@ static void *_openthread_event_loop(void *arg) {
otPlatUartEnable();
/* init OpenThread */
sInstance = otInstanceInit();
sInstance = otInstanceInitSingle();
msg_init_queue(_queue, OPENTHREAD_QUEUE_LEN);
netdev_t *dev;
msg_t msg, reply;
#if defined(MODULE_OPENTHREAD_CLI_FTD) || defined(MODULE_OPENTHREAD_CLI_MTD)
otCliUartInit(sInstance);
#if OPENTHREAD_ENABLE_DIAG
diagInit(sInstance);
#endif
/* Init default parameters */
otPanId panid = OPENTHREAD_PANID;
uint8_t channel = OPENTHREAD_CHANNEL;
@ -99,31 +84,40 @@ static void *_openthread_event_loop(void *arg) {
otIp6SetEnabled(sInstance, true);
/* Start Thread protocol operation */
otThreadSetEnabled(sInstance, true);
#endif
#if OPENTHREAD_ENABLE_DIAG
diagInit(sInstance);
#endif
uint8_t *buf;
ot_job_t *job;
serial_msg_t* serialBuffer;
while (1) {
msg_receive(&msg);
switch (msg.type) {
case OPENTHREAD_XTIMER_MSG_TYPE_EVENT:
/* Tell OpenThread a time event was received */
otPlatAlarmFired(sInstance);
break;
case OPENTHREAD_NETDEV_MSG_TYPE_EVENT:
/* Received an event from driver */
dev = msg.content.ptr;
dev->driver->isr(dev);
break;
case OPENTHREAD_SERIAL_MSG_TYPE_EVENT:
/* Tell OpenThread about the reception of a CLI command */
buf = msg.content.ptr;
otPlatUartReceived(buf, strlen((char *) buf));
break;
case OPENTHREAD_JOB_MSG_TYPE_EVENT:
job = msg.content.ptr;
reply.content.value = ot_exec_command(sInstance, job->command, job->arg, job->answer);
msg_reply(&msg, &reply);
break;
otTaskletsProcess(sInstance);
if (otTaskletsArePending(sInstance) == false) {
msg_receive(&msg);
switch (msg.type) {
case OPENTHREAD_XTIMER_MSG_TYPE_EVENT:
/* Tell OpenThread a time event was received */
otPlatAlarmMilliFired(sInstance);
break;
case OPENTHREAD_NETDEV_MSG_TYPE_EVENT:
/* Received an event from driver */
dev = msg.content.ptr;
dev->driver->isr(dev);
break;
case OPENTHREAD_SERIAL_MSG_TYPE_EVENT:
/* Tell OpenThread about the reception of a CLI command */
serialBuffer = (serial_msg_t*)msg.content.ptr;
otPlatUartReceived((uint8_t*) serialBuffer->buf,serialBuffer->length);
serialBuffer->serial_buffer_status = OPENTHREAD_SERIAL_BUFFER_STATUS_FREE;
break;
case OPENTHREAD_JOB_MSG_TYPE_EVENT:
job = msg.content.ptr;
reply.content.value = ot_exec_command(sInstance, job->command, job->arg, job->answer);
msg_reply(&msg, &reply);
break;
}
}
}

View File

@ -18,7 +18,7 @@
#include <assert.h>
#include "openthread/platform/alarm.h"
#include "openthread/platform/alarm-milli.h"
#include "openthread/platform/uart.h"
#include "ot.h"
#include "random.h"
@ -41,29 +41,10 @@
static at86rf2xx_t at86rf2xx_dev;
#endif
#define OPENTHREAD_NETDEV_BUFLEN (ETHERNET_MAX_LEN)
static uint8_t rx_buf[OPENTHREAD_NETDEV_BUFLEN];
static uint8_t tx_buf[OPENTHREAD_NETDEV_BUFLEN];
static char ot_thread_stack[2 * THREAD_STACKSIZE_MAIN];
/* init and run OpeanThread's UART simulation (stdio) */
void openthread_uart_run(void)
{
char buf[256];
msg_t msg;
msg.type = OPENTHREAD_SERIAL_MSG_TYPE_EVENT;
msg.content.ptr = buf;
buf[1] = 0;
while (1) {
char c = getchar();
buf[0] = c;
msg_send(&msg, openthread_get_pid());
}
}
void openthread_bootstrap(void)
{
/* init random */

View File

@ -19,7 +19,7 @@
#include <stdint.h>
#include "msg.h"
#include "openthread/platform/alarm.h"
#include "openthread/platform/alarm-milli.h"
#include "ot.h"
#include "thread.h"
#include "xtimer.h"
@ -38,7 +38,7 @@ static msg_t ot_alarm_msg;
* @param[in] aT0 The reference time.
* @param[in] aDt The time delay in milliseconds from @p aT0.
*/
void otPlatAlarmStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt)
void otPlatAlarmMilliStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt)
{
(void)aInstance;
(void)aT0;
@ -56,7 +56,7 @@ void otPlatAlarmStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt)
}
/* OpenThread will call this to stop alarms */
void otPlatAlarmStop(otInstance *aInstance)
void otPlatAlarmMilliStop(otInstance *aInstance)
{
(void)aInstance;
DEBUG("openthread: otPlatAlarmStop\n");
@ -64,7 +64,7 @@ void otPlatAlarmStop(otInstance *aInstance)
}
/* OpenThread will call this for getting running time in millisecs */
uint32_t otPlatAlarmGetNow(void)
uint32_t otPlatAlarmMilliGetNow(void)
{
uint32_t now = xtimer_now_usec() / US_PER_MS;
DEBUG("openthread: otPlatAlarmGetNow: %" PRIu32 "\n", now);

View File

@ -264,26 +264,23 @@ OT_COMMAND ot_state(otInstance* ot_instance, void* arg, void* answer) {
(void)arg;
if (answer != NULL) {
uint8_t state = otThreadGetDeviceRole(ot_instance);
*((uint8_t *) answer) = state;
otDeviceRole state = otThreadGetDeviceRole(ot_instance);
*((otDeviceRole *) answer) = state;
DEBUG("state: ");
switch (state) {
case kDeviceRoleOffline:
puts("offline");
break;
case kDeviceRoleDisabled:
case OT_DEVICE_ROLE_DISABLED:
puts("disabled");
break;
case kDeviceRoleDetached:
case OT_DEVICE_ROLE_DETACHED:
puts("detached");
break;
case kDeviceRoleChild:
case OT_DEVICE_ROLE_CHILD:
puts("child");
break;
case kDeviceRoleRouter:
case OT_DEVICE_ROLE_ROUTER:
puts("router");
break;
case kDeviceRoleLeader:
case OT_DEVICE_ROLE_LEADER:
puts("leader");
break;
default:

View File

@ -13,6 +13,7 @@
* @brief Implementation of OpenThread logging platform abstraction
*
* @author Jose Ignacio Alamos <jialamos@uc.cl>
* @author Baptiste Clenet <bapclenet@gmail.com>
* @}
*/
@ -20,10 +21,9 @@
#include <inttypes.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <time.h>
#include "openthread/config.h"
#include "openthread/platform/logging.h"
/* adapted from OpenThread posix example:
@ -31,68 +31,11 @@
__attribute__((__format__ (__printf__, 3, 4)))
void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...)
{
(void) aLogLevel;
(void) aLogRegion;
va_list args;
switch (aLogLevel) {
case kLogLevelNone:
fprintf(stderr, "NONE ");
break;
case kLogLevelCrit:
fprintf(stderr, "CRIT ");
break;
case kLogLevelWarn:
fprintf(stderr, "WARN ");
break;
case kLogLevelInfo:
fprintf(stderr, "INFO ");
break;
case kLogLevelDebg:
fprintf(stderr, "DEBG ");
break;
}
switch (aLogRegion) {
case kLogRegionApi:
fprintf(stderr, "API ");
break;
case kLogRegionMle:
fprintf(stderr, "MLE ");
break;
case kLogRegionArp:
fprintf(stderr, "ARP ");
break;
case kLogRegionNetData:
fprintf(stderr, "NETD ");
break;
case kLogRegionIp6:
fprintf(stderr, "IPV6 ");
break;
case kLogRegionIcmp:
fprintf(stderr, "ICMP ");
break;
case kLogRegionMac:
fprintf(stderr, "MAC ");
break;
case kLogRegionMem:
fprintf(stderr, "MEM ");
break;
default:
break;
}
va_start(args, aFormat);
vfprintf(stderr, aFormat, args);
fprintf(stderr, "\r");
fprintf(stderr, "\n");
va_end(args);
}

View File

@ -21,10 +21,13 @@
#include "openthread/platform/misc.h"
#include "periph/pm.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
void otPlatReset(otInstance *aInstance)
{
(void)aInstance;
printf("reboot...\n");
DEBUG("reboot...\n");
pm_reboot();
}
@ -32,5 +35,10 @@ otPlatResetReason otPlatGetResetReason(otInstance *aInstance)
{
(void)aInstance;
/* TODO: Write me! */
return kPlatResetReason_PowerOn;
return OT_PLAT_RESET_REASON_POWER_ON;
}
void otPlatWakeHost(void)
{
/* TODO: implement an operation to wake the host from sleep state. */
}

183
pkg/openthread/contrib/platform_radio.c Normal file → Executable file
View File

@ -26,6 +26,9 @@
#include "net/ethertype.h"
#include "net/ieee802154.h"
#include "net/netdev/ieee802154.h"
#include "openthread/config.h"
#include "openthread/openthread.h"
#include "openthread/platform/diag.h"
#include "openthread/platform/radio.h"
#include "ot.h"
@ -34,14 +37,12 @@
#define RADIO_IEEE802154_FCS_LEN (2U)
static RadioPacket sTransmitFrame;
static RadioPacket sReceiveFrame;
static otRadioFrame sTransmitFrame;
static otRadioFrame sReceiveFrame;
static int8_t Rssi;
static netdev_t *_dev;
static bool sDisabled;
/* set 15.4 channel */
static int _set_channel(uint16_t channel)
{
@ -54,6 +55,13 @@ static int _set_power(int16_t power)
return _dev->driver->set(_dev, NETOPT_TX_POWER, &power, sizeof(int16_t));
}
static int _get_power(void)
{
int16_t power;
_dev->driver->get(_dev, NETOPT_TX_POWER, &power, sizeof(int16_t));
return power;
}
/* set IEEE802.15.4 PAN ID */
static int _set_panid(uint16_t panid)
{
@ -101,6 +109,11 @@ static netopt_state_t _get_state(void)
return state;
}
static void _set_off(void)
{
_set_state(NETOPT_STATE_OFF);
}
/* sets device state to SLEEP */
static void _set_sleep(void)
{
@ -134,7 +147,7 @@ void recv_pkt(otInstance *aInstance, netdev_t *dev)
/* very unlikely */
if ((len < 0) || ((uint32_t)len > UINT16_MAX)) {
DEBUG("Invalid len: %d\n", len);
otPlatRadioReceiveDone(aInstance, NULL, kThreadError_Abort);
otPlatRadioReceiveDone(aInstance, NULL, OT_ERROR_ABORT);
return;
}
@ -148,16 +161,16 @@ void recv_pkt(otInstance *aInstance, netdev_t *dev)
/* Get RSSI from a radio driver. RSSI should be in [dBm] */
Rssi = (int8_t)rx_info.rssi;
sReceiveFrame.mPower = Rssi;
DEBUG("Received message: len %d\n", (int) sReceiveFrame.mLength);
for (int i = 0; i < sReceiveFrame.mLength; ++i) {
DEBUG("%x ", sReceiveFrame.mPsdu[i]);
if (ENABLE_DEBUG) {
DEBUG("Received message: len %d\n", (int) sReceiveFrame.mLength);
for (int i = 0; i < sReceiveFrame.mLength; ++i) {
DEBUG("%x ", sReceiveFrame.mPsdu[i]);
}
DEBUG("\n");
}
DEBUG("\n");
/* Tell OpenThread that receive has finished */
otPlatRadioReceiveDone(aInstance, res > 0 ? &sReceiveFrame : NULL, res > 0 ? kThreadError_None : kThreadError_Abort);
otPlatRadioReceiveDone(aInstance, res > 0 ? &sReceiveFrame : NULL, res > 0 ? OT_ERROR_NONE : OT_ERROR_ABORT);
}
/* Called upon TX event */
@ -169,19 +182,19 @@ void send_pkt(otInstance *aInstance, netdev_t *dev, netdev_event_t event)
switch (event) {
case NETDEV_EVENT_TX_COMPLETE:
DEBUG("openthread: NETDEV_EVENT_TX_COMPLETE\n");
otPlatRadioTransmitDone(aInstance, &sTransmitFrame, false, kThreadError_None);
otPlatRadioTxDone(aInstance, &sTransmitFrame, NULL, OT_ERROR_NONE);
break;
case NETDEV_EVENT_TX_COMPLETE_DATA_PENDING:
DEBUG("openthread: NETDEV_EVENT_TX_COMPLETE_DATA_PENDING\n");
otPlatRadioTransmitDone(aInstance, &sTransmitFrame, true, kThreadError_None);
otPlatRadioTxDone(aInstance, &sTransmitFrame, NULL, OT_ERROR_NONE);
break;
case NETDEV_EVENT_TX_NOACK:
DEBUG("openthread: NETDEV_EVENT_TX_NOACK\n");
otPlatRadioTransmitDone(aInstance, &sTransmitFrame, false, kThreadError_NoAck);
otPlatRadioTxDone(aInstance, &sTransmitFrame, NULL, OT_ERROR_NO_ACK);
break;
case NETDEV_EVENT_TX_MEDIUM_BUSY:
DEBUG("openthread: NETDEV_EVENT_TX_MEDIUM_BUSY\n");
otPlatRadioTransmitDone(aInstance, &sTransmitFrame, false, kThreadError_ChannelAccessFailure);
otPlatRadioTxDone(aInstance, &sTransmitFrame, NULL, OT_ERROR_CHANNEL_ACCESS_FAILURE);
break;
default:
break;
@ -201,55 +214,59 @@ void otPlatRadioSetExtendedAddress(otInstance *aInstance, uint8_t *aExtendedAddr
{
(void)aInstance;
DEBUG("openthread: otPlatRadioSetExtendedAddress\n");
uint8_t reversed_addr[IEEE802154_LONG_ADDRESS_LEN];
char reversed_addr[IEEE802154_LONG_ADDRESS_LEN];
for (unsigned i = 0; i < IEEE802154_LONG_ADDRESS_LEN; i++) {
reversed_addr[i] = aExtendedAddress[IEEE802154_LONG_ADDRESS_LEN - 1 - i];
reversed_addr[i] = (uint8_t) ((uint8_t *)aExtendedAddress)[IEEE802154_LONG_ADDRESS_LEN - 1 - i];
}
_set_long_addr(reversed_addr);
if (ENABLE_DEBUG) {
for (unsigned i = 0; i < IEEE802154_LONG_ADDRESS_LEN; ++i) {
DEBUG("%x ", (uint8_t) ((uint8_t *)reversed_addr)[i]);
}
DEBUG("\n");
}
_set_long_addr((uint8_t*) reversed_addr);
}
/* OpenThread will call this for setting short address */
void otPlatRadioSetShortAddress(otInstance *aInstance, uint16_t aShortAddress)
{
(void) aInstance;
(void)aInstance;
DEBUG("openthread: otPlatRadioSetShortAddress: setting address to %04x\n", aShortAddress);
_set_addr(((aShortAddress & 0xff) << 8) | ((aShortAddress >> 8) & 0xff));
}
/* OpenThread will call this for enabling the radio */
ThreadError otPlatRadioEnable(otInstance *aInstance)
otError otPlatRadioEnable(otInstance *aInstance)
{
DEBUG("openthread: otPlatRadioEnable\n");
(void) aInstance;
(void)aInstance;
if (sDisabled) {
sDisabled = false;
_set_idle();
}
return kThreadError_None;
}
/* OpenThread will call this for disabling the radio */
ThreadError otPlatRadioDisable(otInstance *aInstance)
{
DEBUG("openthread: otPlatRadioDisable\n");
(void) aInstance;
if (!sDisabled) {
sDisabled = true;
if (!otPlatRadioIsEnabled(aInstance)) {
_set_sleep();
}
return kThreadError_None;
return OT_ERROR_NONE;
}
/* OpenThread will call this for disabling the radio */
otError otPlatRadioDisable(otInstance *aInstance)
{
DEBUG("openthread: otPlatRadioDisable\n");
(void)aInstance;
if (otPlatRadioIsEnabled(aInstance)) {
_set_off();
}
return OT_ERROR_NONE;
}
bool otPlatRadioIsEnabled(otInstance *aInstance)
{
DEBUG("otPlatRadioIsEnabled\n");
(void) aInstance;
(void)aInstance;
netopt_state_t state = _get_state();
if (state == NETOPT_STATE_OFF || state == NETOPT_STATE_SLEEP) {
if (state == NETOPT_STATE_OFF) {
return false;
} else {
return true;
@ -257,30 +274,31 @@ bool otPlatRadioIsEnabled(otInstance *aInstance)
}
/* OpenThread will call this for setting device state to SLEEP */
ThreadError otPlatRadioSleep(otInstance *aInstance)
otError otPlatRadioSleep(otInstance *aInstance)
{
DEBUG("otPlatRadioSleep\n");
(void) aInstance;
(void)aInstance;
_set_sleep();
return kThreadError_None;
return OT_ERROR_NONE;
}
/*OpenThread will call this for waiting the reception of a packet */
ThreadError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel)
otError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel)
{
DEBUG("openthread: otPlatRadioReceive. Channel: %i\n", aChannel);
(void) aInstance;
(void)aInstance;
_set_idle();
_set_channel(aChannel);
return kThreadError_None;
sReceiveFrame.mChannel = aChannel;
return OT_ERROR_NONE;
}
/* OpenThread will call this function to get the transmit buffer */
RadioPacket *otPlatRadioGetTransmitBuffer(otInstance *aInstance)
otRadioFrame *otPlatRadioGetTransmitBuffer(otInstance *aInstance)
{
(void) aInstance;
(void)aInstance;
DEBUG("openthread: otPlatRadioGetTransmitBuffer\n");
return &sTransmitFrame;
}
@ -293,8 +311,28 @@ void otPlatRadioSetDefaultTxPower(otInstance *aInstance, int8_t aPower)
_set_power(aPower);
}
otError otPlatRadioGetTransmitPower(otInstance *aInstance, int8_t *aPower)
{
(void)aInstance;
if (aPower == NULL) {
return OT_ERROR_INVALID_ARGS;
}
*aPower = _get_power();
return OT_ERROR_NONE;
}
otError otPlatRadioSetTransmitPower(otInstance *aInstance, int8_t aPower)
{
(void)aInstance;
_set_power(aPower);
return OT_ERROR_NONE;
}
/* OpenThread will call this for transmitting a packet*/
ThreadError otPlatRadioTransmit(otInstance *aInstance, RadioPacket *aPacket)
otError otPlatRadioTransmit(otInstance *aInstance, otRadioFrame *aPacket)
{
(void) aInstance;
@ -308,33 +346,36 @@ ThreadError otPlatRadioTransmit(otInstance *aInstance, RadioPacket *aPacket)
};
/*Set channel and power based on transmit frame */
DEBUG("otPlatRadioTransmit->channel: %i, length %d\n", (int) aPacket->mChannel, (int)aPacket->mLength);
for (int i = 0; i < aPacket->mLength; ++i) {
DEBUG("%x ", aPacket->mPsdu[i]);
if (ENABLE_DEBUG) {
DEBUG("otPlatRadioTransmit->channel: %i, length %d\n",
(int) aPacket->mChannel, (int)aPacket->mLength);
for (size_t i = 0; i < aPacket->mLength; ++i) {
DEBUG("%x ", aPacket->mPsdu[i]);
}
DEBUG("\n");
}
DEBUG("\n");
_set_channel(aPacket->mChannel);
_set_power(aPacket->mPower);
/* send packet though netdev */
_dev->driver->send(_dev, &iolist);
otPlatRadioTxStarted(aInstance, aPacket);
return kThreadError_None;
return OT_ERROR_NONE;
}
/* OpenThread will call this for getting the radio caps */
otRadioCaps otPlatRadioGetCaps(otInstance *aInstance)
{
(void) aInstance;
(void)aInstance;
DEBUG("openthread: otPlatRadioGetCaps\n");
/* all drivers should handle ACK, including call of NETDEV_EVENT_TX_NOACK */
return kRadioCapsNone;
return OT_RADIO_CAPS_TRANSMIT_RETRIES | OT_RADIO_CAPS_ACK_TIMEOUT;
}
/* OpenThread will call this for getting the state of promiscuous mode */
bool otPlatRadioGetPromiscuous(otInstance *aInstance)
{
(void) aInstance;
(void)aInstance;
DEBUG("openthread: otPlatRadioGetPromiscuous\n");
return _is_promiscuous();
}
@ -342,7 +383,7 @@ bool otPlatRadioGetPromiscuous(otInstance *aInstance)
/* OpenThread will call this for setting the state of promiscuous mode */
void otPlatRadioSetPromiscuous(otInstance *aInstance, bool aEnable)
{
(void) aInstance;
(void)aInstance;
DEBUG("openthread: otPlatRadioSetPromiscuous\n");
_set_promiscuous((aEnable) ? NETOPT_ENABLE : NETOPT_DISABLE);
}
@ -350,7 +391,7 @@ void otPlatRadioSetPromiscuous(otInstance *aInstance, bool aEnable)
int8_t otPlatRadioGetRssi(otInstance *aInstance)
{
DEBUG("otPlatRadioGetRssi\n");
(void) aInstance;
(void)aInstance;
return Rssi;
}
@ -361,36 +402,36 @@ void otPlatRadioEnableSrcMatch(otInstance *aInstance, bool aEnable)
(void)aEnable;
}
ThreadError otPlatRadioAddSrcMatchShortEntry(otInstance *aInstance, const uint16_t aShortAddress)
otError otPlatRadioAddSrcMatchShortEntry(otInstance *aInstance, const uint16_t aShortAddress)
{
DEBUG("otPlatRadioAddSrcMatchShortEntry\n");
(void)aInstance;
(void)aShortAddress;
return kThreadError_None;
return OT_ERROR_NONE;
}
ThreadError otPlatRadioAddSrcMatchExtEntry(otInstance *aInstance, const uint8_t *aExtAddress)
otError otPlatRadioAddSrcMatchExtEntry(otInstance *aInstance, const uint8_t *aExtAddress)
{
DEBUG("otPlatRadioAddSrcMatchExtEntry\n");
(void)aInstance;
(void)aExtAddress;
return kThreadError_None;
return OT_ERROR_NONE;
}
ThreadError otPlatRadioClearSrcMatchShortEntry(otInstance *aInstance, const uint16_t aShortAddress)
otError otPlatRadioClearSrcMatchShortEntry(otInstance *aInstance, const uint16_t aShortAddress)
{
DEBUG("otPlatRadioClearSrcMatchShortEntry\n");
(void)aInstance;
(void)aShortAddress;
return kThreadError_None;
return OT_ERROR_NONE;
}
ThreadError otPlatRadioClearSrcMatchExtEntry(otInstance *aInstance, const uint8_t *aExtAddress)
otError otPlatRadioClearSrcMatchExtEntry(otInstance *aInstance, const uint8_t *aExtAddress)
{
DEBUG("otPlatRadioClearSrcMatchExtEntry\n");
(void)aInstance;
(void)aExtAddress;
return kThreadError_None;
return OT_ERROR_NONE;
}
void otPlatRadioClearSrcMatchShortEntries(otInstance *aInstance)
@ -405,13 +446,13 @@ void otPlatRadioClearSrcMatchExtEntries(otInstance *aInstance)
(void)aInstance;
}
ThreadError otPlatRadioEnergyScan(otInstance *aInstance, uint8_t aScanChannel, uint16_t aScanDuration)
otError otPlatRadioEnergyScan(otInstance *aInstance, uint8_t aScanChannel, uint16_t aScanDuration)
{
DEBUG("otPlatRadioEnergyScan\n");
(void)aInstance;
(void)aScanChannel;
(void)aScanDuration;
return kThreadError_NotImplemented;
return OT_ERROR_NOT_IMPLEMENTED;
}
void otPlatRadioGetIeeeEui64(otInstance *aInstance, uint8_t *aIeee64Eui64)

View File

@ -49,3 +49,13 @@ uint32_t otPlatRandomGet(void)
DEBUG("otPlatRandomGet: %i\n", (int) rand_val);
return rand_val;
}
otError otPlatRandomGetTrue(uint8_t *aOutput, uint16_t aOutputLength)
{
for (uint16_t index = 0; index < aOutputLength; index++) {
aOutput[index] = 0;
uint32_t rand_val = random_uint32();
aOutput[index] = (uint8_t) rand_val;
}
return OT_ERROR_NONE;
}

View File

@ -27,26 +27,26 @@ void otPlatSettingsInit(otInstance *aInstance)
(void)aInstance;
}
ThreadError otPlatSettingsBeginChange(otInstance *aInstance)
otError otPlatSettingsBeginChange(otInstance *aInstance)
{
(void)aInstance;
return kThreadError_None;
return OT_ERROR_NONE;
}
ThreadError otPlatSettingsCommitChange(otInstance *aInstance)
otError otPlatSettingsCommitChange(otInstance *aInstance)
{
DEBUG("openthread: otPlatSettingsCommitChange\n");
(void)aInstance;
return kThreadError_None;
return OT_ERROR_NONE;
}
ThreadError otPlatSettingsAbandonChange(otInstance *aInstance)
otError otPlatSettingsAbandonChange(otInstance *aInstance)
{
(void)aInstance;
return kThreadError_None;
return OT_ERROR_NONE;
}
ThreadError otPlatSettingsGet(otInstance *aInstance, uint16_t aKey, int aIndex, uint8_t *aValue, uint16_t *aValueLength)
otError otPlatSettingsGet(otInstance *aInstance, uint16_t aKey, int aIndex, uint8_t *aValue, uint16_t *aValueLength)
{
(void)aInstance;
(void)aKey;
@ -55,36 +55,33 @@ ThreadError otPlatSettingsGet(otInstance *aInstance, uint16_t aKey, int aIndex,
DEBUG("openthread: otPlatSettingsGet\n");
*aValueLength = 0;
return kThreadError_NotImplemented;
return OT_ERROR_NOT_IMPLEMENTED;
}
ThreadError otPlatSettingsSet(otInstance *aInstance, uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
otError otPlatSettingsSet(otInstance *aInstance, uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
{
(void)aInstance;
(void)aKey;
(void)aValue;
(void)aValueLength;
return kThreadError_None;
return OT_ERROR_NONE;
}
ThreadError otPlatSettingsAdd(otInstance *aInstance, uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
otError otPlatSettingsAdd(otInstance *aInstance, uint16_t aKey, const uint8_t *aValue, uint16_t aValueLength)
{
(void)aInstance;
(void)aKey;
(void)aValue;
(void)aValueLength;
return kThreadError_None;
return OT_ERROR_NONE;
}
ThreadError otPlatSettingsDelete(otInstance *aInstance, uint16_t aKey, int aIndex)
otError otPlatSettingsDelete(otInstance *aInstance, uint16_t aKey, int aIndex)
{
(void)aInstance;
(void)aKey;
(void)aIndex;
return kThreadError_None;
return OT_ERROR_NONE;
}
void otPlatSettingsWipe(otInstance *aInstance)

62
pkg/openthread/contrib/platform_uart.c Normal file → Executable file
View File

@ -13,34 +13,82 @@
* @brief Implementation of OpenThread UART platform abstraction
*
* @author Jose Ignacio Alamos <jialamos@uc.cl>
* @author Baptiste Clenet <bapclenet@gmail.com>
* @}
*/
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "stdio_uart.h"
#include "periph/uart.h"
#include "openthread/types.h"
#include "openthread/platform/uart.h"
#include "ot.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
#define OPENTHREAD_SPINEL_FRAME_MARKER (0x7e)
static serial_msg_t gSerialMessage[OPENTHREAD_NUMBER_OF_SERIAL_BUFFER];
static uint16_t frameLength = 0;
static void uart_handler(void* arg, char c) {
(void)arg;
if (frameLength == 0) {
memset(&gSerialMessage[0], 0, sizeof(serial_msg_t));
}
switch (c) {
case '\r':
case '\n':
if (frameLength > 0) {
gSerialMessage[0].buf[frameLength] = c;
frameLength++;
gSerialMessage[0].length = frameLength;
msg_t msg;
msg.type = OPENTHREAD_SERIAL_MSG_TYPE_EVENT;
msg.content.ptr = &gSerialMessage[0];
msg_send_int(&msg, openthread_get_pid());
frameLength = 0;
}
break;
default:
if (frameLength < OPENTHREAD_SERIAL_BUFFER_SIZE) {
gSerialMessage[0].buf[frameLength] = c;
frameLength++;
}
break;
}
}
/* OpenThread will call this for enabling UART (required for OpenThread's CLI)*/
ThreadError otPlatUartEnable(void)
otError otPlatUartEnable(void)
{
return kThreadError_None;
for (uint8_t i = 0; i < OPENTHREAD_NUMBER_OF_SERIAL_BUFFER; i++) {
gSerialMessage[i].serial_buffer_status = OPENTHREAD_SERIAL_BUFFER_STATUS_FREE;
}
uart_init(STDIO_UART_DEV, STDIO_UART_BAUDRATE, (uart_rx_cb_t) uart_handler, NULL);
return OT_ERROR_NONE;
}
/* OpenThread will call this for disabling UART */
ThreadError otPlatUartDisable(void)
otError otPlatUartDisable(void)
{
return kThreadError_None;
uart_poweroff(STDIO_UART_DEV);
return OT_ERROR_NONE;
}
/* OpenThread will call this for sending data through UART */
ThreadError otPlatUartSend(const uint8_t *aBuf, uint16_t aBufLength)
otError otPlatUartSend(const uint8_t *aBuf, uint16_t aBufLength)
{
uart_write(UART_DEV(0), aBuf, aBufLength);
uart_write(STDIO_UART_DEV, aBuf, aBufLength);
/* Tell OpenThread the sending of UART is done */
otPlatUartSendDone();
return kThreadError_None;
return OT_ERROR_NONE;
}

59
pkg/openthread/include/ot.h Normal file → Executable file
View File

@ -17,7 +17,8 @@
*
* @file
*
* @author José Ignacio Alamos <jialamos@uc.cl>
* @author Jose Ignacio Alamos <jialamos@uc.cl>
* @author Baptiste Clenet <bapclenet@gmail.com>
*/
#ifndef OT_H
@ -34,18 +35,55 @@ extern "C" {
#include "thread.h"
#include "openthread/types.h"
#define OPENTHREAD_XTIMER_MSG_TYPE_EVENT (0x2235) /**< xtimer message receiver event*/
#define OPENTHREAD_NETDEV_MSG_TYPE_EVENT (0x2236) /**< message received from driver */
#define OPENTHREAD_SERIAL_MSG_TYPE_EVENT (0x2237) /**< event indicating a serial (UART) message was sent to OpenThread */
#define OPENTHREAD_MSG_TYPE_RECV (0x2238) /**< event for frame reception */
#define OPENTHREAD_JOB_MSG_TYPE_EVENT (0x2240) /**< event indicating an OT_JOB message */
/**
* @name Openthread message types
* @{
*/
/** @brief xtimer message receiver event */
#define OPENTHREAD_XTIMER_MSG_TYPE_EVENT (0x2235)
/** @brief message received from driver */
#define OPENTHREAD_NETDEV_MSG_TYPE_EVENT (0x2236)
/** @brief event indicating a serial (UART) message was sent to OpenThread */
#define OPENTHREAD_SERIAL_MSG_TYPE_EVENT (0x2237)
/** @brief event for frame reception */
#define OPENTHREAD_MSG_TYPE_RECV (0x2238)
/** @brief event indicating an OT_JOB message */
#define OPENTHREAD_JOB_MSG_TYPE_EVENT (0x2240)
/** @} */
/**
* @name Openthread constants
* @{
*/
/** @brief number of serial reception buffer */
#define OPENTHREAD_NUMBER_OF_SERIAL_BUFFER (1U)
/** @brief sizeof in bytes the two first members of she serial structure */
#define OPENTHREAD_SIZEOF_LENGTH_AND_FREEBUFF (4U)
/** @brief sizeof the serial buffer */
#define OPENTHREAD_SERIAL_BUFFER_SIZE OPENTHREAD_SIZEOF_LENGTH_AND_FREEBUFF + 100
/** @brief sizeof the spinel payload data */
#define OPENTHREAD_SERIAL_BUFFER__PAYLOAD_SIZE OPENTHREAD_SERIAL_BUFFER_SIZE - OPENTHREAD_SIZEOF_LENGTH_AND_FREEBUFF
/** @brief error when no more buffer available */
#define OPENTHREAD_ERROR_NO_EMPTY_SERIAL_BUFFER -1
/** @brief serial buffer ready to use */
#define OPENTHREAD_SERIAL_BUFFER_STATUS_FREE (0x0001)
/** @brief serial buffer ready for processsing */
#define OPENTHREAD_SERIAL_BUFFER_STATUS_READY_TO_PROCESS (0x0002)
/** @brief serial buffer payload full */
#define OPENTHREAD_SERIAL_BUFFER_STATUS_FULL (0x0004)
/** @brief Max length for IEEE802154 frame */
#define IEEE802154_MAX_LENGTH (127U)
/** @brief Max length for a netdev buffer */
#define OPENTHREAD_NETDEV_BUFLEN (IEEE802154_MAX_LENGTH)
/** @} */
/**
* @brief Struct containing a serial message
*/
typedef struct {
void *buf; /**< buffer containing the message */
size_t len; /**< length of the message */
uint16_t length; /**< length of the message */
uint16_t serial_buffer_status; /**< status of the buffer */
uint8_t buf[OPENTHREAD_SERIAL_BUFFER__PAYLOAD_SIZE]; /**< buffer containing the message */
} serial_msg_t;
/**
@ -115,11 +153,6 @@ kernel_pid_t openthread_get_pid(void);
*/
void ot_random_init(void);
/**
* @brief Run OpenThread UART simulator (stdio)
*/
void openthread_uart_run(void);
/**
* @brief Execute OpenThread command. Call this function only in OpenThread thread
*

View File

@ -0,0 +1,51 @@
/*
* Copyright (C) Baptiste Clenet
*
* 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
* @file
* @brief Implementation of OpenThread platform config
*
* @author Baptiste Clenet <bapclenet@gmail.com>
* @}
*/
#ifndef PLATFORM_CONFIG_H
#define PLATFORM_CONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* @def OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS
*
* The number of message buffers in buffer pool
*/
#if OPENTHREAD_MTD
#define OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS (20U)
#else
#define OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS (10U)
#endif
/**
* @def OPENTHREAD_CONFIG_LOG_LEVEL
*
* Set OpenThread log level
*
* @see https://openthread.io/releases/thread-reference-20170716/group/plat-logging
*/
#define OPENTHREAD_CONFIG_LOG_LEVEL OT_LOG_LEVEL_NONE
#ifdef __cplusplus
}
#endif
#endif /* PLATFORM_CONFIG_H */

Binary file not shown.

View File

@ -1,43 +0,0 @@
APPLICATION = openthread
# If no BOARD is found in the environment, use this default:
BOARD ?= samr21-xpro
BOARD_WHITELIST := samr21-xpro iotlab-m3 fox iotlab-a8-m3
# This has to be the absolute path to the RIOT base directory:
RIOTBASE ?= $(CURDIR)/../..
# Change this to 0 show compiler invocation lines by default:
QUIET ?= 1
USEPKG += openthread
USEMODULE += openthread_contrib
USEMODULE += libmbedcrypto
USEMODULE += libopenthread
USEMODULE += libopenthread-cli
USEMODULE += xtimer
ifneq (,$(filter samr21-xpro,$(BOARD)))
DRIVER := at86rf233
endif
ifneq (,$(filter iotlab-m3 fox iotlab-a8-m3,$(BOARD)))
DRIVER := at86rf231
endif
USEMODULE += $(DRIVER)
USEMODULE += random
USEMODULE += shell
USEMODULE += shell_commands
USEMODULE += ps
USEMODULE += ipv6_addr
#required for C++ compiling
CXXEXFLAGS += -fno-rtti
USEMODULE += cpp11-compat
#Define PANID and CHANNEL used by default
#CFLAGS += -DOPENTHREAD_PANID=0xbeef -DOPENTHREAD_CHANNEL=11
include $(RIOTBASE)/Makefile.include

View File

@ -1,36 +0,0 @@
## OpenThread on RIOT
This test demonstrates the [OpenThread](https://github.com/openthread/openthread) stack running on RIOT. When flashed,
it will initialize the OpenThread Command Line Interface for interacting with the stack.
## Quick usage
To test OpenThread on RIOT, you can do the following:
1. Flash nodes with `make BOARD=<target> clean all flash`
2. Write `panid 0x1234`, `ifconfig up` then `thread start` on one node.
3. Check the state of the node with `state`. In the beggining should be `detached`, but after some seconds it should
become `leader`
4. Write `panid 0x1234`, `ifconfig up` then `thread start` on another node.
The second node should become `child` or `router` if there's a leader.
5. Get the mesh IP address of a node with `ipaddr`.
```
ipaddr
fdde:ad00:beef::ff:fe00:8000
fe80::ff:fe00:8000
fdde:ad00:beef:0:946a:c722:a5d9:8481
fe80::3984:f4eb:d182:5dae
```
Addresses starting with `fd` are mesh-local, and addresses starting with `fe80` are link-local.
Mesh-local address types that contain `ff:fe00` are classified as Router Locator (RLOC). Mesh-local address types
that don't contain `ff:fe00` are Endpoint Identifies (EID).
6. Ping from another node to a mesh-local address with `ping fdde:ad00:beef:0:946a:c722:a5d9:8481`.
7. You can try IEEE802.15.4 scan with `scan` command
8. You can also check other commands with `help`
9. Enjoy!
## Note
See the [OpenThread CLI Reference](https://github.com/openthread/openthread/blob/master/src/cli/README.md) for more information about OpenThread CLI commands