mirror of
https://github.com/espressif/openthread.git
synced 2026-07-30 15:47:46 +00:00
[platforms] add support for Microchip SAMR21 (#2297)
* Add support for Microchip SAMR21 Signed-off-by: Oleksandr Grytsov <[email protected]>
This commit is contained in:
committed by
Jonathan Hui
parent
c46b75d0cf
commit
f0d3512317
+12
-2
@@ -1193,11 +1193,11 @@ AM_CONDITIONAL([OPENTHREAD_ENABLE_LINKER_MAP], [test "${enable_linker_map}" = "y
|
||||
|
||||
AC_ARG_WITH(examples,
|
||||
[AS_HELP_STRING([--with-examples=TARGET],
|
||||
[Specify the examples from one of: none, posix, cc2538, cc2650, cc2652, da15000, efr32, emsk, gp712, kw41z, nrf52840 @<:@default=none@:>@.])],
|
||||
[Specify the examples from one of: none, posix, cc2538, cc2650, cc2652, da15000, efr32, emsk, gp712, kw41z, nrf52840, samr21 @<:@default=none@:>@.])],
|
||||
[
|
||||
case "${with_examples}" in
|
||||
|
||||
none|posix|cc2538|cc2650|cc2652|da15000|efr32|emsk|gp712|kw41z|nrf52840)
|
||||
none|posix|cc2538|cc2650|cc2652|da15000|efr32|emsk|gp712|kw41z|nrf52840|samr21)
|
||||
;;
|
||||
*)
|
||||
AC_MSG_ERROR([Invalid value ${with_examples} for --with-examples])
|
||||
@@ -1259,6 +1259,12 @@ 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])
|
||||
;;
|
||||
|
||||
samr21)
|
||||
OPENTHREAD_EXAMPLES_SAMR21=1
|
||||
AC_DEFINE_UNQUOTED([OPENTHREAD_EXAMPLES_SAMR21],[${OPENTHREAD_EXAMPLES_SAMR21}],[Define to 1 if you want to use samr21 examples])
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
AC_MSG_CHECKING([whether to enable examples])
|
||||
@@ -1298,6 +1304,9 @@ AM_CONDITIONAL([OPENTHREAD_EXAMPLES_KW41Z], [test "${OPENTHREAD_EXAMPLES}" = "kw
|
||||
AC_SUBST(OPENTHREAD_EXAMPLES_NRF52840)
|
||||
AM_CONDITIONAL([OPENTHREAD_EXAMPLES_NRF52840], [test "${OPENTHREAD_EXAMPLES}" = "nrf52840"])
|
||||
|
||||
AC_SUBST(OPENTHREAD_EXAMPLES_SAMR21)
|
||||
AM_CONDITIONAL([OPENTHREAD_EXAMPLES_SAMR21], [test "${OPENTHREAD_EXAMPLES}" = "samr21"])
|
||||
|
||||
#
|
||||
# Tools
|
||||
#
|
||||
@@ -1445,6 +1454,7 @@ examples/platforms/emsk/Makefile
|
||||
examples/platforms/gp712/Makefile
|
||||
examples/platforms/kw41z/Makefile
|
||||
examples/platforms/nrf52840/Makefile
|
||||
examples/platforms/samr21/Makefile
|
||||
examples/platforms/posix/Makefile
|
||||
examples/platforms/utils/Makefile
|
||||
tools/Makefile
|
||||
|
||||
@@ -0,0 +1,261 @@
|
||||
#
|
||||
# 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 = arm-none-eabi-ar
|
||||
CCAS = arm-none-eabi-as
|
||||
CPP = arm-none-eabi-cpp
|
||||
CC = arm-none-eabi-gcc
|
||||
CXX = arm-none-eabi-g++
|
||||
LD = arm-none-eabi-ld
|
||||
STRIP = arm-none-eabi-strip
|
||||
NM = arm-none-eabi-nm
|
||||
RANLIB = arm-none-eabi-ranlib
|
||||
OBJCOPY = arm-none-eabi-objcopy
|
||||
|
||||
BuildJobs ?= 10
|
||||
|
||||
configure_OPTIONS = \
|
||||
--enable-cli-app=all \
|
||||
--enable-ncp-app=all \
|
||||
--with-ncp-bus=uart \
|
||||
--enable-diag \
|
||||
--with-examples=samr21 \
|
||||
--enable-linker-map \
|
||||
$(NULL)
|
||||
|
||||
include $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/common-switches.mk
|
||||
|
||||
TopSourceDir := $(dir $(shell readlink $(firstword $(MAKEFILE_LIST))))..
|
||||
AbsTopSourceDir := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))..
|
||||
|
||||
CONFIG_FILE = OPENTHREAD_PROJECT_CORE_CONFIG_FILE='\"openthread-core-samr21-config.h\"'
|
||||
CONFIG_FILE_PATH = $(AbsTopSourceDir)/examples/platforms/samr21/
|
||||
|
||||
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)
|
||||
|
||||
LDFLAGS += \
|
||||
$(COMMONCFLAGS) \
|
||||
$(target_LDFLAGS) \
|
||||
-specs=nano.specs \
|
||||
-specs=nosys.specs \
|
||||
-Wl,--gc-sections \
|
||||
-Wl,--entry=Reset_Handler \
|
||||
$(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 = samr21
|
||||
|
||||
ARCHS = cortex-m0plus
|
||||
|
||||
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)" OBJC="$(OBJC)" OBJCXX="$(OBJCXX)" AR="$(AR)" RANLIB="$(RANLIB)" NM="$(NM)" STRIP="$(STRIP)" CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" \
|
||||
--host=arm-none-eabi \
|
||||
--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): $(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
|
||||
|
||||
#
|
||||
# cortex-m0plus
|
||||
#
|
||||
|
||||
cortex-m0plus_target_ABI = cortex-m0plus
|
||||
cortex-m0plus_target_CPPFLAGS = -mcpu=cortex-m0plus -mfloat-abi=soft -mthumb
|
||||
cortex-m0plus_target_CFLAGS = -mcpu=cortex-m0plus -mfloat-abi=soft -mthumb
|
||||
cortex-m0plus_target_CXXFLAGS = -mcpu=cortex-m0plus -mfloat-abi=soft -mthumb
|
||||
cortex-m0plus_target_LDFLAGS = -mcpu=cortex-m0plus -mfloat-abi=soft -mthumb
|
||||
|
||||
# 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) ""
|
||||
@@ -171,6 +171,16 @@ LDFLAGS_COMMON += \
|
||||
$(NULL)
|
||||
endif # OPENTHREAD_EXAMPLES_KW41Z
|
||||
|
||||
if OPENTHREAD_EXAMPLES_SAMR21
|
||||
LDADD_COMMON += \
|
||||
$(top_builddir)/examples/platforms/samr21/libopenthread-samr21.a \
|
||||
$(NULL)
|
||||
|
||||
LDFLAGS_COMMON += \
|
||||
-T $(top_srcdir)/third_party/microchip/include/samr21x18a.ld \
|
||||
$(NULL)
|
||||
endif # OPENTHREAD_EXAMPLES_SAMR21
|
||||
|
||||
if OPENTHREAD_ENABLE_CLI_FTD
|
||||
bin_PROGRAMS += \
|
||||
ot-cli-ftd \
|
||||
|
||||
@@ -163,6 +163,16 @@ LDFLAGS_COMMON += \
|
||||
$(NULL)
|
||||
endif # OPENTHREAD_EXAMPLES_KW41Z
|
||||
|
||||
if OPENTHREAD_EXAMPLES_SAMR21
|
||||
LDADD_COMMON += \
|
||||
$(top_builddir)/examples/platforms/samr21/libopenthread-samr21.a \
|
||||
$(NULL)
|
||||
|
||||
LDFLAGS_COMMON += \
|
||||
-T $(top_srcdir)/third_party/microchip/include/samr21x18a.ld \
|
||||
$(NULL)
|
||||
endif # OPENTHREAD_EXAMPLES_SAMR21
|
||||
|
||||
if OPENTHREAD_ENABLE_NCP_FTD
|
||||
bin_PROGRAMS += \
|
||||
ot-ncp-ftd \
|
||||
|
||||
@@ -41,6 +41,7 @@ DIST_SUBDIRS = \
|
||||
kw41z \
|
||||
nrf52840 \
|
||||
posix \
|
||||
samr21 \
|
||||
utils \
|
||||
$(NULL)
|
||||
|
||||
@@ -90,6 +91,10 @@ if OPENTHREAD_EXAMPLES_POSIX
|
||||
SUBDIRS += posix
|
||||
endif
|
||||
|
||||
if OPENTHREAD_EXAMPLES_SAMR21
|
||||
SUBDIRS += samr21
|
||||
endif
|
||||
|
||||
# Always pretty (e.g. for 'make pretty') these subdirectories.
|
||||
|
||||
PRETTY_SUBDIRS = \
|
||||
@@ -103,6 +108,7 @@ PRETTY_SUBDIRS = \
|
||||
kw41z \
|
||||
nrf52840 \
|
||||
posix \
|
||||
samr21 \
|
||||
utils \
|
||||
$(NULL)
|
||||
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
#
|
||||
# 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-samr21.a
|
||||
|
||||
override CFLAGS := $(filter-out -pedantic-errors,$(CFLAGS))
|
||||
override CXXFLAGS := $(filter-out -pedantic-errors,$(CXXFLAGS))
|
||||
|
||||
#SAMR21_BOARD=USER_BOARD
|
||||
#SAMR21_CPU=__SAMR21E18A__
|
||||
|
||||
SAMR21_BOARD=SAMR21_XPLAINED_PRO
|
||||
SAMR21_CPU=__SAMR21G18A__
|
||||
|
||||
libopenthread_samr21_a_CPPFLAGS = \
|
||||
-D ARM_MATH_CM0PLUS=true \
|
||||
-D BOARD=$(SAMR21_BOARD) \
|
||||
-D $(SAMR21_CPU) \
|
||||
-D PHY_AT86RF233 \
|
||||
-D SAL_TYPE=AT86RF2xx \
|
||||
-D USART_CALLBACK_MODE=true \
|
||||
-D EXTINT_CALLBACK_MODE=true \
|
||||
-D SPI_CALLBACK_MODE=false \
|
||||
-D CYCLE_MODE \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/examples/platforms \
|
||||
-I$(top_srcdir)/src/core \
|
||||
-I$(top_srcdir)/third_party/microchip/include \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/common/boards \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/common/utils \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/common2/services/delay \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/common2/services/delay/sam0 \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/sam0/boards \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/sam0/boards/samr21_xplained_pro \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/sam0/drivers/extint \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/sam0/drivers/extint/extint_sam_d_r_h \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/sam0/drivers/nvm \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/sam0/drivers/port \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/sam0/drivers/system \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/sam0/drivers/system/clock \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/sam0/drivers/system/clock/clock_samd21_r21_da_ha1 \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/sam0/drivers/system/interrupt \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/sam0/drivers/system/interrupt/system_interrupt_samr21 \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/sam0/drivers/system/pinmux \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/sam0/drivers/system/power \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/sam0/drivers/system/power/power_sam_d_r_h \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/sam0/drivers/system/reset \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/sam0/drivers/system/reset/reset_sam_d_r_h \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/sam0/drivers/sercom \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/sam0/drivers/sercom/i2c \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/sam0/drivers/sercom/i2c/i2c_sam0 \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/sam0/drivers/sercom/spi \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/sam0/drivers/sercom/usart \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/sam0/utils \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/sam0/utils/cmsis/samr21/include \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/sam0/utils/cmsis/samr21/source \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/sam0/utils/header_files \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/sam0/utils/preprocessor \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/thirdparty/CMSIS/Include \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/thirdparty/wireless/avr2130_lwmesh/source/phy/at86rf233/inc \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/thirdparty/wireless/services/sal/inc \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/thirdparty/wireless/services/trx_access \
|
||||
-I$(top_srcdir)/third_party/microchip/asf/thirdparty/wireless/services/trx_access/module_config \
|
||||
-Werror \
|
||||
-Wno-unused-parameter \
|
||||
-Wno-implicit-function-declaration \
|
||||
-fno-strict-aliasing \
|
||||
$(NULL)
|
||||
|
||||
PLATFORM_SOURCES = \
|
||||
alarm.c \
|
||||
cxx_helpers.c \
|
||||
flash.c \
|
||||
logging.c \
|
||||
misc.c \
|
||||
platform.c \
|
||||
radio.c \
|
||||
random.c \
|
||||
uart.c \
|
||||
$(NULL)
|
||||
|
||||
if OPENTHREAD_ENABLE_DIAG
|
||||
PLATFORM_SOURCES += \
|
||||
diag.c \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
libopenthread_samr21_a_SOURCES = \
|
||||
$(PLATFORM_SOURCES) \
|
||||
$(NULL)
|
||||
|
||||
nodist_libopenthread_samr21_a_SOURCES = \
|
||||
@top_builddir@/third_party/microchip/asf/common/utils/interrupt/interrupt_sam_nvic.c \
|
||||
@top_builddir@/third_party/microchip/asf/common2/services/delay/sam0/cycle_counter.c \
|
||||
@top_builddir@/third_party/microchip/asf/sam0/drivers/extint/extint_callback.c \
|
||||
@top_builddir@/third_party/microchip/asf/sam0/drivers/extint/extint_sam_d_r_h/extint.c \
|
||||
@top_builddir@/third_party/microchip/asf/sam0/drivers/nvm/nvm.c \
|
||||
@top_builddir@/third_party/microchip/asf/sam0/drivers/port/port.c \
|
||||
@top_builddir@/third_party/microchip/asf/sam0/drivers/system/clock/clock_samd21_r21_da_ha1/clock.c \
|
||||
@top_builddir@/third_party/microchip/asf/sam0/drivers/system/clock/clock_samd21_r21_da_ha1/gclk.c \
|
||||
@top_builddir@/third_party/microchip/asf/sam0/drivers/system/interrupt/system_interrupt.c \
|
||||
@top_builddir@/third_party/microchip/asf/sam0/drivers/system/pinmux/pinmux.c \
|
||||
@top_builddir@/third_party/microchip/asf/sam0/drivers/sercom/sercom.c \
|
||||
@top_builddir@/third_party/microchip/asf/sam0/drivers/sercom/sercom_interrupt.c \
|
||||
@top_builddir@/third_party/microchip/asf/sam0/drivers/sercom/i2c/i2c_sam0/i2c_master.c \
|
||||
@top_builddir@/third_party/microchip/asf/sam0/drivers/sercom/spi/spi.c \
|
||||
@top_builddir@/third_party/microchip/asf/sam0/drivers/sercom/usart/usart.c \
|
||||
@top_builddir@/third_party/microchip/asf/sam0/drivers/sercom/usart/usart_interrupt.c \
|
||||
@top_builddir@/third_party/microchip/asf/sam0/utils/cmsis/samr21/source/gcc/startup_samr21.c \
|
||||
@top_builddir@/third_party/microchip/asf/sam0/utils/cmsis/samr21/source/system_samr21.c \
|
||||
@top_builddir@/third_party/microchip/asf/sam0/utils/syscalls/gcc/syscalls.c \
|
||||
@top_builddir@/third_party/microchip/asf/thirdparty/wireless/avr2130_lwmesh/source/phy/at86rf233/src/phy.c \
|
||||
@top_builddir@/third_party/microchip/asf/thirdparty/wireless/services/sal/at86rf2xx/src/sal.c \
|
||||
@top_builddir@/third_party/microchip/asf/thirdparty/wireless/services/trx_access/trx_access.c \
|
||||
$(NULL)
|
||||
|
||||
noinst_HEADERS = \
|
||||
$(NULL)
|
||||
|
||||
PRETTY_FILES = \
|
||||
$(PLATFORM_SOURCES) \
|
||||
$(NULL)
|
||||
|
||||
Dash = -
|
||||
libopenthread_samr21_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,188 @@
|
||||
# OpenThread on SAMR21 Example
|
||||
|
||||
This directory contains example platform drivers for the [Microchip ATSAMR21G18A][samr21]
|
||||
based on [SAM R21 Xplained Pro Evaluation Kit][SAMR21_XPLAINED_PRO].
|
||||
|
||||
[samr21]: http://www.microchip.com/wwwproducts/en/ATSAMR21G18A
|
||||
[SAMR21_XPLAINED_PRO]: http://www.microchip.com/DevelopmentTools/ProductDetails.aspx?PartNO=ATSAMR21-XPRO
|
||||
|
||||
The example platform drivers are intended to present the minimal code
|
||||
necessary to support OpenThread. See the "Run the example with SAMR21 boards" section below
|
||||
for an example using basic OpenThread capabilities.
|
||||
|
||||
## Toolchain
|
||||
|
||||
Download and install the [GNU toolchain for ARM Cortex-M][gnu-toolchain].
|
||||
|
||||
[gnu-toolchain]: https://launchpad.net/gcc-arm-embedded
|
||||
|
||||
In a Bash terminal, follow these instructions to install the GNU toolchain and
|
||||
other dependencies.
|
||||
|
||||
```bash
|
||||
$ cd <path-to-openthread>
|
||||
$ ./script/bootstrap
|
||||
```
|
||||
|
||||
## Build Examples
|
||||
|
||||
1. Download [Advanced Software Framework (ASF)][ASF].
|
||||
|
||||
[ASF]: http://www.microchip.com/avr-support/advanced-software-framework-(asf)
|
||||
|
||||
2. Unzip it to <path-to-openthread>/third_party/microchip folder
|
||||
|
||||
```bash
|
||||
$ unzip asf-standalone-archive-3.35.1.54.zip
|
||||
$ cp xdk-asf-3.35.1 -rf <path-to-openthread>/third_party/microchip/asf
|
||||
```
|
||||
3. SAM R21 Xplained Pro board doesn't have IEEE extended address assigned. It should be
|
||||
assigned before build. In this example IEEE address is assigned by setting
|
||||
CONF_IEEE_ADDRESS macro in `conf_board.h`. If you use few SAM R21 Xplained Pro boards
|
||||
for test, make sure that each board has individual IEEE address.
|
||||
|
||||
4. This example can be built for other SAMR21 based modules. For example [ATSAMR21G18-MR21][MODULE-MR21],
|
||||
[ATSAMR21B18-MZ21][MODULE-MZ21]. To build for these modules set
|
||||
SAMR21_BOARD=USER_BOARD and SAMR21_CPU=\_\_SAMR21XXXX\_\_ in `examples/samr21/Makefile.am`. Then
|
||||
configure peripherals in `user_board.h`. For these modules IEEE address is stored at special
|
||||
address in ROM. IEEE address is read from this location if CONF_IEEE_ADDRESS macro is not set.
|
||||
|
||||
[MODULE-MR21]: http://www.atmel.com/Images/Atmel-42475-ATSAMR21G18-MR210UA_Datasheet.pdf
|
||||
[MODULE-MZ21]: http://www.atmel.com/images/Atmel-42486-atsamr21b18-mz210pa_datasheet.pdf
|
||||
|
||||
5. Build OpenThread Firmware (CLI example) on SAMR21 platform.
|
||||
|
||||
```bash
|
||||
$ cd <path-to-openthread>
|
||||
$ ./bootstrap
|
||||
$ make -f examples/Makefile-samr21
|
||||
```
|
||||
|
||||
After a successful build, the `elf` files are found in
|
||||
`<path-to-openthread>/output/samr21/bin`.
|
||||
|
||||
## Flash Binaries
|
||||
|
||||
Compiled binaries may be flashed onto the SAM R21 Xplained Pro using embedded
|
||||
debugger EDBG.
|
||||
|
||||
```bash
|
||||
$ openocd -f board/atmel_samr21_xplained_pro.cfg
|
||||
$ cd <path-to-openthread>/output/samr21/bin
|
||||
$ arm-none-eabi-gdb ot-cli-ftd
|
||||
$ (gdb) target remote 127.0.0.1:3333
|
||||
$ (gdb) load
|
||||
$ (gdb) monitor reset
|
||||
$ (gdb) c
|
||||
```
|
||||
|
||||
## Run the example with SAM R21 Xplained Pro boards
|
||||
1. Flash two SAM R21 Xplained Pro boards with the `CLI example` firmware (as shown above).
|
||||
2. Open terminal to first device `/dev/ttyACM0` (serial port settings: 115200 8-N-1).
|
||||
Type `help` for a 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
|
||||
```
|
||||
|
||||
3. Start a Thread network as Leader.
|
||||
|
||||
```bash
|
||||
> panid 0xface
|
||||
Done
|
||||
> ifconfig up
|
||||
Done
|
||||
> thread start
|
||||
Done
|
||||
|
||||
wait a couple of seconds...
|
||||
|
||||
> state
|
||||
leader
|
||||
Done
|
||||
```
|
||||
|
||||
4. Open terminal to second device `/dev/ttyACM1` (serial port settings: 115200 8-N-1)
|
||||
and attach it to the Thread network as a Router.
|
||||
|
||||
```bash
|
||||
> panid 0xface
|
||||
Done
|
||||
> routerselectionjitter 1
|
||||
Done
|
||||
> ifconfig up
|
||||
Done
|
||||
> thread start
|
||||
Done
|
||||
|
||||
wait a couple of seconds...
|
||||
|
||||
> state
|
||||
router
|
||||
Done
|
||||
```
|
||||
|
||||
5. List all IPv6 addresses of Leader.
|
||||
|
||||
```bash
|
||||
> ipaddr
|
||||
fdde:ad00:beef:0:0:ff:fe00:fc00
|
||||
fdde:ad00:beef:0:0:ff:fe00:800
|
||||
fdde:ad00:beef:0:5b:3bcd:deff:7786
|
||||
fe80:0:0:0:6447:6e10:cf7:ee29
|
||||
Done
|
||||
```
|
||||
|
||||
6. Send an ICMPv6 ping to Leader's Mesh-EID IPv6 address.
|
||||
|
||||
```bash
|
||||
> ping fdde:ad00:beef:0:5b:3bcd:deff:7786
|
||||
8 bytes from fdde:ad00:beef:0:5b:3bcd:deff:7786: icmp_seq=1 hlim=64 time=24ms
|
||||
```
|
||||
|
||||
The above example demonstrates basic OpenThread capabilities. Enable more features/roles (e.g. commissioner,
|
||||
joiner, DHCPv6 Server/Client, etc.) by assigning compile-options before compiling.
|
||||
|
||||
```bash
|
||||
$ cd <path-to-openthread>
|
||||
$ ./bootstrap
|
||||
$ make -f examples/Makefile-samr21 COMMISSIONER=1 JOINER=1 DHCP6_CLIENT=1 DHCP6_SERVER=1
|
||||
```
|
||||
|
||||
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
|
||||
|
||||
## Other boards
|
||||
|
||||
## Verification
|
||||
|
||||
The following toolchain has been used for testing and verification:
|
||||
- gcc version 6.3.1
|
||||
- Advanced Software Framework (ASF) version 3.35.1
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* 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 "asf.h"
|
||||
|
||||
#include <openthread/platform/alarm-milli.h>
|
||||
|
||||
static volatile uint32_t sTime = 0;
|
||||
static uint32_t sDeltaTime = 0;
|
||||
static uint32_t sStartTime = 0;
|
||||
|
||||
void otPlatAlarmMilliStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt)
|
||||
{
|
||||
(void)aInstance;
|
||||
|
||||
sDeltaTime = aDt;
|
||||
sStartTime = aT0;
|
||||
}
|
||||
|
||||
void otPlatAlarmMilliStop(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
|
||||
sDeltaTime = 0;
|
||||
}
|
||||
|
||||
uint32_t otPlatAlarmMilliGetNow(void)
|
||||
{
|
||||
return sTime;
|
||||
}
|
||||
|
||||
|
||||
void SysTick_Handler(void)
|
||||
{
|
||||
sTime++;
|
||||
}
|
||||
|
||||
void samr21AlarmInit(void)
|
||||
{
|
||||
/*Configure system tick to generate periodic interrupts */
|
||||
SysTick_Config(system_gclk_gen_get_hz(GCLK_GENERATOR_0) / 1000);
|
||||
}
|
||||
|
||||
void samr21AlarmProcess(otInstance *aInstance)
|
||||
{
|
||||
if ((sDeltaTime != 0) && ((sTime - sStartTime) >= sDeltaTime))
|
||||
{
|
||||
sDeltaTime = 0;
|
||||
|
||||
#if OPENTHREAD_ENABLE_DIAG
|
||||
|
||||
if (otPlatDiagModeGet())
|
||||
{
|
||||
otPlatDiagAlarmFired(aInstance);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
otPlatAlarmMilliFired(aInstance);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Helper functions for running c++ without the standard library
|
||||
*/
|
||||
|
||||
__extension__ typedef int __guard __attribute__((mode(__DI__)));
|
||||
|
||||
int __cxa_guard_acquire(__guard *g)
|
||||
{
|
||||
return !*(char *)(g);
|
||||
}
|
||||
|
||||
void __cxa_guard_release(__guard *g)
|
||||
{
|
||||
*(char *)g = 1;
|
||||
}
|
||||
|
||||
void __cxa_guard_abort(__guard *g)
|
||||
{
|
||||
(void)g;
|
||||
}
|
||||
|
||||
void __cxa_pure_virtual(void)
|
||||
{
|
||||
while (1);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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 diagnostics.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <openthread/platform/diag.h>
|
||||
|
||||
/**
|
||||
* Diagnostics mode variables.
|
||||
*
|
||||
*/
|
||||
static bool sDiagMode = false;
|
||||
|
||||
void otPlatDiagProcess(otInstance *aInstance, int argc, char *argv[], char *aOutput, size_t aOutputMaxLen)
|
||||
{
|
||||
(void) argc;
|
||||
(void) aInstance;
|
||||
|
||||
// Add more plarform specific diagnostics features here.
|
||||
snprintf(aOutput, aOutputMaxLen, "diag feature '%s' is not supported\r\n", argv[0]);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* 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 non-volatile storage.
|
||||
*/
|
||||
|
||||
#include "asf.h"
|
||||
|
||||
#include "utils/code_utils.h"
|
||||
#include "utils/flash.h"
|
||||
|
||||
#include "openthread-core-samr21-config.h"
|
||||
|
||||
otError utilsFlashInit(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
struct nvm_config configNvm;
|
||||
|
||||
nvm_get_config_defaults(&configNvm);
|
||||
|
||||
configNvm.manual_page_write = false;
|
||||
|
||||
enum status_code status;
|
||||
|
||||
while ((status = nvm_set_config(&configNvm)) == STATUS_BUSY);
|
||||
|
||||
if (status != STATUS_OK)
|
||||
{
|
||||
error = OT_ERROR_FAILED;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
uint32_t utilsFlashGetSize(void)
|
||||
{
|
||||
return SETTINGS_CONFIG_PAGE_NUM * SETTINGS_CONFIG_PAGE_SIZE;
|
||||
}
|
||||
|
||||
otError utilsFlashErasePage(uint32_t aAddress)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (nvm_erase_row(aAddress) != STATUS_OK)
|
||||
{
|
||||
error = OT_ERROR_FAILED;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
otError utilsFlashStatusWait(uint32_t aTimeout)
|
||||
{
|
||||
otError error = OT_ERROR_BUSY;
|
||||
uint32_t start = otPlatAlarmMilliGetNow();
|
||||
|
||||
do
|
||||
{
|
||||
if (nvm_is_ready())
|
||||
{
|
||||
error = OT_ERROR_NONE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (aTimeout && ((otPlatAlarmMilliGetNow() - start) < aTimeout));
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
uint32_t utilsFlashWrite(uint32_t aAddress, uint8_t *aData, uint32_t aSize)
|
||||
{
|
||||
uint32_t rval = aSize;
|
||||
|
||||
otEXPECT_ACTION(aData, rval = 0);
|
||||
otEXPECT_ACTION(aAddress >= SETTINGS_CONFIG_BASE_ADDRESS, rval = 0);
|
||||
otEXPECT_ACTION((aAddress - SETTINGS_CONFIG_BASE_ADDRESS + aSize) <=
|
||||
utilsFlashGetSize(), rval = 0);
|
||||
otEXPECT_ACTION(((aAddress & 3) == 0) && ((aSize & 3) == 0), rval = 0);
|
||||
|
||||
for (uint32_t i = 0; i < (aSize / sizeof(uint32_t)); i++)
|
||||
{
|
||||
*((volatile uint32_t *)aAddress) = *((uint32_t *)aData);
|
||||
aData += sizeof(uint32_t);
|
||||
aAddress += sizeof(uint32_t);
|
||||
}
|
||||
|
||||
// check if write page command is required
|
||||
if ((aAddress) & (NVMCTRL_PAGE_SIZE - 1))
|
||||
{
|
||||
enum status_code status;
|
||||
|
||||
status = nvm_execute_command(NVM_COMMAND_WRITE_PAGE,
|
||||
aAddress & (~(NVMCTRL_PAGE_SIZE - 1)), 0);
|
||||
|
||||
otEXPECT_ACTION(status == STATUS_OK, rval = 0);
|
||||
}
|
||||
|
||||
exit:
|
||||
return rval;
|
||||
}
|
||||
|
||||
uint32_t utilsFlashRead(uint32_t aAddress, uint8_t *aData, uint32_t aSize)
|
||||
{
|
||||
uint32_t rval = aSize;
|
||||
|
||||
otEXPECT_ACTION(aData, rval = 0);
|
||||
otEXPECT_ACTION(aAddress >= SETTINGS_CONFIG_BASE_ADDRESS, rval = 0);
|
||||
otEXPECT_ACTION((aAddress - SETTINGS_CONFIG_BASE_ADDRESS + aSize) <=
|
||||
utilsFlashGetSize(), rval = 0);
|
||||
|
||||
while (aSize--)
|
||||
{
|
||||
*aData++ = (*(uint8_t *)(aAddress++));
|
||||
}
|
||||
|
||||
exit:
|
||||
return rval;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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/cli.h>
|
||||
#include <openthread/platform/logging.h>
|
||||
|
||||
#if (OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT == 0)
|
||||
|
||||
void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...)
|
||||
{
|
||||
(void)aLogLevel;
|
||||
(void)aLogRegion;
|
||||
(void)aFormat;
|
||||
}
|
||||
|
||||
#endif // (OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT == 0)
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* 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 miscellaneous behaviors.
|
||||
*/
|
||||
|
||||
#include "asf.h"
|
||||
|
||||
#include <openthread/platform/misc.h>
|
||||
|
||||
void otPlatReset(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
|
||||
system_reset();
|
||||
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
otPlatResetReason otPlatGetResetReason(otInstance *aInstance)
|
||||
{
|
||||
otPlatResetReason reason;
|
||||
|
||||
switch (system_get_reset_cause())
|
||||
{
|
||||
/** The system was last reset by a software reset */
|
||||
case SYSTEM_RESET_CAUSE_SOFTWARE:
|
||||
reason = OT_PLAT_RESET_REASON_SOFTWARE;
|
||||
break;
|
||||
|
||||
/** The system was last reset by the watchdog timer */
|
||||
case SYSTEM_RESET_CAUSE_WDT:
|
||||
reason = OT_PLAT_RESET_REASON_WATCHDOG;
|
||||
break;
|
||||
|
||||
/** The system was last reset because the external reset
|
||||
line was pulled low */
|
||||
case SYSTEM_RESET_CAUSE_EXTERNAL_RESET:
|
||||
reason = OT_PLAT_RESET_REASON_EXTERNAL;
|
||||
break;
|
||||
|
||||
/** The system was last reset by the BOD33 */
|
||||
case SYSTEM_RESET_CAUSE_BOD33:
|
||||
|
||||
// no break: same reason as below
|
||||
|
||||
/** The system was last reset by the BOD12 */
|
||||
case SYSTEM_RESET_CAUSE_BOD12:
|
||||
reason = OT_PLAT_RESET_REASON_FAULT;
|
||||
break;
|
||||
|
||||
/** The system was last reset by the POR (Power on reset) */
|
||||
case SYSTEM_RESET_CAUSE_POR:
|
||||
reason = OT_PLAT_RESET_REASON_POWER_ON;
|
||||
break;
|
||||
|
||||
default:
|
||||
reason = OT_PLAT_RESET_REASON_UNKNOWN;
|
||||
break;
|
||||
}
|
||||
|
||||
return reason;
|
||||
}
|
||||
|
||||
void otPlatWakeHost(void)
|
||||
{
|
||||
// TODO: implement an operation to wake the host from sleep state.
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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 samr21 compile-time configuration constants
|
||||
* for OpenThread.
|
||||
*/
|
||||
|
||||
#ifndef OPENTHREAD_CORE_SAMR21_CONFIG_H_
|
||||
#define OPENTHREAD_CORE_SAMR21_CONFIG_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
extern uint32_t __d_nv_mem_start;
|
||||
extern uint32_t __d_nv_mem_end;
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_PLATFORM_INFO
|
||||
*
|
||||
* The platform-specific string to insert into the OpenThread version string.
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_CONFIG_PLATFORM_INFO "SAMR21"
|
||||
|
||||
/**
|
||||
* @def SETTINGS_CONFIG_BASE_ADDRESS
|
||||
*
|
||||
* The base address of settings.
|
||||
*
|
||||
*/
|
||||
#define SETTINGS_CONFIG_BASE_ADDRESS ((uint32_t)&__d_nv_mem_start)
|
||||
|
||||
/**
|
||||
* @def SETTINGS_CONFIG_PAGE_SIZE
|
||||
*
|
||||
* The page size of settings.
|
||||
*
|
||||
*/
|
||||
#define SETTINGS_CONFIG_PAGE_SIZE 0x100
|
||||
|
||||
/**
|
||||
* @def SETTINGS_CONFIG_PAGE_NUM
|
||||
*
|
||||
* The page number of settings.
|
||||
*
|
||||
*/
|
||||
#define SETTINGS_CONFIG_PAGE_NUM (((uint32_t)&__d_nv_mem_end - (uint32_t)&__d_nv_mem_start) / SETTINGS_CONFIG_PAGE_SIZE)
|
||||
|
||||
/**
|
||||
* @def RADIO_CONFIG_SRC_MATCH_ENTRY_NUM
|
||||
*
|
||||
* The number of source address table entries.
|
||||
*
|
||||
*/
|
||||
#define RADIO_CONFIG_SRC_MATCH_ENTRY_NUM 128
|
||||
|
||||
/**
|
||||
* @def OPENTHREAD_CONFIG_DEFAULT_MAX_TRANSMIT_POWER
|
||||
*
|
||||
* The default IEEE 802.15.4 maximum transmit power (dBm)
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_CONFIG_DEFAULT_MAX_TRANSMIT_POWER 5
|
||||
|
||||
|
||||
#endif // OPENTHREAD_CORE_SAMR21_CONFIG_H_
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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_SAMR21_H_
|
||||
#define PLATFORM_SAMR21_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "openthread/types.h"
|
||||
|
||||
// Global OpenThread instance structure
|
||||
extern otInstance *sInstance;
|
||||
|
||||
/**
|
||||
* This function initializes the alarm service used by OpenThread.
|
||||
*
|
||||
*/
|
||||
void samr21AlarmInit(void);
|
||||
|
||||
/**
|
||||
* This function performs alarm driver processing.
|
||||
*
|
||||
* @param[in] aInstance The OpenThread instance structure.
|
||||
*
|
||||
*/
|
||||
void samr21AlarmProcess(otInstance *aInstance);
|
||||
|
||||
/**
|
||||
* This function initializes the radio service used by OpenThread.
|
||||
*
|
||||
*/
|
||||
void samr21RadioInit(void);
|
||||
|
||||
/**
|
||||
* This function performs radio driver processing.
|
||||
*
|
||||
* @param[in] aInstance The OpenThread instance structure.
|
||||
*
|
||||
*/
|
||||
void samr21RadioProcess(otInstance *aInstance);
|
||||
|
||||
/**
|
||||
* This function returns 32-bits random value.
|
||||
*
|
||||
*/
|
||||
uint32_t samr21RadioRandomGet(void);
|
||||
|
||||
/**
|
||||
* This function returns random value sequence.
|
||||
*
|
||||
*/
|
||||
void samr21RadioRandomGetTrue(uint8_t *aOutput, uint16_t aOutputLength);
|
||||
|
||||
/**
|
||||
* This function initializes the random number service used by OpenThread.
|
||||
*
|
||||
*/
|
||||
void samr21RandomInit(void);
|
||||
|
||||
/**
|
||||
* This function performs UART driver processing.
|
||||
*
|
||||
*/
|
||||
void samr21UartProcess(void);
|
||||
|
||||
/**
|
||||
* This function returns platform IEEE EUI-64.
|
||||
*
|
||||
*/
|
||||
void samr21GetIeeeEui64(otInstance *aInstance, uint8_t *aIeeeEui64);
|
||||
|
||||
#endif // PLATFORM_SAMR21_H_
|
||||
@@ -0,0 +1,191 @@
|
||||
/*
|
||||
* 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 "asf.h"
|
||||
|
||||
#include <openthread/platform/platform.h>
|
||||
|
||||
#include "platform-samr21.h"
|
||||
|
||||
#include "utils/code_utils.h"
|
||||
|
||||
#ifdef CONF_USER_ROW_EXIST
|
||||
|
||||
#include "user_row.h"
|
||||
|
||||
samr21UserRow *sUserRow = (samr21UserRow *)SAMR21_USER_ROW;
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef CONF_KIT_DATA_EXIST
|
||||
|
||||
#define EDBG_ADDRESS 0x28
|
||||
|
||||
#define EDBG_KIT_DATA_TOKEN 0xD2;
|
||||
|
||||
#define KIT_DATA_MAX_RETRY 1000
|
||||
|
||||
static uint8_t sIeeeEui64[OT_EXT_ADDRESS_SIZE];
|
||||
|
||||
struct i2c_master_module sI2cMasterInstance;
|
||||
|
||||
static void configureI2cMaster()
|
||||
{
|
||||
/* Create and initialize config structure */
|
||||
struct i2c_master_config configI2c;
|
||||
i2c_master_get_config_defaults(&configI2c);
|
||||
|
||||
/* Change pins */
|
||||
configI2c.pinmux_pad0 = EDBG_I2C_SERCOM_PINMUX_PAD0;
|
||||
configI2c.pinmux_pad1 = EDBG_I2C_SERCOM_PINMUX_PAD1;
|
||||
|
||||
/* Initialize and enable device with config */
|
||||
i2c_master_init(&sI2cMasterInstance, EDBG_I2C_MODULE, &configI2c);
|
||||
|
||||
i2c_master_enable(&sI2cMasterInstance);
|
||||
}
|
||||
|
||||
static void getKitData()
|
||||
{
|
||||
uint8_t requestToken = EDBG_KIT_DATA_TOKEN;
|
||||
uint32_t timeout;
|
||||
struct i2c_master_packet masterPacket;
|
||||
|
||||
/** Send the request token */
|
||||
masterPacket.address = EDBG_ADDRESS;
|
||||
masterPacket.data_length = 1;
|
||||
masterPacket.data = &requestToken;
|
||||
masterPacket.ten_bit_address = false;
|
||||
masterPacket.high_speed = false;
|
||||
masterPacket.hs_master_code = 0x0;
|
||||
|
||||
timeout = 0;
|
||||
|
||||
while (i2c_master_write_packet_wait_no_stop(&sI2cMasterInstance, &masterPacket) !=
|
||||
STATUS_OK)
|
||||
{
|
||||
/* Increment timeout counter and check if timed out. */
|
||||
otEXPECT(timeout++ < KIT_DATA_MAX_RETRY);
|
||||
}
|
||||
|
||||
/** Get the extension boards info */
|
||||
masterPacket.data_length = OT_EXT_ADDRESS_SIZE;
|
||||
masterPacket.data = sIeeeEui64;
|
||||
|
||||
timeout = 0;
|
||||
|
||||
while (i2c_master_read_packet_wait(&sI2cMasterInstance, &masterPacket) !=
|
||||
STATUS_OK)
|
||||
{
|
||||
/* Increment timeout counter and check if timed out. */
|
||||
otEXPECT(timeout++ < KIT_DATA_MAX_RETRY);
|
||||
}
|
||||
|
||||
exit:
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
otInstance *sInstance;
|
||||
|
||||
void boardInit(void)
|
||||
{
|
||||
struct port_config pin_conf;
|
||||
|
||||
port_get_config_defaults(&pin_conf);
|
||||
pin_conf.direction = PORT_PIN_DIR_OUTPUT;
|
||||
port_pin_set_config(AT86RFX_SPI_SCK, &pin_conf);
|
||||
port_pin_set_config(AT86RFX_SPI_MOSI, &pin_conf);
|
||||
port_pin_set_config(AT86RFX_SPI_CS, &pin_conf);
|
||||
port_pin_set_config(AT86RFX_RST_PIN, &pin_conf);
|
||||
port_pin_set_config(AT86RFX_SLP_PIN, &pin_conf);
|
||||
port_pin_set_output_level(AT86RFX_SPI_SCK, true);
|
||||
port_pin_set_output_level(AT86RFX_SPI_MOSI, true);
|
||||
port_pin_set_output_level(AT86RFX_SPI_CS, true);
|
||||
port_pin_set_output_level(AT86RFX_RST_PIN, true);
|
||||
port_pin_set_output_level(AT86RFX_SLP_PIN, true);
|
||||
|
||||
pin_conf.direction = PORT_PIN_DIR_INPUT;
|
||||
port_pin_set_config(AT86RFX_SPI_MISO, &pin_conf);
|
||||
}
|
||||
|
||||
void samr21GetIeeeEui64(otInstance *aInstance, uint8_t *aIeeeEui64)
|
||||
{
|
||||
#if defined(CONF_KIT_DATA_EXIST)
|
||||
|
||||
memcpy(aIeeeEui64, sIeeeEui64, OT_EXT_ADDRESS_SIZE);
|
||||
|
||||
#elif defined(CONF_USER_ROW_EXIST)
|
||||
|
||||
for (uint8_t i = 0; i < OT_EXT_ADDRESS_SIZE; i++)
|
||||
{
|
||||
aIeeeEui64[i] = sUserRow->mMacAddress[OT_EXT_ADDRESS_SIZE - i - 1];
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#error Platform IEEE EUI-64 shall be provided
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void PlatformInit(int argc, char *argv[])
|
||||
{
|
||||
system_clock_init();
|
||||
|
||||
boardInit();
|
||||
|
||||
#ifdef CONF_KIT_DATA_EXIST
|
||||
configureI2cMaster();
|
||||
getKitData();
|
||||
#endif
|
||||
|
||||
samr21AlarmInit();
|
||||
samr21RadioInit();
|
||||
}
|
||||
|
||||
void PlatformDeinit(void)
|
||||
{
|
||||
}
|
||||
|
||||
void PlatformProcessDrivers(otInstance *aInstance)
|
||||
{
|
||||
sInstance = aInstance;
|
||||
|
||||
samr21UartProcess();
|
||||
samr21AlarmProcess(aInstance);
|
||||
samr21RadioProcess(aInstance);
|
||||
}
|
||||
@@ -0,0 +1,633 @@
|
||||
/*
|
||||
* 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 "asf.h"
|
||||
#include "phy.h"
|
||||
|
||||
#include <openthread/config.h>
|
||||
#include <openthread/platform/alarm-milli.h>
|
||||
#include <openthread/platform/radio.h>
|
||||
|
||||
#include "platform-samr21.h"
|
||||
|
||||
#include "common/logging.hpp"
|
||||
#include "utils/code_utils.h"
|
||||
|
||||
enum
|
||||
{
|
||||
IEEE802154_ACK_LENGTH = 5,
|
||||
IEEE802154_FCS_SIZE = 2
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
SAMR21_RECEIVE_SENSITIVITY = -99 // dBm
|
||||
};
|
||||
|
||||
static otRadioFrame sTransmitFrame;
|
||||
static uint8_t sTransmitPsdu[OT_RADIO_FRAME_MAX_SIZE];
|
||||
|
||||
static otRadioFrame sReceiveFrame;
|
||||
|
||||
static bool sSleep = false;
|
||||
static bool sRxEnable = false;
|
||||
static bool sTxDone = false;
|
||||
static bool sRxDone = false;
|
||||
static otError sTxStatus = OT_ERROR_NONE;
|
||||
static int8_t sPower = OPENTHREAD_CONFIG_DEFAULT_MAX_TRANSMIT_POWER;
|
||||
static otRadioState sState = OT_RADIO_STATE_DISABLED;
|
||||
static bool sPromiscuous = false;
|
||||
static uint8_t sChannel = 0xFF;
|
||||
|
||||
static int8_t sMaxRssi;
|
||||
static uint32_t sScanStartTime;
|
||||
static uint16_t sScanDuration;
|
||||
static bool sStartScan = false;
|
||||
|
||||
static int8_t sTxPowerTable[] =
|
||||
{
|
||||
4,
|
||||
4,
|
||||
3,
|
||||
3,
|
||||
3,
|
||||
2,
|
||||
1,
|
||||
0,
|
||||
-1,
|
||||
-2,
|
||||
-3,
|
||||
-4,
|
||||
-6,
|
||||
-8,
|
||||
-12,
|
||||
-17
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
* Static
|
||||
******************************************************************************/
|
||||
|
||||
static void radioSleep()
|
||||
{
|
||||
if (!sSleep)
|
||||
{
|
||||
PHY_SetRxState(false);
|
||||
PHY_Sleep();
|
||||
|
||||
sSleep = true;
|
||||
sRxEnable = false;
|
||||
}
|
||||
}
|
||||
|
||||
static void radioWakeup()
|
||||
{
|
||||
if (sSleep)
|
||||
{
|
||||
PHY_Wakeup();
|
||||
}
|
||||
}
|
||||
|
||||
static void radioRxEnable()
|
||||
{
|
||||
if (sSleep)
|
||||
{
|
||||
PHY_Wakeup();
|
||||
|
||||
sSleep = false;
|
||||
}
|
||||
|
||||
if (!sRxEnable)
|
||||
{
|
||||
PHY_SetRxState(true);
|
||||
|
||||
sRxEnable = true;
|
||||
}
|
||||
}
|
||||
|
||||
static void radioTrxOff()
|
||||
{
|
||||
if (sSleep)
|
||||
{
|
||||
PHY_Wakeup();
|
||||
}
|
||||
else if (sRxEnable)
|
||||
{
|
||||
PHY_SetRxState(false);
|
||||
}
|
||||
}
|
||||
|
||||
static void radioRestore()
|
||||
{
|
||||
if (sSleep)
|
||||
{
|
||||
PHY_Sleep();
|
||||
}
|
||||
else if (sRxEnable)
|
||||
{
|
||||
PHY_SetRxState(true);
|
||||
}
|
||||
}
|
||||
|
||||
static void setTxPower(uint8_t aPower)
|
||||
{
|
||||
if (aPower != sPower)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < (sizeof(sTxPowerTable) / sizeof(*sTxPowerTable) - 1); i++)
|
||||
{
|
||||
if (aPower >= sTxPowerTable[i])
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
otLogDebgPlat(sInstance, "Radio set tx power: %d, %d", aPower, i);
|
||||
|
||||
radioTrxOff();
|
||||
|
||||
PHY_SetTxPower(i);
|
||||
|
||||
radioRestore();
|
||||
|
||||
sPower = aPower;
|
||||
}
|
||||
}
|
||||
|
||||
static void setChannel(uint8_t aChannel)
|
||||
{
|
||||
if (aChannel != sChannel)
|
||||
{
|
||||
otLogDebgPlat(sInstance, "Radio set channel: %d", aChannel);
|
||||
|
||||
radioTrxOff();
|
||||
|
||||
PHY_SetChannel(aChannel);
|
||||
|
||||
radioRestore();
|
||||
|
||||
sChannel = aChannel;
|
||||
}
|
||||
}
|
||||
|
||||
static void handleEnergyScan()
|
||||
{
|
||||
if (sStartScan)
|
||||
{
|
||||
if ((otPlatAlarmMilliGetNow() - sScanStartTime) < sScanDuration)
|
||||
{
|
||||
int8_t curRssi = PHY_EdReq();
|
||||
|
||||
if (curRssi > sMaxRssi)
|
||||
{
|
||||
sMaxRssi = curRssi;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sStartScan = false;
|
||||
|
||||
otPlatRadioEnergyScanDone(sInstance, sMaxRssi);
|
||||
|
||||
radioRestore();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void handleRx(void)
|
||||
{
|
||||
if (sRxDone)
|
||||
{
|
||||
sRxDone = false;
|
||||
|
||||
#if OPENTHREAD_ENABLE_RAW_LINK_API
|
||||
// Timestamp
|
||||
sReceiveFrame.mMsec = otPlatAlarmMilliGetNow();
|
||||
sReceiveFrame.mUsec = 0; // Don't support microsecond timer for now.
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_ENABLE_DIAG
|
||||
|
||||
if (otPlatDiagModeGet())
|
||||
{
|
||||
otPlatDiagRadioReceiveDone(sInstance, &sReceiveFrame, OT_ERROR_NONE);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
// signal MAC layer for each received frame if promiscous is enabled
|
||||
// otherwise only signal MAC layer for non-ACK frame
|
||||
if (sPromiscuous || sReceiveFrame.mLength > IEEE802154_ACK_LENGTH)
|
||||
{
|
||||
otLogDebgPlat(sInstance, "Radio receive done, rssi: %d",
|
||||
sReceiveFrame.mPower);
|
||||
|
||||
otPlatRadioReceiveDone(sInstance, &sReceiveFrame, OT_ERROR_NONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void handleTx(void)
|
||||
{
|
||||
if (sTxDone)
|
||||
{
|
||||
sTxDone = false;
|
||||
|
||||
#if OPENTHREAD_ENABLE_DIAG
|
||||
|
||||
if (otPlatDiagModeGet())
|
||||
{
|
||||
otPlatDiagRadioTransmitDone(sInstance, &sTransmitFrame, sTxStatus);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
otLogDebgPlat(sInstance, "Radio transmit done, status: %d",
|
||||
sTxStatus);
|
||||
|
||||
otPlatRadioTxDone(sInstance, &sTransmitFrame, NULL, sTxStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* PHY
|
||||
******************************************************************************/
|
||||
|
||||
void PHY_DataInd(PHY_DataInd_t *ind)
|
||||
{
|
||||
sReceiveFrame.mPsdu = ind->data;
|
||||
sReceiveFrame.mLength = ind->size + IEEE802154_FCS_SIZE;
|
||||
sReceiveFrame.mPower = ind->rssi;
|
||||
|
||||
sRxDone = true;
|
||||
}
|
||||
|
||||
void PHY_DataConf(uint8_t status)
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
case PHY_STATUS_SUCCESS:
|
||||
sTxStatus = OT_ERROR_NONE;
|
||||
break;
|
||||
|
||||
case PHY_STATUS_CHANNEL_ACCESS_FAILURE:
|
||||
sTxStatus = OT_ERROR_CHANNEL_ACCESS_FAILURE;
|
||||
break;
|
||||
|
||||
case PHY_STATUS_NO_ACK:
|
||||
sTxStatus = OT_ERROR_NO_ACK;
|
||||
break;
|
||||
|
||||
default:
|
||||
sTxStatus = OT_ERROR_ABORT;
|
||||
break;
|
||||
}
|
||||
|
||||
sTxDone = true;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Platform
|
||||
******************************************************************************/
|
||||
void samr21RadioInit(void)
|
||||
{
|
||||
sTransmitFrame.mLength = 0;
|
||||
sTransmitFrame.mPsdu = sTransmitPsdu;
|
||||
|
||||
sReceiveFrame.mLength = 0;
|
||||
sReceiveFrame.mPsdu = NULL;
|
||||
|
||||
PHY_Init();
|
||||
}
|
||||
|
||||
void samr21RadioProcess(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
|
||||
PHY_TaskHandler();
|
||||
|
||||
handleEnergyScan();
|
||||
handleRx();
|
||||
handleTx();
|
||||
}
|
||||
|
||||
uint32_t samr21RadioRandomGet(void)
|
||||
{
|
||||
uint32_t result;
|
||||
|
||||
radioWakeup();
|
||||
|
||||
result = PHY_RandomReq() << 16 | PHY_RandomReq();
|
||||
|
||||
radioRestore();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void samr21RadioRandomGetTrue(uint8_t *aOutput, uint16_t aOutputLength)
|
||||
{
|
||||
radioWakeup();
|
||||
|
||||
for (uint16_t i = 0; i < aOutputLength / sizeof(uint16_t); i++)
|
||||
{
|
||||
*((uint16_t *)aOutput) = PHY_RandomReq();
|
||||
aOutput += sizeof(uint16_t);
|
||||
}
|
||||
|
||||
for (uint16_t i = 0; i < aOutputLength % sizeof(uint16_t); i++)
|
||||
{
|
||||
aOutput[i] = PHY_RandomReq();
|
||||
}
|
||||
|
||||
radioRestore();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Radio
|
||||
******************************************************************************/
|
||||
otRadioState otPlatRadioGetState(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
|
||||
return sState;
|
||||
}
|
||||
|
||||
void otPlatRadioGetIeeeEui64(otInstance *aInstance, uint8_t *aIeeeEui64)
|
||||
{
|
||||
samr21GetIeeeEui64(aInstance, aIeeeEui64);
|
||||
}
|
||||
|
||||
void otPlatRadioSetPanId(otInstance *aInstance, uint16_t aPanId)
|
||||
{
|
||||
(void)aInstance;
|
||||
|
||||
otLogDebgPlat(sInstance, "Set Pan ID: 0x%04X", aPanId);
|
||||
|
||||
radioTrxOff();
|
||||
|
||||
PHY_SetPanId(aPanId);
|
||||
|
||||
radioRestore();
|
||||
}
|
||||
|
||||
void otPlatRadioSetExtendedAddress(otInstance *aInstance, const otExtAddress *aAddress)
|
||||
{
|
||||
(void)aInstance;
|
||||
|
||||
radioTrxOff();
|
||||
|
||||
PHY_SetIEEEAddr((uint8_t *)aAddress);
|
||||
|
||||
radioRestore();
|
||||
}
|
||||
|
||||
void otPlatRadioSetShortAddress(otInstance *aInstance, uint16_t aAddress)
|
||||
{
|
||||
(void)aInstance;
|
||||
|
||||
radioTrxOff();
|
||||
|
||||
PHY_SetShortAddr(aAddress);
|
||||
|
||||
radioRestore();
|
||||
}
|
||||
|
||||
bool otPlatRadioIsEnabled(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
|
||||
return (sState != OT_RADIO_STATE_DISABLED);
|
||||
}
|
||||
|
||||
otError otPlatRadioEnable(otInstance *aInstance)
|
||||
{
|
||||
otLogDebgPlat(sInstance, "Radio enable");
|
||||
|
||||
if (!otPlatRadioIsEnabled(aInstance))
|
||||
{
|
||||
radioSleep();
|
||||
|
||||
sState = OT_RADIO_STATE_SLEEP;
|
||||
}
|
||||
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError otPlatRadioDisable(otInstance *aInstance)
|
||||
{
|
||||
otLogDebgPlat(sInstance, "Radio disable");
|
||||
|
||||
if (otPlatRadioIsEnabled(aInstance))
|
||||
{
|
||||
radioSleep();
|
||||
|
||||
sState = OT_RADIO_STATE_DISABLED;
|
||||
}
|
||||
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError otPlatRadioSleep(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
|
||||
otLogDebgPlat(sInstance, "Radio sleep");
|
||||
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
otEXPECT_ACTION(sState == OT_RADIO_STATE_SLEEP ||
|
||||
sState == OT_RADIO_STATE_RECEIVE,
|
||||
error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
radioSleep();
|
||||
|
||||
sState = OT_RADIO_STATE_SLEEP;
|
||||
|
||||
exit:
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel)
|
||||
{
|
||||
(void)aInstance;
|
||||
|
||||
otLogDebgPlat(sInstance, "Radio receive, channel: %d", aChannel);
|
||||
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
otEXPECT_ACTION(sState != OT_RADIO_STATE_DISABLED,
|
||||
error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
setChannel(aChannel);
|
||||
|
||||
radioRxEnable();
|
||||
|
||||
sState = OT_RADIO_STATE_RECEIVE;
|
||||
|
||||
exit:
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
otError otPlatRadioTransmit(otInstance *aInstance, otRadioFrame *aFrame)
|
||||
{
|
||||
(void)aInstance;
|
||||
|
||||
otLogDebgPlat(sInstance, "Radio transmit");
|
||||
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
otEXPECT_ACTION(sState == OT_RADIO_STATE_RECEIVE,
|
||||
error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
uint8_t frame[OT_RADIO_FRAME_MAX_SIZE + 1];
|
||||
|
||||
setChannel(aFrame->mChannel);
|
||||
setTxPower(aFrame->mPower);
|
||||
|
||||
frame[0] = aFrame->mLength - IEEE802154_FCS_SIZE;
|
||||
memcpy(frame + 1, aFrame->mPsdu, aFrame->mLength);
|
||||
|
||||
PHY_DataReq(frame);
|
||||
|
||||
otPlatRadioTxStarted(aInstance, aFrame);
|
||||
|
||||
sState = OT_RADIO_STATE_TRANSMIT;
|
||||
|
||||
exit:
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
otRadioFrame *otPlatRadioGetTransmitBuffer(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
|
||||
return &sTransmitFrame;
|
||||
}
|
||||
|
||||
int8_t otPlatRadioGetRssi(otInstance *aInstance)
|
||||
{
|
||||
return sMaxRssi;
|
||||
}
|
||||
|
||||
otRadioCaps otPlatRadioGetCaps(otInstance *aInstance)
|
||||
{
|
||||
return OT_RADIO_CAPS_ENERGY_SCAN | OT_RADIO_CAPS_TRANSMIT_RETRIES |
|
||||
OT_RADIO_CAPS_ACK_TIMEOUT;
|
||||
}
|
||||
|
||||
bool otPlatRadioGetPromiscuous(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
|
||||
return sPromiscuous;
|
||||
}
|
||||
|
||||
void otPlatRadioSetPromiscuous(otInstance *aInstance, bool aEnable)
|
||||
{
|
||||
(void)aInstance;
|
||||
|
||||
sPromiscuous = aEnable;
|
||||
}
|
||||
|
||||
void otPlatRadioEnableSrcMatch(otInstance *aInstance, bool aEnable)
|
||||
{
|
||||
(void)aInstance;
|
||||
(void)aEnable;
|
||||
}
|
||||
|
||||
otError otPlatRadioAddSrcMatchShortEntry(otInstance *aInstance, const uint16_t aShortAddress)
|
||||
{
|
||||
return OT_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
otError otPlatRadioAddSrcMatchExtEntry(otInstance *aInstance, const otExtAddress *aExtAddress)
|
||||
{
|
||||
return OT_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
otError otPlatRadioClearSrcMatchShortEntry(otInstance *aInstance, const uint16_t aShortAddress)
|
||||
{
|
||||
return OT_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
otError otPlatRadioClearSrcMatchExtEntry(otInstance *aInstance, const otExtAddress *aExtAddress)
|
||||
{
|
||||
return OT_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
void otPlatRadioClearSrcMatchShortEntries(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
}
|
||||
|
||||
void otPlatRadioClearSrcMatchExtEntries(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
}
|
||||
|
||||
otError otPlatRadioEnergyScan(otInstance *aInstance, uint8_t aScanChannel, uint16_t aScanDuration)
|
||||
{
|
||||
(void)aInstance;
|
||||
|
||||
sScanStartTime = otPlatAlarmMilliGetNow();
|
||||
sScanDuration = aScanDuration;
|
||||
|
||||
sMaxRssi = PHY_EdReq();
|
||||
|
||||
sStartScan = true;
|
||||
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
void otPlatRadioSetDefaultTxPower(otInstance *aInstance, int8_t aPower)
|
||||
{
|
||||
(void)aInstance;
|
||||
|
||||
otLogDebgPlat(sInstance, "Radio set default TX power: %d", aPower);
|
||||
|
||||
setTxPower(aPower);
|
||||
}
|
||||
|
||||
int8_t otPlatRadioGetReceiveSensitivity(otInstance *aInstance)
|
||||
{
|
||||
(void)aInstance;
|
||||
|
||||
return SAMR21_RECEIVE_SENSITIVITY;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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 random number generator.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "phy.h"
|
||||
#include "platform-samr21.h"
|
||||
#include <openthread/platform/radio.h>
|
||||
#include <openthread/platform/random.h>
|
||||
|
||||
uint32_t otPlatRandomGet(void)
|
||||
{
|
||||
return samr21RadioRandomGet();
|
||||
}
|
||||
|
||||
otError otPlatRandomGetTrue(uint8_t *aOutput, uint16_t aOutputLength)
|
||||
{
|
||||
samr21RadioRandomGetTrue(aOutput, aOutputLength);
|
||||
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
@@ -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 "asf.h"
|
||||
|
||||
#include <openthread/platform/uart.h>
|
||||
|
||||
enum
|
||||
{
|
||||
kBaudRate = 115200,
|
||||
kReceiveBufferSize = 128,
|
||||
};
|
||||
|
||||
typedef struct RecvBuffer
|
||||
{
|
||||
// The data buffer
|
||||
uint8_t mBuffer[kReceiveBufferSize];
|
||||
// The offset of the first item written to the list.
|
||||
uint16_t mHead;
|
||||
// The offset of the next item to be written to the list.
|
||||
uint16_t mTail;
|
||||
} RecvBuffer;
|
||||
|
||||
static struct usart_module sUsartInstance;
|
||||
|
||||
static RecvBuffer sReceive;
|
||||
|
||||
static bool sTransmitDone = false;
|
||||
|
||||
static void usartReadCallback(struct usart_module *const usartModule)
|
||||
{
|
||||
if (sReceive.mHead != (sReceive.mTail + 1) % kReceiveBufferSize)
|
||||
{
|
||||
sReceive.mTail = (sReceive.mTail + 1) % kReceiveBufferSize;
|
||||
}
|
||||
|
||||
usart_read_job(&sUsartInstance,
|
||||
(uint16_t *)&sReceive.mBuffer[sReceive.mTail]);
|
||||
}
|
||||
|
||||
static void usartWriteCallback(struct usart_module *const usartModule)
|
||||
{
|
||||
sTransmitDone = true;
|
||||
}
|
||||
|
||||
static void processReceive(void)
|
||||
{
|
||||
// Copy tail to prevent multiple reads
|
||||
uint16_t tail = sReceive.mTail;
|
||||
|
||||
// If the data wraps around, process the first part
|
||||
if (sReceive.mHead > tail)
|
||||
{
|
||||
otPlatUartReceived(sReceive.mBuffer + sReceive.mHead, kReceiveBufferSize - sReceive.mHead);
|
||||
|
||||
// Reset the buffer mHead back to zero.
|
||||
sReceive.mHead = 0;
|
||||
}
|
||||
|
||||
// For any data remaining, process it
|
||||
if (sReceive.mHead != tail)
|
||||
{
|
||||
otPlatUartReceived(sReceive.mBuffer + sReceive.mHead, tail - sReceive.mHead);
|
||||
|
||||
// Set mHead to the local tail we have cached
|
||||
sReceive.mHead = tail;
|
||||
}
|
||||
}
|
||||
|
||||
static void processTransmit(void)
|
||||
{
|
||||
if (sTransmitDone)
|
||||
{
|
||||
sTransmitDone = false;
|
||||
otPlatUartSendDone();
|
||||
}
|
||||
}
|
||||
|
||||
void samr21UartProcess(void)
|
||||
{
|
||||
processReceive();
|
||||
processTransmit();
|
||||
}
|
||||
|
||||
otError otPlatUartEnable(void)
|
||||
{
|
||||
struct usart_config configUsart;
|
||||
|
||||
usart_get_config_defaults(&configUsart);
|
||||
|
||||
configUsart.baudrate = 115200;
|
||||
configUsart.mux_setting = UART_SERCOM_MUX_SETTING;
|
||||
configUsart.pinmux_pad0 = UART_SERCOM_PINMUX_PAD0;
|
||||
configUsart.pinmux_pad1 = UART_SERCOM_PINMUX_PAD1;
|
||||
configUsart.pinmux_pad2 = UART_SERCOM_PINMUX_PAD2;
|
||||
configUsart.pinmux_pad3 = UART_SERCOM_PINMUX_PAD3;
|
||||
|
||||
while (usart_init(&sUsartInstance, UART_SERCOM_MODULE, &configUsart)
|
||||
!= STATUS_OK);
|
||||
|
||||
usart_enable(&sUsartInstance);
|
||||
|
||||
sReceive.mHead = 0;
|
||||
sReceive.mTail = 0;
|
||||
|
||||
usart_register_callback(&sUsartInstance, usartWriteCallback,
|
||||
USART_CALLBACK_BUFFER_TRANSMITTED);
|
||||
usart_register_callback(&sUsartInstance, usartReadCallback,
|
||||
USART_CALLBACK_BUFFER_RECEIVED);
|
||||
|
||||
usart_enable_callback(&sUsartInstance, USART_CALLBACK_BUFFER_TRANSMITTED);
|
||||
usart_enable_callback(&sUsartInstance, USART_CALLBACK_BUFFER_RECEIVED);
|
||||
|
||||
usart_read_job(&sUsartInstance,
|
||||
(uint16_t *)&sReceive.mBuffer[sReceive.mTail]);
|
||||
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError otPlatUartDisable(void)
|
||||
{
|
||||
usart_disable(&sUsartInstance);
|
||||
|
||||
return OT_ERROR_NONE;
|
||||
}
|
||||
|
||||
otError otPlatUartSend(const uint8_t *aBuf, uint16_t aBufLength)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (usart_write_buffer_job(&sUsartInstance, (uint8_t *)aBuf,
|
||||
aBufLength) != STATUS_OK)
|
||||
{
|
||||
error = OT_ERROR_FAILED;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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 USER_ROW_H_
|
||||
#define USER_ROW_H_
|
||||
|
||||
// The SAM R21 provides a user readable Non-Volatile Memory (NVM) space
|
||||
// referred to as the user row in the data sheet.
|
||||
// The base address for the application is 0x804008.
|
||||
#define SAMR21_USER_ROW 0x804008
|
||||
|
||||
// User row structure
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
struct samr21UserRow
|
||||
{
|
||||
uint16_t mRevision;
|
||||
uint8_t mMacAddress[8];
|
||||
uint8_t mBoardSerial[10];
|
||||
uint8_t mPartNumber[8];
|
||||
uint8_t mPcbRevision;
|
||||
uint8_t mCrystalCal;
|
||||
uint16_t mCrc16;
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
typedef struct samr21UserRow samr21UserRow;
|
||||
|
||||
#endif /* USER_ROW_H_ */
|
||||
Vendored
+43
@@ -0,0 +1,43 @@
|
||||
# Microchip
|
||||
|
||||
URL: http://www.microchip.com/
|
||||
|
||||
ASF URL: http://www.microchip.com/avr-support/advanced-software-framework-(asf)
|
||||
|
||||
Version: 3.36.0
|
||||
|
||||
## License
|
||||
|
||||
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. The name of Atmel may not be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
4. This software may only be redistributed and used in connection with an
|
||||
Atmel microcontroller product.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
|
||||
## Description
|
||||
|
||||
This folder contains modified ASF include headers which configure SAMR21
|
||||
XPLAINED PRO board. In order to compile openthread for SAMR21 ASF shell
|
||||
be downloaded into asf folder.
|
||||
Vendored
+112
@@ -0,0 +1,112 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief Autogenerated API include file for the Atmel Software Framework (ASF)
|
||||
*
|
||||
* Copyright (c) 2012 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* \asf_license_start
|
||||
*
|
||||
* \page License
|
||||
*
|
||||
* 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. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an
|
||||
* Atmel microcontroller product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
*
|
||||
* \asf_license_stop
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ASF_H
|
||||
#define ASF_H
|
||||
|
||||
/*
|
||||
* This file includes all API header files for the selected drivers from ASF.
|
||||
* Note: There might be duplicate includes required by more than one driver.
|
||||
*
|
||||
* The file is automatically generated and will be re-written when
|
||||
* running the ASF driver selector tool. Any changes will be discarded.
|
||||
*/
|
||||
|
||||
// From module: Common SAM0 compiler driver
|
||||
#include <compiler.h>
|
||||
#include <status_codes.h>
|
||||
|
||||
// From module: Generic board support
|
||||
#include <board.h>
|
||||
|
||||
// From module: EXTINT - External Interrupt (Callback APIs)
|
||||
#include <extint.h>
|
||||
#include <extint_callback.h>
|
||||
|
||||
// From module: Interrupt management - SAM implementation
|
||||
#include <interrupt.h>
|
||||
|
||||
// From module: NVM - Non-Volatile Memory
|
||||
#include <nvm.h>
|
||||
|
||||
// From module: PORT - GPIO Pin Control
|
||||
#include <port.h>
|
||||
|
||||
// From module: Part identification macros
|
||||
#include <parts.h>
|
||||
|
||||
// From module: SYSTEM - Clock Management for SAMD21/R21/DA/HA
|
||||
#include <clock.h>
|
||||
#include <gclk.h>
|
||||
|
||||
// From module: SERCOM Callback API
|
||||
#include <sercom.h>
|
||||
#include <sercom_interrupt.h>
|
||||
|
||||
// From module: SERCOM I2C - Master Mode I2C (Polled APIs)
|
||||
#include <i2c_common.h>
|
||||
#include <i2c_master.h>
|
||||
|
||||
// From module: SERCOM SPI - Serial Peripheral Interface (Polled APIs)
|
||||
#include <spi.h>
|
||||
|
||||
// From module: SERCOM USART - Serial Communications (Callback APIs)
|
||||
#include <usart.h>
|
||||
#include <usart_interrupt.h>
|
||||
|
||||
// From module: SYSTEM - Core System Driver
|
||||
#include <system.h>
|
||||
|
||||
// From module: SYSTEM - I/O Pin Multiplexer
|
||||
#include <pinmux.h>
|
||||
|
||||
// From module: SYSTEM - Interrupt Driver
|
||||
#include <system_interrupt.h>
|
||||
|
||||
// From module: SYSTEM - Power Management for SAM D20/D21/R21/D09/D10/D11/DA/HA
|
||||
#include <power.h>
|
||||
|
||||
// From module: SYSTEM - Reset Management for SAM D20/D21/R21/D09/D10/D11/DA/HA
|
||||
#include <reset.h>
|
||||
|
||||
#endif // ASF_H
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief SAM R21 Xplained Pro board configuration.
|
||||
*
|
||||
* Copyright (c) 2014-2015 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* \asf_license_start
|
||||
*
|
||||
* \page License
|
||||
*
|
||||
* 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. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an
|
||||
* Atmel microcontroller product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
*
|
||||
* \asf_license_stop
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#ifndef CONF_BOARD_H_INCLUDED
|
||||
#define CONF_BOARD_H_INCLUDED
|
||||
|
||||
#define CONF_BOARD_AT86RFX
|
||||
|
||||
#define AT86RFX_SPI_BAUDRATE 5000000UL
|
||||
|
||||
#if BOARD==USER_BOARD
|
||||
|
||||
#define CONF_USER_ROW_EXIST
|
||||
|
||||
#endif
|
||||
|
||||
#if BOARD==SAMR21_XPLAINED_PRO
|
||||
|
||||
#define CONF_KIT_DATA_EXIST
|
||||
|
||||
#define UART_SERCOM_MODULE EDBG_CDC_MODULE
|
||||
#define UART_SERCOM_MUX_SETTING EDBG_CDC_SERCOM_MUX_SETTING
|
||||
#define UART_SERCOM_PINMUX_PAD0 EDBG_CDC_SERCOM_PINMUX_PAD0
|
||||
#define UART_SERCOM_PINMUX_PAD1 EDBG_CDC_SERCOM_PINMUX_PAD1
|
||||
#define UART_SERCOM_PINMUX_PAD2 EDBG_CDC_SERCOM_PINMUX_PAD2
|
||||
#define UART_SERCOM_PINMUX_PAD3 EDBG_CDC_SERCOM_PINMUX_PAD3
|
||||
#define UART_SERCOM_DMAC_ID_TX EDBG_CDC_SERCOM_DMAC_ID_TX
|
||||
#define UART_SERCOM_DMAC_ID_RX EDBG_CDC_SERCOM_DMAC_ID_RX
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* CONF_BOARD_H_INCLUDED */
|
||||
+200
@@ -0,0 +1,200 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief Chip-specific system clock manager configuration
|
||||
*
|
||||
* Copyright (c) 2014-2015 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* \asf_license_start
|
||||
*
|
||||
* \page License
|
||||
*
|
||||
* 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. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an
|
||||
* Atmel microcontroller product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
*
|
||||
* \asf_license_stop
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#include <clock.h>
|
||||
|
||||
#ifndef CONF_CLOCKS_H_INCLUDED
|
||||
#define CONF_CLOCKS_H_INCLUDED
|
||||
|
||||
/* System clock bus configuration */
|
||||
#define CONF_CLOCK_CPU_CLOCK_FAILURE_DETECT false
|
||||
#define CONF_CLOCK_FLASH_WAIT_STATES 2
|
||||
#define CONF_CLOCK_CPU_DIVIDER SYSTEM_MAIN_CLOCK_DIV_1
|
||||
#define CONF_CLOCK_APBA_DIVIDER SYSTEM_MAIN_CLOCK_DIV_1
|
||||
#define CONF_CLOCK_APBB_DIVIDER SYSTEM_MAIN_CLOCK_DIV_1
|
||||
#define CONF_CLOCK_APBC_DIVIDER SYSTEM_MAIN_CLOCK_DIV_1
|
||||
|
||||
/* SYSTEM_CLOCK_SOURCE_OSC8M configuration - Internal 8MHz oscillator */
|
||||
#define CONF_CLOCK_OSC8M_PRESCALER SYSTEM_OSC8M_DIV_1
|
||||
#define CONF_CLOCK_OSC8M_ON_DEMAND false
|
||||
#define CONF_CLOCK_OSC8M_RUN_IN_STANDBY false
|
||||
|
||||
/* SYSTEM_CLOCK_SOURCE_XOSC configuration - External clock/oscillator */
|
||||
#define CONF_CLOCK_XOSC_ENABLE false
|
||||
#define CONF_CLOCK_XOSC_EXTERNAL_CRYSTAL SYSTEM_CLOCK_EXTERNAL_CRYSTAL
|
||||
#define CONF_CLOCK_XOSC_EXTERNAL_FREQUENCY 12000000UL
|
||||
#define CONF_CLOCK_XOSC_STARTUP_TIME SYSTEM_XOSC_STARTUP_32768
|
||||
#define CONF_CLOCK_XOSC_AUTO_GAIN_CONTROL true
|
||||
#define CONF_CLOCK_XOSC_ON_DEMAND true
|
||||
#define CONF_CLOCK_XOSC_RUN_IN_STANDBY false
|
||||
|
||||
/* SYSTEM_CLOCK_SOURCE_XOSC32K configuration - External 32KHz crystal/clock
|
||||
* oscillator */
|
||||
#define CONF_CLOCK_XOSC32K_ENABLE false
|
||||
#define CONF_CLOCK_XOSC32K_EXTERNAL_CRYSTAL SYSTEM_CLOCK_EXTERNAL_CRYSTAL
|
||||
#define CONF_CLOCK_XOSC32K_STARTUP_TIME SYSTEM_XOSC32K_STARTUP_65536
|
||||
#define CONF_CLOCK_XOSC32K_AUTO_AMPLITUDE_CONTROL true
|
||||
#define CONF_CLOCK_XOSC32K_ENABLE_1KHZ_OUPUT false
|
||||
#define CONF_CLOCK_XOSC32K_ENABLE_32KHZ_OUTPUT true
|
||||
#define CONF_CLOCK_XOSC32K_ON_DEMAND true
|
||||
#define CONF_CLOCK_XOSC32K_RUN_IN_STANDBY false
|
||||
|
||||
/* SYSTEM_CLOCK_SOURCE_OSC32K configuration - Internal 32KHz oscillator */
|
||||
#define CONF_CLOCK_OSC32K_ENABLE true
|
||||
#define CONF_CLOCK_OSC32K_STARTUP_TIME SYSTEM_OSC32K_STARTUP_130
|
||||
#define CONF_CLOCK_OSC32K_ENABLE_1KHZ_OUTPUT true
|
||||
#define CONF_CLOCK_OSC32K_ENABLE_32KHZ_OUTPUT true
|
||||
#define CONF_CLOCK_OSC32K_ON_DEMAND true
|
||||
#define CONF_CLOCK_OSC32K_RUN_IN_STANDBY true
|
||||
|
||||
/* SYSTEM_CLOCK_SOURCE_DFLL configuration - Digital Frequency Locked Loop */
|
||||
#define CONF_CLOCK_DFLL_ENABLE true
|
||||
#define CONF_CLOCK_DFLL_LOOP_MODE SYSTEM_CLOCK_DFLL_LOOP_MODE_CLOSED
|
||||
#define CONF_CLOCK_DFLL_ON_DEMAND false
|
||||
#define CONF_CLOCK_DFLL_RUN_IN_STANDBY false
|
||||
|
||||
/* DFLL open loop mode configuration */
|
||||
# define CONF_CLOCK_DFLL_FINE_VALUE (512)
|
||||
|
||||
/* DFLL closed loop mode configuration */
|
||||
#define CONF_CLOCK_DFLL_SOURCE_GCLK_GENERATOR GCLK_GENERATOR_1
|
||||
#define CONF_CLOCK_DFLL_MULTIPLY_FACTOR (48000000 / 32768)
|
||||
#define CONF_CLOCK_DFLL_QUICK_LOCK true
|
||||
#define CONF_CLOCK_DFLL_TRACK_AFTER_FINE_LOCK true
|
||||
#define CONF_CLOCK_DFLL_KEEP_LOCK_ON_WAKEUP true
|
||||
#define CONF_CLOCK_DFLL_ENABLE_CHILL_CYCLE true
|
||||
#define CONF_CLOCK_DFLL_MAX_COARSE_STEP_SIZE (0x1f / 4)
|
||||
#define CONF_CLOCK_DFLL_MAX_FINE_STEP_SIZE (0xff / 4)
|
||||
|
||||
/* SYSTEM_CLOCK_SOURCE_DPLL configuration - Digital Phase-Locked Loop */
|
||||
#define CONF_CLOCK_DPLL_ENABLE false
|
||||
#define CONF_CLOCK_DPLL_ON_DEMAND true
|
||||
#define CONF_CLOCK_DPLL_RUN_IN_STANDBY false
|
||||
#define CONF_CLOCK_DPLL_LOCK_BYPASS false
|
||||
#define CONF_CLOCK_DPLL_WAKE_UP_FAST false
|
||||
#define CONF_CLOCK_DPLL_LOW_POWER_ENABLE false
|
||||
|
||||
#define CONF_CLOCK_DPLL_LOCK_TIME SYSTEM_CLOCK_SOURCE_DPLL_LOCK_TIME_DEFAULT
|
||||
#define CONF_CLOCK_DPLL_REFERENCE_CLOCK SYSTEM_CLOCK_SOURCE_DPLL_REFERENCE_CLOCK_XOSC32K
|
||||
#define CONF_CLOCK_DPLL_FILTER SYSTEM_CLOCK_SOURCE_DPLL_FILTER_DEFAULT
|
||||
|
||||
#define CONF_CLOCK_DPLL_REFERENCE_FREQUENCY 32768
|
||||
#define CONF_CLOCK_DPLL_REFERENCE_DIVIDER 1
|
||||
#define CONF_CLOCK_DPLL_OUTPUT_FREQUENCY 48000000
|
||||
|
||||
/* DPLL GCLK reference configuration */
|
||||
#define CONF_CLOCK_DPLL_REFERENCE_GCLK_GENERATOR GCLK_GENERATOR_1
|
||||
/* DPLL GCLK lock timer configuration */
|
||||
#define CONF_CLOCK_DPLL_LOCK_GCLK_GENERATOR GCLK_GENERATOR_1
|
||||
|
||||
/* Set this to true to configure the GCLK when running clocks_init. If set to
|
||||
* false, none of the GCLK generators will be configured in clocks_init(). */
|
||||
#define CONF_CLOCK_CONFIGURE_GCLK true
|
||||
|
||||
/* Configure GCLK generator 0 (Main Clock) */
|
||||
#define CONF_CLOCK_GCLK_0_ENABLE true
|
||||
#define CONF_CLOCK_GCLK_0_RUN_IN_STANDBY false
|
||||
#define CONF_CLOCK_GCLK_0_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_DFLL
|
||||
#define CONF_CLOCK_GCLK_0_PRESCALER 1
|
||||
#define CONF_CLOCK_GCLK_0_OUTPUT_ENABLE false
|
||||
|
||||
/* Configure GCLK generator 1 */
|
||||
#define CONF_CLOCK_GCLK_1_ENABLE true
|
||||
#define CONF_CLOCK_GCLK_1_RUN_IN_STANDBY false
|
||||
#define CONF_CLOCK_GCLK_1_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_OSC32K
|
||||
#define CONF_CLOCK_GCLK_1_PRESCALER 1
|
||||
#define CONF_CLOCK_GCLK_1_OUTPUT_ENABLE false
|
||||
|
||||
/* Configure GCLK generator 2 (RTC) */
|
||||
#define CONF_CLOCK_GCLK_2_ENABLE true
|
||||
#define CONF_CLOCK_GCLK_2_RUN_IN_STANDBY true
|
||||
#define CONF_CLOCK_GCLK_2_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_OSC32K
|
||||
#define CONF_CLOCK_GCLK_2_PRESCALER 32
|
||||
#define CONF_CLOCK_GCLK_2_OUTPUT_ENABLE false
|
||||
|
||||
/* Configure GCLK generator 3 */
|
||||
#define CONF_CLOCK_GCLK_3_ENABLE false
|
||||
#define CONF_CLOCK_GCLK_3_RUN_IN_STANDBY false
|
||||
#define CONF_CLOCK_GCLK_3_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_OSC8M
|
||||
#define CONF_CLOCK_GCLK_3_PRESCALER 1
|
||||
#define CONF_CLOCK_GCLK_3_OUTPUT_ENABLE false
|
||||
|
||||
/* Configure GCLK generator 4 */
|
||||
#define CONF_CLOCK_GCLK_4_ENABLE true
|
||||
#define CONF_CLOCK_GCLK_4_RUN_IN_STANDBY false
|
||||
#define CONF_CLOCK_GCLK_4_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_ULP32K
|
||||
#define CONF_CLOCK_GCLK_4_PRESCALER 32
|
||||
#define CONF_CLOCK_GCLK_4_OUTPUT_ENABLE false
|
||||
|
||||
/* Configure GCLK generator 5 */
|
||||
#define CONF_CLOCK_GCLK_5_ENABLE false
|
||||
#define CONF_CLOCK_GCLK_5_RUN_IN_STANDBY false
|
||||
#define CONF_CLOCK_GCLK_5_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_OSC8M
|
||||
#define CONF_CLOCK_GCLK_5_PRESCALER 1
|
||||
#define CONF_CLOCK_GCLK_5_OUTPUT_ENABLE false
|
||||
|
||||
/* Configure GCLK generator 6 */
|
||||
#define CONF_CLOCK_GCLK_6_ENABLE false
|
||||
#define CONF_CLOCK_GCLK_6_RUN_IN_STANDBY false
|
||||
#define CONF_CLOCK_GCLK_6_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_OSC8M
|
||||
#define CONF_CLOCK_GCLK_6_PRESCALER 1
|
||||
#define CONF_CLOCK_GCLK_6_OUTPUT_ENABLE false
|
||||
|
||||
/* Configure GCLK generator 7 */
|
||||
#define CONF_CLOCK_GCLK_7_ENABLE false
|
||||
#define CONF_CLOCK_GCLK_7_RUN_IN_STANDBY false
|
||||
#define CONF_CLOCK_GCLK_7_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_OSC8M
|
||||
#define CONF_CLOCK_GCLK_7_PRESCALER 1
|
||||
#define CONF_CLOCK_GCLK_7_OUTPUT_ENABLE false
|
||||
|
||||
/* Configure GCLK generator 8 */
|
||||
#define CONF_CLOCK_GCLK_8_ENABLE false
|
||||
#define CONF_CLOCK_GCLK_8_RUN_IN_STANDBY false
|
||||
#define CONF_CLOCK_GCLK_8_CLOCK_SOURCE SYSTEM_CLOCK_SOURCE_OSC8M
|
||||
#define CONF_CLOCK_GCLK_8_PRESCALER 1
|
||||
#define CONF_CLOCK_GCLK_8_OUTPUT_ENABLE false
|
||||
|
||||
#endif /* CONF_CLOCKS_H_INCLUDED */
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief SAM R21 External Interrupt Driver Configuration Header
|
||||
*
|
||||
* Copyright (C) 2014-2015 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* \asf_license_start
|
||||
*
|
||||
* \page License
|
||||
*
|
||||
* 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. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an
|
||||
* Atmel microcontroller product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
*
|
||||
* \asf_license_stop
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#ifndef CONF_EXTINT_H_INCLUDED
|
||||
#define CONF_EXTINT_H_INCLUDED
|
||||
|
||||
#define EXTINT_CLOCK_SOURCE GCLK_GENERATOR_0
|
||||
#define EXTINT_CALLBACKS_MAX 10
|
||||
|
||||
#endif
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief SAM R21 SPI configuration
|
||||
*
|
||||
* Copyright (C) 2014-2015 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* \asf_license_start
|
||||
*
|
||||
* \page License
|
||||
*
|
||||
* 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. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an
|
||||
* Atmel microcontroller product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
*
|
||||
* \asf_license_stop
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#ifndef CONF_SPI_H_INCLUDED
|
||||
#define CONF_SPI_H_INCLUDED
|
||||
|
||||
#define CONF_SPI_MASTER_ENABLE true
|
||||
#define CONF_SPI_SLAVE_ENABLE false
|
||||
|
||||
#endif /* CONF_SPI_H_INCLUDED */
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* \file *********************************************************************
|
||||
*
|
||||
* \brief Common TRX Access Configuration
|
||||
*
|
||||
* Copyright (c) 2014-2015 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* \asf_license_start
|
||||
*
|
||||
* \page License
|
||||
*
|
||||
* 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. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an
|
||||
* Atmel microcontroller product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
*
|
||||
* \asf_license_stop
|
||||
*/
|
||||
|
||||
#ifndef CONF_TRX_ACCESS_H_INCLUDED
|
||||
#define CONF_TRX_ACCESS_H_INCLUDED
|
||||
|
||||
#endif /* CONF_TRX_ACCESS_H_INCLUDED */
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief Linker script for running in internal FLASH on the SAMR21x18A
|
||||
*
|
||||
* Copyright (c) 2015 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* \asf_license_start
|
||||
*
|
||||
* \page License
|
||||
*
|
||||
* 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. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an
|
||||
* Atmel microcontroller product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||
*
|
||||
* \asf_license_stop
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
SEARCH_DIR(.)
|
||||
|
||||
/* Memory Spaces Definitions */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x00000000, LENGTH = 0x00040000
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00008000
|
||||
}
|
||||
|
||||
/* The stack size used by the application. NOTE: you need to adjust according to your application. */
|
||||
STACK_SIZE = DEFINED(STACK_SIZE) ? STACK_SIZE : DEFINED(__stack_size__) ? __stack_size__ : 0x2000;
|
||||
|
||||
/* Section Definitions */
|
||||
SECTIONS
|
||||
{
|
||||
.text :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_sfixed = .;
|
||||
KEEP(*(.vectors .vectors.*))
|
||||
|
||||
FILL(0xFF)
|
||||
/* PDS NV memory section */
|
||||
. = ALIGN(0x100);
|
||||
PROVIDE(__d_nv_mem_start = .);
|
||||
. += ALIGN(0x1000); /* Size of D_Nv memory section is 0x1000 i.e., 4KB */
|
||||
PROVIDE(__d_nv_mem_end = .);
|
||||
|
||||
*(.text .text.* .gnu.linkonce.t.*)
|
||||
*(.glue_7t) *(.glue_7)
|
||||
*(.rodata .rodata* .gnu.linkonce.r.*)
|
||||
*(.ARM.extab* .gnu.linkonce.armextab.*)
|
||||
|
||||
/* Support C constructors, and C destructors in both user code
|
||||
and the C library. This also provides support for C++ code. */
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.init))
|
||||
. = ALIGN(4);
|
||||
__preinit_array_start = .;
|
||||
KEEP (*(.preinit_array))
|
||||
__preinit_array_end = .;
|
||||
|
||||
. = ALIGN(4);
|
||||
__init_array_start = .;
|
||||
KEEP (*(SORT(.init_array.*)))
|
||||
KEEP (*(.init_array))
|
||||
__init_array_end = .;
|
||||
|
||||
. = ALIGN(4);
|
||||
KEEP (*crtbegin.o(.ctors))
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
|
||||
KEEP (*(SORT(.ctors.*)))
|
||||
KEEP (*crtend.o(.ctors))
|
||||
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.fini))
|
||||
|
||||
. = ALIGN(4);
|
||||
__fini_array_start = .;
|
||||
KEEP (*(.fini_array))
|
||||
KEEP (*(SORT(.fini_array.*)))
|
||||
__fini_array_end = .;
|
||||
|
||||
KEEP (*crtbegin.o(.dtors))
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
|
||||
KEEP (*(SORT(.dtors.*)))
|
||||
KEEP (*crtend.o(.dtors))
|
||||
|
||||
. = ALIGN(4);
|
||||
_efixed = .; /* End of text section */
|
||||
} > rom
|
||||
|
||||
/* .ARM.exidx is sorted, so has to go in its own output section. */
|
||||
PROVIDE_HIDDEN (__exidx_start = .);
|
||||
.ARM.exidx :
|
||||
{
|
||||
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
|
||||
} > rom
|
||||
PROVIDE_HIDDEN (__exidx_end = .);
|
||||
|
||||
. = ALIGN(4);
|
||||
_etext = .;
|
||||
|
||||
.relocate : AT (_etext)
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_srelocate = .;
|
||||
*(.ramfunc .ramfunc.*);
|
||||
*(.data .data.*);
|
||||
. = ALIGN(4);
|
||||
_erelocate = .;
|
||||
} > ram
|
||||
|
||||
/* .bss section which is used for uninitialized data */
|
||||
.bss (NOLOAD) :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_sbss = . ;
|
||||
_szero = .;
|
||||
*(.bss .bss.*)
|
||||
*(COMMON)
|
||||
. = ALIGN(4);
|
||||
_ebss = . ;
|
||||
_ezero = .;
|
||||
} > ram
|
||||
|
||||
/* stack section */
|
||||
.stack (NOLOAD):
|
||||
{
|
||||
. = ALIGN(8);
|
||||
_sstack = .;
|
||||
. = . + STACK_SIZE;
|
||||
. = ALIGN(8);
|
||||
_estack = .;
|
||||
} > ram
|
||||
|
||||
. = ALIGN(4);
|
||||
_end = . ;
|
||||
end = _end;
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief User board definition template
|
||||
*
|
||||
*/
|
||||
|
||||
/* This file is intended to contain definitions and configuration details for
|
||||
* features and devices that are available on the board, e.g., frequency and
|
||||
* startup time for an external crystal, external memory devices, LED and USART
|
||||
* pins.
|
||||
*/
|
||||
/*
|
||||
* Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a>
|
||||
*/
|
||||
|
||||
#ifndef USER_BOARD_H
|
||||
#define USER_BOARD_H
|
||||
|
||||
#include <conf_board.h>
|
||||
#include <compiler.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Resonator definitions */
|
||||
#define BOARD_FREQ_SLCK_XTAL (32768U)
|
||||
#define BOARD_FREQ_SLCK_BYPASS (32768U)
|
||||
#define BOARD_FREQ_MAINCK_XTAL 0 /* Not Mounted */
|
||||
#define BOARD_FREQ_MAINCK_BYPASS 0 /* Not Mounted */
|
||||
#define BOARD_MCK CHIP_FREQ_CPU_MAX
|
||||
#define BOARD_OSC_STARTUP_US 15625
|
||||
|
||||
/** UART interface definitions */
|
||||
#define UART_SERCOM_MODULE SERCOM2
|
||||
#define UART_SERCOM_MUX_SETTING USART_RX_3_TX_2_XCK_3
|
||||
#define UART_SERCOM_PINMUX_PAD0 PINMUX_UNUSED
|
||||
#define UART_SERCOM_PINMUX_PAD1 PINMUX_UNUSED
|
||||
#define UART_SERCOM_PINMUX_PAD2 PINMUX_PA14C_SERCOM2_PAD2
|
||||
#define UART_SERCOM_PINMUX_PAD3 PINMUX_PA15C_SERCOM2_PAD3
|
||||
#define UART_SERCOM_DMAC_ID_TX SERCOM2_DMAC_ID_TX
|
||||
#define UART_SERCOM_DMAC_ID_RX SERCOM2_DMAC_ID_RX
|
||||
|
||||
/** RF SPI interface definitions */
|
||||
#define RF_SPI_MODULE SERCOM4
|
||||
#define RF_SPI_SERCOM_MUX_SETTING SPI_SIGNAL_MUX_SETTING_E
|
||||
#define RF_SPI_SERCOM_PINMUX_PAD0 PINMUX_PC19F_SERCOM4_PAD0
|
||||
#define RF_SPI_SERCOM_PINMUX_PAD1 PINMUX_PB31D_SERCOM5_PAD1
|
||||
#define RF_SPI_SERCOM_PINMUX_PAD2 PINMUX_PB30F_SERCOM4_PAD2
|
||||
#define RF_SPI_SERCOM_PINMUX_PAD3 PINMUX_PC18F_SERCOM4_PAD3
|
||||
|
||||
#define RF_IRQ_MODULE EIC
|
||||
#define RF_IRQ_INPUT 0
|
||||
#define RF_IRQ_PIN PIN_PB00A_EIC_EXTINT0
|
||||
#define RF_IRQ_MUX MUX_PB00A_EIC_EXTINT0
|
||||
#define RF_IRQ_PINMUX PINMUX_PB00A_EIC_EXTINT0
|
||||
|
||||
/** 802.15.4 TRX Interface definitions */
|
||||
#define AT86RFX_SPI SERCOM4
|
||||
#define AT86RFX_RST_PIN PIN_PB15
|
||||
#define AT86RFX_IRQ_PIN PIN_PB00
|
||||
#define AT86RFX_SLP_PIN PIN_PA20
|
||||
#define AT86RFX_SPI_CS PIN_PB31
|
||||
#define AT86RFX_SPI_MOSI PIN_PB30
|
||||
#define AT86RFX_SPI_MISO PIN_PC19
|
||||
#define AT86RFX_SPI_SCK PIN_PC18
|
||||
#define RFCTRL_CFG_ANT_DIV 4
|
||||
|
||||
#define AT86RFX_SPI_SERCOM_MUX_SETTING RF_SPI_SERCOM_MUX_SETTING
|
||||
#define AT86RFX_SPI_SERCOM_PINMUX_PAD0 RF_SPI_SERCOM_PINMUX_PAD0
|
||||
#define AT86RFX_SPI_SERCOM_PINMUX_PAD1 PINMUX_UNUSED
|
||||
#define AT86RFX_SPI_SERCOM_PINMUX_PAD2 RF_SPI_SERCOM_PINMUX_PAD2
|
||||
#define AT86RFX_SPI_SERCOM_PINMUX_PAD3 RF_SPI_SERCOM_PINMUX_PAD3
|
||||
|
||||
#define AT86RFX_IRQ_CHAN RF_IRQ_INPUT
|
||||
#define AT86RFX_IRQ_PINMUX RF_IRQ_PINMUX
|
||||
|
||||
/** Enables the transceiver main interrupt. */
|
||||
#define ENABLE_TRX_IRQ() \
|
||||
extint_chan_enable_callback(AT86RFX_IRQ_CHAN, EXTINT_CALLBACK_TYPE_DETECT)
|
||||
|
||||
/** Disables the transceiver main interrupt. */
|
||||
#define DISABLE_TRX_IRQ() \
|
||||
extint_chan_disable_callback(AT86RFX_IRQ_CHAN, EXTINT_CALLBACK_TYPE_DETECT)
|
||||
|
||||
/** Clears the transceiver main interrupt. */
|
||||
#define CLEAR_TRX_IRQ() \
|
||||
extint_chan_clear_detected(AT86RFX_IRQ_CHAN);
|
||||
|
||||
/** This macro saves the trx interrupt status and disables the trx interrupt. */
|
||||
#define ENTER_TRX_REGION() \
|
||||
{ extint_chan_disable_callback(AT86RFX_IRQ_CHAN, EXTINT_CALLBACK_TYPE_DETECT)
|
||||
|
||||
/* This macro restores the transceiver interrupt status */
|
||||
#define LEAVE_TRX_REGION() \
|
||||
extint_chan_enable_callback(AT86RFX_IRQ_CHAN, EXTINT_CALLBACK_TYPE_DETECT); }
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // USER_BOARD_H
|
||||
Reference in New Issue
Block a user