Skip to content
Closed
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: 5 additions & 0 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,11 @@ ifneq (,$(filter gcoap,$(USEMODULE)))
USEMODULE += gnrc_sock_udp
endif

ifneq (,$(filter openthread,$(USEPKG)))
USEMODULE += openthread_contrib
USEMODULE += mbedcrypto
endif

ifneq (,$(filter luid,$(USEMODULE)))
FEATURES_OPTIONAL += periph_cpuid
endif
Expand Down
40 changes: 31 additions & 9 deletions pkg/openthread/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
PKG_NAME=openthread
PKG_URL=https://github.com/openthread/openthread.git
PKG_VERSION=fbfd76a990b81f007957e1bd774e51bce742e53e
PKG_VERSION=976f7a4078e126d7200f128ded84cb81c8761844
PKG_BUILDDIR ?= $(BINDIRBASE)/pkg/$(BOARD)/$(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
ifneq (,$(filter openthread-ncp-ftd,$(USEMODULE)))
$(info Compile OpenThread with NCP)
OPENTHREAD_ARGS += --enable-ncp-app=ftd --with-ncp-bus=uart \
--enable-commissioner --enable-border-router
endif
OPENTHREAD_ARGS += --enable-application-coap
CONFIG_FILE = OPENTHREAD_PROJECT_CORE_CONFIG_FILE='\"platform_config.h\"'
$(info $$OPENTHREAD_ARGS is [${OPENTHREAD_ARGS}])

.PHONY: all

Expand All @@ -18,7 +30,7 @@ all: git-download
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 +39,19 @@ 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
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
ifneq (,$(filter openthread-ncp-ftd,$(USEMODULE)))
cp $(PKG_BUILDDIR)/output/lib/libopenthread-ftd.a ${BINDIR}/openthread-ftd.a
cp $(PKG_BUILDDIR)/output/lib/libopenthread-ncp-ftd.a ${BINDIR}/openthread-ncp-ftd.a
endif
sed -ie 's/BASE/_BASE/g' $(PKG_BUILDDIR)/output/include/openthread/types.h

include $(RIOTBASE)/pkg/pkg.mk
2 changes: 2 additions & 0 deletions pkg/openthread/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ OPENTHREAD_DIR = $(RIOTBASE)/pkg/openthread
INCLUDES += -I$(OPENTHREAD_DIR)/include \
-I$(OPENTHREAD_DIR)/include/openthread \
-I$(BINDIRBASE)/pkg/$(BOARD)/openthread/output/include \
-I$(BINDIRBASE)/pkg/$(BOARD)/openthread/include \
-I$(BINDIRBASE)/pkg/$(BOARD)/openthread/include/openthread \
-I$(BINDIRBASE)/pkg/$(BOARD)/openthread/include/openthread/platform \

ifneq (,$(filter openthread_contrib,$(USEMODULE)))
DIRS += $(OPENTHREAD_DIR)/contrib
Expand Down
86 changes: 44 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,13 +24,17 @@
#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"
#include "random.h"
#include "ot.h"

#ifdef MODULE_OPENTHREAD_NCP_FTD
#include "openthread/ncp.h"
#endif

#define ENABLE_DEBUG (0)
#include "debug.h"

Expand All @@ -39,18 +44,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 +60,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 +71,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 +88,44 @@ static void *_openthread_event_loop(void *arg) {
otIp6SetEnabled(sInstance, true);
/* Start Thread protocol operation */
otThreadSetEnabled(sInstance, true);
#endif

#ifdef MODULE_OPENTHREAD_NCP_FTD
otNcpInit(sInstance);
#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
21 changes: 1 addition & 20 deletions pkg/openthread/contrib/openthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 */
Expand Down
8 changes: 4 additions & 4 deletions pkg/openthread/contrib/platform_alarm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand All @@ -56,15 +56,15 @@ 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");
xtimer_remove(&ot_timer);
}

/* 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);
Expand Down
17 changes: 7 additions & 10 deletions pkg/openthread/contrib/platform_functions_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading