Merge branch 'release-4.2' into fix/json-buffer-overflows

This commit is contained in:
Simon Duquennoy 2018-10-24 10:49:37 +02:00 committed by GitHub
commit ab1e2f8d28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
65 changed files with 1187 additions and 1033 deletions

2
.gitignore vendored
View File

@ -12,7 +12,7 @@
*.ihex
*.pyc
*~
obj_*
build/*
Makefile.target
Makefile.*.defines
tools/doxygen/html

View File

@ -30,14 +30,26 @@ before_install:
docker push $DOCKER_IMG;
fi
fi
# Build Cooja
- ant -q -f $CNG_HOST_PATH/tools/cooja/build.xml jar
# Build Cooja conditionally
- if [ ${BUILD_COOJA:-false} = true ] ; then
ant -q -f $CNG_HOST_PATH/tools/cooja/build.xml jar ;
fi
# 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
- sudo chgrp -hR 1000 $CNG_HOST_PATH $OUT_OF_TREE_TEST_PATH
# The test script for each build
script:
- docker run --privileged -v $CNG_HOST_PATH:/home/user/contiki-ng -ti $DOCKER_IMG bash --login -c "make -C tests/??-$TEST_NAME";
- 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 $?;
@ -47,6 +59,8 @@ env:
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=
@ -55,14 +69,15 @@ env:
- 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='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'
- TEST_NAME='ieee802154'
- 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'
- TEST_NAME='ipv6' BUILD_COOJA=true
- TEST_NAME='out-of-tree-build'

View File

@ -3,6 +3,9 @@
# 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)
@ -31,3 +34,14 @@ serialview: $(SERIAL_DUMP_BIN)
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)

29
Makefile.help Normal file
View File

@ -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

View File

@ -13,8 +13,6 @@ include $(CONTIKI)/Makefile.identify-target
### Include Makefile.tools to pull in targets that allow us to build tools dir
include $(CONTIKI)/Makefile.tools
CONTIKI_NG_TARGET_LIB = contiki-ng-$(TARGET).a
ifeq ($(DEFINES),)
-include Makefile.$(TARGET).defines
ifneq ($(DEFINES),)
@ -39,7 +37,12 @@ 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_
@ -75,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?)
@ -124,6 +123,11 @@ 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
@ -241,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
@ -303,14 +315,13 @@ 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:
-$(Q)rm -f *.d *.e *.o $(CONTIKI_NG_TARGET_LIB) $(CLEAN)
-$(Q)rm -rf $(OBJECTDIR)
-$(Q)rm -f $(addsuffix -$(TARGET).map, $(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
@ -319,6 +330,7 @@ distclean:
echo Running: $(MAKE) TARGET=$$TARG clean; \
$(MAKE) TARGET=$$TARG clean; \
done
-$(Q)rm -rf $(BUILD_DIR)
-include $(CONTIKI)/arch/platform/$(TARGET)/Makefile.customrules-$(TARGET)
@ -383,46 +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)] [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"
help: usage
include $(CONTIKI)/Makefile.help
targets:
@ls $(CONTIKI)/arch/platform $(TARGETDIRS)
@ -473,9 +462,9 @@ ifeq ($(findstring $(TARGET),native cooja),)
include $(CONTIKI)/Makefile.embedded
endif
# Don't treat %.$(TARGET) as an intermediate file because it is
# in fact the primary target.
.PRECIOUS: %.$(TARGET)
# 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

View File

@ -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
@ -43,22 +51,32 @@ 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 $< $@

View File

@ -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

View File

@ -3,28 +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
### 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) -lm -Wl,--end-group
.SECONDEXPANSION:
%.elf: $(CPU_STARTFILES) $$(CONTIKI_OBJECTFILES) %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(LDSCRIPT)
$(TRACE_LD)
$(Q)$(LD) $(LDFLAGS) ${filter-out $(LDSCRIPT) %.a,$^} ${filter %.a,$^} $(TARGET_LIBFLAGS) -o $@
TARGET_LIBFILES += -lm
include $(CONTIKI)/arch/cpu/arm/cortex-m/Makefile.cortex-m

View File

@ -3,26 +3,5 @@ CONTIKI_ARM_DIRS += cortex-m/cm4
CFLAGS += -mcpu=cortex-m4
LDFLAGS += -mcpu=cortex-m4
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
### 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
%.elf: $(CPU_STARTFILES) %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB) $(TARGET_LIBS)
$(TRACE_LD)
$(Q)$(LD) $(LDFLAGS) ${filter %.o %.a,$^} $(TARGET_LIBFLAGS) -o $@
include $(CONTIKI)/arch/cpu/arm/cortex-m/Makefile.cortex-m

View File

@ -36,11 +36,13 @@
/*---------------------------------------------------------------------------*/
#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 CC2538_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 CC2538_DELAY_BEFORE_RX ((unsigned)US_TO_RTIMERTICKS(250))
#define CC2538_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

View File

@ -1,6 +1,6 @@
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_CC13X0=1 -DCPU_FAMILY_CC13XX=1

View File

@ -1,8 +1,8 @@
CPU_ABS_PATH = arch/cpu/cc26xx-cc13xx
TI_XXWARE = $(CONTIKI_CPU)/$(TI_XXWARE_PATH)
ifeq (,$(wildcard $(TI_XXWARE)))
$(warning $(TI_XXWARE) does not exist.)
ifeq (,$(wildcard $(TI_XXWARE)/*))
$(warning $(TI_XXWARE) does not exist or is empty.)
$(warning Did you run 'git submodule update --init' ?)
$(error "")
endif
@ -81,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
@ -95,5 +97,3 @@ endif
### For the login etc targets
BAUDRATE = 115200
include $(CONTIKI)/arch/cpu/arm/cortex-m/cm3/Makefile.cm3

View File

@ -36,12 +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 RADIO_PHY_OVERHEAD 3
/* 250kbps data rate. One byte = 32us */
#define RADIO_BYTE_AIR_TIME 32
#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))
@ -56,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

View File

@ -96,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 :
{

View File

@ -386,7 +386,7 @@ on(void)
rf_core_power_down();
return RF_CORE_CMD_ERROR;
}
rf_core_setup_interrupts(0);
rf_core_setup_interrupts();
oscillators_switch_to_hf_xosc();
if(rf_ble_cmd_setup_ble_mode() != RF_BLE_CMD_OK) {

View File

@ -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 <atis.elsts@bristol.ac.uk>
*
*/
#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,
};

View File

@ -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_ */

View File

@ -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) {
@ -615,11 +545,11 @@ init_rf_params(void)
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;
}

View File

@ -115,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
@ -141,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);
@ -170,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
@ -222,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 */
@ -236,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
@ -272,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;
@ -420,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
@ -441,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) {
@ -506,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) {
@ -583,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
@ -606,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
@ -637,10 +645,15 @@ init(void)
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;
@ -701,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);
@ -714,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) {
@ -743,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;
@ -764,47 +784,98 @@ send(const void *payload, unsigned short payload_len)
return transmit(payload_len);
}
/*---------------------------------------------------------------------------*/
static int
read_frame(void *buf, unsigned short buf_len)
static void
release_data_entry(void)
{
int_master_status_t status;
rfc_dataEntryGeneral_t *entry = (rfc_dataEntryGeneral_t *)rx_read_entry;
uint8_t *data_ptr = &entry->data;
int len = 0;
int_master_status_t interrupt_status;
if(entry->status == DATA_ENTRY_STATUS_FINISHED) {
/* Clear the length field (2 bytes) */
data_ptr[0] = 0;
data_ptr[1] = 0;
/*
* 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;
/* Set status to 0 "Pending" in element */
entry->status = DATA_ENTRY_STATUS_PENDING;
rx_read_entry = entry->pNextEntry;
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;
}
status = critical_enter();
if(rx_is_full) {
rx_is_full = false;
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(status);
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;
/* 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)));
/* Make sure the flag is reset */
is_receiving_packet = 0;
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;
}
/*---------------------------------------------------------------------------*/
@ -813,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()) {
@ -830,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;
@ -853,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
@ -866,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
@ -881,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;
@ -904,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");
@ -958,7 +1044,7 @@ on(void)
}
}
rf_core_setup_interrupts(false);
rf_core_setup_interrupts();
init_rx_buffers();
@ -985,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.
@ -998,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)
{
@ -1022,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;
@ -1031,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;
@ -1048,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;
}
@ -1056,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:
@ -1087,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) {
@ -1103,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;
@ -1112,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;
@ -1142,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;
}
/*---------------------------------------------------------------------------*/

View File

@ -99,12 +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 rx_is_full = false;
volatile bool rf_core_rx_is_full = false;
/*---------------------------------------------------------------------------*/
PROCESS(rf_core_process, "CC13xx / CC26xx RF driver");
/*---------------------------------------------------------------------------*/
@ -451,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()) {
@ -485,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;
}
/*---------------------------------------------------------------------------*/
@ -544,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;
@ -582,11 +728,11 @@ cc26xx_rf_cpe1_isr(void)
return;
}
}
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*/
rx_is_full = true;
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 */

View File

@ -133,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 */
@ -263,12 +274,65 @@ typedef struct rf_core_primary_mode_s {
/* Radio timer register */
#define RATCNT 0x00000004
/*---------------------------------------------------------------------------*/
/* Buffer full flag */
extern volatile bool rx_is_full;
/* 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
@ -383,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.
@ -405,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
@ -467,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_ */
/*---------------------------------------------------------------------------*/

View File

@ -399,6 +399,9 @@
#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"

View File

@ -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) $@ $^

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -28,11 +28,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) $<

View File

@ -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
* @{

View File

@ -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

View File

@ -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

View File

@ -229,30 +229,34 @@ 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
%.upload: $(BUILD_DIR_BOARD)/%.$(TARGET).bin
${FLASH_PROGRAMMER} -a -c $(DEV_PORT) -B 1000000 -s -w -f $<
else
%.upload: %.$(TARGET).bin
%.upload: $(BUILD_DIR_BOARD)/%.$(TARGET).bin
${FLASH_PROGRAMMER} -V 10 -v -s $(DEV_PORT) -I 38400 -P 1000000 -f $<
endif
@ -276,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

View File

@ -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) $<

View File

@ -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
* @{

View File

@ -46,23 +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 ,)
else
### If we are not running under Mac, we assume Linux
USBDEVPREFIX=
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
@ -81,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) $$<
@ -94,10 +80,8 @@ 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)

View File

@ -1,2 +1,2 @@
MOTELIST_ZOLERTIA = firefly
MOTELIST_ZOLERTIA := Firefly
BOARD_SOURCEFILES += board.c

View File

@ -1,2 +1,2 @@
MOTELIST_ZOLERTIA = firefly
MOTELIST_ZOLERTIA := Firefly
BOARD_SOURCEFILES += board.c

View File

@ -1,4 +1,4 @@
MOTELIST_ZOLERTIA = orion
MOTELIST_ZOLERTIA := Orion
MODULES += arch/dev/enc28j60
CC2538_ENC28J60_ARCH ?= gpio
ifeq ($(WITH_IP64),1)

View File

@ -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

View File

@ -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

View File

@ -2,7 +2,6 @@ CONTIKI_PROJECT = sixp-node
PROJECT_SOURCEFILES += test-sf.c
PLATFORMS_EXCLUDE = sky nrf52dk native simplelink
BOARDS_EXCLUDE = srf06/cc13xx launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350
CONTIKI = ../../../

View File

@ -2,7 +2,7 @@ CONTIKI_PROJECT = node
all: $(CONTIKI_PROJECT)
PLATFORMS_EXCLUDE = sky nrf52dk native simplelink
BOARDS_EXCLUDE = srf06/cc13xx launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350
BOARDS_EXCLUDE = sensortag/cc2650 sensortag/cc1350
MAKE_WITH_SECURITY ?= 0 # force Security from command line
ifeq ($(MAKE_WITH_SECURITY),1)

View File

@ -2,7 +2,6 @@ CONTIKI_PROJECT = node
all: $(CONTIKI_PROJECT)
PLATFORMS_EXCLUDE = sky nrf52dk native simplelink
BOARDS_EXCLUDE = srf06/cc13xx launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350
CONTIKI=../../..

View File

@ -2,7 +2,6 @@ CONTIKI_PROJECT = node-sixtop
all: $(CONTIKI_PROJECT)
PLATFORMS_EXCLUDE = sky nrf52dk native simplelink
BOARDS_EXCLUDE = srf06/cc13xx launchpad/cc1310 launchpad/cc1350 sensortag/cc2650 sensortag/cc1350
PROJECT_SOURCEFILES += sf-simple.c
CONTIKI=../../..

View File

@ -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),

View File

@ -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) {

View File

@ -47,7 +47,11 @@
#include <strings.h>
/*---------------------------------------------------------------------------*/
#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
@ -305,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') {

View File

@ -52,7 +52,9 @@
* 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.

View File

@ -189,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))
/** @} */
/*---------------------------------------------------------------------------*/
/**

View File

@ -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 */

View File

@ -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;
}

View File

@ -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 */
}

View File

@ -77,9 +77,7 @@
/* The approximate number of slots per second */
#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 */
/* 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 */

View File

@ -643,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;
}
}

View File

@ -158,7 +158,7 @@ extern uint8_t tsch_current_channel;
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) */
uint16_t tsch_timing_us[tsch_ts_elements_count];
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 */

View File

@ -24,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 \

View File

@ -89,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 \

View File

@ -28,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 \
@ -68,6 +69,8 @@ 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=

View File

@ -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

View File

@ -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

View File

@ -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)

@ -1 +1 @@
Subproject commit a5904b98366478bb9e7f7fe9f0bb78fc064914c5
Subproject commit 63538bbb882ba06a7b8cf97c11ce2fe4d22e4f88

View File

@ -1,29 +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 python-pip \
default-jdk ant srecord iputils-tracepath rlwrap \
mosquitto mosquitto-clients gdb \
&& 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 && \
@ -35,18 +64,17 @@ 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 install --upgrade pip
RUN pip install setuptools
RUN pip install sphinx_rtd_theme sphinx
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
@ -74,21 +102,8 @@ 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
# Install Mono and libcanberra-gtk:i386 (for Renode)
RUN sudo 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 \
&& sudo apt-get update \
&& sudo apt-get install -y mono-complete gksu libgtk2.0-0 screen uml-utilities gtk-sharp2 libcanberra-gtk-module:i386 \
&& sudo apt-get clean
# Download, build and install Renode
RUN git clone https://github.com/renode/renode.git \
RUN git clone --quiet https://github.com/renode/renode.git \
&& cd ${HOME}/renode \
&& git checkout v1.3 \
&& ./build.sh

View File

@ -1,62 +0,0 @@
Copyright (c) 2001-2003 Chris Liechti <cliechti@gmx.net>
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.

View File

@ -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 <cory@moteiv.com>
# @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;
}

View File

@ -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 );
}
}
}