[platforms] new platform Qorvo GP712. (#1942)

This commit is contained in:
erja-gp
2017-07-11 18:10:00 +02:00
committed by Jonathan Hui
parent 129c419107
commit 3078359e38
25 changed files with 2683 additions and 3 deletions
+11 -3
View File
@@ -1084,11 +1084,11 @@ AC_DEFINE_UNQUOTED([OPENTHREAD_ENABLE_BORDER_ROUTER],[${OPENTHREAD_ENABLE_BORDER
AC_ARG_WITH(examples,
[AS_HELP_STRING([--with-examples=TARGET],
[Specify the examples from one of: none, posix, cc2538, cc2650, da15000, efr32, emsk, kw41z, nrf52840 @<:@default=none@:>@.])],
[Specify the examples from one of: none, posix, cc2538, cc2650, da15000, efr32, emsk, gp712, kw41z, nrf52840 @<:@default=none@:>@.])],
[
case "${with_examples}" in
none|posix|cc2538|cc2650|da15000|efr32|emsk|kw41z|nrf52840)
none|posix|cc2538|cc2650|da15000|efr32|emsk|gp712|kw41z|nrf52840)
;;
*)
AC_MSG_ERROR([Invalid value ${with_examples} for --with-examples])
@@ -1131,6 +1131,11 @@ case ${with_examples} in
AC_DEFINE_UNQUOTED([OPENTHREAD_EXAMPLES_EMSK],[${OPENTHREAD_EXAMPLES_EMSK}],[Define to 1 if you want to use emsk examples])
;;
gp712)
OPENTHREAD_EXAMPLES_GP712=1
AC_DEFINE_UNQUOTED([OPENTHREAD_EXAMPLES_GP712],[${OPENTHREAD_EXAMPLES_GP712}],[Define to 1 if you want to use gp712 examples])
;;
kw41z)
OPENTHREAD_EXAMPLES_KW41Z=1
AC_DEFINE_UNQUOTED([OPENTHREAD_EXAMPLES_KW41Z],[${OPENTHREAD_EXAMPLES_KW41Z}],[Define to 1 if you want to use kw41z examples])
@@ -1140,7 +1145,6 @@ case ${with_examples} in
OPENTHREAD_EXAMPLES_NRF52840=1
AC_DEFINE_UNQUOTED([OPENTHREAD_EXAMPLES_NRF52840],[${OPENTHREAD_EXAMPLES_NRF52840}],[Define to 1 if you want to use nrf52840 examples])
;;
esac
AC_MSG_CHECKING([whether to enable examples])
@@ -1168,6 +1172,9 @@ AM_CONDITIONAL([OPENTHREAD_EXAMPLES_EFR32], [test "${OPENTHREAD_EXAMPLES}" = "ef
AC_SUBST(OPENTHREAD_EXAMPLES_EMSK)
AM_CONDITIONAL([OPENTHREAD_EXAMPLES_EMSK], [test "${OPENTHREAD_EXAMPLES}" = "emsk"])
AC_SUBST(OPENTHREAD_EXAMPLES_GP712)
AM_CONDITIONAL([OPENTHREAD_EXAMPLES_GP712], [test "${OPENTHREAD_EXAMPLES}" = "gp712"])
AC_SUBST(OPENTHREAD_EXAMPLES_KW41Z)
AM_CONDITIONAL([OPENTHREAD_EXAMPLES_KW41Z], [test "${OPENTHREAD_EXAMPLES}" = "kw41z"])
@@ -1335,6 +1342,7 @@ examples/platforms/cc2650/Makefile
examples/platforms/da15000/Makefile
examples/platforms/efr32/Makefile
examples/platforms/emsk/Makefile
examples/platforms/gp712/Makefile
examples/platforms/kw41z/Makefile
examples/platforms/nrf52840/Makefile
examples/platforms/posix/Makefile
+271
View File
@@ -0,0 +1,271 @@
#
# Copyright (c) 2017, The OpenThread Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
.NOTPARALLEL:
TARGET = arm-bcm2708hardfp-linux-gnueabi
PPREFIX = gp712
INFO = GP712
#CROSS_COMPILE = $(TARGET)-
AR = $(CROSS_COMPILE)ar
AS = $(CROSS_COMPILE)as
CPP = $(CROSS_COMPILE)cpp
CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
LD = $(CROSS_COMPILE)ld
STRIP = $(CROSS_COMPILE)strip
NM = $(CROSS_COMPILE)nm
RANLIB = $(CROSS_COMPILE)ranlib
OBJCOPY = $(CROSS_COMPILE)objcopy
BuildJobs ?= 9
configure_OPTIONS = \
--enable-cli-app=ftd \
--enable-diag \
--with-examples=$(PPREFIX) \
--with-platform-info=$(INFO) \
$(NULL)
DEFAULT_LOGGING ?= 1
include $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/common-switches.mk
ifeq ($(CLI_LOGGING),1)
configure_OPTIONS += --enable-cli-logging
endif
GP712_CONFIG_FILE_CPPFLAGS = -DOPENTHREAD_PROJECT_CORE_CONFIG_FILE='\"openthread-core-gp712-config.h\"'
GP712_CONFIG_FILE_CPPFLAGS += -I$(PWD)/examples/platforms/gp712/
COMMONCFLAGS := \
-fdata-sections \
-ffunction-sections \
-Os \
-g \
$(GP712_CONFIG_FILE_CPPFLAGS) \
-W \
-Wall \
$(NULL)
CPPFLAGS += \
$(COMMONCFLAGS) \
$(target_CPPFLAGS) \
$(NULL)
CFLAGS += \
$(COMMONCFLAGS) \
$(target_CFLAGS) \
$(NULL)
CXXFLAGS += \
$(COMMONCFLAGS) \
$(target_CXXFLAGS) \
-fno-exceptions \
-fno-rtti \
$(NULL)
LDFLAGS += \
$(COMMONCFLAGS) \
$(target_LDFLAGS) \
-Wl,--gc-sections \
-Wl,-Map=map.map \
-lrt \
-lpthread \
$(NULL)
ECHO := @echo
MAKE := make
MKDIR_P := mkdir -p
LN_S := ln -s
RM_F := rm -f
INSTALL := /usr/bin/install
INSTALLFLAGS := -p
TopSourceDir := $(dir $(shell readlink $(firstword $(MAKEFILE_LIST))))..
AbsTopSourceDir := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))..
BuildPath = build
TopBuildDir = $(BuildPath)
AbsTopBuildDir = $(PWD)/$(TopBuildDir)
ResultPath = output
TopResultDir = $(ResultPath)
AbsTopResultDir = $(PWD)/$(TopResultDir)
TargetTuple = $(PPREFIX)
ifndef BuildJobs
BuildJobs := $(shell getconf _NPROCESSORS_ONLN)
endif
JOBSFLAG := -j$(BuildJobs)
PREFIX = $(PPREFIX)
#
# configure-arch <arch>
#
# Configure OpenThread for the specified architecture.
#
# arch - The architecture to configure.
#
define configure-arch
$(ECHO) " CONFIG $(1)..."
(cd $(BuildPath)/$(1) && $(AbsTopSourceDir)/configure \
INSTALL="$(INSTALL) $(INSTALLFLAGS)" \
CPP="$(CPP)" CC="$(CC)" CXX="$(CXX)" OBJC="$(OBJC)" OBJCXX="$(OBJCXX)" AR="$(AR)" RANLIB="$(RANLIB)" NM="$(NM)" STRIP="$(STRIP)" CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" \
--prefix=/$(PREFIX) \
--host=$(TARGET) \
--target=$(TARGET) \
--exec-prefix=/$(PREFIX) \
--program-prefix=$(PREFIX)- \
$(configure_OPTIONS))
endef # configure-arch
#
# build-arch <arch>
#
# Build the OpenThread intermediate build products for the specified
# architecture.
#
# arch - The architecture to build.
#
define build-arch
$(ECHO) " BUILD $(1)"
$(MAKE) $(JOBSFLAG) -C $(BuildPath)/$(1) -w \
all
endef # build-arch
#
# stage-arch <arch>
#
# Stage (install) the OpenThread final build products for the specified
# architecture.
#
# arch - The architecture to stage.
#
define stage-arch
$(ECHO) " STAGE $(1)"
$(MAKE) $(JOBSFLAG) -C $(BuildPath)/$(1) -w \
DESTDIR=$(AbsTopResultDir) \
install
endef # stage-arch
#
# ARCH_template <arch>
#
# Define macros, targets and rules to configure, build, and stage the
# OpenThread for a single architecture.
#
# arch - The architecture to instantiate the template for.
#
define ARCH_template
CONFIGURE_TARGETS += configure-$(1)
BUILD_TARGETS += do-build-$(1)
STAGE_TARGETS += stage-$(1)
BUILD_DIRS += $(BuildPath)/$(1)
DIRECTORIES += $(BuildPath)/$(1)
configure-$(1): target_CPPFLAGS=$($(1)_target_CPPFLAGS)
configure-$(1): target_CFLAGS=$($(1)_target_CFLAGS)
configure-$(1): target_CXXFLAGS=$($(1)_target_CXXFLAGS)
configure-$(1): target_LDFLAGS=$($(1)_target_LDFLAGS)
configure-$(1): $(BuildPath)/$(1)/config.status
$(BuildPath)/$(1)/config.status: | $(BuildPath)/$(1)
$$(call configure-arch,$(1))
do-build-$(1): configure-$(1)
do-build-$(1):
+$$(call build-arch,$(1))
stage-$(1): do-build-$(1)
stage-$(1): | $(TopResultDir)
$$(call stage-arch,$(1))
$(1): stage-$(1)
endef # ARCH_template
.DEFAULT_GOAL := all
all: stage
#
# rpi_bcm2708
#
rpi_bcm2708_target_ABI = rpi_bcm2708
rpi_bcm2708_target_CPPFLAGS = -march=armv6j -fomit-frame-pointer -fno-strict-aliasing -fno-pic -ffreestanding -mfloat-abi=hard -mfpu=vfp -pipe
rpi_bcm2708_target_CFLAGS = -march=armv6j -fomit-frame-pointer -fno-strict-aliasing -fno-pic -ffreestanding -mfloat-abi=hard -mfpu=vfp -pipe
rpi_bcm2708_target_CXXFLAGS = -march=armv6j -fomit-frame-pointer -fno-strict-aliasing -fno-pic -ffreestanding -mfloat-abi=hard -mfpu=vfp -pipe
rpi_bcm2708_target_LDFLAGS = -march=armv6j -fomit-frame-pointer -fno-strict-aliasing -fno-pic -ffreestanding -mfloat-abi=hard -mfpu=vfp -pipe
# Instantiate an architecture-specific build template for each target
# architecture.
$(foreach arch,$(TargetTuple),$(eval $(call ARCH_template,$(arch))))
#
# Common / Finalization
#
configure: $(CONFIGURE_TARGETS)
build: $(BUILD_TARGETS)
stage: $(STAGE_TARGETS)
DIRECTORIES = $(TopResultDir) $(TopResultDir)/$(TargetTuple)/lib $(BUILD_DIRS)
CLEAN_DIRS = $(TopResultDir) $(BUILD_DIRS)
all: stage
$(DIRECTORIES):
$(ECHO) " MKDIR $@"
@$(MKDIR_P) "$@"
clean:
$(ECHO) " CLEAN"
@$(RM_F) -r $(CLEAN_DIRS)
help:
$(ECHO) "Simply type 'make -f $(firstword $(MAKEFILE_LIST))' to build OpenThread for the following "
$(ECHO) "architectures: "
$(ECHO) ""
$(ECHO) " $(TargetTuple)"
$(ECHO) ""
$(ECHO) "To build only a particular architecture, specify: "
$(ECHO) ""
$(ECHO) " make -f $(firstword $(MAKEFILE_LIST)) <architecture>"
$(ECHO) ""
+8
View File
@@ -123,6 +123,14 @@ LDFLAGS_COMMON += \
$(NULL)
endif # OPENTHREAD_EXAMPLES_EMSK
if OPENTHREAD_EXAMPLES_GP712
LDADD_COMMON += \
$(top_builddir)/examples/platforms/gp712/libopenthread-gp712.a \
$(top_srcdir)/third_party/Qorvo/gp712/libQorvoRPi.a \
$(NULL)
endif # OPENTHREAD_EXAMPLES_GP712
if OPENTHREAD_EXAMPLES_NRF52840
LDADD_COMMON += \
$(top_builddir)/examples/platforms/nrf52840/libopenthread-nrf52840.a \
+6
View File
@@ -36,6 +36,7 @@ DIST_SUBDIRS = \
da15000 \
efr32 \
emsk \
gp712 \
kw41z \
nrf52840 \
posix \
@@ -68,6 +69,10 @@ if OPENTHREAD_EXAMPLES_EMSK
SUBDIRS += emsk
endif
if OPENTHREAD_EXAMPLES_GP712
SUBDIRS += gp712
endif
if OPENTHREAD_EXAMPLES_KW41Z
SUBDIRS += kw41z
endif
@@ -88,6 +93,7 @@ PRETTY_SUBDIRS = \
da15000 \
efr32 \
emsk \
gp712 \
kw41z \
nrf52840 \
posix \
+73
View File
@@ -0,0 +1,73 @@
#
# Copyright (c) 2016-2017, The OpenThread Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
include $(abs_top_nlbuild_autotools_dir)/automake/pre.am
lib_LIBRARIES = libopenthread-gp712.a
libopenthread_gp712_a_CPPFLAGS = \
-I$(top_srcdir)/include \
-I$(top_srcdir)/examples/platforms \
-I$(top_srcdir)/examples/platforms/utils\
-I$(top_srcdir)/src/core \
-lrt \
-lpthread \
$(NULL)
libopenthread_gp712_settings.cpp: $(srcdir)/../utils/settings.cpp
cp $? $@
CLEANFILES = libopenthread_gp712_settings.cpp
libopenthread_gp712_a_SOURCES = \
alarm.c \
misc.c \
logging.c \
platform.c \
radio.c \
random.c \
uart-posix.c \
flash.c \
libopenthread_gp712_settings.cpp \
$(NULL)
# uart-socket.c \
#
if OPENTHREAD_ENABLE_DIAG
libopenthread_gp712_a_SOURCES += \
diag.c \
$(NULL)
endif
if OPENTHREAD_BUILD_COVERAGE
CLEANFILES += $(wildcard *.gcda *.gcno)
endif # OPENTHREAD_BUILD_COVERAGE
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
+71
View File
@@ -0,0 +1,71 @@
# OpenThread on Qorvo gp712 Example
This directory contains example platform drivers for Qorvo gp712 on RPi.
## Toolchain
This example use the GNU GCC toolchain on the Raspberry Pi.
To build on the Pi:
1) Download the repo to the Pi
2) go to the subfolder in the openthread repo: third_party/nlbuild-autotools/repo/tools/packages and enter this command:
```bash
$ sudo /bin/bash build
```
Note that you may need to install additional packages to make this build work, depending on your actual RPi OS version.
The build process will complain if additional packages are required.
## Build Examples
```bash
$ cd <path-to-openthread>
$ ./bootstrap
$ CERT_LOG=1 CLI_LOGGING=1 COMMISSIONER=1 JOINER=1 DHCP6_CLIENT=1 DHCP6_SERVER=1 BORDER_ROUTER=1 make -f examples/Makefile-gp712
```
After a successful build, the `elf` files are found in
`<path-to-openthread>/output/gp712/bin`.
Building a variant which interfaces via a tcp socket is also possible. Replace the uart-posix.c with uart-socket.c in the Makefile.am from examples/platforms/gp712/Makefile.am and rebuild. Now it should be possible to open a telnet to socket 9190 of the raspberry pi from a remote PC. This also easier testing with the official Thread Test Harness.
##
## Interact
1. Spawn the process:
```bash
$ cd <path-to-openthread>/output/gp712/bin
$ ./gp712-ot-cli-ftd
```
2. Type `help` for list of commands.
```bash
> help
help
channel
childtimeout
contextreusedelay
extaddr
extpanid
ipaddr
keysequence
leaderweight
masterkey
mode
netdataregister
networkidtimeout
networkname
panid
ping
prefix
releaserouterid
rloc16
route
routerupgradethreshold
scan
start
state
stop
whitelist
```
+78
View File
@@ -0,0 +1,78 @@
/*
* Copyright (c) 2016-2017, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file implements the OpenThread platform abstraction for the alarm.
*
*/
#include <stdbool.h>
#include <stdint.h>
#include <sys/time.h>
#include <openthread/openthread.h>
#include <openthread/platform/platform.h>
#include <openthread/platform/alarm.h>
#include <openthread/platform/diag.h>
#include "alarm_qorvo.h"
void qorvoAlarmInit(void)
{
}
uint32_t otPlatAlarmGetNow(void)
{
return qorvoAlarmGetTimeMs();
}
static void qorvoAlarmFired(void *aInstance)
{
otPlatAlarmFired((otInstance *)aInstance);
}
void otPlatAlarmStartAt(otInstance *aInstance, uint32_t t0, uint32_t dt)
{
(void)t0;
qorvoAlarmUnScheduleEventArg((qorvoAlarmCallback_t)qorvoAlarmFired, aInstance);
qorvoAlarmScheduleEventArg(dt * 1000, qorvoAlarmFired, aInstance);
}
void otPlatAlarmStop(otInstance *aInstance)
{
qorvoAlarmUnScheduleEventArg((qorvoAlarmCallback_t)qorvoAlarmFired, aInstance);
}
void qorvoAlarmUpdateTimeout(struct timeval *aTimeout)
{
(void)aTimeout;
}
void qorvoAlarmProcess(void)
{
}
+92
View File
@@ -0,0 +1,92 @@
/*
* Copyright (c) 2016-2017, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file includes the declarations of the Alarm functions from the Qorvo library.
*
*/
#ifndef ALARM_QORVO_H_
#define ALARM_QORVO_H_
#include <stdint.h>
#include <sys/time.h>
#include <unistd.h>
#include <openthread/types.h>
typedef void (*qorvoAlarmCallback_t)( void* );
/**
* This function initializes the alarm service used by OpenThread.
*
*/
void qorvoAlarmInit(void);
/**
* This function retrieves the time remaining until the alarm fires.
*
* @param[out] aTimeval A pointer to the timeval struct.
*
*/
void qorvoAlarmUpdateTimeout(struct timeval *aTimeout);
/**
* This function performs alarm driver processing.
*
*/
void qorvoAlarmProcess(void);
/**
* This function retrieves the current time.
*
* @param[out] The current time in ms.
*
*/
uint32_t qorvoAlarmGetTimeMs(void);
/**
* This function schedules a callback after a relative amount of time.
*
* @param[in] rel_time The relative time in ms.
* @param[in] callback A callback function which will be called.
* @param[in] arg A context pointer which will be passed as an argument to the callback.
*
*/
void qorvoAlarmScheduleEventArg(uint32_t rel_time, qorvoAlarmCallback_t callback, void* arg);
/**
* This function unschedules the callback.
*
* @param[in] callback A callback function which will be removed from the list.
* @param[in] arg A context pointer which will be passed as an argument to the callback.
*
*/
bool qorvoAlarmUnScheduleEventArg(qorvoAlarmCallback_t callback, void* arg);
#endif // ALARM_QORVO_H_
+83
View File
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2016-2017, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <openthread/config.h>
#include <openthread/openthread.h>
#include <openthread/platform/alarm.h>
#include <openthread/platform/radio.h>
/**
* Diagnostics mode variables.
*
*/
static bool sDiagMode = false;
void otPlatDiagProcess(otInstance *aInstance, int argc, char *argv[], char *aOutput, size_t aOutputMaxLen)
{
// Add more plarform specific diagnostics features here.
snprintf(aOutput, aOutputMaxLen, "diag feature '%s' is not supported\r\n", argv[0]);
(void) argc;
(void) aInstance;
}
void otPlatDiagModeSet(bool aMode)
{
sDiagMode = aMode;
}
bool otPlatDiagModeGet()
{
return sDiagMode;
}
void otPlatDiagChannelSet(uint8_t aChannel)
{
(void) aChannel;
}
void otPlatDiagTxPowerSet(int8_t aTxPower)
{
(void) aTxPower;
}
void otPlatDiagRadioReceived(otInstance *aInstance, otRadioFrame *aFrame, otError aError)
{
(void) aInstance;
(void) aFrame;
(void) aError;
}
void otPlatDiagAlarmCallback(otInstance *aInstance)
{
(void) aInstance;
}
+158
View File
@@ -0,0 +1,158 @@
/*
* Copyright (c) 2016-2017, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#define _XOPEN_SOURCE 500
#include "platform_qorvo.h"
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <openthread/config.h>
#include "utils/code_utils.h"
#include "utils/flash.h"
static int sFlashFd;
uint32_t sEraseAddress;
#define FLASH_SIZE 0x40000
#define FLASH_PAGE_SIZE 0x800
#define FLASH_PAGE_NUM 128
otError utilsFlashInit(void)
{
otError error = OT_ERROR_NONE;
char fileName[20];
struct stat st;
bool create = false;
memset(&st, 0, sizeof(st));
if (stat("tmp", &st) == -1)
{
mkdir("tmp", 0777);
}
snprintf(fileName, sizeof(fileName), "tmp/node.flash");
if (access(fileName, 0))
{
create = true;
}
sFlashFd = open(fileName, O_RDWR | O_CREAT, 0666);
lseek(sFlashFd, 0, SEEK_SET);
otEXPECT_ACTION(sFlashFd >= 0, error = OT_ERROR_FAILED);
if (create)
{
for (uint16_t index = 0; index < FLASH_PAGE_NUM; index++)
{
error = utilsFlashErasePage(index * FLASH_PAGE_SIZE);
otEXPECT(error == OT_ERROR_NONE);
}
}
exit:
return error;
}
uint32_t utilsFlashGetSize(void)
{
return FLASH_SIZE;
}
otError utilsFlashErasePage(uint32_t aAddress)
{
otError error = OT_ERROR_NONE;
uint32_t address;
uint8_t dummyPage[ FLASH_SIZE ];
ssize_t r;
otEXPECT_ACTION(sFlashFd >= 0, error = OT_ERROR_FAILED);
otEXPECT_ACTION(aAddress < FLASH_SIZE, error = OT_ERROR_INVALID_ARGS);
// Get start address of the flash page that includes aAddress
address = aAddress & (~(uint32_t)(FLASH_PAGE_SIZE - 1));
// set the page to the erased state.
memset((void *)(&dummyPage[0]), 0xff, FLASH_PAGE_SIZE);
// Write the page
r = pwrite(sFlashFd, &(dummyPage[0]), FLASH_PAGE_SIZE, (off_t)address);
otEXPECT_ACTION((r) == ((FLASH_PAGE_SIZE)), error = OT_ERROR_FAILED);
exit:
return error;
}
otError utilsFlashStatusWait(uint32_t aTimeout)
{
(void)aTimeout;
return OT_ERROR_NONE;
}
uint32_t utilsFlashWrite(uint32_t aAddress, uint8_t *aData, uint32_t aSize)
{
uint32_t ret = 0;
uint32_t index = 0;
uint8_t byte;
otEXPECT(sFlashFd >= 0 && aAddress < FLASH_SIZE);
for (index = 0; index < aSize; index++)
{
ret = utilsFlashRead(aAddress + index, &byte, 1);
otEXPECT(ret == 1);
// Use bitwise AND to emulate the behavior of flash memory
byte &= aData[index];
ret = (uint32_t)pwrite(sFlashFd, &byte, 1, (off_t)(aAddress + index));
otEXPECT(ret == 1);
}
exit:
return index;
}
uint32_t utilsFlashRead(uint32_t aAddress, uint8_t *aData, uint32_t aSize)
{
uint32_t ret = 0;
otEXPECT(sFlashFd >= 0 && aAddress < FLASH_SIZE);
ret = (uint32_t)pread(sFlashFd, aData, aSize, (off_t)aAddress);
exit:
return ret;
}
+107
View File
@@ -0,0 +1,107 @@
/*
* Copyright (c) 2016-2017, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "platform_qorvo.h"
#include <ctype.h>
#include <inttypes.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#ifndef _WIN32
#include <syslog.h>
#endif
#include <openthread/platform/logging.h>
#include "utils/code_utils.h"
// Macro to append content to end of the log string.
#define LOG_PRINTF(...) \
charsWritten = snprintf(&logString[offset], sizeof(logString) - offset , __VA_ARGS__); \
otEXPECT_ACTION(charsWritten >= 0, logString[offset] = 0); \
offset += (unsigned int)charsWritten; \
otEXPECT_ACTION(offset < sizeof(logString), logString[sizeof(logString) -1 ] = 0)
int PlatOtLogLevelToSysLogLevel(otLogLevel aLogLevel)
{
int sysloglevel;
switch (aLogLevel)
{
case OT_LOG_LEVEL_NONE:
sysloglevel = LOG_ERR;
break;
case OT_LOG_LEVEL_CRIT:
sysloglevel = LOG_CRIT;
break;
case OT_LOG_LEVEL_WARN:
sysloglevel = LOG_WARNING;
break;
case OT_LOG_LEVEL_INFO:
sysloglevel = LOG_INFO;
break;
case OT_LOG_LEVEL_DEBG:
sysloglevel = LOG_DEBUG;
break;
default:
sysloglevel = LOG_ERR;
}
return sysloglevel;
}
void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...)
{
char logString[512];
unsigned int offset;
int charsWritten;
va_list args;
offset = 0;
va_start(args, aFormat);
charsWritten = vsnprintf(&logString[offset], sizeof(logString) - offset, aFormat, args);
va_end(args);
otEXPECT_ACTION(charsWritten >= 0, logString[offset] = 0);
exit:
syslog(PlatOtLogLevelToSysLogLevel(aLogLevel), "%s", logString);
(void)aLogRegion;
}
+73
View File
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2016-2017, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "platform_qorvo.h"
#include <unistd.h>
#include <stdio.h>
#include <openthread/types.h>
#include <openthread/platform/misc.h>
#include "radio_qorvo.h"
#include <stdlib.h>
extern int gArgumentsCount;
extern char **gArguments;
extern void platformUartRestore(void);
void otPlatReset(otInstance *aInstance)
{
char *argv[gArgumentsCount + 1];
for (int i = 0; i < gArgumentsCount; ++i)
{
argv[i] = gArguments[i];
}
argv[gArgumentsCount] = NULL;
qorvoRadioReset();
platformUartRestore();
execvp(argv[0], argv);
perror("reset failed");
exit(EXIT_FAILURE);
(void)aInstance;
}
otPlatResetReason otPlatGetResetReason(otInstance *aInstance)
{
(void)aInstance;
return OT_PLAT_RESET_REASON_POWER_ON;
}
void otPlatWakeHost(void)
{
// TODO: implement an operation to wake the host from sleep state.
}
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2016-2017, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file includes gp712 compile-time configuration constants for OpenThread.
*/
#ifndef OPENTHREAD_CORE_GP712_CONFIG_H_
#define OPENTHREAD_CORE_GP712_CONFIG_H_
/**
* @def OPENTHREAD_CONFIG_LEGACY_TRANSMIT_DONE
*
* Define to 1 if you want use legacy transmit done.
*
*/
#define OPENTHREAD_CONFIG_LEGACY_TRANSMIT_DONE 1
#endif // OPENTHREAD_CORE_GP712_CONFIG_H_
+93
View File
@@ -0,0 +1,93 @@
/*
* Copyright (c) 2016-2017, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* @brief
* This file includes the platform-specific initializers.
*/
#include "platform_qorvo.h"
#include "stdio.h"
#include "stdlib.h"
#include <openthread/tasklet.h>
#include <openthread/platform/uart.h>
#include "radio_qorvo.h"
#include "random_qorvo.h"
#include "uart_qorvo.h"
void platformUartInit(void);
void platformUartProcess(void);
otInstance *localInstance = NULL;
int gArgumentsCount = 0;
char **gArguments = NULL;
bool qorvoPlatGotoSleepCheck(void)
{
bool canGotoSleep = false;
if (localInstance)
{
canGotoSleep = !otTaskletsArePending(localInstance);
}
return canGotoSleep;
}
void PlatformInit(int argc, char *argv[])
{
gArgumentsCount = argc;
gArguments = argv;
qorvoPlatInit((qorvoPlatGotoSleepCheckCallback_t)qorvoPlatGotoSleepCheck);
platformUartInit();
//qorvoAlarmInit();
qorvoRandomInit();
qorvoRadioInit();
}
void PlatformProcessDrivers(otInstance *aInstance)
{
if (localInstance == NULL)
{
// local copy in case we need to perform a callback.
localInstance = aInstance;
}
qorvoPlatMainLoop(!otTaskletsArePending(aInstance));
platformUartProcess();
//qorvoRadioProcess();
//qorvoAlarmProcess();
}
+77
View File
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2017, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file includes the platform-specific initializers.
*
*/
#ifndef PLATFORM_QORVO_H_
#define PLATFORM_QORVO_H_
#include <stdint.h>
#include <openthread/types.h>
typedef void (*qorvoPlatPollFunction_t)(uint8_t);
typedef uint8_t (*qorvoPlatGotoSleepCheckCallback_t) (void);
/**
* This function registers a callback to a file descriptor.
*
* @param[in] fd The file descriptor.
* @param[in] pollFunction The callback which should be called when data is ready or needed for the file descriptor.
*
*/
void qorvoPlatRegisterPollFunction(int fd, qorvoPlatPollFunction_t pollFunction);
/**
* This function unregisters a callback for a file descriptor.
*
* @param[in] fd The file descriptor.
*
*/
void qorvoPlatUnRegisterPollFunction(int fd);
/**
* This function initializes the platform.
*
* @param[in] gotoSleepCheckCallback The callback which needs to return if sleep is allowed.
*
*/
void qorvoPlatInit(qorvoPlatGotoSleepCheckCallback_t gotoSleepCheckCallback);
/**
* This function runs the main loop of the platform once.
*
* @param[in] canGoToSleep Indicates if the platform can got to sleep.
*
*/
void qorvoPlatMainLoop(bool canGoToSleep);
#endif // PLATFORM_QORVO_H_
+312
View File
@@ -0,0 +1,312 @@
/*
* Copyright (c) 2016-2017, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file implements the OpenThread platform abstraction for radio communication.
*
*/
#include <string.h>
#include <openthread/openthread.h>
#include <openthread/platform/platform.h>
#include <openthread/platform/radio.h>
#include <openthread/platform/diag.h>
#include "utils/code_utils.h"
#include "radio_qorvo.h"
enum
{
GP712_RECEIVE_SENSITIVITY = -100, // dBm
};
enum
{
IEEE802154_MIN_LENGTH = 5,
IEEE802154_MAX_LENGTH = 127,
IEEE802154_ACK_LENGTH = 5,
IEEE802154_FRAME_TYPE_MASK = 0x7,
IEEE802154_FRAME_TYPE_ACK = 0x2,
IEEE802154_FRAME_PENDING = 1 << 4,
IEEE802154_ACK_REQUEST = 1 << 5,
IEEE802154_DSN_OFFSET = 2,
};
enum
{
QORVO_RSSI_OFFSET = 73,
QORVO_CRC_BIT_MASK = 0x80,
QORVO_LQI_BIT_MASK = 0x7f,
};
extern otRadioFrame sTransmitFrame;
static otRadioState sState;
static otInstance *pQorvoInstance;
typedef struct otCachedSettings_s
{
uint16_t panid;
} otCachedSettings_t;
static otCachedSettings_t otCachedSettings;
static uint8_t sScanstate = 0;
static int8_t sLastReceivedPower = 127;
void otPlatRadioGetIeeeEui64(otInstance *aInstance, uint8_t *aIeeeEui64)
{
(void)aInstance;
qorvoRadioGetIeeeEui64(aIeeeEui64);
}
void otPlatRadioSetPanId(otInstance *aInstance, uint16_t panid)
{
(void)aInstance;
qorvoRadioSetPanId(panid);
otCachedSettings.panid = panid;
}
void otPlatRadioSetExtendedAddress(otInstance *aInstance, uint8_t *address)
{
(void)aInstance;
qorvoRadioSetExtendedAddress(address);
}
void otPlatRadioSetShortAddress(otInstance *aInstance, uint16_t address)
{
(void)aInstance;
qorvoRadioSetShortAddress(address);
}
bool otPlatRadioIsEnabled(otInstance *aInstance)
{
(void)aInstance;
return (sState != OT_RADIO_STATE_DISABLED);
}
otError otPlatRadioEnable(otInstance *aInstance)
{
pQorvoInstance = aInstance;
memset(&otCachedSettings, 0x00, sizeof(otCachedSettings_t));
if (!otPlatRadioIsEnabled(aInstance))
{
sState = OT_RADIO_STATE_SLEEP;
}
return OT_ERROR_NONE;
}
otError otPlatRadioDisable(otInstance *aInstance)
{
(void)aInstance;
otEXPECT(otPlatRadioIsEnabled(aInstance));
if (sState == OT_RADIO_STATE_RECEIVE)
{
qorvoRadioSetRxOnWhenIdle(false);
}
sState = OT_RADIO_STATE_DISABLED;
exit:
return OT_ERROR_NONE;
}
otError otPlatRadioSleep(otInstance *aInstance)
{
(void)aInstance;
otError error = OT_ERROR_INVALID_STATE;
if (sState == OT_RADIO_STATE_RECEIVE)
{
qorvoRadioSetRxOnWhenIdle(false);
error = OT_ERROR_NONE;
sState = OT_RADIO_STATE_SLEEP;
}
return error;
}
otError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel)
{
otError error = OT_ERROR_INVALID_STATE;
pQorvoInstance = aInstance;
if ((sState != OT_RADIO_STATE_DISABLED) && (sScanstate == 0))
{
qorvoRadioSetCurrentChannel(aChannel);
error = OT_ERROR_NONE;
}
if (sState == OT_RADIO_STATE_SLEEP)
{
qorvoRadioSetRxOnWhenIdle(true);
error = OT_ERROR_NONE;
sState = OT_RADIO_STATE_RECEIVE;
}
return error;
}
otError otPlatRadioTransmit(otInstance *aInstance, otRadioFrame *aPacket)
{
otError err = OT_ERROR_NONE;
pQorvoInstance = aInstance;
otEXPECT_ACTION(sState != OT_RADIO_STATE_DISABLED, err = OT_ERROR_INVALID_STATE);
err = qorvoRadioTransmit(aPacket);
exit:
return err;
}
void cbQorvoRadioTransmitDone(otRadioFrame *aPacket, bool aFramePending, otError aError)
{
otPlatRadioTransmitDone(pQorvoInstance, aPacket, aFramePending, aError);
}
void cbQorvoRadioReceiveDone(otRadioFrame *aPacket, otError aError)
{
if (aError == OT_ERROR_NONE)
{
sLastReceivedPower = aPacket->mPower;
}
otPlatRadioReceiveDone(pQorvoInstance, aPacket, aError);
}
otRadioFrame *otPlatRadioGetTransmitBuffer(otInstance *aInstance)
{
(void)aInstance;
return &sTransmitFrame;
}
int8_t otPlatRadioGetRssi(otInstance *aInstance)
{
(void)aInstance;
return sLastReceivedPower;
}
otRadioCaps otPlatRadioGetCaps(otInstance *aInstance)
{
(void)aInstance;
return OT_RADIO_CAPS_ACK_TIMEOUT | OT_RADIO_CAPS_ENERGY_SCAN | OT_RADIO_CAPS_TRANSMIT_RETRIES;
}
bool otPlatRadioGetPromiscuous(otInstance *aInstance)
{
(void)aInstance;
return false;
}
void otPlatRadioSetPromiscuous(otInstance *aInstance, bool aEnable)
{
(void)aInstance;
(void)aEnable;
}
void otPlatRadioEnableSrcMatch(otInstance *aInstance, bool aEnable)
{
(void)aInstance;
qorvoRadioEnableSrcMatch(aEnable);
}
otError otPlatRadioAddSrcMatchShortEntry(otInstance *aInstance, const uint16_t aShortAddress)
{
(void)aInstance;
return qorvoRadioAddSrcMatchShortEntry(aShortAddress, otCachedSettings.panid);
}
otError otPlatRadioAddSrcMatchExtEntry(otInstance *aInstance, const uint8_t *aExtAddress)
{
(void)aInstance;
return qorvoRadioAddSrcMatchExtEntry(aExtAddress, otCachedSettings.panid);
}
otError otPlatRadioClearSrcMatchShortEntry(otInstance *aInstance, const uint16_t aShortAddress)
{
(void)aInstance;
return qorvoRadioClearSrcMatchShortEntry(aShortAddress, otCachedSettings.panid);
}
otError otPlatRadioClearSrcMatchExtEntry(otInstance *aInstance, const uint8_t *aExtAddress)
{
(void)aInstance;
return qorvoRadioClearSrcMatchExtEntry(aExtAddress, otCachedSettings.panid);
}
void otPlatRadioClearSrcMatchShortEntries(otInstance *aInstance)
{
(void)aInstance;
/* clear both short and extended addresses here */
qorvoRadioClearSrcMatchEntries();
}
void otPlatRadioClearSrcMatchExtEntries(otInstance *aInstance)
{
(void)aInstance;
/* not implemented */
/* assumes clearing of short and extended entries is done simultaniously by the openthread stack */
}
otError otPlatRadioEnergyScan(otInstance *aInstance, uint8_t aScanChannel, uint16_t aScanDuration)
{
(void)aInstance;
sScanstate = 1;
return qorvoRadioEnergyScan(aScanChannel, aScanDuration);
}
void cbQorvoRadioEnergyScanDone(int8_t aEnergyScanMaxRssi)
{
sScanstate = 0;
otPlatRadioEnergyScanDone(pQorvoInstance, aEnergyScanMaxRssi);
}
void otPlatRadioSetDefaultTxPower(otInstance *aInstance, int8_t aPower)
{
// TODO: Create a proper implementation for this driver.
(void)aInstance;
(void)aPower;
}
int8_t otPlatRadioGetReceiveSensitivity(otInstance *aInstance)
{
(void)aInstance;
return GP712_RECEIVE_SENSITIVITY;
}
+202
View File
@@ -0,0 +1,202 @@
/*
* Copyright (c) 2017, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file includes the declarations of the radio functions from the Qorvo library.
*
*/
#ifndef RADIO_QORVO_H_
#define RADIO_QORVO_H_
#include <stdint.h>
#include <openthread/types.h>
#include <openthread/platform/radio.h>
/**
* This function initializes the radio.
*
*/
void qorvoRadioInit(void);
/**
* This function resets the radio.
*
*/
void qorvoRadioReset(void);
/**
* This function processes event to/from the radio.
*
*/
void qorvoRadioProcess(void);
/**
* This function starts an ED scan.
*
* @param[in] aScanChannel The channel which needs to be scanned.
* @param[in] aScanDuration The amount of time in ms which needs to be scanned.
*
*/
otError qorvoRadioEnergyScan(uint8_t aScanChannel, uint16_t aScanDuration);
/**
* This function sets the current channel.
*
* @param[in] channel The channel index.
*
*/
void qorvoRadioSetCurrentChannel(uint8_t channel);
/**
* This function sets the idle behaviour of the radio.
*
* @param[in] rxOnWhenIdle If true, the radio remains on which not transmitting.
*
*/
void qorvoRadioSetRxOnWhenIdle(bool rxOnWhenIdle);
/**
* This function retrieves the MAC address of the radio.
*
* @param[out] aIeeeEui64 The MAC address of the radio.
*
*/
void qorvoRadioGetIeeeEui64(uint8_t *aIeeeEui64);
/**
* This function transmits a frame.
*
* @param[in] aPacket The frame which needs to be transmitted.
*
*/
otError qorvoRadioTransmit(otRadioFrame *aPacket);
/**
* This function sets the PanId.
*
* @param[in] panid The panId.
*
*/
void qorvoRadioSetPanId(uint16_t panid);
/**
* This function sets the short address.
*
* @param[in] address The short address.
*
*/
void qorvoRadioSetShortAddress(uint16_t address);
/**
* This function sets the extended address.
*
* @param[in] address The extended address.
*
*/
void qorvoRadioSetExtendedAddress(uint8_t *address);
/**
* This function enables source address matching for indirect transmit.
*
* @param[in] aEnable if True will enable source address matching, false will disable.
*
*/
void qorvoRadioEnableSrcMatch(bool aEnable);
/**
* This function clears all entries from the source address match list.
*
*/
void qorvoRadioClearSrcMatchEntries(void);
/**
* This function adds an short address plus panid to the source address match list.
*
* @param[in] aShortAddress The short address which should be added.
* @param[in] panid The panid.
*
*/
otError qorvoRadioAddSrcMatchShortEntry(const uint16_t aShortAddress, uint16_t panid);
/**
* This function adds an extended address plus panid to the source address match list.
*
* @param[in] aExtAddress The extended address which should be added.
* @param[in] panid The panid.
*
*/
otError qorvoRadioAddSrcMatchExtEntry(const uint8_t *aExtAddress, uint16_t panid);
/**
* This function removes an short address plus panid from the source address match list.
*
* @param[in] aShortAddress The short address which should be removed.
* @param[in] panid The panid.
*
*/
otError qorvoRadioClearSrcMatchShortEntry(const uint16_t aShortAddress, uint16_t panid);
/**
* This function removes an extended address plus panid from the source address match list.
*
* @param[in] aExtAddress The extended address which should be removed.
* @param[in] panid The panid.
*
*/
otError qorvoRadioClearSrcMatchExtEntry(const uint8_t *aExtAddress, uint16_t panid);
/**
* This callback is called when the energy scan is finished.
*
* @param[in] aEnergyScanMaxRssi The amount of energy detected during the ED scan.
*
*/
void cbQorvoRadioEnergyScanDone(int8_t aEnergyScanMaxRssi);
/**
* This callback is called after a transmission is completed (and if required an ACK is received).
*
* @param[in] aPacket The packet which was transmitted.
* @param[in] aFramePending Indicates if the FP bit was set in the ACK frame or not.
* @param[in] aError Indicates if an error occurred during transmission.
*
*/
void cbQorvoRadioTransmitDone(otRadioFrame *aPacket, bool aFramePending, otError aError);
/**
* This callback is called after a frame is received.
*
* @param[in] aPacket The packet which was received.
* @param[in] aError Any error which occurred during reception of the packet.
*
*/
void cbQorvoRadioReceiveDone(otRadioFrame *aPacket, otError aError);
#endif // RADIO_QORVO_H_
+130
View File
@@ -0,0 +1,130 @@
/*
* Copyright (c) 2016-2017, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file implements a pseudo-random number generator.
*
*/
#include <assert.h>
#include <stdio.h>
#include <openthread/types.h>
#include <openthread/platform/random.h>
#include "utils/code_utils.h"
static uint32_t sState = 1;
void qorvoRandomInit(void)
{
#if __SANITIZE_ADDRESS__ == 0
otError error;
error = otPlatRandomGetTrue((uint8_t *)&sState, sizeof(sState));
assert(error == OT_ERROR_NONE);
#else // __SANITIZE_ADDRESS__
sState = (uint32_t)time(NULL);
#endif // __SANITIZE_ADDRESS__
}
uint32_t otPlatRandomGet(void)
{
uint32_t mlcg, p, q;
uint64_t tmpstate;
tmpstate = (uint64_t)33614 * (uint64_t)sState;
q = tmpstate & 0xffffffff;
q = q >> 1;
p = tmpstate >> 32;
mlcg = p + q;
if (mlcg & 0x80000000)
{
mlcg &= 0x7fffffff;
mlcg++;
}
sState = mlcg;
return mlcg;
}
otError otPlatRandomGetTrue(uint8_t *aOutput, uint16_t aOutputLength)
{
otError error = OT_ERROR_NONE;
#if __SANITIZE_ADDRESS__ == 0
FILE *file = NULL;
size_t readLength;
otEXPECT_ACTION(aOutput && aOutputLength, error = OT_ERROR_INVALID_ARGS);
file = fopen("/dev/urandom", "rb");
otEXPECT_ACTION(file != NULL, error = OT_ERROR_FAILED);
readLength = fread(aOutput, 1, aOutputLength, file);
otEXPECT_ACTION(readLength == aOutputLength, error = OT_ERROR_FAILED);
exit:
if (file != NULL)
{
fclose(file);
}
#else // __SANITIZE_ADDRESS__
/*
* THE IMPLEMENTATION BELOW IS NOT COMPLIANT WITH THE THREAD SPECIFICATION.
*
* Address Sanitizer triggers test failures when reading random
* values from /dev/urandom. The pseudo-random number generator
* implementation below is only used to enable continuous
* integration checks with Address Sanitizer enabled.
*/
otEXPECT_ACTION(aOutput && aOutputLength, error = OT_ERROR_INVALID_ARGS);
for (uint16_t length = 0; length < aOutputLength; length++)
{
aOutput[length] = (uint8_t)otPlatRandomGet();
}
exit:
#endif // __SANITIZE_ADDRESS__
return error;
}
+57
View File
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2017, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file includes the declarations of the random functions from the Qorvo library.
*
*/
#ifndef RANDOM_QORVO_H_
#define RANDOM_QORVO_H_
#include <stdint.h>
#include <openthread/types.h>
/**
* This function initializes the random number service used by OpenThread.
*
*/
void qorvoRandomInit(void);
/**
* This function returns an array of random numbers.
*
* @param[out] aOutput Pointer to an array which will be filled with random data.
* @param[in] aOutputLength number of bytes which will be written into the array.
*
*/
void qorvoRandomGet(uint8_t *aOutput, uint8_t aOutputLength);
#endif // RANDOM_QORVO_H_
+275
View File
@@ -0,0 +1,275 @@
/*
* Copyright (c) 2016-2017, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "platform_qorvo.h"
#include "alarm_qorvo.h"
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <openthread/platform/uart.h>
#include "utils/code_utils.h"
#ifdef OPENTHREAD_TARGET_LINUX
#include <sys/prctl.h>
int posix_openpt(int oflag);
int grantpt(int fildes);
int unlockpt(int fd);
char *ptsname(int fd);
#endif // OPENTHREAD_TARGET_LINUX
static uint8_t s_receive_buffer[128];
static const uint8_t *s_write_buffer;
static uint16_t s_write_length;
static int s_in_fd;
static int s_out_fd;
static struct termios original_stdin_termios;
static struct termios original_stdout_termios;
static void restore_stdin_termios(void)
{
tcsetattr(s_in_fd, TCSAFLUSH, &original_stdin_termios);
}
static void restore_stdout_termios(void)
{
tcsetattr(s_out_fd, TCSAFLUSH, &original_stdout_termios);
}
void platformDummy(void *dummyPointer)
{
(void)dummyPointer;
}
static void cbKeyPressed(uint8_t Param)
{
(void) Param;
qorvoAlarmScheduleEventArg(0, platformDummy, (void *) &s_in_fd);
}
void platformUartRestore(void)
{
restore_stdin_termios();
restore_stdout_termios();
dup2(s_out_fd, STDOUT_FILENO);
}
void platformUartInit(void)
{
s_in_fd = dup(STDIN_FILENO);
s_out_fd = dup(STDOUT_FILENO);
dup2(STDERR_FILENO, STDOUT_FILENO);
qorvoPlatRegisterPollFunction(s_in_fd, cbKeyPressed);
qorvoPlatRegisterPollFunction(s_out_fd, cbKeyPressed);
}
otError otPlatUartEnable(void)
{
otError error = OT_ERROR_NONE;
struct termios termios;
#ifdef OPENTHREAD_TARGET_LINUX
// Ensure we terminate this process if the
// parent process dies.
prctl(PR_SET_PDEATHSIG, SIGHUP);
#endif
// We need this signal to make sure that this
// process terminates properly.
signal(SIGPIPE, SIG_DFL);
if (isatty(s_in_fd))
{
tcgetattr(s_in_fd, &original_stdin_termios);
atexit(&restore_stdin_termios);
}
if (isatty(s_out_fd))
{
tcgetattr(s_out_fd, &original_stdout_termios);
atexit(&restore_stdout_termios);
}
if (isatty(s_in_fd))
{
// get current configuration
otEXPECT_ACTION(tcgetattr(s_in_fd, &termios) == 0, perror("tcgetattr"); error = OT_ERROR_GENERIC);
// Set up the termios settings for raw mode. This turns
// off input/output processing, line processing, and character processing.
cfmakeraw(&termios);
// Set up our cflags for local use. Turn on hangup-on-close.
termios.c_cflag |= HUPCL | CREAD | CLOCAL;
// "Minimum number of characters for noncanonical read"
termios.c_cc[VMIN] = 1;
// "Timeout in deciseconds for noncanonical read"
termios.c_cc[VTIME] = 0;
// configure baud rate
otEXPECT_ACTION(cfsetispeed(&termios, B115200) == 0, perror("cfsetispeed"); error = OT_ERROR_GENERIC);
// set configuration
otEXPECT_ACTION(tcsetattr(s_in_fd, TCSANOW, &termios) == 0, perror("tcsetattr"); error = OT_ERROR_GENERIC);
}
if (isatty(s_out_fd))
{
// get current configuration
otEXPECT_ACTION(tcgetattr(s_out_fd, &termios) == 0, perror("tcgetattr"); error = OT_ERROR_GENERIC);
// Set up the termios settings for raw mode. This turns
// off input/output processing, line processing, and character processing.
cfmakeraw(&termios);
// Absolutely obliterate all output processing.
termios.c_oflag = 0;
// Set up our cflags for local use. Turn on hangup-on-close.
termios.c_cflag |= HUPCL | CREAD | CLOCAL;
// configure baud rate
otEXPECT_ACTION(cfsetospeed(&termios, B115200) == 0, perror("cfsetospeed"); error = OT_ERROR_GENERIC);
// set configuration
otEXPECT_ACTION(tcsetattr(s_out_fd, TCSANOW, &termios) == 0, perror("tcsetattr"); error = OT_ERROR_GENERIC);
}
exit:
if (error != OT_ERROR_NONE)
{
close(s_in_fd);
close(s_out_fd);
}
return error;
}
otError otPlatUartDisable(void)
{
otError error = OT_ERROR_NONE;
close(s_in_fd);
close(s_out_fd);
return error;
}
otError otPlatUartSend(const uint8_t *aBuf, uint16_t aBufLength)
{
otError error = OT_ERROR_NONE;
otEXPECT_ACTION(s_write_length == 0, error = OT_ERROR_BUSY);
s_write_buffer = aBuf;
s_write_length = aBufLength;
exit:
return error;
}
void platformUartProcess(void)
{
ssize_t rval;
const int error_flags = POLLERR | POLLNVAL | POLLHUP;
struct pollfd pollfd[] =
{
{ s_in_fd, POLLIN | error_flags, 0 },
{ s_out_fd, POLLOUT | error_flags, 0 },
};
errno = 0;
rval = poll(pollfd, sizeof(pollfd) / sizeof(*pollfd), 0);
if (rval < 0)
{
perror("poll");
exit(EXIT_FAILURE);
}
if (rval > 0)
{
if ((pollfd[0].revents & error_flags) != 0)
{
perror("s_in_fd");
exit(EXIT_FAILURE);
}
if ((pollfd[1].revents & error_flags) != 0)
{
perror("s_out_fd");
exit(EXIT_FAILURE);
}
if (pollfd[0].revents & POLLIN)
{
rval = read(s_in_fd, s_receive_buffer, sizeof(s_receive_buffer));
if (rval <= 0)
{
perror("read");
exit(EXIT_FAILURE);
}
otPlatUartReceived(s_receive_buffer, (uint16_t)rval);
}
if ((s_write_length > 0) && (pollfd[1].revents & POLLOUT))
{
rval = write(s_out_fd, s_write_buffer, s_write_length);
if (rval <= 0)
{
perror("write");
exit(EXIT_FAILURE);
}
s_write_buffer += (uint16_t)rval;
s_write_length -= (uint16_t)rval;
if (s_write_length == 0)
{
otPlatUartSendDone();
}
}
}
}
+337
View File
@@ -0,0 +1,337 @@
/*
* Copyright (c) 2016-2017, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file implements the OpenThread platform abstraction for cli over ip socket communication.
*
*/
#include "platform_qorvo.h"
#include "alarm_qorvo.h"
#include "uart_qorvo.h"
#include <assert.h>
#include <fcntl.h>
#include <poll.h>
#include <stdlib.h>
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <pthread.h>
#include <openthread/config.h>
#include <common/code_utils.hpp>
#include <openthread/platform/uart.h>
#include "utils/code_utils.h"
#define BUFFER_MAX_SIZE 255
#define SOCKET_PORT 9190
#define SOCKET_WRITE(socketInfo, buf, length) sendto(socketInfo.socketId, (const char*)buf, length, 0, &socketInfo.addr, sizeof(socketInfo.addr))
#define SOCKET_READ(socketId, buf, length) recv(socketId, buf, length, 0)
typedef struct
{
uint32_t socketId;
bool isValid;
struct sockaddr addr;
pthread_t rfReadThread;
} PlatSocket_t;
PlatSocket_t PlatSocketConnection;
int PlatSocketPipeFd [2];
int PlatServerSocketId;
void PlatSocketRxNewConn(uint8_t id);
void PlatSocketInit(void);
void PlatSocketDeInit(void);
int PlatSocketTxData(uint16_t length, uint8_t *pData, uint32_t socketId);
#define PLAT_UART_MAX_CHAR 1024
uint32_t PlatSocketId = 0;
void PlatSocketSendInput(void *buffer)
{
uint8_t len = 0;
uint8_t *buf = (uint8_t *) buffer;
len = strlen((char *)buf);
otPlatUartReceived((uint8_t *) buf, (uint16_t)len);
free(buf);
buf = 0;
len = 0;
}
void PlatSocketRx(uint16_t length, const char *buffer, uint32_t socketId)
{
uint8_t *buf = 0;
PlatSocketId = socketId;
if (length > 0)
{
buf = malloc(length + 2);
memcpy(buf, buffer, length);
buf[length] = '\n';
buf[length + 1] = 0;
qorvoAlarmScheduleEventArg(0, PlatSocketSendInput, (void *) buf);
}
}
void PlatSocketClose(uint32_t socketId)
{
(void)socketId;
}
otError otPlatUartEnable(void)
{
PlatSocketInit();
return OT_ERROR_NONE;
}
otError otPlatUartDisable(void)
{
PlatSocketDeInit();
return OT_ERROR_NONE;
}
otError otPlatUartSend(const uint8_t *aBuf, uint16_t aBufLength)
{
otError error = OT_ERROR_NONE;
char localbuf[PLAT_UART_MAX_CHAR];
memcpy(localbuf, aBuf, aBufLength);
localbuf[aBufLength] = 0;
printf("%s", localbuf);
if (PlatSocketId)
{
PlatSocketTxData(aBufLength, (uint8_t *) aBuf, PlatSocketId);
}
otPlatUartSendDone();
return error;
}
void platformUartInit(void)
{
}
void platformUartProcess(void)
{
}
int PlatSocketListenForClients()
{
//Setup server side socket
int sockfd;
struct sockaddr_in serv_addr;
uint32_t flag = 1;
int ret;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
otEXPECT_ACTION(sockfd >= 0, sockfd = -1);
// disable Nagle's algorithm to avoid long latency
setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(flag));
// allow reuse of the same address
setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&flag, sizeof(flag));
memset(&serv_addr, 0, sizeof(serv_addr));
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(SOCKET_PORT);
ret = bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
otEXPECT_ACTION(ret >= 0, close(sockfd); sockfd = -1);
ret = listen(sockfd, 10);
otEXPECT_ACTION(ret != -1, exit(1));
exit:
return sockfd;
}
void PlatSocketRxSignaled(uint8_t id)
{
(void)(id);
//Dummy callback function to flush pipe
uint8_t readChar;
//Remove trigger byte from pipe
read(PlatSocketPipeFd [0], &readChar, 1);
}
void *PlatSocketReadThread(void *pClientSocket)
{
char buffer[BUFFER_MAX_SIZE];
PlatSocket_t *clientSocket = ((PlatSocket_t *)pClientSocket);
memset(buffer, 0, BUFFER_MAX_SIZE);
while (1)
{
int readLen = SOCKET_READ(clientSocket->socketId, buffer, BUFFER_MAX_SIZE);
if (readLen < 0)
{
perror("Reading socket");
break;
}
else
{
if (readLen == 0)
{
break;
}
{
uint8_t someByte = 0x12; //No functional use only using pipe to kick main thread
PlatSocketRx(readLen, buffer, clientSocket->socketId);
write(PlatSocketPipeFd [1], &someByte, 1); //[1] = write fd
}
}
}
clientSocket->isValid = 0;
qorvoPlatUnRegisterPollFunction(clientSocket->socketId);
close(clientSocket->socketId);
PlatSocketClose(clientSocket->socketId);
return NULL;
}
void PlatSocketRxNewConn(uint8_t id)
{
//Find first non-valid client in list - add here
if (PlatSocketConnection.isValid == 0)
{
//Add new client to client list
socklen_t len;
len = sizeof(PlatSocketConnection.addr);
int retval = accept(id, (struct sockaddr *)&PlatSocketConnection.addr, (socklen_t *) &len);
if (retval >= 0)
{
int retErr;
PlatSocketConnection.socketId = retval;
retErr = pthread_create(&PlatSocketConnection.rfReadThread,
NULL,
PlatSocketReadThread,
&PlatSocketConnection);
if (retErr)
{
close(PlatSocketConnection.socketId);
}
else
{
PlatSocketConnection.isValid = 1;
}
}
}
else
{
int tempfd;
tempfd = accept(id, (struct sockaddr *)NULL, NULL);
if (tempfd >= 0)
{
close(tempfd);
}
}
}
/*****************************************************************************
* Public Function Definitions
*****************************************************************************/
void PlatSocketInit(void)
{
memset(&PlatSocketConnection, 0, sizeof(PlatSocketConnection));
// in case we are a server, setup listening for client
PlatServerSocketId = PlatSocketListenForClients();
qorvoPlatRegisterPollFunction(PlatServerSocketId, PlatSocketRxNewConn);
// hack
pipe(PlatSocketPipeFd);
qorvoPlatRegisterPollFunction(PlatSocketPipeFd [0], PlatSocketRxSignaled);
}
void platformUartRestore(void)
{
PlatSocketDeInit();
}
void PlatSocketDeInit(void)
{
qorvoPlatUnRegisterPollFunction(PlatServerSocketId);
close(PlatServerSocketId);
qorvoPlatUnRegisterPollFunction(PlatSocketPipeFd[0]);
close(PlatSocketPipeFd[0]);
close(PlatSocketPipeFd[1]);
close(PlatSocketConnection.socketId);
}
int PlatSocketTxData(uint16_t length, uint8_t *pData, uint32_t socketId)
{
int result = -1;
//All sockets
if (PlatSocketConnection.isValid)
{
if (PlatSocketConnection.socketId == socketId)
{
if (SOCKET_WRITE(PlatSocketConnection, (const char *)pData, length) < 0)
{
perror("TxSocket: Error Writing to client");
close(PlatSocketConnection.socketId);
PlatSocketConnection.isValid = 0;
}
else
{
result = 0;
}
}
}
return result;
}
+89
View File
@@ -0,0 +1,89 @@
/*
* Copyright (c) 2017, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* This file includes the declarations of the uart functions from the Qorvo library.
*
*/
#ifndef UART_QORVO_H_
#define UART_QORVO_H_
#include <stdint.h>
#include <openthread/types.h>
/**
* This function initializes the UART driver.
*
*/
void qorvoUartInit(void);
/**
* This function performs UART driver processing.
*
*/
void qorvoUartProcess(void);
/**
* This function enables the UART driver.
*
*/
void qorvoUartInit(void);
/**
* This function disables the UART driver.
*
*/
void qorvoUartDeInit(void);
/**
* Callback function which will be called when uart transmission is done.
*
*/
void cbQorvoUartTxDone(void);
/**
* Callback function which will be called when uart data is received.
*
* @param[in] aBuf A pointer to an array of received bytes.
* @param[in] aBufLength The number of bytes received from the uart.
*
*/
void qorvoUartSendInput(uint8_t* aBuf, uint16_t aBufLength);
/**
* Function which transmits data via the uart.
*
* @param[out] aBuf A pointer to an array of bytes which need to be transmitted.
* @param[in] aBufLength The number of bytes to be transmitted via the uart.
*
*/
void qorvoUartSendOutput(const uint8_t *aBuf, uint16_t aBufLength);
#endif // UART_QORVO_H_
+21
View File
@@ -0,0 +1,21 @@
Copyright (c) 2012-2016, GreenPeak Technologies
Copyright (c) 2017, Qorvo Inc
This software is owned by Qorvo Inc
and protected under applicable copyright laws.
It is delivered under the terms of the license
and is intended and supplied for use solely and
exclusively with products manufactured by
Qorvo Inc.
THIS SOFTWARE IS PROVIDED IN AN "AS IS"
CONDITION. NO WARRANTIES, WHETHER EXPRESS,
IMPLIED OR STATUTORY, INCLUDING, BUT NOT
LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
QORVO INC. SHALL NOT, IN ANY
CIRCUMSTANCES, BE LIABLE FOR SPECIAL,
INCIDENTAL OR CONSEQUENTIAL DAMAGES,
FOR ANY REASON WHATSOEVER.
+13
View File
@@ -0,0 +1,13 @@
# Qorvo
## Version
0.8.0.0
## License File
[LICENSE](LICENSE.txt)
## Description
This library contains the glue code to interface with the kernel drivers for linux based platforms containing the gp712.
Binary file not shown.