mirror of
https://github.com/espressif/openthread.git
synced 2026-08-26 12:11:17 +00:00
Add support for ARC EMSK (#1549)
* Add embARC EMSK BSP in third_party folder. * Add synopsys in Makefile.am for embARC BSP * Add platform implementation on ARC EMSK * Add EMSK in Makefile.am and Makefile-emsk * Add EMSK support in apps * Modify configure.ac to add ARC EMSK.
This commit is contained in:
@@ -0,0 +1,328 @@
|
||||
#
|
||||
# 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:
|
||||
|
||||
AR = arc-elf32-ar
|
||||
CCAS = arc-elf32-gcc
|
||||
CPP = arc-elf32-cpp
|
||||
CC = arc-elf32-gcc
|
||||
CXX = arc-elf32-g++
|
||||
LD = arc-elf32-gcc
|
||||
STRIP = arc-elf32-strip
|
||||
NM = arc-elf32-nm
|
||||
RANLIB = arc-elf32-ranlib
|
||||
OBJCOPY = arc-elf32-objcopy
|
||||
|
||||
BuildJobs ?= 10
|
||||
|
||||
configure_OPTIONS = \
|
||||
--enable-cli-app=all \
|
||||
--enable-ncp-app=all \
|
||||
--with-ncp-bus=uart \
|
||||
--enable-default-logging \
|
||||
--with-examples=emsk \
|
||||
--with-platform-info=EMSK \
|
||||
$(NULL)
|
||||
|
||||
ifeq ($(CERT_LOG),1)
|
||||
configure_OPTIONS += --enable-cert-log
|
||||
endif
|
||||
|
||||
ifeq ($(COMMISSIONER),1)
|
||||
configure_OPTIONS += --enable-commissioner
|
||||
endif
|
||||
|
||||
ifeq ($(JOINER),1)
|
||||
configure_OPTIONS += --enable-joiner
|
||||
endif
|
||||
|
||||
ifeq ($(DHCP6_SERVER),1)
|
||||
configure_OPTIONS += --enable-dhcp6-server
|
||||
endif
|
||||
|
||||
ifeq ($(DHCP6_CLIENT),1)
|
||||
configure_OPTIONS += --enable-dhcp6-client
|
||||
endif
|
||||
|
||||
TopSourceDir := $(dir $(shell readlink $(firstword $(MAKEFILE_LIST))))..
|
||||
AbsTopSourceDir := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))..
|
||||
|
||||
CONFIG_FILE = OPENTHREAD_PROJECT_CORE_CONFIG_FILE='\"openthread-core-emsk-config.h\"'
|
||||
CONFIG_FILE_PATH = $(AbsTopSourceDir)/examples/platforms/emsk/
|
||||
|
||||
COMMONCFLAGS := \
|
||||
-fdata-sections \
|
||||
-ffunction-sections \
|
||||
-Os \
|
||||
-g \
|
||||
-D$(CONFIG_FILE) \
|
||||
-I$(CONFIG_FILE_PATH) \
|
||||
$(NULL)
|
||||
|
||||
CPPFLAGS += \
|
||||
$(COMMONCFLAGS) \
|
||||
$(target_CPPFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
CFLAGS += \
|
||||
$(COMMONCFLAGS) \
|
||||
$(target_CFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
CXXFLAGS += \
|
||||
$(COMMONCFLAGS) \
|
||||
$(target_CXXFLAGS) \
|
||||
-fno-exceptions \
|
||||
-fno-rtti \
|
||||
$(NULL)
|
||||
|
||||
CCASFLAGS += \
|
||||
$(COMMONCCASFLAGS) \
|
||||
$(target_CCASFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
LDFLAGS += \
|
||||
$(COMMONCFLAGS) \
|
||||
$(target_LDFLAGS) \
|
||||
-nostartfiles \
|
||||
-specs=nano.specs \
|
||||
-Wl,--gc-sections \
|
||||
-Wl,-Map=map.map \
|
||||
-Wl,--defsym=_STACKSIZE=524288 \
|
||||
-Wl,--defsym=_HEAPSIZE=524288 \
|
||||
$(NULL)
|
||||
|
||||
ECHO := @echo
|
||||
MAKE := make
|
||||
MKDIR_P := mkdir -p
|
||||
LN_S := ln -s
|
||||
RM_F := rm -f
|
||||
|
||||
INSTALL := /usr/bin/install
|
||||
INSTALLFLAGS := -p
|
||||
|
||||
BuildPath = build
|
||||
TopBuildDir = $(BuildPath)
|
||||
AbsTopBuildDir = $(PWD)/$(TopBuildDir)
|
||||
|
||||
ResultPath = output
|
||||
TopResultDir = $(ResultPath)
|
||||
AbsTopResultDir = $(PWD)/$(TopResultDir)
|
||||
|
||||
TargetTuple = arc-elf32
|
||||
|
||||
ARCHS = arcem11d
|
||||
|
||||
TopTargetLibDir = $(TopResultDir)/$(TargetTuple)/lib
|
||||
|
||||
ifndef BuildJobs
|
||||
BuildJobs := $(shell getconf _NPROCESSORS_ONLN)
|
||||
endif
|
||||
JOBSFLAG := -j$(BuildJobs)
|
||||
|
||||
#
|
||||
# configure-arch <arch>
|
||||
#
|
||||
# Configure OpenThread for the specified architecture.
|
||||
#
|
||||
# arch - The architecture to configure.
|
||||
#
|
||||
define configure-arch
|
||||
$(ECHO) " CONFIG $(TargetTuple)..."
|
||||
(cd $(BuildPath)/$(TargetTuple) && $(AbsTopSourceDir)/configure \
|
||||
INSTALL="$(INSTALL) $(INSTALLFLAGS)" \
|
||||
CPP="$(CPP)" CC="$(CC)" CXX="$(CXX)" CCAS="$(CCAS)" OBJC="$(OBJC)" OBJCXX="$(OBJCXX)" AR="$(AR)" RANLIB="$(RANLIB)" NM="$(NM)" STRIP="$(STRIP)" CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" CCASFLAGS="$(CCASFLAGS)" LDFLAGS="$(LDFLAGS)" \
|
||||
--host=arc-elf32 \
|
||||
--prefix=/ \
|
||||
--exec-prefix=/$(TargetTuple) \
|
||||
$(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 $(TargetTuple)"
|
||||
$(MAKE) $(JOBSFLAG) -C $(BuildPath)/$(TargetTuple) --no-print-directory \
|
||||
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 $(TargetTuple)"
|
||||
$(MAKE) $(JOBSFLAG) -C $(BuildPath)/$(TargetTuple) --no-print-directory \
|
||||
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)/$(TargetTuple)
|
||||
DIRECTORIES += $(BuildPath)/$(TargetTuple)
|
||||
|
||||
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): target_CCASFLAGS=$($(1)_target_CCASFLAGS)
|
||||
|
||||
configure-$(1): $(BuildPath)/$(TargetTuple)/config.status
|
||||
|
||||
$(BuildPath)/$(TargetTuple)/config.status: | $(BuildPath)/$(TargetTuple)
|
||||
$$(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
|
||||
|
||||
#
|
||||
# EMSK2.3 arcem11d
|
||||
#
|
||||
|
||||
# Common options
|
||||
MKDEP_OPT = -MMD -MT $@ -MF [email protected]
|
||||
OPT_OLEVEL = -O0
|
||||
|
||||
# Include EMSK BSP folder
|
||||
ALL_INCLUDES = -I$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp \
|
||||
-I$(top_srcdir)/examples/platforms/emsk \
|
||||
-I$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/library/clib
|
||||
|
||||
# COMMON_COMPILE_OPT = -mno-sdata $(OPT_OLEVEL) \
|
||||
$(ALL_INCLUDES) $(MKDEP_OPT)
|
||||
|
||||
# Core options of arcem11d in EMSK2.3 from ARC TCF file
|
||||
COMMON_CORE_OPT_GNU = -mcpu=em4_fpuda \
|
||||
-mlittle-endian \
|
||||
-mcode-density \
|
||||
-mdiv-rem \
|
||||
-mswap \
|
||||
-mnorm \
|
||||
-mmpy-option=6 \
|
||||
-mbarrel-shifter \
|
||||
-mfpu=fpuda_all \
|
||||
--param l1-cache-size=16384 \
|
||||
--param l1-cache-line-size=32
|
||||
|
||||
CCORE_OPT_GNU += $(COMMON_CORE_OPT_GNU)
|
||||
CXXCORE_OPT_GNU += $(COMMON_CORE_OPT_GNU)
|
||||
ACORE_OPT_GNU += $(COMMON_CORE_OPT_GNU)
|
||||
LCORE_OPT_GNU += $(COMMON_CORE_OPT_GNU)
|
||||
|
||||
# C/CPP/ASM/Linker Options
|
||||
COMPILE_OPT += $(CCORE_OPT_GNU) \
|
||||
$(COMMON_COMPILE_OPT) -std=gnu99
|
||||
CXX_COMPILE_OPT += $(CXXCORE_OPT_GNU) \
|
||||
$(COMMON_COMPILE_OPT)
|
||||
ASM_OPT += $(ACORE_OPT_GNU) \
|
||||
$(COMMON_COMPILE_OPT) -x assembler-with-cpp
|
||||
LINK_OPT += $(LCORE_OPT_GNU) \
|
||||
-mno-sdata -nostartfiles --verbose
|
||||
|
||||
arcem11d_target_ABI = arcem11d
|
||||
arcem11d_target_CPPFLAGS = $(CXX_COMPILE_OPT)
|
||||
arcem11d_target_CFLAGS = $(COMPILE_OPT)
|
||||
arcem11d_target_CXXFLAGS = $(CXX_COMPILE_OPT)
|
||||
arcem11d_target_CCASFLAGS = $(ASM_OPT)
|
||||
arcem11d_target_LDFLAGS = $(LINK_OPT)
|
||||
|
||||
# Instantiate an architecture-specific build template for each target
|
||||
# architecture.
|
||||
|
||||
$(foreach arch,$(ARCHS),$(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) " $(ARCHS)"
|
||||
$(ECHO) ""
|
||||
$(ECHO) "To build only a particular architecture, specify: "
|
||||
$(ECHO) ""
|
||||
$(ECHO) " make -f $(firstword $(MAKEFILE_LIST)) <architecture>"
|
||||
$(ECHO) ""
|
||||
@@ -113,6 +113,16 @@ LDFLAGS_COMMON += \
|
||||
$(NULL)
|
||||
endif # OPENTHREAD_EXAMPLES_EFR32
|
||||
|
||||
if OPENTHREAD_EXAMPLES_EMSK
|
||||
LDADD_COMMON += \
|
||||
$(top_builddir)/examples/platforms/emsk/libopenthread-emsk.a \
|
||||
$(NULL)
|
||||
|
||||
LDFLAGS_COMMON += \
|
||||
-T $(top_srcdir)/examples/platforms/emsk/emsk.ld \
|
||||
$(NULL)
|
||||
endif # OPENTHREAD_EXAMPLES_EMSK
|
||||
|
||||
if OPENTHREAD_EXAMPLES_NRF52840
|
||||
LDADD_COMMON += \
|
||||
$(top_builddir)/examples/platforms/nrf52840/libopenthread-nrf52840.a \
|
||||
|
||||
@@ -113,6 +113,16 @@ LDFLAGS_COMMON += \
|
||||
$(NULL)
|
||||
endif # OPENTHREAD_EXAMPLES_EFR32
|
||||
|
||||
if OPENTHREAD_EXAMPLES_EMSK
|
||||
LDADD_COMMON += \
|
||||
$(top_builddir)/examples/platforms/emsk/libopenthread-emsk.a \
|
||||
$(NULL)
|
||||
|
||||
LDFLAGS_COMMON += \
|
||||
-T $(top_srcdir)/examples/platforms/emsk/emsk.ld \
|
||||
$(NULL)
|
||||
endif # OPENTHREAD_EXAMPLES_EMSK
|
||||
|
||||
if OPENTHREAD_EXAMPLES_NRF52840
|
||||
LDADD_COMMON += \
|
||||
$(top_builddir)/examples/platforms/nrf52840/libopenthread-nrf52840.a \
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#
|
||||
# Copyright (c) 2016, The OpenThread Authors.
|
||||
# Copyright (c) 2017, The OpenThread Authors.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -35,6 +35,7 @@ DIST_SUBDIRS = \
|
||||
cc2650 \
|
||||
da15000 \
|
||||
efr32 \
|
||||
emsk \
|
||||
kw41z \
|
||||
nrf52840 \
|
||||
posix \
|
||||
@@ -63,6 +64,10 @@ if OPENTHREAD_EXAMPLES_EFR32
|
||||
SUBDIRS += efr32
|
||||
endif
|
||||
|
||||
if OPENTHREAD_EXAMPLES_EMSK
|
||||
SUBDIRS += emsk
|
||||
endif
|
||||
|
||||
if OPENTHREAD_EXAMPLES_KW41Z
|
||||
SUBDIRS += kw41z
|
||||
endif
|
||||
@@ -82,6 +87,7 @@ PRETTY_SUBDIRS = \
|
||||
cc2650 \
|
||||
da15000 \
|
||||
efr32 \
|
||||
emsk \
|
||||
kw41z \
|
||||
nrf52840 \
|
||||
posix \
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
include $(abs_top_nlbuild_autotools_dir)/automake/pre.am
|
||||
|
||||
lib_LIBRARIES = libopenthread-emsk.a
|
||||
|
||||
# Do not enable -Wconversion for emsk
|
||||
override CFLAGS := $(filter-out -Wconversion,$(CFLAGS))
|
||||
override CXXFLAGS := $(filter-out -Wconversion,$(CXXFLAGS))
|
||||
|
||||
# Do not enable -pedantic-errors for emsk
|
||||
override CFLAGS := $(filter-out -pedantic-errors,$(CFLAGS))
|
||||
override CXXFLAGS := $(filter-out -pedantic-errors,$(CXXFLAGS))
|
||||
|
||||
# Do not enable -Werror for emsk
|
||||
override CFLAGS := $(filter-out -Werror,$(CFLAGS))
|
||||
override CXXFLAGS := $(filter-out -Werror,$(CXXFLAGS))
|
||||
|
||||
# Do not enable -Wformat for emsk
|
||||
override CFLAGS := $(filter-out -Wformat,$(CFLAGS))
|
||||
override CXXFLAGS := $(filter-out -Wformat,$(CXXFLAGS))
|
||||
|
||||
libopenthread_emsk_a_CPPFLAGS = \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/examples/platforms \
|
||||
-I$(top_srcdir)/src/core \
|
||||
-I$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp \
|
||||
-I$(top_srcdir)/examples/platforms/emsk \
|
||||
-I$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/library/clib \
|
||||
-Wno-unknown-pragmas \
|
||||
-Wno-unused-function \
|
||||
-Wno-unused-parameter \
|
||||
-Wno-unused-variable \
|
||||
-Wno-implicit-function-declaration \
|
||||
-Wno-unused-variable \
|
||||
-Wno-unused-but-set-variable \
|
||||
-Wno-type-limits \
|
||||
-Wno-sign-compare \
|
||||
-Wno-unused-label \
|
||||
$(NULL)
|
||||
|
||||
libopenthread_emsk_a_SOURCES = \
|
||||
alarm.c \
|
||||
flash.c \
|
||||
misc.c \
|
||||
platform.c \
|
||||
radio.c \
|
||||
random.c \
|
||||
uart.c \
|
||||
$(NULL)
|
||||
|
||||
# EMSK BSP DIR
|
||||
top_emsk_bspdir = @top_builddir@/third_party/synopsys/embarc_emsk_bsp
|
||||
|
||||
libopenthread_emsk_a_SOURCES += \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/arc/startup/arc_cxx_support.c \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/arc/startup/arc_startup.S \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/arc/arc_cache.c \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/arc/arc_exc_asm.S \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/arc/arc_exception.c \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/arc/arc_timer.c \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/board/emsk/common/emsk_init.c \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/board/emsk/common/emsk_timer.c \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/board/emsk/common/mux.c \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/board/emsk/gpio/dw_gpio_obj.c \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/board/emsk/gpio/emsk_gpio.c \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/board/emsk/pmrf/mrf24j40.c \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/board/emsk/pmrf/pmrf.c \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/board/emsk/spi/dw_spi_obj.c \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/board/emsk/spiflash/spiflash.c \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/board/emsk/uart/dw_uart_obj.c \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/board/board.c \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/common/xprintf/xprintf.c \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/common/console_io.c \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/device/designware/gpio/dw_gpio.c \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/device/designware/spi/dw_spi.c \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/device/designware/uart/dw_uart.c \
|
||||
$(NULL)
|
||||
|
||||
libopenthread_emsk_a_SOURCES += \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/library/clib/embARC_misc.c \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/library/clib/embARC_sbrk.c \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/library/clib/embARC_syscalls.c \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/library/clib/embARC_target.c \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/library/clib/fatfs_dirent.c \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/library/clib/malloc.c \
|
||||
@top_builddir@/third_party/synopsys/embarc_emsk_bsp/library/clib/ya_getopt.c \
|
||||
$(NULL)
|
||||
|
||||
|
||||
noinst_HEADERS = \
|
||||
platform-emsk.h \
|
||||
$(NULL)
|
||||
|
||||
noinst_HEADERS += \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/board/emsk/common/emsk_timer.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/board/emsk/common/mux.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/board/emsk/common/mux_hal.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/board/emsk/gpio/dw_gpio_obj.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/board/emsk/gpio/emsk_gpio.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/board/emsk/pmrf/mrf24j40.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/board/emsk/pmrf/pmrf.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/board/emsk/spi/dw_spi_obj.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/board/emsk/spiflash/spiflash.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/board/emsk/uart/dw_uart_obj.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/board/emsk/emsk.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/board/emsk/emsk_hardware.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/common/xprintf/xprintf.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/common/console_io.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/device/designware/gpio/dw_gpio.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/device/designware/spi/dw_spi.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/device/designware/spi/dw_spi_hal.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/device/designware/spi/dw_spi_hal_cfg.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/device/designware/uart/dw_uart.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/device/designware/uart/dw_uart_hal.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/device/device_hal/inc/dev_common.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/device/device_hal/inc/dev_gpio.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/device/device_hal/inc/dev_spi.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/device/device_hal/inc/dev_uart.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/inc/arc/arc.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/inc/arc/arc_asm_common.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/inc/arc/arc_builtin.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/inc/arc/arc_cache.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/inc/arc/arc_em.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/inc/arc/arc_exception.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/inc/arc/arc_feature_config.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/inc/arc/arc_timer.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/inc/embARC_error.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/inc/embARC_toolchain.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/arc_core_config.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/embARC_BSP_config.h \
|
||||
$(NULL)
|
||||
|
||||
noinst_HEADERS += \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/library/clib/dirent.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/library/clib/embARC_syscalls.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/library/clib/embARC_target.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/library/clib/fatfs_dirent.h \
|
||||
$(top_srcdir)/third_party/synopsys/embarc_emsk_bsp/library/clib/ya_getopt.h \
|
||||
$(NULL)
|
||||
|
||||
Dash = -
|
||||
libopenthread_emsk_a_LIBADD = \
|
||||
$(shell find $(top_builddir)/examples/platforms/utils $(Dash)type f $(Dash)name "*.o")
|
||||
|
||||
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
|
||||
@@ -0,0 +1,158 @@
|
||||
# OpenThread on EMSK Example
|
||||
|
||||
This directory contains example platform drivers for Synopsys [DesignWare® ARC® EM][arcem] Starter Kit 2.3[(EMSK2.3)][emsk23] and Digilent [Pmod RF2][pmodrf2] equipped with the Microchip [MRF24J40][mrf24j40] IEEE 802.15.4™ 2.4GHz RF transceiver.
|
||||
|
||||
[arcem]: https://www.synopsys.com/designware-ip/processor-solutions/arc-processors/arc-em-family.html
|
||||
|
||||
[emsk23]: https://www.synopsys.com/dw/ipdir.php?ds=arc_em_starter_kit
|
||||
|
||||
[pmodrf2]: https://reference.digilentinc.com/reference/pmod/pmodrf2/start
|
||||
|
||||
[mrf24j40]: http://www.microchip.com/wwwproducts/en/en027752
|
||||
|
||||
## Note
|
||||
|
||||
The EMSK platform is a configurable, FPGA-based software development platform for the ARC EM Processor Family. Please note that:
|
||||
|
||||
* The platform does not currently feature a True Random Number Generator (TRNG), which is required for certification to the Thread Specification. Users looking to certify the OpenThread implementation for their own ARC-based platforms will need to add a TRNG to their platform and modify our reference implementation based on EMSK accordingly in order to achieve certification for their platform.
|
||||
* The platform does not currently contain a on-chip EUI64, which is required for a network device. Users will need to add a unique number as EUI64 for their own ARC-based platform in `<path-to-openthread>/examples/platforms/emsk/radio.c`. It can be set manually or loaded from non-volatile memory.
|
||||
|
||||
## Toolchain
|
||||
|
||||
Download and install [GNU toolchain for ARC EM][gnu-toolchain].
|
||||
|
||||
[gnu-toolchain]: https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/tags
|
||||
|
||||
Download and install [Digilent Adept Software][digilent-adept] for the Digilent JTAG-USB cable.
|
||||
|
||||
[digilent-adept]: https://store.digilentinc.com/digilent-adept-2-download-only
|
||||
|
||||
## Building the examples
|
||||
|
||||
```bash
|
||||
$ cd <path-to-openthread>
|
||||
$ ./bootstrap
|
||||
$ make -f examples/Makefile-emsk clean
|
||||
$ make -f examples/Makefile-emsk
|
||||
```
|
||||
|
||||
After a successful build, the `elf` files can be found in
|
||||
`<path-to-openthread>/output/arc-elf32/bin`. You can convert them to `bin`
|
||||
files using `arc-elf32-objcopy`:
|
||||
```bash
|
||||
$ arc-elf32-objcopy -O binary ot-cli-ftd ot-cli-ftd.bin
|
||||
```
|
||||
|
||||
## Booting the binaries from SD card
|
||||
|
||||
embARC [embarc] is an open software platform to facilitate the development of embedded systems based on ARCv2 processors. Download embARC [embarc] to generate and flash the EMSK bootloader from source code. See the application note [Using a secondary bootloader on the EMSK][bootloader-appnote] for details.
|
||||
|
||||
[embarc]: https://embarc.org/index.html
|
||||
|
||||
[bootloader-appnote]: https://embarc.org/pdf/20150710_embARC_application_note_secondary_bootloader.pdf
|
||||
|
||||
Modify the file name `arc-elf32-ot-cli-ftd.bin` to `boot.bin`. Copy `boot.bin` to the SD card. The EMSK2.3 includes an SPI flash storage device pre-programmed with FPGA images containing different configurations of DesignWare® ARC EM cores. Set pins 1 and 4 of `SW1` DIP switch and press `FPGA configure` button to configure the ARC EM11D and secondary bootloader.
|
||||
|
||||
## Running the example
|
||||
|
||||
1. Prepare two EMSK2.3 boards and copy the `boot.bin` (CLI example) to the EMSK2.3 SD card (as shown above).
|
||||
|
||||
2. The CLI example uses UART connection. To view raw UART output, start a terminal emulator like Tera Term and PuTTY. Connect EMSK J7 to the COM port with the following serial port settings:
|
||||
- Baud rate: 115200
|
||||
- 8 data bits
|
||||
- 1 stop bit
|
||||
- No parity
|
||||
- No flow control
|
||||
|
||||
3. Open a terminal connection on the first board. The `boot.bin` in the SD card will be loaded to the EMSK after a few seconds.
|
||||
|
||||
```bash
|
||||
MRF24J40 Init started.
|
||||
MRF24J40 Init finished.
|
||||
Node No. :
|
||||
```
|
||||
|
||||
4. Set the node number manually. Input `1` and press the `Enter` key in the terminal emulator.
|
||||
|
||||
```bash
|
||||
Node No. :1
|
||||
OpenThread Init Finished
|
||||
```
|
||||
|
||||
4. Start a new Thread network.
|
||||
|
||||
```bash
|
||||
> panid 0x1234
|
||||
Done
|
||||
> ifconfig up
|
||||
Done
|
||||
> thread start
|
||||
Done
|
||||
```
|
||||
|
||||
4. After a couple of seconds the node will become a Leader of the network.
|
||||
|
||||
```bash
|
||||
> state
|
||||
Leader
|
||||
```
|
||||
|
||||
5. Open a terminal connection and reset the second board. After a few seconds, input `2` and press the `Enter` key in the terminal emulator.
|
||||
|
||||
```bash
|
||||
MRF24J40 Init started.
|
||||
MRF24J40 Init finished.
|
||||
Node No. :2
|
||||
OpenThread Init Finished
|
||||
```
|
||||
|
||||
6. Attach the second node to the network.
|
||||
|
||||
```bash
|
||||
> panid 0x1234
|
||||
Done
|
||||
> ifconfig up
|
||||
Done
|
||||
> thread start
|
||||
Done
|
||||
```
|
||||
|
||||
6. After a couple of seconds the second node will attach and become a Child.
|
||||
|
||||
```bash
|
||||
> state
|
||||
Child
|
||||
```
|
||||
|
||||
7. List all IPv6 addresses of the first board.
|
||||
|
||||
```bash
|
||||
> ipaddr
|
||||
fdde:ad00:beef:0:0:ff:fe00:fc00
|
||||
fdde:ad00:beef:0:0:ff:fe00:ec00
|
||||
fdde:ad00:beef:0:4f6e:7e53:67c8:f5b0
|
||||
fe80:0:0:0:c462:f165:44eb:ef9f
|
||||
```
|
||||
|
||||
8. Choose one of them and send an ICMPv6 ping from the second board.
|
||||
|
||||
```bash
|
||||
> ping fdde:ad00:beef:0:0:ff:fe00:ec00
|
||||
8 bytes from fdde:ad00:beef:0:0:ff:fe00:ec00: icmp_seq=1 hlim=64 time=30ms
|
||||
```
|
||||
|
||||
For a list of all available commands, visit [OpenThread CLI Reference README.md][CLI].
|
||||
|
||||
[CLI]: https://github.com/openthread/openthread/blob/master/src/cli/README.md
|
||||
|
||||
## Verification
|
||||
|
||||
The following hardware have been used for testin and verification:
|
||||
- ARC EM11D on EMSK2.3
|
||||
- Pmod RF2
|
||||
|
||||
The following toolchains and software have been used for testing and verification:
|
||||
- arc-2016.09-release
|
||||
- embARC 2016.05
|
||||
|
||||
The EMSK example has been verified by Synopsys with commit `064aba2`.
|
||||
Executable
+112
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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 implements the OpenThread platform abstraction for the alarm.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "openthread/platform/alarm.h"
|
||||
#include "platform-emsk.h"
|
||||
|
||||
static uint32_t sCounter = 0;
|
||||
static uint32_t expires;
|
||||
static bool sIsRunning = false;
|
||||
|
||||
void emskAlarmInit(void)
|
||||
{
|
||||
sCounter = OSP_GET_CUR_MS();
|
||||
}
|
||||
|
||||
uint32_t otPlatAlarmGetNow(void)
|
||||
{
|
||||
return (OSP_GET_CUR_MS() - sCounter);
|
||||
}
|
||||
|
||||
void otPlatAlarmStartAt(otInstance *aInstance, uint32_t t0, uint32_t dt)
|
||||
{
|
||||
(void)aInstance;
|
||||
expires = t0 + dt;
|
||||
sIsRunning = true;
|
||||
}
|
||||
|
||||
void otPlatAlarmStop(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
sIsRunning = false;
|
||||
}
|
||||
|
||||
void emskAlarmUpdateTimeout(int32_t *aTimeout)
|
||||
{
|
||||
int32_t remaining;
|
||||
|
||||
otEXPECT(aTimeout != NULL);
|
||||
|
||||
if (sIsRunning)
|
||||
{
|
||||
remaining = (int32_t)(expires - otPlatAlarmGetNow());
|
||||
|
||||
if (remaining > 0)
|
||||
{
|
||||
*aTimeout = remaining;
|
||||
}
|
||||
else
|
||||
{
|
||||
*aTimeout = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*aTimeout = 10000;
|
||||
}
|
||||
|
||||
exit:
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
void emskAlarmProcess(otInstance *aInstance)
|
||||
{
|
||||
int32_t remaining;
|
||||
|
||||
if (sIsRunning)
|
||||
{
|
||||
remaining = (int32_t)(expires - otPlatAlarmGetNow());
|
||||
|
||||
if (remaining <= 0)
|
||||
{
|
||||
sIsRunning = false;
|
||||
otPlatAlarmFired(aInstance);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+128
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
SEARCH_DIR(.)
|
||||
GROUP(../../../examples/platforms/emsk/libopenthread-emsk.a libgcc.a libc.a libnosys.a)
|
||||
|
||||
MEMORY
|
||||
{
|
||||
ICCM : ORIGIN = 0x00000000, LENGTH = 0x10000
|
||||
DCCM : ORIGIN = 0x80000000, LENGTH = 0x10000
|
||||
EXT_RAM : ORIGIN = 0x10000000, LENGTH = 0x8000000
|
||||
}
|
||||
ENTRY(_start)
|
||||
SECTIONS
|
||||
{
|
||||
.init :
|
||||
{
|
||||
_f_init = .;
|
||||
KEEP (*(.init_vector))
|
||||
KEEP (*(.init_bootstrap))
|
||||
_e_init = .;
|
||||
} > EXT_RAM
|
||||
.vector : ALIGN(1024)
|
||||
{
|
||||
_f_vector = .;
|
||||
*(.vector)
|
||||
_e_vector = .;
|
||||
} > EXT_RAM
|
||||
.text : ALIGN(4)
|
||||
{
|
||||
_f_text = .;
|
||||
*(.text .text.* .gnu.linkonce.t.*)
|
||||
_e_text = .;
|
||||
} > EXT_RAM
|
||||
.rodata : ALIGN(4)
|
||||
{
|
||||
_f_rodata = .;
|
||||
. = ALIGN(4);
|
||||
__CTOR_LIST__ = .;
|
||||
LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
|
||||
KEEP(*(SORT_BY_NAME(".ctors*")))
|
||||
LONG(0)
|
||||
__CTOR_END__ = .;
|
||||
. = ALIGN(4);
|
||||
__init_array_start = .;
|
||||
KEEP(*(SORT_BY_NAME(".init_array*")))
|
||||
__init_array_end = .;
|
||||
. = ALIGN(4);
|
||||
__DTOR_LIST__ = .;
|
||||
LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)
|
||||
KEEP(*(SORT_BY_NAME(".dtors*")))
|
||||
LONG(0)
|
||||
__DTOR_END__ = .;
|
||||
*(.rodata .rodata.* .gnu.linkonce.r.*)
|
||||
_e_rodata = .;
|
||||
} > EXT_RAM
|
||||
.data : ALIGN(4)
|
||||
{
|
||||
_f_data = .;
|
||||
*(.data .data.* .gnu.linkonce.d.*)
|
||||
_f_sdata = .;
|
||||
__SDATA_BEGIN__ = .;
|
||||
*(.sdata .sdata.* .gnu.linkonce.s.*)
|
||||
_e_sdata = .;
|
||||
_e_data = .;
|
||||
} > EXT_RAM AT > EXT_RAM
|
||||
.bss (NOLOAD) : ALIGN(8)
|
||||
{
|
||||
PROVIDE (__sbss_start = .);
|
||||
PROVIDE (___sbss_start = .);
|
||||
_f_bss = .;
|
||||
_f_sbss = .;
|
||||
*(.dynsbss)
|
||||
*(.sbss .sbss.* .gnu.linkonce.sb.*)
|
||||
*(.scommon)
|
||||
_e_sbss = .;
|
||||
PROVIDE (__sbss_end = .);
|
||||
PROVIDE (___sbss_end = .);
|
||||
*(.dynbss)
|
||||
*(.bss .bss.* .gnu.linkonce.b.*)
|
||||
*(COMMON)
|
||||
_e_bss = .;
|
||||
} > EXT_RAM
|
||||
.stack (NOLOAD) :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_f_stack = .;
|
||||
. = . + 524288;
|
||||
_e_stack = .;
|
||||
} > EXT_RAM
|
||||
.heap (NOLOAD) :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
__start_heap = . ;
|
||||
_f_heap = .;
|
||||
. = . + 524288;
|
||||
_e_heap = .;
|
||||
__end_heap = . ;
|
||||
} > EXT_RAM
|
||||
_load_addr_text = LOADADDR(.text);
|
||||
_load_addr_rodata = LOADADDR(.rodata);
|
||||
_load_addr_data = LOADADDR(.data);
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* 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 implements the OpenThread platform abstraction for flash.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <openthread-config.h>
|
||||
#include "openthread/platform/alarm.h"
|
||||
#include <utils/flash.h>
|
||||
#include <utils/code_utils.h>
|
||||
#include "platform-emsk.h"
|
||||
|
||||
/**
|
||||
* EMSK HAS 128 Mbit (16 MB) SPI flash memory (Winbond W25Q128BV).
|
||||
* The Winbond W25Q128BV array is organized into 65536 programmable pages of
|
||||
* 256-byte each. Up to 256 bytes can be programmed at a time. Pages can be
|
||||
* erased in groups of 16 (4KB sector erase).
|
||||
*/
|
||||
|
||||
/**
|
||||
* EMSK SPIflash memory map with using embARC
|
||||
* FPGA image: from 0x0000 0000
|
||||
* Secondary bootloader: from 0x0078 0000
|
||||
* Available for OpenThread: from 0x00FF D000 to 0x00FF EFFF
|
||||
*/
|
||||
#define OPENTHREAD_FLASH_BASE 0x00ffd000
|
||||
#define OPENTHREAD_FLASH_SIZE 0x00002000
|
||||
|
||||
/**
|
||||
* Define SETTINGS_CONFIG_BASE_ADDRESS,
|
||||
* SETTINGS_CONFIG_PAGE_SIZE, and
|
||||
* SETTINGS_CONFIG_PAGE_NUM for EMSK
|
||||
*/
|
||||
#ifdef SETTINGS_CONFIG_BASE_ADDRESS
|
||||
#undef SETTINGS_CONFIG_BASE_ADDRESS
|
||||
#endif // SETTINGS_CONFIG_BASE_ADDRESS
|
||||
#define SETTINGS_CONFIG_BASE_ADDRESS 0x00ffe000
|
||||
|
||||
#ifdef SETTINGS_CONFIG_PAGE_SIZE
|
||||
#undef SETTINGS_CONFIG_PAGE_SIZE
|
||||
#endif // SETTINGS_CONFIG_PAGE_SIZE
|
||||
#define SETTINGS_CONFIG_PAGE_SIZE FLASH_SECTOR_SIZE
|
||||
|
||||
#ifdef SETTINGS_CONFIG_PAGE_NUM
|
||||
#undef SETTINGS_CONFIG_PAGE_NUM
|
||||
#endif // SETTINGS_CONFIG_PAGE_NUM
|
||||
#define SETTINGS_CONFIG_PAGE_NUM 1
|
||||
|
||||
ThreadError utilsFlashInit(void)
|
||||
{
|
||||
flash_init();
|
||||
return kThreadError_None;
|
||||
}
|
||||
|
||||
uint32_t utilsFlashGetSize(void)
|
||||
{
|
||||
return (uint32_t)FLASH_SECTOR_SIZE;
|
||||
}
|
||||
|
||||
ThreadError utilsFlashErasePage(uint32_t aAddress)
|
||||
{
|
||||
ThreadError error = kThreadError_None;
|
||||
int32_t status;
|
||||
|
||||
otEXPECT_ACTION((aAddress >= OPENTHREAD_FLASH_BASE) && (aAddress < (OPENTHREAD_FLASH_BASE + OPENTHREAD_FLASH_SIZE - 1)),
|
||||
error = kThreadError_InvalidArgs);
|
||||
|
||||
/* Use 2 sectors in the implementation, cannot erase the address over the boundry */
|
||||
status = flash_erase(aAddress, FLASH_SECTOR_SIZE);
|
||||
|
||||
otEXPECT_ACTION(status != -1, error = kThreadError_Failed);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
ThreadError utilsFlashStatusWait(uint32_t aTimeout)
|
||||
{
|
||||
ThreadError error = kThreadError_None;
|
||||
uint32_t start = otPlatAlarmGetNow();
|
||||
bool busy = true;
|
||||
uint32_t status = 0x01;
|
||||
|
||||
while (busy && ((otPlatAlarmGetNow() - start) < aTimeout))
|
||||
{
|
||||
status = flash_read_status();
|
||||
busy = status & 0x01;
|
||||
}
|
||||
|
||||
otEXPECT_ACTION(!busy, error = kThreadError_Busy);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
uint32_t utilsFlashWrite(uint32_t aAddress, uint8_t *aData, uint32_t aSize)
|
||||
{
|
||||
int32_t written_size = 0;
|
||||
uint32_t size = 0;
|
||||
|
||||
otEXPECT_ACTION((aAddress >= OPENTHREAD_FLASH_BASE) &&
|
||||
((aAddress + aSize) <= OPENTHREAD_FLASH_BASE + OPENTHREAD_FLASH_SIZE) &&
|
||||
(!(aAddress & 3)) && (!(aSize & 3)), ;);
|
||||
|
||||
written_size = flash_write(aAddress, aSize, aData);
|
||||
|
||||
if (written_size < 0)
|
||||
{
|
||||
size = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
size = (uint32_t)written_size;
|
||||
}
|
||||
|
||||
exit:
|
||||
return size;
|
||||
}
|
||||
|
||||
uint32_t utilsFlashRead(uint32_t aAddress, uint8_t *aData, uint32_t aSize)
|
||||
{
|
||||
int32_t read_size = 0;
|
||||
uint32_t size = 0;
|
||||
|
||||
otEXPECT_ACTION((aAddress >= OPENTHREAD_FLASH_BASE) &&
|
||||
((aAddress + aSize) <= OPENTHREAD_FLASH_BASE + OPENTHREAD_FLASH_SIZE), ;);
|
||||
|
||||
read_size = flash_read(aAddress, aSize, aData);
|
||||
|
||||
if (read_size < 0)
|
||||
{
|
||||
size = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
size = (uint32_t)read_size;
|
||||
}
|
||||
|
||||
|
||||
exit:
|
||||
return size;
|
||||
}
|
||||
Executable
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 implements the OpenThread platform abstraction for logging.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "openthread/platform/logging.h"
|
||||
|
||||
void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...)
|
||||
{
|
||||
(void)aLogLevel;
|
||||
(void)aLogRegion;
|
||||
(void)aFormat;
|
||||
}
|
||||
|
||||
Executable
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "openthread/platform/misc.h"
|
||||
#include "platform-emsk.h"
|
||||
|
||||
void otPlatReset(otInstance *aInstance)
|
||||
{
|
||||
// Default
|
||||
(void)aInstance;
|
||||
mrf24j40_hard_reset();
|
||||
}
|
||||
|
||||
otPlatResetReason otPlatGetResetReason(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
// TODO: Write me!
|
||||
return kPlatResetReason_PowerOn;
|
||||
}
|
||||
|
||||
void otPlatWakeHost(void)
|
||||
{
|
||||
// TODO: implement an operation to wake the host from sleep state.
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 EMSK compile-time configuration constants for OpenThread.
|
||||
*/
|
||||
|
||||
#ifndef OPENTHREAD_CORE_EMSK_CONFIG_H_
|
||||
#define OPENTHREAD_CORE_EMSK_CONFIG_H_
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_ENABLE_SOFTWARE_ACK_TIMEOUT
|
||||
*
|
||||
* Define to 1 if you want to enable software ACK timeout logic.
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_CONFIG_ENABLE_SOFTWARE_ACK_TIMEOUT 0
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_ENABLE_SOFTWARE_RETRANSMIT
|
||||
*
|
||||
* Define to 1 if you want to enable software retransmission logic.
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_CONFIG_ENABLE_SOFTWARE_RETRANSMIT 0
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_ENABLE_SOFTWARE_ENERGY_SCAN
|
||||
*
|
||||
* Define to 1 if you want to enable software energy scanning logic.
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_CONFIG_ENABLE_SOFTWARE_ENERGY_SCAN 0
|
||||
|
||||
#endif // OPENTHREAD_CORE_EMSK_CONFIG_H_
|
||||
Executable
+91
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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_EMSK_H_
|
||||
#define PLATFORM_EMSK_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "openthread/types.h"
|
||||
|
||||
#include "board/board.h"
|
||||
|
||||
// Global OpenThread instance structure
|
||||
extern otInstance *sInstance;
|
||||
|
||||
/**
|
||||
* This function initializes the alarm service used by OpenThread.
|
||||
*
|
||||
*/
|
||||
void emskAlarmInit(void);
|
||||
|
||||
/**
|
||||
* This function retrieves the time remaining until the alarm fires.
|
||||
*
|
||||
* @param[out] aTimeval A pointer to timer value.
|
||||
*
|
||||
*/
|
||||
void emskAlarmUpdateTimeout(int32_t *aTimeout);
|
||||
|
||||
/**
|
||||
* This function performs alarm driver processing.
|
||||
*
|
||||
*/
|
||||
void emskAlarmProcess(otInstance *aInstance);
|
||||
|
||||
/**
|
||||
* This function initializes the radio service used by OpenThread.
|
||||
*
|
||||
*/
|
||||
void emskRadioInit(void);
|
||||
|
||||
/**
|
||||
* This function performs radio driver processing.
|
||||
*
|
||||
*/
|
||||
void emskRadioProcess(otInstance *aInstance);
|
||||
|
||||
/**
|
||||
* This function initializes the random number service used by OpenThread.
|
||||
*
|
||||
*/
|
||||
void emskRandomInit(void);
|
||||
|
||||
/**
|
||||
* This function performs UART driver processing.
|
||||
*
|
||||
*/
|
||||
void emskUartProcess(void);
|
||||
|
||||
#endif // PLATFORM_EMSK_H_
|
||||
Executable
+63
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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
|
||||
* @brief
|
||||
* This file includes the platform-specific initializers.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "openthread/openthread.h"
|
||||
#include "openthread/platform/uart.h"
|
||||
#include "platform-emsk.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
|
||||
|
||||
void PlatformInit(int argc, char *argv[])
|
||||
{
|
||||
emskAlarmInit();
|
||||
emskRadioInit();
|
||||
emskRandomInit();
|
||||
otPlatUartEnable();
|
||||
|
||||
DBG("OpenThread Init Finished\r\n");
|
||||
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
}
|
||||
|
||||
void PlatformProcessDrivers(otInstance *aInstance)
|
||||
{
|
||||
// sInstance = aInstance;
|
||||
|
||||
emskUartProcess();
|
||||
emskRadioProcess(aInstance);
|
||||
emskAlarmProcess(aInstance);
|
||||
}
|
||||
@@ -0,0 +1,680 @@
|
||||
/*
|
||||
* 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 implements the OpenThread platform abstraction for radio communication.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "openthread/types.h"
|
||||
|
||||
#include <utils/code_utils.h>
|
||||
#include "openthread/platform/radio.h"
|
||||
#include "platform-emsk.h"
|
||||
|
||||
#include "device/device_hal/inc/dev_gpio.h"
|
||||
#include <string.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
|
||||
|
||||
enum
|
||||
{
|
||||
IEEE802154_MIN_LENGTH = 5,
|
||||
IEEE802154_MAX_LENGTH = 127,
|
||||
IEEE802154_ACK_LENGTH = 5,
|
||||
|
||||
IEEE802154_BROADCAST = 0xffff,
|
||||
|
||||
IEEE802154_FRAME_TYPE_ACK = 2 << 0,
|
||||
IEEE802154_FRAME_TYPE_MACCMD = 3 << 0,
|
||||
IEEE802154_FRAME_TYPE_MASK = 7 << 0,
|
||||
|
||||
IEEE802154_SECURITY_ENABLED = 1 << 3,
|
||||
IEEE802154_FRAME_PENDING = 1 << 4,
|
||||
IEEE802154_ACK_REQUEST = 1 << 5,
|
||||
IEEE802154_PANID_COMPRESSION = 1 << 6,
|
||||
|
||||
IEEE802154_DST_ADDR_NONE = 0 << 2,
|
||||
IEEE802154_DST_ADDR_SHORT = 2 << 2,
|
||||
IEEE802154_DST_ADDR_EXT = 3 << 2,
|
||||
IEEE802154_DST_ADDR_MASK = 3 << 2,
|
||||
|
||||
IEEE802154_SRC_ADDR_NONE = 0 << 6,
|
||||
IEEE802154_SRC_ADDR_SHORT = 2 << 6,
|
||||
IEEE802154_SRC_ADDR_EXT = 3 << 6,
|
||||
IEEE802154_SRC_ADDR_MASK = 3 << 6,
|
||||
|
||||
IEEE802154_DSN_OFFSET = 2,
|
||||
IEEE802154_DSTPAN_OFFSET = 3,
|
||||
IEEE802154_DSTADDR_OFFSET = 5,
|
||||
|
||||
IEEE802154_SEC_LEVEL_MASK = 7 << 0,
|
||||
|
||||
IEEE802154_KEY_ID_MODE_0 = 0 << 3,
|
||||
IEEE802154_KEY_ID_MODE_1 = 1 << 3,
|
||||
IEEE802154_KEY_ID_MODE_2 = 2 << 3,
|
||||
IEEE802154_KEY_ID_MODE_3 = 3 << 3,
|
||||
IEEE802154_KEY_ID_MODE_MASK = 3 << 3,
|
||||
|
||||
IEEE802154_MACCMD_DATA_REQ = 4
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
EMSK_RECEIVE_SENSITIVITY = -100, // dBm
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
MRF24J40_RSSI_OFFSET = 90,
|
||||
MRF24J40_RSSI_SLOPE = 5
|
||||
};
|
||||
|
||||
static void radioTransmitMessage(otInstance *aInstance);
|
||||
|
||||
static RadioPacket sTransmitFrame;
|
||||
static RadioPacket sReceiveFrame;
|
||||
static RadioPacket sAckFrame;
|
||||
|
||||
static ThreadError sTransmitError;
|
||||
static ThreadError sReceiveError;
|
||||
|
||||
static uint8_t sTransmitPsdu[IEEE802154_MAX_LENGTH];
|
||||
static uint8_t sReceivePsdu[IEEE802154_MAX_LENGTH];
|
||||
static uint8_t sAckPsdu[IEEE802154_MAX_LENGTH];
|
||||
|
||||
static PhyState sState = kStateDisabled;
|
||||
static bool sIsReceiverEnabled = false;
|
||||
|
||||
static volatile uint8_t Mrf24StatusTx = 0;
|
||||
static volatile uint8_t Mrf24StatusRx = 0;
|
||||
static volatile uint8_t Mrf24StatusSec = 0;
|
||||
|
||||
static DEV_SPI_PTR pmrf_spi_ptr;
|
||||
static DEV_GPIO_PTR pmrf_gpio_ptr;
|
||||
static void RadioIsr(void *ptr);
|
||||
|
||||
/* Variables for test */
|
||||
static uint32_t numInterruptRev = 0;
|
||||
static uint32_t numInterruptTrans = 0;
|
||||
static uint32_t numRadioProcess = 0;
|
||||
|
||||
static inline bool isSecurityEnabled(const uint8_t *frame)
|
||||
{
|
||||
return (frame[0] & IEEE802154_SECURITY_ENABLED) != 0;
|
||||
}
|
||||
|
||||
static inline bool isAckRequested(const uint8_t *frame)
|
||||
{
|
||||
return (frame[0] & IEEE802154_ACK_REQUEST) != 0;
|
||||
}
|
||||
|
||||
static inline bool isPanIdCompressed(const uint8_t *frame)
|
||||
{
|
||||
return (frame[0] & IEEE802154_PANID_COMPRESSION) != 0;
|
||||
}
|
||||
|
||||
static inline uint8_t getHeadLength(const uint8_t *frame)
|
||||
{
|
||||
uint8_t length = 0;
|
||||
/* Frame Control-2 + Sequence Number-1 */
|
||||
length += 2 + 1;
|
||||
|
||||
/* Destination PAN + Address */
|
||||
switch (frame[1] & IEEE802154_DST_ADDR_MASK)
|
||||
{
|
||||
case IEEE802154_DST_ADDR_SHORT:
|
||||
length += sizeof(otPanId) + sizeof(otShortAddress);
|
||||
break;
|
||||
|
||||
case IEEE802154_DST_ADDR_EXT:
|
||||
length += sizeof(otPanId) + sizeof(otExtAddress);
|
||||
break;
|
||||
|
||||
default:
|
||||
length = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* Source PAN + Address */
|
||||
switch (frame[1] & IEEE802154_SRC_ADDR_MASK)
|
||||
{
|
||||
case IEEE802154_SRC_ADDR_SHORT:
|
||||
if (!isPanIdCompressed(frame))
|
||||
{
|
||||
length += sizeof(otPanId);
|
||||
}
|
||||
|
||||
length += sizeof(otShortAddress);
|
||||
break;
|
||||
|
||||
case IEEE802154_SRC_ADDR_EXT:
|
||||
if (!isPanIdCompressed(frame))
|
||||
{
|
||||
length += sizeof(otPanId);
|
||||
}
|
||||
|
||||
length += sizeof(otExtAddress);
|
||||
break;
|
||||
|
||||
default:
|
||||
length = 0;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
exit:
|
||||
return length;
|
||||
}
|
||||
|
||||
void enableReceiver(void)
|
||||
{
|
||||
if (!sIsReceiverEnabled)
|
||||
{
|
||||
mrf24j40_rxfifo_flush();
|
||||
/* add code to enable receiver (wakeup) */
|
||||
sIsReceiverEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
void disableReceiver(void)
|
||||
{
|
||||
if (sIsReceiverEnabled)
|
||||
{
|
||||
mrf24j40_rxfifo_flush();
|
||||
/* add code to disable receiver (sleep) */
|
||||
sIsReceiverEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
void setChannel(uint8_t channel)
|
||||
{
|
||||
mrf24j40_set_channel((int16_t)(channel - 11));
|
||||
}
|
||||
|
||||
void otPlatRadioGetIeeeEui64(otInstance *aInstance, uint8_t *aIeeeEui64)
|
||||
{
|
||||
(void)aInstance;
|
||||
/* should set it manually or preset it in memory */
|
||||
aIeeeEui64[0] = 0x00;
|
||||
aIeeeEui64[1] = 0x50;
|
||||
aIeeeEui64[2] = 0xC2;
|
||||
aIeeeEui64[3] = 0xFF;
|
||||
aIeeeEui64[4] = 0XFE;
|
||||
aIeeeEui64[5] = 0X1D;
|
||||
aIeeeEui64[6] = 0X30;
|
||||
aIeeeEui64[7] = 0x00;
|
||||
}
|
||||
|
||||
void otPlatRadioSetPanId(otInstance *aInstance, uint16_t panid)
|
||||
{
|
||||
(void)aInstance;
|
||||
uint8_t pan[2];
|
||||
|
||||
pan[0] = (uint8_t)(panid & 0xFF);
|
||||
pan[1] = (uint8_t)(panid >> 8);
|
||||
mrf24j40_set_pan(pan);
|
||||
}
|
||||
|
||||
void otPlatRadioSetExtendedAddress(otInstance *aInstance, uint8_t *address)
|
||||
{
|
||||
(void)aInstance;
|
||||
mrf24j40_set_eui(address);
|
||||
}
|
||||
|
||||
void otPlatRadioSetShortAddress(otInstance *aInstance, uint16_t address)
|
||||
{
|
||||
(void)aInstance;
|
||||
uint8_t addr[2];
|
||||
|
||||
addr[0] = (uint8_t)(address & 0xFF);
|
||||
addr[1] = (uint8_t)(address >> 8);
|
||||
mrf24j40_set_short_addr(addr);
|
||||
}
|
||||
|
||||
void emskRadioInit(void)
|
||||
{
|
||||
DEV_GPIO_BIT_ISR isr;
|
||||
DEV_GPIO_INT_CFG int_cfg;
|
||||
|
||||
int32_t ercd;
|
||||
uint32_t temp;
|
||||
|
||||
sTransmitFrame.mLength = 0;
|
||||
sTransmitFrame.mPsdu = sTransmitPsdu;
|
||||
sReceiveFrame.mLength = 0;
|
||||
sReceiveFrame.mPsdu = sReceivePsdu;
|
||||
sAckFrame.mLength = 0;
|
||||
sAckFrame.mPsdu = sAckPsdu;
|
||||
|
||||
pmrf_spi_ptr = spi_get_dev(EMSK_PMRF_0_SPI_ID);
|
||||
ercd = pmrf_spi_ptr->spi_open(DEV_MASTER_MODE, EMSK_PMRF_0_SPIFREQ);
|
||||
|
||||
if ((ercd != E_OK) && (ercd != E_OPNED))
|
||||
{
|
||||
DBG("PmodRF2 SPI open error\r\n");
|
||||
}
|
||||
|
||||
pmrf_spi_ptr->spi_control(SPI_CMD_SET_CLK_MODE, CONV2VOID(EMSK_PMRF_0_SPICLKMODE));
|
||||
|
||||
/*MRF24J40 wakepin:output, rstpin:output, INT_PIN:input, interrupt */
|
||||
pmrf_gpio_ptr = gpio_get_dev(EMSK_PMRF_0_GPIO_ID);
|
||||
ercd = pmrf_gpio_ptr->gpio_open(MRF24J40_WAKE_PIN | MRF24J40_RST_PIN);
|
||||
|
||||
if ((ercd != E_OK) && (ercd != E_OPNED))
|
||||
{
|
||||
DBG("PmodRF2 CRTL port open error");
|
||||
}
|
||||
|
||||
if (ercd == E_OPNED)
|
||||
{
|
||||
pmrf_gpio_ptr->gpio_control(GPIO_CMD_SET_BIT_DIR_OUTPUT, (void *)(MRF24J40_WAKE_PIN | MRF24J40_RST_PIN));
|
||||
pmrf_gpio_ptr->gpio_control(GPIO_CMD_SET_BIT_DIR_INPUT, (void *)MRF24J40_INT_PIN);
|
||||
}
|
||||
|
||||
pmrf_gpio_ptr->gpio_control(GPIO_CMD_DIS_BIT_INT, (void *)MRF24J40_INT_PIN);
|
||||
|
||||
temp = MRF24J40_INT_PIN;
|
||||
int_cfg.int_bit_mask = temp;
|
||||
int_cfg.int_bit_type = GPIO_INT_BITS_EDGE_TRIG(temp);
|
||||
int_cfg.int_bit_polarity = GPIO_INT_BITS_POL_FALL_EDGE(temp);
|
||||
int_cfg.int_bit_debounce = GPIO_INT_BITS_DIS_DEBOUNCE(temp);
|
||||
pmrf_gpio_ptr->gpio_control(GPIO_CMD_SET_BIT_INT_CFG, (void *)(&int_cfg));
|
||||
|
||||
isr.int_bit_ofs = MRF24J40_INT_PIN_OFS;
|
||||
isr.int_bit_handler = RadioIsr;
|
||||
pmrf_gpio_ptr->gpio_control(GPIO_CMD_SET_BIT_ISR, (void *)(&isr));
|
||||
|
||||
/* interrupt for mrf24j40 is enabled at the end of the init process */
|
||||
DBG("MRF24J40 Init Started\r\n");
|
||||
mrf24j40_initialize();
|
||||
DBG("MRF24J40 Init Finished\r\n");
|
||||
|
||||
pmrf_gpio_ptr->gpio_control(GPIO_CMD_ENA_BIT_INT, (void *)MRF24J40_INT_PIN);
|
||||
|
||||
}
|
||||
|
||||
bool otPlatRadioIsEnabled(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
return (sState != kStateDisabled);
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioEnable(otInstance *aInstance)
|
||||
{
|
||||
if (!otPlatRadioIsEnabled(aInstance))
|
||||
{
|
||||
sState = kStateSleep;
|
||||
}
|
||||
|
||||
return kThreadError_None;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioDisable(otInstance *aInstance)
|
||||
{
|
||||
if (otPlatRadioIsEnabled(aInstance))
|
||||
{
|
||||
sState = kStateDisabled;
|
||||
}
|
||||
|
||||
return kThreadError_None;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioSleep(otInstance *aInstance)
|
||||
{
|
||||
ThreadError error = kThreadError_InvalidState;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState == kStateSleep || sState == kStateReceive)
|
||||
{
|
||||
error = kThreadError_None;
|
||||
sState = kStateSleep;
|
||||
disableReceiver();
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel)
|
||||
{
|
||||
ThreadError error = kThreadError_InvalidState;
|
||||
(void)aInstance;
|
||||
|
||||
if (sState != kStateDisabled)
|
||||
{
|
||||
error = kThreadError_None;
|
||||
sState = kStateReceive;
|
||||
setChannel(aChannel);
|
||||
sReceiveFrame.mChannel = aChannel;
|
||||
enableReceiver();
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioTransmit(otInstance *aInstance, RadioPacket *aPacket)
|
||||
{
|
||||
ThreadError error = kThreadError_InvalidState;
|
||||
(void)aInstance;
|
||||
(void)aPacket;
|
||||
|
||||
if (sState == kStateReceive)
|
||||
{
|
||||
error = kThreadError_None;
|
||||
sState = kStateTransmit;
|
||||
}
|
||||
|
||||
return error;
|
||||
|
||||
}
|
||||
|
||||
RadioPacket *otPlatRadioGetTransmitBuffer(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
return &sTransmitFrame;
|
||||
}
|
||||
|
||||
int8_t otPlatRadioGetRssi(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
return 0;
|
||||
}
|
||||
|
||||
otRadioCaps otPlatRadioGetCaps(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
return kRadioCapsNone;
|
||||
}
|
||||
|
||||
bool otPlatRadioGetPromiscuous(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
return (bool)(mrf24j40_read_short_ctrl_reg(MRF24J40_RXMCR) & MRF24J40_PROMI);
|
||||
}
|
||||
|
||||
// should be checked again with CC2538
|
||||
void otPlatRadioSetPromiscuous(otInstance *aInstance, bool aEnable)
|
||||
{
|
||||
(void)aInstance;
|
||||
mrf24j40_set_promiscuous(~aEnable);
|
||||
}
|
||||
|
||||
void readFrame(void)
|
||||
{
|
||||
|
||||
/* readBuffer
|
||||
* 1 bit -- 5 to 127 bits -- 1 bit -- 1bit
|
||||
* Frame Length -- PSDU (Header + Data Payload + FCS) -- LQI -- RSSI
|
||||
*/
|
||||
uint8_t readBuffer[MRF24J40_RXFIFO_SIZE];
|
||||
uint8_t readPlqi = 0;
|
||||
uint8_t readRssi = 0;
|
||||
|
||||
uint16_t length;
|
||||
int16_t i;
|
||||
|
||||
memset(readBuffer, 0, MRF24J40_RXFIFO_SIZE);
|
||||
|
||||
otEXPECT_ACTION(sState == kStateReceive || sState == kStateTransmit, ;);
|
||||
otEXPECT_ACTION(Mrf24StatusRx, ;);
|
||||
|
||||
if (Mrf24StatusRx == 1)
|
||||
{
|
||||
Mrf24StatusRx = 0;
|
||||
}
|
||||
|
||||
if (Mrf24StatusSec == 1)
|
||||
{
|
||||
Mrf24StatusSec = 0;
|
||||
}
|
||||
|
||||
/* Read length */
|
||||
length = (uint16_t)mrf24j40_rxpkt_intcb(readBuffer, &readPlqi, &readRssi);
|
||||
|
||||
otEXPECT_ACTION(IEEE802154_MIN_LENGTH <= length && length <= IEEE802154_MAX_LENGTH, ;);
|
||||
|
||||
/* Read PSDU */
|
||||
memcpy(sReceiveFrame.mPsdu, readBuffer, length - 2);
|
||||
|
||||
sReceiveFrame.mPower = (int8_t)(readRssi / MRF24J40_RSSI_SLOPE) - MRF24J40_RSSI_OFFSET;
|
||||
sReceiveFrame.mLength = (uint8_t) length;
|
||||
sReceiveFrame.mLqi = readPlqi;
|
||||
|
||||
exit:
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
void radioTransmitMessage(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
uint8_t header_len = 0;
|
||||
|
||||
sTransmitError = kThreadError_None;
|
||||
setChannel(sTransmitFrame.mChannel);
|
||||
|
||||
uint8_t reg = mrf24j40_read_short_ctrl_reg(MRF24J40_TXNCON);
|
||||
|
||||
header_len = getHeadLength(sTransmitFrame.mPsdu);
|
||||
|
||||
if (isAckRequested(sTransmitFrame.mPsdu))
|
||||
{
|
||||
reg |= MRF24J40_TXNACKREQ;
|
||||
}
|
||||
else
|
||||
{
|
||||
reg &= ~(MRF24J40_TXNACKREQ);
|
||||
}
|
||||
|
||||
if (isSecurityEnabled(sTransmitFrame.mPsdu))
|
||||
{
|
||||
reg |= MRF24J40_TXNSECEN;
|
||||
}
|
||||
else
|
||||
{
|
||||
reg &= ~(MRF24J40_TXNSECEN);
|
||||
mrf24j40_write_short_ctrl_reg(MRF24J40_TXNCON, mrf24j40_read_short_ctrl_reg(MRF24J40_TXNCON) & (~MRF24J40_TXNSECEN));
|
||||
}
|
||||
|
||||
mrf24j40_txfifo_write(MRF24J40_TXNFIFO, sTransmitFrame.mPsdu, header_len, (sTransmitFrame.mLength - 2));
|
||||
|
||||
mrf24j40_write_short_ctrl_reg(MRF24J40_TXNCON, reg | MRF24J40_TXNTRIG);
|
||||
|
||||
int16_t tx_timeout = 500;
|
||||
Mrf24StatusTx = 0;
|
||||
|
||||
while ((tx_timeout > 0) && (Mrf24StatusTx != 1))
|
||||
{
|
||||
mrf24j40_delay_ms(1);
|
||||
tx_timeout--;
|
||||
|
||||
if (tx_timeout <= 0)
|
||||
{
|
||||
DBG("Radio Transmit Timeout!!!!!!!!!!!!\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void emskRadioProcess(otInstance *aInstance)
|
||||
{
|
||||
numRadioProcess++;
|
||||
|
||||
readFrame();
|
||||
uint8_t reg = mrf24j40_read_short_ctrl_reg(MRF24J40_TXSTAT);
|
||||
|
||||
if (reg & MRF24J40_TXNSTAT)
|
||||
{
|
||||
DBG("TX MAC Timeout!!!!!!\r\n");
|
||||
|
||||
if (reg & MRF24J40_CCAFAIL)
|
||||
{
|
||||
DBG("Channel busy!!!!!!\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
if ((sState == kStateReceive) && (sReceiveFrame.mLength > 0))
|
||||
{
|
||||
otPlatRadioReceiveDone(aInstance, &sReceiveFrame, sReceiveError);
|
||||
}
|
||||
|
||||
if (sState == kStateTransmit)
|
||||
{
|
||||
radioTransmitMessage(aInstance);
|
||||
|
||||
if (sTransmitError != kThreadError_None || (sTransmitFrame.mPsdu[0] & IEEE802154_ACK_REQUEST) == 0)
|
||||
{
|
||||
sState = kStateReceive;
|
||||
otPlatRadioTransmitDone(aInstance, &sTransmitFrame, false, sTransmitError);
|
||||
}
|
||||
else if (Mrf24StatusTx == 1)
|
||||
{
|
||||
Mrf24StatusTx = 0;
|
||||
sState = kStateReceive;
|
||||
otPlatRadioTransmitDone(aInstance, &sTransmitFrame,
|
||||
(mrf24j40_read_short_ctrl_reg(MRF24J40_TXNCON) & MRF24J40_FPSTAT) != 0,
|
||||
sTransmitError);
|
||||
}
|
||||
}
|
||||
|
||||
sReceiveFrame.mLength = 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief isr routine of mrf24j40
|
||||
* \param[in] ptr pointer transferred frome interrupt entry
|
||||
*/
|
||||
static void RadioIsr(void *ptr)
|
||||
{
|
||||
uint8_t int_status = 0;
|
||||
|
||||
int_status = pmrf_read_short_ctrl_reg(MRF24J40_INTSTAT);
|
||||
|
||||
/* a frame is received */
|
||||
if (int_status & MRF24J40_RXIF)
|
||||
{
|
||||
numInterruptRev++;
|
||||
Mrf24StatusRx = 1;
|
||||
}
|
||||
|
||||
/* a frame is transmitted */
|
||||
if (int_status & MRF24J40_TXNIF)
|
||||
{
|
||||
switch (mrf24j40_txpkt_intcb())
|
||||
{
|
||||
case MRF24J40_EBUSY:
|
||||
/* Channel busy */
|
||||
break;
|
||||
|
||||
case MRF24J40_EIO:
|
||||
/* Channel idle */
|
||||
break;
|
||||
|
||||
case 0:
|
||||
numInterruptTrans++;
|
||||
Mrf24StatusTx = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* a frame with security key request is received */
|
||||
if (int_status & MRF24J40_SECIF)
|
||||
{
|
||||
Mrf24StatusSec = 1;
|
||||
mrf24j40_sec_intcb(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* CC2538 supports source address matching for low power consumption
|
||||
and this is not supported in MRF24J40 */
|
||||
void otPlatRadioEnableSrcMatch(otInstance *aInstance, bool aEnable)
|
||||
{
|
||||
(void)aInstance;
|
||||
(void)aEnable;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioAddSrcMatchShortEntry(otInstance *aInstance, const uint16_t aShortAddress)
|
||||
{
|
||||
(void)aInstance;
|
||||
(void)aShortAddress;
|
||||
return kThreadError_None;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioAddSrcMatchExtEntry(otInstance *aInstance, const uint8_t *aExtAddress)
|
||||
{
|
||||
(void)aInstance;
|
||||
(void)aExtAddress;
|
||||
return kThreadError_None;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioClearSrcMatchShortEntry(otInstance *aInstance, const uint16_t aShortAddress)
|
||||
{
|
||||
(void)aInstance;
|
||||
(void)aShortAddress;
|
||||
return kThreadError_None;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioClearSrcMatchExtEntry(otInstance *aInstance, const uint8_t *aExtAddress)
|
||||
{
|
||||
(void)aInstance;
|
||||
(void)aExtAddress;
|
||||
return kThreadError_None;
|
||||
}
|
||||
|
||||
void otPlatRadioClearSrcMatchShortEntries(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
}
|
||||
|
||||
void otPlatRadioClearSrcMatchExtEntries(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioEnergyScan(otInstance *aInstance, uint8_t aScanChannel, uint16_t aScanDuration)
|
||||
{
|
||||
(void)aInstance;
|
||||
(void)aScanChannel;
|
||||
(void)aScanDuration;
|
||||
return kThreadError_NotImplemented;
|
||||
}
|
||||
|
||||
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 EMSK_RECEIVE_SENSITIVITY;
|
||||
}
|
||||
Executable
+106
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* 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 implements a pseudo-random number generator.
|
||||
*
|
||||
* @warning
|
||||
* This implementation is not a true random number generator and does @em satisfy the Thread requirements.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <utils/code_utils.h>
|
||||
|
||||
#include "openthread/platform/random.h"
|
||||
#include "openthread/platform/radio.h"
|
||||
#include "platform-emsk.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static unsigned int seed;
|
||||
|
||||
void emskRandomInit(void)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
printf("Node No.:");
|
||||
scanf("%d", &i);
|
||||
printf("%d\n", i);
|
||||
seed = 10 + i;
|
||||
srand(seed);
|
||||
}
|
||||
|
||||
uint32_t otPlatRandomGet(void)
|
||||
{
|
||||
|
||||
return (uint32_t)rand();
|
||||
}
|
||||
|
||||
ThreadError otPlatRandomGetTrue(uint8_t *aOutput, uint16_t aOutputLength)
|
||||
{
|
||||
ThreadError error = kThreadError_None;
|
||||
uint8_t channel = 0;
|
||||
|
||||
otEXPECT_ACTION(aOutput && aOutputLength, error = kThreadError_InvalidArgs);
|
||||
|
||||
/* disable radio*/
|
||||
if (otPlatRadioIsEnabled(sInstance))
|
||||
{
|
||||
channel = (mrf24j40_read_long_ctrl_reg(MRF24J40_RFCON0) >> 4) + 11;
|
||||
otPlatRadioSleep(sInstance);
|
||||
otPlatRadioDisable(sInstance);
|
||||
}
|
||||
|
||||
/*
|
||||
* THE IMPLEMENTATION BELOW IS NOT COMPLIANT WITH THE THREAD SPECIFICATION.
|
||||
*
|
||||
* Please see Note in `<path-to-openthread>/examples/platforms/emsk/README.md`
|
||||
* for TRNG features on EMSK.
|
||||
*/
|
||||
otEXPECT_ACTION(aOutput && aOutputLength, error = kThreadError_InvalidArgs);
|
||||
|
||||
for (uint16_t length = 0; length < aOutputLength; length++)
|
||||
{
|
||||
/* Get random number */
|
||||
aOutput[length] = (uint8_t)otPlatRandomGet();
|
||||
}
|
||||
|
||||
/* Enable radio*/
|
||||
if (channel)
|
||||
{
|
||||
emskRadioInit();
|
||||
otPlatRadioEnable(sInstance);
|
||||
otPlatRadioReceive(sInstance, channel);
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* 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 implements the OpenThread platform abstraction for UART communication.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "openthread/types.h"
|
||||
#include <utils/code_utils.h>
|
||||
#include "openthread/platform/uart.h"
|
||||
#include "platform-emsk.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
|
||||
|
||||
enum
|
||||
{
|
||||
kUartId = BOARD_CONSOLE_UART_ID,
|
||||
kBaudRate = BOARD_CONSOLE_UART_BAUD,
|
||||
kReceiveBufferSize = 128,
|
||||
};
|
||||
|
||||
static void processReceive(void);
|
||||
static void processTransmit(void);
|
||||
|
||||
static const uint8_t *sTransmitBuffer = NULL;
|
||||
static uint16_t sTransmitLength = 0;
|
||||
|
||||
static uint8_t sReceiveBuffer[kReceiveBufferSize];
|
||||
static uint16_t sReceiveHead = 0;
|
||||
|
||||
static DEV_UART *consoleUart;
|
||||
|
||||
ThreadError otPlatUartEnable(void)
|
||||
{
|
||||
int32_t stateUart = 0;
|
||||
ThreadError error = kThreadError_Drop;
|
||||
|
||||
/* UART in embARC */
|
||||
consoleUart = uart_get_dev(BOARD_CONSOLE_UART_ID);
|
||||
|
||||
otEXPECT_ACTION(!(consoleUart == NULL), DBG("Console UART is missing.\r\n"));
|
||||
|
||||
stateUart = consoleUart->uart_open(BOARD_CONSOLE_UART_BAUD);
|
||||
|
||||
if (stateUart == E_OPNED)
|
||||
{
|
||||
consoleUart->uart_control(UART_CMD_SET_BAUD, (void *)(BOARD_CONSOLE_UART_BAUD));
|
||||
error = kThreadError_None;
|
||||
DBG("Set Console UART Baudrate to %d.\r\n", BOARD_CONSOLE_UART_BAUD);
|
||||
}
|
||||
else if (stateUart == E_OK)
|
||||
{
|
||||
error = kThreadError_None;
|
||||
DBG("Open Console UART Successfully.\r\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG("Open Console UART Error.\r\n");
|
||||
}
|
||||
|
||||
exit:
|
||||
|
||||
return error;
|
||||
|
||||
}
|
||||
|
||||
ThreadError otPlatUartDisable(void)
|
||||
{
|
||||
return kThreadError_None;
|
||||
}
|
||||
|
||||
ThreadError otPlatUartSend(const uint8_t *aBuf, uint16_t aBufLength)
|
||||
{
|
||||
ThreadError error = kThreadError_None;
|
||||
|
||||
otEXPECT_ACTION(sTransmitBuffer == NULL, error = kThreadError_Busy);
|
||||
|
||||
sTransmitBuffer = aBuf;
|
||||
sTransmitLength = aBufLength;
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void processReceive(void)
|
||||
{
|
||||
|
||||
int32_t rdAvail = 0;
|
||||
uint16_t remaining;
|
||||
|
||||
consoleUart->uart_control(UART_CMD_GET_RXAVAIL, (void *)(&rdAvail));
|
||||
otEXPECT_ACTION(rdAvail > 0, ;);
|
||||
|
||||
remaining = kReceiveBufferSize - sReceiveHead;
|
||||
|
||||
if (rdAvail >= remaining)
|
||||
{
|
||||
consoleUart->uart_read((void *)(sReceiveBuffer + sReceiveHead), (uint32_t)remaining);
|
||||
otPlatUartReceived(sReceiveBuffer + sReceiveHead, remaining);
|
||||
sReceiveHead = 0;
|
||||
rdAvail -= (int32_t)remaining;
|
||||
}
|
||||
|
||||
while (rdAvail >= kReceiveBufferSize)
|
||||
{
|
||||
consoleUart->uart_read((void *)(sReceiveBuffer + sReceiveHead), (uint32_t)kReceiveBufferSize);
|
||||
otPlatUartReceived(sReceiveBuffer + sReceiveHead, kReceiveBufferSize);
|
||||
rdAvail -= kReceiveBufferSize;
|
||||
}
|
||||
|
||||
if (rdAvail > 0)
|
||||
{
|
||||
consoleUart->uart_read((void *)(sReceiveBuffer + sReceiveHead), (uint32_t)rdAvail);
|
||||
otPlatUartReceived(sReceiveBuffer + sReceiveHead, rdAvail);
|
||||
sReceiveHead += (uint16_t)rdAvail;
|
||||
}
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void processTransmit(void)
|
||||
{
|
||||
otEXPECT_ACTION(sTransmitBuffer != NULL, ;);
|
||||
|
||||
consoleUart->uart_write((void *)sTransmitBuffer, (int32_t)sTransmitLength);
|
||||
|
||||
sTransmitBuffer = NULL;
|
||||
otPlatUartSendDone();
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void emskUartProcess(void)
|
||||
{
|
||||
processReceive();
|
||||
processTransmit();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user