pkg/openthread: add FTD and NCP support

This commit is contained in:
Jose Alamos 2018-06-12 17:40:27 +02:00
parent 7187bbf8cf
commit 2bf6d01a87
15 changed files with 380 additions and 260 deletions

View File

@ -731,6 +731,11 @@ ifneq (,$(filter gcoap,$(USEMODULE)))
USEMODULE += sock_util USEMODULE += sock_util
endif endif
ifneq (,$(filter openthread,$(USEPKG)))
USEMODULE += openthread_contrib
USEMODULE += mbedcrypto
endif
ifneq (,$(filter luid,$(USEMODULE))) ifneq (,$(filter luid,$(USEMODULE)))
FEATURES_OPTIONAL += periph_cpuid FEATURES_OPTIONAL += periph_cpuid
endif endif

View File

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

View File

@ -1,8 +1,7 @@
OPENTHREAD_DIR = $(RIOTBASE)/pkg/openthread OPENTHREAD_DIR = $(RIOTBASE)/pkg/openthread
INCLUDES += -I$(OPENTHREAD_DIR)/include \ INCLUDES += -I$(OPENTHREAD_DIR)/include \
-I$(PKGDIRBASE)/openthread/output/include \ -I$(PKGDIRBASE)/openthread/include
-I$(PKGDIRBASE)/openthread/include/openthread \
ifneq (,$(filter openthread_contrib,$(USEMODULE))) ifneq (,$(filter openthread_contrib,$(USEMODULE)))
DIRS += $(OPENTHREAD_DIR)/contrib 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 * @brief Netdev adoption for OpenThread
* *
* @author Jose Ignacio Alamos <jialamos@uc.cl> * @author Jose Ignacio Alamos <jialamos@uc.cl>
* @author Baptiste Clenet <bapclenet@gmail.com>
* @} * @}
*/ */
@ -23,7 +24,7 @@
#include "openthread/cli.h" #include "openthread/cli.h"
#include "openthread/instance.h" #include "openthread/instance.h"
#include "openthread/ip6.h" #include "openthread/ip6.h"
#include "openthread/platform/alarm.h" #include "openthread/platform/alarm-milli.h"
#include "openthread/platform/uart.h" #include "openthread/platform/uart.h"
#include "openthread/tasklet.h" #include "openthread/tasklet.h"
#include "openthread/thread.h" #include "openthread/thread.h"
@ -39,18 +40,6 @@ static msg_t _queue[OPENTHREAD_QUEUE_LEN];
static kernel_pid_t _pid; static kernel_pid_t _pid;
static otInstance *sInstance; 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) { uint8_t ot_call_command(char* command, void *arg, void* answer) {
ot_job_t job; 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. */ /* OpenThread will call this when switching state from empty tasklet to non-empty tasklet. */
void otTaskletsSignalPending(otInstance *aInstance) { void otTaskletsSignalPending(otInstance *aInstance) {
otTaskletsProcess(aInstance); (void) aInstance;
} }
static void *_openthread_event_loop(void *arg) { static void *_openthread_event_loop(void *arg) {
@ -78,18 +67,14 @@ static void *_openthread_event_loop(void *arg) {
otPlatUartEnable(); otPlatUartEnable();
/* init OpenThread */ /* init OpenThread */
sInstance = otInstanceInit(); sInstance = otInstanceInitSingle();
msg_init_queue(_queue, OPENTHREAD_QUEUE_LEN); msg_init_queue(_queue, OPENTHREAD_QUEUE_LEN);
netdev_t *dev; netdev_t *dev;
msg_t msg, reply; msg_t msg, reply;
#if defined(MODULE_OPENTHREAD_CLI_FTD) || defined(MODULE_OPENTHREAD_CLI_MTD)
otCliUartInit(sInstance); otCliUartInit(sInstance);
#if OPENTHREAD_ENABLE_DIAG
diagInit(sInstance);
#endif
/* Init default parameters */ /* Init default parameters */
otPanId panid = OPENTHREAD_PANID; otPanId panid = OPENTHREAD_PANID;
uint8_t channel = OPENTHREAD_CHANNEL; uint8_t channel = OPENTHREAD_CHANNEL;
@ -99,31 +84,40 @@ static void *_openthread_event_loop(void *arg) {
otIp6SetEnabled(sInstance, true); otIp6SetEnabled(sInstance, true);
/* Start Thread protocol operation */ /* Start Thread protocol operation */
otThreadSetEnabled(sInstance, true); otThreadSetEnabled(sInstance, true);
#endif
#if OPENTHREAD_ENABLE_DIAG
diagInit(sInstance);
#endif
uint8_t *buf;
ot_job_t *job; ot_job_t *job;
serial_msg_t* serialBuffer;
while (1) { while (1) {
msg_receive(&msg); otTaskletsProcess(sInstance);
switch (msg.type) { if (otTaskletsArePending(sInstance) == false) {
case OPENTHREAD_XTIMER_MSG_TYPE_EVENT: msg_receive(&msg);
/* Tell OpenThread a time event was received */ switch (msg.type) {
otPlatAlarmFired(sInstance); case OPENTHREAD_XTIMER_MSG_TYPE_EVENT:
break; /* Tell OpenThread a time event was received */
case OPENTHREAD_NETDEV_MSG_TYPE_EVENT: otPlatAlarmMilliFired(sInstance);
/* Received an event from driver */ break;
dev = msg.content.ptr; case OPENTHREAD_NETDEV_MSG_TYPE_EVENT:
dev->driver->isr(dev); /* Received an event from driver */
break; dev = msg.content.ptr;
case OPENTHREAD_SERIAL_MSG_TYPE_EVENT: dev->driver->isr(dev);
/* Tell OpenThread about the reception of a CLI command */ break;
buf = msg.content.ptr; case OPENTHREAD_SERIAL_MSG_TYPE_EVENT:
otPlatUartReceived(buf, strlen((char *) buf)); /* Tell OpenThread about the reception of a CLI command */
break; serialBuffer = (serial_msg_t*)msg.content.ptr;
case OPENTHREAD_JOB_MSG_TYPE_EVENT: otPlatUartReceived((uint8_t*) serialBuffer->buf,serialBuffer->length);
job = msg.content.ptr; serialBuffer->serial_buffer_status = OPENTHREAD_SERIAL_BUFFER_STATUS_FREE;
reply.content.value = ot_exec_command(sInstance, job->command, job->arg, job->answer); break;
msg_reply(&msg, &reply); case OPENTHREAD_JOB_MSG_TYPE_EVENT:
break; 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 <assert.h>
#include "openthread/platform/alarm.h" #include "openthread/platform/alarm-milli.h"
#include "openthread/platform/uart.h" #include "openthread/platform/uart.h"
#include "ot.h" #include "ot.h"
#include "random.h" #include "random.h"
@ -41,29 +41,10 @@
static at86rf2xx_t at86rf2xx_dev; static at86rf2xx_t at86rf2xx_dev;
#endif #endif
#define OPENTHREAD_NETDEV_BUFLEN (ETHERNET_MAX_LEN)
static uint8_t rx_buf[OPENTHREAD_NETDEV_BUFLEN]; static uint8_t rx_buf[OPENTHREAD_NETDEV_BUFLEN];
static uint8_t tx_buf[OPENTHREAD_NETDEV_BUFLEN]; static uint8_t tx_buf[OPENTHREAD_NETDEV_BUFLEN];
static char ot_thread_stack[2 * THREAD_STACKSIZE_MAIN]; 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) void openthread_bootstrap(void)
{ {
/* init random */ /* init random */

View File

@ -19,7 +19,7 @@
#include <stdint.h> #include <stdint.h>
#include "msg.h" #include "msg.h"
#include "openthread/platform/alarm.h" #include "openthread/platform/alarm-milli.h"
#include "ot.h" #include "ot.h"
#include "thread.h" #include "thread.h"
#include "xtimer.h" #include "xtimer.h"
@ -38,7 +38,7 @@ static msg_t ot_alarm_msg;
* @param[in] aT0 The reference time. * @param[in] aT0 The reference time.
* @param[in] aDt The time delay in milliseconds from @p aT0. * @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)aInstance;
(void)aT0; (void)aT0;
@ -56,7 +56,7 @@ void otPlatAlarmStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt)
} }
/* OpenThread will call this to stop alarms */ /* OpenThread will call this to stop alarms */
void otPlatAlarmStop(otInstance *aInstance) void otPlatAlarmMilliStop(otInstance *aInstance)
{ {
(void)aInstance; (void)aInstance;
DEBUG("openthread: otPlatAlarmStop\n"); DEBUG("openthread: otPlatAlarmStop\n");
@ -64,7 +64,7 @@ void otPlatAlarmStop(otInstance *aInstance)
} }
/* OpenThread will call this for getting running time in millisecs */ /* 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; uint32_t now = xtimer_now_usec() / US_PER_MS;
DEBUG("openthread: otPlatAlarmGetNow: %" PRIu32 "\n", now); 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; (void)arg;
if (answer != NULL) { if (answer != NULL) {
uint8_t state = otThreadGetDeviceRole(ot_instance); otDeviceRole state = otThreadGetDeviceRole(ot_instance);
*((uint8_t *) answer) = state; *((otDeviceRole *) answer) = state;
DEBUG("state: "); DEBUG("state: ");
switch (state) { switch (state) {
case kDeviceRoleOffline: case OT_DEVICE_ROLE_DISABLED:
puts("offline");
break;
case kDeviceRoleDisabled:
puts("disabled"); puts("disabled");
break; break;
case kDeviceRoleDetached: case OT_DEVICE_ROLE_DETACHED:
puts("detached"); puts("detached");
break; break;
case kDeviceRoleChild: case OT_DEVICE_ROLE_CHILD:
puts("child"); puts("child");
break; break;
case kDeviceRoleRouter: case OT_DEVICE_ROLE_ROUTER:
puts("router"); puts("router");
break; break;
case kDeviceRoleLeader: case OT_DEVICE_ROLE_LEADER:
puts("leader"); puts("leader");
break; break;
default: default:

View File

@ -13,6 +13,7 @@
* @brief Implementation of OpenThread logging platform abstraction * @brief Implementation of OpenThread logging platform abstraction
* *
* @author Jose Ignacio Alamos <jialamos@uc.cl> * @author Jose Ignacio Alamos <jialamos@uc.cl>
* @author Baptiste Clenet <bapclenet@gmail.com>
* @} * @}
*/ */
@ -20,10 +21,9 @@
#include <inttypes.h> #include <inttypes.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h>
#include <string.h> #include <string.h>
#include <time.h>
#include "openthread/config.h"
#include "openthread/platform/logging.h" #include "openthread/platform/logging.h"
/* adapted from OpenThread posix example: /* adapted from OpenThread posix example:
@ -31,68 +31,11 @@
__attribute__((__format__ (__printf__, 3, 4))) __attribute__((__format__ (__printf__, 3, 4)))
void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...) void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...)
{ {
(void) aLogLevel;
(void) aLogRegion;
va_list args; 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); va_start(args, aFormat);
vfprintf(stderr, aFormat, args); vfprintf(stderr, aFormat, args);
fprintf(stderr, "\r"); fprintf(stderr, "\n");
va_end(args); va_end(args);
} }

View File

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

View File

@ -49,3 +49,13 @@ uint32_t otPlatRandomGet(void)
DEBUG("otPlatRandomGet: %i\n", (int) rand_val); DEBUG("otPlatRandomGet: %i\n", (int) rand_val);
return 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; (void)aInstance;
} }
ThreadError otPlatSettingsBeginChange(otInstance *aInstance) otError otPlatSettingsBeginChange(otInstance *aInstance)
{ {
(void)aInstance; (void)aInstance;
return kThreadError_None; return OT_ERROR_NONE;
} }
ThreadError otPlatSettingsCommitChange(otInstance *aInstance) otError otPlatSettingsCommitChange(otInstance *aInstance)
{ {
DEBUG("openthread: otPlatSettingsCommitChange\n"); DEBUG("openthread: otPlatSettingsCommitChange\n");
(void)aInstance; (void)aInstance;
return kThreadError_None; return OT_ERROR_NONE;
} }
ThreadError otPlatSettingsAbandonChange(otInstance *aInstance) otError otPlatSettingsAbandonChange(otInstance *aInstance)
{ {
(void)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)aInstance;
(void)aKey; (void)aKey;
@ -55,36 +55,33 @@ ThreadError otPlatSettingsGet(otInstance *aInstance, uint16_t aKey, int aIndex,
DEBUG("openthread: otPlatSettingsGet\n"); DEBUG("openthread: otPlatSettingsGet\n");
*aValueLength = 0; *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)aInstance;
(void)aKey; (void)aKey;
(void)aValue; (void)aValue;
(void)aValueLength; (void)aValueLength;
return OT_ERROR_NONE;
return kThreadError_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)aInstance;
(void)aKey; (void)aKey;
(void)aValue; (void)aValue;
(void)aValueLength; (void)aValueLength;
return OT_ERROR_NONE;
return kThreadError_None;
} }
ThreadError otPlatSettingsDelete(otInstance *aInstance, uint16_t aKey, int aIndex) otError otPlatSettingsDelete(otInstance *aInstance, uint16_t aKey, int aIndex)
{ {
(void)aInstance; (void)aInstance;
(void)aKey; (void)aKey;
(void)aIndex; (void)aIndex;
return OT_ERROR_NONE;
return kThreadError_None;
} }
void otPlatSettingsWipe(otInstance *aInstance) 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 * @brief Implementation of OpenThread UART platform abstraction
* *
* @author Jose Ignacio Alamos <jialamos@uc.cl> * @author Jose Ignacio Alamos <jialamos@uc.cl>
* @author Baptiste Clenet <bapclenet@gmail.com>
* @} * @}
*/ */
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include "uart_stdio.h"
#include "periph/uart.h" #include "periph/uart.h"
#include "openthread/types.h"
#include "openthread/platform/uart.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)*/ /* 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(UART_STDIO_DEV, UART_STDIO_BAUDRATE, (uart_rx_cb_t) uart_handler, NULL);
return OT_ERROR_NONE;
} }
/* OpenThread will call this for disabling UART */ /* OpenThread will call this for disabling UART */
ThreadError otPlatUartDisable(void) otError otPlatUartDisable(void)
{ {
return kThreadError_None; uart_poweroff(UART_STDIO_DEV);
return OT_ERROR_NONE;
} }
/* OpenThread will call this for sending data through UART */ /* 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(UART_STDIO_DEV, aBuf, aBufLength);
/* Tell OpenThread the sending of UART is done */ /* Tell OpenThread the sending of UART is done */
otPlatUartSendDone(); 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 * @file
* *
* @author José Ignacio Alamos <jialamos@uc.cl> * @author Jose Ignacio Alamos <jialamos@uc.cl>
* @author Baptiste Clenet <bapclenet@gmail.com>
*/ */
#ifndef OT_H #ifndef OT_H
@ -34,18 +35,55 @@ extern "C" {
#include "thread.h" #include "thread.h"
#include "openthread/types.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 */ * @name Openthread message types
#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 */ /** @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 * @brief Struct containing a serial message
*/ */
typedef struct { typedef struct {
void *buf; /**< buffer containing the message */ uint16_t length; /**< length of the message */
size_t len; /**< 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; } serial_msg_t;
/** /**
@ -115,11 +153,6 @@ kernel_pid_t openthread_get_pid(void);
*/ */
void ot_random_init(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 * @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 */