diff --git a/.gitignore b/.gitignore index a67ff3f50..c80b86fd0 100644 --- a/.gitignore +++ b/.gitignore @@ -12,13 +12,15 @@ *.ihex *.pyc *~ -obj_* +build/* Makefile.target Makefile.*.defines tools/doxygen/html +tools/readthedocs/_build patches-* -tools/tunslip -tools/tunslip6 +tools/serial-io/tunslip6 +tools/serial-io/serialdump +serialdump-* build tools/coffee-manager/build/ tools/coffee-manager/coffee.jar @@ -31,6 +33,7 @@ COOJA.testlog *.native *.nrf52dk *.openmote-cc2538 +*.simplelink *.sky *.firmware *.srf06-cc26xx @@ -58,6 +61,8 @@ COOJA.testlog *.err summary tests/[0-9][0-9]-*/org/ +tests/18-coap-lwm2m/Californium.properties +tests/18-coap-lwm2m/leshan-server-demo*.jar # x86 UEFI files cpu/x86/uefi/Makefile.uefi diff --git a/.gitmodules b/.gitmodules index 36eb3cd95..ed5ea056d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -19,3 +19,12 @@ [submodule "tests/18-coap-lwm2m/example-lwm2m-standalone"] path = tests/18-coap-lwm2m/example-lwm2m-standalone url = https://github.com/contiki-ng/example-lwm2m-standalone.git +[submodule "tools/motelist"] + path = tools/motelist + url = https://github.com/contiki-ng/motelist +[submodule "arch/cpu/simplelink-cc13xx-cc26xx/lib/coresdk_cc13xx_cc26xx"] + path = arch/cpu/simplelink-cc13xx-cc26xx/lib/coresdk_cc13xx_cc26xx + url = https://github.com/contiki-ng/coresdk_cc13xx_cc26xx.git +[submodule "arch/cpu/cc26xx-cc13xx/lib/cc2640r2-sdk"] + path = arch/cpu/cc26xx-cc13xx/lib/cc2640r2-sdk + url = https://github.com/contiki-ng/cc2640r2-sdk.git diff --git a/.travis.yml b/.travis.yml index 00dba89ab..ca4dbf8d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,35 +1,83 @@ # Setup environment for Docker language: generic services: docker - notifications: - - email: false + email: false +# Environment setup before test script. Runs for each build before_install: - # Environment setup before test script - - export CNG_HOST_PATH=`pwd` - - export DOCKER_IMG='simonduq/contiki-ng:latest' - - sudo chgrp -hR 1000 $CNG_HOST_PATH - - docker pull $DOCKER_IMG - - ant -q -f $CNG_HOST_PATH/tools/cooja/build.xml jar + # Check if anything has changed within the docker directory + - DOCKER_CHANGED=`git diff --name-only $TRAVIS_COMMIT_RANGE -- tools/docker | wc -l` + # If Docker directory has not changed, pull image from Dockerhub. Else, build + # image from Dockerifle. This needs to be done for each job. Any build error + # will count as Travis test failure. In case this updates develop, push new + # image to Dockerhub (secure credentials only readable on bulids to + # contiki-ng/contiki-ng branches, not forks or PRs) + - > + if [ $DOCKER_CHANGED == 0 ]; then + echo "Docker image unchanged, pull from Dockerhub" + docker pull $DOCKER_IMG; + else + echo "Docker image changed, build from Dockerfile" + docker build tools/docker -t $DOCKER_IMG; + if [ $? != 0 ]; then + echo "Failed to build Docker image" + exit 1 + fi + if [ $TRAVIS_SECURE_ENV_VARS == true ] && [ $TRAVIS_PULL_REQUEST == false ] && [ $TRAVIS_BRANCH == 'develop' ]; then + echo "This build is for an update of branch develop. Push image to Dockerhub" + echo $DOCKERHUB_PASSWD | docker login --username contiker --password-stdin + docker push $DOCKER_IMG; + fi + fi + # Build Cooja conditionally + - if [ ${BUILD_COOJA:-false} = true ] ; then + ant -q -f $CNG_HOST_PATH/tools/cooja/build.xml jar ; + fi -script: # The test script for each build. - - docker run --privileged -v $CNG_HOST_PATH:/home/user/contiki-ng -ti $DOCKER_IMG bash --login -c "make -C tests/??-$TEST_NAME"; + # Create a directory for out of tree tests and clone the test repo therein + # The directory will need created unconditionally so we can always chgrp and + # mount it, even if empty. Checkout a pre-defined version. + - mkdir -p $OUT_OF_TREE_TEST_PATH + - if [ ${TEST_NAME} = "out-of-tree-build" ] ; then + git clone --depth 1 https://github.com/contiki-ng/out-of-tree-tests $OUT_OF_TREE_TEST_PATH && + cd $OUT_OF_TREE_TEST_PATH && + git checkout $OUT_OF_TREE_TEST_VER ; + fi + # Set permissions for Docker mount + - sudo chgrp -hR 1000 $CNG_HOST_PATH $OUT_OF_TREE_TEST_PATH + +# The test script for each build +script: + - docker run --privileged -v $OUT_OF_TREE_TEST_PATH:/home/user/out-of-tree-tests -v $CNG_HOST_PATH:/home/user/contiki-ng -ti $DOCKER_IMG bash --login -c "make -C tests/??-$TEST_NAME"; # Check outcome of the test - $CNG_HOST_PATH/tests/check-test.sh $CNG_HOST_PATH/tests/??-$TEST_NAME; exit $?; +# Environment variables env: - # Parallel builds - - TEST_NAME='compile-base' - - TEST_NAME='compile-arm-ports-01' - - TEST_NAME='compile-arm-ports-02' - - TEST_NAME='rpl-lite' - - TEST_NAME='rpl-classic' - - TEST_NAME='tun-rpl-br' - - TEST_NAME='coap-lwm2m' - - TEST_NAME='simulation-base' - - TEST_NAME='ieee802154' - - TEST_NAME='compile-nxp-ports' - - TEST_NAME='doxygen' - - TEST_NAME='compile-tools' - - TEST_NAME='native-runs' + # Global environment variables, i.e., set for all builds + global: + - DOCKER_IMG='contiker/contiki-ng' + - CNG_HOST_PATH=`pwd` + - OUT_OF_TREE_TEST_PATH=$HOME/out-of-tree-tests + - OUT_OF_TREE_TEST_VER=2869ae7 + # Encrypted environment variables. + # Only available on builds of contiki-ng/contiki-ng branches, not PRs or forks. + - secure: 0nrV5yjpT2kE19Hlm7t619Qbmyjx/G7bSUI1c+U3kZbyuxnRlASjVcDN5uPBoimIfGiBRI0nRq690BogAJt4EKwbC1Dy8kC1XD8mRtQ2AIZ6PHaUoG9iS5sBhFBQK0XkB83bwh6omRn/04O0uuX74ooSWT7fDrWxi/y5+0ysXK6gRtOhdrJ3FU5OkNVewX8NeCdx3pOWhMOtXWdFkMIi1XRdDnvMM5/hHlHMkdXXtaZQX9UsK3Q3DSjPRLZjKRiOlcx9MIg2ebh9ITmd2Du2p2q/LKtoutJckvhbKQPWcZi/B+1ZTSff0FHBIg+EYxf6TeFuia7XSTWH7sr2CDCCtcvSR9bB5yW6jdmGfa8Af8I1TCBuqoSUo0Re50BZBZF7COleEh+IojbjXn2CIDMg5rT4Sh3qcMGvFn9OW1cz5h5UNSOk7EIAXXPcI7Aloxh2sBo4/DrvvbfIsKrvxV9Fx4bdyNtR7dZ7xsoOw6L0zttC3K9naf3VAOeBAyjBiRwm0tWxJC/buhTsKlYrthhyUrwLtYAFL4UHcazvz57hY/cEzR2X6F//9Hp7HFoNtn1E36doX3ZfeI22yxHMo9SYW7O69C45wbhJ29lAA9XXbYVyGBKFkY8C1NCZ0Xckt9H8/Ow5Sz8HmW/NNBJCn0Fsx+jezdGc4ED5naugNbLAyNg= + # Each line in the 'matrix' triggers a separate Travis build + matrix: + - TEST_NAME='compile-base' + - TEST_NAME='compile-arm-ports-01' + - TEST_NAME='compile-arm-ports-02' + - TEST_NAME='rpl-lite' BUILD_COOJA=true + - TEST_NAME='rpl-classic' BUILD_COOJA=true + - TEST_NAME='tun-rpl-br' BUILD_COOJA=true + - TEST_NAME='coap-lwm2m' + - TEST_NAME='simulation-base' BUILD_COOJA=true + - TEST_NAME='ieee802154' BUILD_COOJA=true + - TEST_NAME='compile-nxp-ports' + - TEST_NAME='documentation' + - TEST_NAME='compile-tools' + - TEST_NAME='native-runs' + - TEST_NAME='ipv6' BUILD_COOJA=true + - TEST_NAME='out-of-tree-build' diff --git a/LICENSE.md b/LICENSE.md index b2f909d44..f4b1a054c 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,41 +1,30 @@ -Contiki-NG is licensed under the 3-clause BSD license. This license gives -everyone the right to use and distribute the code, either in binary or -source code format, as long as the copyright license is retained in -the source code. +Copyright (c) (Year), (Name of copyright holder) +All rights reserved. -The copyright for different parts of the code is held by different -people and organizations, but the code is licensed under the same type -of license. The license text is: +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: -``` -/* - * Copyright (c) (Year), (Name of copyright holder) - * 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. - */ -``` +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. diff --git a/Makefile.embedded b/Makefile.embedded new file mode 100644 index 000000000..e6841926b --- /dev/null +++ b/Makefile.embedded @@ -0,0 +1,47 @@ +# This Makefile contains make variables and rules that are only applicable +# to builds for embedded devices (i.e. excluding platforms native and cooja). +# Future extensions to the build system that are of a similar nature (for +# embedded devices only), can be achieved by extending this Makefile here. + +### +### Targets using the tools/serial-io +### +RLWRAPGOALS = login serialdump serialview + +.PHONY: $(RLWRAPGOALS) + +BAUDRATE ?= 115200 +SERIALDUMP_TIME_FMT ?= + +ifeq ($(HOST_OS),Windows) + SERIALDUMP = $(SERIAL_DUMP_BIN) +else + RLWRAP = $(notdir $(shell which rlwrap)) + ifeq ($(RLWRAP),) + ifneq ($(filter $(RLWRAPGOALS),$(MAKECMDGOALS)),) + $(info Running serialdump without rlwrap support.) + $(info Consider installing rlwarp in order to be able to use command history) + endif + endif + SERIALDUMP = $(RLWRAP) $(SERIAL_DUMP_BIN) +endif + +serialdump: $(SERIAL_DUMP_BIN) + $(SERIALDUMP) -b$(BAUDRATE) -T$(SERIALDUMP_TIME_FMT) $(PORT) | tee serialdump-`date +%Y%m%d-%H%M` + +serialview: $(SERIAL_DUMP_BIN) + $(SERIALDUMP) -b$(BAUDRATE) -T$(SERIALDUMP_TIME_FMT) $(PORT) + +login: $(SERIAL_DUMP_BIN) + $(SERIALDUMP) -b$(BAUDRATE) $(PORT) + +### +### Targets using tools/motelist +### +CONTIKI_NG_MOTELIST_DIR = $(TOOLS_DIR)/motelist +CONTIKI_NG_MOTELIST = python $(CONTIKI_NG_MOTELIST_DIR)/motelist.py + +.PHONY: motelist-all + +motelist-all: + $(CONTIKI_NG_MOTELIST) diff --git a/Makefile.help b/Makefile.help new file mode 100644 index 000000000..d8de20c00 --- /dev/null +++ b/Makefile.help @@ -0,0 +1,29 @@ +usage: + @echo "Usage:" + @echo " make [TARGET=(TARGET)] [BOARD=(BOARD)] [DEFINES=(DEFINES)] [PORT=(PORT)] [target]" + @echo "" + @echo "Typical usage:" + @echo " make [TARGET=(TARGET)] [BOARD=(BOARD)] [all]" + @echo "" + @echo " Will build Contiki-NG firmware(s) from the current example dir" + @echo " for platform TARGET, board BOARD." + @echo "" + @echo "Miscellaneous targets:" + @echo " targets Prints list of supported platforms" + @echo " boards Prints a list of supported boards for TARGET" + @echo " savetarget Saves TARGET and BOARD for future invocations of make" + @echo " savedefines Saves DEFINES for future invocations of make" + @echo " clean Removes all compiled files for TARGET" + @echo " distclean Removes all compiled files for all TARGETs" + @echo " viewconf Prints Contiki-NG build configuration for TARGET" + @echo " %.flashprof Shows a Flash/ROM profile of a given firmware (e.g. hello-world.flashprof)" + @echo " %.ramprof Shows a RAM profile of a given firmware (e.g. hello-world.ramprof)" + @echo " %.o Produces an object file from a given source file (e.g. hello-world.o)" + @echo " %.e Produces the pre-processed version of a given source file (e.g. hello-world.e)" + @echo " %.s Produces an assembly file from a given source file (e.g. hello-world.s)" + @echo " login View the serial output of the device connected to PORT" + @echo " serialview Same as login, but prepend serial output with a unix timestamp" + @echo " serialdump same as serialview, but also save the output to a file" + @echo " motelist-all Prints a list of connected devices" + +help: usage diff --git a/Makefile.identify-target b/Makefile.identify-target index 7843fdf6a..86e06c093 100644 --- a/Makefile.identify-target +++ b/Makefile.identify-target @@ -1,3 +1,8 @@ +# This Makefile can be used to identify the selected TARGET used for a +# specific build. It can be included by example Makefiles that need to take +# decisions based on TARGET. It is also automatically included by the +# top-level Makefile.include. + ifeq ($(TARGET),) -include Makefile.target ifeq ($(TARGET),) diff --git a/Makefile.include b/Makefile.include index dd24fcacb..672c7f4c1 100644 --- a/Makefile.include +++ b/Makefile.include @@ -10,7 +10,8 @@ WERROR ?= 1 include $(CONTIKI)/Makefile.identify-target -CONTIKI_NG_TARGET_LIB = contiki-ng-$(TARGET).a +### Include Makefile.tools to pull in targets that allow us to build tools dir +include $(CONTIKI)/Makefile.tools ifeq ($(DEFINES),) -include Makefile.$(TARGET).defines @@ -36,17 +37,25 @@ ifdef CI endif endif -OBJECTDIR = obj_$(TARGET) +BUILD_DIR = build +BUILD_DIR_TARGET = $(BUILD_DIR)/$(TARGET) +BUILD_DIR_BOARD = $(BUILD_DIR_TARGET)/$(BOARD)/$(BUILD_DIR_CONFIG) +OBJECTDIR = $(BUILD_DIR_BOARD)/obj + +CONTIKI_NG_TARGET_LIB = $(BUILD_DIR_BOARD)/contiki-ng-$(TARGET).a LOWERCASE = -abcdefghijklmnopqrstuvwxyz/ UPPERCASE = _ABCDEFGHIJKLMNOPQRSTUVWXYZ_ TARGET_UPPERCASE := ${strip ${shell echo $(TARGET) | sed y!$(LOWERCASE)!$(UPPERCASE)!}} CFLAGS += -DCONTIKI=1 -DCONTIKI_TARGET_$(TARGET_UPPERCASE)=1 CFLAGS += -DCONTIKI_TARGET_STRING=\"$(TARGET)\" -ifneq ($(BOARD),) -TARGET_BOARD_UPPERCASE := ${strip ${shell echo $(BOARD) | sed y!$(LOWERCASE)!$(UPPERCASE)!}} -CFLAGS += -DCONTIKI_BOARD_$(TARGET_BOARD_UPPERCASE)=1 -CFLAGS += -DCONTIKI_BOARD_STRING=\"$(BOARD)\" + +CFLAGS += -Wno-unused-const-variable + +LDFLAGS_WERROR ?= -Wl,--fatal-warnings + +ifeq ($(WERROR),1) + LDFLAGS += $(LDFLAGS_WERROR) endif MODULES += os os/sys os/dev os/lib os/services @@ -69,10 +78,6 @@ endef CONTIKI_OBJECTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(CONTIKI_SOURCEFILES)}} PROJECT_OBJECTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(PROJECT_SOURCEFILES)}} -# Provide way to create $(OBJECTDIR) if it has been removed by make clean -$(OBJECTDIR): - mkdir $@ - uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1))) ### Include target makefile (TODO Unsafe?) @@ -118,6 +123,17 @@ endif # $(BOARD) not empty PLATFORM_ACTION ?= build +# Provide way to create $(OBJECTDIR) if it has been removed by make clean +$(OBJECTDIR): + $(TRACE_MKDIR) + $(Q)mkdir -p $@ + +ifneq ($(BOARD),) + TARGET_BOARD_UPPERCASE := ${strip ${shell echo $(BOARD) | sed y!$(LOWERCASE)!$(UPPERCASE)!}} + CFLAGS += -DCONTIKI_BOARD_$(TARGET_BOARD_UPPERCASE)=1 + CFLAGS += -DCONTIKI_BOARD_STRING=\"$(BOARD)\" +endif + # Configure MAC layer # The different options @@ -165,14 +181,12 @@ MAKE_NET ?= MAKE_NET_IPV6 ifeq ($(MAKE_NET),MAKE_NET_NULLNET) CFLAGS += -DNETSTACK_CONF_WITH_NULLNET=1 + MODULES += os/net/nullnet endif ifeq ($(MAKE_NET),MAKE_NET_IPV6) CFLAGS += -DNETSTACK_CONF_WITH_IPV6=1 MODULES += os/net/ipv6 -else - CFLAGS += -DNETSTACK_CONF_WITH_NULLNET=1 - MODULES += os/net/nullnet endif ifeq ($(MAKE_NET),MAKE_NET_OTHER) @@ -231,12 +245,20 @@ ifeq ($(V),1) TRACE_LD = TRACE_AR = TRACE_AS = + TRACE_OBJCOPY = + TRACE_OBJDUMP = + TRACE_MKDIR = + TRACE_CP = Q= else TRACE_CC = @echo " CC " $< TRACE_LD = @echo " LD " $@ TRACE_AR = @echo " AR " $@ TRACE_AS = @echo " AS " $< + TRACE_OBJCOPY = @echo " OBJCOPY " $< "-->" $@ + TRACE_OBJDUMP = @echo " OBJDUMP " $< "-->" $@ + TRACE_MKDIR = @echo " MKDIR " $@ + TRACE_CP = @echo " CP " $< "-->" $@ Q=@ endif @@ -293,21 +315,22 @@ endef ### Harmonize filename of a .map file, if the platform's build system wants ### to create one -CONTIKI_NG_PROJECT_MAP = $(addsuffix -$(TARGET).map, $(basename $@)) +CONTIKI_NG_PROJECT_MAP = $(BUILD_DIR_BOARD)/$(basename $(notdir $@)).map .PHONY: clean distclean usage help targets boards savetarget savedefines viewconf clean: - -rm -f *.d *.e *.o $(CONTIKI_NG_TARGET_LIB) $(CLEAN) - -rm -rf $(OBJECTDIR) - -rm -f $(addsuffix -$(TARGET).map, $(CONTIKI_PROJECT)) - -rm -f $(addsuffix .$(TARGET), $(CONTIKI_PROJECT)) + -$(Q)rm -f *.d *.e *.o $(CLEAN) + -$(Q)rm -rf $(BUILD_DIR_TARGET) + -$(Q)rm -f $(addsuffix .$(TARGET), $(CONTIKI_PROJECT)) + @echo Target $(TARGET) cleaned distclean: @for TARG in `ls $(CONTIKI)/arch/platform $(TARGETDIRS)`; do \ - echo make $$TARG clean; \ - make TARGET=$$TARG clean; \ + echo Running: $(MAKE) TARGET=$$TARG clean; \ + $(MAKE) TARGET=$$TARG clean; \ done + -$(Q)rm -rf $(BUILD_DIR) -include $(CONTIKI)/arch/platform/$(TARGET)/Makefile.customrules-$(TARGET) @@ -372,38 +395,23 @@ ifndef LD endif ifndef CUSTOM_RULE_LINK -%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB) +$(BUILD_DIR_BOARD)/%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB) $(TRACE_LD) $(Q)$(LD) $(LDFLAGS) $(TARGET_STARTFILES) ${filter-out %.a,$^} \ ${filter %.a,$^} $(TARGET_LIBFILES) -o $@ endif +%.$(TARGET): $(BUILD_DIR_BOARD)/%.$(TARGET) + $(TRACE_CP) + $(Q)cp $< $@ + %.ramprof: %.$(TARGET) $(NM) -S -td --size-sort $< | grep -i " [abdrw] " | cut -d' ' -f2,4 %.flashprof: %.$(TARGET) $(NM) -S -td --size-sort $< | grep -i " [t] " | cut -d' ' -f2,4 -usage: - @echo "Usage:" - @echo " make [TARGET=(TARGET)] [BOARD=(BOARD)] [DEFINES=(DEFINES)] [target]" - @echo "" - @echo "Typical usage:" - @echo " make [TARGET=(TARGET)] [BOARD=(BOARD)] [all]" - @echo "" - @echo " Will build Contiki-NG firmware(s) from the current example dir" - @echo " for platform TARGET, board BOARD." - @echo "" - @echo "Miscellaneous targets:" - @echo " targets Prints list of supported platforms" - @echo " boards Prints a list of supported boards for TARGET" - @echo " savegtarget Saves TARGET and BOARD for future invocations of make" - @echo " savedefines Saves DEFINES for future invocations of make" - @echo " clean Removes all compiled files for TARGET" - @echo " distclean Removes all compiled files for all TARGETs" - @echo " viewconf Prints Contiki-NG build configuration for TARGET" - -help: usage +include $(CONTIKI)/Makefile.help targets: @ls $(CONTIKI)/arch/platform $(TARGETDIRS) @@ -428,6 +436,7 @@ savedefines: @echo "saving Makefile.$(TARGET).defines" @echo >Makefile.$(TARGET).defines "DEFINES = $(DEFINES)" +VIEWCONF = $(CONTIKI)/tools/viewconf/viewconf.c viewconf: @echo "----------------- Make variables: --------------" @echo "##### \"TARGET\": ________________________________ $(TARGET)" @@ -439,17 +448,23 @@ ifdef MAKE_COAP_DTLS_KEYSTORE @echo "##### \"MAKE_COAP_DTLS_KEYSTORE\": _______________ $(MAKE_COAP_DTLS_KEYSTORE)" endif @echo "----------------- C variables: -----------------" - $(Q)$(CC) $(CFLAGS) -E $(CONTIKI)/tools/viewconf.c | grep \#\#\#\#\# + $(Q)$(CC) $(CFLAGS) -E $(VIEWCONF) | grep \#\#\#\#\# @echo "------------------------------------------------" @echo "'==' Means the flag is set to a given a value" @echo "'->' Means the flag is unset, but will default to a given value" @echo "'><' Means the flag is unset and has no default value" @echo "To view more Make variables, edit $(CONTIKI)/Makefile.include, rule 'viewconf'" - @echo "To view more C variables, edit $(CONTIKI)/tools/viewconf.c" + @echo "To view more C variables, edit $(VIEWCONF)" -# Don't treat %.$(TARGET) as an intermediate file because it is -# in fact the primary target. -.PRECIOUS: %.$(TARGET) +### Include Makefile.embedded for relevant platforms, in order to pull in +### rules for login, serialview etc +ifeq ($(findstring $(TARGET),native cooja),) + include $(CONTIKI)/Makefile.embedded +endif + +# Don't treat $(BUILD_DIR_BOARD)/%.$(TARGET) and $(TARGET) as intermediate +# files because for many platforms they are in fact the primary target. +.PRECIOUS: $(BUILD_DIR_BOARD)/%.$(TARGET) %.$(TARGET) # Cancel the predefined implict rule for compiling and linking # a single C source into a binary to force GNU make to consider diff --git a/Makefile.tools b/Makefile.tools new file mode 100644 index 000000000..81653cde6 --- /dev/null +++ b/Makefile.tools @@ -0,0 +1,17 @@ +# Some make rules in the main build system depend on the presence of utilities +# under the tools/ dir. For those dependencies, we use this makefile here to +# recursively invoke the respective build under tools/. + +TOOLS_DIR = $(CONTIKI)/tools +SERIAL_IO_TOOL_DIR = $(TOOLS_DIR)/serial-io + +SERIAL_IO_TOOL_DEPS = $(addprefix $(SERIAL_IO_TOOL_DIR)/, tools-utils.c tools-utils.h) + +TUNSLIP6 = $(SERIAL_IO_TOOL_DIR)/tunslip6 +SERIAL_DUMP_BIN = $(SERIAL_IO_TOOL_DIR)/serialdump + +$(SERIAL_DUMP_BIN): $(SERIAL_IO_TOOL_DIR)/serialdump.c $(SERIAL_IO_TOOL_DEPS) + $(MAKE) -C $(SERIAL_IO_TOOL_DIR) serialdump + +$(TUNSLIP6): $(SERIAL_IO_TOOL_DIR)/tunslip6.c $(SERIAL_IO_TOOL_DEPS) + $(MAKE) -C $(SERIAL_IO_TOOL_DIR) tunslip6 diff --git a/README.md b/README.md index df7d7ff58..e9a1005ef 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,10 @@ Contiki-NG is an open-source, cross-platform operating system for Next-Generation IoT devices. It focuses on dependable (secure and reliable) low-power communication and standard protocols, such as IPv6/6LoWPAN, 6TiSCH, RPL, and CoAP. Contiki-NG comes with extensive documentation, tutorials, a roadmap, release cycle, and well-defined development flow for smooth integration of community contributions. Unless excplicitly stated otherwise, Contiki-NG sources are distributed under -the terms of the [3-clause BSD license](LICENSE.md). +the terms of the [3-clause BSD license](LICENSE.md). This license gives +everyone the right to use and distribute the code, either in binary or +source code format, as long as the copyright license is retained in +the source code. Contiki-NG started as a fork of the Contiki OS and retains some of its original features. diff --git a/arch/cpu/arm/Makefile.arm b/arch/cpu/arm/Makefile.arm index 0b2662423..e8befdb86 100644 --- a/arch/cpu/arm/Makefile.arm +++ b/arch/cpu/arm/Makefile.arm @@ -1,3 +1,11 @@ +### Verbosity control. Use make V=1 to get verbose builds. +### Extends what we already have in the top-level Makefile +ifeq ($(V),1) + TRACE_SREC_CAT = +else + TRACE_SREC_CAT = @echo " SREC_CAT " $< "-->" $@ +endif + CC = arm-none-eabi-gcc CPP = arm-none-eabi-cpp LD = arm-none-eabi-gcc @@ -9,10 +17,13 @@ SIZE = arm-none-eabi-size SREC_CAT = srec_cat CFLAGS += -mthumb -mabi=aapcs -mlittle-endian -CFLAGS += -Werror -Wall +CFLAGS += -Wall CFLAGS += -std=c99 CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing CFLAGS += -fshort-enums -fomit-frame-pointer -fno-builtin +ifeq ($(WERROR),1) + CFLAGS += -Werror +endif LDFLAGS += -mthumb -mlittle-endian @@ -26,29 +37,46 @@ else CFLAGS += -O2 endif -### Use CMSIS and the existing dbg-io from arch/cpu/arm/common -CONTIKI_ARM_DIRS += . common/dbg-io +### Use CMSIS from arch/cpu/arm/common +CONTIKI_ARM_DIRS += . CONTIKI_CPU_DIRS += $(addprefix ../arm/, $(CONTIKI_ARM_DIRS)) +### Default to use os/lib/dbg-io unless configured to do otherwise +MAKE_WITH_LIB_DBG_IO ?= 1 + +ifeq ($(MAKE_WITH_LIB_DBG_IO),1) + MODULES += os/lib/dbg-io +endif + ### CPU-dependent cleanup files CLEAN += *.elf *.bin *.lst *.hex *.i16hex +OUT_HEX = $(BUILD_DIR_BOARD)/%.hex +OUT_I16HEX = $(BUILD_DIR_BOARD)/%.i16hex +OUT_BIN = $(BUILD_DIR_BOARD)/%.bin +OUT_LST = $(BUILD_DIR_BOARD)/%.lst + ### Don't treat the following files as intermediate -.PRECIOUS: %.elf %.hex %.bin +.PRECIOUS: $(OUT_ELF) $(OUT_HEX) $(OUT_BIN) -%.i16hex: %.elf - $(OBJCOPY) -O ihex $< $@ +$(OUT_I16HEX): $(OUT_ELF) + $(TRACE_OBJCOPY) + $(Q)$(OBJCOPY) -O ihex $< $@ -%.hex: %.i16hex - $(SREC_CAT) $< -intel -o $@ -intel +$(OUT_HEX): $(OUT_I16HEX) + $(TRACE_SREC_CAT) + $(Q)$(SREC_CAT) $< -intel -o $@ -intel -%.bin: %.elf - $(OBJCOPY) -O binary $(OBJCOPY_FLAGS) $< $@ +$(OUT_BIN): $(OUT_ELF) + $(TRACE_OBJCOPY) + $(Q)$(OBJCOPY) -O binary $(OBJCOPY_FLAGS) $< $@ -%.lst: %.elf - $(OBJDUMP) $(OBJDUMP_FLAGS) $< > $@ +$(OUT_LST): $(OUT_ELF) + $(TRACE_OBJDUMP) + $(Q)$(OBJDUMP) $(OBJDUMP_FLAGS) $< > $@ ### We don't really need the .hex and .bin for the .$(TARGET) but let's make ### sure they get built -%.$(TARGET): %.elf %.hex %.bin - cp $< $@ +$(BUILD_DIR_BOARD)/%.$(TARGET): $(OUT_ELF) $(OUT_HEX) $(OUT_BIN) + $(TRACE_CP) + $(Q)cp $< $@ diff --git a/arch/cpu/arm/arm-def.h b/arch/cpu/arm/arm-def.h index 92b19048d..c83cfd3fc 100644 --- a/arch/cpu/arm/arm-def.h +++ b/arch/cpu/arm/arm-def.h @@ -57,8 +57,6 @@ typedef uint32_t clock_time_t; typedef uint32_t uip_stats_t; -typedef uint32_t rtimer_clock_t; -#define RTIMER_CLOCK_DIFF(a, b) ((int32_t)((a) - (b))) /** @} */ /* diff --git a/arch/cpu/arm/cortex-m/Makefile.cortex-m b/arch/cpu/arm/cortex-m/Makefile.cortex-m index 444df05cd..0ca1d54ff 100644 --- a/arch/cpu/arm/cortex-m/Makefile.cortex-m +++ b/arch/cpu/arm/cortex-m/Makefile.cortex-m @@ -1,3 +1,28 @@ CONTIKI_ARM_DIRS += cortex-m cortex-m/CMSIS +### Build syscalls for newlib +MODULES += os/lib/newlib + +LDFLAGS += -T $(LDSCRIPT) +LDFLAGS += -Wl,--gc-sections,--sort-section=alignment +LDFLAGS += -Wl,-Map=$(CONTIKI_NG_PROJECT_MAP),--cref,--no-warn-mismatch + +OBJCOPY_FLAGS += --gap-fill 0xff + +CPU_STARTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(CPU_START_SOURCEFILES)}} + +### Resolve any potential circular dependencies between the linked libraries +### See: https://stackoverflow.com/questions/5651869/gcc-what-are-the-start-group-and-end-group-command-line-options/5651895 +TARGET_LIBFLAGS := -Wl,--start-group $(TARGET_LIBFILES) -Wl,--end-group + +CUSTOM_RULE_LINK = 1 + +OUT_ELF = $(BUILD_DIR_BOARD)/%.elf + +.SECONDEXPANSION: + +$(OUT_ELF): $(CPU_STARTFILES) $$(CONTIKI_OBJECTFILES) %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(LDSCRIPT) $(TARGET_LIBS) + $(TRACE_LD) + $(Q)$(LD) $(LDFLAGS) ${filter-out $(LDSCRIPT) %.a,$^} ${filter %.a,$^} $(TARGET_LIBFLAGS) -o $@ + include $(CONTIKI)/arch/cpu/arm/Makefile.arm diff --git a/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 b/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 index f5e8d2a3c..b4bf612da 100644 --- a/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 +++ b/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 @@ -3,24 +3,7 @@ CONTIKI_ARM_DIRS += cortex-m/cm3 CFLAGS += -mcpu=cortex-m3 LDFLAGS += -mcpu=cortex-m3 -nostartfiles -LDFLAGS += -T $(LDSCRIPT) -LDFLAGS += -Wl,--gc-sections,--sort-section=alignment -LDFLAGS += -Wl,-Map=$(CONTIKI_NG_PROJECT_MAP),--cref,--no-warn-mismatch -OBJCOPY_FLAGS += --gap-fill 0xff - -### Build syscalls for newlib -MODULES += os/lib/newlib - -CPU_STARTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(CPU_START_SOURCEFILES)}} - -### Compilation rules -CUSTOM_RULE_LINK = 1 - -.SECONDEXPANSION: - -%.elf: $(CPU_STARTFILES) $$(CONTIKI_OBJECTFILES) %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(LDSCRIPT) - $(TRACE_LD) - $(Q)$(LD) $(LDFLAGS) ${filter-out $(LDSCRIPT) %.a,$^} ${filter %.a,$^} $(TARGET_LIBFILES) -lm -o $@ +TARGET_LIBFILES += -lm include $(CONTIKI)/arch/cpu/arm/cortex-m/Makefile.cortex-m diff --git a/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 b/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 index 1f3cdd00b..7443681ea 100644 --- a/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 +++ b/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 @@ -1,13 +1,7 @@ CONTIKI_ARM_DIRS += cortex-m/cm4 CFLAGS += -mcpu=cortex-m4 + LDFLAGS += -mcpu=cortex-m4 -### Compilation rules -CUSTOM_RULE_LINK=1 - -%.elf: $(TARGET_STARTFILES) %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB) $(TARGET_LIBS) - $(TRACE_LD) - $(Q)$(CC) $(LDFLAGS) ${filter %.o %.a,$^} -o $@ - include $(CONTIKI)/arch/cpu/arm/cortex-m/Makefile.cortex-m diff --git a/arch/cpu/cc2538/Makefile.cc2538 b/arch/cpu/cc2538/Makefile.cc2538 index 891215093..51a5c40c7 100644 --- a/arch/cpu/cc2538/Makefile.cc2538 +++ b/arch/cpu/cc2538/Makefile.cc2538 @@ -28,8 +28,6 @@ CONTIKI_CPU_SOURCEFILES += slip-arch.c slip.c CONTIKI_CPU_SOURCEFILES += i2c.c cc2538-temp-sensor.c vdd3-sensor.c CONTIKI_CPU_SOURCEFILES += cfs-coffee.c cfs-coffee-arch.c pwm.c -MODULES += os/lib/dbg-io - USB_SOURCEFILES += usb-core.c cdc-acm.c usb-arch.c usb-serial.c cdc-acm-descriptors.c CPU_START_SOURCEFILES = startup-gcc.c diff --git a/arch/cpu/cc2538/cc2538-conf.h b/arch/cpu/cc2538/cc2538-conf.h index 725f95439..d34c3dee5 100644 --- a/arch/cpu/cc2538/cc2538-conf.h +++ b/arch/cpu/cc2538/cc2538-conf.h @@ -219,14 +219,6 @@ */ /* RF Config */ -#ifdef RF_CHANNEL -#define CC2538_RF_CONF_CHANNEL RF_CHANNEL -#endif - -#ifndef CC2538_RF_CONF_CHANNEL -#define CC2538_RF_CONF_CHANNEL 26 -#endif /* CC2538_RF_CONF_CHANNEL */ - #ifndef CC2538_RF_CONF_AUTOACK #define CC2538_RF_CONF_AUTOACK 1 /**< RF H/W generates ACKs */ #endif /* CC2538_CONF_AUTOACK */ diff --git a/arch/cpu/cc2538/cc2538-def.h b/arch/cpu/cc2538/cc2538-def.h index e4c7451a6..defa4ecb0 100644 --- a/arch/cpu/cc2538/cc2538-def.h +++ b/arch/cpu/cc2538/cc2538-def.h @@ -36,11 +36,16 @@ /*---------------------------------------------------------------------------*/ #define RTIMER_ARCH_SECOND 32768 /*---------------------------------------------------------------------------*/ +#define CC2538_PHY_OVERHEAD 3 +#define CC2538_BYTE_AIR_TIME 32 /* 352us from calling transmit() until the SFD byte has been sent */ -#define RADIO_DELAY_BEFORE_TX ((unsigned)US_TO_RTIMERTICKS(352)) +#define CC2538_DELAY_BEFORE_TX ((unsigned)US_TO_RTIMERTICKS(352)) /* 192us as in datasheet but ACKs are not always received, so adjusted to 250us */ -#define RADIO_DELAY_BEFORE_RX ((unsigned)US_TO_RTIMERTICKS(250)) -#define RADIO_DELAY_BEFORE_DETECT 0 +#define CC2538_DELAY_BEFORE_RX ((unsigned)US_TO_RTIMERTICKS(250)) +#define CC2538_DELAY_BEFORE_DETECT 0 +/* Frame filtering done in software */ +#define TSCH_CONF_HW_FRAME_FILTERING 0 + #ifndef TSCH_CONF_BASE_DRIFT_PPM /* The drift compared to "true" 10ms slots. * Enable adaptive sync to enable compensation for this. @@ -54,9 +59,6 @@ #define TSCH_CONF_BASE_DRIFT_PPM -977 #endif -#if MAC_CONF_WITH_TSCH -#define TSCH_CONF_HW_FRAME_FILTERING 0 -#endif /* MAC_CONF_WITH_TSCH */ /*---------------------------------------------------------------------------*/ #define SPI_CONF_CONTROLLER_COUNT 2 /*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/cc2538/dev/cc2538-rf.c b/arch/cpu/cc2538/dev/cc2538-rf.c index 5e6661b3e..bddfcc942 100644 --- a/arch/cpu/cc2538/dev/cc2538-rf.c +++ b/arch/cpu/cc2538/dev/cc2538-rf.c @@ -42,6 +42,7 @@ #include "net/packetbuf.h" #include "net/linkaddr.h" #include "net/netstack.h" +#include "net/mac/tsch/tsch.h" #include "sys/energest.h" #include "dev/cc2538-rf.h" #include "dev/rfcore.h" @@ -68,13 +69,10 @@ */ #define UDMA_RX_SIZE_THRESHOLD 3 /*---------------------------------------------------------------------------*/ -#include -#define DEBUG 0 -#if DEBUG -#define PRINTF(...) printf(__VA_ARGS__) -#else -#define PRINTF(...) -#endif +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "cc2538-rf" +#define LOG_LEVEL LOG_LEVEL_NONE /*---------------------------------------------------------------------------*/ /* Local RF Flags */ #define RX_ACTIVE 0x80 @@ -86,6 +84,7 @@ #define LQI_BIT_MASK 0x7F /* RSSI Offset */ #define RSSI_OFFSET 73 +#define RSSI_INVALID -128 /* 192 usec off -> on interval (RX Callib -> SFD Wait). We wait a bit more */ #define ONOFF_TIME RTIMER_ARCH_SECOND / 3125 @@ -113,7 +112,7 @@ static int8_t rssi; static uint8_t crc_corr; /*---------------------------------------------------------------------------*/ static uint8_t rf_flags; -static uint8_t rf_channel = CC2538_RF_CHANNEL; +static uint8_t rf_channel = IEEE802154_DEFAULT_CHANNEL; static int on(void); static int off(void); @@ -156,28 +155,19 @@ PROCESS(cc2538_rf_process, "cc2538 RF driver"); static uint8_t get_channel() { - uint8_t chan = REG(RFCORE_XREG_FREQCTRL) & RFCORE_XREG_FREQCTRL_FREQ; - - return (chan - CC2538_RF_CHANNEL_MIN) / CC2538_RF_CHANNEL_SPACING - + CC2538_RF_CHANNEL_MIN; + return rf_channel; } /*---------------------------------------------------------------------------*/ /** * \brief Set the current operating channel * \param channel The desired channel as a value in [11,26] - * \return Returns a value in [11,26] representing the current channel - * or a negative value if \e channel was out of bounds */ -static int8_t +static void set_channel(uint8_t channel) { uint8_t was_on = 0; - PRINTF("RF: Set Channel\n"); - - if((channel < CC2538_RF_CHANNEL_MIN) || (channel > CC2538_RF_CHANNEL_MAX)) { - return CC2538_RF_CHANNEL_SET_ERROR; - } + LOG_INFO("Set Channel\n"); /* Changes to FREQCTRL take effect after the next recalibration */ @@ -195,8 +185,6 @@ set_channel(uint8_t channel) } rf_channel = channel; - - return (int8_t)channel; } /*---------------------------------------------------------------------------*/ static radio_value_t @@ -244,10 +232,11 @@ get_rssi(void) on(); } - /* Wait on RSSI_VALID */ - while((REG(RFCORE_XREG_RSSISTAT) & RFCORE_XREG_RSSISTAT_RSSI_VALID) == 0); - - rssi = (int8_t)(REG(RFCORE_XREG_RSSI) & RFCORE_XREG_RSSI_RSSI_VAL) - RSSI_OFFSET; + /* Wait for a valid RSSI reading */ + do { + rssi = REG(RFCORE_XREG_RSSI); + } while(rssi == RSSI_INVALID); + rssi -= RSSI_OFFSET; /* If we were off, turn back off */ if(was_off) { @@ -322,6 +311,16 @@ set_frame_filtering(uint8_t enable) } /*---------------------------------------------------------------------------*/ static void +set_shr_search(int enable) +{ + if(enable) { + REG(RFCORE_XREG_FRMCTRL0) &= ~RFCORE_XREG_FRMCTRL0_RX_MODE; + } else { + REG(RFCORE_XREG_FRMCTRL0) |= RFCORE_XREG_FRMCTRL0_RX_MODE; + } +} +/*---------------------------------------------------------------------------*/ +static void mac_timer_init(void) { CLOCK_STABLE(); @@ -403,7 +402,7 @@ channel_clear(void) int cca; uint8_t was_off = 0; - PRINTF("RF: CCA\n"); + LOG_INFO("CCA\n"); /* If we are off, turn on first */ if((REG(RFCORE_XREG_FSMSTAT0) & RFCORE_XREG_FSMSTAT0_FSM_FFCTRL_STATE) == 0) { @@ -431,7 +430,7 @@ channel_clear(void) static int on(void) { - PRINTF("RF: On\n"); + LOG_INFO("On\n"); if(!(rf_flags & RX_ACTIVE)) { CC2538_RF_CSP_ISFLUSHRX(); @@ -447,7 +446,7 @@ on(void) static int off(void) { - PRINTF("RF: Off\n"); + LOG_INFO("Off\n"); /* Wait for ongoing TX to complete (e.g. this could be an outgoing ACK) */ while(REG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_TX_ACTIVE); @@ -470,7 +469,7 @@ off(void) static int init(void) { - PRINTF("RF: Init\n"); + LOG_INFO("Init\n"); if(rf_flags & RF_ON) { return 0; @@ -490,6 +489,7 @@ init(void) REG(RFCORE_XREG_TXFILTCFG) = 0x09; /** TX anti-aliasing filter bandwidth */ REG(RFCORE_XREG_AGCCTRL1) = 0x15; /** AGC target value */ REG(ANA_REGS_IVCTRL) = 0x0B; /** Bias currents */ + REG(RFCORE_XREG_FSCAL1) = 0x01; /** Tune frequency calibration */ /* * Defaults: @@ -513,6 +513,9 @@ init(void) set_channel(rf_channel); + /* Enable SHR search */ + set_shr_search(1); + /* Acknowledge all RF Error interrupts */ REG(RFCORE_XREG_RFERRM) = RFCORE_XREG_RFERRM_RFERRM; NVIC_EnableIRQ(RF_ERR_IRQn); @@ -545,8 +548,6 @@ init(void) rf_flags |= RF_ON; - ENERGEST_ON(ENERGEST_TYPE_LISTEN); - return 1; } /*---------------------------------------------------------------------------*/ @@ -555,7 +556,7 @@ prepare(const void *payload, unsigned short payload_len) { uint8_t i; - PRINTF("RF: Prepare 0x%02x bytes\n", payload_len + CHECKSUM_LEN); + LOG_INFO("Prepare 0x%02x bytes\n", payload_len + CHECKSUM_LEN); /* * When we transmit in very quick bursts, make sure previous transmission @@ -569,12 +570,12 @@ prepare(const void *payload, unsigned short payload_len) CC2538_RF_CSP_ISFLUSHTX(); - PRINTF("RF: data = "); + LOG_INFO("data = "); /* Send the phy length byte first */ REG(RFCORE_SFR_RFDATA) = payload_len + CHECKSUM_LEN; if(CC2538_RF_CONF_TX_USE_DMA) { - PRINTF(""); + LOG_INFO_(""); /* Set the transfer source's end address */ udma_set_channel_src(CC2538_RF_CONF_TX_DMA_CHAN, @@ -598,10 +599,10 @@ prepare(const void *payload, unsigned short payload_len) } else { for(i = 0; i < payload_len; i++) { REG(RFCORE_SFR_RFDATA) = ((unsigned char *)(payload))[i]; - PRINTF("%02x", ((unsigned char *)(payload))[i]); + LOG_INFO_("%02x", ((unsigned char *)(payload))[i]); } } - PRINTF("\n"); + LOG_INFO_("\n"); return 0; } @@ -614,7 +615,7 @@ transmit(unsigned short transmit_len) rtimer_clock_t t0; uint8_t was_off = 0; - PRINTF("RF: Transmit\n"); + LOG_INFO("Transmit\n"); if(!(rf_flags & RX_ACTIVE)) { t0 = RTIMER_NOW(); @@ -649,7 +650,7 @@ transmit(unsigned short transmit_len) } if(!(REG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_TX_ACTIVE)) { - PRINTF("RF: TX never active.\n"); + LOG_ERR("TX never active.\n"); CC2538_RF_CSP_ISFLUSHTX(); ret = RADIO_TX_ERR; } else { @@ -679,7 +680,7 @@ read(void *buf, unsigned short bufsize) uint8_t i; uint8_t len; - PRINTF("RF: Read\n"); + LOG_INFO("Read\n"); if((REG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_FIFOP) == 0) { return 0; @@ -691,33 +692,33 @@ read(void *buf, unsigned short bufsize) /* Check for validity */ if(len > CC2538_RF_MAX_PACKET_LEN) { /* Oops, we must be out of sync. */ - PRINTF("RF: bad sync\n"); + LOG_ERR("RF: bad sync\n"); CC2538_RF_CSP_ISFLUSHRX(); return 0; } if(len <= CC2538_RF_MIN_PACKET_LEN) { - PRINTF("RF: too short\n"); + LOG_ERR("RF: too short\n"); CC2538_RF_CSP_ISFLUSHRX(); return 0; } if(len - CHECKSUM_LEN > bufsize) { - PRINTF("RF: too long\n"); + LOG_ERR("RF: too long\n"); CC2538_RF_CSP_ISFLUSHRX(); return 0; } /* If we reach here, chances are the FIFO is holding a valid frame */ - PRINTF("RF: read (0x%02x bytes) = ", len); + LOG_INFO("read (0x%02x bytes) = ", len); len -= CHECKSUM_LEN; /* Don't bother with uDMA for short frames (e.g. ACKs) */ if(CC2538_RF_CONF_RX_USE_DMA && len > UDMA_RX_SIZE_THRESHOLD) { - PRINTF(""); + LOG_INFO_(""); /* Set the transfer destination's end address */ udma_set_channel_dst(CC2538_RF_CONF_RX_DMA_CHAN, @@ -738,7 +739,7 @@ read(void *buf, unsigned short bufsize) } else { for(i = 0; i < len; ++i) { ((unsigned char *)(buf))[i] = REG(RFCORE_SFR_RFDATA); - PRINTF("%02x", ((unsigned char *)(buf))[i]); + LOG_INFO_("%02x", ((unsigned char *)(buf))[i]); } } @@ -746,14 +747,14 @@ read(void *buf, unsigned short bufsize) rssi = ((int8_t)REG(RFCORE_SFR_RFDATA)) - RSSI_OFFSET; crc_corr = REG(RFCORE_SFR_RFDATA); - PRINTF("%02x%02x\n", (uint8_t)rssi, crc_corr); + LOG_INFO_("%02x%02x\n", (uint8_t)rssi, crc_corr); /* MS bit CRC OK/Not OK, 7 LS Bits, Correlation value */ if(crc_corr & CRC_BIT_MASK) { packetbuf_set_attr(PACKETBUF_ATTR_RSSI, rssi); packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, crc_corr & LQI_BIT_MASK); } else { - PRINTF("RF: Bad CRC\n"); + LOG_ERR("Bad CRC\n"); CC2538_RF_CSP_ISFLUSHRX(); return 0; } @@ -775,7 +776,7 @@ read(void *buf, unsigned short bufsize) static int receiving_packet(void) { - PRINTF("RF: Receiving\n"); + LOG_INFO("Receiving\n"); /* * SFD high while transmitting and receiving. @@ -791,7 +792,7 @@ receiving_packet(void) static int pending_packet(void) { - PRINTF("RF: Pending\n"); + LOG_INFO("Pending\n"); return REG(RFCORE_XREG_FSMSTAT1) & RFCORE_XREG_FSMSTAT1_FIFOP; } @@ -862,6 +863,21 @@ get_value(radio_param_t param, radio_value_t *value) case RADIO_CONST_TXPOWER_MAX: *value = OUTPUT_POWER_MAX; return RADIO_RESULT_OK; + case RADIO_CONST_PHY_OVERHEAD: + *value = (radio_value_t)3; /* 1 len byte, 2 bytes CRC */ + return RADIO_RESULT_OK; + case RADIO_CONST_BYTE_AIR_TIME: + *value = (radio_value_t)32; /* 250kbps data rate. One byte = 32us.*/ + return RADIO_RESULT_OK; + case RADIO_CONST_DELAY_BEFORE_TX: + *value = (radio_value_t)CC2538_DELAY_BEFORE_TX; + return RADIO_RESULT_OK; + case RADIO_CONST_DELAY_BEFORE_RX: + *value = (radio_value_t)CC2538_DELAY_BEFORE_RX; + return RADIO_RESULT_OK; + case RADIO_CONST_DELAY_BEFORE_DETECT: + *value = (radio_value_t)CC2538_DELAY_BEFORE_DETECT; + return RADIO_RESULT_OK; default: return RADIO_RESULT_NOT_SUPPORTED; } @@ -886,9 +902,7 @@ set_value(radio_param_t param, radio_value_t value) value > CC2538_RF_CHANNEL_MAX) { return RADIO_RESULT_INVALID_VALUE; } - if(set_channel(value) == CC2538_RF_CHANNEL_SET_ERROR) { - return RADIO_RESULT_ERROR; - } + set_channel(value); return RADIO_RESULT_OK; case RADIO_PARAM_PAN_ID: set_pan_id(value & 0xffff); @@ -924,6 +938,9 @@ set_value(radio_param_t param, radio_value_t value) case RADIO_PARAM_CCA_THRESHOLD: set_cca_threshold(value); return RADIO_RESULT_OK; + case RADIO_PARAM_SHR_SEARCH: + set_shr_search(value); + return RADIO_RESULT_OK; default: return RADIO_RESULT_NOT_SUPPORTED; } @@ -956,6 +973,16 @@ get_object(radio_param_t param, void *dest, size_t size) return RADIO_RESULT_OK; } +#if MAC_CONF_WITH_TSCH + if(param == RADIO_CONST_TSCH_TIMING) { + if(size != sizeof(uint16_t *) || !dest) { + return RADIO_RESULT_INVALID_VALUE; + } + *(const uint16_t **)dest = tsch_timeslot_timing_us_10000; + return RADIO_RESULT_OK; + } +#endif /* MAC_CONF_WITH_TSCH */ + return RADIO_RESULT_NOT_SUPPORTED; } /*---------------------------------------------------------------------------*/ @@ -1085,7 +1112,7 @@ cc2538_rf_rx_tx_isr(void) void cc2538_rf_err_isr(void) { - PRINTF("RF Error: 0x%08lx\n", REG(RFCORE_SFR_RFERRF)); + LOG_ERR("Error 0x%08lx occurred\n", REG(RFCORE_SFR_RFERRF)); /* If the error is not an RX FIFO overflow, set a flag */ if(REG(RFCORE_SFR_RFERRF) != RFCORE_SFR_RFERRF_RXOVERF) { @@ -1097,10 +1124,5 @@ cc2538_rf_err_isr(void) process_poll(&cc2538_rf_process); } /*---------------------------------------------------------------------------*/ -void -cc2538_rf_set_promiscous_mode(char p) -{ - set_frame_filtering(p); -} -/*---------------------------------------------------------------------------*/ + /** @} */ diff --git a/arch/cpu/cc2538/dev/cc2538-rf.h b/arch/cpu/cc2538/dev/cc2538-rf.h index 87fef3a59..958221783 100644 --- a/arch/cpu/cc2538/dev/cc2538-rf.h +++ b/arch/cpu/cc2538/dev/cc2538-rf.h @@ -56,7 +56,6 @@ #define CC2538_RF_CHANNEL_MIN 11 #define CC2538_RF_CHANNEL_MAX 26 #define CC2538_RF_CHANNEL_SPACING 5 -#define CC2538_RF_CHANNEL_SET_ERROR -1 #define CC2538_RF_MAX_PACKET_LEN 127 #define CC2538_RF_MIN_PACKET_LEN 4 #define CC2538_RF_CCA_CLEAR 1 @@ -74,12 +73,6 @@ #define CC2538_RF_CCA_THRES CC2538_RF_CCA_THRES_USER_GUIDE #endif /* CC2538_RF_CONF_CCA_THRES */ -#ifdef CC2538_RF_CONF_CHANNEL -#define CC2538_RF_CHANNEL CC2538_RF_CONF_CHANNEL -#else -#define CC2538_RF_CHANNEL 18 -#endif /* CC2538_RF_CONF_CHANNEL */ - #ifdef CC2538_RF_CONF_AUTOACK #define CC2538_RF_AUTOACK CC2538_RF_CONF_AUTOACK #else @@ -119,7 +112,6 @@ */ #define CC2538_RF_CSP_ISFLUSHRX() do { \ REG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISFLUSHRX; \ - REG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISFLUSHRX; \ } while(0) /** @@ -127,7 +119,6 @@ */ #define CC2538_RF_CSP_ISFLUSHTX() do { \ REG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISFLUSHTX; \ - REG(RFCORE_SFR_RFST) = CC2538_RF_CSP_OP_ISFLUSHTX; \ } while(0) /*---------------------------------------------------------------------------*/ /** The NETSTACK data structure for the cc2538 RF driver */ @@ -144,16 +135,6 @@ extern const struct radio_driver cc2538_rf_driver; */ void cc2538_rf_set_addr(uint16_t pan); -/** - * \brief Turn promiscous mode on or off - * \param p If promiscous mode should be on (1) or off (0) - * - * This function turns promiscous mode on or off. In promiscous mode, - * every received frame is returned from the RF core. In - * non-promiscous mode, only broadcast frames or frames with our - * address as the receive address are returned from the RF core. - */ -void cc2538_rf_set_promiscous_mode(char p); /*---------------------------------------------------------------------------*/ #endif /* CC2538_RF_H__ */ diff --git a/arch/cpu/cc2538/dev/gpio-hal-arch.h b/arch/cpu/cc2538/dev/gpio-hal-arch.h index 25abb3eb4..ad2f24219 100644 --- a/arch/cpu/cc2538/dev/gpio-hal-arch.h +++ b/arch/cpu/cc2538/dev/gpio-hal-arch.h @@ -56,6 +56,8 @@ #define PIN_TO_NUM(pin) (pin % 8) #define PIN_TO_PORT_BASE(pin) GPIO_PORT_TO_BASE(PIN_TO_PORT(pin)) /*---------------------------------------------------------------------------*/ +#define gpio_hal_arch_init() do { /* Do nothing */ } while(0) + #define gpio_hal_arch_interrupt_enable(p) do { \ GPIO_ENABLE_INTERRUPT(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)); \ NVIC_EnableIRQ(PIN_TO_PORT(p)); \ diff --git a/arch/cpu/cc2538/dev/spi-arch.c b/arch/cpu/cc2538/dev/spi-arch.c index c876e4ed7..aae0ed797 100644 --- a/arch/cpu/cc2538/dev/spi-arch.c +++ b/arch/cpu/cc2538/dev/spi-arch.c @@ -107,7 +107,7 @@ static const spi_regs_t spi_regs[SSI_INSTANCE_COUNT] = { typedef struct spi_locks_s { mutex_t lock; - spi_device_t *owner; + const spi_device_t *owner; } spi_locks_t; /* One lock per SPI controller */ @@ -115,40 +115,40 @@ spi_locks_t board_spi_locks_spi[SPI_CONTROLLER_COUNT] = { { MUTEX_STATUS_UNLOCKE /*---------------------------------------------------------------------------*/ static void -spix_wait_tx_ready(spi_device_t *dev) +spix_wait_tx_ready(const spi_device_t *dev) { /* Infinite loop until SR_TNF - Transmit FIFO Not Full */ while(!(REG(spi_regs[dev->spi_controller].base + SSI_SR) & SSI_SR_TNF)); } /*---------------------------------------------------------------------------*/ static int -spix_read_buf(spi_device_t *dev) +spix_read_buf(const spi_device_t *dev) { return REG(spi_regs[dev->spi_controller].base + SSI_DR); } /*---------------------------------------------------------------------------*/ static void -spix_write_buf(spi_device_t *dev, int data) +spix_write_buf(const spi_device_t *dev, int data) { REG(spi_regs[dev->spi_controller].base + SSI_DR) = data; } /*---------------------------------------------------------------------------*/ static void -spix_wait_eotx(spi_device_t *dev) +spix_wait_eotx(const spi_device_t *dev) { /* wait until not busy */ while(REG(spi_regs[dev->spi_controller].base + SSI_SR) & SSI_SR_BSY); } /*---------------------------------------------------------------------------*/ static void -spix_wait_eorx(spi_device_t *dev) +spix_wait_eorx(const spi_device_t *dev) { /* wait as long as receive is empty */ while(!(REG(spi_regs[dev->spi_controller].base + SSI_SR) & SSI_SR_RNE)); } /*---------------------------------------------------------------------------*/ bool -spi_arch_has_lock(spi_device_t *dev) +spi_arch_has_lock(const spi_device_t *dev) { if(board_spi_locks_spi[dev->spi_controller].owner == dev) { return true; @@ -158,7 +158,7 @@ spi_arch_has_lock(spi_device_t *dev) } /*---------------------------------------------------------------------------*/ bool -spi_arch_is_bus_locked(spi_device_t *dev) +spi_arch_is_bus_locked(const spi_device_t *dev) { if(board_spi_locks_spi[dev->spi_controller].lock == MUTEX_STATUS_LOCKED) { return true; @@ -168,7 +168,7 @@ spi_arch_is_bus_locked(spi_device_t *dev) } /*---------------------------------------------------------------------------*/ spi_status_t -spi_arch_lock_and_open(spi_device_t *dev) +spi_arch_lock_and_open(const spi_device_t *dev) { const spi_regs_t *regs; uint32_t scr; @@ -265,7 +265,7 @@ spi_arch_lock_and_open(spi_device_t *dev) } /*---------------------------------------------------------------------------*/ spi_status_t -spi_arch_close_and_unlock(spi_device_t *dev) +spi_arch_close_and_unlock(const spi_device_t *dev) { if(!spi_arch_has_lock(dev)) { return SPI_DEV_STATUS_BUS_NOT_OWNED; @@ -281,30 +281,9 @@ spi_arch_close_and_unlock(spi_device_t *dev) return SPI_DEV_STATUS_OK; } /*---------------------------------------------------------------------------*/ -spi_status_t -spi_arch_select(spi_device_t *dev) -{ - - if(!spi_arch_has_lock(dev)) { - return SPI_DEV_STATUS_BUS_NOT_OWNED; - } - - SPIX_CS_CLR(PIN_TO_PORT(dev->pin_spi_cs), PIN_TO_NUM(dev->pin_spi_cs)); - - return SPI_DEV_STATUS_OK; -} -/*---------------------------------------------------------------------------*/ -spi_status_t -spi_arch_deselect(spi_device_t *dev) -{ - SPIX_CS_SET(PIN_TO_PORT(dev->pin_spi_cs), PIN_TO_NUM(dev->pin_spi_cs)); - - return SPI_DEV_STATUS_OK; -} -/*---------------------------------------------------------------------------*/ /* Assumes that checking dev and bus is not NULL before calling this */ spi_status_t -spi_arch_transfer(spi_device_t *dev, +spi_arch_transfer(const spi_device_t *dev, const uint8_t *write_buf, int wlen, uint8_t *inbuf, int rlen, int ignore_len) { diff --git a/arch/cpu/cc2538/ieee-addr.c b/arch/cpu/cc2538/ieee-addr.c index c914b511d..6a676f4eb 100644 --- a/arch/cpu/cc2538/ieee-addr.c +++ b/arch/cpu/cc2538/ieee-addr.c @@ -70,11 +70,8 @@ ieee_addr_cpy_to(uint8_t *dst, uint8_t len) if(((uint8_t *)IEEE_ADDR_LOCATION)[3] == oui_ti[0] && ((uint8_t *)IEEE_ADDR_LOCATION)[2] == oui_ti[1] && ((uint8_t *)IEEE_ADDR_LOCATION)[1] == oui_ti[2]) { - for(i = 0; i < len / 2; i++) { - dst[i] = ((uint8_t *)IEEE_ADDR_LOCATION)[len / 2 - 1 - i]; - } - for(i = 0; i < len / 2; i++) { - dst[i + len / 2] = ((uint8_t *)IEEE_ADDR_LOCATION)[len - 1 - i]; + for(i = 0; i < len; i++) { + dst[len - i - 1] = ((uint8_t *)IEEE_ADDR_LOCATION)[i < 4 ? i + 4 : i - 4]; } } else { for(i = 0; i < len; i++) { diff --git a/arch/cpu/cc26xx-cc13xx/Makefile.cc13xx b/arch/cpu/cc26xx-cc13xx/Makefile.cc13xx index 093aa1f02..5ea92e30c 100644 --- a/arch/cpu/cc26xx-cc13xx/Makefile.cc13xx +++ b/arch/cpu/cc26xx-cc13xx/Makefile.cc13xx @@ -1,7 +1,7 @@ TI_XXWARE_PATH = lib/cc13xxware -CONTIKI_CPU_SOURCEFILES += smartrf-settings.c prop-mode.c prop-mode-tx-power.c +CONTIKI_CPU_SOURCEFILES += smartrf-settings.c prop-mode.c prop-mode-tx-power.c cc13xx-50kbps-tsch.c -CFLAGS += -DCPU_FAMILY_CC13XX=1 +CFLAGS += -DCPU_FAMILY_CC13X0=1 -DCPU_FAMILY_CC13XX=1 include $(CONTIKI_CPU)/Makefile.cc26xx-cc13xx diff --git a/arch/cpu/cc26xx-cc13xx/Makefile.cc26x0r2f b/arch/cpu/cc26xx-cc13xx/Makefile.cc26x0r2f new file mode 100644 index 000000000..56d041516 --- /dev/null +++ b/arch/cpu/cc26xx-cc13xx/Makefile.cc26x0r2f @@ -0,0 +1,5 @@ +TI_XXWARE_PATH = lib/cc2640r2-sdk + +CFLAGS += -DCPU_FAMILY_CC26X0R2=1 -DCPU_FAMILY_CC26XXR2=1 + +include $(CONTIKI_CPU)/Makefile.cc26xx-cc13xx diff --git a/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx b/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx index 4bc2cdcad..34a147f7b 100644 --- a/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx +++ b/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx @@ -1,3 +1,5 @@ TI_XXWARE_PATH = lib/cc26xxware +CFLAGS += -DCPU_FAMILY_CC26X0=1 -DCPU_FAMILY_CC26XX=1 + include $(CONTIKI_CPU)/Makefile.cc26xx-cc13xx diff --git a/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx b/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx index e72954c17..94f4e5111 100644 --- a/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx +++ b/arch/cpu/cc26xx-cc13xx/Makefile.cc26xx-cc13xx @@ -1,7 +1,14 @@ CPU_ABS_PATH = arch/cpu/cc26xx-cc13xx TI_XXWARE = $(CONTIKI_CPU)/$(TI_XXWARE_PATH) -### cc26xxware sources under driverlib will be added to the MODULES list +ifeq (,$(wildcard $(TI_XXWARE)/*)) + $(warning $(TI_XXWARE) does not exist or is empty.) + $(warning Did you run 'git submodule update --init' ?) + $(error "") +endif + +### cc26xxware / cc26x0r2fware sources under driverlib will be added to the +### MODULES list TI_XXWARE_SRC = $(CPU_ABS_PATH)/$(TI_XXWARE_PATH)/driverlib ### The directory with startup sources will be added to the CONTIKI_CPU_DIRS @@ -38,8 +45,6 @@ CONTIKI_CPU_SOURCEFILES += ble-cc2650.c ble-hal-cc26xx.c ble-addr.c rf-ble-cmd.c CONTIKI_CPU_SOURCEFILES += random.c soc-trng.c int-master.c CONTIKI_CPU_SOURCEFILES += spi-arch.c -MODULES += os/lib/dbg-io - CONTIKI_SOURCEFILES += $(CONTIKI_CPU_SOURCEFILES) CPU_START_SOURCEFILES += fault-handlers.c $(TI_XXWARE_STARTUP_SRCS) @@ -76,8 +81,10 @@ STACK_SIZE = 0 @$(SIZE) -A $< | egrep "data|bss" | awk '{s+=$$2} END {s=s+$(STACK_SIZE); f=$(RAM_SIZE)-s; printf "[RAM] used %6d, free %6d\n",s,f;}' @$(SIZE) -A $< | egrep "text|isr_vector" | awk '{s+=$$2} END {f=$(FLASH_SIZE)-s; printf "[Flash] used %6d, free %6d\n",s,f;}' +include $(CONTIKI)/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 + ifeq ($(BOARD_SUPPORTS_BSL),1) -%.upload: %.bin +%.upload: $(OUT_BIN) ifeq ($(wildcard $(BSL)), ) @echo "ERROR: Could not find the cc2538-bsl script. Did you run 'git submodule update --init' ?" else @@ -88,21 +95,5 @@ else @echo "This board cannot be programmed through the ROM bootloader and therefore does not support the .upload target." endif -# Check if we are running under Windows -ifeq ($(HOST_OS),Windows) - SERIALDUMP ?= $(CONTIKI)/tools/sky/serialdump-windows -else -ifeq ($(HOST_OS),Darwin) - SERIALDUMP ?= $(CONTIKI)/tools/sky/serialdump-macos -else - # Else assume Linux - SERIALDUMP ?= $(CONTIKI)/tools/sky/serialdump-linux -endif -endif - -UART_BAUDRATE = 115200 - -login: - $(SERIALDUMP) -b$(UART_BAUDRATE) $(PORT) - -include $(CONTIKI)/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 +### For the login etc targets +BAUDRATE = 115200 diff --git a/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-conf.h b/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-conf.h index 83519f795..7400c5ad9 100644 --- a/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-conf.h +++ b/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-conf.h @@ -54,14 +54,6 @@ #define CC2650_FAST_RADIO_STARTUP (MAC_CONF_WITH_TSCH) #endif -#ifdef RF_CHANNEL -#define RF_CORE_CONF_CHANNEL RF_CHANNEL -#endif - -#ifndef RF_CORE_CONF_CHANNEL -#define RF_CORE_CONF_CHANNEL 25 -#endif - /* Number of Prop Mode RX buffers */ #ifndef PROP_MODE_CONF_RX_BUF_CNT #define PROP_MODE_CONF_RX_BUF_CNT 4 @@ -72,22 +64,33 @@ * project has specified otherwise. Depending on the final mode, determine a * default channel (again, if unspecified) and configure RDC params */ -#if CPU_FAMILY_CC13XX +#if CPU_FAMILY_CC13X0 #ifndef CC13XX_CONF_PROP_MODE #define CC13XX_CONF_PROP_MODE 1 #endif /* CC13XX_CONF_PROP_MODE */ -#endif /* CPU_FAMILY_CC13XX */ +#endif /* CPU_FAMILY_CC13X0 */ #if CC13XX_CONF_PROP_MODE +#ifndef NETSTACK_CONF_RADIO #define NETSTACK_CONF_RADIO prop_mode_driver +#endif /* NETSTACK_CONF_RADIO */ -#ifndef RF_CORE_CONF_CHANNEL -#define RF_CORE_CONF_CHANNEL 0 -#endif +/* Channels count from 0 upwards in IEEE 802.15.4g */ +#ifndef IEEE802154_CONF_DEFAULT_CHANNEL +#define IEEE802154_CONF_DEFAULT_CHANNEL 0 +#endif /* IEEE802154_CONF_DEFAULT_CHANNEL */ +#ifndef CSMA_CONF_ACK_WAIT_TIME #define CSMA_CONF_ACK_WAIT_TIME (RTIMER_SECOND / 400) +#endif /* CSMA_CONF_ACK_WAIT_TIME */ + +#ifndef CSMA_CONF_AFTER_ACK_DETECTED_WAIT_TIME #define CSMA_CONF_AFTER_ACK_DETECTED_WAIT_TIME (RTIMER_SECOND / 1000) +#endif /* CSMA_CONF_AFTER_ACK_DETECTED_WAIT_TIME */ + +#ifndef CSMA_CONF_SEND_SOFT_ACK #define CSMA_CONF_SEND_SOFT_ACK 1 +#endif /* CSMA_CONF_SEND_SOFT_ACK */ #else /* CC13XX_CONF_PROP_MODE */ #ifndef NETSTACK_CONF_RADIO @@ -196,8 +199,14 @@ * the chip to enter bootloader mode. * @{ */ -#ifndef ROM_BOOTLOADER_ENABLE -#define ROM_BOOTLOADER_ENABLE 0 + +/* Backward compatibility */ +#ifdef ROM_BOOTLOADER_ENABLE +#define CCXXWARE_CONF_ROM_BOOTLOADER_ENABLE ROM_BOOTLOADER_ENABLE +#endif + +#ifndef CCXXWARE_CONF_ROM_BOOTLOADER_ENABLE +#define CCXXWARE_CONF_ROM_BOOTLOADER_ENABLE 1 #endif /** @} */ /*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h b/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h index 15db03448..97b188e15 100644 --- a/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h +++ b/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h @@ -36,8 +36,43 @@ /*---------------------------------------------------------------------------*/ /* TSCH related defines */ +/* 2 bytes header, 4 bytes CRC */ +#define CC13XX_RADIO_PHY_OVERHEAD 6 +/* 3 bytes preamble, 3 bytes sync */ +#define CC13XX_RADIO_PHY_HEADER_LEN 6 +/* The default data rate is 50 kbps */ +#define CC13XX_RADIO_BIT_RATE 50000 + +/* 1 len byte, 2 bytes CRC */ +#define CC26XX_RADIO_PHY_OVERHEAD 3 +/* 4 bytes preamble, 1 byte sync */ +#define CC26XX_RADIO_PHY_HEADER_LEN 5 +/* The fixed data rate is 250 kbps */ +#define CC26XX_RADIO_BIT_RATE 250000 + +#if CPU_FAMILY_CC13XX +#define RADIO_PHY_HEADER_LEN CC13XX_RADIO_PHY_HEADER_LEN +#define RADIO_PHY_OVERHEAD CC13XX_RADIO_PHY_OVERHEAD +#define RADIO_BIT_RATE CC13XX_RADIO_BIT_RATE + +/* The TSCH default slot length of 10ms is too short, use custom one instead */ +#ifndef TSCH_CONF_DEFAULT_TIMESLOT_TIMING +#define TSCH_CONF_DEFAULT_TIMESLOT_TIMING tsch_timing_cc13xx_50kbps +#endif /* TSCH_CONF_DEFAULT_TIMESLOT_TIMING */ + +/* Symbol for the custom TSCH timeslot timing template */ +#define TSCH_CONF_ARCH_HDR_PATH "rf-core/cc13xx-50kbps-tsch.h" + +#else +#define RADIO_PHY_HEADER_LEN CC26XX_RADIO_PHY_HEADER_LEN +#define RADIO_PHY_OVERHEAD CC26XX_RADIO_PHY_OVERHEAD +#define RADIO_BIT_RATE CC26XX_RADIO_BIT_RATE +#endif + +#define RADIO_BYTE_AIR_TIME (1000000 / (RADIO_BIT_RATE / 8)) + /* Delay between GO signal and SFD */ -#define RADIO_DELAY_BEFORE_TX ((unsigned)US_TO_RTIMERTICKS(81)) +#define RADIO_DELAY_BEFORE_TX ((unsigned)US_TO_RTIMERTICKS(RADIO_PHY_HEADER_LEN * RADIO_BYTE_AIR_TIME)) /* Delay between GO signal and start listening. * This value is so small because the radio is constantly on within each timeslot. */ #define RADIO_DELAY_BEFORE_RX ((unsigned)US_TO_RTIMERTICKS(15)) @@ -52,9 +87,6 @@ #define RADIO_TO_RTIMER(X) ((uint32_t)(((uint64_t)(X) * (RTIMER_SECOND / 256)) / (RADIO_TIMER_SECOND / 256))) #define USEC_TO_RADIO(X) ((X) * 4) -/* The PHY header (preamble + SFD, 4+1 bytes) duration is equivalent to 10 symbols */ -#define RADIO_IEEE_802154_PHY_HEADER_DURATION_USEC 160 - /* Do not turn off TSCH within a timeslot: not enough time */ #define TSCH_CONF_RADIO_ON_DURING_TIMESLOT 1 @@ -85,6 +117,11 @@ #define TSCH_CONF_CHANNEL_SCAN_DURATION (CLOCK_SECOND / 10) #endif +/* Increase this from the default 100 to improve TSCH association speed on this platform */ +#ifndef TSCH_CONF_ASSOCIATION_POLL_FREQUENCY +#define TSCH_CONF_ASSOCIATION_POLL_FREQUENCY 1000 +#endif + /* Slightly reduce the TSCH guard time (from 2200 usec to 1800 usec) to make sure * the CC26xx radio has sufficient time to start up. */ #ifndef TSCH_CONF_RX_WAIT diff --git a/arch/cpu/cc26xx-cc13xx/cc26xx.ld b/arch/cpu/cc26xx-cc13xx/cc26xx.ld index 46ecf1322..4ea422558 100644 --- a/arch/cpu/cc26xx-cc13xx/cc26xx.ld +++ b/arch/cpu/cc26xx-cc13xx/cc26xx.ld @@ -76,6 +76,7 @@ SECTIONS *(.data*) _edata = .; } > SRAM AT > FLASH + _ldata = LOADADDR(.data); .ARM.exidx : { @@ -95,6 +96,8 @@ SECTIONS /* These symbols are used by the stack check library. */ _stack = .; _stack_origin = ORIGIN(SRAM) + LENGTH(SRAM); + _heap = _stack; + _eheap = _stack_origin; .ccfg : { diff --git a/arch/cpu/cc26xx-cc13xx/ccxxware-conf.h b/arch/cpu/cc26xx-cc13xx/ccxxware-conf.h index 97be16b5d..bc26f1171 100644 --- a/arch/cpu/cc26xx-cc13xx/ccxxware-conf.h +++ b/arch/cpu/cc26xx-cc13xx/ccxxware-conf.h @@ -68,6 +68,26 @@ #define SET_CCFG_CCFG_TAP_DAP_1_WUC_TAP_ENABLE 0x00 #endif /** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \brief ROM bootloader configuration + * + * Those values are not meant to be modified by the user + * @{ + */ +#if CCXXWARE_CONF_ROM_BOOTLOADER_ENABLE +#define SET_CCFG_BL_CONFIG_BOOTLOADER_ENABLE 0xC5 +#define SET_CCFG_BL_CONFIG_BL_LEVEL CCXXWARE_CONF_BL_LEVEL +#define SET_CCFG_BL_CONFIG_BL_PIN_NUMBER CCXXWARE_CONF_BL_PIN_NUMBER +#define SET_CCFG_BL_CONFIG_BL_ENABLE 0xC5 +#else +#define SET_CCFG_BL_CONFIG_BOOTLOADER_ENABLE 0x00 +#define SET_CCFG_BL_CONFIG_BL_LEVEL 0x01 +#define SET_CCFG_BL_CONFIG_BL_PIN_NUMBER IOID_UNUSED +#define SET_CCFG_BL_CONFIG_BL_ENABLE 0xFF +#endif +/** @} */ +/*---------------------------------------------------------------------------*/ #endif /* CCXXWARE_CONF_H_ */ /*---------------------------------------------------------------------------*/ /** diff --git a/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.c b/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.c index a7b025800..4fd4f7688 100644 --- a/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.c +++ b/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.c @@ -39,7 +39,6 @@ /*---------------------------------------------------------------------------*/ #include "contiki.h" #include "ti-lib.h" -#include "ti-lib-rom.h" #include "dev/gpio-hal.h" #include @@ -53,7 +52,7 @@ gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg) gpio_hal_pin_cfg_t tmp; /* Clear settings that we are about to change, keep everything else */ - config = ti_lib_rom_ioc_port_configure_get(pin); + config = ti_lib_ioc_port_configure_get(pin); config &= ~CONFIG_MASK; tmp = cfg & GPIO_HAL_PIN_CFG_EDGE_BOTH; @@ -83,7 +82,7 @@ gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg) config |= IOC_INT_ENABLE; } - ti_lib_rom_ioc_port_configure_set(pin, IOC_PORT_GPIO, config); + ti_lib_ioc_port_configure_set(pin, IOC_PORT_GPIO, config); } /*---------------------------------------------------------------------------*/ gpio_hal_pin_cfg_t @@ -94,7 +93,7 @@ gpio_hal_arch_pin_cfg_get(gpio_hal_pin_t pin) uint32_t config; cfg = 0; - config = ti_lib_rom_ioc_port_configure_get(pin); + config = ti_lib_ioc_port_configure_get(pin); /* Pull */ tmp = config & IOC_IOPULL_M; diff --git a/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.h b/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.h index 7d87670c5..3997c1062 100644 --- a/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.h +++ b/arch/cpu/cc26xx-cc13xx/dev/gpio-hal-arch.h @@ -49,15 +49,16 @@ /*---------------------------------------------------------------------------*/ #include "contiki.h" #include "ti-lib.h" -#include "ti-lib-rom.h" #include /*---------------------------------------------------------------------------*/ -#define gpio_hal_arch_interrupt_enable(p) interrupt_enable(p) -#define gpio_hal_arch_interrupt_disable(p) ti_lib_rom_ioc_int_disable(p) +#define gpio_hal_arch_init() do { /* Do nothing */ } while(0) -#define gpio_hal_arch_pin_set_input(p) ti_lib_rom_ioc_pin_type_gpio_input(p) -#define gpio_hal_arch_pin_set_output(p) ti_lib_rom_ioc_pin_type_gpio_output(p) +#define gpio_hal_arch_interrupt_enable(p) interrupt_enable(p) + +#define gpio_hal_arch_interrupt_disable(p) ti_lib_ioc_int_disable(p) +#define gpio_hal_arch_pin_set_input(p) ti_lib_ioc_pin_type_gpio_input(p) +#define gpio_hal_arch_pin_set_output(p) ti_lib_ioc_pin_type_gpio_output(p) #define gpio_hal_arch_set_pin(p) ti_lib_gpio_set_dio(p) #define gpio_hal_arch_clear_pin(p) ti_lib_gpio_clear_dio(p) @@ -73,7 +74,7 @@ static inline void interrupt_enable(gpio_hal_pin_t pin) { ti_lib_gpio_clear_event_dio(pin); - ti_lib_rom_ioc_int_enable(pin); + ti_lib_ioc_int_enable(pin); } /*---------------------------------------------------------------------------*/ #endif /* GPIO_HAL_ARCH_H_ */ diff --git a/arch/cpu/cc26xx-cc13xx/dev/gpio-interrupt.c b/arch/cpu/cc26xx-cc13xx/dev/gpio-interrupt.c index c90e9239d..375e23a4a 100644 --- a/arch/cpu/cc26xx-cc13xx/dev/gpio-interrupt.c +++ b/arch/cpu/cc26xx-cc13xx/dev/gpio-interrupt.c @@ -52,10 +52,10 @@ gpio_interrupt_isr(void) /* Read interrupt flags */ pin_mask = (HWREG(GPIO_BASE + GPIO_O_EVFLAGS31_0) & GPIO_DIO_ALL_MASK); - gpio_hal_event_handler(pin_mask); - /* Clear the interrupt flags */ HWREG(GPIO_BASE + GPIO_O_EVFLAGS31_0) = pin_mask; + + gpio_hal_event_handler(pin_mask); } /*---------------------------------------------------------------------------*/ /** @} */ diff --git a/arch/cpu/cc26xx-cc13xx/dev/soc-rtc.c b/arch/cpu/cc26xx-cc13xx/dev/soc-rtc.c index 8de930a9c..2309026b6 100644 --- a/arch/cpu/cc26xx-cc13xx/dev/soc-rtc.c +++ b/arch/cpu/cc26xx-cc13xx/dev/soc-rtc.c @@ -99,7 +99,7 @@ soc_rtc_init(void) ti_lib_aon_rtc_channel_enable(AON_RTC_CH1); ti_lib_aon_rtc_enable(); - ti_lib_rom_int_enable(INT_AON_RTC_COMB); + ti_lib_int_enable(INT_AON_RTC_COMB); /* Re-enable interrupts */ if(!interrupts_disabled) { diff --git a/arch/cpu/cc26xx-cc13xx/dev/soc-trng.c b/arch/cpu/cc26xx-cc13xx/dev/soc-trng.c index 2fea8418d..30a558640 100644 --- a/arch/cpu/cc26xx-cc13xx/dev/soc-trng.c +++ b/arch/cpu/cc26xx-cc13xx/dev/soc-trng.c @@ -71,7 +71,7 @@ static void disable_number_ready_interrupt(void) { ti_lib_trng_int_disable(TRNG_NUMBER_READY); - ti_lib_rom_int_disable(INT_TRNG_IRQ); + ti_lib_int_disable(INT_TRNG_IRQ); } /*---------------------------------------------------------------------------*/ static void @@ -79,14 +79,14 @@ enable_number_ready_interrupt(void) { ti_lib_trng_int_clear(TRNG_NUMBER_READY); ti_lib_trng_int_enable(TRNG_NUMBER_READY); - ti_lib_rom_int_enable(INT_TRNG_IRQ); + ti_lib_int_enable(INT_TRNG_IRQ); } /*---------------------------------------------------------------------------*/ static bool accessible(void) { /* First, check the PD */ - if(ti_lib_rom_prcm_power_domain_status(PRCM_DOMAIN_PERIPH) + if(ti_lib_prcm_power_domain_status(PRCM_DOMAIN_PERIPH) != PRCM_DOMAIN_POWER_ON) { return false; } @@ -104,12 +104,12 @@ static void power_up(void) { /* First, make sure the PERIPH PD is on */ - ti_lib_rom_prcm_power_domain_on(PRCM_DOMAIN_PERIPH); - while((ti_lib_rom_prcm_power_domain_status(PRCM_DOMAIN_PERIPH) + ti_lib_prcm_power_domain_on(PRCM_DOMAIN_PERIPH); + while((ti_lib_prcm_power_domain_status(PRCM_DOMAIN_PERIPH) != PRCM_DOMAIN_POWER_ON)); /* Enable clock in active mode */ - ti_lib_rom_prcm_peripheral_run_enable(PRCM_PERIPH_TRNG); + ti_lib_prcm_peripheral_run_enable(PRCM_PERIPH_TRNG); ti_lib_prcm_load_set(); while(!ti_lib_prcm_load_get()); } @@ -136,7 +136,7 @@ static uint64_t read_number(void) { uint64_t ran = (uint64_t)HWREG(TRNG_BASE + TRNG_O_OUT1) << 32; - ran += ti_lib_rom_trng_number_get(TRNG_LOW_WORD); + ran += ti_lib_trng_number_get(TRNG_LOW_WORD); return ran; } @@ -237,7 +237,7 @@ soc_trng_rand_asynchronous(uint32_t samples, soc_trng_callback_t cb) ti_lib_trng_int_clear(TRNG_NUMBER_READY); /* Enable clock in sleep mode and register with LPM */ - ti_lib_rom_prcm_peripheral_sleep_enable(PRCM_PERIPH_TRNG); + ti_lib_prcm_peripheral_sleep_enable(PRCM_PERIPH_TRNG); ti_lib_prcm_load_set(); while(!ti_lib_prcm_load_get()); @@ -271,7 +271,7 @@ PROCESS_THREAD(soc_trng_process, ev, data) } /* Disable clock in sleep mode */ - ti_lib_rom_prcm_peripheral_sleep_disable(PRCM_PERIPH_TRNG); + ti_lib_prcm_peripheral_sleep_disable(PRCM_PERIPH_TRNG); ti_lib_prcm_load_set(); while(!ti_lib_prcm_load_get()); diff --git a/arch/cpu/cc26xx-cc13xx/dev/spi-arch.c b/arch/cpu/cc26xx-cc13xx/dev/spi-arch.c index d274a1d52..242cfa503 100644 --- a/arch/cpu/cc26xx-cc13xx/dev/spi-arch.c +++ b/arch/cpu/cc26xx-cc13xx/dev/spi-arch.c @@ -37,7 +37,7 @@ typedef struct spi_locks_s { mutex_t lock; - spi_device_t *owner; + const spi_device_t *owner; } spi_locks_t; /* One lock per SPI controller */ @@ -68,7 +68,7 @@ static const board_spi_controller_t spi_controller[SPI_CONTROLLER_COUNT] = { }; /*---------------------------------------------------------------------------*/ bool -spi_arch_has_lock(spi_device_t *dev) +spi_arch_has_lock(const spi_device_t *dev) { if(board_spi_locks_spi[dev->spi_controller].owner == dev) { return true; @@ -78,7 +78,7 @@ spi_arch_has_lock(spi_device_t *dev) } /*---------------------------------------------------------------------------*/ bool -spi_arch_is_bus_locked(spi_device_t *dev) +spi_arch_is_bus_locked(const spi_device_t *dev) { if(board_spi_locks_spi[dev->spi_controller].lock == MUTEX_STATUS_LOCKED) { return true; @@ -88,7 +88,7 @@ spi_arch_is_bus_locked(spi_device_t *dev) } /*---------------------------------------------------------------------------*/ static uint32_t -get_mode(spi_device_t *dev) +get_mode(const spi_device_t *dev) { /* Select the correct SPI mode */ if(dev->spi_pha == 0 && dev->spi_pol == 0) { @@ -103,7 +103,7 @@ get_mode(spi_device_t *dev) } /*---------------------------------------------------------------------------*/ spi_status_t -spi_arch_lock_and_open(spi_device_t *dev) +spi_arch_lock_and_open(const spi_device_t *dev) { uint32_t c; @@ -123,17 +123,22 @@ spi_arch_lock_and_open(spi_device_t *dev) != PRCM_DOMAIN_POWER_ON)) ; /* Enable clock in active mode */ - ti_lib_rom_prcm_peripheral_run_enable(spi_controller[dev->spi_controller].prcm_periph); + ti_lib_prcm_peripheral_run_enable(spi_controller[dev->spi_controller].prcm_periph); ti_lib_prcm_load_set(); while(!ti_lib_prcm_load_get()) ; /* SPI configuration */ ti_lib_ssi_int_disable(spi_controller[dev->spi_controller].ssi_base, SSI_RXOR | SSI_RXFF | SSI_RXTO | SSI_TXFF); ti_lib_ssi_int_clear(spi_controller[dev->spi_controller].ssi_base, SSI_RXOR | SSI_RXTO); - ti_lib_rom_ssi_config_set_exp_clk(spi_controller[dev->spi_controller].ssi_base, ti_lib_sys_ctrl_clock_get(), - get_mode(dev), SSI_MODE_MASTER, dev->spi_bit_rate, 8); - ti_lib_rom_ioc_pin_type_ssi_master(spi_controller[dev->spi_controller].ssi_base, dev->pin_spi_miso, - dev->pin_spi_mosi, IOID_UNUSED, dev->pin_spi_sck); + + ti_lib_ssi_config_set_exp_clk(spi_controller[dev->spi_controller].ssi_base, + ti_lib_sys_ctrl_clock_get(), + get_mode(dev), SSI_MODE_MASTER, + dev->spi_bit_rate, 8); + ti_lib_ioc_pin_type_ssi_master(spi_controller[dev->spi_controller].ssi_base, + dev->pin_spi_miso, + dev->pin_spi_mosi, IOID_UNUSED, + dev->pin_spi_sck); ti_lib_ssi_enable(spi_controller[dev->spi_controller].ssi_base); @@ -144,14 +149,14 @@ spi_arch_lock_and_open(spi_device_t *dev) } /*---------------------------------------------------------------------------*/ spi_status_t -spi_arch_close_and_unlock(spi_device_t *dev) +spi_arch_close_and_unlock(const spi_device_t *dev) { if(!spi_arch_has_lock(dev)) { return SPI_DEV_STATUS_BUS_NOT_OWNED; } /* Power down SSI */ - ti_lib_rom_prcm_peripheral_run_disable(spi_controller[dev->spi_controller].prcm_periph); + ti_lib_prcm_peripheral_run_disable(spi_controller[dev->spi_controller].prcm_periph); ti_lib_prcm_load_set(); while(!ti_lib_prcm_load_get()) ; @@ -173,7 +178,7 @@ spi_arch_close_and_unlock(spi_device_t *dev) } /*---------------------------------------------------------------------------*/ spi_status_t -spi_arch_transfer(spi_device_t *dev, +spi_arch_transfer(const spi_device_t *dev, const uint8_t *write_buf, int wlen, uint8_t *inbuf, int rlen, int ignore_len) { @@ -205,33 +210,12 @@ spi_arch_transfer(spi_device_t *dev, for(i = 0; i < totlen; i++) { c = i < wlen ? write_buf[i] : 0; ti_lib_ssi_data_put(spi_controller[dev->spi_controller].ssi_base, (uint8_t)c); - ti_lib_rom_ssi_data_get(spi_controller[dev->spi_controller].ssi_base, &c); + ti_lib_ssi_data_get(spi_controller[dev->spi_controller].ssi_base, &c); if(i < rlen) { inbuf[i] = (uint8_t)c; } } - - while(ti_lib_rom_ssi_data_get_non_blocking(spi_controller[dev->spi_controller].ssi_base, &c)) ; - + while(ti_lib_ssi_data_get_non_blocking(spi_controller[dev->spi_controller].ssi_base, &c)) ; return SPI_DEV_STATUS_OK; } /*---------------------------------------------------------------------------*/ -spi_status_t -spi_arch_select(spi_device_t *dev) -{ - - if(!spi_arch_has_lock(dev)) { - return SPI_DEV_STATUS_BUS_NOT_OWNED; - } - - ti_lib_gpio_clear_dio(dev->pin_spi_cs); - - return SPI_DEV_STATUS_OK; -} -spi_status_t -spi_arch_deselect(spi_device_t *dev) -{ - ti_lib_gpio_set_dio(dev->pin_spi_cs); - - return SPI_DEV_STATUS_OK; -} diff --git a/arch/cpu/cc26xx-cc13xx/lib/cc2640r2-sdk b/arch/cpu/cc26xx-cc13xx/lib/cc2640r2-sdk new file mode 160000 index 000000000..0c01cfd36 --- /dev/null +++ b/arch/cpu/cc26xx-cc13xx/lib/cc2640r2-sdk @@ -0,0 +1 @@ +Subproject commit 0c01cfd363fd421d43baaa52af551a4ce8bf9e2b diff --git a/arch/cpu/cc26xx-cc13xx/lpm.c b/arch/cpu/cc26xx-cc13xx/lpm.c index a5e746f24..2337fb24f 100644 --- a/arch/cpu/cc26xx-cc13xx/lpm.c +++ b/arch/cpu/cc26xx-cc13xx/lpm.c @@ -162,7 +162,9 @@ lpm_shutdown(uint32_t wakeup_pin, uint32_t io_pull, uint32_t wake_on) ti_lib_aon_wuc_mcu_power_off_config(MCU_VIRT_PWOFF_DISABLE); /* Latch the IOs in the padring and enable I/O pad sleep mode */ - ti_lib_pwr_ctrl_io_freeze_enable(); + ti_lib_aon_ioc_freeze_enable(); + HWREG(AON_SYSCTL_BASE + AON_SYSCTL_O_SLEEPCTL) = 0; + ti_lib_sys_ctrl_aon_sync(); /* Turn off VIMS cache, CRAM and TRAM - possibly not required */ ti_lib_prcm_cache_retention_disable(); diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/ble-hal/ble-hal-cc26xx.c b/arch/cpu/cc26xx-cc13xx/rf-core/ble-hal/ble-hal-cc26xx.c index d4c761dcd..3245b9c4f 100644 --- a/arch/cpu/cc26xx-cc13xx/rf-core/ble-hal/ble-hal-cc26xx.c +++ b/arch/cpu/cc26xx-cc13xx/rf-core/ble-hal/ble-hal-cc26xx.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2017, Graz University of Technology + * Copyright (c) 2018, University of Bristol - http://www.bristol.ac.uk/ * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -34,6 +35,7 @@ * * \author * Michael Spoerk + * Jinyan BAI */ /*---------------------------------------------------------------------------*/ @@ -63,6 +65,9 @@ #include #include "rf-core/ble-hal/rf-ble-cmd.h" +#if RADIO_CONF_BLE5 +#include "rf_patches/rf_patch_cpe_bt5.h" +#endif /*---------------------------------------------------------------------------*/ #include "sys/log.h" #define LOG_MODULE "BLE-RADIO" @@ -117,9 +122,15 @@ ticks_to_unit(rtimer_clock_t value, uint32_t unit) return (uint32_t)temp; } /*---------------------------------------------------------------------------*/ +#if RADIO_CONF_BLE5 +#define CMD_BUFFER_SIZE 28 +#define PARAM_BUFFER_SIZE 48 +#define OUTPUT_BUFFER_SIZE 24 +#else #define CMD_BUFFER_SIZE 24 #define PARAM_BUFFER_SIZE 36 #define OUTPUT_BUFFER_SIZE 24 +#endif /*---------------------------------------------------------------------------*/ /* ADVERTISING data structures */ #define ADV_RX_BUFFERS_OVERHEAD 8 @@ -358,12 +369,24 @@ on(void) oscillators_request_hf_xosc(); if(!rf_core_is_accessible()) { /* boot the rf core */ - if(rf_core_boot() != RF_CORE_CMD_OK) { - LOG_ERR("ble_controller_reset() could not boot rf-core\n"); - return BLE_RESULT_ERROR; - } - rf_core_setup_interrupts(0); + /* boot and apply Bluetooth 5 Patch */ + if(rf_core_power_up() != RF_CORE_CMD_OK) { + LOG_ERR("rf_core_boot: rf_core_power_up() failed\n"); + rf_core_power_down(); + return RF_CORE_CMD_ERROR; + } + +#if RADIO_CONF_BLE5 + /* Apply Bluetooth 5 patch, if applicable */ + rf_patch_cpe_bt5(); +#endif + if(rf_core_start_rat() != RF_CORE_CMD_OK) { + LOG_ERR("rf_core_boot: rf_core_start_rat() failed\n"); + rf_core_power_down(); + return RF_CORE_CMD_ERROR; + } + rf_core_setup_interrupts(); oscillators_switch_to_hf_xosc(); if(rf_ble_cmd_setup_ble_mode() != RF_BLE_CMD_OK) { @@ -845,7 +868,11 @@ connection_rx(ble_conn_param_t *param) while(RX_ENTRY_STATUS(param->rx_queue_current) == DATA_ENTRY_FINISHED) { rx_data = RX_ENTRY_DATA_PTR(param->rx_queue_current); +#if RADIO_CONF_BLE5 + len = RX_ENTRY_DATA_LENGTH(param->rx_queue_current) - 7 - 2; /* last 9 bytes are status, timestamp, ... */ +#else len = RX_ENTRY_DATA_LENGTH(param->rx_queue_current) - 6 - 2; /* last 8 bytes are status, timestamp, ... */ +#endif channel = (rx_data[len + 3] & 0x3F); frame_type = rx_data[0] & 0x03; more_data = (rx_data[0] & 0x10) >> 4; diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/ble-hal/rf-ble-cmd.c b/arch/cpu/cc26xx-cc13xx/rf-core/ble-hal/rf-ble-cmd.c index cde42f99b..3d427c9ef 100644 --- a/arch/cpu/cc26xx-cc13xx/rf-core/ble-hal/rf-ble-cmd.c +++ b/arch/cpu/cc26xx-cc13xx/rf-core/ble-hal/rf-ble-cmd.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2017, Graz University of Technology + * Copyright (c) 2018, University of Bristol - http://www.bristol.ac.uk/ * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -36,6 +37,7 @@ * * \author * Michael Spoerk + * Jinyan BAI */ /*---------------------------------------------------------------------------*/ #include "contiki.h" @@ -57,6 +59,62 @@ static uint16_t tx_power = 0x3161; /* 0 dBm */ /*static uint16_t tx_power = 0x0CCB; / * -15 dBm * / */ /*---------------------------------------------------------------------------*/ /* BLE overrides */ +#if RADIO_CONF_BLE5 +uint32_t ble_overrides_common[] = +{ + /* Rx: Set LNA IB trim value based on the selected defaultPhy.mainMode setting. (NOTE: The value 0x8 is a placeholder. The value to use should be set during run-time by radio driver function.) */ + ADI_HALFREG_OVERRIDE(0,4,0xF,0x8), + /* Rx: Set LNA IB offset used for automatic software compensation to 0 */ + (uint32_t)0x00008883, + /* Synth: Use 24 MHz crystal, enable extra PLL filtering */ + (uint32_t)0x02010403, + /* Synth: Set fine top and bottom code to 127 and 0 */ + HW_REG_OVERRIDE(0x4020, 0x7F00), + /* Synth: Configure faster calibration */ + HW32_ARRAY_OVERRIDE(0x4004, 1), + /* Synth: Configure faster calibration */ + (uint32_t)0x1C0C0618, + /* Synth: Configure faster calibration */ + (uint32_t)0xC00401A1, + /* Synth: Configure faster calibration */ + (uint32_t)0x21010101, + /* Synth: Configure faster calibration */ + (uint32_t)0xC0040141, + /* Synth: Configure faster calibration */ + (uint32_t)0x00214AD3, + /* Synth: Decrease synth programming time-out by 90 us (0x0298 RAT ticks = 166 us) */ + (uint32_t)0x02980243, + /* Bluetooth 5: Set correct total clock accuracy for received AuxPtr assuming local sleep clock of 50 ppm */ + (uint32_t)0x0E490823, + /* override_frontend_id.xml */ + (uint32_t)0xFFFFFFFF, +}; + +uint32_t ble_overrides_1Mbps[] = +{ + /* Rx: Set LNA IB trim to normal trim value. (NOTE: The value 0x8 is a placeholder. The value to use should be set during run-time by radio driver function.) */ + ADI_HALFREG_OVERRIDE(0,4,0xF,0x8), + /* Rx: Configure AGC to use gain table for improved performance */ + HW_REG_OVERRIDE(0x6084, 0x05F8), + (uint32_t)0xFFFFFFFF, +}; + +uint32_t ble_overrides_2Mbps[] = +{ + /* Rx: Set LNA IB trim to normal trim value. (NOTE: The value 0x8 is a placeholder. The value to use should be set during run-time by radio driver function.) */ + ADI_HALFREG_OVERRIDE(0,4,0xF,0x8), + (uint32_t)0xFFFFFFFF, +}; + +uint32_t ble_overrides_coded[] = +{ + /* Rx: Set LNA IB trim to 0xF (maximum) */ + ADI_HALFREG_OVERRIDE(0,4,0xF,0xF), + /* Rx: Override AGC target gain to improve performance */ + HW_REG_OVERRIDE(0x6088, 0x0018), + (uint32_t)0xFFFFFFFF, +}; +#else static uint32_t ble_overrides[] = { 0x00364038, /* Synth: Set RTRIM (POTAILRESTRIM) to 6 */ 0x000784A3, /* Synth: Set FREF = 3.43 MHz (24 MHz / 7) */ @@ -67,6 +125,7 @@ static uint32_t ble_overrides[] = { 0x008F88B3, /* GPIO mode: https://e2e.ti.com/support/wireless_connectivity/proprietary_sub_1_ghz_simpliciti/f/156/t/488244?*/ 0xFFFFFFFF, /* End of override list */ }; +#endif /*---------------------------------------------------------------------------*/ unsigned short rf_ble_cmd_send(uint8_t *command) @@ -97,14 +156,29 @@ rf_ble_cmd_wait(uint8_t *command) unsigned short rf_ble_cmd_setup_ble_mode(void) { +#if RADIO_CONF_BLE5 + rfc_CMD_BLE5_RADIO_SETUP_t cmd; + + /* Create radio setup command */ + rf_core_init_radio_op((rfc_radioOp_t *)&cmd, sizeof(cmd), CMD_BLE5_RADIO_SETUP); + + cmd.startTrigger.bEnaCmd = 0; + cmd.defaultPhy.mainMode = 1; + cmd.defaultPhy.coding = 1; + cmd.pRegOverrideCommon = ble_overrides_common; + cmd.pRegOverride1Mbps = ble_overrides_1Mbps; + cmd.pRegOverride2Mbps = ble_overrides_2Mbps; + cmd.pRegOverrideCoded = ble_overrides_coded; +#else rfc_CMD_RADIO_SETUP_t cmd; /* Create radio setup command */ rf_core_init_radio_op((rfc_radioOp_t *)&cmd, sizeof(cmd), CMD_RADIO_SETUP); - cmd.txPower = tx_power; - cmd.pRegOverride = ble_overrides; cmd.mode = 0; + cmd.pRegOverride = ble_overrides; +#endif + cmd.txPower = tx_power; /* Send Radio setup to RF Core */ if(rf_ble_cmd_send((uint8_t *)&cmd) != RF_BLE_CMD_OK) { @@ -116,14 +190,26 @@ rf_ble_cmd_setup_ble_mode(void) } /*---------------------------------------------------------------------------*/ /* ADVERTISING functions */ +/*---------------------------------------------------------------------------*/ void rf_ble_cmd_create_adv_cmd(uint8_t *command, uint8_t channel, uint8_t *param, uint8_t *output) { +#if RADIO_CONF_BLE5 + rfc_CMD_BLE5_ADV_t *c = (rfc_CMD_BLE5_ADV_t *)command; + + memset(c, 0x00, sizeof(rfc_CMD_BLE5_ADV_t)); + + c->commandNo = CMD_BLE5_ADV; + c->rangeDelay = 0; + + c->txPower = tx_power; +#else rfc_CMD_BLE_ADV_t *c = (rfc_CMD_BLE_ADV_t *)command; memset(c, 0x00, sizeof(rfc_CMD_BLE_ADV_t)); c->commandNo = CMD_BLE_ADV; +#endif c->condition.rule = COND_NEVER; c->whitening.bOverride = 0; c->channel = channel; @@ -162,12 +248,113 @@ rf_ble_cmd_create_adv_params(uint8_t *param, dataQueue_t *rx_queue, p->endTrigger.triggerType = TRIG_NEVER; } /*---------------------------------------------------------------------------*/ +/* INITIATOR functions */ +/*---------------------------------------------------------------------------*/ +void +rf_ble_cmd_create_initiator_cmd(uint8_t *cmd, uint8_t channel, uint8_t *params, + uint8_t *output, uint32_t start_time) +{ +#if RADIO_CONF_BLE5 + rfc_CMD_BLE5_INITIATOR_t *c = (rfc_CMD_BLE5_INITIATOR_t *)cmd; + + memset(c, 0x00, sizeof(rfc_CMD_BLE5_INITIATOR_t)); + + c->commandNo = CMD_BLE5_INITIATOR; + c->condition.rule = COND_NEVER; + c->whitening.bOverride = 0; + c->channel = channel; + c->pParams = (rfc_ble5InitiatorPar_t *)params; + c->startTrigger.triggerType = TRIG_ABSTIME; + c->startTime = start_time; + c->pOutput = (rfc_ble5ScanInitOutput_t *)output; + + c->txPower = tx_power; + c->rangeDelay = 0; +#else + rfc_CMD_BLE_INITIATOR_t *c = (rfc_CMD_BLE_INITIATOR_t *)cmd; + + memset(c, 0x00, sizeof(rfc_CMD_BLE_INITIATOR_t)); + + c->commandNo = CMD_BLE_INITIATOR; + c->condition.rule = COND_NEVER; + c->whitening.bOverride = 0; + c->channel = channel; + c->pParams = (rfc_bleInitiatorPar_t *)params; + c->startTrigger.triggerType = TRIG_ABSTIME; + c->startTime = start_time; + c->pOutput = (rfc_bleInitiatorOutput_t *)output; +#endif +} +/*---------------------------------------------------------------------------*/ +void +rf_ble_cmd_create_initiator_params(uint8_t *param, dataQueue_t *rx_queue, + uint32_t initiator_time, + ble_addr_type_t own_addr_type, uint8_t *own_addr, + ble_addr_type_t peer_addr_type, uint8_t *peer_addr, + uint32_t connect_time, uint8_t *conn_req_data) +{ +#if RADIO_CONF_BLE5 + rfc_ble5InitiatorPar_t *p = (rfc_ble5InitiatorPar_t *)param; + p->backoffPar.bLastSucceeded = 0; + p->backoffPar.bLastFailed = 0; + p->maxWaitTimeForAuxCh = 0; + p->rxStartTime = 0; + p->rxListenTime = 0; +#else + rfc_bleInitiatorPar_t *p = (rfc_bleInitiatorPar_t *)param; +#endif + p->pRxQ = rx_queue; + p->rxConfig.bAutoFlushIgnored = 1; + p->rxConfig.bAutoFlushCrcErr = 0; + p->rxConfig.bAutoFlushEmpty = 1; + p->rxConfig.bIncludeLenByte = 1; + p->rxConfig.bIncludeCrc = 0; + p->rxConfig.bAppendRssi = 1; + p->rxConfig.bAppendStatus = 1; + p->rxConfig.bAppendTimestamp = 1; + + /* p->initConfig.bUseWhiteList = 0; */ + p->initConfig.bUseWhiteList = 1; + p->initConfig.bDynamicWinOffset = 0; + p->initConfig.deviceAddrType = own_addr_type; + p->initConfig.peerAddrType = peer_addr_type; + p->initConfig.bStrictLenFilter = 1; + + p->connectReqLen = 22; + p->pConnectReqData = conn_req_data; + p->pDeviceAddress = (uint16_t *)own_addr; + p->pWhiteList = (rfc_bleWhiteListEntry_t *)peer_addr; + p->connectTime = connect_time; + p->timeoutTrigger.triggerType = TRIG_REL_START; + p->timeoutTime = initiator_time; + p->endTrigger.triggerType = TRIG_NEVER; +} +/*---------------------------------------------------------------------------*/ /* CONNECTION slave functions */ /*---------------------------------------------------------------------------*/ void rf_ble_cmd_create_slave_cmd(uint8_t *cmd, uint8_t channel, uint8_t *params, uint8_t *output, uint32_t start_time) { +#if RADIO_CONF_BLE5 + rfc_CMD_BLE5_SLAVE_t *c = (rfc_CMD_BLE5_SLAVE_t *)cmd; + + memset(c, 0x00, sizeof(rfc_CMD_BLE5_SLAVE_t)); + + c->commandNo = CMD_BLE5_SLAVE; + c->condition.rule = COND_NEVER; + c->whitening.bOverride = 0; + c->channel = channel; + c->pParams = (rfc_ble5SlavePar_t *)params; + c->startTrigger.triggerType = TRIG_ABSTIME; + c->startTime = start_time; + c->pOutput = (rfc_bleMasterSlaveOutput_t *)output; + + c->phyMode.mainMode = 1; + c->phyMode.coding = 1; + c->txPower = tx_power; + c->rangeDelay = 0; +#else rfc_CMD_BLE_SLAVE_t *c = (rfc_CMD_BLE_SLAVE_t *)cmd; memset(c, 0x00, sizeof(rfc_CMD_BLE_SLAVE_t)); @@ -181,6 +368,7 @@ rf_ble_cmd_create_slave_cmd(uint8_t *cmd, uint8_t channel, uint8_t *params, c->startTrigger.pastTrig = 0; c->startTime = start_time; c->pOutput = (rfc_bleMasterSlaveOutput_t *)output; +#endif } /*---------------------------------------------------------------------------*/ void @@ -190,8 +378,13 @@ rf_ble_cmd_create_slave_params(uint8_t *params, dataQueue_t *rx_queue, uint8_t crc_init_2, uint32_t win_size, uint32_t window_widening, uint8_t first_packet) { +#if RADIO_CONF_BLE5 + rfc_ble5SlavePar_t *p = (rfc_ble5SlavePar_t *)params; + p->maxRxPktLen = 255; + p->maxLenLowRate = 0; +#else rfc_bleSlavePar_t *p = (rfc_bleSlavePar_t *)params; - +#endif p->pRxQ = rx_queue; p->pTxQ = tx_queue; p->rxConfig.bAutoFlushIgnored = 1; @@ -230,6 +423,91 @@ rf_ble_cmd_create_slave_params(uint8_t *params, dataQueue_t *rx_queue, p->endTrigger.triggerType = TRIG_NEVER; } /*---------------------------------------------------------------------------*/ +/* CONNECTION master functions */ +/*---------------------------------------------------------------------------*/ +void +rf_ble_cmd_create_master_cmd(uint8_t *cmd, uint8_t channel, uint8_t *params, + uint8_t *output, uint32_t start_time) +{ +#if RADIO_CONF_BLE5 + rfc_CMD_BLE5_MASTER_t *c = (rfc_CMD_BLE5_MASTER_t *)cmd; + + memset(c, 0x00, sizeof(rfc_CMD_BLE5_MASTER_t)); + + c->commandNo = CMD_BLE5_MASTER; + c->condition.rule = COND_NEVER; + c->whitening.bOverride = 0; + c->channel = channel; + c->pParams = (rfc_ble5MasterPar_t *)params; + c->startTrigger.triggerType = TRIG_ABSTIME; + c->startTime = start_time; + c->pOutput = (rfc_bleMasterSlaveOutput_t *)output; + + c->phyMode.mainMode = 1; + c->phyMode.coding = 1; + c->txPower = tx_power; + c->rangeDelay = 0; +#else + rfc_CMD_BLE_MASTER_t *c = (rfc_CMD_BLE_MASTER_t *)cmd; + + memset(c, 0x00, sizeof(rfc_CMD_BLE_MASTER_t)); + + c->commandNo = CMD_BLE_MASTER; + c->condition.rule = COND_NEVER; + c->whitening.bOverride = 0; + c->channel = channel; + c->pParams = (rfc_bleMasterPar_t *)params; + c->startTrigger.triggerType = TRIG_ABSTIME; + c->startTime = start_time; + c->pOutput = (rfc_bleMasterSlaveOutput_t *)output; +#endif +} +/*---------------------------------------------------------------------------*/ +void +rf_ble_cmd_create_master_params(uint8_t *params, dataQueue_t *rx_queue, + dataQueue_t *tx_queue, uint32_t access_address, + uint8_t crc_init_0, uint8_t crc_init_1, + uint8_t crc_init_2, uint8_t first_packet) +{ +#if RADIO_CONF_BLE5 + rfc_ble5MasterPar_t *p = (rfc_ble5MasterPar_t *)params; + p->maxRxPktLen = 255; + p->maxLenLowRate = 0; +#else + rfc_bleMasterPar_t *p = (rfc_bleMasterPar_t *)params; +#endif + p->pRxQ = rx_queue; + p->pTxQ = tx_queue; + p->rxConfig.bAutoFlushIgnored = 1; + p->rxConfig.bAutoFlushCrcErr = 1; + p->rxConfig.bAutoFlushEmpty = 1; + p->rxConfig.bIncludeLenByte = 1; + p->rxConfig.bIncludeCrc = 0; + p->rxConfig.bAppendRssi = 1; + p->rxConfig.bAppendStatus = 1; + p->rxConfig.bAppendTimestamp = 1; + + if(first_packet) { + /* set parameters for first packet according to TI Technical Reference Manual */ + p->seqStat.lastRxSn = 1; + p->seqStat.lastTxSn = 1; + p->seqStat.nextTxSn = 0; + p->seqStat.bFirstPkt = 1; + p->seqStat.bAutoEmpty = 0; + p->seqStat.bLlCtrlTx = 0; + p->seqStat.bLlCtrlAckRx = 0; + p->seqStat.bLlCtrlAckPending = 0; + } + + p->maxPkt = 12; + p->accessAddress = access_address; + p->crcInit0 = crc_init_0; + p->crcInit1 = crc_init_1; + p->crcInit2 = crc_init_2; + p->endTrigger.triggerType = TRIG_REL_START; + p->endTime = (uint32_t)15 * 4000; /* a connection event must end after 10 ms */ +} +/*---------------------------------------------------------------------------*/ /* DATA queue functions */ /*---------------------------------------------------------------------------*/ unsigned short diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/ble-hal/rf-ble-cmd.h b/arch/cpu/cc26xx-cc13xx/rf-core/ble-hal/rf-ble-cmd.h index d8a86f798..798d1b879 100644 --- a/arch/cpu/cc26xx-cc13xx/rf-core/ble-hal/rf-ble-cmd.h +++ b/arch/cpu/cc26xx-cc13xx/rf-core/ble-hal/rf-ble-cmd.h @@ -106,6 +106,45 @@ void rf_ble_cmd_create_adv_params(uint8_t *param, dataQueue_t *rx_queue, uint8_t scan_resp_data_len, uint8_t *scan_resp_data, ble_addr_type_t own_addr_type, uint8_t *own_addr); +/*---------------------------------------------------------------------------*/ +/** + * \brief Creates a BLE radio command structure that sets up + * BLE initiation event when sent to the radio core + * \param cmd A pointer to command that is created + * \param channel The BLE data channel used for the connection event + * \param params A pointer to the radio command parameters + * \param output A pointer to the radio command output + * \param start_time + * The time in rf_core_ticks when the connection event will start + */ +void rf_ble_cmd_create_initiator_cmd(uint8_t *cmd, uint8_t channel, uint8_t *params, + uint8_t *output, uint32_t start_time); + +/*---------------------------------------------------------------------------*/ +/** + * \brief Creates BLE radio command parameters that are used to set up + * BLE initiation event on the radio core + * \param param A pointer to parameter structure that is created + * \param rx_queue A pointer to the RX queue that is used + * \param initiator_window + * T + * \param own_addr_type + * Either BLE_ADDR_TYPE_PUBLIC or BLE_ADDR_TYPE_RANDOM + * \param own_addr A pointer to the device address that is used as own address + * \param peer_addr_type + * Either BLE_ADDR_TYPE_PUBLIC or BLE_ADDR_TYPE_RANDOM + * \param peer_addr A pointer to the device address that is used as peer address + * \param connect_time + The first possible start time of the first connection event + * \param conn_req_data A pointer to the connect request data + */ +void rf_ble_cmd_create_initiator_params(uint8_t *param, dataQueue_t *rx_queue, + uint32_t initiator_window, + ble_addr_type_t own_addr_type, uint8_t *own_addr, + ble_addr_type_t peer_addr_type, uint8_t *peer_addr, + uint32_t connect_time, + uint8_t *conn_req_data); + /*---------------------------------------------------------------------------*/ /** * \brief Creates a BLE radio command structure that sets up a single @@ -148,6 +187,44 @@ void rf_ble_cmd_create_slave_params(uint8_t *param, dataQueue_t *rx_queue, uint8_t crc_init_2, uint32_t win_size, uint32_t window_widening, uint8_t first_packet); +/*---------------------------------------------------------------------------*/ +/** + * \brief Creates a BLE radio command structure that sets up + * BLE connection event when sent to the radio core + * \param cmd A pointer to command that is created + * \param channel The BLE data channel used for the connection event + * \param params A pointer to the radio command parameters + * \param output A pointer to the radio command output + * \param start_time + * The time in rf_core_ticks when the connection event will start + */ +void rf_ble_cmd_create_master_cmd(uint8_t *cmd, uint8_t channel, uint8_t *params, + uint8_t *output, uint32_t start_time); + +/*---------------------------------------------------------------------------*/ +/** + * \brief Creates BLE radio command parameters that are used to set up + * BLE connection event on the radio core + * \param params A pointer to parameter structure that is created + * \param rx_queue A pointer to the RX queue that is used + * \param tx_queue A pointer to the TX queue that is used + * \param access_address + * The access address of the used BLE connection + * \param crc_init_0 + * Part of the initialization of the CRC checksum + * \param crc_init_1 + * Part of the initialization of the CRC checksum + * \param crc_init_2 + * Part of the initialization of the CRC checksum + * \param first_packet + * 1 for the first packet of the BLE connection so that the + * connection is properly initialized + */ +void rf_ble_cmd_create_master_params(uint8_t *params, dataQueue_t *rx_queue, + dataQueue_t *tx_queue, uint32_t access_address, + uint8_t crc_init_0, uint8_t crc_init_1, + uint8_t crc_init_2, uint8_t first_packet); + /*---------------------------------------------------------------------------*/ /** * \brief Adds a data buffer to a BLE transmission queue diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/cc13xx-50kbps-tsch.c b/arch/cpu/cc26xx-cc13xx/rf-core/cc13xx-50kbps-tsch.c new file mode 100644 index 000000000..af76d63e3 --- /dev/null +++ b/arch/cpu/cc26xx-cc13xx/rf-core/cc13xx-50kbps-tsch.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2018, University of Bristol - http://www.bristol.ac.uk/ + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the Contiki operating system. + * + */ + +/** + * \file + * IEEE 802.15.4 TSCH timeslot timings for CC13xx chips at 50kbps datarate + * \author + * Atis Elsts + * + */ + +#include "contiki.h" +#include "net/mac/tsch/tsch.h" + +#define CC13XX_TSCH_DEFAULT_TS_CCA_OFFSET 1800 +#define CC13XX_TSCH_DEFAULT_TS_CCA 128 +#define CC13XX_TSCH_DEFAULT_TS_TX_OFFSET 2500 +#define CC13XX_TSCH_DEFAULT_TS_RX_OFFSET (CC13XX_TSCH_DEFAULT_TS_TX_OFFSET - (TSCH_CONF_RX_WAIT / 2)) +#define CC13XX_TSCH_DEFAULT_TS_RX_ACK_DELAY 2000 +#define CC13XX_TSCH_DEFAULT_TS_TX_ACK_DELAY 3000 +#define CC13XX_TSCH_DEFAULT_TS_RX_WAIT TSCH_CONF_RX_WAIT +#define CC13XX_TSCH_DEFAULT_TS_ACK_WAIT 3000 +#define CC13XX_TSCH_DEFAULT_TS_RX_TX 192 +#define CC13XX_TSCH_DEFAULT_TS_MAX_ACK 10000 +#define CC13XX_TSCH_DEFAULT_TS_MAX_TX 21600 + +/* Timeslot length: 40000 usec */ +#define CC13XX_TSCH_DEFAULT_TS_TIMESLOT_LENGTH 40000 + +/* TSCH timeslot timing (microseconds) */ +const uint16_t tsch_timing_cc13xx_50kbps[tsch_ts_elements_count] = { + CC13XX_TSCH_DEFAULT_TS_CCA_OFFSET, + CC13XX_TSCH_DEFAULT_TS_CCA, + CC13XX_TSCH_DEFAULT_TS_TX_OFFSET, + CC13XX_TSCH_DEFAULT_TS_RX_OFFSET, + CC13XX_TSCH_DEFAULT_TS_RX_ACK_DELAY, + CC13XX_TSCH_DEFAULT_TS_TX_ACK_DELAY, + CC13XX_TSCH_DEFAULT_TS_RX_WAIT, + CC13XX_TSCH_DEFAULT_TS_ACK_WAIT, + CC13XX_TSCH_DEFAULT_TS_RX_TX, + CC13XX_TSCH_DEFAULT_TS_MAX_ACK, + CC13XX_TSCH_DEFAULT_TS_MAX_TX, + CC13XX_TSCH_DEFAULT_TS_TIMESLOT_LENGTH, +}; diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/cc13xx-50kbps-tsch.h b/arch/cpu/cc26xx-cc13xx/rf-core/cc13xx-50kbps-tsch.h new file mode 100644 index 000000000..5d4fdb376 --- /dev/null +++ b/arch/cpu/cc26xx-cc13xx/rf-core/cc13xx-50kbps-tsch.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2018, University of Bristol - http://www.bristol.ac.uk/ + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the Contiki operating system. + * + */ + +#ifndef CC13XX_50KBPS_TSCH_H_ +#define CC13XX_50KBPS_TSCH_H_ + +#include "contiki.h" + +/* TSCH timeslot timing (microseconds) */ +extern const uint16_t tsch_timing_cc13xx_50kbps[]; + +#endif /* CC13XX_50KBPS_TSCH_H_ */ diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/dot-15-4g.h b/arch/cpu/cc26xx-cc13xx/rf-core/dot-15-4g.h index 7282ac9ba..37c5d3e34 100644 --- a/arch/cpu/cc26xx-cc13xx/rf-core/dot-15-4g.h +++ b/arch/cpu/cc26xx-cc13xx/rf-core/dot-15-4g.h @@ -49,20 +49,21 @@ #include "driverlib/rf_mailbox.h" /*---------------------------------------------------------------------------*/ /* IEEE 802.15.4g frequency band identifiers (Table 68f) */ -#define DOT_15_4G_FREQUENCY_BAND_169 0 /* 169.400–169.475 (Europe) - 169 MHz band */ -#define DOT_15_4G_FREQUENCY_BAND_450 1 /* 450–470 (US FCC Part 22/90) - 450 MHz band */ -#define DOT_15_4G_FREQUENCY_BAND_470 2 /* 470–510 (China) - 470 MHz band */ -#define DOT_15_4G_FREQUENCY_BAND_780 3 /* 779–787 (China) - 780 MHz band */ -#define DOT_15_4G_FREQUENCY_BAND_863 4 /* 863–870 (Europe) - 863 MHz band */ -#define DOT_15_4G_FREQUENCY_BAND_896 5 /* 896–901 (US FCC Part 90) - 896 MHz band */ -#define DOT_15_4G_FREQUENCY_BAND_901 6 /* 901–902 (US FCC Part 24) - 901 MHz band */ -#define DOT_15_4G_FREQUENCY_BAND_915 7 /* 902–928 (US) - 915 MHz band */ -#define DOT_15_4G_FREQUENCY_BAND_917 8 /* 917–923.5 (Korea) - 917 MHz band */ -#define DOT_15_4G_FREQUENCY_BAND_920 9 /* 920–928 (Japan) - 920 MHz band */ -#define DOT_15_4G_FREQUENCY_BAND_928 10 /* 928–960 (US, non-contiguous) - 928 MHz band */ -#define DOT_15_4G_FREQUENCY_BAND_950 11 /* 950–958 (Japan) - 950 MHz band */ -#define DOT_15_4G_FREQUENCY_BAND_1427 12 /* 1427–1518 (US and Canada, non-contiguous) - 1427 MHz band */ -#define DOT_15_4G_FREQUENCY_BAND_2450 13 /* 2400–2483.5 2450 MHz band */ +#define DOT_15_4G_FREQUENCY_BAND_169 0 /* 169.400–169.475 (Europe) - 169 MHz band */ +#define DOT_15_4G_FREQUENCY_BAND_450 1 /* 450–470 (US FCC Part 22/90) - 450 MHz band */ +#define DOT_15_4G_FREQUENCY_BAND_470 2 /* 470–510 (China) - 470 MHz band */ +#define DOT_15_4G_FREQUENCY_BAND_780 3 /* 779–787 (China) - 780 MHz band */ +#define DOT_15_4G_FREQUENCY_BAND_863 4 /* 863–870 (Europe) - 863 MHz band */ +#define DOT_15_4G_FREQUENCY_BAND_896 5 /* 896–901 (US FCC Part 90) - 896 MHz band */ +#define DOT_15_4G_FREQUENCY_BAND_901 6 /* 901–902 (US FCC Part 24) - 901 MHz band */ +#define DOT_15_4G_FREQUENCY_BAND_915 7 /* 902–928 (US) - 915 MHz band */ +#define DOT_15_4G_FREQUENCY_BAND_917 8 /* 917–923.5 (Korea) - 917 MHz band */ +#define DOT_15_4G_FREQUENCY_BAND_920 9 /* 920–928 (Japan) - 920 MHz band */ +#define DOT_15_4G_FREQUENCY_BAND_928 10 /* 928–960 (US, non-contiguous) - 928 MHz band */ +#define DOT_15_4G_FREQUENCY_BAND_950 11 /* 950–958 (Japan) - 950 MHz band */ +#define DOT_15_4G_FREQUENCY_BAND_1427 12 /* 1427–1518 (US and Canada, non-contiguous) - 1427 MHz band */ +#define DOT_15_4G_FREQUENCY_BAND_2450 13 /* 2400–2483.5 2450 MHz band */ +#define DOT_15_4G_FREQUENCY_BAND_CUSTOM 14 /* For use with custom frequency band settings */ /*---------------------------------------------------------------------------*/ /* Default band selection to band 4 - 863MHz */ #ifdef DOT_15_4G_CONF_FREQUENCY_BAND_ID @@ -77,6 +78,18 @@ * bands we only support operating mode #1 (Table 134). * * DOT_15_4G_CHAN0_FREQUENCY is specified here in KHz + * + * Custom bands and configuration can be used with DOT_15_4G_FREQUENCY_BAND_CUSTOM. + * + * Example of custom setup for the 868Mhz sub-band in Europe with 11 channels, + * center frequency at 868.050MHz and channel spacing at 100KHz. + * These should be put in project-config.h or similar. + * + * #define DOT_15_4G_FREQUENCY_BAND_ID DOT_15_4G_FREQUENCY_BAND_CUSTOM + * #define DOT_15_4G_CHAN0_FREQUENCY 868050 + * #define DOT_15_4G_CHANNEL_SPACING 100 + * #define DOT_15_4G_CHANNEL_MAX 11 + * #define PROP_MODE_CONF_LO_DIVIDER 0x05 */ #if DOT_15_4G_FREQUENCY_BAND_ID==DOT_15_4G_FREQUENCY_BAND_470 #define DOT_15_4G_CHANNEL_MAX 198 @@ -116,6 +129,22 @@ #define DOT_15_4G_CHAN0_FREQUENCY 951000 #define PROP_MODE_CONF_LO_DIVIDER 0x05 +#elif DOT_15_4G_FREQUENCY_BAND_ID==DOT_15_4G_FREQUENCY_BAND_CUSTOM +#ifndef DOT_15_4G_CHANNEL_MAX +#error DOT_15_4G_CHANNEL_MAX must be manually set when using custom frequency band +#endif + +#ifndef DOT_15_4G_CHANNEL_SPACING +#error DOT_15_4G_CHANNEL_SPACING must be manually set when using custom frequency band +#endif + +#ifndef DOT_15_4G_CHAN0_FREQUENCY +#error DOT_15_4G_CHAN0_FREQUENCY must be manually set when using custom frequency band +#endif + +#ifndef PROP_MODE_CONF_LO_DIVIDER +#error PROP_MODE_CONF_LO_DIVIDER must be manually set when using custom frequency band +#endif #else #error The selected frequency band is not supported #endif diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/ieee-mode.c b/arch/cpu/cc26xx-cc13xx/rf-core/ieee-mode.c index a5479a4ee..9f4021d21 100644 --- a/arch/cpu/cc26xx-cc13xx/rf-core/ieee-mode.c +++ b/arch/cpu/cc26xx-cc13xx/rf-core/ieee-mode.c @@ -120,6 +120,8 @@ static uint8_t rf_stats[16] = { 0 }; /* The size of the RF commands buffer */ #define RF_CMD_BUFFER_SIZE 128 /*---------------------------------------------------------------------------*/ +#define RAT_TIMESTAMP_OFFSET_2_4_GHZ 0 +/*---------------------------------------------------------------------------*/ /** * \brief Returns the current status of a running Radio Op command * \param a A pointer with the buffer used to initiate the command @@ -130,55 +132,9 @@ static uint8_t rf_stats[16] = { 0 }; */ #define RF_RADIO_OP_GET_STATUS(a) (((rfc_radioOp_t *)a)->status) /*---------------------------------------------------------------------------*/ -/* Special value returned by CMD_IEEE_CCA_REQ when an RSSI is not available */ -#define RF_CMD_CCA_REQ_RSSI_UNKNOWN -128 - -/* Used for the return value of channel_clear */ -#define RF_CCA_CLEAR 1 -#define RF_CCA_BUSY 0 - -/* Used as an error return value for get_cca_info */ -#define RF_GET_CCA_INFO_ERROR 0xFF - -/* - * Values of the individual bits of the ccaInfo field in CMD_IEEE_CCA_REQ's - * status struct - */ -#define RF_CMD_CCA_REQ_CCA_STATE_IDLE 0 /* 00 */ -#define RF_CMD_CCA_REQ_CCA_STATE_BUSY 1 /* 01 */ -#define RF_CMD_CCA_REQ_CCA_STATE_INVALID 2 /* 10 */ - -#define RF_CMD_CCA_REQ_CCA_CORR_IDLE (0 << 4) -#define RF_CMD_CCA_REQ_CCA_CORR_BUSY (1 << 4) -#define RF_CMD_CCA_REQ_CCA_CORR_INVALID (3 << 4) -#define RF_CMD_CCA_REQ_CCA_CORR_MASK (3 << 4) - -#define RF_CMD_CCA_REQ_CCA_SYNC_BUSY (1 << 6) -/*---------------------------------------------------------------------------*/ #define IEEE_MODE_CHANNEL_MIN 11 #define IEEE_MODE_CHANNEL_MAX 26 /*---------------------------------------------------------------------------*/ -/* How long to wait for an ongoing ACK TX to finish before starting frame TX */ -#define TX_WAIT_TIMEOUT (RTIMER_SECOND >> 11) - -/* How long to wait for the RF to enter RX in rf_cmd_ieee_rx */ -#define ENTER_RX_WAIT_TIMEOUT (RTIMER_SECOND >> 10) - -/* How long to wait for the RF to react on CMD_ABORT: around 1 msec */ -#define RF_TURN_OFF_WAIT_TIMEOUT (RTIMER_SECOND >> 10) - -/* How long to wait for the RF to finish TX of a packet or an ACK */ -#define TX_FINISH_WAIT_TIMEOUT (RTIMER_SECOND >> 7) - -#define LIMITED_BUSYWAIT(cond, timeout) do { \ - rtimer_clock_t end_time = RTIMER_NOW() + timeout; \ - while(cond) { \ - if(!RTIMER_CLOCK_LT(RTIMER_NOW(), end_time)) { \ - break; \ - } \ - } \ - } while(0) -/*---------------------------------------------------------------------------*/ /* TX Power dBm lookup table - values from SmartRF Studio */ typedef struct output_config { radio_value_t dbm; @@ -211,33 +167,6 @@ static const output_config_t output_power[] = { /* Default TX Power - position in output_power[] */ static const output_config_t *tx_power_current = &output_power[0]; /*---------------------------------------------------------------------------*/ -static volatile int8_t last_rssi = 0; -static volatile uint8_t last_corr_lqi = 0; - -extern int32_t rat_offset; - -/*---------------------------------------------------------------------------*/ -/* SFD timestamp in RTIMER ticks */ -static volatile uint32_t last_packet_timestamp = 0; -/* SFD timestamp in RAT ticks (but 64 bits) */ -static uint64_t last_rat_timestamp64 = 0; - -/* For RAT overflow handling */ -static struct ctimer rat_overflow_timer; -static volatile uint32_t rat_overflow_counter = 0; -static rtimer_clock_t last_rat_overflow = 0; - -/* RAT has 32-bit register, overflows once 18 minutes */ -#define RAT_RANGE 4294967296ull -/* approximate value */ -#define RAT_OVERFLOW_PERIOD_SECONDS (60 * 18) - -/* XXX: don't know what exactly is this, looks like the time to Tx 3 octets */ -#define TIMESTAMP_OFFSET -(USEC_TO_RADIO(32 * 3) - 1) /* -95.75 usec */ -/*---------------------------------------------------------------------------*/ -/* Are we currently in poll mode? */ -static uint8_t poll_mode = 0; - static rfc_CMD_IEEE_MOD_FILT_t filter_cmd; /*---------------------------------------------------------------------------*/ /* @@ -256,27 +185,28 @@ static uint8_t cmd_ieee_rx_buf[RF_CMD_BUFFER_SIZE] CC_ALIGN(4); #define DATA_ENTRY_LENSZ_BYTE 1 #define DATA_ENTRY_LENSZ_WORD 2 /* 2 bytes */ -#define RX_BUF_SIZE 144 -/* Four receive buffers entries with room for 1 IEEE802.15.4 frame in each */ -static uint8_t rx_buf_0[RX_BUF_SIZE] CC_ALIGN(4); -static uint8_t rx_buf_1[RX_BUF_SIZE] CC_ALIGN(4); -static uint8_t rx_buf_2[RX_BUF_SIZE] CC_ALIGN(4); -static uint8_t rx_buf_3[RX_BUF_SIZE] CC_ALIGN(4); - -#define RX_BUF_INCLUDE_CRC 1 -#define RX_BUF_INCLUDE_RSSI 1 -#define RX_BUF_INCLUDE_CORR 1 -#define RX_BUF_INCLUDE_TIMESTAMP 1 - /* The size of the metadata (excluding the packet length field) */ #define RX_BUF_METADATA_SIZE \ - (2 * RX_BUF_INCLUDE_CRC + RX_BUF_INCLUDE_RSSI + RX_BUF_INCLUDE_CORR + 4 * RX_BUF_INCLUDE_TIMESTAMP) + (2 * RF_CORE_RX_BUF_INCLUDE_CRC \ + + RF_CORE_RX_BUF_INCLUDE_RSSI \ + + RF_CORE_RX_BUF_INCLUDE_CORR \ + + 4 * RF_CORE_RX_BUF_INCLUDE_TIMESTAMP) /* The offset of the packet length in a rx buffer */ #define RX_BUF_LENGTH_OFFSET sizeof(rfc_dataEntry_t) /* The offset of the packet data in a rx buffer */ #define RX_BUF_DATA_OFFSET (RX_BUF_LENGTH_OFFSET + 1) +#define RX_BUF_SIZE (RX_BUF_DATA_OFFSET \ + + NETSTACK_RADIO_MAX_PAYLOAD_LEN \ + + RX_BUF_METADATA_SIZE) + +/* Four receive buffers entries with room for 1 IEEE802.15.4 frame in each */ +static uint8_t rx_buf_0[RX_BUF_SIZE] CC_ALIGN(4); +static uint8_t rx_buf_1[RX_BUF_SIZE] CC_ALIGN(4); +static uint8_t rx_buf_2[RX_BUF_SIZE] CC_ALIGN(4); +static uint8_t rx_buf_3[RX_BUF_SIZE] CC_ALIGN(4); + /* The RX Data Queue */ static dataQueue_t rx_data_queue = { 0 }; @@ -358,8 +288,8 @@ transmitting(void) return 0; } - if((cmd.currentRssi == RF_CMD_CCA_REQ_RSSI_UNKNOWN) && - (cmd.ccaInfo.ccaEnergy == RF_CMD_CCA_REQ_CCA_STATE_BUSY)) { + if((cmd.currentRssi == RF_CORE_CMD_CCA_REQ_RSSI_UNKNOWN) && + (cmd.ccaInfo.ccaEnergy == RF_CORE_CMD_CCA_REQ_CCA_STATE_BUSY)) { return 1; } @@ -368,12 +298,12 @@ transmitting(void) /*---------------------------------------------------------------------------*/ /** * \brief Returns CCA information - * \return RF_GET_CCA_INFO_ERROR if the RF was not on + * \return RF_CORE_GET_CCA_INFO_ERROR if the RF was not on * \return On success, the return value is formatted as per the ccaInfo field * of CMD_IEEE_CCA_REQ * * It is the caller's responsibility to make sure the RF is on. This function - * will return RF_GET_CCA_INFO_ERROR if the RF is off + * will return RF_CORE_GET_CCA_INFO_ERROR if the RF is off * * This function will in fact wait for a valid CCA state */ @@ -385,20 +315,20 @@ get_cca_info(void) if(!rf_is_on()) { PRINTF("get_cca_info: Not on\n"); - return RF_GET_CCA_INFO_ERROR; + return RF_CORE_GET_CCA_INFO_ERROR; } memset(&cmd, 0x00, sizeof(cmd)); - cmd.ccaInfo.ccaState = RF_CMD_CCA_REQ_CCA_STATE_INVALID; + cmd.ccaInfo.ccaState = RF_CORE_CMD_CCA_REQ_CCA_STATE_INVALID; - while(cmd.ccaInfo.ccaState == RF_CMD_CCA_REQ_CCA_STATE_INVALID) { + while(cmd.ccaInfo.ccaState == RF_CORE_CMD_CCA_REQ_CCA_STATE_INVALID) { memset(&cmd, 0x00, sizeof(cmd)); cmd.commandNo = CMD_IEEE_CCA_REQ; if(rf_core_send_cmd((uint32_t)&cmd, &cmd_status) == RF_CORE_CMD_ERROR) { PRINTF("get_cca_info: CMDSTA=0x%08lx\n", cmd_status); - return RF_GET_CCA_INFO_ERROR; + return RF_CORE_GET_CCA_INFO_ERROR; } } @@ -425,14 +355,14 @@ get_rssi(void) was_off = 1; if(on() != RF_CORE_CMD_OK) { PRINTF("get_rssi: on() failed\n"); - return RF_CMD_CCA_REQ_RSSI_UNKNOWN; + return RF_CORE_CMD_CCA_REQ_RSSI_UNKNOWN; } } memset(&cmd, 0x00, sizeof(cmd)); - cmd.ccaInfo.ccaEnergy = RF_CMD_CCA_REQ_CCA_STATE_INVALID; + cmd.ccaInfo.ccaEnergy = RF_CORE_CMD_CCA_REQ_CCA_STATE_INVALID; - while(cmd.ccaInfo.ccaEnergy == RF_CMD_CCA_REQ_CCA_STATE_INVALID) { + while(cmd.ccaInfo.ccaEnergy == RF_CORE_CMD_CCA_REQ_CCA_STATE_INVALID) { memset(&cmd, 0x00, sizeof(cmd)); cmd.commandNo = CMD_IEEE_CCA_REQ; @@ -440,7 +370,7 @@ get_rssi(void) PRINTF("get_rssi: CMDSTA=0x%08lx\n", cmd_status); /* Make sure to return RSSI unknown */ - cmd.currentRssi = RF_CMD_CCA_REQ_RSSI_UNKNOWN; + cmd.currentRssi = RF_CORE_CMD_CCA_REQ_RSSI_UNKNOWN; break; } } @@ -558,8 +488,8 @@ rf_cmd_ieee_rx() return RF_CORE_CMD_ERROR; } - LIMITED_BUSYWAIT(RF_RADIO_OP_GET_STATUS(cmd_ieee_rx_buf) != RF_CORE_RADIO_OP_STATUS_ACTIVE, - ENTER_RX_WAIT_TIMEOUT); + RTIMER_BUSYWAIT_UNTIL(RF_RADIO_OP_GET_STATUS(cmd_ieee_rx_buf) == RF_CORE_RADIO_OP_STATUS_ACTIVE, + RF_CORE_ENTER_RX_TIMEOUT); /* Wait to enter RX */ if(RF_RADIO_OP_GET_STATUS(cmd_ieee_rx_buf) != RF_CORE_RADIO_OP_STATUS_ACTIVE) { @@ -610,16 +540,16 @@ init_rf_params(void) cmd->startTime = 0x00000000; cmd->startTrigger.triggerType = TRIG_NOW; cmd->condition.rule = COND_NEVER; - cmd->channel = RF_CORE_CHANNEL; + cmd->channel = IEEE802154_DEFAULT_CHANNEL; cmd->rxConfig.bAutoFlushCrc = 1; cmd->rxConfig.bAutoFlushIgn = 0; cmd->rxConfig.bIncludePhyHdr = 0; - cmd->rxConfig.bIncludeCrc = RX_BUF_INCLUDE_CRC; - cmd->rxConfig.bAppendRssi = RX_BUF_INCLUDE_RSSI; - cmd->rxConfig.bAppendCorrCrc = RX_BUF_INCLUDE_CORR; + cmd->rxConfig.bIncludeCrc = RF_CORE_RX_BUF_INCLUDE_CRC; + cmd->rxConfig.bAppendRssi = RF_CORE_RX_BUF_INCLUDE_RSSI; + cmd->rxConfig.bAppendCorrCrc = RF_CORE_RX_BUF_INCLUDE_CORR; cmd->rxConfig.bAppendSrcInd = 0; - cmd->rxConfig.bAppendTimestamp = RX_BUF_INCLUDE_TIMESTAMP; + cmd->rxConfig.bAppendTimestamp = RF_CORE_RX_BUF_INCLUDE_TIMESTAMP; cmd->pRxQ = &rx_data_queue; cmd->pOutput = (rfc_ieeeRxOutput_t *)rf_stats; @@ -714,7 +644,7 @@ rx_off(void) } /* Wait for ongoing ACK TX to finish */ - LIMITED_BUSYWAIT(transmitting(), TX_FINISH_WAIT_TIMEOUT); + RTIMER_BUSYWAIT_UNTIL(!transmitting(), RF_CORE_TX_FINISH_TIMEOUT); /* Send a CMD_ABORT command to RF Core */ if(rf_core_send_cmd(CMDR_DIR_CMD(CMD_ABORT), &cmd_status) != RF_CORE_CMD_OK) { @@ -722,7 +652,7 @@ rx_off(void) /* Continue nonetheless */ } - LIMITED_BUSYWAIT(rf_is_on(), RF_TURN_OFF_WAIT_TIMEOUT); + RTIMER_BUSYWAIT_UNTIL(!rf_is_on(), RF_CORE_TURN_OFF_TIMEOUT); if(RF_RADIO_OP_GET_STATUS(cmd_ieee_rx_buf) == IEEE_DONE_STOPPED || RF_RADIO_OP_GET_STATUS(cmd_ieee_rx_buf) == IEEE_DONE_ABORT) { @@ -773,8 +703,8 @@ soft_off(void) return; } - LIMITED_BUSYWAIT((cmd->status & RF_CORE_RADIO_OP_MASKED_STATUS) == - RF_CORE_RADIO_OP_MASKED_STATUS_RUNNING, RF_TURN_OFF_WAIT_TIMEOUT); + RTIMER_BUSYWAIT_UNTIL((cmd->status & RF_CORE_RADIO_OP_MASKED_STATUS) != + RF_CORE_RADIO_OP_MASKED_STATUS_RUNNING, RF_CORE_TURN_OFF_TIMEOUT); } /*---------------------------------------------------------------------------*/ static uint8_t @@ -791,71 +721,10 @@ soft_on(void) static const rf_core_primary_mode_t mode_ieee = { soft_off, soft_on, + rf_is_on, + RAT_TIMESTAMP_OFFSET_2_4_GHZ }; /*---------------------------------------------------------------------------*/ -static uint8_t -check_rat_overflow(bool first_time) -{ - static uint32_t last_value; - uint32_t current_value; - uint8_t interrupts_disabled; - - /* Bail out if the RF is not on */ - if(!rf_is_on()) { - return 0; - } - - interrupts_disabled = ti_lib_int_master_disable(); - if(first_time) { - last_value = HWREG(RFC_RAT_BASE + RATCNT); - } else { - current_value = HWREG(RFC_RAT_BASE + RATCNT); - if(current_value + RAT_RANGE / 4 < last_value) { - /* Overflow detected */ - last_rat_overflow = RTIMER_NOW(); - rat_overflow_counter++; - } - last_value = current_value; - } - if(!interrupts_disabled) { - ti_lib_int_master_enable(); - } - return 1; -} -/*---------------------------------------------------------------------------*/ -static void -handle_rat_overflow(void *unused) -{ - uint8_t success; - uint8_t was_off = 0; - - if(!rf_is_on()) { - was_off = 1; - if(on() != RF_CORE_CMD_OK) { - PRINTF("overflow: on() failed\n"); - ctimer_set(&rat_overflow_timer, CLOCK_SECOND, - handle_rat_overflow, NULL); - return; - } - } - - success = check_rat_overflow(false); - - if(was_off) { - off(); - } - - if(success) { - /* Retry after half of the interval */ - ctimer_set(&rat_overflow_timer, RAT_OVERFLOW_PERIOD_SECONDS * CLOCK_SECOND / 2, - handle_rat_overflow, NULL); - } else { - /* Retry sooner */ - ctimer_set(&rat_overflow_timer, CLOCK_SECOND, - handle_rat_overflow, NULL); - } -} -/*---------------------------------------------------------------------------*/ static int init(void) { @@ -889,9 +758,7 @@ init(void) rf_core_primary_mode_register(&mode_ieee); - check_rat_overflow(true); - ctimer_set(&rat_overflow_timer, RAT_OVERFLOW_PERIOD_SECONDS * CLOCK_SECOND / 2, - handle_rat_overflow, NULL); + rf_core_rat_init(); process_start(&rf_core_process, NULL); return 1; @@ -935,7 +802,7 @@ transmit(unsigned short transmit_len) do { tx_active = transmitting(); } while(tx_active == 1 && - (RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + TX_WAIT_TIMEOUT))); + (RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + RF_CORE_TX_TIMEOUT))); if(tx_active) { PRINTF("transmit: Already TXing and wait timed out\n"); @@ -957,7 +824,7 @@ transmit(unsigned short transmit_len) cmd.startTrigger.triggerType = TRIG_NOW; /* Enable the LAST_FG_COMMAND_DONE interrupt, which will wake us up */ - rf_core_cmd_done_en(true, poll_mode); + rf_core_cmd_done_en(true); ret = rf_core_send_cmd((uint32_t)&cmd, &cmd_status); @@ -973,7 +840,7 @@ transmit(unsigned short transmit_len) * 1) make the `lpm_sleep()` call here unconditional; * 2) change the radio ISR priority to allow radio ISR to interrupt rtimer ISR. */ - if(!poll_mode) { + if(!rf_core_poll_mode) { lpm_sleep(); } } @@ -1007,7 +874,7 @@ transmit(unsigned short transmit_len) * Disable LAST_FG_COMMAND_DONE interrupt. We don't really care about it * except when we are transmitting */ - rf_core_cmd_done_dis(poll_mode); + rf_core_cmd_done_dis(); if(was_off) { off(); @@ -1036,46 +903,6 @@ release_data_entry(void) rx_read_entry = entry->pNextEntry; } /*---------------------------------------------------------------------------*/ -static uint32_t -calc_last_packet_timestamp(uint32_t rat_timestamp) -{ - uint64_t rat_timestamp64; - uint32_t adjusted_overflow_counter; - uint8_t was_off = 0; - - if(!rf_is_on()) { - was_off = 1; - on(); - } - - if(rf_is_on()) { - check_rat_overflow(false); - if(was_off) { - off(); - } - } - - adjusted_overflow_counter = rat_overflow_counter; - - /* if the timestamp is large and the last oveflow was recently, - assume that the timestamp refers to the time before the overflow */ - if(rat_timestamp > (uint32_t)(RAT_RANGE * 3 / 4)) { - if(RTIMER_CLOCK_LT(RTIMER_NOW(), - last_rat_overflow + RAT_OVERFLOW_PERIOD_SECONDS * RTIMER_SECOND / 4)) { - adjusted_overflow_counter--; - } - } - - /* add the overflowed time to the timestamp */ - rat_timestamp64 = rat_timestamp + RAT_RANGE * adjusted_overflow_counter; - /* correct timestamp so that it refers to the end of the SFD */ - rat_timestamp64 += TIMESTAMP_OFFSET; - - last_rat_timestamp64 = rat_timestamp64 - rat_offset; - - return RADIO_TO_RTIMER(rat_timestamp64 - rat_offset); -} -/*---------------------------------------------------------------------------*/ static int read_frame(void *buf, unsigned short buf_len) { @@ -1111,20 +938,20 @@ read_frame(void *buf, unsigned short buf_len) memcpy(buf, (uint8_t *)rx_read_entry + RX_BUF_DATA_OFFSET, len); - last_rssi = (int8_t)rx_read_entry[RX_BUF_DATA_OFFSET + len + 2]; - last_corr_lqi = (uint8_t)rx_read_entry[RX_BUF_DATA_OFFSET + len + 3] & STATUS_CORRELATION; + rf_core_last_rssi = (int8_t)rx_read_entry[RX_BUF_DATA_OFFSET + len]; + rf_core_last_corr_lqi = (uint8_t)rx_read_entry[RX_BUF_DATA_OFFSET + len + 1] & STATUS_CORRELATION; /* get the timestamp */ - memcpy(&rat_timestamp, (uint8_t *)rx_read_entry + RX_BUF_DATA_OFFSET + len + 4, 4); + memcpy(&rat_timestamp, (uint8_t *)rx_read_entry + RX_BUF_DATA_OFFSET + len + 2, 4); - last_packet_timestamp = calc_last_packet_timestamp(rat_timestamp); + rf_core_last_packet_timestamp = rf_core_convert_rat_to_rtimer(rat_timestamp); - if(!poll_mode) { + if(!rf_core_poll_mode) { /* Not in poll mode: packetbuf should not be accessed in interrupt context. * In poll mode, the last packet RSSI and link quality can be obtained through * RADIO_PARAM_LAST_RSSI and RADIO_PARAM_LAST_LINK_QUALITY */ - packetbuf_set_attr(PACKETBUF_ATTR_RSSI, last_rssi); - packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, last_corr_lqi); + packetbuf_set_attr(PACKETBUF_ATTR_RSSI, rf_core_last_rssi); + packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, rf_core_last_corr_lqi); } release_data_entry(); @@ -1137,7 +964,7 @@ channel_clear(void) { uint8_t was_off = 0; uint8_t cca_info; - int ret = RF_CCA_CLEAR; + int ret = RF_CORE_CCA_CLEAR; /* * If we are in the middle of a BLE operation, we got called by ContikiMAC @@ -1145,7 +972,7 @@ channel_clear(void) */ if(rf_ble_is_active() == RF_BLE_ACTIVE) { PRINTF("channel_clear: Interrupt context but BLE in progress\n"); - return RF_CCA_CLEAR; + return RF_CORE_CCA_CLEAR; } if(rf_is_on()) { @@ -1157,7 +984,7 @@ channel_clear(void) * * We could probably even simply return that the channel is clear */ - LIMITED_BUSYWAIT(transmitting(), TX_FINISH_WAIT_TIMEOUT); + RTIMER_BUSYWAIT_UNTIL(!transmitting(), RF_CORE_TX_FINISH_TIMEOUT); } else { was_off = 1; if(on() != RF_CORE_CMD_OK) { @@ -1165,21 +992,21 @@ channel_clear(void) if(was_off) { off(); } - return RF_CCA_CLEAR; + return RF_CORE_CCA_CLEAR; } } cca_info = get_cca_info(); - if(cca_info == RF_GET_CCA_INFO_ERROR) { + if(cca_info == RF_CORE_GET_CCA_INFO_ERROR) { PRINTF("channel_clear: CCA error\n"); - ret = RF_CCA_CLEAR; + ret = RF_CORE_CCA_CLEAR; } else { /* * cca_info bits 1:0 - ccaStatus * Return 1 (clear) if idle or invalid. */ - ret = (cca_info & 0x03) != RF_CMD_CCA_REQ_CCA_STATE_BUSY; + ret = (cca_info & 0x03) != RF_CORE_CMD_CCA_REQ_CCA_STATE_BUSY; } if(was_off) { @@ -1218,12 +1045,12 @@ receiving_packet(void) cca_info = get_cca_info(); /* If we can't read CCA info, return "not receiving" */ - if(cca_info == RF_GET_CCA_INFO_ERROR) { + if(cca_info == RF_CORE_GET_CCA_INFO_ERROR) { return 0; } /* If sync has been seen, return 1 (receiving) */ - if(cca_info & RF_CMD_CCA_REQ_CCA_SYNC_BUSY) { + if(cca_info & RF_CORE_CMD_CCA_REQ_CCA_SYNC_BUSY) { return 1; } @@ -1241,7 +1068,7 @@ pending_packet(void) if(entry->status == DATA_ENTRY_STATUS_FINISHED || entry->status == DATA_ENTRY_STATUS_BUSY) { rv = 1; - if(!poll_mode) { + if(!rf_core_poll_mode) { process_poll(&rf_core_process); } } @@ -1292,7 +1119,7 @@ on(void) return RF_CORE_CMD_ERROR; } - rf_core_setup_interrupts(poll_mode); + rf_core_setup_interrupts(); if(rf_radio_setup() != RF_CORE_CMD_OK) { PRINTF("on: radio_setup() failed\n"); @@ -1314,7 +1141,7 @@ off(void) return RF_CORE_CMD_OK; } - LIMITED_BUSYWAIT(transmitting(), TX_FINISH_WAIT_TIMEOUT); + RTIMER_BUSYWAIT_UNTIL(!transmitting(), RF_CORE_TX_FINISH_TIMEOUT); /* stopping the rx explicitly results in lower sleep-mode power usage */ rx_off(); @@ -1394,7 +1221,7 @@ get_value(radio_param_t param, radio_value_t *value) if(cmd->frameFiltOpt.autoAckEn) { *value |= RADIO_RX_MODE_AUTOACK; } - if(poll_mode) { + if(rf_core_poll_mode) { *value |= RADIO_RX_MODE_POLL_MODE; } @@ -1411,7 +1238,7 @@ get_value(radio_param_t param, radio_value_t *value) case RADIO_PARAM_RSSI: *value = get_rssi(); - if(*value == RF_CMD_CCA_REQ_RSSI_UNKNOWN) { + if(*value == RF_CORE_CMD_CCA_REQ_RSSI_UNKNOWN) { return RADIO_RESULT_ERROR; } else { return RADIO_RESULT_OK; @@ -1429,10 +1256,25 @@ get_value(radio_param_t param, radio_value_t *value) *value = OUTPUT_POWER_MAX; return RADIO_RESULT_OK; case RADIO_PARAM_LAST_RSSI: - *value = last_rssi; + *value = rf_core_last_rssi; return RADIO_RESULT_OK; case RADIO_PARAM_LAST_LINK_QUALITY: - *value = last_corr_lqi; + *value = rf_core_last_corr_lqi; + return RADIO_RESULT_OK; + case RADIO_CONST_PHY_OVERHEAD: + *value = (radio_value_t)RADIO_PHY_OVERHEAD; + return RADIO_RESULT_OK; + case RADIO_CONST_BYTE_AIR_TIME: + *value = (radio_value_t)RADIO_BYTE_AIR_TIME; + return RADIO_RESULT_OK; + case RADIO_CONST_DELAY_BEFORE_TX: + *value = (radio_value_t)RADIO_DELAY_BEFORE_TX; + return RADIO_RESULT_OK; + case RADIO_CONST_DELAY_BEFORE_RX: + *value = (radio_value_t)RADIO_DELAY_BEFORE_RX; + return RADIO_RESULT_OK; + case RADIO_CONST_DELAY_BEFORE_DETECT: + *value = (radio_value_t)RADIO_DELAY_BEFORE_DETECT; return RADIO_RESULT_OK; default: return RADIO_RESULT_NOT_SUPPORTED; @@ -1498,9 +1340,9 @@ set_value(radio_param_t param, radio_value_t value) cmd->frameFiltOpt.bPanCoord = 0; cmd->frameFiltOpt.bStrictLenFilter = 0; - old_poll_mode = poll_mode; - poll_mode = (value & RADIO_RX_MODE_POLL_MODE) != 0; - if(poll_mode == old_poll_mode) { + old_poll_mode = rf_core_poll_mode; + rf_core_poll_mode = (value & RADIO_RX_MODE_POLL_MODE) != 0; + if(rf_core_poll_mode == old_poll_mode) { uint32_t cmd_status; /* do not turn the radio on and off, just send an update command */ @@ -1552,7 +1394,7 @@ set_value(radio_param_t param, radio_value_t value) /* Restart the radio timer (RAT). This causes resynchronization between RAT and RTC: useful for TSCH. */ if(rf_core_restart_rat() == RF_CORE_CMD_OK) { - check_rat_overflow(false); + rf_core_check_rat_overflow(); } if(rx_on() != RF_CORE_CMD_OK) { @@ -1590,7 +1432,7 @@ get_object(radio_param_t param, void *dest, size_t size) if(size != sizeof(rtimer_clock_t) || !dest) { return RADIO_RESULT_INVALID_VALUE; } - *(rtimer_clock_t *)dest = last_packet_timestamp; + *(rtimer_clock_t *)dest = rf_core_last_packet_timestamp; return RADIO_RESULT_OK; } diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/prop-mode.c b/arch/cpu/cc26xx-cc13xx/rf-core/prop-mode.c index f9f49e9a0..0ce6de5dd 100644 --- a/arch/cpu/cc26xx-cc13xx/rf-core/prop-mode.c +++ b/arch/cpu/cc26xx-cc13xx/rf-core/prop-mode.c @@ -45,6 +45,7 @@ #include "net/netstack.h" #include "sys/energest.h" #include "sys/clock.h" +#include "sys/critical.h" #include "sys/rtimer.h" #include "sys/cc.h" #include "lpm.h" @@ -114,24 +115,6 @@ */ #define RF_RADIO_OP_GET_STATUS(a) GET_FIELD_V(a, radioOp, status) /*---------------------------------------------------------------------------*/ -/* Special value returned by CMD_IEEE_CCA_REQ when an RSSI is not available */ -#define RF_CMD_CCA_REQ_RSSI_UNKNOWN -128 - -/* Used for the return value of channel_clear */ -#define RF_CCA_CLEAR 1 -#define RF_CCA_BUSY 0 - -/* Used as an error return value for get_cca_info */ -#define RF_GET_CCA_INFO_ERROR 0xFF - -/* - * Values of the individual bits of the ccaInfo field in CMD_IEEE_CCA_REQ's - * status struct - */ -#define RF_CMD_CCA_REQ_CCA_STATE_IDLE 0 /* 00 */ -#define RF_CMD_CCA_REQ_CCA_STATE_BUSY 1 /* 01 */ -#define RF_CMD_CCA_REQ_CCA_STATE_INVALID 2 /* 10 */ - #ifdef PROP_MODE_CONF_RSSI_THRESHOLD #define PROP_MODE_RSSI_THRESHOLD PROP_MODE_CONF_RSSI_THRESHOLD #else @@ -140,6 +123,8 @@ static int8_t rssi_threshold = PROP_MODE_RSSI_THRESHOLD; /*---------------------------------------------------------------------------*/ +static volatile uint8_t is_receiving_packet; +/*---------------------------------------------------------------------------*/ static int on(void); static int off(void); @@ -169,12 +154,6 @@ static rfc_propRxOutput_t rx_stats; #define DOT_4G_PHR_DW_BIT 0 #endif /*---------------------------------------------------------------------------*/ -/* How long to wait for an ongoing ACK TX to finish before starting frame TX */ -#define TX_WAIT_TIMEOUT (RTIMER_SECOND >> 11) - -/* How long to wait for the RF to enter RX in rf_cmd_ieee_rx */ -#define ENTER_RX_WAIT_TIMEOUT (RTIMER_SECOND >> 10) -/*---------------------------------------------------------------------------*/ /* TX power table for the 431-527MHz band */ #ifdef PROP_MODE_CONF_TX_POWER_431_527 #define PROP_MODE_TX_POWER_431_527 PROP_MODE_CONF_TX_POWER_431_527 @@ -221,12 +200,29 @@ static const prop_mode_tx_power_config_t *tx_power_current = &TX_POWER_DRIVER[1] #define DATA_ENTRY_LENSZ_BYTE 1 #define DATA_ENTRY_LENSZ_WORD 2 /* 2 bytes */ +/* The size of the metadata (excluding the packet length field) */ +#define RX_BUF_METADATA_SIZE \ + (CRC_LEN * RF_CORE_RX_BUF_INCLUDE_CRC \ + + RF_CORE_RX_BUF_INCLUDE_RSSI \ + + RF_CORE_RX_BUF_INCLUDE_CORR \ + + 4 * RF_CORE_RX_BUF_INCLUDE_TIMESTAMP) + +/* The offset of the packet length in a rx buffer */ +#define RX_BUF_LENGTH_OFFSET sizeof(rfc_dataEntry_t) +/* The offset of the packet data in a rx buffer */ +#define RX_BUF_DATA_OFFSET (RX_BUF_LENGTH_OFFSET + DOT_4G_PHR_LEN) + +#define ALIGN_TO_4(size) (((size) + 3) & ~3) + +#define RX_BUF_SIZE ALIGN_TO_4(RX_BUF_DATA_OFFSET \ + + NETSTACK_RADIO_MAX_PAYLOAD_LEN \ + + RX_BUF_METADATA_SIZE) + /* * RX buffers. * PROP_MODE_RX_BUF_CNT buffers of RX_BUF_SIZE bytes each. The start of each * buffer must be 4-byte aligned, therefore RX_BUF_SIZE must divide by 4 */ -#define RX_BUF_SIZE 140 static uint8_t rx_buf[PROP_MODE_RX_BUF_CNT][RX_BUF_SIZE] CC_ALIGN(4); /* The RX Data Queue */ @@ -235,6 +231,12 @@ static dataQueue_t rx_data_queue = { 0 }; /* Receive entry pointer to keep track of read items */ volatile static uint8_t *rx_read_entry; /*---------------------------------------------------------------------------*/ +/* + * Increasing this number causes unicast Tx immediately after broadcast Rx to have + * negative synchronization errors ("dr" in TSCH logs); decreasing it: the opposite. + */ +#define RAT_TIMESTAMP_OFFSET_SUB_GHZ USEC_TO_RADIO(160 * 6 - 240) +/*---------------------------------------------------------------------------*/ /* The outgoing frame buffer */ #define TX_BUF_PAYLOAD_LEN 180 #define TX_BUF_HDR_LEN 2 @@ -271,13 +273,13 @@ get_rssi(void) was_off = 1; if(on() != RF_CORE_CMD_OK) { PRINTF("get_rssi: on() failed\n"); - return RF_CMD_CCA_REQ_RSSI_UNKNOWN; + return RF_CORE_CMD_CCA_REQ_RSSI_UNKNOWN; } } - rssi = RF_CMD_CCA_REQ_RSSI_UNKNOWN; + rssi = RF_CORE_CMD_CCA_REQ_RSSI_UNKNOWN; - while((rssi == RF_CMD_CCA_REQ_RSSI_UNKNOWN || rssi == 0) && ++attempts < 10) { + while((rssi == RF_CORE_CMD_CCA_REQ_RSSI_UNKNOWN || rssi == 0) && ++attempts < 10) { memset(&cmd, 0x00, sizeof(cmd)); cmd.commandNo = CMD_GET_RSSI; @@ -419,13 +421,17 @@ static uint8_t rf_cmd_prop_rx() { uint32_t cmd_status; - rtimer_clock_t t0; volatile rfc_CMD_PROP_RX_ADV_t *cmd_rx_adv; int ret; cmd_rx_adv = (rfc_CMD_PROP_RX_ADV_t *)&smartrf_settings_cmd_prop_rx_adv; cmd_rx_adv->status = RF_CORE_RADIO_OP_STATUS_IDLE; + cmd_rx_adv->rxConf.bIncludeCrc = RF_CORE_RX_BUF_INCLUDE_CRC; + cmd_rx_adv->rxConf.bAppendRssi = RF_CORE_RX_BUF_INCLUDE_RSSI; + cmd_rx_adv->rxConf.bAppendTimestamp = RF_CORE_RX_BUF_INCLUDE_TIMESTAMP; + cmd_rx_adv->rxConf.bAppendStatus = RF_CORE_RX_BUF_INCLUDE_CORR; + /* * Set the max Packet length. This is for the payload only, therefore * 2047 - length offset @@ -440,10 +446,8 @@ rf_cmd_prop_rx() return RF_CORE_CMD_ERROR; } - t0 = RTIMER_NOW(); - - while(cmd_rx_adv->status != RF_CORE_RADIO_OP_STATUS_ACTIVE && - (RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + ENTER_RX_WAIT_TIMEOUT))); + RTIMER_BUSYWAIT_UNTIL(cmd_rx_adv->status == RF_CORE_RADIO_OP_STATUS_ACTIVE, + RF_CORE_ENTER_RX_TIMEOUT); /* Wait to enter RX */ if(cmd_rx_adv->status != RF_CORE_RADIO_OP_STATUS_ACTIVE) { @@ -505,13 +509,16 @@ rx_off_prop(void) return RF_CORE_CMD_OK; } + /* Wait for ongoing ACK TX to finish */ + RTIMER_BUSYWAIT_UNTIL(!transmitting(), RF_CORE_TX_FINISH_TIMEOUT); + /* Send a CMD_ABORT command to RF Core */ if(rf_core_send_cmd(CMDR_DIR_CMD(CMD_ABORT), &cmd_status) != RF_CORE_CMD_OK) { PRINTF("rx_off_prop: CMD_ABORT status=0x%08lx\n", cmd_status); /* Continue nonetheless */ } - while(rf_is_on()); + RTIMER_BUSYWAIT_UNTIL(!rf_is_on(), RF_CORE_TURN_OFF_TIMEOUT); if(smartrf_settings_cmd_prop_rx_adv.status == PROP_DONE_STOPPED || smartrf_settings_cmd_prop_rx_adv.status == PROP_DONE_ABORT) { @@ -582,8 +589,8 @@ soft_off_prop(void) return; } - while((cmd->status & RF_CORE_RADIO_OP_MASKED_STATUS) == - RF_CORE_RADIO_OP_MASKED_STATUS_RUNNING); + RTIMER_BUSYWAIT_UNTIL((cmd->status & RF_CORE_RADIO_OP_MASKED_STATUS) != + RF_CORE_RADIO_OP_MASKED_STATUS_RUNNING, RF_CORE_TURN_OFF_TIMEOUT); } /*---------------------------------------------------------------------------*/ static uint8_t @@ -605,6 +612,8 @@ soft_on_prop(void) static const rf_core_primary_mode_t mode_prop = { soft_off_prop, soft_on_prop, + rf_is_on, + RAT_TIMESTAMP_OFFSET_SUB_GHZ }; /*---------------------------------------------------------------------------*/ static int @@ -629,17 +638,22 @@ init(void) smartrf_settings_cmd_prop_rx_adv.pQueue = &rx_data_queue; smartrf_settings_cmd_prop_rx_adv.pOutput = (uint8_t *)&rx_stats; - set_channel(RF_CORE_CHANNEL); + set_channel(IEEE802154_DEFAULT_CHANNEL); if(on() != RF_CORE_CMD_OK) { PRINTF("init: on() failed\n"); return RF_CORE_CMD_ERROR; } + /* Enable the "sync word seen" interrupt */ + ti_lib_rfc_hw_int_enable(RFC_DBELL_RFHWIEN_MDMSOFT); + ENERGEST_ON(ENERGEST_TYPE_LISTEN); rf_core_primary_mode_register(&mode_prop); + rf_core_rat_init(); + process_start(&rf_core_process, NULL); return 1; @@ -700,7 +714,7 @@ transmit(unsigned short transmit_len) rx_off_prop(); /* Enable the LAST_COMMAND_DONE interrupt to wake us up */ - rf_core_cmd_done_en(false, false); + rf_core_cmd_done_en(false); ret = rf_core_send_cmd((uint32_t)cmd_tx_adv, &cmd_status); @@ -713,7 +727,14 @@ transmit(unsigned short transmit_len) /* Idle away while the command is running */ while((cmd_tx_adv->status & RF_CORE_RADIO_OP_MASKED_STATUS) == RF_CORE_RADIO_OP_MASKED_STATUS_RUNNING) { - lpm_sleep(); + /* Note: for now sleeping while Tx'ing in polling mode is disabled. + * To enable it: + * 1) make the `lpm_sleep()` call here unconditional; + * 2) change the radio ISR priority to allow radio ISR to interrupt rtimer ISR. + */ + if(!rf_core_poll_mode) { + lpm_sleep(); + } } if(cmd_tx_adv->status == RF_CORE_RADIO_OP_STATUS_PROP_DONE_OK) { @@ -742,7 +763,7 @@ transmit(unsigned short transmit_len) * Disable LAST_FG_COMMAND_DONE interrupt. We don't really care about it * except when we are transmitting */ - rf_core_cmd_done_dis(false); + rf_core_cmd_done_dis(); /* Workaround. Set status to IDLE */ cmd_tx_adv->status = RF_CORE_RADIO_OP_STATUS_IDLE; @@ -763,38 +784,98 @@ send(const void *payload, unsigned short payload_len) return transmit(payload_len); } /*---------------------------------------------------------------------------*/ +static void +release_data_entry(void) +{ + rfc_dataEntryGeneral_t *entry = (rfc_dataEntryGeneral_t *)rx_read_entry; + uint8_t *data_ptr = &entry->data; + int_master_status_t interrupt_status; + + /* Clear the length field (2 bytes) */ + data_ptr[0] = 0; + data_ptr[1] = 0; + + /* Set status to 0 "Pending" in element */ + entry->status = DATA_ENTRY_STATUS_PENDING; + rx_read_entry = entry->pNextEntry; + + interrupt_status = critical_enter(); + if(rf_core_rx_is_full) { + rf_core_rx_is_full = false; + PRINTF("RXQ was full, re-enabling radio!\n"); + rx_on_prop(); + } + critical_exit(interrupt_status); + +} +/*---------------------------------------------------------------------------*/ static int read_frame(void *buf, unsigned short buf_len) { rfc_dataEntryGeneral_t *entry = (rfc_dataEntryGeneral_t *)rx_read_entry; uint8_t *data_ptr = &entry->data; int len = 0; + uint32_t rat_timestamp; - if(entry->status == DATA_ENTRY_STATUS_FINISHED) { + /* wait for entry to become finished */ + rtimer_clock_t t0 = RTIMER_NOW(); + while(entry->status == DATA_ENTRY_STATUS_BUSY + && RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (RTIMER_SECOND / 50))); - /* - * First 2 bytes in the data entry are the length. - * Our data entry consists of: Payload + RSSI (1 byte) + Status (1 byte) - * This length includes all of those. - */ - len = (*(uint16_t *)data_ptr); - data_ptr += 2; - len -= 2; + /* Make sure the flag is reset */ + is_receiving_packet = 0; - if(len > 0) { - if(len <= buf_len) { - memcpy(buf, data_ptr, len); - } - - packetbuf_set_attr(PACKETBUF_ATTR_RSSI, (int8_t)data_ptr[len]); - packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, 0x7F); - } - - /* Move read entry pointer to next entry */ - rx_read_entry = entry->pNextEntry; - entry->status = DATA_ENTRY_STATUS_PENDING; + if(entry->status != DATA_ENTRY_STATUS_FINISHED) { + /* No available data */ + return 0; } + /* + * First 2 bytes in the data entry are the length. + * Our data entry consists of: + * Payload + RSSI (1 byte) + Timestamp (4 bytes) + Status (1 byte) + * This length includes all of those. + */ + len = (*(uint16_t *)data_ptr); + + if(len <= RX_BUF_METADATA_SIZE) { + PRINTF("RF: too short!"); + + release_data_entry(); + return 0; + } + + data_ptr += 2; + len -= RX_BUF_METADATA_SIZE; + + if(len > buf_len) { + PRINTF("RF: too long\n"); + + release_data_entry(); + return 0; + } + + memcpy(buf, data_ptr, len); + + /* get the RSSI and status */ + rf_core_last_rssi = (int8_t)data_ptr[len]; + rf_core_last_corr_lqi = data_ptr[len + 5]; + + /* get the timestamp */ + memcpy(&rat_timestamp, data_ptr + len + 1, 4); + + rf_core_last_packet_timestamp = rf_core_convert_rat_to_rtimer(rat_timestamp); + + if(!rf_core_poll_mode) { + /* Not in poll mode: packetbuf should not be accessed in interrupt context. + * In poll mode, the last packet RSSI and link quality can be obtained through + * RADIO_PARAM_LAST_RSSI and RADIO_PARAM_LAST_LINK_QUALITY */ + packetbuf_set_attr(PACKETBUF_ATTR_RSSI, rf_core_last_rssi); + packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, rf_core_last_corr_lqi); + } + + release_data_entry(); + return len; } /*---------------------------------------------------------------------------*/ @@ -803,14 +884,14 @@ channel_clear(void) { uint8_t was_off = 0; uint32_t cmd_status; - int8_t rssi = RF_CMD_CCA_REQ_RSSI_UNKNOWN; + int8_t rssi = RF_CORE_CMD_CCA_REQ_RSSI_UNKNOWN; /* * If we are in the middle of a BLE operation, we got called by ContikiMAC * from within an interrupt context. Indicate a clear channel */ if(rf_ble_is_active() == RF_BLE_ACTIVE) { - return RF_CCA_CLEAR; + return RF_CORE_CCA_CLEAR; } if(!rf_core_is_accessible()) { @@ -820,16 +901,16 @@ channel_clear(void) if(was_off) { off(); } - return RF_CCA_CLEAR; + return RF_CORE_CCA_CLEAR; } } else { if(transmitting()) { PRINTF("channel_clear: called while in TX\n"); - return RF_CCA_CLEAR; + return RF_CORE_CCA_CLEAR; } } - while(rssi == RF_CMD_CCA_REQ_RSSI_UNKNOWN || rssi == 0) { + while(rssi == RF_CORE_CMD_CCA_REQ_RSSI_UNKNOWN || rssi == 0) { if(rf_core_send_cmd(CMDR_DIR_CMD(CMD_GET_RSSI), &cmd_status) != RF_CORE_CMD_OK) { break; @@ -843,10 +924,10 @@ channel_clear(void) } if(rssi >= rssi_threshold) { - return RF_CCA_BUSY; + return RF_CORE_CCA_BUSY; } - return RF_CCA_CLEAR; + return RF_CORE_CCA_CLEAR; } /*---------------------------------------------------------------------------*/ static int @@ -856,11 +937,23 @@ receiving_packet(void) return 0; } - if(channel_clear() == RF_CCA_CLEAR) { - return 0; + if(!is_receiving_packet) { + /* Look for the modem synchronization word detection interrupt flag. + * This flag is raised when the synchronization word is received. + */ + if(HWREG(RFC_DBELL_BASE + RFC_DBELL_O_RFHWIFG) & RFC_DBELL_RFHWIFG_MDMSOFT) { + is_receiving_packet = 1; + } + } else { + /* After the start of the packet: reset the Rx flag once the channel gets clear */ + is_receiving_packet = (channel_clear() == RF_CORE_CCA_BUSY); + if(!is_receiving_packet) { + /* Clear the modem sync flag */ + ti_lib_rfc_hw_int_clear(RFC_DBELL_RFHWIFG_MDMSOFT); + } } - return 1; + return is_receiving_packet; } /*---------------------------------------------------------------------------*/ static int @@ -871,9 +964,12 @@ pending_packet(void) /* Go through all RX buffers and check their status */ do { - if(entry->status == DATA_ENTRY_STATUS_FINISHED) { - rv += 1; - process_poll(&rf_core_process); + if(entry->status == DATA_ENTRY_STATUS_FINISHED + || entry->status == DATA_ENTRY_STATUS_BUSY) { + rv = 1; + if(!rf_core_poll_mode) { + process_poll(&rf_core_process); + } } entry = (rfc_dataEntry_t *)entry->pNextEntry; @@ -894,18 +990,18 @@ on(void) return RF_CORE_CMD_OK; } - /* - * Request the HF XOSC as the source for the HF clock. Needed before we can - * use the FS. This will only request, it will _not_ perform the switch. - */ - oscillators_request_hf_xosc(); - if(rf_is_on()) { PRINTF("on: We were on. PD=%u, RX=0x%04x \n", rf_core_is_accessible(), smartrf_settings_cmd_prop_rx_adv.status); return RF_CORE_CMD_OK; } + /* + * Request the HF XOSC as the source for the HF clock. Needed before we can + * use the FS. This will only request, it will _not_ perform the switch. + */ + oscillators_request_hf_xosc(); + if(!rf_core_is_accessible()) { if(rf_core_power_up() != RF_CORE_CMD_OK) { PRINTF("on: rf_core_power_up() failed\n"); @@ -948,7 +1044,7 @@ on(void) } } - rf_core_setup_interrupts(false); + rf_core_setup_interrupts(); init_rx_buffers(); @@ -975,6 +1071,9 @@ on(void) static int off(void) { + int i; + rfc_dataEntry_t *entry; + /* * If we are in the middle of a BLE operation, we got called by ContikiMAC * from within an interrupt context. Abort, but pretend everything is OK. @@ -988,15 +1087,39 @@ off(void) ENERGEST_OFF(ENERGEST_TYPE_LISTEN); +#if !CC2650_FAST_RADIO_STARTUP /* Switch HF clock source to the RCOSC to preserve power */ oscillators_switch_to_hf_rc(); +#endif /* We pulled the plug, so we need to restore the status manually */ smartrf_settings_cmd_prop_rx_adv.status = RF_CORE_RADIO_OP_STATUS_IDLE; + /* + * Just in case there was an ongoing RX (which started after we begun the + * shutdown sequence), we don't want to leave the buffer in state == ongoing + */ + for(i = 0; i < PROP_MODE_RX_BUF_CNT; i++) { + entry = (rfc_dataEntry_t *)rx_buf[i]; + if(entry->status == DATA_ENTRY_STATUS_BUSY) { + entry->status = DATA_ENTRY_STATUS_PENDING; + } + } + return RF_CORE_CMD_OK; } /*---------------------------------------------------------------------------*/ +/* Enable or disable CCA before sending */ +static radio_result_t +set_send_on_cca(uint8_t enable) +{ + if(enable) { + /* this driver does not have support for CCA on Tx */ + return RADIO_RESULT_NOT_SUPPORTED; + } + return RADIO_RESULT_OK; +} +/*---------------------------------------------------------------------------*/ static radio_result_t get_value(radio_param_t param, radio_value_t *value) { @@ -1012,6 +1135,15 @@ get_value(radio_param_t param, radio_value_t *value) case RADIO_PARAM_CHANNEL: *value = (radio_value_t)get_channel(); return RADIO_RESULT_OK; + case RADIO_PARAM_RX_MODE: + *value = 0; + if(rf_core_poll_mode) { + *value |= RADIO_RX_MODE_POLL_MODE; + } + return RADIO_RESULT_OK; + case RADIO_PARAM_TX_MODE: + *value = 0; + return RADIO_RESULT_OK; case RADIO_PARAM_TXPOWER: *value = get_tx_power(); return RADIO_RESULT_OK; @@ -1021,7 +1153,7 @@ get_value(radio_param_t param, radio_value_t *value) case RADIO_PARAM_RSSI: *value = get_rssi(); - if(*value == RF_CMD_CCA_REQ_RSSI_UNKNOWN) { + if(*value == RF_CORE_CMD_CCA_REQ_RSSI_UNKNOWN) { return RADIO_RESULT_ERROR; } else { return RADIO_RESULT_OK; @@ -1038,6 +1170,28 @@ get_value(radio_param_t param, radio_value_t *value) case RADIO_CONST_TXPOWER_MAX: *value = OUTPUT_POWER_MAX; return RADIO_RESULT_OK; + case RADIO_PARAM_LAST_RSSI: + *value = rf_core_last_rssi; + return RADIO_RESULT_OK; + case RADIO_PARAM_LAST_LINK_QUALITY: + *value = rf_core_last_corr_lqi; + return RADIO_RESULT_OK; + case RADIO_CONST_PHY_OVERHEAD: + /* 2 header bytes, 2 or 4 bytes CRC */ + *value = (radio_value_t)(DOT_4G_PHR_LEN + CRC_LEN); + return RADIO_RESULT_OK; + case RADIO_CONST_BYTE_AIR_TIME: + *value = (radio_value_t)RADIO_BYTE_AIR_TIME; + return RADIO_RESULT_OK; + case RADIO_CONST_DELAY_BEFORE_TX: + *value = (radio_value_t)RADIO_DELAY_BEFORE_TX; + return RADIO_RESULT_OK; + case RADIO_CONST_DELAY_BEFORE_RX: + *value = (radio_value_t)RADIO_DELAY_BEFORE_RX; + return RADIO_RESULT_OK; + case RADIO_CONST_DELAY_BEFORE_DETECT: + *value = (radio_value_t)RADIO_DELAY_BEFORE_DETECT; + return RADIO_RESULT_OK; default: return RADIO_RESULT_NOT_SUPPORTED; } @@ -1046,8 +1200,8 @@ get_value(radio_param_t param, radio_value_t *value) static radio_result_t set_value(radio_param_t param, radio_value_t value) { - uint8_t was_off = 0; radio_result_t rv = RADIO_RESULT_OK; + uint8_t old_poll_mode; switch(param) { case RADIO_PARAM_POWER_MODE: @@ -1077,6 +1231,25 @@ set_value(radio_param_t param, radio_value_t value) set_channel((uint8_t)value); break; + + case RADIO_PARAM_RX_MODE: + if(value & ~(RADIO_RX_MODE_POLL_MODE)) { + return RADIO_RESULT_INVALID_VALUE; + } + + old_poll_mode = rf_core_poll_mode; + rf_core_poll_mode = (value & RADIO_RX_MODE_POLL_MODE) != 0; + if(rf_core_poll_mode == old_poll_mode) { + return RADIO_RESULT_OK; + } + break; + + case RADIO_PARAM_TX_MODE: + if(value & ~(RADIO_TX_MODE_SEND_ON_CCA)) { + return RADIO_RESULT_INVALID_VALUE; + } + return set_send_on_cca((value & RADIO_TX_MODE_SEND_ON_CCA) != 0); + case RADIO_PARAM_TXPOWER: if(value < TX_POWER_DRIVER[get_tx_power_array_last_element()].dbm || value > OUTPUT_POWER_MAX) { @@ -1093,8 +1266,7 @@ set_value(radio_param_t param, radio_value_t value) } return RADIO_RESULT_OK; - case RADIO_PARAM_RX_MODE: - return RADIO_RESULT_OK; + case RADIO_PARAM_CCA_THRESHOLD: rssi_threshold = (int8_t)value; break; @@ -1102,28 +1274,29 @@ set_value(radio_param_t param, radio_value_t value) return RADIO_RESULT_NOT_SUPPORTED; } - /* If we reach here we had no errors. Apply new settings */ + /* If off, the new configuration will be applied the next time radio is started */ if(!rf_is_on()) { - was_off = 1; - if(on() != RF_CORE_CMD_OK) { - PRINTF("set_value: on() failed (2)\n"); - return RADIO_RESULT_ERROR; - } + return RADIO_RESULT_OK; } + /* If we reach here we had no errors. Apply new settings */ if(rx_off_prop() != RF_CORE_CMD_OK) { PRINTF("set_value: rx_off_prop() failed\n"); rv = RADIO_RESULT_ERROR; } - if(soft_on_prop() != RF_CORE_CMD_OK) { - PRINTF("set_value: rx_on_prop() failed\n"); - rv = RADIO_RESULT_ERROR; + /* Restart the radio timer (RAT). + This causes resynchronization between RAT and RTC: useful for TSCH. */ + if(rf_core_restart_rat() != RF_CORE_CMD_OK) { + PRINTF("set_value: rf_core_restart_rat() failed\n"); + /* do not set the error */ + } else { + rf_core_check_rat_overflow(); } - /* If we were off, turn back off */ - if(was_off) { - off(); + if(soft_on_prop() != RF_CORE_CMD_OK) { + PRINTF("set_value: soft_on_prop() failed\n"); + rv = RADIO_RESULT_ERROR; } return rv; @@ -1132,6 +1305,15 @@ set_value(radio_param_t param, radio_value_t value) static radio_result_t get_object(radio_param_t param, void *dest, size_t size) { + if(param == RADIO_PARAM_LAST_PACKET_TIMESTAMP) { + if(size != sizeof(rtimer_clock_t) || !dest) { + return RADIO_RESULT_INVALID_VALUE; + } + *(rtimer_clock_t *)dest = rf_core_last_packet_timestamp; + + return RADIO_RESULT_OK; + } + return RADIO_RESULT_NOT_SUPPORTED; } /*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/rf-core.c b/arch/cpu/cc26xx-cc13xx/rf-core/rf-core.c index 2baa883ad..7e638509d 100644 --- a/arch/cpu/cc26xx-cc13xx/rf-core/rf-core.c +++ b/arch/cpu/cc26xx-cc13xx/rf-core/rf-core.c @@ -76,7 +76,7 @@ /*---------------------------------------------------------------------------*/ /* RF interrupts */ #define RX_FRAME_IRQ IRQ_RX_ENTRY_DONE -#define ERROR_IRQ IRQ_INTERNAL_ERROR +#define ERROR_IRQ (IRQ_INTERNAL_ERROR | IRQ_RX_BUF_FULL) #define RX_NOK_IRQ IRQ_RX_NOK /* Those IRQs are enabled all the time */ @@ -99,9 +99,37 @@ static rfc_radioOp_t *last_radio_op = NULL; /* A struct holding pointers to the primary mode's abort() and restore() */ static const rf_core_primary_mode_t *primary_mode = NULL; /*---------------------------------------------------------------------------*/ +/* RAT has 32-bit register, overflows once 18 minutes */ +#define RAT_RANGE 4294967296ull +/* approximate value */ +#define RAT_OVERFLOW_PERIOD_SECONDS (60 * 18) + +/* how often to check for the overflow, as a minimum */ +#define RAT_OVERFLOW_TIMER_INTERVAL (CLOCK_SECOND * RAT_OVERFLOW_PERIOD_SECONDS / 3) + /* Radio timer (RAT) offset as compared to the rtimer counter (RTC) */ -int32_t rat_offset = 0; -static bool rat_offset_known = false; +static int32_t rat_offset; +static bool rat_offset_known; + +/* Value during the last read of the RAT register */ +static uint32_t rat_last_value; + +/* For RAT overflow handling */ +static struct ctimer rat_overflow_timer; +static volatile uint32_t rat_overflow_counter; +static rtimer_clock_t rat_last_overflow; + +static void rat_overflow_check_timer_cb(void *); +/*---------------------------------------------------------------------------*/ +volatile int8_t rf_core_last_rssi = RF_CORE_CMD_CCA_REQ_RSSI_UNKNOWN; +volatile uint8_t rf_core_last_corr_lqi = 0; +volatile uint32_t rf_core_last_packet_timestamp = 0; +/*---------------------------------------------------------------------------*/ +/* Are we currently in poll mode? */ +uint8_t rf_core_poll_mode = 0; +/*---------------------------------------------------------------------------*/ +/* Buffer full flag */ +volatile bool rf_core_rx_is_full = false; /*---------------------------------------------------------------------------*/ PROCESS(rf_core_process, "CC13xx / CC26xx RF driver"); /*---------------------------------------------------------------------------*/ @@ -396,6 +424,11 @@ rf_core_set_modesel() } else if(chip_type == CHIP_TYPE_CC1350) { HWREG(PRCM_BASE + PRCM_O_RFCMODESEL) = PRCM_RFCMODESEL_CURR_MODE5; rv = RF_CORE_CMD_OK; +#if CPU_FAMILY_CC26X0R2 + } else if(chip_type == CHIP_TYPE_CC2640R2) { + HWREG(PRCM_BASE + PRCM_O_RFCMODESEL) = PRCM_RFCMODESEL_CURR_MODE1; + rv = RF_CORE_CMD_OK; +#endif } return rv; @@ -443,10 +476,10 @@ rf_core_restart_rat(void) } /*---------------------------------------------------------------------------*/ void -rf_core_setup_interrupts(bool poll_mode) +rf_core_setup_interrupts(void) { bool interrupts_disabled; - const uint32_t enabled_irqs = poll_mode ? ENABLED_IRQS_POLL_MODE : ENABLED_IRQS; + const uint32_t enabled_irqs = rf_core_poll_mode ? ENABLED_IRQS_POLL_MODE : ENABLED_IRQS; /* We are already turned on by the caller, so this should not happen */ if(!rf_core_is_accessible()) { @@ -477,19 +510,23 @@ rf_core_setup_interrupts(bool poll_mode) } /*---------------------------------------------------------------------------*/ void -rf_core_cmd_done_en(bool fg, bool poll_mode) +rf_core_cmd_done_en(bool fg) { - uint32_t irq = fg ? IRQ_LAST_FG_COMMAND_DONE : IRQ_LAST_COMMAND_DONE; - const uint32_t enabled_irqs = poll_mode ? ENABLED_IRQS_POLL_MODE : ENABLED_IRQS; + uint32_t irq = 0; + const uint32_t enabled_irqs = rf_core_poll_mode ? ENABLED_IRQS_POLL_MODE : ENABLED_IRQS; + + if(!rf_core_poll_mode) { + irq = fg ? IRQ_LAST_FG_COMMAND_DONE : IRQ_LAST_COMMAND_DONE; + } HWREG(RFC_DBELL_NONBUF_BASE + RFC_DBELL_O_RFCPEIFG) = enabled_irqs; HWREG(RFC_DBELL_NONBUF_BASE + RFC_DBELL_O_RFCPEIEN) = enabled_irqs | irq; } /*---------------------------------------------------------------------------*/ void -rf_core_cmd_done_dis(bool poll_mode) +rf_core_cmd_done_dis(void) { - const uint32_t enabled_irqs = poll_mode ? ENABLED_IRQS_POLL_MODE : ENABLED_IRQS; + const uint32_t enabled_irqs = rf_core_poll_mode ? ENABLED_IRQS_POLL_MODE : ENABLED_IRQS; HWREG(RFC_DBELL_NONBUF_BASE + RFC_DBELL_O_RFCPEIEN) = enabled_irqs; } /*---------------------------------------------------------------------------*/ @@ -536,6 +573,123 @@ rf_core_primary_mode_restore() return RF_CORE_CMD_ERROR; } /*---------------------------------------------------------------------------*/ +uint8_t +rf_core_rat_init(void) +{ + rat_last_value = HWREG(RFC_RAT_BASE + RATCNT); + + ctimer_set(&rat_overflow_timer, RAT_OVERFLOW_TIMER_INTERVAL, + rat_overflow_check_timer_cb, NULL); + + return 1; +} +/*---------------------------------------------------------------------------*/ +uint8_t +rf_core_check_rat_overflow(void) +{ + uint32_t rat_current_value; + uint8_t interrupts_disabled; + + /* Bail out if the RF is not on */ + if(primary_mode == NULL || !primary_mode->is_on()) { + return 0; + } + + interrupts_disabled = ti_lib_int_master_disable(); + + rat_current_value = HWREG(RFC_RAT_BASE + RATCNT); + if(rat_current_value + RAT_RANGE / 4 < rat_last_value) { + /* Overflow detected */ + rat_last_overflow = RTIMER_NOW(); + rat_overflow_counter++; + } + rat_last_value = rat_current_value; + + if(!interrupts_disabled) { + ti_lib_int_master_enable(); + } + + return 1; +} +/*---------------------------------------------------------------------------*/ +static void +rat_overflow_check_timer_cb(void *unused) +{ + uint8_t success = 0; + uint8_t was_off = 0; + + if(primary_mode != NULL) { + + if(!primary_mode->is_on()) { + was_off = 1; + if(NETSTACK_RADIO.on() != RF_CORE_CMD_OK) { + PRINTF("overflow: on() failed\n"); + ctimer_set(&rat_overflow_timer, CLOCK_SECOND, + rat_overflow_check_timer_cb, NULL); + return; + } + } + + success = rf_core_check_rat_overflow(); + + if(was_off) { + NETSTACK_RADIO.off(); + } + } + + if(success) { + /* Retry after half of the interval */ + ctimer_set(&rat_overflow_timer, RAT_OVERFLOW_TIMER_INTERVAL, + rat_overflow_check_timer_cb, NULL); + } else { + /* Retry sooner */ + ctimer_set(&rat_overflow_timer, CLOCK_SECOND, + rat_overflow_check_timer_cb, NULL); + } +} +/*---------------------------------------------------------------------------*/ +uint32_t +rf_core_convert_rat_to_rtimer(uint32_t rat_timestamp) +{ + uint64_t rat_timestamp64; + uint32_t adjusted_overflow_counter; + uint8_t was_off = 0; + + if(primary_mode == NULL) { + PRINTF("rf_core_convert_rat_to_rtimer: not initialized\n"); + return 0; + } + + if(!primary_mode->is_on()) { + was_off = 1; + NETSTACK_RADIO.on(); + } + + rf_core_check_rat_overflow(); + + if(was_off) { + NETSTACK_RADIO.off(); + } + + adjusted_overflow_counter = rat_overflow_counter; + + /* if the timestamp is large and the last oveflow was recently, + assume that the timestamp refers to the time before the overflow */ + if(rat_timestamp > (uint32_t)(RAT_RANGE * 3 / 4)) { + if(RTIMER_CLOCK_LT(RTIMER_NOW(), + rat_last_overflow + RAT_OVERFLOW_PERIOD_SECONDS * RTIMER_SECOND / 4)) { + adjusted_overflow_counter--; + } + } + + /* add the overflowed time to the timestamp */ + rat_timestamp64 = rat_timestamp + RAT_RANGE * adjusted_overflow_counter; + /* correct timestamp so that it refers to the end of the SFD */ + rat_timestamp64 += primary_mode->sfd_timestamp_offset; + + return RADIO_TO_RTIMER(rat_timestamp64 - rat_offset); +} +/*---------------------------------------------------------------------------*/ PROCESS_THREAD(rf_core_process, ev, data) { int len; @@ -575,6 +729,16 @@ cc26xx_rf_cpe1_isr(void) } } + if(HWREG(RFC_DBELL_NONBUF_BASE + RFC_DBELL_O_RFCPEIFG) & IRQ_RX_BUF_FULL) { + PRINTF("\nRF: BUF_FULL\n\n"); + /* set a flag that the buffer is full*/ + rf_core_rx_is_full = true; + /* make sure read_frame() will be called to make space in RX buffer */ + process_poll(&rf_core_process); + /* Clear the IRQ_RX_BUF_FULL interrupt flag by writing zero to bit */ + HWREG(RFC_DBELL_NONBUF_BASE + RFC_DBELL_O_RFCPEIFG) = ~(IRQ_RX_BUF_FULL); + } + /* Clear INTERNAL_ERROR interrupt flag */ HWREG(RFC_DBELL_NONBUF_BASE + RFC_DBELL_O_RFCPEIFG) = 0x7FFFFFFF; } diff --git a/arch/cpu/cc26xx-cc13xx/rf-core/rf-core.h b/arch/cpu/cc26xx-cc13xx/rf-core/rf-core.h index 3264cfc01..6cb65672d 100644 --- a/arch/cpu/cc26xx-cc13xx/rf-core/rf-core.h +++ b/arch/cpu/cc26xx-cc13xx/rf-core/rf-core.h @@ -57,13 +57,6 @@ #include #include /*---------------------------------------------------------------------------*/ -/* The channel to use in IEEE or prop mode. */ -#ifdef RF_CORE_CONF_CHANNEL -#define RF_CORE_CHANNEL RF_CORE_CONF_CHANNEL -#else -#define RF_CORE_CHANNEL 25 -#endif /* RF_CORE_CONF_IEEE_MODE_CHANNEL */ -/*---------------------------------------------------------------------------*/ #define RF_CORE_FRONT_END_MODE_DIFFERENTIAL 0 #define RF_CORE_FRONT_END_MODE_SINGLE_RFP 1 #define RF_CORE_FRONT_END_MODE_SINGLE_RFN 2 @@ -140,6 +133,17 @@ typedef struct rf_core_primary_mode_s { * \return RF_CORE_CMD_OK or RF_CORE_CMD_ERROR */ uint8_t (*restore)(void); + + /** + * \brief A pointer to a function that checks if the radio is on + * \return 1 or 0 + */ + uint8_t (*is_on)(void); + + /** + * \brief Offset of the end of SFD when compared to the radio HW-generated timestamp + */ + int16_t sfd_timestamp_offset; } rf_core_primary_mode_t; /*---------------------------------------------------------------------------*/ /* RF Command status constants - Correspond to values in the CMDSTA register */ @@ -269,10 +273,66 @@ typedef struct rf_core_primary_mode_s { /*---------------------------------------------------------------------------*/ /* Radio timer register */ #define RATCNT 0x00000004 +/*---------------------------------------------------------------------------*/ +/* Special value returned by CMD_IEEE_CCA_REQ when an RSSI is not available */ +#define RF_CORE_CMD_CCA_REQ_RSSI_UNKNOWN -128 + +/* Used for the return value of channel_clear */ +#define RF_CORE_CCA_CLEAR 1 +#define RF_CORE_CCA_BUSY 0 + +/* Used as an error return value for get_cca_info */ +#define RF_CORE_GET_CCA_INFO_ERROR 0xFF + +/* + * Values of the individual bits of the ccaInfo field in CMD_IEEE_CCA_REQ's + * status struct + */ +#define RF_CORE_CMD_CCA_REQ_CCA_STATE_IDLE 0 /* 00 */ +#define RF_CORE_CMD_CCA_REQ_CCA_STATE_BUSY 1 /* 01 */ +#define RF_CORE_CMD_CCA_REQ_CCA_STATE_INVALID 2 /* 10 */ + +#define RF_CORE_CMD_CCA_REQ_CCA_CORR_IDLE (0 << 4) +#define RF_CORE_CMD_CCA_REQ_CCA_CORR_BUSY (1 << 4) +#define RF_CORE_CMD_CCA_REQ_CCA_CORR_INVALID (3 << 4) +#define RF_CORE_CMD_CCA_REQ_CCA_CORR_MASK (3 << 4) + +#define RF_CORE_CMD_CCA_REQ_CCA_SYNC_BUSY (1 << 6) +/*---------------------------------------------------------------------------*/ +#define RF_CORE_RX_BUF_INCLUDE_CRC 0 +#define RF_CORE_RX_BUF_INCLUDE_RSSI 1 +#define RF_CORE_RX_BUF_INCLUDE_CORR 1 +#define RF_CORE_RX_BUF_INCLUDE_TIMESTAMP 1 +/*---------------------------------------------------------------------------*/ +/* How long to wait for an ongoing ACK TX to finish before starting frame TX */ +#define RF_CORE_TX_TIMEOUT (RTIMER_SECOND >> 11) + +/* How long to wait for the RF to enter RX in rf_cmd_ieee_rx */ +#define RF_CORE_ENTER_RX_TIMEOUT (RTIMER_SECOND >> 10) + +/* How long to wait for the RF to react on CMD_ABORT: around 1 msec */ +#define RF_CORE_TURN_OFF_TIMEOUT (RTIMER_SECOND >> 10) + +/* How long to wait for the RF to finish TX of a packet or an ACK */ +#define RF_CORE_TX_FINISH_TIMEOUT (RTIMER_SECOND >> 7) + /*---------------------------------------------------------------------------*/ /* Make the main driver process visible to mode drivers */ PROCESS_NAME(rf_core_process); /*---------------------------------------------------------------------------*/ +/* Buffer full flag */ +extern volatile bool rf_core_rx_is_full; +/*---------------------------------------------------------------------------*/ +/* RSSI of the last read frame */ +extern volatile int8_t rf_core_last_rssi; +/* Correlation/LQI of the last read frame */ +extern volatile uint8_t rf_core_last_corr_lqi; +/* SFD timestamp of the last read frame, in rtimer ticks */ +extern volatile uint32_t rf_core_last_packet_timestamp; +/*---------------------------------------------------------------------------*/ +/* Are we currently in poll mode? */ +extern uint8_t rf_core_poll_mode; +/*---------------------------------------------------------------------------*/ /** * \brief Check whether the RF core is accessible * \retval RF_CORE_ACCESSIBLE The core is powered and ready for access @@ -387,20 +447,19 @@ uint8_t rf_core_boot(void); /** * \brief Setup RF core interrupts */ -void rf_core_setup_interrupts(bool poll_mode); +void rf_core_setup_interrupts(void); /** * \brief Enable interrupt on command done. * \param fg set true to enable irq on foreground command done and false for * background commands or if not in ieee mode. - * \param poll_mode true if the driver is in poll mode * * This is used within TX routines in order to be able to sleep the CM3 and * wake up after TX has finished * * \sa rf_core_cmd_done_dis() */ -void rf_core_cmd_done_en(bool fg, bool poll_mode); +void rf_core_cmd_done_en(bool fg); /** * \brief Disable the LAST_CMD_DONE and LAST_FG_CMD_DONE interrupts. @@ -409,7 +468,7 @@ void rf_core_cmd_done_en(bool fg, bool poll_mode); * * \sa rf_core_cmd_done_en() */ -void rf_core_cmd_done_dis(bool poll_mode); +void rf_core_cmd_done_dis(void); /** * \brief Returns a pointer to the most recent proto-dependent Radio Op @@ -471,6 +530,22 @@ void rf_core_primary_mode_abort(void); * \brief Abort the currently running primary radio op */ uint8_t rf_core_primary_mode_restore(void); + +/** + * \brief Initialize the RAT to RTC conversion machinery + */ +uint8_t rf_core_rat_init(void); + +/** + * \brief Check if RAT overflow has occured and increment the overflow counter if so + */ +uint8_t rf_core_check_rat_overflow(void); + +/** + * \brief Convert from RAT timestamp to rtimer ticks + */ +uint32_t rf_core_convert_rat_to_rtimer(uint32_t rat_timestamp); + /*---------------------------------------------------------------------------*/ #endif /* RF_CORE_H_ */ /*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/cc26xx-cc13xx/ti-lib-rom.h b/arch/cpu/cc26xx-cc13xx/ti-lib-rom.h deleted file mode 100644 index 7334978b9..000000000 --- a/arch/cpu/cc26xx-cc13xx/ti-lib-rom.h +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (c) 2016, Texas Instruments Incorporated - http://www.ti.com/ - * 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. - */ -/*---------------------------------------------------------------------------*/ -/** - * \addtogroup cc26xx-ti-lib - * @{ - * - * \file - * Header file with CC13xxware/CC26xxware ROM API. - */ -/*---------------------------------------------------------------------------*/ -#ifndef TI_LIB_ROM_H_ -#define TI_LIB_ROM_H_ -/*---------------------------------------------------------------------------*/ -/* rom.h */ -#include "driverlib/rom.h" - -/* AON API */ -#define ti_lib_rom_aon_event_mcu_wake_up_set ROM_AONEventMcuWakeUpSet -#define ti_lib_rom_aon_event_mcu_wake_up_get ROM_AONEventMcuWakeUpGet -#define ti_lib_rom_aon_event_aux_wake_up_set ROM_AONEventAuxWakeUpSet -#define ti_lib_rom_aon_event_aux_wake_up_get ROM_AONEventAuxWakeUpGet -#define ti_lib_rom_aon_event_mcu_set ROM_AONEventMcuSet -#define ti_lib_rom_aon_event_mcu_get ROM_AONEventMcuGet - -/* AON_WUC API */ -#define ti_lib_rom_aon_wuc_aux_reset ROM_AONWUCAuxReset -#define ti_lib_rom_aon_wuc_recharge_ctrl_config_set ROM_AONWUCRechargeCtrlConfigSet -#define ti_lib_rom_aon_wuc_osc_config ROM_AONWUCOscConfig - -/* AUX_TDC API */ -#define ti_lib_rom_aux_tdc_config_set ROM_AUXTDCConfigSet -#define ti_lib_rom_aux_tdc_measurement_done ROM_AUXTDCMeasurementDone - -/* AUX_WUC API */ -#define ti_lib_rom_aux_wuc_clock_enable ROM_AUXWUCClockEnable -#define ti_lib_rom_aux_wuc_clock_disable ROM_AUXWUCClockDisable -#define ti_lib_rom_aux_wuc_clock_status ROM_AUXWUCClockStatus -#define ti_lib_rom_aux_wuc_power_ctrl ROM_AUXWUCPowerCtrl - -/* FLASH API */ -#define ti_lib_rom_flash_power_mode_get ROM_FlashPowerModeGet -#define ti_lib_rom_flash_protection_set ROM_FlashProtectionSet -#define ti_lib_rom_flash_protection_get ROM_FlashProtectionGet -#define ti_lib_rom_flash_protection_save ROM_FlashProtectionSave -#define ti_lib_rom_flash_efuse_read_row ROM_FlashEfuseReadRow -#define ti_lib_rom_flash_disable_sectors_for_write ROM_FlashDisableSectorsForWrite - -/* I2C API */ -#define ti_lib_rom_i2c_master_init_exp_clk ROM_I2CMasterInitExpClk -#define ti_lib_rom_i2c_master_err ROM_I2CMasterErr - -/* INTERRUPT API */ -#define ti_lib_rom_int_priority_grouping_set ROM_IntPriorityGroupingSet -#define ti_lib_rom_int_priority_grouping_get ROM_IntPriorityGroupingGet -#define ti_lib_rom_int_priority_set ROM_IntPrioritySet -#define ti_lib_rom_int_priority_get ROM_IntPriorityGet -#define ti_lib_rom_int_enable ROM_IntEnable -#define ti_lib_rom_int_disable ROM_IntDisable -#define ti_lib_rom_int_pend_set ROM_IntPendSet -#define ti_lib_rom_int_pend_get ROM_IntPendGet -#define ti_lib_rom_int_pend_clear ROM_IntPendClear - -/* IOC API */ -#define ti_lib_rom_ioc_port_configure_set ROM_IOCPortConfigureSet -#define ti_lib_rom_ioc_port_configure_get ROM_IOCPortConfigureGet -#define ti_lib_rom_ioc_io_shutdown_set ROM_IOCIOShutdownSet -#define ti_lib_rom_ioc_io_mode_set ROM_IOCIOModeSet -#define ti_lib_rom_ioc_io_int_set ROM_IOCIOIntSet -#define ti_lib_rom_ioc_io_port_pull_set ROM_IOCIOPortPullSet -#define ti_lib_rom_ioc_io_hyst_set ROM_IOCIOHystSet -#define ti_lib_rom_ioc_io_input_set ROM_IOCIOInputSet -#define ti_lib_rom_ioc_io_slew_ctrl_set ROM_IOCIOSlewCtrlSet -#define ti_lib_rom_ioc_io_drv_strength_set ROM_IOCIODrvStrengthSet -#define ti_lib_rom_ioc_io_port_id_set ROM_IOCIOPortIdSet -#define ti_lib_rom_ioc_int_enable ROM_IOCIntEnable -#define ti_lib_rom_ioc_int_disable ROM_IOCIntDisable -#define ti_lib_rom_ioc_pin_type_gpio_input ROM_IOCPinTypeGpioInput -#define ti_lib_rom_ioc_pin_type_gpio_output ROM_IOCPinTypeGpioOutput -#define ti_lib_rom_ioc_pin_type_uart ROM_IOCPinTypeUart -#define ti_lib_rom_ioc_pin_type_ssi_master ROM_IOCPinTypeSsiMaster -#define ti_lib_rom_ioc_pin_type_ssi_slave ROM_IOCPinTypeSsiSlave -#define ti_lib_rom_ioc_pin_type_i2c ROM_IOCPinTypeI2c -#define ti_lib_rom_ioc_pin_type_aux ROM_IOCPinTypeAux - -/* PRCM API */ -#define ti_lib_rom_prcm_inf_clock_configure_set ROM_PRCMInfClockConfigureSet -#define ti_lib_rom_prcm_inf_clock_configure_get ROM_PRCMInfClockConfigureGet -#define ti_lib_rom_prcm_audio_clock_config_set ROM_PRCMAudioClockConfigSet -#define ti_lib_rom_prcm_power_domain_on ROM_PRCMPowerDomainOn -#define ti_lib_rom_prcm_power_domain_off ROM_PRCMPowerDomainOff -#define ti_lib_rom_prcm_peripheral_run_enable ROM_PRCMPeripheralRunEnable -#define ti_lib_rom_prcm_peripheral_run_disable ROM_PRCMPeripheralRunDisable -#define ti_lib_rom_prcm_peripheral_sleep_enable ROM_PRCMPeripheralSleepEnable -#define ti_lib_rom_prcm_peripheral_sleep_disable ROM_PRCMPeripheralSleepDisable -#define ti_lib_rom_prcm_peripheral_deep_sleep_enable ROM_PRCMPeripheralDeepSleepEnable -#define ti_lib_rom_prcm_peripheral_deep_sleep_disable ROM_PRCMPeripheralDeepSleepDisable -#define ti_lib_rom_prcm_power_domain_status ROM_PRCMPowerDomainStatus -#define ti_lib_rom_prcm_deep_sleep ROM_PRCMDeepSleep - -/* SMPH API */ -#define ti_lib_rom_smph_acquire ROM_SMPHAcquire - -/* SSI API */ -#define ti_lib_rom_ssi_config_set_exp_clk ROM_SSIConfigSetExpClk -#define ti_lib_rom_ssi_data_put ROM_SSIDataPut -#define ti_lib_rom_ssi_data_put_non_blocking ROM_SSIDataPutNonBlocking -#define ti_lib_rom_ssi_data_get ROM_SSIDataGet -#define ti_lib_rom_ssi_data_get_non_blocking ROM_SSIDataGetNonBlocking - -/* TIMER API */ -#define ti_lib_rom_timer_configure ROM_TimerConfigure -#define ti_lib_rom_timer_level_control ROM_TimerLevelControl -#define ti_lib_rom_timer_stall_control ROM_TimerStallControl -#define ti_lib_rom_timer_wait_on_trigger_control ROM_TimerWaitOnTriggerControl - -/* TRNG API */ -#define ti_lib_rom_trng_number_get ROM_TRNGNumberGet - -/* UART API */ -#define ti_lib_rom_uart_fifo_level_get ROM_UARTFIFOLevelGet -#define ti_lib_rom_uart_config_set_exp_clk ROM_UARTConfigSetExpClk -#define ti_lib_rom_uart_config_get_exp_clk ROM_UARTConfigGetExpClk -#define ti_lib_rom_uart_disable ROM_UARTDisable -#define ti_lib_rom_uart_char_get_non_blocking ROM_UARTCharGetNonBlocking -#define ti_lib_rom_uart_char_get ROM_UARTCharGet -#define ti_lib_rom_uart_char_put_non_blocking ROM_UARTCharPutNonBlocking -#define ti_lib_rom_uart_char_put ROM_UARTCharPut - -/* UDMA API */ -#define ti_lib_rom_udma_channel_attribute_enable ROM_uDMAChannelAttributeEnable -#define ti_lib_rom_udma_channel_attribute_disable ROM_uDMAChannelAttributeDisable -#define ti_lib_rom_udma_channel_attribute_get ROM_uDMAChannelAttributeGet -#define ti_lib_rom_udma_channel_control_set ROM_uDMAChannelControlSet -#define ti_lib_rom_udma_channel_transfer_set ROM_uDMAChannelTransferSet -#define ti_lib_rom_udma_channel_scatter_gather_set ROM_uDMAChannelScatterGatherSet -#define ti_lib_rom_udma_channel_size_get ROM_uDMAChannelSizeGet -#define ti_lib_rom_udma_channel_mode_get ROM_uDMAChannelModeGet - -/* VIMS API */ -#define ti_lib_rom_vims_configure ROM_VIMSConfigure -#define ti_lib_rom_vims_mode_set ROM_VIMSModeSet - -/* HAPI */ -#define ti_lib_hapi_crc32(a, b, c) HapiCrc32(a, b, c) -#define ti_lib_hapi_get_flash_size() HapiGetFlashSize() -#define ti_lib_hapi_get_chip_id() HapiGetChipId() -#define ti_lib_hapi_sector_erase(a) HapiSectorErase(a) -#define ti_lib_hapi_program_flash(a, b, c) HapiProgramFlash(a, b, c) -#define ti_lib_hapi_reset_device() HapiResetDevice() -#define ti_lib_hapi_fletcher32(a, b, c) HapiFletcher32(a, b, c) -#define ti_lib_hapi_min_value(a, b) HapiMinValue(a,b) -#define ti_lib_hapi_max_value(a, b) HapiMaxValue(a,b) -#define ti_lib_hapi_mean_value(a, b) HapiMeanValue(a,b) -#define ti_lib_hapi_stand_deviation_value(a, b) HapiStandDeviationValue(a,b) -#define ti_lib_hapi_hf_source_safe_switch() HapiHFSourceSafeSwitch() -#define ti_lib_hapi_select_comp_a_input(a) HapiSelectCompAInput(a) -#define ti_lib_hapi_select_comp_a_ref(a) HapiSelectCompARef(a) -#define ti_lib_hapi_select_adc_comp_b_input(a) HapiSelectADCCompBInput(a) -#define ti_lib_hapi_select_comp_b_ref(a) HapiSelectCompBRef(a) -/*---------------------------------------------------------------------------*/ -#endif /* TI_LIB_ROM_H_ */ -/*---------------------------------------------------------------------------*/ -/** - * @} - */ diff --git a/arch/cpu/cc26xx-cc13xx/ti-lib.h b/arch/cpu/cc26xx-cc13xx/ti-lib.h index 3ab5ceb28..d6c7363ee 100644 --- a/arch/cpu/cc26xx-cc13xx/ti-lib.h +++ b/arch/cpu/cc26xx-cc13xx/ti-lib.h @@ -52,9 +52,6 @@ #ifndef TI_LIB_H_ #define TI_LIB_H_ /*---------------------------------------------------------------------------*/ -/* Include ROM API */ -#include "ti-lib-rom.h" -/*---------------------------------------------------------------------------*/ /* aon_batmon.h */ #include "driverlib/aon_batmon.h" @@ -200,8 +197,16 @@ #define ti_lib_chipinfo_get_device_id_hw_rev_code(...) ChipInfo_GetDeviceIdHwRevCode(__VA_ARGS__) #define ti_lib_chipinfo_get_chip_type(...) ChipInfo_GetChipType(__VA_ARGS__) #define ti_lib_chipinfo_get_chip_family(...) ChipInfo_GetChipFamily(__VA_ARGS__) + +#if CPU_FAMILY_CC26X0R2 +#define ti_lib_chipinfo_chip_family_is_cc26xx(...) ChipInfo_ChipFamilyIs_CC26x0(__VA_ARGS__) +#define ti_lib_chipinfo_chip_family_is_cc13xx(...) ChipInfo_ChipFamilyIs_CC13x0(__VA_ARGS__) +#define ti_lib_chipinfo_chip_family_is_cc26x0r2(...) ChipInfo_ChipFamilyIs_CC26x0R2(__VA_ARGS__) +#else #define ti_lib_chipinfo_chip_family_is_cc26xx(...) ChipInfo_ChipFamilyIsCC26xx(__VA_ARGS__) #define ti_lib_chipinfo_chip_family_is_cc13xx(...) ChipInfo_ChipFamilyIsCC13xx(__VA_ARGS__) +#endif /* CPU_FAMILY_CC26X0R2 */ + #define ti_lib_chipinfo_get_hw_revision(...) ChipInfo_GetHwRevision(__VA_ARGS__) #define ti_lib_chipinfo_hw_revision_is_1_0(...) ChipInfo_HwRevisionIs_1_0(__VA_ARGS__) #define ti_lib_chipinfo_hw_revision_is_gteq_2_0(...) ChipInfo_HwRevisionIs_GTEQ_2_0(__VA_ARGS__) @@ -388,14 +393,15 @@ #define ti_lib_pwr_ctrl_source_get(...) PowerCtrlSourceGet(__VA_ARGS__) #define ti_lib_pwr_ctrl_reset_source_get(...) PowerCtrlResetSourceGet(__VA_ARGS__) #define ti_lib_pwr_ctrl_reset_source_clear(...) PowerCtrlResetSourceClear(__VA_ARGS__) -#define ti_lib_pwr_ctrl_io_freeze_enable(...) PowerCtrlIOFreezeEnable(__VA_ARGS__) -#define ti_lib_pwr_ctrl_io_freeze_disable(...) PowerCtrlIOFreezeDisable(__VA_ARGS__) /*---------------------------------------------------------------------------*/ /* rfc.h */ #include "driverlib/rfc.h" #define ti_lib_rfc_rtrim(...) RFCRTrim(__VA_ARGS__) #define ti_lib_rfc_adi3vco_ldo_voltage_mode(...) RFCAdi3VcoLdoVoltageMode(__VA_ARGS__) +#define ti_lib_rfc_hw_int_enable(...) RFCHwIntEnable(__VA_ARGS__) +#define ti_lib_rfc_hw_int_disable(...) RFCHwIntDisable(__VA_ARGS__) +#define ti_lib_rfc_hw_int_clear(...) RFCHwIntClear(__VA_ARGS__) /*---------------------------------------------------------------------------*/ /* sys_ctrl.h */ #include "driverlib/sys_ctrl.h" @@ -408,7 +414,14 @@ #define ti_lib_sys_ctrl_aon_sync(...) SysCtrlAonSync(__VA_ARGS__) #define ti_lib_sys_ctrl_aon_update(...) SysCtrlAonUpdate(__VA_ARGS__) #define ti_lib_sys_ctrl_set_recharge_before_power_down(...) SysCtrlSetRechargeBeforePowerDown(__VA_ARGS__) -#define ti_lib_sys_ctrl_adjust_recharge_after_power_down(...) SysCtrlAdjustRechargeAfterPowerDown(__VA_ARGS__) + +#if CPU_FAMILY_CC26X0R2 +/* May need to change to XOSC_IN_LOW_POWER_MODE */ +#define ti_lib_sys_ctrl_adjust_recharge_after_power_down() SysCtrlAdjustRechargeAfterPowerDown(XOSC_IN_HIGH_POWER_MODE) +#else +#define ti_lib_sys_ctrl_adjust_recharge_after_power_down() SysCtrlAdjustRechargeAfterPowerDown() +#endif /* CPU_FAMILY_CC26X0R2 */ + #define ti_lib_sys_ctrl_dcdc_voltage_conditional_control(...) SysCtrl_DCDC_VoltageConditionalControl(__VA_ARGS__) #define ti_lib_sys_ctrl_reset_source_get(...) SysCtrlResetSourceGet(__VA_ARGS__) #define ti_lib_sys_ctrl_system_reset(...) SysCtrlSystemReset(__VA_ARGS__) diff --git a/arch/cpu/msp430/msp430-def.h b/arch/cpu/msp430/msp430-def.h index e032bb4a0..28b482e9a 100644 --- a/arch/cpu/msp430/msp430-def.h +++ b/arch/cpu/msp430/msp430-def.h @@ -79,6 +79,9 @@ typedef long off_t; /* Our clock resolution, this is the same as Unix HZ. */ #define CLOCK_CONF_SECOND 128UL +/* Use 16-bit rtimer (default in Contiki-NG is 32) */ +#define RTIMER_CONF_CLOCK_SIZE 2 + typedef int spl_t; spl_t splhigh_(void); diff --git a/arch/cpu/msp430/rtimer-arch.h b/arch/cpu/msp430/rtimer-arch.h index 6063292b1..9fd5b46ba 100644 --- a/arch/cpu/msp430/rtimer-arch.h +++ b/arch/cpu/msp430/rtimer-arch.h @@ -42,11 +42,7 @@ #include "sys/rtimer.h" -#ifdef RTIMER_CONF_SECOND -#define RTIMER_ARCH_SECOND RTIMER_CONF_SECOND -#else #define RTIMER_ARCH_SECOND (4096U*8) -#endif /* Do the math in 32bits to save precision. * Round to nearest integer rather than truncate. */ diff --git a/arch/cpu/native/Makefile.native b/arch/cpu/native/Makefile.native index af7328b31..30883622d 100644 --- a/arch/cpu/native/Makefile.native +++ b/arch/cpu/native/Makefile.native @@ -20,8 +20,33 @@ endif CFLAGSNO = -Wall -g -I/usr/local/include $(CFLAGSWERROR) CFLAGS += $(CFLAGSNO) +### Are we building with code size optimisations? +SMALL ?= 0 + +# The optimizations on native platform cannot be enabled in GCC (not Clang) versions less than 7.2 +GCC_IS_CLANG := $(shell gcc --version 2> /dev/null | grep clang) +ifneq ($(GCC_IS_CLANG),) + NATIVE_CAN_OPTIIMIZE = 1 +else + GCC_VERSION := $(shell gcc -dumpfullversion -dumpversion | cut -b1-3) + ifeq ($(shell expr $(GCC_VERSION) \>= 7.2), 1) + NATIVE_CAN_OPTIIMIZE = 1 + else + NATIVE_CAN_OPTIIMIZE = 0 + endif +endif + +ifeq ($(NATIVE_CAN_OPTIIMIZE),1) + ifeq ($(SMALL),1) + CFLAGS += -Os + else + CFLAGS += -O2 + endif +endif + ifeq ($(HOST_OS),Darwin) AROPTS = -rc +LDFLAGS_WERROR := -Wl,-fatal_warnings LDFLAGS += -Wl,-flat_namespace,-map,$(CONTIKI_NG_PROJECT_MAP) CFLAGS += -DHAVE_SNPRINTF=1 -U__ASSERT_USE_STDERR else diff --git a/arch/cpu/native/dev/gpio-hal-arch.c b/arch/cpu/native/dev/gpio-hal-arch.c index 553a23444..366141d77 100644 --- a/arch/cpu/native/dev/gpio-hal-arch.c +++ b/arch/cpu/native/dev/gpio-hal-arch.c @@ -43,6 +43,12 @@ static gpio_hal_pin_cfg_t pin_cfg[GPIO_HAL_PIN_COUNT]; static uint8_t pin_state[GPIO_HAL_PIN_COUNT]; /*---------------------------------------------------------------------------*/ void +gpio_hal_arch_init(void) +{ + /* Do nothing */ +} +/*---------------------------------------------------------------------------*/ +void gpio_hal_arch_interrupt_enable(gpio_hal_pin_t pin) { if(pin >= GPIO_HAL_PIN_COUNT) { diff --git a/arch/cpu/nrf52832/Makefile.nrf52832 b/arch/cpu/nrf52832/Makefile.nrf52832 index 3765484d8..098033ce4 100644 --- a/arch/cpu/nrf52832/Makefile.nrf52832 +++ b/arch/cpu/nrf52832/Makefile.nrf52832 @@ -25,9 +25,9 @@ ifneq ($(NRF52_WITHOUT_SOFTDEVICE),1) NRF52_SOFTDEVICE := $(shell find $(NRF52_SDK_ROOT) -name *iot*_softdevice.hex | head -n 1) endif $(info SoftDevice: $(NRF52_SOFTDEVICE)) - LINKER_SCRIPT := $(CONTIKI_CPU)/ld/nrf52-$(NRF52_DK_REVISION)-sd.ld + LDSCRIPT := $(CONTIKI_CPU)/ld/nrf52-$(NRF52_DK_REVISION)-sd.ld else - LINKER_SCRIPT := $(CONTIKI_CPU)/ld/nrf52.ld + LDSCRIPT := $(CONTIKI_CPU)/ld/nrf52.ld endif OUTPUT_FILENAME := $(CONTIKI_PROJECT) @@ -140,7 +140,7 @@ CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 # keep every function in separate section. This will allow linker to dump unused functions LDFLAGS += -Xlinker -Map=$(CONTIKI_NG_PROJECT_MAP) -LDFLAGS += -mabi=aapcs -L $(TEMPLATE_PATH) -T$(LINKER_SCRIPT) +LDFLAGS += -mabi=aapcs -L $(TEMPLATE_PATH) LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 # let linker to dump unused sections LDFLAGS += -Wl,--gc-sections @@ -172,11 +172,11 @@ vpath %.s $(ASM_PATHS) OBJECTS = $(C_OBJECTS) $(ASM_OBJECTS) -CLEAN += nrf52832.a +NRFLIB = $(BUILD_DIR_BOARD)/nrf52832.a -TARGET_LIBS= nrf52832.a $(NRF52_SDK_ROOT)/components/iot/ble_6lowpan/lib/ble_6lowpan.a +TARGET_LIBS = $(NRFLIB) $(NRF52_SDK_ROOT)/components/iot/ble_6lowpan/lib/ble_6lowpan.a -nrf52832.a: $(OBJECTS) +$(NRFLIB): $(OBJECTS) $(TRACE_AR) $(Q)$(AR) $(AROPTS) $@ $^ diff --git a/arch/cpu/nrf52832/ld/nrf52-pca10036-sd.ld b/arch/cpu/nrf52832/ld/nrf52-pca10036-sd.ld index f3bc5bc43..2afa9e6e2 100644 --- a/arch/cpu/nrf52832/ld/nrf52-pca10036-sd.ld +++ b/arch/cpu/nrf52832/ld/nrf52-pca10036-sd.ld @@ -14,3 +14,5 @@ INCLUDE "nrf5x_common.ld" /* These symbols are used by the stack check library. */ _stack = end; _stack_origin = ORIGIN(RAM) + LENGTH(RAM); +_heap = _stack; +_eheap = _stack_origin; diff --git a/arch/cpu/nrf52832/ld/nrf52-pca10040-sd.ld b/arch/cpu/nrf52832/ld/nrf52-pca10040-sd.ld index 0bc7349e3..b2c747f0a 100644 --- a/arch/cpu/nrf52832/ld/nrf52-pca10040-sd.ld +++ b/arch/cpu/nrf52832/ld/nrf52-pca10040-sd.ld @@ -14,3 +14,5 @@ INCLUDE "nrf5x_common.ld" /* These symbols are used by the stack check library. */ _stack = end; _stack_origin = ORIGIN(RAM) + LENGTH(RAM); +_heap = _stack; +_eheap = _stack_origin; diff --git a/arch/cpu/nrf52832/ld/nrf52.ld b/arch/cpu/nrf52832/ld/nrf52.ld index 87fc9152d..3fead1250 100644 --- a/arch/cpu/nrf52832/ld/nrf52.ld +++ b/arch/cpu/nrf52832/ld/nrf52.ld @@ -14,3 +14,5 @@ INCLUDE "nrf5x_common.ld" /* These symbols are used by the stack check library. */ _stack = end; _stack_origin = ORIGIN(RAM) + LENGTH(RAM); +_heap = _stack; +_eheap = _stack_origin; diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/Makefile.cc13xx-cc26xx b/arch/cpu/simplelink-cc13xx-cc26xx/Makefile.cc13xx-cc26xx new file mode 100644 index 000000000..dfd14637e --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/Makefile.cc13xx-cc26xx @@ -0,0 +1,149 @@ +################################################################################ +### CC13xx/CC26xx CPU makefile + +CC13x2_CC26x2_PRE_RTM ?= 1 + +# Core SDK is placed as a submodule under arch/cpu/cc13xx-cc26xx/lib. +# Do a sanity check that Core SDK submodule has been initialized. +ifndef CORE_SDK + CORE_SDK := $(CONTIKI_CPU)/lib/coresdk_cc13xx_cc26xx + CORE_SDK_INIT := $(shell [ -f $(CORE_SDK)/.git ] && echo 1) + + ifneq ($(CORE_SDK_INIT),1) + $(error The Core SDK submodule is not available. Please run 'git submodule update --init --recursive') + endif +# Note that Core SDK can be overriden with a user-specified SimpleLink SDK. +# As long as the SimpleLink SDK matches the device in use and is of a reasonable +# newer version, then it should be no different than using Core SDK. +else + # Do a sanity check the path exists. + CORE_SDK_VALID := $(shell [ -d $(CORE_SDK) ] && echo 1) + + ifneq ($(CORE_SDK_VALID),1) + $(error User-specified CORE_SDK is not a valid path.) + endif +endif + +################################################################################ +### Device Family + +# CC13x2/CC26x2 has to differentiate both pre-RTM and RTM devices. As of now, +# pre-RTM is suffixed with _v1 while RTM is suffixed with _v2. This will be +# removed when CC13x2/CC26x2 RTMs. For now, provide a switch to choose +# either pre-RTM or RTM. +# Also note that the devices name is cc13x2_cc26x2 for all CC13x2/CC26x2 +# devices, while the library name is individual for each device family. +ifeq ($(SUBFAMILY),cc13x2-cc26x2) + ifeq ($(CC13x2_CC26x2_PRE_RTM),1) + SDK_DEVICES_NAME := cc13x2_cc26x2_v1 + SDK_LIB_NAME := $(DEVICE_FAMILY_LC)_v1 + else + SDK_DEVICES_NAME := cc13x2_cc26x2_v2 + SDK_LIB_NAME := $(DEVICE_FAMILY_LC)_v2 + endif +# CC13x0/CC26x0 does not have this, with both its devices name and library +# name the same as its own device family name. +else + SDK_DEVICES_NAME := $(DEVICE_FAMILY_LC) + SDK_LIB_NAME := $(DEVICE_FAMILY_LC) +endif + +################################################################################ +### CC13xx/CC26xx CPU files + +# Both ccfg-conf.c and startup_cc13xx_cc26xx_gcc.c is located locally in +# the arch/cpu/cc13xx-cc26xx folder. +CPU_START_SOURCEFILES += ccfg-conf.c startup_cc13xx_cc26xx_gcc.c + +# CPU-dependent source files +CONTIKI_CPU_SOURCEFILES += rtimer-arch.c clock-arch.c +CONTIKI_CPU_SOURCEFILES += watchdog-arch.c dbg-arch.c +CONTIKI_CPU_SOURCEFILES += uart0-arch.c slip-arch.c +CONTIKI_CPU_SOURCEFILES += gpio-hal-arch.c int-master-arch.c +CONTIKI_CPU_SOURCEFILES += random.c trng-arch.c +CONTIKI_CPU_SOURCEFILES += spi-arch.c + +# RF source files +CONTIKI_CPU_SOURCEFILES += sched.c data-queue.c +CONTIKI_CPU_SOURCEFILES += ieee-addr.c ble-addr.c +CONTIKI_CPU_SOURCEFILES += ble-beacond.c + +ifeq ($(SUPPORTS_PROP_MODE),1) + CONTIKI_CPU_SOURCEFILES += prop-mode.c prop-settings.c prop-tx-power.c +endif + +ifeq ($(SUPPORTS_IEEE_MODE),1) + CONTIKI_CPU_SOURCEFILES += ieee-mode.c ieee-settings.c ieee-tx-power.c +endif + +ifeq ($(SUPPORTS_BLE_BEACON),1) + CONTIKI_CPU_SOURCEFILES += ble-settings.c ble-tx-power.c +endif + +################################################################################ +### Modules and paths + +# Core SDK paths +SDK_NORTOS := $(CORE_SDK)/kernel/nortos +SDK_SOURCE := $(CORE_SDK)/source +SDK_DRIVERS := $(CORE_SDK)/source/ti/drivers +SDK_DEVICES := $(CORE_SDK)/source/ti/devices/$(SDK_DEVICES_NAME) + +EXTERNALDIRS += $(SDK_SOURCE) $(SDK_NORTOS) + +# CPU-dependent directories +CONTIKI_CPU_DIRS += . dev $(SUBFAMILY) +CONTIKI_CPU_DIRS += rf rf-settings rf-settings/$(DEVICE_FAMILY_LC) + +CONTIKI_SOURCEFILES += $(CONTIKI_CPU_SOURCEFILES) $(DEBUG_IO_SOURCEFILES) + +################################################################################ +### Compiler configuration + +# A weird behaviour of GCC garbage collector has been observed, where +# unitialized global variables with global linkage (aka non-static) put in the +# COMMON section weren't analyzed by the garbage collector at all. No idea why. +# The solution is to disable the common section, which subsequently places all +# unitialized global variables with global linkage in the .bss section, +# allowing the GC to analyze the variables. This is especially an issue with +# Board.h files, as they rely heavily on global variables placed in COMMON to +# be garbage collected if unused. +CFLAGS += -fno-common + +################################################################################ +### Linker configuration + +# Linker flags +LDFLAGS += --entry resetISR +LDFLAGS += --specs=nano.specs +LDFLAGS += -nostartfiles +LDFLAGS += -static + +# Linker script +LDSCRIPT := $(CONTIKI_CPU)/$(SUBFAMILY)/$(SUBFAMILY).lds + +# Globally linked libraries +TARGET_LIBFILES += -lc -lgcc -lnosys -lm + +################################################################################ +### Specialized build targets + +.PHONY: FORCE +FORCE: + +# Always re-build ieee-addr.o in case the command line passes a new NODEID +$(OBJECTDIR)/ieee-addr.o: ieee-addr.c FORCE | $(OBJECTDIR) + $(TRACE_CC) + $(Q)$(CC) $(CFLAGS) -c $< -o $@ + +# Always re-build ccfg-conf.c so any changes to CCFG configuration +# always applies +$(OBJECTDIR)/ccfg-conf.o: ccfg-conf.c FORCE | $(OBJECTDIR) + $(TRACE_CC) + $(Q)$(CC) $(CFLAGS) -c $< -o $@ + +################################################################################ +### Sub-family Makefile + +# Include the Sub-family Makefile specific for the specified device +include $(CONTIKI_CPU)/$(SUBFAMILY)/Makefile.$(SUBFAMILY) diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/Makefile.cc13x0-cc26x0 b/arch/cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/Makefile.cc13x0-cc26x0 new file mode 100644 index 000000000..9aa7c5be2 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/Makefile.cc13x0-cc26x0 @@ -0,0 +1,11 @@ +################################################################################ +### CC13x0/CC26x0 CPU makefile + +# Simplelink SDK pre-compiled libraries +TARGET_LIBFILES += $(SDK_NORTOS)/lib/nortos_$(SDK_LIB_NAME).am3g +TARGET_LIBFILES += $(SDK_DRIVERS)/rf/lib/rf_multiMode_$(SDK_LIB_NAME).am3g +TARGET_LIBFILES += $(SDK_DRIVERS)/lib/drivers_$(SDK_LIB_NAME).am3g +TARGET_LIBFILES += $(SDK_DEVICES)/driverlib/bin/gcc/driverlib.lib + +# CC13x0/CC26x0 is a Cortex-M3 architecture +include $(CONTIKI)/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/cc13x0-cc26x0-cm3.h b/arch/cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/cc13x0-cc26x0-cm3.h new file mode 100644 index 000000000..bda2e2b07 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/cc13x0-cc26x0-cm3.h @@ -0,0 +1,128 @@ +/* + * Template: + * Copyright (c) 2012 ARM LIMITED + * All rights reserved. + * + * CC13xx-CC26xx: + * Copyright (c) 2017, George Oikonomou - http://www.spd.gr + * 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. + */ +/*---------------------------------------------------------------------------*/ +/** + * \addtogroup cc26xx + * @{ + * + * \defgroup cc26xx-cm3 CC13xx/CC26xx CMSIS + * + * CC13xx/CC26xx Cortex-M3 CMSIS definitions + * @{ + * + * \file + * CMSIS Cortex-M3 core peripheral access layer header file for CC13xx/CC26xx + */ +/*---------------------------------------------------------------------------*/ +#ifndef CC13XX_CC26XX_CM3_H_ +#define CC13XX_CC26XX_CM3_H_ +/*---------------------------------------------------------------------------*/ +/** + * \name Interrupt Number Definition + * @{ + */ +typedef enum cc13xx_cc26xx_cm3_irq_e { + /* Cortex-M3 Processor Exceptions */ + CC13XX_CC26XX_CM3_EXCEPTION_RESET = -15, /**< 1 Reset */ + CC13XX_CC26XX_CM3_EXCEPTION_NMI = -14, /**< 2 NMI */ + CC13XX_CC26XX_CM3_EXCEPTION_HARD_FAULT = -13, /**< 3 Hard fault */ + CC13XX_CC26XX_CM3_EXCEPTION_MPU_FAULT = -12, /**< 4 MPU fault */ + CC13XX_CC26XX_CM3_EXCEPTION_BUS_FAULT = -11, /**< 5 Bus fault */ + CC13XX_CC26XX_CM3_EXCEPTION_USAGE_FAULT = -10, /**< 6 Usage fault */ + CC13XX_CC26XX_CM3_EXCEPTION_SV_CALL = -5, /**< 11 SVCall */ + CC13XX_CC26XX_CM3_EXCEPTION_DEBUG_MON = -4, /**< 12 Debug monitor */ + CC13XX_CC26XX_CM3_EXCEPTION_PEND_SV = -2, /**< 14 PendSV */ + CC13XX_CC26XX_CM3_EXCEPTION_SYS_TICK = -1, /**< 15 SysTick */ + + /* CC13xx/CC26xx interrupts */ + CC13XX_CC26XX_CM3_IRQ_EDGE_DETECT = 0, /**< 16 AON edge detect */ + CC13XX_CC26XX_CM3_EXCEPTION_I2C = 1, /**< 17 I2C */ + CC13XX_CC26XX_CM3_EXCEPTION_RF_CPE1 = 2, /**< 18 RF Command and Packet Engine 1 */ + CC13XX_CC26XX_CM3_EXCEPTION_AON_SPI_SLAVE = 3, /**< 19 AON SpiSplave Rx, Tx and CS */ + CC13XX_CC26XX_CM3_EXCEPTION_AON_RTC = 4, /**< 20 AON RTC */ + CC13XX_CC26XX_CM3_EXCEPTION_UART0 = 5, /**< 21 UART0 Rx and Tx */ + CC13XX_CC26XX_CM3_EXCEPTION_AON_AUX_SWEV0 = 6, /**< 22 Sensor Controller software event 0, through AON domain*/ + CC13XX_CC26XX_CM3_EXCEPTION_SSI0 = 7, /**< 23 SSI0 Rx and Tx */ + CC13XX_CC26XX_CM3_EXCEPTION_SSI1 = 8, /**< 24 SSI1 Rx and Tx */ + CC13XX_CC26XX_CM3_EXCEPTION_RF_CPE0 = 9, /**< 25 RF Command and Packet Engine 0 */ + CC13XX_CC26XX_CM3_EXCEPTION_RF_HW = 10, /**< 26 RF Core Hardware */ + CC13XX_CC26XX_CM3_EXCEPTION_RF_CMD_ACK = 11, /**< 27 RF Core Command Acknowledge */ + CC13XX_CC26XX_CM3_EXCEPTION_I2S = 12, /**< 28 I2S */ + CC13XX_CC26XX_CM3_EXCEPTION_AON_AUX_SWEV1 = 13, /**< 29 Sensor Controller software event 1, through AON domain*/ + CC13XX_CC26XX_CM3_EXCEPTION_WATCHDOG = 14, /**< 30 Watchdog timer */ + CC13XX_CC26XX_CM3_EXCEPTION_GPTIMER_0A = 15, /**< 31 Timer 0 subtimer A */ + CC13XX_CC26XX_CM3_EXCEPTION_GPTIMER_0B = 16, /**< 32 Timer 0 subtimer B */ + CC13XX_CC26XX_CM3_EXCEPTION_GPTIMER_1A = 17, /**< 33 Timer 1 subtimer A */ + CC13XX_CC26XX_CM3_EXCEPTION_GPTIMER_1B = 18, /**< 34 Timer 1 subtimer B */ + CC13XX_CC26XX_CM3_EXCEPTION_GPTIMER_2A = 19, /**< 35 Timer 2 subtimer A */ + CC13XX_CC26XX_CM3_EXCEPTION_GPTIMER_2B = 20, /**< 36 Timer 2 subtimer B */ + CC13XX_CC26XX_CM3_EXCEPTION_GPTIMER_3A = 21, /**< 37 Timer 3 subtimer A */ + CC13XX_CC26XX_CM3_EXCEPTION_GPTIMER_3B = 22, /**< 38 Timer 3 subtimer B */ + CC13XX_CC26XX_CM3_EXCEPTION_CRYPTO = 23, /**< 39 Crypto Core Result available */ + CC13XX_CC26XX_CM3_EXCEPTION_UDMA = 24, /**< 40 uDMA Software */ + CC13XX_CC26XX_CM3_EXCEPTION_UDMA_ERR = 25, /**< 41 uDMA Error */ + CC13XX_CC26XX_CM3_EXCEPTION_FLASH_CTRL = 26, /**< 42 Flash controller */ + CC13XX_CC26XX_CM3_EXCEPTION_SW0 = 27, /**< 43 Software Event 0 */ + CC13XX_CC26XX_CM3_EXCEPTION_AUX_COM_EVENT = 28, /**< 44 AUX combined event, directly to MCU domain*/ + CC13XX_CC26XX_CM3_EXCEPTION_AON_PRG0 = 29, /**< 45 AON programmable 0 */ + CC13XX_CC26XX_CM3_EXCEPTION_PROG = 30, /**< 46 Dynamic Programmable interrupt (default source: PRCM)*/ + CC13XX_CC26XX_CM3_EXCEPTION_AUX_COMPA = 31, /**< 47 AUX Comparator A */ + CC13XX_CC26XX_CM3_EXCEPTION_AUX_ADC = 32, /**< 48 AUX ADC IRQ */ + CC13XX_CC26XX_CM3_EXCEPTION_TRNG = 33, /**< 49 TRNG event */ +} cc13xx_cc26xx_cm3_irq_t; + +typedef cc13xx_cc26xx_cm3_irq_t IRQn_Type; + +#define SysTick_IRQn CC13XX_CC26XX_CM3_EXCEPTION_SYS_TICK +/** @} */ +/*---------------------------------------------------------------------------*/ +/** \name Processor and Core Peripheral Section + * @{ + */ +/* Configuration of the Cortex-M3 Processor and Core Peripherals */ +#define __MPU_PRESENT 1 /**< MPU present or not */ +#define __NVIC_PRIO_BITS 3 /**< Number of Bits used for Priority Levels */ +#define __Vendor_SysTickConfig 0 /**< Set to 1 if different SysTick Config is used */ +/** @} */ +/*---------------------------------------------------------------------------*/ +#include "core_cm3.h" /* Cortex-M3 processor and core peripherals */ +/*---------------------------------------------------------------------------*/ +#endif /* CC13XX_CC26XX_CM3_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/cc13x0-cc26x0.icf b/arch/cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/cc13x0-cc26x0.icf new file mode 100644 index 000000000..5dee82c93 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/cc13x0-cc26x0.icf @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +define symbol STACK_SIZE = 0x800; /* 2048 bytes */ +define symbol HEAP_SIZE = 0x100; /* 256 bytes */ + +define symbol __intvec_start__ = 0x00000000; + +/*-Memory Regions-*/ +define symbol ROM_start__ = 0x00000000; +define symbol ROM_end__ = 0x0001FFFF; +define symbol RAM_start__ = 0x20000000; +define symbol RAM_end__ = 0x20004FFF; + +/* Define a memory region that covers the entire 4 GB addressable space */ +define memory mem with size = 4G; + +/* Define a region for the on-chip flash */ +define region FLASH_region = mem:[from ROM_start__ to ROM_end__]; + +/* Define a region for the on-chip SRAM */ +define region RAM_region = mem:[from RAM_start__ to RAM_end__]; + +/* Place the interrupt vectors at the start of flash */ +place at address mem:__intvec_start__ { readonly section .intvec }; +keep { section .intvec }; + +/* Place the CCA area at the end of flash */ +place at end of FLASH_region { readonly section .ccfg }; +keep { section .ccfg }; + +/* Place remaining 'read only' in Flash */ +place in FLASH_region { readonly }; + +/* Place all read/write items into RAM */ +place in RAM_region { readwrite }; +initialize by copy { readwrite }; + +/* + * Define CSTACK block to contain .stack section. This enables the IAR IDE + * to properly show the stack content during debug. Place stack at end of + * retention RAM, do not initialize (initializing the stack will destroy the + * return address from the initialization code, causing the processor to branch + * to zero and fault) + */ +define block CSTACK with alignment = 8, size = STACK_SIZE { section .stack }; +place at end of RAM_region { block CSTACK }; +do not initialize { section .stack, section .noinit }; + +/* Export stack top symbol. Used by startup file */ +define exported symbol STACK_TOP = RAM_end__ + 1; + +/* Primary Heap configuration */ +define block HEAP with alignment = 8, size = HEAP_SIZE { }; + +/* Place heap just before CSTACK */ +place in RAM_region { block HEAP }; diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/cc13x0-cc26x0.lds b/arch/cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/cc13x0-cc26x0.lds new file mode 100644 index 000000000..26930dea8 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/cc13x0-cc26x0.lds @@ -0,0 +1,232 @@ +/* + * Copyright (c) 2017-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +MIN_STACKSIZE = 0x600; /* 1536 bytes */ +HEAPSIZE = 0x100; /* 256 bytes */ + +MEMORY +{ + FLASH (RX) : ORIGIN = 0x00000000, LENGTH = 0x0001ffa8 + /* + * Customer Configuration Area and Bootloader Backdoor configuration in + * flash, 40 bytes + */ + FLASH_CCFG (RX) : ORIGIN = 0x0001ffa8, LENGTH = 0x00000058 + SRAM (RWX) : ORIGIN = 0x20000000, LENGTH = 0x00005000 + GPRAM (RWX) : ORIGIN = 0x11000000, LENGTH = 0x00002000 +} + +REGION_ALIAS("REGION_TEXT", FLASH); +REGION_ALIAS("REGION_BSS", SRAM); +REGION_ALIAS("REGION_DATA", SRAM); +REGION_ALIAS("REGION_STACK", SRAM); +REGION_ALIAS("REGION_HEAP", SRAM); +REGION_ALIAS("REGION_ARM_EXIDX", FLASH); +REGION_ALIAS("REGION_ARM_EXTAB", FLASH); + +SECTIONS { + + PROVIDE (_resetVecs_base_addr = DEFINED(_resetVecs_base_addr) + ? _resetVecs_base_addr + : 0x0); + + .resetVecs (_resetVecs_base_addr) : AT (_resetVecs_base_addr) { + KEEP (*(.resetVecs)) + } > REGION_TEXT + + .ramVecs (NOLOAD) : ALIGN(1024) { + KEEP (*(.ramVecs)) + } > REGION_DATA + + /* + * UDMACC26XX_CONFIG_BASE below must match UDMACC26XX_CONFIG_BASE defined + * by ti/drivers/dma/UDMACC26XX.h + * The user is allowed to change UDMACC26XX_CONFIG_BASE to move it away from + * the default address 0x2000_0400, but remember it must be 1024 bytes aligned. + */ + UDMACC26XX_CONFIG_BASE = 0x20000400; + + /* + * Define absolute addresses for the DMA channels. + * DMA channels must always be allocated at a fixed offset from the DMA base address. + * CTEA := Control Table Entry Address + * --------- DO NOT MODIFY ----------- + */ + DMA_SPI0_RX_CTEA = (UDMACC26XX_CONFIG_BASE + 0x30); + DMA_SPI0_TX_CTEA = (UDMACC26XX_CONFIG_BASE + 0x40); + DMA_ADC_PRI_CTEA = (UDMACC26XX_CONFIG_BASE + 0x70); + DMA_GPT0A_PRI_CTEA = (UDMACC26XX_CONFIG_BASE + 0x90); + DMA_SPI1_RX_CTEA = (UDMACC26XX_CONFIG_BASE + 0x100); + DMA_SPI1_TX_CTEA = (UDMACC26XX_CONFIG_BASE + 0x110); + DMA_ADC_ALT_CTEA = (UDMACC26XX_CONFIG_BASE + 0x270); + DMA_GPT0A_ALT_CTEA = (UDMACC26XX_CONFIG_BASE + 0x290); + + /* + * Allocate SPI0, SPI1, ADC, and GPTimer0 DMA descriptors at absolute addresses. + * --------- DO NOT MODIFY ----------- + */ + UDMACC26XX_dmaSpi0RxControlTableEntry_is_placed = 0; + .dmaSpi0RxControlTableEntry DMA_SPI0_RX_CTEA : AT (DMA_SPI0_RX_CTEA) { + *(.dmaSpi0RxControlTableEntry) + } > REGION_DATA + + UDMACC26XX_dmaSpi0TxControlTableEntry_is_placed = 0; + .dmaSpi0TxControlTableEntry DMA_SPI0_TX_CTEA : AT (DMA_SPI0_TX_CTEA) { + *(.dmaSpi0TxControlTableEntry) + } > REGION_DATA + + UDMACC26XX_dmaADCPriControlTableEntry_is_placed = 0; + .dmaADCPriControlTableEntry DMA_ADC_PRI_CTEA : AT (DMA_ADC_PRI_CTEA) { + *(.dmaADCPriControlTableEntry) + } > REGION_DATA + + UDMACC26XX_dmaGPT0APriControlTableEntry_is_placed = 0; + .dmaGPT0APriControlTableEntry DMA_GPT0A_PRI_CTEA : AT (DMA_GPT0A_PRI_CTEA) { + *(.dmaGPT0APriControlTableEntry) + } > REGION_DATA + + UDMACC26XX_dmaSpi1RxControlTableEntry_is_placed = 0; + .dmaSpi1RxControlTableEntry DMA_SPI1_RX_CTEA : AT (DMA_SPI1_RX_CTEA) { + *(.dmaSpi1RxControlTableEntry) + } > REGION_DATA + + UDMACC26XX_dmaSpi1TxControlTableEntry_is_placed = 0; + .dmaSpi1TxControlTableEntry DMA_SPI1_TX_CTEA : AT (DMA_SPI1_TX_CTEA) { + *(.dmaSpi1TxControlTableEntry) + } > REGION_DATA + + UDMACC26XX_dmaADCAltControlTableEntry_is_placed = 0; + .dmaADCAltControlTableEntry DMA_ADC_ALT_CTEA : AT (DMA_ADC_ALT_CTEA) { + *(.dmaADCAltControlTableEntry) + } > REGION_DATA + + UDMACC26XX_dmaGPT0AAltControlTableEntry_is_placed = 0; + .dmaGPT0AAltControlTableEntry DMA_GPT0A_ALT_CTEA : AT (DMA_GPT0A_ALT_CTEA) { + *(.dmaGPT0AAltControlTableEntry) + } > REGION_DATA + + .text : { + CREATE_OBJECT_SYMBOLS + *(.text) + *(.text.*) + . = ALIGN(0x4); + KEEP (*(.ctors)) + . = ALIGN(0x4); + KEEP (*(.dtors)) + . = ALIGN(0x4); + __init_array_start = .; + KEEP (*(.init_array*)) + __init_array_end = .; + *(.init) + *(.fini*) + } > REGION_TEXT AT> REGION_TEXT + + PROVIDE(__etext = .); + PROVIDE(_etext = .); + PROVIDE(etext = .); + + .rodata : { + *(.rodata) + *(.rodata.*) + } > REGION_TEXT AT> REGION_TEXT + + .data : ALIGN(0x4) { + __data_load__ = LOADADDR(.data); + __data_start__ = .; + *(.data) + *(.data.*) + . = ALIGN (0x4); + __data_end__ = .; + } > REGION_DATA AT> REGION_TEXT + + .ARM.exidx : { + __exidx_start = .; + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + __exidx_end = .; + } > REGION_ARM_EXIDX AT> REGION_ARM_EXIDX + + .ARM.extab : { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > REGION_ARM_EXTAB AT> REGION_ARM_EXTAB + + .nvs (NOLOAD) : ALIGN(0x1000) { + *(.nvs) + } > REGION_TEXT + + .ccfg : { + KEEP(*(.ccfg)) + } > FLASH_CCFG AT> FLASH_CCFG + + .bss : { + __bss_start__ = .; + *(.shbss) + *(.bss) + *(.bss.*) + *(COMMON) + . = ALIGN(0x4); + __bss_end__ = .; + } > REGION_BSS AT> REGION_BSS + + /* Start of heap must be 4 byte aligned */ + .heap (NOLOAD) : ALIGN(0x4) { + PROVIDE(__heap_start__ = .); + PROVIDE(_heap = __heap_start__); + PROVIDE(end = __heap_start__); + PROVIDE(_end = __heap_start__); + PROVIDE(__end = __heap_start__); + + . += HEAPSIZE; + KEEP(*(.heap)) + + PROVIDE(__heap_end__ = .); + PROVIDE(_eheap = __heap_end__); + PROVIDE(__HeapLimit = __heap_end__); + } > REGION_HEAP AT> REGION_HEAP + + PROVIDE(__stack_size = ORIGIN(SRAM) + LENGTH(SRAM) - ALIGN(0x8)); + + /* Start of stack must be 8 byte aligned */ + .stack (NOLOAD) : { + PROVIDE(_stack = ALIGN(0x8)); + PROVIDE(__stack = _stack); + + PROVIDE(_stack_end = ORIGIN(SRAM) + LENGTH(SRAM)); + PROVIDE(__stack_end = _stack_end); + PROVIDE(_stack_origin = _stack_end); + + /* Note that the stack check library requires the symbols */ + /* "_stack" and "_stack_origin" to be defined. */ + + /* Assert that we have enough stack */ + ASSERT(__stack_size >= MIN_STACKSIZE, "Error: No room left for the stack"); + } > REGION_STACK AT> REGION_STACK +} diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/driverlib/rf_ieee_cmd.h b/arch/cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/driverlib/rf_ieee_cmd.h new file mode 100644 index 000000000..c054da400 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/driverlib/rf_ieee_cmd.h @@ -0,0 +1,629 @@ +/****************************************************************************** +* Filename: rf_ieee_cmd.h +* Revised: 2018-01-15 06:15:14 +0100 (Mon, 15 Jan 2018) +* Revision: 18170 +* +* Description: CC13x2/CC26x2 API for IEEE 802.15.4 commands +* +* Copyright (c) 2015 - 2017, Texas Instruments Incorporated +* 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 ORGANIZATION 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 __IEEE_CMD_H +#define __IEEE_CMD_H + +#ifndef __RFC_STRUCT +#define __RFC_STRUCT +#endif + +#ifndef __RFC_STRUCT_ATTR +#if defined(__GNUC__) +#define __RFC_STRUCT_ATTR __attribute__ ((aligned (4))) +#elif defined(__TI_ARM__) +#define __RFC_STRUCT_ATTR __attribute__ ((__packed__,aligned (4))) +#else +#define __RFC_STRUCT_ATTR +#endif +#endif + +//! \addtogroup rfc +//! @{ + +//! \addtogroup ieee_cmd +//! @{ + +#include +#include +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) + +typedef struct __RFC_STRUCT rfc_CMD_IEEE_RX_s rfc_CMD_IEEE_RX_t; +typedef struct __RFC_STRUCT rfc_CMD_IEEE_ED_SCAN_s rfc_CMD_IEEE_ED_SCAN_t; +typedef struct __RFC_STRUCT rfc_CMD_IEEE_TX_s rfc_CMD_IEEE_TX_t; +typedef struct __RFC_STRUCT rfc_CMD_IEEE_CSMA_s rfc_CMD_IEEE_CSMA_t; +typedef struct __RFC_STRUCT rfc_CMD_IEEE_RX_ACK_s rfc_CMD_IEEE_RX_ACK_t; +typedef struct __RFC_STRUCT rfc_CMD_IEEE_ABORT_BG_s rfc_CMD_IEEE_ABORT_BG_t; +typedef struct __RFC_STRUCT rfc_CMD_IEEE_MOD_CCA_s rfc_CMD_IEEE_MOD_CCA_t; +typedef struct __RFC_STRUCT rfc_CMD_IEEE_MOD_FILT_s rfc_CMD_IEEE_MOD_FILT_t; +typedef struct __RFC_STRUCT rfc_CMD_IEEE_MOD_SRC_MATCH_s rfc_CMD_IEEE_MOD_SRC_MATCH_t; +typedef struct __RFC_STRUCT rfc_CMD_IEEE_ABORT_FG_s rfc_CMD_IEEE_ABORT_FG_t; +typedef struct __RFC_STRUCT rfc_CMD_IEEE_STOP_FG_s rfc_CMD_IEEE_STOP_FG_t; +typedef struct __RFC_STRUCT rfc_CMD_IEEE_CCA_REQ_s rfc_CMD_IEEE_CCA_REQ_t; +typedef struct __RFC_STRUCT rfc_ieeeRxOutput_s rfc_ieeeRxOutput_t; +typedef struct __RFC_STRUCT rfc_shortAddrEntry_s rfc_shortAddrEntry_t; +typedef struct __RFC_STRUCT rfc_ieeeRxCorrCrc_s rfc_ieeeRxCorrCrc_t; + +//! \addtogroup CMD_IEEE_RX +//! @{ +#define CMD_IEEE_RX 0x2801 +//! IEEE 802.15.4 Receive Command +struct __RFC_STRUCT rfc_CMD_IEEE_RX_s { + uint16_t commandNo; //!< The command ID number 0x2801 + uint16_t status; //!< \brief An integer telling the status of the command. This value is + //!< updated by the radio CPU during operation and may be read by the + //!< system CPU at any time. + rfc_radioOp_t *pNextOp; //!< Pointer to the next operation to run after this operation is done + ratmr_t startTime; //!< Absolute or relative start time (depending on the value of startTrigger) + struct { + uint8_t triggerType:4; //!< The type of trigger + uint8_t bEnaCmd:1; //!< \brief 0: No alternative trigger command
+ //!< 1: CMD_TRIGGER can be used as an alternative trigger + uint8_t triggerNo:2; //!< The trigger number of the CMD_TRIGGER command that triggers this action + uint8_t pastTrig:1; //!< \brief 0: A trigger in the past is never triggered, or for start of commands, give an error
+ //!< 1: A trigger in the past is triggered as soon as possible + } startTrigger; //!< Identification of the trigger that starts the operation + struct { + uint8_t rule:4; //!< Condition for running next command: Rule for how to proceed + uint8_t nSkip:4; //!< Number of skips + 1 if the rule involves skipping. 0: same, 1: next, 2: skip next, ... + } condition; + uint8_t channel; //!< \brief Channel to tune to in the start of the operation
+ //!< 0: Use existing channel
+ //!< 11--26: Use as IEEE 802.15.4 channel, i.e. frequency is (2405 + 5 × (channel - 11)) MHz
+ //!< 60--207: Frequency is (2300 + channel) MHz
+ //!< Others: Reserved + struct { + uint8_t bAutoFlushCrc:1; //!< If 1, automatically remove packets with CRC error from Rx queue + uint8_t bAutoFlushIgn:1; //!< If 1, automatically remove packets that can be ignored according to frame filtering from Rx queue + uint8_t bIncludePhyHdr:1; //!< If 1, include the received PHY header field in the stored packet; otherwise discard it + uint8_t bIncludeCrc:1; //!< If 1, include the received CRC field in the stored packet; otherwise discard it + uint8_t bAppendRssi:1; //!< If 1, append an RSSI byte to the packet in the Rx queue + uint8_t bAppendCorrCrc:1; //!< If 1, append a correlation value and CRC result byte to the packet in the Rx queue + uint8_t bAppendSrcInd:1; //!< If 1, append an index from the source matching algorithm + uint8_t bAppendTimestamp:1; //!< If 1, append a timestamp to the packet in the Rx queue + } rxConfig; + dataQueue_t* pRxQ; //!< Pointer to receive queue + rfc_ieeeRxOutput_t *pOutput; //!< Pointer to output structure (NULL: Do not store results) + struct { + uint16_t frameFiltEn:1; //!< \brief 0: Disable frame filtering
+ //!< 1: Enable frame filtering + uint16_t frameFiltStop:1; //!< \brief 0: Receive all packets to the end
+ //!< 1: Stop receiving frame once frame filtering has caused the frame to be rejected. + uint16_t autoAckEn:1; //!< \brief 0: Disable auto ACK
+ //!< 1: Enable auto ACK. + uint16_t slottedAckEn:1; //!< \brief 0: Non-slotted ACK
+ //!< 1: Slotted ACK. + uint16_t autoPendEn:1; //!< \brief 0: Auto-pend disabled
+ //!< 1: Auto-pend enabled + uint16_t defaultPend:1; //!< The value of the pending data bit in auto ACK packets that are not subject to auto-pend + uint16_t bPendDataReqOnly:1; //!< \brief 0: Use auto-pend for any packet
+ //!< 1: Use auto-pend for data request packets only + uint16_t bPanCoord:1; //!< \brief 0: Device is not PAN coordinator
+ //!< 1: Device is PAN coordinator + uint16_t maxFrameVersion:2; //!< Reject frames where the frame version field in the FCF is greater than this value + uint16_t fcfReservedMask:3; //!< Value to be AND-ed with the reserved part of the FCF; frame rejected if result is non-zero + uint16_t modifyFtFilter:2; //!< \brief Treatment of MSB of frame type field before frame-type filtering:
+ //!< 0: No modification
+ //!< 1: Invert MSB
+ //!< 2: Set MSB to 0
+ //!< 3: Set MSB to 1 + uint16_t bStrictLenFilter:1; //!< \brief 0: Accept acknowledgement frames of any length >= 5
+ //!< 1: Accept only acknowledgement frames of length 5 + } frameFiltOpt; //!< Frame filtering options + struct { + uint8_t bAcceptFt0Beacon:1; //!< \brief Treatment of frames with frame type 000 (beacon):
+ //!< 0: Reject
+ //!< 1: Accept + uint8_t bAcceptFt1Data:1; //!< \brief Treatment of frames with frame type 001 (data):
+ //!< 0: Reject
+ //!< 1: Accept + uint8_t bAcceptFt2Ack:1; //!< \brief Treatment of frames with frame type 010 (ACK):
+ //!< 0: Reject, unless running ACK receive command
+ //!< 1: Always accept + uint8_t bAcceptFt3MacCmd:1; //!< \brief Treatment of frames with frame type 011 (MAC command):
+ //!< 0: Reject
+ //!< 1: Accept + uint8_t bAcceptFt4Reserved:1; //!< \brief Treatment of frames with frame type 100 (reserved):
+ //!< 0: Reject
+ //!< 1: Accept + uint8_t bAcceptFt5Reserved:1; //!< \brief Treatment of frames with frame type 101 (reserved):
+ //!< 0: Reject
+ //!< 1: Accept + uint8_t bAcceptFt6Reserved:1; //!< \brief Treatment of frames with frame type 110 (reserved):
+ //!< 0: Reject
+ //!< 1: Accept + uint8_t bAcceptFt7Reserved:1; //!< \brief Treatment of frames with frame type 111 (reserved):
+ //!< 0: Reject
+ //!< 1: Accept + } frameTypes; //!< Frame types to receive in frame filtering + struct { + uint8_t ccaEnEnergy:1; //!< Enable energy scan as CCA source + uint8_t ccaEnCorr:1; //!< Enable correlator based carrier sense as CCA source + uint8_t ccaEnSync:1; //!< Enable sync found based carrier sense as CCA source + uint8_t ccaCorrOp:1; //!< \brief Operator to use between energy based and correlator based CCA
+ //!< 0: Report busy channel if either ccaEnergy or ccaCorr are busy
+ //!< 1: Report busy channel if both ccaEnergy and ccaCorr are busy + uint8_t ccaSyncOp:1; //!< \brief Operator to use between sync found based CCA and the others
+ //!< 0: Always report busy channel if ccaSync is busy
+ //!< 1: Always report idle channel if ccaSync is idle + uint8_t ccaCorrThr:2; //!< Threshold for number of correlation peaks in correlator based carrier sense + } ccaOpt; //!< CCA options + int8_t ccaRssiThr; //!< RSSI threshold for CCA + uint8_t __dummy0; + uint8_t numExtEntries; //!< Number of extended address entries + uint8_t numShortEntries; //!< Number of short address entries + uint32_t* pExtEntryList; //!< Pointer to list of extended address entries + uint32_t* pShortEntryList; //!< Pointer to list of short address entries + uint64_t localExtAddr; //!< The extended address of the local device + uint16_t localShortAddr; //!< The short address of the local device + uint16_t localPanID; //!< The PAN ID of the local device + uint16_t __dummy1; + uint8_t __dummy2; + struct { + uint8_t triggerType:4; //!< The type of trigger + uint8_t bEnaCmd:1; //!< \brief 0: No alternative trigger command
+ //!< 1: CMD_TRIGGER can be used as an alternative trigger + uint8_t triggerNo:2; //!< The trigger number of the CMD_TRIGGER command that triggers this action + uint8_t pastTrig:1; //!< \brief 0: A trigger in the past is never triggered, or for start of commands, give an error
+ //!< 1: A trigger in the past is triggered as soon as possible + } endTrigger; //!< Trigger that causes the device to end the Rx operation + ratmr_t endTime; //!< \brief Time used together with endTrigger that causes the device to end the Rx + //!< operation +} __RFC_STRUCT_ATTR; + +//! @} + +//! \addtogroup CMD_IEEE_ED_SCAN +//! @{ +#define CMD_IEEE_ED_SCAN 0x2802 +//! IEEE 802.15.4 Energy Detect Scan Command +struct __RFC_STRUCT rfc_CMD_IEEE_ED_SCAN_s { + uint16_t commandNo; //!< The command ID number 0x2802 + uint16_t status; //!< \brief An integer telling the status of the command. This value is + //!< updated by the radio CPU during operation and may be read by the + //!< system CPU at any time. + rfc_radioOp_t *pNextOp; //!< Pointer to the next operation to run after this operation is done + ratmr_t startTime; //!< Absolute or relative start time (depending on the value of startTrigger) + struct { + uint8_t triggerType:4; //!< The type of trigger + uint8_t bEnaCmd:1; //!< \brief 0: No alternative trigger command
+ //!< 1: CMD_TRIGGER can be used as an alternative trigger + uint8_t triggerNo:2; //!< The trigger number of the CMD_TRIGGER command that triggers this action + uint8_t pastTrig:1; //!< \brief 0: A trigger in the past is never triggered, or for start of commands, give an error
+ //!< 1: A trigger in the past is triggered as soon as possible + } startTrigger; //!< Identification of the trigger that starts the operation + struct { + uint8_t rule:4; //!< Condition for running next command: Rule for how to proceed + uint8_t nSkip:4; //!< Number of skips + 1 if the rule involves skipping. 0: same, 1: next, 2: skip next, ... + } condition; + uint8_t channel; //!< \brief Channel to tune to in the start of the operation
+ //!< 0: Use existing channel
+ //!< 11--26: Use as IEEE 802.15.4 channel, i.e. frequency is (2405 + 5 × (channel - 11)) MHz
+ //!< 60--207: Frequency is (2300 + channel) MHz
+ //!< Others: Reserved + struct { + uint8_t ccaEnEnergy:1; //!< Enable energy scan as CCA source + uint8_t ccaEnCorr:1; //!< Enable correlator based carrier sense as CCA source + uint8_t ccaEnSync:1; //!< Enable sync found based carrier sense as CCA source + uint8_t ccaCorrOp:1; //!< \brief Operator to use between energy based and correlator based CCA
+ //!< 0: Report busy channel if either ccaEnergy or ccaCorr are busy
+ //!< 1: Report busy channel if both ccaEnergy and ccaCorr are busy + uint8_t ccaSyncOp:1; //!< \brief Operator to use between sync found based CCA and the others
+ //!< 0: Always report busy channel if ccaSync is busy
+ //!< 1: Always report idle channel if ccaSync is idle + uint8_t ccaCorrThr:2; //!< Threshold for number of correlation peaks in correlator based carrier sense + } ccaOpt; //!< CCA options + int8_t ccaRssiThr; //!< RSSI threshold for CCA + uint8_t __dummy0; + int8_t maxRssi; //!< The maximum RSSI recorded during the ED scan + struct { + uint8_t triggerType:4; //!< The type of trigger + uint8_t bEnaCmd:1; //!< \brief 0: No alternative trigger command
+ //!< 1: CMD_TRIGGER can be used as an alternative trigger + uint8_t triggerNo:2; //!< The trigger number of the CMD_TRIGGER command that triggers this action + uint8_t pastTrig:1; //!< \brief 0: A trigger in the past is never triggered, or for start of commands, give an error
+ //!< 1: A trigger in the past is triggered as soon as possible + } endTrigger; //!< Trigger that causes the device to end the Rx operation + ratmr_t endTime; //!< \brief Time used together with endTrigger that causes the device to end the Rx + //!< operation +} __RFC_STRUCT_ATTR; + +//! @} + +//! \addtogroup CMD_IEEE_TX +//! @{ +#define CMD_IEEE_TX 0x2C01 +//! IEEE 802.15.4 Transmit Command +struct __RFC_STRUCT rfc_CMD_IEEE_TX_s { + uint16_t commandNo; //!< The command ID number 0x2C01 + uint16_t status; //!< \brief An integer telling the status of the command. This value is + //!< updated by the radio CPU during operation and may be read by the + //!< system CPU at any time. + rfc_radioOp_t *pNextOp; //!< Pointer to the next operation to run after this operation is done + ratmr_t startTime; //!< Absolute or relative start time (depending on the value of startTrigger) + struct { + uint8_t triggerType:4; //!< The type of trigger + uint8_t bEnaCmd:1; //!< \brief 0: No alternative trigger command
+ //!< 1: CMD_TRIGGER can be used as an alternative trigger + uint8_t triggerNo:2; //!< The trigger number of the CMD_TRIGGER command that triggers this action + uint8_t pastTrig:1; //!< \brief 0: A trigger in the past is never triggered, or for start of commands, give an error
+ //!< 1: A trigger in the past is triggered as soon as possible + } startTrigger; //!< Identification of the trigger that starts the operation + struct { + uint8_t rule:4; //!< Condition for running next command: Rule for how to proceed + uint8_t nSkip:4; //!< Number of skips + 1 if the rule involves skipping. 0: same, 1: next, 2: skip next, ... + } condition; + struct { + uint8_t bIncludePhyHdr:1; //!< \brief 0: Find PHY header automatically
+ //!< 1: Insert PHY header from the buffer + uint8_t bIncludeCrc:1; //!< \brief 0: Append automatically calculated CRC
+ //!< 1: Insert FCS (CRC) from the buffer + uint8_t :1; + uint8_t payloadLenMsb:5; //!< \brief Most significant bits of payload length. Should only be non-zero to create long + //!< non-standard packets for test purposes + } txOpt; + uint8_t payloadLen; //!< Number of bytes in the payload + uint8_t* pPayload; //!< Pointer to payload buffer of size payloadLen + ratmr_t timeStamp; //!< Time stamp of transmitted frame +} __RFC_STRUCT_ATTR; + +//! @} + +//! \addtogroup CMD_IEEE_CSMA +//! @{ +#define CMD_IEEE_CSMA 0x2C02 +//! IEEE 802.15.4 CSMA-CA Command +struct __RFC_STRUCT rfc_CMD_IEEE_CSMA_s { + uint16_t commandNo; //!< The command ID number 0x2C02 + uint16_t status; //!< \brief An integer telling the status of the command. This value is + //!< updated by the radio CPU during operation and may be read by the + //!< system CPU at any time. + rfc_radioOp_t *pNextOp; //!< Pointer to the next operation to run after this operation is done + ratmr_t startTime; //!< Absolute or relative start time (depending on the value of startTrigger) + struct { + uint8_t triggerType:4; //!< The type of trigger + uint8_t bEnaCmd:1; //!< \brief 0: No alternative trigger command
+ //!< 1: CMD_TRIGGER can be used as an alternative trigger + uint8_t triggerNo:2; //!< The trigger number of the CMD_TRIGGER command that triggers this action + uint8_t pastTrig:1; //!< \brief 0: A trigger in the past is never triggered, or for start of commands, give an error
+ //!< 1: A trigger in the past is triggered as soon as possible + } startTrigger; //!< Identification of the trigger that starts the operation + struct { + uint8_t rule:4; //!< Condition for running next command: Rule for how to proceed + uint8_t nSkip:4; //!< Number of skips + 1 if the rule involves skipping. 0: same, 1: next, 2: skip next, ... + } condition; + uint16_t randomState; //!< The state of the pseudo-random generator + uint8_t macMaxBE; //!< The IEEE 802.15.4 MAC parameter macMaxBE + uint8_t macMaxCSMABackoffs; //!< The IEEE 802.15.4 MAC parameter macMaxCSMABackoffs + struct { + uint8_t initCW:5; //!< The initialization value for the CW parameter + uint8_t bSlotted:1; //!< \brief 0: non-slotted CSMA
+ //!< 1: slotted CSMA + uint8_t rxOffMode:2; //!< \brief 0: RX stays on during CSMA backoffs
+ //!< 1: The CSMA-CA algorithm will suspend the receiver if no frame is being received
+ //!< 2: The CSMA-CA algorithm will suspend the receiver if no frame is being received, + //!< or after finishing it (including auto ACK) otherwise
+ //!< 3: The CSMA-CA algorithm will suspend the receiver immediately during back-offs + } csmaConfig; + uint8_t NB; //!< The NB parameter from the IEEE 802.15.4 CSMA-CA algorithm + uint8_t BE; //!< The BE parameter from the IEEE 802.15.4 CSMA-CA algorithm + uint8_t remainingPeriods; //!< The number of remaining periods from a paused backoff countdown + int8_t lastRssi; //!< RSSI measured at the last CCA operation + struct { + uint8_t triggerType:4; //!< The type of trigger + uint8_t bEnaCmd:1; //!< \brief 0: No alternative trigger command
+ //!< 1: CMD_TRIGGER can be used as an alternative trigger + uint8_t triggerNo:2; //!< The trigger number of the CMD_TRIGGER command that triggers this action + uint8_t pastTrig:1; //!< \brief 0: A trigger in the past is never triggered, or for start of commands, give an error
+ //!< 1: A trigger in the past is triggered as soon as possible + } endTrigger; //!< Trigger that causes the device to end the CSMA-CA operation + ratmr_t lastTimeStamp; //!< Time of the last CCA operation + ratmr_t endTime; //!< \brief Time used together with endTrigger that causes the device to end the + //!< CSMA-CA operation +} __RFC_STRUCT_ATTR; + +//! @} + +//! \addtogroup CMD_IEEE_RX_ACK +//! @{ +#define CMD_IEEE_RX_ACK 0x2C03 +//! IEEE 802.15.4 Receive Acknowledgement Command +struct __RFC_STRUCT rfc_CMD_IEEE_RX_ACK_s { + uint16_t commandNo; //!< The command ID number 0x2C03 + uint16_t status; //!< \brief An integer telling the status of the command. This value is + //!< updated by the radio CPU during operation and may be read by the + //!< system CPU at any time. + rfc_radioOp_t *pNextOp; //!< Pointer to the next operation to run after this operation is done + ratmr_t startTime; //!< Absolute or relative start time (depending on the value of startTrigger) + struct { + uint8_t triggerType:4; //!< The type of trigger + uint8_t bEnaCmd:1; //!< \brief 0: No alternative trigger command
+ //!< 1: CMD_TRIGGER can be used as an alternative trigger + uint8_t triggerNo:2; //!< The trigger number of the CMD_TRIGGER command that triggers this action + uint8_t pastTrig:1; //!< \brief 0: A trigger in the past is never triggered, or for start of commands, give an error
+ //!< 1: A trigger in the past is triggered as soon as possible + } startTrigger; //!< Identification of the trigger that starts the operation + struct { + uint8_t rule:4; //!< Condition for running next command: Rule for how to proceed + uint8_t nSkip:4; //!< Number of skips + 1 if the rule involves skipping. 0: same, 1: next, 2: skip next, ... + } condition; + uint8_t seqNo; //!< Sequence number to expect + struct { + uint8_t triggerType:4; //!< The type of trigger + uint8_t bEnaCmd:1; //!< \brief 0: No alternative trigger command
+ //!< 1: CMD_TRIGGER can be used as an alternative trigger + uint8_t triggerNo:2; //!< The trigger number of the CMD_TRIGGER command that triggers this action + uint8_t pastTrig:1; //!< \brief 0: A trigger in the past is never triggered, or for start of commands, give an error
+ //!< 1: A trigger in the past is triggered as soon as possible + } endTrigger; //!< Trigger that causes the device to give up acknowledgement reception + ratmr_t endTime; //!< \brief Time used together with endTrigger that causes the device to give up + //!< acknowledgement reception +} __RFC_STRUCT_ATTR; + +//! @} + +//! \addtogroup CMD_IEEE_ABORT_BG +//! @{ +#define CMD_IEEE_ABORT_BG 0x2C04 +//! IEEE 802.15.4 Abort Background Level Command +struct __RFC_STRUCT rfc_CMD_IEEE_ABORT_BG_s { + uint16_t commandNo; //!< The command ID number 0x2C04 + uint16_t status; //!< \brief An integer telling the status of the command. This value is + //!< updated by the radio CPU during operation and may be read by the + //!< system CPU at any time. + rfc_radioOp_t *pNextOp; //!< Pointer to the next operation to run after this operation is done + ratmr_t startTime; //!< Absolute or relative start time (depending on the value of startTrigger) + struct { + uint8_t triggerType:4; //!< The type of trigger + uint8_t bEnaCmd:1; //!< \brief 0: No alternative trigger command
+ //!< 1: CMD_TRIGGER can be used as an alternative trigger + uint8_t triggerNo:2; //!< The trigger number of the CMD_TRIGGER command that triggers this action + uint8_t pastTrig:1; //!< \brief 0: A trigger in the past is never triggered, or for start of commands, give an error
+ //!< 1: A trigger in the past is triggered as soon as possible + } startTrigger; //!< Identification of the trigger that starts the operation + struct { + uint8_t rule:4; //!< Condition for running next command: Rule for how to proceed + uint8_t nSkip:4; //!< Number of skips + 1 if the rule involves skipping. 0: same, 1: next, 2: skip next, ... + } condition; +} __RFC_STRUCT_ATTR; + +//! @} + +//! \addtogroup CMD_IEEE_MOD_CCA +//! @{ +#define CMD_IEEE_MOD_CCA 0x2001 +//! IEEE 802.15.4 Modify CCA Parameter Command +struct __RFC_STRUCT rfc_CMD_IEEE_MOD_CCA_s { + uint16_t commandNo; //!< The command ID number 0x2001 + struct { + uint8_t ccaEnEnergy:1; //!< Enable energy scan as CCA source + uint8_t ccaEnCorr:1; //!< Enable correlator based carrier sense as CCA source + uint8_t ccaEnSync:1; //!< Enable sync found based carrier sense as CCA source + uint8_t ccaCorrOp:1; //!< \brief Operator to use between energy based and correlator based CCA
+ //!< 0: Report busy channel if either ccaEnergy or ccaCorr are busy
+ //!< 1: Report busy channel if both ccaEnergy and ccaCorr are busy + uint8_t ccaSyncOp:1; //!< \brief Operator to use between sync found based CCA and the others
+ //!< 0: Always report busy channel if ccaSync is busy
+ //!< 1: Always report idle channel if ccaSync is idle + uint8_t ccaCorrThr:2; //!< Threshold for number of correlation peaks in correlator based carrier sense + } newCcaOpt; //!< New value of ccaOpt for the running background level operation + int8_t newCcaRssiThr; //!< New value of ccaRssiThr for the running background level operation +} __RFC_STRUCT_ATTR; + +//! @} + +//! \addtogroup CMD_IEEE_MOD_FILT +//! @{ +#define CMD_IEEE_MOD_FILT 0x2002 +//! IEEE 802.15.4 Modify Frame Filtering Parameter Command +struct __RFC_STRUCT rfc_CMD_IEEE_MOD_FILT_s { + uint16_t commandNo; //!< The command ID number 0x2002 + struct { + uint16_t frameFiltEn:1; //!< \brief 0: Disable frame filtering
+ //!< 1: Enable frame filtering + uint16_t frameFiltStop:1; //!< \brief 0: Receive all packets to the end
+ //!< 1: Stop receiving frame once frame filtering has caused the frame to be rejected. + uint16_t autoAckEn:1; //!< \brief 0: Disable auto ACK
+ //!< 1: Enable auto ACK. + uint16_t slottedAckEn:1; //!< \brief 0: Non-slotted ACK
+ //!< 1: Slotted ACK. + uint16_t autoPendEn:1; //!< \brief 0: Auto-pend disabled
+ //!< 1: Auto-pend enabled + uint16_t defaultPend:1; //!< The value of the pending data bit in auto ACK packets that are not subject to auto-pend + uint16_t bPendDataReqOnly:1; //!< \brief 0: Use auto-pend for any packet
+ //!< 1: Use auto-pend for data request packets only + uint16_t bPanCoord:1; //!< \brief 0: Device is not PAN coordinator
+ //!< 1: Device is PAN coordinator + uint16_t maxFrameVersion:2; //!< Reject frames where the frame version field in the FCF is greater than this value + uint16_t fcfReservedMask:3; //!< Value to be AND-ed with the reserved part of the FCF; frame rejected if result is non-zero + uint16_t modifyFtFilter:2; //!< \brief Treatment of MSB of frame type field before frame-type filtering:
+ //!< 0: No modification
+ //!< 1: Invert MSB
+ //!< 2: Set MSB to 0
+ //!< 3: Set MSB to 1 + uint16_t bStrictLenFilter:1; //!< \brief 0: Accept acknowledgement frames of any length >= 5
+ //!< 1: Accept only acknowledgement frames of length 5 + } newFrameFiltOpt; //!< New value of frameFiltOpt for the running background level operation + struct { + uint8_t bAcceptFt0Beacon:1; //!< \brief Treatment of frames with frame type 000 (beacon):
+ //!< 0: Reject
+ //!< 1: Accept + uint8_t bAcceptFt1Data:1; //!< \brief Treatment of frames with frame type 001 (data):
+ //!< 0: Reject
+ //!< 1: Accept + uint8_t bAcceptFt2Ack:1; //!< \brief Treatment of frames with frame type 010 (ACK):
+ //!< 0: Reject, unless running ACK receive command
+ //!< 1: Always accept + uint8_t bAcceptFt3MacCmd:1; //!< \brief Treatment of frames with frame type 011 (MAC command):
+ //!< 0: Reject
+ //!< 1: Accept + uint8_t bAcceptFt4Reserved:1; //!< \brief Treatment of frames with frame type 100 (reserved):
+ //!< 0: Reject
+ //!< 1: Accept + uint8_t bAcceptFt5Reserved:1; //!< \brief Treatment of frames with frame type 101 (reserved):
+ //!< 0: Reject
+ //!< 1: Accept + uint8_t bAcceptFt6Reserved:1; //!< \brief Treatment of frames with frame type 110 (reserved):
+ //!< 0: Reject
+ //!< 1: Accept + uint8_t bAcceptFt7Reserved:1; //!< \brief Treatment of frames with frame type 111 (reserved):
+ //!< 0: Reject
+ //!< 1: Accept + } newFrameTypes; //!< New value of frameTypes for the running background level operation +} __RFC_STRUCT_ATTR; + +//! @} + +//! \addtogroup CMD_IEEE_MOD_SRC_MATCH +//! @{ +#define CMD_IEEE_MOD_SRC_MATCH 0x2003 +//! IEEE 802.15.4 Enable/Disable Source Matching Entry Command +struct __RFC_STRUCT rfc_CMD_IEEE_MOD_SRC_MATCH_s { + uint16_t commandNo; //!< The command ID number 0x2003 + struct { + uint8_t bEnable:1; //!< \brief 0: Disable entry
+ //!< 1: Enable entry + uint8_t srcPend:1; //!< New value of the pending bit for the entry + uint8_t entryType:1; //!< \brief 0: Short address
+ //!< 1: Extended address + } options; + uint8_t entryNo; //!< Index of entry to enable or disable +} __RFC_STRUCT_ATTR; + +//! @} + +//! \addtogroup CMD_IEEE_ABORT_FG +//! @{ +#define CMD_IEEE_ABORT_FG 0x2401 +//! IEEE 802.15.4 Abort Foreground Level Command +struct __RFC_STRUCT rfc_CMD_IEEE_ABORT_FG_s { + uint16_t commandNo; //!< The command ID number 0x2401 +} __RFC_STRUCT_ATTR; + +//! @} + +//! \addtogroup CMD_IEEE_STOP_FG +//! @{ +#define CMD_IEEE_STOP_FG 0x2402 +//! IEEE 802.15.4 Gracefully Stop Foreground Level Command +struct __RFC_STRUCT rfc_CMD_IEEE_STOP_FG_s { + uint16_t commandNo; //!< The command ID number 0x2402 +} __RFC_STRUCT_ATTR; + +//! @} + +//! \addtogroup CMD_IEEE_CCA_REQ +//! @{ +#define CMD_IEEE_CCA_REQ 0x2403 +//! IEEE 802.15.4 CCA and RSSI Information Request Command +struct __RFC_STRUCT rfc_CMD_IEEE_CCA_REQ_s { + uint16_t commandNo; //!< The command ID number 0x2403 + int8_t currentRssi; //!< The RSSI currently observed on the channel + int8_t maxRssi; //!< The maximum RSSI observed on the channel since Rx was started + struct { + uint8_t ccaState:2; //!< \brief Value of the current CCA state
+ //!< 0: Idle
+ //!< 1: Busy
+ //!< 2: Invalid + uint8_t ccaEnergy:2; //!< \brief Value of the current energy detect CCA state
+ //!< 0: Idle
+ //!< 1: Busy
+ //!< 2: Invalid + uint8_t ccaCorr:2; //!< \brief Value of the current correlator based carrier sense CCA state
+ //!< 0: Idle
+ //!< 1: Busy
+ //!< 2: Invalid + uint8_t ccaSync:1; //!< \brief Value of the current sync found based carrier sense CCA state
+ //!< 0: Idle
+ //!< 1: Busy + } ccaInfo; +} __RFC_STRUCT_ATTR; + +//! @} + +//! \addtogroup ieeeRxOutput +//! @{ +//! Output structure for CMD_IEEE_RX + +struct __RFC_STRUCT rfc_ieeeRxOutput_s { + uint8_t nTxAck; //!< Total number of transmitted ACK frames + uint8_t nRxBeacon; //!< Number of received beacon frames + uint8_t nRxData; //!< Number of received data frames + uint8_t nRxAck; //!< Number of received acknowledgement frames + uint8_t nRxMacCmd; //!< Number of received MAC command frames + uint8_t nRxReserved; //!< Number of received frames with reserved frame type + uint8_t nRxNok; //!< Number of received frames with CRC error + uint8_t nRxIgnored; //!< Number of frames received that are to be ignored + uint8_t nRxBufFull; //!< Number of received frames discarded because the Rx buffer was full + int8_t lastRssi; //!< RSSI of last received frame + int8_t maxRssi; //!< Highest RSSI observed in the operation + uint8_t __dummy0; + ratmr_t beaconTimeStamp; //!< Time stamp of last received beacon frame +} __RFC_STRUCT_ATTR; + +//! @} + +//! \addtogroup shortAddrEntry +//! @{ +//! Structure for short address entries + +struct __RFC_STRUCT rfc_shortAddrEntry_s { + uint16_t shortAddr; //!< Short address + uint16_t panId; //!< PAN ID +} __RFC_STRUCT_ATTR; + +//! @} + +//! \addtogroup ieeeRxCorrCrc +//! @{ +//! Receive status byte that may be appended to message in receive buffer + +struct __RFC_STRUCT rfc_ieeeRxCorrCrc_s { + struct { + uint8_t corr:6; //!< The correlation value + uint8_t bIgnore:1; //!< 1 if the packet should be rejected by frame filtering, 0 otherwise + uint8_t bCrcErr:1; //!< 1 if the packet was received with CRC error, 0 otherwise + } status; +} __RFC_STRUCT_ATTR; + +//! @} + +//! @} +//! @} +#endif diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/driverlib/rf_ieee_mailbox.h b/arch/cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/driverlib/rf_ieee_mailbox.h new file mode 100644 index 000000000..fce171ff7 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/driverlib/rf_ieee_mailbox.h @@ -0,0 +1,74 @@ +/****************************************************************************** +* Filename: rf_ieee_mailbox.h +* Revised: 2018-01-23 19:51:42 +0100 (Tue, 23 Jan 2018) +* Revision: 18189 +* +* Description: Definitions for IEEE 802.15.4 interface +* +* Copyright (c) 2015 - 2017, Texas Instruments Incorporated +* 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 ORGANIZATION 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 _IEEE_MAILBOX_H +#define _IEEE_MAILBOX_H + +#include +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) + +/// \name Radio operation status +///@{ +/// \name Operation not finished +///@{ +#define IEEE_SUSPENDED 0x2001 ///< Operation suspended +///@} +/// \name Operation finished normally +///@{ +#define IEEE_DONE_OK 0x2400 ///< Operation ended normally +#define IEEE_DONE_BUSY 0x2401 ///< CSMA-CA operation ended with failure +#define IEEE_DONE_STOPPED 0x2402 ///< Operation stopped after stop command +#define IEEE_DONE_ACK 0x2403 ///< ACK packet received with pending data bit cleared +#define IEEE_DONE_ACKPEND 0x2404 ///< ACK packet received with pending data bit set +#define IEEE_DONE_TIMEOUT 0x2405 ///< Operation ended due to timeout +#define IEEE_DONE_BGEND 0x2406 ///< FG operation ended because necessary background level + ///< operation ended +#define IEEE_DONE_ABORT 0x2407 ///< Operation aborted by command +///@} +/// \name Operation finished with error +///@{ +#define IEEE_ERROR_PAR 0x2800 ///< Illegal parameter +#define IEEE_ERROR_NO_SETUP 0x2801 ///< Operation using Rx or Tx attempted when not in 15.4 mode +#define IEEE_ERROR_NO_FS 0x2802 ///< Operation using Rx or Tx attempted without frequency synth configured +#define IEEE_ERROR_SYNTH_PROG 0x2803 ///< Synthesizer programming failed to complete on time +#define IEEE_ERROR_RXOVF 0x2804 ///< Receiver overflowed during operation +#define IEEE_ERROR_TXUNF 0x2805 ///< Transmitter underflowed during operation +///@} +///@} + +#endif diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/rf_patches/rf_patch_cpe_ieee.h b/arch/cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/rf_patches/rf_patch_cpe_ieee.h new file mode 100644 index 000000000..f3089f061 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/rf_patches/rf_patch_cpe_ieee.h @@ -0,0 +1,269 @@ +/****************************************************************************** +* Filename: rf_patch_cpe_ieee.h +* Revised: $Date$ +* Revision: $Revision$ +* +* Description: RF Core patch file for CC26xx IEEE 802.15.4 PHY +* +* Copyright (c) 2015, Texas Instruments Incorporated +* 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 ORGANIZATION 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 _RF_PATCH_CPE_IEEE_H +#define _RF_PATCH_CPE_IEEE_H + +//***************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//***************************************************************************** +#ifdef __cplusplus +extern "C" +{ +#endif + +#include +#include + +#ifndef CPE_PATCH_TYPE +#define CPE_PATCH_TYPE static const uint32_t +#endif + +#ifndef SYS_PATCH_TYPE +#define SYS_PATCH_TYPE static const uint32_t +#endif + +#ifndef PATCH_FUN_SPEC +#define PATCH_FUN_SPEC static inline +#endif + +#ifndef _APPLY_PATCH_TAB +#define _APPLY_PATCH_TAB +#endif + + +CPE_PATCH_TYPE patchImageIeee[] = { + 0x210004ef, + 0x21000419, + 0x21000519, + 0x21000599, + 0x210004b1, + 0x22024823, + 0x421a7dc3, + 0xd0034472, + 0x1dc04678, + 0xb5f84686, + 0x4c1f4710, + 0x200834ae, + 0x490347a0, + 0x60082008, + 0x3cec6008, + 0xbdf847a0, + 0x40045004, + 0x4c17b5f0, + 0x18612140, + 0x280278c8, + 0x4809d005, + 0x60012100, + 0x47884908, + 0x6e25bdf0, + 0x60354e07, + 0x43280760, + 0x68276620, + 0x480e6024, + 0x60274780, + 0xbdf06035, + 0x4004112c, + 0x000065a5, + 0x40044028, + 0x4c07b510, + 0x29007da1, + 0x2101d105, + 0x024875a1, + 0x393e4904, + 0x68204788, + 0xd0002800, + 0xbd104780, + 0x21000254, + 0x0000398b, + 0x6a034807, + 0x46784907, + 0x46861dc0, + 0x4788b5f8, + 0x009b089b, + 0x6a014802, + 0xd10007c9, + 0xbdf86203, + 0x40045040, + 0x0000f1ab, + 0x6a00480b, + 0xd00407c0, + 0x2201480a, + 0x43117801, + 0x48097001, + 0x72c84700, + 0xd006280d, + 0x00802285, + 0x18800252, + 0x60486840, + 0x48044770, + 0x0000e7fb, + 0x40045040, + 0x21000268, + 0x0000ff39, + 0x210004d9, + 0x4e1ab5f8, + 0x6b314605, + 0x09cc4819, + 0x2d0001e4, + 0x4918d011, + 0x29027809, + 0x7b00d00f, + 0xb6724304, + 0x4f152001, + 0x47b80240, + 0x38204811, + 0x09c18800, + 0xd00407c9, + 0x7ac0e016, + 0x7b40e7f0, + 0x490fe7ee, + 0x61cc6334, + 0x07c00a40, + 0x2001d00c, + 0x6af10380, + 0xd0012d00, + 0xe0004301, + 0x46084381, + 0x490762f1, + 0x63483940, + 0x47b82000, + 0xbdf8b662, + 0x21000280, + 0x21000088, + 0x21000296, + 0x00003cdf, + 0x40044040, + 0x28004907, + 0x2004d000, + 0xb6724a06, + 0x07c97809, + 0x5810d001, + 0x2080e000, + 0xb240b662, + 0x00004770, + 0x2100026b, + 0x40046058, +}; +#define _NWORD_PATCHIMAGE_IEEE 111 + +#define _NWORD_PATCHSYS_IEEE 0 + +#define _IRQ_PATCH_0 0x21000449 +#define _IRQ_PATCH_1 0x21000489 + + +#ifndef _IEEE_SYSRAM_START +#define _IEEE_SYSRAM_START 0x20000000 +#endif + +#ifndef _IEEE_CPERAM_START +#define _IEEE_CPERAM_START 0x21000000 +#endif + +#define _IEEE_SYS_PATCH_FIXED_ADDR 0x20000000 + +#define _IEEE_PARSER_PATCH_TAB_OFFSET 0x0334 +#define _IEEE_PATCH_TAB_OFFSET 0x033C +#define _IEEE_IRQPATCH_OFFSET 0x03AC +#define _IEEE_PATCH_VEC_OFFSET 0x0404 + +PATCH_FUN_SPEC void enterIeeeCpePatch(void) +{ + uint32_t *pPatchVec = (uint32_t *) (_IEEE_CPERAM_START + _IEEE_PATCH_VEC_OFFSET); + +#if (_NWORD_PATCHIMAGE_IEEE > 0) + memcpy(pPatchVec, patchImageIeee, sizeof(patchImageIeee)); +#endif +} + +PATCH_FUN_SPEC void enterIeeeSysPatch(void) +{ +} + +PATCH_FUN_SPEC void configureIeeePatch(void) +{ + uint8_t *pPatchTab = (uint8_t *) (_IEEE_CPERAM_START + _IEEE_PATCH_TAB_OFFSET); + uint32_t *pIrqPatch = (uint32_t *) (_IEEE_CPERAM_START + _IEEE_IRQPATCH_OFFSET); + + + pPatchTab[5] = 0; + pPatchTab[52] = 1; + pPatchTab[103] = 2; + pPatchTab[60] = 3; + pPatchTab[38] = 4; + + pIrqPatch[1] = _IRQ_PATCH_0; + pIrqPatch[9] = _IRQ_PATCH_1; +} + +PATCH_FUN_SPEC void applyIeeePatch(void) +{ + enterIeeeSysPatch(); + enterIeeeCpePatch(); + configureIeeePatch(); +} + +PATCH_FUN_SPEC void refreshIeeePatch(void) +{ + enterIeeeCpePatch(); + configureIeeePatch(); +} + +PATCH_FUN_SPEC void rf_patch_cpe_ieee(void) +{ + applyIeeePatch(); +} + +#undef _IRQ_PATCH_0 +#undef _IRQ_PATCH_1 + +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** +#ifdef __cplusplus +} +#endif + +#endif // _RF_PATCH_CPE_IEEE_H + diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/cc13x2-cc26x2/Makefile.cc13x2-cc26x2 b/arch/cpu/simplelink-cc13xx-cc26xx/cc13x2-cc26x2/Makefile.cc13x2-cc26x2 new file mode 100644 index 000000000..52333f47d --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/cc13x2-cc26x2/Makefile.cc13x2-cc26x2 @@ -0,0 +1,11 @@ +################################################################################ +### CC13x2/CC26x2 CPU makefile + +# Simplelink SDK pre-compiled libraries +TARGET_LIBFILES += $(SDK_NORTOS)/lib/nortos_$(SDK_LIB_NAME).am4fg +TARGET_LIBFILES += $(SDK_DRIVERS)/rf/lib/rf_multiMode_$(SDK_LIB_NAME).am4fg +TARGET_LIBFILES += $(SDK_DRIVERS)/lib/drivers_$(SDK_LIB_NAME).am4fg +TARGET_LIBFILES += $(SDK_DEVICES)/driverlib/bin/gcc/driverlib.lib + +# CC13x2/CC26x2 is a Cortex-M4 architecture +include $(CONTIKI)/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/cc13x2-cc26x2/cc13x2-cc26x2-cm4.h b/arch/cpu/simplelink-cc13xx-cc26xx/cc13x2-cc26x2/cc13x2-cc26x2-cm4.h new file mode 100644 index 000000000..6a9bc65f4 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/cc13x2-cc26x2/cc13x2-cc26x2-cm4.h @@ -0,0 +1,128 @@ +/* + * Template: + * Copyright (c) 2012 ARM LIMITED + * All rights reserved. + * + * CC13xx-CC26xx: + * Copyright (c) 2017, George Oikonomou - http://www.spd.gr + * 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. + */ +/*---------------------------------------------------------------------------*/ +/** + * \addtogroup cc26xx + * @{ + * + * \defgroup cc26xx-cm4 CC13xx/CC26xx CMSIS + * + * CC13xx/CC26xx Cortex-M4 CMSIS definitions + * @{ + * + * \file + * CMSIS Cortex-M4 core peripheral access layer header file for CC13xx/CC26xx + */ +/*---------------------------------------------------------------------------*/ +#ifndef CC13XX_CC26XX_CM4_H_ +#define CC13XX_CC26XX_CM4_H_ +/*---------------------------------------------------------------------------*/ +/** + * \name Interrupt Number Definition + * @{ + */ +typedef enum cc13xx_cc26xx_cm4_irq_e { + /* Cortex-M4 Processor Exceptions */ + CC13XX_CC26XX_CM4_EXCEPTION_RESET = -15, /**< 1 Reset */ + CC13XX_CC26XX_CM4_EXCEPTION_NMI = -14, /**< 2 NMI */ + CC13XX_CC26XX_CM4_EXCEPTION_HARD_FAULT = -13, /**< 3 Hard fault */ + CC13XX_CC26XX_CM4_EXCEPTION_MPU_FAULT = -12, /**< 4 MPU fault */ + CC13XX_CC26XX_CM4_EXCEPTION_BUS_FAULT = -11, /**< 5 Bus fault */ + CC13XX_CC26XX_CM4_EXCEPTION_USAGE_FAULT = -10, /**< 6 Usage fault */ + CC13XX_CC26XX_CM4_EXCEPTION_SV_CALL = -5, /**< 11 SVCall */ + CC13XX_CC26XX_CM4_EXCEPTION_DEBUG_MON = -4, /**< 12 Debug monitor */ + CC13XX_CC26XX_CM4_EXCEPTION_PEND_SV = -2, /**< 14 PendSV */ + CC13XX_CC26XX_CM4_EXCEPTION_SYS_TICK = -1, /**< 15 SysTick */ + + /* CC13xx/CC26xx interrupts */ + CC13XX_CC26XX_CM4_IRQ_EDGE_DETECT = 0, /**< 16 AON edge detect */ + CC13XX_CC26XX_CM4_EXCEPTION_I2C = 1, /**< 17 I2C */ + CC13XX_CC26XX_CM4_EXCEPTION_RF_CPE1 = 2, /**< 18 RF Command and Packet Engine 1 */ + CC13XX_CC26XX_CM4_EXCEPTION_AON_SPI_SLAVE = 3, /**< 19 AON SpiSplave Rx, Tx and CS */ + CC13XX_CC26XX_CM4_EXCEPTION_AON_RTC = 4, /**< 20 AON RTC */ + CC13XX_CC26XX_CM4_EXCEPTION_UART0 = 5, /**< 21 UART0 Rx and Tx */ + CC13XX_CC26XX_CM4_EXCEPTION_AON_AUX_SWEV0 = 6, /**< 22 Sensor Controller software event 0, through AON domain*/ + CC13XX_CC26XX_CM4_EXCEPTION_SSI0 = 7, /**< 23 SSI0 Rx and Tx */ + CC13XX_CC26XX_CM4_EXCEPTION_SSI1 = 8, /**< 24 SSI1 Rx and Tx */ + CC13XX_CC26XX_CM4_EXCEPTION_RF_CPE0 = 9, /**< 25 RF Command and Packet Engine 0 */ + CC13XX_CC26XX_CM4_EXCEPTION_RF_HW = 10, /**< 26 RF Core Hardware */ + CC13XX_CC26XX_CM4_EXCEPTION_RF_CMD_ACK = 11, /**< 27 RF Core Command Acknowledge */ + CC13XX_CC26XX_CM4_EXCEPTION_I2S = 12, /**< 28 I2S */ + CC13XX_CC26XX_CM4_EXCEPTION_AON_AUX_SWEV1 = 13, /**< 29 Sensor Controller software event 1, through AON domain*/ + CC13XX_CC26XX_CM4_EXCEPTION_WATCHDOG = 14, /**< 30 Watchdog timer */ + CC13XX_CC26XX_CM4_EXCEPTION_GPTIMER_0A = 15, /**< 31 Timer 0 subtimer A */ + CC13XX_CC26XX_CM4_EXCEPTION_GPTIMER_0B = 16, /**< 32 Timer 0 subtimer B */ + CC13XX_CC26XX_CM4_EXCEPTION_GPTIMER_1A = 17, /**< 33 Timer 1 subtimer A */ + CC13XX_CC26XX_CM4_EXCEPTION_GPTIMER_1B = 18, /**< 34 Timer 1 subtimer B */ + CC13XX_CC26XX_CM4_EXCEPTION_GPTIMER_2A = 19, /**< 35 Timer 2 subtimer A */ + CC13XX_CC26XX_CM4_EXCEPTION_GPTIMER_2B = 20, /**< 36 Timer 2 subtimer B */ + CC13XX_CC26XX_CM4_EXCEPTION_GPTIMER_3A = 21, /**< 37 Timer 3 subtimer A */ + CC13XX_CC26XX_CM4_EXCEPTION_GPTIMER_3B = 22, /**< 38 Timer 3 subtimer B */ + CC13XX_CC26XX_CM4_EXCEPTION_CRYPTO = 23, /**< 39 Crypto Core Result available */ + CC13XX_CC26XX_CM4_EXCEPTION_UDMA = 24, /**< 40 uDMA Software */ + CC13XX_CC26XX_CM4_EXCEPTION_UDMA_ERR = 25, /**< 41 uDMA Error */ + CC13XX_CC26XX_CM4_EXCEPTION_FLASH_CTRL = 26, /**< 42 Flash controller */ + CC13XX_CC26XX_CM4_EXCEPTION_SW0 = 27, /**< 43 Software Event 0 */ + CC13XX_CC26XX_CM4_EXCEPTION_AUX_COM_EVENT = 28, /**< 44 AUX combined event, directly to MCU domain*/ + CC13XX_CC26XX_CM4_EXCEPTION_AON_PRG0 = 29, /**< 45 AON programmable 0 */ + CC13XX_CC26XX_CM4_EXCEPTION_PROG = 30, /**< 46 Dynamic Programmable interrupt (default source: PRCM)*/ + CC13XX_CC26XX_CM4_EXCEPTION_AUX_COMPA = 31, /**< 47 AUX Comparator A */ + CC13XX_CC26XX_CM4_EXCEPTION_AUX_ADC = 32, /**< 48 AUX ADC IRQ */ + CC13XX_CC26XX_CM4_EXCEPTION_TRNG = 33, /**< 49 TRNG event */ +} cc13xx_cc26xx_cm4_irq_t; + +typedef cc13xx_cc26xx_cm4_irq_t IRQn_Type; + +#define SysTick_IRQn CC13XX_CC26XX_CM4_EXCEPTION_SYS_TICK +/** @} */ +/*---------------------------------------------------------------------------*/ +/** \name Processor and Core Peripheral Section + * @{ + */ +/* Configuration of the Cortex-M4 Processor and Core Peripherals */ +#define __MPU_PRESENT 1 /**< MPU present or not */ +#define __NVIC_PRIO_BITS 3 /**< Number of Bits used for Priority Levels */ +#define __Vendor_SysTickConfig 0 /**< Set to 1 if different SysTick Config is used */ +/** @} */ +/*---------------------------------------------------------------------------*/ +#include "core_cm4.h" /* Cortex-M4 processor and core peripherals */ +/*---------------------------------------------------------------------------*/ +#endif /* CC13XX_CC26XX_CM4_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/cc13x2-cc26x2/cc13x2-cc26x2.icf b/arch/cpu/simplelink-cc13xx-cc26xx/cc13x2-cc26x2/cc13x2-cc26x2.icf new file mode 100644 index 000000000..32316f445 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/cc13x2-cc26x2/cc13x2-cc26x2.icf @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +define symbol STACK_SIZE = 0x800; /* 2048 bytes */ +define symbol HEAP_SIZE = 0x100; /* 256 bytes */ + +define symbol __intvec_start__ = 0x00000000; + +/*-Memory Regions-*/ +define symbol ROM_start__ = 0x00000000; +define symbol ROM_end__ = 0x00057FFF; +define symbol RAM_start__ = 0x20000000; +define symbol RAM_end__ = 0x20013FFF; +define symbol GPRAM_start__ = 0x11000000; +define symbol GPRAM_end__ = 0x11001FFF; + +/* Define a memory region that covers the entire 4 GB addressable space */ +define memory mem with size = 4G; + +/* Define a region for the on-chip flash */ +define region FLASH_region = mem:[from ROM_start__ to ROM_end__]; + +/* Define a region for the on-chip SRAM */ +define region RAM_region = mem:[from RAM_start__ to RAM_end__]; + +/* Define a region for the on-chip GPRAM */ +define region GPRAM_region = mem:[from GPRAM_start__ to GPRAM_end__]; + +/* Place the interrupt vectors at the start of flash */ +place at address mem:__intvec_start__ { readonly section .intvec }; +keep { section .intvec }; + +/* Place the CCA area at the end of flash */ +place at end of FLASH_region { readonly section .ccfg }; +keep { section .ccfg }; + +/* Place remaining 'read only' in Flash */ +place in FLASH_region { readonly }; + +/* Place all read/write items into RAM */ +place in RAM_region { readwrite }; +initialize by copy { readwrite }; + +/* + * Define CSTACK block to contain .stack section. This enables the IAR IDE + * to properly show the stack content during debug. Place stack at end of + * retention RAM, do not initialize (initializing the stack will destroy the + * return address from the initialization code, causing the processor to branch + * to zero and fault) + */ +define block CSTACK with alignment = 8, size = STACK_SIZE { section .stack }; +place at end of RAM_region { block CSTACK }; +do not initialize { section .stack, section .noinit }; + +/* Export stack top symbol. Used by startup file */ +define exported symbol STACK_TOP = RAM_end__ + 1; + +/* Primary Heap configuration */ +define block HEAP with alignment = 8, size = HEAP_SIZE { }; + +/* Place heap just before CSTACK */ +place in RAM_region { block HEAP }; diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/cc13x2-cc26x2/cc13x2-cc26x2.lds b/arch/cpu/simplelink-cc13xx-cc26xx/cc13x2-cc26x2/cc13x2-cc26x2.lds new file mode 100644 index 000000000..9c2211cb8 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/cc13x2-cc26x2/cc13x2-cc26x2.lds @@ -0,0 +1,232 @@ +/* + * Copyright (c) 2017-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +MIN_STACKSIZE = 0x600; /* 1536 bytes */ +HEAPSIZE = 0x100; /* 256 bytes */ + +MEMORY +{ + FLASH (RX) : ORIGIN = 0x00000000, LENGTH = 0x00057fa8 + /* + * Customer Configuration Area and Bootloader Backdoor configuration in + * flash, 40 bytes + */ + FLASH_CCFG (RX) : ORIGIN = 0x00057fa8, LENGTH = 0x00000058 + SRAM (RWX) : ORIGIN = 0x20000000, LENGTH = 0x00014000 + GPRAM (RWX) : ORIGIN = 0x11000000, LENGTH = 0x00002000 +} + +REGION_ALIAS("REGION_TEXT", FLASH); +REGION_ALIAS("REGION_BSS", SRAM); +REGION_ALIAS("REGION_DATA", SRAM); +REGION_ALIAS("REGION_STACK", SRAM); +REGION_ALIAS("REGION_HEAP", SRAM); +REGION_ALIAS("REGION_ARM_EXIDX", FLASH); +REGION_ALIAS("REGION_ARM_EXTAB", FLASH); + +SECTIONS { + + PROVIDE (_resetVecs_base_addr = DEFINED(_resetVecs_base_addr) + ? _resetVecs_base_addr + : 0x0); + + .resetVecs (_resetVecs_base_addr) : AT (_resetVecs_base_addr) { + KEEP (*(.resetVecs)) + } > REGION_TEXT + + .ramVecs (NOLOAD) : ALIGN(1024) { + KEEP (*(.ramVecs)) + } > REGION_DATA + + /* + * UDMACC26XX_CONFIG_BASE below must match UDMACC26XX_CONFIG_BASE defined + * by ti/drivers/dma/UDMACC26XX.h + * The user is allowed to change UDMACC26XX_CONFIG_BASE to move it away from + * the default address 0x2000_1800, but remember it must be 1024 bytes aligned. + */ + UDMACC26XX_CONFIG_BASE = 0x20001800; + + /* + * Define absolute addresses for the DMA channels. + * DMA channels must always be allocated at a fixed offset from the DMA base address. + * CTEA := Control Table Entry Address + * --------- DO NOT MODIFY ----------- + */ + DMA_SPI0_RX_CTEA = (UDMACC26XX_CONFIG_BASE + 0x30); + DMA_SPI0_TX_CTEA = (UDMACC26XX_CONFIG_BASE + 0x40); + DMA_ADC_PRI_CTEA = (UDMACC26XX_CONFIG_BASE + 0x70); + DMA_GPT0A_PRI_CTEA = (UDMACC26XX_CONFIG_BASE + 0x90); + DMA_SPI1_RX_CTEA = (UDMACC26XX_CONFIG_BASE + 0x100); + DMA_SPI1_TX_CTEA = (UDMACC26XX_CONFIG_BASE + 0x110); + DMA_ADC_ALT_CTEA = (UDMACC26XX_CONFIG_BASE + 0x270); + DMA_GPT0A_ALT_CTEA = (UDMACC26XX_CONFIG_BASE + 0x290); + + /* + * Allocate SPI0, SPI1, ADC, and GPTimer0 DMA descriptors at absolute addresses. + * --------- DO NOT MODIFY ----------- + */ + UDMACC26XX_dmaSpi0RxControlTableEntry_is_placed = 0; + .dmaSpi0RxControlTableEntry DMA_SPI0_RX_CTEA : AT (DMA_SPI0_RX_CTEA) { + *(.dmaSpi0RxControlTableEntry) + } > REGION_DATA + + UDMACC26XX_dmaSpi0TxControlTableEntry_is_placed = 0; + .dmaSpi0TxControlTableEntry DMA_SPI0_TX_CTEA : AT (DMA_SPI0_TX_CTEA) { + *(.dmaSpi0TxControlTableEntry) + } > REGION_DATA + + UDMACC26XX_dmaADCPriControlTableEntry_is_placed = 0; + .dmaADCPriControlTableEntry DMA_ADC_PRI_CTEA : AT (DMA_ADC_PRI_CTEA) { + *(.dmaADCPriControlTableEntry) + } > REGION_DATA + + UDMACC26XX_dmaGPT0APriControlTableEntry_is_placed = 0; + .dmaGPT0APriControlTableEntry DMA_GPT0A_PRI_CTEA : AT (DMA_GPT0A_PRI_CTEA) { + *(.dmaGPT0APriControlTableEntry) + } > REGION_DATA + + UDMACC26XX_dmaSpi1RxControlTableEntry_is_placed = 0; + .dmaSpi1RxControlTableEntry DMA_SPI1_RX_CTEA : AT (DMA_SPI1_RX_CTEA) { + *(.dmaSpi1RxControlTableEntry) + } > REGION_DATA + + UDMACC26XX_dmaSpi1TxControlTableEntry_is_placed = 0; + .dmaSpi1TxControlTableEntry DMA_SPI1_TX_CTEA : AT (DMA_SPI1_TX_CTEA) { + *(.dmaSpi1TxControlTableEntry) + } > REGION_DATA + + UDMACC26XX_dmaADCAltControlTableEntry_is_placed = 0; + .dmaADCAltControlTableEntry DMA_ADC_ALT_CTEA : AT (DMA_ADC_ALT_CTEA) { + *(.dmaADCAltControlTableEntry) + } > REGION_DATA + + UDMACC26XX_dmaGPT0AAltControlTableEntry_is_placed = 0; + .dmaGPT0AAltControlTableEntry DMA_GPT0A_ALT_CTEA : AT (DMA_GPT0A_ALT_CTEA) { + *(.dmaGPT0AAltControlTableEntry) + } > REGION_DATA + + .text : { + CREATE_OBJECT_SYMBOLS + *(.text) + *(.text.*) + . = ALIGN(0x4); + KEEP (*(.ctors)) + . = ALIGN(0x4); + KEEP (*(.dtors)) + . = ALIGN(0x4); + __init_array_start = .; + KEEP (*(.init_array*)) + __init_array_end = .; + *(.init) + *(.fini*) + } > REGION_TEXT AT> REGION_TEXT + + PROVIDE (__etext = .); + PROVIDE (_etext = .); + PROVIDE (etext = .); + + .rodata : { + *(.rodata) + *(.rodata.*) + } > REGION_TEXT AT> REGION_TEXT + + .data : ALIGN(0x4) { + __data_load__ = LOADADDR(.data); + __data_start__ = .; + *(.data) + *(.data.*) + . = ALIGN (0x4); + __data_end__ = .; + } > REGION_DATA AT> REGION_TEXT + + .ARM.exidx : { + __exidx_start = .; + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + __exidx_end = .; + } > REGION_ARM_EXIDX AT> REGION_ARM_EXIDX + + .ARM.extab : { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > REGION_ARM_EXTAB AT> REGION_ARM_EXTAB + + .nvs (NOLOAD) : ALIGN(0x2000) { + *(.nvs) + } > REGION_TEXT + + .ccfg : { + KEEP(*(.ccfg)) + } > FLASH_CCFG AT> FLASH_CCFG + + .bss : { + __bss_start__ = .; + *(.shbss) + *(.bss) + *(.bss.*) + *(COMMON) + . = ALIGN(0x4); + __bss_end__ = .; + } > REGION_BSS AT> REGION_BSS + + /* Start of heap must be 4 byte aligned */ + .heap (NOLOAD) : ALIGN(0x4) { + PROVIDE(__heap_start__ = .); + PROVIDE(_heap = __heap_start__); + PROVIDE(end = __heap_start__); + PROVIDE(_end = __heap_start__); + PROVIDE(__end = __heap_start__); + + . += HEAPSIZE; + KEEP(*(.heap)) + + PROVIDE(__heap_end__ = .); + PROVIDE(_eheap = __heap_end__); + PROVIDE(__HeapLimit = __heap_end__); + } > REGION_HEAP AT> REGION_HEAP + + PROVIDE(__stack_size = ORIGIN(SRAM) + LENGTH(SRAM) - ALIGN(0x8)); + + /* Start of stack must be 8 byte aligned */ + .stack (NOLOAD) : { + PROVIDE(_stack = ALIGN(0x8)); + PROVIDE(__stack = _stack); + + PROVIDE(_stack_end = ORIGIN(SRAM) + LENGTH(SRAM)); + PROVIDE(__stack_end = _stack_end); + PROVIDE(_stack_origin = _stack_end); + + /* Note that the stack check library requires the symbols */ + /* "_stack" and "_stack_origin" to be defined. */ + + /* Assert that we have enough stack */ + ASSERT(__stack_size >= MIN_STACKSIZE, "Error: No room left for the stack"); + } > REGION_STACK AT> REGION_STACK +} diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/cc13xx-cc26xx-conf.h b/arch/cpu/simplelink-cc13xx-cc26xx/cc13xx-cc26xx-conf.h new file mode 100644 index 000000000..87fa922b9 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/cc13xx-cc26xx-conf.h @@ -0,0 +1,472 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-cpu + * @{ + * + * \file + * Header with configuration defines common to the CC13xx/CC26xx + * platform. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#ifndef CC13XX_CC26XX_CONF_H_ +#define CC13XX_CC26XX_CONF_H_ +/*---------------------------------------------------------------------------*/ +#include "cc13xx-cc26xx-def.h" + +#include "rf/rf.h" +/*---------------------------------------------------------------------------*/ +/** + * \name Board Configuration. + * + * @{ + */ + +/* Configure that a board has sensors for the dev/sensors.h API. */ +#ifndef BOARD_CONF_HAS_SENSORS +#define BOARD_CONF_HAS_SENSORS 0 +#endif + +/* Enable/disable the dev/sensors.h API for the given board. */ +#ifndef BOARD_CONF_SENSORS_DISABLE +#define BOARD_CONF_SENSORS_DISABLE 0 +#endif +/*---------------------------------------------------------------------------*/ +/** + * \name GPIO HAL configuration. + * + * @{ + */ +#define GPIO_HAL_CONF_ARCH_SW_TOGGLE 0 +#define GPIO_HAL_CONF_ARCH_HDR_PATH "dev/gpio-hal-arch.h" +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name Watchdog Configuration. + * + * @{ + */ +#ifndef WATCHDOG_CONF_DISABLE +#define WATCHDOG_CONF_DISABLE 0 +#endif + +#ifndef WATCHDOG_CONF_TIMER_TOP +#define WATCHDOG_CONF_TIMER_TOP 0xFFFFF +#endif +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name RF configuration. + * + * @{ + */ + +/* + * Set the inactivity timeout period for the RF driver. This determines how + * long the RF driver will wait when inactive until turning off the RF Core. + * Specified in microseconds. + */ +#ifndef RF_CONF_INACTIVITY_TIMEOUT +#define RF_CONF_INACTIVITY_TIMEOUT 2000 /**< 2 ms */ +#endif + +/* + * Configure TX power to either default PA or High PA, defaults to + * default PA. + */ +#ifndef RF_CONF_TXPOWER_HIGH_PA +#define RF_CONF_TXPOWER_HIGH_PA 0 +#endif + +#if (RF_CONF_TXPOWER_HIGH_PA) && !(SUPPORTS_HIGH_PA) +#error "Device does not support High PA" +#endif + +/* + * CC13xx only: Configure TX power to use boot mode, allowing to gain + * up to 14 dBm with the default PA. This will, however, increase power + * consumption. + */ +#ifndef RF_CONF_TXPOWER_BOOST_MODE +#define RF_CONF_TXPOWER_BOOST_MODE 0 +#endif + +/* + * Configure RF mode. That is, whether to run on Sub-1 GHz (Prop-mode) or + * 2.4 GHz (IEEE-mode). + */ +#ifdef RF_CONF_MODE +/* Sanity check a valid configuration is provided. */ +#if !(RF_CONF_MODE & RF_MODE_BM) +#error "Invalid RF_CONF_MODE provided" +#endif + +#define RF_MODE RF_CONF_MODE +#endif /* RF_CONF_MODE */ + +/* Number of RX buffers. */ +#ifndef RF_CONF_RX_BUF_CNT +#define RF_CONF_RX_BUF_CNT 4 +#endif + +/* Size of each RX buffer in bytes. */ +#ifndef RF_CONF_RX_BUF_SIZE +#define RF_CONF_RX_BUF_SIZE 144 +#endif + +/* Enable/disable BLE beacon. */ +#ifndef RF_CONF_BLE_BEACON_ENABLE +#define RF_CONF_BLE_BEACON_ENABLE 0 +#endif + +#if (RF_CONF_BLE_BEACON_ENABLE) && !(SUPPORTS_BLE_BEACON) +#error "Device does not support BLE for BLE beacon" +#endif + +/*----- CC13xx Device Line --------------------------------------------------*/ +/* CC13xx supports both IEEE and Prop mode, depending on which device. */ +#if defined(DEVICE_LINE_CC13XX) + +/* Default to Prop-mode for CC13xx devices if not configured. */ +#ifndef RF_MODE +#define RF_MODE RF_MODE_SUB_1_GHZ +#endif + +/*----- CC13xx Prop-mode ----------------------------------------------------*/ +#if (RF_MODE == RF_MODE_SUB_1_GHZ) && (SUPPORTS_PROP_MODE) + +/* Netstack configuration. */ +#define NETSTACK_CONF_RADIO prop_mode_driver + +/* CSMA configuration. */ +#define CSMA_CONF_ACK_WAIT_TIME (RTIMER_SECOND / 300) +#define CSMA_CONF_AFTER_ACK_DETECTED_WAIT_TIME (RTIMER_SECOND / 1000) +#define CSMA_CONF_SEND_SOFT_ACK 1 + +/*----- CC13xx IEEE-mode ----------------------------------------------------*/ +#elif (RF_MODE == RF_MODE_2_4_GHZ) && (SUPPORTS_IEEE_MODE) + +/* Netstack configuration. */ +#define NETSTACK_CONF_RADIO ieee_mode_driver + +/* CSMA configuration. */ +#define CSMA_CONF_SEND_SOFT_ACK 0 + +#else +/*----- CC13xx Unsupported Mode ---------------------------------------------*/ +#error "Invalid RF mode configuration of CC13xx device" +#endif /* CC13xx RF Mode configuration */ + +/*----- CC26xx Device Line --------------------------------------------------*/ +/* CC26xx only supports IEEE mode */ +#elif defined(DEVICE_LINE_CC26XX) + +/* Default to IEEE-mode for CC26xx devices if not configured */ +#ifndef RF_MODE +#define RF_MODE RF_MODE_2_4_GHZ +#endif + +/*----- CC26xx IEEE-mode ----------------------------------------------------*/ +#if (RF_MODE == RF_MODE_2_4_GHZ) && (SUPPORTS_IEEE_MODE) + +/* Netstack configuration */ +#define NETSTACK_CONF_RADIO ieee_mode_driver + +/* CSMA configuration */ +#define CSMA_CONF_SEND_SOFT_ACK 0 + +/* Frequncy band configuration */ +#undef DOT_15_4G_FREQ_BAND_ID +#define DOT_15_4G_CONF_FREQ_BAND_ID DOT_15_4G_FREQ_BAND_2450 + +#else +/*----- CC26xx Unsupported Mode ---------------------------------------------*/ +#error "IEEE-mode only supported by CC26xx devices" +#endif /* CC26xx RF Mode configuration */ + +/*----- Unsupported device line ---------------------------------------------*/ +#else +#error "Unsupported Device Line defined" +#endif /* Unsupported device line */ + +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name IEEE address configuration. Used to generate our link-local and + * global IPv6 addresses. + * @{ + */ + +/** + * \brief Location of the IEEE address. + * 0 => Read from InfoPage. + * 1 => Use a hardcoded address, configured by IEEE_ADDR_CONF_ADDRESS. + */ +#ifndef IEEE_ADDR_CONF_HARDCODED +#define IEEE_ADDR_CONF_HARDCODED 0 +#endif + +/** + * \brief The hardcoded IEEE address to be used when IEEE_ADDR_CONF_HARDCODED + * is defined as 1. Must be a byte array of size 8. + */ +#ifndef IEEE_ADDR_CONF_ADDRESS +#define IEEE_ADDR_CONF_ADDRESS { 0x00, 0x12, 0x4B, 0x00, 0x89, 0xAB, 0xCD, 0xEF } +#endif +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name IEEE-mode configuration. + * + * @{ + */ + +/** + * \brief Configuration to enable/disable auto ACKs in IEEE-mode. + * 0 => ACK generated by software + * 1 => ACK generated by the radio. + */ +#ifndef IEEE_MODE_CONF_AUTOACK +#define IEEE_MODE_CONF_AUTOACK 1 +#endif + +/** + * \brief Configuration to enable/disable frame filtering in IEEE-mode. + * 0 => Disable promiscous mode. + * 1 => Enable promiscous mode. + */ +#ifndef IEEE_MODE_CONF_PROMISCOUS +#define IEEE_MODE_CONF_PROMISCOUS 0 +#endif + +/** + * \brief Configuration to set the RSSI threshold in dBm in IEEE-mode. + * Defaults to -90 dBm. + */ +#ifndef IEEE_MODE_CONF_CCA_RSSI_THRESHOLD +#define IEEE_MODE_CONF_CCA_RSSI_THRESHOLD 0xA6 +#endif +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name Prop-mode configuration. + * + * @{ + */ + +/** + * \brief Configuration to set whitener in Prop-mode. + * 0 => No whitener + * 1 => Whitener. + */ +#ifndef PROP_MODE_CONF_DW +#define PROP_MODE_CONF_DW 0 +#endif + +/** + * \brief Use 16-bit or 32-bit CRC in Prop-mode. + * 0 => 32-bit CRC. + * 1 => 16-bit CRC. + */ +#ifndef PROP_MODE_CONF_USE_CRC16 +#define PROP_MODE_CONF_USE_CRC16 0 +#endif + +/** + * \brief Configuration to set the RSSI threshold in dBm in Prop-mode. + * Defaults to -90 dBm. + */ +#ifndef PROP_MODE_CONF_CCA_RSSI_THRESHOLD +#define PROP_MODE_CONF_CCA_RSSI_THRESHOLD 0xA6 +#endif +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name TI Drivers Configuration. + * + * @{ + */ + +/** + * \brief Enable or disable UART driver. + */ +#ifndef TI_UART_CONF_ENABLE +#define TI_UART_CONF_ENABLE 1 +#endif + +/** + * \brief Enable or disable UART0 peripheral. + */ +#ifndef TI_UART_CONF_UART0_ENABLE +#define TI_UART_CONF_UART0_ENABLE TI_UART_CONF_ENABLE +#endif + +/** + * \brief Enable or disable UART1 peripheral. + */ +#ifndef TI_UART_CONF_UART1_ENABLE +#define TI_UART_CONF_UART1_ENABLE 0 +#endif + +/** + * \brief UART driver baud rate configuration. + */ +#ifndef TI_UART_CONF_BAUD_RATE +#define TI_UART_CONF_BAUD_RATE 115200 +#endif + +/** + * \brief Enable or disable SPI driver. + */ +#ifndef TI_SPI_CONF_ENABLE +#define TI_SPI_CONF_ENABLE 1 +#endif + +/** + * \brief Enable or disable SPI0 peripheral. + */ +#ifndef TI_SPI_CONF_SPI0_ENABLE +#define TI_SPI_CONF_SPI0_ENABLE TI_SPI_CONF_ENABLE +#endif + +/** + * \brief Enable or disable SPI1 peripheral. + */ +#ifndef TI_SPI_CONF_SPI1_ENABLE +#define TI_SPI_CONF_SPI1_ENABLE 0 +#endif + +/** + * \brief Enable or disable I2C driver. + */ +#ifndef TI_I2C_CONF_ENABLE +#define TI_I2C_CONF_ENABLE 1 +#endif + +/** + * \brief Enable or disable I2C0 peripheral. + */ +#ifndef TI_I2C_CONF_I2C0_ENABLE +#define TI_I2C_CONF_I2C0_ENABLE TI_I2C_CONF_ENABLE +#endif + +/** + * \brief Enable or disable Non-Volatile Storage (NVS) driver. + */ +#ifndef TI_NVS_CONF_ENABLE +#define TI_NVS_CONF_ENABLE 0 +#endif + +/** + * \brief Enable or disable internal flash storage. + */ +#ifndef TI_NVS_CONF_NVS_INTERNAL_ENABLE +#define TI_NVS_CONF_NVS_INTERNAL_ENABLE TI_NVS_CONF_ENABLE +#endif + +/** + * \brief Enable or disable external flash storage. + */ +#ifndef TI_NVS_CONF_NVS_EXTERNAL_ENABLE +#define TI_NVS_CONF_NVS_EXTERNAL_ENABLE TI_NVS_CONF_ENABLE +#endif + +/** + * \brief Enable or disable SD driver. + */ +#ifndef TI_SD_CONF_ENABLE +#define TI_SD_CONF_ENABLE 0 +#endif +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name SPI HAL configuration. + * + * CC13x0/CC26x0 has one SPI interface, while CC13x2/CC26x2 has two + * SPI interfaces. Some additional checks has to be made for the + * SPI_CONF_CONTROLLER_COUNT configuration, as this relies on whether the + * available SPI interfaces are enabled or not, as well as if the SPI driver + * is enabled at all. + * + * @{ + */ +#if TI_SPI_CONF_ENABLE +/* + * The SPI driver is enabled. Therefore, the number of SPI interfaces depends + * on which Device family parent the device falls under and if any of its + * corresponding SPI interfaces are enabled or not. + */ + +#define SPI0_IS_ENABLED ((TI_SPI_CONF_SPI0_ENABLE) ? 1 : 0) +#define SPI1_IS_ENABLED ((TI_SPI_CONF_SPI1_ENABLE) ? 1 : 0) + +#if (DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X0_CC26X0) + +/* CC13x0/CC26x0 only has one SPI interface: SPI0. */ +#define SPI_CONF_CONTROLLER_COUNT (SPI0_IS_ENABLED) + +#elif (DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X2_CC26X2) + +/* CC13x0/CC26x0 only has two SPI interface: SPI0 and SPI1. */ +#define SPI_CONF_CONTROLLER_COUNT (SPI0_IS_ENABLED + SPI1_IS_ENABLED) + +#endif /* DeviceFamily_PARENT */ + +#else /* TI_SPI_CONF_ENABLE */ +/* + * If the SPI driver is disabled then there are 0 available + * SPI interfaces. */ +#define SPI_CONF_CONTROLLER_COUNT 0 +#endif /* TI_SPI_CONF_ENABLE */ +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name Slip configuration + * + * @{ + */ +#ifndef SLIP_ARCH_CONF_ENABLED +/* + * Determine whether we need SLIP + * This will keep working while UIP_FALLBACK_INTERFACE and CMD_CONF_OUTPUT + * keep using SLIP + */ +#if defined(UIP_FALLBACK_INTERFACE) || defined(CMD_CONF_OUTPUT) +#define SLIP_ARCH_CONF_ENABLED 1 +#endif + +#endif /* SLIP_ARCH_CONF_ENABLED */ +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* CC13XX_CC26XX_CONF_H_ */ +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/cc13xx-cc26xx-def.h b/arch/cpu/simplelink-cc13xx-cc26xx/cc13xx-cc26xx-def.h new file mode 100644 index 000000000..5bcde9d93 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/cc13xx-cc26xx-def.h @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-cpu + * @{ + * + * \file + * Header with configuration defines for the Contiki system. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#ifndef CC13XX_CC26XX_DEF_H_ +#define CC13XX_CC26XX_DEF_H_ +/*---------------------------------------------------------------------------*/ +#include +/*---------------------------------------------------------------------------*/ +#if (DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X0_CC26X0) +#include +#elif (DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X2_CC26X2) +#include +#endif +/*---------------------------------------------------------------------------*/ +#include +#include +/*---------------------------------------------------------------------------*/ +#define RTIMER_ARCH_SECOND 65536 +/*---------------------------------------------------------------------------*/ +#define INT_MASTER_CONF_STATUS_DATATYPE uintptr_t +/*---------------------------------------------------------------------------*/ +/* TSCH related defines */ + +/* 1 len byte, 2 bytes CRC */ +#define RADIO_PHY_OVERHEAD 3 +/* 250kbps data rate. One byte = 32us */ +#define RADIO_BYTE_AIR_TIME 32 +/* Delay between GO signal and SFD */ +#define RADIO_DELAY_BEFORE_TX ((unsigned)US_TO_RTIMERTICKS(81)) +/* Delay between GO signal and start listening. + * This value is so small because the radio is constantly on within each timeslot. */ +#define RADIO_DELAY_BEFORE_RX ((unsigned)US_TO_RTIMERTICKS(15)) +/* Delay between the SFD finishes arriving and it is detected in software. */ +#define RADIO_DELAY_BEFORE_DETECT ((unsigned)US_TO_RTIMERTICKS(352)) + +/* Timer conversion; radio is running at 4 MHz */ +#define RAT_SECOND 4000000u +#define RAT_TO_RTIMER(x) ((uint32_t)(((uint64_t)(x)*(RTIMER_SECOND / 256)) / (RAT_SECOND / 256))) +#define USEC_TO_RAT(x) ((x) * 4) + +#if (RTIMER_SECOND % 256) || (RAT_SECOND % 256) +#error RAT_TO_RTIMER macro must be fixed! +#endif + +/* The PHY header (preamble + SFD, 4+1 bytes) duration is equivalent to 10 symbols */ +#define RADIO_IEEE_802154_PHY_HEADER_DURATION_USEC 160 + +/* Do not turn off TSCH within a timeslot: not enough time */ +#define TSCH_CONF_RADIO_ON_DURING_TIMESLOT 1 + +/* Disable TSCH frame filtering */ +#define TSCH_CONF_HW_FRAME_FILTERING 0 + +/* Use hardware timestamps */ +#ifndef TSCH_CONF_RESYNC_WITH_SFD_TIMESTAMPS +#define TSCH_CONF_RESYNC_WITH_SFD_TIMESTAMPS 1 +#define TSCH_CONF_TIMESYNC_REMOVE_JITTER 0 +#endif + +#ifndef TSCH_CONF_BASE_DRIFT_PPM +/* + * The drift compared to "true" 10ms slots. + * Enable adaptive sync to enable compensation for this. + * Slot length 10000 usec + * 328 ticks + * Tick duration 30.517578125 usec + * Real slot duration 10009.765625 usec + * Target - real duration = -9.765625 usec + * TSCH_CONF_BASE_DRIFT_PPM -977 + */ +#define TSCH_CONF_BASE_DRIFT_PPM -977 +#endif + +/* 10 times per second */ +#ifndef TSCH_CONF_CHANNEL_SCAN_DURATION +#define TSCH_CONF_CHANNEL_SCAN_DURATION (CLOCK_SECOND / 10) +#endif + +/* Slightly reduce the TSCH guard time (from 2200 usec to 1800 usec) to make sure + * the CC26xx radio has sufficient time to start up. */ +#ifndef TSCH_CONF_RX_WAIT +#define TSCH_CONF_RX_WAIT 1800 +#endif +/*---------------------------------------------------------------------------*/ +/* Path to CMSIS header */ +#if (DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X0_CC26X0) +#define CMSIS_CONF_HEADER_PATH "cc13x0-cc26x0-cm3.h" +#elif (DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X2_CC26X2) +#define CMSIS_CONF_HEADER_PATH "cc13x2-cc26x2-cm4.h" +#endif +/*---------------------------------------------------------------------------*/ +/* Path to headers with implementation of mutexes and memory barriers */ +#define MUTEX_CONF_ARCH_HEADER_PATH "mutex-cortex.h" +#define MEMORY_BARRIER_CONF_ARCH_HEADER_PATH "memory-barrier-cortex.h" +/*---------------------------------------------------------------------------*/ +#endif /* CC13XX_CC26XX_DEF_H_ */ +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/ccfg-conf.c b/arch/cpu/simplelink-cc13xx-cc26xx/ccfg-conf.c new file mode 100644 index 000000000..ef83fc29b --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/ccfg-conf.c @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-cpu + * @{ + * + * \defgroup cc13xx-cc26xx-ccfg Customer Configuration (CCFG) + * + * @{ + * + * \file + * Configuration of CCFG. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki-conf.h" +/*---------------------------------------------------------------------------*/ +/** + * \name JTAG interface configuration + * + * Enable/Disable the JTAG DAP and TAP interfaces on the chip. + * Setting this to 0 will disable access to the debug interface + * to secure deployed images. + * @{ + */ +#if CCFG_CONF_JTAG_INTERFACE_DISABLE +#define SET_CCFG_CCFG_TI_OPTIONS_TI_FA_ENABLE 0x00 +#define SET_CCFG_CCFG_TAP_DAP_0_CPU_DAP_ENABLE 0x00 +#define SET_CCFG_CCFG_TAP_DAP_0_PRCM_TAP_ENABLE 0x00 +#define SET_CCFG_CCFG_TAP_DAP_0_TEST_TAP_ENABLE 0x00 +#define SET_CCFG_CCFG_TAP_DAP_1_PBIST2_TAP_ENABLE 0x00 +#define SET_CCFG_CCFG_TAP_DAP_1_PBIST1_TAP_ENABLE 0x00 +#define SET_CCFG_CCFG_TAP_DAP_1_WUC_TAP_ENABLE 0x00 +#endif /* CCFG_CONF_JTAG_INTERFACE_DISABLE */ +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name TX Power Boost Mode + * + * CC13xx only: Enable/Disable boost mode, which enables maximum +14 dBm + * output power with the default PA front-end configuration. + * @{ + */ +#if defined(DEVICE_LINE_CC13XX) && (RF_CONF_TXPOWER_BOOST_MODE) +#define CCFG_FORCE_VDDR_HH 1 +#endif +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name ROM Bootloader configuration + * + * Enable/Disable the ROM bootloader in your image, if the board supports it. + * Look in Board.h to choose the DIO and corresponding level that will cause + * the chip to enter bootloader mode. + * @{ + */ +#ifndef CCFG_CONF_ROM_BOOTLOADER_ENABLE +#define CCFG_CONF_ROM_BOOTLOADER_ENABLE 0 +#endif + +#if CCFG_CONF_ROM_BOOTLOADER_ENABLE +#define SET_CCFG_BL_CONFIG_BOOTLOADER_ENABLE 0xC5 +#define SET_CCFG_BL_CONFIG_BL_LEVEL 0x00 +#if defined(CCFG_CONF_BL_PIN_NUMBER) +#define SET_CCFG_BL_CONFIG_BL_PIN_NUMBER CCFG_CONF_BL_PIN_NUMBER +#endif +#define SET_CCFG_BL_CONFIG_BL_ENABLE 0xC5 +#endif /* CCFG_CONF_ROM_BOOTLOADER_ENABLE */ +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name Include the device-specific CCFG file from the SDK. + * + * @{ + */ +#include +#include DeviceFamily_constructPath(startup_files/ccfg.c) +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/dev/clock-arch.c b/arch/cpu/simplelink-cc13xx-cc26xx/dev/clock-arch.c new file mode 100644 index 000000000..ef2d4e1c9 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/dev/clock-arch.c @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-cpu + * @{ + * + * \defgroup cc13xx-cc26xx-clock CC13xx/CC26xx clock library + * + * @{ + * \file + * Implementation of the clock libary for CC13xx/CC26xx. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "sys/etimer.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/aon_rtc.h) +#include DeviceFamily_constructPath(driverlib/cpu.h) +#include DeviceFamily_constructPath(driverlib/interrupt.h) +#include DeviceFamily_constructPath(driverlib/prcm.h) +#include DeviceFamily_constructPath(driverlib/timer.h) + +#include +#include +#include +/*---------------------------------------------------------------------------*/ +static volatile clock_time_t count; +static ClockP_Struct etimer_clock; +/*---------------------------------------------------------------------------*/ +static void +clock_update_cb(void) +{ + const uintptr_t key = HwiP_disable(); + count += 1; + HwiP_restore(key); + + /* Notify the etimer system. */ + if(etimer_pending()) { + etimer_request_poll(); + } +} +/*---------------------------------------------------------------------------*/ +static inline clock_time_t +get_count(void) +{ + clock_time_t count_read; + + const uintptr_t key = HwiP_disable(); + count_read = count; + HwiP_restore(key); + + return count_read; +} +/*---------------------------------------------------------------------------*/ +void +clock_init(void) +{ + /* ClockP_getSystemTickPeriod() returns ticks per us. */ + const uint32_t clockp_ticks_second = + (uint32_t)(1000 * 1000) / (CLOCK_SECOND) / ClockP_getSystemTickPeriod(); + + count = 0; + + ClockP_Params params; + ClockP_Params_init(¶ms); + + params.period = clockp_ticks_second; + params.startFlag = true; + + ClockP_construct(&etimer_clock, (ClockP_Fxn)clock_update_cb, + clockp_ticks_second, ¶ms); +} +/*---------------------------------------------------------------------------*/ +clock_time_t +clock_time(void) +{ + return get_count(); +} +/*---------------------------------------------------------------------------*/ +unsigned long +clock_seconds(void) +{ + return (unsigned long)get_count() / CLOCK_SECOND; +} +/*---------------------------------------------------------------------------*/ +void +clock_wait(clock_time_t i) +{ + clock_time_t start; + + start = clock_time(); + while(clock_time() - start < i); +} +/*---------------------------------------------------------------------------*/ +void +clock_delay_usec(uint16_t usec) +{ + ClockP_usleep(usec); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Obsolete delay function but we implement it here since some code + * still uses it. + */ +void +clock_delay(unsigned int i) +{ + clock_delay_usec(i); +} +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/dev/dbg-arch.c b/arch/cpu/simplelink-cc13xx-cc26xx/dev/dbg-arch.c new file mode 100644 index 000000000..823239f21 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/dev/dbg-arch.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-platform + * @{ + * + * \file + * Implementation of the dbg module for CC13xx/CC26xx, used by stdio. + * The dbg module is implemented by writing to UART0. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "sys/cc.h" +/*---------------------------------------------------------------------------*/ +#include "uart0-arch.h" +/*---------------------------------------------------------------------------*/ +#include +#include +#include +/*---------------------------------------------------------------------------*/ +int +dbg_putchar(int c) +{ + unsigned char ch; + int num_bytes; + + ch = (unsigned char)c; + + num_bytes = (int)uart0_write(&ch, 1); + return (num_bytes > 0) + ? num_bytes + : 0; +} +/*---------------------------------------------------------------------------*/ +unsigned int +dbg_send_bytes(const unsigned char *seq, unsigned int len) +{ + size_t seq_len; + size_t max_len; + int num_bytes; + + seq_len = strlen((const char *)seq); + max_len = MIN(seq_len, (size_t)len); + + if(max_len == 0) { + return 0; + } + + num_bytes = (int)uart0_write(seq, max_len); + return (num_bytes > 0) + ? num_bytes + : 0; +} +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/dev/gpio-hal-arch.c b/arch/cpu/simplelink-cc13xx-cc26xx/dev/gpio-hal-arch.c new file mode 100644 index 000000000..e219faa93 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/dev/gpio-hal-arch.c @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-gpio-hal + * @{ + * + * \file + * Implementation of the GPIO HAL module for CC13xx/CC26xx. The GPIO + * HAL module is implemented by using the PINCC26XX module, except + * for multi-dio functions which use the GPIO driverlib module. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/gpio-hal.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/gpio.h) + +#include +#include +/*---------------------------------------------------------------------------*/ +#include +/*---------------------------------------------------------------------------*/ +static PIN_Config pin_config[] = { PIN_TERMINATE }; +static PIN_State pin_state; +static PIN_Handle pin_handle; +/*---------------------------------------------------------------------------*/ +static void +from_hal_cfg(gpio_hal_pin_cfg_t cfg, PIN_Config *pin_cfg, PIN_Config *pin_mask) +{ + /* Pulling config */ + *pin_mask |= PIN_BM_PULLING; + + switch(cfg & GPIO_HAL_PIN_CFG_PULL_MASK) { + default: /* Default to no pullup/pulldown */ + case GPIO_HAL_PIN_CFG_PULL_NONE: *pin_cfg |= PIN_NOPULL; break; + case GPIO_HAL_PIN_CFG_PULL_UP: *pin_cfg |= PIN_PULLUP; break; + case GPIO_HAL_PIN_CFG_PULL_DOWN: *pin_cfg |= PIN_PULLDOWN; break; + } + + /* Hysteresis config */ + *pin_mask |= PIN_BM_HYSTERESIS; + + if(cfg & GPIO_HAL_PIN_CFG_HYSTERESIS) { + *pin_cfg |= PIN_HYSTERESIS; + } + + /* Interrupt config */ + *pin_mask |= PIN_BM_IRQ; + + if((cfg & GPIO_HAL_PIN_CFG_INT_MASK) == GPIO_HAL_PIN_CFG_INT_ENABLE) { + /* Interrupt edge config */ + switch(cfg & GPIO_HAL_PIN_CFG_EDGE_BOTH) { + case GPIO_HAL_PIN_CFG_EDGE_NONE: *pin_cfg |= PIN_IRQ_DIS; break; + case GPIO_HAL_PIN_CFG_EDGE_FALLING: *pin_cfg |= PIN_IRQ_NEGEDGE; break; + case GPIO_HAL_PIN_CFG_EDGE_RISING: *pin_cfg |= PIN_IRQ_POSEDGE; break; + case GPIO_HAL_PIN_CFG_EDGE_BOTH: *pin_cfg |= PIN_IRQ_BOTHEDGES; break; + } + } else { + *pin_cfg |= PIN_IRQ_DIS; + } +} +/*---------------------------------------------------------------------------*/ +static void +to_hal_cfg(PIN_Config pin_cfg, gpio_hal_pin_cfg_t *cfg) +{ + /* Input config */ + if(pin_cfg & PIN_BM_INPUT_MODE) { + /* Hysteresis config */ + if((pin_cfg & PIN_BM_HYSTERESIS) == PIN_HYSTERESIS) { + *cfg |= GPIO_HAL_PIN_CFG_HYSTERESIS; + } + + /* Pulling config */ + switch(pin_cfg & PIN_BM_PULLING) { + case PIN_NOPULL: *cfg |= GPIO_HAL_PIN_CFG_PULL_NONE; break; + case PIN_PULLUP: *cfg |= GPIO_HAL_PIN_CFG_PULL_UP; break; + case PIN_PULLDOWN: *cfg |= GPIO_HAL_PIN_CFG_PULL_DOWN; break; + } + } + + /* Interrupt config */ + if(pin_cfg & PIN_BM_IRQ) { + /* Interrupt edge config */ + switch(pin_cfg & PIN_BM_IRQ) { + case PIN_IRQ_DIS: *cfg |= GPIO_HAL_PIN_CFG_EDGE_NONE; + *cfg |= GPIO_HAL_PIN_CFG_INT_DISABLE; + break; + case PIN_IRQ_NEGEDGE: *cfg |= GPIO_HAL_PIN_CFG_EDGE_FALLING; + *cfg |= GPIO_HAL_PIN_CFG_INT_ENABLE; + break; + case PIN_IRQ_POSEDGE: *cfg |= GPIO_HAL_PIN_CFG_EDGE_RISING; + *cfg |= GPIO_HAL_PIN_CFG_INT_ENABLE; + break; + case PIN_IRQ_BOTHEDGES: *cfg |= GPIO_HAL_PIN_CFG_EDGE_BOTH; + *cfg |= GPIO_HAL_PIN_CFG_INT_ENABLE; + break; + } + } +} +/*---------------------------------------------------------------------------*/ +static void +gpio_int_cb(PIN_Handle handle, PIN_Id pin_id) +{ + /* Unused args */ + (void)handle; + + /* Notify the GPIO HAL driver */ + gpio_hal_event_handler(gpio_hal_pin_to_mask(pin_id)); +} +/*---------------------------------------------------------------------------*/ +void +gpio_hal_arch_init(void) +{ + /* No error checking */ + pin_handle = PIN_open(&pin_state, pin_config); + PIN_registerIntCb(pin_handle, gpio_int_cb); +} +/*---------------------------------------------------------------------------*/ +void +gpio_hal_arch_interrupt_enable(gpio_hal_pin_t pin) +{ + PIN_Config pin_cfg; + PIN_Config irq_cfg; + + pin_cfg = PIN_getConfig(pin); + PIN_add(pin_handle, pin_cfg); + + irq_cfg = pin_cfg & PIN_BM_IRQ; + PIN_setInterrupt(pin_handle, pin | irq_cfg); +} +/*---------------------------------------------------------------------------*/ +void +gpio_hal_arch_interrupt_disable(gpio_hal_pin_t pin) +{ + PIN_add(pin_handle, PIN_getConfig(pin)); + + PIN_setInterrupt(pin_handle, pin | PIN_IRQ_DIS); +} +/*---------------------------------------------------------------------------*/ +void +gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg) +{ + PIN_add(pin_handle, PIN_getConfig(pin)); + + /* Clear settings that we are about to change, keep everything else. */ + PIN_Config pin_cfg = 0; + PIN_Config pin_mask = 0; + + from_hal_cfg(cfg, &pin_cfg, &pin_mask); + + PIN_setConfig(pin_handle, pin_mask, pin | pin_cfg); +} +/*---------------------------------------------------------------------------*/ +gpio_hal_pin_cfg_t +gpio_hal_arch_pin_cfg_get(gpio_hal_pin_t pin) +{ + PIN_Config pin_cfg = PIN_getConfig(pin); + gpio_hal_pin_cfg_t cfg = 0; + + to_hal_cfg(pin_cfg, &cfg); + + return cfg; +} +/*---------------------------------------------------------------------------*/ +gpio_hal_pin_mask_t +gpio_hal_arch_read_pins(gpio_hal_pin_mask_t pins) +{ + /* For pins configured as output we need to read DOUT31_0 */ + gpio_hal_pin_mask_t oe_pins = GPIO_getOutputEnableMultiDio(pins); + + pins &= ~oe_pins; + + return (HWREG(GPIO_BASE + GPIO_O_DOUT31_0) & oe_pins) | + GPIO_readMultiDio(pins); +} +/*---------------------------------------------------------------------------*/ +uint8_t +gpio_hal_arch_read_pin(gpio_hal_pin_t pin) +{ + return (GPIO_getOutputEnableDio(pin)) + ? PINCC26XX_getOutputValue(pin) + : PINCC26XX_getInputValue(pin); +} +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/dev/gpio-hal-arch.h b/arch/cpu/simplelink-cc13xx-cc26xx/dev/gpio-hal-arch.h new file mode 100644 index 000000000..3ca169a82 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/dev/gpio-hal-arch.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-cpu + * @{ + * + * \defgroup cc13xx-cc26xx-gpio-hal CC13xx/CC26xx GPIO HAL implementation + * + * @{ + * + * \file + * Header file for the CC13xx/CC26xx GPIO HAL functions. + * \author + * Edvard Pettersen + * \note + * Do not include this header directly. + */ +/*---------------------------------------------------------------------------*/ +#ifndef GPIO_HAL_ARCH_H_ +#define GPIO_HAL_ARCH_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/gpio.h) + +#include +/*---------------------------------------------------------------------------*/ +#define gpio_hal_arch_pin_set_input(p) PINCC26XX_setOutputEnable(p, false) +#define gpio_hal_arch_pin_set_output(p) PINCC26XX_setOutputEnable(p, true) + +#define gpio_hal_arch_set_pin(p) PINCC26XX_setOutputValue(p, 1) +#define gpio_hal_arch_clear_pin(p) PINCC26XX_setOutputValue(p, 0) +#define gpio_hal_arch_toggle_pin(p) PINCC26XX_setOutputValue(p, \ + PINCC26XX_getOutputValue(p) \ + ? 0 : 1) +#define gpio_hal_arch_write_pin(p, v) PINCC26XX_setOutputValue(p, v) + +#define gpio_hal_arch_set_pins(p) GPIO_setMultiDio(p) +#define gpio_hal_arch_clear_pins(p) GPIO_clearMultiDio(p) +#define gpio_hal_arch_toggle_pins(p) GPIO_toggleMultiDio(p) +#define gpio_hal_arch_write_pins(p, v) GPIO_writeMultiDio(p, v) +/*---------------------------------------------------------------------------*/ +#endif /* GPIO_HAL_ARCH_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/dev/int-master-arch.c b/arch/cpu/simplelink-cc13xx-cc26xx/dev/int-master-arch.c new file mode 100644 index 000000000..2c72992e6 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/dev/int-master-arch.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-cpu + * @{ + * + * \defgroup cc13xx-cc26xx-int-master CC13xx/CC26xx master interrupt manipulation + * + * Master interrupt manipulation routines for CC13xx/CC26xx. + * + * @{ + * + * \file + * Master interrupt manipulation implementation for CC13xx/CC26xx. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "sys/int-master.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/cpu.h) + +#include +/*---------------------------------------------------------------------------*/ +#include +#include +/*---------------------------------------------------------------------------*/ +void +int_master_enable(void) +{ + HwiP_enable(); +} +/*---------------------------------------------------------------------------*/ +int_master_status_t +int_master_read_and_disable(void) +{ + return (int_master_status_t)HwiP_disable(); +} +/*---------------------------------------------------------------------------*/ +void +int_master_status_set(int_master_status_t status) +{ + HwiP_restore((uintptr_t)status); +} +/*---------------------------------------------------------------------------*/ +bool +int_master_is_enabled(void) +{ + return CPUprimask() ? false : true; +} +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/dev/random.c b/arch/cpu/simplelink-cc13xx-cc26xx/dev/random.c new file mode 100644 index 000000000..4286bfe89 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/dev/random.c @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ + /** + * \addtogroup cc13xx-cc26xx-cpu + * @{ + * + * \defgroup cc13xx-cc26xx-prng Pseudo Random Number Generator (PRNG) for CC13xx/CC26xx. + * @{ + * + * Implementation based on Bob Jenkins' small noncryptographic PRNG. + * - http://burtleburtle.net/bob/rand/smallprng.html + * + * This file overrides os/lib/random.c. Note that the file name must + * match the original file for the override to work. + * + * \file + * Implementation of Pseudo Random Number Generator for CC13xx/CC26xx. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include +/*---------------------------------------------------------------------------*/ +#include +/*---------------------------------------------------------------------------*/ +typedef struct { + uint32_t a; + uint32_t b; + uint32_t c; + uint32_t d; +} ranctx_t; + +static ranctx_t ranctx; +/*---------------------------------------------------------------------------*/ +#define rot32(x, k) (((x) << (k)) | ((x) >> (32 - (k)))) +/*---------------------------------------------------------------------------*/ +/** + * \brief Generates a new random number using the PRNG. + * \return The random number. + */ +unsigned short +random_rand(void) +{ + uint32_t e; + + e = ranctx.a - rot32(ranctx.b, 27); + ranctx.a = ranctx.b ^ rot32(ranctx.c, 17); + ranctx.b = ranctx.c + ranctx.d; + ranctx.c = ranctx.d + e; + ranctx.d = e + ranctx.a; + + return (unsigned short)ranctx.d; +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Initialize the PRNG. + * \param seed Seed for the PRNG. + */ +void +random_init(unsigned short seed) +{ + uint32_t i; + + ranctx.a = 0xf1ea5eed; + ranctx.b = ranctx.c = ranctx.d = (uint32_t)seed; + for(i = 0; i < 20; ++i) { + (void)random_rand(); + } +} +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/dev/rtimer-arch.c b/arch/cpu/simplelink-cc13xx-cc26xx/dev/rtimer-arch.c new file mode 100644 index 000000000..7fd768008 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/dev/rtimer-arch.c @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-rtimer + * @{ + * + * \file + * Implementation of the rtimer driver for CC13xx/CC26xx. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/aon_event.h) +#include DeviceFamily_constructPath(driverlib/aon_rtc.h) +#include DeviceFamily_constructPath(driverlib/interrupt.h) + +#include +#include +/*---------------------------------------------------------------------------*/ +#include +#include +/*---------------------------------------------------------------------------*/ +#define HWIP_RTC_CH AON_RTC_CH0 +#define RTIMER_RTC_CH AON_RTC_CH1 +/*---------------------------------------------------------------------------*/ +typedef void (*isr_fxn_t)(void); +typedef void (*hwi_dispatch_fxn_t)(void); + +static hwi_dispatch_fxn_t hwi_dispatch_fxn; +/*---------------------------------------------------------------------------*/ +/** + * \brief Stub function used when creating the dummy clock object. + */ +static void +rtimer_clock_stub(uintptr_t unused) +{ + (void)unused; + /* do nothing */ +} +/*---------------------------------------------------------------------------*/ +/** + * \brief The Man-in-the-Middle ISR hook for the HWI dispatch ISR. This + * will be the ISR dispatched when INT_AON_RTC_COMB is triggered, + * and will either dispatch the interrupt to the rtimer driver or + * the HWI driver, depening on which event triggered the interrupt. + */ +static void +rtimer_isr_hook(void) +{ + if(AONRTCEventGet(RTIMER_RTC_CH)) { + AONRTCEventClear(RTIMER_RTC_CH); + AONRTCChannelDisable(RTIMER_RTC_CH); + + rtimer_run_next(); + } + /* + * HWI Dispatch clears the interrupt. If HWI wasn't triggered, clear + * the interrupt manually. + */ + if(AONRTCEventGet(HWIP_RTC_CH)) { + hwi_dispatch_fxn(); + } else { + IntPendClear(INT_AON_RTC_COMB); + } +} +/*---------------------------------------------------------------------------*/ +/** + * \brief TODO + */ +void +rtimer_arch_init(void) +{ + uintptr_t key; + ClockP_Struct clk_object; + ClockP_Params clk_params; + volatile isr_fxn_t *ramvec_table; + + key = HwiP_disable(); + + /* + * Create a dummy clock to guarantee the RAM vector table is initialized. + * + * Creating a dummy clock will trigger initialization of TimerP, which + * subsequently initializes the driverlib/interrupt.h module. It is the + * interrupt module that initializes the RAM vector table. + * + * It is safe to destruct the Clock object immediately afterwards. + */ + ClockP_Params_init(&clk_params); + ClockP_construct(&clk_object, rtimer_clock_stub, 0, &clk_params); + ClockP_destruct(&clk_object); + + /* Try to access the RAM vector table. */ + ramvec_table = (isr_fxn_t *)HWREG(NVIC_VTABLE); + if(!ramvec_table) { + /* + * Unable to find the RAM vector table is a serious fault. + * Spin-lock forever. + */ + for(;;) { /* hang */ } + } + + /* + * The HWI Dispatch ISR is located at interrupt number INT_AON_RTC_COMB + * in the RAM vector table. Fetch and store it. + */ + hwi_dispatch_fxn = (hwi_dispatch_fxn_t)ramvec_table[INT_AON_RTC_COMB]; + if(!hwi_dispatch_fxn) { + /* + * Unable to find the HWI dispatch ISR in the RAM vector table is + * a serious fault. Spin-lock forever. + */ + for(;;) { /* hang */ } + } + + /* + * Override the INT_AON_RTC_COMB interrupt number with our own ISR hook, + * which will act as a man-in-the-middle ISR for the HWI dispatch. + */ + IntRegister(INT_AON_RTC_COMB, rtimer_isr_hook); + + AONEventMcuWakeUpSet(AON_EVENT_MCU_WU1, AON_EVENT_RTC_CH1); + AONRTCCombinedEventConfig(HWIP_RTC_CH | RTIMER_RTC_CH); + + HwiP_restore(key); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Schedules an rtimer task to be triggered at time \p t. + * \param t The time when the task will need executed. + * + * \p t is an absolute time, in other words the task will be + * executed AT time \p t, not IN \p t rtimer ticks. + * + * This function schedules a one-shot event with the AON RTC. + * + * This functions converts \p t to a value suitable for the AON RTC. + */ +void +rtimer_arch_schedule(rtimer_clock_t t) +{ + /* Convert the rtimer tick value to a value suitable for the AON RTC */ + AONRTCCompareValueSet(RTIMER_RTC_CH, (uint32_t)t); + AONRTCChannelEnable(RTIMER_RTC_CH); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Returns the current real-time clock time. + * \return The current rtimer time in ticks. + * + * The value is read from the AON RTC counter and converted to a + * number of rtimer ticks. + */ +rtimer_clock_t +rtimer_arch_now() +{ + return (rtimer_clock_t)AONRTCCurrentCompareValueGet(); +} +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/dev/rtimer-arch.h b/arch/cpu/simplelink-cc13xx-cc26xx/dev/rtimer-arch.h new file mode 100644 index 000000000..c42fcbd41 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/dev/rtimer-arch.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-cpu + * @{ + * + * \defgroup cc13xx-cc26xx-rtimer The CC13xx/CC26xx rtimer + * + * Implementation of the rtimer module for CC13xx/CC26xx. This header + * is included by os/sys/rtimer.h. + * + * RTIMER_ARCH_SECOND is defined in cc13xx-cc26xx-def.h. + * @{ + * + * \file + * Header file of the rtimer driver for CC13xx/CC26xx. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#ifndef RTIMER_ARCH_H_ +#define RTIMER_ARCH_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +/*---------------------------------------------------------------------------*/ +rtimer_clock_t rtimer_arch_now(void); +/*---------------------------------------------------------------------------*/ +/* + * HW oscillator frequency is 32 kHz, not 64 kHz. And, RTIMER_NOW() never + * returns an odd value; US_TO_RTIMERTICKS always rounds to the nearest + * even number. + */ +#define US_TO_RTIMERTICKS(us) ( \ + (((us) >= 0) \ + ? (((int32_t)(us) * (RTIMER_ARCH_SECOND / 2) + 500000) / 1000000L) \ + : (((int32_t)(us) * (RTIMER_ARCH_SECOND / 2) - 500000) / 1000000L) \ + ) * 2) + +#define RTIMERTICKS_TO_US(rt) ( \ + ((rt) >= 0) \ + ? (((int32_t)(rt) * 1000000L + (RTIMER_ARCH_SECOND / 2)) / RTIMER_ARCH_SECOND) \ + : (((int32_t)(rt) * 1000000L - (RTIMER_ARCH_SECOND / 2)) / RTIMER_ARCH_SECOND) \ + ) + +/* + * A 64-bit version because the 32-bit one cannot handle T >= 4295 ticks. + * Intended only for positive values of T. + */ +#define RTIMERTICKS_TO_US_64(rt) ( \ + (uint32_t)( \ + ((uint64_t)(rt) * 1000000 + (RTIMER_ARCH_SECOND / 2)) / RTIMER_ARCH_SECOND \ + )) +/*---------------------------------------------------------------------------*/ +#endif /* RTIMER_ARCH_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/dev/slip-arch.c b/arch/cpu/simplelink-cc13xx-cc26xx/dev/slip-arch.c new file mode 100644 index 000000000..d15148428 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/dev/slip-arch.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-cpu + * @{ + * + * \defgroup cc13xx-cc26xx-slip-arch SLIP for CC13xx/CC26xx. + * @{ + * + * \file + * Implementation of SLIP driver for CC13xx/CC26xx. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/slip.h" +/*---------------------------------------------------------------------------*/ +#include "uart0-arch.h" +/*---------------------------------------------------------------------------*/ +/** + * \brief Write a single byte over SLIP. + * \param c The byte to write. + */ +void +slip_arch_writeb(unsigned char c) +{ + uart0_write(&c, 1); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Initialize the SLIP driver. + */ +void +slip_arch_init(void) +{ + /* + * Set an input handler. In doing so, the driver will make sure that UART + * RX stays operational during deep sleep. + */ + uart0_init(); + uart0_set_callback(slip_input_byte); +} +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/dev/spi-arch.c b/arch/cpu/simplelink-cc13xx-cc26xx/dev/spi-arch.c new file mode 100644 index 000000000..f4c6114e8 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/dev/spi-arch.c @@ -0,0 +1,241 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-cpu + * @{ + * + * \defgroup cc13xx-cc26xx-spi CC13xx/CC26xx SPI HAL + * + * @{ + * \file + * Implementation of the SPI HAL driver for CC13xx/CC26xx. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "sys/cc.h" +#include "dev/spi.h" +/*---------------------------------------------------------------------------*/ +#include +#include +#include +/*---------------------------------------------------------------------------*/ +#include +#include +#include +/*---------------------------------------------------------------------------*/ +typedef struct { + SPI_Handle handle; + const spi_device_t *owner; +} spi_arch_t; +/*---------------------------------------------------------------------------*/ +#if (SPI_CONTROLLER_COUNT > 0) +static spi_arch_t spi_arches[SPI_CONTROLLER_COUNT]; +#else +static spi_arch_t *spi_arches = NULL; +#endif +/*---------------------------------------------------------------------------*/ +static inline spi_arch_t * +get_handle(uint8_t spi_controller) +{ + if(spi_controller < SPI_CONTROLLER_COUNT) { + return &spi_arches[spi_controller]; + } else { + return NULL; + } +} +/*---------------------------------------------------------------------------*/ +static SPI_FrameFormat +convert_frame_format(uint8_t pol, uint8_t pha) +{ + pol = (pol) ? 1 : 0; + pha = (pha) ? 1 : 0; + /* + * Convert pol/pha to a single byte on the following format: + * xxxA xxxB + * where A is the polarity bit and B is the phase bit. + * Note that any other value deviating from this format will + * default to the SPI_POL1_PHA1 format. + */ + uint8_t pol_pha = (pol << 4) | (pha << 0); + switch(pol_pha) { + case 0x00: return SPI_POL0_PHA0; + case 0x01: return SPI_POL0_PHA1; + case 0x10: return SPI_POL1_PHA0; + default: /* fallthrough */ + case 0x11: return SPI_POL1_PHA1; + } +} +/*---------------------------------------------------------------------------*/ +bool +spi_arch_has_lock(const spi_device_t *dev) +{ + /* + * The SPI device is the owner if the SPI controller returns a valid + * SPI arch object and the SPI device is owner of that object. + */ + spi_arch_t *spi_arch = get_handle(dev->spi_controller); + return (spi_arch != NULL) && (spi_arch->owner == dev); +} +/*---------------------------------------------------------------------------*/ +bool +spi_arch_is_bus_locked(const spi_device_t *dev) +{ + /* + * The SPI controller is locked by any device if the SPI controller returns + * a valid SPI arch object and the SPI handle of that object is valid. + */ + spi_arch_t *spi_arch = get_handle(dev->spi_controller); + return (spi_arch != NULL) && (spi_arch->handle != NULL); +} +/*---------------------------------------------------------------------------*/ +spi_status_t +spi_arch_lock_and_open(const spi_device_t *dev) +{ + uint_least8_t spi_index; + spi_arch_t *spi_arch; + SPI_Params spi_params; + + const uintptr_t hwi_key = HwiP_disable(); + + spi_index = dev->spi_controller; + spi_arch = get_handle(spi_index); + + /* Ensure the provided SPI index is valid. */ + if(spi_arch == NULL) { + HwiP_restore(hwi_key); + return SPI_DEV_STATUS_EINVAL; + } + + /* Ensure the corresponding SPI interface is not already locked. */ + if(spi_arch_is_bus_locked(dev)) { + HwiP_restore(hwi_key); + return SPI_DEV_STATUS_BUS_LOCKED; + } + + SPI_Params_init(&spi_params); + + spi_params.transferMode = SPI_MODE_BLOCKING; + spi_params.mode = SPI_MASTER; + spi_params.bitRate = dev->spi_bit_rate; + spi_params.dataSize = 8; + spi_params.frameFormat = convert_frame_format(dev->spi_pol, dev->spi_pha); + + /* + * Try to open the SPI driver. Accessing the SPI driver also ensures + * atomic access to the SPI interface. + */ + spi_arch->handle = SPI_open(spi_index, &spi_params); + + if(spi_arch->handle == NULL) { + HwiP_restore(hwi_key); + return SPI_DEV_STATUS_BUS_LOCKED; + } + + spi_arch->owner = dev; + + HwiP_restore(hwi_key); + return SPI_DEV_STATUS_OK; +} +/*---------------------------------------------------------------------------*/ +spi_status_t +spi_arch_close_and_unlock(const spi_device_t *dev) +{ + spi_arch_t *spi_arch; + + const uintptr_t hwi_key = HwiP_disable(); + + /* Ensure the provided SPI index is valid. */ + spi_arch = get_handle(dev->spi_controller); + if(spi_arch == NULL) { + HwiP_restore(hwi_key); + return SPI_DEV_STATUS_EINVAL; + } + + /* Ensure the corresponding SPI device owns the SPI controller. */ + if(!spi_arch_has_lock(dev)) { + HwiP_restore(hwi_key); + return SPI_DEV_STATUS_BUS_NOT_OWNED; + } + + SPI_close(spi_arch->handle); + + spi_arch->handle = NULL; + spi_arch->owner = NULL; + + HwiP_restore(hwi_key); + return SPI_DEV_STATUS_OK; +} +/*---------------------------------------------------------------------------*/ +spi_status_t +spi_arch_transfer(const spi_device_t *dev, + const uint8_t *write_buf, int wlen, + uint8_t *inbuf, int rlen, int ignore_len) +{ + spi_arch_t *spi_arch; + size_t totlen; + SPI_Transaction spi_transaction; + bool transfer_ok; + + /* Ensure the provided SPI index is valid. */ + spi_arch = get_handle(dev->spi_controller); + if(spi_arch == NULL) { + return SPI_DEV_STATUS_EINVAL; + } + + if(!spi_arch_has_lock(dev)) { + return SPI_DEV_STATUS_BUS_NOT_OWNED; + } + + totlen = MAX((size_t)(rlen + ignore_len), (size_t)wlen); + + if(totlen == 0) { + /* Nothing to do */ + return SPI_DEV_STATUS_OK; + } + + spi_transaction.count = totlen; + spi_transaction.txBuf = (void *)write_buf; + spi_transaction.rxBuf = (void *)inbuf; + + transfer_ok = SPI_transfer(spi_arch->handle, &spi_transaction); + + if(!transfer_ok) { + return SPI_DEV_STATUS_TRANSFER_ERR; + } + + return SPI_DEV_STATUS_OK; +} +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/dev/startup_cc13xx_cc26xx_gcc.c b/arch/cpu/simplelink-cc13xx-cc26xx/dev/startup_cc13xx_cc26xx_gcc.c new file mode 100644 index 000000000..7b34cd29b --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/dev/startup_cc13xx_cc26xx_gcc.c @@ -0,0 +1,311 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-cpu + * @{ + * + * \file + * Startup file for GCC for CC13xx/CC26xx. + */ +/*---------------------------------------------------------------------------*/ +/* Check if compiler is GNU Compiler. */ +#if !(defined(__GNUC__)) +#error "startup_cc13xx_cc26xx_gcc.c: Unsupported compiler!" +#endif +/*---------------------------------------------------------------------------*/ +#include + +#include +#include DeviceFamily_constructPath(inc/hw_types.h) +#include DeviceFamily_constructPath(driverlib/interrupt.h) +#include DeviceFamily_constructPath(driverlib/setup.h) +/*---------------------------------------------------------------------------*/ +/* Forward declaration of the default fault handlers. */ +void resetISR(void); +static void nmiISR(void); +static void faultISR(void); +static void defaultHandler(void); +static void busFaultHandler(void); +/*---------------------------------------------------------------------------*/ +/* + * External declaration for the reset handler that is to be called when the + * processor is started. + */ +extern void _c_int00(void); + +/* The entry point for the application. */ +extern int main(void); +/*---------------------------------------------------------------------------*/ +/* Linker variable that marks the top of stack. */ +extern unsigned long _stack_end; + +/* + * The vector table. Note that the proper constructs must be placed on this to + * ensure that it ends up at physical address 0x0000.0000. + */ +__attribute__((section(".resetVecs"))) __attribute__((used)) +static void(*const resetVectors[16])(void) = +{ + (void(*)(void))((uint32_t)&_stack_end), + /* The initial stack pointer */ + resetISR, /* The reset handler */ + nmiISR, /* The NMI handler */ + faultISR, /* The hard fault handler */ + defaultHandler, /* The MPU fault handler */ + busFaultHandler, /* The bus fault handler */ + defaultHandler, /* The usage fault handler */ + 0, /* Reserved */ + 0, /* Reserved */ + 0, /* Reserved */ + 0, /* Reserved */ + defaultHandler, /* SVCall handler */ + defaultHandler, /* Debug monitor handler */ + 0, /* Reserved */ + defaultHandler, /* The PendSV handler */ + defaultHandler /* The SysTick handler */ +}; +/*---------------------------------------------------------------------------*/ +/* + * The following are arrays of pointers to constructor functions that need to + * be called during startup to initialize global objects. + */ +extern void (*__init_array_start[])(void); +extern void (*__init_array_end[])(void); + +/* The following global variable is required for C++ support. */ +void *__dso_handle = (void *)&__dso_handle; +/*---------------------------------------------------------------------------*/ +/* + * The following are constructs created by the linker, indicating where the + * the "data" and "bss" segments reside in memory. The initializers for the + * for the "data" segment resides immediately following the "text" segment. + */ +extern uint32_t __bss_start__; +extern uint32_t __bss_end__; +extern uint32_t __data_load__; +extern uint32_t __data_start__; +extern uint32_t __data_end__; +/*---------------------------------------------------------------------------*/ +/* + * \brief Entry point of the startup code. + * + * Initialize the .data and .bss sections, and call main. + */ +void +localProgramStart(void) +{ + uint32_t *bs; + uint32_t *be; + uint32_t *dl; + uint32_t *ds; + uint32_t *de; + uint32_t count; + uint32_t i; + + IntMasterDisable(); + + /* Final trim of device */ + SetupTrimDevice(); + + /* initiailize .bss to zero */ + bs = &__bss_start__; + be = &__bss_end__; + while(bs < be) { + *bs = 0; + bs++; + } + + /* relocate the .data section */ + dl = &__data_load__; + ds = &__data_start__; + de = &__data_end__; + if(dl != ds) { + while(ds < de) { + *ds = *dl; + dl++; + ds++; + } + } + + /* Run any constructors */ + count = (uint32_t)(__init_array_end - __init_array_start); + for(i = 0; i < count; i++) { + __init_array_start[i](); + } + + /* Call the application's entry point. */ + main(); + + /* If we ever return signal Error */ + faultISR(); +} +/*---------------------------------------------------------------------------*/ +/* + * \brief Reset ISR. + * + * This is the code that gets called when the processor first starts execution + * following a reset event. Only the absolutely necessary set is performed, + * after which the application supplied entry() routine is called. Any fancy + * actions (such as making decisions based on the reset cause register, and + * resetting the bits in that register) are left solely in the hands of the + * application. + */ +void __attribute__((naked)) +resetISR(void) +{ + __asm__ __volatile__ + ( + "movw r0, #:lower16:resetVectors \n" + "movt r0, #:upper16:resetVectors \n" + "ldr r0, [r0] \n" + "mov sp, r0 \n" + "bx %0 \n" + : /* output */ + : /* input */ + "r"(localProgramStart) + ); +} +/*---------------------------------------------------------------------------*/ +/* + * \brief Non-Maskable Interrupt (NMI) ISR. + * + * This is the code that gets called when the processor receives a NMI. This + * simply enters an infinite loop, preserving the system state for examination + * by a debugger. + */ +static void +nmiISR(void) +{ + /* Enter an infinite loop. */ + for(;;) { /* hang */ } +} +/*---------------------------------------------------------------------------*/ +/* + * \brief Debug stack pointer. + * \param sp Stack pointer. + * + * Provide a view into the CPU state from the provided stack pointer. + */ +static void +debugHardfault(uint32_t *sp) +{ + volatile uint32_t r0; /**< R0 register */ + volatile uint32_t r1; /**< R1 register */ + volatile uint32_t r2; /**< R2 register */ + volatile uint32_t r3; /**< R3 register */ + volatile uint32_t r12; /**< R12 register */ + volatile uint32_t lr; /**< LR register */ + volatile uint32_t pc; /**< PC register */ + volatile uint32_t psr; /**< PSR register */ + + (void)(r0 = sp[0]); + (void)(r1 = sp[1]); + (void)(r2 = sp[2]); + (void)(r3 = sp[3]); + (void)(r12 = sp[4]); + (void)(lr = sp[5]); + (void)(pc = sp[6]); + (void)(psr = sp[7]); + + /* Enter an infinite loop. */ + for(;;) { /* hang */ } +} +/*---------------------------------------------------------------------------*/ +/* + * \brief CPU Fault ISR. + * + * This is the code that gets called when the processor receives a fault + * interrupt. Setup a call to debugStackPointer with the current stack pointer. + * The stack pointer in this case would be the CPU state which caused the CPU + * fault. + */ +static void +faultISR(void) +{ + __asm__ __volatile__ + ( + "tst lr, #4 \n" + "ite eq \n" + "mrseq r0, msp \n" + "mrsne r0, psp \n" + "bx %0 \n" + : /* output */ + : /* input */ + "r"(debugHardfault) + ); +} +/*---------------------------------------------------------------------------*/ +/* Dummy variable */ +volatile int x__; + +/* + * \brief Bus Fault Handler. + * + * This is the code that gets called when the processor receives an unexpected + * interrupt. This simply enters an infinite loop, preserving the system state + * for examination by a debugger. + */ +static void +busFaultHandler(void) +{ + x__ = 0; + + /* Enter an infinite loop. */ + for(;;) { /* hang */ } +} +/*---------------------------------------------------------------------------*/ +/* + * \brief Default Handler. + * + * This is the code that gets called when the processor receives an unexpected + * interrupt. This simply enters an infinite loop, preserving the system state + * for examination by a debugger. + */ +static void +defaultHandler(void) +{ + /* Enter an infinite loop. */ + for(;;) { /* hang */ } +} +/*---------------------------------------------------------------------------*/ +/* + * \brief Finalize object function. + * + * This function is called by __libc_fini_array which gets called when exit() + * is called. In order to support exit(), an empty _fini() stub function is + * required. + */ +void +_fini(void) +{ + /* Function body left empty intentionally */ +} +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/dev/startup_cc13xx_cc26xx_iar.c b/arch/cpu/simplelink-cc13xx-cc26xx/dev/startup_cc13xx_cc26xx_iar.c new file mode 100644 index 000000000..3ea8500c2 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/dev/startup_cc13xx_cc26xx_iar.c @@ -0,0 +1,318 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-cpu + * @{ + * + * \file + * Startup file for IAR for CC13xx/CC26xx. + */ +/*---------------------------------------------------------------------------*/ +/* Check if compiler is IAR. */ +#if !(defined(__IAR_SYSTEMS_ICC__)) +#error "startup_cc13xx_cc26xx_iar.c: Unsupported compiler!" +#endif +/*---------------------------------------------------------------------------*/ +/* We need intrinsic functions for IAR (if used in source code). */ +#include + +#include +#include DeviceFamily_constructPath(inc/hw_types.h) +#include DeviceFamily_constructPath(driverlib/setup.h) +#include DeviceFamily_constructPath(driverlib/interrupt.h) +/*---------------------------------------------------------------------------*/ +/* Forward declaration of the reset ISR and the default fault handlers. */ +static void nmiISR(void); +static void faultISR(void); +static void intDefaultHandler(void); +extern int main(void); + +extern void MPUFaultIntHandler(void); +extern void BusFaultIntHandler(void); +extern void UsageFaultIntHandler(void); +extern void SVCallIntHandler(void); +extern void DebugMonIntHandler(void); +extern void PendSVIntHandler(void); +extern void SysTickIntHandler(void); +extern void GPIOIntHandler(void); +extern void I2CIntHandler(void); +extern void RFCCPE1IntHandler(void); +extern void AONRTCIntHandler(void); +extern void UART0IntHandler(void); +extern void AUXSWEvent0IntHandler(void); +extern void SSI0IntHandler(void); +extern void SSI1IntHandler(void); +extern void RFCCPE0IntHandler(void); +extern void RFCHardwareIntHandler(void); +extern void RFCCmdAckIntHandler(void); +extern void I2SIntHandler(void); +extern void AUXSWEvent1IntHandler(void); +extern void WatchdogIntHandler(void); +extern void Timer0AIntHandler(void); +extern void Timer0BIntHandler(void); +extern void Timer1AIntHandler(void); +extern void Timer1BIntHandler(void); +extern void Timer2AIntHandler(void); +extern void Timer2BIntHandler(void); +extern void Timer3AIntHandler(void); +extern void Timer3BIntHandler(void); +extern void CryptoIntHandler(void); +extern void uDMAIntHandler(void); +extern void uDMAErrIntHandler(void); +extern void FlashIntHandler(void); +extern void SWEvent0IntHandler(void); +extern void AUXCombEventIntHandler(void); +extern void AONProgIntHandler(void); +extern void DynProgIntHandler(void); +extern void AUXCompAIntHandler(void); +extern void AUXADCIntHandler(void); +extern void TRNGIntHandler(void); + +/* Default interrupt handlers */ +#pragma weak MPUFaultIntHandler = intDefaultHandler +#pragma weak BusFaultIntHandler = intDefaultHandler +#pragma weak UsageFaultIntHandler = intDefaultHandler +#pragma weak SVCallIntHandler = intDefaultHandler +#pragma weak DebugMonIntHandler = intDefaultHandler +#pragma weak PendSVIntHandler = intDefaultHandler +#pragma weak SysTickIntHandler = intDefaultHandler +#pragma weak GPIOIntHandler = intDefaultHandler +#pragma weak I2CIntHandler = intDefaultHandler +#pragma weak RFCCPE1IntHandler = intDefaultHandler +#pragma weak AONRTCIntHandler = intDefaultHandler +#pragma weak UART0IntHandler = intDefaultHandler +#pragma weak AUXSWEvent0IntHandler = intDefaultHandler +#pragma weak SSI0IntHandler = intDefaultHandler +#pragma weak SSI1IntHandler = intDefaultHandler +#pragma weak RFCCPE0IntHandler = intDefaultHandler +#pragma weak RFCHardwareIntHandler = intDefaultHandler +#pragma weak RFCCmdAckIntHandler = intDefaultHandler +#pragma weak I2SIntHandler = intDefaultHandler +#pragma weak AUXSWEvent1IntHandler = intDefaultHandler +#pragma weak WatchdogIntHandler = intDefaultHandler +#pragma weak Timer0AIntHandler = intDefaultHandler +#pragma weak Timer0BIntHandler = intDefaultHandler +#pragma weak Timer1AIntHandler = intDefaultHandler +#pragma weak Timer1BIntHandler = intDefaultHandler +#pragma weak Timer2AIntHandler = intDefaultHandler +#pragma weak Timer2BIntHandler = intDefaultHandler +#pragma weak Timer3AIntHandler = intDefaultHandler +#pragma weak Timer3BIntHandler = intDefaultHandler +#pragma weak CryptoIntHandler = intDefaultHandler +#pragma weak uDMAIntHandler = intDefaultHandler +#pragma weak uDMAErrIntHandler = intDefaultHandler +#pragma weak FlashIntHandler = intDefaultHandler +#pragma weak SWEvent0IntHandler = intDefaultHandler +#pragma weak AUXCombEventIntHandler = intDefaultHandler +#pragma weak AONProgIntHandler = intDefaultHandler +#pragma weak DynProgIntHandler = intDefaultHandler +#pragma weak AUXCompAIntHandler = intDefaultHandler +#pragma weak AUXADCIntHandler = intDefaultHandler +#pragma weak TRNGIntHandler = intDefaultHandler +/*---------------------------------------------------------------------------*/ +/* The entry point for the application startup code. */ +extern void __iar_program_start(void); + +/* Get stack start (highest address) symbol from linker file. */ +extern const void *STACK_TOP; +/*---------------------------------------------------------------------------*/ +/* + * It is required to place something in the CSTACK segment to get the stack + * check feature in IAR to work as expected + */ +__root static void *dummy_stack @ ".stack"; + +/* + * The vector table. Note that the proper constructs must be placed on this to + * ensure that it ends up at physical address 0x0000.0000 or at the start of + * the program if located at a start address other than 0. + */ +__root void(*const __vector_table[])(void) @ ".intvec" = +{ + (void (*)(void)) & STACK_TOP, /* 0 The initial stack pointer */ + __iar_program_start, /* 1 The reset handler */ + nmiISR, /* 2 The NMI handler */ + faultISR, /* 3 The hard fault handler */ + MPUFaultIntHandler, /* 4 The MPU fault handler */ + BusFaultIntHandler, /* 5 The bus fault handler */ + UsageFaultIntHandler, /* 6 The usage fault handler */ + 0, /* 7 Reserved */ + 0, /* 8 Reserved */ + 0, /* 9 Reserved */ + 0, /* 10 Reserved */ + SVCallIntHandler, /* 11 SVCall handler */ + DebugMonIntHandler, /* 12 Debug monitor handler */ + 0, /* 13 Reserved */ + PendSVIntHandler, /* 14 The PendSV handler */ + SysTickIntHandler, /* 15 The SysTick handler */ + /* --- External interrupts --- */ + GPIOIntHandler, /* 16 AON edge detect */ + I2CIntHandler, /* 17 I2C */ + RFCCPE1IntHandler, /* 18 RF Core Command & Packet Engine 1 */ + intDefaultHandler, /* 19 Reserved */ + AONRTCIntHandler, /* 20 AON RTC */ + UART0IntHandler, /* 21 UART0 Rx and Tx */ + AUXSWEvent0IntHandler, /* 22 AUX software event 0 */ + SSI0IntHandler, /* 23 SSI0 Rx and Tx */ + SSI1IntHandler, /* 24 SSI1 Rx and Tx */ + RFCCPE0IntHandler, /* 25 RF Core Command & Packet Engine 0 */ + RFCHardwareIntHandler, /* 26 RF Core Hardware */ + RFCCmdAckIntHandler, /* 27 RF Core Command Acknowledge */ + I2SIntHandler, /* 28 I2S */ + AUXSWEvent1IntHandler, /* 29 AUX software event 1 */ + WatchdogIntHandler, /* 30 Watchdog timer */ + Timer0AIntHandler, /* 31 Timer 0 subtimer A */ + Timer0BIntHandler, /* 32 Timer 0 subtimer B */ + Timer1AIntHandler, /* 33 Timer 1 subtimer A */ + Timer1BIntHandler, /* 34 Timer 1 subtimer B */ + Timer2AIntHandler, /* 35 Timer 2 subtimer A */ + Timer2BIntHandler, /* 36 Timer 2 subtimer B */ + Timer3AIntHandler, /* 37 Timer 3 subtimer A */ + Timer3BIntHandler, /* 38 Timer 3 subtimer B */ + CryptoIntHandler, /* 39 Crypto Core Result available */ + uDMAIntHandler, /* 40 uDMA Software */ + uDMAErrIntHandler, /* 41 uDMA Error */ + FlashIntHandler, /* 42 Flash controller */ + SWEvent0IntHandler, /* 43 Software Event 0 */ + AUXCombEventIntHandler, /* 44 AUX combined event */ + AONProgIntHandler, /* 45 AON programmable 0 */ + DynProgIntHandler, /* 46 Dynamic Programmable interrupt */ + /* source (Default: PRCM) */ + AUXCompAIntHandler, /* 47 AUX Comparator A */ + AUXADCIntHandler, /* 48 AUX ADC new sample or ADC DMA */ + /* done, ADC underflow, ADC overflow */ + TRNGIntHandler /* 49 TRNG event */ +} +/*---------------------------------------------------------------------------*/ +/* + * \brief Setup trim device. + * \return Return value determines whether to omit seg_init or not. + * 0 => omit seg_init + * 1 => run seg_init + * + * This function is called by __iar_program_start() early in the boot sequence. + * Copy the first 16 vectors from the read-only/reset table to the runtime + * RAM table. Fill the remaining vectors with a stub. This vector table will + * be updated at runtime. + */ +int +__low_level_init(void) +{ + IntMasterDisable(); + + /* Final trim of device */ + SetupTrimDevice(); + + /* Run seg_init */ + return 1; +} +/*---------------------------------------------------------------------------*/ +/* + * \brief Non-Maskable Interrupt (NMI) ISR. + * + * This is the code that gets called when the processor receives a NMI. This + * simply enters an infinite loop, preserving the system state for examination + * by a debugger. + */ +static void +nmiISR(void) +{ + /* Enter an infinite loop. */ + for(;;) { /* hang */ } +} +/*---------------------------------------------------------------------------*/ +/* + * \brief Debug stack pointer. + * \param sp Stack pointer. + * + * Provide a view into the CPU state from the provided stack pointer. + */ +void +debugStackPointer(uint32_t *sp) +{ + volatile uint32_t r0; /**< R0 register */ + volatile uint32_t r1; /**< R1 register */ + volatile uint32_t r2; /**< R2 register */ + volatile uint32_t r3; /**< R3 register */ + volatile uint32_t r12; /**< R12 register */ + volatile uint32_t lr; /**< LR register */ + volatile uint32_t pc; /**< PC register */ + volatile uint32_t psr; /**< PSR register */ + + /* Cast to void to disable warnings of unused variables */ + (void)(r0 = sp[0]); + (void)(r1 = sp[1]); + (void)(r2 = sp[2]); + (void)(r3 = sp[3]); + (void)(r12 = sp[4]); + (void)(lr = sp[5]); + (void)(pc = sp[6]); + (void)(psr = sp[7]); + + /* Enter an infinite loop. */ + for(;;) { /* hang */ } +} +/*---------------------------------------------------------------------------*/ +/* + * \brief CPU Fault ISR. + * + * This is the code that gets called when the processor receives a fault + * interrupt. Setup a call to debugStackPointer with the current stack pointer. + * The stack pointer in this case would be the CPU state which caused the CPU + * fault. + */ +static void +faultISR(void) +{ + __asm__ __volatile__ + ( + "tst lr, #4 \n" + "ite eq \n" + "mrseq r0, msp \n" + "mrsne r0, psp \n" + "b debugStackPointer \n" + ); +} +/*---------------------------------------------------------------------------*/ +/* + * \brief Interrupt Default Handler. + * + * This is the code that gets called when the processor receives an unexpected + * interrupt. This simply enters an infinite loop, preserving the system state + * for examination by a debugger. + */ +static void +intDefaultHandler(void) +{ + /* Enter an infinite loop. */ + for(;;) { /* hang */ } +} +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/dev/trng-arch.c b/arch/cpu/simplelink-cc13xx-cc26xx/dev/trng-arch.c new file mode 100644 index 000000000..d04410bff --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/dev/trng-arch.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-trng + * @{ + * + * \file + * Implementation of True Random Number Generator for CC13xx/CC26xx. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" + +#include "trng-arch.h" +/*---------------------------------------------------------------------------*/ +#include +#include +/*---------------------------------------------------------------------------*/ +/* + * Very dirty workaround because the pre-compiled TI drivers library for + * CC13x0/CC26x0 is missing the CryptoKey object file. This can be removed + * when the pre-compiled library includes the missing object file. + */ +#include +#if (DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X0_CC26X0) +#include +#endif +/*---------------------------------------------------------------------------*/ +#include +#include +/*---------------------------------------------------------------------------*/ +bool +trng_rand(uint8_t *entropy_buf, size_t entropy_len, uint32_t timeout_us) +{ + TRNG_Params trng_params; + TRNG_Handle trng_handle; + CryptoKey entropy_key; + int_fast16_t result; + + TRNG_Params_init(&trng_params); + trng_params.returnBehavior = TRNG_RETURN_BEHAVIOR_BLOCKING; + if(timeout_us != TRNG_WAIT_FOREVER) { + trng_params.timeout = timeout_us; + } + + trng_handle = TRNG_open(0, &trng_params); + if(!trng_handle) { + return false; + } + + CryptoKeyPlaintext_initBlankKey(&entropy_key, entropy_buf, entropy_len); + + result = TRNG_generateEntropy(trng_handle, &entropy_key); + + TRNG_close(trng_handle); + + return result == TRNG_STATUS_SUCCESS; +} +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/dev/trng-arch.h b/arch/cpu/simplelink-cc13xx-cc26xx/dev/trng-arch.h new file mode 100644 index 000000000..fc25b9169 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/dev/trng-arch.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-cpu + * @{ + * + * \defgroup cc13xx-cc26xx-trng True Random Number Generator for CC13xx/CC26xx. + * @{ + * + * \file + * Header file of True Random Number Generator for CC13xx/CC26xx. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#ifndef TRNG_ARCH_H_ +#define TRNG_ARCH_H_ +/*---------------------------------------------------------------------------*/ +#include +/*---------------------------------------------------------------------------*/ +#include +#include +/*---------------------------------------------------------------------------*/ +#define TRNG_WAIT_FOREVER (~(uint32_t)0) +/*---------------------------------------------------------------------------*/ +/** + * \brief Generates a stream of entropy from which you can create + * a true random number from. This is a blocking function + * call with a specified timeout. + * \param entropy_buf Buffer to store a stream of entropy. + * \param entropy_len Length of the entropy buffer. + * \param timeout_us How long to wait until timing out the operation. A + * timeout of TRNG_WAIT_FOREVER blocks forever. + * \return true if successful; else, false. + */ +bool trng_rand(uint8_t *entropy_buf, size_t entropy_len, uint32_t timeout_us); +/*---------------------------------------------------------------------------*/ +#endif /* TRNG_ARCH_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/dev/uart0-arch.c b/arch/cpu/simplelink-cc13xx-cc26xx/dev/uart0-arch.c new file mode 100644 index 000000000..d9dbfb30a --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/dev/uart0-arch.c @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-uart + * @{ + * + * \file + * Implementation of UART driver for CC13xx/CC26xx. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +/*---------------------------------------------------------------------------*/ +#include "uart0-arch.h" +/*---------------------------------------------------------------------------*/ +#include + +#include +/*---------------------------------------------------------------------------*/ +#include +#include +/*---------------------------------------------------------------------------*/ +static UART_Handle uart_handle; + +static volatile uart0_input_fxn_t curr_input_cb; +static unsigned char char_buf; + +static bool initialized; +/*---------------------------------------------------------------------------*/ +static void +uart0_cb(UART_Handle handle, void *buf, size_t count) +{ + /* Simply return if the current callback is NULL. */ + if(!curr_input_cb) { + return; + } + + /* + * Save the current callback function locally, as it might be overwritten + * after calling the callback. + */ + const uart0_input_fxn_t curr_cb = curr_input_cb; + curr_cb(char_buf); + /* + * If curr_input_cb didn't change after the call, do another read. + * Else, the uart0_set_callback was called with a different callback pointer + * and triggered an another read. + */ + if(curr_cb == curr_input_cb) { + UART_read(uart_handle, &char_buf, 1); + } +} +/*---------------------------------------------------------------------------*/ +void +uart0_init(void) +{ + if(initialized) { + return; + } + + UART_Params uart_params; + UART_Params_init(&uart_params); + + uart_params.baudRate = TI_UART_CONF_BAUD_RATE; + uart_params.readMode = UART_MODE_CALLBACK; + uart_params.writeMode = UART_MODE_BLOCKING; + uart_params.readCallback = uart0_cb; + uart_params.readDataMode = UART_DATA_TEXT; + uart_params.readReturnMode = UART_RETURN_NEWLINE; + + /* No error handling. */ + uart_handle = UART_open(Board_UART0, &uart_params); + + initialized = true; +} +/*---------------------------------------------------------------------------*/ +int_fast32_t +uart0_write(const void *buf, size_t buf_size) +{ + if(!initialized) { + return UART_STATUS_ERROR; + } + return UART_write(uart_handle, buf, buf_size); +} +/*---------------------------------------------------------------------------*/ +int_fast32_t +uart0_write_byte(uint8_t byte) +{ + if(!initialized) { + return UART_STATUS_ERROR; + } + return UART_write(uart_handle, &byte, 1); +} +/*---------------------------------------------------------------------------*/ +int_fast32_t +uart0_set_callback(uart0_input_fxn_t input_cb) +{ + if(!initialized) { + return UART_STATUS_ERROR; + } + + if(curr_input_cb == input_cb) { + return UART_STATUS_SUCCESS; + } + + curr_input_cb = input_cb; + if(input_cb) { + return UART_read(uart_handle, &char_buf, 1); + } else { + UART_readCancel(uart_handle); + return UART_STATUS_SUCCESS; + } +} +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/dev/uart0-arch.h b/arch/cpu/simplelink-cc13xx-cc26xx/dev/uart0-arch.h new file mode 100644 index 000000000..9d4a69fe1 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/dev/uart0-arch.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-cpu + * @{ + * + * \defgroup cc13xx-cc26xx-uart UART for CC13xx/CC26xx. + * + * This particular driver utilizes the UART0 peripheral specifically. + * + * Driver for the CC13xx/CC26xx UART controller. + * @{ + * + * \file + * Header file of UART driver for CC13xx/CC26xx. + * \author + * Edvard Pettersen + */ +#ifndef UART0_ARCH_H_ +#define UART0_ARCH_H_ +/*---------------------------------------------------------------------------*/ +#include +#include +/*---------------------------------------------------------------------------*/ +typedef int (*uart0_input_fxn_t)(unsigned char); +/*---------------------------------------------------------------------------*/ +/** + * \brief Initializes the UART driver. + */ +void uart0_init(void); + +/** + * \brief Writes data from a memory buffer to the UART interface. + * \param buf A pointer to the data buffer. + * \param buf_size Size of the data buffer. + * \return Number of bytes that has been written to the UART. If an + * error occurs, a negative value is returned. + */ +int_fast32_t uart0_write(const void *buf, size_t buf_size); + +/** + * \brief Writes a single byte to the UART interface. + * \param byte Byte to write. + * \return Number of bytes that has been written to the UART. If an + * error occurs, a negative value is returned. + */ +int_fast32_t uart0_write_byte(uint8_t byte); + +/** + * \brief Set the callback function for when bytes are received + * on UART0. + * \param input_cb Pointer to the callback function. A valid pointer + * subscribes for UART0 callbacks when bytes are received, + * while a NULL pointer unsubscribes. + * \return 0 for success, negative value for errors. + */ +int_fast32_t uart0_set_callback(uart0_input_fxn_t input_cb); +/*---------------------------------------------------------------------------*/ +#endif /* UART0_ARCH_H_ */ +/** + * @} + * @} + */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/dev/watchdog-arch.c b/arch/cpu/simplelink-cc13xx-cc26xx/dev/watchdog-arch.c new file mode 100644 index 000000000..6cba086b4 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/dev/watchdog-arch.c @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ + /** + * \addtogroup cc13xx-cc26xx-cpu + * @{ + * + * \defgroup cc13xx-cc26xx-watchdog CC13xx/CC26xx watchdog timer driver + * + * Driver for the CC13xx/CC26xx Watchdog Timer + * + * This file is not called watchdog.c because the filename is in use by + * TI CC26xxware/CC13xxware + * @{ + * + * \file + * Implementation of the CC13xx/CC26xx watchdog driver. + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/watchdog.h" +/*---------------------------------------------------------------------------*/ +#include + +#include +/*---------------------------------------------------------------------------*/ +#include +#include +/*---------------------------------------------------------------------------*/ +#define WATCHDOG_DISABLE WATCHDOG_CONF_DISABLE +#define WATCHDOG_TIMER_TOP WATCHDOG_CONF_TIMER_TOP +/*---------------------------------------------------------------------------*/ +static Watchdog_Handle wdt_handle; +/*---------------------------------------------------------------------------*/ +/** + * \brief Initialises the Watchdog module. + * + * Simply sets the reload counter to a default value. The WDT is not + * started yet. To start it, watchdog_start() must be called. + */ +void +watchdog_init(void) +{ + if(WATCHDOG_DISABLE) { + return; + } + + Watchdog_init(); + + Watchdog_Params wdt_params; + Watchdog_Params_init(&wdt_params); + + wdt_params.resetMode = Watchdog_RESET_ON; + wdt_params.debugStallMode = Watchdog_DEBUG_STALL_ON; + + wdt_handle = Watchdog_open(Board_WATCHDOG0, &wdt_params); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Start the Watchdog. + */ +void +watchdog_start(void) +{ + if(WATCHDOG_DISABLE) { + return; + } + + watchdog_periodic(); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Refresh (feed) the Watchdog. + */ +void +watchdog_periodic(void) +{ + if(WATCHDOG_DISABLE) { + return; + } + + Watchdog_setReload(wdt_handle, WATCHDOG_TIMER_TOP); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Stop the Watchdog such that it won't timeout and cause a + * system reset. + */ +void +watchdog_stop(void) +{ + if(WATCHDOG_DISABLE) { + return; + } + + Watchdog_clear(wdt_handle); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Manually trigger a Watchdog timeout. + */ +void +watchdog_reboot(void) +{ + if(WATCHDOG_DISABLE) { + return; + } + + watchdog_start(); + + /* Busy loop until watchdog times out */ + for (;;) { /* hang */ } +} +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/doxygen-group.txt b/arch/cpu/simplelink-cc13xx-cc26xx/doxygen-group.txt new file mode 100644 index 000000000..ca6159c44 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/doxygen-group.txt @@ -0,0 +1,16 @@ +/** + * \defgroup cc13xx-cc26xx-cpu The TI SimpleLink CC13xx and CC26xx SoC + * + * This group documents the TI CC13xx and CC26xx CPUs. The two CPU families are + * very similar, with the main difference being related to radio capability. + * + * Documentation in this group should be considered to be applicable to both + * families, unless explicitly stated otherwise. + * + * \ingroup cpu + */ + +/** + * \defgroup cc13xx-cc26xx-platform TI SimpleLink CC13xx/CC26xx platform + * \ingroup platform + */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/lib/coresdk_cc13xx_cc26xx b/arch/cpu/simplelink-cc13xx-cc26xx/lib/coresdk_cc13xx_cc26xx new file mode 160000 index 000000000..b83faf3be --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/lib/coresdk_cc13xx_cc26xx @@ -0,0 +1 @@ +Subproject commit b83faf3be2cb7468dc836a6fbd9d804638263252 diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ble-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ble-settings.c new file mode 100644 index 000000000..7fc79ae2d --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ble-settings.c @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/*---------------------------------------------------------------------------*/ +/* + * Parameter summary + * Adv. Address: 010203040506 + * Adv. Data: 255 + * BLE Channel: 17 + * Frequency: 2440 MHz + * PDU Payload length: 30 + * TX Power: 9 dBm (requires define CCFG_FORCE_VDDR_HH = 1 in ccfg.c, + * see CC13xx/CC26xx Technical Reference Manual) + * Whitening: true + */ +/*---------------------------------------------------------------------------*/ +#include "sys/cc.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_ble_cmd.h) +#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_ble.h) +#include DeviceFamily_constructPath(rf_patches/rf_patch_rfe_ble.h) + +#include +/*---------------------------------------------------------------------------*/ +#include "ble-settings.h" +/*---------------------------------------------------------------------------*/ +/* TI-RTOS RF Mode Object */ +RF_Mode rf_ble_mode = +{ + .rfMode = RF_MODE_BLE, + .cpePatchFxn = &rf_patch_cpe_ble, + .mcePatchFxn = 0, + .rfePatchFxn = &rf_patch_rfe_ble, +}; +/*---------------------------------------------------------------------------*/ +/* Overrides for CMD_RADIO_SETUP */ +uint32_t rf_ble_overrides[] CC_ALIGN(4) = +{ + /* override_use_patch_ble_1mbps.xml */ + MCE_RFE_OVERRIDE(0,0,0,1,0,0), /* PHY: Use MCE ROM, RFE RAM patch */ + /* override_synth_ble_1mbps.xml */ + HW_REG_OVERRIDE(0x4038,0x0034), /* Synth: Set recommended RTRIM to 4 */ + (uint32_t)0x000784A3, /* Synth: Set Fref to 3.43 MHz */ + HW_REG_OVERRIDE(0x4020,0x7F00), /* Synth: Configure fine calibration setting */ + HW_REG_OVERRIDE(0x4064,0x0040), /* Synth: Configure fine calibration setting */ + (uint32_t)0xB1070503, /* Synth: Configure fine calibration setting */ + (uint32_t)0x05330523, /* Synth: Configure fine calibration setting */ + (uint32_t)0xA47E0583, /* Synth: Set loop bandwidth after lock to 80 kHz */ + (uint32_t)0xEAE00603, /* Synth: Set loop bandwidth after lock to 80 kHz */ + (uint32_t)0x00010623, /* Synth: Set loop bandwidth after lock to 80 kHz */ + HW32_ARRAY_OVERRIDE(0x405C,1), /* Synth: Configure PLL bias */ + (uint32_t)0x18000000, /* Synth: Configure PLL bias */ + /* Synth: Configure VCO LDO */ + ADI_REG_OVERRIDE(1,4,0x9F), /* (in ADI1, set VCOLDOCFG=0x9F to use voltage input reference) */ + ADI_HALFREG_OVERRIDE(1,7,0x4,0x4), /* Synth: Configure synth LDO (in ADI1, set SLDOCTL0.COMP_CAP=1) */ + /* override_phy_ble_1mbps.xml */ + (uint32_t)0x013800C3, /* Tx: Configure symbol shape for BLE frequency deviation requirements */ + HW_REG_OVERRIDE(0x6088, 0x0045), /* Rx: Configure AGC reference level */ + HW_REG_OVERRIDE(0x6084, 0x05FD), /* Rx: Configure AGC gain level */ + (uint32_t)0x00038883, /* Rx: Configure LNA bias current trim offset */ + /* override_frontend_xd.xml */ + (uint32_t)0x00F388A3, /* Rx: Set RSSI offset to adjust reported RSSI by +13 dB */ + /* TX power override */ + ADI_REG_OVERRIDE(0,12,0xF8), /* Tx: Set PA trim to max (in ADI0, set PACTL0=0xF8) */ + (uint32_t)0xFFFFFFFF, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_RADIO_SETUP: Radio Setup Command for Pre-Defined Schemes */ +rfc_CMD_RADIO_SETUP_t rf_ble_cmd_radio_setup = +{ + .commandNo = CMD_RADIO_SETUP, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .mode = 0x00, + .loDivider = 0x00, + .config.frontEndMode = 0x0, + .config.biasMode = 0x0, + .config.analogCfgMode = 0x0, + .config.bNoFsPowerUp = 0x0, + .txPower = 0x3D3F, + .pRegOverride = rf_ble_overrides, +}; +/*---------------------------------------------------------------------------*/ +/* Structure for CMD_BLE_ADV_NC.pParams */ +rfc_bleAdvPar_t rf_ble_adv_par = +{ + .pRxQ = 0, + .rxConfig.bAutoFlushIgnored = 0x0, + .rxConfig.bAutoFlushCrcErr = 0x0, + .rxConfig.bAutoFlushEmpty = 0x0, + .rxConfig.bIncludeLenByte = 0x0, + .rxConfig.bIncludeCrc = 0x0, + .rxConfig.bAppendRssi = 0x0, + .rxConfig.bAppendStatus = 0x0, + .rxConfig.bAppendTimestamp = 0x0, + .advConfig.advFilterPolicy = 0x0, + .advConfig.deviceAddrType = 0x0, + .advConfig.peerAddrType = 0x0, + .advConfig.bStrictLenFilter = 0x0, + .advConfig.rpaMode = 0x0, + .advLen = 0x18, + .scanRspLen = 0x00, + .pAdvData = 0, + .pScanRspData = 0, + .pDeviceAddress = 0, + .pWhiteList = 0, + .__dummy0 = 0x0000, + .__dummy1 = 0x00, + .endTrigger.triggerType = TRIG_NEVER, + .endTrigger.bEnaCmd = 0x0, + .endTrigger.triggerNo = 0x0, + .endTrigger.pastTrig = 0x0, + .endTime = 0x00000000, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_BLE_ADV_NC: BLE Non-Connectable Advertiser Command */ +rfc_CMD_BLE_ADV_NC_t rf_ble_cmd_ble_adv_nc = +{ + .commandNo = CMD_BLE_ADV_NC, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .channel = 0x8C, + .whitening.init = 0x51, + .whitening.bOverride = 0x1, + .pParams = &rf_ble_adv_par, + .pOutput = 0, +}; +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ble-settings.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ble-settings.h new file mode 100644 index 000000000..81fbf67ba --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ble-settings.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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 BLE_SETTINGS_H_ +#define BLE_SETTINGS_H_ +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_ble_cmd.h) + +#include +/*---------------------------------------------------------------------------*/ +/* TI-RTOS RF Mode Object */ +extern RF_Mode rf_ble_mode; +/*---------------------------------------------------------------------------*/ +/* RF Core API commands */ +extern rfc_CMD_RADIO_SETUP_t rf_ble_cmd_radio_setup; +extern rfc_bleAdvPar_t rf_ble_adv_par; +extern rfc_CMD_BLE_ADV_NC_t rf_ble_cmd_ble_adv_nc; +/*---------------------------------------------------------------------------*/ +/* RF Core API Overrides */ +extern uint32_t rf_ble_overrides[]; +/*---------------------------------------------------------------------------*/ +#endif /* BLE_SETTINGS_H_ */ +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ble-tx-power.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ble-tx-power.c new file mode 100644 index 000000000..a0ae346c5 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ble-tx-power.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-rf-tx-power + * @{ + * + * \file + * Source file for BLE Beacon TX power tables for CC13x0. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +/*---------------------------------------------------------------------------*/ +#include "rf/tx-power.h" +/*---------------------------------------------------------------------------*/ +/* + * TX Power table for CC1350 + * The RF_TxPowerTable_DEFAULT_PA_ENTRY macro is defined in RF.h and requires the following arguments: + * RF_TxPowerTable_DEFAULT_PA_ENTRY(bias, gain, boost coefficient) + * See the Technical Reference Manual for further details about the "txPower" Command field. + * The PA settings require the CCFG_FORCE_VDDR_HH = 0 unless stated otherwise. + */ +tx_power_table_t rf_ble_tx_power_table_cc1350[] = +{ + { -21, RF_TxPowerTable_DEFAULT_PA_ENTRY( 8, 3, 1, 6) }, + { -18, RF_TxPowerTable_DEFAULT_PA_ENTRY(11, 3, 1, 6) }, + { -15, RF_TxPowerTable_DEFAULT_PA_ENTRY(14, 3, 1, 10) }, + { -12, RF_TxPowerTable_DEFAULT_PA_ENTRY(20, 3, 1, 12) }, + { -9, RF_TxPowerTable_DEFAULT_PA_ENTRY(26, 3, 1, 14) }, + { -6, RF_TxPowerTable_DEFAULT_PA_ENTRY(35, 3, 1, 18) }, + { -3, RF_TxPowerTable_DEFAULT_PA_ENTRY(47, 3, 1, 22) }, + { 0, RF_TxPowerTable_DEFAULT_PA_ENTRY(29, 0, 1, 45) }, + { 1, RF_TxPowerTable_DEFAULT_PA_ENTRY(33, 0, 1, 49) }, + { 2, RF_TxPowerTable_DEFAULT_PA_ENTRY(38, 0, 1, 55) }, + { 3, RF_TxPowerTable_DEFAULT_PA_ENTRY(44, 0, 1, 63) }, + { 4, RF_TxPowerTable_DEFAULT_PA_ENTRY(52, 0, 1, 59) }, + { 5, RF_TxPowerTable_DEFAULT_PA_ENTRY(60, 0, 1, 47) }, +#if RF_TXPOWER_BOOST_MODE + /* This setting requires CCFG_FORCE_VDDR_HH = 1. */ + { 6, RF_TxPowerTable_DEFAULT_PA_ENTRY(38, 0, 1, 49) }, + /* This setting requires CCFG_FORCE_VDDR_HH = 1. */ + { 7, RF_TxPowerTable_DEFAULT_PA_ENTRY(46, 0, 1, 59) }, + /* This setting requires CCFG_FORCE_VDDR_HH = 1. */ + { 8, RF_TxPowerTable_DEFAULT_PA_ENTRY(55, 0, 1, 51) }, + /* This setting requires CCFG_FORCE_VDDR_HH = 1. */ + { 9, RF_TxPowerTable_DEFAULT_PA_ENTRY(63, 0, 1, 30) }, +#endif + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +tx_power_table_t rf_ble_tx_power_table_empty[] = +{ + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +/* TX power table, based on which board is used. */ +#if defined(DEVICE_CC1350) || defined(DEVICE_CC1350_4) +#define TX_POWER_TABLE rf_ble_tx_power_table_cc1350 + +#else +#define TX_POWER_TABLE rf_ble_tx_power_table_empty +#endif + +/* + * Define symbols for both the TX power table and its size. The TX power + * table size is with one less entry by excluding the termination entry. + */ +tx_power_table_t *const ble_tx_power_table = TX_POWER_TABLE; +const size_t ble_tx_power_table_size = (sizeof(TX_POWER_TABLE) / sizeof(TX_POWER_TABLE[0])) - 1; +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ieee-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ieee-settings.c new file mode 100644 index 000000000..2a383e6c6 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ieee-settings.c @@ -0,0 +1,252 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/*---------------------------------------------------------------------------*/ +/* + * Parameter summary + * IEEE Channel: 11 + * Frequency: 2405 MHz + * SFD: 0 + * Packet Data: 255 + * Preamble (32 bit): 01010101... + * TX Power: 5 dBm (requires define CCFG_FORCE_VDDR_HH = 0 in ccfg.c, + * see CC13xx/CC26xx Technical Reference Manual) + */ +/*---------------------------------------------------------------------------*/ +#include "sys/cc.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) +/* + * rf_ieee_cmd.h must be included "locally" from the arch/cpu directory, + * as it isn't defined in CC13x0 driverlib. + */ +#include "driverlib/rf_ieee_cmd.h" + +#include +/*---------------------------------------------------------------------------*/ +#include "ieee-settings.h" +/*---------------------------------------------------------------------------*/ +/* TI-RTOS RF Mode Object */ +RF_Mode rf_ieee_mode = +{ + .rfMode = RF_MODE_IEEE_15_4, + .cpePatchFxn = 0, + .mcePatchFxn = 0, + .rfePatchFxn = 0, +}; +/*---------------------------------------------------------------------------*/ +/* + * CMD_RADIO_SETUP must be configured with default TX power value + * in the .txPower field. + */ +#define DEFAULT_TX_POWER 0x9330 /* 5 dBm */ +/*---------------------------------------------------------------------------*/ +/* Overrides for CMD_RADIO_SETUP */ +uint32_t rf_ieee_overrides[] CC_ALIGN(4) = +{ + /* override_synth_ieee_15_4.xml */ + HW_REG_OVERRIDE(0x4038,0x0035), /* Synth: Set recommended RTRIM to 5 */ + (uint32_t)0x000784A3, /* Synth: Set Fref to 3.43 MHz */ + (uint32_t)0xA47E0583, /* Synth: Set loop bandwidth after lock to 80 kHz */ + (uint32_t)0xEAE00603, /* Synth: Set loop bandwidth after lock to 80 kHz */ + (uint32_t)0x00010623, /* Synth: Set loop bandwidth after lock to 80 kHz */ + HW32_ARRAY_OVERRIDE(0x405C,1), /* Synth: Configure PLL bias */ + (uint32_t)0x1801F800, /* Synth: Configure PLL bias */ + HW32_ARRAY_OVERRIDE(0x402C,1), /* Synth: Configure PLL latency */ + (uint32_t)0x00608402, /* Synth: Configure PLL latency */ + (uint32_t)0x02010403, /* Synth: Use 24 MHz XOSC as synth clock, enable extra PLL filtering */ + HW32_ARRAY_OVERRIDE(0x4034,1), /* Synth: Configure extra PLL filtering */ + (uint32_t)0x177F0408, /* Synth: Configure extra PLL filtering */ + (uint32_t)0x38000463, /* Synth: Configure extra PLL filtering */ + /* override_phy_ieee_15_4.xml */ + (uint32_t)0x05000243, /* Synth: Increase synth programming timeout */ + (uint32_t)0x002082C3, /* Rx: Adjust Rx FIFO threshold to avoid overflow */ + /* override_frontend_id.xml */ + (uint32_t)0x000288A3, /* Rx: Set RSSI offset to adjust reported RSSI by -2 dB */ + (uint32_t)0x000F8883, /* Rx: Configure LNA bias current trim offset */ + HW_REG_OVERRIDE(0x50DC,0x002B), /* Rx: Adjust AGC DC filter */ + (uint32_t)0xFFFFFFFF, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_RADIO_SETUP: Radio Setup Command for Pre-Defined Schemes */ +rfc_CMD_RADIO_SETUP_t rf_cmd_ieee_radio_setup = +{ + .commandNo = CMD_RADIO_SETUP, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .mode = 0x01, + .config.frontEndMode = 0x0, + .config.biasMode = 0x0, + .config.analogCfgMode = 0x0, + .config.bNoFsPowerUp = 0x0, + .txPower = DEFAULT_TX_POWER, /* 5 dBm default */ + .pRegOverride = rf_ieee_overrides, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_FS: Frequency Synthesizer Programming Command */ +rfc_CMD_FS_t rf_cmd_ieee_fs = +{ + .commandNo = CMD_FS, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .frequency = 0x0965, /* set by driver */ + .fractFreq = 0x0000, /* set by driver */ + .synthConf.bTxMode = 0x1, + .synthConf.refFreq = 0x0, + .__dummy0 = 0x00, + .__dummy1 = 0x00, + .__dummy2 = 0x00, + .__dummy3 = 0x0000, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_IEEE_TX: IEEE 802.15.4 Transmit Command */ +rfc_CMD_IEEE_TX_t rf_cmd_ieee_tx = +{ + .commandNo = CMD_IEEE_TX, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .txOpt.bIncludePhyHdr = 0x0, + .txOpt.bIncludeCrc = 0x0, + .txOpt.payloadLenMsb = 0x0, + .payloadLen = 0x0, /* set by driver */ + .pPayload = 0, /* set by driver */ + .timeStamp = 0x00000000, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_IEEE_RX: IEEE 802.15.4 Receive Command */ +rfc_CMD_IEEE_RX_t rf_cmd_ieee_rx = +{ + .commandNo = CMD_IEEE_RX, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .channel = 0x00, /* set by driver */ + .rxConfig.bAutoFlushCrc = 0x1, + .rxConfig.bAutoFlushIgn = 0x1, + .rxConfig.bIncludePhyHdr = 0x0, + .rxConfig.bIncludeCrc = 0x1, + .rxConfig.bAppendRssi = 0x1, + .rxConfig.bAppendCorrCrc = 0x1, + .rxConfig.bAppendSrcInd = 0x0, + .rxConfig.bAppendTimestamp = 0x1, + .pRxQ = 0, /* set by driver */ + .pOutput = 0, /* set by driver */ + .frameFiltOpt.frameFiltEn = 0x0, /* set by driver */ + .frameFiltOpt.frameFiltStop = 0x1, + .frameFiltOpt.autoAckEn = 0x0, /* set by driver */ + .frameFiltOpt.slottedAckEn = 0x0, + .frameFiltOpt.autoPendEn = 0x0, + .frameFiltOpt.defaultPend = 0x0, + .frameFiltOpt.bPendDataReqOnly = 0x0, + .frameFiltOpt.bPanCoord = 0x0, + .frameFiltOpt.maxFrameVersion = 0x2, + .frameFiltOpt.fcfReservedMask = 0x0, + .frameFiltOpt.modifyFtFilter = 0x0, + .frameFiltOpt.bStrictLenFilter = 0x0, + .frameTypes.bAcceptFt0Beacon = 0x1, + .frameTypes.bAcceptFt1Data = 0x1, + .frameTypes.bAcceptFt2Ack = 0x1, + .frameTypes.bAcceptFt3MacCmd = 0x1, + .frameTypes.bAcceptFt4Reserved = 0x1, + .frameTypes.bAcceptFt5Reserved = 0x1, + .frameTypes.bAcceptFt6Reserved = 0x1, + .frameTypes.bAcceptFt7Reserved = 0x1, + .ccaOpt.ccaEnEnergy = 0x1, + .ccaOpt.ccaEnCorr = 0x1, + .ccaOpt.ccaEnSync = 0x1, + .ccaOpt.ccaCorrOp = 0x1, + .ccaOpt.ccaSyncOp = 0x0, + .ccaOpt.ccaCorrThr = 0x3, + .ccaRssiThr = 0x0, /* set by driver */ + .__dummy0 = 0x00, + .numExtEntries = 0x00, + .numShortEntries = 0x00, + .pExtEntryList = 0, + .pShortEntryList = 0, + .localExtAddr = 0x0, /* set by driver */ + .localShortAddr = 0x0, /* set by driver */ + .localPanID = 0x0000, + .__dummy1 = 0x000000, + .endTrigger.triggerType = TRIG_NEVER, + .endTrigger.bEnaCmd = 0x0, + .endTrigger.triggerNo = 0x0, + .endTrigger.pastTrig = 0x0, + .endTime = 0x00000000, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_IEEE_RX_ACK: IEEE 802.15.4 Receive ACK Command */ +rfc_CMD_IEEE_RX_ACK_t rf_cmd_ieee_rx_ack = +{ + .commandNo = CMD_IEEE_RX_ACK, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .seqNo = 0x0, + .endTrigger.triggerType = TRIG_NEVER, + .endTrigger.bEnaCmd = 0x0, + .endTrigger.triggerNo = 0x0, + .endTrigger.pastTrig = 0x0, + .endTime = 0x00000000, +}; +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ieee-settings.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ieee-settings.h new file mode 100644 index 000000000..bc60d70c3 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ieee-settings.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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 IEEE_SETTINGS_H_ +#define IEEE_SETTINGS_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki-conf.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) +/* + * These two headers must be included "locally" from the arch/cpu directory, + * as they aren't defined in CC13x0 driverlib. + */ +#include "driverlib/rf_ieee_cmd.h" +#include "driverlib/rf_ieee_mailbox.h" + +#include +/*---------------------------------------------------------------------------*/ +/* TI-RTOS RF Mode Object */ +extern RF_Mode rf_ieee_mode; +/*---------------------------------------------------------------------------*/ +/* RF Core API commands */ +extern rfc_CMD_RADIO_SETUP_t rf_cmd_ieee_radio_setup; +extern rfc_CMD_FS_t rf_cmd_ieee_fs; +extern rfc_CMD_IEEE_TX_t rf_cmd_ieee_tx; +extern rfc_CMD_IEEE_RX_t rf_cmd_ieee_rx; +extern rfc_CMD_IEEE_RX_ACK_t rf_cmd_ieee_rx_ack; +/*---------------------------------------------------------------------------*/ +/* RF Core API Overrides */ +extern uint32_t rf_ieee_overrides[]; +/*---------------------------------------------------------------------------*/ +#endif /* IEEE_SETTINGS_H_ */ +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ieee-tx-power.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ieee-tx-power.c new file mode 100644 index 000000000..2d37ef641 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/ieee-tx-power.c @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-rf-tx-power + * @{ + * + * \file + * Source file for IEEE-mode TX power tables for CC13x0. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +/*---------------------------------------------------------------------------*/ +#include "rf/tx-power.h" +/*---------------------------------------------------------------------------*/ +/* + * TX Power table for CC1350 + * The RF_TxPowerTable_DEFAULT_PA_ENTRY macro is defined in RF.h and requires the following arguments: + * RF_TxPowerTable_DEFAULT_PA_ENTRY(bias, gain, boost coefficient) + * See the Technical Reference Manual for further details about the "txPower" Command field. + * The PA settings require the CCFG_FORCE_VDDR_HH = 0 unless stated otherwise. + */ +tx_power_table_t rf_ieee_tx_power_table_cc1350[] = +{ + { -21, RF_TxPowerTable_DEFAULT_PA_ENTRY( 7, 3, 0, 6) }, + { -18, RF_TxPowerTable_DEFAULT_PA_ENTRY( 9, 3, 0, 6) }, + { -15, RF_TxPowerTable_DEFAULT_PA_ENTRY(11, 3, 0, 6) }, + { -12, RF_TxPowerTable_DEFAULT_PA_ENTRY(11, 1, 0, 10) }, + { -9, RF_TxPowerTable_DEFAULT_PA_ENTRY(14, 1, 1, 12) }, + { -6, RF_TxPowerTable_DEFAULT_PA_ENTRY(18, 1, 1, 14) }, + { -3, RF_TxPowerTable_DEFAULT_PA_ENTRY(24, 1, 1, 18) }, + { 0, RF_TxPowerTable_DEFAULT_PA_ENTRY(33, 1, 1, 24) }, + { 1, RF_TxPowerTable_DEFAULT_PA_ENTRY(20, 0, 0, 33) }, + { 2, RF_TxPowerTable_DEFAULT_PA_ENTRY(24, 0, 0, 39) }, + { 3, RF_TxPowerTable_DEFAULT_PA_ENTRY(28, 0, 0, 45) }, + { 4, RF_TxPowerTable_DEFAULT_PA_ENTRY(36, 0, 1, 73) }, + { 5, RF_TxPowerTable_DEFAULT_PA_ENTRY(48, 0, 1, 73) }, + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +tx_power_table_t rf_ieee_tx_power_table_empty[] = +{ + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +/* Only define the symbols if Prop-mode is selected */ +#if (RF_MODE == RF_MODE_2_4_GHZ) +/*---------------------------------------------------------------------------*/ +/* TX power table, based on which board is used. */ +#if defined(DEVICE_CC1350) || defined(DEVICE_CC1350_4) +#define TX_POWER_TABLE rf_ieee_tx_power_table_cc1350 + +#else +#define TX_POWER_TABLE rf_ieee_tx_power_table_empty +#endif + +/* + * Define symbols for both the TX power table and its size. The TX power + * table size is with one less entry by excluding the termination entry. + */ +tx_power_table_t *const rf_tx_power_table = TX_POWER_TABLE; +const size_t rf_tx_power_table_size = (sizeof(TX_POWER_TABLE) / sizeof(TX_POWER_TABLE[0])) - 1; +/*---------------------------------------------------------------------------*/ +#endif /* RF_MODE */ +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/prop-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/prop-settings.c new file mode 100644 index 000000000..64dbe591f --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/prop-settings.c @@ -0,0 +1,310 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/*---------------------------------------------------------------------------*/ +/* + * Parameter summary + * Address: 0 + * Address0: 0xAA + * Address1: 0xBB + * Frequency: 868.00000 MHz + * Data Format: Serial mode disable + * Deviation: 25.000 kHz + * pktLen: 30 + * 802.15.4g Mode: 0 + * Select bit order to transmit PSDU octets:: 1 + * Packet Length Config: Variable + * Max Packet Length: 255 + * Packet Length: 0 + * Packet Data: 255 + * RX Filter BW: 98 kHz + * Symbol Rate: 50.00000 kBaud + * Sync Word Length: 24 Bits + * TX Power: 14 dBm (requires define CCFG_FORCE_VDDR_HH = 1 in ccfg.c, + * see CC13xx/CC26xx Technical Reference Manual) + * Whitening: Dynamically IEEE 802.15.4g compatible whitener and 16/32-bit CRC + */ +/*---------------------------------------------------------------------------*/ +#include "contiki-conf.h" +#include "sys/cc.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_prop_cmd.h) +#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_genfsk.h) +#include DeviceFamily_constructPath(rf_patches/rf_patch_rfe_genfsk.h) + +#include +/*---------------------------------------------------------------------------*/ +#include "prop-settings.h" +/*---------------------------------------------------------------------------*/ +/* TI-RTOS RF Mode Object */ +RF_Mode rf_prop_mode = +{ + .rfMode = RF_MODE_PROPRIETARY_SUB_1, + .cpePatchFxn = &rf_patch_cpe_genfsk, + .mcePatchFxn = 0, + .rfePatchFxn = &rf_patch_rfe_genfsk, +}; +/*---------------------------------------------------------------------------*/ +#if defined(DEVICE_CC1310) +/* + * CMD_PROP_RADIO_DIV_SETUP must be configured with default TX power value + * in the .txPower field. This depends on whether RF_CONF_TXPOWER_BOOST_MODE + * is configured or not. + */ +#if RF_CONF_TXPOWER_BOOST_MODE +#define DEFAULT_TX_POWER 0xA73F /* 14 dBm */ +#else +#define DEFAULT_TX_POWER 0xA63F /* 12.5 dBm (rounded up to 13 dBm) */ +#endif + +#endif /* defined(DEVICE_CC1310) */ +/*---------------------------------------------------------------------------*/ +#if defined(DEVICE_CC1350) +/* + * CMD_PROP_RADIO_DIV_SETUP must be configured with default TX power value + * in the .txPower field. This depends on whether RF_CONF_TXPOWER_BOOST_MODE + * is configured or not. + */ +#if RF_CONF_TXPOWER_BOOST_MODE +#define DEFAULT_TX_POWER 0xAB3F /* 14 dBm */ +#else +#define DEFAULT_TX_POWER 0xBC2B /* 12 dBm */ +#endif + +#endif /* defined(DEVICE_CC1350) */ + /*---------------------------------------------------------------------------*/ +#if defined(DEVICE_CC1350_4) +/* + * CMD_PROP_RADIO_DIV_SETUP must be configured with default TX power value + * in the .txPower field. This depends on whether RF_CONF_TXPOWER_BOOST_MODE + * is configured or not. + */ +#if RF_CONF_TXPOWER_BOOST_MODE +#define DEFAULT_TX_POWER 0x913F /* 15 dBm */ +#else +#define DEFAULT_TX_POWER 0xB83F /* 13.7 dBm (rounded up to 14 dBm) */ +#endif + +#endif /* defined(DEVICE_CC1350_4) */ +/*---------------------------------------------------------------------------*/ +/* Overrides for CMD_PROP_RADIO_DIV_SETUP */ +uint32_t rf_prop_overrides[] CC_ALIGN(4) = +{ + /* override_use_patch_prop_genfsk.xml */ + MCE_RFE_OVERRIDE(0,4,0,1,0,0), /* PHY: Use MCE ROM bank 4, RFE RAM patch */ + /* override_synth_prop_863_930_div5.xml */ + HW_REG_OVERRIDE(0x4038,0x0037), /* Synth: Set recommended RTRIM to 7 */ + (uint32_t)0x000684A3, /* Synth: Set Fref to 4 MHz */ + HW_REG_OVERRIDE(0x4020,0x7F00), /* Synth: Configure fine calibration setting */ + HW_REG_OVERRIDE(0x4064,0x0040), /* Synth: Configure fine calibration setting */ + (uint32_t)0xB1070503, /* Synth: Configure fine calibration setting */ + (uint32_t)0x05330523, /* Synth: Configure fine calibration setting */ + (uint32_t)0x0A480583, /* Synth: Set loop bandwidth after lock to 20 kHz */ + (uint32_t)0x7AB80603, /* Synth: Set loop bandwidth after lock to 20 kHz */ + /* Synth: Configure VCO LDO */ + ADI_REG_OVERRIDE(1,4,0x9F), /* (in ADI1, set VCOLDOCFG=0x9F to use voltage input reference) */ + ADI_HALFREG_OVERRIDE(1,7,0x4,0x4), /* Synth: Configure synth LDO (in ADI1, set SLDOCTL0.COMP_CAP=1) */ + (uint32_t)0x02010403, /* Synth: Use 24 MHz XOSC as synth clock, enable extra PLL filtering */ + (uint32_t)0x00108463, /* Synth: Configure extra PLL filtering */ + (uint32_t)0x04B00243, /* Synth: Increase synth programming timeout (0x04B0 RAT ticks = 300 us) */ + /* override_phy_rx_aaf_bw_0xd.xml */ + /* Rx: Set anti-aliasing filter bandwidth to 0xD */ + ADI_HALFREG_OVERRIDE(0,61,0xF,0xD), /* (in ADI0, set IFAMPCTL3[7:4]=0xD) */ + /* override_phy_gfsk_rx.xml */ + (uint32_t)0x00038883, /* Rx: Set LNA bias current trim offset to 3 */ + HW_REG_OVERRIDE(0x6084,0x35F1), /* Rx: Freeze RSSI on sync found event */ + /* override_phy_gfsk_pa_ramp_agc_reflevel_0x1a.xml */ + /* Tx: Configure PA ramping setting (0x41). */ + HW_REG_OVERRIDE(0x6088,0x411A), /* Rx: Set AGC reference level to 0x1A. */ + HW_REG_OVERRIDE(0x608C,0x8213), /* Tx: Configure PA ramping setting */ + /* override_crc_ieee_802_15_4.xml */ + /* IEEE 802.15.4g: Fix incorrect initialization value for */ + (uint32_t)0x00000943, /* CRC-16 calculation (see TRM section 23.7.5.2.1) */ + /* IEEE 802.15.4g: Fix incorrect initialization value for */ + (uint32_t)0x00000963, /* CRC-16 calculation (see TRM section 23.7.5.2.1) */ +#if defined(DEVICE_CC1350_4) + /* override_phy_rx_rssi_offset_neg2db.xml */ + (uint32_t)0x000288A3, /* Rx: Set RSSI offset to adjust reported RSSI by -2 dB */ +#else + /* override_phy_rx_rssi_offset_5db.xml */ + (uint32_t)0x00FB88A3, /* Rx: Set RSSI offset to adjust reported RSSI by +5 dB */ +#endif + /* TX power override */ +#if RF_CONF_TXPOWER_BOOST_MODE + ADI_REG_OVERRIDE(0,12,0xF8), /* Tx: Set PA trim to max (in ADI0, set PACTL0=0xF8) */ +#endif + (uint32_t)0xFFFFFFFF, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_PROP_RADIO_DIV_SETUP */ +/* Proprietary Mode Radio Setup Command for All Frequency Bands */ +rfc_CMD_PROP_RADIO_DIV_SETUP_t rf_cmd_prop_radio_div_setup = +{ + .commandNo = CMD_PROP_RADIO_DIV_SETUP, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .modulation.modType = 0x1, + .modulation.deviation = 0x64, + .symbolRate.preScale = 0xF, + .symbolRate.rateWord = 0x8000, + .rxBw = 0x24, + .preamConf.nPreamBytes = 0x7, + .preamConf.preamMode = 0x0, + .formatConf.nSwBits = 0x18, + .formatConf.bBitReversal = 0x0, + .formatConf.bMsbFirst = 0x1, + .formatConf.fecMode = 0x0, + .formatConf.whitenMode = 0x7, + .config.frontEndMode = 0x0, /* set by driver */ + .config.biasMode = 0x0, /* set by driver */ + .config.analogCfgMode = 0x0, + .config.bNoFsPowerUp = 0x0, + .txPower = DEFAULT_TX_POWER, + .pRegOverride = rf_prop_overrides, + .centerFreq = 0x0364, /* set by driver */ + .intFreq = 0x8000, /* set by driver */ + .loDivider = 0x05, /* set by driver */ +}; +/*---------------------------------------------------------------------------*/ +/* CMD_FS */ +/* Frequency Synthesizer Programming Command */ +rfc_CMD_FS_t rf_cmd_prop_fs = +{ + .commandNo = CMD_FS, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .frequency = 0x0364, /* set by driver */ + .fractFreq = 0x0000, /* set by driver */ + .synthConf.bTxMode = 0x0, + .synthConf.refFreq = 0x0, + .__dummy0 = 0x00, + .__dummy1 = 0x00, + .__dummy2 = 0x00, + .__dummy3 = 0x0000, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_PROP_TX_ADV */ +/* Proprietary Mode Advanced Transmit Command */ +rfc_CMD_PROP_TX_ADV_t rf_cmd_prop_tx_adv = +{ + .commandNo = CMD_PROP_TX_ADV, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .pktConf.bFsOff = 0x0, + .pktConf.bUseCrc = 0x1, + .pktConf.bCrcIncSw = 0x0, + .pktConf.bCrcIncHdr = 0x0, + .numHdrBits = 0x10, + .pktLen = 0x0, /* set by driver */ + .startConf.bExtTxTrig = 0x0, + .startConf.inputMode = 0x0, + .startConf.source = 0x0, + .preTrigger.triggerType = TRIG_REL_START, + .preTrigger.bEnaCmd = 0x0, + .preTrigger.triggerNo = 0x0, + .preTrigger.pastTrig = 0x1, + .preTime = 0x00000000, + .syncWord = 0x0055904E, + .pPkt = 0, /* set by driver */ +}; +/*---------------------------------------------------------------------------*/ +/* CMD_PROP_RX_ADV */ +/* Proprietary Mode Advanced Receive Command */ +rfc_CMD_PROP_RX_ADV_t rf_cmd_prop_rx_adv = +{ + .commandNo = CMD_PROP_RX_ADV, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .pktConf.bFsOff = 0x0, + .pktConf.bRepeatOk = 0x1, + .pktConf.bRepeatNok = 0x1, + .pktConf.bUseCrc = 0x1, + .pktConf.bCrcIncSw = 0x0, + .pktConf.bCrcIncHdr = 0x0, + .pktConf.endType = 0x0, + .pktConf.filterOp = 0x1, + .rxConf.bAutoFlushIgnored = 0x1, + .rxConf.bAutoFlushCrcErr = 0x1, + .rxConf.bIncludeHdr = 0x0, + .rxConf.bIncludeCrc = 0x0, + .rxConf.bAppendRssi = 0x1, + .rxConf.bAppendTimestamp = 0x0, + .rxConf.bAppendStatus = 0x1, + .syncWord0 = 0x0055904E, + .syncWord1 = 0x00000000, + .maxPktLen = 0x0, /* set by driver */ + .hdrConf.numHdrBits = 0x10, + .hdrConf.lenPos = 0x0, + .hdrConf.numLenBits = 0x0B, + .addrConf.addrType = 0x0, + .addrConf.addrSize = 0x0, + .addrConf.addrPos = 0x0, + .addrConf.numAddr = 0x0, + .lenOffset = 0xFC, + .endTrigger.triggerType = TRIG_NEVER, + .endTrigger.bEnaCmd = 0x0, + .endTrigger.triggerNo = 0x0, + .endTrigger.pastTrig = 0x0, + .endTime = 0x00000000, + .pAddr = 0, /* set by driver */ + .pQueue = 0, /* set by driver */ + .pOutput = 0, /* set by driver */ +}; +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/prop-settings.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/prop-settings.h new file mode 100644 index 000000000..f4f32ad57 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/prop-settings.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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 PROP_SETTINGS_H_ +#define PROP_SETTINGS_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki-conf.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_prop_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_prop_mailbox.h) + +#include +/*---------------------------------------------------------------------------*/ +/* TI-RTOS RF Mode Object */ +extern RF_Mode rf_prop_mode; +/*---------------------------------------------------------------------------*/ +/* TX Power Table */ +extern RF_TxPowerTable_Entry rf_prop_tx_power_table[]; +extern const size_t rf_prop_tx_power_table_size; +/*---------------------------------------------------------------------------*/ +/* RF Core API commands */ +extern rfc_CMD_PROP_RADIO_DIV_SETUP_t rf_cmd_prop_radio_div_setup; +extern rfc_CMD_FS_t rf_cmd_prop_fs; +extern rfc_CMD_PROP_TX_ADV_t rf_cmd_prop_tx_adv; +extern rfc_CMD_PROP_RX_ADV_t rf_cmd_prop_rx_adv; +/*---------------------------------------------------------------------------*/ +/* RF Core API Overrides */ +extern uint32_t rf_prop_overrides[]; +/*---------------------------------------------------------------------------*/ +#endif /* PROP_SETTINGS_H_ */ +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/prop-tx-power.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/prop-tx-power.c new file mode 100644 index 000000000..f2293767f --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x0/prop-tx-power.c @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-rf-tx-power + * @{ + * + * \file + * Source file for Prop-mode TX power tables for CC13x0. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +/*---------------------------------------------------------------------------*/ +#include "rf/tx-power.h" +/*---------------------------------------------------------------------------*/ +/* + * TX Power table for CC1310 + * The RF_TxPowerTable_DEFAULT_PA_ENTRY macro is defined in RF.h and requires the following arguments: + * RF_TxPowerTable_DEFAULT_PA_ENTRY(bias, gain, boost coefficient) + * See the Technical Reference Manual for further details about the "txPower" Command field. + * The PA settings require the CCFG_FORCE_VDDR_HH = 0 unless stated otherwise. + */ +tx_power_table_t rf_prop_tx_power_table_cc1310[] = +{ + { -10, RF_TxPowerTable_DEFAULT_PA_ENTRY( 0, 3, 0, 4) }, + { 0, RF_TxPowerTable_DEFAULT_PA_ENTRY( 1, 1, 0, 0) }, + { 1, RF_TxPowerTable_DEFAULT_PA_ENTRY( 3, 3, 0, 8) }, + { 2, RF_TxPowerTable_DEFAULT_PA_ENTRY( 2, 1, 0, 8) }, + { 3, RF_TxPowerTable_DEFAULT_PA_ENTRY( 4, 3, 0, 10) }, + { 4, RF_TxPowerTable_DEFAULT_PA_ENTRY( 5, 3, 0, 12) }, + { 5, RF_TxPowerTable_DEFAULT_PA_ENTRY( 6, 3, 0, 12) }, + { 6, RF_TxPowerTable_DEFAULT_PA_ENTRY( 7, 3, 0, 14) }, + { 7, RF_TxPowerTable_DEFAULT_PA_ENTRY( 9, 3, 0, 16) }, + { 8, RF_TxPowerTable_DEFAULT_PA_ENTRY(11, 3, 0, 18) }, + { 9, RF_TxPowerTable_DEFAULT_PA_ENTRY(13, 3, 0, 22) }, + { 10, RF_TxPowerTable_DEFAULT_PA_ENTRY(19, 3, 0, 28) }, + { 11, RF_TxPowerTable_DEFAULT_PA_ENTRY(26, 3, 0, 40) }, + { 12, RF_TxPowerTable_DEFAULT_PA_ENTRY(24, 0, 0, 92) }, + /* The original PA value (12.5 dBm) have been rounded to an integer value. */ + { 13, RF_TxPowerTable_DEFAULT_PA_ENTRY(63, 0, 0, 83) }, +#if RF_CONF_TXPOWER_BOOST_MODE + /* This setting requires RF_CONF_TXPOWER_BOOST_MODE = 1. */ + { 14, RF_TxPowerTable_DEFAULT_PA_ENTRY(63, 0, 1, 83) }, +#endif + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +/* + * TX Power table for CC1350 + * The RF_TxPowerTable_DEFAULT_PA_ENTRY macro is defined in RF.h and requires the following arguments: + * RF_TxPowerTable_DEFAULT_PA_ENTRY(bias, gain, boost coefficient) + * See the Technical Reference Manual for further details about the "txPower" Command field. + * The PA settings require the CCFG_FORCE_VDDR_HH = 0 unless stated otherwise. + */ +tx_power_table_t rf_prop_tx_power_table_cc1350[] = +{ + { -10, RF_TxPowerTable_DEFAULT_PA_ENTRY( 0, 3, 0, 2) }, + { 0, RF_TxPowerTable_DEFAULT_PA_ENTRY( 3, 3, 0, 9) }, + { 1, RF_TxPowerTable_DEFAULT_PA_ENTRY( 4, 3, 0, 11) }, + { 2, RF_TxPowerTable_DEFAULT_PA_ENTRY( 5, 3, 0, 12) }, + { 3, RF_TxPowerTable_DEFAULT_PA_ENTRY( 6, 3, 0, 14) }, + { 4, RF_TxPowerTable_DEFAULT_PA_ENTRY( 4, 1, 0, 12) }, + { 5, RF_TxPowerTable_DEFAULT_PA_ENTRY( 8, 3, 0, 16) }, + { 6, RF_TxPowerTable_DEFAULT_PA_ENTRY( 9, 3, 0, 18) }, + { 7, RF_TxPowerTable_DEFAULT_PA_ENTRY(11, 3, 0, 21) }, + { 8, RF_TxPowerTable_DEFAULT_PA_ENTRY(14, 3, 0, 25) }, + { 9, RF_TxPowerTable_DEFAULT_PA_ENTRY(18, 3, 0, 32) }, + { 10, RF_TxPowerTable_DEFAULT_PA_ENTRY(24, 3, 0, 44) }, + { 11, RF_TxPowerTable_DEFAULT_PA_ENTRY(37, 3, 0, 72) }, + { 12, RF_TxPowerTable_DEFAULT_PA_ENTRY(43, 0, 0, 94) }, +#if RF_CONF_TXPOWER_BOOST_MODE + /* This setting requires RF_CONF_TXPOWER_BOOST_MODE = 1. */ + { 14, RF_TxPowerTable_DEFAULT_PA_ENTRY(63, 0, 1, 85) }, +#endif + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +/* + * TX Power table for CC1350_433 + * The RF_TxPowerTable_DEFAULT_PA_ENTRY macro is defined in RF.h and requires the following arguments: + * RF_TxPowerTable_DEFAULT_PA_ENTRY(bias, gain, boost coefficient) + * See the Technical Reference Manual for further details about the "txPower" Command field. + * The PA settings require the CCFG_FORCE_VDDR_HH = 0 unless stated otherwise. + */ +tx_power_table_t rf_prop_tx_power_table_cc1350_4[] = +{ + { -10, RF_TxPowerTable_DEFAULT_PA_ENTRY( 0, 3, 0, 2) }, + { 0, RF_TxPowerTable_DEFAULT_PA_ENTRY( 1, 3, 0, 7) }, + { 2, RF_TxPowerTable_DEFAULT_PA_ENTRY( 1, 3, 0, 9) }, + { 3, RF_TxPowerTable_DEFAULT_PA_ENTRY( 2, 3, 0, 11) }, + { 4, RF_TxPowerTable_DEFAULT_PA_ENTRY( 2, 3, 0, 12) }, + { 5, RF_TxPowerTable_DEFAULT_PA_ENTRY( 3, 3, 0, 16) }, + { 6, RF_TxPowerTable_DEFAULT_PA_ENTRY( 4, 3, 0, 18) }, + { 7, RF_TxPowerTable_DEFAULT_PA_ENTRY( 5, 3, 0, 21) }, + { 8, RF_TxPowerTable_DEFAULT_PA_ENTRY( 6, 3, 0, 23) }, + { 9, RF_TxPowerTable_DEFAULT_PA_ENTRY( 8, 3, 0, 28) }, + { 10, RF_TxPowerTable_DEFAULT_PA_ENTRY(11, 3, 0, 35) }, + { 11, RF_TxPowerTable_DEFAULT_PA_ENTRY( 8, 1, 0, 39) }, + { 12, RF_TxPowerTable_DEFAULT_PA_ENTRY(14, 1, 0, 60) }, + { 13, RF_TxPowerTable_DEFAULT_PA_ENTRY(15, 0, 0, 108) }, + /* The original PA value (13.7 dBm) have been rounded to an integer value. */ + { 14, RF_TxPowerTable_DEFAULT_PA_ENTRY(63, 0, 0, 92) }, +#if RF_CONF_TXPOWER_BOOST_MODE + /* This setting requires RF_CONF_TXPOWER_BOOST_MODE = 1. */ + { 15, RF_TxPowerTable_DEFAULT_PA_ENTRY(63, 0, 1, 72) }, +#endif + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +tx_power_table_t rf_prop_tx_power_table_empty[] = +{ + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +/* Only define the symbols if Prop-mode is selected */ +#if (RF_MODE == RF_MODE_SUB_1_GHZ) +/*---------------------------------------------------------------------------*/ +/* TX power table, based on which board is used. */ +#if defined(DEVICE_CC1310) +#define TX_POWER_TABLE rf_prop_tx_power_table_cc1310 + +#elif defined(DEVICE_CC1350) +#define TX_POWER_TABLE rf_prop_tx_power_table_cc1350 + +#elif defined(DEVICE_CC1350_4) +#define TX_POWER_TABLE rf_prop_tx_power_table_cc1350_4 + +#else +#define TX_POWER_TABLE rf_prop_tx_power_table_empty +#endif + +/* + * Define symbols for both the TX power table and its size. The TX power + * table size is with one less entry by excluding the termination entry. + */ +tx_power_table_t *const rf_tx_power_table = TX_POWER_TABLE; +const size_t rf_tx_power_table_size = (sizeof(TX_POWER_TABLE) / sizeof(TX_POWER_TABLE[0])) - 1; +/*---------------------------------------------------------------------------*/ +#endif /* RF_MODE */ +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ble-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ble-settings.c new file mode 100644 index 000000000..b9e32a04d --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ble-settings.c @@ -0,0 +1,207 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/*---------------------------------------------------------------------------*/ +/* + * Parameter summary + * Adv. Address: 010203040506 + * Adv. Data: dummy + * BLE Channel: 17 + * Extended Header: 09 09 010203040506 babe + * Frequency: 2440 MHz + * PDU Payload length:: 30 + * TX Power: 5 dBm (requires define CCFG_FORCE_VDDR_HH = 0 in ccfg + * see CC13xx/CC26xx Technical Reference Manual) + * Whitening: true + */ +/*---------------------------------------------------------------------------*/ +#include "sys/cc.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_ble_cmd.h) +#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_bt5.h) +#include DeviceFamily_constructPath(rf_patches/rf_patch_rfe_bt5.h) +#include DeviceFamily_constructPath(rf_patches/rf_patch_mce_bt5.h) + +#include +/*---------------------------------------------------------------------------*/ +#include "ble-settings.h" +/*---------------------------------------------------------------------------*/ +/* TI-RTOS RF Mode Object */ +RF_Mode rf_ble_mode = +{ + .rfMode = RF_MODE_AUTO, + .cpePatchFxn = &rf_patch_cpe_bt5, + .mcePatchFxn = &rf_patch_mce_bt5, + .rfePatchFxn = &rf_patch_rfe_bt5, +}; +/*---------------------------------------------------------------------------*/ +/* Overrides for CMD_BLE5_RADIO_SETUP */ +uint32_t rf_ble_overrides_common[] CC_ALIGN(4) = +{ + /* override_ble5_setup_override_common.xml */ + (uint32_t)0x02400403, /* Synth: Use 48 MHz crystal, enable extra PLL filtering */ + (uint32_t)0x001C8473, /* Synth: Configure extra PLL filtering */ + (uint32_t)0x00088433, /* Synth: Configure synth hardware */ + (uint32_t)0x00038793, /* Synth: Set minimum RTRIM to 3 */ + HW32_ARRAY_OVERRIDE(0x4004,1), /* Synth: Configure faster calibration */ + (uint32_t)0x1C0C0618, /* Synth: Configure faster calibration */ + (uint32_t)0xC00401A1, /* Synth: Configure faster calibration */ + (uint32_t)0x00010101, /* Synth: Configure faster calibration */ + (uint32_t)0xC0040141, /* Synth: Configure faster calibration */ + (uint32_t)0x00214AD3, /* Synth: Configure faster calibration */ + (uint32_t)0x02980243, /* Synth: Decrease synth programming time-out (0x0298 RAT ticks = 166 us) */ + /* DC/DC regulator: In Tx, use DCDCCTL5[3:0]=0xC (DITHER_EN=1 and IPEAK=4). */ + (uint32_t)0xFCFC08C3, /* In Rx, use DCDCCTL5[3:0]=0xC (DITHER_EN=1 and IPEAK=4). */ + (uint32_t)0x00038883, /* Rx: Set LNA bias current offset to adjust +3 (default: 0) */ + (uint32_t)0x000288A3, /* Rx: Set RSSI offset to adjust reported RSSI by -2 dB (default: 0) */ + (uint32_t)0x01080263, /* Bluetooth 5: Compensate for reduced pilot tone length */ + (uint32_t)0x08E90AA3, /* Bluetooth 5: Compensate for reduced pilot tone length */ + (uint32_t)0x00068BA3, /* Bluetooth 5: Compensate for reduced pilot tone length */ + /* Bluetooth 5: Set correct total clock accuracy for received AuxPtr */ + (uint32_t)0x0E490C83, /* assuming local sleep clock of 50 ppm */ + (uint32_t)0xFFFFFFFF, +}; +/*---------------------------------------------------------------------------*/ +/* Overrides for CMD_BLE5_RADIO_SETUP */ +uint32_t rf_ble_overrides_1mbps[] CC_ALIGN(4) = +{ + /* override_ble5_setup_override_1mbps.xml */ + MCE_RFE_OVERRIDE(1,0,0,1,0,0), /* PHY: Use MCE RAM patch (mode 0), RFE RAM patch (mode 0) */ + HW_REG_OVERRIDE(0x5320,0x0240), /* Bluetooth 5: Reduce pilot tone length */ + (uint32_t)0x013302A3, /* Bluetooth 5: Compensate for reduced pilot tone length */ + (uint32_t)0xFFFFFFFF, +}; +/*---------------------------------------------------------------------------*/ +/* Overrides for CMD_BLE5_RADIO_SETUP */ +uint32_t rf_ble_overrides_2mbps[] CC_ALIGN(4) = +{ + /* override_ble5_setup_override_2mbps.xml */ + MCE_RFE_OVERRIDE(1,0,2,1,0,2), /* PHY: Use MCE RAM patch (mode 2), RFE RAM patch (mode 2) */ + HW_REG_OVERRIDE(0x5320,0x0240), /* Bluetooth 5: Reduce pilot tone length */ + (uint32_t)0x00D102A3, /* Bluetooth 5: Compensate for reduced pilot tone length */ + (uint32_t)0xFFFFFFFF, +}; +/*---------------------------------------------------------------------------*/ +/* Overrides for CMD_BLE5_RADIO_SETUP */ +uint32_t rf_ble_overrides_coded[] CC_ALIGN(4) = +{ + /* override_ble5_setup_override_coded.xml */ + MCE_RFE_OVERRIDE(1,0,1,1,0,1), /* PHY: Use MCE RAM patch (mode 1), RFE RAM patch (mode 1) */ + HW_REG_OVERRIDE(0x5320,0x0240), /* Bluetooth 5: Reduce pilot tone length */ + (uint32_t)0x078902A3, /* Bluetooth 5: Compensate for reduced pilot tone length */ + (uint32_t)0xFFFFFFFF, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_BLE5_RADIO_SETUP: Bluetooth 5 Radio Setup Command for all PHYs */ +rfc_CMD_BLE5_RADIO_SETUP_t rf_ble_cmd_radio_setup = +{ + .commandNo = CMD_BLE5_RADIO_SETUP, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .defaultPhy.mainMode = 0x0, + .defaultPhy.coding = 0x0, + .loDivider = 0x00, + .config.frontEndMode = 0x0, + .config.biasMode = 0x0, + .config.analogCfgMode = 0x0, + .config.bNoFsPowerUp = 0x0, + .txPower = 0x941E, + .pRegOverrideCommon = rf_ble_overrides_common, + .pRegOverride1Mbps = rf_ble_overrides_1mbps, + .pRegOverride2Mbps = rf_ble_overrides_2mbps, + .pRegOverrideCoded = rf_ble_overrides_coded, +}; +/*---------------------------------------------------------------------------*/ +/* Structure for CMD_BLE5_ADV_NC.pParams */ +rfc_bleAdvPar_t rf_ble_adv_par = +{ + .pRxQ = 0, + .rxConfig.bAutoFlushIgnored = 0x0, + .rxConfig.bAutoFlushCrcErr = 0x0, + .rxConfig.bAutoFlushEmpty = 0x0, + .rxConfig.bIncludeLenByte = 0x0, + .rxConfig.bIncludeCrc = 0x0, + .rxConfig.bAppendRssi = 0x0, + .rxConfig.bAppendStatus = 0x0, + .rxConfig.bAppendTimestamp = 0x0, + .advConfig.advFilterPolicy = 0x0, + .advConfig.deviceAddrType = 0x0, + .advConfig.peerAddrType = 0x0, + .advConfig.bStrictLenFilter = 0x0, + .advConfig.rpaMode = 0x0, + .advLen = 0x18, + .scanRspLen = 0x00, + .pAdvData = 0, + .pScanRspData = 0, + .pDeviceAddress = 0, + .pWhiteList = 0, + .__dummy0 = 0x0000, + .__dummy1 = 0x00, + .endTrigger.triggerType = TRIG_NEVER, + .endTrigger.bEnaCmd = 0x0, + .endTrigger.triggerNo = 0x0, + .endTrigger.pastTrig = 0x0, + .endTime = 0x00000000, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_BLE5_ADV_NC: Bluetooth 5 Non-Connectable Advertiser Command */ +rfc_CMD_BLE5_ADV_NC_t rf_ble_cmd_ble_adv_nc = +{ + .commandNo = 0x182D, + .status = 0x0000, + .pNextOp = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx + .startTime = 0x00000000, + .startTrigger.triggerType = 0x0, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = 0x1, + .condition.nSkip = 0x0, + .channel = 0x8C, + .whitening.init = 0x51, + .whitening.bOverride = 0x1, + .phyMode.mainMode = 0x0, + .phyMode.coding = 0x0, + .rangeDelay = 0x00, + .txPower = 0x0000, + .pParams = &rf_ble_adv_par, + .pOutput = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx + .tx20Power = 0x00000000, +}; +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ble-settings.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ble-settings.h new file mode 100644 index 000000000..2e6defa71 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ble-settings.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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 BLE_SETTINGS_H_ +#define BLE_SETTINGS_H_ +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_ble_cmd.h) + +#include +/*---------------------------------------------------------------------------*/ +/* TI-RTOS RF Mode Object */ +extern RF_Mode rf_ble_mode; +/*---------------------------------------------------------------------------*/ +/* RF Core API commands */ +extern rfc_CMD_BLE5_RADIO_SETUP_t rf_ble_cmd_radio_setup; +extern rfc_bleAdvPar_t rf_ble_adv_par; +extern rfc_CMD_BLE5_ADV_NC_t rf_ble_cmd_ble_adv_nc; +/*---------------------------------------------------------------------------*/ +/* RF Core API Overrides */ +extern uint32_t rf_ble_overrides_common[]; +extern uint32_t rf_ble_overrides_1mbps[]; +extern uint32_t rf_ble_overrides_2mbps[]; +extern uint32_t rf_ble_overrides_coded[]; +/*---------------------------------------------------------------------------*/ +#endif /* BLE_SETTINGS_H_ */ +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ble-tx-power.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ble-tx-power.c new file mode 100644 index 000000000..7a87ca567 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ble-tx-power.c @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-rf-tx-power + * @{ + * + * \file + * Source file for ble-mode TX power tables for CC13x2. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +/*---------------------------------------------------------------------------*/ +#include "rf/tx-power.h" +/*---------------------------------------------------------------------------*/ +/* + * TX Power table for CC1352R + * The RF_TxPowerTable_DEFAULT_PA_ENTRY macro is defined in RF.h and requires the following arguments: + * RF_TxPowerTable_DEFAULT_PA_ENTRY(bias, gain, boost coefficient) + * See the Technical Reference Manual for further details about the "txPower" Command field. + * The PA settings require the CCFG_FORCE_VDDR_HH = 0 unless stated otherwise. + */ +tx_power_table_t rf_ble_tx_power_table_cc1352r[] = +{ + { -21, RF_TxPowerTable_DEFAULT_PA_ENTRY( 7, 3, 0, 3) }, + { -18, RF_TxPowerTable_DEFAULT_PA_ENTRY( 9, 3, 0, 3) }, + { -15, RF_TxPowerTable_DEFAULT_PA_ENTRY( 8, 2, 0, 6) }, + { -12, RF_TxPowerTable_DEFAULT_PA_ENTRY(10, 2, 0, 8) }, + { -10, RF_TxPowerTable_DEFAULT_PA_ENTRY(12, 2, 0, 11) }, + { -9, RF_TxPowerTable_DEFAULT_PA_ENTRY(13, 2, 0, 5) }, + { -6, RF_TxPowerTable_DEFAULT_PA_ENTRY(13, 1, 0, 16) }, + { -5, RF_TxPowerTable_DEFAULT_PA_ENTRY(14, 1, 0, 17) }, + { -3, RF_TxPowerTable_DEFAULT_PA_ENTRY(17, 1, 0, 20) }, + { 0, RF_TxPowerTable_DEFAULT_PA_ENTRY(25, 1, 0, 26) }, + { 1, RF_TxPowerTable_DEFAULT_PA_ENTRY(28, 1, 0, 28) }, + { 2, RF_TxPowerTable_DEFAULT_PA_ENTRY(13, 0, 0, 34) }, + { 3, RF_TxPowerTable_DEFAULT_PA_ENTRY(17, 0, 0, 42) }, + { 4, RF_TxPowerTable_DEFAULT_PA_ENTRY(22, 0, 0, 54) }, + { 5, RF_TxPowerTable_DEFAULT_PA_ENTRY(30, 0, 0, 74) }, + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +/* + * TX Power table for CC1352P with default PA + * The RF_TxPowerTable_DEFAULT_PA_ENTRY macro is defined in RF.h and requires the following arguments: + * RF_TxPowerTable_DEFAULT_PA_ENTRY(bias, gain, boost coefficient) + * See the Technical Reference Manual for further details about the "txPower" Command field. + * The PA settings require the CCFG_FORCE_VDDR_HH = 0 unless stated otherwise. + */ +tx_power_table_t rf_ble_tx_power_table_cc1352p_dpa[] = +{ + { -21, RF_TxPowerTable_DEFAULT_PA_ENTRY( 7, 3, 0, 3) }, + { -18, RF_TxPowerTable_DEFAULT_PA_ENTRY( 9, 3, 0, 3) }, + { -15, RF_TxPowerTable_DEFAULT_PA_ENTRY( 8, 2, 0, 6) }, + { -12, RF_TxPowerTable_DEFAULT_PA_ENTRY(10, 2, 0, 8) }, + { -10, RF_TxPowerTable_DEFAULT_PA_ENTRY(12, 2, 0, 11) }, + { -9, RF_TxPowerTable_DEFAULT_PA_ENTRY(13, 2, 0, 5) }, + { -6, RF_TxPowerTable_DEFAULT_PA_ENTRY(13, 1, 0, 16) }, + { -5, RF_TxPowerTable_DEFAULT_PA_ENTRY(14, 1, 0, 17) }, + { -3, RF_TxPowerTable_DEFAULT_PA_ENTRY(17, 1, 0, 20) }, + { 0, RF_TxPowerTable_DEFAULT_PA_ENTRY(25, 1, 0, 26) }, + { 1, RF_TxPowerTable_DEFAULT_PA_ENTRY(28, 1, 0, 28) }, + { 2, RF_TxPowerTable_DEFAULT_PA_ENTRY(13, 0, 0, 34) }, + { 3, RF_TxPowerTable_DEFAULT_PA_ENTRY(17, 0, 0, 42) }, + { 4, RF_TxPowerTable_DEFAULT_PA_ENTRY(22, 0, 0, 54) }, + { 5, RF_TxPowerTable_DEFAULT_PA_ENTRY(30, 0, 0, 74) }, + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +/* + * TX Power table for CC1352P with high PA + * The RF_TxPowerTable_HIGH_PA_ENTRY macro is defined in RF.h and requires the following arguments: + * RF_TxPowerTable_HIGH_PA_ENTRY(bias, ibboost, boost, coefficient, ldoTrim) + * See the Technical Reference Manual for further details about the "txPower" Command field. + * The PA settings require the CCFG_FORCE_VDDR_HH = 0 unless stated otherwise. + */ +tx_power_table_t rf_ble_tx_power_table_cc1352p_hpa[] = +{ + { 0, RF_TxPowerTable_HIGH_PA_ENTRY(29, 0, 1, 17, 1) }, + { 3, RF_TxPowerTable_HIGH_PA_ENTRY(39, 0, 1, 20, 1) }, + { 6, RF_TxPowerTable_HIGH_PA_ENTRY(46, 0, 1, 26, 7) }, + { 9, RF_TxPowerTable_HIGH_PA_ENTRY(40, 0, 1, 39, 41) }, + { 10, RF_TxPowerTable_HIGH_PA_ENTRY(23, 2, 1, 65, 5) }, + { 11, RF_TxPowerTable_HIGH_PA_ENTRY(24, 2, 1, 29, 7) }, + { 12, RF_TxPowerTable_HIGH_PA_ENTRY(19, 2, 1, 16, 25) }, + { 13, RF_TxPowerTable_HIGH_PA_ENTRY(27, 2, 1, 19, 13) }, + { 14, RF_TxPowerTable_HIGH_PA_ENTRY(24, 2, 1, 19, 27) }, + { 15, RF_TxPowerTable_HIGH_PA_ENTRY(23, 2, 1, 20, 39) }, + { 16, RF_TxPowerTable_HIGH_PA_ENTRY(34, 2, 1, 26, 23) }, + { 17, RF_TxPowerTable_HIGH_PA_ENTRY(38, 2, 1, 33, 25) }, + { 18, RF_TxPowerTable_HIGH_PA_ENTRY(30, 2, 1, 37, 53) }, + { 19, RF_TxPowerTable_HIGH_PA_ENTRY(36, 2, 1, 57, 59) }, + { 20, RF_TxPowerTable_HIGH_PA_ENTRY(56, 2, 1, 45, 63) }, + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +tx_power_table_t rf_ble_tx_power_table_empty[] = +{ + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +/* TX power table, based on which board is used. */ +#if defined(DEVICE_CC1352R) +#define TX_POWER_TABLE rf_ble_tx_power_table_cc1352r + +#elif defined(DEVICE_CC1352P) +#if RF_TXPOWER_HIGH_PA +#define TX_POWER_TABLE rf_ble_tx_power_table_cc1352p_hpa +#else +#define TX_POWER_TABLE rf_ble_tx_power_table_cc1352p_dpa +#endif + +#else +#define TX_POWER_TABLE rf_ble_tx_power_table_empty +#endif + +/* + * Define symbols for both the TX power table and its size. The TX power + * table size is with one less entry by excluding the termination entry. + */ +tx_power_table_t *const ble_tx_power_table = TX_POWER_TABLE; +const size_t ble_tx_power_table_size = (sizeof(TX_POWER_TABLE) / sizeof(TX_POWER_TABLE[0])) - 1; +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ieee-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ieee-settings.c new file mode 100644 index 000000000..1f5e3d8d7 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ieee-settings.c @@ -0,0 +1,322 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/*---------------------------------------------------------------------------*/ +/* + * Parameter summary + * IEEE Channel: 11 + * Frequency: 2405 MHz + * SFD: 0 + * Packet Data: 255 + * Preamble (32 bit): 01010101... + * For Default PA: + * Enable high output power PA: false + * TX Power: 5 dBm (requires define CCFG_FORCE_VDDR_HH = 0 in ccfg.c, + * see CC13xx/CC26xx Technical Reference Manual) + * For High PA: + * Enable high output power PA: true + * TX Power: 20 dBm (requires define CCFG_FORCE_VDDR_HH = 0 in ccfg.c, + * see CC13xx/CC26xx Technical Reference Manual) + */ +/*---------------------------------------------------------------------------*/ +#include "sys/cc.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_ieee_cmd.h) +#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_ieee_802_15_4.h) +#include DeviceFamily_constructPath(rf_patches/rf_patch_mce_ieee_802_15_4.h) + +#include +/*---------------------------------------------------------------------------*/ +#include "ieee-settings.h" +/*---------------------------------------------------------------------------*/ +/* TI-RTOS RF Mode Object */ +RF_Mode rf_ieee_mode = +{ + .rfMode = RF_MODE_AUTO, + .cpePatchFxn = &rf_patch_cpe_ieee_802_15_4, + .mcePatchFxn = &rf_patch_mce_ieee_802_15_4, + .rfePatchFxn = 0, +}; +/*---------------------------------------------------------------------------*/ +#if defined(DEVICE_CC1352R) +/* + * CMD_RADIO_SETUP must be configured with default TX power value + * in the .txPower field. + */ +#define DEFAULT_TX_POWER 0x941E /* 5 dBm */ +/*---------------------------------------------------------------------------*/ +/* Overrides for CMD_RADIO_SETUP */ +uint32_t rf_ieee_overrides[] CC_ALIGN(4) = +{ + /* override_ieee_802_15_4.xml */ + MCE_RFE_OVERRIDE(1,0,0,0,1,0), /* PHY: Use MCE RAM patch, RFE ROM bank 1 */ + (uint32_t)0x02400403, /* Synth: Use 48 MHz crystal, enable extra PLL filtering */ + (uint32_t)0x001C8473, /* Synth: Configure extra PLL filtering */ + (uint32_t)0x00088433, /* Synth: Configure synth hardware */ + (uint32_t)0x00038793, /* Synth: Set minimum RTRIM to 3 */ + HW32_ARRAY_OVERRIDE(0x4004,1), /* Synth: Configure faster calibration */ + (uint32_t)0x1C0C0618, /* Synth: Configure faster calibration */ + (uint32_t)0xC00401A1, /* Synth: Configure faster calibration */ + (uint32_t)0x00010101, /* Synth: Configure faster calibration */ + (uint32_t)0xC0040141, /* Synth: Configure faster calibration */ + (uint32_t)0x00214AD3, /* Synth: Configure faster calibration */ + (uint32_t)0x02980243, /* Synth: Decrease synth programming time-out (0x0298 RAT ticks = 166 us) */ + /* DC/DC regulator: In Tx, use DCDCCTL5[3:0]=0xC (DITHER_EN=1 and IPEAK=4). */ + (uint32_t)0xFCFC08C3, /* In Rx, use DCDCCTL5[3:0]=0xC (DITHER_EN=1 and IPEAK=4). */ + (uint32_t)0x000F8883, /* Rx: Set LNA bias current offset to +15 to saturate trim to max (default: 0) */ + (uint32_t)0xFFFFFFFF, +}; + +#endif /* defined(DEVICE_CC1352R) */ +/*---------------------------------------------------------------------------*/ +#if defined(DEVICE_CC1352P) + +#if RF_CONF_TXPOWER_HIGH_PA +/* + * CMD_PROP_RADIO_DIV_SETUP must be configured with default TX power value + * in the .txPower field. For High PA, this must be 0xFFFF. + */ +#define DEFAULT_TX_POWER 0xFFFF /* High PA */ +/*---------------------------------------------------------------------------*/ +/* Overrides for CMD_RADIO_SETUP with high PA */ +uint32_t rf_ieee_overrides[] CC_ALIGN(4) = +{ + /* override_ieee_802_15_4.xml */ + MCE_RFE_OVERRIDE(1,0,0,0,1,0), /* PHY: Use MCE RAM patch, RFE ROM bank 1 */ + (uint32_t)0x02400403, /* Synth: Use 48 MHz crystal, enable extra PLL filtering */ + (uint32_t)0x001C8473, /* Synth: Configure extra PLL filtering */ + (uint32_t)0x00088433, /* Synth: Configure synth hardware */ + (uint32_t)0x00038793, /* Synth: Set minimum RTRIM to 3 */ + HW32_ARRAY_OVERRIDE(0x4004,1), /* Synth: Configure faster calibration */ + (uint32_t)0x1C0C0618, /* Synth: Configure faster calibration */ + (uint32_t)0xC00401A1, /* Synth: Configure faster calibration */ + (uint32_t)0x00010101, /* Synth: Configure faster calibration */ + (uint32_t)0xC0040141, /* Synth: Configure faster calibration */ + (uint32_t)0x00214AD3, /* Synth: Configure faster calibration */ + (uint32_t)0x02980243, /* Synth: Decrease synth programming time-out (0x0298 RAT ticks = 166 us) */ + /* DC/DC regulator: In Tx, use DCDCCTL5[3:0]=0xC (DITHER_EN=1 and IPEAK=4). */ + (uint32_t)0xFCFC08C3, /* In Rx, use DCDCCTL5[3:0]=0xC (DITHER_EN=1 and IPEAK=4). */ + (uint32_t)0x000F8883, /* Rx: Set LNA bias current offset to +15 to saturate trim to max (default: 0) */ + /* override_frontend_xd.xml */ + /* TX power override */ + (uint32_t)0xFD6EE02B, /* txHighPA=0x3F5BB8 */ + (uint32_t)0xFFFFFFFF, +}; +/*---------------------------------------------------------------------------*/ +#else +/* + * CMD_RADIO_SETUP must be configured with default TX power value + * in the .txPower field. + */ +#define DEFAULT_TX_POWER 0x941E /* 5 dBm */ +/*---------------------------------------------------------------------------*/ +/* Overrides for CMD_RADIO_SETUP with default PA */ +uint32_t rf_ieee_overrides[] CC_ALIGN(4) = +{ + /* override_ieee_802_15_4.xml */ + MCE_RFE_OVERRIDE(1,0,0,0,1,0), /* PHY: Use MCE RAM patch, RFE ROM bank 1 */ + (uint32_t)0x02400403, /* Synth: Use 48 MHz crystal, enable extra PLL filtering */ + (uint32_t)0x001C8473, /* Synth: Configure extra PLL filtering */ + (uint32_t)0x00088433, /* Synth: Configure synth hardware */ + (uint32_t)0x00038793, /* Synth: Set minimum RTRIM to 3 */ + HW32_ARRAY_OVERRIDE(0x4004,1), /* Synth: Configure faster calibration */ + (uint32_t)0x1C0C0618, /* Synth: Configure faster calibration */ + (uint32_t)0xC00401A1, /* Synth: Configure faster calibration */ + (uint32_t)0x00010101, /* Synth: Configure faster calibration */ + (uint32_t)0xC0040141, /* Synth: Configure faster calibration */ + (uint32_t)0x00214AD3, /* Synth: Configure faster calibration */ + (uint32_t)0x02980243, /* Synth: Decrease synth programming time-out (0x0298 RAT ticks = 166 us) */ + /* DC/DC regulator: In Tx, use DCDCCTL5[3:0]=0xC (DITHER_EN=1 and IPEAK=4). */ + (uint32_t)0xFCFC08C3, /* In Rx, use DCDCCTL5[3:0]=0xC (DITHER_EN=1 and IPEAK=4). */ + (uint32_t)0x000F8883, /* Rx: Set LNA bias current offset to +15 to saturate trim to max (default: 0) */ + (uint32_t)0xFFFFFFFF, +}; + +#endif /* RF_CONF_TXPOWER_HIGH_PA */ + +#endif /* defined(DEVICE_CC1352P) */ +/*---------------------------------------------------------------------------*/ +/* CMD_RADIO_SETUP: Radio Setup Command for Pre-Defined Schemes */ +rfc_CMD_RADIO_SETUP_t rf_cmd_ieee_radio_setup = +{ + .commandNo = CMD_RADIO_SETUP, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .mode = 0x01, + .loDivider = 0x00, + .config.frontEndMode = 0x0, + .config.biasMode = 0x0, + .config.analogCfgMode = 0x0, + .config.bNoFsPowerUp = 0x0, + .txPower = DEFAULT_TX_POWER, /* 5 dBm default */ + .pRegOverride = rf_ieee_overrides, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_FS: Frequency Synthesizer Programming Command */ +rfc_CMD_FS_t rf_cmd_ieee_fs = +{ + .commandNo = CMD_FS, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .frequency = 0x0965, /* set by driver */ + .fractFreq = 0x0000, /* set by driver */ + .synthConf.bTxMode = 0x1, + .synthConf.refFreq = 0x0, + .__dummy0 = 0x00, + .__dummy1 = 0x00, + .__dummy2 = 0x00, + .__dummy3 = 0x0000, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_IEEE_TX: IEEE 802.15.4 Transmit Command */ +rfc_CMD_IEEE_TX_t rf_cmd_ieee_tx = +{ + .commandNo = CMD_IEEE_TX, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .txOpt.bIncludePhyHdr = 0x0, + .txOpt.bIncludeCrc = 0x0, + .txOpt.payloadLenMsb = 0x0, + .payloadLen = 0x0, /* set by driver */ + .pPayload = 0, /* set by driver */ + .timeStamp = 0x00000000, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_IEEE_RX: IEEE 802.15.4 Receive Command */ +rfc_CMD_IEEE_RX_t rf_cmd_ieee_rx = +{ + .commandNo = CMD_IEEE_RX, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .channel = 0x00, /* set by driver */ + .rxConfig.bAutoFlushCrc = 0x1, + .rxConfig.bAutoFlushIgn = 0x1, + .rxConfig.bIncludePhyHdr = 0x0, + .rxConfig.bIncludeCrc = 0x1, + .rxConfig.bAppendRssi = 0x1, + .rxConfig.bAppendCorrCrc = 0x1, + .rxConfig.bAppendSrcInd = 0x0, + .rxConfig.bAppendTimestamp = 0x1, + .pRxQ = 0, /* set by driver */ + .pOutput = 0, /* set by driver */ + .frameFiltOpt.frameFiltEn = 0x0, /* set by driver */ + .frameFiltOpt.frameFiltStop = 0x1, + .frameFiltOpt.autoAckEn = 0x0, /* set by driver */ + .frameFiltOpt.slottedAckEn = 0x0, + .frameFiltOpt.autoPendEn = 0x0, + .frameFiltOpt.defaultPend = 0x0, + .frameFiltOpt.bPendDataReqOnly = 0x0, + .frameFiltOpt.bPanCoord = 0x0, + .frameFiltOpt.maxFrameVersion = 0x2, + .frameFiltOpt.fcfReservedMask = 0x0, + .frameFiltOpt.modifyFtFilter = 0x0, + .frameFiltOpt.bStrictLenFilter = 0x0, + .frameTypes.bAcceptFt0Beacon = 0x1, + .frameTypes.bAcceptFt1Data = 0x1, + .frameTypes.bAcceptFt2Ack = 0x1, + .frameTypes.bAcceptFt3MacCmd = 0x1, + .frameTypes.bAcceptFt4Reserved = 0x1, + .frameTypes.bAcceptFt5Reserved = 0x1, + .frameTypes.bAcceptFt6Reserved = 0x1, + .frameTypes.bAcceptFt7Reserved = 0x1, + .ccaOpt.ccaEnEnergy = 0x1, + .ccaOpt.ccaEnCorr = 0x1, + .ccaOpt.ccaEnSync = 0x1, + .ccaOpt.ccaCorrOp = 0x1, + .ccaOpt.ccaSyncOp = 0x0, + .ccaOpt.ccaCorrThr = 0x3, + .ccaRssiThr = 0x0, /* set by driver */ + .__dummy0 = 0x00, + .numExtEntries = 0x00, + .numShortEntries = 0x00, + .pExtEntryList = 0, + .pShortEntryList = 0, + .localExtAddr = 0x0, /* set by driver */ + .localShortAddr = 0x0, /* set by driver */ + .localPanID = 0x0000, + .__dummy1 = 0x000000, + .endTrigger.triggerType = TRIG_NEVER, + .endTrigger.bEnaCmd = 0x0, + .endTrigger.triggerNo = 0x0, + .endTrigger.pastTrig = 0x0, + .endTime = 0x00000000, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_IEEE_RX_ACK: IEEE 802.15.4 Receive ACK Command */ +rfc_CMD_IEEE_RX_ACK_t rf_cmd_ieee_rx_ack = +{ + .commandNo = CMD_IEEE_RX_ACK, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .seqNo = 0x0, + .endTrigger.triggerType = TRIG_NEVER, + .endTrigger.bEnaCmd = 0x0, + .endTrigger.triggerNo = 0x0, + .endTrigger.pastTrig = 0x0, + .endTime = 0x00000000, +}; +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ieee-settings.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ieee-settings.h new file mode 100644 index 000000000..7019598c8 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ieee-settings.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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 IEEE_SETTINGS_H_ +#define IEEE_SETTINGS_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki-conf.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_ieee_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_ieee_mailbox.h) + +#include +/*---------------------------------------------------------------------------*/ +/* TI-RTOS RF Mode Object */ +extern RF_Mode rf_ieee_mode; +/*---------------------------------------------------------------------------*/ +/* RF Core API commands */ +extern rfc_CMD_RADIO_SETUP_t rf_cmd_ieee_radio_setup; +extern rfc_CMD_FS_t rf_cmd_ieee_fs; +extern rfc_CMD_IEEE_TX_t rf_cmd_ieee_tx; +extern rfc_CMD_IEEE_RX_t rf_cmd_ieee_rx; +extern rfc_CMD_IEEE_RX_ACK_t rf_cmd_ieee_rx_ack; +/*---------------------------------------------------------------------------*/ +/* RF Core API Overrides */ +extern uint32_t rf_ieee_overrides[]; +/*---------------------------------------------------------------------------*/ +#endif /* IEEE_SETTINGS_H_ */ +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ieee-tx-power.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ieee-tx-power.c new file mode 100644 index 000000000..efd143e9d --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/ieee-tx-power.c @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-rf-tx-power + * @{ + * + * \file + * Source file for IEEE-mode TX power tables for CC13x2. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +/*---------------------------------------------------------------------------*/ +#include "rf/tx-power.h" +/*---------------------------------------------------------------------------*/ +/* + * TX Power table for CC1312R + * The RF_TxPowerTable_DEFAULT_PA_ENTRY macro is defined in RF.h and requires the following arguments: + * RF_TxPowerTable_DEFAULT_PA_ENTRY(bias, gain, boost coefficient) + * See the Technical Reference Manual for further details about the "txPower" Command field. + * The PA settings require the CCFG_FORCE_VDDR_HH = 0 unless stated otherwise. + */ +tx_power_table_t rf_ieee_tx_power_table_cc1312r[] = +{ + { -21, RF_TxPowerTable_DEFAULT_PA_ENTRY( 7, 3, 0, 3) }, + { -18, RF_TxPowerTable_DEFAULT_PA_ENTRY( 9, 3, 0, 3) }, + { -15, RF_TxPowerTable_DEFAULT_PA_ENTRY( 8, 2, 0, 6) }, + { -12, RF_TxPowerTable_DEFAULT_PA_ENTRY(10, 2, 0, 8) }, + { -10, RF_TxPowerTable_DEFAULT_PA_ENTRY(12, 2, 0, 11) }, + { -9, RF_TxPowerTable_DEFAULT_PA_ENTRY(13, 2, 0, 5) }, + { -6, RF_TxPowerTable_DEFAULT_PA_ENTRY(13, 1, 0, 16) }, + { -5, RF_TxPowerTable_DEFAULT_PA_ENTRY(14, 1, 0, 17) }, + { -3, RF_TxPowerTable_DEFAULT_PA_ENTRY(17, 1, 0, 20) }, + { 0, RF_TxPowerTable_DEFAULT_PA_ENTRY(25, 1, 0, 26) }, + { 1, RF_TxPowerTable_DEFAULT_PA_ENTRY(28, 1, 0, 28) }, + { 2, RF_TxPowerTable_DEFAULT_PA_ENTRY(13, 0, 0, 34) }, + { 3, RF_TxPowerTable_DEFAULT_PA_ENTRY(17, 0, 0, 42) }, + { 4, RF_TxPowerTable_DEFAULT_PA_ENTRY(22, 0, 0, 54) }, + { 5, RF_TxPowerTable_DEFAULT_PA_ENTRY(30, 0, 0, 74) }, + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +/* + * TX Power table for CC1352R + * The RF_TxPowerTable_DEFAULT_PA_ENTRY macro is defined in RF.h and requires the following arguments: + * RF_TxPowerTable_DEFAULT_PA_ENTRY(bias, gain, boost coefficient) + * See the Technical Reference Manual for further details about the "txPower" Command field. + * The PA settings require the CCFG_FORCE_VDDR_HH = 0 unless stated otherwise. + */ +tx_power_table_t rf_ieee_tx_power_table_cc1352r[] = +{ + { -21, RF_TxPowerTable_DEFAULT_PA_ENTRY( 7, 3, 0, 3) }, + { -18, RF_TxPowerTable_DEFAULT_PA_ENTRY( 9, 3, 0, 3) }, + { -15, RF_TxPowerTable_DEFAULT_PA_ENTRY( 8, 2, 0, 6) }, + { -12, RF_TxPowerTable_DEFAULT_PA_ENTRY(10, 2, 0, 8) }, + { -10, RF_TxPowerTable_DEFAULT_PA_ENTRY(12, 2, 0, 11) }, + { -9, RF_TxPowerTable_DEFAULT_PA_ENTRY(13, 2, 0, 5) }, + { -6, RF_TxPowerTable_DEFAULT_PA_ENTRY(13, 1, 0, 16) }, + { -5, RF_TxPowerTable_DEFAULT_PA_ENTRY(14, 1, 0, 17) }, + { -3, RF_TxPowerTable_DEFAULT_PA_ENTRY(17, 1, 0, 20) }, + { 0, RF_TxPowerTable_DEFAULT_PA_ENTRY(25, 1, 0, 26) }, + { 1, RF_TxPowerTable_DEFAULT_PA_ENTRY(28, 1, 0, 28) }, + { 2, RF_TxPowerTable_DEFAULT_PA_ENTRY(13, 0, 0, 34) }, + { 3, RF_TxPowerTable_DEFAULT_PA_ENTRY(17, 0, 0, 42) }, + { 4, RF_TxPowerTable_DEFAULT_PA_ENTRY(22, 0, 0, 54) }, + { 5, RF_TxPowerTable_DEFAULT_PA_ENTRY(30, 0, 0, 74) }, + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +/* + * TX Power table for CC1352P with default PA + * The RF_TxPowerTable_DEFAULT_PA_ENTRY macro is defined in RF.h and requires the following arguments: + * RF_TxPowerTable_DEFAULT_PA_ENTRY(bias, gain, boost coefficient) + * See the Technical Reference Manual for further details about the "txPower" Command field. + * The PA settings require the CCFG_FORCE_VDDR_HH = 0 unless stated otherwise. + */ +tx_power_table_t rf_ieee_tx_power_table_cc1352p_dpa[] = +{ + { -21, RF_TxPowerTable_DEFAULT_PA_ENTRY( 7, 3, 0, 3) }, + { -18, RF_TxPowerTable_DEFAULT_PA_ENTRY( 9, 3, 0, 3) }, + { -15, RF_TxPowerTable_DEFAULT_PA_ENTRY( 8, 2, 0, 6) }, + { -12, RF_TxPowerTable_DEFAULT_PA_ENTRY(10, 2, 0, 8) }, + { -10, RF_TxPowerTable_DEFAULT_PA_ENTRY(12, 2, 0, 11) }, + { -9, RF_TxPowerTable_DEFAULT_PA_ENTRY(13, 2, 0, 5) }, + { -6, RF_TxPowerTable_DEFAULT_PA_ENTRY(13, 1, 0, 16) }, + { -5, RF_TxPowerTable_DEFAULT_PA_ENTRY(14, 1, 0, 17) }, + { -3, RF_TxPowerTable_DEFAULT_PA_ENTRY(17, 1, 0, 20) }, + { 0, RF_TxPowerTable_DEFAULT_PA_ENTRY(25, 1, 0, 26) }, + { 1, RF_TxPowerTable_DEFAULT_PA_ENTRY(28, 1, 0, 28) }, + { 2, RF_TxPowerTable_DEFAULT_PA_ENTRY(13, 0, 0, 34) }, + { 3, RF_TxPowerTable_DEFAULT_PA_ENTRY(17, 0, 0, 42) }, + { 4, RF_TxPowerTable_DEFAULT_PA_ENTRY(22, 0, 0, 54) }, + { 5, RF_TxPowerTable_DEFAULT_PA_ENTRY(30, 0, 0, 74) }, + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +/* + * TX Power table for CC1352P with high PA + * The RF_TxPowerTable_HIGH_PA_ENTRY macro is defined in RF.h and requires the following arguments: + * RF_TxPowerTable_HIGH_PA_ENTRY(bias, ibboost, boost, coefficient, ldoTrim) + * See the Technical Reference Manual for further details about the "txPower" Command field. + * The PA settings require the CCFG_FORCE_VDDR_HH = 0 unless stated otherwise. + */ +tx_power_table_t rf_ieee_tx_power_table_cc1352p_hpa[] = +{ + { 0, RF_TxPowerTable_HIGH_PA_ENTRY(29, 0, 1, 17, 1) }, + { 3, RF_TxPowerTable_HIGH_PA_ENTRY(39, 0, 1, 20, 1) }, + { 6, RF_TxPowerTable_HIGH_PA_ENTRY(46, 0, 1, 26, 7) }, + { 9, RF_TxPowerTable_HIGH_PA_ENTRY(40, 0, 1, 39, 41) }, + { 10, RF_TxPowerTable_HIGH_PA_ENTRY(23, 2, 1, 65, 5) }, + { 11, RF_TxPowerTable_HIGH_PA_ENTRY(24, 2, 1, 29, 7) }, + { 12, RF_TxPowerTable_HIGH_PA_ENTRY(19, 2, 1, 16, 25) }, + { 13, RF_TxPowerTable_HIGH_PA_ENTRY(27, 2, 1, 19, 13) }, + { 14, RF_TxPowerTable_HIGH_PA_ENTRY(24, 2, 1, 19, 27) }, + { 15, RF_TxPowerTable_HIGH_PA_ENTRY(23, 2, 1, 20, 39) }, + { 16, RF_TxPowerTable_HIGH_PA_ENTRY(34, 2, 1, 26, 23) }, + { 17, RF_TxPowerTable_HIGH_PA_ENTRY(38, 2, 1, 33, 25) }, + { 18, RF_TxPowerTable_HIGH_PA_ENTRY(30, 2, 1, 37, 53) }, + { 19, RF_TxPowerTable_HIGH_PA_ENTRY(36, 2, 1, 57, 59) }, + { 20, RF_TxPowerTable_HIGH_PA_ENTRY(56, 2, 1, 45, 63) }, + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +tx_power_table_t rf_ieee_ztx_power_table_empty[] = +{ + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +/* Only define the symbols if Prop-mode is selected */ +#if (RF_MODE == RF_MODE_2_4_GHZ) +/*---------------------------------------------------------------------------*/ +/* TX power table, based on which board is used. */ +#if defined(DEVICE_CC1312R) +#define TX_POWER_TABLE rf_ieee_tx_power_table_cc1312r + +#elif defined(DEVICE_CC1352R) +#define TX_POWER_TABLE rf_ieee_tx_power_table_cc1352r + +#elif defined(DEVICE_CC1352P) +#if RF_TXPOWER_HIGH_PA +#define TX_POWER_TABLE rf_ieee_tx_power_table_cc1352p_hpa +#else +#define TX_POWER_TABLE rf_ieee_tx_power_table_cc1352p_dpa +#endif + +#else +#define TX_POWER_TABLE rf_ieee_tx_power_table_empty +#endif + +/* + * Define symbols for both the TX power table and its size. The TX power + * table size is with one less entry by excluding the termination entry. + */ +tx_power_table_t *const rf_tx_power_table = TX_POWER_TABLE; +const size_t rf_tx_power_table_size = (sizeof(TX_POWER_TABLE) / sizeof(TX_POWER_TABLE[0])) - 1; +/*---------------------------------------------------------------------------*/ +#endif /* RF_MODE */ +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/prop-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/prop-settings.c new file mode 100644 index 000000000..c63e6bef7 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/prop-settings.c @@ -0,0 +1,406 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/*---------------------------------------------------------------------------*/ +/* + * Parameter summary + * Address: 0 + * Address0: 0xAA + * Address1: 0xBB + * Frequency: 915.00000 MHz + * Data Format: Serial mode disable + * Deviation: 25.000 kHz + * pktLen: 30 + * 802.15.4g Mode: 0 + * Select bit order to transmit PSDU octets:: 1 + * Packet Length Config: Variable + * Max Packet Length: 255 + * Packet Length: 20 + * Packet Data: 255 + * RX Filter BW: 98.0 kHz + * Symbol Rate: 50.00000 kBaud + * Sync Word Length: 24 Bits + * For Default PA: + * Enable high output power PA: false + * TX Power: 13.5 dBm (requires define CCFG_FORCE_VDDR_HH = 1 in ccfg.c, + * see CC13xx/CC26xx Technical Reference Manual) + * For High PA: + * Enable high output power PA: true + * TX Power: 20 dBm (requires define CCFG_FORCE_VDDR_HH = 0 in ccfg.c, + * see CC13xx/CC26xx Technical Reference Manual) + * Whitening: Dynamically IEEE 802.15.4g compatible whitener and 16/32-bit CRC + */ +/*---------------------------------------------------------------------------*/ +#include "sys/cc.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_prop_cmd.h) +#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_prop.h) +#include DeviceFamily_constructPath(rf_patches/rf_patch_rfe_genfsk.h) +#include DeviceFamily_constructPath(rf_patches/rf_patch_mce_genfsk.h) + +#include +/*---------------------------------------------------------------------------*/ +#include "prop-settings.h" +/*---------------------------------------------------------------------------*/ +/* TI-RTOS RF Mode Object */ +RF_Mode rf_prop_mode = +{ + .rfMode = RF_MODE_AUTO, + .cpePatchFxn = &rf_patch_cpe_prop, + .mcePatchFxn = &rf_patch_mce_genfsk, + .rfePatchFxn = &rf_patch_rfe_genfsk, +}; +/*---------------------------------------------------------------------------*/ +#if defined(DEVICE_CC1312R) || defined(DEVICE_CC1352R) +/* + * CMD_PROP_RADIO_DIV_SETUP must be configured with default TX power value + * in the .txPower field. This depends on whether RF_CONF_TXPOWER_BOOST_MODE + * is configured or not. + */ +#if RF_CONF_TXPOWER_BOOST_MODE +#define DEFAULT_TX_POWER 0x9F3F /* 14 dBm */ +#else +#define DEFAULT_TX_POWER 0xCC14 /* 12.5 dBm (rounded up to 13 dBm) */ +#endif + +/*---------------------------------------------------------------------------*/ +/* Overrides for CMD_PROP_RADIO_DIV_SETUP */ +uint32_t rf_prop_overrides[] CC_ALIGN(4) = +{ + /* override_use_patch_prop_genfsk.xml */ + MCE_RFE_OVERRIDE(1,0,0,1,0,0), /* PHY: Use MCE RAM patch, RFE RAM patch */ + /* override_synth_prop_863_930_div5.xml */ + (uint32_t)0x02400403, /* Synth: Use 48 MHz crystal as synth clock, enable extra PLL filtering */ + (uint32_t)0x00068793, /* Synth: Set minimum RTRIM to 6 */ + (uint32_t)0x001C8473, /* Synth: Configure extra PLL filtering */ + (uint32_t)0x00088433, /* Synth: Configure extra PLL filtering */ + (uint32_t)0x000684A3, /* Synth: Set Fref to 4 MHz */ + HW32_ARRAY_OVERRIDE(0x4004,1), /* Synth: Configure faster calibration */ + (uint32_t)0x180C0618, /* Synth: Configure faster calibration */ + (uint32_t)0xC00401A1, /* Synth: Configure faster calibration */ + (uint32_t)0x00010101, /* Synth: Configure faster calibration */ + (uint32_t)0xC0040141, /* Synth: Configure faster calibration */ + (uint32_t)0x00214AD3, /* Synth: Configure faster calibration */ + /* Synth: Decrease synth programming time-out by 90 us from default */ + (uint32_t)0x02980243, /* (0x0298 RAT ticks = 166 us) */ + (uint32_t)0x0A480583, /* Synth: Set loop bandwidth after lock to 20 kHz */ + (uint32_t)0x7AB80603, /* Synth: Set loop bandwidth after lock to 20 kHz */ + (uint32_t)0x00000623, /* Synth: Set loop bandwidth after lock to 20 kHz */ + /* override_phy_tx_pa_ramp_genfsk_hpa.xml */ + ADI_HALFREG_OVERRIDE(0,16,0x8,0x8), /* Tx: Configure PA ramp time, PACTL2.RC=0x3 (in ADI0, set PACTL2[3]=1) */ + ADI_HALFREG_OVERRIDE(0,17,0x1,0x1), /* Tx: Configure PA ramp time, PACTL2.RC=0x3 (in ADI0, set PACTL2[4]=1) */ + /* override_phy_rx_frontend_genfsk.xml */ + HW_REG_OVERRIDE(0x609C,0x001A), /* Rx: Set AGC reference level to 0x1A (default: 0x2E) */ + (uint32_t)0x00018883, /* Rx: Set LNA bias current offset to adjust +1 (default: 0) */ + (uint32_t)0x000288A3, /* Rx: Set RSSI offset to adjust reported RSSI by -2 dB (default: 0) */ + /* override_phy_rx_aaf_bw_0xd.xml */ + /* Rx: Set anti-aliasing filter bandwidth to 0xD */ + ADI_HALFREG_OVERRIDE(0,61,0xF,0xD), /* (in ADI0, set IFAMPCTL3[7:4]=0xD) */ +#if RF_CONF_TXPOWER_BOOST_MODE + /* TX power override */ + /* DC/DC regulator: In Tx with 14 dBm PA setting, */ + /* use DCDCCTL5[3:0]=0xF (DITHER_EN=1 and IPEAK=7). */ + (uint32_t)0xFFFC08C3, /* In Rx, use DCDCCTL5[3:0]=0xC (DITHER_EN=1 and IPEAK=4). */ + /* Tx: Set PA trim to max to maximize its output power */ + ADI_REG_OVERRIDE(0,12,0xF8), /* (in ADI0, set PACTL0=0xF8) */ +#else + /* TX power override */ + /* DC/DC regulator: */ + /* In Tx, use DCDCCTL5[3:0]=0xC (DITHER_EN=1 and IPEAK=4). */ + (uint32_t)0xFCFC08C3, /* In Rx, use DCDCCTL5[3:0]=0xC (DITHER_EN=1 and IPEAK=4). */ +#endif + (uint32_t)0xFFFFFFFF, +}; + +#endif /* defined(DEVICE_CC1312R) || defined(DEVICE_CC1352R) */ +/*---------------------------------------------------------------------------*/ +#if defined(DEVICE_CC1352P) + +#if RF_CONF_TXPOWER_HIGH_PA +/* + * CMD_PROP_RADIO_DIV_SETUP must be configured with default TX power value + * in the .txPower field. For High PA, this must be 0xFFFF. + */ +#define DEFAULT_TX_POWER 0xFFFF /* High PA */ + +/*---------------------------------------------------------------------------*/ +/* Overrides for CMD_PROP_RADIO_DIV_SETUP with high PA */ +uint32_t rf_prop_overrides[] CC_ALIGN(4) = +{ + /* override_use_patch_prop_genfsk.xml */ + MCE_RFE_OVERRIDE(1,0,0,1,0,0), /* PHY: Use MCE RAM patch, RFE RAM patch */ + /* override_synth_prop_863_930_div5.xml */ + (uint32_t)0x02400403, /* Synth: Use 48 MHz crystal as synth clock, enable extra PLL filtering */ + (uint32_t)0x00068793, /* Synth: Set minimum RTRIM to 6 */ + (uint32_t)0x001C8473, /* Synth: Configure extra PLL filtering */ + (uint32_t)0x00088433, /* Synth: Configure extra PLL filtering */ + (uint32_t)0x000684A3, /* Synth: Set Fref to 4 MHz */ + HW32_ARRAY_OVERRIDE(0x4004,1), /* Synth: Configure faster calibration */ + (uint32_t)0x180C0618, /* Synth: Configure faster calibration */ + (uint32_t)0xC00401A1, /* Synth: Configure faster calibration */ + (uint32_t)0x00010101, /* Synth: Configure faster calibration */ + (uint32_t)0xC0040141, /* Synth: Configure faster calibration */ + (uint32_t)0x00214AD3, /* Synth: Configure faster calibration */ + /* Synth: Decrease synth programming time-out by 90 us */ + (uint32_t)0x02980243, /* from default (0x0298 RAT ticks = 166 us) */ + (uint32_t)0x0A480583, /* Synth: Set loop bandwidth after lock to 20 kHz */ + (uint32_t)0x7AB80603, /* Synth: Set loop bandwidth after lock to 20 kHz */ + (uint32_t)0x00000623, /* Synth: Set loop bandwidth after lock to 20 kHz */ + /* override_phy_tx_pa_ramp_genfsk_hpa.xml */ + /* Tx: Configure PA ramping, set wait time before turning off */ + HW_REG_OVERRIDE(0x6028,0x002F), /* (0x2F ticks of 16/24 us = 31.3 us). */ + ADI_HALFREG_OVERRIDE(0,16,0x8,0x8), /* Tx: Configure PA ramp time, PACTL2.RC=0x3 (in ADI0, set PACTL2[3]=1) */ + ADI_HALFREG_OVERRIDE(0,17,0x1,0x1), /* Tx: Configure PA ramp time, PACTL2.RC=0x3 (in ADI0, set PACTL2[4]=1) */ + /* override_phy_rx_frontend_genfsk.xml */ + HW_REG_OVERRIDE(0x609C,0x001A), /* Rx: Set AGC reference level to 0x1A (default: 0x2E) */ + (uint32_t)0x00018883, /* Rx: Set LNA bias current offset to adjust +1 (default: 0) */ + (uint32_t)0x000288A3, /* Rx: Set RSSI offset to adjust reported RSSI by -2 dB (default: 0) */ + /* override_phy_rx_aaf_bw_0xd.xml */ + /* Rx: Set anti-aliasing filter bandwidth to 0xD */ + ADI_HALFREG_OVERRIDE(0,61,0xF,0xD), /* (in ADI0, set IFAMPCTL3[7:4]=0xD) */ + /* TX power override */ + /* DC/DC regulator: */ + /* In Tx, use DCDCCTL5[3:0]=0xC (DITHER_EN=1 and IPEAK=4). */ + (uint32_t)0xFCFC08C3, /* In Rx, use DCDCCTL5[3:0]=0xC (DITHER_EN=1 and IPEAK=4). */ + (uint32_t)0x82A86C2B, /* txHighPA=0x20AA1B */ + (uint32_t)0xFFFFFFFF, +}; + +#else +/*---------------------------------------------------------------------------*/ +/* + * CMD_PROP_RADIO_DIV_SETUP must be configured with default TX power value + * in the .txPower field. This depends on whether RF_CONF_TXPOWER_BOOST_MODE + * is configured or not. + */ +#if RF_CONF_TXPOWER_BOOST_MODE +#define DEFAULT_TX_POWER 0x013F /* 13.5 dBm (rounded up to 14 dBm) */ +#else +#define DEFAULT_TX_POWER 0x803F /* 12 dBm */ +#endif + +/*---------------------------------------------------------------------------*/ +/* Overrides for CMD_PROP_RADIO_DIV_SETUP with defualt PA */ +uint32_t rf_prop_overrides[] CC_ALIGN(4) = +{ + /* override_use_patch_prop_genfsk.xml */ + MCE_RFE_OVERRIDE(1,0,0,1,0,0), /* PHY: Use MCE RAM patch, RFE RAM patch */ + /* override_synth_prop_863_930_div5.xml */ + (uint32_t)0x02400403, /* Synth: Use 48 MHz crystal as synth clock, enable extra PLL filtering */ + (uint32_t)0x00068793, /* Synth: Set minimum RTRIM to 6 */ + (uint32_t)0x001C8473, /* Synth: Configure extra PLL filtering */ + (uint32_t)0x00088433, /* Synth: Configure extra PLL filtering */ + (uint32_t)0x000684A3, /* Synth: Set Fref to 4 MHz */ + HW32_ARRAY_OVERRIDE(0x4004,1), /* Synth: Configure faster calibration */ + (uint32_t)0x180C0618, /* Synth: Configure faster calibration */ + (uint32_t)0xC00401A1, /* Synth: Configure faster calibration */ + (uint32_t)0x00010101, /* Synth: Configure faster calibration */ + (uint32_t)0xC0040141, /* Synth: Configure faster calibration */ + (uint32_t)0x00214AD3, /* Synth: Configure faster calibration */ + /* Synth: Decrease synth programming time-out by 90 us from default */ + (uint32_t)0x02980243, /* (0x0298 RAT ticks = 166 us) */ + (uint32_t)0x0A480583, /* Synth: Set loop bandwidth after lock to 20 kHz */ + (uint32_t)0x7AB80603, /* Synth: Set loop bandwidth after lock to 20 kHz */ + (uint32_t)0x00000623, /* Synth: Set loop bandwidth after lock to 20 kHz */ + /* override_phy_tx_pa_ramp_genfsk_hpa.xml */ + /* Tx: Configure PA ramping, set wait time before turning off */ + HW_REG_OVERRIDE(0x6028,0x002F), /* (0x2F ticks of 16/24 us = 31.3 us). */ + ADI_HALFREG_OVERRIDE(0,16,0x8,0x8), /* Tx: Configure PA ramp time, PACTL2.RC=0x3 (in ADI0, set PACTL2[3]=1) */ + ADI_HALFREG_OVERRIDE(0,17,0x1,0x1), /* Tx: Configure PA ramp time, PACTL2.RC=0x3 (in ADI0, set PACTL2[4]=1) */ + /* override_phy_rx_frontend_genfsk.xml */ + HW_REG_OVERRIDE(0x609C,0x001A), /* Rx: Set AGC reference level to 0x1A (default: 0x2E) */ + (uint32_t)0x00018883, /* Rx: Set LNA bias current offset to adjust +1 (default: 0) */ + (uint32_t)0x000288A3, /* Rx: Set RSSI offset to adjust reported RSSI by -2 dB (default: 0) */ + /* override_phy_rx_aaf_bw_0xd.xml */ + /* Rx: Set anti-aliasing filter bandwidth to 0xD */ + ADI_HALFREG_OVERRIDE(0,61,0xF,0xD), /* (in ADI0, set IFAMPCTL3[7:4]=0xD) */ +#if RF_CONF_TXPOWER_BOOST_MODE + /* TX power override */ + /* DC/DC regulator: In Tx with 14 dBm PA setting, */ + /* use DCDCCTL5[3:0]=0xF (DITHER_EN=1 and IPEAK=7). */ + (uint32_t)0xFFFC08C3, /* In Rx, use DCDCCTL5[3:0]=0xC (DITHER_EN=1 and IPEAK=4). */ + /* Tx: Set PA trim to max to maximize its output power */ + ADI_REG_OVERRIDE(0,12,0xF8), /* (in ADI0, set PACTL0=0xF8) */ +#else + /* TX power override */ + /* DC/DC regulator: */ + /* In Tx, use DCDCCTL5[3:0]=0xC (DITHER_EN=1 and IPEAK=4). */ + (uint32_t)0xFCFC08C3, /* In Rx, use DCDCCTL5[3:0]=0xC (DITHER_EN=1 and IPEAK=4). */ +#endif + (uint32_t)0xFFFFFFFF, +}; + +#endif /* RF_CONF_TXPOWER_HIGH_PA */ + +#endif /* defined(DEVICE_CC1352P) */ +/*---------------------------------------------------------------------------*/ +/* CMD_PROP_RADIO_DIV_SETUP: Proprietary Mode Radio Setup Command for All Frequency Bands */ +rfc_CMD_PROP_RADIO_DIV_SETUP_t rf_cmd_prop_radio_div_setup = +{ + .commandNo = CMD_PROP_RADIO_DIV_SETUP, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .modulation.modType = 0x1, + .modulation.deviation = 0x64, + .modulation.deviationStepSz = 0x0, + .symbolRate.preScale = 0xF, + .symbolRate.rateWord = 0x8000, + .symbolRate.decimMode = 0x0, + .rxBw = 0x52, + .preamConf.nPreamBytes = 0x7, + .preamConf.preamMode = 0x0, + .formatConf.nSwBits = 0x18, + .formatConf.bBitReversal = 0x0, + .formatConf.bMsbFirst = 0x1, + .formatConf.fecMode = 0x0, + .formatConf.whitenMode = 0x7, + .config.frontEndMode = 0x0, /* set by driver */ + .config.biasMode = 0x0, /* set by driver */ + .config.analogCfgMode = 0x0, + .config.bNoFsPowerUp = 0x0, + .txPower = DEFAULT_TX_POWER, + .pRegOverride = rf_prop_overrides, + .centerFreq = 0x0393, /* set by driver */ + .intFreq = 0x8000, /* set by driver */ + .loDivider = 0x05, /* set by driver */ +}; +/*---------------------------------------------------------------------------*/ +/* CMD_FS: Frequency Synthesizer Programming Command */ +rfc_CMD_FS_t rf_cmd_prop_fs = +{ + .commandNo = CMD_FS, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .frequency = 0x0393, /* set by driver */ + .fractFreq = 0x0000, /* set by driver */ + .synthConf.bTxMode = 0x0, + .synthConf.refFreq = 0x0, + .__dummy0 = 0x00, + .__dummy1 = 0x00, + .__dummy2 = 0x00, + .__dummy3 = 0x0000, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_PROP_TX_ADV: Proprietary Mode Advanced Transmit Command */ +rfc_CMD_PROP_TX_ADV_t rf_cmd_prop_tx_adv = +{ + .commandNo = CMD_PROP_TX_ADV, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .pktConf.bFsOff = 0x0, + .pktConf.bUseCrc = 0x1, + .pktConf.bCrcIncSw = 0x0, + .pktConf.bCrcIncHdr = 0x0, + .numHdrBits = 0x10, + .pktLen = 0x0, /* set by driver */ + .startConf.bExtTxTrig = 0x0, + .startConf.inputMode = 0x0, + .startConf.source = 0x0, + .preTrigger.triggerType = TRIG_REL_START, + .preTrigger.bEnaCmd = 0x0, + .preTrigger.triggerNo = 0x0, + .preTrigger.pastTrig = 0x1, + .preTime = 0x00000000, + .syncWord = 0x0055904E, + .pPkt = 0, /* set by driver */ +}; +/*---------------------------------------------------------------------------*/ +/* CMD_PROP_RX_ADV: Proprietary Mode Advanced Receive Command */ +rfc_CMD_PROP_RX_ADV_t rf_cmd_prop_rx_adv = +{ + .commandNo = CMD_PROP_RX_ADV, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .pktConf.bFsOff = 0x0, + .pktConf.bRepeatOk = 0x1, + .pktConf.bRepeatNok = 0x1, + .pktConf.bUseCrc = 0x1, + .pktConf.bCrcIncSw = 0x0, + .pktConf.bCrcIncHdr = 0x0, + .pktConf.endType = 0x0, + .pktConf.filterOp = 0x1, + .rxConf.bAutoFlushIgnored = 0x1, + .rxConf.bAutoFlushCrcErr = 0x1, + .rxConf.bIncludeHdr = 0x0, + .rxConf.bIncludeCrc = 0x0, + .rxConf.bAppendRssi = 0x1, + .rxConf.bAppendTimestamp = 0x0, + .rxConf.bAppendStatus = 0x1, + .syncWord0 = 0x0055904E, + .syncWord1 = 0x00000000, + .maxPktLen = 0x0, /* set by driver */ + .hdrConf.numHdrBits = 0x10, + .hdrConf.lenPos = 0x0, + .hdrConf.numLenBits = 0x0B, + .addrConf.addrType = 0x0, + .addrConf.addrSize = 0x0, + .addrConf.addrPos = 0x0, + .addrConf.numAddr = 0x0, + .lenOffset = 0xFC, + .endTrigger.triggerType = TRIG_NEVER, + .endTrigger.bEnaCmd = 0x0, + .endTrigger.triggerNo = 0x0, + .endTrigger.pastTrig = 0x0, + .endTime = 0x00000000, + .pAddr = 0, /* set by driver */ + .pQueue = 0, /* set by driver */ + .pOutput = 0, /* set by driver */ +}; +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/prop-settings.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/prop-settings.h new file mode 100644 index 000000000..ab13a754a --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/prop-settings.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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 PROP_SETTINGS_H_ +#define PROP_SETTINGS_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki-conf.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_prop_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_prop_mailbox.h) + +#include +/*---------------------------------------------------------------------------*/ +/* TI-RTOS RF Mode Object */ +extern RF_Mode rf_prop_mode; +/*---------------------------------------------------------------------------*/ +/* RF Core API commands */ +extern rfc_CMD_PROP_RADIO_DIV_SETUP_t rf_cmd_prop_radio_div_setup; +extern rfc_CMD_FS_t rf_cmd_prop_fs; +extern rfc_CMD_PROP_TX_ADV_t rf_cmd_prop_tx_adv; +extern rfc_CMD_PROP_RX_ADV_t rf_cmd_prop_rx_adv; +/*---------------------------------------------------------------------------*/ +/* RF Core API Overrides */ +extern uint32_t rf_prop_overrides[]; +/*---------------------------------------------------------------------------*/ +#endif /* PROP_SETTINGS_H_ */ +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/prop-tx-power.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/prop-tx-power.c new file mode 100644 index 000000000..8052ac4fb --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc13x2/prop-tx-power.c @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-rf-tx-power + * @{ + * + * \file + * Source file for TX power tables for CC13x2. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +/*---------------------------------------------------------------------------*/ +#include "rf/tx-power.h" +/*---------------------------------------------------------------------------*/ +/* + * TX Power table for CC1312R + * The RF_TxPowerTable_DEFAULT_PA_ENTRY macro is defined in RF.h and requires the following arguments: + * RF_TxPowerTable_DEFAULT_PA_ENTRY(bias, gain, boost coefficient) + * See the Technical Reference Manual for further details about the "txPower" Command field. + * The PA settings require the CCFG_FORCE_VDDR_HH = 0 unless stated otherwise. + */ +tx_power_table_t rf_prop_tx_power_table_cc1312r[] = +{ + { -20, RF_TxPowerTable_DEFAULT_PA_ENTRY(0, 3, 0, 2) }, + { -15, RF_TxPowerTable_DEFAULT_PA_ENTRY(1, 3, 0, 2) }, + { -10, RF_TxPowerTable_DEFAULT_PA_ENTRY(2, 3, 0, 4) }, + { -5, RF_TxPowerTable_DEFAULT_PA_ENTRY(4, 3, 0, 5) }, + { 0, RF_TxPowerTable_DEFAULT_PA_ENTRY(8, 3, 0, 7) }, + { 1, RF_TxPowerTable_DEFAULT_PA_ENTRY(9, 3, 0, 7) }, + { 2, RF_TxPowerTable_DEFAULT_PA_ENTRY(10, 3, 0, 9) }, + { 3, RF_TxPowerTable_DEFAULT_PA_ENTRY(11, 3, 0, 9) }, + { 4, RF_TxPowerTable_DEFAULT_PA_ENTRY(12, 3, 0, 11) }, + { 5, RF_TxPowerTable_DEFAULT_PA_ENTRY(14, 3, 0, 12) }, + { 6, RF_TxPowerTable_DEFAULT_PA_ENTRY(16, 3, 0, 14) }, + { 7, RF_TxPowerTable_DEFAULT_PA_ENTRY(8, 2, 0, 16) }, + { 8, RF_TxPowerTable_DEFAULT_PA_ENTRY(22, 3, 0, 32) }, + { 9, RF_TxPowerTable_DEFAULT_PA_ENTRY(26, 3, 0, 28) }, + { 10, RF_TxPowerTable_DEFAULT_PA_ENTRY(33, 3, 0, 55) }, + { 11, RF_TxPowerTable_DEFAULT_PA_ENTRY(23, 2, 0, 42) }, + { 12, RF_TxPowerTable_DEFAULT_PA_ENTRY(10, 0, 0, 58) }, + /* The original PA value (12.5 dBm) have been rounded to an integer value. */ + { 13, RF_TxPowerTable_DEFAULT_PA_ENTRY(20, 0, 0, 102) }, +#if RF_TXPOWER_BOOST_MODE + /* This setting requires RF_TXPOWER_BOOST_MODE = 1. */ + { 14, RF_TxPowerTable_DEFAULT_PA_ENTRY(63, 0, 1, 79) }, +#endif + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +/* + * TX Power table for CC1352R + * The RF_TxPowerTable_DEFAULT_PA_ENTRY macro is defined in RF.h and requires the following arguments: + * RF_TxPowerTable_DEFAULT_PA_ENTRY(bias, gain, boost coefficient) + * See the Technical Reference Manual for further details about the "txPower" Command field. + * The PA settings require the CCFG_FORCE_VDDR_HH = 0 unless stated otherwise. + */ +tx_power_table_t rf_prop_tx_power_table_cc1352r[] = +{ + { -20, RF_TxPowerTable_DEFAULT_PA_ENTRY(0, 3, 0, 2) }, + { -15, RF_TxPowerTable_DEFAULT_PA_ENTRY(1, 3, 0, 2) }, + { -10, RF_TxPowerTable_DEFAULT_PA_ENTRY(2, 3, 0, 4) }, + { -5, RF_TxPowerTable_DEFAULT_PA_ENTRY(4, 3, 0, 5) }, + { 0, RF_TxPowerTable_DEFAULT_PA_ENTRY(8, 3, 0, 7) }, + { 1, RF_TxPowerTable_DEFAULT_PA_ENTRY(9, 3, 0, 7) }, + { 2, RF_TxPowerTable_DEFAULT_PA_ENTRY(10, 3, 0, 9) }, + { 3, RF_TxPowerTable_DEFAULT_PA_ENTRY(11, 3, 0, 9) }, + { 4, RF_TxPowerTable_DEFAULT_PA_ENTRY(12, 3, 0, 11) }, + { 5, RF_TxPowerTable_DEFAULT_PA_ENTRY(14, 3, 0, 12) }, + { 6, RF_TxPowerTable_DEFAULT_PA_ENTRY(16, 3, 0, 14) }, + { 7, RF_TxPowerTable_DEFAULT_PA_ENTRY(8, 2, 0, 16) }, + { 8, RF_TxPowerTable_DEFAULT_PA_ENTRY(22, 3, 0, 32) }, + { 9, RF_TxPowerTable_DEFAULT_PA_ENTRY(26, 3, 0, 28) }, + { 10, RF_TxPowerTable_DEFAULT_PA_ENTRY(33, 3, 0, 55) }, + { 11, RF_TxPowerTable_DEFAULT_PA_ENTRY(23, 2, 0, 42) }, + { 12, RF_TxPowerTable_DEFAULT_PA_ENTRY(10, 0, 0, 58) }, + /* The original PA value (12.5 dBm) have been rounded to an integer value. */ + { 13, RF_TxPowerTable_DEFAULT_PA_ENTRY(20, 0, 0, 102) }, +#if RF_TXPOWER_BOOST_MODE + /* This setting requires RF_TXPOWER_BOOST_MODE = 1. */ + { 14, RF_TxPowerTable_DEFAULT_PA_ENTRY(63, 0, 1, 79) }, +#endif + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +/* + * TX Power table for CC1352P with default PA + * The RF_TxPowerTable_DEFAULT_PA_ENTRY macro is defined in RF.h and requires the following arguments: + * RF_TxPowerTable_DEFAULT_PA_ENTRY(bias, gain, boost coefficient) + * See the Technical Reference Manual for further details about the "txPower" Command field. + * The PA settings require the CCFG_FORCE_VDDR_HH = 0 unless stated otherwise. + */ +tx_power_table_t rf_prop_tx_power_table_cc1352p_dpa[] = +{ + { -20, RF_TxPowerTable_DEFAULT_PA_ENTRY( 0, 3, 0, 2) }, + { -15, RF_TxPowerTable_DEFAULT_PA_ENTRY( 1, 3, 0, 3) }, + { -10, RF_TxPowerTable_DEFAULT_PA_ENTRY( 2, 3, 0, 3) }, + { -5, RF_TxPowerTable_DEFAULT_PA_ENTRY( 4, 3, 0, 6) }, + { 0, RF_TxPowerTable_DEFAULT_PA_ENTRY( 7, 3, 0, 8) }, + { 1, RF_TxPowerTable_DEFAULT_PA_ENTRY( 8, 3, 0, 9) }, + { 2, RF_TxPowerTable_DEFAULT_PA_ENTRY( 9, 3, 0, 9) }, + { 3, RF_TxPowerTable_DEFAULT_PA_ENTRY(11, 3, 0, 11) }, + { 4, RF_TxPowerTable_DEFAULT_PA_ENTRY(12, 3, 0, 12) }, + { 5, RF_TxPowerTable_DEFAULT_PA_ENTRY(14, 3, 0, 14) }, + { 6, RF_TxPowerTable_DEFAULT_PA_ENTRY( 6, 2, 0, 14) }, + { 7, RF_TxPowerTable_DEFAULT_PA_ENTRY( 4, 1, 0, 16) }, + { 8, RF_TxPowerTable_DEFAULT_PA_ENTRY( 6, 1, 0, 19) }, + { 9, RF_TxPowerTable_DEFAULT_PA_ENTRY( 8, 1, 0, 25) }, + { 10, RF_TxPowerTable_DEFAULT_PA_ENTRY(13, 1, 0, 40) }, + { 11, RF_TxPowerTable_DEFAULT_PA_ENTRY(10, 0, 0, 71) }, + { 12, RF_TxPowerTable_DEFAULT_PA_ENTRY(63, 0, 0, 64) }, +#if RF_TXPOWER_BOOST_MODE + /* + * This setting requires RF_TXPOWER_BOOST_MODE = 1. + * The original PA value (13.5 dBm) have been rounded to an integer value. + */ + { 14, RF_TxPowerTable_DEFAULT_PA_ENTRY(63, 0, 1, 0) }, +#endif + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +/* + * TX Power table for CC1352P with high PA + * The RF_TxPowerTable_HIGH_PA_ENTRY macro is defined in RF.h and requires the following arguments: + * RF_TxPowerTable_HIGH_PA_ENTRY(bias, ibboost, boost, coefficient, ldoTrim) + * See the Technical Reference Manual for further details about the "txPower" Command field. + * The PA settings require the CCFG_FORCE_VDDR_HH = 0 unless stated otherwise. + */ +tx_power_table_t rf_prop_tx_power_table_cc1352p_hpa[] = +{ + { 14, RF_TxPowerTable_HIGH_PA_ENTRY( 7, 0, 0, 23, 4) }, + { 15, RF_TxPowerTable_HIGH_PA_ENTRY(10, 0, 0, 26, 4) }, + { 16, RF_TxPowerTable_HIGH_PA_ENTRY(14, 0, 0, 33, 4) }, + { 17, RF_TxPowerTable_HIGH_PA_ENTRY(18, 0, 0, 40, 6) }, + { 18, RF_TxPowerTable_HIGH_PA_ENTRY(24, 0, 0, 51, 8) }, + { 19, RF_TxPowerTable_HIGH_PA_ENTRY(32, 0, 0, 73, 12) }, + { 20, RF_TxPowerTable_HIGH_PA_ENTRY(27, 0, 0, 85, 32) }, + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +tx_power_table_t rf_prop_tx_power_table_empty[] = +{ + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +/* Only define the symbols if Prop-mode is selected */ +#if (RF_MODE == RF_MODE_SUB_1_GHZ) +/*---------------------------------------------------------------------------*/ +/* TX power table, based on which board is used. */ +#if defined(DEVICE_CC1312R) +#define TX_POWER_TABLE rf_prop_tx_power_table_cc1312r + +#elif defined(DEVICE_CC1352R) +#define TX_POWER_TABLE rf_prop_tx_power_table_cc1352r + +#elif defined(DEVICE_CC1352P) +#if RF_TXPOWER_HIGH_PA +#define TX_POWER_TABLE rf_prop_tx_power_table_cc1352p_hpa +#else +#define TX_POWER_TABLE rf_prop_tx_power_table_cc1352p_dpa +#endif + +#else +#define TX_POWER_TABLE rf_prop_tx_power_table_empty +#endif + +/* + * Define symbols for both the TX power table and its size. The TX power + * table size is with one less entry by excluding the termination entry. + */ +tx_power_table_t *const rf_tx_power_table = TX_POWER_TABLE; +const size_t rf_tx_power_table_size = (sizeof(TX_POWER_TABLE) / sizeof(TX_POWER_TABLE[0])) - 1; +/*---------------------------------------------------------------------------*/ +#endif /* RF_MODE */ +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ble-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ble-settings.c new file mode 100644 index 000000000..7edc3e487 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ble-settings.c @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/*---------------------------------------------------------------------------*/ +/* + * Parameter summary + * Adv. Address: 010203040506 + * Adv. Data: 255 + * BLE Channel: 17 + * Frequency: 2440 MHz + * PDU Payload length:: 30 + * TX Power: 5 dBm + * Whitening: true + */ +/*---------------------------------------------------------------------------*/ +#include "sys/cc.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_ble_cmd.h) +#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_ble.h) +#include DeviceFamily_constructPath(rf_patches/rf_patch_rfe_ble.h) + +#include +/*---------------------------------------------------------------------------*/ +#include "ble-settings.h" +/*---------------------------------------------------------------------------*/ +/* TI-RTOS RF Mode Object */ +RF_Mode rf_ble_mode = +{ + .rfMode = RF_MODE_BLE, + .cpePatchFxn = &rf_patch_cpe_ble, + .mcePatchFxn = 0, + .rfePatchFxn = &rf_patch_rfe_ble, +}; +/*---------------------------------------------------------------------------*/ +/* Overrides for CMD_RADIO_SETUP */ +uint32_t rf_ble_overrides[] CC_ALIGN(4) = +{ + /* override_use_patch_ble_1mbps.xml */ + MCE_RFE_OVERRIDE(0,0,0,1,0,0), /* PHY: Use MCE ROM, RFE RAM patch */ + /* override_synth_ble_1mbps.xml */ + HW_REG_OVERRIDE(0x4038,0x0035), /* Synth: Set recommended RTRIM to 5 */ + (uint32_t)0x000784A3, /* Synth: Set Fref to 3.43 MHz */ + (uint32_t)0xA47E0583, /* Synth: Set loop bandwidth after lock to 80 kHz */ + (uint32_t)0xEAE00603, /* Synth: Set loop bandwidth after lock to 80 kHz */ + (uint32_t)0x00010623, /* Synth: Set loop bandwidth after lock to 80 kHz */ + HW32_ARRAY_OVERRIDE(0x405C,1), /* Synth: Configure PLL bias */ + (uint32_t)0x1801F800, /* Synth: Configure PLL bias */ + HW32_ARRAY_OVERRIDE(0x402C,1), /* Synth: Configure PLL latency */ + (uint32_t)0x00608402, /* Synth: Configure PLL latency */ + (uint32_t)0x02010403, /* Synth: Use 24 MHz XOSC as synth clock, enable extra PLL filtering */ + HW32_ARRAY_OVERRIDE(0x4034,1), /* Synth: Configure extra PLL filtering */ + (uint32_t)0x177F0408, /* Synth: Configure extra PLL filtering */ + (uint32_t)0x38000463, /* Synth: Configure extra PLL filtering */ + /* override_phy_ble_1mbps.xml */ + (uint32_t)0x013800C3, /* Tx: Configure symbol shape for BLE frequency deviation requirements */ + HW_REG_OVERRIDE(0x6088, 0x0045), /* Rx: Configure AGC reference level */ + /* Tx: Configure pilot tone length to ensure stable frequency */ + HW_REG_OVERRIDE(0x52AC, 0x0360), /* before start of packet */ + (uint32_t)0x01AD02A3, /* Tx: Compensate timing offset to match new pilot tone setting */ + (uint32_t)0x01680263, /* Tx: Compensate timing offset to match new pilot tone setting */ + (uint32_t)0xFFFFFFFF, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_RADIO_SETUP: Radio Setup Command for Pre-Defined Schemes */ +rfc_CMD_RADIO_SETUP_t rf_ble_cmd_radio_setup = +{ + .commandNo = CMD_RADIO_SETUP, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .mode = 0x00, + .__dummy0 = 0x00, + .config.frontEndMode = 0x0, + .config.biasMode = 0x0, + .config.analogCfgMode = 0x0, + .config.bNoFsPowerUp = 0x0, + .txPower = 0x9330, + .pRegOverride = rf_ble_overrides, +}; +/*---------------------------------------------------------------------------*/ +/* Structure for CMD_BLE_ADV_NC.pParams */ +rfc_bleAdvPar_t rf_ble_adv_par = +{ + .pRxQ = 0, + .rxConfig.bAutoFlushIgnored = 0x0, + .rxConfig.bAutoFlushCrcErr = 0x0, + .rxConfig.bAutoFlushEmpty = 0x0, + .rxConfig.bIncludeLenByte = 0x0, + .rxConfig.bIncludeCrc = 0x0, + .rxConfig.bAppendRssi = 0x0, + .rxConfig.bAppendStatus = 0x0, + .rxConfig.bAppendTimestamp = 0x0, + .advConfig.advFilterPolicy = 0x0, + .advConfig.deviceAddrType = 0x0, + .advConfig.peerAddrType = 0x0, + .advConfig.bStrictLenFilter = 0x0, + .advConfig.rpaMode = 0x0, + .advLen = 0x18, + .scanRspLen = 0x00, + .pAdvData = 0, + .pScanRspData = 0, + .pDeviceAddress = 0, + .pWhiteList = 0, + .__dummy0 = 0x0000, + .__dummy1 = 0x00, + .endTrigger.triggerType = TRIG_NEVER, + .endTrigger.bEnaCmd = 0x0, + .endTrigger.triggerNo = 0x0, + .endTrigger.pastTrig = 0x0, + .endTime = 0x00000000, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_BLE_ADV_NC: BLE Non-Connectable Advertiser Command */ +rfc_CMD_BLE_ADV_NC_t rf_ble_cmd_ble_adv_nc = +{ + .commandNo = CMD_BLE_ADV_NC, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .channel = 0x8C, + .whitening.init = 0x51, + .whitening.bOverride = 0x1, + .pParams = &rf_ble_adv_par, + .pOutput = 0, +}; +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ble-settings.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ble-settings.h new file mode 100644 index 000000000..c89304105 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ble-settings.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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 BLE_SETTINGS_H_ +#define BLE_SETTINGS_H_ +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_ble_cmd.h) + +#include +/*---------------------------------------------------------------------------*/ +/* TI-RTOS RF Mode Object */ +extern RF_Mode rf_ble_mode; +/*---------------------------------------------------------------------------*/ +/* RF Core API commands */ +extern rfc_CMD_RADIO_SETUP_t rf_ble_cmd_radio_setup; +extern rfc_bleAdvPar_t rf_ble_adv_par; +extern rfc_CMD_BLE_ADV_NC_t rf_ble_cmd_ble_adv_nc; +/*---------------------------------------------------------------------------*/ +/* RF Core API Overrides */ +extern uint32_t rf_ble_overrides[]; +/*---------------------------------------------------------------------------*/ +#endif /* BLE_SETTINGS_H_ */ +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ble-tx-power.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ble-tx-power.c new file mode 100644 index 000000000..7510df27a --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ble-tx-power.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-rf-tx-power + * @{ + * + * \file + * Source file for BLE Beacon TX power tables for CC26x0. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +/*---------------------------------------------------------------------------*/ +#include "rf/tx-power.h" +/*---------------------------------------------------------------------------*/ +/* + * TX Power table for CC2650 + * The RF_TxPowerTable_DEFAULT_PA_ENTRY macro is defined in RF.h and requires the following arguments: + * RF_TxPowerTable_DEFAULT_PA_ENTRY(bias, gain, boost coefficient) + * See the Technical Reference Manual for further details about the "txPower" Command field. + * The PA settings require the CCFG_FORCE_VDDR_HH = 0 unless stated otherwise. + */ +tx_power_table_t rf_ble_tx_power_table_cc2650[] = +{ + { -21, RF_TxPowerTable_DEFAULT_PA_ENTRY( 7, 3, 0, 6) }, + { -18, RF_TxPowerTable_DEFAULT_PA_ENTRY( 9, 3, 0, 6) }, + { -15, RF_TxPowerTable_DEFAULT_PA_ENTRY(11, 3, 0, 6) }, + { -12, RF_TxPowerTable_DEFAULT_PA_ENTRY(11, 1, 0, 10) }, + { -9, RF_TxPowerTable_DEFAULT_PA_ENTRY(14, 1, 1, 12) }, + { -6, RF_TxPowerTable_DEFAULT_PA_ENTRY(18, 1, 1, 14) }, + { -3, RF_TxPowerTable_DEFAULT_PA_ENTRY(24, 1, 1, 18) }, + { 0, RF_TxPowerTable_DEFAULT_PA_ENTRY(33, 1, 1, 24) }, + { 1, RF_TxPowerTable_DEFAULT_PA_ENTRY(20, 0, 0, 33) }, + { 2, RF_TxPowerTable_DEFAULT_PA_ENTRY(24, 0, 0, 39) }, + { 3, RF_TxPowerTable_DEFAULT_PA_ENTRY(28, 0, 0, 45) }, + { 4, RF_TxPowerTable_DEFAULT_PA_ENTRY(36, 0, 1, 73) }, + { 5, RF_TxPowerTable_DEFAULT_PA_ENTRY(48, 0, 1, 73) }, + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +tx_power_table_t rf_ble_tx_power_table_empty[] = +{ + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +/* TX power table, based on which board is used. */ +#if defined(DEVICE_CC2650) +#define TX_POWER_TABLE rf_ble_tx_power_table_cc2650 + +#else +#define TX_POWER_TABLE rf_ble_tx_power_table_empty +#endif + +/* + * Define symbols for both the TX power table and its size. The TX power + * table size is with one less entry by excluding the termination entry. + */ +tx_power_table_t *const ble_tx_power_table = TX_POWER_TABLE; +const size_t ble_tx_power_table_size = (sizeof(TX_POWER_TABLE) / sizeof(TX_POWER_TABLE[0])) - 1; +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ieee-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ieee-settings.c new file mode 100644 index 000000000..e93561962 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ieee-settings.c @@ -0,0 +1,249 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/*---------------------------------------------------------------------------*/ +/* + * Parameter summary + * IEEE Channel: 11 + * Frequency: 2405 MHz + * SFD: 0 + * Packet Data: 255 + * Preamble (32 bit): 01010101... + * TX Power: 5 dBm + */ +/*---------------------------------------------------------------------------*/ +#include "sys/cc.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_ieee_cmd.h) +#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_ieee.h) + +#include +/*---------------------------------------------------------------------------*/ +#include "ieee-settings.h" +/*---------------------------------------------------------------------------*/ +/* TI-RTOS RF Mode Object */ +RF_Mode rf_ieee_mode = +{ + .rfMode = RF_MODE_IEEE_15_4, + .cpePatchFxn = &rf_patch_cpe_ieee, + .mcePatchFxn = 0, + .rfePatchFxn = 0, +}; +/*---------------------------------------------------------------------------*/ +/* + * CMD_RADIO_SETUP must be configured with default TX power value + * in the .txPower field. + */ +#define DEFAULT_TX_POWER 0x9330 /* 5 dBm */ +/*---------------------------------------------------------------------------*/ +/* Overrides for CMD_RADIO_SETUP */ +uint32_t rf_ieee_overrides[] CC_ALIGN(4) = +{ + /* override_synth_ieee_15_4.xml */ + HW_REG_OVERRIDE(0x4038,0x0035), /* Synth: Set recommended RTRIM to 5 */ + (uint32_t)0x000784A3, /* Synth: Set Fref to 3.43 MHz */ + (uint32_t)0xA47E0583, /* Synth: Set loop bandwidth after lock to 80 kHz */ + (uint32_t)0xEAE00603, /* Synth: Set loop bandwidth after lock to 80 kHz */ + (uint32_t)0x00010623, /* Synth: Set loop bandwidth after lock to 80 kHz */ + HW32_ARRAY_OVERRIDE(0x405C,1), /* Synth: Configure PLL bias */ + (uint32_t)0x1801F800, /* Synth: Configure PLL bias */ + HW32_ARRAY_OVERRIDE(0x402C,1), /* Synth: Configure PLL latency */ + (uint32_t)0x00608402, /* Synth: Configure PLL latency */ + (uint32_t)0x02010403, /* Synth: Use 24 MHz XOSC as synth clock, enable extra PLL filtering */ + HW32_ARRAY_OVERRIDE(0x4034,1), /* Synth: Configure extra PLL filtering */ + (uint32_t)0x177F0408, /* Synth: Configure extra PLL filtering */ + (uint32_t)0x38000463, /* Synth: Configure extra PLL filtering */ + /* override_phy_ieee_15_4.xml */ + (uint32_t)0x05000243, /* Synth: Increase synth programming timeout */ + (uint32_t)0x002082C3, /* Rx: Adjust Rx FIFO threshold to avoid overflow */ + /* override_frontend_id.xml */ + (uint32_t)0x000288A3, /* Rx: Set RSSI offset to adjust reported RSSI by -2 dB */ + (uint32_t)0x000F8883, /* Rx: Configure LNA bias current trim offset */ + HW_REG_OVERRIDE(0x50DC,0x002B), /* Rx: Adjust AGC DC filter */ + (uint32_t)0xFFFFFFFF, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_RADIO_SETUP: Radio Setup Command for Pre-Defined Schemes */ +rfc_CMD_RADIO_SETUP_t rf_cmd_ieee_radio_setup = +{ + .commandNo = CMD_RADIO_SETUP, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .mode = 0x01, + .__dummy0 = 0x00, + .config.frontEndMode = 0x0, + .config.biasMode = 0x0, + .config.analogCfgMode = 0x0, + .config.bNoFsPowerUp = 0x0, + .txPower = DEFAULT_TX_POWER, /* 5 dBm default */ + .pRegOverride = rf_ieee_overrides, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_FS: Frequency Synthesizer Programming Command */ +rfc_CMD_FS_t rf_cmd_ieee_fs = +{ + .commandNo = CMD_FS, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .frequency = 0x0965, /* set by driver */ + .fractFreq = 0x0000, /* set by driver */ + .synthConf.bTxMode = 0x1, + .synthConf.refFreq = 0x0, + .__dummy0 = 0x00, + .__dummy1 = 0x00, + .__dummy2 = 0x00, + .__dummy3 = 0x0000, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_IEEE_TX: IEEE 802.15.4 Transmit Command */ +rfc_CMD_IEEE_TX_t rf_cmd_ieee_tx = +{ + .commandNo = CMD_IEEE_TX, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .txOpt.bIncludePhyHdr = 0x0, + .txOpt.bIncludeCrc = 0x0, + .txOpt.payloadLenMsb = 0x0, + .payloadLen = 0x0, /* set by driver */ + .pPayload = 0, /* set by driver */ + .timeStamp = 0x00000000, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_IEEE_RX: IEEE 802.15.4 Receive Command */ +rfc_CMD_IEEE_RX_t rf_cmd_ieee_rx = +{ + .commandNo = CMD_IEEE_RX, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .channel = 0x00, /* set by driver */ + .rxConfig.bAutoFlushCrc = 0x1, + .rxConfig.bAutoFlushIgn = 0x1, + .rxConfig.bIncludePhyHdr = 0x0, + .rxConfig.bIncludeCrc = 0x1, + .rxConfig.bAppendRssi = 0x1, + .rxConfig.bAppendCorrCrc = 0x1, + .rxConfig.bAppendSrcInd = 0x0, + .rxConfig.bAppendTimestamp = 0x1, + .pRxQ = 0, /* set by driver */ + .pOutput = 0, /* set by driver */ + .frameFiltOpt.frameFiltEn = 0x0, /* set by driver */ + .frameFiltOpt.frameFiltStop = 0x1, + .frameFiltOpt.autoAckEn = 0x0, /* set by driver */ + .frameFiltOpt.slottedAckEn = 0x0, + .frameFiltOpt.autoPendEn = 0x0, + .frameFiltOpt.defaultPend = 0x0, + .frameFiltOpt.bPendDataReqOnly = 0x0, + .frameFiltOpt.bPanCoord = 0x0, + .frameFiltOpt.maxFrameVersion = 0x2, + .frameFiltOpt.fcfReservedMask = 0x0, + .frameFiltOpt.modifyFtFilter = 0x0, + .frameFiltOpt.bStrictLenFilter = 0x0, + .frameTypes.bAcceptFt0Beacon = 0x1, + .frameTypes.bAcceptFt1Data = 0x1, + .frameTypes.bAcceptFt2Ack = 0x1, + .frameTypes.bAcceptFt3MacCmd = 0x1, + .frameTypes.bAcceptFt4Reserved = 0x1, + .frameTypes.bAcceptFt5Reserved = 0x1, + .frameTypes.bAcceptFt6Reserved = 0x1, + .frameTypes.bAcceptFt7Reserved = 0x1, + .ccaOpt.ccaEnEnergy = 0x1, + .ccaOpt.ccaEnCorr = 0x1, + .ccaOpt.ccaEnSync = 0x1, + .ccaOpt.ccaCorrOp = 0x1, + .ccaOpt.ccaSyncOp = 0x0, + .ccaOpt.ccaCorrThr = 0x3, + .ccaRssiThr = 0x0, /* set by driver */ + .__dummy0 = 0x00, + .numExtEntries = 0x00, + .numShortEntries = 0x00, + .pExtEntryList = 0, + .pShortEntryList = 0, + .localExtAddr = 0x0, /* set by driver */ + .localShortAddr = 0x0, /* set by driver */ + .localPanID = 0x0000, + .__dummy1 = 0x000000, + .endTrigger.triggerType = TRIG_NEVER, + .endTrigger.bEnaCmd = 0x0, + .endTrigger.triggerNo = 0x0, + .endTrigger.pastTrig = 0x0, + .endTime = 0x00000000, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_IEEE_RX_ACK: IEEE 802.15.4 Receive ACK Command */ +rfc_CMD_IEEE_RX_ACK_t rf_cmd_ieee_rx_ack = +{ + .commandNo = CMD_IEEE_RX_ACK, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .seqNo = 0x0, + .endTrigger.triggerType = TRIG_NEVER, + .endTrigger.bEnaCmd = 0x0, + .endTrigger.triggerNo = 0x0, + .endTrigger.pastTrig = 0x0, + .endTime = 0x00000000, +}; +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ieee-settings.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ieee-settings.h new file mode 100644 index 000000000..7019598c8 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ieee-settings.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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 IEEE_SETTINGS_H_ +#define IEEE_SETTINGS_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki-conf.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_ieee_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_ieee_mailbox.h) + +#include +/*---------------------------------------------------------------------------*/ +/* TI-RTOS RF Mode Object */ +extern RF_Mode rf_ieee_mode; +/*---------------------------------------------------------------------------*/ +/* RF Core API commands */ +extern rfc_CMD_RADIO_SETUP_t rf_cmd_ieee_radio_setup; +extern rfc_CMD_FS_t rf_cmd_ieee_fs; +extern rfc_CMD_IEEE_TX_t rf_cmd_ieee_tx; +extern rfc_CMD_IEEE_RX_t rf_cmd_ieee_rx; +extern rfc_CMD_IEEE_RX_ACK_t rf_cmd_ieee_rx_ack; +/*---------------------------------------------------------------------------*/ +/* RF Core API Overrides */ +extern uint32_t rf_ieee_overrides[]; +/*---------------------------------------------------------------------------*/ +#endif /* IEEE_SETTINGS_H_ */ +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ieee-tx-power.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ieee-tx-power.c new file mode 100644 index 000000000..a3a34a860 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x0/ieee-tx-power.c @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-rf-tx-power + * @{ + * + * \file + * Source file for IEEE-mode TX power tables for CC26x0. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +/*---------------------------------------------------------------------------*/ +#include "rf/tx-power.h" +/*---------------------------------------------------------------------------*/ +/* + * TX Power table for CC2650 + * The RF_TxPowerTable_DEFAULT_PA_ENTRY macro is defined in RF.h and requires the following arguments: + * RF_TxPowerTable_DEFAULT_PA_ENTRY(bias, gain, boost coefficient) + * See the Technical Reference Manual for further details about the "txPower" Command field. + * The PA settings require the CCFG_FORCE_VDDR_HH = 0 unless stated otherwise. + */ +tx_power_table_t rf_ieee_tx_power_table_cc2650[] = +{ + { -21, RF_TxPowerTable_DEFAULT_PA_ENTRY( 7, 3, 0, 6) }, + { -18, RF_TxPowerTable_DEFAULT_PA_ENTRY( 9, 3, 0, 6) }, + { -15, RF_TxPowerTable_DEFAULT_PA_ENTRY(11, 3, 0, 6) }, + { -12, RF_TxPowerTable_DEFAULT_PA_ENTRY(11, 1, 0, 10) }, + { -9, RF_TxPowerTable_DEFAULT_PA_ENTRY(14, 1, 1, 12) }, + { -6, RF_TxPowerTable_DEFAULT_PA_ENTRY(18, 1, 1, 14) }, + { -3, RF_TxPowerTable_DEFAULT_PA_ENTRY(24, 1, 1, 18) }, + { 0, RF_TxPowerTable_DEFAULT_PA_ENTRY(33, 1, 1, 24) }, + { 1, RF_TxPowerTable_DEFAULT_PA_ENTRY(20, 0, 0, 33) }, + { 2, RF_TxPowerTable_DEFAULT_PA_ENTRY(24, 0, 0, 39) }, + { 3, RF_TxPowerTable_DEFAULT_PA_ENTRY(28, 0, 0, 45) }, + { 4, RF_TxPowerTable_DEFAULT_PA_ENTRY(36, 0, 1, 73) }, + { 5, RF_TxPowerTable_DEFAULT_PA_ENTRY(48, 0, 1, 73) }, + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +tx_power_table_t rf_ieee_tx_power_table_empty[] = +{ + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +/* Only define the symbols if Prop-mode is selected */ +#if (RF_MODE == RF_MODE_2_4_GHZ) +/*---------------------------------------------------------------------------*/ +/* TX power table, based on which board is used. */ +#if defined(DEVICE_CC2650) +#define TX_POWER_TABLE rf_ieee_tx_power_table_cc2650 + +#else +#define TX_POWER_TABLE rf_ieee_tx_power_table_empty +#endif + +/* + * Define symbols for both the TX power table and its size. The TX power + * table size is with one less entry by excluding the termination entry. + */ +tx_power_table_t *const rf_tx_power_table = TX_POWER_TABLE; +const size_t rf_tx_power_table_size = (sizeof(TX_POWER_TABLE) / sizeof(TX_POWER_TABLE[0])) - 1; +/*---------------------------------------------------------------------------*/ +#endif /* RF_MODE */ +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ble-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ble-settings.c new file mode 100644 index 000000000..8ee2b2684 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ble-settings.c @@ -0,0 +1,207 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/*---------------------------------------------------------------------------*/ +/* + * Parameter summary + * Adv. Address: 010203040506 + * Adv. Data: dummy + * BLE Channel: 17 + * Extended Header: 09 09 010203040506 babe + * Frequency: 2440 MHz + * PDU Payload length:: 30 + * TX Power: 5 dBm + * Whitening: true + */ +/*---------------------------------------------------------------------------*/ +#include "sys/cc.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_ble_cmd.h) +#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_bt5.h) +#include DeviceFamily_constructPath(rf_patches/rf_patch_rfe_bt5.h) +#include DeviceFamily_constructPath(rf_patches/rf_patch_mce_bt5.h) + +#include +/*---------------------------------------------------------------------------*/ +#include "ble-settings.h" +/*---------------------------------------------------------------------------*/ +/* TI-RTOS RF Mode Object */ +RF_Mode rf_ble_mode = +{ + .rfMode = RF_MODE_AUTO, + .cpePatchFxn = &rf_patch_cpe_bt5, + .mcePatchFxn = &rf_patch_mce_bt5, + .rfePatchFxn = &rf_patch_rfe_bt5, +}; +/*---------------------------------------------------------------------------*/ +/* Overrides for CMD_BLE5_RADIO_SETUP */ +uint32_t rf_ble_overrides_common[] CC_ALIGN(4) = +{ + /* override_ble5_setup_override_common.xml */ + (uint32_t)0x02400403, /* Synth: Use 48 MHz crystal, enable extra PLL filtering */ + (uint32_t)0x001C8473, /* Synth: Configure extra PLL filtering */ + (uint32_t)0x00088433, /* Synth: Configure synth hardware */ + (uint32_t)0x00038793, /* Synth: Set minimum RTRIM to 3 */ + HW32_ARRAY_OVERRIDE(0x4004,1), /* Synth: Configure faster calibration */ + (uint32_t)0x1C0C0618, /* Synth: Configure faster calibration */ + (uint32_t)0xC00401A1, /* Synth: Configure faster calibration */ + (uint32_t)0x00010101, /* Synth: Configure faster calibration */ + (uint32_t)0xC0040141, /* Synth: Configure faster calibration */ + (uint32_t)0x00214AD3, /* Synth: Configure faster calibration */ + (uint32_t)0x02980243, /* Synth: Decrease synth programming time-out (0x0298 RAT ticks = 166 us) */ + /* DC/DC regulator: */ + /* In Tx, use DCDCCTL5[3:0]=0xC (DITHER_EN=1 and IPEAK=4). */ + (uint32_t)0xFCFC08C3, /* In Rx, use DCDCCTL5[3:0]=0xC (DITHER_EN=1 and IPEAK=4). */ + (uint32_t)0x00038883, /* Rx: Set LNA bias current offset to adjust +3 (default: 0) */ + (uint32_t)0x000288A3, /* Rx: Set RSSI offset to adjust reported RSSI by -2 dB (default: 0) */ + (uint32_t)0x01080263, /* Bluetooth 5: Compensate for reduced pilot tone length */ + (uint32_t)0x08E90AA3, /* Bluetooth 5: Compensate for reduced pilot tone length */ + (uint32_t)0x00068BA3, /* Bluetooth 5: Compensate for reduced pilot tone length */ + /* Bluetooth 5: Set correct total clock accuracy for received AuxPtr */ + (uint32_t)0x0E490C83, /* assuming local sleep clock of 50 ppm */ + (uint32_t)0xFFFFFFFF, +}; +/*---------------------------------------------------------------------------*/ +/* Overrides for CMD_BLE5_RADIO_SETUP */ +uint32_t rf_ble_overrides_1mbps[] CC_ALIGN(4) = +{ + /* override_ble5_setup_override_1mbps.xml */ + MCE_RFE_OVERRIDE(1,0,0,1,0,0), /* PHY: Use MCE RAM patch (mode 0), RFE RAM patch (mode 0) */ + HW_REG_OVERRIDE(0x5320,0x0240), /* Bluetooth 5: Reduce pilot tone length */ + (uint32_t)0x013302A3, /* Bluetooth 5: Compensate for reduced pilot tone length */ + (uint32_t)0xFFFFFFFF, +}; +/*---------------------------------------------------------------------------*/ +/* Overrides for CMD_BLE5_RADIO_SETUP */ +uint32_t rf_ble_overrides_2mbps[] CC_ALIGN(4) = +{ + /* override_ble5_setup_override_2mbps.xml */ + MCE_RFE_OVERRIDE(1,0,2,1,0,2), /* PHY: Use MCE RAM patch (mode 2), RFE RAM patch (mode 2) */ + HW_REG_OVERRIDE(0x5320,0x0240), /* Bluetooth 5: Reduce pilot tone length */ + (uint32_t)0x00D102A3, /* Bluetooth 5: Compensate for reduced pilot tone length */ + (uint32_t)0xFFFFFFFF, +}; +/*---------------------------------------------------------------------------*/ +/* Overrides for CMD_BLE5_RADIO_SETUP */ +uint32_t rf_ble_overrides_coded[] CC_ALIGN(4) = +{ + /* override_ble5_setup_override_coded.xml */ + MCE_RFE_OVERRIDE(1,0,1,1,0,1), /* PHY: Use MCE RAM patch (mode 1), RFE RAM patch (mode 1) */ + HW_REG_OVERRIDE(0x5320,0x0240), /* Bluetooth 5: Reduce pilot tone length */ + (uint32_t)0x078902A3, /* Bluetooth 5: Compensate for reduced pilot tone length */ + (uint32_t)0xFFFFFFFF, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_BLE5_RADIO_SETUP: Bluetooth 5 Radio Setup Command for all PHYs */ +rfc_CMD_BLE5_RADIO_SETUP_t rf_ble_cmd_radio_setup = +{ + .commandNo = CMD_BLE5_RADIO_SETUP, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .defaultPhy.mainMode = 0x0, + .defaultPhy.coding = 0x0, + .loDivider = 0x00, + .config.frontEndMode = 0x0, + .config.biasMode = 0x0, + .config.analogCfgMode = 0x0, + .config.bNoFsPowerUp = 0x0, + .txPower = 0x941E, + .pRegOverrideCommon = rf_ble_overrides_common, + .pRegOverride1Mbps = rf_ble_overrides_1mbps, + .pRegOverride2Mbps = rf_ble_overrides_2mbps, + .pRegOverrideCoded = rf_ble_overrides_coded, +}; +/*---------------------------------------------------------------------------*/ +/* Structure for CMD_BLE5_ADV_NC.pParams */ +rfc_bleAdvPar_t rf_ble_adv_par = +{ + .pRxQ = 0, + .rxConfig.bAutoFlushIgnored = 0x0, + .rxConfig.bAutoFlushCrcErr = 0x0, + .rxConfig.bAutoFlushEmpty = 0x0, + .rxConfig.bIncludeLenByte = 0x0, + .rxConfig.bIncludeCrc = 0x0, + .rxConfig.bAppendRssi = 0x0, + .rxConfig.bAppendStatus = 0x0, + .rxConfig.bAppendTimestamp = 0x0, + .advConfig.advFilterPolicy = 0x0, + .advConfig.deviceAddrType = 0x0, + .advConfig.peerAddrType = 0x0, + .advConfig.bStrictLenFilter = 0x0, + .advConfig.rpaMode = 0x0, + .advLen = 0x18, + .scanRspLen = 0x00, + .pAdvData = 0, + .pScanRspData = 0, + .pDeviceAddress = 0, + .pWhiteList = 0, + .__dummy0 = 0x0000, + .__dummy1 = 0x00, + .endTrigger.triggerType = TRIG_NEVER, + .endTrigger.bEnaCmd = 0x0, + .endTrigger.triggerNo = 0x0, + .endTrigger.pastTrig = 0x0, + .endTime = 0x00000000, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_BLE5_ADV_NC: Bluetooth 5 Non-Connectable Advertiser Command */ +rfc_CMD_BLE5_ADV_NC_t rf_ble_cmd_ble_adv_nc = +{ + .commandNo = 0x182D, + .status = 0x0000, + .pNextOp = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx + .startTime = 0x00000000, + .startTrigger.triggerType = 0x0, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = 0x1, + .condition.nSkip = 0x0, + .channel = 0x8C, + .whitening.init = 0x51, + .whitening.bOverride = 0x1, + .phyMode.mainMode = 0x0, + .phyMode.coding = 0x0, + .rangeDelay = 0x00, + .txPower = 0x0000, + .pParams = &rf_ble_adv_par, + .pOutput = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx + .tx20Power = 0x00000000, +}; +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ble-settings.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ble-settings.h new file mode 100644 index 000000000..2e6defa71 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ble-settings.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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 BLE_SETTINGS_H_ +#define BLE_SETTINGS_H_ +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_ble_cmd.h) + +#include +/*---------------------------------------------------------------------------*/ +/* TI-RTOS RF Mode Object */ +extern RF_Mode rf_ble_mode; +/*---------------------------------------------------------------------------*/ +/* RF Core API commands */ +extern rfc_CMD_BLE5_RADIO_SETUP_t rf_ble_cmd_radio_setup; +extern rfc_bleAdvPar_t rf_ble_adv_par; +extern rfc_CMD_BLE5_ADV_NC_t rf_ble_cmd_ble_adv_nc; +/*---------------------------------------------------------------------------*/ +/* RF Core API Overrides */ +extern uint32_t rf_ble_overrides_common[]; +extern uint32_t rf_ble_overrides_1mbps[]; +extern uint32_t rf_ble_overrides_2mbps[]; +extern uint32_t rf_ble_overrides_coded[]; +/*---------------------------------------------------------------------------*/ +#endif /* BLE_SETTINGS_H_ */ +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ble-tx-power.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ble-tx-power.c new file mode 100644 index 000000000..368c19637 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ble-tx-power.c @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-rf-tx-power + * @{ + * + * \file + * Source file for BLE Beacon TX power tables for CC26x2. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +/*---------------------------------------------------------------------------*/ +#include "rf/tx-power.h" +/*---------------------------------------------------------------------------*/ +/* + * TX Power table for CC2652R + * The RF_TxPowerTable_DEFAULT_PA_ENTRY macro is defined in RF.h and requires the following arguments: + * RF_TxPowerTable_DEFAULT_PA_ENTRY(bias, gain, boost coefficient) + * See the Technical Reference Manual for further details about the "txPower" Command field. + * The PA settings require the CCFG_FORCE_VDDR_HH = 0 unless stated otherwise. + */ +tx_power_table_t rf_ble_tx_power_table_cc2652r[] = +{ + { -21, RF_TxPowerTable_DEFAULT_PA_ENTRY( 7, 3, 0, 3) }, + { -18, RF_TxPowerTable_DEFAULT_PA_ENTRY( 9, 3, 0, 3) }, + { -15, RF_TxPowerTable_DEFAULT_PA_ENTRY( 8, 2, 0, 6) }, + { -12, RF_TxPowerTable_DEFAULT_PA_ENTRY(10, 2, 0, 8) }, + { -10, RF_TxPowerTable_DEFAULT_PA_ENTRY(12, 2, 0, 11) }, + { -9, RF_TxPowerTable_DEFAULT_PA_ENTRY(13, 2, 0, 5) }, + { -6, RF_TxPowerTable_DEFAULT_PA_ENTRY(13, 1, 0, 16) }, + { -5, RF_TxPowerTable_DEFAULT_PA_ENTRY(14, 1, 0, 17) }, + { -3, RF_TxPowerTable_DEFAULT_PA_ENTRY(17, 1, 0, 20) }, + { 0, RF_TxPowerTable_DEFAULT_PA_ENTRY(25, 1, 0, 26) }, + { 1, RF_TxPowerTable_DEFAULT_PA_ENTRY(28, 1, 0, 28) }, + { 2, RF_TxPowerTable_DEFAULT_PA_ENTRY(13, 0, 0, 34) }, + { 3, RF_TxPowerTable_DEFAULT_PA_ENTRY(17, 0, 0, 42) }, + { 4, RF_TxPowerTable_DEFAULT_PA_ENTRY(22, 0, 0, 54) }, + { 5, RF_TxPowerTable_DEFAULT_PA_ENTRY(30, 0, 0, 74) }, + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +tx_power_table_t rf_ble_tx_power_table_empty[] = +{ + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +/* TX power table, based on which board is used. */ +#if defined(DEVICE_CC2652R) +#define TX_POWER_TABLE rf_ble_tx_power_table_cc2652r + +#else +#define TX_POWER_TABLE rf_ble_tx_power_table_empty +#endif + +/* + * Define symbols for both the TX power table and its size. The TX power + * table size is with one less entry by excluding the termination entry. + */ +tx_power_table_t *const ble_tx_power_table = TX_POWER_TABLE; +const size_t ble_tx_power_table_size = (sizeof(TX_POWER_TABLE) / sizeof(TX_POWER_TABLE[0])) - 1; +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ieee-settings.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ieee-settings.c new file mode 100644 index 000000000..cc012da89 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ieee-settings.c @@ -0,0 +1,246 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/*---------------------------------------------------------------------------*/ +/* + * Parameter summary + * IEEE Channel: 11 + * Frequency: 2405 MHz + * SFD: 0 + * Packet Data: 255 + * Preamble (32 bit): 01010101... + * TX Power: 5 dBm + */ +/*---------------------------------------------------------------------------*/ +#include "sys/cc.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_ieee_cmd.h) +#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_ieee_802_15_4.h) +#include DeviceFamily_constructPath(rf_patches/rf_patch_mce_ieee_802_15_4.h) + +#include +/*---------------------------------------------------------------------------*/ +#include "ieee-settings.h" +/*---------------------------------------------------------------------------*/ +/* TI-RTOS RF Mode Object */ +RF_Mode rf_ieee_mode = +{ + .rfMode = RF_MODE_AUTO, + .cpePatchFxn = &rf_patch_cpe_ieee_802_15_4, + .mcePatchFxn = &rf_patch_mce_ieee_802_15_4, + .rfePatchFxn = 0, +}; +/*---------------------------------------------------------------------------*/ +/* + * CMD_RADIO_SETUP must be configured with default TX power value + * in the .txPower field. + */ +#define DEFAULT_TX_POWER 0x941E /* 5 dBm */ +/*---------------------------------------------------------------------------*/ +/* Overrides for CMD_RADIO_SETUP */ +uint32_t rf_ieee_overrides[] CC_ALIGN(4) = +{ + /* override_ieee_802_15_4.xml */ + MCE_RFE_OVERRIDE(1,0,0,0,1,0), /* PHY: Use MCE RAM patch, RFE ROM bank 1 */ + (uint32_t)0x02400403, /* Synth: Use 48 MHz crystal, enable extra PLL filtering */ + (uint32_t)0x001C8473, /* Synth: Configure extra PLL filtering */ + (uint32_t)0x00088433, /* Synth: Configure synth hardware */ + (uint32_t)0x00038793, /* Synth: Set minimum RTRIM to 3 */ + HW32_ARRAY_OVERRIDE(0x4004,1), /* Synth: Configure faster calibration */ + (uint32_t)0x1C0C0618, /* Synth: Configure faster calibration */ + (uint32_t)0xC00401A1, /* Synth: Configure faster calibration */ + (uint32_t)0x00010101, /* Synth: Configure faster calibration */ + (uint32_t)0xC0040141, /* Synth: Configure faster calibration */ + (uint32_t)0x00214AD3, /* Synth: Configure faster calibration */ + (uint32_t)0x02980243, /* Synth: Decrease synth programming time-out (0x0298 RAT ticks = 166 us) */ + /* DC/DC regulator: */ + /* In Tx, use DCDCCTL5[3:0]=0xC (DITHER_EN=1 and IPEAK=4). */ + (uint32_t)0xFCFC08C3, /* In Rx, use DCDCCTL5[3:0]=0xC (DITHER_EN=1 and IPEAK=4). */ + (uint32_t)0x000F8883, /* Rx: Set LNA bias current offset to +15 to saturate trim to max (default: 0) */ + (uint32_t)0xFFFFFFFF, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_RADIO_SETUP: Radio Setup Command for Pre-Defined Schemes */ +rfc_CMD_RADIO_SETUP_t rf_cmd_ieee_radio_setup = +{ + .commandNo = CMD_RADIO_SETUP, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .mode = 0x01, + .loDivider = 0x00, + .config.frontEndMode = 0x0, + .config.biasMode = 0x0, + .config.analogCfgMode = 0x0, + .config.bNoFsPowerUp = 0x0, + .txPower = DEFAULT_TX_POWER, + .pRegOverride = rf_ieee_overrides, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_FS: Frequency Synthesizer Programming Command */ +rfc_CMD_FS_t rf_cmd_ieee_fs = +{ + .commandNo = CMD_FS, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .frequency = 0x0965, /* set by driver */ + .fractFreq = 0x0000, /* set by driver */ + .synthConf.bTxMode = 0x1, + .synthConf.refFreq = 0x0, + .__dummy0 = 0x00, + .__dummy1 = 0x00, + .__dummy2 = 0x00, + .__dummy3 = 0x0000, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_IEEE_TX: IEEE 802.15.4 Transmit Command */ +rfc_CMD_IEEE_TX_t rf_cmd_ieee_tx = +{ + .commandNo = CMD_IEEE_TX, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .txOpt.bIncludePhyHdr = 0x0, + .txOpt.bIncludeCrc = 0x0, + .txOpt.payloadLenMsb = 0x0, + .payloadLen = 0x0, /* set by driver */ + .pPayload = 0, /* set by driver */ + .timeStamp = 0x00000000, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_IEEE_RX: IEEE 802.15.4 Receive Command */ +rfc_CMD_IEEE_RX_t rf_cmd_ieee_rx = +{ + .commandNo = CMD_IEEE_RX, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .channel = 0x00, /* set by driver */ + .rxConfig.bAutoFlushCrc = 0x1, + .rxConfig.bAutoFlushIgn = 0x1, + .rxConfig.bIncludePhyHdr = 0x0, + .rxConfig.bIncludeCrc = 0x1, + .rxConfig.bAppendRssi = 0x1, + .rxConfig.bAppendCorrCrc = 0x1, + .rxConfig.bAppendSrcInd = 0x0, + .rxConfig.bAppendTimestamp = 0x1, + .pRxQ = 0, /* set by driver */ + .pOutput = 0, /* set by driver */ + .frameFiltOpt.frameFiltEn = 0x0, /* set by driver */ + .frameFiltOpt.frameFiltStop = 0x1, + .frameFiltOpt.autoAckEn = 0x0, /* set by driver */ + .frameFiltOpt.slottedAckEn = 0x0, + .frameFiltOpt.autoPendEn = 0x0, + .frameFiltOpt.defaultPend = 0x0, + .frameFiltOpt.bPendDataReqOnly = 0x0, + .frameFiltOpt.bPanCoord = 0x0, + .frameFiltOpt.maxFrameVersion = 0x2, + .frameFiltOpt.fcfReservedMask = 0x0, + .frameFiltOpt.modifyFtFilter = 0x0, + .frameFiltOpt.bStrictLenFilter = 0x0, + .frameTypes.bAcceptFt0Beacon = 0x1, + .frameTypes.bAcceptFt1Data = 0x1, + .frameTypes.bAcceptFt2Ack = 0x1, + .frameTypes.bAcceptFt3MacCmd = 0x1, + .frameTypes.bAcceptFt4Reserved = 0x1, + .frameTypes.bAcceptFt5Reserved = 0x1, + .frameTypes.bAcceptFt6Reserved = 0x1, + .frameTypes.bAcceptFt7Reserved = 0x1, + .ccaOpt.ccaEnEnergy = 0x1, + .ccaOpt.ccaEnCorr = 0x1, + .ccaOpt.ccaEnSync = 0x1, + .ccaOpt.ccaCorrOp = 0x1, + .ccaOpt.ccaSyncOp = 0x0, + .ccaOpt.ccaCorrThr = 0x3, + .ccaRssiThr = 0x0, /* set by driver */ + .__dummy0 = 0x00, + .numExtEntries = 0x00, + .numShortEntries = 0x00, + .pExtEntryList = 0, + .pShortEntryList = 0, + .localExtAddr = 0x0, /* set by driver */ + .localShortAddr = 0x0, /* set by driver */ + .localPanID = 0x0000, + .__dummy1 = 0x000000, + .endTrigger.triggerType = TRIG_NEVER, + .endTrigger.bEnaCmd = 0x0, + .endTrigger.triggerNo = 0x0, + .endTrigger.pastTrig = 0x0, + .endTime = 0x00000000, +}; +/*---------------------------------------------------------------------------*/ +/* CMD_IEEE_RX_ACK: IEEE 802.15.4 Receive ACK Command */ +rfc_CMD_IEEE_RX_ACK_t rf_cmd_ieee_rx_ack = +{ + .commandNo = CMD_IEEE_RX_ACK, + .status = IDLE, + .pNextOp = 0, + .startTime = 0x00000000, + .startTrigger.triggerType = TRIG_NOW, + .startTrigger.bEnaCmd = 0x0, + .startTrigger.triggerNo = 0x0, + .startTrigger.pastTrig = 0x0, + .condition.rule = COND_NEVER, + .condition.nSkip = 0x0, + .seqNo = 0x0, + .endTrigger.triggerType = TRIG_NEVER, + .endTrigger.bEnaCmd = 0x0, + .endTrigger.triggerNo = 0x0, + .endTrigger.pastTrig = 0x0, + .endTime = 0x00000000, +}; +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ieee-settings.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ieee-settings.h new file mode 100644 index 000000000..141a0e4b3 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ieee-settings.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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 IEEE_SETTINGS_H_ +#define IEEE_SETTINGS_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki-conf.h" + +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_ieee_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_ieee_mailbox.h) + +#include +/*---------------------------------------------------------------------------*/ +/* TI-RTOS RF Mode Object */ +extern RF_Mode rf_ieee_mode; +/*---------------------------------------------------------------------------*/ +/* RF Core API commands */ +extern rfc_CMD_RADIO_SETUP_t rf_cmd_ieee_radio_setup; +extern rfc_CMD_FS_t rf_cmd_ieee_fs; +extern rfc_CMD_IEEE_TX_t rf_cmd_ieee_tx; +extern rfc_CMD_IEEE_RX_t rf_cmd_ieee_rx; +extern rfc_CMD_IEEE_RX_ACK_t rf_cmd_ieee_rx_ack; +/*---------------------------------------------------------------------------*/ +/* RF Core API Overrides */ +extern uint32_t rf_ieee_overrides[]; +/*---------------------------------------------------------------------------*/ +#endif /* IEEE_SETTINGS_H_ */ +/*---------------------------------------------------------------------------*/ + diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ieee-tx-power.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ieee-tx-power.c new file mode 100644 index 000000000..fcf353209 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf-settings/cc26x2/ieee-tx-power.c @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-rf-tx-power + * @{ + * + * \file + * Source file for IEEE-mode TX power tables for CC26x2. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +/*---------------------------------------------------------------------------*/ +#include "rf/tx-power.h" +/*---------------------------------------------------------------------------*/ +/* + * TX Power table for CC2652R + * The RF_TxPowerTable_DEFAULT_PA_ENTRY macro is defined in RF.h and requires the following arguments: + * RF_TxPowerTable_DEFAULT_PA_ENTRY(bias, gain, boost coefficient) + * See the Technical Reference Manual for further details about the "txPower" Command field. + * The PA settings require the CCFG_FORCE_VDDR_HH = 0 unless stated otherwise. + */ +tx_power_table_t rf_ieee_tx_power_table_cc2652r[] = +{ + { -21, RF_TxPowerTable_DEFAULT_PA_ENTRY(7, 3, 0, 3) }, + { -18, RF_TxPowerTable_DEFAULT_PA_ENTRY(9, 3, 0, 3) }, + { -15, RF_TxPowerTable_DEFAULT_PA_ENTRY(12, 2, 0, 100) }, + { -12, RF_TxPowerTable_DEFAULT_PA_ENTRY(40, 2, 0, 8) }, + { -10, RF_TxPowerTable_DEFAULT_PA_ENTRY(12, 2, 0, 11) }, + { -9, RF_TxPowerTable_DEFAULT_PA_ENTRY(13, 2, 0, 5) }, + { -6, RF_TxPowerTable_DEFAULT_PA_ENTRY(13, 1, 0, 16) }, + { -5, RF_TxPowerTable_DEFAULT_PA_ENTRY(14, 1, 0, 17) }, + { -3, RF_TxPowerTable_DEFAULT_PA_ENTRY(17, 1, 0, 20) }, + { 0, RF_TxPowerTable_DEFAULT_PA_ENTRY(25, 1, 0, 26) }, + { 1, RF_TxPowerTable_DEFAULT_PA_ENTRY(28, 1, 0, 28) }, + { 2, RF_TxPowerTable_DEFAULT_PA_ENTRY(13, 0, 0, 34) }, + { 3, RF_TxPowerTable_DEFAULT_PA_ENTRY(17, 0, 0, 42) }, + { 4, RF_TxPowerTable_DEFAULT_PA_ENTRY(22, 0, 0, 54) }, + { 5, RF_TxPowerTable_DEFAULT_PA_ENTRY(30, 0, 0, 74) }, + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +tx_power_table_t rf_ieee_tx_power_table_empty[] = +{ + RF_TxPowerTable_TERMINATION_ENTRY +}; +/*---------------------------------------------------------------------------*/ +/* Only define the symbols if Prop-mode is selected */ +#if (RF_MODE == RF_MODE_2_4_GHZ) +/*---------------------------------------------------------------------------*/ +/* TX power table, based on which board is used. */ +#if defined(DEVICE_CC2652R) +#define TX_POWER_TABLE rf_ieee_tx_power_table_cc2652r + +#else +#define TX_POWER_TABLE rf_ieee_tx_power_table_empty +#endif + +/* + * Define symbols for both the TX power table and its size. The TX power + * table size is with one less entry by excluding the termination entry. + */ +tx_power_table_t *const rf_tx_power_table = TX_POWER_TABLE; +const size_t rf_tx_power_table_size = (sizeof(TX_POWER_TABLE) / sizeof(TX_POWER_TABLE[0])) - 1; +/*---------------------------------------------------------------------------*/ +#endif /* RF_MODE */ +/*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-addr.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-addr.c new file mode 100644 index 000000000..357e7e7c5 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-addr.c @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2016, Michael Spoerk + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-rf-ble-addr + * @{ + * + * \file + * Implementation of the CC13xx/CC26xx IEEE addresses driver. + * \author + * Michael Spoerk + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/ble-hal.h" +#include "net/linkaddr.h" + +#include "rf/ble-addr.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(inc/hw_memmap.h) +#include DeviceFamily_constructPath(inc/hw_fcfg1.h) +#include DeviceFamily_constructPath(inc/hw_ccfg.h) +/*---------------------------------------------------------------------------*/ +#include +/*---------------------------------------------------------------------------*/ +#define BLE_MAC_PRIMARY_ADDRESS (FCFG1_BASE + FCFG1_O_MAC_BLE_0) +#define BLE_MAC_SECONDARY_ADDRESS (CCFG_BASE + CCFG_O_IEEE_BLE_0) +/*---------------------------------------------------------------------------*/ +uint8_t * +ble_addr_ptr(void) +{ + volatile const uint8_t *const primary = (uint8_t *)BLE_MAC_PRIMARY_ADDRESS; + volatile const uint8_t *const secondary = (uint8_t *)BLE_MAC_SECONDARY_ADDRESS; + + /* + * Reading from primary location... + * ...unless we can find a byte != 0xFF in secondary + * + * Intentionally checking all bytes here instead of len, because we + * are checking validity of the entire address irrespective of the + * actual number of bytes the caller wants to copy over. + */ + size_t i; + for(i = 0; i < BLE_ADDR_SIZE; i++) { + if(secondary[i] != 0xFF) { + /* A byte in secondary is not 0xFF. Use secondary address. */ + return (uint8_t *)secondary; + } + } + + /* All bytes in secondary is 0xFF. Use primary address. */ + return (uint8_t *)primary; +} +/*---------------------------------------------------------------------------*/ +int +ble_addr_cpy(uint8_t *dst) +{ + if(!dst) { + return -1; + } + + volatile const uint8_t *const ble_addr = ble_addr_ptr(); + + /* + * We have chosen what address to read the BLE address from. Do so, + * inverting byte order + */ + size_t i; + for(i = 0; i < BLE_ADDR_SIZE; i++) { + dst[i] = ble_addr[BLE_ADDR_SIZE - 1 - i]; + } + + return 0; +} +/*---------------------------------------------------------------------------*/ +int +ble_addr_to_eui64(uint8_t *dst, uint8_t *src) +{ + if(!dst || !src) { + return -1; + } + + memcpy(dst, src, 3); + dst[3] = 0xFF; + dst[4] = 0xFE; + memcpy(&dst[5], &src[3], 3); + + return 0; +} +/*---------------------------------------------------------------------------*/ +int +ble_addr_to_eui64_cpy(uint8_t *dst) +{ + if(!dst) { + return -1; + } + + int res; + uint8_t ble_addr[BLE_ADDR_SIZE]; + + res = ble_addr_cpy(ble_addr); + if(res) { + return -1; + } + + return ble_addr_to_eui64(dst, ble_addr); +} +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-addr.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-addr.h new file mode 100644 index 000000000..fd63c17d0 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-addr.h @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2016, Michael Spoerk + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-rf + * @{ + * + * \defgroup cc13xx-cc26xx-rf-ble-addr Driver for CC13xx/CC26xx BLE addresses + * + * @{ + * + * \file + * Header file for the CC13xx/CC26xx BLE address driver. + * \author + * Michael Spoerk + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#ifndef BLE_ADDR_H_ +#define BLE_ADDR_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" + +#include +/*---------------------------------------------------------------------------*/ +/** + * \brief Retrieve the pointer to where the BLE address is stored. + * + * This function will return the primary address from info page, unless a + * valid address is found in the secondary address from CCFG. + */ +uint8_t *ble_addr_ptr(void); +/*---------------------------------------------------------------------------*/ +/** + * \brief Copy the node's factory BLE address to a destination memory area + * \param dst A pointer to the destination area where the BLE address is to be + * written + * \return 0 : Returned successfully + * -1 : Returned with error + * + * This function will copy 6 bytes and it will invert byte order in + * the process. The factory address on devices is normally little-endian, + * therefore you should expect dst to store the address in a big-endian order. + */ +int ble_addr_cpy(uint8_t *dst); +/*---------------------------------------------------------------------------*/ +/** + * \brief Copy the node's BLE address to a destination memory area and converts + * it into a EUI64 address in the process + * \param dst A pointer to the destination area where the EUI64 address is to be + * written + * \param src A pointer to the BLE address that is to be copied + * \return 0 : Returned successfully + * -1 : Returned with error + */ +int ble_addr_to_eui64(uint8_t *dst, uint8_t *src); +/*---------------------------------------------------------------------------*/ +/** + * \brief Copy the node's EUI64 address that is based on its factory BLE address + * to a destination memory area + * \param dst A pointer to the destination area where the EUI64 address is to be + * written + * \return 0 : Returned successfully + * -1 : Returned with error + */ +int ble_addr_to_eui64_cpy(uint8_t *dst); +/*---------------------------------------------------------------------------*/ +#endif /* BLE_ADDR_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ \ No newline at end of file diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-beacond.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-beacond.c new file mode 100644 index 000000000..383d168be --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-beacond.c @@ -0,0 +1,359 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-rf-ble + * @{ + * + * \file + * Implementation for the CC13xx/CC26xx BLE Beacon Daemon. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "sys/cc.h" +#include "sys/clock.h" +#include "sys/etimer.h" +#include "sys/process.h" +#include "net/linkaddr.h" +#include "net/netstack.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/chipinfo.h) +#include DeviceFamily_constructPath(driverlib/rf_ble_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) + +#include +/*---------------------------------------------------------------------------*/ +#include "rf/sched.h" +#include "rf/ble-addr.h" +#include "rf/ble-beacond.h" +#include "rf/tx-power.h" +#include "rf/settings.h" +/*---------------------------------------------------------------------------*/ +#include +#include +#include +#include +/*---------------------------------------------------------------------------*/ +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "Radio" +#define LOG_LEVEL LOG_LEVEL_NONE +/*---------------------------------------------------------------------------*/ +#if RF_CONF_BLE_BEACON_ENABLE +/*---------------------------------------------------------------------------*/ +/* BLE Advertisement channels. Not to be changed by the user. */ +typedef enum { + BLE_ADV_CHANNEL_37 = (1 << 0), + BLE_ADV_CHANNEL_38 = (1 << 1), + BLE_ADV_CHANNEL_39 = (1 << 2), + + BLE_ADV_CHANNEL_ALL = (BLE_ADV_CHANNEL_37 | + BLE_ADV_CHANNEL_38 | + BLE_ADV_CHANNEL_39), +} ble_adv_channel_t; + +#define BLE_ADV_CHANNEL_MIN 37 +#define BLE_ADV_CHANNEL_MAX 39 +/*---------------------------------------------------------------------------*/ +/* Maximum BLE advertisement size. Not to be changed by the user. */ +#define BLE_ADV_MAX_SIZE 31 +/*---------------------------------------------------------------------------*/ +/* BLE Intervals: Send a burst of advertisements every BLE_ADV_INTERVAL secs */ +#define BLE_ADV_INTERVAL (CLOCK_SECOND * 5) +#define BLE_ADV_DUTY_CYCLE (CLOCK_SECOND / 10) +#define BLE_ADV_MESSAGES 10 + +/* BLE Advertisement-related macros */ +#define BLE_ADV_TYPE_DEVINFO 0x01 +#define BLE_ADV_TYPE_NAME 0x09 +#define BLE_ADV_TYPE_MANUFACTURER 0xFF +#define BLE_ADV_NAME_BUF_LEN BLE_ADV_MAX_SIZE +#define BLE_ADV_PAYLOAD_BUF_LEN 64 +#define BLE_UUID_SIZE 16 +/*---------------------------------------------------------------------------*/ +typedef struct { + /* Outgoing frame buffer */ + uint8_t tx_buf[BLE_ADV_PAYLOAD_BUF_LEN] CC_ALIGN(4); + + /* Config data */ + size_t adv_name_len; + char adv_name[BLE_ADV_NAME_BUF_LEN]; + + /* Indicates whether deamon is active or not */ + bool is_active; + + /* Periodic timer for sending out BLE advertisements */ + clock_time_t ble_adv_interval; + struct etimer ble_adv_et; + + /* RF driver */ + RF_Handle rf_handle; +} ble_beacond_t; + +static ble_beacond_t ble_beacond; +/*---------------------------------------------------------------------------*/ +PROCESS(ble_beacond_process, "RF BLE Beacon Daemon Process"); +/*---------------------------------------------------------------------------*/ +rf_ble_beacond_result_t +rf_ble_beacond_init(void) +{ + ble_adv_par.pDeviceAddress = (uint16_t *)ble_addr_ptr(); + + RF_Params rf_params; + RF_Params_init(&rf_params); + + /* Should immediately turn off radio if possible */ + rf_params.nInactivityTimeout = 0; + + ble_beacond.rf_handle = ble_open(&rf_params); + + if(ble_beacond.rf_handle == NULL) { + return RF_BLE_BEACOND_ERROR; + } + + return RF_BLE_BEACOND_OK; +} +/*---------------------------------------------------------------------------*/ +rf_ble_beacond_result_t +rf_ble_beacond_config(clock_time_t interval, const char *name) +{ + rf_ble_beacond_result_t res; + + res = RF_BLE_BEACOND_ERROR; + + if(interval > 0) { + ble_beacond.ble_adv_interval = interval; + + res = RF_BLE_BEACOND_OK; + } + + if(name != NULL) { + const size_t name_len = strlen(name); + + if((name_len == 0) || (name_len >= BLE_ADV_NAME_BUF_LEN)) { + ble_beacond.adv_name_len = name_len; + memcpy(ble_beacond.adv_name, name, name_len); + + res = RF_BLE_BEACOND_OK; + } + } + + return res; +} +/*---------------------------------------------------------------------------*/ +rf_ble_beacond_result_t +rf_ble_beacond_start(void) +{ + if(ble_beacond.is_active) { + return RF_BLE_BEACOND_OK; + } + + ble_beacond.is_active = true; + + process_start(&ble_beacond_process, NULL); + + return RF_BLE_BEACOND_OK; +} +/*---------------------------------------------------------------------------*/ +rf_ble_beacond_result_t +rf_ble_beacond_stop(void) +{ + if(!ble_beacond.is_active) { + return RF_BLE_BEACOND_OK; + } + + ble_beacond.is_active = false; + + process_exit(&ble_beacond_process); + + return RF_BLE_BEACOND_OK; +} +/*---------------------------------------------------------------------------*/ +int8_t +rf_ble_is_active(void) +{ + return (int8_t)ble_beacond.is_active; +} +/*---------------------------------------------------------------------------*/ +rf_ble_beacond_result_t +rf_ble_set_tx_power(int8_t dbm) +{ + rf_result_t res; + + if(!tx_power_in_range(dbm, ble_tx_power_table, ble_tx_power_table_size)) { + return RADIO_RESULT_INVALID_VALUE; + } + + res = rf_set_tx_power(ble_beacond.rf_handle, ble_tx_power_table, dbm); + + return (res == RF_RESULT_OK) + ? RF_BLE_BEACOND_OK + : RF_BLE_BEACOND_ERROR; +} +/*---------------------------------------------------------------------------*/ +int8_t +rf_ble_get_tx_power(void) +{ + rf_result_t res; + + int8_t dbm; + res = rf_get_tx_power(ble_beacond.rf_handle, ble_tx_power_table, &dbm); + + if(res != RF_RESULT_OK) { + return RF_TxPowerTable_INVALID_DBM; + } + + return dbm; +} +/*---------------------------------------------------------------------------*/ +static rf_ble_beacond_result_t +ble_beacon_burst(uint8_t channels_bm, uint8_t *data, uint8_t len) +{ + rf_result_t res; + + uint8_t channel; + for(channel = BLE_ADV_CHANNEL_MIN; channel <= BLE_ADV_CHANNEL_MAX; ++channel) { + const uint8_t channel_bv = (1 << (channel - BLE_ADV_CHANNEL_MIN)); + if((channel_bv & channels_bm) == 0) { + continue; + } + + ble_adv_par.advLen = len; + ble_adv_par.pAdvData = data; + + ble_cmd_beacon.channel = channel; + + res = ble_sched_beacon(NULL, 0); + + if(res != RF_RESULT_OK) { + return RF_BLE_BEACOND_ERROR; + } + } + + return RF_BLE_BEACOND_OK; +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(ble_beacond_process, ev, data) +{ + static size_t i; + static size_t len; + + PROCESS_BEGIN(); + + while(1) { + etimer_set(&ble_beacond.ble_adv_et, ble_beacond.ble_adv_interval); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&ble_beacond.ble_adv_et) || + (ev == PROCESS_EVENT_EXIT)); + + if(ev == PROCESS_EVENT_EXIT) { + PROCESS_EXIT(); + } + + /* Set the adv payload each pass: The device name may have changed */ + len = 0; + + /* Device info */ + ble_beacond.tx_buf[len++] = (uint8_t)0x02; /* 2 bytes */ + ble_beacond.tx_buf[len++] = (uint8_t)BLE_ADV_TYPE_DEVINFO; + ble_beacond.tx_buf[len++] = (uint8_t)0x1A; /* LE general discoverable + BR/EDR */ + ble_beacond.tx_buf[len++] = (uint8_t)ble_beacond.adv_name_len; + ble_beacond.tx_buf[len++] = (uint8_t)BLE_ADV_TYPE_NAME; + + memcpy(ble_beacond.tx_buf + len, ble_beacond.adv_name, ble_beacond.adv_name_len); + len += ble_beacond.adv_name_len; + + /* + * Send BLE_ADV_MESSAGES beacon bursts. Each burst on all three + * channels, with a BLE_ADV_DUTY_CYCLE interval between bursts + */ + ble_beacon_burst(BLE_ADV_CHANNEL_ALL, ble_beacond.tx_buf, len); + for(i = 1; i < BLE_ADV_MESSAGES; ++i) { + etimer_set(&ble_beacond.ble_adv_et, BLE_ADV_DUTY_CYCLE); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&ble_beacond.ble_adv_et)); + + ble_beacon_burst(BLE_ADV_CHANNEL_ALL, ble_beacond.tx_buf, len); + } + } + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ +#else /* RF_CONF_BLE_BEACON_ENABLE */ +/*---------------------------------------------------------------------------*/ +rf_ble_beacond_result_t +rf_ble_beacond_init(void) +{ + return RF_BLE_BEACOND_DISABLED; +} +/*---------------------------------------------------------------------------*/ +rf_ble_beacond_result_t +rf_ble_beacond_config(clock_time_t interval, const char *name) +{ + (void)interval; + (void)name; + return RF_BLE_BEACOND_DISABLED; +} +/*---------------------------------------------------------------------------*/ +rf_ble_beacond_result_t +rf_ble_beacond_start(void) +{ + return RF_BLE_BEACOND_DISABLED; +} + +/*---------------------------------------------------------------------------*/ +rf_ble_beacond_result_t +rf_ble_beacond_stop(void) +{ + return RF_BLE_BEACOND_DISABLED; +} +/*---------------------------------------------------------------------------*/ +int8_t +rf_ble_is_active(void) +{ + return -1; +} +/*---------------------------------------------------------------------------*/ +rf_ble_beacond_result_t +rf_ble_set_tx_power(int8_t power) +{ + (void)power; + return RF_BLE_BEACOND_DISABLED; +} +/*---------------------------------------------------------------------------*/ +int8_t +rf_ble_get_tx_power(void) +{ + return ~(int8_t)(0); +} +/*---------------------------------------------------------------------------*/ +#endif /* RF_CONF_BLE_BEACON_ENABLE */ +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-beacond.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-beacond.h new file mode 100644 index 000000000..7741a2d71 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ble-beacond.h @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-rf + * @{ + * + * \defgroup cc13xx-cc26xx-rf-ble CC13xx/CC26xx BLE Beacon Daemon + * + * @{ + * + * \file + * Header file for the CC13xx/CC26xx BLE Beacon Daemon. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#ifndef RF_BLE_BEACOND_H_ +#define RF_BLE_BEACOND_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +/*---------------------------------------------------------------------------*/ +#include +/*---------------------------------------------------------------------------*/ +typedef enum { + RF_BLE_BEACOND_OK, + RF_BLE_BEACOND_ERROR, + RF_BLE_BEACOND_DISABLED, +} rf_ble_beacond_result_t; +/*---------------------------------------------------------------------------*/ +/** + * \brief Initialize the BLE advertisement/beacon daemon + */ +rf_ble_beacond_result_t rf_ble_beacond_init(void); + +/** + * \brief Set the device name to use with the BLE advertisement/beacon daemon + * \param interval The interval (ticks) between two consecutive beacon bursts + * \param name The device name to advertise + * + * If name is NULL it will be ignored. If interval==0 it will be ignored. Thus, + * this function can be used to configure a single parameter at a time if so + * desired. + */ +rf_ble_beacond_result_t rf_ble_beacond_config(clock_time_t interval, const char *name); + +/** + * \brief Start the BLE advertisement/beacon daemon + * \return RF_CORE_CMD_OK: Success, RF_CORE_CMD_ERROR: Failure + * + * Before calling this function, the name to advertise must first be set by + * calling rf_ble_beacond_config(). Otherwise, this function will return an + * error. + */ +rf_ble_beacond_result_t rf_ble_beacond_start(void); + +/** + * \brief Stop the BLE advertisement/beacon daemon + */ +rf_ble_beacond_result_t rf_ble_beacond_stop(void); + +/** + * \brief Check whether the BLE beacond is currently active + * \retval 1 BLE daemon is active + * \retval 0 BLE daemon is inactive + * \retval -1 BLE daemon is disabled + */ +int8_t rf_ble_is_active(void); + +/** + * \brief Set TX power for BLE advertisements + * \param dbm The 'at least' TX power in dBm, values avove 5 dBm will be ignored + * + * Set TX power to 'at least' power dBm. + * This works with a lookup table. If the value of 'power' does not exist in + * the lookup table, TXPOWER will be set to the immediately higher available + * value + */ +rf_ble_beacond_result_t rf_ble_set_tx_power(int8_t dbm); + +/** + * \brief Get TX power for BLE advertisements + * \return The TX power for BLE advertisements + */ +int8_t rf_ble_get_tx_power(void); +/*---------------------------------------------------------------------------*/ +#endif /* RF_BLE_BEACOND_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/data-queue.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf/data-queue.c new file mode 100644 index 000000000..a5f03a8d7 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/data-queue.c @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-rf-data-queue + * @{ + * + * \file + * Implementation of the CC13xx/CC26xx RF data queue. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "sys/cc.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +#include DeviceFamily_constructPath(driverlib/rf_data_entry.h) +/*---------------------------------------------------------------------------*/ +#include "rf/data-queue.h" +/*---------------------------------------------------------------------------*/ +#include +#include +#include +/*---------------------------------------------------------------------------*/ +/* RX buf configuration */ +#define RX_BUF_CNT RF_CONF_RX_BUF_CNT +#define RX_BUF_SIZE RF_CONF_RX_BUF_SIZE +/*---------------------------------------------------------------------------*/ +/* Receive buffer entries with room for 1 IEEE 802.15.4 frame in each */ +typedef union { + data_entry_t data_entry; + uint8_t buf[RX_BUF_SIZE]; +} rx_buf_t CC_ALIGN (4); +/*---------------------------------------------------------------------------*/ +typedef struct { + /* RX bufs */ + rx_buf_t bufs[RX_BUF_CNT]; + /* RFC data queue object */ + data_queue_t data_queue; + /* Current data entry in use by RF */ + data_entry_t *curr_entry; + /* Size in bytes of length field in data entry */ + size_t lensz; +} rx_data_queue_t; + +static rx_data_queue_t rx_data_queue; +/*---------------------------------------------------------------------------*/ +static void +rx_bufs_init(void) +{ + data_entry_t *data_entry; + size_t i; + + for(i = 0; i < RX_BUF_CNT; ++i) { + data_entry = &(rx_data_queue.bufs[i].data_entry); + + data_entry->status = DATA_ENTRY_PENDING; + data_entry->config.type = DATA_ENTRY_TYPE_GEN; + data_entry->config.lenSz = rx_data_queue.lensz; + data_entry->length = RX_BUF_SIZE - sizeof(data_entry_t); + /* Point to fist entry if this is last entry, else point to next entry */ + data_entry->pNextEntry = ((i + 1) == RX_BUF_CNT) + ? rx_data_queue.bufs[0].buf + : rx_data_queue.bufs[i + 1].buf; + } +} +/*---------------------------------------------------------------------------*/ +static void +rx_bufs_reset(void) +{ + size_t i; + for(i = 0; i < RX_BUF_CNT; ++i) { + data_entry_t *const data_entry = &(rx_data_queue.bufs[i].data_entry); + + /* Clear length bytes */ + memset(&(data_entry->data), 0x0, rx_data_queue.lensz); + /* Set status to Pending */ + data_entry->status = DATA_ENTRY_PENDING; + } +} +/*---------------------------------------------------------------------------*/ +data_queue_t * +data_queue_init(size_t lensz) +{ + rx_data_queue.lensz = lensz; + + /* Initialize RX buffers */ + rx_bufs_init(); + + /* Configure data queue as circular buffer */ + rx_data_queue.data_queue.pCurrEntry = rx_data_queue.bufs[0].buf; + rx_data_queue.data_queue.pLastEntry = NULL; + + /* Set current read pointer to first element */ + rx_data_queue.curr_entry = &(rx_data_queue.bufs[0].data_entry); + + return &rx_data_queue.data_queue; +} +/*---------------------------------------------------------------------------*/ +void +data_queue_reset(void) +{ + rx_bufs_reset(); + + /* Only need to reconfigure pCurrEntry */ + rx_data_queue.data_queue.pCurrEntry = rx_data_queue.bufs[0].buf; + + /* Set current read pointer to first element */ + rx_data_queue.curr_entry = &(rx_data_queue.bufs[0].data_entry); +} +/*---------------------------------------------------------------------------*/ +data_entry_t * +data_queue_current_entry(void) +{ + return rx_data_queue.curr_entry; +} +/*---------------------------------------------------------------------------*/ +void +data_queue_release_entry(void) +{ + data_entry_t *const curr_entry = rx_data_queue.curr_entry; + uint8_t *const frame_ptr = (uint8_t *)&(curr_entry->data); + + /* Clear length bytes */ + memset(frame_ptr, 0x0, rx_data_queue.lensz); + /* Set status to Pending */ + curr_entry->status = DATA_ENTRY_PENDING; + + /* Move current entry to the next entry */ + rx_data_queue.curr_entry = (data_entry_t *)(curr_entry->pNextEntry); +} +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/data-queue.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf/data-queue.h new file mode 100644 index 000000000..049cf78d1 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/data-queue.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-rf + * @{ + * + * \defgroup cc13xx-cc26xx-rf-data-queue RF data queue for CC13xx/CC26xx + * + * @{ + * + * \file + * Header file of the CC13xx/CC26xx RF data queue. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#ifndef RF_DATA_QUEUE_H_ +#define RF_DATA_QUEUE_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +#include DeviceFamily_constructPath(driverlib/rf_data_entry.h) +/*---------------------------------------------------------------------------*/ +#include +/*---------------------------------------------------------------------------*/ +typedef dataQueue_t data_queue_t; +typedef rfc_dataEntryGeneral_t data_entry_t; +/*---------------------------------------------------------------------------*/ +data_queue_t *data_queue_init(size_t lensz); +void data_queue_reset(void); +data_entry_t *data_queue_current_entry(void); +void data_queue_release_entry(void); +/*---------------------------------------------------------------------------*/ +#endif /* RF_DATA_QUEUE_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/dot-15-4g.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf/dot-15-4g.h new file mode 100644 index 000000000..5366651e7 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/dot-15-4g.h @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-rf + * @{ + * + * \defgroup cc13xx-cc26xx-rf-15-4g-modes IEEE 802.15.4g Frequency Bands and Modes + * + * @{ + * + * \file + * Header file with descriptors for the various modes of operation + * defined in IEEE 802.15.4g. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#ifndef DOT_15_4G_H_ +#define DOT_15_4G_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +/*---------------------------------------------------------------------------*/ +#include +#include +/*---------------------------------------------------------------------------*/ +/* IEEE 802.15.4g frequency band identifiers (Table 68f) */ +#define DOT_15_4G_FREQ_BAND_169 0 /* 169.400–169.475 (Europe) - 169 MHz band */ +#define DOT_15_4G_FREQ_BAND_450 1 /* 450–470 (US FCC Part 22/90) - 450 MHz band */ +#define DOT_15_4G_FREQ_BAND_470 2 /* 470–510 (China) - 470 MHz band */ +#define DOT_15_4G_FREQ_BAND_780 3 /* 779–787 (China) - 780 MHz band */ +#define DOT_15_4G_FREQ_BAND_863 4 /* 863–870 (Europe) - 863 MHz band */ +#define DOT_15_4G_FREQ_BAND_896 5 /* 896–901 (US FCC Part 90) - 896 MHz band */ +#define DOT_15_4G_FREQ_BAND_901 6 /* 901–902 (US FCC Part 24) - 901 MHz band */ +#define DOT_15_4G_FREQ_BAND_915 7 /* 902–928 (US) - 915 MHz band */ +#define DOT_15_4G_FREQ_BAND_917 8 /* 917–923.5 (Korea) - 917 MHz band */ +#define DOT_15_4G_FREQ_BAND_920 9 /* 920–928 (Japan) - 920 MHz band */ +#define DOT_15_4G_FREQ_BAND_928 10 /* 928–960 (US, non-contiguous) - 928 MHz band */ +#define DOT_15_4G_FREQ_BAND_950 11 /* 950–958 (Japan) - 950 MHz band */ +#define DOT_15_4G_FREQ_BAND_1427 12 /* 1427–1518 (US and Canada, non-contiguous) - 1427 MHz band */ +#define DOT_15_4G_FREQ_BAND_2450 13 /* 2400–2483.5 2450 MHz band */ +/*---------------------------------------------------------------------------*/ +/* Default band selection to band 4 - 863MHz */ +#ifdef DOT_15_4G_CONF_FREQ_BAND_ID +#define DOT_15_4G_FREQ_BAND_ID DOT_15_4G_CONF_FREQ_BAND_ID +#else +#define DOT_15_4G_FREQ_BAND_ID DOT_15_4G_FREQ_BAND_863 +#endif +/*---------------------------------------------------------------------------*/ +/* + * Channel count, spacing and other params relating to the selected band. We + * currently only support some of the bands defined in .15.4g and for those + * bands we only support operating mode #1 (Table 134). + * + * DOT_15_4G_CHAN0_FREQ is specified here in KHz + */ +#if (DOT_15_4G_FREQ_BAND_ID == DOT_15_4G_FREQ_BAND_470) +#define DOT_15_4G_CHAN_MIN 0 +#define DOT_15_4G_CHAN_MAX 198 +#define DOT_15_4G_FREQ_SPACING 200 +#define DOT_15_4G_CHAN0_FREQ 470200 + +#define PROP_MODE_CONF_CENTER_FREQ 0x01EA +#define PROP_MODE_CONF_LO_DIVIDER 0x0A + +#elif (DOT_15_4G_FREQ_BAND_ID == DOT_15_4G_FREQ_BAND_780) +#define DOT_15_4G_CHAN_MIN 0 +#define DOT_15_4G_CHAN_MAX 38 +#define DOT_15_4G_FREQ_SPACING 200 +#define DOT_15_4G_CHAN0_FREQ 779200 + +#define PROP_MODE_CONF_CENTER_FREQ 0x030F +#define PROP_MODE_CONF_LO_DIVIDER 0x06 + +#elif (DOT_15_4G_FREQ_BAND_ID == DOT_15_4G_FREQ_BAND_863) +#define DOT_15_4G_CHAN_MIN 0 +#define DOT_15_4G_CHAN_MAX 33 +#define DOT_15_4G_FREQ_SPACING 200 +#define DOT_15_4G_CHAN0_FREQ 863125 + +#define PROP_MODE_CONF_CENTER_FREQ 0x0362 +#define PROP_MODE_CONF_LO_DIVIDER 0x05 + +#elif (DOT_15_4G_FREQ_BAND_ID == DOT_15_4G_FREQ_BAND_915) +#define DOT_15_4G_CHAN_MIN 0 +#define DOT_15_4G_CHAN_MAX 128 +#define DOT_15_4G_FREQ_SPACING 200 +#define DOT_15_4G_CHAN0_FREQ 902200 + +#define PROP_MODE_CONF_CENTER_FREQ 0x0393 +#define PROP_MODE_CONF_LO_DIVIDER 0x05 + +#elif (DOT_15_4G_FREQ_BAND_ID == DOT_15_4G_FREQ_BAND_920) +#define DOT_15_4G_CHAN_MIN 0 +#define DOT_15_4G_CHAN_MAX 37 +#define DOT_15_4G_FREQ_SPACING 200 +#define DOT_15_4G_CHAN0_FREQ 920600 + +#define PROP_MODE_CONF_CENTER_FREQ 0x039C +#define PROP_MODE_CONF_LO_DIVIDER 0x05 + +#elif (DOT_15_4G_FREQ_BAND_ID == DOT_15_4G_FREQ_BAND_950) +#define DOT_15_4G_CHAN_MIN 0 +#define DOT_15_4G_CHAN_MAX 32 +#define DOT_15_4G_FREQ_SPACING 200 +#define DOT_15_4G_CHAN0_FREQ 951000 + +#define PROP_MODE_CONF_CENTER_FREQ 0x03BA +#define PROP_MODE_CONF_LO_DIVIDER 0x05 + +#elif (DOT_15_4G_FREQ_BAND_ID == DOT_15_4G_FREQ_BAND_2450) +#define DOT_15_4G_CHAN_MIN 11 +#define DOT_15_4G_CHAN_MAX 26 +#define DOT_15_4G_FREQ_SPACING 5000 +#define DOT_15_4G_CHAN0_FREQ 2405000 + +#else +#error "The selected IEEE 802.15.4g frequency band is not supported" +#endif +/*---------------------------------------------------------------------------*/ +static inline uint32_t +dot_15_4g_freq(const uint16_t chan) +{ + const uint32_t chan0 = DOT_15_4G_CHAN0_FREQ; + const uint32_t spacing = DOT_15_4G_FREQ_SPACING; + const uint32_t chan_min = DOT_15_4G_CHAN_MIN; + return chan0 + spacing * ((uint32_t)chan - chan_min); +} +/*---------------------------------------------------------------------------*/ +static inline bool +dot_15_4g_chan_in_range(const uint16_t chan) +{ + const uint16_t chan_min = DOT_15_4G_CHAN_MIN; + const uint16_t chan_max = DOT_15_4G_CHAN_MAX; + return (chan >= chan_min) && + (chan <= chan_max); +} +/*---------------------------------------------------------------------------*/ +#define DOT_15_4G_DEFAULT_CHAN IEEE802154_DEFAULT_CHANNEL +/*---------------------------------------------------------------------------*/ +#endif /* DOT_15_4G_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/ieee-addr.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ieee-addr.c new file mode 100644 index 000000000..4ce39a241 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ieee-addr.c @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-rf-ieee-addr + * @{ + * + * \file + * Implementation of the CC13xx/CC26xx IEEE addresses driver. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "net/linkaddr.h" + +#include "rf/ieee-addr.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(inc/hw_memmap.h) +#include DeviceFamily_constructPath(inc/hw_fcfg1.h) +#include DeviceFamily_constructPath(inc/hw_ccfg.h) +/*---------------------------------------------------------------------------*/ +#include +#include +/*---------------------------------------------------------------------------*/ +#define IEEE_ADDR_HARDCODED IEEE_ADDR_CONF_HARDCODED +#define IEEE_ADDR_ADDRESS IEEE_ADDR_CONF_ADDRESS +/*---------------------------------------------------------------------------*/ +#define IEEE_MAC_PRIMARY_ADDRESS (FCFG1_BASE + FCFG1_O_MAC_15_4_0) +#define IEEE_MAC_SECONDARY_ADDRESS (CCFG_BASE + CCFG_O_IEEE_MAC_0) +/*---------------------------------------------------------------------------*/ +int +ieee_addr_cpy_to(uint8_t *dst, uint8_t len) +{ + if(len > LINKADDR_SIZE) { + return -1; + } + + if(IEEE_ADDR_HARDCODED) { + const uint8_t ieee_addr_hc[LINKADDR_SIZE] = IEEE_ADDR_ADDRESS; + + memcpy(dst, &ieee_addr_hc[LINKADDR_SIZE - len], len); + } else { + int i; + + volatile const uint8_t *const primary = (uint8_t *)IEEE_MAC_PRIMARY_ADDRESS; + volatile const uint8_t *const secondary = (uint8_t *)IEEE_MAC_SECONDARY_ADDRESS; + + /* Reading from primary location... */ + volatile const uint8_t *ieee_addr = primary; + + /* + * ...unless we can find a byte != 0xFF in secondary. + * + * Intentionally checking all 8 bytes here instead of len, because we + * are checking validity of the entire address respective of the + * actual number of bytes the caller wants to copy over. + */ + for(i = 0; i < len; i++) { + if(secondary[i] != 0xFF) { + /* A byte in the secondary location is not 0xFF. Use the secondary */ + ieee_addr = secondary; + break; + } + } + + /* + * We have chosen what address to read the address from. Do so, + * in inverted byte order. + */ + for(i = 0; i < len; i++) { + dst[i] = ieee_addr[len - 1 - i]; + } + } + +#ifdef IEEE_ADDR_NODE_ID + dst[len - 1] = (IEEE_ADDR_NODE_ID >> 0) & 0xFF; + dst[len - 2] = (IEEE_ADDR_NODE_ID >> 8) & 0xFF; +#endif + + return 0; +} +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/ieee-addr.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ieee-addr.h new file mode 100644 index 000000000..dc649cdd1 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ieee-addr.h @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-cpu + * @{ + * + * \defgroup cc13xx-cc26xx-rf-ieee-addr CC13xx/CC26xx IEEE Address Control + * + * Driver for the retrieval of an IEEE address from flash. + * + * The user can specify a hardcoded IEEE address through the + * IEEE_ADDR_CONF_HARDCODED configuration macro. + * + * If the user does not hard-code an address, then one will be read from either + * the primary location (InfoPage) or from the secondary location (on flash). + * + * In order to allow the user to easily program nodes with addresses, the + * secondary location is given priority: If it contains a valid address then + * it will be chosen in favour of the one on InfoPage. + * + * In this context, an address is valid if at least one of the 8 bytes does not + * equal 0xFF. If all 8 bytes are 0xFF, then the primary location will be used. + * + * In all cases, the address is assumed to be written little-endian. + * + * Lastly, it is possible to override the 2 LSB's of the address by using the + * NODE_ID make variable. + * @{ + * + * \file + * Header file for the CC13xx/CC26xx IEEE address driver. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#ifndef IEEE_ADDR_H_ +#define IEEE_ADDR_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +/*---------------------------------------------------------------------------*/ +/** + * \brief Copy the device's IEEE address to a destination buffer. + * \param dst A pointer to the destination area where the IEEE address is to + * be written. + * \param len The number of bytes to write to destination area + * \return 0 : Returned successfully + * -1 : Returned with error + * + * This function will copy \p len bytes in LSB and it will invert byte order + * in the process. The factory address on devices is normally little-endian, + * therefore you should expect dst to store the address in a big-endian order. + */ +int ieee_addr_cpy_to(uint8_t *dst, uint8_t len); +/*---------------------------------------------------------------------------*/ +#endif /* IEEE_ADDR_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/ieee-mode.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ieee-mode.c new file mode 100644 index 000000000..d9f3a5acf --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/ieee-mode.c @@ -0,0 +1,1021 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-rf + * @{ + * + * \defgroup cc13xx-cc26xx-rf-ieee IEEE-mode driver for CC13xx/CC26xx + * + * @{ + * + * \file + * Implementation of the CC13xx/CC26xx IEEE-mode NETSTACK_RADIO driver. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "net/packetbuf.h" +#include "net/linkaddr.h" +#include "net/netstack.h" +#include "sys/energest.h" +#include "sys/clock.h" +#include "sys/rtimer.h" +#include "sys/ctimer.h" +#include "sys/cc.h" +/*---------------------------------------------------------------------------*/ +/* RF driver and RF Core API */ +#include +#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_data_entry.h) +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +/* + * rf_ieee_cmd.h and rf_ieee_mailbox.h are included by RF settings because a + * discrepancy between CC13x0 and CC13x2 IEEE support. CC13x0 doesn't provide + * RFCore definitions of IEEE commands, and are therefore included locally + * from the Contiki build system. CC13x2 includes these normally from driverlib. + * This is taken care of RF settings. + */ + +#include +/*---------------------------------------------------------------------------*/ +/* SimpleLink Platform RF dev */ +#include "rf/rf.h" +#include "rf/data-queue.h" +#include "rf/dot-15-4g.h" +#include "rf/sched.h" +#include "rf/settings.h" +#include "rf/tx-power.h" +/*---------------------------------------------------------------------------*/ +#include +#include +#include +#include +#include +/*---------------------------------------------------------------------------*/ +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "Radio" +#define LOG_LEVEL LOG_LEVEL_NONE +/*---------------------------------------------------------------------------*/ +/* Configuration parameters */ +#define IEEE_MODE_AUTOACK IEEE_MODE_CONF_AUTOACK +#define IEEE_MODE_PROMISCOUS IEEE_MODE_CONF_PROMISCOUS +#define IEEE_MODE_CCA_RSSI_THRESHOLD IEEE_MODE_CONF_CCA_RSSI_THRESHOLD +/*---------------------------------------------------------------------------*/ +/* Timeout constants */ + +/* How long to wait for the rx read entry to become ready */ +#define TIMEOUT_DATA_ENTRY_BUSY (RTIMER_SECOND / 250) + +/* How long to wait for RX to become active after scheduled */ +#define TIMEOUT_ENTER_RX_WAIT (RTIMER_SECOND >> 10) +/*---------------------------------------------------------------------------*/ +#define RAT_RANGE (~(uint32_t)0) +#define RAT_ONE_QUARTER (RAT_RANGE / (uint32_t)4) +#define RAT_THREE_QUARTERS ((RAT_RANGE * (uint32_t)3) / (uint32_t)4) + +/* XXX: don't know what exactly is this, looks like the time to TX 3 octets */ +#define RAT_TIMESTAMP_OFFSET -(USEC_TO_RAT(32 * 3) - 1) /* -95.75 usec */ +/*---------------------------------------------------------------------------*/ +#define STATUS_CORRELATION 0x3f /* bits 0-5 */ +#define STATUS_REJECT_FRAME 0x40 /* bit 6 */ +#define STATUS_CRC_FAIL 0x80 /* bit 7 */ +/*---------------------------------------------------------------------------*/ +#define FRAME_FCF_OFFSET 0 +#define FRAME_SEQNUM_OFFSET 2 + +#define FRAME_ACK_REQUEST 0x20 /* bit 5 */ + +/* TX buf configuration */ +#define TX_BUF_SIZE 180 +/*---------------------------------------------------------------------------*/ +/* Size of the Length representation in Data Entry, one byte in this case */ +typedef uint8_t lensz_t; + +#define FRAME_OFFSET sizeof(lensz_t) +#define FRAME_SHAVE 8 /* FCS (2) + RSSI (1) + Status (1) + Timestamp (4) */ +/*---------------------------------------------------------------------------*/ +/* Used for checking result of CCA_REQ command */ +typedef enum { + CCA_STATE_IDLE = 0, + CCA_STATE_BUSY = 1, + CCA_STATE_INVALID = 2 +} cca_state_t; +/*---------------------------------------------------------------------------*/ +/* RF Core typedefs */ +typedef rfc_ieeeRxOutput_t rx_output_t; +typedef rfc_CMD_IEEE_MOD_FILT_t cmd_mod_filt_t; +typedef rfc_CMD_IEEE_CCA_REQ_t cmd_cca_req_t; + +typedef struct { + /* Outgoing frame buffer */ + uint8_t tx_buf[TX_BUF_SIZE] CC_ALIGN(4); + + /* RF Statistics struct */ + rx_output_t rx_stats; + + /* Indicates RF is supposed to be on or off */ + bool rf_is_on; + /* Enable/disable CCA before sending */ + bool send_on_cca; + /* Are we currently in poll mode? */ + bool poll_mode; + + /* Last RX operation stats */ + struct { + int8_t rssi; + uint8_t corr_lqi; + uint32_t timestamp; + } last; + + /* RAT Overflow Upkeep */ + struct { + struct ctimer overflow_timer; + rtimer_clock_t last_overflow; + volatile uint32_t overflow_count; + } rat; + + /* RF driver */ + RF_Handle rf_handle; +} ieee_radio_t; + +static ieee_radio_t ieee_radio; + +/* Global RF Core commands */ +static cmd_mod_filt_t cmd_mod_filt; +/*---------------------------------------------------------------------------*/ +/* RF Command volatile objects */ +#define cmd_radio_setup (*(volatile rfc_CMD_RADIO_SETUP_t *)&rf_cmd_ieee_radio_setup) +#define cmd_fs (*(volatile rfc_CMD_FS_t *) &rf_cmd_ieee_fs) +#define cmd_tx (*(volatile rfc_CMD_IEEE_TX_t *) &rf_cmd_ieee_tx) +#define cmd_rx (*(volatile rfc_CMD_IEEE_RX_t *) &rf_cmd_ieee_rx) +#define cmd_rx_ack (*(volatile rfc_CMD_IEEE_RX_ACK_t *)&rf_cmd_ieee_rx_ack) +/*---------------------------------------------------------------------------*/ +static inline bool +rx_is_active(void) +{ + return cmd_rx.status == ACTIVE; +} +/*---------------------------------------------------------------------------*/ +/* Forward declarations of local functions */ +static void check_rat_overflow(void); +static uint32_t rat_to_timestamp(const uint32_t); +/*---------------------------------------------------------------------------*/ +/* Forward declarations of Radio driver functions */ +static int init(void); +static int prepare(const void *, unsigned short); +static int transmit(unsigned short); +static int send(const void *, unsigned short); +static int read(void *, unsigned short); +static int channel_clear(void); +static int receiving_packet(void); +static int pending_packet(void); +static int on(void); +static int off(void); +static radio_result_t get_value(radio_param_t, radio_value_t *); +static radio_result_t set_value(radio_param_t, radio_value_t); +static radio_result_t get_object(radio_param_t, void *, size_t); +static radio_result_t set_object(radio_param_t, const void *, size_t); +/*---------------------------------------------------------------------------*/ +static void +rat_overflow_cb(void *arg) +{ + check_rat_overflow(); + /* Check next time after half of the RAT interval */ + const clock_time_t two_quarters = (2 * RAT_ONE_QUARTER * CLOCK_SECOND) / RAT_SECOND; + ctimer_set(&ieee_radio.rat.overflow_timer, two_quarters, rat_overflow_cb, NULL); +} +/*---------------------------------------------------------------------------*/ +static void +init_rf_params(void) +{ + data_queue_t *rx_q = data_queue_init(sizeof(lensz_t)); + + cmd_rx.pRxQ = rx_q; + cmd_rx.pOutput = &ieee_radio.rx_stats; + +#if IEEE_MODE_PROMISCOUS + cmd_rx.frameFiltOpt.frameFiltEn = 0; +#else + cmd_rx.frameFiltOpt.frameFiltEn = 1; +#endif + +#if IEEE_MODE_AUTOACK + cmd_rx.frameFiltOpt.autoAckEn = 1; +#else + cmd_rx.frameFiltOpt.autoAckEn = 0; +#endif + + cmd_rx.ccaRssiThr = IEEE_MODE_CCA_RSSI_THRESHOLD; + + cmd_tx.pNextOp = (RF_Op *)&cmd_rx_ack; + cmd_tx.condition.rule = COND_NEVER; /* Initially ACK turned off */ + + /* + * ACK packet is transmitted 192 us after the end of the received packet, + * takes 352 us for ACK transmission, total of 546 us of expected time to + * recieve ACK in ideal conditions. 700 us endTime for CMD_IEEE_RX_ACK + * should give some margins. + * The ACK frame consists of 6 bytes of SHR/PDR and 5 bytes of PSDU, total + * of 11 bytes. 11 bytes x 32 us/byte equals 352 us of ACK transmission time. + */ + cmd_rx_ack.startTrigger.triggerType = TRIG_NOW; + cmd_rx_ack.endTrigger.triggerType = TRIG_REL_START; + cmd_rx_ack.endTime = RF_convertUsToRatTicks(700); + + /* Initialize address filter command */ + cmd_mod_filt.commandNo = CMD_IEEE_MOD_FILT; + memcpy(&(cmd_mod_filt.newFrameFiltOpt), &(rf_cmd_ieee_rx.frameFiltOpt), sizeof(rf_cmd_ieee_rx.frameFiltOpt)); + memcpy(&(cmd_mod_filt.newFrameTypes), &(rf_cmd_ieee_rx.frameTypes), sizeof(rf_cmd_ieee_rx.frameTypes)); +} +/*---------------------------------------------------------------------------*/ +static rf_result_t +set_channel(uint8_t channel) +{ + if(!dot_15_4g_chan_in_range(channel)) { + LOG_WARN("Supplied hannel %d is illegal, defaults to %d\n", + (int)channel, DOT_15_4G_DEFAULT_CHAN); + channel = DOT_15_4G_DEFAULT_CHAN; + } + + /* + * cmd_rx.channel is initialized to 0, causing any initial call to + * set_channel() to cause a synth calibration, since channel must be in + * range 11-26. + */ + if(channel == cmd_rx.channel) { + /* We are already calibrated to this channel */ + return true; + } + + cmd_rx.channel = channel; + + const uint32_t new_freq = dot_15_4g_freq(channel); + const uint16_t freq = (uint16_t)(new_freq / 1000); + const uint16_t frac = (uint16_t)(((new_freq - (freq * 1000)) * 0x10000) / 1000); + + LOG_DBG("Set channel to %d, frequency 0x%04X.0x%04X (%lu)\n", + (int)channel, freq, frac, new_freq); + + cmd_fs.frequency = freq; + cmd_fs.fractFreq = frac; + + return netstack_sched_fs(); +} +/*---------------------------------------------------------------------------*/ +static void +set_send_on_cca(bool enable) +{ + ieee_radio.send_on_cca = enable; +} +/*---------------------------------------------------------------------------*/ +static void +check_rat_overflow(void) +{ + const bool was_off = !rx_is_active(); + + if(was_off) { + RF_runDirectCmd(ieee_radio.rf_handle, CMD_NOP); + } + + const uint32_t current_value = RF_getCurrentTime(); + + static bool initial_iteration = true; + static uint32_t last_value; + + if(initial_iteration) { + /* First time checking overflow will only store the current value */ + initial_iteration = false; + } else { + /* Overflow happens in the last quarter of the RAT range */ + if((current_value + RAT_ONE_QUARTER) < last_value) { + /* Overflow detected */ + ieee_radio.rat.last_overflow = RTIMER_NOW(); + ieee_radio.rat.overflow_count += 1; + } + } + + last_value = current_value; + + if(was_off) { + RF_yield(ieee_radio.rf_handle); + } +} +/*---------------------------------------------------------------------------*/ +static uint32_t +rat_to_timestamp(const uint32_t rat_ticks) +{ + check_rat_overflow(); + + uint64_t adjusted_overflow_count = ieee_radio.rat.overflow_count; + + /* If the timestamp is in the 4th quarter and the last overflow was recently, + * assume that the timestamp refers to the time before the overflow */ + if(rat_ticks > RAT_THREE_QUARTERS) { + const rtimer_clock_t one_quarter = (RAT_ONE_QUARTER * RTIMER_SECOND) / RAT_SECOND; + if(RTIMER_CLOCK_LT(RTIMER_NOW(), ieee_radio.rat.last_overflow + one_quarter)) { + adjusted_overflow_count -= 1; + } + } + + /* Add the overflowed time to the timestamp */ + const uint64_t rat_ticks_adjusted = (uint64_t)rat_ticks + (uint64_t)RAT_RANGE * adjusted_overflow_count; + + /* Correct timestamp so that it refers to the end of the SFD and convert to RTIMER */ + return RAT_TO_RTIMER(rat_ticks_adjusted + RAT_TIMESTAMP_OFFSET); +} +/*---------------------------------------------------------------------------*/ +static int +init(void) +{ + if(ieee_radio.rf_handle) { + LOG_WARN("Radio already initialized\n"); + return RF_RESULT_OK; + } + + /* RX is off */ + ieee_radio.rf_is_on = false; + + init_rf_params(); + + /* Init RF params and specify non-default params */ + RF_Params rf_params; + RF_Params_init(&rf_params); + rf_params.nInactivityTimeout = RF_CONF_INACTIVITY_TIMEOUT; + + ieee_radio.rf_handle = netstack_open(&rf_params); + + if(ieee_radio.rf_handle == NULL) { + LOG_ERR("Unable to open RF driver\n"); + return RF_RESULT_ERROR; + } + + set_channel(DOT_15_4G_DEFAULT_CHAN); + + int8_t max_tx_power = tx_power_max(rf_tx_power_table, rf_tx_power_table_size); + rf_set_tx_power(ieee_radio.rf_handle, rf_tx_power_table, max_tx_power); + + ENERGEST_ON(ENERGEST_TYPE_LISTEN); + + /* Start RAT overflow upkeep */ + check_rat_overflow(); + clock_time_t two_quarters = (2 * RAT_ONE_QUARTER * CLOCK_SECOND) / RAT_SECOND; + ctimer_set(&ieee_radio.rat.overflow_timer, two_quarters, rat_overflow_cb, NULL); + + /* Start RF process */ + process_start(&rf_sched_process, NULL); + + return RF_RESULT_OK; +} +/*---------------------------------------------------------------------------*/ +static int +prepare(const void *payload, unsigned short payload_len) +{ + const size_t len = MIN((size_t)payload_len, + (size_t)TX_BUF_SIZE); + + memcpy(ieee_radio.tx_buf, payload, len); + return 0; +} +/*---------------------------------------------------------------------------*/ +static int +transmit(unsigned short transmit_len) +{ + rf_result_t res; + + if(ieee_radio.send_on_cca && channel_clear() != 1) { + LOG_WARN("Channel is not clear for transmission\n"); + return RADIO_TX_COLLISION; + } + + /* + * Are we expecting ACK? The ACK Request flag is in the first Frame + * Control Field byte, that is the first byte in the frame. + */ + const bool ack_request = (bool)(ieee_radio.tx_buf[FRAME_FCF_OFFSET] & FRAME_ACK_REQUEST); + if(ack_request) { + /* Yes, turn on chaining */ + cmd_tx.condition.rule = COND_STOP_ON_FALSE; + + /* Reset CMD_IEEE_RX_ACK command */ + cmd_rx_ack.status = IDLE; + /* Sequence number is the third byte in the frame */ + cmd_rx_ack.seqNo = ieee_radio.tx_buf[FRAME_SEQNUM_OFFSET]; + } else { + /* No, turn off chaining */ + cmd_tx.condition.rule = COND_NEVER; + } + + /* Configure TX command */ + cmd_tx.payloadLen = (uint8_t)transmit_len; + cmd_tx.pPayload = ieee_radio.tx_buf; + + res = netstack_sched_ieee_tx(ack_request); + + if(res != RF_RESULT_OK) { + return RADIO_TX_ERR; + } + + if(ack_request) { + switch(cmd_rx_ack.status) { + /* CMD_IEEE_RX_ACK timed out, i.e. never received ACK */ + case IEEE_DONE_TIMEOUT: return RADIO_TX_NOACK; + /* An ACK was received with either pending data bit set or cleared */ + case IEEE_DONE_ACK: /* fallthrough */ + case IEEE_DONE_ACKPEND: return RADIO_TX_OK; + /* Any other statuses are errors */ + default: return RADIO_TX_ERR; + } + } + + /* No ACK expected, TX OK */ + return RADIO_TX_OK; +} +/*---------------------------------------------------------------------------*/ +static int +send(const void *payload, unsigned short payload_len) +{ + prepare(payload, payload_len); + return transmit(payload_len); +} +/*---------------------------------------------------------------------------*/ +static int +read(void *buf, unsigned short buf_len) +{ + volatile data_entry_t *data_entry = data_queue_current_entry(); + + const rtimer_clock_t t0 = RTIMER_NOW(); + /* Only wait if the Radio timer is accessing the entry */ + while((data_entry->status == DATA_ENTRY_BUSY) && + RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + TIMEOUT_DATA_ENTRY_BUSY)) ; + + if(data_entry->status != DATA_ENTRY_FINISHED) { + /* No available data */ + return -1; + } + + /* + * lensz bytes (1) in the data entry are the length of the received frame. + * Data frame is on the following format: + * Length (1) + Payload (N) + FCS (2) + RSSI (1) + Status (1) + Timestamp (4) + * Data frame DOES NOT contain the following: + * no PHY Header bytes + * no Source Index bytes + * Visual representation of frame format: + * + * +--------+---------+---------+--------+--------+-----------+ + * | 1 byte | N bytes | 2 bytes | 1 byte | 1 byte | 4 bytes | + * +--------+---------+---------+--------+--------+-----------+ + * | Length | Payload | FCS | RSSI | Status | Timestamp | + * +--------+---------+---------+--------+--------+-----------+ + * + * Length bytes equal total length of entire frame excluding itself, + * Length = N + FCS (2) + RSSI (1) + Status (1) + Timestamp (4) + * Length = N + 8 + * N = Length - 8 + */ + uint8_t *const frame_ptr = (uint8_t *)&data_entry->data; + const lensz_t frame_len = *(lensz_t *)frame_ptr; + + /* Sanity check that Frame is at least Frame Shave bytes long */ + if(frame_len < FRAME_SHAVE) { + LOG_ERR("Received frame too short, len=%d\n", frame_len); + + data_queue_release_entry(); + return 0; + } + + const uint8_t *payload_ptr = frame_ptr + sizeof(lensz_t); + const unsigned short payload_len = (unsigned short)(frame_len - FRAME_SHAVE); + + /* Sanity check that Payload fits in buffer. */ + if(payload_len > buf_len) { + LOG_ERR("MAC payload too large for buffer, len=%d buf_len=%d\n", + payload_len, buf_len); + + data_queue_release_entry(); + return 0; + } + + memcpy(buf, payload_ptr, payload_len); + + /* RSSI stored FCS (2) bytes after payload. */ + ieee_radio.last.rssi = (int8_t)payload_ptr[payload_len + 2]; + /* LQI retrieved from Status byte, FCS (2) + RSSI (1) bytes after payload. */ + ieee_radio.last.corr_lqi = (uint8_t)(payload_ptr[payload_len + 3] & STATUS_CORRELATION); + /* Timestamp stored FCS (2) + RSSI (1) + Status (1) bytes after payload. */ + const uint32_t rat_ticks = *(uint32_t *)(payload_ptr + payload_len + 4); + ieee_radio.last.timestamp = rat_to_timestamp(rat_ticks); + + if(!ieee_radio.poll_mode) { + /* Not in poll mode: packetbuf should not be accessed in interrupt context. */ + /* In poll mode, the last packet RSSI and link quality can be obtained through */ + /* RADIO_PARAM_LAST_RSSI and RADIO_PARAM_LAST_LINK_QUALITY */ + packetbuf_set_attr(PACKETBUF_ATTR_RSSI, (packetbuf_attr_t)ieee_radio.last.rssi); + packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, (packetbuf_attr_t)ieee_radio.last.corr_lqi); + } + + data_queue_release_entry(); + return (int)payload_len; +} +/*---------------------------------------------------------------------------*/ +static rf_result_t +cca_request(cmd_cca_req_t *cmd_cca_req) +{ + rf_result_t res; + + const bool rx_is_idle = !rx_is_active(); + + if(rx_is_idle) { + res = netstack_sched_rx(false); + if(res != RF_RESULT_OK) { + return RF_RESULT_ERROR; + } + } + + const rtimer_clock_t t0 = RTIMER_NOW(); + while((cmd_rx.status != ACTIVE) && + RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + TIMEOUT_ENTER_RX_WAIT)) ; + + RF_Stat stat = RF_StatRadioInactiveError; + if(rx_is_active()) { + stat = RF_runImmediateCmd(ieee_radio.rf_handle, (uint32_t *)&cmd_cca_req); + } + + if(rx_is_idle) { + netstack_stop_rx(); + } + + if(stat != RF_StatCmdDoneSuccess) { + LOG_ERR("CCA request failed, stat=0x%02X\n", stat); + return RF_RESULT_ERROR; + } + + return RF_RESULT_OK; +} +/*---------------------------------------------------------------------------*/ +static int +channel_clear(void) +{ + cmd_cca_req_t cmd_cca_req; + memset(&cmd_cca_req, 0x0, sizeof(cmd_cca_req_t)); + cmd_cca_req.commandNo = CMD_IEEE_CCA_REQ; + + if(cca_request(&cmd_cca_req) != RF_RESULT_OK) { + return 0; + } + + /* Channel is clear if CCA state is IDLE */ + return cmd_cca_req.ccaInfo.ccaState == CCA_STATE_IDLE; +} +/*---------------------------------------------------------------------------*/ +static int +receiving_packet(void) +{ + cmd_cca_req_t cmd_cca_req; + memset(&cmd_cca_req, 0x0, sizeof(cmd_cca_req_t)); + cmd_cca_req.commandNo = CMD_IEEE_CCA_REQ; + + if(cca_request(&cmd_cca_req) != RF_RESULT_OK) { + return 0; + } + + /* If we are transmitting (can only be an ACK here), we are not receiving */ + if((cmd_cca_req.ccaInfo.ccaEnergy == CCA_STATE_BUSY) && + (cmd_cca_req.ccaInfo.ccaCorr == CCA_STATE_BUSY) && + (cmd_cca_req.ccaInfo.ccaSync == CCA_STATE_BUSY)) { + LOG_WARN("We are TXing ACK, therefore not receiving packets\n"); + return 0; + } + + /* We are receiving a packet if a CCA sync has been seen, i.e. ccaSync is busy (1) */ + return cmd_cca_req.ccaInfo.ccaSync == CCA_STATE_BUSY; +} +/*---------------------------------------------------------------------------*/ +static int +pending_packet(void) +{ + const data_entry_t *const read_entry = data_queue_current_entry(); + volatile const data_entry_t *curr_entry = read_entry; + + int num_pending = 0; + + /* Go through RX Circular buffer and check each data entry status */ + do { + const uint8_t status = curr_entry->status; + if((status == DATA_ENTRY_FINISHED) || + (status == DATA_ENTRY_BUSY)) { + num_pending += 1; + } + + /* Stop when we have looped the circular buffer */ + curr_entry = (data_entry_t *)curr_entry->pNextEntry; + } while(curr_entry != read_entry); + + if((num_pending > 0) && !ieee_radio.poll_mode) { + process_poll(&rf_sched_process); + } + + /* If we didn't find an entry at status finished or busy, no frames are pending */ + return num_pending; +} +/*---------------------------------------------------------------------------*/ +static int +on(void) +{ + rf_result_t res; + + if(ieee_radio.rf_is_on) { + LOG_WARN("Radio is already on\n"); + return RF_RESULT_OK; + } + + data_queue_reset(); + + res = netstack_sched_rx(true); + + if(res != RF_RESULT_OK) { + return RF_RESULT_ERROR; + } + + ieee_radio.rf_is_on = true; + return RF_RESULT_OK; +} +/*---------------------------------------------------------------------------*/ +static int +off(void) +{ + if(!ieee_radio.rf_is_on) { + LOG_WARN("Radio is already off\n"); + return RF_RESULT_OK; + } + + rf_yield(); + + ieee_radio.rf_is_on = false; + return RF_RESULT_OK; +} +/*---------------------------------------------------------------------------*/ +static radio_result_t +get_value(radio_param_t param, radio_value_t *value) +{ + rf_result_t res; + + if(!value) { + return RADIO_RESULT_INVALID_VALUE; + } + + switch(param) { + + /* Power Mode */ + case RADIO_PARAM_POWER_MODE: + *value = (ieee_radio.rf_is_on) + ? RADIO_POWER_MODE_ON + : RADIO_POWER_MODE_OFF; + return RADIO_RESULT_OK; + + /* Channel */ + case RADIO_PARAM_CHANNEL: + *value = (radio_value_t)cmd_rx.channel; + return RADIO_RESULT_OK; + + /* PAN ID */ + case RADIO_PARAM_PAN_ID: + *value = (radio_value_t)cmd_rx.localPanID; + return RADIO_RESULT_OK; + + /* 16-bit address */ + case RADIO_PARAM_16BIT_ADDR: + *value = (radio_value_t)cmd_rx.localShortAddr; + return RADIO_RESULT_OK; + + /* RX mode */ + case RADIO_PARAM_RX_MODE: + *value = 0; + if(cmd_rx.frameFiltOpt.frameFiltEn) { + *value |= (radio_value_t)RADIO_RX_MODE_ADDRESS_FILTER; + } + if(cmd_rx.frameFiltOpt.autoAckEn) { + *value |= (radio_value_t)RADIO_RX_MODE_AUTOACK; + } + if(ieee_radio.poll_mode) { + *value |= (radio_value_t)RADIO_RX_MODE_POLL_MODE; + } + return RADIO_RESULT_OK; + + /* TX mode */ + case RADIO_PARAM_TX_MODE: + *value = 0; + return RADIO_RESULT_OK; + + /* TX power */ + case RADIO_PARAM_TXPOWER: + res = rf_get_tx_power(ieee_radio.rf_handle, rf_tx_power_table, (int8_t *)&value); + return ((res == RF_RESULT_OK) && + (*value != RF_TxPowerTable_INVALID_DBM)) + ? RADIO_RESULT_OK + : RADIO_RESULT_ERROR; + + /* CCA threshold */ + case RADIO_PARAM_CCA_THRESHOLD: + *value = cmd_rx.ccaRssiThr; + return RADIO_RESULT_OK; + + /* RSSI */ + case RADIO_PARAM_RSSI: + *value = RF_getRssi(ieee_radio.rf_handle); + return (*value == RF_GET_RSSI_ERROR_VAL) + ? RADIO_RESULT_ERROR + : RADIO_RESULT_OK; + + /* Channel min */ + case RADIO_CONST_CHANNEL_MIN: + *value = (radio_value_t)DOT_15_4G_CHAN_MIN; + return RADIO_RESULT_OK; + + /* Channel max */ + case RADIO_CONST_CHANNEL_MAX: + *value = (radio_value_t)DOT_15_4G_CHAN_MAX; + return RADIO_RESULT_OK; + + case RADIO_CONST_TXPOWER_MIN: + *value = (radio_value_t)tx_power_min(rf_tx_power_table); + return RADIO_RESULT_OK; + + /* TX power max */ + case RADIO_CONST_TXPOWER_MAX: + *value = (radio_value_t)tx_power_max(rf_tx_power_table, rf_tx_power_table_size); + return RADIO_RESULT_OK; + + /* Last RSSI */ + case RADIO_PARAM_LAST_RSSI: + *value = (radio_value_t)ieee_radio.last.rssi; + return RADIO_RESULT_OK; + + /* Last link quality */ + case RADIO_PARAM_LAST_LINK_QUALITY: + *value = (radio_value_t)ieee_radio.last.corr_lqi; + return RADIO_RESULT_OK; + + default: + return RADIO_RESULT_NOT_SUPPORTED; + } +} +/*---------------------------------------------------------------------------*/ +static radio_result_t +set_value(radio_param_t param, radio_value_t value) +{ + rf_result_t res; + + switch(param) { + + /* Power Mode */ + case RADIO_PARAM_POWER_MODE: + + if(value == RADIO_POWER_MODE_ON) { + return (on() == RF_RESULT_OK) + ? RADIO_RESULT_OK + : RADIO_RESULT_ERROR; + } else if(value == RADIO_POWER_MODE_OFF) { + off(); + return RADIO_RESULT_OK; + } + + return RADIO_RESULT_INVALID_VALUE; + + /* Channel */ + case RADIO_PARAM_CHANNEL: + if(!dot_15_4g_chan_in_range(value)) { + return RADIO_RESULT_INVALID_VALUE; + } + set_channel((uint8_t)value); + return RADIO_RESULT_OK; + + /* PAN ID */ + case RADIO_PARAM_PAN_ID: + cmd_rx.localPanID = (uint16_t)value; + if(!ieee_radio.rf_is_on) { + return RADIO_RESULT_OK; + } + + netstack_stop_rx(); + res = netstack_sched_rx(false); + return (res == RF_RESULT_OK) + ? RADIO_RESULT_OK + : RADIO_RESULT_ERROR; + + /* 16bit address */ + case RADIO_PARAM_16BIT_ADDR: + cmd_rx.localShortAddr = (uint16_t)value; + if(!ieee_radio.rf_is_on) { + return RADIO_RESULT_OK; + } + + netstack_stop_rx(); + res = netstack_sched_rx(false); + return (res == RF_RESULT_OK) + ? RADIO_RESULT_OK + : RADIO_RESULT_ERROR; + + /* RX Mode */ + case RADIO_PARAM_RX_MODE: { + if(value & ~(RADIO_RX_MODE_ADDRESS_FILTER | + RADIO_RX_MODE_AUTOACK | + RADIO_RX_MODE_POLL_MODE)) { + return RADIO_RESULT_INVALID_VALUE; + } + + cmd_rx.frameFiltOpt.frameFiltEn = (value & RADIO_RX_MODE_ADDRESS_FILTER) != 0; + cmd_rx.frameFiltOpt.frameFiltStop = 1; + cmd_rx.frameFiltOpt.autoAckEn = (value & RADIO_RX_MODE_AUTOACK) != 0; + cmd_rx.frameFiltOpt.slottedAckEn = 0; + cmd_rx.frameFiltOpt.autoPendEn = 0; + cmd_rx.frameFiltOpt.defaultPend = 0; + cmd_rx.frameFiltOpt.bPendDataReqOnly = 0; + cmd_rx.frameFiltOpt.bPanCoord = 0; + cmd_rx.frameFiltOpt.bStrictLenFilter = 0; + + const bool old_poll_mode = ieee_radio.poll_mode; + ieee_radio.poll_mode = (value & RADIO_RX_MODE_POLL_MODE) != 0; + if(old_poll_mode == ieee_radio.poll_mode) { + /* Do not turn the radio off and on, just send an update command */ + memcpy(&cmd_mod_filt.newFrameFiltOpt, &(rf_cmd_ieee_rx.frameFiltOpt), sizeof(rf_cmd_ieee_rx.frameFiltOpt)); + const RF_Stat stat = RF_runImmediateCmd(ieee_radio.rf_handle, (uint32_t *)&cmd_mod_filt); + if(stat != RF_StatCmdDoneSuccess) { + LOG_ERR("Setting address filter failed, stat=0x%02X\n", stat); + return RADIO_RESULT_ERROR; + } + return RADIO_RESULT_OK; + } + if(!ieee_radio.rf_is_on) { + return RADIO_RESULT_OK; + } + + netstack_stop_rx(); + res = netstack_sched_rx(false); + return (res == RF_RESULT_OK) + ? RADIO_RESULT_OK + : RADIO_RESULT_ERROR; + } + + /* TX Mode */ + case RADIO_PARAM_TX_MODE: + if(value & ~(RADIO_TX_MODE_SEND_ON_CCA)) { + return RADIO_RESULT_INVALID_VALUE; + } + set_send_on_cca((value & RADIO_TX_MODE_SEND_ON_CCA) != 0); + return RADIO_RESULT_OK; + + /* TX Power */ + case RADIO_PARAM_TXPOWER: + if(!tx_power_in_range((int8_t)value, rf_tx_power_table, rf_tx_power_table_size)) { + return RADIO_RESULT_INVALID_VALUE; + } + res = rf_set_tx_power(ieee_radio.rf_handle, rf_tx_power_table, (int8_t)value); + return (res == RF_RESULT_OK) + ? RADIO_RESULT_OK + : RADIO_RESULT_ERROR; + + /* CCA Threshold */ + case RADIO_PARAM_CCA_THRESHOLD: + cmd_rx.ccaRssiThr = (int8_t)value; + if(!ieee_radio.rf_is_on) { + return RADIO_RESULT_OK; + } + + netstack_stop_rx(); + res = netstack_sched_rx(false); + return (res == RF_RESULT_OK) + ? RADIO_RESULT_OK + : RADIO_RESULT_ERROR; + + default: + return RADIO_RESULT_NOT_SUPPORTED; + } +} +/*---------------------------------------------------------------------------*/ +static radio_result_t +get_object(radio_param_t param, void *dest, size_t size) +{ + if(!dest) { + return RADIO_RESULT_INVALID_VALUE; + } + + switch(param) { + /* 64bit address */ + case RADIO_PARAM_64BIT_ADDR: { + const size_t srcSize = sizeof(cmd_rx.localExtAddr); + if(size != srcSize) { + return RADIO_RESULT_INVALID_VALUE; + } + + const uint8_t *pSrc = (uint8_t *)&(cmd_rx.localExtAddr); + uint8_t *pDest = dest; + for(size_t i = 0; i < srcSize; ++i) { + pDest[i] = pSrc[srcSize - 1 - i]; + } + + return RADIO_RESULT_OK; + } + /* Last packet timestamp */ + case RADIO_PARAM_LAST_PACKET_TIMESTAMP: + if(size != sizeof(rtimer_clock_t)) { + return RADIO_RESULT_INVALID_VALUE; + } + + *(rtimer_clock_t *)dest = ieee_radio.last.timestamp; + + return RADIO_RESULT_OK; + + default: + return RADIO_RESULT_NOT_SUPPORTED; + } +} +/*---------------------------------------------------------------------------*/ +static radio_result_t +set_object(radio_param_t param, const void *src, size_t size) +{ + rf_result_t res; + + if(!src) { + return RADIO_RESULT_INVALID_VALUE; + } + + switch(param) { + /* 64-bit address */ + case RADIO_PARAM_64BIT_ADDR: { + const size_t destSize = sizeof(cmd_rx.localExtAddr); + if(size != destSize) { + return RADIO_RESULT_INVALID_VALUE; + } + + const uint8_t *pSrc = (const uint8_t *)src; + volatile uint8_t *pDest = (uint8_t *)&(cmd_rx.localExtAddr); + for(size_t i = 0; i < destSize; ++i) { + pDest[i] = pSrc[destSize - 1 - i]; + } + + if(!rx_is_active()) { + return RADIO_RESULT_OK; + } + + netstack_stop_rx(); + res = netstack_sched_rx(false); + return (res == RF_RESULT_OK) + ? RADIO_RESULT_OK + : RADIO_RESULT_ERROR; + } + default: + return RADIO_RESULT_NOT_SUPPORTED; + } +} +/*---------------------------------------------------------------------------*/ +const struct radio_driver ieee_mode_driver = { + init, + prepare, + transmit, + send, + read, + channel_clear, + receiving_packet, + pending_packet, + on, + off, + get_value, + set_value, + get_object, + set_object, +}; +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/prop-mode.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf/prop-mode.c new file mode 100644 index 000000000..a100f262a --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/prop-mode.c @@ -0,0 +1,713 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-rf + * @{ + * + * \defgroup cc13xx-cc26xx-rf-prop Prop-mode driver for CC13xx/CC26xx + * + * @{ + * + * \file + * Implementation of the CC13xx/CC26xx prop-mode NETSTACK_RADIO driver. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "net/packetbuf.h" +#include "net/netstack.h" +#include "sys/energest.h" +#include "sys/clock.h" +#include "sys/rtimer.h" +#include "sys/cc.h" +#include "dev/watchdog.h" +/*---------------------------------------------------------------------------*/ +/* RF Core Mailbox API */ +#include +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_data_entry.h) +#include DeviceFamily_constructPath(driverlib/rf_prop_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_prop_mailbox.h) + +#include +/*---------------------------------------------------------------------------*/ +/* Platform RF dev */ +#include "rf/dot-15-4g.h" +#include "rf/sched.h" +#include "rf/data-queue.h" +#include "rf/tx-power.h" +#include "rf/settings.h" +/*---------------------------------------------------------------------------*/ +#include +#include +#include +#include +#include +/*---------------------------------------------------------------------------*/ +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "Radio" +#define LOG_LEVEL LOG_LEVEL_NONE +/*---------------------------------------------------------------------------*/ +#undef CLAMP +#define CLAMP(v, vmin, vmax) (MAX(MIN(v, vmax), vmin)) +/*---------------------------------------------------------------------------*/ +/* Configuration parameters */ +#define PROP_MODE_DYN_WHITENER PROP_MODE_CONF_DW +#define PROP_MODE_USE_CRC16 PROP_MODE_CONF_USE_CRC16 +#define PROP_MODE_CENTER_FREQ PROP_MODE_CONF_CENTER_FREQ +#define PROP_MODE_LO_DIVIDER PROP_MODE_CONF_LO_DIVIDER +#define PROP_MODE_CCA_RSSI_THRESHOLD PROP_MODE_CONF_CCA_RSSI_THRESHOLD +/*---------------------------------------------------------------------------*/ +/* Used for checking result of CCA_REQ command */ +typedef enum { + CCA_STATE_IDLE = 0, + CCA_STATE_BUSY = 1, + CCA_STATE_INVALID = 2 +} cca_state_t; +/*---------------------------------------------------------------------------*/ +/* Defines and variables related to the .15.4g PHY HDR */ +#define DOT_4G_MAX_FRAME_LEN 2047 +#define DOT_4G_PHR_LEN 2 + +/* PHY HDR bits */ +#define DOT_4G_PHR_CRC16 0x10 +#define DOT_4G_PHR_DW 0x08 + +#if PROP_MODE_USE_CRC16 +/* CRC16 */ +#define DOT_4G_PHR_CRC_BIT DOT_4G_PHR_CRC16 +#define CRC_LEN 2 +#else +/* CRC32 */ +#define DOT_4G_PHR_CRC_BIT 0 +#define CRC_LEN 4 +#endif /* PROP_MODE_USE_CRC16 */ + +#if PROP_MODE_DYN_WHITENER +#define DOT_4G_PHR_DW_BIT DOT_4G_PHR_DW +#else +#define DOT_4G_PHR_DW_BIT 0 +#endif +/*---------------------------------------------------------------------------*/ +/* How long to wait for the RF to enter RX in rf_cmd_ieee_rx */ +#define TIMEOUT_ENTER_RX_WAIT (RTIMER_SECOND >> 10) + +/* How long to wait for the rx read entry to become ready */ +#define TIMEOUT_DATA_ENTRY_BUSY (RTIMER_SECOND / 250) +/*---------------------------------------------------------------------------*/ +/* TX buf configuration */ +#define TX_BUF_HDR_LEN 2 +#define TX_BUF_PAYLOAD_LEN 180 + +#define TX_BUF_SIZE (TX_BUF_HDR_LEN + TX_BUF_PAYLOAD_LEN) +/*---------------------------------------------------------------------------*/ +/* Size of the Length field in Data Entry, two bytes in this case */ +typedef uint16_t lensz_t; + +#define FRAME_OFFSET sizeof(lensz_t) +#define FRAME_SHAVE 2 /**< RSSI (1) + Status (1) */ +/*---------------------------------------------------------------------------*/ +/* Constants used when calculating the LQI from the RSSI */ +#define RX_SENSITIVITY_DBM -110 +#define RX_SATURATION_DBM 10 +#define ED_MIN_DBM_ABOVE_RX_SENSITIVITY 10 +#define ED_MAX 0xFF + +#define ED_RF_POWER_MIN_DBM (RX_SENSITIVITY_DBM + ED_MIN_DBM_ABOVE_RX_SENSITIVITY) +#define ED_RF_POWER_MAX_DBM RX_SATURATION_DBM +/*---------------------------------------------------------------------------*/ +/* RF Core typedefs */ +typedef rfc_propRxOutput_t rx_output_t; + +typedef struct { + /* Outgoing frame buffer */ + uint8_t tx_buf[TX_BUF_SIZE] CC_ALIGN(4); + + /* RX Statistics struct */ + rx_output_t rx_stats; + + /* RSSI Threshold */ + int8_t rssi_threshold; + uint16_t channel; + + /* Indicates RF is supposed to be on or off */ + uint8_t rf_is_on; + + /* RF driver */ + RF_Handle rf_handle; +} prop_radio_t; + +static prop_radio_t prop_radio; +/*---------------------------------------------------------------------------*/ +/* Convenience macros for volatile access with the RF commands */ +#define cmd_radio_setup (*(volatile rfc_CMD_PROP_RADIO_DIV_SETUP_t *)&rf_cmd_prop_radio_div_setup) +#define cmd_fs (*(volatile rfc_CMD_FS_t *) &rf_cmd_prop_fs) +#define cmd_tx (*(volatile rfc_CMD_PROP_TX_ADV_t *) &rf_cmd_prop_tx_adv) +#define cmd_rx (*(volatile rfc_CMD_PROP_RX_ADV_t *) &rf_cmd_prop_rx_adv) +/*---------------------------------------------------------------------------*/ +static inline bool +tx_is_active(void) +{ + return cmd_tx.status == ACTIVE; +} +/*---------------------------------------------------------------------------*/ +static inline bool +rx_is_active(void) +{ + return cmd_rx.status == ACTIVE; +} +/*---------------------------------------------------------------------------*/ +static int on(void); +static int off(void); +/*---------------------------------------------------------------------------*/ +static void +init_rf_params(void) +{ + cmd_radio_setup.centerFreq = PROP_MODE_CENTER_FREQ; + cmd_radio_setup.loDivider = PROP_MODE_LO_DIVIDER; + + data_queue_t *data_queue = data_queue_init(sizeof(lensz_t)); + + cmd_rx.maxPktLen = DOT_4G_MAX_FRAME_LEN - cmd_rx.lenOffset; + cmd_rx.pQueue = data_queue; + cmd_rx.pOutput = (uint8_t *)&prop_radio.rx_stats; +} +/*---------------------------------------------------------------------------*/ +static int8_t +get_rssi(void) +{ + rf_result_t res; + + const bool rx_is_idle = !rx_is_active(); + + if(rx_is_idle) { + res = netstack_sched_rx(false); + if(res != RF_RESULT_OK) { + return RF_GET_RSSI_ERROR_VAL; + } + } + + const rtimer_clock_t t0 = RTIMER_NOW(); + while((cmd_rx.status != ACTIVE) && + RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + TIMEOUT_ENTER_RX_WAIT)) ; + + int8_t rssi = RF_GET_RSSI_ERROR_VAL; + if(rx_is_active()) { + rssi = RF_getRssi(prop_radio.rf_handle); + } + + if(rx_is_idle) { + netstack_stop_rx(); + } + + return rssi; +} +/*---------------------------------------------------------------------------*/ +static uint8_t +get_channel(void) +{ + uint32_t freq_khz = cmd_fs.frequency * 1000; + + /* + * For some channels, fractFreq * 1000 / 65536 will return 324.99xx. + * Casting the result to uint32_t will truncate decimals resulting in the + * function returning channel - 1 instead of channel. Thus, we do a quick + * positive integer round up. + */ + freq_khz += (((cmd_fs.fractFreq * 1000) + 65535) / 65536); + + return (uint8_t)((freq_khz - DOT_15_4G_CHAN0_FREQ) / DOT_15_4G_FREQ_SPACING); +} +/*---------------------------------------------------------------------------*/ +static rf_result_t +set_channel(uint16_t channel) +{ + rf_result_t res; + + if(!dot_15_4g_chan_in_range(channel)) { + LOG_WARN("Supplied hannel %d is illegal, defaults to %d\n", + (int)channel, DOT_15_4G_DEFAULT_CHAN); + channel = DOT_15_4G_DEFAULT_CHAN; + } + + if(channel == prop_radio.channel) { + /* We are already calibrated to this channel */ + return RF_RESULT_OK; + } + + const uint32_t new_freq = dot_15_4g_freq(channel); + const uint16_t freq = (uint16_t)(new_freq / 1000); + const uint16_t frac = (uint16_t)(((new_freq - (freq * 1000)) * 0x10000) / 1000); + + LOG_DBG("Set channel to %d, frequency 0x%04X.0x%04X (%lu)\n", + (int)channel, freq, frac, new_freq); + + cmd_fs.frequency = freq; + cmd_fs.fractFreq = frac; + + res = netstack_sched_fs(); + + if(res != RF_RESULT_OK) { + return res; + } + + prop_radio.channel = channel; + return RF_RESULT_OK; +} +/*---------------------------------------------------------------------------*/ +static uint8_t +calculate_lqi(int8_t rssi) +{ + /* + * Note : Currently the LQI value is simply the energy detect measurement. + * A more accurate value could be derived by using the correlation + * value along with the RSSI value. + */ + rssi = CLAMP(rssi, ED_RF_POWER_MIN_DBM, ED_RF_POWER_MAX_DBM); + + /* + * Create energy detect measurement by normalizing and scaling RF power level. + * Note : The division operation below is designed for maximum accuracy and + * best granularity. This is done by grouping the math operations to + * compute the entire numerator before doing any division. + */ + return (ED_MAX * (rssi - ED_RF_POWER_MIN_DBM)) / (ED_RF_POWER_MAX_DBM - ED_RF_POWER_MIN_DBM); +} +/*---------------------------------------------------------------------------*/ +static int +prepare(const void *payload, unsigned short payload_len) +{ + const size_t len = MIN((size_t)payload_len, + (size_t)TX_BUF_PAYLOAD_LEN); + + memcpy(prop_radio.tx_buf + TX_BUF_HDR_LEN, payload, len); + return 0; +} +/*---------------------------------------------------------------------------*/ +static int +transmit(unsigned short transmit_len) +{ + rf_result_t res; + + if(tx_is_active()) { + LOG_ERR("A transmission is already active\n"); + return RADIO_TX_ERR; + } + + /* Length in .15.4g PHY HDR. Includes the CRC but not the HDR itself */ + const uint16_t total_length = transmit_len + CRC_LEN; + /* + * Prepare the .15.4g PHY header + * MS=0, Length MSBits=0, DW and CRC configurable + * Total length = transmit_len (payload) + CRC length + * + * The Radio will flip the bits around, so tx_buf[0] must have the length + * LSBs (PHR[15:8] and tx_buf[1] will have PHR[7:0] + */ + prop_radio.tx_buf[0] = ((total_length >> 0) & 0xFF); + prop_radio.tx_buf[1] = ((total_length >> 8) & 0xFF) + DOT_4G_PHR_DW_BIT + DOT_4G_PHR_CRC_BIT; + + /* pktLen: Total number of bytes in the TX buffer, including the header if + * one exists, but not including the CRC (which is not present in the buffer) */ + cmd_tx.pktLen = transmit_len + DOT_4G_PHR_LEN; + cmd_tx.pPkt = prop_radio.tx_buf; + + res = netstack_sched_prop_tx(); + + return (res == RF_RESULT_OK) + ? RADIO_TX_OK + : RADIO_TX_ERR; +} +/*---------------------------------------------------------------------------*/ +static int +send(const void *payload, unsigned short payload_len) +{ + prepare(payload, payload_len); + return transmit(payload_len); +} +/*---------------------------------------------------------------------------*/ +static int +read(void *buf, unsigned short buf_len) +{ + volatile data_entry_t *data_entry = data_queue_current_entry(); + + const rtimer_clock_t t0 = RTIMER_NOW(); + /* Only wait if the Radio is accessing the entry */ + while((data_entry->status == DATA_ENTRY_BUSY) && + RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + TIMEOUT_DATA_ENTRY_BUSY)) ; + + if(data_entry->status != DATA_ENTRY_FINISHED) { + /* No available data */ + return -1; + } + + /* + * lensz bytes (2) in the data entry are the length of the received frame. + * Data frame is on the following format: + * Length (2) + Payload (N) + RSSI (1) + Status (1) + * Data frame DOES NOT contain the following: + * no Header/PHY bytes + * no appended Received CRC bytes + * no Timestamp bytes + * Visual representation of frame format: + * + * +---------+---------+--------+--------+ + * | 2 bytes | N bytes | 1 byte | 1 byte | + * +---------+---------+--------+--------+ + * | Length | Payload | RSSI | Status | + * +---------+---------+--------+--------+ + * + * Length bytes equal total length of entire frame excluding itself, + * Length = N + RSSI (1) + Status (1) + * = N + 2 + * N = Length - 2 + */ + uint8_t *const frame_ptr = (uint8_t *)&data_entry->data; + const lensz_t frame_len = *(lensz_t *)frame_ptr; + + /* Sanity check that Frame is at least Frame Shave bytes long */ + if(frame_len < FRAME_SHAVE) { + LOG_ERR("Received rame is too short, len=%d\n", frame_len); + + data_queue_release_entry(); + return 0; + } + + const uint8_t *payload_ptr = frame_ptr + sizeof(lensz_t); + const unsigned short payload_len = (unsigned short)(frame_len - FRAME_SHAVE); + + /* Sanity check that Payload fits in Buffer */ + if(payload_len > buf_len) { + LOG_ERR("Payload of received frame is too large for local buffer, len=%d buf_len=%d\n", + payload_len, buf_len); + + data_queue_release_entry(); + return 0; + } + + memcpy(buf, payload_ptr, payload_len); + + /* RSSI stored after payload */ + const int8_t rssi = (int8_t)payload_ptr[payload_len]; + /* LQI calculated from RSSI */ + const uint8_t lqi = calculate_lqi(rssi); + + packetbuf_set_attr(PACKETBUF_ATTR_RSSI, (packetbuf_attr_t)rssi); + packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, (packetbuf_attr_t)lqi); + + data_queue_release_entry(); + return (int)payload_len; +} +/*---------------------------------------------------------------------------*/ +static uint8_t +cca_request(void) +{ + const int8_t rssi = get_rssi(); + + if(rssi == RF_GET_RSSI_ERROR_VAL) { + return CCA_STATE_INVALID; + } + + return (rssi < prop_radio.rssi_threshold) + ? CCA_STATE_IDLE + : CCA_STATE_BUSY; +} +/*---------------------------------------------------------------------------*/ +static int +channel_clear(void) +{ + if(tx_is_active()) { + LOG_ERR("Channel clear called while in TX\n"); + return 0; + } + + const uint8_t cca_state = cca_request(); + + /* Channel is clear if CCA state is IDLE */ + return cca_state == CCA_STATE_IDLE; +} +/*---------------------------------------------------------------------------*/ +static int +receiving_packet(void) +{ + if(!rx_is_active()) { + return 0; + } + + const uint8_t cca_state = cca_request(); + + return cca_state == CCA_STATE_BUSY; +} +/*---------------------------------------------------------------------------*/ +static int +pending_packet(void) +{ + const data_entry_t *const read_entry = data_queue_current_entry(); + volatile const data_entry_t *curr_entry = read_entry; + + int num_pending = 0; + + /* Go through RX Circular buffer and check their status */ + do { + const uint8_t status = curr_entry->status; + if((status == DATA_ENTRY_FINISHED) || + (status == DATA_ENTRY_BUSY)) { + num_pending += 1; + } + + /* Stop when we have looped the circular buffer */ + curr_entry = (data_entry_t *)curr_entry->pNextEntry; + } while(curr_entry != read_entry); + + if(num_pending > 0) { + process_poll(&rf_sched_process); + } + + /* If we didn't find an entry at status finished, no frames are pending */ + return num_pending; +} +/*---------------------------------------------------------------------------*/ +static int +on(void) +{ + rf_result_t res; + + if(prop_radio.rf_is_on) { + LOG_WARN("Radio is already on\n"); + return RF_RESULT_OK; + } + + data_queue_reset(); + + res = netstack_sched_rx(true); + + if(res != RF_RESULT_OK) { + return RF_RESULT_ERROR; + } + + prop_radio.rf_is_on = true; + return RF_RESULT_OK; +} +/*---------------------------------------------------------------------------*/ +static int +off(void) +{ + if(!prop_radio.rf_is_on) { + LOG_WARN("Radio is already off\n"); + return RF_RESULT_OK; + } + + rf_yield(); + + prop_radio.rf_is_on = false; + return RF_RESULT_OK; +} +/*---------------------------------------------------------------------------*/ +static radio_result_t +get_value(radio_param_t param, radio_value_t *value) +{ + rf_result_t res; + + if(!value) { + return RADIO_RESULT_INVALID_VALUE; + } + + switch(param) { + case RADIO_PARAM_POWER_MODE: + /* On / off */ + *value = (prop_radio.rf_is_on) + ? RADIO_POWER_MODE_ON + : RADIO_POWER_MODE_OFF; + + return RADIO_RESULT_OK; + + case RADIO_PARAM_CHANNEL: + *value = (radio_value_t)get_channel(); + return RADIO_RESULT_OK; + + case RADIO_PARAM_TXPOWER: + res = rf_get_tx_power(prop_radio.rf_handle, rf_tx_power_table, (int8_t *)&value); + return ((res == RF_RESULT_OK) && + (*value != RF_TxPowerTable_INVALID_DBM)) + ? RADIO_RESULT_OK + : RADIO_RESULT_ERROR; + + case RADIO_PARAM_CCA_THRESHOLD: + *value = prop_radio.rssi_threshold; + return RADIO_RESULT_OK; + + case RADIO_PARAM_RSSI: + *value = get_rssi(); + return (*value == RF_GET_RSSI_ERROR_VAL) + ? RADIO_RESULT_ERROR + : RADIO_RESULT_OK; + + case RADIO_CONST_CHANNEL_MIN: + *value = DOT_15_4G_CHAN_MIN; + return RADIO_RESULT_OK; + + case RADIO_CONST_CHANNEL_MAX: + *value = DOT_15_4G_CHAN_MAX; + return RADIO_RESULT_OK; + + case RADIO_CONST_TXPOWER_MIN: + *value = (radio_value_t)tx_power_min(rf_tx_power_table); + return RADIO_RESULT_OK; + + case RADIO_CONST_TXPOWER_MAX: + *value = (radio_value_t)tx_power_max(rf_tx_power_table, rf_tx_power_table_size); + return RADIO_RESULT_OK; + + default: + return RADIO_RESULT_NOT_SUPPORTED; + } +} +/*---------------------------------------------------------------------------*/ +static radio_result_t +set_value(radio_param_t param, radio_value_t value) +{ + rf_result_t res; + + switch(param) { + case RADIO_PARAM_POWER_MODE: + + if(value == RADIO_POWER_MODE_ON) { + return (on() == RF_RESULT_OK) + ? RADIO_RESULT_OK + : RADIO_RESULT_ERROR; + } else if(value == RADIO_POWER_MODE_OFF) { + off(); + return RADIO_RESULT_OK; + } + + return RADIO_RESULT_INVALID_VALUE; + + case RADIO_PARAM_CHANNEL: + res = set_channel((uint16_t)value); + return (res == RF_RESULT_OK) + ? RADIO_RESULT_OK + : RADIO_RESULT_ERROR; + + case RADIO_PARAM_TXPOWER: + if(!tx_power_in_range((int8_t)value, rf_tx_power_table, rf_tx_power_table_size)) { + return RADIO_RESULT_INVALID_VALUE; + } + res = rf_set_tx_power(prop_radio.rf_handle, rf_tx_power_table, (int8_t)value); + return (res == RF_RESULT_OK) + ? RADIO_RESULT_OK + : RADIO_RESULT_ERROR; + + case RADIO_PARAM_RX_MODE: + return RADIO_RESULT_OK; + + case RADIO_PARAM_CCA_THRESHOLD: + prop_radio.rssi_threshold = (int8_t)value; + return RADIO_RESULT_OK; + + default: + return RADIO_RESULT_NOT_SUPPORTED; + } +} +/*---------------------------------------------------------------------------*/ +static radio_result_t +get_object(radio_param_t param, void *dest, size_t size) +{ + return RADIO_RESULT_NOT_SUPPORTED; +} +/*---------------------------------------------------------------------------*/ +static radio_result_t +set_object(radio_param_t param, const void *src, size_t size) +{ + return RADIO_RESULT_NOT_SUPPORTED; +} +/*---------------------------------------------------------------------------*/ +static int +init(void) +{ + if(prop_radio.rf_handle) { + LOG_WARN("Radio is already initialized\n"); + return RF_RESULT_OK; + } + + /* RX is off */ + prop_radio.rf_is_on = false; + + /* Set configured RSSI threshold */ + prop_radio.rssi_threshold = PROP_MODE_CCA_RSSI_THRESHOLD; + + init_rf_params(); + + /* Init RF params and specify non-default params */ + RF_Params rf_params; + RF_Params_init(&rf_params); + rf_params.nInactivityTimeout = RF_CONF_INACTIVITY_TIMEOUT; + + /* Open RF Driver */ + prop_radio.rf_handle = netstack_open(&rf_params); + + if(prop_radio.rf_handle == NULL) { + LOG_ERR("Unable to open RF driver during initialization\n"); + return RF_RESULT_ERROR; + } + + set_channel(IEEE802154_DEFAULT_CHANNEL); + + ENERGEST_ON(ENERGEST_TYPE_LISTEN); + + /* Start RF process */ + process_start(&rf_sched_process, NULL); + + return RF_RESULT_OK; +} +/*---------------------------------------------------------------------------*/ +const struct radio_driver prop_mode_driver = { + init, + prepare, + transmit, + send, + read, + channel_clear, + receiving_packet, + pending_packet, + on, + off, + get_value, + set_value, + get_object, + set_object, +}; +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/rf.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf/rf.h new file mode 100644 index 000000000..cfc6b2277 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/rf.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-cpu + * @{ + * + * \defgroup cc13xx-cc26xx-rf RF specific files for CC13xx/CC26xx + * + * @{ + * + * \file + * Header file of common CC13xx/CC26xx RF functionality. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#ifndef RF_CORE_H_ +#define RF_CORE_H_ +/*---------------------------------------------------------------------------*/ +/** + * \name Different modes the RF can operate on, denoted by which frequency + * band said mode operates on. Currently supports the following modes: + * - Sub-1 GHz, called prop-mode + * - 2.4 GHz, called ieee-mode + * + * @{ + */ +#define RF_MODE_SUB_1_GHZ (1 << 0) +#define RF_MODE_2_4_GHZ (1 << 1) + +/* Bitmask of supported RF modes */ +#define RF_MODE_BM (RF_MODE_SUB_1_GHZ | \ + RF_MODE_2_4_GHZ) +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* RF_CORE_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/sched.c b/arch/cpu/simplelink-cc13xx-cc26xx/rf/sched.c new file mode 100644 index 000000000..44387c138 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/sched.c @@ -0,0 +1,590 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-rf-sched + * @{ + * + * \file + * Implementation of the CC13xx/CC26xx RF scheduler. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/watchdog.h" +#include "sys/cc.h" +#include "sys/etimer.h" +#include "sys/process.h" +#include "sys/energest.h" +#include "net/netstack.h" +#include "net/packetbuf.h" +#include "net/mac/mac.h" +#include "lib/random.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) + +#include +/*---------------------------------------------------------------------------*/ +#include "rf/rf.h" +#include "rf/sched.h" +#include "rf/data-queue.h" +#include "rf/settings.h" +/*---------------------------------------------------------------------------*/ +#include +#include +#include +/*---------------------------------------------------------------------------*/ +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "Radio" +#define LOG_LEVEL LOG_LEVEL_NONE +/*---------------------------------------------------------------------------*/ +/* Configuration parameters */ +/*---------------------------------------------------------------------------*/ +#define CMD_FS_RETRIES 3 + +#define RF_EVENTS_CMD_DONE (RF_EventCmdDone | RF_EventLastCmdDone | \ + RF_EventFGCmdDone | RF_EventLastFGCmdDone) + +#define CMD_STATUS(cmd) (CC_ACCESS_NOW(RF_Op, cmd).status) + +#define CMD_HANDLE_OK(handle) (((handle) != RF_ALLOC_ERROR) && \ + ((handle) != RF_SCHEDULE_CMD_ERROR)) + +#define EVENTS_CMD_DONE(events) (((events) & RF_EVENTS_CMD_DONE) != 0) +/*---------------------------------------------------------------------------*/ +/* Synth re-calibration every 3 minutes */ +#define SYNTH_RECAL_INTERVAL (CLOCK_SECOND * 60 * 3) +/* Set re-calibration interval with a jitter of 10 seconds */ +#define SYNTH_RECAL_JITTER (CLOCK_SECOND * 10) + +static struct etimer synth_recal_timer; +/*---------------------------------------------------------------------------*/ +static RF_Object rf_netstack; + +#if RF_CONF_BLE_BEACON_ENABLE +static RF_Object rf_ble; +#endif + +static RF_CmdHandle cmd_rx_handle; + +static bool rf_is_on; +static volatile bool rx_buf_full; +/*---------------------------------------------------------------------------*/ +static void +cmd_rx_cb(RF_Handle client, RF_CmdHandle command, RF_EventMask events) +{ + /* Unused arguments */ + (void)client; + (void)command; + + if(events & RF_EventRxEntryDone) { + process_poll(&rf_sched_process); + } + + if(events & RF_EventRxBufFull) { + rx_buf_full = true; + process_poll(&rf_sched_process); + } +} +/*---------------------------------------------------------------------------*/ +static inline clock_time_t +synth_recal_interval(void) +{ + /* + * Add jitter centered around SYNTH_RECAL_INTERVAL, giving a plus/minus + * jitter seconds halved. + */ + return SYNTH_RECAL_INTERVAL + (random_rand() % SYNTH_RECAL_JITTER) - (SYNTH_RECAL_JITTER / 2); +} +/*---------------------------------------------------------------------------*/ +static inline bool +cmd_rx_is_active(void) +{ + /* + * Active in this case means RX command is either running to be running, + * that is ACTIVE for running or PENDING for to be running. + */ + const uint16_t status = CMD_STATUS(netstack_cmd_rx); + return (status == ACTIVE) || + (status == PENDING); +} +/*---------------------------------------------------------------------------*/ +static uint_fast8_t +cmd_rx_disable(void) +{ + const bool is_active = cmd_rx_is_active(); + + if(is_active) { + CMD_STATUS(netstack_cmd_rx) = DONE_STOPPED; + RF_cancelCmd(&rf_netstack, cmd_rx_handle, RF_ABORT_GRACEFULLY); + cmd_rx_handle = 0; + } + + return (uint_fast8_t)is_active; +} +/*---------------------------------------------------------------------------*/ +static rf_result_t +cmd_rx_restore(uint_fast8_t rx_key) +{ + const bool was_active = (rx_key != 0) ? true : false; + + if(!was_active) { + return RF_RESULT_OK; + } + + RF_ScheduleCmdParams sched_params; + RF_ScheduleCmdParams_init(&sched_params); + + sched_params.priority = RF_PriorityNormal; + sched_params.endTime = 0; + sched_params.allowDelay = RF_AllowDelayAny; + + CMD_STATUS(netstack_cmd_rx) = PENDING; + + cmd_rx_handle = RF_scheduleCmd( + &rf_netstack, + (RF_Op *)&netstack_cmd_rx, + &sched_params, + cmd_rx_cb, + RF_EventRxEntryDone | RF_EventRxBufFull); + + if(!CMD_HANDLE_OK(cmd_rx_handle)) { + LOG_ERR("Unable to restore RX command, handle=%d status=0x%04x", + cmd_rx_handle, CMD_STATUS(netstack_cmd_rx)); + return RF_RESULT_ERROR; + } + + return RF_RESULT_OK; +} +/*---------------------------------------------------------------------------*/ +rf_result_t +rf_yield(void) +{ + /* Force abort of any ongoing RF operation */ + RF_flushCmd(&rf_netstack, RF_CMDHANDLE_FLUSH_ALL, RF_ABORT_GRACEFULLY); +#if RF_CONF_BLE_BEACON_ENABLE + RF_flushCmd(&rf_ble, RF_CMDHANDLE_FLUSH_ALL, RF_ABORT_GRACEFULLY); +#endif + + /* Trigger a manual power-down */ + RF_yield(&rf_netstack); +#if RF_CONF_BLE_BEACON_ENABLE + RF_yield(&rf_ble); +#endif + + ENERGEST_OFF(ENERGEST_TYPE_LISTEN); + + etimer_stop(&synth_recal_timer); + rf_is_on = false; + + return RF_RESULT_OK; +} +/*---------------------------------------------------------------------------*/ +rf_result_t +rf_set_tx_power(RF_Handle handle, RF_TxPowerTable_Entry *table, int8_t dbm) +{ + const RF_Stat stat = RF_setTxPower(handle, RF_TxPowerTable_findValue(table, dbm)); + + return (stat == RF_StatSuccess) + ? RF_RESULT_OK + : RF_RESULT_ERROR; +} +/*---------------------------------------------------------------------------*/ +rf_result_t +rf_get_tx_power(RF_Handle handle, RF_TxPowerTable_Entry *table, int8_t *dbm) +{ + *dbm = RF_TxPowerTable_findPowerLevel(table, RF_getTxPower(handle)); + + return (*dbm != RF_TxPowerTable_INVALID_DBM) + ? RF_RESULT_OK + : RF_RESULT_ERROR; +} +/*---------------------------------------------------------------------------*/ +RF_Handle +netstack_open(RF_Params *params) +{ + return RF_open(&rf_netstack, &netstack_mode, (RF_RadioSetup *)&netstack_cmd_radio_setup, params); +} +/*---------------------------------------------------------------------------*/ +rf_result_t +netstack_sched_fs(void) +{ + const uint_fast8_t rx_key = cmd_rx_disable(); + + /* + * For IEEE-mode, restarting CMD_IEEE_RX re-calibrates the synth by using the + * channel field in the CMD_IEEE_RX command. It is assumed this field is + * already configured before this function is called. However, if + * CMD_IEEE_RX wasn't active, manually calibrate the synth with CMD_FS. + * + * For Prop-mode, the synth is always manually calibrated with CMD_FS. + */ +#if (RF_MODE == RF_CORE_MODE_2_4_GHZ) + if(rx_key) { + cmd_rx_restore(rx_key); + return RF_RESULT_OK; + } +#endif /* RF_MODE == RF_CORE_MODE_2_4_GHZ */ + + RF_EventMask events; + bool synth_error = false; + uint8_t num_tries = 0; + + do { + CMD_STATUS(netstack_cmd_fs) = PENDING; + + events = RF_runCmd( + &rf_netstack, + (RF_Op *)&netstack_cmd_fs, + RF_PriorityNormal, + NULL, + 0); + + synth_error = (EVENTS_CMD_DONE(events)) && (CMD_STATUS(netstack_cmd_fs) == ERROR_SYNTH_PROG); + + } while(synth_error && (num_tries++ < CMD_FS_RETRIES)); + + cmd_rx_restore(rx_key); + + return (CMD_STATUS(netstack_cmd_fs) == DONE_OK) + ? RF_RESULT_OK + : RF_RESULT_ERROR; +} +/*---------------------------------------------------------------------------*/ +rf_result_t +netstack_sched_ieee_tx(bool ack_request) +{ + rf_result_t res; + + RF_ScheduleCmdParams sched_params; + RF_ScheduleCmdParams_init(&sched_params); + + sched_params.priority = RF_PriorityNormal; + sched_params.endTime = 0; + sched_params.allowDelay = RF_AllowDelayAny; + + const bool rx_is_active = cmd_rx_is_active(); + const bool rx_needed = (ack_request && !rx_is_active); + + /* + * If we expect ACK after transmission, RX must be running to be able to + * run the RX_ACK command. Therefore, turn on RX before starting the + * chained TX command. + */ + if(rx_needed) { + res = netstack_sched_rx(false); + if(res != RF_RESULT_OK) { + return res; + } + } + + CMD_STATUS(netstack_cmd_tx) = PENDING; + + RF_CmdHandle tx_handle = RF_scheduleCmd( + &rf_netstack, + (RF_Op *)&netstack_cmd_tx, + &sched_params, + NULL, + 0); + + if(!CMD_HANDLE_OK(tx_handle)) { + LOG_ERR("Unable to schedule TX command, handle=%d status=0x%04x\n", + tx_handle, CMD_STATUS(netstack_cmd_tx)); + return RF_RESULT_ERROR; + } + + if(rx_is_active) { + ENERGEST_SWITCH(ENERGEST_TYPE_LISTEN, ENERGEST_TYPE_TRANSMIT); + } else { + ENERGEST_ON(ENERGEST_TYPE_TRANSMIT); + } + + /* Wait until TX operation finishes */ + RF_EventMask tx_events = RF_pendCmd(&rf_netstack, tx_handle, 0); + + /* Stop RX if it was turned on only for ACK */ + if(rx_needed) { + netstack_stop_rx(); + } + + if(rx_is_active) { + ENERGEST_SWITCH(ENERGEST_TYPE_TRANSMIT, ENERGEST_TYPE_LISTEN); + } else { + ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT); + } + + if(!EVENTS_CMD_DONE(tx_events)) { + LOG_ERR("Pending on TX comand generated error, events=0x%08llx status=0x%04x\n", + tx_events, CMD_STATUS(netstack_cmd_tx)); + return RF_RESULT_ERROR; + } + + return RF_RESULT_OK; +} +/*---------------------------------------------------------------------------*/ +rf_result_t +netstack_sched_prop_tx(void) +{ + RF_ScheduleCmdParams sched_params; + RF_ScheduleCmdParams_init(&sched_params); + + sched_params.priority = RF_PriorityNormal; + sched_params.endTime = 0; + sched_params.allowDelay = RF_AllowDelayAny; + + CMD_STATUS(netstack_cmd_tx) = PENDING; + + RF_CmdHandle tx_handle = RF_scheduleCmd( + &rf_netstack, + (RF_Op *)&netstack_cmd_tx, + &sched_params, + NULL, + 0); + + if(!CMD_HANDLE_OK(tx_handle)) { + LOG_ERR("Unable to schedule TX command, handle=%d status=0x%04x\n", + tx_handle, CMD_STATUS(netstack_cmd_tx)); + return RF_RESULT_ERROR; + } + + /* + * Prop TX requires any on-going RX operation to be stopped to be + * able to transmit. Therefore, disable RX if running. + */ + const bool rx_key = cmd_rx_disable(); + + if(rx_key) { + ENERGEST_SWITCH(ENERGEST_TYPE_LISTEN, ENERGEST_TYPE_TRANSMIT); + } else { + ENERGEST_ON(ENERGEST_TYPE_TRANSMIT); + } + + /* Wait until TX operation finishes */ + RF_EventMask tx_events = RF_pendCmd(&rf_netstack, tx_handle, 0); + + cmd_rx_restore(rx_key); + + if(rx_key) { + ENERGEST_SWITCH(ENERGEST_TYPE_TRANSMIT, ENERGEST_TYPE_LISTEN); + } else { + ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT); + } + + if(!EVENTS_CMD_DONE(tx_events)) { + LOG_ERR("Pending on scheduled TX command generated error, events=0x%08llx status=0x%04x\n", + tx_events, CMD_STATUS(netstack_cmd_tx)); + return RF_RESULT_ERROR; + } + + return RF_RESULT_OK; +} +/*---------------------------------------------------------------------------*/ +rf_result_t +netstack_sched_rx(bool start) +{ + if(cmd_rx_is_active()) { + LOG_WARN("Already in RX when scheduling RX\n"); + return RF_RESULT_OK; + } + + RF_ScheduleCmdParams sched_params; + RF_ScheduleCmdParams_init(&sched_params); + + sched_params.priority = RF_PriorityNormal; + sched_params.endTime = 0; + sched_params.allowDelay = RF_AllowDelayAny; + + CMD_STATUS(netstack_cmd_rx) = PENDING; + + cmd_rx_handle = RF_scheduleCmd( + &rf_netstack, + (RF_Op *)&netstack_cmd_rx, + &sched_params, + cmd_rx_cb, + RF_EventRxEntryDone | RF_EventRxBufFull); + + if(!CMD_HANDLE_OK(cmd_rx_handle)) { + LOG_ERR("Unable to schedule RX command, handle=%d status=0x%04x\n", + cmd_rx_handle, CMD_STATUS(netstack_cmd_rx)); + return RF_RESULT_ERROR; + } + + ENERGEST_ON(ENERGEST_TYPE_LISTEN); + + if(start) { + rf_is_on = true; + process_poll(&rf_sched_process); + } + + return RF_RESULT_OK; +} +/*---------------------------------------------------------------------------*/ +rf_result_t +netstack_stop_rx(void) +{ + if(!cmd_rx_is_active()) { + LOG_WARN("RX not active when stopping RX\n"); + return RF_RESULT_OK; + } + + CMD_STATUS(netstack_cmd_rx) = DONE_STOPPED; + const RF_Stat stat = RF_cancelCmd(&rf_netstack, cmd_rx_handle, RF_ABORT_GRACEFULLY); + cmd_rx_handle = 0; + + ENERGEST_OFF(ENERGEST_TYPE_LISTEN); + + return (stat == RF_StatSuccess) + ? RF_RESULT_OK + : RF_RESULT_ERROR; +} +/*---------------------------------------------------------------------------*/ +RF_Handle +ble_open(RF_Params *params) +{ +#if RF_CONF_BLE_BEACON_ENABLE + return RF_open(&rf_ble, &ble_mode, (RF_RadioSetup *)&ble_cmd_radio_setup, params); + +#else + return (RF_Handle)NULL; +#endif +} +/*---------------------------------------------------------------------------*/ +rf_result_t +ble_sched_beacon(RF_Callback cb, RF_EventMask bm_event) +{ +#if RF_CONF_BLE_BEACON_ENABLE + RF_ScheduleCmdParams sched_params; + RF_ScheduleCmdParams_init(&sched_params); + + sched_params.priority = RF_PriorityNormal; + sched_params.endTime = 0; + sched_params.allowDelay = RF_AllowDelayAny; + + CMD_STATUS(ble_cmd_beacon) = PENDING; + + RF_CmdHandle beacon_handle = RF_scheduleCmd( + &rf_ble, + (RF_Op *)&ble_cmd_beacon, + &sched_params, + cb, + bm_event); + + if(!CMD_HANDLE_OK(beacon_handle)) { + LOG_ERR("Unable to schedule BLE Beacon command, handle=%d status=0x%04x\n", + beacon_handle, CMD_STATUS(ble_cmd_beacon)); + return RF_RESULT_ERROR; + } + + const uint_fast8_t rx_key = cmd_rx_disable(); + + /* Wait until Beacon operation finishes */ + RF_EventMask beacon_events = RF_pendCmd(&rf_ble, beacon_handle, 0); + if(!EVENTS_CMD_DONE(beacon_events)) { + LOG_ERR("Pending on scheduled BLE Beacon command generated error, events=0x%08llx status=0x%04x\n", + beacon_events, CMD_STATUS(ble_cmd_beacon)); + + cmd_rx_restore(rx_key); + return RF_RESULT_ERROR; + } + + cmd_rx_restore(rx_key); + return RF_RESULT_OK; + +#else + return RF_RESULT_ERROR; +#endif +} +/*---------------------------------------------------------------------------*/ +PROCESS(rf_sched_process, "RF Scheduler Process"); +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(rf_sched_process, ev, data) +{ + int len; + + PROCESS_BEGIN(); + + while(1) { + PROCESS_YIELD_UNTIL((ev == PROCESS_EVENT_POLL) || + (ev == PROCESS_EVENT_TIMER)); + + /* start the synth re-calibration timer once. */ + if(rf_is_on) { + rf_is_on = false; + clock_time_t interval = synth_recal_interval(); + LOG_INFO("Starting synth re-calibration timer, next timeout %lu\n", interval); + etimer_set(&synth_recal_timer, interval); + } + + if(ev == PROCESS_EVENT_POLL) { + do { + watchdog_periodic(); + + packetbuf_clear(); + len = NETSTACK_RADIO.read(packetbuf_dataptr(), PACKETBUF_SIZE); + + /* + * RX will stop if the RX buffers are full. In this case, restart + * RX after we've freed at least on packet. + */ + if(rx_buf_full) { + LOG_ERR("RX buffer full, restart RX status=0x%04x\n", CMD_STATUS(netstack_cmd_rx)); + rx_buf_full = false; + + /* Restart RX. */ + netstack_stop_rx(); + netstack_sched_rx(false); + } + + if(len > 0) { + packetbuf_set_datalen(len); + + NETSTACK_MAC.input(); + } + /* Only break when we receive -1 => No available data */ + } while(len >= 0); + } + + /* Scheduling CMD_FS will re-calibrate the synth. */ + if((ev == PROCESS_EVENT_TIMER) && + etimer_expired(&synth_recal_timer)) { + clock_time_t interval = synth_recal_interval(); + LOG_DBG("Re-calibrate synth, next interval %lu\n", interval); + + netstack_sched_fs(); + etimer_set(&synth_recal_timer, interval); + } + } + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/sched.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf/sched.h new file mode 100644 index 000000000..de32dbbd4 --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/sched.h @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-rf + * @{ + * + * \defgroup cc13xx-cc26xx-rf-sched RF Scheduler for CC13xx/CC26xx + * + * @{ + * + * \file + * Header file of the CC13xx/CC26xx RF scheduler. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#ifndef RF_SCHED_H_ +#define RF_SCHED_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "sys/process.h" +/*---------------------------------------------------------------------------*/ +#include +/*---------------------------------------------------------------------------*/ +#include +/*---------------------------------------------------------------------------*/ +PROCESS_NAME(rf_sched_process); +/*---------------------------------------------------------------------------*/ +typedef enum { + RF_RESULT_OK = 0, + RF_RESULT_ERROR, +} rf_result_t; +/*---------------------------------------------------------------------------*/ +/** + * \name Common RF scheduler functionality. + * + * @{ + */ +rf_result_t rf_yield(void); +rf_result_t rf_set_tx_power(RF_Handle handle, RF_TxPowerTable_Entry *table, int8_t dbm); +rf_result_t rf_get_tx_power(RF_Handle handle, RF_TxPowerTable_Entry *table, int8_t *dbm); +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name Nestack Radio scheduler functionality. + * + * Either for Prop-mode or IEEE-mode Radio driver. + * + * @{ + */ +RF_Handle netstack_open(RF_Params *params); +rf_result_t netstack_sched_fs(void); +rf_result_t netstack_sched_ieee_tx(bool ack_request); +rf_result_t netstack_sched_prop_tx(void); +rf_result_t netstack_sched_rx(bool start); +rf_result_t netstack_stop_rx(void); +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name BLE Radio scheduler functionality. + * + * Only for the BLE Beacon Daemon. + * + * @{ + */ +RF_Handle ble_open(RF_Params *params); +rf_result_t ble_sched_beacon(RF_Callback cb, RF_EventMask bm_event); +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* RF_SCHED_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/settings.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf/settings.h new file mode 100644 index 000000000..174114bfb --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/settings.h @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-cpu + * @{ + * + * \defgroup cc13xx-cc26xx-rf-settings RF settings for CC13xx/CC26xx + * + * @{ + * + * \file + * Header file of RF settings for CC13xx/CC26xx. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#ifndef NETSTACK_SETTINGS_H_ +#define NETSTACK_SETTINGS_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +/*---------------------------------------------------------------------------*/ +#include +/*---------------------------------------------------------------------------*/ +/* Netstack RF command configuration */ + +#if SUPPORTS_PROP_MODE +#include "prop-settings.h" +#endif + +#if SUPPORTS_IEEE_MODE +#include "ieee-settings.h" +#endif + +/* Prop-mode RF settings */ +#if (RF_MODE == RF_MODE_SUB_1_GHZ) + +#define netstack_mode rf_prop_mode +#define netstack_cmd_radio_setup rf_cmd_prop_radio_div_setup +#define netstack_cmd_fs rf_cmd_prop_fs +#define netstack_cmd_tx rf_cmd_prop_tx_adv +#define netstack_cmd_rx rf_cmd_prop_rx_adv + +/* IEEE-mode RF settings */ +#elif (RF_MODE == RF_MODE_2_4_GHZ) + +#define netstack_mode rf_ieee_mode +#define netstack_cmd_radio_setup rf_cmd_ieee_radio_setup +#define netstack_cmd_fs rf_cmd_ieee_fs +#define netstack_cmd_tx rf_cmd_ieee_tx +#define netstack_cmd_rx rf_cmd_ieee_rx + +#endif /* RF_MODE */ +/*---------------------------------------------------------------------------*/ +/* BLE Beacon RF command configuration */ +#if SUPPORTS_BLE_BEACON + +#include "ble-settings.h" + +/* CC13x0/CC26x0 devices */ +#if (DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X0_CC26X0) + +#define ble_mode rf_ble_mode +#define ble_cmd_radio_setup rf_ble_cmd_radio_setup +#define ble_adv_par rf_ble_adv_par +#define ble_cmd_beacon rf_ble_cmd_ble_adv_nc + +/* CC13x2/CC26x2 devices */ +#elif (DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X2_CC26X2) + +#define ble_mode rf_ble_mode +#define ble_cmd_radio_setup rf_ble_cmd_radio_setup +#define ble_adv_par rf_ble_adv_par +#define ble_cmd_beacon rf_ble_cmd_ble_adv_nc + +#endif /* DeviceFamily_PARENT */ + +#endif /* SUPPORTS_BLE_BEACON */ +/*---------------------------------------------------------------------------*/ +#endif /* NETSTACK_SETTINGS_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ \ No newline at end of file diff --git a/arch/cpu/simplelink-cc13xx-cc26xx/rf/tx-power.h b/arch/cpu/simplelink-cc13xx-cc26xx/rf/tx-power.h new file mode 100644 index 000000000..91bab7d6b --- /dev/null +++ b/arch/cpu/simplelink-cc13xx-cc26xx/rf/tx-power.h @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-cpu + * @{ + * + * \defgroup cc13xx-cc26xx-rf-tx-power TX power functioanlity for CC13xx/CC26xx + * + * @{ + * + * \file + * Header file of TX power functionality of CC13xx/CC26xx. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#ifndef TX_POWER_H_ +#define TX_POWER_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +/*---------------------------------------------------------------------------*/ +#include +/*---------------------------------------------------------------------------*/ +#include +#include +#include +/*---------------------------------------------------------------------------*/ +#define RF_TXPOWER_HIGH_PA RF_CONF_TXPOWER_HIGH_PA +#define RF_TXPOWER_BOOST_MODE RF_CONF_TXPOWER_BOOST_MODE +/*---------------------------------------------------------------------------*/ +typedef RF_TxPowerTable_Entry tx_power_table_t; +/*---------------------------------------------------------------------------*/ +/** + * \name Extern declarations of TX Power Table variables. + * + * @{ + */ + +/* Nestack RF TX power table */ +extern tx_power_table_t *const rf_tx_power_table; +extern const size_t rf_tx_power_table_size; + +/* BLE Beacon RF TX power table */ +extern tx_power_table_t *const ble_tx_power_table; +extern const size_t ble_tx_power_table_size; +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name TX power table convenience functions. + * + * @{ + */ + +static inline int8_t +tx_power_min(tx_power_table_t *table) +{ + return table[0].power; +} +static inline int8_t +tx_power_max(tx_power_table_t *table, size_t size) +{ + return table[size - 1].power; +} +static inline bool +tx_power_in_range(int8_t dbm, tx_power_table_t *table, size_t size) +{ + return (dbm >= tx_power_min(table)) && + (dbm <= tx_power_max(table, size)); +} +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* TX_POWER_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/dev/cc1200/cc1200-802154g-863-870-fsk-50kbps.c b/arch/dev/cc1200/cc1200-802154g-863-870-fsk-50kbps.c index 0fe452999..ad19b5769 100644 --- a/arch/dev/cc1200/cc1200-802154g-863-870-fsk-50kbps.c +++ b/arch/dev/cc1200/cc1200-802154g-863-870-fsk-50kbps.c @@ -34,6 +34,7 @@ #include "cc1200-rf-cfg.h" #include "cc1200-const.h" +#include "net/mac/tsch/tsch.h" /* * This is a setup for the following configuration: @@ -62,7 +63,53 @@ /*---------------------------------------------------------------------------*/ static const char rf_cfg_descriptor[] = "802.15.4g 863-870MHz MR-FSK mode #1"; /*---------------------------------------------------------------------------*/ -/* + +/* 1 byte time: 160 usec */ +#define CC1200_TSCH_PREAMBLE_LENGTH 800 /* 5 bytes */ +#define CC1200_TSCH_CONF_RX_WAIT 2200 +#define CC1200_TSCH_CONF_RX_ACK_WAIT 400 + +#define CC1200_TSCH_DEFAULT_TS_CCA_OFFSET 1800 +#define CC1200_TSCH_DEFAULT_TS_CCA 128 + +#define CC1200_TSCH_DEFAULT_TS_TX_OFFSET 3800 +#define CC1200_TSCH_DEFAULT_TS_RX_OFFSET (CC1200_TSCH_DEFAULT_TS_TX_OFFSET - CC1200_TSCH_PREAMBLE_LENGTH - (CC1200_TSCH_CONF_RX_WAIT / 2)) +#define CC1200_TSCH_DEFAULT_TS_RX_ACK_DELAY (CC1200_TSCH_DEFAULT_TS_TX_ACK_DELAY - CC1200_TSCH_PREAMBLE_LENGTH - (CC1200_TSCH_CONF_RX_ACK_WAIT / 2)) +#define CC1200_TSCH_DEFAULT_TS_TX_ACK_DELAY 3000 + +#define CC1200_TSCH_DEFAULT_TS_RX_WAIT (CC1200_TSCH_PREAMBLE_LENGTH + CC1200_TSCH_CONF_RX_WAIT) +#define CC1200_TSCH_DEFAULT_TS_ACK_WAIT (CC1200_TSCH_PREAMBLE_LENGTH + CC1200_TSCH_CONF_RX_ACK_WAIT) +#define CC1200_TSCH_DEFAULT_TS_RX_TX 192 +#define CC1200_TSCH_DEFAULT_TS_MAX_ACK 3360 /* 17+1+3 bytes at 50 kbps */ +#define CC1200_TSCH_DEFAULT_TS_MAX_TX 20800 /* 126+1+3 bytes at 50 kbps */ + +#define CC1200_TSCH_DEFAULT_SLACK_TIME 500 +/* Timeslot length: 31460 usec */ +#define CC1200_TSCH_DEFAULT_TS_TIMESLOT_LENGTH \ + ( CC1200_TSCH_DEFAULT_TS_TX_OFFSET \ + + CC1200_TSCH_DEFAULT_TS_MAX_TX \ + + CC1200_TSCH_DEFAULT_TS_TX_ACK_DELAY \ + + CC1200_TSCH_DEFAULT_TS_MAX_ACK \ + + CC1200_TSCH_DEFAULT_SLACK_TIME \ + ) + +/* TSCH timeslot timing (mircoseconds) */ +static const uint16_t cc1200_50kbps_tsch_timing[tsch_ts_elements_count] = { + CC1200_TSCH_DEFAULT_TS_CCA_OFFSET, + CC1200_TSCH_DEFAULT_TS_CCA, + CC1200_TSCH_DEFAULT_TS_TX_OFFSET, + CC1200_TSCH_DEFAULT_TS_RX_OFFSET, + CC1200_TSCH_DEFAULT_TS_RX_ACK_DELAY, + CC1200_TSCH_DEFAULT_TS_TX_ACK_DELAY, + CC1200_TSCH_DEFAULT_TS_RX_WAIT, + CC1200_TSCH_DEFAULT_TS_ACK_WAIT, + CC1200_TSCH_DEFAULT_TS_RX_TX, + CC1200_TSCH_DEFAULT_TS_MAX_ACK, + CC1200_TSCH_DEFAULT_TS_MAX_TX, + CC1200_TSCH_DEFAULT_TS_TIMESLOT_LENGTH, +}; + +/* * Register settings exported from SmartRF Studio using the standard template * "trxEB RF Settings Performance Line". */ @@ -159,6 +206,11 @@ const cc1200_rf_cfg_t cc1200_802154g_863_870_fsk_50kbps = { .size_of_register_settings = sizeof(preferredSettings), .tx_pkt_lifetime = (RTIMER_SECOND / 20), .tx_rx_turnaround = (RTIMER_SECOND / 100), + /* Includes 3 Bytes preamble + 2 Bytes SFD, at 160usec per byte = 800 usec */ + /* Includes time to completion of "Wait for TX to start" if cc1200.c: 397 usec */ + .delay_before_tx = ((unsigned)US_TO_RTIMERTICKS(800 + 397 + 423)), + .delay_before_rx = (unsigned)US_TO_RTIMERTICKS(400), + .delay_before_detect = 0, .chan_center_freq0 = RF_CFG_CHAN_CENTER_F0, .chan_spacing = RF_CFG_CHAN_SPACING, .min_channel = RF_CFG_MIN_CHANNEL, @@ -166,5 +218,7 @@ const cc1200_rf_cfg_t cc1200_802154g_863_870_fsk_50kbps = { .max_txpower = RF_CFG_MAX_TXPOWER, .cca_threshold = RF_CFG_CCA_THRESHOLD, .rssi_offset = RF_CFG_RSSI_OFFSET, + .bitrate = 50000, + .tsch_timing = cc1200_50kbps_tsch_timing, }; /*---------------------------------------------------------------------------*/ diff --git a/arch/dev/cc1200/cc1200-868-4gfsk-1000kbps.c b/arch/dev/cc1200/cc1200-868-4gfsk-1000kbps.c new file mode 100644 index 000000000..29beef6c0 --- /dev/null +++ b/arch/dev/cc1200/cc1200-868-4gfsk-1000kbps.c @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2015, Weptech elektronik GmbH Germany + * http://www.weptech.de + * + * 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. + * + * This file is part of the Contiki operating system. + */ + +#include "cc1200-rf-cfg.h" +#include "cc1200-const.h" +#include "net/mac/tsch/tsch.h" + +/* +* Register settings exported from SmartRF Studio using the standard 1000kpbs 868MHz template + */ + + /* Base frequency in kHz */ + #define RF_CFG_CHAN_CENTER_F0 863125 + /* Channel spacing in Hz */ + #define RF_CFG_CHAN_SPACING 1666667 +/* The minimum channel */ +#define RF_CFG_MIN_CHANNEL 0 +/* The maximum channel */ +#define RF_CFG_MAX_CHANNEL 3 +/* The maximum output power in dBm */ +#define RF_CFG_MAX_TXPOWER CC1200_CONST_TX_POWER_MAX +/* The carrier sense level used for CCA in dBm */ +#define RF_CFG_CCA_THRESHOLD (-91) +/* The RSSI offset in dBm */ +#define RF_CFG_RSSI_OFFSET (-81) +/*---------------------------------------------------------------------------*/ +static const char rf_cfg_descriptor[] = "868MHz 2-GFSK 1000 kbps"; +/*---------------------------------------------------------------------------*/ + +/* 1 byte time: 8 usec */ +#define CC1200_TSCH_PREAMBLE_LENGTH 800 /* 5 bytes */ +#define CC1200_TSCH_CONF_RX_WAIT 2200 +#define CC1200_TSCH_CONF_RX_ACK_WAIT 400 + +#define CC1200_TSCH_DEFAULT_TS_CCA_OFFSET 1800 +#define CC1200_TSCH_DEFAULT_TS_CCA 128 +#define CC1200_TSCH_DEFAULT_TS_TX_OFFSET 2200 +#define CC1200_TSCH_DEFAULT_TS_RX_OFFSET (CC1200_TSCH_DEFAULT_TS_TX_OFFSET - CC1200_TSCH_PREAMBLE_LENGTH - (CC1200_TSCH_CONF_RX_WAIT / 2)) +#define CC1200_TSCH_DEFAULT_TS_RX_ACK_DELAY (CC1200_TSCH_DEFAULT_TS_TX_ACK_DELAY - CC1200_TSCH_PREAMBLE_LENGTH - (CC1200_TSCH_CONF_RX_ACK_WAIT / 2)) +#define CC1200_TSCH_DEFAULT_TS_TX_ACK_DELAY 1900 +#define CC1200_TSCH_DEFAULT_TS_RX_WAIT (CC1200_TSCH_PREAMBLE_LENGTH + CC1200_TSCH_CONF_RX_WAIT) +#define CC1200_TSCH_DEFAULT_TS_ACK_WAIT (CC1200_TSCH_PREAMBLE_LENGTH + CC1200_TSCH_CONF_RX_ACK_WAIT) +#define CC1200_TSCH_DEFAULT_TS_RX_TX 192 +#define CC1200_TSCH_DEFAULT_TS_MAX_ACK 168 /* 17+1+3 bytes at 1000 kbps */ +#define CC1200_TSCH_DEFAULT_TS_MAX_TX 1040 /* 126+1+3 bytes at 1000 kbps */ + +#define CC1200_TSCH_DEFAULT_SLACK_TIME 500 +/* Timeslot length: 5808 usec */ +#define CC1200_TSCH_DEFAULT_TS_TIMESLOT_LENGTH \ + ( CC1200_TSCH_DEFAULT_TS_TX_OFFSET \ + + CC1200_TSCH_DEFAULT_TS_MAX_TX \ + + CC1200_TSCH_DEFAULT_TS_TX_ACK_DELAY \ + + CC1200_TSCH_DEFAULT_TS_MAX_ACK \ + + CC1200_TSCH_DEFAULT_SLACK_TIME \ + ) + +/* TSCH timeslot timing (in rtimer ticks) */ +static const uint16_t cc1200_1000kbps_tsch_timing[tsch_ts_elements_count] = { + CC1200_TSCH_DEFAULT_TS_CCA_OFFSET, + CC1200_TSCH_DEFAULT_TS_CCA, + CC1200_TSCH_DEFAULT_TS_TX_OFFSET, + CC1200_TSCH_DEFAULT_TS_RX_OFFSET, + CC1200_TSCH_DEFAULT_TS_RX_ACK_DELAY, + CC1200_TSCH_DEFAULT_TS_TX_ACK_DELAY, + CC1200_TSCH_DEFAULT_TS_RX_WAIT, + CC1200_TSCH_DEFAULT_TS_ACK_WAIT, + CC1200_TSCH_DEFAULT_TS_RX_TX, + CC1200_TSCH_DEFAULT_TS_MAX_ACK, + CC1200_TSCH_DEFAULT_TS_MAX_TX, + CC1200_TSCH_DEFAULT_TS_TIMESLOT_LENGTH, +}; + +static const registerSetting_t preferredSettings[]= +{ + {CC1200_IOCFG2, 0x06}, + {CC1200_SYNC_CFG1, 0xA8}, + {CC1200_DEVIATION_M, 0x47}, + {CC1200_MODCFG_DEV_E, 0x2F}, + {CC1200_DCFILT_CFG, 0x1E}, + {CC1200_PREAMBLE_CFG0, 0x8A}, + {CC1200_IQIC, 0x00}, + {CC1200_CHAN_BW, 0x01}, + {CC1200_MDMCFG1, 0x42}, + {CC1200_MDMCFG0, 0x05}, + {CC1200_SYMBOL_RATE2, 0xC9}, + {CC1200_SYMBOL_RATE1, 0x99}, + {CC1200_SYMBOL_RATE0, 0x99}, + {CC1200_AGC_REF, 0x2F}, + {CC1200_AGC_CS_THR, 0xF8}, + {CC1200_AGC_CFG2, 0x60}, + {CC1200_AGC_CFG1, 0x12}, + {CC1200_AGC_CFG0, 0x84}, + {CC1200_FIFO_CFG, 0x00}, + {CC1200_FS_CFG, 0x12}, + {CC1200_PKT_CFG2, 0x00}, + {CC1200_PKT_CFG0, 0x20}, + {CC1200_PKT_LEN, 0xFF}, + {CC1200_FREQOFF_CFG, 0x23}, + {CC1200_MDMCFG2, 0x00}, + {CC1200_FREQ2, 0x56}, + {CC1200_FREQ1, 0xCC}, + {CC1200_FREQ0, 0xCC}, + {CC1200_IF_ADC1, 0xEE}, + {CC1200_IF_ADC0, 0x10}, + {CC1200_FS_DIG1, 0x04}, + {CC1200_FS_DIG0, 0xA3}, + {CC1200_FS_CAL1, 0x40}, + {CC1200_FS_CAL0, 0x0E}, + {CC1200_FS_DIVTWO, 0x03}, + {CC1200_FS_DSM0, 0x33}, + {CC1200_FS_DVC1, 0xF7}, + {CC1200_FS_DVC0, 0x0F}, + {CC1200_FS_PFD, 0x00}, + {CC1200_FS_PRE, 0x6E}, + {CC1200_FS_REG_DIV_CML, 0x1C}, + {CC1200_FS_SPARE, 0xAC}, + {CC1200_FS_VCO0, 0xB5}, + {CC1200_IFAMP, 0x0D}, + {CC1200_XOSC5, 0x0E}, + {CC1200_XOSC1, 0x03}, +}; +/*---------------------------------------------------------------------------*/ +/* Global linkage: symbol name must be different in each exported file! */ +const cc1200_rf_cfg_t cc1200_868_4gfsk_1000kbps = { + .cfg_descriptor = rf_cfg_descriptor, + .register_settings = preferredSettings, + .size_of_register_settings = sizeof(preferredSettings), + .tx_pkt_lifetime = (RTIMER_SECOND), + .tx_rx_turnaround = (RTIMER_SECOND / 100), + /* Includes 3 Bytes preamble + 2 Bytes SFD, at 8usec per byte = 40 usec */ + /* Includes time to completion of "Wait for TX to start" if cc1200.c: 397 usec */ + .delay_before_tx = ((unsigned)US_TO_RTIMERTICKS(40 + 397 + 207)), + .delay_before_rx = (unsigned)US_TO_RTIMERTICKS(400), + .delay_before_detect = 0, + .chan_center_freq0 = RF_CFG_CHAN_CENTER_F0, + .chan_spacing = RF_CFG_CHAN_SPACING, + .min_channel = RF_CFG_MIN_CHANNEL, + .max_channel = RF_CFG_MAX_CHANNEL, + .max_txpower = RF_CFG_MAX_TXPOWER, + .cca_threshold = RF_CFG_CCA_THRESHOLD, + .rssi_offset = RF_CFG_RSSI_OFFSET, + .bitrate = 1000000, + .tsch_timing = cc1200_1000kbps_tsch_timing, +}; +/*---------------------------------------------------------------------------*/ diff --git a/arch/dev/cc1200/cc1200-868-fsk-1-2kbps.c b/arch/dev/cc1200/cc1200-868-fsk-1-2kbps.c index 7c8d52cb4..7cb8f3021 100644 --- a/arch/dev/cc1200/cc1200-868-fsk-1-2kbps.c +++ b/arch/dev/cc1200/cc1200-868-fsk-1-2kbps.c @@ -126,6 +126,9 @@ const cc1200_rf_cfg_t cc1200_868_fsk_1_2kbps = { .size_of_register_settings = sizeof(preferredSettings), .tx_pkt_lifetime = (2 * RTIMER_SECOND), .tx_rx_turnaround = (RTIMER_SECOND / 2), + .delay_before_tx = 0, + .delay_before_rx = 0, + .delay_before_detect = 0, .chan_center_freq0 = RF_CFG_CHAN_CENTER_F0, .chan_spacing = RF_CFG_CHAN_SPACING, .min_channel = RF_CFG_MIN_CHANNEL, @@ -133,5 +136,7 @@ const cc1200_rf_cfg_t cc1200_868_fsk_1_2kbps = { .max_txpower = RF_CFG_MAX_TXPOWER, .cca_threshold = RF_CFG_CCA_THRESHOLD, .rssi_offset = RF_CFG_RSSI_OFFSET, + .bitrate = 1200, + .tsch_timing = NULL, }; /*---------------------------------------------------------------------------*/ diff --git a/arch/dev/cc1200/cc1200-rf-cfg.h b/arch/dev/cc1200/cc1200-rf-cfg.h index 4b206959b..3042ffdd5 100644 --- a/arch/dev/cc1200/cc1200-rf-cfg.h +++ b/arch/dev/cc1200/cc1200-rf-cfg.h @@ -69,6 +69,13 @@ typedef struct cc1200_rf_cfg { rtimer_clock_t tx_pkt_lifetime; /* The maximum time it takes to switch from Tx to Rx */ rtimer_clock_t tx_rx_turnaround; + /* The delay between a call to transmit() and end of SFD */ + rtimer_clock_t delay_before_tx; + /* Delay between GO signal and start listening + * Measured 104us: between GO signal and start listening */ + rtimer_clock_t delay_before_rx; + /* Delay between the SFD finishes arriving and it is detected in software */ + rtimer_clock_t delay_before_detect; /* Base frequency in kHz */ uint32_t chan_center_freq0; /* Channel spacing in Hz */ @@ -87,6 +94,10 @@ typedef struct cc1200_rf_cfg { /* The RSSI offset in dBm. * -99 when MDMCFG1.DVGA_GAIN=00, -81 when MDMCFG1.DVGA_GAIN=01 */ int8_t rssi_offset; + /* The bitrate in bps */ + uint32_t bitrate; + /* TSCH timeslot timing */ + const uint16_t *tsch_timing; } cc1200_rf_cfg_t; /*---------------------------------------------------------------------------*/ #endif /* CC1200_RF_CFG_H */ diff --git a/arch/dev/cc1200/cc1200.c b/arch/dev/cc1200/cc1200.c index 3d9b1befc..dd90fdda7 100644 --- a/arch/dev/cc1200/cc1200.c +++ b/arch/dev/cc1200/cc1200.c @@ -47,6 +47,9 @@ #include #include +static int16_t rssi; +static rtimer_clock_t sfd_timestamp = 0; + /*---------------------------------------------------------------------------*/ /* Various implementation specific defines */ /*---------------------------------------------------------------------------*/ @@ -57,7 +60,7 @@ * - 2: Print errors + warnings (recoverable errors) * - 3: Print errors + warnings + information (what's going on...) */ -#define DEBUG_LEVEL 2 +#define DEBUG_LEVEL 0 /* * RF test mode. Blocks inside "configure()". * - Set this parameter to 1 in order to produce an modulated carrier (PN9) @@ -79,6 +82,14 @@ #define CC1200_RF_CFG cc1200_802154g_863_870_fsk_50kbps #endif #endif +/* + * When set, a software buffer is used to store outgoing packets before copying + * to Tx FIFO. This enabled sending packets larger than the FIFO. When unset, + * no buffer is used; instead, the payload is copied directly to the Tx FIFO. + * This is requried by TSCH, for shorter and more predictable delay in the Tx + * chain. This, however, restircts the payload length to the Tx FIFO size. + */ +#define CC1200_WITH_TX_BUF (!MAC_CONF_WITH_TSCH) /* * Set this parameter to 1 in order to use the MARC_STATE register when * polling the chips's status. Else use the status byte returned when sending @@ -93,7 +104,11 @@ * * TODO: Option to be removed upon approval of the driver */ +#if MAC_CONF_WITH_TSCH +#define USE_SFSTXON 0 +#else /* MAC_CONF_WITH_TSCH */ #define USE_SFSTXON 1 +#endif /* MAC_CONF_WITH_TSCH */ /*---------------------------------------------------------------------------*/ /* Phy header length */ #if CC1200_802154G @@ -133,7 +148,15 @@ /* Use GPIO2 as RX / TX FIFO threshold indicator pin */ #define GPIO2_IOCFG CC1200_IOCFG_RXFIFO_THR /* This is the FIFO threshold we use */ +#if MAC_CONF_WITH_TSCH +#if CC1200_802154G +#define FIFO_THRESHOLD 1 +#else +#define FIFO_THRESHOLD 0 +#endif +#else /* MAC_CONF_WITH_TSCH */ #define FIFO_THRESHOLD 32 +#endif /* MAC_CONF_WITH_TSCH */ /* Turn on RX after packet reception */ #define RXOFF_MODE_RX 1 /* Let the CC1200 append RSSI + LQI */ @@ -249,6 +272,8 @@ extern const cc1200_rf_cfg_t CC1200_RF_CFG; #define RF_UPDATE_CHANNEL 0x10 /* SPI was locked when calling RX interrupt, let the pollhandler do the job */ #define RF_POLL_RX_INTERRUPT 0x20 +/* Ongoing reception */ +#define RF_RX_ONGOING 0x40 /* Force calibration in case we don't use CC1200 AUTOCAL + timeout */ #if !CC1200_AUTOCAL #if CC1200_CAL_TIMEOUT_SECONDS @@ -285,15 +310,7 @@ extern const cc1200_rf_cfg_t CC1200_RF_CFG; #define LOCK_SPI() do { spi_locked++; } while(0) #define SPI_IS_LOCKED() (spi_locked != 0) #define RELEASE_SPI() do { spi_locked--; } while(0) -/*---------------------------------------------------------------------------*/ -#define BUSYWAIT_UNTIL(cond, max_time) \ - do { \ - rtimer_clock_t t0; \ - t0 = RTIMER_NOW(); \ - while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (max_time))) { \ - watchdog_periodic(); \ - } \ - } while(0) + /*---------------------------------------------------------------------------*/ #if CC1200_USE_GPIO2 /* Configure GPIO interrupts. GPIO0: falling, GPIO2: rising edge */ @@ -353,38 +370,22 @@ extern const cc1200_rf_cfg_t CC1200_RF_CFG; #define INFO(...) #endif -#if DEBUG_LEVEL > 0 -/* - * As BUSYWAIT_UNTIL was mainly used to test for a state transition, - * we define a separate macro for this adding the possibility to - * throw an error message when the timeout exceeds - */ -#define BUSYWAIT_UNTIL_STATE(s, t) \ - do { \ - rtimer_clock_t t0; \ - t0 = RTIMER_NOW(); \ - while((state() != s) && RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (t))) {} \ - if(!(RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (t)))) { \ - printf("RF: Timeout exceeded in line %d!\n", __LINE__); \ - } \ - } while(0) -#else -#define BUSYWAIT_UNTIL_STATE(s, t) \ - do { \ - rtimer_clock_t t0; \ - t0 = RTIMER_NOW(); \ - while((state() != s) && RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (t))) {} \ - } while(0) -#endif +/* Busy-wait (time-bounded) until the radio reaches a given state */ +#define RTIMER_BUSYWAIT_UNTIL_STATE(s, t) RTIMER_BUSYWAIT_UNTIL(state() == (s), t) + /*---------------------------------------------------------------------------*/ /* Variables */ /*---------------------------------------------------------------------------*/ /* Flag indicating whether non-interrupt routines are using SPI */ static volatile uint8_t spi_locked = 0; +#if CC1200_WITH_TX_BUF /* Packet buffer for transmission, filled within prepare() */ static uint8_t tx_pkt[CC1200_MAX_PAYLOAD_LEN]; +#endif /* CC1200_WITH_TX_BUF */ /* The number of bytes waiting in tx_pkt */ static uint16_t tx_pkt_len; +/* Number of bytes from tx_pkt left to write to FIFO */ +uint16_t bytes_left_to_write; /* Packet buffer for reception */ static uint8_t rx_pkt[CC1200_MAX_PAYLOAD_LEN + APPENDIX_LEN]; /* The number of bytes placed in rx_pkt */ @@ -422,6 +423,9 @@ static struct etimer et; /* Init the radio. */ static int init(void); +/* Prepare and copy PHY header to Tx FIFO */ +static int +copy_header_to_tx_fifo(unsigned short payload_len); /* Prepare the radio with a packet to be sent. */ static int prepare(const void *payload, unsigned short payload_len); @@ -530,7 +534,7 @@ idle_calibrate_rx(void); /* Restart RX from within RX interrupt. */ static void rx_rx(void); -/* Fill TX FIFO, start TX and wait for TX to complete (blocking!). */ +/* Fill TX FIFO (if not already done), start TX and wait for TX to complete (blocking!). */ static int idle_tx_rx(const uint8_t *payload, uint16_t payload_len); /* Update TX power */ @@ -572,7 +576,7 @@ PROCESS_THREAD(cc1200_process, ev, data) /* * We are on and not in TX. As every function of this driver * assures that we are in RX mode - * (using BUSYWAIT_UNTIL_STATE(STATE_RX, ...) construct) in + * (using RTIMER_BUSYWAIT_UNTIL_STATE(STATE_RX, ...) construct) in * either rx_rx(), idle_calibrate_rx() or transmit(), * something probably went wrong in the rx interrupt handler * if we are not in RX at this point. @@ -624,7 +628,7 @@ pollhandler(void) set_channel(new_rf_channel); } - if(rx_pkt_len > 0) { + if((rx_mode_value & RADIO_RX_MODE_POLL_MODE) == 0 && rx_pkt_len > 0) { int len; @@ -722,10 +726,67 @@ prepare(const void *payload, unsigned short payload_len) } tx_pkt_len = payload_len; + +#if CC1200_WITH_TX_BUF + /* Copy payload to buffer, will be sent later */ memcpy(tx_pkt, payload, tx_pkt_len); +#else /* CC1200_WITH_TX_BUF */ +#if (CC1200_MAX_PAYLOAD_LEN > (CC1200_FIFO_SIZE - PHR_LEN)) +#error CC1200 max payload too large +#else + /* Copy header and payload directly to Radio Tx FIFO (127 bytes max) */ + copy_header_to_tx_fifo(payload_len); + burst_write(CC1200_TXFIFO, payload, payload_len); +#endif +#endif /* CC1200_WITH_TX_BUF */ return RADIO_TX_OK; +} +/*---------------------------------------------------------------------------*/ +/* Prepare the radio with a packet to be sent. */ +static int +copy_header_to_tx_fifo(unsigned short payload_len) +{ +#if CC1200_802154G + /* Prepare PHR for 802.15.4g frames */ + struct { + uint8_t phra; + uint8_t phrb; + } phr; +#if CC1200_802154G_CRC16 + payload_len += 2; +#else + payload_len += 4; +#endif + /* Frame length */ + phr.phrb = (uint8_t)(payload_len & 0x00FF); + phr.phra = (uint8_t)((payload_len >> 8) & 0x0007); +#if CC1200_802154G_WHITENING + /* Enable Whitening */ + phr.phra |= (1 << 3); +#endif /* #if CC1200_802154G_WHITENING */ +#if CC1200_802154G_CRC16 + /* FCS type 1, 2 Byte CRC */ + phr.phra |= (1 << 4); +#endif /* #if CC1200_802154G_CRC16 */ +#endif /* #if CC1200_802154G */ + idle(); + + rf_flags &= ~RF_RX_PROCESSING_PKT; + strobe(CC1200_SFRX); + /* Flush TX FIFO */ + strobe(CC1200_SFTX); + +#if CC1200_802154G + /* Write PHR */ + burst_write(CC1200_TXFIFO, (uint8_t *)&phr, PHR_LEN); +#else + /* Write length byte */ + burst_write(CC1200_TXFIFO, (uint8_t *)&payload_len, PHR_LEN); +#endif /* #if CC1200_802154G */ + + return 0; } /*---------------------------------------------------------------------------*/ /* Send the packet that has previously been prepared. */ @@ -735,6 +796,7 @@ transmit(unsigned short transmit_len) uint8_t was_off = 0; int ret = RADIO_TX_OK; + int txret; INFO("RF: Transmit (%d)\n", transmit_len); @@ -790,7 +852,12 @@ transmit(unsigned short transmit_len) #endif /* Send data using TX FIFO */ - if(idle_tx_rx((const uint8_t *)tx_pkt, tx_pkt_len) == RADIO_TX_OK) { +#if CC1200_WITH_TX_BUF + txret = idle_tx_rx(tx_pkt, tx_pkt_len); +#else /* CC1200_WITH_TX_BUF */ + txret = idle_tx_rx(NULL, tx_pkt_len); +#endif /* CC1200_WITH_TX_BUF */ + if(txret == RADIO_TX_OK) { /* * TXOFF_MODE is set to RX, @@ -798,7 +865,7 @@ transmit(unsigned short transmit_len) * again as they were turned off in idle() */ - BUSYWAIT_UNTIL_STATE(STATE_RX, + RTIMER_BUSYWAIT_UNTIL_STATE(STATE_RX, CC1200_RF_CFG.tx_rx_turnaround); ENABLE_GPIO_INTERRUPTS(); @@ -861,7 +928,7 @@ read(void *buf, unsigned short buf_len) if(rx_pkt_len > 0) { - int8_t rssi = rx_pkt[rx_pkt_len - 2]; + rssi = (int8_t)rx_pkt[rx_pkt_len - 2] + (int)CC1200_RF_CFG.rssi_offset; /* CRC is already checked */ uint8_t crc_lqi = rx_pkt[rx_pkt_len - 1]; @@ -938,7 +1005,7 @@ channel_clear(void) } /* Wait for CARRIER_SENSE_VALID signal */ - BUSYWAIT_UNTIL(((rssi0 = single_read(CC1200_RSSI0)) + RTIMER_BUSYWAIT_UNTIL(((rssi0 = single_read(CC1200_RSSI0)) & CC1200_CARRIER_SENSE_VALID), RTIMER_SECOND / 100); RF_ASSERT(rssi0 & CC1200_CARRIER_SENSE_VALID); @@ -1009,9 +1076,16 @@ receiving_packet(void) static int pending_packet(void) { + int ret; + ret = ((rx_pkt_len != 0) ? 1 : 0); + if(ret == 0 && !SPI_IS_LOCKED()) { + LOCK_SPI(); + ret = (single_read(CC1200_NUM_RXBYTES) > 0); + RELEASE_SPI(); + } - INFO("RF: Pending (%d)\n", ((rx_pkt_len != 0) ? 1 : 0)); - return (rx_pkt_len != 0) ? 1 : 0; + INFO("RF: Pending (%d)\n", ret); + return ret; } /*---------------------------------------------------------------------------*/ @@ -1033,11 +1107,12 @@ on(void) /* Wake-up procedure. Wait for GPIO0 to de-assert (CHIP_RDYn) */ cc1200_arch_spi_select(); - BUSYWAIT_UNTIL((cc1200_arch_gpio0_read_pin() == 0), + RTIMER_BUSYWAIT_UNTIL((cc1200_arch_gpio0_read_pin() == 0), RTIMER_SECOND / 100); RF_ASSERT((cc1200_arch_gpio0_read_pin() == 0)); cc1200_arch_spi_deselect(); + rf_flags = RF_INITIALIZED; rf_flags |= RF_ON; /* Radio is IDLE now, re-configure GPIO0 (modified inside off()) */ @@ -1080,6 +1155,16 @@ off(void) idle(); + if(single_read(CC1200_NUM_RXBYTES) > 0) { + RELEASE_SPI(); + /* In case there is something in the Rx FIFO, read it */ + cc1200_rx_interrupt(); + if(SPI_IS_LOCKED()) { + return 0; + } + LOCK_SPI(); + } + /* * As we use GPIO as CHIP_RDYn signal on wake-up / on(), * we re-configure it for CHIP_RDYn. @@ -1106,6 +1191,40 @@ off(void) } /*---------------------------------------------------------------------------*/ +/** + * \brief Reads the current signal strength (RSSI) + * \return The current RSSI in dBm + * + * This function reads the current RSSI on the currently configured + * channel. + */ +static int16_t +get_rssi(void) +{ + int16_t rssi0, rssi1; + uint8_t was_off = 0; + + /* If we are off, turn on first */ + if(!(rf_flags & RF_ON)) { + was_off = 1; + on(); + } + + /* Wait for CARRIER_SENSE_VALID signal */ + RTIMER_BUSYWAIT_UNTIL(((rssi0 = single_read(CC1200_RSSI0)) + & CC1200_CARRIER_SENSE_VALID), + RTIMER_SECOND / 100); + RF_ASSERT(rssi0 & CC1200_CARRIER_SENSE_VALID); + rssi1 = (int8_t)single_read(CC1200_RSSI1) + (int)CC1200_RF_CFG.rssi_offset; + + /* If we were off, turn back off */ + if(was_off) { + off(); + } + + return rssi1; +} +/*---------------------------------------------------------------------------*/ /* Get a radio parameter value. */ static radio_result_t get_value(radio_param_t param, radio_value_t *value) @@ -1156,6 +1275,13 @@ get_value(radio_param_t param, radio_value_t *value) return RADIO_RESULT_OK; case RADIO_PARAM_RSSI: + *value = get_rssi(); + return RADIO_RESULT_OK; + + case RADIO_PARAM_LAST_RSSI: + *value = (radio_value_t)rssi; + return RADIO_RESULT_OK; + case RADIO_PARAM_64BIT_ADDR: return RADIO_RESULT_NOT_SUPPORTED; @@ -1180,6 +1306,34 @@ get_value(radio_param_t param, radio_value_t *value) *value = (radio_value_t)CC1200_RF_CFG.max_txpower; return RADIO_RESULT_OK; + case RADIO_CONST_PHY_OVERHEAD: +#if CC1200_802154G +#if CC1200_802154G_CRC16 + *value = (radio_value_t)4; /* 2 bytes PHR, 2 bytes CRC */ +#else + *value = (radio_value_t)6; /* 2 bytes PHR, 4 bytes CRC */ +#endif +#else + *value = (radio_value_t)3; /* 1 len byte, 2 bytes CRC */ +#endif + return RADIO_RESULT_OK; + + case RADIO_CONST_BYTE_AIR_TIME: + *value = (radio_value_t)8*1000*1000 / CC1200_RF_CFG.bitrate; + return RADIO_RESULT_OK; + + case RADIO_CONST_DELAY_BEFORE_TX: + *value = (radio_value_t)CC1200_RF_CFG.delay_before_tx; + return RADIO_RESULT_OK; + + case RADIO_CONST_DELAY_BEFORE_RX: + *value = (radio_value_t)CC1200_RF_CFG.delay_before_rx; + return RADIO_RESULT_OK; + + case RADIO_CONST_DELAY_BEFORE_DETECT: + *value = (radio_value_t)CC1200_RF_CFG.delay_before_detect; + return RADIO_RESULT_OK; + default: return RADIO_RESULT_NOT_SUPPORTED; @@ -1282,6 +1436,23 @@ set_value(radio_param_t param, radio_value_t value) static radio_result_t get_object(radio_param_t param, void *dest, size_t size) { + if(param == RADIO_PARAM_LAST_PACKET_TIMESTAMP) { + if(size != sizeof(rtimer_clock_t) || !dest) { + return RADIO_RESULT_INVALID_VALUE; + } + *(rtimer_clock_t *)dest = sfd_timestamp; + return RADIO_RESULT_OK; + } + +#if MAC_CONF_WITH_TSCH + if(param == RADIO_CONST_TSCH_TIMING) { + if(size != sizeof(uint16_t *) || !dest) { + return RADIO_RESULT_INVALID_VALUE; + } + *(const uint16_t **)dest = CC1200_RF_CFG.tsch_timing; + return RADIO_RESULT_OK; + } +#endif /* MAC_CONF_WITH_TSCH */ return RADIO_RESULT_NOT_SUPPORTED; @@ -1507,20 +1678,20 @@ configure(void) while(1) { #if (CC1200_RF_TESTMODE == 1) watchdog_periodic(); - BUSYWAIT_UNTIL(0, RTIMER_SECOND / 10); + RTIMER_BUSYWAIT(RTIMER_SECOND / 10); leds_off(LEDS_YELLOW); leds_on(LEDS_RED); watchdog_periodic(); - BUSYWAIT_UNTIL(0, RTIMER_SECOND / 10); + RTIMER_BUSYWAIT(RTIMER_SECOND / 10); leds_off(LEDS_RED); leds_on(LEDS_YELLOW); #else watchdog_periodic(); - BUSYWAIT_UNTIL(0, RTIMER_SECOND / 10); + RTIMER_BUSYWAIT(RTIMER_SECOND / 10); leds_off(LEDS_GREEN); leds_on(LEDS_RED); watchdog_periodic(); - BUSYWAIT_UNTIL(0, RTIMER_SECOND / 10); + RTIMER_BUSYWAIT(RTIMER_SECOND / 10); leds_off(LEDS_RED); leds_on(LEDS_GREEN); #endif @@ -1542,11 +1713,11 @@ configure(void) while(1) { watchdog_periodic(); - BUSYWAIT_UNTIL(0, RTIMER_SECOND / 10); + RTIMER_BUSYWAIT(RTIMER_SECOND / 10); leds_off(LEDS_GREEN); leds_on(LEDS_YELLOW); watchdog_periodic(); - BUSYWAIT_UNTIL(0, RTIMER_SECOND / 10); + RTIMER_BUSYWAIT(RTIMER_SECOND / 10); leds_off(LEDS_YELLOW); leds_on(LEDS_GREEN); clock_delay_usec(1000); @@ -1667,8 +1838,8 @@ calibrate(void) INFO("RF: Calibrate\n"); strobe(CC1200_SCAL); - BUSYWAIT_UNTIL_STATE(STATE_CALIBRATE, RTIMER_SECOND / 100); - BUSYWAIT_UNTIL_STATE(STATE_IDLE, RTIMER_SECOND / 100); + RTIMER_BUSYWAIT_UNTIL_STATE(STATE_CALIBRATE, RTIMER_SECOND / 100); + RTIMER_BUSYWAIT_UNTIL_STATE(STATE_IDLE, RTIMER_SECOND / 100); #if CC1200_CAL_TIMEOUT_SECONDS cal_timer = clock_seconds(); @@ -1705,7 +1876,7 @@ idle(void) } strobe(CC1200_SIDLE); - BUSYWAIT_UNTIL_STATE(STATE_IDLE, RTIMER_SECOND / 100); + RTIMER_BUSYWAIT_UNTIL_STATE(STATE_IDLE, RTIMER_SECOND / 100); } /* idle(), 21.05.2015 */ /*---------------------------------------------------------------------------*/ @@ -1723,7 +1894,7 @@ idle_calibrate_rx(void) rf_flags &= ~RF_RX_PROCESSING_PKT; strobe(CC1200_SFRX); strobe(CC1200_SRX); - BUSYWAIT_UNTIL_STATE(STATE_RX, RTIMER_SECOND / 100); + RTIMER_BUSYWAIT_UNTIL_STATE(STATE_RX, RTIMER_SECOND / 100); ENABLE_GPIO_INTERRUPTS(); @@ -1748,7 +1919,7 @@ rx_rx(void) strobe(CC1200_SFTX); } else { strobe(CC1200_SIDLE); - BUSYWAIT_UNTIL_STATE(STATE_IDLE, + RTIMER_BUSYWAIT_UNTIL_STATE(STATE_IDLE, RTIMER_SECOND / 100); } @@ -1760,79 +1931,29 @@ rx_rx(void) strobe(CC1200_SFRX); strobe(CC1200_SRX); - BUSYWAIT_UNTIL_STATE(STATE_RX, RTIMER_SECOND / 100); + RTIMER_BUSYWAIT_UNTIL_STATE(STATE_RX, RTIMER_SECOND / 100); } /*---------------------------------------------------------------------------*/ -/* Fill TX FIFO, start TX and wait for TX to complete (blocking!). */ +/* Fill TX FIFO (if not already done), start TX and wait for TX to complete (blocking!). */ static int idle_tx_rx(const uint8_t *payload, uint16_t payload_len) { - #if (CC1200_MAX_PAYLOAD_LEN > (CC1200_FIFO_SIZE - PHR_LEN)) - uint16_t bytes_left_to_write; uint8_t to_write; const uint8_t *p; #endif -#if CC1200_802154G - /* Prepare PHR for 802.15.4g frames */ - struct { - uint8_t phra; - uint8_t phrb; - } phr; -#if CC1200_802154G_CRC16 - payload_len += 2; -#else - payload_len += 4; -#endif - /* Frame length */ - phr.phrb = (uint8_t)(payload_len & 0x00FF); - phr.phra = (uint8_t)((payload_len >> 8) & 0x0007); -#if CC1200_802154G_WHITENING - /* Enable Whitening */ - phr.phra |= (1 << 3); -#endif /* #if CC1200_802154G_WHITENING */ -#if CC1200_802154G_CRC16 - /* FCS type 1, 2 Byte CRC */ - phr.phra |= (1 << 4); -#endif /* #if CC1200_802154G_CRC16 */ -#endif /* #if CC1200_802154G */ - /* Prepare for RX */ rf_flags &= ~RF_RX_PROCESSING_PKT; strobe(CC1200_SFRX); - /* Flush TX FIFO */ - strobe(CC1200_SFTX); - -#if USE_SFSTXON - /* - * Enable synthesizer. Saves us a few µs especially if it takes - * long enough to fill the FIFO. This strobe must not be - * send before SFTX! - */ - strobe(CC1200_SFSTXON); -#endif - /* Configure GPIO0 to detect TX state */ single_write(CC1200_IOCFG0, CC1200_IOCFG_MARC_2PIN_STATUS_0); -#if (CC1200_MAX_PAYLOAD_LEN > (CC1200_FIFO_SIZE - PHR_LEN)) - /* - * We already checked that GPIO2 is used if - * CC1200_MAX_PAYLOAD_LEN > 127 / 126 in the header of this file - */ - single_write(CC1200_IOCFG2, CC1200_IOCFG_TXFIFO_THR); -#endif - -#if CC1200_802154G - /* Write PHR */ - burst_write(CC1200_TXFIFO, (uint8_t *)&phr, PHR_LEN); -#else - /* Write length byte */ - burst_write(CC1200_TXFIFO, (uint8_t *)&payload_len, PHR_LEN); -#endif /* #if CC1200_802154G */ +#if CC1200_WITH_TX_BUF + /* Prepare and write header */ + copy_header_to_tx_fifo(payload_len); /* * Fill FIFO with data. If SPI is slow it might make sense @@ -1849,17 +1970,18 @@ idle_tx_rx(const uint8_t *payload, uint16_t payload_len) #else burst_write(CC1200_TXFIFO, payload, payload_len); #endif +#endif /* CC1200_WITH_TX_BUF */ #if USE_SFSTXON /* Wait for synthesizer to be ready */ - BUSYWAIT_UNTIL_STATE(STATE_FSTXON, RTIMER_SECOND / 100); + RTIMER_BUSYWAIT_UNTIL_STATE(STATE_FSTXON, RTIMER_SECOND / 100); #endif /* Start TX */ strobe(CC1200_STX); /* Wait for TX to start. */ - BUSYWAIT_UNTIL((cc1200_arch_gpio0_read_pin() == 1), RTIMER_SECOND / 100); + RTIMER_BUSYWAIT_UNTIL((cc1200_arch_gpio0_read_pin() == 1), RTIMER_SECOND / 100); /* Turned off at the latest in idle() */ TX_LEDS_ON(); @@ -1888,7 +2010,7 @@ idle_tx_rx(const uint8_t *payload, uint16_t payload_len) } -#if (CC1200_MAX_PAYLOAD_LEN > (CC1200_FIFO_SIZE - PHR_LEN)) +#if (CC1200_MAX_PAYLOAD_LEN > (CC1200_FIFO_SIZE - PHR_LEN)) && CC1200_WITH_TX_BUF if(bytes_left_to_write != 0) { rtimer_clock_t t0; uint8_t s; @@ -1922,7 +2044,7 @@ idle_tx_rx(const uint8_t *payload, uint16_t payload_len) */ INFO("RF: TX failure!\n"); - BUSYWAIT_UNTIL((state() != STATE_TX), RTIMER_SECOND / 100); + RTIMER_BUSYWAIT_UNTIL((state() != STATE_TX), RTIMER_SECOND / 100); /* Re-configure GPIO2 */ single_write(CC1200_IOCFG2, GPIO2_IOCFG); idle(); @@ -1936,12 +2058,12 @@ idle_tx_rx(const uint8_t *payload, uint16_t payload_len) } else { /* Wait for TX to complete */ - BUSYWAIT_UNTIL((cc1200_arch_gpio0_read_pin() == 0), + RTIMER_BUSYWAIT_UNTIL((cc1200_arch_gpio0_read_pin() == 0), CC1200_RF_CFG.tx_pkt_lifetime); } #else /* Wait for TX to complete */ - BUSYWAIT_UNTIL((cc1200_arch_gpio0_read_pin() == 0), + RTIMER_BUSYWAIT_UNTIL((cc1200_arch_gpio0_read_pin() == 0), CC1200_RF_CFG.tx_pkt_lifetime); #endif @@ -2026,6 +2148,9 @@ set_channel(uint8_t channel) uint8_t was_off = 0; uint32_t freq; + channel %= (CC1200_RF_CFG.max_channel - CC1200_RF_CFG.min_channel + 1); + channel += CC1200_RF_CFG.min_channel; + #if 0 /* * We explicitly allow a channel update even if the channel does not change. @@ -2156,6 +2281,7 @@ addr_check_auto_ack(uint8_t *frame, uint16_t frame_len) idle(); #endif + prepare((const uint8_t *)ack, ACK_LEN); idle_tx_rx((const uint8_t *)ack, ACK_LEN); /* rx_rx() will follow */ @@ -2204,6 +2330,23 @@ cc1200_rx_interrupt(void) */ static uint8_t buf[CC1200_MAX_PAYLOAD_LEN + APPENDIX_LEN]; + /* + * If CC1200_USE_GPIO2 is enabled, we come here either once RX FIFO + * threshold is reached (GPIO2 rising edge) + * or at the end of the packet (GPIO0 falling edge). + */ +#if CC1200_USE_GPIO2 + int gpio2 = cc1200_arch_gpio2_read_pin(); + int gpio0 = cc1200_arch_gpio0_read_pin(); + if((rf_flags & RF_RX_ONGOING) == 0 && gpio2 > 0) { + rf_flags |= RF_RX_ONGOING; + sfd_timestamp = RTIMER_NOW(); + } + if(gpio0 == 0) { + rf_flags &= ~RF_RX_ONGOING; + } +#endif + if(SPI_IS_LOCKED()) { /* diff --git a/arch/dev/cc2420/cc2420-tsch-15ms.c b/arch/dev/cc2420/cc2420-tsch-15ms.c new file mode 100644 index 000000000..b3b825584 --- /dev/null +++ b/arch/dev/cc2420/cc2420-tsch-15ms.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2018, RISE SICS. + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the Contiki operating system. + * + */ + +/** + * \file + * IEEE 802.15.4 TSCH timeslot timings for 15ms slots + * \author + * Simon Duquennoy + * + */ + +#include "contiki.h" +#include "net/mac/tsch/tsch.h" + +/** + * \brief 15ms TSCH timeslot timings, required for cc2420 platforms as + * they are unable to keep up with the defulat 10ms timeslots. + */ +const uint16_t tsch_timeslot_timing_us_15000[tsch_ts_elements_count] = { + 1800, /* CCAOffset */ + 128, /* CCA */ + 4000, /* TxOffset */ + (4000 - (TSCH_CONF_RX_WAIT / 2)), /* RxOffset */ + 3600, /* RxAckDelay */ + 4000, /* TxAckDelay */ + TSCH_CONF_RX_WAIT, /* RxWait */ + 800, /* AckWait */ + 2072, /* RxTx */ + 2400, /* MaxAck */ + 4256, /* MaxTx */ + 15000, /* TimeslotLength */ +}; diff --git a/arch/platform/cooja/sys/node-id.h b/arch/dev/cc2420/cc2420-tsch-15ms.h similarity index 89% rename from arch/platform/cooja/sys/node-id.h rename to arch/dev/cc2420/cc2420-tsch-15ms.h index a6876bd1f..7c0b47073 100644 --- a/arch/platform/cooja/sys/node-id.h +++ b/arch/dev/cc2420/cc2420-tsch-15ms.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, Swedish Institute of Computer Science. + * Copyright (c) 2018, RISE SICS. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,14 +26,10 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * + * This file is part of the Contiki operating system. + * */ -#ifndef NODE_ID_H_ -#define NODE_ID_H_ +#include "contiki.h" -#include "dev/moteid.h" - -#define node_id simMoteID - -#endif /* NODE_ID_H_ */ +extern const uint16_t tsch_timeslot_timing_us_15000[]; diff --git a/arch/dev/cc2420/cc2420.c b/arch/dev/cc2420/cc2420.c index 9310ec9e4..a1572b0ef 100644 --- a/arch/dev/cc2420/cc2420.c +++ b/arch/dev/cc2420/cc2420.c @@ -96,9 +96,6 @@ static const struct output_config output_power[] = { void cc2420_arch_init(void); -/* XXX hack: these will be made as Chameleon packet attributes */ -rtimer_clock_t cc2420_time_of_arrival, cc2420_time_of_departure; - int cc2420_authority_level_of_sender; volatile uint8_t cc2420_sfd_counter; @@ -641,7 +638,7 @@ cc2420_init(void) init_security(); cc2420_set_pan_addr(0xffff, 0x0000, NULL); - cc2420_set_channel(CC2420_CONF_CHANNEL); + cc2420_set_channel(IEEE802154_DEFAULT_CHANNEL); cc2420_set_cca_threshold(CC2420_CONF_CCA_THRESH); flushrx(); diff --git a/arch/dev/cc2420/cc2420.h b/arch/dev/cc2420/cc2420.h index a030632a6..33135e21c 100644 --- a/arch/dev/cc2420/cc2420.h +++ b/arch/dev/cc2420/cc2420.h @@ -50,10 +50,6 @@ #define WITH_SEND_CCA 1 -#ifndef CC2420_CONF_CHANNEL -#define CC2420_CONF_CHANNEL 26 -#endif /* CC2420_CONF_CHANNEL */ - #ifndef CC2420_CONF_CCA_THRESH #define CC2420_CONF_CCA_THRESH -45 #endif /* CC2420_CONF_CCA_THRESH */ @@ -106,9 +102,6 @@ int cc2420_get_txpower(void); */ int cc2420_interrupt(void); -/* XXX hack: these will be made as Chameleon packet attributes */ -extern rtimer_clock_t cc2420_time_of_arrival, - cc2420_time_of_departure; extern int cc2420_authority_level_of_sender; int cc2420_on(void); diff --git a/arch/dev/ext-flash/ext-flash.c b/arch/dev/ext-flash/ext-flash.c index 10e953ffa..c4b108271 100644 --- a/arch/dev/ext-flash/ext-flash.c +++ b/arch/dev/ext-flash/ext-flash.c @@ -29,11 +29,11 @@ */ /*---------------------------------------------------------------------------*/ /** - * \addtogroup sensortag-cc26xx-ext-flash + * \addtogroup ext-flash * @{ * * \file - * Sensortag/LaunchPad External Flash Driver + * Implementation of a generic external SPI flash driver */ /*---------------------------------------------------------------------------*/ #include "contiki.h" @@ -99,7 +99,7 @@ #define VERIFY_PART_POWERED_DOWN 0 #define VERIFY_PART_OK 1 /*---------------------------------------------------------------------------*/ -static spi_device_t flash_spi_configuration_default = { +static const spi_device_t flash_spi_configuration_default = { .spi_controller = EXT_FLASH_SPI_CONTROLLER, .pin_spi_sck = EXT_FLASH_SPI_PIN_SCK, .pin_spi_miso = EXT_FLASH_SPI_PIN_MISO, @@ -113,8 +113,8 @@ static spi_device_t flash_spi_configuration_default = { /** * Get spi configuration, return default configuration if NULL */ -static spi_device_t * -get_spi_conf(spi_device_t *conf) +static const spi_device_t * +get_spi_conf(const spi_device_t *conf) { if(conf == NULL) { return &flash_spi_configuration_default; @@ -126,7 +126,7 @@ get_spi_conf(spi_device_t *conf) * Clear external flash CSN line */ static bool -select_on_bus(spi_device_t *flash_spi_configuration) +select_on_bus(const spi_device_t *flash_spi_configuration) { if(spi_select(flash_spi_configuration) == SPI_DEV_STATUS_OK) { return true; @@ -138,7 +138,7 @@ select_on_bus(spi_device_t *flash_spi_configuration) * Set external flash CSN line */ static void -deselect(spi_device_t *flash_spi_configuration) +deselect(const spi_device_t *flash_spi_configuration) { spi_deselect(flash_spi_configuration); } @@ -148,7 +148,7 @@ deselect(spi_device_t *flash_spi_configuration) * \return True when successful. */ static bool -wait_ready(spi_device_t *flash_spi_configuration) +wait_ready(const spi_device_t *flash_spi_configuration) { bool ret; const uint8_t wbuf[1] = { BLS_CODE_READ_STATUS }; @@ -196,7 +196,7 @@ wait_ready(spi_device_t *flash_spi_configuration) * was powered down */ static uint8_t -verify_part(spi_device_t *flash_spi_configuration) +verify_part(const spi_device_t *flash_spi_configuration) { const uint8_t wbuf[] = { BLS_CODE_MDID, 0xFF, 0xFF, 0x00 }; uint8_t rbuf[2] = { 0, 0 }; @@ -230,7 +230,7 @@ verify_part(spi_device_t *flash_spi_configuration) * the status register is accessible. */ static bool -power_down(spi_device_t *flash_spi_configuration) +power_down(const spi_device_t *flash_spi_configuration) { uint8_t cmd; uint8_t i; @@ -271,7 +271,7 @@ power_down(spi_device_t *flash_spi_configuration) * \return True if the command was written successfully */ static bool -power_standby(spi_device_t *flash_spi_configuration) +power_standby(const spi_device_t *flash_spi_configuration) { uint8_t cmd; bool success; @@ -297,7 +297,7 @@ power_standby(spi_device_t *flash_spi_configuration) * \return True when successful. */ static bool -write_enable(spi_device_t *flash_spi_configuration) +write_enable(const spi_device_t *flash_spi_configuration) { bool ret; const uint8_t wbuf[] = { BLS_CODE_WRITE_ENABLE }; @@ -316,9 +316,9 @@ write_enable(spi_device_t *flash_spi_configuration) } /*---------------------------------------------------------------------------*/ bool -ext_flash_open(spi_device_t *conf) +ext_flash_open(const spi_device_t *conf) { - spi_device_t *flash_spi_configuration; + const spi_device_t *flash_spi_configuration; flash_spi_configuration = get_spi_conf(conf); @@ -346,10 +346,10 @@ ext_flash_open(spi_device_t *conf) } /*---------------------------------------------------------------------------*/ bool -ext_flash_close(spi_device_t *conf) +ext_flash_close(const spi_device_t *conf) { bool ret; - spi_device_t *flash_spi_configuration; + const spi_device_t *flash_spi_configuration; flash_spi_configuration = get_spi_conf(conf); @@ -365,12 +365,12 @@ ext_flash_close(spi_device_t *conf) } /*---------------------------------------------------------------------------*/ bool -ext_flash_read(spi_device_t *conf, uint32_t offset, uint32_t length, uint8_t *buf) +ext_flash_read(const spi_device_t *conf, uint32_t offset, uint32_t length, uint8_t *buf) { uint8_t wbuf[4]; bool ret; - spi_device_t *flash_spi_configuration; + const spi_device_t *flash_spi_configuration; flash_spi_configuration = get_spi_conf(conf); @@ -406,12 +406,12 @@ ext_flash_read(spi_device_t *conf, uint32_t offset, uint32_t length, uint8_t *bu } /*---------------------------------------------------------------------------*/ bool -ext_flash_write(spi_device_t *conf, uint32_t offset, uint32_t length, const uint8_t *buf) +ext_flash_write(const spi_device_t *conf, uint32_t offset, uint32_t length, const uint8_t *buf) { uint8_t wbuf[4]; uint32_t ilen; /* interim length per instruction */ - spi_device_t *flash_spi_configuration; + const spi_device_t *flash_spi_configuration; flash_spi_configuration = get_spi_conf(conf); @@ -466,7 +466,7 @@ ext_flash_write(spi_device_t *conf, uint32_t offset, uint32_t length, const uint } /*---------------------------------------------------------------------------*/ bool -ext_flash_erase(spi_device_t *conf, uint32_t offset, uint32_t length) +ext_flash_erase(const spi_device_t *conf, uint32_t offset, uint32_t length) { /* * Note that Block erase might be more efficient when the floor map @@ -477,7 +477,7 @@ ext_flash_erase(spi_device_t *conf, uint32_t offset, uint32_t length) uint32_t i, numsectors; uint32_t endoffset = offset + length - 1; - spi_device_t *flash_spi_configuration; + const spi_device_t *flash_spi_configuration; flash_spi_configuration = get_spi_conf(conf); @@ -518,7 +518,7 @@ ext_flash_erase(spi_device_t *conf, uint32_t offset, uint32_t length) } /*---------------------------------------------------------------------------*/ bool -ext_flash_init(spi_device_t *conf) +ext_flash_init(const spi_device_t *conf) { if(ext_flash_open(conf) == false) { return false; diff --git a/arch/dev/ext-flash/ext-flash.h b/arch/dev/ext-flash/ext-flash.h index 20748a2f0..2d081f5be 100644 --- a/arch/dev/ext-flash/ext-flash.h +++ b/arch/dev/ext-flash/ext-flash.h @@ -29,14 +29,23 @@ */ /*---------------------------------------------------------------------------*/ /** - * \addtogroup common-cc26xx-peripherals + * \addtogroup dev * @{ * - * \defgroup sensortag-cc26xx-ext-flash SensorTag/LaunchPad External Flash + * \defgroup ext-flash Generic external SPI flash driver + * + * This is a generic driver for external SPI flash memories. The driver has + * been tested and works with multiple external SPI flash parts. The list of + * parts the driver has been tested against is shown in the README in this + * directory. + * + * If you successfully use this driver with a part that is not listed in the + * README, please let us know so we can update it. + * * @{ * * \file - * Header file for the Sensortag/LaunchPad External Flash Driver + * Header file for the external SPI flash API */ /*---------------------------------------------------------------------------*/ #ifndef EXT_FLASH_H_ @@ -52,7 +61,7 @@ * \param conf SPI bus configuration struct. NULL for default. * \return True when successful. */ -bool ext_flash_open(spi_device_t *conf); +bool ext_flash_open(const spi_device_t *conf); /** * \brief Close the storage driver @@ -61,7 +70,7 @@ bool ext_flash_open(spi_device_t *conf); * * This call will put the device in its lower power mode (power down). */ -bool ext_flash_close(spi_device_t *conf); +bool ext_flash_close(const spi_device_t *conf); /** * \brief Read storage content @@ -73,7 +82,7 @@ bool ext_flash_close(spi_device_t *conf); * * buf must be allocated by the caller */ -bool ext_flash_read(spi_device_t *conf, uint32_t offset, uint32_t length, uint8_t *buf); +bool ext_flash_read(const spi_device_t *conf, uint32_t offset, uint32_t length, uint8_t *buf); /** * \brief Erase storage sectors corresponding to the range. @@ -85,7 +94,7 @@ bool ext_flash_read(spi_device_t *conf, uint32_t offset, uint32_t length, uint8_ * The erase operation will be sector-wise, therefore a call to this function * will generally start the erase procedure at an address lower than offset */ -bool ext_flash_erase(spi_device_t *conf, uint32_t offset, uint32_t length); +bool ext_flash_erase(const spi_device_t *conf, uint32_t offset, uint32_t length); /** * \brief Write to storage sectors. @@ -96,7 +105,7 @@ bool ext_flash_erase(spi_device_t *conf, uint32_t offset, uint32_t length); * * \return True when successful. */ -bool ext_flash_write(spi_device_t *conf, uint32_t offset, uint32_t length, const uint8_t *buf); +bool ext_flash_write(const spi_device_t *conf, uint32_t offset, uint32_t length, const uint8_t *buf); /** * \brief Initialise the external flash @@ -108,7 +117,7 @@ bool ext_flash_write(spi_device_t *conf, uint32_t offset, uint32_t length, const * In order to perform any operation, the caller must first wake the device * up by calling ext_flash_open() */ -bool ext_flash_init(spi_device_t *conf); +bool ext_flash_init(const spi_device_t *conf); /*---------------------------------------------------------------------------*/ #endif /* EXT_FLASH_H_ */ /*---------------------------------------------------------------------------*/ diff --git a/arch/platform/cc2538dk/Makefile.cc2538dk b/arch/platform/cc2538dk/Makefile.cc2538dk index c452ccfaf..148c6e837 100644 --- a/arch/platform/cc2538dk/Makefile.cc2538dk +++ b/arch/platform/cc2538dk/Makefile.cc2538dk @@ -28,12 +28,27 @@ endif BSL = $(CONTIKI)/tools/cc2538-bsl/cc2538-bsl.py -%.upload: %.bin %.elf +%.upload: $(OUT_BIN) $(OUT_ELF) ifeq ($(wildcard $(BSL)), ) @echo "ERROR: Could not find the cc2538-bsl script. Did you run 'git submodule update --init' ?" else - $(eval BSL_ADDRESS_ARG := -a $(shell $(OBJDUMP) -h $*.elf | grep -B1 LOAD | \ + $(eval BSL_ADDRESS_ARG := -a $(shell $(OBJDUMP) -h \ + $(BUILD_DIR_BOARD)/$*.elf | grep -B1 LOAD | \ grep -Ev 'LOAD|\-\-' | awk '{print "0x" $$5}' | \ sort -g | head -1)) $(PYTHON) $(BSL) $(BSL_FLAGS) $(BSL_ADDRESS_ARG) $< endif + +ifeq ($(HOST_OS),Darwin) + RENODE = mono /Applications/Renode.app/Contents/MacOS/bin/Renode.exe +else + RENODE = renode +endif + +SCRIPT ?= $(notdir $(CURDIR)).resc + +.PHONY: renode + +renode: all + $(RENODE) $(SCRIPT) + diff --git a/arch/platform/cc2538dk/dev/board.h b/arch/platform/cc2538dk/dev/board.h index 80f036fd7..2540b7ce7 100644 --- a/arch/platform/cc2538dk/dev/board.h +++ b/arch/platform/cc2538dk/dev/board.h @@ -220,6 +220,18 @@ #endif /* #if SPI1_IN_USE */ /** @} */ /*---------------------------------------------------------------------------*/ +/** + * \name CC2538 TSCH configuration + * + * @{ + */ +#define RADIO_PHY_OVERHEAD CC2538_PHY_OVERHEAD +#define RADIO_BYTE_AIR_TIME CC2538_BYTE_AIR_TIME +#define RADIO_DELAY_BEFORE_TX CC2538_DELAY_BEFORE_TX +#define RADIO_DELAY_BEFORE_RX CC2538_DELAY_BEFORE_RX +#define RADIO_DELAY_BEFORE_DETECT CC2538_DELAY_BEFORE_DETECT +/** @} */ +/*---------------------------------------------------------------------------*/ /** * \name Device string used on startup * @{ diff --git a/arch/platform/cc2538dk/platform.c b/arch/platform/cc2538dk/platform.c index bf945bfdd..2a3ca21ed 100644 --- a/arch/platform/cc2538dk/platform.c +++ b/arch/platform/cc2538dk/platform.c @@ -106,7 +106,7 @@ set_rf_params(void) NETSTACK_RADIO.set_value(RADIO_PARAM_PAN_ID, IEEE802154_PANID); NETSTACK_RADIO.set_value(RADIO_PARAM_16BIT_ADDR, short_addr); - NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, CC2538_RF_CHANNEL); + NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, IEEE802154_DEFAULT_CHANNEL); NETSTACK_RADIO.set_object(RADIO_PARAM_64BIT_ADDR, ext_addr, 8); } /*---------------------------------------------------------------------------*/ diff --git a/arch/platform/cooja/Makefile.cooja b/arch/platform/cooja/Makefile.cooja index d06aa08d5..6a6a9d49e 100644 --- a/arch/platform/cooja/Makefile.cooja +++ b/arch/platform/cooja/Makefile.cooja @@ -34,10 +34,10 @@ endif endif ## QUICKSTART -#MAIN_SRC = $(OBJECTDIR)/$(LIBNAME).c -MAIN_OBJ = $(OBJECTDIR)/$(LIBNAME).o -ARCHIVE = $(OBJECTDIR)/$(LIBNAME).a -JNILIB = $(OBJECTDIR)/$(LIBNAME).$(TARGET) +#MAIN_SRC = $(BUILD_DIR_BOARD)/$(LIBNAME).c +MAIN_OBJ = $(BUILD_DIR_BOARD)/$(LIBNAME).o +ARCHIVE = $(BUILD_DIR_BOARD)/$(LIBNAME).a +JNILIB = $(BUILD_DIR_BOARD)/$(LIBNAME).$(TARGET) CONTIKI_APP_OBJ = $(CONTIKI_APP).o ### COOJA platform sources diff --git a/arch/platform/cooja/Makefile.customrules-cooja b/arch/platform/cooja/Makefile.customrules-cooja index 42d6e125e..60d6240f1 100644 --- a/arch/platform/cooja/Makefile.customrules-cooja +++ b/arch/platform/cooja/Makefile.customrules-cooja @@ -10,11 +10,11 @@ CUSTOM_RULE_LINK=1 REDEF_PRINTF=1 # Redefine functions to enable printf()s inside Cooja -# NB: Assumes ARCHIVE was not overridden and is in $(OBJECTDIR) +# NB: Assumes ARCHIVE was not overridden and is in $(BUILD_DIR_BOARD) $(ARCHIVE): $(CONTIKI_OBJECTFILES) | $(OBJECTDIR) $(AR_COMMAND_1) $^ $(AR_COMMAND_2) -# NB: Assumes JNILIB was not overridden and is in $(OBJECTDIR) +# NB: Assumes JNILIB was not overridden and is in $(BUILD_DIR_BOARD) $(JNILIB): $(CONTIKI_APP_OBJ) $(MAIN_OBJ) $(PROJECT_OBJECTFILES) $(ARCHIVE) | $(OBJECTDIR) ifdef REDEF_PRINTF diff --git a/arch/platform/cooja/contiki-conf.h b/arch/platform/cooja/contiki-conf.h index 75a37f866..44c984dbf 100644 --- a/arch/platform/cooja/contiki-conf.h +++ b/arch/platform/cooja/contiki-conf.h @@ -91,6 +91,11 @@ #define NBR_TABLE_CONF_MAX_NEIGHBORS 300 #endif /* NBR_TABLE_CONF_MAX_NEIGHBORS */ +/* configure queues */ +#ifndef QUEUEBUF_CONF_NUM +#define QUEUEBUF_CONF_NUM 64 +#endif /* QUEUEBUF_CONF_NUM */ + #ifndef UIP_CONF_IPV6_QUEUE_PKT #define UIP_CONF_IPV6_QUEUE_PKT 1 #endif /* UIP_CONF_IPV6_QUEUE_PKT */ @@ -113,9 +118,14 @@ typedef unsigned short uip_stats_t; #define CLOCK_CONF_SECOND 1000L typedef unsigned long clock_time_t; -typedef uint64_t rtimer_clock_t; -#define RTIMER_CLOCK_DIFF(a,b) ((int64_t)((a)-(b))) +/* Use 64-bit rtimer (default in Contiki-NG is 32) */ +#define RTIMER_CONF_CLOCK_SIZE 8 + +/* 1 len byte, 2 bytes CRC */ +#define RADIO_PHY_OVERHEAD 3 +/* 250kbps data rate. One byte = 32us */ +#define RADIO_BYTE_AIR_TIME 32 #define RADIO_DELAY_BEFORE_TX 0 #define RADIO_DELAY_BEFORE_RX 0 #define RADIO_DELAY_BEFORE_DETECT 0 @@ -133,7 +143,6 @@ typedef uint64_t rtimer_clock_t; #define CFS_CONF_OFFSET_TYPE long -#define RF_CHANNEL 26 #define NETSTACK_RADIO_MAX_PAYLOAD_LEN 125 #define PLATFORM_CONF_SUPPORTS_STACK_CHECK 0 diff --git a/arch/platform/cooja/dev/cooja-radio.c b/arch/platform/cooja/dev/cooja-radio.c index 4f7e6a357..f0dee567b 100644 --- a/arch/platform/cooja/dev/cooja-radio.c +++ b/arch/platform/cooja/dev/cooja-radio.c @@ -330,6 +330,10 @@ get_value(radio_param_t param, radio_value_t *value) case RADIO_PARAM_LAST_LINK_QUALITY: *value = simLQI; return RADIO_RESULT_OK; + case RADIO_PARAM_RSSI: + /* return a fixed value depending on the channel */ + *value = -90 + simRadioChannel - 11; + return RADIO_RESULT_OK; default: return RADIO_RESULT_NOT_SUPPORTED; } diff --git a/arch/platform/cooja/dev/watchdog.c b/arch/platform/cooja/dev/watchdog.c index a30fc0fc8..347d9a996 100644 --- a/arch/platform/cooja/dev/watchdog.c +++ b/arch/platform/cooja/dev/watchdog.c @@ -30,8 +30,10 @@ * */ - /* Dummy watchdog routines for the Raven 1284p */ + /* Dummy watchdog routines for Cooja motes */ #include "dev/watchdog.h" +#include "lib/simEnvChange.h" +#include "sys/cooja_mt.h" /*---------------------------------------------------------------------------*/ void @@ -47,6 +49,9 @@ watchdog_start(void) void watchdog_periodic(void) { + /* Yield and give control back to the simulator scheduler */ + simProcessRunValue = 1; + cooja_mt_yield(); } /*---------------------------------------------------------------------------*/ void diff --git a/arch/platform/cooja/platform.c b/arch/platform/cooja/platform.c index 9ef310bce..591abe67e 100644 --- a/arch/platform/cooja/platform.c +++ b/arch/platform/cooja/platform.c @@ -64,6 +64,7 @@ #include "dev/button-sensor.h" #include "dev/pir-sensor.h" #include "dev/vib-sensor.h" +#include "dev/moteid.h" #include "sys/node-id.h" #include "services/rpl-border-router/rpl-border-router.h" @@ -151,13 +152,13 @@ set_lladdr(void) { int i; for(i = 0; i < sizeof(uip_lladdr.addr); i += 2) { - addr.u8[i + 1] = node_id & 0xff; - addr.u8[i + 0] = node_id >> 8; + addr.u8[i + 1] = simMoteID & 0xff; + addr.u8[i + 0] = simMoteID >> 8; } } #else /* NETSTACK_CONF_WITH_IPV6 */ - addr.u8[0] = node_id & 0xff; - addr.u8[1] = node_id >> 8; + addr.u8[0] = simMoteID & 0xff; + addr.u8[1] = simMoteID >> 8; #endif /* NETSTACK_CONF_WITH_IPV6 */ linkaddr_set_node_addr(&addr); } @@ -177,11 +178,6 @@ platform_init_stage_two() void platform_init_stage_three() { - if(node_id > 0) { - LOG_INFO("Node id is set to %u.\n", node_id); - } else { - LOG_INFO("Node id is not set.\n"); - } /* Initialize eeprom */ eeprom_init(); /* Start serial process */ diff --git a/arch/platform/jn516x/Makefile.jn516x b/arch/platform/jn516x/Makefile.jn516x index 9f7a31adf..051c336fb 100644 --- a/arch/platform/jn516x/Makefile.jn516x +++ b/arch/platform/jn516x/Makefile.jn516x @@ -82,7 +82,7 @@ OBJDUMP:=$(CROSS_COMPILE)-objdump ARCH = jn516x-ccm-star.c exceptions.c rtimer-arch.c rtimer-arch-slow.c \ slip_uart0.c clock.c micromac-radio.c int-master.c \ - node-id.c watchdog.c slip.c dbg.c + watchdog.c slip.c dbg.c # Default uart0 for printf and slip TARGET_WITH_UART0 ?= 1 TARGET_WITH_UART1 ?= 0 @@ -103,8 +103,6 @@ endif CONTIKI_TARGET_DIRS = . dev CONTIKI_TARGET_MAIN = platform.c -MODULES += os/lib/dbg-io - ifeq ($(JN516x_WITH_DR1175),1) JN516x_WITH_DR1174 = 1 CFLAGS += -DSENSOR_BOARD_DR1175 @@ -175,17 +173,14 @@ MOTELIST = python $(CONTIKI)/tools/jn516x/mote-list.py ifeq ($(HOST_OS),Windows) USBDEVPREFIX=/dev/com USBDEVBASENAME=COM - SERIALDUMP ?= $(CONTIKI)/tools/jn516x/serialdump-windows else ifeq ($(HOST_OS),Darwin) USBDEVPREFIX= USBDEVBASENAME=/dev/tty.usbserial- - SERIALDUMP ?= $(CONTIKI)/tools/jn516x/serialdump-macos else # Else we assume Linux USBDEVPREFIX= USBDEVBASENAME=/dev/ttyUSB - SERIALDUMP ?= $(CONTIKI)/tools/jn516x/serialdump-linux endif endif @@ -195,7 +190,7 @@ ifndef MOTE $(error MOTE not defined! You must specify which MOTE (serial port) to use) endif endif -PORT = $(USBDEVBASENAME)$(MOTE) +DEV_PORT = $(USBDEVBASENAME)$(MOTE) #### make targets @@ -234,40 +229,44 @@ ALLLIBS = $(addprefix -l,$(LDLIBS)) $(addprefix -l,$(LDSTACKLIBS)) $(addprefix - ABS_APPLIBS = $(addsuffix _$(JENNIC_CHIP_FAMILY).a,$(addprefix $(COMPONENTS_BASE_DIR)/Library/lib,$(APPLIBS))) ifneq ($(wildcard $(SDK_BASE_DIR)/Components/Library/*),) -# The SDK is fully installed, proceed to linking and objcopy to ready-to-upload .jn516x.bin file -%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB) $(ABS_APPLIBS) - echo ${filter %.a,$^} +# The SDK is fully installed, proceed to linking +$(BUILD_DIR_BOARD)/%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB) $(ABS_APPLIBS) + @echo ${filter %.a,$^} $(Q)$(CC) -Wl,--gc-sections $(LDFLAGS) -T$(LINKCMD) -o $@ -Wl,--start-group \ $(patsubst /cygdrive/c/%,c:/%,${filter-out %.a,$^}) \ $(patsubst /cygdrive/c/%,c:/%,${filter %.a,$^}) \ $(ALLLIBS) -Wl,--end-group -Wl,-Map,$(CONTIKI_NG_PROJECT_MAP) - $(OBJCOPY) -S -O binary $@ $@.bin else # The SDK does not include libraries, only build objects and libraries, skip linking -%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB) - echo Creating empty $@ +$(BUILD_DIR_BOARD)/%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB) + @echo Creating empty $@ touch $@ endif -%.$(TARGET).bin: %.$(TARGET) +$(BUILD_DIR_BOARD)/%.$(TARGET).bin: $(BUILD_DIR_BOARD)/%.$(TARGET) + $(TRACE_OBJCOPY) $(Q)$(OBJCOPY) -S -O binary $< $@ +%.$(TARGET).bin: $(BUILD_DIR_BOARD)/%.$(TARGET).bin + $(TRACE_CP) + $(Q)$(CP) $< $@ + ### Upload target to one jn516x mote specified by MOTE=portNumber ifeq ($(HOST_OS),Windows) -%.upload: %.$(TARGET).bin - ${FLASH_PROGRAMMER} -a -c $(PORT) -B 1000000 -s -w -f $< +%.upload: $(BUILD_DIR_BOARD)/%.$(TARGET).bin + ${FLASH_PROGRAMMER} -a -c $(DEV_PORT) -B 1000000 -s -w -f $< else -%.upload: %.$(TARGET).bin - ${FLASH_PROGRAMMER} -V 10 -v -s $(PORT) -I 38400 -P 1000000 -f $< +%.upload: $(BUILD_DIR_BOARD)/%.$(TARGET).bin + ${FLASH_PROGRAMMER} -V 10 -v -s $(DEV_PORT) -I 38400 -P 1000000 -f $< endif ### Flash the given file ifeq ($(HOST_OS),Windows) %.flash: ${FLASH_PROGRAMMER} - ${FLASH_PROGRAMMER} -a -c $(PORT) -B 1000000 -s -w -f $*.$(TARGET).bin + ${FLASH_PROGRAMMER} -a -c $(DEV_PORT) -B 1000000 -s -w -f $*.$(TARGET).bin else %.flash: ${FLASH_PROGRAMMER} - ${FLASH_PROGRAMMER} -V 10 -v -s $(PORT) -I 38400 -P 1000000 -s -f $*.$(TARGET).bin + ${FLASH_PROGRAMMER} -V 10 -v -s $(DEV_PORT) -I 38400 -P 1000000 -s -f $*.$(TARGET).bin endif ### List the ports with connected jn516x motes @@ -281,7 +280,7 @@ motelistinfo: $(Q)$(MOTELIST) ${FLASH_PROGRAMMER} \? ### Upload target to all connected jn516x motes -%.uploadall: %.$(TARGET).bin +%.uploadall: $(BUILD_DIR_BOARD)/%.$(TARGET).bin $(Q)$(MOTELIST) ${FLASH_PROGRAMMER} $< ### Flash the given file to all connected jn516x motes @@ -297,19 +296,6 @@ serialdumpall: ### UART_BAUDRATE: i.e., 115200. default is 1000000 ### example: make TARGET=jn516x UART_BAUDRATE=115200 login MOTE=1 -UART_BAUDRATE ?= 1000000 - -$(CONTIKI)/tools/tunslip6: $(CONTIKI)/tools/tunslip6.c - ($(MAKE) -C $(CONTIKI)/tools tunslip6 CFLAGS= LDFLAGS= LDLIBS= INCFLAGS=) - -$(SERIALDUMP): $(CONTIKI)/tools/jn516x/serialdump.c - (cd $(CONTIKI)/tools/jn516x; ${MAKE} $(notdir $(SERIALDUMP))) - -login: $(SERIALDUMP) - $(SERIALDUMP) -b${UART_BAUDRATE} $(USBDEVPREFIX)$(PORT) - -serialview: $(SERIALDUMP) - $(SERIALDUMP) -b${UART_BAUDRATE} $(USBDEVPREFIX)$(PORT) | $(CONTIKI)/tools/timestamp - -serialdump: $(SERIALDUMP) - $(SERIALDUMP) -b${UART_BAUDRATE} $(USBDEVPREFIX)$(PORT) | $(CONTIKI)/tools/timestamp | tee serialdump-$(notdir $(PORT))-`date +%Y%m%d-%H%M` +### For the login etc targets +BAUDRATE = 1000000 +PORT = $(USBDEVPREFIX)$(DEV_PORT) diff --git a/arch/platform/jn516x/contiki-conf.h b/arch/platform/jn516x/contiki-conf.h index f8dbdc3e5..e4d741400 100644 --- a/arch/platform/jn516x/contiki-conf.h +++ b/arch/platform/jn516x/contiki-conf.h @@ -40,14 +40,6 @@ #include "jn516x-def.h" -#ifdef RF_CHANNEL -#define MICROMAC_CONF_CHANNEL RF_CHANNEL -#endif - -#ifndef MICROMAC_CONF_CHANNEL -#define MICROMAC_CONF_CHANNEL 26 -#endif - /* Configure radio driver */ #ifndef NETSTACK_CONF_RADIO #define NETSTACK_CONF_RADIO micromac_radio_driver diff --git a/arch/platform/jn516x/dev/micromac-radio.c b/arch/platform/jn516x/dev/micromac-radio.c index 3ebc13578..bad81f4f0 100644 --- a/arch/platform/jn516x/dev/micromac-radio.c +++ b/arch/platform/jn516x/dev/micromac-radio.c @@ -100,11 +100,6 @@ #define MIRCOMAC_CONF_BUF_NUM 2 #endif /* MIRCOMAC_CONF_BUF_NUM */ -/* Init radio channel */ -#ifndef MICROMAC_CONF_CHANNEL -#define MICROMAC_CONF_CHANNEL 26 -#endif - /* Default energy level threshold for clear channel detection */ #ifndef MICROMAC_CONF_CCA_THR #define MICROMAC_CONF_CCA_THR 39 /* approximately -85 dBm */ @@ -135,13 +130,6 @@ #define MICROMAC_CONF_ALWAYS_ON 1 #endif /* MICROMAC_CONF_ALWAYS_ON */ -#define BUSYWAIT_UNTIL(cond, max_time) \ - do { \ - rtimer_clock_t t0; \ - t0 = RTIMER_NOW(); \ - while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (max_time))) ; \ - } while(0) - /* Local variables */ static volatile signed char radio_last_rssi; static volatile uint8_t radio_last_correlation; /* LQI */ @@ -159,7 +147,7 @@ static uint8_t autoack_enabled = MICROMAC_CONF_AUTOACK; static uint8_t send_on_cca = 0; /* Current radio channel */ -static int current_channel = MICROMAC_CONF_CHANNEL; +static int current_channel = IEEE802154_DEFAULT_CHANNEL; /* Current set point tx power Actual tx power may be different. Use get_txpower() for actual power */ @@ -382,14 +370,14 @@ transmit(unsigned short payload_len) (send_on_cca ? E_MMAC_TX_USE_CCA : E_MMAC_TX_NO_CCA)); #endif if(poll_mode) { - BUSYWAIT_UNTIL(u32MMAC_PollInterruptSource(E_MMAC_INT_TX_COMPLETE), MAX_PACKET_DURATION); + RTIMER_BUSYWAIT_UNTIL(u32MMAC_PollInterruptSource(E_MMAC_INT_TX_COMPLETE), MAX_PACKET_DURATION); } else { if(in_ack_transmission) { /* as nested interupts are not possible, the tx flag will never be cleared */ - BUSYWAIT_UNTIL(FALSE, MAX_ACK_DURATION); + RTIMER_BUSYWAIT_UNTIL(FALSE, MAX_ACK_DURATION); } else { /* wait until the tx flag is cleared */ - BUSYWAIT_UNTIL(!tx_in_progress, MAX_PACKET_DURATION); + RTIMER_BUSYWAIT_UNTIL(!tx_in_progress, MAX_PACKET_DURATION); } } diff --git a/arch/platform/jn516x/dev/rtimer-arch.h b/arch/platform/jn516x/dev/rtimer-arch.h index 3ffafeeac..63212566b 100644 --- a/arch/platform/jn516x/dev/rtimer-arch.h +++ b/arch/platform/jn516x/dev/rtimer-arch.h @@ -43,19 +43,15 @@ #include "sys/rtimer.h" -#ifdef RTIMER_CONF_SECOND -# define RTIMER_ARCH_SECOND RTIMER_CONF_SECOND -#else #if RTIMER_USE_32KHZ -# if JN516X_EXTERNAL_CRYSTAL_OSCILLATOR -# define RTIMER_ARCH_SECOND 32768 -# else -# define RTIMER_ARCH_SECOND 32000 +#if JN516X_EXTERNAL_CRYSTAL_OSCILLATOR +#define RTIMER_ARCH_SECOND 32768 +#else +#define RTIMER_ARCH_SECOND 32000 #endif #else /* 32MHz CPU clock => 16MHz timer */ -# define RTIMER_ARCH_SECOND (F_CPU / 2) -#endif +#define RTIMER_ARCH_SECOND (F_CPU / 2) #endif #if RTIMER_USE_32KHZ diff --git a/arch/platform/jn516x/dev/uart-driver.c b/arch/platform/jn516x/dev/uart-driver.c index 31a4b286c..aeeffeeb4 100644 --- a/arch/platform/jn516x/dev/uart-driver.c +++ b/arch/platform/jn516x/dev/uart-driver.c @@ -66,14 +66,6 @@ extern volatile unsigned char xonxoff_state; #endif /* UART_XONXOFF_FLOW_CTRL */ -/*** Macro Definitions ***/ -#define BUSYWAIT_UNTIL(cond, max_time) \ - do { \ - rtimer_clock_t t0; \ - t0 = RTIMER_NOW(); \ - while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (max_time))) ; \ - } while(0) - #define DEBUG_UART_BUFFERED FALSE #define CHAR_DEADLINE (uart_char_delay * 100) @@ -276,7 +268,7 @@ uart_driver_write_with_deadline(uint8_t uart_dev, uint8_t ch) volatile int16_t write = 0; watchdog_periodic(); /* wait until there is space in tx fifo */ - BUSYWAIT_UNTIL(write = (uart_driver_get_tx_fifo_available_space(uart_dev) > 0), + RTIMER_BUSYWAIT_UNTIL(write = (uart_driver_get_tx_fifo_available_space(uart_dev) > 0), CHAR_DEADLINE); /* write only if there is space so we do not get stuck */ if(write) { diff --git a/arch/platform/jn516x/jn516x-def.h b/arch/platform/jn516x/jn516x-def.h index 0c76a4332..a7d8906f9 100644 --- a/arch/platform/jn516x/jn516x-def.h +++ b/arch/platform/jn516x/jn516x-def.h @@ -38,6 +38,10 @@ #undef putchar +/* 1 len byte, 2 bytes CRC */ +#define RADIO_PHY_OVERHEAD 3 +/* 250kbps data rate. One byte = 32us */ +#define RADIO_BYTE_AIR_TIME 32 /* Delay between GO signal and SFD * Measured 153us between GO and preamble. Add 5 bytes (preamble + SFD) air time: 153+5*32 = 313 */ #define RADIO_DELAY_BEFORE_TX ((unsigned)US_TO_RTIMERTICKS(313)) @@ -79,10 +83,6 @@ #define JN516X_EXTERNAL_CRYSTAL_OSCILLATOR (RTIMER_USE_32KHZ || JN516X_SLEEP_ENABLED) #endif /* JN516X_EXTERNAL_CRYSTAL_OSCILLATOR */ -/* Core rtimer.h defaults to 16 bit timer unless RTIMER_CLOCK_DIFF is defined */ -typedef uint32_t rtimer_clock_t; -#define RTIMER_CLOCK_DIFF(a, b) ((int32_t)((a) - (b))) - /* 8ms timer tick */ #define CLOCK_CONF_SECOND 125 diff --git a/arch/platform/jn516x/platform.c b/arch/platform/jn516x/platform.c index 20dabfb61..bc9d7b955 100644 --- a/arch/platform/jn516x/platform.c +++ b/arch/platform/jn516x/platform.c @@ -113,8 +113,7 @@ static uint32_t sleep_start_ticks; #define LOG_LEVEL LOG_LEVEL_MAIN /*---------------------------------------------------------------------------*/ /* Reads MAC from SoC - * Must be called before node_id_restore() - * and network addresses initialization */ + * Must be called before network addresses initialization */ static void init_node_mac(void) { @@ -139,14 +138,9 @@ set_linkaddr(void) #if NETSTACK_CONF_WITH_IPV6 memcpy(addr.u8, node_mac, sizeof(addr.u8)); #else - if(node_id == 0) { - int i; - for(i = 0; i < LINKADDR_SIZE; ++i) { - addr.u8[i] = node_mac[LINKADDR_SIZE - 1 - i]; - } - } else { - addr.u8[0] = node_id & 0xff; - addr.u8[1] = node_id >> 8; + int i; + for(i = 0; i < LINKADDR_SIZE; ++i) { + addr.u8[i] = node_mac[LINKADDR_SIZE - 1 - i]; } #endif linkaddr_set_node_addr(&addr); @@ -164,10 +158,6 @@ xosc_init(void) return bAHI_Set32KhzClockMode(E_AHI_XTAL); } /*---------------------------------------------------------------------------*/ -#if WITH_TINYOS_AUTO_IDS -uint16_t TOS_NODE_ID = 0x1234; /* non-zero */ -uint16_t TOS_LOCAL_ADDRESS = 0x1234; /* non-zero */ -#endif /* WITH_TINYOS_AUTO_IDS */ void platform_init_stage_one(void) { @@ -194,20 +184,6 @@ platform_init_stage_one(void) leds_init(); leds_on(LEDS_ALL); init_node_mac(); - - node_id_restore(); - -#if WITH_TINYOS_AUTO_IDS - node_id = TOS_NODE_ID; -#endif /* WITH_TINYOS_AUTO_IDS */ - /* for setting "hardcoded" IEEE 802.15.4 MAC addresses */ -#ifdef IEEE_802154_MAC_ADDRESS - { - uint8_t ieee[] = IEEE_802154_MAC_ADDRESS; - memcpy(node_mac, ieee, sizeof(uip_lladdr.addr)); - node_mac[7] = node_id & 0xff; - } -#endif } /*---------------------------------------------------------------------------*/ void @@ -225,12 +201,6 @@ platform_init_stage_two(void) void platform_init_stage_three(void) { - if(node_id > 0) { - LOG_INFO("Node id is set to %u.\n", node_id); - } else { - LOG_INFO("Node id is not set.\n"); - } - #ifndef UIP_FALLBACK_INTERFACE uart0_set_input(serial_line_input_byte); serial_line_init(); diff --git a/arch/platform/native/contiki-conf.h b/arch/platform/native/contiki-conf.h index 8d2c13820..e8177d7b2 100644 --- a/arch/platform/native/contiki-conf.h +++ b/arch/platform/native/contiki-conf.h @@ -78,6 +78,19 @@ typedef unsigned int uip_stats_t; #define NETSTACK_CONF_LINUXRADIO_DEV "wpan0" +/* configure network size and density */ +#ifndef NETSTACK_MAX_ROUTE_ENTRIES +#define NETSTACK_MAX_ROUTE_ENTRIES 300 +#endif /* NETSTACK_MAX_ROUTE_ENTRIES */ +#ifndef NBR_TABLE_CONF_MAX_NEIGHBORS +#define NBR_TABLE_CONF_MAX_NEIGHBORS 300 +#endif /* NBR_TABLE_CONF_MAX_NEIGHBORS */ + +/* configure queues */ +#ifndef QUEUEBUF_CONF_NUM +#define QUEUEBUF_CONF_NUM 64 +#endif /* QUEUEBUF_CONF_NUM */ + #define UIP_CONF_IPV6_QUEUE_PKT 1 #define UIP_ARCH_IPCHKSUM 1 diff --git a/arch/platform/native/platform.c b/arch/platform/native/platform.c index c5c4f23e7..d00efaac1 100644 --- a/arch/platform/native/platform.c +++ b/arch/platform/native/platform.c @@ -120,9 +120,6 @@ static uint8_t mac_addr[] = PLATFORM_CONF_MAC_ADDR; static uint8_t mac_addr[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; #endif /* PLATFORM_CONF_MAC_ADDR */ -#if !NETSTACK_CONF_WITH_IPV6 -static uint16_t node_id = 0x0102; -#endif /* !NETSTACK_CONF_WITH_IPV6 */ /*---------------------------------------------------------------------------*/ int select_set_callback(int fd, const struct select_callback *callback) @@ -187,14 +184,9 @@ set_lladdr(void) #if NETSTACK_CONF_WITH_IPV6 memcpy(addr.u8, mac_addr, sizeof(addr.u8)); #else - if(node_id == 0) { - int i; - for(i = 0; i < sizeof(linkaddr_t); ++i) { - addr.u8[i] = mac_addr[7 - i]; - } - } else { - addr.u8[0] = node_id & 0xff; - addr.u8[1] = node_id >> 8; + int i; + for(i = 0; i < sizeof(linkaddr_t); ++i) { + addr.u8[i] = mac_addr[7 - i]; } #endif linkaddr_set_node_addr(&addr); diff --git a/arch/platform/nrf52dk/Makefile.nrf52dk b/arch/platform/nrf52dk/Makefile.nrf52dk index 7e931880a..e1d56c090 100644 --- a/arch/platform/nrf52dk/Makefile.nrf52dk +++ b/arch/platform/nrf52dk/Makefile.nrf52dk @@ -9,12 +9,12 @@ CONTIKI_TARGET_DIRS += . dev config CONTIKI_SOURCEFILES += platform.c leds-arch.c nrf52dk-sensors.c button-sensor.c temperature-sensor.c ifeq ($(NRF52_USE_RTT),1) -### Use the existing debug I/O in arch/cpu/arm/common +### Suppress the existing debug I/O in os/lib +MAKE_WITH_LIB_DBG_IO = 0 CONTIKI_TARGET_DIRS += rtt CONTIKI_SOURCEFILES += rtt-printf.c segger-rtt.c segger-rtt-printf.c else CONTIKI_SOURCEFILES += dbg.c -MODULES += os/lib/dbg-io endif ### Unless the example dictates otherwise, build with code size optimisations switched off diff --git a/arch/platform/openmote-cc2538/Makefile.openmote-cc2538 b/arch/platform/openmote-cc2538/Makefile.openmote-cc2538 index d3863fdbc..8b25b0bfe 100644 --- a/arch/platform/openmote-cc2538/Makefile.openmote-cc2538 +++ b/arch/platform/openmote-cc2538/Makefile.openmote-cc2538 @@ -35,11 +35,12 @@ endif BSL = $(CONTIKI)/tools/cc2538-bsl/cc2538-bsl.py -%.upload: %.bin %.elf +%.upload: $(OUT_BIN) $(OUT_ELF) ifeq ($(wildcard $(BSL)), ) @echo "ERROR: Could not find the cc2538-bsl script. Did you run 'git submodule update --init' ?" else - $(eval BSL_ADDRESS_ARG := -a $(shell $(OBJDUMP) -h $*.elf | grep -B1 LOAD | \ + $(eval BSL_ADDRESS_ARG := -a $(shell $(OBJDUMP) -h \ + $(BUILD_DIR_BOARD)/$*.elf | grep -B1 LOAD | \ grep -Ev 'LOAD|\-\-' | awk '{print "0x" $$5}' | \ sort -g | head -1)) $(PYTHON) $(BSL) $(BSL_FLAGS) $(BSL_ADDRESS_ARG) $< diff --git a/arch/platform/openmote-cc2538/board.h b/arch/platform/openmote-cc2538/board.h index abb89b8e2..6e2a15e46 100644 --- a/arch/platform/openmote-cc2538/board.h +++ b/arch/platform/openmote-cc2538/board.h @@ -174,6 +174,18 @@ #define I2C_SDA_PIN 4 /** @} */ /*---------------------------------------------------------------------------*/ +/** + * \name CC2538 TSCH configuration + * + * @{ + */ +#define RADIO_PHY_OVERHEAD CC2538_PHY_OVERHEAD +#define RADIO_BYTE_AIR_TIME CC2538_BYTE_AIR_TIME +#define RADIO_DELAY_BEFORE_TX CC2538_DELAY_BEFORE_TX +#define RADIO_DELAY_BEFORE_RX CC2538_DELAY_BEFORE_RX +#define RADIO_DELAY_BEFORE_DETECT CC2538_DELAY_BEFORE_DETECT +/** @} */ +/*---------------------------------------------------------------------------*/ /** * \name Device string used on startup * @{ diff --git a/arch/platform/openmote-cc2538/platform.c b/arch/platform/openmote-cc2538/platform.c index c226785c6..4656d2332 100644 --- a/arch/platform/openmote-cc2538/platform.c +++ b/arch/platform/openmote-cc2538/platform.c @@ -115,7 +115,7 @@ set_rf_params(void) NETSTACK_RADIO.set_value(RADIO_PARAM_PAN_ID, IEEE802154_PANID); NETSTACK_RADIO.set_value(RADIO_PARAM_16BIT_ADDR, short_addr); - NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, CC2538_RF_CHANNEL); + NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, IEEE802154_DEFAULT_CHANNEL); NETSTACK_RADIO.set_object(RADIO_PARAM_64BIT_ADDR, ext_addr, 8); } /*---------------------------------------------------------------------------*/ diff --git a/arch/platform/simplelink/Makefile.simplelink b/arch/platform/simplelink/Makefile.simplelink new file mode 100644 index 000000000..acb613d6e --- /dev/null +++ b/arch/platform/simplelink/Makefile.simplelink @@ -0,0 +1,48 @@ +################################################################################ +### SimpleLink MCU platform makefile + +################################################################################ +### Sanity check of expected symbols + +ifndef CONTIKI + $(error 'CONTIKI' not defined! You must specify where CONTIKI resides!) +endif + +BOARD ?= srf06/cc26x0 + +################################################################################ +### Resolve the SimpleLink Family + +SIMPLELINK_FAMILIES := cc13xx-cc26xx + +# Given a SimpleLink family as argument, check if it has the Board file. +# If so, return itself; else, return empty string. +verify_family = $(shell [ -d $(CONTIKI)/arch/platform/simplelink/$(1)/$(BOARD) ] && echo $(1)) + +# Test each supported SimpleLink family and see if it contains the specified Board. +# Throw an error if it isn't found. +FAMILY := $(foreach FAMILY, $(SIMPLELINK_FAMILIES), $(call verify_family,$(FAMILY))) +ifeq ($(strip $(FAMILY)),) + $(error Board '$(BOARD)' does not corresponding to any SimpleLink family. Make sure your BOARD variable is correct.) +endif +# If multiple families are found, only the first one is chosen. If this ever +# happens something is not correct. +ifneq ($(words $(FAMILY)),1) + FAMILY := $(firstword $(FAMILY)) + $(warning Multiple SimpleLink families found to support '$(BOARD)'. Resolve to '$(FAMILY)'.) +endif + +# Remove any excess whitespace. +FAMILY := $(strip $(FAMILY)) + +FAMILY_PATH := $(realpath $(CONTIKI)/arch/platform/simplelink/$(FAMILY)) +CLEAN += *.simplelink + +# Include the Simplelink Family specific Makefile +include $(FAMILY_PATH)/Makefile.$(FAMILY) + +################################################################################ +### SimpleLink targets + +simplelink_families: + @echo "$(SIMPLELINK_FAMILIES) (current: $(FAMILY))" diff --git a/arch/platform/simplelink/cc13xx-cc26xx/Makefile.cc13xx-cc26xx b/arch/platform/simplelink/cc13xx-cc26xx/Makefile.cc13xx-cc26xx new file mode 100644 index 000000000..9f2dbe45b --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/Makefile.cc13xx-cc26xx @@ -0,0 +1,62 @@ +################################################################################ +### SimpleLink MCU platform makefile + +################################################################################ +# Board and BSP selection +BOARD_PLATFORMS = launchpad sensortag srf06 + +# All supported boards for this SimpleLink family +BOARDS = $(foreach BOARD, $(BOARD_PLATFORMS), \ + $(shell cd $(FAMILY_PATH); find $(BOARD)/* -type d -print)) + +################################################################################ +# Directory and source configurations + +# Include the board-specific Makefile +BOARD_PATH := $(FAMILY_PATH)/$(BOARD) +include $(BOARD_PATH)/Makefile.$(notdir $(BOARD)) + +DEVICE_FAMILY_LC := $(shell echo "$(DEVICE_FAMILY)" | tr A-Z a-z) + +# Add to the source dirs +TARGET_FAMILY_DIRS += common +TARGET_FAMILY_DIRS += $(BOARD) + +CONTIKI_TARGET_DIRS += $(FAMILY) +CONTIKI_TARGET_DIRS += $(addprefix $(FAMILY)/, $(TARGET_FAMILY_DIRS)) + +BOARD_DEFINES += DeviceFamily_$(DEVICE_FAMILY) +BOARD_DEFINES += DEVICE_LINE_$(DEVICE_LINE) +BOARD_DEFINES += DEVICE_$(DEVICE) +BOARD_DEFINES += $(BOARD_TYPE) +BOARD_DEFINES += SUPPORTS_PROP_MODE=$(SUPPORTS_PROP_MODE) +BOARD_DEFINES += SUPPORTS_IEEE_MODE=$(SUPPORTS_IEEE_MODE) +BOARD_DEFINES += SUPPORTS_BLE_BEACON=$(SUPPORTS_BLE_BEACON) +BOARD_DEFINES += SUPPORTS_HIGH_PA=$(SUPPORTS_HIGH_PA) + +# If the user-specified a Node ID, pass a define +ifdef NODEID + BOARD_DEFINES += IEEE_ADDR_NODE_ID=$(NODEID) +endif + +CFLAGS += $(addprefix -D, $(BOARD_DEFINES)) + +CONTIKI_TARGET_SOURCEFILES += platform.c +CONTIKI_TARGET_SOURCEFILES += batmon-sensor.c +CONTIKI_TARGET_SOURCEFILES += $(BOARD_SOURCEFILES) + +CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) + +# Pull in the correct CPU makefile +CPU_FAMILY = cc13xx-cc26xx + +# Define the CPU directory and pull in the correct CPU Makefile +CONTIKI_CPU := $(realpath $(CONTIKI)/arch/cpu/simplelink-$(CPU_FAMILY)) +include $(CONTIKI_CPU)/Makefile.$(CPU_FAMILY) + +MODULES += os/net os/net/mac os/net/mac/framer + +################################################################################ +# Display all supported Boards for the given SimpleLink Family +simplelink_boards: + @echo "$(BOARDS) (current: $(BOARD))" diff --git a/arch/platform/simplelink/cc13xx-cc26xx/batmon-sensor.c b/arch/platform/simplelink/cc13xx-cc26xx/batmon-sensor.c new file mode 100644 index 000000000..b0433405d --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/batmon-sensor.c @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-batmon + * @{ + * + * \file + * Driver for the CC13xx/CC26xx AON battery monitor. + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "lib/sensors.h" + +#include "batmon-sensor.h" +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(driverlib/aon_batmon.h) +/*---------------------------------------------------------------------------*/ +#include +#include +/*---------------------------------------------------------------------------*/ +#define DEBUG 0 +#if DEBUG +#define PRINTF(...) printf(__VA_ARGS__) +#else +#define PRINTF(...) +#endif +/*---------------------------------------------------------------------------*/ +#define SENSOR_STATUS_DISABLED 0 +#define SENSOR_STATUS_ENABLED 1 + +static int enabled = SENSOR_STATUS_DISABLED; +/*---------------------------------------------------------------------------*/ +/** + * \brief Returns a reading from the sensor + * \param type BATMON_SENSOR_TYPE_TEMP or BATMON_SENSOR_TYPE_VOLT + * + * \return The value as returned by the respective CC26xxware function + */ +static int +value(int type) +{ + if(enabled == SENSOR_STATUS_DISABLED) { + PRINTF("Sensor Disabled\n"); + return BATMON_SENSOR_READING_ERROR; + } + + switch(type) { + case BATMON_SENSOR_TYPE_TEMP: return (int)AONBatMonTemperatureGetDegC(); + case BATMON_SENSOR_TYPE_VOLT: return (int)AONBatMonBatteryVoltageGet(); + default: + PRINTF("Invalid type\n"); + return BATMON_SENSOR_READING_ERROR; + } +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Configuration function for the battery monitor sensor. + * + * \param type Activate, enable or disable the sensor. See below + * \param enable If + * + * When type == SENSORS_HW_INIT we turn on the hardware + * When type == SENSORS_ACTIVE and enable==1 we enable the sensor + * When type == SENSORS_ACTIVE and enable==0 we disable the sensor + */ +static int +configure(int type, int enable) +{ + switch(type) { + case SENSORS_HW_INIT: + AONBatMonEnable(); + enabled = SENSOR_STATUS_ENABLED; + break; + case SENSORS_ACTIVE: + if(enable) { + AONBatMonEnable(); + enabled = SENSOR_STATUS_ENABLED; + } else { + AONBatMonDisable(); + enabled = SENSOR_STATUS_DISABLED; + } + break; + default: + break; + } + return enabled; +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Returns the status of the sensor + * \param type SENSORS_ACTIVE or SENSORS_READY + * \return 1 if the sensor is enabled + */ +static int +status(int type) +{ + switch(type) { + case SENSORS_ACTIVE: + case SENSORS_READY: + return enabled; + break; + default: + break; + } + return SENSOR_STATUS_DISABLED; +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(batmon_sensor, "Battery Monitor", value, configure, status); +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/batmon-sensor.h b/arch/platform/simplelink/cc13xx-cc26xx/batmon-sensor.h new file mode 100644 index 000000000..569671d8c --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/batmon-sensor.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-platform + * @{ + * + * \defgroup cc13xx-cc26xx-batmon CC13xx/CC26xx Battery Monitor sensor driver. + * + * Driver for the on-chip battery voltage and chip temperature sensor. + * @{ + * + * \file + * Header file for the CC13xx/CC26xx battery monitor. + */ +/*---------------------------------------------------------------------------*/ +#ifndef BATMON_SENSOR_H_ +#define BATMON_SENSOR_H_ +/*---------------------------------------------------------------------------*/ +#define BATMON_SENSOR_TYPE_TEMP 1 +#define BATMON_SENSOR_TYPE_VOLT 2 +/*---------------------------------------------------------------------------*/ +#define BATMON_SENSOR_READING_ERROR -1 +/*---------------------------------------------------------------------------*/ +extern const struct sensors_sensor batmon_sensor; +/*---------------------------------------------------------------------------*/ +#endif /* BATMON_SENSOR_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/contiki-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/contiki-conf.h new file mode 100644 index 000000000..212f4fd48 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/contiki-conf.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-platform + * @{ + * + * \file + * Configuration for the SimpleLink CC13xx/CC26xx platform. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#ifndef CONTIKI_CONF_H_ +#define CONTIKI_CONF_H_ +/*---------------------------------------------------------------------------*/ +#include "board-conf.h" +/*---------------------------------------------------------------------------*/ +/* Include Project Specific conf */ +#ifdef PROJECT_CONF_PATH +#include PROJECT_CONF_PATH +#endif +/*---------------------------------------------------------------------------*/ +/* Include CPU-related configuration */ +#include "cc13xx-cc26xx-conf.h" +/*---------------------------------------------------------------------------*/ +/* Must be included after cc13xx-cc26xx-conf.h */ +#include +/*---------------------------------------------------------------------------*/ +#endif /* CONTIKI_CONF_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/Makefile.launchpad b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/Makefile.launchpad new file mode 100644 index 000000000..66ac2df24 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/Makefile.launchpad @@ -0,0 +1,9 @@ +################################################################################ +# SimpleLink LaunchPad makefile + +BOARD_TYPE = BOARD_LAUNCHPAD + +# leds-arch.c etc. +BOARD_SOURCEFILES += button-sensor-arch.c leds-arch.c + +TARGET_FAMILY_DIRS += launchpad diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/board-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/board-conf.h new file mode 100644 index 000000000..71d59501d --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/board-conf.h @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-platform + * @{ + * + * \defgroup launchpad-peripherals LaunchPad peripherals + * + * Defines related to configuring LaunchPad peripherals. All LaunchPads + * are identical to a very large extent. Everything documented within this + * group applies to both sensortags + * + * @{ + * + * \file + * Header file with definitions related to LaunchPad boards. + * \author + * Edvard Pettersen + * \note + * This file should not be included directly + */ +/*---------------------------------------------------------------------------*/ +#ifndef BOARD_CONF_H_ +#define BOARD_CONF_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki-conf.h" +/*---------------------------------------------------------------------------*/ +/** + * \name LED configurations for the dev/leds.h API. + * + * Those values are not meant to be modified by the user + * @{ + */ +#define PLATFORM_HAS_LEDS 1 + +#define LEDS_CONF_COUNT 2 + +#define LEDS_CONF_RED 0 +#define LEDS_CONF_GREEN 1 + +#define LEDS_CONF_ALL ((1 << LEDS_CONF_COUNT) - 1) +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name Button configurations for the dev/button-hal.h API. + * + * Those values are not meant to be modified by the user + * @{ + */ +#define PLATFORM_HAS_BUTTON 1 +#define PLATFORM_SUPPORTS_BUTTON_HAL 1 + +#define BUTTON_HAL_ID_KEY_LEFT 0 +#define BUTTON_HAL_ID_KEY_RIGHT 1 +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name LaunchPad does not have any sensors. + * + * Those values are not meant to be modified by the user + * @{ + */ +#define BOARD_CONF_HAS_SENSORS 0 +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name The external flash SPI CS pin, defined in Board.h. + * + * Note that SPI SCK, MOSI and MISO does not need to be defined, as they are + * implicitly defined via the Board_SPI0 controller. + * + * Those values are not meant to be modified by the user + * @{ + */ +#if TI_SPI_CONF_SPI0_ENABLE +#define EXT_FLASH_SPI_CONTROLLER Board_SPI0 + +#define EXT_FLASH_SPI_PIN_SCK Board_SPI0_SCK +#define EXT_FLASH_SPI_PIN_MOSI Board_SPI0_MOSI +#define EXT_FLASH_SPI_PIN_MISO Board_SPI0_MISO +#define EXT_FLASH_SPI_PIN_CS Board_SPI_FLASH_CS + +#define EXT_FLASH_DEVICE_ID 0x14 +#define EXT_FLASH_MID 0xC2 + +#define EXT_FLASH_PROGRAM_PAGE_SIZE 256 +#define EXT_FLASH_ERASE_SECTOR_SIZE 4096 +#endif /* TI_SPI_CONF_SPI0_ENABLE */ +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* BOARD_CONF_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/board-peripherals.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/board-peripherals.h new file mode 100644 index 000000000..528ddb26f --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/board-peripherals.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-platform + * @{ + * + * \defgroup launchpad-peripherals LaunchPad peripherals + * + * Defines related to configuring LaunchPad peripherals. All + * LaunchPads are identical to a very large extent. Everything + * documented within this group applies to all LaunchPads. + * + * @{ + * + * \file + * Header file with definitions related to LaunchPad boards. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#ifndef BOARD_PERIPHERALS_H_ +#define BOARD_PERIPHERALS_H_ +/*---------------------------------------------------------------------------*/ +#include "board-conf.h" +/*---------------------------------------------------------------------------*/ +#endif /* BOARD_PERIPHERALS_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/button-sensor-arch.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/button-sensor-arch.c new file mode 100644 index 000000000..41bfef92e --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/button-sensor-arch.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup launchpad-peripherals + * @{ + * + * \file + * Button HAL definitions for the LaunchPad buttons. Common across + * all CC13xx/CC26xx LaunchPad boards. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/button-hal.h" +/*---------------------------------------------------------------------------*/ +#include +/*---------------------------------------------------------------------------*/ +/* Key left button, AKA BTN-1. */ +BUTTON_HAL_BUTTON( + key_left, /**< Name */ + "Key Left", /**< Description */ + Board_PIN_BTN1, /**< Board PIN */ + GPIO_HAL_PIN_CFG_PULL_UP | + GPIO_HAL_PIN_CFG_HYSTERESIS, /**< Pull configuration */ + BUTTON_HAL_ID_KEY_LEFT, /**< Unique ID */ + true); /**< Negative logic */ + +/* Key right button, AKA BTN-2. */ +BUTTON_HAL_BUTTON( + key_right, /**< Name */ + "Key Right", /**< Description */ + Board_PIN_BTN2, /**< Board PIN */ + GPIO_HAL_PIN_CFG_PULL_UP | + GPIO_HAL_PIN_CFG_HYSTERESIS, /**< Pull configuration */ + BUTTON_HAL_ID_KEY_RIGHT, /**< Unique ID */ + true); /**< Negative logic */ +/*---------------------------------------------------------------------------*/ +BUTTON_HAL_BUTTONS(&key_left, &key_right); +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/Board.h new file mode 100644 index 000000000..6b3c762d7 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/Board.h @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2015-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 __BOARD_H +#define __BOARD_H + +#define Board_CC1310_LAUNCHXL +#define BOARD_STRING "TI CC1310 LaunchPad" + +#ifdef __cplusplus +extern "C" { +#endif + +#include "CC1310_LAUNCHXL.h" + +#define Board_initGeneral() CC1310_LAUNCHXL_initGeneral() +#define Board_shutDownExtFlash() CC1310_LAUNCHXL_shutDownExtFlash() +#define Board_wakeUpExtFlash() CC1310_LAUNCHXL_wakeUpExtFlash() + +/* These #defines allow us to reuse TI-RTOS across other device families */ + +#define Board_ADC0 CC1310_LAUNCHXL_ADC0 +#define Board_ADC1 CC1310_LAUNCHXL_ADC1 + +#define Board_ADCBUF0 CC1310_LAUNCHXL_ADCBUF0 +#define Board_ADCBUF0CHANNEL0 CC1310_LAUNCHXL_ADCBUF0CHANNEL0 +#define Board_ADCBUF0CHANNEL1 CC1310_LAUNCHXL_ADCBUF0CHANNEL1 + +#define Board_CRYPTO0 CC1310_LAUNCHXL_CRYPTO0 + +#define Board_DIO0 CC1310_LAUNCHXL_DIO0 +#define Board_DIO1 CC1310_LAUNCHXL_DIO1 +#define Board_DIO12 CC1310_LAUNCHXL_DIO12 +#define Board_DIO15 CC1310_LAUNCHXL_DIO15 +#define Board_DIO16_TDO CC1310_LAUNCHXL_DIO16_TDO +#define Board_DIO17_TDI CC1310_LAUNCHXL_DIO17_TDI +#define Board_DIO21 CC1310_LAUNCHXL_DIO21 +#define Board_DIO22 CC1310_LAUNCHXL_DIO22 + +#define Board_GPIO_BUTTON0 CC1310_LAUNCHXL_GPIO_S1 +#define Board_GPIO_BUTTON1 CC1310_LAUNCHXL_GPIO_S2 +#define Board_GPIO_BTN1 CC1310_LAUNCHXL_GPIO_S1 +#define Board_GPIO_BTN2 CC1310_LAUNCHXL_GPIO_S2 +#define Board_GPIO_LED0 CC1310_LAUNCHXL_GPIO_LED_RED +#define Board_GPIO_LED1 CC1310_LAUNCHXL_GPIO_LED_GREEN +#define Board_GPIO_RLED CC1310_LAUNCHXL_GPIO_LED_RED +#define Board_GPIO_GLED CC1310_LAUNCHXL_GPIO_LED_GREEN +#define Board_GPIO_LED_ON CC1310_LAUNCHXL_GPIO_LED_ON +#define Board_GPIO_LED_OFF CC1310_LAUNCHXL_GPIO_LED_OFF + +#define Board_GPTIMER0A CC1310_LAUNCHXL_GPTIMER0A +#define Board_GPTIMER0B CC1310_LAUNCHXL_GPTIMER0B +#define Board_GPTIMER1A CC1310_LAUNCHXL_GPTIMER1A +#define Board_GPTIMER1B CC1310_LAUNCHXL_GPTIMER1B +#define Board_GPTIMER2A CC1310_LAUNCHXL_GPTIMER2A +#define Board_GPTIMER2B CC1310_LAUNCHXL_GPTIMER2B +#define Board_GPTIMER3A CC1310_LAUNCHXL_GPTIMER3A +#define Board_GPTIMER3B CC1310_LAUNCHXL_GPTIMER3B + +#define Board_I2C0 CC1310_LAUNCHXL_I2C0 +#define Board_I2C_TMP CC1310_LAUNCHXL_I2C0 + +#define Board_NVSINTERNAL CC1310_LAUNCHXL_NVSCC26XX0 +#define Board_NVSEXTERNAL CC1310_LAUNCHXL_NVSSPI25X0 + +#define Board_PIN_BUTTON0 CC1310_LAUNCHXL_PIN_BTN1 +#define Board_PIN_BUTTON1 CC1310_LAUNCHXL_PIN_BTN2 +#define Board_PIN_BTN1 CC1310_LAUNCHXL_PIN_BTN1 +#define Board_PIN_BTN2 CC1310_LAUNCHXL_PIN_BTN2 +#define Board_PIN_LED0 CC1310_LAUNCHXL_PIN_RLED +#define Board_PIN_LED1 CC1310_LAUNCHXL_PIN_GLED +#define Board_PIN_LED2 CC1310_LAUNCHXL_PIN_RLED +#define Board_PIN_RLED CC1310_LAUNCHXL_PIN_RLED +#define Board_PIN_GLED CC1310_LAUNCHXL_PIN_GLED + +#define Board_PWM0 CC1310_LAUNCHXL_PWM0 +#define Board_PWM1 CC1310_LAUNCHXL_PWM1 +#define Board_PWM2 CC1310_LAUNCHXL_PWM2 +#define Board_PWM3 CC1310_LAUNCHXL_PWM3 +#define Board_PWM4 CC1310_LAUNCHXL_PWM4 +#define Board_PWM5 CC1310_LAUNCHXL_PWM5 +#define Board_PWM6 CC1310_LAUNCHXL_PWM6 +#define Board_PWM7 CC1310_LAUNCHXL_PWM7 + +#define Board_SD0 CC1310_LAUNCHXL_SDSPI0 + +#define Board_SPI0 CC1310_LAUNCHXL_SPI0 +#define Board_SPI0_MISO CC1310_LAUNCHXL_SPI0_MISO +#define Board_SPI0_MOSI CC1310_LAUNCHXL_SPI0_MOSI +#define Board_SPI0_CLK CC1310_LAUNCHXL_SPI0_CLK +#define Board_SPI0_CSN CC1310_LAUNCHXL_SPI0_CSN +#define Board_SPI1 CC1310_LAUNCHXL_SPI1 +#define Board_SPI1_MISO CC1310_LAUNCHXL_SPI1_MISO +#define Board_SPI1_MOSI CC1310_LAUNCHXL_SPI1_MOSI +#define Board_SPI1_CLK CC1310_LAUNCHXL_SPI1_CLK +#define Board_SPI1_CSN CC1310_LAUNCHXL_SPI1_CSN +#define Board_SPI_FLASH_CS CC1310_LAUNCHXL_SPI_FLASH_CS +#define Board_FLASH_CS_ON 0 +#define Board_FLASH_CS_OFF 1 + +#define Board_SPI_MASTER CC1310_LAUNCHXL_SPI0 +#define Board_SPI_SLAVE CC1310_LAUNCHXL_SPI0 +#define Board_SPI_MASTER_READY CC1310_LAUNCHXL_SPI_MASTER_READY +#define Board_SPI_SLAVE_READY CC1310_LAUNCHXL_SPI_SLAVE_READY + +#define Board_UART0 CC1310_LAUNCHXL_UART0 + +#define Board_WATCHDOG0 CC1310_LAUNCHXL_WATCHDOG0 + +/* Board specific I2C addresses */ +#define Board_TMP_ADDR (0x40) +#define Board_SENSORS_BP_TMP_ADDR Board_TMP_ADDR + +#ifdef __cplusplus +} +#endif + +#endif /* __BOARD_H */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/CC1310_LAUNCHXL.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/CC1310_LAUNCHXL.c new file mode 100644 index 000000000..b33dab9ad --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/CC1310_LAUNCHXL.c @@ -0,0 +1,820 @@ +/* + * Copyright (c) 2015-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +/* + * ====================== CC1310_LAUNCHXL.c =================================== + * This file is responsible for setting up the board specific items for the + * CC1310_LAUNCHXL board. + */ + +#include +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/udma.h) +#include DeviceFamily_constructPath(inc/hw_ints.h) +#include DeviceFamily_constructPath(inc/hw_memmap.h) + +#include "CC1310_LAUNCHXL.h" + +/* + * =============================== ADCBuf =============================== + */ +#include +#include + +ADCBufCC26XX_Object adcBufCC26xxObjects[CC1310_LAUNCHXL_ADCBUFCOUNT]; + +/* + * This table converts a virtual adc channel into a dio and internal analogue + * input signal. This table is necessary for the functioning of the adcBuf + * driver. Comment out unused entries to save flash. Dio and internal signal + * pairs are hardwired. Do not remap them in the table. You may reorder entire + * entries. The mapping of dio and internal signals is package dependent. + */ +const ADCBufCC26XX_AdcChannelLutEntry ADCBufCC26XX_adcChannelLut[CC1310_LAUNCHXL_ADCBUF0CHANNELCOUNT] = { + {CC1310_LAUNCHXL_DIO23_ANALOG, ADC_COMPB_IN_AUXIO7}, + {CC1310_LAUNCHXL_DIO24_ANALOG, ADC_COMPB_IN_AUXIO6}, + {CC1310_LAUNCHXL_DIO25_ANALOG, ADC_COMPB_IN_AUXIO5}, + {CC1310_LAUNCHXL_DIO26_ANALOG, ADC_COMPB_IN_AUXIO4}, + {CC1310_LAUNCHXL_DIO27_ANALOG, ADC_COMPB_IN_AUXIO3}, + {CC1310_LAUNCHXL_DIO28_ANALOG, ADC_COMPB_IN_AUXIO2}, + {CC1310_LAUNCHXL_DIO29_ANALOG, ADC_COMPB_IN_AUXIO1}, + {CC1310_LAUNCHXL_DIO30_ANALOG, ADC_COMPB_IN_AUXIO0}, + {PIN_UNASSIGNED, ADC_COMPB_IN_VDDS}, + {PIN_UNASSIGNED, ADC_COMPB_IN_DCOUPL}, + {PIN_UNASSIGNED, ADC_COMPB_IN_VSS}, +}; + +const ADCBufCC26XX_HWAttrs adcBufCC26xxHWAttrs[CC1310_LAUNCHXL_ADCBUFCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + .adcChannelLut = ADCBufCC26XX_adcChannelLut, + .gpTimerUnit = CC1310_LAUNCHXL_GPTIMER0A, + .gptDMAChannelMask = 1 << UDMA_CHAN_TIMER0_A, + } +}; + +const ADCBuf_Config ADCBuf_config[CC1310_LAUNCHXL_ADCBUFCOUNT] = { + { + &ADCBufCC26XX_fxnTable, + &adcBufCC26xxObjects[CC1310_LAUNCHXL_ADCBUF0], + &adcBufCC26xxHWAttrs[CC1310_LAUNCHXL_ADCBUF0] + }, +}; + +const uint_least8_t ADCBuf_count = CC1310_LAUNCHXL_ADCBUFCOUNT; + +/* + * =============================== ADC =============================== + */ +#include +#include + +ADCCC26XX_Object adcCC26xxObjects[CC1310_LAUNCHXL_ADCCOUNT]; + + +const ADCCC26XX_HWAttrs adcCC26xxHWAttrs[CC1310_LAUNCHXL_ADCCOUNT] = { + { + .adcDIO = CC1310_LAUNCHXL_DIO23_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO7, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1310_LAUNCHXL_DIO24_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO6, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1310_LAUNCHXL_DIO25_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO5, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1310_LAUNCHXL_DIO26_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO4, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1310_LAUNCHXL_DIO27_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO3, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1310_LAUNCHXL_DIO28_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO2, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1310_LAUNCHXL_DIO29_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO1, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1310_LAUNCHXL_DIO30_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO0, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_10P9_MS, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_DCOUPL, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_VSS, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_VDDS, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + } +}; + +const ADC_Config ADC_config[CC1310_LAUNCHXL_ADCCOUNT] = { + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1310_LAUNCHXL_ADC0], &adcCC26xxHWAttrs[CC1310_LAUNCHXL_ADC0]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1310_LAUNCHXL_ADC1], &adcCC26xxHWAttrs[CC1310_LAUNCHXL_ADC1]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1310_LAUNCHXL_ADC2], &adcCC26xxHWAttrs[CC1310_LAUNCHXL_ADC2]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1310_LAUNCHXL_ADC3], &adcCC26xxHWAttrs[CC1310_LAUNCHXL_ADC3]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1310_LAUNCHXL_ADC4], &adcCC26xxHWAttrs[CC1310_LAUNCHXL_ADC4]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1310_LAUNCHXL_ADC5], &adcCC26xxHWAttrs[CC1310_LAUNCHXL_ADC5]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1310_LAUNCHXL_ADC6], &adcCC26xxHWAttrs[CC1310_LAUNCHXL_ADC6]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1310_LAUNCHXL_ADC7], &adcCC26xxHWAttrs[CC1310_LAUNCHXL_ADC7]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1310_LAUNCHXL_ADCDCOUPL], &adcCC26xxHWAttrs[CC1310_LAUNCHXL_ADCDCOUPL]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1310_LAUNCHXL_ADCVSS], &adcCC26xxHWAttrs[CC1310_LAUNCHXL_ADCVSS]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1310_LAUNCHXL_ADCVDDS], &adcCC26xxHWAttrs[CC1310_LAUNCHXL_ADCVDDS]}, +}; + +const uint_least8_t ADC_count = CC1310_LAUNCHXL_ADCCOUNT; + +/* + * =============================== Crypto =============================== + */ +#include + +CryptoCC26XX_Object cryptoCC26XXObjects[CC1310_LAUNCHXL_CRYPTOCOUNT]; + +const CryptoCC26XX_HWAttrs cryptoCC26XXHWAttrs[CC1310_LAUNCHXL_CRYPTOCOUNT] = { + { + .baseAddr = CRYPTO_BASE, + .powerMngrId = PowerCC26XX_PERIPH_CRYPTO, + .intNum = INT_CRYPTO_RESULT_AVAIL_IRQ, + .intPriority = ~0, + } +}; + +const CryptoCC26XX_Config CryptoCC26XX_config[CC1310_LAUNCHXL_CRYPTOCOUNT] = { + { + .object = &cryptoCC26XXObjects[CC1310_LAUNCHXL_CRYPTO0], + .hwAttrs = &cryptoCC26XXHWAttrs[CC1310_LAUNCHXL_CRYPTO0] + } +}; + +/* + * =============================== GPIO =============================== + */ +#include +#include + +/* + * Array of Pin configurations + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC1310_LAUNCHXL.h + * NOTE: Pins not used for interrupts should be placed at the end of the + * array. Callback entries can be omitted from callbacks array to + * reduce memory usage. + */ +GPIO_PinConfig gpioPinConfigs[] = { + /* Input pins */ + GPIOCC26XX_DIO_13 | GPIO_DO_NOT_CONFIG, /* Button 0 */ + GPIOCC26XX_DIO_14 | GPIO_DO_NOT_CONFIG, /* Button 1 */ + + GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG, /* CC1310_LAUNCHXL_SPI_MASTER_READY */ + GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG, /* CC1310_LAUNCHXL_SPI_SLAVE_READY */ + + /* Output pins */ + GPIOCC26XX_DIO_07 | GPIO_DO_NOT_CONFIG, /* Green LED */ + GPIOCC26XX_DIO_06 | GPIO_DO_NOT_CONFIG, /* Red LED */ + + /* SPI Flash CSN */ + GPIOCC26XX_DIO_20 | GPIO_DO_NOT_CONFIG, + + /* SD CS */ + GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG, +}; + +/* + * Array of callback function pointers + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC1310_LAUNCH.h + * NOTE: Pins not used for interrupts can be omitted from callbacks array to + * reduce memory usage (if placed at end of gpioPinConfigs array). + */ +GPIO_CallbackFxn gpioCallbackFunctions[] = { + NULL, /* Button 0 */ + NULL, /* Button 1 */ + NULL, /* CC1310_LAUNCHXL_SPI_MASTER_READY */ + NULL, /* CC1310_LAUNCHXL_SPI_SLAVE_READY */ +}; + +const GPIOCC26XX_Config GPIOCC26XX_config = { + .pinConfigs = (GPIO_PinConfig *)gpioPinConfigs, + .callbacks = (GPIO_CallbackFxn *)gpioCallbackFunctions, + .numberOfPinConfigs = CC1310_LAUNCHXL_GPIOCOUNT, + .numberOfCallbacks = sizeof(gpioCallbackFunctions)/sizeof(GPIO_CallbackFxn), + .intPriority = (~0) +}; + +/* + * =============================== GPTimer =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include + +GPTimerCC26XX_Object gptimerCC26XXObjects[CC1310_LAUNCHXL_GPTIMERCOUNT]; + +const GPTimerCC26XX_HWAttrs gptimerCC26xxHWAttrs[CC1310_LAUNCHXL_GPTIMERPARTSCOUNT] = { + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0A, }, + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0B, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1A, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1B, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2A, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2B, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3A, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3B, }, +}; + +const GPTimerCC26XX_Config GPTimerCC26XX_config[CC1310_LAUNCHXL_GPTIMERPARTSCOUNT] = { + { &gptimerCC26XXObjects[CC1310_LAUNCHXL_GPTIMER0], &gptimerCC26xxHWAttrs[CC1310_LAUNCHXL_GPTIMER0A], GPT_A }, + { &gptimerCC26XXObjects[CC1310_LAUNCHXL_GPTIMER0], &gptimerCC26xxHWAttrs[CC1310_LAUNCHXL_GPTIMER0B], GPT_B }, + { &gptimerCC26XXObjects[CC1310_LAUNCHXL_GPTIMER1], &gptimerCC26xxHWAttrs[CC1310_LAUNCHXL_GPTIMER1A], GPT_A }, + { &gptimerCC26XXObjects[CC1310_LAUNCHXL_GPTIMER1], &gptimerCC26xxHWAttrs[CC1310_LAUNCHXL_GPTIMER1B], GPT_B }, + { &gptimerCC26XXObjects[CC1310_LAUNCHXL_GPTIMER2], &gptimerCC26xxHWAttrs[CC1310_LAUNCHXL_GPTIMER2A], GPT_A }, + { &gptimerCC26XXObjects[CC1310_LAUNCHXL_GPTIMER2], &gptimerCC26xxHWAttrs[CC1310_LAUNCHXL_GPTIMER2B], GPT_B }, + { &gptimerCC26XXObjects[CC1310_LAUNCHXL_GPTIMER3], &gptimerCC26xxHWAttrs[CC1310_LAUNCHXL_GPTIMER3A], GPT_A }, + { &gptimerCC26XXObjects[CC1310_LAUNCHXL_GPTIMER3], &gptimerCC26xxHWAttrs[CC1310_LAUNCHXL_GPTIMER3B], GPT_B }, +}; + +/* + * =============================== I2C =============================== +*/ +#include +#include + +#if TI_I2C_CONF_ENABLE + +I2CCC26XX_Object i2cCC26xxObjects[CC1310_LAUNCHXL_I2CCOUNT]; + +const I2CCC26XX_HWAttrsV1 i2cCC26xxHWAttrs[CC1310_LAUNCHXL_I2CCOUNT] = { +#if TI_I2C_CONF_I2C0_ENABLE + { + .baseAddr = I2C0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_I2C0, + .intNum = INT_I2C_IRQ, + .intPriority = ~0, + .swiPriority = 0, + .sdaPin = CC1310_LAUNCHXL_I2C0_SDA0, + .sclPin = CC1310_LAUNCHXL_I2C0_SCL0, + }, +#endif +}; + +const I2C_Config I2C_config[CC1310_LAUNCHXL_I2CCOUNT] = { +#if TI_I2C_CONF_I2C0_ENABLE + { + .fxnTablePtr = &I2CCC26XX_fxnTable, + .object = &i2cCC26xxObjects[CC1310_LAUNCHXL_I2C0], + .hwAttrs = &i2cCC26xxHWAttrs[CC1310_LAUNCHXL_I2C0] + }, +#endif +}; + +const uint_least8_t I2C_count = CC1310_LAUNCHXL_I2CCOUNT; + +#endif /* TI_I2C_CONF_ENABLE */ + +/* + * =============================== NVS =============================== + */ +#include +#include +#include + +#define NVS_REGIONS_BASE 0x1A000 +#define SECTORSIZE 0x1000 +#define REGIONSIZE (SECTORSIZE * 4) + +#if TI_NVS_CONF_ENABLE + +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + +/* + * Reserve flash sectors for NVS driver use by placing an uninitialized byte + * array at the desired flash address. + */ +#if defined(__TI_COMPILER_VERSION__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +#pragma LOCATION(flashBuf, NVS_REGIONS_BASE); +#pragma NOINIT(flashBuf); +static char flashBuf[REGIONSIZE]; + +#elif defined(__IAR_SYSTEMS_ICC__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +static __no_init char flashBuf[REGIONSIZE] @ NVS_REGIONS_BASE; + +#elif defined(__GNUC__) + +/* + * Place the flash buffers in the .nvs section created in the gcc linker file. + * The .nvs section enforces alignment on a sector boundary but may + * be placed anywhere in flash memory. If desired the .nvs section can be set + * to a fixed address by changing the following in the gcc linker file: + * + * .nvs (FIXED_FLASH_ADDR) (NOLOAD) : AT (FIXED_FLASH_ADDR) { + * *(.nvs) + * } > REGION_TEXT + */ +__attribute__ ((section (".nvs"))) +static char flashBuf[REGIONSIZE]; + +#endif + +/* Allocate objects for NVS Internal Regions */ +NVSCC26XX_Object nvsCC26xxObjects[1]; + +/* Hardware attributes for NVS Internal Regions */ +const NVSCC26XX_HWAttrs nvsCC26xxHWAttrs[1] = { + { + .regionBase = (void *)flashBuf, + .regionSize = REGIONSIZE, + }, +}; + +#endif /* TI_NVS_CONF_NVS_INTERNAL_ENABLE */ + +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + +#define SPISECTORSIZE 0x1000 +#define SPIREGIONSIZE (SPISECTORSIZE * 32) +#define VERIFYBUFSIZE 64 + +static uint8_t verifyBuf[VERIFYBUFSIZE]; + +/* Allocate objects for NVS External Regions */ +NVSSPI25X_Object nvsSPI25XObjects[1]; + +/* Hardware attributes for NVS External Regions */ +const NVSSPI25X_HWAttrs nvsSPI25XHWAttrs[1] = { + { + .regionBaseOffset = 0, + .regionSize = SPIREGIONSIZE, + .sectorSize = SPISECTORSIZE, + .verifyBuf = verifyBuf, + .verifyBufSize = VERIFYBUFSIZE, + .spiHandle = NULL, + .spiIndex = 0, + .spiBitRate = 4000000, + .spiCsnGpioIndex = CC1310_LAUNCHXL_GPIO_SPI_FLASH_CS, + }, +}; + +#endif /* TI_NVS_CONF_NVS_EXTERNAL_ENABLE */ + +/* NVS Region index 0 and 1 refer to NVS and NVS SPI respectively */ +const NVS_Config NVS_config[CC1310_LAUNCHXL_NVSCOUNT] = { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + { + .fxnTablePtr = &NVSCC26XX_fxnTable, + .object = &nvsCC26xxObjects[0], + .hwAttrs = &nvsCC26xxHWAttrs[0], + }, +#endif +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + { + .fxnTablePtr = &NVSSPI25X_fxnTable, + .object = &nvsSPI25XObjects[0], + .hwAttrs = &nvsSPI25XHWAttrs[0], + }, +#endif +}; + +const uint_least8_t NVS_count = CC1310_LAUNCHXL_NVSCOUNT; + +#endif /* TI_NVS_CONF_ENABLE */ + +/* + * =============================== PIN =============================== + */ +#include +#include + +const PIN_Config BoardGpioInitTable[] = { + + CC1310_LAUNCHXL_PIN_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC1310_LAUNCHXL_PIN_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC1310_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC1310_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC1310_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ + CC1310_LAUNCHXL_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */ + CC1310_LAUNCHXL_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */ + CC1310_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */ + CC1310_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */ + CC1310_LAUNCHXL_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI clock */ + + PIN_TERMINATE +}; + +const PINCC26XX_HWAttrs PINCC26XX_hwAttrs = { + .intPriority = ~0, + .swiPriority = 0 +}; + +/* + * =============================== Power =============================== + */ +#include +#include + +const PowerCC26XX_Config PowerCC26XX_config = { + .policyInitFxn = NULL, + .policyFxn = &PowerCC26XX_standbyPolicy, + .calibrateFxn = &PowerCC26XX_calibrate, + .enablePolicy = true, + .calibrateRCOSC_LF = true, + .calibrateRCOSC_HF = true, +}; + +/* + * =============================== PWM =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include +#include + +PWMTimerCC26XX_Object pwmtimerCC26xxObjects[CC1310_LAUNCHXL_PWMCOUNT]; + +const PWMTimerCC26XX_HwAttrs pwmtimerCC26xxHWAttrs[CC1310_LAUNCHXL_PWMCOUNT] = { + { .pwmPin = CC1310_LAUNCHXL_PWMPIN0, .gpTimerUnit = CC1310_LAUNCHXL_GPTIMER0A }, + { .pwmPin = CC1310_LAUNCHXL_PWMPIN1, .gpTimerUnit = CC1310_LAUNCHXL_GPTIMER0B }, + { .pwmPin = CC1310_LAUNCHXL_PWMPIN2, .gpTimerUnit = CC1310_LAUNCHXL_GPTIMER1A }, + { .pwmPin = CC1310_LAUNCHXL_PWMPIN3, .gpTimerUnit = CC1310_LAUNCHXL_GPTIMER1B }, + { .pwmPin = CC1310_LAUNCHXL_PWMPIN4, .gpTimerUnit = CC1310_LAUNCHXL_GPTIMER2A }, + { .pwmPin = CC1310_LAUNCHXL_PWMPIN5, .gpTimerUnit = CC1310_LAUNCHXL_GPTIMER2B }, + { .pwmPin = CC1310_LAUNCHXL_PWMPIN6, .gpTimerUnit = CC1310_LAUNCHXL_GPTIMER3A }, + { .pwmPin = CC1310_LAUNCHXL_PWMPIN7, .gpTimerUnit = CC1310_LAUNCHXL_GPTIMER3B }, +}; + +const PWM_Config PWM_config[CC1310_LAUNCHXL_PWMCOUNT] = { + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1310_LAUNCHXL_PWM0], &pwmtimerCC26xxHWAttrs[CC1310_LAUNCHXL_PWM0] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1310_LAUNCHXL_PWM1], &pwmtimerCC26xxHWAttrs[CC1310_LAUNCHXL_PWM1] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1310_LAUNCHXL_PWM2], &pwmtimerCC26xxHWAttrs[CC1310_LAUNCHXL_PWM2] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1310_LAUNCHXL_PWM3], &pwmtimerCC26xxHWAttrs[CC1310_LAUNCHXL_PWM3] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1310_LAUNCHXL_PWM4], &pwmtimerCC26xxHWAttrs[CC1310_LAUNCHXL_PWM4] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1310_LAUNCHXL_PWM5], &pwmtimerCC26xxHWAttrs[CC1310_LAUNCHXL_PWM5] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1310_LAUNCHXL_PWM6], &pwmtimerCC26xxHWAttrs[CC1310_LAUNCHXL_PWM6] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1310_LAUNCHXL_PWM7], &pwmtimerCC26xxHWAttrs[CC1310_LAUNCHXL_PWM7] }, +}; + +const uint_least8_t PWM_count = CC1310_LAUNCHXL_PWMCOUNT; + +/* + * =============================== RF Driver =============================== + */ +#include + +const RFCC26XX_HWAttrsV2 RFCC26XX_hwAttrs = { + .hwiPriority = ~0, /* Lowest HWI priority */ + .swiPriority = 0, /* Lowest SWI priority */ + .xoscHfAlwaysNeeded = true, /* Keep XOSC dependency while in stanby */ + .globalCallback = NULL, /* No board specific callback */ + .globalEventMask = 0 /* No events subscribed to */ +}; + +/* + * =============================== SD =============================== + */ +#include +#include + +#if TI_SD_CONF_ENABLE + +#if !(TI_SPI_CONF_SPI0_ENABLE) +#error "SD driver requires SPI0 enabled" +#endif + +SDSPI_Object sdspiObjects[CC1310_LAUNCHXL_SDCOUNT]; + +const SDSPI_HWAttrs sdspiHWAttrs[CC1310_LAUNCHXL_SDCOUNT] = { + { + .spiIndex = CC1310_LAUNCHXL_SPI0, + .spiCsGpioIndex = CC1310_LAUNCHXL_SDSPI_CS + } +}; + +const SD_Config SD_config[CC1310_LAUNCHXL_SDCOUNT] = { + { + .fxnTablePtr = &SDSPI_fxnTable, + .object = &sdspiObjects[CC1310_LAUNCHXL_SDSPI0], + .hwAttrs = &sdspiHWAttrs[CC1310_LAUNCHXL_SDSPI0] + }, +}; + +const uint_least8_t SD_count = CC1310_LAUNCHXL_SDCOUNT; + +#endif /* TI_SD_CONF_ENABLE */ + +/* + * =============================== SPI DMA =============================== + */ +#include +#include + +#if TI_SPI_CONF_ENABLE + +SPICC26XXDMA_Object spiCC26XXDMAObjects[CC1310_LAUNCHXL_SPICOUNT]; + +/* + * NOTE: The SPI instances below can be used by the SD driver to communicate + * with a SD card via SPI. The 'defaultTxBufValue' fields below are set to 0xFF + * to satisfy the SDSPI driver requirement. + */ +const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[CC1310_LAUNCHXL_SPICOUNT] = { +#if TI_SPI_CONF_SPI0_ENABLE + { + .baseAddr = SSI0_BASE, + .intNum = INT_SSI0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .powerMngrId = PowerCC26XX_PERIPH_SSI0, + .defaultTxBufValue = 0xFF, + .rxChannelBitMask = 1< +#include + +TRNGCC26X0_Object trngCC26X0Object[CC1310_LAUNCHXL_TRNGCOUNT]; + +const TRNGCC26X0_HWAttrs trngCC26X0HWAttrs[CC1310_LAUNCHXL_TRNGCOUNT] = { + { + .swiPriority = 0, + .intPriority = ~0, + } +}; + +const TRNG_Config TRNG_config[] = { + { &trngCC26X0Object[0], &trngCC26X0HWAttrs[0] }, +}; + +const uint8_t TRNG_count = CC1310_LAUNCHXL_TRNGCOUNT; + + +/* + * =============================== UART =============================== + */ +#include +#include + +#if TI_UART_CONF_ENABLE + +UARTCC26XX_Object uartCC26XXObjects[CC1310_LAUNCHXL_UARTCOUNT]; + +uint8_t uartCC26XXRingBuffer[CC1310_LAUNCHXL_UARTCOUNT][32]; + +const UARTCC26XX_HWAttrsV2 uartCC26XXHWAttrs[CC1310_LAUNCHXL_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .baseAddr = UART0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UART0, + .intNum = INT_UART0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .txPin = CC1310_LAUNCHXL_UART_TX, + .rxPin = CC1310_LAUNCHXL_UART_RX, + .ctsPin = PIN_UNASSIGNED, + .rtsPin = PIN_UNASSIGNED, + .ringBufPtr = uartCC26XXRingBuffer[CC1310_LAUNCHXL_UART0], + .ringBufSize = sizeof(uartCC26XXRingBuffer[CC1310_LAUNCHXL_UART0]), + .txIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_1_8, + .rxIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_4_8, + .errorFxn = NULL + }, +#endif +}; + +const UART_Config UART_config[CC1310_LAUNCHXL_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .fxnTablePtr = &UARTCC26XX_fxnTable, + .object = &uartCC26XXObjects[CC1310_LAUNCHXL_UART0], + .hwAttrs = &uartCC26XXHWAttrs[CC1310_LAUNCHXL_UART0] + }, +#endif +}; + +const uint_least8_t UART_count = CC1310_LAUNCHXL_UARTCOUNT; + +#endif /* TI_UART_CONF_ENABLE */ + +/* + * =============================== UDMA =============================== + */ +#include + +UDMACC26XX_Object udmaObjects[CC1310_LAUNCHXL_UDMACOUNT]; + +const UDMACC26XX_HWAttrs udmaHWAttrs[CC1310_LAUNCHXL_UDMACOUNT] = { + { + .baseAddr = UDMA0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UDMA, + .intNum = INT_DMA_ERR, + .intPriority = ~0 + } +}; + +const UDMACC26XX_Config UDMACC26XX_config[CC1310_LAUNCHXL_UDMACOUNT] = { + { + .object = &udmaObjects[CC1310_LAUNCHXL_UDMA0], + .hwAttrs = &udmaHWAttrs[CC1310_LAUNCHXL_UDMA0] + }, +}; + +/* + * =============================== Watchdog =============================== + */ +#include +#include + +WatchdogCC26XX_Object watchdogCC26XXObjects[CC1310_LAUNCHXL_WATCHDOGCOUNT]; + +const WatchdogCC26XX_HWAttrs watchdogCC26XXHWAttrs[CC1310_LAUNCHXL_WATCHDOGCOUNT] = { + { + .baseAddr = WDT_BASE, + .reloadValue = 1000 /* Reload value in milliseconds */ + }, +}; + +const Watchdog_Config Watchdog_config[CC1310_LAUNCHXL_WATCHDOGCOUNT] = { + { + .fxnTablePtr = &WatchdogCC26XX_fxnTable, + .object = &watchdogCC26XXObjects[CC1310_LAUNCHXL_WATCHDOG0], + .hwAttrs = &watchdogCC26XXHWAttrs[CC1310_LAUNCHXL_WATCHDOG0] + }, +}; + +const uint_least8_t Watchdog_count = CC1310_LAUNCHXL_WATCHDOGCOUNT; + +/* + * Board-specific initialization function to disable external flash. + * This function is defined in the file CC1310_LAUNCHXL_fxns.c + */ +extern void Board_initHook(void); + +/* + * ======== CC1310_LAUNCHXL_initGeneral ======== + */ +void CC1310_LAUNCHXL_initGeneral(void) +{ + Power_init(); + + if (PIN_init(BoardGpioInitTable) != PIN_SUCCESS) { + /* Error with PIN_init */ + while (1); + } + + /* Perform board-specific initialization */ + Board_initHook(); +} diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/CC1310_LAUNCHXL.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/CC1310_LAUNCHXL.h new file mode 100644 index 000000000..f2c1638d7 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/CC1310_LAUNCHXL.h @@ -0,0 +1,381 @@ +/* + * Copyright (c) 2015-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 CC1310_LAUNCHXL.h + * + * @brief CC1310 LaunchPad Board Specific header file. + * + * The CC1310_LAUNCHXL header file should be included in an application as + * follows: + * @code + * #include "CC1310_LAUNCHXL.h" + * @endcode + * + * ============================================================================ + */ +#ifndef __CC1310_LAUNCHXL_BOARD_H__ +#define __CC1310_LAUNCHXL_BOARD_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "contiki-conf.h" + +/* Includes */ +#include +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) + +/* Externs */ +extern const PIN_Config BoardGpioInitTable[]; + +/* Defines */ +#define CC1310_LAUNCHXL + +/* Mapping of pins to board signals using general board aliases + * + */ + +/* Analog capable DIOs */ +#define CC1310_LAUNCHXL_DIO23_ANALOG IOID_23 +#define CC1310_LAUNCHXL_DIO24_ANALOG IOID_24 +#define CC1310_LAUNCHXL_DIO25_ANALOG IOID_25 +#define CC1310_LAUNCHXL_DIO26_ANALOG IOID_26 +#define CC1310_LAUNCHXL_DIO27_ANALOG IOID_27 +#define CC1310_LAUNCHXL_DIO28_ANALOG IOID_28 +#define CC1310_LAUNCHXL_DIO29_ANALOG IOID_29 +#define CC1310_LAUNCHXL_DIO30_ANALOG IOID_30 + +/* Digital IOs */ +#define CC1310_LAUNCHXL_DIO0 IOID_0 +#define CC1310_LAUNCHXL_DIO1 IOID_1 +#define CC1310_LAUNCHXL_DIO12 IOID_12 +#define CC1310_LAUNCHXL_DIO15 IOID_15 +#define CC1310_LAUNCHXL_DIO16_TDO IOID_16 +#define CC1310_LAUNCHXL_DIO17_TDI IOID_17 +#define CC1310_LAUNCHXL_DIO21 IOID_21 +#define CC1310_LAUNCHXL_DIO22 IOID_22 + +/* Discrete Inputs */ +#define CC1310_LAUNCHXL_PIN_BTN1 IOID_13 +#define CC1310_LAUNCHXL_PIN_BTN2 IOID_14 + +/* GPIO */ +#define CC1310_LAUNCHXL_GPIO_LED_ON 1 +#define CC1310_LAUNCHXL_GPIO_LED_OFF 0 + +/* I2C */ +#define CC1310_LAUNCHXL_I2C0_SCL0 IOID_4 +#define CC1310_LAUNCHXL_I2C0_SDA0 IOID_5 + +/* LEDs */ +#define CC1310_LAUNCHXL_PIN_LED_ON 1 +#define CC1310_LAUNCHXL_PIN_LED_OFF 0 +#define CC1310_LAUNCHXL_PIN_RLED IOID_6 +#define CC1310_LAUNCHXL_PIN_GLED IOID_7 + +/* PWM Outputs */ +#define CC1310_LAUNCHXL_PWMPIN0 CC1310_LAUNCHXL_PIN_RLED +#define CC1310_LAUNCHXL_PWMPIN1 CC1310_LAUNCHXL_PIN_GLED +#define CC1310_LAUNCHXL_PWMPIN2 PIN_UNASSIGNED +#define CC1310_LAUNCHXL_PWMPIN3 PIN_UNASSIGNED +#define CC1310_LAUNCHXL_PWMPIN4 PIN_UNASSIGNED +#define CC1310_LAUNCHXL_PWMPIN5 PIN_UNASSIGNED +#define CC1310_LAUNCHXL_PWMPIN6 PIN_UNASSIGNED +#define CC1310_LAUNCHXL_PWMPIN7 PIN_UNASSIGNED + +/* SPI */ +#define CC1310_LAUNCHXL_SPI_FLASH_CS IOID_20 +#define CC1310_LAUNCHXL_FLASH_CS_ON 0 +#define CC1310_LAUNCHXL_FLASH_CS_OFF 1 + +/* SPI Board */ +#define CC1310_LAUNCHXL_SPI0_MISO IOID_8 /* RF1.20 */ +#define CC1310_LAUNCHXL_SPI0_MOSI IOID_9 /* RF1.18 */ +#define CC1310_LAUNCHXL_SPI0_CLK IOID_10 /* RF1.16 */ +#define CC1310_LAUNCHXL_SPI0_CSN PIN_UNASSIGNED +#define CC1310_LAUNCHXL_SPI1_MISO PIN_UNASSIGNED +#define CC1310_LAUNCHXL_SPI1_MOSI PIN_UNASSIGNED +#define CC1310_LAUNCHXL_SPI1_CLK PIN_UNASSIGNED +#define CC1310_LAUNCHXL_SPI1_CSN PIN_UNASSIGNED + +/* UART Board */ +#define CC1310_LAUNCHXL_UART_RX IOID_2 /* RXD */ +#define CC1310_LAUNCHXL_UART_TX IOID_3 /* TXD */ +#define CC1310_LAUNCHXL_UART_CTS IOID_19 /* CTS */ +#define CC1310_LAUNCHXL_UART_RTS IOID_18 /* RTS */ + +/*! + * @brief Initialize the general board specific settings + * + * This function initializes the general board specific settings. + */ +void CC1310_LAUNCHXL_initGeneral(void); + +/*! + * @brief Turn off the external flash on LaunchPads + * + */ +void CC1310_LAUNCHXL_shutDownExtFlash(void); + +/*! + * @brief Wake up the external flash present on the board files + * + * This function toggles the chip select for the amount of time needed + * to wake the chip up. + */ +void CC1310_LAUNCHXL_wakeUpExtFlash(void); + +/*! + * @def CC1310_LAUNCHXL_ADCBufName + * @brief Enum of ADCBufs + */ +typedef enum CC1310_LAUNCHXL_ADCBufName { + CC1310_LAUNCHXL_ADCBUF0 = 0, + + CC1310_LAUNCHXL_ADCBUFCOUNT +} CC1310_LAUNCHXL_ADCBufName; + +/*! + * @def CC1310_LAUNCHXL_ADCBuf0ChannelName + * @brief Enum of ADCBuf channels + */ +typedef enum CC1310_LAUNCHXL_ADCBuf0ChannelName { + CC1310_LAUNCHXL_ADCBUF0CHANNEL0 = 0, + CC1310_LAUNCHXL_ADCBUF0CHANNEL1, + CC1310_LAUNCHXL_ADCBUF0CHANNEL2, + CC1310_LAUNCHXL_ADCBUF0CHANNEL3, + CC1310_LAUNCHXL_ADCBUF0CHANNEL4, + CC1310_LAUNCHXL_ADCBUF0CHANNEL5, + CC1310_LAUNCHXL_ADCBUF0CHANNEL6, + CC1310_LAUNCHXL_ADCBUF0CHANNEL7, + CC1310_LAUNCHXL_ADCBUF0CHANNELVDDS, + CC1310_LAUNCHXL_ADCBUF0CHANNELDCOUPL, + CC1310_LAUNCHXL_ADCBUF0CHANNELVSS, + + CC1310_LAUNCHXL_ADCBUF0CHANNELCOUNT +} CC1310_LAUNCHXL_ADCBuf0ChannelName; + +/*! + * @def CC1310_LAUNCHXL_ADCName + * @brief Enum of ADCs + */ +typedef enum CC1310_LAUNCHXL_ADCName { + CC1310_LAUNCHXL_ADC0 = 0, + CC1310_LAUNCHXL_ADC1, + CC1310_LAUNCHXL_ADC2, + CC1310_LAUNCHXL_ADC3, + CC1310_LAUNCHXL_ADC4, + CC1310_LAUNCHXL_ADC5, + CC1310_LAUNCHXL_ADC6, + CC1310_LAUNCHXL_ADC7, + CC1310_LAUNCHXL_ADCDCOUPL, + CC1310_LAUNCHXL_ADCVSS, + CC1310_LAUNCHXL_ADCVDDS, + + CC1310_LAUNCHXL_ADCCOUNT +} CC1310_LAUNCHXL_ADCName; + +/*! + * @def CC1310_LAUNCHXL_CryptoName + * @brief Enum of Crypto names + */ +typedef enum CC1310_LAUNCHXL_CryptoName { + CC1310_LAUNCHXL_CRYPTO0 = 0, + + CC1310_LAUNCHXL_CRYPTOCOUNT +} CC1310_LAUNCHXL_CryptoName; + +/*! + * @def CC1310_LAUNCHXL_GPIOName + * @brief Enum of GPIO names + */ +typedef enum CC1310_LAUNCHXL_GPIOName { + CC1310_LAUNCHXL_GPIO_S1 = 0, + CC1310_LAUNCHXL_GPIO_S2, + CC1310_LAUNCHXL_SPI_MASTER_READY, + CC1310_LAUNCHXL_SPI_SLAVE_READY, + CC1310_LAUNCHXL_GPIO_LED_GREEN, + CC1310_LAUNCHXL_GPIO_LED_RED, + CC1310_LAUNCHXL_GPIO_SPI_FLASH_CS, + CC1310_LAUNCHXL_SDSPI_CS, + CC1310_LAUNCHXL_GPIOCOUNT +} CC1310_LAUNCHXL_GPIOName; + +/*! + * @def CC1310_LAUNCHXL_GPTimerName + * @brief Enum of GPTimer parts + */ +typedef enum CC1310_LAUNCHXL_GPTimerName { + CC1310_LAUNCHXL_GPTIMER0A = 0, + CC1310_LAUNCHXL_GPTIMER0B, + CC1310_LAUNCHXL_GPTIMER1A, + CC1310_LAUNCHXL_GPTIMER1B, + CC1310_LAUNCHXL_GPTIMER2A, + CC1310_LAUNCHXL_GPTIMER2B, + CC1310_LAUNCHXL_GPTIMER3A, + CC1310_LAUNCHXL_GPTIMER3B, + + CC1310_LAUNCHXL_GPTIMERPARTSCOUNT +} CC1310_LAUNCHXL_GPTimerName; + +/*! + * @def CC1310_LAUNCHXL_GPTimers + * @brief Enum of GPTimers + */ +typedef enum CC1310_LAUNCHXL_GPTimers { + CC1310_LAUNCHXL_GPTIMER0 = 0, + CC1310_LAUNCHXL_GPTIMER1, + CC1310_LAUNCHXL_GPTIMER2, + CC1310_LAUNCHXL_GPTIMER3, + + CC1310_LAUNCHXL_GPTIMERCOUNT +} CC1310_LAUNCHXL_GPTimers; + +/*! + * @def CC1310_LAUNCHXL_I2CName + * @brief Enum of I2C names + */ +typedef enum CC1310_LAUNCHXL_I2CName { +#if TI_I2C_CONF_I2C0_ENABLE + CC1310_LAUNCHXL_I2C0 = 0, +#endif + + CC1310_LAUNCHXL_I2CCOUNT +} CC1310_LAUNCHXL_I2CName; + +/*! + * @def CC1310_LAUNCHXL_NVSName + * @brief Enum of NVS names + */ +typedef enum CC1310_LAUNCHXL_NVSName { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + CC1310_LAUNCHXL_NVSCC26XX0 = 0, +#endif +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + CC1310_LAUNCHXL_NVSSPI25X0, +#endif + + CC1310_LAUNCHXL_NVSCOUNT +} CC1310_LAUNCHXL_NVSName; + +/*! + * @def CC1310_LAUNCHXL_PWMName + * @brief Enum of PWM outputs + */ +typedef enum CC1310_LAUNCHXL_PWMName { + CC1310_LAUNCHXL_PWM0 = 0, + CC1310_LAUNCHXL_PWM1, + CC1310_LAUNCHXL_PWM2, + CC1310_LAUNCHXL_PWM3, + CC1310_LAUNCHXL_PWM4, + CC1310_LAUNCHXL_PWM5, + CC1310_LAUNCHXL_PWM6, + CC1310_LAUNCHXL_PWM7, + + CC1310_LAUNCHXL_PWMCOUNT +} CC1310_LAUNCHXL_PWMName; + +/*! + * @def CC1310_LAUNCHXL_SDName + * @brief Enum of SD names + */ +typedef enum CC1310_LAUNCHXL_SDName { + CC1310_LAUNCHXL_SDSPI0 = 0, + + CC1310_LAUNCHXL_SDCOUNT +} CC1310_LAUNCHXL_SDName; + +/*! + * @def CC1310_LAUNCHXL_SPIName + * @brief Enum of SPI names + */ +typedef enum CC1310_LAUNCHXL_SPIName { +#if TI_SPI_CONF_SPI0_ENABLE + CC1310_LAUNCHXL_SPI0 = 0, +#endif +#if TI_SPI_CONF_SPI1_ENABLE + CC1310_LAUNCHXL_SPI1, +#endif + + CC1310_LAUNCHXL_SPICOUNT +} CC1310_LAUNCHXL_SPIName; + +/*! + * @def CC1310_LAUNCHXL_TRNGName + * @brief Enum of TRNGs + */ +typedef enum CC1310_LAUNCHXL_TRNGName { + CC1310_LAUNCHXL_TRNG0 = 0, + + CC1310_LAUNCHXL_TRNGCOUNT +} CC1310_LAUNCHXL_TRNGName; + +/*! + * @def CC1310_LAUNCHXL_UARTName + * @brief Enum of UARTs + */ +typedef enum CC1310_LAUNCHXL_UARTName { +#if TI_UART_CONF_UART0_ENABLE + CC1310_LAUNCHXL_UART0 = 0, +#endif + + CC1310_LAUNCHXL_UARTCOUNT +} CC1310_LAUNCHXL_UARTName; + +/*! + * @def CC1310_LAUNCHXL_UDMAName + * @brief Enum of DMA buffers + */ +typedef enum CC1310_LAUNCHXL_UDMAName { + CC1310_LAUNCHXL_UDMA0 = 0, + + CC1310_LAUNCHXL_UDMACOUNT +} CC1310_LAUNCHXL_UDMAName; + +/*! + * @def CC1310_LAUNCHXL_WatchdogName + * @brief Enum of Watchdogs + */ +typedef enum CC1310_LAUNCHXL_WatchdogName { + CC1310_LAUNCHXL_WATCHDOG0 = 0, + + CC1310_LAUNCHXL_WATCHDOGCOUNT +} CC1310_LAUNCHXL_WatchdogName; + + +#ifdef __cplusplus +} +#endif + +#endif /* __CC1310_LAUNCHXL_BOARD_H__ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/CC1310_LAUNCHXL_fxns.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/CC1310_LAUNCHXL_fxns.c new file mode 100644 index 000000000..6918918bb --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/CC1310_LAUNCHXL_fxns.c @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +/* + * ======== CC1310_LAUNCHXL_fxns.c ======== + * This file contains the board-specific initialization functions. + */ + +#include +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/cpu.h) + +#include + +#include "Board.h" + + +/* + * ======== CC1310_LAUNCHXL_sendExtFlashByte ======== + */ +void CC1310_LAUNCHXL_sendExtFlashByte(PIN_Handle pinHandle, uint8_t byte) +{ + uint8_t i; + + /* SPI Flash CS */ + PIN_setOutputValue(pinHandle, IOID_20, 0); + + for (i = 0; i < 8; i++) { + PIN_setOutputValue(pinHandle, IOID_10, 0); /* SPI Flash CLK */ + + /* SPI Flash MOSI */ + PIN_setOutputValue(pinHandle, IOID_9, (byte >> (7 - i)) & 0x01); + PIN_setOutputValue(pinHandle, IOID_10, 1); /* SPI Flash CLK */ + + /* + * Waste a few cycles to keep the CLK high for at + * least 45% of the period. + * 3 cycles per loop: 8 loops @ 48 Mhz = 0.5 us. + */ + CPUdelay(8); + } + + PIN_setOutputValue(pinHandle, IOID_10, 0); /* CLK */ + PIN_setOutputValue(pinHandle, IOID_20, 1); /* CS */ + + /* + * Keep CS high at least 40 us + * 3 cycles per loop: 700 loops @ 48 Mhz ~= 44 us + */ + CPUdelay(700); +} + +/* + * ======== CC1310_LAUNCHXL_wakeUpExtFlash ======== + */ +void CC1310_LAUNCHXL_wakeUpExtFlash(void) +{ + PIN_Config extFlashPinTable[] = { + /* SPI Flash CS */ + IOID_20 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + PIN_TERMINATE + }; + PIN_State extFlashPinState; + PIN_Handle extFlashPinHandle = PIN_open(&extFlashPinState, extFlashPinTable); + + /* + * To wake up we need to toggle the chip select at + * least 20 ns and ten wait at least 35 us. + */ + + /* Toggle chip select for ~20ns to wake ext. flash */ + PIN_setOutputValue(extFlashPinHandle, IOID_20, 0); + /* 3 cycles per loop: 1 loop @ 48 Mhz ~= 62 ns */ + CPUdelay(1); + PIN_setOutputValue(extFlashPinHandle, IOID_20, 1); + /* 3 cycles per loop: 560 loops @ 48 Mhz ~= 35 us */ + CPUdelay(560); + + PIN_close(extFlashPinHandle); +} + +/* + * ======== CC1310_LAUNCHXL_shutDownExtFlash ======== + */ +void CC1310_LAUNCHXL_shutDownExtFlash(void) +{ + /* + * To be sure we are putting the flash into sleep and not waking it, + * we first have to make a wake up call + */ + CC1310_LAUNCHXL_wakeUpExtFlash(); + + PIN_Config extFlashPinTable[] = { + /* SPI Flash CS*/ + IOID_20 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash CLK */ + IOID_10 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash MOSI */ + IOID_9 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash MISO */ + IOID_8 | PIN_INPUT_EN | PIN_PULLDOWN, + PIN_TERMINATE + }; + PIN_State extFlashPinState; + PIN_Handle extFlashPinHandle = PIN_open(&extFlashPinState, extFlashPinTable); + + uint8_t extFlashShutdown = 0xB9; + + CC1310_LAUNCHXL_sendExtFlashByte(extFlashPinHandle, extFlashShutdown); + + PIN_close(extFlashPinHandle); +} + +/* + * ======== Board_initHook ======== + * Called by Board_init() to perform board-specific initialization. + */ +void Board_initHook() +{ + CC1310_LAUNCHXL_shutDownExtFlash(); +} diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/Makefile.cc1310 b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/Makefile.cc1310 new file mode 100644 index 000000000..d43113151 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/Makefile.cc1310 @@ -0,0 +1,21 @@ +################################################################################ +# SimpleLink Device makefile + +SUBFAMILY = cc13x0-cc26x0 +DEVICE_FAMILY = CC13X0 +DEVICE_LINE = CC13XX +DEVICE = CC1310 + +BOARD_SOURCEFILES += CC1310_LAUNCHXL.c CC1310_LAUNCHXL_fxns.c + +SUPPORTS_PROP_MODE = 1 +SUPPORTS_IEEE_MODE = 0 +SUPPORTS_BLE_BEACON = 0 + +SUPPORTS_HIGH_PA = 0 + +### Signal that we can be programmed with cc2538-bsl +BOARD_SUPPORTS_BSL = 1 + +# Include the common board makefile +include $(FAMILY_PATH)/launchpad/Makefile.launchpad diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/Board.h new file mode 100644 index 000000000..c3763b019 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/Board.h @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2015-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 __BOARD_H +#define __BOARD_H + +#define Board_CC1312R1_LAUNCHXL +#define BOARD_STRING "TI CC1312R1 LaunchPad" + +#ifdef __cplusplus +extern "C" { +#endif + +#include "CC1312R1_LAUNCHXL.h" + +#define Board_initGeneral() CC1312R1_LAUNCHXL_initGeneral() +#define Board_shutDownExtFlash() CC1312R1_LAUNCHXL_shutDownExtFlash() +#define Board_wakeUpExtFlash() CC1312R1_LAUNCHXL_wakeUpExtFlash() + +/* These #defines allow us to reuse TI-RTOS across other device families */ + +#define Board_ADC0 CC1312R1_LAUNCHXL_ADC0 +#define Board_ADC1 CC1312R1_LAUNCHXL_ADC1 + +#define Board_ADCBUF0 CC1312R1_LAUNCHXL_ADCBUF0 +#define Board_ADCBUF0CHANNEL0 CC1312R1_LAUNCHXL_ADCBUF0CHANNEL0 +#define Board_ADCBUF0CHANNEL1 CC1312R1_LAUNCHXL_ADCBUF0CHANNEL1 + +#define Board_ECDH0 CC1312R1_LAUNCHXL_ECDH0 +#define Board_ECDSA0 CC1312R1_LAUNCHXL_ECDSA0 +#define Board_ECJPAKE0 CC1312R1_LAUNCHXL_ECJPAKE0 +#define Board_AESCCM0 CC1312R1_LAUNCHXL_AESCCM0 +#define Board_AESECB0 CC1312R1_LAUNCHXL_AESECB0 +#define Board_SHA20 CC1312R1_LAUNCHXL_SHA20 + +#define Board_DIO0 CC1312R1_LAUNCHXL_DIO0 +#define Board_DIO1 CC1312R1_LAUNCHXL_DIO1 +#define Board_DIO12 CC1312R1_LAUNCHXL_DIO12 +#define Board_DIO15 CC1312R1_LAUNCHXL_DIO15 +#define Board_DIO16_TDO CC1312R1_LAUNCHXL_DIO16_TDO +#define Board_DIO17_TDI CC1312R1_LAUNCHXL_DIO17_TDI +#define Board_DIO21 CC1312R1_LAUNCHXL_DIO21 +#define Board_DIO22 CC1312R1_LAUNCHXL_DIO22 + +#define Board_GPIO_BUTTON0 CC1312R1_LAUNCHXL_GPIO_S1 +#define Board_GPIO_BUTTON1 CC1312R1_LAUNCHXL_GPIO_S2 +#define Board_GPIO_BTN1 CC1312R1_LAUNCHXL_GPIO_S1 +#define Board_GPIO_BTN2 CC1312R1_LAUNCHXL_GPIO_S2 +#define Board_GPIO_LED0 CC1312R1_LAUNCHXL_GPIO_LED_RED +#define Board_GPIO_LED1 CC1312R1_LAUNCHXL_GPIO_LED_GREEN +#define Board_GPIO_RLED CC1312R1_LAUNCHXL_GPIO_LED_RED +#define Board_GPIO_GLED CC1312R1_LAUNCHXL_GPIO_LED_GREEN +#define Board_GPIO_LED_ON CC1312R1_LAUNCHXL_GPIO_LED_ON +#define Board_GPIO_LED_OFF CC1312R1_LAUNCHXL_GPIO_LED_OFF + +#define Board_GPTIMER0A CC1312R1_LAUNCHXL_GPTIMER0A +#define Board_GPTIMER0B CC1312R1_LAUNCHXL_GPTIMER0B +#define Board_GPTIMER1A CC1312R1_LAUNCHXL_GPTIMER1A +#define Board_GPTIMER1B CC1312R1_LAUNCHXL_GPTIMER1B +#define Board_GPTIMER2A CC1312R1_LAUNCHXL_GPTIMER2A +#define Board_GPTIMER2B CC1312R1_LAUNCHXL_GPTIMER2B +#define Board_GPTIMER3A CC1312R1_LAUNCHXL_GPTIMER3A +#define Board_GPTIMER3B CC1312R1_LAUNCHXL_GPTIMER3B + +#define Board_I2C0 CC1312R1_LAUNCHXL_I2C0 +#define Board_I2C_TMP CC1312R1_LAUNCHXL_I2C0 + +#define Board_NVSINTERNAL CC1312R1_LAUNCHXL_NVSCC26XX0 +#define Board_NVSEXTERNAL CC1312R1_LAUNCHXL_NVSSPI25X0 + +#define Board_PIN_BUTTON0 CC1312R1_LAUNCHXL_PIN_BTN1 +#define Board_PIN_BUTTON1 CC1312R1_LAUNCHXL_PIN_BTN2 +#define Board_PIN_BTN1 CC1312R1_LAUNCHXL_PIN_BTN1 +#define Board_PIN_BTN2 CC1312R1_LAUNCHXL_PIN_BTN2 +#define Board_PIN_LED0 CC1312R1_LAUNCHXL_PIN_RLED +#define Board_PIN_LED1 CC1312R1_LAUNCHXL_PIN_GLED +#define Board_PIN_LED2 CC1312R1_LAUNCHXL_PIN_RLED +#define Board_PIN_RLED CC1312R1_LAUNCHXL_PIN_RLED +#define Board_PIN_GLED CC1312R1_LAUNCHXL_PIN_GLED + +#define Board_PWM0 CC1312R1_LAUNCHXL_PWM0 +#define Board_PWM1 CC1312R1_LAUNCHXL_PWM1 +#define Board_PWM2 CC1312R1_LAUNCHXL_PWM2 +#define Board_PWM3 CC1312R1_LAUNCHXL_PWM3 +#define Board_PWM4 CC1312R1_LAUNCHXL_PWM4 +#define Board_PWM5 CC1312R1_LAUNCHXL_PWM5 +#define Board_PWM6 CC1312R1_LAUNCHXL_PWM6 +#define Board_PWM7 CC1312R1_LAUNCHXL_PWM7 + +#define Board_SD0 CC1312R1_LAUNCHXL_SDSPI0 + +#define Board_SPI0 CC1312R1_LAUNCHXL_SPI0 +#define Board_SPI0_MISO CC1312R1_LAUNCHXL_SPI0_MISO +#define Board_SPI0_MOSI CC1312R1_LAUNCHXL_SPI0_MOSI +#define Board_SPI0_CLK CC1312R1_LAUNCHXL_SPI0_CLK +#define Board_SPI0_CSN CC1312R1_LAUNCHXL_SPI0_CSN +#define Board_SPI1 CC1312R1_LAUNCHXL_SPI1 +#define Board_SPI1_MISO CC1312R1_LAUNCHXL_SPI1_MISO +#define Board_SPI1_MOSI CC1312R1_LAUNCHXL_SPI1_MOSI +#define Board_SPI1_CLK CC1312R1_LAUNCHXL_SPI1_CLK +#define Board_SPI1_CSN CC1312R1_LAUNCHXL_SPI1_CSN +#define Board_SPI_FLASH_CS CC1312R1_LAUNCHXL_SPI_FLASH_CS +#define Board_FLASH_CS_ON 0 +#define Board_FLASH_CS_OFF 1 + +#define Board_SPI_MASTER CC1312R1_LAUNCHXL_SPI0 +#define Board_SPI_SLAVE CC1312R1_LAUNCHXL_SPI0 +#define Board_SPI_MASTER_READY CC1312R1_LAUNCHXL_SPI_MASTER_READY +#define Board_SPI_SLAVE_READY CC1312R1_LAUNCHXL_SPI_SLAVE_READY + +#define Board_UART0 CC1312R1_LAUNCHXL_UART0 +#define Board_UART1 CC1312R1_LAUNCHXL_UART1 + +#define Board_WATCHDOG0 CC1312R1_LAUNCHXL_WATCHDOG0 + +/* Board specific I2C addresses */ +#define Board_TMP_ADDR (0x40) +#define Board_SENSORS_BP_TMP_ADDR Board_TMP_ADDR + +#ifdef __cplusplus +} +#endif + +#endif /* __BOARD_H */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/CC1312R1_LAUNCHXL.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/CC1312R1_LAUNCHXL.c new file mode 100644 index 000000000..44fd41035 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/CC1312R1_LAUNCHXL.c @@ -0,0 +1,941 @@ +/* + * Copyright (c) 2015-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +/* + * ====================== CC1312R1_LAUNCHXL.c =================================== + * This file is responsible for setting up the board specific items for the + * CC1312R1_LAUNCHXL board. + */ + +#include +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/udma.h) +#include DeviceFamily_constructPath(inc/hw_ints.h) +#include DeviceFamily_constructPath(inc/hw_memmap.h) + +#include "CC1312R1_LAUNCHXL.h" + +/* + * =============================== ADCBuf =============================== + */ +#include +#include + +ADCBufCC26X2_Object adcBufCC26xxObjects[CC1312R1_LAUNCHXL_ADCBUFCOUNT]; + +/* + * This table converts a virtual adc channel into a dio and internal analogue + * input signal. This table is necessary for the functioning of the adcBuf + * driver. Comment out unused entries to save flash. Dio and internal signal + * pairs are hardwired. Do not remap them in the table. You may reorder entire + * entries. The mapping of dio and internal signals is package dependent. + */ +const ADCBufCC26X2_AdcChannelLutEntry ADCBufCC26X2_adcChannelLut[CC1312R1_LAUNCHXL_ADCBUF0CHANNELCOUNT] = { + {CC1312R1_LAUNCHXL_DIO23_ANALOG, ADC_COMPB_IN_AUXIO7}, + {CC1312R1_LAUNCHXL_DIO24_ANALOG, ADC_COMPB_IN_AUXIO6}, + {CC1312R1_LAUNCHXL_DIO25_ANALOG, ADC_COMPB_IN_AUXIO5}, + {CC1312R1_LAUNCHXL_DIO26_ANALOG, ADC_COMPB_IN_AUXIO4}, + {CC1312R1_LAUNCHXL_DIO27_ANALOG, ADC_COMPB_IN_AUXIO3}, + {CC1312R1_LAUNCHXL_DIO28_ANALOG, ADC_COMPB_IN_AUXIO2}, + {CC1312R1_LAUNCHXL_DIO29_ANALOG, ADC_COMPB_IN_AUXIO1}, + {CC1312R1_LAUNCHXL_DIO30_ANALOG, ADC_COMPB_IN_AUXIO0}, + {PIN_UNASSIGNED, ADC_COMPB_IN_VDDS}, + {PIN_UNASSIGNED, ADC_COMPB_IN_DCOUPL}, + {PIN_UNASSIGNED, ADC_COMPB_IN_VSS}, +}; + +const ADCBufCC26X2_HWAttrs adcBufCC26xxHWAttrs[CC1312R1_LAUNCHXL_ADCBUFCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + .adcChannelLut = ADCBufCC26X2_adcChannelLut, + .gpTimerUnit = CC1312R1_LAUNCHXL_GPTIMER0A, + } +}; + +const ADCBuf_Config ADCBuf_config[CC1312R1_LAUNCHXL_ADCBUFCOUNT] = { + { + &ADCBufCC26X2_fxnTable, + &adcBufCC26xxObjects[CC1312R1_LAUNCHXL_ADCBUF0], + &adcBufCC26xxHWAttrs[CC1312R1_LAUNCHXL_ADCBUF0] + }, +}; + +const uint_least8_t ADCBuf_count = CC1312R1_LAUNCHXL_ADCBUFCOUNT; + +/* + * =============================== ADC =============================== + */ +#include +#include + +ADCCC26XX_Object adcCC26xxObjects[CC1312R1_LAUNCHXL_ADCCOUNT]; + + +const ADCCC26XX_HWAttrs adcCC26xxHWAttrs[CC1312R1_LAUNCHXL_ADCCOUNT] = { + { + .adcDIO = CC1312R1_LAUNCHXL_DIO23_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO7, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1312R1_LAUNCHXL_DIO24_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO6, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1312R1_LAUNCHXL_DIO25_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO5, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1312R1_LAUNCHXL_DIO26_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO4, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1312R1_LAUNCHXL_DIO27_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO3, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1312R1_LAUNCHXL_DIO28_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO2, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1312R1_LAUNCHXL_DIO29_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO1, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1312R1_LAUNCHXL_DIO30_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO0, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_10P9_MS, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_DCOUPL, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_VSS, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_VDDS, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + } +}; + +const ADC_Config ADC_config[CC1312R1_LAUNCHXL_ADCCOUNT] = { + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1312R1_LAUNCHXL_ADC0], &adcCC26xxHWAttrs[CC1312R1_LAUNCHXL_ADC0]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1312R1_LAUNCHXL_ADC1], &adcCC26xxHWAttrs[CC1312R1_LAUNCHXL_ADC1]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1312R1_LAUNCHXL_ADC2], &adcCC26xxHWAttrs[CC1312R1_LAUNCHXL_ADC2]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1312R1_LAUNCHXL_ADC3], &adcCC26xxHWAttrs[CC1312R1_LAUNCHXL_ADC3]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1312R1_LAUNCHXL_ADC4], &adcCC26xxHWAttrs[CC1312R1_LAUNCHXL_ADC4]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1312R1_LAUNCHXL_ADC5], &adcCC26xxHWAttrs[CC1312R1_LAUNCHXL_ADC5]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1312R1_LAUNCHXL_ADC6], &adcCC26xxHWAttrs[CC1312R1_LAUNCHXL_ADC6]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1312R1_LAUNCHXL_ADC7], &adcCC26xxHWAttrs[CC1312R1_LAUNCHXL_ADC7]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1312R1_LAUNCHXL_ADCDCOUPL], &adcCC26xxHWAttrs[CC1312R1_LAUNCHXL_ADCDCOUPL]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1312R1_LAUNCHXL_ADCVSS], &adcCC26xxHWAttrs[CC1312R1_LAUNCHXL_ADCVSS]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1312R1_LAUNCHXL_ADCVDDS], &adcCC26xxHWAttrs[CC1312R1_LAUNCHXL_ADCVDDS]}, +}; + +const uint_least8_t ADC_count = CC1312R1_LAUNCHXL_ADCCOUNT; + +/* + * =============================== ECDH =============================== + */ +#include +#include + +ECDHCC26X2_Object ecdhCC26X2Objects[CC1312R1_LAUNCHXL_ECDHCOUNT]; + +const ECDHCC26X2_HWAttrs ecdhCC26X2HWAttrs[CC1312R1_LAUNCHXL_ECDHCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const ECDH_Config ECDH_config[CC1312R1_LAUNCHXL_ECDHCOUNT] = { + { + .object = &ecdhCC26X2Objects[CC1312R1_LAUNCHXL_ECDH0], + .hwAttrs = &ecdhCC26X2HWAttrs[CC1312R1_LAUNCHXL_ECDH0] + }, +}; + +const uint_least8_t ECDH_count = CC1312R1_LAUNCHXL_ECDHCOUNT; + +/* + * =============================== ECDSA =============================== + */ +#include +#include + +ECDSACC26X2_Object ecdsaCC26X2Objects[CC1312R1_LAUNCHXL_ECDSACOUNT]; + +const ECDSACC26X2_HWAttrs ecdsaCC26X2HWAttrs[CC1312R1_LAUNCHXL_ECDSACOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const ECDSA_Config ECDSA_config[CC1312R1_LAUNCHXL_ECDSACOUNT] = { + { + .object = &ecdsaCC26X2Objects[CC1312R1_LAUNCHXL_ECDSA0], + .hwAttrs = &ecdsaCC26X2HWAttrs[CC1312R1_LAUNCHXL_ECDSA0] + }, +}; + +const uint_least8_t ECDSA_count = CC1312R1_LAUNCHXL_ECDSACOUNT; + +/* + * =============================== ECJPAKE =============================== + */ +#include +#include + +ECJPAKECC26X2_Object ecjpakeCC26X2Objects[CC1312R1_LAUNCHXL_ECJPAKECOUNT]; + +const ECJPAKECC26X2_HWAttrs ecjpakeCC26X2HWAttrs[CC1312R1_LAUNCHXL_ECJPAKECOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const ECJPAKE_Config ECJPAKE_config[CC1312R1_LAUNCHXL_ECJPAKECOUNT] = { + { + .object = &ecjpakeCC26X2Objects[CC1312R1_LAUNCHXL_ECJPAKE0], + .hwAttrs = &ecjpakeCC26X2HWAttrs[CC1312R1_LAUNCHXL_ECJPAKE0] + }, +}; + +const uint_least8_t ECJPAKE_count = CC1312R1_LAUNCHXL_ECJPAKECOUNT; + + +/* + * =============================== SHA2 =============================== + */ +#include +#include + +SHA2CC26X2_Object sha2CC26X2Objects[CC1312R1_LAUNCHXL_SHA2COUNT]; + +const SHA2CC26X2_HWAttrs sha2CC26X2HWAttrs[CC1312R1_LAUNCHXL_SHA2COUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const SHA2_Config SHA2_config[CC1312R1_LAUNCHXL_SHA2COUNT] = { + { + .object = &sha2CC26X2Objects[CC1312R1_LAUNCHXL_SHA20], + .hwAttrs = &sha2CC26X2HWAttrs[CC1312R1_LAUNCHXL_SHA20] + }, +}; + +const uint_least8_t SHA2_count = CC1312R1_LAUNCHXL_SHA2COUNT; + +/* + * =============================== AESCCM =============================== + */ +#include +#include + +AESCCMCC26XX_Object aesccmCC26XXObjects[CC1312R1_LAUNCHXL_AESCCMCOUNT]; + +const AESCCMCC26XX_HWAttrs aesccmCC26XXHWAttrs[CC1312R1_LAUNCHXL_AESCCMCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const AESCCM_Config AESCCM_config[CC1312R1_LAUNCHXL_AESCCMCOUNT] = { + { + .object = &aesccmCC26XXObjects[CC1312R1_LAUNCHXL_AESCCM0], + .hwAttrs = &aesccmCC26XXHWAttrs[CC1312R1_LAUNCHXL_AESCCM0] + }, +}; + +const uint_least8_t AESCCM_count = CC1312R1_LAUNCHXL_AESCCMCOUNT; + +/* + * =============================== AESECB =============================== + */ +#include +#include + +AESECBCC26XX_Object aesecbCC26XXObjects[CC1312R1_LAUNCHXL_AESECBCOUNT]; + +const AESECBCC26XX_HWAttrs aesecbCC26XXHWAttrs[CC1312R1_LAUNCHXL_AESECBCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const AESECB_Config AESECB_config[CC1312R1_LAUNCHXL_AESECBCOUNT] = { + { + .object = &aesecbCC26XXObjects[CC1312R1_LAUNCHXL_AESECB0], + .hwAttrs = &aesecbCC26XXHWAttrs[CC1312R1_LAUNCHXL_AESECB0] + }, +}; + +const uint_least8_t AESECB_count = CC1312R1_LAUNCHXL_AESECBCOUNT; + +/* + * =============================== GPIO =============================== + */ +#include +#include + +/* + * Array of Pin configurations + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC1312R1_LAUNCHXL.h + * NOTE: Pins not used for interrupts should be placed at the end of the + * array. Callback entries can be omitted from callbacks array to + * reduce memory usage. + */ +GPIO_PinConfig gpioPinConfigs[] = { + /* Input pins */ + GPIOCC26XX_DIO_13 | GPIO_DO_NOT_CONFIG, /* Button 0 */ + GPIOCC26XX_DIO_14 | GPIO_DO_NOT_CONFIG, /* Button 1 */ + + GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG, /* CC1312R1_LAUNCHXL_SPI_MASTER_READY */ + GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG, /* CC1312R1_LAUNCHXL_SPI_SLAVE_READY */ + + /* Output pins */ + GPIOCC26XX_DIO_07 | GPIO_DO_NOT_CONFIG, /* Green LED */ + GPIOCC26XX_DIO_06 | GPIO_DO_NOT_CONFIG, /* Red LED */ + + /* SPI Flash CSN */ + GPIOCC26XX_DIO_20 | GPIO_DO_NOT_CONFIG, + + /* SD CS */ + GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG, +}; + +/* + * Array of callback function pointers + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC1312R1_LAUNCH.h + * NOTE: Pins not used for interrupts can be omitted from callbacks array to + * reduce memory usage (if placed at end of gpioPinConfigs array). + */ +GPIO_CallbackFxn gpioCallbackFunctions[] = { + NULL, /* Button 0 */ + NULL, /* Button 1 */ + NULL, /* CC1312R1_LAUNCHXL_SPI_MASTER_READY */ + NULL, /* CC1312R1_LAUNCHXL_SPI_SLAVE_READY */ +}; + +const GPIOCC26XX_Config GPIOCC26XX_config = { + .pinConfigs = (GPIO_PinConfig *)gpioPinConfigs, + .callbacks = (GPIO_CallbackFxn *)gpioCallbackFunctions, + .numberOfPinConfigs = CC1312R1_LAUNCHXL_GPIOCOUNT, + .numberOfCallbacks = sizeof(gpioCallbackFunctions)/sizeof(GPIO_CallbackFxn), + .intPriority = (~0) +}; + +/* + * =============================== GPTimer =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include + +GPTimerCC26XX_Object gptimerCC26XXObjects[CC1312R1_LAUNCHXL_GPTIMERCOUNT]; + +const GPTimerCC26XX_HWAttrs gptimerCC26xxHWAttrs[CC1312R1_LAUNCHXL_GPTIMERPARTSCOUNT] = { + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0A, }, + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0B, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1A, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1B, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2A, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2B, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3A, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3B, }, +}; + +const GPTimerCC26XX_Config GPTimerCC26XX_config[CC1312R1_LAUNCHXL_GPTIMERPARTSCOUNT] = { + { &gptimerCC26XXObjects[CC1312R1_LAUNCHXL_GPTIMER0], &gptimerCC26xxHWAttrs[CC1312R1_LAUNCHXL_GPTIMER0A], GPT_A }, + { &gptimerCC26XXObjects[CC1312R1_LAUNCHXL_GPTIMER0], &gptimerCC26xxHWAttrs[CC1312R1_LAUNCHXL_GPTIMER0B], GPT_B }, + { &gptimerCC26XXObjects[CC1312R1_LAUNCHXL_GPTIMER1], &gptimerCC26xxHWAttrs[CC1312R1_LAUNCHXL_GPTIMER1A], GPT_A }, + { &gptimerCC26XXObjects[CC1312R1_LAUNCHXL_GPTIMER1], &gptimerCC26xxHWAttrs[CC1312R1_LAUNCHXL_GPTIMER1B], GPT_B }, + { &gptimerCC26XXObjects[CC1312R1_LAUNCHXL_GPTIMER2], &gptimerCC26xxHWAttrs[CC1312R1_LAUNCHXL_GPTIMER2A], GPT_A }, + { &gptimerCC26XXObjects[CC1312R1_LAUNCHXL_GPTIMER2], &gptimerCC26xxHWAttrs[CC1312R1_LAUNCHXL_GPTIMER2B], GPT_B }, + { &gptimerCC26XXObjects[CC1312R1_LAUNCHXL_GPTIMER3], &gptimerCC26xxHWAttrs[CC1312R1_LAUNCHXL_GPTIMER3A], GPT_A }, + { &gptimerCC26XXObjects[CC1312R1_LAUNCHXL_GPTIMER3], &gptimerCC26xxHWAttrs[CC1312R1_LAUNCHXL_GPTIMER3B], GPT_B }, +}; + +/* + * =============================== I2C =============================== +*/ +#include +#include + +#if TI_I2C_CONF_ENABLE + +I2CCC26XX_Object i2cCC26xxObjects[CC1312R1_LAUNCHXL_I2CCOUNT]; + +const I2CCC26XX_HWAttrsV1 i2cCC26xxHWAttrs[CC1312R1_LAUNCHXL_I2CCOUNT] = { +#if TI_I2C_CONF_I2C0_ENABLE + { + .baseAddr = I2C0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_I2C0, + .intNum = INT_I2C_IRQ, + .intPriority = ~0, + .swiPriority = 0, + .sdaPin = CC1312R1_LAUNCHXL_I2C0_SDA0, + .sclPin = CC1312R1_LAUNCHXL_I2C0_SCL0, + }, +#endif +}; + +const I2C_Config I2C_config[CC1312R1_LAUNCHXL_I2CCOUNT] = { +#if TI_I2C_CONF_I2C0_ENABLE + { + .fxnTablePtr = &I2CCC26XX_fxnTable, + .object = &i2cCC26xxObjects[CC1312R1_LAUNCHXL_I2C0], + .hwAttrs = &i2cCC26xxHWAttrs[CC1312R1_LAUNCHXL_I2C0] + }, +#endif +}; + +const uint_least8_t I2C_count = CC1312R1_LAUNCHXL_I2CCOUNT; + +#endif /* TI_I2C_CONF_ENABLE */ + +/* + * =============================== NVS =============================== + */ +#include +#include +#include + +#define NVS_REGIONS_BASE 0x48000 +#define SECTORSIZE 0x2000 +#define REGIONSIZE (SECTORSIZE * 4) + +#if TI_NVS_CONF_ENABLE + +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + +/* + * Reserve flash sectors for NVS driver use by placing an uninitialized byte + * array at the desired flash address. + */ +#if defined(__TI_COMPILER_VERSION__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +#pragma LOCATION(flashBuf, NVS_REGIONS_BASE); +#pragma NOINIT(flashBuf); +static char flashBuf[REGIONSIZE]; + +#elif defined(__IAR_SYSTEMS_ICC__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +static __no_init char flashBuf[REGIONSIZE] @ NVS_REGIONS_BASE; + +#elif defined(__GNUC__) + +/* + * Place the flash buffers in the .nvs section created in the gcc linker file. + * The .nvs section enforces alignment on a sector boundary but may + * be placed anywhere in flash memory. If desired the .nvs section can be set + * to a fixed address by changing the following in the gcc linker file: + * + * .nvs (FIXED_FLASH_ADDR) (NOLOAD) : AT (FIXED_FLASH_ADDR) { + * *(.nvs) + * } > REGION_TEXT + */ +__attribute__ ((section (".nvs"))) +static char flashBuf[REGIONSIZE]; + +#endif + +/* Allocate objects for NVS Internal Regions */ +NVSCC26XX_Object nvsCC26xxObjects[1]; + +/* Hardware attributes for NVS Internal Regions */ +const NVSCC26XX_HWAttrs nvsCC26xxHWAttrs[1] = { + { + .regionBase = (void *)flashBuf, + .regionSize = REGIONSIZE, + }, +}; + +#endif /* TI_NVS_CONF_NVS_INTERNAL_ENABLE */ + +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + +#define SPISECTORSIZE 0x1000 +#define SPIREGIONSIZE (SPISECTORSIZE * 32) +#define VERIFYBUFSIZE 64 + +static uint8_t verifyBuf[VERIFYBUFSIZE]; + +/* Allocate objects for NVS External Regions */ +NVSSPI25X_Object nvsSPI25XObjects[1]; + +/* Hardware attributes for NVS External Regions */ +const NVSSPI25X_HWAttrs nvsSPI25XHWAttrs[1] = { + { + .regionBaseOffset = 0, + .regionSize = SPIREGIONSIZE, + .sectorSize = SPISECTORSIZE, + .verifyBuf = verifyBuf, + .verifyBufSize = VERIFYBUFSIZE, + .spiHandle = NULL, + .spiIndex = 0, + .spiBitRate = 4000000, + .spiCsnGpioIndex = CC1312R1_LAUNCHXL_GPIO_SPI_FLASH_CS, + }, +}; + +#endif /* TI_NVS_CONF_NVS_EXTERNAL_ENABLE */ + +/* NVS Region index 0 and 1 refer to NVS and NVS SPI respectively */ +const NVS_Config NVS_config[CC1312R1_LAUNCHXL_NVSCOUNT] = { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + { + .fxnTablePtr = &NVSCC26XX_fxnTable, + .object = &nvsCC26xxObjects[0], + .hwAttrs = &nvsCC26xxHWAttrs[0], + }, +#endif +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + { + .fxnTablePtr = &NVSSPI25X_fxnTable, + .object = &nvsSPI25XObjects[0], + .hwAttrs = &nvsSPI25XHWAttrs[0], + }, +#endif +}; + +const uint_least8_t NVS_count = CC1312R1_LAUNCHXL_NVSCOUNT; + +#endif /* TI_NVS_CONF_ENABLE */ + +/* + * =============================== PIN =============================== + */ +#include +#include + +const PIN_Config BoardGpioInitTable[] = { + + CC1312R1_LAUNCHXL_PIN_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC1312R1_LAUNCHXL_PIN_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC1312R1_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC1312R1_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC1312R1_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ + CC1312R1_LAUNCHXL_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */ + CC1312R1_LAUNCHXL_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */ + CC1312R1_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */ + CC1312R1_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */ + CC1312R1_LAUNCHXL_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI clock */ + + PIN_TERMINATE +}; + +const PINCC26XX_HWAttrs PINCC26XX_hwAttrs = { + .intPriority = ~0, + .swiPriority = 0 +}; + +/* + * =============================== Power =============================== + */ +#include +#include + +const PowerCC26X2_Config PowerCC26X2_config = { + .policyInitFxn = NULL, + .policyFxn = &PowerCC26XX_standbyPolicy, + .calibrateFxn = &PowerCC26XX_calibrate, + .enablePolicy = true, + .calibrateRCOSC_LF = true, + .calibrateRCOSC_HF = true, +}; + +/* + * =============================== PWM =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include +#include + +PWMTimerCC26XX_Object pwmtimerCC26xxObjects[CC1312R1_LAUNCHXL_PWMCOUNT]; + +const PWMTimerCC26XX_HwAttrs pwmtimerCC26xxHWAttrs[CC1312R1_LAUNCHXL_PWMCOUNT] = { + { .pwmPin = CC1312R1_LAUNCHXL_PWMPIN0, .gpTimerUnit = CC1312R1_LAUNCHXL_GPTIMER0A }, + { .pwmPin = CC1312R1_LAUNCHXL_PWMPIN1, .gpTimerUnit = CC1312R1_LAUNCHXL_GPTIMER0B }, + { .pwmPin = CC1312R1_LAUNCHXL_PWMPIN2, .gpTimerUnit = CC1312R1_LAUNCHXL_GPTIMER1A }, + { .pwmPin = CC1312R1_LAUNCHXL_PWMPIN3, .gpTimerUnit = CC1312R1_LAUNCHXL_GPTIMER1B }, + { .pwmPin = CC1312R1_LAUNCHXL_PWMPIN4, .gpTimerUnit = CC1312R1_LAUNCHXL_GPTIMER2A }, + { .pwmPin = CC1312R1_LAUNCHXL_PWMPIN5, .gpTimerUnit = CC1312R1_LAUNCHXL_GPTIMER2B }, + { .pwmPin = CC1312R1_LAUNCHXL_PWMPIN6, .gpTimerUnit = CC1312R1_LAUNCHXL_GPTIMER3A }, + { .pwmPin = CC1312R1_LAUNCHXL_PWMPIN7, .gpTimerUnit = CC1312R1_LAUNCHXL_GPTIMER3B }, +}; + +const PWM_Config PWM_config[CC1312R1_LAUNCHXL_PWMCOUNT] = { + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1312R1_LAUNCHXL_PWM0], &pwmtimerCC26xxHWAttrs[CC1312R1_LAUNCHXL_PWM0] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1312R1_LAUNCHXL_PWM1], &pwmtimerCC26xxHWAttrs[CC1312R1_LAUNCHXL_PWM1] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1312R1_LAUNCHXL_PWM2], &pwmtimerCC26xxHWAttrs[CC1312R1_LAUNCHXL_PWM2] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1312R1_LAUNCHXL_PWM3], &pwmtimerCC26xxHWAttrs[CC1312R1_LAUNCHXL_PWM3] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1312R1_LAUNCHXL_PWM4], &pwmtimerCC26xxHWAttrs[CC1312R1_LAUNCHXL_PWM4] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1312R1_LAUNCHXL_PWM5], &pwmtimerCC26xxHWAttrs[CC1312R1_LAUNCHXL_PWM5] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1312R1_LAUNCHXL_PWM6], &pwmtimerCC26xxHWAttrs[CC1312R1_LAUNCHXL_PWM6] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1312R1_LAUNCHXL_PWM7], &pwmtimerCC26xxHWAttrs[CC1312R1_LAUNCHXL_PWM7] }, +}; + +const uint_least8_t PWM_count = CC1312R1_LAUNCHXL_PWMCOUNT; + +/* + * =============================== RF Driver =============================== + */ +#include + +const RFCC26XX_HWAttrsV2 RFCC26XX_hwAttrs = { + .hwiPriority = ~0, /* Lowest HWI priority */ + .swiPriority = 0, /* Lowest SWI priority */ + .xoscHfAlwaysNeeded = true, /* Keep XOSC dependency while in stanby */ + .globalCallback = NULL, /* No board specific callback */ + .globalEventMask = 0 /* No events subscribed to */ +}; + +/* + * =============================== SD =============================== + */ +#include +#include + +#if TI_SD_CONF_ENABLE + +#if !(TI_SPI_CONF_SPI0_ENABLE) +#error "SD driver requires SPI0 enabled" +#endif + +SDSPI_Object sdspiObjects[CC1312R1_LAUNCHXL_SDCOUNT]; + +const SDSPI_HWAttrs sdspiHWAttrs[CC1312R1_LAUNCHXL_SDCOUNT] = { + { + .spiIndex = CC1312R1_LAUNCHXL_SPI0, + .spiCsGpioIndex = CC1312R1_LAUNCHXL_SDSPI_CS + } +}; + +const SD_Config SD_config[CC1312R1_LAUNCHXL_SDCOUNT] = { + { + .fxnTablePtr = &SDSPI_fxnTable, + .object = &sdspiObjects[CC1312R1_LAUNCHXL_SDSPI0], + .hwAttrs = &sdspiHWAttrs[CC1312R1_LAUNCHXL_SDSPI0] + }, +}; + +const uint_least8_t SD_count = CC1312R1_LAUNCHXL_SDCOUNT; + +#endif /* TI_SD_CONF_ENABLE */ + +/* + * =============================== SPI DMA =============================== + */ +#include +#include + +#if TI_SPI_CONF_ENABLE + +SPICC26XXDMA_Object spiCC26XXDMAObjects[CC1312R1_LAUNCHXL_SPICOUNT]; + +/* + * NOTE: The SPI instances below can be used by the SD driver to communicate + * with a SD card via SPI. The 'defaultTxBufValue' fields below are set to 0xFF + * to satisfy the SDSPI driver requirement. + */ +const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[CC1312R1_LAUNCHXL_SPICOUNT] = { +#if TI_SPI_CONF_SPI0_ENABLE + { + .baseAddr = SSI0_BASE, + .intNum = INT_SSI0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .powerMngrId = PowerCC26XX_PERIPH_SSI0, + .defaultTxBufValue = 0xFF, + .rxChannelBitMask = 1< +#include + +TRNGCC26X2_Object trngCC26X2Object[CC1312R1_LAUNCHXL_TRNGCOUNT]; + +const TRNGCC26X2_HWAttrs trngCC26X2HWAttrs[CC1312R1_LAUNCHXL_TRNGCOUNT] = { + { + .swiPriority = 0, + .intPriority = ~0, + } +}; + +const TRNG_Config TRNG_config[] = { + { &trngCC26X2Object[0], &trngCC26X2HWAttrs[0] }, +}; + +const uint8_t TRNG_count = CC1312R1_LAUNCHXL_TRNGCOUNT; + + +/* + * =============================== UART =============================== + */ +#include +#include + +#if TI_UART_CONF_ENABLE + +UARTCC26XX_Object uartCC26XXObjects[CC1312R1_LAUNCHXL_UARTCOUNT]; + +uint8_t uartCC26XXRingBuffer[CC1312R1_LAUNCHXL_UARTCOUNT][32]; + +const UARTCC26XX_HWAttrsV2 uartCC26XXHWAttrs[CC1312R1_LAUNCHXL_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .baseAddr = UART0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UART0, + .intNum = INT_UART0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .txPin = CC1312R1_LAUNCHXL_UART_TX, + .rxPin = CC1312R1_LAUNCHXL_UART_RX, + .ctsPin = PIN_UNASSIGNED, + .rtsPin = PIN_UNASSIGNED, + .ringBufPtr = uartCC26XXRingBuffer[CC1312R1_LAUNCHXL_UART0], + .ringBufSize = sizeof(uartCC26XXRingBuffer[CC1312R1_LAUNCHXL_UART0]), + .txIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_1_8, + .rxIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_4_8, + .errorFxn = NULL + }, +#endif +}; + +const UART_Config UART_config[CC1312R1_LAUNCHXL_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .fxnTablePtr = &UARTCC26XX_fxnTable, + .object = &uartCC26XXObjects[CC1312R1_LAUNCHXL_UART0], + .hwAttrs = &uartCC26XXHWAttrs[CC1312R1_LAUNCHXL_UART0] + }, +#endif +}; + +const uint_least8_t UART_count = CC1312R1_LAUNCHXL_UARTCOUNT; + +#endif /* TI_UART_CONF_ENABLE */ + +/* + * =============================== UDMA =============================== + */ +#include + +UDMACC26XX_Object udmaObjects[CC1312R1_LAUNCHXL_UDMACOUNT]; + +const UDMACC26XX_HWAttrs udmaHWAttrs[CC1312R1_LAUNCHXL_UDMACOUNT] = { + { + .baseAddr = UDMA0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UDMA, + .intNum = INT_DMA_ERR, + .intPriority = ~0 + } +}; + +const UDMACC26XX_Config UDMACC26XX_config[CC1312R1_LAUNCHXL_UDMACOUNT] = { + { + .object = &udmaObjects[CC1312R1_LAUNCHXL_UDMA0], + .hwAttrs = &udmaHWAttrs[CC1312R1_LAUNCHXL_UDMA0] + }, +}; + +/* + * =============================== Watchdog =============================== + */ +#include +#include + +WatchdogCC26XX_Object watchdogCC26XXObjects[CC1312R1_LAUNCHXL_WATCHDOGCOUNT]; + +const WatchdogCC26XX_HWAttrs watchdogCC26XXHWAttrs[CC1312R1_LAUNCHXL_WATCHDOGCOUNT] = { + { + .baseAddr = WDT_BASE, + .reloadValue = 1000 /* Reload value in milliseconds */ + }, +}; + +const Watchdog_Config Watchdog_config[CC1312R1_LAUNCHXL_WATCHDOGCOUNT] = { + { + .fxnTablePtr = &WatchdogCC26XX_fxnTable, + .object = &watchdogCC26XXObjects[CC1312R1_LAUNCHXL_WATCHDOG0], + .hwAttrs = &watchdogCC26XXHWAttrs[CC1312R1_LAUNCHXL_WATCHDOG0] + }, +}; + +const uint_least8_t Watchdog_count = CC1312R1_LAUNCHXL_WATCHDOGCOUNT; + +/* + * Board-specific initialization function to disable external flash. + * This function is defined in the file CC1312R1_LAUNCHXL_fxns.c + */ +extern void Board_initHook(void); + +/* + * ======== CC1312R1_LAUNCHXL_initGeneral ======== + */ +void CC1312R1_LAUNCHXL_initGeneral(void) +{ + Power_init(); + + if (PIN_init(BoardGpioInitTable) != PIN_SUCCESS) { + /* Error with PIN_init */ + while (1); + } + + /* Perform board-specific initialization */ + Board_initHook(); +} diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/CC1312R1_LAUNCHXL.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/CC1312R1_LAUNCHXL.h new file mode 100644 index 000000000..0295dc0b4 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/CC1312R1_LAUNCHXL.h @@ -0,0 +1,440 @@ +/* + * Copyright (c) 2015-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 CC1312R1_LAUNCHXL.h + * + * @brief CC1312R1 LaunchPad Board Specific header file. + * + * The CC1312R1_LAUNCHXL header file should be included in an application as + * follows: + * @code + * #include "CC1312R1_LAUNCHXL.h" + * @endcode + * + * ============================================================================ + */ +#ifndef __CC1312R1_LAUNCHXL_BOARD_H__ +#define __CC1312R1_LAUNCHXL_BOARD_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "contiki-conf.h" + +/* Includes */ +#include +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) + +/* Externs */ +extern const PIN_Config BoardGpioInitTable[]; + +/* Defines */ +#define CC1312R1_LAUNCHXL + +/* Mapping of pins to board signals using general board aliases + * + */ + +/* Analog capable DIOs */ +#define CC1312R1_LAUNCHXL_DIO23_ANALOG IOID_23 +#define CC1312R1_LAUNCHXL_DIO24_ANALOG IOID_24 +#define CC1312R1_LAUNCHXL_DIO25_ANALOG IOID_25 +#define CC1312R1_LAUNCHXL_DIO26_ANALOG IOID_26 +#define CC1312R1_LAUNCHXL_DIO27_ANALOG IOID_27 +#define CC1312R1_LAUNCHXL_DIO28_ANALOG IOID_28 +#define CC1312R1_LAUNCHXL_DIO29_ANALOG IOID_29 +#define CC1312R1_LAUNCHXL_DIO30_ANALOG IOID_30 + +/* Digital IOs */ +#define CC1312R1_LAUNCHXL_DIO0 IOID_0 +#define CC1312R1_LAUNCHXL_DIO1 IOID_1 +#define CC1312R1_LAUNCHXL_DIO12 IOID_12 +#define CC1312R1_LAUNCHXL_DIO15 IOID_15 +#define CC1312R1_LAUNCHXL_DIO16_TDO IOID_16 +#define CC1312R1_LAUNCHXL_DIO17_TDI IOID_17 +#define CC1312R1_LAUNCHXL_DIO21 IOID_21 +#define CC1312R1_LAUNCHXL_DIO22 IOID_22 + +/* Discrete Inputs */ +#define CC1312R1_LAUNCHXL_PIN_BTN1 IOID_13 +#define CC1312R1_LAUNCHXL_PIN_BTN2 IOID_14 + +/* GPIO */ +#define CC1312R1_LAUNCHXL_GPIO_LED_ON 1 +#define CC1312R1_LAUNCHXL_GPIO_LED_OFF 0 + +/* I2C */ +#define CC1312R1_LAUNCHXL_I2C0_SCL0 IOID_4 +#define CC1312R1_LAUNCHXL_I2C0_SDA0 IOID_5 + +/* LEDs */ +#define CC1312R1_LAUNCHXL_PIN_LED_ON 1 +#define CC1312R1_LAUNCHXL_PIN_LED_OFF 0 +#define CC1312R1_LAUNCHXL_PIN_RLED IOID_6 +#define CC1312R1_LAUNCHXL_PIN_GLED IOID_7 + +/* PWM Outputs */ +#define CC1312R1_LAUNCHXL_PWMPIN0 CC1312R1_LAUNCHXL_PIN_RLED +#define CC1312R1_LAUNCHXL_PWMPIN1 CC1312R1_LAUNCHXL_PIN_GLED +#define CC1312R1_LAUNCHXL_PWMPIN2 PIN_UNASSIGNED +#define CC1312R1_LAUNCHXL_PWMPIN3 PIN_UNASSIGNED +#define CC1312R1_LAUNCHXL_PWMPIN4 PIN_UNASSIGNED +#define CC1312R1_LAUNCHXL_PWMPIN5 PIN_UNASSIGNED +#define CC1312R1_LAUNCHXL_PWMPIN6 PIN_UNASSIGNED +#define CC1312R1_LAUNCHXL_PWMPIN7 PIN_UNASSIGNED + +/* SPI */ +#define CC1312R1_LAUNCHXL_SPI_FLASH_CS IOID_20 +#define CC1312R1_LAUNCHXL_FLASH_CS_ON 0 +#define CC1312R1_LAUNCHXL_FLASH_CS_OFF 1 + +/* SPI Board */ +#define CC1312R1_LAUNCHXL_SPI0_MISO IOID_8 /* RF1.20 */ +#define CC1312R1_LAUNCHXL_SPI0_MOSI IOID_9 /* RF1.18 */ +#define CC1312R1_LAUNCHXL_SPI0_CLK IOID_10 /* RF1.16 */ +#define CC1312R1_LAUNCHXL_SPI0_CSN PIN_UNASSIGNED +#define CC1312R1_LAUNCHXL_SPI1_MISO PIN_UNASSIGNED +#define CC1312R1_LAUNCHXL_SPI1_MOSI PIN_UNASSIGNED +#define CC1312R1_LAUNCHXL_SPI1_CLK PIN_UNASSIGNED +#define CC1312R1_LAUNCHXL_SPI1_CSN PIN_UNASSIGNED + +/* UART Board */ +#define CC1312R1_LAUNCHXL_UART0_RX IOID_2 /* RXD */ +#define CC1312R1_LAUNCHXL_UART0_TX IOID_3 /* TXD */ +#define CC1312R1_LAUNCHXL_UART0_CTS IOID_19 /* CTS */ +#define CC1312R1_LAUNCHXL_UART0_RTS IOID_18 /* RTS */ +#define CC1312R1_LAUNCHXL_UART1_RX PIN_UNASSIGNED +#define CC1312R1_LAUNCHXL_UART1_TX PIN_UNASSIGNED +#define CC1312R1_LAUNCHXL_UART1_CTS PIN_UNASSIGNED +#define CC1312R1_LAUNCHXL_UART1_RTS PIN_UNASSIGNED +/* For backward compatibility */ +#define CC1312R1_LAUNCHXL_UART_RX CC1312R1_LAUNCHXL_UART0_RX +#define CC1312R1_LAUNCHXL_UART_TX CC1312R1_LAUNCHXL_UART0_TX +#define CC1312R1_LAUNCHXL_UART_CTS CC1312R1_LAUNCHXL_UART0_CTS +#define CC1312R1_LAUNCHXL_UART_RTS CC1312R1_LAUNCHXL_UART0_RTS + +/*! + * @brief Initialize the general board specific settings + * + * This function initializes the general board specific settings. + */ +void CC1312R1_LAUNCHXL_initGeneral(void); + +/*! + * @brief Turn off the external flash on LaunchPads + * + */ +void CC1312R1_LAUNCHXL_shutDownExtFlash(void); + +/*! + * @brief Wake up the external flash present on the board files + * + * This function toggles the chip select for the amount of time needed + * to wake the chip up. + */ +void CC1312R1_LAUNCHXL_wakeUpExtFlash(void); + +/*! + * @def CC1312R1_LAUNCHXL_ADCBufName + * @brief Enum of ADCBufs + */ +typedef enum CC1312R1_LAUNCHXL_ADCBufName { + CC1312R1_LAUNCHXL_ADCBUF0 = 0, + + CC1312R1_LAUNCHXL_ADCBUFCOUNT +} CC1312R1_LAUNCHXL_ADCBufName; + +/*! + * @def CC1312R1_LAUNCHXL_ADCBuf0ChannelName + * @brief Enum of ADCBuf channels + */ +typedef enum CC1312R1_LAUNCHXL_ADCBuf0ChannelName { + CC1312R1_LAUNCHXL_ADCBUF0CHANNEL0 = 0, + CC1312R1_LAUNCHXL_ADCBUF0CHANNEL1, + CC1312R1_LAUNCHXL_ADCBUF0CHANNEL2, + CC1312R1_LAUNCHXL_ADCBUF0CHANNEL3, + CC1312R1_LAUNCHXL_ADCBUF0CHANNEL4, + CC1312R1_LAUNCHXL_ADCBUF0CHANNEL5, + CC1312R1_LAUNCHXL_ADCBUF0CHANNEL6, + CC1312R1_LAUNCHXL_ADCBUF0CHANNEL7, + CC1312R1_LAUNCHXL_ADCBUF0CHANNELVDDS, + CC1312R1_LAUNCHXL_ADCBUF0CHANNELDCOUPL, + CC1312R1_LAUNCHXL_ADCBUF0CHANNELVSS, + + CC1312R1_LAUNCHXL_ADCBUF0CHANNELCOUNT +} CC1312R1_LAUNCHXL_ADCBuf0ChannelName; + +/*! + * @def CC1312R1_LAUNCHXL_ADCName + * @brief Enum of ADCs + */ +typedef enum CC1312R1_LAUNCHXL_ADCName { + CC1312R1_LAUNCHXL_ADC0 = 0, + CC1312R1_LAUNCHXL_ADC1, + CC1312R1_LAUNCHXL_ADC2, + CC1312R1_LAUNCHXL_ADC3, + CC1312R1_LAUNCHXL_ADC4, + CC1312R1_LAUNCHXL_ADC5, + CC1312R1_LAUNCHXL_ADC6, + CC1312R1_LAUNCHXL_ADC7, + CC1312R1_LAUNCHXL_ADCDCOUPL, + CC1312R1_LAUNCHXL_ADCVSS, + CC1312R1_LAUNCHXL_ADCVDDS, + + CC1312R1_LAUNCHXL_ADCCOUNT +} CC1312R1_LAUNCHXL_ADCName; + +/*! + * @def CC1312R1_LAUNCHXL_ECDHName + * @brief Enum of ECDH names + */ +typedef enum CC1312R1_LAUNCHXL_ECDHName { + CC1312R1_LAUNCHXL_ECDH0 = 0, + + CC1312R1_LAUNCHXL_ECDHCOUNT +} CC1312R1_LAUNCHXL_ECDHName; + +/*! + * @def CC1312R1_LAUNCHXL_ECDSAName + * @brief Enum of ECDSA names + */ +typedef enum CC1312R1_LAUNCHXL_ECDSAName { + CC1312R1_LAUNCHXL_ECDSA0 = 0, + + CC1312R1_LAUNCHXL_ECDSACOUNT +} CC1312R1_LAUNCHXL_ECDSAName; + +/*! + * @def CC1312R1_LAUNCHXL_ECJPAKEName + * @brief Enum of ECJPAKE names + */ +typedef enum CC1312R1_LAUNCHXL_ECJPAKEName { + CC1312R1_LAUNCHXL_ECJPAKE0 = 0, + + CC1312R1_LAUNCHXL_ECJPAKECOUNT +} CC1312R1_LAUNCHXL_ECJPAKEName; + +/*! + * @def CC1312R1_LAUNCHXL_AESCCMName + * @brief Enum of AESCCM names + */ +typedef enum CC1312R1_LAUNCHXL_AESCCMName { + CC1312R1_LAUNCHXL_AESCCM0 = 0, + + CC1312R1_LAUNCHXL_AESCCMCOUNT +} CC1312R1_LAUNCHXL_AESCCMName; + +/*! + * @def CC1312R1_LAUNCHXL_AESECBName + * @brief Enum of AESECB names + */ +typedef enum CC1312R1_LAUNCHXL_AESECBName { + CC1312R1_LAUNCHXL_AESECB0 = 0, + + CC1312R1_LAUNCHXL_AESECBCOUNT +} CC1312R1_LAUNCHXL_AESECBName; + +/*! + * @def CC1312R1_LAUNCHXL_SHA2Name + * @brief Enum of SHA2 names + */ +typedef enum CC1312R1_LAUNCHXL_SHA2Name { + CC1312R1_LAUNCHXL_SHA20 = 0, + + CC1312R1_LAUNCHXL_SHA2COUNT +} CC1312R1_LAUNCHXL_SHA2Name; + +/*! + * @def CC1312R1_LAUNCHXL_GPIOName + * @brief Enum of GPIO names + */ +typedef enum CC1312R1_LAUNCHXL_GPIOName { + CC1312R1_LAUNCHXL_GPIO_S1 = 0, + CC1312R1_LAUNCHXL_GPIO_S2, + CC1312R1_LAUNCHXL_SPI_MASTER_READY, + CC1312R1_LAUNCHXL_SPI_SLAVE_READY, + CC1312R1_LAUNCHXL_GPIO_LED_GREEN, + CC1312R1_LAUNCHXL_GPIO_LED_RED, + CC1312R1_LAUNCHXL_GPIO_SPI_FLASH_CS, + CC1312R1_LAUNCHXL_SDSPI_CS, + CC1312R1_LAUNCHXL_GPIOCOUNT +} CC1312R1_LAUNCHXL_GPIOName; + +/*! + * @def CC1312R1_LAUNCHXL_GPTimerName + * @brief Enum of GPTimer parts + */ +typedef enum CC1312R1_LAUNCHXL_GPTimerName { + CC1312R1_LAUNCHXL_GPTIMER0A = 0, + CC1312R1_LAUNCHXL_GPTIMER0B, + CC1312R1_LAUNCHXL_GPTIMER1A, + CC1312R1_LAUNCHXL_GPTIMER1B, + CC1312R1_LAUNCHXL_GPTIMER2A, + CC1312R1_LAUNCHXL_GPTIMER2B, + CC1312R1_LAUNCHXL_GPTIMER3A, + CC1312R1_LAUNCHXL_GPTIMER3B, + + CC1312R1_LAUNCHXL_GPTIMERPARTSCOUNT +} CC1312R1_LAUNCHXL_GPTimerName; + +/*! + * @def CC1312R1_LAUNCHXL_GPTimers + * @brief Enum of GPTimers + */ +typedef enum CC1312R1_LAUNCHXL_GPTimers { + CC1312R1_LAUNCHXL_GPTIMER0 = 0, + CC1312R1_LAUNCHXL_GPTIMER1, + CC1312R1_LAUNCHXL_GPTIMER2, + CC1312R1_LAUNCHXL_GPTIMER3, + + CC1312R1_LAUNCHXL_GPTIMERCOUNT +} CC1312R1_LAUNCHXL_GPTimers; + +/*! + * @def CC1312R1_LAUNCHXL_I2CName + * @brief Enum of I2C names + */ +typedef enum CC1312R1_LAUNCHXL_I2CName { +#if TI_I2C_CONF_I2C0_ENABLE + CC1312R1_LAUNCHXL_I2C0 = 0, +#endif + + CC1312R1_LAUNCHXL_I2CCOUNT +} CC1312R1_LAUNCHXL_I2CName; + +/*! + * @def CC1312R1_LAUNCHXL_NVSName + * @brief Enum of NVS names + */ +typedef enum CC1312R1_LAUNCHXL_NVSName { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + CC1312R1_LAUNCHXL_NVSCC26XX0 = 0, +#endif +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + CC1312R1_LAUNCHXL_NVSSPI25X0, +#endif + + CC1312R1_LAUNCHXL_NVSCOUNT +} CC1312R1_LAUNCHXL_NVSName; + +/*! + * @def CC1312R1_LAUNCHXL_PWMName + * @brief Enum of PWM outputs + */ +typedef enum CC1312R1_LAUNCHXL_PWMName { + CC1312R1_LAUNCHXL_PWM0 = 0, + CC1312R1_LAUNCHXL_PWM1, + CC1312R1_LAUNCHXL_PWM2, + CC1312R1_LAUNCHXL_PWM3, + CC1312R1_LAUNCHXL_PWM4, + CC1312R1_LAUNCHXL_PWM5, + CC1312R1_LAUNCHXL_PWM6, + CC1312R1_LAUNCHXL_PWM7, + + CC1312R1_LAUNCHXL_PWMCOUNT +} CC1312R1_LAUNCHXL_PWMName; + +/*! + * @def CC1312R1_LAUNCHXL_SDName + * @brief Enum of SD names + */ +typedef enum CC1312R1_LAUNCHXL_SDName { + CC1312R1_LAUNCHXL_SDSPI0 = 0, + + CC1312R1_LAUNCHXL_SDCOUNT +} CC1312R1_LAUNCHXL_SDName; + +/*! + * @def CC1312R1_LAUNCHXL_SPIName + * @brief Enum of SPI names + */ +typedef enum CC1312R1_LAUNCHXL_SPIName { +#if TI_SPI_CONF_SPI0_ENABLE + CC1312R1_LAUNCHXL_SPI0 = 0, +#endif +#if TI_SPI_CONF_SPI1_ENABLE + CC1312R1_LAUNCHXL_SPI1, +#endif + + CC1312R1_LAUNCHXL_SPICOUNT +} CC1312R1_LAUNCHXL_SPIName; + +/*! + * @def CC1312R1_LAUNCHXL_TRNGName + * @brief Enum of TRNGs + */ +typedef enum CC1312R1_LAUNCHXL_TRNGName { + CC1312R1_LAUNCHXL_TRNG0 = 0, + + CC1312R1_LAUNCHXL_TRNGCOUNT +} CC1312R1_LAUNCHXL_TRNGName; + +/*! + * @def CC1312R1_LAUNCHXL_UARTName + * @brief Enum of UARTs + */ +typedef enum CC1312R1_LAUNCHXL_UARTName { +#if TI_UART_CONF_UART0_ENABLE + CC1312R1_LAUNCHXL_UART0 = 0, +#endif + + CC1312R1_LAUNCHXL_UARTCOUNT +} CC1312R1_LAUNCHXL_UARTName; + +/*! + * @def CC1312R1_LAUNCHXL_UDMAName + * @brief Enum of DMA buffers + */ +typedef enum CC1312R1_LAUNCHXL_UDMAName { + CC1312R1_LAUNCHXL_UDMA0 = 0, + + CC1312R1_LAUNCHXL_UDMACOUNT +} CC1312R1_LAUNCHXL_UDMAName; + +/*! + * @def CC1312R1_LAUNCHXL_WatchdogName + * @brief Enum of Watchdogs + */ +typedef enum CC1312R1_LAUNCHXL_WatchdogName { + CC1312R1_LAUNCHXL_WATCHDOG0 = 0, + + CC1312R1_LAUNCHXL_WATCHDOGCOUNT +} CC1312R1_LAUNCHXL_WatchdogName; + + +#ifdef __cplusplus +} +#endif + +#endif /* __CC1312R1_LAUNCHXL_BOARD_H__ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/CC1312R1_LAUNCHXL_fxns.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/CC1312R1_LAUNCHXL_fxns.c new file mode 100644 index 000000000..0a28583d4 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/CC1312R1_LAUNCHXL_fxns.c @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +/* + * ======== CC1312R1_LAUNCHXL_fxns.c ======== + * This file contains the board-specific initialization functions. + */ + +#include +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/cpu.h) +#include + +#include "Board.h" + +/* + * ======== CC1312R1_LAUNCHXL_sendExtFlashByte ======== + */ +void CC1312R1_LAUNCHXL_sendExtFlashByte(PIN_Handle pinHandle, uint8_t byte) +{ + uint8_t i; + + /* SPI Flash CS */ + PIN_setOutputValue(pinHandle, IOID_20, 0); + + for (i = 0; i < 8; i++) { + PIN_setOutputValue(pinHandle, IOID_10, 0); /* SPI Flash CLK */ + + /* SPI Flash MOSI */ + PIN_setOutputValue(pinHandle, IOID_9, (byte >> (7 - i)) & 0x01); + PIN_setOutputValue(pinHandle, IOID_10, 1); /* SPI Flash CLK */ + + /* + * Waste a few cycles to keep the CLK high for at + * least 45% of the period. + * 3 cycles per loop: 8 loops @ 48 Mhz = 0.5 us. + */ + CPUdelay(8); + } + + PIN_setOutputValue(pinHandle, IOID_10, 0); /* CLK */ + PIN_setOutputValue(pinHandle, IOID_20, 1); /* CS */ + + /* + * Keep CS high at least 40 us + * 3 cycles per loop: 700 loops @ 48 Mhz ~= 44 us + */ + CPUdelay(700); +} + +/* + * ======== CC1312R1_LAUNCHXL_wakeUpExtFlash ======== + */ +void CC1312R1_LAUNCHXL_wakeUpExtFlash(void) +{ + PIN_Config extFlashPinTable[] = { + /* SPI Flash CS */ + IOID_20 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + PIN_TERMINATE + }; + PIN_State extFlashPinState; + PIN_Handle extFlashPinHandle = PIN_open(&extFlashPinState, extFlashPinTable); + + /* + * To wake up we need to toggle the chip select at + * least 20 ns and ten wait at least 35 us. + */ + + /* Toggle chip select for ~20ns to wake ext. flash */ + PIN_setOutputValue(extFlashPinHandle, IOID_20, 0); + /* 3 cycles per loop: 1 loop @ 48 Mhz ~= 62 ns */ + CPUdelay(1); + PIN_setOutputValue(extFlashPinHandle, IOID_20, 1); + /* 3 cycles per loop: 560 loops @ 48 Mhz ~= 35 us */ + CPUdelay(560); + + PIN_close(extFlashPinHandle); +} + +/* + * ======== CC1312R1_LAUNCHXL_shutDownExtFlash ======== + */ +void CC1312R1_LAUNCHXL_shutDownExtFlash(void) +{ + /* + * To be sure we are putting the flash into sleep and not waking it, + * we first have to make a wake up call + */ + CC1312R1_LAUNCHXL_wakeUpExtFlash(); + + PIN_Config extFlashPinTable[] = { + /* SPI Flash CS*/ + IOID_20 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash CLK */ + IOID_10 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash MOSI */ + IOID_9 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash MISO */ + IOID_8 | PIN_INPUT_EN | PIN_PULLDOWN, + PIN_TERMINATE + }; + PIN_State extFlashPinState; + PIN_Handle extFlashPinHandle = PIN_open(&extFlashPinState, extFlashPinTable); + + uint8_t extFlashShutdown = 0xB9; + + CC1312R1_LAUNCHXL_sendExtFlashByte(extFlashPinHandle, extFlashShutdown); + + PIN_close(extFlashPinHandle); +} + +/* + * ======== Board_initHook ======== + * Called by Board_init() to perform board-specific initialization. + */ +void Board_initHook() +{ + CC1312R1_LAUNCHXL_shutDownExtFlash(); +} diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/Makefile.cc1312r1 b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/Makefile.cc1312r1 new file mode 100644 index 000000000..b88997c9a --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/Makefile.cc1312r1 @@ -0,0 +1,21 @@ +################################################################################ +# SimpleLink Device makefile + +SUBFAMILY = cc13x2-cc26x2 +DEVICE_FAMILY = CC13X2 +DEVICE_LINE = CC13XX +DEVICE = CC1312R + +BOARD_SOURCEFILES += CC1312R1_LAUNCHXL.c CC1312R1_LAUNCHXL_fxns.c + +SUPPORTS_PROP_MODE = 1 +SUPPORTS_IEEE_MODE = 0 +SUPPORTS_BLE_BEACON = 0 + +SUPPORTS_HIGH_PA = 0 + +### Signal that we can be programmed with cc2538-bsl +BOARD_SUPPORTS_BSL = 0 + +# Include the common board makefile +include $(FAMILY_PATH)/launchpad/Makefile.launchpad diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/Board.h new file mode 100644 index 000000000..c8094432a --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/Board.h @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2017-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 __BOARD_H +#define __BOARD_H + +#define Board_CC1350_LAUNCHXL_433 +#define BOARD_STRING "TI CC1350-433 LaunchPad" + +#ifdef __cplusplus +extern "C" { +#endif + +#include "CC1350_LAUNCHXL_433.h" + +#define Board_initGeneral() CC1350_LAUNCHXL_433_initGeneral() +#define Board_shutDownExtFlash() CC1350_LAUNCHXL_433_shutDownExtFlash() +#define Board_wakeUpExtFlash() CC1350_LAUNCHXL_433_wakeUpExtFlash() + +/* These #defines allow us to reuse TI-RTOS across other device families */ + +#define Board_ADC0 CC1350_LAUNCHXL_433_ADC0 +#define Board_ADC1 CC1350_LAUNCHXL_433_ADC1 + +#define Board_ADCBUF0 CC1350_LAUNCHXL_433_ADCBUF0 +#define Board_ADCBUF0CHANNEL0 CC1350_LAUNCHXL_433_ADCBUF0CHANNEL0 +#define Board_ADCBUF0CHANNEL1 CC1350_LAUNCHXL_433_ADCBUF0CHANNEL1 + +#define Board_CRYPTO0 CC1350_LAUNCHXL_433_CRYPTO0 + +#define Board_DIO0 CC1350_LAUNCHXL_433_DIO0 +#define Board_DIO1_RFSW CC1350_LAUNCHXL_433_DIO1_RF_SUB1GHZ +#define Board_DIO12 CC1350_LAUNCHXL_433_DIO12 +#define Board_DIO15 CC1350_LAUNCHXL_433_DIO15 +#define Board_DIO16_TDO CC1350_LAUNCHXL_433_DIO16_TDO +#define Board_DIO17_TDI CC1350_LAUNCHXL_433_DIO17_TDI +#define Board_DIO21 CC1350_LAUNCHXL_433_DIO21 +#define Board_DIO22 CC1350_LAUNCHXL_433_DIO22 +#define Board_DIO30_SWPWR CC1350_LAUNCHXL_433_DIO30_RF_POWER + +#define Board_DIO23_ANALOG CC1350_LAUNCHXL_433_DIO23_ANALOG +#define Board_DIO24_ANALOG CC1350_LAUNCHXL_433_DIO24_ANALOG +#define Board_DIO25_ANALOG CC1350_LAUNCHXL_433_DIO25_ANALOG +#define Board_DIO26_ANALOG CC1350_LAUNCHXL_433_DIO26_ANALOG +#define Board_DIO27_ANALOG CC1350_LAUNCHXL_433_DIO27_ANALOG +#define Board_DIO28_ANALOG CC1350_LAUNCHXL_433_DIO28_ANALOG +#define Board_DIO29_ANALOG CC1350_LAUNCHXL_433_DIO29_ANALOG +#define Board_DIO30_ANALOG CC1350_LAUNCHXL_433_DIO30_ANALOG + +/* + * Board_RF_SUB1GHZ and Board_RF_POWER are the names generated by SysConfig. + * Define them here so that RF callback function can reference them. + */ +#define Board_RF_SUB1GHZ CC1350_LAUNCHXL_433_DIO1_RF_SUB1GHZ +#define Board_RF_POWER CC1350_LAUNCHXL_433_DIO30_RF_POWER + +#define Board_GPIO_BUTTON0 CC1350_LAUNCHXL_433_GPIO_S1 +#define Board_GPIO_BUTTON1 CC1350_LAUNCHXL_433_GPIO_S2 +#define Board_GPIO_BTN1 CC1350_LAUNCHXL_433_GPIO_S1 +#define Board_GPIO_BTN2 CC1350_LAUNCHXL_433_GPIO_S2 +#define Board_GPIO_LED0 CC1350_LAUNCHXL_433_GPIO_LED_RED +#define Board_GPIO_LED1 CC1350_LAUNCHXL_433_GPIO_LED_GREEN +#define Board_GPIO_RLED CC1350_LAUNCHXL_433_GPIO_LED_RED +#define Board_GPIO_GLED CC1350_LAUNCHXL_433_GPIO_LED_GREEN +#define Board_GPIO_LED_ON CC1350_LAUNCHXL_433_GPIO_LED_ON +#define Board_GPIO_LED_OFF CC1350_LAUNCHXL_433_GPIO_LED_OFF + +#define Board_GPTIMER0A CC1350_LAUNCHXL_433_GPTIMER0A +#define Board_GPTIMER0B CC1350_LAUNCHXL_433_GPTIMER0B +#define Board_GPTIMER1A CC1350_LAUNCHXL_433_GPTIMER1A +#define Board_GPTIMER1B CC1350_LAUNCHXL_433_GPTIMER1B +#define Board_GPTIMER2A CC1350_LAUNCHXL_433_GPTIMER2A +#define Board_GPTIMER2B CC1350_LAUNCHXL_433_GPTIMER2B +#define Board_GPTIMER3A CC1350_LAUNCHXL_433_GPTIMER3A +#define Board_GPTIMER3B CC1350_LAUNCHXL_433_GPTIMER3B + +#define Board_NVSINTERNAL CC1350_LAUNCHXL_433_NVSCC26XX0 +#define Board_NVSEXTERNAL CC1350_LAUNCHXL_433_NVSSPI25X0 + +#define Board_I2C0 CC1350_LAUNCHXL_433_I2C0 +#define Board_I2C_TMP CC1350_LAUNCHXL_433_I2C0 + +#define Board_PIN_BUTTON0 CC1350_LAUNCHXL_433_PIN_BTN1 +#define Board_PIN_BUTTON1 CC1350_LAUNCHXL_433_PIN_BTN2 +#define Board_PIN_BTN1 CC1350_LAUNCHXL_433_PIN_BTN1 +#define Board_PIN_BTN2 CC1350_LAUNCHXL_433_PIN_BTN2 +#define Board_PIN_LED0 CC1350_LAUNCHXL_433_PIN_RLED +#define Board_PIN_LED1 CC1350_LAUNCHXL_433_PIN_GLED +#define Board_PIN_LED2 CC1350_LAUNCHXL_433_PIN_RLED +#define Board_PIN_RLED CC1350_LAUNCHXL_433_PIN_RLED +#define Board_PIN_GLED CC1350_LAUNCHXL_433_PIN_GLED + +#define Board_PWM0 CC1350_LAUNCHXL_433_PWM0 +#define Board_PWM1 CC1350_LAUNCHXL_433_PWM1 +#define Board_PWM2 CC1350_LAUNCHXL_433_PWM2 +#define Board_PWM3 CC1350_LAUNCHXL_433_PWM3 +#define Board_PWM4 CC1350_LAUNCHXL_433_PWM4 +#define Board_PWM5 CC1350_LAUNCHXL_433_PWM5 +#define Board_PWM6 CC1350_LAUNCHXL_433_PWM6 +#define Board_PWM7 CC1350_LAUNCHXL_433_PWM7 + +#define Board_SD0 CC1350_LAUNCHXL_433_SDSPI0 + +#define Board_SPI0 CC1350_LAUNCHXL_433_SPI0 +#define Board_SPI0_MISO CC1350_LAUNCHXL_433_SPI0_MISO +#define Board_SPI0_MOSI CC1350_LAUNCHXL_433_SPI0_MOSI +#define Board_SPI0_CLK CC1350_LAUNCHXL_433_SPI0_CLK +#define Board_SPI0_CSN CC1350_LAUNCHXL_433_SPI0_CSN +#define Board_SPI1 CC1350_LAUNCHXL_433_SPI1 +#define Board_SPI1_MISO CC1350_LAUNCHXL_433_SPI1_MISO +#define Board_SPI1_MOSI CC1350_LAUNCHXL_433_SPI1_MOSI +#define Board_SPI1_CLK CC1350_LAUNCHXL_433_SPI1_CLK +#define Board_SPI1_CSN CC1350_LAUNCHXL_433_SPI1_CSN +#define Board_SPI_FLASH_CS CC1350_LAUNCHXL_433_SPI_FLASH_CS +#define Board_FLASH_CS_ON (0) +#define Board_FLASH_CS_OFF (1) + +#define Board_SPI_MASTER CC1350_LAUNCHXL_433_SPI0 +#define Board_SPI_SLAVE CC1350_LAUNCHXL_433_SPI0 +#define Board_SPI_MASTER_READY CC1350_LAUNCHXL_433_SPI_MASTER_READY +#define Board_SPI_SLAVE_READY CC1350_LAUNCHXL_433_SPI_SLAVE_READY + +#define Board_UART0 CC1350_LAUNCHXL_433_UART0 + +#define Board_WATCHDOG0 CC1350_LAUNCHXL_433_WATCHDOG0 + +/* Board specific I2C addresses */ +#define Board_TMP_ADDR (0x40) +#define Board_SENSORS_BP_TMP_ADDR Board_TMP_ADDR + +#ifdef __cplusplus +} +#endif + +#endif /* __BOARD_H */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/CC1350_LAUNCHXL_433.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/CC1350_LAUNCHXL_433.c new file mode 100644 index 000000000..b4d34a54b --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/CC1350_LAUNCHXL_433.c @@ -0,0 +1,828 @@ +/* + * Copyright (c) 2017-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +/* + * ============================ CC1350_LAUNCHXL_433.c ============================ + * This file is responsible for setting up the board specific items for the + * CC1350_LAUNCHXL_433 board. + */ + +#include +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/udma.h) +#include DeviceFamily_constructPath(inc/hw_ints.h) +#include DeviceFamily_constructPath(inc/hw_memmap.h) + +#include "CC1350_LAUNCHXL_433.h" + +/* + * =============================== ADCBuf =============================== + */ +#include +#include + +ADCBufCC26XX_Object adcBufCC26XXobjects[CC1350_LAUNCHXL_433_ADCBUFCOUNT]; + +/* + * This table converts a virtual adc channel into a dio and internal analogue + * input signal. This table is necessary for the functioning of the adcBuf + * driver. Comment out unused entries to save flash. Dio and internal signal + * pairs are hardwired. Do not remap them in the table. You may reorder entire + * entries. The mapping of dio and internal signals is package dependent. + */ +const ADCBufCC26XX_AdcChannelLutEntry ADCBufCC26XX_adcChannelLut[CC1350_LAUNCHXL_433_ADCBUF0CHANNELCOUNT] = { + {CC1350_LAUNCHXL_433_DIO23_ANALOG, ADC_COMPB_IN_AUXIO7}, + {CC1350_LAUNCHXL_433_DIO24_ANALOG, ADC_COMPB_IN_AUXIO6}, + {CC1350_LAUNCHXL_433_DIO25_ANALOG, ADC_COMPB_IN_AUXIO5}, + {CC1350_LAUNCHXL_433_DIO26_ANALOG, ADC_COMPB_IN_AUXIO4}, + {CC1350_LAUNCHXL_433_DIO27_ANALOG, ADC_COMPB_IN_AUXIO3}, + {CC1350_LAUNCHXL_433_DIO28_ANALOG, ADC_COMPB_IN_AUXIO2}, + {CC1350_LAUNCHXL_433_DIO29_ANALOG, ADC_COMPB_IN_AUXIO1}, + {CC1350_LAUNCHXL_433_DIO30_ANALOG, ADC_COMPB_IN_AUXIO0}, + {PIN_UNASSIGNED, ADC_COMPB_IN_VDDS}, + {PIN_UNASSIGNED, ADC_COMPB_IN_DCOUPL}, + {PIN_UNASSIGNED, ADC_COMPB_IN_VSS}, +}; + +const ADCBufCC26XX_HWAttrs adcBufCC26XXHWAttrs[CC1350_LAUNCHXL_433_ADCBUFCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + .adcChannelLut = ADCBufCC26XX_adcChannelLut, + .gpTimerUnit = CC1350_LAUNCHXL_433_GPTIMER0A, + .gptDMAChannelMask = 1 << UDMA_CHAN_TIMER0_A, + } +}; + +const ADCBuf_Config ADCBuf_config[CC1350_LAUNCHXL_433_ADCBUFCOUNT] = { + { + &ADCBufCC26XX_fxnTable, + &adcBufCC26XXobjects[CC1350_LAUNCHXL_433_ADCBUF0], + &adcBufCC26XXHWAttrs[CC1350_LAUNCHXL_433_ADCBUF0] + }, +}; + +const uint_least8_t ADCBuf_count = CC1350_LAUNCHXL_433_ADCBUFCOUNT; + +/* + * =============================== ADC =============================== + */ +#include +#include + +ADCCC26XX_Object adcCC26xxObjects[CC1350_LAUNCHXL_433_ADCCOUNT]; + +const ADCCC26XX_HWAttrs adcCC26xxHWAttrs[CC1350_LAUNCHXL_433_ADCCOUNT] = { + { + .adcDIO = CC1350_LAUNCHXL_433_DIO23_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO7, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1350_LAUNCHXL_433_DIO24_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO6, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1350_LAUNCHXL_433_DIO25_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO5, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1350_LAUNCHXL_433_DIO26_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO4, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1350_LAUNCHXL_433_DIO27_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO3, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1350_LAUNCHXL_433_DIO28_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO2, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1350_LAUNCHXL_433_DIO29_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO1, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1350_LAUNCHXL_433_DIO30_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO0, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_10P9_MS, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_DCOUPL, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_VSS, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_VDDS, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + } +}; + +const ADC_Config ADC_config[CC1350_LAUNCHXL_433_ADCCOUNT] = { + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1350_LAUNCHXL_433_ADC0], &adcCC26xxHWAttrs[CC1350_LAUNCHXL_433_ADC0]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1350_LAUNCHXL_433_ADC1], &adcCC26xxHWAttrs[CC1350_LAUNCHXL_433_ADC1]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1350_LAUNCHXL_433_ADC2], &adcCC26xxHWAttrs[CC1350_LAUNCHXL_433_ADC2]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1350_LAUNCHXL_433_ADC3], &adcCC26xxHWAttrs[CC1350_LAUNCHXL_433_ADC3]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1350_LAUNCHXL_433_ADC4], &adcCC26xxHWAttrs[CC1350_LAUNCHXL_433_ADC4]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1350_LAUNCHXL_433_ADC5], &adcCC26xxHWAttrs[CC1350_LAUNCHXL_433_ADC5]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1350_LAUNCHXL_433_ADC6], &adcCC26xxHWAttrs[CC1350_LAUNCHXL_433_ADC6]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1350_LAUNCHXL_433_ADC7], &adcCC26xxHWAttrs[CC1350_LAUNCHXL_433_ADC7]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1350_LAUNCHXL_433_ADCDCOUPL], &adcCC26xxHWAttrs[CC1350_LAUNCHXL_433_ADCDCOUPL]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1350_LAUNCHXL_433_ADCVSS], &adcCC26xxHWAttrs[CC1350_LAUNCHXL_433_ADCVSS]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1350_LAUNCHXL_433_ADCVDDS], &adcCC26xxHWAttrs[CC1350_LAUNCHXL_433_ADCVDDS]}, +}; + +const uint_least8_t ADC_count = CC1350_LAUNCHXL_433_ADCCOUNT; + +/* + * =============================== Crypto =============================== + */ +#include + +CryptoCC26XX_Object cryptoCC26XXObjects[CC1350_LAUNCHXL_433_CRYPTOCOUNT]; + +const CryptoCC26XX_HWAttrs cryptoCC26XXHWAttrs[CC1350_LAUNCHXL_433_CRYPTOCOUNT] = { + { + .baseAddr = CRYPTO_BASE, + .powerMngrId = PowerCC26XX_PERIPH_CRYPTO, + .intNum = INT_CRYPTO_RESULT_AVAIL_IRQ, + .intPriority = ~0, + } +}; + +const CryptoCC26XX_Config CryptoCC26XX_config[CC1350_LAUNCHXL_433_CRYPTOCOUNT] = { + { + .object = &cryptoCC26XXObjects[CC1350_LAUNCHXL_433_CRYPTO0], + .hwAttrs = &cryptoCC26XXHWAttrs[CC1350_LAUNCHXL_433_CRYPTO0] + }, +}; + +/* + * =============================== GPIO =============================== + */ +#include +#include + +/* + * Array of Pin configurations + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC1350_LAUNCHXL_433.h + * NOTE: Pins not used for interrupts should be placed at the end of the + * array. Callback entries can be omitted from callbacks array to + * reduce memory usage. + */ +GPIO_PinConfig gpioPinConfigs[] = { + /* Input pins */ + GPIOCC26XX_DIO_13 | GPIO_DO_NOT_CONFIG, /* Button 0 */ + GPIOCC26XX_DIO_14 | GPIO_DO_NOT_CONFIG, /* Button 1 */ + + GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG, /* CC1350_LAUNCHXL_433_SPI_MASTER_READY */ + GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG, /* CC1350_LAUNCHXL_433_SPI_SLAVE_READY */ + + /* Output pins */ + GPIOCC26XX_DIO_07 | GPIO_DO_NOT_CONFIG, /* Green LED */ + GPIOCC26XX_DIO_06 | GPIO_DO_NOT_CONFIG, /* Red LED */ + + /* SPI Flash CSN */ + GPIOCC26XX_DIO_20 | GPIO_DO_NOT_CONFIG, + + /* SD CS */ + GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG, +}; + +/* + * Array of callback function pointers + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC1350_LAUNCHXL_433.h + * NOTE: Pins not used for interrupts can be omitted from callbacks array to + * reduce memory usage (if placed at end of gpioPinConfigs array). + */ +GPIO_CallbackFxn gpioCallbackFunctions[] = { + NULL, /* Button 0 */ + NULL, /* Button 1 */ + NULL, /* CC1350_LAUNCHXL_433_SPI_MASTER_READY */ + NULL, /* CC1350_LAUNCHXL_433_SPI_SLAVE_READY */ +}; + +const GPIOCC26XX_Config GPIOCC26XX_config = { + .pinConfigs = (GPIO_PinConfig *)gpioPinConfigs, + .callbacks = (GPIO_CallbackFxn *)gpioCallbackFunctions, + .numberOfPinConfigs = sizeof(gpioPinConfigs)/sizeof(GPIO_PinConfig), + .numberOfCallbacks = sizeof(gpioCallbackFunctions)/sizeof(GPIO_CallbackFxn), + .intPriority = (~0) +}; + +/* + * =============================== GPTimer =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include + +GPTimerCC26XX_Object gptimerCC26XXObjects[CC1350_LAUNCHXL_433_GPTIMERCOUNT]; + +const GPTimerCC26XX_HWAttrs gptimerCC26xxHWAttrs[CC1350_LAUNCHXL_433_GPTIMERPARTSCOUNT] = { + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0A, }, + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0B, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1A, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1B, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2A, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2B, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3A, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3B, }, +}; + +const GPTimerCC26XX_Config GPTimerCC26XX_config[CC1350_LAUNCHXL_433_GPTIMERPARTSCOUNT] = { + { &gptimerCC26XXObjects[CC1350_LAUNCHXL_433_GPTIMER0], &gptimerCC26xxHWAttrs[CC1350_LAUNCHXL_433_GPTIMER0A], GPT_A }, + { &gptimerCC26XXObjects[CC1350_LAUNCHXL_433_GPTIMER0], &gptimerCC26xxHWAttrs[CC1350_LAUNCHXL_433_GPTIMER0B], GPT_B }, + { &gptimerCC26XXObjects[CC1350_LAUNCHXL_433_GPTIMER1], &gptimerCC26xxHWAttrs[CC1350_LAUNCHXL_433_GPTIMER1A], GPT_A }, + { &gptimerCC26XXObjects[CC1350_LAUNCHXL_433_GPTIMER1], &gptimerCC26xxHWAttrs[CC1350_LAUNCHXL_433_GPTIMER1B], GPT_B }, + { &gptimerCC26XXObjects[CC1350_LAUNCHXL_433_GPTIMER2], &gptimerCC26xxHWAttrs[CC1350_LAUNCHXL_433_GPTIMER2A], GPT_A }, + { &gptimerCC26XXObjects[CC1350_LAUNCHXL_433_GPTIMER2], &gptimerCC26xxHWAttrs[CC1350_LAUNCHXL_433_GPTIMER2B], GPT_B }, + { &gptimerCC26XXObjects[CC1350_LAUNCHXL_433_GPTIMER3], &gptimerCC26xxHWAttrs[CC1350_LAUNCHXL_433_GPTIMER3A], GPT_A }, + { &gptimerCC26XXObjects[CC1350_LAUNCHXL_433_GPTIMER3], &gptimerCC26xxHWAttrs[CC1350_LAUNCHXL_433_GPTIMER3B], GPT_B }, +}; + +/* + * =============================== I2C =============================== +*/ +#include +#include + +#if TI_I2C_CONF_ENABLE + +I2CCC26XX_Object i2cCC26xxObjects[CC1350_LAUNCHXL_433_I2CCOUNT]; + +const I2CCC26XX_HWAttrsV1 i2cCC26xxHWAttrs[CC1350_LAUNCHXL_433_I2CCOUNT] = { + { + .baseAddr = I2C0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_I2C0, + .intNum = INT_I2C_IRQ, + .intPriority = ~0, + .swiPriority = 0, + .sdaPin = CC1350_LAUNCHXL_433_I2C0_SDA0, + .sclPin = CC1350_LAUNCHXL_433_I2C0_SCL0, + } +}; + +const I2C_Config I2C_config[CC1350_LAUNCHXL_433_I2CCOUNT] = { + { + .fxnTablePtr = &I2CCC26XX_fxnTable, + .object = &i2cCC26xxObjects[CC1350_LAUNCHXL_433_I2C0], + .hwAttrs = &i2cCC26xxHWAttrs[CC1350_LAUNCHXL_433_I2C0] + }, +}; + +const uint_least8_t I2C_count = CC1350_LAUNCHXL_433_I2CCOUNT; + +#endif /* TI_I2C_CONF_ENABLE */ + +/* + * =============================== NVS =============================== + */ +#include +#include +#include + +#define NVS_REGIONS_BASE 0x1A000 +#define SECTORSIZE 0x1000 +#define REGIONSIZE (SECTORSIZE * 4) + +#if TI_NVS_CONF_ENABLE + +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + +/* + * Reserve flash sectors for NVS driver use by placing an uninitialized byte + * array at the desired flash address. + */ +#if defined(__TI_COMPILER_VERSION__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +#pragma LOCATION(flashBuf, NVS_REGIONS_BASE); +#pragma NOINIT(flashBuf); +static char flashBuf[REGIONSIZE]; + +#elif defined(__IAR_SYSTEMS_ICC__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +static __no_init char flashBuf[REGIONSIZE] @ NVS_REGIONS_BASE; + +#elif defined(__GNUC__) + +/* + * Place the flash buffers in the .nvs section created in the gcc linker file. + * The .nvs section enforces alignment on a sector boundary but may + * be placed anywhere in flash memory. If desired the .nvs section can be set + * to a fixed address by changing the following in the gcc linker file: + * + * .nvs (FIXED_FLASH_ADDR) (NOLOAD) : AT (FIXED_FLASH_ADDR) { + * *(.nvs) + * } > REGION_TEXT + */ +__attribute__ ((section (".nvs"))) +static char flashBuf[REGIONSIZE]; + +#endif + +/* Allocate objects for NVS Internal Regions */ +NVSCC26XX_Object nvsCC26xxObjects[1]; + +/* Hardware attributes for NVS Internal Regions */ +const NVSCC26XX_HWAttrs nvsCC26xxHWAttrs[1] = { + { + .regionBase = (void *)flashBuf, + .regionSize = REGIONSIZE, + }, +}; + +#endif /* TI_NVS_CONF_NVS_INTERNAL_ENABLE */ + +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + +#define SPISECTORSIZE 0x1000 +#define SPIREGIONSIZE (SPISECTORSIZE * 32) +#define VERIFYBUFSIZE 64 + +static uint8_t verifyBuf[VERIFYBUFSIZE]; + +/* Allocate objects for NVS External Regions */ +NVSSPI25X_Object nvsSPI25XObjects[1]; + +/* Hardware attributes for NVS External Regions */ +const NVSSPI25X_HWAttrs nvsSPI25XHWAttrs[1] = { + { + .regionBaseOffset = 0, + .regionSize = SPIREGIONSIZE, + .sectorSize = SPISECTORSIZE, + .verifyBuf = verifyBuf, + .verifyBufSize = VERIFYBUFSIZE, + .spiHandle = NULL, + .spiIndex = 0, + .spiBitRate = 4000000, + .spiCsnGpioIndex = CC1350_LAUNCHXL_433_GPIO_SPI_FLASH_CS, + }, +}; + +#endif /* TI_NVS_CONF_NVS_EXTERNAL_ENABLE */ + +/* NVS Region index 0 and 1 refer to NVS and NVS SPI respectively */ +const NVS_Config NVS_config[CC1350_LAUNCHXL_433_NVSCOUNT] = { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + { + .fxnTablePtr = &NVSCC26XX_fxnTable, + .object = &nvsCC26xxObjects[0], + .hwAttrs = &nvsCC26xxHWAttrs[0], + }, +#endif +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + { + .fxnTablePtr = &NVSSPI25X_fxnTable, + .object = &nvsSPI25XObjects[0], + .hwAttrs = &nvsSPI25XHWAttrs[0], + }, +#endif +}; + +const uint_least8_t NVS_count = CC1350_LAUNCHXL_433_NVSCOUNT; + +#endif /* TI_NVS_CONF_ENABLE */ + +/* + * =============================== PIN =============================== + */ +#include +#include + +const PIN_Config BoardGpioInitTable[] = { + + CC1350_LAUNCHXL_433_PIN_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC1350_LAUNCHXL_433_PIN_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC1350_LAUNCHXL_433_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC1350_LAUNCHXL_433_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC1350_LAUNCHXL_433_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ + CC1350_LAUNCHXL_433_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */ + CC1350_LAUNCHXL_433_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */ + CC1350_LAUNCHXL_433_DIO1_RF_SUB1GHZ | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* RF SW Switch defaults to 2.4 GHz path*/ + CC1350_LAUNCHXL_433_DIO30_RF_POWER | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* External RF Switch is powered off by default */ + CC1350_LAUNCHXL_433_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */ + CC1350_LAUNCHXL_433_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */ + CC1350_LAUNCHXL_433_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI clock */ + PIN_TERMINATE +}; + +const PINCC26XX_HWAttrs PINCC26XX_hwAttrs = { + .intPriority = ~0, + .swiPriority = 0 +}; + +/* + * =============================== Power =============================== + */ +#include +#include + +const PowerCC26XX_Config PowerCC26XX_config = { + .policyInitFxn = NULL, + .policyFxn = &PowerCC26XX_standbyPolicy, + .calibrateFxn = &PowerCC26XX_calibrate, + .enablePolicy = true, + .calibrateRCOSC_LF = true, + .calibrateRCOSC_HF = true, +}; + +/* + * =============================== PWM =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include +#include + +PWMTimerCC26XX_Object pwmtimerCC26xxObjects[CC1350_LAUNCHXL_433_PWMCOUNT]; + +const PWMTimerCC26XX_HwAttrs pwmtimerCC26xxHWAttrs[CC1350_LAUNCHXL_433_PWMCOUNT] = { + { .pwmPin = CC1350_LAUNCHXL_433_PWMPIN0, .gpTimerUnit = CC1350_LAUNCHXL_433_GPTIMER0A }, + { .pwmPin = CC1350_LAUNCHXL_433_PWMPIN1, .gpTimerUnit = CC1350_LAUNCHXL_433_GPTIMER0B }, + { .pwmPin = CC1350_LAUNCHXL_433_PWMPIN2, .gpTimerUnit = CC1350_LAUNCHXL_433_GPTIMER1A }, + { .pwmPin = CC1350_LAUNCHXL_433_PWMPIN3, .gpTimerUnit = CC1350_LAUNCHXL_433_GPTIMER1B }, + { .pwmPin = CC1350_LAUNCHXL_433_PWMPIN4, .gpTimerUnit = CC1350_LAUNCHXL_433_GPTIMER2A }, + { .pwmPin = CC1350_LAUNCHXL_433_PWMPIN5, .gpTimerUnit = CC1350_LAUNCHXL_433_GPTIMER2B }, + { .pwmPin = CC1350_LAUNCHXL_433_PWMPIN6, .gpTimerUnit = CC1350_LAUNCHXL_433_GPTIMER3A }, + { .pwmPin = CC1350_LAUNCHXL_433_PWMPIN7, .gpTimerUnit = CC1350_LAUNCHXL_433_GPTIMER3B }, +}; + +const PWM_Config PWM_config[CC1350_LAUNCHXL_433_PWMCOUNT] = { + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350_LAUNCHXL_433_PWM0], &pwmtimerCC26xxHWAttrs[CC1350_LAUNCHXL_433_PWM0] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350_LAUNCHXL_433_PWM1], &pwmtimerCC26xxHWAttrs[CC1350_LAUNCHXL_433_PWM1] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350_LAUNCHXL_433_PWM2], &pwmtimerCC26xxHWAttrs[CC1350_LAUNCHXL_433_PWM2] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350_LAUNCHXL_433_PWM3], &pwmtimerCC26xxHWAttrs[CC1350_LAUNCHXL_433_PWM3] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350_LAUNCHXL_433_PWM4], &pwmtimerCC26xxHWAttrs[CC1350_LAUNCHXL_433_PWM4] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350_LAUNCHXL_433_PWM5], &pwmtimerCC26xxHWAttrs[CC1350_LAUNCHXL_433_PWM5] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350_LAUNCHXL_433_PWM6], &pwmtimerCC26xxHWAttrs[CC1350_LAUNCHXL_433_PWM6] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350_LAUNCHXL_433_PWM7], &pwmtimerCC26xxHWAttrs[CC1350_LAUNCHXL_433_PWM7] }, +}; + +const uint_least8_t PWM_count = CC1350_LAUNCHXL_433_PWMCOUNT; + +/* + * =============================== RF Driver =============================== + */ +#include + +/* + * Board-specific callback function to set the correct antenna path. + * + * This function is called by the RF driver on global driver events. + * It contains a default implementation to set the correct antenna path. + * This function is defined in the file CC1350_LAUNCHXL_433_fxns.c + */ +extern void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg); + +const RFCC26XX_HWAttrsV2 RFCC26XX_hwAttrs = { + .hwiPriority = ~0, /* Lowest HWI priority */ + .swiPriority = 0, /* Lowest SWI priority */ + .xoscHfAlwaysNeeded = true, /* Keep XOSC dependency while in stanby */ + + /* Register the board specific callback */ + .globalCallback = &rfDriverCallback, + /* Subscribe the callback to both events */ + .globalEventMask = RF_GlobalEventRadioSetup | RF_GlobalEventRadioPowerDown +}; + +/* + * =============================== SD =============================== + */ +#include +#include + +#if TI_SD_CONF_ENABLE + +#if !(TI_SPI_CONF_SPI0_ENABLE) +#error "SD driver requires SPI0 enabled" +#endif + +SDSPI_Object sdspiObjects[CC1350_LAUNCHXL_433_SDCOUNT]; + +const SDSPI_HWAttrs sdspiHWAttrs[CC1350_LAUNCHXL_433_SDCOUNT] = { + { + .spiIndex = CC1350_LAUNCHXL_433_SPI0, + .spiCsGpioIndex = CC1350_LAUNCHXL_433_SDSPI_CS + } +}; + +const SD_Config SD_config[CC1350_LAUNCHXL_433_SDCOUNT] = { + { + .fxnTablePtr = &SDSPI_fxnTable, + .object = &sdspiObjects[CC1350_LAUNCHXL_433_SDSPI0], + .hwAttrs = &sdspiHWAttrs[CC1350_LAUNCHXL_433_SDSPI0] + }, +}; + +const uint_least8_t SD_count = CC1350_LAUNCHXL_433_SDCOUNT; + +#endif /* TI_SD_CONF_ENABLE */ + +/* + * =============================== SPI DMA =============================== + */ +#include +#include + +#if TI_SPI_CONF_ENABLE + +SPICC26XXDMA_Object spiCC26XXDMAObjects[CC1350_LAUNCHXL_433_SPICOUNT]; + +/* + * NOTE: The SPI instances below can be used by the SD driver to communicate + * with a SD card via SPI. The 'defaultTxBufValue' fields below are set to 0xFF + * to satisfy the SDSPI driver requirement. + */ +const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[CC1350_LAUNCHXL_433_SPICOUNT] = { +#if TI_SPI_CONF_SPI0_ENABLE + { + .baseAddr = SSI0_BASE, + .intNum = INT_SSI0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .powerMngrId = PowerCC26XX_PERIPH_SSI0, + .defaultTxBufValue = 0xFF, + .rxChannelBitMask = 1< +#include + +TRNGCC26X0_Object trngCC26X0Object[CC1350_LAUNCHXL_433_TRNGCOUNT]; + +const TRNGCC26X0_HWAttrs trngCC26X0HWAttrs[CC1350_LAUNCHXL_433_TRNGCOUNT] = { + { + .swiPriority = 0, + .intPriority = ~0, + } +}; + +const TRNG_Config TRNG_config[] = { + { &trngCC26X0Object[0], &trngCC26X0HWAttrs[0] }, +}; + +const uint8_t TRNG_count = CC1350_LAUNCHXL_433_TRNGCOUNT; + + +/* + * =============================== UART =============================== + */ +#include +#include + +#if TI_UART_CONF_ENABLE + +UARTCC26XX_Object uartCC26XXObjects[CC1350_LAUNCHXL_433_UARTCOUNT]; + +uint8_t uartCC26XXRingBuffer[CC1350_LAUNCHXL_433_UARTCOUNT][32]; + +const UARTCC26XX_HWAttrsV2 uartCC26XXHWAttrs[CC1350_LAUNCHXL_433_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .baseAddr = UART0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UART0, + .intNum = INT_UART0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .txPin = CC1350_LAUNCHXL_433_UART_TX, + .rxPin = CC1350_LAUNCHXL_433_UART_RX, + .ctsPin = PIN_UNASSIGNED, + .rtsPin = PIN_UNASSIGNED, + .ringBufPtr = uartCC26XXRingBuffer[CC1350_LAUNCHXL_433_UART0], + .ringBufSize = sizeof(uartCC26XXRingBuffer[CC1350_LAUNCHXL_433_UART0]), + .txIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_1_8, + .rxIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_4_8, + .errorFxn = NULL + }, +#endif +}; + +const UART_Config UART_config[CC1350_LAUNCHXL_433_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .fxnTablePtr = &UARTCC26XX_fxnTable, + .object = &uartCC26XXObjects[CC1350_LAUNCHXL_433_UART0], + .hwAttrs = &uartCC26XXHWAttrs[CC1350_LAUNCHXL_433_UART0] + }, +#endif +}; + +const uint_least8_t UART_count = CC1350_LAUNCHXL_433_UARTCOUNT; + +#endif /* TI_UART_CONF_ENABLE */ + +/* + * =============================== UDMA =============================== + */ +#include + +UDMACC26XX_Object udmaObjects[CC1350_LAUNCHXL_433_UDMACOUNT]; + +const UDMACC26XX_HWAttrs udmaHWAttrs[CC1350_LAUNCHXL_433_UDMACOUNT] = { + { + .baseAddr = UDMA0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UDMA, + .intNum = INT_DMA_ERR, + .intPriority = ~0 + } +}; + +const UDMACC26XX_Config UDMACC26XX_config[CC1350_LAUNCHXL_433_UDMACOUNT] = { + { + .object = &udmaObjects[CC1350_LAUNCHXL_433_UDMA0], + .hwAttrs = &udmaHWAttrs[CC1350_LAUNCHXL_433_UDMA0] + }, +}; + +/* + * =============================== Watchdog =============================== + */ +#include +#include + +WatchdogCC26XX_Object watchdogCC26XXObjects[CC1350_LAUNCHXL_433_WATCHDOGCOUNT]; + +const WatchdogCC26XX_HWAttrs watchdogCC26XXHWAttrs[CC1350_LAUNCHXL_433_WATCHDOGCOUNT] = { + { + .baseAddr = WDT_BASE, + .reloadValue = 1000 /* Reload value in milliseconds */ + }, +}; + +const Watchdog_Config Watchdog_config[CC1350_LAUNCHXL_433_WATCHDOGCOUNT] = { + { + .fxnTablePtr = &WatchdogCC26XX_fxnTable, + .object = &watchdogCC26XXObjects[CC1350_LAUNCHXL_433_WATCHDOG0], + .hwAttrs = &watchdogCC26XXHWAttrs[CC1350_LAUNCHXL_433_WATCHDOG0] + }, +}; + +const uint_least8_t Watchdog_count = CC1350_LAUNCHXL_433_WATCHDOGCOUNT; + +/* + * Board-specific initialization function to disable external flash. + * This function is defined in the file CC1350_LAUNCHXL_433_fxns.c + */ +extern void Board_initHook(void); + +/* + * ======== CC1350_LAUNCHXL_433_initGeneral ======== + */ +void CC1350_LAUNCHXL_433_initGeneral(void) +{ + Power_init(); + + if (PIN_init(BoardGpioInitTable) != PIN_SUCCESS) { + /* Error with PIN_init */ + while (1); + } + + /* Perform board-specific initialization */ + Board_initHook(); +} diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/CC1350_LAUNCHXL_433.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/CC1350_LAUNCHXL_433.h new file mode 100644 index 000000000..5377700d5 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/CC1350_LAUNCHXL_433.h @@ -0,0 +1,375 @@ +/* + * Copyright (c) 2017-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 CC1350_LAUNCHXL_433.h + * + * @brief CC1350 LaunchPad Board Specific header file. + * + * The CC1350_LAUNCHXL_433 header file should be included in an application as + * follows: + * @code + * #include "CC1350_LAUNCHXL_433.h" + * @endcode + * + * ============================================================================ + */ +#ifndef __CC1350_LAUNCHXL_433_BOARD_H__ +#define __CC1350_LAUNCHXL_433_BOARD_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "contiki-conf.h" + +/* Includes */ +#include +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) + +/* Externs */ +extern const PIN_Config BoardGpioInitTable[]; + +/* Defines */ +#define CC1350_LAUNCHXL_433 + +/* Mapping of pins to board signals using general board aliases + * + */ + +/* Analog Capable DIOs */ +#define CC1350_LAUNCHXL_433_DIO23_ANALOG IOID_23 +#define CC1350_LAUNCHXL_433_DIO24_ANALOG IOID_24 +#define CC1350_LAUNCHXL_433_DIO25_ANALOG IOID_25 +#define CC1350_LAUNCHXL_433_DIO26_ANALOG IOID_26 +#define CC1350_LAUNCHXL_433_DIO27_ANALOG IOID_27 +#define CC1350_LAUNCHXL_433_DIO28_ANALOG IOID_28 +#define CC1350_LAUNCHXL_433_DIO29_ANALOG IOID_29 +#define CC1350_LAUNCHXL_433_DIO30_ANALOG IOID_30 + +/* Digital IOs */ +#define CC1350_LAUNCHXL_433_DIO0 IOID_0 +#define CC1350_LAUNCHXL_433_DIO1_RF_SUB1GHZ IOID_1 +#define CC1350_LAUNCHXL_433_DIO12 IOID_12 +#define CC1350_LAUNCHXL_433_DIO15 IOID_15 +#define CC1350_LAUNCHXL_433_DIO16_TDO IOID_16 +#define CC1350_LAUNCHXL_433_DIO17_TDI IOID_17 +#define CC1350_LAUNCHXL_433_DIO21 IOID_21 +#define CC1350_LAUNCHXL_433_DIO22 IOID_22 +#define CC1350_LAUNCHXL_433_DIO30_RF_POWER IOID_30 + +/* Discrete Inputs */ +#define CC1350_LAUNCHXL_433_PIN_BTN1 IOID_13 +#define CC1350_LAUNCHXL_433_PIN_BTN2 IOID_14 + + +/* GPIO */ +#define CC1350_LAUNCHXL_433_GPIO_LED_ON 1 +#define CC1350_LAUNCHXL_433_GPIO_LED_OFF 0 + +/* I2C */ +#define CC1350_LAUNCHXL_433_I2C0_SCL0 IOID_4 +#define CC1350_LAUNCHXL_433_I2C0_SDA0 IOID_5 + + +/* LEDs */ +#define CC1350_LAUNCHXL_433_PIN_LED_ON 1 +#define CC1350_LAUNCHXL_433_PIN_LED_OFF 0 +#define CC1350_LAUNCHXL_433_PIN_RLED IOID_6 +#define CC1350_LAUNCHXL_433_PIN_GLED IOID_7 + +/* PWM Outputs */ +#define CC1350_LAUNCHXL_433_PWMPIN0 CC1350_LAUNCHXL_433_PIN_RLED +#define CC1350_LAUNCHXL_433_PWMPIN1 CC1350_LAUNCHXL_433_PIN_GLED +#define CC1350_LAUNCHXL_433_PWMPIN2 PIN_UNASSIGNED +#define CC1350_LAUNCHXL_433_PWMPIN3 PIN_UNASSIGNED +#define CC1350_LAUNCHXL_433_PWMPIN4 PIN_UNASSIGNED +#define CC1350_LAUNCHXL_433_PWMPIN5 PIN_UNASSIGNED +#define CC1350_LAUNCHXL_433_PWMPIN6 PIN_UNASSIGNED +#define CC1350_LAUNCHXL_433_PWMPIN7 PIN_UNASSIGNED + +/* SPI */ +#define CC1350_LAUNCHXL_433_SPI_FLASH_CS IOID_20 +#define CC1350_LAUNCHXL_433_FLASH_CS_ON 0 +#define CC1350_LAUNCHXL_433_FLASH_CS_OFF 1 + +/* SPI Board */ +#define CC1350_LAUNCHXL_433_SPI0_MISO IOID_8 /* RF1.20 */ +#define CC1350_LAUNCHXL_433_SPI0_MOSI IOID_9 /* RF1.18 */ +#define CC1350_LAUNCHXL_433_SPI0_CLK IOID_10 /* RF1.16 */ +#define CC1350_LAUNCHXL_433_SPI0_CSN PIN_UNASSIGNED +#define CC1350_LAUNCHXL_433_SPI1_MISO PIN_UNASSIGNED +#define CC1350_LAUNCHXL_433_SPI1_MOSI PIN_UNASSIGNED +#define CC1350_LAUNCHXL_433_SPI1_CLK PIN_UNASSIGNED +#define CC1350_LAUNCHXL_433_SPI1_CSN PIN_UNASSIGNED + +/* UART Board */ +#define CC1350_LAUNCHXL_433_UART_RX IOID_2 /* RXD */ +#define CC1350_LAUNCHXL_433_UART_TX IOID_3 /* TXD */ +#define CC1350_LAUNCHXL_433_UART_CTS IOID_19 /* CTS */ +#define CC1350_LAUNCHXL_433_UART_RTS IOID_18 /* RTS */ + +/*! + * @brief Initialize the general board specific settings + * + * This function initializes the general board specific settings. + */ +void CC1350_LAUNCHXL_433_initGeneral(void); + +/*! + * @brief Turn off the external flash on LaunchPads + * + */ +void CC1350_LAUNCHXL_433_shutDownExtFlash(void); + +/*! + * @brief Wake up the external flash present on the board files + * + * This function toggles the chip select for the amount of time needed + * to wake the chip up. + */ +void CC1350_LAUNCHXL_433_wakeUpExtFlash(void); + +/*! + * @def CC1350_LAUNCHXL_433_ADCBufName + * @brief Enum of ADCBufs + */ +typedef enum CC1350_LAUNCHXL_433_ADCBufName { + CC1350_LAUNCHXL_433_ADCBUF0 = 0, + + CC1350_LAUNCHXL_433_ADCBUFCOUNT +} CC1350_LAUNCHXL_433_ADCBufName; + +/*! + * @def CC1350_LAUNCHXL_433_ADCBuf0ChannelName + * @brief Enum of ADCBuf channels + */ +typedef enum CC1350_LAUNCHXL_433_ADCBuf0ChannelName { + CC1350_LAUNCHXL_433_ADCBUF0CHANNEL0 = 0, + CC1350_LAUNCHXL_433_ADCBUF0CHANNEL1, + CC1350_LAUNCHXL_433_ADCBUF0CHANNEL2, + CC1350_LAUNCHXL_433_ADCBUF0CHANNEL3, + CC1350_LAUNCHXL_433_ADCBUF0CHANNEL4, + CC1350_LAUNCHXL_433_ADCBUF0CHANNEL5, + CC1350_LAUNCHXL_433_ADCBUF0CHANNEL6, + CC1350_LAUNCHXL_433_ADCBUF0CHANNEL7, + CC1350_LAUNCHXL_433_ADCBUF0CHANNELVDDS, + CC1350_LAUNCHXL_433_ADCBUF0CHANNELDCOUPL, + CC1350_LAUNCHXL_433_ADCBUF0CHANNELVSS, + + CC1350_LAUNCHXL_433_ADCBUF0CHANNELCOUNT +} CC1350_LAUNCHXL_433_ADCBuf0ChannelName; + +/*! + * @def CC1350_LAUNCHXL_433_ADCName + * @brief Enum of ADCs + */ +typedef enum CC1350_LAUNCHXL_433_ADCName { + CC1350_LAUNCHXL_433_ADC0 = 0, + CC1350_LAUNCHXL_433_ADC1, + CC1350_LAUNCHXL_433_ADC2, + CC1350_LAUNCHXL_433_ADC3, + CC1350_LAUNCHXL_433_ADC4, + CC1350_LAUNCHXL_433_ADC5, + CC1350_LAUNCHXL_433_ADC6, + CC1350_LAUNCHXL_433_ADC7, + CC1350_LAUNCHXL_433_ADCDCOUPL, + CC1350_LAUNCHXL_433_ADCVSS, + CC1350_LAUNCHXL_433_ADCVDDS, + + CC1350_LAUNCHXL_433_ADCCOUNT +} CC1350_LAUNCHXL_433_ADCName; + +/*! + * @def CC1350_LAUNCHXL_433_CryptoName + * @brief Enum of Crypto names + */ +typedef enum CC1350_LAUNCHXL_433_CryptoName { + CC1350_LAUNCHXL_433_CRYPTO0 = 0, + + CC1350_LAUNCHXL_433_CRYPTOCOUNT +} CC1350_LAUNCHXL_433_CryptoName; + +/*! + * @def CC1350_LAUNCHXL_433_GPIOName + * @brief Enum of GPIO names + */ +typedef enum CC1350_LAUNCHXL_433_GPIOName { + CC1350_LAUNCHXL_433_GPIO_S1 = 0, + CC1350_LAUNCHXL_433_GPIO_S2, + CC1350_LAUNCHXL_433_SPI_MASTER_READY, + CC1350_LAUNCHXL_433_SPI_SLAVE_READY, + CC1350_LAUNCHXL_433_GPIO_LED_GREEN, + CC1350_LAUNCHXL_433_GPIO_LED_RED, + CC1350_LAUNCHXL_433_GPIO_SPI_FLASH_CS, + CC1350_LAUNCHXL_433_SDSPI_CS, + CC1350_LAUNCHXL_433_GPIOCOUNT +} CC1350_LAUNCHXL_433_GPIOName; + +/*! + * @def CC1350_LAUNCHXL_433_GPTimerName + * @brief Enum of GPTimer parts + */ +typedef enum CC1350_LAUNCHXL_433_GPTimerName { + CC1350_LAUNCHXL_433_GPTIMER0A = 0, + CC1350_LAUNCHXL_433_GPTIMER0B, + CC1350_LAUNCHXL_433_GPTIMER1A, + CC1350_LAUNCHXL_433_GPTIMER1B, + CC1350_LAUNCHXL_433_GPTIMER2A, + CC1350_LAUNCHXL_433_GPTIMER2B, + CC1350_LAUNCHXL_433_GPTIMER3A, + CC1350_LAUNCHXL_433_GPTIMER3B, + + CC1350_LAUNCHXL_433_GPTIMERPARTSCOUNT +} CC1350_LAUNCHXL_433_GPTimerName; + +/*! + * @def CC1350_LAUNCHXL_433_GPTimers + * @brief Enum of GPTimers + */ +typedef enum CC1350_LAUNCHXL_433_GPTimers { + CC1350_LAUNCHXL_433_GPTIMER0 = 0, + CC1350_LAUNCHXL_433_GPTIMER1, + CC1350_LAUNCHXL_433_GPTIMER2, + CC1350_LAUNCHXL_433_GPTIMER3, + + CC1350_LAUNCHXL_433_GPTIMERCOUNT +} CC1350_LAUNCHXL_433_GPTimers; + +/*! + * @def CC1350_LAUNCHXL_433_I2CName + * @brief Enum of I2C names + */ +typedef enum CC1350_LAUNCHXL_433_I2CName { + CC1350_LAUNCHXL_433_I2C0 = 0, + + CC1350_LAUNCHXL_433_I2CCOUNT +} CC1350_LAUNCHXL_433_I2CName; + +/*! + * @def CC1350_LAUNCHXL_433_NVSName + * @brief Enum of NVS names + */ +typedef enum CC1350_LAUNCHXL_433_NVSName { +#ifndef Board_EXCLUDE_NVS_INTERNAL_FLASH + CC1350_LAUNCHXL_433_NVSCC26XX0 = 0, +#endif +#ifndef Board_EXCLUDE_NVS_EXTERNAL_FLASH + CC1350_LAUNCHXL_433_NVSSPI25X0, +#endif + + CC1350_LAUNCHXL_433_NVSCOUNT +} CC1350_LAUNCHXL_433_NVSName; + +/*! + * @def CC1350_LAUNCHXL_433_PWMName + * @brief Enum of PWM outputs + */ +typedef enum CC1350_LAUNCHXL_433_PWMName { + CC1350_LAUNCHXL_433_PWM0 = 0, + CC1350_LAUNCHXL_433_PWM1, + CC1350_LAUNCHXL_433_PWM2, + CC1350_LAUNCHXL_433_PWM3, + CC1350_LAUNCHXL_433_PWM4, + CC1350_LAUNCHXL_433_PWM5, + CC1350_LAUNCHXL_433_PWM6, + CC1350_LAUNCHXL_433_PWM7, + + CC1350_LAUNCHXL_433_PWMCOUNT +} CC1350_LAUNCHXL_433_PWMName; + +/*! + * @def CC1350_LAUNCHXL_433_SDName + * @brief Enum of SD names + */ +typedef enum CC1350_LAUNCHXL_433_SDName { + CC1350_LAUNCHXL_433_SDSPI0 = 0, + + CC1350_LAUNCHXL_433_SDCOUNT +} CC1350_LAUNCHXL_433_SDName; + +/*! + * @def CC1350_LAUNCHXL_433_SPIName + * @brief Enum of SPI names + */ +typedef enum CC1350_LAUNCHXL_433_SPIName { + CC1350_LAUNCHXL_433_SPI0 = 0, + CC1350_LAUNCHXL_433_SPI1, + + CC1350_LAUNCHXL_433_SPICOUNT +} CC1350_LAUNCHXL_433_SPIName; + +/*! + * @def CC1350_LAUNCHXL_433_TRNGName + * @brief Enum of TRNGs + */ +typedef enum CC1350_LAUNCHXL_433_TRNGName { + CC1350_LAUNCHXL_433_TRNG0 = 0, + + CC1350_LAUNCHXL_433_TRNGCOUNT +} CC1350_LAUNCHXL_433_TRNGName; + +/*! + * @def CC1350_LAUNCHXL_433_UARTName + * @brief Enum of UARTs + */ +typedef enum CC1350_LAUNCHXL_433_UARTName { + CC1350_LAUNCHXL_433_UART0 = 0, + + CC1350_LAUNCHXL_433_UARTCOUNT +} CC1350_LAUNCHXL_433_UARTName; + +/*! + * @def CC1350_LAUNCHXL_433_UDMAName + * @brief Enum of DMA buffers + */ +typedef enum CC1350_LAUNCHXL_433_UDMAName { + CC1350_LAUNCHXL_433_UDMA0 = 0, + + CC1350_LAUNCHXL_433_UDMACOUNT +} CC1350_LAUNCHXL_433_UDMAName; + +/*! + * @def CC1350_LAUNCHXL_433_WatchdogName + * @brief Enum of Watchdogs + */ +typedef enum CC1350_LAUNCHXL_433_WatchdogName { + CC1350_LAUNCHXL_433_WATCHDOG0 = 0, + + CC1350_LAUNCHXL_433_WATCHDOGCOUNT +} CC1350_LAUNCHXL_433_WatchdogName; + +#ifdef __cplusplus +} +#endif + +#endif /* __CC1350_LAUNCHXL_433_BOARD_H__ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/CC1350_LAUNCHXL_433_fxns.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/CC1350_LAUNCHXL_433_fxns.c new file mode 100644 index 000000000..a8a6b16c0 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/CC1350_LAUNCHXL_433_fxns.c @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ +/* + * ======== CC1350_LAUNCHXL_433_fxns.c ======== + * This file contains the board-specific initialization functions, and + * RF callback function for antenna switching. + */ +#include +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/cpu.h) + +#include +#include + +#include "Board.h" + + +/* + * ======== CC1350_LAUNCHXL_433_sendExtFlashByte ======== + */ +void CC1350_LAUNCHXL_433_sendExtFlashByte(PIN_Handle pinHandle, uint8_t byte) +{ + uint8_t i; + + /* SPI Flash CS */ + PIN_setOutputValue(pinHandle, IOID_20, 0); + + for (i = 0; i < 8; i++) { + PIN_setOutputValue(pinHandle, IOID_10, 0); /* SPI Flash CLK */ + + /* SPI Flash MOSI */ + PIN_setOutputValue(pinHandle, IOID_9, (byte >> (7 - i)) & 0x01); + PIN_setOutputValue(pinHandle, IOID_10, 1); /* SPI Flash CLK */ + + /* + * Waste a few cycles to keep the CLK high for at + * least 45% of the period. + * 3 cycles per loop: 8 loops @ 48 Mhz = 0.5 us. + */ + CPUdelay(8); + } + + PIN_setOutputValue(pinHandle, IOID_10, 0); /* CLK */ + PIN_setOutputValue(pinHandle, IOID_20, 1); /* CS */ + + /* + * Keep CS high at least 40 us + * 3 cycles per loop: 700 loops @ 48 Mhz ~= 44 us + */ + CPUdelay(700); +} + +/* + * ======== CC1350_LAUNCHXL_433_wakeUpExtFlash ======== + */ +void CC1350_LAUNCHXL_433_wakeUpExtFlash(void) +{ + PIN_Config extFlashPinTable[] = { + /* SPI Flash CS */ + IOID_20 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + PIN_TERMINATE + }; + PIN_State extFlashPinState; + PIN_Handle extFlashPinHandle = PIN_open(&extFlashPinState, extFlashPinTable); + + /* + * To wake up we need to toggle the chip select at + * least 20 ns and ten wait at least 35 us. + */ + + /* Toggle chip select for ~20ns to wake ext. flash */ + PIN_setOutputValue(extFlashPinHandle, IOID_20, 0); + /* 3 cycles per loop: 1 loop @ 48 Mhz ~= 62 ns */ + CPUdelay(1); + PIN_setOutputValue(extFlashPinHandle, IOID_20, 1); + /* 3 cycles per loop: 560 loops @ 48 Mhz ~= 35 us */ + CPUdelay(560); + + PIN_close(extFlashPinHandle); +} + +/* + * ======== CC1350_LAUNCHXL_433_shutDownExtFlash ======== + */ +void CC1350_LAUNCHXL_433_shutDownExtFlash(void) +{ + /* + * To be sure we are putting the flash into sleep and not waking it, + * we first have to make a wake up call + */ + CC1350_LAUNCHXL_433_wakeUpExtFlash(); + + PIN_Config extFlashPinTable[] = { + /* SPI Flash CS*/ + IOID_20 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash CLK */ + IOID_10 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash MOSI */ + IOID_9 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash MISO */ + IOID_8 | PIN_INPUT_EN | PIN_PULLDOWN, + PIN_TERMINATE + }; + PIN_State extFlashPinState; + PIN_Handle extFlashPinHandle = PIN_open(&extFlashPinState, extFlashPinTable); + + uint8_t extFlashShutdown = 0xB9; + + CC1350_LAUNCHXL_433_sendExtFlashByte(extFlashPinHandle, extFlashShutdown); + + PIN_close(extFlashPinHandle); +} + +/* + * ======== Board_initHook ======== + * Called by Board_init() to perform board-specific initialization. + */ +void Board_initHook() +{ + CC1350_LAUNCHXL_433_shutDownExtFlash(); +} + +/* + * For the SysConfig generated Board.h file, Board_RF_SUB1GHZ will not be + * defined unless the RF module is added to the configuration. Therefore, + * we don't include this code if Board_RF_SUB1GHZ is not defined. + */ +#if defined(Board_RF_SUB1GHZ) + +/* + * ======== CC1350_LAUNCHXL_433_rfDriverCallback ======== + * This is an implementation for the CC1350 launchpad which uses a + * single signal for antenna switching. + */ +void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg) +{ + (void)client; + RF_RadioSetup* setupCommand = (RF_RadioSetup*)arg; + + if (events & RF_GlobalEventRadioSetup) { + /* Power up the antenna switch */ + PINCC26XX_setOutputValue(Board_RF_POWER, 1); + + if (setupCommand->common.commandNo == CMD_PROP_RADIO_DIV_SETUP) { + /* Sub-1 GHz, requires antenna switch high */ + PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 1); + } + } + else if (events & RF_GlobalEventRadioPowerDown) { + /* Disable antenna switch to save current */ + PINCC26XX_setOutputValue(Board_RF_POWER, 0); + PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 0); + } +} +#endif diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/Makefile.cc1350-4 b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/Makefile.cc1350-4 new file mode 100644 index 000000000..8ea92347b --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/Makefile.cc1350-4 @@ -0,0 +1,21 @@ +################################################################################ +# SimpleLink Device makefile + +SUBFAMILY = cc13x0-cc26x0 +DEVICE_FAMILY = CC13X0 +DEVICE_LINE = CC13XX +DEVICE = CC1350_4 + +BOARD_SOURCEFILES += CC1350_LAUNCHXL_433.c CC1350_LAUNCHXL_433_fxns.c + +SUPPORTS_PROP_MODE = 1 +SUPPORTS_IEEE_MODE = 1 +SUPPORTS_BLE_BEACON = 1 + +SUPPORTS_HIGH_PA = 0 + +### Signal that we can be programmed with cc2538-bsl +BOARD_SUPPORTS_BSL = 1 + +# Include the common board makefile +include $(FAMILY_PATH)/launchpad/Makefile.launchpad diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/Board.h new file mode 100644 index 000000000..2099b1845 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/Board.h @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2015-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 __BOARD_H +#define __BOARD_H + +#define Board_CC1350_LAUNCHXL +#define BOARD_STRING "TI CC1350 LaunchPad" + +#ifdef __cplusplus +extern "C" { +#endif + +#include "CC1350_LAUNCHXL.h" + +#define Board_initGeneral() CC1350_LAUNCHXL_initGeneral() +#define Board_shutDownExtFlash() CC1350_LAUNCHXL_shutDownExtFlash() +#define Board_wakeUpExtFlash() CC1350_LAUNCHXL_wakeUpExtFlash() + +/* These #defines allow us to reuse TI-RTOS across other device families */ + +#define Board_ADC0 CC1350_LAUNCHXL_ADC0 +#define Board_ADC1 CC1350_LAUNCHXL_ADC1 + +#define Board_ADCBUF0 CC1350_LAUNCHXL_ADCBUF0 +#define Board_ADCBUF0CHANNEL0 CC1350_LAUNCHXL_ADCBUF0CHANNEL0 +#define Board_ADCBUF0CHANNEL1 CC1350_LAUNCHXL_ADCBUF0CHANNEL1 + +#define Board_CRYPTO0 CC1350_LAUNCHXL_CRYPTO0 + +#define Board_DIO0 CC1350_LAUNCHXL_DIO0 +#define Board_DIO1_RFSW CC1350_LAUNCHXL_DIO1_RF_SUB1GHZ +#define Board_DIO12 CC1350_LAUNCHXL_DIO12 +#define Board_DIO15 CC1350_LAUNCHXL_DIO15 +#define Board_DIO16_TDO CC1350_LAUNCHXL_DIO16_TDO +#define Board_DIO17_TDI CC1350_LAUNCHXL_DIO17_TDI +#define Board_DIO21 CC1350_LAUNCHXL_DIO21 +#define Board_DIO22 CC1350_LAUNCHXL_DIO22 +#define Board_DIO30_SWPWR CC1350_LAUNCHXL_DIO30_RF_POWER + +#define Board_DIO23_ANALOG CC1350_LAUNCHXL_DIO23_ANALOG +#define Board_DIO24_ANALOG CC1350_LAUNCHXL_DIO24_ANALOG +#define Board_DIO25_ANALOG CC1350_LAUNCHXL_DIO25_ANALOG +#define Board_DIO26_ANALOG CC1350_LAUNCHXL_DIO26_ANALOG +#define Board_DIO27_ANALOG CC1350_LAUNCHXL_DIO27_ANALOG +#define Board_DIO28_ANALOG CC1350_LAUNCHXL_DIO28_ANALOG +#define Board_DIO29_ANALOG CC1350_LAUNCHXL_DIO29_ANALOG +#define Board_DIO30_ANALOG CC1350_LAUNCHXL_DIO30_ANALOG + +/* + * Board_RF_SUB1GHZ and Board_RF_POWER are the names generated by SysConfig. + * Define them here so that RF callback function can reference them. + */ +#define Board_RF_SUB1GHZ CC1350_LAUNCHXL_DIO1_RF_SUB1GHZ +#define Board_RF_POWER CC1350_LAUNCHXL_DIO30_RF_POWER + +#define Board_GPIO_BUTTON0 CC1350_LAUNCHXL_GPIO_S1 +#define Board_GPIO_BUTTON1 CC1350_LAUNCHXL_GPIO_S2 +#define Board_GPIO_BTN1 CC1350_LAUNCHXL_GPIO_S1 +#define Board_GPIO_BTN2 CC1350_LAUNCHXL_GPIO_S2 +#define Board_GPIO_LED0 CC1350_LAUNCHXL_GPIO_LED_RED +#define Board_GPIO_LED1 CC1350_LAUNCHXL_GPIO_LED_GREEN +#define Board_GPIO_RLED CC1350_LAUNCHXL_GPIO_LED_RED +#define Board_GPIO_GLED CC1350_LAUNCHXL_GPIO_LED_GREEN +#define Board_GPIO_LED_ON CC1350_LAUNCHXL_GPIO_LED_ON +#define Board_GPIO_LED_OFF CC1350_LAUNCHXL_GPIO_LED_OFF + +#define Board_GPTIMER0A CC1350_LAUNCHXL_GPTIMER0A +#define Board_GPTIMER0B CC1350_LAUNCHXL_GPTIMER0B +#define Board_GPTIMER1A CC1350_LAUNCHXL_GPTIMER1A +#define Board_GPTIMER1B CC1350_LAUNCHXL_GPTIMER1B +#define Board_GPTIMER2A CC1350_LAUNCHXL_GPTIMER2A +#define Board_GPTIMER2B CC1350_LAUNCHXL_GPTIMER2B +#define Board_GPTIMER3A CC1350_LAUNCHXL_GPTIMER3A +#define Board_GPTIMER3B CC1350_LAUNCHXL_GPTIMER3B + +#define Board_NVSINTERNAL CC1350_LAUNCHXL_NVSCC26XX0 +#define Board_NVSEXTERNAL CC1350_LAUNCHXL_NVSSPI25X0 + +#define Board_I2C0 CC1350_LAUNCHXL_I2C0 +#define Board_I2C_TMP CC1350_LAUNCHXL_I2C0 + +#define Board_PIN_BUTTON0 CC1350_LAUNCHXL_PIN_BTN1 +#define Board_PIN_BUTTON1 CC1350_LAUNCHXL_PIN_BTN2 +#define Board_PIN_BTN1 CC1350_LAUNCHXL_PIN_BTN1 +#define Board_PIN_BTN2 CC1350_LAUNCHXL_PIN_BTN2 +#define Board_PIN_LED0 CC1350_LAUNCHXL_PIN_RLED +#define Board_PIN_LED1 CC1350_LAUNCHXL_PIN_GLED +#define Board_PIN_LED2 CC1350_LAUNCHXL_PIN_RLED +#define Board_PIN_RLED CC1350_LAUNCHXL_PIN_RLED +#define Board_PIN_GLED CC1350_LAUNCHXL_PIN_GLED + +#define Board_PWM0 CC1350_LAUNCHXL_PWM0 +#define Board_PWM1 CC1350_LAUNCHXL_PWM1 +#define Board_PWM2 CC1350_LAUNCHXL_PWM2 +#define Board_PWM3 CC1350_LAUNCHXL_PWM3 +#define Board_PWM4 CC1350_LAUNCHXL_PWM4 +#define Board_PWM5 CC1350_LAUNCHXL_PWM5 +#define Board_PWM6 CC1350_LAUNCHXL_PWM6 +#define Board_PWM7 CC1350_LAUNCHXL_PWM7 + +#define Board_SD0 CC1350_LAUNCHXL_SDSPI0 + +#define Board_SPI0 CC1350_LAUNCHXL_SPI0 +#define Board_SPI0_MISO CC1350_LAUNCHXL_SPI0_MISO +#define Board_SPI0_MOSI CC1350_LAUNCHXL_SPI0_MOSI +#define Board_SPI0_CLK CC1350_LAUNCHXL_SPI0_CLK +#define Board_SPI0_CSN CC1350_LAUNCHXL_SPI0_CSN +#define Board_SPI1 CC1350_LAUNCHXL_SPI1 +#define Board_SPI1_MISO CC1350_LAUNCHXL_SPI1_MISO +#define Board_SPI1_MOSI CC1350_LAUNCHXL_SPI1_MOSI +#define Board_SPI1_CLK CC1350_LAUNCHXL_SPI1_CLK +#define Board_SPI1_CSN CC1350_LAUNCHXL_SPI1_CSN +#define Board_SPI_FLASH_CS CC1350_LAUNCHXL_SPI_FLASH_CS +#define Board_FLASH_CS_ON (0) +#define Board_FLASH_CS_OFF (1) + +#define Board_SPI_MASTER CC1350_LAUNCHXL_SPI0 +#define Board_SPI_SLAVE CC1350_LAUNCHXL_SPI0 +#define Board_SPI_MASTER_READY CC1350_LAUNCHXL_SPI_MASTER_READY +#define Board_SPI_SLAVE_READY CC1350_LAUNCHXL_SPI_SLAVE_READY + +#define Board_UART0 CC1350_LAUNCHXL_UART0 + +#define Board_WATCHDOG0 CC1350_LAUNCHXL_WATCHDOG0 + +/* Board specific I2C addresses */ +#define Board_TMP_ADDR (0x40) +#define Board_SENSORS_BP_TMP_ADDR Board_TMP_ADDR + +#ifdef __cplusplus +} +#endif + +#endif /* __BOARD_H */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/CC1350_LAUNCHXL.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/CC1350_LAUNCHXL.c new file mode 100644 index 000000000..1277fc66a --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/CC1350_LAUNCHXL.c @@ -0,0 +1,833 @@ +/* + * Copyright (c) 2015-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +/* + * ============================ CC1350_LAUNCHXL.c ============================ + * This file is responsible for setting up the board specific items for the + * CC1350_LAUNCHXL board. + */ + +#include +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/udma.h) +#include DeviceFamily_constructPath(inc/hw_ints.h) +#include DeviceFamily_constructPath(inc/hw_memmap.h) + +#include "CC1350_LAUNCHXL.h" + +/* + * =============================== ADCBuf =============================== + */ +#include +#include + +static ADCBufCC26XX_Object adcBufCC26XXobjects[CC1350_LAUNCHXL_ADCBUFCOUNT]; + +/* + * This table converts a virtual adc channel into a dio and internal analogue + * input signal. This table is necessary for the functioning of the adcBuf + * driver. Comment out unused entries to save flash. Dio and internal signal + * pairs are hardwired. Do not remap them in the table. You may reorder entire + * entries. The mapping of dio and internal signals is package dependent. + */ +const ADCBufCC26XX_AdcChannelLutEntry ADCBufCC26XX_adcChannelLut[CC1350_LAUNCHXL_ADCBUF0CHANNELCOUNT] = { + {CC1350_LAUNCHXL_DIO23_ANALOG, ADC_COMPB_IN_AUXIO7}, + {CC1350_LAUNCHXL_DIO24_ANALOG, ADC_COMPB_IN_AUXIO6}, + {CC1350_LAUNCHXL_DIO25_ANALOG, ADC_COMPB_IN_AUXIO5}, + {CC1350_LAUNCHXL_DIO26_ANALOG, ADC_COMPB_IN_AUXIO4}, + {CC1350_LAUNCHXL_DIO27_ANALOG, ADC_COMPB_IN_AUXIO3}, + {CC1350_LAUNCHXL_DIO28_ANALOG, ADC_COMPB_IN_AUXIO2}, + {CC1350_LAUNCHXL_DIO29_ANALOG, ADC_COMPB_IN_AUXIO1}, + {CC1350_LAUNCHXL_DIO30_ANALOG, ADC_COMPB_IN_AUXIO0}, + {PIN_UNASSIGNED, ADC_COMPB_IN_VDDS}, + {PIN_UNASSIGNED, ADC_COMPB_IN_DCOUPL}, + {PIN_UNASSIGNED, ADC_COMPB_IN_VSS}, +}; + +const ADCBufCC26XX_HWAttrs adcBufCC26XXHWAttrs[CC1350_LAUNCHXL_ADCBUFCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + .adcChannelLut = ADCBufCC26XX_adcChannelLut, + .gpTimerUnit = CC1350_LAUNCHXL_GPTIMER0A, + .gptDMAChannelMask = 1 << UDMA_CHAN_TIMER0_A, + } +}; + +const ADCBuf_Config ADCBuf_config[CC1350_LAUNCHXL_ADCBUFCOUNT] = { + { + &ADCBufCC26XX_fxnTable, + &adcBufCC26XXobjects[CC1350_LAUNCHXL_ADCBUF0], + //NULL, + &adcBufCC26XXHWAttrs[CC1350_LAUNCHXL_ADCBUF0] + }, +}; + +const uint_least8_t ADCBuf_count = CC1350_LAUNCHXL_ADCBUFCOUNT; + +/* + * =============================== ADC =============================== + */ +#include +#include + +static ADCCC26XX_Object adcCC26xxObjects[CC1350_LAUNCHXL_ADCCOUNT]; + +const ADCCC26XX_HWAttrs adcCC26xxHWAttrs[CC1350_LAUNCHXL_ADCCOUNT] = { + { + .adcDIO = CC1350_LAUNCHXL_DIO23_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO7, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1350_LAUNCHXL_DIO24_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO6, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1350_LAUNCHXL_DIO25_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO5, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1350_LAUNCHXL_DIO26_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO4, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1350_LAUNCHXL_DIO27_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO3, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1350_LAUNCHXL_DIO28_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO2, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1350_LAUNCHXL_DIO29_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO1, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1350_LAUNCHXL_DIO30_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO0, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_10P9_MS, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_DCOUPL, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_VSS, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_VDDS, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + } +}; + +const ADC_Config ADC_config[CC1350_LAUNCHXL_ADCCOUNT] = { + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1350_LAUNCHXL_ADC0], &adcCC26xxHWAttrs[CC1350_LAUNCHXL_ADC0]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1350_LAUNCHXL_ADC1], &adcCC26xxHWAttrs[CC1350_LAUNCHXL_ADC1]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1350_LAUNCHXL_ADC2], &adcCC26xxHWAttrs[CC1350_LAUNCHXL_ADC2]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1350_LAUNCHXL_ADC3], &adcCC26xxHWAttrs[CC1350_LAUNCHXL_ADC3]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1350_LAUNCHXL_ADC4], &adcCC26xxHWAttrs[CC1350_LAUNCHXL_ADC4]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1350_LAUNCHXL_ADC5], &adcCC26xxHWAttrs[CC1350_LAUNCHXL_ADC5]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1350_LAUNCHXL_ADC6], &adcCC26xxHWAttrs[CC1350_LAUNCHXL_ADC6]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1350_LAUNCHXL_ADC7], &adcCC26xxHWAttrs[CC1350_LAUNCHXL_ADC7]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1350_LAUNCHXL_ADCDCOUPL], &adcCC26xxHWAttrs[CC1350_LAUNCHXL_ADCDCOUPL]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1350_LAUNCHXL_ADCVSS], &adcCC26xxHWAttrs[CC1350_LAUNCHXL_ADCVSS]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1350_LAUNCHXL_ADCVDDS], &adcCC26xxHWAttrs[CC1350_LAUNCHXL_ADCVDDS]}, +}; + +const uint_least8_t ADC_count = CC1350_LAUNCHXL_ADCCOUNT; + +/* + * =============================== Crypto =============================== + */ +#include + +CryptoCC26XX_Object cryptoCC26XXObjects[CC1350_LAUNCHXL_CRYPTOCOUNT]; + +const CryptoCC26XX_HWAttrs cryptoCC26XXHWAttrs[CC1350_LAUNCHXL_CRYPTOCOUNT] = { + { + .baseAddr = CRYPTO_BASE, + .powerMngrId = PowerCC26XX_PERIPH_CRYPTO, + .intNum = INT_CRYPTO_RESULT_AVAIL_IRQ, + .intPriority = ~0, + } +}; + +const CryptoCC26XX_Config CryptoCC26XX_config[CC1350_LAUNCHXL_CRYPTOCOUNT] = { + { + .object = &cryptoCC26XXObjects[CC1350_LAUNCHXL_CRYPTO0], + .hwAttrs = &cryptoCC26XXHWAttrs[CC1350_LAUNCHXL_CRYPTO0] + }, +}; + +/* + * =============================== GPIO =============================== + */ +#include +#include + +/* + * Array of Pin configurations + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC1350_LAUNCHXL.h + * NOTE: Pins not used for interrupts should be placed at the end of the + * array. Callback entries can be omitted from callbacks array to + * reduce memory usage. + */ +GPIO_PinConfig gpioPinConfigs[] = { + /* Input pins */ + GPIOCC26XX_DIO_13 | GPIO_DO_NOT_CONFIG, /* Button 0 */ + GPIOCC26XX_DIO_14 | GPIO_DO_NOT_CONFIG, /* Button 1 */ + + GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG, /* CC1350_LAUNCHXL_SPI_MASTER_READY */ + GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG, /* CC1350_LAUNCHXL_SPI_SLAVE_READY */ + + /* Output pins */ + GPIOCC26XX_DIO_07 | GPIO_DO_NOT_CONFIG, /* Green LED */ + GPIOCC26XX_DIO_06 | GPIO_DO_NOT_CONFIG, /* Red LED */ + + /* SPI Flash CSN */ + GPIOCC26XX_DIO_20 | GPIO_DO_NOT_CONFIG, + + /* SD CS */ + GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG, +}; + +/* + * Array of callback function pointers + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC1350_LAUNCHXL.h + * NOTE: Pins not used for interrupts can be omitted from callbacks array to + * reduce memory usage (if placed at end of gpioPinConfigs array). + */ +GPIO_CallbackFxn gpioCallbackFunctions[] = { + NULL, /* Button 0 */ + NULL, /* Button 1 */ + NULL, /* CC1350_LAUNCHXL_SPI_MASTER_READY */ + NULL, /* CC1350_LAUNCHXL_SPI_SLAVE_READY */ +}; + +const GPIOCC26XX_Config GPIOCC26XX_config = { + .pinConfigs = (GPIO_PinConfig *)gpioPinConfigs, + .callbacks = (GPIO_CallbackFxn *)gpioCallbackFunctions, + .numberOfPinConfigs = sizeof(gpioPinConfigs)/sizeof(GPIO_PinConfig), + .numberOfCallbacks = sizeof(gpioCallbackFunctions)/sizeof(GPIO_CallbackFxn), + .intPriority = (~0) +}; + +/* + * =============================== GPTimer =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include + +GPTimerCC26XX_Object gptimerCC26XXObjects[CC1350_LAUNCHXL_GPTIMERCOUNT]; + +const GPTimerCC26XX_HWAttrs gptimerCC26xxHWAttrs[CC1350_LAUNCHXL_GPTIMERPARTSCOUNT] = { + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0A, }, + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0B, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1A, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1B, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2A, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2B, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3A, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3B, }, +}; + +const GPTimerCC26XX_Config GPTimerCC26XX_config[CC1350_LAUNCHXL_GPTIMERPARTSCOUNT] = { + { &gptimerCC26XXObjects[CC1350_LAUNCHXL_GPTIMER0], &gptimerCC26xxHWAttrs[CC1350_LAUNCHXL_GPTIMER0A], GPT_A }, + { &gptimerCC26XXObjects[CC1350_LAUNCHXL_GPTIMER0], &gptimerCC26xxHWAttrs[CC1350_LAUNCHXL_GPTIMER0B], GPT_B }, + { &gptimerCC26XXObjects[CC1350_LAUNCHXL_GPTIMER1], &gptimerCC26xxHWAttrs[CC1350_LAUNCHXL_GPTIMER1A], GPT_A }, + { &gptimerCC26XXObjects[CC1350_LAUNCHXL_GPTIMER1], &gptimerCC26xxHWAttrs[CC1350_LAUNCHXL_GPTIMER1B], GPT_B }, + { &gptimerCC26XXObjects[CC1350_LAUNCHXL_GPTIMER2], &gptimerCC26xxHWAttrs[CC1350_LAUNCHXL_GPTIMER2A], GPT_A }, + { &gptimerCC26XXObjects[CC1350_LAUNCHXL_GPTIMER2], &gptimerCC26xxHWAttrs[CC1350_LAUNCHXL_GPTIMER2B], GPT_B }, + { &gptimerCC26XXObjects[CC1350_LAUNCHXL_GPTIMER3], &gptimerCC26xxHWAttrs[CC1350_LAUNCHXL_GPTIMER3A], GPT_A }, + { &gptimerCC26XXObjects[CC1350_LAUNCHXL_GPTIMER3], &gptimerCC26xxHWAttrs[CC1350_LAUNCHXL_GPTIMER3B], GPT_B }, +}; + +/* + * =============================== I2C =============================== +*/ +#include +#include + +#if TI_I2C_CONF_ENABLE + +I2CCC26XX_Object i2cCC26xxObjects[CC1350_LAUNCHXL_I2CCOUNT]; + +const I2CCC26XX_HWAttrsV1 i2cCC26xxHWAttrs[CC1350_LAUNCHXL_I2CCOUNT] = { +#if TI_I2C_CONF_I2C0_ENABLE + { + .baseAddr = I2C0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_I2C0, + .intNum = INT_I2C_IRQ, + .intPriority = ~0, + .swiPriority = 0, + .sdaPin = CC1350_LAUNCHXL_I2C0_SDA0, + .sclPin = CC1350_LAUNCHXL_I2C0_SCL0, + }, +#endif +}; + +const I2C_Config I2C_config[CC1350_LAUNCHXL_I2CCOUNT] = { +#if TI_I2C_CONF_I2C0_ENABLE + { + .fxnTablePtr = &I2CCC26XX_fxnTable, + .object = &i2cCC26xxObjects[CC1350_LAUNCHXL_I2C0], + .hwAttrs = &i2cCC26xxHWAttrs[CC1350_LAUNCHXL_I2C0] + }, +#endif +}; + +const uint_least8_t I2C_count = CC1350_LAUNCHXL_I2CCOUNT; + +#endif /* TI_I2C_CONF_ENABLE */ + +/* + * =============================== NVS =============================== + */ +#include +#include +#include + +#define NVS_REGIONS_BASE 0x1A000 +#define SECTORSIZE 0x1000 +#define REGIONSIZE (SECTORSIZE * 4) + +#if TI_NVS_CONF_ENABLE + +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + +/* + * Reserve flash sectors for NVS driver use by placing an uninitialized byte + * array at the desired flash address. + */ +#if defined(__TI_COMPILER_VERSION__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +#pragma LOCATION(flashBuf, NVS_REGIONS_BASE); +#pragma NOINIT(flashBuf); +static char flashBuf[REGIONSIZE]; + +#elif defined(__IAR_SYSTEMS_ICC__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +static __no_init char flashBuf[REGIONSIZE] @ NVS_REGIONS_BASE; + +#elif defined(__GNUC__) + +/* + * Place the flash buffers in the .nvs section created in the gcc linker file. + * The .nvs section enforces alignment on a sector boundary but may + * be placed anywhere in flash memory. If desired the .nvs section can be set + * to a fixed address by changing the following in the gcc linker file: + * + * .nvs (FIXED_FLASH_ADDR) (NOLOAD) : AT (FIXED_FLASH_ADDR) { + * *(.nvs) + * } > REGION_TEXT + */ +__attribute__ ((section (".nvs"))) +static char flashBuf[REGIONSIZE]; + +#endif + +/* Allocate objects for NVS Internal Regions */ +NVSCC26XX_Object nvsCC26xxObjects[1]; + +/* Hardware attributes for NVS Internal Regions */ +const NVSCC26XX_HWAttrs nvsCC26xxHWAttrs[1] = { + { + .regionBase = (void *)flashBuf, + .regionSize = REGIONSIZE, + }, +}; + +#endif /* TI_NVS_CONF_NVS_INTERNAL_ENABLE */ + +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + +#define SPISECTORSIZE 0x1000 +#define SPIREGIONSIZE (SPISECTORSIZE * 32) +#define VERIFYBUFSIZE 64 + +static uint8_t verifyBuf[VERIFYBUFSIZE]; + +/* Allocate objects for NVS External Regions */ +NVSSPI25X_Object nvsSPI25XObjects[1]; + +/* Hardware attributes for NVS External Regions */ +const NVSSPI25X_HWAttrs nvsSPI25XHWAttrs[1] = { + { + .regionBaseOffset = 0, + .regionSize = SPIREGIONSIZE, + .sectorSize = SPISECTORSIZE, + .verifyBuf = verifyBuf, + .verifyBufSize = VERIFYBUFSIZE, + .spiHandle = NULL, + .spiIndex = 0, + .spiBitRate = 4000000, + .spiCsnGpioIndex = CC1350_LAUNCHXL_GPIO_SPI_FLASH_CS, + }, +}; + +#endif /* TI_NVS_CONF_NVS_EXTERNAL_ENABLE */ + +/* NVS Region index 0 and 1 refer to NVS and NVS SPI respectively */ +const NVS_Config NVS_config[CC1350_LAUNCHXL_NVSCOUNT] = { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + { + .fxnTablePtr = &NVSCC26XX_fxnTable, + .object = &nvsCC26xxObjects[0], + .hwAttrs = &nvsCC26xxHWAttrs[0], + }, +#endif +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + { + .fxnTablePtr = &NVSSPI25X_fxnTable, + .object = &nvsSPI25XObjects[0], + .hwAttrs = &nvsSPI25XHWAttrs[0], + }, +#endif +}; + +const uint_least8_t NVS_count = CC1350_LAUNCHXL_NVSCOUNT; + +#endif /* TI_NVS_CONF_ENABLE */ + +/* + * =============================== PIN =============================== + */ +#include +#include + +const PIN_Config BoardGpioInitTable[] = { + + CC1350_LAUNCHXL_PIN_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC1350_LAUNCHXL_PIN_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC1350_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC1350_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC1350_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ + CC1350_LAUNCHXL_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */ + CC1350_LAUNCHXL_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */ + CC1350_LAUNCHXL_DIO1_RF_SUB1GHZ | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* RF SW Switch defaults to 2.4 GHz path*/ + CC1350_LAUNCHXL_DIO30_RF_POWER | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* External RF Switch is powered off by default */ + CC1350_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */ + CC1350_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */ + CC1350_LAUNCHXL_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI clock */ + PIN_TERMINATE +}; + +const PINCC26XX_HWAttrs PINCC26XX_hwAttrs = { + .intPriority = ~0, + .swiPriority = 0 +}; + +/* + * =============================== Power =============================== + */ +#include +#include + +const PowerCC26XX_Config PowerCC26XX_config = { + .policyInitFxn = NULL, + .policyFxn = &PowerCC26XX_standbyPolicy, + .calibrateFxn = &PowerCC26XX_calibrate, + .enablePolicy = true, + .calibrateRCOSC_LF = true, + .calibrateRCOSC_HF = true, +}; + +/* + * =============================== PWM =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include +#include + +PWMTimerCC26XX_Object pwmtimerCC26xxObjects[CC1350_LAUNCHXL_PWMCOUNT]; + +const PWMTimerCC26XX_HwAttrs pwmtimerCC26xxHWAttrs[CC1350_LAUNCHXL_PWMCOUNT] = { + { .pwmPin = CC1350_LAUNCHXL_PWMPIN0, .gpTimerUnit = CC1350_LAUNCHXL_GPTIMER0A }, + { .pwmPin = CC1350_LAUNCHXL_PWMPIN1, .gpTimerUnit = CC1350_LAUNCHXL_GPTIMER0B }, + { .pwmPin = CC1350_LAUNCHXL_PWMPIN2, .gpTimerUnit = CC1350_LAUNCHXL_GPTIMER1A }, + { .pwmPin = CC1350_LAUNCHXL_PWMPIN3, .gpTimerUnit = CC1350_LAUNCHXL_GPTIMER1B }, + { .pwmPin = CC1350_LAUNCHXL_PWMPIN4, .gpTimerUnit = CC1350_LAUNCHXL_GPTIMER2A }, + { .pwmPin = CC1350_LAUNCHXL_PWMPIN5, .gpTimerUnit = CC1350_LAUNCHXL_GPTIMER2B }, + { .pwmPin = CC1350_LAUNCHXL_PWMPIN6, .gpTimerUnit = CC1350_LAUNCHXL_GPTIMER3A }, + { .pwmPin = CC1350_LAUNCHXL_PWMPIN7, .gpTimerUnit = CC1350_LAUNCHXL_GPTIMER3B }, +}; + +const PWM_Config PWM_config[CC1350_LAUNCHXL_PWMCOUNT] = { + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350_LAUNCHXL_PWM0], &pwmtimerCC26xxHWAttrs[CC1350_LAUNCHXL_PWM0] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350_LAUNCHXL_PWM1], &pwmtimerCC26xxHWAttrs[CC1350_LAUNCHXL_PWM1] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350_LAUNCHXL_PWM2], &pwmtimerCC26xxHWAttrs[CC1350_LAUNCHXL_PWM2] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350_LAUNCHXL_PWM3], &pwmtimerCC26xxHWAttrs[CC1350_LAUNCHXL_PWM3] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350_LAUNCHXL_PWM4], &pwmtimerCC26xxHWAttrs[CC1350_LAUNCHXL_PWM4] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350_LAUNCHXL_PWM5], &pwmtimerCC26xxHWAttrs[CC1350_LAUNCHXL_PWM5] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350_LAUNCHXL_PWM6], &pwmtimerCC26xxHWAttrs[CC1350_LAUNCHXL_PWM6] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350_LAUNCHXL_PWM7], &pwmtimerCC26xxHWAttrs[CC1350_LAUNCHXL_PWM7] }, +}; + +const uint_least8_t PWM_count = CC1350_LAUNCHXL_PWMCOUNT; + +/* + * =============================== RF Driver =============================== + */ +#include + +/* + * Board-specific callback function to set the correct antenna path. + * + * This function is called by the RF driver on global driver events. + * It contains a default implementation to set the correct antenna path. + * This function is defined in the file CC1350_LAUNCHXL_fxns.c + */ +extern void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg); + +const RFCC26XX_HWAttrsV2 RFCC26XX_hwAttrs = { + .hwiPriority = ~0, /* Lowest HWI priority */ + .swiPriority = 0, /* Lowest SWI priority */ + .xoscHfAlwaysNeeded = true, /* Keep XOSC dependency while in stanby */ + + /* Register the board specific callback */ + .globalCallback = &rfDriverCallback, + /* Subscribe the callback to both events */ + .globalEventMask = RF_GlobalEventRadioSetup | RF_GlobalEventRadioPowerDown +}; + +/* + * =============================== SD =============================== + */ +#include +#include + +#if TI_SD_CONF_ENABLE + +#if !(TI_SPI_CONF_SPI0_ENABLE) +#error "SD driver requires SPI0 enabled" +#endif + +SDSPI_Object sdspiObjects[CC1350_LAUNCHXL_SDCOUNT]; + +const SDSPI_HWAttrs sdspiHWAttrs[CC1350_LAUNCHXL_SDCOUNT] = { + { + .spiIndex = CC1350_LAUNCHXL_SPI0, + .spiCsGpioIndex = CC1350_LAUNCHXL_SDSPI_CS + } +}; + +const SD_Config SD_config[CC1350_LAUNCHXL_SDCOUNT] = { + { + .fxnTablePtr = &SDSPI_fxnTable, + .object = &sdspiObjects[CC1350_LAUNCHXL_SDSPI0], + .hwAttrs = &sdspiHWAttrs[CC1350_LAUNCHXL_SDSPI0] + }, +}; + +const uint_least8_t SD_count = CC1350_LAUNCHXL_SDCOUNT; + +#endif /* TI_SD_CONF_ENABLE */ + +/* + * =============================== SPI DMA =============================== + */ +#include +#include + +#if TI_SPI_CONF_ENABLE + +SPICC26XXDMA_Object spiCC26XXDMAObjects[CC1350_LAUNCHXL_SPICOUNT]; + +/* + * NOTE: The SPI instances below can be used by the SD driver to communicate + * with a SD card via SPI. The 'defaultTxBufValue' fields below are set to 0xFF + * to satisfy the SDSPI driver requirement. + */ +const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[CC1350_LAUNCHXL_SPICOUNT] = { +#if TI_SPI_CONF_SPI0_ENABLE + { + .baseAddr = SSI0_BASE, + .intNum = INT_SSI0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .powerMngrId = PowerCC26XX_PERIPH_SSI0, + .defaultTxBufValue = 0xFF, + .rxChannelBitMask = 1< +#include + +TRNGCC26X0_Object trngCC26X0Object[CC1350_LAUNCHXL_TRNGCOUNT]; + +const TRNGCC26X0_HWAttrs trngCC26X0HWAttrs[CC1350_LAUNCHXL_TRNGCOUNT] = { + { + .swiPriority = 0, + .intPriority = ~0, + } +}; + +const TRNG_Config TRNG_config[] = { + { &trngCC26X0Object[0], &trngCC26X0HWAttrs[0] }, +}; + +const uint8_t TRNG_count = CC1350_LAUNCHXL_TRNGCOUNT; + + +/* + * =============================== UART =============================== + */ +#include +#include + +#if TI_UART_CONF_ENABLE + +UARTCC26XX_Object uartCC26XXObjects[CC1350_LAUNCHXL_UARTCOUNT]; + +uint8_t uartCC26XXRingBuffer[CC1350_LAUNCHXL_UARTCOUNT][32]; + +const UARTCC26XX_HWAttrsV2 uartCC26XXHWAttrs[CC1350_LAUNCHXL_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .baseAddr = UART0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UART0, + .intNum = INT_UART0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .txPin = CC1350_LAUNCHXL_UART_TX, + .rxPin = CC1350_LAUNCHXL_UART_RX, + .ctsPin = PIN_UNASSIGNED, + .rtsPin = PIN_UNASSIGNED, + .ringBufPtr = uartCC26XXRingBuffer[CC1350_LAUNCHXL_UART0], + .ringBufSize = sizeof(uartCC26XXRingBuffer[CC1350_LAUNCHXL_UART0]), + .txIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_1_8, + .rxIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_4_8, + .errorFxn = NULL + }, +#endif +}; + +const UART_Config UART_config[CC1350_LAUNCHXL_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .fxnTablePtr = &UARTCC26XX_fxnTable, + .object = &uartCC26XXObjects[CC1350_LAUNCHXL_UART0], + .hwAttrs = &uartCC26XXHWAttrs[CC1350_LAUNCHXL_UART0] + }, +#endif +}; + +const uint_least8_t UART_count = CC1350_LAUNCHXL_UARTCOUNT; + +#endif /* TI_UART_CONF_ENABLE */ + +/* + * =============================== UDMA =============================== + */ +#include + +UDMACC26XX_Object udmaObjects[CC1350_LAUNCHXL_UDMACOUNT]; + +const UDMACC26XX_HWAttrs udmaHWAttrs[CC1350_LAUNCHXL_UDMACOUNT] = { + { + .baseAddr = UDMA0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UDMA, + .intNum = INT_DMA_ERR, + .intPriority = ~0 + } +}; + +const UDMACC26XX_Config UDMACC26XX_config[CC1350_LAUNCHXL_UDMACOUNT] = { + { + .object = &udmaObjects[CC1350_LAUNCHXL_UDMA0], + .hwAttrs = &udmaHWAttrs[CC1350_LAUNCHXL_UDMA0] + }, +}; + +/* + * =============================== Watchdog =============================== + */ +#include +#include + +WatchdogCC26XX_Object watchdogCC26XXObjects[CC1350_LAUNCHXL_WATCHDOGCOUNT]; + +const WatchdogCC26XX_HWAttrs watchdogCC26XXHWAttrs[CC1350_LAUNCHXL_WATCHDOGCOUNT] = { + { + .baseAddr = WDT_BASE, + .reloadValue = 1000 /* Reload value in milliseconds */ + }, +}; + +const Watchdog_Config Watchdog_config[CC1350_LAUNCHXL_WATCHDOGCOUNT] = { + { + .fxnTablePtr = &WatchdogCC26XX_fxnTable, + .object = &watchdogCC26XXObjects[CC1350_LAUNCHXL_WATCHDOG0], + .hwAttrs = &watchdogCC26XXHWAttrs[CC1350_LAUNCHXL_WATCHDOG0] + }, +}; + +const uint_least8_t Watchdog_count = CC1350_LAUNCHXL_WATCHDOGCOUNT; + +/* + * Board-specific initialization function to disable external flash. + * This function is defined in the file CC1350_LAUNCHXL_fxns.c + */ +extern void Board_initHook(void); + +/* + * ======== CC1350_LAUNCHXL_initGeneral ======== + */ +void CC1350_LAUNCHXL_initGeneral(void) +{ + Power_init(); + + if (PIN_init(BoardGpioInitTable) != PIN_SUCCESS) { + /* Error with PIN_init */ + while (1); + } + + /* Perform board-specific initialization */ + Board_initHook(); +} diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/CC1350_LAUNCHXL.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/CC1350_LAUNCHXL.h new file mode 100644 index 000000000..9167a15c3 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/CC1350_LAUNCHXL.h @@ -0,0 +1,383 @@ +/* + * Copyright (c) 2015-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 CC1350_LAUNCHXL.h + * + * @brief CC1350 LaunchPad Board Specific header file. + * + * The CC1350_LAUNCHXL header file should be included in an application as + * follows: + * @code + * #include "CC1350_LAUNCHXL.h" + * @endcode + * + * ============================================================================ + */ +#ifndef __CC1350_LAUNCHXL_BOARD_H__ +#define __CC1350_LAUNCHXL_BOARD_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "contiki-conf.h" + +/* Includes */ +#include +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) + +/* Externs */ +extern const PIN_Config BoardGpioInitTable[]; + +/* Defines */ +#define CC1350_LAUNCHXL + +/* Mapping of pins to board signals using general board aliases + * + */ + +/* Analog Capable DIOs */ +#define CC1350_LAUNCHXL_DIO23_ANALOG IOID_23 +#define CC1350_LAUNCHXL_DIO24_ANALOG IOID_24 +#define CC1350_LAUNCHXL_DIO25_ANALOG IOID_25 +#define CC1350_LAUNCHXL_DIO26_ANALOG IOID_26 +#define CC1350_LAUNCHXL_DIO27_ANALOG IOID_27 +#define CC1350_LAUNCHXL_DIO28_ANALOG IOID_28 +#define CC1350_LAUNCHXL_DIO29_ANALOG IOID_29 +#define CC1350_LAUNCHXL_DIO30_ANALOG IOID_30 + +/* Digital IOs */ +#define CC1350_LAUNCHXL_DIO0 IOID_0 +#define CC1350_LAUNCHXL_DIO1_RF_SUB1GHZ IOID_1 +#define CC1350_LAUNCHXL_DIO12 IOID_12 +#define CC1350_LAUNCHXL_DIO15 IOID_15 +#define CC1350_LAUNCHXL_DIO16_TDO IOID_16 +#define CC1350_LAUNCHXL_DIO17_TDI IOID_17 +#define CC1350_LAUNCHXL_DIO21 IOID_21 +#define CC1350_LAUNCHXL_DIO22 IOID_22 +#define CC1350_LAUNCHXL_DIO30_RF_POWER IOID_30 + +/* Discrete Inputs */ +#define CC1350_LAUNCHXL_PIN_BTN1 IOID_13 +#define CC1350_LAUNCHXL_PIN_BTN2 IOID_14 + + +/* GPIO */ +#define CC1350_LAUNCHXL_GPIO_LED_ON 1 +#define CC1350_LAUNCHXL_GPIO_LED_OFF 0 + +/* I2C */ +#define CC1350_LAUNCHXL_I2C0_SCL0 IOID_4 +#define CC1350_LAUNCHXL_I2C0_SDA0 IOID_5 + + +/* LEDs */ +#define CC1350_LAUNCHXL_PIN_LED_ON 1 +#define CC1350_LAUNCHXL_PIN_LED_OFF 0 +#define CC1350_LAUNCHXL_PIN_RLED IOID_6 +#define CC1350_LAUNCHXL_PIN_GLED IOID_7 + +/* PWM Outputs */ +#define CC1350_LAUNCHXL_PWMPIN0 CC1350_LAUNCHXL_PIN_RLED +#define CC1350_LAUNCHXL_PWMPIN1 CC1350_LAUNCHXL_PIN_GLED +#define CC1350_LAUNCHXL_PWMPIN2 PIN_UNASSIGNED +#define CC1350_LAUNCHXL_PWMPIN3 PIN_UNASSIGNED +#define CC1350_LAUNCHXL_PWMPIN4 PIN_UNASSIGNED +#define CC1350_LAUNCHXL_PWMPIN5 PIN_UNASSIGNED +#define CC1350_LAUNCHXL_PWMPIN6 PIN_UNASSIGNED +#define CC1350_LAUNCHXL_PWMPIN7 PIN_UNASSIGNED + +/* SPI */ +#define CC1350_LAUNCHXL_SPI_FLASH_CS IOID_20 +#define CC1350_LAUNCHXL_FLASH_CS_ON 0 +#define CC1350_LAUNCHXL_FLASH_CS_OFF 1 + +/* SPI Board */ +#define CC1350_LAUNCHXL_SPI0_MISO IOID_8 /* RF1.20 */ +#define CC1350_LAUNCHXL_SPI0_MOSI IOID_9 /* RF1.18 */ +#define CC1350_LAUNCHXL_SPI0_CLK IOID_10 /* RF1.16 */ +#define CC1350_LAUNCHXL_SPI0_CSN PIN_UNASSIGNED +#define CC1350_LAUNCHXL_SPI1_MISO PIN_UNASSIGNED +#define CC1350_LAUNCHXL_SPI1_MOSI PIN_UNASSIGNED +#define CC1350_LAUNCHXL_SPI1_CLK PIN_UNASSIGNED +#define CC1350_LAUNCHXL_SPI1_CSN PIN_UNASSIGNED + +/* UART Board */ +#define CC1350_LAUNCHXL_UART_RX IOID_2 /* RXD */ +#define CC1350_LAUNCHXL_UART_TX IOID_3 /* TXD */ +#define CC1350_LAUNCHXL_UART_CTS IOID_19 /* CTS */ +#define CC1350_LAUNCHXL_UART_RTS IOID_18 /* RTS */ + +/*! + * @brief Initialize the general board specific settings + * + * This function initializes the general board specific settings. + */ +void CC1350_LAUNCHXL_initGeneral(void); + +/*! + * @brief Turn off the external flash on LaunchPads + * + */ +void CC1350_LAUNCHXL_shutDownExtFlash(void); + +/*! + * @brief Wake up the external flash present on the board files + * + * This function toggles the chip select for the amount of time needed + * to wake the chip up. + */ +void CC1350_LAUNCHXL_wakeUpExtFlash(void); + +/*! + * @def CC1350_LAUNCHXL_ADCBufName + * @brief Enum of ADCBufs + */ +typedef enum CC1350_LAUNCHXL_ADCBufName { + CC1350_LAUNCHXL_ADCBUF0 = 0, + + CC1350_LAUNCHXL_ADCBUFCOUNT +} CC1350_LAUNCHXL_ADCBufName; + +/*! + * @def CC1350_LAUNCHXL_ADCBuf0ChannelName + * @brief Enum of ADCBuf channels + */ +typedef enum CC1350_LAUNCHXL_ADCBuf0ChannelName { + CC1350_LAUNCHXL_ADCBUF0CHANNEL0 = 0, + CC1350_LAUNCHXL_ADCBUF0CHANNEL1, + CC1350_LAUNCHXL_ADCBUF0CHANNEL2, + CC1350_LAUNCHXL_ADCBUF0CHANNEL3, + CC1350_LAUNCHXL_ADCBUF0CHANNEL4, + CC1350_LAUNCHXL_ADCBUF0CHANNEL5, + CC1350_LAUNCHXL_ADCBUF0CHANNEL6, + CC1350_LAUNCHXL_ADCBUF0CHANNEL7, + CC1350_LAUNCHXL_ADCBUF0CHANNELVDDS, + CC1350_LAUNCHXL_ADCBUF0CHANNELDCOUPL, + CC1350_LAUNCHXL_ADCBUF0CHANNELVSS, + + CC1350_LAUNCHXL_ADCBUF0CHANNELCOUNT +} CC1350_LAUNCHXL_ADCBuf0ChannelName; + +/*! + * @def CC1350_LAUNCHXL_ADCName + * @brief Enum of ADCs + */ +typedef enum CC1350_LAUNCHXL_ADCName { + CC1350_LAUNCHXL_ADC0 = 0, + CC1350_LAUNCHXL_ADC1, + CC1350_LAUNCHXL_ADC2, + CC1350_LAUNCHXL_ADC3, + CC1350_LAUNCHXL_ADC4, + CC1350_LAUNCHXL_ADC5, + CC1350_LAUNCHXL_ADC6, + CC1350_LAUNCHXL_ADC7, + CC1350_LAUNCHXL_ADCDCOUPL, + CC1350_LAUNCHXL_ADCVSS, + CC1350_LAUNCHXL_ADCVDDS, + + CC1350_LAUNCHXL_ADCCOUNT +} CC1350_LAUNCHXL_ADCName; + +/*! + * @def CC1350_LAUNCHXL_CryptoName + * @brief Enum of Crypto names + */ +typedef enum CC1350_LAUNCHXL_CryptoName { + CC1350_LAUNCHXL_CRYPTO0 = 0, + + CC1350_LAUNCHXL_CRYPTOCOUNT +} CC1350_LAUNCHXL_CryptoName; + +/*! + * @def CC1350_LAUNCHXL_GPIOName + * @brief Enum of GPIO names + */ +typedef enum CC1350_LAUNCHXL_GPIOName { + CC1350_LAUNCHXL_GPIO_S1 = 0, + CC1350_LAUNCHXL_GPIO_S2, + CC1350_LAUNCHXL_SPI_MASTER_READY, + CC1350_LAUNCHXL_SPI_SLAVE_READY, + CC1350_LAUNCHXL_GPIO_LED_GREEN, + CC1350_LAUNCHXL_GPIO_LED_RED, + CC1350_LAUNCHXL_GPIO_SPI_FLASH_CS, + CC1350_LAUNCHXL_SDSPI_CS, + CC1350_LAUNCHXL_GPIOCOUNT +} CC1350_LAUNCHXL_GPIOName; + +/*! + * @def CC1350_LAUNCHXL_GPTimerName + * @brief Enum of GPTimer parts + */ +typedef enum CC1350_LAUNCHXL_GPTimerName { + CC1350_LAUNCHXL_GPTIMER0A = 0, + CC1350_LAUNCHXL_GPTIMER0B, + CC1350_LAUNCHXL_GPTIMER1A, + CC1350_LAUNCHXL_GPTIMER1B, + CC1350_LAUNCHXL_GPTIMER2A, + CC1350_LAUNCHXL_GPTIMER2B, + CC1350_LAUNCHXL_GPTIMER3A, + CC1350_LAUNCHXL_GPTIMER3B, + + CC1350_LAUNCHXL_GPTIMERPARTSCOUNT +} CC1350_LAUNCHXL_GPTimerName; + +/*! + * @def CC1350_LAUNCHXL_GPTimers + * @brief Enum of GPTimers + */ +typedef enum CC1350_LAUNCHXL_GPTimers { + CC1350_LAUNCHXL_GPTIMER0 = 0, + CC1350_LAUNCHXL_GPTIMER1, + CC1350_LAUNCHXL_GPTIMER2, + CC1350_LAUNCHXL_GPTIMER3, + + CC1350_LAUNCHXL_GPTIMERCOUNT +} CC1350_LAUNCHXL_GPTimers; + +/*! + * @def CC1350_LAUNCHXL_I2CName + * @brief Enum of I2C names + */ +typedef enum CC1350_LAUNCHXL_I2CName { +#if TI_I2C_CONF_I2C0_ENABLE + CC1350_LAUNCHXL_I2C0 = 0, +#endif + + CC1350_LAUNCHXL_I2CCOUNT +} CC1350_LAUNCHXL_I2CName; + +/*! + * @def CC1350_LAUNCHXL_NVSName + * @brief Enum of NVS names + */ +typedef enum CC1350_LAUNCHXL_NVSName { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + CC1350_LAUNCHXL_NVSCC26XX0 = 0, +#endif +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + CC1350_LAUNCHXL_NVSSPI25X0, +#endif + + CC1350_LAUNCHXL_NVSCOUNT +} CC1350_LAUNCHXL_NVSName; + +/*! + * @def CC1350_LAUNCHXL_PWMName + * @brief Enum of PWM outputs + */ +typedef enum CC1350_LAUNCHXL_PWMName { + CC1350_LAUNCHXL_PWM0 = 0, + CC1350_LAUNCHXL_PWM1, + CC1350_LAUNCHXL_PWM2, + CC1350_LAUNCHXL_PWM3, + CC1350_LAUNCHXL_PWM4, + CC1350_LAUNCHXL_PWM5, + CC1350_LAUNCHXL_PWM6, + CC1350_LAUNCHXL_PWM7, + + CC1350_LAUNCHXL_PWMCOUNT +} CC1350_LAUNCHXL_PWMName; + +/*! + * @def CC1350_LAUNCHXL_SDName + * @brief Enum of SD names + */ +typedef enum CC1350_LAUNCHXL_SDName { + CC1350_LAUNCHXL_SDSPI0 = 0, + + CC1350_LAUNCHXL_SDCOUNT +} CC1350_LAUNCHXL_SDName; + +/*! + * @def CC1350_LAUNCHXL_SPIName + * @brief Enum of SPI names + */ +typedef enum CC1350_LAUNCHXL_SPIName { +#if TI_SPI_CONF_SPI0_ENABLE + CC1350_LAUNCHXL_SPI0 = 0, +#endif +#if TI_SPI_CONF_SPI1_ENABLE + CC1350_LAUNCHXL_SPI1, +#endif + + CC1350_LAUNCHXL_SPICOUNT +} CC1350_LAUNCHXL_SPIName; + +/*! + * @def CC1350_LAUNCHXL_TRNGName + * @brief Enum of TRNGs + */ +typedef enum CC1350_LAUNCHXL_TRNGName { + CC1350_LAUNCHXL_TRNG0 = 0, + + CC1350_LAUNCHXL_TRNGCOUNT +} CC1350_LAUNCHXL_TRNGName; + +/*! + * @def CC1350_LAUNCHXL_UARTName + * @brief Enum of UARTs + */ +typedef enum CC1350_LAUNCHXL_UARTName { +#if TI_UART_CONF_UART0_ENABLE + CC1350_LAUNCHXL_UART0 = 0, +#endif + + CC1350_LAUNCHXL_UARTCOUNT +} CC1350_LAUNCHXL_UARTName; + +/*! + * @def CC1350_LAUNCHXL_UDMAName + * @brief Enum of DMA buffers + */ +typedef enum CC1350_LAUNCHXL_UDMAName { + CC1350_LAUNCHXL_UDMA0 = 0, + + CC1350_LAUNCHXL_UDMACOUNT +} CC1350_LAUNCHXL_UDMAName; + +/*! + * @def CC1350_LAUNCHXL_WatchdogName + * @brief Enum of Watchdogs + */ +typedef enum CC1350_LAUNCHXL_WatchdogName { + CC1350_LAUNCHXL_WATCHDOG0 = 0, + + CC1350_LAUNCHXL_WATCHDOGCOUNT +} CC1350_LAUNCHXL_WatchdogName; + +#ifdef __cplusplus +} +#endif + +#endif /* __CC1350_LAUNCHXL_BOARD_H__ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/CC1350_LAUNCHXL_fxns.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/CC1350_LAUNCHXL_fxns.c new file mode 100644 index 000000000..90f69a0c0 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/CC1350_LAUNCHXL_fxns.c @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +/* + * ======== CC1350_LAUNCHXL_fxns.c ======== + * This file contains the board-specific initialization functions, and + * RF callback function for antenna switching. + */ + +#include +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/cpu.h) + +#include +#include + +#include "Board.h" + + +/* + * ======== CC1350_LAUNCHXL_sendExtFlashByte ======== + */ +void CC1350_LAUNCHXL_sendExtFlashByte(PIN_Handle pinHandle, uint8_t byte) +{ + uint8_t i; + + /* SPI Flash CS */ + PIN_setOutputValue(pinHandle, IOID_20, 0); + + for (i = 0; i < 8; i++) { + PIN_setOutputValue(pinHandle, IOID_10, 0); /* SPI Flash CLK */ + + /* SPI Flash MOSI */ + PIN_setOutputValue(pinHandle, IOID_9, (byte >> (7 - i)) & 0x01); + PIN_setOutputValue(pinHandle, IOID_10, 1); /* SPI Flash CLK */ + + /* + * Waste a few cycles to keep the CLK high for at + * least 45% of the period. + * 3 cycles per loop: 8 loops @ 48 Mhz = 0.5 us. + */ + CPUdelay(8); + } + + PIN_setOutputValue(pinHandle, IOID_10, 0); /* CLK */ + PIN_setOutputValue(pinHandle, IOID_20, 1); /* CS */ + + /* + * Keep CS high at least 40 us + * 3 cycles per loop: 700 loops @ 48 Mhz ~= 44 us + */ + CPUdelay(700); +} + +/* + * ======== CC1350_LAUNCHXL_wakeUpExtFlash ======== + */ +void CC1350_LAUNCHXL_wakeUpExtFlash(void) +{ + PIN_Config extFlashPinTable[] = { + /* SPI Flash CS */ + IOID_20 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + PIN_TERMINATE + }; + PIN_State extFlashPinState; + PIN_Handle extFlashPinHandle = PIN_open(&extFlashPinState, extFlashPinTable); + + /* + * To wake up we need to toggle the chip select at + * least 20 ns and ten wait at least 35 us. + */ + + /* Toggle chip select for ~20ns to wake ext. flash */ + PIN_setOutputValue(extFlashPinHandle, IOID_20, 0); + /* 3 cycles per loop: 1 loop @ 48 Mhz ~= 62 ns */ + CPUdelay(1); + PIN_setOutputValue(extFlashPinHandle, IOID_20, 1); + /* 3 cycles per loop: 560 loops @ 48 Mhz ~= 35 us */ + CPUdelay(560); + + PIN_close(extFlashPinHandle); +} + +/* + * ======== CC1350_LAUNCHXL_shutDownExtFlash ======== + */ +void CC1350_LAUNCHXL_shutDownExtFlash(void) +{ + /* + * To be sure we are putting the flash into sleep and not waking it, + * we first have to make a wake up call + */ + CC1350_LAUNCHXL_wakeUpExtFlash(); + + PIN_Config extFlashPinTable[] = { + /* SPI Flash CS*/ + IOID_20 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash CLK */ + IOID_10 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash MOSI */ + IOID_9 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash MISO */ + IOID_8 | PIN_INPUT_EN | PIN_PULLDOWN, + PIN_TERMINATE + }; + PIN_State extFlashPinState; + PIN_Handle extFlashPinHandle = PIN_open(&extFlashPinState, extFlashPinTable); + + uint8_t extFlashShutdown = 0xB9; + + CC1350_LAUNCHXL_sendExtFlashByte(extFlashPinHandle, extFlashShutdown); + + PIN_close(extFlashPinHandle); +} + +/* + * ======== Board_initHook ======== + * Called by Board_init() to perform board-specific initialization. + */ +void Board_initHook() +{ + CC1350_LAUNCHXL_shutDownExtFlash(); +} + +/* + * For the SysConfig generated Board.h file, Board_RF_SUB1GHZ will not be + * defined unless the RF module is added to the configuration. Therefore, + * we don't include this code if Board_RF_SUB1GHZ is not defined. + */ +#if defined(Board_RF_SUB1GHZ) + +/* + * ======== rfDriverCallback ======== + * This is an implementation for the CC1350 launchpad which uses a + * single signal for antenna switching. + */ +void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg) +{ + (void)client; + RF_RadioSetup* setupCommand = (RF_RadioSetup*)arg; + + if (events & RF_GlobalEventRadioSetup) { + /* Power up the antenna switch */ + PINCC26XX_setOutputValue(Board_RF_POWER, 1); + + if (setupCommand->common.commandNo == CMD_PROP_RADIO_DIV_SETUP) { + /* Sub-1 GHz, requires antenna switch high */ + PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 1); + } + } + else if (events & RF_GlobalEventRadioPowerDown) { + /* Disable antenna switch to save current */ + PINCC26XX_setOutputValue(Board_RF_POWER, 0); + PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 0); + } +} +#endif diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/Makefile.cc1350 b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/Makefile.cc1350 new file mode 100644 index 000000000..350a5a045 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/Makefile.cc1350 @@ -0,0 +1,21 @@ +################################################################################ +# SimpleLink Device makefile + +SUBFAMILY = cc13x0-cc26x0 +DEVICE_FAMILY = CC13X0 +DEVICE_LINE = CC13XX +DEVICE = CC1350 + +BOARD_SOURCEFILES += CC1350_LAUNCHXL.c CC1350_LAUNCHXL_fxns.c + +SUPPORTS_PROP_MODE = 1 +SUPPORTS_IEEE_MODE = 1 +SUPPORTS_BLE_BEACON = 1 + +SUPPORTS_HIGH_PA = 0 + +### Signal that we can be programmed with cc2538-bsl +BOARD_SUPPORTS_BSL = 1 + +# Include the common board makefile +include $(FAMILY_PATH)/launchpad/Makefile.launchpad diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/Board.h new file mode 100644 index 000000000..d22d73c17 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/Board.h @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2017-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 __BOARD_H +#define __BOARD_H + +#define Board_CC1352P_2_LAUNCHXL +#define BOARD_STRING "TI CC1352P-2 LaunchPad" + +#ifdef __cplusplus +extern "C" { +#endif + +#include "CC1352P_2_LAUNCHXL.h" + +#define Board_initGeneral() CC1352P_2_LAUNCHXL_initGeneral() +#define Board_shutDownExtFlash() CC1352P_2_LAUNCHXL_shutDownExtFlash() +#define Board_wakeUpExtFlash() CC1352P_2_LAUNCHXL_wakeUpExtFlash() + +/* These #defines allow us to reuse TI-RTOS across other device families */ + +#define Board_ADC0 CC1352P_2_LAUNCHXL_ADC0 +#define Board_ADC1 CC1352P_2_LAUNCHXL_ADC1 + +#define Board_ADCBUF0 CC1352P_2_LAUNCHXL_ADCBUF0 +#define Board_ADCBUF0CHANNEL0 CC1352P_2_LAUNCHXL_ADCBUF0CHANNEL0 +#define Board_ADCBUF0CHANNEL1 CC1352P_2_LAUNCHXL_ADCBUF0CHANNEL1 + +#define Board_CRYPTO0 CC1352P_2_LAUNCHXL_CRYPTO0 +#define Board_ECDH0 CC1352P_2_LAUNCHXL_ECDH0 +#define Board_ECDSA0 CC1352P_2_LAUNCHXL_ECDSA0 +#define Board_ECJPAKE0 CC1352P_2_LAUNCHXL_ECJPAKE0 +#define Board_AESCCM0 CC1352P_2_LAUNCHXL_AESCCM0 +#define Board_AESECB0 CC1352P_2_LAUNCHXL_AESECB0 +#define Board_SHA20 CC1352P_2_LAUNCHXL_SHA20 + +#define Board_DIO12 CC1352P_2_LAUNCHXL_DIO12 +#define Board_DIO15 CC1352P_2_LAUNCHXL_DIO15 +#define Board_DIO16_TDO CC1352P_2_LAUNCHXL_DIO16_TDO +#define Board_DIO17_TDI CC1352P_2_LAUNCHXL_DIO17_TDI +#define Board_DIO21 CC1352P_2_LAUNCHXL_DIO21 +#define Board_DIO22 CC1352P_2_LAUNCHXL_DIO22 + +#define Board_DIO23_ANALOG CC1352P_2_LAUNCHXL_DIO23_ANALOG +#define Board_DIO24_ANALOG CC1352P_2_LAUNCHXL_DIO24_ANALOG +#define Board_DIO25_ANALOG CC1352P_2_LAUNCHXL_DIO25_ANALOG +#define Board_DIO26_ANALOG CC1352P_2_LAUNCHXL_DIO26_ANALOG +#define Board_DIO27_ANALOG CC1352P_2_LAUNCHXL_DIO27_ANALOG +#define Board_DIO28_ANALOG CC1352P_2_LAUNCHXL_DIO28_ANALOG +#define Board_DIO29_ANALOG CC1352P_2_LAUNCHXL_DIO29_ANALOG +#define Board_DIO30_RFSW CC1352P_2_LAUNCHXL_DIO30_RF_SUB1GHZ + +/* + * Board_RF_SUB1GHZ, Board_RF_HIGH_PA, and Board_RF_24GHZ are the names + * generated by SysConfig. Define them here so that the RF callback function + * can reference them. + */ +#define Board_RF_24GHZ CC1352P_2_LAUNCHXL_DIO28_RF_24GHZ +#define Board_RF_HIGH_PA CC1352P_2_LAUNCHXL_DIO29_RF_HIGH_PA +#define Board_RF_SUB1GHZ CC1352P_2_LAUNCHXL_DIO30_RF_SUB1GHZ + +#define Board_GPIO_BUTTON0 CC1352P_2_LAUNCHXL_GPIO_S1 +#define Board_GPIO_BUTTON1 CC1352P_2_LAUNCHXL_GPIO_S2 +#define Board_GPIO_BTN1 CC1352P_2_LAUNCHXL_GPIO_S1 +#define Board_GPIO_BTN2 CC1352P_2_LAUNCHXL_GPIO_S2 +#define Board_GPIO_LED0 CC1352P_2_LAUNCHXL_GPIO_LED_RED +#define Board_GPIO_LED1 CC1352P_2_LAUNCHXL_GPIO_LED_GREEN +#define Board_GPIO_LED2 CC1352P_2_LAUNCHXL_GPIO_LED_RED +#define Board_GPIO_RLED CC1352P_2_LAUNCHXL_GPIO_LED_RED +#define Board_GPIO_GLED CC1352P_2_LAUNCHXL_GPIO_LED_GREEN +#define Board_GPIO_LED_ON CC1352P_2_LAUNCHXL_GPIO_LED_ON +#define Board_GPIO_LED_OFF CC1352P_2_LAUNCHXL_GPIO_LED_OFF + +#define Board_GPTIMER0A CC1352P_2_LAUNCHXL_GPTIMER0A +#define Board_GPTIMER0B CC1352P_2_LAUNCHXL_GPTIMER0B +#define Board_GPTIMER1A CC1352P_2_LAUNCHXL_GPTIMER1A +#define Board_GPTIMER1B CC1352P_2_LAUNCHXL_GPTIMER1B +#define Board_GPTIMER2A CC1352P_2_LAUNCHXL_GPTIMER2A +#define Board_GPTIMER2B CC1352P_2_LAUNCHXL_GPTIMER2B +#define Board_GPTIMER3A CC1352P_2_LAUNCHXL_GPTIMER3A +#define Board_GPTIMER3B CC1352P_2_LAUNCHXL_GPTIMER3B + +#define Board_I2C0 CC1352P_2_LAUNCHXL_I2C0 +#define Board_I2C_TMP Board_I2C0 + +#define Board_NVSINTERNAL CC1352P_2_LAUNCHXL_NVSCC26XX0 +#define Board_NVSEXTERNAL CC1352P_2_LAUNCHXL_NVSSPI25X0 + +#define Board_PIN_BUTTON0 CC1352P_2_LAUNCHXL_PIN_BTN1 +#define Board_PIN_BUTTON1 CC1352P_2_LAUNCHXL_PIN_BTN2 +#define Board_PIN_BTN1 CC1352P_2_LAUNCHXL_PIN_BTN1 +#define Board_PIN_BTN2 CC1352P_2_LAUNCHXL_PIN_BTN2 +#define Board_PIN_LED0 CC1352P_2_LAUNCHXL_PIN_RLED +#define Board_PIN_LED1 CC1352P_2_LAUNCHXL_PIN_GLED +#define Board_PIN_LED2 CC1352P_2_LAUNCHXL_PIN_RLED +#define Board_PIN_RLED CC1352P_2_LAUNCHXL_PIN_RLED +#define Board_PIN_GLED CC1352P_2_LAUNCHXL_PIN_GLED + +#define Board_PWM0 CC1352P_2_LAUNCHXL_PWM0 +#define Board_PWM1 CC1352P_2_LAUNCHXL_PWM1 +#define Board_PWM2 CC1352P_2_LAUNCHXL_PWM2 +#define Board_PWM3 CC1352P_2_LAUNCHXL_PWM3 +#define Board_PWM4 CC1352P_2_LAUNCHXL_PWM4 +#define Board_PWM5 CC1352P_2_LAUNCHXL_PWM5 +#define Board_PWM6 CC1352P_2_LAUNCHXL_PWM6 +#define Board_PWM7 CC1352P_2_LAUNCHXL_PWM7 + +#define Board_SD0 CC1352P_2_LAUNCHXL_SDSPI0 + +#define Board_SPI0 CC1352P_2_LAUNCHXL_SPI0 +#define Board_SPI0_MISO CC1352P_2_LAUNCHXL_SPI0_MISO +#define Board_SPI0_MOSI CC1352P_2_LAUNCHXL_SPI0_MOSI +#define Board_SPI0_CLK CC1352P_2_LAUNCHXL_SPI0_CLK +#define Board_SPI0_CSN CC1352P_2_LAUNCHXL_SPI0_CSN +#define Board_SPI1 CC1352P_2_LAUNCHXL_SPI1 +#define Board_SPI1_MISO CC1352P_2_LAUNCHXL_SPI1_MISO +#define Board_SPI1_MOSI CC1352P_2_LAUNCHXL_SPI1_MOSI +#define Board_SPI1_CLK CC1352P_2_LAUNCHXL_SPI1_CLK +#define Board_SPI1_CSN CC1352P_2_LAUNCHXL_SPI1_CSN +#define Board_SPI_FLASH_CS CC1352P_2_LAUNCHXL_SPI_FLASH_CS +#define Board_FLASH_CS_ON 0 +#define Board_FLASH_CS_OFF 1 + +#define Board_SPI_MASTER CC1352P_2_LAUNCHXL_SPI0 +#define Board_SPI_SLAVE CC1352P_2_LAUNCHXL_SPI0 +#define Board_SPI_MASTER_READY CC1352P_2_LAUNCHXL_SPI_MASTER_READY +#define Board_SPI_SLAVE_READY CC1352P_2_LAUNCHXL_SPI_SLAVE_READY + +#define Board_UART0 CC1352P_2_LAUNCHXL_UART0 +#define Board_UART1 CC1352P_2_LAUNCHXL_UART1 + +#define Board_WATCHDOG0 CC1352P_2_LAUNCHXL_WATCHDOG0 + +/* Board specific I2C addresses */ +#define Board_TMP_ADDR (0x40) +#define Board_SENSORS_BP_TMP_ADDR Board_TMP_ADDR + +#ifdef __cplusplus +} +#endif + +#endif /* __BOARD_H */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/CC1352P_2_LAUNCHXL.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/CC1352P_2_LAUNCHXL.c new file mode 100644 index 000000000..a1b74bce4 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/CC1352P_2_LAUNCHXL.c @@ -0,0 +1,949 @@ +/* + * Copyright (c) 2017-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +/* + * ====================== CC1352P_2_LAUNCHXL.c =================================== + * This file is responsible for setting up the board specific items for the + * CC1352P_2_LAUNCHXL board. + */ + +#include +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/udma.h) +#include DeviceFamily_constructPath(inc/hw_ints.h) +#include DeviceFamily_constructPath(inc/hw_memmap.h) + +#include "CC1352P_2_LAUNCHXL.h" + +/* + * =============================== ADCBuf =============================== + */ +#include +#include + +ADCBufCC26X2_Object adcBufCC26xxObjects[CC1352P_2_LAUNCHXL_ADCBUFCOUNT]; + +/* + * This table converts a virtual adc channel into a dio and internal analogue + * input signal. This table is necessary for the functioning of the adcBuf + * driver. Comment out unused entries to save flash. Dio and internal signal + * pairs are hardwired. Do not remap them in the table. You may reorder entire + * entries. The mapping of dio and internal signals is package dependent. + */ +const ADCBufCC26X2_AdcChannelLutEntry ADCBufCC26X2_adcChannelLut[CC1352P_2_LAUNCHXL_ADCBUF0CHANNELCOUNT] = { + {CC1352P_2_LAUNCHXL_DIO23_ANALOG, ADC_COMPB_IN_AUXIO7}, + {CC1352P_2_LAUNCHXL_DIO24_ANALOG, ADC_COMPB_IN_AUXIO6}, + {CC1352P_2_LAUNCHXL_DIO25_ANALOG, ADC_COMPB_IN_AUXIO5}, + {CC1352P_2_LAUNCHXL_DIO26_ANALOG, ADC_COMPB_IN_AUXIO4}, + {CC1352P_2_LAUNCHXL_DIO27_ANALOG, ADC_COMPB_IN_AUXIO3}, + {PIN_UNASSIGNED, ADC_COMPB_IN_VDDS}, + {PIN_UNASSIGNED, ADC_COMPB_IN_DCOUPL}, + {PIN_UNASSIGNED, ADC_COMPB_IN_VSS}, +}; + +const ADCBufCC26X2_HWAttrs adcBufCC26xxHWAttrs[CC1352P_2_LAUNCHXL_ADCBUFCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + .adcChannelLut = ADCBufCC26X2_adcChannelLut, + .gpTimerUnit = CC1352P_2_LAUNCHXL_GPTIMER0A, + } +}; + +const ADCBuf_Config ADCBuf_config[CC1352P_2_LAUNCHXL_ADCBUFCOUNT] = { + { + &ADCBufCC26X2_fxnTable, + &adcBufCC26xxObjects[CC1352P_2_LAUNCHXL_ADCBUF0], + &adcBufCC26xxHWAttrs[CC1352P_2_LAUNCHXL_ADCBUF0] + }, +}; + +const uint_least8_t ADCBuf_count = CC1352P_2_LAUNCHXL_ADCBUFCOUNT; + +/* + * =============================== ADC =============================== + */ +#include +#include + +ADCCC26XX_Object adcCC26xxObjects[CC1352P_2_LAUNCHXL_ADCCOUNT]; + +const ADCCC26XX_HWAttrs adcCC26xxHWAttrs[CC1352P_2_LAUNCHXL_ADCCOUNT] = { + { + .adcDIO = CC1352P_2_LAUNCHXL_DIO23_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO7, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1352P_2_LAUNCHXL_DIO24_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO6, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1352P_2_LAUNCHXL_DIO25_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO5, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1352P_2_LAUNCHXL_DIO26_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO4, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1352P_2_LAUNCHXL_DIO27_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO3, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_DCOUPL, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_VSS, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_VDDS, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + } +}; + +const ADC_Config ADC_config[CC1352P_2_LAUNCHXL_ADCCOUNT] = { + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352P_2_LAUNCHXL_ADC0], &adcCC26xxHWAttrs[CC1352P_2_LAUNCHXL_ADC0]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352P_2_LAUNCHXL_ADC1], &adcCC26xxHWAttrs[CC1352P_2_LAUNCHXL_ADC1]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352P_2_LAUNCHXL_ADC2], &adcCC26xxHWAttrs[CC1352P_2_LAUNCHXL_ADC2]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352P_2_LAUNCHXL_ADC3], &adcCC26xxHWAttrs[CC1352P_2_LAUNCHXL_ADC3]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352P_2_LAUNCHXL_ADC4], &adcCC26xxHWAttrs[CC1352P_2_LAUNCHXL_ADC4]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352P_2_LAUNCHXL_ADCDCOUPL], &adcCC26xxHWAttrs[CC1352P_2_LAUNCHXL_ADCDCOUPL]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352P_2_LAUNCHXL_ADCVSS], &adcCC26xxHWAttrs[CC1352P_2_LAUNCHXL_ADCVSS]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352P_2_LAUNCHXL_ADCVDDS], &adcCC26xxHWAttrs[CC1352P_2_LAUNCHXL_ADCVDDS]}, +}; + +const uint_least8_t ADC_count = CC1352P_2_LAUNCHXL_ADCCOUNT; + +/* + * =============================== ECDH =============================== + */ +#include +#include + +ECDHCC26X2_Object ecdhCC26X2Objects[CC1352P_2_LAUNCHXL_ECDHCOUNT]; + +const ECDHCC26X2_HWAttrs ecdhCC26X2HWAttrs[CC1352P_2_LAUNCHXL_ECDHCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const ECDH_Config ECDH_config[CC1352P_2_LAUNCHXL_ECDHCOUNT] = { + { + .object = &ecdhCC26X2Objects[CC1352P_2_LAUNCHXL_ECDH0], + .hwAttrs = &ecdhCC26X2HWAttrs[CC1352P_2_LAUNCHXL_ECDH0] + }, +}; + +const uint_least8_t ECDH_count = CC1352P_2_LAUNCHXL_ECDHCOUNT; + +/* + * =============================== ECDSA =============================== + */ +#include +#include + +ECDSACC26X2_Object ecdsaCC26X2Objects[CC1352P_2_LAUNCHXL_ECDSACOUNT]; + +const ECDSACC26X2_HWAttrs ecdsaCC26X2HWAttrs[CC1352P_2_LAUNCHXL_ECDSACOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const ECDSA_Config ECDSA_config[CC1352P_2_LAUNCHXL_ECDSACOUNT] = { + { + .object = &ecdsaCC26X2Objects[CC1352P_2_LAUNCHXL_ECDSA0], + .hwAttrs = &ecdsaCC26X2HWAttrs[CC1352P_2_LAUNCHXL_ECDSA0] + }, +}; + +const uint_least8_t ECDSA_count = CC1352P_2_LAUNCHXL_ECDSACOUNT; + +/* + * =============================== ECJPAKE =============================== + */ +#include +#include + +ECJPAKECC26X2_Object ecjpakeCC26X2Objects[CC1352P_2_LAUNCHXL_ECJPAKECOUNT]; + +const ECJPAKECC26X2_HWAttrs ecjpakeCC26X2HWAttrs[CC1352P_2_LAUNCHXL_ECJPAKECOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const ECJPAKE_Config ECJPAKE_config[CC1352P_2_LAUNCHXL_ECJPAKECOUNT] = { + { + .object = &ecjpakeCC26X2Objects[CC1352P_2_LAUNCHXL_ECJPAKE0], + .hwAttrs = &ecjpakeCC26X2HWAttrs[CC1352P_2_LAUNCHXL_ECJPAKE0] + }, +}; + +const uint_least8_t ECJPAKE_count = CC1352P_2_LAUNCHXL_ECJPAKECOUNT; + + +/* + * =============================== SHA2 =============================== + */ +#include +#include + +SHA2CC26X2_Object sha2CC26X2Objects[CC1352P_2_LAUNCHXL_SHA2COUNT]; + +const SHA2CC26X2_HWAttrs sha2CC26X2HWAttrs[CC1352P_2_LAUNCHXL_SHA2COUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const SHA2_Config SHA2_config[CC1352P_2_LAUNCHXL_SHA2COUNT] = { + { + .object = &sha2CC26X2Objects[CC1352P_2_LAUNCHXL_SHA20], + .hwAttrs = &sha2CC26X2HWAttrs[CC1352P_2_LAUNCHXL_SHA20] + }, +}; + +const uint_least8_t SHA2_count = CC1352P_2_LAUNCHXL_SHA2COUNT; + +/* + * =============================== AESCCM =============================== + */ +#include +#include + +AESCCMCC26XX_Object aesccmCC26XXObjects[CC1352P_2_LAUNCHXL_AESCCMCOUNT]; + +const AESCCMCC26XX_HWAttrs aesccmCC26XXHWAttrs[CC1352P_2_LAUNCHXL_AESCCMCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const AESCCM_Config AESCCM_config[CC1352P_2_LAUNCHXL_AESCCMCOUNT] = { + { + .object = &aesccmCC26XXObjects[CC1352P_2_LAUNCHXL_AESCCM0], + .hwAttrs = &aesccmCC26XXHWAttrs[CC1352P_2_LAUNCHXL_AESCCM0] + }, +}; + +const uint_least8_t AESCCM_count = CC1352P_2_LAUNCHXL_AESCCMCOUNT; + +/* + * =============================== AESECB =============================== + */ +#include +#include + +AESECBCC26XX_Object aesecbCC26XXObjects[CC1352P_2_LAUNCHXL_AESECBCOUNT]; + +const AESECBCC26XX_HWAttrs aesecbCC26XXHWAttrs[CC1352P_2_LAUNCHXL_AESECBCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const AESECB_Config AESECB_config[CC1352P_2_LAUNCHXL_AESECBCOUNT] = { + { + .object = &aesecbCC26XXObjects[CC1352P_2_LAUNCHXL_AESECB0], + .hwAttrs = &aesecbCC26XXHWAttrs[CC1352P_2_LAUNCHXL_AESECB0] + }, +}; + +const uint_least8_t AESECB_count = CC1352P_2_LAUNCHXL_AESECBCOUNT; + +/* + * =============================== GPIO =============================== + */ +#include +#include + +/* + * Array of Pin configurations + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC1352P_2_LAUNCHXL.h + * NOTE: Pins not used for interrupts should be placed at the end of the + * array. Callback entries can be omitted from callbacks array to + * reduce memory usage. + */ +GPIO_PinConfig gpioPinConfigs[] = { + /* Input pins */ + GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG, /* Button 0 */ + GPIOCC26XX_DIO_14 | GPIO_DO_NOT_CONFIG, /* Button 1 */ + + GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG, /* CC1352P_2_LAUNCHXL_SPI_MASTER_READY */ + GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG, /* CC1352P_2_LAUNCHXL_SPI_SLAVE_READY */ + + /* Output pins */ + GPIOCC26XX_DIO_07 | GPIO_DO_NOT_CONFIG, /* Green LED */ + GPIOCC26XX_DIO_06 | GPIO_DO_NOT_CONFIG, /* Red LED */ + + /* SPI Flash CSN */ + GPIOCC26XX_DIO_20 | GPIO_DO_NOT_CONFIG, + + /* SD CS */ + GPIOCC26XX_DIO_19 | GPIO_DO_NOT_CONFIG, +}; + +/* + * Array of callback function pointers + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC1352P_LAUNCH.h + * NOTE: Pins not used for interrupts can be omitted from callbacks array to + * reduce memory usage (if placed at end of gpioPinConfigs array). + */ +GPIO_CallbackFxn gpioCallbackFunctions[] = { + NULL, /* Button 0 */ + NULL, /* Button 1 */ + NULL, /* CC1352P_2_LAUNCHXL_SPI_MASTER_READY */ + NULL, /* CC1352P_2_LAUNCHXL_SPI_SLAVE_READY */ +}; + +const GPIOCC26XX_Config GPIOCC26XX_config = { + .pinConfigs = (GPIO_PinConfig *)gpioPinConfigs, + .callbacks = (GPIO_CallbackFxn *)gpioCallbackFunctions, + .numberOfPinConfigs = CC1352P_2_LAUNCHXL_GPIOCOUNT, + .numberOfCallbacks = sizeof(gpioCallbackFunctions)/sizeof(GPIO_CallbackFxn), + .intPriority = (~0) +}; + +/* + * =============================== GPTimer =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include + +GPTimerCC26XX_Object gptimerCC26XXObjects[CC1352P_2_LAUNCHXL_GPTIMERCOUNT]; + +const GPTimerCC26XX_HWAttrs gptimerCC26xxHWAttrs[CC1352P_2_LAUNCHXL_GPTIMERPARTSCOUNT] = { + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0A, }, + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0B, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1A, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1B, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2A, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2B, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3A, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3B, }, +}; + +const GPTimerCC26XX_Config GPTimerCC26XX_config[CC1352P_2_LAUNCHXL_GPTIMERPARTSCOUNT] = { + { &gptimerCC26XXObjects[CC1352P_2_LAUNCHXL_GPTIMER0], &gptimerCC26xxHWAttrs[CC1352P_2_LAUNCHXL_GPTIMER0A], GPT_A }, + { &gptimerCC26XXObjects[CC1352P_2_LAUNCHXL_GPTIMER0], &gptimerCC26xxHWAttrs[CC1352P_2_LAUNCHXL_GPTIMER0B], GPT_B }, + { &gptimerCC26XXObjects[CC1352P_2_LAUNCHXL_GPTIMER1], &gptimerCC26xxHWAttrs[CC1352P_2_LAUNCHXL_GPTIMER1A], GPT_A }, + { &gptimerCC26XXObjects[CC1352P_2_LAUNCHXL_GPTIMER1], &gptimerCC26xxHWAttrs[CC1352P_2_LAUNCHXL_GPTIMER1B], GPT_B }, + { &gptimerCC26XXObjects[CC1352P_2_LAUNCHXL_GPTIMER2], &gptimerCC26xxHWAttrs[CC1352P_2_LAUNCHXL_GPTIMER2A], GPT_A }, + { &gptimerCC26XXObjects[CC1352P_2_LAUNCHXL_GPTIMER2], &gptimerCC26xxHWAttrs[CC1352P_2_LAUNCHXL_GPTIMER2B], GPT_B }, + { &gptimerCC26XXObjects[CC1352P_2_LAUNCHXL_GPTIMER3], &gptimerCC26xxHWAttrs[CC1352P_2_LAUNCHXL_GPTIMER3A], GPT_A }, + { &gptimerCC26XXObjects[CC1352P_2_LAUNCHXL_GPTIMER3], &gptimerCC26xxHWAttrs[CC1352P_2_LAUNCHXL_GPTIMER3B], GPT_B }, +}; + +/* + * =============================== I2C =============================== +*/ +#include +#include + +#if TI_I2C_CONF_ENABLE + +I2CCC26XX_Object i2cCC26xxObjects[CC1352P_2_LAUNCHXL_I2CCOUNT]; + +const I2CCC26XX_HWAttrsV1 i2cCC26xxHWAttrs[CC1352P_2_LAUNCHXL_I2CCOUNT] = { +#if TI_I2C_CONF_I2C0_ENABLE + { + .baseAddr = I2C0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_I2C0, + .intNum = INT_I2C_IRQ, + .intPriority = ~0, + .swiPriority = 0, + .sdaPin = CC1352P_2_LAUNCHXL_I2C0_SDA0, + .sclPin = CC1352P_2_LAUNCHXL_I2C0_SCL0, + }, +#endif +}; + +const I2C_Config I2C_config[CC1352P_2_LAUNCHXL_I2CCOUNT] = { +#if TI_I2C_CONF_I2C0_ENABLE + { + .fxnTablePtr = &I2CCC26XX_fxnTable, + .object = &i2cCC26xxObjects[CC1352P_2_LAUNCHXL_I2C0], + .hwAttrs = &i2cCC26xxHWAttrs[CC1352P_2_LAUNCHXL_I2C0] + }, +#endif +}; + +const uint_least8_t I2C_count = CC1352P_2_LAUNCHXL_I2CCOUNT; + +#endif /* TI_I2C_CONF_ENABLE */ + +/* + * =============================== NVS =============================== + */ +#include +#include +#include + +#define NVS_REGIONS_BASE 0x48000 +#define SECTORSIZE 0x2000 +#define REGIONSIZE (SECTORSIZE * 4) + +#if TI_NVS_CONF_ENABLE + +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + +/* + * Reserve flash sectors for NVS driver use by placing an uninitialized byte + * array at the desired flash address. + */ +#if defined(__TI_COMPILER_VERSION__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +#pragma LOCATION(flashBuf, NVS_REGIONS_BASE); +#pragma NOINIT(flashBuf); +static char flashBuf[REGIONSIZE]; + +#elif defined(__IAR_SYSTEMS_ICC__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +static __no_init char flashBuf[REGIONSIZE] @ NVS_REGIONS_BASE; + +#elif defined(__GNUC__) + +/* + * Place the flash buffers in the .nvs section created in the gcc linker file. + * The .nvs section enforces alignment on a sector boundary but may + * be placed anywhere in flash memory. If desired the .nvs section can be set + * to a fixed address by changing the following in the gcc linker file: + * + * .nvs (FIXED_FLASH_ADDR) (NOLOAD) : AT (FIXED_FLASH_ADDR) { + * *(.nvs) + * } > REGION_TEXT + */ +__attribute__ ((section (".nvs"))) +static char flashBuf[REGIONSIZE]; + +#endif + +/* Allocate objects for NVS Internal Regions */ +NVSCC26XX_Object nvsCC26xxObjects[1]; + +/* Hardware attributes for NVS Internal Regions */ +const NVSCC26XX_HWAttrs nvsCC26xxHWAttrs[1] = { + { + .regionBase = (void *)flashBuf, + .regionSize = REGIONSIZE, + }, +}; + +#endif /* TI_NVS_CONF_NVS_INTERNAL_ENABLE */ + +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + +#define SPISECTORSIZE 0x1000 +#define SPIREGIONSIZE (SPISECTORSIZE * 32) +#define VERIFYBUFSIZE 64 + +static uint8_t verifyBuf[VERIFYBUFSIZE]; + +/* Allocate objects for NVS External Regions */ +NVSSPI25X_Object nvsSPI25XObjects[1]; + +/* Hardware attributes for NVS External Regions */ +const NVSSPI25X_HWAttrs nvsSPI25XHWAttrs[1] = { + { + .regionBaseOffset = 0, + .regionSize = SPIREGIONSIZE, + .sectorSize = SPISECTORSIZE, + .verifyBuf = verifyBuf, + .verifyBufSize = VERIFYBUFSIZE, + .spiHandle = NULL, + .spiIndex = 0, + .spiBitRate = 4000000, + .spiCsnGpioIndex = CC1352P_2_LAUNCHXL_GPIO_SPI_FLASH_CS, + }, +}; + +#endif /* TI_NVS_CONF_NVS_EXTERNAL_ENABLE */ + +/* NVS Region index 0 and 1 refer to NVS and NVS SPI respectively */ +const NVS_Config NVS_config[CC1352P_2_LAUNCHXL_NVSCOUNT] = { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + { + .fxnTablePtr = &NVSCC26XX_fxnTable, + .object = &nvsCC26xxObjects[0], + .hwAttrs = &nvsCC26xxHWAttrs[0], + }, +#endif +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + { + .fxnTablePtr = &NVSSPI25X_fxnTable, + .object = &nvsSPI25XObjects[0], + .hwAttrs = &nvsSPI25XHWAttrs[0], + }, +#endif +}; + +const uint_least8_t NVS_count = CC1352P_2_LAUNCHXL_NVSCOUNT; + +#endif /* TI_NVS_CONF_ENABLE */ + +/* + * =============================== PIN =============================== + */ +#include +#include + +const PIN_Config BoardGpioInitTable[] = { + + CC1352P_2_LAUNCHXL_PIN_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC1352P_2_LAUNCHXL_PIN_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC1352P_2_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC1352P_2_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC1352P_2_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ + CC1352P_2_LAUNCHXL_UART0_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */ + CC1352P_2_LAUNCHXL_UART0_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */ + CC1352P_2_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */ + CC1352P_2_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */ + CC1352P_2_LAUNCHXL_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI clock */ + CC1352P_2_LAUNCHXL_DIO28_RF_24GHZ | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* Path disabled */ + CC1352P_2_LAUNCHXL_DIO29_RF_HIGH_PA | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* Path disabled */ + CC1352P_2_LAUNCHXL_DIO30_RF_SUB1GHZ | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* Path disabled */ + PIN_TERMINATE +}; + +const PINCC26XX_HWAttrs PINCC26XX_hwAttrs = { + .intPriority = ~0, + .swiPriority = 0 +}; + +/* + * =============================== Power =============================== + */ +#include +#include + +const PowerCC26X2_Config PowerCC26X2_config = { + .policyInitFxn = NULL, + .policyFxn = &PowerCC26XX_standbyPolicy, + .calibrateFxn = &PowerCC26XX_calibrate, + .enablePolicy = true, + .calibrateRCOSC_LF = true, + .calibrateRCOSC_HF = true, +}; + +/* + * =============================== PWM =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include +#include + +PWMTimerCC26XX_Object pwmtimerCC26xxObjects[CC1352P_2_LAUNCHXL_PWMCOUNT]; + +const PWMTimerCC26XX_HwAttrs pwmtimerCC26xxHWAttrs[CC1352P_2_LAUNCHXL_PWMCOUNT] = { + { .pwmPin = CC1352P_2_LAUNCHXL_PWMPIN0, .gpTimerUnit = CC1352P_2_LAUNCHXL_GPTIMER0A }, + { .pwmPin = CC1352P_2_LAUNCHXL_PWMPIN1, .gpTimerUnit = CC1352P_2_LAUNCHXL_GPTIMER0B }, + { .pwmPin = CC1352P_2_LAUNCHXL_PWMPIN2, .gpTimerUnit = CC1352P_2_LAUNCHXL_GPTIMER1A }, + { .pwmPin = CC1352P_2_LAUNCHXL_PWMPIN3, .gpTimerUnit = CC1352P_2_LAUNCHXL_GPTIMER1B }, + { .pwmPin = CC1352P_2_LAUNCHXL_PWMPIN4, .gpTimerUnit = CC1352P_2_LAUNCHXL_GPTIMER2A }, + { .pwmPin = CC1352P_2_LAUNCHXL_PWMPIN5, .gpTimerUnit = CC1352P_2_LAUNCHXL_GPTIMER2B }, + { .pwmPin = CC1352P_2_LAUNCHXL_PWMPIN6, .gpTimerUnit = CC1352P_2_LAUNCHXL_GPTIMER3A }, + { .pwmPin = CC1352P_2_LAUNCHXL_PWMPIN7, .gpTimerUnit = CC1352P_2_LAUNCHXL_GPTIMER3B }, +}; + +const PWM_Config PWM_config[CC1352P_2_LAUNCHXL_PWMCOUNT] = { + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352P_2_LAUNCHXL_PWM0], &pwmtimerCC26xxHWAttrs[CC1352P_2_LAUNCHXL_PWM0] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352P_2_LAUNCHXL_PWM1], &pwmtimerCC26xxHWAttrs[CC1352P_2_LAUNCHXL_PWM1] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352P_2_LAUNCHXL_PWM2], &pwmtimerCC26xxHWAttrs[CC1352P_2_LAUNCHXL_PWM2] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352P_2_LAUNCHXL_PWM3], &pwmtimerCC26xxHWAttrs[CC1352P_2_LAUNCHXL_PWM3] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352P_2_LAUNCHXL_PWM4], &pwmtimerCC26xxHWAttrs[CC1352P_2_LAUNCHXL_PWM4] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352P_2_LAUNCHXL_PWM5], &pwmtimerCC26xxHWAttrs[CC1352P_2_LAUNCHXL_PWM5] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352P_2_LAUNCHXL_PWM6], &pwmtimerCC26xxHWAttrs[CC1352P_2_LAUNCHXL_PWM6] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352P_2_LAUNCHXL_PWM7], &pwmtimerCC26xxHWAttrs[CC1352P_2_LAUNCHXL_PWM7] }, +}; + +const uint_least8_t PWM_count = CC1352P_2_LAUNCHXL_PWMCOUNT; + +/* + * =============================== RF Driver =============================== + */ +#include + +/* + * Board-specific callback function to set the correct antenna path. + * + * This function is called by the RF driver on global driver events. + * It contains a default implementation to set the correct antenna path. + * This function is defined in the file CC1352P_2_LAUNCHXL_fxns.c + */ +extern void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void* arg); + +const RFCC26XX_HWAttrsV2 RFCC26XX_hwAttrs = { + .hwiPriority = ~0, /* Lowest HWI priority */ + .swiPriority = 0, /* Lowest SWI priority */ + .xoscHfAlwaysNeeded = true, /* Keep XOSC dependency while in stanby */ + + /* Register the board specific callback */ + .globalCallback = &rfDriverCallback, + + /* Subscribe the callback to both events */ + .globalEventMask = RF_GlobalEventRadioSetup | RF_GlobalEventRadioPowerDown +}; + +/* + * =============================== SD =============================== + */ +#include +#include + +#if TI_SD_CONF_ENABLE + +#if !(TI_SPI_CONF_SPI0_ENABLE) +#error "SD driver requires SPI0 enabled" +#endif + +SDSPI_Object sdspiObjects[CC1352P_2_LAUNCHXL_SDCOUNT]; + +const SDSPI_HWAttrs sdspiHWAttrs[CC1352P_2_LAUNCHXL_SDCOUNT] = { + { + .spiIndex = CC1352P_2_LAUNCHXL_SPI0, + .spiCsGpioIndex = CC1352P_2_LAUNCHXL_GPIO_DIO_19 + } +}; + +const SD_Config SD_config[CC1352P_2_LAUNCHXL_SDCOUNT] = { + { + .fxnTablePtr = &SDSPI_fxnTable, + .object = &sdspiObjects[CC1352P_2_LAUNCHXL_SDSPI0], + .hwAttrs = &sdspiHWAttrs[CC1352P_2_LAUNCHXL_SDSPI0] + }, +}; + +const uint_least8_t SD_count = CC1352P_2_LAUNCHXL_SDCOUNT; + +#endif /* TI_SD_CONF_ENABLE */ + +/* + * =============================== SPI DMA =============================== + */ +#include +#include + +#if TI_SPI_CONF_ENABLE + +SPICC26XXDMA_Object spiCC26XXDMAObjects[CC1352P_2_LAUNCHXL_SPICOUNT]; + +/* + * NOTE: The SPI instances below can be used by the SD driver to communicate + * with a SD card via SPI. The 'defaultTxBufValue' fields below are set to 0xFF + * to satisfy the SDSPI driver requirement. + */ +const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[CC1352P_2_LAUNCHXL_SPICOUNT] = { +#if TI_SPI_CONF_SPI0_ENABLE + { + .baseAddr = SSI0_BASE, + .intNum = INT_SSI0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .powerMngrId = PowerCC26XX_PERIPH_SSI0, + .defaultTxBufValue = 0xFF, + .rxChannelBitMask = 1< +#include + +TRNGCC26X2_Object trngCC26X2Object[CC1352P_2_LAUNCHXL_TRNGCOUNT]; + +const TRNGCC26X2_HWAttrs trngCC26X2HWAttrs[CC1352P_2_LAUNCHXL_TRNGCOUNT] = { + { + .swiPriority = 0, + .intPriority = ~0, + } +}; + +const TRNG_Config TRNG_config[] = { + { &trngCC26X2Object[0], &trngCC26X2HWAttrs[0] }, +}; + +const uint8_t TRNG_count = CC1352P_2_LAUNCHXL_TRNGCOUNT; + + +/* + * =============================== UART =============================== + */ +#include +#include + +#if TI_UART_CONF_ENABLE + +UARTCC26XX_Object uartCC26XXObjects[CC1352P_2_LAUNCHXL_UARTCOUNT]; + +uint8_t uartCC26XXRingBuffer[CC1352P_2_LAUNCHXL_UARTCOUNT][32]; + +const UARTCC26XX_HWAttrsV2 uartCC26XXHWAttrs[CC1352P_2_LAUNCHXL_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .baseAddr = UART0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UART0, + .intNum = INT_UART0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .txPin = CC1352P_2_LAUNCHXL_UART0_TX, + .rxPin = CC1352P_2_LAUNCHXL_UART0_RX, + .ctsPin = PIN_UNASSIGNED, + .rtsPin = PIN_UNASSIGNED, + .ringBufPtr = uartCC26XXRingBuffer[CC1352P_2_LAUNCHXL_UART0], + .ringBufSize = sizeof(uartCC26XXRingBuffer[CC1352P_2_LAUNCHXL_UART0]), + .txIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_1_8, + .rxIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_4_8, + .errorFxn = NULL + }, +#endif +#if TI_UART_CONF_UART1_ENABLE + { + .baseAddr = UART1_BASE, + .powerMngrId = PowerCC26X2_PERIPH_UART1, + .intNum = INT_UART1_COMB, + .intPriority = ~0, + .swiPriority = 0, + .txPin = CC1352P_2_LAUNCHXL_UART1_TX, + .rxPin = CC1352P_2_LAUNCHXL_UART1_RX, + .ctsPin = PIN_UNASSIGNED, + .rtsPin = PIN_UNASSIGNED, + .ringBufPtr = uartCC26XXRingBuffer[CC1352P_2_LAUNCHXL_UART1], + .ringBufSize = sizeof(uartCC26XXRingBuffer[CC1352P_2_LAUNCHXL_UART1]), + .txIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_1_8, + .rxIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_4_8, + .errorFxn = NULL + }, +#endif +}; + +const UART_Config UART_config[CC1352P_2_LAUNCHXL_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .fxnTablePtr = &UARTCC26XX_fxnTable, + .object = &uartCC26XXObjects[CC1352P_2_LAUNCHXL_UART0], + .hwAttrs = &uartCC26XXHWAttrs[CC1352P_2_LAUNCHXL_UART0] + }, +#endif +#if TI_UART_CONF_UART1_ENABLE + { + .fxnTablePtr = &UARTCC26XX_fxnTable, + .object = &uartCC26XXObjects[CC1352P_2_LAUNCHXL_UART1], + .hwAttrs = &uartCC26XXHWAttrs[CC1352P_2_LAUNCHXL_UART1] + }, +#endif +}; + +const uint_least8_t UART_count = CC1352P_2_LAUNCHXL_UARTCOUNT; + +#endif /* TI_UART_CONF_ENABLE */ + +/* + * =============================== UDMA =============================== + */ +#include + +UDMACC26XX_Object udmaObjects[CC1352P_2_LAUNCHXL_UDMACOUNT]; + +const UDMACC26XX_HWAttrs udmaHWAttrs[CC1352P_2_LAUNCHXL_UDMACOUNT] = { + { + .baseAddr = UDMA0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UDMA, + .intNum = INT_DMA_ERR, + .intPriority = ~0 + } +}; + +const UDMACC26XX_Config UDMACC26XX_config[CC1352P_2_LAUNCHXL_UDMACOUNT] = { + { + .object = &udmaObjects[CC1352P_2_LAUNCHXL_UDMA0], + .hwAttrs = &udmaHWAttrs[CC1352P_2_LAUNCHXL_UDMA0] + }, +}; + + + +/* + * =============================== Watchdog =============================== + */ +#include +#include + +WatchdogCC26XX_Object watchdogCC26XXObjects[CC1352P_2_LAUNCHXL_WATCHDOGCOUNT]; + +const WatchdogCC26XX_HWAttrs watchdogCC26XXHWAttrs[CC1352P_2_LAUNCHXL_WATCHDOGCOUNT] = { + { + .baseAddr = WDT_BASE, + .reloadValue = 1000 /* Reload value in milliseconds */ + }, +}; + +const Watchdog_Config Watchdog_config[CC1352P_2_LAUNCHXL_WATCHDOGCOUNT] = { + { + .fxnTablePtr = &WatchdogCC26XX_fxnTable, + .object = &watchdogCC26XXObjects[CC1352P_2_LAUNCHXL_WATCHDOG0], + .hwAttrs = &watchdogCC26XXHWAttrs[CC1352P_2_LAUNCHXL_WATCHDOG0] + }, +}; + +const uint_least8_t Watchdog_count = CC1352P_2_LAUNCHXL_WATCHDOGCOUNT; + +/* + * Board-specific initialization function to disable external flash. + * This function is defined in the file CC1352P_2_LAUNCHXL_fxns.c + */ +extern void Board_initHook(void); + +/* + * ======== CC1352P_2_LAUNCHXL_initGeneral ======== + */ +void CC1352P_2_LAUNCHXL_initGeneral(void) +{ + Power_init(); + + if (PIN_init(BoardGpioInitTable) != PIN_SUCCESS) { + /* Error with PIN_init */ + while (1); + } + + /* Perform board-specific initialization */ + Board_initHook(); +} diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/CC1352P_2_LAUNCHXL.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/CC1352P_2_LAUNCHXL.h new file mode 100644 index 000000000..a3defe845 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/CC1352P_2_LAUNCHXL.h @@ -0,0 +1,452 @@ +/* + * Copyright (c) 2017-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 CC1352P_2_LAUNCHXL.h + * + * @brief CC1352P_2_LAUNCHXL Board Specific header file. + * + * The CC1352P_2_LAUNCHXL header file should be included in an application as + * follows: + * @code + * #include "CC1352P_2_LAUNCHXL.h" + * @endcode + * + * =========================================================================== + */ +#ifndef __CC1352P_2_LAUNCHXL_BOARD_H__ +#define __CC1352P_2_LAUNCHXL_BOARD_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "contiki-conf.h" + +/* Includes */ +#include +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) + +/* Externs */ +extern const PIN_Config BoardGpioInitTable[]; + +/* Defines */ +#define CC1352P_2_LAUNCHXL + +/* Mapping of pins to board signals using general board aliases + * + */ + +/* Mapping of pins to board signals using general board aliases + * + */ +/* Analog Capable DIOs */ +#define CC1352P_2_LAUNCHXL_DIO23_ANALOG IOID_23 +#define CC1352P_2_LAUNCHXL_DIO24_ANALOG IOID_24 +#define CC1352P_2_LAUNCHXL_DIO25_ANALOG IOID_25 +#define CC1352P_2_LAUNCHXL_DIO26_ANALOG IOID_26 +#define CC1352P_2_LAUNCHXL_DIO27_ANALOG IOID_27 + +/* RF Antenna Switch */ +#define CC1352P_2_LAUNCHXL_DIO28_RF_24GHZ IOID_28 +#define CC1352P_2_LAUNCHXL_DIO29_RF_HIGH_PA IOID_29 +#define CC1352P_2_LAUNCHXL_DIO30_RF_SUB1GHZ IOID_30 + +/* Digital IOs */ +#define CC1352P_2_LAUNCHXL_DIO12 IOID_12 +#define CC1352P_2_LAUNCHXL_DIO15 IOID_15 +#define CC1352P_2_LAUNCHXL_DIO16_TDO IOID_16 +#define CC1352P_2_LAUNCHXL_DIO17_TDI IOID_17 +#define CC1352P_2_LAUNCHXL_DIO21 IOID_21 +#define CC1352P_2_LAUNCHXL_DIO22 IOID_22 + +/* Discrete Inputs */ +#define CC1352P_2_LAUNCHXL_PIN_BTN1 IOID_15 +#define CC1352P_2_LAUNCHXL_PIN_BTN2 IOID_14 + +/* GPIO */ +#define CC1352P_2_LAUNCHXL_GPIO_LED_ON 1 +#define CC1352P_2_LAUNCHXL_GPIO_LED_OFF 0 + +/* I2C */ +#define CC1352P_2_LAUNCHXL_I2C0_SCL0 IOID_22 +#define CC1352P_2_LAUNCHXL_I2C0_SDA0 IOID_5 + +/* LEDs */ +#define CC1352P_2_LAUNCHXL_PIN_LED_ON 1 +#define CC1352P_2_LAUNCHXL_PIN_LED_OFF 0 +#define CC1352P_2_LAUNCHXL_PIN_RLED IOID_6 +#define CC1352P_2_LAUNCHXL_PIN_GLED IOID_7 + +/* PWM Outputs */ +#define CC1352P_2_LAUNCHXL_PWMPIN0 CC1352P_2_LAUNCHXL_PIN_RLED +#define CC1352P_2_LAUNCHXL_PWMPIN1 CC1352P_2_LAUNCHXL_PIN_GLED +#define CC1352P_2_LAUNCHXL_PWMPIN2 PIN_UNASSIGNED +#define CC1352P_2_LAUNCHXL_PWMPIN3 PIN_UNASSIGNED +#define CC1352P_2_LAUNCHXL_PWMPIN4 PIN_UNASSIGNED +#define CC1352P_2_LAUNCHXL_PWMPIN5 PIN_UNASSIGNED +#define CC1352P_2_LAUNCHXL_PWMPIN6 PIN_UNASSIGNED +#define CC1352P_2_LAUNCHXL_PWMPIN7 PIN_UNASSIGNED + +/* SPI */ +#define CC1352P_2_LAUNCHXL_SPI_FLASH_CS IOID_20 +#define CC1352P_2_LAUNCHXL_FLASH_CS_ON 0 +#define CC1352P_2_LAUNCHXL_FLASH_CS_OFF 1 + +/* SPI Board */ +#define CC1352P_2_LAUNCHXL_SPI0_MISO IOID_8 /* RF1.20 */ +#define CC1352P_2_LAUNCHXL_SPI0_MOSI IOID_9 /* RF1.18 */ +#define CC1352P_2_LAUNCHXL_SPI0_CLK IOID_10 /* RF1.16 */ +#define CC1352P_2_LAUNCHXL_SPI0_CSN PIN_UNASSIGNED +#define CC1352P_2_LAUNCHXL_SPI1_MISO PIN_UNASSIGNED +#define CC1352P_2_LAUNCHXL_SPI1_MOSI PIN_UNASSIGNED +#define CC1352P_2_LAUNCHXL_SPI1_CLK PIN_UNASSIGNED +#define CC1352P_2_LAUNCHXL_SPI1_CSN PIN_UNASSIGNED + +/* UART Board */ +#define CC1352P_2_LAUNCHXL_UART0_RX IOID_12 /* RXD */ +#define CC1352P_2_LAUNCHXL_UART0_TX IOID_13 /* TXD */ +#define CC1352P_2_LAUNCHXL_UART0_CTS IOID_19 /* CTS */ +#define CC1352P_2_LAUNCHXL_UART0_RTS IOID_18 /* RTS */ +#define CC1352P_2_LAUNCHXL_UART1_RX PIN_UNASSIGNED +#define CC1352P_2_LAUNCHXL_UART1_TX PIN_UNASSIGNED +#define CC1352P_2_LAUNCHXL_UART1_CTS PIN_UNASSIGNED +#define CC1352P_2_LAUNCHXL_UART1_RTS PIN_UNASSIGNED +/* For backward compatibility */ +#define CC1352P_2_LAUNCHXL_UART_RX CC1352P_2_LAUNCHXL_UART0_RX +#define CC1352P_2_LAUNCHXL_UART_TX CC1352P_2_LAUNCHXL_UART0_TX +#define CC1352P_2_LAUNCHXL_UART_CTS CC1352P_2_LAUNCHXL_UART0_CTS +#define CC1352P_2_LAUNCHXL_UART_RTS CC1352P_2_LAUNCHXL_UART0_RTS + +/*! + * @brief Initialize the general board specific settings + * + * This function initializes the general board specific settings. + */ +void CC1352P_2_LAUNCHXL_initGeneral(void); + +/*! + * @brief Shut down the external flash present on the board files + * + * This function bitbangs the SPI sequence necessary to turn off + * the external flash on LaunchPads. + */ +void CC1352P_2_LAUNCHXL_shutDownExtFlash(void); + +/*! + * @brief Wake up the external flash present on the board files + * + * This function toggles the chip select for the amount of time needed + * to wake the chip up. + */ +void CC1352P_2_LAUNCHXL_wakeUpExtFlash(void); + + +/*! + * \brief Initializes the antenna switch IOs. + * + * This function sets up the antenna switch and occupies + * the necessary IO pins. After calling this function, they + * cannot be used in the application anymore. + */ +void CC1352P_2_LAUNCHXL_initAntennaSwitch(void); + +/*! + * @def CC1352P_2_LAUNCHXL_ADCBufName + * @brief Enum of ADCs + */ +typedef enum CC1352P_2_LAUNCHXL_ADCBufName { + CC1352P_2_LAUNCHXL_ADCBUF0 = 0, + + CC1352P_2_LAUNCHXL_ADCBUFCOUNT +} CC1352P_2_LAUNCHXL_ADCBufName; + +/*! + * @def CC1352P_2_LAUNCHXL_ADCBuf0ChannelName + * @brief Enum of ADCBuf channels + */ +typedef enum CC1352P_2_LAUNCHXL_ADCBuf0ChannelName { + CC1352P_2_LAUNCHXL_ADCBUF0CHANNEL0 = 0, + CC1352P_2_LAUNCHXL_ADCBUF0CHANNEL1, + CC1352P_2_LAUNCHXL_ADCBUF0CHANNEL2, + CC1352P_2_LAUNCHXL_ADCBUF0CHANNEL3, + CC1352P_2_LAUNCHXL_ADCBUF0CHANNEL4, + CC1352P_2_LAUNCHXL_ADCBUF0CHANNELVDDS, + CC1352P_2_LAUNCHXL_ADCBUF0CHANNELDCOUPL, + CC1352P_2_LAUNCHXL_ADCBUF0CHANNELVSS, + + CC1352P_2_LAUNCHXL_ADCBUF0CHANNELCOUNT +} CC1352P_2_LAUNCHXL_ADCBuf0ChannelName; + +/*! + * @def CC1352P_2_LAUNCHXL_ADCName + * @brief Enum of ADCs + */ +typedef enum CC1352P_2_LAUNCHXL_ADCName { + CC1352P_2_LAUNCHXL_ADC0 = 0, + CC1352P_2_LAUNCHXL_ADC1, + CC1352P_2_LAUNCHXL_ADC2, + CC1352P_2_LAUNCHXL_ADC3, + CC1352P_2_LAUNCHXL_ADC4, + CC1352P_2_LAUNCHXL_ADCDCOUPL, + CC1352P_2_LAUNCHXL_ADCVSS, + CC1352P_2_LAUNCHXL_ADCVDDS, + + CC1352P_2_LAUNCHXL_ADCCOUNT +} CC1352P_2_LAUNCHXL_ADCName; + +/*! + * @def CC1352P_2_LAUNCHXL_ECDHName + * @brief Enum of ECDH names + */ +typedef enum CC1352P_2_LAUNCHXL_ECDHName { + CC1352P_2_LAUNCHXL_ECDH0 = 0, + + CC1352P_2_LAUNCHXL_ECDHCOUNT +} CC1352P_2_LAUNCHXL_ECDHName; + +/*! + * @def CC1352P_2_LAUNCHXL_ECDSAName + * @brief Enum of ECDSA names + */ +typedef enum CC1352P_2_LAUNCHXL_ECDSAName { + CC1352P_2_LAUNCHXL_ECDSA0 = 0, + + CC1352P_2_LAUNCHXL_ECDSACOUNT +} CC1352P_2_LAUNCHXL_ECDSAName; + +/*! + * @def CC1352P_2_LAUNCHXL_ECJPAKEName + * @brief Enum of ECJPAKE names + */ +typedef enum CC1352P_2_LAUNCHXL_ECJPAKEName { + CC1352P_2_LAUNCHXL_ECJPAKE0 = 0, + + CC1352P_2_LAUNCHXL_ECJPAKECOUNT +} CC1352P_2_LAUNCHXL_ECJPAKEName; + +/*! + * @def CC1352P_2_LAUNCHXL_AESCCMName + * @brief Enum of AESCCM names + */ +typedef enum CC1352P_2_LAUNCHXL_AESCCMName { + CC1352P_2_LAUNCHXL_AESCCM0 = 0, + + CC1352P_2_LAUNCHXL_AESCCMCOUNT +} CC1352P_2_LAUNCHXL_AESCCMName; + +/*! + * @def CC1352P_2_LAUNCHXL_AESECBName + * @brief Enum of AESECB names + */ +typedef enum CC1352P_2_LAUNCHXL_AESECBName { + CC1352P_2_LAUNCHXL_AESECB0 = 0, + + CC1352P_2_LAUNCHXL_AESECBCOUNT +} CC1352P_2_LAUNCHXL_AESECBName; + +/*! + * @def CC1352P_2_LAUNCHXL_SHA2Name + * @brief Enum of SHA2 names + */ +typedef enum CC1352P_2_LAUNCHXL_SHA2Name { + CC1352P_2_LAUNCHXL_SHA20 = 0, + + CC1352P_2_LAUNCHXL_SHA2COUNT +} CC1352P_2_LAUNCHXL_SHA2Name; + +/*! + * @def CC1352P_2_LAUNCHXL_GPIOName + * @brief Enum of GPIO names + */ +typedef enum CC1352P_2_LAUNCHXL_GPIOName { + CC1352P_2_LAUNCHXL_GPIO_S1 = 0, + CC1352P_2_LAUNCHXL_GPIO_S2, + CC1352P_2_LAUNCHXL_SPI_MASTER_READY, + CC1352P_2_LAUNCHXL_SPI_SLAVE_READY, + CC1352P_2_LAUNCHXL_GPIO_LED_GREEN, + CC1352P_2_LAUNCHXL_GPIO_LED_RED, + CC1352P_2_LAUNCHXL_GPIO_SPI_FLASH_CS, + CC1352P_2_LAUNCHXL_GPIO_SDSPI_CS, + CC1352P_2_LAUNCHXL_GPIOCOUNT +} CC1352P_2_LAUNCHXL_GPIOName; + +/*! + * @def CC1352P_2_LAUNCHXL_GPTimerName + * @brief Enum of GPTimer parts + */ +typedef enum CC1352P_2_LAUNCHXL_GPTimerName { + CC1352P_2_LAUNCHXL_GPTIMER0A = 0, + CC1352P_2_LAUNCHXL_GPTIMER0B, + CC1352P_2_LAUNCHXL_GPTIMER1A, + CC1352P_2_LAUNCHXL_GPTIMER1B, + CC1352P_2_LAUNCHXL_GPTIMER2A, + CC1352P_2_LAUNCHXL_GPTIMER2B, + CC1352P_2_LAUNCHXL_GPTIMER3A, + CC1352P_2_LAUNCHXL_GPTIMER3B, + + CC1352P_2_LAUNCHXL_GPTIMERPARTSCOUNT +} CC1352P_2_LAUNCHXL_GPTimerName; + +/*! + * @def CC1352P_2_LAUNCHXL_GPTimers + * @brief Enum of GPTimers + */ +typedef enum CC1352P_2_LAUNCHXL_GPTimers { + CC1352P_2_LAUNCHXL_GPTIMER0 = 0, + CC1352P_2_LAUNCHXL_GPTIMER1, + CC1352P_2_LAUNCHXL_GPTIMER2, + CC1352P_2_LAUNCHXL_GPTIMER3, + + CC1352P_2_LAUNCHXL_GPTIMERCOUNT +} CC1352P_2_LAUNCHXL_GPTimers; + +/*! + * @def CC1352P_2_LAUNCHXL_I2CName + * @brief Enum of I2C names + */ +typedef enum CC1352P_2_LAUNCHXL_I2CName { +#if TI_I2C_CONF_I2C0_ENABLE + CC1352P_2_LAUNCHXL_I2C0 = 0, +#endif + + CC1352P_2_LAUNCHXL_I2CCOUNT +} CC1352P_2_LAUNCHXL_I2CName; + +/*! + * @def CC1352P_2_LAUNCHXL_NVSName + * @brief Enum of NVS names + */ +typedef enum CC1352P_2_LAUNCHXL_NVSName { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + CC1352P_2_LAUNCHXL_NVSCC26XX0 = 0, +#endif +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + CC1352P_2_LAUNCHXL_NVSSPI25X0, +#endif + + CC1352P_2_LAUNCHXL_NVSCOUNT +} CC1352P_2_LAUNCHXL_NVSName; + +/*! + * @def CC1352P_2_LAUNCHXL_PWMName + * @brief Enum of PWM outputs + */ +typedef enum CC1352P_2_LAUNCHXL_PWMName { + CC1352P_2_LAUNCHXL_PWM0 = 0, + CC1352P_2_LAUNCHXL_PWM1, + CC1352P_2_LAUNCHXL_PWM2, + CC1352P_2_LAUNCHXL_PWM3, + CC1352P_2_LAUNCHXL_PWM4, + CC1352P_2_LAUNCHXL_PWM5, + CC1352P_2_LAUNCHXL_PWM6, + CC1352P_2_LAUNCHXL_PWM7, + + CC1352P_2_LAUNCHXL_PWMCOUNT +} CC1352P_2_LAUNCHXL_PWMName; + +/*! + * @def CC1352P_2_LAUNCHXL_SDName + * @brief Enum of SD names + */ +typedef enum CC1352P_2_LAUNCHXL_SDName { + CC1352P_2_LAUNCHXL_SDSPI0 = 0, + + CC1352P_2_LAUNCHXL_SDCOUNT +} CC1352P_2_LAUNCHXL_SDName; + +/*! + * @def CC1352P_2_LAUNCHXL_SPIName + * @brief Enum of SPI names + */ +typedef enum CC1352P_2_LAUNCHXL_SPIName { +#if TI_SPI_CONF_SPI0_ENABLE + CC1352P_2_LAUNCHXL_SPI0 = 0, +#endif +#if TI_SPI_CONF_SPI1_ENABLE + CC1352P_2_LAUNCHXL_SPI1, +#endif + + CC1352P_2_LAUNCHXL_SPICOUNT +} CC1352P_2_LAUNCHXL_SPIName; + +/*! + * @def CC1352P_2_LAUNCHXL_TRNGName + * @brief Enum of TRNGs + */ +typedef enum CC1352P_2_LAUNCHXL_TRNGName { + CC1352P_2_LAUNCHXL_TRNG0 = 0, + + CC1352P_2_LAUNCHXL_TRNGCOUNT +} CC1352P_2_LAUNCHXL_TRNGName; + +/*! + * @def CC1352P_2_LAUNCHXL_UARTName + * @brief Enum of UARTs + */ +typedef enum CC1352P_2_LAUNCHXL_UARTName { +#if TI_UART_CONF_UART0_ENABLE + CC1352P_2_LAUNCHXL_UART0 = 0, +#endif +#if TI_UART_CONF_UART1_ENABLE + CC1352P_2_LAUNCHXL_UART1, +#endif + + CC1352P_2_LAUNCHXL_UARTCOUNT +} CC1352P_2_LAUNCHXL_UARTName; + +/*! + * @def CC1352P_2_LAUNCHXL_UDMAName + * @brief Enum of DMA buffers + */ +typedef enum CC1352P_2_LAUNCHXL_UDMAName { + CC1352P_2_LAUNCHXL_UDMA0 = 0, + + CC1352P_2_LAUNCHXL_UDMACOUNT +} CC1352P_2_LAUNCHXL_UDMAName; + +/*! + * @def CC1352P_2_LAUNCHXL_WatchdogName + * @brief Enum of Watchdogs + */ +typedef enum CC1352P_2_LAUNCHXL_WatchdogName { + CC1352P_2_LAUNCHXL_WATCHDOG0 = 0, + + CC1352P_2_LAUNCHXL_WATCHDOGCOUNT +} CC1352P_2_LAUNCHXL_WatchdogName; + + +#ifdef __cplusplus +} +#endif + +#endif /* __CC1352P_2_LAUNCHXL_BOARD_H__ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/CC1352P_2_LAUNCHXL_fxns.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/CC1352P_2_LAUNCHXL_fxns.c new file mode 100644 index 000000000..f8b4930c8 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/CC1352P_2_LAUNCHXL_fxns.c @@ -0,0 +1,256 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +/* + * ======== CC1352P_2_LAUNCHXL_fxns.c ======== + * This file contains the board-specific initialization functions, and + * RF callback function for antenna switching. + */ + +#include +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/cpu.h) +#include +#include + +#include "Board.h" + +/* + * ======== CC1352P_2_LAUNCHXL_sendExtFlashByte ======== + */ +void CC1352P_2_LAUNCHXL_sendExtFlashByte(PIN_Handle pinHandle, uint8_t byte) +{ + uint8_t i; + + /* SPI Flash CS */ + PIN_setOutputValue(pinHandle, IOID_20, 0); + + for (i = 0; i < 8; i++) { + PIN_setOutputValue(pinHandle, IOID_10, 0); /* SPI Flash CLK */ + + /* SPI Flash MOSI */ + PIN_setOutputValue(pinHandle, IOID_9, (byte >> (7 - i)) & 0x01); + PIN_setOutputValue(pinHandle, IOID_10, 1); /* SPI Flash CLK */ + + /* + * Waste a few cycles to keep the CLK high for at + * least 45% of the period. + * 3 cycles per loop: 8 loops @ 48 Mhz = 0.5 us. + */ + CPUdelay(8); + } + + PIN_setOutputValue(pinHandle, IOID_10, 0); /* CLK */ + PIN_setOutputValue(pinHandle, IOID_20, 1); /* CS */ + + /* + * Keep CS high at least 40 us + * 3 cycles per loop: 700 loops @ 48 Mhz ~= 44 us + */ + CPUdelay(700); +} + +/* + * ======== CC1352P_2_LAUNCHXL_wakeUpExtFlash ======== + */ +void CC1352P_2_LAUNCHXL_wakeUpExtFlash(void) +{ + PIN_Config extFlashPinTable[] = { + /* SPI Flash CS */ + IOID_20 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + PIN_TERMINATE + }; + PIN_State extFlashPinState; + PIN_Handle extFlashPinHandle = PIN_open(&extFlashPinState, extFlashPinTable); + + /* + * To wake up we need to toggle the chip select at + * least 20 ns and ten wait at least 35 us. + */ + + /* Toggle chip select for ~20ns to wake ext. flash */ + PIN_setOutputValue(extFlashPinHandle, IOID_20, 0); + /* 3 cycles per loop: 1 loop @ 48 Mhz ~= 62 ns */ + CPUdelay(1); + PIN_setOutputValue(extFlashPinHandle, IOID_20, 1); + /* 3 cycles per loop: 560 loops @ 48 Mhz ~= 35 us */ + CPUdelay(560); + + PIN_close(extFlashPinHandle); +} + +/* + * ======== CC1352P_2_LAUNCHXL_shutDownExtFlash ======== + */ +void CC1352P_2_LAUNCHXL_shutDownExtFlash(void) +{ + /* To be sure we are putting the flash into sleep and not waking it, we first have to make a wake up call */ + CC1352P_2_LAUNCHXL_wakeUpExtFlash(); + + PIN_Config extFlashPinTable[] = { + /* SPI Flash CS*/ + IOID_20 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash CLK */ + IOID_10 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash MOSI */ + IOID_9 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash MISO */ + IOID_8 | PIN_INPUT_EN | PIN_PULLDOWN, + PIN_TERMINATE + }; + PIN_State extFlashPinState; + PIN_Handle extFlashPinHandle = PIN_open(&extFlashPinState, extFlashPinTable); + + uint8_t extFlashShutdown = 0xB9; + + CC1352P_2_LAUNCHXL_sendExtFlashByte(extFlashPinHandle, extFlashShutdown); + + PIN_close(extFlashPinHandle); +} + +/* + * For the SysConfig generated Board.h file, Board_RF_SUB1GHZ will not be + * defined unless the RF module is added to the configuration. Therefore, + * we don't include this code if Board_RF_SUB1GHZ is not defined. + */ +#if defined(Board_RF_SUB1GHZ) + +/* + * ======== Antenna switching ======== + */ +static PIN_Handle antennaPins; +static PIN_State antennaState; + +void initAntennaSwitch() +{ + PIN_Config antennaConfig[] = { + Board_RF_24GHZ | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* Path disabled */ + Board_RF_HIGH_PA | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* Path disabled */ + Board_RF_SUB1GHZ | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* Path disabled */ + PIN_TERMINATE + }; + antennaPins = PIN_open(&antennaState, antennaConfig); +} + +/* + * ======== rfDriverCallback ======== + * Sets up the antenna switch depending on the current PHY configuration. + * Truth table: + * + * Path DIO28 DIO29 DIO30 + * =========== ===== ===== ===== + * Off 0 0 0 + * Sub-1 GHz 0 0 1 + * 2.4 GHz 1 0 0 + * 20 dBm TX 0 1 0 + */ +void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg) +{ + /* Switch off all paths first. Needs to be done anyway in every sub-case below. */ + PINCC26XX_setOutputValue(Board_RF_24GHZ, 0); + PINCC26XX_setOutputValue(Board_RF_HIGH_PA, 0); + PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 0); + + if (events & RF_GlobalEventRadioSetup) { + /* Decode the current PA configuration. */ + RF_TxPowerTable_PAType paType = (RF_TxPowerTable_PAType)RF_getTxPower(client).paType; + + /* Decode the generic argument as a setup command. */ + RF_RadioSetup* setupCommand = (RF_RadioSetup*)arg; + + if (setupCommand->common.commandNo == CMD_PROP_RADIO_DIV_SETUP) { + /* Sub-1 GHz */ + if (paType == RF_TxPowerTable_HighPA) { + /* PA enable --> HIGH PA + * LNA enable --> Sub-1 GHz + */ + PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_GPIO); + // Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not + // de-asserted on CC1352 Rev A. + PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_RFC_GPO3); + PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_RFC_GPO0); + } else { + /* RF core active --> Sub-1 GHz */ + PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_GPIO); + PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_GPIO); + PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_GPIO); + PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 1); + } + } else { + /* 2.4 GHz */ + if (paType == RF_TxPowerTable_HighPA) + { + /* PA enable --> HIGH PA + * LNA enable --> 2.4 GHz + */ + PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_RFC_GPO0); + // Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not + // de-asserted on CC1352 Rev A. + PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_RFC_GPO3); + PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_GPIO); + } else { + /* RF core active --> 2.4 GHz */ + PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_GPIO); + PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_GPIO); + PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_GPIO); + PINCC26XX_setOutputValue(Board_RF_24GHZ, 1); + } + } + } else { + /* Reset the IO multiplexer to GPIO functionality */ + PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_GPIO); + PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_GPIO); + PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_GPIO); + } +} +#endif + +/* + * ======== Board_initHook ======== + * Called by Board_init() to perform board-specific initialization. + */ +void Board_initHook() +{ +#if defined(Board_RF_SUB1GHZ) + initAntennaSwitch(); +#endif + + CC1352P_2_LAUNCHXL_shutDownExtFlash(); +} diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/Makefile.cc1352p-2 b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/Makefile.cc1352p-2 new file mode 100644 index 000000000..2a31100d4 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-2/Makefile.cc1352p-2 @@ -0,0 +1,21 @@ +################################################################################ +# SimpleLink Device makefile + +SUBFAMILY = cc13x2-cc26x2 +DEVICE_FAMILY = CC13X2 +DEVICE_LINE = CC13XX +DEVICE = CC1352P + +BOARD_SOURCEFILES += CC1352P_2_LAUNCHXL.c CC1352P_2_LAUNCHXL_fxns.c + +SUPPORTS_PROP_MODE = 1 +SUPPORTS_IEEE_MODE = 1 +SUPPORTS_BLE_BEACON = 1 + +SUPPORTS_HIGH_PA = 1 + +### Signal that we can be programmed with cc2538-bsl +BOARD_SUPPORTS_BSL = 0 + +# Include the common board makefile +include $(FAMILY_PATH)/launchpad/Makefile.launchpad diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/Board.h new file mode 100644 index 000000000..381651708 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/Board.h @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2017-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 __BOARD_H +#define __BOARD_H + +#define Board_CC1352P_4_LAUNCHXL +#define BOARD_STRING "TI CC1352P-4 LaunchPad" + +#ifdef __cplusplus +extern "C" { +#endif + +#include "CC1352P_4_LAUNCHXL.h" + +#define Board_initGeneral() CC1352P_4_LAUNCHXL_initGeneral() +#define Board_shutDownExtFlash() CC1352P_4_LAUNCHXL_shutDownExtFlash() +#define Board_wakeUpExtFlash() CC1352P_4_LAUNCHXL_wakeUpExtFlash() + +/* These #defines allow us to reuse TI-RTOS across other device families */ + +#define Board_ADC0 CC1352P_4_LAUNCHXL_ADC0 +#define Board_ADC1 CC1352P_4_LAUNCHXL_ADC1 + +#define Board_ADCBUF0 CC1352P_4_LAUNCHXL_ADCBUF0 +#define Board_ADCBUF0CHANNEL0 CC1352P_4_LAUNCHXL_ADCBUF0CHANNEL0 +#define Board_ADCBUF0CHANNEL1 CC1352P_4_LAUNCHXL_ADCBUF0CHANNEL1 + +#define Board_CRYPTO0 CC1352P_4_LAUNCHXL_CRYPTO0 +#define Board_ECDH0 CC1352P_4_LAUNCHXL_ECDH0 +#define Board_ECDSA0 CC1352P_4_LAUNCHXL_ECDSA0 +#define Board_ECJPAKE0 CC1352P_4_LAUNCHXL_ECJPAKE0 +#define Board_AESCCM0 CC1352P_4_LAUNCHXL_AESCCM0 +#define Board_AESECB0 CC1352P_4_LAUNCHXL_AESECB0 +#define Board_SHA20 CC1352P_4_LAUNCHXL_SHA20 + +#define Board_DIO12 CC1352P_4_LAUNCHXL_DIO12 +#define Board_DIO15 CC1352P_4_LAUNCHXL_DIO15 +#define Board_DIO16_TDO CC1352P_4_LAUNCHXL_DIO16_TDO +#define Board_DIO17_TDI CC1352P_4_LAUNCHXL_DIO17_TDI +#define Board_DIO21 CC1352P_4_LAUNCHXL_DIO21 +#define Board_DIO22 CC1352P_4_LAUNCHXL_DIO22 + +#define Board_DIO23_ANALOG CC1352P_4_LAUNCHXL_DIO23_ANALOG +#define Board_DIO24_ANALOG CC1352P_4_LAUNCHXL_DIO24_ANALOG +#define Board_DIO25_ANALOG CC1352P_4_LAUNCHXL_DIO25_ANALOG +#define Board_DIO26_ANALOG CC1352P_4_LAUNCHXL_DIO26_ANALOG +#define Board_DIO27_ANALOG CC1352P_4_LAUNCHXL_DIO27_ANALOG +#define Board_DIO28_ANALOG CC1352P_4_LAUNCHXL_DIO28_ANALOG +#define Board_DIO29_ANALOG CC1352P_4_LAUNCHXL_DIO29_ANALOG +#define Board_DIO30_RFSW CC1352P_4_LAUNCHXL_DIO30_RF_SUB1GHZ + +/* + * Board_RF_SUB1GHZ, Board_RF_HIGH_PA, and Board_RF_24GHZ are the names + * generated by SysConfig. Define them here so that the RF callback function + * can reference them. + */ +#define Board_RF_24GHZ CC1352P_4_LAUNCHXL_DIO28_RF_24GHZ +#define Board_RF_HIGH_PA CC1352P_4_LAUNCHXL_DIO29_RF_HIGH_PA +#define Board_RF_SUB1GHZ CC1352P_4_LAUNCHXL_DIO30_RF_SUB1GHZ + +#define Board_GPIO_BUTTON0 CC1352P_4_LAUNCHXL_GPIO_S1 +#define Board_GPIO_BUTTON1 CC1352P_4_LAUNCHXL_GPIO_S2 +#define Board_GPIO_BTN1 CC1352P_4_LAUNCHXL_GPIO_S1 +#define Board_GPIO_BTN2 CC1352P_4_LAUNCHXL_GPIO_S2 +#define Board_GPIO_LED0 CC1352P_4_LAUNCHXL_GPIO_LED_RED +#define Board_GPIO_LED1 CC1352P_4_LAUNCHXL_GPIO_LED_GREEN +#define Board_GPIO_LED2 CC1352P_4_LAUNCHXL_GPIO_LED_RED +#define Board_GPIO_RLED CC1352P_4_LAUNCHXL_GPIO_LED_RED +#define Board_GPIO_GLED CC1352P_4_LAUNCHXL_GPIO_LED_GREEN +#define Board_GPIO_LED_ON CC1352P_4_LAUNCHXL_GPIO_LED_ON +#define Board_GPIO_LED_OFF CC1352P_4_LAUNCHXL_GPIO_LED_OFF + +#define Board_GPTIMER0A CC1352P_4_LAUNCHXL_GPTIMER0A +#define Board_GPTIMER0B CC1352P_4_LAUNCHXL_GPTIMER0B +#define Board_GPTIMER1A CC1352P_4_LAUNCHXL_GPTIMER1A +#define Board_GPTIMER1B CC1352P_4_LAUNCHXL_GPTIMER1B +#define Board_GPTIMER2A CC1352P_4_LAUNCHXL_GPTIMER2A +#define Board_GPTIMER2B CC1352P_4_LAUNCHXL_GPTIMER2B +#define Board_GPTIMER3A CC1352P_4_LAUNCHXL_GPTIMER3A +#define Board_GPTIMER3B CC1352P_4_LAUNCHXL_GPTIMER3B + +#define Board_I2C0 CC1352P_4_LAUNCHXL_I2C0 +#define Board_I2C_TMP Board_I2C0 + +#define Board_NVSINTERNAL CC1352P_4_LAUNCHXL_NVSCC26XX0 +#define Board_NVSEXTERNAL CC1352P_4_LAUNCHXL_NVSSPI25X0 + +#define Board_PIN_BUTTON0 CC1352P_4_LAUNCHXL_PIN_BTN1 +#define Board_PIN_BUTTON1 CC1352P_4_LAUNCHXL_PIN_BTN2 +#define Board_PIN_BTN1 CC1352P_4_LAUNCHXL_PIN_BTN1 +#define Board_PIN_BTN2 CC1352P_4_LAUNCHXL_PIN_BTN2 +#define Board_PIN_LED0 CC1352P_4_LAUNCHXL_PIN_RLED +#define Board_PIN_LED1 CC1352P_4_LAUNCHXL_PIN_GLED +#define Board_PIN_LED2 CC1352P_4_LAUNCHXL_PIN_RLED +#define Board_PIN_RLED CC1352P_4_LAUNCHXL_PIN_RLED +#define Board_PIN_GLED CC1352P_4_LAUNCHXL_PIN_GLED + +#define Board_PWM0 CC1352P_4_LAUNCHXL_PWM0 +#define Board_PWM1 CC1352P_4_LAUNCHXL_PWM1 +#define Board_PWM2 CC1352P_4_LAUNCHXL_PWM2 +#define Board_PWM3 CC1352P_4_LAUNCHXL_PWM3 +#define Board_PWM4 CC1352P_4_LAUNCHXL_PWM4 +#define Board_PWM5 CC1352P_4_LAUNCHXL_PWM5 +#define Board_PWM6 CC1352P_4_LAUNCHXL_PWM6 +#define Board_PWM7 CC1352P_4_LAUNCHXL_PWM7 + +#define Board_SD0 CC1352P_4_LAUNCHXL_SDSPI0 + +#define Board_SPI0 CC1352P_4_LAUNCHXL_SPI0 +#define Board_SPI0_MISO CC1352P_4_LAUNCHXL_SPI0_MISO +#define Board_SPI0_MOSI CC1352P_4_LAUNCHXL_SPI0_MOSI +#define Board_SPI0_CLK CC1352P_4_LAUNCHXL_SPI0_CLK +#define Board_SPI0_CSN CC1352P_4_LAUNCHXL_SPI0_CSN +#define Board_SPI1 CC1352P_4_LAUNCHXL_SPI1 +#define Board_SPI1_MISO CC1352P_4_LAUNCHXL_SPI1_MISO +#define Board_SPI1_MOSI CC1352P_4_LAUNCHXL_SPI1_MOSI +#define Board_SPI1_CLK CC1352P_4_LAUNCHXL_SPI1_CLK +#define Board_SPI1_CSN CC1352P_4_LAUNCHXL_SPI1_CSN +#define Board_SPI_FLASH_CS CC1352P_4_LAUNCHXL_SPI_FLASH_CS +#define Board_FLASH_CS_ON 0 +#define Board_FLASH_CS_OFF 1 + +#define Board_SPI_MASTER CC1352P_4_LAUNCHXL_SPI0 +#define Board_SPI_SLAVE CC1352P_4_LAUNCHXL_SPI0 +#define Board_SPI_MASTER_READY CC1352P_4_LAUNCHXL_SPI_MASTER_READY +#define Board_SPI_SLAVE_READY CC1352P_4_LAUNCHXL_SPI_SLAVE_READY + +#define Board_UART0 CC1352P_4_LAUNCHXL_UART0 +#define Board_UART1 CC1352P_4_LAUNCHXL_UART1 + +#define Board_WATCHDOG0 CC1352P_4_LAUNCHXL_WATCHDOG0 + +/* Board specific I2C addresses */ +#define Board_TMP_ADDR (0x40) +#define Board_SENSORS_BP_TMP_ADDR Board_TMP_ADDR + +#ifdef __cplusplus +} +#endif + +#endif /* __BOARD_H */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/CC1352P_4_LAUNCHXL.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/CC1352P_4_LAUNCHXL.c new file mode 100644 index 000000000..63a41d64b --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/CC1352P_4_LAUNCHXL.c @@ -0,0 +1,949 @@ +/* + * Copyright (c) 2017-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +/* + * ====================== CC1352P_4_LAUNCHXL.c =================================== + * This file is responsible for setting up the board specific items for the + * CC1352P_4_LAUNCHXL board. + */ + +#include +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/udma.h) +#include DeviceFamily_constructPath(inc/hw_ints.h) +#include DeviceFamily_constructPath(inc/hw_memmap.h) + +#include "CC1352P_4_LAUNCHXL.h" + +/* + * =============================== ADCBuf =============================== + */ +#include +#include + +ADCBufCC26X2_Object adcBufCC26xxObjects[CC1352P_4_LAUNCHXL_ADCBUFCOUNT]; + +/* + * This table converts a virtual adc channel into a dio and internal analogue + * input signal. This table is necessary for the functioning of the adcBuf + * driver. Comment out unused entries to save flash. Dio and internal signal + * pairs are hardwired. Do not remap them in the table. You may reorder entire + * entries. The mapping of dio and internal signals is package dependent. + */ +const ADCBufCC26X2_AdcChannelLutEntry ADCBufCC26X2_adcChannelLut[CC1352P_4_LAUNCHXL_ADCBUF0CHANNELCOUNT] = { + {CC1352P_4_LAUNCHXL_DIO23_ANALOG, ADC_COMPB_IN_AUXIO7}, + {CC1352P_4_LAUNCHXL_DIO24_ANALOG, ADC_COMPB_IN_AUXIO6}, + {CC1352P_4_LAUNCHXL_DIO25_ANALOG, ADC_COMPB_IN_AUXIO5}, + {CC1352P_4_LAUNCHXL_DIO26_ANALOG, ADC_COMPB_IN_AUXIO4}, + {CC1352P_4_LAUNCHXL_DIO27_ANALOG, ADC_COMPB_IN_AUXIO3}, + {PIN_UNASSIGNED, ADC_COMPB_IN_VDDS}, + {PIN_UNASSIGNED, ADC_COMPB_IN_DCOUPL}, + {PIN_UNASSIGNED, ADC_COMPB_IN_VSS}, +}; + +const ADCBufCC26X2_HWAttrs adcBufCC26xxHWAttrs[CC1352P_4_LAUNCHXL_ADCBUFCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + .adcChannelLut = ADCBufCC26X2_adcChannelLut, + .gpTimerUnit = CC1352P_4_LAUNCHXL_GPTIMER0A, + } +}; + +const ADCBuf_Config ADCBuf_config[CC1352P_4_LAUNCHXL_ADCBUFCOUNT] = { + { + &ADCBufCC26X2_fxnTable, + &adcBufCC26xxObjects[CC1352P_4_LAUNCHXL_ADCBUF0], + &adcBufCC26xxHWAttrs[CC1352P_4_LAUNCHXL_ADCBUF0] + }, +}; + +const uint_least8_t ADCBuf_count = CC1352P_4_LAUNCHXL_ADCBUFCOUNT; + +/* + * =============================== ADC =============================== + */ +#include +#include + +ADCCC26XX_Object adcCC26xxObjects[CC1352P_4_LAUNCHXL_ADCCOUNT]; + +const ADCCC26XX_HWAttrs adcCC26xxHWAttrs[CC1352P_4_LAUNCHXL_ADCCOUNT] = { + { + .adcDIO = CC1352P_4_LAUNCHXL_DIO23_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO7, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1352P_4_LAUNCHXL_DIO24_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO6, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1352P_4_LAUNCHXL_DIO25_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO5, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1352P_4_LAUNCHXL_DIO26_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO4, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1352P_4_LAUNCHXL_DIO27_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO3, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_DCOUPL, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_VSS, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_VDDS, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + } +}; + +const ADC_Config ADC_config[CC1352P_4_LAUNCHXL_ADCCOUNT] = { + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352P_4_LAUNCHXL_ADC0], &adcCC26xxHWAttrs[CC1352P_4_LAUNCHXL_ADC0]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352P_4_LAUNCHXL_ADC1], &adcCC26xxHWAttrs[CC1352P_4_LAUNCHXL_ADC1]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352P_4_LAUNCHXL_ADC2], &adcCC26xxHWAttrs[CC1352P_4_LAUNCHXL_ADC2]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352P_4_LAUNCHXL_ADC3], &adcCC26xxHWAttrs[CC1352P_4_LAUNCHXL_ADC3]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352P_4_LAUNCHXL_ADC4], &adcCC26xxHWAttrs[CC1352P_4_LAUNCHXL_ADC4]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352P_4_LAUNCHXL_ADCDCOUPL], &adcCC26xxHWAttrs[CC1352P_4_LAUNCHXL_ADCDCOUPL]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352P_4_LAUNCHXL_ADCVSS], &adcCC26xxHWAttrs[CC1352P_4_LAUNCHXL_ADCVSS]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352P_4_LAUNCHXL_ADCVDDS], &adcCC26xxHWAttrs[CC1352P_4_LAUNCHXL_ADCVDDS]}, +}; + +const uint_least8_t ADC_count = CC1352P_4_LAUNCHXL_ADCCOUNT; + +/* + * =============================== ECDH =============================== + */ +#include +#include + +ECDHCC26X2_Object ecdhCC26X2Objects[CC1352P_4_LAUNCHXL_ECDHCOUNT]; + +const ECDHCC26X2_HWAttrs ecdhCC26X2HWAttrs[CC1352P_4_LAUNCHXL_ECDHCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const ECDH_Config ECDH_config[CC1352P_4_LAUNCHXL_ECDHCOUNT] = { + { + .object = &ecdhCC26X2Objects[CC1352P_4_LAUNCHXL_ECDH0], + .hwAttrs = &ecdhCC26X2HWAttrs[CC1352P_4_LAUNCHXL_ECDH0] + }, +}; + +const uint_least8_t ECDH_count = CC1352P_4_LAUNCHXL_ECDHCOUNT; + +/* + * =============================== ECDSA =============================== + */ +#include +#include + +ECDSACC26X2_Object ecdsaCC26X2Objects[CC1352P_4_LAUNCHXL_ECDSACOUNT]; + +const ECDSACC26X2_HWAttrs ecdsaCC26X2HWAttrs[CC1352P_4_LAUNCHXL_ECDSACOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const ECDSA_Config ECDSA_config[CC1352P_4_LAUNCHXL_ECDSACOUNT] = { + { + .object = &ecdsaCC26X2Objects[CC1352P_4_LAUNCHXL_ECDSA0], + .hwAttrs = &ecdsaCC26X2HWAttrs[CC1352P_4_LAUNCHXL_ECDSA0] + }, +}; + +const uint_least8_t ECDSA_count = CC1352P_4_LAUNCHXL_ECDSACOUNT; + +/* + * =============================== ECJPAKE =============================== + */ +#include +#include + +ECJPAKECC26X2_Object ecjpakeCC26X2Objects[CC1352P_4_LAUNCHXL_ECJPAKECOUNT]; + +const ECJPAKECC26X2_HWAttrs ecjpakeCC26X2HWAttrs[CC1352P_4_LAUNCHXL_ECJPAKECOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const ECJPAKE_Config ECJPAKE_config[CC1352P_4_LAUNCHXL_ECJPAKECOUNT] = { + { + .object = &ecjpakeCC26X2Objects[CC1352P_4_LAUNCHXL_ECJPAKE0], + .hwAttrs = &ecjpakeCC26X2HWAttrs[CC1352P_4_LAUNCHXL_ECJPAKE0] + }, +}; + +const uint_least8_t ECJPAKE_count = CC1352P_4_LAUNCHXL_ECJPAKECOUNT; + + +/* + * =============================== SHA2 =============================== + */ +#include +#include + +SHA2CC26X2_Object sha2CC26X2Objects[CC1352P_4_LAUNCHXL_SHA2COUNT]; + +const SHA2CC26X2_HWAttrs sha2CC26X2HWAttrs[CC1352P_4_LAUNCHXL_SHA2COUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const SHA2_Config SHA2_config[CC1352P_4_LAUNCHXL_SHA2COUNT] = { + { + .object = &sha2CC26X2Objects[CC1352P_4_LAUNCHXL_SHA20], + .hwAttrs = &sha2CC26X2HWAttrs[CC1352P_4_LAUNCHXL_SHA20] + }, +}; + +const uint_least8_t SHA2_count = CC1352P_4_LAUNCHXL_SHA2COUNT; + +/* + * =============================== AESCCM =============================== + */ +#include +#include + +AESCCMCC26XX_Object aesccmCC26XXObjects[CC1352P_4_LAUNCHXL_AESCCMCOUNT]; + +const AESCCMCC26XX_HWAttrs aesccmCC26XXHWAttrs[CC1352P_4_LAUNCHXL_AESCCMCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const AESCCM_Config AESCCM_config[CC1352P_4_LAUNCHXL_AESCCMCOUNT] = { + { + .object = &aesccmCC26XXObjects[CC1352P_4_LAUNCHXL_AESCCM0], + .hwAttrs = &aesccmCC26XXHWAttrs[CC1352P_4_LAUNCHXL_AESCCM0] + }, +}; + +const uint_least8_t AESCCM_count = CC1352P_4_LAUNCHXL_AESCCMCOUNT; + +/* + * =============================== AESECB =============================== + */ +#include +#include + +AESECBCC26XX_Object aesecbCC26XXObjects[CC1352P_4_LAUNCHXL_AESECBCOUNT]; + +const AESECBCC26XX_HWAttrs aesecbCC26XXHWAttrs[CC1352P_4_LAUNCHXL_AESECBCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const AESECB_Config AESECB_config[CC1352P_4_LAUNCHXL_AESECBCOUNT] = { + { + .object = &aesecbCC26XXObjects[CC1352P_4_LAUNCHXL_AESECB0], + .hwAttrs = &aesecbCC26XXHWAttrs[CC1352P_4_LAUNCHXL_AESECB0] + }, +}; + +const uint_least8_t AESECB_count = CC1352P_4_LAUNCHXL_AESECBCOUNT; + +/* + * =============================== GPIO =============================== + */ +#include +#include + +/* + * Array of Pin configurations + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC1352P_4_LAUNCHXL.h + * NOTE: Pins not used for interrupts should be placed at the end of the + * array. Callback entries can be omitted from callbacks array to + * reduce memory usage. + */ +GPIO_PinConfig gpioPinConfigs[] = { + /* Input pins */ + GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG, /* Button 0 */ + GPIOCC26XX_DIO_14 | GPIO_DO_NOT_CONFIG, /* Button 1 */ + + GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG, /* CC1352P_4_LAUNCHXL_SPI_MASTER_READY */ + GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG, /* CC1352P_4_LAUNCHXL_SPI_SLAVE_READY */ + + /* Output pins */ + GPIOCC26XX_DIO_07 | GPIO_DO_NOT_CONFIG, /* Green LED */ + GPIOCC26XX_DIO_06 | GPIO_DO_NOT_CONFIG, /* Red LED */ + + /* SPI Flash CSN */ + GPIOCC26XX_DIO_20 | GPIO_DO_NOT_CONFIG, + + /* SD CS */ + GPIOCC26XX_DIO_19 | GPIO_DO_NOT_CONFIG, +}; + +/* + * Array of callback function pointers + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC1352P_LAUNCH.h + * NOTE: Pins not used for interrupts can be omitted from callbacks array to + * reduce memory usage (if placed at end of gpioPinConfigs array). + */ +GPIO_CallbackFxn gpioCallbackFunctions[] = { + NULL, /* Button 0 */ + NULL, /* Button 1 */ + NULL, /* CC1352P_4_LAUNCHXL_SPI_MASTER_READY */ + NULL, /* CC1352P_4_LAUNCHXL_SPI_SLAVE_READY */ +}; + +const GPIOCC26XX_Config GPIOCC26XX_config = { + .pinConfigs = (GPIO_PinConfig *)gpioPinConfigs, + .callbacks = (GPIO_CallbackFxn *)gpioCallbackFunctions, + .numberOfPinConfigs = CC1352P_4_LAUNCHXL_GPIOCOUNT, + .numberOfCallbacks = sizeof(gpioCallbackFunctions)/sizeof(GPIO_CallbackFxn), + .intPriority = (~0) +}; + +/* + * =============================== GPTimer =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include + +GPTimerCC26XX_Object gptimerCC26XXObjects[CC1352P_4_LAUNCHXL_GPTIMERCOUNT]; + +const GPTimerCC26XX_HWAttrs gptimerCC26xxHWAttrs[CC1352P_4_LAUNCHXL_GPTIMERPARTSCOUNT] = { + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0A, }, + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0B, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1A, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1B, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2A, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2B, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3A, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3B, }, +}; + +const GPTimerCC26XX_Config GPTimerCC26XX_config[CC1352P_4_LAUNCHXL_GPTIMERPARTSCOUNT] = { + { &gptimerCC26XXObjects[CC1352P_4_LAUNCHXL_GPTIMER0], &gptimerCC26xxHWAttrs[CC1352P_4_LAUNCHXL_GPTIMER0A], GPT_A }, + { &gptimerCC26XXObjects[CC1352P_4_LAUNCHXL_GPTIMER0], &gptimerCC26xxHWAttrs[CC1352P_4_LAUNCHXL_GPTIMER0B], GPT_B }, + { &gptimerCC26XXObjects[CC1352P_4_LAUNCHXL_GPTIMER1], &gptimerCC26xxHWAttrs[CC1352P_4_LAUNCHXL_GPTIMER1A], GPT_A }, + { &gptimerCC26XXObjects[CC1352P_4_LAUNCHXL_GPTIMER1], &gptimerCC26xxHWAttrs[CC1352P_4_LAUNCHXL_GPTIMER1B], GPT_B }, + { &gptimerCC26XXObjects[CC1352P_4_LAUNCHXL_GPTIMER2], &gptimerCC26xxHWAttrs[CC1352P_4_LAUNCHXL_GPTIMER2A], GPT_A }, + { &gptimerCC26XXObjects[CC1352P_4_LAUNCHXL_GPTIMER2], &gptimerCC26xxHWAttrs[CC1352P_4_LAUNCHXL_GPTIMER2B], GPT_B }, + { &gptimerCC26XXObjects[CC1352P_4_LAUNCHXL_GPTIMER3], &gptimerCC26xxHWAttrs[CC1352P_4_LAUNCHXL_GPTIMER3A], GPT_A }, + { &gptimerCC26XXObjects[CC1352P_4_LAUNCHXL_GPTIMER3], &gptimerCC26xxHWAttrs[CC1352P_4_LAUNCHXL_GPTIMER3B], GPT_B }, +}; + +/* + * =============================== I2C =============================== +*/ +#include +#include + +#if TI_I2C_CONF_ENABLE + +I2CCC26XX_Object i2cCC26xxObjects[CC1352P_4_LAUNCHXL_I2CCOUNT]; + +const I2CCC26XX_HWAttrsV1 i2cCC26xxHWAttrs[CC1352P_4_LAUNCHXL_I2CCOUNT] = { +#if TI_I2C_CONF_I2C0_ENABLE + { + .baseAddr = I2C0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_I2C0, + .intNum = INT_I2C_IRQ, + .intPriority = ~0, + .swiPriority = 0, + .sdaPin = CC1352P_4_LAUNCHXL_I2C0_SDA0, + .sclPin = CC1352P_4_LAUNCHXL_I2C0_SCL0, + }, +#endif +}; + +const I2C_Config I2C_config[CC1352P_4_LAUNCHXL_I2CCOUNT] = { +#if TI_I2C_CONF_I2C0_ENABLE + { + .fxnTablePtr = &I2CCC26XX_fxnTable, + .object = &i2cCC26xxObjects[CC1352P_4_LAUNCHXL_I2C0], + .hwAttrs = &i2cCC26xxHWAttrs[CC1352P_4_LAUNCHXL_I2C0] + }, +#endif +}; + +const uint_least8_t I2C_count = CC1352P_4_LAUNCHXL_I2CCOUNT; + +#endif /* TI_I2C_CONF_ENABLE */ + +/* + * =============================== NVS =============================== + */ +#include +#include +#include + +#define NVS_REGIONS_BASE 0x48000 +#define SECTORSIZE 0x2000 +#define REGIONSIZE (SECTORSIZE * 4) + +#if TI_NVS_CONF_ENABLE + +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + +/* + * Reserve flash sectors for NVS driver use by placing an uninitialized byte + * array at the desired flash address. + */ +#if defined(__TI_COMPILER_VERSION__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +#pragma LOCATION(flashBuf, NVS_REGIONS_BASE); +#pragma NOINIT(flashBuf); +static char flashBuf[REGIONSIZE]; + +#elif defined(__IAR_SYSTEMS_ICC__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +static __no_init char flashBuf[REGIONSIZE] @ NVS_REGIONS_BASE; + +#elif defined(__GNUC__) + +/* + * Place the flash buffers in the .nvs section created in the gcc linker file. + * The .nvs section enforces alignment on a sector boundary but may + * be placed anywhere in flash memory. If desired the .nvs section can be set + * to a fixed address by changing the following in the gcc linker file: + * + * .nvs (FIXED_FLASH_ADDR) (NOLOAD) : AT (FIXED_FLASH_ADDR) { + * *(.nvs) + * } > REGION_TEXT + */ +__attribute__ ((section (".nvs"))) +static char flashBuf[REGIONSIZE]; + +#endif + +/* Allocate objects for NVS Internal Regions */ +NVSCC26XX_Object nvsCC26xxObjects[1]; + +/* Hardware attributes for NVS Internal Regions */ +const NVSCC26XX_HWAttrs nvsCC26xxHWAttrs[1] = { + { + .regionBase = (void *)flashBuf, + .regionSize = REGIONSIZE, + }, +}; + +#endif /* TI_NVS_CONF_NVS_INTERNAL_ENABLE */ + +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + +#define SPISECTORSIZE 0x1000 +#define SPIREGIONSIZE (SPISECTORSIZE * 32) +#define VERIFYBUFSIZE 64 + +static uint8_t verifyBuf[VERIFYBUFSIZE]; + +/* Allocate objects for NVS External Regions */ +NVSSPI25X_Object nvsSPI25XObjects[1]; + +/* Hardware attributes for NVS External Regions */ +const NVSSPI25X_HWAttrs nvsSPI25XHWAttrs[1] = { + { + .regionBaseOffset = 0, + .regionSize = SPIREGIONSIZE, + .sectorSize = SPISECTORSIZE, + .verifyBuf = verifyBuf, + .verifyBufSize = VERIFYBUFSIZE, + .spiHandle = NULL, + .spiIndex = 0, + .spiBitRate = 4000000, + .spiCsnGpioIndex = CC1352P_4_LAUNCHXL_GPIO_SPI_FLASH_CS, + }, +}; + +#endif /* TI_NVS_CONF_NVS_EXTERNAL_ENABLE */ + +/* NVS Region index 0 and 1 refer to NVS and NVS SPI respectively */ +const NVS_Config NVS_config[CC1352P_4_LAUNCHXL_NVSCOUNT] = { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + { + .fxnTablePtr = &NVSCC26XX_fxnTable, + .object = &nvsCC26xxObjects[0], + .hwAttrs = &nvsCC26xxHWAttrs[0], + }, +#endif +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + { + .fxnTablePtr = &NVSSPI25X_fxnTable, + .object = &nvsSPI25XObjects[0], + .hwAttrs = &nvsSPI25XHWAttrs[0], + }, +#endif +}; + +const uint_least8_t NVS_count = CC1352P_4_LAUNCHXL_NVSCOUNT; + +#endif /* TI_NVS_CONF_ENABLE */ + +/* + * =============================== PIN =============================== + */ +#include +#include + +const PIN_Config BoardGpioInitTable[] = { + + CC1352P_4_LAUNCHXL_PIN_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC1352P_4_LAUNCHXL_PIN_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC1352P_4_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC1352P_4_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC1352P_4_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ + CC1352P_4_LAUNCHXL_UART0_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */ + CC1352P_4_LAUNCHXL_UART0_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */ + CC1352P_4_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */ + CC1352P_4_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */ + CC1352P_4_LAUNCHXL_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI clock */ + CC1352P_4_LAUNCHXL_DIO28_RF_24GHZ | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* Path disabled */ + CC1352P_4_LAUNCHXL_DIO29_RF_HIGH_PA | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* Path disabled */ + CC1352P_4_LAUNCHXL_DIO30_RF_SUB1GHZ | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* Path disabled */ + PIN_TERMINATE +}; + +const PINCC26XX_HWAttrs PINCC26XX_hwAttrs = { + .intPriority = ~0, + .swiPriority = 0 +}; + +/* + * =============================== Power =============================== + */ +#include +#include + +const PowerCC26X2_Config PowerCC26X2_config = { + .policyInitFxn = NULL, + .policyFxn = &PowerCC26XX_standbyPolicy, + .calibrateFxn = &PowerCC26XX_calibrate, + .enablePolicy = true, + .calibrateRCOSC_LF = true, + .calibrateRCOSC_HF = true, +}; + +/* + * =============================== PWM =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include +#include + +PWMTimerCC26XX_Object pwmtimerCC26xxObjects[CC1352P_4_LAUNCHXL_PWMCOUNT]; + +const PWMTimerCC26XX_HwAttrs pwmtimerCC26xxHWAttrs[CC1352P_4_LAUNCHXL_PWMCOUNT] = { + { .pwmPin = CC1352P_4_LAUNCHXL_PWMPIN0, .gpTimerUnit = CC1352P_4_LAUNCHXL_GPTIMER0A }, + { .pwmPin = CC1352P_4_LAUNCHXL_PWMPIN1, .gpTimerUnit = CC1352P_4_LAUNCHXL_GPTIMER0B }, + { .pwmPin = CC1352P_4_LAUNCHXL_PWMPIN2, .gpTimerUnit = CC1352P_4_LAUNCHXL_GPTIMER1A }, + { .pwmPin = CC1352P_4_LAUNCHXL_PWMPIN3, .gpTimerUnit = CC1352P_4_LAUNCHXL_GPTIMER1B }, + { .pwmPin = CC1352P_4_LAUNCHXL_PWMPIN4, .gpTimerUnit = CC1352P_4_LAUNCHXL_GPTIMER2A }, + { .pwmPin = CC1352P_4_LAUNCHXL_PWMPIN5, .gpTimerUnit = CC1352P_4_LAUNCHXL_GPTIMER2B }, + { .pwmPin = CC1352P_4_LAUNCHXL_PWMPIN6, .gpTimerUnit = CC1352P_4_LAUNCHXL_GPTIMER3A }, + { .pwmPin = CC1352P_4_LAUNCHXL_PWMPIN7, .gpTimerUnit = CC1352P_4_LAUNCHXL_GPTIMER3B }, +}; + +const PWM_Config PWM_config[CC1352P_4_LAUNCHXL_PWMCOUNT] = { + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352P_4_LAUNCHXL_PWM0], &pwmtimerCC26xxHWAttrs[CC1352P_4_LAUNCHXL_PWM0] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352P_4_LAUNCHXL_PWM1], &pwmtimerCC26xxHWAttrs[CC1352P_4_LAUNCHXL_PWM1] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352P_4_LAUNCHXL_PWM2], &pwmtimerCC26xxHWAttrs[CC1352P_4_LAUNCHXL_PWM2] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352P_4_LAUNCHXL_PWM3], &pwmtimerCC26xxHWAttrs[CC1352P_4_LAUNCHXL_PWM3] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352P_4_LAUNCHXL_PWM4], &pwmtimerCC26xxHWAttrs[CC1352P_4_LAUNCHXL_PWM4] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352P_4_LAUNCHXL_PWM5], &pwmtimerCC26xxHWAttrs[CC1352P_4_LAUNCHXL_PWM5] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352P_4_LAUNCHXL_PWM6], &pwmtimerCC26xxHWAttrs[CC1352P_4_LAUNCHXL_PWM6] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352P_4_LAUNCHXL_PWM7], &pwmtimerCC26xxHWAttrs[CC1352P_4_LAUNCHXL_PWM7] }, +}; + +const uint_least8_t PWM_count = CC1352P_4_LAUNCHXL_PWMCOUNT; + +/* + * =============================== RF Driver =============================== + */ +#include + +/* + * Board-specific callback function to set the correct antenna path. + * + * This function is called by the RF driver on global driver events. + * It contains a default implementation to set the correct antenna path. + * This function is defined in the file CC1352P_4_LAUNCHXL_fxns.c + */ +extern void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void* arg); + +const RFCC26XX_HWAttrsV2 RFCC26XX_hwAttrs = { + .hwiPriority = ~0, /* Lowest HWI priority */ + .swiPriority = 0, /* Lowest SWI priority */ + .xoscHfAlwaysNeeded = true, /* Keep XOSC dependency while in stanby */ + + /* Register the board specific callback */ + .globalCallback = &rfDriverCallback, + + /* Subscribe the callback to both events */ + .globalEventMask = RF_GlobalEventRadioSetup | RF_GlobalEventRadioPowerDown +}; + +/* + * =============================== SD =============================== + */ +#include +#include + +#if TI_SD_CONF_ENABLE + +#if !(TI_SPI_CONF_SPI0_ENABLE) +#error "SD driver requires SPI0 enabled" +#endif + +SDSPI_Object sdspiObjects[CC1352P_4_LAUNCHXL_SDCOUNT]; + +const SDSPI_HWAttrs sdspiHWAttrs[CC1352P_4_LAUNCHXL_SDCOUNT] = { + { + .spiIndex = CC1352P_4_LAUNCHXL_SPI0, + .spiCsGpioIndex = CC1352P_4_LAUNCHXL_GPIO_DIO_19 + } +}; + +const SD_Config SD_config[CC1352P_4_LAUNCHXL_SDCOUNT] = { + { + .fxnTablePtr = &SDSPI_fxnTable, + .object = &sdspiObjects[CC1352P_4_LAUNCHXL_SDSPI0], + .hwAttrs = &sdspiHWAttrs[CC1352P_4_LAUNCHXL_SDSPI0] + }, +}; + +const uint_least8_t SD_count = CC1352P_4_LAUNCHXL_SDCOUNT; + +#endif /* TI_SD_CONF_ENABLE */ + +/* + * =============================== SPI DMA =============================== + */ +#include +#include + +SPICC26XXDMA_Object spiCC26XXDMAObjects[CC1352P_4_LAUNCHXL_SPICOUNT]; + +#if TI_SPI_CONF_ENABLE + +/* + * NOTE: The SPI instances below can be used by the SD driver to communicate + * with a SD card via SPI. The 'defaultTxBufValue' fields below are set to 0xFF + * to satisfy the SDSPI driver requirement. + */ +const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[CC1352P_4_LAUNCHXL_SPICOUNT] = { +#if TI_SPI_CONF_SPI0_ENABLE + { + .baseAddr = SSI0_BASE, + .intNum = INT_SSI0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .powerMngrId = PowerCC26XX_PERIPH_SSI0, + .defaultTxBufValue = 0xFF, + .rxChannelBitMask = 1< +#include + +TRNGCC26X2_Object trngCC26X2Object[CC1352P_4_LAUNCHXL_TRNGCOUNT]; + +const TRNGCC26X2_HWAttrs trngCC26X2HWAttrs[CC1352P_4_LAUNCHXL_TRNGCOUNT] = { + { + .swiPriority = 0, + .intPriority = ~0, + } +}; + +const TRNG_Config TRNG_config[] = { + { &trngCC26X2Object[0], &trngCC26X2HWAttrs[0] }, +}; + +const uint8_t TRNG_count = CC1352P_4_LAUNCHXL_TRNGCOUNT; + + +/* + * =============================== UART =============================== + */ +#include +#include + +#if TI_UART_CONF_ENABLE + +UARTCC26XX_Object uartCC26XXObjects[CC1352P_4_LAUNCHXL_UARTCOUNT]; + +uint8_t uartCC26XXRingBuffer[CC1352P_4_LAUNCHXL_UARTCOUNT][32]; + +const UARTCC26XX_HWAttrsV2 uartCC26XXHWAttrs[CC1352P_4_LAUNCHXL_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .baseAddr = UART0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UART0, + .intNum = INT_UART0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .txPin = CC1352P_4_LAUNCHXL_UART0_TX, + .rxPin = CC1352P_4_LAUNCHXL_UART0_RX, + .ctsPin = PIN_UNASSIGNED, + .rtsPin = PIN_UNASSIGNED, + .ringBufPtr = uartCC26XXRingBuffer[CC1352P_4_LAUNCHXL_UART0], + .ringBufSize = sizeof(uartCC26XXRingBuffer[CC1352P_4_LAUNCHXL_UART0]), + .txIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_1_8, + .rxIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_4_8, + .errorFxn = NULL + }, +#endif +#if TI_UART_CONF_UART1_ENABLE + { + .baseAddr = UART1_BASE, + .powerMngrId = PowerCC26X2_PERIPH_UART1, + .intNum = INT_UART1_COMB, + .intPriority = ~0, + .swiPriority = 0, + .txPin = CC1352P_4_LAUNCHXL_UART1_TX, + .rxPin = CC1352P_4_LAUNCHXL_UART1_RX, + .ctsPin = PIN_UNASSIGNED, + .rtsPin = PIN_UNASSIGNED, + .ringBufPtr = uartCC26XXRingBuffer[CC1352P_4_LAUNCHXL_UART1], + .ringBufSize = sizeof(uartCC26XXRingBuffer[CC1352P_4_LAUNCHXL_UART1]), + .txIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_1_8, + .rxIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_4_8, + .errorFxn = NULL + }, +#endif +}; + +const UART_Config UART_config[CC1352P_4_LAUNCHXL_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .fxnTablePtr = &UARTCC26XX_fxnTable, + .object = &uartCC26XXObjects[CC1352P_4_LAUNCHXL_UART0], + .hwAttrs = &uartCC26XXHWAttrs[CC1352P_4_LAUNCHXL_UART0] + }, +#endif +#if TI_UART_CONF_UART1_ENABLE + { + .fxnTablePtr = &UARTCC26XX_fxnTable, + .object = &uartCC26XXObjects[CC1352P_4_LAUNCHXL_UART1], + .hwAttrs = &uartCC26XXHWAttrs[CC1352P_4_LAUNCHXL_UART1] + }, +#endif +}; + +const uint_least8_t UART_count = CC1352P_4_LAUNCHXL_UARTCOUNT; + +#endif /* TI_UART_CONF_ENABLE */ + +/* + * =============================== UDMA =============================== + */ +#include + +UDMACC26XX_Object udmaObjects[CC1352P_4_LAUNCHXL_UDMACOUNT]; + +const UDMACC26XX_HWAttrs udmaHWAttrs[CC1352P_4_LAUNCHXL_UDMACOUNT] = { + { + .baseAddr = UDMA0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UDMA, + .intNum = INT_DMA_ERR, + .intPriority = ~0 + } +}; + +const UDMACC26XX_Config UDMACC26XX_config[CC1352P_4_LAUNCHXL_UDMACOUNT] = { + { + .object = &udmaObjects[CC1352P_4_LAUNCHXL_UDMA0], + .hwAttrs = &udmaHWAttrs[CC1352P_4_LAUNCHXL_UDMA0] + }, +}; + + + +/* + * =============================== Watchdog =============================== + */ +#include +#include + +WatchdogCC26XX_Object watchdogCC26XXObjects[CC1352P_4_LAUNCHXL_WATCHDOGCOUNT]; + +const WatchdogCC26XX_HWAttrs watchdogCC26XXHWAttrs[CC1352P_4_LAUNCHXL_WATCHDOGCOUNT] = { + { + .baseAddr = WDT_BASE, + .reloadValue = 1000 /* Reload value in milliseconds */ + }, +}; + +const Watchdog_Config Watchdog_config[CC1352P_4_LAUNCHXL_WATCHDOGCOUNT] = { + { + .fxnTablePtr = &WatchdogCC26XX_fxnTable, + .object = &watchdogCC26XXObjects[CC1352P_4_LAUNCHXL_WATCHDOG0], + .hwAttrs = &watchdogCC26XXHWAttrs[CC1352P_4_LAUNCHXL_WATCHDOG0] + }, +}; + +const uint_least8_t Watchdog_count = CC1352P_4_LAUNCHXL_WATCHDOGCOUNT; + +/* + * Board-specific initialization function to disable external flash. + * This function is defined in the file CC1352P_4_LAUNCHXL_fxns.c + */ +extern void Board_initHook(void); + +/* + * ======== CC1352P_4_LAUNCHXL_initGeneral ======== + */ +void CC1352P_4_LAUNCHXL_initGeneral(void) +{ + Power_init(); + + if (PIN_init(BoardGpioInitTable) != PIN_SUCCESS) { + /* Error with PIN_init */ + while (1); + } + + /* Perform board-specific initialization */ + Board_initHook(); +} diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/CC1352P_4_LAUNCHXL.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/CC1352P_4_LAUNCHXL.h new file mode 100644 index 000000000..d33d50847 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/CC1352P_4_LAUNCHXL.h @@ -0,0 +1,452 @@ +/* + * Copyright (c) 2017-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 CC1352P_4_LAUNCHXL.h + * + * @brief CC1352P_4_LAUNCHXL Board Specific header file. + * + * The CC1352P_4_LAUNCHXL header file should be included in an application as + * follows: + * @code + * #include "CC1352P_4_LAUNCHXL.h" + * @endcode + * + * =========================================================================== + */ +#ifndef __CC1352P_4_LAUNCHXL_BOARD_H__ +#define __CC1352P_4_LAUNCHXL_BOARD_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "contiki-conf.h" + +/* Includes */ +#include +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) + +/* Externs */ +extern const PIN_Config BoardGpioInitTable[]; + +/* Defines */ +#define CC1352P_4_LAUNCHXL + +/* Mapping of pins to board signals using general board aliases + * + */ + +/* Mapping of pins to board signals using general board aliases + * + */ +/* Analog Capable DIOs */ +#define CC1352P_4_LAUNCHXL_DIO23_ANALOG IOID_23 +#define CC1352P_4_LAUNCHXL_DIO24_ANALOG IOID_24 +#define CC1352P_4_LAUNCHXL_DIO25_ANALOG IOID_25 +#define CC1352P_4_LAUNCHXL_DIO26_ANALOG IOID_26 +#define CC1352P_4_LAUNCHXL_DIO27_ANALOG IOID_27 + +/* RF Antenna Switch */ +#define CC1352P_4_LAUNCHXL_DIO28_RF_24GHZ IOID_28 +#define CC1352P_4_LAUNCHXL_DIO29_RF_HIGH_PA IOID_29 +#define CC1352P_4_LAUNCHXL_DIO30_RF_SUB1GHZ IOID_30 + +/* Digital IOs */ +#define CC1352P_4_LAUNCHXL_DIO12 IOID_12 +#define CC1352P_4_LAUNCHXL_DIO15 IOID_15 +#define CC1352P_4_LAUNCHXL_DIO16_TDO IOID_16 +#define CC1352P_4_LAUNCHXL_DIO17_TDI IOID_17 +#define CC1352P_4_LAUNCHXL_DIO21 IOID_21 +#define CC1352P_4_LAUNCHXL_DIO22 IOID_22 + +/* Discrete Inputs */ +#define CC1352P_4_LAUNCHXL_PIN_BTN1 IOID_15 +#define CC1352P_4_LAUNCHXL_PIN_BTN2 IOID_14 + +/* GPIO */ +#define CC1352P_4_LAUNCHXL_GPIO_LED_ON 1 +#define CC1352P_4_LAUNCHXL_GPIO_LED_OFF 0 + +/* I2C */ +#define CC1352P_4_LAUNCHXL_I2C0_SCL0 IOID_21 +#define CC1352P_4_LAUNCHXL_I2C0_SDA0 IOID_5 + +/* LEDs */ +#define CC1352P_4_LAUNCHXL_PIN_LED_ON 1 +#define CC1352P_4_LAUNCHXL_PIN_LED_OFF 0 +#define CC1352P_4_LAUNCHXL_PIN_RLED IOID_6 +#define CC1352P_4_LAUNCHXL_PIN_GLED IOID_7 + +/* PWM Outputs */ +#define CC1352P_4_LAUNCHXL_PWMPIN0 CC1352P_4_LAUNCHXL_PIN_RLED +#define CC1352P_4_LAUNCHXL_PWMPIN1 CC1352P_4_LAUNCHXL_PIN_GLED +#define CC1352P_4_LAUNCHXL_PWMPIN2 PIN_UNASSIGNED +#define CC1352P_4_LAUNCHXL_PWMPIN3 PIN_UNASSIGNED +#define CC1352P_4_LAUNCHXL_PWMPIN4 PIN_UNASSIGNED +#define CC1352P_4_LAUNCHXL_PWMPIN5 PIN_UNASSIGNED +#define CC1352P_4_LAUNCHXL_PWMPIN6 PIN_UNASSIGNED +#define CC1352P_4_LAUNCHXL_PWMPIN7 PIN_UNASSIGNED + +/* SPI */ +#define CC1352P_4_LAUNCHXL_SPI_FLASH_CS IOID_20 +#define CC1352P_4_LAUNCHXL_FLASH_CS_ON 0 +#define CC1352P_4_LAUNCHXL_FLASH_CS_OFF 1 + +/* SPI Board */ +#define CC1352P_4_LAUNCHXL_SPI0_MISO IOID_8 /* RF1.20 */ +#define CC1352P_4_LAUNCHXL_SPI0_MOSI IOID_9 /* RF1.18 */ +#define CC1352P_4_LAUNCHXL_SPI0_CLK IOID_10 /* RF1.16 */ +#define CC1352P_4_LAUNCHXL_SPI0_CSN PIN_UNASSIGNED +#define CC1352P_4_LAUNCHXL_SPI1_MISO PIN_UNASSIGNED +#define CC1352P_4_LAUNCHXL_SPI1_MOSI PIN_UNASSIGNED +#define CC1352P_4_LAUNCHXL_SPI1_CLK PIN_UNASSIGNED +#define CC1352P_4_LAUNCHXL_SPI1_CSN PIN_UNASSIGNED + +/* UART Board */ +#define CC1352P_4_LAUNCHXL_UART0_RX IOID_12 /* RXD */ +#define CC1352P_4_LAUNCHXL_UART0_TX IOID_13 /* TXD */ +#define CC1352P_4_LAUNCHXL_UART0_CTS PIN_UNASSIGNED /* CTS */ +#define CC1352P_4_LAUNCHXL_UART0_RTS IOID_18 /* RTS */ +#define CC1352P_4_LAUNCHXL_UART1_RX PIN_UNASSIGNED +#define CC1352P_4_LAUNCHXL_UART1_TX PIN_UNASSIGNED +#define CC1352P_4_LAUNCHXL_UART1_CTS PIN_UNASSIGNED +#define CC1352P_4_LAUNCHXL_UART1_RTS PIN_UNASSIGNED +/* For backward compatibility */ +#define CC1352P_4_LAUNCHXL_UART_RX CC1352P_4_LAUNCHXL_UART0_RX +#define CC1352P_4_LAUNCHXL_UART_TX CC1352P_4_LAUNCHXL_UART0_TX +#define CC1352P_4_LAUNCHXL_UART_CTS CC1352P_4_LAUNCHXL_UART0_CTS +#define CC1352P_4_LAUNCHXL_UART_RTS CC1352P_4_LAUNCHXL_UART0_RTS + +/*! + * @brief Initialize the general board specific settings + * + * This function initializes the general board specific settings. + */ +void CC1352P_4_LAUNCHXL_initGeneral(void); + +/*! + * @brief Shut down the external flash present on the board files + * + * This function bitbangs the SPI sequence necessary to turn off + * the external flash on LaunchPads. + */ +void CC1352P_4_LAUNCHXL_shutDownExtFlash(void); + +/*! + * @brief Wake up the external flash present on the board files + * + * This function toggles the chip select for the amount of time needed + * to wake the chip up. + */ +void CC1352P_4_LAUNCHXL_wakeUpExtFlash(void); + + +/*! + * \brief Initializes the antenna switch IOs. + * + * This function sets up the antenna switch and occupies + * the necessary IO pins. After calling this function, they + * cannot be used in the application anymore. + */ +void CC1352P_4_LAUNCHXL_initAntennaSwitch(void); + +/*! + * @def CC1352P_4_LAUNCHXL_ADCBufName + * @brief Enum of ADCs + */ +typedef enum CC1352P_4_LAUNCHXL_ADCBufName { + CC1352P_4_LAUNCHXL_ADCBUF0 = 0, + + CC1352P_4_LAUNCHXL_ADCBUFCOUNT +} CC1352P_4_LAUNCHXL_ADCBufName; + +/*! + * @def CC1352P_4_LAUNCHXL_ADCBuf0ChannelName + * @brief Enum of ADCBuf channels + */ +typedef enum CC1352P_4_LAUNCHXL_ADCBuf0ChannelName { + CC1352P_4_LAUNCHXL_ADCBUF0CHANNEL0 = 0, + CC1352P_4_LAUNCHXL_ADCBUF0CHANNEL1, + CC1352P_4_LAUNCHXL_ADCBUF0CHANNEL2, + CC1352P_4_LAUNCHXL_ADCBUF0CHANNEL3, + CC1352P_4_LAUNCHXL_ADCBUF0CHANNEL4, + CC1352P_4_LAUNCHXL_ADCBUF0CHANNELVDDS, + CC1352P_4_LAUNCHXL_ADCBUF0CHANNELDCOUPL, + CC1352P_4_LAUNCHXL_ADCBUF0CHANNELVSS, + + CC1352P_4_LAUNCHXL_ADCBUF0CHANNELCOUNT +} CC1352P_4_LAUNCHXL_ADCBuf0ChannelName; + +/*! + * @def CC1352P_4_LAUNCHXL_ADCName + * @brief Enum of ADCs + */ +typedef enum CC1352P_4_LAUNCHXL_ADCName { + CC1352P_4_LAUNCHXL_ADC0 = 0, + CC1352P_4_LAUNCHXL_ADC1, + CC1352P_4_LAUNCHXL_ADC2, + CC1352P_4_LAUNCHXL_ADC3, + CC1352P_4_LAUNCHXL_ADC4, + CC1352P_4_LAUNCHXL_ADCDCOUPL, + CC1352P_4_LAUNCHXL_ADCVSS, + CC1352P_4_LAUNCHXL_ADCVDDS, + + CC1352P_4_LAUNCHXL_ADCCOUNT +} CC1352P_4_LAUNCHXL_ADCName; + +/*! + * @def CC1352P_4_LAUNCHXL_ECDHName + * @brief Enum of ECDH names + */ +typedef enum CC1352P_4_LAUNCHXL_ECDHName { + CC1352P_4_LAUNCHXL_ECDH0 = 0, + + CC1352P_4_LAUNCHXL_ECDHCOUNT +} CC1352P_4_LAUNCHXL_ECDHName; + +/*! + * @def CC1352P_4_LAUNCHXL_ECDSAName + * @brief Enum of ECDSA names + */ +typedef enum CC1352P_4_LAUNCHXL_ECDSAName { + CC1352P_4_LAUNCHXL_ECDSA0 = 0, + + CC1352P_4_LAUNCHXL_ECDSACOUNT +} CC1352P_4_LAUNCHXL_ECDSAName; + +/*! + * @def CC1352P_4_LAUNCHXL_ECJPAKEName + * @brief Enum of ECJPAKE names + */ +typedef enum CC1352P_4_LAUNCHXL_ECJPAKEName { + CC1352P_4_LAUNCHXL_ECJPAKE0 = 0, + + CC1352P_4_LAUNCHXL_ECJPAKECOUNT +} CC1352P_4_LAUNCHXL_ECJPAKEName; + +/*! + * @def CC1352P_4_LAUNCHXL_AESCCMName + * @brief Enum of AESCCM names + */ +typedef enum CC1352P_4_LAUNCHXL_AESCCMName { + CC1352P_4_LAUNCHXL_AESCCM0 = 0, + + CC1352P_4_LAUNCHXL_AESCCMCOUNT +} CC1352P_4_LAUNCHXL_AESCCMName; + +/*! + * @def CC1352P_4_LAUNCHXL_AESECBName + * @brief Enum of AESECB names + */ +typedef enum CC1352P_4_LAUNCHXL_AESECBName { + CC1352P_4_LAUNCHXL_AESECB0 = 0, + + CC1352P_4_LAUNCHXL_AESECBCOUNT +} CC1352P_4_LAUNCHXL_AESECBName; + +/*! + * @def CC1352P_4_LAUNCHXL_SHA2Name + * @brief Enum of SHA2 names + */ +typedef enum CC1352P_4_LAUNCHXL_SHA2Name { + CC1352P_4_LAUNCHXL_SHA20 = 0, + + CC1352P_4_LAUNCHXL_SHA2COUNT +} CC1352P_4_LAUNCHXL_SHA2Name; + +/*! + * @def CC1352P_4_LAUNCHXL_GPIOName + * @brief Enum of GPIO names + */ +typedef enum CC1352P_4_LAUNCHXL_GPIOName { + CC1352P_4_LAUNCHXL_GPIO_S1 = 0, + CC1352P_4_LAUNCHXL_GPIO_S2, + CC1352P_4_LAUNCHXL_SPI_MASTER_READY, + CC1352P_4_LAUNCHXL_SPI_SLAVE_READY, + CC1352P_4_LAUNCHXL_GPIO_LED_GREEN, + CC1352P_4_LAUNCHXL_GPIO_LED_RED, + CC1352P_4_LAUNCHXL_GPIO_SPI_FLASH_CS, + CC1352P_4_LAUNCHXL_GPIO_SDSPI_CS, + CC1352P_4_LAUNCHXL_GPIOCOUNT +} CC1352P_4_LAUNCHXL_GPIOName; + +/*! + * @def CC1352P_4_LAUNCHXL_GPTimerName + * @brief Enum of GPTimer parts + */ +typedef enum CC1352P_4_LAUNCHXL_GPTimerName { + CC1352P_4_LAUNCHXL_GPTIMER0A = 0, + CC1352P_4_LAUNCHXL_GPTIMER0B, + CC1352P_4_LAUNCHXL_GPTIMER1A, + CC1352P_4_LAUNCHXL_GPTIMER1B, + CC1352P_4_LAUNCHXL_GPTIMER2A, + CC1352P_4_LAUNCHXL_GPTIMER2B, + CC1352P_4_LAUNCHXL_GPTIMER3A, + CC1352P_4_LAUNCHXL_GPTIMER3B, + + CC1352P_4_LAUNCHXL_GPTIMERPARTSCOUNT +} CC1352P_4_LAUNCHXL_GPTimerName; + +/*! + * @def CC1352P_4_LAUNCHXL_GPTimers + * @brief Enum of GPTimers + */ +typedef enum CC1352P_4_LAUNCHXL_GPTimers { + CC1352P_4_LAUNCHXL_GPTIMER0 = 0, + CC1352P_4_LAUNCHXL_GPTIMER1, + CC1352P_4_LAUNCHXL_GPTIMER2, + CC1352P_4_LAUNCHXL_GPTIMER3, + + CC1352P_4_LAUNCHXL_GPTIMERCOUNT +} CC1352P_4_LAUNCHXL_GPTimers; + +/*! + * @def CC1352P_4_LAUNCHXL_I2CName + * @brief Enum of I2C names + */ +typedef enum CC1352P_4_LAUNCHXL_I2CName { +#if TI_I2C_CONF_I2C0_ENABLE + CC1352P_4_LAUNCHXL_I2C0 = 0, +#endif + + CC1352P_4_LAUNCHXL_I2CCOUNT +} CC1352P_4_LAUNCHXL_I2CName; + +/*! + * @def CC1352P_4_LAUNCHXL_NVSName + * @brief Enum of NVS names + */ +typedef enum CC1352P_4_LAUNCHXL_NVSName { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + CC1352P_4_LAUNCHXL_NVSCC26XX0 = 0, +#endif +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + CC1352P_4_LAUNCHXL_NVSSPI25X0, +#endif + + CC1352P_4_LAUNCHXL_NVSCOUNT +} CC1352P_4_LAUNCHXL_NVSName; + +/*! + * @def CC1352P_4_LAUNCHXL_PWMName + * @brief Enum of PWM outputs + */ +typedef enum CC1352P_4_LAUNCHXL_PWMName { + CC1352P_4_LAUNCHXL_PWM0 = 0, + CC1352P_4_LAUNCHXL_PWM1, + CC1352P_4_LAUNCHXL_PWM2, + CC1352P_4_LAUNCHXL_PWM3, + CC1352P_4_LAUNCHXL_PWM4, + CC1352P_4_LAUNCHXL_PWM5, + CC1352P_4_LAUNCHXL_PWM6, + CC1352P_4_LAUNCHXL_PWM7, + + CC1352P_4_LAUNCHXL_PWMCOUNT +} CC1352P_4_LAUNCHXL_PWMName; + +/*! + * @def CC1352P_4_LAUNCHXL_SDName + * @brief Enum of SD names + */ +typedef enum CC1352P_4_LAUNCHXL_SDName { + CC1352P_4_LAUNCHXL_SDSPI0 = 0, + + CC1352P_4_LAUNCHXL_SDCOUNT +} CC1352P_4_LAUNCHXL_SDName; + +/*! + * @def CC1352P_4_LAUNCHXL_SPIName + * @brief Enum of SPI names + */ +typedef enum CC1352P_4_LAUNCHXL_SPIName { +#if TI_SPI_CONF_SPI0_ENABLE + CC1352P_4_LAUNCHXL_SPI0 = 0, +#endif +#if TI_SPI_CONF_SPI1_ENABLE + CC1352P_4_LAUNCHXL_SPI1, +#endif + + CC1352P_4_LAUNCHXL_SPICOUNT +} CC1352P_4_LAUNCHXL_SPIName; + +/*! + * @def CC1352P_4_LAUNCHXL_TRNGName + * @brief Enum of TRNGs + */ +typedef enum CC1352P_4_LAUNCHXL_TRNGName { + CC1352P_4_LAUNCHXL_TRNG0 = 0, + + CC1352P_4_LAUNCHXL_TRNGCOUNT +} CC1352P_4_LAUNCHXL_TRNGName; + +/*! + * @def CC1352P_4_LAUNCHXL_UARTName + * @brief Enum of UARTs + */ +typedef enum CC1352P_4_LAUNCHXL_UARTName { +#if TI_UART_CONF_UART0_ENABLE + CC1352P_4_LAUNCHXL_UART0 = 0, +#endif +#if TI_UART_CONF_UART1_ENABLE + CC1352P_4_LAUNCHXL_UART1, +#endif + + CC1352P_4_LAUNCHXL_UARTCOUNT +} CC1352P_4_LAUNCHXL_UARTName; + +/*! + * @def CC1352P_4_LAUNCHXL_UDMAName + * @brief Enum of DMA buffers + */ +typedef enum CC1352P_4_LAUNCHXL_UDMAName { + CC1352P_4_LAUNCHXL_UDMA0 = 0, + + CC1352P_4_LAUNCHXL_UDMACOUNT +} CC1352P_4_LAUNCHXL_UDMAName; + +/*! + * @def CC1352P_4_LAUNCHXL_WatchdogName + * @brief Enum of Watchdogs + */ +typedef enum CC1352P_4_LAUNCHXL_WatchdogName { + CC1352P_4_LAUNCHXL_WATCHDOG0 = 0, + + CC1352P_4_LAUNCHXL_WATCHDOGCOUNT +} CC1352P_4_LAUNCHXL_WatchdogName; + + +#ifdef __cplusplus +} +#endif + +#endif /* __CC1352P_4_LAUNCHXL_BOARD_H__ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/CC1352P_4_LAUNCHXL_fxns.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/CC1352P_4_LAUNCHXL_fxns.c new file mode 100644 index 000000000..ef9c0531c --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/CC1352P_4_LAUNCHXL_fxns.c @@ -0,0 +1,256 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +/* + * ======== CC1352P_4_LAUNCHXL_fxns.c ======== + * This file contains the board-specific initialization functions, and + * RF callback function for antenna switching. + */ + +#include +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/cpu.h) +#include +#include + +#include "Board.h" + +/* + * ======== CC1352P_4_LAUNCHXL_sendExtFlashByte ======== + */ +void CC1352P_4_LAUNCHXL_sendExtFlashByte(PIN_Handle pinHandle, uint8_t byte) +{ + uint8_t i; + + /* SPI Flash CS */ + PIN_setOutputValue(pinHandle, IOID_20, 0); + + for (i = 0; i < 8; i++) { + PIN_setOutputValue(pinHandle, IOID_10, 0); /* SPI Flash CLK */ + + /* SPI Flash MOSI */ + PIN_setOutputValue(pinHandle, IOID_9, (byte >> (7 - i)) & 0x01); + PIN_setOutputValue(pinHandle, IOID_10, 1); /* SPI Flash CLK */ + + /* + * Waste a few cycles to keep the CLK high for at + * least 45% of the period. + * 3 cycles per loop: 8 loops @ 48 Mhz = 0.5 us. + */ + CPUdelay(8); + } + + PIN_setOutputValue(pinHandle, IOID_10, 0); /* CLK */ + PIN_setOutputValue(pinHandle, IOID_20, 1); /* CS */ + + /* + * Keep CS high at least 40 us + * 3 cycles per loop: 700 loops @ 48 Mhz ~= 44 us + */ + CPUdelay(700); +} + +/* + * ======== CC1352P_4_LAUNCHXL_wakeUpExtFlash ======== + */ +void CC1352P_4_LAUNCHXL_wakeUpExtFlash(void) +{ + PIN_Config extFlashPinTable[] = { + /* SPI Flash CS */ + IOID_20 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + PIN_TERMINATE + }; + PIN_State extFlashPinState; + PIN_Handle extFlashPinHandle = PIN_open(&extFlashPinState, extFlashPinTable); + + /* + * To wake up we need to toggle the chip select at + * least 20 ns and ten wait at least 35 us. + */ + + /* Toggle chip select for ~20ns to wake ext. flash */ + PIN_setOutputValue(extFlashPinHandle, IOID_20, 0); + /* 3 cycles per loop: 1 loop @ 48 Mhz ~= 62 ns */ + CPUdelay(1); + PIN_setOutputValue(extFlashPinHandle, IOID_20, 1); + /* 3 cycles per loop: 560 loops @ 48 Mhz ~= 35 us */ + CPUdelay(560); + + PIN_close(extFlashPinHandle); +} + +/* + * ======== CC1352P_4_LAUNCHXL_shutDownExtFlash ======== + */ +void CC1352P_4_LAUNCHXL_shutDownExtFlash(void) +{ + /* To be sure we are putting the flash into sleep and not waking it, we first have to make a wake up call */ + CC1352P_4_LAUNCHXL_wakeUpExtFlash(); + + PIN_Config extFlashPinTable[] = { + /* SPI Flash CS*/ + IOID_20 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash CLK */ + IOID_10 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash MOSI */ + IOID_9 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash MISO */ + IOID_8 | PIN_INPUT_EN | PIN_PULLDOWN, + PIN_TERMINATE + }; + PIN_State extFlashPinState; + PIN_Handle extFlashPinHandle = PIN_open(&extFlashPinState, extFlashPinTable); + + uint8_t extFlashShutdown = 0xB9; + + CC1352P_4_LAUNCHXL_sendExtFlashByte(extFlashPinHandle, extFlashShutdown); + + PIN_close(extFlashPinHandle); +} + +/* + * For the SysConfig generated Board.h file, Board_RF_SUB1GHZ will not be + * defined unless the RF module is added to the configuration. Therefore, + * we don't include this code if Board_RF_SUB1GHZ is not defined. + */ +#if defined(Board_RF_SUB1GHZ) + +/* + * ======== Antenna switching ======== + */ +static PIN_Handle antennaPins; +static PIN_State antennaState; + +void initAntennaSwitch() +{ + PIN_Config antennaConfig[] = { + Board_RF_24GHZ | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* Path disabled */ + Board_RF_HIGH_PA | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* Path disabled */ + Board_RF_SUB1GHZ | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* Path disabled */ + PIN_TERMINATE + }; + antennaPins = PIN_open(&antennaState, antennaConfig); +} + +/* + * ======== rfDriverCallback ======== + * Sets up the antenna switch depending on the current PHY configuration. + * Truth table: + * + * Path DIO28 DIO29 DIO30 + * =========== ===== ===== ===== + * Off 0 0 0 + * Sub-1 GHz 0 0 1 + * 2.4 GHz 1 0 0 + * 20 dBm TX 0 1 0 + */ +void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg) +{ + /* Switch off all paths first. Needs to be done anyway in every sub-case below. */ + PINCC26XX_setOutputValue(Board_RF_24GHZ, 0); + PINCC26XX_setOutputValue(Board_RF_HIGH_PA, 0); + PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 0); + + if (events & RF_GlobalEventRadioSetup) { + /* Decode the current PA configuration. */ + RF_TxPowerTable_PAType paType = (RF_TxPowerTable_PAType)RF_getTxPower(client).paType; + + /* Decode the generic argument as a setup command. */ + RF_RadioSetup* setupCommand = (RF_RadioSetup*)arg; + + if (setupCommand->common.commandNo == CMD_PROP_RADIO_DIV_SETUP) { + /* Sub-1 GHz */ + if (paType == RF_TxPowerTable_HighPA) { + /* PA enable --> HIGH PA + * LNA enable --> Sub-1 GHz + */ + PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_GPIO); + // Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not + // de-asserted on CC1352 Rev A. + PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_RFC_GPO3); + PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_RFC_GPO0); + } else { + /* RF core active --> Sub-1 GHz */ + PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_GPIO); + PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_GPIO); + PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_GPIO); + PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 1); + } + } else { + /* 2.4 GHz */ + if (paType == RF_TxPowerTable_HighPA) + { + /* PA enable --> HIGH PA + * LNA enable --> 2.4 GHz + */ + PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_RFC_GPO0); + // Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not + // de-asserted on CC1352 Rev A. + PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_RFC_GPO3); + PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_GPIO); + } else { + /* RF core active --> 2.4 GHz */ + PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_GPIO); + PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_GPIO); + PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_GPIO); + PINCC26XX_setOutputValue(Board_RF_24GHZ, 1); + } + } + } else { + /* Reset the IO multiplexer to GPIO functionality */ + PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_GPIO); + PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_GPIO); + PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_GPIO); + } +} +#endif + +/* + * ======== Board_initHook ======== + * Called by Board_init() to perform board-specific initialization. + */ +void Board_initHook() +{ +#if defined(Board_RF_SUB1GHZ) + initAntennaSwitch(); +#endif + + CC1352P_4_LAUNCHXL_shutDownExtFlash(); +} diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/Makefile.cc1352p-4 b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/Makefile.cc1352p-4 new file mode 100644 index 000000000..076e186b4 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p-4/Makefile.cc1352p-4 @@ -0,0 +1,21 @@ +################################################################################ +# SimpleLink Device makefile + +SUBFAMILY = cc13x2-cc26x2 +DEVICE_FAMILY = CC13X2 +DEVICE_LINE = CC13XX +DEVICE = CC1352P + +BOARD_SOURCEFILES += CC1352P_4_LAUNCHXL.c CC1352P_4_LAUNCHXL_fxns.c + +SUPPORTS_PROP_MODE = 1 +SUPPORTS_IEEE_MODE = 1 +SUPPORTS_BLE_BEACON = 1 + +SUPPORTS_HIGH_PA = 1 + +### Signal that we can be programmed with cc2538-bsl +BOARD_SUPPORTS_BSL = 0 + +# Include the common board makefile +include $(FAMILY_PATH)/launchpad/Makefile.launchpad diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/Board.h new file mode 100644 index 000000000..1fef09180 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/Board.h @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2017-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 __BOARD_H +#define __BOARD_H + +#define Board_CC1352P1_LAUNCHXL +#define BOARD_STRING "TI CC1352P1 LaunchPad" + +#ifdef __cplusplus +extern "C" { +#endif + +#include "CC1352P1_LAUNCHXL.h" + +#define Board_initGeneral() CC1352P1_LAUNCHXL_initGeneral() +#define Board_shutDownExtFlash() CC1352P1_LAUNCHXL_shutDownExtFlash() +#define Board_wakeUpExtFlash() CC1352P1_LAUNCHXL_wakeUpExtFlash() + +/* These #defines allow us to reuse TI-RTOS across other device families */ + +#define Board_ADC0 CC1352P1_LAUNCHXL_ADC0 +#define Board_ADC1 CC1352P1_LAUNCHXL_ADC1 + +#define Board_ADCBUF0 CC1352P1_LAUNCHXL_ADCBUF0 +#define Board_ADCBUF0CHANNEL0 CC1352P1_LAUNCHXL_ADCBUF0CHANNEL0 +#define Board_ADCBUF0CHANNEL1 CC1352P1_LAUNCHXL_ADCBUF0CHANNEL1 + +#define Board_CRYPTO0 CC1352P1_LAUNCHXL_CRYPTO0 +#define Board_ECDH0 CC1352P1_LAUNCHXL_ECDH0 +#define Board_ECDSA0 CC1352P1_LAUNCHXL_ECDSA0 +#define Board_ECJPAKE0 CC1352P1_LAUNCHXL_ECJPAKE0 +#define Board_AESCCM0 CC1352P1_LAUNCHXL_AESCCM0 +#define Board_AESECB0 CC1352P1_LAUNCHXL_AESECB0 +#define Board_SHA20 CC1352P1_LAUNCHXL_SHA20 + +#define Board_DIO12 CC1352P1_LAUNCHXL_DIO12 +#define Board_DIO15 CC1352P1_LAUNCHXL_DIO15 +#define Board_DIO16_TDO CC1352P1_LAUNCHXL_DIO16_TDO +#define Board_DIO17_TDI CC1352P1_LAUNCHXL_DIO17_TDI +#define Board_DIO21 CC1352P1_LAUNCHXL_DIO21 +#define Board_DIO22 CC1352P1_LAUNCHXL_DIO22 + +#define Board_DIO23_ANALOG CC1352P1_LAUNCHXL_DIO23_ANALOG +#define Board_DIO24_ANALOG CC1352P1_LAUNCHXL_DIO24_ANALOG +#define Board_DIO25_ANALOG CC1352P1_LAUNCHXL_DIO25_ANALOG +#define Board_DIO26_ANALOG CC1352P1_LAUNCHXL_DIO26_ANALOG +#define Board_DIO27_ANALOG CC1352P1_LAUNCHXL_DIO27_ANALOG +#define Board_DIO28_ANALOG CC1352P1_LAUNCHXL_DIO28_ANALOG +#define Board_DIO29_ANALOG CC1352P1_LAUNCHXL_DIO29_ANALOG +#define Board_DIO30_RFSW CC1352P1_LAUNCHXL_DIO30_RF_SUB1GHZ + +/* + * Board_RF_SUB1GHZ, Board_RF_HIGH_PA, and Board_RF_24GHZ are the names + * generated by SysConfig. Define them here so that the RF callback function + * can reference them. + */ +#define Board_RF_24GHZ CC1352P1_LAUNCHXL_DIO28_RF_24GHZ +#define Board_RF_HIGH_PA CC1352P1_LAUNCHXL_DIO29_RF_HIGH_PA +#define Board_RF_SUB1GHZ CC1352P1_LAUNCHXL_DIO30_RF_SUB1GHZ + +#define Board_GPIO_BUTTON0 CC1352P1_LAUNCHXL_GPIO_S1 +#define Board_GPIO_BUTTON1 CC1352P1_LAUNCHXL_GPIO_S2 +#define Board_GPIO_BTN1 CC1352P1_LAUNCHXL_GPIO_S1 +#define Board_GPIO_BTN2 CC1352P1_LAUNCHXL_GPIO_S2 +#define Board_GPIO_LED0 CC1352P1_LAUNCHXL_GPIO_LED_RED +#define Board_GPIO_LED1 CC1352P1_LAUNCHXL_GPIO_LED_GREEN +#define Board_GPIO_LED2 CC1352P1_LAUNCHXL_GPIO_LED_RED +#define Board_GPIO_RLED CC1352P1_LAUNCHXL_GPIO_LED_RED +#define Board_GPIO_GLED CC1352P1_LAUNCHXL_GPIO_LED_GREEN +#define Board_GPIO_LED_ON CC1352P1_LAUNCHXL_GPIO_LED_ON +#define Board_GPIO_LED_OFF CC1352P1_LAUNCHXL_GPIO_LED_OFF + +#define Board_GPTIMER0A CC1352P1_LAUNCHXL_GPTIMER0A +#define Board_GPTIMER0B CC1352P1_LAUNCHXL_GPTIMER0B +#define Board_GPTIMER1A CC1352P1_LAUNCHXL_GPTIMER1A +#define Board_GPTIMER1B CC1352P1_LAUNCHXL_GPTIMER1B +#define Board_GPTIMER2A CC1352P1_LAUNCHXL_GPTIMER2A +#define Board_GPTIMER2B CC1352P1_LAUNCHXL_GPTIMER2B +#define Board_GPTIMER3A CC1352P1_LAUNCHXL_GPTIMER3A +#define Board_GPTIMER3B CC1352P1_LAUNCHXL_GPTIMER3B + +#define Board_I2C0 CC1352P1_LAUNCHXL_I2C0 +#define Board_I2C_TMP Board_I2C0 + +#define Board_NVSINTERNAL CC1352P1_LAUNCHXL_NVSCC26XX0 +#define Board_NVSEXTERNAL CC1352P1_LAUNCHXL_NVSSPI25X0 + +#define Board_PIN_BUTTON0 CC1352P1_LAUNCHXL_PIN_BTN1 +#define Board_PIN_BUTTON1 CC1352P1_LAUNCHXL_PIN_BTN2 +#define Board_PIN_BTN1 CC1352P1_LAUNCHXL_PIN_BTN1 +#define Board_PIN_BTN2 CC1352P1_LAUNCHXL_PIN_BTN2 +#define Board_PIN_LED0 CC1352P1_LAUNCHXL_PIN_RLED +#define Board_PIN_LED1 CC1352P1_LAUNCHXL_PIN_GLED +#define Board_PIN_LED2 CC1352P1_LAUNCHXL_PIN_RLED +#define Board_PIN_RLED CC1352P1_LAUNCHXL_PIN_RLED +#define Board_PIN_GLED CC1352P1_LAUNCHXL_PIN_GLED + +#define Board_PWM0 CC1352P1_LAUNCHXL_PWM0 +#define Board_PWM1 CC1352P1_LAUNCHXL_PWM1 +#define Board_PWM2 CC1352P1_LAUNCHXL_PWM2 +#define Board_PWM3 CC1352P1_LAUNCHXL_PWM3 +#define Board_PWM4 CC1352P1_LAUNCHXL_PWM4 +#define Board_PWM5 CC1352P1_LAUNCHXL_PWM5 +#define Board_PWM6 CC1352P1_LAUNCHXL_PWM6 +#define Board_PWM7 CC1352P1_LAUNCHXL_PWM7 + +#define Board_SD0 CC1352P1_LAUNCHXL_SDSPI0 + +#define Board_SPI0 CC1352P1_LAUNCHXL_SPI0 +#define Board_SPI0_MISO CC1352P1_LAUNCHXL_SPI0_MISO +#define Board_SPI0_MOSI CC1352P1_LAUNCHXL_SPI0_MOSI +#define Board_SPI0_CLK CC1352P1_LAUNCHXL_SPI0_CLK +#define Board_SPI0_CSN CC1352P1_LAUNCHXL_SPI0_CSN +#define Board_SPI1 CC1352P1_LAUNCHXL_SPI1 +#define Board_SPI1_MISO CC1352P1_LAUNCHXL_SPI1_MISO +#define Board_SPI1_MOSI CC1352P1_LAUNCHXL_SPI1_MOSI +#define Board_SPI1_CLK CC1352P1_LAUNCHXL_SPI1_CLK +#define Board_SPI1_CSN CC1352P1_LAUNCHXL_SPI1_CSN +#define Board_SPI_FLASH_CS CC1352P1_LAUNCHXL_SPI_FLASH_CS +#define Board_FLASH_CS_ON 0 +#define Board_FLASH_CS_OFF 1 + +#define Board_SPI_MASTER CC1352P1_LAUNCHXL_SPI0 +#define Board_SPI_SLAVE CC1352P1_LAUNCHXL_SPI0 +#define Board_SPI_MASTER_READY CC1352P1_LAUNCHXL_SPI_MASTER_READY +#define Board_SPI_SLAVE_READY CC1352P1_LAUNCHXL_SPI_SLAVE_READY + +#define Board_UART0 CC1352P1_LAUNCHXL_UART0 +#define Board_UART1 CC1352P1_LAUNCHXL_UART1 + +#define Board_WATCHDOG0 CC1352P1_LAUNCHXL_WATCHDOG0 + +/* Board specific I2C addresses */ +#define Board_TMP_ADDR (0x40) +#define Board_SENSORS_BP_TMP_ADDR Board_TMP_ADDR + +#ifdef __cplusplus +} +#endif + +#endif /* __BOARD_H */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/CC1352P1_LAUNCHXL.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/CC1352P1_LAUNCHXL.c new file mode 100644 index 000000000..d4f953fba --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/CC1352P1_LAUNCHXL.c @@ -0,0 +1,949 @@ +/* + * Copyright (c) 2017-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +/* + * ====================== CC1352P1_LAUNCHXL.c =================================== + * This file is responsible for setting up the board specific items for the + * CC1352P1_LAUNCHXL board. + */ + +#include +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/udma.h) +#include DeviceFamily_constructPath(inc/hw_ints.h) +#include DeviceFamily_constructPath(inc/hw_memmap.h) + +#include "CC1352P1_LAUNCHXL.h" + +/* + * =============================== ADCBuf =============================== + */ +#include +#include + +ADCBufCC26X2_Object adcBufCC26xxObjects[CC1352P1_LAUNCHXL_ADCBUFCOUNT]; + +/* + * This table converts a virtual adc channel into a dio and internal analogue + * input signal. This table is necessary for the functioning of the adcBuf + * driver. Comment out unused entries to save flash. Dio and internal signal + * pairs are hardwired. Do not remap them in the table. You may reorder entire + * entries. The mapping of dio and internal signals is package dependent. + */ +const ADCBufCC26X2_AdcChannelLutEntry ADCBufCC26X2_adcChannelLut[CC1352P1_LAUNCHXL_ADCBUF0CHANNELCOUNT] = { + {CC1352P1_LAUNCHXL_DIO23_ANALOG, ADC_COMPB_IN_AUXIO7}, + {CC1352P1_LAUNCHXL_DIO24_ANALOG, ADC_COMPB_IN_AUXIO6}, + {CC1352P1_LAUNCHXL_DIO25_ANALOG, ADC_COMPB_IN_AUXIO5}, + {CC1352P1_LAUNCHXL_DIO26_ANALOG, ADC_COMPB_IN_AUXIO4}, + {CC1352P1_LAUNCHXL_DIO27_ANALOG, ADC_COMPB_IN_AUXIO3}, + {PIN_UNASSIGNED, ADC_COMPB_IN_VDDS}, + {PIN_UNASSIGNED, ADC_COMPB_IN_DCOUPL}, + {PIN_UNASSIGNED, ADC_COMPB_IN_VSS}, +}; + +const ADCBufCC26X2_HWAttrs adcBufCC26xxHWAttrs[CC1352P1_LAUNCHXL_ADCBUFCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + .adcChannelLut = ADCBufCC26X2_adcChannelLut, + .gpTimerUnit = CC1352P1_LAUNCHXL_GPTIMER0A, + } +}; + +const ADCBuf_Config ADCBuf_config[CC1352P1_LAUNCHXL_ADCBUFCOUNT] = { + { + &ADCBufCC26X2_fxnTable, + &adcBufCC26xxObjects[CC1352P1_LAUNCHXL_ADCBUF0], + &adcBufCC26xxHWAttrs[CC1352P1_LAUNCHXL_ADCBUF0] + }, +}; + +const uint_least8_t ADCBuf_count = CC1352P1_LAUNCHXL_ADCBUFCOUNT; + +/* + * =============================== ADC =============================== + */ +#include +#include + +ADCCC26XX_Object adcCC26xxObjects[CC1352P1_LAUNCHXL_ADCCOUNT]; + +const ADCCC26XX_HWAttrs adcCC26xxHWAttrs[CC1352P1_LAUNCHXL_ADCCOUNT] = { + { + .adcDIO = CC1352P1_LAUNCHXL_DIO23_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO7, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1352P1_LAUNCHXL_DIO24_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO6, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1352P1_LAUNCHXL_DIO25_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO5, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1352P1_LAUNCHXL_DIO26_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO4, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1352P1_LAUNCHXL_DIO27_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO3, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_DCOUPL, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_VSS, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_VDDS, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + } +}; + +const ADC_Config ADC_config[CC1352P1_LAUNCHXL_ADCCOUNT] = { + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352P1_LAUNCHXL_ADC0], &adcCC26xxHWAttrs[CC1352P1_LAUNCHXL_ADC0]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352P1_LAUNCHXL_ADC1], &adcCC26xxHWAttrs[CC1352P1_LAUNCHXL_ADC1]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352P1_LAUNCHXL_ADC2], &adcCC26xxHWAttrs[CC1352P1_LAUNCHXL_ADC2]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352P1_LAUNCHXL_ADC3], &adcCC26xxHWAttrs[CC1352P1_LAUNCHXL_ADC3]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352P1_LAUNCHXL_ADC4], &adcCC26xxHWAttrs[CC1352P1_LAUNCHXL_ADC4]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352P1_LAUNCHXL_ADCDCOUPL], &adcCC26xxHWAttrs[CC1352P1_LAUNCHXL_ADCDCOUPL]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352P1_LAUNCHXL_ADCVSS], &adcCC26xxHWAttrs[CC1352P1_LAUNCHXL_ADCVSS]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352P1_LAUNCHXL_ADCVDDS], &adcCC26xxHWAttrs[CC1352P1_LAUNCHXL_ADCVDDS]}, +}; + +const uint_least8_t ADC_count = CC1352P1_LAUNCHXL_ADCCOUNT; + +/* + * =============================== ECDH =============================== + */ +#include +#include + +ECDHCC26X2_Object ecdhCC26X2Objects[CC1352P1_LAUNCHXL_ECDHCOUNT]; + +const ECDHCC26X2_HWAttrs ecdhCC26X2HWAttrs[CC1352P1_LAUNCHXL_ECDHCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const ECDH_Config ECDH_config[CC1352P1_LAUNCHXL_ECDHCOUNT] = { + { + .object = &ecdhCC26X2Objects[CC1352P1_LAUNCHXL_ECDH0], + .hwAttrs = &ecdhCC26X2HWAttrs[CC1352P1_LAUNCHXL_ECDH0] + }, +}; + +const uint_least8_t ECDH_count = CC1352P1_LAUNCHXL_ECDHCOUNT; + +/* + * =============================== ECDSA =============================== + */ +#include +#include + +ECDSACC26X2_Object ecdsaCC26X2Objects[CC1352P1_LAUNCHXL_ECDSACOUNT]; + +const ECDSACC26X2_HWAttrs ecdsaCC26X2HWAttrs[CC1352P1_LAUNCHXL_ECDSACOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const ECDSA_Config ECDSA_config[CC1352P1_LAUNCHXL_ECDSACOUNT] = { + { + .object = &ecdsaCC26X2Objects[CC1352P1_LAUNCHXL_ECDSA0], + .hwAttrs = &ecdsaCC26X2HWAttrs[CC1352P1_LAUNCHXL_ECDSA0] + }, +}; + +const uint_least8_t ECDSA_count = CC1352P1_LAUNCHXL_ECDSACOUNT; + +/* + * =============================== ECJPAKE =============================== + */ +#include +#include + +ECJPAKECC26X2_Object ecjpakeCC26X2Objects[CC1352P1_LAUNCHXL_ECJPAKECOUNT]; + +const ECJPAKECC26X2_HWAttrs ecjpakeCC26X2HWAttrs[CC1352P1_LAUNCHXL_ECJPAKECOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const ECJPAKE_Config ECJPAKE_config[CC1352P1_LAUNCHXL_ECJPAKECOUNT] = { + { + .object = &ecjpakeCC26X2Objects[CC1352P1_LAUNCHXL_ECJPAKE0], + .hwAttrs = &ecjpakeCC26X2HWAttrs[CC1352P1_LAUNCHXL_ECJPAKE0] + }, +}; + +const uint_least8_t ECJPAKE_count = CC1352P1_LAUNCHXL_ECJPAKECOUNT; + + +/* + * =============================== SHA2 =============================== + */ +#include +#include + +SHA2CC26X2_Object sha2CC26X2Objects[CC1352P1_LAUNCHXL_SHA2COUNT]; + +const SHA2CC26X2_HWAttrs sha2CC26X2HWAttrs[CC1352P1_LAUNCHXL_SHA2COUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const SHA2_Config SHA2_config[CC1352P1_LAUNCHXL_SHA2COUNT] = { + { + .object = &sha2CC26X2Objects[CC1352P1_LAUNCHXL_SHA20], + .hwAttrs = &sha2CC26X2HWAttrs[CC1352P1_LAUNCHXL_SHA20] + }, +}; + +const uint_least8_t SHA2_count = CC1352P1_LAUNCHXL_SHA2COUNT; + +/* + * =============================== AESCCM =============================== + */ +#include +#include + +AESCCMCC26XX_Object aesccmCC26XXObjects[CC1352P1_LAUNCHXL_AESCCMCOUNT]; + +const AESCCMCC26XX_HWAttrs aesccmCC26XXHWAttrs[CC1352P1_LAUNCHXL_AESCCMCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const AESCCM_Config AESCCM_config[CC1352P1_LAUNCHXL_AESCCMCOUNT] = { + { + .object = &aesccmCC26XXObjects[CC1352P1_LAUNCHXL_AESCCM0], + .hwAttrs = &aesccmCC26XXHWAttrs[CC1352P1_LAUNCHXL_AESCCM0] + }, +}; + +const uint_least8_t AESCCM_count = CC1352P1_LAUNCHXL_AESCCMCOUNT; + +/* + * =============================== AESECB =============================== + */ +#include +#include + +AESECBCC26XX_Object aesecbCC26XXObjects[CC1352P1_LAUNCHXL_AESECBCOUNT]; + +const AESECBCC26XX_HWAttrs aesecbCC26XXHWAttrs[CC1352P1_LAUNCHXL_AESECBCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const AESECB_Config AESECB_config[CC1352P1_LAUNCHXL_AESECBCOUNT] = { + { + .object = &aesecbCC26XXObjects[CC1352P1_LAUNCHXL_AESECB0], + .hwAttrs = &aesecbCC26XXHWAttrs[CC1352P1_LAUNCHXL_AESECB0] + }, +}; + +const uint_least8_t AESECB_count = CC1352P1_LAUNCHXL_AESECBCOUNT; + +/* + * =============================== GPIO =============================== + */ +#include +#include + +/* + * Array of Pin configurations + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC1352P1_LAUNCHXL.h + * NOTE: Pins not used for interrupts should be placed at the end of the + * array. Callback entries can be omitted from callbacks array to + * reduce memory usage. + */ +GPIO_PinConfig gpioPinConfigs[] = { + /* Input pins */ + GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG, /* Button 0 */ + GPIOCC26XX_DIO_14 | GPIO_DO_NOT_CONFIG, /* Button 1 */ + + GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG, /* CC1352P1_LAUNCHXL_SPI_MASTER_READY */ + GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG, /* CC1352P1_LAUNCHXL_SPI_SLAVE_READY */ + + /* Output pins */ + GPIOCC26XX_DIO_07 | GPIO_DO_NOT_CONFIG, /* Green LED */ + GPIOCC26XX_DIO_06 | GPIO_DO_NOT_CONFIG, /* Red LED */ + + /* SPI Flash CSN */ + GPIOCC26XX_DIO_20 | GPIO_DO_NOT_CONFIG, + + /* SD CS */ + GPIOCC26XX_DIO_19 | GPIO_DO_NOT_CONFIG, +}; + +/* + * Array of callback function pointers + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC1352P_LAUNCH.h + * NOTE: Pins not used for interrupts can be omitted from callbacks array to + * reduce memory usage (if placed at end of gpioPinConfigs array). + */ +GPIO_CallbackFxn gpioCallbackFunctions[] = { + NULL, /* Button 0 */ + NULL, /* Button 1 */ + NULL, /* CC1352P1_LAUNCHXL_SPI_MASTER_READY */ + NULL, /* CC1352P1_LAUNCHXL_SPI_SLAVE_READY */ +}; + +const GPIOCC26XX_Config GPIOCC26XX_config = { + .pinConfigs = (GPIO_PinConfig *)gpioPinConfigs, + .callbacks = (GPIO_CallbackFxn *)gpioCallbackFunctions, + .numberOfPinConfigs = CC1352P1_LAUNCHXL_GPIOCOUNT, + .numberOfCallbacks = sizeof(gpioCallbackFunctions)/sizeof(GPIO_CallbackFxn), + .intPriority = (~0) +}; + +/* + * =============================== GPTimer =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include + +GPTimerCC26XX_Object gptimerCC26XXObjects[CC1352P1_LAUNCHXL_GPTIMERCOUNT]; + +const GPTimerCC26XX_HWAttrs gptimerCC26xxHWAttrs[CC1352P1_LAUNCHXL_GPTIMERPARTSCOUNT] = { + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0A, }, + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0B, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1A, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1B, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2A, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2B, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3A, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3B, }, +}; + +const GPTimerCC26XX_Config GPTimerCC26XX_config[CC1352P1_LAUNCHXL_GPTIMERPARTSCOUNT] = { + { &gptimerCC26XXObjects[CC1352P1_LAUNCHXL_GPTIMER0], &gptimerCC26xxHWAttrs[CC1352P1_LAUNCHXL_GPTIMER0A], GPT_A }, + { &gptimerCC26XXObjects[CC1352P1_LAUNCHXL_GPTIMER0], &gptimerCC26xxHWAttrs[CC1352P1_LAUNCHXL_GPTIMER0B], GPT_B }, + { &gptimerCC26XXObjects[CC1352P1_LAUNCHXL_GPTIMER1], &gptimerCC26xxHWAttrs[CC1352P1_LAUNCHXL_GPTIMER1A], GPT_A }, + { &gptimerCC26XXObjects[CC1352P1_LAUNCHXL_GPTIMER1], &gptimerCC26xxHWAttrs[CC1352P1_LAUNCHXL_GPTIMER1B], GPT_B }, + { &gptimerCC26XXObjects[CC1352P1_LAUNCHXL_GPTIMER2], &gptimerCC26xxHWAttrs[CC1352P1_LAUNCHXL_GPTIMER2A], GPT_A }, + { &gptimerCC26XXObjects[CC1352P1_LAUNCHXL_GPTIMER2], &gptimerCC26xxHWAttrs[CC1352P1_LAUNCHXL_GPTIMER2B], GPT_B }, + { &gptimerCC26XXObjects[CC1352P1_LAUNCHXL_GPTIMER3], &gptimerCC26xxHWAttrs[CC1352P1_LAUNCHXL_GPTIMER3A], GPT_A }, + { &gptimerCC26XXObjects[CC1352P1_LAUNCHXL_GPTIMER3], &gptimerCC26xxHWAttrs[CC1352P1_LAUNCHXL_GPTIMER3B], GPT_B }, +}; + +/* + * =============================== I2C =============================== +*/ +#include +#include + +#if TI_I2C_CONF_ENABLE + +I2CCC26XX_Object i2cCC26xxObjects[CC1352P1_LAUNCHXL_I2CCOUNT]; + +const I2CCC26XX_HWAttrsV1 i2cCC26xxHWAttrs[CC1352P1_LAUNCHXL_I2CCOUNT] = { +#if TI_I2C_CONF_I2C0_ENABLE + { + .baseAddr = I2C0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_I2C0, + .intNum = INT_I2C_IRQ, + .intPriority = ~0, + .swiPriority = 0, + .sdaPin = CC1352P1_LAUNCHXL_I2C0_SDA0, + .sclPin = CC1352P1_LAUNCHXL_I2C0_SCL0, + }, +#endif +}; + +const I2C_Config I2C_config[CC1352P1_LAUNCHXL_I2CCOUNT] = { +#if TI_I2C_CONF_I2C0_ENABLE + { + .fxnTablePtr = &I2CCC26XX_fxnTable, + .object = &i2cCC26xxObjects[CC1352P1_LAUNCHXL_I2C0], + .hwAttrs = &i2cCC26xxHWAttrs[CC1352P1_LAUNCHXL_I2C0] + }, +#endif +}; + +const uint_least8_t I2C_count = CC1352P1_LAUNCHXL_I2CCOUNT; + +#endif /* TI_I2C_CONF_ENABLE */ + +/* + * =============================== NVS =============================== + */ +#include +#include +#include + +#define NVS_REGIONS_BASE 0x48000 +#define SECTORSIZE 0x2000 +#define REGIONSIZE (SECTORSIZE * 4) + +#if TI_NVS_CONF_ENABLE + +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + +/* + * Reserve flash sectors for NVS driver use by placing an uninitialized byte + * array at the desired flash address. + */ +#if defined(__TI_COMPILER_VERSION__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +#pragma LOCATION(flashBuf, NVS_REGIONS_BASE); +#pragma NOINIT(flashBuf); +static char flashBuf[REGIONSIZE]; + +#elif defined(__IAR_SYSTEMS_ICC__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +static __no_init char flashBuf[REGIONSIZE] @ NVS_REGIONS_BASE; + +#elif defined(__GNUC__) + +/* + * Place the flash buffers in the .nvs section created in the gcc linker file. + * The .nvs section enforces alignment on a sector boundary but may + * be placed anywhere in flash memory. If desired the .nvs section can be set + * to a fixed address by changing the following in the gcc linker file: + * + * .nvs (FIXED_FLASH_ADDR) (NOLOAD) : AT (FIXED_FLASH_ADDR) { + * *(.nvs) + * } > REGION_TEXT + */ +__attribute__ ((section (".nvs"))) +static char flashBuf[REGIONSIZE]; + +#endif + +/* Allocate objects for NVS Internal Regions */ +NVSCC26XX_Object nvsCC26xxObjects[1]; + +/* Hardware attributes for NVS Internal Regions */ +const NVSCC26XX_HWAttrs nvsCC26xxHWAttrs[1] = { + { + .regionBase = (void *)flashBuf, + .regionSize = REGIONSIZE, + }, +}; + +#endif /* TI_NVS_CONF_NVS_INTERNAL_ENABLE */ + +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + +#define SPISECTORSIZE 0x1000 +#define SPIREGIONSIZE (SPISECTORSIZE * 32) +#define VERIFYBUFSIZE 64 + +static uint8_t verifyBuf[VERIFYBUFSIZE]; + +/* Allocate objects for NVS External Regions */ +NVSSPI25X_Object nvsSPI25XObjects[1]; + +/* Hardware attributes for NVS External Regions */ +const NVSSPI25X_HWAttrs nvsSPI25XHWAttrs[1] = { + { + .regionBaseOffset = 0, + .regionSize = SPIREGIONSIZE, + .sectorSize = SPISECTORSIZE, + .verifyBuf = verifyBuf, + .verifyBufSize = VERIFYBUFSIZE, + .spiHandle = NULL, + .spiIndex = 0, + .spiBitRate = 4000000, + .spiCsnGpioIndex = CC1352P1_LAUNCHXL_GPIO_SPI_FLASH_CS, + }, +}; + +#endif /* TI_NVS_CONF_NVS_EXTERNAL_ENABLE */ + +/* NVS Region index 0 and 1 refer to NVS and NVS SPI respectively */ +const NVS_Config NVS_config[CC1352P1_LAUNCHXL_NVSCOUNT] = { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + { + .fxnTablePtr = &NVSCC26XX_fxnTable, + .object = &nvsCC26xxObjects[0], + .hwAttrs = &nvsCC26xxHWAttrs[0], + }, +#endif +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + { + .fxnTablePtr = &NVSSPI25X_fxnTable, + .object = &nvsSPI25XObjects[0], + .hwAttrs = &nvsSPI25XHWAttrs[0], + }, +#endif +}; + +const uint_least8_t NVS_count = CC1352P1_LAUNCHXL_NVSCOUNT; + +#endif /* TI_NVS_CONF_ENABLE */ + +/* + * =============================== PIN =============================== + */ +#include +#include + +const PIN_Config BoardGpioInitTable[] = { + + CC1352P1_LAUNCHXL_PIN_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC1352P1_LAUNCHXL_PIN_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC1352P1_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC1352P1_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC1352P1_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ + CC1352P1_LAUNCHXL_UART0_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */ + CC1352P1_LAUNCHXL_UART0_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */ + CC1352P1_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */ + CC1352P1_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */ + CC1352P1_LAUNCHXL_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI clock */ + CC1352P1_LAUNCHXL_DIO28_RF_24GHZ | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* Path disabled */ + CC1352P1_LAUNCHXL_DIO29_RF_HIGH_PA | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* Path disabled */ + CC1352P1_LAUNCHXL_DIO30_RF_SUB1GHZ | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* Path disabled */ + PIN_TERMINATE +}; + +const PINCC26XX_HWAttrs PINCC26XX_hwAttrs = { + .intPriority = ~0, + .swiPriority = 0 +}; + +/* + * =============================== Power =============================== + */ +#include +#include + +const PowerCC26X2_Config PowerCC26X2_config = { + .policyInitFxn = NULL, + .policyFxn = &PowerCC26XX_standbyPolicy, + .calibrateFxn = &PowerCC26XX_calibrate, + .enablePolicy = true, + .calibrateRCOSC_LF = true, + .calibrateRCOSC_HF = true, +}; + +/* + * =============================== PWM =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include +#include + +PWMTimerCC26XX_Object pwmtimerCC26xxObjects[CC1352P1_LAUNCHXL_PWMCOUNT]; + +const PWMTimerCC26XX_HwAttrs pwmtimerCC26xxHWAttrs[CC1352P1_LAUNCHXL_PWMCOUNT] = { + { .pwmPin = CC1352P1_LAUNCHXL_PWMPIN0, .gpTimerUnit = CC1352P1_LAUNCHXL_GPTIMER0A }, + { .pwmPin = CC1352P1_LAUNCHXL_PWMPIN1, .gpTimerUnit = CC1352P1_LAUNCHXL_GPTIMER0B }, + { .pwmPin = CC1352P1_LAUNCHXL_PWMPIN2, .gpTimerUnit = CC1352P1_LAUNCHXL_GPTIMER1A }, + { .pwmPin = CC1352P1_LAUNCHXL_PWMPIN3, .gpTimerUnit = CC1352P1_LAUNCHXL_GPTIMER1B }, + { .pwmPin = CC1352P1_LAUNCHXL_PWMPIN4, .gpTimerUnit = CC1352P1_LAUNCHXL_GPTIMER2A }, + { .pwmPin = CC1352P1_LAUNCHXL_PWMPIN5, .gpTimerUnit = CC1352P1_LAUNCHXL_GPTIMER2B }, + { .pwmPin = CC1352P1_LAUNCHXL_PWMPIN6, .gpTimerUnit = CC1352P1_LAUNCHXL_GPTIMER3A }, + { .pwmPin = CC1352P1_LAUNCHXL_PWMPIN7, .gpTimerUnit = CC1352P1_LAUNCHXL_GPTIMER3B }, +}; + +const PWM_Config PWM_config[CC1352P1_LAUNCHXL_PWMCOUNT] = { + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352P1_LAUNCHXL_PWM0], &pwmtimerCC26xxHWAttrs[CC1352P1_LAUNCHXL_PWM0] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352P1_LAUNCHXL_PWM1], &pwmtimerCC26xxHWAttrs[CC1352P1_LAUNCHXL_PWM1] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352P1_LAUNCHXL_PWM2], &pwmtimerCC26xxHWAttrs[CC1352P1_LAUNCHXL_PWM2] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352P1_LAUNCHXL_PWM3], &pwmtimerCC26xxHWAttrs[CC1352P1_LAUNCHXL_PWM3] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352P1_LAUNCHXL_PWM4], &pwmtimerCC26xxHWAttrs[CC1352P1_LAUNCHXL_PWM4] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352P1_LAUNCHXL_PWM5], &pwmtimerCC26xxHWAttrs[CC1352P1_LAUNCHXL_PWM5] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352P1_LAUNCHXL_PWM6], &pwmtimerCC26xxHWAttrs[CC1352P1_LAUNCHXL_PWM6] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352P1_LAUNCHXL_PWM7], &pwmtimerCC26xxHWAttrs[CC1352P1_LAUNCHXL_PWM7] }, +}; + +const uint_least8_t PWM_count = CC1352P1_LAUNCHXL_PWMCOUNT; + +/* + * =============================== RF Driver =============================== + */ +#include + +/* + * Board-specific callback function to set the correct antenna path. + * + * This function is called by the RF driver on global driver events. + * It contains a default implementation to set the correct antenna path. + * This function is defined in the file CC1352P1_LAUNCHXL_fxns.c + */ +extern void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void* arg); + +const RFCC26XX_HWAttrsV2 RFCC26XX_hwAttrs = { + .hwiPriority = ~0, /* Lowest HWI priority */ + .swiPriority = 0, /* Lowest SWI priority */ + .xoscHfAlwaysNeeded = true, /* Keep XOSC dependency while in stanby */ + + /* Register the board specific callback */ + .globalCallback = &rfDriverCallback, + + /* Subscribe the callback to both events */ + .globalEventMask = RF_GlobalEventRadioSetup | RF_GlobalEventRadioPowerDown +}; + +/* + * =============================== SD =============================== + */ +#include +#include + +#if TI_SD_CONF_ENABLE + +#if !(TI_SPI_CONF_SPI0_ENABLE) +#error "SD driver requires SPI0 enabled" +#endif + +SDSPI_Object sdspiObjects[CC1352P1_LAUNCHXL_SDCOUNT]; + +const SDSPI_HWAttrs sdspiHWAttrs[CC1352P1_LAUNCHXL_SDCOUNT] = { + { + .spiIndex = CC1352P1_LAUNCHXL_SPI0, + .spiCsGpioIndex = CC1352P1_LAUNCHXL_GPIO_DIO_19 + } +}; + +const SD_Config SD_config[CC1352P1_LAUNCHXL_SDCOUNT] = { + { + .fxnTablePtr = &SDSPI_fxnTable, + .object = &sdspiObjects[CC1352P1_LAUNCHXL_SDSPI0], + .hwAttrs = &sdspiHWAttrs[CC1352P1_LAUNCHXL_SDSPI0] + }, +}; + +const uint_least8_t SD_count = CC1352P1_LAUNCHXL_SDCOUNT; + +#endif /* TI_SD_CONF_ENABLE */ + +/* + * =============================== SPI DMA =============================== + */ +#include +#include + +#if TI_SPI_CONF_ENABLE + +SPICC26XXDMA_Object spiCC26XXDMAObjects[CC1352P1_LAUNCHXL_SPICOUNT]; + +/* + * NOTE: The SPI instances below can be used by the SD driver to communicate + * with a SD card via SPI. The 'defaultTxBufValue' fields below are set to 0xFF + * to satisfy the SDSPI driver requirement. + */ +const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[CC1352P1_LAUNCHXL_SPICOUNT] = { +#if TI_SPI_CONF_SPI0_ENABLE + { + .baseAddr = SSI0_BASE, + .intNum = INT_SSI0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .powerMngrId = PowerCC26XX_PERIPH_SSI0, + .defaultTxBufValue = 0xFF, + .rxChannelBitMask = 1< +#include + +TRNGCC26X2_Object trngCC26X2Object[CC1352P1_LAUNCHXL_TRNGCOUNT]; + +const TRNGCC26X2_HWAttrs trngCC26X2HWAttrs[CC1352P1_LAUNCHXL_TRNGCOUNT] = { + { + .swiPriority = 0, + .intPriority = ~0, + } +}; + +const TRNG_Config TRNG_config[] = { + { &trngCC26X2Object[0], &trngCC26X2HWAttrs[0] }, +}; + +const uint8_t TRNG_count = CC1352P1_LAUNCHXL_TRNGCOUNT; + + +/* + * =============================== UART =============================== + */ +#include +#include + +#if TI_UART_CONF_ENABLE + +UARTCC26XX_Object uartCC26XXObjects[CC1352P1_LAUNCHXL_UARTCOUNT]; + +uint8_t uartCC26XXRingBuffer[CC1352P1_LAUNCHXL_UARTCOUNT][32]; + +const UARTCC26XX_HWAttrsV2 uartCC26XXHWAttrs[CC1352P1_LAUNCHXL_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .baseAddr = UART0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UART0, + .intNum = INT_UART0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .txPin = CC1352P1_LAUNCHXL_UART0_TX, + .rxPin = CC1352P1_LAUNCHXL_UART0_RX, + .ctsPin = PIN_UNASSIGNED, + .rtsPin = PIN_UNASSIGNED, + .ringBufPtr = uartCC26XXRingBuffer[CC1352P1_LAUNCHXL_UART0], + .ringBufSize = sizeof(uartCC26XXRingBuffer[CC1352P1_LAUNCHXL_UART0]), + .txIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_1_8, + .rxIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_4_8, + .errorFxn = NULL + }, +#endif +#if TI_UART_CONF_UART1_ENABLE + { + .baseAddr = UART1_BASE, + .powerMngrId = PowerCC26X2_PERIPH_UART1, + .intNum = INT_UART1_COMB, + .intPriority = ~0, + .swiPriority = 0, + .txPin = CC1352P1_LAUNCHXL_UART1_TX, + .rxPin = CC1352P1_LAUNCHXL_UART1_RX, + .ctsPin = PIN_UNASSIGNED, + .rtsPin = PIN_UNASSIGNED, + .ringBufPtr = uartCC26XXRingBuffer[CC1352P1_LAUNCHXL_UART1], + .ringBufSize = sizeof(uartCC26XXRingBuffer[CC1352P1_LAUNCHXL_UART1]), + .txIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_1_8, + .rxIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_4_8, + .errorFxn = NULL + }, +#endif +}; + +const UART_Config UART_config[CC1352P1_LAUNCHXL_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .fxnTablePtr = &UARTCC26XX_fxnTable, + .object = &uartCC26XXObjects[CC1352P1_LAUNCHXL_UART0], + .hwAttrs = &uartCC26XXHWAttrs[CC1352P1_LAUNCHXL_UART0] + }, +#endif +#if TI_UART_CONF_UART1_ENABLE + { + .fxnTablePtr = &UARTCC26XX_fxnTable, + .object = &uartCC26XXObjects[CC1352P1_LAUNCHXL_UART1], + .hwAttrs = &uartCC26XXHWAttrs[CC1352P1_LAUNCHXL_UART1] + }, +#endif +}; + +const uint_least8_t UART_count = CC1352P1_LAUNCHXL_UARTCOUNT; + +#endif /* TI_UART_CONF_ENABLE */ + +/* + * =============================== UDMA =============================== + */ +#include + +UDMACC26XX_Object udmaObjects[CC1352P1_LAUNCHXL_UDMACOUNT]; + +const UDMACC26XX_HWAttrs udmaHWAttrs[CC1352P1_LAUNCHXL_UDMACOUNT] = { + { + .baseAddr = UDMA0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UDMA, + .intNum = INT_DMA_ERR, + .intPriority = ~0 + } +}; + +const UDMACC26XX_Config UDMACC26XX_config[CC1352P1_LAUNCHXL_UDMACOUNT] = { + { + .object = &udmaObjects[CC1352P1_LAUNCHXL_UDMA0], + .hwAttrs = &udmaHWAttrs[CC1352P1_LAUNCHXL_UDMA0] + }, +}; + + + +/* + * =============================== Watchdog =============================== + */ +#include +#include + +WatchdogCC26XX_Object watchdogCC26XXObjects[CC1352P1_LAUNCHXL_WATCHDOGCOUNT]; + +const WatchdogCC26XX_HWAttrs watchdogCC26XXHWAttrs[CC1352P1_LAUNCHXL_WATCHDOGCOUNT] = { + { + .baseAddr = WDT_BASE, + .reloadValue = 1000 /* Reload value in milliseconds */ + }, +}; + +const Watchdog_Config Watchdog_config[CC1352P1_LAUNCHXL_WATCHDOGCOUNT] = { + { + .fxnTablePtr = &WatchdogCC26XX_fxnTable, + .object = &watchdogCC26XXObjects[CC1352P1_LAUNCHXL_WATCHDOG0], + .hwAttrs = &watchdogCC26XXHWAttrs[CC1352P1_LAUNCHXL_WATCHDOG0] + }, +}; + +const uint_least8_t Watchdog_count = CC1352P1_LAUNCHXL_WATCHDOGCOUNT; + +/* + * Board-specific initialization function to disable external flash. + * This function is defined in the file CC1352P1_LAUNCHXL_fxns.c + */ +extern void Board_initHook(void); + +/* + * ======== CC1352P1_LAUNCHXL_initGeneral ======== + */ +void CC1352P1_LAUNCHXL_initGeneral(void) +{ + Power_init(); + + if (PIN_init(BoardGpioInitTable) != PIN_SUCCESS) { + /* Error with PIN_init */ + while (1); + } + + /* Perform board-specific initialization */ + Board_initHook(); +} diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/CC1352P1_LAUNCHXL.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/CC1352P1_LAUNCHXL.h new file mode 100644 index 000000000..067a3ea87 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/CC1352P1_LAUNCHXL.h @@ -0,0 +1,456 @@ +/* + * Copyright (c) 2017-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 CC1352P1_LAUNCHXL.h + * + * @brief CC1352P1_LAUNCHXL Board Specific header file. + * + * The CC1352P1_LAUNCHXL header file should be included in an application as + * follows: + * @code + * #include "CC1352P1_LAUNCHXL.h" + * @endcode + * + * =========================================================================== + */ +#ifndef __CC1352P1_LAUNCHXL_BOARD_H__ +#define __CC1352P1_LAUNCHXL_BOARD_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "contiki-conf.h" + +/* Includes */ +#include +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) + +/* Externs */ +extern const PIN_Config BoardGpioInitTable[]; + +/* Defines */ +#define CC1352P1_LAUNCHXL + +/* Mapping of pins to board signals using general board aliases + * + */ + +/* Mapping of pins to board signals using general board aliases + * + */ +/* Analog Capable DIOs */ +#define CC1352P1_LAUNCHXL_DIO23_ANALOG IOID_23 +#define CC1352P1_LAUNCHXL_DIO24_ANALOG IOID_24 +#define CC1352P1_LAUNCHXL_DIO25_ANALOG IOID_25 +#define CC1352P1_LAUNCHXL_DIO26_ANALOG IOID_26 +#define CC1352P1_LAUNCHXL_DIO27_ANALOG IOID_27 + +/* RF Antenna Switch */ +#define CC1352P1_LAUNCHXL_DIO28_RF_24GHZ IOID_28 +#define CC1352P1_LAUNCHXL_DIO29_RF_HIGH_PA IOID_29 +#define CC1352P1_LAUNCHXL_DIO30_RF_SUB1GHZ IOID_30 + +/* Digital IOs */ +#define CC1352P1_LAUNCHXL_DIO12 IOID_12 +#define CC1352P1_LAUNCHXL_DIO15 IOID_15 +#define CC1352P1_LAUNCHXL_DIO16_TDO IOID_16 +#define CC1352P1_LAUNCHXL_DIO17_TDI IOID_17 +#define CC1352P1_LAUNCHXL_DIO21 IOID_21 +#define CC1352P1_LAUNCHXL_DIO22 IOID_22 + +/* Discrete Inputs */ +#define CC1352P1_LAUNCHXL_PIN_BTN1 IOID_15 +#define CC1352P1_LAUNCHXL_PIN_BTN2 IOID_14 + +/* GPIO */ +#define CC1352P1_LAUNCHXL_GPIO_LED_ON 1 +#define CC1352P1_LAUNCHXL_GPIO_LED_OFF 0 + +/* I2C */ +#define CC1352P1_LAUNCHXL_I2C0_SCL0 IOID_22 +#define CC1352P1_LAUNCHXL_I2C0_SDA0 IOID_5 + +/* LEDs */ +#define CC1352P1_LAUNCHXL_PIN_LED_ON 1 +#define CC1352P1_LAUNCHXL_PIN_LED_OFF 0 +#define CC1352P1_LAUNCHXL_PIN_RLED IOID_6 +#define CC1352P1_LAUNCHXL_PIN_GLED IOID_7 + +/* PWM Outputs */ +#define CC1352P1_LAUNCHXL_PWMPIN0 CC1352P1_LAUNCHXL_PIN_RLED +#define CC1352P1_LAUNCHXL_PWMPIN1 CC1352P1_LAUNCHXL_PIN_GLED +#define CC1352P1_LAUNCHXL_PWMPIN2 PIN_UNASSIGNED +#define CC1352P1_LAUNCHXL_PWMPIN3 PIN_UNASSIGNED +#define CC1352P1_LAUNCHXL_PWMPIN4 PIN_UNASSIGNED +#define CC1352P1_LAUNCHXL_PWMPIN5 PIN_UNASSIGNED +#define CC1352P1_LAUNCHXL_PWMPIN6 PIN_UNASSIGNED +#define CC1352P1_LAUNCHXL_PWMPIN7 PIN_UNASSIGNED + +/* SPI */ +#define CC1352P1_LAUNCHXL_SPI_FLASH_CS IOID_20 +#define CC1352P1_LAUNCHXL_FLASH_CS_ON 0 +#define CC1352P1_LAUNCHXL_FLASH_CS_OFF 1 + +/* SPI Board */ +#define CC1352P1_LAUNCHXL_SPI0_MISO IOID_8 /* RF1.20 */ +#define CC1352P1_LAUNCHXL_SPI0_MOSI IOID_9 /* RF1.18 */ +#define CC1352P1_LAUNCHXL_SPI0_CLK IOID_10 /* RF1.16 */ +#define CC1352P1_LAUNCHXL_SPI0_CSN PIN_UNASSIGNED +#define CC1352P1_LAUNCHXL_SPI1_MISO PIN_UNASSIGNED +#define CC1352P1_LAUNCHXL_SPI1_MOSI PIN_UNASSIGNED +#define CC1352P1_LAUNCHXL_SPI1_CLK PIN_UNASSIGNED +#define CC1352P1_LAUNCHXL_SPI1_CSN PIN_UNASSIGNED + +/* UART Board */ +#define CC1352P1_LAUNCHXL_UART0_RX IOID_12 /* RXD */ +#define CC1352P1_LAUNCHXL_UART0_TX IOID_13 /* TXD */ +#define CC1352P1_LAUNCHXL_UART0_CTS IOID_19 /* CTS */ +#define CC1352P1_LAUNCHXL_UART0_RTS IOID_18 /* RTS */ +#define CC1352P1_LAUNCHXL_UART1_RX PIN_UNASSIGNED +#define CC1352P1_LAUNCHXL_UART1_TX PIN_UNASSIGNED +#define CC1352P1_LAUNCHXL_UART1_CTS PIN_UNASSIGNED +#define CC1352P1_LAUNCHXL_UART1_RTS PIN_UNASSIGNED +/* For backward compatibility */ +#define CC1352P1_LAUNCHXL_UART_RX CC1352P1_LAUNCHXL_UART0_RX +#define CC1352P1_LAUNCHXL_UART_TX CC1352P1_LAUNCHXL_UART0_TX +#define CC1352P1_LAUNCHXL_UART_CTS CC1352P1_LAUNCHXL_UART0_CTS +#define CC1352P1_LAUNCHXL_UART_RTS CC1352P1_LAUNCHXL_UART0_RTS + +/*! + * @brief Initialize the general board specific settings + * + * This function initializes the general board specific settings. + */ +void CC1352P1_LAUNCHXL_initGeneral(void); + +/*! + * @brief Shut down the external flash present on the board files + * + * This function bitbangs the SPI sequence necessary to turn off + * the external flash on LaunchPads. + */ +void CC1352P1_LAUNCHXL_shutDownExtFlash(void); + +/*! + * @brief Wake up the external flash present on the board files + * + * This function toggles the chip select for the amount of time needed + * to wake the chip up. + */ +void CC1352P1_LAUNCHXL_wakeUpExtFlash(void); + + +/*! + * \brief Initializes the antenna switch IOs. + * + * This function sets up the antenna switch and occupies + * the necessary IO pins. After calling this function, they + * cannot be used in the application anymore. + */ +void CC1352P1_LAUNCHXL_initAntennaSwitch(void); + +/*! + * @def CC1352P1_LAUNCHXL_ADCBufName + * @brief Enum of ADCs + */ +typedef enum CC1352P1_LAUNCHXL_ADCBufName { + CC1352P1_LAUNCHXL_ADCBUF0 = 0, + + CC1352P1_LAUNCHXL_ADCBUFCOUNT +} CC1352P1_LAUNCHXL_ADCBufName; + +/*! + * @def CC1352P1_LAUNCHXL_ADCBuf0ChannelName + * @brief Enum of ADCBuf channels + */ +typedef enum CC1352P1_LAUNCHXL_ADCBuf0ChannelName { + CC1352P1_LAUNCHXL_ADCBUF0CHANNEL0 = 0, + CC1352P1_LAUNCHXL_ADCBUF0CHANNEL1, + CC1352P1_LAUNCHXL_ADCBUF0CHANNEL2, + CC1352P1_LAUNCHXL_ADCBUF0CHANNEL3, + CC1352P1_LAUNCHXL_ADCBUF0CHANNEL4, + CC1352P1_LAUNCHXL_ADCBUF0CHANNEL5, + CC1352P1_LAUNCHXL_ADCBUF0CHANNEL6, + CC1352P1_LAUNCHXL_ADCBUF0CHANNELVDDS, + CC1352P1_LAUNCHXL_ADCBUF0CHANNELDCOUPL, + CC1352P1_LAUNCHXL_ADCBUF0CHANNELVSS, + + CC1352P1_LAUNCHXL_ADCBUF0CHANNELCOUNT +} CC1352P1_LAUNCHXL_ADCBuf0ChannelName; + +/*! + * @def CC1352P1_LAUNCHXL_ADCName + * @brief Enum of ADCs + */ +typedef enum CC1352P1_LAUNCHXL_ADCName { + CC1352P1_LAUNCHXL_ADC0 = 0, + CC1352P1_LAUNCHXL_ADC1, + CC1352P1_LAUNCHXL_ADC2, + CC1352P1_LAUNCHXL_ADC3, + CC1352P1_LAUNCHXL_ADC4, + CC1352P1_LAUNCHXL_ADC5, + CC1352P1_LAUNCHXL_ADC6, + CC1352P1_LAUNCHXL_ADCDCOUPL, + CC1352P1_LAUNCHXL_ADCVSS, + CC1352P1_LAUNCHXL_ADCVDDS, + + CC1352P1_LAUNCHXL_ADCCOUNT +} CC1352P1_LAUNCHXL_ADCName; + +/*! + * @def CC1352P1_LAUNCHXL_ECDHName + * @brief Enum of ECDH names + */ +typedef enum CC1352P1_LAUNCHXL_ECDHName { + CC1352P1_LAUNCHXL_ECDH0 = 0, + + CC1352P1_LAUNCHXL_ECDHCOUNT +} CC1352P1_LAUNCHXL_ECDHName; + +/*! + * @def CC1352P1_LAUNCHXL_ECDSAName + * @brief Enum of ECDSA names + */ +typedef enum CC1352P1_LAUNCHXL_ECDSAName { + CC1352P1_LAUNCHXL_ECDSA0 = 0, + + CC1352P1_LAUNCHXL_ECDSACOUNT +} CC1352P1_LAUNCHXL_ECDSAName; + +/*! + * @def CC1352P1_LAUNCHXL_ECJPAKEName + * @brief Enum of ECJPAKE names + */ +typedef enum CC1352P1_LAUNCHXL_ECJPAKEName { + CC1352P1_LAUNCHXL_ECJPAKE0 = 0, + + CC1352P1_LAUNCHXL_ECJPAKECOUNT +} CC1352P1_LAUNCHXL_ECJPAKEName; + +/*! + * @def CC1352P1_LAUNCHXL_AESCCMName + * @brief Enum of AESCCM names + */ +typedef enum CC1352P1_LAUNCHXL_AESCCMName { + CC1352P1_LAUNCHXL_AESCCM0 = 0, + + CC1352P1_LAUNCHXL_AESCCMCOUNT +} CC1352P1_LAUNCHXL_AESCCMName; + +/*! + * @def CC1352P1_LAUNCHXL_AESECBName + * @brief Enum of AESECB names + */ +typedef enum CC1352P1_LAUNCHXL_AESECBName { + CC1352P1_LAUNCHXL_AESECB0 = 0, + + CC1352P1_LAUNCHXL_AESECBCOUNT +} CC1352P1_LAUNCHXL_AESECBName; + +/*! + * @def CC1352P1_LAUNCHXL_SHA2Name + * @brief Enum of SHA2 names + */ +typedef enum CC1352P1_LAUNCHXL_SHA2Name { + CC1352P1_LAUNCHXL_SHA20 = 0, + + CC1352P1_LAUNCHXL_SHA2COUNT +} CC1352P1_LAUNCHXL_SHA2Name; + +/*! + * @def CC1352P1_LAUNCHXL_GPIOName + * @brief Enum of GPIO names + */ +typedef enum CC1352P1_LAUNCHXL_GPIOName { + CC1352P1_LAUNCHXL_GPIO_S1 = 0, + CC1352P1_LAUNCHXL_GPIO_S2, + CC1352P1_LAUNCHXL_SPI_MASTER_READY, + CC1352P1_LAUNCHXL_SPI_SLAVE_READY, + CC1352P1_LAUNCHXL_GPIO_LED_GREEN, + CC1352P1_LAUNCHXL_GPIO_LED_RED, + CC1352P1_LAUNCHXL_GPIO_SPI_FLASH_CS, + CC1352P1_LAUNCHXL_GPIO_SDSPI_CS, + CC1352P1_LAUNCHXL_GPIOCOUNT +} CC1352P1_LAUNCHXL_GPIOName; + +/*! + * @def CC1352P1_LAUNCHXL_GPTimerName + * @brief Enum of GPTimer parts + */ +typedef enum CC1352P1_LAUNCHXL_GPTimerName { + CC1352P1_LAUNCHXL_GPTIMER0A = 0, + CC1352P1_LAUNCHXL_GPTIMER0B, + CC1352P1_LAUNCHXL_GPTIMER1A, + CC1352P1_LAUNCHXL_GPTIMER1B, + CC1352P1_LAUNCHXL_GPTIMER2A, + CC1352P1_LAUNCHXL_GPTIMER2B, + CC1352P1_LAUNCHXL_GPTIMER3A, + CC1352P1_LAUNCHXL_GPTIMER3B, + + CC1352P1_LAUNCHXL_GPTIMERPARTSCOUNT +} CC1352P1_LAUNCHXL_GPTimerName; + +/*! + * @def CC1352P1_LAUNCHXL_GPTimers + * @brief Enum of GPTimers + */ +typedef enum CC1352P1_LAUNCHXL_GPTimers { + CC1352P1_LAUNCHXL_GPTIMER0 = 0, + CC1352P1_LAUNCHXL_GPTIMER1, + CC1352P1_LAUNCHXL_GPTIMER2, + CC1352P1_LAUNCHXL_GPTIMER3, + + CC1352P1_LAUNCHXL_GPTIMERCOUNT +} CC1352P1_LAUNCHXL_GPTimers; + +/*! + * @def CC1352P1_LAUNCHXL_I2CName + * @brief Enum of I2C names + */ +typedef enum CC1352P1_LAUNCHXL_I2CName { +#if TI_I2C_CONF_I2C0_ENABLE + CC1352P1_LAUNCHXL_I2C0 = 0, +#endif + + CC1352P1_LAUNCHXL_I2CCOUNT +} CC1352P1_LAUNCHXL_I2CName; + +/*! + * @def CC1352P1_LAUNCHXL_NVSName + * @brief Enum of NVS names + */ +typedef enum CC1352P1_LAUNCHXL_NVSName { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + CC1352P1_LAUNCHXL_NVSCC26XX0 = 0, +#endif +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + CC1352P1_LAUNCHXL_NVSSPI25X0, +#endif + + CC1352P1_LAUNCHXL_NVSCOUNT +} CC1352P1_LAUNCHXL_NVSName; + +/*! + * @def CC1352P1_LAUNCHXL_PWMName + * @brief Enum of PWM outputs + */ +typedef enum CC1352P1_LAUNCHXL_PWMName { + CC1352P1_LAUNCHXL_PWM0 = 0, + CC1352P1_LAUNCHXL_PWM1, + CC1352P1_LAUNCHXL_PWM2, + CC1352P1_LAUNCHXL_PWM3, + CC1352P1_LAUNCHXL_PWM4, + CC1352P1_LAUNCHXL_PWM5, + CC1352P1_LAUNCHXL_PWM6, + CC1352P1_LAUNCHXL_PWM7, + + CC1352P1_LAUNCHXL_PWMCOUNT +} CC1352P1_LAUNCHXL_PWMName; + +/*! + * @def CC1352P1_LAUNCHXL_SDName + * @brief Enum of SD names + */ +typedef enum CC1352P1_LAUNCHXL_SDName { + CC1352P1_LAUNCHXL_SDSPI0 = 0, + + CC1352P1_LAUNCHXL_SDCOUNT +} CC1352P1_LAUNCHXL_SDName; + +/*! + * @def CC1352P1_LAUNCHXL_SPIName + * @brief Enum of SPI names + */ +typedef enum CC1352P1_LAUNCHXL_SPIName { +#if TI_SPI_CONF_SPI0_ENABLE + CC1352P1_LAUNCHXL_SPI0 = 0, +#endif +#if TI_SPI_CONF_SPI1_ENABLE + CC1352P1_LAUNCHXL_SPI1, +#endif + + CC1352P1_LAUNCHXL_SPICOUNT +} CC1352P1_LAUNCHXL_SPIName; + +/*! + * @def CC1352P1_LAUNCHXL_TRNGName + * @brief Enum of TRNGs + */ +typedef enum CC1352P1_LAUNCHXL_TRNGName { + CC1352P1_LAUNCHXL_TRNG0 = 0, + + CC1352P1_LAUNCHXL_TRNGCOUNT +} CC1352P1_LAUNCHXL_TRNGName; + +/*! + * @def CC1352P1_LAUNCHXL_UARTName + * @brief Enum of UARTs + */ +typedef enum CC1352P1_LAUNCHXL_UARTName { +#if TI_UART_CONF_UART0_ENABLE + CC1352P1_LAUNCHXL_UART0 = 0, +#endif +#if TI_UART_CONF_UART1_ENABLE + CC1352P1_LAUNCHXL_UART1, +#endif + + CC1352P1_LAUNCHXL_UARTCOUNT +} CC1352P1_LAUNCHXL_UARTName; + +/*! + * @def CC1352P1_LAUNCHXL_UDMAName + * @brief Enum of DMA buffers + */ +typedef enum CC1352P1_LAUNCHXL_UDMAName { + CC1352P1_LAUNCHXL_UDMA0 = 0, + + CC1352P1_LAUNCHXL_UDMACOUNT +} CC1352P1_LAUNCHXL_UDMAName; + +/*! + * @def CC1352P1_LAUNCHXL_WatchdogName + * @brief Enum of Watchdogs + */ +typedef enum CC1352P1_LAUNCHXL_WatchdogName { + CC1352P1_LAUNCHXL_WATCHDOG0 = 0, + + CC1352P1_LAUNCHXL_WATCHDOGCOUNT +} CC1352P1_LAUNCHXL_WatchdogName; + + +#ifdef __cplusplus +} +#endif + +#endif /* __CC1352P1_LAUNCHXL_BOARD_H__ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/CC1352P1_LAUNCHXL_fxns.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/CC1352P1_LAUNCHXL_fxns.c new file mode 100644 index 000000000..9f3000929 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/CC1352P1_LAUNCHXL_fxns.c @@ -0,0 +1,256 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +/* + * ======== CC1352P1_LAUNCHXL_fxns.c ======== + * This file contains the board-specific initialization functions, and + * RF callback function for antenna switching. + */ + +#include +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/cpu.h) +#include +#include + +#include "Board.h" + +/* + * ======== CC1352P1_LAUNCHXL_sendExtFlashByte ======== + */ +void CC1352P1_LAUNCHXL_sendExtFlashByte(PIN_Handle pinHandle, uint8_t byte) +{ + uint8_t i; + + /* SPI Flash CS */ + PIN_setOutputValue(pinHandle, IOID_20, 0); + + for (i = 0; i < 8; i++) { + PIN_setOutputValue(pinHandle, IOID_10, 0); /* SPI Flash CLK */ + + /* SPI Flash MOSI */ + PIN_setOutputValue(pinHandle, IOID_9, (byte >> (7 - i)) & 0x01); + PIN_setOutputValue(pinHandle, IOID_10, 1); /* SPI Flash CLK */ + + /* + * Waste a few cycles to keep the CLK high for at + * least 45% of the period. + * 3 cycles per loop: 8 loops @ 48 Mhz = 0.5 us. + */ + CPUdelay(8); + } + + PIN_setOutputValue(pinHandle, IOID_10, 0); /* CLK */ + PIN_setOutputValue(pinHandle, IOID_20, 1); /* CS */ + + /* + * Keep CS high at least 40 us + * 3 cycles per loop: 700 loops @ 48 Mhz ~= 44 us + */ + CPUdelay(700); +} + +/* + * ======== CC1352P1_LAUNCHXL_wakeUpExtFlash ======== + */ +void CC1352P1_LAUNCHXL_wakeUpExtFlash(void) +{ + PIN_Config extFlashPinTable[] = { + /* SPI Flash CS */ + IOID_20 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + PIN_TERMINATE + }; + PIN_State extFlashPinState; + PIN_Handle extFlashPinHandle = PIN_open(&extFlashPinState, extFlashPinTable); + + /* + * To wake up we need to toggle the chip select at + * least 20 ns and ten wait at least 35 us. + */ + + /* Toggle chip select for ~20ns to wake ext. flash */ + PIN_setOutputValue(extFlashPinHandle, IOID_20, 0); + /* 3 cycles per loop: 1 loop @ 48 Mhz ~= 62 ns */ + CPUdelay(1); + PIN_setOutputValue(extFlashPinHandle, IOID_20, 1); + /* 3 cycles per loop: 560 loops @ 48 Mhz ~= 35 us */ + CPUdelay(560); + + PIN_close(extFlashPinHandle); +} + +/* + * ======== CC1352P1_LAUNCHXL_shutDownExtFlash ======== + */ +void CC1352P1_LAUNCHXL_shutDownExtFlash(void) +{ + /* To be sure we are putting the flash into sleep and not waking it, we first have to make a wake up call */ + CC1352P1_LAUNCHXL_wakeUpExtFlash(); + + PIN_Config extFlashPinTable[] = { + /* SPI Flash CS*/ + IOID_20 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash CLK */ + IOID_10 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash MOSI */ + IOID_9 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash MISO */ + IOID_8 | PIN_INPUT_EN | PIN_PULLDOWN, + PIN_TERMINATE + }; + PIN_State extFlashPinState; + PIN_Handle extFlashPinHandle = PIN_open(&extFlashPinState, extFlashPinTable); + + uint8_t extFlashShutdown = 0xB9; + + CC1352P1_LAUNCHXL_sendExtFlashByte(extFlashPinHandle, extFlashShutdown); + + PIN_close(extFlashPinHandle); +} + +/* + * For the SysConfig generated Board.h file, Board_RF_SUB1GHZ will not be + * defined unless the RF module is added to the configuration. Therefore, + * we don't include this code if Board_RF_SUB1GHZ is not defined. + */ +#if defined(Board_RF_SUB1GHZ) + +/* + * ======== Antenna switching ======== + */ +static PIN_Handle antennaPins; +static PIN_State antennaState; + +void initAntennaSwitch() +{ + PIN_Config antennaConfig[] = { + Board_RF_24GHZ | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* Path disabled */ + Board_RF_HIGH_PA | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* Path disabled */ + Board_RF_SUB1GHZ | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* Path disabled */ + PIN_TERMINATE + }; + antennaPins = PIN_open(&antennaState, antennaConfig); +} + +/* + * ======== rfDriverCallback ======== + * Sets up the antenna switch depending on the current PHY configuration. + * Truth table: + * + * Path DIO28 DIO29 DIO30 + * =========== ===== ===== ===== + * Off 0 0 0 + * Sub-1 GHz 0 0 1 + * 2.4 GHz 1 0 0 + * 20 dBm TX 0 1 0 + */ +void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg) +{ + /* Switch off all paths first. Needs to be done anyway in every sub-case below. */ + PINCC26XX_setOutputValue(Board_RF_24GHZ, 0); + PINCC26XX_setOutputValue(Board_RF_HIGH_PA, 0); + PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 0); + + if (events & RF_GlobalEventRadioSetup) { + /* Decode the current PA configuration. */ + RF_TxPowerTable_PAType paType = (RF_TxPowerTable_PAType)RF_getTxPower(client).paType; + + /* Decode the generic argument as a setup command. */ + RF_RadioSetup* setupCommand = (RF_RadioSetup*)arg; + + if (setupCommand->common.commandNo == CMD_PROP_RADIO_DIV_SETUP) { + /* Sub-1 GHz */ + if (paType == RF_TxPowerTable_HighPA) { + /* PA enable --> HIGH PA + * LNA enable --> Sub-1 GHz + */ + PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_GPIO); + // Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not + // de-asserted on CC1352 Rev A. + PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_RFC_GPO3); + PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_RFC_GPO0); + } else { + /* RF core active --> Sub-1 GHz */ + PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_GPIO); + PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_GPIO); + PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_GPIO); + PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 1); + } + } else { + /* 2.4 GHz */ + if (paType == RF_TxPowerTable_HighPA) + { + /* PA enable --> HIGH PA + * LNA enable --> 2.4 GHz + */ + PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_RFC_GPO0); + // Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not + // de-asserted on CC1352 Rev A. + PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_RFC_GPO3); + PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_GPIO); + } else { + /* RF core active --> 2.4 GHz */ + PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_GPIO); + PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_GPIO); + PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_GPIO); + PINCC26XX_setOutputValue(Board_RF_24GHZ, 1); + } + } + } else { + /* Reset the IO multiplexer to GPIO functionality */ + PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_GPIO); + PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_GPIO); + PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_GPIO); + } +} +#endif + +/* + * ======== Board_initHook ======== + * Called by Board_init() to perform board-specific initialization. + */ +void Board_initHook() +{ +#if defined(Board_RF_SUB1GHZ) + initAntennaSwitch(); +#endif + + CC1352P1_LAUNCHXL_shutDownExtFlash(); +} diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/Makefile.cc1352p1 b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/Makefile.cc1352p1 new file mode 100644 index 000000000..37afeef96 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/Makefile.cc1352p1 @@ -0,0 +1,21 @@ +################################################################################ +# SimpleLink Device makefile + +SUBFAMILY = cc13x2-cc26x2 +DEVICE_FAMILY = CC13X2 +DEVICE_LINE = CC13XX +DEVICE = CC1352P + +BOARD_SOURCEFILES += CC1352P1_LAUNCHXL.c CC1352P1_LAUNCHXL_fxns.c + +SUPPORTS_PROP_MODE = 1 +SUPPORTS_IEEE_MODE = 1 +SUPPORTS_BLE_BEACON = 1 + +SUPPORTS_HIGH_PA = 1 + +### Signal that we can be programmed with cc2538-bsl +BOARD_SUPPORTS_BSL = 0 + +# Include the common board makefile +include $(FAMILY_PATH)/launchpad/Makefile.launchpad diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/Board.h new file mode 100644 index 000000000..8bf0ee002 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/Board.h @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2017-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 __BOARD_H +#define __BOARD_H + +#define Board_CC1352R1_LAUNCHXL +#define BOARD_STRING "TI CC1352R1 LaunchPad" + +#ifdef __cplusplus +extern "C" { +#endif + +#include "CC1352R1_LAUNCHXL.h" + +#define Board_initGeneral() CC1352R1_LAUNCHXL_initGeneral() +#define Board_shutDownExtFlash() CC1352R1_LAUNCHXL_shutDownExtFlash() +#define Board_wakeUpExtFlash() CC1352R1_LAUNCHXL_wakeUpExtFlash() + +/* These #defines allow us to reuse TI-RTOS across other device families */ + +#define Board_ADC0 CC1352R1_LAUNCHXL_ADC0 +#define Board_ADC1 CC1352R1_LAUNCHXL_ADC1 + +#define Board_ADCBUF0 CC1352R1_LAUNCHXL_ADCBUF0 +#define Board_ADCBUF0CHANNEL0 CC1352R1_LAUNCHXL_ADCBUF0CHANNEL0 +#define Board_ADCBUF0CHANNEL1 CC1352R1_LAUNCHXL_ADCBUF0CHANNEL1 + +#define Board_ECDH0 CC1352R1_LAUNCHXL_ECDH0 +#define Board_ECDSA0 CC1352R1_LAUNCHXL_ECDSA0 +#define Board_ECJPAKE0 CC1352R1_LAUNCHXL_ECJPAKE0 +#define Board_AESCCM0 CC1352R1_LAUNCHXL_AESCCM0 +#define Board_AESECB0 CC1352R1_LAUNCHXL_AESECB0 +#define Board_SHA20 CC1352R1_LAUNCHXL_SHA20 + +#define Board_DIO12 CC1352R1_LAUNCHXL_DIO12 +#define Board_DIO15 CC1352R1_LAUNCHXL_DIO15 +#define Board_DIO16_TDO CC1352R1_LAUNCHXL_DIO16_TDO +#define Board_DIO17_TDI CC1352R1_LAUNCHXL_DIO17_TDI +#define Board_DIO21 CC1352R1_LAUNCHXL_DIO21 +#define Board_DIO22 CC1352R1_LAUNCHXL_DIO22 + +#define Board_DIO23_ANALOG CC1352R1_LAUNCHXL_DIO23_ANALOG +#define Board_DIO24_ANALOG CC1352R1_LAUNCHXL_DIO24_ANALOG +#define Board_DIO25_ANALOG CC1352R1_LAUNCHXL_DIO25_ANALOG +#define Board_DIO26_ANALOG CC1352R1_LAUNCHXL_DIO26_ANALOG +#define Board_DIO27_ANALOG CC1352R1_LAUNCHXL_DIO27_ANALOG +#define Board_DIO28_ANALOG CC1352R1_LAUNCHXL_DIO28_ANALOG +#define Board_DIO29_ANALOG CC1352R1_LAUNCHXL_DIO29_ANALOG +#define Board_DIO30_RFSW CC1352R1_LAUNCHXL_DIO30_RF_SUB1GHZ + +/* + * Board_RF_SUB1GHZ is the name generated by SysConfig. Define it + * here so that RF callback function can reference it. + */ +#define Board_RF_SUB1GHZ CC1352R1_LAUNCHXL_DIO30_RF_SUB1GHZ + +#define Board_GPIO_BUTTON0 CC1352R1_LAUNCHXL_GPIO_S1 +#define Board_GPIO_BUTTON1 CC1352R1_LAUNCHXL_GPIO_S2 +#define Board_GPIO_BTN1 CC1352R1_LAUNCHXL_GPIO_S1 +#define Board_GPIO_BTN2 CC1352R1_LAUNCHXL_GPIO_S2 +#define Board_GPIO_LED0 CC1352R1_LAUNCHXL_GPIO_LED_RED +#define Board_GPIO_LED1 CC1352R1_LAUNCHXL_GPIO_LED_GREEN +#define Board_GPIO_LED2 CC1352R1_LAUNCHXL_GPIO_LED_RED +#define Board_GPIO_RLED CC1352R1_LAUNCHXL_GPIO_LED_RED +#define Board_GPIO_GLED CC1352R1_LAUNCHXL_GPIO_LED_GREEN +#define Board_GPIO_LED_ON CC1352R1_LAUNCHXL_GPIO_LED_ON +#define Board_GPIO_LED_OFF CC1352R1_LAUNCHXL_GPIO_LED_OFF + +#define Board_GPTIMER0A CC1352R1_LAUNCHXL_GPTIMER0A +#define Board_GPTIMER0B CC1352R1_LAUNCHXL_GPTIMER0B +#define Board_GPTIMER1A CC1352R1_LAUNCHXL_GPTIMER1A +#define Board_GPTIMER1B CC1352R1_LAUNCHXL_GPTIMER1B +#define Board_GPTIMER2A CC1352R1_LAUNCHXL_GPTIMER2A +#define Board_GPTIMER2B CC1352R1_LAUNCHXL_GPTIMER2B +#define Board_GPTIMER3A CC1352R1_LAUNCHXL_GPTIMER3A +#define Board_GPTIMER3B CC1352R1_LAUNCHXL_GPTIMER3B + +#define Board_I2C0 CC1352R1_LAUNCHXL_I2C0 +#define Board_I2C_TMP Board_I2C0 + +#define Board_NVSINTERNAL CC1352R1_LAUNCHXL_NVSCC26XX0 +#define Board_NVSEXTERNAL CC1352R1_LAUNCHXL_NVSSPI25X0 + +#define Board_PIN_BUTTON0 CC1352R1_LAUNCHXL_PIN_BTN1 +#define Board_PIN_BUTTON1 CC1352R1_LAUNCHXL_PIN_BTN2 +#define Board_PIN_BTN1 CC1352R1_LAUNCHXL_PIN_BTN1 +#define Board_PIN_BTN2 CC1352R1_LAUNCHXL_PIN_BTN2 +#define Board_PIN_LED0 CC1352R1_LAUNCHXL_PIN_RLED +#define Board_PIN_LED1 CC1352R1_LAUNCHXL_PIN_GLED +#define Board_PIN_LED2 CC1352R1_LAUNCHXL_PIN_RLED +#define Board_PIN_RLED CC1352R1_LAUNCHXL_PIN_RLED +#define Board_PIN_GLED CC1352R1_LAUNCHXL_PIN_GLED + +#define Board_PWM0 CC1352R1_LAUNCHXL_PWM0 +#define Board_PWM1 CC1352R1_LAUNCHXL_PWM1 +#define Board_PWM2 CC1352R1_LAUNCHXL_PWM2 +#define Board_PWM3 CC1352R1_LAUNCHXL_PWM3 +#define Board_PWM4 CC1352R1_LAUNCHXL_PWM4 +#define Board_PWM5 CC1352R1_LAUNCHXL_PWM5 +#define Board_PWM6 CC1352R1_LAUNCHXL_PWM6 +#define Board_PWM7 CC1352R1_LAUNCHXL_PWM7 + +#define Board_SD0 CC1352R1_LAUNCHXL_SDSPI0 + +#define Board_SPI0 CC1352R1_LAUNCHXL_SPI0 +#define Board_SPI0_MISO CC1352R1_LAUNCHXL_SPI0_MISO +#define Board_SPI0_MOSI CC1352R1_LAUNCHXL_SPI0_MOSI +#define Board_SPI0_CLK CC1352R1_LAUNCHXL_SPI0_CLK +#define Board_SPI0_CSN CC1352R1_LAUNCHXL_SPI0_CSN +#define Board_SPI1 CC1352R1_LAUNCHXL_SPI1 +#define Board_SPI1_MISO CC1352R1_LAUNCHXL_SPI1_MISO +#define Board_SPI1_MOSI CC1352R1_LAUNCHXL_SPI1_MOSI +#define Board_SPI1_CLK CC1352R1_LAUNCHXL_SPI1_CLK +#define Board_SPI1_CSN CC1352R1_LAUNCHXL_SPI1_CSN +#define Board_SPI_FLASH_CS CC1352R1_LAUNCHXL_SPI_FLASH_CS +#define Board_FLASH_CS_ON 0 +#define Board_FLASH_CS_OFF 1 + +#define Board_SPI_MASTER CC1352R1_LAUNCHXL_SPI0 +#define Board_SPI_SLAVE CC1352R1_LAUNCHXL_SPI0 +#define Board_SPI_MASTER_READY CC1352R1_LAUNCHXL_SPI_MASTER_READY +#define Board_SPI_SLAVE_READY CC1352R1_LAUNCHXL_SPI_SLAVE_READY + +#define Board_UART0 CC1352R1_LAUNCHXL_UART0 +#define Board_UART1 CC1352R1_LAUNCHXL_UART1 + +#define Board_WATCHDOG0 CC1352R1_LAUNCHXL_WATCHDOG0 + +/* Board specific I2C addresses */ +#define Board_TMP_ADDR (0x40) +#define Board_SENSORS_BP_TMP_ADDR Board_TMP_ADDR + +#ifdef __cplusplus +} +#endif + +#endif /* __BOARD_H */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/CC1352R1_LAUNCHXL.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/CC1352R1_LAUNCHXL.c new file mode 100644 index 000000000..a9197a4f5 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/CC1352R1_LAUNCHXL.c @@ -0,0 +1,971 @@ +/* + * Copyright (c) 2017-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +/* + * ====================== CC1352R1_LAUNCHXL.c =================================== + * This file is responsible for setting up the board specific items for the + * CC1352R1_LAUNCHXL board. + */ + +#include "contiki.h" + +#include +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/udma.h) +#include DeviceFamily_constructPath(inc/hw_ints.h) +#include DeviceFamily_constructPath(inc/hw_memmap.h) + +#include "CC1352R1_LAUNCHXL.h" + +/* + * =============================== ADCBuf =============================== + */ +#include +#include + +ADCBufCC26X2_Object adcBufCC26xxObjects[CC1352R1_LAUNCHXL_ADCBUFCOUNT]; + +/* + * This table converts a virtual adc channel into a dio and internal analogue + * input signal. This table is necessary for the functioning of the adcBuf + * driver. Comment out unused entries to save flash. Dio and internal signal + * pairs are hardwired. Do not remap them in the table. You may reorder entire + * entries. The mapping of dio and internal signals is package dependent. + */ +const ADCBufCC26X2_AdcChannelLutEntry ADCBufCC26X2_adcChannelLut[CC1352R1_LAUNCHXL_ADCBUF0CHANNELCOUNT] = { + {CC1352R1_LAUNCHXL_DIO23_ANALOG, ADC_COMPB_IN_AUXIO7}, + {CC1352R1_LAUNCHXL_DIO24_ANALOG, ADC_COMPB_IN_AUXIO6}, + {CC1352R1_LAUNCHXL_DIO25_ANALOG, ADC_COMPB_IN_AUXIO5}, + {CC1352R1_LAUNCHXL_DIO26_ANALOG, ADC_COMPB_IN_AUXIO4}, + {CC1352R1_LAUNCHXL_DIO27_ANALOG, ADC_COMPB_IN_AUXIO3}, + {CC1352R1_LAUNCHXL_DIO28_ANALOG, ADC_COMPB_IN_AUXIO2}, + {CC1352R1_LAUNCHXL_DIO29_ANALOG, ADC_COMPB_IN_AUXIO1}, + {PIN_UNASSIGNED, ADC_COMPB_IN_VDDS}, + {PIN_UNASSIGNED, ADC_COMPB_IN_DCOUPL}, + {PIN_UNASSIGNED, ADC_COMPB_IN_VSS}, +}; + +const ADCBufCC26X2_HWAttrs adcBufCC26xxHWAttrs[CC1352R1_LAUNCHXL_ADCBUFCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + .adcChannelLut = ADCBufCC26X2_adcChannelLut, + .gpTimerUnit = CC1352R1_LAUNCHXL_GPTIMER0A, + } +}; + +const ADCBuf_Config ADCBuf_config[CC1352R1_LAUNCHXL_ADCBUFCOUNT] = { + { + &ADCBufCC26X2_fxnTable, + &adcBufCC26xxObjects[CC1352R1_LAUNCHXL_ADCBUF0], + &adcBufCC26xxHWAttrs[CC1352R1_LAUNCHXL_ADCBUF0] + }, +}; + +const uint_least8_t ADCBuf_count = CC1352R1_LAUNCHXL_ADCBUFCOUNT; + +/* + * =============================== ADC =============================== + */ +#include +#include + +ADCCC26XX_Object adcCC26xxObjects[CC1352R1_LAUNCHXL_ADCCOUNT]; + +const ADCCC26XX_HWAttrs adcCC26xxHWAttrs[CC1352R1_LAUNCHXL_ADCCOUNT] = { + { + .adcDIO = CC1352R1_LAUNCHXL_DIO23_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO7, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1352R1_LAUNCHXL_DIO24_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO6, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1352R1_LAUNCHXL_DIO25_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO5, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1352R1_LAUNCHXL_DIO26_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO4, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1352R1_LAUNCHXL_DIO27_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO3, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1352R1_LAUNCHXL_DIO28_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO2, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC1352R1_LAUNCHXL_DIO29_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO1, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_DCOUPL, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_VSS, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_VDDS, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + } +}; + +const ADC_Config ADC_config[CC1352R1_LAUNCHXL_ADCCOUNT] = { + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352R1_LAUNCHXL_ADC0], &adcCC26xxHWAttrs[CC1352R1_LAUNCHXL_ADC0]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352R1_LAUNCHXL_ADC1], &adcCC26xxHWAttrs[CC1352R1_LAUNCHXL_ADC1]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352R1_LAUNCHXL_ADC2], &adcCC26xxHWAttrs[CC1352R1_LAUNCHXL_ADC2]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352R1_LAUNCHXL_ADC3], &adcCC26xxHWAttrs[CC1352R1_LAUNCHXL_ADC3]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352R1_LAUNCHXL_ADC4], &adcCC26xxHWAttrs[CC1352R1_LAUNCHXL_ADC4]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352R1_LAUNCHXL_ADC5], &adcCC26xxHWAttrs[CC1352R1_LAUNCHXL_ADC5]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352R1_LAUNCHXL_ADC6], &adcCC26xxHWAttrs[CC1352R1_LAUNCHXL_ADC6]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352R1_LAUNCHXL_ADCDCOUPL], &adcCC26xxHWAttrs[CC1352R1_LAUNCHXL_ADCDCOUPL]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352R1_LAUNCHXL_ADCVSS], &adcCC26xxHWAttrs[CC1352R1_LAUNCHXL_ADCVSS]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1352R1_LAUNCHXL_ADCVDDS], &adcCC26xxHWAttrs[CC1352R1_LAUNCHXL_ADCVDDS]}, +}; + +const uint_least8_t ADC_count = CC1352R1_LAUNCHXL_ADCCOUNT; + +/* + * =============================== ECDH =============================== + */ +#include +#include + +ECDHCC26X2_Object ecdhCC26X2Objects[CC1352R1_LAUNCHXL_ECDHCOUNT]; + +const ECDHCC26X2_HWAttrs ecdhCC26X2HWAttrs[CC1352R1_LAUNCHXL_ECDHCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const ECDH_Config ECDH_config[CC1352R1_LAUNCHXL_ECDHCOUNT] = { + { + .object = &ecdhCC26X2Objects[CC1352R1_LAUNCHXL_ECDH0], + .hwAttrs = &ecdhCC26X2HWAttrs[CC1352R1_LAUNCHXL_ECDH0] + }, +}; + +const uint_least8_t ECDH_count = CC1352R1_LAUNCHXL_ECDHCOUNT; + +/* + * =============================== ECDSA =============================== + */ +#include +#include + +ECDSACC26X2_Object ecdsaCC26X2Objects[CC1352R1_LAUNCHXL_ECDSACOUNT]; + +const ECDSACC26X2_HWAttrs ecdsaCC26X2HWAttrs[CC1352R1_LAUNCHXL_ECDSACOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const ECDSA_Config ECDSA_config[CC1352R1_LAUNCHXL_ECDSACOUNT] = { + { + .object = &ecdsaCC26X2Objects[CC1352R1_LAUNCHXL_ECDSA0], + .hwAttrs = &ecdsaCC26X2HWAttrs[CC1352R1_LAUNCHXL_ECDSA0] + }, +}; + +const uint_least8_t ECDSA_count = CC1352R1_LAUNCHXL_ECDSACOUNT; + +/* + * =============================== ECJPAKE =============================== + */ +#include +#include + +ECJPAKECC26X2_Object ecjpakeCC26X2Objects[CC1352R1_LAUNCHXL_ECJPAKECOUNT]; + +const ECJPAKECC26X2_HWAttrs ecjpakeCC26X2HWAttrs[CC1352R1_LAUNCHXL_ECJPAKECOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const ECJPAKE_Config ECJPAKE_config[CC1352R1_LAUNCHXL_ECJPAKECOUNT] = { + { + .object = &ecjpakeCC26X2Objects[CC1352R1_LAUNCHXL_ECJPAKE0], + .hwAttrs = &ecjpakeCC26X2HWAttrs[CC1352R1_LAUNCHXL_ECJPAKE0] + }, +}; + +const uint_least8_t ECJPAKE_count = CC1352R1_LAUNCHXL_ECJPAKECOUNT; + + +/* + * =============================== SHA2 =============================== + */ +#include +#include + +SHA2CC26X2_Object sha2CC26X2Objects[CC1352R1_LAUNCHXL_SHA2COUNT]; + +const SHA2CC26X2_HWAttrs sha2CC26X2HWAttrs[CC1352R1_LAUNCHXL_SHA2COUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const SHA2_Config SHA2_config[CC1352R1_LAUNCHXL_SHA2COUNT] = { + { + .object = &sha2CC26X2Objects[CC1352R1_LAUNCHXL_SHA20], + .hwAttrs = &sha2CC26X2HWAttrs[CC1352R1_LAUNCHXL_SHA20] + }, +}; + +const uint_least8_t SHA2_count = CC1352R1_LAUNCHXL_SHA2COUNT; + +/* + * =============================== AESCCM =============================== + */ +#include +#include + +AESCCMCC26XX_Object aesccmCC26XXObjects[CC1352R1_LAUNCHXL_AESCCMCOUNT]; + +const AESCCMCC26XX_HWAttrs aesccmCC26XXHWAttrs[CC1352R1_LAUNCHXL_AESCCMCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const AESCCM_Config AESCCM_config[CC1352R1_LAUNCHXL_AESCCMCOUNT] = { + { + .object = &aesccmCC26XXObjects[CC1352R1_LAUNCHXL_AESCCM0], + .hwAttrs = &aesccmCC26XXHWAttrs[CC1352R1_LAUNCHXL_AESCCM0] + }, +}; + +const uint_least8_t AESCCM_count = CC1352R1_LAUNCHXL_AESCCMCOUNT; + +/* + * =============================== AESECB =============================== + */ +#include +#include + +AESECBCC26XX_Object aesecbCC26XXObjects[CC1352R1_LAUNCHXL_AESECBCOUNT]; + +const AESECBCC26XX_HWAttrs aesecbCC26XXHWAttrs[CC1352R1_LAUNCHXL_AESECBCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const AESECB_Config AESECB_config[CC1352R1_LAUNCHXL_AESECBCOUNT] = { + { + .object = &aesecbCC26XXObjects[CC1352R1_LAUNCHXL_AESECB0], + .hwAttrs = &aesecbCC26XXHWAttrs[CC1352R1_LAUNCHXL_AESECB0] + }, +}; + +const uint_least8_t AESECB_count = CC1352R1_LAUNCHXL_AESECBCOUNT; + +/* + * =============================== GPIO =============================== + */ +#include +#include + +/* + * Array of Pin configurations + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC1352R1_LAUNCHXL.h + * NOTE: Pins not used for interrupts should be placed at the end of the + * array. Callback entries can be omitted from callbacks array to + * reduce memory usage. + */ +GPIO_PinConfig gpioPinConfigs[] = { + /* Input pins */ + GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG, /* Button 0 */ + GPIOCC26XX_DIO_14 | GPIO_DO_NOT_CONFIG, /* Button 1 */ + + GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG, /* CC1352R1_LAUNCHXL_SPI_MASTER_READY */ + GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG, /* CC1352R1_LAUNCHXL_SPI_SLAVE_READY */ + + /* Output pins */ + GPIOCC26XX_DIO_07 | GPIO_DO_NOT_CONFIG, /* Green LED */ + GPIOCC26XX_DIO_06 | GPIO_DO_NOT_CONFIG, /* Red LED */ + + /* SPI Flash CSN */ + GPIOCC26XX_DIO_20 | GPIO_DO_NOT_CONFIG, + + /* SD CS */ + GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG, +}; + +/* + * Array of callback function pointers + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC1352R1_LAUNCH.h + * NOTE: Pins not used for interrupts can be omitted from callbacks array to + * reduce memory usage (if placed at end of gpioPinConfigs array). + */ +GPIO_CallbackFxn gpioCallbackFunctions[] = { + NULL, /* Button 0 */ + NULL, /* Button 1 */ + NULL, /* CC1352R1_LAUNCHXL_SPI_MASTER_READY */ + NULL, /* CC1352R1_LAUNCHXL_SPI_SLAVE_READY */ +}; + +const GPIOCC26XX_Config GPIOCC26XX_config = { + .pinConfigs = (GPIO_PinConfig *)gpioPinConfigs, + .callbacks = (GPIO_CallbackFxn *)gpioCallbackFunctions, + .numberOfPinConfigs = CC1352R1_LAUNCHXL_GPIOCOUNT, + .numberOfCallbacks = sizeof(gpioCallbackFunctions)/sizeof(GPIO_CallbackFxn), + .intPriority = (~0) +}; + +/* + * =============================== GPTimer =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include + +GPTimerCC26XX_Object gptimerCC26XXObjects[CC1352R1_LAUNCHXL_GPTIMERCOUNT]; + +const GPTimerCC26XX_HWAttrs gptimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_GPTIMERPARTSCOUNT] = { + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0A, }, + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0B, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1A, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1B, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2A, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2B, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3A, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3B, }, +}; + +const GPTimerCC26XX_Config GPTimerCC26XX_config[CC1352R1_LAUNCHXL_GPTIMERPARTSCOUNT] = { + { &gptimerCC26XXObjects[CC1352R1_LAUNCHXL_GPTIMER0], &gptimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_GPTIMER0A], GPT_A }, + { &gptimerCC26XXObjects[CC1352R1_LAUNCHXL_GPTIMER0], &gptimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_GPTIMER0B], GPT_B }, + { &gptimerCC26XXObjects[CC1352R1_LAUNCHXL_GPTIMER1], &gptimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_GPTIMER1A], GPT_A }, + { &gptimerCC26XXObjects[CC1352R1_LAUNCHXL_GPTIMER1], &gptimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_GPTIMER1B], GPT_B }, + { &gptimerCC26XXObjects[CC1352R1_LAUNCHXL_GPTIMER2], &gptimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_GPTIMER2A], GPT_A }, + { &gptimerCC26XXObjects[CC1352R1_LAUNCHXL_GPTIMER2], &gptimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_GPTIMER2B], GPT_B }, + { &gptimerCC26XXObjects[CC1352R1_LAUNCHXL_GPTIMER3], &gptimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_GPTIMER3A], GPT_A }, + { &gptimerCC26XXObjects[CC1352R1_LAUNCHXL_GPTIMER3], &gptimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_GPTIMER3B], GPT_B }, +}; + +/* + * =============================== I2C =============================== +*/ +#include +#include + +#if TI_I2C_CONF_ENABLE + +I2CCC26XX_Object i2cCC26xxObjects[CC1352R1_LAUNCHXL_I2CCOUNT]; + +const I2CCC26XX_HWAttrsV1 i2cCC26xxHWAttrs[CC1352R1_LAUNCHXL_I2CCOUNT] = { +#if TI_I2C_CONF_I2C0_ENABLE + { + .baseAddr = I2C0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_I2C0, + .intNum = INT_I2C_IRQ, + .intPriority = ~0, + .swiPriority = 0, + .sdaPin = CC1352R1_LAUNCHXL_I2C0_SDA0, + .sclPin = CC1352R1_LAUNCHXL_I2C0_SCL0, + }, +#endif +}; + +const I2C_Config I2C_config[CC1352R1_LAUNCHXL_I2CCOUNT] = { +#if TI_I2C_CONF_I2C0_ENABLE + { + .fxnTablePtr = &I2CCC26XX_fxnTable, + .object = &i2cCC26xxObjects[CC1352R1_LAUNCHXL_I2C0], + .hwAttrs = &i2cCC26xxHWAttrs[CC1352R1_LAUNCHXL_I2C0] + }, +#endif +}; + +const uint_least8_t I2C_count = CC1352R1_LAUNCHXL_I2CCOUNT; + +#endif /* TI_I2C_CONF_ENABLE */ + +/* + * =============================== NVS =============================== + */ +#include +#include +#include + +#define NVS_REGIONS_BASE 0x48000 +#define SECTORSIZE 0x2000 +#define REGIONSIZE (SECTORSIZE * 4) + +#if TI_NVS_CONF_ENABLE + +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + +/* + * Reserve flash sectors for NVS driver use by placing an uninitialized byte + * array at the desired flash address. + */ +#if defined(__TI_COMPILER_VERSION__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +#pragma LOCATION(flashBuf, NVS_REGIONS_BASE); +#pragma NOINIT(flashBuf); +static char flashBuf[REGIONSIZE]; + +#elif defined(__IAR_SYSTEMS_ICC__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +static __no_init char flashBuf[REGIONSIZE] @ NVS_REGIONS_BASE; + +#elif defined(__GNUC__) + +/* + * Place the flash buffers in the .nvs section created in the gcc linker file. + * The .nvs section enforces alignment on a sector boundary but may + * be placed anywhere in flash memory. If desired the .nvs section can be set + * to a fixed address by changing the following in the gcc linker file: + * + * .nvs (FIXED_FLASH_ADDR) (NOLOAD) : AT (FIXED_FLASH_ADDR) { + * *(.nvs) + * } > REGION_TEXT + */ +__attribute__ ((section (".nvs"))) +static char flashBuf[REGIONSIZE]; + +#endif + +/* Allocate objects for NVS Internal Regions */ +NVSCC26XX_Object nvsCC26xxObjects[1]; + +/* Hardware attributes for NVS Internal Regions */ +const NVSCC26XX_HWAttrs nvsCC26xxHWAttrs[1] = { + { + .regionBase = (void *)flashBuf, + .regionSize = REGIONSIZE, + }, +}; + +#endif /* TI_NVS_CONF_NVS_INTERNAL_ENABLE */ + +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + +#define SPISECTORSIZE 0x1000 +#define SPIREGIONSIZE (SPISECTORSIZE * 32) +#define VERIFYBUFSIZE 64 + +static uint8_t verifyBuf[VERIFYBUFSIZE]; + +/* Allocate objects for NVS External Regions */ +NVSSPI25X_Object nvsSPI25XObjects[1]; + +/* Hardware attributes for NVS External Regions */ +const NVSSPI25X_HWAttrs nvsSPI25XHWAttrs[1] = { + { + .regionBaseOffset = 0, + .regionSize = SPIREGIONSIZE, + .sectorSize = SPISECTORSIZE, + .verifyBuf = verifyBuf, + .verifyBufSize = VERIFYBUFSIZE, + .spiHandle = NULL, + .spiIndex = 0, + .spiBitRate = 4000000, + .spiCsnGpioIndex = CC1352R1_LAUNCHXL_GPIO_SPI_FLASH_CS, + }, +}; + +#endif /* TI_NVS_CONF_NVS_EXTERNAL_ENABLE */ + +/* NVS Region index 0 and 1 refer to NVS and NVS SPI respectively */ +const NVS_Config NVS_config[CC1352R1_LAUNCHXL_NVSCOUNT] = { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + { + .fxnTablePtr = &NVSCC26XX_fxnTable, + .object = &nvsCC26xxObjects[0], + .hwAttrs = &nvsCC26xxHWAttrs[0], + }, +#endif +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + { + .fxnTablePtr = &NVSSPI25X_fxnTable, + .object = &nvsSPI25XObjects[0], + .hwAttrs = &nvsSPI25XHWAttrs[0], + }, +#endif +}; + +const uint_least8_t NVS_count = CC1352R1_LAUNCHXL_NVSCOUNT; + +#endif /* TI_NVS_CONF_ENABLE */ + +/* + * =============================== PIN =============================== + */ +#include +#include + +const PIN_Config BoardGpioInitTable[] = { + + CC1352R1_LAUNCHXL_PIN_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC1352R1_LAUNCHXL_PIN_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC1352R1_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC1352R1_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC1352R1_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ + CC1352R1_LAUNCHXL_UART0_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */ + CC1352R1_LAUNCHXL_UART0_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */ + CC1352R1_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */ + CC1352R1_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */ + CC1352R1_LAUNCHXL_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI clock */ + CC1352R1_LAUNCHXL_DIO30_RF_SUB1GHZ | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* RF SW Switch defaults to 2.4GHz path */ + PIN_TERMINATE +}; + +const PINCC26XX_HWAttrs PINCC26XX_hwAttrs = { + .intPriority = ~0, + .swiPriority = 0 +}; + +/* + * =============================== Power =============================== + */ +#include +#include + +const PowerCC26X2_Config PowerCC26X2_config = { + .policyInitFxn = NULL, + .policyFxn = &PowerCC26XX_standbyPolicy, + .calibrateFxn = &PowerCC26XX_calibrate, + .enablePolicy = true, + .calibrateRCOSC_LF = true, + .calibrateRCOSC_HF = true, +}; + +/* + * =============================== PWM =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include +#include + +PWMTimerCC26XX_Object pwmtimerCC26xxObjects[CC1352R1_LAUNCHXL_PWMCOUNT]; + +const PWMTimerCC26XX_HwAttrs pwmtimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_PWMCOUNT] = { + { .pwmPin = CC1352R1_LAUNCHXL_PWMPIN0, .gpTimerUnit = CC1352R1_LAUNCHXL_GPTIMER0A }, + { .pwmPin = CC1352R1_LAUNCHXL_PWMPIN1, .gpTimerUnit = CC1352R1_LAUNCHXL_GPTIMER0B }, + { .pwmPin = CC1352R1_LAUNCHXL_PWMPIN2, .gpTimerUnit = CC1352R1_LAUNCHXL_GPTIMER1A }, + { .pwmPin = CC1352R1_LAUNCHXL_PWMPIN3, .gpTimerUnit = CC1352R1_LAUNCHXL_GPTIMER1B }, + { .pwmPin = CC1352R1_LAUNCHXL_PWMPIN4, .gpTimerUnit = CC1352R1_LAUNCHXL_GPTIMER2A }, + { .pwmPin = CC1352R1_LAUNCHXL_PWMPIN5, .gpTimerUnit = CC1352R1_LAUNCHXL_GPTIMER2B }, + { .pwmPin = CC1352R1_LAUNCHXL_PWMPIN6, .gpTimerUnit = CC1352R1_LAUNCHXL_GPTIMER3A }, + { .pwmPin = CC1352R1_LAUNCHXL_PWMPIN7, .gpTimerUnit = CC1352R1_LAUNCHXL_GPTIMER3B }, +}; + +const PWM_Config PWM_config[CC1352R1_LAUNCHXL_PWMCOUNT] = { + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352R1_LAUNCHXL_PWM0], &pwmtimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_PWM0] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352R1_LAUNCHXL_PWM1], &pwmtimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_PWM1] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352R1_LAUNCHXL_PWM2], &pwmtimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_PWM2] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352R1_LAUNCHXL_PWM3], &pwmtimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_PWM3] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352R1_LAUNCHXL_PWM4], &pwmtimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_PWM4] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352R1_LAUNCHXL_PWM5], &pwmtimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_PWM5] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352R1_LAUNCHXL_PWM6], &pwmtimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_PWM6] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1352R1_LAUNCHXL_PWM7], &pwmtimerCC26xxHWAttrs[CC1352R1_LAUNCHXL_PWM7] }, +}; + +const uint_least8_t PWM_count = CC1352R1_LAUNCHXL_PWMCOUNT; + +/* + * =============================== RF Driver =============================== + */ +#include + +/* + * Board-specific callback function to set the correct antenna path. + * + * This function is called by the RF driver on global driver events. + * It contains a default implementation to set the correct antenna path. + * This function is defined in the file CC1352R1_LAUNCHXL_fxns.c + */ +extern void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg); + +const RFCC26XX_HWAttrsV2 RFCC26XX_hwAttrs = { + .hwiPriority = ~0, /* Lowest HWI priority */ + .swiPriority = 0, /* Lowest SWI priority */ + .xoscHfAlwaysNeeded = true, /* Keep XOSC dependency while in stanby */ + + /* Register the board specific callback */ + .globalCallback = &rfDriverCallback, + + /* Subscribe the callback to both events */ + .globalEventMask = RF_GlobalEventRadioSetup | RF_GlobalEventRadioPowerDown +}; + +/* + * =============================== SD =============================== + */ +#include +#include + +#if TI_SD_CONF_ENABLE + +#if !(TI_SPI_CONF_SPI0_ENABLE) +#error "SD driver requires SPI0 enabled" +#endif + +SDSPI_Object sdspiObjects[CC1352R1_LAUNCHXL_SDCOUNT]; + +const SDSPI_HWAttrs sdspiHWAttrs[CC1352R1_LAUNCHXL_SDCOUNT] = { + { + .spiIndex = CC1352R1_LAUNCHXL_SPI0, + .spiCsGpioIndex = CC1352R1_LAUNCHXL_SDSPI_CS + } +}; + +const SD_Config SD_config[CC1352R1_LAUNCHXL_SDCOUNT] = { + { + .fxnTablePtr = &SDSPI_fxnTable, + .object = &sdspiObjects[CC1352R1_LAUNCHXL_SDSPI0], + .hwAttrs = &sdspiHWAttrs[CC1352R1_LAUNCHXL_SDSPI0] + }, +}; + +const uint_least8_t SD_count = CC1352R1_LAUNCHXL_SDCOUNT; + +#endif /* TI_SD_CONF_ENABLE */ + +/* + * =============================== SPI DMA =============================== + */ +#include +#include + +#if TI_SPI_CONF_ENABLE + +SPICC26XXDMA_Object spiCC26XXDMAObjects[CC1352R1_LAUNCHXL_SPICOUNT]; + +/* + * NOTE: The SPI instances below can be used by the SD driver to communicate + * with a SD card via SPI. The 'defaultTxBufValue' fields below are set to 0xFF + * to satisfy the SDSPI driver requirement. + */ +const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[CC1352R1_LAUNCHXL_SPICOUNT] = { +#if TI_SPI_CONF_SPI0_ENABLE + { + .baseAddr = SSI0_BASE, + .intNum = INT_SSI0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .powerMngrId = PowerCC26XX_PERIPH_SSI0, + .defaultTxBufValue = 0xFF, + .rxChannelBitMask = 1< +#include + +TRNGCC26X2_Object trngCC26X2Object[CC1352R1_LAUNCHXL_TRNGCOUNT]; + +const TRNGCC26X2_HWAttrs trngCC26X2HWAttrs[CC1352R1_LAUNCHXL_TRNGCOUNT] = { + { + .swiPriority = 0, + .intPriority = ~0, + } +}; + +const TRNG_Config TRNG_config[] = { + { &trngCC26X2Object[0], &trngCC26X2HWAttrs[0] }, +}; + +const uint8_t TRNG_count = CC1352R1_LAUNCHXL_TRNGCOUNT; + + +/* + * =============================== UART =============================== + */ +#include +#include + +#if TI_UART_CONF_ENABLE + +UARTCC26XX_Object uartCC26XXObjects[CC1352R1_LAUNCHXL_UARTCOUNT]; + +uint8_t uartCC26XXRingBuffer[CC1352R1_LAUNCHXL_UARTCOUNT][32]; + +const UARTCC26XX_HWAttrsV2 uartCC26XXHWAttrs[CC1352R1_LAUNCHXL_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .baseAddr = UART0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UART0, + .intNum = INT_UART0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .txPin = CC1352R1_LAUNCHXL_UART0_TX, + .rxPin = CC1352R1_LAUNCHXL_UART0_RX, + .ctsPin = PIN_UNASSIGNED, + .rtsPin = PIN_UNASSIGNED, + .ringBufPtr = uartCC26XXRingBuffer[CC1352R1_LAUNCHXL_UART0], + .ringBufSize = sizeof(uartCC26XXRingBuffer[CC1352R1_LAUNCHXL_UART0]), + .txIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_1_8, + .rxIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_4_8, + .errorFxn = NULL + }, +#endif +#if TI_UART_CONF_UART1_ENABLE + { + .baseAddr = UART1_BASE, + .powerMngrId = PowerCC26X2_PERIPH_UART1, + .intNum = INT_UART1_COMB, + .intPriority = ~0, + .swiPriority = 0, + .txPin = CC1352R1_LAUNCHXL_UART1_TX, + .rxPin = CC1352R1_LAUNCHXL_UART1_RX, + .ctsPin = PIN_UNASSIGNED, + .rtsPin = PIN_UNASSIGNED, + .ringBufPtr = uartCC26XXRingBuffer[CC1352R1_LAUNCHXL_UART1], + .ringBufSize = sizeof(uartCC26XXRingBuffer[CC1352R1_LAUNCHXL_UART1]), + .txIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_1_8, + .rxIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_4_8, + .errorFxn = NULL + }, +#endif +}; + +const UART_Config UART_config[CC1352R1_LAUNCHXL_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .fxnTablePtr = &UARTCC26XX_fxnTable, + .object = &uartCC26XXObjects[CC1352R1_LAUNCHXL_UART0], + .hwAttrs = &uartCC26XXHWAttrs[CC1352R1_LAUNCHXL_UART0] + }, +#endif +#if TI_UART_CONF_UART1_ENABLE + { + .fxnTablePtr = &UARTCC26XX_fxnTable, + .object = &uartCC26XXObjects[CC1352R1_LAUNCHXL_UART1], + .hwAttrs = &uartCC26XXHWAttrs[CC1352R1_LAUNCHXL_UART1] + }, +#endif +}; + +const uint_least8_t UART_count = CC1352R1_LAUNCHXL_UARTCOUNT; + +#endif /* TI_UART_CONF_ENABLE */ + +/* + * =============================== UDMA =============================== + */ +#include + +UDMACC26XX_Object udmaObjects[CC1352R1_LAUNCHXL_UDMACOUNT]; + +const UDMACC26XX_HWAttrs udmaHWAttrs[CC1352R1_LAUNCHXL_UDMACOUNT] = { + { + .baseAddr = UDMA0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UDMA, + .intNum = INT_DMA_ERR, + .intPriority = ~0 + } +}; + +const UDMACC26XX_Config UDMACC26XX_config[CC1352R1_LAUNCHXL_UDMACOUNT] = { + { + .object = &udmaObjects[CC1352R1_LAUNCHXL_UDMA0], + .hwAttrs = &udmaHWAttrs[CC1352R1_LAUNCHXL_UDMA0] + }, +}; + + + +/* + * =============================== Watchdog =============================== + */ +#include +#include + +WatchdogCC26XX_Object watchdogCC26XXObjects[CC1352R1_LAUNCHXL_WATCHDOGCOUNT]; + +const WatchdogCC26XX_HWAttrs watchdogCC26XXHWAttrs[CC1352R1_LAUNCHXL_WATCHDOGCOUNT] = { + { + .baseAddr = WDT_BASE, + .reloadValue = 1000 /* Reload value in milliseconds */ + }, +}; + +const Watchdog_Config Watchdog_config[CC1352R1_LAUNCHXL_WATCHDOGCOUNT] = { + { + .fxnTablePtr = &WatchdogCC26XX_fxnTable, + .object = &watchdogCC26XXObjects[CC1352R1_LAUNCHXL_WATCHDOG0], + .hwAttrs = &watchdogCC26XXHWAttrs[CC1352R1_LAUNCHXL_WATCHDOG0] + }, +}; + +const uint_least8_t Watchdog_count = CC1352R1_LAUNCHXL_WATCHDOGCOUNT; + +/* + * Board-specific initialization function to disable external flash. + * This function is defined in the file CC1352R1_LAUNCHXL_fxns.c + */ +extern void Board_initHook(void); + +/* + * ======== CC1352R1_LAUNCHXL_initGeneral ======== + */ +void CC1352R1_LAUNCHXL_initGeneral(void) +{ + Power_init(); + + if (PIN_init(BoardGpioInitTable) != PIN_SUCCESS) { + /* Error with PIN_init */ + while (1); + } + + /* Perform board-specific initialization */ + Board_initHook(); +} diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/CC1352R1_LAUNCHXL.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/CC1352R1_LAUNCHXL.h new file mode 100644 index 000000000..b6362cf9f --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/CC1352R1_LAUNCHXL.h @@ -0,0 +1,447 @@ +/* + * Copyright (c) 2017-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 CC1352R1_LAUNCHXL.h + * + * @brief CC1352R1_LAUNCHXL Board Specific header file. + * + * The CC1352R1_LAUNCHXL header file should be included in an application as + * follows: + * @code + * #include "CC1352R1_LAUNCHXL.h" + * @endcode + * + * =========================================================================== + */ +#ifndef __CC1352R1_LAUNCHXL_BOARD_H__ +#define __CC1352R1_LAUNCHXL_BOARD_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "contiki-conf.h" + +/* Includes */ +#include +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) + +/* Externs */ +extern const PIN_Config BoardGpioInitTable[]; + +/* Defines */ +#define CC1352R1_LAUNCHXL + +/* Mapping of pins to board signals using general board aliases + * + */ + +/* Mapping of pins to board signals using general board aliases + * + */ +/* Analog Capable DIOs */ +#define CC1352R1_LAUNCHXL_DIO23_ANALOG IOID_23 +#define CC1352R1_LAUNCHXL_DIO24_ANALOG IOID_24 +#define CC1352R1_LAUNCHXL_DIO25_ANALOG IOID_25 +#define CC1352R1_LAUNCHXL_DIO26_ANALOG IOID_26 +#define CC1352R1_LAUNCHXL_DIO27_ANALOG IOID_27 +#define CC1352R1_LAUNCHXL_DIO28_ANALOG IOID_28 +#define CC1352R1_LAUNCHXL_DIO29_ANALOG IOID_29 + +/* Antenna switch */ +#define CC1352R1_LAUNCHXL_DIO30_RF_SUB1GHZ IOID_30 + +/* Digital IOs */ +#define CC1352R1_LAUNCHXL_DIO12 IOID_12 +#define CC1352R1_LAUNCHXL_DIO15 IOID_15 +#define CC1352R1_LAUNCHXL_DIO16_TDO IOID_16 +#define CC1352R1_LAUNCHXL_DIO17_TDI IOID_17 +#define CC1352R1_LAUNCHXL_DIO21 IOID_21 +#define CC1352R1_LAUNCHXL_DIO22 IOID_22 + +/* Discrete Inputs */ +#define CC1352R1_LAUNCHXL_PIN_BTN1 IOID_15 +#define CC1352R1_LAUNCHXL_PIN_BTN2 IOID_14 + +/* GPIO */ +#define CC1352R1_LAUNCHXL_GPIO_LED_ON 1 +#define CC1352R1_LAUNCHXL_GPIO_LED_OFF 0 + +/* I2C */ +#define CC1352R1_LAUNCHXL_I2C0_SCL0 IOID_4 +#define CC1352R1_LAUNCHXL_I2C0_SDA0 IOID_5 + + +/* LEDs */ +#define CC1352R1_LAUNCHXL_PIN_LED_ON 1 +#define CC1352R1_LAUNCHXL_PIN_LED_OFF 0 +#define CC1352R1_LAUNCHXL_PIN_RLED IOID_6 +#define CC1352R1_LAUNCHXL_PIN_GLED IOID_7 + +/* PWM Outputs */ +#define CC1352R1_LAUNCHXL_PWMPIN0 CC1352R1_LAUNCHXL_PIN_RLED +#define CC1352R1_LAUNCHXL_PWMPIN1 CC1352R1_LAUNCHXL_PIN_GLED +#define CC1352R1_LAUNCHXL_PWMPIN2 PIN_UNASSIGNED +#define CC1352R1_LAUNCHXL_PWMPIN3 PIN_UNASSIGNED +#define CC1352R1_LAUNCHXL_PWMPIN4 PIN_UNASSIGNED +#define CC1352R1_LAUNCHXL_PWMPIN5 PIN_UNASSIGNED +#define CC1352R1_LAUNCHXL_PWMPIN6 PIN_UNASSIGNED +#define CC1352R1_LAUNCHXL_PWMPIN7 PIN_UNASSIGNED + +/* SPI */ +#define CC1352R1_LAUNCHXL_SPI_FLASH_CS IOID_20 +#define CC1352R1_LAUNCHXL_FLASH_CS_ON 0 +#define CC1352R1_LAUNCHXL_FLASH_CS_OFF 1 + +/* SPI Board */ +#define CC1352R1_LAUNCHXL_SPI0_MISO IOID_8 /* RF1.20 */ +#define CC1352R1_LAUNCHXL_SPI0_MOSI IOID_9 /* RF1.18 */ +#define CC1352R1_LAUNCHXL_SPI0_CLK IOID_10 /* RF1.16 */ +#define CC1352R1_LAUNCHXL_SPI0_CSN PIN_UNASSIGNED +#define CC1352R1_LAUNCHXL_SPI1_MISO PIN_UNASSIGNED +#define CC1352R1_LAUNCHXL_SPI1_MOSI PIN_UNASSIGNED +#define CC1352R1_LAUNCHXL_SPI1_CLK PIN_UNASSIGNED +#define CC1352R1_LAUNCHXL_SPI1_CSN PIN_UNASSIGNED + +/* UART Board */ +#define CC1352R1_LAUNCHXL_UART0_RX IOID_12 /* RXD */ +#define CC1352R1_LAUNCHXL_UART0_TX IOID_13 /* TXD */ +#define CC1352R1_LAUNCHXL_UART0_CTS IOID_19 /* CTS */ +#define CC1352R1_LAUNCHXL_UART0_RTS IOID_18 /* RTS */ +#define CC1352R1_LAUNCHXL_UART1_RX PIN_UNASSIGNED +#define CC1352R1_LAUNCHXL_UART1_TX PIN_UNASSIGNED +#define CC1352R1_LAUNCHXL_UART1_CTS PIN_UNASSIGNED +#define CC1352R1_LAUNCHXL_UART1_RTS PIN_UNASSIGNED +/* For backward compatibility */ +#define CC1352R1_LAUNCHXL_UART_RX CC1352R1_LAUNCHXL_UART0_RX +#define CC1352R1_LAUNCHXL_UART_TX CC1352R1_LAUNCHXL_UART0_TX +#define CC1352R1_LAUNCHXL_UART_CTS CC1352R1_LAUNCHXL_UART0_CTS +#define CC1352R1_LAUNCHXL_UART_RTS CC1352R1_LAUNCHXL_UART0_RTS + +/*! + * @brief Initialize the general board specific settings + * + * This function initializes the general board specific settings. + */ +void CC1352R1_LAUNCHXL_initGeneral(void); + +/*! + * @brief Shut down the external flash present on the board files + * + * This function bitbangs the SPI sequence necessary to turn off + * the external flash on LaunchPads. + */ +void CC1352R1_LAUNCHXL_shutDownExtFlash(void); + +/*! + * @brief Wake up the external flash present on the board files + * + * This function toggles the chip select for the amount of time needed + * to wake the chip up. + */ +void CC1352R1_LAUNCHXL_wakeUpExtFlash(void); + +/*! + * @def CC1352R1_LAUNCHXL_ADCBufName + * @brief Enum of ADCs + */ +typedef enum CC1352R1_LAUNCHXL_ADCBufName { + CC1352R1_LAUNCHXL_ADCBUF0 = 0, + + CC1352R1_LAUNCHXL_ADCBUFCOUNT +} CC1352R1_LAUNCHXL_ADCBufName; + +/*! + * @def CC1352R1_LAUNCHXL_ADCBuf0ChannelName + * @brief Enum of ADCBuf channels + */ +typedef enum CC1352R1_LAUNCHXL_ADCBuf0ChannelName { + CC1352R1_LAUNCHXL_ADCBUF0CHANNEL0 = 0, + CC1352R1_LAUNCHXL_ADCBUF0CHANNEL1, + CC1352R1_LAUNCHXL_ADCBUF0CHANNEL2, + CC1352R1_LAUNCHXL_ADCBUF0CHANNEL3, + CC1352R1_LAUNCHXL_ADCBUF0CHANNEL4, + CC1352R1_LAUNCHXL_ADCBUF0CHANNEL5, + CC1352R1_LAUNCHXL_ADCBUF0CHANNEL6, + CC1352R1_LAUNCHXL_ADCBUF0CHANNELVDDS, + CC1352R1_LAUNCHXL_ADCBUF0CHANNELDCOUPL, + CC1352R1_LAUNCHXL_ADCBUF0CHANNELVSS, + + CC1352R1_LAUNCHXL_ADCBUF0CHANNELCOUNT +} CC1352R1_LAUNCHXL_ADCBuf0ChannelName; + +/*! + * @def CC1352R1_LAUNCHXL_ADCName + * @brief Enum of ADCs + */ +typedef enum CC1352R1_LAUNCHXL_ADCName { + CC1352R1_LAUNCHXL_ADC0 = 0, + CC1352R1_LAUNCHXL_ADC1, + CC1352R1_LAUNCHXL_ADC2, + CC1352R1_LAUNCHXL_ADC3, + CC1352R1_LAUNCHXL_ADC4, + CC1352R1_LAUNCHXL_ADC5, + CC1352R1_LAUNCHXL_ADC6, + CC1352R1_LAUNCHXL_ADCDCOUPL, + CC1352R1_LAUNCHXL_ADCVSS, + CC1352R1_LAUNCHXL_ADCVDDS, + + CC1352R1_LAUNCHXL_ADCCOUNT +} CC1352R1_LAUNCHXL_ADCName; + +/*! + * @def CC1352R1_LAUNCHXL_ECDHName + * @brief Enum of ECDH names + */ +typedef enum CC1352R1_LAUNCHXL_ECDHName { + CC1352R1_LAUNCHXL_ECDH0 = 0, + + CC1352R1_LAUNCHXL_ECDHCOUNT +} CC1352R1_LAUNCHXL_ECDHName; + +/*! + * @def CC1352R1_LAUNCHXL_ECDSAName + * @brief Enum of ECDSA names + */ +typedef enum CC1352R1_LAUNCHXL_ECDSAName { + CC1352R1_LAUNCHXL_ECDSA0 = 0, + + CC1352R1_LAUNCHXL_ECDSACOUNT +} CC1352R1_LAUNCHXL_ECDSAName; + +/*! + * @def CC1352R1_LAUNCHXL_ECJPAKEName + * @brief Enum of ECJPAKE names + */ +typedef enum CC1352R1_LAUNCHXL_ECJPAKEName { + CC1352R1_LAUNCHXL_ECJPAKE0 = 0, + + CC1352R1_LAUNCHXL_ECJPAKECOUNT +} CC1352R1_LAUNCHXL_ECJPAKEName; + +/*! + * @def CC1352R1_LAUNCHXL_AESCCMName + * @brief Enum of AESCCM names + */ +typedef enum CC1352R1_LAUNCHXL_AESCCMName { + CC1352R1_LAUNCHXL_AESCCM0 = 0, + + CC1352R1_LAUNCHXL_AESCCMCOUNT +} CC1352R1_LAUNCHXL_AESCCMName; + +/*! + * @def CC1352R1_LAUNCHXL_AESECBName + * @brief Enum of AESECB names + */ +typedef enum CC1352R1_LAUNCHXL_AESECBName { + CC1352R1_LAUNCHXL_AESECB0 = 0, + + CC1352R1_LAUNCHXL_AESECBCOUNT +} CC1352R1_LAUNCHXL_AESECBName; + +/*! + * @def CC1352R1_LAUNCHXL_SHA2Name + * @brief Enum of SHA2 names + */ +typedef enum CC1352R1_LAUNCHXL_SHA2Name { + CC1352R1_LAUNCHXL_SHA20 = 0, + + CC1352R1_LAUNCHXL_SHA2COUNT +} CC1352R1_LAUNCHXL_SHA2Name; + +/*! + * @def CC1352R1_LAUNCHXL_GPIOName + * @brief Enum of GPIO names + */ +typedef enum CC1352R1_LAUNCHXL_GPIOName { + CC1352R1_LAUNCHXL_GPIO_S1 = 0, + CC1352R1_LAUNCHXL_GPIO_S2, + CC1352R1_LAUNCHXL_SPI_MASTER_READY, + CC1352R1_LAUNCHXL_SPI_SLAVE_READY, + CC1352R1_LAUNCHXL_GPIO_LED_GREEN, + CC1352R1_LAUNCHXL_GPIO_LED_RED, + CC1352R1_LAUNCHXL_GPIO_SPI_FLASH_CS, + CC1352R1_LAUNCHXL_SDSPI_CS, + CC1352R1_LAUNCHXL_GPIOCOUNT +} CC1352R1_LAUNCHXL_GPIOName; + +/*! + * @def CC1352R1_LAUNCHXL_GPTimerName + * @brief Enum of GPTimer parts + */ +typedef enum CC1352R1_LAUNCHXL_GPTimerName { + CC1352R1_LAUNCHXL_GPTIMER0A = 0, + CC1352R1_LAUNCHXL_GPTIMER0B, + CC1352R1_LAUNCHXL_GPTIMER1A, + CC1352R1_LAUNCHXL_GPTIMER1B, + CC1352R1_LAUNCHXL_GPTIMER2A, + CC1352R1_LAUNCHXL_GPTIMER2B, + CC1352R1_LAUNCHXL_GPTIMER3A, + CC1352R1_LAUNCHXL_GPTIMER3B, + + CC1352R1_LAUNCHXL_GPTIMERPARTSCOUNT +} CC1352R1_LAUNCHXL_GPTimerName; + +/*! + * @def CC1352R1_LAUNCHXL_GPTimers + * @brief Enum of GPTimers + */ +typedef enum CC1352R1_LAUNCHXL_GPTimers { + CC1352R1_LAUNCHXL_GPTIMER0 = 0, + CC1352R1_LAUNCHXL_GPTIMER1, + CC1352R1_LAUNCHXL_GPTIMER2, + CC1352R1_LAUNCHXL_GPTIMER3, + + CC1352R1_LAUNCHXL_GPTIMERCOUNT +} CC1352R1_LAUNCHXL_GPTimers; + +/*! + * @def CC1352R1_LAUNCHXL_I2CName + * @brief Enum of I2C names + */ +typedef enum CC1352R1_LAUNCHXL_I2CName { +#if TI_I2C_CONF_I2C0_ENABLE + CC1352R1_LAUNCHXL_I2C0 = 0, +#endif + + CC1352R1_LAUNCHXL_I2CCOUNT +} CC1352R1_LAUNCHXL_I2CName; + +/*! + * @def CC1352R1_LAUNCHXL_NVSName + * @brief Enum of NVS names + */ +typedef enum CC1352R1_LAUNCHXL_NVSName { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + CC1352R1_LAUNCHXL_NVSCC26XX0 = 0, +#endif +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + CC1352R1_LAUNCHXL_NVSSPI25X0, +#endif + + CC1352R1_LAUNCHXL_NVSCOUNT +} CC1352R1_LAUNCHXL_NVSName; + +/*! + * @def CC1352R1_LAUNCHXL_PWMName + * @brief Enum of PWM outputs + */ +typedef enum CC1352R1_LAUNCHXL_PWMName { + CC1352R1_LAUNCHXL_PWM0 = 0, + CC1352R1_LAUNCHXL_PWM1, + CC1352R1_LAUNCHXL_PWM2, + CC1352R1_LAUNCHXL_PWM3, + CC1352R1_LAUNCHXL_PWM4, + CC1352R1_LAUNCHXL_PWM5, + CC1352R1_LAUNCHXL_PWM6, + CC1352R1_LAUNCHXL_PWM7, + + CC1352R1_LAUNCHXL_PWMCOUNT +} CC1352R1_LAUNCHXL_PWMName; + +/*! + * @def CC1352R1_LAUNCHXL_SDName + * @brief Enum of SD names + */ +typedef enum CC1352R1_LAUNCHXL_SDName { + CC1352R1_LAUNCHXL_SDSPI0 = 0, + + CC1352R1_LAUNCHXL_SDCOUNT +} CC1352R1_LAUNCHXL_SDName; + +/*! + * @def CC1352R1_LAUNCHXL_SPIName + * @brief Enum of SPI names + */ +typedef enum CC1352R1_LAUNCHXL_SPIName { +#if TI_SPI_CONF_SPI0_ENABLE + CC1352R1_LAUNCHXL_SPI0 = 0, +#endif +#if TI_SPI_CONF_SPI1_ENABLE + CC1352R1_LAUNCHXL_SPI1, +#endif + + CC1352R1_LAUNCHXL_SPICOUNT +} CC1352R1_LAUNCHXL_SPIName; + +/*! + * @def CC1352R1_LAUNCHXL_TRNGName + * @brief Enum of TRNGs + */ +typedef enum CC1352R1_LAUNCHXL_TRNGName { + CC1352R1_LAUNCHXL_TRNG0 = 0, + + CC1352R1_LAUNCHXL_TRNGCOUNT +} CC1352R1_LAUNCHXL_TRNGName; + +/*! + * @def CC1352R1_LAUNCHXL_UARTName + * @brief Enum of UARTs + */ +typedef enum CC1352R1_LAUNCHXL_UARTName { +#if TI_UART_CONF_UART0_ENABLE + CC1352R1_LAUNCHXL_UART0 = 0, +#endif +#if TI_UART_CONF_UART1_ENABLE + CC1352R1_LAUNCHXL_UART1, +#endif + + CC1352R1_LAUNCHXL_UARTCOUNT +} CC1352R1_LAUNCHXL_UARTName; + +/*! + * @def CC1352R1_LAUNCHXL_UDMAName + * @brief Enum of DMA buffers + */ +typedef enum CC1352R1_LAUNCHXL_UDMAName { + CC1352R1_LAUNCHXL_UDMA0 = 0, + + CC1352R1_LAUNCHXL_UDMACOUNT +} CC1352R1_LAUNCHXL_UDMAName; + +/*! + * @def CC1352R1_LAUNCHXL_WatchdogName + * @brief Enum of Watchdogs + */ +typedef enum CC1352R1_LAUNCHXL_WatchdogName { + CC1352R1_LAUNCHXL_WATCHDOG0 = 0, + + CC1352R1_LAUNCHXL_WATCHDOGCOUNT +} CC1352R1_LAUNCHXL_WatchdogName; + + +#ifdef __cplusplus +} +#endif + +#endif /* __CC1352R1_LAUNCHXL_BOARD_H__ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/CC1352R1_LAUNCHXL_fxns.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/CC1352R1_LAUNCHXL_fxns.c new file mode 100644 index 000000000..520b91297 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/CC1352R1_LAUNCHXL_fxns.c @@ -0,0 +1,187 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +/* + * ======== CC1352R1_LAUNCHXL_fxns.c ======== + * This file contains the board-specific initialization functions, and + * RF callback function for antenna switching. + */ + +#include +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/cpu.h) +#include +#include + +#include "Board.h" + +/* + * ======== CC1352R1_LAUNCHXL_sendExtFlashByte ======== + */ +void CC1352R1_LAUNCHXL_sendExtFlashByte(PIN_Handle pinHandle, uint8_t byte) +{ + uint8_t i; + + /* SPI Flash CS */ + PIN_setOutputValue(pinHandle, IOID_20, 0); + + for (i = 0; i < 8; i++) { + PIN_setOutputValue(pinHandle, IOID_10, 0); /* SPI Flash CLK */ + + /* SPI Flash MOSI */ + PIN_setOutputValue(pinHandle, IOID_9, (byte >> (7 - i)) & 0x01); + PIN_setOutputValue(pinHandle, IOID_10, 1); /* SPI Flash CLK */ + + /* + * Waste a few cycles to keep the CLK high for at + * least 45% of the period. + * 3 cycles per loop: 8 loops @ 48 Mhz = 0.5 us. + */ + CPUdelay(8); + } + + PIN_setOutputValue(pinHandle, IOID_10, 0); /* CLK */ + PIN_setOutputValue(pinHandle, IOID_20, 1); /* CS */ + + /* + * Keep CS high at least 40 us + * 3 cycles per loop: 700 loops @ 48 Mhz ~= 44 us + */ + CPUdelay(700); +} + +/* + * ======== CC1352R1_LAUNCHXL_wakeUpExtFlash ======== + */ +void CC1352R1_LAUNCHXL_wakeUpExtFlash(void) +{ + PIN_Config extFlashPinTable[] = { + /* SPI Flash CS */ + IOID_20 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + PIN_TERMINATE + }; + PIN_State extFlashPinState; + PIN_Handle extFlashPinHandle = PIN_open(&extFlashPinState, extFlashPinTable); + + /* + * To wake up we need to toggle the chip select at + * least 20 ns and ten wait at least 35 us. + */ + + /* Toggle chip select for ~20ns to wake ext. flash */ + PIN_setOutputValue(extFlashPinHandle, IOID_20, 0); + /* 3 cycles per loop: 1 loop @ 48 Mhz ~= 62 ns */ + CPUdelay(1); + PIN_setOutputValue(extFlashPinHandle, IOID_20, 1); + /* 3 cycles per loop: 560 loops @ 48 Mhz ~= 35 us */ + CPUdelay(560); + + PIN_close(extFlashPinHandle); +} + +/* + * ======== CC1352R1_LAUNCHXL_shutDownExtFlash ======== + */ +void CC1352R1_LAUNCHXL_shutDownExtFlash(void) +{ + /* + * To be sure we are putting the flash into sleep and not waking it, + * we first have to make a wake up call + */ + CC1352R1_LAUNCHXL_wakeUpExtFlash(); + + PIN_Config extFlashPinTable[] = { + /* SPI Flash CS*/ + IOID_20 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash CLK */ + IOID_10 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash MOSI */ + IOID_9 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash MISO */ + IOID_8 | PIN_INPUT_EN | PIN_PULLDOWN, + PIN_TERMINATE + }; + PIN_State extFlashPinState; + PIN_Handle extFlashPinHandle = PIN_open(&extFlashPinState, extFlashPinTable); + + uint8_t extFlashShutdown = 0xB9; + + CC1352R1_LAUNCHXL_sendExtFlashByte(extFlashPinHandle, extFlashShutdown); + + PIN_close(extFlashPinHandle); +} + +/* + * ======== Board_initHook ======== + * Called by Board_init() to perform board-specific initialization. + */ +void Board_initHook() +{ + CC1352R1_LAUNCHXL_shutDownExtFlash(); +} + +/* + * For the SysConfig generated Board.h file, Board_RF_SUB1GHZ will not be + * defined unless the RF module is added to the configuration. Therefore, + * we don't include this code if Board_RF_SUB1GHZ is not defined. + */ +#if defined(Board_RF_SUB1GHZ) + +/* + * ======== rfDriverCallback ======== + * This is an implementation for the CC1352R1 launchpad which uses a + * single signal for antenna switching. + */ +void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg) +{ + (void)client; + RF_RadioSetup* setupCommand = (RF_RadioSetup*)arg; + + if ((events & RF_GlobalEventRadioSetup) && + (setupCommand->common.commandNo == CMD_PROP_RADIO_DIV_SETUP)) { + /* Sub-1 GHz, requires antenna switch high */ + PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 1); + } + else if (events & RF_GlobalEventRadioPowerDown) { + /* Disable antenna switch to save current */ + PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 0); + } +} +#endif diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/Makefile.cc1352r1 b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/Makefile.cc1352r1 new file mode 100644 index 000000000..acc892e33 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/Makefile.cc1352r1 @@ -0,0 +1,21 @@ +################################################################################ +# SimpleLink Device makefile + +SUBFAMILY = cc13x2-cc26x2 +DEVICE_FAMILY = CC13X2 +DEVICE_LINE = CC13XX +DEVICE = CC1352R + +BOARD_SOURCEFILES += CC1352R1_LAUNCHXL.c CC1352R1_LAUNCHXL_fxns.c + +SUPPORTS_PROP_MODE = 1 +SUPPORTS_IEEE_MODE = 1 +SUPPORTS_BLE_BEACON = 1 + +SUPPORTS_HIGH_PA = 0 + +### Signal that we can be programmed with cc2538-bsl +BOARD_SUPPORTS_BSL = 0 + +# Include the common board makefile +include $(FAMILY_PATH)/launchpad/Makefile.launchpad diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/Board.h new file mode 100644 index 000000000..8f3e437f0 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/Board.h @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2015-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 __BOARD_H +#define __BOARD_H + +#define Board_CC2650_LAUNCHXL +#define BOARD_STRING "TI CC2650 LaunchPad" + +#ifdef __cplusplus +extern "C" { +#endif + +#include "CC2650_LAUNCHXL.h" + +#define Board_initGeneral() CC2650_LAUNCHXL_initGeneral() +#define Board_shutDownExtFlash() CC2650_LAUNCHXL_shutDownExtFlash() +#define Board_wakeUpExtFlash() CC2650_LAUNCHXL_wakeUpExtFlash() + +/* These #defines allow us to reuse TI-RTOS across other device families */ + +#define Board_ADC0 CC2650_LAUNCHXL_ADC0 +#define Board_ADC1 CC2650_LAUNCHXL_ADC1 + +#define Board_ADCBUF0 CC2650_LAUNCHXL_ADCBUF0 +#define Board_ADCBUF0CHANNEL0 CC2650_LAUNCHXL_ADCBUF0CHANNEL0 +#define Board_ADCBUF0CHANNEL1 CC2650_LAUNCHXL_ADCBUF0CHANNEL1 + +#define Board_CRYPTO0 CC2650_LAUNCHXL_CRYPTO0 + +#define Board_DIO0 CC2650_LAUNCHXL_DIO0 +#define Board_DIO1_RFSW CC2650_LAUNCHXL_DIO1_RFSW +#define Board_DIO12 CC2650_LAUNCHXL_DIO12 +#define Board_DIO15 CC2650_LAUNCHXL_DIO15 +#define Board_DIO16_TDO CC2650_LAUNCHXL_DIO16_TDO +#define Board_DIO17_TDI CC2650_LAUNCHXL_DIO17_TDI +#define Board_DIO21 CC2650_LAUNCHXL_DIO21 +#define Board_DIO22 CC2650_LAUNCHXL_DIO22 + +#define Board_DIO23_ANALOG CC2650_LAUNCHXL_DIO23_ANALOG +#define Board_DIO24_ANALOG CC2650_LAUNCHXL_DIO24_ANALOG +#define Board_DIO25_ANALOG CC2650_LAUNCHXL_DIO25_ANALOG +#define Board_DIO26_ANALOG CC2650_LAUNCHXL_DIO26_ANALOG +#define Board_DIO27_ANALOG CC2650_LAUNCHXL_DIO27_ANALOG +#define Board_DIO28_ANALOG CC2650_LAUNCHXL_DIO28_ANALOG +#define Board_DIO29_ANALOG CC2650_LAUNCHXL_DIO29_ANALOG +#define Board_DIO30_ANALOG CC2650_LAUNCHXL_DIO30_ANALOG + +#define Board_GPIO_BUTTON0 CC2650_LAUNCHXL_GPIO_S1 +#define Board_GPIO_BUTTON1 CC2650_LAUNCHXL_GPIO_S2 +#define Board_GPIO_BTN1 CC2650_LAUNCHXL_GPIO_S1 +#define Board_GPIO_BTN2 CC2650_LAUNCHXL_GPIO_S2 +#define Board_GPIO_LED0 CC2650_LAUNCHXL_GPIO_LED_RED +#define Board_GPIO_LED1 CC2650_LAUNCHXL_GPIO_LED_GREEN +#define Board_GPIO_RLED CC2650_LAUNCHXL_GPIO_LED_RED +#define Board_GPIO_GLED CC2650_LAUNCHXL_GPIO_LED_GREEN +#define Board_GPIO_LED_ON CC2650_LAUNCHXL_GPIO_LED_ON +#define Board_GPIO_LED_OFF CC2650_LAUNCHXL_GPIO_LED_OFF + +#define Board_GPTIMER0A CC2650_LAUNCHXL_GPTIMER0A +#define Board_GPTIMER0B CC2650_LAUNCHXL_GPTIMER0B +#define Board_GPTIMER1A CC2650_LAUNCHXL_GPTIMER1A +#define Board_GPTIMER1B CC2650_LAUNCHXL_GPTIMER1B +#define Board_GPTIMER2A CC2650_LAUNCHXL_GPTIMER2A +#define Board_GPTIMER2B CC2650_LAUNCHXL_GPTIMER2B +#define Board_GPTIMER3A CC2650_LAUNCHXL_GPTIMER3A +#define Board_GPTIMER3B CC2650_LAUNCHXL_GPTIMER3B + +#define Board_I2C0 CC2650_LAUNCHXL_I2C0 +#define Board_I2C_TMP CC2650_LAUNCHXL_I2C0 + +#define Board_NVSINTERNAL CC2650_LAUNCHXL_NVSCC26XX0 +#define Board_NVSEXTERNAL CC2650_LAUNCHXL_NVSSPI25X0 + +#define Board_PIN_BUTTON0 CC2650_LAUNCHXL_PIN_BTN1 +#define Board_PIN_BUTTON1 CC2650_LAUNCHXL_PIN_BTN2 +#define Board_PIN_BTN1 CC2650_LAUNCHXL_PIN_BTN1 +#define Board_PIN_BTN2 CC2650_LAUNCHXL_PIN_BTN2 +#define Board_PIN_LED0 CC2650_LAUNCHXL_PIN_RLED +#define Board_PIN_LED1 CC2650_LAUNCHXL_PIN_GLED +#define Board_PIN_LED2 CC2650_LAUNCHXL_PIN_RLED +#define Board_PIN_RLED CC2650_LAUNCHXL_PIN_RLED +#define Board_PIN_GLED CC2650_LAUNCHXL_PIN_GLED + +#define Board_PWM0 CC2650_LAUNCHXL_PWM0 +#define Board_PWM1 CC2650_LAUNCHXL_PWM1 +#define Board_PWM2 CC2650_LAUNCHXL_PWM2 +#define Board_PWM3 CC2650_LAUNCHXL_PWM3 +#define Board_PWM4 CC2650_LAUNCHXL_PWM4 +#define Board_PWM5 CC2650_LAUNCHXL_PWM5 +#define Board_PWM6 CC2650_LAUNCHXL_PWM6 +#define Board_PWM7 CC2650_LAUNCHXL_PWM7 + +#define Board_SD0 CC2650_LAUNCHXL_SDSPI0 + +#define Board_SPI0 CC2650_LAUNCHXL_SPI0 +#define Board_SPI0_MISO CC2650_LAUNCHXL_SPI0_MISO +#define Board_SPI0_MOSI CC2650_LAUNCHXL_SPI0_MOSI +#define Board_SPI0_CLK CC2650_LAUNCHXL_SPI0_CLK +#define Board_SPI0_CSN CC2650_LAUNCHXL_SPI0_CSN +#define Board_SPI1 CC2650_LAUNCHXL_SPI1 +#define Board_SPI1_MISO CC2650_LAUNCHXL_SPI1_MISO +#define Board_SPI1_MOSI CC2650_LAUNCHXL_SPI1_MOSI +#define Board_SPI1_CLK CC2650_LAUNCHXL_SPI1_CLK +#define Board_SPI1_CSN CC2650_LAUNCHXL_SPI1_CSN +#define Board_SPI_FLASH_CS CC2650_LAUNCHXL_SPI_FLASH_CS +#define Board_FLASH_CS_ON 0 +#define Board_FLASH_CS_OFF 1 + +#define Board_SPI_MASTER CC2650_LAUNCHXL_SPI0 +#define Board_SPI_SLAVE CC2650_LAUNCHXL_SPI0 +#define Board_SPI_MASTER_READY CC2650_LAUNCHXL_SPI_MASTER_READY +#define Board_SPI_SLAVE_READY CC2650_LAUNCHXL_SPI_SLAVE_READY + +#define Board_UART0 CC2650_LAUNCHXL_UART0 + +#define Board_WATCHDOG0 CC2650_LAUNCHXL_WATCHDOG0 + +/* Board specific I2C addresses */ +#define Board_TMP_ADDR (0x40) +#define Board_SENSORS_BP_TMP_ADDR Board_TMP_ADDR + +#ifdef __cplusplus +} +#endif + +#endif /* __BOARD_H */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/CC2650_LAUNCHXL.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/CC2650_LAUNCHXL.c new file mode 100644 index 000000000..ed0a4796e --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/CC2650_LAUNCHXL.c @@ -0,0 +1,821 @@ +/* + * Copyright (c) 2016-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +/* + * ====================== CC2650_LAUNCHXL.c =================================== + * This file is responsible for setting up the board specific items for the + * CC2650_LAUNCHXL board. + */ + +#include +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/udma.h) +#include DeviceFamily_constructPath(inc/hw_ints.h) +#include DeviceFamily_constructPath(inc/hw_memmap.h) + +#include "CC2650_LAUNCHXL.h" + +/* + * =============================== ADCBuf =============================== + */ +#include +#include + +ADCBufCC26XX_Object adcBufCC26xxObjects[CC2650_LAUNCHXL_ADCBUFCOUNT]; + +/* + * This table converts a virtual adc channel into a dio and internal analogue + * input signal. This table is necessary for the functioning of the adcBuf + * driver. Comment out unused entries to save flash. Dio and internal signal + * pairs are hardwired. Do not remap them in the table. You may reorder entire + * entries. The mapping of dio and internal signals is package dependent. + */ +const ADCBufCC26XX_AdcChannelLutEntry ADCBufCC26XX_adcChannelLut[CC2650_LAUNCHXL_ADCBUF0CHANNELCOUNT] = { + {CC2650_LAUNCHXL_DIO23_ANALOG, ADC_COMPB_IN_AUXIO7}, + {CC2650_LAUNCHXL_DIO24_ANALOG, ADC_COMPB_IN_AUXIO6}, + {CC2650_LAUNCHXL_DIO25_ANALOG, ADC_COMPB_IN_AUXIO5}, + {CC2650_LAUNCHXL_DIO26_ANALOG, ADC_COMPB_IN_AUXIO4}, + {CC2650_LAUNCHXL_DIO27_ANALOG, ADC_COMPB_IN_AUXIO3}, + {CC2650_LAUNCHXL_DIO28_ANALOG, ADC_COMPB_IN_AUXIO2}, + {CC2650_LAUNCHXL_DIO29_ANALOG, ADC_COMPB_IN_AUXIO1}, + {CC2650_LAUNCHXL_DIO30_ANALOG, ADC_COMPB_IN_AUXIO0}, + {PIN_UNASSIGNED, ADC_COMPB_IN_VDDS}, + {PIN_UNASSIGNED, ADC_COMPB_IN_DCOUPL}, + {PIN_UNASSIGNED, ADC_COMPB_IN_VSS}, +}; + +const ADCBufCC26XX_HWAttrs adcBufCC26xxHWAttrs[CC2650_LAUNCHXL_ADCBUFCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + .adcChannelLut = ADCBufCC26XX_adcChannelLut, + .gpTimerUnit = CC2650_LAUNCHXL_GPTIMER0A, + .gptDMAChannelMask = 1 << UDMA_CHAN_TIMER0_A, + } +}; + +const ADCBuf_Config ADCBuf_config[CC2650_LAUNCHXL_ADCBUFCOUNT] = { + { + &ADCBufCC26XX_fxnTable, + &adcBufCC26xxObjects[CC2650_LAUNCHXL_ADCBUF0], + &adcBufCC26xxHWAttrs[CC2650_LAUNCHXL_ADCBUF0] + }, +}; + +const uint_least8_t ADCBuf_count = CC2650_LAUNCHXL_ADCBUFCOUNT; + +/* + * =============================== ADC =============================== + */ +#include +#include + +ADCCC26XX_Object adcCC26xxObjects[CC2650_LAUNCHXL_ADCCOUNT]; + +const ADCCC26XX_HWAttrs adcCC26xxHWAttrs[CC2650_LAUNCHXL_ADCCOUNT] = { + { + .adcDIO = CC2650_LAUNCHXL_DIO23_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO7, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC2650_LAUNCHXL_DIO24_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO6, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC2650_LAUNCHXL_DIO25_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO5, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC2650_LAUNCHXL_DIO26_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO4, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC2650_LAUNCHXL_DIO27_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO3, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC2650_LAUNCHXL_DIO28_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO2, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC2650_LAUNCHXL_DIO29_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO1, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC2650_LAUNCHXL_DIO30_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO0, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_10P9_MS, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_DCOUPL, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_VSS, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_VDDS, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + } +}; + +const ADC_Config ADC_config[CC2650_LAUNCHXL_ADCCOUNT] = { + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC2650_LAUNCHXL_ADC0], &adcCC26xxHWAttrs[CC2650_LAUNCHXL_ADC0]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC2650_LAUNCHXL_ADC1], &adcCC26xxHWAttrs[CC2650_LAUNCHXL_ADC1]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC2650_LAUNCHXL_ADC2], &adcCC26xxHWAttrs[CC2650_LAUNCHXL_ADC2]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC2650_LAUNCHXL_ADC3], &adcCC26xxHWAttrs[CC2650_LAUNCHXL_ADC3]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC2650_LAUNCHXL_ADC4], &adcCC26xxHWAttrs[CC2650_LAUNCHXL_ADC4]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC2650_LAUNCHXL_ADC5], &adcCC26xxHWAttrs[CC2650_LAUNCHXL_ADC5]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC2650_LAUNCHXL_ADC6], &adcCC26xxHWAttrs[CC2650_LAUNCHXL_ADC6]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC2650_LAUNCHXL_ADC7], &adcCC26xxHWAttrs[CC2650_LAUNCHXL_ADC7]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC2650_LAUNCHXL_ADCDCOUPL], &adcCC26xxHWAttrs[CC2650_LAUNCHXL_ADCDCOUPL]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC2650_LAUNCHXL_ADCVSS], &adcCC26xxHWAttrs[CC2650_LAUNCHXL_ADCVSS]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC2650_LAUNCHXL_ADCVDDS], &adcCC26xxHWAttrs[CC2650_LAUNCHXL_ADCVDDS]}, +}; + +const uint_least8_t ADC_count = CC2650_LAUNCHXL_ADCCOUNT; + +/* + * =============================== Crypto =============================== + */ +#include + +CryptoCC26XX_Object cryptoCC26XXObjects[CC2650_LAUNCHXL_CRYPTOCOUNT]; + +const CryptoCC26XX_HWAttrs cryptoCC26XXHWAttrs[CC2650_LAUNCHXL_CRYPTOCOUNT] = { + { + .baseAddr = CRYPTO_BASE, + .powerMngrId = PowerCC26XX_PERIPH_CRYPTO, + .intNum = INT_CRYPTO_RESULT_AVAIL_IRQ, + .intPriority = ~0, + } +}; + +const CryptoCC26XX_Config CryptoCC26XX_config[CC2650_LAUNCHXL_CRYPTOCOUNT] = { + { + .object = &cryptoCC26XXObjects[CC2650_LAUNCHXL_CRYPTO0], + .hwAttrs = &cryptoCC26XXHWAttrs[CC2650_LAUNCHXL_CRYPTO0] + }, +}; + +/* + * =============================== GPIO =============================== + */ +#include +#include + +/* + * Array of Pin configurations + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC2650_LAUNCHXL.h + * NOTE: Pins not used for interrupts should be placed at the end of the + * array. Callback entries can be omitted from callbacks array to + * reduce memory usage. + */ +GPIO_PinConfig gpioPinConfigs[] = { + /* Input pins */ + GPIOCC26XX_DIO_13 | GPIO_DO_NOT_CONFIG, /* Button 0 */ + GPIOCC26XX_DIO_14 | GPIO_DO_NOT_CONFIG, /* Button 1 */ + + GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG, /* CC2650_LAUNCHXL_SPI_MASTER_READY */ + GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG, /* CC2650_LAUNCHXL_SPI_SLAVE_READY */ + + /* Output pins */ + GPIOCC26XX_DIO_07 | GPIO_DO_NOT_CONFIG, /* Green LED */ + GPIOCC26XX_DIO_06 | GPIO_DO_NOT_CONFIG, /* Red LED */ + + /* SPI Flash CSN */ + GPIOCC26XX_DIO_20 | GPIO_DO_NOT_CONFIG, + + /* SD CS */ + GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG, +}; + +/* + * Array of callback function pointers + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC2650_LAUNCH.h + * NOTE: Pins not used for interrupts can be omitted from callbacks array to + * reduce memory usage (if placed at end of gpioPinConfigs array). + */ +GPIO_CallbackFxn gpioCallbackFunctions[] = { + NULL, /* Button 0 */ + NULL, /* Button 1 */ + NULL, /* CC2650_LAUNCHXL_SPI_MASTER_READY */ + NULL, /* CC2650_LAUNCHXL_SPI_SLAVE_READY */ +}; + +const GPIOCC26XX_Config GPIOCC26XX_config = { + .pinConfigs = (GPIO_PinConfig *)gpioPinConfigs, + .callbacks = (GPIO_CallbackFxn *)gpioCallbackFunctions, + .numberOfPinConfigs = CC2650_LAUNCHXL_GPIOCOUNT, + .numberOfCallbacks = sizeof(gpioCallbackFunctions)/sizeof(GPIO_CallbackFxn), + .intPriority = (~0) +}; + +/* + * =============================== GPTimer =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include + +GPTimerCC26XX_Object gptimerCC26XXObjects[CC2650_LAUNCHXL_GPTIMERCOUNT]; + +const GPTimerCC26XX_HWAttrs gptimerCC26xxHWAttrs[CC2650_LAUNCHXL_GPTIMERPARTSCOUNT] = { + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0A, }, + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0B, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1A, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1B, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2A, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2B, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3A, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3B, }, +}; + +const GPTimerCC26XX_Config GPTimerCC26XX_config[CC2650_LAUNCHXL_GPTIMERPARTSCOUNT] = { + { &gptimerCC26XXObjects[CC2650_LAUNCHXL_GPTIMER0], &gptimerCC26xxHWAttrs[CC2650_LAUNCHXL_GPTIMER0A], GPT_A }, + { &gptimerCC26XXObjects[CC2650_LAUNCHXL_GPTIMER0], &gptimerCC26xxHWAttrs[CC2650_LAUNCHXL_GPTIMER0B], GPT_B }, + { &gptimerCC26XXObjects[CC2650_LAUNCHXL_GPTIMER1], &gptimerCC26xxHWAttrs[CC2650_LAUNCHXL_GPTIMER1A], GPT_A }, + { &gptimerCC26XXObjects[CC2650_LAUNCHXL_GPTIMER1], &gptimerCC26xxHWAttrs[CC2650_LAUNCHXL_GPTIMER1B], GPT_B }, + { &gptimerCC26XXObjects[CC2650_LAUNCHXL_GPTIMER2], &gptimerCC26xxHWAttrs[CC2650_LAUNCHXL_GPTIMER2A], GPT_A }, + { &gptimerCC26XXObjects[CC2650_LAUNCHXL_GPTIMER2], &gptimerCC26xxHWAttrs[CC2650_LAUNCHXL_GPTIMER2B], GPT_B }, + { &gptimerCC26XXObjects[CC2650_LAUNCHXL_GPTIMER3], &gptimerCC26xxHWAttrs[CC2650_LAUNCHXL_GPTIMER3A], GPT_A }, + { &gptimerCC26XXObjects[CC2650_LAUNCHXL_GPTIMER3], &gptimerCC26xxHWAttrs[CC2650_LAUNCHXL_GPTIMER3B], GPT_B }, +}; + +/* + * =============================== I2C =============================== +*/ +#include +#include + +#if TI_I2C_CONF_ENABLE + +I2CCC26XX_Object i2cCC26xxObjects[CC2650_LAUNCHXL_I2CCOUNT]; + +const I2CCC26XX_HWAttrsV1 i2cCC26xxHWAttrs[CC2650_LAUNCHXL_I2CCOUNT] = { +#if TI_I2C_CONF_I2C0_ENABLE + { + .baseAddr = I2C0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_I2C0, + .intNum = INT_I2C_IRQ, + .intPriority = ~0, + .swiPriority = 0, + .sdaPin = CC2650_LAUNCHXL_I2C0_SDA0, + .sclPin = CC2650_LAUNCHXL_I2C0_SCL0, + }, +#endif +}; + +const I2C_Config I2C_config[CC2650_LAUNCHXL_I2CCOUNT] = { +#if TI_I2C_CONF_I2C0_ENABLE + { + .fxnTablePtr = &I2CCC26XX_fxnTable, + .object = &i2cCC26xxObjects[CC2650_LAUNCHXL_I2C0], + .hwAttrs = &i2cCC26xxHWAttrs[CC2650_LAUNCHXL_I2C0] + }, +#endif +}; + +const uint_least8_t I2C_count = CC2650_LAUNCHXL_I2CCOUNT; + +#endif /* TI_I2C_CONF_ENABLE */ + +/* + * =============================== NVS =============================== + */ +#include +#include +#include + +#define NVS_REGIONS_BASE 0x1A000 +#define SECTORSIZE 0x1000 +#define REGIONSIZE (SECTORSIZE * 4) + +#if TI_NVS_CONF_ENABLE + +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + +/* + * Reserve flash sectors for NVS driver use by placing an uninitialized byte + * array at the desired flash address. + */ +#if defined(__TI_COMPILER_VERSION__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +#pragma LOCATION(flashBuf, NVS_REGIONS_BASE); +#pragma NOINIT(flashBuf); +static char flashBuf[REGIONSIZE]; + +#elif defined(__IAR_SYSTEMS_ICC__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +static __no_init char flashBuf[REGIONSIZE] @ NVS_REGIONS_BASE; + +#elif defined(__GNUC__) + +/* + * Place the flash buffers in the .nvs section created in the gcc linker file. + * The .nvs section enforces alignment on a sector boundary but may + * be placed anywhere in flash memory. If desired the .nvs section can be set + * to a fixed address by changing the following in the gcc linker file: + * + * .nvs (FIXED_FLASH_ADDR) (NOLOAD) : AT (FIXED_FLASH_ADDR) { + * *(.nvs) + * } > REGION_TEXT + */ +__attribute__ ((section (".nvs"))) +static char flashBuf[REGIONSIZE]; + +#endif + +/* Allocate objects for NVS Internal Regions */ +NVSCC26XX_Object nvsCC26xxObjects[1]; + +/* Hardware attributes for NVS Internal Regions */ +const NVSCC26XX_HWAttrs nvsCC26xxHWAttrs[1] = { + { + .regionBase = (void *)flashBuf, + .regionSize = REGIONSIZE, + }, +}; + +#endif /* TI_NVS_CONF_NVS_INTERNAL_ENABLE */ + +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + +#define SPISECTORSIZE 0x1000 +#define SPIREGIONSIZE (SPISECTORSIZE * 32) +#define VERIFYBUFSIZE 64 + +static uint8_t verifyBuf[VERIFYBUFSIZE]; + +/* Allocate objects for NVS External Regions */ +NVSSPI25X_Object nvsSPI25XObjects[1]; + +/* Hardware attributes for NVS External Regions */ +const NVSSPI25X_HWAttrs nvsSPI25XHWAttrs[1] = { + { + .regionBaseOffset = 0, + .regionSize = SPIREGIONSIZE, + .sectorSize = SPISECTORSIZE, + .verifyBuf = verifyBuf, + .verifyBufSize = VERIFYBUFSIZE, + .spiHandle = NULL, + .spiIndex = 0, + .spiBitRate = 4000000, + .spiCsnGpioIndex = CC2650_LAUNCHXL_GPIO_SPI_FLASH_CS, + }, +}; + +#endif /* Board_EXCLUDE_NVS_EXTERNAL_FLASH */ + +/* NVS Region index 0 and 1 refer to NVS and NVS SPI respectively */ +const NVS_Config NVS_config[CC2650_LAUNCHXL_NVSCOUNT] = { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + { + .fxnTablePtr = &NVSCC26XX_fxnTable, + .object = &nvsCC26xxObjects[0], + .hwAttrs = &nvsCC26xxHWAttrs[0], + }, +#endif +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + { + .fxnTablePtr = &NVSSPI25X_fxnTable, + .object = &nvsSPI25XObjects[0], + .hwAttrs = &nvsSPI25XHWAttrs[0], + }, +#endif +}; + +const uint_least8_t NVS_count = CC2650_LAUNCHXL_NVSCOUNT; + +#endif /* TI_NVS_CONF_ENABLE */ + +/* + * =============================== PIN =============================== + */ +#include +#include + +const PIN_Config BoardGpioInitTable[] = { + + CC2650_LAUNCHXL_PIN_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC2650_LAUNCHXL_PIN_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC2650_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC2650_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC2650_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ + CC2650_LAUNCHXL_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */ + CC2650_LAUNCHXL_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */ + CC2650_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */ + CC2650_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */ + CC2650_LAUNCHXL_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI clock */ + + PIN_TERMINATE +}; + +const PINCC26XX_HWAttrs PINCC26XX_hwAttrs = { + .intPriority = ~0, + .swiPriority = 0 +}; + +/* + * =============================== Power =============================== + */ +#include +#include + +const PowerCC26XX_Config PowerCC26XX_config = { + .policyInitFxn = NULL, + .policyFxn = &PowerCC26XX_standbyPolicy, + .calibrateFxn = &PowerCC26XX_calibrate, + .enablePolicy = true, + .calibrateRCOSC_LF = true, + .calibrateRCOSC_HF = true, +}; + +/* + * =============================== PWM =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include +#include + +PWMTimerCC26XX_Object pwmtimerCC26xxObjects[CC2650_LAUNCHXL_PWMCOUNT]; + +const PWMTimerCC26XX_HwAttrs pwmtimerCC26xxHWAttrs[CC2650_LAUNCHXL_PWMCOUNT] = { + { .pwmPin = CC2650_LAUNCHXL_PWMPIN0, .gpTimerUnit = CC2650_LAUNCHXL_GPTIMER0A }, + { .pwmPin = CC2650_LAUNCHXL_PWMPIN1, .gpTimerUnit = CC2650_LAUNCHXL_GPTIMER0B }, + { .pwmPin = CC2650_LAUNCHXL_PWMPIN2, .gpTimerUnit = CC2650_LAUNCHXL_GPTIMER1A }, + { .pwmPin = CC2650_LAUNCHXL_PWMPIN3, .gpTimerUnit = CC2650_LAUNCHXL_GPTIMER1B }, + { .pwmPin = CC2650_LAUNCHXL_PWMPIN4, .gpTimerUnit = CC2650_LAUNCHXL_GPTIMER2A }, + { .pwmPin = CC2650_LAUNCHXL_PWMPIN5, .gpTimerUnit = CC2650_LAUNCHXL_GPTIMER2B }, + { .pwmPin = CC2650_LAUNCHXL_PWMPIN6, .gpTimerUnit = CC2650_LAUNCHXL_GPTIMER3A }, + { .pwmPin = CC2650_LAUNCHXL_PWMPIN7, .gpTimerUnit = CC2650_LAUNCHXL_GPTIMER3B }, +}; + +const PWM_Config PWM_config[CC2650_LAUNCHXL_PWMCOUNT] = { + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC2650_LAUNCHXL_PWM0], &pwmtimerCC26xxHWAttrs[CC2650_LAUNCHXL_PWM0] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC2650_LAUNCHXL_PWM1], &pwmtimerCC26xxHWAttrs[CC2650_LAUNCHXL_PWM1] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC2650_LAUNCHXL_PWM2], &pwmtimerCC26xxHWAttrs[CC2650_LAUNCHXL_PWM2] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC2650_LAUNCHXL_PWM3], &pwmtimerCC26xxHWAttrs[CC2650_LAUNCHXL_PWM3] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC2650_LAUNCHXL_PWM4], &pwmtimerCC26xxHWAttrs[CC2650_LAUNCHXL_PWM4] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC2650_LAUNCHXL_PWM5], &pwmtimerCC26xxHWAttrs[CC2650_LAUNCHXL_PWM5] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC2650_LAUNCHXL_PWM6], &pwmtimerCC26xxHWAttrs[CC2650_LAUNCHXL_PWM6] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC2650_LAUNCHXL_PWM7], &pwmtimerCC26xxHWAttrs[CC2650_LAUNCHXL_PWM7] }, +}; + +const uint_least8_t PWM_count = CC2650_LAUNCHXL_PWMCOUNT; + +/* + * =============================== RF Driver =============================== + */ +#include + +const RFCC26XX_HWAttrsV2 RFCC26XX_hwAttrs = { + .hwiPriority = ~0, /* Lowest HWI priority */ + .swiPriority = 0, /* Lowest SWI priority */ + .xoscHfAlwaysNeeded = true, /* Keep XOSC dependency while in stanby */ + .globalCallback = NULL, /* No board specific callback */ + .globalEventMask = 0 /* No events subscribed to */ +}; + +/* + * =============================== SD =============================== + */ +#include +#include + +#if TI_SD_CONF_ENABLE + +#if !(TI_SPI_CONF_SPI0_ENABLE) +#error "SD driver requires SPI0 enabled" +#endif + +SDSPI_Object sdspiObjects[CC2650_LAUNCHXL_SDCOUNT]; + +const SDSPI_HWAttrs sdspiHWAttrs[CC2650_LAUNCHXL_SDCOUNT] = { + { + .spiIndex = CC2650_LAUNCHXL_SPI0, + .spiCsGpioIndex = CC2650_LAUNCHXL_SDSPI_CS + } +}; + +const SD_Config SD_config[CC2650_LAUNCHXL_SDCOUNT] = { + { + .fxnTablePtr = &SDSPI_fxnTable, + .object = &sdspiObjects[CC2650_LAUNCHXL_SDSPI0], + .hwAttrs = &sdspiHWAttrs[CC2650_LAUNCHXL_SDSPI0] + }, +}; + +const uint_least8_t SD_count = CC2650_LAUNCHXL_SDCOUNT; + +#endif /* TI_SD_CONF_ENABLE */ + +/* + * =============================== SPI DMA =============================== + */ +#include +#include + +#if TI_SPI_CONF_ENABLE + +SPICC26XXDMA_Object spiCC26XXDMAObjects[CC2650_LAUNCHXL_SPICOUNT]; + +/* + * NOTE: The SPI instances below can be used by the SD driver to communicate + * with a SD card via SPI. The 'defaultTxBufValue' fields below are set to 0xFF + * to satisfy the SDSPI driver requirement. + */ +const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[CC2650_LAUNCHXL_SPICOUNT] = { +#if TI_SPI_CONF_SPI0_ENABLE + { + .baseAddr = SSI0_BASE, + .intNum = INT_SSI0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .powerMngrId = PowerCC26XX_PERIPH_SSI0, + .defaultTxBufValue = 0xFF, + .rxChannelBitMask = 1< +#include + +TRNGCC26X0_Object trngCC26X0Object[CC2650_LAUNCHXL_TRNGCOUNT]; + +const TRNGCC26X0_HWAttrs trngCC26X0HWAttrs[CC2650_LAUNCHXL_TRNGCOUNT] = { + { + .swiPriority = 0, + .intPriority = ~0, + } +}; + +const TRNG_Config TRNG_config[] = { + { &trngCC26X0Object[0], &trngCC26X0HWAttrs[0] }, +}; + +const uint8_t TRNG_count = CC2650_LAUNCHXL_TRNGCOUNT; + + +/* + * =============================== UART =============================== + */ +#include +#include + +#if TI_UART_CONF_ENABLE + +UARTCC26XX_Object uartCC26XXObjects[CC2650_LAUNCHXL_UARTCOUNT]; + +uint8_t uartCC26XXRingBuffer[CC2650_LAUNCHXL_UARTCOUNT][32]; + +const UARTCC26XX_HWAttrsV2 uartCC26XXHWAttrs[CC2650_LAUNCHXL_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .baseAddr = UART0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UART0, + .intNum = INT_UART0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .txPin = CC2650_LAUNCHXL_UART_TX, + .rxPin = CC2650_LAUNCHXL_UART_RX, + .ctsPin = PIN_UNASSIGNED, + .rtsPin = PIN_UNASSIGNED, + .ringBufPtr = uartCC26XXRingBuffer[CC2650_LAUNCHXL_UART0], + .ringBufSize = sizeof(uartCC26XXRingBuffer[CC2650_LAUNCHXL_UART0]), + .txIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_1_8, + .rxIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_4_8, + .errorFxn = NULL + }, +#endif +}; + +const UART_Config UART_config[CC2650_LAUNCHXL_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .fxnTablePtr = &UARTCC26XX_fxnTable, + .object = &uartCC26XXObjects[CC2650_LAUNCHXL_UART0], + .hwAttrs = &uartCC26XXHWAttrs[CC2650_LAUNCHXL_UART0] + }, +#endif +}; + +const uint_least8_t UART_count = CC2650_LAUNCHXL_UARTCOUNT; + +#endif /* TI_UART_CONF_ENABLE */ + +/* + * =============================== UDMA =============================== + */ +#include + +UDMACC26XX_Object udmaObjects[CC2650_LAUNCHXL_UDMACOUNT]; + +const UDMACC26XX_HWAttrs udmaHWAttrs[CC2650_LAUNCHXL_UDMACOUNT] = { + { + .baseAddr = UDMA0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UDMA, + .intNum = INT_DMA_ERR, + .intPriority = ~0 + } +}; + +const UDMACC26XX_Config UDMACC26XX_config[CC2650_LAUNCHXL_UDMACOUNT] = { + { + .object = &udmaObjects[CC2650_LAUNCHXL_UDMA0], + .hwAttrs = &udmaHWAttrs[CC2650_LAUNCHXL_UDMA0] + }, +}; + + + +/* + * =============================== Watchdog =============================== + */ +#include +#include + +WatchdogCC26XX_Object watchdogCC26XXObjects[CC2650_LAUNCHXL_WATCHDOGCOUNT]; + +const WatchdogCC26XX_HWAttrs watchdogCC26XXHWAttrs[CC2650_LAUNCHXL_WATCHDOGCOUNT] = { + { + .baseAddr = WDT_BASE, + .reloadValue = 1000 /* Reload value in milliseconds */ + }, +}; + +const Watchdog_Config Watchdog_config[CC2650_LAUNCHXL_WATCHDOGCOUNT] = { + { + .fxnTablePtr = &WatchdogCC26XX_fxnTable, + .object = &watchdogCC26XXObjects[CC2650_LAUNCHXL_WATCHDOG0], + .hwAttrs = &watchdogCC26XXHWAttrs[CC2650_LAUNCHXL_WATCHDOG0] + }, +}; + +const uint_least8_t Watchdog_count = CC2650_LAUNCHXL_WATCHDOGCOUNT; + +/* + * Board-specific initialization function to disable external flash. + * This function is defined in the file CC2650_LAUNCHXL_fxns.c + */ +extern void Board_initHook(void); + +/* + * ======== CC2650_LAUNCHXL_initGeneral ======== + */ +void CC2650_LAUNCHXL_initGeneral(void) +{ + Power_init(); + + if (PIN_init(BoardGpioInitTable) != PIN_SUCCESS) { + /* Error with PIN_init */ + while (1); + } + + /* Perform board-specific initialization */ + Board_initHook(); +} diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/CC2650_LAUNCHXL.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/CC2650_LAUNCHXL.h new file mode 100644 index 000000000..8c440aa9d --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/CC2650_LAUNCHXL.h @@ -0,0 +1,380 @@ +/* + * Copyright (c) 2015-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 CC2650_LAUNCHXL.h + * + * @brief CC2650 LaunchPad Board Specific header file. + * + * The CC2650_LAUNCHXL header file should be included in an application as + * follows: + * @code + * #include "CC2650_LAUNCHXL.h" + * @endcode + * + * ============================================================================ + */ +#ifndef __CC2650_LAUNCHXL_BOARD_H__ +#define __CC2650_LAUNCHXL_BOARD_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "contiki-conf.h" + +/* Includes */ +#include +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) + +/* Externs */ +extern const PIN_Config BoardGpioInitTable[]; + +/* Defines */ +#define CC2650_LAUNCHXL + +/* Mapping of pins to board signals using general board aliases + * + */ + +/* Analog Capable DIOs */ +#define CC2650_LAUNCHXL_DIO23_ANALOG IOID_23 +#define CC2650_LAUNCHXL_DIO24_ANALOG IOID_24 +#define CC2650_LAUNCHXL_DIO25_ANALOG IOID_25 +#define CC2650_LAUNCHXL_DIO26_ANALOG IOID_26 +#define CC2650_LAUNCHXL_DIO27_ANALOG IOID_27 +#define CC2650_LAUNCHXL_DIO28_ANALOG IOID_28 +#define CC2650_LAUNCHXL_DIO29_ANALOG IOID_29 +#define CC2650_LAUNCHXL_DIO30_ANALOG IOID_30 + +/* Digital IOs */ +#define CC2650_LAUNCHXL_DIO0 IOID_0 +#define CC2650_LAUNCHXL_DIO1_RFSW IOID_1 +#define CC2650_LAUNCHXL_DIO12 IOID_12 +#define CC2650_LAUNCHXL_DIO15 IOID_15 +#define CC2650_LAUNCHXL_DIO16_TDO IOID_16 +#define CC2650_LAUNCHXL_DIO17_TDI IOID_17 +#define CC2650_LAUNCHXL_DIO21 IOID_21 +#define CC2650_LAUNCHXL_DIO22 IOID_22 + +/* Discrete Inputs */ +#define CC2650_LAUNCHXL_PIN_BTN1 IOID_13 +#define CC2650_LAUNCHXL_PIN_BTN2 IOID_14 + +/* GPIO */ +#define CC2650_LAUNCHXL_GPIO_LED_ON 1 +#define CC2650_LAUNCHXL_GPIO_LED_OFF 0 + +/* I2C */ +#define CC2650_LAUNCHXL_I2C0_SCL0 IOID_4 +#define CC2650_LAUNCHXL_I2C0_SDA0 IOID_5 + +/* LEDs */ +#define CC2650_LAUNCHXL_PIN_LED_ON 1 +#define CC2650_LAUNCHXL_PIN_LED_OFF 0 +#define CC2650_LAUNCHXL_PIN_RLED IOID_6 +#define CC2650_LAUNCHXL_PIN_GLED IOID_7 + +/* PWM Outputs */ +#define CC2650_LAUNCHXL_PWMPIN0 CC2650_LAUNCHXL_PIN_RLED +#define CC2650_LAUNCHXL_PWMPIN1 CC2650_LAUNCHXL_PIN_GLED +#define CC2650_LAUNCHXL_PWMPIN2 PIN_UNASSIGNED +#define CC2650_LAUNCHXL_PWMPIN3 PIN_UNASSIGNED +#define CC2650_LAUNCHXL_PWMPIN4 PIN_UNASSIGNED +#define CC2650_LAUNCHXL_PWMPIN5 PIN_UNASSIGNED +#define CC2650_LAUNCHXL_PWMPIN6 PIN_UNASSIGNED +#define CC2650_LAUNCHXL_PWMPIN7 PIN_UNASSIGNED + +/* SPI */ +#define CC2650_LAUNCHXL_SPI_FLASH_CS IOID_20 +#define CC2650_LAUNCHXL_FLASH_CS_ON 0 +#define CC2650_LAUNCHXL_FLASH_CS_OFF 1 + +/* SPI Board */ +#define CC2650_LAUNCHXL_SPI0_MISO IOID_8 /* RF1.20 */ +#define CC2650_LAUNCHXL_SPI0_MOSI IOID_9 /* RF1.18 */ +#define CC2650_LAUNCHXL_SPI0_CLK IOID_10 /* RF1.16 */ +#define CC2650_LAUNCHXL_SPI0_CSN PIN_UNASSIGNED +#define CC2650_LAUNCHXL_SPI1_MISO PIN_UNASSIGNED +#define CC2650_LAUNCHXL_SPI1_MOSI PIN_UNASSIGNED +#define CC2650_LAUNCHXL_SPI1_CLK PIN_UNASSIGNED +#define CC2650_LAUNCHXL_SPI1_CSN PIN_UNASSIGNED + +/* UART Board */ +#define CC2650_LAUNCHXL_UART_RX IOID_2 /* RXD */ +#define CC2650_LAUNCHXL_UART_TX IOID_3 /* TXD */ +#define CC2650_LAUNCHXL_UART_CTS IOID_19 /* CTS */ +#define CC2650_LAUNCHXL_UART_RTS IOID_18 /* RTS */ + +/*! + * @brief Initialize the general board specific settings + * + * This function initializes the general board specific settings. + */ +void CC2650_LAUNCHXL_initGeneral(void); + +/*! + * @brief Turn off the external flash on LaunchPads + * + */ +void CC2650_LAUNCHXL_shutDownExtFlash(void); + +/*! + * @brief Wake up the external flash present on the board files + * + * This function toggles the chip select for the amount of time needed + * to wake the chip up. + */ +void CC2650_LAUNCHXL_wakeUpExtFlash(void); + +/*! + * @def CC2650_LAUNCHXL_ADCBufName + * @brief Enum of ADCs + */ +typedef enum CC2650_LAUNCHXL_ADCBufName { + CC2650_LAUNCHXL_ADCBUF0 = 0, + + CC2650_LAUNCHXL_ADCBUFCOUNT +} CC2650_LAUNCHXL_ADCBufName; + +/*! + * @def CC2650_LAUNCHXL_ADCBuf0ChannelName + * @brief Enum of ADCBuf channels + */ +typedef enum CC2650_LAUNCHXL_ADCBuf0ChannelName { + CC2650_LAUNCHXL_ADCBUF0CHANNEL0 = 0, + CC2650_LAUNCHXL_ADCBUF0CHANNEL1, + CC2650_LAUNCHXL_ADCBUF0CHANNEL2, + CC2650_LAUNCHXL_ADCBUF0CHANNEL3, + CC2650_LAUNCHXL_ADCBUF0CHANNEL4, + CC2650_LAUNCHXL_ADCBUF0CHANNEL5, + CC2650_LAUNCHXL_ADCBUF0CHANNEL6, + CC2650_LAUNCHXL_ADCBUF0CHANNEL7, + CC2650_LAUNCHXL_ADCBUF0CHANNELVDDS, + CC2650_LAUNCHXL_ADCBUF0CHANNELDCOUPL, + CC2650_LAUNCHXL_ADCBUF0CHANNELVSS, + + CC2650_LAUNCHXL_ADCBUF0CHANNELCOUNT +} CC2650_LAUNCHXL_ADCBuf0ChannelName; + +/*! + * @def CC2650_LAUNCHXL_ADCName + * @brief Enum of ADCs + */ +typedef enum CC2650_LAUNCHXL_ADCName { + CC2650_LAUNCHXL_ADC0 = 0, + CC2650_LAUNCHXL_ADC1, + CC2650_LAUNCHXL_ADC2, + CC2650_LAUNCHXL_ADC3, + CC2650_LAUNCHXL_ADC4, + CC2650_LAUNCHXL_ADC5, + CC2650_LAUNCHXL_ADC6, + CC2650_LAUNCHXL_ADC7, + CC2650_LAUNCHXL_ADCDCOUPL, + CC2650_LAUNCHXL_ADCVSS, + CC2650_LAUNCHXL_ADCVDDS, + + CC2650_LAUNCHXL_ADCCOUNT +} CC2650_LAUNCHXL_ADCName; + +/*! + * @def CC2650_LAUNCHXL_CryptoName + * @brief Enum of Crypto names + */ +typedef enum CC2650_LAUNCHXL_CryptoName { + CC2650_LAUNCHXL_CRYPTO0 = 0, + + CC2650_LAUNCHXL_CRYPTOCOUNT +} CC2650_LAUNCHXL_CryptoName; + +/*! + * @def CC2650_LAUNCHXL_GPIOName + * @brief Enum of GPIO names + */ +typedef enum CC2650_LAUNCHXL_GPIOName { + CC2650_LAUNCHXL_GPIO_S1 = 0, + CC2650_LAUNCHXL_GPIO_S2, + CC2650_LAUNCHXL_SPI_MASTER_READY, + CC2650_LAUNCHXL_SPI_SLAVE_READY, + CC2650_LAUNCHXL_GPIO_LED_GREEN, + CC2650_LAUNCHXL_GPIO_LED_RED, + CC2650_LAUNCHXL_GPIO_SPI_FLASH_CS, + CC2650_LAUNCHXL_SDSPI_CS, + CC2650_LAUNCHXL_GPIOCOUNT +} CC2650_LAUNCHXL_GPIOName; + +/*! + * @def CC2650_LAUNCHXL_GPTimerName + * @brief Enum of GPTimer parts + */ +typedef enum CC2650_LAUNCHXL_GPTimerName { + CC2650_LAUNCHXL_GPTIMER0A = 0, + CC2650_LAUNCHXL_GPTIMER0B, + CC2650_LAUNCHXL_GPTIMER1A, + CC2650_LAUNCHXL_GPTIMER1B, + CC2650_LAUNCHXL_GPTIMER2A, + CC2650_LAUNCHXL_GPTIMER2B, + CC2650_LAUNCHXL_GPTIMER3A, + CC2650_LAUNCHXL_GPTIMER3B, + + CC2650_LAUNCHXL_GPTIMERPARTSCOUNT +} CC2650_LAUNCHXL_GPTimerName; + +/*! + * @def CC2650_LAUNCHXL_GPTimers + * @brief Enum of GPTimers + */ +typedef enum CC2650_LAUNCHXL_GPTimers { + CC2650_LAUNCHXL_GPTIMER0 = 0, + CC2650_LAUNCHXL_GPTIMER1, + CC2650_LAUNCHXL_GPTIMER2, + CC2650_LAUNCHXL_GPTIMER3, + + CC2650_LAUNCHXL_GPTIMERCOUNT +} CC2650_LAUNCHXL_GPTimers; + +/*! + * @def CC2650_LAUNCHXL_I2CName + * @brief Enum of I2C names + */ +typedef enum CC2650_LAUNCHXL_I2CName { +#if TI_I2C_CONF_I2C0_ENABLE + CC2650_LAUNCHXL_I2C0 = 0, +#endif + + CC2650_LAUNCHXL_I2CCOUNT +} CC2650_LAUNCHXL_I2CName; + +/*! + * @def CC2650_LAUNCHXL_NVSName + * @brief Enum of NVS names + */ +typedef enum CC2650_LAUNCHXL_NVSName { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + CC2650_LAUNCHXL_NVSCC26XX0 = 0, +#endif +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + CC2650_LAUNCHXL_NVSSPI25X0, +#endif + + CC2650_LAUNCHXL_NVSCOUNT +} CC2650_LAUNCHXL_NVSName; + +/*! + * @def CC2650_LAUNCHXL_PWMName + * @brief Enum of PWM outputs + */ +typedef enum CC2650_LAUNCHXL_PWMName { + CC2650_LAUNCHXL_PWM0 = 0, + CC2650_LAUNCHXL_PWM1, + CC2650_LAUNCHXL_PWM2, + CC2650_LAUNCHXL_PWM3, + CC2650_LAUNCHXL_PWM4, + CC2650_LAUNCHXL_PWM5, + CC2650_LAUNCHXL_PWM6, + CC2650_LAUNCHXL_PWM7, + + CC2650_LAUNCHXL_PWMCOUNT +} CC2650_LAUNCHXL_PWMName; + +/*! + * @def CC2650_LAUNCHXL_SDName + * @brief Enum of SD names + */ +typedef enum CC2650_LAUNCHXL_SDName { + CC2650_LAUNCHXL_SDSPI0 = 0, + + CC2650_LAUNCHXL_SDCOUNT +} CC2650_LAUNCHXL_SDName; + +/*! + * @def CC2650_LAUNCHXL_SPIName + * @brief Enum of SPI names + */ +typedef enum CC2650_LAUNCHXL_SPIName { +#if TI_SPI_CONF_SPI0_ENABLE + CC2650_LAUNCHXL_SPI0 = 0, +#endif +#if TI_SPI_CONF_SPI1_ENABLE + CC2650_LAUNCHXL_SPI1, +#endif + + CC2650_LAUNCHXL_SPICOUNT +} CC2650_LAUNCHXL_SPIName; + +/*! + * @def CC2650_LAUNCHXL_TRNGName + * @brief Enum of TRNGs + */ +typedef enum CC2650_LAUNCHXL_TRNGName { + CC2650_LAUNCHXL_TRNG0 = 0, + + CC2650_LAUNCHXL_TRNGCOUNT +} CC2650_LAUNCHXL_TRNGName; + +/*! + * @def CC2650_LAUNCHXL_UARTName + * @brief Enum of UARTs + */ +typedef enum CC2650_LAUNCHXL_UARTName { +#if TI_UART_CONF_UART0_ENABLE + CC2650_LAUNCHXL_UART0 = 0, +#endif + + CC2650_LAUNCHXL_UARTCOUNT +} CC2650_LAUNCHXL_UARTName; + +/*! + * @def CC2650_LAUNCHXL_UDMAName + * @brief Enum of DMA buffers + */ +typedef enum CC2650_LAUNCHXL_UDMAName { + CC2650_LAUNCHXL_UDMA0 = 0, + + CC2650_LAUNCHXL_UDMACOUNT +} CC2650_LAUNCHXL_UDMAName; + +/*! + * @def CC2650_LAUNCHXL_WatchdogName + * @brief Enum of Watchdogs + */ +typedef enum CC2650_LAUNCHXL_WatchdogName { + CC2650_LAUNCHXL_WATCHDOG0 = 0, + + CC2650_LAUNCHXL_WATCHDOGCOUNT +} CC2650_LAUNCHXL_WatchdogName; + +#ifdef __cplusplus +} +#endif + +#endif /* __CC2650_LAUNCHXL_BOARD_H__ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/CC2650_LAUNCHXL_fxns.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/CC2650_LAUNCHXL_fxns.c new file mode 100644 index 000000000..f471e33d6 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/CC2650_LAUNCHXL_fxns.c @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +/* + * ======== CC2650_LAUNCHXL_fxns.c ======== + * This file contains the board-specific initialization functions. + */ + +#include +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/cpu.h) + +#include + +#include "Board.h" + +/* + * ======== CC2650_LAUNCHXL_sendExtFlashByte ======== + */ +void CC2650_LAUNCHXL_sendExtFlashByte(PIN_Handle pinHandle, uint8_t byte) +{ + uint8_t i; + + /* SPI Flash CS */ + PIN_setOutputValue(pinHandle, IOID_20, 0); + + for (i = 0; i < 8; i++) { + PIN_setOutputValue(pinHandle, IOID_10, 0); /* SPI Flash CLK */ + + /* SPI Flash MOSI */ + PIN_setOutputValue(pinHandle, IOID_9, (byte >> (7 - i)) & 0x01); + PIN_setOutputValue(pinHandle, IOID_10, 1); /* SPI Flash CLK */ + + /* + * Waste a few cycles to keep the CLK high for at + * least 45% of the period. + * 3 cycles per loop: 8 loops @ 48 Mhz = 0.5 us. + */ + CPUdelay(8); + } + + PIN_setOutputValue(pinHandle, IOID_10, 0); /* CLK */ + PIN_setOutputValue(pinHandle, IOID_20, 1); /* CS */ + + /* + * Keep CS high at least 40 us + * 3 cycles per loop: 700 loops @ 48 Mhz ~= 44 us + */ + CPUdelay(700); +} + +/* + * ======== CC2650_LAUNCHXL_wakeUpExtFlash ======== + */ +void CC2650_LAUNCHXL_wakeUpExtFlash(void) +{ + PIN_Config extFlashPinTable[] = { + /* SPI Flash CS */ + IOID_20 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + PIN_TERMINATE + }; + PIN_State extFlashPinState; + PIN_Handle extFlashPinHandle = PIN_open(&extFlashPinState, extFlashPinTable); + + /* + * To wake up we need to toggle the chip select at + * least 20 ns and ten wait at least 35 us. + */ + + /* Toggle chip select for ~20ns to wake ext. flash */ + PIN_setOutputValue(extFlashPinHandle, IOID_20, 0); + /* 3 cycles per loop: 1 loop @ 48 Mhz ~= 62 ns */ + CPUdelay(1); + PIN_setOutputValue(extFlashPinHandle, IOID_20, 1); + /* 3 cycles per loop: 560 loops @ 48 Mhz ~= 35 us */ + CPUdelay(560); + + PIN_close(extFlashPinHandle); +} + +/* + * ======== CC2650_LAUNCHXL_shutDownExtFlash ======== + */ +void CC2650_LAUNCHXL_shutDownExtFlash(void) +{ + /* + * To be sure we are putting the flash into sleep and not waking it, + * we first have to make a wake up call + */ + CC2650_LAUNCHXL_wakeUpExtFlash(); + + PIN_Config extFlashPinTable[] = { + /* SPI Flash CS*/ + IOID_20 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash CLK */ + IOID_10 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash MOSI */ + IOID_9 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash MISO */ + IOID_8 | PIN_INPUT_EN | PIN_PULLDOWN, + PIN_TERMINATE + }; + PIN_State extFlashPinState; + PIN_Handle extFlashPinHandle = PIN_open(&extFlashPinState, extFlashPinTable); + + uint8_t extFlashShutdown = 0xB9; + + CC2650_LAUNCHXL_sendExtFlashByte(extFlashPinHandle, extFlashShutdown); + + PIN_close(extFlashPinHandle); +} + +/* + * ======== Board_initHook ======== + * Called by Board_init() to perform board-specific initialization. + */ +void Board_initHook() +{ + CC2650_LAUNCHXL_shutDownExtFlash(); +} diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/Makefile.cc2650 b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/Makefile.cc2650 new file mode 100644 index 000000000..d03a02397 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/Makefile.cc2650 @@ -0,0 +1,21 @@ +################################################################################ +# SimpleLink Device makefile + +SUBFAMILY = cc13x0-cc26x0 +DEVICE_FAMILY = CC26X0 +DEVICE_LINE = CC26XX +DEVICE = CC2650 + +BOARD_SOURCEFILES += CC2650_LAUNCHXL.c CC2650_LAUNCHXL_fxns.c + +SUPPORTS_PROP_MODE = 0 +SUPPORTS_IEEE_MODE = 1 +SUPPORTS_BLE_BEACON = 1 + +SUPPORTS_HIGH_PA = 0 + +### Signal that we can be programmed with cc2538-bsl +BOARD_SUPPORTS_BSL = 1 + +# Include the common board makefile +include $(FAMILY_PATH)/launchpad/Makefile.launchpad diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/Board.h new file mode 100644 index 000000000..a19145b2c --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/Board.h @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2015-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 __BOARD_H +#define __BOARD_H + +#define Board_CC26X2R1_LAUNCHXL +#define BOARD_STRING "TI CC26x2R1 LaunchPad" + +#ifdef __cplusplus +extern "C" { +#endif + +#include "CC26X2R1_LAUNCHXL.h" + +#define Board_initGeneral() CC26X2R1_LAUNCHXL_initGeneral() + +#define Board_shutDownExtFlash() CC26X2R1_LAUNCHXL_shutDownExtFlash() + +#define Board_wakeUpExtFlash() CC26X2R1_LAUNCHXL_wakeUpExtFlash() + +/* These #defines allow us to reuse TI-RTOS across other device families */ + +#define Board_ADC0 CC26X2R1_LAUNCHXL_ADC0 +#define Board_ADC1 CC26X2R1_LAUNCHXL_ADC1 + +#define Board_ADCBUF0 CC26X2R1_LAUNCHXL_ADCBUF0 +#define Board_ADCBUF0CHANNEL0 CC26X2R1_LAUNCHXL_ADCBUF0CHANNEL0 +#define Board_ADCBUF0CHANNEL1 CC26X2R1_LAUNCHXL_ADCBUF0CHANNEL1 + +#define Board_ECDH0 CC26X2R1_LAUNCHXL_ECDH0 +#define Board_ECDSA0 CC26X2R1_LAUNCHXL_ECDSA0 +#define Board_ECJPAKE0 CC26X2R1_LAUNCHXL_ECJPAKE0 +#define Board_AESCCM0 CC26X2R1_LAUNCHXL_AESCCM0 +#define Board_AESECB0 CC26X2R1_LAUNCHXL_AESECB0 +#define Board_SHA20 CC26X2R1_LAUNCHXL_SHA20 + +#define Board_DIO0 CC26X2R1_LAUNCHXL_DIO0 +#define Board_DIO1_RFSW CC26X2R1_LAUNCHXL_DIO1_RFSW +#define Board_DIO12 CC26X2R1_LAUNCHXL_DIO12 +#define Board_DIO15 CC26X2R1_LAUNCHXL_DIO15 +#define Board_DIO16_TDO CC26X2R1_LAUNCHXL_DIO16_TDO +#define Board_DIO17_TDI CC26X2R1_LAUNCHXL_DIO17_TDI +#define Board_DIO21 CC26X2R1_LAUNCHXL_DIO21 +#define Board_DIO22 CC26X2R1_LAUNCHXL_DIO22 + +#define Board_DIO23_ANALOG CC26X2R1_LAUNCHXL_DIO23_ANALOG +#define Board_DIO24_ANALOG CC26X2R1_LAUNCHXL_DIO24_ANALOG +#define Board_DIO25_ANALOG CC26X2R1_LAUNCHXL_DIO25_ANALOG +#define Board_DIO26_ANALOG CC26X2R1_LAUNCHXL_DIO26_ANALOG +#define Board_DIO27_ANALOG CC26X2R1_LAUNCHXL_DIO27_ANALOG +#define Board_DIO28_ANALOG CC26X2R1_LAUNCHXL_DIO28_ANALOG +#define Board_DIO29_ANALOG CC26X2R1_LAUNCHXL_DIO29_ANALOG +#define Board_DIO30_ANALOG CC26X2R1_LAUNCHXL_DIO30_ANALOG + +#define Board_GPIO_BUTTON0 CC26X2R1_LAUNCHXL_GPIO_S1 +#define Board_GPIO_BUTTON1 CC26X2R1_LAUNCHXL_GPIO_S2 +#define Board_GPIO_BTN1 CC26X2R1_LAUNCHXL_GPIO_S1 +#define Board_GPIO_BTN2 CC26X2R1_LAUNCHXL_GPIO_S2 +#define Board_GPIO_LED0 CC26X2R1_LAUNCHXL_GPIO_LED_RED +#define Board_GPIO_LED1 CC26X2R1_LAUNCHXL_GPIO_LED_GREEN +#define Board_GPIO_LED2 CC26X2R1_LAUNCHXL_GPIO_LED_RED +#define Board_GPIO_RLED CC26X2R1_LAUNCHXL_GPIO_LED_RED +#define Board_GPIO_GLED CC26X2R1_LAUNCHXL_GPIO_LED_GREEN +#define Board_GPIO_LED_ON CC26X2R1_LAUNCHXL_GPIO_LED_ON +#define Board_GPIO_LED_OFF CC26X2R1_LAUNCHXL_GPIO_LED_OFF + +#define Board_GPTIMER0A CC26X2R1_LAUNCHXL_GPTIMER0A +#define Board_GPTIMER0B CC26X2R1_LAUNCHXL_GPTIMER0B +#define Board_GPTIMER1A CC26X2R1_LAUNCHXL_GPTIMER1A +#define Board_GPTIMER1B CC26X2R1_LAUNCHXL_GPTIMER1B +#define Board_GPTIMER2A CC26X2R1_LAUNCHXL_GPTIMER2A +#define Board_GPTIMER2B CC26X2R1_LAUNCHXL_GPTIMER2B +#define Board_GPTIMER3A CC26X2R1_LAUNCHXL_GPTIMER3A +#define Board_GPTIMER3B CC26X2R1_LAUNCHXL_GPTIMER3B + +#define Board_I2C0 CC26X2R1_LAUNCHXL_I2C0 +#define Board_I2C_TMP Board_I2C0 + +#define Board_NVSINTERNAL CC26X2R1_LAUNCHXL_NVSCC26XX0 +#define Board_NVSEXTERNAL CC26X2R1_LAUNCHXL_NVSSPI25X0 + +#define Board_PIN_BUTTON0 CC26X2R1_LAUNCHXL_PIN_BTN1 +#define Board_PIN_BUTTON1 CC26X2R1_LAUNCHXL_PIN_BTN2 +#define Board_PIN_BTN1 CC26X2R1_LAUNCHXL_PIN_BTN1 +#define Board_PIN_BTN2 CC26X2R1_LAUNCHXL_PIN_BTN2 +#define Board_PIN_LED0 CC26X2R1_LAUNCHXL_PIN_RLED +#define Board_PIN_LED1 CC26X2R1_LAUNCHXL_PIN_GLED +#define Board_PIN_LED2 CC26X2R1_LAUNCHXL_PIN_RLED +#define Board_PIN_RLED CC26X2R1_LAUNCHXL_PIN_RLED +#define Board_PIN_GLED CC26X2R1_LAUNCHXL_PIN_GLED + +#define Board_PWM0 CC26X2R1_LAUNCHXL_PWM0 +#define Board_PWM1 CC26X2R1_LAUNCHXL_PWM1 +#define Board_PWM2 CC26X2R1_LAUNCHXL_PWM2 +#define Board_PWM3 CC26X2R1_LAUNCHXL_PWM3 +#define Board_PWM4 CC26X2R1_LAUNCHXL_PWM4 +#define Board_PWM5 CC26X2R1_LAUNCHXL_PWM5 +#define Board_PWM6 CC26X2R1_LAUNCHXL_PWM6 +#define Board_PWM7 CC26X2R1_LAUNCHXL_PWM7 + +#define Board_SD0 CC26X2R1_LAUNCHXL_SDSPI0 + +#define Board_SPI0 CC26X2R1_LAUNCHXL_SPI0 +#define Board_SPI0_MISO CC26X2R1_LAUNCHXL_SPI0_MISO +#define Board_SPI0_MOSI CC26X2R1_LAUNCHXL_SPI0_MOSI +#define Board_SPI0_CLK CC26X2R1_LAUNCHXL_SPI0_CLK +#define Board_SPI0_CSN CC26X2R1_LAUNCHXL_SPI0_CSN +#define Board_SPI1 CC26X2R1_LAUNCHXL_SPI1 +#define Board_SPI1_MISO CC26X2R1_LAUNCHXL_SPI1_MISO +#define Board_SPI1_MOSI CC26X2R1_LAUNCHXL_SPI1_MOSI +#define Board_SPI1_CLK CC26X2R1_LAUNCHXL_SPI1_CLK +#define Board_SPI1_CSN CC26X2R1_LAUNCHXL_SPI1_CSN +#define Board_SPI_FLASH_CS CC26X2R1_LAUNCHXL_SPI_FLASH_CS +#define Board_FLASH_CS_ON 0 +#define Board_FLASH_CS_OFF 1 + +#define Board_SPI_MASTER CC26X2R1_LAUNCHXL_SPI0 +#define Board_SPI_SLAVE CC26X2R1_LAUNCHXL_SPI0 +#define Board_SPI_MASTER_READY CC26X2R1_LAUNCHXL_SPI_MASTER_READY +#define Board_SPI_SLAVE_READY CC26X2R1_LAUNCHXL_SPI_SLAVE_READY + +#define Board_UART0 CC26X2R1_LAUNCHXL_UART0 +#define Board_UART1 CC26X2R1_LAUNCHXL_UART1 + +#define Board_WATCHDOG0 CC26X2R1_LAUNCHXL_WATCHDOG0 + +/* Board specific I2C addresses */ +#define Board_TMP_ADDR (0x40) +#define Board_SENSORS_BP_TMP_ADDR Board_TMP_ADDR + +#ifdef __cplusplus +} +#endif + +#endif /* __BOARD_H */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/CC26X2R1_LAUNCHXL.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/CC26X2R1_LAUNCHXL.c new file mode 100644 index 000000000..db47744de --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/CC26X2R1_LAUNCHXL.c @@ -0,0 +1,968 @@ +/* + * Copyright (c) 2016-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +/* + * ====================== CC26X2R1_LAUNCHXL.c =================================== + * This file is responsible for setting up the board specific items for the + * CC26X2R1_LAUNCHXL board. + */ +#include "contiki.h" + +#include +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/udma.h) +#include DeviceFamily_constructPath(inc/hw_ints.h) +#include DeviceFamily_constructPath(inc/hw_memmap.h) + +#include "CC26X2R1_LAUNCHXL.h" + +/* + * =============================== ADCBuf =============================== + */ +#include +#include + +ADCBufCC26X2_Object adcBufCC26xxObjects[CC26X2R1_LAUNCHXL_ADCBUFCOUNT]; + +/* + * This table converts a virtual adc channel into a dio and internal analogue + * input signal. This table is necessary for the functioning of the adcBuf + * driver. Comment out unused entries to save flash. Dio and internal signal + * pairs are hardwired. Do not remap them in the table. You may reorder entire + * entries. The mapping of dio and internal signals is package dependent. + */ +const ADCBufCC26X2_AdcChannelLutEntry ADCBufCC26X2_adcChannelLut[CC26X2R1_LAUNCHXL_ADCBUF0CHANNELCOUNT] = { + {CC26X2R1_LAUNCHXL_DIO23_ANALOG, ADC_COMPB_IN_AUXIO7}, + {CC26X2R1_LAUNCHXL_DIO24_ANALOG, ADC_COMPB_IN_AUXIO6}, + {CC26X2R1_LAUNCHXL_DIO25_ANALOG, ADC_COMPB_IN_AUXIO5}, + {CC26X2R1_LAUNCHXL_DIO26_ANALOG, ADC_COMPB_IN_AUXIO4}, + {CC26X2R1_LAUNCHXL_DIO27_ANALOG, ADC_COMPB_IN_AUXIO3}, + {CC26X2R1_LAUNCHXL_DIO28_ANALOG, ADC_COMPB_IN_AUXIO2}, + {CC26X2R1_LAUNCHXL_DIO29_ANALOG, ADC_COMPB_IN_AUXIO1}, + {CC26X2R1_LAUNCHXL_DIO30_ANALOG, ADC_COMPB_IN_AUXIO0}, + {PIN_UNASSIGNED, ADC_COMPB_IN_VDDS}, + {PIN_UNASSIGNED, ADC_COMPB_IN_DCOUPL}, + {PIN_UNASSIGNED, ADC_COMPB_IN_VSS}, +}; + +const ADCBufCC26X2_HWAttrs adcBufCC26xxHWAttrs[CC26X2R1_LAUNCHXL_ADCBUFCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + .adcChannelLut = ADCBufCC26X2_adcChannelLut, + .gpTimerUnit = CC26X2R1_LAUNCHXL_GPTIMER0A, + } +}; + +const ADCBuf_Config ADCBuf_config[CC26X2R1_LAUNCHXL_ADCBUFCOUNT] = { + { + &ADCBufCC26X2_fxnTable, + &adcBufCC26xxObjects[CC26X2R1_LAUNCHXL_ADCBUF0], + &adcBufCC26xxHWAttrs[CC26X2R1_LAUNCHXL_ADCBUF0] + }, +}; + +const uint_least8_t ADCBuf_count = CC26X2R1_LAUNCHXL_ADCBUFCOUNT; + +/* + * =============================== ADC =============================== + */ +#include +#include + +ADCCC26XX_Object adcCC26xxObjects[CC26X2R1_LAUNCHXL_ADCCOUNT]; + +const ADCCC26XX_HWAttrs adcCC26xxHWAttrs[CC26X2R1_LAUNCHXL_ADCCOUNT] = { + { + .adcDIO = CC26X2R1_LAUNCHXL_DIO23_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO7, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC26X2R1_LAUNCHXL_DIO24_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO6, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC26X2R1_LAUNCHXL_DIO25_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO5, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC26X2R1_LAUNCHXL_DIO26_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO4, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC26X2R1_LAUNCHXL_DIO27_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO3, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC26X2R1_LAUNCHXL_DIO28_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO2, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC26X2R1_LAUNCHXL_DIO29_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO1, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = CC26X2R1_LAUNCHXL_DIO30_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO0, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_10P9_MS, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_DCOUPL, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_VSS, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_VDDS, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + } +}; + +const ADC_Config ADC_config[CC26X2R1_LAUNCHXL_ADCCOUNT] = { + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC26X2R1_LAUNCHXL_ADC0], &adcCC26xxHWAttrs[CC26X2R1_LAUNCHXL_ADC0]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC26X2R1_LAUNCHXL_ADC1], &adcCC26xxHWAttrs[CC26X2R1_LAUNCHXL_ADC1]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC26X2R1_LAUNCHXL_ADC2], &adcCC26xxHWAttrs[CC26X2R1_LAUNCHXL_ADC2]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC26X2R1_LAUNCHXL_ADC3], &adcCC26xxHWAttrs[CC26X2R1_LAUNCHXL_ADC3]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC26X2R1_LAUNCHXL_ADC4], &adcCC26xxHWAttrs[CC26X2R1_LAUNCHXL_ADC4]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC26X2R1_LAUNCHXL_ADC5], &adcCC26xxHWAttrs[CC26X2R1_LAUNCHXL_ADC5]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC26X2R1_LAUNCHXL_ADC6], &adcCC26xxHWAttrs[CC26X2R1_LAUNCHXL_ADC6]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC26X2R1_LAUNCHXL_ADC7], &adcCC26xxHWAttrs[CC26X2R1_LAUNCHXL_ADC7]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC26X2R1_LAUNCHXL_ADCDCOUPL], &adcCC26xxHWAttrs[CC26X2R1_LAUNCHXL_ADCDCOUPL]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC26X2R1_LAUNCHXL_ADCVSS], &adcCC26xxHWAttrs[CC26X2R1_LAUNCHXL_ADCVSS]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC26X2R1_LAUNCHXL_ADCVDDS], &adcCC26xxHWAttrs[CC26X2R1_LAUNCHXL_ADCVDDS]}, +}; + +const uint_least8_t ADC_count = CC26X2R1_LAUNCHXL_ADCCOUNT; + + +/* + * =============================== ECDH =============================== + */ +#include +#include + +ECDHCC26X2_Object ecdhCC26X2Objects[CC26X2R1_LAUNCHXL_ECDHCOUNT]; + +const ECDHCC26X2_HWAttrs ecdhCC26X2HWAttrs[CC26X2R1_LAUNCHXL_ECDHCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const ECDH_Config ECDH_config[CC26X2R1_LAUNCHXL_ECDHCOUNT] = { + { + .object = &ecdhCC26X2Objects[CC26X2R1_LAUNCHXL_ECDH0], + .hwAttrs = &ecdhCC26X2HWAttrs[CC26X2R1_LAUNCHXL_ECDH0] + }, +}; + +const uint_least8_t ECDH_count = CC26X2R1_LAUNCHXL_ECDHCOUNT; + +/* + * =============================== ECDSA =============================== + */ +#include +#include + +ECDSACC26X2_Object ecdsaCC26X2Objects[CC26X2R1_LAUNCHXL_ECDSACOUNT]; + +const ECDSACC26X2_HWAttrs ecdsaCC26X2HWAttrs[CC26X2R1_LAUNCHXL_ECDSACOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const ECDSA_Config ECDSA_config[CC26X2R1_LAUNCHXL_ECDSACOUNT] = { + { + .object = &ecdsaCC26X2Objects[CC26X2R1_LAUNCHXL_ECDSA0], + .hwAttrs = &ecdsaCC26X2HWAttrs[CC26X2R1_LAUNCHXL_ECDSA0] + }, +}; + +const uint_least8_t ECDSA_count = CC26X2R1_LAUNCHXL_ECDSACOUNT; + +/* + * =============================== ECJPAKE =============================== + */ +#include +#include + +ECJPAKECC26X2_Object ecjpakeCC26X2Objects[CC26X2R1_LAUNCHXL_ECJPAKECOUNT]; + +const ECJPAKECC26X2_HWAttrs ecjpakeCC26X2HWAttrs[CC26X2R1_LAUNCHXL_ECJPAKECOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const ECJPAKE_Config ECJPAKE_config[CC26X2R1_LAUNCHXL_ECJPAKECOUNT] = { + { + .object = &ecjpakeCC26X2Objects[CC26X2R1_LAUNCHXL_ECJPAKE0], + .hwAttrs = &ecjpakeCC26X2HWAttrs[CC26X2R1_LAUNCHXL_ECJPAKE0] + }, +}; + +const uint_least8_t ECJPAKE_count = CC26X2R1_LAUNCHXL_ECJPAKECOUNT; + +/* + * =============================== SHA2 =============================== + */ +#include +#include + +SHA2CC26X2_Object sha2CC26X2Objects[CC26X2R1_LAUNCHXL_SHA2COUNT]; + +const SHA2CC26X2_HWAttrs sha2CC26X2HWAttrs[CC26X2R1_LAUNCHXL_SHA2COUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const SHA2_Config SHA2_config[CC26X2R1_LAUNCHXL_SHA2COUNT] = { + { + .object = &sha2CC26X2Objects[CC26X2R1_LAUNCHXL_SHA20], + .hwAttrs = &sha2CC26X2HWAttrs[CC26X2R1_LAUNCHXL_SHA20] + }, +}; + +const uint_least8_t SHA2_count = CC26X2R1_LAUNCHXL_SHA2COUNT; + +/* + * =============================== AESCCM =============================== + */ +#include +#include + +AESCCMCC26XX_Object aesccmCC26XXObjects[CC26X2R1_LAUNCHXL_AESCCMCOUNT]; + +const AESCCMCC26XX_HWAttrs aesccmCC26XXHWAttrs[CC26X2R1_LAUNCHXL_AESCCMCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const AESCCM_Config AESCCM_config[CC26X2R1_LAUNCHXL_AESCCMCOUNT] = { + { + .object = &aesccmCC26XXObjects[CC26X2R1_LAUNCHXL_AESCCM0], + .hwAttrs = &aesccmCC26XXHWAttrs[CC26X2R1_LAUNCHXL_AESCCM0] + }, +}; + +const uint_least8_t AESCCM_count = CC26X2R1_LAUNCHXL_AESCCMCOUNT; + +/* + * =============================== AESECB =============================== + */ +#include +#include + +AESECBCC26XX_Object aesecbCC26XXObjects[CC26X2R1_LAUNCHXL_AESECBCOUNT]; + +const AESECBCC26XX_HWAttrs aesecbCC26XXHWAttrs[CC26X2R1_LAUNCHXL_AESECBCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + } +}; + +const AESECB_Config AESECB_config[CC26X2R1_LAUNCHXL_AESECBCOUNT] = { + { + .object = &aesecbCC26XXObjects[CC26X2R1_LAUNCHXL_AESECB0], + .hwAttrs = &aesecbCC26XXHWAttrs[CC26X2R1_LAUNCHXL_AESECB0] + }, +}; + +const uint_least8_t AESECB_count = CC26X2R1_LAUNCHXL_AESECBCOUNT; + +/* + * =============================== GPIO =============================== + */ +#include +#include + +/* + * Array of Pin configurations + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC26X2R1_LAUNCHXL.h + * NOTE: Pins not used for interrupts should be placed at the end of the + * array. Callback entries can be omitted from callbacks array to + * reduce memory usage. + */ +GPIO_PinConfig gpioPinConfigs[] = { + /* Input pins */ + GPIOCC26XX_DIO_13 | GPIO_DO_NOT_CONFIG, /* Button 0 */ + GPIOCC26XX_DIO_14 | GPIO_DO_NOT_CONFIG, /* Button 1 */ + + GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG, /* CC26X2R1_LAUNCHXL_SPI_MASTER_READY */ + GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG, /* CC26X2R1_LAUNCHXL_SPI_SLAVE_READY */ + + /* Output pins */ + GPIOCC26XX_DIO_07 | GPIO_DO_NOT_CONFIG, /* Green LED */ + GPIOCC26XX_DIO_06 | GPIO_DO_NOT_CONFIG, /* Red LED */ + + /* SPI Flash CSN */ + GPIOCC26XX_DIO_20 | GPIO_DO_NOT_CONFIG, + + /* SD CS */ + GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG, +}; + +/* + * Array of callback function pointers + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC26X2R1_LAUNCH.h + * NOTE: Pins not used for interrupts can be omitted from callbacks array to + * reduce memory usage (if placed at end of gpioPinConfigs array). + */ +GPIO_CallbackFxn gpioCallbackFunctions[] = { + NULL, /* Button 0 */ + NULL, /* Button 1 */ + NULL, /* CC26X2R1_LAUNCHXL_SPI_MASTER_READY */ + NULL, /* CC26X2R1_LAUNCHXL_SPI_SLAVE_READY */ +}; + +const GPIOCC26XX_Config GPIOCC26XX_config = { + .pinConfigs = (GPIO_PinConfig *)gpioPinConfigs, + .callbacks = (GPIO_CallbackFxn *)gpioCallbackFunctions, + .numberOfPinConfigs = CC26X2R1_LAUNCHXL_GPIOCOUNT, + .numberOfCallbacks = sizeof(gpioCallbackFunctions)/sizeof(GPIO_CallbackFxn), + .intPriority = (~0) +}; + +/* + * =============================== GPTimer =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include + +GPTimerCC26XX_Object gptimerCC26XXObjects[CC26X2R1_LAUNCHXL_GPTIMERCOUNT]; + +const GPTimerCC26XX_HWAttrs gptimerCC26xxHWAttrs[CC26X2R1_LAUNCHXL_GPTIMERPARTSCOUNT] = { + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0A, }, + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0B, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1A, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1B, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2A, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2B, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3A, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3B, }, +}; + +const GPTimerCC26XX_Config GPTimerCC26XX_config[CC26X2R1_LAUNCHXL_GPTIMERPARTSCOUNT] = { + { &gptimerCC26XXObjects[CC26X2R1_LAUNCHXL_GPTIMER0], &gptimerCC26xxHWAttrs[CC26X2R1_LAUNCHXL_GPTIMER0A], GPT_A }, + { &gptimerCC26XXObjects[CC26X2R1_LAUNCHXL_GPTIMER0], &gptimerCC26xxHWAttrs[CC26X2R1_LAUNCHXL_GPTIMER0B], GPT_B }, + { &gptimerCC26XXObjects[CC26X2R1_LAUNCHXL_GPTIMER1], &gptimerCC26xxHWAttrs[CC26X2R1_LAUNCHXL_GPTIMER1A], GPT_A }, + { &gptimerCC26XXObjects[CC26X2R1_LAUNCHXL_GPTIMER1], &gptimerCC26xxHWAttrs[CC26X2R1_LAUNCHXL_GPTIMER1B], GPT_B }, + { &gptimerCC26XXObjects[CC26X2R1_LAUNCHXL_GPTIMER2], &gptimerCC26xxHWAttrs[CC26X2R1_LAUNCHXL_GPTIMER2A], GPT_A }, + { &gptimerCC26XXObjects[CC26X2R1_LAUNCHXL_GPTIMER2], &gptimerCC26xxHWAttrs[CC26X2R1_LAUNCHXL_GPTIMER2B], GPT_B }, + { &gptimerCC26XXObjects[CC26X2R1_LAUNCHXL_GPTIMER3], &gptimerCC26xxHWAttrs[CC26X2R1_LAUNCHXL_GPTIMER3A], GPT_A }, + { &gptimerCC26XXObjects[CC26X2R1_LAUNCHXL_GPTIMER3], &gptimerCC26xxHWAttrs[CC26X2R1_LAUNCHXL_GPTIMER3B], GPT_B }, +}; + +/* + * =============================== I2C =============================== +*/ +#include +#include + +#if TI_I2C_CONF_ENABLE + +I2CCC26XX_Object i2cCC26xxObjects[CC26X2R1_LAUNCHXL_I2CCOUNT]; + +const I2CCC26XX_HWAttrsV1 i2cCC26xxHWAttrs[CC26X2R1_LAUNCHXL_I2CCOUNT] = { +#if TI_I2C_CONF_I2C0_ENABLE + { + .baseAddr = I2C0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_I2C0, + .intNum = INT_I2C_IRQ, + .intPriority = ~0, + .swiPriority = 0, + .sdaPin = CC26X2R1_LAUNCHXL_I2C0_SDA0, + .sclPin = CC26X2R1_LAUNCHXL_I2C0_SCL0, + }, +#endif +}; + +const I2C_Config I2C_config[CC26X2R1_LAUNCHXL_I2CCOUNT] = { +#if TI_I2C_CONF_I2C0_ENABLE + { + .fxnTablePtr = &I2CCC26XX_fxnTable, + .object = &i2cCC26xxObjects[CC26X2R1_LAUNCHXL_I2C0], + .hwAttrs = &i2cCC26xxHWAttrs[CC26X2R1_LAUNCHXL_I2C0] + }, +#endif +}; + +const uint_least8_t I2C_count = CC26X2R1_LAUNCHXL_I2CCOUNT; + +#endif /* TI_I2C_CONF_ENABLE */ + +/* + * =============================== NVS =============================== + */ +#include +#include +#include + +#define NVS_REGIONS_BASE 0x48000 +#define SECTORSIZE 0x2000 +#define REGIONSIZE (SECTORSIZE * 4) + +#if TI_NVS_CONF_ENABLE + +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + +/* + * Reserve flash sectors for NVS driver use by placing an uninitialized byte + * array at the desired flash address. + */ +#if defined(__TI_COMPILER_VERSION__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +#pragma LOCATION(flashBuf, NVS_REGIONS_BASE); +#pragma NOINIT(flashBuf); +static char flashBuf[REGIONSIZE]; + +#elif defined(__IAR_SYSTEMS_ICC__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +static __no_init char flashBuf[REGIONSIZE] @ NVS_REGIONS_BASE; + +#elif defined(__GNUC__) + +/* + * Place the flash buffers in the .nvs section created in the gcc linker file. + * The .nvs section enforces alignment on a sector boundary but may + * be placed anywhere in flash memory. If desired the .nvs section can be set + * to a fixed address by changing the following in the gcc linker file: + * + * .nvs (FIXED_FLASH_ADDR) (NOLOAD) : AT (FIXED_FLASH_ADDR) { + * *(.nvs) + * } > REGION_TEXT + */ +__attribute__ ((section (".nvs"))) +static char flashBuf[REGIONSIZE]; + +#endif + +/* Allocate objects for NVS Internal Regions */ +NVSCC26XX_Object nvsCC26xxObjects[1]; + +/* Hardware attributes for NVS Internal Regions */ +const NVSCC26XX_HWAttrs nvsCC26xxHWAttrs[1] = { + { + .regionBase = (void *)flashBuf, + .regionSize = REGIONSIZE, + }, +}; + +#endif /* TI_NVS_CONF_NVS_INTERNAL_ENABLE */ + +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + +#define SPISECTORSIZE 0x1000 +#define SPIREGIONSIZE (SPISECTORSIZE * 32) +#define VERIFYBUFSIZE 64 + +static uint8_t verifyBuf[VERIFYBUFSIZE]; + +/* Allocate objects for NVS External Regions */ +NVSSPI25X_Object nvsSPI25XObjects[1]; + +/* Hardware attributes for NVS External Regions */ +const NVSSPI25X_HWAttrs nvsSPI25XHWAttrs[1] = { + { + .regionBaseOffset = 0, + .regionSize = SPIREGIONSIZE, + .sectorSize = SPISECTORSIZE, + .verifyBuf = verifyBuf, + .verifyBufSize = VERIFYBUFSIZE, + .spiHandle = NULL, + .spiIndex = 0, + .spiBitRate = 4000000, + .spiCsnGpioIndex = CC26X2R1_LAUNCHXL_GPIO_SPI_FLASH_CS, + }, +}; + +#endif /* TI_NVS_CONF_NVS_EXTERNAL_ENABLE */ + +/* NVS Region index 0 and 1 refer to NVS and NVS SPI respectively */ +const NVS_Config NVS_config[CC26X2R1_LAUNCHXL_NVSCOUNT] = { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + { + .fxnTablePtr = &NVSCC26XX_fxnTable, + .object = &nvsCC26xxObjects[0], + .hwAttrs = &nvsCC26xxHWAttrs[0], + }, +#endif +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + { + .fxnTablePtr = &NVSSPI25X_fxnTable, + .object = &nvsSPI25XObjects[0], + .hwAttrs = &nvsSPI25XHWAttrs[0], + }, +#endif +}; + +const uint_least8_t NVS_count = CC26X2R1_LAUNCHXL_NVSCOUNT; + +#endif /* TI_NVS_CONF_ENABLE */ + +/* + * =============================== PIN =============================== + */ +#include +#include + +const PIN_Config BoardGpioInitTable[] = { + + CC26X2R1_LAUNCHXL_PIN_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC26X2R1_LAUNCHXL_PIN_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC26X2R1_LAUNCHXL_PIN_BTN1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC26X2R1_LAUNCHXL_PIN_BTN2 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC26X2R1_LAUNCHXL_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ + CC26X2R1_LAUNCHXL_UART0_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */ + CC26X2R1_LAUNCHXL_UART0_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */ + CC26X2R1_LAUNCHXL_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */ + CC26X2R1_LAUNCHXL_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */ + CC26X2R1_LAUNCHXL_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI clock */ + + PIN_TERMINATE +}; + +const PINCC26XX_HWAttrs PINCC26XX_hwAttrs = { + .intPriority = ~0, + .swiPriority = 0 +}; + +/* + * =============================== Power =============================== + */ +#include +#include + +const PowerCC26X2_Config PowerCC26X2_config = { + .policyInitFxn = NULL, + .policyFxn = &PowerCC26XX_standbyPolicy, + .calibrateFxn = &PowerCC26XX_calibrate, + .enablePolicy = true, + .calibrateRCOSC_LF = true, + .calibrateRCOSC_HF = true, +}; + +/* + * =============================== PWM =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include +#include + +PWMTimerCC26XX_Object pwmtimerCC26xxObjects[CC26X2R1_LAUNCHXL_PWMCOUNT]; + +const PWMTimerCC26XX_HwAttrs pwmtimerCC26xxHWAttrs[CC26X2R1_LAUNCHXL_PWMCOUNT] = { + { .pwmPin = CC26X2R1_LAUNCHXL_PWMPIN0, .gpTimerUnit = CC26X2R1_LAUNCHXL_GPTIMER0A }, + { .pwmPin = CC26X2R1_LAUNCHXL_PWMPIN1, .gpTimerUnit = CC26X2R1_LAUNCHXL_GPTIMER0B }, + { .pwmPin = CC26X2R1_LAUNCHXL_PWMPIN2, .gpTimerUnit = CC26X2R1_LAUNCHXL_GPTIMER1A }, + { .pwmPin = CC26X2R1_LAUNCHXL_PWMPIN3, .gpTimerUnit = CC26X2R1_LAUNCHXL_GPTIMER1B }, + { .pwmPin = CC26X2R1_LAUNCHXL_PWMPIN4, .gpTimerUnit = CC26X2R1_LAUNCHXL_GPTIMER2A }, + { .pwmPin = CC26X2R1_LAUNCHXL_PWMPIN5, .gpTimerUnit = CC26X2R1_LAUNCHXL_GPTIMER2B }, + { .pwmPin = CC26X2R1_LAUNCHXL_PWMPIN6, .gpTimerUnit = CC26X2R1_LAUNCHXL_GPTIMER3A }, + { .pwmPin = CC26X2R1_LAUNCHXL_PWMPIN7, .gpTimerUnit = CC26X2R1_LAUNCHXL_GPTIMER3B }, +}; + +const PWM_Config PWM_config[CC26X2R1_LAUNCHXL_PWMCOUNT] = { + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC26X2R1_LAUNCHXL_PWM0], &pwmtimerCC26xxHWAttrs[CC26X2R1_LAUNCHXL_PWM0] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC26X2R1_LAUNCHXL_PWM1], &pwmtimerCC26xxHWAttrs[CC26X2R1_LAUNCHXL_PWM1] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC26X2R1_LAUNCHXL_PWM2], &pwmtimerCC26xxHWAttrs[CC26X2R1_LAUNCHXL_PWM2] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC26X2R1_LAUNCHXL_PWM3], &pwmtimerCC26xxHWAttrs[CC26X2R1_LAUNCHXL_PWM3] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC26X2R1_LAUNCHXL_PWM4], &pwmtimerCC26xxHWAttrs[CC26X2R1_LAUNCHXL_PWM4] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC26X2R1_LAUNCHXL_PWM5], &pwmtimerCC26xxHWAttrs[CC26X2R1_LAUNCHXL_PWM5] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC26X2R1_LAUNCHXL_PWM6], &pwmtimerCC26xxHWAttrs[CC26X2R1_LAUNCHXL_PWM6] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC26X2R1_LAUNCHXL_PWM7], &pwmtimerCC26xxHWAttrs[CC26X2R1_LAUNCHXL_PWM7] }, +}; + +const uint_least8_t PWM_count = CC26X2R1_LAUNCHXL_PWMCOUNT; + +/* + * =============================== RF Driver =============================== + */ +#include + +const RFCC26XX_HWAttrsV2 RFCC26XX_hwAttrs = { + .hwiPriority = ~0, /* Lowest HWI priority */ + .swiPriority = 0, /* Lowest SWI priority */ + .xoscHfAlwaysNeeded = true, /* Keep XOSC dependency while in stanby */ + .globalCallback = NULL, /* No board specific callback */ + .globalEventMask = 0 /* No events subscribed to */ +}; + +/* + * =============================== SD =============================== + */ +#include +#include + +#if TI_SD_CONF_ENABLE + +#if !(TI_SPI_CONF_SPI0_ENABLE) +#error "SD driver requires SPI0 enabled" +#endif + +SDSPI_Object sdspiObjects[CC26X2R1_LAUNCHXL_SDCOUNT]; + +const SDSPI_HWAttrs sdspiHWAttrs[CC26X2R1_LAUNCHXL_SDCOUNT] = { + { + .spiIndex = CC26X2R1_LAUNCHXL_SPI0, + .spiCsGpioIndex = CC26X2R1_LAUNCHXL_SDSPI_CS + } +}; + +const SD_Config SD_config[CC26X2R1_LAUNCHXL_SDCOUNT] = { + { + .fxnTablePtr = &SDSPI_fxnTable, + .object = &sdspiObjects[CC26X2R1_LAUNCHXL_SDSPI0], + .hwAttrs = &sdspiHWAttrs[CC26X2R1_LAUNCHXL_SDSPI0] + }, +}; + +const uint_least8_t SD_count = CC26X2R1_LAUNCHXL_SDCOUNT; + +#endif /* TI_SD_CONF_ENABLE */ + +/* + * =============================== SPI DMA =============================== + */ +#include +#include + +#if TI_SPI_CONF_ENABLE + +SPICC26XXDMA_Object spiCC26XXDMAObjects[CC26X2R1_LAUNCHXL_SPICOUNT]; + +/* + * NOTE: The SPI instances below can be used by the SD driver to communicate + * with a SD card via SPI. The 'defaultTxBufValue' fields below are set to 0xFF + * to satisfy the SDSPI driver requirement. + */ +const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[CC26X2R1_LAUNCHXL_SPICOUNT] = { +#if TI_SPI_CONF_SPI0_ENABLE + { + .baseAddr = SSI0_BASE, + .intNum = INT_SSI0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .powerMngrId = PowerCC26XX_PERIPH_SSI0, + .defaultTxBufValue = 0xFF, + .rxChannelBitMask = 1< +#include + +TRNGCC26X2_Object trngCC26X2Object[CC26X2R1_LAUNCHXL_TRNGCOUNT]; + +const TRNGCC26X2_HWAttrs trngCC26X2HWAttrs[CC26X2R1_LAUNCHXL_TRNGCOUNT] = { + { + .swiPriority = 0, + .intPriority = ~0, + } +}; + +const TRNG_Config TRNG_config[] = { + { &trngCC26X2Object[0], &trngCC26X2HWAttrs[0] }, +}; + +const uint8_t TRNG_count = CC26X2R1_LAUNCHXL_TRNGCOUNT; + + +/* + * =============================== UART =============================== + */ +#include +#include + +#if TI_UART_CONF_ENABLE + +UARTCC26XX_Object uartCC26XXObjects[CC26X2R1_LAUNCHXL_UARTCOUNT]; + +uint8_t uartCC26XXRingBuffer[CC26X2R1_LAUNCHXL_UARTCOUNT][32]; + +const UARTCC26XX_HWAttrsV2 uartCC26XXHWAttrs[CC26X2R1_LAUNCHXL_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .baseAddr = UART0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UART0, + .intNum = INT_UART0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .txPin = CC26X2R1_LAUNCHXL_UART0_TX, + .rxPin = CC26X2R1_LAUNCHXL_UART0_RX, + .ctsPin = PIN_UNASSIGNED, + .rtsPin = PIN_UNASSIGNED, + .ringBufPtr = uartCC26XXRingBuffer[CC26X2R1_LAUNCHXL_UART0], + .ringBufSize = sizeof(uartCC26XXRingBuffer[CC26X2R1_LAUNCHXL_UART0]), + .txIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_1_8, + .rxIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_4_8, + .errorFxn = NULL + }, +#endif +#if TI_UART_CONF_UART1_ENABLE + { + .baseAddr = UART1_BASE, + .powerMngrId = PowerCC26X2_PERIPH_UART1, + .intNum = INT_UART1_COMB, + .intPriority = ~0, + .swiPriority = 0, + .txPin = CC26X2R1_LAUNCHXL_UART1_TX, + .rxPin = CC26X2R1_LAUNCHXL_UART1_RX, + .ctsPin = PIN_UNASSIGNED, + .rtsPin = PIN_UNASSIGNED, + .ringBufPtr = uartCC26XXRingBuffer[CC26X2R1_LAUNCHXL_UART1], + .ringBufSize = sizeof(uartCC26XXRingBuffer[CC26X2R1_LAUNCHXL_UART1]), + .txIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_1_8, + .rxIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_4_8, + .errorFxn = NULL + }, +#endif +}; + +const UART_Config UART_config[CC26X2R1_LAUNCHXL_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .fxnTablePtr = &UARTCC26XX_fxnTable, + .object = &uartCC26XXObjects[CC26X2R1_LAUNCHXL_UART0], + .hwAttrs = &uartCC26XXHWAttrs[CC26X2R1_LAUNCHXL_UART0] + }, +#endif +#if TI_UART_CONF_UART1_ENABLE + { + .fxnTablePtr = &UARTCC26XX_fxnTable, + .object = &uartCC26XXObjects[CC26X2R1_LAUNCHXL_UART1], + .hwAttrs = &uartCC26XXHWAttrs[CC26X2R1_LAUNCHXL_UART1] + }, +#endif +}; + +const uint_least8_t UART_count = CC26X2R1_LAUNCHXL_UARTCOUNT; + +#endif /* TI_UART_CONF_ENABLE */ + +/* + * =============================== UDMA =============================== + */ +#include + +UDMACC26XX_Object udmaObjects[CC26X2R1_LAUNCHXL_UDMACOUNT]; + +const UDMACC26XX_HWAttrs udmaHWAttrs[CC26X2R1_LAUNCHXL_UDMACOUNT] = { + { + .baseAddr = UDMA0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UDMA, + .intNum = INT_DMA_ERR, + .intPriority = ~0 + } +}; + +const UDMACC26XX_Config UDMACC26XX_config[CC26X2R1_LAUNCHXL_UDMACOUNT] = { + { + .object = &udmaObjects[CC26X2R1_LAUNCHXL_UDMA0], + .hwAttrs = &udmaHWAttrs[CC26X2R1_LAUNCHXL_UDMA0] + }, +}; + + + +/* + * =============================== Watchdog =============================== + */ +#include +#include + +WatchdogCC26XX_Object watchdogCC26XXObjects[CC26X2R1_LAUNCHXL_WATCHDOGCOUNT]; + +const WatchdogCC26XX_HWAttrs watchdogCC26XXHWAttrs[CC26X2R1_LAUNCHXL_WATCHDOGCOUNT] = { + { + .baseAddr = WDT_BASE, + .reloadValue = 1000 /* Reload value in milliseconds */ + }, +}; + +const Watchdog_Config Watchdog_config[CC26X2R1_LAUNCHXL_WATCHDOGCOUNT] = { + { + .fxnTablePtr = &WatchdogCC26XX_fxnTable, + .object = &watchdogCC26XXObjects[CC26X2R1_LAUNCHXL_WATCHDOG0], + .hwAttrs = &watchdogCC26XXHWAttrs[CC26X2R1_LAUNCHXL_WATCHDOG0] + }, +}; + +const uint_least8_t Watchdog_count = CC26X2R1_LAUNCHXL_WATCHDOGCOUNT; + +/* + * Board-specific initialization function to disable external flash. + * This function is defined in the file CC26X2R1_LAUNCHXL_fxns.c + */ +extern void Board_initHook(void); + +/* + * ======== CC26X2R1_LAUNCHXL_initGeneral ======== + */ +void CC26X2R1_LAUNCHXL_initGeneral(void) +{ + Power_init(); + + if (PIN_init(BoardGpioInitTable) != PIN_SUCCESS) { + /* Error with PIN_init */ + while (1); + } + + /* Perform board-specific initialization */ + Board_initHook(); +} diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/CC26X2R1_LAUNCHXL.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/CC26X2R1_LAUNCHXL.h new file mode 100644 index 000000000..840d937e7 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/CC26X2R1_LAUNCHXL.h @@ -0,0 +1,448 @@ +/* + * Copyright (c) 2015-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 CC26X2R1_LAUNCHXL.h + * + * @brief CC26X2R1_LAUNCHXL Board Specific header file. + * + * The CC26X2R1_LAUNCHXL header file should be included in an application as + * follows: + * @code + * #include "CC26X2R1_LAUNCHXL.h" + * @endcode + * + * ============================================================================ + */ +#ifndef __CC26X2R1_LAUNCHXL_BOARD_H__ +#define __CC26X2R1_LAUNCHXL_BOARD_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "contiki-conf.h" + +/* Includes */ +#include +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) + +/* Externs */ +extern const PIN_Config BoardGpioInitTable[]; + +/* Defines */ +#define CC26X2R1_LAUNCHXL +/* Mapping of pins to board signals using general board aliases + * + */ + +/* Mapping of pins to board signals using general board aliases + * + */ + +/* Analog Capable DIOs */ +#define CC26X2R1_LAUNCHXL_DIO23_ANALOG IOID_23 +#define CC26X2R1_LAUNCHXL_DIO24_ANALOG IOID_24 +#define CC26X2R1_LAUNCHXL_DIO25_ANALOG IOID_25 +#define CC26X2R1_LAUNCHXL_DIO26_ANALOG IOID_26 +#define CC26X2R1_LAUNCHXL_DIO27_ANALOG IOID_27 +#define CC26X2R1_LAUNCHXL_DIO28_ANALOG IOID_28 +#define CC26X2R1_LAUNCHXL_DIO29_ANALOG IOID_29 +#define CC26X2R1_LAUNCHXL_DIO30_ANALOG IOID_30 + +/* Digital IOs */ +#define CC26X2R1_LAUNCHXL_DIO0 IOID_0 +#define CC26X2R1_LAUNCHXL_DIO1_RFSW IOID_1 +#define CC26X2R1_LAUNCHXL_DIO12 IOID_12 +#define CC26X2R1_LAUNCHXL_DIO15 IOID_15 +#define CC26X2R1_LAUNCHXL_DIO16_TDO IOID_16 +#define CC26X2R1_LAUNCHXL_DIO17_TDI IOID_17 +#define CC26X2R1_LAUNCHXL_DIO21 IOID_21 +#define CC26X2R1_LAUNCHXL_DIO22 IOID_22 + +/* Discrete Inputs */ +#define CC26X2R1_LAUNCHXL_PIN_BTN1 IOID_13 +#define CC26X2R1_LAUNCHXL_PIN_BTN2 IOID_14 + +/* GPIO */ +#define CC26X2R1_LAUNCHXL_GPIO_LED_ON 1 +#define CC26X2R1_LAUNCHXL_GPIO_LED_OFF 0 + +/* I2C */ +#define CC26X2R1_LAUNCHXL_I2C0_SCL0 IOID_4 +#define CC26X2R1_LAUNCHXL_I2C0_SDA0 IOID_5 + +/* LEDs */ +#define CC26X2R1_LAUNCHXL_PIN_LED_ON 1 +#define CC26X2R1_LAUNCHXL_PIN_LED_OFF 0 +#define CC26X2R1_LAUNCHXL_PIN_RLED IOID_6 +#define CC26X2R1_LAUNCHXL_PIN_GLED IOID_7 + +/* PWM Outputs */ +#define CC26X2R1_LAUNCHXL_PWMPIN0 CC26X2R1_LAUNCHXL_PIN_RLED +#define CC26X2R1_LAUNCHXL_PWMPIN1 CC26X2R1_LAUNCHXL_PIN_GLED +#define CC26X2R1_LAUNCHXL_PWMPIN2 PIN_UNASSIGNED +#define CC26X2R1_LAUNCHXL_PWMPIN3 PIN_UNASSIGNED +#define CC26X2R1_LAUNCHXL_PWMPIN4 PIN_UNASSIGNED +#define CC26X2R1_LAUNCHXL_PWMPIN5 PIN_UNASSIGNED +#define CC26X2R1_LAUNCHXL_PWMPIN6 PIN_UNASSIGNED +#define CC26X2R1_LAUNCHXL_PWMPIN7 PIN_UNASSIGNED + +/* SPI */ +#define CC26X2R1_LAUNCHXL_SPI_FLASH_CS IOID_20 +#define CC26X2R1_LAUNCHXL_FLASH_CS_ON 0 +#define CC26X2R1_LAUNCHXL_FLASH_CS_OFF 1 + +/* SPI Board */ +#define CC26X2R1_LAUNCHXL_SPI0_MISO IOID_8 /* RF1.20 */ +#define CC26X2R1_LAUNCHXL_SPI0_MOSI IOID_9 /* RF1.18 */ +#define CC26X2R1_LAUNCHXL_SPI0_CLK IOID_10 /* RF1.16 */ +#define CC26X2R1_LAUNCHXL_SPI0_CSN PIN_UNASSIGNED +#define CC26X2R1_LAUNCHXL_SPI1_MISO PIN_UNASSIGNED +#define CC26X2R1_LAUNCHXL_SPI1_MOSI PIN_UNASSIGNED +#define CC26X2R1_LAUNCHXL_SPI1_CLK PIN_UNASSIGNED +#define CC26X2R1_LAUNCHXL_SPI1_CSN PIN_UNASSIGNED + +/* UART Board */ +#define CC26X2R1_LAUNCHXL_UART0_RX IOID_2 /* RXD */ +#define CC26X2R1_LAUNCHXL_UART0_TX IOID_3 /* TXD */ +#define CC26X2R1_LAUNCHXL_UART0_CTS IOID_19 /* CTS */ +#define CC26X2R1_LAUNCHXL_UART0_RTS IOID_18 /* RTS */ +#define CC26X2R1_LAUNCHXL_UART1_RX PIN_UNASSIGNED +#define CC26X2R1_LAUNCHXL_UART1_TX PIN_UNASSIGNED +#define CC26X2R1_LAUNCHXL_UART1_CTS PIN_UNASSIGNED +#define CC26X2R1_LAUNCHXL_UART1_RTS PIN_UNASSIGNED +/* For backward compatibility */ +#define CC26X2R1_LAUNCHXL_UART_RX CC26X2R1_LAUNCHXL_UART0_RX +#define CC26X2R1_LAUNCHXL_UART_TX CC26X2R1_LAUNCHXL_UART0_TX +#define CC26X2R1_LAUNCHXL_UART_CTS CC26X2R1_LAUNCHXL_UART0_CTS +#define CC26X2R1_LAUNCHXL_UART_RTS CC26X2R1_LAUNCHXL_UART0_RTS + +/*! + * @brief Initialize the general board specific settings + * + * This function initializes the general board specific settings. + */ +void CC26X2R1_LAUNCHXL_initGeneral(void); + +/*! + * @brief Shut down the external flash present on the board files + * + * This function bitbangs the SPI sequence necessary to turn off + * the external flash on LaunchPads. + */ +void CC26X2R1_LAUNCHXL_shutDownExtFlash(void); + +/*! + * @brief Wake up the external flash present on the board files + * + * This function toggles the chip select for the amount of time needed + * to wake the chip up. + */ +void CC26X2R1_LAUNCHXL_wakeUpExtFlash(void); + + +/*! + * @def CC26X2R1_LAUNCHXL_ADCBufName + * @brief Enum of ADCs + */ +typedef enum CC26X2R1_LAUNCHXL_ADCBufName { + CC26X2R1_LAUNCHXL_ADCBUF0 = 0, + + CC26X2R1_LAUNCHXL_ADCBUFCOUNT +} CC26X2R1_LAUNCHXL_ADCBufName; + +/*! + * @def CC26X2R1_LAUNCHXL_ADCBuf0ChannelName + * @brief Enum of ADCBuf channels + */ +typedef enum CC26X2R1_LAUNCHXL_ADCBuf0ChannelName { + CC26X2R1_LAUNCHXL_ADCBUF0CHANNEL0 = 0, + CC26X2R1_LAUNCHXL_ADCBUF0CHANNEL1, + CC26X2R1_LAUNCHXL_ADCBUF0CHANNEL2, + CC26X2R1_LAUNCHXL_ADCBUF0CHANNEL3, + CC26X2R1_LAUNCHXL_ADCBUF0CHANNEL4, + CC26X2R1_LAUNCHXL_ADCBUF0CHANNEL5, + CC26X2R1_LAUNCHXL_ADCBUF0CHANNEL6, + CC26X2R1_LAUNCHXL_ADCBUF0CHANNEL7, + CC26X2R1_LAUNCHXL_ADCBUF0CHANNELVDDS, + CC26X2R1_LAUNCHXL_ADCBUF0CHANNELDCOUPL, + CC26X2R1_LAUNCHXL_ADCBUF0CHANNELVSS, + + CC26X2R1_LAUNCHXL_ADCBUF0CHANNELCOUNT +} CC26X2R1_LAUNCHXL_ADCBuf0ChannelName; + +/*! + * @def CC26X2R1_LAUNCHXL_ADCName + * @brief Enum of ADCs + */ +typedef enum CC26X2R1_LAUNCHXL_ADCName { + CC26X2R1_LAUNCHXL_ADC0 = 0, + CC26X2R1_LAUNCHXL_ADC1, + CC26X2R1_LAUNCHXL_ADC2, + CC26X2R1_LAUNCHXL_ADC3, + CC26X2R1_LAUNCHXL_ADC4, + CC26X2R1_LAUNCHXL_ADC5, + CC26X2R1_LAUNCHXL_ADC6, + CC26X2R1_LAUNCHXL_ADC7, + CC26X2R1_LAUNCHXL_ADCDCOUPL, + CC26X2R1_LAUNCHXL_ADCVSS, + CC26X2R1_LAUNCHXL_ADCVDDS, + + CC26X2R1_LAUNCHXL_ADCCOUNT +} CC26X2R1_LAUNCHXL_ADCName; + +/*! + * @def CC26X2R1_LAUNCHXL_ECDHName + * @brief Enum of ECDH names + */ +typedef enum CC26X2R1_LAUNCHXL_ECDHName { + CC26X2R1_LAUNCHXL_ECDH0 = 0, + + CC26X2R1_LAUNCHXL_ECDHCOUNT +} CC26X2R1_LAUNCHXL_ECDHName; + +/*! + * @def CC26X2R1_LAUNCHXL_ECDSAName + * @brief Enum of ECDSA names + */ +typedef enum CC26X2R1_LAUNCHXL_ECDSAName { + CC26X2R1_LAUNCHXL_ECDSA0 = 0, + + CC26X2R1_LAUNCHXL_ECDSACOUNT +} CC26X2R1_LAUNCHXL_ECDSAName; + +/*! + * @def CC26X2R1_LAUNCHXL_ECJPAKEName + * @brief Enum of ECJPAKE names + */ +typedef enum CC26X2R1_LAUNCHXL_ECJPAKEName { + CC26X2R1_LAUNCHXL_ECJPAKE0 = 0, + + CC26X2R1_LAUNCHXL_ECJPAKECOUNT +} CC26X2R1_LAUNCHXL_ECJPAKEName; + +/*! + * @def CC26X2R1_LAUNCHXL_AESCCMName + * @brief Enum of AESCCM names + */ +typedef enum CC26X2R1_LAUNCHXL_AESCCMName { + CC26X2R1_LAUNCHXL_AESCCM0 = 0, + + CC26X2R1_LAUNCHXL_AESCCMCOUNT +} CC26X2R1_LAUNCHXL_AESCCMName; + +/*! + * @def CC26X2R1_LAUNCHXL_AESECBName + * @brief Enum of AESECB names + */ +typedef enum CC26X2R1_LAUNCHXL_AESECBName { + CC26X2R1_LAUNCHXL_AESECB0 = 0, + + CC26X2R1_LAUNCHXL_AESECBCOUNT +} CC26X2R1_LAUNCHXL_AESECBName; + +/*! + * @def CC26X2R1_LAUNCHXL_SHA2Name + * @brief Enum of SHA2 names + */ +typedef enum CC26X2R1_LAUNCHXL_SHA2Name { + CC26X2R1_LAUNCHXL_SHA20 = 0, + + CC26X2R1_LAUNCHXL_SHA2COUNT +} CC26X2R1_LAUNCHXL_SHA2Name; + +/*! + * @def CC26X2R1_LAUNCHXL_GPIOName + * @brief Enum of GPIO names + */ +typedef enum CC26X2R1_LAUNCHXL_GPIOName { + CC26X2R1_LAUNCHXL_GPIO_S1 = 0, + CC26X2R1_LAUNCHXL_GPIO_S2, + CC26X2R1_LAUNCHXL_SPI_MASTER_READY, + CC26X2R1_LAUNCHXL_SPI_SLAVE_READY, + CC26X2R1_LAUNCHXL_GPIO_LED_GREEN, + CC26X2R1_LAUNCHXL_GPIO_LED_RED, + CC26X2R1_LAUNCHXL_GPIO_SPI_FLASH_CS, + CC26X2R1_LAUNCHXL_SDSPI_CS, + CC26X2R1_LAUNCHXL_GPIOCOUNT +} CC26X2R1_LAUNCHXL_GPIOName; + +/*! + * @def CC26X2R1_LAUNCHXL_GPTimerName + * @brief Enum of GPTimer parts + */ +typedef enum CC26X2R1_LAUNCHXL_GPTimerName { + CC26X2R1_LAUNCHXL_GPTIMER0A = 0, + CC26X2R1_LAUNCHXL_GPTIMER0B, + CC26X2R1_LAUNCHXL_GPTIMER1A, + CC26X2R1_LAUNCHXL_GPTIMER1B, + CC26X2R1_LAUNCHXL_GPTIMER2A, + CC26X2R1_LAUNCHXL_GPTIMER2B, + CC26X2R1_LAUNCHXL_GPTIMER3A, + CC26X2R1_LAUNCHXL_GPTIMER3B, + + CC26X2R1_LAUNCHXL_GPTIMERPARTSCOUNT +} CC26X2R1_LAUNCHXL_GPTimerName; + +/*! + * @def CC26X2R1_LAUNCHXL_GPTimers + * @brief Enum of GPTimers + */ +typedef enum CC26X2R1_LAUNCHXL_GPTimers { + CC26X2R1_LAUNCHXL_GPTIMER0 = 0, + CC26X2R1_LAUNCHXL_GPTIMER1, + CC26X2R1_LAUNCHXL_GPTIMER2, + CC26X2R1_LAUNCHXL_GPTIMER3, + + CC26X2R1_LAUNCHXL_GPTIMERCOUNT +} CC26X2R1_LAUNCHXL_GPTimers; + +/*! + * @def CC26X2R1_LAUNCHXL_I2CName + * @brief Enum of I2C names + */ +typedef enum CC26X2R1_LAUNCHXL_I2CName { +#if TI_I2C_CONF_I2C0_ENABLE + CC26X2R1_LAUNCHXL_I2C0 = 0, +#endif + + CC26X2R1_LAUNCHXL_I2CCOUNT +} CC26X2R1_LAUNCHXL_I2CName; + +/*! + * @def CC26X2R1_LAUNCHXL_NVSName + * @brief Enum of NVS names + */ +typedef enum CC26X2R1_LAUNCHXL_NVSName { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + CC26X2R1_LAUNCHXL_NVSCC26XX0 = 0, +#endif +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + CC26X2R1_LAUNCHXL_NVSSPI25X0, +#endif + + CC26X2R1_LAUNCHXL_NVSCOUNT +} CC26X2R1_LAUNCHXL_NVSName; + +/*! + * @def CC26X2R1_LAUNCHXL_PWMName + * @brief Enum of PWM outputs + */ +typedef enum CC26X2R1_LAUNCHXL_PWMName { + CC26X2R1_LAUNCHXL_PWM0 = 0, + CC26X2R1_LAUNCHXL_PWM1, + CC26X2R1_LAUNCHXL_PWM2, + CC26X2R1_LAUNCHXL_PWM3, + CC26X2R1_LAUNCHXL_PWM4, + CC26X2R1_LAUNCHXL_PWM5, + CC26X2R1_LAUNCHXL_PWM6, + CC26X2R1_LAUNCHXL_PWM7, + + CC26X2R1_LAUNCHXL_PWMCOUNT +} CC26X2R1_LAUNCHXL_PWMName; + +/*! + * @def CC26X2R1_LAUNCHXL_SDName + * @brief Enum of SD names + */ +typedef enum CC26X2R1_LAUNCHXL_SDName { + CC26X2R1_LAUNCHXL_SDSPI0 = 0, + + CC26X2R1_LAUNCHXL_SDCOUNT +} CC26X2R1_LAUNCHXL_SDName; + +/*! + * @def CC26X2R1_LAUNCHXL_SPIName + * @brief Enum of SPI names + */ +typedef enum CC26X2R1_LAUNCHXL_SPIName { +#if TI_SPI_CONF_SPI0_ENABLE + CC26X2R1_LAUNCHXL_SPI0 = 0, +#endif +#if TI_SPI_CONF_SPI1_ENABLE + CC26X2R1_LAUNCHXL_SPI1, +#endif + + CC26X2R1_LAUNCHXL_SPICOUNT +} CC26X2R1_LAUNCHXL_SPIName; + +/*! + * @def CC26X2R1_LAUNCHXL_TRNGName + * @brief Enum of TRNGs + */ +typedef enum CC26X2R1_LAUNCHXL_TRNGName { + CC26X2R1_LAUNCHXL_TRNG0 = 0, + + CC26X2R1_LAUNCHXL_TRNGCOUNT +} CC26X2R1_LAUNCHXL_TRNGName; + +/*! + * @def CC26X2R1_LAUNCHXL_UARTName + * @brief Enum of UARTs + */ +typedef enum CC26X2R1_LAUNCHXL_UARTName { +#if TI_UART_CONF_UART0_ENABLE + CC26X2R1_LAUNCHXL_UART0 = 0, +#endif +#if TI_UART_CONF_UART1_ENABLE + CC26X2R1_LAUNCHXL_UART1, +#endif + + CC26X2R1_LAUNCHXL_UARTCOUNT +} CC26X2R1_LAUNCHXL_UARTName; + +/*! + * @def CC26X2R1_LAUNCHXL_UDMAName + * @brief Enum of DMA buffers + */ +typedef enum CC26X2R1_LAUNCHXL_UDMAName { + CC26X2R1_LAUNCHXL_UDMA0 = 0, + + CC26X2R1_LAUNCHXL_UDMACOUNT +} CC26X2R1_LAUNCHXL_UDMAName; + +/*! + * @def CC26X2R1_LAUNCHXL_WatchdogName + * @brief Enum of Watchdogs + */ +typedef enum CC26X2R1_LAUNCHXL_WatchdogName { + CC26X2R1_LAUNCHXL_WATCHDOG0 = 0, + + CC26X2R1_LAUNCHXL_WATCHDOGCOUNT +} CC26X2R1_LAUNCHXL_WatchdogName; + +#ifdef __cplusplus +} +#endif + +#endif /* __CC26X2R1_LAUNCHXL_BOARD_H__ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/CC26X2R1_LAUNCHXL_fxns.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/CC26X2R1_LAUNCHXL_fxns.c new file mode 100644 index 000000000..606339f2d --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/CC26X2R1_LAUNCHXL_fxns.c @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +/* + * =================== CC26X2R1_LAUNCHXL_fxns.c ============================ + * This file contains the board-specific initialization functions. + */ + +#include +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/cpu.h) + +#include + +#include "Board.h" + +/* + * ======== CC26X2R1_LAUNCHXL_sendExtFlashByte ======== + */ +void CC26X2R1_LAUNCHXL_sendExtFlashByte(PIN_Handle pinHandle, uint8_t byte) +{ + uint8_t i; + + /* SPI Flash CS */ + PIN_setOutputValue(pinHandle, IOID_20, 0); + + for (i = 0; i < 8; i++) { + PIN_setOutputValue(pinHandle, IOID_10, 0); /* SPI Flash CLK */ + + /* SPI Flash MOSI */ + PIN_setOutputValue(pinHandle, IOID_9, (byte >> (7 - i)) & 0x01); + PIN_setOutputValue(pinHandle, IOID_10, 1); /* SPI Flash CLK */ + + /* + * Waste a few cycles to keep the CLK high for at + * least 45% of the period. + * 3 cycles per loop: 8 loops @ 48 Mhz = 0.5 us. + */ + CPUdelay(8); + } + + PIN_setOutputValue(pinHandle, IOID_10, 0); /* CLK */ + PIN_setOutputValue(pinHandle, IOID_20, 1); /* CS */ + + /* + * Keep CS high at least 40 us + * 3 cycles per loop: 700 loops @ 48 Mhz ~= 44 us + */ + CPUdelay(700); +} + +/* + * ======== CC26X2R1_LAUNCHXL_wakeUpExtFlash ======== + */ +void CC26X2R1_LAUNCHXL_wakeUpExtFlash(void) +{ + PIN_Config extFlashPinTable[] = { + /* SPI Flash CS */ + IOID_20 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + PIN_TERMINATE + }; + PIN_State extFlashPinState; + PIN_Handle extFlashPinHandle = PIN_open(&extFlashPinState, extFlashPinTable); + + /* + * To wake up we need to toggle the chip select at + * least 20 ns and ten wait at least 35 us. + */ + + /* Toggle chip select for ~20ns to wake ext. flash */ + PIN_setOutputValue(extFlashPinHandle, IOID_20, 0); + /* 3 cycles per loop: 1 loop @ 48 Mhz ~= 62 ns */ + CPUdelay(1); + PIN_setOutputValue(extFlashPinHandle, IOID_20, 1); + /* 3 cycles per loop: 560 loops @ 48 Mhz ~= 35 us */ + CPUdelay(560); + + PIN_close(extFlashPinHandle); +} + +/* + * ======== CC26X2R1_LAUNCHXL_shutDownExtFlash ======== + */ +void CC26X2R1_LAUNCHXL_shutDownExtFlash(void) +{ + /* + * To be sure we are putting the flash into sleep and not waking it, + * we first have to make a wake up call + */ + CC26X2R1_LAUNCHXL_wakeUpExtFlash(); + + PIN_Config extFlashPinTable[] = { + /* SPI Flash CS*/ + IOID_20 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash CLK */ + IOID_10 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash MOSI */ + IOID_9 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash MISO */ + IOID_8 | PIN_INPUT_EN | PIN_PULLDOWN, + PIN_TERMINATE + }; + PIN_State extFlashPinState; + PIN_Handle extFlashPinHandle = PIN_open(&extFlashPinState, extFlashPinTable); + + uint8_t extFlashShutdown = 0xB9; + + CC26X2R1_LAUNCHXL_sendExtFlashByte(extFlashPinHandle, extFlashShutdown); + + PIN_close(extFlashPinHandle); +} + +/* + * ======== Board_initHook ======== + * Called by Board_init() to perform board-specific initialization. + */ +void Board_initHook() +{ + CC26X2R1_LAUNCHXL_shutDownExtFlash(); +} diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/Makefile.cc26x2r1 b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/Makefile.cc26x2r1 new file mode 100644 index 000000000..803b592c0 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/Makefile.cc26x2r1 @@ -0,0 +1,21 @@ +################################################################################ +# SimpleLink Device makefile + +SUBFAMILY = cc13x2-cc26x2 +DEVICE_FAMILY = CC26X2 +DEVICE_LINE = CC26XX +DEVICE = CC2652R + +BOARD_SOURCEFILES += CC26X2R1_LAUNCHXL.c CC26X2R1_LAUNCHXL_fxns.c + +SUPPORTS_PROP_MODE = 0 +SUPPORTS_IEEE_MODE = 1 +SUPPORTS_BLE_BEACON = 1 + +SUPPORTS_HIGH_PA = 0 + +### Signal that we can be programmed with cc2538-bsl +BOARD_SUPPORTS_BSL = 0 + +# Include the common board makefile +include $(FAMILY_PATH)/launchpad/Makefile.launchpad diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/leds-arch.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/leds-arch.c new file mode 100644 index 000000000..85065e104 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/leds-arch.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup launchpad-peripherals + * @{ + * + * \file + * LED HAL definitions for the LaunchPad LEDs. Common across all + * CC13xx/CC26xx LaunchPad LEDs. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/leds.h" +/*---------------------------------------------------------------------------*/ +#include +/*---------------------------------------------------------------------------*/ +#include +/*---------------------------------------------------------------------------*/ +const leds_t leds_arch_leds[] = { + /* Red LED, AKA LED0 */ + { .pin = Board_PIN_LED0, .negative_logic = false }, + /* Green LED, AKA LED1 */ + { .pin = Board_PIN_LED1, .negative_logic = false }, +}; +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/platform.c b/arch/platform/simplelink/cc13xx-cc26xx/platform.c new file mode 100644 index 000000000..c78fe1946 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/platform.c @@ -0,0 +1,275 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-platform + * @{ + * + * \file + * Setup the SimpleLink CC13xx/CC26xx ecosystem with the + * Contiki environment. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "contiki-net.h" +#include "sys/clock.h" +#include "sys/rtimer.h" +#include "sys/node-id.h" +#include "sys/platform.h" +#include "dev/button-hal.h" +#include "dev/gpio-hal.h" +#include "dev/serial-line.h" +#include "dev/leds.h" +#include "net/mac/framer/frame802154.h" +#include "lib/random.h" +#include "lib/sensors.h" +/*---------------------------------------------------------------------------*/ +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/driverlib_release.h) +#include DeviceFamily_constructPath(driverlib/chipinfo.h) +#include DeviceFamily_constructPath(driverlib/vims.h) + +#include +#include +#include +#include +#include +#include +#include +#include +#include +/*---------------------------------------------------------------------------*/ +#include "board-peripherals.h" +#include "uart0-arch.h" +#include "trng-arch.h" +/*---------------------------------------------------------------------------*/ +#include "rf/rf.h" +#include "rf/ble-beacond.h" +#include "rf/ieee-addr.h" +/*---------------------------------------------------------------------------*/ +#include +#include +/*---------------------------------------------------------------------------*/ +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "CC13xx/CC26xx" +#define LOG_LEVEL LOG_LEVEL_MAIN +/*---------------------------------------------------------------------------*/ +/* + * Board-specific initialization function. This function is defined in + * the _fxns.c file. + */ +extern void Board_initHook(void); +/*---------------------------------------------------------------------------*/ +/* + * \brief Fade a specified LED. + */ +static void +fade(PIN_Id pin) +{ + volatile uint32_t i; + uint32_t k; + uint32_t j; + uint32_t pivot = 800; + uint32_t pivot_half = pivot / 2; + + for(k = 0; k < pivot; ++k) { + j = (k > pivot_half) ? pivot - k : k; + + PINCC26XX_setOutputValue(pin, 1); + for(i = 0; i < j; ++i) { + __asm__ __volatile__ ("nop"); + } + PINCC26XX_setOutputValue(pin, 0); + for(i = 0; i < pivot_half - j; ++i) { + __asm__ __volatile__ ("nop"); + } + } +} +/*---------------------------------------------------------------------------*/ +/* + * \brief Configure RF params for the radio driver. + */ +static void +set_rf_params(void) +{ + uint8_t ext_addr[8]; + uint16_t short_addr; + + memset(ext_addr, 0x0, sizeof(ext_addr)); + + ieee_addr_cpy_to(ext_addr, sizeof(ext_addr)); + + /* Short address is the last two bytes of the MAC address */ + short_addr = (((uint16_t)ext_addr[7] << 0) | + ((uint16_t)ext_addr[6] << 8)); + + NETSTACK_RADIO.set_value(RADIO_PARAM_PAN_ID, IEEE802154_PANID); + NETSTACK_RADIO.set_value(RADIO_PARAM_16BIT_ADDR, short_addr); + NETSTACK_RADIO.set_object(RADIO_PARAM_64BIT_ADDR, ext_addr, sizeof(ext_addr)); +} +/*---------------------------------------------------------------------------*/ +void +platform_init_stage_one(void) +{ + DRIVERLIB_ASSERT_CURR_RELEASE(); + + /* Enable flash cache */ + VIMSModeSet(VIMS_BASE, VIMS_MODE_ENABLED); + /* Configure round robin arbitration and prefetching */ + VIMSConfigure(VIMS_BASE, true, true); + + Power_init(); + + /* BoardGpioInitTable declared in Board.h */ + if(PIN_init(BoardGpioInitTable) != PIN_SUCCESS) { + /* + * Something is seriously wrong if PIN initialization of the Board GPIO + * table fails. + */ + for(;;) { /* hang */ } + } + + /* Perform board-specific initialization */ + Board_initHook(); + + /* Contiki drivers init */ + gpio_hal_init(); + leds_init(); + + fade(Board_PIN_LED0); + + /* TI Drivers init */ +#if TI_UART_CONF_ENABLE + UART_init(); +#endif +#if TI_I2C_CONF_ENABLE + I2C_init(); +#endif +#if TI_SPI_CONF_ENABLE + SPI_init(); +#endif +#if TI_NVS_CONF_ENABLE + NVS_init(); +#endif + + TRNG_init(); + + fade(Board_PIN_LED1); + + /* NoRTOS must be called last */ + NoRTOS_start(); +} +/*---------------------------------------------------------------------------*/ +void +platform_init_stage_two(void) +{ + serial_line_init(); + +#if TI_UART_CONF_UART0_ENABLE + uart0_init(); +#endif + +#if BUILD_WITH_SHELL + uart0_set_callback(serial_line_input_byte); +#endif + + /* Use TRNG to seed PRNG. If TRNG fails, use a hard-coded seed. */ + unsigned short seed = 0; + if(!trng_rand((uint8_t *)&seed, sizeof(seed), TRNG_WAIT_FOREVER)) { + /* Default to some hard-coded seed. */ + seed = 0x1234; + } + random_init(seed); + + /* Populate linkaddr_node_addr */ + ieee_addr_cpy_to(linkaddr_node_addr.u8, LINKADDR_SIZE); + + button_hal_init(); + + fade(Board_PIN_LED0); +} +/*---------------------------------------------------------------------------*/ +void +platform_init_stage_three(void) +{ +#if RF_CONF_BLE_BEACON_ENABLE + rf_ble_beacond_init(); +#endif + + radio_value_t chan = 0; + radio_value_t pan = 0; + + set_rf_params(); + + LOG_DBG("With DriverLib v%u.%u\n", DRIVERLIB_RELEASE_GROUP, + DRIVERLIB_RELEASE_BUILD); + LOG_DBG("IEEE 802.15.4: %s, Sub-1 GHz: %s, BLE: %s\n", + ChipInfo_SupportsIEEE_802_15_4() ? "Yes" : "No", + ChipInfo_SupportsPROPRIETARY() ? "Yes" : "No", + ChipInfo_SupportsBLE() ? "Yes" : "No"); + +#if (RF_MODE == RF_MODE_SUB_1_GHZ) + LOG_INFO("Operating frequency on Sub-1 GHz\n"); +#elif (RF_MODE == RF_MODE_2_4_GHZ) + LOG_INFO("Operating frequency on 2.4 GHz\n"); +#endif + + NETSTACK_RADIO.get_value(RADIO_PARAM_CHANNEL, &chan); + LOG_INFO("RF: Channel %d", chan); + + if(NETSTACK_RADIO.get_value(RADIO_PARAM_PAN_ID, &pan) == RADIO_RESULT_OK) { + LOG_INFO(", PANID 0x%04X", pan); + } + LOG_INFO("\n"); + + LOG_INFO("Node ID: %d\n", node_id); + +#if BOARD_CONF_SENSORS_ENABLE + process_start(&sensors_process, NULL); +#endif + + fade(Board_PIN_LED1); +} +/*---------------------------------------------------------------------------*/ +void +platform_idle(void) +{ + /* Drop to some low power mode */ + Power_idleFunc(); +} +/*---------------------------------------------------------------------------*/ +/** + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/Makefile.sensortag b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/Makefile.sensortag new file mode 100644 index 000000000..cdb55c48f --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/Makefile.sensortag @@ -0,0 +1,13 @@ +################################################################################ +# SimpleLink LaunchPad makefile + +BOARD_TYPE = BOARD_SENSORTAG + +# leds-arch.c etc. +BOARD_SOURCEFILES += sensortag-sensors.c +BOARD_SOURCEFILES += button-sensor-arch.c +BOARD_SOURCEFILES += bmp-280-sensor.c hdc-1000-sensor.c +BOARD_SOURCEFILES += mpu-9250-sensor.c opt-3001-sensor.c +BOARD_SOURCEFILES += tmp-007-sensor.c buzzer.c + +TARGET_FAMILY_DIRS += sensortag \ No newline at end of file diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/bmp-280-sensor.c b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/bmp-280-sensor.c new file mode 100644 index 000000000..bf47c1571 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/bmp-280-sensor.c @@ -0,0 +1,427 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup sensortag-bmp-sensor + * @{ + * + * \file + * Driver for the Sensortag BMP280 Altimeter / Pressure Sensor + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "lib/sensors.h" +#include "sys/ctimer.h" +/*---------------------------------------------------------------------------*/ +#include "board-conf.h" +#include "bmp-280-sensor.h" +/*---------------------------------------------------------------------------*/ +#include + +#include +/*---------------------------------------------------------------------------*/ +#include +#include +#include +/*---------------------------------------------------------------------------*/ +#define DEBUG 0 +#if DEBUG +#define PRINTF(...) printf(__VA_ARGS__) +#else +#define PRINTF(...) +#endif +/*---------------------------------------------------------------------------*/ +/* + * Disable the entire file if sensors are disabled, as it could potentially + * create compile errors with missing defines from either the Board file or + * configuration defines. + */ +#if BOARD_SENSORS_ENABLE +/*---------------------------------------------------------------------------*/ +#ifndef Board_BMP280_ADDR +#error "Board file doesn't define I2C address Board_BMP280_ADDR" +#endif +/* Sensor I2C address */ +#define BMP280_I2C_ADDRESS Board_BMP280_ADDR +/*---------------------------------------------------------------------------*/ +/* Registers */ +#define ADDR_CALIB 0x88 +#define ADDR_PROD_ID 0xD0 +#define ADDR_RESET 0xE0 +#define ADDR_STATUS 0xF3 +#define ADDR_CTRL_MEAS 0xF4 +#define ADDR_CONFIG 0xF5 +#define ADDR_PRESS_MSB 0xF7 +#define ADDR_PRESS_LSB 0xF8 +#define ADDR_PRESS_XLSB 0xF9 +#define ADDR_TEMP_MSB 0xFA +#define ADDR_TEMP_LSB 0xFB +#define ADDR_TEMP_XLSB 0xFC +/*---------------------------------------------------------------------------*/ +/* Reset values */ +#define VAL_PROD_ID 0x58 +#define VAL_RESET 0x00 +#define VAL_STATUS 0x00 +#define VAL_CTRL_MEAS 0x00 +#define VAL_CONFIG 0x00 +#define VAL_PRESS_MSB 0x80 +#define VAL_PRESS_LSB 0x00 +#define VAL_TEMP_MSB 0x80 +#define VAL_TEMP_LSB 0x00 +/*---------------------------------------------------------------------------*/ +/* Test values */ +#define VAL_RESET_EXECUTE 0xB6 +#define VAL_CTRL_MEAS_TEST 0x55 +/*---------------------------------------------------------------------------*/ +/* Misc. */ +#define MEAS_DATA_SIZE 6 +#define CALIB_DATA_SIZE 24 +/*---------------------------------------------------------------------------*/ +#define RES_OFF 0 +#define RES_ULTRA_LOW_POWER 1 +#define RES_LOW_POWER 2 +#define RES_STANDARD 3 +#define RES_HIGH 5 +#define RES_ULTRA_HIGH 6 +/*---------------------------------------------------------------------------*/ +/* Bit fields in CTRL_MEAS register */ +#define PM_OFF 0 +#define PM_FORCED 1 +#define PM_NORMAL 3 +/*---------------------------------------------------------------------------*/ +#define OSRST(v) ((v) << 5) +#define OSRSP(v) ((v) << 2) +/*---------------------------------------------------------------------------*/ +typedef struct { + uint16_t dig_t1; + int16_t dig_t2; + int16_t dig_t3; + uint16_t dig_p1; + int16_t dig_p2; + int16_t dig_p3; + int16_t dig_p4; + int16_t dig_p5; + int16_t dig_p6; + int16_t dig_p7; + int16_t dig_p8; + int16_t dig_p9; +} BMP_280_Calibration; +/*---------------------------------------------------------------------------*/ +static BMP_280_Calibration calib_data; +/*---------------------------------------------------------------------------*/ +static I2C_Handle i2c_handle; +/*---------------------------------------------------------------------------*/ +typedef enum { + SENSOR_STATUS_DISABLED, + SENSOR_STATUS_INITIALISED, + SENSOR_STATUS_NOT_READY, + SENSOR_STATUS_READY +} SENSOR_STATUS; + +static volatile SENSOR_STATUS sensor_status = SENSOR_STATUS_DISABLED; +/*---------------------------------------------------------------------------*/ +/* Wait SENSOR_STARTUP_DELAY clock ticks for the sensor to be ready - ~80ms */ +#define SENSOR_STARTUP_DELAY 3 + +static struct ctimer startup_timer; +/*---------------------------------------------------------------------------*/ +static void +notify_ready(void *unused) +{ + (void)unused; + + sensor_status = SENSOR_STATUS_READY; + sensors_changed(&bmp_280_sensor); +} +/*---------------------------------------------------------------------------*/ +static bool +i2c_write_read(void *writeBuf, size_t writeCount, void *readBuf, size_t readCount) +{ + I2C_Transaction i2cTransaction = { + .writeBuf = writeBuf, + .writeCount = writeCount, + .readBuf = readBuf, + .readCount = readCount, + .slaveAddress = BMP280_I2C_ADDRESS, + }; + + return I2C_transfer(i2c_handle, &i2cTransaction); +} +#define i2c_write(writeBuf, writeCount) i2c_write_read(writeBuf, writeCount, NULL, 0) +#define i2c_read(readBuf, readCount) i2c_write_read(NULL, 0, readBuf, readCount) +/*---------------------------------------------------------------------------*/ +/** + * \brief Initalise the sensor. + * \return Boolean Value descibing whether initialization were + * successful or not. + * \retval true Successful initialization + * \retval false Error during initialization + */ +static bool +init(void) +{ + if(i2c_handle) { + return true; + } + + I2C_Params i2cParams; + I2C_Params_init(&i2cParams); + + i2cParams.transferMode = I2C_MODE_BLOCKING; + i2cParams.bitRate = I2C_400kHz; + + i2c_handle = I2C_open(Board_I2C0, &i2cParams); + if(i2c_handle == NULL) { + return false; + } + + uint8_t reset_data[] = { ADDR_RESET, VAL_RESET_EXECUTE }; + + uint8_t calib_reg = ADDR_CALIB; + /* Read and store calibration data */ + return i2c_write_read(&calib_reg, sizeof(calib_reg), &calib_data, sizeof(calib_data)) + /* then reset the sensor */ + && i2c_write(reset_data, sizeof(reset_data)); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Enable/disable measurements. + * \param enable Enable if true; else, disable. + * \return Boolean Value descibing whether initialization were + * successful or not. + * \retval true Successful initialization + * \retval false Error during initialization + */ +static bool +enable_sensor(bool enable) +{ + uint8_t val = (enable) + ? PM_FORCED | OSRSP(1) | OSRST(1) + : PM_OFF; + + uint8_t ctrl_meas_data[] = { ADDR_CTRL_MEAS, val }; + return i2c_write(&ctrl_meas_data, sizeof(ctrl_meas_data)); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Read temperature and pressure data. + * \param data Pointer to a buffer where temperature and pressure will be + * written. + * \param count Number of byes to read. + * \return Boolean Value descibing whether initialization were + * successful or not. + * \retval true Successful initialization + * \retval false Error during initialization + */ +static bool +read_data(uint8_t *data, size_t count) +{ + uint8_t press_msb_reg = ADDR_PRESS_MSB; + return i2c_write_read(&press_msb_reg, sizeof(press_msb_reg), data, count); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Convert raw data to values in degrees C (temp) and Pascal + * (pressure). + * \param data Pointer to a buffer that holds raw sensor data. + * \param temp Pointer to a variable where the converted temperature will + * be written. + * \param press Pointer to a variable where the converted pressure will be + * written. + */ +static void +convert(uint8_t *data, int32_t *temp, uint32_t *press) +{ + BMP_280_Calibration *p = &calib_data; + + /* Pressure */ + const int32_t upress = (int32_t)( + (((uint32_t)data[0]) << 12) | + (((uint32_t)data[1]) << 4) | + (((uint32_t)data[2]) >> 4) + ); + /* Temperature */ + const int32_t utemp = (int32_t)( + (((uint32_t)data[3]) << 12) | + (((uint32_t)data[4]) << 4) | + (((uint32_t)data[5]) >> 4) + ); + + /* Compensate temperature */ + int32_t v_x1_u32r = (((utemp >> 3) - ((int32_t)p->dig_t1 << 1)) * (int32_t)p->dig_t2) >> 11; + int32_t v_x2_u32r = (((((utemp >> 4) - (int32_t)p->dig_t1) * ((utemp >> 4) - (int32_t)p->dig_t1)) >> 12) * (int32_t)p->dig_t3) >> 14; + + const uint32_t t_fine = v_x1_u32r + v_x2_u32r; + const int32_t temperature = (t_fine * 5 + 128) >> 8; + *temp = temperature; + + /* Compensate pressure */ + v_x1_u32r = ((int32_t)t_fine >> 1) - (int32_t)64000; + v_x2_u32r = (((v_x1_u32r >> 2) * (v_x1_u32r >> 2)) >> 11) * (int32_t)p->dig_p6; + v_x2_u32r = ((v_x1_u32r * (int32_t)p->dig_p5) << 1) + v_x2_u32r; + v_x2_u32r = (v_x2_u32r >> 2) + ((int32_t)p->dig_p4 << 16); + v_x1_u32r = ((((((v_x1_u32r >> 2) * (v_x1_u32r >> 2)) >> 13) * p->dig_p3) >> 3) + (((int32_t)p->dig_p2 * v_x1_u32r) >> 1)) >> 18; + v_x1_u32r = ((32768 + v_x1_u32r) * (int32_t)p->dig_p1) >> 15; + + if(v_x1_u32r == 0) { + /* Avoid exception caused by division by zero */ + *press = 0; + return; + } + + uint32_t pressure = (((uint32_t)((int32_t)1048576 - upress)) - (v_x2_u32r >> 12)) * 3125; + if((int32_t)pressure < 0) { + pressure = (pressure << 1) / (uint32_t)v_x1_u32r; + } else { + pressure = (pressure / (uint32_t)v_x1_u32r) * 2; + } + + v_x1_u32r = (((int32_t)(((pressure >> 3) * (pressure >> 3)) >> 13)) * (int32_t)p->dig_p9) >> 12; + v_x2_u32r = ((int32_t)(pressure >> 2) * (int32_t)p->dig_p8) >> 13; + pressure = (uint32_t)(((v_x1_u32r + v_x2_u32r + p->dig_p7) >> 4) + (int32_t)pressure); + + *press = pressure; +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Returns a reading from the sensor. + * \param type Parameter of type BMP_280_SENSOR_TYPE, choosing between either + * measuring temperature or pressure. + * \return Sensor data of either Temperature (centi degrees C) or + * Pressure (Pascal). + */ +static int +value(int type) +{ + int32_t temp = 0; + uint32_t pres = 0; + + if(sensor_status != SENSOR_STATUS_READY) { + PRINTF("Sensor disabled or starting up (%d)\n", sensor_status); + return BMP_280_READING_ERROR; + } + + /* A buffer for the raw reading from the sensor */ + uint8_t sensor_value[MEAS_DATA_SIZE]; + + switch(type) { + case BMP_280_SENSOR_TYPE_TEMP: + case BMP_280_SENSOR_TYPE_PRESS: + memset(sensor_value, 0, MEAS_DATA_SIZE); + if(!read_data(sensor_value, MEAS_DATA_SIZE)) { + return BMP_280_READING_ERROR; + } + + PRINTF("val: %02x%02x%02x %02x%02x%02x\n", + sensor_value[0], sensor_value[1], sensor_value[2], + sensor_value[3], sensor_value[4], sensor_value[5]); + + convert(sensor_value, &temp, &pres); + + if(type == BMP_280_SENSOR_TYPE_TEMP) { + return (int)temp; + } else if(type == BMP_280_SENSOR_TYPE_PRESS) { + return (int)pres; + } else { + return 0; + } + + default: + PRINTF("Invalid BMP 208 Sensor Type\n"); + return BMP_280_READING_ERROR; + } +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Configuration function for the BMP280 sensor. + * \param type Activate, enable or disable the sensor. See below + * \param enable Disable sensor if 0; else, enable sensor otherwise. + * When type == SENSORS_HW_INIT we turn on the hardware. + * When type == SENSORS_ACTIVE and enable==1 we enable the sensor. + * When type == SENSORS_ACTIVE and enable==0 we disable the sensor. + */ +static int +configure(int type, int enable) +{ + switch(type) { + case SENSORS_HW_INIT: + if(init()) { + enable_sensor(false); + sensor_status = SENSOR_STATUS_INITIALISED; + } else { + sensor_status = SENSOR_STATUS_DISABLED; + } + break; + + case SENSORS_ACTIVE: + /* Must be initialised first */ + if(sensor_status == SENSOR_STATUS_DISABLED) { + break; + } + if(enable) { + enable_sensor(true); + ctimer_set(&startup_timer, SENSOR_STARTUP_DELAY, notify_ready, NULL); + sensor_status = SENSOR_STATUS_NOT_READY; + } else { + ctimer_stop(&startup_timer); + enable_sensor(false); + sensor_status = SENSOR_STATUS_INITIALISED; + } + break; + + default: + break; + } + return sensor_status; +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Returns the status of the sensor. + * \param type SENSORS_ACTIVE or SENSORS_READY. + * \return Current status of the sensor. + */ +static int +status(int type) +{ + switch(type) { + case SENSORS_ACTIVE: + case SENSORS_READY: + return sensor_status; + default: + return SENSOR_STATUS_DISABLED; + } +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(bmp_280_sensor, "BMP280", value, configure, status); +/*---------------------------------------------------------------------------*/ +#endif /* BOARD_SENSORS_ENABLE */ +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/bmp-280-sensor.h b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/bmp-280-sensor.h new file mode 100644 index 000000000..02b2034b1 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/bmp-280-sensor.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup sensortag-peripherals + * @{ + * + * \defgroup sensortag-bmp-sensor SensorTag Pressure Sensor + * + * Due to the time required for the sensor to startup, this driver is meant to + * be used in an asynchronous fashion. The caller must first activate the + * sensor by calling SENSORS_ACTIVATE(). This will trigger the sensor's startup + * sequence, but the call will not wait for it to complete so that the CPU can + * perform other tasks or drop to a low power mode. + * + * Once the sensor is stable, the driver will generate a sensors_changed event. + * + * We take readings in "Forced" mode. In this mode, the BMP will take a single + * measurement and it will then automatically go to sleep. + * + * SENSORS_ACTIVATE must be called again to trigger a new reading cycle + * @{ + * + * \file + * Header file for the Sensortag BMP280 Altimeter / Pressure Sensor + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#ifndef BMP_280_SENSOR_H_ +#define BMP_280_SENSOR_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "lib/sensors.h" +/*---------------------------------------------------------------------------*/ +#include "board-conf.h" +/*---------------------------------------------------------------------------*/ +/* The BMP-280 driver uses the I2C0 peripheral to access the senssor */ +#if BOARD_SENSORS_ENABLE +#if (TI_I2C_CONF_ENABLE == 0) || (TI_I2C_CONF_I2C0_ENABLE == 0) +#error "The BMP280 requires the I2C driver (TI_I2C_CONF_ENABLE = 1)" +#endif +#endif +/*---------------------------------------------------------------------------*/ +typedef enum { + BMP_280_SENSOR_TYPE_TEMP, + BMP_280_SENSOR_TYPE_PRESS +} BMP_280_SENSOR_TYPE; +/*---------------------------------------------------------------------------*/ +#define BMP_280_READING_ERROR -1 +/*---------------------------------------------------------------------------*/ +extern const struct sensors_sensor bmp_280_sensor; +/*---------------------------------------------------------------------------*/ +#endif /* BMP_280_SENSOR_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/board-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/board-conf.h new file mode 100644 index 000000000..bb8689c98 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/board-conf.h @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-platform + * @{ + * + * \defgroup sensortag-peripherals Sensortag peripherals + * + * Defines related to configuring SensorTag peripherals. The two sensortags, + * CC1350STK and CC2650STK, are identical to a very large extent. + * Everything documented within this group applies to both sensortags. + * + * @{ + * + * \file + * Header file with definitions related to the sensors on the Sensortags + * \author + * Edvard Pettersen + * \note + * This file should not be included directly + */ +/*---------------------------------------------------------------------------*/ +#ifndef BOARD_CONF_H_ +#define BOARD_CONF_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki-conf.h" +/*---------------------------------------------------------------------------*/ +#include "leds-arch.h" +/*---------------------------------------------------------------------------*/ +/** + * \name LED configurations for the dev/leds.h API. The actual LED + * configuration of available LEDs are done in leds-arch.h. + * + * Those values are not meant to be modified by the user + * @{ + */ +#define PLATFORM_HAS_LEDS 1 +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name Button configurations for the dev/button-hal.h API. + * + * Those values are not meant to be modified by the user + * @{ + */ +#define PLATFORM_HAS_BUTTON 1 +#define PLATFORM_SUPPORTS_BUTTON_HAL 1 + +#define BUTTON_HAL_ID_KEY_LEFT 0 +#define BUTTON_HAL_ID_KEY_RIGHT 1 +#define BUTTON_HAL_ID_REED_RELAY 2 +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name SensorTag does have sensors. + * + * Those values are not meant to be modified by the user + * @{ + */ +#define BOARD_CONF_HAS_SENSORS 1 +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name Enable or disable the SensorTag sensors. + * + * Those values are not meant to be modified by the user + * @{ + */ +#define BOARD_SENSORS_ENABLE (!(BOARD_CONF_SENSORS_DISABLE)) +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name The external flash SPI CS pin, defined in Board.h. + * + * Those values are not meant to be modified by the user + * @{ + */ +#if TI_SPI_CONF_SPI0_ENABLE +#define EXT_FLASH_SPI_CONTROLLER Board_SPI0 + +#define EXT_FLASH_SPI_PIN_SCK Board_SPI0_SCK +#define EXT_FLASH_SPI_PIN_MOSI Board_SPI0_MOSI +#define EXT_FLASH_SPI_PIN_MISO Board_SPI0_MISO +#define EXT_FLASH_SPI_PIN_CS Board_SPI_FLASH_CS + +#define EXT_FLASH_DEVICE_ID 0x14 +#define EXT_FLASH_MID 0xC2 + +#define EXT_FLASH_PROGRAM_PAGE_SIZE 256 +#define EXT_FLASH_ERASE_SECTOR_SIZE 4096 +#endif /* TI_SPI_CONF_SPI0_ENABLE */ +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* BOARD_CONF_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/board-peripherals.h b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/board-peripherals.h new file mode 100644 index 000000000..7a4f8c19b --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/board-peripherals.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-platform + * @{ + * + * \defgroup sensortag-peripherals Sensortag peripherals + * + * Defines related to configuring SensorTag peripherals. The two sensortags, + * CC1350STK and CC2650STK, are identical to a very large extent. + * Everything documented within this group applies to both sensortags. + * + * @{ + * + * \file + * Header file with definitions related to the sensors on the Sensortags + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#ifndef BOARD_PERIPHERALS_H_ +#define BOARD_PERIPHERALS_H_ +/*---------------------------------------------------------------------------*/ +#include "board-conf.h" +/*---------------------------------------------------------------------------*/ +#include "bmp-280-sensor.h" +#include "tmp-007-sensor.h" +#include "opt-3001-sensor.h" +#include "hdc-1000-sensor.h" +#include "mpu-9250-sensor.h" +#include "buzzer.h" +/*---------------------------------------------------------------------------*/ +#endif /* BOARD_PERIPHERALS_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/button-sensor-arch.c b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/button-sensor-arch.c new file mode 100644 index 000000000..4b2ccba9b --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/button-sensor-arch.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup sensortag-peripherals + * @{ + * + * \file + * Button HAL definitions for the SensorTag buttons. Common across + * all CC13xx/CC26xx SensorTag boards. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/button-hal.h" +/*---------------------------------------------------------------------------*/ +#include +/*---------------------------------------------------------------------------*/ +/* Key left button, AKA BTN-1 */ +BUTTON_HAL_BUTTON( + key_left, /**< Name */ + "Key Left", /**< Description */ + Board_KEY_LEFT, /**< PIN */ + GPIO_HAL_PIN_CFG_PULL_UP | + GPIO_HAL_PIN_CFG_HYSTERESIS, /**< Pull configuration */ + BUTTON_HAL_ID_KEY_LEFT, /**< Unique ID */ + true); /**< Negative logic */ + +/* Key right button, AKA BTN-2 */ +BUTTON_HAL_BUTTON( + key_right, /**< Name */ + "Key Right", /**< Description */ + Board_KEY_RIGHT, /**< PIN */ + GPIO_HAL_PIN_CFG_PULL_UP | + GPIO_HAL_PIN_CFG_HYSTERESIS, /**< Pull configuration */ + BUTTON_HAL_ID_KEY_RIGHT, /**< Unique ID */ + true); /**< Negative logic */ + +/* Reed Relay button */ +BUTTON_HAL_BUTTON( + reed_relay, /**< Name */ + "Reed Relay", /**< Description */ + Board_RELAY, /**< PIN */ + GPIO_HAL_PIN_CFG_PULL_DOWN | + GPIO_HAL_PIN_CFG_HYSTERESIS, /**< Pull configuration */ + BUTTON_HAL_ID_REED_RELAY, /**< Unique ID */ + true); /**< Negative logic */ +/*---------------------------------------------------------------------------*/ +BUTTON_HAL_BUTTONS(&key_left, &key_right, &reed_relay); +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/buzzer.c b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/buzzer.c new file mode 100644 index 000000000..1815a370d --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/buzzer.c @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/*---------------------------------------------------------------------------*/ +/** + * \addtogroup sensortag-buzzer + * @{ + * + * \file + * Driver for the Sensortag Buzzer. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "buzzer.h" +/*---------------------------------------------------------------------------*/ +#include +#include +#include +#include +#include +#include +/*---------------------------------------------------------------------------*/ +#include +#include +#include +/*---------------------------------------------------------------------------*/ +/* Configure BUZZER pin */ +#ifndef Board_BUZZER +#error "Board file doesn't define pin Board_BUZZER" +#endif +#define BUZZER_PIN Board_BUZZER +/*---------------------------------------------------------------------------*/ +static const PIN_Config pin_table[] = { + BUZZER_PIN | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW, + PIN_TERMINATE +}; + +static PIN_State pin_state; +static PIN_Handle pin_handle; + +static GPTimerCC26XX_Handle gpt_handle; + +static bool has_init; +static volatile bool is_running; +/*---------------------------------------------------------------------------*/ +bool +buzzer_init() +{ + if(has_init) { + return true; + } + + GPTimerCC26XX_Params gpt_params; + GPTimerCC26XX_Params_init(&gpt_params); + + gpt_params.mode = GPT_CONFIG_16BIT; + gpt_params.mode = GPT_MODE_PERIODIC_UP; + gpt_params.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF; + + gpt_handle = GPTimerCC26XX_open(Board_GPTIMER0A, &gpt_params); + if(!gpt_handle) { + return false; + } + + is_running = false; + + has_init = true; + return true; +} +/*---------------------------------------------------------------------------*/ +bool +buzzer_running() +{ + return is_running; +} +/*---------------------------------------------------------------------------*/ +bool +buzzer_start(uint32_t freq) +{ + if(!has_init) { + return false; + } + + if(freq == 0) { + return false; + } + + if(is_running) { + return true; + } + + pin_handle = PIN_open(&pin_state, pin_table); + if(!pin_handle) { + return false; + } + + Power_setDependency(PowerCC26XX_XOSC_HF); + + PINCC26XX_setMux(pin_handle, BUZZER_PIN, GPT_PIN_0A); + + /* MCU runs at 48 MHz */ + GPTimerCC26XX_Value load_value = (48 * 1000 * 1000) / freq; + + GPTimerCC26XX_setLoadValue(gpt_handle, load_value); + GPTimerCC26XX_start(gpt_handle); + + is_running = true; + return true; +} +/*---------------------------------------------------------------------------*/ +void +buzzer_stop() +{ + if(!gpt_handle) { + return; + } + + if(!is_running) { + return; + } + + Power_releaseDependency(PowerCC26XX_XOSC_HF); + + GPTimerCC26XX_stop(gpt_handle); + + PIN_close(pin_handle); + pin_handle = NULL; + + is_running = false; +} +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/buzzer.h b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/buzzer.h new file mode 100644 index 000000000..3895be4b7 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/buzzer.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup sensortag-peripherals + * @{ + * + * \defgroup sensortag-buzzer SensorTag Buzzer + * @{ + * + * \file + * Header file for the Sensortag Buzzer. + * \author + * Edvard Pettersen . + */ +/*---------------------------------------------------------------------------*/ +#ifndef BUZZER_H_ +#define BUZZER_H_ +/*---------------------------------------------------------------------------*/ +#include +#include +/*---------------------------------------------------------------------------*/ +/** + * \brief Initialise the buzzer + */ +bool buzzer_init(void); + +/** + * \brief Start the buzzer. + * \param freq The buzzer frequency in Hz. + */ +bool buzzer_start(uint32_t freq); + +/** + * \brief Stop the buzzer. + */ +void buzzer_stop(void); + +/** + * \brief Retrieve the buzzer state. + * \return Running status of the buzzer. + * \retval 0 Buzzer is off + * \retval 1 Buzzer is on + */ +bool buzzer_running(void); +/*---------------------------------------------------------------------------*/ +#endif /* BUZZER_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/Board.h new file mode 100644 index 000000000..ecdb6d2af --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/Board.h @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2015-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 __BOARD_H +#define __BOARD_H + +#define Board_CC1350STK +#define BOARD_STRING "TI CC1350 SensorTag" + +#ifdef __cplusplus +extern "C" { +#endif + +#include "CC1350STK.h" + +#define Board_initGeneral() CC1350STK_initGeneral() +#define Board_shutDownExtFlash() CC1350STK_shutDownExtFlash() +#define Board_wakeUpExtFlash() CC1350STK_wakeUpExtFlash() + +/* These #defines allow us to reuse TI-RTOS across other device families */ + +#define Board_BUZZER CC1350STK_BUZZER +#define Board_BUZZER_ON CC1350STK_LED_ON +#define Board_BUZZER_OFF CC1350STK_LED_OFF + +#define Board_CRYPTO0 CC1350STK_CRYPTO0 + +#define Board_GPIO_BUTTON0 CC1350STK_GPIO_S1 +#define Board_GPIO_BUTTON1 CC1350STK_GPIO_S2 +#define Board_GPIO_LED0 CC1350STK_GPIO_LED0 +#define Board_GPIO_LED1 CC1350STK_GPIO_LED0 +#define Board_GPIO_LED_ON CC1350STK_GPIO_LED_ON +#define Board_GPIO_LED_OFF CC1350STK_GPIO_LED_OFF + +#define Board_GPTIMER0A CC1350STK_GPTIMER0A +#define Board_GPTIMER0B CC1350STK_GPTIMER0B +#define Board_GPTIMER1A CC1350STK_GPTIMER1A +#define Board_GPTIMER1B CC1350STK_GPTIMER1B +#define Board_GPTIMER2A CC1350STK_GPTIMER2A +#define Board_GPTIMER2B CC1350STK_GPTIMER2B +#define Board_GPTIMER3A CC1350STK_GPTIMER3A +#define Board_GPTIMER3B CC1350STK_GPTIMER3B + +#define Board_I2C0 CC1350STK_I2C0 +#define Board_I2C0_SDA1 CC1350STK_I2C0_SDA1 +#define Board_I2C0_SCL1 CC1350STK_I2C0_SCL1 +#define Board_I2C_TMP CC1350STK_I2C0 + +#define Board_KEY_LEFT CC1350STK_KEY_LEFT +#define Board_KEY_RIGHT CC1350STK_KEY_RIGHT +#define Board_RELAY CC1350STK_RELAY + +#define Board_MIC_POWER CC1350STK_MIC_POWER +#define Board_MIC_POWER_OM CC1350STK_MIC_POWER_ON +#define Board_MIC_POWER_OFF CC1350STK_MIC_POWER_OFF + +#define Board_MPU_INT CC1350STK_MPU_INT +#define Board_MPU_POWER CC1350STK_MPU_POWER +#define Board_MPU_POWER_OFF CC1350STK_MPU_POWER_OFF +#define Board_MPU_POWER_ON CC1350STK_MPU_POWER_ON + +#define Board_TMP_RDY CC1350STK_TMP_RDY + +#define Board_NVSINTERNAL CC1350STK_NVSCC26XX0 +#define Board_NVSEXTERNAL CC1350STK_NVSSPI25X0 + +#define Board_PDM0 CC2650STK_PDM0 + +#define Board_PIN_BUTTON0 CC1350STK_KEY_LEFT +#define Board_PIN_BUTTON1 CC1350STK_KEY_RIGHT +#define Board_PIN_BTN1 CC1350STK_KEY_LEFT +#define Board_PIN_BTN2 CC1350STK_KEY_RIGHT +#define Board_PIN_LED0 CC1350STK_PIN_LED1 +#define Board_PIN_LED1 CC1350STK_PIN_LED1 +#define Board_PIN_LED2 CC1350STK_PIN_LED1 + +#define Board_PWM0 CC1350STK_PWM0 +#define Board_PWM1 CC1350STK_PWM0 +#define Board_PWM2 CC1350STK_PWM2 +#define Board_PWM3 CC1350STK_PWM3 +#define Board_PWM4 CC1350STK_PWM4 +#define Board_PWM5 CC1350STK_PWM5 +#define Board_PWM6 CC1350STK_PWM6 +#define Board_PWM7 CC1350STK_PWM7 + +#define Board_SPI0 CC1350STK_SPI0 +#define Board_SPI0_MISO CC1350STK_SPI0_MISO +#define Board_SPI0_MOSI CC1350STK_SPI0_MOSI +#define Board_SPI0_CLK CC1350STK_SPI0_CLK +#define Board_SPI0_CSN CC1350STK_SPI0_CSN +#define Board_SPI1 CC1350STK_SPI1 +#define Board_SPI1_MISO CC1350STK_SPI1_MISO +#define Board_SPI1_MOSI CC1350STK_SPI1_MOSI +#define Board_SPI1_CLK CC1350STK_SPI1_CLK +#define Board_SPI1_CSN CC1350STK_SPI1_CSN +#define Board_SPI_FLASH_CS CC1350STK_SPI_FLASH_CS +#define Board_FLASH_CS_ON CC1350STK_FLASH_CS_ON +#define Board_FLASH_CS_OFF CC1350STK_FLASH_CS_OFF + +#define Board_UART0 CC1350STK_UART0 + +#define Board_WATCHDOG0 CC1350STK_WATCHDOG0 + +/* Board specific I2C addresses */ +#define Board_BMP280_ADDR (0x77) +#define Board_HDC1000_ADDR (0x43) +#define Board_MPU9250_ADDR (0x68) +#define Board_MPU9250_MAG_ADDR (0x0C) +#define Board_OPT3001_ADDR (0x45) +#define Board_TMP_ADDR (0x44) + +#ifdef __cplusplus +} +#endif + +#endif /* __BOARD_H */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/CC1350STK.c b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/CC1350STK.c new file mode 100644 index 000000000..de15954f0 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/CC1350STK.c @@ -0,0 +1,653 @@ +/* + * Copyright (c) 2016-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +/* + * ====================== CC1350STK.c ========================================= + * This file is responsible for setting up the board specific items for the + * CC1350STK board. + */ + +#include +#include +#include + +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/udma.h) +#include DeviceFamily_constructPath(inc/hw_ints.h) +#include DeviceFamily_constructPath(inc/hw_memmap.h) + +#include "CC1350STK.h" + +/* + * =============================== Crypto =============================== + */ +#include + +CryptoCC26XX_Object cryptoCC26XXObjects[CC1350STK_CRYPTOCOUNT]; + +const CryptoCC26XX_HWAttrs cryptoCC26XXHWAttrs[CC1350STK_CRYPTOCOUNT] = { + { + .baseAddr = CRYPTO_BASE, + .powerMngrId = PowerCC26XX_PERIPH_CRYPTO, + .intNum = INT_CRYPTO_RESULT_AVAIL_IRQ, + .intPriority = ~0, + } +}; + +const CryptoCC26XX_Config CryptoCC26XX_config[CC1350STK_CRYPTOCOUNT] = { + { + .object = &cryptoCC26XXObjects[CC1350STK_CRYPTO0], + .hwAttrs = &cryptoCC26XXHWAttrs[CC1350STK_CRYPTO0] + } +}; + +/* + * =============================== GPIO =============================== + */ +#include +#include + +/* + * Array of Pin configurations + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC1350STK.h + * NOTE: Pins not used for interrupts should be placed at the end of the + * array. Callback entries can be omitted from callbacks array to + * reduce memory usage. + */ +GPIO_PinConfig gpioPinConfigs[] = { + /* Input pins */ + GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG, /* Button 0 */ + GPIOCC26XX_DIO_04 | GPIO_DO_NOT_CONFIG, /* Button 1 */ + + /* Output pins */ + GPIOCC26XX_DIO_10 | GPIO_DO_NOT_CONFIG, /* LED */ + + /* SPI Flash CSN */ + GPIOCC26XX_DIO_14 | GPIO_DO_NOT_CONFIG, +}; + +/* + * Array of callback function pointers + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC1350STK.h + * NOTE: Pins not used for interrupts can be omitted from callbacks array to + * reduce memory usage (if placed at end of gpioPinConfigs array). + */ +GPIO_CallbackFxn gpioCallbackFunctions[] = { + NULL, /* Button 0 */ + NULL, /* Button 1 */ +}; + +const GPIOCC26XX_Config GPIOCC26XX_config = { + .pinConfigs = (GPIO_PinConfig *)gpioPinConfigs, + .callbacks = (GPIO_CallbackFxn *)gpioCallbackFunctions, + .numberOfPinConfigs = CC1350STK_GPIOCOUNT, + .numberOfCallbacks = sizeof(gpioCallbackFunctions)/sizeof(GPIO_CallbackFxn), + .intPriority = (~0) +}; + +/* + * =============================== GPTimer =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include + +GPTimerCC26XX_Object gptimerCC26XXObjects[CC1350STK_GPTIMERCOUNT]; + +const GPTimerCC26XX_HWAttrs gptimerCC26xxHWAttrs[CC1350STK_GPTIMERPARTSCOUNT] = { + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0A, }, + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0B, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1A, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1B, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2A, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2B, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3A, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3B, }, +}; + +const GPTimerCC26XX_Config GPTimerCC26XX_config[CC1350STK_GPTIMERPARTSCOUNT] = { + { &gptimerCC26XXObjects[CC1350STK_GPTIMER0], &gptimerCC26xxHWAttrs[CC1350STK_GPTIMER0A], GPT_A }, + { &gptimerCC26XXObjects[CC1350STK_GPTIMER0], &gptimerCC26xxHWAttrs[CC1350STK_GPTIMER0B], GPT_B }, + { &gptimerCC26XXObjects[CC1350STK_GPTIMER1], &gptimerCC26xxHWAttrs[CC1350STK_GPTIMER1A], GPT_A }, + { &gptimerCC26XXObjects[CC1350STK_GPTIMER1], &gptimerCC26xxHWAttrs[CC1350STK_GPTIMER1B], GPT_B }, + { &gptimerCC26XXObjects[CC1350STK_GPTIMER2], &gptimerCC26xxHWAttrs[CC1350STK_GPTIMER2A], GPT_A }, + { &gptimerCC26XXObjects[CC1350STK_GPTIMER2], &gptimerCC26xxHWAttrs[CC1350STK_GPTIMER2B], GPT_B }, + { &gptimerCC26XXObjects[CC1350STK_GPTIMER3], &gptimerCC26xxHWAttrs[CC1350STK_GPTIMER3A], GPT_A }, + { &gptimerCC26XXObjects[CC1350STK_GPTIMER3], &gptimerCC26xxHWAttrs[CC1350STK_GPTIMER3B], GPT_B }, +}; + +/* + * =============================== I2C =============================== +*/ +#include +#include + +#if TI_I2C_CONF_ENABLE + +I2CCC26XX_Object i2cCC26xxObjects[CC1350STK_I2CCOUNT]; + +const I2CCC26XX_HWAttrsV1 i2cCC26xxHWAttrs[CC1350STK_I2CCOUNT] = { +#if TI_I2C_CONF_I2C0_ENABLE + { + .baseAddr = I2C0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_I2C0, + .intNum = INT_I2C_IRQ, + .intPriority = ~0, + .swiPriority = 0, + .sdaPin = CC1350STK_I2C0_SDA0, + .sclPin = CC1350STK_I2C0_SCL0, + }, +#endif +}; + +const I2C_Config I2C_config[CC1350STK_I2CCOUNT] = { +#if TI_I2C_CONF_I2C0_ENABLE + { + .fxnTablePtr = &I2CCC26XX_fxnTable, + .object = &i2cCC26xxObjects[CC1350STK_I2C0], + .hwAttrs = &i2cCC26xxHWAttrs[CC1350STK_I2C0] + }, +#endif +}; + +const uint_least8_t I2C_count = CC1350STK_I2CCOUNT; + +#endif /* TI_I2C_CONF_ENABLE */ + +/* + * =============================== NVS =============================== + */ +#include +#include +#include + +#define NVS_REGIONS_BASE 0x1A000 +#define SECTORSIZE 0x1000 +#define REGIONSIZE (SECTORSIZE * 4) + +#if TI_NVS_CONF_ENABLE + +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + +/* + * Reserve flash sectors for NVS driver use by placing an uninitialized byte + * array at the desired flash address. + */ +#if defined(__TI_COMPILER_VERSION__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +#pragma LOCATION(flashBuf, NVS_REGIONS_BASE); +#pragma NOINIT(flashBuf); +static char flashBuf[REGIONSIZE]; + +#elif defined(__IAR_SYSTEMS_ICC__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +static __no_init char flashBuf[REGIONSIZE] @ NVS_REGIONS_BASE; + +#elif defined(__GNUC__) + +/* + * Place the flash buffers in the .nvs section created in the gcc linker file. + * The .nvs section enforces alignment on a sector boundary but may + * be placed anywhere in flash memory. If desired the .nvs section can be set + * to a fixed address by changing the following in the gcc linker file: + * + * .nvs (FIXED_FLASH_ADDR) (NOLOAD) : AT (FIXED_FLASH_ADDR) { + * *(.nvs) + * } > REGION_TEXT + */ +__attribute__ ((section (".nvs"))) +static char flashBuf[REGIONSIZE]; + +#endif + +/* Allocate objects for NVS and NVS SPI */ +NVSCC26XX_Object nvsCC26xxObjects[1]; + +/* Hardware attributes for NVS */ +const NVSCC26XX_HWAttrs nvsCC26xxHWAttrs[1] = { + { + .regionBase = (void *)flashBuf, + .regionSize = REGIONSIZE, + }, +}; + +#endif /* TI_NVS_CONF_NVS_INTERNAL_ENABLE */ + +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + +#define SPISECTORSIZE 0x1000 +#define SPIREGIONSIZE (SECTORSIZE * 32) +#define VERIFYBUFSIZE 64 + +static uint8_t verifyBuf[VERIFYBUFSIZE]; + +NVSSPI25X_Object nvsSPI25XObjects[1]; + +/* Hardware attributes for NVS SPI */ +const NVSSPI25X_HWAttrs nvsSPI25XHWAttrs[1] = { + { + .regionBaseOffset = 0, + .regionSize = SPIREGIONSIZE, + .sectorSize = SPISECTORSIZE, + .verifyBuf = verifyBuf, + .verifyBufSize = VERIFYBUFSIZE, + .spiHandle = NULL, + .spiIndex = 0, + .spiBitRate = 4000000, + .spiCsnGpioIndex = CC1350STK_GPIO_SPI_FLASH_CS, + }, +}; + +#endif /* Board_EXCLUDE_NVS_EXTERNAL_FLASH */ + +/* NVS Region index 0 and 1 refer to NVS and NVS SPI respectively */ +const NVS_Config NVS_config[CC1350STK_NVSCOUNT] = { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + { + .fxnTablePtr = &NVSCC26XX_fxnTable, + .object = &nvsCC26xxObjects[0], + .hwAttrs = &nvsCC26xxHWAttrs[0], + }, +#endif +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + { + .fxnTablePtr = &NVSSPI25X_fxnTable, + .object = &nvsSPI25XObjects[0], + .hwAttrs = &nvsSPI25XHWAttrs[0], + }, +#endif +}; + +const uint_least8_t NVS_count = CC1350STK_NVSCOUNT; + +#endif /* TI_NVS_CONF_ENABLE */ + +/* + * =============================== PDM =============================== +*/ +#include +#include + +PDMCC26XX_Object pdmCC26XXObjects[CC1350STK_PDMCOUNT]; +PDMCC26XX_I2S_Object pdmCC26XXI2SObjects[CC1350STK_PDMCOUNT]; + +const PDMCC26XX_HWAttrs pdmCC26XXHWAttrs[CC1350STK_PDMCOUNT] = { + { + .micPower = CC1350STK_MIC_POWER, + .taskPriority = 2 + } +}; + +const PDMCC26XX_Config PDMCC26XX_config[CC1350STK_PDMCOUNT] = { + { + .object = &pdmCC26XXObjects[CC1350STK_PDM0], + .hwAttrs = &pdmCC26XXHWAttrs[CC1350STK_PDM0] + } +}; + +const PDMCC26XX_I2S_HWAttrs pdmC26XXI2SHWAttrs[CC1350STK_PDMCOUNT] = { + { + .baseAddr = I2S0_BASE, + .intNum = INT_I2S_IRQ, + .powerMngrId = PowerCC26XX_PERIPH_I2S, + .intPriority = ~0, + .mclkPin = PIN_UNASSIGNED, + .bclkPin = CC1350STK_AUDIO_CLK, + .wclkPin = PIN_UNASSIGNED, + .ad0Pin = CC1350STK_AUDIO_DI, + } +}; + +const PDMCC26XX_I2S_Config PDMCC26XX_I2S_config[CC1350STK_PDMCOUNT] = { + { + .object = &pdmCC26XXI2SObjects[CC1350STK_PDM0], + .hwAttrs = &pdmC26XXI2SHWAttrs[CC1350STK_PDM0] + } +}; + +/* + * =============================== PIN =============================== + */ +#include +#include + +const PIN_Config BoardGpioInitTable[] = { + + CC1350STK_PIN_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC1350STK_KEY_LEFT | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC1350STK_KEY_RIGHT | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC1350STK_RELAY | PIN_INPUT_EN | PIN_PULLDOWN | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Relay is active high */ + CC1350STK_MPU_INT | PIN_INPUT_EN | PIN_PULLDOWN | PIN_IRQ_NEGEDGE | PIN_HYSTERESIS, /* MPU_INT is active low */ + CC1350STK_TMP_RDY | PIN_INPUT_EN | PIN_PULLUP | PIN_HYSTERESIS, /* TMP_RDY is active high */ + CC1350STK_BUZZER | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* Buzzer initially off */ + CC1350STK_MPU_POWER | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* MPU initially on */ + CC1350STK_MIC_POWER | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* MIC initially off */ + CC1350STK_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ + CC1350STK_SPI_DEVPK_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* DevPack chip select */ + CC1350STK_AUDIO_DI | PIN_INPUT_EN | PIN_PULLDOWN, /* Audio DI */ + CC1350STK_AUDIODO | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* Audio data out */ + CC1350STK_AUDIO_CLK | PIN_INPUT_EN | PIN_PULLDOWN, /* DevPack */ + CC1350STK_DP2 | PIN_INPUT_EN | PIN_PULLDOWN, /* DevPack */ + CC1350STK_DP1 | PIN_INPUT_EN | PIN_PULLDOWN, /* DevPack */ + CC1350STK_DP0 | PIN_INPUT_EN | PIN_PULLDOWN, /* DevPack */ + CC1350STK_DP3 | PIN_INPUT_EN | PIN_PULLDOWN, /* DevPack */ + CC1350STK_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* DevPack */ + CC1350STK_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* DevPack */ + CC1350STK_DEVPK_ID | PIN_INPUT_EN | PIN_NOPULL, /* Device pack ID - external PU */ + CC1350STK_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */ + CC1350STK_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */ + CC1350STK_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI clock */ + + PIN_TERMINATE +}; + +const PINCC26XX_HWAttrs PINCC26XX_hwAttrs = { + .intPriority = ~0, + .swiPriority = 0 +}; + +/* + * =============================== Power =============================== + */ +const PowerCC26XX_Config PowerCC26XX_config = { + .policyInitFxn = NULL, + .policyFxn = &PowerCC26XX_standbyPolicy, + .calibrateFxn = &PowerCC26XX_calibrate, + .enablePolicy = true, + .calibrateRCOSC_LF = true, + .calibrateRCOSC_HF = true, +}; + +/* + * =============================== PWM =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include +#include + +PWMTimerCC26XX_Object pwmtimerCC26xxObjects[CC1350STK_PWMCOUNT]; + +const PWMTimerCC26XX_HwAttrs pwmtimerCC26xxHWAttrs[CC1350STK_PWMCOUNT] = { + { .pwmPin = CC1350STK_PWMPIN0, .gpTimerUnit = CC1350STK_GPTIMER0A }, + { .pwmPin = CC1350STK_PWMPIN1, .gpTimerUnit = CC1350STK_GPTIMER0B }, + { .pwmPin = CC1350STK_PWMPIN2, .gpTimerUnit = CC1350STK_GPTIMER1A }, + { .pwmPin = CC1350STK_PWMPIN3, .gpTimerUnit = CC1350STK_GPTIMER1B }, + { .pwmPin = CC1350STK_PWMPIN4, .gpTimerUnit = CC1350STK_GPTIMER2A }, + { .pwmPin = CC1350STK_PWMPIN5, .gpTimerUnit = CC1350STK_GPTIMER2B }, + { .pwmPin = CC1350STK_PWMPIN6, .gpTimerUnit = CC1350STK_GPTIMER3A }, + { .pwmPin = CC1350STK_PWMPIN7, .gpTimerUnit = CC1350STK_GPTIMER3B }, +}; + +const PWM_Config PWM_config[CC1350STK_PWMCOUNT] = { + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350STK_PWM0], &pwmtimerCC26xxHWAttrs[CC1350STK_PWM0] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350STK_PWM1], &pwmtimerCC26xxHWAttrs[CC1350STK_PWM1] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350STK_PWM2], &pwmtimerCC26xxHWAttrs[CC1350STK_PWM2] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350STK_PWM3], &pwmtimerCC26xxHWAttrs[CC1350STK_PWM3] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350STK_PWM4], &pwmtimerCC26xxHWAttrs[CC1350STK_PWM4] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350STK_PWM5], &pwmtimerCC26xxHWAttrs[CC1350STK_PWM5] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350STK_PWM6], &pwmtimerCC26xxHWAttrs[CC1350STK_PWM6] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350STK_PWM7], &pwmtimerCC26xxHWAttrs[CC1350STK_PWM7] }, +}; + +const uint_least8_t PWM_count = CC1350STK_PWMCOUNT; + +/* + * =============================== RF Driver =============================== + */ +#include + +const RFCC26XX_HWAttrsV2 RFCC26XX_hwAttrs = { + .hwiPriority = ~0, /* Lowest HWI priority */ + .swiPriority = 0, /* Lowest SWI priority */ + .xoscHfAlwaysNeeded = true, /* Keep XOSC dependency while in stanby */ + .globalCallback = NULL, /* No board specific callback */ + .globalEventMask = 0 /* No events subscribed to */ +}; + +/* + * =============================== SPI DMA =============================== + */ +#include +#include + +#if TI_SPI_CONF_ENABLE + +SPICC26XXDMA_Object spiCC26XXDMAObjects[CC1350STK_SPICOUNT]; + +const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[CC1350STK_SPICOUNT] = { +#if TI_SPI_CONF_SPI0_ENABLE + { + .baseAddr = SSI0_BASE, + .intNum = INT_SSI0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .powerMngrId = PowerCC26XX_PERIPH_SSI0, + .defaultTxBufValue = 0, + .rxChannelBitMask = 1< +#include + +TRNGCC26X0_Object trngCC26X0Object[CC1350STK_TRNGCOUNT]; + +const TRNGCC26X0_HWAttrs trngCC26X0HWAttrs[CC1350STK_TRNGCOUNT] = { + { + .swiPriority = 0, + .intPriority = ~0, + } +}; + +const TRNG_Config TRNG_config[] = { + { &trngCC26X0Object[0], &trngCC26X0HWAttrs[0] }, +}; + +const uint8_t TRNG_count = CC1350STK_TRNGCOUNT; + + +/* + * =============================== UART =============================== + */ +#include +#include + +#if TI_UART_CONF_ENABLE + +UARTCC26XX_Object uartCC26XXObjects[CC1350STK_UARTCOUNT]; + +uint8_t uartCC26XXRingBuffer[CC1350STK_UARTCOUNT][32]; + +const UARTCC26XX_HWAttrsV2 uartCC26XXHWAttrs[CC1350STK_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .baseAddr = UART0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UART0, + .intNum = INT_UART0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .txPin = CC1350STK_UART_TX, + .rxPin = CC1350STK_UART_RX, + .ctsPin = PIN_UNASSIGNED, + .rtsPin = PIN_UNASSIGNED, + .ringBufPtr = uartCC26XXRingBuffer[CC1350STK_UART0], + .ringBufSize = sizeof(uartCC26XXRingBuffer[CC1350STK_UART0]), + .txIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_1_8, + .rxIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_4_8, + .errorFxn = NULL + }, +#endif +}; + +const UART_Config UART_config[CC1350STK_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .fxnTablePtr = &UARTCC26XX_fxnTable, + .object = &uartCC26XXObjects[CC1350STK_UART0], + .hwAttrs = &uartCC26XXHWAttrs[CC1350STK_UART0] + }, +#endif +}; + +const uint_least8_t UART_count = CC1350STK_UARTCOUNT; + +#endif /* TI_UART_CONF_ENABLE */ + +/* + * =============================== UDMA =============================== + */ +#include + +UDMACC26XX_Object udmaObjects[CC1350STK_UDMACOUNT]; + +const UDMACC26XX_HWAttrs udmaHWAttrs[CC1350STK_UDMACOUNT] = { + { + .baseAddr = UDMA0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UDMA, + .intNum = INT_DMA_ERR, + .intPriority = ~0 + } +}; + +const UDMACC26XX_Config UDMACC26XX_config[CC1350STK_UDMACOUNT] = { + { + .object = &udmaObjects[CC1350STK_UDMA0], + .hwAttrs = &udmaHWAttrs[CC1350STK_UDMA0] + }, +}; + +/* + * =============================== Watchdog =============================== + */ +#include +#include + +WatchdogCC26XX_Object watchdogCC26XXObjects[CC1350STK_WATCHDOGCOUNT]; + +const WatchdogCC26XX_HWAttrs watchdogCC26XXHWAttrs[CC1350STK_WATCHDOGCOUNT] = { + { + .baseAddr = WDT_BASE, + .reloadValue = 1000 /* Reload value in milliseconds */ + }, +}; + +const Watchdog_Config Watchdog_config[CC1350STK_WATCHDOGCOUNT] = { + { + .fxnTablePtr = &WatchdogCC26XX_fxnTable, + .object = &watchdogCC26XXObjects[CC1350STK_WATCHDOG0], + .hwAttrs = &watchdogCC26XXHWAttrs[CC1350STK_WATCHDOG0] + }, +}; + +const uint_least8_t Watchdog_count = CC1350STK_WATCHDOGCOUNT; + +/* + * Board-specific initialization function to disable external flash. + * This function is defined in the file CC1350STK_fxns.c + */ +extern void Board_initHook(void); + +/* + * ======== CC1350STK_initGeneral ======== + */ +void CC1350STK_initGeneral(void) +{ + Power_init(); + + if ( PIN_init(BoardGpioInitTable) != PIN_SUCCESS) { + /* Error with PIN_init */ + while (1); + } + + /* Perform board-specific initialization */ + Board_initHook(); +} diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/CC1350STK.h b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/CC1350STK.h new file mode 100644 index 000000000..2347876b1 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/CC1350STK.h @@ -0,0 +1,346 @@ +/* + * Copyright (c) 2015-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 CC1350STK.h + * + * @brief CC1350STK Board Specific header file. + * + * The CC1350STK header file should be included in an application as + * follows: + * @code + * #include "CC1350STK.h" + * @endcode + * ============================================================================ + */ +#ifndef __CC1350STK_BOARD_H__ +#define __CC1350STK_BOARD_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "contiki-conf.h" + +/* Includes */ +#include +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) + +/* Externs */ +extern const PIN_Config BoardGpioInitTable[]; + +/* Defines */ +#define CC1350STK + +/* Mapping of pins to board signals using general board aliases + * + */ + +/* Audio */ +#define CC1350STK_MIC_POWER IOID_13 +#define CC1350STK_MIC_POWER_ON 1 +#define CC1350STK_MIC_POWER_OFF 0 +#define CC1350STK_AUDIO_DI IOID_2 +#define CC1350STK_AUDIO_CLK IOID_3 + +/* Buzzer */ +#define CC1350STK_BUZZER IOID_21 +#define CC1350STK_BUZZER_ON 1 +#define CC1350STK_BUZZER_OFF 0 + +/* DevPack */ +#define CC1350STK_AUDIOFS_TDO IOID_16 +#define CC1350STK_AUDIODO IOID_22 +#define CC1350STK_DP2 IOID_23 +#define CC1350STK_DP1 IOID_24 +#define CC1350STK_DP0 IOID_25 +#define CC1350STK_DP3 IOID_27 +#define CC1350STK_DP4_UARTRX IOID_28 +#define CC1350STK_DP5_UARTTX IOID_29 +#define CC1350STK_DEVPK_ID IOID_30 +#define CC1350STK_SPI_DEVPK_CS IOID_20 + +/* Discrete Outputs */ +#define CC1350STK_PIN_LED1 IOID_10 +#define CC1350STK_LED_ON 1 +#define CC1350STK_LED_OFF 0 + + +/* Discrete Inputs */ +#define CC1350STK_KEY_LEFT IOID_15 +#define CC1350STK_KEY_RIGHT IOID_4 +#define CC1350STK_RELAY IOID_1 + +/* GPIO */ +#define CC1350STK_GPIO_LED_ON 1 +#define CC1350STK_GPIO_LED_OFF 0 + +/* I2C */ +#define CC1350STK_I2C0_SDA0 IOID_5 +#define CC1350STK_I2C0_SCL0 IOID_6 +#define CC1350STK_I2C0_SDA1 IOID_8 +#define CC1350STK_I2C0_SCL1 IOID_9 + +/* LED-Audio DevPack */ +#define CC1350STK_DEVPK_LIGHT_BLUE IOID_23 +#define CC1350STK_DEVPK_LIGHT_GREEN IOID_24 +#define CC1350STK_DEVPK_LIGHT_WHITE IOID_25 +#define CC1350STK_DEVPK_LIGHT_RED IOID_27 + +/* Power */ +#define CC1350STK_MPU_POWER IOID_12 +#define CC1350STK_MPU_POWER_ON 1 +#define CC1350STK_MPU_POWER_OFF 0 + +/* PWM */ +#define CC1350STK_PWMPIN0 CC1350STK_PIN_LED1 +#define CC1350STK_PWMPIN1 CC1350STK_PIN_LED1 +#define CC1350STK_PWMPIN2 PIN_UNASSIGNED +#define CC1350STK_PWMPIN3 PIN_UNASSIGNED +#define CC1350STK_PWMPIN4 PIN_UNASSIGNED +#define CC1350STK_PWMPIN5 PIN_UNASSIGNED +#define CC1350STK_PWMPIN6 PIN_UNASSIGNED +#define CC1350STK_PWMPIN7 PIN_UNASSIGNED + +/* Sensors */ +#define CC1350STK_MPU_INT IOID_7 +#define CC1350STK_TMP_RDY IOID_11 + +/* SPI */ +#define CC1350STK_SPI_FLASH_CS IOID_14 +#define CC1350STK_FLASH_CS_ON 0 +#define CC1350STK_FLASH_CS_OFF 1 + +/* SPI Board */ +#define CC1350STK_SPI0_MISO IOID_18 +#define CC1350STK_SPI0_MOSI IOID_19 +#define CC1350STK_SPI0_CLK IOID_17 +#define CC1350STK_SPI0_CSN PIN_UNASSIGNED +#define CC1350STK_SPI1_MISO PIN_UNASSIGNED +#define CC1350STK_SPI1_MOSI PIN_UNASSIGNED +#define CC1350STK_SPI1_CLK PIN_UNASSIGNED +#define CC1350STK_SPI1_CSN PIN_UNASSIGNED + +/* UART */ +#define CC1350STK_UART_TX CC1350STK_DP5_UARTTX +#define CC1350STK_UART_RX CC1350STK_DP4_UARTRX + +/*! + * @brief Initialize the general board specific settings + * + * This function initializes the general board specific settings. + */ +void CC1350STK_initGeneral(void); + +/*! + * @brief Turn off the external flash on LaunchPads + * + */ +void CC1350STK_shutDownExtFlash(void); + +/*! + * @brief Wake up the external flash present on the board files + * + * This function toggles the chip select for the amount of time needed + * to wake the chip up. + */ +void CC1350STK_wakeUpExtFlash(void); + +/*! + * @def CC1350STK_CryptoName + * @brief Enum of Crypto names + */ +typedef enum CC1350STK_CryptoName { + CC1350STK_CRYPTO0 = 0, + + CC1350STK_CRYPTOCOUNT +} CC1350STK_CryptoName; + +/*! + * @def CC1350STK_GPIOName + * @brief Enum of GPIO names + */ +typedef enum CC1350STK_GPIOName { + CC1350STK_GPIO_S1 = 0, + CC1350STK_GPIO_S2, + CC1350STK_GPIO_LED0, + CC1350STK_GPIO_SPI_FLASH_CS, + + CC1350STK_GPIOCOUNT +} CC1350STK_GPIOName; + +/*! + * @def CC1350STK_GPTimerName + * @brief Enum of GPTimers parts + */ +typedef enum CC1350STK_GPTimerName { + CC1350STK_GPTIMER0A = 0, + CC1350STK_GPTIMER0B, + CC1350STK_GPTIMER1A, + CC1350STK_GPTIMER1B, + CC1350STK_GPTIMER2A, + CC1350STK_GPTIMER2B, + CC1350STK_GPTIMER3A, + CC1350STK_GPTIMER3B, + + CC1350STK_GPTIMERPARTSCOUNT +} CC1350STK_GPTimerName; + +/*! + * @def CC1350STK_GPTimers + * @brief Enum of GPTimers + */ +typedef enum CC1350STK_GPTimers { + CC1350STK_GPTIMER0 = 0, + CC1350STK_GPTIMER1, + CC1350STK_GPTIMER2, + CC1350STK_GPTIMER3, + + CC1350STK_GPTIMERCOUNT +} CC1350STK_GPTimers; + +/*! + * @def CC1350STK_I2CName + * @brief Enum of I2C names + */ +typedef enum CC1350STK_I2CName { +#if TI_I2C_CONF_I2C0_ENABLE + CC1350STK_I2C0 = 0, +#endif + + CC1350STK_I2CCOUNT +} CC1350STK_I2CName; + +/*! + * @def CC1350STK_NVSName + * @brief Enum of NVS names + */ +typedef enum CC1350STK_NVSName { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + CC1350STK_NVSCC26XX0 = 0, +#endif +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + CC1350STK_NVSSPI25X0, +#endif + + CC1350STK_NVSCOUNT +} CC1350STK_NVSName; + +/*! + * @def CC1350STK_PDMName + * @brief Enum of PDM names + */ +typedef enum CC1350STK_PDMName { + CC1350STK_PDM0 = 0, + + CC1350STK_PDMCOUNT +} CC1350STK_PDMName; + +/*! + * @def CC1350STK_PWMName + * @brief Enum of PWM outputs + */ +typedef enum CC1350STK_PWMName { + CC1350STK_PWM0 = 0, + CC1350STK_PWM1, + CC1350STK_PWM2, + CC1350STK_PWM3, + CC1350STK_PWM4, + CC1350STK_PWM5, + CC1350STK_PWM6, + CC1350STK_PWM7, + + CC1350STK_PWMCOUNT +} CC1350STK_PWMName; + +/*! + * @def CC1350STK_SPIName + * @brief Enum of SPI names + */ +typedef enum CC1350STK_SPIName { +#if TI_SPI_CONF_SPI0_ENABLE + CC1350STK_SPI0 = 0, +#endif +#if TI_SPI_CONF_SPI1_ENABLE + CC1350STK_SPI1, +#endif + + CC1350STK_SPICOUNT +} CC1350STK_SPIName; + +/*! + * @def CC1350STK_TRNGName + * @brief Enum of TRNGs + */ +typedef enum CC1350STK_TRNGName { + CC1350STK_TRNG0 = 0, + + CC1350STK_TRNGCOUNT +} CC1350STK_TRNGName; + +/*! + * @def CC1350STK_UARTName + * @brief Enum of UARTs + */ +typedef enum CC1350STK_UARTName { +#if TI_UART_CONF_UART0_ENABLE + CC1350STK_UART0 = 0, +#endif + + CC1350STK_UARTCOUNT +} CC1350STK_UARTName; + +/*! + * @def CC1350STK_UDMAName + * @brief Enum of DMA buffers + */ +typedef enum CC1350STK_UDMAName { + CC1350STK_UDMA0 = 0, + + CC1350STK_UDMACOUNT +} CC1350STK_UDMAName; + +/*! + * @def CC1350STK_WatchdogName + * @brief Enum of Watchdogs + */ +typedef enum CC1350STK_WatchdogName { + CC1350STK_WATCHDOG0 = 0, + + CC1350STK_WATCHDOGCOUNT +} CC1350STK_WatchdogName; + +#ifdef __cplusplus +} +#endif + +#endif /* __CC1350STK_BOARD_H__ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/CC1350STK_fxns.c b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/CC1350STK_fxns.c new file mode 100644 index 000000000..dd20cb301 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/CC1350STK_fxns.c @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ +/* + * ====================== CC1350STK_fxns.c ========================================= + * This file contains the board-specific initialization functions. + */ + +#include +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/cpu.h) + +#include "Board.h" + +/* + * ======== CC1350STK_sendExtFlashByte ======== + */ +void CC1350STK_sendExtFlashByte(PIN_Handle pinHandle, uint8_t byte) +{ + uint8_t i; + + /* SPI Flash CS */ + PIN_setOutputValue(pinHandle, IOID_14, 0); + + for (i = 0; i < 8; i++) { + PIN_setOutputValue(pinHandle, IOID_17, 0); /* SPI Flash CLK */ + + /* SPI Flash MOSI */ + PIN_setOutputValue(pinHandle, IOID_19, (byte >> (7 - i)) & 0x01); + PIN_setOutputValue(pinHandle, IOID_17, 1); + + /* + * Waste a few cycles to keep the CLK high for at + * least 45% of the period. + * 3 cycles per loop: 8 loops @ 48 Mhz = 0.5 us. + */ + CPUdelay(8); + } + + PIN_setOutputValue(pinHandle, IOID_17, 0); + PIN_setOutputValue(pinHandle, IOID_14, 1); + + /* + * Keep CS high at least 40 us + * 3 cycles per loop: 700 loops @ 48 Mhz ~= 44 us + */ + CPUdelay(700); +} + +/* + * ======== CC1350STK_wakeUpExtFlash ======== + */ +void CC1350STK_wakeUpExtFlash(void) +{ + PIN_Config extFlashPinTable[] = { + IOID_14 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + PIN_TERMINATE + }; + PIN_State extFlashPinState; + PIN_Handle extFlashPinHandle = PIN_open(&extFlashPinState, extFlashPinTable); + + /* + * To wake up we need to toggle the chip select at + * least 20 ns and ten wait at least 35 us. + */ + + /* Toggle chip select for ~20ns to wake ext. flash */ + PIN_setOutputValue(extFlashPinHandle, IOID_14, 0); + /* 3 cycles per loop: 1 loop @ 48 Mhz ~= 62 ns */ + CPUdelay(1); + PIN_setOutputValue(extFlashPinHandle, IOID_14, 1); + /* 3 cycles per loop: 560 loops @ 48 Mhz ~= 35 us */ + CPUdelay(560); + + PIN_close(extFlashPinHandle); +} + +/* + * ======== CC1350STK_shutDownExtFlash ======== + */ +void CC1350STK_shutDownExtFlash(void) +{ + /* + * To be sure we are putting the flash into sleep and not waking it, + * we first have to make a wake up call + */ + CC1350STK_wakeUpExtFlash(); + + PIN_Config extFlashPinTable[] = { + /* SPI Flash CS*/ + IOID_14 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash CLK */ + IOID_17 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash MOSI */ + IOID_19 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash MISO */ + IOID_18 | PIN_INPUT_EN | PIN_PULLDOWN, + PIN_TERMINATE + }; + PIN_State extFlashPinState; + PIN_Handle extFlashPinHandle = PIN_open(&extFlashPinState, extFlashPinTable); + + uint8_t extFlashShutdown = 0xB9; + + CC1350STK_sendExtFlashByte(extFlashPinHandle, extFlashShutdown); + + PIN_close(extFlashPinHandle); +} + +/* + * ======== Board_initHook ======== + * Called by Board_init() to perform board-specific initialization. + */ +void Board_initHook() +{ + CC1350STK_shutDownExtFlash(); +} diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/Makefile.cc1350 b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/Makefile.cc1350 new file mode 100644 index 000000000..f9b395f95 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/Makefile.cc1350 @@ -0,0 +1,22 @@ +################################################################################ +# SimpleLink Device makefile + +SUBFAMILY = cc13x0-cc26x0 +DEVICE_FAMILY = CC13X0 +DEVICE_LINE = CC13XX +DEVICE = CC1350 + +BOARD_SOURCEFILES += CC1350STK.c CC1350STK_fxns.c +BOARD_SOURCEFILES += leds-arch.c + +SUPPORTS_PROP_MODE = 1 +SUPPORTS_IEEE_MODE = 1 +SUPPORTS_BLE_BEACON = 1 + +SUPPORTS_HIGH_PA = 0 + +### Signal that we can be programmed with cc2538-bsl +BOARD_SUPPORTS_BSL = 1 + +# Include the common board makefile +include $(FAMILY_PATH)/sensortag/Makefile.sensortag diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/leds-arch.c b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/leds-arch.c new file mode 100644 index 000000000..020d538bf --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/leds-arch.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup sensortag-peripherals + * @{ + * + * \file + * LED HAL definitions for the CC1350STK LEDs. Is not compatible with + * the CC2650STK. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/leds.h" +/*---------------------------------------------------------------------------*/ +#include +/*---------------------------------------------------------------------------*/ +#include +/*---------------------------------------------------------------------------*/ +const leds_t leds_arch_leds[] = { + /* Red LED, AKA LED0 */ + { .pin = Board_PIN_LED0, .negative_logic = false }, +}; +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/leds-arch.h b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/leds-arch.h new file mode 100644 index 000000000..535396f43 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc1350/leds-arch.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** \addtogroup sensortag-peripherals + * @{ + * + * \file + * LED HAL definitions for the CC1350STK LEDs. Is not compatible with + * the CC2650STK. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#ifndef LEDS_ARCH_H_ +#define LEDS_ARCH_H_ +/*---------------------------------------------------------------------------*/ +/** + * \name LED configurations for the dev/leds.h API. + * + * Those values are not meant to be modified by the user + * @{ + */ +#define LEDS_CONF_COUNT 1 + +#define LEDS_CONF_RED 0 + +#define LEDS_CONF_ALL ((1 << LEDS_CONF_COUNT) - 1) +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* LEDS_ARCH_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/Board.h new file mode 100644 index 000000000..e334645bb --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/Board.h @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2015-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 __BOARD_H +#define __BOARD_H + +#define Board_CC2650STK +#define BOARD_STRING "TI CC2650 SensorTag" + +#ifdef __cplusplus +extern "C" { +#endif + +#include "CC2650STK.h" + +#define Board_initGeneral() CC2650STK_initGeneral() +#define Board_shutDownExtFlash() CC2650STK_shutDownExtFlash() +#define Board_wakeUpExtFlash() CC2650STK_wakeUpExtFlash() + +/* These #defines allow us to reuse TI-RTOS across other device families */ + +#define Board_BUZZER CC2650STK_BUZZER +#define Board_BUZZER_ON CC2650STK_LED_ON +#define Board_BUZZER_OFF CC2650STK_LED_OFF + +#define Board_CRYPTO0 CC2650STK_CRYPTO0 + +#define Board_GPIO_BUTTON0 CC2650STK_GPIO_S1 +#define Board_GPIO_BUTTON1 CC2650STK_GPIO_S2 +#define Board_GPIO_LED0 CC2650STK_GPIO_LED0 +#define Board_GPIO_LED1 CC2650STK_GPIO_LED0 +#define Board_GPIO_LED_ON CC2650STK_GPIO_LED_ON +#define Board_GPIO_LED_OFF CC2650STK_GPIO_LED_OFF + +#define Board_GPTIMER0A CC2650STK_GPTIMER0A +#define Board_GPTIMER0B CC2650STK_GPTIMER0B +#define Board_GPTIMER1A CC2650STK_GPTIMER1A +#define Board_GPTIMER1B CC2650STK_GPTIMER1B +#define Board_GPTIMER2A CC2650STK_GPTIMER2A +#define Board_GPTIMER2B CC2650STK_GPTIMER2B +#define Board_GPTIMER3A CC2650STK_GPTIMER3A +#define Board_GPTIMER3B CC2650STK_GPTIMER3B + +#define Board_I2C0 CC2650STK_I2C0 +#define Board_I2C0_SDA1 CC2650STK_I2C0_SDA1 +#define Board_I2C0_SCL1 CC2650STK_I2C0_SCL1 +#define Board_I2C_TMP CC2650STK_I2C0 + +#define Board_KEY_LEFT CC2650STK_KEY_LEFT +#define Board_KEY_RIGHT CC2650STK_KEY_RIGHT +#define Board_RELAY CC2650STK_RELAY + +#define Board_MIC_POWER CC2650STK_MIC_POWER +#define Board_MIC_POWER_OM CC2650STK_MIC_POWER_ON +#define Board_MIC_POWER_OFF CC2650STK_MIC_POWER_OFF + +#define Board_MPU_INT CC2650STK_MPU_INT +#define Board_MPU_POWER CC2650STK_MPU_POWER +#define Board_MPU_POWER_OFF CC2650STK_MPU_POWER_OFF +#define Board_MPU_POWER_ON CC2650STK_MPU_POWER_ON + +#define Board_TMP_RDY CC2650STK_TMP_RDY + +#define Board_NVSINTERNAL CC2650STK_NVSCC26XX0 +#define Board_NVSEXTERNAL CC2650STK_NVSSPI25X0 + +#define Board_PDM0 CC2650STK_PDM0 + +#define Board_PIN_BUTTON0 CC2650STK_KEY_LEFT +#define Board_PIN_BUTTON1 CC2650STK_KEY_RIGHT +#define Board_PIN_BTN1 CC2650STK_KEY_LEFT +#define Board_PIN_BTN2 CC2650STK_KEY_RIGHT +#define Board_PIN_LED0 CC2650STK_PIN_LED0 +#define Board_PIN_LED1 CC2650STK_PIN_LED1 +#define Board_PIN_LED2 CC2650STK_PIN_LED1 + +#define Board_PWM0 CC2650STK_PWM0 +#define Board_PWM1 CC2650STK_PWM0 +#define Board_PWM2 CC2650STK_PWM2 +#define Board_PWM3 CC2650STK_PWM3 +#define Board_PWM4 CC2650STK_PWM4 +#define Board_PWM5 CC2650STK_PWM5 +#define Board_PWM6 CC2650STK_PWM6 +#define Board_PWM7 CC2650STK_PWM7 + +#define Board_SPI0 CC2650STK_SPI0 +#define Board_SPI0_MISO CC2650STK_SPI0_MISO +#define Board_SPI0_MOSI CC2650STK_SPI0_MOSI +#define Board_SPI0_CLK CC2650STK_SPI0_CLK +#define Board_SPI0_CSN CC2650STK_SPI0_CSN +#define Board_SPI1 CC2650STK_SPI1 +#define Board_SPI1_MISO CC2650STK_SPI1_MISO +#define Board_SPI1_MOSI CC2650STK_SPI1_MOSI +#define Board_SPI1_CLK CC2650STK_SPI1_CLK +#define Board_SPI1_CSN CC2650STK_SPI1_CSN +#define Board_SPI_FLASH_CS CC2650STK_SPI_FLASH_CS +#define Board_FLASH_CS_ON CC2650STK_FLASH_CS_ON +#define Board_FLASH_CS_OFF CC2650STK_FLASH_CS_OFF + +#define Board_UART0 CC2650STK_UART0 + +#define Board_WATCHDOG0 CC2650STK_WATCHDOG0 + +/* Board specific I2C addresses */ +#define Board_BMP280_ADDR (0x77) +#define Board_HDC1000_ADDR (0x43) +#define Board_MPU9250_ADDR (0x68) +#define Board_MPU9250_MAG_ADDR (0x0C) +#define Board_OPT3001_ADDR (0x45) +#define Board_TMP_ADDR (0x44) + +#ifdef __cplusplus +} +#endif + +#endif /* __BOARD_H */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/CC2650STK.c b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/CC2650STK.c new file mode 100644 index 000000000..7b16c58ee --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/CC2650STK.c @@ -0,0 +1,653 @@ +/* + * Copyright (c) 2016-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +/* + * ====================== CC2650STK.c ========================================= + * This file is responsible for setting up the board specific items for the + * CC2650STK board. + */ + +#include +#include +#include + +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/udma.h) +#include DeviceFamily_constructPath(inc/hw_ints.h) +#include DeviceFamily_constructPath(inc/hw_memmap.h) + +#include "CC2650STK.h" + +/* + * =============================== Crypto =============================== + */ +#include + +CryptoCC26XX_Object cryptoCC26XXObjects[CC2650STK_CRYPTOCOUNT]; + +const CryptoCC26XX_HWAttrs cryptoCC26XXHWAttrs[CC2650STK_CRYPTOCOUNT] = { + { + .baseAddr = CRYPTO_BASE, + .powerMngrId = PowerCC26XX_PERIPH_CRYPTO, + .intNum = INT_CRYPTO_RESULT_AVAIL_IRQ, + .intPriority = ~0, + } +}; + +const CryptoCC26XX_Config CryptoCC26XX_config[CC2650STK_CRYPTOCOUNT] = { + { + .object = &cryptoCC26XXObjects[CC2650STK_CRYPTO0], + .hwAttrs = &cryptoCC26XXHWAttrs[CC2650STK_CRYPTO0] + } +}; + +/* + * =============================== GPIO =============================== + */ +#include +#include + +/* + * Array of Pin configurations + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC2650STK.h + * NOTE: Pins not used for interrupts should be placed at the end of the + * array. Callback entries can be omitted from callbacks array to + * reduce memory usage. + */ +GPIO_PinConfig gpioPinConfigs[] = { + /* Input pins */ + GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG, /* Button 0 */ + GPIOCC26XX_DIO_04 | GPIO_DO_NOT_CONFIG, /* Button 1 */ + + /* Output pins */ + GPIOCC26XX_DIO_10 | GPIO_DO_NOT_CONFIG, /* LED */ + + /* SPI Flash CSN */ + GPIOCC26XX_DIO_14 | GPIO_DO_NOT_CONFIG, +}; + +/* + * Array of callback function pointers + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC2650STK.h + * NOTE: Pins not used for interrupts can be omitted from callbacks array to + * reduce memory usage (if placed at end of gpioPinConfigs array). + */ +GPIO_CallbackFxn gpioCallbackFunctions[] = { + NULL, /* Button 0 */ + NULL, /* Button 1 */ +}; + +const GPIOCC26XX_Config GPIOCC26XX_config = { + .pinConfigs = (GPIO_PinConfig *)gpioPinConfigs, + .callbacks = (GPIO_CallbackFxn *)gpioCallbackFunctions, + .numberOfPinConfigs = CC2650STK_GPIOCOUNT, + .numberOfCallbacks = sizeof(gpioCallbackFunctions)/sizeof(GPIO_CallbackFxn), + .intPriority = (~0) +}; + +/* + * =============================== GPTimer =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include + +GPTimerCC26XX_Object gptimerCC26XXObjects[CC2650STK_GPTIMERCOUNT]; + +const GPTimerCC26XX_HWAttrs gptimerCC26xxHWAttrs[CC2650STK_GPTIMERPARTSCOUNT] = { + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0A, }, + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0B, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1A, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1B, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2A, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2B, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3A, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3B, }, +}; + +const GPTimerCC26XX_Config GPTimerCC26XX_config[CC2650STK_GPTIMERPARTSCOUNT] = { + { &gptimerCC26XXObjects[CC2650STK_GPTIMER0], &gptimerCC26xxHWAttrs[CC2650STK_GPTIMER0A], GPT_A }, + { &gptimerCC26XXObjects[CC2650STK_GPTIMER0], &gptimerCC26xxHWAttrs[CC2650STK_GPTIMER0B], GPT_B }, + { &gptimerCC26XXObjects[CC2650STK_GPTIMER1], &gptimerCC26xxHWAttrs[CC2650STK_GPTIMER1A], GPT_A }, + { &gptimerCC26XXObjects[CC2650STK_GPTIMER1], &gptimerCC26xxHWAttrs[CC2650STK_GPTIMER1B], GPT_B }, + { &gptimerCC26XXObjects[CC2650STK_GPTIMER2], &gptimerCC26xxHWAttrs[CC2650STK_GPTIMER2A], GPT_A }, + { &gptimerCC26XXObjects[CC2650STK_GPTIMER2], &gptimerCC26xxHWAttrs[CC2650STK_GPTIMER2B], GPT_B }, + { &gptimerCC26XXObjects[CC2650STK_GPTIMER3], &gptimerCC26xxHWAttrs[CC2650STK_GPTIMER3A], GPT_A }, + { &gptimerCC26XXObjects[CC2650STK_GPTIMER3], &gptimerCC26xxHWAttrs[CC2650STK_GPTIMER3B], GPT_B }, +}; + +/* + * =============================== I2C =============================== +*/ +#include +#include + +#if TI_I2C_CONF_ENABLE + +I2CCC26XX_Object i2cCC26xxObjects[CC2650STK_I2CCOUNT]; + +const I2CCC26XX_HWAttrsV1 i2cCC26xxHWAttrs[CC2650STK_I2CCOUNT] = { +#if TI_I2C_CONF_I2C0_ENABLE + { + .baseAddr = I2C0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_I2C0, + .intNum = INT_I2C_IRQ, + .intPriority = ~0, + .swiPriority = 0, + .sdaPin = CC2650STK_I2C0_SDA0, + .sclPin = CC2650STK_I2C0_SCL0, + }, +#endif +}; + +const I2C_Config I2C_config[CC2650STK_I2CCOUNT] = { +#if TI_I2C_CONF_I2C0_ENABLE + { + .fxnTablePtr = &I2CCC26XX_fxnTable, + .object = &i2cCC26xxObjects[CC2650STK_I2C0], + .hwAttrs = &i2cCC26xxHWAttrs[CC2650STK_I2C0] + }, +#endif +}; + +const uint_least8_t I2C_count = CC2650STK_I2CCOUNT; + +#endif /* TI_I2C_CONF_ENABLE */ + +/* + * =============================== NVS =============================== + */ +#include +#include +#include + +#define NVS_REGIONS_BASE 0x1A000 +#define SECTORSIZE 0x1000 +#define REGIONSIZE (SECTORSIZE * 4) + +#if TI_NVS_CONF_ENABLE + +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + +/* + * Reserve flash sectors for NVS driver use by placing an uninitialized byte + * array at the desired flash address. + */ +#if defined(__TI_COMPILER_VERSION__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +#pragma LOCATION(flashBuf, NVS_REGIONS_BASE); +#pragma NOINIT(flashBuf); +static char flashBuf[REGIONSIZE]; + +#elif defined(__IAR_SYSTEMS_ICC__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +static __no_init char flashBuf[REGIONSIZE] @ NVS_REGIONS_BASE; + +#elif defined(__GNUC__) + +/* + * Place the flash buffers in the .nvs section created in the gcc linker file. + * The .nvs section enforces alignment on a sector boundary but may + * be placed anywhere in flash memory. If desired the .nvs section can be set + * to a fixed address by changing the following in the gcc linker file: + * + * .nvs (FIXED_FLASH_ADDR) (NOLOAD) : AT (FIXED_FLASH_ADDR) { + * *(.nvs) + * } > REGION_TEXT + */ +__attribute__ ((section (".nvs"))) +static char flashBuf[REGIONSIZE]; + +#endif + +NVSCC26XX_Object nvsCC26xxObjects[1]; + +/* Hardware attributes for NVS */ +const NVSCC26XX_HWAttrs nvsCC26xxHWAttrs[1] = { + { + .regionBase = (void *)flashBuf, + .regionSize = REGIONSIZE, + }, +}; + +#endif /* TI_NVS_CONF_NVS_INTERNAL_ENABLE */ + +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + +#define SPISECTORSIZE 0x1000 +#define SPIREGIONSIZE (SPISECTORSIZE * 32) +#define VERIFYBUFSIZE 64 + +static uint8_t verifyBuf[VERIFYBUFSIZE]; + +/* Allocate objects for NVS and NVS SPI */ +NVSSPI25X_Object nvsSPI25XObjects[1]; + +/* Hardware attributes for NVS SPI */ +const NVSSPI25X_HWAttrs nvsSPI25XHWAttrs[1] = { + { + .regionBaseOffset = 0, + .regionSize = SPIREGIONSIZE, + .sectorSize = SPISECTORSIZE, + .verifyBuf = verifyBuf, + .verifyBufSize = VERIFYBUFSIZE, + .spiHandle = NULL, + .spiIndex = 0, + .spiBitRate = 4000000, + .spiCsnGpioIndex = CC2650STK_GPIO_SPI_FLASH_CS, + }, +}; + +#endif /* Board_EXCLUDE_NVS_EXTERNAL_FLASH */ + +/* NVS Region index 0 and 1 refer to NVS and NVS SPI respectively */ +const NVS_Config NVS_config[CC2650STK_NVSCOUNT] = { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + { + .fxnTablePtr = &NVSCC26XX_fxnTable, + .object = &nvsCC26xxObjects[0], + .hwAttrs = &nvsCC26xxHWAttrs[0], + }, +#endif +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + { + .fxnTablePtr = &NVSSPI25X_fxnTable, + .object = &nvsSPI25XObjects[0], + .hwAttrs = &nvsSPI25XHWAttrs[0], + }, +#endif +}; + +const uint_least8_t NVS_count = CC2650STK_NVSCOUNT; + +#endif /* TI_NVS_CONF_ENABLE */ + +/* + * =============================== PDM =============================== +*/ +#include +#include + +PDMCC26XX_Object pdmCC26XXObjects[CC2650STK_PDMCOUNT]; +PDMCC26XX_I2S_Object pdmCC26XXI2SObjects[CC2650STK_PDMCOUNT]; + +const PDMCC26XX_HWAttrs pdmCC26XXHWAttrs[CC2650STK_PDMCOUNT] = { + { + .micPower = CC2650STK_MIC_POWER, + .taskPriority = 2 + } +}; + +const PDMCC26XX_Config PDMCC26XX_config[CC2650STK_PDMCOUNT] = { + { + .object = &pdmCC26XXObjects[CC2650STK_PDM0], + .hwAttrs = &pdmCC26XXHWAttrs[CC2650STK_PDM0] + } +}; + +const PDMCC26XX_I2S_HWAttrs pdmC26XXI2SHWAttrs[CC2650STK_PDMCOUNT] = { + { + .baseAddr = I2S0_BASE, + .intNum = INT_I2S_IRQ, + .powerMngrId = PowerCC26XX_PERIPH_I2S, + .intPriority = ~0, + .mclkPin = PIN_UNASSIGNED, + .bclkPin = CC2650STK_AUDIO_CLK, + .wclkPin = PIN_UNASSIGNED, + .ad0Pin = CC2650STK_AUDIO_DI, + } +}; + +const PDMCC26XX_I2S_Config PDMCC26XX_I2S_config[CC2650STK_PDMCOUNT] = { + { + .object = &pdmCC26XXI2SObjects[CC2650STK_PDM0], + .hwAttrs = &pdmC26XXI2SHWAttrs[CC2650STK_PDM0] + } +}; + +/* + * =============================== PIN =============================== + */ +#include +#include + +const PIN_Config BoardGpioInitTable[] = { + + CC2650STK_PIN_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC2650STK_KEY_LEFT | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC2650STK_KEY_RIGHT | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC2650STK_RELAY | PIN_INPUT_EN | PIN_PULLDOWN | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Relay is active high */ + CC2650STK_MPU_INT | PIN_INPUT_EN | PIN_PULLDOWN | PIN_IRQ_NEGEDGE | PIN_HYSTERESIS, /* MPU_INT is active low */ + CC2650STK_TMP_RDY | PIN_INPUT_EN | PIN_PULLUP | PIN_HYSTERESIS, /* TMP_RDY is active high */ + CC2650STK_BUZZER | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* Buzzer initially off */ + CC2650STK_MPU_POWER | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* MPU initially on */ + CC2650STK_MIC_POWER | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* MIC initially off */ + CC2650STK_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ + CC2650STK_SPI_DEVPK_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* DevPack chip select */ + CC2650STK_AUDIO_DI | PIN_INPUT_EN | PIN_PULLDOWN, /* Audio DI */ + CC2650STK_AUDIODO | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* Audio data out */ + CC2650STK_AUDIO_CLK | PIN_INPUT_EN | PIN_PULLDOWN, /* DevPack */ + CC2650STK_DP2 | PIN_INPUT_EN | PIN_PULLDOWN, /* DevPack */ + CC2650STK_DP1 | PIN_INPUT_EN | PIN_PULLDOWN, /* DevPack */ + CC2650STK_DP0 | PIN_INPUT_EN | PIN_PULLDOWN, /* DevPack */ + CC2650STK_DP3 | PIN_INPUT_EN | PIN_PULLDOWN, /* DevPack */ + CC2650STK_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* DevPack */ + CC2650STK_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* DevPack */ + CC2650STK_DEVPK_ID | PIN_INPUT_EN | PIN_NOPULL, /* Device pack ID - external PU */ + CC2650STK_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */ + CC2650STK_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */ + CC2650STK_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI clock */ + + PIN_TERMINATE +}; + +const PINCC26XX_HWAttrs PINCC26XX_hwAttrs = { + .intPriority = ~0, + .swiPriority = 0 +}; + +/* + * =============================== Power =============================== + */ +const PowerCC26XX_Config PowerCC26XX_config = { + .policyInitFxn = NULL, + .policyFxn = &PowerCC26XX_standbyPolicy, + .calibrateFxn = &PowerCC26XX_calibrate, + .enablePolicy = true, + .calibrateRCOSC_LF = true, + .calibrateRCOSC_HF = true, +}; + +/* + * =============================== PWM =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include +#include + +PWMTimerCC26XX_Object pwmtimerCC26xxObjects[CC2650STK_PWMCOUNT]; + +const PWMTimerCC26XX_HwAttrs pwmtimerCC26xxHWAttrs[CC2650STK_PWMCOUNT] = { + { .pwmPin = CC2650STK_PWMPIN0, .gpTimerUnit = CC2650STK_GPTIMER0A }, + { .pwmPin = CC2650STK_PWMPIN1, .gpTimerUnit = CC2650STK_GPTIMER0B }, + { .pwmPin = CC2650STK_PWMPIN2, .gpTimerUnit = CC2650STK_GPTIMER1A }, + { .pwmPin = CC2650STK_PWMPIN3, .gpTimerUnit = CC2650STK_GPTIMER1B }, + { .pwmPin = CC2650STK_PWMPIN4, .gpTimerUnit = CC2650STK_GPTIMER2A }, + { .pwmPin = CC2650STK_PWMPIN5, .gpTimerUnit = CC2650STK_GPTIMER2B }, + { .pwmPin = CC2650STK_PWMPIN6, .gpTimerUnit = CC2650STK_GPTIMER3A }, + { .pwmPin = CC2650STK_PWMPIN7, .gpTimerUnit = CC2650STK_GPTIMER3B }, +}; + +const PWM_Config PWM_config[CC2650STK_PWMCOUNT] = { + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC2650STK_PWM0], &pwmtimerCC26xxHWAttrs[CC2650STK_PWM0] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC2650STK_PWM1], &pwmtimerCC26xxHWAttrs[CC2650STK_PWM1] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC2650STK_PWM2], &pwmtimerCC26xxHWAttrs[CC2650STK_PWM2] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC2650STK_PWM3], &pwmtimerCC26xxHWAttrs[CC2650STK_PWM3] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC2650STK_PWM4], &pwmtimerCC26xxHWAttrs[CC2650STK_PWM4] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC2650STK_PWM5], &pwmtimerCC26xxHWAttrs[CC2650STK_PWM5] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC2650STK_PWM6], &pwmtimerCC26xxHWAttrs[CC2650STK_PWM6] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC2650STK_PWM7], &pwmtimerCC26xxHWAttrs[CC2650STK_PWM7] }, +}; + +const uint_least8_t PWM_count = CC2650STK_PWMCOUNT; + +/* + * =============================== RF Driver =============================== + */ +#include + +const RFCC26XX_HWAttrsV2 RFCC26XX_hwAttrs = { + .hwiPriority = ~0, /* Lowest HWI priority */ + .swiPriority = 0, /* Lowest SWI priority */ + .xoscHfAlwaysNeeded = true, /* Keep XOSC dependency while in stanby */ + .globalCallback = NULL, /* No board specific callback */ + .globalEventMask = 0 /* No events subscribed to */ +}; + +/* + * =============================== SPI DMA =============================== + */ +#include +#include + +#if TI_SPI_CONF_ENABLE + +SPICC26XXDMA_Object spiCC26XXDMAObjects[CC2650STK_SPICOUNT]; + +const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[CC2650STK_SPICOUNT] = { +#if TI_SPI_CONF_SPI0_ENABLE + { + .baseAddr = SSI0_BASE, + .intNum = INT_SSI0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .powerMngrId = PowerCC26XX_PERIPH_SSI0, + .defaultTxBufValue = 0, + .rxChannelBitMask = 1< +#include + +TRNGCC26X0_Object trngCC26X0Object[CC2650STK_TRNGCOUNT]; + +const TRNGCC26X0_HWAttrs trngCC26X0HWAttrs[CC2650STK_TRNGCOUNT] = { + { + .swiPriority = 0, + .intPriority = ~0, + } +}; + +const TRNG_Config TRNG_config[] = { + { &trngCC26X0Object[0], &trngCC26X0HWAttrs[0] }, +}; + +const uint8_t TRNG_count = CC2650STK_TRNGCOUNT; + + +/* + * =============================== UART =============================== + */ +#include +#include + +#if TI_UART_CONF_ENABLE + +UARTCC26XX_Object uartCC26XXObjects[CC2650STK_UARTCOUNT]; + +uint8_t uartCC26XXRingBuffer[CC2650STK_UARTCOUNT][32]; + +const UARTCC26XX_HWAttrsV2 uartCC26XXHWAttrs[CC2650STK_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .baseAddr = UART0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UART0, + .intNum = INT_UART0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .txPin = CC2650STK_UART_TX, + .rxPin = CC2650STK_UART_RX, + .ctsPin = PIN_UNASSIGNED, + .rtsPin = PIN_UNASSIGNED, + .ringBufPtr = uartCC26XXRingBuffer[CC2650STK_UART0], + .ringBufSize = sizeof(uartCC26XXRingBuffer[CC2650STK_UART0]), + .txIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_1_8, + .rxIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_4_8, + .errorFxn = NULL + }, +#endif +}; + +const UART_Config UART_config[CC2650STK_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .fxnTablePtr = &UARTCC26XX_fxnTable, + .object = &uartCC26XXObjects[CC2650STK_UART0], + .hwAttrs = &uartCC26XXHWAttrs[CC2650STK_UART0] + }, +#endif +}; + +const uint_least8_t UART_count = CC2650STK_UARTCOUNT; + +#endif /* TI_UART_CONF_ENABLE */ + +/* + * =============================== UDMA =============================== + */ +#include + +UDMACC26XX_Object udmaObjects[CC2650STK_UDMACOUNT]; + +const UDMACC26XX_HWAttrs udmaHWAttrs[CC2650STK_UDMACOUNT] = { + { + .baseAddr = UDMA0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UDMA, + .intNum = INT_DMA_ERR, + .intPriority = ~0 + } +}; + +const UDMACC26XX_Config UDMACC26XX_config[CC2650STK_UDMACOUNT] = { + { + .object = &udmaObjects[CC2650STK_UDMA0], + .hwAttrs = &udmaHWAttrs[CC2650STK_UDMA0] + }, +}; + +/* + * =============================== Watchdog =============================== + */ +#include +#include + +WatchdogCC26XX_Object watchdogCC26XXObjects[CC2650STK_WATCHDOGCOUNT]; + +const WatchdogCC26XX_HWAttrs watchdogCC26XXHWAttrs[CC2650STK_WATCHDOGCOUNT] = { + { + .baseAddr = WDT_BASE, + .reloadValue = 1000 /* Reload value in milliseconds */ + }, +}; + +const Watchdog_Config Watchdog_config[CC2650STK_WATCHDOGCOUNT] = { + { + .fxnTablePtr = &WatchdogCC26XX_fxnTable, + .object = &watchdogCC26XXObjects[CC2650STK_WATCHDOG0], + .hwAttrs = &watchdogCC26XXHWAttrs[CC2650STK_WATCHDOG0] + }, +}; + +const uint_least8_t Watchdog_count = CC2650STK_WATCHDOGCOUNT; + +/* + * Board-specific initialization function to disable external flash. + * This function is defined in the file CC2650STK_fxns.c + */ +extern void Board_initHook(void); + +/* + * ======== CC2650STK_initGeneral ======== + */ +void CC2650STK_initGeneral(void) +{ + Power_init(); + + if ( PIN_init(BoardGpioInitTable) != PIN_SUCCESS) { + /* Error with PIN_init */ + while (1); + } + + /* Perform board-specific initialization */ + Board_initHook(); +} diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/CC2650STK.h b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/CC2650STK.h new file mode 100644 index 000000000..17533f6cd --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/CC2650STK.h @@ -0,0 +1,348 @@ +/* + * Copyright (c) 2015-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 CC2650STK.h + * + * @brief CC2650STK Board Specific header file. + * + * The CC2650STK header file should be included in an application as + * follows: + * @code + * #include "CC2650STK.h" + * @endcode + * ============================================================================ + */ +#ifndef __CC2650STK_BOARD_H__ +#define __CC2650STK_BOARD_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "contiki-conf.h" + +/* Includes */ +#include +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) + +/* Externs */ +extern const PIN_Config BoardGpioInitTable[]; + +/* Defines */ +#define CC2650STK + +/* Mapping of pins to board signals using general board aliases + * + */ + +/* Audio */ +#define CC2650STK_MIC_POWER IOID_13 +#define CC2650STK_MIC_POWER_ON 1 +#define CC2650STK_MIC_POWER_OFF 0 +#define CC2650STK_AUDIO_DI IOID_2 +#define CC2650STK_AUDIO_CLK IOID_11 + +/* Buzzer */ +#define CC2650STK_BUZZER IOID_21 +#define CC2650STK_BUZZER_ON 1 +#define CC2650STK_BUZZER_OFF 0 + +/* DevPack */ +#define CC2650STK_AUDIOFS_TDO IOID_16 +#define CC2650STK_AUDIODO IOID_22 +#define CC2650STK_DP2 IOID_23 +#define CC2650STK_DP1 IOID_24 +#define CC2650STK_DP0 IOID_25 +#define CC2650STK_DP3 IOID_27 +#define CC2650STK_DP4_UARTRX IOID_28 +#define CC2650STK_DP5_UARTTX IOID_29 +#define CC2650STK_DEVPK_ID IOID_30 +#define CC2650STK_SPI_DEVPK_CS IOID_20 + +/* Discrete Outputs */ +#define CC2650STK_PIN_LED0 IOID_10 +#define CC2650STK_PIN_LED1 IOID_15 +#define CC2650STK_LED_ON 1 +#define CC2650STK_LED_OFF 0 + + +/* Discrete Inputs */ +#define CC2650STK_KEY_LEFT IOID_0 +#define CC2650STK_KEY_RIGHT IOID_4 +#define CC2650STK_RELAY IOID_3 + +/* GPIO */ +#define CC2650STK_GPIO_LED_ON 1 +#define CC2650STK_GPIO_LED_OFF 0 + +/* I2C */ +#define CC2650STK_I2C0_SDA0 IOID_5 +#define CC2650STK_I2C0_SCL0 IOID_6 +#define CC2650STK_I2C0_SDA1 IOID_8 +#define CC2650STK_I2C0_SCL1 IOID_9 + +/* LED-Audio DevPack */ +#define CC2650STK_DEVPK_LIGHT_BLUE IOID_23 +#define CC2650STK_DEVPK_LIGHT_GREEN IOID_24 +#define CC2650STK_DEVPK_LIGHT_WHITE IOID_25 +#define CC2650STK_DEVPK_LIGHT_RED IOID_27 + +/* Power */ +#define CC2650STK_MPU_POWER IOID_12 +#define CC2650STK_MPU_POWER_ON 1 +#define CC2650STK_MPU_POWER_OFF 0 + +/* PWM */ +#define CC2650STK_PWMPIN0 CC2650STK_PIN_LED1 +#define CC2650STK_PWMPIN1 CC2650STK_PIN_LED1 +#define CC2650STK_PWMPIN2 PIN_UNASSIGNED +#define CC2650STK_PWMPIN3 PIN_UNASSIGNED +#define CC2650STK_PWMPIN4 PIN_UNASSIGNED +#define CC2650STK_PWMPIN5 PIN_UNASSIGNED +#define CC2650STK_PWMPIN6 PIN_UNASSIGNED +#define CC2650STK_PWMPIN7 PIN_UNASSIGNED + +/* Sensors */ +#define CC2650STK_MPU_INT IOID_7 +#define CC2650STK_TMP_RDY IOID_1 + +/* SPI */ +#define CC2650STK_SPI_FLASH_CS IOID_14 +#define CC2650STK_FLASH_CS_ON 0 +#define CC2650STK_FLASH_CS_OFF 1 + +/* SPI Board */ +#define CC2650STK_SPI0_MISO IOID_18 +#define CC2650STK_SPI0_MOSI IOID_19 +#define CC2650STK_SPI0_CLK IOID_17 +#define CC2650STK_SPI0_CSN PIN_UNASSIGNED +#define CC2650STK_SPI1_MISO PIN_UNASSIGNED +#define CC2650STK_SPI1_MOSI PIN_UNASSIGNED +#define CC2650STK_SPI1_CLK PIN_UNASSIGNED +#define CC2650STK_SPI1_CSN PIN_UNASSIGNED + +/* UART */ +#define CC2650STK_UART_TX CC2650STK_DP5_UARTTX +#define CC2650STK_UART_RX CC2650STK_DP4_UARTRX + +/*! + * @brief Initialize the general board specific settings + * + * This function initializes the general board specific settings. + */ +void CC2650STK_initGeneral(void); + +/*! + * @brief Turn off the external flash on LaunchPads + * + */ +void CC2650STK_shutDownExtFlash(void); + +/*! + * @brief Wake up the external flash present on the board files + * + * This function toggles the chip select for the amount of time needed + * to wake the chip up. + */ +void CC2650STK_wakeUpExtFlash(void); + +/*! + * @def CC2650STK_CryptoName + * @brief Enum of Crypto names + */ +typedef enum CC2650STK_CryptoName { + CC2650STK_CRYPTO0 = 0, + + CC2650STK_CRYPTOCOUNT +} CC2650STK_CryptoName; + +/*! + * @def CC2650STK_GPIOName + * @brief Enum of GPIO names + */ +typedef enum CC2650STK_GPIOName { + CC2650STK_GPIO_S1 = 0, + CC2650STK_GPIO_S2, + CC2650STK_GPIO_LED0, + CC2650STK_GPIO_SPI_FLASH_CS, + + CC2650STK_GPIOCOUNT +} CC2650STK_GPIOName; + +/*! + * @def CC2650STK_GPTimerName + * @brief Enum of GPTimers parts + */ +typedef enum CC2650STK_GPTimerName { + CC2650STK_GPTIMER0A = 0, + CC2650STK_GPTIMER0B, + CC2650STK_GPTIMER1A, + CC2650STK_GPTIMER1B, + CC2650STK_GPTIMER2A, + CC2650STK_GPTIMER2B, + CC2650STK_GPTIMER3A, + CC2650STK_GPTIMER3B, + + CC2650STK_GPTIMERPARTSCOUNT +} CC2650STK_GPTimerName; + +/*! + * @def CC2650STK_GPTimers + * @brief Enum of GPTimers + */ +typedef enum CC2650STK_GPTimers { + CC2650STK_GPTIMER0 = 0, + CC2650STK_GPTIMER1, + CC2650STK_GPTIMER2, + CC2650STK_GPTIMER3, + + CC2650STK_GPTIMERCOUNT +} CC2650STK_GPTimers; + +/*! + * @def CC2650STK_I2CName + * @brief Enum of I2C names + */ +typedef enum CC2650STK_I2CName { +#if TI_I2C_CONF_I2C0_ENABLE + CC2650STK_I2C0 = 0, +#endif + + CC2650STK_I2CCOUNT +} CC2650STK_I2CName; + +/*! + * @def CC2650STK_NVSName + * @brief Enum of NVS names + */ +typedef enum CC2650STK_NVSName { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + CC2650STK_NVSCC26XX0 = 0, +#endif +#if TI_NVS_CONF_NVS_EXTERNAL_ENABLE + CC2650STK_NVSSPI25X0, +#endif + + CC2650STK_NVSCOUNT +} CC2650STK_NVSName; + +/*! + * @def CC2650STK_PDMName + * @brief Enum of PDM names + */ +typedef enum CC2650STK_PDMName { + CC2650STK_PDM0 = 0, + + CC2650STK_PDMCOUNT +} CC2650STK_PDMName; + +/*! + * @def CC2650STK_PWMName + * @brief Enum of PWM outputs + */ +typedef enum CC2650STK_PWMName { + CC2650STK_PWM0 = 0, + CC2650STK_PWM1, + CC2650STK_PWM2, + CC2650STK_PWM3, + CC2650STK_PWM4, + CC2650STK_PWM5, + CC2650STK_PWM6, + CC2650STK_PWM7, + + CC2650STK_PWMCOUNT +} CC2650STK_PWMName; + +/*! + * @def CC2650STK_SPIName + * @brief Enum of SPI names + */ +typedef enum CC2650STK_SPIName { +#if TI_SPI_CONF_SPI0_ENABLE + CC2650STK_SPI0 = 0, +#endif +#if TI_SPI_CONF_SPI1_ENABLE + CC2650STK_SPI1, +#endif + + CC2650STK_SPICOUNT +} CC2650STK_SPIName; + +/*! + * @def CC2650STK_TRNGName + * @brief Enum of TRNGs + */ +typedef enum CC2650STK_TRNGName { + CC2650STK_TRNG0 = 0, + + CC2650STK_TRNGCOUNT +} CC2650STK_TRNGName; + +/*! + * @def CC2650STK_UARTName + * @brief Enum of UARTs + */ +typedef enum CC2650STK_UARTName { +#if TI_UART_CONF_UART0_ENABLE + CC2650STK_UART0 = 0, +#endif + + + CC2650STK_UARTCOUNT +} CC2650STK_UARTName; + +/*! + * @def CC2650STK_UDMAName + * @brief Enum of DMA buffers + */ +typedef enum CC2650STK_UDMAName { + CC2650STK_UDMA0 = 0, + + CC2650STK_UDMACOUNT +} CC2650STK_UDMAName; + +/*! + * @def CC2650STK_WatchdogName + * @brief Enum of Watchdogs + */ +typedef enum CC2650STK_WatchdogName { + CC2650STK_WATCHDOG0 = 0, + + CC2650STK_WATCHDOGCOUNT +} CC2650STK_WatchdogName; + +#ifdef __cplusplus +} +#endif + +#endif /* __CC2650STK_BOARD_H__ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/CC2650STK_fxns.c b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/CC2650STK_fxns.c new file mode 100644 index 000000000..3312a1702 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/CC2650STK_fxns.c @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ +/* + * ====================== CC2650STK_fxns.c ========================================= + * This file contains the board-specific initialization functions. + */ + +#include +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/cpu.h) + +#include "Board.h" + +/* + * ======== CC2650STK_sendExtFlashByte ======== + */ +void CC2650STK_sendExtFlashByte(PIN_Handle pinHandle, uint8_t byte) +{ + uint8_t i; + + /* SPI Flash CS */ + PIN_setOutputValue(pinHandle, IOID_14, 0); + + for (i = 0; i < 8; i++) { + PIN_setOutputValue(pinHandle, IOID_17, 0); /* SPI Flash CLK */ + + /* SPI Flash MOSI */ + PIN_setOutputValue(pinHandle, IOID_19, (byte >> (7 - i)) & 0x01); + PIN_setOutputValue(pinHandle, IOID_17, 1); + + /* + * Waste a few cycles to keep the CLK high for at + * least 45% of the period. + * 3 cycles per loop: 8 loops @ 48 Mhz = 0.5 us. + */ + CPUdelay(8); + } + + PIN_setOutputValue(pinHandle, IOID_17, 0); + PIN_setOutputValue(pinHandle, IOID_14, 1); + + /* + * Keep CS high at least 40 us + * 3 cycles per loop: 700 loops @ 48 Mhz ~= 44 us + */ + CPUdelay(700); +} + +/* + * ======== CC2650STK_wakeUpExtFlash ======== + */ +void CC2650STK_wakeUpExtFlash(void) +{ + PIN_Config extFlashPinTable[] = { + IOID_14 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + PIN_TERMINATE + }; + PIN_State extFlashPinState; + PIN_Handle extFlashPinHandle = PIN_open(&extFlashPinState, extFlashPinTable); + + /* + * To wake up we need to toggle the chip select at + * least 20 ns and ten wait at least 35 us. + */ + + /* Toggle chip select for ~20ns to wake ext. flash */ + PIN_setOutputValue(extFlashPinHandle, IOID_14, 0); + /* 3 cycles per loop: 1 loop @ 48 Mhz ~= 62 ns */ + CPUdelay(1); + PIN_setOutputValue(extFlashPinHandle, IOID_14, 1); + /* 3 cycles per loop: 560 loops @ 48 Mhz ~= 35 us */ + CPUdelay(560); + + PIN_close(extFlashPinHandle); +} + +/* + * ======== CC2650STK_shutDownExtFlash ======== + */ +void CC2650STK_shutDownExtFlash(void) +{ + /* + * To be sure we are putting the flash into sleep and not waking it, + * we first have to make a wake up call + */ + CC2650STK_wakeUpExtFlash(); + + PIN_Config extFlashPinTable[] = { + /* SPI Flash CS*/ + IOID_14 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash CLK */ + IOID_17 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash MOSI */ + IOID_19 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | + PIN_INPUT_DIS | PIN_DRVSTR_MED, + /* SPI Flash MISO */ + IOID_18 | PIN_INPUT_EN | PIN_PULLDOWN, + PIN_TERMINATE + }; + PIN_State extFlashPinState; + PIN_Handle extFlashPinHandle = PIN_open(&extFlashPinState, extFlashPinTable); + + uint8_t extFlashShutdown = 0xB9; + + CC2650STK_sendExtFlashByte(extFlashPinHandle, extFlashShutdown); + + PIN_close(extFlashPinHandle); +} + +/* + * ======== Board_initHook ======== + * Called by Board_init() to perform board-specific initialization. + */ +void Board_initHook() +{ + CC2650STK_shutDownExtFlash(); +} diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/Makefile.cc2650 b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/Makefile.cc2650 new file mode 100644 index 000000000..d5b3303ba --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/Makefile.cc2650 @@ -0,0 +1,22 @@ +################################################################################ +# SimpleLink Device makefile + +SUBFAMILY = cc13x0-cc26x0 +DEVICE_FAMILY = CC26X0 +DEVICE_LINE = CC26XX +DEVICE = CC2650 + +BOARD_SOURCEFILES += CC2650STK.c CC2650STK_fxns.c +BOARD_SOURCEFILES += leds-arch.c + +SUPPORTS_PROP_MODE = 0 +SUPPORTS_IEEE_MODE = 1 +SUPPORTS_BLE_BEACON = 1 + +SUPPORTS_HIGH_PA = 0 + +### Signal that we can be programmed with cc2538-bsl +BOARD_SUPPORTS_BSL = 1 + +# Include the common board makefile +include $(FAMILY_PATH)/sensortag/Makefile.sensortag diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/leds-arch.c b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/leds-arch.c new file mode 100644 index 000000000..97b2ca597 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/leds-arch.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup sensortag-peripherals + * @{ + * + * \file + * LED HAL definitions for the CC2650STK LEDs. Is not compatible with + * the CC1350STK. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/leds.h" +/*---------------------------------------------------------------------------*/ +#include +/*---------------------------------------------------------------------------*/ +#include +/*---------------------------------------------------------------------------*/ +const leds_t leds_arch_leds[] = { + /* Red LED, AKA LED0 */ + { .pin = Board_PIN_LED0, .negative_logic = false }, + /* Green LED, AKA LED1 */ + { .pin = Board_PIN_LED1, .negative_logic = false }, +}; +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/leds-arch.h b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/leds-arch.h new file mode 100644 index 000000000..fcb89bd69 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/cc2650/leds-arch.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** \addtogroup sensortag-peripherals + * @{ + * + * \file + * LED HAL definitions for the CC1350STK LEDs. Is not compatible with + * the CC2650STK. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#ifndef LEDS_ARCH_H_ +#define LEDS_ARCH_H_ +/*---------------------------------------------------------------------------*/ +/** + * \name LED configurations for the dev/leds.h API. + * + * Those values are not meant to be modified by the user + * @{ + */ +#define LEDS_CONF_COUNT 2 + +#define LEDS_CONF_RED 0 +#define LEDS_CONF_GREEN 1 + +#define LEDS_CONF_ALL ((1 << LEDS_CONF_COUNT) - 1) +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* LEDS_ARCH_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/hdc-1000-sensor.c b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/hdc-1000-sensor.c new file mode 100644 index 000000000..85840605d --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/hdc-1000-sensor.c @@ -0,0 +1,354 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup sensortag-hdc-sensor + * @{ + * + * \file + * Driver for the Sensortag HDC1000 sensor. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "sys/ctimer.h" +#include "lib/sensors.h" +/*---------------------------------------------------------------------------*/ +#include "board-conf.h" +#include "hdc-1000-sensor.h" +/*---------------------------------------------------------------------------*/ +#include + +#include +/*---------------------------------------------------------------------------*/ +#include +#include +#include +#include +/*---------------------------------------------------------------------------*/ +#define DEBUG 0 +#if DEBUG +#define PRINTF(...) printf(__VA_ARGS__) +#else +#define PRINTF(...) +#endif +/*---------------------------------------------------------------------------*/ +/* + * Disable the entire file if sensors are disabled, as it could potentially + * create compile errors with missing defines from either the Board file or + * configuration defines. + */ +#if BOARD_SENSORS_ENABLE +/*---------------------------------------------------------------------------*/ +#ifndef Board_HDC1000_ADDR +#error "Board file doesn't define the I2C address Board_HDC1000_ADDR" +#endif +/* Sensor I2C address */ +#define HDC1000_I2C_ADDRESS Board_HDC1000_ADDR +/*---------------------------------------------------------------------------*/ +/* Registers */ +#define HDC1000_REG_TEMP 0x00 /* Temperature */ +#define HDC1000_REG_HUM 0x01 /* Humidity */ +#define HDC1000_REG_CONFIG 0x02 /* Configuration */ +#define HDC1000_REG_SERID_H 0xFB /* Serial ID high */ +#define HDC1000_REG_SERID_M 0xFC /* Serial ID middle */ +#define HDC1000_REG_SERID_L 0xFD /* Serial ID low */ +#define HDC1000_REG_MANF_ID 0xFE /* Manufacturer ID */ +#define HDC1000_REG_DEV_ID 0xFF /* Device ID */ +/*---------------------------------------------------------------------------*/ +/* Fixed values */ +#define HDC1000_VAL_MANF_ID 0x5449 +#define HDC1000_VAL_DEV_ID 0x1000 +#define HDC1000_VAL_CONFIG 0x1000 /* 14 bit, acquired in sequence */ +/*---------------------------------------------------------------------------*/ +/* Byte swap of 16-bit register value */ +#define HI_UINT16(a) (((a) >> 8) & 0xFF) +#define LO_UINT16(a) ((a) & 0xFF) + +#define SWAP16(v) ((LO_UINT16(v) << 8) | HI_UINT16(v)) + +#define LSB16(v) (LO_UINT16(v)), (HI_UINT16(v)) +/*---------------------------------------------------------------------------*/ +static I2C_Handle i2c_handle; +/*---------------------------------------------------------------------------*/ +/* Raw data as returned from the sensor (Big Endian) */ +typedef struct { + uint16_t temp; + uint16_t hum; +} HDC_1000_SensorData; + +static HDC_1000_SensorData sensor_data; +/*---------------------------------------------------------------------------*/ +static volatile HDC_1000_SENSOR_STATUS sensor_status = HDC_1000_SENSOR_STATUS_DISABLED; +/*---------------------------------------------------------------------------*/ +/* + * Maximum measurement durations in clock ticks. We use 14bit resolution, thus: + * - Tmp: 6.35ms + * - RH: 6.5ms + */ +#define MEASUREMENT_DURATION 2 + +/* + * Wait SENSOR_STARTUP_DELAY clock ticks between activation and triggering a + * reading (max 15ms) + */ +#define SENSOR_STARTUP_DELAY 3 + +static struct ctimer startup_timer; +/*---------------------------------------------------------------------------*/ +/** + * \brief Setup and peform an I2C transaction. + * \param wbuf Output buffer during the I2C transation. + * \param wcount How many bytes in the wbuf. + * \param rbuf Input buffer during the I2C transation. + * \param rcount How many bytes to read into rbuf. + * \return true if the I2C operation was successful; + * else, return false. + */ +static bool +i2c_write_read(void *wbuf, size_t wcount, void *rbuf, size_t rcount) +{ + I2C_Transaction i2c_transaction = { + .writeBuf = wbuf, + .writeCount = wcount, + .readBuf = rbuf, + .readCount = rcount, + .slaveAddress = HDC1000_I2C_ADDRESS, + }; + + return I2C_transfer(i2c_handle, &i2c_transaction); +} +/** + * \brief Peform a write only I2C transaction. + * \param wbuf Output buffer during the I2C transation. + * \param wcount How many bytes in the wbuf. + * \return true if the I2C operation was successful; + * else, return false. + */ +static inline bool +i2c_write(void *wbuf, size_t wcount) +{ + return i2c_write_read(wbuf, wcount, NULL, 0); +} +/** + * \brief Peform a read only I2C transaction. + * \param rbuf Input buffer during the I2C transation. + * \param rcount How many bytes to read into rbuf. + * \return true if the I2C operation was successful; + * else, return false. + */ +static inline bool +i2c_read(void *rbuf, size_t rcount) +{ + return i2c_write_read(NULL, 0, rbuf, rcount); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Initialize the HDC-1000 sensor driver. + * \return true if I2C operation successful; else, return false. + */ +static bool +sensor_init(void) +{ + if(i2c_handle) { + return true; + } + + I2C_Params i2c_params; + I2C_Params_init(&i2c_params); + + i2c_params.transferMode = I2C_MODE_BLOCKING; + i2c_params.bitRate = I2C_400kHz; + + i2c_handle = I2C_open(Board_I2C0, &i2c_params); + if(i2c_handle == NULL) { + return false; + } + + /* Enable reading data in one operation */ + uint8_t config_data[] = { HDC1000_REG_CONFIG, LSB16(HDC1000_VAL_CONFIG) }; + + return i2c_write(config_data, sizeof(config_data)); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Start measurement. + * \return true if I2C operation successful; else, return false. + */ +static bool +start(void) +{ + uint8_t temp_reg[] = { HDC1000_REG_TEMP }; + + return i2c_write(temp_reg, sizeof(temp_reg)); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Convert raw data to temperature and humidity. + * \param temp Output variable to store converted temperature. + * \param hum Output variable to store converted humidity. + */ +static void +convert(int32_t *temp, int32_t *hum) +{ + int32_t raw_temp = SWAP16(sensor_data.temp); + int32_t raw_hum = SWAP16(sensor_data.hum); + + /* Convert temperature to degrees C */ + *temp = raw_temp * 100 * 165 / 65536 - 40000; + /* Convert relative humidity to a %RH value */ + *hum = raw_hum * 100 * 100 / 65536; +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Callback when sensor is ready to read data from. + */ +static void +notify_ready(void *unused) +{ + /* Unused args */ + (void)unused; + + /* Latch readings */ + if(i2c_read(&sensor_data, sizeof(sensor_data))) { + sensor_status = HDC_1000_SENSOR_STATUS_READINGS_READY; + } else { + sensor_status = HDC_1000_SENSOR_STATUS_I2C_ERROR; + } + + sensors_changed(&hdc_1000_sensor); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Returns a reading from the sensor. + * \param type HDC_1000_SENSOR_TYPE_TEMP or HDC_1000_SENSOR_TYPE_HUMID. + * \return Temperature (centi degrees C) or Humidity (centi %RH). + */ +static int +value(int type) +{ + int32_t temp = 0; + int32_t hum = 0; + + if(sensor_status != HDC_1000_SENSOR_STATUS_READINGS_READY) { + PRINTF("Sensor disabled or starting up (%d)\n", sensor_status); + return HDC_1000_READING_ERROR; + } + + switch(type) { + case HDC_1000_SENSOR_TYPE_TEMP: + case HDC_1000_SENSOR_TYPE_HUMID: + convert(&temp, &hum); + PRINTF("HDC: t=%d h=%d\n", (int)temp, (int)hum); + + if(type == HDC_1000_SENSOR_TYPE_TEMP) { + return (int)temp; + } else if(type == HDC_1000_SENSOR_TYPE_HUMID) { + return (int)hum; + } else { + return HDC_1000_READING_ERROR; + } + + default: + PRINTF("Invalid type\n"); + return HDC_1000_READING_ERROR; + } +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Configuration function for the HDC1000 sensor. + * \param type Activate, enable or disable the sensor. See below. + * \param enable Either enable or disable the sensor. + * When type == SENSORS_HW_INIT we turn on the hardware. + * When type == SENSORS_ACTIVE and enable==1 we enable the sensor. + * When type == SENSORS_ACTIVE and enable==0 we disable the sensor. + */ +static int +configure(int type, int enable) +{ + switch(type) { + case SENSORS_HW_INIT: + memset(&sensor_data, 0, sizeof(sensor_data)); + + if(sensor_init()) { + sensor_status = HDC_1000_SENSOR_STATUS_INITIALISED; + } else { + sensor_status = HDC_1000_SENSOR_STATUS_I2C_ERROR; + } + break; + + case SENSORS_ACTIVE: + /* Must be initialised first */ + if(sensor_status == HDC_1000_SENSOR_STATUS_DISABLED) { + break; + } + + if(enable) { + if(!start()) { + sensor_status = HDC_1000_SENSOR_STATUS_I2C_ERROR; + break; + } + ctimer_set(&startup_timer, SENSOR_STARTUP_DELAY, notify_ready, NULL); + sensor_status = HDC_1000_SENSOR_STATUS_TAKING_READINGS; + } else { + ctimer_stop(&startup_timer); + sensor_status = HDC_1000_SENSOR_STATUS_INITIALISED; + } + break; + + default: + break; + } + return sensor_status; +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Returns the status of the sensor. + * \param type SENSORS_ACTIVE or SENSORS_READY. + * \return One of the SENSOR_STATUS_xyz defines. + */ +static int +status(int type) +{ + switch(type) { + case SENSORS_ACTIVE: + case SENSORS_READY: + return sensor_status; + + default: + return HDC_1000_SENSOR_STATUS_DISABLED; + } +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(hdc_1000_sensor, "HDC1000", value, configure, status); +/*---------------------------------------------------------------------------*/ +#endif /* BOARD_SENSORS_ENABLE */ +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/hdc-1000-sensor.h b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/hdc-1000-sensor.h new file mode 100644 index 000000000..4dcab02c2 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/hdc-1000-sensor.h @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup sensortag-peripherals + * @{ + * + * \defgroup sensortag-hdc-sensor SensorTag HDC1000 - Temperature and + * Humidity Sensor + * + * Due to the time required for the sensor to startup, this driver is meant to + * be used in an asynchronous fashion. The caller must first activate the + * sensor by calling SENSORS_ACTIVATE(). This will trigger the sensor's startup + * sequence, but the call will not wait for it to complete so that the CPU can + * perform other tasks or drop to a low power mode. Once the sensor has taken + * readings, it will automatically go back to low power mode. + * + * Once the sensor is stable, the driver will retrieve readings from the sensor + * and latch them. It will then generate a sensors_changed event. + * + * The user can then retrieve readings by calling .value() and by passing + * either HDC_1000_SENSOR_TYPE_TEMP or HDC_1000_SENSOR_TYPE_HUMID as the + * argument. Multiple calls to value() will not trigger new readings, they will + * simply return the most recent latched values. + * + * The user can query the sensor's status by calling status(). + * + * To get a fresh reading, the user must trigger a new reading cycle by calling + * SENSORS_ACTIVATE(). + * @{ + * + * \file + * Header file for the Sensortag HDC1000 sensor. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#ifndef HDC_1000_SENSOR_H +#define HDC_1000_SENSOR_H +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "lib/sensors.h" +/*---------------------------------------------------------------------------*/ +#include "board-conf.h" +/*---------------------------------------------------------------------------*/ +#if BOARD_SENSORS_ENABLE +#if (TI_I2C_CONF_ENABLE == 0) || (TI_I2C_CONF_I2C0_ENABLE == 0) +#error "The HDC-1000 requires the I2C driver (TI_I2C_CONF_ENABLE = 1)" +#endif +#endif +/*---------------------------------------------------------------------------*/ +typedef enum { + HDC_1000_SENSOR_TYPE_TEMP, + HDC_1000_SENSOR_TYPE_HUMID +} HDC_1000_SENSOR_TYPE; +/*---------------------------------------------------------------------------*/ +/** + * \name HDC1000 driver states + * @{ + */ +typedef enum { + HDC_1000_SENSOR_STATUS_DISABLED, /**< Not initialised */ + HDC_1000_SENSOR_STATUS_INITIALISED, /**< Initialised but idle */ + HDC_1000_SENSOR_STATUS_TAKING_READINGS, /**< Readings in progress */ + HDC_1000_SENSOR_STATUS_I2C_ERROR, /**< I2C transaction failed */ + HDC_1000_SENSOR_STATUS_READINGS_READY /**< Both readings ready */ +} HDC_1000_SENSOR_STATUS; +/** @} */ +/*---------------------------------------------------------------------------*/ +#define HDC_1000_READING_ERROR -1 +/*---------------------------------------------------------------------------*/ +extern const struct sensors_sensor hdc_1000_sensor; +/*---------------------------------------------------------------------------*/ +#endif /* HDC_1000_SENSOR_H */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/mpu-9250-sensor.c b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/mpu-9250-sensor.c new file mode 100644 index 000000000..8842d4177 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/mpu-9250-sensor.c @@ -0,0 +1,659 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup sensortag-mpu + * @{ + * + * \file + * Driver for the Sensortag Invensense MPU9250 motion processing unit + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "lib/sensors.h" +#include "sys/rtimer.h" +/*---------------------------------------------------------------------------*/ +#include "board-conf.h" +#include "mpu-9250-sensor.h" +/*---------------------------------------------------------------------------*/ +#include + +#include +#include DeviceFamily_constructPath(driverlib/cpu.h) + +#include +#include +/*---------------------------------------------------------------------------*/ +#include +#include +#include +#include +/*---------------------------------------------------------------------------*/ +#define DEBUG 0 +#if DEBUG +#define PRINTF(...) printf(__VA_ARGS__) +#else +#define PRINTF(...) +#endif +/*---------------------------------------------------------------------------*/ +/* + * Disable the entire file if sensors are disabled, as it could potentially + * create compile errors with missing defines from either the Board file or + * configuration defines. + */ +#if BOARD_SENSORS_ENABLE +/*---------------------------------------------------------------------------*/ +#ifndef Board_MPU9250_ADDR +#error "Board file doesn't define I2C address Board_MPU9250_ADDR" +#endif +#ifndef Board_MPU9250_MAG_ADDR +#error "Board file doesn't define I2C address Board_MPU9250_MAG_ADDR" +#endif + +/* Sensor I2C address */ +#define MPU_9250_I2C_ADDRESS Board_MPU9250_ADDR +#define MPU_9250_MAG_I2C_ADDRESS Board_MPU9250_MAG_ADDR +/*-------------a--------------------------------------------------------------*/ +/* Self Test Registers */ +#define REG_SELF_TEST_X_GYRO 0x00 /* R/W */ +#define REG_SELF_TEST_Y_GYRO 0x01 /* R/W */ +#define REG_SELF_TEST_Z_GYRO 0x02 /* R/W */ +#define REG_SELF_TEST_X_ACCEL 0x0D /* R/W */ +#define REG_SELF_TEST_Z_ACCEL 0x0E /* R/W */ +#define REG_SELF_TEST_Y_ACCEL 0x0F /* R/W */ +/*---------------------------------------------------------------------------*/ +/* Axis Registers */ +#define REG_XG_OFFSET_H 0x13 /* R/W */ +#define REG_XG_OFFSET_L 0x14 /* R/W */ +#define REG_YG_OFFSET_H 0x15 /* R/W */ +#define REG_YG_OFFSET_L 0x16 /* R/W */ +#define REG_ZG_OFFSET_H 0x17 /* R/W */ +#define REG_ZG_OFFSET_L 0x18 /* R/W */ +/*---------------------------------------------------------------------------*/ +/* Control Registers */ +#define REG_SMPLRT_DIV 0x19 /* R/W */ +#define REG_CONFIG 0x1A /* R/W */ +#define REG_GYRO_CONFIG 0x1B /* R/W */ +#define REG_ACCEL_CONFIG 0x1C /* R/W */ +#define REG_ACCEL_CONFIG_2 0x1D /* R/W */ +#define REG_LP_ACCEL_ODR 0x1E /* R/W */ +#define REG_WOM_THR 0x1F /* R/W */ +#define REG_FIFO_EN 0x23 /* R/W */ +/*---------------------------------------------------------------------------*/ +/* + * Registers 0x24 - 0x36 are not applicable to the SensorTag HW configuration + * (IC2 Master) + */ +#define REG_INT_PIN_CFG 0x37 /* R/W */ +#define REG_INT_ENABLE 0x38 /* R/W */ +#define REG_INT_STATUS 0x3A /* R */ +#define REG_ACCEL_XOUT_H 0x3B /* R */ +#define REG_ACCEL_XOUT_L 0x3C /* R */ +#define REG_ACCEL_YOUT_H 0x3D /* R */ +#define REG_ACCEL_YOUT_L 0x3E /* R */ +#define REG_ACCEL_ZOUT_H 0x3F /* R */ +#define REG_ACCEL_ZOUT_L 0x40 /* R */ +#define REG_TEMP_OUT_H 0x41 /* R */ +#define REG_TEMP_OUT_L 0x42 /* R */ +#define REG_GYRO_XOUT_H 0x43 /* R */ +#define REG_GYRO_XOUT_L 0x44 /* R */ +#define REG_GYRO_YOUT_H 0x45 /* R */ +#define REG_GYRO_YOUT_L 0x46 /* R */ +#define REG_GYRO_ZOUT_H 0x47 /* R */ +#define REG_GYRO_ZOUT_L 0x48 /* R */ +/*---------------------------------------------------------------------------*/ +/* + * Registers 0x49 - 0x60 are not applicable to the SensorTag HW configuration + * (external sensor data) + * + * Registers 0x63 - 0x67 are not applicable to the SensorTag HW configuration + * (I2C master) + */ +#define REG_SIG_PATH_RST 0x68 /* R/W */ +#define REG_ACC_INTEL_CTRL 0x69 /* R/W */ +#define REG_USER_CTRL 0x6A /* R/W */ +#define REG_PWR_MGMT_1 0x6B /* R/W */ +#define REG_PWR_MGMT_2 0x6C /* R/W */ +#define REG_FIFO_COUNT_H 0x72 /* R/W */ +#define REG_FIFO_COUNT_L 0x73 /* R/W */ +#define REG_FIFO_R_W 0x74 /* R/W */ +#define REG_WHO_AM_I 0x75 /* R/W */ +/*---------------------------------------------------------------------------*/ +/* Masks is mpuConfig valiable */ +#define ACC_CONFIG_MASK 0x38 +#define GYRO_CONFIG_MASK 0x07 +/*---------------------------------------------------------------------------*/ +/* Values PWR_MGMT_1 */ +#define PWR_MGMT_1_VAL_MPU_SLEEP 0x4F /* Sleep + stop all clocks */ +#define PWR_MGMT_1_VAL_MPU_WAKE_UP 0x09 /* Disable temp. + intern osc */ +/*---------------------------------------------------------------------------*/ +/* Values PWR_MGMT_2 */ +#define PWR_MGMT_2_VAL_ALL_AXES 0x3F +#define PWR_MGMT_2_VAL_GYRO_AXES 0x07 +#define PWR_MGMT_2_VAL_ACC_AXES 0x38 +/*---------------------------------------------------------------------------*/ +/* Output data rates */ +#define INV_LPA_0_3125HZ 0 +#define INV_LPA_0_625HZ 1 +#define INV_LPA_1_25HZ 2 +#define INV_LPA_2_5HZ 3 +#define INV_LPA_5HZ 4 +#define INV_LPA_10HZ 5 +#define INV_LPA_20HZ 6 +#define INV_LPA_40HZ 7 +#define INV_LPA_80HZ 8 +#define INV_LPA_160HZ 9 +#define INV_LPA_320HZ 10 +#define INV_LPA_640HZ 11 +#define INV_LPA_STOPPED 255 +/*---------------------------------------------------------------------------*/ +/* Bit values */ +#define BIT_ANY_RD_CLR 0x10 +#define BIT_RAW_RDY_EN 0x01 +#define BIT_WOM_EN 0x40 +#define BIT_LPA_CYCLE 0x20 +#define BIT_STBY_XA 0x20 +#define BIT_STBY_YA 0x10 +#define BIT_STBY_ZA 0x08 +#define BIT_STBY_XG 0x04 +#define BIT_STBY_YG 0x02 +#define BIT_STBY_ZG 0x01 +#define BIT_STBY_XYZA (BIT_STBY_XA | BIT_STBY_YA | BIT_STBY_ZA) +#define BIT_STBY_XYZG (BIT_STBY_XG | BIT_STBY_YG | BIT_STBY_ZG) +/*---------------------------------------------------------------------------*/ +static PIN_Config mpu_9250_pin_table[] = { + Board_MPU_INT | PIN_INPUT_EN | PIN_PULLDOWN | PIN_HYSTERESIS, + Board_MPU_POWER | PIN_GPIO_OUTPUT_EN | PIN_DRVSTR_MAX | PIN_GPIO_LOW, + PIN_TERMINATE +}; + +static PIN_State pin_state; +static PIN_Handle pin_handle; +static I2C_Handle i2c_handle; + +/*---------------------------------------------------------------------------*/ +typedef struct { + volatile MPU_9250_SENSOR_STATUS status; + volatile MPU_9250_SENSOR_TYPE type; + MPU_9250_SENSOR_ACC_RANGE acc_range; +} MPU_9250_Object; + +static MPU_9250_Object mpu_9250; +/*---------------------------------------------------------------------------*/ +/* 3 16-byte words for all sensor readings */ +#define SENSOR_DATA_BUF_SIZE 3 +/* Data sizes */ +#define DATA_SIZE 6 +/*---------------------------------------------------------------------------*/ +/* + * Wait SENSOR_BOOT_DELAY ticks for the sensor to boot and + * SENSOR_STARTUP_DELAY for readings to be ready + * Gyro is a little slower than Acc + */ +#define SENSOR_BOOT_DELAY 8 +#define SENSOR_STARTUP_DELAY 5 + +static struct ctimer startup_timer; +/*---------------------------------------------------------------------------*/ + +/* + * Wait timeout in rtimer ticks. This is just a random low number, since the + * first time we read the sensor status, it should be ready to return data + */ +#define READING_WAIT_TIMEOUT 10 +/*---------------------------------------------------------------------------*/ +/* Code in flash, cache disabled: 7 cycles per loop */ +/* ui32Count = [delay in us] * [CPU clock in MHz] / [cycles per loop] */ +#define delay_ms(ms) CPUdelay((ms) * 1000 * 48 / 7) +/*---------------------------------------------------------------------------*/ +/** + * \brief Setup and peform an I2C transaction. + * \param wbuf Output buffer during the I2C transation. + * \param wcount How many bytes in the wbuf. + * \param rbuf Input buffer during the I2C transation. + * \param rcount How many bytes to read into rbuf. + * \return true if the I2C operation was successful; + * else, return false. + */ +static bool +i2c_write_read(void *wbuf, size_t wcount, void *rbuf, size_t rcount) +{ + I2C_Transaction i2c_transaction = { + .writeBuf = wbuf, + .writeCount = wcount, + .readBuf = rbuf, + .readCount = rcount, + .slaveAddress = MPU_9250_I2C_ADDRESS, + }; + + return I2C_transfer(i2c_handle, &i2c_transaction); +} +/** + * \brief Peform a write only I2C transaction. + * \param wbuf Output buffer during the I2C transation. + * \param wcount How many bytes in the wbuf. + * \return true if the I2C operation was successful; + * else, return false. + */ +static inline bool +i2c_write(void *wbuf, size_t wcount) +{ + return i2c_write_read(wbuf, wcount, NULL, 0); +} +/** + * \brief Peform a read only I2C transaction. + * \param rbuf Input buffer during the I2C transation. + * \param rcount How many bytes to read into rbuf. + * \return true if the I2C operation was successful; + * else, return false. + */ +static inline bool +i2c_read(void *rbuf, size_t rcount) +{ + return i2c_write_read(NULL, 0, rbuf, rcount); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Initialize the MPU-9250 sensor driver. + * \return true if I2C operation successful; else, return false. + */ +static bool +sensor_init(void) +{ + pin_handle = PIN_open(&pin_state, mpu_9250_pin_table); + if(pin_handle == NULL) { + return false; + } + + I2C_Params i2cParams; + I2C_Params_init(&i2cParams); + i2cParams.transferMode = I2C_MODE_BLOCKING; + i2cParams.bitRate = I2C_400kHz; + + i2c_handle = I2C_open(Board_I2C0, &i2cParams); + if(i2c_handle == NULL) { + PIN_close(&pin_state); + return false; + } + + mpu_9250.type = MPU_9250_SENSOR_TYPE_NONE; + mpu_9250.status = MPU_9250_SENSOR_STATUS_DISABLED; + mpu_9250.acc_range = MPU_9250_SENSOR_ACC_RANGE_ARG; + + return true; +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Place the sensor in low-power mode. + */ +static void +sensor_sleep(void) +{ + { + uint8_t all_axes_data[] = { REG_PWR_MGMT_2, PWR_MGMT_2_VAL_ALL_AXES }; + i2c_write(all_axes_data, sizeof(all_axes_data)); + } + { + uint8_t mpu_sleep_data[] = { REG_PWR_MGMT_1, PWR_MGMT_1_VAL_MPU_SLEEP }; + i2c_write(mpu_sleep_data, sizeof(mpu_sleep_data)); + } +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Wakeup the sensor from low-power mode. + */ +static void +sensor_wakeup(void) +{ + { + uint8_t mpu_wakeup_data[] = { REG_PWR_MGMT_1, PWR_MGMT_1_VAL_MPU_WAKE_UP }; + i2c_write(mpu_wakeup_data, sizeof(mpu_wakeup_data)); + } + { + /* All axis initially disabled */ + uint8_t all_axes_data[] = { REG_PWR_MGMT_2, PWR_MGMT_2_VAL_ALL_AXES }; + i2c_write(all_axes_data, sizeof(all_axes_data)); + } + { + /* Restore the range */ + uint8_t accel_cfg_data[] = { REG_ACCEL_CONFIG, mpu_9250.acc_range }; + i2c_write(accel_cfg_data, sizeof(accel_cfg_data)); + } + { + /* Clear interrupts */ + uint8_t int_status_data[] = { REG_INT_STATUS }; + uint8_t dummy; + i2c_write_read(int_status_data, sizeof(int_status_data), &dummy, 1); + } +} +/*---------------------------------------------------------------------------*/ +static void +sensor_set_acc_range(MPU_9250_SENSOR_ACC_RANGE acc_range) +{ + /* Apply the range */ + uint8_t accel_cfg_data[] = { REG_ACCEL_CONFIG, acc_range }; + i2c_write(accel_cfg_data, sizeof(accel_cfg_data)); +} +/*---------------------------------------------------------------------------*/ +static void +sensor_set_axes(MPU_9250_SENSOR_TYPE sensor_type) +{ + uint8_t _data[] = { REG_PWR_MGMT_2, ~(uint8_t)sensor_type }; + i2c_write(_data, sizeof(_data)); +} +/*---------------------------------------------------------------------------*/ +static void +convert_to_le(uint8_t *data, uint8_t len) +{ + int i; + for(i = 0; i < len; i += 2) { + uint8_t tmp; + tmp = data[i]; + data[i] = data[i + 1]; + data[i + 1] = tmp; + } +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Check whether a data or wake on motion interrupt has occurred. + * \return Return the interrupt status. + * + * This driver does not use interrupts, however this function allows + * us to determine whether a new sensor reading is available. + */ +static bool +sensor_data_ready(uint8_t *int_status) +{ + uint8_t int_status_data[] = { REG_INT_STATUS }; + const bool spi_ok = i2c_write_read(int_status_data, sizeof(int_status_data), int_status, 1); + + return spi_ok && (*int_status != 0); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Read data from the accelerometer, total of 3 words (X, Y, Z). + * \return true if a valid reading could be taken; otherwise, false. + */ +static bool +acc_read(uint8_t int_status, uint16_t *data) +{ + if(!(int_status & BIT_RAW_RDY_EN)) { + return false; + } + + /* Burst read of all accelerometer values */ + uint8_t accel_xout_h[] = { REG_ACCEL_XOUT_H }; + bool spi_ok = i2c_write_read(accel_xout_h, sizeof(accel_xout_h), data, DATA_SIZE); + if(!spi_ok) { + return false; + } + + convert_to_le((uint8_t *)data, DATA_SIZE); + + return true; +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Read data from the accelerometer, total of 3 words (X, Y, Z). + * \return true if a valid reading could be taken; otherwise, false. + */ +static bool +gyro_read(uint8_t int_status, uint16_t *data) +{ + if(!(int_status & BIT_RAW_RDY_EN)) { + return false; + } + + /* Burst read of all accelerometer values */ + uint8_t gyro_xout_h[] = { REG_GYRO_XOUT_H }; + bool spi_ok = i2c_write_read(gyro_xout_h, sizeof(gyro_xout_h), data, DATA_SIZE); + if(!spi_ok) { + return false; + } + + convert_to_le((uint8_t *)data, DATA_SIZE); + + return true; +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Convert accelerometer raw reading to a value in G. + * \param raw_data The raw accelerometer reading. + * \return The converted value. + */ +static int32_t +acc_convert(int32_t raw_data) +{ + switch(mpu_9250.acc_range) { + case MPU_9250_SENSOR_ACC_RANGE_2G: return raw_data * 100 * 2 / 32768; + case MPU_9250_SENSOR_ACC_RANGE_4G: return raw_data * 100 * 4 / 32768; + case MPU_9250_SENSOR_ACC_RANGE_8G: return raw_data * 100 * 8 / 32768; + case MPU_9250_SENSOR_ACC_RANGE_16G: return raw_data * 100 * 16 / 32768; + } + return 0; +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Convert gyro raw reading to a value in deg/sec. + * \param raw_data The raw accelerometer reading. + * \return The converted value. + */ +static int32_t +gyro_convert(int32_t raw_data) +{ + /* calculate rotation, unit deg/s, range -250, +250 */ + return raw_data * 100 * 500 / 65536; +} +/*---------------------------------------------------------------------------*/ +static void +notify_ready_cb(void *unused) +{ + (void)unused; + + mpu_9250.status = MPU_9250_SENSOR_STATUS_READY; + sensors_changed(&mpu_9250_sensor); +} +/*---------------------------------------------------------------------------*/ +static void +initialise_cb(void *unused) +{ + (void)unused; + + if(mpu_9250.type == MPU_9250_SENSOR_TYPE_NONE) { + return; + } + + /* Wake up the sensor */ + sensor_wakeup(); + + /* Configure the accelerometer range */ + if((mpu_9250.type & MPU_9250_SENSOR_TYPE_ACC) != 0) { + sensor_set_acc_range(mpu_9250.acc_range); + } + + /* Enable gyro + accelerometer readout */ + sensor_set_axes(mpu_9250.type); + delay_ms(10); + + ctimer_set(&startup_timer, SENSOR_STARTUP_DELAY, notify_ready_cb, NULL); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Returns a reading from the sensor. + * \param type MPU_9250_SENSOR_TYPE_ACC_[XYZ] or + * MPU_9250_SENSOR_TYPE_GYRO_[XYZ]. + * \return Centi-G (ACC) or centi-Deg/Sec (Gyro). + */ +static int +value(int type) +{ + if(mpu_9250.status == MPU_9250_SENSOR_STATUS_DISABLED) { + PRINTF("MPU: Sensor Disabled\n"); + return MPU_9250_READING_ERROR; + } + + if(mpu_9250.type == MPU_9250_SENSOR_TYPE_NONE) { + return MPU_9250_READING_ERROR; + } + + uint8_t int_status = 0; + const rtimer_clock_t t0 = RTIMER_NOW(); + while(!sensor_data_ready(&int_status)) { + if(!(RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + READING_WAIT_TIMEOUT))) { + return MPU_9250_READING_ERROR; + } + } + + uint16_t sensor_value[SENSOR_DATA_BUF_SIZE]; + memset(sensor_value, 0, sizeof(sensor_value)); + + /* Read accel data */ + if((type & MPU_9250_SENSOR_TYPE_ACC) != 0) { + + if(!acc_read(int_status, sensor_value)) { + return MPU_9250_READING_ERROR; + } + + PRINTF("MPU: ACC = 0x%04x 0x%04x 0x%04x = ", + sensor_value[0], sensor_value[1], sensor_value[2]); + + /* Convert */ + switch(type) { + case MPU_9250_SENSOR_TYPE_ACC_X: return acc_convert(sensor_value[0]); + case MPU_9250_SENSOR_TYPE_ACC_Y: return acc_convert(sensor_value[1]); + case MPU_9250_SENSOR_TYPE_ACC_Z: return acc_convert(sensor_value[2]); + default: return MPU_9250_READING_ERROR; + } + + /* Read gyro data */ + } else if((type & MPU_9250_SENSOR_TYPE_GYRO) != 0) { + + if(!gyro_read(int_status, sensor_value)) { + return MPU_9250_READING_ERROR; + } + + PRINTF("MPU: Gyro = 0x%04x 0x%04x 0x%04x = ", + sensor_value[0], sensor_value[1], sensor_value[2]); + + /* Convert */ + switch(type) { + case MPU_9250_SENSOR_TYPE_GYRO_X: return gyro_convert(sensor_value[0]); + case MPU_9250_SENSOR_TYPE_GYRO_Y: return gyro_convert(sensor_value[1]); + case MPU_9250_SENSOR_TYPE_GYRO_Z: return gyro_convert(sensor_value[2]); + default: return MPU_9250_READING_ERROR; + } + + /* Invalid sensor type */ + } else { + PRINTF("MPU: Invalid type\n"); + return MPU_9250_READING_ERROR; + } +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Configuration function for the MPU9250 sensor. + * \param type Activate, enable or disable the sensor. See below. + * \param enable Enable or disable sensor. + * When type == SENSORS_HW_INIT we turn on the hardware. + * When type == SENSORS_ACTIVE and enable==1 we enable the sensor. + * When type == SENSORS_ACTIVE and enable==0 we disable the sensor. + */ +static int +configure(int type, int enable) +{ + /* Mask enable */ + const MPU_9250_SENSOR_TYPE enable_type = enable & MPU_9250_SENSOR_TYPE_ALL; + + switch(type) { + case SENSORS_HW_INIT: + if(sensor_init()) { + mpu_9250.status = MPU_9250_SENSOR_STATUS_ENABLED; + } else { + mpu_9250.status = MPU_9250_SENSOR_STATUS_DISABLED; + } + break; + + case SENSORS_ACTIVE: + if(enable_type != MPU_9250_SENSOR_TYPE_NONE) { + PRINTF("MPU: Enabling\n"); + + mpu_9250.type = enable_type; + mpu_9250.status = MPU_9250_SENSOR_STATUS_BOOTING; + + PIN_setOutputValue(pin_handle, Board_MPU_POWER, 1); + + ctimer_set(&startup_timer, SENSOR_BOOT_DELAY, initialise_cb, NULL); + } else { + PRINTF("MPU: Disabling\n"); + + ctimer_stop(&startup_timer); + + if(PIN_getOutputValue(Board_MPU_POWER)) { + sensor_sleep(); + + I2C_cancel(i2c_handle); + PIN_setOutputValue(pin_handle, Board_MPU_POWER, 0); + } + + mpu_9250.type = MPU_9250_SENSOR_TYPE_NONE; + mpu_9250.status = MPU_9250_SENSOR_STATUS_DISABLED; + } + break; + + default: + break; + } + return mpu_9250.status; +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Returns the status of the sensor + * \param type SENSORS_ACTIVE or SENSORS_READY + * \return 1 if the sensor is enabled, else 0. + */ +static int +status(int type) +{ + switch(type) { + case SENSORS_ACTIVE: + case SENSORS_READY: + return mpu_9250.status; + + default: + return MPU_9250_SENSOR_STATUS_DISABLED; + } +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(mpu_9250_sensor, "MPU9250", value, configure, status); +/*---------------------------------------------------------------------------*/ +#endif /* BOARD_SENSORS_ENABLE */ +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/mpu-9250-sensor.h b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/mpu-9250-sensor.h new file mode 100644 index 000000000..d66e91977 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/mpu-9250-sensor.h @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup sensortag-peripherals + * @{ + * + * \defgroup sensortag-mpu SensorTag Motion Processing Unit + * + * Driver for the Invensense MPU-9250 Motion Processing Unit. + * + * Due to the time required between triggering a reading and the + * reading becoming available, this driver is meant to be used in an + * asynchronous fashion. The caller must first activate the sensor by + * calling + * + * mpu_9250_sensor.configure(SENSORS_ACTIVE, xyz); + * + * The value for the xyz arguments depends on the required readings. If + * the caller intends to read both the accelerometer as well as the gyro + * then xyz should be MPU_9250_SENSOR_TYPE_ALL. If the caller only needs + * to take a reading from one of the two elements, xyz should be one of + * MPU_9250_SENSOR_TYPE_ACC or MPU_9250_SENSOR_TYPE_GYRO + * + * Calling configure() will power up the sensor and initialise it. When + * the sensor is ready to provide readings, the driver will generate a + * sensors_changed event. + * + * Calls to status() will return the driver's state which could indicate + * that the sensor is off, booting or on. + * + * Once a reading has been taken, the caller has two options: + * - Turn the sensor off by calling SENSORS_DEACTIVATE, but in order to + * take subsequent readings the sensor must be started up all over + * - Leave the sensor on. In this scenario, the caller can simply keep + * calling value() for subsequent readings, but having the sensor on + * will consume more energy, especially if both accelerometer and the + * gyro are on. + * @{ + * + * \file + * Header file for the Sensortag Invensense MPU-9250 motion processing unit + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#ifndef MPU_9250_SENSOR_H_ +#define MPU_9250_SENSOR_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +/*---------------------------------------------------------------------------*/ +#include "board-conf.h" +/*---------------------------------------------------------------------------*/ +#if BOARD_SENSORS_ENABLE +#if (TI_I2C_CONF_ENABLE == 0) || (TI_I2C_CONF_I2C0_ENABLE == 0) +#error "The MPU-9250 requires the I2C driver (TI_I2C_CONF_ENABLE = 1)" +#endif +#endif +/*---------------------------------------------------------------------------*/ +#define MPU_9250_READING_ERROR -1 +/*---------------------------------------------------------------------------*/ +/* Accelerometer / Gyro Axes */ +typedef enum { + MPU_9250_SENSOR_TYPE_NONE = (0), /**< 0b000000 = 0x00 */ + MPU_9250_SENSOR_TYPE_GYRO_X = (1 << 0), /**< 0b000001 = 0x01 */ + MPU_9250_SENSOR_TYPE_GYRO_Y = (1 << 1), /**< 0b000010 = 0x02 */ + MPU_9250_SENSOR_TYPE_GYRO_Z = (1 << 2), /**< 0b000100 = 0x04 */ + MPU_9250_SENSOR_TYPE_ACC_X = (1 << 3), /**< 0b001000 = 0x08 */ + MPU_9250_SENSOR_TYPE_ACC_Y = (1 << 4), /**< 0b010000 = 0x10 */ + MPU_9250_SENSOR_TYPE_ACC_Z = (1 << 5), /**< 0b100000 = 0x20 */ + MPU_9250_SENSOR_TYPE_GYRO = MPU_9250_SENSOR_TYPE_GYRO_X + | MPU_9250_SENSOR_TYPE_GYRO_Y + | MPU_9250_SENSOR_TYPE_GYRO_Z, + /**< 0b000111 = 0x07 */ + MPU_9250_SENSOR_TYPE_ACC = MPU_9250_SENSOR_TYPE_ACC_X + | MPU_9250_SENSOR_TYPE_ACC_Y + | MPU_9250_SENSOR_TYPE_ACC_Z, + /**< 0b111000 = 0x38 */ + MPU_9250_SENSOR_TYPE_ALL = MPU_9250_SENSOR_TYPE_GYRO + | MPU_9250_SENSOR_TYPE_ACC + /**< 0b111111 = 0x3F */ +} MPU_9250_SENSOR_TYPE; +/*---------------------------------------------------------------------------*/ +/* Accelerometer range */ +typedef enum { + MPU_9250_SENSOR_ACC_RANGE_2G = 0, + MPU_9250_SENSOR_ACC_RANGE_4G = 1, + MPU_9250_SENSOR_ACC_RANGE_8G = 2, + MPU_9250_SENSOR_ACC_RANGE_16G = 3 +} MPU_9250_SENSOR_ACC_RANGE; +/*---------------------------------------------------------------------------*/ +/* Sensor status */ +typedef enum { + MPU_9250_SENSOR_STATUS_DISABLED, + MPU_9250_SENSOR_STATUS_ENABLED, + MPU_9250_SENSOR_STATUS_BOOTING, + MPU_9250_SENSOR_STATUS_READY +} MPU_9250_SENSOR_STATUS; +/*---------------------------------------------------------------------------*/ +/* Accelerometer range configuration, type MPU_9250_SENSOR_ACC_RANGE */ +#ifdef MPU_9250_SENSOR_CONF_ACC_RANGE_ARG +#define MPU_9250_SENSOR_ACC_RANGE_ARG MPU_9250_SENSOR_CONF_ACC_RANGE +#else +#define MPU_9250_SENSOR_ACC_RANGE_ARG MPU_9250_SENSOR_ACC_RANGE_2G +#endif +/*---------------------------------------------------------------------------*/ +extern const struct sensors_sensor mpu_9250_sensor; +/*---------------------------------------------------------------------------*/ +#endif /* MPU_9250_SENSOR_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/opt-3001-sensor.c b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/opt-3001-sensor.c new file mode 100644 index 000000000..885fefe88 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/opt-3001-sensor.c @@ -0,0 +1,376 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup sensortag-opt-sensor + * @{ + * + * \file + * Driver for the Sensortag OPT-3001 light sensor. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "lib/sensors.h" +#include "sys/ctimer.h" +/*---------------------------------------------------------------------------*/ +#include "board-conf.h" +#include "opt-3001-sensor.h" +/*---------------------------------------------------------------------------*/ +#include + +#include +/*---------------------------------------------------------------------------*/ +#include +#include +#include +#include +/*---------------------------------------------------------------------------*/ +#define DEBUG 0 +#if DEBUG +#define PRINTF(...) printf(__VA_ARGS__) +#else +#define PRINTF(...) +#endif +/*---------------------------------------------------------------------------*/ +/* + * Disable the entire file if sensors are disabled, as it could potentially + * create compile errors with missing defines from either the Board file or + * configuration defines. + */ +#if BOARD_SENSORS_ENABLE +/*---------------------------------------------------------------------------*/ +#ifndef Board_OPT3001_ADDR +#error "Board file doesn't define I2C address Board_OPT3001_ADDR" +#endif +/* Slave address */ +#define OPT_3001_I2C_ADDRESS Board_OPT3001_ADDR +/*---------------------------------------------------------------------------*/ +/* Register addresses */ +#define REG_RESULT 0x00 +#define REG_CONFIGURATION 0x01 +#define REG_LOW_LIMIT 0x02 +#define REG_HIGH_LIMIT 0x03 + +#define REG_MANUFACTURER_ID 0x7E +#define REG_DEVICE_ID 0x7F +/*---------------------------------------------------------------------------*/ +/* + * Configuration Register Bits and Masks. + * We use uint16_t to read from / write to registers, meaning that the + * register's MSB is the variable's LSB. + */ +#define CFG_RN 0x00F0 /**< [15..12] Range Number */ +#define CFG_CT 0x0008 /**< [11] Conversion Time */ +#define CFG_M 0x0006 /**< [10..9] Mode of Conversion */ +#define CFG_OVF 0x0001 /**< [8] Overflow */ +#define CFG_CRF 0x8000 /**< [7] Conversion Ready Field */ +#define CFG_FH 0x4000 /**< [6] Flag High */ +#define CFG_FL 0x2000 /**< [5] Flag Low */ +#define CFG_L 0x1000 /**< [4] Latch */ +#define CFG_POL 0x0800 /**< [3] Polarity */ +#define CFG_ME 0x0400 /**< [2] Mask Exponent */ +#define CFG_FC 0x0300 /**< [1..0] Fault Count */ +/*---------------------------------------------------------------------------*/ +/* Possible Values for CT */ +#define CFG_CT_100 0x0000 +#define CFG_CT_800 CFG_CT +/*---------------------------------------------------------------------------*/ +/* Possible Values for M */ +#define CFG_M_CONTI 0x0004 +#define CFG_M_SINGLE 0x0002 +#define CFG_M_SHUTDOWN 0x0000 +/*---------------------------------------------------------------------------*/ +/* Reset Value for the register 0xC810. All zeros except: */ +#define CFG_RN_RESET 0x00C0 +#define CFG_CT_RESET CFG_CT_800 +#define CFG_L_RESET 0x1000 +#define CFG_DEFAULTS (CFG_RN_RESET | CFG_CT_100 | CFG_L_RESET) +/*---------------------------------------------------------------------------*/ +/* Enable / Disable */ +#define CFG_ENABLE_CONTINUOUS (CFG_M_CONTI | CFG_DEFAULTS) +#define CFG_ENABLE_SINGLE_SHOT (CFG_M_SINGLE | CFG_DEFAULTS) +#define CFG_DISABLE CFG_DEFAULTS +/*---------------------------------------------------------------------------*/ +/* Register length */ +#define REGISTER_LENGTH 2 +/*---------------------------------------------------------------------------*/ +/* Sensor data size */ +#define DATA_LENGTH 2 +/*---------------------------------------------------------------------------*/ +/* Byte swap of 16-bit register value */ +#define HI_UINT16(a) (((a) >> 8) & 0xFF) +#define LO_UINT16(a) (((a) >> 0) & 0xFF) + +#define SWAP16(v) ((LO_UINT16(v) << 8) | (HI_UINT16(v) << 0)) + +#define LSB16(v) (LO_UINT16(v)), (HI_UINT16(v)) +#define MSB16(v) (HI_UINT16(v)), (LO_UINT16(v)) +/*---------------------------------------------------------------------------*/ +typedef struct { + volatile OPT_3001_STATUS status; +} OPT_3001_Object; + +static OPT_3001_Object opt_3001; +/*---------------------------------------------------------------------------*/ +/* Wait SENSOR_STARTUP_DELAY for the sensor to be ready - 125ms */ +#define SENSOR_STARTUP_DELAY (CLOCK_SECOND >> 3) + +static struct ctimer startup_timer; +/*---------------------------------------------------------------------------*/ +static I2C_Handle i2c_handle; +/*---------------------------------------------------------------------------*/ +/** + * \brief Setup and peform an I2C transaction. + * \param wbuf Output buffer during the I2C transation. + * \param wcount How many bytes in the wbuf. + * \param rbuf Input buffer during the I2C transation. + * \param rcount How many bytes to read into rbuf. + * \return true if the I2C operation was successful; + * else, return false. + */ +static bool +i2c_write_read(void *wbuf, size_t wcount, void *rbuf, size_t rcount) +{ + I2C_Transaction i2c_transaction = { + .writeBuf = wbuf, + .writeCount = wcount, + .readBuf = rbuf, + .readCount = rcount, + .slaveAddress = OPT_3001_I2C_ADDRESS, + }; + + return I2C_transfer(i2c_handle, &i2c_transaction); +} +/** + * \brief Peform a write only I2C transaction. + * \param wbuf Output buffer during the I2C transation. + * \param wcount How many bytes in the wbuf. + * \return true if the I2C operation was successful; + * else, return false. + */ +static inline bool +i2c_write(void *wbuf, size_t wcount) +{ + return i2c_write_read(wbuf, wcount, NULL, 0); +} +/** + * \brief Peform a read only I2C transaction. + * \param rbuf Input buffer during the I2C transation. + * \param rcount How many bytes to read into rbuf. + * \return true if the I2C operation was successful; + * else, return false. + */ +static inline bool +i2c_read(void *rbuf, size_t rcount) +{ + return i2c_write_read(NULL, 0, rbuf, rcount); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Initialize the OPT-3001 sensor driver. + * \return true if I2C operation successful; else, return false. + */ +static bool +sensor_init(void) +{ + if(i2c_handle) { + return true; + } + + I2C_Params i2c_params; + I2C_Params_init(&i2c_params); + + i2c_params.transferMode = I2C_MODE_BLOCKING; + i2c_params.bitRate = I2C_400kHz; + + i2c_handle = I2C_open(Board_I2C0, &i2c_params); + if(i2c_handle == NULL) { + return false; + } + + opt_3001.status = OPT_3001_STATUS_DISABLED; + + return true; +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Turn the sensor on/off + * \param enable Enable sensor if true; else, disable sensor. + */ +static bool +sensor_enable(bool enable) +{ + uint16_t data = (enable) + ? CFG_ENABLE_SINGLE_SHOT + : CFG_DISABLE; + + uint8_t cfg_data[] = { REG_CONFIGURATION, LSB16(data) }; + return i2c_write(cfg_data, sizeof(cfg_data)); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Callback when sensor is ready to read data from. + */ +static void +notify_ready_cb(void *unused) +{ + /* Unused args */ + (void)unused; + + /* + * Depending on the CONFIGURATION.CONVERSION_TIME bits, a conversion will + * take either 100 or 800 ms. Here we inspect the CONVERSION_READY bit and + * if the reading is ready we notify, otherwise we just reschedule ourselves + */ + + uint8_t cfg_data[] = { REG_CONFIGURATION }; + uint16_t cfg_value = 0; + + bool spi_ok = i2c_write_read(cfg_data, sizeof(cfg_data), &cfg_value, sizeof(cfg_value)); + if(!spi_ok) { + opt_3001.status = OPT_3001_STATUS_I2C_ERROR; + return; + } + + if(cfg_value & CFG_CRF) { + opt_3001.status = OPT_3001_STATUS_DATA_READY; + sensors_changed(&opt_3001_sensor); + } else { + ctimer_set(&startup_timer, SENSOR_STARTUP_DELAY, notify_ready_cb, NULL); + } +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Returns a reading from the sensor. + * \param type Ignored. + * \return Illuminance in centilux. + */ +static int +value(int type) +{ + /* Unused args */ + (void)type; + + if(opt_3001.status != OPT_3001_STATUS_DATA_READY) { + return OPT_3001_READING_ERROR; + } + + uint8_t cfg_data[] = { REG_CONFIGURATION }; + uint16_t cfg_value = 0; + + bool spi_ok = i2c_write_read(cfg_data, sizeof(cfg_data), &cfg_value, sizeof(cfg_value)); + if(!spi_ok) { + opt_3001.status = OPT_3001_STATUS_I2C_ERROR; + return OPT_3001_READING_ERROR; + } + + uint8_t result_data[] = { REG_RESULT }; + uint16_t result_value = 0; + + spi_ok = i2c_write_read(result_data, sizeof(result_data), &result_value, sizeof(result_value)); + if(!spi_ok) { + opt_3001.status = OPT_3001_STATUS_I2C_ERROR; + return OPT_3001_READING_ERROR; + } + + result_value = SWAP16(result_value); + + uint32_t e = (result_value & 0x0FFF) >> 0; + uint32_t m = (result_value & 0xF000) >> 12; + uint32_t converted = m * 100 * (1 << e); + + PRINTF("OPT: %04X r=%d (centilux)\n", result_value, + (int)(converted)); + + return (int)converted; +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Configuration function for the OPT3001 sensor. + * \param type Activate, enable or disable the sensor. See below. + * \param enable Enable or disable sensor. + * + * When type == SENSORS_HW_INIT we turn on the hardware. + * When type == SENSORS_ACTIVE and enable==1 we enable the sensor. + * When type == SENSORS_ACTIVE and enable==0 we disable the sensor. + */ +static int +configure(int type, int enable) +{ + int rv = 0; + switch(type) { + case SENSORS_HW_INIT: + if(sensor_init()) { + opt_3001.status = OPT_3001_STATUS_STANDBY; + } else { + opt_3001.status = OPT_3001_STATUS_DISABLED; + rv = OPT_3001_READING_ERROR; + } + break; + + case SENSORS_ACTIVE: + if(enable) { + sensor_enable(true); + ctimer_set(&startup_timer, SENSOR_STARTUP_DELAY, notify_ready_cb, NULL); + + opt_3001.status = OPT_3001_STATUS_BOOTING; + } else { + ctimer_stop(&startup_timer); + sensor_enable(false); + } + break; + + default: + break; + } + + return rv; +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Returns the status of the sensor. + * \param type Ignored. + * \return The state of the sensor SENSOR_STATE_xyz. + */ +static int +status(int type) +{ + /* Unused args */ + (void)type; + + return opt_3001.status; +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(opt_3001_sensor, "OPT3001", value, configure, status); +/*---------------------------------------------------------------------------*/ +#endif /* BOARD_SENSORS_ENABLE */ +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/opt-3001-sensor.h b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/opt-3001-sensor.h new file mode 100644 index 000000000..221ea041f --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/opt-3001-sensor.h @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup sensortag-peripherals + * @{ + * + * \defgroup sensortag-opt-sensor SensorTag Optical Sensor + * + * Due to the time required for the sensor to startup, this driver is + * meant to be used in an asynchronous fashion. The caller must first + * activate the sensor by calling SENSORS_ACTIVATE(). This will trigger + * the sensor's startup sequence, but the call will not wait for it to + * complete so that the CPU can perform other tasks or drop to a low + * power mode. + * + * Once the reading and conversion are complete, the driver will + * generate a sensors_changed event. + * + * We use single-shot readings. In this mode, the hardware + * automatically goes back to its shutdown mode after the conversion + * is finished. However, it will still respond to I2C operations, so + * the last conversion can still be read out. + * + * In order to take a new reading, the caller has to use + * SENSORS_ACTIVATE again. + * @{ + * + * \file + * Header file for the Sensortag OPT-3001 light sensor. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#ifndef OPT_3001_SENSOR_H_ +#define OPT_3001_SENSOR_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +/*---------------------------------------------------------------------------*/ +#include "board-conf.h" +/*---------------------------------------------------------------------------*/ +#if BOARD_SENSORS_ENABLE +#if (TI_I2C_CONF_ENABLE == 0) || (TI_I2C_CONF_I2C0_ENABLE == 0) +#error "The OPT-3001 requires the I2C driver (TI_I2C_CONF_ENABLE = 1)" +#endif +#endif +/*---------------------------------------------------------------------------*/ +#define OPT_3001_READING_ERROR -1 +/*---------------------------------------------------------------------------*/ +typedef enum { + OPT_3001_STATUS_DISABLED, + OPT_3001_STATUS_STANDBY, + OPT_3001_STATUS_BOOTING, + OPT_3001_STATUS_ACTIVE, + OPT_3001_STATUS_DATA_READY, + OPT_3001_STATUS_I2C_ERROR, +} OPT_3001_STATUS; +/*---------------------------------------------------------------------------*/ +extern const struct sensors_sensor opt_3001_sensor; +/*---------------------------------------------------------------------------*/ +#endif /* OPT_3001_SENSOR_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/sensortag-sensors.c b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/sensortag-sensors.c new file mode 100644 index 000000000..d2da9fa8f --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/sensortag-sensors.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup sensortag-peripherals + * @{ + * + * \file + * Generic module controlling sensors on SensorTag. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "lib/sensors.h" +/*---------------------------------------------------------------------------*/ +#include "board-conf.h" +#include "board-peripherals.h" +/*---------------------------------------------------------------------------*/ +/* Exports a global symbol to be used by the sensor API */ +#if BOARD_SENSORS_ENABLE +SENSORS(&bmp_280_sensor, &tmp_007_sensor, &opt_3001_sensor, &hdc_1000_sensor, &mpu_9250_sensor); +#endif +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/tmp-007-sensor.c b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/tmp-007-sensor.c new file mode 100644 index 000000000..7e08006ea --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/tmp-007-sensor.c @@ -0,0 +1,420 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup sensortag-tmp-sensor + * @{ + * + * \file + * Driver for the Sensortag TI TMP-007 IR Thermophile sensor. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "lib/sensors.h" +#include "sys/ctimer.h" +/*---------------------------------------------------------------------------*/ +#include "board-conf.h" +#include "tmp-007-sensor.h" +/*---------------------------------------------------------------------------*/ +#include + +#include +#include +/*---------------------------------------------------------------------------*/ +#include +#include +#include +/*---------------------------------------------------------------------------*/ +#define DEBUG 0 +#if DEBUG +#define PRINTF(...) printf(__VA_ARGS__) +#else +#define PRINTF(...) +#endif +/*---------------------------------------------------------------------------*/ +/* + * Disable the entire file if sensors are disabled, as it could potentially + * create compile errors with missing defines from either the Board file or + * configuration defines. + */ +#if BOARD_SENSORS_ENABLE +/*---------------------------------------------------------------------------*/ +/* Slave address */ +#ifndef Board_TMP_ADDR +#error "Board file doesn't define I2C address Board_TMP_ADDR" +#endif +#define TMP_007_I2C_ADDRESS Board_TMP_ADDR + +/* Sensor Interrupt pin */ +#ifndef Board_TMP_RDY +#error "Board file doesn't define interrupt pin Board_TMP_RDY" +#endif +#define TMP_007_TMP_RDY Board_TMP_RDY +/*---------------------------------------------------------------------------*/ +/* TMP-007 register addresses */ +#define REG_VOLTAGE 0x00 +#define REG_LOCAL_TEMP 0x01 +#define REG_CONFIG 0x02 +#define REG_OBJ_TEMP 0x03 +#define REG_STATUS 0x04 +#define REG_PROD_ID 0x1F +/*---------------------------------------------------------------------------*/ +/* TMP-007 register values */ +#define VAL_CONFIG_ON 0x1000 /**< Sensor on state */ +#define VAL_CONFIG_OFF 0x0000 /**< Sensor off state */ +#define VAL_CONFIG_RESET 0x8000 +#define VAL_PROD_ID 0x0078 /**< Product ID */ +/*---------------------------------------------------------------------------*/ +/* Conversion ready (status register) bit values */ +#define CONV_RDY_BIT 0x4000 +/*---------------------------------------------------------------------------*/ +/* Register length */ +#define REGISTER_LENGTH 2 +/*---------------------------------------------------------------------------*/ +/* Sensor data size */ +#define DATA_SIZE 4 +/*---------------------------------------------------------------------------*/ +/* Byte swap of 16-bit register value */ +#define HI_UINT16(a) (((a) >> 8) & 0xFF) +#define LO_UINT16(a) (((a) >> 0) & 0xFF) + +#define SWAP16(v) ((LO_UINT16(v) << 8) | (HI_UINT16(v) << 0)) + +#define LSB16(v) (LO_UINT16(v)), (HI_UINT16(v)) +#define MSB16(v) (HI_UINT16(v)), (LO_UINT16(v)) +/*---------------------------------------------------------------------------*/ +static const PIN_Config pin_table[] = { + TMP_007_TMP_RDY | PIN_INPUT_EN | PIN_PULLUP | PIN_HYSTERESIS | PIN_IRQ_NEGEDGE, + PIN_TERMINATE +}; + +static PIN_State pin_state; +static PIN_Handle pin_handle; + +static I2C_Handle i2c_handle; +/*---------------------------------------------------------------------------*/ +typedef struct { + TMP_007_TYPE type; + volatile TMP_007_STATUS status; + uint16_t local_tmp_latched; + uint16_t obj_tmp_latched; +} TMP_007_Object; + +static TMP_007_Object tmp_007; +/*---------------------------------------------------------------------------*/ +/* Wait SENSOR_STARTUP_DELAY clock ticks for the sensor to be ready - 275ms */ +#define SENSOR_STARTUP_DELAY 36 + +static struct ctimer startup_timer; +/*---------------------------------------------------------------------------*/ +/** + * \brief Setup and peform an I2C transaction. + * \param wbuf Output buffer during the I2C transation. + * \param wcount How many bytes in the wbuf. + * \param rbuf Input buffer during the I2C transation. + * \param rcount How many bytes to read into rbuf. + * \return true if the I2C operation was successful; + * else, return false. + */ +static bool +i2c_write_read(void *wbuf, size_t wcount, void *rbuf, size_t rcount) +{ + I2C_Transaction i2c_transaction = { + .writeBuf = wbuf, + .writeCount = wcount, + .readBuf = rbuf, + .readCount = rcount, + .slaveAddress = TMP_007_I2C_ADDRESS, + }; + + return I2C_transfer(i2c_handle, &i2c_transaction); +} +/** + * \brief Peform a write only I2C transaction. + * \param wbuf Output buffer during the I2C transation. + * \param wcount How many bytes in the wbuf. + * \return true if the I2C operation was successful; + * else, return false. + */ +static inline bool +i2c_write(void *wbuf, size_t wcount) +{ + return i2c_write_read(wbuf, wcount, NULL, 0); +} +/** + * \brief Peform a read only I2C transaction. + * \param rbuf Input buffer during the I2C transation. + * \param rcount How many bytes to read into rbuf. + * \return true if the I2C operation was successful; + * else, return false. + */ +static inline bool +i2c_read(void *rbuf, size_t rcount) +{ + return i2c_write_read(NULL, 0, rbuf, rcount); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Initialize the TMP-007 sensor driver. + * \return true if I2C operation successful; else, return false. + */ +static bool +sensor_init(void) +{ + if(pin_handle && i2c_handle) { + return true; + } + + pin_handle = PIN_open(&pin_state, pin_table); + if(!pin_handle) { + return false; + } + + I2C_Params i2c_params; + I2C_Params_init(&i2c_params); + + i2c_params.transferMode = I2C_MODE_BLOCKING; + i2c_params.bitRate = I2C_400kHz; + + i2c_handle = I2C_open(Board_I2C0, &i2c_params); + if(i2c_handle == NULL) { + PIN_close(pin_handle); + return false; + } + + tmp_007.status = TMP_007_STATUS_DISABLED; + + return true; +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Callback when sensor is ready to read data from. + */ +static void +notify_ready_cb(void *not_used) +{ + tmp_007.status = TMP_007_STATUS_READY; + sensors_changed(&tmp_007_sensor); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Turn the sensor on or off. + */ +static bool +enable_sensor(bool enable) +{ + uint16_t cfg_value = (enable) + ? VAL_CONFIG_ON + : VAL_CONFIG_OFF; + + uint8_t cfg_data[] = { REG_CONFIG, LSB16(cfg_value) }; + + return i2c_write(cfg_data, sizeof(cfg_data)); +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Read the sensor value registers. + * \param local_tmp Output variable holding the Temperature in + * 16-bit format. + * \param obj_tmp Output variable holding the Object temperature in + * 16-bit format. + * \return true if valid data could be retrieved; else, false. + */ +static bool +read_data(uint16_t *local_tmp, uint16_t *obj_tmp) +{ + bool spi_ok = false; + + uint8_t status_data[] = { REG_STATUS }; + uint16_t status_value = 0; + + spi_ok = i2c_write_read(status_data, sizeof(status_data), + &status_value, sizeof(status_value)); + if(!spi_ok) { + return false; + } + status_value = SWAP16(status_value); + + if((status_value & CONV_RDY_BIT) == 0) { + return false; + } + + uint8_t local_temp_data[] = { REG_LOCAL_TEMP }; + uint16_t local_temp_value = 0; + + spi_ok = i2c_write_read(local_temp_data, sizeof(local_temp_data), + &local_temp_value, sizeof(local_temp_value)); + if(!spi_ok) { + return false; + } + + uint8_t obj_temp_data[] = { REG_OBJ_TEMP }; + uint16_t obj_temp_value = 0; + + spi_ok = i2c_write_read(obj_temp_data, sizeof(obj_temp_data), + &obj_temp_value, sizeof(obj_temp_value)); + if(!spi_ok) { + return false; + } + + *local_tmp = SWAP16(local_temp_value); + *obj_tmp = SWAP16(obj_temp_value); + + return true; +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Convert raw data to values in degrees Celsius. + * \param local_tmp Output variable holding the raw ambient temperature + * from sensor. + * \param obj_tmp Output variable holding the raw object temperature + * from sensor. + */ +static void +convert(uint16_t *local_tmp, uint16_t *obj_tmp) +{ + uint32_t local = (uint32_t)*local_tmp; + uint32_t obj = (uint32_t)*obj_tmp; + + local = (local >> 2) * 3125 / 100; + obj = (obj >> 2) * 3125 / 100; + + *local_tmp = (uint16_t)local; + *obj_tmp = (uint16_t)obj; +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Returns a reading from the sensor. + * \param type TMP_007_SENSOR_TYPE_OBJECT or TMP_007_SENSOR_TYPE_AMBIENT. + * \return Object or Ambient temperature in milli degrees Celsius. + */ +static int +value(int type) +{ + uint16_t raw_local_tmp = 0, local_tmp = 0; + uint16_t raw_obj_tmp = 0, obj_tmp = 0; + + if(tmp_007.status != TMP_007_STATUS_READY) { + PRINTF("Sensor disabled or starting up (%d)\n", tmp_007.status); + return TMP_007_READING_ERROR; + } + + switch(type) { + case TMP_007_TYPE_OBJECT: return tmp_007.obj_tmp_latched; + case TMP_007_TYPE_AMBIENT: return tmp_007.local_tmp_latched; + + case TMP_007_TYPE_ALL: + if(!read_data(&raw_local_tmp, &raw_obj_tmp)) { + return TMP_007_READING_ERROR; + } + + local_tmp = raw_local_tmp; + obj_tmp = raw_obj_tmp; + convert(&local_tmp, &obj_tmp); + + PRINTF("TMP: %04X %04X o=%d a=%d\n", raw_local_tmp, raw_obj_tmp, + (int)(local_tmp), (int)(obj_tmp)); + + tmp_007.local_tmp_latched = (int)(local_tmp); + tmp_007.obj_tmp_latched = (int)(obj_tmp); + + return 0; + + default: + PRINTF("Invalid type (%d)\n", type); + return TMP_007_READING_ERROR; + } +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Configuration function for the TMP-007 sensor. + * \param type Activate, enable or disable the sensor. See below. + * \param enable Enable or disable sensor. + * + * When type == SENSORS_HW_INIT we turn on the hardware. + * When type == SENSORS_ACTIVE and enable==1 we enable the sensor. + * When type == SENSORS_ACTIVE and enable==0 we disable the sensor. + */ +static int +configure(int type, int enable) +{ + switch(type) { + case SENSORS_HW_INIT: + if(!sensor_init()) { + return TMP_007_STATUS_DISABLED; + } + + enable_sensor(false); + + tmp_007.status = TMP_007_STATUS_INITIALIZED; + break; + + case SENSORS_ACTIVE: + /* Must be initialised first */ + if(tmp_007.status == TMP_007_STATUS_DISABLED) { + return TMP_007_STATUS_DISABLED; + } + if(enable) { + enable_sensor(true); + ctimer_set(&startup_timer, SENSOR_STARTUP_DELAY, notify_ready_cb, NULL); + tmp_007.status = TMP_007_STATUS_NOT_READY; + } else { + ctimer_stop(&startup_timer); + enable_sensor(false); + tmp_007.status = TMP_007_STATUS_INITIALIZED; + } + break; + + default: + break; + } + + return tmp_007.status; +} +/*---------------------------------------------------------------------------*/ +/** + * \brief Returns the status of the sensor. + * \param type Ignored. + * \return Status of the sensor. + */ +static int +status(int type) +{ + (void)type; + + return tmp_007.status; +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(tmp_007_sensor, "TMP-007", value, configure, status); +/*---------------------------------------------------------------------------*/ +#endif /* BOARD_SENSORS_ENABLE */ +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/tmp-007-sensor.h b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/tmp-007-sensor.h new file mode 100644 index 000000000..1c806abe8 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/tmp-007-sensor.h @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup sensortag-peripherals + * @{ + * + * \defgroup sensortag-tmp-sensor SensorTag IR Thermophile sensor + * + * Due to the time required for the sensor to startup, this driver is + * meant to be used in an asynchronous fashion. The caller must first + * activate the sensor by calling SENSORS_ACTIVATE(). This will trigger + * the sensor's startup sequence, but the call will not wait for it to + * complete so that the CPU can perform other tasks or drop to a low + * power mode. + * + * Once the sensor is stable, the driver will generate a + * sensors_changed event. + * + * The caller should then use value(TMP_007_SENSOR_TYPE_ALL) to + * read sensor values and latch them. Once completed successfully, + * individual readings can be retrieved with calls to + * value(TMP_007_SENSOR_TYPE_OBJECT) or + * value(TMP_007_SENSOR_TYPE_AMBIENT). + * + * Once required readings have been taken, the caller has two options: + * - Turn the sensor off by calling SENSORS_DEACTIVATE, but in order + * to take subsequent readings SENSORS_ACTIVATE must be called again. + * - Leave the sensor on. In this scenario, the caller can simply keep + * calling value(TMP_007_SENSOR_TYPE_ALL) to read and latch new + * values. However keeping the sensor on will consume more energy. + * @{ + * + * \file + * Header file for the Sensortag TMP-007 IR Thermophile sensor. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#ifndef TMP_007_SENSOR_H_ +#define TMP_007_SENSOR_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +/*---------------------------------------------------------------------------*/ +#include "board-conf.h" +/*---------------------------------------------------------------------------*/ +#if BOARD_SENSORS_ENABLE +#if (TI_I2C_CONF_ENABLE == 0) || (TI_I2C_CONF_I2C0_ENABLE == 0) +#error "The BMP280 requires the I2C driver to be enabled (TI_I2C_CONF_ENABLE = 1)" +#endif +#endif +/*---------------------------------------------------------------------------*/ +typedef enum { + TMP_007_TYPE_OBJECT = (1 << 0), + TMP_007_TYPE_AMBIENT = (1 << 1), + + TMP_007_TYPE_ALL = (TMP_007_TYPE_OBJECT | + TMP_007_TYPE_AMBIENT), +} TMP_007_TYPE; +/*---------------------------------------------------------------------------*/ +typedef enum { + TMP_007_STATUS_DISABLED, + TMP_007_STATUS_INITIALIZED, + TMP_007_STATUS_NOT_READY, + TMP_007_STATUS_READY, + TMP_007_STATUS_I2C_ERROR, +} TMP_007_STATUS; +/*---------------------------------------------------------------------------*/ +#define TMP_007_READING_ERROR -1 +/*---------------------------------------------------------------------------*/ +extern const struct sensors_sensor tmp_007_sensor; +/*---------------------------------------------------------------------------*/ +#endif /* TMP_007_SENSOR_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/srf06/Makefile.srf06 b/arch/platform/simplelink/cc13xx-cc26xx/srf06/Makefile.srf06 new file mode 100644 index 000000000..d6686e10a --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/srf06/Makefile.srf06 @@ -0,0 +1,11 @@ +################################################################################ +# SimpleLink LaunchPad makefile + +BOARD_TYPE = BOARD_SMARTRF06EB + +# leds-arch.c etc. +BOARD_SOURCEFILES += srf06-sensors.c +BOARD_SOURCEFILES += button-sensor-arch.c leds-arch.c +BOARD_SOURCEFILES += als-sensor.c + +TARGET_FAMILY_DIRS += srf06 diff --git a/arch/platform/simplelink/cc13xx-cc26xx/srf06/als-sensor.c b/arch/platform/simplelink/cc13xx-cc26xx/srf06/als-sensor.c new file mode 100644 index 000000000..4f625943b --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/srf06/als-sensor.c @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup srf06-peripherals + * @{ + * + * \file + * Driver for the SmartRF06 EB ALS sensor. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/gpio-hal.h" +#include "lib/sensors.h" +#include "sys/timer.h" + +#include "als-sensor.h" +/*---------------------------------------------------------------------------*/ +#include + +#include +/*---------------------------------------------------------------------------*/ +#include +/*---------------------------------------------------------------------------*/ +static ADC_Handle adc_handle; +/*---------------------------------------------------------------------------*/ +static int +init(void) +{ + ADC_Params adc_params; + ADC_Params_init(&adc_params); + + adc_handle = ADC_open(Board_ADCALS, &adc_params); + if(adc_handle == NULL) { + return 0; + } + + return 1; +} +/*---------------------------------------------------------------------------*/ +static int +config(int type, int enable) +{ + switch(type) { + case SENSORS_HW_INIT: + return init(); + + case SENSORS_ACTIVE: + gpio_hal_arch_pin_set_output(Board_ALS_PWR); + gpio_hal_arch_pin_set_input(Board_ALS_OUT); + + if(enable) { + gpio_hal_arch_set_pin(Board_ALS_PWR); + clock_delay_usec(2000); + } else { + gpio_hal_arch_clear_pin(Board_ALS_PWR); + } + break; + + default: + break; + } + return 1; +} +/*---------------------------------------------------------------------------*/ +static int +value(int type) +{ + + uint16_t adc_value = 0; + int_fast16_t res = ADC_convert(adc_handle, &adc_value); + if(res != ADC_STATUS_SUCCESS) { + return -1; + } + + return (int)adc_value; +} +/*---------------------------------------------------------------------------*/ +static int +status(int type) +{ + return 1; +} +/*---------------------------------------------------------------------------*/ +SENSORS_SENSOR(als_sensor, ALS_SENSOR, value, config, status); +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/srf06/als-sensor.h b/arch/platform/simplelink/cc13xx-cc26xx/srf06/als-sensor.h new file mode 100644 index 000000000..dd9141fad --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/srf06/als-sensor.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup srf06-peripherals + * @{ + * + * \file + * Header file for the SmartRF06 EB ALS sensor. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#ifndef ALS_SENSOR_H_ +#define ALS_SENSOR_H_ +/*---------------------------------------------------------------------------*/ +#include "lib/sensors.h" +/*---------------------------------------------------------------------------*/ +#define ALS_SENSOR "ALS" +/*---------------------------------------------------------------------------*/ +extern const struct sensors_sensor als_sensor; +/*---------------------------------------------------------------------------*/ +#endif /* ALS_SENSOR_H_ */ +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/srf06/board-conf.h b/arch/platform/simplelink/cc13xx-cc26xx/srf06/board-conf.h new file mode 100644 index 000000000..037e7eb3f --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/srf06/board-conf.h @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup srf06-peripherals + * @{ + * + * \file + * Header file with definitions related to SmartRF06 EB boards. + * \author + * Edvard Pettersen + * \note + * This file should not be included directly + */ +/*---------------------------------------------------------------------------*/ +#ifndef BOARD_CONF_H_ +#define BOARD_CONF_H_ +/*---------------------------------------------------------------------------*/ +/** + * \name LED configurations for the dev/leds.h API. + * + * Those values are not meant to be modified by the user + * @{ + */ +#define PLATFORM_HAS_LEDS 1 + +#define LEDS_CONF_COUNT 4 + +#define LEDS_CONF_RED 0 +#define LEDS_CONF_YELLOW 1 +#define LEDS_CONF_GREEN 2 +#define LEDS_CONF_ORANGE 3 + +#define LEDS_CONF_ALL ((1 << LEDS_CONF_COUNT) - 1) +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name Button configurations for the dev/button-hal.h API. + * + * Those values are not meant to be modified by the user + * @{ + */ +#define PLATFORM_HAS_BUTTON 1 +#define PLATFORM_SUPPORTS_BUTTON_HAL 1 + +#define BUTTON_HAL_ID_KEY_LEFT 0 +#define BUTTON_HAL_ID_KEY_RIGHT 1 +#define BUTTON_HAL_ID_KEY_UP 2 +#define BUTTON_HAL_ID_KEY_DOWN 3 +#define BUTTON_HAL_ID_KEY_SELECT 4 +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name SmartRF06 EB does have sensors. + * + * Those values are not meant to be modified by the user + * @{ + */ +#define BOARD_CONF_HAS_SENSORS 1 +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name Enable or disable the SmartRF06EB sensors. + * + * Those values are not meant to be modified by the user + * @{ + */ +#define BOARD_SENSORS_ENABLE (!(BOARD_CONF_SENSORS_DISABLE)) +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* BOARD_CONF_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/srf06/board-peripherals.h b/arch/platform/simplelink/cc13xx-cc26xx/srf06/board-peripherals.h new file mode 100644 index 000000000..5a30b5fe1 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/srf06/board-peripherals.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup cc13xx-cc26xx-platform + * @{ + * + * \defgroup srf06-peripherals SmartRF06 Evaluation Board peripherals + * + * Defines related to configuring SmartRF06 EB's peripherals. All + * SmartRF06 EBs are identical to a very large extent. Everything + * documented within this group applies to all SmartRF06 EBs. + * + * @{ + * + * \file + * Header file with definitions related to SmartRF06 EB boards. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#ifndef BOARD_PERIPHERALS_H_ +#define BOARD_PERIPHERALS_H_ +/*---------------------------------------------------------------------------*/ +#include "als-sensor.h" +/*---------------------------------------------------------------------------*/ +#include "board-conf.h" +/*---------------------------------------------------------------------------*/ +#endif /* BOARD_PERIPHERALS_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/srf06/button-sensor-arch.c b/arch/platform/simplelink/cc13xx-cc26xx/srf06/button-sensor-arch.c new file mode 100644 index 000000000..9c3df6abb --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/srf06/button-sensor-arch.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup srf06-peripherals + * @{ + * + * \file + * Button HAL definitions for the SmartRF06 Evaluation Board's buttons. + * Common across all CC13xx/CC26xx devices on SmartRF06 EB. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/button-hal.h" +/*---------------------------------------------------------------------------*/ +#include +/*---------------------------------------------------------------------------*/ +/* Key select button */ +BUTTON_HAL_BUTTON( + key_select, /**< Name */ + "Key Select", /**< Description */ + Board_KEY_SELECT, /**< PIN */ + GPIO_HAL_PIN_CFG_PULL_UP | + GPIO_HAL_PIN_CFG_HYSTERESIS, /**< Pull configuration */ + BUTTON_HAL_ID_KEY_SELECT, /**< Unique ID */ + true); /**< Negative logic */ + +/* Key up button */ +BUTTON_HAL_BUTTON( + key_up, /**< Name */ + "Key Up", /**< Description */ + Board_KEY_UP, /**< PIN */ + GPIO_HAL_PIN_CFG_PULL_UP | + GPIO_HAL_PIN_CFG_HYSTERESIS, /**< Pull configuration */ + BUTTON_HAL_ID_KEY_UP, /**< Unique ID */ + true); /**< Negative logic */ + +/* Key down button */ +BUTTON_HAL_BUTTON( + key_down, /**< Name */ + "Key Down", /**< Description */ + Board_KEY_DOWN, /**< PIN */ + GPIO_HAL_PIN_CFG_PULL_UP | + GPIO_HAL_PIN_CFG_HYSTERESIS, /**< Pull configuration */ + BUTTON_HAL_ID_KEY_DOWN, /**< Unique ID */ + true); /**< Negative logic */ + +/* Key left button */ +BUTTON_HAL_BUTTON( + key_left, /**< Name */ + "Key Left", /**< Description */ + Board_KEY_LEFT, /**< PIN */ + GPIO_HAL_PIN_CFG_PULL_UP | + GPIO_HAL_PIN_CFG_HYSTERESIS, /**< Pull configuration */ + BUTTON_HAL_ID_KEY_LEFT, /**< Unique ID */ + true); /**< Negative logic */ + +/* Key right button */ +BUTTON_HAL_BUTTON( + key_right, /**< Name */ + "Key Right", /**< Description */ + Board_KEY_RIGHT, /**< PIN */ + GPIO_HAL_PIN_CFG_PULL_UP | + GPIO_HAL_PIN_CFG_HYSTERESIS, /**< Pull configuration */ + BUTTON_HAL_ID_KEY_RIGHT, /**< Unique ID */ + true); /**< Negative logic */ +/*---------------------------------------------------------------------------*/ +BUTTON_HAL_BUTTONS(&key_select, &key_up, &key_down, &key_left, &key_right); +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/Board.h new file mode 100644 index 000000000..0941b222f --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/Board.h @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2015-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 __BOARD_H +#define __BOARD_H + +#define Board_CC1350DK_7XD +#define BOARD_STRING "TI SmartRF06EB + CC13x0 EM" + +#ifdef __cplusplus +extern "C" { +#endif + +#include "CC1350DK_7XD.h" + +#define Board_initGeneral() CC1350DK_7XD_initGeneral() +#define Board_shutDownExtFlash() CC1350DK_7XD_shutDownExtFlash() +#define Board_wakeUpExtFlash() CC1350DK_7XD_wakeUpExtFlash() + +/* These #defines allow us to reuse TI-RTOS across other device families */ + +#define Board_ADCALS CC1350DK_7XD_ADCALS + +#define Board_ADC0 CC1350DK_7XD_ADCVDDS +#define Board_ADC1 CC1350DK_7XD_ADCALS + +#define Board_ADCBUF0 CC1350DK_7XD_ADCBUF0 +#define Board_ADCBUF0CHANNEL0 CC1350DK_7XD_ADCBUF0CHANNELVDDS +#define Board_ADCBUF0CHANNEL1 CC1350DK_7XD_ADCBUF0CHANNELADCALS + +#define Board_CRYPTO0 CC1350DK_7XD_CRYPTO0 + +#define Board_DIO0 CC1350DK_7XD_DIO0 +#define Board_DIO1_RFSW CC1350DK_7XD_DIO1_RFSW +#define Board_DIO12 CC1350DK_7XD_DIO12 +#define Board_DIO15 CC1350DK_7XD_DIO15 +#define Board_DIO16_TDO CC1350DK_7XD_DIO16_TDO +#define Board_DIO17_TDI CC1350DK_7XD_DIO17_TDI +#define Board_DIO21 CC1350DK_7XD_DIO21 +#define Board_DIO22 CC1350DK_7XD_DIO22 + +#define Board_DIO23_ANALOG CC1350DK_7XD_DIO23_ANALOG +#define Board_DIO24_ANALOG CC1350DK_7XD_DIO24_ANALOG +#define Board_DIO25_ANALOG CC1350DK_7XD_DIO25_ANALOG +#define Board_DIO26_ANALOG CC1350DK_7XD_DIO26_ANALOG +#define Board_DIO27_ANALOG CC1350DK_7XD_DIO27_ANALOG +#define Board_DIO28_ANALOG CC1350DK_7XD_DIO28_ANALOG +#define Board_DIO29_ANALOG CC1350DK_7XD_DIO29_ANALOG +#define Board_DIO30_ANALOG CC1350DK_7XD_DIO30_ANALOG + +#define Board_GPIO_BTN0 CC1350DK_7XD_PIN_KEY_SELECT +#define Board_GPIO_BTN1 CC1350DK_7XD_PIN_KEY_UP +#define Board_GPIO_BTN2 CC1350DK_7XD_PIN_KEY_DOWN +#define Board_GPIO_BTN3 CC1350DK_7XD_PIN_KEY_LEFT +#define Board_GPIO_BTN4 CC1350DK_7XD_PIN_KEY_RIGHT +#define Board_GPIO_LED0 CC1350DK_7XD_PIN_LED1 +#define Board_GPIO_LED1 CC1350DK_7XD_PIN_LED2 +#define Board_GPIO_LED2 CC1350DK_7XD_PIN_LED3 +#define Board_GPIO_LED3 CC1350DK_7XD_PIN_LED4 +#define Board_GPIO_LED_ON CC1350DK_7XD_GPIO_LED_ON +#define Board_GPIO_LED_OFF CC1350DK_7XD_GPIO_LED_OFF + +#define Board_GPTIMER0A CC1350DK_7XD_GPTIMER0A +#define Board_GPTIMER0B CC1350DK_7XD_GPTIMER0B +#define Board_GPTIMER1A CC1350DK_7XD_GPTIMER1A +#define Board_GPTIMER1B CC1350DK_7XD_GPTIMER1B +#define Board_GPTIMER2A CC1350DK_7XD_GPTIMER2A +#define Board_GPTIMER2B CC1350DK_7XD_GPTIMER2B +#define Board_GPTIMER3A CC1350DK_7XD_GPTIMER3A +#define Board_GPTIMER3B CC1350DK_7XD_GPTIMER3B + +#define Board_I2C0 CC1350DK_7XD_I2C0 + +#define Board_NVSINTERNAL CC1350DK_7XD_NVSCC26XX0 + +#define Board_KEY_SELECT CC1350DK_7XD_PIN_KEY_SELECT +#define Board_KEY_UP CC1350DK_7XD_PIN_KEY_UP +#define Board_KEY_DOWN CC1350DK_7XD_PIN_KEY_DOWN +#define Board_KEY_LEFT CC1350DK_7XD_PIN_KEY_LEFT +#define Board_KEY_RIGHT CC1350DK_7XD_PIN_KEY_RIGHT + +#define Board_PIN_BUTTON0 CC1350DK_7XD_PIN_KEY_SELECT +#define Board_PIN_BUTTON1 CC1350DK_7XD_PIN_KEY_UP +#define Board_PIN_BUTTON2 CC1350DK_7XD_PIN_KEY_DOWN +#define Board_PIN_BUTTON3 CC1350DK_7XD_PIN_KEY_LEFT +#define Board_PIN_BUTTON4 CC1350DK_7XD_PIN_KEY_RIGHT +#define Board_PIN_BTN1 CC1350DK_7XD_PIN_KEY_SELECT +#define Board_PIN_BTN2 CC1350DK_7XD_PIN_KEY_UP +#define Board_PIN_BTN3 CC1350DK_7XD_PIN_KEY_DOWN +#define Board_PIN_BTN4 CC1350DK_7XD_PIN_KEY_LEFT +#define Board_PIN_BTN5 CC1350DK_7XD_PIN_KEY_RIGHT +#define Board_PIN_LED0 CC1350DK_7XD_PIN_LED1 +#define Board_PIN_LED1 CC1350DK_7XD_PIN_LED2 +#define Board_PIN_LED2 CC1350DK_7XD_PIN_LED3 +#define Board_PIN_LED3 CC1350DK_7XD_PIN_LED4 + +#define Board_PWM0 CC1350DK_7XD_PWM0 +#define Board_PWM1 CC1350DK_7XD_PWM1 +#define Board_PWM2 CC1350DK_7XD_PWM2 +#define Board_PWM3 CC1350DK_7XD_PWM3 +#define Board_PWM4 CC1350DK_7XD_PWM4 +#define Board_PWM5 CC1350DK_7XD_PWM5 +#define Board_PWM6 CC1350DK_7XD_PWM6 +#define Board_PWM7 CC1350DK_7XD_PWM7 + +#define Board_SD0 CC1350DK_7XD_SDSPI0 + +#define Board_SPI0 CC1350DK_7XD_SPI0 +#define Board_SPI0_MISO CC1350DK_7XD_SPI0_MISO +#define Board_SPI0_MOSI CC1350DK_7XD_SPI0_MOSI +#define Board_SPI0_CLK CC1350DK_7XD_SPI0_CLK +#define Board_SPI0_CSN CC1350DK_7XD_SPI0_CSN +#define Board_SPI1 CC1350DK_7XD_SPI1 +#define Board_SPI1_MISO CC1350DK_7XD_SPI1_MISO +#define Board_SPI1_MOSI CC1350DK_7XD_SPI1_MOSI +#define Board_SPI1_CLK CC1350DK_7XD_SPI1_CLK +#define Board_SPI1_CSN CC1350DK_7XD_SPI1_CSN +#define Board_FLASH_CS_ON 0 +#define Board_FLASH_CS_OFF 1 + +#define Board_SPI_MASTER CC1350DK_7XD_SPI0 +#define Board_SPI_SLAVE CC1350DK_7XD_SPI0 +#define Board_SPI_MASTER_READY CC1350DK_7XD_SPI_MASTER_READY +#define Board_SPI_SLAVE_READY CC1350DK_7XD_SPI_SLAVE_READY + +#define Board_UART0 CC1350DK_7XD_UART0 + +#define Board_WATCHDOG0 CC1350DK_7XD_WATCHDOG0 + +#define Board_SDCARD_CS CC1350DK_7XD_SDCARD_CS + +#define Board_LCD_MODE CC1350DK_7XD_LCD_MODE +#define Board_LCD_RST CC1350DK_7XD_LCD_RST +#define Board_LCD_CS CC1350DK_7XD_LCD_CS + +#define Board_ALS_OUT CC1350DK_7XD_ALS_OUT +#define Board_ALS_PWR CC1350DK_7XD_ALS_PWR + +#define Board_ACC_PWR CC1350DK_7XD_ACC_PWR +#define Board_ACC_CS CC1350DK_7XD_ACC_CS + +#ifdef __cplusplus +} +#endif + +#endif /* __BOARD_H */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/CC1350DK_7XD.c b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/CC1350DK_7XD.c new file mode 100644 index 000000000..2040a7582 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/CC1350DK_7XD.c @@ -0,0 +1,719 @@ +/* + * Copyright (c) 2016-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +/* + * ====================== CC1350DK_7XD.c =================================== + * This file is responsible for setting up the board specific items for the + * CC1350DK_7XD board. + */ + +#include +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/udma.h) +#include DeviceFamily_constructPath(inc/hw_ints.h) +#include DeviceFamily_constructPath(inc/hw_memmap.h) + +#include "CC1350DK_7XD.h" + +/* + * =============================== ADCBuf =============================== + */ +#include +#include + +ADCBufCC26XX_Object adcBufCC26xxObjects[CC1350DK_7XD_ADCBUFCOUNT]; + +/* + * This table converts a virtual adc channel into a dio and internal analogue + * input signal. This table is necessary for the functioning of the adcBuf + * driver. Comment out unused entries to save flash. Dio and internal signal + * pairs are hardwired. Do not remap them in the table. You may reorder entire + * entries. The mapping of dio and internal signals is package dependent. + */ +const ADCBufCC26XX_AdcChannelLutEntry ADCBufCC26XX_adcChannelLut[CC1350DK_7XD_ADCBUF0CHANNELCOUNT] = { + {CC1350DK_7XD_ALS_OUT, ADC_COMPB_IN_AUXIO7}, + {PIN_UNASSIGNED, ADC_COMPB_IN_DCOUPL}, + {PIN_UNASSIGNED, ADC_COMPB_IN_VSS}, + {PIN_UNASSIGNED, ADC_COMPB_IN_VDDS}, +}; + +const ADCBufCC26XX_HWAttrs adcBufCC26xxHWAttrs[CC1350DK_7XD_ADCBUFCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + .adcChannelLut = ADCBufCC26XX_adcChannelLut, + .gpTimerUnit = CC1350DK_7XD_GPTIMER0A, + .gptDMAChannelMask = 1 << UDMA_CHAN_TIMER0_A, + } +}; + +const ADCBuf_Config ADCBuf_config[CC1350DK_7XD_ADCBUFCOUNT] = { + { + &ADCBufCC26XX_fxnTable, + &adcBufCC26xxObjects[CC1350DK_7XD_ADCBUF0], + &adcBufCC26xxHWAttrs[CC1350DK_7XD_ADCBUF0] + }, +}; + +const uint_least8_t ADCBuf_count = CC1350DK_7XD_ADCBUFCOUNT; + +/* + * =============================== ADC =============================== + */ +#include +#include + +ADCCC26XX_Object adcCC26xxObjects[CC1350DK_7XD_ADCCOUNT]; + +const ADCCC26XX_HWAttrs adcCC26xxHWAttrs[CC1350DK_7XD_ADCCOUNT] = { + { + .adcDIO = CC1350DK_7XD_DIO23_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO7, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_DCOUPL, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_VSS, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_VDDS, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + } +}; + +const ADC_Config ADC_config[CC1350DK_7XD_ADCCOUNT] = { + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1350DK_7XD_ADCALS], &adcCC26xxHWAttrs[CC1350DK_7XD_ADCALS]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1350DK_7XD_ADCDCOUPL], &adcCC26xxHWAttrs[CC1350DK_7XD_ADCDCOUPL]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1350DK_7XD_ADCVSS], &adcCC26xxHWAttrs[CC1350DK_7XD_ADCVSS]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1350DK_7XD_ADCVDDS], &adcCC26xxHWAttrs[CC1350DK_7XD_ADCVDDS]}, +}; + +const uint_least8_t ADC_count = CC1350DK_7XD_ADCCOUNT; + +/* + * =============================== Crypto =============================== + */ +#include + +CryptoCC26XX_Object cryptoCC26XXObjects[CC1350DK_7XD_CRYPTOCOUNT]; + +const CryptoCC26XX_HWAttrs cryptoCC26XXHWAttrs[CC1350DK_7XD_CRYPTOCOUNT] = { + { + .baseAddr = CRYPTO_BASE, + .powerMngrId = PowerCC26XX_PERIPH_CRYPTO, + .intNum = INT_CRYPTO_RESULT_AVAIL_IRQ, + .intPriority = ~0, + } +}; + +const CryptoCC26XX_Config CryptoCC26XX_config[CC1350DK_7XD_CRYPTOCOUNT] = { + { + .object = &cryptoCC26XXObjects[CC1350DK_7XD_CRYPTO0], + .hwAttrs = &cryptoCC26XXHWAttrs[CC1350DK_7XD_CRYPTO0] + }, +}; + +/* + * =============================== GPIO =============================== + */ +#include +#include + +/* + * Array of Pin configurations + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC1350DK_7XD.h + * NOTE: Pins not used for interrupts should be placed at the end of the + * array. Callback entries can be omitted from callbacks array to + * reduce memory usage. + */ +GPIO_PinConfig gpioPinConfigs[] = { + /* Input pins */ + GPIOCC26XX_DIO_11 | GPIO_DO_NOT_CONFIG, /* Key Select */ + GPIOCC26XX_DIO_19 | GPIO_DO_NOT_CONFIG, /* Key Up */ + GPIOCC26XX_DIO_12 | GPIO_DO_NOT_CONFIG, /* Key Down */ + GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG, /* Key Left */ + GPIOCC26XX_DIO_18 | GPIO_DO_NOT_CONFIG, /* Key Right */ + + GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG, /* CC1350DK_7XD_SPI_MASTER_READY */ + GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG, /* CC1350DK_7XD_SPI_SLAVE_READY */ + + /* Output pins */ + GPIOCC26XX_DIO_25 | GPIO_DO_NOT_CONFIG, /* LED 1 */ + GPIOCC26XX_DIO_27 | GPIO_DO_NOT_CONFIG, /* LED 2 */ + GPIOCC26XX_DIO_07 | GPIO_DO_NOT_CONFIG, /* LED 3 */ + GPIOCC26XX_DIO_06 | GPIO_DO_NOT_CONFIG, /* LED 4 */ + + /* SDCARD */ + GPIOCC26XX_DIO_30 | GPIO_DO_NOT_CONFIG, /* SPI chip select */ + + /* Accelerometer */ + GPIOCC26XX_DIO_24 | GPIO_DO_NOT_CONFIG, /* SPI chip select */ +}; + +/* + * Array of callback function pointers + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC2650_LAUNCH.h + * NOTE: Pins not used for interrupts can be omitted from callbacks array to + * reduce memory usage (if placed at end of gpioPinConfigs array). + */ +GPIO_CallbackFxn gpioCallbackFunctions[] = { + NULL, /* Button 0 */ + NULL, /* Button 1 */ + NULL, /* CC1350DK_7XD_SPI_MASTER_READY */ + NULL, /* CC1350DK_7XD_SPI_SLAVE_READY */ +}; + +const GPIOCC26XX_Config GPIOCC26XX_config = { + .pinConfigs = (GPIO_PinConfig *)gpioPinConfigs, + .callbacks = (GPIO_CallbackFxn *)gpioCallbackFunctions, + .numberOfPinConfigs = CC1350DK_7XD_GPIOCOUNT, + .numberOfCallbacks = sizeof(gpioCallbackFunctions)/sizeof(GPIO_CallbackFxn), + .intPriority = (~0) +}; + +/* + * =============================== GPTimer =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include + +GPTimerCC26XX_Object gptimerCC26XXObjects[CC1350DK_7XD_GPTIMERCOUNT]; + +const GPTimerCC26XX_HWAttrs gptimerCC26xxHWAttrs[CC1350DK_7XD_GPTIMERPARTSCOUNT] = { + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0A, }, + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0B, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1A, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1B, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2A, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2B, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3A, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3B, }, +}; + +const GPTimerCC26XX_Config GPTimerCC26XX_config[CC1350DK_7XD_GPTIMERPARTSCOUNT] = { + { &gptimerCC26XXObjects[CC1350DK_7XD_GPTIMER0], &gptimerCC26xxHWAttrs[CC1350DK_7XD_GPTIMER0A], GPT_A }, + { &gptimerCC26XXObjects[CC1350DK_7XD_GPTIMER0], &gptimerCC26xxHWAttrs[CC1350DK_7XD_GPTIMER0B], GPT_B }, + { &gptimerCC26XXObjects[CC1350DK_7XD_GPTIMER1], &gptimerCC26xxHWAttrs[CC1350DK_7XD_GPTIMER1A], GPT_A }, + { &gptimerCC26XXObjects[CC1350DK_7XD_GPTIMER1], &gptimerCC26xxHWAttrs[CC1350DK_7XD_GPTIMER1B], GPT_B }, + { &gptimerCC26XXObjects[CC1350DK_7XD_GPTIMER2], &gptimerCC26xxHWAttrs[CC1350DK_7XD_GPTIMER2A], GPT_A }, + { &gptimerCC26XXObjects[CC1350DK_7XD_GPTIMER2], &gptimerCC26xxHWAttrs[CC1350DK_7XD_GPTIMER2B], GPT_B }, + { &gptimerCC26XXObjects[CC1350DK_7XD_GPTIMER3], &gptimerCC26xxHWAttrs[CC1350DK_7XD_GPTIMER3A], GPT_A }, + { &gptimerCC26XXObjects[CC1350DK_7XD_GPTIMER3], &gptimerCC26xxHWAttrs[CC1350DK_7XD_GPTIMER3B], GPT_B }, +}; + +/* + * =============================== I2C =============================== +*/ +#include +#include + +#if TI_I2C_CONF_ENABLE + +I2CCC26XX_Object i2cCC26xxObjects[CC1350DK_7XD_I2CCOUNT]; + +const I2CCC26XX_HWAttrsV1 i2cCC26xxHWAttrs[CC1350DK_7XD_I2CCOUNT] = { +#if TI_I2C_CONF_I2C0_ENABLE + { + .baseAddr = I2C0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_I2C0, + .intNum = INT_I2C_IRQ, + .intPriority = ~0, + .swiPriority = 0, + .sdaPin = CC1350DK_7XD_I2C0_SDA0, + .sclPin = CC1350DK_7XD_I2C0_SCL0, + }, +#endif +}; + +const I2C_Config I2C_config[CC1350DK_7XD_I2CCOUNT] = { +#if TI_I2C_CONF_I2C0_ENABLE + { + .fxnTablePtr = &I2CCC26XX_fxnTable, + .object = &i2cCC26xxObjects[CC1350DK_7XD_I2C0], + .hwAttrs = &i2cCC26xxHWAttrs[CC1350DK_7XD_I2C0] + }, +#endif +}; + +const uint_least8_t I2C_count = CC1350DK_7XD_I2CCOUNT; + +#endif /* TI_I2C_CONF_ENABLE */ + +/* + * =============================== NVS =============================== + */ +#include +#include +#include + +#define NVS_REGIONS_BASE 0x1A000 +#define SECTORSIZE 0x1000 +#define REGIONSIZE (SECTORSIZE * 4) + +#if TI_NVS_CONF_ENABLE + +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE +/* + * Reserve flash sectors for NVS driver use by placing an uninitialized byte + * array at the desired flash address. + */ +#if defined(__TI_COMPILER_VERSION__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +#pragma LOCATION(flashBuf, NVS_REGIONS_BASE); +#pragma NOINIT(flashBuf); +static char flashBuf[REGIONSIZE]; + +#elif defined(__IAR_SYSTEMS_ICC__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +static __no_init char flashBuf[REGIONSIZE] @ NVS_REGIONS_BASE; + +#elif defined(__GNUC__) + +/* + * Place the flash buffers in the .nvs section created in the gcc linker file. + * The .nvs section enforces alignment on a sector boundary but may + * be placed anywhere in flash memory. If desired the .nvs section can be set + * to a fixed address by changing the following in the gcc linker file: + * + * .nvs (FIXED_FLASH_ADDR) (NOLOAD) : AT (FIXED_FLASH_ADDR) { + * *(.nvs) + * } > REGION_TEXT + */ +__attribute__ ((section (".nvs"))) +static char flashBuf[REGIONSIZE]; + +#endif + +/* Allocate objects for NVS Internal Regions */ +NVSCC26XX_Object nvsCC26xxObjects[1]; + +/* Hardware attributes for NVS Internal Regions */ +const NVSCC26XX_HWAttrs nvsCC26xxHWAttrs[1] = { + { + .regionBase = (void *)flashBuf, + .regionSize = REGIONSIZE, + }, +}; + +#endif /* TI_NVS_CONF_NVS_INTERNAL_ENABLE */ + +/* NVS Region index 0 and 1 refer to NVS and NVS SPI respectively */ +const NVS_Config NVS_config[CC1350DK_7XD_NVSCOUNT] = { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + { + .fxnTablePtr = &NVSCC26XX_fxnTable, + .object = &nvsCC26xxObjects[0], + .hwAttrs = &nvsCC26xxHWAttrs[0], + }, +#endif +}; + +const uint_least8_t NVS_count = CC1350DK_7XD_NVSCOUNT; + +#endif /* TI_NVS_CONF_ENABLE */ + +/* + * =============================== PIN =============================== + */ +#include +#include + +const PIN_Config BoardGpioInitTable[] = { + + CC1350DK_7XD_PIN_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC1350DK_7XD_PIN_LED2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC1350DK_7XD_PIN_LED3 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC1350DK_7XD_PIN_LED4 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC1350DK_7XD_PIN_KEY_SELECT | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC1350DK_7XD_PIN_KEY_UP | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC1350DK_7XD_PIN_KEY_DOWN | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC1350DK_7XD_PIN_KEY_LEFT | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC1350DK_7XD_PIN_KEY_UP | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC1350DK_7XD_SDCARD_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ + CC1350DK_7XD_ACC_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ + CC1350DK_7XD_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */ + CC1350DK_7XD_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */ + CC1350DK_7XD_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */ + CC1350DK_7XD_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */ + CC1350DK_7XD_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI clock */ + + PIN_TERMINATE +}; + +const PINCC26XX_HWAttrs PINCC26XX_hwAttrs = { + .intPriority = ~0, + .swiPriority = 0 +}; + +/* + * =============================== Power =============================== + */ +#include +#include + +const PowerCC26XX_Config PowerCC26XX_config = { + .policyInitFxn = NULL, + .policyFxn = &PowerCC26XX_standbyPolicy, + .calibrateFxn = &PowerCC26XX_calibrate, + .enablePolicy = true, + .calibrateRCOSC_LF = true, + .calibrateRCOSC_HF = true, +}; + +/* + * =============================== PWM =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include +#include + +PWMTimerCC26XX_Object pwmtimerCC26xxObjects[CC1350DK_7XD_PWMCOUNT]; + +const PWMTimerCC26XX_HwAttrs pwmtimerCC26xxHWAttrs[CC1350DK_7XD_PWMCOUNT] = { + { .pwmPin = CC1350DK_7XD_PWMPIN0, .gpTimerUnit = CC1350DK_7XD_GPTIMER0A }, + { .pwmPin = CC1350DK_7XD_PWMPIN1, .gpTimerUnit = CC1350DK_7XD_GPTIMER0B }, + { .pwmPin = CC1350DK_7XD_PWMPIN2, .gpTimerUnit = CC1350DK_7XD_GPTIMER1A }, + { .pwmPin = CC1350DK_7XD_PWMPIN3, .gpTimerUnit = CC1350DK_7XD_GPTIMER1B }, + { .pwmPin = CC1350DK_7XD_PWMPIN4, .gpTimerUnit = CC1350DK_7XD_GPTIMER2A }, + { .pwmPin = CC1350DK_7XD_PWMPIN5, .gpTimerUnit = CC1350DK_7XD_GPTIMER2B }, + { .pwmPin = CC1350DK_7XD_PWMPIN6, .gpTimerUnit = CC1350DK_7XD_GPTIMER3A }, + { .pwmPin = CC1350DK_7XD_PWMPIN7, .gpTimerUnit = CC1350DK_7XD_GPTIMER3B }, +}; + +const PWM_Config PWM_config[CC1350DK_7XD_PWMCOUNT] = { + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350DK_7XD_PWM0], &pwmtimerCC26xxHWAttrs[CC1350DK_7XD_PWM0] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350DK_7XD_PWM1], &pwmtimerCC26xxHWAttrs[CC1350DK_7XD_PWM1] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350DK_7XD_PWM2], &pwmtimerCC26xxHWAttrs[CC1350DK_7XD_PWM2] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350DK_7XD_PWM3], &pwmtimerCC26xxHWAttrs[CC1350DK_7XD_PWM3] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350DK_7XD_PWM4], &pwmtimerCC26xxHWAttrs[CC1350DK_7XD_PWM4] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350DK_7XD_PWM5], &pwmtimerCC26xxHWAttrs[CC1350DK_7XD_PWM5] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350DK_7XD_PWM6], &pwmtimerCC26xxHWAttrs[CC1350DK_7XD_PWM6] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC1350DK_7XD_PWM7], &pwmtimerCC26xxHWAttrs[CC1350DK_7XD_PWM7] }, +}; + +const uint_least8_t PWM_count = CC1350DK_7XD_PWMCOUNT; + +/* + * =============================== RF Driver =============================== + */ +#include + +const RFCC26XX_HWAttrsV2 RFCC26XX_hwAttrs = { + .hwiPriority = ~0, /* Lowest HWI priority */ + .swiPriority = 0, /* Lowest SWI priority */ + .xoscHfAlwaysNeeded = true, /* Keep XOSC dependency while in stanby */ + .globalCallback = NULL, /* No board specific callback */ + .globalEventMask = 0 /* No events subscribed to */ +}; + +/* + * =============================== SD =============================== + */ +#include +#include + +#if TI_SD_CONF_ENABLE + +#if !(TI_SPI_CONF_SPI0_ENABLE) +#error "SD driver requires SPI0 enabled" +#endif + +SDSPI_Object sdspiObjects[CC1350DK_7XD_SDCOUNT]; + +const SDSPI_HWAttrs sdspiHWAttrs[CC1350DK_7XD_SDCOUNT] = { + { + .spiIndex = CC1350DK_7XD_SPI0, + .spiCsGpioIndex = CC1350DK_7XD_SDCARD_CS + } +}; + +const SD_Config SD_config[CC1350DK_7XD_SDCOUNT] = { + { + .fxnTablePtr = &SDSPI_fxnTable, + .object = &sdspiObjects[CC1350DK_7XD_SDSPI0], + .hwAttrs = &sdspiHWAttrs[CC1350DK_7XD_SDSPI0] + }, +}; + +const uint_least8_t SD_count = CC1350DK_7XD_SDCOUNT; + +#endif /* TI_SD_CONF_ENABLE */ + +/* + * =============================== SPI DMA =============================== + */ +#include +#include + +#if TI_SPI_CONF_ENABLE + +SPICC26XXDMA_Object spiCC26XXDMAObjects[CC1350DK_7XD_SPICOUNT]; + +/* + * NOTE: The SPI instances below can be used by the SD driver to communicate + * with a SD card via SPI. The 'defaultTxBufValue' fields below are set to 0xFF + * to satisfy the SDSPI driver requirement. + */ +const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[CC1350DK_7XD_SPICOUNT] = { +#if TI_SPI_CONF_SPI0_ENABLE + { + .baseAddr = SSI0_BASE, + .intNum = INT_SSI0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .powerMngrId = PowerCC26XX_PERIPH_SSI0, + .defaultTxBufValue = 0xFF, + .rxChannelBitMask = 1< +#include + +TRNGCC26X0_Object trngCC26X0Object[CC1350DK_7XD_TRNGCOUNT]; + +const TRNGCC26X0_HWAttrs trngCC26X0HWAttrs[CC1350DK_7XD_TRNGCOUNT] = { + { + .swiPriority = 0, + .intPriority = ~0, + } +}; + +const TRNG_Config TRNG_config[] = { + { &trngCC26X0Object[0], &trngCC26X0HWAttrs[0] }, +}; + +const uint8_t TRNG_count = CC1350DK_7XD_TRNGCOUNT; + + +/* + * =============================== UART =============================== + */ +#include +#include + +#if TI_UART_CONF_ENABLE + +UARTCC26XX_Object uartCC26XXObjects[CC1350DK_7XD_UARTCOUNT]; + +uint8_t uartCC26XXRingBuffer[CC1350DK_7XD_UARTCOUNT][32]; + +const UARTCC26XX_HWAttrsV2 uartCC26XXHWAttrs[CC1350DK_7XD_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .baseAddr = UART0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UART0, + .intNum = INT_UART0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .txPin = CC1350DK_7XD_UART_TX, + .rxPin = CC1350DK_7XD_UART_RX, + .ctsPin = PIN_UNASSIGNED, + .rtsPin = PIN_UNASSIGNED, + .ringBufPtr = uartCC26XXRingBuffer[CC1350DK_7XD_UART0], + .ringBufSize = sizeof(uartCC26XXRingBuffer[CC1350DK_7XD_UART0]), + .txIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_1_8, + .rxIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_4_8, + .errorFxn = NULL + }, +#endif +}; + +const UART_Config UART_config[CC1350DK_7XD_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .fxnTablePtr = &UARTCC26XX_fxnTable, + .object = &uartCC26XXObjects[CC1350DK_7XD_UART0], + .hwAttrs = &uartCC26XXHWAttrs[CC1350DK_7XD_UART0] + }, +#endif +}; + +const uint_least8_t UART_count = CC1350DK_7XD_UARTCOUNT; + +#endif /* TI_UART_CONF_ENABLE */ + +/* + * =============================== UDMA =============================== + */ +#include + +UDMACC26XX_Object udmaObjects[CC1350DK_7XD_UDMACOUNT]; + +const UDMACC26XX_HWAttrs udmaHWAttrs[CC1350DK_7XD_UDMACOUNT] = { + { + .baseAddr = UDMA0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UDMA, + .intNum = INT_DMA_ERR, + .intPriority = ~0 + } +}; + +const UDMACC26XX_Config UDMACC26XX_config[CC1350DK_7XD_UDMACOUNT] = { + { + .object = &udmaObjects[CC1350DK_7XD_UDMA0], + .hwAttrs = &udmaHWAttrs[CC1350DK_7XD_UDMA0] + }, +}; + + + +/* + * =============================== Watchdog =============================== + */ +#include +#include + +WatchdogCC26XX_Object watchdogCC26XXObjects[CC1350DK_7XD_WATCHDOGCOUNT]; + +const WatchdogCC26XX_HWAttrs watchdogCC26XXHWAttrs[CC1350DK_7XD_WATCHDOGCOUNT] = { + { + .baseAddr = WDT_BASE, + .reloadValue = 1000 /* Reload value in milliseconds */ + }, +}; + +const Watchdog_Config Watchdog_config[CC1350DK_7XD_WATCHDOGCOUNT] = { + { + .fxnTablePtr = &WatchdogCC26XX_fxnTable, + .object = &watchdogCC26XXObjects[CC1350DK_7XD_WATCHDOG0], + .hwAttrs = &watchdogCC26XXHWAttrs[CC1350DK_7XD_WATCHDOG0] + }, +}; + +const uint_least8_t Watchdog_count = CC1350DK_7XD_WATCHDOGCOUNT; + +/* + * Board-specific initialization function to disable external flash. + * This function is defined in the file CC1350DK_7XD_fxns.c + */ +extern void Board_initHook(void); + +/* + * ======== CC1350DK_7XD_initGeneral ======== + */ +void CC1350DK_7XD_initGeneral(void) +{ + Power_init(); + + if (PIN_init(BoardGpioInitTable) != PIN_SUCCESS) { + /* Error with PIN_init */ + while (1); + } + + /* Perform board-specific initialization */ + Board_initHook(); +} diff --git a/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/CC1350DK_7XD.h b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/CC1350DK_7XD.h new file mode 100644 index 000000000..4c705abe5 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/CC1350DK_7XD.h @@ -0,0 +1,380 @@ +/* + * Copyright (c) 2015-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 CC1350DK_7XD.h + * + * @brief CC2650 LaunchPad Board Specific header file. + * + * The CC1350DK_7XD header file should be included in an application as + * follows: + * @code + * #include "CC1350DK_7XD.h" + * @endcode + * + * ============================================================================ + */ +#ifndef __CC1350DK_7XD_BOARD_H__ +#define __CC1350DK_7XD_BOARD_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "contiki-conf.h" + +/* Includes */ +#include +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) + +/* Externs */ +extern const PIN_Config BoardGpioInitTable[]; + +/* Defines */ +#define CC1350DK_7XD + +/* Mapping of pins to board signals using general board aliases + * + */ + +/* Analog Capable DIOs */ +#define CC1350DK_7XD_DIO23_ANALOG IOID_23 +#define CC1350DK_7XD_DIO24_ANALOG IOID_24 +#define CC1350DK_7XD_DIO25_ANALOG IOID_25 +#define CC1350DK_7XD_DIO26_ANALOG IOID_26 +#define CC1350DK_7XD_DIO27_ANALOG IOID_27 +#define CC1350DK_7XD_DIO28_ANALOG IOID_28 +#define CC1350DK_7XD_DIO29_ANALOG IOID_29 +#define CC1350DK_7XD_DIO30_ANALOG IOID_30 + +/* Digital IOs */ +#define CC1350DK_7XD_DIO0 IOID_0 +#define CC1350DK_7XD_DIO1_RFSW IOID_1 +#define CC1350DK_7XD_DIO12 IOID_12 +#define CC1350DK_7XD_DIO15 IOID_15 +#define CC1350DK_7XD_DIO16_TDO IOID_16 +#define CC1350DK_7XD_DIO17_TDI IOID_17 +#define CC1350DK_7XD_DIO21 IOID_21 +#define CC1350DK_7XD_DIO22 IOID_22 + +/* Discrete Inputs */ +#define CC1350DK_7XD_PIN_KEY_SELECT IOID_11 +#define CC1350DK_7XD_PIN_KEY_UP IOID_19 +#define CC1350DK_7XD_PIN_KEY_DOWN IOID_12 +#define CC1350DK_7XD_PIN_KEY_LEFT IOID_15 +#define CC1350DK_7XD_PIN_KEY_RIGHT IOID_18 + +/* GPIO */ +#define CC1350DK_7XD_GPIO_LED_ON 1 +#define CC1350DK_7XD_GPIO_LED_OFF 0 + +/* I2C */ +#define CC1350DK_7XD_I2C0_SCL0 PIN_UNASSIGNED +#define CC1350DK_7XD_I2C0_SDA0 PIN_UNASSIGNED + +/* LEDs */ +#define CC1350DK_7XD_PIN_LED_ON 1 +#define CC1350DK_7XD_PIN_LED_OFF 0 +#define CC1350DK_7XD_PIN_LED1 IOID_25 +#define CC1350DK_7XD_PIN_LED2 IOID_27 +#define CC1350DK_7XD_PIN_LED3 IOID_7 +#define CC1350DK_7XD_PIN_LED4 IOID_6 + +/* PWM Outputs */ +#define CC1350DK_7XD_PWMPIN0 CC1350DK_7XD_PIN_LED1 +#define CC1350DK_7XD_PWMPIN1 CC1350DK_7XD_PIN_LED2 +#define CC1350DK_7XD_PWMPIN2 PIN_UNASSIGNED +#define CC1350DK_7XD_PWMPIN3 PIN_UNASSIGNED +#define CC1350DK_7XD_PWMPIN4 PIN_UNASSIGNED +#define CC1350DK_7XD_PWMPIN5 PIN_UNASSIGNED +#define CC1350DK_7XD_PWMPIN6 PIN_UNASSIGNED +#define CC1350DK_7XD_PWMPIN7 PIN_UNASSIGNED + +/* SPI Board */ +#define CC1350DK_7XD_SPI0_MISO IOID_8 +#define CC1350DK_7XD_SPI0_MOSI IOID_9 +#define CC1350DK_7XD_SPI0_CLK IOID_10 +#define CC1350DK_7XD_SPI0_CSN PIN_UNASSIGNED +#define CC1350DK_7XD_SPI1_MISO PIN_UNASSIGNED +#define CC1350DK_7XD_SPI1_MOSI PIN_UNASSIGNED +#define CC1350DK_7XD_SPI1_CLK PIN_UNASSIGNED +#define CC1350DK_7XD_SPI1_CSN PIN_UNASSIGNED + +/* UART Board */ +#define CC1350DK_7XD_UART_RX IOID_2 +#define CC1350DK_7XD_UART_TX IOID_3 +#define CC1350DK_7XD_UART_CTS IOID_22 +#define CC1350DK_7XD_UART_RTS IOID_21 + +/* SD Card */ +#define CC1350DK_7XD_SDCARD_CS IOID_30 + +/* Ambient Light Sensor */ +#define CC1350DK_7XD_ALS_OUT IOID_23 +#define CC1350DK_7XD_ALS_PWR IOID_26 + +/* Accelerometer */ +#define CC1350DK_7XD_ACC_PWR IOID_20 +#define CC1350DK_7XD_ACC_CS IOID_24 + +/*! + * @brief Initialize the general board specific settings + * + * This function initializes the general board specific settings. + */ +void CC1350DK_7XD_initGeneral(void); + +/*! + * @brief Turn off the external flash on LaunchPads + * + */ +void CC1350DK_7XD_shutDownExtFlash(void); + +/*! + * @brief Wake up the external flash present on the board files + * + * This function toggles the chip select for the amount of time needed + * to wake the chip up. + */ +void CC1350DK_7XD_wakeUpExtFlash(void); + +/*! + * @def CC1350DK_7XD_ADCBufName + * @brief Enum of ADCs + */ +typedef enum CC1350DK_7XD_ADCBufName { + CC1350DK_7XD_ADCBUF0 = 0, + + CC1350DK_7XD_ADCBUFCOUNT +} CC1350DK_7XD_ADCBufName; + +/*! + * @def CC1350DK_7XD_ADCBuf0ChannelName + * @brief Enum of ADCBuf channels + */ +typedef enum CC1350DK_7XD_ADCBuf0ChannelName { + CC1350DK_7XD_ADCBUF0CHANNELADCALS = 0, + CC1350DK_7XD_ADCBUF0CHANNELVDDS, + CC1350DK_7XD_ADCBUF0CHANNELDCOUPL, + CC1350DK_7XD_ADCBUF0CHANNELVSS, + + CC1350DK_7XD_ADCBUF0CHANNELCOUNT +} CC1350DK_7XD_ADCBuf0ChannelName; + +/*! + * @def CC1350DK_7XD_ADCName + * @brief Enum of ADCs + */ +typedef enum CC1350DK_7XD_ADCName { + CC1350DK_7XD_ADCALS = 0, + CC1350DK_7XD_ADCDCOUPL, + CC1350DK_7XD_ADCVSS, + CC1350DK_7XD_ADCVDDS, + + CC1350DK_7XD_ADCCOUNT +} CC1350DK_7XD_ADCName; + +/*! + * @def CC1350DK_7XD_CryptoName + * @brief Enum of Crypto names + */ +typedef enum CC1350DK_7XD_CryptoName { + CC1350DK_7XD_CRYPTO0 = 0, + + CC1350DK_7XD_CRYPTOCOUNT +} CC1350DK_7XD_CryptoName; + +/*! + * @def CC1350DK_7XD_GPIOName + * @brief Enum of GPIO names + */ +typedef enum CC1350DK_7XD_GPIOName { + CC1350DK_7XD_GPIO_KEY_SELECT = 0, + CC1350DK_7XD_GPIO_KEY_UP, + CC1350DK_7XD_GPIO_KEY_DOWN, + CC1350DK_7XD_GPIO_KEY_LEFT, + CC1350DK_7XD_GPIO_KEY_RIGHT, + CC1350DK_7XD_SPI_MASTER_READY, + CC1350DK_7XD_SPI_SLAVE_READY, + CC1350DK_7XD_GPIO_LED1, + CC1350DK_7XD_GPIO_LED2, + CC1350DK_7XD_GPIO_LED3, + CC1350DK_7XD_GPIO_LED4, + CC1350DK_7XD_GPIO_SDCARD_CS, + CC1350DK_7XD_GPIO_ACC_CS, + + CC1350DK_7XD_GPIOCOUNT +} CC1350DK_7XD_GPIOName; + +/*! + * @def CC1350DK_7XD_GPTimerName + * @brief Enum of GPTimer parts + */ +typedef enum CC1350DK_7XD_GPTimerName { + CC1350DK_7XD_GPTIMER0A = 0, + CC1350DK_7XD_GPTIMER0B, + CC1350DK_7XD_GPTIMER1A, + CC1350DK_7XD_GPTIMER1B, + CC1350DK_7XD_GPTIMER2A, + CC1350DK_7XD_GPTIMER2B, + CC1350DK_7XD_GPTIMER3A, + CC1350DK_7XD_GPTIMER3B, + + CC1350DK_7XD_GPTIMERPARTSCOUNT +} CC1350DK_7XD_GPTimerName; + +/*! + * @def CC1350DK_7XD_GPTimers + * @brief Enum of GPTimers + */ +typedef enum CC1350DK_7XD_GPTimers { + CC1350DK_7XD_GPTIMER0 = 0, + CC1350DK_7XD_GPTIMER1, + CC1350DK_7XD_GPTIMER2, + CC1350DK_7XD_GPTIMER3, + + CC1350DK_7XD_GPTIMERCOUNT +} CC1350DK_7XD_GPTimers; + +/*! + * @def CC1350DK_7XD_I2CName + * @brief Enum of I2C names + */ +typedef enum CC1350DK_7XD_I2CName { +#if TI_I2C_CONF_I2C0_ENABLE + CC1350DK_7XD_I2C0 = 0, +#endif + + CC1350DK_7XD_I2CCOUNT +} CC1350DK_7XD_I2CName; + +/*! + * @def CC1350DK_7XD_NVSName + * @brief Enum of NVS names + */ +typedef enum CC1350DK_7XD_NVSName { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + CC1350DK_7XD_NVSCC26XX0 = 0, +#endif + + CC1350DK_7XD_NVSCOUNT +} CC1350DK_7XD_NVSName; + +/*! + * @def CC1350DK_7XD_PWMName + * @brief Enum of PWM outputs + */ +typedef enum CC1350DK_7XD_PWMName { + CC1350DK_7XD_PWM0 = 0, + CC1350DK_7XD_PWM1, + CC1350DK_7XD_PWM2, + CC1350DK_7XD_PWM3, + CC1350DK_7XD_PWM4, + CC1350DK_7XD_PWM5, + CC1350DK_7XD_PWM6, + CC1350DK_7XD_PWM7, + + CC1350DK_7XD_PWMCOUNT +} CC1350DK_7XD_PWMName; + +/*! + * @def CC1350DK_7XD_SDName + * @brief Enum of SD names + */ +typedef enum CC1350DK_7XD_SDName { + CC1350DK_7XD_SDSPI0 = 0, + + CC1350DK_7XD_SDCOUNT +} CC1350DK_7XD_SDName; + +/*! + * @def CC1350DK_7XD_SPIName + * @brief Enum of SPI names + */ +typedef enum CC1350DK_7XD_SPIName { +#if TI_SPI_CONF_SPI0_ENABLE + CC1350DK_7XD_SPI0 = 0, +#endif +#if TI_SPI_CONF_SPI1_ENABLE + CC1350DK_7XD_SPI1, +#endif + + CC1350DK_7XD_SPICOUNT +} CC1350DK_7XD_SPIName; + +/*! + * @def CC1350DK_7XD_TRNGName + * @brief Enum of TRNGs + */ +typedef enum CC1350DK_7XD_TRNGName { + CC1350DK_7XD_TRNG0 = 0, + + CC1350DK_7XD_TRNGCOUNT +} CC1350DK_7XD_TRNGName; + +/*! + * @def CC1350DK_7XD_UARTName + * @brief Enum of UARTs + */ +typedef enum CC1350DK_7XD_UARTName { +#if TI_UART_CONF_UART0_ENABLE + CC1350DK_7XD_UART0 = 0, +#endif + + CC1350DK_7XD_UARTCOUNT +} CC1350DK_7XD_UARTName; + +/*! + * @def CC1350DK_7XD_UDMAName + * @brief Enum of DMA buffers + */ +typedef enum CC1350DK_7XD_UDMAName { + CC1350DK_7XD_UDMA0 = 0, + + CC1350DK_7XD_UDMACOUNT +} CC1350DK_7XD_UDMAName; + +/*! + * @def CC1350DK_7XD_WatchdogName + * @brief Enum of Watchdogs + */ +typedef enum CC1350DK_7XD_WatchdogName { + CC1350DK_7XD_WATCHDOG0 = 0, + + CC1350DK_7XD_WATCHDOGCOUNT +} CC1350DK_7XD_WatchdogName; + +#ifdef __cplusplus +} +#endif + +#endif /* __CC1350DK_7XD_BOARD_H__ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/CC1350DK_7XD_fxns.c b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/CC1350DK_7XD_fxns.c new file mode 100644 index 000000000..b7983730a --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/CC1350DK_7XD_fxns.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +/* + * ======== CC1350DK_7XD_fxns.c ======== + * This file contains the board-specific initialization functions. + */ + +#include +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/cpu.h) + +#include + +#include "Board.h" + +/* + * ======== CC1350DK_7XD_wakeUpExtFlash ======== + */ +void CC1350DK_7XD_wakeUpExtFlash(void) +{ + /* No external flash on CC1350DK_7XD */ +} + +/* + * ======== CC1350DK_7XD_shutDownExtFlash ======== + */ +void CC1350DK_7XD_shutDownExtFlash(void) +{ + /* No external flash on CC1350DK_7XD */ +} + +/* + * ======== Board_initHook ======== + * Called by Board_init() to perform board-specific initialization. + */ +void Board_initHook() +{ + CC1350DK_7XD_shutDownExtFlash(); +} diff --git a/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/Makefile.cc13x0 b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/Makefile.cc13x0 new file mode 100644 index 000000000..8b034de05 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc13x0/Makefile.cc13x0 @@ -0,0 +1,21 @@ +################################################################################ +# SimpleLink Device makefile + +SUBFAMILY = cc13x0-cc26x0 +DEVICE_FAMILY = CC13X0 +DEVICE_LINE = CC13XX +DEVICE = CC1350 + +BOARD_SOURCEFILES += CC1350DK_7XD.c CC1350DK_7XD_fxns.c + +SUPPORTS_PROP_MODE = 1 +SUPPORTS_IEEE_MODE = 1 +SUPPORTS_BLE_BEACON = 1 + +SUPPORTS_HIGH_PA = 0 + +### Signal that we can be programmed with cc2538-bsl +BOARD_SUPPORTS_BSL = 1 + +# Include the common board makefile +include $(FAMILY_PATH)/srf06/Makefile.srf06 diff --git a/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/Board.h new file mode 100644 index 000000000..c42d3a169 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/Board.h @@ -0,0 +1,175 @@ +/* + * Copyright (c) 2015-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 __BOARD_H +#define __BOARD_H + +#define Board_CC2650DK_7ID +#define BOARD_STRING "TI SmartRF06EB + CC26x0 EM" + +#ifdef __cplusplus +extern "C" { +#endif + +#include "CC2650DK_7ID.h" + +#define Board_initGeneral() CC2650DK_7ID_initGeneral() +#define Board_shutDownExtFlash() CC2650DK_7ID_shutDownExtFlash() +#define Board_wakeUpExtFlash() CC2650DK_7ID_wakeUpExtFlash() + +/* These #defines allow us to reuse TI-RTOS across other device families */ + +#define Board_ADCALS CC2650DK_7ID_ADCALS + +#define Board_ADC0 CC2650DK_7ID_ADCVDDS +#define Board_ADC1 CC2650DK_7ID_ADCALS + +#define Board_ADCBUF0 CC2650DK_7ID_ADCBUF0 +#define Board_ADCBUF0CHANNEL0 CC2650DK_7ID_ADCBUF0CHANNELVDDS +#define Board_ADCBUF0CHANNEL1 CC2650DK_7ID_ADCBUF0CHANNELADCALS + +#define Board_CRYPTO0 CC2650DK_7ID_CRYPTO0 + +#define Board_DIO0 CC2650DK_7ID_DIO0 +#define Board_DIO1_RFSW CC2650DK_7ID_DIO1_RFSW +#define Board_DIO12 CC2650DK_7ID_DIO12 +#define Board_DIO15 CC2650DK_7ID_DIO15 +#define Board_DIO16_TDO CC2650DK_7ID_DIO16_TDO +#define Board_DIO17_TDI CC2650DK_7ID_DIO17_TDI +#define Board_DIO21 CC2650DK_7ID_DIO21 +#define Board_DIO22 CC2650DK_7ID_DIO22 + +#define Board_DIO23_ANALOG CC2650DK_7ID_DIO23_ANALOG +#define Board_DIO24_ANALOG CC2650DK_7ID_DIO24_ANALOG +#define Board_DIO25_ANALOG CC2650DK_7ID_DIO25_ANALOG +#define Board_DIO26_ANALOG CC2650DK_7ID_DIO26_ANALOG +#define Board_DIO27_ANALOG CC2650DK_7ID_DIO27_ANALOG +#define Board_DIO28_ANALOG CC2650DK_7ID_DIO28_ANALOG +#define Board_DIO29_ANALOG CC2650DK_7ID_DIO29_ANALOG +#define Board_DIO30_ANALOG CC2650DK_7ID_DIO30_ANALOG + +#define Board_GPIO_BTN0 CC2650DK_7ID_PIN_KEY_SELECT +#define Board_GPIO_BTN1 CC2650DK_7ID_PIN_KEY_UP +#define Board_GPIO_BTN2 CC2650DK_7ID_PIN_KEY_DOWN +#define Board_GPIO_BTN3 CC2650DK_7ID_PIN_KEY_LEFT +#define Board_GPIO_BTN4 CC2650DK_7ID_PIN_KEY_RIGHT +#define Board_GPIO_LED0 CC2650DK_7ID_PIN_LED1 +#define Board_GPIO_LED1 CC2650DK_7ID_PIN_LED2 +#define Board_GPIO_LED2 CC2650DK_7ID_PIN_LED3 +#define Board_GPIO_LED3 CC2650DK_7ID_PIN_LED4 +#define Board_GPIO_LED_ON CC2650DK_7ID_GPIO_LED_ON +#define Board_GPIO_LED_OFF CC2650DK_7ID_GPIO_LED_OFF + +#define Board_GPTIMER0A CC2650DK_7ID_GPTIMER0A +#define Board_GPTIMER0B CC2650DK_7ID_GPTIMER0B +#define Board_GPTIMER1A CC2650DK_7ID_GPTIMER1A +#define Board_GPTIMER1B CC2650DK_7ID_GPTIMER1B +#define Board_GPTIMER2A CC2650DK_7ID_GPTIMER2A +#define Board_GPTIMER2B CC2650DK_7ID_GPTIMER2B +#define Board_GPTIMER3A CC2650DK_7ID_GPTIMER3A +#define Board_GPTIMER3B CC2650DK_7ID_GPTIMER3B + +#define Board_I2C0 CC2650DK_7ID_I2C0 + +#define Board_NVSINTERNAL CC2650DK_7ID_NVSCC26XX0 + +#define Board_KEY_SELECT CC2650DK_7ID_PIN_KEY_SELECT +#define Board_KEY_UP CC2650DK_7ID_PIN_KEY_UP +#define Board_KEY_DOWN CC2650DK_7ID_PIN_KEY_DOWN +#define Board_KEY_LEFT CC2650DK_7ID_PIN_KEY_LEFT +#define Board_KEY_RIGHT CC2650DK_7ID_PIN_KEY_RIGHT + +#define Board_PIN_BUTTON0 CC2650DK_7ID_PIN_KEY_SELECT +#define Board_PIN_BUTTON1 CC2650DK_7ID_PIN_KEY_UP +#define Board_PIN_BUTTON2 CC2650DK_7ID_PIN_KEY_DOWN +#define Board_PIN_BUTTON3 CC2650DK_7ID_PIN_KEY_LEFT +#define Board_PIN_BUTTON4 CC2650DK_7ID_PIN_KEY_RIGHT +#define Board_PIN_BTN1 CC2650DK_7ID_PIN_KEY_SELECT +#define Board_PIN_BTN2 CC2650DK_7ID_PIN_KEY_UP +#define Board_PIN_BTN3 CC2650DK_7ID_PIN_KEY_DOWN +#define Board_PIN_BTN4 CC2650DK_7ID_PIN_KEY_LEFT +#define Board_PIN_BTN5 CC2650DK_7ID_PIN_KEY_RIGHT +#define Board_PIN_LED0 CC2650DK_7ID_PIN_LED1 +#define Board_PIN_LED1 CC2650DK_7ID_PIN_LED2 +#define Board_PIN_LED2 CC2650DK_7ID_PIN_LED3 +#define Board_PIN_LED3 CC2650DK_7ID_PIN_LED4 + +#define Board_PWM0 CC2650DK_7ID_PWM0 +#define Board_PWM1 CC2650DK_7ID_PWM1 +#define Board_PWM2 CC2650DK_7ID_PWM2 +#define Board_PWM3 CC2650DK_7ID_PWM3 +#define Board_PWM4 CC2650DK_7ID_PWM4 +#define Board_PWM5 CC2650DK_7ID_PWM5 +#define Board_PWM6 CC2650DK_7ID_PWM6 +#define Board_PWM7 CC2650DK_7ID_PWM7 + +#define Board_SD0 CC2650DK_7ID_SDSPI0 + +#define Board_SPI0 CC2650DK_7ID_SPI0 +#define Board_SPI0_MISO CC2650DK_7ID_SPI0_MISO +#define Board_SPI0_MOSI CC2650DK_7ID_SPI0_MOSI +#define Board_SPI0_CLK CC2650DK_7ID_SPI0_CLK +#define Board_SPI0_CSN CC2650DK_7ID_SPI0_CSN +#define Board_SPI1 CC2650DK_7ID_SPI1 +#define Board_SPI1_MISO CC2650DK_7ID_SPI1_MISO +#define Board_SPI1_MOSI CC2650DK_7ID_SPI1_MOSI +#define Board_SPI1_CLK CC2650DK_7ID_SPI1_CLK +#define Board_SPI1_CSN CC2650DK_7ID_SPI1_CSN +#define Board_FLASH_CS_ON 0 +#define Board_FLASH_CS_OFF 1 + +#define Board_SPI_MASTER CC2650DK_7ID_SPI0 +#define Board_SPI_SLAVE CC2650DK_7ID_SPI0 +#define Board_SPI_MASTER_READY CC2650DK_7ID_SPI_MASTER_READY +#define Board_SPI_SLAVE_READY CC2650DK_7ID_SPI_SLAVE_READY + +#define Board_UART0 CC2650DK_7ID_UART0 + +#define Board_WATCHDOG0 CC2650DK_7ID_WATCHDOG0 + +#define Board_SDCARD_CS CC2650DK_7ID_SDCARD_CS + +#define Board_LCD_MODE CC2650DK_7ID_LCD_MODE +#define Board_LCD_RST CC2650DK_7ID_LCD_RST +#define Board_LCD_CS CC2650DK_7ID_LCD_CS + +#define Board_ALS_OUT CC2650DK_7ID_ALS_OUT +#define Board_ALS_PWR CC2650DK_7ID_ALS_PWR + +#define Board_ACC_PWR CC2650DK_7ID_ACC_PWR +#define Board_ACC_CS CC2650DK_7ID_ACC_CS + +#ifdef __cplusplus +} +#endif + +#endif /* __BOARD_H */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/CC2650DK_7ID.c b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/CC2650DK_7ID.c new file mode 100644 index 000000000..4d0115d38 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/CC2650DK_7ID.c @@ -0,0 +1,720 @@ +/* + * Copyright (c) 2016-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +/* + * ====================== CC2650DK_7ID.c =================================== + * This file is responsible for setting up the board specific items for the + * CC2650DK_7ID board. + */ + +#include +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/udma.h) +#include DeviceFamily_constructPath(inc/hw_ints.h) +#include DeviceFamily_constructPath(inc/hw_memmap.h) + +#include "CC2650DK_7ID.h" + +/* + * =============================== ADCBuf =============================== + */ +#include +#include + +ADCBufCC26XX_Object adcBufCC26xxObjects[CC2650DK_7ID_ADCBUFCOUNT]; + +/* + * This table converts a virtual adc channel into a dio and internal analogue + * input signal. This table is necessary for the functioning of the adcBuf + * driver. Comment out unused entries to save flash. Dio and internal signal + * pairs are hardwired. Do not remap them in the table. You may reorder entire + * entries. The mapping of dio and internal signals is package dependent. + */ +const ADCBufCC26XX_AdcChannelLutEntry ADCBufCC26XX_adcChannelLut[CC2650DK_7ID_ADCBUF0CHANNELCOUNT] = { + {CC2650DK_7ID_ALS_OUT, ADC_COMPB_IN_AUXIO7}, + {PIN_UNASSIGNED, ADC_COMPB_IN_DCOUPL}, + {PIN_UNASSIGNED, ADC_COMPB_IN_VSS}, + {PIN_UNASSIGNED, ADC_COMPB_IN_VDDS}, +}; + +const ADCBufCC26XX_HWAttrs adcBufCC26xxHWAttrs[CC2650DK_7ID_ADCBUFCOUNT] = { + { + .intPriority = ~0, + .swiPriority = 0, + .adcChannelLut = ADCBufCC26XX_adcChannelLut, + .gpTimerUnit = CC2650DK_7ID_GPTIMER0A, + .gptDMAChannelMask = 1 << UDMA_CHAN_TIMER0_A, + } +}; + +const ADCBuf_Config ADCBuf_config[CC2650DK_7ID_ADCBUFCOUNT] = { + { + &ADCBufCC26XX_fxnTable, + &adcBufCC26xxObjects[CC2650DK_7ID_ADCBUF0], + &adcBufCC26xxHWAttrs[CC2650DK_7ID_ADCBUF0] + }, +}; + +const uint_least8_t ADCBuf_count = CC2650DK_7ID_ADCBUFCOUNT; + +/* + * =============================== ADC =============================== + */ +#include +#include + +ADCCC26XX_Object adcCC26xxObjects[CC2650DK_7ID_ADCCOUNT]; + +const ADCCC26XX_HWAttrs adcCC26xxHWAttrs[CC2650DK_7ID_ADCCOUNT] = { + { + .adcDIO = CC2650DK_7ID_DIO23_ANALOG, + .adcCompBInput = ADC_COMPB_IN_AUXIO7, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_DCOUPL, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_VSS, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + }, + { + .adcDIO = PIN_UNASSIGNED, + .adcCompBInput = ADC_COMPB_IN_VDDS, + .refSource = ADCCC26XX_FIXED_REFERENCE, + .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US, + .inputScalingEnabled = true, + .triggerSource = ADCCC26XX_TRIGGER_MANUAL, + .returnAdjustedVal = false + } +}; + +const ADC_Config ADC_config[CC2650DK_7ID_ADCCOUNT] = { + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC2650DK_7ID_ADCALS], &adcCC26xxHWAttrs[CC2650DK_7ID_ADCALS]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC2650DK_7ID_ADCDCOUPL], &adcCC26xxHWAttrs[CC2650DK_7ID_ADCDCOUPL]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC2650DK_7ID_ADCVSS], &adcCC26xxHWAttrs[CC2650DK_7ID_ADCVSS]}, + {&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC2650DK_7ID_ADCVDDS], &adcCC26xxHWAttrs[CC2650DK_7ID_ADCVDDS]}, +}; + +const uint_least8_t ADC_count = CC2650DK_7ID_ADCCOUNT; + +/* + * =============================== Crypto =============================== + */ +#include + +CryptoCC26XX_Object cryptoCC26XXObjects[CC2650DK_7ID_CRYPTOCOUNT]; + +const CryptoCC26XX_HWAttrs cryptoCC26XXHWAttrs[CC2650DK_7ID_CRYPTOCOUNT] = { + { + .baseAddr = CRYPTO_BASE, + .powerMngrId = PowerCC26XX_PERIPH_CRYPTO, + .intNum = INT_CRYPTO_RESULT_AVAIL_IRQ, + .intPriority = ~0, + } +}; + +const CryptoCC26XX_Config CryptoCC26XX_config[CC2650DK_7ID_CRYPTOCOUNT] = { + { + .object = &cryptoCC26XXObjects[CC2650DK_7ID_CRYPTO0], + .hwAttrs = &cryptoCC26XXHWAttrs[CC2650DK_7ID_CRYPTO0] + }, +}; + +/* + * =============================== GPIO =============================== + */ +#include +#include + +/* + * Array of Pin configurations + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC2650DK_7ID.h + * NOTE: Pins not used for interrupts should be placed at the end of the + * array. Callback entries can be omitted from callbacks array to + * reduce memory usage. + */ +GPIO_PinConfig gpioPinConfigs[] = { + /* Input pins */ + GPIOCC26XX_DIO_11 | GPIO_DO_NOT_CONFIG, /* Key Select */ + GPIOCC26XX_DIO_19 | GPIO_DO_NOT_CONFIG, /* Key Up */ + GPIOCC26XX_DIO_12 | GPIO_DO_NOT_CONFIG, /* Key Down */ + GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG, /* Key Left */ + GPIOCC26XX_DIO_18 | GPIO_DO_NOT_CONFIG, /* Key Right */ + + GPIOCC26XX_DIO_15 | GPIO_DO_NOT_CONFIG, /* CC2650DK_7ID_SPI_MASTER_READY */ + GPIOCC26XX_DIO_21 | GPIO_DO_NOT_CONFIG, /* CC2650DK_7ID_SPI_SLAVE_READY */ + + /* Output pins */ + GPIOCC26XX_DIO_25 | GPIO_DO_NOT_CONFIG, /* LED 1 */ + GPIOCC26XX_DIO_27 | GPIO_DO_NOT_CONFIG, /* LED 2 */ + GPIOCC26XX_DIO_07 | GPIO_DO_NOT_CONFIG, /* LED 3 */ + GPIOCC26XX_DIO_06 | GPIO_DO_NOT_CONFIG, /* LED 4 */ + + /* SDCARD */ + GPIOCC26XX_DIO_30 | GPIO_DO_NOT_CONFIG, /* SPI chip select */ + + /* Accelerometer */ + GPIOCC26XX_DIO_24 | GPIO_DO_NOT_CONFIG, /* SPI chip select */ +}; + +/* + * Array of callback function pointers + * NOTE: The order of the pin configurations must coincide with what was + * defined in CC2650_LAUNCH.h + * NOTE: Pins not used for interrupts can be omitted from callbacks array to + * reduce memory usage (if placed at end of gpioPinConfigs array). + */ +GPIO_CallbackFxn gpioCallbackFunctions[] = { + NULL, /* Button 0 */ + NULL, /* Button 1 */ + NULL, /* CC2650DK_7ID_SPI_MASTER_READY */ + NULL, /* CC2650DK_7ID_SPI_SLAVE_READY */ +}; + +const GPIOCC26XX_Config GPIOCC26XX_config = { + .pinConfigs = (GPIO_PinConfig *)gpioPinConfigs, + .callbacks = (GPIO_CallbackFxn *)gpioCallbackFunctions, + .numberOfPinConfigs = CC2650DK_7ID_GPIOCOUNT, + .numberOfCallbacks = sizeof(gpioCallbackFunctions)/sizeof(GPIO_CallbackFxn), + .intPriority = (~0) +}; + +/* + * =============================== GPTimer =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include + +GPTimerCC26XX_Object gptimerCC26XXObjects[CC2650DK_7ID_GPTIMERCOUNT]; + +const GPTimerCC26XX_HWAttrs gptimerCC26xxHWAttrs[CC2650DK_7ID_GPTIMERPARTSCOUNT] = { + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0A, }, + { .baseAddr = GPT0_BASE, .intNum = INT_GPT0B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT0, .pinMux = GPT_PIN_0B, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1A, }, + { .baseAddr = GPT1_BASE, .intNum = INT_GPT1B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT1, .pinMux = GPT_PIN_1B, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2A, }, + { .baseAddr = GPT2_BASE, .intNum = INT_GPT2B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT2, .pinMux = GPT_PIN_2B, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3A, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3A, }, + { .baseAddr = GPT3_BASE, .intNum = INT_GPT3B, .intPriority = (~0), .powerMngrId = PowerCC26XX_PERIPH_GPT3, .pinMux = GPT_PIN_3B, }, +}; + +const GPTimerCC26XX_Config GPTimerCC26XX_config[CC2650DK_7ID_GPTIMERPARTSCOUNT] = { + { &gptimerCC26XXObjects[CC2650DK_7ID_GPTIMER0], &gptimerCC26xxHWAttrs[CC2650DK_7ID_GPTIMER0A], GPT_A }, + { &gptimerCC26XXObjects[CC2650DK_7ID_GPTIMER0], &gptimerCC26xxHWAttrs[CC2650DK_7ID_GPTIMER0B], GPT_B }, + { &gptimerCC26XXObjects[CC2650DK_7ID_GPTIMER1], &gptimerCC26xxHWAttrs[CC2650DK_7ID_GPTIMER1A], GPT_A }, + { &gptimerCC26XXObjects[CC2650DK_7ID_GPTIMER1], &gptimerCC26xxHWAttrs[CC2650DK_7ID_GPTIMER1B], GPT_B }, + { &gptimerCC26XXObjects[CC2650DK_7ID_GPTIMER2], &gptimerCC26xxHWAttrs[CC2650DK_7ID_GPTIMER2A], GPT_A }, + { &gptimerCC26XXObjects[CC2650DK_7ID_GPTIMER2], &gptimerCC26xxHWAttrs[CC2650DK_7ID_GPTIMER2B], GPT_B }, + { &gptimerCC26XXObjects[CC2650DK_7ID_GPTIMER3], &gptimerCC26xxHWAttrs[CC2650DK_7ID_GPTIMER3A], GPT_A }, + { &gptimerCC26XXObjects[CC2650DK_7ID_GPTIMER3], &gptimerCC26xxHWAttrs[CC2650DK_7ID_GPTIMER3B], GPT_B }, +}; + +/* + * =============================== I2C =============================== +*/ +#include +#include + +#if TI_I2C_CONF_ENABLE + +I2CCC26XX_Object i2cCC26xxObjects[CC2650DK_7ID_I2CCOUNT]; + +const I2CCC26XX_HWAttrsV1 i2cCC26xxHWAttrs[CC2650DK_7ID_I2CCOUNT] = { +#if TI_I2C_CONF_I2C0_ENABLE + { + .baseAddr = I2C0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_I2C0, + .intNum = INT_I2C_IRQ, + .intPriority = ~0, + .swiPriority = 0, + .sdaPin = CC2650DK_7ID_I2C0_SDA0, + .sclPin = CC2650DK_7ID_I2C0_SCL0, + }, +#endif +}; + +const I2C_Config I2C_config[CC2650DK_7ID_I2CCOUNT] = { +#if TI_I2C_CONF_I2C0_ENABLE + { + .fxnTablePtr = &I2CCC26XX_fxnTable, + .object = &i2cCC26xxObjects[CC2650DK_7ID_I2C0], + .hwAttrs = &i2cCC26xxHWAttrs[CC2650DK_7ID_I2C0] + }, +#endif +}; + +const uint_least8_t I2C_count = CC2650DK_7ID_I2CCOUNT; + +#endif /* TI_I2C_CONF_ENABLE */ + +/* + * =============================== NVS =============================== + */ +#include +#include +#include + +#define NVS_REGIONS_BASE 0x1A000 +#define SECTORSIZE 0x1000 +#define REGIONSIZE (SECTORSIZE * 4) + +#if TI_NVS_CONF_ENABLE + +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + +/* + * Reserve flash sectors for NVS driver use by placing an uninitialized byte + * array at the desired flash address. + */ +#if defined(__TI_COMPILER_VERSION__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +#pragma LOCATION(flashBuf, NVS_REGIONS_BASE); +#pragma NOINIT(flashBuf); +static char flashBuf[REGIONSIZE]; + +#elif defined(__IAR_SYSTEMS_ICC__) + +/* + * Place uninitialized array at NVS_REGIONS_BASE + */ +static __no_init char flashBuf[REGIONSIZE] @ NVS_REGIONS_BASE; + +#elif defined(__GNUC__) + +/* + * Place the flash buffers in the .nvs section created in the gcc linker file. + * The .nvs section enforces alignment on a sector boundary but may + * be placed anywhere in flash memory. If desired the .nvs section can be set + * to a fixed address by changing the following in the gcc linker file: + * + * .nvs (FIXED_FLASH_ADDR) (NOLOAD) : AT (FIXED_FLASH_ADDR) { + * *(.nvs) + * } > REGION_TEXT + */ +__attribute__ ((section (".nvs"))) +static char flashBuf[REGIONSIZE]; + +#endif + +/* Allocate objects for NVS Internal Regions */ +NVSCC26XX_Object nvsCC26xxObjects[1]; + +/* Hardware attributes for NVS Internal Regions */ +const NVSCC26XX_HWAttrs nvsCC26xxHWAttrs[1] = { + { + .regionBase = (void *)flashBuf, + .regionSize = REGIONSIZE, + }, +}; + +#endif /* TI_NVS_CONF_NVS_INTERNAL_ENABLE */ + +/* NVS Region index 0 and 1 refer to NVS and NVS SPI respectively */ +const NVS_Config NVS_config[CC2650DK_7ID_NVSCOUNT] = { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + { + .fxnTablePtr = &NVSCC26XX_fxnTable, + .object = &nvsCC26xxObjects[0], + .hwAttrs = &nvsCC26xxHWAttrs[0], + }, +#endif +}; + +const uint_least8_t NVS_count = CC2650DK_7ID_NVSCOUNT; + +#endif /* TI_NVS_CONF_ENABLE */ + +/* + * =============================== PIN =============================== + */ +#include +#include + +const PIN_Config BoardGpioInitTable[] = { + + CC2650DK_7ID_PIN_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC2650DK_7ID_PIN_LED2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC2650DK_7ID_PIN_LED3 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC2650DK_7ID_PIN_LED4 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */ + CC2650DK_7ID_PIN_KEY_SELECT | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC2650DK_7ID_PIN_KEY_UP | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC2650DK_7ID_PIN_KEY_DOWN | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC2650DK_7ID_PIN_KEY_LEFT | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC2650DK_7ID_PIN_KEY_UP | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS, /* Button is active low */ + CC2650DK_7ID_SDCARD_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ + CC2650DK_7ID_ACC_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, /* External flash chip select */ + CC2650DK_7ID_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */ + CC2650DK_7ID_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */ + CC2650DK_7ID_SPI0_MOSI | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master out - slave in */ + CC2650DK_7ID_SPI0_MISO | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI master in - slave out */ + CC2650DK_7ID_SPI0_CLK | PIN_INPUT_EN | PIN_PULLDOWN, /* SPI clock */ + + PIN_TERMINATE +}; + +const PINCC26XX_HWAttrs PINCC26XX_hwAttrs = { + .intPriority = ~0, + .swiPriority = 0 +}; + +/* + * =============================== Power =============================== + */ +#include +#include + +const PowerCC26XX_Config PowerCC26XX_config = { + .policyInitFxn = NULL, + .policyFxn = &PowerCC26XX_standbyPolicy, + .calibrateFxn = &PowerCC26XX_calibrate, + .enablePolicy = true, + .calibrateRCOSC_LF = true, + .calibrateRCOSC_HF = true, +}; + +/* + * =============================== PWM =============================== + * Remove unused entries to reduce flash usage both in Board.c and Board.h + */ +#include +#include + +PWMTimerCC26XX_Object pwmtimerCC26xxObjects[CC2650DK_7ID_PWMCOUNT]; + +const PWMTimerCC26XX_HwAttrs pwmtimerCC26xxHWAttrs[CC2650DK_7ID_PWMCOUNT] = { + { .pwmPin = CC2650DK_7ID_PWMPIN0, .gpTimerUnit = CC2650DK_7ID_GPTIMER0A }, + { .pwmPin = CC2650DK_7ID_PWMPIN1, .gpTimerUnit = CC2650DK_7ID_GPTIMER0B }, + { .pwmPin = CC2650DK_7ID_PWMPIN2, .gpTimerUnit = CC2650DK_7ID_GPTIMER1A }, + { .pwmPin = CC2650DK_7ID_PWMPIN3, .gpTimerUnit = CC2650DK_7ID_GPTIMER1B }, + { .pwmPin = CC2650DK_7ID_PWMPIN4, .gpTimerUnit = CC2650DK_7ID_GPTIMER2A }, + { .pwmPin = CC2650DK_7ID_PWMPIN5, .gpTimerUnit = CC2650DK_7ID_GPTIMER2B }, + { .pwmPin = CC2650DK_7ID_PWMPIN6, .gpTimerUnit = CC2650DK_7ID_GPTIMER3A }, + { .pwmPin = CC2650DK_7ID_PWMPIN7, .gpTimerUnit = CC2650DK_7ID_GPTIMER3B }, +}; + +const PWM_Config PWM_config[CC2650DK_7ID_PWMCOUNT] = { + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC2650DK_7ID_PWM0], &pwmtimerCC26xxHWAttrs[CC2650DK_7ID_PWM0] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC2650DK_7ID_PWM1], &pwmtimerCC26xxHWAttrs[CC2650DK_7ID_PWM1] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC2650DK_7ID_PWM2], &pwmtimerCC26xxHWAttrs[CC2650DK_7ID_PWM2] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC2650DK_7ID_PWM3], &pwmtimerCC26xxHWAttrs[CC2650DK_7ID_PWM3] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC2650DK_7ID_PWM4], &pwmtimerCC26xxHWAttrs[CC2650DK_7ID_PWM4] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC2650DK_7ID_PWM5], &pwmtimerCC26xxHWAttrs[CC2650DK_7ID_PWM5] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC2650DK_7ID_PWM6], &pwmtimerCC26xxHWAttrs[CC2650DK_7ID_PWM6] }, + { &PWMTimerCC26XX_fxnTable, &pwmtimerCC26xxObjects[CC2650DK_7ID_PWM7], &pwmtimerCC26xxHWAttrs[CC2650DK_7ID_PWM7] }, +}; + +const uint_least8_t PWM_count = CC2650DK_7ID_PWMCOUNT; + +/* + * =============================== RF Driver =============================== + */ +#include + +const RFCC26XX_HWAttrsV2 RFCC26XX_hwAttrs = { + .hwiPriority = ~0, /* Lowest HWI priority */ + .swiPriority = 0, /* Lowest SWI priority */ + .xoscHfAlwaysNeeded = true, /* Keep XOSC dependency while in stanby */ + .globalCallback = NULL, /* No board specific callback */ + .globalEventMask = 0 /* No events subscribed to */ +}; + +/* + * =============================== SD =============================== + */ +#include +#include + +#if TI_SD_CONF_ENABLE + +#if !(TI_SPI_CONF_SPI0_ENABLE) +#error "SD driver requires SPI0 enabled" +#endif + +SDSPI_Object sdspiObjects[CC2650DK_7ID_SDCOUNT]; + +const SDSPI_HWAttrs sdspiHWAttrs[CC2650DK_7ID_SDCOUNT] = { + { + .spiIndex = CC2650DK_7ID_SPI0, + .spiCsGpioIndex = CC2650DK_7ID_SDCARD_CS + } +}; + +const SD_Config SD_config[CC2650DK_7ID_SDCOUNT] = { + { + .fxnTablePtr = &SDSPI_fxnTable, + .object = &sdspiObjects[CC2650DK_7ID_SDSPI0], + .hwAttrs = &sdspiHWAttrs[CC2650DK_7ID_SDSPI0] + }, +}; + +const uint_least8_t SD_count = CC2650DK_7ID_SDCOUNT; + +#endif /* TI_SD_CONF_ENABLE */ + +/* + * =============================== SPI DMA =============================== + */ +#include +#include + +#if TI_SPI_CONF_ENABLE + +SPICC26XXDMA_Object spiCC26XXDMAObjects[CC2650DK_7ID_SPICOUNT]; + +/* + * NOTE: The SPI instances below can be used by the SD driver to communicate + * with a SD card via SPI. The 'defaultTxBufValue' fields below are set to 0xFF + * to satisfy the SDSPI driver requirement. + */ +const SPICC26XXDMA_HWAttrsV1 spiCC26XXDMAHWAttrs[CC2650DK_7ID_SPICOUNT] = { +#if TI_SPI_CONF_SPI0_ENABLE + { + .baseAddr = SSI0_BASE, + .intNum = INT_SSI0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .powerMngrId = PowerCC26XX_PERIPH_SSI0, + .defaultTxBufValue = 0xFF, + .rxChannelBitMask = 1< +#include + +TRNGCC26X0_Object trngCC26X0Object[CC2650DK_7ID_TRNGCOUNT]; + +const TRNGCC26X0_HWAttrs trngCC26X0HWAttrs[CC2650DK_7ID_TRNGCOUNT] = { + { + .swiPriority = 0, + .intPriority = ~0, + } +}; + +const TRNG_Config TRNG_config[] = { + { &trngCC26X0Object[0], &trngCC26X0HWAttrs[0] }, +}; + +const uint8_t TRNG_count = CC2650DK_7ID_TRNGCOUNT; + + +/* + * =============================== UART =============================== + */ +#include +#include + +#if TI_UART_CONF_ENABLE + +UARTCC26XX_Object uartCC26XXObjects[CC2650DK_7ID_UARTCOUNT]; + +uint8_t uartCC26XXRingBuffer[CC2650DK_7ID_UARTCOUNT][32]; + +const UARTCC26XX_HWAttrsV2 uartCC26XXHWAttrs[CC2650DK_7ID_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .baseAddr = UART0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UART0, + .intNum = INT_UART0_COMB, + .intPriority = ~0, + .swiPriority = 0, + .txPin = CC2650DK_7ID_UART_TX, + .rxPin = CC2650DK_7ID_UART_RX, + .ctsPin = PIN_UNASSIGNED, + .rtsPin = PIN_UNASSIGNED, + .ringBufPtr = uartCC26XXRingBuffer[CC2650DK_7ID_UART0], + .ringBufSize = sizeof(uartCC26XXRingBuffer[CC2650DK_7ID_UART0]), + .txIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_1_8, + .rxIntFifoThr = UARTCC26XX_FIFO_THRESHOLD_4_8, + .errorFxn = NULL + }, +#endif +}; + +const UART_Config UART_config[CC2650DK_7ID_UARTCOUNT] = { +#if TI_UART_CONF_UART0_ENABLE + { + .fxnTablePtr = &UARTCC26XX_fxnTable, + .object = &uartCC26XXObjects[CC2650DK_7ID_UART0], + .hwAttrs = &uartCC26XXHWAttrs[CC2650DK_7ID_UART0] + }, +#endif +}; + +const uint_least8_t UART_count = CC2650DK_7ID_UARTCOUNT; + +#endif /* TI_UART_CONF_ENABLE */ + +/* + * =============================== UDMA =============================== + */ +#include + +UDMACC26XX_Object udmaObjects[CC2650DK_7ID_UDMACOUNT]; + +const UDMACC26XX_HWAttrs udmaHWAttrs[CC2650DK_7ID_UDMACOUNT] = { + { + .baseAddr = UDMA0_BASE, + .powerMngrId = PowerCC26XX_PERIPH_UDMA, + .intNum = INT_DMA_ERR, + .intPriority = ~0 + } +}; + +const UDMACC26XX_Config UDMACC26XX_config[CC2650DK_7ID_UDMACOUNT] = { + { + .object = &udmaObjects[CC2650DK_7ID_UDMA0], + .hwAttrs = &udmaHWAttrs[CC2650DK_7ID_UDMA0] + }, +}; + + + +/* + * =============================== Watchdog =============================== + */ +#include +#include + +WatchdogCC26XX_Object watchdogCC26XXObjects[CC2650DK_7ID_WATCHDOGCOUNT]; + +const WatchdogCC26XX_HWAttrs watchdogCC26XXHWAttrs[CC2650DK_7ID_WATCHDOGCOUNT] = { + { + .baseAddr = WDT_BASE, + .reloadValue = 1000 /* Reload value in milliseconds */ + }, +}; + +const Watchdog_Config Watchdog_config[CC2650DK_7ID_WATCHDOGCOUNT] = { + { + .fxnTablePtr = &WatchdogCC26XX_fxnTable, + .object = &watchdogCC26XXObjects[CC2650DK_7ID_WATCHDOG0], + .hwAttrs = &watchdogCC26XXHWAttrs[CC2650DK_7ID_WATCHDOG0] + }, +}; + +const uint_least8_t Watchdog_count = CC2650DK_7ID_WATCHDOGCOUNT; + +/* + * Board-specific initialization function to disable external flash. + * This function is defined in the file CC2650DK_7ID_fxns.c + */ +extern void Board_initHook(void); + +/* + * ======== CC2650DK_7ID_initGeneral ======== + */ +void CC2650DK_7ID_initGeneral(void) +{ + Power_init(); + + if (PIN_init(BoardGpioInitTable) != PIN_SUCCESS) { + /* Error with PIN_init */ + while (1); + } + + /* Perform board-specific initialization */ + Board_initHook(); +} diff --git a/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/CC2650DK_7ID.h b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/CC2650DK_7ID.h new file mode 100644 index 000000000..21bae0eed --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/CC2650DK_7ID.h @@ -0,0 +1,380 @@ +/* + * Copyright (c) 2015-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 CC2650DK_7ID.h + * + * @brief CC2650 LaunchPad Board Specific header file. + * + * The CC2650DK_7ID header file should be included in an application as + * follows: + * @code + * #include "CC2650DK_7ID.h" + * @endcode + * + * ============================================================================ + */ +#ifndef __CC2650DK_7ID_BOARD_H__ +#define __CC2650DK_7ID_BOARD_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "contiki-conf.h" + +/* Includes */ +#include +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) + +/* Externs */ +extern const PIN_Config BoardGpioInitTable[]; + +/* Defines */ +#define CC2650DK_7ID + +/* Mapping of pins to board signals using general board aliases + * + */ + +/* Analog Capable DIOs */ +#define CC2650DK_7ID_DIO23_ANALOG IOID_23 +#define CC2650DK_7ID_DIO24_ANALOG IOID_24 +#define CC2650DK_7ID_DIO25_ANALOG IOID_25 +#define CC2650DK_7ID_DIO26_ANALOG IOID_26 +#define CC2650DK_7ID_DIO27_ANALOG IOID_27 +#define CC2650DK_7ID_DIO28_ANALOG IOID_28 +#define CC2650DK_7ID_DIO29_ANALOG IOID_29 +#define CC2650DK_7ID_DIO30_ANALOG IOID_30 + +/* Digital IOs */ +#define CC2650DK_7ID_DIO0 IOID_0 +#define CC2650DK_7ID_DIO1_RFSW IOID_1 +#define CC2650DK_7ID_DIO12 IOID_12 +#define CC2650DK_7ID_DIO15 IOID_15 +#define CC2650DK_7ID_DIO16_TDO IOID_16 +#define CC2650DK_7ID_DIO17_TDI IOID_17 +#define CC2650DK_7ID_DIO21 IOID_21 +#define CC2650DK_7ID_DIO22 IOID_22 + +/* Discrete Inputs */ +#define CC2650DK_7ID_PIN_KEY_SELECT IOID_11 +#define CC2650DK_7ID_PIN_KEY_UP IOID_19 +#define CC2650DK_7ID_PIN_KEY_DOWN IOID_12 +#define CC2650DK_7ID_PIN_KEY_LEFT IOID_15 +#define CC2650DK_7ID_PIN_KEY_RIGHT IOID_18 + +/* GPIO */ +#define CC2650DK_7ID_GPIO_LED_ON 1 +#define CC2650DK_7ID_GPIO_LED_OFF 0 + +/* I2C */ +#define CC2650DK_7ID_I2C0_SCL0 PIN_UNASSIGNED +#define CC2650DK_7ID_I2C0_SDA0 PIN_UNASSIGNED + +/* LEDs */ +#define CC2650DK_7ID_PIN_LED_ON 1 +#define CC2650DK_7ID_PIN_LED_OFF 0 +#define CC2650DK_7ID_PIN_LED1 IOID_25 +#define CC2650DK_7ID_PIN_LED2 IOID_27 +#define CC2650DK_7ID_PIN_LED3 IOID_7 +#define CC2650DK_7ID_PIN_LED4 IOID_6 + +/* PWM Outputs */ +#define CC2650DK_7ID_PWMPIN0 CC2650DK_7ID_PIN_LED1 +#define CC2650DK_7ID_PWMPIN1 CC2650DK_7ID_PIN_LED2 +#define CC2650DK_7ID_PWMPIN2 PIN_UNASSIGNED +#define CC2650DK_7ID_PWMPIN3 PIN_UNASSIGNED +#define CC2650DK_7ID_PWMPIN4 PIN_UNASSIGNED +#define CC2650DK_7ID_PWMPIN5 PIN_UNASSIGNED +#define CC2650DK_7ID_PWMPIN6 PIN_UNASSIGNED +#define CC2650DK_7ID_PWMPIN7 PIN_UNASSIGNED + +/* SPI Board */ +#define CC2650DK_7ID_SPI0_MISO IOID_8 +#define CC2650DK_7ID_SPI0_MOSI IOID_9 +#define CC2650DK_7ID_SPI0_CLK IOID_10 +#define CC2650DK_7ID_SPI0_CSN PIN_UNASSIGNED +#define CC2650DK_7ID_SPI1_MISO PIN_UNASSIGNED +#define CC2650DK_7ID_SPI1_MOSI PIN_UNASSIGNED +#define CC2650DK_7ID_SPI1_CLK PIN_UNASSIGNED +#define CC2650DK_7ID_SPI1_CSN PIN_UNASSIGNED + +/* UART Board */ +#define CC2650DK_7ID_UART_RX IOID_2 +#define CC2650DK_7ID_UART_TX IOID_3 +#define CC2650DK_7ID_UART_CTS IOID_0 +#define CC2650DK_7ID_UART_RTS IOID_21 + +/* SD Card */ +#define CC2650DK_7ID_SDCARD_CS IOID_30 + +/* Ambient Light Sensor */ +#define CC2650DK_7ID_ALS_OUT IOID_23 +#define CC2650DK_7ID_ALS_PWR IOID_26 + +/* Accelerometer */ +#define CC2650DK_7ID_ACC_PWR IOID_20 +#define CC2650DK_7ID_ACC_CS IOID_24 + +/*! + * @brief Initialize the general board specific settings + * + * This function initializes the general board specific settings. + */ +void CC2650DK_7ID_initGeneral(void); + +/*! + * @brief Turn off the external flash on LaunchPads + * + */ +void CC2650DK_7ID_shutDownExtFlash(void); + +/*! + * @brief Wake up the external flash present on the board files + * + * This function toggles the chip select for the amount of time needed + * to wake the chip up. + */ +void CC2650DK_7ID_wakeUpExtFlash(void); + +/*! + * @def CC2650DK_7ID_ADCBufName + * @brief Enum of ADCs + */ +typedef enum CC2650DK_7ID_ADCBufName { + CC2650DK_7ID_ADCBUF0 = 0, + + CC2650DK_7ID_ADCBUFCOUNT +} CC2650DK_7ID_ADCBufName; + +/*! + * @def CC2650DK_7ID_ADCBuf0ChannelName + * @brief Enum of ADCBuf channels + */ +typedef enum CC2650DK_7ID_ADCBuf0ChannelName { + CC2650DK_7ID_ADCBUF0CHANNELADCALS = 0, + CC2650DK_7ID_ADCBUF0CHANNELVDDS, + CC2650DK_7ID_ADCBUF0CHANNELDCOUPL, + CC2650DK_7ID_ADCBUF0CHANNELVSS, + + CC2650DK_7ID_ADCBUF0CHANNELCOUNT +} CC2650DK_7ID_ADCBuf0ChannelName; + +/*! + * @def CC2650DK_7ID_ADCName + * @brief Enum of ADCs + */ +typedef enum CC2650DK_7ID_ADCName { + CC2650DK_7ID_ADCALS = 0, + CC2650DK_7ID_ADCDCOUPL, + CC2650DK_7ID_ADCVSS, + CC2650DK_7ID_ADCVDDS, + + CC2650DK_7ID_ADCCOUNT +} CC2650DK_7ID_ADCName; + +/*! + * @def CC2650DK_7ID_CryptoName + * @brief Enum of Crypto names + */ +typedef enum CC2650DK_7ID_CryptoName { + CC2650DK_7ID_CRYPTO0 = 0, + + CC2650DK_7ID_CRYPTOCOUNT +} CC2650DK_7ID_CryptoName; + +/*! + * @def CC2650DK_7ID_GPIOName + * @brief Enum of GPIO names + */ +typedef enum CC2650DK_7ID_GPIOName { + CC2650DK_7ID_GPIO_KEY_SELECT = 0, + CC2650DK_7ID_GPIO_KEY_UP, + CC2650DK_7ID_GPIO_KEY_DOWN, + CC2650DK_7ID_GPIO_KEY_LEFT, + CC2650DK_7ID_GPIO_KEY_RIGHT, + CC2650DK_7ID_SPI_MASTER_READY, + CC2650DK_7ID_SPI_SLAVE_READY, + CC2650DK_7ID_GPIO_LED1, + CC2650DK_7ID_GPIO_LED2, + CC2650DK_7ID_GPIO_LED3, + CC2650DK_7ID_GPIO_LED4, + CC2650DK_7ID_GPIO_SDCARD_CS, + CC2650DK_7ID_GPIO_ACC_CS, + + CC2650DK_7ID_GPIOCOUNT +} CC2650DK_7ID_GPIOName; + +/*! + * @def CC2650DK_7ID_GPTimerName + * @brief Enum of GPTimer parts + */ +typedef enum CC2650DK_7ID_GPTimerName { + CC2650DK_7ID_GPTIMER0A = 0, + CC2650DK_7ID_GPTIMER0B, + CC2650DK_7ID_GPTIMER1A, + CC2650DK_7ID_GPTIMER1B, + CC2650DK_7ID_GPTIMER2A, + CC2650DK_7ID_GPTIMER2B, + CC2650DK_7ID_GPTIMER3A, + CC2650DK_7ID_GPTIMER3B, + + CC2650DK_7ID_GPTIMERPARTSCOUNT +} CC2650DK_7ID_GPTimerName; + +/*! + * @def CC2650DK_7ID_GPTimers + * @brief Enum of GPTimers + */ +typedef enum CC2650DK_7ID_GPTimers { + CC2650DK_7ID_GPTIMER0 = 0, + CC2650DK_7ID_GPTIMER1, + CC2650DK_7ID_GPTIMER2, + CC2650DK_7ID_GPTIMER3, + + CC2650DK_7ID_GPTIMERCOUNT +} CC2650DK_7ID_GPTimers; + +/*! + * @def CC2650DK_7ID_I2CName + * @brief Enum of I2C names + */ +typedef enum CC2650DK_7ID_I2CName { +#if TI_I2C_CONF_I2C0_ENABLE + CC2650DK_7ID_I2C0 = 0, +#endif + + CC2650DK_7ID_I2CCOUNT +} CC2650DK_7ID_I2CName; + +/*! + * @def CC2650DK_7ID_NVSName + * @brief Enum of NVS names + */ +typedef enum CC2650DK_7ID_NVSName { +#if TI_NVS_CONF_NVS_INTERNAL_ENABLE + CC2650DK_7ID_NVSCC26XX0 = 0, +#endif + + CC2650DK_7ID_NVSCOUNT +} CC2650DK_7ID_NVSName; + +/*! + * @def CC2650DK_7ID_PWMName + * @brief Enum of PWM outputs + */ +typedef enum CC2650DK_7ID_PWMName { + CC2650DK_7ID_PWM0 = 0, + CC2650DK_7ID_PWM1, + CC2650DK_7ID_PWM2, + CC2650DK_7ID_PWM3, + CC2650DK_7ID_PWM4, + CC2650DK_7ID_PWM5, + CC2650DK_7ID_PWM6, + CC2650DK_7ID_PWM7, + + CC2650DK_7ID_PWMCOUNT +} CC2650DK_7ID_PWMName; + +/*! + * @def CC2650DK_7ID_SDName + * @brief Enum of SD names + */ +typedef enum CC2650DK_7ID_SDName { + CC2650DK_7ID_SDSPI0 = 0, + + CC2650DK_7ID_SDCOUNT +} CC2650DK_7ID_SDName; + +/*! + * @def CC2650DK_7ID_TRNGName + * @brief Enum of TRNGs + */ +typedef enum CC2650DK_7ID_TRNGName { + CC2650DK_7ID_TRNG0 = 0, + + CC2650DK_7ID_TRNGCOUNT +} CC2650DK_7ID_TRNGName; + +/*! + * @def CC2650DK_7ID_SPIName + * @brief Enum of SPI names + */ +typedef enum CC2650DK_7ID_SPIName { +#if TI_SPI_CONF_SPI0_ENABLE + CC2650DK_7ID_SPI0 = 0, +#endif +#if TI_SPI_CONF_SPI1_ENABLE + CC2650DK_7ID_SPI1, +#endif + + CC2650DK_7ID_SPICOUNT +} CC2650DK_7ID_SPIName; + +/*! + * @def CC2650DK_7ID_UARTName + * @brief Enum of UARTs + */ +typedef enum CC2650DK_7ID_UARTName { +#if TI_UART_CONF_UART0_ENABLE + CC2650DK_7ID_UART0 = 0, +#endif + + CC2650DK_7ID_UARTCOUNT +} CC2650DK_7ID_UARTName; + +/*! + * @def CC2650DK_7ID_UDMAName + * @brief Enum of DMA buffers + */ +typedef enum CC2650DK_7ID_UDMAName { + CC2650DK_7ID_UDMA0 = 0, + + CC2650DK_7ID_UDMACOUNT +} CC2650DK_7ID_UDMAName; + +/*! + * @def CC2650DK_7ID_WatchdogName + * @brief Enum of Watchdogs + */ +typedef enum CC2650DK_7ID_WatchdogName { + CC2650DK_7ID_WATCHDOG0 = 0, + + CC2650DK_7ID_WATCHDOGCOUNT +} CC2650DK_7ID_WatchdogName; + +#ifdef __cplusplus +} +#endif + +#endif /* __CC2650DK_7ID_BOARD_H__ */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/CC2650DK_7ID_fxns.c b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/CC2650DK_7ID_fxns.c new file mode 100644 index 000000000..aa6a6c60e --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/CC2650DK_7ID_fxns.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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. + */ + +/* + * ======== CC2650DK_7ID_fxns.c ======== + * This file contains the board-specific initialization functions. + */ + +#include +#include +#include + +#include +#include DeviceFamily_constructPath(driverlib/ioc.h) +#include DeviceFamily_constructPath(driverlib/cpu.h) + +#include + +#include "Board.h" + +/* + * ======== CC2650DK_7ID_wakeUpExtFlash ======== + */ +void CC2650DK_7ID_wakeUpExtFlash(void) +{ + /* No external flash on CC2650DK_7ID */ +} + +/* + * ======== CC2650DK_7ID_shutDownExtFlash ======== + */ +void CC2650DK_7ID_shutDownExtFlash(void) +{ + /* No external flash on CC2650DK_7ID */ +} + +/* + * ======== Board_initHook ======== + * Called by Board_init() to perform board-specific initialization. + */ +void Board_initHook() +{ + CC2650DK_7ID_shutDownExtFlash(); +} diff --git a/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/Makefile.cc26x0 b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/Makefile.cc26x0 new file mode 100644 index 000000000..5f554cda4 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/srf06/cc26x0/Makefile.cc26x0 @@ -0,0 +1,21 @@ +################################################################################ +# SimpleLink Device makefile + +SUBFAMILY = cc13x0-cc26x0 +DEVICE_FAMILY = CC26X0 +DEVICE_LINE = CC26XX +DEVICE = CC2650 + +BOARD_SOURCEFILES += CC2650DK_7ID.c CC2650DK_7ID_fxns.c + +SUPPORTS_PROP_MODE = 0 +SUPPORTS_IEEE_MODE = 1 +SUPPORTS_BLE_BEACON = 1 + +SUPPORTS_HIGH_PA = 0 + +### Signal that we can be programmed with cc2538-bsl +BOARD_SUPPORTS_BSL = 1 + +# Include the common board makefile +include $(FAMILY_PATH)/srf06/Makefile.srf06 diff --git a/arch/platform/simplelink/cc13xx-cc26xx/srf06/leds-arch.c b/arch/platform/simplelink/cc13xx-cc26xx/srf06/leds-arch.c new file mode 100644 index 000000000..23f1e1b53 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/srf06/leds-arch.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup srf06-peripherals + * @{ + * + * \file + * LED HAL definitions for the SmartRF06 Evaluation Board's LEDs. + * Common across all CC13xx/CC26xx devices for the SmartRF06 EB. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "dev/leds.h" +/*---------------------------------------------------------------------------*/ +#include +/*---------------------------------------------------------------------------*/ +#include +/*---------------------------------------------------------------------------*/ +const leds_t leds_arch_leds[] = { + /* Red LED, AKA LED0 */ + { .pin = Board_PIN_LED0, .negative_logic = false }, + /* Yellow LED, AKA LED1 */ + { .pin = Board_PIN_LED1, .negative_logic = false }, + /* Green LED, AKA LED2 */ + { .pin = Board_PIN_LED2, .negative_logic = false }, + /* Red-orange LED, AKA LED3 */ + { .pin = Board_PIN_LED3, .negative_logic = false }, +}; +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/srf06/srf06-sensors.c b/arch/platform/simplelink/cc13xx-cc26xx/srf06/srf06-sensors.c new file mode 100644 index 000000000..1660cc0c8 --- /dev/null +++ b/arch/platform/simplelink/cc13xx-cc26xx/srf06/srf06-sensors.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/** + * \addtogroup srf06-peripherals + * @{ + * + * \file + * Generic module controlling sensors on SmartRF06 Evaluation Board. + * \author + * Edvard Pettersen + */ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +#include "lib/sensors.h" +/*---------------------------------------------------------------------------*/ +#include "board-conf.h" +#include "board-peripherals.h" +/*---------------------------------------------------------------------------*/ +/* Exports a global symbol to be used by the sensor API */ +#if BOARD_SENSORS_ENABLE +SENSORS(&als_sensor); +#endif +/*---------------------------------------------------------------------------*/ +/** @} */ diff --git a/arch/platform/sky/Makefile.common b/arch/platform/sky/Makefile.common index 081ffaa9f..5018da3da 100644 --- a/arch/platform/sky/Makefile.common +++ b/arch/platform/sky/Makefile.common @@ -1,6 +1,6 @@ # $Id: Makefile.common,v 1.3 2010/08/24 16:24:11 joxe Exp $ -ARCH=spi-legacy.c ds2411.c xmem.c i2c.c node-id.c sensors.c cfs-coffee.c \ +ARCH=spi-legacy.c ds2411.c xmem.c i2c.c sensors.c cfs-coffee.c \ cc2420.c cc2420-arch.c cc2420-arch-sfd.c \ sky-sensors.c uip-ipchksum.c \ uart1.c slip_uart1.c uart1-putchar.c platform.c @@ -54,7 +54,6 @@ else ifeq ($(HOST_OS),Darwin) ifndef MOTELIST USBDEVPREFIX= - SERIALDUMP = $(CONTIKI)/tools/sky/serialdump-macos MOTELIST = $(CONTIKI)/tools/sky/motelist-macos TMOTE_BSL_FILE = tmote-bsl-linux TMOTE_BSL=$(if $(wildcard $(CONTIKI)/tools/sky/$(TMOTE_BSL_FILE)),1,0) @@ -75,7 +74,6 @@ else # Else we assume Linux ifndef MOTELIST USBDEVPREFIX= - SERIALDUMP = $(CONTIKI)/tools/sky/serialdump-linux MOTELIST = $(CONTIKI)/tools/sky/motelist-linux TMOTE_BSL_FILE = tmote-bsl-linux TMOTE_BSL=$(if $(wildcard $(CONTIKI)/tools/sky/$(TMOTE_BSL_FILE)),1,0) @@ -171,21 +169,7 @@ $(CONTIKI)/tools/tunslip: (cd $(CONTIKI)/tools; $(MAKE) tunslip) ifdef MOTE -serialdump: - $(SERIALDUMP) -b115200 $(USBDEVPREFIX)$(word $(MOTE), $(CMOTES)) | $(CONTIKI)/tools/timestamp | tee serialdump-`date +%Y%m%d-%H%M` - -serialview: - $(SERIALDUMP) -b115200 $(USBDEVPREFIX)$(word $(MOTE), $(CMOTES)) | $(CONTIKI)/tools/timestamp - -login: - $(SERIALDUMP) -b115200 $(USBDEVPREFIX)$(word $(MOTE), $(CMOTES)) + PORT = $(USBDEVPREFIX)$(word $(MOTE), $(CMOTES)) else -serialdump: - $(SERIALDUMP) -b115200 $(USBDEVPREFIX)$(firstword $(CMOTES)) | $(CONTIKI)/tools/timestamp | tee serialdump-`date +%Y%m%d-%H%M` - -serialview: - $(SERIALDUMP) -b115200 $(USBDEVPREFIX)$(firstword $(CMOTES)) | $(CONTIKI)/tools/timestamp - -login: - $(SERIALDUMP) -b115200 $(USBDEVPREFIX)$(firstword $(CMOTES)) + PORT = $(USBDEVPREFIX)$(firstword $(CMOTES)) endif diff --git a/arch/platform/sky/contiki-conf.h b/arch/platform/sky/contiki-conf.h index 500e00e08..d690af86a 100644 --- a/arch/platform/sky/contiki-conf.h +++ b/arch/platform/sky/contiki-conf.h @@ -11,21 +11,20 @@ #include "sky-def.h" #include "msp430-def.h" /*---------------------------------------------------------------------------*/ -/* Map RF_CHANNEL to cc2420 default channel */ -#ifdef RF_CHANNEL -#define CC2420_CONF_CHANNEL RF_CHANNEL -#endif /* RF_CHANNEL */ /* Configure radio driver */ #ifndef NETSTACK_CONF_RADIO #define NETSTACK_CONF_RADIO cc2420_driver #endif /* NETSTACK_CONF_RADIO */ +/* Symbol for the TSCH 15ms timeslot timing template */ +#define TSCH_CONF_ARCH_HDR_PATH "dev/cc2420/cc2420-tsch-15ms.h" + /* The TSCH default slot length of 10ms is a bit too short for this platform, * use 15ms instead. */ -#ifndef TSCH_CONF_DEFAULT_TIMESLOT_LENGTH -#define TSCH_CONF_DEFAULT_TIMESLOT_LENGTH 15000 -#endif /* TSCH_CONF_DEFAULT_TIMESLOT_LENGTH */ +#ifndef TSCH_CONF_DEFAULT_TIMESLOT_TIMING +#define TSCH_CONF_DEFAULT_TIMESLOT_TIMING tsch_timeslot_timing_us_15000 +#endif /* TSCH_CONF_DEFAULT_TIMESLOT_TIMING */ /* Save RAM through a smaller uIP buffer */ #ifndef UIP_CONF_BUFFER_SIZE diff --git a/arch/platform/sky/platform.c b/arch/platform/sky/platform.c index d71471340..8044a7196 100644 --- a/arch/platform/sky/platform.c +++ b/arch/platform/sky/platform.c @@ -43,6 +43,7 @@ #include "lib/random.h" #include "net/netstack.h" #include "net/mac/framer/frame802154.h" +#include "net/mac/tsch/tsch.h" #if NETSTACK_CONF_WITH_IPV6 #include "net/ipv6/uip-ds6.h" @@ -103,23 +104,14 @@ set_lladdr(void) #if NETSTACK_CONF_WITH_IPV6 memcpy(addr.u8, ds2411_id, sizeof(addr.u8)); #else - if(node_id == 0) { - int i; - for(i = 0; i < sizeof(linkaddr_t); ++i) { - addr.u8[i] = ds2411_id[7 - i]; - } - } else { - addr.u8[0] = node_id & 0xff; - addr.u8[1] = node_id >> 8; + int i; + for(i = 0; i < sizeof(linkaddr_t); ++i) { + addr.u8[i] = ds2411_id[7 - i]; } #endif linkaddr_set_node_addr(&addr); } /*---------------------------------------------------------------------------*/ -#if WITH_TINYOS_AUTO_IDS -uint16_t TOS_NODE_ID = 0x1234; /* non-zero */ -uint16_t TOS_LOCAL_ADDRESS = 0x1234; /* non-zero */ -#endif /* WITH_TINYOS_AUTO_IDS */ void platform_init_stage_one(void) { @@ -153,23 +145,7 @@ platform_init_stage_two(void) * Hardware initialization done! */ -#if WITH_TINYOS_AUTO_IDS - node_id = TOS_NODE_ID; -#else /* WITH_TINYOS_AUTO_IDS */ - /* Restore node id if such has been stored in external mem */ - node_id_restore(); -#endif /* WITH_TINYOS_AUTO_IDS */ - - /* for setting "hardcoded" IEEE 802.15.4 MAC addresses */ -#ifdef IEEE_802154_MAC_ADDRESS - { - uint8_t ieee[] = IEEE_802154_MAC_ADDRESS; - memcpy(ds2411_id, ieee, sizeof(uip_lladdr.addr)); - ds2411_id[7] = node_id & 0xff; - } -#endif - - random_init(ds2411_id[0] + node_id); + random_init(ds2411_id[0]); leds_off(LEDS_BLUE); @@ -198,21 +174,7 @@ platform_init_stage_three(void) cc2420_set_pan_addr(IEEE802154_PANID, shortaddr, longaddr); - if(node_id > 0) { - LOG_INFO("Node id: %u\n", node_id); - } else { - LOG_INFO("Node id: N/A\n"); - } - -#if NETSTACK_CONF_WITH_IPV6 - LOG_INFO("%s, rf channel %u, CCA threshold %i\n", - NETSTACK_MAC.name, - CC2420_CONF_CHANNEL, - CC2420_CONF_CCA_THRESH); -#else /* NETSTACK_CONF_WITH_IPV6 */ - LOG_INFO("%s, rf channel %u\n", - NETSTACK_MAC.name, CC2420_CONF_CHANNEL); -#endif /* NETSTACK_CONF_WITH_IPV6 */ + LOG_INFO("CC2420 CCA threshold %i\n", CC2420_CONF_CCA_THRESH); #if !NETSTACK_CONF_WITH_IPV6 uart1_set_input(serial_line_input_byte); diff --git a/arch/platform/sky/sky-def.h b/arch/platform/sky/sky-def.h index edab43ee7..1077563a3 100644 --- a/arch/platform/sky/sky-def.h +++ b/arch/platform/sky/sky-def.h @@ -43,6 +43,11 @@ * Definitions below are dictated by the hardware and not really * changeable! */ + + /* 1 len byte, 2 bytes CRC */ + #define RADIO_PHY_OVERHEAD 3 + /* 250kbps data rate. One byte = 32us */ + #define RADIO_BYTE_AIR_TIME 32 /* Delay between GO signal and SFD: radio fixed delay + 4Bytes preample + 1B SFD -- 1Byte time is 32us * ~327us + 129preample = 456 us */ #define RADIO_DELAY_BEFORE_TX ((unsigned)US_TO_RTIMERTICKS(456)) diff --git a/arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx b/arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx index db4209adc..03eefcf8b 100644 --- a/arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx +++ b/arch/platform/srf06-cc26xx/Makefile.srf06-cc26xx @@ -6,7 +6,7 @@ endif ### Board and BSP selection BOARD ?= srf06/cc26xx -BOARDS = srf06/cc26xx srf06/cc13xx launchpad/cc2650 launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350 +BOARDS = srf06/cc26xx srf06/cc13xx launchpad/cc2640r2 launchpad/cc2650 launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350 CONTIKI_TARGET_DIRS += . diff --git a/arch/platform/srf06-cc26xx/contiki-conf.h b/arch/platform/srf06-cc26xx/contiki-conf.h index 4a1470b40..23c086db3 100644 --- a/arch/platform/srf06-cc26xx/contiki-conf.h +++ b/arch/platform/srf06-cc26xx/contiki-conf.h @@ -50,23 +50,13 @@ /** * \name Button configurations * - * Configure a button as power on/off: We use the right button for both boards. * @{ */ -#ifndef BUTTON_SENSOR_CONF_ENABLE_SHUTDOWN -#define BUTTON_SENSOR_CONF_ENABLE_SHUTDOWN 1 -#endif /* Notify various examples that we have Buttons */ #define PLATFORM_HAS_BUTTON 1 #define PLATFORM_SUPPORTS_BUTTON_HAL 1 -/* - * Override button symbols from dev/button-sensor.h, for the examples that - * include it - */ -#define button_sensor button_left_sensor -#define button_sensor2 button_right_sensor /** @} */ /*---------------------------------------------------------------------------*/ /* Platform-specific define to signify sensor reading failure */ diff --git a/arch/platform/srf06-cc26xx/launchpad/cc1310/board.h b/arch/platform/srf06-cc26xx/launchpad/cc1310/board.h index 41e929571..43a330e28 100644 --- a/arch/platform/srf06-cc26xx/launchpad/cc1310/board.h +++ b/arch/platform/srf06-cc26xx/launchpad/cc1310/board.h @@ -111,15 +111,10 @@ */ #define EXT_FLASH_SPI_CONTROLLER SPI_CONTROLLER_SPI0 -#define BOARD_IOID_FLASH_SCK IOID_10 -#define BOARD_IOID_FLASH_MOSI IOID_9 -#define BOARD_IOID_FLASH_MISO IOID_8 -#define BOARD_IOID_FLASH_CS IOID_20 - -#define EXT_FLASH_SPI_PIN_SCK 10 -#define EXT_FLASH_SPI_PIN_MOSI 9 -#define EXT_FLASH_SPI_PIN_MISO 8 -#define EXT_FLASH_SPI_PIN_CS 20 +#define EXT_FLASH_SPI_PIN_SCK IOID_10 +#define EXT_FLASH_SPI_PIN_MOSI IOID_9 +#define EXT_FLASH_SPI_PIN_MISO IOID_8 +#define EXT_FLASH_SPI_PIN_CS IOID_20 #define EXT_FLASH_DEVICE_ID 0x14 #define EXT_FLASH_MID 0xC2 @@ -141,23 +136,14 @@ /** * \brief ROM bootloader configuration * - * Change SET_CCFG_BL_CONFIG_BL_PIN_NUMBER to BOARD_IOID_KEY_xyz to select - * which button triggers the bootloader on reset. - * - * The remaining values are not meant to be modified by the user + * Change CCXXWARE_CONF_BL_PIN_NUMBER to BOARD_IOID_KEY_xyz to select which + * button triggers the bootloader on reset. Use CCXXWARE_CONF_BL_LEVEL to + * control the pin level that enables the bootloader (0: low, 1: high). It is + * also possible to use any other externally-controlled DIO. * @{ */ -#if ROM_BOOTLOADER_ENABLE -#define SET_CCFG_BL_CONFIG_BOOTLOADER_ENABLE 0xC5 -#define SET_CCFG_BL_CONFIG_BL_LEVEL 0x00 -#define SET_CCFG_BL_CONFIG_BL_PIN_NUMBER BOARD_IOID_KEY_LEFT -#define SET_CCFG_BL_CONFIG_BL_ENABLE 0xC5 -#else -#define SET_CCFG_BL_CONFIG_BOOTLOADER_ENABLE 0x00 -#define SET_CCFG_BL_CONFIG_BL_LEVEL 0x01 -#define SET_CCFG_BL_CONFIG_BL_PIN_NUMBER 0xFF -#define SET_CCFG_BL_CONFIG_BL_ENABLE 0xFF -#endif +#define CCXXWARE_CONF_BL_PIN_NUMBER BOARD_IOID_KEY_LEFT +#define CCXXWARE_CONF_BL_LEVEL 0 /** @} */ /*---------------------------------------------------------------------------*/ /** diff --git a/arch/platform/srf06-cc26xx/launchpad/cc1350/board.h b/arch/platform/srf06-cc26xx/launchpad/cc1350/board.h index 643d69e0b..5f6239531 100644 --- a/arch/platform/srf06-cc26xx/launchpad/cc1350/board.h +++ b/arch/platform/srf06-cc26xx/launchpad/cc1350/board.h @@ -111,15 +111,10 @@ */ #define EXT_FLASH_SPI_CONTROLLER SPI_CONTROLLER_SPI0 -#define BOARD_IOID_FLASH_SCK IOID_10 -#define BOARD_IOID_FLASH_MOSI IOID_9 -#define BOARD_IOID_FLASH_MISO IOID_8 -#define BOARD_IOID_FLASH_CS IOID_20 - -#define EXT_FLASH_SPI_PIN_SCK 10 -#define EXT_FLASH_SPI_PIN_MOSI 9 -#define EXT_FLASH_SPI_PIN_MISO 8 -#define EXT_FLASH_SPI_PIN_CS 20 +#define EXT_FLASH_SPI_PIN_SCK IOID_10 +#define EXT_FLASH_SPI_PIN_MOSI IOID_9 +#define EXT_FLASH_SPI_PIN_MISO IOID_8 +#define EXT_FLASH_SPI_PIN_CS IOID_20 #define EXT_FLASH_DEVICE_ID 0x14 #define EXT_FLASH_MID 0xC2 @@ -158,23 +153,14 @@ /** * \brief ROM bootloader configuration * - * Change SET_CCFG_BL_CONFIG_BL_PIN_NUMBER to BOARD_IOID_KEY_xyz to select - * which button triggers the bootloader on reset. - * - * The remaining values are not meant to be modified by the user + * Change CCXXWARE_CONF_BL_PIN_NUMBER to BOARD_IOID_KEY_xyz to select which + * button triggers the bootloader on reset. Use CCXXWARE_CONF_BL_LEVEL to + * control the pin level that enables the bootloader (0: low, 1: high). It is + * also possible to use any other externally-controlled DIO. * @{ */ -#if ROM_BOOTLOADER_ENABLE -#define SET_CCFG_BL_CONFIG_BOOTLOADER_ENABLE 0xC5 -#define SET_CCFG_BL_CONFIG_BL_LEVEL 0x00 -#define SET_CCFG_BL_CONFIG_BL_PIN_NUMBER BOARD_IOID_KEY_LEFT -#define SET_CCFG_BL_CONFIG_BL_ENABLE 0xC5 -#else -#define SET_CCFG_BL_CONFIG_BOOTLOADER_ENABLE 0x00 -#define SET_CCFG_BL_CONFIG_BL_LEVEL 0x01 -#define SET_CCFG_BL_CONFIG_BL_PIN_NUMBER 0xFF -#define SET_CCFG_BL_CONFIG_BL_ENABLE 0xFF -#endif +#define CCXXWARE_CONF_BL_PIN_NUMBER BOARD_IOID_KEY_LEFT +#define CCXXWARE_CONF_BL_LEVEL 0 /** @} */ /*---------------------------------------------------------------------------*/ /** diff --git a/arch/platform/srf06-cc26xx/launchpad/cc1350/rf-switch.c b/arch/platform/srf06-cc26xx/launchpad/cc1350/rf-switch.c index 42e648a73..639b246cc 100644 --- a/arch/platform/srf06-cc26xx/launchpad/cc1350/rf-switch.c +++ b/arch/platform/srf06-cc26xx/launchpad/cc1350/rf-switch.c @@ -63,9 +63,9 @@ LPM_MODULE(rf_switch_module, NULL, shutdown_handler, NULL, LPM_DOMAIN_NONE); void rf_switch_init() { - ti_lib_rom_ioc_pin_type_gpio_output(POWER_PIN); + ti_lib_ioc_pin_type_gpio_output(POWER_PIN); ti_lib_gpio_clear_dio(POWER_PIN); - ti_lib_rom_ioc_pin_type_gpio_output(SELECT_PIN); + ti_lib_ioc_pin_type_gpio_output(SELECT_PIN); ti_lib_gpio_clear_dio(SELECT_PIN); lpm_register_module(&rf_switch_module); diff --git a/arch/platform/srf06-cc26xx/launchpad/cc2640r2/Makefile.cc2640r2 b/arch/platform/srf06-cc26xx/launchpad/cc2640r2/Makefile.cc2640r2 new file mode 100644 index 000000000..5abb37a97 --- /dev/null +++ b/arch/platform/srf06-cc26xx/launchpad/cc2640r2/Makefile.cc2640r2 @@ -0,0 +1,8 @@ +### Will allow the inclusion of the correct CPU makefile +CPU_FAMILY = cc26x0r2f + +### Add to the source dirs +CONTIKI_TARGET_DIRS += launchpad/cc2640r2 + +### Include the common launchpad makefile +include $(PLATFORM_ROOT_DIR)/launchpad/Makefile.launchpad diff --git a/arch/platform/srf06-cc26xx/launchpad/cc2640r2/board.h b/arch/platform/srf06-cc26xx/launchpad/cc2640r2/board.h new file mode 100644 index 000000000..1bf42ec18 --- /dev/null +++ b/arch/platform/srf06-cc26xx/launchpad/cc2640r2/board.h @@ -0,0 +1,205 @@ +/* + * Copyright (c) 2015, Texas Instruments Incorporated - http://www.ti.com/ + * 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. + */ +/*---------------------------------------------------------------------------*/ +/** \addtogroup launchpad-peripherals + * @{ + * + * \defgroup launchpad-cc2640r2-specific CC2640R2 LaunchPad Peripherals + * + * Defines related to the CC2640R2 LaunchPad + * + * This file provides connectivity information on LEDs, Buttons, UART and + * other peripherals + * + * This file is not meant to be modified by the user. + * @{ + * + * \file + * Header file with definitions related to the I/O connections on the TI + * CC2640R2 LaunchPad + * + * \note Do not include this file directly. It gets included by contiki-conf + * after all relevant directives have been set. + */ +/*---------------------------------------------------------------------------*/ +#ifndef BOARD_H_ +#define BOARD_H_ +/*---------------------------------------------------------------------------*/ +#include "ioc.h" +/*---------------------------------------------------------------------------*/ +/** + * \name LED HAL configuration + * + * Those values are not meant to be modified by the user + * @{ + */ +#define LEDS_CONF_COUNT 2 +#define LEDS_CONF_RED 1 +#define LEDS_CONF_GREEN 2 +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name LED IOID mappings + * + * Those values are not meant to be modified by the user + * @{ + */ +#define BOARD_IOID_LED_1 IOID_6 +#define BOARD_IOID_LED_2 IOID_7 +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name UART IOID mapping + * + * Those values are not meant to be modified by the user + * @{ + */ +#define BOARD_IOID_UART_RX IOID_2 +#define BOARD_IOID_UART_TX IOID_3 +#define BOARD_IOID_UART_RTS IOID_18 +#define BOARD_IOID_UART_CTS IOID_19 +#define BOARD_UART_RX (1 << BOARD_IOID_UART_RX) +#define BOARD_UART_TX (1 << BOARD_IOID_UART_TX) +#define BOARD_UART_RTS (1 << BOARD_IOID_UART_RTS) +#define BOARD_UART_CTS (1 << BOARD_IOID_UART_CTS) +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name Button IOID mapping + * + * Those values are not meant to be modified by the user + * @{ + */ +#define BOARD_IOID_KEY_LEFT IOID_13 +#define BOARD_IOID_KEY_RIGHT IOID_14 +#define BOARD_KEY_LEFT (1 << BOARD_IOID_KEY_LEFT) +#define BOARD_KEY_RIGHT (1 << BOARD_IOID_KEY_RIGHT) +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name External flash IOID mapping + * + * Those values are not meant to be modified by the user + * @{ + */ +#define EXT_FLASH_SPI_CONTROLLER SPI_CONTROLLER_SPI0 + +#define EXT_FLASH_SPI_PIN_SCK IOID_10 +#define EXT_FLASH_SPI_PIN_MOSI IOID_9 +#define EXT_FLASH_SPI_PIN_MISO IOID_8 +#define EXT_FLASH_SPI_PIN_CS IOID_20 + +#define EXT_FLASH_DEVICE_ID 0x14 +#define EXT_FLASH_MID 0xC2 + +#define EXT_FLASH_PROGRAM_PAGE_SIZE 256 +#define EXT_FLASH_ERASE_SECTOR_SIZE 4096 +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \brief I2C IOID mappings + * + * Those values are not meant to be modified by the user + * @{ + */ +#define BOARD_IOID_SCL IOID_4 +#define BOARD_IOID_SDA IOID_5 +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \brief ROM bootloader configuration + * + * Change CCXXWARE_CONF_BL_PIN_NUMBER to BOARD_IOID_KEY_xyz to select which + * button triggers the bootloader on reset. Use CCXXWARE_CONF_BL_LEVEL to + * control the pin level that enables the bootloader (0: low, 1: high). It is + * also possible to use any other externally-controlled DIO. + * @{ + */ +#define CCXXWARE_CONF_BL_PIN_NUMBER BOARD_IOID_KEY_LEFT +#define CCXXWARE_CONF_BL_LEVEL 0 +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \brief Remaining pins + * + * Those values are not meant to be modified by the user + * @{ + */ +#define BOARD_IOID_DIO0 IOID_0 +#define BOARD_IOID_DIO1 IOID_1 +#define BOARD_IOID_CS IOID_11 +#define BOARD_IOID_TDO IOID_16 +#define BOARD_IOID_TDI IOID_17 +#define BOARD_IOID_DIO12 IOID_12 +#define BOARD_IOID_DIO15 IOID_15 +#define BOARD_IOID_DIO21 IOID_21 +#define BOARD_IOID_DIO22 IOID_22 +#define BOARD_IOID_DIO23 IOID_23 +#define BOARD_IOID_DIO24 IOID_24 +#define BOARD_IOID_DIO25 IOID_25 +#define BOARD_IOID_DIO26 IOID_26 +#define BOARD_IOID_DIO27 IOID_27 +#define BOARD_IOID_DIO28 IOID_28 +#define BOARD_IOID_DIO29 IOID_29 +#define BOARD_IOID_DIO30 IOID_30 + +#define BOARD_UNUSED_PINS { \ + BOARD_IOID_DIO0, BOARD_IOID_DIO1, BOARD_IOID_CS, BOARD_IOID_TDO, \ + BOARD_IOID_TDI, BOARD_IOID_DIO12, BOARD_IOID_DIO15, BOARD_IOID_DIO21, \ + BOARD_IOID_DIO22, BOARD_IOID_DIO23, BOARD_IOID_DIO24, BOARD_IOID_DIO25, \ + BOARD_IOID_DIO26, BOARD_IOID_DIO27, BOARD_IOID_DIO28, BOARD_IOID_DIO29, \ + BOARD_IOID_DIO30, IOID_UNUSED \ + } +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \brief Board indices for the button HAL + * + * Those values are not meant to be modified by the user + * @{ + */ +#define BOARD_BUTTON_HAL_INDEX_KEY_LEFT 0x00 +#define BOARD_BUTTON_HAL_INDEX_KEY_RIGHT 0x01 +/** @} */ +/*---------------------------------------------------------------------------*/ +/** + * \name Device string used on startup + * @{ + */ +#define BOARD_STRING "LAUNCHXL-CC2640R2" + +/** @} */ +/*---------------------------------------------------------------------------*/ +#endif /* BOARD_H_ */ +/*---------------------------------------------------------------------------*/ +/** + * @} + * @} + */ diff --git a/arch/platform/srf06-cc26xx/launchpad/cc2650/board.h b/arch/platform/srf06-cc26xx/launchpad/cc2650/board.h index 822e776b8..95946cd14 100644 --- a/arch/platform/srf06-cc26xx/launchpad/cc2650/board.h +++ b/arch/platform/srf06-cc26xx/launchpad/cc2650/board.h @@ -111,15 +111,10 @@ */ #define EXT_FLASH_SPI_CONTROLLER SPI_CONTROLLER_SPI0 -#define BOARD_IOID_FLASH_SCK IOID_10 -#define BOARD_IOID_FLASH_MOSI IOID_9 -#define BOARD_IOID_FLASH_MISO IOID_8 -#define BOARD_IOID_FLASH_CS IOID_20 - -#define EXT_FLASH_SPI_PIN_SCK 10 -#define EXT_FLASH_SPI_PIN_MOSI 9 -#define EXT_FLASH_SPI_PIN_MISO 8 -#define EXT_FLASH_SPI_PIN_CS 20 +#define EXT_FLASH_SPI_PIN_SCK IOID_10 +#define EXT_FLASH_SPI_PIN_MOSI IOID_9 +#define EXT_FLASH_SPI_PIN_MISO IOID_8 +#define EXT_FLASH_SPI_PIN_CS IOID_20 #define EXT_FLASH_DEVICE_ID 0x14 #define EXT_FLASH_MID 0xC2 @@ -141,23 +136,14 @@ /** * \brief ROM bootloader configuration * - * Change SET_CCFG_BL_CONFIG_BL_PIN_NUMBER to BOARD_IOID_KEY_xyz to select - * which button triggers the bootloader on reset. - * - * The remaining values are not meant to be modified by the user + * Change CCXXWARE_CONF_BL_PIN_NUMBER to BOARD_IOID_KEY_xyz to select which + * button triggers the bootloader on reset. Use CCXXWARE_CONF_BL_LEVEL to + * control the pin level that enables the bootloader (0: low, 1: high). It is + * also possible to use any other externally-controlled DIO. * @{ */ -#if ROM_BOOTLOADER_ENABLE -#define SET_CCFG_BL_CONFIG_BOOTLOADER_ENABLE 0xC5 -#define SET_CCFG_BL_CONFIG_BL_LEVEL 0x00 -#define SET_CCFG_BL_CONFIG_BL_PIN_NUMBER BOARD_IOID_KEY_LEFT -#define SET_CCFG_BL_CONFIG_BL_ENABLE 0xC5 -#else -#define SET_CCFG_BL_CONFIG_BOOTLOADER_ENABLE 0x00 -#define SET_CCFG_BL_CONFIG_BL_LEVEL 0x01 -#define SET_CCFG_BL_CONFIG_BL_PIN_NUMBER 0xFF -#define SET_CCFG_BL_CONFIG_BL_ENABLE 0xFF -#endif +#define CCXXWARE_CONF_BL_PIN_NUMBER BOARD_IOID_KEY_LEFT +#define CCXXWARE_CONF_BL_LEVEL 0 /** @} */ /*---------------------------------------------------------------------------*/ /** diff --git a/arch/platform/srf06-cc26xx/platform.c b/arch/platform/srf06-cc26xx/platform.c index bfda15dad..d160c13e1 100644 --- a/arch/platform/srf06-cc26xx/platform.c +++ b/arch/platform/srf06-cc26xx/platform.c @@ -81,8 +81,6 @@ #define LOG_MODULE "CC26xx/CC13xx" #define LOG_LEVEL LOG_LEVEL_MAIN /*---------------------------------------------------------------------------*/ -unsigned short node_id = 0; -/*---------------------------------------------------------------------------*/ /** \brief Board specific iniatialisation */ void board_init(void); /*---------------------------------------------------------------------------*/ @@ -128,11 +126,8 @@ set_rf_params(void) NETSTACK_RADIO.set_value(RADIO_PARAM_PAN_ID, IEEE802154_PANID); NETSTACK_RADIO.set_value(RADIO_PARAM_16BIT_ADDR, short_addr); - NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, RF_CORE_CHANNEL); + NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, IEEE802154_DEFAULT_CHANNEL); NETSTACK_RADIO.set_object(RADIO_PARAM_64BIT_ADDR, ext_addr, 8); - - /* also set the global node id */ - node_id = short_addr; #endif } /*---------------------------------------------------------------------------*/ @@ -163,9 +158,11 @@ platform_init_stage_one() * latches in the first place. Before doing these things though, we should * allow software to first regain control of pins */ - ti_lib_pwr_ctrl_io_freeze_disable(); + ti_lib_aon_ioc_freeze_disable(); + HWREG(AON_SYSCTL_BASE + AON_SYSCTL_O_SLEEPCTL) = 1; + ti_lib_sys_ctrl_aon_sync(); - ti_lib_rom_int_enable(INT_AON_GPIO_EDGE); + ti_lib_int_enable(INT_AON_GPIO_EDGE); ti_lib_int_master_enable(); soc_rtc_init(); @@ -227,8 +224,6 @@ platform_init_stage_three() } LOG_INFO_("\n"); - LOG_INFO(" Node ID: %d\n", node_id); - #if BOARD_HAS_SENSORS process_start(&sensors_process, NULL); #endif diff --git a/arch/platform/srf06-cc26xx/sensortag/cc1350/board.h b/arch/platform/srf06-cc26xx/sensortag/cc1350/board.h index 6fdab1295..84fd0717c 100644 --- a/arch/platform/srf06-cc26xx/sensortag/cc1350/board.h +++ b/arch/platform/srf06-cc26xx/sensortag/cc1350/board.h @@ -137,15 +137,10 @@ */ #define EXT_FLASH_SPI_CONTROLLER SPI_CONTROLLER_SPI0 -#define BOARD_IOID_FLASH_SCK IOID_17 -#define BOARD_IOID_FLASH_MOSI IOID_19 -#define BOARD_IOID_FLASH_MISO IOID_18 -#define BOARD_IOID_FLASH_CS IOID_14 - -#define EXT_FLASH_SPI_PIN_SCK 17 -#define EXT_FLASH_SPI_PIN_MOSI 19 -#define EXT_FLASH_SPI_PIN_MISO 18 -#define EXT_FLASH_SPI_PIN_CS 14 +#define EXT_FLASH_SPI_PIN_SCK IOID_17 +#define EXT_FLASH_SPI_PIN_MOSI IOID_19 +#define EXT_FLASH_SPI_PIN_MISO IOID_18 +#define EXT_FLASH_SPI_PIN_CS IOID_14 #define EXT_FLASH_DEVICE_ID 0x14 #define EXT_FLASH_MID 0xC2 @@ -253,6 +248,16 @@ #define BOARD_BUTTON_HAL_INDEX_REED_RELAY 0xFF /** @} */ /*---------------------------------------------------------------------------*/ +/** + * \brief ROM bootloader configuration + * + * Sensortags do not support the bootloader + * @{ + */ +#define CCXXWARE_CONF_BL_PIN_NUMBER IOID_UNUSED +#define CCXXWARE_CONF_BL_LEVEL 0 +/** @} */ +/*---------------------------------------------------------------------------*/ /** * \name Device string used on startup * @{ diff --git a/arch/platform/srf06-cc26xx/sensortag/cc2650/board.h b/arch/platform/srf06-cc26xx/sensortag/cc2650/board.h index 7da0e9458..915b7161f 100644 --- a/arch/platform/srf06-cc26xx/sensortag/cc2650/board.h +++ b/arch/platform/srf06-cc26xx/sensortag/cc2650/board.h @@ -139,18 +139,18 @@ */ #define EXT_FLASH_SPI_CONTROLLER SPI_CONTROLLER_SPI0 -#define BOARD_IOID_FLASH_SCK IOID_17 -#define BOARD_IOID_FLASH_MOSI IOID_19 -#define BOARD_IOID_FLASH_MISO IOID_18 -#define BOARD_IOID_FLASH_CS IOID_14 - -#define EXT_FLASH_SPI_PIN_SCK 17 -#define EXT_FLASH_SPI_PIN_MOSI 19 -#define EXT_FLASH_SPI_PIN_MISO 18 -#define EXT_FLASH_SPI_PIN_CS 14 +#define EXT_FLASH_SPI_PIN_SCK IOID_17 +#define EXT_FLASH_SPI_PIN_MOSI IOID_19 +#define EXT_FLASH_SPI_PIN_MISO IOID_18 +#define EXT_FLASH_SPI_PIN_CS IOID_14 +#if SENSORTAG_CC2650_REV_1_2_0 +#define EXT_FLASH_DEVICE_ID 0x12 +#define EXT_FLASH_MID 0xEF +#else #define EXT_FLASH_DEVICE_ID 0x14 #define EXT_FLASH_MID 0xC2 +#endif #define EXT_FLASH_PROGRAM_PAGE_SIZE 256 #define EXT_FLASH_ERASE_SECTOR_SIZE 4096 @@ -229,6 +229,16 @@ #define BOARD_BUTTON_HAL_INDEX_REED_RELAY 0xFF /** @} */ /*---------------------------------------------------------------------------*/ +/** + * \brief ROM bootloader configuration + * + * Sensortags do not support the bootloader + * @{ + */ +#define CCXXWARE_CONF_BL_PIN_NUMBER IOID_UNUSED +#define CCXXWARE_CONF_BL_LEVEL 0 +/** @} */ +/*---------------------------------------------------------------------------*/ /** * \name Device string used on startup * @{ diff --git a/arch/platform/srf06-cc26xx/sensortag/hdc-1000-sensor.c b/arch/platform/srf06-cc26xx/sensortag/hdc-1000-sensor.c index acc5f19be..15ee8d434 100644 --- a/arch/platform/srf06-cc26xx/sensortag/hdc-1000-sensor.c +++ b/arch/platform/srf06-cc26xx/sensortag/hdc-1000-sensor.c @@ -205,7 +205,7 @@ notify_ready(void *not_used) /*---------------------------------------------------------------------------*/ /** * \brief Returns a reading from the sensor - * \param type HDC_1000_SENSOR_TYPE_TEMP or HDC_1000_SENSOR_TYPE_HUMIDITY + * \param type HDC_1000_SENSOR_TYPE_TEMP or HDC_1000_SENSOR_TYPE_HUMID * \return Temperature (centi degrees C) or Humidity (centi %RH) */ static int @@ -221,7 +221,7 @@ value(int type) } if((type != HDC_1000_SENSOR_TYPE_TEMP) && - type != HDC_1000_SENSOR_TYPE_HUMIDITY) { + type != HDC_1000_SENSOR_TYPE_HUMID) { PRINTF("Invalid type\n"); return CC26XX_SENSOR_READING_ERROR; } else { @@ -231,7 +231,7 @@ value(int type) if(type == HDC_1000_SENSOR_TYPE_TEMP) { rv = (int)(temp * 100); - } else if(type == HDC_1000_SENSOR_TYPE_HUMIDITY) { + } else if(type == HDC_1000_SENSOR_TYPE_HUMID) { rv = (int)(hum * 100); } } diff --git a/arch/platform/srf06-cc26xx/sensortag/hdc-1000-sensor.h b/arch/platform/srf06-cc26xx/sensortag/hdc-1000-sensor.h index d3089d742..5c3a8aaff 100644 --- a/arch/platform/srf06-cc26xx/sensortag/hdc-1000-sensor.h +++ b/arch/platform/srf06-cc26xx/sensortag/hdc-1000-sensor.h @@ -45,7 +45,7 @@ * and latch them. It will then generate a sensors_changed event. * * The user can then retrieve readings by calling .value() and by passing - * either HDC_1000_SENSOR_TYPE_TEMP or HDC_1000_SENSOR_TYPE_HUMIDITY as the + * either HDC_1000_SENSOR_TYPE_TEMP or HDC_1000_SENSOR_TYPE_HUMID as the * argument. Multiple calls to value() will not trigger new readings, they will * simply return the most recent latched values. * @@ -65,7 +65,7 @@ #include "lib/sensors.h" /*---------------------------------------------------------------------------*/ #define HDC_1000_SENSOR_TYPE_TEMP 1 -#define HDC_1000_SENSOR_TYPE_HUMIDITY 2 +#define HDC_1000_SENSOR_TYPE_HUMID 2 /*---------------------------------------------------------------------------*/ /** * \name HDC1000 driver states diff --git a/arch/platform/srf06-cc26xx/sensortag/mpu-9250-sensor.c b/arch/platform/srf06-cc26xx/sensortag/mpu-9250-sensor.c index a2b3651e5..9e9685cd3 100644 --- a/arch/platform/srf06-cc26xx/sensortag/mpu-9250-sensor.c +++ b/arch/platform/srf06-cc26xx/sensortag/mpu-9250-sensor.c @@ -601,11 +601,11 @@ configure(int type, int enable) { switch(type) { case SENSORS_HW_INIT: - ti_lib_rom_ioc_pin_type_gpio_input(BOARD_IOID_MPU_INT); + ti_lib_ioc_pin_type_gpio_input(BOARD_IOID_MPU_INT); ti_lib_ioc_io_port_pull_set(BOARD_IOID_MPU_INT, IOC_IOPULL_DOWN); ti_lib_ioc_io_hyst_set(BOARD_IOID_MPU_INT, IOC_HYST_ENABLE); - ti_lib_rom_ioc_pin_type_gpio_output(BOARD_IOID_MPU_POWER); + ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_MPU_POWER); ti_lib_ioc_io_drv_strength_set(BOARD_IOID_MPU_POWER, IOC_CURRENT_4MA, IOC_STRENGTH_MAX); ti_lib_gpio_clear_dio(BOARD_IOID_MPU_POWER); diff --git a/arch/platform/srf06-cc26xx/srf06/als-sensor.c b/arch/platform/srf06-cc26xx/srf06/als-sensor.c index 3b6fdecb9..42e714065 100644 --- a/arch/platform/srf06-cc26xx/srf06/als-sensor.c +++ b/arch/platform/srf06-cc26xx/srf06/als-sensor.c @@ -59,10 +59,10 @@ config(int type, int enable) ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_ALS_PWR); break; case SENSORS_ACTIVE: - ti_lib_rom_ioc_pin_type_gpio_output(BOARD_IOID_ALS_PWR); - ti_lib_rom_ioc_port_configure_set(BOARD_IOID_ALS_OUT, IOC_PORT_GPIO, - IOC_STD_OUTPUT); - ti_lib_rom_ioc_pin_type_gpio_input(BOARD_IOID_ALS_OUT); + ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_ALS_PWR); + ti_lib_ioc_port_configure_set(BOARD_IOID_ALS_OUT, IOC_PORT_GPIO, + IOC_STD_OUTPUT); + ti_lib_ioc_pin_type_gpio_input(BOARD_IOID_ALS_OUT); if(enable) { ti_lib_gpio_set_dio(BOARD_IOID_ALS_PWR); diff --git a/arch/platform/srf06-cc26xx/srf06/cc13xx/board.h b/arch/platform/srf06-cc26xx/srf06/cc13xx/board.h index 9fece9180..4c0fcf686 100644 --- a/arch/platform/srf06-cc26xx/srf06/cc13xx/board.h +++ b/arch/platform/srf06-cc26xx/srf06/cc13xx/board.h @@ -213,23 +213,14 @@ /** * \brief ROM bootloader configuration * - * Change SET_CCFG_BL_CONFIG_BL_PIN_NUMBER to BOARD_IOID_KEY_xyz to select - * which button triggers the bootloader on reset. - * - * The remaining values are not meant to be modified by the user + * Change CCXXWARE_CONF_BL_PIN_NUMBER to BOARD_IOID_KEY_xyz to select which + * button triggers the bootloader on reset. Use CCXXWARE_CONF_BL_LEVEL to + * control the pin level that enables the bootloader (0: low, 1: high). It is + * also possible to use any other externally-controlled DIO. * @{ */ -#if ROM_BOOTLOADER_ENABLE -#define SET_CCFG_BL_CONFIG_BOOTLOADER_ENABLE 0xC5 -#define SET_CCFG_BL_CONFIG_BL_LEVEL 0x00 -#define SET_CCFG_BL_CONFIG_BL_PIN_NUMBER BOARD_IOID_KEY_SELECT -#define SET_CCFG_BL_CONFIG_BL_ENABLE 0xC5 -#else -#define SET_CCFG_BL_CONFIG_BOOTLOADER_ENABLE 0x00 -#define SET_CCFG_BL_CONFIG_BL_LEVEL 0x01 -#define SET_CCFG_BL_CONFIG_BL_PIN_NUMBER 0xFF -#define SET_CCFG_BL_CONFIG_BL_ENABLE 0xFF -#endif +#define CCXXWARE_CONF_BL_PIN_NUMBER BOARD_IOID_KEY_SELECT +#define CCXXWARE_CONF_BL_LEVEL 0 /** @} */ /*---------------------------------------------------------------------------*/ /** diff --git a/arch/platform/srf06-cc26xx/srf06/cc26xx/board.h b/arch/platform/srf06-cc26xx/srf06/cc26xx/board.h index b9171388a..f31a94fb3 100644 --- a/arch/platform/srf06-cc26xx/srf06/cc26xx/board.h +++ b/arch/platform/srf06-cc26xx/srf06/cc26xx/board.h @@ -213,23 +213,14 @@ /** * \brief ROM bootloader configuration * - * Change SET_CCFG_BL_CONFIG_BL_PIN_NUMBER to BOARD_IOID_KEY_xyz to select - * which button triggers the bootloader on reset. - * - * The remaining values are not meant to be modified by the user + * Change CCXXWARE_CONF_BL_PIN_NUMBER to BOARD_IOID_KEY_xyz to select which + * button triggers the bootloader on reset. Use CCXXWARE_CONF_BL_LEVEL to + * control the pin level that enables the bootloader (0: low, 1: high). It is + * also possible to use any other externally-controlled DIO. * @{ */ -#if ROM_BOOTLOADER_ENABLE -#define SET_CCFG_BL_CONFIG_BOOTLOADER_ENABLE 0xC5 -#define SET_CCFG_BL_CONFIG_BL_LEVEL 0x00 -#define SET_CCFG_BL_CONFIG_BL_PIN_NUMBER BOARD_IOID_KEY_SELECT -#define SET_CCFG_BL_CONFIG_BL_ENABLE 0xC5 -#else -#define SET_CCFG_BL_CONFIG_BOOTLOADER_ENABLE 0x00 -#define SET_CCFG_BL_CONFIG_BL_LEVEL 0x01 -#define SET_CCFG_BL_CONFIG_BL_PIN_NUMBER 0xFF -#define SET_CCFG_BL_CONFIG_BL_ENABLE 0xFF -#endif +#define CCXXWARE_CONF_BL_PIN_NUMBER BOARD_IOID_KEY_SELECT +#define CCXXWARE_CONF_BL_LEVEL 0 /** @} */ /*---------------------------------------------------------------------------*/ /** diff --git a/arch/platform/zoul/Makefile.zoul b/arch/platform/zoul/Makefile.zoul index 586a74ae2..e43f84744 100644 --- a/arch/platform/zoul/Makefile.zoul +++ b/arch/platform/zoul/Makefile.zoul @@ -46,25 +46,8 @@ MODULES += arch/dev/cc1200 arch/dev/rgb-led os/storage/cfs BSL = $(CONTIKI)/tools/cc2538-bsl/cc2538-bsl.py -### Use the specific Zoul subplatform to query for connected devices -ifdef MOTELIST_ZOLERTIA - MOTELIST_FLAGS += -b $(MOTELIST_ZOLERTIA) -endif - -### Detect if a mote is connected over serial port -ifeq ($(HOST_OS),Darwin) - USBDEVPREFIX= - MOTELIST := $(CONTIKI)/tools/zolertia/motelist-zolertia-macos - MOTES := $(shell $(MOTELIST) -c 2>&- | cut -f 2 -d ,) - SERIALDUMP := $(CONTIKI)/tools/sky/serialdump-macos -else -### If we are not running under Mac, we assume Linux - USBDEVPREFIX= - SERIALDUMP := $(CONTIKI)/tools/sky/serialdump-linux - MOTELIST := $(CONTIKI)/tools/zolertia/motelist-zolertia - MOTES := $(shell $(MOTELIST) -b $(MOTELIST_ZOLERTIA) -c 2>&- | cut -f 2 -d , | \ - perl -ne 'print $$1 . " " if(m-(/dev/\w+)-);') -endif +MOTES := $(shell python $(TOOLS_DIR)/motelist/motelist.py --omit-header \ + | grep $(MOTELIST_ZOLERTIA) | cut -f1 -d " ") ### If PORT is defined, override to keep backward compatibility ifdef PORT @@ -83,11 +66,12 @@ endif ### Variable that expands into a pattern rule to upload to a given MOTE. ### Requires $(MOTE) to be defined -### $$$$ Double escapes $s that need to be passed to the shell - once for when make parses UPLOAD_RULE, and once for when the expanded rule is parsed by make. +### $$$$ Double escapes $s that need to be passed to the shell - once for when +### make parses UPLOAD_RULE, and once for when the expanded rule is parsed by make. define UPLOAD_RULE -%.$(MOTE): %.bin %.elf +%.$(MOTE): $(OUT_BIN) $(OUT_ELF) @echo "Flashing $(MOTE)" - @BSL_ADDRESS=`$(OBJDUMP) -h $$*.elf | grep -B1 LOAD | \ + @BSL_ADDRESS=`$(OBJDUMP) -h $(BUILD_DIR_BOARD)/$$*.elf | grep -B1 LOAD | \ grep -Ev 'LOAD|\-\-' | awk '{print "0x" $$$$5}' | \ sort -g | head -1`; \ $(PYTHON) $(BSL) $(BSL_FLAGS) -b $(BSL_SPEED) -a $$$${BSL_ADDRESS} -p $(MOTE) $$< @@ -96,15 +80,11 @@ endef ### Create an upload rule for every MOTE connected $(foreach MOTE,$(MOTES),$(eval $(UPLOAD_RULE))) -motelist: - $(MOTELIST) -zoul-motelist: - $(MOTELIST) $(MOTELIST_FLAGS) +.PHONY: zoul-motes + zoul-motes: @echo $(MOTES) -serialview: - $(SERIALDUMP) -b115200 $(USBDEVPREFIX)$(firstword $(MOTES)) | $(CONTIKI)/tools/timestamp - -login: - $(SERIALDUMP) -b115200 $(USBDEVPREFIX)$(firstword $(MOTES)) +### For the login etc targets +BAUDRATE = 115200 +PORT = $(USBDEVPREFIX)$(firstword $(MOTES)) diff --git a/arch/platform/zoul/contiki-conf.h b/arch/platform/zoul/contiki-conf.h index 098c37404..a4c455d86 100644 --- a/arch/platform/zoul/contiki-conf.h +++ b/arch/platform/zoul/contiki-conf.h @@ -55,6 +55,25 @@ #endif /* PROJECT_CONF_PATH */ /*---------------------------------------------------------------------------*/ #include "cc2538-def.h" + +unsigned radio_phy_overhead(void); +unsigned radio_byte_air_time(void); +unsigned radio_delay_before_tx(void); +unsigned radio_delay_before_rx(void); +unsigned radio_delay_before_detect(void); +uint16_t *radio_tsch_timeslot_timing(void); + +/** @} */ +/*---------------------------------------------------------------------------*/ + +#define RADIO_PHY_OVERHEAD radio_phy_overhead() +#define RADIO_BYTE_AIR_TIME radio_byte_air_time() +#define RADIO_DELAY_BEFORE_TX radio_delay_before_tx() +#define RADIO_DELAY_BEFORE_RX radio_delay_before_rx() +#define RADIO_DELAY_BEFORE_DETECT radio_delay_before_detect() + +#define TSCH_CONF_DEFAULT_TIMESLOT_TIMING radio_tsch_timeslot_timing() + /*---------------------------------------------------------------------------*/ /** * \name Serial Boot Loader Backdoor configuration diff --git a/arch/platform/zoul/dev/cc1200-zoul-arch.c b/arch/platform/zoul/dev/cc1200-zoul-arch.c index 8c9d8cdd7..b0fd8dd96 100644 --- a/arch/platform/zoul/dev/cc1200-zoul-arch.c +++ b/arch/platform/zoul/dev/cc1200-zoul-arch.c @@ -76,18 +76,8 @@ /*---------------------------------------------------------------------------*/ #if DEBUG_CC1200_ARCH > 0 #define PRINTF(...) printf(__VA_ARGS__) -#define BUSYWAIT_UNTIL(cond, max_time) \ - do { \ - rtimer_clock_t t0; \ - t0 = RTIMER_NOW(); \ - while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (max_time))) {} \ - if(!(RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (max_time)))) { \ - printf("ARCH: Timeout exceeded in line %d!\n", __LINE__); \ - } \ - } while(0) #else #define PRINTF(...) -#define BUSYWAIT_UNTIL(cond, max_time) while(!cond) #endif /*---------------------------------------------------------------------------*/ extern int cc1200_rx_interrupt(void); @@ -105,7 +95,7 @@ cc1200_arch_spi_select(void) /* Set CSn to low (0) */ GPIO_CLR_PIN(CC1200_SPI_CSN_PORT_BASE, CC1200_SPI_CSN_PIN_MASK); /* The MISO pin should go low before chip is fully enabled. */ - BUSYWAIT_UNTIL( + RTIMER_BUSYWAIT_UNTIL( GPIO_READ_PIN(CC1200_SPI_MISO_PORT_BASE, CC1200_SPI_MISO_PIN_MASK) == 0, RTIMER_SECOND / 100); } @@ -288,7 +278,7 @@ cc1200_arch_init(void) cc1200_arch_spi_deselect(); /* Ensure MISO is high */ - BUSYWAIT_UNTIL( + RTIMER_BUSYWAIT_UNTIL( GPIO_READ_PIN(CC1200_SPI_MISO_PORT_BASE, CC1200_SPI_MISO_PIN_MASK), RTIMER_SECOND / 10); } @@ -297,4 +287,3 @@ cc1200_arch_init(void) * @} * @} */ - diff --git a/arch/platform/zoul/dev/dht22.c b/arch/platform/zoul/dev/dht22.c index f12859dff..23174b2e6 100644 --- a/arch/platform/zoul/dev/dht22.c +++ b/arch/platform/zoul/dev/dht22.c @@ -51,15 +51,6 @@ #define PRINTF(...) #endif /*---------------------------------------------------------------------------*/ -#define BUSYWAIT_UNTIL(max_time) \ - do { \ - rtimer_clock_t t0; \ - t0 = RTIMER_NOW(); \ - while(RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + (max_time))) { \ - watchdog_periodic(); \ - } \ - } while(0) -/*---------------------------------------------------------------------------*/ #define DHT22_PORT_BASE GPIO_PORT_TO_BASE(DHT22_PORT) #define DHT22_PIN_MASK GPIO_PIN_MASK(DHT22_PIN) /*---------------------------------------------------------------------------*/ @@ -72,7 +63,7 @@ dht22_read(void) { uint8_t i; uint8_t j = 0; - uint8_t last_state; + uint8_t last_state = 0xFF; uint8_t counter = 0; uint8_t checksum = 0; @@ -80,12 +71,12 @@ dht22_read(void) /* Exit low power mode and initialize variables */ GPIO_SET_OUTPUT(DHT22_PORT_BASE, DHT22_PIN_MASK); GPIO_SET_PIN(DHT22_PORT_BASE, DHT22_PIN_MASK); - BUSYWAIT_UNTIL(DHT22_AWAKE_TIME); + RTIMER_BUSYWAIT(DHT22_AWAKE_TIME); memset(dht22_data, 0, DHT22_BUFFER); /* Initialization sequence */ GPIO_CLR_PIN(DHT22_PORT_BASE, DHT22_PIN_MASK); - BUSYWAIT_UNTIL(DHT22_START_TIME); + RTIMER_BUSYWAIT(DHT22_START_TIME); GPIO_SET_PIN(DHT22_PORT_BASE, DHT22_PIN_MASK); clock_delay_usec(DHT22_READY_TIME); @@ -95,7 +86,6 @@ dht22_read(void) * if the line is high between 70-74us the bit sent will be "1" (one). */ GPIO_SET_INPUT(DHT22_PORT_BASE, DHT22_PIN_MASK); - last_state = GPIO_READ_PIN(DHT22_PORT_BASE, DHT22_PIN_MASK); for(i = 0; i < DHT22_MAX_TIMMING; i++) { counter = 0; @@ -208,8 +198,8 @@ value(int type) } } /*---------------------------------------------------------------------------*/ -int -dht22_read_all(int *temperature, int *humidity) +int16_t +dht22_read_all(int16_t *temperature, int16_t *humidity) { if((temperature == NULL) || (humidity == NULL)) { PRINTF("DHT22: Invalid arguments\n"); diff --git a/arch/platform/zoul/dev/dht22.h b/arch/platform/zoul/dev/dht22.h index f75a96494..ecd02a26e 100644 --- a/arch/platform/zoul/dev/dht22.h +++ b/arch/platform/zoul/dev/dht22.h @@ -90,7 +90,7 @@ #define DHT22_COUNT 8 /**< Minimum ticks to detect a "1" bit */ #define DHT22_MAX_TIMMING 85 /**< Maximum ticks in a single operation */ #define DHT22_READING_DELAY 1 /**< 1 us */ -#define DHT22_READY_TIME 20 /**< 40 us */ +#define DHT22_READY_TIME 40 /**< 40 us */ #define DHT22_START_TIME (RTIMER_SECOND / 50) /**< 20 ms */ #define DHT22_AWAKE_TIME (RTIMER_SECOND / 4) /**< 250 ms */ /** @} */ @@ -99,7 +99,7 @@ * \name DHT22 auxiliary functions * @{ */ -int dht22_read_all(int *temperature, int *humidity); +int16_t dht22_read_all(int16_t *temperature, int16_t *humidity); /** @} */ /* -------------------------------------------------------------------------- */ #define DHT22_SENSOR "DHT22 sensor" diff --git a/arch/platform/zoul/firefly-reva/Makefile.firefly-reva b/arch/platform/zoul/firefly-reva/Makefile.firefly-reva index afecf9fa5..bfbcb03fb 100644 --- a/arch/platform/zoul/firefly-reva/Makefile.firefly-reva +++ b/arch/platform/zoul/firefly-reva/Makefile.firefly-reva @@ -1,2 +1,2 @@ -MOTELIST_ZOLERTIA = firefly +MOTELIST_ZOLERTIA := Firefly BOARD_SOURCEFILES += board.c diff --git a/arch/platform/zoul/firefly/Makefile.firefly b/arch/platform/zoul/firefly/Makefile.firefly index afecf9fa5..bfbcb03fb 100644 --- a/arch/platform/zoul/firefly/Makefile.firefly +++ b/arch/platform/zoul/firefly/Makefile.firefly @@ -1,2 +1,2 @@ -MOTELIST_ZOLERTIA = firefly +MOTELIST_ZOLERTIA := Firefly BOARD_SOURCEFILES += board.c diff --git a/arch/platform/zoul/orion/Makefile.orion b/arch/platform/zoul/orion/Makefile.orion index ebc1bdad4..b7313afc0 100644 --- a/arch/platform/zoul/orion/Makefile.orion +++ b/arch/platform/zoul/orion/Makefile.orion @@ -1,4 +1,4 @@ -MOTELIST_ZOLERTIA = orion +MOTELIST_ZOLERTIA := Orion MODULES += arch/dev/enc28j60 CC2538_ENC28J60_ARCH ?= gpio ifeq ($(WITH_IP64),1) diff --git a/arch/platform/zoul/platform.c b/arch/platform/zoul/platform.c index 8cce149ee..bed948829 100644 --- a/arch/platform/zoul/platform.c +++ b/arch/platform/zoul/platform.c @@ -171,7 +171,7 @@ set_rf_params(void) NETSTACK_RADIO.set_value(RADIO_PARAM_PAN_ID, IEEE802154_PANID); NETSTACK_RADIO.set_value(RADIO_PARAM_16BIT_ADDR, short_addr); - NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, CC2538_RF_CHANNEL); + NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, IEEE802154_DEFAULT_CHANNEL); NETSTACK_RADIO.set_object(RADIO_PARAM_64BIT_ADDR, ext_addr, 8); } /*---------------------------------------------------------------------------*/ @@ -257,6 +257,48 @@ platform_idle() lpm_enter(); } /*---------------------------------------------------------------------------*/ +unsigned +radio_phy_overhead(void) { + radio_value_t ret; + NETSTACK_RADIO.get_value(RADIO_CONST_PHY_OVERHEAD, &ret); + return (unsigned)ret; +} +/*---------------------------------------------------------------------------*/ +unsigned +radio_byte_air_time(void) { + radio_value_t ret; + NETSTACK_RADIO.get_value(RADIO_CONST_BYTE_AIR_TIME, &ret); + return (unsigned)ret; +} +/*---------------------------------------------------------------------------*/ +unsigned +radio_delay_before_tx(void) { + radio_value_t ret; + NETSTACK_RADIO.get_value(RADIO_CONST_DELAY_BEFORE_TX, &ret); + return (unsigned)ret; +} +/*---------------------------------------------------------------------------*/ +unsigned +radio_delay_before_rx(void) { + radio_value_t ret; + NETSTACK_RADIO.get_value(RADIO_CONST_DELAY_BEFORE_RX, &ret); + return (unsigned)ret; +} +/*---------------------------------------------------------------------------*/ +unsigned +radio_delay_before_detect(void) { + radio_value_t ret; + NETSTACK_RADIO.get_value(RADIO_CONST_DELAY_BEFORE_DETECT, &ret); + return (unsigned)ret; +} +/*---------------------------------------------------------------------------*/ +uint16_t * +radio_tsch_timeslot_timing(void) { + uint16_t *ret; + NETSTACK_RADIO.get_object(RADIO_CONST_TSCH_TIMING, &ret, sizeof(ret)); + return ret; +} +/*---------------------------------------------------------------------------*/ /** * @} * @} diff --git a/arch/platform/zoul/remote-reva/Makefile.remote-reva b/arch/platform/zoul/remote-reva/Makefile.remote-reva index fcccdf0f4..ec4095265 100644 --- a/arch/platform/zoul/remote-reva/Makefile.remote-reva +++ b/arch/platform/zoul/remote-reva/Makefile.remote-reva @@ -1,4 +1,4 @@ -MOTELIST_ZOLERTIA = remote +MOTELIST_ZOLERTIA := RE-Mote BOARD_SOURCEFILES += board.c antenna-sw.c mmc-arch.c rtcc.c power-mgmt.c MODULES += os/lib/fs/fat os/lib/fs/fat/option arch/platform/zoul/fs/fat arch/dev/disk/mmc diff --git a/arch/platform/zoul/remote-revb/Makefile.remote-revb b/arch/platform/zoul/remote-revb/Makefile.remote-revb index fcccdf0f4..ec4095265 100644 --- a/arch/platform/zoul/remote-revb/Makefile.remote-revb +++ b/arch/platform/zoul/remote-revb/Makefile.remote-revb @@ -1,4 +1,4 @@ -MOTELIST_ZOLERTIA = remote +MOTELIST_ZOLERTIA := RE-Mote BOARD_SOURCEFILES += board.c antenna-sw.c mmc-arch.c rtcc.c power-mgmt.c MODULES += os/lib/fs/fat os/lib/fs/fat/option arch/platform/zoul/fs/fat arch/dev/disk/mmc diff --git a/examples/6tisch/6p-packet/Makefile b/examples/6tisch/6p-packet/Makefile index 7dcf9ccd3..3ba74d3b9 100644 --- a/examples/6tisch/6p-packet/Makefile +++ b/examples/6tisch/6p-packet/Makefile @@ -1,8 +1,7 @@ CONTIKI_PROJECT = sixp-node PROJECT_SOURCEFILES += test-sf.c -PLATFORMS_EXCLUDE = sky nrf52dk native -BOARDS_EXCLUDE = srf06/cc13xx launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350 +PLATFORMS_EXCLUDE = sky nrf52dk native simplelink CONTIKI = ../../../ diff --git a/examples/6tisch/channel-selection-demo/Makefile b/examples/6tisch/channel-selection-demo/Makefile new file mode 100644 index 000000000..a44c76f10 --- /dev/null +++ b/examples/6tisch/channel-selection-demo/Makefile @@ -0,0 +1,34 @@ +CONTIKI_PROJECT = node +all: $(CONTIKI_PROJECT) + +CONTIKI=../../.. + +PLATFORMS_EXCLUDE = sky nrf52dk native +BOARDS_EXCLUDE = srf06/cc13xx launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350 + +# The channel selection library +MODULES += os/services/tsch-cs + +# force Orchestra from command line +MAKE_WITH_ORCHESTRA ?= 0 +# force Security from command line +MAKE_WITH_SECURITY ?= 0 +# print #routes periodically, used for regression tests +MAKE_WITH_PERIODIC_ROUTES_PRINT ?= 0 + +MAKE_MAC = MAKE_MAC_TSCH +MODULES += os/services/shell + +ifeq ($(MAKE_WITH_ORCHESTRA),1) +MODULES += os/services/orchestra +endif + +ifeq ($(MAKE_WITH_SECURITY),1) +CFLAGS += -DWITH_SECURITY=1 +endif + +ifeq ($(MAKE_WITH_PERIODIC_ROUTES_PRINT),1) +CFLAGS += -DWITH_PERIODIC_ROUTES_PRINT=1 +endif + +include $(CONTIKI)/Makefile.include diff --git a/examples/6tisch/channel-selection-demo/README.md b/examples/6tisch/channel-selection-demo/README.md new file mode 100644 index 000000000..b6415ab9b --- /dev/null +++ b/examples/6tisch/channel-selection-demo/README.md @@ -0,0 +1,8 @@ +Demonstration of TSCH adaptive channel selection based on background noise RSSI metric. +TSCH stats must be enabled for the adaptive selection functionality to compile and work. + +This code relies on the `os/services/channel-selection` library that implements +the "RSSI upstream" adaptative channel selection strategy, described in the following paper: + +A. Elsts, X. Fafoutis, G. Oikonomou and R. Piechocki. Adaptive Channel Selection in IEEE 802.15.4 TSCH Networks, 1st Global Internet of Things Summit, 2017. +http://ieeexplore.ieee.org/document/8016246/ \ No newline at end of file diff --git a/examples/6tisch/channel-selection-demo/node.c b/examples/6tisch/channel-selection-demo/node.c new file mode 100644 index 000000000..86dca79d8 --- /dev/null +++ b/examples/6tisch/channel-selection-demo/node.c @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2015, SICS Swedish ICT. + * Copyright (c) 2018, University of Bristol - http://www.bristol.ac.uk + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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 + * A RPL+TSCH node. + * + * \author Simon Duquennoy + * Atis Elsts + */ + +#include "contiki.h" +#include "sys/node-id.h" +#include "sys/log.h" +#include "net/ipv6/uip-ds6-route.h" +#include "net/ipv6/uip-sr.h" +#include "net/mac/tsch/tsch.h" +#include "net/routing/routing.h" +#include "tsch-cs.h" + +#define DEBUG DEBUG_PRINT +#include "net/ipv6/uip-debug.h" + +/*---------------------------------------------------------------------------*/ +PROCESS(node_process, "RPL Node"); +AUTOSTART_PROCESSES(&node_process); + +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(node_process, ev, data) +{ + int is_coordinator; + + PROCESS_BEGIN(); + + is_coordinator = 0; + +#if CONTIKI_TARGET_COOJA + is_coordinator = (node_id == 1); +#endif + + if(is_coordinator) { + NETSTACK_ROUTING.root_start(); + } + NETSTACK_MAC.on(); + +#if WITH_PERIODIC_ROUTES_PRINT + { + static struct etimer et; + /* Print out routing tables every minute */ + etimer_set(&et, CLOCK_SECOND * 60); + while(1) { + /* Used for non-regression testing */ + #if (UIP_MAX_ROUTES != 0) + PRINTF("Routing entries: %u\n", uip_ds6_route_num_routes()); + #endif + #if (UIP_SR_LINK_NUM != 0) + PRINTF("Routing links: %u\n", uip_sr_num_nodes()); + #endif + PROCESS_YIELD_UNTIL(etimer_expired(&et)); + etimer_reset(&et); + } + } +#endif /* WITH_PERIODIC_ROUTES_PRINT */ + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/examples/6tisch/channel-selection-demo/project-conf.h b/examples/6tisch/channel-selection-demo/project-conf.h new file mode 100644 index 000000000..dcf326036 --- /dev/null +++ b/examples/6tisch/channel-selection-demo/project-conf.h @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2015, SICS Swedish ICT. + * Copyright (c) 2017, University of Bristol - http://www.bristol.ac.uk + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + */ + +/** + * \author Simon Duquennoy + * Atis Elsts + */ + +#ifndef __PROJECT_CONF_H__ +#define __PROJECT_CONF_H__ + +#include +#include + +/* Set to enable TSCH security */ +#ifndef WITH_SECURITY +#define WITH_SECURITY 0 +#endif /* WITH_SECURITY */ + +/* USB serial takes space, free more space elsewhere */ +#define SICSLOWPAN_CONF_FRAG 0 +#define UIP_CONF_BUFFER_SIZE 160 + +/*******************************************************/ +/******************* Configure TSCH ********************/ +/*******************************************************/ + +/* IEEE802.15.4 PANID */ +#define IEEE802154_CONF_PANID 0x81a5 + +/* Do not start TSCH at init, wait for NETSTACK_MAC.on() */ +#define TSCH_CONF_AUTOSTART 0 + +/* 6TiSCH minimal schedule length. + * Larger values result in less frequent active slots: reduces capacity and saves energy. */ +#define TSCH_SCHEDULE_CONF_DEFAULT_LENGTH 3 + +#if WITH_SECURITY + +/* Enable security */ +#define LLSEC802154_CONF_ENABLED 1 + +#endif /* WITH_SECURITY */ + +/* Enable TSCH statistics: must be on for channel selection to work */ +#define TSCH_STATS_CONF_ON 1 + +/* Enable periodic RSSI sampling for TSCH statistics */ +#define TSCH_STATS_CONF_SAMPLE_NOISE_RSSI 1 + +/* Reduce the TSCH stat "decay to normal" period to get printouts more often */ +#define TSCH_STATS_CONF_DECAY_INTERVAL (60 * CLOCK_SECOND) + +/* For adaptive channel selection */ +extern void tsch_cs_channel_stats_updated(uint8_t updated_channel, uint16_t old_busyness_metric); +extern bool tsch_cs_process(void); +/* These will be called from the core TSCH code */ +#define TSCH_CALLBACK_CHANNEL_STATS_UPDATED tsch_cs_channel_stats_updated +#define TSCH_CALLBACK_SELECT_CHANNELS tsch_cs_process + +/* The coordinator will update the network nodes with new hopping sequences */ +#define TSCH_PACKET_CONF_EB_WITH_HOPPING_SEQUENCE 1 + +/* Reduce the EB period in order to update the network nodes with more agility */ +#define TSCH_CONF_EB_PERIOD (4 * CLOCK_SECOND) +#define TSCH_CONF_MAX_EB_PERIOD (4 * CLOCK_SECOND) + +/*******************************************************/ +/************* Other system configuration **************/ +/*******************************************************/ + +/* Logging */ +#define LOG_CONF_LEVEL_RPL LOG_LEVEL_INFO +#define LOG_CONF_LEVEL_TCPIP LOG_LEVEL_WARN +#define LOG_CONF_LEVEL_IPV6 LOG_LEVEL_WARN +#define LOG_CONF_LEVEL_6LOWPAN LOG_LEVEL_WARN +#define LOG_CONF_LEVEL_MAC LOG_LEVEL_DBG +#define LOG_CONF_LEVEL_FRAMER LOG_LEVEL_INFO +#define TSCH_LOG_CONF_PER_SLOT 1 + +#endif /* __PROJECT_CONF_H__ */ diff --git a/examples/6tisch/etsi-plugtest-2017/Makefile b/examples/6tisch/etsi-plugtest-2017/Makefile index 3279b6ebc..6dc463078 100644 --- a/examples/6tisch/etsi-plugtest-2017/Makefile +++ b/examples/6tisch/etsi-plugtest-2017/Makefile @@ -1,8 +1,8 @@ CONTIKI_PROJECT = node all: $(CONTIKI_PROJECT) -PLATFORMS_EXCLUDE = sky nrf52dk native -BOARDS_EXCLUDE = srf06/cc13xx launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350 +PLATFORMS_EXCLUDE = sky nrf52dk native simplelink +BOARDS_EXCLUDE = sensortag/cc2650 sensortag/cc1350 MAKE_WITH_SECURITY ?= 0 # force Security from command line ifeq ($(MAKE_WITH_SECURITY),1) diff --git a/examples/6tisch/etsi-plugtest-2017/node.c b/examples/6tisch/etsi-plugtest-2017/node.c index 3046bb291..32d0429c0 100644 --- a/examples/6tisch/etsi-plugtest-2017/node.c +++ b/examples/6tisch/etsi-plugtest-2017/node.c @@ -37,7 +37,7 @@ */ #include "contiki.h" -#include "node-id.h" +#include "sys/node-id.h" #include "sys/log.h" #include "net/ipv6/uip-ds6-route.h" #include "net/mac/tsch/tsch.h" diff --git a/examples/6tisch/simple-node/Makefile b/examples/6tisch/simple-node/Makefile index 63ce8ecbd..06a83ebdd 100644 --- a/examples/6tisch/simple-node/Makefile +++ b/examples/6tisch/simple-node/Makefile @@ -1,8 +1,7 @@ CONTIKI_PROJECT = node all: $(CONTIKI_PROJECT) -PLATFORMS_EXCLUDE = sky nrf52dk native -BOARDS_EXCLUDE = srf06/cc13xx launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350 +PLATFORMS_EXCLUDE = sky nrf52dk native simplelink CONTIKI=../../.. diff --git a/examples/6tisch/simple-node/node.c b/examples/6tisch/simple-node/node.c index d2f75ae33..381d81f8e 100644 --- a/examples/6tisch/simple-node/node.c +++ b/examples/6tisch/simple-node/node.c @@ -37,7 +37,7 @@ */ #include "contiki.h" -#include "node-id.h" +#include "sys/node-id.h" #include "sys/log.h" #include "net/ipv6/uip-ds6-route.h" #include "net/ipv6/uip-sr.h" diff --git a/examples/6tisch/sixtop/Makefile b/examples/6tisch/sixtop/Makefile index 5ca6be853..5c35696e4 100644 --- a/examples/6tisch/sixtop/Makefile +++ b/examples/6tisch/sixtop/Makefile @@ -1,8 +1,7 @@ CONTIKI_PROJECT = node-sixtop all: $(CONTIKI_PROJECT) -PLATFORMS_EXCLUDE = sky nrf52dk native -BOARDS_EXCLUDE = srf06/cc13xx launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350 +PLATFORMS_EXCLUDE = sky nrf52dk native simplelink PROJECT_SOURCEFILES += sf-simple.c CONTIKI=../../.. diff --git a/examples/6tisch/sixtop/node-sixtop.c b/examples/6tisch/sixtop/node-sixtop.c index 67bee378a..e2dfe08c2 100755 --- a/examples/6tisch/sixtop/node-sixtop.c +++ b/examples/6tisch/sixtop/node-sixtop.c @@ -38,7 +38,7 @@ */ #include "contiki.h" -#include "node-id.h" +#include "sys/node-id.h" #include "sys/log.h" #include "net/ipv6/uip-ds6-route.h" #include "net/mac/tsch/tsch.h" diff --git a/examples/6tisch/sixtop/project-conf.h b/examples/6tisch/sixtop/project-conf.h index 5235353c2..bb107175f 100755 --- a/examples/6tisch/sixtop/project-conf.h +++ b/examples/6tisch/sixtop/project-conf.h @@ -74,33 +74,4 @@ #endif /* WITH_SECURITY */ -/*******************************************************/ -/************* Other system configuration **************/ -/*******************************************************/ - -#if CONTIKI_TARGET_Z1 -/* Save some space to fit the limited RAM of the z1 */ -#define UIP_CONF_TCP 0 -#define QUEUEBUF_CONF_NUM 2 -#define NETSTACK_MAX_ROUTE_ENTRIES 2 -#define NBR_TABLE_CONF_MAX_NEIGHBORS 2 -#define UIP_CONF_ND6_SEND_NA 0 -#define SICSLOWPAN_CONF_FRAG 0 - -#if WITH_SECURITY -/* Note: on sky or z1 in cooja, crypto operations are done in S/W and - * cannot be accommodated in normal slots. Use 65ms slots instead, and - * a very short 6TiSCH minimal schedule length */ -#define TSCH_CONF_DEFAULT_TIMESLOT_LENGTH 65000 -#define TSCH_SCHEDULE_CONF_DEFAULT_LENGTH 2 -#endif /* WITH_SECURITY */ - -#endif /* CONTIKI_TARGET_Z1 */ - -#if CONTIKI_TARGET_CC2538DK || CONTIKI_TARGET_ZOUL || \ - CONTIKI_TARGET_OPENMOTE_CC2538 -#define TSCH_CONF_HW_FRAME_FILTERING 0 -#endif /* CONTIKI_TARGET_CC2538DK || CONTIKI_TARGET_ZOUL \ - || CONTIKI_TARGET_OPENMOTE_CC2538 */ - #endif /* PROJECT_CONF_H_ */ diff --git a/examples/6tisch/sixtop/sf-simple.c b/examples/6tisch/sixtop/sf-simple.c index 689c668e7..f7393ab4c 100644 --- a/examples/6tisch/sixtop/sf-simple.c +++ b/examples/6tisch/sixtop/sf-simple.c @@ -108,7 +108,7 @@ print_cell_list(const uint8_t *cell_list, uint16_t cell_list_len) uint16_t i; sf_simple_cell_t cell; - for(i = 0; i < (cell_list_len / sizeof(cell)); i++) { + for(i = 0; i < cell_list_len; i += sizeof(cell)) { read_cell(&cell_list[i], &cell); PRINTF("%u ", cell.timeslot_offset); } @@ -132,7 +132,7 @@ add_links_to_schedule(const linkaddr_t *peer_addr, uint8_t link_option, return; } - for(i = 0; i < (cell_list_len / sizeof(cell)); i++) { + for(i = 0; i < cell_list_len; i += sizeof(cell)) { read_cell(&cell_list[i], &cell); if(cell.timeslot_offset == 0xffff) { continue; @@ -166,7 +166,7 @@ remove_links_to_schedule(const uint8_t *cell_list, uint16_t cell_list_len) return; } - for(i = 0; i < (cell_list_len / sizeof(cell)); i++) { + for(i = 0; i < cell_list_len; i += sizeof(cell)) { read_cell(&cell_list[i], &cell); if(cell.timeslot_offset == 0xffff) { continue; @@ -335,7 +335,7 @@ delete_req_input(const uint8_t *body, uint16_t body_len, if(num_cells > 0 && cell_list_len > 0) { /* ensure before delete */ - for(i = 0, removed_link = 0; i < (cell_list_len / sizeof(cell)); i++) { + for(i = 0, removed_link = 0; i < cell_list_len; i += sizeof(cell)) { read_cell(&cell_list[i], &cell); if(tsch_schedule_get_link_by_timeslot(slotframe, cell.timeslot_offset) != NULL) { diff --git a/examples/6tisch/tsch-stats/Makefile b/examples/6tisch/tsch-stats/Makefile new file mode 100644 index 000000000..0c8863301 --- /dev/null +++ b/examples/6tisch/tsch-stats/Makefile @@ -0,0 +1,31 @@ +CONTIKI_PROJECT = node +all: $(CONTIKI_PROJECT) + +CONTIKI=../../.. + +PLATFORMS_EXCLUDE = sky nrf52dk native +BOARDS_EXCLUDE = srf06/cc13xx launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350 + +# force Orchestra from command line +MAKE_WITH_ORCHESTRA ?= 0 +# force Security from command line +MAKE_WITH_SECURITY ?= 0 +# print #routes periodically, used for regression tests +MAKE_WITH_PERIODIC_ROUTES_PRINT ?= 0 + +MAKE_MAC = MAKE_MAC_TSCH +MODULES += os/services/shell + +ifeq ($(MAKE_WITH_ORCHESTRA),1) +MODULES += os/services/orchestra +endif + +ifeq ($(MAKE_WITH_SECURITY),1) +CFLAGS += -DWITH_SECURITY=1 +endif + +ifeq ($(MAKE_WITH_PERIODIC_ROUTES_PRINT),1) +CFLAGS += -DWITH_PERIODIC_ROUTES_PRINT=1 +endif + +include $(CONTIKI)/Makefile.include diff --git a/examples/6tisch/tsch-stats/README.md b/examples/6tisch/tsch-stats/README.md new file mode 100644 index 000000000..1ee915f9d --- /dev/null +++ b/examples/6tisch/tsch-stats/README.md @@ -0,0 +1 @@ +Demonstration of TSCH stats. \ No newline at end of file diff --git a/examples/6tisch/tsch-stats/node.c b/examples/6tisch/tsch-stats/node.c new file mode 100644 index 000000000..92b19306a --- /dev/null +++ b/examples/6tisch/tsch-stats/node.c @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2015, SICS Swedish ICT. + * Copyright (c) 2018, University of Bristol - http://www.bristol.ac.uk + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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 + * A RPL+TSCH node. + * + * \author Simon Duquennoy + * Atis Elsts + */ + +#include "contiki.h" +#include "sys/node-id.h" +#include "sys/log.h" +#include "net/ipv6/uip-ds6-route.h" +#include "net/ipv6/uip-sr.h" +#include "net/mac/tsch/tsch.h" +#include "net/routing/routing.h" + +#define DEBUG DEBUG_PRINT +#include "net/ipv6/uip-debug.h" + +/*---------------------------------------------------------------------------*/ +PROCESS(node_process, "RPL Node"); +AUTOSTART_PROCESSES(&node_process); + +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(node_process, ev, data) +{ + int is_coordinator; + + PROCESS_BEGIN(); + + is_coordinator = 0; + +#if CONTIKI_TARGET_COOJA + is_coordinator = (node_id == 1); +#endif + + if(is_coordinator) { + NETSTACK_ROUTING.root_start(); + } + NETSTACK_MAC.on(); + +#if WITH_PERIODIC_ROUTES_PRINT + { + static struct etimer et; + /* Print out routing tables every minute */ + etimer_set(&et, CLOCK_SECOND * 60); + while(1) { + /* Used for non-regression testing */ + #if (UIP_MAX_ROUTES != 0) + PRINTF("Routing entries: %u\n", uip_ds6_route_num_routes()); + #endif + #if (UIP_SR_LINK_NUM != 0) + PRINTF("Routing links: %u\n", uip_sr_num_nodes()); + #endif + PROCESS_YIELD_UNTIL(etimer_expired(&et)); + etimer_reset(&et); + } + } +#endif /* WITH_PERIODIC_ROUTES_PRINT */ + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/examples/6tisch/tsch-stats/project-conf.h b/examples/6tisch/tsch-stats/project-conf.h new file mode 100644 index 000000000..f3e80dc99 --- /dev/null +++ b/examples/6tisch/tsch-stats/project-conf.h @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2015, SICS Swedish ICT. + * Copyright (c) 2017, University of Bristol - http://www.bristol.ac.uk + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + */ + +/** + * \author Simon Duquennoy + * Atis Elsts + */ + +#ifndef __PROJECT_CONF_H__ +#define __PROJECT_CONF_H__ + +/* Set to enable TSCH security */ +#ifndef WITH_SECURITY +#define WITH_SECURITY 0 +#endif /* WITH_SECURITY */ + +/* USB serial takes space, free more space elsewhere */ +#define SICSLOWPAN_CONF_FRAG 0 +#define UIP_CONF_BUFFER_SIZE 160 + +/*******************************************************/ +/******************* Configure TSCH ********************/ +/*******************************************************/ + +/* IEEE802.15.4 PANID */ +#define IEEE802154_CONF_PANID 0x81a5 + +/* Do not start TSCH at init, wait for NETSTACK_MAC.on() */ +#define TSCH_CONF_AUTOSTART 0 + +/* 6TiSCH minimal schedule length. + * Larger values result in less frequent active slots: reduces capacity and saves energy. */ +#define TSCH_SCHEDULE_CONF_DEFAULT_LENGTH 3 + +#if WITH_SECURITY + +/* Enable security */ +#define LLSEC802154_CONF_ENABLED 1 + +#endif /* WITH_SECURITY */ + +/* Enable TSCH statistics */ +#define TSCH_STATS_CONF_ON 1 + +/* Enable periodic RSSI sampling for TSCH statistics */ +#define TSCH_STATS_CONF_SAMPLE_NOISE_RSSI 1 + +/* Reduce the TSCH stat "decay to normal" period to get printouts more often */ +#define TSCH_STATS_CONF_DECAY_INTERVAL (60 * CLOCK_SECOND) + +/*******************************************************/ +/************* Other system configuration **************/ +/*******************************************************/ + +/* Logging */ +#define LOG_CONF_LEVEL_RPL LOG_LEVEL_INFO +#define LOG_CONF_LEVEL_TCPIP LOG_LEVEL_WARN +#define LOG_CONF_LEVEL_IPV6 LOG_LEVEL_WARN +#define LOG_CONF_LEVEL_6LOWPAN LOG_LEVEL_WARN +#define LOG_CONF_LEVEL_MAC LOG_LEVEL_DBG +#define LOG_CONF_LEVEL_FRAMER LOG_LEVEL_INFO +#define TSCH_LOG_CONF_PER_SLOT 1 + +#endif /* __PROJECT_CONF_H__ */ diff --git a/examples/benchmarks/rpl-req-resp/Makefile b/examples/benchmarks/rpl-req-resp/Makefile new file mode 100644 index 000000000..11413ecd3 --- /dev/null +++ b/examples/benchmarks/rpl-req-resp/Makefile @@ -0,0 +1,29 @@ +CONTIKI_PROJECT = node +all: $(CONTIKI_PROJECT) + +PLATFORMS_EXCLUDE = sky nrf52dk native simplelink +BOARDS_EXCLUDE = srf06/cc13xx launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350 + +MODULES_REL += ../testbeds +MODULES += os/services/deployment +MODULES += os/services/simple-energest + +CONFIG?=CONFIG_TSCH_OPTIMS + +ifeq ($(CONFIG),CONFIG_CSMA) +MAKE_MAC = MAKE_MAC_CSMA +else ifeq ($(CONFIG),CONFIG_TSCH) +MAKE_MAC = MAKE_MAC_TSCH +MODULES += os/services/orchestra +else ifeq ($(CONFIG),CONFIG_TSCH_OPTIMS) +MAKE_MAC = MAKE_MAC_TSCH +MODULES += os/services/orchestra +CFLAGS += -DCONFIG_OPTIMS=1 +else ifeq ($(CONFIG),CONFIG_TSCH_OPTIMS2) +MAKE_MAC = MAKE_MAC_TSCH +MODULES += os/services/orchestra +CFLAGS += -DCONFIG_OPTIMS=2 +endif + +CONTIKI = ../../.. +include $(CONTIKI)/Makefile.include diff --git a/examples/benchmarks/rpl-req-resp/node.c b/examples/benchmarks/rpl-req-resp/node.c new file mode 100644 index 000000000..4b92415f9 --- /dev/null +++ b/examples/benchmarks/rpl-req-resp/node.c @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2018, RISE SICS. + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the Contiki operating system. + * + */ + +/** + * \file + * Benchmark: the root sends requests to all nodes in a randomized + * order, and receives resopnses back. + * \author + * Simon Duquennoy + */ + +#include "contiki.h" +#include "contiki-net.h" +#include "services/deployment/deployment.h" + +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "App" +#define LOG_LEVEL LOG_LEVEL_INFO + +#define UDP_PORT 8214 +#define SEND_INTERVAL (CLOCK_SECOND) + +static struct simple_udp_connection udp_conn; + +/*---------------------------------------------------------------------------*/ +PROCESS(app_process, "App process"); +AUTOSTART_PROCESSES(&app_process); + +/*---------------------------------------------------------------------------*/ +static void +udp_rx_callback(struct simple_udp_connection *c, + const uip_ipaddr_t *sender_addr, + uint16_t sender_port, + const uip_ipaddr_t *receiver_addr, + uint16_t receiver_port, + const uint8_t *data, + uint16_t datalen) +{ + uint32_t count; + int is_response; + /* Copy and parse payload */ + memcpy(&count, data, sizeof(uint32_t)); + /* Most significant bit: request (0) / response (1) */ + is_response = count & 0x80000000; + count &= 0x7fffffff; + + if(is_response) { + LOG_INFO("Received response %"PRIu32" from ", count); + LOG_INFO_6ADDR(sender_addr); + LOG_INFO_("\n"); + } else { + LOG_INFO("Received request %"PRIu32" from ", count); + LOG_INFO_6ADDR(sender_addr); + LOG_INFO_("\n"); + LOG_INFO("Sending response %"PRIu32" to ", count); + LOG_INFO_6ADDR(sender_addr); + LOG_INFO_("\n"); + /* Set most significant bit to signal a response */ + count |= 0x80000000; + simple_udp_sendto(&udp_conn, &count, sizeof(count), sender_addr); + } +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(app_process, ev, data) +{ + static struct etimer timer; + static uip_ipaddr_t dest_ipaddr; + + PROCESS_BEGIN(); + + /* Initialize UDP connection */ + simple_udp_register(&udp_conn, UDP_PORT, NULL, + UDP_PORT, udp_rx_callback); + + if(node_id == ROOT_ID) { + /* Wait 5 seconds before starting */ + etimer_set(&timer, CLOCK_SECOND * 5); + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer)); + + /* We are the root, start a DAG */ + NETSTACK_ROUTING.root_start(); + /* Set dest_ipaddr with DODAG ID, so we get the prefix */ + NETSTACK_ROUTING.get_root_ipaddr(&dest_ipaddr); + /* Setup a periodic timer that expires after 10 seconds. */ + etimer_set(&timer, CLOCK_SECOND * 10); + /* Wait until all nodes have joined */ + do { + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer)); + etimer_reset(&timer); + + if(deployment_node_count() > NETSTACK_MAX_ROUTE_ENTRIES) { + LOG_WARN("Not enough routing entries for deployment: %u/%u\n", + deployment_node_count(), NETSTACK_MAX_ROUTE_ENTRIES); + } + LOG_INFO("Node count: %u/%u\n", uip_sr_num_nodes(), deployment_node_count()); + + } while(uip_sr_num_nodes() < deployment_node_count()); + + /* Now start requesting nodes at random */ + etimer_set(&timer, SEND_INTERVAL); + while(uip_sr_num_nodes() == deployment_node_count()) { + static uint32_t count = 0; + uint16_t dest_id; + + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer)); + etimer_reset(&timer); + + /* Select a destination at random. Iterate until we do not select ourselve */ + do { + dest_id = deployment_id_from_index(random_rand() % deployment_node_count()); + } while(dest_id == ROOT_ID); + /* Prefix was already set, set IID now */ + deployment_iid_from_id(&dest_ipaddr, dest_id); + + /* Request: most significant bit not unset */ + LOG_INFO("Sending request %"PRIu32" to ", count); + LOG_INFO_6ADDR(&dest_ipaddr); + LOG_INFO_("\n"); + simple_udp_sendto(&udp_conn, &count, sizeof(count), &dest_ipaddr); + count++; + } + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/examples/benchmarks/rpl-req-resp/parse.py b/examples/benchmarks/rpl-req-resp/parse.py new file mode 100644 index 000000000..a15b9c49b --- /dev/null +++ b/examples/benchmarks/rpl-req-resp/parse.py @@ -0,0 +1,269 @@ +#!/usr/bin/env python + +import re +import os +import fileinput +import math +import yaml +import pandas as pd +from pandas import * +from pylab import * +from datetime import * +from collections import OrderedDict +from IPython import embed +import matplotlib as mpl + +pd.set_option('display.max_rows', 48) +pd.set_option('display.width', None) +pd.set_option('display.max_columns', None) + +networkFormationTime = None +parents = {} + +def calculateHops(node): + hops = 0 + while(parents[node] != None): + node = parents[node] + hops += 1 + # safeguard, in case of scrambled logs + if hops > 50: + return hops + return hops + +def calculateChildren(node): + children = 0 + for n in parents.keys(): + if(parents[n] == node): + children += 1 + return children + +def updateTopology(child, parent): + global parents + if not child in parents: + parents[child] = {} + if not parent in parents: + parents[parent] = None + parents[child] = parent + +def parseRPL(log): + res = re.compile('.*? rank (\d*).*?dioint (\d*).*?nbr count (\d*)').match(log) + if res: + rank = int(res.group(1)) + trickle = (2**int(res.group(2)))/(60*1000.) + nbrCount = int(res.group(3)) + return {'event': 'rank', 'rank': rank, 'trickle': trickle } + res = re.compile('parent switch: .*? -> .*?-(\d*)$').match(log) + if res: + parent = int(res.group(1)) + return {'event': 'switch', 'pswitch': parent } + res = re.compile('sending a (.+?) ').match(log) + if res: + message = res.group(1) + return {'event': 'sending', 'message': message } + res = re.compile('links: 6G-(\d+)\s*to 6G-(\d+)').match(log) + if res: + child = int(res.group(1)) + parent = int(res.group(2)) + updateTopology(child, parent) + return None + res = re.compile('links: end of list').match(log) + if res: + # This was the last line, commit full topology + return {'event': 'topology' } + return None + +def parseEnergest(log): + res = re.compile('Radio Tx\s*:\s*(\d*)/\s*(\d+)').match(log) + if res: + tx = float(res.group(1)) + total = float(res.group(2)) + return {'channel-utilization': 100.*tx/total } + res = re.compile('Radio total\s*:\s*(\d*)/\s*(\d+)').match(log) + if res: + radio = float(res.group(1)) + total = float(res.group(2)) + return {'duty-cycle': 100.*radio/total } + return None + +def parseApp(log): + res = re.compile('Sending (.+?) (\d+) to 6G-(\d+)').match(log) + if res: + type = res.group(1) + id = int(res.group(2)) + dest = int(res.group(3)) + return {'event': 'send', 'type': type, 'id': id, 'node': dest } + res = re.compile('Received (.+?) (\d+) from 6G-(\d+)').match(log) + if res: + type = res.group(1) + id = int(res.group(2)) + src = int(res.group(3)) + return {'event': 'recv', 'type': type, 'id': id, 'src': src } + return None + +def parseLine(line): + res = re.compile('\s*([.\d]+)\\tID:(\d+)\\t\[(.*?):(.*?)\](.*)$').match(line) + if res: + time = float(res.group(1)) + nodeid = int(res.group(2)) + level = res.group(3).strip() + module = res.group(4).strip() + log = res.group(5).strip() + return time, nodeid, level, module, log + return None, None, None, None, None + +def doParse(file): + global networkFormationTime + + time = None + lastPrintedTime = 0 + + arrays = { + "packets": [], + "energest": [], + "ranks": [], + "trickle": [], + "switches": [], + "topology": [], + } + +# print("\nProcessing %s" %(file)) + # Filter out non-printable chars from log file + os.system("cat %s | tr -dc '[:print:]\n\t' | sponge %s" %(file, file)) + for line in open(file, 'r').readlines(): + # match time, id, module, log; The common format for all log lines + time, nodeid, level, module, log = parseLine(line) + + if time == None: + # malformed line + continue + + if time - lastPrintedTime >= 60: +# print("%u, "%(time / 60),end='', flush=True) + lastPrintedTime = time + + entry = { + "timestamp": timedelta(seconds=time), + "node": nodeid, + } + + try: + if module == "App": + ret = parseApp(log) + if(ret != None): + entry.update(ret) + if(ret['event'] == 'send' and ret['type'] == 'request'): + # populate series of sent requests + entry['pdr'] = 0. + arrays["packets"].append(entry) + if networkFormationTime == None: + networkFormationTime = time + elif(ret['event'] == 'recv' and ret['type'] == 'response'): + # update sent request series with latency and PDR + txElement = [x for x in arrays["packets"] if x['event']=='send' and x['id']==ret['id']][0] + txElement['latency'] = time - txElement['timestamp'].seconds + txElement['pdr'] = 100. + + if module == "Energest": + ret = parseEnergest(log) + if(ret != None): + entry.update(ret) + arrays["energest"].append(entry) + + if module == "RPL": + ret = parseRPL(log) + if(ret != None): + entry.update(ret) + if(ret['event'] == 'rank'): + arrays["ranks"].append(entry) + arrays["trickle"].append(entry) + elif(ret['event'] == 'switch'): + arrays["switches"].append(entry) + elif(ret['event'] == 'sending'): + if not ret['message'] in arrays: + arrays[ret['message']] = [] + arrays[ret['message']].append(entry) + elif(ret['event'] == 'topology'): + for n in parents.keys(): + nodeEntry = entry.copy() + nodeEntry["node"] = n + nodeEntry["hops"] = calculateHops(n) + nodeEntry["children"] = calculateChildren(n) + arrays["topology"].append(nodeEntry) + except: # typical exception: failed str conversion to int, due to lossy logs + print("Exception: %s" %(str(sys.exc_info()[0]))) + continue + +# print("") + + # Remove last few packets -- might be in-flight when test stopped + arrays["packets"] = arrays["packets"][0:-10] + + dfs = {} + for key in arrays.keys(): + if(len(arrays[key]) > 0): + df = DataFrame(arrays[key]) + dfs[key] = df.set_index("timestamp") + + return dfs + +def outputStats(dfs, key, metric, agg, name, metricLabel = None): + if not key in dfs: + return + + df = dfs[key] + perNode = getattr(df.groupby("node")[metric], agg)() + perTime = getattr(df.groupby([pd.Grouper(freq="2Min")])[metric], agg)() + + print(" %s:" %(metricLabel if metricLabel != None else metric)) + print(" name: %s" %(name)) + print(" per-node:") + print(" x: [%s]" %(", ".join(["%u"%x for x in sort(df.node.unique())]))) + print(" y: [%s]" %(', '.join(["%.4f"%(x) for x in perNode]))) + print(" per-time:") + print(" x: [%s]" %(", ".join(["%u"%x for x in range(0, 2*len(df.groupby([pd.Grouper(freq="2Min")]).mean().index), 2)]))) + print(" y: [%s]" %(', '.join(["%.4f"%(x) for x in perTime]).replace("nan", "null"))) + +def main(): + if len(sys.argv) < 1: + return + else: + file = sys.argv[1].rstrip('/') + + # Parse the original log + dfs = doParse(file) + + if len(dfs) == 0: + return + + print("global-stats:") + print(" pdr: %.4f" %(dfs["packets"]["pdr"].mean())) + print(" loss-rate: %.e" %(1-(dfs["packets"]["pdr"].mean()/100))) + print(" packets-sent: %u" %(dfs["packets"]["pdr"].count())) + print(" packets-received: %u" %(dfs["packets"]["pdr"].sum()/100)) + print(" latency: %.4f" %(dfs["packets"]["latency"].mean())) + print(" duty-cycle: %.2f" %(dfs["energest"]["duty-cycle"].mean())) + print(" channel-utilization: %.2f" %(dfs["energest"]["channel-utilization"].mean())) + print(" network-formation-time: %.2f" %(networkFormationTime)) + print("stats:") + + # Output relevant metrics + outputStats(dfs, "packets", "pdr", "mean", "Round-trip PDR (%)") + outputStats(dfs, "packets", "latency", "mean", "Round-trip latency (s)") + + outputStats(dfs, "energest", "duty-cycle", "mean", "Radio duty cycle (%)") + outputStats(dfs, "energest", "channel-utilization", "mean", "Channel utilization (%)") + + outputStats(dfs, "ranks", "rank", "mean", "RPL rank (ETX-128)") + outputStats(dfs, "switches", "pswitch", "count", "RPL parent switches (#)") + outputStats(dfs, "trickle", "trickle", "mean", "RPL Trickle period (min)") + + outputStats(dfs, "DIS", "message", "count", "RPL DIS sent (#)", "rpl-dis") + outputStats(dfs, "unicast-DIO", "message", "count", "RPL uDIO sent (#)", "rpl-udio") + outputStats(dfs, "multicast-DIO", "message", "count", "RPL mDIO sent (#)", "rpl-mdio") + outputStats(dfs, "DAO", "message", "count", "RPL DAO sent (#)", "rpl-dao") + outputStats(dfs, "DAO-ACK", "message", "count", "RPL DAO-ACK sent (#)", "rpl-daoack") + + outputStats(dfs, "topology", "hops", "mean", "RPL hop count (#)") + outputStats(dfs, "topology", "children", "mean", "RPL children count (#)") + +main() diff --git a/examples/benchmarks/rpl-req-resp/project-conf.h b/examples/benchmarks/rpl-req-resp/project-conf.h new file mode 100644 index 000000000..1140bb9e5 --- /dev/null +++ b/examples/benchmarks/rpl-req-resp/project-conf.h @@ -0,0 +1,48 @@ +#ifndef PROJECT_CONF_H_ +#define PROJECT_CONF_H_ + +/* Testbed configuration */ +#define ROOT_ID 1 +#if CONTIKI_TARGET_COOJA +#define DEPLOYMENT_MAPPING deployment_cooja8 +#else /* CONTIKI_TARGET_COOJA */ +#define DEPLOYMENT_MAPPING deployment_sics_firefly +#endif /* CONTIKI_TARGET_COOJA */ +#define IEEE802154_CONF_PANID 0x8921 + +/* Logging */ +#define LOG_CONF_LEVEL_RPL LOG_LEVEL_INFO +#define LOG_CONF_LEVEL_MAC LOG_LEVEL_WARN +#define LOG_CONF_WITH_COMPACT_ADDR 1 + +/* Provisioning */ +#define NETSTACK_MAX_ROUTE_ENTRIES 25 +#define NBR_TABLE_CONF_MAX_NEIGHBORS 8 + +#if CONFIG_OPTIMS >= 1 + +/* RPL configuration */ +#define RPL_MRHOF_CONF_SQUARED_ETX 1 +#define RPL_CONF_MAX_RANKINC 0 + +/* TSCH configuration */ +#define TSCH_CONF_RX_WAIT 1000 +#define ORCHESTRA_CONF_UNICAST_PERIOD 7 + +#if CONFIG_OPTIMS == 2 + +/* Five nines reliability paper used the config below */ +#define RPL_CONF_DIO_INTERVAL_MIN 14 /* 2^14 ms = 16.384 s */ +#define RPL_CONF_DIO_INTERVAL_DOUBLINGS 6 /* 2^(14+6) ms = 1048.576 s */ +#define RPL_CONF_PROBING_INTERVAL (60 * CLOCK_SECOND) + +/* Five nines reliability paper used the config below */ +#define TSCH_CONF_KEEPALIVE_TIMEOUT (20 * CLOCK_SECOND) +#define TSCH_CONF_MAX_KEEPALIVE_TIMEOUT (60 * CLOCK_SECOND) +//#define TSCH_CONF_EB_PERIOD (16 * CLOCK_SECOND) +//#define TSCH_CONF_MAX_EB_PERIOD (50 * CLOCK_SECOND) + +#endif +#endif + +#endif /* PROJECT_CONF_H_ */ diff --git a/examples/benchmarks/rpl-req-resp/sim.csc b/examples/benchmarks/rpl-req-resp/sim.csc new file mode 100644 index 000000000..d973a1d8d --- /dev/null +++ b/examples/benchmarks/rpl-req-resp/sim.csc @@ -0,0 +1,275 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/powertracker + + My simulation + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype90 + Cooja Mote Type #1 + [CONTIKI_DIR]/examples/benchmarks/rpl-req-resp/node.c + make node.cooja TARGET=cooja + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + + org.contikios.cooja.interfaces.Position + 12.478629242391953 + 42.201041276604826 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 1 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype90 + + + + org.contikios.cooja.interfaces.Position + 25.625935608473608 + 82.53975431376661 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 2 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype90 + + + + org.contikios.cooja.interfaces.Position + 51.615094138350024 + 59.70602651475372 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 3 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype90 + + + + org.contikios.cooja.interfaces.Position + 41.04314122620578 + 121.24693889311891 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 4 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype90 + + + + org.contikios.cooja.interfaces.Position + 64.9463558635099 + 104.25039302469283 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 5 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype90 + + + + org.contikios.cooja.interfaces.Position + 93.59263858654369 + 75.40399148300003 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 6 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype90 + + + + org.contikios.cooja.interfaces.Position + 75.6297158696234 + 139.97002035548905 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 7 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype90 + + + + org.contikios.cooja.interfaces.Position + 104.34293924684245 + 116.07658566915099 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 8 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype90 + + + + org.contikios.cooja.plugins.SimControl + 280 + 2 + 160 + 400 + 0 + + + org.contikios.cooja.plugins.Visualizer + + true + org.contikios.cooja.plugins.skins.IDVisualizerSkin + org.contikios.cooja.plugins.skins.GridVisualizerSkin + org.contikios.cooja.plugins.skins.TrafficVisualizerSkin + org.contikios.cooja.plugins.skins.UDGMVisualizerSkin + 2.4250860844175466 0.0 0.0 2.4250860844175466 35.26895372864869 -46.9106236441515 + + 400 + 3 + 400 + 1 + 1 + + + org.contikios.cooja.plugins.LogListener + + App + + + + 827 + 0 + 665 + 681 + -1 + + + org.contikios.cooja.plugins.TimeLine + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + + + + 500.0 + + 1539 + 1 + 263 + 0 + 709 + + diff --git a/examples/benchmarks/testbeds/cooja8.c b/examples/benchmarks/testbeds/cooja8.c new file mode 100644 index 000000000..f6ccaec97 --- /dev/null +++ b/examples/benchmarks/testbeds/cooja8.c @@ -0,0 +1,14 @@ +#include "services/deployment/deployment.h" + +/** \brief A mapping table for a 8-node Cooja mote simulation. */ +const struct id_mac deployment_cooja8[] = { + { 1, {{0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01}}}, + { 2, {{0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02}}}, + { 3, {{0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03}}}, + { 4, {{0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x04}}}, + { 5, {{0x00,0x05,0x00,0x05,0x00,0x05,0x00,0x05}}}, + { 6, {{0x00,0x06,0x00,0x06,0x00,0x06,0x00,0x06}}}, + { 7, {{0x00,0x07,0x00,0x07,0x00,0x07,0x00,0x07}}}, + { 8, {{0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08}}}, + { 0, {{0}}} +}; diff --git a/examples/benchmarks/testbeds/sics-firefly.c b/examples/benchmarks/testbeds/sics-firefly.c new file mode 100644 index 000000000..0478dc65d --- /dev/null +++ b/examples/benchmarks/testbeds/sics-firefly.c @@ -0,0 +1,31 @@ +#include "services/deployment/deployment.h" + +/** \brief The 25-node RISE SICS node testbed. Firefly-reva nodes. */ +const struct id_mac deployment_sics_firefly[] = { + { 1, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb6,0x14}}}, + { 2, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb1,0xe7}}}, + { 3, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb4,0x35}}}, + { 4, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb1,0xcf}}}, + { 5, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb2,0x06}}}, + { 6, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb1,0x5f}}}, + { 8, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb1,0x91}}}, + { 7, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb1,0x29}}}, + { 9, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb1,0xc6}}}, + { 10, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb1,0x63}}}, + { 12, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb2,0x03}}}, + { 11, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb4,0x3b}}}, + { 13, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb6,0x0d}}}, + { 14, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb5,0x66}}}, + { 15, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb5,0x8a}}}, + { 16, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb4,0x49}}}, + { 17, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb1,0x35}}}, + { 18, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb2,0x15}}}, + { 19, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb5,0xfc}}}, + { 20, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb1,0xa8}}}, + { 21, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb1,0x6a}}}, + { 22, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb4,0x5b}}}, + { 23, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb1,0xe6}}}, + { 24, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb6,0x00}}}, + { 25, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb1,0xb8}}}, + { 0, {{0}}} +}; diff --git a/examples/coap/README.md b/examples/coap/README.md index 36ec0b022..7d0ac47d2 100644 --- a/examples/coap/README.md +++ b/examples/coap/README.md @@ -1,4 +1,4 @@ -# CoAP examples: client, server, and plugtest serverA Quick Introduction to the Erbium (Er) CoAP Engine +# CoAP examples: client, server, and plugtest server * coap-example-server: A CoAP server example showing how to use the CoAP layer to develop server-side applications. * coap-example-client: A CoAP client that polls the /actuators/toggle resource every 10 seconds and cycles through 4 resources on button press (target address is hard-coded). diff --git a/examples/coap/coap-example-client/coap-example-client.c b/examples/coap/coap-example-client/coap-example-client.c index 1606d884a..645283093 100644 --- a/examples/coap/coap-example-client/coap-example-client.c +++ b/examples/coap/coap-example-client/coap-example-client.c @@ -92,9 +92,6 @@ PROCESS_THREAD(er_example_client, ev, data) coap_endpoint_parse(SERVER_EP, strlen(SERVER_EP), &server_ep); - /* receives all CoAP messages */ - coap_engine_init(); - etimer_set(&et, TOGGLE_INTERVAL * CLOCK_SECOND); #if PLATFORM_HAS_BUTTON diff --git a/examples/coap/coap-example-client/coap-example-observe-client.c b/examples/coap/coap-example-client/coap-example-observe-client.c index 914a21bdd..3b6eb9871 100644 --- a/examples/coap/coap-example-client/coap-example-observe-client.c +++ b/examples/coap/coap-example-client/coap-example-observe-client.c @@ -141,8 +141,6 @@ PROCESS_THREAD(er_example_observe_client, ev, data) /* store server address in server_ipaddr */ SERVER_NODE(server_ipaddr); - /* receives all CoAP messages */ - coap_init_engine(); /* init timer and button (if available) */ etimer_set(&et, TOGGLE_INTERVAL * CLOCK_SECOND); #if PLATFORM_HAS_BUTTON diff --git a/examples/coap/coap-example-server/coap-example-server.c b/examples/coap/coap-example-server/coap-example-server.c index 375fc4bd9..f32b743f7 100644 --- a/examples/coap/coap-example-server/coap-example-server.c +++ b/examples/coap/coap-example-server/coap-example-server.c @@ -92,9 +92,6 @@ PROCESS_THREAD(er_example_server, ev, data) LOG_INFO("Starting Erbium Example Server\n"); - /* Initialize the REST engine. */ - coap_engine_init(); - /* * Bind the resources to their Uri-Path. * WARNING: Activating twice only means alternate path, not two instances! diff --git a/examples/coap/coap-plugtest-server/coap-plugtest-server.c b/examples/coap/coap-plugtest-server/coap-plugtest-server.c index 4b6c6d557..8783ae6dd 100644 --- a/examples/coap/coap-plugtest-server/coap-plugtest-server.c +++ b/examples/coap/coap-plugtest-server/coap-plugtest-server.c @@ -86,9 +86,6 @@ PROCESS_THREAD(plugtest_server, ev, data) LOG_INFO("ETSI IoT CoAP Plugtests Server\n"); - /* Initialize the REST engine. */ - coap_engine_init(); - /* Activate the application-specific resources. */ coap_activate_resource(&res_plugtest_test, "test"); coap_activate_resource(&res_plugtest_validate, "validate"); diff --git a/examples/dev/button-hal/Makefile b/examples/dev/button-hal/Makefile index 0c209918c..b2a73fe3c 100644 --- a/examples/dev/button-hal/Makefile +++ b/examples/dev/button-hal/Makefile @@ -3,6 +3,6 @@ CONTIKI = ../../.. all: $(CONTIKI_PROJECT) -PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul native +PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul native simplelink include $(CONTIKI)/Makefile.include diff --git a/examples/dev/gpio-hal/Makefile b/examples/dev/gpio-hal/Makefile index 016f53377..70f38a11a 100644 --- a/examples/dev/gpio-hal/Makefile +++ b/examples/dev/gpio-hal/Makefile @@ -1,7 +1,7 @@ CONTIKI_PROJECT = gpio-hal-example CONTIKI = ../../.. -PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul native +PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul native simplelink include $(CONTIKI)/Makefile.identify-target diff --git a/examples/dev/gpio-hal/gpio-hal-example.c b/examples/dev/gpio-hal/gpio-hal-example.c index 380c06388..75137e26a 100644 --- a/examples/dev/gpio-hal/gpio-hal-example.c +++ b/examples/dev/gpio-hal/gpio-hal-example.c @@ -46,9 +46,9 @@ static uint8_t counter; /*---------------------------------------------------------------------------*/ /* Print gpio_hal_pin_mask_t using the correct format */ #if GPIO_HAL_PIN_COUNT > 32 -#define PIN_MASK_FMT PRIx64 +#define PIN_MASK_FMT "0x%016" PRIx64 #else -#define PIN_MASK_FMT PRIx32 +#define PIN_MASK_FMT "0x%08" PRIx32 #endif /*---------------------------------------------------------------------------*/ PROCESS(gpio_hal_example, "GPIO HAL Example"); @@ -127,7 +127,7 @@ PROCESS_THREAD(gpio_hal_example, ev, data) } /* Test read */ - printf("%u: Pins are 1-%u, 2=%u, 3=%u, mask=0x%08" PIN_MASK_FMT "\n", + printf("%u: Pins are 1-%u, 2=%u, 3=%u, mask=" PIN_MASK_FMT "\n", counter & 7, gpio_hal_arch_read_pin(out_pin1), gpio_hal_arch_read_pin(out_pin2), diff --git a/examples/dev/gpio-hal/simplelink/pins.c b/examples/dev/gpio-hal/simplelink/pins.c new file mode 100644 index 000000000..16a7afa1f --- /dev/null +++ b/examples/dev/gpio-hal/simplelink/pins.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2015-2018, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * 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. + * + * * Neither the name of Texas Instruments Incorporated 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 OWNER 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 "contiki.h" +#include "dev/gpio-hal.h" +/*---------------------------------------------------------------------------*/ +#include +/*---------------------------------------------------------------------------*/ +gpio_hal_pin_t out_pin1 = Board_PIN_LED0; +gpio_hal_pin_t out_pin2 = Board_PIN_LED1; +gpio_hal_pin_t out_pin3 = Board_PIN_LED2; +/*---------------------------------------------------------------------------*/ +gpio_hal_pin_t btn_pin = Board_PIN_BTN1; +/*---------------------------------------------------------------------------*/ diff --git a/examples/libs/deployment/Makefile b/examples/libs/deployment/Makefile new file mode 100644 index 000000000..5ad17e22d --- /dev/null +++ b/examples/libs/deployment/Makefile @@ -0,0 +1,7 @@ +CONTIKI_PROJECT = node +all: $(CONTIKI_PROJECT) + +MODULES += os/services/deployment + +CONTIKI = ../../.. +include $(CONTIKI)/Makefile.include diff --git a/examples/libs/deployment/README.md b/examples/libs/deployment/README.md new file mode 100644 index 000000000..8484c3aee --- /dev/null +++ b/examples/libs/deployment/README.md @@ -0,0 +1,3 @@ +A simple example of how to use the deployment module. Intended for Cooja, +with a Cooja motes, as in the provided simulation file `sim.csc`. For use +in a real deployment, set DEPLOYMENT_MAPPING to your own ID-MAC mapping table. diff --git a/examples/libs/deployment/node.c b/examples/libs/deployment/node.c new file mode 100644 index 000000000..2cbe1f276 --- /dev/null +++ b/examples/libs/deployment/node.c @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2018, RISE SICS. + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the Contiki operating system. + * + */ + +/** + * \file + * Benchmark: the root sends requests to all nodes in a randomized + * order, and receives resopnses back. + * \author + * Simon Duquennoy + */ + +#include "contiki.h" +#include "contiki-net.h" +#include "services/deployment/deployment.h" + +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "App" +#define LOG_LEVEL LOG_LEVEL_INFO + +#include "services/deployment/deployment.h" + +/** \brief A mapping table for a 8-node Cooja mote simulation. + * Define your own for any given deployment environment */ +const struct id_mac deployment_cooja8[] = { + { 1, {{0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01}}}, + { 2, {{0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02}}}, + { 3, {{0x00,0x03,0x00,0x03,0x00,0x03,0x00,0x03}}}, + { 4, {{0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x04}}}, + { 5, {{0x00,0x05,0x00,0x05,0x00,0x05,0x00,0x05}}}, + { 6, {{0x00,0x06,0x00,0x06,0x00,0x06,0x00,0x06}}}, + { 7, {{0x00,0x07,0x00,0x07,0x00,0x07,0x00,0x07}}}, + { 8, {{0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08}}}, + { 0, {{0}}} +}; + +/** \brief An example mapping for Openmotes in Flocklab. + * To use, set DEPLOYMENT_MAPPING to deployment_flocklab_openmotes */ +const struct id_mac deployment_flocklab_openmotes[] = { + { 3, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0x9b,0x29}}}, + { 6, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0x9b,0x34}}}, + { 8, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0x9b,0x1f}}}, + { 15, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0x9b,0x85}}}, + { 16, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0x9b,0x00}}}, + { 18, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0x9b,0x37}}}, + { 22, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0x9b,0x08}}}, + { 23, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0x9b,0x5f}}}, + { 31, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0x9b,0xb1}}}, + { 0, {{0}}} +}; + +/*---------------------------------------------------------------------------*/ +PROCESS(app_process, "App process"); +AUTOSTART_PROCESSES(&app_process); + +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(app_process, ev, data) +{ + static struct etimer timer; + static uip_ipaddr_t ipaddr; + static linkaddr_t lladdr; + static int i; + + PROCESS_BEGIN(); + + if(node_id == ROOT_ID) { + /* We are the root, start a DAG */ + NETSTACK_ROUTING.root_start(); + /* Setup a periodic timer that expires after 10 seconds. */ + etimer_set(&timer, CLOCK_SECOND * 10); + /* Wait until all nodes have joined */ + while(1) { + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer)); + etimer_reset(&timer); + /* Log expected IPv6 addresses of all nodes */ + LOG_INFO("Node list:\n"); + for(i = 0; iMAC) */ +#define DEPLOYMENT_MAPPING deployment_cooja8 +/* Compact address logging (both link-layer and IPv6). + * Shows an abbreviated form that contains the node-id */ +#define LOG_CONF_WITH_COMPACT_ADDR 1 + +#endif /* PROJECT_CONF_H_ */ diff --git a/examples/libs/deployment/sim.csc b/examples/libs/deployment/sim.csc new file mode 100644 index 000000000..9daa11426 --- /dev/null +++ b/examples/libs/deployment/sim.csc @@ -0,0 +1,275 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/powertracker + + My simulation + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype90 + Cooja Mote Type #1 + [CONTIKI_DIR]/examples/libs/deployment/node.c + make node.cooja TARGET=cooja + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + + org.contikios.cooja.interfaces.Position + 12.478629242391953 + 42.201041276604826 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 1 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype90 + + + + org.contikios.cooja.interfaces.Position + 25.625935608473608 + 82.53975431376661 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 2 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype90 + + + + org.contikios.cooja.interfaces.Position + 51.615094138350024 + 59.70602651475372 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 3 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype90 + + + + org.contikios.cooja.interfaces.Position + 41.04314122620578 + 121.24693889311891 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 4 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype90 + + + + org.contikios.cooja.interfaces.Position + 64.9463558635099 + 104.25039302469283 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 5 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype90 + + + + org.contikios.cooja.interfaces.Position + 93.59263858654369 + 75.40399148300003 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 6 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype90 + + + + org.contikios.cooja.interfaces.Position + 75.6297158696234 + 139.97002035548905 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 7 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype90 + + + + org.contikios.cooja.interfaces.Position + 104.34293924684245 + 116.07658566915099 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 8 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype90 + + + + org.contikios.cooja.plugins.SimControl + 280 + 2 + 160 + 400 + 0 + + + org.contikios.cooja.plugins.Visualizer + + true + org.contikios.cooja.plugins.skins.IDVisualizerSkin + org.contikios.cooja.plugins.skins.GridVisualizerSkin + org.contikios.cooja.plugins.skins.TrafficVisualizerSkin + org.contikios.cooja.plugins.skins.UDGMVisualizerSkin + 2.4250860844175466 0.0 0.0 2.4250860844175466 35.26895372864869 -46.9106236441515 + + 400 + 3 + 400 + 1 + 1 + + + org.contikios.cooja.plugins.LogListener + + App + + + + 827 + 0 + 665 + 681 + -1 + + + org.contikios.cooja.plugins.TimeLine + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + + + + 500.0 + + 1539 + 1 + 263 + 0 + 709 + + diff --git a/examples/libs/ipv6-uipbuf/Makefile b/examples/libs/ipv6-uipbuf/Makefile new file mode 100644 index 000000000..b7500284e --- /dev/null +++ b/examples/libs/ipv6-uipbuf/Makefile @@ -0,0 +1,5 @@ +CONTIKI_PROJECT = udp-client udp-server +all: $(CONTIKI_PROJECT) + +CONTIKI=../../.. +include $(CONTIKI)/Makefile.include diff --git a/examples/libs/ipv6-uipbuf/README.md b/examples/libs/ipv6-uipbuf/README.md new file mode 100644 index 000000000..6f028202e --- /dev/null +++ b/examples/libs/ipv6-uipbuf/README.md @@ -0,0 +1,5 @@ +This example is meant to showcase the capabilities of uipbuf. It currently +focuses only on UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS, which lets an application +set a custom max number of MAC transmissions. Optionally, this information +can be passed on over multiple hops, so that the attribute applies along +the full path. This requires setting UIP_CONF_TAG_TC_WITH_VARIABLE_RETRANSMISSIONS. diff --git a/examples/libs/ipv6-uipbuf/ipv6-uipbuf-cooja.csc b/examples/libs/ipv6-uipbuf/ipv6-uipbuf-cooja.csc new file mode 100644 index 000000000..71adabb74 --- /dev/null +++ b/examples/libs/ipv6-uipbuf/ipv6-uipbuf-cooja.csc @@ -0,0 +1,180 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/powertracker + + IPv6 uipbuf Example + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype829 + Cooja Mote Type #1 + [CONTIKI_DIR]/examples/libs/ipv6-uipbuf/udp-server.c + make udp-server.cooja TARGET=cooja + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype405 + Cooja Mote Type #2 + [CONTIKI_DIR]/examples/libs/ipv6-uipbuf/udp-client.c + make udp-client.cooja TARGET=cooja + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + + org.contikios.cooja.interfaces.Position + 43.291897546941804 + 7.17470867058031 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 1 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype829 + + + + org.contikios.cooja.interfaces.Position + 41.0074953544532 + 42.15996473110367 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 2 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype405 + + + + org.contikios.cooja.plugins.SimControl + 229 + 3 + 157 + 11 + 6 + + + org.contikios.cooja.plugins.Visualizer + + true + org.contikios.cooja.plugins.skins.IDVisualizerSkin + org.contikios.cooja.plugins.skins.UDGMVisualizerSkin + 1.1719333465234514 0.0 0.0 1.1719333465234514 -4.934308660658031 20.209777273580123 + + 234 + 1 + 257 + 10 + 170 + + + org.contikios.cooja.plugins.LogListener + + App + + + + 1074 + 0 + 713 + 844 + 3 + + + org.contikios.cooja.plugins.TimeLine + + 0 + 1 + + + + 140.4158108891898 + + 1920 + 2 + 384 + 1 + 716 + + + org.contikios.cooja.plugins.RadioLogger + + 407 + + false + false + + 595 + 4 + 706 + 245 + 4 + + diff --git a/examples/libs/ipv6-uipbuf/ipv6-uipbuf-sky.csc b/examples/libs/ipv6-uipbuf/ipv6-uipbuf-sky.csc new file mode 100644 index 000000000..30fc54e14 --- /dev/null +++ b/examples/libs/ipv6-uipbuf/ipv6-uipbuf-sky.csc @@ -0,0 +1,170 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/powertracker + + IPv6 uipbuf Example + generated + 5000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 50.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.mspmote.SkyMoteType + sky1 + Sky Mote Type #sky1 + [CONTIKI_DIR]/examples/libs/ipv6-uipbuf/udp-server.c + make udp-server.sky TARGET=sky + [CONTIKI_DIR]/examples/libs/ipv6-uipbuf/udp-server.sky + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.interfaces.IPAddress + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + org.contikios.cooja.mspmote.interfaces.MspClock + org.contikios.cooja.mspmote.interfaces.MspMoteID + org.contikios.cooja.mspmote.interfaces.SkyButton + org.contikios.cooja.mspmote.interfaces.SkyFlash + org.contikios.cooja.mspmote.interfaces.SkyCoffeeFilesystem + org.contikios.cooja.mspmote.interfaces.Msp802154Radio + org.contikios.cooja.mspmote.interfaces.MspSerial + org.contikios.cooja.mspmote.interfaces.SkyLED + org.contikios.cooja.mspmote.interfaces.MspDebugOutput + org.contikios.cooja.mspmote.interfaces.SkyTemperature + + + org.contikios.cooja.mspmote.SkyMoteType + sky2 + Sky Mote Type #sky2 + [CONTIKI_DIR]/examples/libs/ipv6-uipbuf/udp-client.c + make udp-client.sky TARGET=sky + [CONTIKI_DIR]/examples/libs/ipv6-uipbuf/udp-client.sky + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.interfaces.IPAddress + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + org.contikios.cooja.mspmote.interfaces.MspClock + org.contikios.cooja.mspmote.interfaces.MspMoteID + org.contikios.cooja.mspmote.interfaces.SkyButton + org.contikios.cooja.mspmote.interfaces.SkyFlash + org.contikios.cooja.mspmote.interfaces.SkyCoffeeFilesystem + org.contikios.cooja.mspmote.interfaces.Msp802154Radio + org.contikios.cooja.mspmote.interfaces.MspSerial + org.contikios.cooja.mspmote.interfaces.SkyLED + org.contikios.cooja.mspmote.interfaces.MspDebugOutput + org.contikios.cooja.mspmote.interfaces.SkyTemperature + + + + + org.contikios.cooja.interfaces.Position + 30.051578821079996 + -64.69428746901113 + 0.0 + + + org.contikios.cooja.mspmote.interfaces.MspClock + 1.0 + + + org.contikios.cooja.mspmote.interfaces.MspMoteID + 1 + + sky1 + + + + + org.contikios.cooja.interfaces.Position + 21.31366587648077 + -34.91404431659299 + 0.0 + + + org.contikios.cooja.mspmote.interfaces.MspClock + 1.0 + + + org.contikios.cooja.mspmote.interfaces.MspMoteID + 2 + + sky2 + + + + org.contikios.cooja.plugins.SimControl + 249 + 4 + 184 + 3 + 15 + + + org.contikios.cooja.plugins.Visualizer + + org.contikios.cooja.plugins.skins.IDVisualizerSkin + org.contikios.cooja.plugins.skins.UDGMVisualizerSkin + org.contikios.cooja.plugins.skins.AttributeVisualizerSkin + 1.3598488697820064 0.0 0.0 1.3598488697820064 6.142207908179105 118.20877091196155 + + 234 + 1 + 227 + 14 + 210 + + + org.contikios.cooja.plugins.LogListener + + + + + + 1011 + 0 + 556 + 759 + 7 + + + org.contikios.cooja.plugins.TimeLine + + 0 + 1 + + + + 681.712557066089 + + 1804 + 3 + 352 + 0 + 567 + + + org.contikios.cooja.plugins.RadioLogger + + 150 + + false + false + + 500 + 2 + 546 + 259 + 12 + + diff --git a/examples/libs/ipv6-uipbuf/project-conf.h b/examples/libs/ipv6-uipbuf/project-conf.h new file mode 100644 index 000000000..dfbf0d329 --- /dev/null +++ b/examples/libs/ipv6-uipbuf/project-conf.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2018, RISE SICS. + * 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 HOLDER 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 PROJECT_CONF_H_ +#define PROJECT_CONF_H_ + +/* Include max MAC Tx in the IPv6 Traffic Class field */ +#define UIP_CONF_TAG_TC_WITH_VARIABLE_RETRANSMISSIONS 1 + +#endif /* PROJECT_CONF_H_ */ diff --git a/examples/libs/ipv6-uipbuf/udp-client.c b/examples/libs/ipv6-uipbuf/udp-client.c new file mode 100644 index 000000000..bee1cda83 --- /dev/null +++ b/examples/libs/ipv6-uipbuf/udp-client.c @@ -0,0 +1,85 @@ +#include "contiki.h" +#include "net/routing/routing.h" +#include "random.h" +#include "net/netstack.h" +#include "net/ipv6/simple-udp.h" + +#include "sys/log.h" +#define LOG_MODULE "App" +#define LOG_LEVEL LOG_LEVEL_INFO + +#define WITH_SERVER_REPLY 1 +#define UDP_CLIENT_PORT 8765 +#define UDP_SERVER_PORT 5678 + +static struct simple_udp_connection udp_conn; + +#define START_INTERVAL (15 * CLOCK_SECOND) +#define SEND_INTERVAL (60 * CLOCK_SECOND) + +static struct simple_udp_connection udp_conn; + +/*---------------------------------------------------------------------------*/ +PROCESS(udp_client_process, "UDP client"); +AUTOSTART_PROCESSES(&udp_client_process); +/*---------------------------------------------------------------------------*/ +static void +udp_rx_callback(struct simple_udp_connection *c, + const uip_ipaddr_t *sender_addr, + uint16_t sender_port, + const uip_ipaddr_t *receiver_addr, + uint16_t receiver_port, + const uint8_t *data, + uint16_t datalen) +{ + unsigned count = *(unsigned *)data; + /* If tagging of traffic class is enabled tc will print number of + transmission - otherwise it will be 0 */ + LOG_INFO("Received response %u (Max MAC Tx: %d) from ", count, + uipbuf_get_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS)); + LOG_INFO_6ADDR(sender_addr); + LOG_INFO_("\n"); +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(udp_client_process, ev, data) +{ + static struct etimer periodic_timer; + static unsigned count; + uip_ipaddr_t dest_ipaddr; + + PROCESS_BEGIN(); + + /* Initialize UDP connection */ + simple_udp_register(&udp_conn, UDP_CLIENT_PORT, NULL, + UDP_SERVER_PORT, udp_rx_callback); + + etimer_set(&periodic_timer, random_rand() % SEND_INTERVAL); + while(1) { + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer)); + + if(NETSTACK_ROUTING.node_is_reachable() && NETSTACK_ROUTING.get_root_ipaddr(&dest_ipaddr)) { + /* Set the number of transmissions to use for this packet - + this can be used to create more reliable transmissions or + less reliable than the default. Works end-to-end if + UIP_CONF_TAG_TC_WITH_VARIABLE_RETRANSMISSIONS is set to 1. + */ + uipbuf_set_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS, 1 + count % 5); + /* Send to DAG root */ + LOG_INFO("Sending request %u (Max MAC Tx: %d) to ", count, + uipbuf_get_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS)); + LOG_INFO_6ADDR(&dest_ipaddr); + LOG_INFO_("\n"); + simple_udp_sendto(&udp_conn, &count, sizeof(count), &dest_ipaddr); + count++; + } else { + LOG_INFO("Not reachable yet\n"); + } + + /* Add some jitter */ + etimer_set(&periodic_timer, SEND_INTERVAL + - CLOCK_SECOND + (random_rand() % (2 * CLOCK_SECOND))); + } + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/examples/libs/ipv6-uipbuf/udp-server.c b/examples/libs/ipv6-uipbuf/udp-server.c new file mode 100644 index 000000000..288a0cba9 --- /dev/null +++ b/examples/libs/ipv6-uipbuf/udp-server.c @@ -0,0 +1,84 @@ +/* + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the Contiki operating system. + * + */ + +#include "contiki.h" +#include "net/routing/routing.h" +#include "net/netstack.h" +#include "net/ipv6/simple-udp.h" + +#include "sys/log.h" +#define LOG_MODULE "App" +#define LOG_LEVEL LOG_LEVEL_INFO + +#define WITH_SERVER_REPLY 1 +#define UDP_CLIENT_PORT 8765 +#define UDP_SERVER_PORT 5678 + +static struct simple_udp_connection udp_conn; + +PROCESS(udp_server_process, "UDP server"); +AUTOSTART_PROCESSES(&udp_server_process); +/*---------------------------------------------------------------------------*/ +static void +udp_rx_callback(struct simple_udp_connection *c, + const uip_ipaddr_t *sender_addr, + uint16_t sender_port, + const uip_ipaddr_t *receiver_addr, + uint16_t receiver_port, + const uint8_t *data, + uint16_t datalen) +{ + unsigned count = *(unsigned *)data; + LOG_INFO("Received request %u (Max MAC Tx: %d) from ", count, + uipbuf_get_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS)); + LOG_INFO_6ADDR(sender_addr); + LOG_INFO_("\n"); +#if WITH_SERVER_REPLY + LOG_INFO("Sending response %u (Max MAC Tx: %d) to ", count, + uipbuf_get_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS)); + LOG_INFO_6ADDR(sender_addr); + LOG_INFO_("\n"); + simple_udp_sendto(&udp_conn, &count, sizeof(count), sender_addr); +#endif /* WITH_SERVER_REPLY */ +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(udp_server_process, ev, data) +{ + PROCESS_BEGIN(); + + /* Initialize DAG root */ + NETSTACK_ROUTING.root_start(); + + /* Initialize UDP connection */ + simple_udp_register(&udp_conn, UDP_SERVER_PORT, NULL, + UDP_CLIENT_PORT, udp_rx_callback); + + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ diff --git a/examples/libs/shell/Makefile b/examples/libs/shell/Makefile new file mode 100644 index 000000000..7be7dd18e --- /dev/null +++ b/examples/libs/shell/Makefile @@ -0,0 +1,9 @@ +CONTIKI_PROJECT = example +all: $(CONTIKI_PROJECT) + +MODULES += os/services/shell +CONTIKI = ../../.. + +PLATFORMS_EXCLUDE = sky + +include $(CONTIKI)/Makefile.include diff --git a/examples/libs/shell/README.md b/examples/libs/shell/README.md new file mode 100644 index 000000000..a76aa8c05 --- /dev/null +++ b/examples/libs/shell/README.md @@ -0,0 +1 @@ +This is a minimal example for the shell. diff --git a/arch/platform/jn516x/dev/node-id.c b/examples/libs/shell/example.c similarity index 80% rename from arch/platform/jn516x/dev/node-id.c rename to examples/libs/shell/example.c index c29aa8282..51cc98826 100644 --- a/arch/platform/jn516x/dev/node-id.c +++ b/examples/libs/shell/example.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, SICS Swedish ICT. + * Copyright (c) 2018, RISE SICS. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,30 +32,25 @@ /** * \file - * For compatibility with Contiki node-id interface - * + * A very simple example using the shell * \author - * Beshr Al Nahas + * Simon Duquennoy */ #include "contiki.h" -#include "sys/node-id.h" -#include "contiki.h" +#include /* For printf() */ /*---------------------------------------------------------------------------*/ -extern unsigned char node_mac[8]; -unsigned short node_id = 0; +PROCESS(example_process, "Example process: shell"); +AUTOSTART_PROCESSES(&example_process); /*---------------------------------------------------------------------------*/ -void -node_id_restore(void) +PROCESS_THREAD(example_process, ev, data) { - /* base node-id on MAC address */ - node_id = (node_mac[6] << 8) | node_mac[7]; + PROCESS_BEGIN(); + + /* This process does nothing. Connect to the node with `make login` + * to use the shell. */ + + PROCESS_END(); } /*---------------------------------------------------------------------------*/ -void -node_id_burn(unsigned short id) -{ - /* does not burn anything */ - node_id = id; -} diff --git a/examples/libs/simple-energest/Makefile b/examples/libs/simple-energest/Makefile new file mode 100644 index 000000000..056aa5c43 --- /dev/null +++ b/examples/libs/simple-energest/Makefile @@ -0,0 +1,6 @@ +CONTIKI_PROJECT = example +all: $(CONTIKI_PROJECT) + +MODULES += os/services/simple-energest +CONTIKI = ../../.. +include $(CONTIKI)/Makefile.include diff --git a/examples/libs/simple-energest/README.md b/examples/libs/simple-energest/README.md new file mode 100644 index 000000000..42e382b5f --- /dev/null +++ b/examples/libs/simple-energest/README.md @@ -0,0 +1 @@ +This is a minimal example for the module simple-energest. diff --git a/arch/platform/sky/node-id.c b/examples/libs/simple-energest/example.c similarity index 73% rename from arch/platform/sky/node-id.c rename to examples/libs/simple-energest/example.c index ce6f68f85..35d1f0b8d 100644 --- a/arch/platform/sky/node-id.c +++ b/examples/libs/simple-energest/example.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, Swedish Institute of Computer Science. + * Copyright (c) 2018, RISE SICS. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,40 +32,25 @@ /** * \file - * Utility to store a node id in the external flash + * A very simple example of simple-energest * \author - * Adam Dunkels + * Simon Duquennoy */ -#include "sys/node-id.h" #include "contiki.h" -#include "dev/xmem.h" - -unsigned short node_id = 0; +#include /* For printf() */ /*---------------------------------------------------------------------------*/ -void -node_id_restore(void) +PROCESS(example_process, "Example process: simple-energest"); +AUTOSTART_PROCESSES(&example_process); +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(example_process, ev, data) { - unsigned char buf[4]; - xmem_pread(buf, 4, NODE_ID_XMEM_OFFSET); - if(buf[0] == 0xad && - buf[1] == 0xde) { - node_id = (buf[2] << 8) | buf[3]; - } else { - node_id = 0; - } -} -/*---------------------------------------------------------------------------*/ -void -node_id_burn(unsigned short id) -{ - unsigned char buf[4]; - buf[0] = 0xad; - buf[1] = 0xde; - buf[2] = id >> 8; - buf[3] = id & 0xff; - xmem_erase(XMEM_ERASE_UNIT_SIZE, NODE_ID_XMEM_OFFSET); - xmem_pwrite(buf, 4, NODE_ID_XMEM_OFFSET); + PROCESS_BEGIN(); + + /* Do nothing, just let simple-energest write its summary + * at a period of SIMPLE_ENERGEST_CONF_PERIOD */ + + PROCESS_END(); } /*---------------------------------------------------------------------------*/ diff --git a/examples/libs/timers/all-timers.c b/examples/libs/timers/all-timers.c index 2a1f27b28..bb6dfed90 100644 --- a/examples/libs/timers/all-timers.c +++ b/examples/libs/timers/all-timers.c @@ -79,7 +79,7 @@ PROCESS_THREAD(timer_process, ev, data) PROCESS_BEGIN(); ctimer_set(&timer_ctimer, CLOCK_SECOND, ctimer_callback, NULL); - rtimer_set(&timer_rtimer, RTIMER_NOW() + CLOCK_SECOND / 2, 0, + rtimer_set(&timer_rtimer, RTIMER_NOW() + RTIMER_SECOND / 2, 0, rtimer_callback, NULL); while(1) { diff --git a/examples/lwm2m-ipso-objects/Makefile b/examples/lwm2m-ipso-objects/Makefile index 7fa79d1ee..c2cef2cfd 100644 --- a/examples/lwm2m-ipso-objects/Makefile +++ b/examples/lwm2m-ipso-objects/Makefile @@ -11,4 +11,7 @@ MODULES += os/services/lwm2m MODULES += os/services/ipso-objects CONTIKI=../.. +include $(CONTIKI)/Makefile.identify-target +MODULES_REL += $(TARGET) + include $(CONTIKI)/Makefile.include diff --git a/examples/lwm2m-ipso-objects/example-ipso-objects.c b/examples/lwm2m-ipso-objects/example-ipso-objects.c index 013c62205..51bd84040 100644 --- a/examples/lwm2m-ipso-objects/example-ipso-objects.c +++ b/examples/lwm2m-ipso-objects/example-ipso-objects.c @@ -77,7 +77,7 @@ read_temp_value(const ipso_sensor_t *s, int32_t *value) static lwm2m_status_t read_hum_value(const ipso_sensor_t *s, int32_t *value) { - *value = 10 * hdc_1000_sensor.value(HDC_1000_SENSOR_TYPE_HUMIDITY); + *value = 10 * hdc_1000_sensor.value(HDC_1000_SENSOR_TYPE_HUMID); return LWM2M_STATUS_OK; } /* Lux reading */ diff --git a/examples/lwm2m-ipso-objects/example-server.c b/examples/lwm2m-ipso-objects/example-server.c index 0b55b80a2..98e1fef9a 100644 --- a/examples/lwm2m-ipso-objects/example-server.c +++ b/examples/lwm2m-ipso-objects/example-server.c @@ -288,9 +288,6 @@ PROCESS_THREAD(router_process, ev, data) PROCESS_BEGIN(); - /* receives all CoAP messages */ - coap_engine_init(); - /* Initialize DAG root */ NETSTACK_ROUTING.root_start(); diff --git a/examples/lwm2m-ipso-objects/project-conf.h b/examples/lwm2m-ipso-objects/project-conf.h index a7ad8b3ea..a8603c67b 100644 --- a/examples/lwm2m-ipso-objects/project-conf.h +++ b/examples/lwm2m-ipso-objects/project-conf.h @@ -30,9 +30,6 @@ #ifndef PROJECT_CONF_H_ #define PROJECT_CONF_H_ -/* No sleep on CC2538 to enable full 32 KiB RAM */ -#define LPM_CONF_ENABLE 0 - #ifdef BOARD_STRING #define LWM2M_DEVICE_MODEL_NUMBER BOARD_STRING #elif defined(CONTIKI_TARGET_WISMOTE) @@ -62,4 +59,12 @@ /* Enable client-side support for COAP observe */ #define COAP_OBSERVE_CLIENT 1 +/* Definitions to enable Queue Mode, include the dynamic adaptation and change the default parameters */ +/* #define LWM2M_QUEUE_MODE_CONF_ENABLED 1 + #define LWM2M_QUEUE_MODE_CONF_INCLUDE_DYNAMIC_ADAPTATION 1 + #define LWM2M_QUEUE_MODE_CONF_DEFAULT_CLIENT_AWAKE_TIME 2000 + #define LWM2M_QUEUE_MODE_CONF_DEFAULT_CLIENT_SLEEP_TIME 10000 + #define LWM2M_QUEUE_MODE_CONF_DEFAULT_DYNAMIC_ADAPTATION_FLAG 0 + #define LWM2M_QUEUE_MODE_OBJECT_CONF_ENABLED 1 */ + #endif /* PROJECT_CONF_H_ */ diff --git a/examples/lwm2m-ipso-objects/zoul/module-macros.h b/examples/lwm2m-ipso-objects/zoul/module-macros.h new file mode 100644 index 000000000..4db4e82fe --- /dev/null +++ b/examples/lwm2m-ipso-objects/zoul/module-macros.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2018, RISE SICS AB. + * 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 HOLDER 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. + */ +/*---------------------------------------------------------------------------*/ +/* Only sleep mode 1 on Zoul to enable full 32 KiB RAM */ +#define LPM_CONF_MAX_PM 1 +/*---------------------------------------------------------------------------*/ +/* Macros to enter sleep mode and wake up in the Zoul module. Sleep consists + * on turn off the radio and start a RTIMER to wake up, and wake up consists on + * turn on the radio again + */ +#define LWM2M_Q_MODE_WAKE_UP() do { \ + NETSTACK_MAC.on(); \ +} while(0) + +#define LWM2M_Q_MODE_SLEEP_MS(TIME_MS) do { \ + uint64_t aux = TIME_MS * RTIMER_SECOND; \ + NETSTACK_MAC.off(); \ + rtimer_arch_schedule(RTIMER_NOW() + (rtimer_clock_t)(aux / 1000)); \ +} while(0) + + diff --git a/examples/mqtt-client/Makefile b/examples/mqtt-client/Makefile index d315cfea3..a9ab11613 100644 --- a/examples/mqtt-client/Makefile +++ b/examples/mqtt-client/Makefile @@ -8,6 +8,6 @@ CONTIKI = ../.. MODULES_REL += arch/platform/$(TARGET) -PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul native +PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul native simplelink include $(CONTIKI)/Makefile.include diff --git a/examples/mqtt-client/README.md b/examples/mqtt-client/README.md index 44bba8877..8312ec024 100644 --- a/examples/mqtt-client/README.md +++ b/examples/mqtt-client/README.md @@ -13,25 +13,34 @@ The demo will give some visual feedback with a LED (configurable): This example is known to work with all platforms that support the new button API. +This example can operate in two modes: A default mode to be used with the +mosquitto MQTT broker and a second mode to be used with the IBM Watson IoT +platform. + +To enable Watson mode, define `MQTT_CLIENT_CONF_WITH_IBM_WATSON` as 1 in the +example's `project-conf.h`. + Publishing ---------- By default the example will attempt to publish readings to an MQTT broker -running on the IPv6 address specified as `MQTT_DEMO_BROKER_IP_ADDR` in +running on the IPv6 address specified as `MQTT_CLIENT_CONF_BROKER_IP_ADDR` in `project-conf.h`. This functionality was tested successfully with -[mosquitto](http://mosquitto.org/). +[mosquitto](http://mosquitto.org/). This define will be ignored in IBM Watson +mode. The publish messages include sensor readings but also some other information, such as device uptime in seconds and a message sequence number. The demo will publish to topic `iot-2/evt/status/fmt/json`. The device will connect using -client-id `d:contiki-ng:mqtt-client:`, where `` gets -constructed from the device's IEEE address. +client-id `d::mqtt-client:`, where `` gets +constructed from the device's IEEE address. `` can be controlled +through the `MQTT_CLIENT_CONF_ORG_ID` define. Subscribing ----------- You can also subscribe to topics and receive commands, but this will only work if you use "Org ID" != 'quickstart'. To achieve this, you will need to -change 'Org ID' (`DEFAULT_ORG_ID`). In this scenario, the device will subscribe -to: +change `MQTT_CLIENT_CONF_ORG_ID` in `project-conf.h`. In this scenario, the +device will subscribe to: `iot-2/cmd/+/fmt/json` @@ -53,13 +62,18 @@ messages, outgoing publish messages use proper json payload. IBM Quickstart Service ---------------------- It is also possible to publish to IBM's quickstart service. To do so, you need -to undefine `MQTT_DEMO_BROKER_IP_ADDR`. +to enable this mode by setting `MQTT_CLIENT_CONF_WITH_IBM_WATSON` to 1 in +`project-conf.h`. The device will then try to connect to IBM's quickstart over NAT64, so you will need a NAT64 gateway in your network to make this work. A guide on how to -setup NAT64 is out of scope here. +setup NAT64 is out of scope here, but you can find one in the +[Contiki-NG wiki](https://github.com/contiki-ng/contiki-ng/wiki/NAT64-for-Contiki%E2%80%90NG). -If you want to use IBM's cloud service with a registered device, change -'Org ID' (`DEFAULT_ORG_ID`) and provide the 'Auth Token' (`DEFAULT_AUTH_TOKEN`), -which acts as a 'password', but bear in mind that it gets transported in clear -text. +If you want to use IBM's cloud service with a registered device, you will need +to set `MQTT_CLIENT_CONF_ORG_ID` and then also to provide the 'Auth Token' +(`MQTT_CLIENT_CONF_AUTH_TOKEN`), which acts as a 'password'. You will also +need to configure your Organisation / Registered device on Watson such that +TLS is optional. + +Note: The token will be transported in cleartext. diff --git a/examples/mqtt-client/mqtt-client.c b/examples/mqtt-client/mqtt-client.c index 258660459..b71a193ea 100644 --- a/examples/mqtt-client/mqtt-client.c +++ b/examples/mqtt-client/mqtt-client.c @@ -47,24 +47,67 @@ #include /*---------------------------------------------------------------------------*/ #define LOG_MODULE "mqtt-client" +#ifdef MQTT_CLIENT_CONF_LOG_LEVEL +#define LOG_LEVEL MQTT_CLIENT_CONF_LOG_LEVEL +#else #define LOG_LEVEL LOG_LEVEL_NONE +#endif +/*---------------------------------------------------------------------------*/ +/* Controls whether the example will work in IBM Watson IoT platform mode */ +#ifdef MQTT_CLIENT_CONF_WITH_IBM_WATSON +#define MQTT_CLIENT_WITH_IBM_WATSON MQTT_CLIENT_CONF_WITH_IBM_WATSON +#else +#define MQTT_CLIENT_WITH_IBM_WATSON 0 +#endif +/*---------------------------------------------------------------------------*/ +/* MQTT broker address. Ignored in Watson mode */ +#ifdef MQTT_CLIENT_CONF_BROKER_IP_ADDR +#define MQTT_CLIENT_BROKER_IP_ADDR MQTT_CLIENT_CONF_BROKER_IP_ADDR +#else +#define MQTT_CLIENT_BROKER_IP_ADDR "fd00::1" +#endif /*---------------------------------------------------------------------------*/ /* - * IBM server: messaging.quickstart.internetofthings.ibmcloud.com - * (184.172.124.189) mapped in an NAT64 (prefix 64:ff9b::/96) IPv6 address - * Note: If not able to connect; lookup the IP address again as it may change. + * MQTT Org ID. * - * Alternatively, publish to a local MQTT broker (e.g. mosquitto) running on - * the node that hosts your border router + * If it equals "quickstart", the client will connect without authentication. + * In all other cases, the client will connect with authentication mode. + * + * In Watson mode, the username will be "use-token-auth". In non-Watson mode + * the username will be MQTT_CLIENT_USERNAME. + * + * In all cases, the password will be MQTT_CLIENT_AUTH_TOKEN. */ -#ifdef MQTT_CLIENT_CONF_BROKER_IP_ADDR -static const char *broker_ip = MQTT_CLIENT_CONF_BROKER_IP_ADDR; -#define DEFAULT_ORG_ID "contiki-ng" +#ifdef MQTT_CLIENT_CONF_ORG_ID +#define MQTT_CLIENT_ORG_ID MQTT_CLIENT_CONF_ORG_ID #else -static const char *broker_ip = "0064:ff9b:0000:0000:0000:0000:b8ac:7cbd"; -#define DEFAULT_ORG_ID "quickstart" +#define MQTT_CLIENT_ORG_ID "quickstart" #endif /*---------------------------------------------------------------------------*/ +/* MQTT token */ +#ifdef MQTT_CLIENT_CONF_AUTH_TOKEN +#define MQTT_CLIENT_AUTH_TOKEN MQTT_CLIENT_CONF_AUTH_TOKEN +#else +#define MQTT_CLIENT_AUTH_TOKEN "AUTHTOKEN" +#endif +/*---------------------------------------------------------------------------*/ +#if MQTT_CLIENT_WITH_IBM_WATSON +/* With IBM Watson support */ +static const char *broker_ip = "0064:ff9b:0000:0000:0000:0000:b8ac:7cbd"; +#define MQTT_CLIENT_USERNAME "use-token-auth" + +#else /* MQTT_CLIENT_WITH_IBM_WATSON */ +/* Without IBM Watson support. To be used with other brokers, e.g. Mosquitto */ +static const char *broker_ip = MQTT_CLIENT_BROKER_IP_ADDR; + +#ifdef MQTT_CLIENT_CONF_USERNAME +#define MQTT_CLIENT_USERNAME MQTT_CLIENT_CONF_USERNAME +#else +#define MQTT_CLIENT_USERNAME "use-token-auth" +#endif + +#endif /* MQTT_CLIENT_WITH_IBM_WATSON */ +/*---------------------------------------------------------------------------*/ #ifdef MQTT_CLIENT_CONF_STATUS_LED #define MQTT_CLIENT_STATUS_LED MQTT_CLIENT_CONF_STATUS_LED #else @@ -122,18 +165,12 @@ static uint8_t state; #define CONFIG_CMD_TYPE_LEN 8 #define CONFIG_IP_ADDR_STR_LEN 64 /*---------------------------------------------------------------------------*/ -#define RSSI_MEASURE_INTERVAL_MAX 86400 /* secs: 1 day */ -#define RSSI_MEASURE_INTERVAL_MIN 5 /* secs */ -#define PUBLISH_INTERVAL_MAX 86400 /* secs: 1 day */ -#define PUBLISH_INTERVAL_MIN 5 /* secs */ -/*---------------------------------------------------------------------------*/ /* A timeout used when waiting to connect to a network */ #define NET_CONNECT_PERIODIC (CLOCK_SECOND >> 2) #define NO_NET_LED_DURATION (NET_CONNECT_PERIODIC >> 1) /*---------------------------------------------------------------------------*/ /* Default configuration values */ #define DEFAULT_TYPE_ID "mqtt-client" -#define DEFAULT_AUTH_TOKEN "AUTHZ" #define DEFAULT_EVENT_TYPE_ID "status" #define DEFAULT_SUBSCRIBE_CMD_TYPE "+" #define DEFAULT_BROKER_PORT 1883 @@ -272,6 +309,7 @@ pub_handler(const char *topic, uint16_t topic_len, const uint8_t *chunk, } if(strncmp(&topic[10], "leds", 4) == 0) { + LOG_DBG("Received MQTT SUB\n"); if(chunk[0] == '1') { leds_on(LEDS_RED); } else if(chunk[0] == '0') { @@ -423,9 +461,10 @@ init_config() /* Populate configuration with default values */ memset(&conf, 0, sizeof(mqtt_client_config_t)); - memcpy(conf.org_id, DEFAULT_ORG_ID, strlen(DEFAULT_ORG_ID)); + memcpy(conf.org_id, MQTT_CLIENT_ORG_ID, strlen(MQTT_CLIENT_ORG_ID)); memcpy(conf.type_id, DEFAULT_TYPE_ID, strlen(DEFAULT_TYPE_ID)); - memcpy(conf.auth_token, DEFAULT_AUTH_TOKEN, strlen(DEFAULT_AUTH_TOKEN)); + memcpy(conf.auth_token, MQTT_CLIENT_AUTH_TOKEN, + strlen(MQTT_CLIENT_AUTH_TOKEN)); memcpy(conf.event_type_id, DEFAULT_EVENT_TYPE_ID, strlen(DEFAULT_EVENT_TYPE_ID)); memcpy(conf.broker_ip, broker_ip, strlen(broker_ip)); @@ -459,6 +498,7 @@ publish(void) int len; int remaining = APP_BUFFER_SIZE; int i; + char def_rt_str[64]; seq_nr_value++; @@ -485,7 +525,6 @@ publish(void) buf_ptr += len; /* Put our Default route's string representation in a buffer */ - char def_rt_str[64]; memset(def_rt_str, 0, sizeof(def_rt_str)); ipaddr_sprintf(def_rt_str, sizeof(def_rt_str), uip_ds6_defrt_choose()); @@ -568,7 +607,7 @@ state_machine(void) state = STATE_ERROR; break; } else { - mqtt_set_username_password(&conn, "use-token-auth", + mqtt_set_username_password(&conn, MQTT_CLIENT_USERNAME, conf.auth_token); } } diff --git a/examples/mqtt-client/project-conf.h b/examples/mqtt-client/project-conf.h index 7b041ae38..6b011f7b0 100644 --- a/examples/mqtt-client/project-conf.h +++ b/examples/mqtt-client/project-conf.h @@ -35,8 +35,42 @@ /* Enable TCP */ #define UIP_CONF_TCP 1 -/* If undefined, the demo will attempt to connect to IBM's quickstart */ +/* Change to 1 to use with the IBM Watson IoT platform */ +#define MQTT_CLIENT_CONF_WITH_IBM_WATSON 0 + +/* + * The IPv6 address of the MQTT broker to connect to. + * Ignored if MQTT_CLIENT_CONF_WITH_IBM_WATSON is 1 + */ #define MQTT_CLIENT_CONF_BROKER_IP_ADDR "fd00::1" + +/* + * The Organisation ID. + * + * When in Watson mode, the example will default to Org ID "quickstart" and + * will connect using non-authenticated mode. If you want to use registered + * devices, set your Org ID here and then make sure you set the correct token + * through MQTT_CLIENT_CONF_AUTH_TOKEN. + */ +#ifndef MQTT_CLIENT_CONF_ORG_ID +#define MQTT_CLIENT_CONF_ORG_ID "quickstart" +#endif + +/* + * The MQTT username. + * + * Ignored in Watson mode: In this mode the username is always "use-token-auth" + */ +#define MQTT_CLIENT_CONF_USERNAME "mqtt-client-username" + +/* + * The MQTT auth token (password) used when connecting to the MQTT broker. + * + * Used with as well as without Watson. + * + * Transported in cleartext! + */ +#define MQTT_CLIENT_CONF_AUTH_TOKEN "AUTHTOKEN" /*---------------------------------------------------------------------------*/ #endif /* PROJECT_CONF_H_ */ /*---------------------------------------------------------------------------*/ diff --git a/examples/multicast/Makefile b/examples/multicast/Makefile index 6037c8172..86c16e481 100644 --- a/examples/multicast/Makefile +++ b/examples/multicast/Makefile @@ -3,6 +3,8 @@ all: $(CONTIKI_PROJECT) # nrf52dk only supports slave mode, i.e., with no routing PLATFORMS_EXCLUDE = nrf52dk +# does not fit sky motes +PLATFORMS_EXCLUDE += sky CONTIKI = ../.. diff --git a/examples/multicast/root.c b/examples/multicast/root.c index f997e9613..59d5d2aa8 100644 --- a/examples/multicast/root.c +++ b/examples/multicast/root.c @@ -45,6 +45,7 @@ #include "net/ipv6/multicast/uip-mcast6.h" #include +#include #define DEBUG DEBUG_PRINT #include "net/ipv6/uip-debug.h" diff --git a/examples/platform-specific/cc26xx/ble-ipv6/project-conf.h b/examples/platform-specific/cc26xx/ble-ipv6/project-conf.h index 815cfb90a..b311a2fa5 100644 --- a/examples/platform-specific/cc26xx/ble-ipv6/project-conf.h +++ b/examples/platform-specific/cc26xx/ble-ipv6/project-conf.h @@ -36,9 +36,6 @@ #ifndef PROJECT_CONF_H_ #define PROJECT_CONF_H_ -/*---------------------------------------------------------------------------*/ -/* Disable button shutdown functionality */ -#define BUTTON_SENSOR_CONF_ENABLE_SHUTDOWN 0 /*---------------------------------------------------------------------------*/ /* Change to match your configuration */ #define BOARD_CONF_DEBUGGER_DEVPACK 1 diff --git a/examples/platform-specific/cc26xx/cc26xx-demo.c b/examples/platform-specific/cc26xx/cc26xx-demo.c index 8c90905af..81e99f3fa 100644 --- a/examples/platform-specific/cc26xx/cc26xx-demo.c +++ b/examples/platform-specific/cc26xx/cc26xx-demo.c @@ -203,7 +203,7 @@ get_hdc_reading() printf("HDC: Temp Read Error\n"); } - value = hdc_1000_sensor.value(HDC_1000_SENSOR_TYPE_HUMIDITY); + value = hdc_1000_sensor.value(HDC_1000_SENSOR_TYPE_HUMID); if(value != CC26XX_SENSOR_READING_ERROR) { printf("HDC: Humidity=%d.%02d %%RH\n", value / 100, value % 100); } else { diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/README.md b/examples/platform-specific/cc26xx/cc26xx-web-demo/README.md index 6acd69b3a..912fcb72a 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/README.md +++ b/examples/platform-specific/cc26xx/cc26xx-web-demo/README.md @@ -10,11 +10,17 @@ demonstrate the CC26xx capability. The applications are: * A web server which can be used to display sensor readings but also to configure MQTT functionality -The example has been configured to run for all CC26xx-based boards: i) The -SensorTag 2.0 and ii) The Srf06EB with a CC26xx or CC13xx EM mounted on it. +The example has been configured to run for all CC26xx-based boards. -To change between target boards, follow the instructions in the platform's -REDME file. Do not forget to `make clean` when switching between the boards. +To change between target boards, follow the instructions in the wiki. +Do not forget to `make clean` when switching between the boards. + +Specifically for some older CC2650 SensorTags, you may also need to change +`project-conf.h` such that `SENSORTAG_CC2650_REV_1_2_0` is defined as 1. To +check if your sensortag is one of those older ones, look for "REV: 1.2" +printed on the PCB. There may also be a sticker that reads "HW Rev 1.2.0". An +indication that you may need to do this is if you get a "Could not open flash +to load config" error on device startup. You can disable some of those individual components by changing the respective defines in `project-conf.h`. For instance, to disable the CoAP functionality, @@ -171,3 +177,9 @@ the state of the LED. Bear in mind that, even though the topic suggests that messages are of json format, they are in fact not. This was done in order to avoid linking a json parser into the firmware. + +IBM Watson IoT Platform +---------------------------- +To use IBM Watson IoT Platform, you have to go to SECURITY tab of Device page to select "TLS Optional". This step is critical. If you don't do this, you need to use TLS for connection and default cc26xx-web-demo won't work. + +![IBM Watson IoT Platform TLS Optional Configuration](img/ibm-watson-iot-platform-tls-optional.png) diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/cc26xx-web-demo.c b/examples/platform-specific/cc26xx/cc26xx-web-demo/cc26xx-web-demo.c index f69a19478..3944a58b2 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/cc26xx-web-demo.c +++ b/examples/platform-specific/cc26xx/cc26xx-web-demo/cc26xx-web-demo.c @@ -636,7 +636,7 @@ get_hdc_reading() } if(hdc_hum_reading.publish) { - value = hdc_1000_sensor.value(HDC_1000_SENSOR_TYPE_HUMIDITY); + value = hdc_1000_sensor.value(HDC_1000_SENSOR_TYPE_HUMID); if(value != CC26XX_SENSOR_READING_ERROR) { hdc_hum_reading.raw = value; diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/cc26xx-web-demo.h b/examples/platform-specific/cc26xx/cc26xx-web-demo/cc26xx-web-demo.h index 0761725c7..f59e41bc7 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/cc26xx-web-demo.h +++ b/examples/platform-specific/cc26xx/cc26xx-web-demo/cc26xx-web-demo.h @@ -119,7 +119,7 @@ /*---------------------------------------------------------------------------*/ /* Default configuration values */ #define CC26XX_WEB_DEMO_DEFAULT_ORG_ID "quickstart" -#if CPU_FAMILY_CC13XX +#if CPU_FAMILY_CC13X0 #define CC26XX_WEB_DEMO_DEFAULT_TYPE_ID "cc13xx" #else #define CC26XX_WEB_DEMO_DEFAULT_TYPE_ID "cc26xx" diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/coap-server.c b/examples/platform-specific/cc26xx/cc26xx-web-demo/coap-server.c index 54289f102..37b9a295d 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/coap-server.c +++ b/examples/platform-specific/cc26xx/cc26xx-web-demo/coap-server.c @@ -133,9 +133,6 @@ PROCESS_THREAD(coap_server_process, ev, data) printf("CC26XX CoAP Server\n"); - /* Initialize the REST engine. */ - coap_engine_init(); - coap_activate_resource(&res_batmon_temp, "sen/batmon/temp"); coap_activate_resource(&res_batmon_volt, "sen/batmon/voltage"); diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/img/ibm-watson-iot-platform-tls-optional.png b/examples/platform-specific/cc26xx/cc26xx-web-demo/img/ibm-watson-iot-platform-tls-optional.png new file mode 100644 index 000000000..93c98624f Binary files /dev/null and b/examples/platform-specific/cc26xx/cc26xx-web-demo/img/ibm-watson-iot-platform-tls-optional.png differ diff --git a/examples/platform-specific/cc26xx/cc26xx-web-demo/project-conf.h b/examples/platform-specific/cc26xx/cc26xx-web-demo/project-conf.h index 40a1e8262..ee40e1749 100644 --- a/examples/platform-specific/cc26xx/cc26xx-web-demo/project-conf.h +++ b/examples/platform-specific/cc26xx/cc26xx-web-demo/project-conf.h @@ -33,7 +33,7 @@ /*---------------------------------------------------------------------------*/ /* Change to match your configuration */ #define IEEE802154_CONF_PANID 0xABCD -#define RF_CORE_CONF_CHANNEL 26 +#define IEEE802154_CONF_DEFAULT_CHANNEL 26 #define RF_BLE_CONF_ENABLED 1 /*---------------------------------------------------------------------------*/ @@ -53,8 +53,18 @@ */ #define CC26XX_WEB_DEMO_CONF_ADC_DEMO 0 /*---------------------------------------------------------------------------*/ +/* + * Change to 1 if you are using an older CC2650 Sensortag (look for Rev: 1.2 + * printed on the PCB, or for a sticker reading "HW Rev 1.2.0"). + * + * This may be the case if you are getting this error: + * "Could not open flash to load config" + * when your sensortag is starting up. + */ +#define SENSORTAG_CC2650_REV_1_2_0 0 +/*---------------------------------------------------------------------------*/ /* Enable the ROM bootloader */ -#define ROM_BOOTLOADER_ENABLE 1 +#define CCXXWARE_CONF_ROM_BOOTLOADER_ENABLE 1 /*---------------------------------------------------------------------------*/ /* * Shrink the size of the uIP buffer, routing table and ND cache. diff --git a/examples/platform-specific/cc26xx/project-conf.h b/examples/platform-specific/cc26xx/project-conf.h index 8231dd4ea..3cbc0da86 100644 --- a/examples/platform-specific/cc26xx/project-conf.h +++ b/examples/platform-specific/cc26xx/project-conf.h @@ -32,11 +32,11 @@ #define PROJECT_CONF_H_ /*---------------------------------------------------------------------------*/ /* Enable the ROM bootloader */ -#define ROM_BOOTLOADER_ENABLE 1 +#define CCXXWARE_CONF_ROM_BOOTLOADER_ENABLE 1 /*---------------------------------------------------------------------------*/ /* Change to match your configuration */ #define IEEE802154_CONF_PANID 0xABCD -#define RF_CORE_CONF_CHANNEL 25 +#define IEEE802154_CONF_DEFAULT_CHANNEL 25 #define RF_BLE_CONF_ENABLED 1 /*---------------------------------------------------------------------------*/ #endif /* PROJECT_CONF_H_ */ diff --git a/examples/platform-specific/cc26xx/very-sleepy-demo/project-conf.h b/examples/platform-specific/cc26xx/very-sleepy-demo/project-conf.h index b60df036d..0f8467a68 100644 --- a/examples/platform-specific/cc26xx/very-sleepy-demo/project-conf.h +++ b/examples/platform-specific/cc26xx/very-sleepy-demo/project-conf.h @@ -33,11 +33,10 @@ /*---------------------------------------------------------------------------*/ /* Change to match your configuration */ #define IEEE802154_CONF_PANID 0xABCD -#define RF_CORE_CONF_CHANNEL 25 +#define IEEE802154_CONF_DEFAULT_CHANNEL 25 /*---------------------------------------------------------------------------*/ - /* Enable the ROM bootloader */ -#define ROM_BOOTLOADER_ENABLE 1 +#define CCXXWARE_CONF_ROM_BOOTLOADER_ENABLE 1 /*---------------------------------------------------------------------------*/ /* For very sleepy operation */ #define RF_BLE_CONF_ENABLED 0 diff --git a/examples/platform-specific/cc26xx/very-sleepy-demo/very-sleepy-demo.c b/examples/platform-specific/cc26xx/very-sleepy-demo/very-sleepy-demo.c index cac8033b7..ebd55712b 100644 --- a/examples/platform-specific/cc26xx/very-sleepy-demo/very-sleepy-demo.c +++ b/examples/platform-specific/cc26xx/very-sleepy-demo/very-sleepy-demo.c @@ -344,8 +344,6 @@ PROCESS_THREAD(very_sleepy_demo_process, ev, data) event_new_config = process_alloc_event(); - coap_engine_init(); - readings_resource.flags += IS_OBSERVABLE; coap_activate_resource(&readings_resource, "sen/readings"); coap_activate_resource(&very_sleepy_conf, "very_sleepy_config"); diff --git a/examples/platform-specific/jn516x/rpl/coap-dongle-node/dongle-node.c b/examples/platform-specific/jn516x/rpl/coap-dongle-node/dongle-node.c index 2fb2d7761..9c7cbb7aa 100644 --- a/examples/platform-specific/jn516x/rpl/coap-dongle-node/dongle-node.c +++ b/examples/platform-specific/jn516x/rpl/coap-dongle-node/dongle-node.c @@ -135,7 +135,6 @@ PROCESS_THREAD(start_app, ev, data) NETSTACK_MAC.on(); printf("Starting RPL node\n"); - coap_engine_init(); coap_activate_resource(&resource_led_toggle, "Dongle/LED-toggle"); PROCESS_END(); diff --git a/examples/platform-specific/jn516x/rpl/coap-dr1175-node/dr1175-node.c b/examples/platform-specific/jn516x/rpl/coap-dr1175-node/dr1175-node.c index 443cf4fbe..4a8432099 100644 --- a/examples/platform-specific/jn516x/rpl/coap-dr1175-node/dr1175-node.c +++ b/examples/platform-specific/jn516x/rpl/coap-dr1175-node/dr1175-node.c @@ -355,7 +355,6 @@ PROCESS_THREAD(start_app, ev, data) NETSTACK_MAC.on(); printf("Starting RPL node\n"); - coap_engine_init(); coap_activate_resource(&resource_light_sensor_value, "DR1175/LightSensor/Value"); coap_activate_resource(&resource_light_sensor_unit, "DR1175/LightSensor/Unit"); coap_activate_resource(&resource_temperature_unit, "DR1175/Temperature/Unit"); diff --git a/examples/platform-specific/jn516x/rpl/coap-dr1199-node/dr1199-node.c b/examples/platform-specific/jn516x/rpl/coap-dr1199-node/dr1199-node.c index d341170ad..d493636b5 100644 --- a/examples/platform-specific/jn516x/rpl/coap-dr1199-node/dr1199-node.c +++ b/examples/platform-specific/jn516x/rpl/coap-dr1199-node/dr1199-node.c @@ -356,7 +356,6 @@ PROCESS_THREAD(start_app, ev, data) NETSTACK_MAC.on(); printf("Starting RPL node\n"); - coap_engine_init(); coap_activate_resource(&resource_switch_sw1, "DR1199/Switch/SW1"); coap_activate_resource(&resource_switch_sw2, "DR1199/Switch/SW2"); coap_activate_resource(&resource_switch_sw3, "DR1199/Switch/SW3"); diff --git a/examples/platform-specific/jn516x/rpl/common-conf.h b/examples/platform-specific/jn516x/rpl/common-conf.h index daa66ae29..8ffb3b4f5 100644 --- a/examples/platform-specific/jn516x/rpl/common-conf.h +++ b/examples/platform-specific/jn516x/rpl/common-conf.h @@ -72,8 +72,6 @@ #define IEEE802154_CONF_PANID 0xabcd -#define MICROMAC_CONF_CHANNEL 26 - /* UART Configuration */ #define UART_HW_FLOW_CTRL 0 diff --git a/examples/platform-specific/jn516x/tsch/common-conf.h b/examples/platform-specific/jn516x/tsch/common-conf.h index 39d012d52..5911f34ee 100644 --- a/examples/platform-specific/jn516x/tsch/common-conf.h +++ b/examples/platform-specific/jn516x/tsch/common-conf.h @@ -104,8 +104,6 @@ #if MAC_CONF_WITH_CSMA /* Configure Csma with ACK (default MAC) */ -#define MICROMAC_CONF_CHANNEL 26 - #define MICROMAC_CONF_AUTOACK 1 /* increase internal radio buffering */ diff --git a/examples/platform-specific/jn516x/tsch/simple-sensor-network/node/node.c b/examples/platform-specific/jn516x/tsch/simple-sensor-network/node/node.c index 42fa11fb7..251b0d135 100644 --- a/examples/platform-specific/jn516x/tsch/simple-sensor-network/node/node.c +++ b/examples/platform-specific/jn516x/tsch/simple-sensor-network/node/node.c @@ -38,7 +38,7 @@ #include "net/routing/routing.h" #include "net/ipv6/uip-debug.h" #include "lib/random.h" -#include "node-id.h" +#include "sys/node-id.h" #include "waveform.h" #include "leds.h" #include "net/ipv6/uiplib.h" @@ -194,7 +194,7 @@ PROCESS_THREAD(node_process, ev, data) if (host_found) { /* Make sample count dependent on asn. After a disconnect, waveforms remain synchronous. Use node_mac to create phase offset between waveforms in different nodes */ - sample_count = ((tsch_current_asn.ls4b/((1000/(TSCH_CONF_DEFAULT_TIMESLOT_LENGTH/1000)))/INTERVAL)+node_mac[7]) % (SIZE_OF_WAVEFORM-1); + sample_count = ((tsch_current_asn.ls4b/((1000/(tsch_timing_us[tsch_ts_timeslot_length]/1000)))/INTERVAL)+node_mac[7]) % (SIZE_OF_WAVEFORM-1); printf("%d sec. waveform=%s. cnt=%d. value=%d\n", total_time, waveform_table[selected_waveform].str, sample_count, waveform_table[selected_waveform].table[sample_count]); my_sprintf(udp_buf, waveform_table[selected_waveform].table[sample_count]); uip_udp_packet_send(udp_conn_tx, udp_buf, strlen(udp_buf)); diff --git a/examples/platform-specific/jn516x/tsch/tx-power-verification/node/node.c b/examples/platform-specific/jn516x/tsch/tx-power-verification/node/node.c index 995dc3304..2230f4831 100644 --- a/examples/platform-specific/jn516x/tsch/tx-power-verification/node/node.c +++ b/examples/platform-specific/jn516x/tsch/tx-power-verification/node/node.c @@ -110,7 +110,6 @@ PROCESS_THREAD(start_app, ev, data) NETSTACK_MAC.on(); printf("Starting RPL node\n"); - coap_engine_init(); coap_activate_resource(&resource_set_tx_power, "Set-TX-Power"); coap_activate_resource(&resource_get_tx_power, "Get-TX-Power"); diff --git a/examples/platform-specific/jn516x/tsch/uart1-test-node/uart1-test-node.c b/examples/platform-specific/jn516x/tsch/uart1-test-node/uart1-test-node.c index dd647fa21..8759e8307 100644 --- a/examples/platform-specific/jn516x/tsch/uart1-test-node/uart1-test-node.c +++ b/examples/platform-specific/jn516x/tsch/uart1-test-node/uart1-test-node.c @@ -151,7 +151,6 @@ PROCESS_THREAD(start_app, ev, data) NETSTACK_MAC.on(); printf("Starting RPL node\n"); - coap_engine_init(); coap_activate_resource(&resource_coap_rx_uart1, "UART1-RX"); coap_activate_resource(&resource_coap_tx_uart1, "UART1-TX"); diff --git a/examples/platform-specific/nrf52dk/coap-demo/coap-client/coap-client.c b/examples/platform-specific/nrf52dk/coap-demo/coap-client/coap-client.c index 4effcc876..916c06603 100644 --- a/examples/platform-specific/nrf52dk/coap-demo/coap-client/coap-client.c +++ b/examples/platform-specific/nrf52dk/coap-demo/coap-client/coap-client.c @@ -148,9 +148,6 @@ PROCESS_THREAD(er_example_observe_client, ev, data) static coap_endpoint_t server_endpoint; coap_endpoint_parse(SERVER_IPV6_EP, strlen(SERVER_IPV6_EP), &server_endpoint); - /* receives all CoAP messages */ - coap_engine_init(); - #if PLATFORM_HAS_BUTTON SENSORS_ACTIVATE(button_1); SENSORS_ACTIVATE(button_2); diff --git a/examples/platform-specific/nrf52dk/coap-demo/coap-server/coap-server.c b/examples/platform-specific/nrf52dk/coap-demo/coap-server/coap-server.c index 6b4025cd3..584f54318 100644 --- a/examples/platform-specific/nrf52dk/coap-demo/coap-server/coap-server.c +++ b/examples/platform-specific/nrf52dk/coap-demo/coap-server/coap-server.c @@ -103,8 +103,6 @@ PROCESS_THREAD(er_example_server, ev, data) print_local_addresses(); - /* Initialize the REST engine. */ - coap_engine_init(); coap_activate_resource(&res_led3, "lights/led3"); SENSORS_ACTIVATE(button_1); diff --git a/examples/platform-specific/zoul/Makefile b/examples/platform-specific/zoul/Makefile index 88dcb3ce2..3b57eb035 100644 --- a/examples/platform-specific/zoul/Makefile +++ b/examples/platform-specific/zoul/Makefile @@ -1,9 +1,9 @@ -CONTIKI_PROJECT = test-tsl256x test-sht25 test-servo.c +CONTIKI_PROJECT = test-tsl256x test-sht25 test-servo CONTIKI_PROJECT += test-bmp085-bmp180 test-motion test-rotation-sensor CONTIKI_PROJECT += test-grove-light-sensor test-grove-loudness-sensor CONTIKI_PROJECT += test-weather-meter test-grove-gyro test-lcd test-iaq CONTIKI_PROJECT += test-pm10-sensor test-vac-sensor test-aac-sensor -CONTIKI_PROJECT += test-zonik test-dht22.c test-ac-dimmer.c +CONTIKI_PROJECT += test-zonik test-dht22 test-ac-dimmer CONTIKI_PROJECT += test-bme280 CONTIKI_TARGET_SOURCEFILES += tsl256x.c sht25.c bmpx8x.c motion-sensor.c diff --git a/examples/rpl-border-router/webserver/httpd-simple.c b/examples/rpl-border-router/webserver/httpd-simple.c index d8ce76816..7ce984e6a 100644 --- a/examples/rpl-border-router/webserver/httpd-simple.c +++ b/examples/rpl-border-router/webserver/httpd-simple.c @@ -128,7 +128,8 @@ PT_THREAD(handle_output(struct httpd_state *s)) s->script = NULL; s->script = httpd_simple_get_script(&s->filename[1]); if(s->script == NULL) { - strncpy(s->filename, "/notfound.html", sizeof(s->filename)); + strncpy(s->filename, "/notfound.html", sizeof(s->filename) - 1); + s->filename[sizeof(s->filename) - 1] = '\0'; PT_WAIT_THREAD(&s->outputpt, send_headers(s, http_header_404)); PT_WAIT_THREAD(&s->outputpt, @@ -170,7 +171,8 @@ PT_THREAD(handle_input(struct httpd_state *s)) urlconv_tofilename(s->filename, s->inputbuf, sizeof(s->filename)); #else /* URLCONV */ if(s->inputbuf[1] == ISO_space) { - strncpy(s->filename, http_index_html, sizeof(s->filename)); + strncpy(s->filename, http_index_html, sizeof(s->filename) - 1); + s->filename[sizeof(s->filename) - 1] = '\0'; } else { s->inputbuf[PSOCK_DATALEN(&s->sin) - 1] = 0; strncpy(s->filename, s->inputbuf, sizeof(s->filename)); diff --git a/examples/rpl-udp/Makefile b/examples/rpl-udp/Makefile index 26190e839..78e6d1653 100644 --- a/examples/rpl-udp/Makefile +++ b/examples/rpl-udp/Makefile @@ -1,20 +1,5 @@ CONTIKI_PROJECT = udp-client udp-server all: $(CONTIKI_PROJECT) -.PHONY: renode -renode: all -ifneq ($(TARGET),cc2538dk) - $(error Only the cc2538dk TARGET is supported for Renode demo scripts) -endif -ifndef SCRIPT - $(warning SCRIPT not defined! Using "rpl-udp.resc" as default) - renode rpl-udp.resc -else -ifeq ($(wildcard $(SCRIPT)),) - $(error SCRIPT "$(SCRIPT)" does not exist!) -endif - renode $(SCRIPT) -endif - CONTIKI=../.. include $(CONTIKI)/Makefile.include diff --git a/examples/rpl-udp/rpl-udp-sky.csc b/examples/rpl-udp/rpl-udp-sky.csc index 7975acf05..4b9ce6099 100644 --- a/examples/rpl-udp/rpl-udp-sky.csc +++ b/examples/rpl-udp/rpl-udp-sky.csc @@ -24,7 +24,7 @@ sky1 Sky Mote Type #sky1 [CONTIKI_DIR]/examples/rpl-udp/udp-server.c - make clean udp-server.sky TARGET=sky + make udp-server.sky TARGET=sky [CONTIKI_DIR]/examples/rpl-udp/udp-server.sky org.contikios.cooja.interfaces.Position org.contikios.cooja.interfaces.RimeAddress @@ -47,7 +47,7 @@ sky2 Sky Mote Type #sky2 [CONTIKI_DIR]/examples/rpl-udp/udp-client.c - make clean udp-client.sky TARGET=sky + make udp-client.sky TARGET=sky [CONTIKI_DIR]/examples/rpl-udp/udp-client.sky org.contikios.cooja.interfaces.Position org.contikios.cooja.interfaces.RimeAddress diff --git a/examples/rpl-udp/udp-client.c b/examples/rpl-udp/udp-client.c index a10d188ac..1fb030034 100644 --- a/examples/rpl-udp/udp-client.c +++ b/examples/rpl-udp/udp-client.c @@ -33,10 +33,7 @@ udp_rx_callback(struct simple_udp_connection *c, uint16_t datalen) { unsigned count = *(unsigned *)data; - /* If tagging of traffic class is enabled tc will print number of - transmission - otherwise it will be 0 */ - LOG_INFO("Received response %u (tc:%d) from ", count, - uipbuf_get_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS)); + LOG_INFO("Received response %u from ", count); LOG_INFO_6ADDR(sender_addr); LOG_INFO_("\n"); } @@ -62,12 +59,6 @@ PROCESS_THREAD(udp_client_process, ev, data) LOG_INFO("Sending request %u to ", count); LOG_INFO_6ADDR(&dest_ipaddr); LOG_INFO_("\n"); - /* Set the number of transmissions to use for this packet - - this can be used to create more reliable transmissions or - less reliable than the default. Works end-to-end if - UIP_CONF_TAG_TC_WITH_VARIABLE_RETRANSMISSIONS is set to 1. - */ - uipbuf_set_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS, 1 + count % 5); simple_udp_sendto(&udp_conn, &count, sizeof(count), &dest_ipaddr); count++; } else { diff --git a/examples/sensniff/Makefile b/examples/sensniff/Makefile index e207590bb..090bc694d 100644 --- a/examples/sensniff/Makefile +++ b/examples/sensniff/Makefile @@ -1,7 +1,7 @@ CONTIKI_PROJECT = sensniff CONTIKI = ../.. -PLATFORMS_ONLY = cc2538dk openmote-cc2538 zoul srf06-cc26xx jn516x +PLATFORMS_ONLY = cc2538dk openmote-cc2538 zoul srf06-cc26xx jn516x simplelink PROJECT_SOURCEFILES += sensniff-mac.c netstack.c MODULES_REL += pool $(TARGET) diff --git a/examples/sensniff/pool/simplelink-cc13xx-cc26xx-io.h b/examples/sensniff/pool/simplelink-cc13xx-cc26xx-io.h new file mode 100644 index 000000000..a77f9eb76 --- /dev/null +++ b/examples/sensniff/pool/simplelink-cc13xx-cc26xx-io.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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 SIMPLELINK_CC13XX_CC26XX_IO_H_ +#define SIMPLELINK_CC13XX_CC26XX_IO_H_ +/*---------------------------------------------------------------------------*/ +#include "contiki.h" +/*---------------------------------------------------------------------------*/ +#include "dev/uart0-arch.h" +/*---------------------------------------------------------------------------*/ +#define sensniff_io_byte_out(b) uart0_write_byte(b) +#define sensniff_io_flush() +#define sensniff_io_set_input(f) uart0_set_callback(f) +/*---------------------------------------------------------------------------*/ +#endif /* SIMPLELINK_CC13XX_CC26XX_IO_H_ */ +/*---------------------------------------------------------------------------*/ diff --git a/examples/sensniff/simplelink/target-conf.h b/examples/sensniff/simplelink/target-conf.h new file mode 100644 index 000000000..043e5a08f --- /dev/null +++ b/examples/sensniff/simplelink/target-conf.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/ + * 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 TARGET_CONF_H_ +#define TARGET_CONF_H_ +/*---------------------------------------------------------------------------*/ +#define TI_UART_CONF_BAUD_RATE 460800 +#define RF_CONF_BLE_BEACON_ENABLE 0 +/*---------------------------------------------------------------------------*/ +#define SENSNIFF_IO_DRIVER_H "pool/simplelink-cc13xx-cc26xx-io.h" +/*---------------------------------------------------------------------------*/ +#endif /* TARGET_CONF_H_ */ +/*---------------------------------------------------------------------------*/ diff --git a/examples/sensniff/srf06-cc26xx/target-conf.h b/examples/sensniff/srf06-cc26xx/target-conf.h index 4d9deffda..b86df35c5 100644 --- a/examples/sensniff/srf06-cc26xx/target-conf.h +++ b/examples/sensniff/srf06-cc26xx/target-conf.h @@ -32,9 +32,9 @@ #ifndef TARGET_CONF_H_ #define TARGET_CONF_H_ /*---------------------------------------------------------------------------*/ -#define CC26XX_UART_CONF_BAUD_RATE 460800 -#define RF_BLE_CONF_ENABLED 0 -#define ROM_BOOTLOADER_ENABLE 1 +#define CC26XX_UART_CONF_BAUD_RATE 460800 +#define RF_BLE_CONF_ENABLED 0 +#define CCXXWARE_CONF_ROM_BOOTLOADER_ENABLE 1 /*---------------------------------------------------------------------------*/ #define SENSNIFF_IO_DRIVER_H "pool/cc13xx-cc26xx-io.h" /*---------------------------------------------------------------------------*/ diff --git a/examples/slip-radio/slip-radio.c b/examples/slip-radio/slip-radio.c index b39032d96..a20bd8676 100644 --- a/examples/slip-radio/slip-radio.c +++ b/examples/slip-radio/slip-radio.c @@ -143,7 +143,7 @@ slip_radio_cmd_handler(const uint8_t *data, int len) packetbuf_clear(); pos = packetutils_deserialize_atts(&data[3], len - 3); if(pos < 0) { - LOG_ERR("slip-radio: illegal packet attributes\n"); + LOG_ERR("illegal packet attributes\n"); return 1; } pos += 3; @@ -154,7 +154,7 @@ slip_radio_cmd_handler(const uint8_t *data, int len) memcpy(packetbuf_dataptr(), &data[pos], len); packetbuf_set_datalen(len); - LOG_DBG("slip-radio: sending %u (%d bytes)\n", + LOG_DBG("sending %u (%d bytes)\n", data[2], packetbuf_datalen()); /* parse frame before sending to get addresses, etc. */ @@ -193,7 +193,7 @@ slip_radio_cmd_handler(const uint8_t *data, int len) /* this is just a test so far... just to see if it works */ uip_buf[0] = '!'; uip_buf[1] = 'M'; - for(i = 0; i < 8; i++) { + for(i = 0; i < UIP_LLADDR_LEN; i++) { uip_buf[2 + i] = uip_lladdr.addr[i]; } uip_len = 10; diff --git a/os/contiki-default-conf.h b/os/contiki-default-conf.h index 8ec1a41f7..f8fbc9933 100644 --- a/os/contiki-default-conf.h +++ b/os/contiki-default-conf.h @@ -41,6 +41,16 @@ #define IEEE802154_CONF_PANID 0xabcd #endif /* IEEE802154_CONF_PANID */ +/* IEEE802154_CONF_DEFAULT_CHANNEL defines the default channel for IEEE 802.15.4 + * networks, for MAC layers without a channel selection or channel hopping + * mechanism. Current 802.15.4 MAC layers: + * - CSMA: uses IEEE802154_CONF_DEFAULT_CHANNEL + * - TSCH: uses its own TSCH_DEFAULT_HOPPING_SEQUENCE instead + */ +#ifndef IEEE802154_CONF_DEFAULT_CHANNEL +#define IEEE802154_CONF_DEFAULT_CHANNEL 26 +#endif /* IEEE802154_CONF_DEF_CHANNEL */ + /* QUEUEBUF_CONF_NUM specifies the number of queue buffers. Queue buffers are used throughout the Contiki netstack but the configuration option can be tweaked to save memory. Performance can diff --git a/os/contiki-main.c b/os/contiki-main.c index 234b759ee..db8893717 100644 --- a/os/contiki-main.c +++ b/os/contiki-main.c @@ -42,14 +42,18 @@ /*---------------------------------------------------------------------------*/ #include "contiki.h" #include "contiki-net.h" +#include "sys/node-id.h" #include "sys/platform.h" #include "sys/energest.h" #include "sys/stack-check.h" #include "dev/watchdog.h" +#include "net/app-layer/coap/coap-engine.h" #include "services/rpl-border-router/rpl-border-router.h" #include "services/orchestra/orchestra.h" #include "services/shell/serial-shell.h" +#include "services/simple-energest/simple-energest.h" +#include "services/tsch-cs/tsch-cs.h" #include #include @@ -85,14 +89,22 @@ main(void) platform_init_stage_two(); - LOG_INFO("Starting " CONTIKI_VERSION_STRING "\n"); - - LOG_INFO(" Net: %s\n", NETSTACK_NETWORK.name); - LOG_INFO(" MAC: %s\n", NETSTACK_MAC.name); - netstack_init(); + node_id_init(); - LOG_INFO("Link-layer address "); + LOG_INFO("Starting " CONTIKI_VERSION_STRING "\n"); + LOG_INFO("- Routing: %s\n", NETSTACK_ROUTING.name); + LOG_INFO("- Net: %s\n", NETSTACK_NETWORK.name); + LOG_INFO("- MAC: %s\n", NETSTACK_MAC.name); + LOG_INFO("- 802.15.4 PANID: 0x%04x\n", IEEE802154_PANID); +#if MAC_CONF_WITH_TSCH + LOG_INFO("- 802.15.4 TSCH default hopping sequence length: %u\n", (unsigned)sizeof(TSCH_DEFAULT_HOPPING_SEQUENCE)); +#else /* MAC_CONF_WITH_TSCH */ + LOG_INFO("- 802.15.4 Default channel: %u\n", IEEE802154_DEFAULT_CHANNEL); +#endif /* MAC_CONF_WITH_TSCH */ + + LOG_INFO("Node ID: %u\n", node_id); + LOG_INFO("Link-layer address: "); LOG_INFO_LLADDR(&linkaddr_node_addr); LOG_INFO_("\n"); @@ -103,7 +115,7 @@ main(void) process_start(&tcpip_process, NULL); lladdr = uip_ds6_get_link_local(-1); - LOG_INFO("Tentative link-local IPv6 address "); + LOG_INFO("Tentative link-local IPv6 address: "); LOG_INFO_6ADDR(lladdr != NULL ? &lladdr->ipaddr : NULL); LOG_INFO_("\n"); } @@ -126,6 +138,20 @@ main(void) LOG_DBG("With Shell\n"); #endif /* BUILD_WITH_SHELL */ +#if BUILD_WITH_COAP + coap_engine_init(); + LOG_DBG("With CoAP\n"); +#endif /* BUILD_WITH_SHELL */ + +#if BUILD_WITH_SIMPLE_ENERGEST + simple_energest_init(); +#endif /* BUILD_WITH_SIMPLE_ENERGEST */ + +#if BUILD_WITH_TSCH_CS + /* Initialize the channel selection module */ + tsch_cs_adaptations_init(); +#endif /* BUILD_WITH_TSCH_CS */ + autostart_start(autostart_processes); watchdog_start(); diff --git a/os/dev/gpio-hal.c b/os/dev/gpio-hal.c index 658152293..949d829a7 100644 --- a/os/dev/gpio-hal.c +++ b/os/dev/gpio-hal.c @@ -75,6 +75,7 @@ void gpio_hal_init() { list_init(handlers); + gpio_hal_arch_init(); } /*---------------------------------------------------------------------------*/ #if GPIO_HAL_ARCH_SW_TOGGLE diff --git a/os/dev/gpio-hal.h b/os/dev/gpio-hal.h index b6af7bf74..5ad9f472b 100644 --- a/os/dev/gpio-hal.h +++ b/os/dev/gpio-hal.h @@ -82,7 +82,7 @@ typedef uint8_t gpio_hal_pin_t; * A logical representation of a pin's configuration. It is an OR combination * of GPIO_HAL_PIN_CFG_xyz macros. */ -typedef uint8_t gpio_hal_pin_cfg_t; +typedef uint32_t gpio_hal_pin_cfg_t; #ifdef GPIO_HAL_CONF_PIN_COUNT #define GPIO_HAL_PIN_COUNT GPIO_HAL_CONF_PIN_COUNT @@ -107,6 +107,8 @@ typedef void (*gpio_hal_callback_t)(gpio_hal_pin_mask_t pin_mask); #define GPIO_HAL_PIN_CFG_PULL_MASK (GPIO_HAL_PIN_CFG_PULL_UP | \ GPIO_HAL_PIN_CFG_PULL_DOWN) +#define GPIO_HAL_PIN_CFG_HYSTERESIS 0x10 + #define GPIO_HAL_PIN_CFG_EDGE_NONE 0x00 #define GPIO_HAL_PIN_CFG_EDGE_RISING 0x04 #define GPIO_HAL_PIN_CFG_EDGE_FALLING 0x08 @@ -187,7 +189,7 @@ void gpio_hal_event_handler(gpio_hal_pin_mask_t pins); * \param pin The pin * \return The corresponding mask */ -#define gpio_hal_pin_to_mask(pin) (1 << (pin)) +#define gpio_hal_pin_to_mask(pin) ((gpio_hal_pin_mask_t)1 << (pin)) /** @} */ /*---------------------------------------------------------------------------*/ /** @@ -233,6 +235,18 @@ void gpio_hal_event_handler(gpio_hal_pin_mask_t pins); #include GPIO_HAL_CONF_ARCH_HDR_PATH #endif /* GPIO_HAL_CONF_ARCH_HDR_PATH */ /*---------------------------------------------------------------------------*/ +#ifndef gpio_hal_arch_init +/** + * \brief Perform architecture specific gpio initaliaztion + * + * It is the platform developer's responsibility to provide an implementation. + * + * The implementation can be provided as a global symbol, an inline function + * or a function-like macro, as described above. + */ +void gpio_hal_arch_init(void); +#endif +/*---------------------------------------------------------------------------*/ #ifndef gpio_hal_arch_interrupt_enable /** * \brief Enable interrupts for a gpio pin diff --git a/os/dev/radio.h b/os/dev/radio.h index 982acc51d..e6ca64f3d 100644 --- a/os/dev/radio.h +++ b/os/dev/radio.h @@ -170,6 +170,9 @@ enum { * it needs to be used with radio.get_object()/set_object(). */ RADIO_PARAM_LAST_PACKET_TIMESTAMP, + /* For enabling and disabling the SHR search */ + RADIO_PARAM_SHR_SEARCH, + /* Constants (read only) */ /* The lowest radio channel. */ @@ -180,7 +183,14 @@ enum { /* The minimum transmission power in dBm. */ RADIO_CONST_TXPOWER_MIN, /* The maximum transmission power in dBm. */ - RADIO_CONST_TXPOWER_MAX + RADIO_CONST_TXPOWER_MAX, + + RADIO_CONST_TSCH_TIMING, + RADIO_CONST_PHY_OVERHEAD, + RADIO_CONST_BYTE_AIR_TIME, + RADIO_CONST_DELAY_BEFORE_TX, + RADIO_CONST_DELAY_BEFORE_RX, + RADIO_CONST_DELAY_BEFORE_DETECT, }; /* Radio power modes */ diff --git a/os/dev/spi.c b/os/dev/spi.c index c41cf206f..091cf8e51 100644 --- a/os/dev/spi.c +++ b/os/dev/spi.c @@ -43,7 +43,7 @@ #include /*---------------------------------------------------------------------------*/ spi_status_t -spi_acquire(spi_device_t *dev) +spi_acquire(const spi_device_t *dev) { if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; @@ -54,7 +54,7 @@ spi_acquire(spi_device_t *dev) } /*---------------------------------------------------------------------------*/ spi_status_t -spi_release(spi_device_t *dev) +spi_release(const spi_device_t *dev) { if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; @@ -65,19 +65,27 @@ spi_release(spi_device_t *dev) } /*---------------------------------------------------------------------------*/ spi_status_t -spi_select(spi_device_t *dev) +spi_select(const spi_device_t *dev) { - return spi_arch_select(dev); + if(!spi_arch_has_lock(dev)) { + return SPI_DEV_STATUS_BUS_NOT_OWNED; + } + + gpio_hal_arch_clear_pin(dev->pin_spi_cs); + + return SPI_DEV_STATUS_OK; } /*---------------------------------------------------------------------------*/ spi_status_t -spi_deselect(spi_device_t *dev) +spi_deselect(const spi_device_t *dev) { - return spi_arch_deselect(dev); + gpio_hal_arch_set_pin(dev->pin_spi_cs); + + return SPI_DEV_STATUS_OK; } /*---------------------------------------------------------------------------*/ bool -spi_has_bus(spi_device_t *dev) +spi_has_bus(const spi_device_t *dev) { if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return false; @@ -87,7 +95,7 @@ spi_has_bus(spi_device_t *dev) } /*---------------------------------------------------------------------------*/ spi_status_t -spi_write_byte(spi_device_t *dev, uint8_t data) +spi_write_byte(const spi_device_t *dev, uint8_t data) { if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; @@ -101,7 +109,7 @@ spi_write_byte(spi_device_t *dev, uint8_t data) } /*---------------------------------------------------------------------------*/ spi_status_t -spi_write(spi_device_t *dev, const uint8_t *data, int size) +spi_write(const spi_device_t *dev, const uint8_t *data, int size) { if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; @@ -115,7 +123,7 @@ spi_write(spi_device_t *dev, const uint8_t *data, int size) } /*---------------------------------------------------------------------------*/ spi_status_t -spi_read_byte(spi_device_t *dev, uint8_t *buf) +spi_read_byte(const spi_device_t *dev, uint8_t *buf) { if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; @@ -129,7 +137,7 @@ spi_read_byte(spi_device_t *dev, uint8_t *buf) } /*---------------------------------------------------------------------------*/ spi_status_t -spi_read(spi_device_t *dev, uint8_t *buf, int size) +spi_read(const spi_device_t *dev, uint8_t *buf, int size) { if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; @@ -143,7 +151,7 @@ spi_read(spi_device_t *dev, uint8_t *buf, int size) } /*---------------------------------------------------------------------------*/ spi_status_t -spi_read_skip(spi_device_t *dev, int size) +spi_read_skip(const spi_device_t *dev, int size) { if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; @@ -157,7 +165,7 @@ spi_read_skip(spi_device_t *dev, int size) } /*---------------------------------------------------------------------------*/ spi_status_t -spi_transfer(spi_device_t *dev, +spi_transfer(const spi_device_t *dev, const uint8_t *wdata, int wsize, uint8_t *rbuf, int rsize, int ignore) { @@ -181,7 +189,7 @@ spi_transfer(spi_device_t *dev, } /*---------------------------------------------------------------------------*/ spi_status_t -spi_read_register(spi_device_t *dev, uint8_t reg, uint8_t *data, int size) +spi_read_register(const spi_device_t *dev, uint8_t reg, uint8_t *data, int size) { spi_status_t status; if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { @@ -204,7 +212,7 @@ spi_read_register(spi_device_t *dev, uint8_t reg, uint8_t *data, int size) } /*---------------------------------------------------------------------------*/ spi_status_t -spi_strobe(spi_device_t *dev, uint8_t strobe, uint8_t *result) +spi_strobe(const spi_device_t *dev, uint8_t strobe, uint8_t *result) { if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; diff --git a/os/dev/spi.h b/os/dev/spi.h index 0c9aadc73..9dda05b8e 100644 --- a/os/dev/spi.h +++ b/os/dev/spi.h @@ -80,6 +80,7 @@ typedef enum { SPI_DEV_STATUS_OK, /* Everything OK */ SPI_DEV_STATUS_EINVAL, /* Erroneous input value */ + SPI_DEV_STATUS_TRANSFER_ERR, /* Error during SPI transfer */ SPI_DEV_STATUS_BUS_LOCKED, /* SPI bus is already locked */ SPI_DEV_STATUS_BUS_NOT_OWNED, /* SPI bus is locked by someone else */ SPI_DEV_STATUS_CLOSED /* SPI bus has not opened properly */ @@ -114,7 +115,7 @@ typedef struct spi_device { * to be locked and the opening configuration. * \return SPI return code */ -spi_status_t spi_acquire(spi_device_t *dev); +spi_status_t spi_acquire(const spi_device_t *dev); /** * \brief Closes and then unlocks an SPI controller @@ -126,7 +127,7 @@ spi_status_t spi_acquire(spi_device_t *dev); * This should work only if the device has already locked the SPI * controller. */ -spi_status_t spi_release(spi_device_t *dev); +spi_status_t spi_release(const spi_device_t *dev); /** * \brief Selects the SPI peripheral @@ -136,7 +137,7 @@ spi_status_t spi_release(spi_device_t *dev); * Clears the CS pin. This should work only if the device has * already locked the SPI controller. */ -spi_status_t spi_select(spi_device_t *dev); +spi_status_t spi_select(const spi_device_t *dev); /** * \brief Deselects the SPI peripheral @@ -145,14 +146,14 @@ spi_status_t spi_select(spi_device_t *dev); * * Sets the CS pin. Lock is not required. */ -spi_status_t spi_deselect(spi_device_t *dev); +spi_status_t spi_deselect(const spi_device_t *dev); /** * \brief Checks if a device has locked an SPI controller * \param dev An SPI device configuration which defines the controller. * \return true if the device has the lock, false otherwise. */ -bool spi_has_bus(spi_device_t *dev); +bool spi_has_bus(const spi_device_t *dev); /** * \brief Writes a single byte to an SPI device @@ -162,7 +163,7 @@ bool spi_has_bus(spi_device_t *dev); * * It should work only if the device has already locked the SPI controller. */ -spi_status_t spi_write_byte(spi_device_t *dev, uint8_t data); +spi_status_t spi_write_byte(const spi_device_t *dev, uint8_t data); /** * \brief Reads a single byte from an SPI device @@ -172,7 +173,7 @@ spi_status_t spi_write_byte(spi_device_t *dev, uint8_t data); * * It should work only if the device has already locked the SPI controller. */ -spi_status_t spi_read_byte(spi_device_t *dev, uint8_t *data); +spi_status_t spi_read_byte(const spi_device_t *dev, uint8_t *data); /** * \brief Writes a buffer to an SPI device @@ -183,7 +184,7 @@ spi_status_t spi_read_byte(spi_device_t *dev, uint8_t *data); * * It should work only if the device has already locked the SPI controller. */ -spi_status_t spi_write(spi_device_t *dev, +spi_status_t spi_write(const spi_device_t *dev, const uint8_t *data, int size); /** @@ -195,7 +196,7 @@ spi_status_t spi_write(spi_device_t *dev, * * It should work only if the device has already locked the SPI controller. */ -spi_status_t spi_read(spi_device_t *dev, uint8_t *data, int size); +spi_status_t spi_read(const spi_device_t *dev, uint8_t *data, int size); /** * \brief Reads and ignores data from an SPI device @@ -206,7 +207,7 @@ spi_status_t spi_read(spi_device_t *dev, uint8_t *data, int size); * Reads size bytes from the SPI and throws them away. * It should work only if the device has already locked the SPI controller. */ -spi_status_t spi_read_skip(spi_device_t *dev, int size); +spi_status_t spi_read_skip(const spi_device_t *dev, int size); /** * \brief Performs a generic SPI transfer @@ -225,7 +226,7 @@ spi_status_t spi_read_skip(spi_device_t *dev, int size); * be copied to buf. The remaining ignore_len bytes won't be copied to the * buffer. The maximum of wlen and rlen+ignore_len of bytes will be transfered. */ -spi_status_t spi_transfer(spi_device_t *dev, +spi_status_t spi_transfer(const spi_device_t *dev, const uint8_t *data, int wsize, uint8_t *buf, int rsize, int ignore); @@ -238,7 +239,7 @@ spi_status_t spi_transfer(spi_device_t *dev, * * It should work only if the device has already locked the SPI controller. */ -spi_status_t spi_strobe(spi_device_t *dev, uint8_t strobe, +spi_status_t spi_strobe(const spi_device_t *dev, uint8_t strobe, uint8_t *status); /** @@ -251,7 +252,7 @@ spi_status_t spi_strobe(spi_device_t *dev, uint8_t strobe, * * It should work only if the device has already locked the SPI controller. */ -spi_status_t spi_read_register(spi_device_t *dev, uint8_t reg, +spi_status_t spi_read_register(const spi_device_t *dev, uint8_t reg, uint8_t *data, int size); /*---------------------------------------------------------------------------*/ @@ -265,7 +266,7 @@ spi_status_t spi_read_register(spi_device_t *dev, uint8_t reg, * \return 1 if the device has the lock, 0 otherwise. * */ -bool spi_arch_has_lock(spi_device_t *dev); +bool spi_arch_has_lock(const spi_device_t *dev); /** * \brief Checks if an SPI controller is locked by any device @@ -274,7 +275,7 @@ bool spi_arch_has_lock(spi_device_t *dev); * \return 1 if the controller is locked, 0 otherwise. * */ -bool spi_arch_is_bus_locked(spi_device_t *dev); +bool spi_arch_is_bus_locked(const spi_device_t *dev); /** * \brief Locks and opens an SPI controller to the configuration specified. @@ -285,7 +286,7 @@ bool spi_arch_is_bus_locked(spi_device_t *dev); * controller. * */ -spi_status_t spi_arch_lock_and_open(spi_device_t *dev); +spi_status_t spi_arch_lock_and_open(const spi_device_t *dev); /** * \brief Closes and unlocks an SPI controller @@ -298,7 +299,7 @@ spi_status_t spi_arch_lock_and_open(spi_device_t *dev); * controller. * */ -spi_status_t spi_arch_close_and_unlock(spi_device_t *dev); +spi_status_t spi_arch_close_and_unlock(const spi_device_t *dev); /** * \brief Performs an SPI transfer @@ -317,30 +318,11 @@ spi_status_t spi_arch_close_and_unlock(spi_device_t *dev); * be copied to buf. The remaining ignore_len bytes won't be copied to the * buffer. The maximum of wlen and rlen+ignore_len of bytes will be transfered. */ -spi_status_t spi_arch_transfer(spi_device_t *dev, +spi_status_t spi_arch_transfer(const spi_device_t *dev, const uint8_t *data, int wlen, uint8_t *buf, int rlen, int ignore_len); -/** - * \brief Selects an SPI device - * \param dev An SPI device configuration that specifies the CS pin. - * \return SPI return code - * - * Clears the CS pin. It should work only if the device has already - * locked the SPI controller. - */ -spi_status_t spi_arch_select(spi_device_t *dev); - -/** - * \brief Deselects an SPI device - * \param dev An SPI device configuration that specifies the CS pin. - * \return SPI return code - * - * Set the CS pin. Locking the SPI controller is not needed. - */ -spi_status_t spi_arch_deselect(spi_device_t *dev); - #endif /* SPI_H_ */ /*---------------------------------------------------------------------------*/ /** diff --git a/os/lib/aes-128.c b/os/lib/aes-128.c index 98e115c3f..3b0082e7c 100644 --- a/os/lib/aes-128.c +++ b/os/lib/aes-128.c @@ -166,16 +166,6 @@ encrypt(uint8_t *state) } } /*---------------------------------------------------------------------------*/ -void -aes_128_set_padded_key(uint8_t *key, uint8_t key_len) -{ - uint8_t block[AES_128_BLOCK_SIZE]; - - memset(block, 0, AES_128_BLOCK_SIZE); - memcpy(block, key, key_len); - AES_128.set_key(block); -} -/*---------------------------------------------------------------------------*/ const struct aes_128_driver aes_128_driver = { set_key, encrypt diff --git a/os/lib/aes-128.h b/os/lib/aes-128.h index 458b93915..e003c2b25 100644 --- a/os/lib/aes-128.h +++ b/os/lib/aes-128.h @@ -67,11 +67,6 @@ struct aes_128_driver { void (* encrypt)(uint8_t *plaintext_and_result); }; -/** - * \brief Pads the key with zeroes before calling AES_128.set_key - */ -void aes_128_set_padded_key(uint8_t *key, uint8_t key_len); - extern const struct aes_128_driver AES_128; #endif /* AES_128_H_ */ diff --git a/os/lib/json/jsonparse.c b/os/lib/json/jsonparse.c index 6277b56c4..941420521 100644 --- a/os/lib/json/jsonparse.c +++ b/os/lib/json/jsonparse.c @@ -32,34 +32,42 @@ #include "jsonparse.h" #include #include +#include /*--------------------------------------------------------------------*/ -static int +static bool push(struct jsonparse_state *state, char c) { - state->stack[state->depth] = c; - state->depth++; - state->vtype = 0; - return state->depth < JSONPARSE_MAX_DEPTH; + if(state->depth < JSONPARSE_MAX_DEPTH) { + state->stack[state->depth] = c; + state->depth++; + state->vtype = 0; + return true; + } else { + return false; + } } /*--------------------------------------------------------------------*/ -static void +static bool modify(struct jsonparse_state *state, char c) { if(state->depth > 0) { state->stack[state->depth - 1] = c; + return true; + } else { + return false; } } /*--------------------------------------------------------------------*/ -static char +static bool pop(struct jsonparse_state *state) { if(state->depth == 0) { - return JSON_TYPE_ERROR; + return false; } state->depth--; state->vtype = state->stack[state->depth]; - return state->stack[state->depth]; + return true; } /*--------------------------------------------------------------------*/ /* will pass by the value and store the start and length of the value for @@ -134,15 +142,11 @@ skip_ws(struct jsonparse_state *state) } } /*--------------------------------------------------------------------*/ -static int +static bool is_atomic(struct jsonparse_state *state) { char v = state->vtype; - if(v == 'N' || v == '"' || v == '0' || v == 'n' || v == 't' || v == 'f') { - return 1; - } else { - return 0; - } + return v == 'N' || v == '"' || v == '0' || v == 'n' || v == 't' || v == 'f'; } /*--------------------------------------------------------------------*/ void @@ -163,6 +167,7 @@ jsonparse_next(struct jsonparse_state *state) char c; char s; char v; + bool ret; skip_ws(state); c = state->json[state->pos]; @@ -173,48 +178,51 @@ jsonparse_next(struct jsonparse_state *state) switch(c) { case '{': if((s == 0 && v == 0) || s == '[' || s == ':') { - push(state, c); - } else { - state->error = JSON_ERROR_UNEXPECTED_OBJECT; - return JSON_TYPE_ERROR; + if(push(state, c)) { + return c; + } } - return c; + state->error = JSON_ERROR_UNEXPECTED_OBJECT; + return JSON_TYPE_ERROR; case '}': if((s == ':' && v != ',' && v != 0 ) || (s == '{' && v == 0)) { - pop(state); - } else { - state->error = JSON_ERROR_UNEXPECTED_END_OF_OBJECT; - return JSON_TYPE_ERROR; + if(pop(state)) { + return c; + } } - return c; + state->error = JSON_ERROR_UNEXPECTED_END_OF_OBJECT; + return JSON_TYPE_ERROR; case ']': if(s == '[' && v != ',') { - pop(state); - } else { - state->error = JSON_ERROR_UNEXPECTED_END_OF_ARRAY; - return JSON_TYPE_ERROR; + if(pop(state)) { + return c; + } } - return c; + state->error = JSON_ERROR_UNEXPECTED_END_OF_ARRAY; + return JSON_TYPE_ERROR; case ':': if(s == '{' && v == 'N') { - modify(state, ':'); + ret = modify(state, ':'); state->vtype = 0; - } else { - state->error = JSON_ERROR_SYNTAX; - return JSON_TYPE_ERROR; + if(ret) { + return jsonparse_next(state); + } } - return jsonparse_next(state); + state->error = JSON_ERROR_SYNTAX; + return JSON_TYPE_ERROR; case ',': if(s == ':' && v != 0) { - modify(state, '{'); + ret = modify(state, '{'); state->vtype = c; + if(ret) { + return c; + } } else if(s == '[') { state->vtype = c; - } else { - state->error = JSON_ERROR_SYNTAX; - return JSON_TYPE_ERROR; + return c; } - return c; + state->error = JSON_ERROR_SYNTAX; + return JSON_TYPE_ERROR; case '"': if((s == 0 && v == 0) || s == '{' || s == '[' || s == ':') { return atomic(state, c = (s == '{' ? JSON_TYPE_PAIR_NAME : c)); @@ -225,12 +233,12 @@ jsonparse_next(struct jsonparse_state *state) return c; case '[': if((s == 0 && v == 0) || s == '[' || s == ':') { - push(state, c); - } else { - state->error = JSON_ERROR_UNEXPECTED_ARRAY; - return JSON_TYPE_ERROR; + if(push(state, c)) { + return c; + } } - return c; + state->error = JSON_ERROR_UNEXPECTED_ARRAY; + return JSON_TYPE_ERROR; case 0: if(v == 0 || state->depth > 0) { state->error = JSON_ERROR_SYNTAX; diff --git a/os/lib/json/jsontree.c b/os/lib/json/jsontree.c index 13d7d8604..259525376 100644 --- a/os/lib/json/jsontree.c +++ b/os/lib/json/jsontree.c @@ -198,7 +198,10 @@ jsontree_print_next(struct jsontree_context *js_ctx) } else { ov = o->values[index]; } - /* TODO check max depth */ + if(js_ctx->depth >= JSONTREE_MAX_DEPTH - 1) { + /* Too deep: return 0 */ + return 0; + } js_ctx->depth++; /* step down to value... */ js_ctx->index[js_ctx->depth] = 0; /* and init index */ js_ctx->values[js_ctx->depth] = ov; @@ -299,7 +302,10 @@ find_next(struct jsontree_context *js_ctx) } else { ov = o->values[index]; } - /* TODO check max depth */ + if(js_ctx->depth >= JSONTREE_MAX_DEPTH - 1) { + /* Too deep: return NULL */ + return NULL; + } js_ctx->depth++; /* step down to value... */ js_ctx->index[js_ctx->depth] = 0; /* and init index */ js_ctx->values[js_ctx->depth] = ov; diff --git a/os/lib/list.c b/os/lib/list.c index afa9df585..9eaf1945e 100644 --- a/os/lib/list.c +++ b/os/lib/list.c @@ -324,4 +324,26 @@ list_item_next(void *item) return item == NULL ? NULL : ((struct list *)item)->next; } /*---------------------------------------------------------------------------*/ +/** + * \brief Check if the list contains an item + * \param list The list that is checked + * \param item An item to look for in the list + * \returns 0 if the list does not contains the item, and 1 otherwise + * + * This function searches for an item in the list and returns + * 0 if the list does not contain the item, and 1 if the item + * is present in the list. + */ +bool +list_contains(list_t list, void *item) +{ + struct list *l; + for(l = *list; l != NULL; l = l->next) { + if(item == l) { + return true; + } + } + return false; +} +/*---------------------------------------------------------------------------*/ /** @} */ diff --git a/os/lib/list.h b/os/lib/list.h index 7d3ff43d3..af0136435 100644 --- a/os/lib/list.h +++ b/os/lib/list.h @@ -66,6 +66,8 @@ #ifndef LIST_H_ #define LIST_H_ +#include + #define LIST_CONCAT2(s1, s2) s1##s2 #define LIST_CONCAT(s1, s2) LIST_CONCAT2(s1, s2) @@ -151,6 +153,8 @@ void list_insert(list_t list, void *previtem, void *newitem); void * list_item_next(void *item); +bool list_contains(list_t list, void *item); + #endif /* LIST_H_ */ /** @} */ diff --git a/os/net/app-layer/coap/coap-blocking-api.c b/os/net/app-layer/coap/coap-blocking-api.c index 1be7cbe7c..9fd691d74 100644 --- a/os/net/app-layer/coap/coap-blocking-api.c +++ b/os/net/app-layer/coap/coap-blocking-api.c @@ -60,37 +60,36 @@ void coap_blocking_request_callback(void *callback_data, coap_message_t *response) { - coap_request_state_t *state = (coap_request_state_t *)callback_data; + coap_blocking_request_state_t *blocking_state = (coap_blocking_request_state_t *)callback_data; - state->response = response; - process_poll(state->process); + blocking_state->state.response = response; + process_poll(blocking_state->process); } /*---------------------------------------------------------------------------*/ PT_THREAD(coap_blocking_request - (coap_request_state_t *state, process_event_t ev, + (coap_blocking_request_state_t *blocking_state, process_event_t ev, coap_endpoint_t *remote_ep, coap_message_t *request, coap_blocking_response_handler_t request_callback)) { - PT_BEGIN(&state->pt); + /* Before PT_BEGIN in order to not be a local variable in the PT_Thread and maintain it */ + coap_request_state_t *state = &blocking_state->state; - static uint32_t res_block; - static uint8_t more; - static uint8_t block_error; + PT_BEGIN(&blocking_state->pt); state->block_num = 0; state->response = NULL; - state->process = PROCESS_CURRENT(); + blocking_state->process = PROCESS_CURRENT(); - more = 0; - res_block = 0; - block_error = 0; + state->more = 0; + state->res_block = 0; + state->block_error = 0; do { request->mid = coap_get_mid(); if((state->transaction = coap_new_transaction(request->mid, remote_ep))) { state->transaction->callback = coap_blocking_request_callback; - state->transaction->callback_data = state; + state->transaction->callback_data = blocking_state; if(state->block_num > 0) { coap_set_header_block2(request, state->block_num, 0, @@ -104,33 +103,46 @@ PT_THREAD(coap_blocking_request coap_send_transaction(state->transaction); LOG_DBG("Requested #%"PRIu32" (MID %u)\n", state->block_num, request->mid); - PT_YIELD_UNTIL(&state->pt, ev == PROCESS_EVENT_POLL); + PT_YIELD_UNTIL(&blocking_state->pt, ev == PROCESS_EVENT_POLL); if(!state->response) { LOG_WARN("Server not responding\n"); - PT_EXIT(&state->pt); + state->status = COAP_REQUEST_STATUS_TIMEOUT; + PT_EXIT(&blocking_state->pt); } - coap_get_header_block2(state->response, &res_block, &more, NULL, NULL); + coap_get_header_block2(state->response, &state->res_block, &state->more, NULL, NULL); - LOG_DBG("Received #%"PRIu32"%s (%u bytes)\n", res_block, more ? "+" : "", + LOG_DBG("Received #%"PRIu32"%s (%u bytes)\n", state->res_block, state->more ? "+" : "", state->response->payload_len); + if(state->more) { + state->status = COAP_REQUEST_STATUS_MORE; + } else { + state->status = COAP_REQUEST_STATUS_RESPONSE; + } - if(res_block == state->block_num) { + if(state->res_block == state->block_num) { request_callback(state->response); ++(state->block_num); } else { LOG_WARN("WRONG BLOCK %"PRIu32"/%"PRIu32"\n", - res_block, state->block_num); - ++block_error; + state->res_block, state->block_num); + ++(state->block_error); } } else { LOG_WARN("Could not allocate transaction buffer"); - PT_EXIT(&state->pt); + PT_EXIT(&blocking_state->pt); } - } while(more && block_error < COAP_MAX_ATTEMPTS); + } while(state->more && (state->block_error) < COAP_MAX_ATTEMPTS); - PT_END(&state->pt); + if((state->block_error) >= COAP_MAX_ATTEMPTS) { + /* failure - now we give up */ + state->status = COAP_REQUEST_STATUS_BLOCK_ERROR; + } else { + /* No more blocks, request finished */ + state->status = COAP_REQUEST_STATUS_FINISHED; + } + PT_END(&blocking_state->pt); } /*---------------------------------------------------------------------------*/ /** @} */ diff --git a/os/net/app-layer/coap/coap-blocking-api.h b/os/net/app-layer/coap/coap-blocking-api.h index d9a916c04..716a261b5 100644 --- a/os/net/app-layer/coap/coap-blocking-api.h +++ b/os/net/app-layer/coap/coap-blocking-api.h @@ -39,31 +39,30 @@ #include "sys/pt.h" #include "coap-transactions.h" +#include "coap-request-state.h" /*---------------------------------------------------------------------------*/ /*- Client Part -------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/ -typedef struct coap_request_state { +typedef struct coap_blocking_request_state { + coap_request_state_t state; struct pt pt; struct process *process; - coap_transaction_t *transaction; - coap_message_t *response; - uint32_t block_num; -} coap_request_state_t; +} coap_blocking_request_state_t; typedef void (* coap_blocking_response_handler_t)(coap_message_t *response); PT_THREAD(coap_blocking_request - (coap_request_state_t *state, process_event_t ev, + (coap_blocking_request_state_t *blocking_state, process_event_t ev, coap_endpoint_t *remote, coap_message_t *request, coap_blocking_response_handler_t request_callback)); #define COAP_BLOCKING_REQUEST(server_endpoint, request, chunk_handler) \ { \ - static coap_request_state_t request_state; \ - PT_SPAWN(process_pt, &request_state.pt, \ - coap_blocking_request(&request_state, ev, \ + static coap_blocking_request_state_t blocking_state; \ + PT_SPAWN(process_pt, &blocking_state.pt, \ + coap_blocking_request(&blocking_state, ev, \ server_endpoint, \ request, chunk_handler) \ ); \ diff --git a/os/net/app-layer/coap/coap-callback-api.c b/os/net/app-layer/coap/coap-callback-api.c index b1b05597e..74585ccb3 100644 --- a/os/net/app-layer/coap/coap-callback-api.c +++ b/os/net/app-layer/coap/coap-callback-api.c @@ -48,25 +48,20 @@ #include "sys/cc.h" #include #include +#include /* Log configuration */ #include "coap-log.h" #define LOG_MODULE "coap" #define LOG_LEVEL LOG_LEVEL_COAP -/* These should go into the state struct so that we can have multiple - requests */ - -static uint32_t res_block; -static uint8_t more; -static uint8_t block_error; - static void coap_request_callback(void *callback_data, coap_message_t *response); /*---------------------------------------------------------------------------*/ -static void -progress_request(coap_request_state_t *state) { +static int +progress_request(coap_callback_request_state_t *callback_state) { + coap_request_state_t *state = &callback_state->state; coap_message_t *request = state->request; request->mid = coap_get_mid(); if((state->transaction = @@ -83,7 +78,9 @@ progress_request(coap_request_state_t *state) { coap_send_transaction(state->transaction); LOG_DBG("Requested #%"PRIu32" (MID %u)\n", state->block_num, request->mid); + return 1; } + return 0; } /*---------------------------------------------------------------------------*/ @@ -91,7 +88,9 @@ progress_request(coap_request_state_t *state) { static void coap_request_callback(void *callback_data, coap_message_t *response) { - coap_request_state_t *state = (coap_request_state_t *)callback_data; + coap_callback_request_state_t *callback_state = (coap_callback_request_state_t*)callback_data; + coap_request_state_t *state = &callback_state->state; + uint32_t res_block1; state->response = response; @@ -100,58 +99,70 @@ coap_request_callback(void *callback_data, coap_message_t *response) if(!state->response) { LOG_WARN("Server not responding giving up...\n"); - state->callback(state); + state->status = COAP_REQUEST_STATUS_TIMEOUT; + callback_state->callback(callback_state); return; } /* Got a response */ - coap_get_header_block2(state->response, &res_block, &more, NULL, NULL); + coap_get_header_block2(state->response, &state->res_block, &state->more, NULL, NULL); coap_get_header_block1(state->response, &res_block1, NULL, NULL, NULL); LOG_DBG("Received #%lu%s B1:%lu (%u bytes)\n", - (unsigned long)res_block, (unsigned)more ? "+" : "", + (unsigned long)state->res_block, (unsigned)state->more ? "+" : "", (unsigned long)res_block1, state->response->payload_len); - if(res_block == state->block_num) { + if(state->res_block == state->block_num) { /* Call the callback function as we have more data */ - state->callback(state); + if(state->more) { + state->status = COAP_REQUEST_STATUS_MORE; + } else { + state->status = COAP_REQUEST_STATUS_RESPONSE; + } + callback_state->callback(callback_state); /* this is only for counting BLOCK2 blocks.*/ ++(state->block_num); } else { - LOG_WARN("WRONG BLOCK %"PRIu32"/%"PRIu32"\n", res_block, state->block_num); - ++block_error; + LOG_WARN("WRONG BLOCK %"PRIu32"/%"PRIu32"\n", state->res_block, state->block_num); + ++(state->block_error); } - if(more && block_error < COAP_MAX_ATTEMPTS) { - progress_request(state); + if(state->more) { + if((state->block_error) < COAP_MAX_ATTEMPTS) { + progress_request(callback_state); + } else { + /* failure - now we give up and notify the callback */ + state->status = COAP_REQUEST_STATUS_BLOCK_ERROR; + callback_state->callback(callback_state); + } } else { - /* failure - now we give up and notify the callback */ + /* No more blocks, finish and notify the callback */ + state->status = COAP_REQUEST_STATUS_FINISHED; state->response = NULL; - state->callback(state); + callback_state->callback(callback_state); } } /*---------------------------------------------------------------------------*/ -void -coap_send_request(coap_request_state_t *state, coap_endpoint_t *endpoint, +int +coap_send_request(coap_callback_request_state_t *callback_state, coap_endpoint_t *endpoint, coap_message_t *request, - void (*callback)(coap_request_state_t *state)) + void (*callback)(coap_callback_request_state_t *callback_state)) { - /* can we have these variables shared between multiple requests? */ - /* ripped from blocking request */ - more = 0; - res_block = 0; - block_error = 0; + coap_request_state_t *state = &callback_state->state; + state->more = 0; + state->res_block = 0; + state->block_error = 0; state->block_num = 0; state->response = NULL; state->request = request; state->remote_endpoint = endpoint; - state->callback = callback; + callback_state->callback = callback; - progress_request(state); + return progress_request(callback_state); } /*---------------------------------------------------------------------------*/ /** @} */ diff --git a/os/net/app-layer/coap/coap-callback-api.h b/os/net/app-layer/coap/coap-callback-api.h index 6de7ab587..a9019aeb8 100644 --- a/os/net/app-layer/coap/coap-callback-api.h +++ b/os/net/app-layer/coap/coap-callback-api.h @@ -47,27 +47,30 @@ #include "coap-engine.h" #include "coap-transactions.h" +#include "coap-request-state.h" #include "sys/cc.h" /*---------------------------------------------------------------------------*/ /*- Client Part -------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/ -typedef struct coap_request_state coap_request_state_t; +typedef struct coap_callback_request_state coap_callback_request_state_t; -struct coap_request_state { - coap_transaction_t *transaction; - coap_message_t *response; - coap_message_t *request; - coap_endpoint_t *remote_endpoint; - uint32_t block_num; - void *user_data; - coap_timer_t coap_timer; - void (*callback)(coap_request_state_t *state); +struct coap_callback_request_state { + coap_request_state_t state; + void (*callback)(coap_callback_request_state_t *state); }; -void coap_send_request(coap_request_state_t *state, coap_endpoint_t *endpoint, +/** + * \brief Send a CoAP request to a remote endpoint + * \param callback_state The callback state to handle the CoAP request + * \param endpoint The destination endpoint + * \param request The request to be sent + * \param callback callback to execute when the response arrives or the timeout expires + * \return 1 if there is a transaction available to send, 0 otherwise + */ +int coap_send_request(coap_callback_request_state_t *callback_state, coap_endpoint_t *endpoint, coap_message_t *request, - void (*callback)(coap_request_state_t *state)); + void (*callback)(coap_callback_request_state_t *callback_state)); #endif /* COAP_CALLBACK_API_H_ */ /** @} */ diff --git a/os/net/app-layer/coap/coap-conf.h b/os/net/app-layer/coap/coap-conf.h index 911017ed8..5b610dca3 100644 --- a/os/net/app-layer/coap/coap-conf.h +++ b/os/net/app-layer/coap/coap-conf.h @@ -99,7 +99,9 @@ #endif /* COAP_MAX_OBSERVERS */ /* Interval in notifies in which NON notifies are changed to CON notifies to check client. */ -#ifndef COAP_OBSERVE_REFRESH_INTERVAL +#ifdef COAP_CONF_OBSERVE_REFRESH_INTERVAL +#define COAP_OBSERVE_REFRESH_INTERVAL COAP_CONF_OBSERVE_REFRESH_INTERVAL +#else #define COAP_OBSERVE_REFRESH_INTERVAL 20 #endif /* COAP_OBSERVE_REFRESH_INTERVAL */ diff --git a/os/net/app-layer/coap/coap-engine.c b/os/net/app-layer/coap/coap-engine.c index cbfa70ee9..474826c1c 100644 --- a/os/net/app-layer/coap/coap-engine.c +++ b/os/net/app-layer/coap/coap-engine.c @@ -371,7 +371,6 @@ coap_engine_init(void) { /* avoid initializing twice */ if(is_initialized) { - LOG_DBG("already running - double initialization?\n"); return; } is_initialized = 1; diff --git a/os/net/app-layer/coap/coap-observe.c b/os/net/app-layer/coap/coap-observe.c index 83f5edf4a..3574acac4 100644 --- a/os/net/app-layer/coap/coap-observe.c +++ b/os/net/app-layer/coap/coap-observe.c @@ -244,7 +244,9 @@ coap_notify_observers_sub(coap_resource_t *resource, const char *subpath) /*TODO implement special transaction for CON, sharing the same buffer to allow for more observers */ if((transaction = coap_new_transaction(coap_get_mid(), &obs->endpoint))) { - if(obs->obs_counter % COAP_OBSERVE_REFRESH_INTERVAL == 0) { + /* if COAP_OBSERVE_REFRESH_INTERVAL is zero, never send observations as confirmable messages */ + if(COAP_OBSERVE_REFRESH_INTERVAL != 0 + && (obs->obs_counter % COAP_OBSERVE_REFRESH_INTERVAL == 0)) { LOG_DBG(" Force Confirmable for\n"); notification->type = COAP_TYPE_CON; } @@ -353,4 +355,18 @@ coap_observe_handler(coap_resource_t *resource, coap_message_t *coap_req, } } /*---------------------------------------------------------------------------*/ +uint8_t +coap_has_observers(char *path) +{ + coap_observer_t *obs = NULL; + + for(obs = (coap_observer_t *)list_head(observers_list); obs; + obs = obs->next) { + if((strncmp(obs->url, path, strlen(path))) == 0) { + return 1; + } + } + return 0; +} +/*---------------------------------------------------------------------------*/ /** @} */ diff --git a/os/net/app-layer/coap/coap-observe.h b/os/net/app-layer/coap/coap-observe.h index c276522c5..93898f954 100644 --- a/os/net/app-layer/coap/coap-observe.h +++ b/os/net/app-layer/coap/coap-observe.h @@ -80,5 +80,7 @@ void coap_notify_observers_sub(coap_resource_t *resource, const char *subpath); void coap_observe_handler(coap_resource_t *resource, coap_message_t *request, coap_message_t *response); +uint8_t coap_has_observers(char *path); + #endif /* COAP_OBSERVE_H_ */ /** @} */ diff --git a/os/net/app-layer/coap/coap-request-state.h b/os/net/app-layer/coap/coap-request-state.h new file mode 100644 index 000000000..4c5881bb6 --- /dev/null +++ b/os/net/app-layer/coap/coap-request-state.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2018, RISE SICS AB. + * 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 HOLDER 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. + */ + +/** + * \addtogroup coap + * @{ + */ + +/** + * \file + * Common request state for all the APIs + * \author + * Carlos Gonzalo Peces + */ +#ifndef COAP_REQUEST_STATE_H_ +#define COAP_REQUEST_STATE_H_ + +typedef enum { + COAP_REQUEST_STATUS_RESPONSE, /* Response received and no more blocks */ + COAP_REQUEST_STATUS_MORE, /* Response received and there are more blocks */ + COAP_REQUEST_STATUS_FINISHED, /* Request finished */ + COAP_REQUEST_STATUS_TIMEOUT, /* Request Timeout after all retransmissions */ + COAP_REQUEST_STATUS_BLOCK_ERROR /* Blocks in wrong order */ +} coap_request_status_t; + + +typedef struct coap_request_state { + coap_transaction_t *transaction; + coap_message_t *response; + coap_message_t *request; + coap_endpoint_t *remote_endpoint; + uint32_t block_num; + uint32_t res_block; + uint8_t more; + uint8_t block_error; + void *user_data; + coap_request_status_t status; +} coap_request_state_t; + + +#endif /* COAP_REQUEST_STATE_H_ */ +/** @} */ diff --git a/os/net/app-layer/coap/coap-transactions.c b/os/net/app-layer/coap/coap-transactions.c index 7e34d22e4..a62e8d21f 100644 --- a/os/net/app-layer/coap/coap-transactions.c +++ b/os/net/app-layer/coap/coap-transactions.c @@ -98,12 +98,11 @@ coap_send_transaction(coap_transaction_t *t) { LOG_DBG("Sending transaction %u\n", t->mid); - coap_sendto(&t->endpoint, t->message, t->message_len); - if(COAP_TYPE_CON == ((COAP_HEADER_TYPE_MASK & t->message[0]) >> COAP_HEADER_TYPE_POSITION)) { - if(t->retrans_counter < COAP_MAX_RETRANSMIT) { + if(t->retrans_counter <= COAP_MAX_RETRANSMIT) { /* not timed out yet */ + coap_sendto(&t->endpoint, t->message, t->message_len); LOG_DBG("Keeping transaction %u\n", t->mid); if(t->retrans_counter == 0) { @@ -138,6 +137,7 @@ coap_send_transaction(coap_transaction_t *t) } } } else { + coap_sendto(&t->endpoint, t->message, t->message_len); coap_clear_transaction(t); } } diff --git a/os/net/app-layer/coap/coap-uip.c b/os/net/app-layer/coap/coap-uip.c index 8db2bbbbf..e2be92326 100644 --- a/os/net/app-layer/coap/coap-uip.c +++ b/os/net/app-layer/coap/coap-uip.c @@ -49,6 +49,7 @@ #include "contiki.h" #include "net/ipv6/uip-udp-packet.h" #include "net/ipv6/uiplib.h" +#include "net/routing/routing.h" #include "coap.h" #include "coap-engine.h" #include "coap-endpoint.h" @@ -58,10 +59,6 @@ #include "coap-keystore.h" #include "coap-keystore-simple.h" -#if UIP_CONF_IPV6_RPL -#include "rpl.h" -#endif /* UIP_CONF_IPV6_RPL */ - /* Log configuration */ #include "coap-log.h" #define LOG_MODULE "coap-uip" @@ -214,30 +211,27 @@ coap_endpoint_parse(const char *text, size_t size, coap_endpoint_t *ep) /* Only IPv6 supported */ int start = index_of(text, 0, size, '['); int end = index_of(text, start, size, ']'); - int secure = strncmp((const char *)text, "coaps:", 6) == 0; uint32_t port; - if(start > 0 && end > start && - uiplib_ipaddrconv((const char *)&text[start], &ep->ipaddr)) { + + ep->secure = strncmp(text, "coaps:", 6) == 0; + if(start >= 0 && end > start && + uiplib_ipaddrconv(&text[start], &ep->ipaddr)) { if(text[end + 1] == ':' && get_port(text + end + 2, size - end - 2, &port)) { ep->port = UIP_HTONS(port); - } else if(secure) { - /** - * Secure CoAP should use a different port but for now - * the same port is used. - */ - LOG_DBG("Using secure port (coaps)\n"); + } else if(ep->secure) { + /* Use secure CoAP port by default for secure endpoints. */ ep->port = SERVER_LISTEN_SECURE_PORT; - ep->secure = 1; } else { ep->port = SERVER_LISTEN_PORT; - ep->secure = 0; } return 1; - } else { - if(uiplib_ipaddrconv((const char *)&text, &ep->ipaddr)) { + } else if(size < UIPLIB_IPV6_MAX_STR_LEN) { + char buf[UIPLIB_IPV6_MAX_STR_LEN]; + memcpy(buf, text, size); + buf[size] = '\0'; + if(uiplib_ipaddrconv(buf, &ep->ipaddr)) { ep->port = SERVER_LISTEN_PORT; - ep->secure = 0; return 1; } } @@ -263,13 +257,12 @@ coap_endpoint_is_secure(const coap_endpoint_t *ep) int coap_endpoint_is_connected(const coap_endpoint_t *ep) { -#if UIP_CONF_IPV6_RPL #ifndef CONTIKI_TARGET_NATIVE - if(rpl_get_any_dag() == NULL) { + if(!uip_is_addr_linklocal(&ep->ipaddr) + && NETSTACK_ROUTING.node_is_reachable() == 0) { return 0; } #endif -#endif /* UIP_CONF_IPV6_RPL */ #ifdef WITH_DTLS if(ep != NULL && ep->secure != 0) { diff --git a/os/net/app-layer/coap/coap.c b/os/net/app-layer/coap/coap.c index c28e2d8b5..8bc2f90f9 100644 --- a/os/net/app-layer/coap/coap.c +++ b/os/net/app-layer/coap/coap.c @@ -47,6 +47,7 @@ #include #include +#include #include "sys/cc.h" #include "coap.h" diff --git a/os/net/app-layer/coap/module-macros.h b/os/net/app-layer/coap/module-macros.h new file mode 100644 index 000000000..053040e50 --- /dev/null +++ b/os/net/app-layer/coap/module-macros.h @@ -0,0 +1 @@ +#define BUILD_WITH_COAP 1 diff --git a/os/net/app-layer/mqtt/mqtt.c b/os/net/app-layer/mqtt/mqtt.c index 46a542c3f..9571244d8 100644 --- a/os/net/app-layer/mqtt/mqtt.c +++ b/os/net/app-layer/mqtt/mqtt.c @@ -872,6 +872,7 @@ parse_publish_vhdr(struct mqtt_connection *conn, /* Read out topic length */ if(conn->in_packet.topic_len_received == 0) { + conn->in_packet.topic_pos = 0; conn->in_packet.topic_len = (input_data_ptr[(*pos)++] << 8); conn->in_packet.byte_counter++; if(*pos >= input_data_len) { @@ -880,7 +881,11 @@ parse_publish_vhdr(struct mqtt_connection *conn, conn->in_packet.topic_len |= input_data_ptr[(*pos)++]; conn->in_packet.byte_counter++; conn->in_packet.topic_len_received = 1; - + /* Abort if topic is longer than our topic buffer */ + if(conn->in_packet.topic_len > MQTT_MAX_TOPIC_LENGTH) { + DBG("MQTT - topic too long %u/%u\n", conn->in_packet.topic_len, MQTT_MAX_TOPIC_LENGTH); + return; + } DBG("MQTT - Read PUBLISH topic len %i\n", conn->in_packet.topic_len); /* WARNING: Check here if TOPIC fits in payload area, otherwise error */ } diff --git a/os/net/ipv6/multicast/esmrf.c b/os/net/ipv6/multicast/esmrf.c index 00619c354..5b6f1b863 100644 --- a/os/net/ipv6/multicast/esmrf.c +++ b/os/net/ipv6/multicast/esmrf.c @@ -376,7 +376,9 @@ in() static void init() { - UIP_MCAST6_STATS_INIT(NULL); + ESMRF_STATS_INIT(); + UIP_MCAST6_STATS_INIT(&stats); + uip_mcast6_route_init(); /* Register the ICMPv6 input handler */ uip_icmp6_register_input_handler(&esmrf_icmp_handler); diff --git a/os/net/ipv6/multicast/esmrf.h b/os/net/ipv6/multicast/esmrf.h index a44a87396..15857a1d4 100644 --- a/os/net/ipv6/multicast/esmrf.h +++ b/os/net/ipv6/multicast/esmrf.h @@ -68,16 +68,9 @@ /* Stats datatype */ /*---------------------------------------------------------------------------*/ struct esmrf_stats { - uint16_t mcast_in_unique; - uint16_t mcast_in_all; /* At layer 3 */ - uint16_t mcast_in_ours; /* Unique and we are a group member */ - uint16_t mcast_fwd; /* Forwarded by us but we are not the seed */ - uint16_t mcast_out; /* We are the seed */ - uint16_t mcast_bad; - uint16_t mcast_dropped; uint16_t icmp_out; uint16_t icmp_in; uint16_t icmp_bad; }; - +/*---------------------------------------------------------------------------*/ #endif /* ESMRF_H_ */ diff --git a/os/net/ipv6/multicast/smrf.h b/os/net/ipv6/multicast/smrf.h index bbe7e5e26..d69aa73a5 100644 --- a/os/net/ipv6/multicast/smrf.h +++ b/os/net/ipv6/multicast/smrf.h @@ -70,18 +70,6 @@ #define SMRF_MAX_SPREAD 4 #endif /*---------------------------------------------------------------------------*/ -/* Stats datatype */ -/*---------------------------------------------------------------------------*/ -struct smrf_stats { - uint16_t mcast_in_unique; - uint16_t mcast_in_all; /* At layer 3 */ - uint16_t mcast_in_ours; /* Unique and we are a group member */ - uint16_t mcast_fwd; /* Forwarded by us but we are not the seed */ - uint16_t mcast_out; /* We are the seed */ - uint16_t mcast_bad; - uint16_t mcast_dropped; -}; -/*---------------------------------------------------------------------------*/ #endif /* SMRF_H_ */ /*---------------------------------------------------------------------------*/ /** @} */ diff --git a/os/net/ipv6/resolv.c b/os/net/ipv6/resolv.c index f75a084a9..2bcd3983b 100644 --- a/os/net/ipv6/resolv.c +++ b/os/net/ipv6/resolv.c @@ -1017,7 +1017,8 @@ newdata(void) namemapptr->state = STATE_DONE; #if RESOLV_SUPPORTS_RECORD_EXPIRATION - namemapptr->expiration = ans->ttl[1] + (ans->ttl[0] << 8); + namemapptr->expiration = (uint32_t) uip_ntohs(ans->ttl[0]) << 16 | + (uint32_t) uip_ntohs(ans->ttl[1]); namemapptr->expiration += clock_seconds(); #endif /* RESOLV_SUPPORTS_RECORD_EXPIRATION */ diff --git a/os/net/ipv6/sicslowpan.c b/os/net/ipv6/sicslowpan.c index 4e3e4e00c..9e4e3a8b4 100644 --- a/os/net/ipv6/sicslowpan.c +++ b/os/net/ipv6/sicslowpan.c @@ -140,13 +140,13 @@ #define MAC_MAX_PAYLOAD (127 - 2) #endif /* SICSLOWPAN_CONF_MAC_MAX_PAYLOAD */ -/** \brief Fixed size of a frame header. This value is - * used in case framer returns an error or if SICSLOWPAN_USE_FIXED_HDRLEN - * is defined. - */ -#ifndef SICSLOWPAN_FIXED_HDRLEN -#define SICSLOWPAN_FIXED_HDRLEN 21 -#endif +/** \brief Maximum size of a frame header. This value is + * used in case framer returns an error */ +#ifdef SICSLOWPAN_CONF_MAC_MAX_HEADER +#define MAC_MAX_HEADER SICSLOWPAN_CONF_MAC_MAX_HEADER +#else /* SICSLOWPAN_CONF_MAC_MAX_HEADER */ +#define MAC_MAX_HEADER 21 +#endif /* SICSLOWPAN_CONF_MAC_MAX_HEADER */ /* set this to zero if not compressing EXT_HDR - for backwards compatibility */ #ifdef SICSLOWPAN_CONF_COMPRESS_EXT_HDR @@ -336,8 +336,6 @@ store_fragment(uint8_t index, uint8_t offset) frag_buf[i].index = index; memcpy(frag_buf[i].data, packetbuf_ptr + packetbuf_hdr_len, packetbuf_datalen() - packetbuf_hdr_len); - - LOG_INFO("Fragsize: %d\n", frag_buf[i].len); /* return the length of the stored fragment */ return frag_buf[i].len; } @@ -371,7 +369,7 @@ add_fragment(uint16_t tag, uint16_t frag_size, uint8_t offset) } if(found < 0) { - LOG_WARN("*** Failed to store new fragment session - tag: %d\n", tag); + LOG_WARN("reassembly: failed to store new fragment session - tag: %d\n", tag); return -1; } @@ -398,7 +396,7 @@ add_fragment(uint16_t tag, uint16_t frag_size, uint8_t offset) if(found < 0) { /* no entry found for storing the new fragment */ - LOG_WARN("*** Failed to store N-fragment - could not find session - tag: %d offset: %d\n", tag, offset); + LOG_WARN("reassembly: failed to store N-fragment - could not find session - tag: %d offset: %d\n", tag, offset); return -1; } @@ -413,7 +411,7 @@ add_fragment(uint16_t tag, uint16_t frag_size, uint8_t offset) } else { /* should we also clear all fragments since we failed to store this fragment? */ - LOG_WARN("*** Failed to store fragment - packet reassembly will fail tag:%d l\n", frag_info[i].tag); + LOG_WARN("reassembly: failed to store fragment - packet reassembly will fail tag:%d l\n", frag_info[i].tag); return -1; } } @@ -610,7 +608,7 @@ uncompress_addr(uip_ipaddr_t *ipaddr, uint8_t const prefix[], prefcount = prefcount == 15 ? 16 : prefcount; postcount = postcount == 15 ? 16 : postcount; - LOG_INFO("Uncompressing %d + %d => ", prefcount, postcount); + LOG_DBG("uncompression: address %d %d", prefcount, postcount); if(prefcount > 0) { memcpy(ipaddr, prefix, prefcount); @@ -631,8 +629,8 @@ uncompress_addr(uip_ipaddr_t *ipaddr, uint8_t const prefix[], uip_ds6_set_addr_iid(ipaddr, lladdr); } - LOG_INFO_6ADDR(ipaddr); - LOG_INFO_("\n"); + LOG_DBG_6ADDR(ipaddr); + LOG_DBG_("\n"); } /*--------------------------------------------------------------------*/ @@ -680,7 +678,7 @@ compress_hdr_iphc(linkaddr_t *link_destaddr) if(LOG_DBG_ENABLED) { uint16_t ndx; - LOG_DBG("before compression (%d): ", UIP_IP_BUF->len[1]); + LOG_DBG("compression: before (%d): ", UIP_IP_BUF->len[1]); for(ndx = 0; ndx < UIP_IP_BUF->len[1] + 40; ndx++) { uint8_t data = ((uint8_t *) (UIP_IP_BUF))[ndx]; LOG_DBG_("%02x", data); @@ -729,7 +727,7 @@ compress_hdr_iphc(linkaddr_t *link_destaddr) if(addr_context_lookup_by_prefix(&UIP_IP_BUF->destipaddr) != NULL || addr_context_lookup_by_prefix(&UIP_IP_BUF->srcipaddr) != NULL) { /* set context flag and increase hc06_ptr */ - LOG_INFO("IPHC: compressing dest or src ipaddr - setting CID\n"); + LOG_DBG("compression: dest or src ipaddr - setting CID\n"); iphc1 |= SICSLOWPAN_IPHC_CID; hc06_ptr++; } @@ -816,13 +814,13 @@ compress_hdr_iphc(linkaddr_t *link_destaddr) /* source address - cannot be multicast */ if(uip_is_addr_unspecified(&UIP_IP_BUF->srcipaddr)) { - LOG_INFO("IPHC: compressing unspecified - setting SAC\n"); + LOG_DBG("compression: addr unspecified - setting SAC\n"); iphc1 |= SICSLOWPAN_IPHC_SAC; iphc1 |= SICSLOWPAN_IPHC_SAM_00; } else if((context = addr_context_lookup_by_prefix(&UIP_IP_BUF->srcipaddr)) != NULL) { /* elide the prefix - indicate by CID and set context + SAC */ - LOG_INFO("IPHC: compressing src with context - setting CID & SAC ctx: %d\n", + LOG_DBG("compression: src with context - setting CID & SAC ctx: %d\n", context->number); iphc1 |= SICSLOWPAN_IPHC_CID | SICSLOWPAN_IPHC_SAC; PACKETBUF_IPHC_BUF[2] |= context->number << 4; @@ -905,9 +903,9 @@ compress_hdr_iphc(linkaddr_t *link_destaddr) next_nhc = hc06_ptr; /* here we set the next header is compressed. */ ext_hdr_len = 0; /* reserve the write place of this next header position */ - LOG_INFO("Compressing first header: %d\n", *next_hdr); + LOG_DBG("compression: first header: %d\n", *next_hdr); while(next_hdr != NULL && IS_COMPRESSABLE_PROTO(*next_hdr)) { - LOG_INFO("Compressing next header: %d\n", *next_hdr); + LOG_DBG("compression: next header: %d\n", *next_hdr); int proto = -1; /* used for the specific ext hdr */ /* UDP and EXT header compression */ switch(*next_hdr) { @@ -926,7 +924,7 @@ compress_hdr_iphc(linkaddr_t *link_destaddr) proto = proto == -1 ? SICSLOWPAN_NHC_ETX_HDR_DESTO : proto; /* Len is defined to be in octets from the length byte */ len = (ext_hdr->len << 3) + 8; - LOG_INFO("Handling next header: %d (len:%d)\n", *next_hdr, len); + LOG_DBG("compression: next header %d (len:%d)\n", *next_hdr, len); /* pick up the next header */ next_hdr = &ext_hdr->next; /* If the next header is not compressable we need to reserve the @@ -935,7 +933,7 @@ compress_hdr_iphc(linkaddr_t *link_destaddr) if(!IS_COMPRESSABLE_PROTO(*next_hdr)) { CHECK_BUFFER_SPACE(1); hc06_ptr++; - LOG_INFO("Keeping the next header in this ext hdr: %d\n", + LOG_DBG("compression: keeping the next header in this ext hdr: %d\n", ext_hdr->next); } /* copy the ext-hdr into the hc06 buffer */ @@ -961,14 +959,14 @@ compress_hdr_iphc(linkaddr_t *link_destaddr) /* allocate a byte for the next header posision as UDP has no next */ hc06_ptr++; udp_buf = UIP_UDP_BUF(ext_hdr_len); - LOG_INFO("IPHC: Uncompressed UDP ports on send side: %x, %x\n", + LOG_DBG("compression: inlined UDP ports on send side: %x, %x\n", UIP_HTONS(udp_buf->srcport), UIP_HTONS(udp_buf->destport)); /* Mask out the last 4 bits can be used as a mask */ if(((UIP_HTONS(udp_buf->srcport) & 0xfff0) == SICSLOWPAN_UDP_4_BIT_PORT_MIN) && ((UIP_HTONS(udp_buf->destport) & 0xfff0) == SICSLOWPAN_UDP_4_BIT_PORT_MIN)) { /* we can compress 12 bits of both source and dest */ *next_nhc = SICSLOWPAN_NHC_UDP_CS_P_11; - LOG_INFO("IPHC: remove 12 b of both source & dest with prefix 0xFOB\n"); + LOG_DBG("IPHC: remove 12 b of both source & dest with prefix 0xFOB\n"); CHECK_BUFFER_SPACE(1); *hc06_ptr = (uint8_t)((UIP_HTONS(udp_buf->srcport) - @@ -979,7 +977,7 @@ compress_hdr_iphc(linkaddr_t *link_destaddr) } else if((UIP_HTONS(udp_buf->destport) & 0xff00) == SICSLOWPAN_UDP_8_BIT_PORT_MIN) { /* we can compress 8 bits of dest, leave source. */ *next_nhc = SICSLOWPAN_NHC_UDP_CS_P_01; - LOG_INFO("IPHC: leave source, remove 8 bits of dest with prefix 0xF0\n"); + LOG_DBG("IPHC: leave source, remove 8 bits of dest with prefix 0xF0\n"); CHECK_BUFFER_SPACE(3); memcpy(hc06_ptr, &udp_buf->srcport, 2); *(hc06_ptr + 2) = @@ -989,7 +987,7 @@ compress_hdr_iphc(linkaddr_t *link_destaddr) } else if((UIP_HTONS(udp_buf->srcport) & 0xff00) == SICSLOWPAN_UDP_8_BIT_PORT_MIN) { /* we can compress 8 bits of src, leave dest. Copy compressed port */ *next_nhc = SICSLOWPAN_NHC_UDP_CS_P_10; - LOG_INFO("IPHC: remove 8 bits of source with prefix 0xF0, leave dest. hch: %i\n", *next_nhc); + LOG_DBG("IPHC: remove 8 bits of source with prefix 0xF0, leave dest. hch: %i\n", *next_nhc); CHECK_BUFFER_SPACE(3); *hc06_ptr = (uint8_t)((UIP_HTONS(udp_buf->srcport) - @@ -999,7 +997,7 @@ compress_hdr_iphc(linkaddr_t *link_destaddr) } else { /* we cannot compress. Copy uncompressed ports, full checksum */ *next_nhc = SICSLOWPAN_NHC_UDP_CS_P_00; - LOG_INFO("IPHC: cannot compress UDP headers\n"); + LOG_DBG("IPHC: cannot compress UDP headers\n"); CHECK_BUFFER_SPACE(4); memcpy(hc06_ptr, &udp_buf->srcport, 4); hc06_ptr += 4; @@ -1009,17 +1007,17 @@ compress_hdr_iphc(linkaddr_t *link_destaddr) memcpy(hc06_ptr, &udp_buf->udpchksum, 2); hc06_ptr += 2; uncomp_hdr_len += UIP_UDPH_LEN; - /* this is the final header... */ + /* this is the final header. */ next_hdr = NULL; break; default: - LOG_ERR("IPHC: could not handle compression of header"); + LOG_ERR("compression: could not handle compression of header"); } } if(next_hdr != NULL) { /* Last header could not be compressed - we assume that this is then OK!*/ /* as the last EXT_HDR should be "uncompressed" and have the next there */ - LOG_INFO("IPHC: last header could is not compressed: %d\n", *next_hdr); + LOG_DBG("compression: last header could is not compressed: %d\n", *next_hdr); } /* before the packetbuf_hdr_len operation */ PACKETBUF_IPHC_BUF[0] = iphc0; @@ -1027,7 +1025,7 @@ compress_hdr_iphc(linkaddr_t *link_destaddr) if(LOG_DBG_ENABLED) { uint16_t ndx; - LOG_DBG("after compression %d: ", (int)(hc06_ptr - packetbuf_ptr)); + LOG_DBG("compression: after (%d): ", (int)(hc06_ptr - packetbuf_ptr)); for(ndx = 0; ndx < hc06_ptr - packetbuf_ptr; ndx++) { uint8_t data = ((uint8_t *) packetbuf_ptr)[ndx]; LOG_DBG_("%02x", data); @@ -1074,7 +1072,7 @@ uncompress_hdr_iphc(uint8_t *buf, uint16_t ip_len) /* another if the CID flag is set */ if(iphc1 & SICSLOWPAN_IPHC_CID) { - LOG_INFO("IPHC: CID flag set - increase header with one\n"); + LOG_DBG("uncompression: CID flag set - increase header with one\n"); hc06_ptr++; } @@ -1122,7 +1120,7 @@ uncompress_hdr_iphc(uint8_t *buf, uint16_t ip_len) if((iphc0 & SICSLOWPAN_IPHC_NH_C) == 0) { /* Next header is carried inline */ SICSLOWPAN_IP_BUF(buf)->proto = *hc06_ptr; - LOG_INFO("IPHC: next header inline: %d\n", SICSLOWPAN_IP_BUF(buf)->proto); + LOG_DBG("uncompression: next header inline: %d\n", SICSLOWPAN_IP_BUF(buf)->proto); hc06_ptr += 1; } @@ -1146,7 +1144,7 @@ uncompress_hdr_iphc(uint8_t *buf, uint16_t ip_len) if (tmp != 0) { context = addr_context_lookup_by_number(sci); if(context == NULL) { - LOG_ERR("uncompress_hdr: error context not found\n"); + LOG_ERR("uncompression: error context not found\n"); return; } } @@ -1193,7 +1191,7 @@ uncompress_hdr_iphc(uint8_t *buf, uint16_t ip_len) /* all valid cases below need the context! */ if(context == NULL) { - LOG_ERR("uncompress_hdr: error context not found\n"); + LOG_ERR("uncompression: error context not found\n"); return; } uncompress_addr(&SICSLOWPAN_IP_BUF(buf)->destipaddr, context->prefix, @@ -1228,12 +1226,12 @@ uncompress_hdr_iphc(uint8_t *buf, uint16_t ip_len) if(!nh) { next = *hc06_ptr; hc06_ptr++; - LOG_INFO("Next header is not compressed... next: %d\n", next); + LOG_DBG("uncompression: next header is inlined. Next: %d\n", next); } len = *hc06_ptr; hc06_ptr++; - LOG_INFO("IPHC: Found extension-header id=%d next=%d len=%d\n", eid, next, len); + LOG_DBG("uncompression: found ext header id: %d next: %d len: %d\n", eid, next, len); switch(eid) { case SICSLOWPAN_NHC_ETX_HDR_HBHO: proto = UIP_PROTO_HBHO; @@ -1248,7 +1246,7 @@ uncompress_hdr_iphc(uint8_t *buf, uint16_t ip_len) proto = UIP_PROTO_DESTO; break; default: - LOG_INFO("IPHC: error unsupported extension-header\n"); + LOG_DBG("uncompression: error unsupported ext header\n"); return; } *last_nextheader = proto; @@ -1263,7 +1261,7 @@ uncompress_hdr_iphc(uint8_t *buf, uint16_t ip_len) ip_payload += (exthdr->len + 1) * 8; ext_hdr_len += (exthdr->len + 1) * 8; - LOG_INFO("Uncompressed EXT hdr: %d len:%d exhdrlen:%d (calc: %d)\n", + LOG_DBG("uncompression: %d len: %d exhdrlen: %d (calc: %d)\n", proto, len, exthdr->len, (exthdr->len + 1) * 8); } @@ -1274,13 +1272,13 @@ uncompress_hdr_iphc(uint8_t *buf, uint16_t ip_len) uint8_t checksum_compressed; *last_nextheader = UIP_PROTO_UDP; checksum_compressed = *hc06_ptr & SICSLOWPAN_NHC_UDP_CHECKSUMC; - LOG_INFO("IPHC: Incoming header value: %i\n", *hc06_ptr); + LOG_DBG("uncompression: incoming header value: %i\n", *hc06_ptr); switch(*hc06_ptr & SICSLOWPAN_NHC_UDP_CS_P_11) { case SICSLOWPAN_NHC_UDP_CS_P_00: /* 1 byte for NHC, 4 byte for ports, 2 bytes chksum */ memcpy(&udp_buf->srcport, hc06_ptr + 1, 2); memcpy(&udp_buf->destport, hc06_ptr + 3, 2); - LOG_INFO("IPHC: Uncompressed UDP ports (ptr+5): %x, %x\n", + LOG_DBG("uncompression: UDP ports (ptr+5): %x, %x\n", UIP_HTONS(udp_buf->srcport), UIP_HTONS(udp_buf->destport)); hc06_ptr += 5; @@ -1288,21 +1286,21 @@ uncompress_hdr_iphc(uint8_t *buf, uint16_t ip_len) case SICSLOWPAN_NHC_UDP_CS_P_01: /* 1 byte for NHC + source 16bit inline, dest = 0xF0 + 8 bit inline */ - LOG_INFO("IPHC: Decompressing destination\n"); + LOG_DBG("uncompression: destination address\n"); memcpy(&udp_buf->srcport, hc06_ptr + 1, 2); udp_buf->destport = UIP_HTONS(SICSLOWPAN_UDP_8_BIT_PORT_MIN + (*(hc06_ptr + 3))); - LOG_INFO("IPHC: Uncompressed UDP ports (ptr+4): %x, %x\n", + LOG_DBG("uncompression: UDP ports (ptr+4): %x, %x\n", UIP_HTONS(udp_buf->srcport), UIP_HTONS(udp_buf->destport)); hc06_ptr += 4; break; case SICSLOWPAN_NHC_UDP_CS_P_10: /* 1 byte for NHC + source = 0xF0 + 8bit inline, dest = 16 bit inline*/ - LOG_INFO("IPHC: Decompressing source\n"); + LOG_DBG("uncompression: source address\n"); udp_buf->srcport = UIP_HTONS(SICSLOWPAN_UDP_8_BIT_PORT_MIN + (*(hc06_ptr + 1))); memcpy(&udp_buf->destport, hc06_ptr + 2, 2); - LOG_INFO("IPHC: Uncompressed UDP ports (ptr+4): %x, %x\n", + LOG_DBG("uncompression: UDP ports (ptr+4): %x, %x\n", UIP_HTONS(udp_buf->srcport), UIP_HTONS(udp_buf->destport)); hc06_ptr += 4; break; @@ -1313,27 +1311,27 @@ uncompress_hdr_iphc(uint8_t *buf, uint16_t ip_len) (*(hc06_ptr + 1) >> 4)); udp_buf->destport = UIP_HTONS(SICSLOWPAN_UDP_4_BIT_PORT_MIN + ((*(hc06_ptr + 1)) & 0x0F)); - LOG_INFO("IPHC: Uncompressed UDP ports (ptr+2): %x, %x\n", + LOG_DBG("uncompression: UDP ports (ptr+2): %x, %x\n", UIP_HTONS(udp_buf->srcport), UIP_HTONS(udp_buf->destport)); hc06_ptr += 2; break; default: - LOG_INFO("sicslowpan uncompress_hdr: error unsupported UDP compression\n"); + LOG_DBG("uncompression: error unsupported UDP compression\n"); return; } if(!checksum_compressed) { /* has_checksum, default */ memcpy(&udp_buf->udpchksum, hc06_ptr, 2); hc06_ptr += 2; - LOG_INFO("IPHC: sicslowpan uncompress_hdr: checksum included\n"); + LOG_DBG("uncompression: checksum included\n"); } else { - LOG_INFO("IPHC: sicslowpan uncompress_hdr: checksum *NOT* included\n"); + LOG_DBG("uncompression: checksum *NOT* included\n"); } /* length field in UDP header (8 byte header + payload) */ udp_len = 8 + packetbuf_datalen() - (hc06_ptr - packetbuf_ptr); udp_buf->udplen = UIP_HTONS(ip_len == 0 ? udp_len : ip_len - UIP_IPH_LEN - ext_hdr_len); - LOG_INFO("Setting UDP length: %u (ext: %u) ip_len: %d udp_len:%d\n", + LOG_DBG("uncompression: UDP length: %u (ext: %u) ip_len: %d udp_len: %d\n", UIP_HTONS(udp_buf->udplen), ext_hdr_len, ip_len, udp_len); uncomp_hdr_len += UIP_UDPH_LEN; @@ -1344,7 +1342,7 @@ uncompress_hdr_iphc(uint8_t *buf, uint16_t ip_len) /* IP length field. */ if(ip_len == 0) { int len = packetbuf_datalen() - packetbuf_hdr_len + uncomp_hdr_len - UIP_IPH_LEN; - LOG_INFO("IP payload length: %d. %u - %u + %u - %u\n", len, + LOG_DBG("uncompression: IP payload length: %d. %u - %u + %u - %u\n", len, packetbuf_datalen(), packetbuf_hdr_len, uncomp_hdr_len, UIP_IPH_LEN); /* This is not a fragmented packet */ @@ -1495,6 +1493,48 @@ send_packet(linkaddr_t *dest) watchdog know that we are still alive. */ watchdog_periodic(); } +#if SICSLOWPAN_CONF_FRAG +/*--------------------------------------------------------------------*/ +/** + * \brief This function is called by the 6lowpan code to copy a fragment's + * payload from uIP and send it down the stack. + * \param uip_offset the offset in the uIP buffer where to copy the payload from + * \param dest the link layer destination address of the packet + * \return 1 if success, 0 otherwise + */ +static int +fragment_copy_payload_and_send(uint16_t uip_offset, linkaddr_t *dest) { + struct queuebuf *q; + + /* Now copy fragment payload from uip_buf */ + memcpy(packetbuf_ptr + packetbuf_hdr_len, + (uint8_t *)UIP_IP_BUF + uip_offset, packetbuf_payload_len); + packetbuf_set_datalen(packetbuf_payload_len + packetbuf_hdr_len); + + /* Backup packetbuf to queuebuf. Enables preserving attributes for all framgnets */ + q = queuebuf_new_from_packetbuf(); + if(q == NULL) { + LOG_WARN("output: could not allocate queuebuf, dropping fragment\n"); + return 0; + } + + /* Send fragment */ + send_packet(dest); + + /* Restore packetbuf from queuebuf */ + queuebuf_to_packetbuf(q); + queuebuf_free(q); + + /* Check tx result. */ + if((last_tx_status == MAC_TX_COLLISION) || + (last_tx_status == MAC_TX_ERR) || + (last_tx_status == MAC_TX_ERR_FATAL)) { + LOG_ERR("output: error in fragment tx, dropping subsequent fragments.\n"); + return 0; + } + return 1; +} +#endif /* SICSLOWPAN_CONF_FRAG */ /*--------------------------------------------------------------------*/ /** \brief Take an IP packet and format it to be sent on an 802.15.4 * network using 6lowpan. @@ -1509,6 +1549,8 @@ static uint8_t output(const linkaddr_t *localdest) { int framer_hdrlen; + int max_payload; + int frag_needed; /* The MAC address of the destination of the packet */ linkaddr_t dest; @@ -1538,23 +1580,19 @@ output(const linkaddr_t *localdest) linkaddr_copy(&dest, localdest); } - LOG_INFO("output: sending packet len %d\n", uip_len); + LOG_INFO("output: sending IPv6 packet with len %d\n", uip_len); /* copy over the retransmission count from uipbuf attributes */ packetbuf_set_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS, uipbuf_get_attr(UIPBUF_ATTR_MAX_MAC_TRANSMISSIONS)); /* Calculate NETSTACK_FRAMER's header length, that will be added in the NETSTACK_MAC */ -#ifndef SICSLOWPAN_USE_FIXED_HDRLEN packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, &dest); framer_hdrlen = NETSTACK_FRAMER.length(); if(framer_hdrlen < 0) { /* Framing failed, we assume the maximum header length */ - framer_hdrlen = SICSLOWPAN_FIXED_HDRLEN; + framer_hdrlen = MAC_MAX_HEADER; } -#else /* USE_FRAMER_HDRLEN */ - framer_hdrlen = SICSLOWPAN_FIXED_HDRLEN; -#endif /* USE_FRAMER_HDRLEN */ mac_max_payload = MAC_MAX_PAYLOAD - framer_hdrlen; @@ -1576,131 +1614,134 @@ output(const linkaddr_t *localdest) return 0; } #endif /* SICSLOWPAN_COMPRESSION >= SICSLOWPAN_COMPRESSION_IPHC */ - LOG_INFO("output: header of len %d\n", packetbuf_hdr_len); - if((int)uip_len - (int)uncomp_hdr_len > mac_max_payload - (int)packetbuf_hdr_len) { + /* Calculate NETSTACK_FRAMER's header length, that will be added in the NETSTACK_MAC. + * We calculate it here only to make a better decision of whether the outgoing packet + * needs to be fragmented or not. */ + packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, &dest); + framer_hdrlen = NETSTACK_FRAMER.length(); + if(framer_hdrlen < 0) { + /* Framing failed, we assume the maximum header length */ + framer_hdrlen = MAC_MAX_HEADER; + } + + max_payload = MAC_MAX_PAYLOAD - framer_hdrlen; + frag_needed = (int)uip_len - (int)uncomp_hdr_len + (int)packetbuf_hdr_len > max_payload; + LOG_INFO("output: header len %d -> %d, total len %d -> %d, MAC max payload %d, frag_needed %d\n", + uncomp_hdr_len, packetbuf_hdr_len, + uip_len, uip_len - uncomp_hdr_len + packetbuf_hdr_len, + max_payload, frag_needed); + + if(frag_needed) { #if SICSLOWPAN_CONF_FRAG /* Number of bytes processed. */ uint16_t processed_ip_out_len; - - struct queuebuf *q; uint16_t frag_tag; + int curr_frag = 0; /* * The outbound IPv6 packet is too large to fit into a single 15.4 * packet, so we fragment it into multiple packets and send them. - * The first fragment contains frag1 dispatch, then - * IPv6/IPHC/HC_UDP dispatchs/headers. - * The following fragments contain only the fragn dispatch. + * The first fragment contains frag1 dispatch, then IPv6/IPHC/HC_UDP + * dispatchs/headers and IPv6 payload (with len multiple of 8 bytes). + * The subsequent fragments contain the FRAGN dispatch and more of the + * IPv6 payload (still multiple of 8 bytes, except for the last fragment) */ - int estimated_fragments = ((int)uip_len) / (mac_max_payload - SICSLOWPAN_FRAGN_HDR_LEN) + 1; + /* Total IPv6 payload */ + int total_payload = (uip_len - uncomp_hdr_len); + /* IPv6 payload that goes to first fragment */ + int frag1_payload = (max_payload - packetbuf_hdr_len - SICSLOWPAN_FRAG1_HDR_LEN) & 0xfffffff8; + /* max IPv6 payload in each FRAGN. Must be multiple of 8 bytes */ + int fragn_max_payload = (max_payload - SICSLOWPAN_FRAGN_HDR_LEN) & 0xfffffff8; + /* max IPv6 payload in the last fragment. Needs not be multiple of 8 bytes */ + int last_fragn_max_payload = max_payload - SICSLOWPAN_FRAGN_HDR_LEN; + /* sum of all IPv6 payload that goes to non-first and non-last fragments */ + int middle_fragn_total_payload = MAX(total_payload - frag1_payload - last_fragn_max_payload, 0); + /* Ceiling of: 2 + middle_fragn_total_payload / fragn_max_payload */ + int fragment_count = 2; + if(middle_fragn_total_payload > 0) { + fragment_count += 1 + (middle_fragn_total_payload - 1) / fragn_max_payload; + } + int freebuf = queuebuf_numfree() - 1; - LOG_INFO("uip_len: %d, fragments: %d, free bufs: %d\n", uip_len, estimated_fragments, freebuf); - if(freebuf < estimated_fragments) { - LOG_WARN("Dropping packet, not enough free bufs\n"); + LOG_INFO("output: fragmentation needed, fragments: %u, free queuebufs: %u\n", + fragment_count, freebuf); + + if(freebuf < fragment_count) { + LOG_WARN("output: dropping packet, not enough free bufs (needed: %u, free: %u)\n", + fragment_count, freebuf); return 0; } - LOG_INFO("Fragmentation sending packet len %d\n", uip_len); - - /* Create 1st Fragment */ - LOG_INFO("output: 1st fragment "); - - /* Reset last tx status to ok in case the fragment transmissions are deferred */ - last_tx_status = MAC_TX_OK; - - /* move IPHC/IPv6 header */ - memmove(packetbuf_ptr + SICSLOWPAN_FRAG1_HDR_LEN, packetbuf_ptr, packetbuf_hdr_len); - - /* - * FRAG1 dispatch + header - * Note that the length is in units of 8 bytes - */ - SET16(PACKETBUF_FRAG_PTR, PACKETBUF_FRAG_DISPATCH_SIZE, - ((SICSLOWPAN_DISPATCH_FRAG1 << 8) | uip_len)); - frag_tag = my_tag++; - SET16(PACKETBUF_FRAG_PTR, PACKETBUF_FRAG_TAG, frag_tag); - - /* Copy payload and send */ - packetbuf_hdr_len += SICSLOWPAN_FRAG1_HDR_LEN; - packetbuf_payload_len = (mac_max_payload - packetbuf_hdr_len) & 0xfffffff8; - LOG_INFO_("(len %d, tag %d)\n", packetbuf_payload_len, frag_tag); - - if(packetbuf_payload_len < 0) { + if(frag1_payload < 0) { /* The current implementation requires that all headers fit in the first * fragment. Here is a corner case where the header did fit packetbuf * but do no longer fit after truncating for a length multiple of 8. */ - LOG_WARN("compressed header does not fit first fragment\n"); + LOG_WARN("output: compressed header does not fit first fragment\n"); return 0; } - memcpy(packetbuf_ptr + packetbuf_hdr_len, - (uint8_t *)UIP_IP_BUF + uncomp_hdr_len, packetbuf_payload_len); - packetbuf_set_datalen(packetbuf_payload_len + packetbuf_hdr_len); - q = queuebuf_new_from_packetbuf(); - if(q == NULL) { - LOG_WARN("could not allocate queuebuf for first fragment, dropping packet\n"); - return 0; - } - send_packet(&dest); - queuebuf_to_packetbuf(q); - queuebuf_free(q); - q = NULL; + /* Reset last tx status -- MAC layers most often call packet_sent asynchrously */ + last_tx_status = MAC_TX_OK; + /* Update fragment tag */ + frag_tag = my_tag++; - /* Check tx result. */ - if((last_tx_status == MAC_TX_COLLISION) || - (last_tx_status == MAC_TX_ERR) || - (last_tx_status == MAC_TX_ERR_FATAL)) { - LOG_ERR("error in fragment tx, dropping subsequent fragments.\n"); + /* Move IPHC/IPv6 header to make room for FRAG1 header */ + memmove(packetbuf_ptr + SICSLOWPAN_FRAG1_HDR_LEN, packetbuf_ptr, packetbuf_hdr_len); + packetbuf_hdr_len += SICSLOWPAN_FRAG1_HDR_LEN; + + /* Set FRAG1 header */ + SET16(PACKETBUF_FRAG_PTR, PACKETBUF_FRAG_DISPATCH_SIZE, + ((SICSLOWPAN_DISPATCH_FRAG1 << 8) | uip_len)); + SET16(PACKETBUF_FRAG_PTR, PACKETBUF_FRAG_TAG, frag_tag); + + /* Set frag1 payload len. Was already caulcated earlier as frag1_payload */ + packetbuf_payload_len = frag1_payload; + + /* Copy payload from uIP and send fragment */ + /* Send fragment */ + LOG_INFO("output: fragment %d/%d (tag %d, payload %d)\n", + curr_frag + 1, fragment_count, + frag_tag, packetbuf_payload_len); + if(fragment_copy_payload_and_send(uncomp_hdr_len, &dest) == 0) { return 0; } - /* set processed_ip_out_len to what we already sent from the IP payload*/ - processed_ip_out_len = packetbuf_payload_len + uncomp_hdr_len; + /* Now prepare for subsequent fragments. */ - /* - * Create following fragments - * Datagram tag is already in the buffer, we need to set the - * FRAGN dispatch and for each fragment, the offset - */ + /* FRAGN header: tag was already set at FRAG1. Now set dispatch for all FRAGN */ packetbuf_hdr_len = SICSLOWPAN_FRAGN_HDR_LEN; -/* PACKETBUF_FRAG_BUF->dispatch_size = */ -/* uip_htons((SICSLOWPAN_DISPATCH_FRAGN << 8) | uip_len); */ SET16(PACKETBUF_FRAG_PTR, PACKETBUF_FRAG_DISPATCH_SIZE, ((SICSLOWPAN_DISPATCH_FRAGN << 8) | uip_len)); - packetbuf_payload_len = (mac_max_payload - packetbuf_hdr_len) & 0xfffffff8; + + /* Keep track of the total length of data sent */ + processed_ip_out_len = uncomp_hdr_len + packetbuf_payload_len; + + /* Create and send subsequent fragments. */ while(processed_ip_out_len < uip_len) { - LOG_INFO("output: fragment "); + curr_frag++; + /* FRAGN header: set offset for this fragment */ PACKETBUF_FRAG_PTR[PACKETBUF_FRAG_OFFSET] = processed_ip_out_len >> 3; - /* Copy payload and send */ - if(uip_len - processed_ip_out_len < packetbuf_payload_len) { + /* Calculate fragment len */ + if(uip_len - processed_ip_out_len > last_fragn_max_payload) { + /* Not last fragment, send max FRAGN payload */ + packetbuf_payload_len = fragn_max_payload; + } else { /* last fragment */ packetbuf_payload_len = uip_len - processed_ip_out_len; } - LOG_INFO_("(offset %d, len %d, tag %d)\n", - processed_ip_out_len >> 3, packetbuf_payload_len, frag_tag); - memcpy(packetbuf_ptr + packetbuf_hdr_len, - (uint8_t *)UIP_IP_BUF + processed_ip_out_len, packetbuf_payload_len); - packetbuf_set_datalen(packetbuf_payload_len + packetbuf_hdr_len); - q = queuebuf_new_from_packetbuf(); - if(q == NULL) { - LOG_WARN("could not allocate queuebuf, dropping fragment\n"); - return 0; - } - send_packet(&dest); - queuebuf_to_packetbuf(q); - queuebuf_free(q); - q = NULL; - processed_ip_out_len += packetbuf_payload_len; - /* Check tx result. */ - if((last_tx_status == MAC_TX_COLLISION) || - (last_tx_status == MAC_TX_ERR) || - (last_tx_status == MAC_TX_ERR_FATAL)) { - LOG_ERR("error in fragment tx, dropping subsequent fragments.\n"); + /* Copy payload from uIP and send fragment */ + /* Send fragment */ + LOG_INFO("output: fragment %d/%d (tag %d, payload %d, offset %d)\n", + curr_frag + 1, fragment_count, + frag_tag, packetbuf_payload_len, processed_ip_out_len); + if(fragment_copy_payload_and_send(processed_ip_out_len, &dest) == 0) { return 0; } + + processed_ip_out_len += packetbuf_payload_len; } #else /* SICSLOWPAN_CONF_FRAG */ LOG_ERR("output: Packet too large to be sent without fragmentation support; dropping packet\n"); @@ -1761,7 +1802,7 @@ input(void) packetbuf_ptr = packetbuf_dataptr(); if(packetbuf_datalen() == 0) { - LOG_WARN("empty packet\n"); + LOG_WARN("input: empty packet\n"); return; } @@ -1780,20 +1821,21 @@ input(void) */ switch((GET16(PACKETBUF_FRAG_PTR, PACKETBUF_FRAG_DISPATCH_SIZE) >> 8) & SICSLOWPAN_DISPATCH_FRAG_MASK) { case SICSLOWPAN_DISPATCH_FRAG1: - LOG_INFO("input: FRAG1 "); frag_offset = 0; frag_size = GET16(PACKETBUF_FRAG_PTR, PACKETBUF_FRAG_DISPATCH_SIZE) & 0x07ff; frag_tag = GET16(PACKETBUF_FRAG_PTR, PACKETBUF_FRAG_TAG); - LOG_INFO_ ("size %d, tag %d, offset %d)\n", - frag_size, frag_tag, frag_offset); packetbuf_hdr_len += SICSLOWPAN_FRAG1_HDR_LEN; first_fragment = 1; is_fragment = 1; + LOG_INFO("input: received first element of a fragmented packet (tag %d, len %d)\n", + frag_tag, frag_size); + /* Add the fragment to the fragmentation context */ frag_context = add_fragment(frag_tag, frag_size, frag_offset); if(frag_context == -1) { + LOG_ERR("input: failed to allocate new reassembly context\n"); return; } @@ -1805,24 +1847,17 @@ input(void) * set offset, tag, size * Offset is in units of 8 bytes */ - LOG_INFO("input: FRAGN "); frag_offset = PACKETBUF_FRAG_PTR[PACKETBUF_FRAG_OFFSET]; frag_tag = GET16(PACKETBUF_FRAG_PTR, PACKETBUF_FRAG_TAG); frag_size = GET16(PACKETBUF_FRAG_PTR, PACKETBUF_FRAG_DISPATCH_SIZE) & 0x07ff; - LOG_INFO_("size %d, tag %d, offset %d)\n", - frag_size, frag_tag, frag_offset); packetbuf_hdr_len += SICSLOWPAN_FRAGN_HDR_LEN; - /* If this is the last fragment, we may shave off any extrenous - bytes at the end. We must be liberal in what we accept. */ - LOG_INFO_("last_fragment?: packetbuf_payload_len %d frag_size %d\n", - packetbuf_datalen() - packetbuf_hdr_len, frag_size); - /* Add the fragment to the fragmentation context (this will also copy the payload) */ frag_context = add_fragment(frag_tag, frag_size, frag_offset); if(frag_context == -1) { + LOG_ERR("input: reassembly context not found (tag %d)\n", frag_tag); return; } @@ -1858,10 +1893,10 @@ input(void) /* Process next dispatch and headers */ if((PACKETBUF_6LO_PTR[PACKETBUF_6LO_DISPATCH] & SICSLOWPAN_DISPATCH_IPHC_MASK) == SICSLOWPAN_DISPATCH_IPHC) { - LOG_INFO("input: IPHC\n"); + LOG_DBG("uncompression: IPHC dispatch\n"); uncompress_hdr_iphc(buffer, frag_size); } else if(PACKETBUF_6LO_PTR[PACKETBUF_6LO_DISPATCH] == SICSLOWPAN_DISPATCH_IPV6) { - LOG_INFO("input: IPV6\n"); + LOG_DBG("uncompression: IPV6 dispatch\n"); packetbuf_hdr_len += SICSLOWPAN_IPV6_HDR_LEN; /* Put uncompressed IP header in sicslowpan_buf. */ @@ -1871,8 +1906,8 @@ input(void) packetbuf_hdr_len += UIP_IPH_LEN; uncomp_hdr_len += UIP_IPH_LEN; } else { - LOG_ERR("input: unknown dispatch: 0x%02x\n", - PACKETBUF_6LO_PTR[PACKETBUF_6LO_DISPATCH]); + LOG_ERR("uncompression: unknown dispatch: 0x%02x\n", + PACKETBUF_6LO_PTR[PACKETBUF_6LO_DISPATCH] & SICSLOWPAN_DISPATCH_IPHC_MASK); return; } @@ -1887,18 +1922,25 @@ input(void) * If this is a subsequent fragment, this is the contrary. */ if(packetbuf_datalen() < packetbuf_hdr_len) { - LOG_ERR("packet dropped due to header > total packet\n"); + LOG_ERR("input: packet dropped due to header > total packet\n"); return; } packetbuf_payload_len = packetbuf_datalen() - packetbuf_hdr_len; +#if SICSLOWPAN_CONF_FRAG + if(is_fragment) { + LOG_INFO("input: fragment (tag %d, payload %d, offset %d) -- %u %u\n", + frag_tag, packetbuf_payload_len, frag_offset << 3, packetbuf_datalen(), packetbuf_hdr_len); + } +#endif /*SICSLOWPAN_CONF_FRAG*/ + /* Sanity-check size of incoming packet to avoid buffer overflow */ { int req_size = UIP_LLH_LEN + uncomp_hdr_len + (uint16_t)(frag_offset << 3) + packetbuf_payload_len; if(req_size > sizeof(uip_buf)) { LOG_ERR( - "packet dropped, minimum required IP_BUF size: %d+%d+%d+%d=%d (current size: %u)\n", + "input: packet dropped, minimum required IP_BUF size: %d+%d+%d+%d=%d (current size: %u)\n", UIP_LLH_LEN, uncomp_hdr_len, (uint16_t)(frag_offset << 3), packetbuf_payload_len, req_size, (unsigned)sizeof(uip_buf)); return; @@ -1943,12 +1985,12 @@ input(void) #else uip_len = packetbuf_payload_len + uncomp_hdr_len; #endif /* SICSLOWPAN_CONF_FRAG */ - LOG_INFO("input: IP packet ready (length %d)\n", + LOG_INFO("input: received IPv6 packet with len %d\n", uip_len); if(LOG_DBG_ENABLED) { uint16_t ndx; - LOG_DBG("after decompression %u:", UIP_IP_BUF->len[1]); + LOG_DBG("uncompression: after (%u):", UIP_IP_BUF->len[1]); for (ndx = 0; ndx < UIP_IP_BUF->len[1] + 40; ndx++) { uint8_t data = ((uint8_t *) (UIP_IP_BUF))[ndx]; LOG_DBG_("%02x", data); diff --git a/os/net/ipv6/tcpip.c b/os/net/ipv6/tcpip.c index 5db4b9a21..8d546c1d7 100644 --- a/os/net/ipv6/tcpip.c +++ b/os/net/ipv6/tcpip.c @@ -480,7 +480,7 @@ output_fallback(void) } /*---------------------------------------------------------------------------*/ static void -annotate_transmission(uip_ipaddr_t *nexthop) +annotate_transmission(const uip_ipaddr_t *nexthop) { #if TCPIP_CONF_ANNOTATE_TRANSMISSIONS static uint8_t annotate_last; @@ -495,10 +495,10 @@ annotate_transmission(uip_ipaddr_t *nexthop) #endif /* TCPIP_CONF_ANNOTATE_TRANSMISSIONS */ } /*---------------------------------------------------------------------------*/ -static uip_ipaddr_t* +static const uip_ipaddr_t* get_nexthop(uip_ipaddr_t *addr) { - uip_ipaddr_t *nexthop; + const uip_ipaddr_t *nexthop; uip_ds6_route_t *route; LOG_INFO("output: processing %u bytes packet from ", uip_len); @@ -597,7 +597,7 @@ send_queued(uip_ds6_nbr_t *nbr) } /*---------------------------------------------------------------------------*/ static int -send_nd6_ns(uip_ipaddr_t *nexthop) +send_nd6_ns(const uip_ipaddr_t *nexthop) { int err = 1; @@ -638,7 +638,7 @@ tcpip_ipv6_output(void) uip_ipaddr_t ipaddr; uip_ds6_nbr_t *nbr = NULL; const uip_lladdr_t *linkaddr; - uip_ipaddr_t *nexthop; + const uip_ipaddr_t *nexthop; if(uip_len == 0) { return; diff --git a/os/net/ipv6/uip-ds6-nbr.c b/os/net/ipv6/uip-ds6-nbr.c index e49125548..f937986b5 100644 --- a/os/net/ipv6/uip-ds6-nbr.c +++ b/os/net/ipv6/uip-ds6-nbr.c @@ -127,6 +127,41 @@ uip_ds6_nbr_rm(uip_ds6_nbr_t *nbr) return 0; } +/*---------------------------------------------------------------------------*/ +int +uip_ds6_nbr_update_ll(uip_ds6_nbr_t **nbr_pp, const uip_lladdr_t *new_ll_addr) +{ + uip_ds6_nbr_t nbr_backup; + + if(nbr_pp == NULL || new_ll_addr == NULL) { + LOG_ERR("%s: invalid argument\n", __func__); + return -1; + } + + /* make sure new_ll_addr is not used in some other nbr */ + if(uip_ds6_nbr_ll_lookup(new_ll_addr) != NULL) { + LOG_ERR("%s: new_ll_addr, ", __func__); + LOG_ERR_LLADDR((const linkaddr_t *)new_ll_addr); + LOG_ERR_(", is already used in another nbr\n"); + return -1; + } + + memcpy(&nbr_backup, *nbr_pp, sizeof(uip_ds6_nbr_t)); + if(uip_ds6_nbr_rm(*nbr_pp) == 0) { + LOG_ERR("%s: input nbr cannot be removed\n", __func__); + return -1; + } + + if((*nbr_pp = uip_ds6_nbr_add(&nbr_backup.ipaddr, new_ll_addr, + nbr_backup.isrouter, nbr_backup.state, + NBR_TABLE_REASON_IPV6_ND, NULL)) == NULL) { + LOG_ERR("%s: cannot allocate a new nbr for new_ll_addr\n", __func__); + return -1; + } + memcpy(*nbr_pp, &nbr_backup, sizeof(uip_ds6_nbr_t)); + + return 0; +} /*---------------------------------------------------------------------------*/ const uip_ipaddr_t * uip_ds6_nbr_get_ipaddr(const uip_ds6_nbr_t *nbr) diff --git a/os/net/ipv6/uip-ds6-nbr.h b/os/net/ipv6/uip-ds6-nbr.h index 9aec47b4a..d645ac627 100644 --- a/os/net/ipv6/uip-ds6-nbr.h +++ b/os/net/ipv6/uip-ds6-nbr.h @@ -90,6 +90,7 @@ uip_ds6_nbr_t *uip_ds6_nbr_add(const uip_ipaddr_t *ipaddr, nbr_table_reason_t reason, void *data); int uip_ds6_nbr_rm(uip_ds6_nbr_t *nbr); const uip_lladdr_t *uip_ds6_nbr_get_ll(const uip_ds6_nbr_t *nbr); +int uip_ds6_nbr_update_ll(uip_ds6_nbr_t **nbr, const uip_lladdr_t *new_ll_addr); const uip_ipaddr_t *uip_ds6_nbr_get_ipaddr(const uip_ds6_nbr_t *nbr); uip_ds6_nbr_t *uip_ds6_nbr_lookup(const uip_ipaddr_t *ipaddr); uip_ds6_nbr_t *uip_ds6_nbr_ll_lookup(const uip_lladdr_t *lladdr); diff --git a/os/net/ipv6/uip-ds6-route.c b/os/net/ipv6/uip-ds6-route.c index a8fdd88fb..ed263edc4 100644 --- a/os/net/ipv6/uip-ds6-route.c +++ b/os/net/ipv6/uip-ds6-route.c @@ -133,8 +133,8 @@ assert_nbr_routes_list_sane(void) /*---------------------------------------------------------------------------*/ #if UIP_DS6_NOTIFICATIONS static void -call_route_callback(int event, uip_ipaddr_t *route, - uip_ipaddr_t *nexthop) +call_route_callback(int event, const uip_ipaddr_t *route, + const uip_ipaddr_t *nexthop) { int num; struct uip_ds6_notification *n; @@ -199,7 +199,7 @@ uip_ds6_route_nexthop_lladdr(uip_ds6_route_t *route) } #endif /* (UIP_MAX_ROUTES != 0) */ /*---------------------------------------------------------------------------*/ -uip_ipaddr_t * +const uip_ipaddr_t * uip_ds6_route_nexthop(uip_ds6_route_t *route) { #if (UIP_MAX_ROUTES != 0) @@ -263,7 +263,7 @@ uip_ds6_route_num_routes(void) } /*---------------------------------------------------------------------------*/ uip_ds6_route_t * -uip_ds6_route_lookup(uip_ipaddr_t *addr) +uip_ds6_route_lookup(const uip_ipaddr_t *addr) { #if (UIP_MAX_ROUTES != 0) uip_ds6_route_t *r; @@ -321,8 +321,8 @@ uip_ds6_route_lookup(uip_ipaddr_t *addr) } /*---------------------------------------------------------------------------*/ uip_ds6_route_t * -uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length, - uip_ipaddr_t *nexthop) +uip_ds6_route_add(const uip_ipaddr_t *ipaddr, uint8_t length, + const uip_ipaddr_t *nexthop) { #if (UIP_MAX_ROUTES != 0) uip_ds6_route_t *r; @@ -350,7 +350,7 @@ uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length, one first. */ r = uip_ds6_route_lookup(ipaddr); if(r != NULL) { - uip_ipaddr_t *current_nexthop; + const uip_ipaddr_t *current_nexthop; current_nexthop = uip_ds6_route_nexthop(r); if(current_nexthop != NULL && uip_ipaddr_cmp(nexthop, current_nexthop)) { /* no need to update route - already correct! */ @@ -580,7 +580,7 @@ rm_routelist_callback(nbr_table_item_t *ptr) #endif /* (UIP_MAX_ROUTES != 0) */ /*---------------------------------------------------------------------------*/ void -uip_ds6_route_rm_by_nexthop(uip_ipaddr_t *nexthop) +uip_ds6_route_rm_by_nexthop(const uip_ipaddr_t *nexthop) { #if (UIP_MAX_ROUTES != 0) /* Get routing entry list of this neighbor */ @@ -601,7 +601,7 @@ uip_ds6_defrt_head(void) } /*---------------------------------------------------------------------------*/ uip_ds6_defrt_t * -uip_ds6_defrt_add(uip_ipaddr_t *ipaddr, unsigned long interval) +uip_ds6_defrt_add(const uip_ipaddr_t *ipaddr, unsigned long interval) { uip_ds6_defrt_t *d; @@ -684,7 +684,7 @@ uip_ds6_defrt_rm(uip_ds6_defrt_t *defrt) } /*---------------------------------------------------------------------------*/ uip_ds6_defrt_t * -uip_ds6_defrt_lookup(uip_ipaddr_t *ipaddr) +uip_ds6_defrt_lookup(const uip_ipaddr_t *ipaddr) { uip_ds6_defrt_t *d; if(ipaddr == NULL) { @@ -700,7 +700,7 @@ uip_ds6_defrt_lookup(uip_ipaddr_t *ipaddr) return NULL; } /*---------------------------------------------------------------------------*/ -uip_ipaddr_t * +const uip_ipaddr_t * uip_ds6_defrt_choose(void) { uip_ds6_defrt_t *d; diff --git a/os/net/ipv6/uip-ds6-route.h b/os/net/ipv6/uip-ds6-route.h index 9f435824c..69ab18f5b 100644 --- a/os/net/ipv6/uip-ds6-route.h +++ b/os/net/ipv6/uip-ds6-route.h @@ -89,8 +89,8 @@ void uip_ds6_route_init(void); #define UIP_DS6_NOTIFICATION_ROUTE_RM 3 typedef void (* uip_ds6_notification_callback)(int event, - uip_ipaddr_t *route, - uip_ipaddr_t *nexthop, + const uip_ipaddr_t *route, + const uip_ipaddr_t *nexthop, int num_routes); struct uip_ds6_notification { struct uip_ds6_notification *next; @@ -201,11 +201,11 @@ typedef struct uip_ds6_defrt { /** \name Default router list basic routines */ /** @{ */ uip_ds6_defrt_t *uip_ds6_defrt_head(void); -uip_ds6_defrt_t *uip_ds6_defrt_add(uip_ipaddr_t *ipaddr, +uip_ds6_defrt_t *uip_ds6_defrt_add(const uip_ipaddr_t *ipaddr, unsigned long interval); void uip_ds6_defrt_rm(uip_ds6_defrt_t *defrt); -uip_ds6_defrt_t *uip_ds6_defrt_lookup(uip_ipaddr_t *ipaddr); -uip_ipaddr_t *uip_ds6_defrt_choose(void); +uip_ds6_defrt_t *uip_ds6_defrt_lookup(const uip_ipaddr_t *ipaddr); +const uip_ipaddr_t *uip_ds6_defrt_choose(void); void uip_ds6_defrt_periodic(void); /** @} */ @@ -213,13 +213,13 @@ void uip_ds6_defrt_periodic(void); /** \name Routing Table basic routines */ /** @{ */ -uip_ds6_route_t *uip_ds6_route_lookup(uip_ipaddr_t *destipaddr); -uip_ds6_route_t *uip_ds6_route_add(uip_ipaddr_t *ipaddr, uint8_t length, - uip_ipaddr_t *next_hop); +uip_ds6_route_t *uip_ds6_route_lookup(const uip_ipaddr_t *destipaddr); +uip_ds6_route_t *uip_ds6_route_add(const uip_ipaddr_t *ipaddr, uint8_t length, + const uip_ipaddr_t *next_hop); void uip_ds6_route_rm(uip_ds6_route_t *route); -void uip_ds6_route_rm_by_nexthop(uip_ipaddr_t *nexthop); +void uip_ds6_route_rm_by_nexthop(const uip_ipaddr_t *nexthop); -uip_ipaddr_t *uip_ds6_route_nexthop(uip_ds6_route_t *); +const uip_ipaddr_t *uip_ds6_route_nexthop(uip_ds6_route_t *); int uip_ds6_route_num_routes(void); uip_ds6_route_t *uip_ds6_route_head(void); uip_ds6_route_t *uip_ds6_route_next(uip_ds6_route_t *); diff --git a/os/net/ipv6/uip-ds6.c b/os/net/ipv6/uip-ds6.c index 6dd178dc8..4e82b3745 100644 --- a/os/net/ipv6/uip-ds6.c +++ b/os/net/ipv6/uip-ds6.c @@ -91,6 +91,9 @@ static uip_ds6_maddr_t *locmaddr; static uip_ds6_aaddr_t *locaaddr; #endif /* UIP_DS6_AADDR_NB */ static uip_ds6_prefix_t *locprefix; +#if (UIP_LLADDR_LEN == 2) +static const uint8_t iid_prefix[] = { 0x00, 0x00 , 0x00 , 0xff , 0xfe , 0x00 }; +#endif /* (UIP_LLADDR_LEN == 2) */ /*---------------------------------------------------------------------------*/ void @@ -553,8 +556,6 @@ uip_ds6_select_src(uip_ipaddr_t *src, uip_ipaddr_t *dst) void uip_ds6_set_addr_iid(uip_ipaddr_t *ipaddr, uip_lladdr_t *lladdr) { - /* We consider only links with IEEE EUI-64 identifier or - * IEEE 48-bit MAC addresses */ #if (UIP_LLADDR_LEN == 8) memcpy(ipaddr->u8 + 8, lladdr, UIP_LLADDR_LEN); ipaddr->u8[8] ^= 0x02; @@ -564,11 +565,14 @@ uip_ds6_set_addr_iid(uip_ipaddr_t *ipaddr, uip_lladdr_t *lladdr) ipaddr->u8[12] = 0xfe; memcpy(ipaddr->u8 + 13, (uint8_t *)lladdr + 3, 3); ipaddr->u8[8] ^= 0x02; +#elif (UIP_LLADDR_LEN == 2) + /* derive IID as per RFC 6282 */ + memcpy(ipaddr->u8 + 8, iid_prefix, 6); + memcpy(ipaddr->u8 + 8 + 6, lladdr, UIP_LLADDR_LEN); #else -#error uip-ds6.c cannot build interface address when UIP_LLADDR_LEN is not 6 or 8 +#error uip-ds6.c cannot build interface address when UIP_LLADDR_LEN is not 6, 8, or 2 #endif } - /*---------------------------------------------------------------------------*/ void uip_ds6_set_lladdr_from_iid(uip_lladdr_t *lladdr, const uip_ipaddr_t *ipaddr) @@ -576,8 +580,10 @@ uip_ds6_set_lladdr_from_iid(uip_lladdr_t *lladdr, const uip_ipaddr_t *ipaddr) #if (UIP_LLADDR_LEN == 8) memcpy(lladdr, ipaddr->u8 + 8, UIP_LLADDR_LEN); lladdr->addr[0] ^= 0x02; +#elif (UIP_LLADDR_LEN == 2) + memcpy(lladdr, ipaddr->u8 + 6, UIP_LLADDR_LEN); #else -#error uip-ds6.c cannot build lladdr address when UIP_LLADDR_LEN is not 8 +#error uip-ds6.c cannot build lladdr address when UIP_LLADDR_LEN is not 8 or 2 #endif } diff --git a/os/net/ipv6/uip-icmp6.c b/os/net/ipv6/uip-icmp6.c index be33a1101..707a13309 100644 --- a/os/net/ipv6/uip-icmp6.c +++ b/os/net/ipv6/uip-icmp6.c @@ -253,10 +253,6 @@ uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param) { void uip_icmp6_send(const uip_ipaddr_t *dest, int type, int code, int payload_len) { - LOG_INFO("Sending ICMPv6 packet to "); - LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr); - LOG_INFO_(", type %u, code %u, len %u\n", type, code, payload_len); - UIP_IP_BUF->vtc = 0x60; UIP_IP_BUF->tcflow = 0; UIP_IP_BUF->flow = 0; @@ -279,6 +275,10 @@ uip_icmp6_send(const uip_ipaddr_t *dest, int type, int code, int payload_len) UIP_STAT(++uip_stat.icmp.sent); UIP_STAT(++uip_stat.ip.sent); + LOG_INFO("Sending ICMPv6 packet to "); + LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr); + LOG_INFO_(", type %u, code %u, len %u\n", type, code, payload_len); + tcpip_ipv6_output(); } /*---------------------------------------------------------------------------*/ diff --git a/os/net/ipv6/uip-nd6.c b/os/net/ipv6/uip-nd6.c index ce555ed53..63ae46b47 100644 --- a/os/net/ipv6/uip-nd6.c +++ b/os/net/ipv6/uip-nd6.c @@ -69,6 +69,7 @@ */ #include +#include #include "net/ipv6/uip-icmp6.h" #include "net/ipv6/uip-nd6.h" #include "net/ipv6/uip-ds6.h" @@ -230,7 +231,9 @@ ns_input(void) } if(memcmp(&nd6_opt_llao[UIP_ND6_OPT_DATA_OFFSET], lladdr, UIP_LLADDR_LEN) != 0) { - if(nbr_table_update_lladdr((const linkaddr_t *)lladdr, (const linkaddr_t *)&lladdr_aligned, 1) == 0) { + if(uip_ds6_nbr_update_ll(&nbr, + (const uip_lladdr_t *)&lladdr_aligned) + < 0) { /* failed to update the lladdr */ goto discard; } @@ -528,13 +531,14 @@ na_input(void) if(nd6_opt_llao != NULL) { is_llchange = memcmp(&nd6_opt_llao[UIP_ND6_OPT_DATA_OFFSET], lladdr, - UIP_LLADDR_LEN); + UIP_LLADDR_LEN) == 0 ? 0 : 1; } if(nbr->state == NBR_INCOMPLETE) { if(nd6_opt_llao == NULL || !extract_lladdr_from_llao_aligned(&lladdr_aligned)) { goto discard; } - if(nbr_table_update_lladdr((const linkaddr_t *)lladdr, (const linkaddr_t *)&lladdr_aligned, 1) == 0) { + if(uip_ds6_nbr_update_ll(&nbr, + (const uip_lladdr_t *)&lladdr_aligned) < 0) { /* failed to update the lladdr */ goto discard; } @@ -561,7 +565,9 @@ na_input(void) if(is_override || !is_llchange || nd6_opt_llao == NULL) { if(nd6_opt_llao != NULL && is_llchange) { if(!extract_lladdr_from_llao_aligned(&lladdr_aligned) || - nbr_table_update_lladdr((const linkaddr_t *) lladdr, (const linkaddr_t *) &lladdr_aligned, 1) == 0) { + uip_ds6_nbr_update_ll(&nbr, + (const uip_lladdr_t *)&lladdr_aligned) + < 0) { /* failed to update the lladdr */ goto discard; } @@ -925,7 +931,8 @@ ra_input(void) if(memcmp(&nd6_opt_llao[UIP_ND6_OPT_DATA_OFFSET], lladdr, UIP_LLADDR_LEN) != 0) { /* change of link layer address */ - if(nbr_table_update_lladdr((const linkaddr_t *)lladdr, (const linkaddr_t *)&lladdr_aligned, 1) == 0) { + if(uip_ds6_nbr_update_ll(&nbr, + (const uip_lladdr_t *)&lladdr_aligned) < 0) { /* failed to update the lladdr */ goto discard; } diff --git a/os/net/ipv6/uip-sr.c b/os/net/ipv6/uip-sr.c index 15b123552..133fd6f28 100644 --- a/os/net/ipv6/uip-sr.c +++ b/os/net/ipv6/uip-sr.c @@ -41,6 +41,7 @@ #include "contiki.h" #include "net/ipv6/uip-sr.h" +#include "net/ipv6/uiplib.h" #include "net/routing/routing.h" #include "lib/list.h" #include "lib/memb.h" @@ -246,4 +247,57 @@ uip_sr_free_all(void) num_nodes--; } } +/*---------------------------------------------------------------------------*/ +int +uip_sr_link_snprint(char *buf, int buflen, uip_sr_node_t *link) +{ + int index = 0; + uip_ipaddr_t child_ipaddr; + uip_ipaddr_t parent_ipaddr; + + NETSTACK_ROUTING.get_sr_node_ipaddr(&child_ipaddr, link); + NETSTACK_ROUTING.get_sr_node_ipaddr(&parent_ipaddr, link->parent); + + if(LOG_WITH_COMPACT_ADDR) { + index += log_6addr_compact_snprint(buf+index, buflen-index, &child_ipaddr); + } else { + index += uiplib_ipaddr_snprint(buf+index, buflen-index, &child_ipaddr); + } + if(index >= buflen) { + return index; + } + + if(link->parent == NULL) { + index += snprintf(buf+index, buflen-index, " (DODAG root)"); + if(index >= buflen) { + return index; + } + } else { + index += snprintf(buf+index, buflen-index, " to "); + if(index >= buflen) { + return index; + } + if(LOG_WITH_COMPACT_ADDR) { + index += log_6addr_compact_snprint(buf+index, buflen-index, &parent_ipaddr); + } else { + index += uiplib_ipaddr_snprint(buf+index, buflen-index, &parent_ipaddr); + } + if(index >= buflen) { + return index; + } + } + if(link->lifetime != UIP_SR_INFINITE_LIFETIME) { + index += snprintf(buf+index, buflen-index, + " (lifetime: %lu seconds)", (unsigned long)link->lifetime); + if(index >= buflen) { + return index; + } + } else { + index += snprintf(buf+index, buflen-index, " (lifetime: infinite)"); + if(index >= buflen) { + return index; + } + } + return index; +} /** @} */ diff --git a/os/net/ipv6/uip-sr.h b/os/net/ipv6/uip-sr.h index 7224cea14..01ed57c1c 100644 --- a/os/net/ipv6/uip-sr.h +++ b/os/net/ipv6/uip-sr.h @@ -180,6 +180,17 @@ void uip_sr_init(void); */ void uip_sr_free_all(void); +/** +* Print a textual description of a source routing link +* +* \param buf The buffer where to write content +* \param buflen The buffer len +* \param link A pointer to the source routing link +* \return Identical to snprintf: number of bytes written excluding ending null +* byte. A value >= buflen if the buffer was too small. +*/ +int uip_sr_link_snprint(char *buf, int buflen, uip_sr_node_t *link); + /** @} */ #endif /* UIP_SR_H */ diff --git a/os/net/ipv6/uip.h b/os/net/ipv6/uip.h index 7751b8fc3..9f5eb159d 100755 --- a/os/net/ipv6/uip.h +++ b/os/net/ipv6/uip.h @@ -81,6 +81,7 @@ #include "net/ipv6/uipopt.h" #include "net/ipv6/uipbuf.h" +#include "net/linkaddr.h" /* For memcmp */ #include @@ -107,14 +108,16 @@ typedef uip_ip4addr_t uip_ipaddr_t; /*---------------------------------------------------------------------------*/ +#define UIP_802154_SHORTADDR_LEN 2 +#define UIP_802154_LONGADDR_LEN 8 /** \brief 16 bit 802.15.4 address */ typedef struct uip_802154_shortaddr { - uint8_t addr[2]; + uint8_t addr[UIP_802154_SHORTADDR_LEN]; } uip_802154_shortaddr; /** \brief 64 bit 802.15.4 address */ typedef struct uip_802154_longaddr { - uint8_t addr[8]; + uint8_t addr[UIP_802154_LONGADDR_LEN]; } uip_802154_longaddr; /** \brief 802.11 address */ @@ -134,11 +137,15 @@ typedef struct uip_eth_addr { #if UIP_CONF_LL_802154 /** \brief 802.15.4 address */ +#if LINKADDR_SIZE == UIP_802154_LONGADDR_LEN typedef uip_802154_longaddr uip_lladdr_t; -#define UIP_802154_SHORTADDR_LEN 2 -#define UIP_802154_LONGADDR_LEN 8 +#elif LINKADDR_SIZE == UIP_802154_SHORTADDR_LEN +typedef uip_802154_shortaddr uip_lladdr_t; +#else /* LINKADDR_SIZE == 8 */ +#error unsupported configuration of LINKADDR_SIZE +#endif /* LINKADDR_SIZE == 8 */ /** \brief Link layer address length */ -#define UIP_LLADDR_LEN UIP_802154_LONGADDR_LEN +#define UIP_LLADDR_LEN LINKADDR_SIZE #else /*UIP_CONF_LL_802154*/ #if UIP_CONF_LL_80211 /** \brief 802.11 address */ diff --git a/os/net/ipv6/uip6.c b/os/net/ipv6/uip6.c index e913a83e1..dfbec52b7 100644 --- a/os/net/ipv6/uip6.c +++ b/os/net/ipv6/uip6.c @@ -1089,7 +1089,7 @@ uip_process(uint8_t flag) if((UIP_IP_BUF->vtc & 0xf0) != 0x60) { /* IP version and header length. */ UIP_STAT(++uip_stat.ip.drop); UIP_STAT(++uip_stat.ip.vhlerr); - LOG_ERR("invalid version."); + LOG_ERR("invalid version\n"); goto drop; } /* diff --git a/os/net/ipv6/uiplib.c b/os/net/ipv6/uiplib.c index afe6de42b..a6d8b4f0c 100644 --- a/os/net/ipv6/uiplib.c +++ b/os/net/ipv6/uiplib.c @@ -3,17 +3,17 @@ * Computer Science. * 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. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote * products derived from this software without specific prior - * written permission. + * written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED @@ -25,7 +25,7 @@ * 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. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of the uIP TCP/IP stack and the Contiki operating system. * @@ -33,8 +33,11 @@ */ /** + * \addtogroup uip-addr-lib + * @{ + * * \file - * Various uIP library functions. + * Implementation of the IP address manipulation library * \author * Nicolas Tsiftes * Niclas Finne @@ -117,7 +120,7 @@ uiplib_ip6addrconv(const char *addrstr, uip_ip6addr_t *ipaddr) } #endif /* NETSTACK_CONF_WITH_IPV6 */ /*---------------------------------------------------------------------------*/ -/* Parse a IPv4-address from a string. Returns the number of characters read +/* Parse a IPv4-address from a string. Returns the number of characters read * for the address. */ int uiplib_ip4addrconv(const char *addrstr, uip_ip4addr_t *ipaddr) @@ -156,48 +159,9 @@ uiplib_ip4addrconv(const char *addrstr, uip_ip4addr_t *ipaddr) void uiplib_ipaddr_print(const uip_ipaddr_t *addr) { - uint16_t a; - unsigned int i; - int f; - - if(addr == NULL) { - printf("(NULL IP addr)"); - return; - } - - if(ip64_addr_is_ipv4_mapped_addr(addr)) { - /* - * Printing IPv4-mapped addresses is done according to RFC 4291 [1] - * - * "An alternative form that is sometimes more - * convenient when dealing with a mixed environment - * of IPv4 and IPv6 nodes is x:x:x:x:x:x:d.d.d.d, - * where the 'x's are the hexadecimal values of the - * six high-order 16-bit pieces of the address, and - * the 'd's are the decimal values of the four - * low-order 8-bit pieces of the address (standard - * IPv4 representation)." - * - * [1] https://tools.ietf.org/html/rfc4291#page-4 - */ - printf("::FFFF:%u.%u.%u.%u", addr->u8[12], addr->u8[13], addr->u8[14], addr->u8[15]); - } else { - for(i = 0, f = 0; i < sizeof(uip_ipaddr_t); i += 2) { - a = (addr->u8[i] << 8) + addr->u8[i + 1]; - if(a == 0 && f >= 0) { - if(f++ == 0) { - printf("::"); - } - } else { - if(f > 0) { - f = -1; - } else if(i > 0) { - printf(":"); - } - printf("%x", a); - } - } - } + char buf[UIPLIB_IPV6_MAX_STR_LEN]; + uiplib_ipaddr_snprint(buf, sizeof(buf), addr); + printf("%s", buf); } /*---------------------------------------------------------------------------*/ int @@ -205,15 +169,16 @@ uiplib_ipaddr_snprint(char *buf, size_t size, const uip_ipaddr_t *addr) { uint16_t a; unsigned int i; - int f, n; + int f; + int n = 0; if(size == 0) { return 0; } if(addr == NULL) { - n = snprintf(buf, size - 1, "(NULL IP addr)"); - + n = snprintf(buf, size, "(NULL IP addr)"); + return n; } else if(ip64_addr_is_ipv4_mapped_addr(addr)) { /* * Printing IPv4-mapped addresses is done according to RFC 4291 [1] @@ -229,32 +194,38 @@ uiplib_ipaddr_snprint(char *buf, size_t size, const uip_ipaddr_t *addr) * * [1] https://tools.ietf.org/html/rfc4291#page-4 */ - n = snprintf(buf, size - 1, "::FFFF:%u.%u.%u.%u", addr->u8[12], + n = snprintf(buf, size, "::FFFF:%u.%u.%u.%u", addr->u8[12], addr->u8[13], addr->u8[14], addr->u8[15]); + return n; } else { - for(n = 0, i = 0, f = 0; i < sizeof(uip_ipaddr_t) && n < size - 1; i += 2) { + for(i = 0, f = 0; i < sizeof(uip_ipaddr_t); i += 2) { a = (addr->u8[i] << 8) + addr->u8[i + 1]; if(a == 0 && f >= 0) { if(f++ == 0) { - buf[n++] = ':'; - buf[n++] = ':'; + n += snprintf(buf+n, size-n, "::"); + if(n >= size) { + return n; + } } } else { if(f > 0) { f = -1; } else if(i > 0) { - buf[n++] = ':'; + n += snprintf(buf+n, size-n, ":"); + if(n >= size) { + return n; + } + } + n += snprintf(buf+n, size-n, "%x", a); + if(n >= size) { + return n; } - n += snprintf(&buf[n], size - n - 1, "%x", a); } } } - - /* - * Make sure the output string is always null-terminated. - */ - buf[MIN(n, size - 1)] = '\0'; - return n; } /*---------------------------------------------------------------------------*/ +/** + * @} + */ diff --git a/os/net/ipv6/uiplib.h b/os/net/ipv6/uiplib.h index 6a122033e..b30a1bcb5 100644 --- a/os/net/ipv6/uiplib.h +++ b/os/net/ipv6/uiplib.h @@ -1,19 +1,19 @@ /* * Copyright (c) 2002, Adam Dunkels. - * All rights reserved. + * 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. + * 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. + * with the distribution. * 3. The name of the author may not be used to endorse or promote * products derived from this software without specific prior - * written permission. + * written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED @@ -25,29 +25,30 @@ * 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. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of the Contiki desktop environment for the C64. * * */ - -/** - * \file - * Various uIP library functions. - * \author - * Adam Dunkels - * - */ - #ifndef UIPLIB_H_ #define UIPLIB_H_ #include "net/ipv6/uip.h" /** - * \addtogroup uipconvfunc + * \addtogroup uip * @{ + * + * \defgroup uip-addr-lib uIP address manipulation library + * + * A library with various IP address manipulation functions + * @{ + * + * \file + * Header file for the IP address manipulation library + * \author + * Adam Dunkels */ /** @@ -65,7 +66,7 @@ * the numerical representation of the address. * * \retval 0 If the IP address could not be parsed. - * \retval Non-zero If the IP address was parsed. + * \retval Non-zero If the IP address was parsed. */ #if NETSTACK_CONF_WITH_IPV6 #define uiplib_ipaddrconv uiplib_ip6addrconv @@ -77,10 +78,10 @@ int uiplib_ip4addrconv(const char *addrstr, uip_ip4addr_t *addr); int uiplib_ip6addrconv(const char *addrstr, uip_ip6addr_t *addr); /** @} */ -/** - * \addtogroup uiplib - * @{ - */ + +/* The maxium length of an IPv6 string, including terminating null bytes + * fd01:0002:0003:0004:0005:0006:0007:0008 => 39 + 1 bytes */ +#define UIPLIB_IPV6_MAX_STR_LEN 40 /** * Print an IP address using printf(). @@ -99,6 +100,8 @@ void uiplib_ipaddr_print(const uip_ipaddr_t *addr); */ int uiplib_ipaddr_snprint(char *buffer, size_t size, const uip_ipaddr_t *addr); -/** @} */ - #endif /* UIPLIB_H_ */ +/** + * @} + * @} + */ diff --git a/os/net/link-stats.c b/os/net/link-stats.c index fbb7677da..c11365b9a 100644 --- a/os/net/link-stats.c +++ b/os/net/link-stats.c @@ -37,12 +37,10 @@ #include "net/link-stats.h" #include -#define DEBUG 0 -#if DEBUG -#define PRINTF(...) printf(__VA_ARGS__) -#else -#define PRINTF(...) -#endif +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "Link Stats" +#define LOG_LEVEL LOG_LEVEL_MAC /* Maximum value for the Tx count counter */ #define TX_COUNT_MAX 32 @@ -63,8 +61,8 @@ /* ETX fixed point divisor. 128 is the value used by RPL (RFC 6551 and RFC 6719) */ #define ETX_DIVISOR LINK_STATS_ETX_DIVISOR -/* Number of Tx used to update the ETX EWMA in case of no-ACK */ -#define ETX_NOACK_PENALTY 20 +/* In case of no-ACK, add ETX_NOACK_PENALTY to the real Tx count, as a penalty */ +#define ETX_NOACK_PENALTY 12 /* Initial ETX value */ #define ETX_DEFAULT 2 @@ -82,6 +80,13 @@ link_stats_from_lladdr(const linkaddr_t *lladdr) return nbr_table_get_from_lladdr(link_stats, lladdr); } /*---------------------------------------------------------------------------*/ +/* Returns the neighbor's address given a link stats item */ +const linkaddr_t * +link_stats_get_lladdr(const struct link_stats *stat) +{ + return nbr_table_get_lladdr(link_stats, stat); +} +/*---------------------------------------------------------------------------*/ /* Are the statistics fresh? */ int link_stats_is_fresh(const struct link_stats *stats) @@ -156,9 +161,21 @@ link_stats_packet_sent(const linkaddr_t *lladdr, int status, int numtx) stats->last_tx_time = clock_time(); stats->freshness = MIN(stats->freshness + numtx, FRESHNESS_MAX); +#if LINK_STATS_PACKET_COUNTERS + /* Update paket counters */ + stats->cnt_current.num_packets_tx += numtx; + if(status == MAC_TX_OK) { + stats->cnt_current.num_packets_acked++; + } +#endif + + /* Add penalty in case of no-ACK */ + if(status == MAC_TX_NOACK) { + numtx += ETX_NOACK_PENALTY; + } + #if LINK_STATS_ETX_FROM_PACKET_COUNT /* Compute ETX from packet and ACK count */ - numtx = (status == MAC_TX_NOACK) ? ETX_NOACK_PENALTY : numtx; /* Halve both counter after TX_COUNT_MAX */ if(stats->tx_count + numtx > TX_COUNT_MAX) { stats->tx_count /= 2; @@ -179,7 +196,7 @@ link_stats_packet_sent(const linkaddr_t *lladdr, int status, int numtx) /* Compute ETX using an EWMA */ /* ETX used for this update */ - packet_etx = ((status == MAC_TX_NOACK) ? ETX_NOACK_PENALTY : numtx) * ETX_DIVISOR; + packet_etx = numtx * ETX_DIVISOR; /* ETX alpha used for this update */ ewma_alpha = link_stats_is_fresh(stats) ? EWMA_ALPHA : EWMA_BOOTSTRAP_ALPHA; @@ -215,8 +232,38 @@ link_stats_input_callback(const linkaddr_t *lladdr) /* Update RSSI EWMA */ stats->rssi = ((int32_t)stats->rssi * (EWMA_SCALE - EWMA_ALPHA) + (int32_t)packet_rssi * EWMA_ALPHA) / EWMA_SCALE; + +#if LINK_STATS_PACKET_COUNTERS + stats->cnt_current.num_packets_rx++; +#endif } /*---------------------------------------------------------------------------*/ +#if LINK_STATS_PACKET_COUNTERS +/*---------------------------------------------------------------------------*/ +static void +print_and_update_counters(void) +{ + struct link_stats *stats; + + for(stats = nbr_table_head(link_stats); stats != NULL; + stats = nbr_table_next(link_stats, stats)) { + + struct link_packet_counter *c = &stats->cnt_current; + + LOG_INFO("num packets: tx=%u ack=%u rx=%u to=", + c->num_packets_tx, c->num_packets_acked, c->num_packets_rx); + LOG_INFO_LLADDR(link_stats_get_lladdr(stats)); + LOG_INFO_("\n"); + + stats->cnt_total.num_packets_tx += stats->cnt_current.num_packets_tx; + stats->cnt_total.num_packets_acked += stats->cnt_current.num_packets_acked; + stats->cnt_total.num_packets_rx += stats->cnt_current.num_packets_rx; + memset(&stats->cnt_current, 0, sizeof(stats->cnt_current)); + } +} +/*---------------------------------------------------------------------------*/ +#endif /* LINK_STATS_PACKET_COUNTERS */ +/*---------------------------------------------------------------------------*/ /* Periodic timer called at a period of FRESHNESS_HALF_LIFE */ static void periodic(void *ptr) @@ -227,6 +274,10 @@ periodic(void *ptr) for(stats = nbr_table_head(link_stats); stats != NULL; stats = nbr_table_next(link_stats, stats)) { stats->freshness >>= 1; } + +#if LINK_STATS_PACKET_COUNTERS + print_and_update_counters(); +#endif } /*---------------------------------------------------------------------------*/ /* Resets link-stats module */ diff --git a/os/net/link-stats.h b/os/net/link-stats.h index cca15fd32..51f1d285b 100644 --- a/os/net/link-stats.h +++ b/os/net/link-stats.h @@ -56,6 +56,25 @@ #define LINK_STATS_ETX_FROM_PACKET_COUNT 0 #endif /* LINK_STATS_ETX_FROM_PACKET_COUNT */ +/* Store and periodically print packet counters? */ +#ifdef LINK_STATS_CONF_PACKET_COUNTERS +#define LINK_STATS_PACKET_COUNTERS LINK_STATS_CONF_PACKET_COUNTERS +#else /* LINK_STATS_CONF_PACKET_COUNTERS */ +#define LINK_STATS_PACKET_COUNTERS 0 +#endif /* LINK_STATS_PACKET_COUNTERS */ + +typedef uint16_t link_packet_stat_t; + +struct link_packet_counter { + /* total attempts to transmit unicast packets */ + link_packet_stat_t num_packets_tx; + /* total ACKs for unicast packets */ + link_packet_stat_t num_packets_acked; + /* total number of unicast and broadcast packets received */ + link_packet_stat_t num_packets_rx; +}; + + /* All statistics of a given link */ struct link_stats { clock_time_t last_tx_time; /* Last Tx timestamp */ @@ -66,10 +85,17 @@ struct link_stats { uint8_t tx_count; /* Tx count, used for ETX calculation */ uint8_t ack_count; /* ACK count, used for ETX calculation */ #endif /* LINK_STATS_ETX_FROM_PACKET_COUNT */ + +#if LINK_STATS_PACKET_COUNTERS + struct link_packet_counter cnt_current; /* packets in the current period */ + struct link_packet_counter cnt_total; /* packets in total */ +#endif }; /* Returns the neighbor's link statistics */ const struct link_stats *link_stats_from_lladdr(const linkaddr_t *lladdr); +/* Returns the address of the neighbor */ +const linkaddr_t *link_stats_get_lladdr(const struct link_stats *); /* Are the statistics fresh? */ int link_stats_is_fresh(const struct link_stats *stats); /* Resets link-stats module */ diff --git a/os/net/linkaddr.h b/os/net/linkaddr.h index 6f7380218..7926550b1 100644 --- a/os/net/linkaddr.h +++ b/os/net/linkaddr.h @@ -70,11 +70,6 @@ typedef union { #endif /* LINKADDR_SIZE == 2 */ } linkaddr_t; -typedef union { - uint8_t u8[8]; - uint16_t u16[4]; -} linkaddr_extended_t; - /** * \brief Copy a link-layer address * \param dest The destination diff --git a/os/net/mac/ble/ble-l2cap.c b/os/net/mac/ble/ble-l2cap.c index f12fbb369..076d919e8 100644 --- a/os/net/mac/ble/ble-l2cap.c +++ b/os/net/mac/ble/ble-l2cap.c @@ -512,7 +512,6 @@ const struct mac_driver ble_l2cap_driver = { input, on, off, - NULL, }; /*---------------------------------------------------------------------------*/ PROCESS_THREAD(ble_l2cap_tx_process, ev, data) diff --git a/os/net/mac/csma/csma-output.c b/os/net/mac/csma/csma-output.c index 9c88d569d..1773e0cb0 100644 --- a/os/net/mac/csma/csma-output.c +++ b/os/net/mac/csma/csma-output.c @@ -50,11 +50,6 @@ #include "lib/list.h" #include "lib/memb.h" -#if CONTIKI_TARGET_COOJA -#include "lib/simEnvChange.h" -#include "sys/cooja_mt.h" -#endif /* CONTIKI_TARGET_COOJA */ - /* Log configuration */ #include "sys/log.h" #define LOG_MODULE "CSMA" @@ -201,17 +196,10 @@ send_one_packet(void *ptr) if(is_broadcast) { ret = MAC_TX_OK; } else { - rtimer_clock_t wt; - /* Check for ack */ - wt = RTIMER_NOW(); - watchdog_periodic(); - while(RTIMER_CLOCK_LT(RTIMER_NOW(), wt + CSMA_ACK_WAIT_TIME)) { -#if CONTIKI_TARGET_COOJA - simProcessRunValue = 1; - cooja_mt_yield(); -#endif /* CONTIKI_TARGET_COOJA */ - } + + /* Wait for max CSMA_ACK_WAIT_TIME */ + RTIMER_BUSYWAIT_UNTIL(NETSTACK_RADIO.pending_packet(), CSMA_ACK_WAIT_TIME); ret = MAC_TX_NOACK; if(NETSTACK_RADIO.receiving_packet() || @@ -220,17 +208,8 @@ send_one_packet(void *ptr) int len; uint8_t ackbuf[CSMA_ACK_LEN]; - if(CSMA_AFTER_ACK_DETECTED_WAIT_TIME > 0) { - wt = RTIMER_NOW(); - watchdog_periodic(); - while(RTIMER_CLOCK_LT(RTIMER_NOW(), - wt + CSMA_AFTER_ACK_DETECTED_WAIT_TIME)) { -#if CONTIKI_TARGET_COOJA - simProcessRunValue = 1; - cooja_mt_yield(); -#endif /* CONTIKI_TARGET_COOJA */ - } - } + /* Wait an additional CSMA_AFTER_ACK_DETECTED_WAIT_TIME to complete reception */ + RTIMER_BUSYWAIT_UNTIL(NETSTACK_RADIO.pending_packet(), CSMA_AFTER_ACK_DETECTED_WAIT_TIME); if(NETSTACK_RADIO.pending_packet()) { len = NETSTACK_RADIO.read(ackbuf, CSMA_ACK_LEN); diff --git a/os/net/mac/framer/framer-802154.c b/os/net/mac/framer/framer-802154.c index 7122c5ccd..b4c24da19 100644 --- a/os/net/mac/framer/framer-802154.c +++ b/os/net/mac/framer/framer-802154.c @@ -171,7 +171,6 @@ framer_802154_setup_params(packetbuf_attr_t (*get_attr)(uint8_t type), #if LLSEC802154_USES_EXPLICIT_KEYS params->aux_hdr.security_control.key_id_mode = get_attr(PACKETBUF_ATTR_KEY_ID_MODE); params->aux_hdr.key_index = get_attr(PACKETBUF_ATTR_KEY_INDEX); - params->aux_hdr.key_source.u16[0] = get_attr(PACKETBUF_ATTR_KEY_SOURCE_BYTES_0_1); #endif /* LLSEC802154_USES_EXPLICIT_KEYS */ #else params->fcf.security_enabled = 0; @@ -273,7 +272,6 @@ parse(void) #if LLSEC802154_USES_EXPLICIT_KEYS packetbuf_set_attr(PACKETBUF_ATTR_KEY_ID_MODE, frame.aux_hdr.security_control.key_id_mode); packetbuf_set_attr(PACKETBUF_ATTR_KEY_INDEX, frame.aux_hdr.key_index); - packetbuf_set_attr(PACKETBUF_ATTR_KEY_SOURCE_BYTES_0_1, frame.aux_hdr.key_source.u16[0]); #endif /* LLSEC802154_USES_EXPLICIT_KEYS */ } #endif /* LLSEC802154_USES_AUX_HEADER */ diff --git a/os/net/mac/mac.h b/os/net/mac/mac.h index ce68d46c7..4f2a75b15 100644 --- a/os/net/mac/mac.h +++ b/os/net/mac/mac.h @@ -43,6 +43,14 @@ #include "contiki.h" #include "dev/radio.h" +/** + *\brief The default channel for IEEE 802.15.4 networks. + */ +#ifdef IEEE802154_CONF_DEFAULT_CHANNEL +#define IEEE802154_DEFAULT_CHANNEL IEEE802154_CONF_DEFAULT_CHANNEL +#else /* IEEE802154_CONF_DEFAULT_CHANNEL */ +#define IEEE802154_DEFAULT_CHANNEL 26 +#endif /* IEEE802154_CONF_DEFAULT_CHANNEL */ typedef void (* mac_callback_t)(void *ptr, int status, int transmissions); diff --git a/os/net/mac/tsch/tsch-adaptive-timesync.c b/os/net/mac/tsch/tsch-adaptive-timesync.c index a23a4f1b0..cf10e9cf1 100644 --- a/os/net/mac/tsch/tsch-adaptive-timesync.c +++ b/os/net/mac/tsch/tsch-adaptive-timesync.c @@ -109,7 +109,9 @@ timesync_learn_drift_ticks(uint32_t time_delta_asn, int32_t drift_ticks) TSCH_LOG_ADD(tsch_log_message, snprintf(log->message, sizeof(log->message), - "drift %ld", tsch_adaptive_timesync_get_drift_ppm())); + "drift %ld ppm (min/max delta seen: %"PRId32"/%"PRId32")", + tsch_adaptive_timesync_get_drift_ppm(), + min_drift_seen, max_drift_seen)); } /*---------------------------------------------------------------------------*/ /* Either reset or update the neighbor's drift */ @@ -136,6 +138,8 @@ tsch_timesync_update(struct tsch_neighbor *n, uint16_t time_delta_asn, int32_t d compensated_ticks += drift_correction; } } + min_drift_seen = MIN(drift_correction, min_drift_seen); + max_drift_seen = MAX(drift_correction, max_drift_seen); } /*---------------------------------------------------------------------------*/ /* Error-accumulation free compensation algorithm */ diff --git a/os/net/mac/tsch/tsch-conf.h b/os/net/mac/tsch/tsch-conf.h index 3ee47b9cb..76e463a0c 100644 --- a/os/net/mac/tsch/tsch-conf.h +++ b/os/net/mac/tsch/tsch-conf.h @@ -151,7 +151,7 @@ #ifdef TSCH_CONF_HOPPING_SEQUENCE_MAX_LEN #define TSCH_HOPPING_SEQUENCE_MAX_LEN TSCH_CONF_HOPPING_SEQUENCE_MAX_LEN #else -#define TSCH_HOPPING_SEQUENCE_MAX_LEN 16 +#define TSCH_HOPPING_SEQUENCE_MAX_LEN sizeof(TSCH_DEFAULT_HOPPING_SEQUENCE) #endif /******** Configuration: association *******/ @@ -317,6 +317,15 @@ #define TSCH_SCHEDULE_WITH_6TISCH_MINIMAL (!(BUILD_WITH_ORCHESTRA)) #endif +/* Set an upper bound on burst length. Set to 0 to never set the frame pending + * bit, i.e., never trigger a burst. Note that receiver-side support for burst + * is always enabled, as it is part of IEEE 802.1.5.4-2015 (Section 7.2.1.3)*/ +#ifdef TSCH_CONF_BURST_MAX_LEN +#define TSCH_BURST_MAX_LEN TSCH_CONF_BURST_MAX_LEN +#else +#define TSCH_BURST_MAX_LEN 32 +#endif + /* 6TiSCH Minimal schedule slotframe length */ #ifdef TSCH_SCHEDULE_CONF_DEFAULT_LENGTH #define TSCH_SCHEDULE_DEFAULT_LENGTH TSCH_SCHEDULE_CONF_DEFAULT_LENGTH @@ -356,18 +365,21 @@ /******** Configuration: CSMA *******/ /* TSCH CSMA-CA parameters, see IEEE 802.15.4e-2012 */ + /* Min backoff exponent */ #ifdef TSCH_CONF_MAC_MIN_BE #define TSCH_MAC_MIN_BE TSCH_CONF_MAC_MIN_BE #else #define TSCH_MAC_MIN_BE 1 #endif + /* Max backoff exponent */ #ifdef TSCH_CONF_MAC_MAX_BE #define TSCH_MAC_MAX_BE TSCH_CONF_MAC_MAX_BE #else #define TSCH_MAC_MAX_BE 5 #endif + /* Max number of re-transmissions */ #ifdef TSCH_CONF_MAC_MAX_FRAME_RETRIES #define TSCH_MAC_MAX_FRAME_RETRIES TSCH_CONF_MAC_MAX_FRAME_RETRIES @@ -382,6 +394,13 @@ #define TSCH_PACKET_EACK_WITH_SRC_ADDR 0 #endif +/* Perform CCA before sending? */ +#ifdef TSCH_CONF_CCA_ENABLED +#define TSCH_CCA_ENABLED TSCH_CONF_CCA_ENABLED +#else +#define TSCH_CCA_ENABLED 0 +#endif + /* Include destination address in ACK? */ #ifdef TSCH_PACKET_CONF_EACK_WITH_DEST_ADDR #define TSCH_PACKET_EACK_WITH_DEST_ADDR TSCH_PACKET_CONF_EACK_WITH_DEST_ADDR @@ -406,12 +425,12 @@ by default, useful in case of duplicate seqno */ #define TSCH_RADIO_ON_DURING_TIMESLOT 0 #endif - - -/* Timeslot timing */ -#ifndef TSCH_CONF_DEFAULT_TIMESLOT_LENGTH -#define TSCH_CONF_DEFAULT_TIMESLOT_LENGTH 10000 -#endif /* TSCH_CONF_DEFAULT_TIMESLOT_LENGTH */ +/* TSCH timeslot timing template */ +#ifdef TSCH_CONF_DEFAULT_TIMESLOT_TIMING +#define TSCH_DEFAULT_TIMESLOT_TIMING TSCH_CONF_DEFAULT_TIMESLOT_TIMING +#else +#define TSCH_DEFAULT_TIMESLOT_TIMING tsch_timeslot_timing_us_10000 +#endif /* Configurable Rx guard time is micro-seconds */ #ifndef TSCH_CONF_RX_WAIT diff --git a/os/net/mac/tsch/tsch-const.h b/os/net/mac/tsch/tsch-const.h index 81ca7ffa8..d158c802c 100644 --- a/os/net/mac/tsch/tsch-const.h +++ b/os/net/mac/tsch/tsch-const.h @@ -75,87 +75,14 @@ #define TSCH_TIMESYNC_MEASUREMENT_ERROR US_TO_RTIMERTICKS(32) /* The approximate number of slots per second */ -#define TSCH_SLOTS_PER_SECOND (1000000 / TSCH_DEFAULT_TS_TIMESLOT_LENGTH) +#define TSCH_SLOTS_PER_SECOND (1000000 / tsch_timing_us[tsch_ts_timeslot_length]) -/* Calculate packet tx/rx duration in rtimer ticks based on sent - * packet len in bytes with 802.15.4 250kbps data rate. - * One byte = 32us. Add two bytes for CRC and one for len field */ -#define TSCH_PACKET_DURATION(len) US_TO_RTIMERTICKS(32 * ((len) + 3)) +/* Calculate packet tx/rx duration in rtimer ticks based on packet length in bytes. */ +#define TSCH_PACKET_DURATION(len) US_TO_RTIMERTICKS(RADIO_BYTE_AIR_TIME * ((len) + RADIO_PHY_OVERHEAD)) /* Convert rtimer ticks to clock and vice versa */ #define TSCH_CLOCK_TO_TICKS(c) (((c) * RTIMER_SECOND) / CLOCK_SECOND) #define TSCH_CLOCK_TO_SLOTS(c, timeslot_length) (TSCH_CLOCK_TO_TICKS(c) / timeslot_length) -/* The default timeslot timing in the standard is a guard time of - * 2200 us, a Tx offset of 2120 us and a Rx offset of 1120 us. - * As a result, the listening device has a guard time not centered - * on the expected Tx time. This is to be fixed in the next iteration - * of the standard. This can be enabled with: - * #define TSCH_DEFAULT_TS_TX_OFFSET 2120 - * #define TSCH_DEFAULT_TS_RX_OFFSET 1120 - * #define TSCH_DEFAULT_TS_RX_WAIT 2200 - * - * Instead, we align the Rx guard time on expected Tx time. The Rx - * guard time is user-configurable with TSCH_CONF_RX_WAIT. - - * (TS_TX_OFFSET - (TS_RX_WAIT / 2)) instead */ - -#if TSCH_CONF_DEFAULT_TIMESLOT_LENGTH == 10000 -/* Default timeslot timing as per IEEE 802.15.4e */ - -#define TSCH_DEFAULT_TS_CCA_OFFSET 1800 -#define TSCH_DEFAULT_TS_CCA 128 -#define TSCH_DEFAULT_TS_TX_OFFSET 2120 -#define TSCH_DEFAULT_TS_RX_OFFSET (TSCH_DEFAULT_TS_TX_OFFSET - (TSCH_CONF_RX_WAIT / 2)) -#define TSCH_DEFAULT_TS_RX_ACK_DELAY 800 -#define TSCH_DEFAULT_TS_TX_ACK_DELAY 1000 -#define TSCH_DEFAULT_TS_RX_WAIT TSCH_CONF_RX_WAIT -#define TSCH_DEFAULT_TS_ACK_WAIT 400 -#define TSCH_DEFAULT_TS_RX_TX 192 -#define TSCH_DEFAULT_TS_MAX_ACK 2400 -#define TSCH_DEFAULT_TS_MAX_TX 4256 -#define TSCH_DEFAULT_TS_TIMESLOT_LENGTH 10000 - -#elif TSCH_CONF_DEFAULT_TIMESLOT_LENGTH == 15000 -/* Default timeslot timing for platforms requiring 15ms slots */ - -#define TSCH_DEFAULT_TS_CCA_OFFSET 1800 -#define TSCH_DEFAULT_TS_CCA 128 -#define TSCH_DEFAULT_TS_TX_OFFSET 4000 -#define TSCH_DEFAULT_TS_RX_OFFSET (TSCH_DEFAULT_TS_TX_OFFSET - (TSCH_CONF_RX_WAIT / 2)) -#define TSCH_DEFAULT_TS_RX_ACK_DELAY 3600 -#define TSCH_DEFAULT_TS_TX_ACK_DELAY 4000 -#define TSCH_DEFAULT_TS_RX_WAIT TSCH_CONF_RX_WAIT -#define TSCH_DEFAULT_TS_ACK_WAIT 800 -#define TSCH_DEFAULT_TS_RX_TX 2072 -#define TSCH_DEFAULT_TS_MAX_ACK 2400 -#define TSCH_DEFAULT_TS_MAX_TX 4256 -#define TSCH_DEFAULT_TS_TIMESLOT_LENGTH 15000 - -#elif TSCH_CONF_DEFAULT_TIMESLOT_LENGTH == 65000U -/* 65ms timeslot, i.e. nearly the max length allowed by standard (16-bit unsigned in micro-seconds). - * Useful for running link-layer security on sky in Cooja, where only S/W security is supported. - * Note: this slot timing would require a total of 120ms. If a slot overlaps with the next active slot, - * the latter will be skipped. - * This configuration is mostly a work-around to test link-layer security in Cooja, it is recommended - * to use it with a 6TiSCH minimal schedule of length >= 2. */ - -#define TSCH_DEFAULT_TS_CCA_OFFSET 1800 -#define TSCH_DEFAULT_TS_CCA 128 -#define TSCH_DEFAULT_TS_TX_OFFSET 52000 -#define TSCH_DEFAULT_TS_RX_OFFSET (TSCH_DEFAULT_TS_TX_OFFSET - (TSCH_CONF_RX_WAIT / 2)) -#define TSCH_DEFAULT_TS_RX_ACK_DELAY 58600 -#define TSCH_DEFAULT_TS_TX_ACK_DELAY 59000 -#define TSCH_DEFAULT_TS_RX_WAIT TSCH_CONF_RX_WAIT -#define TSCH_DEFAULT_TS_ACK_WAIT 800 -#define TSCH_DEFAULT_TS_RX_TX 2072 -#define TSCH_DEFAULT_TS_MAX_ACK 2400 -#define TSCH_DEFAULT_TS_MAX_TX 4256 -#define TSCH_DEFAULT_TS_TIMESLOT_LENGTH 65000 - -#else -#error "TSCH: Unsupported default timeslot length" -#endif - #endif /* __TSCH_CONST_H__ */ /** @} */ diff --git a/os/net/mac/tsch/tsch-log.c b/os/net/mac/tsch/tsch-log.c index d27dac064..e705f50ab 100644 --- a/os/net/mac/tsch/tsch-log.c +++ b/os/net/mac/tsch/tsch-log.c @@ -82,10 +82,11 @@ tsch_log_process_pending(void) printf("[INFO: TSCH-LOG ] {asn %02x.%08lx link-NULL} ", log->asn.ms1b, log->asn.ls4b); } else { struct tsch_slotframe *sf = tsch_schedule_get_slotframe_by_handle(log->link->slotframe_handle); - printf("[INFO: TSCH-LOG ] {asn %02x.%08lx link %2u %3u %3u %2u ch %2u} ", + printf("[INFO: TSCH-LOG ] {asn %02x.%08lx link %2u %3u %3u %2u %2u ch %2u} ", log->asn.ms1b, log->asn.ls4b, - log->link->slotframe_handle, sf ? sf->size.val : 0, log->link->timeslot, log->link->channel_offset, - tsch_calculate_channel(&log->asn, log->link->channel_offset)); + log->link->slotframe_handle, sf ? sf->size.val : 0, + log->burst_count, log->link->timeslot + log->burst_count, log->link->channel_offset, + log->channel); } switch(log->type) { case tsch_log_tx: @@ -135,6 +136,8 @@ tsch_log_prepare_add(void) struct tsch_log_t *log = &log_array[log_index]; log->asn = tsch_current_asn; log->link = current_link; + log->burst_count = tsch_current_burst_count; + log->channel = tsch_current_channel; return log; } else { log_dropped++; diff --git a/os/net/mac/tsch/tsch-log.h b/os/net/mac/tsch/tsch-log.h index 468eff869..186cda120 100644 --- a/os/net/mac/tsch/tsch-log.h +++ b/os/net/mac/tsch/tsch-log.h @@ -80,6 +80,8 @@ struct tsch_log_t { } type; struct tsch_asn_t asn; struct tsch_link *link; + uint8_t burst_count; + uint8_t channel; union { char message[48]; struct { diff --git a/os/net/mac/tsch/tsch-packet.c b/os/net/mac/tsch/tsch-packet.c index 64f03b588..133e9a668 100644 --- a/os/net/mac/tsch/tsch-packet.c +++ b/os/net/mac/tsch/tsch-packet.c @@ -70,6 +70,9 @@ */ static struct packetbuf_attr eackbuf_attrs[PACKETBUF_NUM_ATTRS]; +/* The offset of the frame pending bit flag within the first byte of FCF */ +#define IEEE802154_FRAME_PENDING_BIT_OFFSET 4 + /*---------------------------------------------------------------------------*/ static int tsch_packet_eackbuf_set_attr(uint8_t type, const packetbuf_attr_t val) @@ -459,4 +462,18 @@ tsch_packet_parse_eb(const uint8_t *buf, int buf_size, return curr_len; } /*---------------------------------------------------------------------------*/ +/* Set frame pending bit in a packet (whose header was already build) */ +void +tsch_packet_set_frame_pending(uint8_t *buf, int buf_size) +{ + buf[0] |= (1 << IEEE802154_FRAME_PENDING_BIT_OFFSET); +} +/*---------------------------------------------------------------------------*/ +/* Get frame pending bit from a packet */ +int +tsch_packet_get_frame_pending(uint8_t *buf, int buf_size) +{ + return (buf[0] >> IEEE802154_FRAME_PENDING_BIT_OFFSET) & 1; +} +/*---------------------------------------------------------------------------*/ /** @} */ diff --git a/os/net/mac/tsch/tsch-packet.h b/os/net/mac/tsch/tsch-packet.h index 6b05d6653..cdf7c7bed 100644 --- a/os/net/mac/tsch/tsch-packet.h +++ b/os/net/mac/tsch/tsch-packet.h @@ -101,6 +101,19 @@ int tsch_packet_update_eb(uint8_t *buf, int buf_size, uint8_t tsch_sync_ie_offse int tsch_packet_parse_eb(const uint8_t *buf, int buf_size, frame802154_t *frame, struct ieee802154_ies *ies, uint8_t *hdrlen, int frame_without_mic); +/** + * \brief Set frame pending bit in a packet (whose header was already build) + * \param buf The buffer where the packet resides + * \param buf_size The buffer size + */ +void tsch_packet_set_frame_pending(uint8_t *buf, int buf_size); +/** + * \brief Get frame pending bit from a packet + * \param buf The buffer where the packet resides + * \param buf_size The buffer size + * \return The value of the frame pending bit, 1 or 0 + */ +int tsch_packet_get_frame_pending(uint8_t *buf, int buf_size); #endif /* __TSCH_PACKET_H__ */ /** @} */ diff --git a/os/net/mac/tsch/tsch-queue.c b/os/net/mac/tsch/tsch-queue.c index 4ef5130fb..f586ac90e 100644 --- a/os/net/mac/tsch/tsch-queue.c +++ b/os/net/mac/tsch/tsch-queue.c @@ -173,6 +173,8 @@ tsch_queue_update_time_source(const linkaddr_t *new_addr) old_time_src->is_time_source = 0; } + tsch_stats_reset_neighbor_stats(); + #ifdef TSCH_CALLBACK_NEW_TIME_SOURCE TSCH_CALLBACK_NEW_TIME_SOURCE(old_time_src, new_time_src); #endif diff --git a/os/net/mac/tsch/tsch-schedule.c b/os/net/mac/tsch/tsch-schedule.c index 70a6b92ae..3785cacb2 100644 --- a/os/net/mac/tsch/tsch-schedule.c +++ b/os/net/mac/tsch/tsch-schedule.c @@ -171,6 +171,45 @@ tsch_schedule_get_link_by_handle(uint16_t handle) return NULL; } /*---------------------------------------------------------------------------*/ +static const char * +print_link_options(uint16_t link_options) +{ + static char buffer[20]; + unsigned length; + + buffer[0] = '\0'; + if(link_options & LINK_OPTION_TX) { + strcat(buffer, "Tx|"); + } + if(link_options & LINK_OPTION_RX) { + strcat(buffer, "Rx|"); + } + if(link_options & LINK_OPTION_SHARED) { + strcat(buffer, "Sh|"); + } + length = strlen(buffer); + if(length > 0) { + buffer[length - 1] = '\0'; + } + + return buffer; +} +/*---------------------------------------------------------------------------*/ +static const char * +print_link_type(uint16_t link_type) +{ + switch(link_type) { + case LINK_TYPE_NORMAL: + return "NORMAL"; + case LINK_TYPE_ADVERTISING: + return "ADV"; + case LINK_TYPE_ADVERTISING_ONLY: + return "ADV_ONLY"; + default: + return "?"; + } +} +/*---------------------------------------------------------------------------*/ /* Adds a link to a slotframe, return a pointer to it (NULL if failure) */ struct tsch_link * tsch_schedule_add_link(struct tsch_slotframe *slotframe, @@ -218,8 +257,10 @@ tsch_schedule_add_link(struct tsch_slotframe *slotframe, } linkaddr_copy(&l->addr, address); - LOG_INFO("add_link %u %u %u %u %u ", - slotframe->handle, link_options, link_type, timeslot, channel_offset); + LOG_INFO("add_link sf=%u opt=%s type=%s ts=%u ch=%u addr=", + slotframe->handle, + print_link_options(link_options), + print_link_type(link_type), timeslot, channel_offset); LOG_INFO_LLADDR(address); LOG_INFO_("\n"); /* Release the lock before we update the neighbor (will take the lock) */ @@ -260,8 +301,10 @@ tsch_schedule_remove_link(struct tsch_slotframe *slotframe, struct tsch_link *l) if(l == current_link) { current_link = NULL; } - LOG_INFO("remove_link %u %u %u %u ", - slotframe->handle, l->link_options, l->timeslot, l->channel_offset); + LOG_INFO("remove_link sf=%u opt=%s type=%s ts=%u ch=%u addr=", + slotframe->handle, + print_link_options(l->link_options), + print_link_type(l->link_type), l->timeslot, l->channel_offset); LOG_INFO_LLADDR(&l->addr); LOG_INFO_("\n"); @@ -423,7 +466,7 @@ tsch_schedule_create_minimal(void) * but is required according to 802.15.4e if also used for EB transmission. * Timeslot: 0, channel offset: 0. */ tsch_schedule_add_link(sf_min, - LINK_OPTION_RX | LINK_OPTION_TX | LINK_OPTION_SHARED | LINK_OPTION_TIME_KEEPING, + (LINK_OPTION_RX | LINK_OPTION_TX | LINK_OPTION_SHARED | LINK_OPTION_TIME_KEEPING), LINK_TYPE_ADVERTISING, &tsch_broadcast_address, 0, 0); } diff --git a/os/net/mac/tsch/tsch-security.c b/os/net/mac/tsch/tsch-security.c index 1c4266626..12f0de6d5 100644 --- a/os/net/mac/tsch/tsch-security.c +++ b/os/net/mac/tsch/tsch-security.c @@ -53,6 +53,10 @@ #include #include +#if LLSEC802154_ENABLED && !LLSEC802154_USES_EXPLICIT_KEYS +#error LLSEC802154_ENABLED set but LLSEC802154_USES_EXPLICIT_KEYS unset +#endif /* LLSEC802154_ENABLED */ + /* The two keys K1 and K2 from 6TiSCH minimal configuration * K1: well-known, used for EBs * K2: secret, used for data and ACK diff --git a/os/net/mac/tsch/tsch-security.h b/os/net/mac/tsch/tsch-security.h index 56c854414..4320d3a70 100644 --- a/os/net/mac/tsch/tsch-security.h +++ b/os/net/mac/tsch/tsch-security.h @@ -54,10 +54,6 @@ * - set LLSEC802154_CONF_USES_EXPLICIT_KEYS * */ -#if LLSEC802154_ENABLED && !LLSEC802154_USES_EXPLICIT_KEYS -#error LLSEC802154_ENABLED set but LLSEC802154_USES_EXPLICIT_KEYS unset -#endif /* LLSEC802154_ENABLED */ - /* K1, defined in 6TiSCH minimal, is well-known (offers no security) and used for EBs only */ #ifdef TSCH_SECURITY_CONF_K1 #define TSCH_SECURITY_K1 TSCH_SECURITY_CONF_K1 diff --git a/os/net/mac/tsch/tsch-slot-operation.c b/os/net/mac/tsch/tsch-slot-operation.c index c4bb25e88..a801bc92e 100644 --- a/os/net/mac/tsch/tsch-slot-operation.c +++ b/os/net/mac/tsch/tsch-slot-operation.c @@ -52,10 +52,6 @@ #include "net/queuebuf.h" #include "net/mac/framer/framer-802154.h" #include "net/mac/tsch/tsch.h" -#if CONTIKI_TARGET_COOJA -#include "lib/simEnvChange.h" -#include "sys/cooja_mt.h" -#endif /* CONTIKI_TARGET_COOJA */ #include "sys/log.h" /* TSCH debug macros, i.e. to set LEDs or GPIOs on various TSCH @@ -94,7 +90,7 @@ /* Truncate received drift correction information to maximum half * of the guard time (one fourth of TSCH_DEFAULT_TS_RX_WAIT) */ -#define SYNC_IE_BOUND ((int32_t)US_TO_RTIMERTICKS(TSCH_DEFAULT_TS_RX_WAIT / 4)) +#define SYNC_IE_BOUND ((int32_t)US_TO_RTIMERTICKS(tsch_timing_us[tsch_ts_rx_wait] / 4)) /* By default: check that rtimer runs at >=32kHz and use a guard time of 10us */ #if RTIMER_SECOND < (32 * 1024) @@ -155,7 +151,7 @@ static rtimer_clock_t volatile current_slot_start; static volatile int tsch_in_slot_operation = 0; /* If we are inside a slot, this tells the current channel */ -static uint8_t current_channel; +uint8_t tsch_current_channel; /* Info about the link, packet and neighbor of * the current (or next) slot */ @@ -167,6 +163,11 @@ static struct tsch_link *backup_link = NULL; static struct tsch_packet *current_packet = NULL; static struct tsch_neighbor *current_neighbor = NULL; +/* Indicates whether an extra link is needed to handle the current burst */ +static int burst_link_scheduled = 0; +/* Counts the length of the current burst */ +int tsch_current_burst_count = 0; + /* Protothread for association */ PT_THREAD(tsch_scan(struct pt *pt)); /* Protothread for slot operation, called from rtimer interrupt @@ -201,10 +202,7 @@ tsch_get_lock(void) busy_wait = 1; busy_wait_time = RTIMER_NOW(); while(tsch_in_slot_operation) { -#if CONTIKI_TARGET_COOJA - simProcessRunValue = 1; - cooja_mt_yield(); -#endif /* CONTIKI_TARGET_COOJA */ + watchdog_periodic(); } busy_wait_time = RTIMER_NOW() - busy_wait_time; } @@ -298,7 +296,7 @@ tsch_schedule_slot_operation(struct rtimer *tm, rtimer_clock_t ref_time, rtimer_ } /* block until the time to schedule comes */ - BUSYWAIT_UNTIL_ABS(0, ref_time, offset); + RTIMER_BUSYWAIT_UNTIL_ABS(0, ref_time, offset); return 0; } /*---------------------------------------------------------------------------*/ @@ -309,7 +307,7 @@ tsch_schedule_slot_operation(struct rtimer *tm, rtimer_clock_t ref_time, rtimer_ do { \ if(tsch_schedule_slot_operation(tm, ref_time, offset - RTIMER_GUARD, str)) { \ PT_YIELD(pt); \ - BUSYWAIT_UNTIL_ABS(0, ref_time, offset); \ + RTIMER_BUSYWAIT_UNTIL_ABS(0, ref_time, offset); \ } \ } while(0); /*---------------------------------------------------------------------------*/ @@ -456,16 +454,26 @@ PT_THREAD(tsch_tx_slot(struct pt *pt, struct rtimer *t)) /* is this a broadcast packet? (wait for ack?) */ static uint8_t is_broadcast; static rtimer_clock_t tx_start_time; + /* Did we set the frame pending bit to request an extra burst link? */ + static int burst_link_requested; -#if CCA_ENABLED +#if TSCH_CCA_ENABLED static uint8_t cca_status; -#endif +#endif /* TSCH_CCA_ENABLED */ /* get payload */ packet = queuebuf_dataptr(current_packet->qb); packet_len = queuebuf_datalen(current_packet->qb); /* is this a broadcast packet? (wait for ack?) */ is_broadcast = current_neighbor->is_broadcast; + /* Unicast. More packets in queue for the neighbor? */ + burst_link_requested = 0; + if(!is_broadcast + && tsch_current_burst_count + 1 < TSCH_BURST_MAX_LEN + && tsch_queue_packet_count(¤t_neighbor->addr) > 1) { + burst_link_requested = 1; + tsch_packet_set_frame_pending(packet, packet_len); + } /* read seqno from payload */ seqno = ((uint8_t *)(packet))[2]; /* if this is an EB, then update its Sync-IE */ @@ -492,22 +500,22 @@ PT_THREAD(tsch_tx_slot(struct pt *pt, struct rtimer *t)) if(packet_ready && NETSTACK_RADIO.prepare(packet, packet_len) == 0) { /* 0 means success */ static rtimer_clock_t tx_duration; -#if CCA_ENABLED +#if TSCH_CCA_ENABLED cca_status = 1; /* delay before CCA */ - TSCH_SCHEDULE_AND_YIELD(pt, t, current_slot_start, TS_CCA_OFFSET, "cca"); + TSCH_SCHEDULE_AND_YIELD(pt, t, current_slot_start, tsch_timing[tsch_ts_cca_offset], "cca"); TSCH_DEBUG_TX_EVENT(); tsch_radio_on(TSCH_RADIO_CMD_ON_WITHIN_TIMESLOT); /* CCA */ - BUSYWAIT_UNTIL_ABS(!(cca_status |= NETSTACK_RADIO.channel_clear()), - current_slot_start, TS_CCA_OFFSET + TS_CCA); + RTIMER_BUSYWAIT_UNTIL_ABS(!(cca_status &= NETSTACK_RADIO.channel_clear()), + current_slot_start, tsch_timing[tsch_ts_cca_offset] + tsch_timing[tsch_ts_cca]); TSCH_DEBUG_TX_EVENT(); /* there is not enough time to turn radio off */ /* NETSTACK_RADIO.off(); */ if(cca_status == 0) { mac_tx_status = MAC_TX_COLLISION; } else -#endif /* CCA_ENABLED */ +#endif /* TSCH_CCA_ENABLED */ { /* delay before TX */ TSCH_SCHEDULE_AND_YIELD(pt, t, current_slot_start, tsch_timing[tsch_ts_tx_offset] - RADIO_DELAY_BEFORE_TX, "TxBeforeTx"); @@ -546,14 +554,14 @@ PT_THREAD(tsch_tx_slot(struct pt *pt, struct rtimer *t)) TSCH_DEBUG_TX_EVENT(); tsch_radio_on(TSCH_RADIO_CMD_ON_WITHIN_TIMESLOT); /* Wait for ACK to come */ - BUSYWAIT_UNTIL_ABS(NETSTACK_RADIO.receiving_packet(), + RTIMER_BUSYWAIT_UNTIL_ABS(NETSTACK_RADIO.receiving_packet(), tx_start_time, tx_duration + tsch_timing[tsch_ts_rx_ack_delay] + tsch_timing[tsch_ts_ack_wait] + RADIO_DELAY_BEFORE_DETECT); TSCH_DEBUG_TX_EVENT(); ack_start_time = RTIMER_NOW() - RADIO_DELAY_BEFORE_DETECT; /* Wait for ACK to finish */ - BUSYWAIT_UNTIL_ABS(!NETSTACK_RADIO.receiving_packet(), + RTIMER_BUSYWAIT_UNTIL_ABS(!NETSTACK_RADIO.receiving_packet(), ack_start_time, tsch_timing[tsch_ts_max_ack]); TSCH_DEBUG_TX_EVENT(); tsch_radio_off(TSCH_RADIO_CMD_OFF_WITHIN_TIMESLOT); @@ -610,6 +618,7 @@ PT_THREAD(tsch_tx_slot(struct pt *pt, struct rtimer *t)) "!truncated dr %d %d", (int)eack_time_correction, (int)drift_correction); ); } + tsch_stats_on_time_synchronization(eack_time_correction); is_drift_correction_used = 1; tsch_timesync_update(current_neighbor, since_last_timesync, drift_correction); /* Keep track of sync time */ @@ -618,6 +627,12 @@ PT_THREAD(tsch_tx_slot(struct pt *pt, struct rtimer *t)) tsch_schedule_keepalive(); } mac_tx_status = MAC_TX_OK; + + /* We requested an extra slot and got an ack. This means + the extra slot will be scheduled at the received */ + if(burst_link_requested) { + burst_link_scheduled = 1; + } } else { mac_tx_status = MAC_TX_NOACK; } @@ -628,6 +643,8 @@ PT_THREAD(tsch_tx_slot(struct pt *pt, struct rtimer *t)) mac_tx_status = MAC_TX_ERR; } } + } else { + mac_tx_status = MAC_TX_ERR; } } @@ -645,6 +662,11 @@ PT_THREAD(tsch_tx_slot(struct pt *pt, struct rtimer *t)) ringbufindex_put(&dequeued_ringbuf); } + /* If this is an unicast packet to timesource, update stats */ + if(current_neighbor != NULL && current_neighbor->is_time_source) { + tsch_stats_tx_packet(current_neighbor, mac_tx_status, tsch_current_channel); + } + /* Log every tx attempt */ TSCH_LOG_ADD(tsch_log_tx, log->tx.mac_tx_status = mac_tx_status; @@ -721,7 +743,7 @@ PT_THREAD(tsch_rx_slot(struct pt *pt, struct rtimer *t)) packet_seen = NETSTACK_RADIO.receiving_packet() || NETSTACK_RADIO.pending_packet(); if(!packet_seen) { /* Check if receiving within guard time */ - BUSYWAIT_UNTIL_ABS((packet_seen = NETSTACK_RADIO.receiving_packet()), + RTIMER_BUSYWAIT_UNTIL_ABS((packet_seen = NETSTACK_RADIO.receiving_packet()), current_slot_start, tsch_timing[tsch_ts_rx_offset] + tsch_timing[tsch_ts_rx_wait] + RADIO_DELAY_BEFORE_DETECT); } if(!packet_seen) { @@ -733,7 +755,7 @@ PT_THREAD(tsch_rx_slot(struct pt *pt, struct rtimer *t)) rx_start_time = RTIMER_NOW() - RADIO_DELAY_BEFORE_DETECT; /* Wait until packet is received, turn radio off */ - BUSYWAIT_UNTIL_ABS(!NETSTACK_RADIO.receiving_packet(), + RTIMER_BUSYWAIT_UNTIL_ABS(!NETSTACK_RADIO.receiving_packet(), current_slot_start, tsch_timing[tsch_ts_rx_offset] + tsch_timing[tsch_ts_rx_wait] + tsch_timing[tsch_ts_max_tx]); TSCH_DEBUG_RX_EVENT(); tsch_radio_off(TSCH_RADIO_CMD_OFF_WITHIN_TIMESLOT); @@ -743,13 +765,14 @@ PT_THREAD(tsch_rx_slot(struct pt *pt, struct rtimer *t)) static int header_len; static frame802154_t frame; radio_value_t radio_last_rssi; + radio_value_t radio_last_lqi; /* Read packet */ current_input->len = NETSTACK_RADIO.read((void *)current_input->payload, TSCH_PACKET_MAX_LEN); NETSTACK_RADIO.get_value(RADIO_PARAM_LAST_RSSI, &radio_last_rssi); current_input->rx_asn = tsch_current_asn; current_input->rssi = (signed)radio_last_rssi; - current_input->channel = current_channel; + current_input->channel = tsch_current_channel; header_len = frame802154_parse((uint8_t *)current_input->payload, current_input->len, &frame); frame_valid = header_len > 0 && frame802154_check_dest_panid(&frame) && @@ -761,6 +784,8 @@ PT_THREAD(tsch_rx_slot(struct pt *pt, struct rtimer *t)) #endif packet_duration = TSCH_PACKET_DURATION(current_input->len); + /* limit packet_duration to its max value */ + packet_duration = MIN(packet_duration, tsch_timing[tsch_ts_max_tx]); if(!frame_valid) { TSCH_LOG_ADD(tsch_log_message, @@ -800,6 +825,7 @@ PT_THREAD(tsch_rx_slot(struct pt *pt, struct rtimer *t)) int do_nack = 0; rx_count++; estimated_drift = RTIMER_CLOCK_DIFF(expected_rx_time, rx_start_time); + tsch_stats_on_time_synchronization(estimated_drift); #if TSCH_TIMESYNC_REMOVE_JITTER /* remove jitter due to measurement errors */ @@ -844,6 +870,9 @@ PT_THREAD(tsch_rx_slot(struct pt *pt, struct rtimer *t)) TSCH_DEBUG_RX_EVENT(); NETSTACK_RADIO.transmit(ack_len); tsch_radio_off(TSCH_RADIO_CMD_OFF_WITHIN_TIMESLOT); + + /* Schedule a burst link iff the frame pending bit was set */ + burst_link_scheduled = tsch_packet_get_frame_pending(current_input->payload, current_input->len); } } @@ -865,6 +894,12 @@ PT_THREAD(tsch_rx_slot(struct pt *pt, struct rtimer *t)) /* Add current input to ringbuf */ ringbufindex_put(&input_ringbuf); + /* If the neighbor is known, update its stats */ + if(n != NULL) { + NETSTACK_RADIO.get_value(RADIO_PARAM_LAST_LINK_QUALITY, &radio_last_lqi); + tsch_stats_rx_packet(n, current_input->rssi, radio_last_lqi, tsch_current_channel); + } + /* Log every reception */ TSCH_LOG_ADD(tsch_log_rx, linkaddr_copy(&log->rx.src, (linkaddr_t *)&frame.src_addr); @@ -927,6 +962,8 @@ PT_THREAD(tsch_slot_operation(struct rtimer *t, void *ptr)) int is_active_slot; TSCH_DEBUG_SLOT_START(); tsch_in_slot_operation = 1; + /* Measure on-air noise level while TSCH is idle */ + tsch_stats_sample_rssi(); /* Reset drift correction */ drift_correction = 0; is_drift_correction_used = 0; @@ -940,9 +977,16 @@ PT_THREAD(tsch_slot_operation(struct rtimer *t, void *ptr)) } is_active_slot = current_packet != NULL || (current_link->link_options & LINK_OPTION_RX); if(is_active_slot) { - /* Hop channel */ - current_channel = tsch_calculate_channel(&tsch_current_asn, current_link->channel_offset); - NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, current_channel); + /* If we are in a burst, we stick to current channel instead of + * doing channel hopping, as per IEEE 802.15.4-2015 */ + if(burst_link_scheduled) { + /* Reset burst_link_scheduled flag. Will be set again if burst continue. */ + burst_link_scheduled = 0; + } else { + /* Hop channel */ + tsch_current_channel = tsch_calculate_channel(&tsch_current_asn, current_link->channel_offset); + } + NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, tsch_current_channel); /* Turn the radio on already here if configured so; necessary for radios with slow startup */ tsch_radio_on(TSCH_RADIO_CMD_ON_START_OF_TIMESLOT); /* Decide whether it is a TX/RX/IDLE or OFF slot */ @@ -960,6 +1004,10 @@ PT_THREAD(tsch_slot_operation(struct rtimer *t, void *ptr)) static struct pt slot_rx_pt; PT_SPAWN(&slot_operation_pt, &slot_rx_pt, tsch_rx_slot(&slot_rx_pt, t)); } + } else { + /* Make sure to end the burst in cast, for some reason, we were + * in a burst but now without any more packet to send. */ + burst_link_scheduled = 0; } TSCH_DEBUG_SLOT_END(); } @@ -993,13 +1041,27 @@ PT_THREAD(tsch_slot_operation(struct rtimer *t, void *ptr)) tsch_queue_update_all_backoff_windows(¤t_link->addr); } - /* Get next active link */ - current_link = tsch_schedule_get_next_active_link(&tsch_current_asn, ×lot_diff, &backup_link); - if(current_link == NULL) { - /* There is no next link. Fall back to default - * behavior: wake up at the next slot. */ + /* A burst link was scheduled. Replay the current link at the + next time offset */ + if(burst_link_scheduled) { timeslot_diff = 1; + backup_link = NULL; + /* Keep track of the number of repetitions */ + tsch_current_burst_count++; + } else { + /* Get next active link */ + current_link = tsch_schedule_get_next_active_link(&tsch_current_asn, ×lot_diff, &backup_link); + if(current_link == NULL) { + /* There is no next link. Fall back to default + * behavior: wake up at the next slot. */ + timeslot_diff = 1; + } else { + /* Reset burst index now that the link was scheduled from + normal schedule (as opposed to from ongoing burst) */ + tsch_current_burst_count = 0; + } } + /* Update ASN */ TSCH_ASN_INC(tsch_current_asn, timeslot_diff); /* Time to next wake up */ diff --git a/os/net/mac/tsch/tsch-slot-operation.h b/os/net/mac/tsch/tsch-slot-operation.h index 1c71c5587..b1c05697b 100644 --- a/os/net/mac/tsch/tsch-slot-operation.h +++ b/os/net/mac/tsch/tsch-slot-operation.h @@ -57,6 +57,8 @@ extern struct ringbufindex input_ringbuf; extern struct input_packet input_array[TSCH_MAX_INCOMING_PACKETS]; /* Last clock_time_t where synchronization happened */ extern clock_time_t last_sync_time; +/* Counts the length of the current burst */ +extern int tsch_current_burst_count; /********** Functions *********/ diff --git a/os/net/mac/tsch/tsch-stats.c b/os/net/mac/tsch/tsch-stats.c new file mode 100644 index 000000000..474728e6d --- /dev/null +++ b/os/net/mac/tsch/tsch-stats.c @@ -0,0 +1,236 @@ +/* + * Copyright (c) 2016-2017, University of Bristol - http://www.bristol.ac.uk + * + * 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 INSTITUTE 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 INSTITUTE 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 + * Source file for TSCH statistics + * \author + * Atis Elsts + */ + +#include "contiki.h" +#include "net/mac/tsch/tsch.h" +#include "net/netstack.h" +#include "dev/radio.h" + +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "TSCH Stats" +#define LOG_LEVEL LOG_LEVEL_MAC + +/*---------------------------------------------------------------------------*/ +#if TSCH_STATS_ON +/*---------------------------------------------------------------------------*/ + +struct tsch_global_stats tsch_stats; +struct tsch_neighbor_stats tsch_neighbor_stats; + +/* Called every TSCH_STATS_DECAY_INTERVAL ticks */ +static struct ctimer periodic_timer; + +static void periodic(void *); + +/*---------------------------------------------------------------------------*/ +void +tsch_stats_init(void) +{ +#if TSCH_STATS_SAMPLE_NOISE_RSSI + int i; + + for(i = 0; i < TSCH_STATS_NUM_CHANNELS; ++i) { + tsch_stats.noise_rssi[i] = TSCH_STATS_DEFAULT_RSSI; + tsch_stats.channel_free_ewma[i] = TSCH_STATS_DEFAULT_CHANNEL_FREE; + } +#endif + + tsch_stats_reset_neighbor_stats(); + + /* Start the periodic processing soonish */ + ctimer_set(&periodic_timer, TSCH_STATS_DECAY_INTERVAL / 10, periodic, NULL); +} +/*---------------------------------------------------------------------------*/ +void +tsch_stats_reset_neighbor_stats(void) +{ + int i; + struct tsch_channel_stats *ch_stats; + + ch_stats = tsch_neighbor_stats.channel_stats; + for(i = 0; i < TSCH_STATS_NUM_CHANNELS; ++i) { + ch_stats[i].rssi = TSCH_STATS_DEFAULT_RSSI; + ch_stats[i].lqi = TSCH_STATS_DEFAULT_LQI; + ch_stats[i].p_tx_success = TSCH_STATS_DEFAULT_P_TX; + } +} +/*---------------------------------------------------------------------------*/ +struct tsch_neighbor_stats * +tsch_stats_get_from_neighbor(struct tsch_neighbor *n) +{ + /* Due to RAM limitations, this module only collects neighbor stats about the time source */ + if(n != NULL && n->is_time_source) { + return &tsch_neighbor_stats; + } + return NULL; +} +/*---------------------------------------------------------------------------*/ +void +tsch_stats_tx_packet(struct tsch_neighbor *n, uint8_t mac_status, uint8_t channel) +{ + struct tsch_neighbor_stats *stats; + + stats = tsch_stats_get_from_neighbor(n); + if(stats != NULL) { + uint8_t index = tsch_stats_channel_to_index(channel); + uint16_t new_tx_value = (mac_status == MAC_TX_OK ? 1 : 0); + new_tx_value *= TSCH_STATS_BINARY_SCALING_FACTOR; + TSCH_STATS_EWMA_UPDATE(stats->channel_stats[index].p_tx_success, new_tx_value); + } +} +/*---------------------------------------------------------------------------*/ +void +tsch_stats_rx_packet(struct tsch_neighbor *n, int8_t rssi, uint8_t lqi, uint8_t channel) +{ + struct tsch_neighbor_stats *stats; + + stats = tsch_stats_get_from_neighbor(n); + if(stats != NULL) { + uint8_t index = tsch_stats_channel_to_index(channel); + + TSCH_STATS_EWMA_UPDATE(stats->channel_stats[index].rssi, + TSCH_STATS_TRANSFORM(rssi, TSCH_STATS_RSSI_SCALING_FACTOR)); + TSCH_STATS_EWMA_UPDATE(stats->channel_stats[index].lqi, + TSCH_STATS_TRANSFORM(lqi, TSCH_STATS_LQI_SCALING_FACTOR)); + } +} +/*---------------------------------------------------------------------------*/ +void +tsch_stats_on_time_synchronization(int32_t sync_error) +{ + /* Update the maximal error so far if the absolute value of the new one is larger */ + tsch_stats.max_sync_error = MAX(tsch_stats.max_sync_error, ABS(sync_error)); +} +/*---------------------------------------------------------------------------*/ +void +tsch_stats_sample_rssi(void) +{ +#if TSCH_STATS_SAMPLE_NOISE_RSSI + uint8_t index; + radio_value_t value; + radio_result_t rv; + + static uint8_t measurement_channel = TSCH_STATS_FIRST_CHANNEL; + + index = tsch_stats_channel_to_index(measurement_channel); + + /* Select the measurement channel */ + NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, measurement_channel); + + /* Need to explicitly turn on for Coojamotes */ + NETSTACK_RADIO.on(); + + /* Measure the background noise RSSI and act on it */ + rv = NETSTACK_RADIO.get_value(RADIO_PARAM_RSSI, &value); + if(rv == RADIO_RESULT_OK) { + tsch_stat_t prev_busyness_metric; + uint16_t is_free; + + is_free = (((int)value <= TSCH_STATS_BUSY_CHANNEL_RSSI) ? 1 : 0) * TSCH_STATS_BINARY_SCALING_FACTOR; + + /* LOG_DBG("noise RSSI on %u: %d\n", measurement_channel, (int)value); */ + + TSCH_STATS_EWMA_UPDATE(tsch_stats.noise_rssi[index], + TSCH_STATS_TRANSFORM((int)value, TSCH_STATS_RSSI_SCALING_FACTOR)); + + prev_busyness_metric = tsch_stats.channel_free_ewma[index]; + (void)prev_busyness_metric; + TSCH_STATS_EWMA_UPDATE(tsch_stats.channel_free_ewma[index], is_free); + + /* potentially select a new TSCH hopping sequence */ +#ifdef TSCH_CALLBACK_CHANNEL_STATS_UPDATED + TSCH_CALLBACK_CHANNEL_STATS_UPDATED(measurement_channel, prev_busyness_metric); +#endif + } else { + LOG_ERR("! sampling RSSI failed: %d\n", (int)rv); + } + + /* Increment the channel index for the next time */ + measurement_channel++; + if(measurement_channel >= TSCH_STATS_FIRST_CHANNEL + TSCH_STATS_NUM_CHANNELS) { + measurement_channel = TSCH_STATS_FIRST_CHANNEL; + } +#endif /* TSCH_STATS_SAMPLE_NOISE_RSSI */ +} +/*---------------------------------------------------------------------------*/ +/* Periodic timer called every TSCH_STATS_DECAY_INTERVAL ticks */ +static void +periodic(void *ptr) +{ + int i; + struct tsch_neighbor *timesource; + struct tsch_channel_stats *stats = tsch_neighbor_stats.channel_stats; + +#if TSCH_STATS_SAMPLE_NOISE_RSSI + LOG_DBG("Noise RSSI:\n"); + for(i = 0; i < TSCH_STATS_NUM_CHANNELS; ++i) { + LOG_DBG(" channel %u: %d rssi, %u/%u free\n", + TSCH_STATS_FIRST_CHANNEL + i, + tsch_stats.noise_rssi[i] / TSCH_STATS_RSSI_SCALING_FACTOR, + tsch_stats.channel_free_ewma[i], + TSCH_STATS_BINARY_SCALING_FACTOR); + } +#endif + + timesource = tsch_queue_get_time_source(); + if(timesource != NULL) { + LOG_DBG("Time source neighbor:\n"); + + for(i = 0; i < TSCH_STATS_NUM_CHANNELS; ++i) { + LOG_DBG(" channel %u: %d rssi, %u lqi, %u/%u P(tx)\n", + TSCH_STATS_FIRST_CHANNEL + i, + stats[i].rssi / TSCH_STATS_RSSI_SCALING_FACTOR, + stats[i].lqi / TSCH_STATS_LQI_SCALING_FACTOR, + stats[i].p_tx_success, + TSCH_STATS_BINARY_SCALING_FACTOR); + } + } + + /* Do not decay the periodic global stats, as they are updated independely of packet rate */ + for(i = 0; i < TSCH_STATS_NUM_CHANNELS; ++i) { + /* decay Rx stats */ + TSCH_STATS_EWMA_UPDATE(stats[i].rssi, TSCH_STATS_DEFAULT_RSSI); + TSCH_STATS_EWMA_UPDATE(stats[i].lqi, TSCH_STATS_DEFAULT_LQI); + /* decay Tx stats */ + TSCH_STATS_EWMA_UPDATE(stats[i].p_tx_success, TSCH_STATS_DEFAULT_P_TX); + } + + ctimer_set(&periodic_timer, TSCH_STATS_DECAY_INTERVAL, periodic, NULL); +} +/*---------------------------------------------------------------------------*/ +#endif /* TSCH_STATS_ON */ +/*---------------------------------------------------------------------------*/ diff --git a/os/net/mac/tsch/tsch-stats.h b/os/net/mac/tsch/tsch-stats.h new file mode 100644 index 000000000..794cf1df1 --- /dev/null +++ b/os/net/mac/tsch/tsch-stats.h @@ -0,0 +1,223 @@ +/* + * Copyright (c) 2016-2017, University of Bristol - http://www.bristol.ac.uk + * + * 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 INSTITUTE 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 INSTITUTE 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 + * Header file for TSCH statistics + * \author + * Atis Elsts + */ + +/** + * \addtogroup tsch + * @{ +*/ + +#ifndef __TSCH_STATS_H__ +#define __TSCH_STATS_H__ + +/********** Includes **********/ + +#include "contiki.h" +#include "net/linkaddr.h" +#include "net/mac/tsch/tsch-conf.h" +#include "net/mac/tsch/tsch-queue.h" + +/************ Constants ***********/ + +/* Enable the collection of TSCH statistics? */ +#ifdef TSCH_STATS_CONF_ON +#define TSCH_STATS_ON TSCH_STATS_CONF_ON +#else +#define TSCH_STATS_ON 0 +#endif + +/* Enable the collection background noise RSSI? */ +#ifdef TSCH_STATS_CONF_SAMPLE_NOISE_RSSI +#define TSCH_STATS_SAMPLE_NOISE_RSSI TSCH_STATS_CONF_SAMPLE_NOISE_RSSI +#else +#define TSCH_STATS_SAMPLE_NOISE_RSSI 0 +#endif + +/* + * How to update a TSCH statistic. + * Uses a hardcoded EWMA alpha value equal to 0.125 by default. + */ +#ifdef TSCH_STATS_CONF_EWMA_UPDATE +#define TSCH_STATS_EWMA_UPDATE TSCH_STATS_CONF_EWMA_UPDATE +#else +#define TSCH_STATS_EWMA_UPDATE(x, v) (x) = (((x) * 7 / 8) + (v) / 8) +#endif + +/* + * A channel is considered busy if at the sampling instant + * it has RSSI higher or equal to this limit. + */ +#ifdef TSCH_STATS_CONF_BUSY_CHANNEL_RSSI +#define TSCH_STATS_BUSY_CHANNEL_RSSI TSCH_STATS_CONF_BUSY_CHANNEL_RSSI +#else +#define TSCH_STATS_BUSY_CHANNEL_RSSI -85 +#endif + +/* The period after which stat values are decayed towards the default values */ +#ifdef TSCH_STATS_CONF_DECAY_INTERVAL +#define TSCH_STATS_DECAY_INTERVAL TSCH_STATS_CONF_DECAY_INTERVAL +#else +#define TSCH_STATS_DECAY_INTERVAL (20ul * 60 * CLOCK_SECOND) +#endif + +/* + * The total number of MAC-layer channels. + * Sixteen for the IEEE802.15.4 2.4 GHz band. + */ +#ifdef TSCH_STATS_CONF_NUM_CHANNELS +#define TSCH_STATS_NUM_CHANNELS TSCH_STATS_CONF_NUM_CHANNELS +#else +#define TSCH_STATS_NUM_CHANNELS 16 +#endif + +/* The number of the first MAC-layer channel. */ +#ifdef TSCH_STATS_CONF_FIRST_CHANNEL +#define TSCH_STATS_FIRST_CHANNEL TSCH_STATS_CONF_FIRST_CHANNEL +#else +#define TSCH_STATS_FIRST_CHANNEL 11 +#endif + +/* Internal: the scaling of the various stats */ +#define TSCH_STATS_RSSI_SCALING_FACTOR -16 +#define TSCH_STATS_LQI_SCALING_FACTOR 16 +#define TSCH_STATS_BINARY_SCALING_FACTOR 4096 + +/* + * Transform a statistic from external form to the internal representation. + * To transform back, simply divide by the factor. + */ +#define TSCH_STATS_TRANSFORM(x, factor) ((int16_t)(x) * factor) + +/* The default value for RSSI statistics: -90 dBm */ +#define TSCH_STATS_DEFAULT_RSSI TSCH_STATS_TRANSFORM(-90, TSCH_STATS_RSSI_SCALING_FACTOR) +/* The default value for LQI statistics: 100 */ +#define TSCH_STATS_DEFAULT_LQI TSCH_STATS_TRANSFORM(100, TSCH_STATS_LQI_SCALING_FACTOR) +/* The default value for P_tx (packet transmission probability) statistics: 50% */ +#define TSCH_STATS_DEFAULT_P_TX (TSCH_STATS_BINARY_SCALING_FACTOR / 2) +/* The default value for channel free status: 100% */ +#define TSCH_STATS_DEFAULT_CHANNEL_FREE TSCH_STATS_BINARY_SCALING_FACTOR + +/* #define these callbacks to do the adaptive channel selection based on RSSI */ +/* TSCH_CALLBACK_CHANNEL_STATS_UPDATED(channel, previous_metric); */ +/* TSCH_CALLBACK_SELECT_CHANNELS(); */ + + +/************ Types ***********/ + +typedef uint16_t tsch_stat_t; + +struct tsch_global_stats { + /* the maximum synchronization error */ + uint32_t max_sync_error; + /* number of disassociations */ + uint16_t num_disassociations; +#if TSCH_STATS_SAMPLE_NOISE_RSSI + /* per-channel noise estimates */ + tsch_stat_t noise_rssi[TSCH_STATS_NUM_CHANNELS]; + /* derived from `noise_rssi` and BUSY_CHANNEL_RSSI */ + tsch_stat_t channel_free_ewma[TSCH_STATS_NUM_CHANNELS]; +#endif /* TSCH_STATS_SAMPLE_NOISE_RSSI */ +}; + +struct tsch_channel_stats { + /* EWMA, from receptions */ + tsch_stat_t rssi; + /* EWMA, from receptions */ + tsch_stat_t lqi; + /* EWMA of probability, for unicast transmissions only */ + tsch_stat_t p_tx_success; +}; + +struct tsch_neighbor_stats { + struct tsch_channel_stats channel_stats[TSCH_STATS_NUM_CHANNELS]; +}; + +struct tsch_neighbor; /* Forward declaration */ + + +/************ External variables ***********/ + +#if TSCH_STATS_ON + +/* Statistics for the local node */ +extern struct tsch_global_stats tsch_stats; + +/* For the timesource neighbor */ +extern struct tsch_neighbor_stats tsch_neighbor_stats; + + +/************ Functions ***********/ + +void tsch_stats_init(void); + +void tsch_stats_tx_packet(struct tsch_neighbor *, uint8_t mac_status, uint8_t channel); + +void tsch_stats_rx_packet(struct tsch_neighbor *, int8_t rssi, uint8_t lqi, uint8_t channel); + +void tsch_stats_on_time_synchronization(int32_t sync_error); + +void tsch_stats_sample_rssi(void); + +struct tsch_neighbor_stats *tsch_stats_get_from_neighbor(struct tsch_neighbor *); + +void tsch_stats_reset_neighbor_stats(void); + +#else /* TSCH_STATS_ON */ + +#define tsch_stats_init() +#define tsch_stats_tx_packet(n, mac_status, channel) +#define tsch_stats_rx_packet(n, rssi, lqi, channel) +#define tsch_stats_on_time_synchronization(sync_error) +#define tsch_stats_sample_rssi() +#define tsch_stats_get_from_neighbor(neighbor) NULL +#define tsch_stats_reset_neighbor_stats() + +#endif /* TSCH_STATS_ON */ + +static inline uint8_t +tsch_stats_channel_to_index(uint8_t channel) +{ + return channel - TSCH_STATS_FIRST_CHANNEL; +} + +static inline uint8_t +tsch_stats_index_to_channel(uint8_t channel_index) +{ + return channel_index + TSCH_STATS_FIRST_CHANNEL; +} + + +#endif /* __TSCH_STATS_H__ */ +/** @} */ diff --git a/os/net/mac/tsch/tsch-timeslot-timing.c b/os/net/mac/tsch/tsch-timeslot-timing.c new file mode 100644 index 000000000..a75676101 --- /dev/null +++ b/os/net/mac/tsch/tsch-timeslot-timing.c @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2018, RISE SICS. + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + * This file is part of the Contiki operating system. + * + */ + +/** + * \file + * IEEE 802.15.4 TSCH timeslot timings + * \author + * Simon Duquennoy + * + */ + +/** + * \addtogroup tsch + * @{ +*/ + +#include "contiki.h" +#include "net/mac/tsch/tsch.h" + +/** + * \brief The default timeslot timing in the standard is a guard time of + * 2200 us, a Tx offset of 2120 us and a Rx offset of 1120 us. + * As a result, the listening device has a guard time not centered + * on the expected Tx time. This is to be fixed in the next iteration + * of the standard. This can be enabled with: + * TxOffset: 2120 + * RxOffset: 1120 + * RxWait: 2200 + * + * Instead, we align the Rx guard time on expected Tx time. The Rx + * guard time is user-configurable with TSCH_CONF_RX_WAIT. + * (TxOffset - (RxWait / 2)) instead + */ + +const uint16_t tsch_timeslot_timing_us_10000[tsch_ts_elements_count] = { + 1800, /* CCAOffset */ + 128, /* CCA */ + 2120, /* TxOffset */ + (2120 - (TSCH_CONF_RX_WAIT / 2)), /* RxOffset */ + 800, /* RxAckDelay */ + 1000, /* TxAckDelay */ + TSCH_CONF_RX_WAIT, /* RxWait */ + 400, /* AckWait */ + 192, /* RxTx */ + 2400, /* MaxAck */ + 4256, /* MaxTx */ + 10000, /* TimeslotLength */ +}; + +/** @} */ diff --git a/os/net/mac/tsch/tsch.c b/os/net/mac/tsch/tsch.c index dea750120..25b565809 100644 --- a/os/net/mac/tsch/tsch.c +++ b/os/net/mac/tsch/tsch.c @@ -102,20 +102,9 @@ uint8_t tsch_hopping_sequence[TSCH_HOPPING_SEQUENCE_MAX_LEN]; struct tsch_asn_divisor_t tsch_hopping_sequence_length; /* Default TSCH timeslot timing (in micro-second) */ -static const uint16_t tsch_default_timing_us[tsch_ts_elements_count] = { - TSCH_DEFAULT_TS_CCA_OFFSET, - TSCH_DEFAULT_TS_CCA, - TSCH_DEFAULT_TS_TX_OFFSET, - TSCH_DEFAULT_TS_RX_OFFSET, - TSCH_DEFAULT_TS_RX_ACK_DELAY, - TSCH_DEFAULT_TS_TX_ACK_DELAY, - TSCH_DEFAULT_TS_RX_WAIT, - TSCH_DEFAULT_TS_ACK_WAIT, - TSCH_DEFAULT_TS_RX_TX, - TSCH_DEFAULT_TS_MAX_ACK, - TSCH_DEFAULT_TS_MAX_TX, - TSCH_DEFAULT_TS_TIMESLOT_LENGTH, -}; +static const uint16_t *tsch_default_timing_us; +/* TSCH timeslot timing (in micro-second) */ +uint16_t tsch_timing_us[tsch_ts_elements_count]; /* TSCH timeslot timing (in rtimer ticks) */ rtimer_clock_t tsch_timing[tsch_ts_elements_count]; @@ -160,6 +149,8 @@ static struct ctimer keepalive_timer; unsigned long tx_count; unsigned long rx_count; unsigned long sync_count; +int32_t min_drift_seen; +int32_t max_drift_seen; /* TSCH processes and protothreads */ PT_THREAD(tsch_scan(struct pt *pt)); @@ -229,8 +220,10 @@ tsch_reset(void) TSCH_ASN_INIT(tsch_current_asn, 0, 0); current_link = NULL; /* Reset timeslot timing to defaults */ + tsch_default_timing_us = TSCH_DEFAULT_TIMESLOT_TIMING; for(i = 0; i < tsch_ts_elements_count; i++) { - tsch_timing[i] = US_TO_RTIMERTICKS(tsch_default_timing_us[i]); + tsch_timing_us[i] = tsch_default_timing_us[i]; + tsch_timing[i] = US_TO_RTIMERTICKS(tsch_timing_us[i]); } #ifdef TSCH_CALLBACK_LEAVING_NETWORK TSCH_CALLBACK_LEAVING_NETWORK(); @@ -410,6 +403,22 @@ eb_input(struct input_packet *current_input) } #endif /* TSCH_AUTOSELECT_TIME_SOURCE */ } + + /* TSCH hopping sequence */ + if(eb_ies.ie_channel_hopping_sequence_id != 0) { + if(eb_ies.ie_hopping_sequence_len != tsch_hopping_sequence_length.val + || memcmp((uint8_t *)tsch_hopping_sequence, eb_ies.ie_hopping_sequence_list, tsch_hopping_sequence_length.val)) { + if(eb_ies.ie_hopping_sequence_len <= sizeof(tsch_hopping_sequence)) { + memcpy((uint8_t *)tsch_hopping_sequence, eb_ies.ie_hopping_sequence_list, + eb_ies.ie_hopping_sequence_len); + TSCH_ASN_DIVISOR_INIT(tsch_hopping_sequence_length, eb_ies.ie_hopping_sequence_len); + + LOG_WARN("Updating TSCH hopping sequence from EB\n"); + } else { + LOG_WARN("TSCH:! parse_eb: hopping sequence too long (%u)\n", eb_ies.ie_hopping_sequence_len); + } + } + } } } } @@ -563,10 +572,11 @@ tsch_associate(const struct input_packet *input_eb, rtimer_clock_t timestamp) /* TSCH timeslot timing */ for(i = 0; i < tsch_ts_elements_count; i++) { if(ies.ie_tsch_timeslot_id == 0) { - tsch_timing[i] = US_TO_RTIMERTICKS(tsch_default_timing_us[i]); + tsch_timing_us[i] = tsch_default_timing_us[i]; } else { - tsch_timing[i] = US_TO_RTIMERTICKS(ies.ie_tsch_timeslot[i]); + tsch_timing_us[i] = ies.ie_tsch_timeslot[i]; } + tsch_timing[i] = US_TO_RTIMERTICKS(tsch_timing_us[i]); } /* TSCH hopping sequence */ @@ -648,6 +658,8 @@ tsch_associate(const struct input_packet *input_eb, rtimer_clock_t timestamp) tx_count = 0; rx_count = 0; sync_count = 0; + min_drift_seen = 0; + max_drift_seen = 0; /* Start sending keep-alives now that tsch_is_associated is set */ tsch_schedule_keepalive(); @@ -710,11 +722,11 @@ PT_THREAD(tsch_scan(struct pt *pt)) /* Pick a channel at random in TSCH_JOIN_HOPPING_SEQUENCE */ uint8_t scan_channel = TSCH_JOIN_HOPPING_SEQUENCE[ random_rand() % sizeof(TSCH_JOIN_HOPPING_SEQUENCE)]; - if(current_channel != scan_channel) { - NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, scan_channel); - current_channel = scan_channel; - LOG_INFO("scanning on channel %u\n", scan_channel); - } + + NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, scan_channel); + current_channel = scan_channel; + LOG_INFO("scanning on channel %u\n", scan_channel); + current_channel_since = now_time; } @@ -725,20 +737,30 @@ PT_THREAD(tsch_scan(struct pt *pt)) if(!is_packet_pending && NETSTACK_RADIO.receiving_packet()) { /* If we are currently receiving a packet, wait until end of reception */ t0 = RTIMER_NOW(); - BUSYWAIT_UNTIL_ABS((is_packet_pending = NETSTACK_RADIO.pending_packet()), t0, RTIMER_SECOND / 100); + RTIMER_BUSYWAIT_UNTIL_ABS((is_packet_pending = NETSTACK_RADIO.pending_packet()), t0, RTIMER_SECOND / 100); } if(is_packet_pending) { + rtimer_clock_t t1; /* Read packet */ input_eb.len = NETSTACK_RADIO.read(input_eb.payload, TSCH_PACKET_MAX_LEN); /* Save packet timestamp */ NETSTACK_RADIO.get_object(RADIO_PARAM_LAST_PACKET_TIMESTAMP, &t0, sizeof(rtimer_clock_t)); + t1 = RTIMER_NOW(); /* Parse EB and attempt to associate */ LOG_INFO("scan: received packet (%u bytes) on channel %u\n", input_eb.len, current_channel); - tsch_associate(&input_eb, t0); + /* Sanity-check the timestamp */ + if(ABS(RTIMER_CLOCK_DIFF(t0, t1)) < tsch_timing[tsch_ts_timeslot_length]) { + tsch_associate(&input_eb, t0); + } else { + LOG_WARN("scan: dropping packet, timestamp too far from current time %u %u\n", + (unsigned)t0, + (unsigned)t1 + ); + } } if(tsch_is_associated) { @@ -860,6 +882,9 @@ PROCESS_THREAD(tsch_pending_events_process, ev, data) tsch_rx_process_pending(); tsch_tx_process_pending(); tsch_log_process_pending(); +#ifdef TSCH_CALLBACK_SELECT_CHANNELS + TSCH_CALLBACK_SELECT_CHANNELS(); +#endif } PROCESS_END(); } @@ -874,6 +899,12 @@ tsch_init(void) radio_value_t radio_tx_mode; rtimer_clock_t t; + /* Check that the platform provides a TSCH timeslot timing template */ + if(TSCH_DEFAULT_TIMESLOT_TIMING == NULL) { + LOG_ERR("! platform does not provide a timeslot timing template.\n"); + return; + } + /* Radio Rx mode */ if(NETSTACK_RADIO.get_value(RADIO_PARAM_RX_MODE, &radio_rx_mode) != RADIO_RESULT_OK) { LOG_ERR("! radio does not support getting RADIO_PARAM_RX_MODE. Abort init.\n"); @@ -914,6 +945,7 @@ tsch_init(void) /* Check max hopping sequence length vs default sequence length */ if(TSCH_HOPPING_SEQUENCE_MAX_LEN < sizeof(TSCH_DEFAULT_HOPPING_SEQUENCE)) { LOG_ERR("! TSCH_HOPPING_SEQUENCE_MAX_LEN < sizeof(TSCH_DEFAULT_HOPPING_SEQUENCE). Abort init.\n"); + return; } /* Init the queuebuf and TSCH sub-modules */ @@ -940,6 +972,8 @@ tsch_init(void) #if TSCH_WITH_SIXTOP sixtop_init(); #endif + + tsch_stats_init(); } /*---------------------------------------------------------------------------*/ /* Function send for TSCH-MAC, puts the packet in packetbuf in the MAC queue */ diff --git a/os/net/mac/tsch/tsch.h b/os/net/mac/tsch/tsch.h index 0f108bd93..db23b4851 100644 --- a/os/net/mac/tsch/tsch.h +++ b/os/net/mac/tsch/tsch.h @@ -60,28 +60,16 @@ frequency hopping for enhanced reliability. #include "net/mac/tsch/tsch-packet.h" #include "net/mac/tsch/tsch-security.h" #include "net/mac/tsch/tsch-schedule.h" +#include "net/mac/tsch/tsch-stats.h" #if UIP_CONF_IPV6_RPL #include "net/mac/tsch/tsch-rpl.h" #endif /* UIP_CONF_IPV6_RPL */ -#if CONTIKI_TARGET_COOJA -#include "lib/simEnvChange.h" -#include "sys/cooja_mt.h" -#endif /* CONTIKI_TARGET_COOJA */ -/*********** Macros *********/ - -/* Wait for a condition with timeout t0+offset. */ -#if CONTIKI_TARGET_COOJA -#define BUSYWAIT_UNTIL_ABS(cond, t0, offset) \ - while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), (t0) + (offset))) { \ - simProcessRunValue = 1; \ - cooja_mt_yield(); \ - }; -#else -#define BUSYWAIT_UNTIL_ABS(cond, t0, offset) \ - while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), (t0) + (offset))) ; -#endif /* CONTIKI_TARGET_COOJA */ +/* Include Arch-Specific conf */ +#ifdef TSCH_CONF_ARCH_HDR_PATH +#include TSCH_CONF_ARCH_HDR_PATH +#endif /* TSCH_CONF_ARCH_HDR_PATH */ /*********** Callbacks *********/ @@ -164,15 +152,23 @@ extern const linkaddr_t tsch_eb_address; extern struct tsch_asn_t tsch_current_asn; extern uint8_t tsch_join_priority; extern struct tsch_link *current_link; +/* If we are inside a slot, this tells the current channel */ +extern uint8_t tsch_current_channel; /* TSCH channel hopping sequence */ extern uint8_t tsch_hopping_sequence[TSCH_HOPPING_SEQUENCE_MAX_LEN]; extern struct tsch_asn_divisor_t tsch_hopping_sequence_length; +/* TSCH timeslot timing (in micro-second) */ +extern uint16_t tsch_timing_us[tsch_ts_elements_count]; /* TSCH timeslot timing (in rtimer ticks) */ extern rtimer_clock_t tsch_timing[tsch_ts_elements_count]; /* Statistics on the current session */ extern unsigned long tx_count; extern unsigned long rx_count; extern unsigned long sync_count; +extern int32_t min_drift_seen; +extern int32_t max_drift_seen; +/* The TSCH standard 10ms timeslot timing */ +extern const uint16_t tsch_timeslot_timing_us_10000[tsch_ts_elements_count]; /* TSCH processes */ PROCESS_NAME(tsch_process); diff --git a/os/net/nbr-table.c b/os/net/nbr-table.c index 77d3cb07d..8a8eaeb78 100644 --- a/os/net/nbr-table.c +++ b/os/net/nbr-table.c @@ -439,39 +439,6 @@ nbr_table_get_lladdr(nbr_table_t *table, const void *item) return key != NULL ? &key->lladdr : NULL; } /*---------------------------------------------------------------------------*/ -/* Update link-layer address of an item */ -int -nbr_table_update_lladdr(const linkaddr_t *old_addr, const linkaddr_t *new_addr, - int remove_if_duplicate) -{ - int index; - int new_index; - nbr_table_key_t *key; - index = index_from_lladdr(old_addr); - if(index == -1) { - /* Failure to change since there is nothing to change. */ - return 0; - } - if((new_index = index_from_lladdr(new_addr)) != -1) { - /* check if it is a change or not - do not remove / fail if same */ - if(new_index == index) { - return 1; - } - /* This new entry already exists - failure! - remove if requested. */ - if(remove_if_duplicate) { - remove_key(key_from_index(index)); - } - return 0; - } - key = key_from_index(index); - /** - * Copy the new lladdr into the key - since we know that there is no - * conflicting entry. - */ - memcpy(&key->lladdr, new_addr, sizeof(linkaddr_t)); - return 1; -} -/*---------------------------------------------------------------------------*/ #if DEBUG static void print_table() diff --git a/os/net/nbr-table.h b/os/net/nbr-table.h index d7fad5267..0dccd1092 100644 --- a/os/net/nbr-table.h +++ b/os/net/nbr-table.h @@ -113,7 +113,6 @@ int nbr_table_unlock(nbr_table_t *table, nbr_table_item_t *item); /** \name Neighbor tables: address manipulation */ /** @{ */ linkaddr_t *nbr_table_get_lladdr(nbr_table_t *table, const nbr_table_item_t *item); -int nbr_table_update_lladdr(const linkaddr_t *old_addr, const linkaddr_t *new_addr, int remove_if_duplicate); /** @} */ #endif /* NBR_TABLE_H_ */ diff --git a/os/net/packetbuf.h b/os/net/packetbuf.h index 39ce4a467..20e071474 100644 --- a/os/net/packetbuf.h +++ b/os/net/packetbuf.h @@ -236,7 +236,6 @@ enum { #if LLSEC802154_USES_EXPLICIT_KEYS PACKETBUF_ATTR_KEY_ID_MODE, PACKETBUF_ATTR_KEY_INDEX, - PACKETBUF_ATTR_KEY_SOURCE_BYTES_0_1, #endif /* LLSEC802154_USES_EXPLICIT_KEYS */ /* Scope 2 attributes: used between end-to-end nodes. */ diff --git a/os/net/routing/nullrouting/nullrouting.c b/os/net/routing/nullrouting/nullrouting.c index 1b23d453a..bb1399fbb 100644 --- a/os/net/routing/nullrouting/nullrouting.c +++ b/os/net/routing/nullrouting/nullrouting.c @@ -106,7 +106,9 @@ local_repair(const char *str) static void ext_header_remove(void) { +#if NETSTACK_CONF_WITH_IPV6 uip_ext_len = 0; +#endif /* NETSTACK_CONF_WITH_IPV6 */ } /*---------------------------------------------------------------------------*/ static int diff --git a/os/net/routing/rpl-classic/rpl-dag-root.c b/os/net/routing/rpl-classic/rpl-dag-root.c index 05adff4de..3a0162627 100644 --- a/os/net/routing/rpl-classic/rpl-dag-root.c +++ b/os/net/routing/rpl-classic/rpl-dag-root.c @@ -36,10 +36,12 @@ #include "net/routing/rpl-classic/rpl-private.h" #include "net/ipv6/uip-ds6-route.h" +#include "sys/log.h" + #include -#define DEBUG DEBUG_NONE -#include "net/ipv6/uip-debug.h" +#define LOG_MODULE "RPL" +#define LOG_LEVEL LOG_LEVEL_RPL /*---------------------------------------------------------------------------*/ static void @@ -47,7 +49,6 @@ set_global_address(uip_ipaddr_t *prefix, uip_ipaddr_t *iid) { static uip_ipaddr_t root_ipaddr; int i; - uint8_t state; /* Assign a unique local address (RFC4193, http://tools.ietf.org/html/rfc4193). */ @@ -64,13 +65,17 @@ set_global_address(uip_ipaddr_t *prefix, uip_ipaddr_t *iid) uip_ds6_addr_add(&root_ipaddr, 0, ADDR_AUTOCONF); - printf("IPv6 addresses: "); - for(i = 0; i < UIP_DS6_ADDR_NB; i++) { - state = uip_ds6_if.addr_list[i].state; - if(uip_ds6_if.addr_list[i].isused && - (state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) { - uip_debug_ipaddr_print(&uip_ds6_if.addr_list[i].ipaddr); - printf("\n"); + if(LOG_DBG_ENABLED) { + uint8_t state; + + LOG_DBG("IPv6 addresses: "); + for(i = 0; i < UIP_DS6_ADDR_NB; i++) { + state = uip_ds6_if.addr_list[i].state; + if(uip_ds6_if.addr_list[i].isused && + (state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) { + LOG_DBG_6ADDR(&uip_ds6_if.addr_list[i].ipaddr); + LOG_DBG_("\n"); + } } } } @@ -126,14 +131,14 @@ rpl_dag_root_start(void) uip_ip6addr(&prefix, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0); rpl_set_prefix(dag, &prefix, 64); - PRINTF("rpl_dag_root_set_prefix_dag: created a new RPL dag\n"); + LOG_INFO("root_set_prefix: created a new RPL dag\n"); return 0; } else { - PRINTF("rpl_dag_root_set_prefix_dag: failed to create a new RPL DAG\n"); + LOG_ERR("root_set_prefix: failed to create a new RPL DAG\n"); return -1; } } else { - PRINTF("rpl_dag_root_set_prefix_dag: failed to create a new RPL DAG, no preferred IP address found\n"); + LOG_ERR("root_set_prefix_dag: failed to create a new RPL DAG, no preferred IP address found\n"); return -2; } } diff --git a/os/net/routing/rpl-classic/rpl-dag.c b/os/net/routing/rpl-classic/rpl-dag.c index 742ef16c4..cbaee6959 100644 --- a/os/net/routing/rpl-classic/rpl-dag.c +++ b/os/net/routing/rpl-classic/rpl-dag.c @@ -56,12 +56,13 @@ #include "lib/list.h" #include "lib/memb.h" #include "sys/ctimer.h" +#include "sys/log.h" #include #include -#define DEBUG DEBUG_NONE -#include "net/ipv6/uip-debug.h" +#define LOG_MODULE "RPL" +#define LOG_LEVEL LOG_LEVEL_RPL /* A configurable function called after every RPL parent switch */ #ifdef RPL_CALLBACK_PARENT_SWITCH @@ -233,19 +234,19 @@ static void rpl_set_preferred_parent(rpl_dag_t *dag, rpl_parent_t *p) { if(dag != NULL && dag->preferred_parent != p) { - PRINTF("RPL: rpl_set_preferred_parent "); + LOG_INFO("rpl_set_preferred_parent "); if(p != NULL) { - PRINT6ADDR(rpl_parent_get_ipaddr(p)); + LOG_INFO_6ADDR(rpl_parent_get_ipaddr(p)); } else { - PRINTF("NULL"); + LOG_INFO_("NULL"); } - PRINTF(" used to be "); + LOG_INFO_(" used to be "); if(dag->preferred_parent != NULL) { - PRINT6ADDR(rpl_parent_get_ipaddr(dag->preferred_parent)); + LOG_INFO_6ADDR(rpl_parent_get_ipaddr(dag->preferred_parent)); } else { - PRINTF("NULL"); + LOG_INFO_("NULL"); } - PRINTF("\n"); + LOG_INFO_("\n"); #ifdef RPL_CALLBACK_PARENT_SWITCH RPL_CALLBACK_PARENT_SWITCH(dag->preferred_parent, p); @@ -281,8 +282,7 @@ remove_parents(rpl_dag_t *dag, rpl_rank_t minimum_rank) { rpl_parent_t *p; - PRINTF("RPL: Removing parents (minimum rank %u)\n", - minimum_rank); + LOG_INFO("Removing parents (minimum rank %u)\n", minimum_rank); p = nbr_table_head(rpl_parents); while(p != NULL) { @@ -298,8 +298,7 @@ nullify_parents(rpl_dag_t *dag, rpl_rank_t minimum_rank) { rpl_parent_t *p; - PRINTF("RPL: Nullifying parents (minimum rank %u)\n", - minimum_rank); + LOG_INFO("Nullifying parents (minimum rank %u)\n", minimum_rank); p = nbr_table_head(rpl_parents); while(p != NULL) { @@ -371,11 +370,11 @@ rpl_set_root(uint8_t instance_id, uip_ipaddr_t *dag_id) RPL_LOLLIPOP_INCREMENT(version); } if(dag == dag->instance->current_dag) { - PRINTF("RPL: Dropping a joined DAG when setting this node as root"); + LOG_INFO("Dropping a joined DAG when setting this node as root\n"); rpl_set_default_route(instance, NULL); dag->instance->current_dag = NULL; } else { - PRINTF("RPL: Dropping a DAG when setting this node as root"); + LOG_INFO("Dropping a DAG when setting this node as root\n"); } rpl_free_dag(dag); } @@ -384,7 +383,7 @@ rpl_set_root(uint8_t instance_id, uip_ipaddr_t *dag_id) dag = rpl_alloc_dag(instance_id, dag_id); if(dag == NULL) { - PRINTF("RPL: Failed to allocate a DAG\n"); + LOG_ERR("Failed to allocate a DAG\n"); return NULL; } @@ -397,7 +396,7 @@ rpl_set_root(uint8_t instance_id, uip_ipaddr_t *dag_id) instance->mop = RPL_MOP_DEFAULT; instance->of = rpl_find_of(RPL_OF_OCP); if(instance->of == NULL) { - PRINTF("RPL: OF with OCP %u not supported\n", RPL_OF_OCP); + LOG_WARN("OF with OCP %u not supported\n", RPL_OF_OCP); return NULL; } @@ -433,11 +432,11 @@ rpl_set_root(uint8_t instance_id, uip_ipaddr_t *dag_id) instance->of->update_metric_container(instance); default_instance = instance; - PRINTF("RPL: Node set to be a DAG root with DAG ID "); - PRINT6ADDR(&dag->dag_id); - PRINTF("\n"); + LOG_INFO("Node set to be a DAG root with DAG ID "); + LOG_INFO_6ADDR(&dag->dag_id); + LOG_INFO_("\n"); - ANNOTATE("#A root=%u\n", dag->dag_id.u8[sizeof(dag->dag_id) - 1]); + LOG_ANNOTATE("#A root=%u\n", dag->dag_id.u8[sizeof(dag->dag_id) - 1]); rpl_reset_dio_timer(instance); @@ -452,14 +451,14 @@ rpl_repair_root(uint8_t instance_id) instance = rpl_get_instance(instance_id); if(instance == NULL || instance->current_dag->rank != ROOT_RANK(instance)) { - PRINTF("RPL: rpl_repair_root triggered but not root\n"); + LOG_WARN("rpl_repair_root triggered but not root\n"); return 0; } RPL_STAT(rpl_stats.root_repairs++); RPL_LOLLIPOP_INCREMENT(instance->current_dag->version); RPL_LOLLIPOP_INCREMENT(instance->dtsn_out); - PRINTF("RPL: rpl_repair_root initiating global repair with version %d\n", instance->current_dag->version); + LOG_INFO("rpl_repair_root initiating global repair with version %d\n", instance->current_dag->version); rpl_reset_dio_timer(instance); return 1; } @@ -490,9 +489,9 @@ check_prefix(rpl_prefix_t *last_prefix, rpl_prefix_t *new_prefix) set_ip_from_prefix(&ipaddr, last_prefix); rep = uip_ds6_addr_lookup(&ipaddr); if(rep != NULL) { - PRINTF("RPL: removing global IP address "); - PRINT6ADDR(&ipaddr); - PRINTF("\n"); + LOG_DBG("removing global IP address "); + LOG_DBG_6ADDR(&ipaddr); + LOG_DBG_("\n"); uip_ds6_addr_rm(rep); } } @@ -500,9 +499,9 @@ check_prefix(rpl_prefix_t *last_prefix, rpl_prefix_t *new_prefix) if(new_prefix != NULL) { set_ip_from_prefix(&ipaddr, new_prefix); if(uip_ds6_addr_lookup(&ipaddr) == NULL) { - PRINTF("RPL: adding global IP address "); - PRINT6ADDR(&ipaddr); - PRINTF("\n"); + LOG_DBG("adding global IP address "); + LOG_DBG_6ADDR(&ipaddr); + LOG_DBG_("\n"); uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); } } @@ -524,15 +523,15 @@ rpl_set_prefix(rpl_dag_t *dag, uip_ipaddr_t *prefix, unsigned len) memcpy(&dag->prefix_info.prefix, prefix, (len + 7) / 8); dag->prefix_info.length = len; dag->prefix_info.flags = UIP_ND6_RA_FLAG_AUTONOMOUS; - PRINTF("RPL: Prefix set - will announce this in DIOs\n"); + LOG_INFO("Prefix set - will announce this in DIOs\n"); if(dag->rank != ROOT_RANK(dag->instance)) { /* Autoconfigure an address if this node does not already have an address with this prefix. Otherwise, update the prefix */ if(last_len == 0) { - PRINTF("rpl_set_prefix - prefix NULL\n"); + LOG_INFO("rpl_set_prefix - prefix NULL\n"); check_prefix(NULL, &dag->prefix_info); } else { - PRINTF("rpl_set_prefix - prefix NON-NULL\n"); + LOG_INFO("rpl_set_prefix - prefix NON-NULL\n"); check_prefix(&last_prefix, &dag->prefix_info); } } @@ -543,17 +542,17 @@ int rpl_set_default_route(rpl_instance_t *instance, uip_ipaddr_t *from) { if(instance->def_route != NULL) { - PRINTF("RPL: Removing default route through "); - PRINT6ADDR(&instance->def_route->ipaddr); - PRINTF("\n"); + LOG_DBG("Removing default route through "); + LOG_DBG_6ADDR(&instance->def_route->ipaddr); + LOG_DBG_("\n"); uip_ds6_defrt_rm(instance->def_route); instance->def_route = NULL; } if(from != NULL) { - PRINTF("RPL: Adding default route through "); - PRINT6ADDR(from); - PRINTF("\n"); + LOG_DBG("Adding default route through "); + LOG_DBG_6ADDR(from); + LOG_DBG("\n"); instance->def_route = uip_ds6_defrt_add(from, RPL_DEFAULT_ROUTE_INFINITE_LIFETIME ? 0 : RPL_LIFETIME(instance, instance->default_lifetime)); if(instance->def_route == NULL) { @@ -632,7 +631,7 @@ rpl_free_instance(rpl_instance_t *instance) rpl_dag_t *dag; rpl_dag_t *end; - PRINTF("RPL: Leaving the instance %u\n", instance->instance_id); + LOG_INFO("Leaving the instance %u\n", instance->instance_id); /* Remove any DAG inside this instance */ for(dag = &instance->dag_table[0], end = dag + RPL_MAX_DAG_PER_INSTANCE; dag < end; ++dag) { @@ -661,9 +660,9 @@ void rpl_free_dag(rpl_dag_t *dag) { if(dag->joined) { - PRINTF("RPL: Leaving the DAG "); - PRINT6ADDR(&dag->dag_id); - PRINTF("\n"); + LOG_INFO("Leaving the DAG "); + LOG_INFO_6ADDR(&dag->dag_id); + LOG_INFO_("\n"); dag->joined = 0; /* Remove routes installed by DAOs. */ @@ -693,15 +692,15 @@ rpl_add_parent(rpl_dag_t *dag, rpl_dio_t *dio, uip_ipaddr_t *addr) * Typically, the parent is added upon receiving a DIO. */ const uip_lladdr_t *lladdr = uip_ds6_nbr_lladdr_from_ipaddr(addr); - PRINTF("RPL: rpl_add_parent lladdr %p ", lladdr); - PRINT6ADDR(addr); - PRINTF("\n"); + LOG_DBG("rpl_add_parent lladdr %p ", lladdr); + LOG_DBG_6ADDR(addr); + LOG_DBG_("\n"); if(lladdr != NULL) { /* Add parent in rpl_parents - again this is due to DIO */ p = nbr_table_add_lladdr(rpl_parents, (linkaddr_t *)lladdr, NBR_TABLE_REASON_RPL_DIO, dio); if(p == NULL) { - PRINTF("RPL: rpl_add_parent p NULL\n"); + LOG_DBG("rpl_add_parent p NULL\n"); } else { p->dag = dag; p->rank = dio->rank; @@ -792,9 +791,9 @@ rpl_select_dag(rpl_instance_t *instance, rpl_parent_t *p) rpl_remove_routes(instance->current_dag); } - PRINTF("RPL: New preferred DAG: "); - PRINT6ADDR(&best_dag->dag_id); - PRINTF("\n"); + LOG_INFO("New preferred DAG: "); + LOG_INFO_6ADDR(&best_dag->dag_id); + LOG_INFO_("\n"); if(best_dag->prefix_info.flags & UIP_ND6_RA_FLAG_AUTONOMOUS) { check_prefix(&instance->current_dag->prefix_info, &best_dag->prefix_info); @@ -817,7 +816,7 @@ rpl_select_dag(rpl_instance_t *instance, rpl_parent_t *p) } if(!acceptable_rank(best_dag, best_dag->rank)) { - PRINTF("RPL: New rank unacceptable!\n"); + LOG_WARN("New rank unacceptable!\n"); rpl_set_preferred_parent(instance->current_dag, NULL); if(RPL_IS_STORING(instance) && last_parent != NULL) { /* Send a No-Path DAO to the removed preferred parent. */ @@ -828,7 +827,7 @@ rpl_select_dag(rpl_instance_t *instance, rpl_parent_t *p) if(best_dag->preferred_parent != last_parent) { rpl_set_default_route(instance, rpl_parent_get_ipaddr(best_dag->preferred_parent)); - PRINTF("RPL: Changed preferred parent, rank changed from %u to %u\n", + LOG_INFO("Changed preferred parent, rank changed from %u to %u\n", (unsigned)old_rank, best_dag->rank); RPL_STAT(rpl_stats.parent_switch++); if(RPL_IS_STORING(instance)) { @@ -843,11 +842,11 @@ rpl_select_dag(rpl_instance_t *instance, rpl_parent_t *p) /* The DAO parent set changed - schedule a DAO transmission. */ rpl_schedule_dao(instance); rpl_reset_dio_timer(instance); -#if DEBUG - rpl_print_neighbor_list(); -#endif + if(LOG_DBG_ENABLED) { + rpl_print_neighbor_list(); + } } else if(best_dag->rank != old_rank) { - PRINTF("RPL: Preferred parent update, rank changed from %u to %u\n", + LOG_DBG("RPL: Preferred parent update, rank changed from %u to %u\n", (unsigned)old_rank, best_dag->rank); } return best_dag; @@ -871,7 +870,7 @@ best_parent(rpl_dag_t *dag, int fresh_only) /* Exclude parents from other DAGs or announcing an infinite rank */ if(p->dag != dag || p->rank == RPL_INFINITE_RANK || p->rank < ROOT_RANK(dag->instance)) { if(p->rank < ROOT_RANK(dag->instance)) { - PRINTF("RPL: Parent has invalid rank\n"); + LOG_WARN("Parent has invalid rank\n"); } continue; } @@ -908,6 +907,8 @@ rpl_select_parent(rpl_dag_t *dag) #if RPL_WITH_PROBING if(rpl_parent_is_fresh(best)) { rpl_set_preferred_parent(dag, best); + /* Unschedule any already scheduled urgent probing */ + dag->instance->urgent_probing_target = NULL; } else { /* The best is not fresh. Look for the best fresh now. */ rpl_parent_t *best_fresh = best_parent(dag, 1); @@ -920,7 +921,7 @@ rpl_select_parent(rpl_dag_t *dag) } /* Probe the best parent shortly in order to get a fresh estimate */ dag->instance->urgent_probing_target = best; - rpl_schedule_probing(dag->instance); + rpl_schedule_probing_now(dag->instance); } #else /* RPL_WITH_PROBING */ rpl_set_preferred_parent(dag, best); @@ -937,9 +938,9 @@ rpl_select_parent(rpl_dag_t *dag) void rpl_remove_parent(rpl_parent_t *parent) { - PRINTF("RPL: Removing parent "); - PRINT6ADDR(rpl_parent_get_ipaddr(parent)); - PRINTF("\n"); + LOG_INFO("Removing parent "); + LOG_INFO_6ADDR(rpl_parent_get_ipaddr(parent)); + LOG_INFO_("\n"); rpl_nullify_parent(parent); @@ -956,9 +957,9 @@ rpl_nullify_parent(rpl_parent_t *parent) dag->rank = RPL_INFINITE_RANK; if(dag->joined) { if(dag->instance->def_route != NULL) { - PRINTF("RPL: Removing default route "); - PRINT6ADDR(rpl_parent_get_ipaddr(parent)); - PRINTF("\n"); + LOG_DBG("Removing default route "); + LOG_DBG_6ADDR(rpl_parent_get_ipaddr(parent)); + LOG_DBG_("\n"); uip_ds6_defrt_rm(dag->instance->def_route); dag->instance->def_route = NULL; } @@ -972,9 +973,9 @@ rpl_nullify_parent(rpl_parent_t *parent) } } - PRINTF("RPL: Nullifying parent "); - PRINT6ADDR(rpl_parent_get_ipaddr(parent)); - PRINTF("\n"); + LOG_INFO("Nullifying parent "); + LOG_INFO_6ADDR(rpl_parent_get_ipaddr(parent)); + LOG_INFO_("\n"); } /*---------------------------------------------------------------------------*/ void @@ -984,10 +985,10 @@ rpl_move_parent(rpl_dag_t *dag_src, rpl_dag_t *dag_dst, rpl_parent_t *parent) rpl_set_preferred_parent(dag_src, NULL); dag_src->rank = RPL_INFINITE_RANK; if(dag_src->joined && dag_src->instance->def_route != NULL) { - PRINTF("RPL: Removing default route "); - PRINT6ADDR(rpl_parent_get_ipaddr(parent)); - PRINTF("\n"); - PRINTF("rpl_move_parent\n"); + LOG_DBG("Removing default route "); + LOG_DBG_6ADDR(rpl_parent_get_ipaddr(parent)); + LOG_DBG_("\n"); + LOG_DBG("rpl_move_parent\n"); uip_ds6_defrt_rm(dag_src->instance->def_route); dag_src->instance->def_route = NULL; } @@ -998,9 +999,9 @@ rpl_move_parent(rpl_dag_t *dag_src, rpl_dag_t *dag_dst, rpl_parent_t *parent) } } - PRINTF("RPL: Moving parent "); - PRINT6ADDR(rpl_parent_get_ipaddr(parent)); - PRINTF("\n"); + LOG_INFO("Moving parent "); + LOG_INFO_6ADDR(rpl_parent_get_ipaddr(parent)); + LOG_INFO_("\n"); parent->dag = dag_dst; } @@ -1098,7 +1099,7 @@ rpl_join_instance(uip_ipaddr_t *from, rpl_dio_t *dio) if((!RPL_WITH_NON_STORING && dio->mop == RPL_MOP_NON_STORING) || (!RPL_WITH_STORING && (dio->mop == RPL_MOP_STORING_NO_MULTICAST || dio->mop == RPL_MOP_STORING_MULTICAST))) { - PRINTF("RPL: DIO advertising a non-supported MOP %u\n", dio->mop); + LOG_WARN("DIO advertising a non-supported MOP %u\n", dio->mop); return; } @@ -1106,30 +1107,30 @@ rpl_join_instance(uip_ipaddr_t *from, rpl_dio_t *dio) objective code point of the DIO. */ of = rpl_find_of(dio->ocp); if(of == NULL) { - PRINTF("RPL: DIO for DAG instance %u does not specify a supported OF: %u\n", + LOG_WARN("DIO for DAG instance %u does not specify a supported OF: %u\n", dio->instance_id, dio->ocp); return; } dag = rpl_alloc_dag(dio->instance_id, &dio->dag_id); if(dag == NULL) { - PRINTF("RPL: Failed to allocate a DAG object!\n"); + LOG_ERR("Failed to allocate a DAG object!\n"); return; } instance = dag->instance; p = rpl_add_parent(dag, dio, from); - PRINTF("RPL: Adding "); - PRINT6ADDR(from); - PRINTF(" as a parent: "); + LOG_DBG("Adding "); + LOG_DBG_6ADDR(from); + LOG_DBG_(" as a parent: "); if(p == NULL) { - PRINTF("failed\n"); + LOG_DBG_("failed\n"); instance->used = 0; return; } p->dtsn = dio->dtsn; - PRINTF("succeeded\n"); + LOG_DBG_("succeeded\n"); /* Autoconfigure an address if this node does not already have an address with this prefix. */ @@ -1175,12 +1176,12 @@ rpl_join_instance(uip_ipaddr_t *from, rpl_dio_t *dio) default_instance = instance; } - PRINTF("RPL: Joined DAG with instance ID %u, rank %hu, DAG ID ", + LOG_INFO("Joined DAG with instance ID %u, rank %hu, DAG ID ", dio->instance_id, dag->rank); - PRINT6ADDR(&dag->dag_id); - PRINTF("\n"); + LOG_INFO_6ADDR(&dag->dag_id); + LOG_INFO_("\n"); - ANNOTATE("#A join=%u\n", dag->dag_id.u8[sizeof(dag->dag_id) - 1]); + LOG_ANNOTATE("#A join=%u\n", dag->dag_id.u8[sizeof(dag->dag_id) - 1]); rpl_reset_dio_timer(instance); rpl_set_default_route(instance, from); @@ -1188,7 +1189,7 @@ rpl_join_instance(uip_ipaddr_t *from, rpl_dio_t *dio) if(instance->mop != RPL_MOP_NO_DOWNWARD_ROUTES) { rpl_schedule_dao(instance); } else { - PRINTF("RPL: The DIO does not meet the prerequisites for sending a DAO\n"); + LOG_WARN("The DIO does not meet the prerequisites for sending a DAO\n"); } instance->of->reset(dag); @@ -1206,7 +1207,7 @@ rpl_add_dag(uip_ipaddr_t *from, rpl_dio_t *dio) dag = rpl_alloc_dag(dio->instance_id, &dio->dag_id); if(dag == NULL) { - PRINTF("RPL: Failed to allocate a DAG object!\n"); + LOG_ERR("Failed to allocate a DAG object!\n"); return NULL; } @@ -1214,16 +1215,16 @@ rpl_add_dag(uip_ipaddr_t *from, rpl_dio_t *dio) previous_dag = find_parent_dag(instance, from); if(previous_dag == NULL) { - PRINTF("RPL: Adding "); - PRINT6ADDR(from); - PRINTF(" as a parent: "); + LOG_DBG("Adding "); + LOG_DBG_6ADDR(from); + LOG_DBG_(" as a parent: "); p = rpl_add_parent(dag, dio, from); if(p == NULL) { - PRINTF("failed\n"); + LOG_DBG_("failed\n"); dag->used = 0; return NULL; } - PRINTF("succeeded\n"); + LOG_DBG_("succeeded\n"); } else { p = rpl_find_parent(previous_dag, from); if(p != NULL) { @@ -1244,7 +1245,7 @@ rpl_add_dag(uip_ipaddr_t *from, rpl_dio_t *dio) instance->dio_redundancy != dio->dag_redund || instance->default_lifetime != dio->default_lifetime || instance->lifetime_unit != dio->lifetime_unit) { - PRINTF("RPL: DIO for DAG instance %u incompatible with previous DIO\n", + LOG_WARN("DIO for DAG instance %u incompatible with previous DIO\n", dio->instance_id); rpl_remove_parent(p); dag->used = 0; @@ -1265,12 +1266,12 @@ rpl_add_dag(uip_ipaddr_t *from, rpl_dio_t *dio) dag->rank = rpl_rank_via_parent(p); dag->min_rank = dag->rank; /* So far this is the lowest rank we know of. */ - PRINTF("RPL: Joined DAG with instance ID %u, rank %hu, DAG ID ", + LOG_INFO("Joined DAG with instance ID %u, rank %hu, DAG ID ", dio->instance_id, dag->rank); - PRINT6ADDR(&dag->dag_id); - PRINTF("\n"); + LOG_INFO_6ADDR(&dag->dag_id); + LOG_INFO_("\n"); - ANNOTATE("#A join=%u\n", dag->dag_id.u8[sizeof(dag->dag_id) - 1]); + LOG_ANNOTATE("#A join=%u\n", dag->dag_id.u8[sizeof(dag->dag_id) - 1]); rpl_process_parent_event(instance, p); p->dtsn = dio->dtsn; @@ -1301,16 +1302,16 @@ global_repair(uip_ipaddr_t *from, rpl_dag_t *dag, rpl_dio_t *dio) p = rpl_add_parent(dag, dio, from); if(p == NULL) { - PRINTF("RPL: Failed to add a parent during the global repair\n"); + LOG_ERR("Failed to add a parent during the global repair\n"); dag->rank = RPL_INFINITE_RANK; } else { dag->rank = rpl_rank_via_parent(p); dag->min_rank = dag->rank; - PRINTF("RPL: rpl_process_parent_event global repair\n"); + LOG_DBG("rpl_process_parent_event global repair\n"); rpl_process_parent_event(dag->instance, p); } - PRINTF("RPL: Participating in a global repair (version=%u, rank=%hu)\n", + LOG_DBG("Participating in a global repair (version=%u, rank=%hu)\n", dag->version, dag->rank); RPL_STAT(rpl_stats.global_repairs++); @@ -1323,10 +1324,10 @@ rpl_local_repair(rpl_instance_t *instance) int i; if(instance == NULL) { - PRINTF("RPL: local repair requested for instance NULL\n"); + LOG_WARN("local repair requested for instance NULL\n"); return; } - PRINTF("RPL: Starting a local instance repair\n"); + LOG_INFO("Starting a local instance repair\n"); for(i = 0; i < RPL_MAX_DAG_PER_INSTANCE; i++) { if(instance->dag_table[i].used) { instance->dag_table[i].rank = RPL_INFINITE_RANK; @@ -1365,9 +1366,9 @@ rpl_recalculate_ranks(void) while(p != NULL) { if(p->dag != NULL && p->dag->instance && (p->flags & RPL_PARENT_FLAG_UPDATED)) { p->flags &= ~RPL_PARENT_FLAG_UPDATED; - PRINTF("RPL: rpl_process_parent_event recalculate_ranks\n"); + LOG_DBG("rpl_process_parent_event recalculate_ranks\n"); if(!rpl_process_parent_event(p->dag->instance, p)) { - PRINTF("RPL: A parent was dropped\n"); + LOG_DBG("A parent was dropped\n"); } } p = nbr_table_next(rpl_parents, p); @@ -1380,26 +1381,26 @@ rpl_process_parent_event(rpl_instance_t *instance, rpl_parent_t *p) int return_value; rpl_parent_t *last_parent = instance->current_dag->preferred_parent; -#if DEBUG - rpl_rank_t old_rank; - old_rank = instance->current_dag->rank; -#endif /* DEBUG */ +#if LOG_DBG_ENABLED + rpl_rank_t old_rank; + old_rank = instance->current_dag->rank; +#endif /* LOG_DBG_ENABLED */ return_value = 1; if(RPL_IS_STORING(instance) && uip_ds6_route_is_nexthop(rpl_parent_get_ipaddr(p)) && !rpl_parent_is_reachable(p) && instance->mop > RPL_MOP_NON_STORING) { - PRINTF("RPL: Unacceptable link %u, removing routes via: ", rpl_get_parent_link_metric(p)); - PRINT6ADDR(rpl_parent_get_ipaddr(p)); - PRINTF("\n"); + LOG_WARN("Unacceptable link %u, removing routes via: ", rpl_get_parent_link_metric(p)); + LOG_WARN_6ADDR(rpl_parent_get_ipaddr(p)); + LOG_WARN_("\n"); rpl_remove_routes_by_nexthop(rpl_parent_get_ipaddr(p), p->dag); } if(!acceptable_rank(p->dag, p->rank)) { /* The candidate parent is no longer valid: the rank increase resulting from the choice of it as a parent would be too high. */ - PRINTF("RPL: Unacceptable rank %u (Current min %u, MaxRankInc %u)\n", (unsigned)p->rank, + LOG_WARN("Unacceptable rank %u (Current min %u, MaxRankInc %u)\n", (unsigned)p->rank, p->dag->min_rank, p->dag->instance->max_rankinc); rpl_nullify_parent(p); if(p != instance->current_dag->preferred_parent) { @@ -1412,26 +1413,26 @@ rpl_process_parent_event(rpl_instance_t *instance, rpl_parent_t *p) if(rpl_select_dag(instance, p) == NULL) { if(last_parent != NULL) { /* No suitable parent anymore; trigger a local repair. */ - PRINTF("RPL: No parents found in any DAG\n"); + LOG_ERR("No parents found in any DAG\n"); rpl_local_repair(instance); return 0; } } -#if DEBUG +#if LOG_DBG_ENABLED if(DAG_RANK(old_rank, instance) != DAG_RANK(instance->current_dag->rank, instance)) { - PRINTF("RPL: Moving in the instance from rank %hu to %hu\n", + LOG_INFO("Moving in the instance from rank %hu to %hu\n", DAG_RANK(old_rank, instance), DAG_RANK(instance->current_dag->rank, instance)); if(instance->current_dag->rank != RPL_INFINITE_RANK) { - PRINTF("RPL: The preferred parent is "); - PRINT6ADDR(rpl_parent_get_ipaddr(instance->current_dag->preferred_parent)); - PRINTF(" (rank %u)\n", + LOG_DBG("The preferred parent is "); + LOG_DBG_6ADDR(rpl_parent_get_ipaddr(instance->current_dag->preferred_parent)); + LOG_DBG_(" (rank %u)\n", (unsigned)DAG_RANK(instance->current_dag->preferred_parent->rank, instance)); } else { - PRINTF("RPL: We don't have any parent"); + LOG_WARN("We don't have any parent"); } } -#endif /* DEBUG */ +#endif /* LOG_DBG_ENABLED */ return return_value; } @@ -1441,9 +1442,9 @@ add_nbr_from_dio(uip_ipaddr_t *from, rpl_dio_t *dio) { /* add this to the neighbor cache if not already there */ if(rpl_icmp6_update_nbr_table(from, NBR_TABLE_REASON_RPL_DIO, dio) == NULL) { - PRINTF("RPL: Out of memory, dropping DIO from "); - PRINT6ADDR(from); - PRINTF("\n"); + LOG_ERR("Out of memory, dropping DIO from "); + LOG_ERR_6ADDR(from); + LOG_ERR_("\n"); return 0; } return 1; @@ -1463,7 +1464,7 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio) #else if(dio->mop != RPL_MOP_DEFAULT) { #endif - PRINTF("RPL: Ignoring a DIO with an unsupported MOP: %d\n", dio->mop); + LOG_ERR("Ignoring a DIO with an unsupported MOP: %d\n", dio->mop); return; } @@ -1473,15 +1474,15 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio) if(dag != NULL && instance != NULL) { if(lollipop_greater_than(dio->version, dag->version)) { if(dag->rank == ROOT_RANK(instance)) { - PRINTF("RPL: Root received inconsistent DIO version number (current: %u, received: %u)\n", dag->version, dio->version); + LOG_WARN("Root received inconsistent DIO version number (current: %u, received: %u)\n", dag->version, dio->version); dag->version = dio->version; RPL_LOLLIPOP_INCREMENT(dag->version); rpl_reset_dio_timer(instance); } else { - PRINTF("RPL: Global repair\n"); + LOG_DBG("Global repair\n"); if(dio->prefix_info.length != 0) { if(dio->prefix_info.flags & UIP_ND6_RA_FLAG_AUTONOMOUS) { - PRINTF("RPL: Prefix announced in DIO\n"); + LOG_DBG("Prefix announced in DIO\n"); rpl_set_prefix(dag, &dio->prefix_info.prefix, dio->prefix_info.length); } } @@ -1492,7 +1493,7 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio) if(lollipop_greater_than(dag->version, dio->version)) { /* The DIO sender is on an older version of the DAG. */ - PRINTF("RPL: old version received => inconsistency detected\n"); + LOG_WARN("old version received => inconsistency detected\n"); if(dag->joined) { rpl_reset_dio_timer(instance); return; @@ -1501,41 +1502,41 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio) } if(instance == NULL) { - PRINTF("RPL: New instance detected (ID=%u): Joining...\n", dio->instance_id); + LOG_INFO("New instance detected (ID=%u): Joining...\n", dio->instance_id); if(add_nbr_from_dio(from, dio)) { rpl_join_instance(from, dio); } else { - PRINTF("RPL: Not joining since could not add parent\n"); + LOG_WARN("Not joining since could not add parent\n"); } return; } if(instance->current_dag->rank == ROOT_RANK(instance) && instance->current_dag != dag) { - PRINTF("RPL: Root ignored DIO for different DAG\n"); + LOG_WARN("Root ignored DIO for different DAG\n"); return; } if(dag == NULL) { #if RPL_MAX_DAG_PER_INSTANCE > 1 - PRINTF("RPL: Adding new DAG to known instance.\n"); + LOG_INFO("Adding new DAG to known instance.\n"); if(!add_nbr_from_dio(from, dio)) { - PRINTF("RPL: Could not add new DAG, could not add parent\n"); + LOG_WARN("Could not add new DAG, could not add parent\n"); return; } dag = rpl_add_dag(from, dio); if(dag == NULL) { - PRINTF("RPL: Failed to add DAG.\n"); + LOG_WARN("Failed to add DAG.\n"); return; } #else /* RPL_MAX_DAG_PER_INSTANCE > 1 */ - PRINTF("RPL: Only one instance supported.\n"); + LOG_WARN("Only one instance supported.\n"); return; #endif /* RPL_MAX_DAG_PER_INSTANCE > 1 */ } if(dio->rank < ROOT_RANK(instance)) { - PRINTF("RPL: Ignoring DIO with too low rank: %u\n", + LOG_INFO("Ignoring DIO with too low rank: %u\n", (unsigned)dio->rank); return; } @@ -1543,13 +1544,13 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio) /* Prefix Information Option treated to add new prefix */ if(dio->prefix_info.length != 0) { if(dio->prefix_info.flags & UIP_ND6_RA_FLAG_AUTONOMOUS) { - PRINTF("RPL: Prefix announced in DIO\n"); + LOG_DBG("Prefix announced in DIO\n"); rpl_set_prefix(dag, &dio->prefix_info.prefix, dio->prefix_info.length); } } if(!add_nbr_from_dio(from, dio)) { - PRINTF("RPL: Could not add parent based on DIO\n"); + LOG_WARN("Could not add parent based on DIO\n"); return; } @@ -1562,9 +1563,9 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio) /* The DIO comes from a valid DAG, we can refresh its lifetime */ dag->lifetime = (1UL << (instance->dio_intmin + instance->dio_intdoubl)) * RPL_DAG_LIFETIME / 1000; - PRINTF("Set dag "); - PRINT6ADDR(&dag->dag_id); - PRINTF(" lifetime to %ld\n", dag->lifetime); + LOG_INFO("Set dag "); + LOG_INFO_6ADDR(&dag->dag_id); + LOG_INFO_(" lifetime to %ld\n", (long int) dag->lifetime); /* * At this point, we know that this DIO pertains to a DAG that @@ -1580,14 +1581,14 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio) /* Add the DIO sender as a candidate parent. */ p = rpl_add_parent(dag, dio, from); if(p == NULL) { - PRINTF("RPL: Failed to add a new parent ("); - PRINT6ADDR(from); - PRINTF(")\n"); + LOG_WARN("Failed to add a new parent ("); + LOG_WARN_6ADDR(from); + LOG_WARN_(")\n"); return; } - PRINTF("RPL: New candidate parent with rank %u: ", (unsigned)p->rank); - PRINT6ADDR(from); - PRINTF("\n"); + LOG_INFO("New candidate parent with rank %u: ", (unsigned)p->rank); + LOG_INFO_6ADDR(from); + LOG_INFO_("\n"); } else { p = rpl_find_parent(previous_dag, from); if(p != NULL) { @@ -1596,7 +1597,7 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio) } } else { if(p->rank == dio->rank) { - PRINTF("RPL: Received consistent DIO\n"); + LOG_WARN("Received consistent DIO\n"); if(dag->joined) { instance->dio_counter++; } @@ -1612,11 +1613,11 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio) /* Parent info has been updated, trigger rank recalculation */ p->flags |= RPL_PARENT_FLAG_UPDATED; - PRINTF("RPL: preferred DAG "); - PRINT6ADDR(&instance->current_dag->dag_id); - PRINTF(", rank %u, min_rank %u, ", + LOG_INFO("preferred DAG "); + LOG_INFO_6ADDR(&instance->current_dag->dag_id); + LOG_INFO_(", rank %u, min_rank %u, ", instance->current_dag->rank, instance->current_dag->min_rank); - PRINTF("parent rank %u, link metric %u\n", + LOG_INFO_("parent rank %u, link metric %u\n", p->rank, rpl_get_parent_link_metric(p)); /* We have allocated a candidate parent; process the DIO further. */ @@ -1625,7 +1626,7 @@ rpl_process_dio(uip_ipaddr_t *from, rpl_dio_t *dio) memcpy(&p->mc, &dio->mc, sizeof(p->mc)); #endif /* RPL_WITH_MC */ if(rpl_process_parent_event(instance, p) == 0) { - PRINTF("RPL: The candidate parent is rejected\n"); + LOG_WARN("The candidate parent is rejected\n"); return; } diff --git a/os/net/routing/rpl-classic/rpl-ext-header.c b/os/net/routing/rpl-classic/rpl-ext-header.c index e6498b993..8488d5ac6 100644 --- a/os/net/routing/rpl-classic/rpl-ext-header.c +++ b/os/net/routing/rpl-classic/rpl-ext-header.c @@ -52,8 +52,10 @@ #include "net/routing/rpl-classic/rpl-private.h" #include "net/packetbuf.h" -#define DEBUG DEBUG_NONE -#include "net/ipv6/uip-debug.h" +#include "sys/log.h" + +#define LOG_MODULE "RPL" +#define LOG_LEVEL LOG_LEVEL_RPL #include #include @@ -83,7 +85,7 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset) || UIP_EXT_HDR_OPT_RPL_BUF->opt_type != UIP_EXT_HDR_OPT_RPL || UIP_EXT_HDR_OPT_RPL_BUF->opt_len != RPL_HDR_OPT_LEN) { - PRINTF("RPL: Hop-by-hop extension header has wrong size or type (%u %u %u)\n", + LOG_ERR("Hop-by-hop extension header has wrong size or type (%u %u %u)\n", UIP_HBHO_BUF->len, UIP_EXT_HDR_OPT_RPL_BUF->opt_type, UIP_EXT_HDR_OPT_RPL_BUF->opt_len); @@ -92,13 +94,13 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset) instance = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF->instance); if(instance == NULL) { - PRINTF("RPL: Unknown instance: %u\n", + LOG_ERR("Unknown instance: %u\n", UIP_EXT_HDR_OPT_RPL_BUF->instance); return 0; } if(UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_FWD_ERR) { - PRINTF("RPL: Forward error!\n"); + LOG_ERR("Forward error!\n"); /* We should try to repair it by removing the neighbor that caused the packet to be forwareded in the first place. We drop any routes that go through the neighbor that sent the packet to @@ -117,7 +119,7 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset) } if(!instance->current_dag->joined) { - PRINTF("RPL: No DAG in the instance\n"); + LOG_ERR("No DAG in the instance\n"); return 0; } down = 0; @@ -142,14 +144,14 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset) sender_closer = sender_rank < instance->current_dag->rank; - PRINTF("RPL: Packet going %s, sender closer %d (%d < %d)\n", down == 1 ? "down" : "up", + LOG_DBG("Packet going %s, sender closer %d (%d < %d)\n", down == 1 ? "down" : "up", sender_closer, sender_rank, instance->current_dag->rank ); if((down && !sender_closer) || (!down && sender_closer)) { - PRINTF("RPL: Loop detected - senderrank: %d my-rank: %d sender_closer: %d\n", + LOG_WARN("Loop detected - senderrank: %d my-rank: %d sender_closer: %d\n", sender_rank, instance->current_dag->rank, sender_closer); /* Attempt to repair the loop by sending a unicast DIO back to the sender @@ -160,18 +162,18 @@ rpl_ext_header_hbh_update(int uip_ext_opt_offset) } if(UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_RANK_ERR) { RPL_STAT(rpl_stats.loop_errors++); - PRINTF("RPL: Rank error signalled in RPL option!\n"); + LOG_ERR(" Rank error signalled in RPL option!\n"); /* Packet must be dropped and dio trickle timer reset, see RFC6550 - 11.2.2.2 */ rpl_reset_dio_timer(instance); return 0; } - PRINTF("RPL: Single error tolerated\n"); + LOG_WARN("Single error tolerated\n"); RPL_STAT(rpl_stats.loop_warnings++); UIP_EXT_HDR_OPT_RPL_BUF->flags |= RPL_HDR_OPT_RANK_ERR; return 1; } - PRINTF("RPL: Rank OK\n"); + LOG_DBG("Rank OK\n"); return 1; } /*---------------------------------------------------------------------------*/ @@ -281,7 +283,7 @@ rpl_ext_header_srh_update(void) path_len = ((ext_len - padding - RPL_RH_LEN - RPL_SRH_LEN - (16 - cmpre)) / (16 - cmpri)) + 1; (void)path_len; - PRINTF("RPL: read SRH, path len %u, segments left %u, Cmpri %u, Cmpre %u, ext len %u (padding %u)\n", + LOG_DBG("read SRH, path len %u, segments left %u, Cmpri %u, Cmpre %u, ext len %u (padding %u)\n", path_len, segments_left, cmpri, cmpre, ext_len, padding); if(segments_left == 0) { @@ -303,9 +305,9 @@ rpl_ext_header_srh_update(void) /* Update segments left field */ UIP_RH_BUF->seg_left--; - PRINTF("RPL: SRH next hop "); - PRINT6ADDR(&UIP_IP_BUF->destipaddr); - PRINTF("\n"); + LOG_INFO("SRH next hop "); + LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr); + LOG_INFO_("\n"); } uip_ext_len = last_uip_ext_len; return 1; @@ -346,9 +348,9 @@ insert_srh_header(void) rpl_dag_t *dag; uip_ipaddr_t node_addr; - PRINTF("RPL: SRH creating source routing header with destination "); - PRINT6ADDR(&UIP_IP_BUF->destipaddr); - PRINTF(" \n"); + LOG_INFO("SRH creating source routing header with destination "); + LOG_INFO_6ADDR(&UIP_IP_BUF->destipaddr); + LOG_INFO_("\n"); /* Construct source route. We do not do this recursively to keep the runtime stack usage constant. */ @@ -356,7 +358,7 @@ insert_srh_header(void) dag = rpl_get_dag(&UIP_IP_BUF->destipaddr); if(dag == NULL) { - PRINTF("RPL: SRH DAG not found\n"); + LOG_ERR("SRH DAG not found\n"); return 0; } @@ -368,12 +370,12 @@ insert_srh_header(void) root_node = uip_sr_get_node(dag, &dag->dag_id); if(root_node == NULL) { - PRINTF("RPL: SRH root node not found\n"); + LOG_ERR("SRH root node not found\n"); return 0; } if(!uip_sr_is_addr_reachable(dag, &UIP_IP_BUF->destipaddr)) { - PRINTF("RPL: SRH no path found to destination\n"); + LOG_ERR("SRH no path found to destination\n"); return 0; } @@ -385,7 +387,7 @@ insert_srh_header(void) cmpre = 15; if(node == root_node) { - PRINTF("RPL: SRH no need to insert SRH\n"); + LOG_DBG("SRH no need to insert SRH\n"); return 1; } @@ -397,9 +399,9 @@ insert_srh_header(void) cmpri = MIN(cmpri, count_matching_bytes(&node_addr, &UIP_IP_BUF->destipaddr, 16)); cmpre = cmpri; - PRINTF("RPL: SRH Hop "); - PRINT6ADDR(&node_addr); - PRINTF("\n"); + LOG_DBG("SRH Hop "); + LOG_DBG_6ADDR(&node_addr); + LOG_DBG_("\n"); node = node->parent; path_len++; } @@ -412,12 +414,12 @@ insert_srh_header(void) padding = ext_len % 8 == 0 ? 0 : (8 - (ext_len % 8)); ext_len += padding; - PRINTF("RPL: SRH Path len: %u, ComprI %u, ComprE %u, ext len %u (padding %u)\n", + LOG_DBG("SRH Path len: %u, ComprI %u, ComprE %u, ext len %u (padding %u)\n", path_len, cmpri, cmpre, ext_len, padding); /* Check if there is enough space to store the extension header */ if(uip_len + ext_len > UIP_BUFSIZE - UIP_LLH_LEN) { - PRINTF("RPL: Packet too long: impossible to add source routing header (%u bytes)\n", ext_len); + LOG_ERR("Packet too long: impossible to add source routing header (%u bytes)\n", ext_len); return 0; } @@ -486,7 +488,7 @@ update_hbh_header(void) if(UIP_HBHO_BUF->len != ((RPL_HOP_BY_HOP_LEN - 8) / 8) || UIP_EXT_HDR_OPT_RPL_BUF->opt_len != RPL_HDR_OPT_LEN) { - PRINTF("RPL: Hop-by-hop extension header has wrong size (%u %u)\n", + LOG_ERR("Hop-by-hop extension header has wrong size (%u %u)\n", UIP_EXT_HDR_OPT_RPL_BUF->opt_len, uip_ext_len); return 0; /* Drop */ @@ -494,12 +496,12 @@ update_hbh_header(void) instance = rpl_get_instance(UIP_EXT_HDR_OPT_RPL_BUF->instance); if(instance == NULL || !instance->used || !instance->current_dag->joined) { - PRINTF("RPL: Unable to add/update hop-by-hop extension header: incorrect instance\n"); + LOG_ERR("Unable to add/update hop-by-hop extension header: incorrect instance\n"); uip_ext_len = last_uip_ext_len; return 0; /* Drop */ } - PRINTF("RPL: Updating RPL option\n"); + LOG_INFO("Updating RPL option\n"); /* Update sender rank and instance, will update flags next */ UIP_EXT_HDR_OPT_RPL_BUF->senderrank = UIP_HTONS(instance->current_dag->rank); UIP_EXT_HDR_OPT_RPL_BUF->instance = instance->instance_id; @@ -512,10 +514,10 @@ update_hbh_header(void) if((UIP_EXT_HDR_OPT_RPL_BUF->flags & RPL_HDR_OPT_DOWN)) { if(uip_ds6_route_lookup(&UIP_IP_BUF->destipaddr) == NULL) { UIP_EXT_HDR_OPT_RPL_BUF->flags |= RPL_HDR_OPT_FWD_ERR; - PRINTF("RPL forwarding error\n"); + LOG_WARN("RPL forwarding error\n"); /* We should send back the packet to the originating parent, but it is not feasible yet, so we send a No-Path DAO instead */ - PRINTF("RPL generate No-Path DAO\n"); + LOG_WARN("RPL generate No-Path DAO\n"); parent = rpl_get_parent((uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_SENDER)); if(parent != NULL) { dao_output_target(parent, &UIP_IP_BUF->destipaddr, RPL_ZERO_LIFETIME); @@ -531,11 +533,11 @@ update_hbh_header(void) /* No route was found, so this packet will go towards the RPL root. If so, we should not set the down flag. */ UIP_EXT_HDR_OPT_RPL_BUF->flags &= ~RPL_HDR_OPT_DOWN; - PRINTF("RPL option going up\n"); + LOG_DBG("RPL option going up\n"); } else { /* A DAO route was found so we set the down flag. */ UIP_EXT_HDR_OPT_RPL_BUF->flags |= RPL_HDR_OPT_DOWN; - PRINTF("RPL option going down\n"); + LOG_DBG("RPL option going down\n"); } } } @@ -557,9 +559,9 @@ insert_hbh_header(const rpl_instance_t *instance) uip_ext_opt_offset = 2; /* Insert hop-by-hop header */ - PRINTF("RPL: Creating hop-by-hop option\n"); + LOG_DBG("Creating hop-by-hop option\n"); if(uip_len + RPL_HOP_BY_HOP_LEN > UIP_BUFSIZE - UIP_LLH_LEN) { - PRINTF("RPL: Packet too long: impossible to add hop-by-hop option\n"); + LOG_ERR("Packet too long: impossible to add hop-by-hop option\n"); uip_ext_len = last_uip_ext_len; return 0; } @@ -619,7 +621,7 @@ rpl_ext_header_remove(void) if(UIP_IP_BUF->len[1] > temp_len) { UIP_IP_BUF->len[0]--; } - PRINTF("RPL: Removing RPL extension header (type %u, len %u)\n", *uip_next_hdr, rpl_ext_hdr_len); + LOG_DBG("Removing RPL extension header (type %u, len %u)\n", *uip_next_hdr, rpl_ext_hdr_len); memmove(UIP_EXT_BUF, ((uint8_t *)UIP_EXT_BUF) + rpl_ext_hdr_len, uip_len - UIP_IPH_LEN); } else { uip_next_hdr = &UIP_EXT_BUF->next; diff --git a/os/net/routing/rpl-classic/rpl-icmp6.c b/os/net/routing/rpl-classic/rpl-icmp6.c index 914575dbf..a246e576e 100644 --- a/os/net/routing/rpl-classic/rpl-icmp6.c +++ b/os/net/routing/rpl-classic/rpl-icmp6.c @@ -56,12 +56,13 @@ #include "net/ipv6/multicast/uip-mcast6.h" #include "random.h" +#include "sys/log.h" + #include #include -#define DEBUG DEBUG_NONE - -#include "net/ipv6/uip-debug.h" +#define LOG_MODULE "RPL" +#define LOG_LEVEL LOG_LEVEL_RPL /*---------------------------------------------------------------------------*/ #define RPL_DIO_GROUNDED 0x80 @@ -201,11 +202,11 @@ rpl_icmp6_update_nbr_table(uip_ipaddr_t *from, nbr_table_reason_t reason, void * if((nbr = uip_ds6_nbr_add(from, (uip_lladdr_t *) packetbuf_addr(PACKETBUF_ADDR_SENDER), 0, NBR_REACHABLE, reason, data)) != NULL) { - PRINTF("RPL: Neighbor added to neighbor cache "); - PRINT6ADDR(from); - PRINTF(", "); - PRINTLLADDR((uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_SENDER)); - PRINTF("\n"); + LOG_INFO("Neighbor added to neighbor cache "); + LOG_INFO_6ADDR(from); + LOG_INFO_(", "); + LOG_INFO_LLADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER)); + LOG_INFO_("\n"); } } @@ -219,31 +220,31 @@ dis_input(void) rpl_instance_t *end; /* DAG Information Solicitation */ - PRINTF("RPL: Received a DIS from "); - PRINT6ADDR(&UIP_IP_BUF->srcipaddr); - PRINTF("\n"); + LOG_INFO("Received a DIS from "); + LOG_INFO_6ADDR(&UIP_IP_BUF->srcipaddr); + LOG_INFO_("\n"); for(instance = &instance_table[0], end = instance + RPL_MAX_INSTANCES; instance < end; ++instance) { if(instance->used == 1) { if(uip_is_addr_mcast(&UIP_IP_BUF->destipaddr)) { #if RPL_LEAF_ONLY - PRINTF("RPL: LEAF ONLY Multicast DIS will NOT reset DIO timer\n"); + LOG_INFO("LEAF ONLY Multicast DIS will NOT reset DIO timer\n"); #else /* !RPL_LEAF_ONLY */ - PRINTF("RPL: Multicast DIS => reset DIO timer\n"); + LOG_DBG("Multicast DIS => reset DIO timer\n"); rpl_reset_dio_timer(instance); #endif /* !RPL_LEAF_ONLY */ } else { /* Check if this neighbor should be added according to the policy. */ if(rpl_icmp6_update_nbr_table(&UIP_IP_BUF->srcipaddr, NBR_TABLE_REASON_RPL_DIS, NULL) == NULL) { - PRINTF("RPL: Out of Memory, not sending unicast DIO, DIS from "); - PRINT6ADDR(&UIP_IP_BUF->srcipaddr); - PRINTF(", "); - PRINTLLADDR((uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_SENDER)); - PRINTF("\n"); + LOG_ERR("Out of Memory, not sending unicast DIO, DIS from "); + LOG_ERR_6ADDR(&UIP_IP_BUF->srcipaddr); + LOG_ERR_(", "); + LOG_ERR_LLADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER)); + LOG_ERR_("\n"); } else { - PRINTF("RPL: Unicast DIS, reply to sender\n"); + LOG_DBG("Unicast DIS, reply to sender\n"); dio_output(instance, &UIP_IP_BUF->srcipaddr); } /* } */ @@ -276,9 +277,9 @@ dis_output(uip_ipaddr_t *addr) addr = &tmpaddr; } - PRINTF("RPL: Sending a DIS to "); - PRINT6ADDR(addr); - PRINTF("\n"); + LOG_INFO("Sending a DIS to "); + LOG_INFO_6ADDR(addr); + LOG_INFO_("\n"); uip_icmp6_send(addr, ICMP6_RPL, RPL_CODE_DIS, 2); } @@ -309,9 +310,9 @@ dio_input(void) uip_ipaddr_copy(&from, &UIP_IP_BUF->srcipaddr); /* DAG Information Object */ - PRINTF("RPL: Received a DIO from "); - PRINT6ADDR(&from); - PRINTF("\n"); + LOG_INFO("Received a DIO from "); + LOG_INFO_6ADDR(&from); + LOG_INFO_("\n"); buffer_length = uip_len - uip_l3_icmp_hdr_len; @@ -324,7 +325,7 @@ dio_input(void) dio.rank = get16(buffer, i); i += 2; - PRINTF("RPL: Incoming DIO (id, ver, rank) = (%u,%u,%u)\n", + LOG_DBG("Incoming DIO (id, ver, rank) = (%u,%u,%u)\n", (unsigned)dio.instance_id, (unsigned)dio.version, (unsigned)dio.rank); @@ -340,9 +341,9 @@ dio_input(void) memcpy(&dio.dag_id, buffer + i, sizeof(dio.dag_id)); i += sizeof(dio.dag_id); - PRINTF("RPL: Incoming DIO (dag_id, pref) = ("); - PRINT6ADDR(&dio.dag_id); - PRINTF(", %u)\n", dio.preference); + LOG_DBG("Incoming DIO (dag_id, pref) = ("); + LOG_DBG_6ADDR(&dio.dag_id); + LOG_DBG_(", %u)\n", dio.preference); /* Check if there are any DIO suboptions. */ for(; i < buffer_length; i += len) { @@ -355,17 +356,17 @@ dio_input(void) } if(len + i > buffer_length) { - PRINTF("RPL: Invalid DIO packet\n"); + LOG_WARN("Invalid DIO packet\n"); RPL_STAT(rpl_stats.malformed_msgs++); goto discard; } - PRINTF("RPL: DIO option %u, length: %u\n", subopt_type, len - 2); + LOG_DBG("Incoming DIO (option, length) = (%u, %u)\n", subopt_type, len - 2); switch(subopt_type) { case RPL_OPTION_DAG_METRIC_CONTAINER: if(len < 6) { - PRINTF("RPL: Invalid DAG MC, len = %d\n", len); + LOG_WARN("Invalid DAG MC, len = %d\n", len); RPL_STAT(rpl_stats.malformed_msgs++); goto discard; } @@ -381,7 +382,7 @@ dio_input(void) } else if(dio.mc.type == RPL_DAG_MC_ETX) { dio.mc.obj.etx = get16(buffer, i + 6); - PRINTF("RPL: DAG MC: type %u, flags %u, aggr %u, prec %u, length %u, ETX %u\n", + LOG_DBG("DAG MC: type %u, flags %u, aggr %u, prec %u, length %u, ETX %u\n", (unsigned)dio.mc.type, (unsigned)dio.mc.flags, (unsigned)dio.mc.aggr, @@ -392,13 +393,13 @@ dio_input(void) dio.mc.obj.energy.flags = buffer[i + 6]; dio.mc.obj.energy.energy_est = buffer[i + 7]; } else { - PRINTF("RPL: Unhandled DAG MC type: %u\n", (unsigned)dio.mc.type); + LOG_WARN("Unhandled DAG MC type: %u\n", (unsigned)dio.mc.type); goto discard; } break; case RPL_OPTION_ROUTE_INFO: if(len < 9) { - PRINTF("RPL: Invalid destination prefix option, len = %d\n", len); + LOG_WARN("Invalid destination prefix option, len = %d\n", len); RPL_STAT(rpl_stats.malformed_msgs++); goto discard; } @@ -410,11 +411,11 @@ dio_input(void) if(((dio.destination_prefix.length + 7) / 8) + 8 <= len && dio.destination_prefix.length <= 128) { - PRINTF("RPL: Copying destination prefix\n"); + LOG_INFO("Copying destination prefix\n"); memcpy(&dio.destination_prefix.prefix, &buffer[i + 8], (dio.destination_prefix.length + 7) / 8); } else { - PRINTF("RPL: Invalid route info option, len = %d\n", len); + LOG_WARN("Invalid route info option, len = %d\n", len); RPL_STAT(rpl_stats.malformed_msgs++); goto discard; } @@ -422,7 +423,7 @@ dio_input(void) break; case RPL_OPTION_DAG_CONF: if(len != 16) { - PRINTF("RPL: Invalid DAG configuration option, len = %d\n", len); + LOG_WARN("Invalid DAG configuration option, len = %d\n", len); RPL_STAT(rpl_stats.malformed_msgs++); goto discard; } @@ -437,14 +438,14 @@ dio_input(void) /* buffer + 12 is reserved */ dio.default_lifetime = buffer[i + 13]; dio.lifetime_unit = get16(buffer, i + 14); - PRINTF("RPL: DAG conf:dbl=%d, min=%d red=%d maxinc=%d mininc=%d ocp=%d d_l=%u l_u=%u\n", + LOG_INFO("DAG conf:dbl=%d, min=%d red=%d maxinc=%d mininc=%d ocp=%d d_l=%u l_u=%u\n", dio.dag_intdoubl, dio.dag_intmin, dio.dag_redund, dio.dag_max_rankinc, dio.dag_min_hoprankinc, dio.ocp, dio.default_lifetime, dio.lifetime_unit); break; case RPL_OPTION_PREFIX_INFO: if(len != 32) { - PRINTF("RPL: Invalid DAG prefix info, len != 32\n"); + LOG_WARN("Invalid DAG prefix info, len != 32\n"); RPL_STAT(rpl_stats.malformed_msgs++); goto discard; } @@ -454,11 +455,11 @@ dio_input(void) /* preferred lifetime stored in lifetime */ dio.prefix_info.lifetime = get32(buffer, i + 8); /* 32-bit reserved at i + 12 */ - PRINTF("RPL: Copying prefix information\n"); + LOG_INFO("Copying prefix information\n"); memcpy(&dio.prefix_info.prefix, &buffer[i + 16], 16); break; default: - PRINTF("RPL: Unsupported suboption type in DIO: %u\n", + LOG_WARN("Unsupported suboption type in DIO: %u\n", (unsigned)subopt_type); } } @@ -488,7 +489,7 @@ dio_output(rpl_instance_t *instance, uip_ipaddr_t *uc_addr) /* In leaf mode, we only send DIO messages as unicasts in response to unicast DIS messages. */ if(uc_addr == NULL) { - PRINTF("RPL: LEAF ONLY have multicast addr: skip dio_output\n"); + LOG_DBG("LEAF ONLY have multicast addr: skip dio_output\n"); return; } #endif /* RPL_LEAF_ONLY */ @@ -502,7 +503,7 @@ dio_output(rpl_instance_t *instance, uip_ipaddr_t *uc_addr) is_root = (dag->rank == ROOT_RANK(instance)); #if RPL_LEAF_ONLY - PRINTF("RPL: LEAF ONLY DIO rank set to RPL_INFINITE_RANK\n"); + LOG_DBG("LEAF ONLY DIO rank set to RPL_INFINITE_RANK\n"); set16(buffer, pos, RPL_INFINITE_RANK); #else /* RPL_LEAF_ONLY */ set16(buffer, pos, dag->rank); @@ -553,7 +554,7 @@ dio_output(rpl_instance_t *instance, uip_ipaddr_t *uc_addr) buffer[pos++] = instance->mc.obj.energy.flags; buffer[pos++] = instance->mc.obj.energy.energy_est; } else { - PRINTF("RPL: Unable to send DIO because of unhandled DAG MC type %u\n", + LOG_ERR("Unable to send DIO because of unhandled DAG MC type %u\n", (unsigned)instance->mc.type); return; } @@ -593,37 +594,38 @@ dio_output(rpl_instance_t *instance, uip_ipaddr_t *uc_addr) pos += 4; memcpy(&buffer[pos], &dag->prefix_info.prefix, 16); pos += 16; - PRINTF("RPL: Sending prefix info in DIO for "); - PRINT6ADDR(&dag->prefix_info.prefix); - PRINTF("\n"); + LOG_DBG("Sending prefix info in DIO for "); + LOG_DBG_6ADDR(&dag->prefix_info.prefix); + LOG_DBG_("\n"); } else { - PRINTF("RPL: No prefix to announce (len %d)\n", + LOG_DBG("No prefix to announce (len %d)\n", dag->prefix_info.length); } #if RPL_LEAF_ONLY -#if (DEBUG) & DEBUG_PRINT - if(uc_addr == NULL) { - PRINTF("RPL: LEAF ONLY sending unicast-DIO from multicast-DIO\n"); + if(LOG_DBG_ENABLED) { + if(uc_addr == NULL) { + LOG_DBG("LEAF ONLY sending unicast-DIO from multicast-DIO\n"); + } } -#endif /* DEBUG_PRINT */ - PRINTF("RPL: Sending unicast-DIO with rank %u to ", + + LOG_INFO("Sending unicast-DIO with rank %u to ", (unsigned)dag->rank); - PRINT6ADDR(uc_addr); - PRINTF("\n"); + LOG_INFO_6ADDR(uc_addr); + LOG_INFO_("\n"); uip_icmp6_send(uc_addr, ICMP6_RPL, RPL_CODE_DIO, pos); #else /* RPL_LEAF_ONLY */ /* Unicast requests get unicast replies! */ if(uc_addr == NULL) { - PRINTF("RPL: Sending a multicast-DIO with rank %u\n", + LOG_INFO("Sending a multicast-DIO with rank %u\n", (unsigned)instance->current_dag->rank); uip_create_linklocal_rplnodes_mcast(&addr); uip_icmp6_send(&addr, ICMP6_RPL, RPL_CODE_DIO, pos); } else { - PRINTF("RPL: Sending unicast-DIO with rank %u to ", + LOG_INFO("Sending unicast-DIO with rank %u to ", (unsigned)instance->current_dag->rank); - PRINT6ADDR(uc_addr); - PRINTF("\n"); + LOG_INFO_6ADDR(uc_addr); + LOG_INFO_("\n"); uip_icmp6_send(uc_addr, ICMP6_RPL, RPL_CODE_DIO, pos); } #endif /* RPL_LEAF_ONLY */ @@ -685,7 +687,7 @@ dao_input_storing(void) /* Is the DAG ID present? */ if(flags & RPL_DAO_D_FLAG) { if(memcmp(&dag->dag_id, &buffer[pos], sizeof(dag->dag_id))) { - PRINTF("RPL: Ignoring a DAO for a DAG different from ours\n"); + LOG_INFO("Ignoring a DAO for a DAG different from ours\n"); return; } pos += 16; @@ -695,10 +697,10 @@ dao_input_storing(void) RPL_ROUTE_FROM_MULTICAST_DAO : RPL_ROUTE_FROM_UNICAST_DAO; /* Destination Advertisement Object */ - PRINTF("RPL: Received a (%s) DAO with sequence number %u from ", + LOG_DBG("Received a (%s) DAO with sequence number %u from ", learned_from == RPL_ROUTE_FROM_UNICAST_DAO? "unicast": "multicast", sequence); - PRINT6ADDR(&dao_sender_addr); - PRINTF("\n"); + LOG_DBG_6ADDR(&dao_sender_addr); + LOG_DBG_("\n"); if(learned_from == RPL_ROUTE_FROM_UNICAST_DAO) { /* Check whether this is a DAO forwarding loop. */ @@ -707,7 +709,7 @@ dao_input_storing(void) /* if we already route to this node it is likely */ if(parent != NULL && DAG_RANK(parent->rank, instance) < DAG_RANK(dag->rank, instance)) { - PRINTF("RPL: Loop detected when receiving a unicast DAO from a node with a lower rank! (%u < %u)\n", + LOG_WARN("Loop detected when receiving a unicast DAO from a node with a lower rank! (%u < %u)\n", DAG_RANK(parent->rank, instance), DAG_RANK(dag->rank, instance)); parent->rank = RPL_INFINITE_RANK; parent->flags |= RPL_PARENT_FLAG_UPDATED; @@ -716,7 +718,7 @@ dao_input_storing(void) /* If we get the DAO from our parent, we also have a loop. */ if(parent != NULL && parent == dag->preferred_parent) { - PRINTF("RPL: Loop detected when receiving a unicast DAO from our parent\n"); + LOG_WARN("Loop detected when receiving a unicast DAO from our parent\n"); parent->rank = RPL_INFINITE_RANK; parent->flags |= RPL_PARENT_FLAG_UPDATED; return; @@ -750,10 +752,10 @@ dao_input_storing(void) } } - PRINTF("RPL: DAO lifetime: %u, prefix length: %u prefix: ", + LOG_INFO("DAO lifetime: %u, prefix length: %u prefix: ", (unsigned)lifetime, (unsigned)prefixlen); - PRINT6ADDR(&prefix); - PRINTF("\n"); + LOG_INFO_6ADDR(&prefix); + LOG_INFO_("\n"); #if RPL_WITH_MULTICAST if(uip_is_addr_mcast_global(&prefix)) { @@ -774,16 +776,16 @@ dao_input_storing(void) rep = uip_ds6_route_lookup(&prefix); if(lifetime == RPL_ZERO_LIFETIME) { - PRINTF("RPL: No-Path DAO received\n"); + LOG_INFO("No-Path DAO received\n"); /* No-Path DAO received; invoke the route purging routine. */ if(rep != NULL && !RPL_ROUTE_IS_NOPATH_RECEIVED(rep) && rep->length == prefixlen && uip_ds6_route_nexthop(rep) != NULL && uip_ipaddr_cmp(uip_ds6_route_nexthop(rep), &dao_sender_addr)) { - PRINTF("RPL: Setting expiration timer for prefix "); - PRINT6ADDR(&prefix); - PRINTF("\n"); + LOG_DBG("Setting expiration timer for prefix "); + LOG_DBG_6ADDR(&prefix); + LOG_DBG_("\n"); RPL_ROUTE_SET_NOPATH_RECEIVED(rep); rep->state.lifetime = RPL_NOPATH_REMOVAL_DELAY; @@ -794,10 +796,10 @@ dao_input_storing(void) uint8_t out_seq; out_seq = prepare_for_dao_fwd(sequence, rep); - PRINTF("RPL: Forwarding No-path DAO to parent - out_seq:%d", + LOG_DBG("Forwarding No-path DAO to parent - out_seq:%d", out_seq); - PRINT6ADDR(rpl_parent_get_ipaddr(dag->preferred_parent)); - PRINTF("\n"); + LOG_DBG_6ADDR(rpl_parent_get_ipaddr(dag->preferred_parent)); + LOG_DBG_("\n"); buffer = UIP_ICMP_PAYLOAD; buffer[3] = out_seq; /* add an outgoing seq no before fwd */ @@ -815,15 +817,15 @@ dao_input_storing(void) return; } - PRINTF("RPL: Adding DAO route\n"); + LOG_INFO("Adding DAO route\n"); /* Update and add neighbor - if no room - fail. */ if((nbr = rpl_icmp6_update_nbr_table(&dao_sender_addr, NBR_TABLE_REASON_RPL_DAO, instance)) == NULL) { - PRINTF("RPL: Out of Memory, dropping DAO from "); - PRINT6ADDR(&dao_sender_addr); - PRINTF(", "); - PRINTLLADDR((uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_SENDER)); - PRINTF("\n"); + LOG_ERR("Out of Memory, dropping DAO from "); + LOG_ERR_6ADDR(&dao_sender_addr); + LOG_ERR_(", "); + LOG_ERR_LLADDR(packetbuf_addr(PACKETBUF_ADDR_SENDER)); + LOG_ERR_("\n"); if(flags & RPL_DAO_K_FLAG) { /* signal the failure to add the node */ dao_ack_output(instance, &dao_sender_addr, sequence, @@ -836,7 +838,7 @@ dao_input_storing(void) rep = rpl_add_route(dag, &prefix, prefixlen, &dao_sender_addr); if(rep == NULL) { RPL_STAT(rpl_stats.mem_overflows++); - PRINTF("RPL: Could not add a route after receiving a DAO\n"); + LOG_ERR("Could not add a route after receiving a DAO\n"); if(flags & RPL_DAO_K_FLAG) { /* signal the failure to add the node */ dao_ack_output(instance, &dao_sender_addr, sequence, @@ -887,9 +889,9 @@ fwd_dao: } } - PRINTF("RPL: Forwarding DAO to parent "); - PRINT6ADDR(rpl_parent_get_ipaddr(dag->preferred_parent)); - PRINTF(" in seq: %d out seq: %d\n", sequence, out_seq); + LOG_DBG("Forwarding DAO to parent "); + LOG_DBG_6ADDR(rpl_parent_get_ipaddr(dag->preferred_parent)); + LOG_DBG_(" in seq: %d out seq: %d\n", sequence, out_seq); buffer = UIP_ICMP_PAYLOAD; buffer[3] = out_seq; /* add an outgoing seq no before fwd */ @@ -897,7 +899,7 @@ fwd_dao: ICMP6_RPL, RPL_CODE_DAO, buffer_length); } if(should_ack) { - PRINTF("RPL: Sending DAO ACK\n"); + LOG_DBG("Sending DAO ACK\n"); uip_clear_buf(); dao_ack_output(instance, &dao_sender_addr, sequence, RPL_DAO_ACK_UNCONDITIONAL_ACCEPT); @@ -927,6 +929,11 @@ dao_input_nonstoring(void) int len; int i; + /* Destination Advertisement Object */ + LOG_INFO("Received a DAO from "); + LOG_INFO_6ADDR(&UIP_IP_BUF->srcipaddr); + LOG_INFO_("\n"); + prefixlen = 0; uip_ipaddr_copy(&dao_sender_addr, &UIP_IP_BUF->srcipaddr); @@ -949,7 +956,7 @@ dao_input_nonstoring(void) /* Is the DAG ID present? */ if(flags & RPL_DAO_D_FLAG) { if(memcmp(&dag->dag_id, &buffer[pos], sizeof(dag->dag_id))) { - PRINTF("RPL: Ignoring a DAO for a DAG different from ours\n"); + LOG_INFO("Ignoring a DAO for a DAG different from ours\n"); return; } pos += 16; @@ -984,25 +991,29 @@ dao_input_nonstoring(void) } } - PRINTF("RPL: DAO lifetime: %u, prefix length: %u prefix: ", + LOG_INFO("DAO lifetime: %u, prefix length: %u prefix: ", (unsigned)lifetime, (unsigned)prefixlen); - PRINT6ADDR(&prefix); - PRINTF(", parent: "); - PRINT6ADDR(&dao_parent_addr); - PRINTF(" \n"); + LOG_INFO_6ADDR(&prefix); + LOG_INFO_(", parent: "); + LOG_INFO_6ADDR(&dao_parent_addr); + LOG_INFO_("\n"); if(lifetime == RPL_ZERO_LIFETIME) { - PRINTF("RPL: No-Path DAO received\n"); + LOG_DBG("No-Path DAO received\n"); uip_sr_expire_parent(dag, &prefix, &dao_parent_addr); } else { if(uip_sr_update_node(dag, &prefix, &dao_parent_addr, RPL_LIFETIME(instance, lifetime)) == NULL) { - PRINTF("RPL: failed to add link\n"); + LOG_WARN("DAO failed to add link prefix: "); + LOG_WARN_6ADDR(&prefix); + LOG_WARN_(", parent: "); + LOG_WARN_6ADDR(&dao_parent_addr); + LOG_WARN_("\n"); return; } } if(flags & RPL_DAO_K_FLAG) { - PRINTF("RPL: Sending DAO ACK\n"); + LOG_DBG("Sending DAO ACK\n"); uip_clear_buf(); dao_ack_output(instance, &dao_sender_addr, sequence, RPL_DAO_ACK_UNCONDITIONAL_ACCEPT); @@ -1017,14 +1028,14 @@ dao_input(void) uint8_t instance_id; /* Destination Advertisement Object */ - PRINTF("RPL: Received a DAO from "); - PRINT6ADDR(&UIP_IP_BUF->srcipaddr); - PRINTF("\n"); + LOG_INFO("Received a DAO from "); + LOG_INFO_6ADDR(&UIP_IP_BUF->srcipaddr); + LOG_INFO_("\n"); instance_id = UIP_ICMP_PAYLOAD[0]; instance = rpl_get_instance(instance_id); if(instance == NULL) { - PRINTF("RPL: Ignoring a DAO for an unknown RPL instance(%u)\n", + LOG_INFO("Ignoring a DAO for an unknown RPL instance(%u)\n", instance_id); goto discard; } @@ -1076,7 +1087,7 @@ handle_dao_retransmission(void *ptr) return; } - PRINTF("RPL: will retransmit DAO - seq:%d trans:%d\n", instance->my_dao_seqno, + LOG_INFO("will retransmit DAO - seq:%d trans:%d\n", instance->my_dao_seqno, instance->my_dao_transmissions); if(get_global_addr(&prefix) == 0) { @@ -1101,7 +1112,7 @@ dao_output(rpl_parent_t *parent, uint8_t lifetime) uip_ipaddr_t prefix; if(get_global_addr(&prefix) == 0) { - PRINTF("RPL: No global address set for this node - suppressing DAO\n"); + LOG_ERR("No global address set for this node - suppressing DAO\n"); return; } @@ -1159,30 +1170,30 @@ dao_output_target_seq(rpl_parent_t *parent, uip_ipaddr_t *prefix, } if(parent == NULL) { - PRINTF("RPL dao_output_target error parent NULL\n"); + LOG_ERR("dao_output_target error parent NULL\n"); return; } parent_ipaddr = rpl_parent_get_ipaddr(parent); if(parent_ipaddr == NULL) { - PRINTF("RPL dao_output_target error parent IP address NULL\n"); + LOG_ERR("dao_output_target error parent IP address NULL\n"); return; } dag = parent->dag; if(dag == NULL) { - PRINTF("RPL dao_output_target error dag NULL\n"); + LOG_ERR("dao_output_target error dag NULL\n"); return; } instance = dag->instance; if(instance == NULL) { - PRINTF("RPL dao_output_target error instance NULL\n"); + LOG_ERR("dao_output_target error instance NULL\n"); return; } if(prefix == NULL) { - PRINTF("RPL dao_output_target error prefix NULL\n"); + LOG_ERR("dao_output_target error prefix NULL\n"); return; } #ifdef RPL_DEBUG_DAO_OUTPUT @@ -1240,15 +1251,15 @@ dao_output_target_seq(rpl_parent_t *parent, uip_ipaddr_t *prefix, dest_ipaddr = &parent->dag->dag_id; } - PRINTF("RPL: Sending a %sDAO with sequence number %u, lifetime %u, prefix ", + LOG_INFO("Sending a %sDAO with sequence number %u, lifetime %u, prefix ", lifetime == RPL_ZERO_LIFETIME ? "No-Path " : "", seq_no, lifetime); - PRINT6ADDR(prefix); - PRINTF(" to "); - PRINT6ADDR(dest_ipaddr); - PRINTF(" , parent "); - PRINT6ADDR(parent_ipaddr); - PRINTF("\n"); + LOG_INFO_6ADDR(prefix); + LOG_INFO_(" to "); + LOG_INFO_6ADDR(dest_ipaddr); + LOG_INFO_(" , parent "); + LOG_INFO_6ADDR(parent_ipaddr); + LOG_INFO_("\n"); if(dest_ipaddr != NULL) { uip_icmp6_send(dest_ipaddr, ICMP6_RPL, RPL_CODE_DAO, pos); @@ -1291,16 +1302,16 @@ dao_ack_input(void) } if(instance->current_dag->rank == ROOT_RANK(instance)) { - PRINTF("RPL: DODAG root received a DAO ACK, ignoring it\n"); + LOG_DBG("DODAG root received a DAO ACK, ignoring it\n"); uip_clear_buf(); return; } - PRINTF("RPL: Received a DAO %s with sequence number %d (%d) and status %d from ", + LOG_INFO("Received a DAO %s with sequence number %d (%d) and status %d from ", status < 128 ? "ACK" : "NACK", sequence, instance->my_dao_seqno, status); - PRINT6ADDR(&UIP_IP_BUF->srcipaddr); - PRINTF("\n"); + LOG_INFO_6ADDR(&UIP_IP_BUF->srcipaddr); + LOG_INFO_("\n"); if(sequence == instance->my_dao_seqno) { instance->has_downward_route = status < 128; @@ -1334,11 +1345,11 @@ dao_ack_input(void) nexthop = uip_ds6_route_nexthop(re); if(nexthop == NULL) { - PRINTF("RPL: No next hop to fwd DAO ACK to\n"); + LOG_WARN("No next hop to fwd DAO ACK to\n"); } else { - PRINTF("RPL: Fwd DAO ACK to:"); - PRINT6ADDR(nexthop); - PRINTF("\n"); + LOG_INFO("Fwd DAO ACK to:"); + LOG_INFO_6ADDR(nexthop); + LOG_INFO_("\n"); buffer[2] = re->state.dao_seqno_in; uip_icmp6_send(nexthop, ICMP6_RPL, RPL_CODE_DAO_ACK, 4); } @@ -1348,7 +1359,7 @@ dao_ack_input(void) uip_ds6_route_rm(re); } } else { - PRINTF("RPL: No route entry found to forward DAO ACK (seqno %u)\n", sequence); + LOG_WARN("No route entry found to forward DAO ACK (seqno %u)\n", sequence); } } #endif /* RPL_WITH_DAO_ACK */ @@ -1362,9 +1373,9 @@ dao_ack_output(rpl_instance_t *instance, uip_ipaddr_t *dest, uint8_t sequence, #if RPL_WITH_DAO_ACK unsigned char *buffer; - PRINTF("RPL: Sending a DAO %s with sequence number %d to ", status < 128 ? "ACK" : "NACK", sequence); - PRINT6ADDR(dest); - PRINTF(" with status %d\n", status); + LOG_INFO("Sending a DAO %s with sequence number %d to ", status < 128 ? "ACK" : "NACK", sequence); + LOG_INFO_6ADDR(dest); + LOG_INFO_(" with status %d\n", status); buffer = UIP_ICMP_PAYLOAD; diff --git a/os/net/routing/rpl-classic/rpl-mrhof.c b/os/net/routing/rpl-classic/rpl-mrhof.c index f3c75985b..988991b19 100644 --- a/os/net/routing/rpl-classic/rpl-mrhof.c +++ b/os/net/routing/rpl-classic/rpl-mrhof.c @@ -51,8 +51,10 @@ #include "net/nbr-table.h" #include "net/link-stats.h" -#define DEBUG DEBUG_NONE -#include "net/ipv6/uip-debug.h" +#include "sys/log.h" + +#define LOG_MODULE "RPL" +#define LOG_LEVEL LOG_LEVEL_RPL /* RFC6551 and RFC6719 do not mandate the use of a specific formula to * compute the ETX value. This MRHOF implementation relies on the value @@ -97,7 +99,7 @@ to the threshold of 96 in the non-squared case) */ static void reset(rpl_dag_t *dag) { - PRINTF("RPL: Reset MRHOF\n"); + LOG_INFO("Reset MRHOF\n"); } /*---------------------------------------------------------------------------*/ #if RPL_WITH_DAO_ACK @@ -108,7 +110,7 @@ dao_ack_callback(rpl_parent_t *p, int status) return; } /* here we need to handle failed DAO's and other stuff */ - PRINTF("RPL: MRHOF - DAO ACK received with status: %d\n", status); + LOG_DBG("MRHOF - DAO ACK received with status: %d\n", status); if(status >= RPL_DAO_ACK_UNABLE_TO_ACCEPT) { /* punish the ETX as if this was 10 packets lost */ link_stats_packet_sent(rpl_get_parent_lladdr(p), MAC_TX_OK, 10); @@ -262,7 +264,7 @@ update_metric_container(rpl_instance_t *instance) dag = instance->current_dag; if(dag == NULL || !dag->joined) { - PRINTF("RPL: Cannot update the metric container when not joined\n"); + LOG_WARN("Cannot update the metric container when not joined\n"); return; } @@ -297,7 +299,7 @@ update_metric_container(rpl_instance_t *instance) instance->mc.obj.energy.energy_est = path_cost >> 8; break; default: - PRINTF("RPL: MRHOF, non-supported MC %u\n", instance->mc.type); + LOG_WARN("MRHOF, non-supported MC %u\n", instance->mc.type); break; } } diff --git a/os/net/routing/rpl-classic/rpl-nbr-policy.c b/os/net/routing/rpl-classic/rpl-nbr-policy.c index 077977a10..344840d0e 100644 --- a/os/net/routing/rpl-classic/rpl-nbr-policy.c +++ b/os/net/routing/rpl-classic/rpl-nbr-policy.c @@ -49,8 +49,10 @@ #include "net/ipv6/uip-ds6-nbr.h" #include "net/ipv6/uip-ds6-route.h" -#define DEBUG DEBUG_NONE -#include "net/ipv6/uip-debug.h" +#include "sys/log.h" + +#define LOG_MODULE "RPL" +#define LOG_LEVEL LOG_LEVEL_RPL /* * Policy for neighbor adds @@ -71,7 +73,7 @@ static int num_free; static linkaddr_t *worst_rank_nbr; /* the parent that has the worst rank */ static rpl_rank_t worst_rank; /*---------------------------------------------------------------------------*/ -#if DEBUG == DEBUG_FULL +#if LOG_DBG_ENABLED /* * This create a periodic call of the update_nbr function that will print * useful debugging information when in DEBUG_FULL mode @@ -85,7 +87,7 @@ handle_periodic_timer(void *ptr) update_nbr(); ctimer_restart(&periodic_timer); } -#endif /* DEBUG == DEBUG_FULL */ +#endif /* LOG_DBG_ENABLED */ /*---------------------------------------------------------------------------*/ static void update_nbr(void) @@ -96,13 +98,13 @@ update_nbr(void) int is_used; rpl_rank_t rank; -#if DEBUG == DEBUG_FULL - if(!timer_init) { - timer_init = 1; - ctimer_set(&periodic_timer, 60 * CLOCK_SECOND, - &handle_periodic_timer, NULL); - } -#endif /* DEBUG == DEBUG_FULL */ +#if LOG_DBG_ENABLED + if(!timer_init) { + timer_init = 1; + ctimer_set(&periodic_timer, 60 * CLOCK_SECOND, + &handle_periodic_timer, NULL); + } +#endif /* LOG_DBG_ENABLED */ worst_rank = 0; worst_rank_nbr = NULL; @@ -152,9 +154,9 @@ update_nbr(void) worst_rank_nbr = lladdr; worst_rank = RPL_INFINITE_RANK; } else if(is_used > 1) { - PRINTF("NBR-POLICY: *** Neighbor is both child and candidate parent: "); - PRINTLLADDR((uip_lladdr_t *)lladdr); - PRINTF("\n"); + LOG_DBG("nbr-policy: *** neighbor is both child and candidate parent: "); + LOG_DBG_LLADDR(lladdr); + LOG_DBG_("\n"); } nbr = nbr_table_next(ds6_neighbors, nbr); @@ -163,7 +165,7 @@ update_nbr(void) /* how many more IP neighbors can be have? */ num_free = NBR_TABLE_MAX_NEIGHBORS - num_used; - PRINTF("NBR-POLICY: Free: %d, Children: %d, Parents: %d Routes: %d\n", + LOG_DBG("nbr-policy: free: %d, children: %d, parents: %d routes: %d\n", num_free, num_children, num_parents, uip_ds6_route_num_routes()); } /*---------------------------------------------------------------------------*/ @@ -177,7 +179,7 @@ find_removable_dis(uip_ipaddr_t *from) if(num_free > 0) { /* there are free entries (e.g. unsused by RPL and ND6) but since it is used by other modules we can not pick these entries for removal. */ - PRINTF("Num-free > 0 = %d - Other for RPL/ND6 unused NBR entry exists .", + LOG_DBG("nbr-policy: num-free > 0 = %d - Other for RPL/ND6 unused NBR entry exists.\n", num_free); } if(num_children < MAX_CHILDREN) { @@ -195,20 +197,20 @@ find_removable_dio(uip_ipaddr_t *from, rpl_dio_t *dio) instance = rpl_get_instance(dio->instance_id); if(instance == NULL || instance->current_dag == NULL) { - PRINTF("Did not find instance id: %d\n", dio->instance_id); + LOG_WARN("nbr-policy: did not find instance id: %d\n", dio->instance_id); return NULL; } /* Add the new neighbor only if it is better than the worst parent. */ if(dio->rank + instance->min_hoprankinc < worst_rank - instance->min_hoprankinc / 2) { /* Found *great* neighbor - add! */ - PRINTF("Found better neighbor %d < %d - add to cache...\n", + LOG_DBG("nbr-policy: DIO rank %u, worst_rank %u -- add to cache\n", dio->rank, worst_rank); return worst_rank_nbr; } - PRINTF("Found worse neighbor with new %d and old %d - NOT add to cache.\n", + LOG_DBG("nbr-policy: DIO rank %u, worst_rank %u -- do not add to cache\n", dio->rank, worst_rank); return NULL; } @@ -229,7 +231,7 @@ find_removable_dao(uip_ipaddr_t *from, rpl_instance_t *instance) /* Check if this DAO sender is not yet neighbor and there is already too many children. */ if(num_children >= max) { - PRINTF("Can not add another child - already at max.\n"); + LOG_ERR("nbr-policy: can not add another child - already at max.\n"); return NULL; } /* remove the worst ranked nbr */ diff --git a/os/net/routing/rpl-classic/rpl-of0.c b/os/net/routing/rpl-classic/rpl-of0.c index 1a679d23b..602b8934d 100644 --- a/os/net/routing/rpl-classic/rpl-of0.c +++ b/os/net/routing/rpl-classic/rpl-of0.c @@ -47,8 +47,10 @@ #include "net/nbr-table.h" #include "net/link-stats.h" -#define DEBUG DEBUG_NONE -#include "net/ipv6/uip-debug.h" +#include "sys/log.h" + +#define LOG_MODULE "RPL" +#define LOG_LEVEL LOG_LEVEL_RPL /* Constants from RFC6552. We use the default values. */ #define RANK_STRETCH 0 /* Must be in the range [0;5] */ @@ -87,7 +89,7 @@ static void reset(rpl_dag_t *dag) { - PRINTF("RPL: Reset OF0\n"); + LOG_INFO("Reset OF0\n"); } /*---------------------------------------------------------------------------*/ #if RPL_WITH_DAO_ACK @@ -98,7 +100,7 @@ dao_ack_callback(rpl_parent_t *p, int status) return; } /* here we need to handle failed DAO's and other stuff */ - PRINTF("RPL: OF0 - DAO ACK received with status: %d\n", status); + LOG_DBG("OF0 - DAO ACK received with status: %d\n", status); if(status >= RPL_DAO_ACK_UNABLE_TO_ACCEPT) { /* punish the ETX as if this was 10 packets lost */ link_stats_packet_sent(rpl_get_parent_lladdr(p), MAC_TX_OK, 10); diff --git a/os/net/routing/rpl-classic/rpl-private.h b/os/net/routing/rpl-classic/rpl-private.h index 1259fffeb..5a01c538a 100644 --- a/os/net/routing/rpl-classic/rpl-private.h +++ b/os/net/routing/rpl-classic/rpl-private.h @@ -341,6 +341,7 @@ void rpl_schedule_dao_immediately(rpl_instance_t *); void rpl_schedule_unicast_dio_immediately(rpl_instance_t *instance); void rpl_cancel_dao(rpl_instance_t *instance); void rpl_schedule_probing(rpl_instance_t *instance); +void rpl_schedule_probing_now(rpl_instance_t *instance); void rpl_reset_dio_timer(rpl_instance_t *); void rpl_reset_periodic_timer(void); diff --git a/os/net/routing/rpl-classic/rpl-timers.c b/os/net/routing/rpl-classic/rpl-timers.c index c812a8897..0bcfc57dd 100644 --- a/os/net/routing/rpl-classic/rpl-timers.c +++ b/os/net/routing/rpl-classic/rpl-timers.c @@ -48,9 +48,10 @@ #include "net/ipv6/uip-sr.h" #include "lib/random.h" #include "sys/ctimer.h" +#include "sys/log.h" -#define DEBUG DEBUG_NONE -#include "net/ipv6/uip-debug.h" +#define LOG_MODULE "RPL" +#define LOG_LEVEL LOG_LEVEL_RPL /* A configurable function called after update of the RPL DIO interval */ #ifdef RPL_CALLBACK_NEW_DIO_INTERVAL @@ -133,7 +134,7 @@ new_dio_interval(rpl_instance_t *instance) /* keep some stats */ instance->dio_totint++; instance->dio_totrecv += instance->dio_counter; - ANNOTATE("#A rank=%u.%u(%u),stats=%d %d %d %d,color=%s\n", + LOG_ANNOTATE("#A rank=%u.%u(%u),stats=%d %d %d %d,color=%s\n", DAG_RANK(instance->current_dag->rank, instance), (10 * (instance->current_dag->rank % instance->min_hoprankinc)) / instance->min_hoprankinc, instance->current_dag->version, @@ -146,7 +147,7 @@ new_dio_interval(rpl_instance_t *instance) instance->dio_counter = 0; /* schedule the timer */ - PRINTF("RPL: Scheduling DIO timer %lu ticks in future (Interval)\n", ticks); + LOG_INFO("Scheduling DIO timer %lu ticks in future (Interval)\n", ticks); ctimer_set(&instance->dio_timer, ticks, &handle_dio_timer, instance); #ifdef RPL_CALLBACK_NEW_DIO_INTERVAL @@ -161,12 +162,12 @@ handle_dio_timer(void *ptr) instance = (rpl_instance_t *)ptr; - PRINTF("RPL: DIO Timer triggered\n"); + LOG_DBG("DIO Timer triggered\n"); if(!dio_send_ok) { if(uip_ds6_get_link_local(ADDR_PREFERRED) != NULL) { dio_send_ok = 1; } else { - PRINTF("RPL: Postponing DIO transmission since link local address is not ok\n"); + LOG_WARN("Postponing DIO transmission since link local address is not ok\n"); ctimer_set(&instance->dio_timer, CLOCK_SECOND, &handle_dio_timer, instance); return; } @@ -180,25 +181,25 @@ handle_dio_timer(void *ptr) #endif /* RPL_CONF_STATS */ dio_output(instance, NULL); } else { - PRINTF("RPL: Suppressing DIO transmission (%d >= %d)\n", + LOG_DBG("Suppressing DIO transmission (%d >= %d)\n", instance->dio_counter, instance->dio_redundancy); } instance->dio_send = 0; - PRINTF("RPL: Scheduling DIO timer %lu ticks in future (sent)\n", + LOG_DBG("Scheduling DIO timer %lu ticks in future (sent)\n", instance->dio_next_delay); ctimer_set(&instance->dio_timer, instance->dio_next_delay, handle_dio_timer, instance); } else { /* check if we need to double interval */ if(instance->dio_intcurrent < instance->dio_intmin + instance->dio_intdoubl) { instance->dio_intcurrent++; - PRINTF("RPL: DIO Timer interval doubled %d\n", instance->dio_intcurrent); + LOG_DBG("DIO Timer interval doubled %d\n", instance->dio_intcurrent); } new_dio_interval(instance); } -#if DEBUG - rpl_print_neighbor_list(); -#endif + if(LOG_DBG_ENABLED) { + rpl_print_neighbor_list(); + } } /*---------------------------------------------------------------------------*/ void @@ -245,7 +246,7 @@ set_dao_lifetime_timer(rpl_instance_t *instance) CLOCK_SECOND / 2; /* make the time for the re registration be betwen 1/2 - 3/4 of lifetime */ expiration_time = expiration_time + (random_rand() % (expiration_time / 2)); - PRINTF("RPL: Scheduling DAO lifetime timer %u ticks in the future\n", + LOG_DBG("Scheduling DAO lifetime timer %u ticks in the future\n", (unsigned)expiration_time); ctimer_set(&instance->dao_lifetime_timer, expiration_time, handle_dao_timer, instance); @@ -264,14 +265,14 @@ handle_dao_timer(void *ptr) instance = (rpl_instance_t *)ptr; if(!dio_send_ok && uip_ds6_get_link_local(ADDR_PREFERRED) == NULL) { - PRINTF("RPL: Postpone DAO transmission\n"); + LOG_INFO("Postpone DAO transmission\n"); ctimer_set(&instance->dao_timer, CLOCK_SECOND, handle_dao_timer, instance); return; } /* Send the DAO to the DAO parent set -- the preferred parent in our case. */ if(instance->current_dag->preferred_parent != NULL) { - PRINTF("RPL: handle_dao_timer - sending DAO\n"); + LOG_INFO("handle_dao_timer - sending DAO\n"); /* Set the route lifetime to the default value. */ dao_output(instance->current_dag->preferred_parent, instance->default_lifetime); @@ -300,7 +301,7 @@ handle_dao_timer(void *ptr) } #endif } else { - PRINTF("RPL: No suitable DAO parent\n"); + LOG_INFO("No suitable DAO parent\n"); } ctimer_stop(&instance->dao_timer); @@ -322,7 +323,7 @@ schedule_dao(rpl_instance_t *instance, clock_time_t latency) expiration_time = etimer_expiration_time(&instance->dao_timer.etimer); if(!etimer_expired(&instance->dao_timer.etimer)) { - PRINTF("RPL: DAO timer already scheduled\n"); + LOG_DBG("DAO timer already scheduled\n"); } else { if(latency != 0) { expiration_time = latency / 2 + @@ -330,7 +331,7 @@ schedule_dao(rpl_instance_t *instance, clock_time_t latency) } else { expiration_time = 0; } - PRINTF("RPL: Scheduling DAO timer %u ticks in the future\n", + LOG_DBG("Scheduling DAO timer %u ticks in the future\n", (unsigned)expiration_time); ctimer_set(&instance->dao_timer, expiration_time, handle_dao_timer, instance); @@ -380,14 +381,7 @@ rpl_schedule_unicast_dio_immediately(rpl_instance_t *instance) clock_time_t get_probing_delay(rpl_dag_t *dag) { - if(dag != NULL && dag->instance != NULL - && dag->instance->urgent_probing_target != NULL) { - /* Urgent probing needed (to find out if a neighbor may become preferred parent) */ - return random_rand() % (CLOCK_SECOND * 10); - } else { - /* Else, use normal probing interval */ - return ((RPL_PROBING_INTERVAL) / 2) + random_rand() % (RPL_PROBING_INTERVAL); - } + return ((RPL_PROBING_INTERVAL) / 2) + random_rand() % (RPL_PROBING_INTERVAL); } /*---------------------------------------------------------------------------*/ rpl_parent_t * @@ -486,7 +480,7 @@ handle_probing_timer(void *ptr) if(target_ipaddr != NULL) { const struct link_stats *stats = rpl_get_parent_link_stats(probing_target); (void)stats; - PRINTF("RPL: probing %u %s last tx %u min ago\n", + LOG_INFO("probing %u %s last tx %u min ago\n", rpl_get_parent_lladdr(probing_target)->u8[7], instance->urgent_probing_target != NULL ? "(urgent)" : "", probing_target != NULL ? @@ -494,15 +488,14 @@ handle_probing_timer(void *ptr) ); /* Send probe, e.g. unicast DIO or DIS */ RPL_PROBING_SEND_FUNC(instance, target_ipaddr); - instance->urgent_probing_target = NULL; } /* Schedule next probing */ rpl_schedule_probing(instance); -#if DEBUG - rpl_print_neighbor_list(); -#endif + if(LOG_DBG_ENABLED) { + rpl_print_neighbor_list(); + } } /*---------------------------------------------------------------------------*/ void @@ -511,5 +504,12 @@ rpl_schedule_probing(rpl_instance_t *instance) ctimer_set(&instance->probing_timer, RPL_PROBING_DELAY_FUNC(instance->current_dag), handle_probing_timer, instance); } +/*---------------------------------------------------------------------------*/ +void +rpl_schedule_probing_now(rpl_instance_t *instance) +{ + ctimer_set(&instance->probing_timer, random_rand() % (CLOCK_SECOND * 4), + handle_probing_timer, instance); +} #endif /* RPL_WITH_PROBING */ /** @}*/ diff --git a/os/net/routing/rpl-classic/rpl.c b/os/net/routing/rpl-classic/rpl.c index b1905d611..1778329b9 100644 --- a/os/net/routing/rpl-classic/rpl.c +++ b/os/net/routing/rpl-classic/rpl.c @@ -52,12 +52,14 @@ #include "net/routing/rpl-classic/rpl-dag-root.h" #include "net/ipv6/multicast/uip-mcast6.h" -#define DEBUG DEBUG_NONE -#include "net/ipv6/uip-debug.h" +#include "sys/log.h" #include #include +#define LOG_MODULE "RPL" +#define LOG_LEVEL LOG_LEVEL_RPL + #if RPL_CONF_STATS rpl_stats_t rpl_stats; #endif @@ -83,7 +85,7 @@ rpl_set_mode(enum rpl_mode m) inform our parent that we now are reachable. Before we do this, we must set the mode variable, since DAOs will not be sent if we are in feather mode. */ - PRINTF("RPL: switching to mesh mode\n"); + LOG_DBG("rpl_set_mode: switching to mesh mode\n"); mode = m; if(default_instance != NULL) { @@ -91,15 +93,15 @@ rpl_set_mode(enum rpl_mode m) } } else if(m == RPL_MODE_FEATHER) { - PRINTF("RPL: switching to feather mode\n"); + LOG_INFO("rpl_set_mode: switching to feather mode\n"); if(default_instance != NULL) { - PRINTF("rpl_set_mode: RPL sending DAO with zero lifetime\n"); + LOG_INFO("rpl_set_mode: RPL sending DAO with zero lifetime\n"); if(default_instance->current_dag != NULL) { dao_output(default_instance->current_dag->preferred_parent, RPL_ZERO_LIFETIME); } rpl_cancel_dao(default_instance); } else { - PRINTF("rpl_set_mode: no default instance\n"); + LOG_INFO("rpl_set_mode: no default instance\n"); } mode = m; @@ -145,17 +147,17 @@ rpl_purge_routes(void) uip_ipaddr_copy(&prefix, &r->ipaddr); uip_ds6_route_rm(r); r = uip_ds6_route_head(); - PRINTF("No more routes to "); - PRINT6ADDR(&prefix); + LOG_INFO("No more routes to "); + LOG_INFO_6ADDR(&prefix); dag = default_instance->current_dag; /* Propagate this information with a No-Path DAO to preferred parent if we are not a RPL Root */ if(dag->rank != ROOT_RANK(default_instance)) { - PRINTF(" -> generate No-Path DAO\n"); + LOG_INFO_(" -> generate No-Path DAO\n"); dao_output_target(dag->preferred_parent, &prefix, RPL_ZERO_LIFETIME); /* Don't schedule more than 1 No-Path DAO, let next iteration handle that */ return; } - PRINTF("\n"); + LOG_INFO_("\n"); } else { r = uip_ds6_route_next(r); } @@ -223,7 +225,7 @@ rpl_remove_routes_by_nexthop(uip_ipaddr_t *nexthop, rpl_dag_t *dag) } r = uip_ds6_route_next(r); } - ANNOTATE("#L %u 0\n", nexthop->u8[sizeof(uip_ipaddr_t) - 1]); + LOG_ANNOTATE("#L %u 0\n", nexthop->u8[sizeof(uip_ipaddr_t) - 1]); } /*---------------------------------------------------------------------------*/ uip_ds6_route_t * @@ -233,7 +235,7 @@ rpl_add_route(rpl_dag_t *dag, uip_ipaddr_t *prefix, int prefix_len, uip_ds6_route_t *rep; if((rep = uip_ds6_route_add(prefix, prefix_len, next_hop)) == NULL) { - PRINTF("RPL: No space for more route entries\n"); + LOG_ERR("No space for more route entries\n"); return NULL; } @@ -242,11 +244,11 @@ rpl_add_route(rpl_dag_t *dag, uip_ipaddr_t *prefix, int prefix_len, /* always clear state flags for the no-path received when adding/refreshing */ RPL_ROUTE_CLEAR_NOPATH_RECEIVED(rep); - PRINTF("RPL: Added a route to "); - PRINT6ADDR(prefix); - PRINTF("/%d via ", prefix_len); - PRINT6ADDR(next_hop); - PRINTF("\n"); + LOG_INFO("Added a route to "); + LOG_INFO_6ADDR(prefix); + LOG_INFO_("/%d via ", prefix_len); + LOG_INFO_6ADDR(next_hop); + LOG_INFO_("\n"); return rep; } @@ -266,8 +268,15 @@ rpl_link_callback(const linkaddr_t *addr, int status, int numtx) if(instance->used == 1 ) { parent = rpl_find_parent_any_dag(instance, &ipaddr); if(parent != NULL) { + /* If this is the neighbor we were probing urgently, mark urgent + probing as done */ +#if RPL_WITH_PROBING + if(instance->urgent_probing_target == parent) { + instance->urgent_probing_target = NULL; + } +#endif /* RPL_WITH_PROBING */ /* Trigger DAG rank recalculation. */ - PRINTF("RPL: rpl_link_callback triggering update\n"); + LOG_DBG("rpl_link_callback triggering update\n"); parent->flags |= RPL_PARENT_FLAG_UPDATED; } } @@ -281,12 +290,12 @@ rpl_ipv6_neighbor_callback(uip_ds6_nbr_t *nbr) rpl_instance_t *instance; rpl_instance_t *end; - PRINTF("RPL: Neighbor state changed for "); - PRINT6ADDR(&nbr->ipaddr); + LOG_DBG("Neighbor state changed for "); + LOG_DBG_6ADDR(&nbr->ipaddr); #if UIP_ND6_SEND_NS || UIP_ND6_SEND_RA - PRINTF(", nscount=%u, state=%u\n", nbr->nscount, nbr->state); + LOG_DBG_(", nscount=%u, state=%u\n", nbr->nscount, nbr->state); #else /* UIP_ND6_SEND_NS || UIP_ND6_SEND_RA */ - PRINTF(", state=%u\n", nbr->state); + LOG_DBG_(", state=%u\n", nbr->state); #endif /* UIP_ND6_SEND_NS || UIP_ND6_SEND_RA */ for(instance = &instance_table[0], end = instance + RPL_MAX_INSTANCES; instance < end; ++instance) { if(instance->used == 1 ) { @@ -294,7 +303,7 @@ rpl_ipv6_neighbor_callback(uip_ds6_nbr_t *nbr) if(p != NULL) { p->rank = RPL_INFINITE_RANK; /* Trigger DAG rank recalculation. */ - PRINTF("RPL: rpl_ipv6_neighbor_callback infinite rank\n"); + LOG_DBG("rpl_ipv6_neighbor_callback infinite rank\n"); p->flags |= RPL_PARENT_FLAG_UPDATED; } } @@ -315,9 +324,9 @@ rpl_purge_dags(void) if(instance->dag_table[i].used) { if(instance->dag_table[i].lifetime == 0) { if(!instance->dag_table[i].joined) { - PRINTF("Removing dag "); - PRINT6ADDR(&instance->dag_table[i].dag_id); - PRINTF("\n"); + LOG_INFO("Removing dag "); + LOG_INFO_6ADDR(&instance->dag_table[i].dag_id); + LOG_INFO_("\n"); rpl_free_dag(&instance->dag_table[i]); } } else { @@ -333,7 +342,7 @@ static void init(void) { uip_ipaddr_t rplmaddr; - PRINTF("RPL started\n"); + LOG_INFO("rpl-classic started\n"); default_instance = NULL; rpl_dag_init(); @@ -398,7 +407,7 @@ drop_route(uip_ds6_route_t *route) static void leave_network(void) { - PRINTF("RPL: leave_network not supported in RPL Classic\n"); + LOG_ERR("leave_network not supported in RPL Classic\n"); } /*---------------------------------------------------------------------------*/ static int diff --git a/os/net/routing/rpl-lite/rpl-conf.h b/os/net/routing/rpl-lite/rpl-conf.h index a3693f8b9..5d674fa96 100644 --- a/os/net/routing/rpl-lite/rpl-conf.h +++ b/os/net/routing/rpl-lite/rpl-conf.h @@ -185,10 +185,17 @@ * This value decides if this node must stay as a leaf or not * as allowed by draft-ietf-roll-rpl-19#section-8.5 */ -#ifdef RPL_CONF_LEAF_ONLY -#define RPL_LEAF_ONLY RPL_CONF_LEAF_ONLY +#ifdef RPL_CONF_DEFAULT_LEAF_ONLY +#define RPL_DEFAULT_LEAF_ONLY RPL_CONF_DEFAULT_LEAF_ONLY #else -#define RPL_LEAF_ONLY 0 +#define RPL_DEFAULT_LEAF_ONLY 0 +#endif + +/* + * Function used to validate dio before using it to init dag + */ +#ifdef RPL_CONF_VALIDATE_DIO_FUNC +#define RPL_VALIDATE_DIO_FUNC RPL_CONF_VALIDATE_DIO_FUNC #endif /******************************************************************************/ @@ -265,7 +272,7 @@ #ifdef RPL_CONF_DAG_LIFETIME #define RPL_DAG_LIFETIME RPL_CONF_DAG_LIFETIME #else -#define RPL_DAG_LIFETIME (60 * 60) /* one hour */ +#define RPL_DAG_LIFETIME (8 * 60) /* 8 hours */ #endif /* RPL_CONF_DAG_LIFETIME */ /* diff --git a/os/net/routing/rpl-lite/rpl-dag-root.c b/os/net/routing/rpl-lite/rpl-dag-root.c index 0d5cebe92..c3e356828 100644 --- a/os/net/routing/rpl-lite/rpl-dag-root.c +++ b/os/net/routing/rpl-lite/rpl-dag-root.c @@ -42,12 +42,35 @@ #include "net/routing/rpl-lite/rpl.h" #include "net/ipv6/uip-ds6-route.h" +#include "net/ipv6/uip-sr.h" /* Log configuration */ #include "sys/log.h" #define LOG_MODULE "RPL" #define LOG_LEVEL LOG_LEVEL_RPL +/*---------------------------------------------------------------------------*/ +void +rpl_dag_root_print_links(const char *str) +{ + if(rpl_dag_root_is_root()) { + if(uip_sr_num_nodes() > 0) { + uip_sr_node_t *link; + /* Our routing links */ + LOG_INFO("links: %u routing links in total (%s)\n", uip_sr_num_nodes(), str); + link = uip_sr_node_head(); + while(link != NULL) { + char buf[100]; + uip_sr_link_snprint(buf, sizeof(buf), link); + LOG_INFO("links: %s\n", buf); + link = uip_sr_node_next(link); + } + LOG_INFO("links: end of list\n"); + } else { + LOG_INFO("No routing links\n"); + } + } +} /*---------------------------------------------------------------------------*/ static void set_global_address(uip_ipaddr_t *prefix, uip_ipaddr_t *iid) @@ -71,11 +94,12 @@ set_global_address(uip_ipaddr_t *prefix, uip_ipaddr_t *iid) uip_ds6_addr_add(&root_ipaddr, 0, ADDR_AUTOCONF); - LOG_INFO("IPv6 addresses: "); + LOG_INFO("IPv6 addresses:\n"); for(i = 0; i < UIP_DS6_ADDR_NB; i++) { state = uip_ds6_if.addr_list[i].state; if(uip_ds6_if.addr_list[i].isused && (state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) { + LOG_INFO("-- "); LOG_INFO_6ADDR(&uip_ds6_if.addr_list[i].ipaddr); LOG_INFO_("\n"); } diff --git a/os/net/routing/rpl-lite/rpl-dag-root.h b/os/net/routing/rpl-lite/rpl-dag-root.h index af0048c4d..71b999765 100644 --- a/os/net/routing/rpl-lite/rpl-dag-root.h +++ b/os/net/routing/rpl-lite/rpl-dag-root.h @@ -63,6 +63,12 @@ int rpl_dag_root_start(void); * \return 1 if we are dag root, 0 otherwise */ int rpl_dag_root_is_root(void); +/** + * Prints a summary of all routing links + * + * \param str A descriptive text on the caller +*/ +void rpl_dag_root_print_links(const char *str); /** @} */ diff --git a/os/net/routing/rpl-lite/rpl-dag.c b/os/net/routing/rpl-lite/rpl-dag.c index 68d9e7aaa..09caa9625 100644 --- a/os/net/routing/rpl-lite/rpl-dag.c +++ b/os/net/routing/rpl-lite/rpl-dag.c @@ -61,6 +61,12 @@ static int init_dag_from_dio(rpl_dio_t *dio); /* Allocate instance table. */ rpl_instance_t curr_instance; +/*---------------------------------------------------------------------------*/ + +#ifdef RPL_VALIDATE_DIO_FUNC +int RPL_VALIDATE_DIO_FUNC(rpl_dio_t *dio); +#endif /* RPL_PROBING_SELECT_FUNC */ + /*---------------------------------------------------------------------------*/ const char * rpl_dag_state_to_str(enum rpl_dag_state state) @@ -542,6 +548,13 @@ init_dag_from_dio(rpl_dio_t *dio) static int process_dio_init_dag(uip_ipaddr_t *from, rpl_dio_t *dio) { +#ifdef RPL_VALIDATE_DIO_FUNC + if(!RPL_VALIDATE_DIO_FUNC(dio)) { + LOG_WARN("DIO validation failed\n"); + return 0; + } +#endif + /* Check MOP */ if(dio->mop != RPL_MOP_NO_DOWNWARD_ROUTES && dio->mop != RPL_MOP_NON_STORING) { LOG_WARN("ignoring DIO with an unsupported MOP: %d\n", dio->mop); diff --git a/os/net/routing/rpl-lite/rpl-icmp6.c b/os/net/routing/rpl-lite/rpl-icmp6.c index 1e4a50423..be5ea2948 100644 --- a/os/net/routing/rpl-lite/rpl-icmp6.c +++ b/os/net/routing/rpl-lite/rpl-icmp6.c @@ -342,14 +342,14 @@ rpl_icmp6_dio_output(uip_ipaddr_t *uc_addr) /* Make sure we're up-to-date before sending data out */ rpl_dag_update_state(); -#if RPL_LEAF_ONLY - /* In leaf mode, we only send DIO messages as unicasts in response to - unicast DIS messages. */ - if(uc_addr == NULL) { - /* Do not send multicast DIO in leaf mode */ - return; + if(rpl_get_leaf_only()) { + /* In leaf mode, we only send DIO messages as unicasts in response to + unicast DIS messages. */ + if(uc_addr == NULL) { + /* Do not send multicast DIO in leaf mode */ + return; + } } -#endif /* RPL_LEAF_ONLY */ /* DAG Information Object */ pos = 0; @@ -358,11 +358,11 @@ rpl_icmp6_dio_output(uip_ipaddr_t *uc_addr) buffer[pos++] = curr_instance.instance_id; buffer[pos++] = curr_instance.dag.version; -#if RPL_LEAF_ONLY - set16(buffer, pos, RPL_INFINITE_RANK); -#else /* RPL_LEAF_ONLY */ - set16(buffer, pos, curr_instance.dag.rank); -#endif /* RPL_LEAF_ONLY */ + if(rpl_get_leaf_only()) { + set16(buffer, pos, RPL_INFINITE_RANK); + } else { + set16(buffer, pos, curr_instance.dag.rank); + } pos += 2; buffer[pos] = 0; @@ -383,29 +383,29 @@ rpl_icmp6_dio_output(uip_ipaddr_t *uc_addr) memcpy(buffer + pos, &curr_instance.dag.dag_id, sizeof(curr_instance.dag.dag_id)); pos += 16; -#if !RPL_LEAF_ONLY - if(curr_instance.mc.type != RPL_DAG_MC_NONE) { - buffer[pos++] = RPL_OPTION_DAG_METRIC_CONTAINER; - buffer[pos++] = 6; - buffer[pos++] = curr_instance.mc.type; - buffer[pos++] = curr_instance.mc.flags >> 1; - buffer[pos] = (curr_instance.mc.flags & 1) << 7; - buffer[pos++] |= (curr_instance.mc.aggr << 4) | curr_instance.mc.prec; - if(curr_instance.mc.type == RPL_DAG_MC_ETX) { - buffer[pos++] = 2; - set16(buffer, pos, curr_instance.mc.obj.etx); - pos += 2; - } else if(curr_instance.mc.type == RPL_DAG_MC_ENERGY) { - buffer[pos++] = 2; - buffer[pos++] = curr_instance.mc.obj.energy.flags; - buffer[pos++] = curr_instance.mc.obj.energy.energy_est; - } else { - LOG_ERR("unable to send DIO because of unsupported DAG MC type %u\n", - (unsigned)curr_instance.mc.type); - return; + if(!rpl_get_leaf_only()) { + if(curr_instance.mc.type != RPL_DAG_MC_NONE) { + buffer[pos++] = RPL_OPTION_DAG_METRIC_CONTAINER; + buffer[pos++] = 6; + buffer[pos++] = curr_instance.mc.type; + buffer[pos++] = curr_instance.mc.flags >> 1; + buffer[pos] = (curr_instance.mc.flags & 1) << 7; + buffer[pos++] |= (curr_instance.mc.aggr << 4) | curr_instance.mc.prec; + if(curr_instance.mc.type == RPL_DAG_MC_ETX) { + buffer[pos++] = 2; + set16(buffer, pos, curr_instance.mc.obj.etx); + pos += 2; + } else if(curr_instance.mc.type == RPL_DAG_MC_ENERGY) { + buffer[pos++] = 2; + buffer[pos++] = curr_instance.mc.obj.energy.flags; + buffer[pos++] = curr_instance.mc.obj.energy.energy_est; + } else { + LOG_ERR("unable to send DIO because of unsupported DAG MC type %u\n", + (unsigned)curr_instance.mc.type); + return; + } } } -#endif /* !RPL_LEAF_ONLY */ /* Always add a DAG configuration option. */ buffer[pos++] = RPL_OPTION_DAG_CONF; @@ -442,9 +442,9 @@ rpl_icmp6_dio_output(uip_ipaddr_t *uc_addr) pos += 16; } -#if !RPL_LEAF_ONLY - addr = addr != NULL ? addr : &rpl_multicast_addr; -#endif /* RPL_LEAF_ONLY */ + if(!rpl_get_leaf_only()) { + addr = addr != NULL ? addr : &rpl_multicast_addr; + } LOG_INFO("sending a %s-DIO with rank %u to ", uc_addr != NULL ? "unicast" : "multicast", diff --git a/os/net/routing/rpl-lite/rpl-mrhof.c b/os/net/routing/rpl-lite/rpl-mrhof.c index 5504f4fda..79c06d496 100644 --- a/os/net/routing/rpl-lite/rpl-mrhof.c +++ b/os/net/routing/rpl-lite/rpl-mrhof.c @@ -77,10 +77,18 @@ /* Configuration parameters of RFC6719. Reject parents that have a higher * link metric than the following. The default value is 512. */ +#ifdef RPL_MRHOF_CONF_MAX_LINK_METRIC +#define MAX_LINK_METRIC RPL_MRHOF_CONF_MAX_LINK_METRIC +#else /* RPL_MRHOF_CONF_MAX_LINK_METRIC */ #define MAX_LINK_METRIC 512 /* Eq ETX of 4 */ +#endif /* RPL_MRHOF_CONF_MAX_LINK_METRIC */ /* Reject parents that have a higher path cost than the following. */ +#ifdef RPL_MRHOF_CONF_MAX_PATH_COST +#define MAX_PATH_COST RPL_MRHOF_CONF_MAX_PATH_COST +#else /* RPL_MRHOF_CONF_MAX_PATH_COST */ #define MAX_PATH_COST 32768 /* Eq path ETX of 256 */ +#endif /* RPL_MRHOF_CONF_MAX_PATH_COST */ #if !RPL_MRHOF_SQUARED_ETX /* Hysteresis of MRHOF: the rank must differ more than PARENT_SWITCH_THRESHOLD_DIV diff --git a/os/net/routing/rpl-lite/rpl-nbr-policy.c b/os/net/routing/rpl-lite/rpl-nbr-policy.c index 3db84f3a8..9752b1446 100644 --- a/os/net/routing/rpl-lite/rpl-nbr-policy.c +++ b/os/net/routing/rpl-lite/rpl-nbr-policy.c @@ -104,7 +104,7 @@ update_state(void) /* how many more IP neighbors can be have? */ num_free = NBR_TABLE_MAX_NEIGHBORS - num_used; - LOG_INFO("nbr-policy: free: %d, parents: %d\n", num_free, num_parents); + LOG_DBG("nbr-policy: free: %d, parents: %d\n", num_free, num_parents); } /*---------------------------------------------------------------------------*/ static const linkaddr_t * @@ -127,12 +127,12 @@ find_removable_dio(uip_ipaddr_t *from, rpl_dio_t *dio) /* Add the new neighbor only if it is better than the current worst. */ if(dio->rank + curr_instance.min_hoprankinc < worst_rank - curr_instance.min_hoprankinc / 2) { /* Found *great* neighbor - add! */ - LOG_INFO("nbr-policy: DIO rank %u, worse_rank %u -- add to cache\n", + LOG_DBG("nbr-policy: DIO rank %u, worst_rank %u -- add to cache\n", dio->rank, worst_rank); return worst_rank_nbr_lladdr; } - LOG_INFO("nbr-policy: DIO rank %u, worse_rank %u -- do not add to cache\n", + LOG_DBG("nbr-policy: DIO rank %u, worst_rank %u -- do not add to cache\n", dio->rank, worst_rank); return NULL; } diff --git a/os/net/routing/rpl-lite/rpl-neighbor.c b/os/net/routing/rpl-lite/rpl-neighbor.c index 8afa2440f..a0f5d95b0 100644 --- a/os/net/routing/rpl-lite/rpl-neighbor.c +++ b/os/net/routing/rpl-lite/rpl-neighbor.c @@ -46,6 +46,7 @@ #include "net/routing/rpl-lite/rpl.h" #include "net/link-stats.h" #include "net/nbr-table.h" +#include "net/ipv6/uiplib.h" /* Log configuration */ #include "sys/log.h" @@ -85,6 +86,59 @@ acceptable_rank(rpl_rank_t rank) && rank <= max_acceptable_rank(); } /*---------------------------------------------------------------------------*/ +int +rpl_neighbor_snprint(char *buf, int buflen, rpl_nbr_t *nbr) +{ + int index = 0; + rpl_nbr_t *best = best_parent(0); + const struct link_stats *stats = rpl_neighbor_get_link_stats(nbr); + clock_time_t clock_now = clock_time(); + + if(LOG_WITH_COMPACT_ADDR) { + index += log_6addr_compact_snprint(buf+index, buflen-index, rpl_neighbor_get_ipaddr(nbr)); + } else { + index += uiplib_ipaddr_snprint(buf+index, buflen-index, rpl_neighbor_get_ipaddr(nbr)); + } + if(index >= buflen) { + return index; + } + index += snprintf(buf+index, buflen-index, + "%5u, %5u => %5u -- %2u %c%c%c%c%c", + nbr->rank, + rpl_neighbor_get_link_metric(nbr), + rpl_neighbor_rank_via_nbr(nbr), + stats != NULL ? stats->freshness : 0, + (nbr->rank == ROOT_RANK) ? 'r' : ' ', + nbr == best ? 'b' : ' ', + (acceptable_rank(rpl_neighbor_rank_via_nbr(nbr)) && rpl_neighbor_is_acceptable_parent(nbr)) ? 'a' : ' ', + link_stats_is_fresh(stats) ? 'f' : ' ', + nbr == curr_instance.dag.preferred_parent ? 'p' : ' ' + ); + if(index >= buflen) { + return index; + } + if(stats->last_tx_time > 0) { + index += snprintf(buf+index, buflen-index, + " (last tx %u min ago", + (unsigned)((clock_now - stats->last_tx_time) / (60 * CLOCK_SECOND))); + } else { + index += snprintf(buf+index, buflen-index, + " (no tx"); + } + if(index >= buflen) { + return index; + } + if(nbr->better_parent_since > 0) { + index += snprintf(buf+index, buflen-index, + ", better since %u min)", + (unsigned)((clock_now - nbr->better_parent_since) / (60 * CLOCK_SECOND))); + } else { + index += snprintf(buf+index, buflen-index, + ")"); + } + return index; +} +/*---------------------------------------------------------------------------*/ void rpl_neighbor_print_list(const char *str) { @@ -92,8 +146,6 @@ rpl_neighbor_print_list(const char *str) int curr_dio_interval = curr_instance.dag.dio_intcurrent; int curr_rank = curr_instance.dag.rank; rpl_nbr_t *nbr = nbr_table_head(rpl_neighbors); - rpl_nbr_t *best = best_parent(0); - clock_time_t clock_now = clock_time(); LOG_INFO("nbr: own state, addr "); LOG_INFO_6ADDR(rpl_get_global_address()); @@ -103,30 +155,9 @@ rpl_neighbor_print_list(const char *str) max_acceptable_rank(), curr_dio_interval, rpl_neighbor_count(), str); while(nbr != NULL) { - const struct link_stats *stats = rpl_neighbor_get_link_stats(nbr); - LOG_INFO("nbr: "); - LOG_INFO_6ADDR(rpl_neighbor_get_ipaddr(nbr)); - LOG_INFO_(" %5u, %5u => %5u -- %2u %c%c%c%c%c", - nbr->rank, - rpl_neighbor_get_link_metric(nbr), - rpl_neighbor_rank_via_nbr(nbr), - stats != NULL ? stats->freshness : 0, - (nbr->rank == ROOT_RANK) ? 'r' : ' ', - nbr == best ? 'b' : ' ', - (acceptable_rank(rpl_neighbor_rank_via_nbr(nbr)) && rpl_neighbor_is_acceptable_parent(nbr)) ? 'a' : ' ', - link_stats_is_fresh(stats) ? 'f' : ' ', - nbr == curr_instance.dag.preferred_parent ? 'p' : ' ' - ); - if(stats->last_tx_time > 0) { - LOG_INFO_(" (last tx %u min ago", (unsigned)((clock_now - stats->last_tx_time) / (60 * CLOCK_SECOND))); - } else { - LOG_INFO_(" (no tx"); - } - if(nbr->better_parent_since > 0) { - LOG_INFO_(", better since %u min)\n", (unsigned)((clock_now - nbr->better_parent_since) / (60 * CLOCK_SECOND))); - } else { - LOG_INFO_(")\n"); - } + char buf[120]; + rpl_neighbor_snprint(buf, sizeof(buf), nbr); + LOG_INFO("nbr: %s\n", buf); nbr = nbr_table_next(rpl_neighbors, nbr); } LOG_INFO("nbr: end of list\n"); @@ -368,6 +399,8 @@ rpl_neighbor_select_best(void) #if RPL_WITH_PROBING if(best != NULL) { if(rpl_neighbor_is_fresh(best)) { + /* Unschedule any already scheduled urgent probing */ + curr_instance.dag.urgent_probing_target = NULL; /* Return best if it is fresh */ return best; } else { @@ -376,11 +409,11 @@ rpl_neighbor_select_best(void) /* The best is not fresh. Probe it (unless there is already an urgent probing target). We will be called back after the probing anyway. */ if(curr_instance.dag.urgent_probing_target == NULL) { - LOG_WARN("best parent is not fresh, schedule urgent probing to "); - LOG_WARN_6ADDR(rpl_neighbor_get_ipaddr(best)); - LOG_WARN_("\n"); + LOG_INFO("best parent is not fresh, schedule urgent probing to "); + LOG_INFO_6ADDR(rpl_neighbor_get_ipaddr(best)); + LOG_INFO_("\n"); curr_instance.dag.urgent_probing_target = best; - rpl_schedule_probing(); + rpl_schedule_probing_now(); } /* The best is our preferred parent. It is not fresh but used to be, diff --git a/os/net/routing/rpl-lite/rpl-neighbor.h b/os/net/routing/rpl-lite/rpl-neighbor.h index 028d089c7..31ed02cd2 100644 --- a/os/net/routing/rpl-lite/rpl-neighbor.h +++ b/os/net/routing/rpl-lite/rpl-neighbor.h @@ -192,6 +192,17 @@ void rpl_neighbor_remove_all(void); */ rpl_nbr_t *rpl_neighbor_select_best(void); +/** +* Print a textual description of RPL neighbor into a string +* +* \param buf The buffer where to write content +* \param buflen The buffer len +* \param nbr A pointer to a RPL neighbor that will be written to the buffer +* \return Identical to snprintf: number of bytes written excluding ending null +* byte. A value >= buflen if the buffer was too small. +*/ +int rpl_neighbor_snprint(char *buf, int buflen, rpl_nbr_t *nbr); + typedef rpl_nbr_t rpl_parent_t; #define rpl_parent_get_from_ipaddr(addr) rpl_neighbor_get_from_ipaddr(addr) #define rpl_parent_get_ipaddr(nbr) rpl_neighbor_get_ipaddr(nbr) diff --git a/os/net/routing/rpl-lite/rpl-timers.c b/os/net/routing/rpl-lite/rpl-timers.c index 6cd188f9d..c41b92948 100644 --- a/os/net/routing/rpl-lite/rpl-timers.c +++ b/os/net/routing/rpl-lite/rpl-timers.c @@ -150,11 +150,11 @@ rpl_timers_dio_reset(const char *str) { if(rpl_dag_ready_to_advertise()) { LOG_INFO("reset DIO timer (%s)\n", str); -#if !RPL_LEAF_ONLY - curr_instance.dag.dio_counter = 0; - curr_instance.dag.dio_intcurrent = curr_instance.dio_intmin; - new_dio_interval(); -#endif /* RPL_LEAF_ONLY */ + if(!rpl_get_leaf_only()) { + curr_instance.dag.dio_counter = 0; + curr_instance.dag.dio_intcurrent = curr_instance.dio_intmin; + new_dio_interval(); + } } } /*---------------------------------------------------------------------------*/ @@ -342,13 +342,7 @@ handle_dao_ack_timer(void *ptr) clock_time_t get_probing_delay(void) { - if(curr_instance.used && curr_instance.dag.urgent_probing_target != NULL) { - /* Urgent probing needed (to find out if a neighbor may become preferred parent) */ - return random_rand() % (CLOCK_SECOND * 4); - } else { - /* Else, use normal probing interval */ - return ((RPL_PROBING_INTERVAL) / 2) + random_rand() % (RPL_PROBING_INTERVAL); - } + return ((RPL_PROBING_INTERVAL) / 2) + random_rand() % (RPL_PROBING_INTERVAL); } /*---------------------------------------------------------------------------*/ rpl_nbr_t * @@ -440,7 +434,7 @@ handle_probing_timer(void *ptr) ); /* Send probe, e.g. unicast DIO or DIS */ RPL_PROBING_SEND_FUNC(target_ipaddr); - curr_instance.dag.urgent_probing_target = NULL; + /* urgent_probing_target will be NULLed in the packet_sent callback */ } else { LOG_INFO("no neighbor needs probing\n"); } @@ -457,6 +451,15 @@ rpl_schedule_probing(void) handle_probing_timer, NULL); } } +/*---------------------------------------------------------------------------*/ +void +rpl_schedule_probing_now(void) +{ + if(curr_instance.used) { + ctimer_set(&curr_instance.dag.probing_timer, + random_rand() % (CLOCK_SECOND * 4), handle_probing_timer, NULL); + } +} #endif /* RPL_WITH_PROBING */ /*---------------------------------------------------------------------------*/ /*------------------------------- Leaving-- -------------------------------- */ @@ -518,6 +521,7 @@ handle_periodic_timer(void *ptr) if(LOG_INFO_ENABLED) { rpl_neighbor_print_list("Periodic"); + rpl_dag_root_print_links("Periodic"); } ctimer_reset(&periodic_timer); diff --git a/os/net/routing/rpl-lite/rpl-timers.h b/os/net/routing/rpl-lite/rpl-timers.h index 884a55696..e153858fc 100644 --- a/os/net/routing/rpl-lite/rpl-timers.h +++ b/os/net/routing/rpl-lite/rpl-timers.h @@ -104,6 +104,11 @@ void rpl_timers_schedule_dao_ack(uip_ipaddr_t *target, uint16_t sequence); */ void rpl_schedule_probing(void); +/** + * Schedule probing within a few seconds +*/ +void rpl_schedule_probing_now(void); + /** * Schedule a state update ASAP. Useful to force an update from a context * where updating directly would be unsafe. diff --git a/os/net/routing/rpl-lite/rpl.c b/os/net/routing/rpl-lite/rpl.c index acfe94c37..47ffc5387 100644 --- a/os/net/routing/rpl-lite/rpl.c +++ b/os/net/routing/rpl-lite/rpl.c @@ -50,6 +50,7 @@ #define LOG_LEVEL LOG_LEVEL_RPL uip_ipaddr_t rpl_multicast_addr; +static uint8_t rpl_leaf_only = RPL_DEFAULT_LEAF_ONLY; /*---------------------------------------------------------------------------*/ int @@ -98,6 +99,11 @@ rpl_link_callback(const linkaddr_t *addr, int status, int numtx) if(curr_instance.used == 1 ) { rpl_nbr_t *nbr = rpl_neighbor_get_from_lladdr((uip_lladdr_t *)addr); if(nbr != NULL) { + /* If this is the neighbor we were probing urgently, mark urgent + probing as done */ + if(curr_instance.dag.urgent_probing_target == nbr) { + curr_instance.dag.urgent_probing_target = NULL; + } /* Link stats were updated, and we need to update our internal state. Updating from here is unsafe; postpone */ LOG_INFO("packet sent to "); @@ -223,6 +229,18 @@ drop_route(uip_ds6_route_t *route) /* Do nothing. RPL-lite only supports non-storing mode, i.e. no routes */ } /*---------------------------------------------------------------------------*/ +void +rpl_set_leaf_only(uint8_t value) +{ + rpl_leaf_only = value; +} +/*---------------------------------------------------------------------------*/ +uint8_t +rpl_get_leaf_only(void) +{ + return rpl_leaf_only; +} +/*---------------------------------------------------------------------------*/ const struct routing_driver rpl_lite_driver = { "RPL Lite", init, diff --git a/os/net/routing/rpl-lite/rpl.h b/os/net/routing/rpl-lite/rpl.h index 25ac3863e..e39c825c4 100644 --- a/os/net/routing/rpl-lite/rpl.h +++ b/os/net/routing/rpl-lite/rpl.h @@ -133,6 +133,20 @@ int rpl_lollipop_greater_than(int a, int b); */ void rpl_refresh_routes(const char *str); +/** + * Changes the value of the rpl_leaf_only flag, which determines if a node acts + * only as a leaf in the network + * + * \param value the value to set: 0-disable, 1-enable + */ +void rpl_set_leaf_only(uint8_t value); + +/** + * Get the value of the rpl_leaf_only flag + * + * \return The value of the rpl_leaf_only flag + */ +uint8_t rpl_get_leaf_only(void); /** @} */ #endif /* RPL_H */ diff --git a/os/net/security/tinydtls b/os/net/security/tinydtls index 5ec7ad129..53a0d97da 160000 --- a/os/net/security/tinydtls +++ b/os/net/security/tinydtls @@ -1 +1 @@ -Subproject commit 5ec7ad12984eebf22a7eb5d779f24945db4829e2 +Subproject commit 53a0d97da748a67093c49cb38744650c71d58c4d diff --git a/os/services/deployment/deployment.c b/os/services/deployment/deployment.c new file mode 100644 index 000000000..087d9766d --- /dev/null +++ b/os/services/deployment/deployment.c @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2018, RISE SICS. + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + */ + +/** +* \addtogroup deployment +* @{ +*/ + +/** + * \file + * Code managing id<->mac address<->IPv6 address mapping, and doing this + * for different deployment scenarios: Cooja, Nodes, Indriya or Twist testbeds + * + * \author Simon Duquennoy + */ + +#include "contiki.h" +#include "contiki-net.h" +#include "deployment.h" +#include "sys/node-id.h" +#include +#include + +/** + * \brief List of ID<->MAC mapping used for different deployments + */ +extern const struct id_mac DEPLOYMENT_MAPPING[]; +/** + * \brief The number of nodes in the deployment + */ +static int node_count = 0; + +/*---------------------------------------------------------------------------*/ +void +deployment_init(void) +{ + const struct id_mac *curr = DEPLOYMENT_MAPPING; + /* Initialize node_id */ + node_id = deployment_id_from_lladdr((const linkaddr_t *)&linkaddr_node_addr); + /* Count nodes */ + node_count = 0; + while(curr->id != 0) { + node_count++; + curr++; + } +} +/*---------------------------------------------------------------------------*/ +int +deployment_node_count(void) +{ + return node_count; +} +/*---------------------------------------------------------------------------*/ +uint16_t +deployment_id_from_lladdr(const linkaddr_t *lladdr) +{ + const struct id_mac *curr = DEPLOYMENT_MAPPING; + if(lladdr == NULL) { + return 0; + } + while(curr->id != 0) { + /* Assume network-wide unique 16-bit MAC addresses */ + if(linkaddr_cmp(lladdr, &curr->mac)) { + return curr->id; + } + curr++; + } + return 0; +} +/*---------------------------------------------------------------------------*/ +void +deployment_lladdr_from_id(linkaddr_t *lladdr, uint16_t id) +{ + const struct id_mac *curr = DEPLOYMENT_MAPPING; + if(id == 0 || lladdr == NULL) { + return; + } + while(curr->id != 0) { + if(curr->id == id) { + linkaddr_copy(lladdr, &curr->mac); + return; + } + curr++; + } +} +/*---------------------------------------------------------------------------*/ +uint16_t +deployment_id_from_iid(const uip_ipaddr_t *ipaddr) +{ + const linkaddr_t lladdr; + uip_ds6_set_lladdr_from_iid((uip_lladdr_t *)&lladdr, ipaddr); + return deployment_id_from_lladdr(&lladdr); +} +/*---------------------------------------------------------------------------*/ +void +deployment_iid_from_id(uip_ipaddr_t *ipaddr, uint16_t id) +{ + linkaddr_t lladdr; + deployment_lladdr_from_id(&lladdr, id); + uip_ds6_set_addr_iid(ipaddr, (uip_lladdr_t *)&lladdr); +} +/*---------------------------------------------------------------------------*/ +uint16_t +deployment_id_from_index(uint16_t index) +{ + if(index < deployment_node_count()) { + return DEPLOYMENT_MAPPING[index].id; + } else { + return 0; + } +} +/*---------------------------------------------------------------------------*/ + +/** @} */ diff --git a/os/services/deployment/deployment.h b/os/services/deployment/deployment.h new file mode 100644 index 000000000..29cd5214b --- /dev/null +++ b/os/services/deployment/deployment.h @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2018, RISE SICS. + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + */ + +/** +* \addtogroup deployment +* @{ +* +* \file + Per-deployment MAC <-> nodeid mapping +* \author Simon Duquennoy +* +*/ + +#ifndef DEPLOYMENT_H_ +#define DEPLOYMENT_H_ + +#include "contiki-conf.h" +#include "sys/node-id.h" +#include "net/ipv6/uip.h" +#include "net/linkaddr.h" + +/** + * \brief ID<->MAC address mapping structure + */ +struct id_mac { + uint16_t id; + linkaddr_t mac; +}; + +/** + * DEPLOYMENT_MAPPING: + * A table of struct id_mac that provides ID-MAC mapping for a deployment. + * Example with four nodes: + * In configuration file: + * \#define DEPLOYMENT_MAPPING custom_array + * In a .c file: + * const struct id_mac custom_array[] = { + { 1, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb6,0x14}}}, + { 2, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb1,0xe7}}}, + { 3, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb4,0x35}}}, + { 4, {{0x00,0x12,0x4b,0x00,0x06,0x0d,0xb1,0xcf}}}, + { 0, {{0}}} + }; + */ + +/** + * Initialize the deployment module + */ +void deployment_init(void); + +/** + * Get the number of nodes for the deployment (length of mapping table) + * + * \return The number of nodes in the deployment + */ +int deployment_node_count(void); + +/** + * Get node ID from a link-layer address, from the deployment mapping table + * + * \param lladdr The link-layer address to look up for + * \return Node ID from a corresponding link-layer address + */ +uint16_t deployment_id_from_lladdr(const linkaddr_t *lladdr); + +/** + * Get node link-layer address from a node ID, from the deployment mapping table + * + * \param lladdr A pointer where to write the link-layer address + * \param id The node ID to look up for + */ +void deployment_lladdr_from_id(linkaddr_t *lladdr, uint16_t id); + +/** + * Get node ID from the IID of an IPv6 address + * + * \param ipaddr The IPv6 (global or link-local) address that contains the IID + * \return Node ID from a corresponding IID + */ +uint16_t deployment_id_from_iid(const uip_ipaddr_t *ipaddr); + +/** + * Get IPv6 IID from node IDs + * + * \param ipaddr The IPv6 where to write the IID + * \param id The node ID + */ +void deployment_iid_from_id(uip_ipaddr_t *ipaddr, uint16_t id); + +/** + * Get node ID from index in mapping table + * + * \param index The index in the deployment mapping table + * \return Node ID at the corresponding index + */ +uint16_t deployment_id_from_index(uint16_t index); + +#endif /* DEPLOYMENT_H_ */ +/** @} */ diff --git a/os/services/deployment/module-macros.h b/os/services/deployment/module-macros.h new file mode 100644 index 000000000..ed2d639ef --- /dev/null +++ b/os/services/deployment/module-macros.h @@ -0,0 +1 @@ +#define BUILD_WITH_DEPLOYMENT 1 diff --git a/os/services/ip64/ip64-arp.c b/os/services/ip64/ip64-arp.c index 5f3cff29a..75197558d 100644 --- a/os/services/ip64/ip64-arp.c +++ b/os/services/ip64/ip64-arp.c @@ -94,7 +94,6 @@ struct arp_entry { static const struct ip64_eth_addr broadcast_ethaddr = {{0xff,0xff,0xff,0xff,0xff,0xff}}; -static const uint16_t broadcast_ipaddr[2] = {0xffff,0xffff}; static struct arp_entry arp_table[UIP_ARPTAB_SIZE]; diff --git a/os/services/ipso-objects/ipso-temperature.c b/os/services/ipso-objects/ipso-temperature.c index c27d8b6ba..db550a5c5 100644 --- a/os/services/ipso-objects/ipso-temperature.c +++ b/os/services/ipso-objects/ipso-temperature.c @@ -74,8 +74,8 @@ static lwm2m_status_t get_temp_value(const ipso_sensor_t *s, int32_t *value) { #ifdef IPSO_TEMPERATURE - if(IPSO_TEMPERATURE.read_value == NULL || - IPSO_TEMPERATURE.read_value(value) != 0) { + if(IPSO_TEMPERATURE.read_value != NULL && + IPSO_TEMPERATURE.read_value(value) == 0) { return LWM2M_STATUS_OK; } #endif /* IPSO_TEMPERATURE */ diff --git a/os/services/lwm2m/lwm2m-engine.c b/os/services/lwm2m/lwm2m-engine.c index 1dca95a44..1d6032bd2 100644 --- a/os/services/lwm2m/lwm2m-engine.c +++ b/os/services/lwm2m/lwm2m-engine.c @@ -39,6 +39,7 @@ * \author * Joakim Eriksson * Niclas Finne + * Carlos Gonzalo Peces */ #include "lwm2m-engine.h" @@ -56,7 +57,6 @@ #include #include #include - #ifndef LWM2M_ENGINE_CLIENT_ENDPOINT_NAME #include "net/ipv6/uip-ds6.h" #endif /* LWM2M_ENGINE_CLIENT_ENDPOINT_NAME */ @@ -68,9 +68,9 @@ #ifndef LWM2M_ENGINE_CLIENT_ENDPOINT_PREFIX #ifdef LWM2M_DEVICE_MODEL_NUMBER -#define LWM2M_ENGINE_CLIENT_ENDPOINT_PREFIX LWM2M_DEVICE_MODEL_NUMBER +#define LWM2M_ENGINE_CLIENT_ENDPOINT_PREFIX "Contiki-NG-"LWM2M_DEVICE_MODEL_NUMBER #else /* LWM2M_DEVICE_MODEL_NUMBER */ -#define LWM2M_ENGINE_CLIENT_ENDPOINT_PREFIX "Contiki-" +#define LWM2M_ENGINE_CLIENT_ENDPOINT_PREFIX "Contiki-NG" #endif /* LWM2M_DEVICE_MODEL_NUMBER */ #endif /* LWM2M_ENGINE_CLIENT_ENDPOINT_PREFIX */ @@ -80,10 +80,24 @@ #define USE_RD_CLIENT 1 #endif /* LWM2M_ENGINE_CONF_USE_RD_CLIENT */ + +#if LWM2M_QUEUE_MODE_ENABLED + /* Queue Mode is handled using the RD Client and the Q-Mode object */ +#define USE_RD_CLIENT 1 +#endif + #if USE_RD_CLIENT #include "lwm2m-rd-client.h" #endif +#if LWM2M_QUEUE_MODE_ENABLED +#include "lwm2m-queue-mode.h" +#include "lwm2m-notification-queue.h" +#if LWM2M_QUEUE_MODE_OBJECT_ENABLED +#include "lwm2m-queue-mode-object.h" +#endif /* LWM2M_QUEUE_MODE_OBJECT_ENABLED */ +#endif /* LWM2M_QUEUE_MODE_ENABLED */ + /* MACRO for getting out resource ID from resource array ID + flags */ #define RSC_ID(x) ((uint16_t)(x & 0xffff)) #define RSC_READABLE(x) ((x & LWM2M_RESOURCE_READ) > 0) @@ -129,7 +143,6 @@ static struct { /* in the future also a timeout */ } created; - COAP_HANDLER(lwm2m_handler, lwm2m_handler_callback); LIST(object_list); LIST(generic_object_list); @@ -543,6 +556,9 @@ lwm2m_engine_init(void) #endif /* LWM2M_ENGINE_CLIENT_ENDPOINT_NAME */ + /* Initialize CoAP engine. Contiki-NG already does that from the main, + * but for standalone use of lwm2m, this is required here. coap_engine_init() + * checks for double-initialization and can be called twice safely. */ coap_engine_init(); /* Register the CoAP handler for lightweight object handling */ @@ -551,6 +567,10 @@ lwm2m_engine_init(void) #if USE_RD_CLIENT lwm2m_rd_client_init(endpoint); #endif + +#if LWM2M_QUEUE_MODE_ENABLED && LWM2M_QUEUE_MODE_OBJECT_ENABLED + lwm2m_queue_mode_object_init(); +#endif } /*---------------------------------------------------------------------------*/ /* @@ -743,7 +763,7 @@ perform_multi_resource_read_op(lwm2m_object_t *object, } /* ---------- Read operation ------------- */ } else if(ctx->operation == LWM2M_OP_READ) { - lwm2m_status_t success; + lwm2m_status_t success = 0; uint8_t lv; lv = ctx->level; @@ -1370,6 +1390,10 @@ lwm2m_handler_callback(coap_message_t *request, coap_message_t *response, context.inbuf->size = coap_get_payload(request, (const uint8_t **)&context.inbuf->buffer); context.inbuf->pos = 0; +#if LWM2M_QUEUE_MODE_ENABLED +lwm2m_queue_mode_request_received(); +#endif /* LWM2M_QUEUE_MODE_ENABLED */ + /* Maybe this should be part of CoAP itself - this seems not to be working with the leshan server */ #define LWM2M_CONF_ENTITY_TOO_LARGE_BLOCK1 0 @@ -1629,14 +1653,46 @@ lwm2m_handler_callback(coap_message_t *request, coap_message_t *response, return COAP_HANDLER_STATUS_PROCESSED; } /*---------------------------------------------------------------------------*/ -void lwm2m_notify_object_observers(lwm2m_object_instance_t *obj, +static void +lwm2m_send_notification(char* path) +{ +#if LWM2M_QUEUE_MODE_ENABLED && LWM2M_QUEUE_MODE_INCLUDE_DYNAMIC_ADAPTATION + if(lwm2m_queue_mode_get_dynamic_adaptation_flag()) { + lwm2m_queue_mode_set_handler_from_notification(); + } +#endif + coap_notify_observers_sub(NULL, path); +} +/*---------------------------------------------------------------------------*/ +void +lwm2m_notify_object_observers(lwm2m_object_instance_t *obj, uint16_t resource) { char path[20]; /* 60000/60000/60000 */ if(obj != NULL) { snprintf(path, 20, "%d/%d/%d", obj->object_id, obj->instance_id, resource); - coap_notify_observers_sub(NULL, path); } + +#if LWM2M_QUEUE_MODE_ENABLED + + if(coap_has_observers(path)) { + /* Client is sleeping -> add the notification to the list */ + if(!lwm2m_rd_client_is_client_awake()) { + lwm2m_notification_queue_add_notification_path(obj->object_id, obj->instance_id, resource); + + /* if it is the first notification -> wake up and send update */ + if(!lwm2m_queue_mode_is_waked_up_by_notification()) { + lwm2m_queue_mode_set_waked_up_by_notification(); + lwm2m_rd_client_fsm_execute_queue_mode_update(); + } + /* Client is awake -> send the notification */ + } else { + lwm2m_send_notification(path); + } + } +#else + lwm2m_send_notification(path); +#endif } /*---------------------------------------------------------------------------*/ /** @} */ diff --git a/os/services/lwm2m/lwm2m-engine.h b/os/services/lwm2m/lwm2m-engine.h index 62a667e99..0ca24fb90 100644 --- a/os/services/lwm2m/lwm2m-engine.h +++ b/os/services/lwm2m/lwm2m-engine.h @@ -39,12 +39,14 @@ * \author * Joakim Eriksson * Niclas Finne + * Carlos Gonzalo Peces */ #ifndef LWM2M_ENGINE_H #define LWM2M_ENGINE_H #include "lwm2m-object.h" +#include "lwm2m-queue-mode-conf.h" #define LWM2M_FLOAT32_BITS 10 #define LWM2M_FLOAT32_FRAC (1L << LWM2M_FLOAT32_BITS) @@ -114,6 +116,5 @@ void lwm2m_notify_object_observers(lwm2m_object_instance_t *obj, void lwm2m_engine_set_opaque_callback(lwm2m_context_t *ctx, lwm2m_write_opaque_callback cb); - #endif /* LWM2M_ENGINE_H */ /** @} */ diff --git a/os/services/lwm2m/lwm2m-notification-queue.c b/os/services/lwm2m/lwm2m-notification-queue.c new file mode 100644 index 000000000..c901bef82 --- /dev/null +++ b/os/services/lwm2m/lwm2m-notification-queue.c @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2017, RISE SICS AB. + * 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 HOLDER 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. + */ + +/** + * \addtogroup lwm2m + * @{ + */ + +/** + * \file + * Implementation of functions to manage the queue to store notifications + when waiting for the response to the update message in Queue Mode. + * \author + * Carlos Gonzalo Peces + */ +/*---------------------------------------------------------------------------*/ +#include "lwm2m-notification-queue.h" + +#if LWM2M_QUEUE_MODE_ENABLED + +#include "lwm2m-queue-mode.h" +#include "lwm2m-engine.h" +#include "coap-engine.h" +#include "lib/memb.h" +#include "lib/list.h" +#include +#include +#include +#include + +/* Log configuration */ +#include "coap-log.h" +#define LOG_MODULE "lwm2m-notification-queue" +#define LOG_LEVEL LOG_LEVEL_LWM2M + +#ifdef LWM2M_NOTIFICATION_QUEUE_CONF_LENGTH +#define LWM2M_NOTIFICATION_QUEUE_LENGTH LWM2M_NOTIFICATION_QUEUE_CONF_LENGTH +#else +#define LWM2M_NOTIFICATION_QUEUE_LENGTH COAP_MAX_OBSERVERS +#endif + +/*---------------------------------------------------------------------------*/ +/* Queue to store the notifications in the period when the client has woken up, sent the update and it's waiting for the server response*/ +MEMB(notification_memb, notification_path_t, LWM2M_NOTIFICATION_QUEUE_LENGTH); /* Length + 1 to allocate the new path to add */ +LIST(notification_paths_queue); +/*---------------------------------------------------------------------------*/ +void +lwm2m_notification_queue_init(void) +{ + list_init(notification_paths_queue); +} +/*---------------------------------------------------------------------------*/ +static void +extend_path(notification_path_t *path_object, char *path, int path_size) +{ + switch(path_object->level) { + case 1: + snprintf(path, path_size, "%u", path_object->reduced_path[0]); + break; + case 2: + snprintf(path, path_size, "%u/%u", path_object->reduced_path[0], path_object->reduced_path[1]); + break; + case 3: + snprintf(path, path_size, "%u/%u/%u", path_object->reduced_path[0], path_object->reduced_path[1], path_object->reduced_path[2]); + break; + } +} +/*---------------------------------------------------------------------------*/ +static int +is_notification_path_present(uint16_t object_id, uint16_t instance_id, uint16_t resource_id) +{ + notification_path_t *iteration_path = (notification_path_t *)list_head(notification_paths_queue); + while(iteration_path != NULL) { + if(iteration_path->reduced_path[0] == object_id && iteration_path->reduced_path[1] == instance_id + && iteration_path->reduced_path[2] == resource_id) { + return 1; + } + iteration_path = iteration_path->next; + } + return 0; +} +/*---------------------------------------------------------------------------*/ +static void +remove_notification_path(notification_path_t *path) +{ + list_remove(notification_paths_queue, path); + memb_free(¬ification_memb, path); +} +/*---------------------------------------------------------------------------*/ +void +lwm2m_notification_queue_add_notification_path(uint16_t object_id, uint16_t instance_id, uint16_t resource_id) +{ + if(is_notification_path_present(object_id, instance_id, resource_id)) { + LOG_DBG("Notification path already present, not queueing it\n"); + return; + } + notification_path_t *path_object = memb_alloc(¬ification_memb); + if(path_object == NULL) { + LOG_DBG("Queue is full, could not allocate new notification\n"); + return; + } + path_object->reduced_path[0] = object_id; + path_object->reduced_path[1] = instance_id; + path_object->reduced_path[2] = resource_id; + path_object->level = 3; + list_add(notification_paths_queue, path_object); + LOG_DBG("Notification path added to the list: %u/%u/%u\n", object_id, instance_id, resource_id); +} +/*---------------------------------------------------------------------------*/ +void +lwm2m_notification_queue_send_notifications() +{ + char path[20]; + notification_path_t *iteration_path = (notification_path_t *)list_head(notification_paths_queue); + notification_path_t *aux = iteration_path; + + while(iteration_path != NULL) { + extend_path(iteration_path, path, sizeof(path)); +#if LWM2M_QUEUE_MODE_INCLUDE_DYNAMIC_ADAPTATION + if(lwm2m_queue_mode_get_dynamic_adaptation_flag()) { + lwm2m_queue_mode_set_handler_from_notification(); + } +#endif + LOG_DBG("Sending stored notification with path: %s\n", path); + coap_notify_observers_sub(NULL, path); + aux = iteration_path; + iteration_path = iteration_path->next; + remove_notification_path(aux); + } +} +#endif /* LWM2M_QUEUE_MODE_ENABLED */ +/** @} */ \ No newline at end of file diff --git a/os/services/lwm2m/lwm2m-notification-queue.h b/os/services/lwm2m/lwm2m-notification-queue.h new file mode 100644 index 000000000..e3f4719ac --- /dev/null +++ b/os/services/lwm2m/lwm2m-notification-queue.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2017, RISE SICS AB. + * 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 HOLDER 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. + */ + +/** + * \addtogroup lwm2m + * @{ + */ + +/** + * \file + * Header file for functions to manage the queue to store notifications + when waiting for the response to the update message in Queue Mode. + * \author + * Carlos Gonzalo Peces + */ + +#ifndef LWM2M_NOTIFICATION_QUEUE_H +#define LWM2M_NOTIFICATION_QUEUE_H + +#include "contiki.h" +#include "lwm2m-queue-mode-conf.h" + +#include + +typedef struct notification_path { + struct notification_path *next; + uint16_t reduced_path[3]; + uint8_t level; /* The depth level of the path: 1. object, 2. object/instance, 3. object/instance/resource */ +} notification_path_t; + +void lwm2m_notification_queue_init(void); + +void lwm2m_notification_queue_add_notification_path(uint16_t object_id, uint16_t instance_id, uint16_t resource_id); + +void lwm2m_notification_queue_send_notifications(); + +#endif /* LWM2M_NOTIFICATION_QUEUE_H */ +/** @} */ \ No newline at end of file diff --git a/os/services/lwm2m/lwm2m-queue-mode-conf.h b/os/services/lwm2m/lwm2m-queue-mode-conf.h new file mode 100644 index 000000000..3432c112a --- /dev/null +++ b/os/services/lwm2m/lwm2m-queue-mode-conf.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2017, RISE SICS AB. + * 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 HOLDER 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. + */ + +/** + * \addtogroup lwm2m + * @{ + */ + +/** + * \file + * Queue Mode Configuration Parameters + * \author + * Carlos Gonzalo Peces + */ + +#ifndef LWM2M_QUEUE_MODE_CONF_H +#define LWM2M_QUEUE_MODE_CONF_H + +#include "contiki.h" + +/* Enable the Queue Mode */ +#ifdef LWM2M_QUEUE_MODE_CONF_ENABLED +#define LWM2M_QUEUE_MODE_ENABLED LWM2M_QUEUE_MODE_CONF_ENABLED +#else +#define LWM2M_QUEUE_MODE_ENABLED 0 +#endif /* LWM2M_QUEUE_MODE_CONF_ENABLED */ + +/* Default Sleeping Time */ +#ifdef LWM2M_QUEUE_MODE_CONF_DEFAULT_CLIENT_SLEEP_TIME +#define LWM2M_QUEUE_MODE_DEFAULT_CLIENT_SLEEP_TIME LWM2M_QUEUE_MODE_CONF_DEFAULT_CLIENT_SLEEP_TIME +#else +#define LWM2M_QUEUE_MODE_DEFAULT_CLIENT_SLEEP_TIME 10000 /* msec */ +#endif /* LWM2M_QUEUE_MODE_DEFAULT_CLIENT_SLEEPING_TIME */ + +/* Default Awake Time */ +#ifdef LWM2M_QUEUE_MODE_CONF_DEFAULT_CLIENT_AWAKE_TIME +#define LWM2M_QUEUE_MODE_DEFAULT_CLIENT_AWAKE_TIME LWM2M_QUEUE_MODE_CONF_DEFAULT_CLIENT_AWAKE_TIME +#else +#define LWM2M_QUEUE_MODE_DEFAULT_CLIENT_AWAKE_TIME 5000 /* msec */ +#endif /* LWM2M_QUEUE_MODE_DEFAULT_CLIENT_AWAKE_TIME */ + +/* Include the possibility to do the dynamic adaptation of the client awake time */ +#ifdef LWM2M_QUEUE_MODE_CONF_INCLUDE_DYNAMIC_ADAPTATION +#define LWM2M_QUEUE_MODE_INCLUDE_DYNAMIC_ADAPTATION LWM2M_QUEUE_MODE_CONF_INCLUDE_DYNAMIC_ADAPTATION +#else +#define LWM2M_QUEUE_MODE_INCLUDE_DYNAMIC_ADAPTATION 0 /* not included */ +#endif /* LWM2M_QUEUE_MODE_INCLUDE_DYNAMIC_ADAPTATION */ + +/* Default value for the dynamic adaptation flag */ +#ifdef LWM2M_QUEUE_MODE_CONF_DEFAULT_DYNAMIC_ADAPTATION_FLAG +#define LWM2M_QUEUE_MODE_DEFAULT_DYNAMIC_ADAPTATION_FLAG LWM2M_QUEUE_MODE_CONF_DEFAULT_DYNAMIC_ADAPTATION_FLAG +#else +#define LWM2M_QUEUE_MODE_DEFAULT_DYNAMIC_ADAPTATION_FLAG 0 /* disabled */ +#endif /* LWM2M_QUEUE_MODE_DEFAULT_DYNAMIC_ADAPTATION_FLAG */ + +/* Length of the list of times for the dynamic adaptation */ +#define LWM2M_QUEUE_MODE_DYNAMIC_ADAPTATION_WINDOW_LENGTH 10 + +/* Enable and disable the Queue Mode Object */ +#ifdef LWM2M_QUEUE_MODE_OBJECT_CONF_ENABLED +#define LWM2M_QUEUE_MODE_OBJECT_ENABLED LWM2M_QUEUE_MODE_OBJECT_CONF_ENABLED +#else +#define LWM2M_QUEUE_MODE_OBJECT_ENABLED 0 /* not included */ +#endif /* LWM2M_QUEUE_MODE_OBJECT_ENABLED */ + + + +#endif /* LWM2M_QUEUE_MODE_CONF_H */ +/** @} */ diff --git a/os/services/lwm2m/lwm2m-queue-mode-object.c b/os/services/lwm2m/lwm2m-queue-mode-object.c new file mode 100644 index 000000000..a3c000d69 --- /dev/null +++ b/os/services/lwm2m/lwm2m-queue-mode-object.c @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2017, RISE SICS AB. + * 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 HOLDER 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. + */ + +/** + * \addtogroup lwm2m + * @{ + */ + +/** + * \file + * Implementation of the Contiki OMA LWM2M Queue Mode object + to manage the parameters from the server side + * \author + * Carlos Gonzalo Peces + */ + +#include "lwm2m-object.h" +#include "lwm2m-queue-mode.h" + +/* Log configuration */ +#include "coap-log.h" +#define LOG_MODULE "lwm2m-qmode-object" +#define LOG_LEVEL LOG_LEVEL_LWM2M + +#if LWM2M_QUEUE_MODE_ENABLED && LWM2M_QUEUE_MODE_OBJECT_ENABLED + +#define LWM2M_QUEUE_MODE_OBJECT_ID 30000 +#define LWM2M_AWAKE_TIME_ID 30000 +#define LWM2M_SLEEP_TIME_ID 30001 + +#if LWM2M_QUEUE_MODE_INCLUDE_DYNAMIC_ADAPTATION +#define LWM2M_DYNAMIC_ADAPTATION_FLAG_ID 30002 +#define UPDATE_WITH_MEAN 0 /* 1-mean time 0-maximum time */ +#endif + +static const lwm2m_resource_id_t resources[] = +{ RW(LWM2M_AWAKE_TIME_ID), + RW(LWM2M_SLEEP_TIME_ID), +#if LWM2M_QUEUE_MODE_INCLUDE_DYNAMIC_ADAPTATION + RW(LWM2M_DYNAMIC_ADAPTATION_FLAG_ID), +#endif +}; + +/*---------------------------------------------------------------------------*/ +static lwm2m_status_t +lwm2m_callback(lwm2m_object_instance_t *object, lwm2m_context_t *ctx) +{ + if(ctx->operation == LWM2M_OP_READ) { + switch(ctx->resource_id) { + case LWM2M_AWAKE_TIME_ID: + lwm2m_object_write_int(ctx, (int32_t)lwm2m_queue_mode_get_awake_time()); + return LWM2M_STATUS_OK; + case LWM2M_SLEEP_TIME_ID: + lwm2m_object_write_int(ctx, (int32_t)lwm2m_queue_mode_get_sleep_time()); + return LWM2M_STATUS_OK; +#if LWM2M_QUEUE_MODE_INCLUDE_DYNAMIC_ADAPTATION + case LWM2M_DYNAMIC_ADAPTATION_FLAG_ID: + lwm2m_object_write_int(ctx, (int32_t)lwm2m_queue_mode_get_dynamic_adaptation_flag()); + return LWM2M_STATUS_OK; +#endif + } + } else if(ctx->operation == LWM2M_OP_WRITE) { + switch(ctx->resource_id) { + int32_t value_read; + size_t len; + + case LWM2M_AWAKE_TIME_ID: + + len = lwm2m_object_read_int(ctx, ctx->inbuf->buffer, ctx->inbuf->size, + &value_read); + LOG_DBG("Client Awake Time write request value: %d\n", (int)value_read); + if(len == 0) { + LOG_WARN("FAIL: could not write awake time\n"); + return LWM2M_STATUS_WRITE_ERROR; + } else { + lwm2m_queue_mode_set_awake_time(value_read); + return LWM2M_STATUS_OK; + } + + case LWM2M_SLEEP_TIME_ID: + len = lwm2m_object_read_int(ctx, ctx->inbuf->buffer, ctx->inbuf->size, + &value_read); + LOG_DBG("Client Sleep Time write request value: %d\n", (int)value_read); + if(len == 0) { + LOG_WARN("FAIL: could not write sleep time\n"); + return LWM2M_STATUS_WRITE_ERROR; + } else { + lwm2m_queue_mode_set_sleep_time(value_read); + return LWM2M_STATUS_OK; + } +#if LWM2M_QUEUE_MODE_INCLUDE_DYNAMIC_ADAPTATION + case LWM2M_DYNAMIC_ADAPTATION_FLAG_ID: + len = lwm2m_object_read_int(ctx, ctx->inbuf->buffer, ctx->inbuf->size, + &value_read); + LOG_DBG("Dynamic Adaptation Flag request value: %d\n", (int)value_read); + if(len == 0) { + LOG_WARN("FAIL: could not write dynamic flag\n"); + return LWM2M_STATUS_WRITE_ERROR; + } else { + lwm2m_queue_mode_set_dynamic_adaptation_flag(value_read); + return LWM2M_STATUS_OK; + } +#endif + } + } + + return LWM2M_STATUS_OPERATION_NOT_ALLOWED; +} +/*---------------------------------------------------------------------------*/ +static lwm2m_object_instance_t queue_object = { + .object_id = LWM2M_QUEUE_MODE_OBJECT_ID, + .instance_id = 0, + .resource_ids = resources, + .resource_count = sizeof(resources) / sizeof(lwm2m_resource_id_t), + .resource_dim_callback = NULL, + .callback = lwm2m_callback, +}; +/*---------------------------------------------------------------------------*/ +void +lwm2m_queue_mode_object_init(void) +{ + lwm2m_engine_add_object(&queue_object); +} +#endif /* LWM2M_QUEUE_MODE_ENABLED && LWM2M_QUEUE_MODE_OBJECT_ENABLED */ +/** @} */ \ No newline at end of file diff --git a/os/services/lwm2m/lwm2m-queue-mode-object.h b/os/services/lwm2m/lwm2m-queue-mode-object.h new file mode 100644 index 000000000..017b797fc --- /dev/null +++ b/os/services/lwm2m/lwm2m-queue-mode-object.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2017, RISE SICS AB. + * 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 HOLDER 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. + */ + +/** + * \addtogroup oma-lwm2m + * @{ + */ + +/** + * \file + * Header file for the Contiki OMA LWM2M Queue Mode object + to manage the parameters from the server side + * \author + * Carlos Gonzalo Peces + */ + +#ifndef LWM2M_QUEUE_MODE_OBJECT_H_ +#define LWM2M_QUEUE_MODE_OBJECT_H_ + +#include "lwm2m-queue-mode-conf.h" + +void lwm2m_queue_mode_object_init(void); + +#endif /* LWM2M_Q_OBJECT_H_ */ +/** @} */ \ No newline at end of file diff --git a/os/services/lwm2m/lwm2m-queue-mode.c b/os/services/lwm2m/lwm2m-queue-mode.c new file mode 100644 index 000000000..aad80ce3e --- /dev/null +++ b/os/services/lwm2m/lwm2m-queue-mode.c @@ -0,0 +1,270 @@ +/* + * Copyright (c) 2017, RISE SICS AB. + * 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 HOLDER 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. + */ + +/** + * \addtogroup lwm2m + * @{ + */ + +/** + * \file + * Implementation of the Contiki OMA LWM2M Queue Mode for managing the parameters + * \author + * Carlos Gonzalo Peces + */ + +#include "lwm2m-queue-mode.h" + +#if LWM2M_QUEUE_MODE_ENABLED + +#include "lwm2m-engine.h" +#include "lwm2m-rd-client.h" +#include "lib/memb.h" +#include "lib/list.h" +#include + +/* Log configuration */ +#include "coap-log.h" +#define LOG_MODULE "lwm2m-queue-mode" +#define LOG_LEVEL LOG_LEVEL_LWM2M + +/* Queue Mode dynamic adaptation masks */ +#define FIRST_REQUEST_MASK 0x01 +#define HANDLER_FROM_NOTIFICATION_MASK 0x02 + +static uint16_t queue_mode_awake_time = LWM2M_QUEUE_MODE_DEFAULT_CLIENT_AWAKE_TIME; +static uint32_t queue_mode_sleep_time = LWM2M_QUEUE_MODE_DEFAULT_CLIENT_SLEEP_TIME; + +/* Flag for notifications */ +static uint8_t waked_up_by_notification; + +/* For the dynamic adaptation of the awake time */ +#if LWM2M_QUEUE_MODE_INCLUDE_DYNAMIC_ADAPTATION +static uint8_t queue_mode_dynamic_adaptation_flag = LWM2M_QUEUE_MODE_DEFAULT_DYNAMIC_ADAPTATION_FLAG; + +/* Window to save the times and do the dynamic adaptation of the awake time*/ +uint16_t times_window[LWM2M_QUEUE_MODE_DYNAMIC_ADAPTATION_WINDOW_LENGTH] = { 0 }; +uint8_t times_window_index = 0; +static uint8_t dynamic_adaptation_params = 0x00; /* bit0: first_request, bit1: handler from notification */ +static uint64_t previous_request_time; +static inline void clear_first_request(); +static inline uint8_t is_first_request(); +static inline void clear_handler_from_notification(); +static inline uint8_t get_handler_from_notification(); +#endif /* LWM2M_QUEUE_MODE_INCLUDE_DYNAMIC_ADAPTATION */ +/*---------------------------------------------------------------------------*/ +uint16_t +lwm2m_queue_mode_get_awake_time() +{ + LOG_DBG("Client Awake Time: %d ms\n", (int)queue_mode_awake_time); + return queue_mode_awake_time; +} +/*---------------------------------------------------------------------------*/ +void +lwm2m_queue_mode_set_awake_time(uint16_t time) +{ + queue_mode_awake_time = time; +} +/*---------------------------------------------------------------------------*/ +uint32_t +lwm2m_queue_mode_get_sleep_time() +{ + LOG_DBG("Client Sleep Time: %d ms\n", (int)queue_mode_sleep_time); + return queue_mode_sleep_time; +} +/*---------------------------------------------------------------------------*/ +void +lwm2m_queue_mode_set_sleep_time(uint32_t time) +{ + queue_mode_sleep_time = time; +} +/*---------------------------------------------------------------------------*/ +#if LWM2M_QUEUE_MODE_INCLUDE_DYNAMIC_ADAPTATION +uint8_t +lwm2m_queue_mode_get_dynamic_adaptation_flag() +{ + LOG_DBG("Dynamic Adaptation Flag: %d ms\n", (int)queue_mode_dynamic_adaptation_flag); + return queue_mode_dynamic_adaptation_flag; +} +/*---------------------------------------------------------------------------*/ +void +lwm2m_queue_mode_set_dynamic_adaptation_flag(uint8_t flag) +{ + queue_mode_dynamic_adaptation_flag = flag; +} +#endif +/*---------------------------------------------------------------------------*/ +#if !UPDATE_WITH_MEAN +static uint16_t +get_maximum_time() +{ + uint16_t max_time = 0; + uint8_t i; + for(i = 0; i < LWM2M_QUEUE_MODE_DYNAMIC_ADAPTATION_WINDOW_LENGTH; i++) { + if(times_window[i] > max_time) { + max_time = times_window[i]; + } + } + return max_time; +} +#endif +/*---------------------------------------------------------------------------*/ +#if UPDATE_WITH_MEAN +static uint16_t +get_mean_time() +{ + uint16_t mean_time = 0; + uint8_t i; + for(i = 0; i < LWM2M_QUEUE_MODE_DYNAMIC_ADAPTATION_WINDOW_LENGTH; i++) { + if(mean_time == 0) { + mean_time = times_window[i]; + } else { + if(times_window[i] != 0) { + mean_time = (mean_time + times_window[i]) / 2; + } + } + } + return mean_time; +} +#endif +/*---------------------------------------------------------------------------*/ +static void +update_awake_time() +{ +#if UPDATE_WITH_MEAN + uint16_t mean_time = get_mean_time(); + LOG_DBG("Dynamic Adaptation: updated awake time: %d ms\n", (int)mean_time); + lwm2m_queue_mode_set_awake_time(mean_time + (mean_time >> 1)); /* 50% margin */ + return; +#else + uint16_t max_time = get_maximum_time(); + LOG_DBG("Dynamic Adaptation: updated awake time: %d ms\n", (int)max_time); + lwm2m_queue_mode_set_awake_time(max_time + (max_time >> 1)); /* 50% margin */ + return; +#endif +} +/*---------------------------------------------------------------------------*/ +void +lwm2m_queue_mode_add_time_to_window(uint16_t time) +{ + if(times_window_index == LWM2M_QUEUE_MODE_DYNAMIC_ADAPTATION_WINDOW_LENGTH) { + times_window_index = 0; + } + times_window[times_window_index] = time; + times_window_index++; + update_awake_time(); +} +/*---------------------------------------------------------------------------*/ +uint8_t +lwm2m_queue_mode_is_waked_up_by_notification() +{ + return waked_up_by_notification; +} +/*---------------------------------------------------------------------------*/ +void +lwm2m_queue_mode_clear_waked_up_by_notification() +{ + waked_up_by_notification = 0; +} +/*---------------------------------------------------------------------------*/ +void +lwm2m_queue_mode_set_waked_up_by_notification() +{ + waked_up_by_notification = 1; +} +/*---------------------------------------------------------------------------*/ +void +lwm2m_queue_mode_request_received() +{ + if(lwm2m_rd_client_is_client_awake()) { + lwm2m_rd_client_restart_client_awake_timer(); + } +#if LWM2M_QUEUE_MODE_INCLUDE_DYNAMIC_ADAPTATION + if(lwm2m_queue_mode_get_dynamic_adaptation_flag() && !get_handler_from_notification()) { + if(is_first_request()) { + previous_request_time = coap_timer_uptime(); + clear_first_request(); + } else { + if(coap_timer_uptime() - previous_request_time >= 0) { + if(coap_timer_uptime() - previous_request_time > 0xffff) { + lwm2m_queue_mode_add_time_to_window(0xffff); + } else { + lwm2m_queue_mode_add_time_to_window(coap_timer_uptime() - previous_request_time); + } + } + previous_request_time = coap_timer_uptime(); + } + } + if(get_handler_from_notification()) { + clear_handler_from_notification(); + } +#endif /* LWM2M_QUEUE_MODE_INCLUDE_DYNAMIC_ADAPTATION */ +} +/*---------------------------------------------------------------------------*/ +#if LWM2M_QUEUE_MODE_INCLUDE_DYNAMIC_ADAPTATION +void +lwm2m_queue_mode_set_first_request() +{ + dynamic_adaptation_params |= FIRST_REQUEST_MASK; +} +/*---------------------------------------------------------------------------*/ +void +lwm2m_queue_mode_set_handler_from_notification() +{ + dynamic_adaptation_params |= HANDLER_FROM_NOTIFICATION_MASK; +} +/*---------------------------------------------------------------------------*/ +static inline uint8_t +is_first_request() +{ + return dynamic_adaptation_params & FIRST_REQUEST_MASK; +} +/*---------------------------------------------------------------------------*/ +static inline uint8_t +get_handler_from_notification() +{ + return (dynamic_adaptation_params & HANDLER_FROM_NOTIFICATION_MASK) != 0; +} +/*---------------------------------------------------------------------------*/ +static inline void +clear_first_request() +{ + dynamic_adaptation_params &= ~FIRST_REQUEST_MASK; +} +/*---------------------------------------------------------------------------*/ +static inline void +clear_handler_from_notification() +{ + dynamic_adaptation_params &= ~HANDLER_FROM_NOTIFICATION_MASK; +} +#endif /* LWM2M_QUEUE_MODE_INCLUDE_DYNAMIC_ADAPTATION */ +#endif /* LWM2M_QUEUE_MODE_ENABLED */ +/** @} */ + diff --git a/os/services/lwm2m/lwm2m-queue-mode.h b/os/services/lwm2m/lwm2m-queue-mode.h new file mode 100644 index 000000000..5c65face5 --- /dev/null +++ b/os/services/lwm2m/lwm2m-queue-mode.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2017, RISE SICS AB. + * 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 HOLDER 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. + */ + +/** + * \addtogroup oma-lwm2m + * @{ + */ + +/** + * \file + * Header file for the Contiki OMA LWM2M Queue Mode implementation + to manage the parameters + * \author + * Carlos Gonzalo Peces + */ + +#ifndef LWM2M_QUEUE_MODE_H_ +#define LWM2M_QUEUE_MODE_H_ + +#include "lwm2m-queue-mode-conf.h" +#include + +uint16_t lwm2m_queue_mode_get_awake_time(); +void lwm2m_queue_mode_set_awake_time(uint16_t time); +uint32_t lwm2m_queue_mode_get_sleep_time(); +void lwm2m_queue_mode_set_sleep_time(uint32_t time); + +#if LWM2M_QUEUE_MODE_INCLUDE_DYNAMIC_ADAPTATION +uint8_t lwm2m_queue_mode_get_dynamic_adaptation_flag(); +void lwm2m_queue_mode_set_dynamic_adaptation_flag(uint8_t flag); +void lwm2m_queue_mode_add_time_to_window(uint16_t time); +#endif + +uint8_t lwm2m_queue_mode_is_waked_up_by_notification(); +void lwm2m_queue_mode_clear_waked_up_by_notification(); +void lwm2m_queue_mode_set_waked_up_by_notification(); + +void lwm2m_queue_mode_set_first_request(); +void lwm2m_queue_mode_set_handler_from_notification(); + +void lwm2m_queue_mode_request_received(); + +#endif /* LWM2M_QUEUE_MODE_H_ */ +/** @} */ diff --git a/os/services/lwm2m/lwm2m-rd-client.c b/os/services/lwm2m/lwm2m-rd-client.c index 03d21e33e..4b4b11528 100644 --- a/os/services/lwm2m/lwm2m-rd-client.c +++ b/os/services/lwm2m/lwm2m-rd-client.c @@ -41,8 +41,8 @@ * Joakim Eriksson * Niclas Finne * Joel Hoglund + * Carlos Gonzalo Peces */ - #include "lwm2m-engine.h" #include "lwm2m-object.h" #include "lwm2m-device.h" @@ -62,6 +62,11 @@ #include "rpl.h" #endif /* UIP_CONF_IPV6_RPL */ +#if LWM2M_QUEUE_MODE_ENABLED +#include "lwm2m-queue-mode.h" +#include "lwm2m-notification-queue.h" +#endif /* LWM2M_QUEUE_MODE_ENABLED */ + /* Log configuration */ #include "coap-log.h" #define LOG_MODULE "lwm2m-rd" @@ -79,7 +84,7 @@ #define STATE_MACHINE_UPDATE_INTERVAL 500 static struct lwm2m_session_info session_info; -static coap_request_state_t rd_request_state; +static coap_callback_request_state_t rd_request_state; static coap_message_t request[1]; /* This way the message can be treated as pointer as usual. */ @@ -100,6 +105,10 @@ static coap_message_t request[1]; /* This way the message can be treated as #define DEREGISTER_SENT 11 #define DEREGISTER_FAILED 12 #define DEREGISTERED 13 +#if LWM2M_QUEUE_MODE_ENABLED +#define QUEUE_MODE_AWAKE 14 +#define QUEUE_MODE_SEND_UPDATE 15 +#endif #define FLAG_RD_DATA_DIRTY 0x01 #define FLAG_RD_DATA_UPDATE_TRIGGERED 0x02 @@ -109,7 +118,6 @@ static uint8_t rd_state = 0; static uint8_t rd_flags = FLAG_RD_DATA_UPDATE_ON_DIRTY; static uint64_t wait_until_network_check = 0; static uint64_t last_update; -static uint64_t last_rd_progress = 0; static char query_data[64]; /* allocate some data for queries and updates */ static uint8_t rd_data[128]; /* allocate some data for the RD */ @@ -117,12 +125,24 @@ static uint8_t rd_data[128]; /* allocate some data for the RD */ static uint32_t rd_block1; static uint8_t rd_more; static coap_timer_t rd_timer; -static void (*rd_callback)(coap_request_state_t *state); +static void (*rd_callback)(coap_callback_request_state_t *callback_state); static coap_timer_t block1_timer; +#if LWM2M_QUEUE_MODE_ENABLED +static coap_timer_t queue_mode_client_awake_timer; /* Timer to control the client's + * awake time + */ +static uint8_t queue_mode_client_awake; /* 1 - client is awake, + * 0 - client is sleeping + */ +static uint16_t queue_mode_client_awake_time; /* The time to be awake */ +/* Callback for the client awake timer */ +static void queue_mode_awake_timer_callback(coap_timer_t *timer); +#endif + static void check_periodic_observations(); -static void update_callback(coap_request_state_t *state); +static void update_callback(coap_callback_request_state_t *callback_state); static int set_rd_data(coap_message_t *request) @@ -147,7 +167,8 @@ set_rd_data(coap_message_t *request) } /*---------------------------------------------------------------------------*/ static void -prepare_update(coap_message_t *request, int triggered) { +prepare_update(coap_message_t *request, int triggered) +{ coap_init_message(request, COAP_TYPE_CON, COAP_POST, 0); coap_set_header_uri_path(request, session_info.assigned_ep); @@ -348,10 +369,11 @@ update_bootstrap_server(void) * TODO */ static void -bootstrap_callback(coap_request_state_t *state) +bootstrap_callback(coap_callback_request_state_t *callback_state) { + coap_request_state_t *state = &callback_state->state; LOG_DBG("Bootstrap callback Response: %d, ", state->response != NULL); - if(state->response) { + if(state->status == COAP_REQUEST_STATUS_RESPONSE) { if(CHANGED_2_04 == state->response->code) { LOG_DBG_("Considered done!\n"); rd_state = BOOTSTRAP_DONE; @@ -361,12 +383,14 @@ bootstrap_callback(coap_request_state_t *state) LOG_DBG_("Failed with code %d. Retrying\n", state->response->code); /* TODO Application callback? */ rd_state = INIT; - } else if(BOOTSTRAP_SENT == rd_state) { /* this can handle double invocations */ - /* Failure! */ - LOG_DBG("Bootstrap failed! Retry?"); + } else if(state->status == COAP_REQUEST_STATUS_TIMEOUT) { + LOG_DBG_("Server not responding! Retry?"); rd_state = DO_BOOTSTRAP; + } else if(state->status == COAP_REQUEST_STATUS_FINISHED) { + LOG_DBG_("Request finished. Ignore\n"); } else { - LOG_DBG("Ignore\n"); + LOG_DBG_("Unexpected error! Retry?"); + rd_state = DO_BOOTSTRAP; } } /*---------------------------------------------------------------------------*/ @@ -405,10 +429,11 @@ block1_rd_callback(coap_timer_t *timer) * Page 65-66 in 07 April 2016 spec. */ static void -registration_callback(coap_request_state_t *state) +registration_callback(coap_callback_request_state_t *callback_state) { - LOG_DBG("Registration callback. Response: %d, ", state->response != NULL); - if(state->response) { + coap_request_state_t *state = &callback_state->state; + LOG_DBG("Registration callback. Status: %d. Response: %d, ", state->status, state->response != NULL); + if(state->status == COAP_REQUEST_STATUS_RESPONSE) { /* check state and possibly set registration to done */ /* If we get a continue - we need to call the rd generator one more time */ if(CONTINUE_2_31 == state->response->code) { @@ -423,7 +448,16 @@ registration_callback(coap_request_state_t *state) state->response->location_path_len); session_info.assigned_ep[state->response->location_path_len] = 0; /* if we decide to not pass the lt-argument on registration, we should force an initial "update" to register lifetime with server */ +#if LWM2M_QUEUE_MODE_ENABLED +#if LWM2M_QUEUE_MODE_INCLUDE_DYNAMIC_ADAPTATION + if(lwm2m_queue_mode_get_dynamic_adaptation_flag()) { + lwm2m_queue_mode_set_first_request(); + } +#endif + lwm2m_rd_client_fsm_execute_queue_mode_awake(); /* Avoid 500 ms delay and move directly to the state*/ +#else rd_state = REGISTRATION_DONE; +#endif /* remember the last reg time */ last_update = coap_timer_uptime(); LOG_DBG_("Done (assigned EP='%s')!\n", session_info.assigned_ep); @@ -441,10 +475,14 @@ registration_callback(coap_request_state_t *state) } /* TODO Application callback? */ rd_state = INIT; - /* remember last progress time */ - last_rd_progress = coap_timer_uptime(); + } else if(state->status == COAP_REQUEST_STATUS_TIMEOUT) { + LOG_DBG_("Server not responding, trying to reconnect\n"); + rd_state = INIT; + } else if(state->status == COAP_REQUEST_STATUS_FINISHED){ + LOG_DBG_("Request finished. Ignore\n"); } else { - LOG_DBG_("Ignore\n"); + LOG_DBG_("Unexpected error, trying to reconnect\n"); + rd_state = INIT; } } /*---------------------------------------------------------------------------*/ @@ -452,11 +490,12 @@ registration_callback(coap_request_state_t *state) * Page 65-66 in 07 April 2016 spec. */ static void -update_callback(coap_request_state_t *state) +update_callback(coap_callback_request_state_t *callback_state) { - LOG_DBG("Update callback. Response: %d, ", state->response != NULL); + coap_request_state_t *state = &callback_state->state; + LOG_DBG("Update callback. Status: %d. Response: %d, ", state->status, state->response != NULL); - if(state->response) { + if(state->status == COAP_REQUEST_STATUS_RESPONSE) { /* If we get a continue - we need to call the rd generator one more time */ if(CONTINUE_2_31 == state->response->code) { /* We assume that size never change?! */ @@ -468,28 +507,49 @@ update_callback(coap_request_state_t *state) LOG_DBG_("Done!\n"); /* remember the last reg time */ last_update = coap_timer_uptime(); +#if LWM2M_QUEUE_MODE_ENABLED + /* If it has been waked up by a notification, send the stored notifications in queue */ + if(lwm2m_queue_mode_is_waked_up_by_notification()) { + + lwm2m_queue_mode_clear_waked_up_by_notification(); + lwm2m_notification_queue_send_notifications(); + } +#if LWM2M_QUEUE_MODE_INCLUDE_DYNAMIC_ADAPTATION + if(lwm2m_queue_mode_get_dynamic_adaptation_flag()) { + lwm2m_queue_mode_set_first_request(); + } +#endif /* LWM2M_QUEUE_MODE_INCLUDE_DYNAMIC_ADAPTATION */ + lwm2m_rd_client_fsm_execute_queue_mode_awake(); /* Avoid 500 ms delay and move directly to the state*/ +#else rd_state = REGISTRATION_DONE; rd_flags &= ~FLAG_RD_DATA_UPDATE_TRIGGERED; +#endif /* LWM2M_QUEUE_MODE_ENABLED */ } else { /* Possible error response codes are 4.00 Bad request & 4.04 Not Found */ LOG_DBG_("Failed with code %d. Retrying registration\n", state->response->code); rd_state = DO_REGISTRATION; } - /* remember last progress */ - last_rd_progress = coap_timer_uptime(); + } else if(state->status == COAP_REQUEST_STATUS_TIMEOUT) { + LOG_DBG_("Server not responding, trying to reconnect\n"); + rd_state = INIT; + } else if(state->status == COAP_REQUEST_STATUS_FINISHED){ + LOG_DBG_("Request finished. Ignore\n"); } else { - LOG_DBG("Ignore\n"); + LOG_DBG_("Unexpected error, trying to reconnect\n"); + rd_state = INIT; } } /*---------------------------------------------------------------------------*/ static void -deregister_callback(coap_request_state_t *state) +deregister_callback(coap_callback_request_state_t *callback_state) { - LOG_DBG("Deregister callback. Response Code: %d\n", + coap_request_state_t *state = &callback_state->state; + LOG_DBG("Deregister callback. Status: %d. Response Code: %d\n", + state->status, state->response != NULL ? state->response->code : 0); - if(state->response && (DELETED_2_02 == state->response->code)) { + if(state->status == COAP_REQUEST_STATUS_RESPONSE && (DELETED_2_02 == state->response->code)) { LOG_DBG("Deregistration success\n"); rd_state = DEREGISTERED; perform_session_callback(LWM2M_RD_CLIENT_DEREGISTERED); @@ -502,13 +562,6 @@ deregister_callback(coap_request_state_t *state) } } /*---------------------------------------------------------------------------*/ -static void -recover_from_rd_delay(void) -{ - /* This can be improved in the future... */ - rd_state = INIT; -} -/*---------------------------------------------------------------------------*/ /* CoAP timer callback */ static void periodic_process(coap_timer_t *timer) @@ -516,7 +569,15 @@ periodic_process(coap_timer_t *timer) uint64_t now; /* reschedule the CoAP timer */ +#if LWM2M_QUEUE_MODE_ENABLED + /* In Queue Mode, the machine is not executed periodically, but with the awake/sleeping times */ + if(!((rd_state & 0xF) == 0xE)) { + coap_timer_reset(&rd_timer, STATE_MACHINE_UPDATE_INTERVAL); + } +#else coap_timer_reset(&rd_timer, STATE_MACHINE_UPDATE_INTERVAL); +#endif + now = coap_timer_uptime(); LOG_DBG("RD Client - state: %d, ms: %lu\n", rd_state, @@ -557,10 +618,10 @@ periodic_process(coap_timer_t *timer) LOG_INFO_COAP_EP(&session_info.bs_server_ep); LOG_INFO_("] as '%s'\n", query_data); - coap_send_request(&rd_request_state, &session_info.bs_server_ep, - request, bootstrap_callback); - - rd_state = BOOTSTRAP_SENT; + if(coap_send_request(&rd_request_state, &session_info.bs_server_ep, + request, bootstrap_callback)) { + rd_state = BOOTSTRAP_SENT; + } } } break; @@ -656,18 +717,14 @@ periodic_process(coap_timer_t *timer) } LOG_INFO_("' More:%d\n", rd_more); - coap_send_request(&rd_request_state, &session_info.server_ep, - request, registration_callback); - last_rd_progress = coap_timer_uptime(); - rd_state = REGISTRATION_SENT; + if(coap_send_request(&rd_request_state, &session_info.server_ep, + request, registration_callback)){ + rd_state = REGISTRATION_SENT; + } } break; case REGISTRATION_SENT: /* just wait until the callback kicks us to the next state... */ - if(last_rd_progress + MAX_RD_UPDATE_WAIT < coap_timer_uptime()) { - /* Timeout on the update - something is wrong? */ - recover_from_rd_delay(); - } break; case REGISTRATION_DONE: /* All is done! */ @@ -679,27 +736,45 @@ periodic_process(coap_timer_t *timer) ((uint32_t)session_info.lifetime * 500) <= now - last_update) { /* triggered or time to send an update to the server, at half-time! sec vs ms */ prepare_update(request, rd_flags & FLAG_RD_DATA_UPDATE_TRIGGERED); - coap_send_request(&rd_request_state, &session_info.server_ep, request, - update_callback); - last_rd_progress = coap_timer_uptime(); + if(coap_send_request(&rd_request_state, &session_info.server_ep, request, + update_callback)) { + rd_state = UPDATE_SENT; + } + } + break; +#if LWM2M_QUEUE_MODE_ENABLED + case QUEUE_MODE_AWAKE: + LOG_DBG("Queue Mode: Client is AWAKE at %lu\n", (unsigned long)coap_timer_uptime()); + queue_mode_client_awake = 1; + queue_mode_client_awake_time = lwm2m_queue_mode_get_awake_time(); + coap_timer_set(&queue_mode_client_awake_timer, queue_mode_client_awake_time); + break; + case QUEUE_MODE_SEND_UPDATE: +/* Define this macro to make the necessary actions for waking up, + * depending on the platform + */ +#ifdef LWM2M_QUEUE_MODE_WAKE_UP + LWM2M_QUEUE_MODE_WAKE_UP(); +#endif /* LWM2M_QUEUE_MODE_WAKE_UP */ + prepare_update(request, rd_flags & FLAG_RD_DATA_UPDATE_TRIGGERED); + if(coap_send_request(&rd_request_state, &session_info.server_ep, request, + update_callback)) { rd_state = UPDATE_SENT; } break; +#endif /* LWM2M_QUEUE_MODE_ENABLED */ case UPDATE_SENT: /* just wait until the callback kicks us to the next state... */ - if(last_rd_progress + MAX_RD_UPDATE_WAIT < coap_timer_uptime()) { - /* Timeout on the update - something is wrong? */ - recover_from_rd_delay(); - } break; case DEREGISTER: LOG_INFO("DEREGISTER %s\n", session_info.assigned_ep); coap_init_message(request, COAP_TYPE_CON, COAP_DELETE, 0); coap_set_header_uri_path(request, session_info.assigned_ep); - coap_send_request(&rd_request_state, &session_info.server_ep, request, - deregister_callback); - rd_state = DEREGISTER_SENT; + if(coap_send_request(&rd_request_state, &session_info.server_ep, request, + deregister_callback)) { + rd_state = DEREGISTER_SENT; + } break; case DEREGISTER_SENT: break; @@ -718,15 +793,27 @@ lwm2m_rd_client_init(const char *ep) { session_info.ep = ep; /* default binding U = UDP, UQ = UDP Q-mode*/ +#if LWM2M_QUEUE_MODE_ENABLED + session_info.binding = "UQ"; + /* Enough margin to ensure that the client is not unregistered (we + * do not know the time it can stay awake) + */ + session_info.lifetime = (LWM2M_QUEUE_MODE_DEFAULT_CLIENT_SLEEP_TIME / 1000) * 2; +#else session_info.binding = "U"; if(session_info.lifetime == 0) { session_info.lifetime = LWM2M_DEFAULT_CLIENT_LIFETIME; } +#endif + rd_state = INIT; /* call the RD client periodically */ coap_timer_set_callback(&rd_timer, periodic_process); coap_timer_set(&rd_timer, STATE_MACHINE_UPDATE_INTERVAL); +#if LWM2M_QUEUE_MODE_ENABLED + coap_timer_set_callback(&queue_mode_client_awake_timer, queue_mode_awake_timer_callback); +#endif } /*---------------------------------------------------------------------------*/ static void @@ -735,4 +822,54 @@ check_periodic_observations(void) /* TODO */ } /*---------------------------------------------------------------------------*/ +/* + *Queue Mode Support + */ +#if LWM2M_QUEUE_MODE_ENABLED +/*---------------------------------------------------------------------------*/ +void +lwm2m_rd_client_restart_client_awake_timer(void) +{ + coap_timer_set(&queue_mode_client_awake_timer, queue_mode_client_awake_time); +} +/*---------------------------------------------------------------------------*/ +uint8_t +lwm2m_rd_client_is_client_awake(void) +{ + return queue_mode_client_awake; +} +/*---------------------------------------------------------------------------*/ +static void +queue_mode_awake_timer_callback(coap_timer_t *timer) +{ + /* Timer has expired, no requests has been received, client can go to sleep */ + LOG_DBG("Queue Mode: Client is SLEEPING at %lu\n", (unsigned long)coap_timer_uptime()); + queue_mode_client_awake = 0; + +/* Define this macro to enter sleep mode depending on the platform */ +#ifdef LWM2M_QUEUE_MODE_SLEEP_MS + LWM2M_QUEUE_MODE_SLEEP_MS(lwm2m_queue_mode_get_sleep_time()); +#endif /* LWM2M_QUEUE_MODE_SLEEP_MS */ + rd_state = QUEUE_MODE_SEND_UPDATE; + coap_timer_set(&rd_timer, lwm2m_queue_mode_get_sleep_time()); +} +/*---------------------------------------------------------------------------*/ +void +lwm2m_rd_client_fsm_execute_queue_mode_awake() +{ + coap_timer_stop(&rd_timer); + rd_state = QUEUE_MODE_AWAKE; + periodic_process(&rd_timer); +} +/*---------------------------------------------------------------------------*/ +void +lwm2m_rd_client_fsm_execute_queue_mode_update() +{ + coap_timer_stop(&rd_timer); + rd_state = QUEUE_MODE_SEND_UPDATE; + periodic_process(&rd_timer); +} +/*---------------------------------------------------------------------------*/ +#endif /* LWM2M_QUEUE_MODE_ENABLED */ +/*---------------------------------------------------------------------------*/ /** @} */ diff --git a/os/services/lwm2m/lwm2m-rd-client.h b/os/services/lwm2m/lwm2m-rd-client.h index 7fba7e0ae..cfc5c549d 100644 --- a/os/services/lwm2m/lwm2m-rd-client.h +++ b/os/services/lwm2m/lwm2m-rd-client.h @@ -40,6 +40,7 @@ * \author * Joakim Eriksson * Niclas Finne + * Carlos Gonzalo Peces */ #ifndef LWM2M_RD_CLIENT_H_ @@ -52,6 +53,7 @@ #define LWM2M_RD_CLIENT_DISCONNECTED 5 #include "lwm2m-object.h" +#include "lwm2m-queue-mode-conf.h" struct lwm2m_session_info; typedef void (*session_callback_t)(struct lwm2m_session_info *session, int status); @@ -75,6 +77,13 @@ void lwm2m_rd_client_init(const char *ep); void lwm2m_rd_client_set_session_callback(session_callback_t cb); +#if LWM2M_QUEUE_MODE_ENABLED +uint8_t lwm2m_rd_client_is_client_awake(void); +void lwm2m_rd_client_restart_client_awake_timer(void); +void lwm2m_rd_client_fsm_execute_queue_mode_awake(); +void lwm2m_rd_client_fsm_execute_queue_mode_update(); +#endif + #ifndef LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN #define LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN 15 #endif /* LWM2M_RD_CLIENT_ASSIGNED_ENDPOINT_MAX_LEN */ diff --git a/os/services/lwm2m/lwm2m-tlv.c b/os/services/lwm2m/lwm2m-tlv.c index 2bda7f8bb..cdadee9f6 100644 --- a/os/services/lwm2m/lwm2m-tlv.c +++ b/os/services/lwm2m/lwm2m-tlv.c @@ -44,6 +44,7 @@ #include #include +#include #include "lwm2m-tlv.h" /* Log configuration */ diff --git a/os/services/rpl-border-router/embedded/Makefile.embedded b/os/services/rpl-border-router/embedded/Makefile.embedded index c62f7df54..8324722fc 100644 --- a/os/services/rpl-border-router/embedded/Makefile.embedded +++ b/os/services/rpl-border-router/embedded/Makefile.embedded @@ -1,9 +1,7 @@ -$(CONTIKI)/tools/tunslip6: $(CONTIKI)/tools/tunslip6.c - (cd $(CONTIKI)/tools && $(MAKE) tunslip6) - PREFIX ?= fd00::1/64 -connect-router: $(CONTIKI)/tools/tunslip6 - sudo $(CONTIKI)/tools/tunslip6 $(PREFIX) -connect-router-cooja: $(CONTIKI)/tools/tunslip6 - sudo $(CONTIKI)/tools/tunslip6 -a 127.0.0.1 $(PREFIX) +connect-router: $(TUNSLIP6) + sudo $(TUNSLIP6) $(PREFIX) + +connect-router-cooja: $(TUNSLIP6) + sudo $(TUNSLIP6) -a 127.0.0.1 $(PREFIX) diff --git a/os/services/rpl-border-router/embedded/slip-bridge.c b/os/services/rpl-border-router/embedded/slip-bridge.c index c40447d7f..d1f97339d 100644 --- a/os/services/rpl-border-router/embedded/slip-bridge.c +++ b/os/services/rpl-border-router/embedded/slip-bridge.c @@ -95,7 +95,7 @@ slip_input_callback(void) int j; /* this is just a test so far... just to see if it works */ uip_buf[0] = '!'; - for(j = 0; j < 8; j++) { + for(j = 0; j < UIP_LLADDR_LEN; j++) { uip_buf[2 + j * 2] = hexchar[uip_lladdr.addr[j] >> 4]; uip_buf[3 + j * 2] = hexchar[uip_lladdr.addr[j] & 15]; } diff --git a/os/services/rpl-border-router/native/Makefile.native b/os/services/rpl-border-router/native/Makefile.native index a225e1666..3f758c1be 100644 --- a/os/services/rpl-border-router/native/Makefile.native +++ b/os/services/rpl-border-router/native/Makefile.native @@ -7,7 +7,7 @@ MAKE_NET = MAKE_NET_IPV6 PREFIX ?= fd00::1/64 connect-router: border-router.native - sudo ./border-router.native $(PREFIX) + sudo rlwrap ./border-router.native $(PREFIX) connect-router-cooja: border-router.native - sudo ./border-router.native -a localhost $(PREFIX) + sudo rlwrap ./border-router.native -a localhost $(PREFIX) diff --git a/os/services/rpl-border-router/native/border-router-cmds.c b/os/services/rpl-border-router/native/border-router-cmds.c index 9d0e2eb9f..aa0d44710 100644 --- a/os/services/rpl-border-router/native/border-router-cmds.c +++ b/os/services/rpl-border-router/native/border-router-cmds.c @@ -46,8 +46,11 @@ #include "shell.h" #include -#define DEBUG DEBUG_NONE -#include "net/ipv6/uip-debug.h" +/*---------------------------------------------------------------------------*/ +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "BR" +#define LOG_LEVEL LOG_LEVEL_NONE uint8_t command_context; @@ -115,7 +118,7 @@ border_router_cmd_handler(const uint8_t *data, int len) { /* handle global repair, etc here */ if(data[0] == '!') { - PRINTF("Got configuration message of type %c\n", data[1]); + LOG_DBG("Got configuration message of type %c\n", data[1]); if(command_context == CMD_CONTEXT_STDIO) { switch(data[1]) { case 'G': @@ -151,7 +154,7 @@ border_router_cmd_handler(const uint8_t *data, int len) /* We need to know that this is from the slip-radio here. */ switch(data[1]) { case 'M': - PRINTF("Setting MAC address\n"); + LOG_DBG("Setting MAC address\n"); border_router_set_mac(&data[2]); return 1; case 'V': @@ -163,7 +166,7 @@ border_router_cmd_handler(const uint8_t *data, int len) } return 1; case 'R': - PRINTF("Packet data report for sid:%d st:%d tx:%d\n", + LOG_DBG("Packet data report for sid:%d st:%d tx:%d\n", data[2], data[3], data[4]); packet_sent(data[2], data[3], data[4]); return 1; @@ -172,7 +175,7 @@ border_router_cmd_handler(const uint8_t *data, int len) } } } else if(data[0] == '?') { - PRINTF("Got request message of type %c\n", data[1]); + LOG_DBG("Got request message of type %c\n", data[1]); if(data[1] == 'M' && command_context == CMD_CONTEXT_STDIO) { uint8_t buf[20]; char *hexchar = "0123456789abcdef"; @@ -180,7 +183,7 @@ border_router_cmd_handler(const uint8_t *data, int len) /* this is just a test so far... just to see if it works */ buf[0] = '!'; buf[1] = 'M'; - for(j = 0; j < 8; j++) { + for(j = 0; j < UIP_LLADDR_LEN; j++) { buf[2 + j * 2] = hexchar[uip_lladdr.addr[j] >> 4]; buf[3 + j * 2] = hexchar[uip_lladdr.addr[j] & 15]; } @@ -226,15 +229,14 @@ PROCESS_THREAD(border_router_cmd_process, ev, data) { static struct pt shell_input_pt; PROCESS_BEGIN(); - PRINTF("Started br-cmd process\n"); shell_init(); while(1) { PROCESS_YIELD(); if(ev == serial_line_event_message && data != NULL) { - PRINTF("Got serial data!!! %s of len: %lu\n", - (char *)data, strlen((char *)data)); + LOG_DBG("Got serial data!!! %s of len: %u\n", + (char *)data, (unsigned)strlen((char *)data)); command_context = CMD_CONTEXT_STDIO; if(cmd_input(data, strlen((char *)data))) { /* Commnand executed - all is fine */ diff --git a/os/services/rpl-border-router/native/border-router-mac.c b/os/services/rpl-border-router/native/border-router-mac.c index bcfb829b7..fbf8b6496 100644 --- a/os/services/rpl-border-router/native/border-router-mac.c +++ b/os/services/rpl-border-router/native/border-router-mac.c @@ -44,13 +44,11 @@ #include "border-router.h" #include -#define DEBUG 0 -#if DEBUG -#include -#define PRINTF(...) printf(__VA_ARGS__) -#else -#define PRINTF(...) -#endif +/*---------------------------------------------------------------------------*/ +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "BR-MAC" +#define LOG_LEVEL LOG_LEVEL_NONE #define MAX_CALLBACKS 16 static int callback_pos; @@ -76,7 +74,7 @@ packet_sent(uint8_t sessionid, uint8_t status, uint8_t tx) packetbuf_attr_copyfrom(callback->attrs, callback->addrs); mac_call_sent_callback(callback->cback, callback->ptr, status, tx); } else { - PRINTF("*** ERROR: too high session id %d\n", sessionid); + LOG_ERR("Session id to high (%d)\n", sessionid); } } /*---------------------------------------------------------------------------*/ @@ -113,11 +111,12 @@ send_packet(mac_callback_t sent, void *ptr) /* Will make it send only DATA packets... for now */ packetbuf_set_attr(PACKETBUF_ATTR_FRAME_TYPE, FRAME802154_DATAFRAME); - /* printf("Sending packet of type: %s \n", get_frame_type(packetbuf_attr(PACKETBUF_ATTR_FRAME_TYPE))); */ + + LOG_INFO("sending packet (%u bytes)\n", packetbuf_datalen()); if(NETSTACK_FRAMER.create() < 0) { /* Failed to allocate space for headers */ - PRINTF("br-rdc: send failed, too large header\n"); + LOG_WARN("send failed, too large header\n"); mac_call_sent_callback(sent, ptr, MAC_TX_ERR_FATAL, 1); } else { /* here we send the data over SLIP to the radio-chip */ @@ -126,7 +125,7 @@ send_packet(mac_callback_t sent, void *ptr) size = packetutils_serialize_atts(&buf[3], sizeof(buf) - 3); #endif if(size < 0 || size + packetbuf_totlen() + 3 > sizeof(buf)) { - PRINTF("br-rdc: send failed, too large header\n"); + LOG_WARN("send failed, too large header\n"); mac_call_sent_callback(sent, ptr, MAC_TX_ERR_FATAL, 1); } else { sid = setup_callback(sent, ptr); @@ -147,7 +146,7 @@ static void packet_input(void) { if(NETSTACK_FRAMER.parse() < 0) { - PRINTF("br-rdc: failed to parse %u\n", packetbuf_datalen()); + LOG_DBG("failed to parse %u\n", packetbuf_datalen()); } else { NETSTACK_NETWORK.input(); } diff --git a/os/services/rpl-border-router/native/border-router-native.c b/os/services/rpl-border-router/native/border-router-native.c index 3da0ef000..2adebe121 100644 --- a/os/services/rpl-border-router/native/border-router-native.c +++ b/os/services/rpl-border-router/native/border-router-native.c @@ -47,8 +47,11 @@ #include "border-router.h" #include "border-router-cmds.h" -#define DEBUG DEBUG_FULL -#include "net/ipv6/uip-debug.h" +/*---------------------------------------------------------------------------*/ +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "BR" +#define LOG_LEVEL LOG_LEVEL_INFO #include @@ -106,7 +109,7 @@ PROCESS_THREAD(border_router_process, ev, data) process_start(&border_router_cmd_process, NULL); - PRINTF("RPL-Border router started\n"); + LOG_INFO("RPL-Border router started\n"); slip_config_handle_arguments(contiki_argc, contiki_argv); @@ -123,12 +126,12 @@ PROCESS_THREAD(border_router_process, ev, data) uip_ipaddr_t prefix; if(uiplib_ipaddrconv((const char *)slip_config_ipaddr, &prefix)) { - PRINTF("Setting prefix "); - PRINT6ADDR(&prefix); - PRINTF("\n"); + LOG_INFO("Setting prefix "); + LOG_INFO_6ADDR(&prefix); + LOG_INFO_("\n"); set_prefix_64(&prefix); } else { - PRINTF("Parse error: %s\n", slip_config_ipaddr); + LOG_ERR("Parse error: %s\n", slip_config_ipaddr); exit(0); } } diff --git a/os/services/rpl-border-router/native/slip-dev.c b/os/services/rpl-border-router/native/slip-dev.c index 63b6f1638..3ccd1db4b 100644 --- a/os/services/rpl-border-router/native/slip-dev.c +++ b/os/services/rpl-border-router/native/slip-dev.c @@ -336,7 +336,7 @@ slip_flushbuf(int fd) if(slip_begin == slip_packet_end) { slip_packet_count--; if(slip_end > slip_packet_end) { - memcpy(slip_buf, slip_buf + slip_packet_end, + memmove(slip_buf, slip_buf + slip_packet_end, slip_end - slip_packet_end); } slip_end -= slip_packet_end; @@ -562,7 +562,7 @@ slip_init(void) slip_send(slipfd, SLIP_END); inslip = fdopen(slipfd, "r"); if(inslip == NULL) { - err(1, "main: fdopen"); + err(1, "slip_init: fdopen"); } } /*---------------------------------------------------------------------------*/ diff --git a/os/services/rpl-border-router/native/tun-bridge.c b/os/services/rpl-border-router/native/tun-bridge.c index a60819b26..289a32185 100644 --- a/os/services/rpl-border-router/native/tun-bridge.c +++ b/os/services/rpl-border-router/native/tun-bridge.c @@ -50,8 +50,11 @@ #include #include -#define DEBUG DEBUG_FULL -#include "net/ipv6/uip-debug.h" +/*---------------------------------------------------------------------------*/ +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "BR" +#define LOG_LEVEL LOG_LEVEL_NONE #ifdef linux #include @@ -202,12 +205,12 @@ tun_init() slip_init(); - PRINTF("Opening tun interface:%s\n", slip_config_tundev); + LOG_INFO("Opening tun interface:%s\n", slip_config_tundev); tunfd = tun_alloc(slip_config_tundev); if(tunfd == -1) { - err(1, "main: open"); + err(1, "tun_init: open"); } select_set_callback(tunfd, &tun_select_callback); @@ -251,7 +254,7 @@ init(void) static int output(void) { - PRINTF("SUT: %u\n", uip_len); + LOG_DBG("SUT: %u\n", uip_len); if(uip_len > 0) { return tun_output(&uip_buf[UIP_LLH_LEN], uip_len); } diff --git a/os/services/shell/shell-commands.c b/os/services/shell/shell-commands.c index 3dbce09f2..e8bb4b6b2 100644 --- a/os/services/shell/shell-commands.c +++ b/os/services/shell/shell-commands.c @@ -45,6 +45,7 @@ #include "contiki.h" #include "shell.h" #include "shell-commands.h" +#include "lib/list.h" #include "sys/log.h" #include "dev/watchdog.h" #include "net/ipv6/uip.h" @@ -76,7 +77,8 @@ static uint16_t curr_ping_datalen; #if TSCH_WITH_SIXTOP static shell_command_6top_sub_cmd_t sixtop_sub_cmd = NULL; #endif /* TSCH_WITH_SIXTOP */ - +static struct shell_command_set_t builtin_shell_command_set; +LIST(shell_command_sets); /*---------------------------------------------------------------------------*/ static const char * ds6_nbr_state_to_str(uint8_t state) @@ -146,6 +148,27 @@ rpl_ocp_to_str(int ocp) } /*---------------------------------------------------------------------------*/ static +PT_THREAD(cmd_rpl_nbr(struct pt *pt, shell_output_func output, char *args)) +{ + PT_BEGIN(pt); + + if(!curr_instance.used || rpl_neighbor_count() == 0) { + SHELL_OUTPUT(output, "RPL neighbors: none\n"); + } else { + rpl_nbr_t *nbr = nbr_table_head(rpl_neighbors); + SHELL_OUTPUT(output, "RPL neighbors:\n"); + while(nbr != NULL) { + char buf[120]; + rpl_neighbor_snprint(buf, sizeof(buf), nbr); + SHELL_OUTPUT(output, "%s\n", buf); + nbr = nbr_table_next(rpl_neighbors, nbr); + } + } + + PT_END(pt); +} +/*---------------------------------------------------------------------------*/ +static PT_THREAD(cmd_rpl_status(struct pt *pt, shell_output_func output, char *args)) { PT_BEGIN(pt); @@ -324,15 +347,16 @@ PT_THREAD(cmd_log(struct pt *pt, shell_output_func output, char *args)) static PT_THREAD(cmd_help(struct pt *pt, shell_output_func output, char *args)) { - struct shell_command_t *cmd_ptr; - + struct shell_command_set_t *set; + const struct shell_command_t *cmd; PT_BEGIN(pt); SHELL_OUTPUT(output, "Available commands:\n"); - cmd_ptr = shell_commands; - while(cmd_ptr->name != NULL) { - SHELL_OUTPUT(output, "%s\n", cmd_ptr->help); - cmd_ptr++; + /* Note: we explicitly don't expend any code space to deal with shadowing */ + for(set = list_head(shell_command_sets); set != NULL; set = list_item_next(set)) { + for(cmd = set->commands; cmd->name != NULL; ++cmd) { + SHELL_OUTPUT(output, "%s\n", cmd->help); + } } PT_END(pt); @@ -594,24 +618,9 @@ PT_THREAD(cmd_routes(struct pt *pt, shell_output_func output, char *args)) SHELL_OUTPUT(output, "Routing links (%u in total):\n", uip_sr_num_nodes()); link = uip_sr_node_head(); while(link != NULL) { - uip_ipaddr_t child_ipaddr; - uip_ipaddr_t parent_ipaddr; - NETSTACK_ROUTING.get_sr_node_ipaddr(&child_ipaddr, link); - NETSTACK_ROUTING.get_sr_node_ipaddr(&parent_ipaddr, link->parent); - SHELL_OUTPUT(output, "-- "); - shell_output_6addr(output, &child_ipaddr); - if(link->parent == NULL) { - memset(&parent_ipaddr, 0, sizeof(parent_ipaddr)); - SHELL_OUTPUT(output, " (DODAG root)"); - } else { - SHELL_OUTPUT(output, " to "); - shell_output_6addr(output, &parent_ipaddr); - } - if(link->lifetime != UIP_SR_INFINITE_LIFETIME) { - SHELL_OUTPUT(output, " (lifetime: %lu seconds)\n", (unsigned long)link->lifetime); - } else { - SHELL_OUTPUT(output, " (lifetime: infinite)\n"); - } + char buf[100]; + uip_sr_link_snprint(buf, sizeof(buf), link); + SHELL_OUTPUT(output, "-- %s\n", buf); link = uip_sr_node_next(link); } } else { @@ -723,12 +732,48 @@ PT_THREAD(cmd_6top(struct pt *pt, shell_output_func output, char *args)) void shell_commands_init(void) { + list_init(shell_command_sets); + list_add(shell_command_sets, &builtin_shell_command_set); /* Set up Ping Reply callback */ uip_icmp6_echo_reply_callback_add(&echo_reply_notification, echo_reply_handler); } /*---------------------------------------------------------------------------*/ -struct shell_command_t shell_commands[] = { +void +shell_command_set_register(struct shell_command_set_t *set) +{ + list_push(shell_command_sets, set); +} +/*---------------------------------------------------------------------------*/ +int +shell_command_set_deregister(struct shell_command_set_t *set) +{ + if(!list_contains(shell_command_sets, set)) { + return !0; + } + list_remove(shell_command_sets, set); + return 0; +} +/*---------------------------------------------------------------------------*/ +const struct shell_command_t * +shell_command_lookup(const char *name) +{ + struct shell_command_set_t *set; + const struct shell_command_t *cmd; + + for(set = list_head(shell_command_sets); + set != NULL; + set = list_item_next(set)) { + for(cmd = set->commands; cmd->name != NULL; ++cmd) { + if(!strcmp(cmd->name, name)) { + return cmd; + } + } + } + return NULL; +} +/*---------------------------------------------------------------------------*/ +const struct shell_command_t builtin_shell_commands[] = { { "help", cmd_help, "'> help': Shows this help" }, { "reboot", cmd_reboot, "'> reboot': Reboot the board by watchdog_reboot()" }, { "ip-addr", cmd_ipaddr, "'> ip-addr': Shows all IPv6 addresses" }, @@ -745,6 +790,7 @@ struct shell_command_t shell_commands[] = { #endif /* UIP_CONF_IPV6_RPL */ #if ROUTING_CONF_RPL_LITE { "rpl-status", cmd_rpl_status, "'> rpl-status': Shows a summary of the current RPL state" }, + { "rpl-nbr", cmd_rpl_nbr, "'> rpl-nbr': Shows the RPL neighbor table" }, #endif /* ROUTING_CONF_RPL_LITE */ { "routes", cmd_routes, "'> routes': Shows the route entries" }, #if MAC_CONF_WITH_TSCH @@ -758,4 +804,8 @@ struct shell_command_t shell_commands[] = { { NULL, NULL, NULL }, }; +static struct shell_command_set_t builtin_shell_command_set = { + .next = NULL, + .commands = builtin_shell_commands, +}; /** @} */ diff --git a/os/services/shell/shell-commands.h b/os/services/shell/shell-commands.h index f89703273..f510e861d 100644 --- a/os/services/shell/shell-commands.h +++ b/os/services/shell/shell-commands.h @@ -53,8 +53,14 @@ struct shell_command_t { const char *help; }; -/* The set of supported commands */ -extern struct shell_command_t shell_commands[]; +struct shell_command_set_t { + struct shell_command_set_t *next; + const struct shell_command_t *const commands; +}; + +void shell_command_set_register(struct shell_command_set_t *); +int shell_command_set_deregister(struct shell_command_set_t *); +const struct shell_command_t *shell_command_lookup(const char *); /** * Initializes Shell-commands module diff --git a/os/services/shell/shell.c b/os/services/shell/shell.c index 1e344dc1a..c219b1903 100644 --- a/os/services/shell/shell.c +++ b/os/services/shell/shell.c @@ -50,40 +50,15 @@ #include "shell-commands.h" #include "net/ipv6/uip.h" #include "net/ipv6/ip64-addr.h" +#include "net/ipv6/uiplib.h" /*---------------------------------------------------------------------------*/ void shell_output_6addr(shell_output_func output, const uip_ipaddr_t *ipaddr) { - uint16_t a; - unsigned int i; - int f; - - if(ipaddr == NULL) { - SHELL_OUTPUT(output, "(NULL IP addr)"); - return; - } - - if(ip64_addr_is_ipv4_mapped_addr(ipaddr)) { - /* Printing IPv4-mapped addresses is done according to RFC 4291 */ - SHELL_OUTPUT(output, "::FFFF:%u.%u.%u.%u", ipaddr->u8[12], ipaddr->u8[13], ipaddr->u8[14], ipaddr->u8[15]); - } else { - for(i = 0, f = 0; i < sizeof(uip_ipaddr_t); i += 2) { - a = (ipaddr->u8[i] << 8) + ipaddr->u8[i + 1]; - if(a == 0 && f >= 0) { - if(f++ == 0) { - SHELL_OUTPUT(output, "::"); - } - } else { - if(f > 0) { - f = -1; - } else if(i > 0) { - SHELL_OUTPUT(output, ":"); - } - SHELL_OUTPUT(output, "%x", a); - } - } - } + char buf[UIPLIB_IPV6_MAX_STR_LEN]; + uiplib_ipaddr_snprint(buf, sizeof(buf), ipaddr); + SHELL_OUTPUT(output, "%s", buf); } /*---------------------------------------------------------------------------*/ void @@ -114,7 +89,7 @@ output_prompt(shell_output_func output) PT_THREAD(shell_input(struct pt *pt, shell_output_func output, const char *cmd)) { static char *args; - static struct shell_command_t *cmd_ptr; + static const struct shell_command_t *cmd_descr = NULL; PT_BEGIN(pt); @@ -130,20 +105,14 @@ PT_THREAD(shell_input(struct pt *pt, shell_output_func output, const char *cmd)) args++; } - /* Lookup for command */ - cmd_ptr = shell_commands; - while(cmd_ptr->name != NULL) { - if(strcmp(cmd, cmd_ptr->name) == 0) { - static struct pt cmd_pt; - PT_SPAWN(pt, &cmd_pt, cmd_ptr->func(&cmd_pt, output, args)); - goto done; - } - cmd_ptr++; + cmd_descr = shell_command_lookup(cmd); + if(cmd_descr != NULL) { + static struct pt cmd_pt; + PT_SPAWN(pt, &cmd_pt, cmd_descr->func(&cmd_pt, output, args)); + } else { + SHELL_OUTPUT(output, "Command not found. Type 'help' for a list of commands\n"); } - SHELL_OUTPUT(output, "Command not found. Type 'help' for a list of commands\n"); - -done: output_prompt(output); PT_END(pt); } diff --git a/os/services/simple-energest/module-macros.h b/os/services/simple-energest/module-macros.h new file mode 100644 index 000000000..f5ae1e890 --- /dev/null +++ b/os/services/simple-energest/module-macros.h @@ -0,0 +1,2 @@ +#define BUILD_WITH_SIMPLE_ENERGEST 1 +#define ENERGEST_CONF_ON 1 diff --git a/os/services/simple-energest/simple-energest.c b/os/services/simple-energest/simple-energest.c new file mode 100644 index 000000000..fc7393bc6 --- /dev/null +++ b/os/services/simple-energest/simple-energest.c @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2018, RISE SICS. + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + */ + +/** +* \addtogroup simple-energest +* @{ +*/ + +/** + * \file + * A process that periodically prints out the time spent in + * radio tx, radio rx, total time and duty cycle. + * + * \author Simon Duquennoy + */ + +#include "contiki.h" +#include "sys/energest.h" +#include "simple-energest.h" +#include +#include + +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "Energest" +#define LOG_LEVEL LOG_LEVEL_INFO + +static unsigned long last_tx, last_rx, last_time, last_cpu, last_lpm, last_deep_lpm; +static unsigned long delta_tx, delta_rx, delta_time, delta_cpu, delta_lpm, delta_deep_lpm; +static unsigned long curr_tx, curr_rx, curr_time, curr_cpu, curr_lpm, curr_deep_lpm; + +PROCESS(simple_energest_process, "Simple Energest"); +/*---------------------------------------------------------------------------*/ +static unsigned long +to_permil(unsigned long delta_metric, unsigned long delta_time) +{ + return (1000ul * (delta_metric)) / delta_time; +} +/*---------------------------------------------------------------------------*/ +static void +simple_energest_step(void) +{ + static unsigned count = 0; + + energest_flush(); + + curr_time = ENERGEST_GET_TOTAL_TIME(); + curr_cpu = energest_type_time(ENERGEST_TYPE_CPU); + curr_lpm = energest_type_time(ENERGEST_TYPE_LPM); + curr_deep_lpm = energest_type_time(ENERGEST_TYPE_DEEP_LPM); + curr_tx = energest_type_time(ENERGEST_TYPE_TRANSMIT); + curr_rx = energest_type_time(ENERGEST_TYPE_LISTEN); + + delta_time = curr_time - last_time; + delta_cpu = curr_cpu - last_cpu; + delta_lpm = curr_lpm - last_lpm; + delta_deep_lpm = curr_deep_lpm - last_deep_lpm; + delta_tx = curr_tx - last_tx; + delta_rx = curr_rx - last_rx; + + last_time = curr_time; + last_cpu = curr_cpu; + last_lpm = curr_lpm; + last_deep_lpm = curr_deep_lpm; + last_tx = curr_tx; + last_rx = curr_rx; + + LOG_INFO("--- Period summary #%u (%lu seconds)\n", count++, delta_time/ENERGEST_SECOND); + LOG_INFO("Total time : %10lu\n", delta_time); + LOG_INFO("CPU : %10lu/%10lu (%lu permil)\n", delta_cpu, delta_time, to_permil(delta_cpu, delta_time)); + LOG_INFO("LPM : %10lu/%10lu (%lu permil)\n", delta_lpm, delta_time, to_permil(delta_lpm, delta_time)); + LOG_INFO("Deep LPM : %10lu/%10lu (%lu permil)\n", delta_deep_lpm, delta_time, to_permil(delta_deep_lpm, delta_time)); + LOG_INFO("Radio Tx : %10lu/%10lu (%lu permil)\n", delta_tx, delta_time, to_permil(delta_tx, delta_time)); + LOG_INFO("Radio Rx : %10lu/%10lu (%lu permil)\n", delta_rx, delta_time, to_permil(delta_rx, delta_time)); + LOG_INFO("Radio total : %10lu/%10lu (%lu permil)\n", delta_tx+delta_rx, delta_time, to_permil(delta_tx+delta_rx, delta_time)); +} +/*---------------------------------------------------------------------------*/ +PROCESS_THREAD(simple_energest_process, ev, data) +{ + static struct etimer periodic_timer; + PROCESS_BEGIN(); + + etimer_set(&periodic_timer, SIMPLE_ENERGEST_PERIOD); + while(1) { + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer)); + etimer_reset(&periodic_timer); + simple_energest_step(); + } + PROCESS_END(); +} +/*---------------------------------------------------------------------------*/ +void +simple_energest_init(void) +{ + energest_flush(); + last_time = ENERGEST_GET_TOTAL_TIME(); + last_cpu = energest_type_time(ENERGEST_TYPE_CPU); + last_lpm = energest_type_time(ENERGEST_TYPE_LPM); + curr_tx = energest_type_time(ENERGEST_TYPE_TRANSMIT); + last_deep_lpm = energest_type_time(ENERGEST_TYPE_DEEP_LPM); + last_rx = energest_type_time(ENERGEST_TYPE_LISTEN); + process_start(&simple_energest_process, NULL); +} + +/** @} */ diff --git a/os/services/simple-energest/simple-energest.h b/os/services/simple-energest/simple-energest.h new file mode 100644 index 000000000..4f7281e9c --- /dev/null +++ b/os/services/simple-energest/simple-energest.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018, RISE SICS. + * 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 Institute 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 INSTITUTE 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 INSTITUTE 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. + * + */ + + /** + * \addtogroup simple-energest + * @{ + */ + + /** + * \file + * A process that periodically prints out the time spent in + * radio tx, radio rx, total time and duty cycle. + * + * \author Simon Duquennoy + */ + +#ifndef SIMPLE_ENERGEST_H_ +#define SIMPLE_ENERGEST_H_ + +/** \brief The period at which Energest statistics will be logged */ +#ifdef SIMPLE_ENERGEST_CONF_PERIOD +#define SIMPLE_ENERGEST_PERIOD SIMPLE_ENERGEST_CONF_PERIOD +#else /* SIMPLE_ENERGEST_CONF_PERIOD */ +#define SIMPLE_ENERGEST_PERIOD (CLOCK_SECOND * 60) +#endif /* SIMPLE_ENERGEST_CONF_PERIOD */ + +/** + * Initialize the deployment module + */ +void simple_energest_init(void); + +#endif /* SIMPLE_ENERGEST_H_ */ +/** @} */ diff --git a/os/services/tsch-cs/Makefile b/os/services/tsch-cs/Makefile new file mode 100644 index 000000000..23e2acb3d --- /dev/null +++ b/os/services/tsch-cs/Makefile @@ -0,0 +1 @@ +CFLAGS += -DBUILD_WITH_TSCH_CS=1 diff --git a/os/services/tsch-cs/tsch-cs.c b/os/services/tsch-cs/tsch-cs.c new file mode 100644 index 000000000..801f74b77 --- /dev/null +++ b/os/services/tsch-cs/tsch-cs.c @@ -0,0 +1,328 @@ +/* + * Copyright (c) 2016-2018, University of Bristol - http://www.bristol.ac.uk + * + * 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 INSTITUTE 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 INSTITUTE 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 + * Source file for TSCH adaptive channel selection + * \author + * Atis Elsts + */ + +#include "tsch.h" +#include "tsch-stats.h" +#include "tsch-cs.h" + +/* Log configuration */ +#include "sys/log.h" +#define LOG_MODULE "TSCH CS" +#define LOG_LEVEL LOG_LEVEL_MAC + +/*---------------------------------------------------------------------------*/ + +/* Allow to change only 1 channel at once */ +#define TSCH_CS_MAX_CHANNELS_CHANGED 1 + +/* Do not up change channels more frequently than this */ +#define TSCH_CS_MIN_UPDATE_INTERVAL_SEC 60 + +/* Do not change channels if the difference in qualities is below this */ +#define TSCH_CS_HYSTERESIS (TSCH_STATS_BINARY_SCALING_FACTOR / 10) + +/* After removing a channel from the sequence, do not add it back at least this time */ +#define TSCH_CS_BLACKLIST_DURATION_SEC (5 * 60) + +/* A potential for change detected? */ +static bool recaculation_requested; + +/* Time (in seconds) when channels were marked as busy; 0 if they are not busy */ +static uint32_t tsch_cs_busy_since[TSCH_STATS_NUM_CHANNELS]; + +/* + * The following variables are kept in order to avoid completely migrating away + * from the initial hopping sequence (as then new nodes would not be able to join). + * The invariant is: tsch_cs_initial_bitmap & tsch_cs_current_bitmap != 0 + */ +/* The bitmap with the initial channels */ +static tsch_cs_bitmap_t tsch_cs_initial_bitmap; +/* The bitmap with the current channels */ +static tsch_cs_bitmap_t tsch_cs_current_bitmap; + +/* structure for sorting */ +struct tsch_cs_quality { + /* channel number */ + uint8_t channel; + /* the higher, the better */ + tsch_stat_t metric; +}; +/*---------------------------------------------------------------------------*/ +static inline bool +tsch_cs_bitmap_contains(tsch_cs_bitmap_t bitmap, uint8_t channel) +{ + return (1 << (channel - TSCH_STATS_FIRST_CHANNEL)) & bitmap; +} +/*---------------------------------------------------------------------------*/ +static inline tsch_cs_bitmap_t +tsch_cs_bitmap_set(tsch_cs_bitmap_t bitmap, uint8_t channel) +{ + return (1 << (channel - TSCH_STATS_FIRST_CHANNEL)) | bitmap; +} +/*---------------------------------------------------------------------------*/ +static tsch_cs_bitmap_t +tsch_cs_bitmap_calc(void) +{ + tsch_cs_bitmap_t result = 0; + int i; + for(i = 0; i < tsch_hopping_sequence_length.val; ++i) { + result = tsch_cs_bitmap_set(result, tsch_hopping_sequence[i]); + } + return result; +} +/*---------------------------------------------------------------------------*/ +void +tsch_cs_adaptations_init(void) +{ + tsch_cs_initial_bitmap = tsch_cs_bitmap_calc(); + tsch_cs_current_bitmap = tsch_cs_initial_bitmap; +} +/*---------------------------------------------------------------------------*/ +/* Sort the elements to that the channels with the best metrics are in the front */ +static void +tsch_cs_bubble_sort(struct tsch_cs_quality *qualities) +{ + int i, j; + struct tsch_cs_quality tmp; + + for(i = 0; i < TSCH_STATS_NUM_CHANNELS; ++i) { + for(j = 0; j + 1 < TSCH_STATS_NUM_CHANNELS; ++j) { + if(qualities[j].metric < qualities[j+1].metric){ + tmp = qualities[j]; + qualities[j] = qualities[j+1]; + qualities[j+1] = tmp; + } + } + } +} +/*---------------------------------------------------------------------------*/ +/* Select a single, currently unused, good enough channel. Returns 0xff on failure. */ +static uint8_t +tsch_cs_select_replacement(uint8_t old_channel, tsch_stat_t old_ewma, + struct tsch_cs_quality *qualities, uint8_t is_in_sequence[]) +{ + int i; + uint32_t now = clock_seconds(); + tsch_cs_bitmap_t bitmap = tsch_cs_bitmap_set(0, old_channel); + + /* Don't want to replace a channel if the improvement is miniscule (< 10%) */ + old_ewma += TSCH_CS_HYSTERESIS; + + /* iterate up to -1 because we know that at least one of the channels is bad */ + for(i = 0; i < TSCH_STATS_NUM_CHANNELS - 1; ++i) { + /* select a replacement candidate */ + uint8_t candidate = qualities[i].channel; + + if(qualities[i].metric < TSCH_CS_FREE_THRESHOLD) { + /* This channel is not good enough. + * since we know that the other channels in the sorted list are even worse, + * it makes sense to return immediately rather than to continue t + */ + LOG_DBG("ch %u: busy\n", candidate); + return 0xff; + } + + if(qualities[i].metric < old_ewma) { + /* not good enough to replace */ + LOG_DBG("ch %u: hysteresis check failed\n", candidate); + return 0xff; + } + + /* already in the current TSCH hopping sequence? */ + if(is_in_sequence[candidate - TSCH_STATS_FIRST_CHANNEL] != 0xff) { + LOG_DBG("ch %u: in seq\n", candidate); + continue; + } + + /* ignore this candidate if too recently blacklisted */ + if(tsch_cs_busy_since[candidate - TSCH_STATS_FIRST_CHANNEL] != 0 + && tsch_cs_busy_since[candidate - TSCH_STATS_FIRST_CHANNEL] + TSCH_CS_BLACKLIST_DURATION_SEC > now) { + LOG_DBG("ch %u: recent bl\n", candidate); + continue; + } + + /* check if removing the old channel would break our hopping sequence invariant */ + if(bitmap == (tsch_cs_initial_bitmap & tsch_cs_current_bitmap)) { + /* the channel is the only one that belongs to both */ + if(!tsch_cs_bitmap_contains(tsch_cs_initial_bitmap, candidate)) { + /* the candidate is not in the initial sequence; not acceptable */ + continue; + } + } + + return candidate; + } + + return 0xff; +} +/*---------------------------------------------------------------------------*/ +bool +tsch_cs_process(void) +{ + int i; + bool try_replace; + bool has_replaced; + struct tsch_cs_quality qualities[TSCH_STATS_NUM_CHANNELS]; + uint8_t is_channel_busy[TSCH_STATS_NUM_CHANNELS]; + uint8_t is_in_sequence[TSCH_STATS_NUM_CHANNELS]; + static uint32_t last_time_changed; + + if(!recaculation_requested) { + /* nothing to do */ + return false; + } + + if(last_time_changed != 0 && last_time_changed + TSCH_CS_MIN_UPDATE_INTERVAL_SEC > clock_seconds()) { + /* too soon */ + return false; + } + + /* reset the flag */ + recaculation_requested = false; + + for(i = 0; i < TSCH_STATS_NUM_CHANNELS; ++i) { + qualities[i].channel = i + TSCH_STATS_FIRST_CHANNEL; + qualities[i].metric = tsch_stats.channel_free_ewma[i]; + } + + /* bubble sort the channels */ + tsch_cs_bubble_sort(qualities); + + /* start with the threshold values */ + for(i = 0; i < TSCH_STATS_NUM_CHANNELS; ++i) { + is_channel_busy[i] = (tsch_stats.channel_free_ewma[i] < TSCH_CS_FREE_THRESHOLD); + } + memset(is_in_sequence, 0xff, sizeof(is_in_sequence)); + for(i = 0; i < tsch_hopping_sequence_length.val; ++i) { + uint8_t channel = tsch_hopping_sequence[i]; + is_in_sequence[channel - TSCH_STATS_FIRST_CHANNEL] = i; + } + + /* mark the first N channels as "good" - there is nothing better to select */ + for(i = 0; i < tsch_hopping_sequence_length.val; ++i) { + is_channel_busy[qualities[i].channel - TSCH_STATS_FIRST_CHANNEL] = 0; + } + + for(i = 0; i < TSCH_STATS_NUM_CHANNELS; ++i) { + uint8_t ci = qualities[i].channel - TSCH_STATS_FIRST_CHANNEL; + (void)ci; + LOG_DBG("ch %u q %u busy %u in seq %u\n", + qualities[i].channel, + qualities[i].metric, + is_channel_busy[ci], + is_in_sequence[ci] == 0xff ? 0 : 1); + } + + try_replace = false; + for(i = 0; i < tsch_hopping_sequence_length.val; ++i) { + uint8_t channel = tsch_hopping_sequence[i]; + if(is_channel_busy[channel - TSCH_STATS_FIRST_CHANNEL]) { + try_replace = true; + } + } + if(!try_replace) { + LOG_DBG("cs: not replacing\n"); + return false; + } + + has_replaced = false; + for(i = TSCH_STATS_NUM_CHANNELS - 1; i >= tsch_hopping_sequence_length.val; --i) { + if(is_in_sequence[qualities[i].channel - TSCH_STATS_FIRST_CHANNEL] != 0xff) { + /* found the worst channel; it must be busy */ + uint8_t channel = qualities[i].channel; + tsch_stat_t ewma_metric = qualities[i].metric; + uint8_t replacement = tsch_cs_select_replacement(channel, ewma_metric, + qualities, is_in_sequence); + uint8_t position = is_in_sequence[channel - TSCH_STATS_FIRST_CHANNEL]; + + if(replacement != 0xff) { + printf("\ncs: replacing channel %u %u (%u) with %u\n", + channel, tsch_hopping_sequence[position], position, replacement); + /* mark the old channel as busy */ + tsch_cs_busy_since[channel - TSCH_STATS_FIRST_CHANNEL] = clock_seconds(); + /* do the actual replacement in the global TSCH HS variable */ + tsch_hopping_sequence[position] = replacement; + has_replaced = true; + /* recalculate the hopping sequence bitmap */ + tsch_cs_current_bitmap = tsch_cs_bitmap_calc(); + } + break; /* replace just one at once */ + } + } + + if(has_replaced) { + last_time_changed = clock_seconds(); + return true; + } + + LOG_DBG("cs: no changes\n"); + return false; +} +/*---------------------------------------------------------------------------*/ +void +tsch_cs_channel_stats_updated(uint8_t updated_channel, uint16_t old_busyness_metric) +{ + uint8_t index; + bool old_is_busy; + bool new_is_busy; + + /* Enable this only on the coordinator node */ + if(!tsch_is_coordinator) { + return; + } + + /* Do not try to adapt before enough information has been learned */ + if(clock_seconds() < TSCH_CS_LEARNING_PERIOD_SEC) { + return; + } + + index = tsch_stats_channel_to_index(updated_channel); + + old_is_busy = (old_busyness_metric < TSCH_CS_FREE_THRESHOLD); + new_is_busy = (tsch_stats.channel_free_ewma[index] < TSCH_CS_FREE_THRESHOLD); + + if(old_is_busy != new_is_busy) { + /* the status of the channel has changed*/ + recaculation_requested = true; + + } else if(new_is_busy) { + /* run the reselection algorithm iff the channel is both (1) bad and (2) in use */ + if(tsch_cs_bitmap_contains(tsch_cs_current_bitmap, updated_channel)) { + /* the channel is in use and is busy */ + recaculation_requested = true; + } + } +} diff --git a/os/services/tsch-cs/tsch-cs.h b/os/services/tsch-cs/tsch-cs.h new file mode 100644 index 000000000..900e77339 --- /dev/null +++ b/os/services/tsch-cs/tsch-cs.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2016-2018, University of Bristol - http://www.bristol.ac.uk + * + * 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 INSTITUTE 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 INSTITUTE 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 + * Header file for TSCH adaptive channel selection + * \author + * Atis Elsts + */ + +#ifndef __TSCH_CS_H__ +#define __TSCH_CS_H__ + +#include "contiki.h" +#include + +/* If `channel_free_ewma` value is less than this, the channel is considered busy */ +#ifdef TSCH_CS_CONF_FREE_THRESHOLD +#define TSCH_CS_FREE_THRESHOLD TSCH_CS_CONF_FREE_THRESHOLD +#else +/* < 85% free */ +#define TSCH_CS_FREE_THRESHOLD ((tsch_stat_t)(85ul * TSCH_STATS_BINARY_SCALING_FACTOR / 100)) +#endif + +#define TSCH_CS_LEARNING_PERIOD_SEC 30 + +/** + * \brief Initializes the TSCH hopping sequence selection module. + */ +void tsch_cs_adaptations_init(void); + +/** + * \brief Signal the need to potentially update the TSCH hopping sequence. + * \param updated_channel The channel with the updated RSSI measurement + * \param old_busyness_metric The EWMA value of the "channel busy" status before the last RSSI measurement + */ +void tsch_cs_channel_stats_updated(uint8_t updated_channel, uint16_t old_busyness_metric); + +/** + * \brief Potentially update the TSCH hopping sequence + * \return true if the hopping sequence was updated, false otherwise + */ +bool tsch_cs_process(void); + + +/* A bit corresponds to a channel; `uint16_t` value is OK for up to 16 channels. */ +typedef uint16_t tsch_cs_bitmap_t; + + +#endif /* __TSCH_CS_H__ */ diff --git a/os/storage/antelope/aql-adt.c b/os/storage/antelope/aql-adt.c index d78f3f3c5..e07bffd7a 100644 --- a/os/storage/antelope/aql-adt.c +++ b/os/storage/antelope/aql-adt.c @@ -90,6 +90,21 @@ aql_clear(aql_adt_t *adt) memset(adt->aggregators, 0, sizeof(adt->aggregators)); } +db_result_t +aql_add_relation(aql_adt_t *adt, const char *name) +{ + if(adt->relation_count >= AQL_RELATION_LIMIT) { + return DB_LIMIT_ERROR; + } + + strncpy(adt->relations[adt->relation_count], name, + sizeof(adt->relations[0]) - 1); + adt->relations[adt->relation_count][sizeof(adt->relations[0]) - 1] = '\0'; + adt->relation_count++; + + return DB_OK; +} + db_result_t aql_add_attribute(aql_adt_t *adt, char *name, domain_t domain, unsigned element_size, int processed_only) diff --git a/os/storage/antelope/aql-lexer.c b/os/storage/antelope/aql-lexer.c index 4bdefecf2..0510385b5 100644 --- a/os/storage/antelope/aql-lexer.c +++ b/os/storage/antelope/aql-lexer.c @@ -207,6 +207,10 @@ next_string(lexer_t *lexer, const char *s) *lexer->token = STRING_VALUE; lexer->input = end + 1; /* Skip the closing delimiter. */ + if(length > DB_MAX_ELEMENT_SIZE - 1) { + length = DB_MAX_ELEMENT_SIZE - 1; + } + memcpy(lexer->value, s, length); (*lexer->value)[length] = '\0'; @@ -236,6 +240,10 @@ next_token(lexer_t *lexer, const char *s) *lexer->token = IDENTIFIER; + if(length > DB_MAX_ELEMENT_SIZE - 1) { + length = DB_MAX_ELEMENT_SIZE - 1; + } + memcpy(lexer->value, s, length); (*lexer->value)[length] = '\0'; diff --git a/os/storage/antelope/aql-parser.c b/os/storage/antelope/aql-parser.c index 503833b0a..f65a8a6ce 100644 --- a/os/storage/antelope/aql-parser.c +++ b/os/storage/antelope/aql-parser.c @@ -269,8 +269,10 @@ PARSER(operand) NEXT; switch(TOKEN) { case IDENTIFIER: - lvm_register_variable(VALUE, LVM_LONG); - lvm_set_variable(&p, VALUE); + if(LVM_ERROR(lvm_register_variable(VALUE, LVM_LONG)) || + LVM_ERROR(lvm_set_variable(&p, VALUE))) { + RETURN(SYNTAX_ERROR); + } AQL_ADD_PROCESSING_ATTRIBUTE(adt, VALUE); break; case STRING_VALUE: @@ -278,7 +280,9 @@ PARSER(operand) case FLOAT_VALUE: break; case INTEGER_VALUE: - lvm_set_long(&p, *(long *)lexer->value); + if(LVM_ERROR(lvm_set_long(&p, *(long *)lexer->value))) { + RETURN(SYNTAX_ERROR); + } break; default: RETURN(SYNTAX_ERROR); @@ -340,7 +344,9 @@ PARSER(expr) default: RETURN(SYNTAX_ERROR); } - lvm_set_op(&p, op); + if(LVM_ERROR(lvm_set_op(&p, op))) { + RETURN(SYNTAX_ERROR); + } lvm_set_end(&p, saved_end); } @@ -389,7 +395,9 @@ PARSER(comparison) RETURN(SYNTAX_ERROR); } - lvm_set_relation(&p, rel); + if(LVM_ERROR(lvm_set_relation(&p, rel))) { + RETURN(SYNTAX_ERROR); + } lvm_set_end(&p, saved_end); if(!PARSE(expr)) { @@ -422,7 +430,9 @@ PARSER(where) connective = TOKEN == AND ? LVM_AND : LVM_OR; saved_end = lvm_shift_for_operator(&p, saved_end); - lvm_set_relation(&p, connective); + if(LVM_ERROR(lvm_set_relation(&p, connective))) { + RETURN(SYNTAX_ERROR); + } lvm_set_end(&p, saved_end); NEXT; diff --git a/os/storage/antelope/aql.h b/os/storage/antelope/aql.h index ab29f7e5d..4b898c4ac 100644 --- a/os/storage/antelope/aql.h +++ b/os/storage/antelope/aql.h @@ -188,10 +188,10 @@ typedef struct aql_adt aql_adt_t; #define AQL_SET_FLAG(adt, flag) (((adt)->flags) |= (flag)) #define AQL_GET_FLAGS(adt) ((adt)->flags) -#define AQL_ADD_RELATION(adt, rel) \ - strcpy((adt)->relations[(adt)->relation_count++], (rel)) #define AQL_RELATION_COUNT(adt) ((adt)->relation_count) -#define AQL_ADD_ATTRIBUTE(adt, attr, dom, size) \ +#define AQL_ADD_RELATION(adt, name) \ + aql_add_relation(adt, name) +#define AQL_ADD_ATTRIBUTE(adt, attr, dom, size) \ aql_add_attribute(adt, attr, dom, size, 0) #define AQL_ADD_PROCESSING_ATTRIBUTE(adt, attr) \ aql_add_attribute((adt), (attr), DOMAIN_UNSPECIFIED, 0, 1) @@ -211,6 +211,7 @@ void lexer_rewind(lexer_t *); void aql_clear(aql_adt_t *adt); aql_status_t aql_parse(aql_adt_t *adt, char *query_string); +db_result_t aql_add_relation(aql_adt_t *adt, const char *name); db_result_t aql_add_attribute(aql_adt_t *adt, char *name, domain_t domain, unsigned element_size, int processed_only); diff --git a/os/storage/antelope/db-options.h b/os/storage/antelope/db-options.h index 2be415f4e..ca8587071 100644 --- a/os/storage/antelope/db-options.h +++ b/os/storage/antelope/db-options.h @@ -108,7 +108,7 @@ /* The maximum size of the LVM bytecode compiled from a single database query. */ #ifndef DB_VM_BYTECODE_SIZE -#define DB_VM_BYTECODE_SIZE 128 +#define DB_VM_BYTECODE_SIZE 256 #endif /* DB_VM_BYTECODE_SIZE */ /*----------------------------------------------------------------------------*/ diff --git a/os/storage/antelope/lvm.c b/os/storage/antelope/lvm.c index 731da1622..7abed8d27 100644 --- a/os/storage/antelope/lvm.c +++ b/os/storage/antelope/lvm.c @@ -82,10 +82,10 @@ typedef struct derivation derivation_t; /* Registered variables for a LVM expression. Their values may be changed between executions of the expression. */ -static variable_t variables[LVM_MAX_VARIABLE_ID - 1]; +static variable_t variables[LVM_MAX_VARIABLE_ID]; /* Range derivations of variables that are used for index searches. */ -static derivation_t derivations[LVM_MAX_VARIABLE_ID - 1]; +static derivation_t derivations[LVM_MAX_VARIABLE_ID]; #if DEBUG static void @@ -187,7 +187,7 @@ eval_expr(lvm_instance_t *p, operator_t op, operand_t *result) get_operand(p, &operand[i]); break; default: - return SEMANTIC_ERROR; + return LVM_SEMANTIC_ERROR; } value[i] = operand_to_long(&operand[i]); } @@ -204,18 +204,18 @@ eval_expr(lvm_instance_t *p, operator_t op, operand_t *result) break; case LVM_DIV: if(value[1] == 0) { - return MATH_ERROR; + return LVM_MATH_ERROR; } result_value = value[0] / value[1]; break; default: - return EXECUTION_ERROR; + return LVM_EXECUTION_ERROR; } result->type = LVM_LONG; result->value.l = result_value; - return TRUE; + return LVM_TRUE; } static int @@ -236,7 +236,7 @@ eval_logic(lvm_instance_t *p, operator_t *op) for(i = 0; i < arguments; i++) { type = get_type(p); if(type != LVM_CMP_OP) { - return SEMANTIC_ERROR; + return LVM_SEMANTIC_ERROR; } operator = get_operator(p); logic_result[i] = eval_logic(p, operator); @@ -248,9 +248,9 @@ eval_logic(lvm_instance_t *p, operator_t *op) if(*op == LVM_NOT) { return !logic_result[0]; } else if(*op == LVM_AND) { - return logic_result[0] == TRUE && logic_result[1] == TRUE; + return logic_result[0] == LVM_TRUE && logic_result[1] == LVM_TRUE; } else { - return logic_result[0] == TRUE || logic_result[1] == TRUE; + return logic_result[0] == LVM_TRUE || logic_result[1] == LVM_TRUE; } } @@ -268,7 +268,7 @@ eval_logic(lvm_instance_t *p, operator_t *op) get_operand(p, &operand); break; default: - return SEMANTIC_ERROR; + return LVM_SEMANTIC_ERROR; } result[i] = operand_to_long(&operand); } @@ -294,7 +294,7 @@ eval_logic(lvm_instance_t *p, operator_t *op) break; } - return EXECUTION_ERROR; + return LVM_EXECUTION_ERROR; } void @@ -334,7 +334,8 @@ lvm_shift_for_operator(lvm_instance_t *p, lvm_ip_t end) old_end = p->end; - if(p->end + sizeof(operator_t) > p->size || end >= old_end) { + if(p->end + sizeof(operator_t) + sizeof(node_type_t) > p->size || + end >= old_end) { p->error = __LINE__; return 0; } @@ -369,13 +370,6 @@ lvm_set_end(lvm_instance_t *p, lvm_ip_t end) return old_end; } -void -lvm_set_type(lvm_instance_t *p, node_type_t type) -{ - *(node_type_t *)(p->code + p->end) = type; - p->end += sizeof(type); -} - lvm_status_t lvm_execute(lvm_instance_t *p) { @@ -384,14 +378,14 @@ lvm_execute(lvm_instance_t *p) lvm_status_t status; p->ip = 0; - status = EXECUTION_ERROR; + status = LVM_EXECUTION_ERROR; type = get_type(p); switch(type) { case LVM_CMP_OP: operator = get_operator(p); status = eval_logic(p, operator); if(!LVM_ERROR(status)) { - PRINTF("The statement is %s\n", status == TRUE ? "true" : "false"); + PRINTF("The statement is %s\n", status == LVM_TRUE ? "true" : "false"); } else { PRINTF("Execution error: %d\n", (int)status); } @@ -403,31 +397,80 @@ lvm_execute(lvm_instance_t *p) return status; } -void +lvm_status_t +lvm_set_type(lvm_instance_t *p, node_type_t type) +{ + if(p->end + sizeof(node_type_t) >= DB_VM_BYTECODE_SIZE) { + PRINTF("Error: overflow in lvm_set_type\n"); + return LVM_STACK_OVERFLOW; + } + + *(node_type_t *)(p->code + p->end) = type; + p->end += sizeof(type); + return LVM_TRUE; +} + +lvm_status_t lvm_set_op(lvm_instance_t *p, operator_t op) { - lvm_set_type(p, LVM_ARITH_OP); + lvm_status_t status; + + status = lvm_set_type(p, LVM_ARITH_OP); + if(status != LVM_TRUE) { + return status; + } + + if(p->end + sizeof(op) >= DB_VM_BYTECODE_SIZE) { + PRINTF("Error: overflow in lvm_set_op\n"); + return LVM_STACK_OVERFLOW; + } + memcpy(&p->code[p->end], &op, sizeof(op)); p->end += sizeof(op); + return LVM_TRUE; } -void +lvm_status_t lvm_set_relation(lvm_instance_t *p, operator_t op) { - lvm_set_type(p, LVM_CMP_OP); + lvm_status_t status; + + status = lvm_set_type(p, LVM_CMP_OP); + if(status != LVM_TRUE) { + return status; + } + + if(p->end + sizeof(op) >= DB_VM_BYTECODE_SIZE) { + PRINTF("Error: overflow in lvm_set_relation\n"); + return LVM_STACK_OVERFLOW; + } + memcpy(&p->code[p->end], &op, sizeof(op)); p->end += sizeof(op); + return LVM_TRUE; } -void +lvm_status_t lvm_set_operand(lvm_instance_t *p, operand_t *op) { - lvm_set_type(p, LVM_OPERAND); + lvm_status_t status; + + status = lvm_set_type(p, LVM_OPERAND); + if(status != LVM_TRUE) { + return status; + } + + if(p->end + sizeof(*op) >= DB_VM_BYTECODE_SIZE) { + PRINTF("Error: overflow in lvm_set_operand\n"); + return LVM_STACK_OVERFLOW; + } + memcpy(&p->code[p->end], op, sizeof(*op)); p->end += sizeof(*op); + return LVM_TRUE; } -void +lvm_status_t lvm_set_long(lvm_instance_t *p, long l) { operand_t op; @@ -435,7 +478,7 @@ lvm_set_long(lvm_instance_t *p, long l) op.type = LVM_LONG; op.value.l = l; - lvm_set_operand(p, &op); + return lvm_set_operand(p, &op); } lvm_status_t @@ -446,7 +489,7 @@ lvm_register_variable(char *name, operand_type_t type) id = lookup(name); if(id == LVM_MAX_VARIABLE_ID) { - return VARIABLE_LIMIT_REACHED; + return LVM_VARIABLE_LIMIT_REACHED; } var = &variables[id]; @@ -456,7 +499,7 @@ lvm_register_variable(char *name, operand_type_t type) var->type = type; } - return TRUE; + return LVM_TRUE; } lvm_status_t @@ -466,25 +509,28 @@ lvm_set_variable_value(char *name, operand_value_t value) id = lookup(name); if(id == LVM_MAX_VARIABLE_ID) { - return INVALID_IDENTIFIER; + return LVM_INVALID_IDENTIFIER; } + variables[id].value = value; - return TRUE; + return LVM_TRUE; } -void +lvm_status_t lvm_set_variable(lvm_instance_t *p, char *name) { operand_t op; variable_id_t id; id = lookup(name); - if(id < LVM_MAX_VARIABLE_ID) { - PRINTF("var id = %d\n", id); - op.type = LVM_VARIABLE; - op.value.id = id; - lvm_set_operand(p, &op); + if(id == LVM_MAX_VARIABLE_ID) { + return LVM_INVALID_IDENTIFIER; } + + PRINTF("var id = %d\n", id); + op.type = LVM_VARIABLE; + op.value.id = id; + return lvm_set_operand(p, &op); } void @@ -598,7 +644,7 @@ derive_relation(lvm_instance_t *p, derivation_t *local_derivations) derivation_t d2[LVM_MAX_VARIABLE_ID]; if(*operator != LVM_AND && *operator != LVM_OR) { - return DERIVATION_ERROR; + return LVM_DERIVATION_ERROR; } PRINTF("Attempting to infer ranges from a logical connective\n"); @@ -608,7 +654,7 @@ derive_relation(lvm_instance_t *p, derivation_t *local_derivations) if(LVM_ERROR(derive_relation(p, d1)) || LVM_ERROR(derive_relation(p, d2))) { - return DERIVATION_ERROR; + return LVM_DERIVATION_ERROR; } if(*operator == LVM_AND) { @@ -616,7 +662,7 @@ derive_relation(lvm_instance_t *p, derivation_t *local_derivations) } else if(*operator == LVM_OR) { create_union(local_derivations, d1, d2); } - return TRUE; + return LVM_TRUE; } for(i = 0; i < 2; i++) { @@ -626,18 +672,18 @@ derive_relation(lvm_instance_t *p, derivation_t *local_derivations) get_operand(p, &operand[i]); break; default: - return DERIVATION_ERROR; + return LVM_DERIVATION_ERROR; } } if(operand[0].type == LVM_VARIABLE && operand[1].type == LVM_VARIABLE) { - return DERIVATION_ERROR; + return LVM_DERIVATION_ERROR; } /* Determine which of the operands that is the variable. */ if(operand[0].type == LVM_VARIABLE) { if(operand[1].type == LVM_VARIABLE) { - return DERIVATION_ERROR; + return LVM_DERIVATION_ERROR; } variable_id = operand[0].value.id; value = &operand[1].value; @@ -647,7 +693,7 @@ derive_relation(lvm_instance_t *p, derivation_t *local_derivations) } if(variable_id >= LVM_MAX_VARIABLE_ID) { - return DERIVATION_ERROR; + return LVM_DERIVATION_ERROR; } PRINTF("variable id %d, value %ld\n", variable_id, *(long *)value); @@ -675,12 +721,12 @@ derive_relation(lvm_instance_t *p, derivation_t *local_derivations) derivation->max.l = value->l; break; default: - return DERIVATION_ERROR; + return LVM_DERIVATION_ERROR; } derivation->derived = 1; - return TRUE; + return LVM_TRUE; } lvm_status_t @@ -700,12 +746,12 @@ lvm_get_derived_range(lvm_instance_t *p, char *name, if(derivations[i].derived) { *min = derivations[i].min; *max = derivations[i].max; - return TRUE; + return LVM_TRUE; } - return DERIVATION_ERROR; + return LVM_DERIVATION_ERROR; } } - return INVALID_IDENTIFIER; + return LVM_INVALID_IDENTIFIER; } #if DEBUG @@ -755,7 +801,8 @@ print_operand(lvm_instance_t *p, lvm_ip_t index) switch(operand.type) { case LVM_VARIABLE: - if(operand.value.id >= LVM_MAX_VARIABLE_ID || variables[operand.value.id].name == NULL) { + if(operand.value.id >= LVM_MAX_VARIABLE_ID || + variables[operand.value.id].name == NULL) { PRINTF("var(id:%d):?? ", operand.value.id); } else { PRINTF("var(%s):%ld ", variables[operand.value.id].name, diff --git a/os/storage/antelope/lvm.h b/os/storage/antelope/lvm.h index 0969501d9..6b56d6bd1 100644 --- a/os/storage/antelope/lvm.h +++ b/os/storage/antelope/lvm.h @@ -45,16 +45,16 @@ #include "db-options.h" enum lvm_status { - FALSE = 0, - TRUE = 1, - INVALID_IDENTIFIER = 2, - SEMANTIC_ERROR = 3, - MATH_ERROR = 4, - STACK_OVERFLOW = 5, - TYPE_ERROR = 6, - VARIABLE_LIMIT_REACHED = 7, - EXECUTION_ERROR = 8, - DERIVATION_ERROR = 9 + LVM_FALSE = 0, + LVM_TRUE = 1, + LVM_INVALID_IDENTIFIER = 2, + LVM_SEMANTIC_ERROR = 3, + LVM_MATH_ERROR = 4, + LVM_STACK_OVERFLOW = 5, + LVM_TYPE_ERROR = 6, + LVM_VARIABLE_LIMIT_REACHED = 7, + LVM_EXECUTION_ERROR = 8, + LVM_DERIVATION_ERROR = 9 }; typedef enum lvm_status lvm_status_t; @@ -135,10 +135,10 @@ lvm_ip_t lvm_jump_to_operand(lvm_instance_t *p); lvm_ip_t lvm_shift_for_operator(lvm_instance_t *p, lvm_ip_t end); lvm_ip_t lvm_get_end(lvm_instance_t *p); lvm_ip_t lvm_set_end(lvm_instance_t *p, lvm_ip_t end); -void lvm_set_op(lvm_instance_t *p, operator_t op); -void lvm_set_relation(lvm_instance_t *p, operator_t op); -void lvm_set_operand(lvm_instance_t *p, operand_t *op); -void lvm_set_long(lvm_instance_t *p, long l); -void lvm_set_variable(lvm_instance_t *p, char *name); +lvm_status_t lvm_set_op(lvm_instance_t *p, operator_t op); +lvm_status_t lvm_set_relation(lvm_instance_t *p, operator_t op); +lvm_status_t lvm_set_operand(lvm_instance_t *p, operand_t *op); +lvm_status_t lvm_set_long(lvm_instance_t *p, long l); +lvm_status_t lvm_set_variable(lvm_instance_t *p, char *name); #endif /* LVM_H */ diff --git a/os/storage/antelope/relation.c b/os/storage/antelope/relation.c index c8757bf08..0e939a068 100644 --- a/os/storage/antelope/relation.c +++ b/os/storage/antelope/relation.c @@ -813,9 +813,9 @@ relation_process_select(void *handle_ptr) } } - wanted_result = TRUE; + wanted_result = LVM_TRUE; if(AQL_GET_FLAGS(adt) & AQL_FLAG_INVERSE_LOGIC) { - wanted_result = FALSE; + wanted_result = LVM_FALSE; } /* Check whether the given predicate is true for this tuple. */ diff --git a/os/sys/ctimer.h b/os/sys/ctimer.h index 2d391a5e5..e7e463ac4 100644 --- a/os/sys/ctimer.h +++ b/os/sys/ctimer.h @@ -76,7 +76,8 @@ struct ctimer { * is the exact time that the callback timer last * expired. Therefore, this function will cause the timer * to be stable over time, unlike the ctimer_restart() - * function. + * function. If this is executed before the timer expired, + * this function has no effect. * * \sa ctimer_restart() */ diff --git a/os/sys/etimer.h b/os/sys/etimer.h index 02ad5df11..2922b9aa2 100644 --- a/os/sys/etimer.h +++ b/os/sys/etimer.h @@ -107,7 +107,8 @@ void etimer_set(struct etimer *et, clock_time_t interval); * is the exact time that the event timer last * expired. Therefore, this function will cause the timer * to be stable over time, unlike the etimer_restart() - * function. + * function. If this is executed before the timer expired, + * this function has no effect. * * \sa etimer_restart() */ diff --git a/os/sys/log-conf.h b/os/sys/log-conf.h index 24cf21f71..17d8562cc 100644 --- a/os/sys/log-conf.h +++ b/os/sys/log-conf.h @@ -46,7 +46,8 @@ #ifndef __LOG_CONF_H__ #define __LOG_CONF_H__ -/* Log only the last 16 bytes of link-layer and IPv6 addresses */ +/* Log only the last 16 bytes of link-layer and IPv6 addresses (or, if) + * the deployment module is enabled, the node IDs */ #ifdef LOG_CONF_WITH_COMPACT_ADDR #define LOG_WITH_COMPACT_ADDR LOG_CONF_WITH_COMPACT_ADDR #else /* LOG_CONF_WITH_COMPACT_ADDR */ diff --git a/os/sys/log.c b/os/sys/log.c index 90709ec5f..abb960b98 100644 --- a/os/sys/log.c +++ b/os/sys/log.c @@ -50,6 +50,8 @@ #include "sys/log.h" #include "net/ipv6/ip64-addr.h" +#include "net/ipv6/uiplib.h" +#include "deployment/deployment.h" int curr_log_level_rpl = LOG_CONF_LEVEL_RPL; int curr_log_level_tcpip = LOG_CONF_LEVEL_TCPIP; @@ -84,53 +86,41 @@ struct log_module all_modules[] = { void log_6addr(const uip_ipaddr_t *ipaddr) { - uint16_t a; - unsigned int i; - int f; - + char buf[UIPLIB_IPV6_MAX_STR_LEN]; + uiplib_ipaddr_snprint(buf, sizeof(buf), ipaddr); + LOG_OUTPUT("%s", buf); +} +/*---------------------------------------------------------------------------*/ +int +log_6addr_compact_snprint(char *buf, size_t size, const uip_ipaddr_t *ipaddr) +{ if(ipaddr == NULL) { - LOG_OUTPUT("(NULL IP addr)"); - return; - } - - if(ip64_addr_is_ipv4_mapped_addr(ipaddr)) { - /* Printing IPv4-mapped addresses is done according to RFC 4291 */ - LOG_OUTPUT("::FFFF:%u.%u.%u.%u", ipaddr->u8[12], ipaddr->u8[13], ipaddr->u8[14], ipaddr->u8[15]); + return snprintf(buf, size, "6A-NULL"); } else { - for(i = 0, f = 0; i < sizeof(uip_ipaddr_t); i += 2) { - a = (ipaddr->u8[i] << 8) + ipaddr->u8[i + 1]; - if(a == 0 && f >= 0) { - if(f++ == 0) { - LOG_OUTPUT("::"); - } - } else { - if(f > 0) { - f = -1; - } else if(i > 0) { - LOG_OUTPUT(":"); - } - LOG_OUTPUT("%x", a); - } + char *prefix = NULL; + if(uip_is_addr_mcast(ipaddr)) { + prefix = "6M"; + } else if(uip_is_addr_linklocal(ipaddr)) { + prefix = "6L"; + } else { + prefix = "6G"; } +#if BUILD_WITH_DEPLOYMENT + return snprintf(buf, size, "%s-%03u", prefix, deployment_id_from_iid(ipaddr)); +#else /* BUILD_WITH_DEPLOYMENT */ + return snprintf(buf, size, "%s-%04x", prefix, UIP_HTONS(ipaddr->u16[sizeof(uip_ipaddr_t)/2-1])); +#endif /* BUILD_WITH_DEPLOYMENT */ } } /*---------------------------------------------------------------------------*/ void log_6addr_compact(const uip_ipaddr_t *ipaddr) { - if(ipaddr == NULL) { - LOG_OUTPUT("6A-NULL"); - } else if(uip_is_addr_mcast(ipaddr)) { - LOG_OUTPUT("6M-%04x", UIP_HTONS(ipaddr->u16[sizeof(uip_ipaddr_t)/2-1])); - } else if(uip_is_addr_linklocal(ipaddr)) { - LOG_OUTPUT("6L-%04x", UIP_HTONS(ipaddr->u16[sizeof(uip_ipaddr_t)/2-1])); - } else { - LOG_OUTPUT("6G-%04x", UIP_HTONS(ipaddr->u16[sizeof(uip_ipaddr_t)/2-1])); - } + char buf[8]; + log_6addr_compact_snprint(buf, sizeof(buf), ipaddr); + LOG_OUTPUT("%s", buf); } - #endif /* NETSTACK_CONF_WITH_IPV6 */ - /*---------------------------------------------------------------------------*/ void log_lladdr(const linkaddr_t *lladdr) @@ -155,7 +145,15 @@ log_lladdr_compact(const linkaddr_t *lladdr) if(lladdr == NULL || linkaddr_cmp(lladdr, &linkaddr_null)) { LOG_OUTPUT("LL-NULL"); } else { +#if BUILD_WITH_DEPLOYMENT + LOG_OUTPUT("LL-%04u", deployment_id_from_lladdr(lladdr)); +#else /* BUILD_WITH_DEPLOYMENT */ +#if LINKADDR_SIZE == 8 LOG_OUTPUT("LL-%04x", UIP_HTONS(lladdr->u16[LINKADDR_SIZE/2-1])); +#elif LINKADDR_SIZE == 2 + LOG_OUTPUT("LL-%04x", UIP_HTONS(lladdr->u16)); +#endif +#endif /* BUILD_WITH_DEPLOYMENT */ } } /*---------------------------------------------------------------------------*/ diff --git a/os/sys/log.h b/os/sys/log.h index e27a3007e..0f5f840d2 100644 --- a/os/sys/log.h +++ b/os/sys/log.h @@ -194,6 +194,17 @@ void log_6addr(const uip_ipaddr_t *ipaddr); */ void log_6addr_compact(const uip_ipaddr_t *ipaddr); +/** + * Write at most size - 1 characters of the IP address to the output string, + * in a compact representation. The output is always null-terminated, unless + * size is 0. + * + * \param buf A pointer to an output string with at least size bytes. + * \param size The max number of characters to write to the output string. + * \param ipaddr A pointer to a uip_ipaddr_t that will be printed with printf(). + */ +int log_6addr_compact_snprint(char *buf, size_t size, const uip_ipaddr_t *ipaddr); + #endif /* NETSTACK_CONF_WITH_IPV6 */ /** diff --git a/arch/platform/sky/apps/burn-nodeid.c b/os/sys/node-id.c similarity index 59% rename from arch/platform/sky/apps/burn-nodeid.c rename to os/sys/node-id.c index 128ba2ba9..2fd52f8dc 100644 --- a/arch/platform/sky/apps/burn-nodeid.c +++ b/os/sys/node-id.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, Swedish Institute of Computer Science. + * Copyright (c) 2018, RISE SICS. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,49 +32,25 @@ /** * \file - * A program for burning a node ID into the flash ROM of a Tmote Sky node. + * Node-id management * \author - * Adam Dunkels + * Simon Duquennoy */ -#include "dev/leds.h" -#include "dev/watchdog.h" -#include "sys/node-id.h" #include "contiki.h" -#include "sys/etimer.h" +#include "sys/node-id.h" +#include "net/linkaddr.h" +#include "services/deployment/deployment.h" -#include +uint16_t node_id = 0; -static struct etimer etimer; - -PROCESS(burn_process, "Burn node id"); -AUTOSTART_PROCESSES(&burn_process); -/*---------------------------------------------------------------------------*/ -PROCESS_THREAD(burn_process, ev, data) -{ - PROCESS_BEGIN(); - - etimer_set(&etimer, 5*CLOCK_SECOND); - PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); - - watchdog_stop(); - leds_on(LEDS_RED); -#if NODEID - printf("Burning node id %d\n", NODEID); - node_id_burn(NODEID); - leds_on(LEDS_BLUE); - node_id_restore(); - printf("Restored node id %d\n", node_id); -#else -#error "burn-nodeid must be compiled with nodeid=" - node_id_restore(); - printf("Restored node id %d\n", node_id); -#endif - leds_off(LEDS_RED + LEDS_BLUE); - watchdog_start(); - while(1) { - PROCESS_WAIT_EVENT(); - } - PROCESS_END(); +void +node_id_init(void) { +#if BUILD_WITH_DEPLOYMENT + deployment_init(); +#else /* BUILD_WITH_DEPLOYMENT */ + /* Initialize with a default value derived from linkaddr */ + node_id = linkaddr_node_addr.u8[LINKADDR_SIZE - 1] + + (linkaddr_node_addr.u8[LINKADDR_SIZE - 2] << 8); +#endif /* BUILD_WITH_DEPLOYMENT */ } -/*---------------------------------------------------------------------------*/ diff --git a/os/sys/node-id.h b/os/sys/node-id.h index 0b6ebe6b1..58909ddaa 100644 --- a/os/sys/node-id.h +++ b/os/sys/node-id.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, Swedish Institute of Computer Science. + * Copyright (c) 2018, RISE SICS. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,16 +28,28 @@ * * This file is part of the Contiki operating system. * - * Author: Adam Dunkels - * */ + /** + * \addtogroup node-id + * @{ + * + * \file + * Node-id (simple 16-bit identifiers) handling + * \author Simon Duquennoy + * + */ + #ifndef NODE_ID_H_ #define NODE_ID_H_ -void node_id_restore(void); -void node_id_burn(unsigned short node_id); - -extern unsigned short node_id; +/* A global variable that hosts the node ID */ +extern uint16_t node_id; +/** + * Initialize the node ID. Must be called after initialized of linkaddr + */ +void node_id_init(void); #endif /* NODE_ID_H_ */ + /** @} */ + diff --git a/os/sys/rtimer.h b/os/sys/rtimer.h index 95d11c33d..260f08950 100644 --- a/os/sys/rtimer.h +++ b/os/sys/rtimer.h @@ -54,12 +54,37 @@ #define RTIMER_H_ #include "contiki.h" +#include "dev/watchdog.h" +#include -#ifndef RTIMER_CLOCK_DIFF -typedef unsigned short rtimer_clock_t; -#define RTIMER_CLOCK_DIFF(a,b) ((signed short)((a)-(b))) -#endif /* RTIMER_CLOCK_DIFF */ +/** \brief The rtimer size (in bytes) */ +#ifdef RTIMER_CONF_CLOCK_SIZE +#define RTIMER_CLOCK_SIZE RTIMER_CONF_CLOCK_SIZE +#else /* RTIMER_CONF_CLOCK_SIZE */ +/* Default: 32bit rtimer*/ +#define RTIMER_CLOCK_SIZE 4 +#endif /* RTIMER_CONF_CLOCK_SIZE */ +#if RTIMER_CLOCK_SIZE == 2 +/* 16-bit rtimer */ +typedef uint16_t rtimer_clock_t; +#define RTIMER_CLOCK_DIFF(a,b) ((int16_t)((a)-(b))) + +#elif RTIMER_CLOCK_SIZE == 4 +/* 32-bit rtimer */ +typedef uint32_t rtimer_clock_t; +#define RTIMER_CLOCK_DIFF(a, b) ((int32_t)((a) - (b))) + +#elif RTIMER_CLOCK_SIZE == 8 +/* 64-bit rtimer */ +typedef uint64_t rtimer_clock_t; +#define RTIMER_CLOCK_DIFF(a,b) ((int64_t)((a)-(b))) + +#else +#error Unsupported rtimer size (check RTIMER_CLOCK_SIZE) +#endif + +#define RTIMER_CLOCK_MAX ((rtimer_clock_t)-1) #define RTIMER_CLOCK_LT(a, b) (RTIMER_CLOCK_DIFF((a),(b)) < 0) #include "rtimer-arch.h" @@ -163,6 +188,26 @@ void rtimer_arch_schedule(rtimer_clock_t t); #define RTIMER_GUARD_TIME (RTIMER_ARCH_SECOND >> 14) #endif /* RTIMER_CONF_GUARD_TIME */ +/** \brief Busy-wait until a condition. Start time is t0, max wait time is max_time */ +#define RTIMER_BUSYWAIT_UNTIL_ABS(cond, t0, max_time) \ + ({ \ + bool c; \ + while(!(c = cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), (t0) + (max_time))) { \ + watchdog_periodic(); \ + } \ + c; \ + }) + +/** \brief Busy-wait until a condition for at most max_time */ +#define RTIMER_BUSYWAIT_UNTIL(cond, max_time) \ + ({ \ + rtimer_clock_t t0 = RTIMER_NOW(); \ + RTIMER_BUSYWAIT_UNTIL_ABS(cond, t0, max_time); \ + }) + +/** \brief Busy-wait for a fixed duration */ +#define RTIMER_BUSYWAIT(duration) RTIMER_BUSYWAIT_UNTIL(0, duration) + #endif /* RTIMER_H_ */ /** @} */ diff --git a/os/sys/stimer.c b/os/sys/stimer.c index 1301dc41e..007587e83 100644 --- a/os/sys/stimer.c +++ b/os/sys/stimer.c @@ -77,7 +77,8 @@ stimer_set(struct stimer *t, unsigned long interval) * given to the stimer_set() function. The start point of the interval * is the exact time that the timer last expired. Therefore, this * function will cause the timer to be stable over time, unlike the - * stimer_restart() function. + * stimer_restart() function. If this is executed before the + * timer expired, this function has no effect. * * \param t A pointer to the timer. * @@ -86,7 +87,9 @@ stimer_set(struct stimer *t, unsigned long interval) void stimer_reset(struct stimer *t) { - t->start += t->interval; + if(stimer_expired(t)) { + t->start += t->interval; + } } /*---------------------------------------------------------------------------*/ /** diff --git a/os/sys/timer.c b/os/sys/timer.c index 1eeae64de..b99aa4127 100644 --- a/os/sys/timer.c +++ b/os/sys/timer.c @@ -74,9 +74,8 @@ timer_set(struct timer *t, clock_time_t interval) * given to the timer_set() function. The start point of the interval * is the exact time that the timer last expired. Therefore, this * function will cause the timer to be stable over time, unlike the - * timer_restart() function. - * - * \note Must not be executed before timer expired + * timer_restart() function. If this is executed before the + * timer expired, this function has no effect. * * \param t A pointer to the timer. * \sa timer_restart() @@ -84,7 +83,9 @@ timer_set(struct timer *t, clock_time_t interval) void timer_reset(struct timer *t) { - t->start += t->interval; + if(timer_expired(t)) { + t->start += t->interval; + } } /*---------------------------------------------------------------------------*/ /** diff --git a/tests/00-doxygen/Makefile b/tests/00-documentation/Makefile similarity index 60% rename from tests/00-doxygen/Makefile rename to tests/00-documentation/Makefile index 3d99c5d00..ea0aa85b4 100644 --- a/tests/00-doxygen/Makefile +++ b/tests/00-documentation/Makefile @@ -24,35 +24,56 @@ # 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. +TOOLS_DIR = ../../tools -DOCDIR=../../tools/doxygen +DOXYGEN = doxygen +DOXYGEN_DIR = $(TOOLS_DIR)/doxygen +DOXYGEN_LOG = $(DOXYGEN).log +DOXYGEN_ERR = $(DOXYGEN).err + +RAEDTHEDOCS = readthedocs +READTHEDOCS_DIR = $(TOOLS_DIR)/readthedocs +READTHEDOCS_LOG = $(RAEDTHEDOCS).log +READTHEDOCS_ERR = $(RAEDTHEDOCS).err + +CLEAN_TARGETS += $(DOXYGEN_LOG) $(DOXYGEN_ERR) +CLEAN_TARGETS += $(READTHEDOCS_LOG) $(READTHEDOCS_ERR) all: clean summary doxygen: - @make -C $(DOCDIR) 2> doxygen.err > /dev/null + -@$(MAKE) -C $(DOXYGEN_DIR) 2> $(DOXYGEN_ERR) > /dev/null -summary: doxygen +readthedocs: + -@$(MAKE) -C $(READTHEDOCS_DIR) 2> $(READTHEDOCS_ERR) > /dev/null + +summary: doxygen readthedocs @( \ 1> summary; \ - if [ -s doxygen.err ] ; then \ - echo "Doxygen: TEST FAIL" | tee summary; \ + if [ -s $(DOXYGEN_ERR) ] ; then \ + echo "Doxygen: TEST FAIL" | tee -a summary; \ echo "Errors:"; \ - cat doxygen.err; \ + cat $(DOXYGEN_ERR); \ fi ; \ - if [ -s $(DOCDIR)/doxygen.log ] ; then \ - echo "Doxygen: TEST FAIL" | tee summary; \ + if [ -s $(DOXYGEN_DIR)/doxygen.log ] ; then \ + echo "Doxygen: TEST FAIL" | tee -a summary; \ echo "Warnings:"; \ - cat $(DOCDIR)/doxygen.log; \ + cat $(DOXYGEN_DIR)/doxygen.log; \ + fi ; \ + if [ -s $(READTHEDOCS_ERR) ] ; then \ + echo "Readthedocs: TEST FAIL" | tee -a summary; \ + echo "Errors:"; \ + cat $(READTHEDOCS_ERR); \ fi ; \ if [ ! -s summary ] ; then \ - echo "Doxygen: TEST OK (no warning nor error)" | tee summary; \ + echo "Documentation: TEST OK (no warning nor error)" | tee summary; \ fi ; \ ) - @rm doxygen.err + @rm -f $(CLEAN_TARGETS) @echo "========== Summary ==========" @cat summary clean: - @rm -f summary doxygen.err - @make -C $(DOCDIR) clean + @rm -f summary $(CLEAN_TARGETS) + @$(MAKE) -C $(DOXYGEN_DIR) clean + @$(MAKE) -C $(READTHEDOCS_DIR) clean diff --git a/tests/01-compile-base/Makefile b/tests/01-compile-base/Makefile index 67346c086..09f89418d 100644 --- a/tests/01-compile-base/Makefile +++ b/tests/01-compile-base/Makefile @@ -7,7 +7,6 @@ hello-world/native:MAKE_NET=MAKE_NET_NULLNET \ hello-world/native:MAKE_ROUTING=MAKE_ROUTING_RPL_CLASSIC \ hello-world/sky \ storage/eeprom-test/native \ -multicast/sky \ libs/logging/native \ libs/energest/native \ libs/energest/sky \ @@ -16,6 +15,8 @@ libs/data-structures/sky \ libs/stack-check/sky \ lwm2m-ipso-objects/native \ lwm2m-ipso-objects/native:MAKE_WITH_DTLS=1 \ +lwm2m-ipso-objects/native:DEFINES=LWM2M_Q_MODE_CONF_ENABLED=1 \ +lwm2m-ipso-objects/native:DEFINES=LWM2M_Q_MODE_CONF_ENABLED=1,LWM2M_Q_MODE_CONF_INCLUDE_DYNAMIC_ADAPTATION=1 \ rpl-udp/sky \ rpl-border-router/native \ rpl-border-router/native:MAKE_ROUTING=MAKE_ROUTING_RPL_CLASSIC \ @@ -23,6 +24,8 @@ rpl-border-router/sky \ slip-radio/sky \ libs/ipv6-hooks/sky \ nullnet/native \ +nullnet/sky \ +nullnet/sky:MAKE_MAC=MAKE_MAC_TSCH \ mqtt-client/native \ coap/coap-example-client/native \ coap/coap-example-server/native \ diff --git a/tests/02-compile-arm-ports-01/Makefile b/tests/02-compile-arm-ports-01/Makefile index 5e73c4ecb..aaebab164 100644 --- a/tests/02-compile-arm-ports-01/Makefile +++ b/tests/02-compile-arm-ports-01/Makefile @@ -24,6 +24,7 @@ dev/gpio-hal/srf06-cc26xx:BOARD=sensortag/cc2650 \ dev/gpio-hal/srf06-cc26xx:BOARD=launchpad/cc1310 \ dev/gpio-hal/srf06-cc26xx:BOARD=launchpad/cc1350 \ dev/gpio-hal/srf06-cc26xx:BOARD=launchpad/cc2650 \ +dev/gpio-hal/srf06-cc26xx:BOARD=launchpad/cc2640r2 \ dev/leds/srf06-cc26xx:BOARD=srf06/cc13xx \ dev/leds/srf06-cc26xx:BOARD=srf06/cc26xx \ dev/leds/srf06-cc26xx:BOARD=sensortag/cc1350 \ @@ -31,10 +32,45 @@ dev/leds/srf06-cc26xx:BOARD=sensortag/cc2650 \ dev/leds/srf06-cc26xx:BOARD=launchpad/cc1310 \ dev/leds/srf06-cc26xx:BOARD=launchpad/cc1350 \ dev/leds/srf06-cc26xx:BOARD=launchpad/cc2650 \ +dev/leds/srf06-cc26xx:BOARD=launchpad/cc2640r2 \ 6tisch/etsi-plugtest-2017/srf06-cc26xx:BOARD=launchpad/cc2650 \ mqtt-client/srf06-cc26xx:BOARD=srf06/cc26xx \ mqtt-client/srf06-cc26xx:BOARD=launchpad/cc2650 \ mqtt-client/srf06-cc26xx:BOARD=sensortag/cc2650 \ +hello-world/simplelink:BOARD=launchpad/cc26x2r1 \ +hello-world/simplelink:BOARD=sensortag/cc2650 \ +nullnet/simplelink:BOARD=sensortag/cc2650 \ +rpl-border-router/simplelink:BOARD=launchpad/cc26x2r1 \ +sensniff/simplelink:BOARD=launchpad/cc26x2r1 \ +dev/gpio-hal/simplelink:BOARD=launchpad/cc1310 \ +dev/gpio-hal/simplelink:BOARD=launchpad/cc1312r1 \ +dev/gpio-hal/simplelink:BOARD=launchpad/cc1350 \ +dev/gpio-hal/simplelink:BOARD=launchpad/cc1350-4 \ +dev/gpio-hal/simplelink:BOARD=launchpad/cc1352p1 \ +dev/gpio-hal/simplelink:BOARD=launchpad/cc1352p-2 \ +dev/gpio-hal/simplelink:BOARD=launchpad/cc1352p-4 \ +dev/gpio-hal/simplelink:BOARD=launchpad/cc1352r1 \ +dev/gpio-hal/simplelink:BOARD=launchpad/cc26x2r1 \ +dev/gpio-hal/simplelink:BOARD=sensortag/cc1350 \ +dev/gpio-hal/simplelink:BOARD=sensortag/cc2650 \ +dev/gpio-hal/simplelink:BOARD=srf06/cc13x0 \ +dev/gpio-hal/simplelink:BOARD=srf06/cc26x0 \ +dev/leds/simplelink:BOARD=launchpad/cc1310 \ +dev/leds/simplelink:BOARD=launchpad/cc1312r1 \ +dev/leds/simplelink:BOARD=launchpad/cc1350 \ +dev/leds/simplelink:BOARD=launchpad/cc1350-4 \ +dev/leds/simplelink:BOARD=launchpad/cc1352p1 \ +dev/leds/simplelink:BOARD=launchpad/cc1352p-2 \ +dev/leds/simplelink:BOARD=launchpad/cc1352p-4 \ +dev/leds/simplelink:BOARD=launchpad/cc1352r1 \ +dev/leds/simplelink:BOARD=launchpad/cc26x2r1 \ +dev/leds/simplelink:BOARD=sensortag/cc1350 \ +dev/leds/simplelink:BOARD=sensortag/cc2650 \ +dev/leds/simplelink:BOARD=srf06/cc13x0 \ +dev/leds/simplelink:BOARD=srf06/cc26x0 \ +mqtt-client/simplelink:BOARD=launchpad/cc26x2r1 \ +mqtt-client/simplelink:BOARD=sensortag/cc2650:DEFINES=BOARD_CONF_SENSORS_DISABLE=1,TI_SPI_CONF_ENABLE=0 \ +mqtt-client/simplelink:BOARD=srf06/cc26x0:DEFINES=BOARD_CONF_SENSORS_DISABLE=1,TI_SPI_CONF_ENABLE=0 \ mqtt-client/cc2538dk \ storage/cfs-coffee/cc2538dk \ sensniff/cc2538dk \ @@ -43,6 +79,7 @@ coap/coap-example-client/cc2538dk \ coap/coap-example-server/cc2538dk \ slip-radio/cc2538dk \ lwm2m-ipso-objects/cc2538dk \ +lwm2m-ipso-objects/cc2538dk:DEFINES=LWM2M_Q_MODE_CONF_ENABLED=1 \ multicast/cc2538dk \ dev/gpio-hal/cc2538dk \ dev/leds/cc2538dk \ @@ -52,6 +89,8 @@ platform-specific/cc2538-common/pka/cc2538dk \ hello-world/cc2538dk \ rpl-border-router/cc2538dk \ rpl-border-router/cc2538dk:MAKE_ROUTING=MAKE_ROUTING_RPL_CLASSIC \ +6tisch/simple-node/cc2538dk \ +6tisch/simple-node/cc2538dk:MAKE_WITH_SECURITY=1,MAKE_WITH_ORCHESTRA=1 \ hello-world/nrf52dk \ platform-specific/nrf52dk/coap-demo/coap-server/nrf52dk \ platform-specific/nrf52dk/coap-demo/coap-client/nrf52dk:SERVER_IPV6_EP=ffff \ diff --git a/tests/03-compile-arm-ports-02/Makefile b/tests/03-compile-arm-ports-02/Makefile index db016afaa..655967e1b 100644 --- a/tests/03-compile-arm-ports-02/Makefile +++ b/tests/03-compile-arm-ports-02/Makefile @@ -17,6 +17,8 @@ coap/coap-example-server/zoul \ multicast/zoul \ lwm2m-ipso-objects/zoul \ lwm2m-ipso-objects/zoul:MAKE_WITH_DTLS=1 \ +lwm2m-ipso-objects/zoul:DEFINES=LWM2M_Q_MODE_CONF_ENABLED=1 \ +lwm2m-ipso-objects/zoul:DEFINES=LWM2M_Q_MODE_CONF_ENABLED=1,LWM2M_Q_MODE_CONF_INCLUDE_DYNAMIC_ADAPTATION=1\ hello-world/zoul \ sensniff/zoul \ sensniff/zoul:ZOUL_CONF_SUB_GHZ_SNIFFER=1 \ @@ -26,6 +28,7 @@ storage/antelope-shell/zoul \ 6tisch/simple-node/zoul:MAKE_WITH_ORCHESTRA=1 \ 6tisch/simple-node/zoul:MAKE_WITH_SECURITY=1 \ libs/logging/zoul \ +libs/logging/zoul:MAKE_MAC=MAKE_MAC_TSCH \ 6tisch/etsi-plugtest-2017/zoul:BOARD=remote \ 6tisch/6p-packet/zoul \ 6tisch/sixtop/zoul \ @@ -34,8 +37,10 @@ libs/timers/zoul \ libs/energest/zoul \ libs/trickle-library/zoul \ libs/data-structures/zoul \ +libs/ipv6-uipbuf/zoul \ nullnet/zoul \ slip-radio/zoul \ +benchmarks/rpl-req-resp/zoul \ dev/gpio-hal/zoul:BOARD=remote-reva \ dev/gpio-hal/zoul:BOARD=remote-revb \ dev/gpio-hal/zoul:BOARD=firefly-reva \ @@ -61,6 +66,11 @@ dev/gpio-hal/openmote-cc2538 \ dev/leds/openmote-cc2538 \ rpl-border-router/openmote-cc2538 \ libs/ipv6-hooks/openmote-cc2538 \ +libs/shell/openmote-cc2538 \ +libs/simple-energest/openmote-cc2538 \ +libs/deployment/openmote-cc2538 \ +6tisch/simple-node/openmote-cc2538 \ +6tisch/simple-node/openmote-cc2538:MAKE_WITH_SECURITY=1,MAKE_WITH_ORCHESTRA=1 \ TOOLS= diff --git a/tests/05-compile-tools/Makefile b/tests/05-compile-tools/Makefile index 43f84405a..6377d6674 100644 --- a/tests/05-compile-tools/Makefile +++ b/tests/05-compile-tools/Makefile @@ -25,7 +25,7 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. -TOOLS=tools tools/sky tools/jn516x +TOOLS=tools/serial-io BASEDIR=../../ TESTLOGS=$(subst /,__,$(patsubst %,%.testlog, $(TOOLS))) diff --git a/tests/07-simulation-base/code-data-structures/test-data-structures.c b/tests/07-simulation-base/code-data-structures/test-data-structures.c index dc4d8bb5b..da3833dc3 100644 --- a/tests/07-simulation-base/code-data-structures/test-data-structures.c +++ b/tests/07-simulation-base/code-data-structures/test-data-structures.c @@ -156,6 +156,19 @@ UNIT_TEST(test_list) UNIT_TEST_ASSERT(tail->next == NULL); UNIT_TEST_ASSERT(list_length(lst) == 4); + /* + * Check that list contains elements 0, 1, 2, 3 + * and not others + * 0 --> 1 --> 2 --> 3 --> NULL + */ + UNIT_TEST_ASSERT(list_contains(lst, &elements[0])); + UNIT_TEST_ASSERT(list_contains(lst, &elements[1])); + UNIT_TEST_ASSERT(list_contains(lst, &elements[2])); + UNIT_TEST_ASSERT(list_contains(lst, &elements[3])); + int i; + for(i=4; i 1 --> 2 --> NULL diff --git a/tests/08-native-runs/01-test-data-structures.sh b/tests/08-native-runs/01-test-data-structures.sh index 790235638..2343756fe 100755 --- a/tests/08-native-runs/01-test-data-structures.sh +++ b/tests/08-native-runs/01-test-data-structures.sh @@ -1,4 +1,5 @@ #!/bin/bash +source ../utils.sh # Contiki directory CONTIKI=$1 @@ -16,7 +17,7 @@ sleep 2 echo "Closing native node" sleep 2 -pgrep $CODE | xargs kill -9 +kill_bg $CPID if grep -q "=check-me= FAILED" $CODE.log ; then echo "==== make.log ====" ; cat make.log; diff --git a/tests/08-native-runs/02-mqtt-client.sh b/tests/08-native-runs/02-mqtt-client.sh new file mode 100755 index 000000000..cb1ee937a --- /dev/null +++ b/tests/08-native-runs/02-mqtt-client.sh @@ -0,0 +1,79 @@ +#!/bin/bash +source ../utils.sh + +# Contiki directory +CONTIKI=$1 + +# Example code directory +CODE_DIR=$CONTIKI/examples/mqtt-client/ +CODE=mqtt-client + +CLIENT_LOG=$CODE.log +CLIENT_TESTLOG=$CODE.testlog +CLIENT_ERR=$CODE.err +MOSQ_SUB_LOG=mosquitto_sub.log +MOSQ_SUB_ERR=mosquitto_sub.err + +# Start mosquitto server +echo "Starting mosquitto daemon" +mosquitto &> /dev/null & +MOSQID=$! +sleep 2 + +# Start mosquitto_sub client. Subscribe +echo "Starting mosquitto subscriber" +mosquitto_sub -t iot-2/evt/status/fmt/json > $MOSQ_SUB_LOG 2> $MOSQ_SUB_ERR & +MSUBID=$! +sleep 2 + +# Starting Contiki-NG native node +echo "Starting native node" +make -C $CODE_DIR TARGET=native \ + DEFINES=MQTT_CLIENT_CONF_ORG_ID=\\\"travis-test\\\",MQTT_CLIENT_CONF_LOG_LEVEL=LOG_LEVEL_DBG \ + > make.log 2> make.err +sudo $CODE_DIR/$CODE.native > $CLIENT_LOG 2> $CLIENT_ERR & +CPID=$! + +# The mqtt-client will publish every 30 secs. Wait for 45 +sleep 45 + +# Send a publish to the mqtt client +mosquitto_pub -m "1" -t iot-2/cmd/leds/fmt/json + +echo "Closing native node" +sleep 2 +kill_bg $CPID + +echo "Stopping mosquitto daemon" +kill_bg $MOSQID + +echo "Stopping mosquitto subscriber" +kill_bg $MSUBID + +# Success criteria: +# * mosquitto_sub output not empty +# * mqtt-client.native output contains "MQTT SUB" +SUB_RCV=`grep "MQTT SUB" $CLIENT_LOG` +if [ -s "$MOSQ_SUB_LOG" -a -n "$SUB_RCV" ] +then + cp $CLIENT_LOG $CODE.testlog + printf "%-32s TEST OK\n" "$CODE" | tee $CODE.testlog; +else + echo "==== make.log ====" ; cat make.log; + echo "==== make.err ====" ; cat make.err; + echo "==== $CLIENT_LOG ====" ; cat $CLIENT_LOG; + echo "==== $CLIENT_ERR ====" ; cat $CLIENT_ERR; + echo "==== $MOSQ_SUB_LOG ====" ; cat $MOSQ_SUB_LOG; + echo "==== $MOSQ_SUB_ERR ====" ; cat $MOSQ_SUB_ERR; + + printf "%-32s TEST FAIL\n" "$CODE" | tee $CODE.testlog; +fi + +rm make.log +rm make.err +rm $CLIENT_LOG $CLIENT_ERR +rm $MOSQ_SUB_LOG $MOSQ_SUB_ERR + +# We do not want Make to stop -> Return 0 +# The Makefile will check if a log contains FAIL at the end +exit 0 diff --git a/tests/09-ipv6/01-ping-lla-csma-w-rpl.csc b/tests/09-ipv6/01-ping-lla-csma-w-rpl.csc new file mode 100644 index 000000000..0a6e3a376 --- /dev/null +++ b/tests/09-ipv6/01-ping-lla-csma-w-rpl.csc @@ -0,0 +1,108 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/powertracker + + My simulation + 1.0 + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype787 + Cooja Mote Type #1 + [CONTIKI_DIR]/tests/09-ipv6/code/node.c + make clean + make WITH_CSMA=1 node.cooja + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + + org.contikios.cooja.interfaces.Position + 14.03051207883138 + 82.02801380504546 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 1 + + + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + ip-nbr~;ping fe80::202:2:2:2~;ip-nbr~;help~;je;p~;ping da~;ping~;help~; + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.interfaces.Position + 28.22612889898729 + 43.60027658221718 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 2 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.plugins.ScriptRunner + + [CONTIKI_DIR]/tests/09-ipv6/js/ping-test-lla.js + true + + 495 + 0 + 525 + 190 + 18 + + diff --git a/tests/09-ipv6/02-ping-ula-csma-w-rpl.csc b/tests/09-ipv6/02-ping-ula-csma-w-rpl.csc new file mode 100644 index 000000000..802f068cc --- /dev/null +++ b/tests/09-ipv6/02-ping-ula-csma-w-rpl.csc @@ -0,0 +1,108 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/powertracker + + My simulation + 1.0 + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype787 + Cooja Mote Type #1 + [CONTIKI_DIR]/tests/09-ipv6/code/node.c + make clean + make WITH_ULA=1 WITH_CSMA=1 node.cooja + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + + org.contikios.cooja.interfaces.Position + 14.03051207883138 + 82.02801380504546 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 1 + + + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + ip-nbr~;ping fe80::202:2:2:2~;ip-nbr~;help~;je;p~;ping da~;ping~;help~; + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.interfaces.Position + 28.22612889898729 + 43.60027658221718 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 2 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.plugins.ScriptRunner + + [CONTIKI_DIR]/tests/09-ipv6/js/ping-test-ula.js + true + + 495 + 0 + 525 + 190 + 18 + + diff --git a/tests/09-ipv6/03-ping-lla-tsch-w-rpl.csc b/tests/09-ipv6/03-ping-lla-tsch-w-rpl.csc new file mode 100644 index 000000000..2642f363d --- /dev/null +++ b/tests/09-ipv6/03-ping-lla-tsch-w-rpl.csc @@ -0,0 +1,108 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/powertracker + + My simulation + 1.0 + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype787 + Cooja Mote Type #1 + [CONTIKI_DIR]/tests/09-ipv6/code/node.c + make clean + make WITH_TSCH=1 node.cooja + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + + org.contikios.cooja.interfaces.Position + 14.03051207883138 + 82.02801380504546 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 1 + + + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + ip-nbr~;ping fe80::202:2:2:2~;ip-nbr~;help~;je;p~;ping da~;ping~;help~; + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.interfaces.Position + 28.22612889898729 + 43.60027658221718 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 2 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.plugins.ScriptRunner + + [CONTIKI_DIR]/tests/09-ipv6/js/ping-test-lla.js + true + + 495 + 0 + 525 + 190 + 18 + + diff --git a/tests/09-ipv6/04-ping-ula-tsch-w-rpl.csc b/tests/09-ipv6/04-ping-ula-tsch-w-rpl.csc new file mode 100644 index 000000000..c18f8ac0b --- /dev/null +++ b/tests/09-ipv6/04-ping-ula-tsch-w-rpl.csc @@ -0,0 +1,108 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/powertracker + + My simulation + 1.0 + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype787 + Cooja Mote Type #1 + [CONTIKI_DIR]/tests/09-ipv6/code/node.c + make clean + make WITH_ULA=1 WITH_TSCH=1 node.cooja + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + + org.contikios.cooja.interfaces.Position + 14.03051207883138 + 82.02801380504546 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 1 + + + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + ip-nbr~;ping fe80::202:2:2:2~;ip-nbr~;help~;je;p~;ping da~;ping~;help~; + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.interfaces.Position + 28.22612889898729 + 43.60027658221718 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 2 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.plugins.ScriptRunner + + [CONTIKI_DIR]/tests/09-ipv6/js/ping-test-ula.js + true + + 495 + 0 + 525 + 190 + 18 + + diff --git a/tests/09-ipv6/05-ping-lla-csma-wo-rpl.csc b/tests/09-ipv6/05-ping-lla-csma-wo-rpl.csc new file mode 100644 index 000000000..9b3d1c50f --- /dev/null +++ b/tests/09-ipv6/05-ping-lla-csma-wo-rpl.csc @@ -0,0 +1,108 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/powertracker + + My simulation + 1.0 + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype787 + Cooja Mote Type #1 + [CONTIKI_DIR]/tests/09-ipv6/code/node.c + make clean + make WITH_CSMA=1 WITHOUT_RPL=1 node.cooja + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + + org.contikios.cooja.interfaces.Position + 14.03051207883138 + 82.02801380504546 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 1 + + + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + ip-nbr~;ping fe80::202:2:2:2~;ip-nbr~;help~;je;p~;ping da~;ping~;help~; + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.interfaces.Position + 28.22612889898729 + 43.60027658221718 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 2 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.plugins.ScriptRunner + + [CONTIKI_DIR]/tests/09-ipv6/js/ping-test-lla.js + true + + 495 + 0 + 525 + 190 + 18 + + diff --git a/tests/09-ipv6/06-ping-ula-csma-wo-rpl.csc b/tests/09-ipv6/06-ping-ula-csma-wo-rpl.csc new file mode 100644 index 000000000..3640cbb1f --- /dev/null +++ b/tests/09-ipv6/06-ping-ula-csma-wo-rpl.csc @@ -0,0 +1,108 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/powertracker + + My simulation + 1.0 + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype787 + Cooja Mote Type #1 + [CONTIKI_DIR]/tests/09-ipv6/code/node.c + make clean + make WITH_ULA=1 WITH_CSMA=1 WITHOUT_RPL=1 node.cooja + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + + org.contikios.cooja.interfaces.Position + 14.03051207883138 + 82.02801380504546 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 1 + + + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + ip-nbr~;ping fe80::202:2:2:2~;ip-nbr~;help~;je;p~;ping da~;ping~;help~; + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.interfaces.Position + 28.22612889898729 + 43.60027658221718 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 2 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.plugins.ScriptRunner + + [CONTIKI_DIR]/tests/09-ipv6/js/ping-test-ula.js + true + + 495 + 0 + 525 + 190 + 18 + + diff --git a/tests/09-ipv6/07-ping-lla-tsch-wo-rpl.csc b/tests/09-ipv6/07-ping-lla-tsch-wo-rpl.csc new file mode 100644 index 000000000..2960bacaf --- /dev/null +++ b/tests/09-ipv6/07-ping-lla-tsch-wo-rpl.csc @@ -0,0 +1,108 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/powertracker + + My simulation + 1.0 + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype787 + Cooja Mote Type #1 + [CONTIKI_DIR]/tests/09-ipv6/code/node.c + make clean + make WITH_TSCH=1 WITHOUT_RPL=1 node.cooja + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + + org.contikios.cooja.interfaces.Position + 14.03051207883138 + 82.02801380504546 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 1 + + + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + ip-nbr~;ping fe80::202:2:2:2~;ip-nbr~;help~;je;p~;ping da~;ping~;help~; + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.interfaces.Position + 28.22612889898729 + 43.60027658221718 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 2 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.plugins.ScriptRunner + + [CONTIKI_DIR]/tests/09-ipv6/js/ping-test-lla.js + true + + 495 + 0 + 525 + 190 + 18 + + diff --git a/tests/09-ipv6/08-ping-ula-tsch-wo-rpl.csc b/tests/09-ipv6/08-ping-ula-tsch-wo-rpl.csc new file mode 100644 index 000000000..73953b0b3 --- /dev/null +++ b/tests/09-ipv6/08-ping-ula-tsch-wo-rpl.csc @@ -0,0 +1,108 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/powertracker + + My simulation + 1.0 + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype787 + Cooja Mote Type #1 + [CONTIKI_DIR]/tests/09-ipv6/code/node.c + make clean + make WITH_ULA=1 WITH_TSCH=1 WITHOUT_RPL=1 node.cooja + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + + org.contikios.cooja.interfaces.Position + 14.03051207883138 + 82.02801380504546 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 1 + + + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + ip-nbr~;ping fe80::202:2:2:2~;ip-nbr~;help~;je;p~;ping da~;ping~;help~; + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.interfaces.Position + 28.22612889898729 + 43.60027658221718 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 2 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype787 + + + + org.contikios.cooja.plugins.ScriptRunner + + [CONTIKI_DIR]/tests/09-ipv6/js/ping-test-ula.js + true + + 495 + 0 + 525 + 190 + 18 + + diff --git a/tests/09-ipv6/Makefile b/tests/09-ipv6/Makefile new file mode 100644 index 000000000..272bc7da1 --- /dev/null +++ b/tests/09-ipv6/Makefile @@ -0,0 +1 @@ +include ../Makefile.simulation-test diff --git a/tests/09-ipv6/code/Makefile b/tests/09-ipv6/code/Makefile new file mode 100644 index 000000000..2c910f1cd --- /dev/null +++ b/tests/09-ipv6/code/Makefile @@ -0,0 +1,35 @@ +CONTIKI_PRJECT = node +all: $(CONTIKI_PROJECT) + +MODULES += os/services/shell +CFLAGS += -DLOG_CONF_LEVEL_RPL=LOG_LEVEL_INFO +CFLAGS += -DLOG_CONF_LEVEL_TCPIP=LOG_LEVEL_INFO +CFLAGS += -DLOG_CONF_LEVEL_IPV6=LOG_LEVEL_DBG +CFLAGS += -DLOG_CONF_LEVEL_MAC=LOG_LEVEL_INFO + +ifeq ($(WITH_ULA),1) + CFLAGS += -DWITH_ULA=1 +endif + +ifeq ($(WITHOUT_RPL),1) + MAKE_ROUTING = MAKE_ROUTING_NULLROUTING +else + CFLAGS += -DRPL_CONF_DAO_DELAY=1 +endif + +ifeq ($WITH_CSMA),1) + MAKE_MAC = MAKE_MAC_CSMA +endif + +ifeq ($(WITH_TSCH),1) + MAKE_MAC = MAKE_MAC_TSCH + CFLAGS += -DWITH_TSCH=1 + CFLAGS += -DTSCH_CONF_AUTOSTART=1 + CFLAGS += -DTSCH_CONF_DEFAULT_HOPPING_SEQUENCE=TSCH_HOPPING_SEQUENCE_1_1 +endif + +PLATFORM_ONLY = cooja +TARGET = cooja + +CONTIKI = ../../../ +include $(CONTIKI)/Makefile.include diff --git a/tests/09-ipv6/code/node.c b/tests/09-ipv6/code/node.c new file mode 100644 index 000000000..f465e2642 --- /dev/null +++ b/tests/09-ipv6/code/node.c @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2016, Yasuyuki Tanaka + * 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 + +PROCESS(node_process, "Node"); +AUTOSTART_PROCESSES(&node_process); + +PROCESS_THREAD(node_process, ev, data) +{ + static struct etimer et; +#if WITH_ULA + static uip_ipaddr_t ipaddr; +#endif /* WITH_ULA */ + +#if WITH_TSCH + static linkaddr_t coordinator_addr = {{0x00, 0x01, 0x00, 0x01, + 0x00, 0x01, 0x00, 0x01}}; +#endif /* WITH_TSCH */ + + PROCESS_BEGIN(); + +#if WITH_TSCH + if(linkaddr_cmp(&coordinator_addr, &linkaddr_node_addr)) { + tsch_set_coordinator(1); + } +#endif /* WITH_TSCH */ + +#if WITH_ULA + uip_ip6addr(&ipaddr, UIP_DS6_DEFAULT_PREFIX, 0, 0, 0, 0, 0, 0, 0); + uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0, 0, 0, 0); + uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); + uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); +#endif /* WITH_ULA */ + + serial_shell_init(); + + etimer_set(&et, CLOCK_SECOND); + while(1) { + /* + * keep doing something so that simulation runs until its timeout + */ + PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); + printf(".\n"); + etimer_reset(&et); + } + + PROCESS_END(); +} diff --git a/tests/09-ipv6/js/ping-test-lla.js b/tests/09-ipv6/js/ping-test-lla.js new file mode 100644 index 000000000..d9beedf8b --- /dev/null +++ b/tests/09-ipv6/js/ping-test-lla.js @@ -0,0 +1,45 @@ +TIMEOUT(20000, log.testFailed()); + +dst_lla = "fe80::202:2:2:2"; +dst_mac = "0002.0002.0002.0002"; +step = 0; + +while(1) { + YIELD(); + log.log(time + " " + id + " "+ msg + "\n"); + + if(msg.contains("Node ID: ")) { + if(id == 1) { + write(sim.getMoteWithID(1), "rpl-set-root 1"); + } + step += 1; + } + + if(step == 2 && time > 15000000) { + write(sim.getMoteWithID(1), "ping " + dst_lla); + step += 1; + } + + if(msg.contains("Received ping reply")) { + write(sim.getMoteWithID(1), "ip-nbr"); + } + + if(msg.contains("<->")) { + re = /-- | <-> |, router|, state /; + nc = msg.split(re); + ip_addr = nc[1]; + ll_addr = nc[2]; + is_router = nc[3]; + state = nc[4].trim(); + if(ip_addr == dst_lla && + ll_addr == dst_mac && + state == "Reachable") { + log.testOK(); + } else { + log.log(ip_addr + "\n"); + log.log(ll_addr + "\n"); + log.log(state + "\n"); + log.testFailed(); + } + } +} diff --git a/tests/09-ipv6/js/ping-test-ula.js b/tests/09-ipv6/js/ping-test-ula.js new file mode 100644 index 000000000..adbd22ccf --- /dev/null +++ b/tests/09-ipv6/js/ping-test-ula.js @@ -0,0 +1,47 @@ +;TIMEOUT(20000, log.testFailed()); + +dst_lla = "fe80::202:2:2:2"; +dst_ula = "fd00::202:2:2:2"; +dst_mac = "0002.0002.0002.0002"; +step = 0; + +while(1) { + YIELD(); + log.log(time + " " + id + " "+ msg + "\n"); + + if(msg.contains("Node ID: ")) { + if(id == 1) { + write(sim.getMoteWithID(1), "rpl-set-root 1"); + } + step += 1; + } + + if(step == 2 && time > 15000000) { + write(sim.getMoteWithID(1), "ping " + dst_ula); + step += 1; + } + + if(msg.contains("Received ping reply")) { + write(sim.getMoteWithID(1), "ip-nbr"); + } + + if(msg.contains("<->")) { + re = /-- | <-> |, router|, state /; + nc = msg.split(re); + ip_addr = nc[1]; + ll_addr = nc[2]; + is_router = nc[3]; + state = nc[4].trim(); + /* in RPL case, nbr doesn't have ula. */ + if((ip_addr == dst_lla || ip_addr == dst_ula) && + ll_addr == dst_mac && + state == "Reachable") { + log.testOK(); + } else { + log.log(ip_addr + "\n"); + log.log(ll_addr + "\n"); + log.log(state + "\n"); + log.testFailed(); + } + } +} diff --git a/tests/15-rpl-classic/code/receiver-node.c b/tests/15-rpl-classic/code/receiver-node.c index 20bf165f8..798aea84d 100644 --- a/tests/15-rpl-classic/code/receiver-node.c +++ b/tests/15-rpl-classic/code/receiver-node.c @@ -94,7 +94,7 @@ set_global_address(void) #if RPL_WITH_STORING uint8_t should_blink = 1; static void -route_callback(int event, uip_ipaddr_t *route, uip_ipaddr_t *ipaddr, int num_routes) +route_callback(int event, const uip_ipaddr_t *route, const uip_ipaddr_t *ipaddr, int num_routes) { if(event == UIP_DS6_NOTIFICATION_DEFRT_ADD) { should_blink = 0; diff --git a/tests/17-tun-rpl-br/01-border-router-cooja.sh b/tests/17-tun-rpl-br/01-border-router-cooja.sh index 11b2edc8a..a91e5905b 100755 --- a/tests/17-tun-rpl-br/01-border-router-cooja.sh +++ b/tests/17-tun-rpl-br/01-border-router-cooja.sh @@ -4,6 +4,6 @@ CONTIKI=$1 # Simulation file -BASENAME=01-border-router-cooja +BASENAME=$(basename $0 .sh) bash test-border-router.sh $CONTIKI $BASENAME fd00::204:4:4:4 60 diff --git a/tests/17-tun-rpl-br/02-border-router-cooja-tsch.sh b/tests/17-tun-rpl-br/02-border-router-cooja-tsch.sh index c7e61c8a7..760432c10 100755 --- a/tests/17-tun-rpl-br/02-border-router-cooja-tsch.sh +++ b/tests/17-tun-rpl-br/02-border-router-cooja-tsch.sh @@ -4,7 +4,7 @@ CONTIKI=$1 # Simulation file -BASENAME=02-border-router-cooja-tsch +BASENAME=$(basename $0 .sh) # Add a little extra initial time to account for TSCH association time bash test-border-router.sh $CONTIKI $BASENAME fd00::204:4:4:4 120 diff --git a/tests/17-tun-rpl-br/03-border-router-sky.sh b/tests/17-tun-rpl-br/03-border-router-sky.sh index 7ffa4265e..9bdd86111 100755 --- a/tests/17-tun-rpl-br/03-border-router-sky.sh +++ b/tests/17-tun-rpl-br/03-border-router-sky.sh @@ -4,6 +4,6 @@ CONTIKI=$1 # Simulation file -BASENAME=03-border-router-sky +BASENAME=$(basename $0 .sh) bash test-border-router.sh $CONTIKI $BASENAME fd00::0212:7404:0004:0404 60 diff --git a/tests/17-tun-rpl-br/04-border-router-traceroute.sh b/tests/17-tun-rpl-br/04-border-router-traceroute.sh index e1e9d6cdd..611140248 100755 --- a/tests/17-tun-rpl-br/04-border-router-traceroute.sh +++ b/tests/17-tun-rpl-br/04-border-router-traceroute.sh @@ -1,10 +1,11 @@ #!/bin/bash +source ../utils.sh # Contiki directory CONTIKI=$1 # Simulation file -BASENAME=04-border-router-traceroute +BASENAME=$(basename $0 .sh) # Destination IPv6 IPADDR=fd00::204:4:4:4 @@ -21,10 +22,9 @@ java -Xshare:on -jar $CONTIKI/tools/cooja/dist/cooja.jar -nogui=$BASENAME.csc -c JPID=$! sleep 20 -# Connect to the simlation +# Connect to the simulation echo "Starting tunslip6" -make -C $CONTIKI/tools tunslip6 -make -C $CONTIKI/examples/rpl-border-router/ connect-router-cooja TARGET=zoul >> $BASENAME.tunslip.log 2>&1 & +make -C $CONTIKI/examples/rpl-border-router/ connect-router-cooja TARGET=zoul >> $BASENAME.tunslip6.log 2>&1 & MPID=$! printf "Waiting for network formation (%d seconds)\n" "$WAIT_TIME" sleep $WAIT_TIME @@ -38,8 +38,8 @@ HOPS=`wc $BASENAME.scriptlog -l | cut -f 1 -d ' '` echo "Closing simulation and tunslip6" sleep 1 -kill -9 $JPID -kill -9 $MPID +kill_bg $JPID +kill_bg $MPID sleep 1 rm COOJA.testlog rm COOJA.log @@ -48,7 +48,7 @@ if [ $STATUS -eq 0 ] && [ $HOPS -eq $TARGETHOPS ] ; then printf "%-32s TEST OK\n" "$BASENAME" | tee $BASENAME.testlog; else echo "==== $BASENAME.coojalog ====" ; cat $BASENAME.coojalog; - echo "==== $BASENAME.tunslip.log ====" ; cat $BASENAME.tunslip.log; + echo "==== $BASENAME.tunslip6.log ====" ; cat $BASENAME.tunslip6.log; echo "==== $BASENAME.scriptlog ====" ; cat $BASENAME.scriptlog; printf "%-32s TEST FAIL\n" "$BASENAME" | tee $BASENAME.testlog; diff --git a/tests/17-tun-rpl-br/05-native-ping.sh b/tests/17-tun-rpl-br/05-native-ping.sh index 9e677c16e..6bb53ccd8 100755 --- a/tests/17-tun-rpl-br/05-native-ping.sh +++ b/tests/17-tun-rpl-br/05-native-ping.sh @@ -1,9 +1,10 @@ #!/bin/bash +source ../utils.sh # Contiki directory CONTIKI=$1 # Test basename -BASENAME=01-native-ping +BASENAME=$(basename $0 .sh) IPADDR=fd00::302:304:506:708 @@ -22,7 +23,7 @@ STATUS=${PIPESTATUS[0]} echo "Closing native node" sleep 2 -pgrep hello-world | sudo xargs kill -9 +kill_bg $CPID if [ $STATUS -eq 0 ] ; then cp $BASENAME.log $BASENAME.testlog diff --git a/tests/17-tun-rpl-br/06-native-coap.sh b/tests/17-tun-rpl-br/06-native-coap.sh index 88627ec19..4c1925699 100755 --- a/tests/17-tun-rpl-br/06-native-coap.sh +++ b/tests/17-tun-rpl-br/06-native-coap.sh @@ -1,9 +1,10 @@ #!/bin/bash +source ../utils.sh # Contiki directory CONTIKI=$1 # Test basename -BASENAME=06-native-coap +BASENAME=$(basename $0 .sh) IPADDR=fd00::302:304:506:708 @@ -38,7 +39,7 @@ done echo "Closing native node" sleep 2 -pgrep coap-example | sudo xargs kill -9 +kill_bg $CPID if [ $TESTCOUNT -eq $OKCOUNT ] ; then printf "%-32s TEST OK %3d/%d\n" "$BASENAME" "$OKCOUNT" "$TESTCOUNT" | tee $BASENAME.testlog; diff --git a/tests/17-tun-rpl-br/07-native-border-router-cooja.sh b/tests/17-tun-rpl-br/07-native-border-router-cooja.sh index 8f91bd726..c239e4e98 100755 --- a/tests/17-tun-rpl-br/07-native-border-router-cooja.sh +++ b/tests/17-tun-rpl-br/07-native-border-router-cooja.sh @@ -4,6 +4,6 @@ CONTIKI=$1 # Simulation file -BASENAME=07-native-border-router-cooja +BASENAME=$(basename $0 .sh) bash test-native-border-router.sh $CONTIKI $BASENAME fd00::204:4:4:4 60 diff --git a/tests/17-tun-rpl-br/08-border-router-cooja-frag.csc b/tests/17-tun-rpl-br/08-border-router-cooja-frag.csc new file mode 100644 index 000000000..b0d95600a --- /dev/null +++ b/tests/17-tun-rpl-br/08-border-router-cooja-frag.csc @@ -0,0 +1,252 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/powertracker + + My simulation + 1.0 + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype295 + Cooja Mote Type #1 + [CONTIKI_DIR]/examples/rpl-border-router/border-router.c + make TARGET=cooja clean +make -j border-router.cooja TARGET=cooja + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype686 + Cooja Mote Type #2 + [CONTIKI_DIR]/examples/hello-world/hello-world.c + make TARGET=cooja clean +make -j hello-world.cooja TARGET=cooja + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + + org.contikios.cooja.interfaces.Position + 54.36775767371176 + 24.409055040864118 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 1 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype295 + + + + org.contikios.cooja.interfaces.Position + 83.54989222799365 + 52.63050856506214 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 2 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype686 + + + + org.contikios.cooja.interfaces.Position + 108.91767775240822 + 78.59778809170032 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 3 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype686 + + + + org.contikios.cooja.interfaces.Position + 139.91021061864723 + 98.34190023350419 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 4 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype686 + + + + org.contikios.cooja.plugins.SimControl + 280 + 1 + 160 + 400 + 0 + + + org.contikios.cooja.plugins.Visualizer + + true + org.contikios.cooja.plugins.skins.UDGMVisualizerSkin + org.contikios.cooja.plugins.skins.IDVisualizerSkin + 1.9798610460263038 0.0 0.0 1.9798610460263038 -61.112037797038525 -1.2848438586294648 + + 400 + 4 + 400 + 1 + 1 + + + org.contikios.cooja.plugins.LogListener + + ID:4 + + + + 1404 + 2 + 240 + 400 + 160 + + + org.contikios.cooja.plugins.TimeLine + + 0 + 1 + 2 + 3 + + + + 500.0 + + 1804 + 6 + 166 + 0 + 753 + + + org.contikios.cooja.plugins.Notes + + Enter notes here + true + + 1124 + 5 + 160 + 680 + 0 + + + org.contikios.cooja.serialsocket.SerialSocketServer + 0 + + 60001 + true + + 362 + 3 + 116 + 13 + 414 + + + org.contikios.cooja.plugins.ScriptRunner + + + true + + 600 + 0 + 700 + 1037 + 40 + + diff --git a/tests/17-tun-rpl-br/08-border-router-cooja-frag.sh b/tests/17-tun-rpl-br/08-border-router-cooja-frag.sh new file mode 100755 index 000000000..0d308acb6 --- /dev/null +++ b/tests/17-tun-rpl-br/08-border-router-cooja-frag.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# Contiki directory +CONTIKI=$1 + +# Simulation file +BASENAME=$(basename $0 .sh) + +bash test-border-router.sh $CONTIKI $BASENAME fd00::204:4:4:4 60 1200 4 diff --git a/tests/17-tun-rpl-br/09-native-border-router-cooja-frag.csc b/tests/17-tun-rpl-br/09-native-border-router-cooja-frag.csc new file mode 100644 index 000000000..7140d183c --- /dev/null +++ b/tests/17-tun-rpl-br/09-native-border-router-cooja-frag.csc @@ -0,0 +1,254 @@ + + + [APPS_DIR]/mrm + [APPS_DIR]/mspsim + [APPS_DIR]/avrora + [APPS_DIR]/serial_socket + [APPS_DIR]/powertracker + + My simulation + 1.0 + 123456 + 1000000 + + org.contikios.cooja.radiomediums.UDGM + 50.0 + 100.0 + 1.0 + 1.0 + + + 40000 + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype295 + Cooja Mote Type #1 + [CONTIKI_DIR]/examples/slip-radio/slip-radio.c + make TARGET=cooja clean +make -j slip-radio.cooja TARGET=cooja + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + org.contikios.cooja.contikimote.ContikiMoteType + mtype686 + Cooja Mote Type #2 + [CONTIKI_DIR]/examples/hello-world/hello-world.c + make TARGET=cooja clean +make -j hello-world.cooja TARGET=cooja + org.contikios.cooja.interfaces.Position + org.contikios.cooja.interfaces.Battery + org.contikios.cooja.contikimote.interfaces.ContikiVib + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + org.contikios.cooja.contikimote.interfaces.ContikiRS232 + org.contikios.cooja.contikimote.interfaces.ContikiBeeper + org.contikios.cooja.interfaces.RimeAddress + org.contikios.cooja.contikimote.interfaces.ContikiIPAddress + org.contikios.cooja.contikimote.interfaces.ContikiRadio + org.contikios.cooja.contikimote.interfaces.ContikiButton + org.contikios.cooja.contikimote.interfaces.ContikiPIR + org.contikios.cooja.contikimote.interfaces.ContikiClock + org.contikios.cooja.contikimote.interfaces.ContikiLED + org.contikios.cooja.contikimote.interfaces.ContikiCFS + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + org.contikios.cooja.interfaces.Mote2MoteRelations + org.contikios.cooja.interfaces.MoteAttributes + false + + + + org.contikios.cooja.interfaces.Position + 54.36775767371176 + 24.409055040864118 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 1 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype295 + + + + org.contikios.cooja.interfaces.Position + 83.54989222799365 + 52.63050856506214 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 2 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype686 + + + + org.contikios.cooja.interfaces.Position + 108.91767775240822 + 78.59778809170032 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 3 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype686 + + + + org.contikios.cooja.interfaces.Position + 139.91021061864723 + 98.34190023350419 + 0.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiMoteID + 4 + + + org.contikios.cooja.contikimote.interfaces.ContikiRadio + 250.0 + + + org.contikios.cooja.contikimote.interfaces.ContikiEEPROM + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== + + mtype686 + + + + org.contikios.cooja.plugins.SimControl + 280 + 1 + 160 + 400 + 0 + + + org.contikios.cooja.plugins.Visualizer + + true + org.contikios.cooja.plugins.skins.UDGMVisualizerSkin + org.contikios.cooja.plugins.skins.IDVisualizerSkin + 1.9798610460263038 0.0 0.0 1.9798610460263038 -61.112037797038525 -1.2848438586294648 + + 400 + 4 + 400 + 1 + 1 + + + org.contikios.cooja.plugins.LogListener + + ID:4 + + + + 1404 + 2 + 240 + 400 + 160 + + + org.contikios.cooja.plugins.TimeLine + + 0 + 1 + 2 + 3 + + + + 500.0 + + 1804 + 6 + 166 + 0 + 753 + + + org.contikios.cooja.plugins.Notes + + Enter notes here + true + + 1124 + 5 + 160 + 680 + 0 + + + org.contikios.cooja.serialsocket.SerialSocketServer + 0 + + 60001 + true + + 362 + 3 + 116 + 13 + 414 + + + org.contikios.cooja.plugins.ScriptRunner + + + true + + 600 + 0 + 700 + 1037 + 40 + + diff --git a/tests/17-tun-rpl-br/09-native-border-router-cooja-frag.sh b/tests/17-tun-rpl-br/09-native-border-router-cooja-frag.sh new file mode 100755 index 000000000..5b893ffc7 --- /dev/null +++ b/tests/17-tun-rpl-br/09-native-border-router-cooja-frag.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# Contiki directory +CONTIKI=$1 + +# Simulation file +BASENAME=$(basename $0 .sh) + +bash test-native-border-router.sh $CONTIKI $BASENAME fd00::204:4:4:4 60 1200 4 diff --git a/tests/17-tun-rpl-br/test-border-router.sh b/tests/17-tun-rpl-br/test-border-router.sh index 6bfb8cf62..a69446254 100755 --- a/tests/17-tun-rpl-br/test-border-router.sh +++ b/tests/17-tun-rpl-br/test-border-router.sh @@ -1,4 +1,5 @@ #!/bin/bash +source ../utils.sh # Contiki directory CONTIKI=$1 @@ -12,6 +13,12 @@ IPADDR=$3 # Time allocated for convergence WAIT_TIME=$4 +# Payload len. Default is ping6's default, 56. +PING_SIZE=${5:-56} + +# Inter-ping delay. Default is ping6's default, 1s. +PING_DELAY=${6:-1} + # ICMP request-reply count COUNT=5 @@ -21,25 +28,24 @@ java -Xshare:on -jar $CONTIKI/tools/cooja/dist/cooja.jar -nogui=$BASENAME.csc -c JPID=$! sleep 20 -# Connect to the simlation +# Connect to the simulation echo "Starting tunslip6" -make -C $CONTIKI/tools tunslip6 -make -C $CONTIKI/examples/rpl-border-router/ connect-router-cooja TARGET=zoul >> $BASENAME.tunslip.log 2>&1 & +make -C $CONTIKI/examples/rpl-border-router/ connect-router-cooja TARGET=zoul >> $BASENAME.tunslip6.log 2>&1 & MPID=$! printf "Waiting for network formation (%d seconds)\n" "$WAIT_TIME" sleep $WAIT_TIME # Do ping echo "Pinging" -ping6 $IPADDR -c $COUNT | tee $BASENAME.scriptlog +ping6 $IPADDR -c $COUNT -s $PING_SIZE -i $PING_DELAY | tee $BASENAME.scriptlog # Fetch ping6 status code (not $? because this is piped) STATUS=${PIPESTATUS[0]} REPLIES=`grep -c 'icmp_seq=' $BASENAME.scriptlog` echo "Closing simulation and tunslip6" sleep 1 -kill -9 $JPID -kill -9 $MPID +kill_bg $JPID +kill_bg $MPID sleep 1 rm COOJA.testlog rm COOJA.log @@ -48,7 +54,7 @@ if [ $STATUS -eq 0 ] && [ $REPLIES -eq $COUNT ] ; then printf "%-32s TEST OK\n" "$BASENAME" | tee $BASENAME.testlog; else echo "==== $BASENAME.coojalog ====" ; cat $BASENAME.coojalog; - echo "==== $BASENAME.tunslip.log ====" ; cat $BASENAME.tunslip.log; + echo "==== $BASENAME.tunslip6.log ====" ; cat $BASENAME.tunslip6.log; echo "==== $BASENAME.scriptlog ====" ; cat $BASENAME.scriptlog; printf "%-32s TEST FAIL\n" "$BASENAME" | tee $BASENAME.testlog; diff --git a/tests/17-tun-rpl-br/test-native-border-router.sh b/tests/17-tun-rpl-br/test-native-border-router.sh old mode 100644 new mode 100755 index 38dce1bae..e2e205f20 --- a/tests/17-tun-rpl-br/test-native-border-router.sh +++ b/tests/17-tun-rpl-br/test-native-border-router.sh @@ -1,4 +1,5 @@ #!/bin/bash +source ../utils.sh # Contiki directory CONTIKI=$1 @@ -12,6 +13,12 @@ IPADDR=$3 # Time allocated for convergence WAIT_TIME=$4 +# Payload len. Default is ping6's default, 56. +PING_SIZE=${5:-56} + +# Inter-ping delay. Default is ping6's default, 1s. +PING_DELAY=${6:-1} + # ICMP request-reply count COUNT=5 @@ -21,7 +28,7 @@ java -Xshare:on -jar $CONTIKI/tools/cooja/dist/cooja.jar -nogui=$BASENAME.csc -c JPID=$! sleep 20 -# Connect to the simlation +# Connect to the simulation echo "Starting native border-router" nohup make -C $CONTIKI/examples/rpl-border-router/ connect-router-cooja TARGET=native >> $BASENAME.nbr.log 2>&1 & MPID=$! @@ -30,15 +37,15 @@ sleep $WAIT_TIME # Do ping echo "Pinging" -ping6 $IPADDR -c $COUNT | tee $BASENAME.scriptlog +ping6 $IPADDR -c $COUNT -s $PING_SIZE -i $PING_DELAY | tee $BASENAME.scriptlog # Fetch ping6 status code (not $? because this is piped) STATUS=${PIPESTATUS[0]} REPLIES=`grep -c 'icmp_seq=' $BASENAME.scriptlog` echo "Closing simulation and nbr" sleep 1 -kill -9 $JPID -kill -9 $MPID +kill_bg $JPID +kill_bg $MPID sleep 1 rm COOJA.testlog rm COOJA.log diff --git a/tests/18-coap-lwm2m/06-lwm2m-ipso-test.sh b/tests/18-coap-lwm2m/06-lwm2m-ipso-test.sh index 9aacc2976..f596206a9 100755 --- a/tests/18-coap-lwm2m/06-lwm2m-ipso-test.sh +++ b/tests/18-coap-lwm2m/06-lwm2m-ipso-test.sh @@ -1,4 +1,5 @@ #!/bin/bash +source ../utils.sh # Contiki directory CONTIKI=$1 @@ -16,9 +17,10 @@ CPID=$! sleep 10 echo "Downloading leshan" -wget -nc https://joakimeriksson.github.io/resources/leshan-server-demo-1.0.0-SNAPSHOT-jar-with-dependencies.jar +LESHAN_JAR=leshan-server-demo-1.0.0-SNAPSHOT-jar-with-dependencies.jar +wget -nc https://joakimeriksson.github.io/resources/$LESHAN_JAR echo "Starting leshan server" -java -jar leshan-server-demo-1.0.0-SNAPSHOT-jar-with-dependencies.jar >leshan.log 2>leshan.err & +java -jar $LESHAN_JAR >leshan.log 2>leshan.err & LESHID=$! COUNTER=10 @@ -32,11 +34,11 @@ done echo "Closing native node" sleep 1 -pgrep ipso | sudo xargs kill -9 +kill_bg $CPID echo "Closing leshan" sleep 1 -pgrep java | sudo xargs kill -9 +kill_bg $LESHID if grep -q 'OK' leshan.err ; then diff --git a/tests/18-coap-lwm2m/07-lwm2m-standalone-test.sh b/tests/18-coap-lwm2m/07-lwm2m-standalone-test.sh index b13352447..2e6371896 100755 --- a/tests/18-coap-lwm2m/07-lwm2m-standalone-test.sh +++ b/tests/18-coap-lwm2m/07-lwm2m-standalone-test.sh @@ -1,4 +1,5 @@ #!/bin/bash +source ../utils.sh # Contiki directory CONTIKI=$1 @@ -11,9 +12,10 @@ make CONTIKI_NG=../../$CONTIKI -C example-lwm2m-standalone/lwm2m clean >/dev/nul make CONTIKI_NG=../../$CONTIKI -C example-lwm2m-standalone/lwm2m >make.log 2>make.err echo "Downloading leshan" -wget -nc https://joakimeriksson.github.io/resources/leshan-server-demo-1.0.0-SNAPSHOT-jar-with-dependencies.jar +LESHAN_JAR=leshan-server-demo-1.0.0-SNAPSHOT-jar-with-dependencies.jar +wget -nc https://joakimeriksson.github.io/resources/$LESHAN_JAR echo "Starting leshan server" -java -jar leshan-server-demo-1.0.0-SNAPSHOT-jar-with-dependencies.jar -lp 5686 -slp 5687 >leshan.log 2>leshan.err & +java -jar $LESHAN_JAR -lp 5686 -slp 5687 >leshan.log 2>leshan.err & LESHID=$! echo "Starting lwm2m standalone example" @@ -33,11 +35,11 @@ done echo "Closing standalone example" sleep 1 -pgrep lwm2m-example | sudo xargs kill -9 +kill_bg $CPID echo "Closing leshan" sleep 1 -pgrep java | sudo xargs kill -9 +kill_bg $LESHID if grep -q 'OK' leshan.err ; then diff --git a/tests/18-coap-lwm2m/08-lwm2m-qmode-ipso-test.sh b/tests/18-coap-lwm2m/08-lwm2m-qmode-ipso-test.sh new file mode 100755 index 000000000..b5ce6aa3f --- /dev/null +++ b/tests/18-coap-lwm2m/08-lwm2m-qmode-ipso-test.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +# Contiki directory +CONTIKI=$1 +# Test basename +BASENAME=08-lwm2m-qmode-ipso-test + +IPADDR=fd00::302:304:506:708 + +# Starting Contiki-NG native node +echo "Starting native node - lwm2m/ipso objects with Q-Mode" +make -C $CONTIKI/examples/lwm2m-ipso-objects clean >/dev/null +make -C $CONTIKI/examples/lwm2m-ipso-objects DEFINES=LWM2M_QUEUE_MODE_CONF_ENABLED=1,LWM2M_QUEUE_MODE_CONF_INCLUDE_DYNAMIC_ADAPTATION=1,LWM2M_QUEUE_MODE_OBJECT_CONF_ENABLED=1 > make.log 2> make.err +sudo $CONTIKI/examples/lwm2m-ipso-objects/example-ipso-objects.native > node.log 2> node.err & +CPID=$! +sleep 10 + +echo "Downloading leshan with Q-Mode support" +LESHAN_JAR=leshan-server-demo-qmode-support1.0.0-SNAPSHOT-jar-with-dependencies.jar +wget -nc https://carlosgp143.github.io/resources/$LESHAN_JAR +echo "Starting leshan server with Q-Mode enabled" +java -jar $LESHAN_JAR >leshan.log 2>leshan.err & +LESHID=$! + +COUNTER=10 +while [ $COUNTER -gt 0 ]; do + sleep 5 + aux=$(grep -c 'OK' leshan.err) + if [ $aux -eq 2 ] ; then + break + fi + let COUNTER-=1 +done + +echo "Closing native node" +sleep 1 +pgrep ipso | sudo xargs kill -9 + +echo "Closing leshan" +sleep 1 +pgrep java | sudo xargs kill -9 + +#Two OKs needed: awake and sleeping +aux=$(grep -c 'OK' leshan.err) +if [ $aux -eq 2 ] +then + cp leshan.err $BASENAME.testlog; + printf "%-32s TEST OK\n" "$BASENAME" | tee $BASENAME.testlog; +else + echo "==== make.log ====" ; cat make.log; + echo "==== make.err ====" ; cat make.err; + echo "==== node.log ====" ; cat node.log; + echo "==== node.err ====" ; cat node.err; + echo "==== leshan.log ====" ; cat leshan.log; + echo "==== leshan.err ====" ; cat leshan.err; + echo "==== $BASENAME.log ====" ; cat $BASENAME.log; + + printf "%-32s TEST FAIL\n" "$BASENAME" | tee $BASENAME.testlog; +fi + +rm make.log +rm make.err +rm node.log +rm node.err +rm leshan.log +rm leshan.err + +# We do not want Make to stop -> Return 0 +# The Makefile will check if a log contains FAIL at the end +exit 0 diff --git a/tests/18-coap-lwm2m/09-lwm2m-qmode-standalone-test.sh b/tests/18-coap-lwm2m/09-lwm2m-qmode-standalone-test.sh new file mode 100755 index 000000000..d84d3cd93 --- /dev/null +++ b/tests/18-coap-lwm2m/09-lwm2m-qmode-standalone-test.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +# Contiki directory +CONTIKI=$1 +# Test basename +BASENAME=09-lwm2m-qmode-standalone-test + +# Building standalone posix example +echo "Compiling standalone posix example" +make CONTIKI_NG=../../$CONTIKI -C example-lwm2m-standalone/lwm2m clean >/dev/null +make CONTIKI_NG=../../$CONTIKI -C example-lwm2m-standalone/lwm2m DEFINES=LWM2M_QUEUE_MODE_CONF_ENABLED=1,LWM2M_QUEUE_MODE_CONF_INCLUDE_DYNAMIC_ADAPTATION=1,LWM2M_QUEUE_MODE_OBJECT_CONF_ENABLED=1 >make.log 2>make.err + +echo "Downloading leshan with Q-Mode support" +LESHAN_JAR=leshan-server-demo-qmode-support1.0.0-SNAPSHOT-jar-with-dependencies.jar +wget -nc https://carlosgp143.github.io/resources/$LESHAN_JAR +echo "Starting leshan server with Q-Mode enabled" +java -jar $LESHAN_JAR -lp 5686 -slp 5687 >leshan.log 2>leshan.err & +LESHID=$! + +echo "Starting lwm2m standalone example" +example-lwm2m-standalone/lwm2m/lwm2m-example coap://127.0.0.1:5686 > node.log 2> node.err & + +CPID=$! + +COUNTER=10 +while [ $COUNTER -gt 0 ]; do + sleep 5 + aux=$(grep -c 'OK' leshan.err) + if [ $aux -eq 2 ] ; then + break + fi + let COUNTER-=1 +done + +echo "Closing standalone example" +sleep 1 +pgrep lwm2m-example | sudo xargs kill -9 + +echo "Closing leshan" +sleep 1 +pgrep java | sudo xargs kill -9 + +aux=$(grep -c 'OK' leshan.err) +if [ $aux -eq 2 ] +then + cp leshan.err $BASENAME.testlog; + printf "%-32s TEST OK\n" "$BASENAME" | tee $BASENAME.testlog; +else + echo "==== make.log ====" ; cat make.log; + echo "==== make.err ====" ; cat make.err; + echo "==== node.log ====" ; cat node.log; + echo "==== node.err ====" ; cat node.err; + echo "==== leshan.log ====" ; cat leshan.log; + echo "==== leshan.err ====" ; cat leshan.err; + echo "==== $BASENAME.log ====" ; cat $BASENAME.log; + + printf "%-32s TEST FAIL\n" "$BASENAME" | tee $BASENAME.testlog; +fi + +rm make.log +rm make.err +rm node.log +rm node.err +rm leshan.log +rm leshan.err + +# We do not want Make to stop -> Return 0 +# The Makefile will check if a log contains FAIL at the end +exit 0 diff --git a/tests/18-coap-lwm2m/pytests/test-qmode-awake.py b/tests/18-coap-lwm2m/pytests/test-qmode-awake.py new file mode 100644 index 000000000..775e1cff0 --- /dev/null +++ b/tests/18-coap-lwm2m/pytests/test-qmode-awake.py @@ -0,0 +1,20 @@ +import unittest, array, time + +class TestQueueModeAwake(unittest.TestCase): + global respAwakeTime + global respSleepTime + + def test_read_awake_time(self): + self.assertEqual(respAwakeTime.getCode().getName(), "CONTENT") + + def test_read_sleep_time(self): + self.assertEqual(respSleepTime.getCode().getName(), "CONTENT") + + +print "----------------------------------------" +print "LWM2M Queue Mode Awake State Tester" +print "----------------------------------------" + + +suite = unittest.TestLoader().loadTestsFromTestCase(TestQueueModeAwake) +unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/tests/18-coap-lwm2m/pytests/test-qmode-sleep.py b/tests/18-coap-lwm2m/pytests/test-qmode-sleep.py new file mode 100644 index 000000000..66dc061ff --- /dev/null +++ b/tests/18-coap-lwm2m/pytests/test-qmode-sleep.py @@ -0,0 +1,19 @@ +from __future__ import with_statement +import unittest, array, time + +class TestQueueModeSleep(unittest.TestCase): + global client + + def test_read_awake_time(self): + self.assertIsNone(client.read("30000/0/30000")) + + def test_read_sleep_time(self): + self.assertIsNone(client.read("30000/0/30001")) + + +print "----------------------------------------" +print "LWM2M Queue Mode Sleep State Tester - name of client: ", client.endpoint +print "----------------------------------------" + +suite = unittest.TestLoader().loadTestsFromTestCase(TestQueueModeSleep) +unittest.TextTestRunner(verbosity=2).run(suite) diff --git a/tests/19-out-of-tree-build/Makefile b/tests/19-out-of-tree-build/Makefile new file mode 100644 index 000000000..759027062 --- /dev/null +++ b/tests/19-out-of-tree-build/Makefile @@ -0,0 +1,20 @@ +EXAMPLESDIR=$(HOME)/out-of-tree-tests +TOOLSDIR=$(HOME)/contiki-ng/tools + +EXAMPLES = \ +hello-world/native \ +hello-world/native:MAKE_NET=MAKE_NET_NULLNET \ +hello-world/native:MAKE_ROUTING=MAKE_ROUTING_RPL_CLASSIC \ +hello-world/sky \ +hello-world/nrf52dk \ +hello-world/cc2538dk \ +hello-world/zoul \ +hello-world/openmote-cc2538 \ +hello-world/srf06-cc26xx \ +hello-world/jn516x \ +hello-world/simplelink:BOARD=launchpad/cc26x2r1 \ +hello-world/simplelink:BOARD=sensortag/cc2650 \ + +TOOLS= + +include ../Makefile.compile-test diff --git a/tests/Makefile b/tests/Makefile index a879c805f..ddee606f2 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -36,7 +36,7 @@ summary: $(SUMMARIES) @cat $(SUMMARIES) > $@ %/summary: - @make -C $* summary || true + @$(MAKE) -C $* summary || true clean: rm -f $(SUMMARIES) summary diff --git a/tests/Makefile.compile-test b/tests/Makefile.compile-test index 1a5952033..e30f9da36 100644 --- a/tests/Makefile.compile-test +++ b/tests/Makefile.compile-test @@ -40,7 +40,7 @@ get_target_vars = $(wordlist 2,15,$(subst :, ,$1)) define dooneexample @echo -n Building example $(3): $(1) $(4) for target $(2) @((cd $(EXAMPLESDIR)/$(1); \ - make $(4) TARGET=$(2) clean && make -j $(4) TARGET=$(2) WERROR=1) > \ + $(MAKE) $(4) TARGET=$(2) clean && make -j $(4) TARGET=$(2) WERROR=1) > \ /dev/null 2>make.err && \ (echo " -> OK" && printf "%-75s %-40s %-20s TEST OK\n" "$(1)" "$(4)" "$(2)" > $(3)-$(subst /,-,$(1))$(2).testlog) || \ (echo " -> FAIL" && printf "%-75s %-40s %-20s TEST FAIL\n" "$(1)" "$(4)" "$(2)" > $(3)-$(subst /,-,$(1))$(2).testlog ; cat make.err)) @@ -65,4 +65,4 @@ clean: @rm -f *.testlog summary @$(foreach example, $(EXAMPLES), \ $(foreach target, $(EXAMPLESTARGETS), \ - (cd $(EXAMPLESDIR)/$(example); make TARGET=$(target) clean);)) + (cd $(EXAMPLESDIR)/$(example); $(MAKE) TARGET=$(target) clean);)) diff --git a/tests/Makefile.script-test b/tests/Makefile.script-test index e4dd0da6a..e58acec80 100644 --- a/tests/Makefile.script-test +++ b/tests/Makefile.script-test @@ -5,18 +5,14 @@ CONTIKI=../.. all: clean summary -summary: cooja $(TESTLOGS) +summary: $(TESTLOGS) @cat *.testlog > summary @echo "========== Summary ==========" @cat summary -%.testlog: %.sh cooja +%.testlog: %.sh @echo "========== Running script test $(basename $@).sh ==========" @bash "$(basename $@).sh" "$(CONTIKI)" clean: @rm -f *.*log report summary - -cooja: $(CONTIKI)/tools/cooja/dist/cooja.jar -$(CONTIKI)/tools/cooja/dist/cooja.jar: - (cd $(CONTIKI)/tools/cooja; ant jar) diff --git a/tests/compile-all/build.sh b/tests/compile-all/build.sh index 795343eeb..81441816e 100755 --- a/tests/compile-all/build.sh +++ b/tests/compile-all/build.sh @@ -40,17 +40,21 @@ # To invoke the building for a specific platform, run: # $ PLATFORMS=zoul ./build.sh # +CONTIKI_NG_TOP_DIR="../.." +EXAMPLES_DIR=$CONTIKI_NG_TOP_DIR/examples if [[ "$PLATFORMS" == "" ]] then - PLATFORMS=`ls ../../arch/platform` + PLATFORMS=`ls $CONTIKI_NG_TOP_DIR/arch/platform` fi if [[ "$MAKEFILES" == "" ]] then - MAKEFILES=`find ../../examples/ -name Makefile` + MAKEFILES=`find $EXAMPLES_DIR -name Makefile` fi +HELLO_WORLD=$EXAMPLES_DIR/hello-world + # Set the make goal the first argument of the script or to "all" if called w/o arguments if [[ $# -gt 0 ]] then @@ -97,16 +101,14 @@ do continue fi - if [[ "$platform" == "srf06-cc26xx" ]] + # Detect all boards for the current platform by calling + # make TARGET=$platform boards + # in the hello-world dir. + BOARDS=`make -s -C $HELLO_WORLD TARGET=$platform boards \ + | grep -v "no boards" | rev | cut -f3- -d" " | rev` + + if [[ -z $BOARDS ]] then - # srf06-cc26xx has multiple boards - BOARDS="srf06/cc26xx srf06/cc13xx launchpad/cc2650 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350" - elif [[ "$platform" == "zoul" ]] - then - # Zoul has multiple boards - BOARDS="remote-reva remote-revb firefly-reva firefly orion" - else - # Other platforms have just a single board BOARDS="default" fi diff --git a/tests/utils.sh b/tests/utils.sh new file mode 100755 index 000000000..bd00ca539 --- /dev/null +++ b/tests/utils.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +function echo_run( ) +{ + echo $@ + $@ +} + +function kill_bg( ) +{ + PID=$1 + CMD=$(ps -p $PID -o cmd=) + SUDO= + TOKILL=$PID + if [[ ${CMD:0:5} == "sudo " ]] ; then + SUDO="sudo " + TOKILL=$(ps --ppid $PID -o pid=) + fi + echo_run ${SUDO}kill -9 $TOKILL +} diff --git a/tools/Makefile b/tools/Makefile deleted file mode 100644 index ef1711d7c..000000000 --- a/tools/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -all: tunslip6 - -CFLAGS += -Wall -Werror - -tunslip6: tools-utils.c tunslip6.c - -clean: - rm -f *.o tunslip6 diff --git a/tools/cc2538-bsl b/tools/cc2538-bsl index 81cd4cbe5..59fd804b8 160000 --- a/tools/cc2538-bsl +++ b/tools/cc2538-bsl @@ -1 +1 @@ -Subproject commit 81cd4cbe5e05e4fa97782d1859ed15b769f4bf2b +Subproject commit 59fd804b80aec868d74ce37c6195086b817981ea diff --git a/tools/code-style/uncrustify.cfg b/tools/code-style/uncrustify.cfg index 37b49a48b..7b2b353ec 100644 --- a/tools/code-style/uncrustify.cfg +++ b/tools/code-style/uncrustify.cfg @@ -35,7 +35,7 @@ sp_balance_nested_parens=false align_keep_tabs=false align_with_tabs=false align_on_tabstop=false -align_number_left=false +align_number_right=false align_func_params=false align_same_func_call_params=false align_var_def_colon=false diff --git a/tools/cooja b/tools/cooja index 22b1262d9..63538bbb8 160000 --- a/tools/cooja +++ b/tools/cooja @@ -1 +1 @@ -Subproject commit 22b1262d9e668d9cf6c8eaf70715f1bcd5728642 +Subproject commit 63538bbb882ba06a7b8cf97c11ce2fe4d22e4f88 diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile index d8e9c0a79..6eb9dbb17 100644 --- a/tools/docker/Dockerfile +++ b/tools/docker/Dockerfile @@ -1,28 +1,58 @@ FROM 32bit/ubuntu:16.04 +ENV DEBIAN_FRONTEND noninteractive + # Tools -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - build-essential doxygen git wget unzip python-serial \ - default-jdk ant srecord iputils-tracepath && \ - apt-get clean +RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF && \ + echo "deb http://download.mono-project.com/repo/ubuntu xenial main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list && \ + apt-get -qq update && \ + apt-get -qq -y --no-install-recommends install \ + ant \ + build-essential \ + default-jdk \ + doxygen \ + gdb \ + git \ + gksu \ + gtk-sharp2 \ + iputils-tracepath \ + libcanberra-gtk-module:i386 \ + libgtk2.0-0 \ + mono-complete \ + mosquitto \ + mosquitto-clients \ + npm \ + python-pip \ + python-serial \ + rlwrap \ + screen \ + srecord \ + uml-utilities \ + unzip \ + wget \ + > /dev/null \ + && apt-get -qq clean + +# Install coap-cli +RUN npm -q install coap-cli -g \ + && sudo ln -s /usr/bin/nodejs /usr/bin/node # Install ARM toolchain -RUN wget https://launchpad.net/gcc-arm-embedded/5.0/5-2015-q4-major/+download/gcc-arm-none-eabi-5_2-2015q4-20151219-linux.tar.bz2 && \ +RUN wget -nv https://launchpad.net/gcc-arm-embedded/5.0/5-2015-q4-major/+download/gcc-arm-none-eabi-5_2-2015q4-20151219-linux.tar.bz2 && \ tar xjf gcc-arm-none-eabi-5_2-2015q4-20151219-linux.tar.bz2 -C /tmp/ && \ cp -f -r /tmp/gcc-arm-none-eabi-5_2-2015q4/* /usr/local/ && \ rm -rf /tmp/gcc-arm-none-eabi-* gcc-arm-none-eabi-*-linux.tar.bz2 # Install msp430 toolchain -RUN wget http://simonduq.github.io/resources/mspgcc-4.7.2-compiled.tar.bz2 && \ +RUN wget -nv http://simonduq.github.io/resources/mspgcc-4.7.2-compiled.tar.bz2 && \ tar xjf mspgcc*.tar.bz2 -C /tmp/ && \ cp -f -r /tmp/msp430/* /usr/local/ && \ rm -rf /tmp/msp430 mspgcc*.tar.bz2 # Install NXP toolchain (partial, with binaries excluded. Download from nxp.com) -RUN wget http://simonduq.github.io/resources/ba-elf-gcc-4.7.4-part1.tar.bz2 && \ - wget http://simonduq.github.io/resources/ba-elf-gcc-4.7.4-part2.tar.bz2 && \ - wget http://simonduq.github.io/resources/jn516x-sdk-4163-1416.tar.bz2 && \ +RUN wget -nv http://simonduq.github.io/resources/ba-elf-gcc-4.7.4-part1.tar.bz2 && \ + wget -nv http://simonduq.github.io/resources/ba-elf-gcc-4.7.4-part2.tar.bz2 && \ + wget -nv http://simonduq.github.io/resources/jn516x-sdk-4163-1416.tar.bz2 && \ mkdir /tmp/jn516x-sdk /tmp/ba-elf-gcc && \ tar xjf jn516x-sdk-*.tar.bz2 -C /tmp/jn516x-sdk && \ tar xjf ba-elf-gcc-*part1.tar.bz2 -C /tmp/ba-elf-gcc && \ @@ -34,13 +64,18 @@ RUN wget http://simonduq.github.io/resources/ba-elf-gcc-4.7.4-part1.tar.bz2 && \ ENV PATH="/usr/ba-elf-gcc/bin:${PATH}" ## Install nRF52 SDK -RUN wget https://developer.nordicsemi.com/nRF5_IoT_SDK/nRF5_IoT_SDK_v0.9.x/nrf5_iot_sdk_3288530.zip && \ +RUN wget -nv https://developer.nordicsemi.com/nRF5_IoT_SDK/nRF5_IoT_SDK_v0.9.x/nrf5_iot_sdk_3288530.zip && \ mkdir /usr/nrf52-sdk && \ - unzip nrf5_iot_sdk_3288530.zip -d /usr/nrf52-sdk && \ + unzip -q nrf5_iot_sdk_3288530.zip -d /usr/nrf52-sdk && \ rm nrf5_iot_sdk_3288530.zip ENV NRF52_SDK_ROOT /usr/nrf52-sdk +# Install sphinx and sphinx_rtd_theme, required for building and testing the +# readthedocs API documentation +RUN pip -q install --upgrade pip +RUN pip -q install setuptools && pip -q install sphinx_rtd_theme sphinx + # Create user, enable X forwarding, add to group dialout # -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix RUN export uid=1000 gid=1000 && \ @@ -67,24 +102,25 @@ WORKDIR ${HOME} RUN echo "#!/bin/bash\nant -Dbasedir=${COOJA} -f ${COOJA}/build.xml run" > ${HOME}/cooja && \ chmod +x ${HOME}/cooja -# Install coap-cli -RUN sudo apt-get install -y npm \ - && sudo apt-get clean \ - && sudo npm install coap-cli -g \ - && sudo ln -s /usr/bin/nodejs /usr/bin/node +# Download, build and install Renode +RUN git clone --quiet https://github.com/renode/renode.git \ + && cd ${HOME}/renode \ + && git checkout v1.3 \ + && ./build.sh +ENV PATH="${HOME}/renode:${PATH}" -# Optional: download Contiki-NG and pre-compile Cooja. -# Else, use a Docker bind mount to share the repo with the host. -# Docker run option: +# By default, we use a Docker bind mount to share the repo with the host, +# with Docker run option: # -v :/home/user/contiki-ng -RUN git clone --recursive https://github.com/contiki-ng/contiki-ng.git ${CONTIKI_NG} -RUN ant -q -f ${CONTIKI_NG}/tools/cooja/build.xml jar +# Alternatively, uncomment the next two lines to download Contiki-NG and pre-compile Cooja. +#RUN git clone --recursive https://github.com/contiki-ng/contiki-ng.git ${CONTIKI_NG} +#RUN ant -q -f ${CONTIKI_NG}/tools/cooja/build.xml jar # Working directory WORKDIR ${CONTIKI_NG} -# Enable IPv6 -- must be done at runtime, not in Dockerfile -RUN echo "sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0 > /dev/null" >> /home/user/.profile +# Enable IPv6 -- must be done at runtime, hence added to .profile +RUN echo "sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0 > /dev/null" >> ${HOME}/.profile # Start a bash CMD bash --login diff --git a/tools/doxygen/Doxyfile b/tools/doxygen/Doxyfile index a7dc79fab..dab2c18e3 100644 --- a/tools/doxygen/Doxyfile +++ b/tools/doxygen/Doxyfile @@ -809,6 +809,10 @@ EXCLUDE_SYMLINKS = NO EXCLUDE_PATTERNS = */cpu/cc26xx-cc13xx/lib/* \ */cpu/cc26xx-cc13xx/rf-core/api/* \ + */cpu/simplelink-cc13xx-cc26xx/lib/* \ + */cpu/simplelink-cc13xx-cc26xx/rf-settings/* \ + */cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/driverlib/* \ + */cpu/simplelink-cc13xx-cc26xx/cc13x0-cc26x0/rf_patches/* \ */platform/stm32nucleo-spirit1/stm32cube-lib/* \ */os/net/security/tinydtls/* diff --git a/tools/jn516x/Makefile b/tools/jn516x/Makefile deleted file mode 100644 index 2c4254a71..000000000 --- a/tools/jn516x/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -ifndef HOST_OS - ifeq ($(OS),Windows_NT) - HOST_OS := Windows - else - HOST_OS := $(shell uname) - endif -endif - -ifeq ($(HOST_OS),Windows) - SERIALDUMP = serialdump-windows -endif - -ifeq ($(HOST_OS),Darwin) - SERIALDUMP = serialdump-macos -endif - -ifndef SERIALDUMP - # Assume Linux - SERIALDUMP = serialdump-linux -endif - -all: $(SERIALDUMP) - -CFLAGS += -Wall -Werror - -$(SERIALDUMP): serialdump.c - $(CC) -O2 -o $@ $< - -clean: - rm -f $(SERIALDUMP) diff --git a/tools/jn516x/serialdump-linux b/tools/jn516x/serialdump-linux deleted file mode 100644 index 69fd8cfdb..000000000 Binary files a/tools/jn516x/serialdump-linux and /dev/null differ diff --git a/tools/jn516x/serialdump.c b/tools/jn516x/serialdump.c deleted file mode 100644 index 26b0884e2..000000000 --- a/tools/jn516x/serialdump.c +++ /dev/null @@ -1,396 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define BAUDRATE B115200 -#define BAUDRATE_S "115200" -#ifdef linux -#define MODEMDEVICE "/dev/ttyS0" -#else -#define MODEMDEVICE "/dev/com1" -#endif /* linux */ - -#define SLIP_END 0300 -#define SLIP_ESC 0333 -#define SLIP_ESC_END 0334 -#define SLIP_ESC_ESC 0335 - -#define CSNA_INIT 0x01 - -#define BUFSIZE 40 -#define HCOLS 20 -#define ICOLS 18 - -#define MODE_START_DATE 0 -#define MODE_DATE 1 -#define MODE_START_TEXT 2 -#define MODE_TEXT 3 -#define MODE_INT 4 -#define MODE_HEX 5 -#define MODE_SLIP_AUTO 6 -#define MODE_SLIP 7 -#define MODE_SLIP_HIDE 8 - -static unsigned char rxbuf[2048]; - -static int -usage(int result) -{ - printf("Usage: serialdump [-x] [-s[on]] [-i] [-bSPEED] [SERIALDEVICE]\n"); - printf(" -x for hexadecimal output\n"); - printf(" -i for decimal output\n"); - printf(" -s for automatic SLIP mode\n"); - printf(" -so for SLIP only mode (all data is SLIP packets)\n"); - printf(" -sn to hide SLIP packages\n"); - printf(" -T[format] to add time for each text line\n"); - printf(" (see man page for strftime() for format description)\n"); - return result; -} - -static void -print_hex_line(unsigned char *prefix, unsigned char *outbuf, int index) -{ - int i; - - printf("\r%s", prefix); - for(i = 0; i < index; i++) { - if((i % 4) == 0) { - printf(" "); - } - printf("%02X", outbuf[i] & 0xFF); - } - printf(" "); - for(i = index; i < HCOLS; i++) { - if((i % 4) == 0) { - printf(" "); - } - printf(" "); - } - for(i = 0; i < index; i++) { - if(outbuf[i] < 30 || outbuf[i] > 126) { - printf("."); - } else { - printf("%c", outbuf[i]); - } - } -} - -int -main(int argc, char **argv) -{ - struct termios options; - fd_set mask, smask; - int fd; - speed_t speed = BAUDRATE; - char *speedname = BAUDRATE_S; - char *device = MODEMDEVICE; - char *timeformat = NULL; - unsigned char buf[BUFSIZE], outbuf[HCOLS]; - unsigned char mode = MODE_START_TEXT; - int nfound, flags = 0; - unsigned char lastc = '\0'; - - int index = 1; - while(index < argc) { - if(argv[index][0] == '-') { - switch(argv[index][1]) { - case 'b': - /* set speed */ - if(strcmp(&argv[index][2], "38400") == 0) { - speed = B38400; - speedname = "38400"; - } else if(strcmp(&argv[index][2], "19200") == 0) { - speed = B19200; - speedname = "19200"; - } else if(strcmp(&argv[index][2], "57600") == 0) { - speed = B57600; - speedname = "57600"; - } else if(strcmp(&argv[index][2], "115200") == 0) { - speed = B115200; - speedname = "115200"; - } else if(strcmp(&argv[index][2], "230400") == 0) { - speed = B230400; - speedname = "230400"; - } else if(strcmp(&argv[index][2], "460800") == 0) { - speed = B460800; - speedname = "460800"; - } else if(strcmp(&argv[index][2], "500000") == 0) { - speed = B500000; - speedname = "500000"; - } else if(strcmp(&argv[index][2], "576000") == 0) { - speed = B576000; - speedname = "576000"; - } else if(strcmp(&argv[index][2], "921600") == 0) { - speed = B921600; - speedname = "921600"; - } else if(strcmp(&argv[index][2], "1000000") == 0) { - speed = B1000000; - speedname = "1000000"; - } else { - fprintf(stderr, "unsupported speed: %s\n", &argv[index][2]); - return usage(1); - } - break; - case 'x': - mode = MODE_HEX; - break; - case 'i': - mode = MODE_INT; - break; - case 's': - switch(argv[index][2]) { - case 'n': - mode = MODE_SLIP_HIDE; - break; - case 'o': - mode = MODE_SLIP; - break; - default: - mode = MODE_SLIP_AUTO; - break; - } - break; - case 'T': - if(strlen(&argv[index][2]) == 0) { - timeformat = "%Y-%m-%d %H:%M:%S"; - } else { - timeformat = &argv[index][2]; - } - mode = MODE_START_DATE; - break; - case 'h': - return usage(0); - default: - fprintf(stderr, "unknown option '%c'\n", argv[index][1]); - return usage(1); - } - index++; - } else { - device = argv[index++]; - if(index < argc) { - fprintf(stderr, "too many arguments\n"); - return usage(1); - } - } - } - fprintf(stderr, "connecting to %s (%s)", device, speedname); - -#ifdef O_SYNC - fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY /*| O_DIRECT*/ | O_SYNC); - if(fd < 0 && errno == EINVAL){ // O_SYNC not supported (e.g. raspberian) - fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY | O_DIRECT); - } -#else - fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY | O_SYNC ); -#endif - if(fd < 0) { - fprintf(stderr, "\n"); - perror("open"); - exit(-1); - } - fprintf(stderr, " [OK]\n"); - - if(fcntl(fd, F_SETFL, 0) < 0) { - perror("could not set fcntl"); - exit(-1); - } - - if(tcgetattr(fd, &options) < 0) { - perror("could not get options"); - exit(-1); - } - /* fprintf(stderr, "serial options set\n"); */ - cfsetispeed(&options, speed); - cfsetospeed(&options, speed); - /* Enable the receiver and set local mode */ - options.c_cflag |= (CLOCAL | CREAD); - /* Mask the character size bits and turn off (odd) parity */ - options.c_cflag &= ~(CSIZE | PARENB | PARODD); - /* Select 8 data bits */ - options.c_cflag |= CS8; - - /* Raw input */ - options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); - /* Raw output */ - options.c_oflag &= ~OPOST; - - if(tcsetattr(fd, TCSANOW, &options) < 0) { - perror("could not set options"); - exit(-1); - } - - /* Make read() return immediately */ - /* if (fcntl(fd, F_SETFL, FNDELAY) < 0) { */ - /* perror("\ncould not set fcntl"); */ - /* exit(-1); */ - /* } */ - - FD_ZERO(&mask); - FD_SET(fd, &mask); - FD_SET(fileno(stdin), &mask); - - index = 0; - for(;;) { - smask = mask; - nfound = select(FD_SETSIZE, &smask, (fd_set *) 0, (fd_set *) 0, (struct timeval *) 0); - if(nfound < 0) { - if(errno == EINTR) { - fprintf(stderr, "interrupted system call\n"); - continue; - } - /* something is very wrong! */ - perror("select"); - exit(1); - } - - if(FD_ISSET(fileno(stdin), &smask)) { - /* data from standard in */ - int n = read(fileno(stdin), buf, sizeof(buf)); - if(n < 0) { - perror("could not read"); - exit(-1); - } else if(n > 0) { - /* because commands might need parameters, lines needs to be - separated which means the terminating LF must be sent */ - /* while(n > 0 && buf[n - 1] < 32) { */ - /* n--; */ - /* } */ - if(n > 0) { - int i; - /* fprintf(stderr, "SEND %d bytes\n", n);*/ - /* write slowly */ - for(i = 0; i < n; i++) { - if(write(fd, &buf[i], 1) <= 0) { - perror("write"); - exit(1); - } else { - fflush(NULL); - usleep(6000); - } - } - } - } else { - /* End of input, exit. */ - exit(0); - } - } - - if(FD_ISSET(fd, &smask)) { - int i, j, n = read(fd, buf, sizeof(buf)); - if(n < 0) { - perror("could not read"); - exit(-1); - } - - for(i = 0; i < n; i++) { - switch(mode) { - case MODE_START_TEXT: - case MODE_TEXT: - printf("%c", buf[i]); - break; - case MODE_START_DATE: { - time_t t; - t = time(&t); - strftime(outbuf, HCOLS, timeformat, localtime(&t)); - printf("%s|", outbuf); - mode = MODE_DATE; - } - /* continue into the MODE_DATE */ - case MODE_DATE: - printf("%c", buf[i]); - if(buf[i] == '\n') { - mode = MODE_START_DATE; - } - break; - case MODE_INT: - printf("%03d ", buf[i]); - if(++index >= ICOLS) { - index = 0; - printf("\n"); - } - break; - case MODE_HEX: - rxbuf[index++] = buf[i]; - if(index >= HCOLS) { - print_hex_line("", rxbuf, index); - index = 0; - printf("\n"); - } - break; - - case MODE_SLIP_AUTO: - case MODE_SLIP_HIDE: - if(!flags && (buf[i] != SLIP_END)) { - /* Not a SLIP packet? */ - printf("%c", buf[i]); - break; - } - /* continue to slip only mode */ - case MODE_SLIP: - switch(buf[i]) { - case SLIP_ESC: - lastc = SLIP_ESC; - break; - - case SLIP_END: - if(index > 0) { - if(flags != 2 && mode != MODE_SLIP_HIDE) { - /* not overflowed: show packet */ - print_hex_line("SLIP: ", rxbuf, index > HCOLS ? HCOLS : index); - printf("\n"); - } - lastc = '\0'; - index = 0; - flags = 0; - } else { - flags = !flags; - } - break; - - default: - if(lastc == SLIP_ESC) { - lastc = '\0'; - - /* Previous read byte was an escape byte, so this byte will be - interpreted differently from others. */ - switch(buf[i]) { - case SLIP_ESC_END: - buf[i] = SLIP_END; - break; - case SLIP_ESC_ESC: - buf[i] = SLIP_ESC; - break; - } - } - - rxbuf[index++] = buf[i]; - if(index >= sizeof(rxbuf)) { - fprintf(stderr, "**** slip overflow\n"); - index = 0; - flags = 2; - } - break; - } - break; - } - } - - /* after processing for some output modes */ - if(index > 0) { - switch(mode) { - case MODE_HEX: - print_hex_line("", rxbuf, index); - break; - } - } - fflush(stdout); - } - } -} diff --git a/tools/makefsdata b/tools/makefsdata deleted file mode 100755 index 5ea48a611..000000000 --- a/tools/makefsdata +++ /dev/null @@ -1,375 +0,0 @@ -#!/usr/bin/perl -#Generate a .c source that preinitializes a file system -#David Kopf July 2009 -#Extended from the existing non-coffee tool - -#The simplest format is used with httpd-fs.c. It contains a linked -#list pointing to file names and file contents. - -#An extension uses the same linked list that points to a the file names -#and contents within a coffee file system having fixed file sizes. -#This allows the content to be rewritten by coffee while still being -#readable by httpd-fs.c New files or sector extension of existing files -#is not possible, but a larger initial sector allocation could be given -#to some files to allow a limited size increase. Since this would leave the -#wrong file size in the linked list, httpd-fs would have to terminate on -#a reverse zero scan like coffee does. Rewriting the linked list would -#probably be OK if in eeprom, but not if in program flash. Suggestions -#for a workaround would be welcome! - -#Lastly a full coffee file system can be preinitialized. File reads must -#then be done using coffee. - -#Assumes the coffee file_header structure is -#struct file_header { -# coffee_page_t log_page; -# uint16_t log_records; -# uint16_t log_record_size; -# coffee_page_t max_pages; -# uint8_t deprecated_eof_hint; -# uint8_t flags=3 for the initial value; -# char name[COFFEE_NAME_LENGTH]; -# } __attribute__((packed)); - -goto DEFAULTS; -START:$version="1.1"; - -#Process options -for($n=0;$n<=$#ARGV;$n++) { - $arg=$ARGV[$n]; - if ($arg eq "-v") { - print "makefsdata Version $version\n"; - } elsif ($arg eq "-A") { - $n++;$attribute=$ARGV[$n]; - } elsif ($arg eq "-C") { - $coffee=1; - } elsif ($arg eq "-c") { - $complement=1; - } elsif ($arg eq "-i") { - $n++;$includefile=$ARGV[$n]; -# } elsif ($arg eq "-p") { -# $n++;$coffee_page_length=$ARGV[$n]; - } elsif ($arg eq "-s") { - $n++;$coffee_sector_size=$ARGV[$n]; - } elsif ($arg eq "-t") { - $n++;$coffee_page_t =$ARGV[$n]; - } elsif ($arg eq "-f") { - $n++;$coffee_name_length=$ARGV[$n]; - } elsif ($arg eq "-S") { - $n++;$sectionname=$ARGV[$n]; - } elsif ($arg eq "-l") { - $linkedlist=1; - } elsif ($arg eq "-d") { - $n++;$directory=$ARGV[$n]; - } elsif ($arg eq "-o") { - $n++;$outputfile=$ARGV[$n]; - $coffeefile=$outputfile; - } else { -DEFAULTS: -#Set up defaults -$coffee=0; -#$coffee_page_length=256; -$coffee_sector_size=256; -$coffee_page_t=1; -$coffee_name_length=16; -$complement=0; -$directory=""; -$outputfile="httpd-fsdata.c"; -$coffeefile="httpd-coffeedata.c"; -$includefile="makefsdata.h"; -$linkedlist=0; -$attribute=""; -$sectionname=".coffeefiles"; -if (!$version) {goto START;} - print "\n"; - print "Usage: makefsdata <-d input_directory> <-o output_file>\n\n"; - print " Generates c source file to pre-initialize a contiki file system.\n"; - print " The default output is a simple linked list readable by httpd-fs.c\n"; - print " and written to $outputfile.\n\n"; - print " The -C option makes a coffee file system to default output $coffeefile.\n"; - print " A linked list can be still be generated for use with httpd-fs.c so long\n"; - print " as coffee does not extend, delete, or add any files.\n\n"; - print " The input directory structure is copied. If input_directory is specified\n"; - print " it becomes the root \"/\". If no input_directory is specified the first\n"; - print " subdirectory found in the current directory is used as the root.\n\n"; - print " WARNING : If the output file exists it will be overwritten without confirmation!\n\n"; - print " Options are:\n"; - print " -v Display the version number\n"; - print " -A attribute Append \"attribute\" to the declaration, e.g. PROGMEM to put data in AVR program flash memory\n"; - print " -C Use coffee file system format\n"; - print " -c Complement the data, useful for obscurity or fast page erases for coffee\n"; - print " -i filename Treat any input files with name \"filename\" as include files.\n"; - print " Useful for giving a server a name and ip address associated with the web content.\n"; - print " The default is $includefile.\n\n"; - print " The following apply only to coffee file system\n"; -# print " -p pagesize Page size in bytes (default $coffee_page_length)\n"; - print " -s sectorsize Sector size in bytes (default $coffee_sector_size)\n"; - print " -t page_t Number of bytes in coffee_page_t (1,2,or 4, default $coffee_page_t)\n"; - print " -f namesize File name field size in bytes (default $coffee_name_length)\n"; - print " -S section Section name for data (default $sectionname)\n"; - print " -l Append a linked list for use with httpd-fs\n"; - exit; - } -} - -#--------------------Configure parameters----------------------- -if ($coffee) { - $outputfile=$coffeefile; - $coffee_header_length=2*$coffee_page_t+$coffee_name_length+6; - if ($coffee_page_t==1) { - $coffeemax=0xff; - } elsif ($coffee_page_t==2) { - $coffeemax=0xffff; - } elsif ($coffee_page_t==4) { - $coffeemax=0xffffffff; - } else { - die "Unsupported coffee_page_t $coffee_page_t\n"; - } -} else { -# $coffee_page_length=1; - $coffee_sector_size=1; - $linkedlist=1; - $coffee_name_length=256; - $coffee_max=0xffffffff; - $coffee_header_length=0; -} -$null="0x00";if ($complement) {$null="0xff";} -$tab=" "; #optional tabs or spaces at beginning of line, e.g. "\t\t" - -#--------------------Create output file------------------------- -#awkward but could not figure out how to compare paths later unless the file exists -- dak -if (!open(OUTPUT, "> $outputfile")) {die "Aborted: Could not create output file $outputfile";} -print(OUTPUT "\n"); -close($outputfile); -use Cwd qw(abs_path); -if (!open(OUTPUT, "> $outputfile")) {die "Aborted: Could not create output file $outputfile";} -$outputfile=abs_path($outputfile); - -#--------------------Get a list of input files------------------ -if ($directory eq "") { - opendir(DIR, "."); - @files = grep { !/^\./ && !/(CVS|~)/ } readdir(DIR); - closedir(DIR); - foreach $file (@files) { - if(-d $file && $file !~ /^\./) { - $directory=$file; - break; - } - } -} -if ($directory eq "") {die "Aborted: No subdirectory in current directory";} -if (!chdir("$directory")) {die "Aborted: Directory \"$directory\" does not exist!";} - -if ($coffee) { - print "Processing directory $directory as root of coffee file system\n"; -} else { - print "Processing directory $directory as root of packed httpd-fs file system\n"; -} -opendir(DIR, "."); -@files = grep { !/^\./ && !/(CVS|~)/ && !/(makefsdata.ignore)/ } readdir(DIR); -closedir(DIR); - -foreach $file (@files) { - if(-d $file && $file !~ /^\./) { - print "Adding subdirectory $file\n"; - opendir(DIR, $file); - @newfiles = grep { !/^\./ && !/(CVS|~)/ } readdir(DIR); - closedir(DIR); -# printf "Adding files @newfiles\n"; - @files = (@files, map { $_ = "$file/$_" } @newfiles); - next; - } -} -#--------------------Write the output file------------------- -print "Writing to $outputfile\n"; -($DAY, $MONTH, $YEAR) = (localtime)[3,4,5]; -printf(OUTPUT "/*********Generated by contiki/tools/makefsdata on %04d-%02d-%02d*********/\n", $YEAR+1900, $MONTH+1, $DAY); -if ($coffee) { - print(OUTPUT "/*For coffee filesystem of sector size $coffee_sector_size and header length $coffee_header_length bytes*/\n"); -} -print(OUTPUT "\n"); -#--------------------Process include file------------------- -foreach $file (@files) {if ($file eq $includefile) { - open(FILE, $file) || die "Aborted: Could not open include file $file\n"; - print "Including text from $file\n"; - $file_length= -s FILE; - read(FILE, $data, $file_length); - print OUTPUT ($data); - close(FILE); - next; #include all include file matches -# break; #include only first include file match -}} - -#--------------------Process data files------------------- -$n=0;$coffeesize=0;$coffeesectors=0; -foreach $file (@files) {if(-f $file) { - if (length($file)>=($coffee_name_length-1)) {die "Aborted: File name $file is too long";} - if (abs_path("$file") eq abs_path("$outputfile")) { - print "Skipping output file $outputfile - recursive input NOT allowed\n"; - next; - } - if ($file eq $includefile) {next;} - open(FILE, $file) || die "Aborted: Could not open file $file\n"; - print "Adding /$file\n"; - if (grep /.png/||/.jpg/||/jpeg/||/.pdf/||/.gif/||/.bin/||/.zip/,$file) {binmode FILE;} - - $file_length= -s FILE; - $file =~ s-^-/-; - $fvar = $file; - $fvar =~ s-/-_-g; - $fvar =~ s-\.-_-g; - - if ($coffee) { - $coffee_sectors=int(($coffee_header_length+$file_length+$coffee_sector_size-1)/$coffee_sector_size); -# $coffee_sectors=sprintf("%.0f",($coffee_header_length+$file_length+$coffee_sector_size-1)/$coffee_sector_size)-1; - $coffee_length=$coffee_sectors*$coffee_sector_size; - } else { - $coffee_length=$file_length+length($file)+1; - } - $flen[$n]=$file_length; - $clen[$n]=$coffee_length; - $n++;$coffeesectors+=$coffee_sectors;$coffeesize+=$coffee_length; - if ($coffee) { - if ($coffeesectors>$coffeemax) { - print "Warning: sector number $coffeesectors overflows allocated sector size in coffee header\n"; - } - print(OUTPUT "\n__attribute__ ((section (\"$sectionname\")))\n"); - print(OUTPUT "volatile const char data".$fvar."[$coffee_length] = {\n"); - } else { - print(OUTPUT "\nconst char data".$fvar."[$coffee_length] $attribute = {\n"); - } - print(OUTPUT "$tab/* $file */\n$tab"); -#--------------------Header----------------------------- -#log_page - if ($coffee) { - print (OUTPUT " "); - for($j=0;$j<$coffee_page_t;$j++) {print (OUTPUT "$ null ,");} -#log_records, log_record_size - for($j=0;$j<4;$j++) {print (OUTPUT "$null, ");} -#max_pages - if ($complement) {$coffee_sectors=$coffee_sectors^0xffffffff;} - if ($coffee_page_t==1) { - printf(OUTPUT "0x%2.2x, ",($coffee_sectors )&0xff); - } elsif ($coffee_page_t==2) { - printf(OUTPUT "0x%2.2x, ",($coffee_sectors>> 8)&0xff); - printf(OUTPUT "0x%2.2x, ",($coffee_sectors )&0xff); - } elsif ($coffee_page_t==4) { - printf(OUTPUT "0x%2.2x, ",($coffee_sectors>>24)&0xff); - printf(OUTPUT "0x%2.2x, ",($coffee_sectors>>16)&0xff); - printf(OUTPUT "0x%2.2x, ",($coffee_sectors>> 8)&0xff); - printf(OUTPUT "0x%2.2x, ",($coffee_sectors )&0xff); - } - if ($complement) {$coffee_sectors=$coffee_sectors^0xffffffff;} -#eof hint and flags - if ($complement) { - print(OUTPUT "0xff, 0xfc,\n$tab"); - } else { - print(OUTPUT "0x00, 0x03,\n$tab"); - } - } - -#-------------------File name-------------------------- - for($j = 0; $j < length($file); $j++) { - $temp=unpack("C", substr($file, $j, 1)); - if ($complement) {$temp=$temp^0xff;} - printf(OUTPUT " %#02.2x,", $temp); - } - if ($coffee) { - for(; $j < $coffee_name_length-1; $j++) {printf(OUTPUT " $null,");} - {print(OUTPUT " $null");} - } else { - {printf(OUTPUT " $null");} - } -#------------------File Data--------------------------- - $coffee_length-=$coffee_header_length; - $i = 10; - while(read(FILE, $data, 1)) { - $temp=unpack("C", $data); - if ($complement) {$temp=$temp^0xff;} - if($i == 10) { - printf(OUTPUT ",\n$tab 0x%2.2x", $temp); - $i = 0; - } else { - printf(OUTPUT ", 0x%2.2x", $temp) - } - $i++;$coffee_length--; - } - - if ($coffee) { - print (OUTPUT ","); - while (--$coffee_length) { - if($i==9) { - print(OUTPUT " $null,\n$tab"); - $i = 0; - } else { - print (OUTPUT " $null,"); - $i++; - } - } - print (OUTPUT " $null"); - } - print (OUTPUT "};\n"); - close(FILE); - push(@fvars, $fvar); - push(@pfiles, $file); -}} - -if ($linkedlist) { -#-------------------httpd_fsdata_file links------------------- -#The non-coffee PROGMEM flash file system for the Raven webserver uses a linked flash list as follows: -print(OUTPUT "\n\n/* Structure of linked list (all offsets relative to start of section):\n"); -print(OUTPUT "struct httpd_fsdata_file {\n"); -print(OUTPUT "$tab const struct httpd_fsdata_file *next; //actual flash address of next link\n"); -print(OUTPUT "$tab const char *name; //offset to coffee file name\n"); -print(OUTPUT "$tab const char *data; //offset to coffee file data\n"); -print(OUTPUT "$tab const int len; //length of file data\n"); -print(OUTPUT "#if HTTPD_FS_STATISTICS == 1 //not enabled since list is in PROGMEM\n"); -print(OUTPUT "$tab uint16_t count; //storage for file statistics\n"); -print(OUTPUT "#endif\n"); -print(OUTPUT "}\n*/\n"); - -# For the static httpd-fs.c file system the file name and data addresses in the linked list -# point to the actual memory locations. -# For the coffee file system the addresses start from zero. The starting address must be added -# in the coffee read routine. - -for($i = 0; $i < @fvars; $i++) { - $file = $pfiles[$i]; - $fvar = $fvars[$i]; - if($i == 0) { - $prevfile = "NULL"; - $data_offset=0; - } else { - $data_offset=$data_offset+$clen[$i-1]; - $prevfile = "file" . $fvars[$i - 1]; - } - $filename_offset=$data_offset+6+2*$coffee_page_t; - $coffee_offset=$data_offset+$coffee_header_length; - if ($coffee_offset>0xffff) {print "Warning : Linked list offset field overflow\n";} - print(OUTPUT "const struct httpd_fsdata_file"); - for ($t=length($file);$t<16;$t++) {print(OUTPUT " ")}; - print(OUTPUT " file".$fvar."[] "); - if ($attribute) {print(OUTPUT "$attribute ");} - print(OUTPUT "={{"); - for ($t=length($prevfile);$t<20;$t++) {print(OUTPUT " ")}; - print(OUTPUT "$prevfile, "); - if ($coffee) { - printf(OUTPUT "(const char *)0x%4.4x, ",$filename_offset); - printf(OUTPUT "(const char *)0x%4.4x, ",$coffee_offset); - printf(OUTPUT "%5u}};\n",$flen[$i]); - } else { - print(OUTPUT "data$fvar"); - for ($t=length($file);$t<15;$t++) {print(OUTPUT " ")}; - print(OUTPUT ", data$fvar"); - for ($t=length($file);$t<15;$t++) {print(OUTPUT " ")}; - print(OUTPUT " +".(length($file)+1).", sizeof(data$fvar)"); - for ($t=length($file);$t<16;$t++) {print(OUTPUT " ")}; - print(OUTPUT " -".(length($file)+1)."}};\n"); - } -} -print(OUTPUT "\n#define HTTPD_FS_ROOT file$fvars[$n-1]\n"); -print(OUTPUT "#define HTTPD_FS_NUMFILES $n\n"); -print(OUTPUT "#define HTTPD_FS_SIZE $coffeesize\n"); -} -print "All done, files occupy $coffeesize bytes\n"; - diff --git a/tools/motelist b/tools/motelist new file mode 160000 index 000000000..2f089ac92 --- /dev/null +++ b/tools/motelist @@ -0,0 +1 @@ +Subproject commit 2f089ac9277521b32371e68391e53d0bd0017288 diff --git a/tools/readthedocs/Makefile b/tools/readthedocs/Makefile new file mode 100644 index 000000000..ecf5b58d4 --- /dev/null +++ b/tools/readthedocs/Makefile @@ -0,0 +1,19 @@ +# Makefile used to generate documentation with sphinx, which is used on +# readthedocs. Use this Makefile to test readthedocs generation locally on +# your computer. +# +# For this to work, you will need to install sphinx and sphinx_rtd_theme. They +# can be installed through pip +.PHONY = clean all readthedocs + +SPHINX = sphinx-build +SPHINX_CONF_DIR = . +SPHINX_OUT_DIR = _build + +all: readthedocs + +clean: + rm -rf $(SPHINX_OUT_DIR) + +readthedocs: + $(SPHINX) -b html $(SPHINX_CONF_DIR) $(SPHINX_OUT_DIR) diff --git a/tools/readthedocs/api-doc.py b/tools/readthedocs/api-doc.py new file mode 100644 index 000000000..c59b0864e --- /dev/null +++ b/tools/readthedocs/api-doc.py @@ -0,0 +1,65 @@ +# Sphinx extension that builds Contiki-NG documentation and copies it over to +# the sphinx build dir +import subprocess +from sphinx.util import logging +logger = logging.getLogger(__name__) + + +api_doc_defaults = { + 'doxygen_src_dir': '../doxygen', + 'doxygen_out_dir': 'html', + 'doxygen_suppress_out': True, + 'doxygen_build': True, +} + + +def api_doc_build(app, exception): + if exception is not None: + logger.warning('%s exiting without building' % (__name__,)) + return + + if app.config.api_doc_doxygen_build: + make_invocation_suffix = ('> /dev/null' + if app.config.api_doc_doxygen_suppress_out + else '') + make_invocation = ' '.join(('make -C', + app.config.api_doc_doxygen_src_dir, + make_invocation_suffix)) + + logger.info('%s building API docs from "%s"' + % (__name__, app.config.api_doc_doxygen_src_dir)) + logger.info('%s executing "%s"' + % (__name__, make_invocation)) + + subprocess.call(make_invocation, shell=True) + + api_doc_build_dir = "/".join((app.config.api_doc_doxygen_src_dir, + app.config.api_doc_doxygen_out_dir)) + api_doc_static_api_dir = "/".join((app.outdir, '_api')) + + logger.info('%s moving "%s" to "%s"' + % (__name__, api_doc_build_dir, api_doc_static_api_dir)) + subprocess.call(' '.join(('mv', api_doc_build_dir, + api_doc_static_api_dir)), + shell=True) + + # Fundamentally a workaround: Readthedocs doxygen build plain refulses + # to build the same html/*.js files as local builds do. So we ship them + # and we copy them over to the output dir by force, till readthedocs + # starts behaving, hopefully in the near future + subprocess.call(' '.join(('cp js/dynsections.js', + api_doc_static_api_dir)), + shell=True) + + +def setup(app): + for k, v in api_doc_defaults.items(): + config_val = 'api_doc_' + k + logger.debug('Add config value %s: %s' %(config_val, v)) + app.add_config_value(config_val, v, '') + + # We will build and copy the docs after the end of the sphinx build, and. + # only if it has been successful. Regsiter for the build-finished event. + app.connect('build-finished', api_doc_build) + + logger.info('%s initialised' % (__name__,)) diff --git a/tools/readthedocs/conf.py b/tools/readthedocs/conf.py new file mode 100644 index 000000000..50e43737e --- /dev/null +++ b/tools/readthedocs/conf.py @@ -0,0 +1,112 @@ +# -*- coding: utf-8 -*- +# +# Configuration file for the Sphinx documentation builder. +# +# This file does only contain a selection of the most common options. For a +# full list see the documentation: +# http://www.sphinx-doc.org/en/master/config + + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +import os +import sys +sys.path.insert(0, os.path.abspath('.')) + + +# -- Project information ----------------------------------------------------- + +project = u'Contiki-NG' +copyright = u'2018, Contiki-NG maintainers and contributors' +author = u'Contiki-NG maintainers and contributors' + +# The short X.Y version +version = u'' +# The full version, including alpha/beta/rc tags +release = u'' + + +# -- General configuration --------------------------------------------------- + +# If your documentation needs a minimal Sphinx version, state it here. +# +# needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + 'api-doc' +] + +# api-doc configuration +api_doc_doxygen_src_dir = '../doxygen' +api_doc_doxygen_out_dir = 'html' +api_doc_doxygen_suppress_out = True +api_doc_doxygen_build = True + +# Add any paths that contain templates here, relative to this directory. +#templates_path = ['_templates'] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# +# source_suffix = ['.rst', '.md'] +source_suffix = '.rst' + +# The master toctree document. +master_doc = 'index' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path . +exclude_patterns = [u'_build', 'Thumbs.db', '.DS_Store'] + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'sphinx_rtd_theme' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +# +# html_theme_options = {} + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +#html_static_path = ['_static'] + +# Custom sidebar templates, must be a dictionary that maps document names +# to template names. +# +# The default sidebars (for documents that don't match any pattern) are +# defined by theme itself. Builtin themes are using these templates by +# default: ``['localtoc.html', 'relations.html', 'sourcelink.html', +# 'searchbox.html']``. +# +# html_sidebars = {} + + +# -- Options for HTMLHelp output --------------------------------------------- + +# Output file base name for HTML help builder. +htmlhelp_basename = 'Contiki-NGdoc' diff --git a/tools/readthedocs/index.rst b/tools/readthedocs/index.rst new file mode 100644 index 000000000..794c0866b --- /dev/null +++ b/tools/readthedocs/index.rst @@ -0,0 +1,23 @@ +Contiki-NG API documentation! +============================= + +These pages host Contiki-NG's API documentation. + +The primary target audience +consists developers who want to develop an application with Contiki-NG or who +want to modify Contiki-NG itself. + +For guides and tutorials, visit the `Contiki-NG wiki`_. + +Index +===== +* `API Home`_ +* `List of Modules`_ +* `Data Structure Index`_ +* `Index of Files`_ + +.. _Contiki-NG wiki: https://github.com/contiki-ng/contiki-ng/wiki +.. _API Home: _api/index.html +.. _List of Modules: _api/modules.html +.. _Data Structure Index: _api/annotated.html +.. _Index of Files: _api/files.html diff --git a/tools/readthedocs/js/dynsections.js b/tools/readthedocs/js/dynsections.js new file mode 100644 index 000000000..537e3e498 --- /dev/null +++ b/tools/readthedocs/js/dynsections.js @@ -0,0 +1,127 @@ +/* + @licstart The following is the entire license notice for the + JavaScript code in this file. + + Copyright (C) 1997-2017 by Dimitri van Heesch + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + @licend The above is the entire license notice + for the JavaScript code in this file + */ +function toggleVisibility(linkObj) +{ + var base = $(linkObj).attr('id'); + var summary = $('#'+base+'-summary'); + var content = $('#'+base+'-content'); + var trigger = $('#'+base+'-trigger'); + var src=$(trigger).attr('src'); + if (content.is(':visible')===true) { + content.hide(); + summary.show(); + $(linkObj).addClass('closed').removeClass('opened'); + $(trigger).attr('src',src.substring(0,src.length-8)+'closed.png'); + } else { + content.show(); + summary.hide(); + $(linkObj).removeClass('closed').addClass('opened'); + $(trigger).attr('src',src.substring(0,src.length-10)+'open.png'); + } + return false; +} + +function updateStripes() +{ + $('table.directory tr'). + removeClass('even').filter(':visible:even').addClass('even'); +} + +function toggleLevel(level) +{ + $('table.directory tr').each(function() { + var l = this.id.split('_').length-1; + var i = $('#img'+this.id.substring(3)); + var a = $('#arr'+this.id.substring(3)); + if (l #include #include @@ -9,15 +12,18 @@ #include #include #include - +/*---------------------------------------------------------------------------*/ #define BAUDRATE B115200 #define BAUDRATE_S "115200" + +speed_t b_rate = BAUDRATE; +/*---------------------------------------------------------------------------*/ #ifdef linux #define MODEMDEVICE "/dev/ttyS0" #else #define MODEMDEVICE "/dev/com1" #endif /* linux */ - +/*---------------------------------------------------------------------------*/ #define SLIP_END 0300 #define SLIP_ESC 0333 #define SLIP_ESC_END 0334 @@ -38,13 +44,19 @@ #define MODE_SLIP_AUTO 6 #define MODE_SLIP 7 #define MODE_SLIP_HIDE 8 +/*---------------------------------------------------------------------------*/ +#ifndef O_SYNC +#define O_SYNC 0 +#endif +#define OPEN_FLAGS (O_RDWR | O_NOCTTY | O_NDELAY | O_SYNC) +/*---------------------------------------------------------------------------*/ static unsigned char rxbuf[2048]; - +/*---------------------------------------------------------------------------*/ static int usage(int result) { - printf("Usage: serialdump [-x] [-s[on]] [-i] [-bSPEED] [SERIALDEVICE]\n"); + printf("Usage: serialdump [-x] [-s[on]] [-i] [-bSPEED] T[format] [SERIALDEVICE]\n"); printf(" -x for hexadecimal output\n"); printf(" -i for decimal output\n"); printf(" -s for automatic SLIP mode\n"); @@ -54,7 +66,7 @@ usage(int result) printf(" (see man page for strftime() for format description)\n"); return result; } - +/*---------------------------------------------------------------------------*/ static void print_hex_line(char *prefix, unsigned char *outbuf, int index) { @@ -82,13 +94,13 @@ print_hex_line(char *prefix, unsigned char *outbuf, int index) } } } - +/*---------------------------------------------------------------------------*/ static void intHandler(int sig) { exit(0); } - +/*---------------------------------------------------------------------------*/ int main(int argc, char **argv) { @@ -97,8 +109,7 @@ main(int argc, char **argv) struct termios options; fd_set mask, smask; int fd; - speed_t speed = BAUDRATE; - char *speedname = BAUDRATE_S; + int baudrate = BUNKNOWN; char *device = MODEMDEVICE; char *timeformat = NULL; unsigned char buf[BUFSIZE]; @@ -111,57 +122,41 @@ main(int argc, char **argv) while(index < argc) { if(argv[index][0] == '-') { switch(argv[index][1]) { - case 'b': - /* set speed */ - if(strcmp(&argv[index][2], "38400") == 0) { - speed = B38400; - speedname = "38400"; - } else if(strcmp(&argv[index][2], "19200") == 0) { - speed = B19200; - speedname = "19200"; - } else if(strcmp(&argv[index][2], "57600") == 0) { - speed = B57600; - speedname = "57600"; - } else if(strcmp(&argv[index][2], "115200") == 0) { - speed = B115200; - speedname = "115200"; - } else { - fprintf(stderr, "unsupported speed: %s\n", &argv[index][2]); - return usage(1); - } + case 'b': + baudrate = atoi(&argv[index][2]); + break; + case 'x': + mode = MODE_HEX; + break; + case 'i': + mode = MODE_INT; + break; + case 's': + switch(argv[index][2]) { + case 'n': + mode = MODE_SLIP_HIDE; break; - case 'x': - mode = MODE_HEX; + case 'o': + mode = MODE_SLIP; break; - case 'i': - mode = MODE_INT; - break; - case 's': - switch(argv[index][2]) { - case 'n': - mode = MODE_SLIP_HIDE; - break; - case 'o': - mode = MODE_SLIP; - break; - default: - mode = MODE_SLIP_AUTO; - break; - } - break; - case 'T': - if(strlen(&argv[index][2]) == 0) { - timeformat = "%Y-%m-%d %H:%M:%S"; - } else { - timeformat = &argv[index][2]; - } - mode = MODE_START_DATE; - break; - case 'h': - return usage(0); default: - fprintf(stderr, "unknown option '%c'\n", argv[index][1]); - return usage(1); + mode = MODE_SLIP_AUTO; + break; + } + break; + case 'T': + if(strlen(&argv[index][2]) == 0) { + timeformat = "%Y-%m-%d %H:%M:%S"; + } else { + timeformat = &argv[index][2]; + } + mode = MODE_START_DATE; + break; + case 'h': + return usage(0); + default: + fprintf(stderr, "unknown option '%c'\n", argv[index][1]); + return usage(1); } index++; } else { @@ -172,24 +167,19 @@ main(int argc, char **argv) } } } - fprintf(stderr, "connecting to %s (%s)", device, speedname); - - -#ifndef O_SYNC -#define O_SYNC 0 -#endif -#ifdef O_DIRECT - fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY | O_DIRECT | O_SYNC); - /* Some systems do not support certain parameters (e.g. raspbian) - * Just do some random testing. Not sure whether there is a better way - * of doing this. */ - if(fd < 0 && errno == EINVAL){ - fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY | O_SYNC); + if(baudrate != BUNKNOWN) { + b_rate = select_baudrate(baudrate); + if(b_rate == 0) { + fprintf(stderr, "unknown baudrate %d\n", baudrate); + exit(-1); + } } -#else - fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY | O_SYNC); -#endif + + fprintf(stderr, "connecting to %s", device); + + fd = open(device, OPEN_FLAGS); + if(fd < 0) { fprintf(stderr, "\n"); perror("open"); @@ -206,9 +196,10 @@ main(int argc, char **argv) perror("could not get options"); exit(-1); } - /* fprintf(stderr, "serial options set\n"); */ - cfsetispeed(&options, speed); - cfsetospeed(&options, speed); + + cfsetispeed(&options, b_rate); + cfsetospeed(&options, b_rate); + /* Enable the receiver and set local mode */ options.c_cflag |= (CLOCAL | CREAD); /* Mask the character size bits and turn off (odd) parity */ @@ -228,12 +219,6 @@ main(int argc, char **argv) exit(-1); } - /* Make read() return immediately */ - /* if (fcntl(fd, F_SETFL, FNDELAY) < 0) { */ - /* perror("\ncould not set fcntl"); */ - /* exit(-1); */ - /* } */ - FD_ZERO(&mask); FD_SET(fd, &mask); FD_SET(fileno(stdin), &mask); @@ -241,7 +226,7 @@ main(int argc, char **argv) index = 0; for(;;) { smask = mask; - nfound = select(FD_SETSIZE, &smask, (fd_set *) 0, (fd_set *) 0, (struct timeval *) 0); + nfound = select(FD_SETSIZE, &smask, (fd_set *)0, (fd_set *)0, (struct timeval *)0); if(nfound < 0) { if(errno == EINTR) { fprintf(stderr, "interrupted system call\n"); @@ -260,7 +245,7 @@ main(int argc, char **argv) exit(-1); } else if(n > 0) { /* because commands might need parameters, lines needs to be - separated which means the terminating LF must be sent */ + separated which means the terminating LF must be sent */ /* while(n > 0 && buf[n - 1] < 32) { */ /* n--; */ /* } */ @@ -298,103 +283,103 @@ main(int argc, char **argv) for(i = 0; i < n; i++) { switch(mode) { - case MODE_START_TEXT: - case MODE_TEXT: - printf("%c", buf[i]); - break; - case MODE_START_DATE: { - time_t t; - t = time(&t); - strftime(outbuf, HCOLS, timeformat, localtime(&t)); - printf("%s|", outbuf); - mode = MODE_DATE; + case MODE_START_TEXT: + case MODE_TEXT: + printf("%c", buf[i]); + break; + case MODE_START_DATE: { + time_t t; + t = time(&t); + strftime(outbuf, HCOLS, timeformat, localtime(&t)); + printf("[%s] ", outbuf); + mode = MODE_DATE; + } + /* continue into the MODE_DATE */ + case MODE_DATE: + printf("%c", buf[i]); + if(buf[i] == '\n') { + mode = MODE_START_DATE; } - /* continue into the MODE_DATE */ - case MODE_DATE: + break; + case MODE_INT: + printf("%03d ", buf[i]); + if(++index >= ICOLS) { + index = 0; + printf("\n"); + } + break; + case MODE_HEX: + rxbuf[index++] = buf[i]; + if(index >= HCOLS) { + print_hex_line("", rxbuf, index); + index = 0; + printf("\n"); + } + break; + + case MODE_SLIP_AUTO: + case MODE_SLIP_HIDE: + if(!flags && (buf[i] != SLIP_END)) { + /* Not a SLIP packet? */ printf("%c", buf[i]); - if(buf[i] == '\n') { - mode = MODE_START_DATE; - } break; - case MODE_INT: - printf("%03d ", buf[i]); - if(++index >= ICOLS) { + } + /* continue to slip only mode */ + case MODE_SLIP: + switch(buf[i]) { + case SLIP_ESC: + lastc = SLIP_ESC; + break; + + case SLIP_END: + if(index > 0) { + if(flags != 2 && mode != MODE_SLIP_HIDE) { + /* not overflowed: show packet */ + print_hex_line("SLIP: ", rxbuf, index > HCOLS ? HCOLS : index); + printf("\n"); + } + lastc = '\0'; index = 0; - printf("\n"); + flags = 0; + } else { + flags = !flags; } break; - case MODE_HEX: + + default: + if(lastc == SLIP_ESC) { + lastc = '\0'; + + /* Previous read byte was an escape byte, so this byte will be + interpreted differently from others. */ + switch(buf[i]) { + case SLIP_ESC_END: + buf[i] = SLIP_END; + break; + case SLIP_ESC_ESC: + buf[i] = SLIP_ESC; + break; + } + } + rxbuf[index++] = buf[i]; - if(index >= HCOLS) { - print_hex_line("", rxbuf, index); + if(index >= sizeof(rxbuf)) { + fprintf(stderr, "**** slip overflow\n"); index = 0; - printf("\n"); - } - break; - - case MODE_SLIP_AUTO: - case MODE_SLIP_HIDE: - if(!flags && (buf[i] != SLIP_END)) { - /* Not a SLIP packet? */ - printf("%c", buf[i]); - break; - } - /* continue to slip only mode */ - case MODE_SLIP: - switch(buf[i]) { - case SLIP_ESC: - lastc = SLIP_ESC; - break; - - case SLIP_END: - if(index > 0) { - if(flags != 2 && mode != MODE_SLIP_HIDE) { - /* not overflowed: show packet */ - print_hex_line("SLIP: ", rxbuf, index > HCOLS ? HCOLS : index); - printf("\n"); - } - lastc = '\0'; - index = 0; - flags = 0; - } else { - flags = !flags; - } - break; - - default: - if(lastc == SLIP_ESC) { - lastc = '\0'; - - /* Previous read byte was an escape byte, so this byte will be - interpreted differently from others. */ - switch(buf[i]) { - case SLIP_ESC_END: - buf[i] = SLIP_END; - break; - case SLIP_ESC_ESC: - buf[i] = SLIP_ESC; - break; - } - } - - rxbuf[index++] = buf[i]; - if(index >= sizeof(rxbuf)) { - fprintf(stderr, "**** slip overflow\n"); - index = 0; - flags = 2; - } - break; + flags = 2; } break; + } + break; } } /* after processing for some output modes */ if(index > 0) { switch(mode) { - case MODE_HEX: - print_hex_line("", rxbuf, index); - break; + case MODE_HEX: + print_hex_line("", rxbuf, index); + break; } } fflush(stdout); diff --git a/tools/tools-utils.c b/tools/serial-io/tools-utils.c similarity index 98% rename from tools/tools-utils.c rename to tools/serial-io/tools-utils.c index 6ad0a9365..8e292e9b3 100644 --- a/tools/tools-utils.c +++ b/tools/serial-io/tools-utils.c @@ -30,7 +30,7 @@ * */ -#include "tools-utils.h" +#include "tools-utils.h" speed_t select_baudrate(int baudrate) { @@ -104,6 +104,7 @@ select_baudrate(int baudrate) { return B115200; #endif #ifdef B230400 + case 230400: return B230400; #endif #ifdef B460800 @@ -158,4 +159,3 @@ select_baudrate(int baudrate) { return 0; } } - diff --git a/tools/tools-utils.h b/tools/serial-io/tools-utils.h similarity index 97% rename from tools/tools-utils.h rename to tools/serial-io/tools-utils.h index 4b996cc75..c3e655305 100644 --- a/tools/tools-utils.h +++ b/tools/serial-io/tools-utils.h @@ -35,6 +35,9 @@ #include +/* The unspecified baudrate */ +#define BUNKNOWN -2 + #if __APPLE__ #ifndef B460800 #define B460800 460800 diff --git a/tools/tunslip6.c b/tools/serial-io/tunslip6.c similarity index 98% rename from tools/tunslip6.c rename to tools/serial-io/tunslip6.c index e1a72078a..48b0ecd0f 100644 --- a/tools/tunslip6.c +++ b/tools/serial-io/tunslip6.c @@ -579,8 +579,10 @@ tun_alloc(char *dev, int tap) * IFF_NO_PI - Do not provide packet information */ ifr.ifr_flags = (tap ? IFF_TAP : IFF_TUN) | IFF_NO_PI; - if(*dev != 0) - strncpy(ifr.ifr_name, dev, IFNAMSIZ); + if(*dev != 0) { + strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name) - 1); + ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0'; + } if((err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ) { close(fd); @@ -793,9 +795,9 @@ main(int argc, char **argv) case 's': if(strncmp("/dev/", optarg, 5) == 0) { - siodev = optarg + 5; + siodev = optarg + 5; } else { - siodev = optarg; + siodev = optarg; } break; @@ -806,10 +808,11 @@ main(int argc, char **argv) case 't': if(strncmp("/dev/", optarg, 5) == 0) { - strncpy(tundev, optarg + 5, sizeof(tundev)); + strncpy(tundev, optarg + 5, sizeof(tundev) - 1); } else { - strncpy(tundev, optarg, sizeof(tundev)); + strncpy(tundev, optarg, sizeof(tundev) - 1); } + tundev[sizeof(tundev) - 1] = '\0'; break; case 'a': @@ -885,6 +888,17 @@ exit(1); } } +#ifdef __APPLE__ + if(*tundev == '\0') { + /* Use default. */ + if(tap) { + strcpy(tundev, "tap0"); + } else { + strcpy(tundev, "tun0"); + } + } +#endif + if(host != NULL) { struct addrinfo hints, *servinfo, *p; int rv; diff --git a/tools/sky/Makefile b/tools/sky/Makefile deleted file mode 100644 index 2c4254a71..000000000 --- a/tools/sky/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -ifndef HOST_OS - ifeq ($(OS),Windows_NT) - HOST_OS := Windows - else - HOST_OS := $(shell uname) - endif -endif - -ifeq ($(HOST_OS),Windows) - SERIALDUMP = serialdump-windows -endif - -ifeq ($(HOST_OS),Darwin) - SERIALDUMP = serialdump-macos -endif - -ifndef SERIALDUMP - # Assume Linux - SERIALDUMP = serialdump-linux -endif - -all: $(SERIALDUMP) - -CFLAGS += -Wall -Werror - -$(SERIALDUMP): serialdump.c - $(CC) -O2 -o $@ $< - -clean: - rm -f $(SERIALDUMP) diff --git a/tools/sky/serialdump-linux b/tools/sky/serialdump-linux deleted file mode 100755 index 4d3e616a9..000000000 Binary files a/tools/sky/serialdump-linux and /dev/null differ diff --git a/tools/sky/serialdump-macos b/tools/sky/serialdump-macos deleted file mode 100755 index 775f88707..000000000 Binary files a/tools/sky/serialdump-macos and /dev/null differ diff --git a/tools/sky/serialdump-windows.exe b/tools/sky/serialdump-windows.exe deleted file mode 100755 index 11ac7cae6..000000000 Binary files a/tools/sky/serialdump-windows.exe and /dev/null differ diff --git a/tools/timestamp b/tools/timestamp deleted file mode 100755 index 16db8c988..000000000 --- a/tools/timestamp +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -# We run perl through a shell to avoid having to hard-code the path to perl -perl -e '$|=1; while(<>) {print time . " $_";}' diff --git a/tools/vagrant/bootstrap.sh b/tools/vagrant/bootstrap.sh index 996ffb12e..1a7c2a5a6 100755 --- a/tools/vagrant/bootstrap.sh +++ b/tools/vagrant/bootstrap.sh @@ -1,15 +1,14 @@ #!/usr/bin/env bash -# i386 binary support on x64 system +# Install i386 binary support on x64 system and required tools sudo dpkg --add-architecture i386 sudo apt update sudo apt install -y --no-install-recommends \ - libc6:i386 libstdc++6:i386 libncurses5:i386 libz1:i386 + libc6:i386 libstdc++6:i386 libncurses5:i386 libz1:i386 \ + build-essential doxygen git wget unzip python-serial rlwrap npm \ + default-jdk ant srecord python-pip iputils-tracepath uncrustify \ + python-magic linux-image-extra-virtual -# Tools -sudo apt-get install -y --no-install-recommends \ - build-essential doxygen git wget unzip python-serial \ - default-jdk ant srecord python-pip iputils-tracepath uncrustify python-magic sudo apt-get clean sudo python2 -m pip install intelhex @@ -61,8 +60,6 @@ source ${HOME}/.bashrc echo "#!/bin/bash\nant -Dbasedir=${COOJA} -f ${COOJA}/build.xml run" > ${HOME}/cooja && chmod +x ${HOME}/cooja # Install coap-cli -sudo apt-get install -y npm -sudo apt-get clean sudo npm install coap-cli -g sudo ln -s /usr/bin/nodejs /usr/bin/node diff --git a/tools/viewconf.c b/tools/viewconf/viewconf.c similarity index 92% rename from tools/viewconf.c rename to tools/viewconf/viewconf.c index 5e6ee3d5e..b5fe8dc7f 100644 --- a/tools/viewconf.c +++ b/tools/viewconf/viewconf.c @@ -16,18 +16,18 @@ ##### "CONTIKI_VERSION_STRING": ________________ == CONTIKI_VERSION_STRING -#ifdef IEEE802154_CONF_PANID -##### "IEEE802154_CONF_PANID":__________________ == IEEE802154_CONF_PANID -#else -##### "IEEE802154_CONF_PANID":__________________ == IEEE802154_PANID -#endif - #ifdef FRAME802154_CONF_VERSION ##### "FRAME802154_CONF_VERSION":_______________ == FRAME802154_CONF_VERSION #else ##### "FRAME802154_CONF_VERSION":_______________ == FRAME802154_VERSION #endif +#ifdef IEEE802154_CONF_PANID +##### "IEEE802154_CONF_PANID":__________________ == IEEE802154_CONF_PANID +#else +##### "IEEE802154_CONF_PANID":__________________ == IEEE802154_PANID +#endif + #if MAC_CONF_WITH_TSCH #ifdef TSCH_CONF_DEFAULT_HOPPING_SEQUENCE @@ -54,10 +54,10 @@ ##### "TSCH_CONF_MAX_EB_PERIOD": _______________ -> TSCH_MAX_EB_PERIOD #endif -#if TSCH_CONF_DEFAULT_TIMESLOT_LENGTH -##### "TSCH_CONF_DEFAULT_TIMESLOT_LENGTH": _____ == TSCH_CONF_DEFAULT_TIMESLOT_LENGTH +#ifdef TSCH_CONF_DEFAULT_TIMESLOT_TIMING +##### "TSCH_CONF_DEFAULT_TIMESLOT_TIMING": _____ == TSCH_CONF_DEFAULT_TIMESLOT_TIMING #else -##### "TSCH_CONF_DEFAULT_TIMESLOT_LENGTH": _____ -> TSCH_DEFAULT_TIMESLOT_LENGTH +##### "TSCH_CONF_DEFAULT_TIMESLOT_TIMING": _____ -> TSCH_DEFAULT_TIMESLOT_TIMING #endif #ifdef TSCH_SCHEDULE_CONF_DEFAULT_LENGTH @@ -68,10 +68,10 @@ #else /* MAC_CONF_WITH_TSCH */ -#ifdef RF_CHANNEL -##### "RF_CHANNEL": ____________________________ == RF_CHANNEL +#ifdef IEEE802154_CONF_DEFAULT_CHANNEL +##### "IEEE802154_CONF_DEFAULT_CHANNEL": _______ == IEEE802154_CONF_DEFAULT_CHANNEL #else -##### "RF_CHANNEL": ____________________________ >< +##### "IEEE802154_CONF_DEFAULT_CHANNEL": _______ -> IEEE802154_DEFAULT_CHANNEL #endif #endif /*MAC_CONF_WITH_TSCH */ diff --git a/tools/zolertia/license-bsl.txt b/tools/zolertia/license-bsl.txt deleted file mode 100644 index e6775e9d7..000000000 --- a/tools/zolertia/license-bsl.txt +++ /dev/null @@ -1,62 +0,0 @@ -Copyright (c) 2001-2003 Chris Liechti - -All Rights Reserved. - -This is the Python license. In short, you can use this product in -commercial and non-commercial applications, modify it, redistribute it. -A notification to the author when you use and/or modify it is welcome. - -TERMS AND CONDITIONS FOR ACCESSING OR OTHERWISE USING THIS SOFTWARE -============================================ - -LICENSE AGREEMENT ------------------ - -1. This LICENSE AGREEMENT is between the copyright holder of this -product, and the Individual or Organization ("Licensee") accessing -and otherwise using this product in source or binary form and its -associated documentation. - -2. Subject to the terms and conditions of this License Agreement, -the copyright holder hereby grants Licensee a nonexclusive, -royalty-free, world-wide license to reproduce, analyze, test, -perform and/or display publicly, prepare derivative works, distribute, -and otherwise use this product alone or in any derivative version, -provided, however, that copyright holders License Agreement and -copyright holders notice of copyright are retained in this product -alone or in any derivative version prepared by Licensee. - -3. In the event Licensee prepares a derivative work that is based on -or incorporates this product or any part thereof, and wants to make -the derivative work available to others as provided herein, then -Licensee hereby agrees to include in any such work a brief summary of -the changes made to this product. - -4. The copyright holder is making this product available to Licensee -on an "AS IS" basis. THE COPYRIGHT HOLDER MAKES NO REPRESENTATIONS -OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE, BUT NOT -LIMITATION, THE COPYRIGHT HOLDER MAKES NO AND DISCLAIMS ANY -REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS FOR -ANY PARTICULAR PURPOSE OR THAT THE USE OF THIS PRODUCT WILL -NOT INFRINGE ANY THIRD PARTY RIGHTS. - -5. THE COPYRIGHT HOLDER SHALL NOT BE LIABLE TO LICENSEE OR ANY -OTHER USERS OF THIS PRODUCT FOR ANY INCIDENTAL, SPECIAL, OR -CONSEQUENTIAL DAMAGES OR LOSS AS A RESULT OF MODIFYING, -DISTRIBUTING, OR OTHERWISE USING THIS PRODUCT, OR ANY -DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY -THEREOF. - -6. This License Agreement will automatically terminate upon a -material breach of its terms and conditions. - -7. Nothing in this License Agreement shall be deemed to create any -relationship of agency, partnership, or joint venture between the -copyright holder and Licensee. This License Agreement does not grant -permission to use trademarks or trade names from the copyright holder -in a trademark sense to endorse or promote products or services of -Licensee, or any third party. - -8. By copying, installing or otherwise using this product, Licensee -agrees to be bound by the terms and conditions of this License -Agreement. diff --git a/tools/zolertia/motelist-zolertia b/tools/zolertia/motelist-zolertia deleted file mode 100755 index e5f7da99e..000000000 --- a/tools/zolertia/motelist-zolertia +++ /dev/null @@ -1,295 +0,0 @@ -#!/usr/bin/perl -w -use strict; -# $Id: motelist-z1,v 1.1 2010/08/24 15:48:20 joxe Exp $ -# @author Cory Sharp -# @author Joe Polastre - -my $help = <<'EOF'; -usage: motelist [options] - - $Revision: 1.1 $ - -options: - -h display this help - -c compact format, not pretty but easier for parsing - -f specify the usb-serial file (for smote.cs) - -k kernel version: 2.4, 2.6, auto (default) - -m method to scan usb: procfs, sysfs, auto (default) - -dev_prefix force the device prefix for the serial device - -usb display extra usb information - -b specify which Zolertia board to list (z1, remote, etc) -EOF - -my %Opt = ( - compact => 0, - usb => 0, - board => "", - method => "auto", - kernel => "auto", - dev_prefix => [ "/dev/usb/tts/", "/dev/ttyUSB", "/dev/tts/USB" ], - usbserial => "sudo cat /proc/tty/driver/usbserial |", -); - -while (@ARGV) { - last unless $ARGV[0] =~ /^-/; - my $opt = shift @ARGV; - if( $opt eq "-h" ) { print "$help\n"; exit 0; } - elsif( $opt eq "-c" ) { $Opt{compact} = 1; } - elsif( $opt eq "-f" ) { $Opt{usbserial} = shift @ARGV; } - elsif( $opt eq "-k" ) { $Opt{kernel} = shift @ARGV; } - elsif( $opt eq "-m" ) { $Opt{method} = shift @ARGV; } - elsif( $opt eq "-dev_prefix" ) { $Opt{dev_prefix} = shift @ARGV; } - elsif( $opt eq "-usb" ) { $Opt{usb} = 1; } - elsif( $opt eq "-b" ) { $Opt{board} = shift @ARGV; } - else { print STDERR "$help\nerror, unknown command line option $opt\n"; exit 1; } -} - -if( $Opt{kernel} eq "auto" ) { - $Opt{kernel} = "unknown"; - $Opt{kernel} = $1 if snarf("/proc/version") =~ /\bLinux version (\d+\.\d+)/; -} - -if( $Opt{method} eq "auto" ) { - $Opt{method} = ($Opt{kernel} eq "2.4") ? "procfs" : "sysfs"; -} - -if( $Opt{board} eq "z1" ) { - $Opt{board} = "Zolertia Z1"; -} elsif( $Opt{board} eq "remote" ) { - $Opt{board} = "Zolertia RE-Mote platform"; -} elsif( $Opt{board} eq "firefly" ) { - $Opt{board} = "Zolertia Firefly platform"; -} elsif( $Opt{board} eq "orion" ) { - $Opt{board} = "Zolertia Orion Ethernet router"; -} - -my @devs = $Opt{method} eq "procfs" ? scan_procfs() : scan_sysfs(); -print_motelist( sort { cmp_usbdev($a,$b) } @devs ); - - -# -# SysFS -# -sub scan_sysfs { - - my $tmp = '($_->{UsbVendor}||"") eq "10c4" && ($_->{UsbProduct}||"") eq "ea60"'; - - if($Opt{board}) { - $tmp = '($_->{ProductString}||"") eq $Opt{board} && ' . $tmp - } - - # Scan /sys/bus/usb/drivers/usb for CP210x devices - my @cpdevs = - grep { eval "$tmp" } - map { { - SysPath => $_, - UsbVendor => snarf("$_/idVendor",1), - UsbProduct => snarf("$_/idProduct",1), - ProductString => snarf("$_/product",1), - } } - glob("/sys/bus/usb/drivers/usb/*"); - - # Gather information about each CP210x device - for my $f (@cpdevs) { - my $syspath = $f->{SysPath}; - $f->{InfoSerial} = snarf("$syspath/serial",1); - $f->{InfoManufacturer} = snarf("$syspath/manufacturer",1); - $f->{InfoProduct} = snarf("$syspath/product",1); - $f->{UsbDevNum} = snarf("$syspath/devnum",1); - - my $devstr = readlink($syspath); - if( $devstr =~ m{([^/]+)/usb(\d+)/.*-([^/]+)$} ) { - $f->{UsbPath} = "usb-$1-$3"; - $f->{UsbBusNum} = $2; - } - ($f->{SysDev} = $syspath) =~ s{^.*/}{}; - - my $port = "$syspath/$f->{SysDev}:1.0"; - ($f->{DriverName} = readlink("$port/driver")) =~ s{^.*/}{} if -l "$port/driver"; - ($f->{SerialDevName} = (glob("$port/tty*"),undef)[0]) =~ s{^.*/}{}; - $f->{SerialDevNum} = $1 if $f->{SerialDevName} =~ /(\d+)/; - $f->{SerialDevName} = getSerialDevName( $f->{SerialDevNum} ) || " (none)"; - } - return @cpdevs; -} - - -# -# Scan Procfs -# -sub scan_procfs { - - my $text_devs = snarf("< /proc/bus/usb/devices"); - my $text_serial = snarf($Opt{usbserial}); - - my @usbdevs = map { {parse_usb_devices_text($_)} } - grep { !/^\s*$/ } split /\n+(?=T:)/, $text_devs; - my %usbtree = build_usb_tree( @usbdevs ); - my %usbserialtree = build_usbserial_tree( $text_serial ); - for my $tts ( values %usbserialtree ) { - $usbtree{usbkey($tts->{path})}{usbserial} = $tts if defined $tts->{path}; - } - - my @cpdevs = map { { - UsbVendor => $_->{Vendor}, - UsbProduct => $_->{ProdID}, - InfoManufacturer => $_->{Manufacturer}, - InfoProduct => $_->{Product}, - InfoSerial => $_->{SerialNumber}, - UsbBusNum => $_->{nbus}, - UsbDevNum => $_->{ndev}, - UsbPath => (($Opt{kernel} eq "2.4") ? $_->{usbserial}{path} : $_->{usbpath}), - DriverName => $_->{driver}, - SerialDevNum => $_->{usbserial}{tts}, - SerialDevName => getSerialDevName($_->{usbserial}{tts}) || " (none)", - } } - grep { ($_->{Vendor}||"") eq "0403" && ($_->{ProdID}||"") eq "6001" } - values %usbtree; - - return @cpdevs; -} - -sub build_usb_tree { - my @devs = @_; - my %tree = (); - for my $dev (sort { $a->{Lev} <=> $b->{Lev} } @devs) { - my ($bus,$lev,$prnt) = ( $dev->{Bus}+0, $dev->{Lev}+0, $dev->{Prnt}+0 ); - my $devnum = $dev->{"Dev#"}+0; - $dev->{nbus} = $bus; - $dev->{ndev} = $devnum; - $tree{"bus$bus"} = {} unless exists $tree{"bus$bus"}; - $tree{"bus$bus"}{"dev$devnum"} = $dev; - if( $lev == 0 ) { - $dev->{usbpath} = "usb-$dev->{SerialNumber}"; - } else { - my $sep = ($lev==1) ? "-" : "."; - $dev->{parent} = $tree{"bus$bus"}{"dev$prnt"}; - $dev->{usbpath} = $dev->{parent}{usbpath} . $sep . ($dev->{Port}+1); - } - $tree{usbkey($dev->{usbpath})} = $dev; - } - return %tree; -} - -sub parse_usb_devices_text { - my $text = shift; - $text =~ s/^\S+\s*//gm; - return ($text =~ m/([^\s=]+)=\s*(.*?\S)\s*(?=[^\s=]+=|$)/mg); -} - -sub build_usbserial_tree { - my $text = shift; - my %tree = (); - while( $text =~ /^([^:]+):(.*)/mg ) { - my ($tts,$params) = ($1,$2); - $tree{$tts} = { tts => $tts }; - while ($params =~ m/\s+([^:]+):(?:"([^"]*)"|(\S+))/g) { - $tree{$tts}{$1} = $2||$3; - } - } - return %tree; -} - -sub usbkey { - if( $Opt{kernel} eq "2.4" ) { - (my $key = $_[0]) =~ s/^.*-//; - return $key; - } - return $_[0]; -} - - -# -# getSerialDevName -# -# For each device, force to use dev_prefix if it's not an array. Otherwise, -# assume it's a list of candidate prefixes. Check them and commit to the -# first one that actually exists. -# -sub getSerialDevName { - my $devnum = shift; - my $devname = undef; - if( defined $devnum ) { - if( ref($Opt{dev_prefix}) eq "ARRAY" ) { - $devname = $devnum; - for my $prefix (@{$Opt{dev_prefix}}) { - my $file = $prefix . $devnum; - if( -e $file ) { $devname = $file; last; } - } - } else { - $devname = $Opt{dev_prefix} . $devnum; - } - } - return $devname; -} - - -# -# Print motelist -# -sub print_motelist { - my @devs = @_; - - # If none were found, quit - if( @devs == 0 ) { - print "No devices found.\n"; - return; - } - - # Print a header - if( !$Opt{compact} ) { - if( $Opt{usb} ) { - print << "EOF" unless $Opt{compact}; ---- --- ------------------------ -------------- ---------------- ------------------------------------- -Bus Dev USB Path Reference Device Description ---- --- ------------------------ -------------- ---------------- ------------------------------------- -EOF - } else { - print << "EOF" unless $Opt{compact}; --------------- ---------------- --------------------------------------------- -Reference Device Description --------------- ---------------- --------------------------------------------- -EOF - } - } - - # Print the usb information - for my $dev (sort { cmp_usbdev($a,$b) } @devs) { - my $desc = join( " ", $dev->{InfoManufacturer}||"", $dev->{InfoProduct}||"" ) || " (none)"; - my @output = ( $dev->{InfoSerial}||" (none)", $dev->{SerialDevName}, $desc ); - @output = ( $dev->{UsbBusNum}, $dev->{UsbDevNum}, $dev->{UsbPath}, @output ) if $Opt{usb}; - if( $Opt{compact} ) { - print join(",",@output) . "\n"; - } else { - printf( ($Opt{usb}?"%3d %3d %-24s ":"")."%-14s %-16s %s\n", @output ); - } - } -} - - -# -# Cmp Usbdev's -# -sub cmp_usbdev { - my ($a,$b) = @_; - if( defined $a->{SerialDevNum} ) { - if( defined $b->{SerialDevNum} ) { - return $a->{SerialDevNum} <=> $b->{SerialDevNum}; - } - return -1; - } - return 1 if defined $b->{SerialDevNum}; - return ($a->{InfoSerial}||"") cmp ($b->{InfoSerial}||""); -} - -# -# Read a file in -# -sub snarf { - open my $fh, $_[0] or return undef; - my $text = do{local $/;<$fh>}; - close $fh; - $text =~ s/\s+$// if $_[1]; - return $text; -} - diff --git a/tools/zolertia/motelist-zolertia-macos b/tools/zolertia/motelist-zolertia-macos deleted file mode 100755 index 526b4887e..000000000 --- a/tools/zolertia/motelist-zolertia-macos +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/perl -w -use strict; - -my $help = <<'EOF'; -usage: motelist [options] - -options: - -h display this help - -c compact format, not pretty but easier for parsing -EOF - -my %Opt = ( - compact => 0, - dev_prefix => [ "/dev/tty.SLAB" ], -); - -while (@ARGV) { - last unless $ARGV[0] =~ /^-/; - my $opt = shift @ARGV; - if( $opt eq "-h" ) { print "$help\n"; exit 0; } - elsif( $opt eq "-c" ) { $Opt{compact} = 1; } - else { print STDERR "$help\nerror, unknown command line option $opt\n"; exit 1; } -} - -print_motelist( scan_dev() ); - -# -# Scan /dev for tty.SLAB* -# -sub scan_dev { - my @devs; - foreach (`ls /dev/tty.SLAB* 2>&1`) { - my($dev, $serial) = /(\/dev\/tty.SLAB(\S+))/; - if ($serial ne "*:") { - my $d; - $d->{"InfoSerial"} = $serial; - $d->{"SerialDevName"} = $dev; - push(@devs, $d); - } - } - return @devs; -} - - -# -# Print motelist -# -sub print_motelist { - my @devs = @_; - - # If none were found, quit - if( @devs == 0 ) { - #print "No devices found.\n"; - return; - } - - # Print a header - if( !$Opt{compact} ) { - print << "EOF" unless $Opt{compact}; -Reference Device Description ----------- --------------------------- --------------------------------------- -EOF - } - - # Print the usb information - for my $dev (@devs) { - my $desc = "(none)"; - my @output = ( $dev->{"InfoSerial"}, $dev->{"SerialDevName"}, $desc ); - if( $Opt{compact} ) { - print join(",",@output) . "\n"; - } else { - printf( "%-10s %-27s %s\n", @output ); - } - } -}