Skip to content
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
5 changes: 0 additions & 5 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -653,11 +653,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
Expand Down
52 changes: 52 additions & 0 deletions examples/openthread/Makefile
Original file line number Diff line number Diff line change
@@ -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
70 changes: 70 additions & 0 deletions examples/openthread/README.md
Original file line number Diff line number Diff line change
@@ -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).
14 changes: 5 additions & 9 deletions tests/openthread/main.c → examples/openthread/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not keep the openthread shell ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the OpenThread shell. The flow is OpenThread Core <-> Openthread CLI <-> UART

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes but here it's removed, so how can the OT shell be used ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I see what you mean. Now there's no "openthread_uart_run" simulator. It directly handles UART at interrupt level in the file platform_uart.c

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, got it now !

return 0;
}
34 changes: 23 additions & 11 deletions pkg/openthread/Makefile
Original file line number Diff line number Diff line change
@@ -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 \
Expand All @@ -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
10 changes: 10 additions & 0 deletions pkg/openthread/Makefile.dep
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions pkg/openthread/Makefile.include
Original file line number Diff line number Diff line change
@@ -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
Expand Down
78 changes: 36 additions & 42 deletions pkg/openthread/contrib/netdev/openthread_netdev.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* @brief Netdev adoption for OpenThread
*
* @author Jose Ignacio Alamos <jialamos@uc.cl>
* @author Baptiste Clenet <bapclenet@gmail.com>
* @}
*/

Expand All @@ -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"
Expand All @@ -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;

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

Expand Down
Loading