diff --git a/configure.ac b/configure.ac index 8c0c7fcca..5ee4e4ad7 100644 --- a/configure.ac +++ b/configure.ac @@ -804,14 +804,14 @@ AC_MSG_CHECKING([whether to build examples]) AC_ARG_WITH(examples, [AS_HELP_STRING([--with-examples=TARGET], - [Build example applications for one of: simulation, cc2538 @<:@default=no@:>@. + [Build example applications for one of: simulation @<:@default=no@:>@. Note that building example applications also builds the associated OpenThread platform libraries and any third_party libraries needed to support the examples.])], [ case "${with_examples}" in no) ;; - simulation|cc2538) + simulation) ;; *) AC_MSG_RESULT(ERROR) @@ -824,7 +824,6 @@ AC_ARG_WITH(examples, AM_CONDITIONAL([OPENTHREAD_ENABLE_EXAMPLES], [test ${with_examples} != "no"]) AM_CONDITIONAL([OPENTHREAD_EXAMPLES_SIMULATION],[test "${with_examples}" = "simulation"]) -AM_CONDITIONAL([OPENTHREAD_EXAMPLES_CC2538], [test "${with_examples}" = "cc2538"]) AM_COND_IF([OPENTHREAD_EXAMPLES_SIMULATION], CPPFLAGS="${CPPFLAGS} -DOPENTHREAD_EXAMPLES_SIMULATION=1", CPPFLAGS="${CPPFLAGS} -DOPENTHREAD_EXAMPLES_SIMULATION=0") @@ -845,11 +844,11 @@ AC_MSG_CHECKING([whether to build platform libraries]) AC_ARG_WITH(platform, [AS_HELP_STRING([--with-platform=TARGET], - [Build OpenThread platform libraries for one of: cc2538, posix, simulation @<:@default=simulation@:>@.])], + [Build OpenThread platform libraries for one of: posix, simulation @<:@default=simulation@:>@.])], [ # Make sure the given target is valid. case "${with_platform}" in - no|cc2538|posix|simulation) + no|posix|simulation) ;; *) AC_MSG_RESULT(ERROR) @@ -880,7 +879,6 @@ AM_CONDITIONAL([OPENTHREAD_ENABLE_PLATFORM], [test ${with_platform} != "no"]) OPENTHREAD_ENABLE_PLATFORM=${with_platform} -AM_CONDITIONAL([OPENTHREAD_PLATFORM_CC2538], [test "${with_platform}" = "cc2538"]) AM_CONDITIONAL([OPENTHREAD_PLATFORM_POSIX], [test "${with_platform}" = "posix"]) AM_CONDITIONAL([OPENTHREAD_PLATFORM_SIMULATION],[test "${with_platform}" = "simulation"]) @@ -1023,7 +1021,6 @@ examples/apps/Makefile examples/apps/cli/Makefile examples/apps/ncp/Makefile examples/platforms/Makefile -examples/platforms/cc2538/Makefile examples/platforms/simulation/Makefile examples/platforms/utils/Makefile tools/Makefile diff --git a/examples/Makefile-cc2538 b/examples/Makefile-cc2538 deleted file mode 100644 index 99d895a53..000000000 --- a/examples/Makefile-cc2538 +++ /dev/null @@ -1,309 +0,0 @@ -# -# Copyright (c) 2016, 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 \ - --enable-ftd \ - --enable-mtd \ - --enable-ncp \ - --enable-radio-only \ - --enable-linker-map \ - --with-examples=cc2538 \ - $(NULL) - -TopSourceDir := $(dir $(shell readlink $(firstword $(MAKEFILE_LIST)))).. -AbsTopSourceDir := $(dir $(realpath $(firstword $(MAKEFILE_LIST)))).. - -CC2538_CONFIG_FILE_CPPFLAGS = -DOPENTHREAD_PROJECT_CORE_CONFIG_FILE='\"openthread-core-cc2538-config.h\"' -CC2538_CONFIG_FILE_CPPFLAGS += -DOPENTHREAD_CORE_CONFIG_PLATFORM_CHECK_FILE='\"openthread-core-cc2538-config-check.h\"' -CC2538_CONFIG_FILE_CPPFLAGS += -I$(AbsTopSourceDir)/examples/platforms/cc2538/ - -COMMONCFLAGS := \ - -fdata-sections \ - -ffunction-sections \ - -Os \ - -g \ - $(CC2538_CONFIG_FILE_CPPFLAGS) \ - $(NULL) - -include $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/common-switches.mk - -# Optional CC2592 options, first and foremost, whether to enable support for it -# at all. -ifeq ($(CC2592),1) -COMMONCFLAGS += -DOPENTHREAD_CONFIG_CC2538_WITH_CC2592=1 - -# If the PA_EN is on another port C pin, specify it with CC2592_PA_PIN. -ifneq ($(CC2592_PA_EN),) -COMMONCFLAGS += -DOPENTHREAD_CONFIG_CC2592_PA_EN_PIN=$(CC2592_PA_EN) -endif - -# If the LNA_EN is on another port C pin, specify it with CC2592_LNA_PIN. -ifneq ($(CC2592_LNA_EN),) -COMMONCFLAGS += -DOPENTHREAD_CONFIG_CC2592_LNA_EN_PIN=$(CC2592_LNA_EN) -endif - -# If we're not using HGM, set CC2538_USE_HGM to 0. -ifeq ($(CC2592_USE_HGM),0) -COMMONCFLAGS += -DOPENTHREAD_CONFIG_CC2592_USE_HGM=0 -else # CC2592_USE_HGM=1 - -# HGM in use, if not on port D, specify the port here (A, B or C) with CC2592_HGM_PORT. -ifneq ($(CC2592_HGM_PORT),) -COMMONCFLAGS += -DOPENTHREAD_CONFIG_CC2592_HGM_PORT=GPIO_$(CC2592_HGM_PORT)_BASE -endif - -# If HGM is not at pin 2, specify which pin here with CC2592_HGM_PIN. -ifneq ($(CC2592_HGM_PIN),) -COMMONCFLAGS += -DOPENTHREAD_CONFIG_CC2592_HGM_PIN=$(CC2592_HGM_PIN) -endif - -# If we want it off by default, specify CC2592_HGM_DEFAULT_STATE=0 -ifeq ($(CC2592_HGM_DEFAULT_STATE),0) -COMMONCFLAGS += -DOPENTHREAD_CONFIG_CC2592_HGM_DEFAULT_STATE=false -endif - -endif # CC2592_USE_HGM - -endif # CC2592 - -ifneq ($(CC2538_RECEIVE_SENSITIVITY),) -COMMONCFLAGS += -DOPENTHREAD_CONFIG_CC2538_RECEIVE_SENSITIVITY=$(CC2538_RECEIVE_SENSITIVITY) -endif - -ifneq ($(CC2538_RSSI_OFFSET),) -COMMONCFLAGS += -DOPENTHREAD_CONFIG_CC2538_RSSI_OFFSET=$(CC2538_RSSI_OFFSET) -endif - -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 \ - $(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 = cc2538 - -ARCHS = cortex-m3 - -TopTargetLibDir = $(TopResultDir)/$(TargetTuple)/lib - -ifndef BuildJobs -BuildJobs := $(shell getconf _NPROCESSORS_ONLN) -endif -JOBSFLAG := -j$(BuildJobs) - -# -# configure-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 -# -# 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 -# -# 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 -# -# 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-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)) " - $(ECHO) "" diff --git a/examples/platforms/Makefile.am b/examples/platforms/Makefile.am index e7bd3ed6c..7f86919d8 100644 --- a/examples/platforms/Makefile.am +++ b/examples/platforms/Makefile.am @@ -30,6 +30,7 @@ include $(abs_top_nlbuild_autotools_dir)/automake/pre.am EXTRA_DIST = \ cc1352 \ + cc2538 \ cc2652 \ efr32 \ gp712 \ @@ -45,7 +46,6 @@ EXTRA_DIST = \ # Always package (e.g. for 'make dist') these subdirectories. DIST_SUBDIRS = \ - cc2538 \ simulation \ utils \ $(NULL) @@ -56,10 +56,6 @@ SUBDIRS = \ utils \ $(NULL) -if OPENTHREAD_PLATFORM_CC2538 -SUBDIRS += cc2538 -endif - if OPENTHREAD_PLATFORM_SIMULATION SUBDIRS += simulation endif diff --git a/examples/platforms/Makefile.platform.am b/examples/platforms/Makefile.platform.am index 8ab6520e2..71b82b0c2 100644 --- a/examples/platforms/Makefile.platform.am +++ b/examples/platforms/Makefile.platform.am @@ -41,10 +41,6 @@ LDFLAGS_COMMON = $(NULL) SOURCES_COMMON = $(NULL) LIBTOOLFLAGS_COMMON = --preserve-dup-deps -if OPENTHREAD_EXAMPLES_CC2538 -include $(top_srcdir)/examples/platforms/cc2538/Makefile.platform.am -endif - if OPENTHREAD_EXAMPLES_SIMULATION include $(top_srcdir)/examples/platforms/simulation/Makefile.platform.am endif diff --git a/examples/platforms/cc2538/CMakeLists.txt b/examples/platforms/cc2538/CMakeLists.txt deleted file mode 100644 index f8ed5f212..000000000 --- a/examples/platforms/cc2538/CMakeLists.txt +++ /dev/null @@ -1,79 +0,0 @@ -# -# Copyright (c) 2019, 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. -# - -set(OT_PLATFORM_LIB "openthread-cc2538" PARENT_SCOPE) - -if(NOT OT_CONFIG) - set(OT_CONFIG "openthread-core-cc2538-config.h") - set(OT_CONFIG ${OT_CONFIG} PARENT_SCOPE) -endif() - -list(APPEND OT_PLATFORM_DEFINES - "OPENTHREAD_CORE_CONFIG_PLATFORM_CHECK_FILE=\"openthread-core-cc2538-config-check.h\"" - "OPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1" -) -set(OT_PLATFORM_DEFINES ${OT_PLATFORM_DEFINES} PARENT_SCOPE) - -list(APPEND OT_PLATFORM_DEFINES "OPENTHREAD_PROJECT_CORE_CONFIG_FILE=\"${OT_CONFIG}\"") - -add_library(openthread-cc2538 - alarm.c - diag.c - entropy.c - flash.c - misc.c - radio.c - startup-gcc.c - system.c - logging.c - uart.c - $ -) - -target_link_libraries(openthread-cc2538 - PRIVATE - ot-config - PUBLIC - -T${PROJECT_SOURCE_DIR}/examples/platforms/cc2538/cc2538.ld - -Wl,--gc-sections -Wl,-Map=$.map -) - -target_compile_definitions(openthread-cc2538 - PUBLIC - ${OT_PLATFORM_DEFINES} -) - -target_compile_options(openthread-cc2538 PRIVATE - ${OT_CFLAGS} -) - -target_include_directories(openthread-cc2538 PRIVATE - ${OT_PUBLIC_INCLUDES} - ${PROJECT_SOURCE_DIR}/examples/platforms - ${PROJECT_SOURCE_DIR}/src/core -) diff --git a/examples/platforms/cc2538/Makefile.am b/examples/platforms/cc2538/Makefile.am deleted file mode 100644 index fb802f211..000000000 --- a/examples/platforms/cc2538/Makefile.am +++ /dev/null @@ -1,69 +0,0 @@ -# -# Copyright (c) 2016, 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 - -# Do not enable -Wcast-align for this platform -override CFLAGS := $(filter-out -Wcast-align,$(CFLAGS)) -override CXXFLAGS := $(filter-out -Wcast-align,$(CXXFLAGS)) - -lib_LIBRARIES = libopenthread-cc2538.a - -libopenthread_cc2538_a_CPPFLAGS = \ - -I$(top_srcdir)/include \ - -I$(top_srcdir)/examples/platforms \ - -I$(top_srcdir)/src/core \ - $(NULL) - -PLATFORM_SOURCES = \ - alarm.c \ - cc2538-reg.h \ - diag.c \ - entropy.c \ - flash.c \ - misc.c \ - openthread-core-cc2538-config.h \ - openthread-core-cc2538-config-check.h \ - platform-cc2538.h \ - radio.c \ - rom-utility.h \ - startup-gcc.c \ - system.c \ - logging.c \ - uart.c \ - $(NULL) - -libopenthread_cc2538_a_SOURCES = \ - $(PLATFORM_SOURCES) \ - $(NULL) - -Dash = - -libopenthread_cc2538_a_LIBADD = \ - $(shell find $(top_builddir)/examples/platforms/utils $(Dash)type f $(Dash)name "*.o") - -include $(abs_top_nlbuild_autotools_dir)/automake/post.am diff --git a/examples/platforms/cc2538/Makefile.platform.am b/examples/platforms/cc2538/Makefile.platform.am deleted file mode 100644 index f908b4ed8..000000000 --- a/examples/platforms/cc2538/Makefile.platform.am +++ /dev/null @@ -1,39 +0,0 @@ -# -# 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. -# - -# -# cc2538 platform-specific Makefile -# - -LDADD_COMMON += \ - $(top_builddir)/examples/platforms/cc2538/libopenthread-cc2538.a \ - $(NULL) - -LDFLAGS_COMMON += \ - -T $(top_srcdir)/examples/platforms/cc2538/cc2538.ld \ - $(NULL) diff --git a/examples/platforms/cc2538/README.md b/examples/platforms/cc2538/README.md index 91d5b7afb..d6674dde2 100644 --- a/examples/platforms/cc2538/README.md +++ b/examples/platforms/cc2538/README.md @@ -1,112 +1 @@ -# OpenThread on CC2538 Example - -This directory contains example 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. - -## Toolchain - -Download and install the [GNU toolchain for ARM Cortex-M][gnu-toolchain]. - -[gnu-toolchain]: https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm - -In a Bash terminal, follow these instructions to install the GNU toolchain and other dependencies. - -```bash -$ cd -$ ./script/bootstrap -``` - -## Building - -In a Bash terminal, follow these instructions to build the cc2538 examples. - -```bash -$ cd -$ ./bootstrap -$ make -f examples/Makefile-cc2538 -``` - -### CC2592 support - -If your board has a CC2592 range extender front-end IC connected to the CC2538 (e.g. the CC2538-CC2592 EM reference design), you need to initialise this part before reception of radio traffic will work. - -Support is enabled in OpenThread by building with `CC2592=1`: - -```bash -$ make -f examples/Makefile-cc2538 CC2592=1 -``` - -The default settings should work for any design following the integration advice given in TI's application report ["AN130 - Using CC2592 Front End With CC2538"](http://www.ti.com/lit/pdf/swra447). - -Additional settings can be customised: - -- `CC2592_PA_EN`: This specifies which pin (on port C of the CC2538) connects to the CC2592's `PA_EN` pin. The default is `3` (PC3). -- `CC2592_LNA_EN`: This specifies which pin (on port C of the CC2538) connects to the CC2592's `LNA_EN` pin. The default is `2` (PC2). -- `CC2592_USE_HGM`: This defines whether the HGM pin of the CC2592 is under GPIO control or not. If not, it is assumed that the HGM pin is tied to a power rail. -- `CC2592_HGM_PORT`: The HGM pin can be connected to any free GPIO. TI recommend using PD2, however if you've used a pin on another GPIO port, you may specify that port (`A`, `B` or `C`) here. -- `CC2592_HGM_PORT`: The HGM pin can be connected to any free GPIO. TI recommend using PD2, however if you've used a pin on another GPIO port, you may specify that port (`A`, `B` or `C`) here. Default is `D`. -- `CC2592_HGM_PIN`: The HGM pin can be connected to any free GPIO. TI recommend using PD2, however if you've used a pin on another GPIO pin, you can specify the pin here. Default is `2`. -- `CC2592_HGM_DEFAULT_STATE`: By default, HGM is enabled at power-on, but you may want to have it default to off, specify `CC2592_HGM_DEFAULT_STATE=0` to do so. -- `CC2538_RECEIVE_SENSITIVITY`: If you have tied the HGM pin to a power rail, this allows you to calibrate the RSSI values according to the new receive sensitivity. This has no effect if `CC2592_USE_HGM=1` (the default). -- `CC2538_RSSI_OFFSET`: If you have tied the HGM pin to a power rail, this allows you to calibrate the RSSI values according to the new RSSI offset. This has no effect if `CC2592_USE_HGM=1` (the default). - -## Flash Binaries - -If the build completed successfully, the `elf` files may be found in `/output/cc2538/bin`. - -To flash the images with [Flash Programmer 2][ti-flash-programmer-2], the files must have the `*.elf` extension. - -```bash -$ cd /output/cc2538/bin -$ cp ot-cli ot-cli.elf -``` - -To load the images with the [serial bootloader][ti-cc2538-bootloader], the images must be converted to `bin`. This is done using `arm-none-eabi-objcopy` - -```bash -$ cd /output/cc2538/bin -$ arm-none-eabi-objcopy -O binary ot-cli ot-cli.bin -``` - -The [cc2538-bsl.py script][cc2538-bsl-tool] provides a convenient method for flashing a CC2538 via the UART. To enter the bootloader backdoor for flashing, hold down SELECT for CC2538DK (corresponds to logic '0') while you press the Reset button. - -[ti-flash-programmer-2]: http://www.ti.com/tool/flash-programmer -[ti-cc2538-bootloader]: http://www.ti.com/lit/an/swra466a/swra466a.pdf -[cc2538-bsl-tool]: https://github.com/JelmerT/cc2538-bsl - -## 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 -mode -netdata register -networkidtimeout -networkkey -networkname -panid -ping -prefix -releaserouterid -rloc16 -route -routerupgradethreshold -scan -start -state -stop -``` +The OpenThread on CC2538 example has moved to https://github.com/openthread/ot-cc2538 diff --git a/examples/platforms/cc2538/alarm.c b/examples/platforms/cc2538/alarm.c deleted file mode 100644 index 7deefda0c..000000000 --- a/examples/platforms/cc2538/alarm.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (c) 2016, 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 -#include - -#include -#include -#include - -#include "platform-cc2538.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; - -static uint8_t sTimersIsRunning = 0; -static uint32_t sTimersExpireAt[OT_CC2538_TIMERS_COUNT]; - -extern void cc2538EnergyScanTimerHandler(void); - -void cc2538SetTimer(otCC2538Timer aTimer, uint32_t aDelay) -{ - sTimersIsRunning |= (1 << aTimer); - sTimersExpireAt[aTimer] = sCounter + aDelay; -} - -void cc2538AlarmInit(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 otPlatAlarmMilliGetNow(void) -{ - return sCounter; -} - -void otPlatAlarmMilliStartAt(otInstance *aInstance, uint32_t t0, uint32_t dt) -{ - OT_UNUSED_VARIABLE(aInstance); - - sAlarmT0 = t0; - sAlarmDt = dt; - sIsRunning = true; -} - -void otPlatAlarmMilliStop(otInstance *aInstance) -{ - OT_UNUSED_VARIABLE(aInstance); - - sIsRunning = false; -} - -void cc2538AlarmProcess(otInstance *aInstance) -{ - uint32_t expires; - bool fire = false; - - if (sTimersIsRunning) - { - if ((int32_t)(sTimersExpireAt[OT_CC2538_TIMER_ENERGY_SCAN] - sCounter) < 0) - { - sTimersIsRunning &= ~(1 << OT_CC2538_TIMER_ENERGY_SCAN); - cc2538EnergyScanTimerHandler(); - } - } - - 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; - -#if OPENTHREAD_CONFIG_DIAG_ENABLE - - if (otPlatDiagModeGet()) - { - otPlatDiagAlarmFired(aInstance); - } - else -#endif - { - otPlatAlarmMilliFired(aInstance); - } - } - } -} - -void SysTick_Handler() -{ - sCounter++; -} diff --git a/examples/platforms/cc2538/arm-none-eabi.cmake b/examples/platforms/cc2538/arm-none-eabi.cmake deleted file mode 100644 index 2e39ec11d..000000000 --- a/examples/platforms/cc2538/arm-none-eabi.cmake +++ /dev/null @@ -1,42 +0,0 @@ -# -# Copyright (c) 2019, 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. -# - -set(CMAKE_SYSTEM_NAME Generic) -set(CMAKE_SYSTEM_PROCESSOR ARM) - -set(CMAKE_C_COMPILER arm-none-eabi-gcc) -set(CMAKE_CXX_COMPILER arm-none-eabi-g++) -set(CMAKE_ASM_COMPILER arm-none-eabi-as) -set(CMAKE_RANLIB arm-none-eabi-ranlib) - -set(COMMON_C_FLAGS "-mthumb -fno-builtin -Wall -fdata-sections -ffunction-sections -mabi=aapcs -mcpu=cortex-m3 -mfloat-abi=soft") - -set(CMAKE_C_FLAGS_INIT "${COMMON_C_FLAGS} -std=gnu99") -set(CMAKE_CXX_FLAGS_INIT "${COMMON_C_FLAGS} -fno-exceptions -fno-rtti") -set(CMAKE_ASM_FLAGS_INIT "${COMMON_C_FLAGS}") -set(CMAKE_EXE_LINKER_FLAGS_INIT "${COMMON_C_FLAGS} -specs=nano.specs -specs=nosys.specs -nostartfiles") diff --git a/examples/platforms/cc2538/cc2538-reg.h b/examples/platforms/cc2538/cc2538-reg.h deleted file mode 100644 index 54972fbea..000000000 --- a/examples/platforms/cc2538/cc2538-reg.h +++ /dev/null @@ -1,326 +0,0 @@ -/* - * Copyright (c) 2016, 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 CC2538 register definitions. - * - */ - -#ifndef CC2538_REG_H_ -#define CC2538_REG_H_ - -#include - -// clang-format off - -#define HWREG(x) (*((volatile uint32_t *)(x))) - -/*! - * For registers that are arrays of 32-bit integers. - * - * @param reg Register address - * @param idx Register array index - */ -#define HWREG_ARR(reg, idx) HWREG((reg) + ((idx) << 2)) - -#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 RFCORE_XREG_SRCMATCH_EN 0x00000001 // SRCMATCH.SRC_MATCH_EN(1) -#define RFCORE_XREG_SRCMATCH_AUTOPEND 0x00000002 // SRCMATCH.AUTOPEND(1) -#define RFCORE_XREG_SRCMATCH_PEND_DATAREQ_ONLY 0x00000004 // SRCMATCH.PEND_DATAREQ_ONLY(1) - -#define RFCORE_XREG_SRCMATCH_ENABLE_STATUS_SIZE 3 // Num of register for source match enable status -#define RFCORE_XREG_SRCMATCH_SHORT_ENTRIES 24 // 24 short address entries in maximum -#define RFCORE_XREG_SRCMATCH_EXT_ENTRIES 12 // 12 extended address entries in maximum -#define RFCORE_XREG_SRCMATCH_SHORT_ENTRY_OFFSET 4 // address offset for one short address entry -#define RFCORE_XREG_SRCMATCH_EXT_ENTRY_OFFSET 8 // address offset for one extended address entry - -#define INT_UART0 21 // UART0 Rx and Tx - -#define IEEE_EUI64 0x00280028 // Address of IEEE EUI-64 address - -#define RFCORE_FFSM_SRCADDRESS_TABLE 0x40088400 // Source Address Table - -#define RFCORE_FFSM_SRCEXTPENDEN0 0x40088590 // Enable/Disable automatic pending per extended address -#define RFCORE_FFSM_SRCSHORTPENDEN0 0x4008859C // Enable/Disable automatic pending per short 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_SRCSHORTEN0 0x4008860C // Short address matching -#define RFCORE_XREG_SRCEXTEN0 0x40088618 // Extended address matching - -#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_TXPOWER 0x40088640 // Controls the output power -#define RFCORE_XREG_FSMSTAT0 0x40088648 // Radio finite state machine status -#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_RSSI 0x40088660 // RSSI status register -#define RFCORE_XREG_RSSISTAT 0x40088664 // RSSI valid status register -#define RFCORE_XREG_AGCCTRL1 0x400886C8 // AGC reference level -#define RFCORE_XREG_RFC_OBS_CTRL 0x400887AC // RF Core observable output -#define RFCORE_XREG_TXFILTCFG 0x400887E8 // TX filter configuration -#define RFCORE_XREG_RFRND 0x4008869C // Random data -#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 CCTEST_OBSSEL 0x44010014 // CCTEST observable output route - -#define RFCORE_XREG_FRMFILT0_FRAME_FILTER_EN 0x00000001 // Enables frame filtering - -#define RFCORE_XREG_FRMCTRL0_AUTOACK 0x00000020 -#define RFCORE_XREG_FRMCTRL0_ENERGY_SCAN 0x00000010 -#define RFCORE_XREG_FRMCTRL0_AUTOCRC 0x00000040 -#define RFCORE_XREG_FRMCTRL0_INFINITY_RX 0x00000008 - -#define RFCORE_XREG_FRMCTRL1_PENDING_OR 0x00000004 - -#define RFCORE_XREG_RFRND_IRND 0x00000001 - -#define RFCORE_XREG_FSMSTAT0_STATE_MASK 0x0000003F -#define RFCORE_XREG_FSMSTAT0_CAL_DONE 0x00000080 -#define RFCORE_XREG_FSMSTAT0_CAL_RUN 0x00000040 - -#define RFCORE_XREG_FSMSTAT0_STATE_IDLE 0x00000000 -#define RFCORE_XREG_FSMSTAT0_STATE_RX_CAL 0x00000002 -#define RFCORE_XREG_FSMSTAT0_STATE_SFD_WAIT0 0x00000003 -#define RFCORE_XREG_FSMSTAT0_STATE_SFD_WAIT1 0x00000004 -#define RFCORE_XREG_FSMSTAT0_STATE_SFD_WAIT2 0x00000005 -#define RFCORE_XREG_FSMSTAT0_STATE_SFD_WAIT3 0x00000006 -#define RFCORE_XREG_FSMSTAT0_STATE_RX0 0x00000007 -#define RFCORE_XREG_FSMSTAT0_STATE_RX1 0x00000008 -#define RFCORE_XREG_FSMSTAT0_STATE_RX2 0x00000009 -#define RFCORE_XREG_FSMSTAT0_STATE_RX3 0x0000000A -#define RFCORE_XREG_FSMSTAT0_STATE_RX4 0x0000000B -#define RFCORE_XREG_FSMSTAT0_STATE_RX5 0x0000000C -#define RFCORE_XREG_FSMSTAT0_STATE_RX6 0x0000000D -#define RFCORE_XREG_FSMSTAT0_STATE_RX_WAIT 0x0000000E -#define RFCORE_XREG_FSMSTAT0_STATE_RX_FRST 0x00000010 -#define RFCORE_XREG_FSMSTAT0_STATE_RX_OVER 0x00000011 -#define RFCORE_XREG_FSMSTAT0_STATE_TX_CAL 0x00000020 -#define RFCORE_XREG_FSMSTAT0_STATE_TX0 0x00000022 -#define RFCORE_XREG_FSMSTAT0_STATE_TX1 0x00000023 -#define RFCORE_XREG_FSMSTAT0_STATE_TX2 0x00000024 -#define RFCORE_XREG_FSMSTAT0_STATE_TX3 0x00000025 -#define RFCORE_XREG_FSMSTAT0_STATE_TX4 0x00000026 -#define RFCORE_XREG_FSMSTAT0_STATE_TX_FINAL 0x00000027 -#define RFCORE_XREG_FSMSTAT0_STATE_RXTX_TRANS 0x00000028 -#define RFCORE_XREG_FSMSTAT0_STATE_ACK_CAL 0x00000030 -#define RFCORE_XREG_FSMSTAT0_STATE_ACK0 0x00000031 -#define RFCORE_XREG_FSMSTAT0_STATE_ACK1 0x00000032 -#define RFCORE_XREG_FSMSTAT0_STATE_ACK2 0x00000033 -#define RFCORE_XREG_FSMSTAT0_STATE_ACK3 0x00000034 -#define RFCORE_XREG_FSMSTAT0_STATE_ACK4 0x00000035 -#define RFCORE_XREG_FSMSTAT0_STATE_ACK5 0x00000036 -#define RFCORE_XREG_FSMSTAT0_STATE_ACK_DELAY 0x00000037 -#define RFCORE_XREG_FSMSTAT0_STATE_TX_UNDER 0x00000038 -#define RFCORE_XREG_FSMSTAT0_STATE_TX_DOWN0 0x0000001A -#define RFCORE_XREG_FSMSTAT0_STATE_TX_DOWN1 0x0000003A - -#define RFCORE_XREG_FSMSTAT1_RX_ACTIVE 0x00000001 -#define RFCORE_XREG_FSMSTAT1_TX_ACTIVE 0x00000002 -#define RFCORE_XREG_FSMSTAT1_LOCK_STATUS 0x00000004 -#define RFCORE_XREG_FSMSTAT1_SAMPLED_CCA 0x00000008 -#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_XREG_RFC_OBS_POL_INV 0x00000040 // Invert polarity of OBS signal -#define RFCORE_XREG_RFC_OBS_MUX_ZERO 0x00000000 // Observable = constant zero -#define RFCORE_XREG_RFC_OBS_MUX_ONE 0x00000001 // Observable = constant one -#define RFCORE_XREG_RFC_OBS_MUX_SNIFF_DATA 0x00000008 // RFC sniff data -#define RFCORE_XREG_RFC_OBS_MUX_SNIFF_CLK 0x00000009 // RFC sniff clock -#define RFCORE_XREG_RFC_OBS_MUX_RSSI_VALID 0x0000000c // RSSI valid -#define RFCORE_XREG_RFC_OBS_MUX_DEMOD_CCA 0x0000000d // Clear channel assessment -#define RFCORE_XREG_RFC_OBS_MUX_SAMPLED_CCA 0x0000000e // Sampled CCA signal -#define RFCORE_XREG_RFC_OBS_MUX_SFD_SYNC 0x0000000f // SFD received or transmitted -#define RFCORE_XREG_RFC_OBS_MUX_TX_ACTIVE 0x00000010 // Transmitter is active -#define RFCORE_XREG_RFC_OBS_MUX_RX_ACTIVE 0x00000011 // Receiver is active -#define RFCORE_XREG_RFC_OBS_MUX_FFCTRL_FIFO 0x00000012 // One or more bytes in FIFO -#define RFCORE_XREG_RFC_OBS_MUX_FFCTRL_FIFOP 0x00000013 // One or more frames in FIFO -#define RFCORE_XREG_RFC_OBS_MUX_PACKET_DONE 0x00000014 // Packet received -#define RFCORE_XREG_RFC_OBS_MUX_RFC_XOR_RAND_IQ 0x00000016 // RAND I ^ RAND Q -#define RFCORE_XREG_RFC_OBS_MUX_RFC_RAND_Q 0x00000017 // Random data from Q channel -#define RFCORE_XREG_RFC_OBS_MUX_RFC_RAND_I 0x00000018 // Random data from I channel -#define RFCORE_XREG_RFC_OBS_MUX_LOCK_STATUS 0x00000019 // PLL is in lock -#define RFCORE_XREG_RFC_OBS_MUX_PA_PD 0x00000028 // Power amp power down -#define RFCORE_XREG_RFC_OBS_MUX_LNA_PD 0x0000002a // LNA power down - -#define RFCORE_SFR_RFERRF_NLOCK 0x00000001 // Failed to achieve PLL lock. -#define RFCORE_SFR_RFERRF_RXABO 0x00000002 // RX Aborted. -#define RFCORE_SFR_RFERRF_RXOVERF 0x00000004 // RX FIFO overflowed. -#define RFCORE_SFR_RFERRF_RXUNDERF 0x00000008 // RX FIFO underflowed. -#define RFCORE_SFR_RFERRF_TXOVERF 0x00000010 // TX FIFO overflowed. -#define RFCORE_SFR_RFERRF_TXUNDERF 0x00000020 // TX FIFO underflowed. -#define RFCORE_SFR_RFERRF_STROBEERR 0x00000040 // Command Strobe Error. - -#define RFCORE_SFR_RFST_INSTR_RXON 0xE3 // Instruction set RX on -#define RFCORE_SFR_RFST_INSTR_TXON 0xE9 // Instruction set TX on -#define RFCORE_SFR_RFST_INSTR_RFOFF 0xEF // Instruction set RF off -#define RFCORE_SFR_RFST_INSTR_FLUSHRX 0xED // Instruction set flush rx buffer -#define RFCORE_SFR_RFST_INSTR_FLUSHTX 0xEE // Instruction set flush tx buffer - -#define CCTEST_OBSSEL_EN 0x00000080 // Enable the OBS output on this pin -#define CCTEST_OBSSEL_SEL_OBS0 0x00000000 // Route OBS0 to pin -#define CCTEST_OBSSEL_SEL_OBS1 0x00000001 // Route OBS1 to pin -#define CCTEST_OBSSEL_SEL_OBS2 0x00000002 // Route OBS2 to pin - -#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_PWRDBG 0x400D2074 -#define SYS_CTRL_PWRDBG_FORCE_WARM_RESET 0x00000008 - -#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 SYS_CTRL_RCGCUART_UART1 0x00000002 -#define SYS_CTRL_SCGCUART_UART1 0x00000002 -#define SYS_CTRL_DCGCUART_UART1 0x00000002 - -#define IOC_PA0_SEL 0x400D4000 // Peripheral select control -#define IOC_PA1_SEL 0x400D4004 // Peripheral select control -#define IOC_PA2_SEL 0x400D4008 -#define IOC_PA3_SEL 0x400D400C -#define IOC_UARTRXD_UART0 0x400D4100 -#define IOC_UARTRXD_UART1 0x400D4108 - -#define IOC_PA0_OVER 0x400D4080 -#define IOC_PA1_OVER 0x400D4084 -#define IOC_PA2_OVER 0x400D4088 -#define IOC_PA3_OVER 0x400D408C - -#define IOC_MUX_OUT_SEL_UART0_TXD 0x00000000 -#define IOC_MUX_OUT_SEL_UART1_TXD 0x00000002 - -#define IOC_OVERRIDE_OE 0x00000008 // PAD Config Override Output Enable -#define IOC_OVERRIDE_DIS 0x00000000 // PAD Config Override Disabled - -#define IOC_PAD_IN_SEL_PA0 0x00000000 // PA0 -#define IOC_PAD_IN_SEL_PA1 0x00000001 // PA1 -#define IOC_PAD_IN_SEL_PA2 0x00000002 // PA2 -#define IOC_PAD_IN_SEL_PA3 0x00000003 // PA3 - -#define UART0_BASE 0x4000C000 -#define UART1_BASE 0x4000D000 -#define GPIO_A_BASE 0x400D9000 // GPIO A -#define GPIO_B_BASE 0x400DA000 // GPIO B -#define GPIO_C_BASE 0x400DB000 // GPIO C -#define GPIO_D_BASE 0x400DC000 // GPIO D - -#define GPIO_O_DIR 0x00000400 -#define GPIO_O_AFSEL 0x00000420 - -#define GPIO_PIN(x) (1UL << x) // Arbitrary GPIO pin -#define GPIO_PIN_0 0x00000001 // GPIO pin 0 -#define GPIO_PIN_1 0x00000002 // GPIO pin 1 -#define GPIO_PIN_2 0x00000004 // GPIO pin 2 -#define GPIO_PIN_3 0x00000008 // GPIO pin 3 -#define GPIO_PIN_4 0x00000010 // GPIO pin 4 -#define GPIO_PIN_5 0x00000020 // GPIO pin 5 -#define GPIO_PIN_6 0x00000040 // GPIO pin 6 -#define GPIO_PIN_7 0x00000080 // GPIO pin 7 - -#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 - -#define SOC_ADC_ADCCON1 0x400D7000 // ADC Control -#define SOC_ADC_RNDL 0x400D7014 // RNG low data -#define SOC_ADC_RNDH 0x400D7018 // RNG high data - -#define SOC_ADC_ADCCON1_RCTRL0 0x00000004 // ADCCON1 RCTRL bit 0 -#define SOC_ADC_ADCCON1_RCTRL1 0x00000008 // ADCCON1 RCTRL bit 1 - -#define FLASH_CTRL_FCTL 0x400D3008 // Flash control -#define FLASH_CTRL_DIECFG0 0x400D3014 // Flash information - -// clang-format on - -#endif diff --git a/examples/platforms/cc2538/cc2538.ld b/examples/platforms/cc2538/cc2538.ld deleted file mode 100644 index daff1621f..000000000 --- a/examples/platforms/cc2538/cc2538.ld +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (c) 2016, 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 - * GCC linker script for CC2538. - */ - -_512k_bytes = (512*1024); -_256k_bytes = (256*1024); -_128k_bytes = (128*1024); -_FLASH_page_size = 2048; - -/* - * Change for your chip, default is 512k chips - */ -_FLASH_size_bytes = _512k_bytes; -_FLASH_n_pages = (_FLASH_size_bytes / _FLASH_page_size); -/* reduce the usable size by: the CCA + settings Page A & B, total 3 pages */ -_FLASH_usable_size = (_FLASH_size_bytes - (3 * _FLASH_page_size)); -_FLASH_start = 0x00200000; -_FLASH_end = (_FLASH_start + _FLASH_size_bytes); - -/* - * The CCA (Customer Configuration Area) is always the last page. - * See: http://www.ti.com/lit/ug/swru319c/swru319c.pdf - * table 8-2 for more details. - */ -_FLASH_cca_page = (_FLASH_end - (1 * _FLASH_page_size)); - -/* - * OpenThread NV storage goes in the settings page. - * OpenThread requires at least 2 adjacent pages, call them A and B. - */ -_FLASH_settings_pageB = (_FLASH_end - (2 * _FLASH_page_size)); -_FLASH_settings_pageA = (_FLASH_end - (3 * _FLASH_page_size)); - -MEMORY -{ - /* would like to use SYMBOLS (from above)here but we cannot - * GCC version 4.9 does not support symbolic expressions here. - * But later versions do support the feature. - */ - FLASH (rx) : ORIGIN = 0x00200000, LENGTH = 0x0007c000 - FLASH_CCA (rx) : ORIGIN = 0x0027FFD4, LENGTH = 0x2c - SRAM (rwx) : ORIGIN = 0x20000000, LENGTH = 32K -} -/* - * To safty check what would have been the SYMBOL values - * we use these ASSERTS to verify things are still good. - */ -ASSERT( _FLASH_start == 0x00200000, "invalid flash start address for cc2538") -ASSERT( _FLASH_cca_page == 0x0027f800, "invalid cca start address for cc2538") -ASSERT( _FLASH_usable_size == 0x0007e800, "Invalid usable size for this config") - - - -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 - - .ARM.exidx : ALIGN(4) - { - *(.ARM.exidx*) - } > 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 -} diff --git a/examples/platforms/cc2538/diag.c b/examples/platforms/cc2538/diag.c deleted file mode 100644 index 579c1e794..000000000 --- a/examples/platforms/cc2538/diag.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2016, 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 -#include -#include -#include - -#include -#include -#include - -#include "platform-cc2538.h" - -#if OPENTHREAD_CONFIG_DIAG_ENABLE - -/** - * Diagnostics mode variables. - * - */ -static bool sDiagMode = false; - -void otPlatDiagModeSet(bool aMode) -{ - sDiagMode = aMode; -} - -bool otPlatDiagModeGet() -{ - return sDiagMode; -} - -void otPlatDiagChannelSet(uint8_t aChannel) -{ - OT_UNUSED_VARIABLE(aChannel); -} - -void otPlatDiagTxPowerSet(int8_t aTxPower) -{ - OT_UNUSED_VARIABLE(aTxPower); -} - -void otPlatDiagRadioReceived(otInstance *aInstance, otRadioFrame *aFrame, otError aError) -{ - OT_UNUSED_VARIABLE(aInstance); - OT_UNUSED_VARIABLE(aFrame); - OT_UNUSED_VARIABLE(aError); -} - -void otPlatDiagAlarmCallback(otInstance *aInstance) -{ - OT_UNUSED_VARIABLE(aInstance); -} - -#endif // OPENTHREAD_CONFIG_DIAG_ENABLE diff --git a/examples/platforms/cc2538/entropy.c b/examples/platforms/cc2538/entropy.c deleted file mode 100644 index 47a31be04..000000000 --- a/examples/platforms/cc2538/entropy.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2019, 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 an entropy source based on ADC. - * - */ - -#include - -#include - -#include "platform-cc2538.h" -#include "utils/code_utils.h" - -static void generateRandom(uint8_t *aOutput, uint16_t aOutputLength) -{ - uint32_t frmctrl0; - - HWREG(SOC_ADC_ADCCON1) &= ~(SOC_ADC_ADCCON1_RCTRL1 | SOC_ADC_ADCCON1_RCTRL0); - HWREG(SYS_CTRL_RCGCRFC) = SYS_CTRL_RCGCRFC_RFC0; - - while (HWREG(SYS_CTRL_RCGCRFC) != SYS_CTRL_RCGCRFC_RFC0) - ; - - frmctrl0 = HWREG(RFCORE_XREG_FRMCTRL0); - HWREG(RFCORE_XREG_FRMCTRL0) = RFCORE_XREG_FRMCTRL0_INFINITY_RX; - HWREG(RFCORE_SFR_RFST) = RFCORE_SFR_RFST_INSTR_RXON; - - while (!HWREG(RFCORE_XREG_RSSISTAT) & RFCORE_XREG_RSSISTAT_RSSI_VALID) - ; - - for (uint16_t index = 0; index < aOutputLength; index++) - { - aOutput[index] = 0; - - for (uint8_t offset = 0; offset < 8 * sizeof(uint8_t); offset++) - { - aOutput[index] <<= 1; - aOutput[index] |= (HWREG(RFCORE_XREG_RFRND) & RFCORE_XREG_RFRND_IRND); - } - } - - HWREG(RFCORE_SFR_RFST) = RFCORE_SFR_RFST_INSTR_RFOFF; - HWREG(RFCORE_XREG_FRMCTRL0) = frmctrl0; -} - -void cc2538RandomInit(void) -{ - uint16_t seed = 0; - - while (seed == 0x0000 || seed == 0x8003) - { - generateRandom((uint8_t *)&seed, sizeof(seed)); - } - - HWREG(SOC_ADC_RNDL) = (seed >> 8) & 0xff; - HWREG(SOC_ADC_RNDL) = seed & 0xff; -} - -otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength) -{ - otError error = OT_ERROR_NONE; - uint8_t channel = 0; - - otEXPECT_ACTION(aOutput, error = OT_ERROR_INVALID_ARGS); - - if (sInstance && otPlatRadioIsEnabled(sInstance)) - { - channel = 11 + (HWREG(RFCORE_XREG_FREQCTRL) - 11) / 5; - otPlatRadioSleep(sInstance); - otPlatRadioDisable(sInstance); - } - - generateRandom(aOutput, aOutputLength); - - if (channel) - { - cc2538RadioInit(); - otPlatRadioEnable(sInstance); - otPlatRadioReceive(sInstance, channel); - } - -exit: - return error; -} diff --git a/examples/platforms/cc2538/flash.c b/examples/platforms/cc2538/flash.c deleted file mode 100644 index 04c8a6559..000000000 --- a/examples/platforms/cc2538/flash.c +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2016, 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 -#include -#include - -#include "platform-cc2538.h" -#include "rom-utility.h" - -#define FLASH_CTRL_FCTL_BUSY 0x00000080 - -#define FLASH_PAGE_SIZE 2048 -#define FLASH_PAGE_NUM 2 -#define FLASH_SWAP_SIZE (FLASH_PAGE_SIZE * (FLASH_PAGE_NUM / 2)) - -/* The linker script creates this external symbol */ -extern uint8_t _FLASH_settings_pageA[]; - -/* Convert a settings offset to the physical address within the flash settings pages */ -static uint32_t flashPhysAddr(uint8_t aSwapIndex, uint32_t aOffset) -{ - uint32_t address = (uint32_t)(&_FLASH_settings_pageA[0]) + aOffset; - - if (aSwapIndex) - { - address += FLASH_SWAP_SIZE; - } - - return address; -} - -void otPlatFlashInit(otInstance *aInstance) -{ - OT_UNUSED_VARIABLE(aInstance); -} - -uint32_t otPlatFlashGetSwapSize(otInstance *aInstance) -{ - OT_UNUSED_VARIABLE(aInstance); - - return FLASH_SWAP_SIZE; -} - -void otPlatFlashErase(otInstance *aInstance, uint8_t aSwapIndex) -{ - OT_UNUSED_VARIABLE(aInstance); - - ROM_PageErase(flashPhysAddr(aSwapIndex, 0), FLASH_PAGE_SIZE); - while (HWREG(FLASH_CTRL_FCTL) & FLASH_CTRL_FCTL_BUSY) - { - } -} - -void otPlatFlashWrite(otInstance *aInstance, uint8_t aSwapIndex, uint32_t aOffset, const void *aData, uint32_t aSize) -{ - OT_UNUSED_VARIABLE(aInstance); - - uint32_t *data = (uint32_t *)(aData); - - for (uint32_t size = 0; size < aSize; size += sizeof(uint32_t), aOffset += sizeof(uint32_t), data++) - { - ROM_ProgramFlash(data, flashPhysAddr(aSwapIndex, aOffset), sizeof(uint32_t)); - - while (HWREG(FLASH_CTRL_FCTL) & FLASH_CTRL_FCTL_BUSY) - { - } - } -} - -void otPlatFlashRead(otInstance *aInstance, uint8_t aSwapIndex, uint32_t aOffset, uint8_t *aData, uint32_t aSize) -{ - OT_UNUSED_VARIABLE(aInstance); - - memcpy(aData, (void *)flashPhysAddr(aSwapIndex, aOffset), aSize); -} diff --git a/examples/platforms/cc2538/logging.c b/examples/platforms/cc2538/logging.c deleted file mode 100644 index 82158aeed..000000000 --- a/examples/platforms/cc2538/logging.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2016, 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 logging.c - * Platform abstraction for the logging - * - */ - -#include -#include -#include -#include - -#if (OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED) -OT_TOOL_WEAK void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...) -{ - OT_UNUSED_VARIABLE(aLogLevel); - OT_UNUSED_VARIABLE(aLogRegion); - OT_UNUSED_VARIABLE(aFormat); -} -#endif diff --git a/examples/platforms/cc2538/misc.c b/examples/platforms/cc2538/misc.c deleted file mode 100644 index 94dca3dd0..000000000 --- a/examples/platforms/cc2538/misc.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2016, 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 - -#include "platform-cc2538.h" - -void otPlatReset(otInstance *aInstance) -{ - OT_UNUSED_VARIABLE(aInstance); - HWREG(SYS_CTRL_PWRDBG) = SYS_CTRL_PWRDBG_FORCE_WARM_RESET; -} - -otPlatResetReason otPlatGetResetReason(otInstance *aInstance) -{ - OT_UNUSED_VARIABLE(aInstance); - // TODO: Write me! - return OT_PLAT_RESET_REASON_POWER_ON; -} - -void otPlatWakeHost(void) -{ - // TODO: implement an operation to wake the host from sleep state. -} diff --git a/examples/platforms/cc2538/openthread-core-cc2538-config-check.h b/examples/platforms/cc2538/openthread-core-cc2538-config-check.h deleted file mode 100644 index 93788b121..000000000 --- a/examples/platforms/cc2538/openthread-core-cc2538-config-check.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2019, 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. - */ - -#ifndef OPENTHREAD_CORE_CC2538_CONFIG_CHECK_H_ -#define OPENTHREAD_CORE_CC2538_CONFIG_CHECK_H_ - -#if OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT -#error "Platform cc2538 doesn't support configuration option: OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT" -#endif - -#endif /* OPENTHREAD_CORE_CC2538_CONFIG_CHECK_H_ */ diff --git a/examples/platforms/cc2538/openthread-core-cc2538-config.h b/examples/platforms/cc2538/openthread-core-cc2538-config.h deleted file mode 100644 index 1f262173e..000000000 --- a/examples/platforms/cc2538/openthread-core-cc2538-config.h +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Copyright (c) 2016, 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 cc2538 compile-time configuration constants for OpenThread. - */ - -#ifndef OPENTHREAD_CORE_CC2538_CONFIG_H_ -#define OPENTHREAD_CORE_CC2538_CONFIG_H_ - -/** - * @def OPENTHREAD_CONFIG_PLATFORM_INFO - * - * The platform-specific string to insert into the OpenThread version string. - * - */ -#define OPENTHREAD_CONFIG_PLATFORM_INFO "CC2538" - -/** - * @def OPENTHREAD_CONFIG_MAC_SOFTWARE_ACK_TIMEOUT_ENABLE - * - * Define to 1 if you want to enable software ACK timeout logic. - * - */ -#define OPENTHREAD_CONFIG_MAC_SOFTWARE_ACK_TIMEOUT_ENABLE 1 - -/** - * @def OPENTHREAD_CONFIG_MAC_SOFTWARE_RETRANSMIT_ENABLE - * - * Define to 1 if you want to enable software retransmission logic. - * - */ -#define OPENTHREAD_CONFIG_MAC_SOFTWARE_RETRANSMIT_ENABLE 1 - -/** - * @def OPENTHREAD_CONFIG_MAC_SOFTWARE_CSMA_BACKOFF_ENABLE - * - * Define to 1 if you want to enable software CSMA-CA backoff logic. - * - */ -#define OPENTHREAD_CONFIG_MAC_SOFTWARE_CSMA_BACKOFF_ENABLE 1 - -/** - * @def OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE - * - * Define to 1 if you want to enable software transmission security logic. - * - */ -#define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE 0 - -/** - * @def OPENTHREAD_CONFIG_MAC_SOFTWARE_ENERGY_SCAN_ENABLE - * - * Define to 1 if you want to enable software energy scanning logic. - * - */ -#define OPENTHREAD_CONFIG_MAC_SOFTWARE_ENERGY_SCAN_ENABLE 1 - -/** - * @def OPENTHREAD_CONFIG_NCP_HDLC_ENABLE - * - * Define to 1 to enable NCP HDLC support. - * - */ -#define OPENTHREAD_CONFIG_NCP_HDLC_ENABLE 1 - -/** - * @def OPENTHREAD_CONFIG_CC2538_USE_RADIO_RX_INTERRUPT - * - * Enable support for using interrupt-driven radio reception. This allows - * for a single frame to be received whilst the CPU is busy processing some - * other code. - * - * To disable interrupts and just rely on polling, set this to 0. - * - */ -#ifndef OPENTHREAD_CONFIG_CC2538_USE_RADIO_RX_INTERRUPT -#define OPENTHREAD_CONFIG_CC2538_USE_RADIO_RX_INTERRUPT 1 -#endif - -/** - * @def OPENTHREAD_CONFIG_CC2538_WITH_CC2592 - * - * Enable support for the CC2592 range-extender front-end. - * - * This is a feature of the CC2538-CC2592 EM and other peripherals which - * extends the range of the bare CC2538 to over a kilometre line-of-sight. - * The CC2592 needs to be wired up to the RF port on the CC2538 in accordance - * with application note 130 ("Using CC2592 Front End With CC2538", TI doc - * SWRA447). - * - * If you have such a board, change this to 1. - * - */ -#ifndef OPENTHREAD_CONFIG_CC2538_WITH_CC2592 -#define OPENTHREAD_CONFIG_CC2538_WITH_CC2592 0 -#endif - -/** - * @def OPENTHREAD_CONFIG_CC2592_PA_EN_PIN - * - * Define the pin (on port C) that connects to the CC2592 PA_EN pin. - * - * One of the 3 observable channels on the CC2538 radio module will be - * configured to take the "PA power down" signal from the radio module itself, - * invert it, and emit it on this GPIO pin. Due to hardware constraints, it - * may only be connected to a pin on GPIO port C. - * - * The default (PC3) is as per TI recommendations in AN130. - * - */ -#ifndef OPENTHREAD_CONFIG_CC2592_PA_EN_PIN -#define OPENTHREAD_CONFIG_CC2592_PA_EN_PIN 3 -#endif - -/** - * @def OPENTHREAD_CONFIG_CC2592_LNA_EN_PIN - * - * Define the pin (on port C) that connects to the CC2592 LNA_EN pin. - * - * One of the 3 observable channels on the CC2538 radio module will be - * configured to take the "LNA power down" signal from the radio module itself, - * invert it, and emit it on this GPIO pin. Due to hardware constraints, it - * may only be connected to a pin on GPIO port C. - * - * The default (PC2) is as per TI recommendations in AN130. - * - */ -#ifndef OPENTHREAD_CONFIG_CC2592_LNA_EN_PIN -#define OPENTHREAD_CONFIG_CC2592_LNA_EN_PIN 2 -#endif - -/** - * @def OPENTHREAD_CONFIG_CC2592_USE_HGM - * - * Enable control of the high-gain mode signal. - * - * High-gain mode is enabled through the `HGM` pin on the CC2592, which may be - * connected to any free GPIO pin for software control, or may be linked to - * VDD or 0V to hard-wire it to a given state. - * - * Set this to 0 if you have wired this pin to a power rail, or have a - * non-standard way of controlling it. - * - */ -#ifndef OPENTHREAD_CONFIG_CC2592_USE_HGM -#define OPENTHREAD_CONFIG_CC2592_USE_HGM 1 -#endif - -/** - * @def OPENTHREAD_CONFIG_CC2538_RECEIVE_SENSITIVITY - * - * Set the CC2538 receive sensitivity. - * - * A bare CC2538 has a receive sensitivity of -88dBm. The CC2592 changes this - * to -85 or -81 depending on whether the HGM pin is high or low. If - * `OPENTHREAD_CONFIG_CC2592_USE_HGM` is 0, then this sets the receive - * sensitivity. - * - */ -#ifndef OPENTHREAD_CONFIG_CC2538_RECEIVE_SENSITIVITY -#define OPENTHREAD_CONFIG_CC2538_RECEIVE_SENSITIVITY -88 -#endif - -/** - * @def OPENTHREAD_CONFIG_CC2538_RSSI_OFFSET - * - * Set the CC2538 RSSI offset. This calibrates the RSSI readings received from - * the CC2538 radio module to give a reading in dBm. - * - * For a standard CC2538 (no front-end), the RSSI offset is 73. - * - * For a CC2592 hard-wired in high-gain mode, an offset of 85 should be used; - * or for low-gain mode, 81. If `OPENTHREAD_CONFIG_CC2592_USE_HGM` is 0, then - * this calibrates the RSSI value accordingly. - */ -#ifndef OPENTHREAD_CONFIG_CC2538_RSSI_OFFSET -#define OPENTHREAD_CONFIG_CC2538_RSSI_OFFSET 73 -#endif - -/** - * @def OPENTHREAD_CONFIG_CC2592_HGM_PORT - * - * Define the GPIO port that the HGM pin is connected to. It may be - * connected to any available GPIO pin. - * - * The default (GPIO port D) is as per TI recommendations. - * - */ -#ifndef OPENTHREAD_CONFIG_CC2592_HGM_PORT -#define OPENTHREAD_CONFIG_CC2592_HGM_PORT GPIO_D_BASE -#endif - -/** - * @def OPENTHREAD_CONFIG_CC2592_HGM_PIN - * - * Define the pin on the GPIO port that the HGM pin is connected to. It - * may be connected to any available GPIO pin. - * - * The default (PD2) is as per TI recommendations. - * - */ -#ifndef OPENTHREAD_CONFIG_CC2592_HGM_PIN -#define OPENTHREAD_CONFIG_CC2592_HGM_PIN 2 -#endif - -/** - * @def OPENTHREAD_CONFIG_CC2592_HGM_DEFAULT_STATE - * - * Define the default state of the CC2592's HGM pin. - * - * The default is to turn high-gain mode on. - * - */ -#ifndef OPENTHREAD_CONFIG_CC2592_HGM_DEFAULT_STATE -#define OPENTHREAD_CONFIG_CC2592_HGM_DEFAULT_STATE true -#endif - -/** - * @def OPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE - * - * Define to 1 to enable otPlatFlash* APIs to support non-volatile storage. - * - * When defined to 1, the platform MUST implement the otPlatFlash* APIs instead of the otPlatSettings* APIs. - * - */ -#define OPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE 1 - -#endif // OPENTHREAD_CORE_CC2538_CONFIG_H_ diff --git a/examples/platforms/cc2538/platform-cc2538.h b/examples/platforms/cc2538/platform-cc2538.h deleted file mode 100644 index f89b01bbb..000000000 --- a/examples/platforms/cc2538/platform-cc2538.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2016, 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_CC2538_H_ -#define PLATFORM_CC2538_H_ - -#include -#include -#include -#include - -#include "cc2538-reg.h" - -// Global OpenThread instance structure -extern otInstance *sInstance; - -/** - * Initialize the debug uart - */ -void cc2538DebugUartInit(void); - -/** - * This function initializes the alarm service used by OpenThread. - * - */ -void cc2538AlarmInit(void); - -/** - * This function performs alarm driver processing. - * - * @param[in] aInstance The OpenThread instance structure. - * - */ -void cc2538AlarmProcess(otInstance *aInstance); - -/** - * This function initializes the radio service used by OpenThread. - * - */ -void cc2538RadioInit(void); - -/** - * This function performs radio driver processing. - * - * @param[in] aInstance The OpenThread instance structure. - * - */ -void cc2538RadioProcess(otInstance *aInstance); - -/** - * This function initializes the random number service used by OpenThread. - * - */ -void cc2538RandomInit(void); - -/** - * This function performs UART driver processing. - * - */ -void cc2538UartProcess(void); - -#if OPENTHREAD_CONFIG_CC2538_WITH_CC2592 && OPENTHREAD_CONFIG_CC2592_USE_HGM -/** - * Change the state of the CC2592 HGM pin. - * - * @param aState Whether or not to enable HGM - */ -void cc2538RadioSetHgm(bool aState); - -/** - * Retrieve the state of the CC2592 HGM pin. - */ -bool cc2538RadioGetHgm(void); -#endif // OPENTHREAD_CONFIG_CC2538_WITH_CC2592 && OPENTHREAD_CONFIG_CC2592_USE_HGM - -typedef enum -{ - OT_CC2538_TIMER_ENERGY_SCAN, ///< Internal timer for energy scan - OT_CC2538_TIMERS_COUNT, ///< Number of internal timers -} otCC2538Timer; - -/** - * This function sets the internal timer. - * - * @param[in] aTimer The timer identifier. - * @param[in] aDelay The delay to trigger the timer, and must be no more than `INT32_MAX`. - * - */ -void cc2538SetTimer(otCC2538Timer aTimer, uint32_t aDelay); - -#endif // PLATFORM_CC2538_H_ diff --git a/examples/platforms/cc2538/radio.c b/examples/platforms/cc2538/radio.c deleted file mode 100644 index 0878f115d..000000000 --- a/examples/platforms/cc2538/radio.c +++ /dev/null @@ -1,1273 +0,0 @@ -/* - * Copyright (c) 2016, 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 -#include -#include -#include -#include - -#include "platform-cc2538.h" -#include "utils/code_utils.h" - -#define RFCORE_XREG_RFIRQM0 0x4008868C // RF interrupt masks -#define RFCORE_XREG_RFIRQM1 0x40088690 // RF interrupt masks -#define RFCORE_XREG_RFERRM 0x40088694 // RF error interrupt mask - -#define RFCORE_SFR_RFIRQF0_RXMASKZERO 0x00000080 // RXENABLE is now completely clear -#define RFCORE_SFR_RFIRQF0_RXPKTDONE 0x00000040 // A complete frame has been received -#define RFCORE_SFR_RFIRQF0_FRAME_ACCEPTED 0x00000020 // Frame has passed frame filtering -#define RFCORE_SFR_RFIRQF0_SRC_MATCH_FOUND 0x00000010 // Source match is found -#define RFCORE_SFR_RFIRQF0_SRC_MATCH_DONE 0x00000008 // Source matching is complete -#define RFCORE_SFR_RFIRQF0_FIFOP 0x00000004 // The number of bytes in the RX fifo is above threshold -#define RFCORE_SFR_RFIRQF0_SFD 0x00000002 // SFD has been received or transmitted -#define RFCORE_SFR_RFIRQF0_ACT_UNUSED 0x00000001 // Reserved - -#define RFCORE_XREG_RFIRQM0_RXMASKZERO 0x00000080 -#define RFCORE_XREG_RFIRQM0_RXPKTDONE 0x00000040 -#define RFCORE_XREG_RFIRQM0_FRAME_ACCEPTED 0x00000020 -#define RFCORE_XREG_RFIRQM0_SRC_MATCH_FOUND 0x00000010 -#define RFCORE_XREG_RFIRQM0_SRC_MATCH_DONE 0x00000008 -#define RFCORE_XREG_RFIRQM0_FIFOP 0x00000004 -#define RFCORE_XREG_RFIRQM0_SFD 0x00000002 -#define RFCORE_XREG_RFIRQM0_ACT_UNUSED 0x00000001 - -#define RFCORE_SFR_RFIRQF1_CSP_WAIT 0x00000020 -#define RFCORE_SFR_RFIRQF1_CSP_STOP 0x00000010 -#define RFCORE_SFR_RFIRQF1_CSP_MANINT 0x00000008 -#define RFCORE_SFR_RFIRQF1_RF_IDLE 0x00000004 -#define RFCORE_SFR_RFIRQF1_TXDONE 0x00000002 -#define RFCORE_SFR_RFIRQF1_TXACKDONE 0x00000001 - -#define RFCORE_XREG_RFIRQM1_CSP_WAIT 0x00000020 -#define RFCORE_XREG_RFIRQM1_CSP_STOP 0x00000010 -#define RFCORE_XREG_RFIRQM1_CSP_MANINT 0x00000008 -#define RFCORE_XREG_RFIRQM1_RF_IDLE 0x00000004 -#define RFCORE_XREG_RFIRQM1_TXDONE 0x00000002 -#define RFCORE_XREG_RFIRQM1_TXACKDONE 0x00000001 - -#define RFCORE_XREG_RFERRM_STROBE_ERR 0x00000040 -#define RFCORE_XREG_RFERRM_TXUNDERF 0x00000020 -#define RFCORE_XREG_RFERRM_TXOVERF 0x00000010 -#define RFCORE_XREG_RFERRM_RXUNDERF 0x00000008 -#define RFCORE_XREG_RFERRM_RXOVERF 0x00000004 -#define RFCORE_XREG_RFERRM_RXABO 0x00000002 -#define RFCORE_XREG_RFERRM_NLOCK 0x00000001 - -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_RSSI_OFFSET = OPENTHREAD_CONFIG_CC2538_RSSI_OFFSET, - // TI AN130 (SWRA447) Table 4 (bottom of page 3) - CC2592_RSSI_OFFSET_HGM = 85, - CC2592_RSSI_OFFSET_LGM = 81, - CC2538_CRC_BIT_MASK = 0x80, - CC2538_LQI_BIT_MASK = 0x7f, -}; - -// All values in dBm -enum -{ - CC2538_RECEIVE_SENSITIVITY = OPENTHREAD_CONFIG_CC2538_RECEIVE_SENSITIVITY, - // TI AN130 (SWRA447) Table 3 (middle of page 3) - CC2592_RECEIVE_SENSITIVITY_LGM = -99, - CC2592_RECEIVE_SENSITIVITY_HGM = -101, -}; - -typedef struct TxPowerTable -{ - int8_t mTxPowerVal; - uint8_t mTxPowerReg; -} TxPowerTable; - -// The transmit power table. -static const TxPowerTable sTxPowerTable[] = { -#if OPENTHREAD_CONFIG_CC2538_WITH_CC2592 - // CC2538 using CC2592 PA - // Values are from AN130 table 6 (page 4) - {22, 0xFF}, // 22.0dBm =~ 158.5mW - {21, 0xD5}, // 20.9dBm =~ 123.0mW - {20, 0xC5}, // 20.1dBm =~ 102.3mW - {19, 0xB0}, // 19.0dBm =~ 79.4mW - {18, 0xA1}, // 17.8dBm =~ 60.3mW - {16, 0x91}, // 16.4dBm =~ 43.7mW - {15, 0x88}, // 14.9dBm =~ 30.9mW - {13, 0x72}, // 13.0dBm =~ 20.0mW - {11, 0x62}, // 11.0dBm =~ 12.6mW - {10, 0x58}, // 9.5dBm =~ 8.9mW - {8, 0x42}, // 7.5dBm =~ 5.6mW -#else - // CC2538 operating "bare foot" - // Values are from SmartRF Studio 2.4.0 - {7, 0xFF}, // - {5, 0xED}, // - {3, 0xD5}, // - {1, 0xC5}, // - {0, 0xB6}, // - {-1, 0xB0}, // - {-3, 0xA1}, // - {-5, 0x91}, // - {-7, 0x88}, // - {-9, 0x72}, // - {-11, 0x62}, // - {-13, 0x58}, // - {-15, 0x42}, // - {-24, 0x00}, // -#endif -}; - -static otRadioFrame sTransmitFrame; -static otRadioFrame sReceiveFrame; -static otError sTransmitError; -static otError sReceiveError; - -static uint8_t sTransmitPsdu[IEEE802154_MAX_LENGTH]; -static uint8_t sReceivePsdu[IEEE802154_MAX_LENGTH]; -static uint8_t sChannel = 0; -static int8_t sTxPower = 0; - -static otRadioState sState = OT_RADIO_STATE_DISABLED; -static bool sIsReceiverEnabled = false; - -#if OPENTHREAD_CONFIG_LOG_PLATFORM && OPENTHREAD_CONFIG_CC2538_USE_RADIO_RX_INTERRUPT -// Debugging _and_ logging are enabled, so if there's a dropped frame -// we'll need to store the length here as using snprintf from an interrupt -// handler is not a good idea. -static uint8_t sDroppedFrameLength = 0; -#endif - -static int8_t cc2538RadioGetRssiOffset(void); - -void enableReceiver(void) -{ - if (!sIsReceiverEnabled) - { - otLogInfoPlat("Enabling receiver", NULL); - - // flush rxfifo - HWREG(RFCORE_SFR_RFST) = RFCORE_SFR_RFST_INSTR_FLUSHRX; - HWREG(RFCORE_SFR_RFST) = RFCORE_SFR_RFST_INSTR_FLUSHRX; - - // enable receiver - HWREG(RFCORE_SFR_RFST) = RFCORE_SFR_RFST_INSTR_RXON; - sIsReceiverEnabled = true; - } -} - -void disableReceiver(void) -{ - if (sIsReceiverEnabled) - { - otLogInfoPlat("Disabling receiver", NULL); - - while (HWREG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_TX_ACTIVE) - ; - - // flush rxfifo - HWREG(RFCORE_SFR_RFST) = RFCORE_SFR_RFST_INSTR_FLUSHRX; - HWREG(RFCORE_SFR_RFST) = RFCORE_SFR_RFST_INSTR_FLUSHRX; - - if (HWREG(RFCORE_XREG_RXENABLE) != 0) - { - // disable receiver - HWREG(RFCORE_SFR_RFST) = RFCORE_SFR_RFST_INSTR_RFOFF; - } - - sIsReceiverEnabled = false; - } -} - -void setChannel(uint8_t aChannel) -{ - if (sChannel != aChannel) - { - bool enabled = false; - - if (sIsReceiverEnabled) - { - disableReceiver(); - enabled = true; - } - - otLogInfoPlat("Channel=%d", aChannel); - - HWREG(RFCORE_XREG_FREQCTRL) = 11 + (aChannel - 11) * 5; - sChannel = aChannel; - - if (enabled) - { - enableReceiver(); - } - } -} - -void setTxPower(int8_t aTxPower) -{ - uint8_t i = 0; - - if (sTxPower != aTxPower) - { - otLogInfoPlat("TxPower=%d", aTxPower); - - for (i = sizeof(sTxPowerTable) / sizeof(TxPowerTable) - 1; i > 0; i--) - { - if (aTxPower < sTxPowerTable[i].mTxPowerVal) - { - break; - } - } - - HWREG(RFCORE_XREG_TXPOWER) = sTxPowerTable[i].mTxPowerReg; - sTxPower = aTxPower; - } -} - -static bool cc2538SrcMatchEnabled(void) -{ - return (HWREG(RFCORE_XREG_FRMCTRL1) & RFCORE_XREG_FRMCTRL1_PENDING_OR) == 0; -} - -static bool cc2538GetSrcMatchFoundIntFlag(void) -{ - bool flag = (HWREG(RFCORE_SFR_RFIRQF0) & RFCORE_SFR_RFIRQF0_SRC_MATCH_FOUND) != 0; - if (flag) - { - HWREG(RFCORE_SFR_RFIRQF0) &= ~RFCORE_SFR_RFIRQF0_SRC_MATCH_FOUND; - } - return flag; -} - -void otPlatRadioGetIeeeEui64(otInstance *aInstance, uint8_t *aIeeeEui64) -{ - OT_UNUSED_VARIABLE(aInstance); - - // EUI64 is in a mixed-endian format. Split in two halves, each 32-bit - // half is in little-endian format (machine endian). However, the - // most significant part of the EUI64 comes first, so we can't cheat - // with a uint64_t! - // - // See https://e2e.ti.com/support/wireless_connectivity/low_power_rf_tools/f/155/p/307344/1072252 - - volatile uint32_t *eui64 = &HWREG(IEEE_EUI64); - - // Read first 32-bits - uint32_t part = eui64[0]; - for (uint8_t i = 0; i < (OT_EXT_ADDRESS_SIZE / 2); i++) - { - aIeeeEui64[3 - i] = part; - part >>= 8; - } - - // Read the last 32-bits - part = eui64[1]; - for (uint8_t i = 0; i < (OT_EXT_ADDRESS_SIZE / 2); i++) - { - aIeeeEui64[7 - i] = part; - part >>= 8; - } -} - -void otPlatRadioSetPanId(otInstance *aInstance, uint16_t aPanid) -{ - OT_UNUSED_VARIABLE(aInstance); - - otLogInfoPlat("PANID=%X", aPanid); - - HWREG(RFCORE_FFSM_PAN_ID0) = aPanid & 0xFF; - HWREG(RFCORE_FFSM_PAN_ID1) = aPanid >> 8; -} - -void otPlatRadioSetExtendedAddress(otInstance *aInstance, const otExtAddress *aAddress) -{ - OT_UNUSED_VARIABLE(aInstance); - - otLogInfoPlat("ExtAddr=%X%X%X%X%X%X%X%X", aAddress->m8[7], aAddress->m8[6], aAddress->m8[5], aAddress->m8[4], - aAddress->m8[3], aAddress->m8[2], aAddress->m8[1], aAddress->m8[0]); - - for (int i = 0; i < 8; i++) - { - ((volatile uint32_t *)RFCORE_FFSM_EXT_ADDR0)[i] = aAddress->m8[i]; - } -} - -void otPlatRadioSetShortAddress(otInstance *aInstance, uint16_t aAddress) -{ - OT_UNUSED_VARIABLE(aInstance); - - otLogInfoPlat("ShortAddr=%X", aAddress); - - HWREG(RFCORE_FFSM_SHORT_ADDR0) = aAddress & 0xFF; - HWREG(RFCORE_FFSM_SHORT_ADDR1) = aAddress >> 8; -} - -void cc2538RadioInit(void) -{ - sTransmitFrame.mLength = 0; - sTransmitFrame.mPsdu = sTransmitPsdu; - sReceiveFrame.mLength = 0; - sReceiveFrame.mPsdu = sReceivePsdu; - -#if OPENTHREAD_CONFIG_CC2538_USE_RADIO_RX_INTERRUPT - // Enable interrupts for RX/TX, interrupt 26. - // That's NVIC index 0 (26 >> 5) bit 26 (26 & 0x1f). - HWREG(NVIC_EN0 + (0 * 4)) = (1 << 26); - HWREG(RFCORE_XREG_RFIRQM0) |= RFCORE_XREG_RFIRQM0_RXPKTDONE; -#endif - - // 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; - - // default: SRCMATCH.SRC_MATCH_EN(1), SRCMATCH.AUTOPEND(1), - // SRCMATCH.PEND_DATAREQ_ONLY(1), RFCORE_XREG_FRMCTRL1_PENDING_OR(0) - - HWREG(RFCORE_XREG_TXPOWER) = sTxPowerTable[0].mTxPowerReg; - sTxPower = sTxPowerTable[0].mTxPowerVal; - -#if OPENTHREAD_CONFIG_CC2538_WITH_CC2592 - // PA_EN pin configuration. - // Step 1. make it an output - HWREG(GPIO_C_BASE | GPIO_O_DIR) |= GPIO_PIN(OPENTHREAD_CONFIG_CC2592_PA_EN_PIN); - // Step 2. Route PA_PD to OBS0 and invert it to produce PA_EN - HWREG_ARR(RFCORE_XREG_RFC_OBS_CTRL, 0) = RFCORE_XREG_RFC_OBS_POL_INV // Invert the output - | RFCORE_XREG_RFC_OBS_MUX_PA_PD; // PA "power down" signal - // Step 3. Connect the selected pin to OBS0 and enable OBS0. - HWREG_ARR(CCTEST_OBSSEL, OPENTHREAD_CONFIG_CC2592_PA_EN_PIN) = CCTEST_OBSSEL_EN // Enable the output - | CCTEST_OBSSEL_SEL_OBS0; // Select OBS0 - - // LNA_EN pin configuration. - HWREG(GPIO_C_BASE | GPIO_O_DIR) |= GPIO_PIN(OPENTHREAD_CONFIG_CC2592_LNA_EN_PIN); - HWREG_ARR(RFCORE_XREG_RFC_OBS_CTRL, 1) = RFCORE_XREG_RFC_OBS_POL_INV | RFCORE_XREG_RFC_OBS_MUX_LNA_PD; - HWREG_ARR(CCTEST_OBSSEL, OPENTHREAD_CONFIG_CC2592_LNA_EN_PIN) = CCTEST_OBSSEL_EN | CCTEST_OBSSEL_SEL_OBS1; - -#if OPENTHREAD_CONFIG_CC2592_USE_HGM - // HGM pin configuration. Set the pin state first so we don't glitch. - cc2538RadioSetHgm(OPENTHREAD_CONFIG_CC2592_HGM_DEFAULT_STATE); - HWREG(OPENTHREAD_CONFIG_CC2592_HGM_PORT | GPIO_O_DIR) |= GPIO_PIN(OPENTHREAD_CONFIG_CC2592_HGM_PIN); -#endif // OPENTHREAD_CONFIG_CC2592_USE_HGM -#endif // OPENTHREAD_CONFIG_CC2538_WITH_CC2592 - - otLogInfoPlat("Initialized", NULL); -} - -#if OPENTHREAD_CONFIG_CC2538_WITH_CC2592 && OPENTHREAD_CONFIG_CC2592_USE_HGM -void cc2538RadioSetHgm(bool aState) -{ - if (aState) - { - HWREG_ARR(OPENTHREAD_CONFIG_CC2592_HGM_PORT, GPIO_PIN(OPENTHREAD_CONFIG_CC2592_HGM_PIN)) = - GPIO_PIN(OPENTHREAD_CONFIG_CC2592_HGM_PIN); - } - else - { - HWREG_ARR(OPENTHREAD_CONFIG_CC2592_HGM_PORT, GPIO_PIN(OPENTHREAD_CONFIG_CC2592_HGM_PIN)) = 0; - } -} - -bool cc2538RadioGetHgm(void) -{ - if (HWREG_ARR(OPENTHREAD_CONFIG_CC2592_HGM_PORT, GPIO_PIN(OPENTHREAD_CONFIG_CC2592_HGM_PIN)) & - GPIO_PIN(OPENTHREAD_CONFIG_CC2592_HGM_PIN)) - { - return true; - } - else - { - return false; - } -} -#endif // OPENTHREAD_CONFIG_CC2538_WITH_CC2592 && OPENTHREAD_CONFIG_CC2592_USE_HGM - -bool otPlatRadioIsEnabled(otInstance *aInstance) -{ - OT_UNUSED_VARIABLE(aInstance); - - return (sState != OT_RADIO_STATE_DISABLED) ? true : false; -} - -otError otPlatRadioEnable(otInstance *aInstance) -{ - if (!otPlatRadioIsEnabled(aInstance)) - { - otLogDebgPlat("State=OT_RADIO_STATE_SLEEP", NULL); - sState = OT_RADIO_STATE_SLEEP; - } - - return OT_ERROR_NONE; -} - -otError otPlatRadioDisable(otInstance *aInstance) -{ - if (otPlatRadioIsEnabled(aInstance)) - { - otLogDebgPlat("State=OT_RADIO_STATE_DISABLED", NULL); - sState = OT_RADIO_STATE_DISABLED; - } - - return OT_ERROR_NONE; -} - -otError otPlatRadioSleep(otInstance *aInstance) -{ - OT_UNUSED_VARIABLE(aInstance); - - otError error = OT_ERROR_INVALID_STATE; - - if (sState == OT_RADIO_STATE_SLEEP || sState == OT_RADIO_STATE_RECEIVE) - { - otLogDebgPlat("State=OT_RADIO_STATE_SLEEP", NULL); - error = OT_ERROR_NONE; - sState = OT_RADIO_STATE_SLEEP; - disableReceiver(); - } - - return error; -} - -otError otPlatRadioReceive(otInstance *aInstance, uint8_t aChannel) -{ - OT_UNUSED_VARIABLE(aInstance); - - otError error = OT_ERROR_INVALID_STATE; - - if (sState != OT_RADIO_STATE_DISABLED) - { - otLogDebgPlat("State=OT_RADIO_STATE_RECEIVE", NULL); - - error = OT_ERROR_NONE; - sState = OT_RADIO_STATE_RECEIVE; - setChannel(aChannel); - sReceiveFrame.mChannel = aChannel; - enableReceiver(); - } - - return error; -} - -static void setupTransmit(otRadioFrame *aFrame) -{ - int i; - - // wait for current TX operation to complete, if any. - while (HWREG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_TX_ACTIVE) - ; - - // flush txfifo - HWREG(RFCORE_SFR_RFST) = RFCORE_SFR_RFST_INSTR_FLUSHTX; - HWREG(RFCORE_SFR_RFST) = RFCORE_SFR_RFST_INSTR_FLUSHTX; - - // frame length - HWREG(RFCORE_SFR_RFDATA) = aFrame->mLength; - - // frame data - for (i = 0; i < aFrame->mLength; i++) - { - HWREG(RFCORE_SFR_RFDATA) = aFrame->mPsdu[i]; - } - - setChannel(aFrame->mChannel); -} - -otError otPlatRadioTransmit(otInstance *aInstance, otRadioFrame *aFrame) -{ - OT_UNUSED_VARIABLE(aInstance); - - otError error = OT_ERROR_INVALID_STATE; - - if (sState == OT_RADIO_STATE_RECEIVE) - { - int i; - - error = OT_ERROR_NONE; - sState = OT_RADIO_STATE_TRANSMIT; - sTransmitError = OT_ERROR_NONE; - - setupTransmit(aFrame); - - // Set up a counter to inform us if we get stuck. - i = 1000000; - - // Wait for radio to enter receive state. - while ((HWREG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_RX_ACTIVE) == 0) - { - // Count down the cycles, and emit a message if we get to zero. - // Ideally, we should never get there! - if (i) - { - i--; - } - else - { - otLogCritPlat("Radio is stuck!!! FSMSTAT0=0x%08x FSMSTAT1=0x%08x RFERRF=0x%08x", - HWREG(RFCORE_XREG_FSMSTAT0), HWREG(RFCORE_XREG_FSMSTAT1), HWREG(RFCORE_SFR_RFERRF)); - i = 1000000; - } - - // Ensure we haven't overflowed the RX buffer in the mean time, as this - // will cause a deadlock here otherwise. Similarly, if we see an aborted - // RX, handle that here too to prevent deadlock. - if (HWREG(RFCORE_SFR_RFERRF) & (RFCORE_SFR_RFERRF_RXOVERF | RFCORE_SFR_RFERRF_RXABO)) - { - if (HWREG(RFCORE_SFR_RFERRF) & RFCORE_SFR_RFERRF_RXOVERF) - { - otLogCritPlat("RX Buffer Overflow detected", NULL); - } - - if (HWREG(RFCORE_SFR_RFERRF) & RFCORE_SFR_RFERRF_RXABO) - { - otLogCritPlat("Aborted RX detected", NULL); - } - - // Flush the RX buffer - HWREG(RFCORE_SFR_RFST) = RFCORE_SFR_RFST_INSTR_FLUSHRX; - HWREG(RFCORE_SFR_RFST) = RFCORE_SFR_RFST_INSTR_FLUSHRX; - } - - // Check for idle state. After flushing the RX buffer, we may wind up here. - if (!(HWREG(RFCORE_XREG_FSMSTAT1) & (RFCORE_XREG_FSMSTAT1_TX_ACTIVE | RFCORE_XREG_FSMSTAT1_RX_ACTIVE))) - { - otLogCritPlat("Idle state detected", NULL); - - // In this case, the state of our driver mis-matches our state. So force - // matters by clearing our channel variable and calling setChannel. This - // should bring our radio into the RX state, which should allow us to go - // into TX. - sChannel = 0; - setupTransmit(aFrame); - } - } - - // wait for valid rssi - while ((HWREG(RFCORE_XREG_RSSISTAT) & RFCORE_XREG_RSSISTAT_RSSI_VALID) == 0) - ; - - otEXPECT_ACTION(((HWREG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_CCA) && - !((HWREG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_SFD))), - sTransmitError = OT_ERROR_CHANNEL_ACCESS_FAILURE); - - // begin transmit - HWREG(RFCORE_SFR_RFST) = RFCORE_SFR_RFST_INSTR_TXON; - - otPlatRadioTxStarted(aInstance, aFrame); - - while (HWREG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_TX_ACTIVE) - ; - - otLogDebgPlat("Transmitted %d bytes", aFrame->mLength); - } - -exit: - return error; -} - -otRadioFrame *otPlatRadioGetTransmitBuffer(otInstance *aInstance) -{ - OT_UNUSED_VARIABLE(aInstance); - - return &sTransmitFrame; -} - -int8_t otPlatRadioGetRssi(otInstance *aInstance) -{ - OT_UNUSED_VARIABLE(aInstance); - - int8_t rssi = OT_RADIO_RSSI_INVALID; - - if ((HWREG(RFCORE_XREG_RSSISTAT) & RFCORE_XREG_RSSISTAT_RSSI_VALID) != 0) - { - rssi = HWREG(RFCORE_XREG_RSSI) & 0xff; - - if (rssi > cc2538RadioGetRssiOffset() - 128) - { - rssi -= cc2538RadioGetRssiOffset(); - } - else - { - rssi = -128; - } - } - - return rssi; -} - -otRadioCaps otPlatRadioGetCaps(otInstance *aInstance) -{ - OT_UNUSED_VARIABLE(aInstance); - - return OT_RADIO_CAPS_ENERGY_SCAN; -} - -static bool cc2538RadioGetPromiscuous(void) -{ - return (HWREG(RFCORE_XREG_FRMFILT0) & RFCORE_XREG_FRMFILT0_FRAME_FILTER_EN) == 0; -} - -bool otPlatRadioGetPromiscuous(otInstance *aInstance) -{ - OT_UNUSED_VARIABLE(aInstance); - - return cc2538RadioGetPromiscuous(); -} - -static int8_t cc2538RadioGetRssiOffset(void) -{ -#if OPENTHREAD_CONFIG_CC2538_WITH_CC2592 && OPENTHREAD_CONFIG_CC2592_USE_HGM - if (cc2538RadioGetHgm()) - { - return CC2592_RSSI_OFFSET_HGM; - } - else - { - return CC2592_RSSI_OFFSET_LGM; - } -#else // OPENTHREAD_CONFIG_CC2538_WITH_CC2592 && OPENTHREAD_CONFIG_CC2592_USE_HGM - return CC2538_RSSI_OFFSET; -#endif // OPENTHREAD_CONFIG_CC2538_WITH_CC2592 && OPENTHREAD_CONFIG_CC2592_USE_HGM -} - -void otPlatRadioSetPromiscuous(otInstance *aInstance, bool aEnable) -{ - OT_UNUSED_VARIABLE(aInstance); - - otLogInfoPlat("PromiscuousMode=%d", aEnable ? 1 : 0); - - if (aEnable) - { - HWREG(RFCORE_XREG_FRMFILT0) &= ~RFCORE_XREG_FRMFILT0_FRAME_FILTER_EN; - } - else - { - HWREG(RFCORE_XREG_FRMFILT0) |= RFCORE_XREG_FRMFILT0_FRAME_FILTER_EN; - } -} - -static void readFrame(void) -{ - uint8_t length; - uint8_t crcCorr; - int i; - - /* - * There is already a frame present in the buffer, return early so - * we do not overwrite it (hopefully we'll catch it on the next run). - */ - otEXPECT(sReceiveFrame.mLength == 0); - - otEXPECT(sState == OT_RADIO_STATE_RECEIVE || sState == OT_RADIO_STATE_TRANSMIT); - otEXPECT((HWREG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_FIFOP) != 0); - - // read length - length = HWREG(RFCORE_SFR_RFDATA); - otEXPECT(IEEE802154_MIN_LENGTH <= length && length <= IEEE802154_MAX_LENGTH); - -#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE -#error Time sync requires the timestamp of SFD rather than that of rx done! -#else - // Timestamp - if (cc2538RadioGetPromiscuous()) -#endif - { - // The current driver only supports milliseconds resolution. - sReceiveFrame.mInfo.mRxInfo.mTimestamp = otPlatAlarmMilliGetNow() * 1000; - } - - // read psdu - for (i = 0; i < length - 2; i++) - { - sReceiveFrame.mPsdu[i] = HWREG(RFCORE_SFR_RFDATA); - } - - sReceiveFrame.mInfo.mRxInfo.mRssi = (int8_t)HWREG(RFCORE_SFR_RFDATA) - cc2538RadioGetRssiOffset(); - crcCorr = HWREG(RFCORE_SFR_RFDATA); - - if (crcCorr & CC2538_CRC_BIT_MASK) - { - sReceiveFrame.mLength = length; - sReceiveFrame.mInfo.mRxInfo.mLqi = crcCorr & CC2538_LQI_BIT_MASK; - - if (length > IEEE802154_ACK_LENGTH) - { - // Set ACK FP flag for the received frame according to whether SRC_MATCH_FOUND was triggered just before - // if SRC MATCH is not enabled, SRC_MATCH_FOUND is not triggered and all ACK FP is always set - sReceiveFrame.mInfo.mRxInfo.mAckedWithFramePending = - cc2538SrcMatchEnabled() ? cc2538GetSrcMatchFoundIntFlag() : true; - } - } - else - { - // resets rxfifo - HWREG(RFCORE_SFR_RFST) = RFCORE_SFR_RFST_INSTR_FLUSHRX; - HWREG(RFCORE_SFR_RFST) = RFCORE_SFR_RFST_INSTR_FLUSHRX; -#if OPENTHREAD_CONFIG_LOG_PLATFORM && OPENTHREAD_CONFIG_CC2538_USE_RADIO_RX_INTERRUPT - // Debugging _and_ logging are enabled, it may not be safe to do - // logging if we're in the interrupt context, so just stash the - // length and do the logging later. - sDroppedFrameLength = length; -#else - otLogDebgPlat("Dropping %d received bytes (Invalid CRC)", length); -#endif - } - - // 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) = RFCORE_SFR_RFST_INSTR_FLUSHRX; - HWREG(RFCORE_SFR_RFST) = RFCORE_SFR_RFST_INSTR_FLUSHRX; - } - -exit: - return; -} - -void cc2538RadioProcess(otInstance *aInstance) -{ -#if OPENTHREAD_CONFIG_CC2538_USE_RADIO_RX_INTERRUPT - // Disable the receive interrupt so that sReceiveFrame doesn't get - // blatted by the interrupt handler while we're polling. - HWREG(RFCORE_XREG_RFIRQM0) &= ~RFCORE_XREG_RFIRQM0_RXPKTDONE; -#endif - - readFrame(); - -#if OPENTHREAD_CONFIG_LOG_PLATFORM && OPENTHREAD_CONFIG_CC2538_USE_RADIO_RX_INTERRUPT - if (sDroppedFrameLength != 0) - { - otLogDebgPlat("Dropping %d received bytes (Invalid CRC)", sDroppedFrameLength); - sDroppedFrameLength = 0; - } -#endif - - if ((sState == OT_RADIO_STATE_RECEIVE && sReceiveFrame.mLength > 0) || - (sState == OT_RADIO_STATE_TRANSMIT && sReceiveFrame.mLength > IEEE802154_ACK_LENGTH)) - { -#if OPENTHREAD_CONFIG_DIAG_ENABLE - - if (otPlatDiagModeGet()) - { - otPlatDiagRadioReceiveDone(aInstance, &sReceiveFrame, sReceiveError); - } - else -#endif - { - // signal MAC layer for each received frame if promiscuous is enabled - // otherwise only signal MAC layer for non-ACK frame - if (((HWREG(RFCORE_XREG_FRMFILT0) & RFCORE_XREG_FRMFILT0_FRAME_FILTER_EN) == 0) || - (sReceiveFrame.mLength > IEEE802154_ACK_LENGTH)) - { - otLogDebgPlat("Received %d bytes", sReceiveFrame.mLength); - otPlatRadioReceiveDone(aInstance, &sReceiveFrame, sReceiveError); - } - } - } - - if (sState == OT_RADIO_STATE_TRANSMIT) - { - if (sTransmitError != OT_ERROR_NONE || (sTransmitFrame.mPsdu[0] & IEEE802154_ACK_REQUEST) == 0) - { - if (sTransmitError != OT_ERROR_NONE) - { - otLogDebgPlat("Transmit failed ErrorCode=%d", sTransmitError); - } - - sState = OT_RADIO_STATE_RECEIVE; - -#if OPENTHREAD_CONFIG_DIAG_ENABLE - - if (otPlatDiagModeGet()) - { - otPlatDiagRadioTransmitDone(aInstance, &sTransmitFrame, sTransmitError); - } - else -#endif - { - otPlatRadioTxDone(aInstance, &sTransmitFrame, NULL, 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 = OT_RADIO_STATE_RECEIVE; - - otPlatRadioTxDone(aInstance, &sTransmitFrame, &sReceiveFrame, sTransmitError); - } - } - - sReceiveFrame.mLength = 0; - -#if OPENTHREAD_CONFIG_CC2538_USE_RADIO_RX_INTERRUPT - // Turn the receive interrupt handler back on now the buffer is clear. - HWREG(RFCORE_XREG_RFIRQM0) |= RFCORE_XREG_RFIRQM0_RXPKTDONE; -#endif -} - -void RFCoreRxTxIntHandler(void) -{ -#if OPENTHREAD_CONFIG_CC2538_USE_RADIO_RX_INTERRUPT - if (HWREG(RFCORE_SFR_RFIRQF0) & RFCORE_SFR_RFIRQF0_RXPKTDONE) - { - readFrame(); - - if (sReceiveFrame.mLength > 0) - { - // A frame has been received, disable the interrupt handler - // until the main loop has dealt with this previous frame, - // otherwise we might overwrite it whilst it is being read. - HWREG(RFCORE_XREG_RFIRQM0) &= ~RFCORE_XREG_RFIRQM0_RXPKTDONE; - } - } -#endif - - HWREG(RFCORE_SFR_RFIRQF0) = 0; -} - -void RFCoreErrIntHandler(void) -{ - HWREG(RFCORE_SFR_RFERRF) = 0; -} - -uint32_t getSrcMatchEntriesEnableStatus(bool aShort) -{ - uint32_t status = 0; - uint32_t *addr = aShort ? (uint32_t *)RFCORE_XREG_SRCSHORTEN0 : (uint32_t *)RFCORE_XREG_SRCEXTEN0; - - for (uint8_t i = 0; i < RFCORE_XREG_SRCMATCH_ENABLE_STATUS_SIZE; i++) - { - status |= HWREG(addr++) << (i * 8); - } - - return status; -} - -int8_t findSrcMatchShortEntry(uint16_t aShortAddress) -{ - int8_t entry = -1; - uint16_t shortAddr; - uint32_t bitMask; - uint32_t *addr = NULL; - uint32_t status = getSrcMatchEntriesEnableStatus(true); - - for (uint8_t i = 0; i < RFCORE_XREG_SRCMATCH_SHORT_ENTRIES; i++) - { - bitMask = 0x00000001 << i; - - if ((status & bitMask) == 0) - { - continue; - } - - addr = (uint32_t *)RFCORE_FFSM_SRCADDRESS_TABLE + (i * RFCORE_XREG_SRCMATCH_SHORT_ENTRY_OFFSET); - - shortAddr = HWREG(addr + 2); - shortAddr |= HWREG(addr + 3) << 8; - - if ((shortAddr == aShortAddress)) - { - entry = i; - break; - } - } - - return entry; -} - -int8_t findSrcMatchExtEntry(const otExtAddress *aExtAddress) -{ - int8_t entry = -1; - uint32_t bitMask; - uint32_t *addr = NULL; - uint32_t status = getSrcMatchEntriesEnableStatus(false); - - for (uint8_t i = 0; i < RFCORE_XREG_SRCMATCH_EXT_ENTRIES; i++) - { - uint8_t j = 0; - bitMask = 0x00000001 << 2 * i; - - if ((status & bitMask) == 0) - { - continue; - } - - addr = (uint32_t *)RFCORE_FFSM_SRCADDRESS_TABLE + (i * RFCORE_XREG_SRCMATCH_EXT_ENTRY_OFFSET); - - for (j = 0; j < sizeof(otExtAddress); j++) - { - if (HWREG(addr + j) != aExtAddress->m8[j]) - { - break; - } - } - - if (j == sizeof(otExtAddress)) - { - entry = i; - break; - } - } - - return entry; -} - -void setSrcMatchEntryEnableStatus(bool aShort, uint8_t aEntry, bool aEnable) -{ - uint8_t entry = aShort ? aEntry : (2 * aEntry); - uint8_t index = entry / 8; - uint32_t *addrEn = aShort ? (uint32_t *)RFCORE_XREG_SRCSHORTEN0 : (uint32_t *)RFCORE_XREG_SRCEXTEN0; - uint32_t *addrAutoPendEn = aShort ? (uint32_t *)RFCORE_FFSM_SRCSHORTPENDEN0 : (uint32_t *)RFCORE_FFSM_SRCEXTPENDEN0; - uint32_t bitMask = 0x00000001; - - if (aEnable) - { - HWREG(addrEn + index) |= (bitMask) << (entry % 8); - HWREG(addrAutoPendEn + index) |= (bitMask) << (entry % 8); - } - else - { - HWREG(addrEn + index) &= ~((bitMask) << (entry % 8)); - HWREG(addrAutoPendEn + index) &= ~((bitMask) << (entry % 8)); - } -} - -int8_t findSrcMatchAvailEntry(bool aShort) -{ - int8_t entry = -1; - uint32_t bitMask; - uint32_t shortEnableStatus = getSrcMatchEntriesEnableStatus(true); - uint32_t extEnableStatus = getSrcMatchEntriesEnableStatus(false); - - otLogDebgPlat("Short enable status: 0x%x", shortEnableStatus); - otLogDebgPlat("Ext enable status: 0x%x", extEnableStatus); - - if (aShort) - { - bitMask = 0x00000001; - - for (uint8_t i = 0; i < RFCORE_XREG_SRCMATCH_SHORT_ENTRIES; i++) - { - if ((extEnableStatus & bitMask) == 0) - { - if ((shortEnableStatus & bitMask) == 0) - { - entry = i; - break; - } - } - - if (i % 2 == 1) - { - extEnableStatus = extEnableStatus >> 2; - } - - shortEnableStatus = shortEnableStatus >> 1; - } - } - else - { - bitMask = 0x00000003; - - for (uint8_t i = 0; i < RFCORE_XREG_SRCMATCH_EXT_ENTRIES; i++) - { - if (((extEnableStatus | shortEnableStatus) & bitMask) == 0) - { - entry = i; - break; - } - - extEnableStatus = extEnableStatus >> 2; - shortEnableStatus = shortEnableStatus >> 2; - } - } - - return entry; -} - -void cc2538EnergyScanTimerHandler(void) -{ - int8_t rssi = otPlatRadioGetRssi(sInstance); - - disableReceiver(); - - HWREG(RFCORE_XREG_FRMCTRL0) &= ~RFCORE_XREG_FRMCTRL0_ENERGY_SCAN; - HWREG(RFCORE_XREG_FREQCTRL) = 11 + (sChannel - 11) * 5; - - if (sIsReceiverEnabled) - { - enableReceiver(); - } - - otPlatRadioEnergyScanDone(sInstance, rssi); -} - -void otPlatRadioEnableSrcMatch(otInstance *aInstance, bool aEnable) -{ - OT_UNUSED_VARIABLE(aInstance); - - otLogInfoPlat("EnableSrcMatch=%d", aEnable ? 1 : 0); - - if (aEnable) - { - // only set FramePending when ack for data poll if there are queued messages - // for entries in the source match table. - HWREG(RFCORE_XREG_FRMCTRL1) &= ~RFCORE_XREG_FRMCTRL1_PENDING_OR; - } - else - { - // set FramePending for all ack. - HWREG(RFCORE_XREG_FRMCTRL1) |= RFCORE_XREG_FRMCTRL1_PENDING_OR; - } -} - -otError otPlatRadioAddSrcMatchShortEntry(otInstance *aInstance, uint16_t aShortAddress) -{ - OT_UNUSED_VARIABLE(aInstance); - - otError error = OT_ERROR_NONE; - int8_t entry = findSrcMatchAvailEntry(true); - uint32_t *addr = (uint32_t *)RFCORE_FFSM_SRCADDRESS_TABLE; - - otLogDebgPlat("Add ShortAddr entry: %d", entry); - - otEXPECT_ACTION(entry >= 0, error = OT_ERROR_NO_BUFS); - - addr += (entry * RFCORE_XREG_SRCMATCH_SHORT_ENTRY_OFFSET); - - HWREG(addr++) = HWREG(RFCORE_FFSM_PAN_ID0); - HWREG(addr++) = HWREG(RFCORE_FFSM_PAN_ID1); - HWREG(addr++) = aShortAddress & 0xFF; - HWREG(addr++) = aShortAddress >> 8; - - setSrcMatchEntryEnableStatus(true, (uint8_t)(entry), true); - -exit: - return error; -} - -otError otPlatRadioAddSrcMatchExtEntry(otInstance *aInstance, const otExtAddress *aExtAddress) -{ - OT_UNUSED_VARIABLE(aInstance); - - otError error = OT_ERROR_NONE; - int8_t entry = findSrcMatchAvailEntry(false); - uint32_t *addr = (uint32_t *)RFCORE_FFSM_SRCADDRESS_TABLE; - - otLogDebgPlat("Add ExtAddr entry: %d", entry); - - otEXPECT_ACTION(entry >= 0, error = OT_ERROR_NO_BUFS); - - addr += (entry * RFCORE_XREG_SRCMATCH_EXT_ENTRY_OFFSET); - - for (uint8_t i = 0; i < sizeof(otExtAddress); i++) - { - HWREG(addr++) = aExtAddress->m8[i]; - } - - setSrcMatchEntryEnableStatus(false, (uint8_t)(entry), true); - -exit: - return error; -} - -otError otPlatRadioClearSrcMatchShortEntry(otInstance *aInstance, uint16_t aShortAddress) -{ - OT_UNUSED_VARIABLE(aInstance); - - otError error = OT_ERROR_NONE; - int8_t entry = findSrcMatchShortEntry(aShortAddress); - - otLogDebgPlat("Clear ShortAddr entry: %d", entry); - - otEXPECT_ACTION(entry >= 0, error = OT_ERROR_NO_ADDRESS); - - setSrcMatchEntryEnableStatus(true, (uint8_t)(entry), false); - -exit: - return error; -} - -otError otPlatRadioClearSrcMatchExtEntry(otInstance *aInstance, const otExtAddress *aExtAddress) -{ - OT_UNUSED_VARIABLE(aInstance); - - otError error = OT_ERROR_NONE; - int8_t entry = findSrcMatchExtEntry(aExtAddress); - - otLogDebgPlat("Clear ExtAddr entry: %d", entry); - - otEXPECT_ACTION(entry >= 0, error = OT_ERROR_NO_ADDRESS); - - setSrcMatchEntryEnableStatus(false, (uint8_t)(entry), false); - -exit: - return error; -} - -void otPlatRadioClearSrcMatchShortEntries(otInstance *aInstance) -{ - OT_UNUSED_VARIABLE(aInstance); - - uint32_t *addrEn = (uint32_t *)RFCORE_XREG_SRCSHORTEN0; - uint32_t *addrAutoPendEn = (uint32_t *)RFCORE_FFSM_SRCSHORTPENDEN0; - - otLogDebgPlat("Clear ShortAddr entries", NULL); - - for (uint8_t i = 0; i < RFCORE_XREG_SRCMATCH_ENABLE_STATUS_SIZE; i++) - { - HWREG(addrEn++) = 0; - HWREG(addrAutoPendEn++) = 0; - } -} - -void otPlatRadioClearSrcMatchExtEntries(otInstance *aInstance) -{ - OT_UNUSED_VARIABLE(aInstance); - - uint32_t *addrEn = (uint32_t *)RFCORE_XREG_SRCEXTEN0; - uint32_t *addrAutoPendEn = (uint32_t *)RFCORE_FFSM_SRCEXTPENDEN0; - - otLogDebgPlat("Clear ExtAddr entries", NULL); - - for (uint8_t i = 0; i < RFCORE_XREG_SRCMATCH_ENABLE_STATUS_SIZE; i++) - { - HWREG(addrEn++) = 0; - HWREG(addrAutoPendEn++) = 0; - } -} - -otError otPlatRadioEnergyScan(otInstance *aInstance, uint8_t aScanChannel, uint16_t aScanDuration) -{ - OT_UNUSED_VARIABLE(aInstance); - - otLogInfoPlat("ScanChannel=%d", aScanChannel); - - if (aScanChannel != sChannel) - { - if (sIsReceiverEnabled) - { - disableReceiver(); - } - - HWREG(RFCORE_XREG_FREQCTRL) = 11 + (aScanChannel - 11) * 5; - - enableReceiver(); - } - else if (!sIsReceiverEnabled) - { - enableReceiver(); - } - - // Collect peak signal strength - HWREG(RFCORE_XREG_FRMCTRL0) |= RFCORE_XREG_FRMCTRL0_ENERGY_SCAN; - - cc2538SetTimer(OT_CC2538_TIMER_ENERGY_SCAN, aScanDuration); - - return OT_ERROR_NONE; -} - -otError otPlatRadioGetTransmitPower(otInstance *aInstance, int8_t *aPower) -{ - OT_UNUSED_VARIABLE(aInstance); - - otError error = OT_ERROR_NONE; - - otEXPECT_ACTION(aPower != NULL, error = OT_ERROR_INVALID_ARGS); - *aPower = sTxPower; - -exit: - return error; -} - -otError otPlatRadioSetTransmitPower(otInstance *aInstance, int8_t aPower) -{ - OT_UNUSED_VARIABLE(aInstance); - - setTxPower(aPower); - return OT_ERROR_NONE; -} - -otError otPlatRadioGetCcaEnergyDetectThreshold(otInstance *aInstance, int8_t *aThreshold) -{ - OT_UNUSED_VARIABLE(aInstance); - OT_UNUSED_VARIABLE(aThreshold); - - return OT_ERROR_NOT_IMPLEMENTED; -} - -otError otPlatRadioSetCcaEnergyDetectThreshold(otInstance *aInstance, int8_t aThreshold) -{ - OT_UNUSED_VARIABLE(aInstance); - OT_UNUSED_VARIABLE(aThreshold); - - return OT_ERROR_NOT_IMPLEMENTED; -} - -int8_t otPlatRadioGetReceiveSensitivity(otInstance *aInstance) -{ - OT_UNUSED_VARIABLE(aInstance); - -#if OPENTHREAD_CONFIG_CC2538_WITH_CC2592 && OPENTHREAD_CONFIG_CC2592_USE_HGM - if (cc2538RadioGetHgm()) - { - return CC2592_RECEIVE_SENSITIVITY_HGM; - } - else - { - return CC2592_RECEIVE_SENSITIVITY_LGM; - } -#else // OPENTHREAD_CONFIG_CC2538_WITH_CC2592 && OPENTHREAD_CONFIG_CC2592_USE_HGM - return CC2538_RECEIVE_SENSITIVITY; -#endif // OPENTHREAD_CONFIG_CC2538_WITH_CC2592 && OPENTHREAD_CONFIG_CC2592_USE_HGM -} diff --git a/examples/platforms/cc2538/rom-utility.h b/examples/platforms/cc2538/rom-utility.h deleted file mode 100644 index d0686efde..000000000 --- a/examples/platforms/cc2538/rom-utility.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2016, 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. - */ - -#ifndef ROM_UTILITY_H_ -#define ROM_UTILITY_H_ - -#define ROM_API_TABLE_ADDR 0x00000048 - -typedef uint32_t (*volatile FPTR_CRC32_T)(uint8_t * /*pData*/, uint32_t /*byteCount*/); -typedef uint32_t (*volatile FPTR_GETFLSIZE_T)(void); -typedef uint32_t (*volatile FPTR_GETCHIPID_T)(void); -typedef int32_t (*volatile FPTR_PAGEERASE_T)(uint32_t /*FlashAddr*/, uint32_t /*Size*/); -typedef int32_t (*volatile FPTR_PROGFLASH_T)(uint32_t * /*pRamData*/, uint32_t /*FlashAdr*/, uint32_t /*ByteCount*/); -typedef void (*volatile FPTR_RESETDEV_T)(void); -typedef void *(*volatile FPTR_MEMSET_T)(void * /*s*/, int32_t /*c*/, uint32_t /*n*/); -typedef void *(*volatile FPTR_MEMCPY_T)(void * /*s1*/, const void * /*s2*/, uint32_t /*n*/); -typedef int32_t (*volatile FPTR_MEMCMP_T)(const void * /*s1*/, const void * /*s2*/, uint32_t /*n*/); -typedef void *(*volatile FPTR_MEMMOVE_T)(void * /*s1*/, const void * /*s2*/, uint32_t /*n*/); - -typedef struct -{ - FPTR_CRC32_T Crc32; - FPTR_GETFLSIZE_T GetFlashSize; - FPTR_GETCHIPID_T GetChipId; - FPTR_PAGEERASE_T PageErase; - FPTR_PROGFLASH_T ProgramFlash; - FPTR_RESETDEV_T ResetDevice; - FPTR_MEMSET_T memset; - FPTR_MEMCPY_T memcpy; - FPTR_MEMCMP_T memcmp; - FPTR_MEMMOVE_T memmove; -} ROM_API_T; - -// clang-format off - -#define P_ROM_API ((ROM_API_T*)ROM_API_TABLE_ADDR) - -#define ROM_Crc32(a,b) P_ROM_API->Crc32(a,b) -#define ROM_GetFlashSize() P_ROM_API->GetFlashSize() -#define ROM_GetChipId() P_ROM_API->GetChipId() -#define ROM_PageErase(a,b) P_ROM_API->PageErase(a,b) -#define ROM_ProgramFlash(a,b,c) P_ROM_API->ProgramFlash(a,b,c) -#define ROM_ResetDevice() P_ROM_API->ResetDevice() -#define ROM_Memset(a,b,c) P_ROM_API->memset(a,b,c) -#define ROM_Memcpy(a,b,c) P_ROM_API->memcpy(a,b,c) -#define ROM_Memcmp(a,b,c) P_ROM_API->memcmp(a,b,c) -#define ROM_Memmove(a,b,c) P_ROM_API->memmove(a,b,c) - -// clang-format on - -#endif // ROM_UTILITY_H_ diff --git a/examples/platforms/cc2538/startup-gcc.c b/examples/platforms/cc2538/startup-gcc.c deleted file mode 100644 index f174bfa09..000000000 --- a/examples/platforms/cc2538/startup-gcc.c +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright (c) 2016, 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 gcc-specific startup code for the cc2538. - */ - -#include -#include - -#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)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[640] __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) - ; -} - -// clang-format off - -#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 - -// clang-format on - -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) - ; -} diff --git a/examples/platforms/cc2538/system.c b/examples/platforms/cc2538/system.c deleted file mode 100644 index 0d1cd63de..000000000 --- a/examples/platforms/cc2538/system.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2016, The OpenThread Authors. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * @file - * @brief - * This file includes the platform-specific initializers. - */ -#include "platform-cc2538.h" -#include - -otInstance *sInstance; - -void otSysInit(int argc, char *argv[]) -{ - OT_UNUSED_VARIABLE(argc); - OT_UNUSED_VARIABLE(argv); - -#if OPENTHREAD_CONFIG_ENABLE_DEBUG_UART - cc2538DebugUartInit(); -#endif - cc2538AlarmInit(); - cc2538RandomInit(); - cc2538RadioInit(); -} - -bool otSysPseudoResetWasRequested(void) -{ - return false; -} - -void otSysProcessDrivers(otInstance *aInstance) -{ - sInstance = aInstance; - - // should sleep and wait for interrupts here - - cc2538UartProcess(); - cc2538RadioProcess(aInstance); - cc2538AlarmProcess(aInstance); -} diff --git a/examples/platforms/cc2538/uart.c b/examples/platforms/cc2538/uart.c deleted file mode 100644 index 3325c9904..000000000 --- a/examples/platforms/cc2538/uart.c +++ /dev/null @@ -1,318 +0,0 @@ -/* - * Copyright (c) 2016, 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 -#include - -#include -#include -#include - -#include -#include - -#include "platform-cc2538.h" -#include "utils/code_utils.h" -#include "utils/uart.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; - -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 RecvBuffer sReceive; - -static void enable_uart_clocks(void) -{ - static int uart_clocks_done = 0; - - if (uart_clocks_done) - { - return; - } - - uart_clocks_done = 1; - -#if OPENTHREAD_CONFIG_ENABLE_DEBUG_UART - HWREG(SYS_CTRL_RCGCUART) = (SYS_CTRL_RCGCUART_UART0 | SYS_CTRL_RCGCUART_UART1); - HWREG(SYS_CTRL_SCGCUART) = (SYS_CTRL_SCGCUART_UART0 | SYS_CTRL_SCGCUART_UART1); - HWREG(SYS_CTRL_DCGCUART) = (SYS_CTRL_DCGCUART_UART0 | SYS_CTRL_DCGCUART_UART1); -#else - HWREG(SYS_CTRL_RCGCUART) = SYS_CTRL_RCGCUART_UART0; - HWREG(SYS_CTRL_SCGCUART) = SYS_CTRL_SCGCUART_UART0; - HWREG(SYS_CTRL_DCGCUART) = SYS_CTRL_DCGCUART_UART0; -#endif -} - -otError otPlatUartEnable(void) -{ - uint32_t div; - - sReceive.mHead = 0; - sReceive.mTail = 0; - - // clock - enable_uart_clocks(); - - 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_UARTRXD_UART0) = IOC_PAD_IN_SEL_PA0; - 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 OT_ERROR_NONE; -} - -otError otPlatUartDisable(void) -{ - return OT_ERROR_NONE; -} - -otError otPlatUartSend(const uint8_t *aBuf, uint16_t aBufLength) -{ - otError error = OT_ERROR_NONE; - - otEXPECT_ACTION(sTransmitBuffer == NULL, error = OT_ERROR_BUSY); - - sTransmitBuffer = aBuf; - sTransmitLength = aBufLength; - -exit: - return error; -} - -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; - } -} - -otError otPlatUartFlush(void) -{ - otEXPECT(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; - return OT_ERROR_NONE; - -exit: - return OT_ERROR_INVALID_STATE; -} - -void processTransmit(void) -{ - otPlatUartFlush(); - otPlatUartSendDone(); -} - -void cc2538UartProcess(void) -{ - processReceive(); - processTransmit(); -} - -void UART0IntHandler(void) -{ - uint32_t mis; - 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); - - // We can only write if incrementing mTail doesn't equal mHead - if (sReceive.mHead != (sReceive.mTail + 1) % kReceiveBufferSize) - { - sReceive.mBuffer[sReceive.mTail] = byte; - sReceive.mTail = (sReceive.mTail + 1) % kReceiveBufferSize; - } - } - } -} - -#if OPENTHREAD_CONFIG_ENABLE_DEBUG_UART - -int otPlatDebugUart_kbhit(void) -{ - uint32_t v; - - /* get flags */ - v = HWREG(UART1_BASE + UART_O_FR); - - /* if FIFO empty we have no data */ - return !(v & UART_FR_RXFE); -} - -int otPlatDebugUart_getc(void) -{ - int v = 1; - - /* if nothing in fifo */ - if (!otPlatDebugUart_kbhit()) - { - return -1; - } - - /* fetch */ - v = (int)HWREG(UART0_BASE + UART_O_DR); - v = (v & 0x0ff); - return v; -} - -void otPlatDebugUart_putchar_raw(int b) -{ - /* wait till not busy */ - while (HWREG(UART1_BASE + UART_O_FR) & UART_FR_TXFF) - ; - - /* write byte */ - HWREG(UART1_BASE + UART_O_DR) = ((uint32_t)(b & 0x0ff)); -} - -void cc2538DebugUartInit(void) -{ - int32_t a, b; - - // clocks - enable_uart_clocks(); - - HWREG(UART1_BASE + UART_O_CC) = 0; - - // UART1 - tx pin - // Using an RF06 Evaluation board - // http://www.ti.com/tool/cc2538dk - // PA3 => is jumper position RF1.14 - // To use these, you will require a "flying-lead" UART adapter - HWREG(IOC_PA3_SEL) = IOC_MUX_OUT_SEL_UART1_TXD; - HWREG(IOC_PA3_OVER) = IOC_OVERRIDE_OE; - HWREG(GPIO_A_BASE + GPIO_O_AFSEL) |= GPIO_PIN_3; - - // UART1 - rx pin we don't really use but we setup anyway - // PA2 => is jumper position RF1.16 - HWREG(IOC_UARTRXD_UART1) = IOC_PAD_IN_SEL_PA2; - HWREG(IOC_PA2_OVER) = IOC_OVERRIDE_DIS; - HWREG(GPIO_A_BASE + GPIO_O_AFSEL) |= GPIO_PIN_2; - - HWREG(UART1_BASE + UART_O_CC) = 0; - - // baud rate - b = (((kPlatformClock * 8) / kBaudRate) + 1) / 2; - a = b / 64; - b = b % 64; - - HWREG(UART1_BASE + UART_O_IBRD) = a; - HWREG(UART1_BASE + UART_O_FBRD) = b; - HWREG(UART1_BASE + UART_O_LCRH) = UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE; - - /* NOTE: - * uart1 is not using IRQs it is tx only - * and we block when writing bytes - */ - HWREG(UART1_BASE + UART_O_CTL) = UART_CTL_UARTEN | UART_CTL_TXE | UART_CTL_RXE; -} - -#endif diff --git a/script/cmake-build b/script/cmake-build index b91b7be09..b7c6d3ed5 100755 --- a/script/cmake-build +++ b/script/cmake-build @@ -66,7 +66,7 @@ OT_CMAKE_NINJA_TARGET=${OT_CMAKE_NINJA_TARGET:-} OT_SRCDIR="$(cd "$(dirname "$0")"/.. && pwd)" readonly OT_SRCDIR -readonly OT_PLATFORMS=(cc2538 simulation posix) +readonly OT_PLATFORMS=(simulation posix) readonly OT_POSIX_SIM_COMMON_OPTIONS=( "-DOT_ANYCAST_LOCATOR=ON" "-DOT_BORDER_AGENT=ON" @@ -162,9 +162,6 @@ main() local_options=("-DOT_LINK_RAW=ON") options+=("${OT_POSIX_SIM_COMMON_OPTIONS[@]}" "${local_options[@]}") ;; - cc2538) - options+=("-DCMAKE_TOOLCHAIN_FILE=examples/platforms/${platform}/arm-none-eabi.cmake" "-DCMAKE_BUILD_TYPE=MinSizeRel") - ;; *) options+=("-DCMAKE_TOOLCHAIN_FILE=examples/platforms/${platform}/arm-none-eabi.cmake") ;; diff --git a/src/posix/README.md b/src/posix/README.md index 9d3ff6293..d45a4a388 100644 --- a/src/posix/README.md +++ b/src/posix/README.md @@ -139,28 +139,6 @@ To build and program the device with RCP application, complete the following ste ./build/posix/src/posix/ot-cli 'spinel+hdlc+uart:///dev/ttyACM0?uart-baudrate=115200' ``` -### CC2538 - -#### Build - -``` -./script/cmake-build cc2538 -DOT_APP_CLI=OFF -DOT_APP_NCP=OFF -DOT_FTD=OFF -DOT_MTD=OFF -``` - -#### Flash - -```sh -arm-none-eabi-objcopy -O ihex build/cc2538/examples/apps/ncp/ot-rcp ot-rcp.bin -# see https://github.com/JelmerT/cc2538-bsl -python cc2538-bsl/cc2538-bsl.py -b 460800 -e -w -v -p /dev/ttyUSB0 ot-rcp.bin -``` - -#### Run - -```sh -./build/posix/src/posix/ot-cli 'spinel+hdlc+uart:///dev/ttyUSB0?uart-baudrate=115200' -``` - ## Daemon Mode OpenThread Posix Daemon mode uses a unix socket as input and output, so that OpenThread core can run as a service. And a client can communicate with it by connecting to the socket. The protocol is OpenThread CLI.