mirror of
https://github.com/espressif/openthread.git
synced 2026-09-07 09:40:12 +00:00
Initial example for the CC2538. (#148)
This commit is contained in:
+84
-12
@@ -1,5 +1,38 @@
|
||||
#
|
||||
# Copyright (c) 2016, Nest Labs, Inc.
|
||||
# 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.
|
||||
#
|
||||
|
||||
language: cpp
|
||||
|
||||
env:
|
||||
- BUILD_TARGET="pretty-check"
|
||||
- BUILD_TARGET="posix"
|
||||
- BUILD_TARGET="cc2538"
|
||||
|
||||
compiler:
|
||||
- clang
|
||||
- gcc
|
||||
@@ -8,22 +41,61 @@ os:
|
||||
- linux
|
||||
- osx
|
||||
|
||||
matrix:
|
||||
exclude:
|
||||
- compiler: clang
|
||||
env: BUILD_TARGET="cc2538"
|
||||
- compiler: clang
|
||||
env: BUILD_TARGET="pretty-check"
|
||||
|
||||
before_install:
|
||||
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install python-pexpect; fi
|
||||
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then sudo easy_install pexpect; fi
|
||||
|
||||
install:
|
||||
- pushd ~
|
||||
- wget https://sourceforge.net/projects/astyle/files/astyle/astyle%202.05.1/astyle_2.05.1_linux.tar.gz/download -O astyle.tar.gz
|
||||
- tar -xzvf astyle.tar.gz
|
||||
- pushd astyle/build/gcc && LDFLAGS=" " make
|
||||
- export PATH=$PWD/bin:$PATH
|
||||
- popd
|
||||
- popd
|
||||
- if [ "$BUILD_TARGET" == "pretty-check" ]; then
|
||||
pushd ~ &&
|
||||
wget https://sourceforge.net/projects/astyle/files/astyle/astyle%202.05.1/astyle_2.05.1_linux.tar.gz/download -O astyle.tar.gz &&
|
||||
tar xzvf astyle.tar.gz &&
|
||||
pushd astyle/build/gcc && LDFLAGS=" " make &&
|
||||
export PATH=$PWD/bin:$PATH &&
|
||||
popd &&
|
||||
popd &&
|
||||
astyle --version ;
|
||||
fi
|
||||
|
||||
- if [ "$BUILD_TARGET" == "cc2538" ] && [ "$TRAVIS_OS_NAME" == "linux" ] ; then
|
||||
sudo apt-get install lib32z1 &&
|
||||
pushd ~ &&
|
||||
wget https://launchpad.net/gcc-arm-embedded/4.9/4.9-2015-q3-update/+download/gcc-arm-none-eabi-4_9-2015q3-20150921-linux.tar.bz2 &&
|
||||
tar xjf gcc-arm-none-eabi-4_9-2015q3-20150921-linux.tar.bz2 &&
|
||||
export PATH=$PWD/gcc-arm-none-eabi-4_9-2015q3/bin:$PATH &&
|
||||
popd &&
|
||||
arm-none-eabi-gcc --version ;
|
||||
fi
|
||||
|
||||
- if [ "$BUILD_TARGET" == "cc2538" ] && [ "$TRAVIS_OS_NAME" == "osx" ] ; then
|
||||
pushd ~ &&
|
||||
wget https://launchpad.net/gcc-arm-embedded/4.9/4.9-2015-q3-update/+download/gcc-arm-none-eabi-4_9-2015q3-20150921-mac.tar.bz2 &&
|
||||
tar xjf gcc-arm-none-eabi-4_9-2015q3-20150921-mac.tar.bz2 &&
|
||||
export PATH=$PWD/gcc-arm-none-eabi-4_9-2015q3/bin:$PATH &&
|
||||
popd &&
|
||||
arm-none-eabi-gcc --version ;
|
||||
fi
|
||||
|
||||
script:
|
||||
- ./bootstrap
|
||||
- ./configure
|
||||
- make pretty-check
|
||||
- make distclean
|
||||
- make -f Makefile-Standalone distcheck
|
||||
- if [ "$BUILD_TARGET" == "pretty-check" ]; then
|
||||
./bootstrap &&
|
||||
./configure &&
|
||||
make pretty-check ;
|
||||
fi
|
||||
|
||||
- if [ "$BUILD_TARGET" == "posix" ]; then
|
||||
./bootstrap &&
|
||||
make -f Makefile-Standalone distcheck ;
|
||||
fi
|
||||
|
||||
- if [ "$BUILD_TARGET" == "cc2538" ]; then
|
||||
./bootstrap &&
|
||||
make -f examples/cc2538/Makefile-cc2538 ;
|
||||
fi
|
||||
|
||||
+15
-2
@@ -381,11 +381,11 @@ AM_CONDITIONAL([OPENTHREAD_ENABLE_NCP], [test "${enable_ncp}" = "yes"])
|
||||
|
||||
AC_ARG_WITH(examples,
|
||||
[AS_HELP_STRING([--with-examples=TARGET],
|
||||
[Specify the examples from one of: none, posix @<:@default=none@:>@.])],
|
||||
[Specify the examples from one of: none, posix, cc2538 @<:@default=none@:>@.])],
|
||||
[
|
||||
case "${with_examples}" in
|
||||
|
||||
none|posix)
|
||||
none|posix|cc2538)
|
||||
;;
|
||||
*)
|
||||
AC_MSG_ERROR([Invalid value ${with_examples} for --with-examples])
|
||||
@@ -402,6 +402,10 @@ case ${with_examples} in
|
||||
OPENTHREAD_EXAMPLES_POSIX=1
|
||||
;;
|
||||
|
||||
cc2538)
|
||||
OPENTHREAD_EXAMPLES_CC2538=1
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
AC_MSG_RESULT(${OPENTHREAD_EXAMPLES})
|
||||
@@ -413,6 +417,10 @@ AC_SUBST(OPENTHREAD_EXAMPLES_POSIX)
|
||||
AM_CONDITIONAL([OPENTHREAD_EXAMPLES_POSIX], [test "${OPENTHREAD_EXAMPLES}" = "posix"])
|
||||
AC_DEFINE_UNQUOTED([OPENTHREAD_EXAMPLES_POSIX],[${OPENTHREAD_EXAMPLES_POSIX}],[Define to 1 if you want to use posix examples])
|
||||
|
||||
AC_SUBST(OPENTHREAD_EXAMPLES_CC2538)
|
||||
AM_CONDITIONAL([OPENTHREAD_EXAMPLES_CC2538], [test "${OPENTHREAD_EXAMPLES}" = "cc2538"])
|
||||
AC_DEFINE_UNQUOTED([OPENTHREAD_EXAMPLES_CC2538],[${OPENTHREAD_EXAMPLES_CC2538}],[Define to 1 if you want to use cc2538 examples])
|
||||
|
||||
#
|
||||
# Tools
|
||||
#
|
||||
@@ -523,6 +531,11 @@ examples/posix/app/Makefile
|
||||
examples/posix/app/cli/Makefile
|
||||
examples/posix/app/ncp/Makefile
|
||||
examples/posix/platform/Makefile
|
||||
examples/cc2538/Makefile
|
||||
examples/cc2538/app/Makefile
|
||||
examples/cc2538/app/cli/Makefile
|
||||
examples/cc2538/app/ncp/Makefile
|
||||
examples/cc2538/platform/Makefile
|
||||
tests/Makefile
|
||||
tests/scripts/Makefile
|
||||
tests/unit/Makefile
|
||||
|
||||
@@ -32,6 +32,7 @@ include $(abs_top_nlbuild_autotools_dir)/automake/pre.am
|
||||
|
||||
DIST_SUBDIRS = \
|
||||
posix \
|
||||
cc2538 \
|
||||
$(NULL)
|
||||
|
||||
# Always build (e.g. for 'make all') these subdirectories.
|
||||
@@ -40,10 +41,15 @@ if OPENTHREAD_EXAMPLES_POSIX
|
||||
SUBDIRS = posix
|
||||
endif
|
||||
|
||||
if OPENTHREAD_EXAMPLES_CC2538
|
||||
SUBDIRS = cc2538
|
||||
endif
|
||||
|
||||
# Always pretty (e.g. for 'make pretty') these subdirectories.
|
||||
|
||||
PRETTY_SUBDIRS = \
|
||||
posix \
|
||||
cc2538 \
|
||||
$(NULL)
|
||||
|
||||
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
0.5
|
||||
@@ -0,0 +1,248 @@
|
||||
#
|
||||
# Copyright (c) 2016, Nest Labs, Inc.
|
||||
# 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
|
||||
AS = 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
|
||||
|
||||
configure_OPTIONS = \
|
||||
--enable-cli \
|
||||
--enable-ncp \
|
||||
--with-examples=cc2538 \
|
||||
$(NULL)
|
||||
|
||||
COMMONCFLAGS = \
|
||||
-fdata-sections \
|
||||
-ffunction-sections \
|
||||
-Os \
|
||||
-g \
|
||||
$(NULL)
|
||||
|
||||
CPPFLAGS = \
|
||||
$(COMMONCFLAGS) \
|
||||
$(target_CPPFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
CFLAGS = \
|
||||
$(COMMONCFLAGS) \
|
||||
$(target_CFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
CXXFLAGS = \
|
||||
$(COMMONCFLAGS) \
|
||||
$(target_CXXFLAGS) \
|
||||
-fno-exceptions \
|
||||
-fno-rtti \
|
||||
$(NULL)
|
||||
|
||||
LDFLAGS = \
|
||||
$(COMMONCFLAGS) \
|
||||
$(target_LDFLAGS) \
|
||||
-nostartfiles \
|
||||
-specs=nano.specs \
|
||||
-specs=nosys.specs \
|
||||
-Wl,--gc-sections \
|
||||
-Wl,-Map=map.map \
|
||||
$(NULL)
|
||||
|
||||
LIBS = \
|
||||
$(NULL)
|
||||
|
||||
ECHO := @echo
|
||||
MAKE := make
|
||||
MKDIR_P := mkdir -p
|
||||
LN_S := ln -s
|
||||
RM_F := rm -f
|
||||
|
||||
INSTALL := /usr/bin/install
|
||||
INSTALLFLAGS := -p
|
||||
|
||||
TopSourceDir := $(dir $(shell readlink $(firstword $(MAKEFILE_LIST))))../../
|
||||
AbsTopSourceDir := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))../../
|
||||
|
||||
BuildPath = build
|
||||
TopBuildDir = $(BuildPath)
|
||||
AbsTopBuildDir = $(PWD)/$(TopBuildDir)
|
||||
|
||||
ResultPath = output
|
||||
TopResultDir = $(ResultPath)
|
||||
AbsTopResultDir = $(PWD)/$(TopResultDir)
|
||||
|
||||
TargetTuple = arm-none-eabi
|
||||
|
||||
ARCHS = cortex-m3
|
||||
|
||||
TopTargetLibDir = $(TopResultDir)/$(if $(1),$(1)-,)$(TargetTuple)/lib
|
||||
|
||||
#
|
||||
# configure-arch <arch>
|
||||
#
|
||||
# Configure OpenThread for the specified architecture.
|
||||
#
|
||||
# arch - The architecture to configure.
|
||||
#
|
||||
define configure-arch
|
||||
$(ECHO) " CONFIG $(1)-$(TargetTuple)..."
|
||||
(cd $(BuildPath)/$(1)-$(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)" LIBS="$(LIBS)" \
|
||||
--host=arm-none-eabi \
|
||||
--target=arm-none-eabi \
|
||||
--prefix=/ \
|
||||
$(configure_OPTIONS))
|
||||
endef # configure-arch
|
||||
|
||||
#
|
||||
# build-arch <arch>
|
||||
#
|
||||
# Build the OpenThread intermediate build products for the specified
|
||||
# architecture.
|
||||
#
|
||||
# arch - The architecture to build.
|
||||
#
|
||||
define build-arch
|
||||
$(ECHO) " BUILD $(1)-$(TargetTuple)"
|
||||
$(MAKE) -C $(BuildPath)/$(1)-$(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 $(1)-$(TargetTuple)"
|
||||
$(MAKE) -C $(BuildPath)/$(1)-$(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)/$(1)-$(TargetTuple)
|
||||
DIRECTORIES += $(BuildPath)/$(1)-$(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)/$(1)-$(TargetTuple)/config.status
|
||||
|
||||
$(BuildPath)/$(1)-$(TargetTuple)/config.status: | $(BuildPath)/$(1)-$(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-m3
|
||||
#
|
||||
|
||||
cortex-m3_target_ABI = cortex-m3
|
||||
cortex-m3_target_CPPFLAGS = -mcpu=cortex-m3 -mfloat-abi=soft -mthumb
|
||||
cortex-m3_target_CFLAGS = -mcpu=cortex-m3 -mfloat-abi=soft -mthumb
|
||||
cortex-m3_target_CXXFLAGS = -mcpu=cortex-m3 -mfloat-abi=soft -mthumb
|
||||
cortex-m3_target_LDFLAGS = -mcpu=cortex-m3 -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) ""
|
||||
@@ -0,0 +1,57 @@
|
||||
#
|
||||
# Copyright (c) 2016, Nest Labs, Inc.
|
||||
# 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
|
||||
|
||||
EXTRA_DIST = \
|
||||
Makefile-cc2538 \
|
||||
README.md \
|
||||
$(NULL)
|
||||
|
||||
# Always package (e.g. for 'make dist') these subdirectories.
|
||||
|
||||
DIST_SUBDIRS = \
|
||||
platform \
|
||||
app \
|
||||
$(NULL)
|
||||
|
||||
# Always build (e.g. for 'make all') these subdirectories.
|
||||
|
||||
SUBDIRS = \
|
||||
platform \
|
||||
app \
|
||||
$(NULL)
|
||||
|
||||
# Always pretty (e.g. for 'make pretty') these subdirectories.
|
||||
|
||||
PRETTY_SUBDIRS = \
|
||||
platform \
|
||||
app \
|
||||
$(NULL)
|
||||
|
||||
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
|
||||
@@ -0,0 +1,85 @@
|
||||
# OpenThread on CC2538 Example
|
||||
|
||||
This directory contains example applications and platform drivers for
|
||||
the [Texas Instruments CC2538][cc2538].
|
||||
|
||||
[cc2538]: http://www.ti.com/product/CC2538
|
||||
|
||||
The example platform drivers are intended to present the minimal code
|
||||
necessary to support OpenThread. As a result, the example platform
|
||||
drivers do not necessarily highlight the platform's full capabilities.
|
||||
|
||||
## What's Included
|
||||
|
||||
Folder | Description
|
||||
-----------|-----------------------------------------
|
||||
`apps/cli` | Example application that exposes the CLI over UART
|
||||
`platform` | Minimal implementation of `otPlat*` APIs
|
||||
|
||||
## Toolchain
|
||||
|
||||
Download and install the [GNU toolchain for ARM
|
||||
Cortex-M][gnu-toolchain].
|
||||
|
||||
[gnu-toolchain]: https://launchpad.net/gcc-arm-embedded
|
||||
|
||||
## Build Examples
|
||||
|
||||
```bash
|
||||
$ cd <path-to-openthread>
|
||||
$ ./bootstrap
|
||||
$ make -f examples/cc2538/Makefile-cc2538
|
||||
```
|
||||
|
||||
After a successful build, the `elf` files are found in
|
||||
`<path-to-openthread>/output/bin`. You can convert them to `bin`
|
||||
files using `arm-none-eabi-objcopy`:
|
||||
```bash
|
||||
$ arm-none-eabi-objcopy -O binary arm-none-eabi-soc arm-none-eabi-soc.bin
|
||||
```
|
||||
|
||||
## Flash Binaries
|
||||
|
||||
Compiled binaries may be flashed onto the CC2538 using the [Serial
|
||||
Bootloader Interface][cc2538-bsl] or [JTAG interface][jtag]. The
|
||||
[cc2538-bsl.py script][cc2538-bsl-tool] provides a convenient method
|
||||
for flashing a CC2538 via the UART.
|
||||
|
||||
[cc2538-bsl]: http://www.ti.com/lit/an/swra466a/swra466a.pdf
|
||||
[cc2538-bsl-tool]: https://github.com/JelmerT/cc2538-bsl
|
||||
[jtag]: https://en.wikipedia.org/wiki/JTAG
|
||||
|
||||
## Interact
|
||||
|
||||
1. Open terminal to `/dev/ttyUSB1` (serial port settings: 115200 8-N-1).
|
||||
2. Type `help` for list of commands.
|
||||
|
||||
```bash
|
||||
> help
|
||||
help
|
||||
channel
|
||||
childtimeout
|
||||
contextreusedelay
|
||||
extaddr
|
||||
extpanid
|
||||
ipaddr
|
||||
keysequence
|
||||
leaderweight
|
||||
masterkey
|
||||
mode
|
||||
netdataregister
|
||||
networkidtimeout
|
||||
networkname
|
||||
panid
|
||||
ping
|
||||
prefix
|
||||
releaserouterid
|
||||
rloc16
|
||||
route
|
||||
routerupgradethreshold
|
||||
scan
|
||||
start
|
||||
state
|
||||
stop
|
||||
whitelist
|
||||
```
|
||||
@@ -0,0 +1,58 @@
|
||||
#
|
||||
# Copyright (c) 2016, Nest Labs, Inc.
|
||||
# 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
|
||||
|
||||
# Always package (e.g. for 'make dist') these subdirectories.
|
||||
|
||||
DIST_SUBDIRS = \
|
||||
cli \
|
||||
ncp \
|
||||
$(NULL)
|
||||
|
||||
# Always build (e.g. for 'make all') these subdirectories.
|
||||
|
||||
SUBDIRS = \
|
||||
$(NULL)
|
||||
|
||||
if OPENTHREAD_ENABLE_CLI
|
||||
SUBDIRS += cli
|
||||
endif
|
||||
|
||||
if OPENTHREAD_ENABLE_NCP
|
||||
SUBDIRS += ncp
|
||||
endif
|
||||
|
||||
# Always pretty (e.g. for 'make pretty') these subdirectories.
|
||||
|
||||
PRETTY_SUBDIRS = \
|
||||
cli \
|
||||
ncp \
|
||||
$(NULL)
|
||||
|
||||
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
|
||||
@@ -0,0 +1,55 @@
|
||||
#
|
||||
# Copyright (c) 2016, Nest Labs, Inc.
|
||||
# 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
|
||||
|
||||
bin_PROGRAMS = soc
|
||||
|
||||
soc_CPPFLAGS = \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/src \
|
||||
-I$(top_srcdir)/src/core \
|
||||
-I$(top_srcdir)/examples/cc2538/platform \
|
||||
$(NULL)
|
||||
|
||||
soc_LDADD = \
|
||||
$(top_builddir)/src/core/libopenthread.a \
|
||||
$(top_builddir)/src/cli/libopenthread-cli.a \
|
||||
$(top_builddir)/examples/cc2538/platform/libopenthread-cc2538.a \
|
||||
$(top_builddir)/third_party/mbedtls/libmbedcrypto.a \
|
||||
$(NULL)
|
||||
|
||||
soc_LDFLAGS = \
|
||||
-T $(top_srcdir)/examples/cc2538/platform/cc2538.ld \
|
||||
$(NULL)
|
||||
|
||||
soc_SOURCES = \
|
||||
main.c \
|
||||
$(NULL)
|
||||
|
||||
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
|
||||
@@ -0,0 +1,73 @@
|
||||
# OpenThread CLI Example
|
||||
|
||||
This example application demonstrates a minimal OpenThread application
|
||||
that exposes the OpenThread configuration and management interfaces
|
||||
via a basic command-line interface. The steps below take you through
|
||||
the minimal steps required to ping one emulated Thread device from
|
||||
another emulated Thread device.
|
||||
|
||||
## 1. Build
|
||||
|
||||
Follow the [CC2538 example build instructions](../../README.md).
|
||||
|
||||
## 2. Start node 1
|
||||
|
||||
Open a terminal to UART0 on node 1 (115200 8-N-1).
|
||||
|
||||
Start OpenThread:
|
||||
|
||||
```bash
|
||||
> start
|
||||
Done
|
||||
```
|
||||
|
||||
Wait a few seconds and verify that the device has become a Thread Leader:
|
||||
|
||||
```bash
|
||||
> state
|
||||
leader
|
||||
Done
|
||||
```
|
||||
|
||||
View IPv6 addresses assigned to Node 1's Thread interface:
|
||||
|
||||
```bash
|
||||
> ipaddr
|
||||
fdde:ad00:beef:0:0:ff:fe00:0
|
||||
fe80:0:0:0:0:ff:fe00:0
|
||||
fdde:ad00:beef:0:558:f56b:d688:799
|
||||
fe80:0:0:0:f3d9:2a82:c8d8:fe43
|
||||
Done
|
||||
```
|
||||
|
||||
## 2. Start node 2
|
||||
|
||||
Open a terminal to UART0 on node 2 (115200 8-N-1).
|
||||
|
||||
Start OpenThread:
|
||||
|
||||
```bash
|
||||
> start
|
||||
Done
|
||||
```
|
||||
|
||||
Wait a few seconds and verify that the device has become a Thread Router:
|
||||
|
||||
```bash
|
||||
> state
|
||||
router
|
||||
Done
|
||||
```
|
||||
|
||||
## 3. Ping Node 1 from Node 2
|
||||
|
||||
```bash
|
||||
> ping fdde:ad00:beef:0:558:f56b:d688:799
|
||||
16 bytes from fdde:ad00:beef:0:558:f56b:d688:799: icmp_seq=1 hlim=64
|
||||
```
|
||||
|
||||
## 4. Want more?
|
||||
|
||||
You may note that the example above did not include any network parameter configuration, such as the IEEE 802.15.4 PAN ID or the Thread Master Key. OpenThread currently implements default values for network parameters, however, you may use the CLI to change network parameters, other configurations, and perform other operations.
|
||||
|
||||
See the [OpenThread CLI Reference README.md](../../../../src/cli/README.md) to explore more.
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Nest Labs, Inc.
|
||||
* 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 <stdlib.h>
|
||||
|
||||
#include <openthread.h>
|
||||
#include <cli/cli-serial.h>
|
||||
#include <platform.h>
|
||||
|
||||
void otSignalTaskletPending(void)
|
||||
{
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
PlatformInit();
|
||||
otInit();
|
||||
otCliSerialInit();
|
||||
|
||||
while (1)
|
||||
{
|
||||
otProcessNextTasklet();
|
||||
PlatformProcessDrivers();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
#
|
||||
# Copyright (c) 2016, Nest Labs, Inc.
|
||||
# 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
|
||||
|
||||
bin_PROGRAMS = ncp
|
||||
|
||||
ncp_CPPFLAGS = \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/src \
|
||||
-I$(top_srcdir)/src/core \
|
||||
-I$(top_srcdir)/examples/cc2538/platform \
|
||||
$(NULL)
|
||||
|
||||
ncp_LDADD = \
|
||||
$(top_builddir)/src/ncp/libopenthread-ncp.a \
|
||||
$(top_builddir)/src/core/libopenthread.a \
|
||||
$(top_builddir)/examples/cc2538/platform/libopenthread-cc2538.a \
|
||||
$(top_builddir)/third_party/mbedtls/libmbedcrypto.a \
|
||||
$(NULL)
|
||||
|
||||
ncp_LDFLAGS = \
|
||||
-T $(top_srcdir)/examples/cc2538/platform/cc2538.ld \
|
||||
$(NULL)
|
||||
|
||||
ncp_SOURCES = \
|
||||
main.c \
|
||||
$(NULL)
|
||||
|
||||
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Nest Labs, Inc.
|
||||
* 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 <stdlib.h>
|
||||
|
||||
#include <openthread.h>
|
||||
#include <ncp/ncp.h>
|
||||
#include <platform.h>
|
||||
|
||||
void otSignalTaskletPending(void)
|
||||
{
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
PlatformInit();
|
||||
otInit();
|
||||
otNcpInit();
|
||||
|
||||
while (1)
|
||||
{
|
||||
otProcessNextTasklet();
|
||||
PlatformProcessDrivers();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
#
|
||||
# Copyright (c) 2016, Nest Labs, Inc.
|
||||
# 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-cc2538.a
|
||||
|
||||
libopenthread_cc2538_a_CPPFLAGS = \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/src \
|
||||
-I$(top_srcdir)/src/core \
|
||||
$(NULL)
|
||||
|
||||
libopenthread_cc2538_a_SOURCES = \
|
||||
alarm.c \
|
||||
logging.c \
|
||||
platform.c \
|
||||
radio.c \
|
||||
random.c \
|
||||
serial.c \
|
||||
startup-gcc.c \
|
||||
$(NULL)
|
||||
|
||||
noinst_HEADERS = \
|
||||
cc2538-reg.h \
|
||||
platform.h \
|
||||
$(NULL)
|
||||
|
||||
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Nest Labs, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file implements the OpenThread platform abstraction for the alarm.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <platform/alarm.h>
|
||||
#include "cc2538-reg.h"
|
||||
|
||||
enum
|
||||
{
|
||||
kSystemClock = 32000000, ///< MHz
|
||||
kTicksPerSec = 1000, ///< Ticks per second
|
||||
};
|
||||
|
||||
static uint32_t sCounter = 0;
|
||||
static uint32_t sAlarmT0 = 0;
|
||||
static uint32_t sAlarmDt = 0;
|
||||
static bool sIsRunning = false;
|
||||
|
||||
void PlatformAlarmInit(void)
|
||||
{
|
||||
HWREG(NVIC_ST_RELOAD) = kSystemClock / kTicksPerSec;
|
||||
HWREG(NVIC_ST_CTRL) = NVIC_ST_CTRL_CLK_SRC | NVIC_ST_CTRL_INTEN | NVIC_ST_CTRL_ENABLE;
|
||||
}
|
||||
|
||||
uint32_t otPlatAlarmGetNow(void)
|
||||
{
|
||||
return sCounter;
|
||||
}
|
||||
|
||||
void otPlatAlarmStartAt(uint32_t t0, uint32_t dt)
|
||||
{
|
||||
sAlarmT0 = t0;
|
||||
sAlarmDt = dt;
|
||||
sIsRunning = true;
|
||||
}
|
||||
|
||||
void otPlatAlarmStop(void)
|
||||
{
|
||||
sIsRunning = false;
|
||||
}
|
||||
|
||||
void PlatformAlarmProcess(void)
|
||||
{
|
||||
uint32_t expires;
|
||||
bool fire = false;
|
||||
|
||||
if (sIsRunning)
|
||||
{
|
||||
expires = sAlarmT0 + sAlarmDt;
|
||||
|
||||
if (sAlarmT0 <= sCounter)
|
||||
{
|
||||
if (expires >= sAlarmT0 && expires <= sCounter)
|
||||
{
|
||||
fire = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (expires >= sAlarmT0 || expires <= sCounter)
|
||||
{
|
||||
fire = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fire)
|
||||
{
|
||||
sIsRunning = false;
|
||||
otPlatAlarmFired();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SysTick_Handler()
|
||||
{
|
||||
sCounter++;
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Nest Labs, Inc.
|
||||
* 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 CC2538 register definitions.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CC2538_REG_H_
|
||||
#define CC2538_REG_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define HWREG(x) (*((volatile uint32_t *)(x)))
|
||||
|
||||
#define NVIC_ST_CTRL 0xE000E010 // SysTick Control and Status
|
||||
#define NVIC_ST_RELOAD 0xE000E014 // SysTick Reload Value Register
|
||||
#define NVIC_EN0 0xE000E100 // Interrupt 0-31 Set Enable
|
||||
|
||||
#define NVIC_ST_CTRL_COUNT 0x00010000 // Count Flag
|
||||
#define NVIC_ST_CTRL_CLK_SRC 0x00000004 // Clock Source
|
||||
#define NVIC_ST_CTRL_INTEN 0x00000002 // Interrupt Enable
|
||||
#define NVIC_ST_CTRL_ENABLE 0x00000001 // Enable
|
||||
|
||||
#define INT_UART0 21 // UART0 Rx and Tx
|
||||
|
||||
#define IEEE_EUI64 0x00280028 // Address of IEEE EUI-64 address
|
||||
|
||||
#define RFCORE_FFSM_EXT_ADDR0 0x400885A8 // Local address information
|
||||
#define RFCORE_FFSM_PAN_ID0 0x400885C8 // Local address information
|
||||
#define RFCORE_FFSM_PAN_ID1 0x400885CC // Local address information
|
||||
#define RFCORE_FFSM_SHORT_ADDR0 0x400885D0 // Local address information
|
||||
#define RFCORE_FFSM_SHORT_ADDR1 0x400885D4 // Local address information
|
||||
#define RFCORE_XREG_FRMFILT0 0x40088600 // The frame filtering function
|
||||
#define RFCORE_XREG_SRCMATCH 0x40088608 // Source address matching and pending bits
|
||||
#define RFCORE_XREG_FRMCTRL0 0x40088624 // Frame handling
|
||||
#define RFCORE_XREG_FRMCTRL1 0x40088628 // Frame handling
|
||||
#define RFCORE_XREG_RXENABLE 0x4008862C // RX enabling
|
||||
#define RFCORE_XREG_FREQCTRL 0x4008863C // Controls the RF frequency
|
||||
#define RFCORE_XREG_FSMSTAT1 0x4008864C // Radio status register
|
||||
#define RFCORE_XREG_FIFOPCTRL 0x40088650 // FIFOP threshold
|
||||
#define RFCORE_XREG_CCACTRL0 0x40088658 // CCA threshold
|
||||
#define RFCORE_XREG_RSSISTAT 0x40088664 // RSSI valid status register
|
||||
#define RFCORE_XREG_AGCCTRL1 0x400886C8 // AGC reference level
|
||||
#define RFCORE_XREG_TXFILTCFG 0x400887E8 // TX filter configuration
|
||||
#define RFCORE_SFR_RFDATA 0x40088828 // The TX FIFO and RX FIFO
|
||||
#define RFCORE_SFR_RFERRF 0x4008882C // RF error interrupt flags
|
||||
#define RFCORE_SFR_RFIRQF0 0x40088834 // RF interrupt flags
|
||||
#define RFCORE_SFR_RFST 0x40088838 // RF CSMA-CA/strobe processor
|
||||
|
||||
#define RFCORE_XREG_FRMFILT0_FRAME_FILTER_EN 0x00000001 // Enables frame filtering
|
||||
|
||||
#define RFCORE_XREG_FRMCTRL0_AUTOACK 0x00000020
|
||||
#define RFCORE_XREG_FRMCTRL0_AUTOCRC 0x00000040
|
||||
|
||||
#define RFCORE_XREG_FRMCTRL1_PENDING_OR 0x00000004
|
||||
|
||||
#define RFCORE_XREG_FSMSTAT1_TX_ACTIVE 0x00000002
|
||||
#define RFCORE_XREG_FSMSTAT1_CCA 0x00000010 // Clear channel assessment
|
||||
#define RFCORE_XREG_FSMSTAT1_SFD 0x00000020
|
||||
#define RFCORE_XREG_FSMSTAT1_FIFOP 0x00000040
|
||||
#define RFCORE_XREG_FSMSTAT1_FIFO 0x00000080
|
||||
|
||||
#define RFCORE_XREG_RSSISTAT_RSSI_VALID 0x00000001 // RSSI value is valid.
|
||||
|
||||
#define RFCORE_SFR_RFERRF_RXOVERF 0x00000004 // RX FIFO overflowed.
|
||||
|
||||
#define ANA_REGS_BASE 0x400D6000 // ANA_REGS
|
||||
#define ANA_REGS_O_IVCTRL 0x00000004 // Analog control register
|
||||
|
||||
#define SYS_CTRL_CLOCK_CTRL 0x400D2000 // The clock control register
|
||||
#define SYS_CTRL_SYSDIV_32MHZ 0x00000000 // Sys_div for sysclk 32MHz
|
||||
#define SYS_CTRL_CLOCK_CTRL_AMP_DET 0x00200000
|
||||
|
||||
#define SYS_CTRL_RCGCUART 0x400D2028
|
||||
#define SYS_CTRL_SCGCUART 0x400D202C
|
||||
#define SYS_CTRL_DCGCUART 0x400D2030
|
||||
#define SYS_CTRL_I_MAP 0x400D2098
|
||||
#define SYS_CTRL_RCGCRFC 0x400D20A8
|
||||
#define SYS_CTRL_SCGCRFC 0x400D20AC
|
||||
#define SYS_CTRL_DCGCRFC 0x400D20B0
|
||||
#define SYS_CTRL_EMUOVR 0x400D20B4
|
||||
|
||||
#define SYS_CTRL_RCGCRFC_RFC0 0x00000001
|
||||
#define SYS_CTRL_SCGCRFC_RFC0 0x00000001
|
||||
#define SYS_CTRL_DCGCRFC_RFC0 0x00000001
|
||||
|
||||
#define SYS_CTRL_I_MAP_ALTMAP 0x00000001
|
||||
|
||||
#define SYS_CTRL_RCGCUART_UART0 0x00000001
|
||||
#define SYS_CTRL_SCGCUART_UART0 0x00000001
|
||||
#define SYS_CTRL_DCGCUART_UART0 0x00000001
|
||||
|
||||
#define IOC_PA0_SEL 0x400D4000 // Peripheral select control
|
||||
#define IOC_PA1_SEL 0x400D4004 // Peripheral select control
|
||||
#define IOC_UARTRXD_UART0 0x400D4100
|
||||
|
||||
#define IOC_PA0_OVER 0x400D4080
|
||||
#define IOC_PA1_OVER 0x400D4084
|
||||
|
||||
#define IOC_MUX_OUT_SEL_UART0_TXD 0x00000000
|
||||
|
||||
#define IOC_OVERRIDE_OE 0x00000008 // PAD Config Override Output Enable
|
||||
#define IOC_OVERRIDE_DIS 0x00000000 // PAD Config Override Disabled
|
||||
|
||||
#define UART0_BASE 0x4000C000
|
||||
#define GPIO_A_BASE 0x400D9000 // GPIO
|
||||
|
||||
#define GPIO_O_DIR 0x00000400
|
||||
#define GPIO_O_AFSEL 0x00000420
|
||||
|
||||
#define GPIO_PIN_0 0x00000001 // GPIO pin 0
|
||||
#define GPIO_PIN_1 0x00000002 // GPIO pin 1
|
||||
|
||||
#define UART_O_DR 0x00000000 // UART data
|
||||
#define UART_O_FR 0x00000018 // UART flag
|
||||
#define UART_O_IBRD 0x00000024
|
||||
#define UART_O_FBRD 0x00000028
|
||||
#define UART_O_LCRH 0x0000002C
|
||||
#define UART_O_CTL 0x00000030 // UART control
|
||||
#define UART_O_IM 0x00000038 // UART interrupt mask
|
||||
#define UART_O_MIS 0x00000040 // UART masked interrupt status
|
||||
#define UART_O_ICR 0x00000044 // UART interrupt clear
|
||||
#define UART_O_CC 0x00000FC8 // UART clock configuration
|
||||
|
||||
#define UART_FR_RXFE 0x00000010 // UART receive FIFO empty
|
||||
#define UART_FR_TXFF 0x00000020 // UART transmit FIFO full
|
||||
#define UART_FR_RXFF 0x00000040 // UART receive FIFO full
|
||||
|
||||
#define UART_CONFIG_WLEN_8 0x00000060 // 8 bit data
|
||||
#define UART_CONFIG_STOP_ONE 0x00000000 // One stop bit
|
||||
#define UART_CONFIG_PAR_NONE 0x00000000 // No parity
|
||||
|
||||
#define UART_CTL_UARTEN 0x00000001 // UART enable
|
||||
#define UART_CTL_TXE 0x00000100 // UART transmit enable
|
||||
#define UART_CTL_RXE 0x00000200 // UART receive enable
|
||||
|
||||
#define UART_IM_RXIM 0x00000010 // UART receive interrupt mask
|
||||
#define UART_IM_RTIM 0x00000040 // UART receive time-out interrupt
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Nest Labs, Inc.
|
||||
* 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
|
||||
* GCC linker script for CC2538.
|
||||
*/
|
||||
|
||||
MEMORY
|
||||
{
|
||||
FLASH (rx) : ORIGIN = 0x00200000, LENGTH = 0x0007FFD4
|
||||
FLASH_CCA (rx) : ORIGIN = 0x0027FFD4, LENGTH = 0x2C
|
||||
SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K
|
||||
}
|
||||
|
||||
ENTRY(flash_cca_lock_page)
|
||||
SECTIONS
|
||||
{
|
||||
.text : ALIGN(4)
|
||||
{
|
||||
_text = .;
|
||||
*(.vectors)
|
||||
*(.text*)
|
||||
*(.rodata*)
|
||||
KEEP(*(.init))
|
||||
KEEP(*(.fini))
|
||||
_etext = .;
|
||||
} > FLASH= 0
|
||||
|
||||
.init_array :
|
||||
{
|
||||
_init_array = .;
|
||||
KEEP(*(SORT(.init_array.*)))
|
||||
KEEP(*(.init_array*))
|
||||
_einit_array = .;
|
||||
} > FLASH
|
||||
|
||||
.data : ALIGN(4)
|
||||
{
|
||||
_data = .;
|
||||
*(.data*)
|
||||
_edata = .;
|
||||
} > SRAM AT > FLASH
|
||||
_ldata = LOADADDR(.data);
|
||||
|
||||
.bss : ALIGN(4)
|
||||
{
|
||||
_bss = .;
|
||||
*(.bss*)
|
||||
*(COMMON)
|
||||
_ebss = .;
|
||||
} > SRAM
|
||||
|
||||
_heap = .;
|
||||
end = .;
|
||||
|
||||
.stack : ALIGN(4)
|
||||
{
|
||||
*(.stack)
|
||||
} > SRAM
|
||||
|
||||
.flashcca :
|
||||
{
|
||||
KEEP(*(.flash_cca))
|
||||
} > FLASH_CCA
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Nest Labs, Inc.
|
||||
* 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 <platform/logging.h>
|
||||
|
||||
void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Nest Labs, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief
|
||||
* This file includes the platform-specific initializers.
|
||||
*/
|
||||
|
||||
#include <platform/serial.h>
|
||||
#include "platform.h"
|
||||
|
||||
void PlatformInit(void)
|
||||
{
|
||||
PlatformAlarmInit();
|
||||
PlatformRadioInit();
|
||||
PlatformRandomInit();
|
||||
otPlatSerialEnable();
|
||||
}
|
||||
|
||||
void PlatformProcessDrivers(void)
|
||||
{
|
||||
// should sleep and wait for interrupts here
|
||||
|
||||
PlatformSerialProcess();
|
||||
PlatformRadioProcess();
|
||||
PlatformAlarmProcess();
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Nest Labs, Inc.
|
||||
* 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_H_
|
||||
#define PLATFORM_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This method performs all platform-specific initialization.
|
||||
*
|
||||
*/
|
||||
void PlatformInit(void);
|
||||
|
||||
/**
|
||||
* This method performs all platform-specific processing.
|
||||
*
|
||||
*/
|
||||
void PlatformProcessDrivers(void);
|
||||
|
||||
/**
|
||||
* This method initializes the alarm service used by OpenThread.
|
||||
*
|
||||
*/
|
||||
void PlatformAlarmInit(void);
|
||||
|
||||
/**
|
||||
* This method performs alarm driver processing.
|
||||
*
|
||||
*/
|
||||
void PlatformAlarmProcess(void);
|
||||
|
||||
/**
|
||||
* This method initializes the radio service used by OpenThread.
|
||||
*
|
||||
*/
|
||||
void PlatformRadioInit(void);
|
||||
|
||||
/**
|
||||
* This method performs radio driver processing.
|
||||
*
|
||||
*/
|
||||
void PlatformRadioProcess(void);
|
||||
|
||||
/**
|
||||
* This method initializes the random number service used by OpenThread.
|
||||
*
|
||||
*/
|
||||
void PlatformRandomInit(void);
|
||||
|
||||
/**
|
||||
* This method performs radio driver processing.
|
||||
*
|
||||
*/
|
||||
void PlatformSerialProcess(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // PLATFORM_H_
|
||||
@@ -0,0 +1,430 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Nest Labs, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file implements the OpenThread platform abstraction for radio communication.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <openthread-types.h>
|
||||
|
||||
#include <common/code_utils.hpp>
|
||||
#include <platform/radio.h>
|
||||
#include "cc2538-reg.h"
|
||||
|
||||
enum
|
||||
{
|
||||
IEEE802154_MIN_LENGTH = 5,
|
||||
IEEE802154_MAX_LENGTH = 127,
|
||||
IEEE802154_ACK_LENGTH = 5,
|
||||
IEEE802154_FRAME_TYPE_MASK = 0x7,
|
||||
IEEE802154_FRAME_TYPE_ACK = 0x2,
|
||||
IEEE802154_FRAME_PENDING = 1 << 4,
|
||||
IEEE802154_ACK_REQUEST = 1 << 5,
|
||||
IEEE802154_DSN_OFFSET = 2,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CC2538_RF_CSP_OP_ISRXON = 0xE3,
|
||||
CC2538_RF_CSP_OP_ISTXON = 0xE9,
|
||||
CC2538_RF_CSP_OP_ISRFOFF = 0xEF,
|
||||
CC2538_RF_CSP_OP_ISFLUSHRX = 0xED,
|
||||
CC2538_RF_CSP_OP_ISFLUSHTX = 0xEE,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CC2538_RSSI_OFFSET = 73,
|
||||
CC2538_CRC_BIT_MASK = 0x80,
|
||||
CC2538_LQI_BIT_MASK = 0x7f,
|
||||
};
|
||||
|
||||
static RadioPacket sTransmitFrame;
|
||||
static RadioPacket sReceiveFrame;
|
||||
static ThreadError sTransmitError;
|
||||
static ThreadError sReceiveError;
|
||||
|
||||
static uint8_t sTransmitPsdu[IEEE802154_MAX_LENGTH];
|
||||
static uint8_t sReceivePsdu[IEEE802154_MAX_LENGTH];
|
||||
|
||||
typedef enum PhyState
|
||||
{
|
||||
kStateDisabled = 0,
|
||||
kStateSleep,
|
||||
kStateIdle,
|
||||
kStateListen,
|
||||
kStateReceive,
|
||||
kStateTransmit,
|
||||
} PhyState;
|
||||
|
||||
static PhyState sState;
|
||||
|
||||
void enableReceiver(void)
|
||||
{
|
||||
// flush rxfifo
|
||||
HWREG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISFLUSHRX;
|
||||
HWREG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISFLUSHRX;
|
||||
|
||||
// enable receiver
|
||||
HWREG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISRXON;
|
||||
}
|
||||
|
||||
void disableReceiver(void)
|
||||
{
|
||||
while (HWREG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_TX_ACTIVE);
|
||||
|
||||
// flush rxfifo
|
||||
HWREG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISFLUSHRX;
|
||||
HWREG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISFLUSHRX;
|
||||
|
||||
if (HWREG(RFCORE_XREG_RXENABLE) != 0)
|
||||
{
|
||||
// disable receiver
|
||||
HWREG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISRFOFF;
|
||||
}
|
||||
}
|
||||
|
||||
void setChannel(uint8_t channel)
|
||||
{
|
||||
HWREG(RFCORE_XREG_FREQCTRL) = 11 + (channel - 11) * 5;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioSetPanId(uint16_t panid)
|
||||
{
|
||||
HWREG(RFCORE_FFSM_PAN_ID0) = panid & 0xFF;
|
||||
HWREG(RFCORE_FFSM_PAN_ID1) = panid >> 8;
|
||||
return kThreadError_None;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioSetExtendedAddress(uint8_t *address)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
((volatile uint32_t *)RFCORE_FFSM_EXT_ADDR0)[i] = address[i];
|
||||
}
|
||||
|
||||
return kThreadError_None;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioSetShortAddress(uint16_t address)
|
||||
{
|
||||
HWREG(RFCORE_FFSM_SHORT_ADDR0) = address & 0xFF;
|
||||
HWREG(RFCORE_FFSM_SHORT_ADDR1) = address >> 8;
|
||||
return kThreadError_None;
|
||||
}
|
||||
|
||||
void PlatformRadioInit(void)
|
||||
{
|
||||
sTransmitFrame.mLength = 0;
|
||||
sTransmitFrame.mPsdu = sTransmitPsdu;
|
||||
sReceiveFrame.mLength = 0;
|
||||
sReceiveFrame.mPsdu = sReceivePsdu;
|
||||
|
||||
// enable clock
|
||||
HWREG(SYS_CTRL_RCGCRFC) = SYS_CTRL_RCGCRFC_RFC0;
|
||||
HWREG(SYS_CTRL_SCGCRFC) = SYS_CTRL_SCGCRFC_RFC0;
|
||||
HWREG(SYS_CTRL_DCGCRFC) = SYS_CTRL_DCGCRFC_RFC0;
|
||||
|
||||
// Table 23-7.
|
||||
HWREG(RFCORE_XREG_AGCCTRL1) = 0x15;
|
||||
HWREG(RFCORE_XREG_TXFILTCFG) = 0x09;
|
||||
HWREG(ANA_REGS_BASE + ANA_REGS_O_IVCTRL) = 0x0b;
|
||||
|
||||
HWREG(RFCORE_XREG_CCACTRL0) = 0xf8;
|
||||
HWREG(RFCORE_XREG_FIFOPCTRL) = IEEE802154_MAX_LENGTH;
|
||||
|
||||
HWREG(RFCORE_XREG_FRMCTRL0) = RFCORE_XREG_FRMCTRL0_AUTOCRC | RFCORE_XREG_FRMCTRL0_AUTOACK;
|
||||
HWREG(RFCORE_XREG_FRMCTRL1) |= RFCORE_XREG_FRMCTRL1_PENDING_OR;
|
||||
|
||||
// disable source address matching
|
||||
HWREG(RFCORE_XREG_SRCMATCH) = 0;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioEnable(void)
|
||||
{
|
||||
ThreadError error = kThreadError_None;
|
||||
|
||||
VerifyOrExit(sState == kStateDisabled, error = kThreadError_Busy);
|
||||
sState = kStateSleep;
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioDisable(void)
|
||||
{
|
||||
ThreadError error = kThreadError_None;
|
||||
|
||||
VerifyOrExit(sState == kStateIdle, error = kThreadError_Busy);
|
||||
sState = kStateDisabled;
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioSleep(void)
|
||||
{
|
||||
ThreadError error = kThreadError_None;
|
||||
|
||||
VerifyOrExit(error = kStateIdle, error = kThreadError_Busy);
|
||||
sState = kStateSleep;
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioIdle(void)
|
||||
{
|
||||
ThreadError error = kThreadError_None;
|
||||
|
||||
switch (sState)
|
||||
{
|
||||
case kStateSleep:
|
||||
sState = kStateIdle;
|
||||
break;
|
||||
|
||||
case kStateIdle:
|
||||
break;
|
||||
|
||||
case kStateListen:
|
||||
case kStateTransmit:
|
||||
disableReceiver();
|
||||
sState = kStateIdle;
|
||||
break;
|
||||
|
||||
case kStateReceive:
|
||||
case kStateDisabled:
|
||||
ExitNow(error = kThreadError_Busy);
|
||||
break;
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioReceive(uint8_t aChannel)
|
||||
{
|
||||
ThreadError error = kThreadError_None;
|
||||
|
||||
VerifyOrExit(sState == kStateIdle, error = kThreadError_Busy);
|
||||
sState = kStateListen;
|
||||
|
||||
setChannel(aChannel);
|
||||
enableReceiver();
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
RadioPacket *otPlatRadioGetTransmitBuffer(void)
|
||||
{
|
||||
return &sTransmitFrame;
|
||||
}
|
||||
|
||||
ThreadError otPlatRadioTransmit(void)
|
||||
{
|
||||
ThreadError error = kThreadError_None;
|
||||
int i;
|
||||
|
||||
VerifyOrExit(sState == kStateIdle, error = kThreadError_Busy);
|
||||
sState = kStateTransmit;
|
||||
sTransmitError = kThreadError_None;
|
||||
|
||||
while (HWREG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_TX_ACTIVE);
|
||||
|
||||
// flush txfifo
|
||||
HWREG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISFLUSHTX;
|
||||
HWREG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISFLUSHTX;
|
||||
|
||||
// frame length
|
||||
HWREG(RFCORE_SFR_RFDATA) = sTransmitFrame.mLength;
|
||||
|
||||
// frame data
|
||||
for (i = 0; i < sTransmitFrame.mLength; i++)
|
||||
{
|
||||
HWREG(RFCORE_SFR_RFDATA) = sTransmitFrame.mPsdu[i];
|
||||
}
|
||||
|
||||
setChannel(sTransmitFrame.mChannel);
|
||||
enableReceiver();
|
||||
|
||||
while ((HWREG(RFCORE_XREG_FSMSTAT1) & 1) == 0);
|
||||
|
||||
// wait for valid rssi
|
||||
while ((HWREG(RFCORE_XREG_RSSISTAT) & RFCORE_XREG_RSSISTAT_RSSI_VALID) == 0);
|
||||
|
||||
VerifyOrExit(HWREG(RFCORE_XREG_FSMSTAT1) & (RFCORE_XREG_FSMSTAT1_CCA | RFCORE_XREG_FSMSTAT1_SFD),
|
||||
sTransmitError = kThreadError_ChannelAccessFailure);
|
||||
|
||||
// begin transmit
|
||||
HWREG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISTXON;
|
||||
|
||||
while (HWREG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_TX_ACTIVE);
|
||||
|
||||
exit:
|
||||
|
||||
if (sTransmitError != kThreadError_None || (sTransmitFrame.mPsdu[0] & IEEE802154_ACK_REQUEST) == 0)
|
||||
{
|
||||
disableReceiver();
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
int8_t otPlatRadioGetNoiseFloor(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
otRadioCaps otPlatRadioGetCaps(void)
|
||||
{
|
||||
return kRadioCapsNone;
|
||||
}
|
||||
|
||||
bool otPlatRadioGetPromiscuous(void)
|
||||
{
|
||||
return (HWREG(RFCORE_XREG_FRMFILT0) & RFCORE_XREG_FRMFILT0_FRAME_FILTER_EN) == 0;
|
||||
}
|
||||
|
||||
void otPlatRadioSetPromiscuous(bool aEnable)
|
||||
{
|
||||
if (aEnable)
|
||||
{
|
||||
HWREG(RFCORE_XREG_FRMFILT0) &= ~RFCORE_XREG_FRMFILT0_FRAME_FILTER_EN;
|
||||
}
|
||||
else
|
||||
{
|
||||
HWREG(RFCORE_XREG_FRMFILT0) |= RFCORE_XREG_FRMFILT0_FRAME_FILTER_EN;
|
||||
}
|
||||
}
|
||||
|
||||
void readFrame(void)
|
||||
{
|
||||
uint8_t length;
|
||||
uint8_t crcCorr;
|
||||
int i;
|
||||
|
||||
VerifyOrExit(sState == kStateListen || sState == kStateTransmit, ;);
|
||||
VerifyOrExit((HWREG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_FIFOP) != 0, ;);
|
||||
|
||||
// read length
|
||||
length = HWREG(RFCORE_SFR_RFDATA);
|
||||
VerifyOrExit(IEEE802154_MIN_LENGTH <= length && length <= IEEE802154_MAX_LENGTH, ;);
|
||||
|
||||
// read psdu
|
||||
for (i = 0; i < length - 2; i++)
|
||||
{
|
||||
sReceiveFrame.mPsdu[i] = HWREG(RFCORE_SFR_RFDATA);
|
||||
}
|
||||
|
||||
sReceiveFrame.mPower = (int8_t)HWREG(RFCORE_SFR_RFDATA) - CC2538_RSSI_OFFSET;
|
||||
crcCorr = HWREG(RFCORE_SFR_RFDATA);
|
||||
|
||||
if (crcCorr & CC2538_CRC_BIT_MASK)
|
||||
{
|
||||
sReceiveFrame.mLength = length;
|
||||
sReceiveFrame.mLqi = crcCorr & CC2538_LQI_BIT_MASK;
|
||||
}
|
||||
|
||||
// check for rxfifo overflow
|
||||
if ((HWREG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_FIFOP) != 0 &&
|
||||
(HWREG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_FIFO) != 0)
|
||||
{
|
||||
HWREG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISFLUSHRX;
|
||||
HWREG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISFLUSHRX;
|
||||
}
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
int PlatformRadioProcess(void)
|
||||
{
|
||||
readFrame();
|
||||
|
||||
switch (sState)
|
||||
{
|
||||
case kStateDisabled:
|
||||
break;
|
||||
|
||||
case kStateSleep:
|
||||
break;
|
||||
|
||||
case kStateIdle:
|
||||
break;
|
||||
|
||||
case kStateListen:
|
||||
case kStateReceive:
|
||||
if (sReceiveFrame.mLength > 0)
|
||||
{
|
||||
sState = kStateIdle;
|
||||
otPlatRadioReceiveDone(&sReceiveFrame, sReceiveError);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case kStateTransmit:
|
||||
if (sTransmitError != kThreadError_None || (sTransmitFrame.mPsdu[0] & IEEE802154_ACK_REQUEST) == 0)
|
||||
{
|
||||
sState = kStateIdle;
|
||||
otPlatRadioTransmitDone(false, sTransmitError);
|
||||
}
|
||||
else if (sReceiveFrame.mLength == IEEE802154_ACK_LENGTH &&
|
||||
(sReceiveFrame.mPsdu[0] & IEEE802154_FRAME_TYPE_MASK) == IEEE802154_FRAME_TYPE_ACK &&
|
||||
(sReceiveFrame.mPsdu[IEEE802154_DSN_OFFSET] == sTransmitFrame.mPsdu[IEEE802154_DSN_OFFSET]))
|
||||
{
|
||||
sState = kStateIdle;
|
||||
otPlatRadioTransmitDone((sReceiveFrame.mPsdu[0] & IEEE802154_FRAME_PENDING) != 0, sTransmitError);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
sReceiveFrame.mLength = 0;
|
||||
|
||||
if (sState == kStateIdle)
|
||||
{
|
||||
disableReceiver();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void RFCoreRxTxIntHandler(void)
|
||||
{
|
||||
HWREG(RFCORE_SFR_RFIRQF0) = 0;
|
||||
}
|
||||
|
||||
void RFCoreErrIntHandler(void)
|
||||
{
|
||||
HWREG(RFCORE_SFR_RFERRF) = 0;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Nest Labs, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file implements a pseudo-random number generator.
|
||||
*
|
||||
* @warning
|
||||
* This implementation is not a true random number generator and does @em satisfy the Thread requirements.
|
||||
*/
|
||||
|
||||
#include <platform/random.h>
|
||||
#include "cc2538-reg.h"
|
||||
|
||||
static uint32_t s_state = 1;
|
||||
|
||||
void PlatformRandomInit(void)
|
||||
{
|
||||
// use Extended Identifier portion of IEEE EUI-64 as the seed
|
||||
s_state = HWREG(IEEE_EUI64 + 4);
|
||||
}
|
||||
|
||||
uint32_t otPlatRandomGet(void)
|
||||
{
|
||||
uint32_t mlcg, p, q;
|
||||
uint64_t tmpstate;
|
||||
|
||||
tmpstate = (uint64_t)33614 * (uint64_t)s_state;
|
||||
q = tmpstate & 0xffffffff;
|
||||
q = q >> 1;
|
||||
p = tmpstate >> 32;
|
||||
mlcg = p + q;
|
||||
|
||||
if (mlcg & 0x80000000)
|
||||
{
|
||||
mlcg &= 0x7fffffff;
|
||||
mlcg++;
|
||||
}
|
||||
|
||||
s_state = mlcg;
|
||||
|
||||
return mlcg;
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Nest Labs, Inc.
|
||||
* 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 serial communication.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <openthread-types.h>
|
||||
#include <common/code_utils.hpp>
|
||||
#include <platform/serial.h>
|
||||
#include "cc2538-reg.h"
|
||||
|
||||
enum
|
||||
{
|
||||
kPlatformClock = 32000000,
|
||||
kBaudRate = 115200,
|
||||
kReceiveBufferSize = 128,
|
||||
};
|
||||
|
||||
extern void UART0IntHandler(void);
|
||||
|
||||
static void processReceive(void);
|
||||
static void processTransmit(void);
|
||||
|
||||
static const uint8_t *sTransmitBuffer = NULL;
|
||||
static uint16_t sTransmitLength = 0;
|
||||
|
||||
static uint8_t sReceiveBuffer[kReceiveBufferSize];
|
||||
static uint16_t sReceiveHead = 0;
|
||||
static uint16_t sReceiveLength = 0;
|
||||
|
||||
ThreadError otPlatSerialEnable(void)
|
||||
{
|
||||
uint32_t div;
|
||||
|
||||
// clock
|
||||
HWREG(SYS_CTRL_RCGCUART) = SYS_CTRL_RCGCUART_UART0;
|
||||
HWREG(SYS_CTRL_SCGCUART) = SYS_CTRL_SCGCUART_UART0;
|
||||
HWREG(SYS_CTRL_DCGCUART) = SYS_CTRL_DCGCUART_UART0;
|
||||
|
||||
HWREG(UART0_BASE + UART_O_CC) = 0;
|
||||
|
||||
// tx pin
|
||||
HWREG(IOC_PA1_SEL) = IOC_MUX_OUT_SEL_UART0_TXD;
|
||||
HWREG(IOC_PA1_OVER) = IOC_OVERRIDE_OE;
|
||||
HWREG(GPIO_A_BASE + GPIO_O_AFSEL) |= GPIO_PIN_1;
|
||||
|
||||
// rx pin
|
||||
HWREG(IOC_PA0_SEL) = IOC_UARTRXD_UART0;
|
||||
HWREG(IOC_PA0_OVER) = IOC_OVERRIDE_DIS;
|
||||
HWREG(GPIO_A_BASE + GPIO_O_AFSEL) |= GPIO_PIN_0;
|
||||
|
||||
HWREG(UART0_BASE + UART_O_CTL) = 0;
|
||||
|
||||
// baud rate
|
||||
div = (((kPlatformClock * 8) / kBaudRate) + 1) / 2;
|
||||
HWREG(UART0_BASE + UART_O_IBRD) = div / 64;
|
||||
HWREG(UART0_BASE + UART_O_FBRD) = div % 64;
|
||||
HWREG(UART0_BASE + UART_O_LCRH) = UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE;
|
||||
|
||||
// configure interrupts
|
||||
HWREG(UART0_BASE + UART_O_IM) |= UART_IM_RXIM | UART_IM_RTIM;
|
||||
|
||||
// enable
|
||||
HWREG(UART0_BASE + UART_O_CTL) = UART_CTL_UARTEN | UART_CTL_TXE | UART_CTL_RXE;
|
||||
|
||||
// enable interrupts
|
||||
HWREG(NVIC_EN0) = 1 << ((INT_UART0 - 16) & 31);
|
||||
|
||||
return kThreadError_None;
|
||||
}
|
||||
|
||||
ThreadError otPlatSerialDisable(void)
|
||||
{
|
||||
return kThreadError_None;
|
||||
}
|
||||
|
||||
ThreadError otPlatSerialSend(const uint8_t *aBuf, uint16_t aBufLength)
|
||||
{
|
||||
ThreadError error = kThreadError_None;
|
||||
|
||||
VerifyOrExit(sTransmitBuffer == NULL, error = kThreadError_Busy);
|
||||
|
||||
sTransmitBuffer = aBuf;
|
||||
sTransmitLength = aBufLength;
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void processReceive(void)
|
||||
{
|
||||
uint16_t remaining;
|
||||
|
||||
VerifyOrExit(sReceiveLength > 0, ;);
|
||||
|
||||
remaining = kReceiveBufferSize - sReceiveHead;
|
||||
|
||||
if (sReceiveLength >= remaining)
|
||||
{
|
||||
otPlatSerialReceived(sReceiveBuffer + sReceiveHead, remaining);
|
||||
sReceiveHead = 0;
|
||||
sReceiveLength -= remaining;
|
||||
}
|
||||
|
||||
if (sReceiveLength > 0)
|
||||
{
|
||||
otPlatSerialReceived(sReceiveBuffer + sReceiveHead, sReceiveLength);
|
||||
sReceiveHead += sReceiveLength;
|
||||
sReceiveLength = 0;
|
||||
}
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void processTransmit(void)
|
||||
{
|
||||
VerifyOrExit(sTransmitBuffer != NULL, ;);
|
||||
|
||||
for (; sTransmitLength > 0; sTransmitLength--)
|
||||
{
|
||||
while (HWREG(UART0_BASE + UART_O_FR) & UART_FR_TXFF);
|
||||
|
||||
HWREG(UART0_BASE + UART_O_DR) = *sTransmitBuffer++;
|
||||
}
|
||||
|
||||
sTransmitBuffer = NULL;
|
||||
otPlatSerialSendDone();
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void PlatformSerialProcess(void)
|
||||
{
|
||||
processReceive();
|
||||
processTransmit();
|
||||
}
|
||||
|
||||
void UART0IntHandler(void)
|
||||
{
|
||||
uint32_t mis;
|
||||
uint16_t tail;
|
||||
uint8_t byte;
|
||||
|
||||
mis = HWREG(UART0_BASE + UART_O_MIS);
|
||||
HWREG(UART0_BASE + UART_O_ICR) = mis;
|
||||
|
||||
if (mis & (UART_IM_RXIM | UART_IM_RTIM))
|
||||
{
|
||||
while (!(HWREG(UART0_BASE + UART_O_FR) & UART_FR_RXFE))
|
||||
{
|
||||
byte = HWREG(UART0_BASE + UART_O_DR);
|
||||
|
||||
if (sReceiveLength < kReceiveBufferSize)
|
||||
{
|
||||
tail = (sReceiveHead + sReceiveLength) % kReceiveBufferSize;
|
||||
sReceiveBuffer[tail] = byte;
|
||||
sReceiveLength++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Nest Labs, Inc.
|
||||
* 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 gcc-specific startup code for the cc2538.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "cc2538-reg.h"
|
||||
|
||||
extern uint8_t _ldata;
|
||||
extern uint8_t _data;
|
||||
extern uint8_t _edata;
|
||||
extern uint8_t _bss;
|
||||
extern uint8_t _ebss;
|
||||
extern uint8_t _init_array;
|
||||
extern uint8_t _einit_array;
|
||||
|
||||
__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 __cxa_pure_virtual(void) { while (1); }
|
||||
|
||||
void IntDefaultHandler(void);
|
||||
void ResetHandler(void);
|
||||
|
||||
extern void SysTick_Handler(void);
|
||||
extern void UART0IntHandler(void);
|
||||
extern void RFCoreRxTxIntHandler(void);
|
||||
extern void RFCoreErrIntHandler(void);
|
||||
extern void main(void);
|
||||
|
||||
static uint64_t stack[256] __attribute__((section(".stack")));
|
||||
|
||||
__attribute__((section(".vectors"), used))
|
||||
void (*const vectors[])(void) =
|
||||
{
|
||||
(void (*)(void))((unsigned long)stack + sizeof(stack)), // Initial Stack Pointer
|
||||
ResetHandler, // 1 The reset handler
|
||||
ResetHandler, // 2 The NMI handler
|
||||
IntDefaultHandler, // 3 The hard fault handler
|
||||
IntDefaultHandler, // 4 The MPU fault handler
|
||||
IntDefaultHandler, // 5 The bus fault handler
|
||||
IntDefaultHandler, // 6 The usage fault handler
|
||||
0, // 7 Reserved
|
||||
0, // 8 Reserved
|
||||
0, // 9 Reserved
|
||||
0, // 10 Reserved
|
||||
IntDefaultHandler, // 11 SVCall handler
|
||||
IntDefaultHandler, // 12 Debug monitor handler
|
||||
0, // 13 Reserved
|
||||
IntDefaultHandler, // 14 The PendSV handler
|
||||
SysTick_Handler, // 15 The SysTick handler
|
||||
IntDefaultHandler, // 16 GPIO Port A
|
||||
IntDefaultHandler, // 17 GPIO Port B
|
||||
IntDefaultHandler, // 18 GPIO Port C
|
||||
IntDefaultHandler, // 19 GPIO Port D
|
||||
0, // 20 none
|
||||
UART0IntHandler, // 21 UART0 Rx and Tx
|
||||
IntDefaultHandler, // 22 UART1 Rx and Tx
|
||||
IntDefaultHandler, // 23 SSI0 Rx and Tx
|
||||
IntDefaultHandler, // 24 I2C Master and Slave
|
||||
0, // 25 Reserved
|
||||
0, // 26 Reserved
|
||||
0, // 27 Reserved
|
||||
0, // 28 Reserved
|
||||
0, // 29 Reserved
|
||||
IntDefaultHandler, // 30 ADC Sequence 0
|
||||
0, // 31 Reserved
|
||||
0, // 32 Reserved
|
||||
0, // 33 Reserved
|
||||
IntDefaultHandler, // 34 Watchdog timer, timer 0
|
||||
IntDefaultHandler, // 35 Timer 0 subtimer A
|
||||
IntDefaultHandler, // 36 Timer 0 subtimer B
|
||||
IntDefaultHandler, // 37 Timer 1 subtimer A
|
||||
IntDefaultHandler, // 38 Timer 1 subtimer B
|
||||
IntDefaultHandler, // 39 Timer 2 subtimer A
|
||||
IntDefaultHandler, // 40 Timer 2 subtimer B
|
||||
IntDefaultHandler, // 41 Analog Comparator 0
|
||||
RFCoreRxTxIntHandler, // 42 RFCore Rx/Tx
|
||||
RFCoreErrIntHandler, // 43 RFCore Error
|
||||
IntDefaultHandler, // 44 IcePick
|
||||
IntDefaultHandler, // 45 FLASH Control
|
||||
IntDefaultHandler, // 46 AES
|
||||
IntDefaultHandler, // 47 PKA
|
||||
IntDefaultHandler, // 48 Sleep Timer
|
||||
IntDefaultHandler, // 49 MacTimer
|
||||
IntDefaultHandler, // 50 SSI1 Rx and Tx
|
||||
IntDefaultHandler, // 51 Timer 3 subtimer A
|
||||
IntDefaultHandler, // 52 Timer 3 subtimer B
|
||||
0, // 53 Reserved
|
||||
0, // 54 Reserved
|
||||
0, // 55 Reserved
|
||||
0, // 56 Reserved
|
||||
0, // 57 Reserved
|
||||
0, // 58 Reserved
|
||||
0, // 59 Reserved
|
||||
IntDefaultHandler, // 60 USB 2538
|
||||
0, // 61 Reserved
|
||||
IntDefaultHandler, // 62 uDMA
|
||||
IntDefaultHandler, // 63 uDMA Error
|
||||
};
|
||||
|
||||
void IntDefaultHandler(void)
|
||||
{
|
||||
while (1);
|
||||
}
|
||||
|
||||
#define FLASH_CCA_BOOTLDR_CFG_DISABLE 0xEFFFFFFF ///< Disable backdoor function
|
||||
#define FLASH_CCA_BOOTLDR_CFG_ENABLE 0xF0FFFFFF ///< Enable backdoor function
|
||||
#define FLASH_CCA_BOOTLDR_CFG_ACTIVE_HIGH 0x08000000 ///< Selected pin on pad A active high
|
||||
#define FLASH_CCA_BOOTLDR_CFG_PORT_A_PIN_M 0x07000000 ///< Selected pin on pad A mask
|
||||
#define FLASH_CCA_BOOTLDR_CFG_PORT_A_PIN_S 24 ///< Selected pin on pad A shift
|
||||
#define FLASH_CCA_IMAGE_VALID 0x00000000 ///< Indicates valid image in flash
|
||||
|
||||
#define FLASH_CCA_CONF_BOOTLDR_BACKDOOR_PORT_A_PIN 3 ///< Select Button on SmartRF06 Eval Board
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t ui32BootldrCfg;
|
||||
uint32_t ui32ImageValid;
|
||||
uint32_t ui32ImageVectorAddr;
|
||||
uint8_t ui8lock[32];
|
||||
} flash_cca_lock_page_t;
|
||||
|
||||
__attribute__((__section__(".flashcca"), used))
|
||||
const flash_cca_lock_page_t flash_cca_lock_page =
|
||||
{
|
||||
FLASH_CCA_BOOTLDR_CFG_ENABLE | (FLASH_CCA_CONF_BOOTLDR_BACKDOOR_PORT_A_PIN << FLASH_CCA_BOOTLDR_CFG_PORT_A_PIN_S),
|
||||
FLASH_CCA_IMAGE_VALID,
|
||||
(uint32_t) &vectors,
|
||||
{
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
|
||||
}
|
||||
};
|
||||
|
||||
typedef void (*init_fn_t)(void);
|
||||
|
||||
void ResetHandler(void)
|
||||
{
|
||||
HWREG(SYS_CTRL_EMUOVR) = 0xFF;
|
||||
|
||||
// configure clocks
|
||||
HWREG(SYS_CTRL_CLOCK_CTRL) |= SYS_CTRL_CLOCK_CTRL_AMP_DET;
|
||||
HWREG(SYS_CTRL_CLOCK_CTRL) = SYS_CTRL_SYSDIV_32MHZ;
|
||||
|
||||
// alternate map
|
||||
HWREG(SYS_CTRL_I_MAP) |= SYS_CTRL_I_MAP_ALTMAP;
|
||||
|
||||
// copy the data segment initializers from flash to SRAM
|
||||
memcpy(&_data, &_ldata, &_edata - &_data);
|
||||
|
||||
// zero-fill the bss segment
|
||||
memset(&_bss, 0, &_ebss - &_bss);
|
||||
|
||||
// C++ runtime initialization (BSS, Data, relocation, etc.)
|
||||
init_fn_t *fp;
|
||||
|
||||
for (fp = (init_fn_t *)&_init_array; fp < (init_fn_t *)&_einit_array; fp++)
|
||||
{
|
||||
(*fp)();
|
||||
}
|
||||
|
||||
// call the application's entry point
|
||||
main();
|
||||
|
||||
// end here if main() returns
|
||||
while (1);
|
||||
}
|
||||
@@ -108,8 +108,15 @@ const uint8_t *otGetExtendedPanId(void)
|
||||
|
||||
void otSetExtendedPanId(const uint8_t *aExtendedPanId)
|
||||
{
|
||||
uint8_t mlPrefix[8];
|
||||
|
||||
sThreadNetif->GetMac().SetExtendedPanId(aExtendedPanId);
|
||||
sThreadNetif->GetMle().SetMeshLocalPrefix(aExtendedPanId);
|
||||
|
||||
mlPrefix[0] = 0xfd;
|
||||
memcpy(mlPrefix + 1, aExtendedPanId, 5);
|
||||
mlPrefix[6] = 0x00;
|
||||
mlPrefix[7] = 0x00;
|
||||
sThreadNetif->GetMle().SetMeshLocalPrefix(mlPrefix);
|
||||
}
|
||||
|
||||
ThreadError otGetLeaderRloc(otIp6Address *aAddress)
|
||||
|
||||
Reference in New Issue
Block a user