diff --git a/.github/workflows/test-on-iotlab.yml b/.github/workflows/test-on-iotlab.yml index 10a0af31ba..fb9938a2ff 100644 --- a/.github/workflows/test-on-iotlab.yml +++ b/.github/workflows/test-on-iotlab.yml @@ -33,6 +33,10 @@ jobs: fail-fast: false matrix: boards: + - riot: dwm1001 + iotlab: + archi: dwm1001:dw1000 + site: saclay - riot: iotlab-m3 iotlab: archi: m3:at86rf231 @@ -49,18 +53,22 @@ jobs: iotlab: archi: nrf52840dk:multi site: saclay - - riot: dwm1001 - iotlab: - archi: dwm1001:dw1000 - site: saclay - riot: nrf52832-mdk iotlab: archi: nrf52832mdk:ble site: saclay + - riot: nucleo-wl55jc + iotlab: + archi: nucleo-wl55jc:stm32wl + site: grenoble - riot: samr21-xpro iotlab: archi: samr21:at86rf233 site: saclay + - riot: samr34-xpro + iotlab: + archi: samr34:sx1276 + site: grenoble - riot: b-l072z-lrwan1 iotlab: archi: st-lrwan1:sx1276 @@ -74,10 +82,6 @@ jobs: env: IOTLAB_NODE: auto BUILD_IN_DOCKER: 1 - # Force .bin files generation because these files are used to flash on IoT-LAB and - # because compile_and_test_for_board forces RIOT_CI_BUILD which skip .bin - # files generation - DOCKER_ENVIRONMENT_CMDLINE: -e BUILD_FILES=\$$\(BINFILE\) COMPILE_AND_TEST_FOR_BOARD: ./dist/tools/compile_and_test_for_board/compile_and_test_for_board.py COMPILE_AND_TEST_ARGS: --with-test-only --jobs=2 --report-xml # Exclude applications that are expected to fail or cannot run on iotlab diff --git a/.murdock b/.murdock index c6f2b70f14..d78b802338 100755 --- a/.murdock +++ b/.murdock @@ -1,7 +1,7 @@ #!/bin/sh # uncomment and change this to limit builds, e.g., -#export BOARDS="samr21-xpro native" +export BOARDS="samr21-xpro native" # and / or #export APPS="examples/hello-world tests/unittests" @@ -105,27 +105,21 @@ tests/ieee802154_hal # As a rule of thumb, only add boards here if there are not differences in # modules or packages. # Eventually this list will be removed... +# +# msbiot and pyboard are on the list as kconfig tunes the pll due to different +# HSE values from the standard, this is not the case in makefile. : ${TEST_KCONFIG_BOARD_BLOCKLIST:=" 6lowpan-clicker -esp32-wrover-kit -esp8266-esp-12x -esp8266-olimex-mod -esp8266-sparkfun-thing -limifrog-v1 -lora-e5-dev -msbiot -msb-430h -nucleo-l011k4 -nucleo-wl55jc -omote -openmote-b pic32-wifire + +esp32-wrover-kit +esp8266-olimex-mod + +msbiot pyboard -remote-pa -samd10-xmini -stk3200 -stm32f030f4-demo -stm32f3discovery + +lora-e5-dev +nucleo-wl55jc stm32mp157c-dk2 "} @@ -382,7 +376,7 @@ get_compile_jobs() { get_apps | \ maybe_filter_changed_apps | \ - dwqc ${DWQ_ENV} -s \ + dwqc ${DWQ_ENV} --queue default-first -s \ ${DWQ_JOBID:+--subjob} \ "$0 get_app_board_toolchain_pairs \${1} $0 compile" } diff --git a/Makefile.base b/Makefile.base index 0132e8c7e7..cfc060c973 100644 --- a/Makefile.base +++ b/Makefile.base @@ -97,8 +97,8 @@ compile-commands: | $(DIRS:%=COMPILE-COMMANDS--%) $(file >>$(BINDIR)/$(MODULE)/compile_cmds.txt,TARGET_ARCH: $(TARGET_ARCH)) $(file >>$(BINDIR)/$(MODULE)/compile_cmds.txt,TARGET_ARCH_LLVM: $(TARGET_ARCH_LLVM)) -# include makefile snippets for packages in $(USEPKG) that modify GENSRC: --include $(USEPKG:%=$(RIOTPKG)/%/Makefile.gensrc) +# include makefile snippets for packages in $(PKG_PATHS) that modify GENSRC: +-include $(PKG_PATHS:%=%Makefile.gensrc) GENOBJC := $(GENSRC:%.c=%.o) OBJC_LTO := $(SRC:%.c=$(BINDIR)/$(MODULE)/%.o) diff --git a/Makefile.dep b/Makefile.dep index 6e0f815619..ad9c764824 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -10,7 +10,7 @@ # include external modules dependencies # processed before RIOT ones to be evaluated before the 'default' rules. --include $(EXTERNAL_MODULE_PATHS:%=%/Makefile.dep) +-include $(EXTERNAL_MODULE_PATHS:%=%Makefile.dep) # pull dependencies from sys and drivers include $(RIOTBASE)/sys/Makefile.dep @@ -20,7 +20,7 @@ include $(RIOTBASE)/drivers/Makefile.dep -include $(sort $(USEMODULE:%=$(RIOTBASE)/drivers/%/Makefile.dep)) # pull dependencies from packages --include $(USEPKG:%=$(RIOTPKG)/%/Makefile.dep) +-include $(PKG_PATHS:%=%Makefile.dep) ifneq (,$(filter mpu_stack_guard,$(USEMODULE))) FEATURES_REQUIRED += cortexm_mpu diff --git a/Makefile.include b/Makefile.include index a91c125ecc..dd83db28a0 100644 --- a/Makefile.include +++ b/Makefile.include @@ -386,6 +386,17 @@ ifneq (,$(IOTLAB_NODE)) PROGRAMMER ?= iotlab # iotlab uses ELFFILE by default for flashing boards. FLASHFILE ?= $(ELFFILE) + # RIOT_CI_BUILD disables the build of BINFILE which is required for flashing + # on IoT-LAB + ifeq (1,$(RIOT_CI_BUILD)) + BUILD_FILES += $(BINFILE) + endif + # Disable IOTLAB_NODE if inside Docker to avoid including the + # iotlab.single.inc.mk file which is useless there: it's only useful for + # flashing and this is done outside of Docker. + ifeq (1,$(INSIDE_DOCKER)) + IOTLAB_NODE := + endif endif # Add standard include directories @@ -416,6 +427,12 @@ ifeq (1,$(TEST_KCONFIG)) USEMODULE := $(KCONFIG_MODULES) KCONFIG_PACKAGES := $(call lowercase,$(patsubst CONFIG_PACKAGE_%,%,$(filter CONFIG_PACKAGE_%,$(.VARIABLES)))) USEPKG := $(KCONFIG_PACKAGES) + + # Locate used packages in $(RIOTPKG). + PKG_PATHS := $(sort $(foreach dir,$(RIOTPKG),\ + $(foreach pkg,$(USEPKG),$(dir $(wildcard $(dir)/$(pkg)/Makefile))))) + + EXTERNAL_MODULE_PATHS := $(dir $(EXTERNAL_MODULE_KCONFIGS)) else # always select provided architecture features FEATURES_REQUIRED += $(filter arch_%,$(FEATURES_PROVIDED)) @@ -559,11 +576,11 @@ include $(RIOTBASE)/sys/Makefile.include # include Makefile.includes of each driver modules if they exist -include $(USEMODULE:%=$(RIOTBASE)/drivers/%/Makefile.include) -# include Makefile.includes for packages in $(USEPKG) --include $(USEPKG:%=$(RIOTPKG)/%/Makefile.include) +# include Makefile.includes for packages in $(PKG_PATHS) +-include $(PKG_PATHS:%=%Makefile.include) # include external modules configuration --include $(EXTERNAL_MODULE_PATHS:%=%/Makefile.include) +-include $(EXTERNAL_MODULE_PATHS:%=%Makefile.include) # Deduplicate includes without sorting them # see https://stackoverflow.com/questions/16144115/makefile-remove-duplicate-words-without-sorting @@ -760,31 +777,30 @@ endif # The `clean` needs to be serialized before everything else. all $(BASELIBS) $(ARCHIVES) $(BUILDDEPS) ..in-docker-container: | $(CLEAN) -.PHONY: pkg-prepare pkg-build pkg-build-% +.PHONY: pkg-prepare pkg-build pkg-prepare: - -@for i in $(USEPKG) ; do "$(MAKE)" -C $(RIOTPKG)/$$i prepare ; done + -@$(foreach dir,$(PKG_PATHS),"$(MAKE)" -C $(dir) prepare $(NEWLINE)) -pkg-build: $(USEPKG:%=pkg-build-%) -pkg-build-%: $(BUILDDEPS) - $(QQ)"$(MAKE)" -C $(RIOTPKG)/$* +pkg-build: $(BUILDDEPS) + $(foreach dir,$(PKG_PATHS),$(QQ)"$(MAKE)" -C $(dir) $(NEWLINE)) clean: ifndef MAKE_RESTARTS - -@for i in $(USEPKG) ; do "$(MAKE)" -C $(RIOTPKG)/$$i clean ; done + -@$(foreach dir,$(PKG_PATHS),"$(MAKE)" -C $(dir) clean $(NEWLINE)) -@rm -rf $(BINDIR) -@rm -rf $(SCANBUILD_OUTPUTDIR) endif # Remove intermediates, but keep the .elf, .hex and .map etc. clean-intermediates: - -@for i in $(USEPKG) ; do "$(MAKE)" -C $(RIOTPKG)/$$i distclean ; done + -@$(foreach dir,$(PKG_PATHS),"$(MAKE)" -C $(dir) distclean $(NEWLINE)) -@rm -rf $(BINDIR)/*.a $(BINDIR)/*/ clean-pkg: - -@for i in $(USEPKG) ; do "$(MAKE)" -C $(RIOTPKG)/$$i distclean ; done + -@$(foreach dir,$(PKG_PATHS),"$(MAKE)" -C $(dir) distclean $(NEWLINE)) distclean: - -@for i in $(USEPKG) ; do "$(MAKE)" -C $(RIOTPKG)/$$i distclean ; done + -@$(foreach dir,$(PKG_PATHS),"$(MAKE)" -C $(dir) distclean $(NEWLINE)) -@rm -rf $(BINDIRBASE) # Include PROGRAMMER_FLASH/PROGRAMMER_RESET variables diff --git a/boards/adafruit-itsybitsy-m4/board.c b/boards/adafruit-itsybitsy-m4/board.c index 4cf4acf16c..c163ed97cb 100644 --- a/boards/adafruit-itsybitsy-m4/board.c +++ b/boards/adafruit-itsybitsy-m4/board.c @@ -40,7 +40,6 @@ static const mtd_spi_nor_params_t _samd51_nor_params = { .cs = SAM0_QSPI_PIN_CS, .wp = SAM0_QSPI_PIN_DATA_2, .hold = SAM0_QSPI_PIN_DATA_3, - .addr_width = 3, }; static mtd_spi_nor_t samd51_nor_dev = { diff --git a/boards/common/weact-f4x1cx/board.c b/boards/common/weact-f4x1cx/board.c index 1451e3dd0e..fc772669e9 100644 --- a/boards/common/weact-f4x1cx/board.c +++ b/boards/common/weact-f4x1cx/board.c @@ -40,7 +40,6 @@ static const mtd_spi_nor_params_t _weact_nor_params = { .cs = WEACT_4X1CX_NOR_SPI_CS, .wp = GPIO_UNDEF, .hold = GPIO_UNDEF, - .addr_width = 3, }; static mtd_spi_nor_t weact_nor_dev = { diff --git a/boards/esp32-wrover-kit/Makefile.features b/boards/esp32-wrover-kit/Makefile.features index 17054e8466..c3a06b4d0f 100644 --- a/boards/esp32-wrover-kit/Makefile.features +++ b/boards/esp32-wrover-kit/Makefile.features @@ -19,5 +19,5 @@ FEATURES_PROVIDED += arduino # This configuration enables modules that are only available when using Kconfig # module modelling ifeq (1, $(TEST_KCONFIG)) - KCONFIG_ADD_CONFIG += $(BOARDDIR)/esp32-wrover-kit.config + KCONFIG_BOARD_CONFIG += $(BOARDDIR)/esp32-wrover-kit.config endif diff --git a/boards/feather-m0/include/board.h b/boards/feather-m0/include/board.h index 0f89ef0b52..956b29e928 100644 --- a/boards/feather-m0/include/board.h +++ b/boards/feather-m0/include/board.h @@ -59,9 +59,11 @@ extern "C" { * @{ **/ #define SX127X_PARAM_SPI SPI_DEV(0) +#if defined(BOARD_FEATHER_M0_LORA) #define SX127X_PARAM_SPI_NSS GPIO_PIN(PA, 6) #define SX127X_PARAM_RESET GPIO_PIN(PA, 8) #define SX127X_PARAM_DIO0 GPIO_PIN(PA, 9) +#endif #define SX127X_PARAM_DIO1 GPIO_UNDEF #define SX127X_PARAM_DIO2 GPIO_UNDEF #define SX127X_PARAM_DIO3 GPIO_UNDEF diff --git a/boards/ikea-tradfri/board.c b/boards/ikea-tradfri/board.c index ab3a3bd4cd..2b7df58d59 100644 --- a/boards/ikea-tradfri/board.c +++ b/boards/ikea-tradfri/board.c @@ -38,7 +38,6 @@ static const mtd_spi_nor_params_t _ikea_tradfri_nor_params = { .cs = IKEA_TRADFRI_NOR_SPI_CS, .wp = GPIO_UNDEF, .hold = GPIO_UNDEF, - .addr_width = 3, }; static mtd_spi_nor_t ikea_tradfri_nor_dev = { diff --git a/boards/iotlab-m3/mtd.c b/boards/iotlab-m3/mtd.c index 9bd42fcebe..23bf99753a 100644 --- a/boards/iotlab-m3/mtd.c +++ b/boards/iotlab-m3/mtd.c @@ -40,7 +40,6 @@ static const mtd_spi_nor_params_t _mtd_nor_params = { .cs = GPIO_PIN(PORT_A, 11), .wp = GPIO_PIN(PORT_C, 6), .hold = GPIO_PIN(PORT_C, 9), - .addr_width = 3, }; static mtd_spi_nor_t mtd_nor_dev = { diff --git a/boards/limifrog-v1/Kconfig b/boards/limifrog-v1/Kconfig index 6d324cc3f8..3ae9f51a91 100644 --- a/boards/limifrog-v1/Kconfig +++ b/boards/limifrog-v1/Kconfig @@ -19,4 +19,6 @@ config BOARD_LIMIFROG_V1 select HAS_PERIPH_TIMER select HAS_PERIPH_UART + select HAVE_LIS3MDL + source "$(RIOTBOARD)/common/stm32/Kconfig" diff --git a/boards/msb-430h/Kconfig b/boards/msb-430h/Kconfig index 48d875e466..e7c8fc8e1f 100644 --- a/boards/msb-430h/Kconfig +++ b/boards/msb-430h/Kconfig @@ -16,5 +16,6 @@ config BOARD_MSB_430H select HAS_PERIPH_TIMER select HAS_PERIPH_UART select BOARD_COMMON_MSB_430 + select HAVE_SHT11 source "$(RIOTBOARD)/common/msb-430/Kconfig" diff --git a/boards/msbiot/Kconfig b/boards/msbiot/Kconfig index 22f64169c7..7a94c4e974 100644 --- a/boards/msbiot/Kconfig +++ b/boards/msbiot/Kconfig @@ -27,4 +27,7 @@ config BOARD_MSBIOT select BOARD_HAS_HSE select BOARD_HAS_LSE + select HAVE_MPU9150 + select HAVE_SAUL_GPIO + source "$(RIOTBOARD)/common/stm32/Kconfig" diff --git a/boards/mulle/board.c b/boards/mulle/board.c index 6774901cb6..e9d5a9e047 100644 --- a/boards/mulle/board.c +++ b/boards/mulle/board.c @@ -56,7 +56,6 @@ static const mtd_spi_nor_params_t mulle_nor_params = { .wait_32k_erase = 20LU * US_PER_MS, .wait_chip_wake_up = 1LU * US_PER_MS, .spi = MULLE_NOR_SPI_DEV, - .addr_width = 3, .mode = SPI_MODE_3, .cs = MULLE_NOR_SPI_CS, .wp = GPIO_UNDEF, diff --git a/boards/nrf52840dk/mtd.c b/boards/nrf52840dk/mtd.c index 374fba9a43..449560f635 100644 --- a/boards/nrf52840dk/mtd.c +++ b/boards/nrf52840dk/mtd.c @@ -40,7 +40,6 @@ static const mtd_spi_nor_params_t _nrf52840dk_nor_params = { .cs = NRF52840DK_NOR_SPI_CS, .wp = GPIO_UNDEF, .hold = GPIO_UNDEF, - .addr_width = 3, }; static mtd_spi_nor_t nrf52840dk_nor_dev = { diff --git a/boards/omote/Kconfig b/boards/omote/Kconfig index e2f484819e..6a5dfa90d2 100644 --- a/boards/omote/Kconfig +++ b/boards/omote/Kconfig @@ -18,3 +18,7 @@ config BOARD_OMOTE select HAS_PERIPH_TIMER select HAS_PERIPH_UART select HAS_RIOTBOOT + + select HAVE_SAUL_GPIO + select HAVE_BMP180 + select HAVE_ADXL345 diff --git a/boards/openmote-b/Kconfig b/boards/openmote-b/Kconfig index f09a0f6ec2..526b8d1b71 100644 --- a/boards/openmote-b/Kconfig +++ b/boards/openmote-b/Kconfig @@ -18,3 +18,6 @@ config BOARD_OPENMOTE_B select HAS_PERIPH_TIMER select HAS_PERIPH_UART select HAS_RIOTBOOT + + select HAVE_SI7006 + select HAVE_SAUL_GPIO diff --git a/boards/p-nucleo-wb55/doc.txt b/boards/p-nucleo-wb55/doc.txt index b6d666415d..c972900528 100644 --- a/boards/p-nucleo-wb55/doc.txt +++ b/boards/p-nucleo-wb55/doc.txt @@ -1,6 +1,6 @@ /** @defgroup boards_p-nucleo-wb55 STM32 p-nucleo-wb55 -@ingroup boards_common_nucleo +@ingroup boards @brief Support for the STM32 p-nucleo-wb55 Hardware @@ -45,11 +45,7 @@ Flashing the device ------------------- The ST p-nucleo-wb55 board includes an on-board ST-LINK programmer and can be -flashed using OpenOCD. - -@note The latest release of OpenOCD doesn't contain support for this board, -so a recent development version must be built from source to be able to flash -this board. +flashed using OpenOCD (use version 0.11.0 at least). To flash this board, just use the following command: @@ -102,8 +98,8 @@ Implementation Status | | RTC | yes | | | | RNG | yes | | | | Timer | yes | TIM2 | -| | WDT | no | | -| | USB | no | | +| | WDT | yes | | +| | USB | yes | | | | PWM | no | | | | AES | no | | diff --git a/boards/pinetime/board.c b/boards/pinetime/board.c index bdc9e3bd56..8039504d00 100644 --- a/boards/pinetime/board.c +++ b/boards/pinetime/board.c @@ -43,7 +43,6 @@ static const mtd_spi_nor_params_t _pinetime_nor_params = { .cs = PINETIME_NOR_SPI_CS, .wp = GPIO_UNDEF, .hold = GPIO_UNDEF, - .addr_width = 3, }; static mtd_spi_nor_t pinetime_nor_dev = { diff --git a/boards/qn9080dk/board.c b/boards/qn9080dk/board.c index 22fc53cd05..93ecd63ae0 100644 --- a/boards/qn9080dk/board.c +++ b/boards/qn9080dk/board.c @@ -43,7 +43,6 @@ static const mtd_spi_nor_params_t _mtd_nor_params = { .cs = SPI_HWCS(0), /* GPIO(PORT_A, 3) is used for HWCS(0) on FC2 */ .wp = GPIO_UNDEF, .hold = GPIO_UNDEF, - .addr_width = 3, /* 24-bit addresses */ }; static mtd_spi_nor_t mtd_nor_dev = { diff --git a/boards/remote-pa/Kconfig b/boards/remote-pa/Kconfig index ab17b4e9d0..0ddce3b7dc 100644 --- a/boards/remote-pa/Kconfig +++ b/boards/remote-pa/Kconfig @@ -11,5 +11,7 @@ config BOARD_REMOTE_PA bool default y select BOARD_COMMON_REMOTE + select HAVE_SAUL_GPIO + select HAVE_SAUL_ADC source "$(RIOTBOARD)/common/remote/Kconfig" diff --git a/boards/samd10-xmini/Kconfig b/boards/samd10-xmini/Kconfig index 2e9f7e8991..86e056c5c8 100644 --- a/boards/samd10-xmini/Kconfig +++ b/boards/samd10-xmini/Kconfig @@ -20,3 +20,9 @@ config BOARD_SAMD10_XMINI select HAS_PERIPH_SPI select HAS_PERIPH_TIMER select HAS_PERIPH_UART + select HAVE_SAUL_GPIO + +choice LIBC_IMPLEMENTATION + # Use Picolibc to reduce ROM usage + default MODULE_PICOLIBC +endchoice diff --git a/boards/same54-xpro/board.c b/boards/same54-xpro/board.c index df47b4a51f..777a3428db 100644 --- a/boards/same54-xpro/board.c +++ b/boards/same54-xpro/board.c @@ -24,7 +24,7 @@ #include "timex.h" #ifdef MODULE_MTD -/* N25Q256A */ +/* N25Q256A or SST26VF064B */ static const mtd_spi_nor_params_t _same54_nor_params = { .opcode = &mtd_spi_nor_opcode_default, .wait_chip_erase = 240 * US_PER_SEC, @@ -38,7 +38,6 @@ static const mtd_spi_nor_params_t _same54_nor_params = { .cs = SAM0_QSPI_PIN_CS, .wp = SAM0_QSPI_PIN_DATA_2, .hold = SAM0_QSPI_PIN_DATA_3, - .addr_width = 4, }; static mtd_spi_nor_t same54_nor_dev = { diff --git a/boards/samr34-xpro/doc.txt b/boards/samr34-xpro/doc.txt new file mode 100644 index 0000000000..7c92e0f2c4 --- /dev/null +++ b/boards/samr34-xpro/doc.txt @@ -0,0 +1,40 @@ +/** +@defgroup boards_samr34-xpro Microchip SAM R34 Xplained Pro +@ingroup boards +@brief Support for the Microchip SAM R34 Xplained Pro and WLR089 Xplained Pro + +## Overview + +The `SAMR34 Xplained Pro` is a compact evaluation board by Microchip featuring a +SAMR34J18 SoC. The SoC includes a SAML21 ARM Cortex-M0+ micro-controller +bundled with Semtech's SX1276, a 868/915 MHz LoRa compatible radio. +For programming the MCU comes with 40Kb of RAM and 256Kb of flash memory. + +## Hardware + +![samr34-xpro image](https://www.microchip.com/content/dam/mchp/mrt-dam/devtools/3072-180605-wpd-dm320111-2.jpg) + +An evaluation board for the radio certified WLR089 module exists as the WLR089 Xplained Pro, it is compatible with the `samr34-xpro`. + +![wlr089-xpro](https://www.microchip.com/content/dam/mchp/mrt-dam/devtools/3411-264438-1598368489-c14679-200616-wsg-ev23m25a-wlr089-explained-pro-evaluation-board.jpg) + + +### MCU +| MCU | SAMR34J18B | +|:---------- |:--------------------- | +| Family | ARM Cortex-M0+ | +| Vendor | Atmel | +| RAM | 32 kiB + 8 kiB battery RAM | +| Flash | 256 KiB | +| Frequency | up to 48MHz | +| FPU | no | +| Timers | 6 (3xTC (8,16,32 bit), 3xTCC (16 bit)) | +| ADCs | 1x 12-bit (8 channels)| +| UARTs | max 5 (shared with SPI and I2C) | +| SPIs | max 5 (see UART) | +| I2Cs | max 5 (see UART) | +| Vcc | 1.8V - 3.6V | +| Datasheet | [Datasheet](https://ww1.microchip.com/downloads/en/DeviceDoc/SAMR34-R35-Low-Power-LoRa-Sub-GHz-SiP-Data-Sheet-DS70005356B.pdf) | +| Board Manual | [SAM R34 XPro](https://www.microchip.com/en-us/development-tool/DM320111)
[WLR089 XPro](https://www.microchip.com/en-us/development-tool/EV23M25A)| + + */ diff --git a/boards/samr34-xpro/include/board.h b/boards/samr34-xpro/include/board.h index 80ada8ac1e..e2473d8fb9 100644 --- a/boards/samr34-xpro/include/board.h +++ b/boards/samr34-xpro/include/board.h @@ -7,9 +7,7 @@ */ /** - * @defgroup boards_samr34-xpro Microchip SAM R34 Xplained Pro - * @ingroup boards - * @brief Support for the Microchip SAM R34 Xplained Pro board. + * @ingroup boards_samr34-xpro * @{ * * @file @@ -32,50 +30,50 @@ extern "C" { * @name Semtech SX1276 configuration * @{ */ -#define SX127X_PARAM_SPI (SPI_DEV(0)) -#define SX127X_PARAM_SPI_NSS GPIO_PIN(1, 31) /* D10 */ -#define SX127X_PARAM_RESET GPIO_PIN(1, 15) /* A0 */ -#define SX127X_PARAM_DIO0 GPIO_PIN(1, 16) /* D2 */ -#define SX127X_PARAM_DIO1 GPIO_PIN(0, 11) /* D3 */ -#define SX127X_PARAM_DIO2 GPIO_PIN(0, 12) /* D4 */ -#define SX127X_PARAM_DIO3 GPIO_PIN(1, 17) /* D5 */ -#define SX127X_PARAM_PASELECT (SX127X_PA_RFO) +#define SX127X_PARAM_SPI SPI_DEV(0) /**< internal SPI */ +#define SX127X_PARAM_SPI_NSS GPIO_PIN(1, 31) /**< D10 */ +#define SX127X_PARAM_RESET GPIO_PIN(1, 15) /**< A0 */ +#define SX127X_PARAM_DIO0 GPIO_PIN(1, 16) /**< D2 */ +#define SX127X_PARAM_DIO1 GPIO_PIN(0, 11) /**< D3 */ +#define SX127X_PARAM_DIO2 GPIO_PIN(0, 12) /**< D4 */ +#define SX127X_PARAM_DIO3 GPIO_PIN(1, 17) /**< D5 */ +#define SX127X_PARAM_PASELECT SX127X_PA_RFO /**< no boost */ /** @}*/ /** * @name Board specific configuration * @{ */ -#define TCXO_PWR_PIN GPIO_PIN(PA, 9) -#define TX_OUTPUT_SEL_PIN GPIO_PIN(PA, 13) +#define TCXO_PWR_PIN GPIO_PIN(PA, 9) /**< 32 MHz oscillator for radio enable */ +#define TX_OUTPUT_SEL_PIN GPIO_PIN(PA, 13) /**< BAND_SEL */ /** @}*/ /** * @name LED pin definitions and handlers * @{ */ -#define LED_PORT PORT->Group[0] +#define LED_PORT PORT->Group[0] /**< GPIO port */ -#define LED0_PIN GPIO_PIN(PA, 18) -#define LED0_MASK (1 << 18) -#define LED0_ON (LED_PORT.OUTCLR.reg = LED0_MASK) -#define LED0_OFF (LED_PORT.OUTSET.reg = LED0_MASK) -#define LED0_TOGGLE (LED_PORT.OUTTGL.reg = LED0_MASK) +#define LED0_PIN GPIO_PIN(PA, 18) /**< GPIO pin */ +#define LED0_MASK (1 << 18) /**< GPIO pin mask */ +#define LED0_ON (LED_PORT.OUTCLR.reg = LED0_MASK) /**< enable LED */ +#define LED0_OFF (LED_PORT.OUTSET.reg = LED0_MASK) /**< disable LED */ +#define LED0_TOGGLE (LED_PORT.OUTTGL.reg = LED0_MASK) /**< toggle LED */ -#define LED1_PIN GPIO_PIN(PA, 19) -#define LED1_MASK (1 << 19) -#define LED1_ON (LED_PORT.OUTCLR.reg = LED1_MASK) -#define LED1_OFF (LED_PORT.OUTSET.reg = LED1_MASK) -#define LED1_TOGGLE (LED_PORT.OUTTGL.reg = LED1_MASK) +#define LED1_PIN GPIO_PIN(PA, 19) /**< GPIO pin */ +#define LED1_MASK (1 << 19) /**< GPIO pin mask */ +#define LED1_ON (LED_PORT.OUTCLR.reg = LED1_MASK) /**< enable LED */ +#define LED1_OFF (LED_PORT.OUTSET.reg = LED1_MASK) /**< disable LED */ +#define LED1_TOGGLE (LED_PORT.OUTTGL.reg = LED1_MASK) /**< toggle LED */ /** @} */ /** * @name BTN0 (SW0 Button) pin definitions * @{ */ -#define BTN0_PORT PORT->Group[0] -#define BTN0_PIN GPIO_PIN(PA, 28) -#define BTN0_MODE GPIO_IN_PU +#define BTN0_PORT PORT->Group[0] /**< GPIO port */ +#define BTN0_PIN GPIO_PIN(PA, 28) /**< GPIO pin */ +#define BTN0_MODE GPIO_IN_PU /**< Pull Up GPIO */ /** @} */ /** diff --git a/boards/serpente/board.c b/boards/serpente/board.c index e3504be7dc..d72184937a 100644 --- a/boards/serpente/board.c +++ b/boards/serpente/board.c @@ -41,7 +41,6 @@ static const mtd_spi_nor_params_t _serpente_nor_params = { .cs = SERPENTE_NOR_SPI_CS, .wp = GPIO_UNDEF, .hold = GPIO_UNDEF, - .addr_width = 3, }; static mtd_spi_nor_t serpente_nor_dev = { diff --git a/boards/stk3200/Makefile.dep b/boards/stk3200/Makefile.dep index b38ada67a7..c27f40cacf 100644 --- a/boards/stk3200/Makefile.dep +++ b/boards/stk3200/Makefile.dep @@ -3,9 +3,6 @@ ifneq (,$(filter saul_default,$(USEMODULE))) USEMODULE += saul_gpio endif -# limit the stack size so most tests and examples compile -CFLAGS += -DTHREAD_STACKSIZE_DEFAULT=512 - # add board common drivers USEMODULE += boards_common_silabs USEMODULE += silabs_bc diff --git a/boards/stk3200/Makefile.include b/boards/stk3200/Makefile.include index 149d8aeebb..9d029b224e 100644 --- a/boards/stk3200/Makefile.include +++ b/boards/stk3200/Makefile.include @@ -1,5 +1,8 @@ # setup JLink for flashing JLINK_PRE_FLASH = r +# limit the stack size so most tests and examples compile +CFLAGS += -DTHREAD_STACKSIZE_DEFAULT=512 + # include board common include $(RIOTBOARD)/common/silabs/Makefile.include diff --git a/core/include/rmutex.h b/core/include/rmutex.h index 3fc6585782..7a3daa7146 100644 --- a/core/include/rmutex.h +++ b/core/include/rmutex.h @@ -24,11 +24,6 @@ #define RMUTEX_H #include -#ifdef __cplusplus -#include "c11_atomics_compat.hpp" -#else -#include -#endif #include "mutex.h" #include "sched.h" @@ -62,14 +57,14 @@ typedef struct rmutex_t { * atomic_int_least16_t is used. Note @ref kernel_pid_t is an int16 * @internal */ - atomic_int_least16_t owner; + kernel_pid_t owner; } rmutex_t; /** * @brief Static initializer for rmutex_t. * @details This initializer is preferable to rmutex_init(). */ -#define RMUTEX_INIT { MUTEX_INIT, 0, ATOMIC_VAR_INIT(KERNEL_PID_UNDEF) } +#define RMUTEX_INIT { MUTEX_INIT, 0, KERNEL_PID_UNDEF } /** * @brief Initializes a recursive mutex object. diff --git a/core/include/sched.h b/core/include/sched.h index 23cfc56d75..5a5c2bbb34 100644 --- a/core/include/sched.h +++ b/core/include/sched.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 Freie Universität Berlin + * Copyright (C) 2014-2017 Freie Universität Berlin * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -75,6 +75,7 @@ * @brief Scheduler API definition * * @author Kaspar Schleiser + * @author Hauke Petersen */ #ifndef SCHED_H @@ -252,6 +253,19 @@ extern clist_node_t sched_runqueues[SCHED_PRIO_LEVELS]; */ NORETURN void sched_task_exit(void); +/** + * @brief Change the priority of the given thread + * + * @note This functions expects interrupts to be disabled when called! + * + * @pre (thread != NULL) + * @pre (priority < SCHED_PRIO_LEVELS) + * + * @param[in,out] thread target thread + * @param[in] priority new priority to assign to @p thread + */ +void sched_change_priority(thread_t *thread, uint8_t priority); + /** * @brief Set CPU to idle mode (CPU dependent) * diff --git a/core/rmutex.c b/core/rmutex.c index f967049258..4eebca0bb4 100644 --- a/core/rmutex.c +++ b/core/rmutex.c @@ -24,9 +24,10 @@ #include #include +#include "assert.h" +#include "atomic_utils.h" #include "rmutex.h" #include "thread.h" -#include "assert.h" #define ENABLE_DEBUG 0 #include "debug.h" @@ -78,7 +79,7 @@ static int _lock(rmutex_t *rmutex, int trylock) */ /* ensure that owner is read atomically, since I need a consistent value */ - owner = atomic_load_explicit(&rmutex->owner, memory_order_relaxed); + owner = atomic_load_kernel_pid(&rmutex->owner); DEBUG("rmutex %" PRIi16 " : mutex held by %" PRIi16 " \n", thread_getpid(), owner); @@ -104,8 +105,7 @@ static int _lock(rmutex_t *rmutex, int trylock) DEBUG("rmutex %" PRIi16 " : setting the owner\n", thread_getpid()); /* ensure that owner is written atomically, since others need a consistent value */ - atomic_store_explicit(&rmutex->owner, thread_getpid(), - memory_order_relaxed); + atomic_store_kernel_pid(&rmutex->owner, thread_getpid()); DEBUG("rmutex %" PRIi16 " : increasing refs\n", thread_getpid()); @@ -127,8 +127,8 @@ int rmutex_trylock(rmutex_t *rmutex) void rmutex_unlock(rmutex_t *rmutex) { - assert(atomic_load_explicit(&rmutex->owner, - memory_order_relaxed) == thread_getpid()); + /* ensure that owner is read atomically, since I need a consistent value */ + assert(atomic_load_kernel_pid(&rmutex->owner) == thread_getpid()); assert(rmutex->refcount > 0); DEBUG("rmutex %" PRIi16 " : decrementing refs refs\n", thread_getpid()); @@ -143,8 +143,7 @@ void rmutex_unlock(rmutex_t *rmutex) DEBUG("rmutex %" PRIi16 " : resetting owner\n", thread_getpid()); /* ensure that owner is written only once */ - atomic_store_explicit(&rmutex->owner, KERNEL_PID_UNDEF, - memory_order_relaxed); + atomic_store_kernel_pid(&rmutex->owner, KERNEL_PID_UNDEF); DEBUG("rmutex %" PRIi16 " : releasing mutex\n", thread_getpid()); diff --git a/core/sched.c b/core/sched.c index f59305b78d..8ff2ec1d6d 100644 --- a/core/sched.c +++ b/core/sched.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 Freie Universität Berlin + * Copyright (C) 2014-2017 Freie Universität Berlin * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -15,6 +15,7 @@ * * @author Kaspar Schleiser * @author René Kijewski + * @author Hauke Petersen * * @} */ @@ -86,21 +87,21 @@ static void (*sched_cb)(kernel_pid_t active_thread, * and readout away, switching between the two orders depending on the CLZ * instruction availability */ -static inline void _set_runqueue_bit(thread_t *process) +static inline void _set_runqueue_bit(uint8_t priority) { #if defined(BITARITHM_HAS_CLZ) - runqueue_bitcache |= BIT31 >> process->priority; + runqueue_bitcache |= BIT31 >> priority; #else - runqueue_bitcache |= 1 << process->priority; + runqueue_bitcache |= 1 << priority; #endif } -static inline void _clear_runqueue_bit(thread_t *process) +static inline void _clear_runqueue_bit(uint8_t priority) { #if defined(BITARITHM_HAS_CLZ) - runqueue_bitcache &= ~(BIT31 >> process->priority); + runqueue_bitcache &= ~(BIT31 >> priority); #else - runqueue_bitcache &= ~(1 << process->priority); + runqueue_bitcache &= ~(1 << priority); #endif } @@ -218,41 +219,54 @@ thread_t *__attribute__((used)) sched_run(void) return next_thread; } +/* Note: Forcing the compiler to inline this function will reduce .text for applications + * not linking in sched_change_priority(), which benefits the vast majority of apps. + */ +static inline __attribute__((always_inline)) void _runqueue_push(thread_t *thread, uint8_t priority) +{ + DEBUG("sched_set_status: adding thread %" PRIkernel_pid " to runqueue %" PRIu8 ".\n", + thread->pid, priority); + clist_rpush(&sched_runqueues[priority], &(thread->rq_entry)); + _set_runqueue_bit(priority); + + /* some thread entered a runqueue + * if it is the active runqueue + * inform the runqueue_change callback */ +#if (IS_USED(MODULE_SCHED_RUNQ_CALLBACK)) + thread_t *active_thread = thread_get_active(); + if (active_thread && active_thread->priority == priority) { + sched_runq_callback(priority); + } +#endif +} + +/* Note: Forcing the compiler to inline this function will reduce .text for applications + * not linking in sched_change_priority(), which benefits the vast majority of apps. + */ +static inline __attribute__((always_inline)) void _runqueue_pop(thread_t *thread) +{ + DEBUG("sched_set_status: removing thread %" PRIkernel_pid " from runqueue %" PRIu8 ".\n", + thread->pid, thread->priority); + clist_lpop(&sched_runqueues[thread->priority]); + + if (!sched_runqueues[thread->priority].next) { + _clear_runqueue_bit(thread->priority); +#if (IS_USED(MODULE_SCHED_RUNQ_CALLBACK)) + sched_runq_callback(thread->priority); +#endif + } +} + void sched_set_status(thread_t *process, thread_status_t status) { if (status >= STATUS_ON_RUNQUEUE) { if (!(process->status >= STATUS_ON_RUNQUEUE)) { - DEBUG( - "sched_set_status: adding thread %" PRIkernel_pid " to runqueue %" PRIu8 ".\n", - process->pid, process->priority); - clist_rpush(&sched_runqueues[process->priority], - &(process->rq_entry)); - _set_runqueue_bit(process); - - /* some thread entered a runqueue - * if it is the active runqueue - * inform the runqueue_change callback */ -#if (IS_USED(MODULE_SCHED_RUNQ_CALLBACK)) - thread_t *active_thread = thread_get_active(); - if (active_thread && active_thread->priority == process->priority) { - sched_runq_callback(process->priority); - } -#endif + _runqueue_push(process, process->priority); } } else { if (process->status >= STATUS_ON_RUNQUEUE) { - DEBUG( - "sched_set_status: removing thread %" PRIkernel_pid " from runqueue %" PRIu8 ".\n", - process->pid, process->priority); - clist_lpop(&sched_runqueues[process->priority]); - - if (!sched_runqueues[process->priority].next) { - _clear_runqueue_bit(process); -#if (IS_USED(MODULE_SCHED_RUNQ_CALLBACK)) - sched_runq_callback(process->priority); -#endif - } + _runqueue_pop(process); } } @@ -306,3 +320,40 @@ void sched_register_cb(void (*callback)(kernel_pid_t, kernel_pid_t)) sched_cb = callback; } #endif + +void sched_change_priority(thread_t *thread, uint8_t priority) +{ + assert(thread && (priority < SCHED_PRIO_LEVELS)); + + if (thread->priority == priority) { + return; + } + + unsigned irq_state = irq_disable(); + + if (thread_is_active(thread)) { + _runqueue_pop(thread); + _runqueue_push(thread, priority); + } + thread->priority = priority; + + irq_restore(irq_state); + + thread_t *active = thread_get_active(); + + if ((active == thread) + || ((active != NULL) && (active->priority > priority) && thread_is_active(thread)) + ) { + /* If the change in priority would result in a different decision of + * the scheduler, we need to yield to make sure the change in priority + * takes effect immediately. This can be due to one of the following: + * + * 1) The priority of the thread currently running has been reduced + * (higher numeric value), so that other threads now have priority + * over the currently running. + * 2) The priority of a pending thread has been increased (lower numeric value) so that it + * now has priority over the running thread. + */ + thread_yield_higher(); + } +} diff --git a/cpu/cortexm_common/vectors_cortexm.c b/cpu/cortexm_common/vectors_cortexm.c index 175d6cb25c..232e0109fe 100644 --- a/cpu/cortexm_common/vectors_cortexm.c +++ b/cpu/cortexm_common/vectors_cortexm.c @@ -161,10 +161,7 @@ void reset_handler_default(void) #endif /* CPU_HAS_BACKUP_RAM */ #ifdef MODULE_MPU_NOEXEC_RAM - /* Mark the RAM non executable. This is a protection mechanism which - * makes exploitation of buffer overflows significantly harder. - * - * This marks the memory region from 0x20000000 to 0x3FFFFFFF as non + /* This marks the memory region from 0x20000000 to 0x3FFFFFFF as non * executable. This is the Cortex-M SRAM region used for on-chip RAM. */ mpu_configure( diff --git a/cpu/native/native_cpu.c b/cpu/native/native_cpu.c index cdbbcc629e..87370a89ea 100644 --- a/cpu/native/native_cpu.c +++ b/cpu/native/native_cpu.c @@ -102,11 +102,10 @@ int thread_isr_stack_usage(void) return -1; } -static inline void *align_stack(void *stack_start, int *stacksize) +static inline void *align_stack(uintptr_t start, int *stacksize) { const size_t alignment = sizeof(uintptr_t); const uintptr_t align_mask = alignment - 1; - uintptr_t start = (uintptr_t)stack_start; size_t unalignment = (start & align_mask) ? (alignment - (start & align_mask)) : 0; start += unalignment; @@ -117,10 +116,9 @@ static inline void *align_stack(void *stack_start, int *stacksize) char *thread_stack_init(thread_task_func_t task_func, void *arg, void *stack_start, int stacksize) { - char *stk; ucontext_t *p; - stack_start = align_stack(stack_start, &stacksize); + stack_start = align_stack((uintptr_t)stack_start, &stacksize); VALGRIND_STACK_REGISTER(stack_start, (char *)stack_start + stacksize); VALGRIND_DEBUG("VALGRIND_STACK_REGISTER(%p, %p)\n", @@ -128,18 +126,16 @@ char *thread_stack_init(thread_task_func_t task_func, void *arg, void *stack_sta DEBUG("thread_stack_init\n"); - stk = stack_start; - /* Use intermediate cast to uintptr_t to silence -Wcast-align. The stack * is aligned to word size above. */ - p = (ucontext_t *)(uintptr_t)(stk + (stacksize - sizeof(ucontext_t))); + p = (ucontext_t *)(uintptr_t)((uint8_t *)stack_start + (stacksize - sizeof(ucontext_t))); stacksize -= sizeof(ucontext_t); if (getcontext(p) == -1) { err(EXIT_FAILURE, "thread_stack_init: getcontext"); } - p->uc_stack.ss_sp = stk; + p->uc_stack.ss_sp = stack_start; p->uc_stack.ss_size = stacksize; p->uc_stack.ss_flags = 0; p->uc_link = &end_context; diff --git a/cpu/nrf52/radio/nrf802154/nrf802154_radio.c b/cpu/nrf52/radio/nrf802154/nrf802154_radio.c index b31389b510..1a97973bcb 100644 --- a/cpu/nrf52/radio/nrf802154/nrf802154_radio.c +++ b/cpu/nrf52/radio/nrf802154/nrf802154_radio.c @@ -259,6 +259,7 @@ static int _confirm_op(ieee802154_dev_t *dev, ieee802154_hal_op_t op, void *ctx) int radio_state = NRF_RADIO->STATE; switch (op) { case IEEE802154_HAL_OP_TRANSMIT: + info = ctx; eagain = (state != STATE_IDLE && state != STATE_CCA_BUSY && NRF_RADIO->STATE != RADIO_STATE_STATE_Disabled); diff --git a/cpu/riscv_common/Kconfig b/cpu/riscv_common/Kconfig index 707cf33278..ff8958aced 100644 --- a/cpu/riscv_common/Kconfig +++ b/cpu/riscv_common/Kconfig @@ -12,7 +12,7 @@ config CPU_ARCH_RISCV select HAS_NEWLIB select HAS_PERIPH_CORETIMER select HAS_PICOLIBC if '$(RIOT_CI_BUILD)' != '1' - #select HAS_RUST_TARGET + select HAS_RUST_TARGET select HAS_SSP select MODULE_MALLOC_THREAD_SAFE if TEST_KCONFIG diff --git a/cpu/riscv_common/Makefile.features b/cpu/riscv_common/Makefile.features index 39d2d1c083..23a8d9441f 100644 --- a/cpu/riscv_common/Makefile.features +++ b/cpu/riscv_common/Makefile.features @@ -8,7 +8,7 @@ FEATURES_PROVIDED += cpp FEATURES_PROVIDED += libstdcpp FEATURES_PROVIDED += newlib FEATURES_PROVIDED += periph_coretimer -#FEATURES_PROVIDED += rust_target +FEATURES_PROVIDED += rust_target FEATURES_PROVIDED += ssp # RISC-V toolchain on CI does not work properly with picolibc yet diff --git a/cpu/riscv_common/ldscripts/riscv_base.ld b/cpu/riscv_common/ldscripts/riscv_base.ld index 17f2f9406a..66860b05f4 100644 --- a/cpu/riscv_common/ldscripts/riscv_base.ld +++ b/cpu/riscv_common/ldscripts/riscv_base.ld @@ -35,8 +35,8 @@ SECTIONS __stack_size = DEFINED(__stack_size) ? __stack_size : 256; /* Populate information about rom size */ - _srom = ORIGIN(rom); - _erom = ORIGIN(rom) + LENGTH(rom); + _srom = ORIGIN(flash); + _erom = ORIGIN(flash) + LENGTH(flash); .init : { @@ -220,5 +220,5 @@ SECTIONS .end_fw (NOLOAD) : ALIGN(4) { _end_fw = . ; - } > rom + } > flash } diff --git a/cpu/stm32/kconfigs/Kconfig.clk b/cpu/stm32/kconfigs/Kconfig.clk index 7ddc851b91..758d4827a4 100644 --- a/cpu/stm32/kconfigs/Kconfig.clk +++ b/cpu/stm32/kconfigs/Kconfig.clk @@ -174,7 +174,7 @@ endif # CPU_FAM_F2 || CPU_FAM_F4 || CPU_FAM_F7 || CPU_FAM_G0 || CPU_FAM_G4 || C if CPU_FAM_F0 || CPU_FAM_F1 || CPU_FAM_F3 config CLOCK_PLL_PREDIV int "PLLIN division factor" if CUSTOM_PLL_PARAMS && !CPU_LINE_STM32F031X6 && !CPU_LINE_STM32F042X6 && !CPU_LINE_STM32F303X8 - default 2 if CPU_LINE_STM32F031X6 || CPU_LINE_STM32F042X6 || CPU_LINE_STM32F303X8 + default 2 if CPU_LINE_STM32F031X6 || CPU_LINE_STM32F042X6 || CPU_LINE_STM32F303X8 || CPU_LINE_STM32F303XC default 1 range 1 16 diff --git a/dist/pythonlibs/testrunner/spawn.py b/dist/pythonlibs/testrunner/spawn.py index 60d06187d7..e334a894b3 100644 --- a/dist/pythonlibs/testrunner/spawn.py +++ b/dist/pythonlibs/testrunner/spawn.py @@ -39,7 +39,13 @@ TEST_INTERACTIVE_DELAY = int(os.environ.get('TEST_INTERACTIVE_DELAY') or 1) # By default never reset after the terminal is open unless explicitly requested # through an environment variable. TESTRUNNER_RESET_AFTER_TERM = int(os.environ.get('TESTRUNNER_RESET_AFTER_TERM') - or '0') + or 0) + +# When running e.g. tests/shell_ble we don't want to reset the board, because +# then ble-serial would terminate and the created virtual serial port would get +# lost. By default the board is reset before the test starts. +TESTRUNNER_RESET_BOARD_ON_STARTUP = \ + int(os.environ.get('TESTRUNNER_RESET_BOARD_ON_STARTUP') or 1) MAKE = os.environ.get('MAKE', 'make') @@ -70,7 +76,8 @@ def find_exc_origin(exc_info): def setup_child(timeout=10, spawnclass=pexpect.spawnu, env=None, logfile=None): # Some boards can't be reset after a terminal is open. Therefore reset # before `cleanterm`. - _reset_board(env) + if TESTRUNNER_RESET_BOARD_ON_STARTUP: + _reset_board(env) # on platforms exposing UART over USB, wait a little before connecting to # the serial terminal. This gives time for stdio to be ready. diff --git a/dist/testbed-support/makefile.iotlab.archi.inc.mk b/dist/testbed-support/makefile.iotlab.archi.inc.mk index 5c5992613a..1b34034b97 100644 --- a/dist/testbed-support/makefile.iotlab.archi.inc.mk +++ b/dist/testbed-support/makefile.iotlab.archi.inc.mk @@ -13,8 +13,10 @@ IOTLAB_ARCHI_nrf52dk = nrf52dk:ble IOTLAB_ARCHI_nrf52832-mdk = nrf52832mdk:ble IOTLAB_ARCHI_nrf52840dk = nrf52840dk:multi IOTLAB_ARCHI_nrf52840-mdk = nrf52840mdk:multi +IOTLAB_ARCHI_nucleo-wl55jc = nucleo-wl55jc:stm32wl IOTLAB_ARCHI_pba-d-01-kw2x = phynode:kw2xrf IOTLAB_ARCHI_samr21-xpro = samr21:at86rf233 IOTLAB_ARCHI_samr30-xpro = samr30:at86rf212b +IOTLAB_ARCHI_samr34-xpro = samr34:sx1276 IOTLAB_ARCHI_zigduino = zigduino:atmega128rfa1 IOTLAB_ARCHI := $(IOTLAB_ARCHI_$(BOARD)) diff --git a/dist/tools/compile_commands/compile_commands.py b/dist/tools/compile_commands/compile_commands.py index bbb0ca89e1..bc46006ff4 100755 --- a/dist/tools/compile_commands/compile_commands.py +++ b/dist/tools/compile_commands/compile_commands.py @@ -228,6 +228,9 @@ def generate_module_compile_commands(path, state, args): except ValueError: pass + if args.clangd: + cdetails.cflags.append('-Wno-unknown-warning-option') + c_extra_includes = [] cxx_extra_includes = [] @@ -288,14 +291,16 @@ if __name__ == '__main__': help='Drop the given flag, if present (repeatable)') parser.add_argument('--clangd', default=False, action='store_const', const=True, help='Shorthand for --add-built-in-includes --add-libstdxx-includes ' + - '--filter-out=-Wformat-truncation --filter-out=-Wformat-overflow ' + - '--filter-out=-mno-thumb-interwork') + 'and some CFLAG adjustments throughy --filter-out, and ignores ' + + 'unknown warning flags') _args = parser.parse_args() if _args.clangd: _args.add_built_in_includes = True _args.add_libstdcxx_includes = True - _args.filter_out = ['-Wformat-truncation', '-Wformat-overflow', '-mno-thumb-interwork', + _args.filter_out = ['-mno-thumb-interwork', # Only even included for versions of GCC that support it '-malign-data=natural', + # Only supported starting with clang 11 + '-msmall-data-limit=8', ] generate_compile_commands(_args) diff --git a/dist/tools/doccheck/exclude_patterns b/dist/tools/doccheck/exclude_patterns index 398900ddf1..bd2ff2310f 100644 --- a/dist/tools/doccheck/exclude_patterns +++ b/dist/tools/doccheck/exclude_patterns @@ -13357,6 +13357,7 @@ drivers/sx127x/include/sx127x_registers\.h:[0-9]+: warning: Member SX127X_RNG_RE drivers/sx127x/include/sx127x_registers\.h:[0-9]+: warning: Member SX127X_RNG_REG_MODEM_CONFIG2 \(macro definition\) of file sx127x_registers\.h is not documented\. drivers/sx127x/include/sx127x_registers\.h:[0-9]+: warning: Member VERSION_SX1272 \(macro definition\) of file sx127x_registers\.h is not documented\. drivers/sx127x/include/sx127x_registers\.h:[0-9]+: warning: Member VERSION_SX1276 \(macro definition\) of file sx127x_registers\.h is not documented\. +drivers/sx127x/include/sx127x_registers\.h:[0-9]+: warning: Member VERSION_SX1276_WLR089 \(macro definition\) of file sx127x_registers\.h is not documented\. drivers/tcs37727/include/tcs37727\-internal\.h:[0-9]+: warning: Member B_COEF_IF \(macro definition\) of file tcs37727\-internal\.h is not documented\. drivers/tcs37727/include/tcs37727\-internal\.h:[0-9]+: warning: Member CT_COEF_IF \(macro definition\) of file tcs37727\-internal\.h is not documented\. drivers/tcs37727/include/tcs37727\-internal\.h:[0-9]+: warning: Member CT_OFFSET_IF \(macro definition\) of file tcs37727\-internal\.h is not documented\. diff --git a/dist/tools/zep_dispatch/README.md b/dist/tools/zep_dispatch/README.md index 6d862a17c2..92b632a727 100644 --- a/dist/tools/zep_dispatch/README.md +++ b/dist/tools/zep_dispatch/README.md @@ -144,3 +144,20 @@ instance [0 | Iface: 7 | mop: 2 | ocp: 0 | mhri: 256 | mri 0] ``` This should also be visible in Foren6. + +Topology generation +------------------- + +To generate a random topology use the `topogen.sh` script. +This will randomly distribute *N* nodes on on a *W* × *H* map. +Each node has a radio range *R* ± *V* where *V* is a random variance that can also be set to 0. + +The further away a node is from a sending node, the higher the packet loss probability. +Nodes outside the sending radius have a zero probability of receiving a packet. + +If you have `gnuplot` installed this will also generate a plot of the resulting node distribution: + +![example topology](https://gist.githubusercontent.com/benpicco/6fd6f7c79a30cbbc41c3a65e53ed3682/raw/33afb859b65d949238129096858d14e2319fb5fb/network.topo.svg) + +A light color means that a node only has a one-way connection to the network, gray means a node is +entirely isolated. diff --git a/dist/tools/zep_dispatch/topogen.sh b/dist/tools/zep_dispatch/topogen.sh index 733bfbdc2e..db19059282 100755 --- a/dist/tools/zep_dispatch/topogen.sh +++ b/dist/tools/zep_dispatch/topogen.sh @@ -16,11 +16,11 @@ else CRESET= fi -WIDTH=100 -HEIGHT=100 -RANGE=30 -VARIANCE=15 -NUM=10 +WIDTH=100 # X dimension of the simulated world +HEIGHT=100 # Y dimension of the simulated world +RANGE=30 # base node radio range +VARIANCE=15 # random offset to radio range +NUM=10 # number of nodes echo "writing to $FILE" diff --git a/doc.txt b/doc.txt index c88e9cdd19..78dca2c188 100644 --- a/doc.txt +++ b/doc.txt @@ -41,7 +41,8 @@ * The following list of what `DEVELHELP=1` enables is not comprehensive, but * should give a rough impression of what to expect: * - * * Many runtime checks are enabled (stack overflow protection, warnings when + * * Many runtime checks are enabled (stack overflow protection by means of + * @ref pseudomodule_mpu_stack_guard or @ref SCHED_TEST_STACK, warnings when * sending messages to invalid PIDs, …), some of which just log errors to * stdout, some even halt the system. * * Some structures contain additional information, e.g. threads store their diff --git a/doc/doxygen/riot.doxyfile b/doc/doxygen/riot.doxyfile index 1f3eb3b090..1771dbfb75 100644 --- a/doc/doxygen/riot.doxyfile +++ b/doc/doxygen/riot.doxyfile @@ -275,7 +275,9 @@ OPTIMIZE_OUTPUT_VHDL = NO # Note that for custom extensions you also need to set FILE_PATTERNS otherwise # the files are not read by doxygen. -EXTENSION_MAPPING = +# Python is close enough that we can have Makefile comments starting with `##` +# that are both recognized by Doxygen and comments to Make +EXTENSION_MAPPING = mk=Python # If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments # according to the Markdown format, which allows for more readable @@ -771,7 +773,8 @@ INPUT = ../../doc.txt \ src/emulators.md \ src/release-cycle.md \ src/changelog.md \ - ../../LOSTANDFOUND.md + ../../LOSTANDFOUND.md \ + ../../makefiles/pseudomodules.inc.mk # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses diff --git a/drivers/adxl345/Kconfig b/drivers/adxl345/Kconfig index b0ee1109f0..172b32c7b4 100644 --- a/drivers/adxl345/Kconfig +++ b/drivers/adxl345/Kconfig @@ -10,3 +10,9 @@ config MODULE_ADXL345 depends on HAS_PERIPH_I2C depends on TEST_KCONFIG select MODULE_PERIPH_I2C + +config HAVE_ADXL345 + bool + select MODULE_ADXL345 if MODULE_SAUL_DEFAULT + help + Indicates that a adxl345 sensor is present. diff --git a/drivers/bmp180/Kconfig b/drivers/bmp180/Kconfig index 110993d6db..03d10aa0bc 100644 --- a/drivers/bmp180/Kconfig +++ b/drivers/bmp180/Kconfig @@ -12,3 +12,9 @@ config MODULE_BMP180 select MODULE_PERIPH_I2C select MODULE_ZTIMER select MODULE_ZTIMER_MSEC + +config HAVE_BMP180 + bool + select MODULE_BMP180 if MODULE_SAUL_DEFAULT + help + Indicates that a bmp180 sensor is present. diff --git a/drivers/dose/Makefile.dep b/drivers/dose/Makefile.dep index c6bca1fe29..6f3cc3507b 100644 --- a/drivers/dose/Makefile.dep +++ b/drivers/dose/Makefile.dep @@ -12,4 +12,4 @@ USEMODULE += eui_provider USEMODULE += iolist USEMODULE += netdev_eth USEMODULE += random -USEMODULE += xtimer +USEMODULE += ztimer_usec diff --git a/drivers/dose/dose.c b/drivers/dose/dose.c index 0312713413..b7784e0669 100644 --- a/drivers/dose/dose.c +++ b/drivers/dose/dose.c @@ -21,6 +21,7 @@ #include #include +#include "board.h" #include "dose.h" #include "random.h" #include "irq.h" @@ -28,10 +29,15 @@ #include "net/eui_provider.h" #include "net/netdev/eth.h" +#include "timex.h" #define ENABLE_DEBUG 0 #include "debug.h" +#if !defined(DOSE_TIMER_DEV) && IS_ACTIVE(MODULE_DOSE_WATCHDOG) +#error "DOSE_TIMER_DEV needs to be set by the board" +#endif + static uint16_t crc16_update(uint16_t crc, uint8_t octet); static dose_signal_t state_transit_blocked(dose_t *ctx, dose_signal_t signal); static dose_signal_t state_transit_idle(dose_t *ctx, dose_signal_t signal); @@ -40,7 +46,7 @@ static dose_signal_t state_transit_send(dose_t *ctx, dose_signal_t signal); static void state(dose_t *ctx, dose_signal_t src); static void _isr_uart(void *arg, uint8_t c); static void _isr_gpio(void *arg); -static void _isr_xtimer(void *arg); +static void _isr_ztimer(void *arg); static void clear_recv_buf(dose_t *ctx); static void _isr(netdev_t *netdev); static int _recv(netdev_t *dev, void *buf, size_t len, void *info); @@ -53,9 +59,6 @@ static int _init(netdev_t *dev); static void _poweron(dose_t *dev); static void _poweroff(dose_t *dev, dose_state_t sleep_state); -/* smallest possible xtimer timeout */ -static const xtimer_ticks32_t xtimer_min_timeout = {.ticks32 = XTIMER_BACKOFF}; - static uint16_t crc16_update(uint16_t crc, uint8_t octet) { crc = (uint8_t)(crc >> 8) | (crc << 8); @@ -163,7 +166,7 @@ static void _dose_watchdog_cb(void *arg, int chan) } DEBUG_PUTS("timeout"); - state(&_dose_base[i], DOSE_SIGNAL_XTIMER); + state(&_dose_base[i], DOSE_SIGNAL_ZTIMER); break; default: break; @@ -187,9 +190,8 @@ static dose_signal_t state_transit_blocked(dose_t *ctx, dose_signal_t signal) (void) signal; uint32_t backoff; - backoff = random_uint32_range(xtimer_usec_from_ticks(xtimer_min_timeout), - 2 * ctx->timeout_base); - xtimer_set(&ctx->timeout, backoff); + backoff = random_uint32_range(0, 2 * ctx->timeout_base); + ztimer_set(ZTIMER_USEC, &ctx->timeout, backoff); return DOSE_SIGNAL_NONE; } @@ -262,7 +264,7 @@ static dose_signal_t state_transit_recv(dose_t *ctx, dose_signal_t signal) if (rc == DOSE_SIGNAL_NONE && !IS_ACTIVE(MODULE_DOSE_WATCHDOG)) { /* No signal is returned. We stay in the RECV state. */ - xtimer_set(&ctx->timeout, ctx->timeout_base); + ztimer_set(ZTIMER_USEC, &ctx->timeout, ctx->timeout_base); } return rc; @@ -281,7 +283,7 @@ static dose_signal_t state_transit_send(dose_t *ctx, dose_signal_t signal) * will bring us back to the BLOCKED state after _send has emitted * its last octet. */ #ifndef MODULE_PERIPH_UART_COLLISION - xtimer_set(&ctx->timeout, ctx->timeout_base); + ztimer_set(ZTIMER_USEC, &ctx->timeout, ctx->timeout_base); #endif return DOSE_SIGNAL_NONE; @@ -305,10 +307,10 @@ static void state(dose_t *ctx, dose_signal_t signal) break; case DOSE_STATE_SEND + DOSE_SIGNAL_END: - case DOSE_STATE_SEND + DOSE_SIGNAL_XTIMER: + case DOSE_STATE_SEND + DOSE_SIGNAL_ZTIMER: case DOSE_STATE_INIT + DOSE_SIGNAL_INIT: case DOSE_STATE_RECV + DOSE_SIGNAL_END: - case DOSE_STATE_RECV + DOSE_SIGNAL_XTIMER: + case DOSE_STATE_RECV + DOSE_SIGNAL_ZTIMER: signal = state_transit_idle(ctx, signal); ctx->state = DOSE_STATE_IDLE; break; @@ -322,7 +324,7 @@ static void state(dose_t *ctx, dose_signal_t signal) ctx->state = DOSE_STATE_RECV; break; - case DOSE_STATE_BLOCKED + DOSE_SIGNAL_XTIMER: + case DOSE_STATE_BLOCKED + DOSE_SIGNAL_ZTIMER: case DOSE_STATE_SEND + DOSE_SIGNAL_UART: signal = state_transit_send(ctx, signal); ctx->state = DOSE_STATE_SEND; @@ -354,7 +356,7 @@ static void _isr_gpio(void *arg) state(dev, DOSE_SIGNAL_GPIO); } -static void _isr_xtimer(void *arg) +static void _isr_ztimer(void *arg) { dose_t *dev = arg; @@ -364,7 +366,7 @@ static void _isr_xtimer(void *arg) #endif case DOSE_STATE_BLOCKED: case DOSE_STATE_SEND: - state(dev, DOSE_SIGNAL_XTIMER); + state(dev, DOSE_SIGNAL_ZTIMER); break; default: ; @@ -516,7 +518,7 @@ static inline void _send_done(dose_t *ctx, bool collision) #ifdef MODULE_PERIPH_UART_COLLISION uart_collision_detect_disable(ctx->uart); if (collision) { - state(ctx, DOSE_SIGNAL_XTIMER); + state(ctx, DOSE_SIGNAL_ZTIMER); } #else (void)ctx; @@ -775,18 +777,12 @@ void dose_setup(dose_t *ctx, const dose_params_t *params, uint8_t index) ); /* The timeout base is the minimal timeout base used for this driver. - * We have to ensure it is above the XTIMER_BACKOFF. Otherwise state - * transitions are triggered from another state transition setting up the - * timeout. * To calculate how long it takes to transfer one byte we assume * 8 data bits + 1 start bit + 1 stop bit per byte. */ ctx->timeout_base = CONFIG_DOSE_TIMEOUT_BYTES * 10UL * US_PER_SEC / params->baudrate; - if (ctx->timeout_base < xtimer_usec_from_ticks(xtimer_min_timeout)) { - ctx->timeout_base = xtimer_usec_from_ticks(xtimer_min_timeout); - } DEBUG("dose timeout set to %" PRIu32 " µs\n", ctx->timeout_base); - ctx->timeout.callback = _isr_xtimer; + ctx->timeout.callback = _isr_ztimer; ctx->timeout.arg = ctx; #ifdef MODULE_DOSE_WATCHDOG diff --git a/drivers/include/dose.h b/drivers/include/dose.h index 2ecf00239d..043437d954 100644 --- a/drivers/include/dose.h +++ b/drivers/include/dose.h @@ -82,7 +82,7 @@ #include "net/eui48.h" #include "bitarithm.h" #include "mutex.h" -#include "xtimer.h" +#include "ztimer.h" #ifdef __cplusplus extern "C" { @@ -120,7 +120,7 @@ typedef enum { DOSE_SIGNAL_INIT = 0x10, /**< Init the state machine */ DOSE_SIGNAL_GPIO = 0x20, /**< Sense GPIO detected a falling edge */ DOSE_SIGNAL_UART = 0x30, /**< Octet has been received */ - DOSE_SIGNAL_XTIMER = 0x40, /**< Timer timed out */ + DOSE_SIGNAL_ZTIMER = 0x40, /**< Timer timed out */ DOSE_SIGNAL_SEND = 0x50, /**< Enter send state */ DOSE_SIGNAL_END = 0x60 /**< Leave send state */ } dose_signal_t; @@ -165,13 +165,11 @@ typedef enum { /** * @brief Hardware timer to use with the `dose_watchdog` module. * - * This will be used to detect RX timeout instead of xtimer to speed up + * This will be used to detect RX timeout instead of ztimer to speed up * the RX path when high data rates / less CPU overhead is required. */ #if DOXYGEN #define DOSE_TIMER_DEV TIMER_DEV(…) -#elif !defined(DOSE_TIMER_DEV) && IS_ACTIVE(MODULE_DOSE_WATCHDOG) -#error "DOSE_TIMER_DEV needs to be set by the board" #endif /** @@ -197,7 +195,7 @@ typedef struct { gpio_t sense_pin; /**< GPIO to sense for start bits on the UART's rx line */ #endif gpio_t standby_pin; /**< GPIO to put the CAN transceiver in standby mode */ - xtimer_t timeout; /**< Timeout timer ensuring always to get back to IDLE state */ + ztimer_t timeout; /**< Timeout timer ensuring always to get back to IDLE state */ uint32_t timeout_base; /**< Base timeout in us */ uart_t uart; /**< UART device to use */ uint8_t uart_octet; /**< Last received octet */ diff --git a/drivers/include/mtd_spi_nor.h b/drivers/include/mtd_spi_nor.h index ad61670255..3852946e07 100644 --- a/drivers/include/mtd_spi_nor.h +++ b/drivers/include/mtd_spi_nor.h @@ -113,7 +113,6 @@ typedef struct { gpio_t cs; /**< CS pin GPIO handle */ gpio_t wp; /**< Write Protect pin GPIO handle */ gpio_t hold; /**< HOLD pin GPIO handle */ - uint8_t addr_width; /**< Number of bytes in addresses, usually 3 for small devices */ } mtd_spi_nor_params_t; /** @@ -150,6 +149,12 @@ typedef struct { * Computed by mtd_spi_nor_init, no need to touch outside the driver. */ uint8_t sec_addr_shift; + /** + * @brief number of address bytes + * + * Computed by mtd_spi_nor_init, no need to touch outside the driver. + */ + uint8_t addr_width; } mtd_spi_nor_t; /** diff --git a/drivers/mpu9x50/Kconfig b/drivers/mpu9x50/Kconfig index 54213effac..f98828e105 100644 --- a/drivers/mpu9x50/Kconfig +++ b/drivers/mpu9x50/Kconfig @@ -5,30 +5,46 @@ # directory for more details. # -if TEST_KCONFIG -choice - bool "MPU-9X50 accelerometer/magnetometer/gyroscope" - optional - depends on HAS_PERIPH_I2C - help - This driver supports both MPU9150 and MPU9250. Choose one model. - -config MODULE_MPU9150 - bool "MPU-9150" - select MODULE_MPU9X50 - -config MODULE_MPU9250 - bool "MPU-9250" - select MODULE_MPU9X50 - -endchoice - -config MODULE_MPU9X50 +menuconfig MODULE_MPU9X50 bool + prompt "MPU-9X50 accelerometer/magnetometer/gyroscope" if !(MODULE_SAUL_DEFAULT && HAVE_MPU9X50) + default y if (MODULE_SAUL_DEFAULT && HAVE_MPU9X50) + depends on TEST_KCONFIG depends on HAS_PERIPH_I2C select MODULE_PERIPH_I2C select MODULE_ZTIMER select MODULE_ZTIMER_MSEC -endif # TEST_KCONFIG +choice + bool "Sensor variant" + default MODULE_MPU9150 if HAVE_MPU9150 + default MODULE_MPU9250 if HAVE_MPU9250 + depends on MODULE_MPU9X50 + help + This driver supports both MPU9150 and MPU9250. Choose one model. + +config MODULE_MPU9150 + bool "MPU-9150" + +config MODULE_MPU9250 + bool "MPU-9250" + +endchoice + +config HAVE_MPU9150 + bool + select HAVE_MPU9X50 + help + Indicates that a mpu9150 sensor is present. + +config HAVE_MPU9250 + bool + select HAVE_MPU9X50 + help + Indicates that a mpu9250 sensor is present. + +config HAVE_MPU9X50 + bool + help + Indicates that a mpu9X50 sensor is present. diff --git a/drivers/mtd_spi_nor/mtd_spi_nor.c b/drivers/mtd_spi_nor/mtd_spi_nor.c index a444275bc6..77d4646c72 100644 --- a/drivers/mtd_spi_nor/mtd_spi_nor.c +++ b/drivers/mtd_spi_nor/mtd_spi_nor.c @@ -45,6 +45,8 @@ #define SFLASH_CMD_4_BYTE_ADDR (0xB7) /**< enable 32 bit addressing */ #define SFLASH_CMD_3_BYTE_ADDR (0xE9) /**< enable 24 bit addressing */ +#define SFLASH_CMD_ULBPR (0x98) /**< Global Block Protection Unlock */ + #define MTD_64K (65536ul) #define MTD_64K_ADDR_MASK (0xFFFF) #define MTD_32K (32768ul) @@ -66,6 +68,7 @@ typedef enum { SPI_NOR_JEDEC_ATMEL = 0x1F | JEDEC_BANK(1), + SPI_NOR_JEDEC_MICROCHIP = 0xBF | JEDEC_BANK(1), } jedec_manuf_t; /** @} */ @@ -88,7 +91,7 @@ static void mtd_spi_release(const mtd_spi_nor_t *dev) static inline uint8_t* _be_addr(const mtd_spi_nor_t *dev, uint32_t *addr) { *addr = htonl(*addr); - return &((uint8_t*)addr)[4 - dev->params->addr_width]; + return &((uint8_t*)addr)[4 - dev->addr_width]; } /** @@ -111,7 +114,7 @@ static void mtd_spi_cmd_addr_read(const mtd_spi_nor_t *dev, uint8_t opcode, if (IS_ACTIVE(ENABLE_TRACE)) { TRACE("mtd_spi_cmd_addr_read: addr:"); - for (unsigned int i = 0; i < dev->params->addr_width; ++i) { + for (unsigned int i = 0; i < dev->addr_width; ++i) { TRACE(" %02x", addr_buf[i]); } TRACE("\n"); @@ -120,7 +123,7 @@ static void mtd_spi_cmd_addr_read(const mtd_spi_nor_t *dev, uint8_t opcode, /* Send opcode followed by address */ spi_transfer_byte(_get_spi(dev), dev->params->cs, true, opcode); spi_transfer_bytes(_get_spi(dev), dev->params->cs, true, - (char *)addr_buf, NULL, dev->params->addr_width); + (char *)addr_buf, NULL, dev->addr_width); /* Read data */ spi_transfer_bytes(_get_spi(dev), dev->params->cs, false, @@ -147,7 +150,7 @@ static void mtd_spi_cmd_addr_write(const mtd_spi_nor_t *dev, uint8_t opcode, if (IS_ACTIVE(ENABLE_TRACE)) { TRACE("mtd_spi_cmd_addr_write: addr:"); - for (unsigned int i = 0; i < dev->params->addr_width; ++i) { + for (unsigned int i = 0; i < dev->addr_width; ++i) { TRACE(" %02x", addr_buf[i]); } TRACE("\n"); @@ -159,7 +162,7 @@ static void mtd_spi_cmd_addr_write(const mtd_spi_nor_t *dev, uint8_t opcode, /* only keep CS asserted when there is data that follows */ bool cont = (count > 0); spi_transfer_bytes(_get_spi(dev), dev->params->cs, cont, - (char *)addr_buf, NULL, dev->params->addr_width); + (char *)addr_buf, NULL, dev->addr_width); /* Write data */ if (cont) { @@ -303,6 +306,28 @@ static uint32_t mtd_spi_nor_get_size(const mtd_jedec_id_t *id) (id->device[1] & ~0x3) == 0) { return (0x1F & id->device[0]) * MBIT_AS_BYTES; } + if (mtd_spi_manuf_match(id, SPI_NOR_JEDEC_MICROCHIP)) { + switch (id->device[1]) { + case 0x12: /* SST26VF020A */ + case 0x8c: /* SST25VF020B */ + return 2 * MBIT_AS_BYTES; + case 0x54: /* SST26WF040B */ + case 0x8d: /* SST25VF040B */ + return 4 * MBIT_AS_BYTES; + case 0x58: /* SST26WF080B */ + case 0x8e: /* SST25VF080B */ + return 8 * MBIT_AS_BYTES; + case 0x1: /* SST26VF016 */ + case 0x41: /* SST26VF016B */ + return 16 * MBIT_AS_BYTES; + case 0x2: /* SST26VF032 */ + case 0x42: /* SST26VF032B */ + return 32 * MBIT_AS_BYTES; + case 0x43: /* SST26VF064B */ + case 0x53: /* SST26WF064C */ + return 64 * MBIT_AS_BYTES; + } + } /* everyone else seems to use device ID 2 for density */ return 1 << id->device[1]; @@ -376,6 +401,12 @@ static void _init_pins(mtd_spi_nor_t *dev) } } +static void _enable_32bit_addr(mtd_spi_nor_t *dev) +{ + mtd_spi_cmd(dev, dev->params->opcode->wren); + mtd_spi_cmd(dev, SFLASH_CMD_4_BYTE_ADDR); +} + static int mtd_spi_nor_power(mtd_dev_t *mtd, enum mtd_power_state power) { mtd_spi_nor_t *dev = (mtd_spi_nor_t *)mtd; @@ -399,9 +430,8 @@ static int mtd_spi_nor_power(mtd_dev_t *mtd, enum mtd_power_state power) } #endif /* enable 32 bit address mode */ - if (dev->params->addr_width == 4) { - mtd_spi_cmd(dev, dev->params->opcode->wren); - mtd_spi_cmd(dev, SFLASH_CMD_4_BYTE_ADDR); + if (dev->addr_width == 4) { + _enable_32bit_addr(dev); } break; @@ -414,6 +444,20 @@ static int mtd_spi_nor_power(mtd_dev_t *mtd, enum mtd_power_state power) return 0; } +static void _set_addr_width(mtd_dev_t *mtd) +{ + mtd_spi_nor_t *dev = (mtd_spi_nor_t *)mtd; + + uint32_t flash_size = mtd->pages_per_sector * mtd->page_size + * mtd->sector_count; + + if (flash_size > 0xFFFFFF) { + dev->addr_width = 4; + } else { + dev->addr_width = 3; + } +} + static int mtd_spi_nor_init(mtd_dev_t *mtd) { DEBUG("mtd_spi_nor_init: %p\n", (void *)mtd); @@ -422,10 +466,6 @@ static int mtd_spi_nor_init(mtd_dev_t *mtd) DEBUG("mtd_spi_nor_init: -> spi: %lx, cs: %lx, opcodes: %p\n", (unsigned long)_get_spi(dev), (unsigned long)dev->params->cs, (void *)dev->params->opcode); - /* verify configuration */ - assert(dev->params->addr_width > 0); - assert(dev->params->addr_width <= 4); - /* CS, WP, Hold */ _init_pins(dev); @@ -450,6 +490,7 @@ static int mtd_spi_nor_init(mtd_dev_t *mtd) mtd->sector_count = mtd_spi_nor_get_size(&dev->jedec_id) / (mtd->pages_per_sector * mtd->page_size); } + _set_addr_width(mtd); DEBUG("mtd_spi_nor_init: %" PRIu32 " bytes " "(%" PRIu32 " sectors, %" PRIu32 " bytes/sector, " @@ -459,14 +500,23 @@ static int mtd_spi_nor_init(mtd_dev_t *mtd) mtd->sector_count, mtd->pages_per_sector * mtd->page_size, mtd->pages_per_sector * mtd->sector_count, mtd->pages_per_sector, mtd->page_size); - DEBUG("mtd_spi_nor_init: Using %u byte addresses\n", dev->params->addr_width); + DEBUG("mtd_spi_nor_init: Using %u byte addresses\n", dev->addr_width); uint8_t status; mtd_spi_cmd_read(dev, dev->params->opcode->rdsr, &status, sizeof(status)); - mtd_spi_release(dev); - DEBUG("mtd_spi_nor_init: device status = 0x%02x\n", (unsigned int)status); + /* enable 32 bit address mode */ + if (dev->addr_width == 4) { + _enable_32bit_addr(dev); + } + + /* Global Block-Protection Unlock */ + mtd_spi_cmd(dev, dev->params->opcode->wren); + mtd_spi_cmd(dev, SFLASH_CMD_ULBPR); + + mtd_spi_release(dev); + /* check whether page size and sector size are powers of two (most chips' are) * and compute the number of shifts needed to get the page and sector addresses * from a byte address */ diff --git a/drivers/sx127x/include/sx127x_registers.h b/drivers/sx127x/include/sx127x_registers.h index 82fe55e44e..03da694325 100644 --- a/drivers/sx127x/include/sx127x_registers.h +++ b/drivers/sx127x/include/sx127x_registers.h @@ -558,6 +558,7 @@ extern "C" { /* Version */ #define SX127X_REG_VERSION (0x42) #define VERSION_SX1276 (0x12) +#define VERSION_SX1276_WLR089 (0x13) #define VERSION_SX1272 (0x22) /* Additional settings */ diff --git a/drivers/sx127x/sx127x_internal.c b/drivers/sx127x/sx127x_internal.c index e5323feb5e..d3b86b40ae 100644 --- a/drivers/sx127x/sx127x_internal.c +++ b/drivers/sx127x/sx127x_internal.c @@ -53,7 +53,7 @@ int sx127x_check_version(const sx127x_t *dev) } DEBUG("[sx127x] SX1272 transceiver detected\n"); #else /* MODULE_SX1276) */ - if (version != VERSION_SX1276) { + if (version != VERSION_SX1276 && version != VERSION_SX1276_WLR089) { DEBUG("[sx127x] sx1276 test failed, invalid version number: %d\n", version); return -1; diff --git a/examples/hello-world/main.c b/examples/hello-world/main.c index f51bf8c0a0..4968a3a30d 100644 --- a/examples/hello-world/main.c +++ b/examples/hello-world/main.c @@ -23,7 +23,7 @@ int main(void) { - puts("Hello World!"); + puts("Hello CI TEST"); printf("You are running RIOT on a(n) %s board.\n", RIOT_BOARD); printf("This board features a(n) %s MCU.\n", RIOT_MCU); diff --git a/makefiles/cargo-targets.inc.mk b/makefiles/cargo-targets.inc.mk index f9343e1ddf..e6b9809ed6 100644 --- a/makefiles/cargo-targets.inc.mk +++ b/makefiles/cargo-targets.inc.mk @@ -11,7 +11,9 @@ CARGO_COMPILE_COMMANDS_FLAGS = --clang $(CARGO_COMPILE_COMMANDS): $(BUILDDEPS) $(Q)DIRS="$(DIRS)" APPLICATION_BLOBS="$(BLOBS)" \ "$(MAKE)" -C $(APPDIR) -f $(RIOTMAKE)/application.inc.mk compile-commands + @# replacement addresses https://github.com/rust-lang/rust-bindgen/issues/1555 $(Q)$(RIOTTOOLS)/compile_commands/compile_commands.py $(CARGO_COMPILE_COMMANDS_FLAGS) $(BINDIR) \ + | sed 's/"riscv-none-embed"/"riscv32"/g' \ | $(LAZYSPONGE) $@ diff --git a/makefiles/dependency_resolution.inc.mk b/makefiles/dependency_resolution.inc.mk index a3a76223c2..55a142076c 100644 --- a/makefiles/dependency_resolution.inc.mk +++ b/makefiles/dependency_resolution.inc.mk @@ -6,6 +6,10 @@ EXTERNAL_MODULE_PATHS := $(sort $(foreach dir,$(EXTERNAL_MODULE_DIRS),\ $(foreach mod,$(USEMODULE),$(dir $(wildcard $(dir)/$(mod)/Makefile))))) +# Locate used packages in $(RIOTPKG). +PKG_PATHS := $(sort $(foreach dir,$(RIOTPKG),\ + $(foreach pkg,$(USEPKG),$(dir $(wildcard $(dir)/$(pkg)/Makefile))))) + # Back up current state to detect changes OLD_STATE := $(USEMODULE) $(USEPKG) $(FEATURES_USED) diff --git a/makefiles/docker.inc.mk b/makefiles/docker.inc.mk index cfa6cc7c4e..6a547fdeaf 100644 --- a/makefiles/docker.inc.mk +++ b/makefiles/docker.inc.mk @@ -47,6 +47,7 @@ export DOCKER_ENV_VARS += \ ELFFILE \ HEXFILE \ FLASHFILE \ + IOTLAB_NODE \ LINK \ LINKFLAGPREFIX \ LINKFLAGS \ @@ -241,6 +242,11 @@ DOCKER_APPDIR = $(DOCKER_RIOTPROJECT)/$(BUILDRELPATH) # Directory mapping in docker and directories environment variable configuration DOCKER_VOLUMES_AND_ENV += $(call docker_volume,$(ETC_LOCALTIME),/etc/localtime,ro) DOCKER_VOLUMES_AND_ENV += $(call docker_volume,$(RIOTBASE),$(DOCKER_RIOTBASE)) +# Selective components of Cargo to ensure crates are not re-downloaded (and +# subsequently rebuilt) on every run. Not using all of ~/.cargo as ~/.cargo/bin +# would be run by Cargo and that'd be very weird. +DOCKER_VOLUMES_AND_ENV += $(call docker_volume,$(HOME)/.cargo/registry,$(DOCKER_BUILD_ROOT)/.cargo/registry) +DOCKER_VOLUMES_AND_ENV += $(call docker_volume,$(HOME)/.cargo/git,$(DOCKER_BUILD_ROOT)/.cargo/git) DOCKER_VOLUMES_AND_ENV += -e 'RIOTBASE=$(DOCKER_RIOTBASE)' DOCKER_VOLUMES_AND_ENV += -e 'CCACHE_BASEDIR=$(DOCKER_RIOTBASE)' diff --git a/makefiles/kconfig.mk b/makefiles/kconfig.mk index 189d13c685..c64f1f6ebb 100644 --- a/makefiles/kconfig.mk +++ b/makefiles/kconfig.mk @@ -179,8 +179,8 @@ $(KCONFIG_GENERATED_ENV_CONFIG): FORCE | $(GENERATED_DIR) | $(LAZYSPONGE) $(LAZYSPONGE_FLAGS) $@ # All directories in EXTERNAL_MODULES_PATHS which have a Kconfig file -EXTERNAL_MODULE_KCONFIGS ?= $(sort $(foreach dir,$(EXTERNAL_MODULE_PATHS),\ - $(wildcard $(dir)/Kconfig))) +EXTERNAL_MODULE_KCONFIGS ?= $(sort $(foreach dir,$(EXTERNAL_MODULE_DIRS),\ + $(wildcard $(dir)/*/Kconfig))) # Build a Kconfig file that source all external modules configuration # files. Every EXTERNAL_MODULE_DIRS with a Kconfig file is written to # KCONFIG_EXTERNAL_CONFIGS as 'osource dir/Kconfig' diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index c2a03b2d4a..5a5c9ab281 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -1,6 +1,38 @@ +## @defgroup pseudomodules Generic pseudomodules +## @brief Modules influencing general RIOT behavior +## +## These are implemented in other modules or core components, +## and serve to enable certain functionality. +## +## Here, pseudomodules are used instead of plain defines (that would be set using `CFLAGS += -DMODULE_NAME`) +## because they can participate in dependency resolution: +## they can pull in other modules. +## +## Pseudomodules are often enabled automatically through module dependencies, +## but can also be enabled manually by stating `USEMODULE += module_name` in the Makefile. +## +## The list of documented pseudomodules is not comprehensive by far; +## @ref makefiles/pseudomodules.inc.mk lists all that are not defined inside their main modules. +## Not all modules listed there are "generic" pseudomodules; +## some are merely optional components of a particular subsystem and should be documented there. +## +## See also the documentation on pseudomodules in general. +## +## @{ + PSEUDOMODULES += atomic_utils PSEUDOMODULES += base64url + +## @defgroup pseudomodule_board_software_reset board_software_reset +## @brief Use any software-only reset button on the board to reboot +## +## Some boards have reset buttons that are not wired to the MCU's reset line, +## but merely are configured to cause a reset by convention. +## +## If this module is active, the button will be configured thusly (and then not +## be advertised in any other capacity, e.g. through @ref sys_auto_init_saul). PSEUDOMODULES += board_software_reset + PSEUDOMODULES += can_mbox PSEUDOMODULES += can_pm PSEUDOMODULES += can_raw @@ -87,8 +119,21 @@ PSEUDOMODULES += log PSEUDOMODULES += log_printfnoformat PSEUDOMODULES += log_color PSEUDOMODULES += lora + +## @defgroup pseudomodule_mpu_stack_guard mpu_stack_guard +## @brief MPU based stack guard +## +## When this module is active (which it is by default on supported MCUs), +## the Memory Protection Unit will be configured to detect stack overflows. PSEUDOMODULES += mpu_stack_guard + +## @defgroup pseudomodule_mpu_noexec_ram mpu_noexec_ram +## @brief Mark RAM as non-executable using the MPU +## +## Mark the RAM non executable. +## This is a protection mechanism which makes exploitation of buffer overflows significantly harder. PSEUDOMODULES += mpu_noexec_ram + PSEUDOMODULES += mtd_write_page PSEUDOMODULES += nanocoap_% PSEUDOMODULES += netdev_default @@ -109,11 +154,15 @@ PSEUDOMODULES += netstats_rpl PSEUDOMODULES += nimble PSEUDOMODULES += nimble_adv_ext PSEUDOMODULES += nimble_autoconn_% +PSEUDOMODULES += nimble_netif_ext PSEUDOMODULES += nimble_phy_coded PSEUDOMODULES += nimble_phy_2mbit +PSEUDOMODULES += nimble_rpble_ext +PSEUDOMODULES += nimble_statconn_ext PSEUDOMODULES += newlib PSEUDOMODULES += newlib_gnu_source PSEUDOMODULES += newlib_nano +PSEUDOMODULES += nice PSEUDOMODULES += nrf24l01p_ng_diagnostics PSEUDOMODULES += openthread PSEUDOMODULES += picolibc @@ -155,6 +204,7 @@ PSEUDOMODULES += stdin PSEUDOMODULES += stdio_available PSEUDOMODULES += stdio_cdc_acm PSEUDOMODULES += stdio_ethos +PSEUDOMODULES += stdio_nimble_debug PSEUDOMODULES += stdio_uart_rx PSEUDOMODULES += stm32_eth PSEUDOMODULES += stm32_eth_auto @@ -214,3 +264,5 @@ NO_PSEUDOMODULES += auto_init_usbus NO_PSEUDOMODULES += auto_init_screen # Packages and drivers may also add modules to PSEUDOMODULES in their `Makefile.include`. + +## @} diff --git a/makefiles/stdio.inc.mk b/makefiles/stdio.inc.mk index 477bb6d97e..a5dd528670 100644 --- a/makefiles/stdio.inc.mk +++ b/makefiles/stdio.inc.mk @@ -2,6 +2,7 @@ STDIO_MODULES = \ slipdev_stdio \ stdio_cdc_acm \ stdio_ethos \ + stdio_nimble \ stdio_null \ stdio_rtt \ stdio_semihosting \ @@ -29,6 +30,18 @@ ifneq (,$(filter stdio_ethos,$(USEMODULE))) USEMODULE += stdin endif +ifneq (,$(filter stdio_nimble,$(USEMODULE))) + USEMODULE += stdio_available + USEPKG += nimble + USEMODULE += tsrb + USEMODULE += isrpipe + USEMODULE += nimble_svc_gap + USEMODULE += nimble_svc_gatt + ifneq (,$(filter stdio_nimble_debug,$(USEMODULE))) + FEATURES_REQUIRED += periph_uart + endif +endif + ifneq (,$(filter stdin,$(USEMODULE))) ifneq (,$(filter stdio_uart,$(USEMODULE))) USEMODULE += stdio_uart_rx diff --git a/makefiles/vars.inc.mk b/makefiles/vars.inc.mk index c8607d295b..70df740c53 100644 --- a/makefiles/vars.inc.mk +++ b/makefiles/vars.inc.mk @@ -45,6 +45,7 @@ export BINDIR # This is the folder where the application should b export CARGO_TARGET_DIR # This is the folder where Rust parts of the application should be built in. export BUILD_DIR # This is the base folder to store common build files and artifacts, e.g. test results. export APPDIR # The base folder containing the application +export PKG_PATHS # List of absolute paths where packages of $(USEPKG) can be found export PKGDIRBASE # The base folder for building packages export PYTHONPATH # Python default search path for module filesi, with RIOT specific packages diff --git a/pkg/Kconfig b/pkg/Kconfig index f396515be3..f44e88d899 100644 --- a/pkg/Kconfig +++ b/pkg/Kconfig @@ -21,6 +21,7 @@ rsource "esp32_sdk/Kconfig" rsource "esp32_sdk_libs/Kconfig" rsource "esp8266_sdk/Kconfig" rsource "fff/Kconfig" +rsource "fido2_tests/Kconfig" rsource "gecko_sdk/Kconfig" rsource "gemmlowp/Kconfig" rsource "hacl/Kconfig" diff --git a/pkg/esp32_sdk/Makefile b/pkg/esp32_sdk/Makefile index 0d0c813b5d..1538c7d02c 100644 --- a/pkg/esp32_sdk/Makefile +++ b/pkg/esp32_sdk/Makefile @@ -20,11 +20,13 @@ ESP32_SDK_LIBS = $(addprefix $(ESP32_SDK_BUILD_DIR)/, $(ESP32_SDK_COMPONENT_LIBS all: $(ESP32_SDK_LIBS) $(ESP32_SDK_VER_FILE) -$(ESP32_SDK_BUILD_DIR): +$(PKG_PREPARED): $(ESP32_SDK_BUILD_DIR) $(ESP32_SDK_VER_FILE) + +$(ESP32_SDK_BUILD_DIR): $(PKG_PATCHED) $(Q)mkdir -p $(ESP32_SDK_BUILD_DIR) # Set the SDK version from the SDK hash/tag. For example "v3.1-51-g913a06a9". -$(ESP32_SDK_VER_FILE): +$(ESP32_SDK_VER_FILE): $(PKG_PATCHED) | $(ESP32_SDK_BUILD_DIR) $(Q)echo "#define IDF_VER \"$(ESP32_SDK_VER_CMD)\"" > $@ $(ESP32_SDK_BUILD_DIR)/lib%.a: \ diff --git a/pkg/esp32_sdk_libs/Makefile b/pkg/esp32_sdk_libs/Makefile index 56760a4e25..0ce50096dd 100644 --- a/pkg/esp32_sdk_libs/Makefile +++ b/pkg/esp32_sdk_libs/Makefile @@ -31,7 +31,9 @@ ESP32_SDK_LIBS = $(addprefix $(ESP32_SDK_BUILD_DIR)/, $(ESP32_SDK_COMPONENT_LIBS all: $(ESP32_SDK_LIBS) -$(ESP32_SDK_BUILD_DIR): +$(PKG_PREPARED): $(ESP32_SDK_BUILD_DIR) + +$(ESP32_SDK_BUILD_DIR): $(PKG_PATCHED) $(Q)mkdir -p $(ESP32_SDK_BUILD_DIR) $(ESP32_SDK_BUILD_DIR)/lib%.a: \ diff --git a/pkg/esp8266_sdk/Makefile b/pkg/esp8266_sdk/Makefile index 1453c63006..59cde6131d 100644 --- a/pkg/esp8266_sdk/Makefile +++ b/pkg/esp8266_sdk/Makefile @@ -20,7 +20,9 @@ ESP_SDK_LIBS = $(addprefix $(ESP8266_SDK_BUILD_DIR)/, $(ESP_SDK_COMPONENT_LIBS)) all: $(ESP_SDK_LIBS) $(ESP8266_SDK_BUILD_DIR)/esp8266_idf_version.h -$(ESP8266_SDK_BUILD_DIR): +$(PKG_PREPARED): $(ESP8266_SDK_BUILD_DIR) + +$(ESP8266_SDK_BUILD_DIR): $(PKG_PATCHED) $(Q)mkdir -p $(ESP8266_SDK_BUILD_DIR) # Set the SDK version from the SDK hash/tag. For example "v3.1-51-g913a06a9". diff --git a/pkg/fido2_tests/Kconfig b/pkg/fido2_tests/Kconfig new file mode 100644 index 0000000000..9648b31c7d --- /dev/null +++ b/pkg/fido2_tests/Kconfig @@ -0,0 +1,4 @@ +config PACKAGE_FIDO2_TESTS + bool "FIDO2 tests" + help + Test suite for FIDO2, U2F, and other security key functions. diff --git a/pkg/nimble/Makefile b/pkg/nimble/Makefile index b51b048a57..832f06411c 100644 --- a/pkg/nimble/Makefile +++ b/pkg/nimble/Makefile @@ -23,7 +23,7 @@ else CFLAGS += -Wno-unused-but-set-variable endif -IGNORE := nimble_autoconn_% nimble_phy_% nimble_adv_ext +IGNORE := nimble_autoconn_% nimble_phy_% nimble_%_ext SUBMODS := $(filter-out $(IGNORE),$(filter nimble_%,$(USEMODULE))) .PHONY: all diff --git a/pkg/nimble/Makefile.dep b/pkg/nimble/Makefile.dep index f9e44d4f98..2388eefc15 100644 --- a/pkg/nimble/Makefile.dep +++ b/pkg/nimble/Makefile.dep @@ -12,6 +12,15 @@ USEMODULE += nimble_riot_contrib # RIOT port USEMODULE += nimble_porting_nimble +# Pull in dependencies based on used features +ifneq (,$(filter ble_phy_coded,$(FEATURES_USED))) + USEMODULE += nimble_phy_coded +endif + +ifneq (,$(filter ble_phy_2mbit,$(FEATURES_USED))) + USEMODULE += nimble_phy_2mbit +endif + # NOTE: this dependency depends on inclusion order, for it to work properly # mynewt-core should be selected as nimble backend as early as possible, # i.e. at the application level. @@ -56,6 +65,10 @@ ifneq (,$(filter nimble_autoadv,$(USEMODULE))) USEMODULE += bluetil_ad endif +ifneq (,$(filter nimble_autoconn_ext,$(USEMODULE))) + USEMODULE += nimble_netif_ext +endif + ifneq (,$(filter nimble_autoconn_%,$(USEMODULE))) USEMODULE += nimble_autoconn endif @@ -67,10 +80,6 @@ ifneq (,$(filter nimble_autoconn,$(USEMODULE))) USEMODULE += bluetil_ad endif -ifneq (,$(filter nimble_phy_%,$(USEMODULE))) - USEMODULE += nimble_adv_ext -endif - ifneq (,$(filter nimble_phy_2mbit,$(USEMODULE))) FEATURES_REQUIRED += ble_phy_2mbit endif @@ -79,6 +88,11 @@ ifneq (,$(filter nimble_phy_coded,$(USEMODULE))) FEATURES_REQUIRED += ble_phy_coded endif +ifneq (,$(filter nimble_rpble_ext,$(USEMODULE))) + USEMODULE += nimble_rpble + USEMODULE += nimble_netif_ext +endif + ifneq (,$(filter nimble_rpble,$(USEMODULE))) USEMODULE += gnrc_rpl USEMODULE += nimble_netif @@ -92,12 +106,22 @@ ifneq (,$(filter nimble_scanlist,$(USEMODULE))) USEMODULE += ztimer_usec endif +ifneq (,$(filter nimble_statconn_ext,$(USEMODULE))) + USEMODULE += nimble_statconn + USEMODULE += nimble_netif_ext +endif + ifneq (,$(filter nimble_statconn,$(USEMODULE))) USEMODULE += random USEMODULE += nimble_netif USEMODULE += nimble_addr endif +ifneq (,$(filter nimble_netif_ext,$(USEMODULE))) + USEMODULE += nimble_netif + USEMODULE += nimble_adv_ext +endif + ifneq (,$(filter nimble_netif,$(USEMODULE))) FEATURES_REQUIRED += ble_nimble_netif USEMODULE += random diff --git a/pkg/nimble/Makefile.include b/pkg/nimble/Makefile.include index 099fc815ad..2bc10547d7 100644 --- a/pkg/nimble/Makefile.include +++ b/pkg/nimble/Makefile.include @@ -26,6 +26,14 @@ ifneq (,$(filter nimble_controller,$(USEMODULE))) ifneq (,$(filter nimble_drivers_nrf5x,$(USEMODULE))) INCLUDES += $(NIMIBASE)/nimble/drivers/$(CPU_FAM)/include endif + + # Enable additional PHY modes if requested by the build + ifneq (,$(filter ble_phy_2mbit,$(FEATURES_USED))) + CFLAGS += -DMYNEWT_VAL_BLE_LL_CFG_FEAT_LE_2M_PHY=1 + endif + ifneq (,$(filter ble_phy_coded,$(FEATURES_USED))) + CFLAGS += -DMYNEWT_VAL_BLE_LL_CFG_FEAT_LE_CODED_PHY=1 + endif endif # include nimble host headers @@ -94,18 +102,6 @@ ifneq (,$(filter nimble_adv_ext,$(USEMODULE))) endif endif -ifneq (,$(filter nimble_phy_2mbit,$(USEMODULE))) - ifneq (,$(filter nimble_controller,$(USEMODULE))) - CFLAGS += -DMYNEWT_VAL_BLE_LL_CFG_FEAT_LE_2M_PHY=1 - endif -endif - -ifneq (,$(filter nimble_phy_coded,$(USEMODULE))) - ifneq (,$(filter nimble_controller,$(USEMODULE))) - CFLAGS += -DMYNEWT_VAL_BLE_LL_CFG_FEAT_LE_CODED_PHY=1 - endif -endif - ifneq (,$(filter nimble_netif,$(USEMODULE))) INCLUDES += -I$(RIOTPKG)/nimble/netif/include @@ -135,6 +131,17 @@ ifneq (,$(filter nimble_netif,$(USEMODULE))) CFLAGS += -DMYNEWT_VAL_BLE_LL_CONN_INIT_SLOTS=1 CFLAGS += -DMYNEWT_VAL_BLE_LL_CFG_FEAT_DATA_LEN_EXT=1 endif +else + ifneq (,$(filter stdio_nimble,$(USEMODULE))) + # the maximum fragment size that we can receive. For maximum efficiency this + # should be equal to the maximum configured link layer packet size. + # WARNING: this value MUST never be larger than MYNEWT_VAL_BLE_LL_MAX_PKT_SIZE + CFLAGS += -DMYNEWT_VAL_BLE_L2CAP_COC_MPS=251 + + # in order to fit a 251 byte COC data segment into a single mbuf buffer, the + # used block size must be at least 297 byte (251 data + 48 overhead) + CFLAGS += -DMYNEWT_VAL_MSYS_1_BLOCK_SIZE="(MYNEWT_VAL_BLE_L2CAP_COC_MPS + 48)" + endif endif ifneq (,$(filter nimble_rpble,$(USEMODULE))) diff --git a/pkg/nimble/autoconn/include/nimble_autoconn.h b/pkg/nimble/autoconn/include/nimble_autoconn.h index d9e23bfb4f..d600b650e2 100644 --- a/pkg/nimble/autoconn/include/nimble_autoconn.h +++ b/pkg/nimble/autoconn/include/nimble_autoconn.h @@ -131,29 +131,31 @@ enum { */ typedef struct { /** amount of time spend in scanning mode [in ms] */ - uint32_t period_scan; + uint32_t period_scan_ms; /** amount of time spend in advertising mode [in ms] */ - uint32_t period_adv; + uint32_t period_adv_ms; /** a random value from 0 to this value is added to the duration of each * scanning and advertising period [in ms] */ - uint32_t period_jitter; + uint32_t period_jitter_ms; /** advertising interval used when in advertising mode [in ms] */ - uint32_t adv_itvl; + uint32_t adv_itvl_ms; /** scan interval applied while in scanning state [in ms] */ - uint32_t scan_itvl; + uint32_t scan_itvl_ms; /** scan window applied while in scanning state [in ms] */ - uint32_t scan_win; + uint32_t scan_win_ms; /** opening a new connection is aborted after this time [in ms] */ - uint32_t conn_timeout; + uint32_t conn_timeout_ms; /** connection interval used when opening a new connection, lower bound. * [in ms] */ - uint32_t conn_itvl_min; + uint32_t conn_itvl_min_ms; /** connection interval, upper bound [in ms] */ - uint32_t conn_itvl_max; - /** slave latency used for new connections [in ms] */ + uint32_t conn_itvl_max_ms; + /** slave latency used for new connections */ uint16_t conn_latency; /** supervision timeout used for new connections [in ms] */ - uint32_t conn_super_to; + uint32_t conn_super_to_ms; + /** BLE PHY mode to use */ + nimble_phy_t phy_mode; /** node ID included in the advertising data, may be NULL */ const char *node_id; } nimble_autoconn_params_t; diff --git a/pkg/nimble/autoconn/include/nimble_autoconn_params.h b/pkg/nimble/autoconn/include/nimble_autoconn_params.h index 67532286f9..121bb03491 100644 --- a/pkg/nimble/autoconn/include/nimble_autoconn_params.h +++ b/pkg/nimble/autoconn/include/nimble_autoconn_params.h @@ -64,24 +64,32 @@ extern "C" { #define NIMBLE_AUTOCONN_CONN_SVTO_MS (2500U) /* 2.5s */ #endif +/** + * @brief Default BLE PHY mode used by autoconn + */ +#ifndef NIMBLE_AUTOCONN_PHY_MODE +#define NIMBLE_AUTOCONN_PHY_MODE NIMBLE_PHY_1M +#endif + #ifndef NIMBLE_AUTOCONN_NODE_ID #define NIMBLE_AUTOCONN_NODE_ID "RIOT-autoconn" #endif #ifndef NIMBLE_AUTOCONN_PARAMS #define NIMBLE_AUTOCONN_PARAMS \ - { .period_scan = NIMBLE_AUTOCONN_PERIOD_SCAN_MS, \ - .period_adv = NIMBLE_AUTOCONN_PERIOD_ADV_MS, \ - .period_jitter = NIMBLE_AUTOCONN_PERIOD_JITTER_MS, \ - .adv_itvl = NIMBLE_AUTOCONN_ADV_ITVL_MS, \ - .scan_itvl = NIMBLE_AUTOCONN_SCAN_ITVL_MS, \ - .scan_win = NIMBLE_AUTOCONN_SCAN_WIN_MS, \ - .conn_timeout = NIMBLE_AUTOCONN_CONN_TIMEOUT_MS, \ - .conn_itvl_min = NIMBLE_AUTOCONN_CONN_ITVL_MIN_MS, \ - .conn_itvl_max = NIMBLE_AUTOCONN_CONN_ITVL_MAX_MS, \ - .conn_latency = NIMBLE_AUTOCONN_CONN_LATENCY, \ - .conn_super_to = NIMBLE_AUTOCONN_CONN_SVTO_MS, \ - .node_id = NIMBLE_AUTOCONN_NODE_ID, } + { .period_scan_ms = NIMBLE_AUTOCONN_PERIOD_SCAN_MS, \ + .period_adv_ms = NIMBLE_AUTOCONN_PERIOD_ADV_MS, \ + .period_jitter_ms = NIMBLE_AUTOCONN_PERIOD_JITTER_MS, \ + .adv_itvl_ms = NIMBLE_AUTOCONN_ADV_ITVL_MS, \ + .scan_itvl_ms = NIMBLE_AUTOCONN_SCAN_ITVL_MS, \ + .scan_win_ms = NIMBLE_AUTOCONN_SCAN_WIN_MS, \ + .conn_timeout_ms = NIMBLE_AUTOCONN_CONN_TIMEOUT_MS, \ + .conn_itvl_min_ms = NIMBLE_AUTOCONN_CONN_ITVL_MIN_MS, \ + .conn_itvl_max_ms = NIMBLE_AUTOCONN_CONN_ITVL_MAX_MS, \ + .conn_latency = NIMBLE_AUTOCONN_CONN_LATENCY, \ + .conn_super_to_ms = NIMBLE_AUTOCONN_CONN_SVTO_MS, \ + .phy_mode = NIMBLE_AUTOCONN_PHY_MODE, \ + .node_id = NIMBLE_AUTOCONN_NODE_ID, } #endif /**@}*/ diff --git a/pkg/nimble/autoconn/nimble_autoconn.c b/pkg/nimble/autoconn/nimble_autoconn.c index ddb9d4e8b2..5598da9d50 100644 --- a/pkg/nimble/autoconn/nimble_autoconn.c +++ b/pkg/nimble/autoconn/nimble_autoconn.c @@ -55,9 +55,8 @@ static volatile uint8_t _enabled = 0; static bluetil_ad_t _ad; static uint8_t _ad_buf[BLE_HS_ADV_MAX_SZ]; -static struct ble_gap_adv_params _adv_params; -static struct ble_gap_conn_params _conn_params; -static uint32_t _conn_timeout; +static nimble_netif_accept_cfg_t _accept_params; +static nimble_netif_connect_cfg_t _conn_params; static struct ble_npl_callout _state_evt; static ble_npl_time_t _timeout_adv_period; @@ -77,7 +76,7 @@ static void _on_state_change(struct ble_npl_event *ev) /* stop scanning */ nimble_scanner_stop(); /* start advertising/accepting */ - int res = nimble_netif_accept(_ad.buf, _ad.pos, &_adv_params); + int res = nimble_netif_accept(_ad.buf, _ad.pos, &_accept_params); assert((res == 0) || (res == -ENOMEM)); (void)res; @@ -137,11 +136,18 @@ static void _on_scan_evt(uint8_t type, const ble_addr_t *addr, { (void)info; +#if IS_USED(MODULE_NIMBLE_AUTOCONN_EXT) + if ((type != (NIMBLE_SCANNER_EXT_ADV | BLE_HCI_ADV_CONN_MASK)) || + (info->status != BLE_GAP_EXT_ADV_DATA_STATUS_COMPLETE)) { + return; + } +#else /* we are only interested in ADV_IND packets, the rest can be dropped right * away */ if (type != BLE_HCI_ADV_RPT_EVTYPE_ADV_IND) { return; } +#endif bluetil_ad_t ad = { .buf = (uint8_t *)ad_buf, @@ -157,7 +163,7 @@ static void _on_scan_evt(uint8_t type, const ble_addr_t *addr, nimble_scanner_stop(); DEBUG("[autoconn] SCAN success, initiating connection\n"); _state = STATE_CONN; - int res = nimble_netif_connect(addr, &_conn_params, _conn_timeout); + int res = nimble_netif_connect(addr, &_conn_params); assert(res >= 0); (void)res; } @@ -271,47 +277,66 @@ int nimble_autoconn_update(const nimble_autoconn_params_t *params, } /* scan and advertising period configuration */ - ble_npl_time_ms_to_ticks(params->period_adv, &_timeout_adv_period); - ble_npl_time_ms_to_ticks(params->period_scan, &_timeout_scan_period); - ble_npl_time_ms_to_ticks(params->period_jitter, &_period_jitter); + ble_npl_time_ms_to_ticks(params->period_adv_ms, &_timeout_adv_period); + ble_npl_time_ms_to_ticks(params->period_scan_ms, &_timeout_scan_period); + ble_npl_time_ms_to_ticks(params->period_jitter_ms, &_period_jitter); /* populate the connection parameters */ - _conn_params.scan_itvl = BLE_GAP_SCAN_ITVL_MS(params->scan_win); - _conn_params.scan_window = _conn_params.scan_itvl; - _conn_params.itvl_min = BLE_GAP_CONN_ITVL_MS(params->conn_itvl_min); - _conn_params.itvl_max = BLE_GAP_CONN_ITVL_MS(params->conn_itvl_max); - _conn_params.latency = 0; - _conn_params.supervision_timeout = BLE_GAP_SUPERVISION_TIMEOUT_MS( - params->conn_super_to); - _conn_params.min_ce_len = 0; - _conn_params.max_ce_len = 0; - _conn_timeout = params->conn_timeout; + memset(&_conn_params, 0, sizeof(_conn_params)); + _conn_params.scan_itvl_ms = params->scan_itvl_ms; + _conn_params.scan_window_ms = params->scan_win_ms; + _conn_params.conn_itvl_min_ms = params->conn_itvl_min_ms; + _conn_params.conn_itvl_max_ms = params->conn_itvl_max_ms; + _conn_params.conn_supervision_timeout_ms = params->conn_super_to_ms; + _conn_params.conn_slave_latency = params->conn_latency; + _conn_params.timeout_ms = params->conn_timeout_ms; +#if IS_USED(MODULE_NIMBLE_AUTOCONN_EXT) + _conn_params.phy_mode = params->phy_mode; +#else + _conn_params.phy_mode = NIMBLE_PHY_1M; +#endif + _conn_params.own_addr_type = nimble_riot_own_addr_type; /* we use the same values to updated existing connections */ struct ble_gap_upd_params conn_update_params; - conn_update_params.itvl_min = _conn_params.itvl_min; - conn_update_params.itvl_max = _conn_params.itvl_max; - conn_update_params.latency = _conn_params.latency; - conn_update_params.supervision_timeout = _conn_params.supervision_timeout; + conn_update_params.itvl_min = BLE_GAP_CONN_ITVL_MS(params->conn_itvl_min_ms); + conn_update_params.itvl_max = BLE_GAP_CONN_ITVL_MS(params->conn_itvl_max_ms); + conn_update_params.latency = params->conn_latency; + conn_update_params.supervision_timeout = + BLE_GAP_SUPERVISION_TIMEOUT_MS(params->conn_super_to_ms); conn_update_params.min_ce_len = 0; conn_update_params.max_ce_len = 0; /* calculate the used scan parameters */ nimble_scanner_cfg_t scan_params; - scan_params.itvl_ms = params->scan_itvl; - scan_params.win_ms = params->scan_win; - scan_params.flags = NIMBLE_SCANNER_PASSIVE - | NIMBLE_SCANNER_FILTER_DUPS - | NIMBLE_SCANNER_PHY_1M; + scan_params.itvl_ms = params->scan_itvl_ms; + scan_params.win_ms = params->scan_win_ms; + scan_params.flags = (NIMBLE_SCANNER_PASSIVE | NIMBLE_SCANNER_FILTER_DUPS); +#if IS_USED(MODULE_NIMBLE_AUTOCONN_EXT) && IS_USED(MODULE_NIMBLE_PHY_CODED) + if (params->phy_mode == NIMBLE_PHY_CODED) { + scan_params.flags |= NIMBLE_SCANNER_PHY_CODED; + } + else { + scan_params.flags |= NIMBLE_SCANNER_PHY_1M; + } +#else + scan_params.flags |= NIMBLE_SCANNER_PHY_1M; +#endif /* set the advertising parameters used */ - _adv_params.conn_mode = BLE_GAP_CONN_MODE_UND; - _adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN; - _adv_params.itvl_min = BLE_GAP_ADV_ITVL_MS(params->adv_itvl); - _adv_params.itvl_max = _adv_params.itvl_min; - _adv_params.channel_map = 0; - _adv_params.filter_policy = 0; - _adv_params.high_duty_cycle = 0; + memset(&_accept_params, 0, sizeof(_accept_params)); +#if IS_USED(MODULE_NIMBLE_AUTOCONN_EXT) + _accept_params.flags = 0; + _accept_params.primary_phy = params->phy_mode; + _accept_params.secondary_phy = params->phy_mode; +#else + _accept_params.flags = NIMBLE_NETIF_FLAG_LEGACY; + _accept_params.primary_phy = NIMBLE_PHY_1M; + _accept_params.secondary_phy = NIMBLE_PHY_1M; +#endif + _accept_params.adv_itvl_ms = params->adv_itvl_ms; + _accept_params.timeout_ms = BLE_HS_FOREVER; + _accept_params.own_addr_type = nimble_riot_own_addr_type; /* initialize the advertising data that will be used */ if (adlen > 0) { diff --git a/pkg/nimble/contrib/include/nimble_riot.h b/pkg/nimble/contrib/include/nimble_riot.h index b61aebd1c3..25d3392a2c 100644 --- a/pkg/nimble/contrib/include/nimble_riot.h +++ b/pkg/nimble/contrib/include/nimble_riot.h @@ -69,6 +69,20 @@ extern "C" { #define NIMBLE_HOST_STACKSIZE (THREAD_STACKSIZE_DEFAULT) #endif +/** + * @brief BLE PHY modes + */ +typedef enum { + NIMBLE_PHY_INVALID, /**< PHY mode invalid */ + NIMBLE_PHY_1M, /**< legacy 1Mbit PHY mode (always supported) */ +#if IS_USED(MODULE_NIMBLE_PHY_2MBIT) + NIMBLE_PHY_2M, /**< 2Mbit PHY mode */ +#endif +#if IS_USED(MODULE_NIMBLE_PHY_CODED) + NIMBLE_PHY_CODED, /**< Coded (long range) PHY mode */ +#endif +} nimble_phy_t; + /** * @brief Export our own address type for later usage */ diff --git a/pkg/nimble/contrib/nimble_riot.c b/pkg/nimble/contrib/nimble_riot.c index 59597addc6..02603f667c 100644 --- a/pkg/nimble/contrib/nimble_riot.c +++ b/pkg/nimble/contrib/nimble_riot.c @@ -176,6 +176,13 @@ void nimble_riot_init(void) nimble_autoconn_enable(); #endif +#ifdef MODULE_STDIO_NIMBLE + extern void stdio_nimble_init(void); + /* stdio_nimble_init() needs to be called after nimble stack initialization + * and before nimble_autoadv_init() */ + stdio_nimble_init(); +#endif + #ifdef MODULE_NIMBLE_AUTOADV extern void nimble_autoadv_init(void); nimble_autoadv_init(); diff --git a/pkg/nimble/netif/include/nimble_netif.h b/pkg/nimble/netif/include/nimble_netif.h index 9b019ddd40..e955d1a7c5 100644 --- a/pkg/nimble/netif/include/nimble_netif.h +++ b/pkg/nimble/netif/include/nimble_netif.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Freie Universität Berlin + * Copyright (C) 2018-2021 Freie Universität Berlin * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -70,6 +70,7 @@ #include #include "net/ble.h" +#include "nimble_riot.h" #include "host/ble_hs.h" @@ -103,6 +104,46 @@ extern "C" { #define NIMBLE_NETIF_MTU (1280U) #endif +/** + * @brief Flags for enabling legacy advertisement and high-duty cycle mode + * when accepting incoming connections + */ +enum { + NIMBLE_NETIF_FLAG_LEGACY = 0x01, /**< use legacy advertising mode */ + NIMBLE_NETIF_FLAG_HD_MODE = 0x02, /**< use high duty cycle mode, only + * valid for direct advertising */ +}; + +/** + * @brief Parameter set used to configure accepting connections (advertising) + */ +typedef struct { + uint8_t flags; /**< flags */ + uint8_t channel_map; /**< specify custom channel map */ + uint8_t own_addr_type; /**< specify our own address type to use */ + int8_t tx_power; /**< specify TX power to be used */ + uint32_t adv_itvl_ms; /**< advertising interval [ms] */ + uint32_t timeout_ms; /**< stop accepting after this time [ms] */ + nimble_phy_t primary_phy; /**< primary PHY mode */ + nimble_phy_t secondary_phy; /**< secondary PHY mode */ +} nimble_netif_accept_cfg_t; + +/** + * @brief Parameter set used to configure connection initiation + */ +typedef struct { + uint16_t scan_itvl_ms; /**< scan interval [ms] */ + uint16_t scan_window_ms; /**< scan window [ms] */ + uint16_t conn_itvl_min_ms; /**< connection interval, lower bound [ms] */ + uint16_t conn_itvl_max_ms; /**< connection interval, upper bound [ms] */ + uint16_t conn_supervision_timeout_ms; /**< supervision timeout [ms] */ + uint16_t conn_slave_latency;/**< slave latency */ + uint32_t timeout_ms; /**< abort connection initiation after this time + * [ms] */ + uint8_t phy_mode; /**< PHY mode used for the connection */ + uint8_t own_addr_type; /**< specify our own address type to use */ +} nimble_netif_connect_cfg_t; + /** * @brief Set to > 0 to enforce different connection intervals for each of the * nodes BLE connections @@ -197,19 +238,18 @@ void nimble_netif_eventcb(nimble_netif_eventcb_t cb); * * @param[in] addr address of the advertising BLE slave, in the NimBLE * addr format (little endian) - * @param[in] conn_params connection (timing) parameters, set to NULL to use - * NimBLEs default parameters - * @param[in] timeout connect timeout [in ms] + * @param[in] cfg connection parameters * * @return the used connection handle on success - * @return -EBUSY if already connected to the given address or if - * a connection setup procedure is in progress + * @return -EBUSY if already connected to the given address or if a connection + * setup procedure is in progress * @return -ENOMEM if no connection context memory is available * @return -ECANCELED if unable to find valid connection interval + * @return -EINVAL if unable to apply given PHY mode + * @return -EIO on all other NimBLE errors */ int nimble_netif_connect(const ble_addr_t *addr, - struct ble_gap_conn_params *conn_params, - uint32_t timeout); + const nimble_netif_connect_cfg_t *cfg); /** * @brief Close the connection with the given handle @@ -219,6 +259,7 @@ int nimble_netif_connect(const ble_addr_t *addr, * @return 0 on success * @return -EINVAL if the handle is invalid * @return -ENOTCONN if context for given handle is not connected + * @return -EIO on all other NimBLE errors */ int nimble_netif_close(int handle); @@ -227,36 +268,39 @@ int nimble_netif_close(int handle); * * @param[in] ad advertising data (in BLE AD format) * @param[in] ad_len length of @p ad in bytes - * @param[in] adv_params advertising (timing) parameters to use + * @param[in] cfg advertising parameters to use * * @return 0 on success * @return -EALREADY if already advertising * @return -ENOMEM on insufficient connection memory + * @return -EINVAL on invalid configuration parameters + * @return -ECANCELED on other errors */ int nimble_netif_accept(const uint8_t *ad, size_t ad_len, - const struct ble_gap_adv_params *adv_params); + const nimble_netif_accept_cfg_t *cfg); /** * @brief Wait for an incoming connection from a specific peer, sending - * directed advertisements (IND_DIR) + * directed advertisements * * @param[in] addr BLE address of the target peer - * @param[in] timeout_ms stop advertising after this time (in ms), set to - * BLE_HS_FOREVER to disable timeout - * @param[in] adv_params advertising (timing) parameters to use + * @param[in] cfg advertising parameters to use * * @return 0 on success * @return -EALREADY if already advertising * @return -ENOMEM on insufficient connection memory + * @return -EINVAL on invalid configuration parameters + * @return -ECANCELED on other errors */ -int nimble_netif_accept_direct(const ble_addr_t *addr, uint32_t timeout_ms, - const struct ble_gap_adv_params *adv_params); +int nimble_netif_accept_direct(const ble_addr_t *addr, + const nimble_netif_accept_cfg_t *cfg); /** * @brief Stop accepting incoming connections (stop advertising) * * * @return 0 on success * @return -EALREADY if not currently advertising + * @return -EIO on other NimBLE errors */ int nimble_netif_accept_stop(void); diff --git a/pkg/nimble/netif/nimble_netif.c b/pkg/nimble/netif/nimble_netif.c index ab307bccb1..7477520c64 100644 --- a/pkg/nimble/netif/nimble_netif.c +++ b/pkg/nimble/netif/nimble_netif.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Freie Universität Berlin + * Copyright (C) 2018-2021 Freie Universität Berlin * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -55,6 +55,8 @@ #define NIMBLE_NETIF_PRIO GNRC_NETIF_PRIO #endif +#define EXT_ADV_INST 0 + /* thread flag used for signaling transmit readiness */ #define FLAG_TX_UNSTALLED (1u << 13) #define FLAG_TX_NOTCONN (1u << 12) @@ -543,10 +545,14 @@ static int _on_gap_slave_evt(struct ble_gap_event *event, void *arg) /* nothing to do here */ break; case BLE_GAP_EVENT_ADV_COMPLETE: { - uint8_t addr[BLE_ADDR_LEN]; - nimble_netif_conn_free(handle, addr); - _notify(handle, NIMBLE_NETIF_ACCEPT_STOP, addr); + if (conn->state == NIMBLE_NETIF_ADV) { + uint8_t addr[BLE_ADDR_LEN]; + nimble_netif_conn_free(handle, addr); + _notify(handle, NIMBLE_NETIF_ACCEPT_STOP, addr); + } } + case BLE_GAP_EVENT_PHY_UPDATE_COMPLETE: + break; default: break; } @@ -577,14 +583,10 @@ void nimble_netif_eventcb(nimble_netif_eventcb_t cb) } int nimble_netif_connect(const ble_addr_t *addr, - struct ble_gap_conn_params *conn_params, - uint32_t timeout) + const nimble_netif_connect_cfg_t *params) { assert(addr); - assert(_eventcb); - - uint16_t itvl_min = 0; - uint16_t itvl_max = 0; + assert(params); /* the netif_conn module expects addresses in network byte order */ uint8_t addrn[BLE_ADDR_LEN]; @@ -602,33 +604,63 @@ int nimble_netif_connect(const ble_addr_t *addr, return -ENOMEM; } - if ((conn_params != NULL) - && (conn_params->itvl_min != conn_params->itvl_max)) { - /* we need to save the min/max intervals in order to restore them - * later on */ - itvl_min = conn_params->itvl_min; - itvl_max = conn_params->itvl_max; - - uint16_t itvl = nimble_netif_conn_gen_itvl(itvl_min, itvl_max); - if (itvl == 0) { - return -ECANCELED; - } - conn_params->itvl_min = itvl; - conn_params->itvl_max = itvl; + /* generate connection interval */ + uint16_t itvl = params->conn_itvl_min_ms; + if (params->conn_itvl_min_ms < params->conn_itvl_max_ms) { + itvl = nimble_netif_conn_gen_itvl(params->conn_itvl_min_ms, + params->conn_itvl_max_ms); + } + if (itvl == 0) { + nimble_netif_conn_free(handle, NULL); + return -ECANCELED; } - int res = ble_gap_connect(nimble_riot_own_addr_type, addr, timeout, - conn_params, _on_gap_master_evt, (void *)handle); - assert(res == 0); - (void)res; + struct ble_gap_conn_params p = { + .scan_itvl = BLE_GAP_SCAN_ITVL_MS(params->scan_itvl_ms), + .scan_window = BLE_GAP_SCAN_WIN_MS(params->scan_window_ms), + .itvl_min = BLE_GAP_CONN_ITVL_MS(itvl), + .itvl_max = BLE_GAP_CONN_ITVL_MS(itvl), + .latency = params->conn_slave_latency, + .supervision_timeout = BLE_GAP_SUPERVISION_TIMEOUT_MS( + params->conn_supervision_timeout_ms), + .min_ce_len = 0, + .max_ce_len = 0, + }; - if (itvl_min != itvl_max) { - conn_params->itvl_min = itvl_min; - conn_params->itvl_max = itvl_max; +#if MYNEWT_VAL_BLE_EXT_ADV + uint8_t phy_mask; + if (params->phy_mode == NIMBLE_PHY_1M) { + phy_mask = BLE_GAP_LE_PHY_1M_MASK; + } +#if IS_USED(MODULE_NIMBLE_PHY_2MBIT) + else if (params->phy_mode == NIMBLE_PHY_2M) { + phy_mask = (BLE_GAP_LE_PHY_1M_MASK | BLE_GAP_LE_PHY_2M_MASK); + } +#endif +#if IS_USED(MODULE_NIMBLE_PHY_CODED) + else if (params->phy_mode == NIMBLE_PHY_CODED) { + phy_mask = BLE_GAP_LE_PHY_CODED_MASK; + } +#endif + else { + return -EINVAL; + } + + int res = ble_gap_ext_connect(params->own_addr_type, addr, + params->timeout_ms, phy_mask, &p, &p, &p, + _on_gap_master_evt, (void *)handle); +#else + uint32_t timeout = (params->timeout_ms == 0) ? BLE_HS_FOREVER + : params->timeout_ms; + int res = ble_gap_connect(params->own_addr_type, addr, + timeout, &p, + _on_gap_master_evt, (void *)handle); +#endif + if (res != 0) { + return -EIO; } _notify(handle, NIMBLE_NETIF_INIT_MASTER, addrn); - return handle; } @@ -642,63 +674,168 @@ int nimble_netif_close(int handle) return -ENOTCONN; } - int res = ble_gap_terminate(ble_l2cap_get_conn_handle(conn->coc), - BLE_ERR_REM_USER_CONN_TERM); - assert(res == 0); - (void)res; + int res = ble_gap_terminate(conn->gaphandle, BLE_ERR_REM_USER_CONN_TERM); + if (res != 0) { + return -EIO; + } return 0; } -static int _accept(const uint8_t *ad, size_t ad_len, const ble_addr_t *addr, - uint32_t timeout, - const struct ble_gap_adv_params *adv_params) +#if MYNEWT_VAL_BLE_EXT_ADV +static int _get_phy_hci(uint8_t mode) { - assert(adv_params); + switch (mode) { + case NIMBLE_PHY_1M: + return BLE_HCI_LE_PHY_1M; +#if IS_USED(MODULE_NIMBLE_PHY_2MBIT) + case NIMBLE_PHY_2M: + return BLE_HCI_LE_PHY_2M; +#endif +#if IS_USED(MODULE_NIMBLE_PHY_CODED) + case NIMBLE_PHY_CODED: + return BLE_HCI_LE_PHY_CODED; +#endif + default: + return -1; + } +} +#endif +static int _accept(const uint8_t *ad, size_t ad_len, const ble_addr_t *addr, + const nimble_netif_accept_cfg_t *params) +{ int handle; int res; (void)res; + assert(params); + /* allocate a connection context for incoming connections */ handle = nimble_netif_conn_start_adv(); if (handle < 0) { return handle; } - /* set advertisement data */ - if (ad != NULL) { - res = ble_gap_adv_set_data(ad, (int)ad_len); - assert(res == 0); - } /* remember address if applicable */ if (addr) { nimble_netif_conn_t *conn = nimble_netif_conn_get(handle); bluetil_addr_swapped_cp(addr->val, conn->addr); } - /* remember context and start advertising */ - res = ble_gap_adv_start(nimble_riot_own_addr_type, addr, timeout, - adv_params, _on_gap_slave_evt, (void *)handle); - assert(res == 0); +#if MYNEWT_VAL_BLE_EXT_ADV + struct ble_gap_ext_adv_params p; + memset(&p, 0, sizeof(p)); + + /* figure out PHY modes */ + int phy_pri = _get_phy_hci(params->primary_phy); + int phy_sec = _get_phy_hci(params->secondary_phy); + if ((phy_pri < 0) || (phy_sec < 0)) { + nimble_netif_conn_free(handle, NULL); + return -EINVAL; + } + /* the 2M PHY is not allowed as primary phy, we need to used the 1M PHY + * instead. This is for convenience so uses may define 2M as primary PHY */ + if (phy_pri == BLE_HCI_LE_PHY_2M) { + phy_pri = BLE_HCI_LE_PHY_1M; + } + + if (addr != NULL) { + p.directed = 1; + memcpy(&p.peer, addr, sizeof(p.peer)); + if (params->flags & NIMBLE_NETIF_FLAG_HD_MODE) { + p.high_duty_directed = 1; + } + } + else { + p.connectable = 1; + } + if (params->flags & NIMBLE_NETIF_FLAG_LEGACY) { + p.legacy_pdu = 1; + /* legacy connectable PDUs are always scannable */ + p.scannable = 1; + } + p.itvl_min = BLE_GAP_ADV_ITVL_MS(params->adv_itvl_ms); + p.itvl_max = BLE_GAP_ADV_ITVL_MS(params->adv_itvl_ms); + p.channel_map = params->channel_map; + p.own_addr_type = params->own_addr_type; + p.primary_phy = (uint8_t)phy_pri; + p.secondary_phy = (uint8_t)phy_sec; + p.tx_power = params->tx_power; + + res = ble_gap_ext_adv_configure(EXT_ADV_INST, &p, NULL, + _on_gap_slave_evt, (void *)handle); + if (res != 0) { + nimble_netif_conn_free(handle, NULL); + return -EINVAL; + } + + if (ad != NULL) { + struct os_mbuf *data = os_msys_get_pkthdr(ad_len, 0); + if (data == NULL) { + nimble_netif_conn_free(handle, NULL); + return -ENOMEM; + } + res = os_mbuf_append(data, ad, ad_len); + if (res != 0) { + os_mbuf_free_chain(data); + nimble_netif_conn_free(handle, NULL); + return -ENOMEM; + } + res = ble_gap_ext_adv_set_data(EXT_ADV_INST, data); + assert(res == 0); + } + res = ble_gap_ext_adv_start(EXT_ADV_INST, params->timeout_ms / 10, 0); +#else + uint8_t mode = (addr != NULL) ? BLE_GAP_CONN_MODE_DIR + : BLE_GAP_CONN_MODE_UND; + struct ble_gap_adv_params p = { + .conn_mode = mode, + .disc_mode = BLE_GAP_DISC_MODE_GEN, + .itvl_min = BLE_GAP_ADV_ITVL_MS(params->adv_itvl_ms), + .itvl_max = BLE_GAP_ADV_ITVL_MS(params->adv_itvl_ms), + .channel_map = params->channel_map, + .filter_policy = 0, + .high_duty_cycle = (params->flags & NIMBLE_NETIF_FLAG_HD_MODE) ? 1 : 0, + }; + + /* set advertisement data, if applicable */ + if (ad != NULL) { + res = ble_gap_adv_set_data(ad, (int)ad_len); + if (res != 0) { + nimble_netif_conn_free(handle, NULL); + return -EINVAL; + } + } + + /* start advertising */ + uint32_t timeout = (params->timeout_ms == 0) ? BLE_HS_FOREVER + : params->timeout_ms; + res = ble_gap_adv_start(params->own_addr_type, addr, timeout, + &p, _on_gap_slave_evt, (void *)handle); +#endif + if (res != 0) { + nimble_netif_conn_free(handle, NULL); + return -ECANCELED; + } _notify(handle, NIMBLE_NETIF_ACCEPTING, _netif.l2addr); - return 0; } int nimble_netif_accept(const uint8_t *ad, size_t ad_len, - const struct ble_gap_adv_params *adv_params) + const nimble_netif_accept_cfg_t *params) { assert(ad != NULL); assert(ad_len > 0); - return _accept(ad, ad_len, NULL, BLE_HS_FOREVER, adv_params); + return _accept(ad, ad_len, NULL, params); } -int nimble_netif_accept_direct(const ble_addr_t *addr, uint32_t timeout, - const struct ble_gap_adv_params *adv_params) +int nimble_netif_accept_direct(const ble_addr_t *addr, + const nimble_netif_accept_cfg_t *params) { - return _accept(NULL, 0, addr, timeout, adv_params); + assert(addr); + return _accept(NULL, 0, addr, params); } int nimble_netif_accept_stop(void) @@ -708,9 +845,15 @@ int nimble_netif_accept_stop(void) return -EALREADY; } - int res = ble_gap_adv_stop(); - assert(res == 0); - (void)res; + int res; +#if MYNEWT_VAL_BLE_EXT_ADV + res = ble_gap_ext_adv_stop(EXT_ADV_INST); +#else + res = ble_gap_adv_stop(); +#endif + if (res != 0) { + return -EIO; + } nimble_netif_conn_free(handle, NULL); _notify(handle, NIMBLE_NETIF_ACCEPT_STOP, _netif.l2addr); diff --git a/pkg/nimble/rpble/include/nimble_rpble.h b/pkg/nimble/rpble/include/nimble_rpble.h index 08fd71b9db..d09c292ad5 100644 --- a/pkg/nimble/rpble/include/nimble_rpble.h +++ b/pkg/nimble/rpble/include/nimble_rpble.h @@ -113,6 +113,7 @@ typedef struct { uint16_t conn_latency; /**< used slave latency for parent connection */ uint32_t conn_super_to_ms; /**< used supervision timeout for parent * connection, in ms */ + nimble_phy_t phy_mode; /**< BLE PHY mode to use */ uint32_t eval_itvl_min_ms; /**< amount of time a node searches for * potential parents, lower bound in ms */ uint32_t eval_itvl_max_ms; /**< amount of time a node searches for diff --git a/pkg/nimble/rpble/include/nimble_rpble_params.h b/pkg/nimble/rpble/include/nimble_rpble_params.h index 4f665f3595..6e03512939 100644 --- a/pkg/nimble/rpble/include/nimble_rpble_params.h +++ b/pkg/nimble/rpble/include/nimble_rpble_params.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Freie Universität Berlin + * Copyright (C) 2019-2021 Freie Universität Berlin * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -69,6 +69,13 @@ extern "C" { #define NIMBLE_RPBLE_EVAL_ITVL_MAX_MS 13000U #endif +/** + * @brief Default BLE PHY mode used by rpble + */ +#ifndef NIMBLE_RPBLE_PHY_MODE +#define NIMBLE_RPBLE_PHY_MODE NIMBLE_PHY_1M +#endif + #ifndef NIMBLE_RPBLE_PARAMS #define NIMBLE_RPBLE_PARAMS \ { .scan_itvl_ms = NIMBLE_RPBLE_SCAN_ITVL_MS, \ @@ -81,6 +88,7 @@ extern "C" { .conn_itvl_max_ms = NIMBLE_RPBLE_CONN_ITVL_MAX_MS, \ .conn_latency = NIMBLE_RPBLE_CONN_LATENCY, \ .conn_super_to_ms = NIMBLE_RPBLE_CONN_SUPER_TO_MS, \ + .phy_mode = NIMBLE_RPBLE_PHY_MODE, \ .eval_itvl_min_ms = NIMBLE_RPBLE_EVAL_ITVL_MIN_MS, \ .eval_itvl_max_ms = NIMBLE_RPBLE_EVAL_ITVL_MAX_MS } #endif diff --git a/pkg/nimble/rpble/nimble_rpble.c b/pkg/nimble/rpble/nimble_rpble.c index 63006689f0..da56a56e6e 100644 --- a/pkg/nimble/rpble/nimble_rpble.c +++ b/pkg/nimble/rpble/nimble_rpble.c @@ -50,9 +50,8 @@ #define POS_FREE_SLOTS 22 /* keep the timing parameters for connections and advertisements */ -static struct ble_gap_adv_params _adv_params = { 0 }; -static struct ble_gap_conn_params _conn_params = { 0 }; -static uint32_t _conn_scan_to; /* in ms */ +static nimble_netif_accept_cfg_t _accept_params; +static nimble_netif_connect_cfg_t _conn_params; /* local RPL context */ static nimble_rpble_ctx_t _local_rpl_ctx; @@ -107,7 +106,7 @@ static void _children_accept(void) assert(res == BLUETIL_AD_OK); /* start advertising this node */ - res = nimble_netif_accept(ad.buf, ad.pos, &_adv_params); + res = nimble_netif_accept(ad.buf, ad.pos, &_accept_params); assert(res == 0); } @@ -118,10 +117,17 @@ static void _on_scan_evt(uint8_t type, const ble_addr_t *addr, int res; (void)info; +#if IS_USED(MODULE_NIMBLE_RPBLE_EXT) + if ((type != (NIMBLE_SCANNER_EXT_ADV | BLE_HCI_ADV_CONN_MASK)) || + (info->status != BLE_GAP_EXT_ADV_DATA_STATUS_COMPLETE)) { + return; + } +#else /* filter out all non-connectible advertisements */ if (type != BLE_HCI_ADV_RPT_EVTYPE_ADV_IND) { return; } +#endif /* check if scanned node does actually speak rpble */ bluetil_ad_data_t sd_field; @@ -199,7 +205,7 @@ static void _parent_connect(struct ble_npl_event *ev) } /* try to connect to parent */ - int res = nimble_netif_connect(&_psel.addr, &_conn_params, _conn_scan_to); + int res = nimble_netif_connect(&_psel.addr, &_conn_params); if (res < 0) { _parent_find(); return; @@ -283,19 +289,36 @@ int nimble_rpble_param_update(const nimble_rpble_cfg_t *cfg) cfg->eval_itvl_max_ms); ble_npl_time_ms_to_ticks(itvl, &_eval_itvl); - _adv_params.conn_mode = BLE_GAP_CONN_MODE_UND; - _adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN; - _adv_params.itvl_min = BLE_GAP_ADV_ITVL_MS(cfg->adv_itvl_ms); - _adv_params.itvl_max = _adv_params.itvl_min; + /* accept parameter extraction */ + memset(&_accept_params, 0, sizeof(_accept_params)); +#if IS_USED(MODULE_NIMBLE_RPBLE_EXT) + _accept_params.flags = 0; + _accept_params.primary_phy = cfg->phy_mode; + _accept_params.secondary_phy = cfg->phy_mode; +#else + _accept_params.flags = NIMBLE_NETIF_FLAG_LEGACY; + _accept_params.primary_phy = NIMBLE_PHY_1M; + _accept_params.secondary_phy = NIMBLE_PHY_1M; +#endif + _accept_params.adv_itvl_ms = cfg->adv_itvl_ms; + _accept_params.timeout_ms = BLE_HS_FOREVER; + _accept_params.own_addr_type = nimble_riot_own_addr_type; - _conn_params.scan_itvl = BLE_GAP_SCAN_ITVL_MS(cfg->conn_scan_itvl_ms); - _conn_params.scan_window = BLE_GAP_SCAN_WIN_MS(cfg->conn_scan_win_ms); - _conn_params.latency = cfg->conn_latency; - _conn_params.supervision_timeout = - BLE_GAP_SUPERVISION_TIMEOUT_MS(cfg->conn_super_to_ms); - _conn_params.itvl_min = BLE_GAP_CONN_ITVL_MS(cfg->conn_itvl_min_ms); - _conn_params.itvl_max = BLE_GAP_CONN_ITVL_MS(cfg->conn_itvl_max_ms); - _conn_scan_to = cfg->conn_scan_to_ms; + /* connection parameter extraction */ + memset(&_conn_params, 0, sizeof(_conn_params)); + _conn_params.scan_itvl_ms = cfg->conn_scan_itvl_ms; + _conn_params.scan_window_ms = cfg->conn_scan_win_ms; + _conn_params.conn_itvl_min_ms = cfg->conn_itvl_min_ms; + _conn_params.conn_itvl_max_ms = cfg->conn_itvl_max_ms; + _conn_params.conn_supervision_timeout_ms = cfg->conn_super_to_ms; + _conn_params.conn_slave_latency = cfg->conn_latency; + _conn_params.timeout_ms = cfg->conn_scan_to_ms; +#if IS_USED(MODULE_NIMBLE_RPBLE_EXT) + _conn_params.phy_mode = cfg->phy_mode; +#else + _conn_params.phy_mode = NIMBLE_PHY_1M; +#endif + _conn_params.own_addr_type = nimble_riot_own_addr_type; /* register event callback */ nimble_netif_eventcb(_on_netif_evt); @@ -304,9 +327,18 @@ int nimble_rpble_param_update(const nimble_rpble_cfg_t *cfg) nimble_scanner_cfg_t scan_params = { 0 }; scan_params.itvl_ms = cfg->scan_itvl_ms; scan_params.win_ms = cfg->scan_win_ms; - scan_params.flags = NIMBLE_SCANNER_PASSIVE - | NIMBLE_SCANNER_FILTER_DUPS - | NIMBLE_SCANNER_PHY_1M; + scan_params.flags = (NIMBLE_SCANNER_PASSIVE | NIMBLE_SCANNER_FILTER_DUPS); + +#if IS_USED(MODULE_NIMBLE_RPBLE_EXT) && IS_USED(MODULE_NIMBLE_PHY_CODED) + if (cfg->phy_mode == NIMBLE_PHY_CODED) { + scan_params.flags |= NIMBLE_SCANNER_PHY_CODED; + } + else { + scan_params.flags |= NIMBLE_SCANNER_PHY_1M; + } +#else + scan_params.flags |= NIMBLE_SCANNER_PHY_1M; +#endif nimble_scanner_init(&scan_params, _on_scan_evt); /* start to look for parents */ diff --git a/pkg/nimble/scanner/include/nimble_scanner.h b/pkg/nimble/scanner/include/nimble_scanner.h index 02144a4a23..a58d2e6754 100644 --- a/pkg/nimble/scanner/include/nimble_scanner.h +++ b/pkg/nimble/scanner/include/nimble_scanner.h @@ -44,7 +44,9 @@ enum { NIMBLE_SCANNER_LIMITED = 0x02, /**< do limited discovery */ NIMBLE_SCANNER_FILTER_DUPS = 0x04, /**< filter duplicates */ NIMBLE_SCANNER_PHY_1M = 0x10, /**< scan on 1Mbit PHY */ +#if IS_USED(MODULE_NIMBLE_PHY_CODED) NIMBLE_SCANNER_PHY_CODED = 0x20, /**< scan on CODED PHY */ +#endif }; /** diff --git a/pkg/nimble/scanner/nimble_scanner.c b/pkg/nimble/scanner/nimble_scanner.c index ba82cc6807..69d832b2df 100644 --- a/pkg/nimble/scanner/nimble_scanner.c +++ b/pkg/nimble/scanner/nimble_scanner.c @@ -100,9 +100,12 @@ int nimble_scanner_start(void) uint8_t limited = (_scan_flags & NIMBLE_SCANNER_LIMITED) ? 1 : 0; const struct ble_gap_ext_disc_params *uncoded = (_scan_flags & NIMBLE_SCANNER_PHY_1M) ? &_scan_params : NULL; +#if IS_USED(MODULE_NIMBLE_PHY_CODED) const struct ble_gap_ext_disc_params *coded = (_scan_flags & NIMBLE_SCANNER_PHY_CODED) ? &_scan_params : NULL; - +#else + const struct ble_gap_ext_disc_params *coded = NULL; +#endif int32_t dur = (_scan_duration == BLE_HS_FOREVER) ? 0 : _scan_duration / 10; diff --git a/pkg/nimble/statconn/include/nimble_statconn.h b/pkg/nimble/statconn/include/nimble_statconn.h index da39800701..63ef2c3281 100644 --- a/pkg/nimble/statconn/include/nimble_statconn.h +++ b/pkg/nimble/statconn/include/nimble_statconn.h @@ -113,6 +113,21 @@ extern "C" { #define NIMBLE_STATCONN_CONN_SUPERTO_MS (2500U) #endif +/** + * @brief BLE PHY mode used by statconn. This value is only used if statconn + * is used in its extended mode (module `nimble_statconn_ext`) + */ +#ifndef NIMBLE_STATCONN_PHY_MODE +#define NIMBLE_STATCONN_PHY_MODE NIMBLE_PHY_1M +#endif + +/** + * @brief Statconn connection parameters + */ +typedef struct { + nimble_phy_t phy_mode; /**< BLE PHY mode used for the connection */ +} nimble_statconn_cfg_t; + /** * @brief Initialize the statconn module * @@ -138,23 +153,31 @@ void nimble_statconn_eventcb(nimble_netif_eventcb_t cb); * connection by that master. * * @param[in] addr BLE address of the peer + * @param[in] cfg additional connection parameters, set to NULL to apply + * default values * * @return 0 if peer was successfully added * @return -EALREADY if the peer address is already in use * @return -ENOMEM if no empty connection slot is available + * @return -EINVAL if invalid configuration parameters are given */ -int nimble_statconn_add_master(const uint8_t *addr); +int nimble_statconn_add_master(const uint8_t *addr, + const nimble_statconn_cfg_t *cfg); /** * @brief Connect to a peer (slave) with a given address as master * * @param[in] addr BLE address of the peer + * @param[in] cfg additional connection parameters, set to NULL to apply + * default values * * @return 0 if peer was successfully added * @return -EALREADY if the peer address is already in use * @return -ENOMEM if no empty connection slot is available + * @return -EINVAL if invalid configuration parameters are given */ -int nimble_statconn_add_slave(const uint8_t *addr); +int nimble_statconn_add_slave(const uint8_t *addr, + const nimble_statconn_cfg_t *cfg); /** * @brief Remove the connection to the given peer diff --git a/pkg/nimble/statconn/nimble_statconn.c b/pkg/nimble/statconn/nimble_statconn.c index bd99309572..a2134edb3e 100644 --- a/pkg/nimble/statconn/nimble_statconn.c +++ b/pkg/nimble/statconn/nimble_statconn.c @@ -44,6 +44,9 @@ typedef struct { uint8_t addr[BLE_ADDR_LEN]; /**< peer addr, network byte order */ uint8_t state; /**< internal state */ +#if IS_USED(MODULE_NIMBLE_STATCONN_EXT) + nimble_phy_t phy_mode; /**< PHY mode used by this slot */ +#endif } slot_t; static const uint8_t _ad[2] = { BLE_GAP_AD_FLAGS, BLUETIL_AD_FLAGS_DEFAULT }; @@ -51,9 +54,8 @@ static const uint8_t _ad[2] = { BLE_GAP_AD_FLAGS, BLUETIL_AD_FLAGS_DEFAULT }; static mutex_t _lock = MUTEX_INIT; static slot_t _slots[NIMBLE_NETIF_MAX_CONN]; -static struct ble_gap_adv_params _adv_params; -static struct ble_gap_conn_params _conn_params; -static uint32_t _conn_timeout; +static nimble_netif_accept_cfg_t _accept_params; +static nimble_netif_connect_cfg_t _conn_params; static nimble_netif_eventcb_t _eventcb = NULL; @@ -87,10 +89,17 @@ static void _activate(uint8_t role) peer.type = BLE_ADDR_RANDOM; bluetil_addr_swapped_cp(slot->addr, peer.val); /* try to (re)open the connection */ - nimble_netif_connect(&peer, &_conn_params, _conn_timeout); +#if IS_USED(MODULE_NIMBLE_STATCONN_EXT) + _conn_params.phy_mode = slot->phy_mode; +#endif + nimble_netif_connect(&peer, &_conn_params); } else if (slot && (role == ROLE_S)) { - nimble_netif_accept(_ad, sizeof(_ad), &_adv_params); +#if IS_USED(MODULE_NIMBLE_STATCONN_EXT) + _accept_params.primary_phy = slot->phy_mode; + _accept_params.secondary_phy = slot->phy_mode; +#endif + nimble_netif_accept(_ad, sizeof(_ad), &_accept_params); } mutex_unlock(&_lock); } @@ -153,7 +162,8 @@ static void _on_netif_evt(int handle, nimble_netif_event_t event, } } -static int _be(uint8_t role, const uint8_t *addr) +static int _be(uint8_t role, const uint8_t *addr, + const nimble_statconn_cfg_t *cfg) { mutex_lock(&_lock); slot_t *s = _get_addr(addr); @@ -170,6 +180,18 @@ static int _be(uint8_t role, const uint8_t *addr) s->state = (role | PENDING); memcpy(s->addr, addr, BLE_ADDR_LEN); mutex_unlock(&_lock); + +#if IS_USED(MODULE_NIMBLE_STATCONN_EXT) + if (cfg != NULL) { + s->phy_mode = cfg->phy_mode; + } + else { + s->phy_mode = NIMBLE_STATCONN_PHY_MODE; + } +#else + (void)cfg; +#endif + _activate(role); return 0; } @@ -179,27 +201,31 @@ void nimble_statconn_init(void) memset(_slots, 0, sizeof(_slots)); /* set the advertising parameters used */ - _adv_params.conn_mode = BLE_GAP_CONN_MODE_UND; - _adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN; - _adv_params.itvl_min = BLE_GAP_ADV_ITVL_MS(NIMBLE_STATCONN_ADV_ITVL_MS); - _adv_params.itvl_max = _adv_params.itvl_min; - _adv_params.channel_map = 0; - _adv_params.filter_policy = 0; - _adv_params.high_duty_cycle = 0; + memset(&_accept_params, 0, sizeof(_accept_params)); +#if IS_USED(MODULE_NIMBLE_STATCONN_EXT) + _accept_params.flags = 0; +#else + _accept_params.flags = NIMBLE_NETIF_FLAG_LEGACY; + _accept_params.primary_phy = NIMBLE_PHY_1M; + _accept_params.secondary_phy = NIMBLE_PHY_1M; +#endif + _accept_params.adv_itvl_ms = NIMBLE_STATCONN_ADV_ITVL_MS; + _accept_params.timeout_ms = BLE_HS_FOREVER; + _accept_params.own_addr_type = nimble_riot_own_addr_type; /* set connection parameters */ - _conn_params.scan_itvl = BLE_GAP_SCAN_ITVL_MS(NIMBLE_STATCONN_CONN_WIN_MS); - _conn_params.scan_window = _conn_params.scan_itvl; - _conn_params.latency = NIMBLE_STATCONN_CONN_LATENCY; - _conn_params.supervision_timeout = BLE_GAP_SUPERVISION_TIMEOUT_MS( - NIMBLE_STATCONN_CONN_SUPERTO_MS); - _conn_params.itvl_min = BLE_GAP_CONN_ITVL_MS( - NIMBLE_STATCONN_CONN_ITVL_MIN_MS); - _conn_params.itvl_max = BLE_GAP_CONN_ITVL_MS( - NIMBLE_STATCONN_CONN_ITVL_MAX_MS); - _conn_params.min_ce_len = 0; - _conn_params.max_ce_len = 0; - _conn_timeout = NIMBLE_STATCONN_CONN_TIMEOUT_MS; + memset(&_conn_params, 0, sizeof(_conn_params)); +#if !IS_USED(MODULE_NIMBLE_AUTOCONN_EXT) + _conn_params.phy_mode = NIMBLE_PHY_1M; +#endif + _conn_params.scan_itvl_ms = NIMBLE_STATCONN_CONN_WIN_MS; + _conn_params.scan_window_ms = NIMBLE_STATCONN_CONN_WIN_MS; + _conn_params.conn_itvl_min_ms = NIMBLE_STATCONN_CONN_ITVL_MIN_MS; + _conn_params.conn_itvl_max_ms = NIMBLE_STATCONN_CONN_ITVL_MAX_MS; + _conn_params.conn_supervision_timeout_ms = NIMBLE_STATCONN_CONN_SUPERTO_MS; + _conn_params.conn_slave_latency = NIMBLE_STATCONN_CONN_LATENCY; + _conn_params.timeout_ms = NIMBLE_STATCONN_CONN_TIMEOUT_MS; + _conn_params.own_addr_type = nimble_riot_own_addr_type; /* register our event callback */ nimble_netif_eventcb(_on_netif_evt); @@ -210,14 +236,16 @@ void nimble_statconn_eventcb(nimble_netif_eventcb_t cb) _eventcb = cb; } -int nimble_statconn_add_master(const uint8_t *addr) +int nimble_statconn_add_master(const uint8_t *addr, + const nimble_statconn_cfg_t *cfg) { - return _be(ROLE_S, addr); + return _be(ROLE_S, addr, cfg); } -int nimble_statconn_add_slave(const uint8_t *addr) +int nimble_statconn_add_slave(const uint8_t *addr, + const nimble_statconn_cfg_t *cfg) { - return _be(ROLE_M, addr); + return _be(ROLE_M, addr, cfg); } int nimble_statconn_rm(const uint8_t *addr) diff --git a/pkg/tinycbor/Makefile b/pkg/tinycbor/Makefile index 8352a6619a..e1204a85e9 100644 --- a/pkg/tinycbor/Makefile +++ b/pkg/tinycbor/Makefile @@ -1,7 +1,7 @@ PKG_NAME=tinycbor PKG_URL=https://github.com/intel/tinycbor -# Tinycbor v0.5.3 -PKG_VERSION=755f9ef932f9830a63a712fd2ac971d838b131f1 +# Tinycbor v0.6.0 +PKG_VERSION=d393c16f3eb30d0c47e6f9d92db62272f0ec4dc7 PKG_LICENSE=MIT include $(RIOTBASE)/pkg/pkg.mk diff --git a/release-notes.txt b/release-notes.txt index 868eef6cf1..7b024047bf 100644 --- a/release-notes.txt +++ b/release-notes.txt @@ -1,3 +1,801 @@ +RIOT-2022.01 - Release Notes +============================ +RIOT is a multi-threading operating system which enables soft real-time +capabilities and comes with support for a range of devices that are typically +found in the Internet of Things: 8-bit and 16-bit microcontrollers as well as +light-weight 32-bit processors. + +RIOT is based on the following design principles: energy-efficiency, soft +real-time capabilities, small memory footprint, modularity, and uniform API +access, independent of the underlying hardware (with partial POSIX compliance). + +RIOT is developed by an international open-source community which is +independent of specific vendors (e.g. similarly to the Linux community) and is +licensed with a non-viral copyleft license (LGPLv2.1), which allows indirect +business models around the free open-source software platform provided by RIOT. + + +About this release +================== + +The 2022.01 release brings support for new packages, new boards and drivers, +as well as several package upgrades and bug fixes. Among others, this release +improves the RIOT codebase with: + +Rust support +------------ + +RIOT now offers convenient integration of Rust application programming, with +wrappers interfacing to RIOT modules such as timers, network stack. + + +Improved timers +--------------- + +Many modules have migrated from using xtimer to our more power-efficient +alternative ztimer. Also, ztimer64 was introduced, which enables +a drop-in replacement for all of xtimer features. + + +Kconfig support +--------------- + +Kconfig modeling coverage is significantly extended. Nearly all supported +boards are now modeled with Kconfig. + + +Summary: +-------- + +436 pull requests, composed of 1159 commits, have been merged since the +last release, and 11 issues have been solved. 43 people contributed with +code in 88 days. 2475 files have been touched with 44925 (+) insertions and +14687 deletions (-). + + +Notations used below +==================== + + + means new feature/item + * means modified feature/item + - means removed feature/item + + +New features and changes +======================== + +Full list available at https://github.com/RIOT-OS/RIOT/milestone/37?closed=1 + +Core +---- + ++ core/include/kernel_defines.h: add index_of() macro (#17142) ++ core: Add IS_CT_CONSTANT() (#17273) ++ core: add WITHOUT_PEDANTIC() and DECLARE_CONSTANT() (#17176) +* core: Warn about using irq_enable (#17433) +* core: make SCHED_TEST_STACK boolean and default to 1 with DEVELHELP (#17132) + +System Libraries +---------------- + ++ sys/architecture: add HAS_ALIGNMENT_OF() helper (#17177) ++ sys/arduino: add assertion to gpio handling (#17443) ++ sys/atomic_utils: add atomic_{load,store}_ptr() (#17256) ++ sys/include/event/periodic: add count (#17276) ++ sys/isrpipe: add isrpipe_write (#17336) ++ sys/sched_rr: Add a round robin scheduler module (#16126) ++ sys/stdio: add optional function stdio_available (#17446) ++ sys/test_utils/result_output: add sort to multiple output check (#17269) ++ sys/tsrb: add peek functions (#17266) ++ sys/tsrb: add tsrb_clear (#17337) ++ sys/ztimer: add 'ztimer_no_periph_rtt' (#17284) ++ sys/ztimer: add some best practices (#17370) ++ sys/ztimer: ztimer_now() add warning regarding comparing now() values (#17404) ++ usb/hid: Add HID report descriptor defines (#17242) ++ sys/arduino: add Serial over stdio support (#17447) ++ sys: introduce sysclk function to retrieve core clock frequency (#17342) ++ sys/new_delete: add malloc/free based new/delete implementation (#17464) +* event/timeout: remove forced ZTIMER_USEC dependency (#16958) +* riotboot_dfu: use ztimer instead of xtimer (#17051) +* riotboot_serial: enter bootloader mode by pin (#17248) +* schedstatistics: Convert to ztimer (#17216) +* stdio_rtt: Convert to ztimer (#17122) +* stdio_semihosting: Convert to ztimer (#17123) +* sys/can: migrate to ztimer (#17366) +* sys/cpp11-compat: use new/delete operators from sys/cpp_new_delete (#17475) +* sys/evtimer: use now returned by set (#17394) +* sys/fmt: make fmt_s32_dfp() string based (#17106) +* sys/Makefile.dep: fix event periodic dependency (#17318) +* sys/picolibc_syscalls_default: support new picolibc stdio globals (#17001) +* sys/random: default to musl LCG instead of TinyMT (#17188) +* sys/suit: adjust dependencies for CoAP transport (#17182) +* sys/test_utils/result_output/json: optional space after symbol (#17034) +* sys/turo: Allow default selection of json (#17039) +* sys/ztimer/xtimer2ztimer.cocci: extend and fix api replacements (#17234) +* sys/ztimer64: default select ztimer64_init (#17414) +* sys/ztimer64: make _del_entry_from_list() safe for uninit ztimer64_t (#17368) +* sys/ztimer: remove double ztimer indirection (#17272) +* sys/ztimer: ztimer_remove report success (#17408) +* usbus/cdc_acm: Return stall on line coding not supported (#17085) +* usbus/hid: fix ep_out readiness (#17230) +* usbus/hid: fix ep_out readiness (#17245) +* usbus: Bind extra USB config (#17380) +* usbus: check received setup request data amount (#17203) +* sys/ztimer64: initial PR (#16928) + +Networking +---------- + ++ gnrc_pktbuf_cmd: add od dependency with gnrc_pktbuf_static (#17228) ++ sys/net/dhcpv6: Add stateless DHCPv6 (#16731) ++ sys/net: Add ipv4/ipv6 pseudomodules (#16966) ++ sys/shell/sc_nimble_netif: add ping subcommand (#16539) +* dsm: rename DTLS_PEER_MAX and make it dependent on + CONFIG_DTLS_PEER_MAX (#16967) +* gcoap_dtls: destroy session in _tl_send only on connection errors (#16963) +* gnrc_dhcpv6_client / uhcp: delay router advertisements until prefix + was received (#16755) +* gnrc_gomach: adapt duty recording parameters' namings. (#8954) +* gnrc_netif: move netdev initialization to ops->init (#16918) +* lwip: bump to v2.1.3 (#16774) +* net/gcoap: port to ztimer (#17141) +* nimble/statconn: use errno return values (#17344) +* pkg/lwip: Don't control IPv6 via IPv4 flag (#17175) +* pkg/lwip: Fix dualstack build when only using 6lowpan (#17174) +* pkg/openthread: bump version to 20200818 + adapt to use CMake to + configure the build (#16948) +* pkg/openthread: migrate to ztimer (#17120) +* pkg/paho-mqtt: migrate to ztimer (#17143) +* pkg/semtech-loramac: fix get/set dr command (#17117) +* sys/evtimer,ztimer: do not depend on ztimer_now64 (#17357) +* sys/net/gnrc: fix compilation with -Wcast-align (#17157) +* sys/shell/gnrc_netif: Allow 'ifconfig help' (#17006) +* test/ieee802154_hal: general cleanup and cosmetic fixes (#16913) +* tests/lwip_sock: Take lock before calling etharp (#17145) +* socket_zep: port to radio HAL (#16932) +* ieee802154/hal: adapt to latest changes of #13943 (#16946) + +Packages +-------- + ++ pkg/lz4: add support for LZ4 compression/decompression (#17178) ++ pkg/uzlib: add support for zlib compression/decompression (#17179) ++ pkg: add support for Elk Tiny Javascript engine (#16887) ++ pkg: add support for FreeRTOS coreJSON library (#16997) ++ pkg/arduino_sdi_12: add SDI-12 for Arduino as package (#16587) +* hacl: Switch git address to RIOT-OS-pkgmirror (#16941) +* make: support package mirrors (#16927) +* pkg/emlearn: bump to 0.12 (#16937) +* pkg/jerryscript: bump to 2.4.0 (#16938) +* pkg/mynewt-core/patches: silence cast-align (#17397) +* pkg/qr-code-generator: bump to 1.7.0 (#16939) +* pkg/uwb-core: fix wrong header include (#17345) +* pkg/uwb-core: enable frame filtering, allow usage of common event thread (#17264) +* pkg/wakaama: use ztimer (#17103) +* pkg/arduino_sdi_12: support the remote-revb board (#17119) +* pkg/fatfs: bump version to r0.14b (#16412) +* Update tiny-asn1 package (#16936) +* pkg/lvgl: use ztimer instead of xtimer (#17031) +* pkg: migrate some packages to ztimer (#17309) + +Boards +------ + ++ boards/feather-m0: add arduino feature (#17401) ++ boards/iotlab-m3: add MTD definition (#17339) ++ boards/nrf9160dk: add riotboot support (#17226) ++ boards/nucleo-g431rb: added PWM configuration (#17030) ++ boards/p-l496g-cell02: add riotboot feature (#17463) ++ boards/stm32f469i-disco: Add DAC (#17214) ++ boards/stm32g031-disco,examples,tests: Added STM32G031-DISCO board (#16959) ++ boards: add board support for Alientek Pandora (#17259) ++ boards: add support for stm32f746g-disco (#17198) +* boards/common/microbit: fix doxygen grouping (#17440) +* boards/esp* and cpu/esp: feature definition cleanup (#17438) +* boards/lora-e5-dev: enable 3.3V and 5V output by default (#17158) +* boards/lora-e5-dev: fix default DARWIN port (#17373) +* boards/stm32f469i-disco: Create board (#16898) +* boards/{calliope-mini,microbit*}: factorize common microbit module, + use ztimer (#17124) +* boards: cpu: replace GPIO_UNDEF by SPI_CS_UNDEF in SPI configuration (#17468) +* boards: model nrf52 boards (#17299) +* boards: unify user button defines (#17428) +* tools/elf2uf2: addition of new PROGRAMMER for RPi-pico (#17348) + +CPU +--- + ++ Add some Rust building infrastructure and example (#16274) ++ cpu/esp32: add clear bus during init to the I2C software + implementation (#17346) ++ cpu/nrf9160: add periph_flashpage support (#17225) ++ cpu/stm32: Add hardening changes to stm32 (#16979) ++ nimble_scanner: rework to enable scanning BLE5 PHYs and extended + advertisements (#16843) ++ nrf5x_common: Add qdec peripheral implementation (#17201) ++ cpu/esp32: Add openocd programming support (#16911) ++ cpu/stm32: add driver for the LTDC peripheral (#17437) ++ cpu/stm32: add new usbdev FS support (#17281) ++ cpu/stm32: add support for U5 family (#17410) +* boards/common/esp8266: Set RTS and DTR to 0 on pyterm. (#16305) +* cc2538_rf: remove RX Busy detection in request_set_trx_state (#16821) +* cpu/arm7_common: suppress false positives of cppcheck (#17218) +* cpu/atmega_common: make cppcheck happy (#17219) +* cpu/atmega_common: Remember CTC mode with timer_periodic (#17387) +* cpu/atxmega/include/cpu_conf: ztimer64 arithmetic idle stack fix (#17362) +* cpu/cortexm_common: make CI happy (#17220) +* cpu/esp32: make CI happy (#17221) +* cpu/esp32: place freertos and periph in IRAM (#17087) +* cpu/esp32: support CPU clocks 2 MHz and 40 MHz (#17413) +* cpu/esp: change dynamic SSID option handling (#17415) +* cpu/esp: migrate to ztimer (#17386) +* cpu/kinetis/include: fix xtimer backend timer selection (#17393) +* cpu/native/include: other stacksizes based on default (#16956) +* cpu/native: migrate periph_rtc to ztimer (#17125) +* cpu/qn908x: migrate ADC periph to ztimer (#17321) +* cpu/sam0_common: SPI: don't perform DMA transfer for small buffers (#16926) +* cpu/sam0_common: uart: set oversampling based on baud rate (#17186) +* cpu/stm32/include/cpu_conf_stm32_common.h: fix typo in macro (#17187) +* cpu/stm32: bump cmsis repositories to latest releases + extend CPU + models kconfig (#17293) +* cpu/stm32: duplicated ADC devices definitions (#16968) +* cpu/stm32: migrate adc and eth periphs to ztimer (#17320) +* cpu/stm32: split periph_cpu.h in sub headers (#17441) +* cpu: do not auto-select ztimer_periph_rtt for sam0, fe310 (#17395) +* drivers/periph: use uint_fast8_t as default type (#17191) +* esp8266: Download Espressif RTOS SDK as a new RIOT PKG (#16425) +* periph/flashpage: extend API (#16972) +* periph/flashpage: fix wrong doxygen group (#17202) +* stm32/usbdev: Use ztimer instead of xtimer (#17047) +* cpu/esp: compile optional modules in CI (#17314) +* cpu/stm32/wl: initial periph_adc implementation (#17183) +* cpu/stm32: enable USB OTG FS on high end L4 (#17302) + + +Device Drivers +-------------- + ++ drivers/dose: enable standby pin (#16752) ++ drivers/hm330x: initial commit (#16333) ++ drivers: add PCF857X I2C I/O expander driver (#10430) ++ drivers: only build saul interface if saul module is used + add + saul_drivers test application (#17470) ++ netdev: add netdev_register_signal (#16922) ++ drivers/ft5x06: add support for touch panel controller (#17448) ++ drivers/stmpe811: add spi mode (#17088) ++ drivers/dose: make use of UART collision detection feature (#16681) +* driver/at30tse75x: port to ztimer_usec (#17137) +* drivers/ads101x: migrate to ztimer (#17102) +* drivers/ata8520e: migrate to ztimer (#17105) +* drivers/atwinc15x0: migrate to ztimer (#17381) +* drivers/bmp180: migrate to ztimer (#17101) +* drivers/dose: calculate timeout based on symbol rate (#16768) +* drivers/dsp0401: migrate to ztimer (#17110) +* drivers/mhz19: migrate to ztimer (#17308) +* drivers/rn2xx3: migrate to ztimer (#17112) +* drivers/sdcard_spi: convert to ztimer_usec (#17361) +* drivers/stmpe811: improve interrupt callback management (#17487) +* drivers/xbee: migrate to ztimer_msec (#17114) +* drivers: migrate mpu9x50 and si70xx to ztimer (#17358) +* drivers: migrate some drivers to ztimer (#17315) +* drivers: remove some useless xtimer includes (#17303) +* drivers: several cleanups related to xtimer + some ztimer migration (#17375) +* makefiles: remove PCF857x pseudomodule definitions (#17343) +* drivers/periph_common: build periph module selectively (#17418) + +Documentation +------------- + ++ boards/lora-e5-dev: add warning in doc (#17185) ++ doc/getting-started.md: added beginner friendly instructions (#17050) ++ doc/rust: Add maintenance guidance (#17505) +* boards/lora-e5-dev: extended documentation (#17244) +* boards/stm32f746g-disco: extend documentation (#17310) +* doc/.../getting-started.md: update software requirements (#17002) +* doc/boards/rpi-pico: Addition of section concerning shell access (#17454) +* doc: fix libcoap removal commit (#17378) +* pkg/openwsn: update doc (#17131) +* tools/zep_dispatch: document foren6 usage (#17326) +* doc: fix missing or non matching arguments in Doxygen documentation (#17461) + +Build System / Tooling +---------------------- + ++ dist/tools/ci: add can_fast_ci_run.py (#17239) ++ dist/tools/doccheck/exclude_patterns: add new warnings (#17104) ++ dist/tools/doccheck: add create_pattern.sh (#17082) ++ make: add info-emulated-boards helper target (#16975) ++ Makefile.base: add SUBMODULES_NO_SRC to excluded a selected SUBMODULE + *.c (#17222) ++ tools/compile_and_test_for_board: apply black automatic code + formatter + add format checker in tox (#16905) ++ tools/insufficient_memory: add create_makefile.ci.sh and Makefile.ci + make target (#16109) ++ tools/pythonlibs/riotctrl_*: add code format check with black (#16915) ++ tools/zep_dispatch: add support for foren6 sniffer (#16879) ++ tools/zep_dispatch: add topology generator (#16889) ++ makefiles/cflags.inc.mk: Add -Wcast-align (#14955) +* cppcheck: output all annotations as error (#17134) +* dist/tools/coccinelle/force: remove static.cocci (#17139) +* Makefile.include: remove warning about EXTERNAL_MODULE_DIRS API + change (#16984) +* Makefile.include: rename Makefile.ci target to create-Makefile.ci (#17205) +* makefiles/docker.inc.mk: pass TEST_KCONFIG (#17398) +* murdock: make use of can_fast_ci_run.py (#17325) +* static-tests: disable cppcheck (#17282) +* tools/backport_pr: check code format with black (#16907) +* tools: can_fast_ci_run.py: ignore comment changes for `\.[ch]$` (#17405) + +Kconfig +------- + ++ cpu/avr8: model kconfig (#16929) ++ cpu/efm32: model kconfig (#16912) ++ cpu/esp: integrate CPU clock frequency selection in Kconfig (#17424) ++ cpu/msp430: add Kconfig (#17290) ++ cpu/nrf52: initial kconfig modeling (no netif) (#16837) ++ cpu/nrf9160: add Kconfig dependencies (#17291) ++ cpu/riscv: model Kconfig (#16909) ++ makefiles/kconfig: add board & CPU config variables (#17376) ++ pkg/uwb*: add Kconfig dependency modelling (#16780) ++ sys/trace: migrate to ztimer and add Kconfig support (#17319) ++ .murdock: Add modules/pkgs diff of make/kconfig (#17094) ++ .murdock: Add nucleo boards to kconfig test (#16845) ++ .murdock: Add same54-xpro to kconfig tests (#17255) +* .murdock: Kconfig test apps for all boards (#17402) +* boards/adafruit-itsybitsy-m4: Model kconfig (#17331) +* boards/feather-m0*: base board definition in Kconfig (#17445) +* boards/samd21-based: model Kconfig (#17355) +* boards/saml21-based: model kconfig (#17270) +* boards/stm32-based: model Kconfig (#17374) +* cpu/esp{32,8266}: model kconfig (#17232) +* cpu/kinetis: model kconfig (#17235) +* cpu/lpc23xx: model kconfig (#17279) +* cpu/nrf51: model kconfig (#17274) +* cpu/qn908x: model kconfig (#17277) +* cpu/{cc26xx, cc13xx}: model kconfig (#17236) +* drivers/sx126x/Kconfig: rework model selection (#17289) +* sys/benchmark/kconfig: cleanup ztimer dependency (#17317) +* sys/log: model Kconfig (#17286) +* sys/vfs: model Kconfig (#17287) + +Examples +-------- + ++ example/gcoap: add LWIP make option (#17130) +* examples/gcoap: split client and server implementation (#17471) +* examples/gnrc_networking_subnets: remove broken symlink (#17389) +* examples/lorawan: use ztimer_msec if not rtc (#17181) +* examples/gnrc_networking: cleanup and static function declarations in + udp.c (#17384) + +Testing +------- + ++ pkg/fff: Add fake functions framework package (#17076) ++ murdock: add some doc on how to efficiently limit builds (#17312) ++ tests/bench_ztimer: add port of bench_xtimer (#17391) ++ tests/pkg_ucglib: add missing function declaration (#17347) +* gh/workflows/release-tests: update LoRaWAN parameters to ttnv3 (#17009) +* gha/workflows/release-test: set python version to 3.8 (#17038) +* tests/*: Fix nightly failures due to f-string (#17283) +* tests/malloc: fix counting bugs (#17323) +* tests/periph_adc: migrate to ztimer (#17322) +* tests/periph_timer_periodic: spice up test (#17388) +* tests/unittests/tests-base64: enlarge test buffer for worst case (#17292) +* test/pkg_u8g2: increase main stacksize for SDL (#16954) +* tests/pkg_fatfs{_vfs}: drop whitelist (#17478) +* Fix some cppcheck errors (#17271) + +API Changes +----------- + +* core/kernel_defines.h: drop ALIGN_OF() (#17267) +* core/kernel_defines: drop BUILD_BUG_ON() (#17268) +* core/msg: make msg_avail() return 0 on no queue (#17262) +* cpu: call cpu_init() from startup code, not from board (#16055) +* drivers/periph_i2c: let i2c_acquire return void (#17275) +* sys/ztimer: ztimer_set() return the now value (#17385) +* USB: refactor to xmit-based API (#17064) + +Deprecations +============ + +Deprecations (2) +---------------- + +* cpu/mips: deprecate mips cpu (#17304) +* sys/include/xtimer.h: deprecate nanosleep (#17296) +* sys/include/evtimer.h: deprecate evtimer_now_min (#17357) +* usbdev/USBUS: deprecate transfer failure reporting report (#17046) + +Removals (9) +------------ + +- boards/fox: remove BOARD (#17021) +- dist/iotlab: remove deprecated auto-ssh backward compatibility (#17476) +- drivers/ethos: remove deprecated USE_ETHOS_FOR_STDIO define (#17499) +- make: remove deprecation warnings raised with flasher tools old vars (#17490) +- pkg/libcoap: remove (#17163) +- sys/asymcute: remove deprecated CONFIG_ASYMCUTE_BUFSIZE_EXP (#17481) +- sys/crypto: remove deprecated CIPHER_AES_128 (#17480) +- sys/saul_reg: remove deprecated saul_reg_rm function (#17489) +- sys/shell: remove deprecated SHELL_NO_{ECHO,PROMPT} defines (#17484) + +Bug fixes (66) +============== + +* cpu/native: add `-no-pie` to LINKFLAGS (#16186) +* boards/adafruit-clue: use internal RC oscillator (#17069) +* boards/feather-m0-*: fix Arduino feature in Kconfig (#17444) +* boards/nrf9160dk: fix LED macros (#17328) +* boards/nucleo-g07xrb: fix or exclude some doxygen warnings (#17079) +* boards/nucleo-g07xrb: fix or exclude some doxygen warnings [backport + 2021.10] (#17084) +* boards/stm32f723e-disco: use connect_assert_srst with openocd (#17462) +* boards/stm32f746g-disco: use connect_assert_srst with openocd (#17449) +* boards/stm32f769i-disco: fix and cleanup default configuration (#17199) +* cdc_ecm: Truncate frames at max ethernet size (#17200) +* cpu/atmega1281: fix pcint (#17227) +* cpu/esp*: small documentation fixes (#17456) +* cpu/esp32: fix esp_wifi_enterprise compilation problem (#17306) +* cpu/esp8266: fix problems with ESP WiFi and migration to ztimer (#17427) +* cpu/esp8266: place freertos functions in IRAM (#17080) +* cpu/esp: revert the change for default definition of ESP_WIFI_PASS (#17420) +* cpu/esp_common: fix unaligned access in periph_flashpage (#17150) +* cpu/native: align stack in thread_stack_init() (#17155) +* cpu/sam0: prevent disabled irq from being called (#17007) +* cpu/stm32/periph/usbdev: fix alignment issues (#17154) +* cpu/stm32: clone cmsis header in build/stm32 (#17212) +* dhcpv6_client: keep integers in retransmission calculations signed (#16992) +* doc: fix the reference to libcoap removal commit in LOSTANDFOUND.md (#17371) +* driver/css811: fix read status (#17340) +* drivers/ccs811: fix of documentation (#17169) +* drivers/dht: correct interpreting raw values (#16934) +* drivers/dose: fix standby mode (#17184) +* drivers/encx24j600: fix unaligned memory access (#17156) +* drivers/lis3dh: fix unaligned memory access (#17149) +* drivers/sx126x: fix sync word and TX PA configuration (#17138) +* ethos: move bulk of state machine out of ISR context (#17265) +* Fix NDEBUG compilation problems (#14364) +* gnrc_ipv6_nib: queue packets that trigger probing on border router (#16947) +* ieee802154 / tests/unittests: fix all-asan reported errors (#17329) +* Makefile.base: cleanup non selected source object files (#16945) +* Makefile.base: do not clean objects of bindist modules (#16981) +* makefile.dep: require `arch_%` `cpu_core_%` features first (#17224) +* murdock: don't run can_fast_ci_run if `FULL_BUILD==1` (#17495) +* nimble: fix nimble_scanner regression bugs (#17334) +* pkg/arduino_sdi_12: fix for the feather-m0 board (#17501) +* pkg/ccn-ndn: migrate to ztimer (#17377) +* pkg/littlefs{,2}: fix compilation with -Wcast-align (#17151) +* pkg/nimble: version bump to fix broken scanning (#16960) +* pkg/paho-mqtt: fix memory corruption (#17503) +* pkg/relic: bump to current master (#17161) +* pycrypto: use pycryptodome instead (#17107) +* SECURITY.md: fix broken email reference (#17118) +* shell/gnrc_icmpv6_echo: Fix hang with no msg queue (#17261) +* sys/fido2: fix CBOR parsing (#17192) +* sys/fido2: fix CBOR parsing [backport 2021.10] (#17193) +* sys/net/dns: mark dns_hdr_t as packed (#17153) +* sys/net/fib: fix compilation with -Wcast-align (#17194) +* sys/net/gcoap: Use socket _buf API to recognize truncated requests (#16378) +* sys/posix/socket: align struct sockaddr{,_storage} (#17152) +* sys/posix/socket: use explicit bind (#16852) +* sys/test_utils/result_output: fix turo_float() precision value (#17036) +* sys/ztimer/kconfig: enable xtimer compat only with timer backend (#17307) +* sys/ztimer: don't access non-existent timer (#17409) +* sys/ztimer: don't default to rtc for ztimer_sec (#17113) +* sys/ztimer: fix backend selection (#17372) +* tests/socket_zep: fix automatic test (#17432) +* tests/unittests: fix unaligned access (#17195) +* tools/openocd: check OPENOCD_VERIFY after IMAGE_OFFSET is computed (#17251) +* tools/zep_dispatch: forward based on source addr, not MAC addr (#16957) +* turo: some json fixes (#17027) +* usbus/dfu: fix underflow condition while updating firmware (#17128) + + +Known issues +============ + +Network related issues (53) +--------------------------- + +* 6lo gnrc fragmentation expects driver to block on TX (#7474) +* 6lo: RIOT does not receive packets from Linux when short_addr is set (#11033) +* Address registration handling inappropriate (#15867) +* app/netdev: application stops working after receiving frames with + assertion or completely without error (#8271) +* at86rf2xx: Dead lock when sending while receiving (#8242) +* at86rf2xx: lost interrupts (#5486) +* CC2538 RF overlapping PIN usage (#8779) +* core: "Invalid read of size 4" (#7199) +* cpu/esp8266: Tracking open problems of esp_wifi netdev driver (#10861) +* dist/tools/sliptty/start_network.sh: IPv6 connectivity is broken on + PC (#14689) +* driver/mrf24j40: blocks shell input with auto_init_gnrc_netif (#12943) +* drivers/at86rf215: Incorrect channel number set for subGHz (#15906) +* DTLS examples cannot send message to localhost (#14315) +* Emcute cannot create a double-byte name (#12642) +* ethernet: Missing multicast addr assignment (#13493) +* ethos: fails to respond to first message. (#11988) +* ethos: Unable to choose global source address. (#13745) +* ethos: Unable to handle fragmented IPv6 packets from Linux kernel (#12264) +* examples/cord_ep: Dead lock when (re-)registering in callback + function (#12884) +* examples/gnrc_border_router: esp_wifi crashes on disconnect (#14679) +* Forwarding a packet back to its link layer source should not be + allowed (#5051) +* gcoap example request on tap I/F fails with NIB issue (#8199) +* gcoap: Suspected crosstalk between requests (possible NULL call) (#14390) +* General 802.15.4/CC2538 RF driver dislikes fast ACKs (#7304) +* gnrc ipv6: multicast packets are not dispatched to the upper layers (#5230) +* gnrc_border_router stops routing after a while (#16398) +* gnrc_icmpv6_echo: flood-pinging another node leads to leaks in own + packet buffer (#12565) +* gnrc_ipv6: Multicast is not forwarded if routing node listens to the + address (#4527) +* gnrc_rpl: missing bounds checks in _parse_options (#16085) +* gnrc_rpl: nib route not updated when topology / DODAG changes (#17327) +* gnrc_sock_udp: Possible Race condition on copy in application buffer (#10389) +* gomach: Resetting netif with cli doesn't return (#10370) +* ieee802154_submac: IPv6 fragmentation broken (#16998) +* LoRaWan node ISR stack overflowed (#14962) +* lwip_sock_tcp / sock_async: received events before calling + sock_accept() are lost due to race condition. (#16303) +* Missing drop implementations in netdev_driver_t::recv (#10410) +* net: netdev_driver_t::send() doc unclear (#10969) +* netdev_ieee802154: Mismatch between radio ll address and in memory + address (#10380) +* nrf52: Not able to add global or ULA address to interface (#13280) +* nrfmin: communication not possible after multicast ping with no + interval (#11405) +* openthread: does not build on current Arch (#10809) +* ping6 is failing when testing with cc2538dk (#13997) +* pkg/tinydtls: auxiliary data API does not work for async sockets (#16054) +* Possible memory leak in RIOT/build/pkg/ndn-riot/app.c (#15638) +* Riot-os freezes with lwip + enc28j60 + stm32L4 (#13088) +* samr30 xpro doesn't seem to use its radio ok (#12761) +* scan-build errors found during 2019.07 testing (#11852) +* send data with UDP at 10HZ, the program die (#11860) +* stale border router does not get replaced (#12210) +* tests/lwip: does not compile for IPv4 on 6LoWPAN-based boards. (#17162) +* two nodes livelock sending neighbor solicitations back and forth + between each other (#16670) +* Unclear how Router Solicitations are (or should be) handled (#15926) +* xbee: setting PAN ID sometimes fails (#10338) + +Timer related issues (15) +------------------------- + +* cpu/native: timer interrupt issue (#6442) +* misc issues with tests/trickle (#9052) +* MSP430: periph_timer clock config wrong (#8251) +* periph/timer: `timer_set()` underflow safety check (tracking issue) (#13072) +* periph_timer: systematic proportional error in timer_set (#10545) +* saml21 system time vs rtc (#10523) +* Sleep mode for Arduino (#13321) +* stm32_common/periph/rtc: current implementation broken/poor accuracy (#8746) +* sys/newlib: gettimeofday() returns time since boot, not current wall + time. (#9187) +* tests: xtimer_drift gets stuck on native (#6052) +* xtimer mis-scaling with long sleep times (#9049) +* xtimer: add's items to the wrong list if the timer overflows between + _xtimer_now() and irq_disable() (#7114) +* xtimer_set_msg: crash when using same message for 2 timers (#10510) +* xtimer_usleep stuck for small values (#7347) +* xtimer_usleep wrong delay time (#10073) + +Drivers related issues (17) +--------------------------- + +* (almost solved) SPI SD-Card driver: SPI initialisation freeze until + timeout (#14439) +* adc is not a ADC-Driver but a analog pin abstraction (#14424) +* at86rf2xx: Simultaneous use of different transceiver types is not + supported (#4876) +* cpu/msp430: GPIO driver doesn't work properly (#9419) +* driver/hts221: Temperature and Humidity readings incorrect (#12445) +* ESP32 + DHT + SAUL reading two endpoints causes freeze. (#12057) +* examples/dtls-wolfssl not working on pba-d-01-kw2x (#13527) +* fail to send data to can bus (#12371) +* floats and doubles being used all over the place. (#12045) +* mdt_erase success, but vfs_format resets board (esp32-heltec- + lora32-v2) (#14506) +* periph/spi: Switching between CPOL=0,1 problems on Kinetis with + software CS (#6567) +* periph: GPIO drivers are not thread safe (#4866) +* Potential security and safety race conditions on attached devices (#13444) +* PWM: Single-phase initialization creates flicker (#15121) +* STM32: SPI clock not returning to idle state and generating + additional clock cycles (#11104) +* TCP client cannot send read only data (#16541) +* Two bugs may lead to NULL dereference. (#15006) + +Native related issues (6) +------------------------- + +* examples/ccn-lite: floating point exception while testing on native (#15878) +* examples/micropython: floating point exception while testing on + native (#15870) +* native getchar is blocking RIOT (#16834) +* native not float safe (#495) +* native: tlsf: early malloc will lead to a crash (#5796) +* SIGFPE on native architecture when printing double floats on Ubuntu + 21.04 (#16282) + +Other platforms related issues (21) +----------------------------------- + +* Failing tests on FE310 (Hifive1b) (#13086) +* [TRACKING] Fixes for automatic tests of ESP32 boards. (#12763) +* arm7: printf() with float/double not working (#11885) +* boards/hifive1: flashing issue (#13104) +* Cannot use LLVM with Cortex-M boards (#13390) +* cpu/cortexm_common: irq_enable returns the current state of + interrupts (not previous) (#10076) +* cpu/sam0: flashpage write / read cycle produces different results + depending on code layout in flash (#14929) +* cpu/stm32f1: CPU hangs after wake-up from STOP power mode (#13918) +* esp32-wroom-32: tests/netstats_l2 failing sometimes (#14237) +* esp8266 precompiled bootloaders don't support partitions past 1MB (#16402) +* gcoap/esp8266: Stack overflow with gcoap example (#13606) +* I found stm32 DMA periph driver bugs! when I tested stm32l431rc + board. (#16242) +* Incorrect default $PORT building for esp32-wroom-32 on macOS (#10258) +* MIPS: toolchain objcopy doesn't work and no .bin can be generated (#14410) +* MPU doesn't work on cortex-m0+ (#14822) +* newlib-nano: Printf formatting does not work properly for some + numeric types (#1891) +* periph_timer: Test coverage & broken on STM32F767ZI (#15072) +* riscv: ISR stack is too small for ENABLE_DEBUG in core files (#16395) +* stm32152re: hardfault when DBGMCU_CR_DBG* bits are set and branch + after __WFI() (#14015) +* stm32f7: Large performance difference between stm32f746 and stm32f767 (#14728) +* sys/riotboot/flashwrite: unaligned write when skipping + `RIOTBOOT_MAGIC` on stm32wb (#15917) + +Build system related issues (14) +-------------------------------- + +* `buildtest` uses wrong build directory (#9742) +* `make -j flash` fails due to missing make dependencies or `make + flash-only` rebuilds the .elf (#16385) +* Build dependencies - processing order issues (#9913) +* build: info-build doesn't work with boards without port set (#15185) +* BUILD_IN_DOCKER ignores USEMODULE (#14504) +* dist/tools/cppcheck/cppchck.sh: errors when running with Cppcheck + 1.89 (#12771) +* doxygen: riot.css modified by 'make doc' (#8122) +* LTO broken (binaries too large) (#16202) +* macros: RIOT_FILE_RELATIVE printing wrong file name for headers (#4053) +* make: ccache leads to differing binaries (#14264) +* make: Setting constants on compile time doesn't really set them + everywhere (#3256) +* make: use of immediate value of variables before they have their + final value (#8913) +* Tracking: remove harmful use of `export` in make and immediate + evaluation (#10850) +* Windows AVR Mega development makefile Error (#6120) + +Other issues (53) +----------------- + +* [TRACKING] sys/shell refactoring. (#12105) +* _NVIC_SystemReset stuck in infinite loop when calling pm_reboot + through shell after flashing with J-Link (#13044) +* `make term` no longer works with JLinkExe v6.94 (#16022) +* `make term` output is inconsistent between boards, `ethos` and + `native` (#12108) +* assert: c99 static_assert macro doesn't function for multiple + static_asserts in the same scope (#9371) +* Basic test for periph/rtt introduced in #15431 is incorrect (#15940) +* boards/esp32-wroom-32: tests/mtd_raw flakey (#16130) +* boards/saml11-xpro: second UART is broken (#17206) +* Bug: openocd 0.10.0-6 Ubuntu dies while debugging with -rtos auto (#13285) +* C++11 extensions in header files (#5561) +* Can't build relic with benchmarks or tests (#12897) +* CC2538DK board docs: broken links (#12889) +* cpu/stm32/periph/rtc overflow error (#16574) +* cpu/stm32: some tests are failing on CM33 (l5, u5) (#17439) +* doc/LOSTANDFOUND: not rendered as expected (#17063) +* edbg: long lines flooded over serial become garbled (#14548) +* examples / tests: LoRa tests fail on platforms that don't support + LoRa (#14520) +* File systems report names with leading slashes (#14635) +* flashing issue on frdm-k64f (#15903) +* frdm-k22f failing tests/periph_flashpage (#17057) +* gcoap_dtls: Selecting transport at run time is not possible (#16674) +* I2C not working under RIOT with U8G2 pkg (#16381) +* ieee802154_security: Nonce is reused after reboot (#16844) +* lwip: drivers/at86rf2xx/at86rf2xx_netdev.c invalid state during TCP + disconnect (#17209) +* lwip: invalid state transition on ieee802154_submac users (#17208) +* Making the newlib thread-safe (#4488) +* mcuboot: flashes but no output (#17524) +* nanocoap: incomplete response to /.well-known/core request (#10731) +* newlib-nano: Printf formatting does not work properly with `"PRIu8"` (#17083) +* Order of auto_init functions (#13541) +* pkg/tinydtls: Multiple issues (#16108) +* Possible memset optimized out in crypto code (#10751) +* Potential race condition in compile_and_test_for_board.py (#12621) +* pyterm on stdio_cdc_acm stops working after a few seconds (#16077) +* RIOT cannot compile with the latest version of macOS (10.14) and + Xcode 10 (#10121) +* RIOT is saw-toothing in energy consumption (even when idling) (#5009) +* riotboot/nrf52840dk: flashing slot1 with JLINK fails (#14576) +* scheduler: priority inversion problem (#7365) +* sys/fmt: Missing tests for fmt_float, fmt_lpad (#7220) +* sys/riotboot: documentation issues (#11243) +* sys/stdio_uart: dropped data when received at once (#10639) +* tests/cpp11_*: failing on i-nucleo-lrwan1 (#14578) +* tests/lwip target board for python test is hardcoded to native (#6533) +* tests/periph_flashpage: failing on stm32l475ve (#17280) +* tests/pkg_libhydrogen: test fails on master for the samr21-xpro with + LLVM (#15066) +* tests/pkg_tensorflow-lite: tests randomly failing on nrf52dk and + esp32-wroom-32 (#13133) +* tests/test_tools: test fails while testing on samr21-xpro/iotlab-m3 (#15888) +* tests/thread_float: crashes on avr-rss2 (#16908) +* tests: broken with stdio_rtt if auto_init is disabled (#13120) +* tests: some tests don't work with `newlib` lock functions. (#12732) +* Tracker: Reduce scope on unintended COMMON variables (#2346) +* usb-serial/list-ttys.sh: Broken when a debugger offers multiple + serial ports (#15814) +* Use of multiple CAN bus on compatible boards (#14801) + +There are 179 known issues in this release + +Fixed Issues since the last release (2021.10) +============================================= + +- sx127x: wrong RSSI values (#17451) +- drivers/aip31068: initialization fails in most cases when using + esp_i2c_sw (#17311) +- cpu/esp32: esp_wifi_enterprise compilation error (#17305) +- ethos: race condition seems to cause packet loss (#17254) +- tests/lwip_sock_ip: failing on `native` when using IPV4 (#17144) +- Sam boards: isr_eic call all IRQ raised without taking into account + their status (enabled/disabled) (#16978) +- esp8266: Hangs when erasing spi sector on mtd0 if using esp_wifi (#16281) +- esp32: can't use newer C++ standard than c++11 (#15685) +- tests/mpu_noexec_ram: fails on i-nucleo-lrwan1 (#14572) +- Different build behavior between `murdock` and + `riot/riotbuild:latest` image (#9645) +- pkg: libcoap is partially broken and outdated (#7737) + +11 fixed issues since last release (2021.10) + + +Acknowledgements +================ +We would like to thank all companies that provided us with hardware for porting +and testing RIOT-OS. Further thanks go to companies and institutions that +directly sponsored development time. And finally, big thanks to all of you +contributing in so many different ways to make RIOT worthwhile! + + +More information +================ +http://www.riot-os.org + + +Matrix and Forum +================ +* Join the RIOT Matrix room at: #riot-os:matrix.org +* Join the RIOT Forum at: forum.riot-os.org + + +License +======= +* The code developed by the RIOT community is licensed under the GNU Lesser + General Public License (LGPL) version 2.1 as published by the Free Software + Foundation. +* Some external sources and packages are published under a separate license. + +All code files contain licensing information. + + + RIOT-2021.10 - Release Notes ============================ RIOT is a multi-threading operating system which enables soft real-time diff --git a/sys/Makefile.dep b/sys/Makefile.dep index a1d6651908..563136966e 100644 --- a/sys/Makefile.dep +++ b/sys/Makefile.dep @@ -843,7 +843,6 @@ ifneq (,$(filter fido2_ctap,$(USEMODULE))) USEMODULE += ztimer_msec USEMODULE += event USEMODULE += event_timeout - USEMODULE += prng_sha256prng USEMODULE += cipher_modes USEMODULE += crypto_aes_256 USEMODULE += hashes diff --git a/sys/fido2/Kconfig b/sys/fido2/Kconfig index 1b94a5b221..bd2edac28b 100644 --- a/sys/fido2/Kconfig +++ b/sys/fido2/Kconfig @@ -4,4 +4,17 @@ # General Public License v2.1. See the file LICENSE in the top level # directory for more details. +menuconfig MODULE_FIDO2 + bool "FIDO2" + help + FIDO2 is an authentication standard that seeks to solve the password + problem by enabling passwordless authentication. FIDO2 consists of the + W3C Web Authentication specification (WebAuthn) and the Client to + Authenticator Protocol (CTAP). For more information visit + https://fidoalliance.org/fido2. + +if MODULE_FIDO2 + rsource "ctap/Kconfig" + +endif # MODULE_FIDO2 diff --git a/sys/fido2/ctap/Kconfig b/sys/fido2/ctap/Kconfig index ce5c673bff..d64921ec1e 100644 --- a/sys/fido2/ctap/Kconfig +++ b/sys/fido2/ctap/Kconfig @@ -4,13 +4,37 @@ # General Public License v2.1. See the file LICENSE in the top level # directory for more details. -menuconfig KCONFIG_USEMODULE_FIDO2_CTAP +menuconfig MODULE_FIDO2_CTAP bool "FIDO2 CTAP" - depends on USEMODULE_FIDO2_CTAP + depends on HAS_PERIPH_FLASHPAGE + depends on HAS_PERIPH_GPIO + depends on HAS_PERIPH_GPIO_IRQ + depends on MODULE_FIDO2 + depends on TEST_KCONFIG + select PACKAGE_TINYCBOR + select PACKAGE_MICRO-ECC + select PACKAGE_TINY-ASN1 + select MODULE_PERIPH_GPIO + select MODULE_PERIPH_GPIO_IRQ + select MODULE_EVENT + select MODULE_EVENT_TIMEOUT + select MODULE_ZTIMER + select MODULE_ZTIMER_MSEC + select MODULE_MTD + select MODULE_MTD_FLASHPAGE + select MODULE_MTD_WRITE_PAGE + select MODULE_RANDOM + select MODULE_CRYPTO_AES_256 + select MODULE_CIPHER_MODES + select MODULE_HASHES help - Configure a FIDO2 CTAP authenticator via KConfig. + Y to enable CTAP protocol support. The Client-to-Authenticator + Protocol (CTAP) is an application layer protocol for the communication + between an authenticator and a host. CTAP is part of the FIDO2 Project. + For more information visit https://fidoalliance.org/fido2. -if KCONFIG_USEMODULE_FIDO2_CTAP + +if MODULE_FIDO2_CTAP config FIDO2_CTAP_STACK_SIZE int "CTAP thread stack size" @@ -93,4 +117,4 @@ config FIDO2_CTAP_FLASH_START_PAGE rsource "transport/Kconfig" -endif # KCONFIG_USEMODULE_FIDO2_CTAP +endif # MODULE_FIDO2_CTAP diff --git a/sys/fido2/ctap/transport/Kconfig b/sys/fido2/ctap/transport/Kconfig index 5ec3a7e824..b9525f2cb6 100644 --- a/sys/fido2/ctap/transport/Kconfig +++ b/sys/fido2/ctap/transport/Kconfig @@ -4,4 +4,9 @@ # General Public License v2.1. See the file LICENSE in the top level # directory for more details. +menuconfig MODULE_FIDO2_CTAP_TRANSPORT + bool "FIDO2 CTAP transport" + depends on MODULE_FIDO2_CTAP + depends on TEST_KCONFIG + rsource "hid/Kconfig" diff --git a/sys/fido2/ctap/transport/hid/Kconfig b/sys/fido2/ctap/transport/hid/Kconfig index b989225a11..20af9313c3 100644 --- a/sys/fido2/ctap/transport/hid/Kconfig +++ b/sys/fido2/ctap/transport/hid/Kconfig @@ -4,13 +4,16 @@ # General Public License v2.1. See the file LICENSE in the top level # directory for more details. -menuconfig KCONFIG_USEMODULE_FIDO2_CTAP_TRANSPORT_HID - bool "FIDO2 CTAP TRANSPORT HID" - depends on USEMODULE_FIDO2_CTAP_TRANSPORT_HID +menuconfig MODULE_FIDO2_CTAP_TRANSPORT_HID + bool "FIDO2 CTAP transport HID" + depends on MODULE_FIDO2_CTAP_TRANSPORT + depends on TEST_KCONFIG + select MODULE_ISRPIPE + select MODULE_USBUS_HID help Configure a FIDO2 CTAP authenticator via KConfig. -if KCONFIG_USEMODULE_FIDO2_CTAP_TRANSPORT_HID +if MODULE_FIDO2_CTAP_TRANSPORT_HID config FIDO2_CTAP_TRANSPORT_HID_TRANSACTION_TIMEOUT int "CTAPHID Transaction timeout in milliseconds" @@ -20,4 +23,4 @@ config FIDO2_CTAP_TRANSPORT_HID_TRANSACTION_TIMEOUT of time to prevent the authenticator from being locked by a stalling application. -endif # KCONFIG_USEMODULE_FIDO2_CTAP_TRANSPORT_HID +endif # MODULE_FIDO2_CTAP_TRANSPORT_HID diff --git a/sys/include/atomic_utils.h b/sys/include/atomic_utils.h index 50dbaef208..16d4d2b467 100644 --- a/sys/include/atomic_utils.h +++ b/sys/include/atomic_utils.h @@ -139,6 +139,8 @@ #include #include "irq.h" +#include "sched.h" + #include "atomic_utils_arch.h" #ifdef __cplusplus @@ -263,6 +265,16 @@ static inline uintptr_t atomic_load_uintptr(const volatile uintptr_t *var) { static inline void * atomic_load_ptr(void **ptr_addr) { return (void *)atomic_load_uintptr((const volatile uintptr_t *)ptr_addr); } +/** + * @brief Load an `kernel_pid_t` atomically + * + * @param[in] var Variable to load atomically + * @return The value stored in @p var + */ +static inline kernel_pid_t atomic_load_kernel_pid(const volatile kernel_pid_t *var) +{ + return atomic_load_u16((const volatile uint16_t *)var); +} /** @} */ /** @@ -321,6 +333,17 @@ static inline void atomic_store_uintptr(volatile uintptr_t *dest, uintptr_t val) static inline void atomic_store_ptr(void **dest, const void *val) { atomic_store_uintptr((volatile uintptr_t *)dest, (uintptr_t)val); } +/** + * @brief Store an `kernel_pid_t` atomically + * + * @param[out] dest Location to atomically write the new value to + * @param[in] val Value to write + */ +static inline void atomic_store_kernel_pid(volatile kernel_pid_t *dest, + kernel_pid_t val) +{ + atomic_store_u16((volatile uint16_t *)dest, (uint16_t)val); +} /** @} */ /** diff --git a/sys/include/phydat.h b/sys/include/phydat.h index 4e7a99d72c..b83f11c2cc 100644 --- a/sys/include/phydat.h +++ b/sys/include/phydat.h @@ -97,6 +97,7 @@ enum { UNIT_V, /**< Volts */ UNIT_W, /**< Watt */ UNIT_GS, /**< gauss */ + UNIT_T, /**< Tesla */ UNIT_DBM, /**< decibel-milliwatts */ UNIT_COULOMB, /**< coulomb */ UNIT_F, /**< Farad */ diff --git a/sys/include/stdio_nimble.h b/sys/include/stdio_nimble.h new file mode 100644 index 0000000000..4476daf1be --- /dev/null +++ b/sys/include/stdio_nimble.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2019 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @defgroup sys_stdio_nimble STDIO over NimBLE + * @ingroup sys + * + * @experimental This feature is experimental as some use-cases, such as examples/twr_aloha, show + * unexpected behaviour. + * + * @brief Standard input/output backend using NimBLE. + * + * @note 'stdio_read' blocks until at least one character was read. + * + * @note 'stdio_write' is considered non-blocking even though it uses a mutex to protect the + * write buffer since only 'stdio_write' uses this mutex. Characters will be written + * in FIFO mode. Characters that do not fit in the buffer will be dropped. + * + * @{ + * @file + * + * @author Hendrik van Essen + */ + +#ifndef STDIO_NIMBLE_H +#define STDIO_NIMBLE_H + +#include "stdio_base.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Whether to clear the buffers when establishing a new connection or + * not. Defaults to true. + */ +#ifndef CONFIG_STDIO_NIMBLE_CLEAR_BUFFER_ON_CONNECT +#define CONFIG_STDIO_NIMBLE_CLEAR_BUFFER_ON_CONNECT 1 +#endif + +/** + * @brief Size of buffer for stdin in bytes + * + * @note Must be a power of two! + */ +#ifndef CONFIG_STDIO_NIMBLE_STDIN_BUFSIZE +#define CONFIG_STDIO_NIMBLE_STDIN_BUFSIZE 1024 +#endif + +/** + * @brief Size of buffer for stdout in bytes + * + * @note Must be a power of two! + */ +#ifndef CONFIG_STDIO_NIMBLE_STDOUT_BUFSIZE +#define CONFIG_STDIO_NIMBLE_STDOUT_BUFSIZE 2048 +#endif + +#ifdef __cplusplus +} +#endif +/** @} */ +#endif /* STDIO_NIMBLE_H */ diff --git a/sys/net/gnrc/Makefile.dep b/sys/net/gnrc/Makefile.dep index 6adb734191..36736af2fc 100644 --- a/sys/net/gnrc/Makefile.dep +++ b/sys/net/gnrc/Makefile.dep @@ -137,6 +137,7 @@ ifneq (,$(filter gnrc_netif,$(USEMODULE))) USEMODULE += netif USEMODULE += l2util USEMODULE += fmt + USEMODULE += ztimer_msec ifneq (,$(filter netdev_ieee802154_submac,$(USEMODULE))) USEMODULE += gnrc_netif_pktq endif diff --git a/sys/net/gnrc/netif/gnrc_netif.c b/sys/net/gnrc/netif/gnrc_netif.c index ff420bdad2..4c197e999e 100644 --- a/sys/net/gnrc/netif/gnrc_netif.c +++ b/sys/net/gnrc/netif/gnrc_netif.c @@ -41,8 +41,8 @@ #include "fmt.h" #include "log.h" #include "sched.h" -#if IS_USED(MODULE_XTIMER) || IS_USED(MODULE_ZTIMER_XTIMER_COMPAT) -#include "xtimer.h" +#if IS_USED(MODULE_ZTIMER) +#include "ztimer.h" #endif #include "net/gnrc/netif.h" @@ -1370,7 +1370,7 @@ bool gnrc_netif_ipv6_wait_for_global_address(gnrc_netif_t *netif, /* wait for global address */ msg_t m; while (!has_global) { - if (xtimer_msg_receive_timeout(&m, timeout_ms * US_PER_MS) < 0) { + if (ztimer_msg_receive_timeout(ZTIMER_MSEC, &m, timeout_ms) < 0) { DEBUG_PUTS("gnrc_netif: timeout waiting for prefix"); break; } @@ -1867,7 +1867,7 @@ static void *_gnrc_netif_thread(void *args) /* now let rest of GNRC use the interface */ gnrc_netif_release(netif); #if (CONFIG_GNRC_NETIF_MIN_WAIT_AFTER_SEND_US > 0U) - xtimer_ticks32_t last_wakeup = xtimer_now(); + uint32_t last_wakeup = ztimer_now(ZTIMER_USEC); #endif while (1) { @@ -1893,13 +1893,14 @@ static void *_gnrc_netif_thread(void *args) DEBUG("gnrc_netif: GNRC_NETDEV_MSG_TYPE_SND received\n"); _send(netif, msg.content.ptr, false); #if (CONFIG_GNRC_NETIF_MIN_WAIT_AFTER_SEND_US > 0U) - xtimer_periodic_wakeup( + ztimer_periodic_wakeup( + ZTIMER_USEC, &last_wakeup, CONFIG_GNRC_NETIF_MIN_WAIT_AFTER_SEND_US ); /* override last_wakeup in case last_wakeup + * CONFIG_GNRC_NETIF_MIN_WAIT_AFTER_SEND_US was in the past */ - last_wakeup = xtimer_now(); + last_wakeup = ztimer_now(ZTIMER_USEC); #endif break; case GNRC_NETAPI_MSG_TYPE_SET: diff --git a/sys/phydat/phydat_str.c b/sys/phydat/phydat_str.c index bbdea52bad..bad60643f3 100644 --- a/sys/phydat/phydat_str.c +++ b/sys/phydat/phydat_str.c @@ -114,6 +114,7 @@ const char *phydat_unit_to_str(uint8_t unit) case UNIT_W: return "W"; case UNIT_DBM: return "dBm"; case UNIT_GS: return "Gs"; + case UNIT_T: return "T"; case UNIT_BAR: return "Bar"; case UNIT_PA: return "Pa"; case UNIT_PERMILL: return "permille"; diff --git a/sys/shell/commands/Makefile b/sys/shell/commands/Makefile index 78f789acaa..eeddbbbb07 100644 --- a/sys/shell/commands/Makefile +++ b/sys/shell/commands/Makefile @@ -14,6 +14,9 @@ endif ifneq (,$(filter mci,$(USEMODULE))) SRC += sc_disk.c endif +ifneq (,$(filter nice,$(USEMODULE))) + SRC += sc_nice.c +endif ifneq (,$(filter periph_pm,$(USEMODULE))) SRC += sc_pm.c endif diff --git a/sys/shell/commands/sc_nice.c b/sys/shell/commands/sc_nice.c new file mode 100644 index 0000000000..2905f9c389 --- /dev/null +++ b/sys/shell/commands/sc_nice.c @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2021 Otto-von-Guericke-Universität Magdeburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup sys_shell_commands + * @{ + * + * @file + * @brief A shell command to change the niceness (inverse priority) of a thread + * + * @note Enable this by using the modules shell_commands and nice + * + * @author Marian Buschsieweke + * + * @} + */ + +#include +#include + +#include "sched.h" +#include "thread.h" + +int _sc_nice(int argc, char **argv) +{ + if (argc != 3) { + printf("Usage: %s \n" + "Note: Lower number means higher priority (niceness)\n", + argv[0]); + return EXIT_FAILURE; + } + + /* Note: thread_get() does bounds checking and returns NULL on out of bounds PID */ + thread_t *thread = thread_get(atoi(argv[1])); + if (!thread) { + printf("No active thread found for ID \"%s\"\n", argv[1]); + return EXIT_FAILURE; + } + + uint8_t prio = atoi(argv[2]); + if (prio >= SCHED_PRIO_LEVELS) { + printf("Priority \"%s\" is invalid (try 0..%u)\n", + argv[2], (unsigned)SCHED_PRIO_LEVELS - 1); + } + + sched_change_priority(thread, prio); + return EXIT_SUCCESS; +} diff --git a/sys/shell/commands/sc_nimble_netif.c b/sys/shell/commands/sc_nimble_netif.c index 1709a59a4d..8338b3c37f 100644 --- a/sys/shell/commands/sc_nimble_netif.c +++ b/sys/shell/commands/sc_nimble_netif.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "fmt.h" #include "ztimer.h" @@ -30,17 +31,37 @@ #include "net/bluetil/ad.h" #include "net/bluetil/addr.h" -#if !IS_USED(MODULE_NIMBLE_AUTOCONN) && !IS_USED(MODULE_NIMBLE_STATCONN) +#define FULL_CONTROL !IS_USED(MODULE_NIMBLE_AUTOCONN) && \ + !IS_USED(MODULE_NIMBLE_STATCONN) && \ + !IS_USED(MODULE_NIMBLE_RPBLE) + +#if FULL_CONTROL #include "nimble_scanlist.h" #include "nimble_scanner.h" #endif -#define DEFAULT_NODE_NAME "bleRIOT" -#define DEFAULT_SCAN_DURATION (500U) /* 500ms */ -#define DEFAULT_CONN_TIMEOUT (500U) /* 500ms */ +#define DEFAULT_SCAN_DURATION_MS 500U +#define DEFAULT_CONN_TIMEOUT_MS 500U +#define DEFAULT_SCAN_ITVL_MS 100U +#define DEFAULT_CONN_ITVL_MS 75U +#define DEFAULT_TX_POWER 0 /* 0dBm */ +#define DEFAULT_ADV_ITVL_MS 75U -#if !IS_USED(MODULE_NIMBLE_AUTOCONN) && !IS_USED(MODULE_NIMBLE_STATCONN) +static const char *_phystr[] = { "N/A", "1M", "2M", "CODED" }; + +#if FULL_CONTROL static const char *_name_to_connect = NULL; +static nimble_netif_connect_cfg_t _connect_params = { + .scan_itvl_ms = DEFAULT_SCAN_ITVL_MS, + .scan_window_ms = DEFAULT_SCAN_ITVL_MS, + .conn_itvl_min_ms = DEFAULT_CONN_ITVL_MS, + .conn_itvl_max_ms = DEFAULT_CONN_ITVL_MS, + .conn_supervision_timeout_ms = DEFAULT_CONN_ITVL_MS * 20, + .conn_slave_latency = 0, + .timeout_ms = 0, /* will be filled later */ + .phy_mode = 0, /* will be filled later */ + .own_addr_type = 0 /* will be filled later */, +}; static void _scan_for_name(uint8_t type, const ble_addr_t *addr, const nimble_scanner_info_t *info, @@ -56,7 +77,7 @@ static void _scan_for_name(uint8_t type, const ble_addr_t *addr, _name_to_connect, strlen(_name_to_connect)); if (res) { nimble_scanner_stop(); - nimble_netif_connect(addr, NULL, DEFAULT_CONN_TIMEOUT); + nimble_netif_connect(addr, &_connect_params); } } @@ -90,12 +111,34 @@ static void _on_ble_evt(int handle, nimble_netif_event_t event, case NIMBLE_NETIF_ABORT_SLAVE: _print_evt("CONNECTION ABORT", handle, addr); break; + case NIMBLE_NETIF_ACCEPT_STOP: + _print_evt("ACCEPT STOP", handle, addr); case NIMBLE_NETIF_CONN_UPDATED: default: /* do nothing */ break; } } + +static uint8_t _parsephy(const char *phy_str) +{ + if (memcmp(phy_str, "1M", 2) == 0) { + return NIMBLE_PHY_1M; + } +#if IS_ACTIVE(MODULE_NIMBLE_PHY_2MBIT) + else if (memcmp(phy_str, "2M", 2) == 0) { + return NIMBLE_PHY_2M; + } +#endif +#if IS_ACTIVE(MODULE_NIMBLE_PHY_CODED) + else if (memcmp(phy_str, "CODED", 5) == 0) { + return NIMBLE_PHY_CODED; + } +#endif + else { + return NIMBLE_PHY_INVALID; + } +} #endif static int _conn_dump(nimble_netif_conn_t *conn, int handle, void *arg) @@ -117,8 +160,20 @@ static int _conn_dump(nimble_netif_conn_t *conn, int handle, void *arg) printf(" "); bluetil_addr_ipv6_l2ll_print(conn->addr); #endif - printf(" (%c,%ums,%ums,%i)", role, itvl, sto, (int)desc.conn_latency); - puts(""); + +#if IS_USED(MODULE_NIMBLE_NETIF_EXT) + uint8_t phy_rx, phy_tx; + (void)phy_tx; + res = ble_gap_read_le_phy(conn->gaphandle, &phy_tx, &phy_rx); + if (res != 0) { + phy_rx = 1; + } +#else + /* when not using extended advertisements we always use the 1M phy mode */ + uint8_t phy_rx = 1; +#endif + printf(" (%c,%ums,%ums,%i,%s)\n", + role, itvl, sto, (int)desc.conn_latency, _phystr[phy_rx]); return 0; } @@ -159,7 +214,7 @@ static void _conn_list(void) if (active > 0) { nimble_netif_conn_foreach(NIMBLE_NETIF_L2CAP_CONNECTED, _conn_dump, NULL); - puts(" (role, conn itvl, superv. timeout, slave latency)"); + puts(" (role, conn itvl, superv. timeout, slave latency, PHY)"); } } @@ -179,6 +234,15 @@ static void _cmd_info(void) #endif puts(""); + printf("Supported PHY modes: 1M"); +#if IS_USED(MODULE_NIMBLE_PHY_2MBIT) + printf(" 2M"); +#endif +#if IS_USED(MODULE_NIMBLE_PHY_CODED) + printf(" CODED"); +#endif + puts(""); + printf(" Free slots: %u/%u\n", free, NIMBLE_NETIF_MAX_CONN); printf("Advertising: "); if (nimble_netif_conn_get_adv() != NIMBLE_NETIF_CONN_INVALID) { @@ -196,99 +260,107 @@ static void _cmd_info(void) puts(""); } -#if !IS_USED(MODULE_NIMBLE_AUTOCONN) && !IS_USED(MODULE_NIMBLE_STATCONN) -static void _cmd_adv(const char *name) +#if FULL_CONTROL +static int _cmd_adv(int argc, char **argv, bool legacy) { int res; (void)res; - uint8_t buf[BLE_HS_ADV_MAX_SZ]; - bluetil_ad_t ad; - const struct ble_gap_adv_params _adv_params = { - .conn_mode = BLE_GAP_CONN_MODE_UND, - .disc_mode = BLE_GAP_DISC_MODE_LTD, - .itvl_min = BLE_GAP_ADV_FAST_INTERVAL2_MIN, - .itvl_max = BLE_GAP_ADV_FAST_INTERVAL2_MAX, - }; + const char *name = NULL; + uint8_t addrn[BLE_ADDR_LEN]; + ble_addr_t addr = { .type = nimble_riot_own_addr_type }; + + /* stop sub-command: stop advertising */ + if (memcmp(argv[2], "stop", 4) == 0) { + res = nimble_netif_accept_stop(); + if (res == 0) { + puts("advertising stopped"); + } + else if (res == -EALREADY) { + puts("no advertising in progress"); + } + return 0; + } /* make sure no advertising is in progress */ if (nimble_netif_conn_is_adv()) { puts("err: advertising already in progress"); - return; + return 1; } - /* build advertising data */ - res = bluetil_ad_init_with_flags(&ad, buf, BLE_HS_ADV_MAX_SZ, - BLUETIL_AD_FLAGS_DEFAULT); - assert(res == BLUETIL_AD_OK); - uint16_t ipss = BLE_GATT_SVC_IPSS; - res = bluetil_ad_add(&ad, BLE_GAP_AD_UUID16_INCOMP, &ipss, sizeof(ipss)); - assert(res == BLUETIL_AD_OK); - if (name == NULL) { - name = DEFAULT_NODE_NAME; + /* try if first parameter is a BLE address, if so, use directed + * advertisement */ + if (bluetil_addr_from_str(addrn, argv[2]) != NULL) { + /* NimBLE expects address in little endian, so swap */ + bluetil_addr_swapped_cp(addrn, addr.val); + puts("Found BLE address: sending directed advertisements"); } - res = bluetil_ad_add(&ad, BLE_GAP_AD_NAME, name, strlen(name)); - if (res != BLUETIL_AD_OK) { - puts("err: the given name is too long"); - return; + else { + name = argv[2]; + } + + uint32_t timeout = 0; + if (argc >= 4) { + timeout = (uint32_t)atoi(argv[3]); + } + + uint8_t phy_sec = BLE_GAP_LE_PHY_1M; + if (argc >= 5) { + phy_sec = _parsephy(argv[4]); + if (phy_sec == 0) { + puts("err: PHY mode not supported\n"); + return 1; + } + } + uint8_t phy_pri = (phy_sec == BLE_HCI_LE_PHY_2M) ? BLE_HCI_LE_PHY_1M + : phy_sec; + + nimble_netif_accept_cfg_t p = { + .flags = (legacy) ? NIMBLE_NETIF_FLAG_LEGACY : 0, + .adv_itvl_ms = DEFAULT_ADV_ITVL_MS, + .primary_phy = phy_pri, + .secondary_phy = phy_sec, + .tx_power = DEFAULT_TX_POWER, + .channel_map = 0, + .timeout_ms = timeout, + .own_addr_type = nimble_riot_own_addr_type, + }; + + if (name != NULL) { + uint8_t buf[BLE_HS_ADV_MAX_SZ]; + bluetil_ad_t ad; + /* build advertising data */ + res = bluetil_ad_init_with_flags(&ad, buf, BLE_HS_ADV_MAX_SZ, + BLUETIL_AD_FLAGS_DEFAULT); + assert(res == BLUETIL_AD_OK); + uint16_t ipss = BLE_GATT_SVC_IPSS; + res = bluetil_ad_add(&ad, BLE_GAP_AD_UUID16_INCOMP, &ipss, sizeof(ipss)); + assert(res == BLUETIL_AD_OK); + res = bluetil_ad_add(&ad, BLE_GAP_AD_NAME, name, strlen(name)); + if (res != BLUETIL_AD_OK) { + puts("err: the given name is too long"); + return 1; + } + + res = nimble_netif_accept(ad.buf, ad.pos, &p); + } + else { + res = nimble_netif_accept_direct(&addr, &p); } - /* start listening for incoming connections */ - res = nimble_netif_accept(ad.buf, ad.pos, &_adv_params); if (res != 0) { printf("err: unable to start advertising (%i)\n", res); } else { - printf("success: advertising this node as '%s'\n", name); - } -} - -static void _cmd_adv_direct(const char *addr_str) -{ - int res; - (void)res; - uint8_t addrn[BLE_ADDR_LEN]; - ble_addr_t addr; - const struct ble_gap_adv_params _adv_params = { - .conn_mode = BLE_GAP_CONN_MODE_DIR, - .disc_mode = BLE_GAP_DISC_MODE_GEN, - .itvl_min = BLE_GAP_ADV_FAST_INTERVAL2_MIN, - .itvl_max = BLE_GAP_ADV_FAST_INTERVAL2_MAX, - }; - - /* make sure no advertising is in progress */ - if (nimble_netif_conn_is_adv()) { - puts("err: advertising already in progress"); - return; - } - - /* parse and convert address -> RIOT uses big endian notation, NimBLE - * expects little endian... */ - if (bluetil_addr_from_str(addrn, addr_str) == NULL) { - puts("err: unable to parse BLE address"); - return; - } - addr.type = nimble_riot_own_addr_type; - bluetil_addr_swapped_cp(addrn, addr.val); - - /* start advertising directed advertising with the given BLE address */ - res = nimble_netif_accept_direct(&addr, BLE_HS_FOREVER, &_adv_params); - if (res != 0) { - printf("err: unable to start directed advertising (%i)\n", res); - } - else { - puts("success: started to send directed advertisements"); - } -} - -static void _cmd_adv_stop(void) -{ - int res = nimble_netif_accept_stop(); - if (res == 0) { - puts("canceled advertising"); - } - else { - puts("no advertising in progress"); + if (name != NULL) { + printf("success: advertising this node as '%s'\n", name); + } + else { + printf("success: sending direct advertisements to "); + bluetil_addr_print(addrn); + puts(""); + } } + return 0; } static void _do_scan(nimble_scanner_cb cb, unsigned duration) @@ -301,7 +373,19 @@ static void _do_scan(nimble_scanner_cb cb, unsigned duration) printf("err: scanner already active\n"); return; } - nimble_scanner_init(NULL, cb); + + nimble_scanner_cfg_t p = { + .itvl_ms = DEFAULT_SCAN_ITVL_MS, + .win_ms = DEFAULT_SCAN_ITVL_MS, +#if IS_USED(MODULE_NIMBLE_PHY_CODED) + .flags = (NIMBLE_SCANNER_PASSIVE | NIMBLE_SCANNER_PHY_1M | + NIMBLE_SCANNER_PHY_CODED), +#else + .flags = (NIMBLE_SCANNER_PASSIVE | NIMBLE_SCANNER_PHY_1M), +#endif + }; + + nimble_scanner_init(&p, cb); nimble_scanlist_clear(); nimble_scanner_start(); ztimer_sleep(ZTIMER_MSEC, duration); @@ -316,58 +400,73 @@ static void _cmd_scan(unsigned duration) nimble_scanlist_print(); } -static void _cmd_connect_addr(ble_addr_t *addr) +static void _cmd_connect(int argc, char **argv) { - /* simply use NimBLEs default connection parameters */ - int res = nimble_netif_connect(addr, NULL, DEFAULT_CONN_TIMEOUT); - if (res < 0) { - printf("err: unable to trigger connection sequence (%i)\n", res); - return; - } + ble_addr_t addr; + int proceed = 0; - printf("initiated connection procedure with "); + /* populate connection parameters */ + _connect_params.timeout_ms = DEFAULT_CONN_TIMEOUT_MS; + if (argc >= 4) { + _connect_params.timeout_ms = (uint32_t)atoi(argv[3]); + } + _connect_params.phy_mode = NIMBLE_PHY_1M; + if (argc >= 5) { + _connect_params.phy_mode = _parsephy(argv[4]); + if (_connect_params.phy_mode == 0) { + puts("err: PHY mode not supported\n"); + return; + } + } + _connect_params.own_addr_type = nimble_riot_own_addr_type; + + /* try to parse address directly */ uint8_t addrn[BLE_ADDR_LEN]; - bluetil_addr_swapped_cp(addr->val, addrn); - bluetil_addr_print(addrn); - puts(""); - -} - -static void _cmd_connect_addr_raw(const uint8_t *addr_in) -{ - /* RANDOM is the most common type, has no noticeable effect when connecting - anyhow... */ - ble_addr_t addr = { .type = BLE_ADDR_RANDOM }; - /* NimBLE expects address in little endian, so swap */ - bluetil_addr_swapped_cp(addr_in, addr.val); - _cmd_connect_addr(&addr); -} - -static void _cmd_connect_name(const char *name, unsigned duration) -{ - if (_name_to_connect != NULL) { - printf("err: already trying to connect to '%s'\n", _name_to_connect); + if (bluetil_addr_from_str(addrn, argv[2]) != NULL) { + addr.type = nimble_riot_own_addr_type; + /* NimBLE expects address in little endian, so swap */ + bluetil_addr_swapped_cp(addrn, addr.val); + proceed = 1; + } + /* try if param is a number, if so use it as scanlist entry number */ + else if (fmt_is_number(argv[2])) { + unsigned pos = atoi(argv[2]); + nimble_scanlist_entry_t *sle = nimble_scanlist_get_by_pos(pos); + if (sle == NULL) { + puts("err: unable to find given entry in scanlist"); + return; + } + _connect_params.phy_mode = sle->phy_sec; + memcpy(&addr, &sle->addr, sizeof(addr)); + proceed = 1; + } + /* else interpret value as name and search for that peer */ + else { + unsigned duration = DEFAULT_SCAN_DURATION_MS; + if (argc > 3) { + duration = atoi(argv[3]); + } + _name_to_connect = argv[2]; + printf("trying to find and connect to a node with name '%s'\n", argv[2]); + _do_scan(_scan_for_name, duration); + if (_name_to_connect != NULL) { + printf("fail: unable to connect to '%s'\n", _name_to_connect); + _name_to_connect = NULL; + } return; } - _name_to_connect = name; - printf("trying to find and connect to a node with name '%s'\n", name); - _do_scan(_scan_for_name, duration); - if (_name_to_connect != NULL) { - printf("fail: unable to connect to '%s'\n", _name_to_connect); - _name_to_connect = NULL; - } -} -static void _cmd_connect_scanlist(unsigned pos) -{ - nimble_scanlist_entry_t *sle = nimble_scanlist_get_by_pos(pos); - if (sle == NULL) { - puts("err: unable to find given entry in scanlist"); - return; + if (proceed == 1) { + int res = nimble_netif_connect(&addr, &_connect_params); + if (res == 0) { + puts("Successfully connected 123"); + } + else { + puts("err: unable to connect"); + } } - _cmd_connect_addr(&sle->addr); } -#endif /* MODULE_NIMBLE_AUTOCONN */ +#endif static void _cmd_close(int handle) { @@ -406,7 +505,7 @@ static int _ishelp(char *argv) void sc_nimble_netif_init(void) { -#if !IS_USED(MODULE_NIMBLE_AUTOCONN) && !IS_USED(MODULE_NIMBLE_STATCONN) +#if FULL_CONTROL /* setup the scanning environment */ nimble_scanlist_init(); @@ -418,8 +517,9 @@ void sc_nimble_netif_init(void) int _nimble_netif_handler(int argc, char **argv) { if ((argc == 1) || _ishelp(argv[1])) { -#if !IS_USED(MODULE_NIMBLE_AUTOCONN) && !IS_USED(MODULE_NIMBLE_STATCONN) - printf("usage: %s [help|info|adv|scan|connect|close|update|chanmap]\n", argv[0]); +#if FULL_CONTROL + printf("usage: %s [help|info|adv|adv_ext|adv_dir|" + "scan|connect|close|update|chanmap]\n", argv[0]); #else printf("usage: %s [help|info|close|update|chanmap]\n", argv[0]); #endif @@ -429,34 +529,26 @@ int _nimble_netif_handler(int argc, char **argv) _cmd_info(); } -#if !IS_USED(MODULE_NIMBLE_AUTOCONN) && !IS_USED(MODULE_NIMBLE_STATCONN) - else if (memcmp(argv[1], "adv", 3) == 0) { - char *name = NULL; - if (argc > 2) { - if (_ishelp(argv[2])) { - printf("usage: %s adv [help|stop|direct |]\n", - argv[0]); - return 0; - } - if (memcmp(argv[2], "stop", 4) == 0) { - _cmd_adv_stop(); - return 0; - } - if (memcmp(argv[2], "direct", 6) == 0) { - puts("DBG: direct adv"); - if (argc < 4) { - printf("error, no BLE address given\n"); - return 0; - } - _cmd_adv_direct(argv[3]); - return 0; - } - name = argv[2]; +#if FULL_CONTROL + else if (memcmp(argv[1], "adv_ext", 7) == 0) { + if (argc <= 2 || _ishelp(argv[2])) { + printf("usage: %s adv_ext [timeout] [phy mode]\n" + " timeout in ms, 0 for no timeout\n" + " phy mode: [1M|2M|CODED]\n", argv[0]); + return 0; } - _cmd_adv(name); + return _cmd_adv(argc, argv, false); + } + else if (memcmp(argv[1], "adv", 3) == 0) { + if (argc <= 2 || _ishelp(argv[2])) { + printf("usage: %s adv [timeout]\n" + " timeout in ms, 0 for no timeout\n", argv[0]); + return 0; + } + return _cmd_adv(argc, argv, true); } else if (memcmp(argv[1], "scan", 4) == 0) { - uint32_t duration = DEFAULT_SCAN_DURATION; + uint32_t duration = DEFAULT_SCAN_DURATION_MS; if (argc > 2) { if (_ishelp(argv[2])) { printf("usage: %s scan [help|list|[duration in ms]]\n", argv[0]); @@ -472,32 +564,16 @@ int _nimble_netif_handler(int argc, char **argv) } else if (memcmp(argv[1], "connect", 7) == 0) { if ((argc < 3) || _ishelp(argv[2])) { - printf("usage: %s connect [help|list|||]\n", - argv[0]); + printf("usage: %s %s [help|list|||] " + "[timeout ms] [phy mode]\n" + " phy mode: [1M|2M|CODED]\n", argv[0], argv[1]); return 0; } if (memcmp(argv[2], "list", 4) == 0) { _conn_list(); return 0; } - /* try if param is an BLE address */ - uint8_t addr[BLE_ADDR_LEN]; - if (bluetil_addr_from_str(addr, argv[2]) != NULL) { - _cmd_connect_addr_raw(addr); - return 0; - } - /* try if param is a name (contains non-number chars) */ - if (!fmt_is_number(argv[2])) { - unsigned duration = DEFAULT_SCAN_DURATION; - if (argc > 3) { - duration = atoi(argv[3]); - } - _cmd_connect_name(argv[2], duration); - return 0; - } - - unsigned pos = atoi(argv[2]); - _cmd_connect_scanlist(pos); + _cmd_connect(argc, argv); } #endif else if (memcmp(argv[1], "close", 5) == 0) { diff --git a/sys/shell/commands/sc_nimble_statconn.c b/sys/shell/commands/sc_nimble_statconn.c index 26726c42a9..99679649c5 100644 --- a/sys/shell/commands/sc_nimble_statconn.c +++ b/sys/shell/commands/sc_nimble_statconn.c @@ -24,13 +24,48 @@ #include "net/bluetil/addr.h" #include "nimble_statconn.h" + +static uint8_t _parsephy(const char *phy_str) +{ + if (memcmp(phy_str, "1M", 2) == 0) { + return NIMBLE_PHY_1M; + } +#if IS_ACTIVE(MODULE_NIMBLE_PHY_2MBIT) + else if (memcmp(phy_str, "2M", 2) == 0) { + return NIMBLE_PHY_2M; + } +#endif +#if IS_ACTIVE(MODULE_NIMBLE_PHY_CODED) + else if (memcmp(phy_str, "CODED", 5) == 0) { + return NIMBLE_PHY_CODED; + } +#endif + else { + return NIMBLE_PHY_INVALID; + } +} + int _nimble_statconn_handler(int argc, char **argv) { + nimble_statconn_cfg_t cfg; + if ((argc < 3)) { - printf("usage: %s \n", argv[0]); + printf("usage: %s [phy mode]\n" + " phy_mode := [1M, 2M, CODED]\n", argv[0]); return 0; } + if (argc >= 4) { + cfg.phy_mode = _parsephy(argv[3]); + if (cfg.phy_mode == NIMBLE_PHY_INVALID) { + puts("err: PHY mode not supported"); + return 1; + } + } + else { + cfg.phy_mode = NIMBLE_STATCONN_PHY_MODE; + } + /* parse address */ uint8_t addr[BLE_ADDR_LEN]; if (bluetil_addr_from_str(addr, argv[2]) == NULL) { @@ -39,7 +74,7 @@ int _nimble_statconn_handler(int argc, char **argv) } if (strncmp(argv[1], "addm", 4) == 0) { - if (nimble_statconn_add_master(addr) == 0) { + if (nimble_statconn_add_master(addr, &cfg) == 0) { puts("success: connecting to peer as slave"); } else { @@ -47,7 +82,7 @@ int _nimble_statconn_handler(int argc, char **argv) } } else if (strncmp(argv[1], "adds", 4) == 0) { - if (nimble_statconn_add_slave(addr) == 0) { + if (nimble_statconn_add_slave(addr, &cfg) == 0) { puts("success: connecting to peer as master"); } else { diff --git a/sys/shell/commands/shell_commands.c b/sys/shell/commands/shell_commands.c index 79d963f4f4..33a948a4d2 100644 --- a/sys/shell/commands/shell_commands.c +++ b/sys/shell/commands/shell_commands.c @@ -187,6 +187,10 @@ extern int _i2c_scan(int argc, char **argv); extern int _loramac_handler(int argc, char **argv); #endif +#ifdef MODULE_NICE +extern int _sc_nice(int argc, char **argv); +#endif + #ifdef MODULE_NIMBLE_NETIF extern int _nimble_netif_handler(int argc, char **argv); #endif @@ -267,6 +271,9 @@ const shell_command_t _shell_command_list[] = { #ifdef MODULE_GNRC_IPV6_NIB {"nib", "Configure neighbor information base", _gnrc_ipv6_nib}, #endif +#ifdef MODULE_NICE + {"nice", "Change priority of an active thread", _sc_nice}, +#endif #ifdef MODULE_NETSTATS_NEIGHBOR {"neigh", "Show neighbor statistics", _netstats_nb}, #endif diff --git a/sys/stdio_nimble/Makefile b/sys/stdio_nimble/Makefile new file mode 100644 index 0000000000..48422e909a --- /dev/null +++ b/sys/stdio_nimble/Makefile @@ -0,0 +1 @@ +include $(RIOTBASE)/Makefile.base diff --git a/sys/stdio_nimble/README.md b/sys/stdio_nimble/README.md new file mode 100644 index 0000000000..381b2efa63 --- /dev/null +++ b/sys/stdio_nimble/README.md @@ -0,0 +1,110 @@ +# STDIO NimBLE + +This module uses NimBLE for stdio. The bluetooth characteristic for +stdin is writable and the characteristic for stdout uses the indicate +mechanism to publish the system's output to a connected device. Data will be +sent out asynchronously via callout functions. + +To use this module, add +``` +USEMODULE += stdio_nimble +``` +to your makefile. + +You can change the default buffer sizes by adding +``` +CFLAGS += -DCONFIG_STDIO_NIMBLE_STDIN_BUFSIZE=1024 +CFLAGS += -DCONFIG_STDIO_NIMBLE_STDOUT_BUFSIZE=2048 +``` +to your makefile. \ +**NOTE:** These values must be a power of two! + +By default, stdin and stdout buffers are cleared on a connect event. To keep the +content add the following to your makefile: +``` +CFLAGS += -DCONFIG_STDIO_NIMBLE_CLEAR_BUFFER_ON_CONNECT=0 +``` + +For automatic bluetooth advertising a module is provided: *nimble_autoadv*. +It will take care of enabling advertising on disconnect events and +disabling advertising on connect events. It can be enabled by adding +``` +USEMODULE += nimble_autoadv +``` +to your makefile. + +The advertised device name can then optionally be configured with +``` +CFLAGS += -DNIMBLE_AUTOADV_DEVICE_NAME='"Riot OS device"' +``` +Otherwise the device will appear as "*RIOT OS device*". + +## Instructions to connect to the bluetooth shell via ble-serial + +- Configure and compile shell app for nrf52840dongle target in `tests/shell`.\ + +Add following to Makefile: +``` +BOARD = nrf52840dongle +USEMODULE += nimble_autoadv +USEMODULE += stdio_nimble +``` + +**NOTE:** You can also have a look at `tests/shell_ble`. + +- Flash + +`$ make -C tests/shell -j clean all flash` + +- Install the ble-serial tool + +`$ pip install ble-serial` + +- Scan for your device (device name `Riot OS device`) and note its BLE address.\ + When you get `ble-scan: command not found` you can also run + `python -m ble_serial.scan` instead. +``` +$ ble-scan +Started BLE scan + +6BE8174C-A0F8-4479-AFA6-9828372CAFE9 (RSSI=-40): Riot OS device +A2862DCB-D382-4C0B-95BF-FA9A961F8D88 (RSSI=-48): Unknown +F2C75C08-7DD7-4F43-BEF0-151C92068FE5 (RSSI=-66): Unknown +69400683-FBE5-4B45-8CFE-98594076E5F4 (RSSI=-89): Unknown +``` + +- Discover characteristics (check the one advertised by the gatt server stdin/stdout) +``` +$ ble-scan -d 6BE8174C-A0F8-4479-AFA6-9828372CAFE9 +Started deep scan of 6BE8174C-A0F8-4479-AFA6-9828372CAFE9 + +SERVICE e6d54866-0292-4779-b8f8-c52bbec91e71 (Handle: 10): Unknown + CHARACTERISTIC 35f28386-3070-4f3b-ba38-27507e991762 (Handle: 11): Unknown ['indicate'] + DESCRIPTOR 00002902-0000-1000-8000-00805f9b34fb (Handle: 13): Client Characteristic Configuration + CHARACTERISTIC ccdd113f-40d5-4d68-86ac-a728dd82f4aa (Handle: 14): Unknown ['write'] + +Completed deep scan of 6BE8174C-A0F8-4479-AFA6-9828372CAFE9 +``` + +- Create a virtual port and mount it on /tmp/dev_riot_ble +``` +$ ble-serial -d 6BE8174C-A0F8-4479-AFA6-9828372CAFE9 -p /tmp/dev_riot_ble --write-uuid ccdd113f-40d5-4d68-86ac-a728dd82f4aa --read-uuid 35f28386-3070-4f3b-ba38-27507e991762 +17:44:18.765 | INFO | linux_pty.py: Slave created on /tmp/dev_riot_ble -> /dev/ttys006 +17:44:18.766 | INFO | ble_interface.py: Receiver set up +17:44:18.766 | INFO | ble_interface.py: Trying to connect with 6BE8174C-A0F8-4479-AFA6-9828372CAFE9 +17:44:19.861 | INFO | ble_interface.py: Device 6BE8174C-A0F8-4479-AFA6-9828372CAFE9 connected +17:44:19.862 | INFO | ble_interface.py: Found write characteristic ccdd113f-40d5-4d68-86ac-a728dd82f4aa (H. 14) +17:44:19.862 | INFO | ble_interface.py: Found notify characteristic 35f28386-3070-4f3b-ba38-27507e991762 (H. 11) +17:44:19.883 | INFO | main.py: Running main loop! +``` + +- Open the virtual com port (the port name is from the logs in previous steps) +``` +$ picocom -q -b 115200 --imap lfcrlf /tmp/dev_riot_ble +ps + pid | state Q | pri + 1 | running Q | 7 + 2 | bl anyfl _ | 5 + 3 | bl anyfl _ | 0 +> +``` \ No newline at end of file diff --git a/sys/stdio_nimble/stdio_nimble.c b/sys/stdio_nimble/stdio_nimble.c new file mode 100644 index 0000000000..3a71b6e340 --- /dev/null +++ b/sys/stdio_nimble/stdio_nimble.c @@ -0,0 +1,387 @@ +/* + * Copyright (C) 2019 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup sys + * @{ + * + * @file + * @brief STDIO over NimBLE implementation + * + * + * @author Hendrik van Essen + * @author Francisco Molina + * + * @} + */ + +#include +#include + +#include "nimble_riot.h" +#include "nimble/nimble_port.h" +#include "net/bluetil/ad.h" + +#include "host/ble_hs.h" +#include "host/util/util.h" +#include "host/ble_gatt.h" +#include "services/gap/ble_svc_gap.h" +#include "services/gatt/ble_svc_gatt.h" + +#if IS_USED(MODULE_STDIO_NIMBLE_DEBUG) +#include +#include "stdio_uart.h" +#include "periph/uart.h" +#endif /* IS_USED(MODULE_STDIO_NIMBLE_DEBUG) */ + +#if IS_USED(MODULE_VFS) +#include "vfs.h" +#endif + +#include "tsrb.h" +#include "isrpipe.h" +#include "stdio_nimble.h" + +#define NIMBLE_MAX_PAYLOAD MYNEWT_VAL(BLE_LL_MAX_PKT_SIZE) + +/* Nimble uses ZTIMER_MSEC => 1 tick equals 1 ms */ +#define CALLOUT_TICKS_MS 1 + +enum { + STDIO_NIMBLE_DISCONNECTED, + STDIO_NIMBLE_CONNECTED, + STDIO_NIMBLE_SUBSCRIBED, + STDIO_NIMBLE_SENDING, +}; + +/* isrpipe for stdin */ +static uint8_t _isrpipe_stdin_mem[CONFIG_STDIO_NIMBLE_STDIN_BUFSIZE]; +static isrpipe_t _isrpipe_stdin = ISRPIPE_INIT(_isrpipe_stdin_mem); + +/* tsrb for stdout */ +static uint8_t _tsrb_stdout_mem[CONFIG_STDIO_NIMBLE_STDOUT_BUFSIZE]; +static tsrb_t _tsrb_stdout = TSRB_INIT(_tsrb_stdout_mem); + +/* intermediate buffer to transfer data between tsrb and nimble functions, + * which are all based on os_mbuf implementation */ +static uint8_t _stdin_read_buf[NIMBLE_MAX_PAYLOAD]; +static uint8_t _stdout_write_buf[NIMBLE_MAX_PAYLOAD]; + +/* information about bluetooth connection */ +static uint16_t _conn_handle; +static uint16_t _val_handle_stdout; +static volatile uint8_t _status = STDIO_NIMBLE_DISCONNECTED; + +/* nimble related structs */ +static struct ble_npl_callout _send_stdout_callout; +static struct ble_gap_event_listener _gap_event_listener; + +#if IS_USED(MODULE_STDIO_NIMBLE_DEBUG) +#define DEBUG_PRINTF_BUFSIZE 512 +#define PREFIX_STDIN "\nSTDIN: " +#define PREFIX_STDOUT "STDOUT: " + +static char _debug_printf_buf[DEBUG_PRINTF_BUFSIZE]; +#endif /* IS_USED(MODULE_STDIO_NIMBLE_DEBUG) */ + +static int _debug_printf(const char *format, ...) +{ +#if IS_USED(MODULE_STDIO_NIMBLE_DEBUG) + unsigned state = irq_disable(); + va_list va; + va_start(va, format); + int rc = vsnprintf(_debug_printf_buf, DEBUG_PRINTF_BUFSIZE, format, va); + va_end(va); + uart_write(STDIO_UART_DEV, (const uint8_t *)_debug_printf_buf, rc); + irq_restore(state); + + return rc; +#else + (void)format; + return 0; +#endif +} + +/** + * @brief UUID for stdio service (value: e6d54866-0292-4779-b8f8-c52bbec91e71) + */ +static const ble_uuid128_t gatt_svr_svc_stdio_uuid + = BLE_UUID128_INIT(0x71, 0x1e, 0xc9, 0xbe, 0x2b, 0xc5, 0xf8, 0xb8, + 0x79, 0x47, 0x92, 0x02, 0x66, 0x48, 0xd5, 0xe6); + +/** + * @brief UUID for stdout characteristic (value: 35f28386-3070-4f3b-ba38-27507e991762) + */ +static const ble_uuid128_t gatt_svr_chr_stdout_uuid + = BLE_UUID128_INIT(0x62, 0x17, 0x99, 0x7e, 0x50, 0x27, 0x38, 0xba, + 0x3b, 0x4f, 0x70, 0x30, 0x86, 0x83, 0xf2, 0x35); + +/** + * @brief UUID for stdin characteristic (value: ccdd113f-40d5-4d68-86ac-a728dd82f4aa) + */ +static const ble_uuid128_t gatt_svr_chr_stdin_uuid + = BLE_UUID128_INIT(0xaa, 0xf4, 0x82, 0xdd, 0x28, 0xa7, 0xac, 0x86, + 0x68, 0x4d, 0xd5, 0x40, 0x3f, 0x11, 0xdd, 0xcc); + +/** + * @brief Nimble access callback for stdin characteristic + */ +static int gatt_svr_chr_access_stdin( + uint16_t conn_handle, uint16_t attr_handle, + struct ble_gatt_access_ctxt *ctxt, void *arg); + +/** + * @brief Dummy access callback, because nimble requires one + */ +static int gatt_svr_chr_access_noop( + uint16_t conn_handle, uint16_t attr_handle, + struct ble_gatt_access_ctxt *ctxt, void *arg) +{ + + (void)conn_handle; + (void)attr_handle; + (void)ctxt; + (void)arg; + + return 0; +} + +/** + * @brief Struct to define the stdio bluetooth service with its characteristics + */ +static const struct ble_gatt_svc_def _gatt_svr_svcs[] = +{ + /* + * access_cb defines a callback for read and write access events on + * given characteristics + */ + { + /* Service: stdio */ + .type = BLE_GATT_SVC_TYPE_PRIMARY, + .uuid = (ble_uuid_t *)&gatt_svr_svc_stdio_uuid.u, + .characteristics = (struct ble_gatt_chr_def[]) { { + /* Characteristic: stdout */ + .uuid = (ble_uuid_t *)&gatt_svr_chr_stdout_uuid.u, + .access_cb = gatt_svr_chr_access_noop, + .val_handle = &_val_handle_stdout, + .flags = BLE_GATT_CHR_F_INDICATE, + }, { + /* Characteristic: stdin */ + .uuid = (ble_uuid_t *)&gatt_svr_chr_stdin_uuid.u, + .access_cb = gatt_svr_chr_access_stdin, + .flags = BLE_GATT_CHR_F_WRITE, + }, { + 0, /* No more characteristics in this service */ + }, } + }, + { + 0, /* No more services */ + }, +}; + +static void _purge_buffer(void) +{ + tsrb_clear(&_isrpipe_stdin.tsrb); + +#if IS_USED(MODULE_SHELL) + /* send Ctrl-C to the shell to reset the input */ + isrpipe_write_one(&_isrpipe_stdin, '\x03'); +#endif + + tsrb_clear(&_tsrb_stdout); +} + +static void _send_stdout(struct ble_npl_event *ev) +{ + (void)ev; + + /* rearm callout */ + ble_npl_callout_reset(&_send_stdout_callout, CALLOUT_TICKS_MS); + + if (_status == STDIO_NIMBLE_SUBSCRIBED) { + _status = STDIO_NIMBLE_SENDING; + int to_send = tsrb_peek(&_tsrb_stdout, _stdout_write_buf, NIMBLE_MAX_PAYLOAD); + + if (to_send > 0) { + struct os_mbuf *om = ble_hs_mbuf_from_flat(_stdout_write_buf, to_send); + if (om != NULL) { + int rc = ble_gattc_indicate_custom(_conn_handle, _val_handle_stdout, om); + if (rc == 0) { + /* bytes were successfully sent, so drop them from the buffer */ + tsrb_drop(&_tsrb_stdout, to_send); + _debug_printf("%d bytes sent successfully\n", to_send); + } + else { + _status = STDIO_NIMBLE_SUBSCRIBED; + } + } + else { + _status = STDIO_NIMBLE_SUBSCRIBED; + } + } + else { + _status = STDIO_NIMBLE_SUBSCRIBED; + } + } +} + +static int _gap_event_cb(struct ble_gap_event *event, void *arg) +{ + (void)arg; + + switch (event->type) { + + case BLE_GAP_EVENT_CONNECT: + _debug_printf("BLE_GAP_EVENT_CONNECT\n"); + if (event->connect.status == 0) { + _status = STDIO_NIMBLE_CONNECTED; + if (CONFIG_STDIO_NIMBLE_CLEAR_BUFFER_ON_CONNECT) { + _purge_buffer(); + } + _conn_handle = event->connect.conn_handle; + } + else { + _status = STDIO_NIMBLE_DISCONNECTED; + } + break; + + case BLE_GAP_EVENT_DISCONNECT: + _debug_printf("BLE_GAP_EVENT_DISCONNECT\n"); + _status = STDIO_NIMBLE_DISCONNECTED; + break; + + case BLE_GAP_EVENT_SUBSCRIBE: + _debug_printf("BLE_GAP_EVENT_SUBSCRIBE\n"); + if (event->subscribe.attr_handle == _val_handle_stdout) { + if (event->subscribe.cur_indicate == 1) { + _status = STDIO_NIMBLE_SUBSCRIBED; + } + else { + _status = STDIO_NIMBLE_CONNECTED; + } + } + break; + + case BLE_GAP_EVENT_NOTIFY_TX: + _debug_printf("BLE_GAP_EVENT_NOTIFY_TX\n"); + if (event->notify_tx.indication == 1) { + if (event->notify_tx.status == BLE_HS_EDONE) { + _status = STDIO_NIMBLE_SUBSCRIBED; + } + else if (event->notify_tx.status != 0) { + _status = STDIO_NIMBLE_SUBSCRIBED; + } + } + break; + + case BLE_GAP_EVENT_MTU: + _debug_printf("BLE_GAP_EVENT_MTU: mtu = %d\n", event->mtu.value); + break; + } + + return 0; +} + +static int gatt_svr_chr_access_stdin( + uint16_t conn_handle, uint16_t attr_handle, + struct ble_gatt_access_ctxt *ctxt, void *arg) +{ + (void)conn_handle; + (void)attr_handle; + (void)arg; + + uint16_t om_len = OS_MBUF_PKTLEN(ctxt->om); + + /* read sent data */ + int rc = ble_hs_mbuf_to_flat(ctxt->om, _stdin_read_buf, sizeof(_stdin_read_buf), &om_len); + + isrpipe_write(&_isrpipe_stdin, _stdin_read_buf, om_len); + + return rc; +} + +void stdio_init(void) +{ +#if IS_USED(MODULE_VFS) + vfs_bind_stdio(); +#endif + +#if IS_USED(MODULE_STDIO_NIMBLE_DEBUG) + uart_init(STDIO_UART_DEV, STDIO_UART_BAUDRATE, NULL, NULL); +#endif + + ble_npl_callout_init(&_send_stdout_callout, nimble_port_get_dflt_eventq(), + _send_stdout, NULL); +} + +#if IS_USED(MODULE_STDIO_AVAILABLE) +int stdio_available(void) +{ + return tsrb_avail(&_isrpipe_stdin.tsrb); +} +#endif + +ssize_t stdio_read(void *buffer, size_t count) +{ + /* blocks until at least one character was read */ + ssize_t res = isrpipe_read(&_isrpipe_stdin, buffer, count); + +#if IS_USED(MODULE_STDIO_NIMBLE_DEBUG) + unsigned state = irq_disable(); + uart_write(STDIO_UART_DEV, (const uint8_t *)PREFIX_STDIN, strlen(PREFIX_STDIN)); + uart_write(STDIO_UART_DEV, (const uint8_t *)buffer, res); + uart_write(STDIO_UART_DEV, (const uint8_t *)"\n", 1); + irq_restore(state); +#endif + + return res; +} + +ssize_t stdio_write(const void *buffer, size_t len) +{ + unsigned state = irq_disable(); + +#if IS_USED(MODULE_STDIO_NIMBLE_DEBUG) + uart_write(STDIO_UART_DEV, (const uint8_t *)PREFIX_STDOUT, strlen(PREFIX_STDOUT)); + uart_write(STDIO_UART_DEV, (const uint8_t *)buffer, len); + uart_write(STDIO_UART_DEV, (const uint8_t *)"\n", 1); +#endif + + irq_restore(state); + + unsigned int consumed = tsrb_add(&_tsrb_stdout, buffer, len); + + if (!ble_npl_callout_is_active(&_send_stdout_callout)) { + /* bootstrap callout */ + ble_npl_callout_reset(&_send_stdout_callout, CALLOUT_TICKS_MS); + } + + return consumed; +} + +/* is going to be called by auto_init */ +void stdio_nimble_init(void) +{ + int rc = 0; + + /* verify and add our custom services */ + rc = ble_gatts_count_cfg(_gatt_svr_svcs); + assert(rc == 0); + rc = ble_gatts_add_svcs(_gatt_svr_svcs); + assert(rc == 0); + + /* reload the GATT server to link our added services */ + ble_gatts_start(); + + /* register gap event listener */ + rc = ble_gap_event_listener_register(&_gap_event_listener, _gap_event_cb, NULL); + assert(rc == 0); + + /* fix compilation error when using DEVELHELP=0 */ + (void)rc; +} diff --git a/sys/xtimer/xtimer.c b/sys/xtimer/xtimer.c index 3b3541bdfb..0381bd368f 100644 --- a/sys/xtimer/xtimer.c +++ b/sys/xtimer/xtimer.c @@ -23,6 +23,7 @@ #include #include "xtimer.h" +#include "atomic_utils.h" #include "msg.h" #include "mutex.h" #include "rmutex.h" @@ -224,8 +225,7 @@ int xtimer_rmutex_lock_timeout(rmutex_t *rmutex, uint64_t timeout) return 0; } if (xtimer_mutex_lock_timeout(&rmutex->mutex, timeout) == 0) { - atomic_store_explicit(&rmutex->owner, - thread_getpid(), memory_order_relaxed); + atomic_store_kernel_pid(&rmutex->owner, thread_getpid()); rmutex->refcount++; return 0; } diff --git a/sys/ztimer/util.c b/sys/ztimer/util.c index 822b82a5be..be0716422b 100644 --- a/sys/ztimer/util.c +++ b/sys/ztimer/util.c @@ -23,6 +23,7 @@ #include #include +#include "atomic_utils.h" #include "irq.h" #include "mutex.h" #include "rmutex.h" @@ -190,8 +191,7 @@ int ztimer_rmutex_lock_timeout(ztimer_clock_t *clock, rmutex_t *rmutex, return 0; } if (ztimer_mutex_lock_timeout(clock, &rmutex->mutex, timeout) == 0) { - atomic_store_explicit(&rmutex->owner, - thread_getpid(), memory_order_relaxed); + atomic_store_kernel_pid(&rmutex->owner, thread_getpid()); rmutex->refcount++; return 0; } diff --git a/sys/ztimer64/util.c b/sys/ztimer64/util.c index 99aaf94d35..530778790c 100644 --- a/sys/ztimer64/util.c +++ b/sys/ztimer64/util.c @@ -23,6 +23,7 @@ #include #include +#include "atomic_utils.h" #include "irq.h" #include "mutex.h" #include "rmutex.h" @@ -183,8 +184,7 @@ int ztimer64_rmutex_lock_until(ztimer64_clock_t *clock, rmutex_t *rmutex, return 0; } if (ztimer64_mutex_lock_until(clock, &rmutex->mutex, target) == 0) { - atomic_store_explicit(&rmutex->owner, - thread_getpid(), memory_order_relaxed); + atomic_store_kernel_pid(&rmutex->owner, thread_getpid()); rmutex->refcount++; return 0; } diff --git a/sys/ztimer64/ztimer64.c b/sys/ztimer64/ztimer64.c index 4e1021c9e5..e1b8974c73 100644 --- a/sys/ztimer64/ztimer64.c +++ b/sys/ztimer64/ztimer64.c @@ -23,6 +23,8 @@ */ #include #include +/* stdio.h needs to be included before inttypes.h (newlibc) */ +#include #include #include "ztimer64.h" @@ -294,9 +296,7 @@ void ztimer64_clock_print(const ztimer64_clock_t *clock) const ztimer64_base_t *entry = clock->first; while (entry) { - printf("0x%08x:%" PRIu64 "\n", (unsigned)entry, - entry->target); - + printf("0x%08x:%" PRIu64 "\n", (unsigned)entry, entry->target); entry = entry->next; } puts(""); diff --git a/tests/driver_at86rf215/Makefile.ci b/tests/driver_at86rf215/Makefile.ci index 502cf84658..2ce525a914 100644 --- a/tests/driver_at86rf215/Makefile.ci +++ b/tests/driver_at86rf215/Makefile.ci @@ -31,4 +31,5 @@ BOARD_INSUFFICIENT_MEMORY := \ telosb \ waspmote-pro \ zigduino \ + z1 # diff --git a/tests/driver_lc709203f/README.md b/tests/driver_lc709203f/README.md index 3e025767ca..a56626e959 100644 --- a/tests/driver_lc709203f/README.md +++ b/tests/driver_lc709203f/README.md @@ -2,6 +2,6 @@ This is a test application for the ON Semiconductor lc709203F Battery Fuel Gauge # Usage Just enter the `make BOARD=??? flash` command in the `tests/driver_lc709203F/` folder. -Make sure the `LC709203F_INT_PIN` is set in your boards periph_conf.h +Make sure the `LC709203F_PARAMS_ALARM_PIN` is set in your boards `board.h` # Results The sensor will first test the low RSOC interrupt by setting the threshold limit to 100%. Therefore a low RSOC interrupt should be triggered and the message "ALARM low RSOC" should be printed to the terminal. After that all major measurements will be printed and refreshed every 5s. diff --git a/tests/driver_mpu9x50/app.config.test b/tests/driver_mpu9x50/app.config.test index edb625451b..df67bd9024 100644 --- a/tests/driver_mpu9x50/app.config.test +++ b/tests/driver_mpu9x50/app.config.test @@ -1,5 +1,5 @@ # this file enables modules defined in Kconfig. Do not use this file for # application configuration. This is only needed during migration. -CONFIG_MODULE_MPU9150=y +CONFIG_MODULE_MPU9X50=y CONFIG_MODULE_ZTIMER=y CONFIG_MODULE_ZTIMER_MSEC=y diff --git a/tests/gnrc_netif_ipv6_wait_for_global_address/main.c b/tests/gnrc_netif_ipv6_wait_for_global_address/main.c index 30858dd8c6..1dd573de3a 100644 --- a/tests/gnrc_netif_ipv6_wait_for_global_address/main.c +++ b/tests/gnrc_netif_ipv6_wait_for_global_address/main.c @@ -27,7 +27,7 @@ #include "net/gnrc/netif.h" #include "net/gnrc/netif/raw.h" #include "net/netdev_test.h" -#include "xtimer.h" +#include "ztimer.h" #define TEST_NETIF_NUMOF 2 #define TEST_NETIF_PRIO 3 @@ -54,7 +54,7 @@ static void tear_down(void) static void *_adder_thread(void *netif) { - xtimer_msleep(10); + ztimer_sleep(ZTIMER_MSEC, 10); gnrc_netif_ipv6_addr_add(netif, &_test_addr, 64, GNRC_NETIF_IPV6_ADDRS_FLAGS_STATE_VALID); return NULL; @@ -74,16 +74,16 @@ static void _assert_wait_blocks(gnrc_netif_t *add_netif, gnrc_netif_t *wait_netif, bool success) { - uint32_t now = xtimer_now_usec(); + uint32_t now = ztimer_now(ZTIMER_MSEC); uint32_t timeout = 20; _add_delayed_addr(add_netif); TEST_ASSERT(gnrc_netif_ipv6_wait_for_global_address(wait_netif, timeout) == success); if (success) { - TEST_ASSERT(((xtimer_now_usec() - now) / US_PER_MS) < timeout); + TEST_ASSERT((ztimer_now(ZTIMER_MSEC) - now) < timeout); } else { - TEST_ASSERT(((xtimer_now_usec() - now) / US_PER_MS) >= timeout); + TEST_ASSERT((ztimer_now(ZTIMER_MSEC) - now) >= timeout); } } diff --git a/tests/kconfig/Makefile b/tests/kconfig/Makefile index 5e73126239..89da973e17 100644 --- a/tests/kconfig/Makefile +++ b/tests/kconfig/Makefile @@ -4,4 +4,8 @@ USEMODULE += external_module_1 USEMODULE += external_module_2 EXTERNAL_MODULE_DIRS += external_modules +ifeq (1, $(TEST_KCONFIG)) + KCONFIG_ADD_CONFIG += $(APPDIR)/app.config +endif + include $(RIOTBASE)/Makefile.include diff --git a/tests/kconfig/app.config.test b/tests/kconfig/app.config.test new file mode 100644 index 0000000000..5cf8111726 --- /dev/null +++ b/tests/kconfig/app.config.test @@ -0,0 +1,2 @@ +CONFIG_MODULE_EXTERNAL_MODULE_1=y +CONFIG_MODULE_EXTERNAL_MODULE_2=y diff --git a/tests/kconfig/external_modules/external_module_1/Kconfig b/tests/kconfig/external_modules/external_module_1/Kconfig index 6f3306d486..d15ced618c 100644 --- a/tests/kconfig/external_modules/external_module_1/Kconfig +++ b/tests/kconfig/external_modules/external_module_1/Kconfig @@ -11,3 +11,7 @@ config EXTERNAL_MODULE_1_MESSAGE default "External Message 1 defined in Kconfig file" endif # KCONFIG_EXTERNAL_MODULE_1 + +config MODULE_EXTERNAL_MODULE_1 + bool "Select external module 2" + depends on TEST_KCONFIG diff --git a/tests/kconfig/external_modules/external_module_2/Kconfig b/tests/kconfig/external_modules/external_module_2/Kconfig index 011963dcc4..a3d36cce87 100644 --- a/tests/kconfig/external_modules/external_module_2/Kconfig +++ b/tests/kconfig/external_modules/external_module_2/Kconfig @@ -11,3 +11,7 @@ config EXTERNAL_MODULE_2_MESSAGE default "External Message 2 defined in Kconfig file" endif # KCONFIG_EXTERNAL_MODULE_2 + +config MODULE_EXTERNAL_MODULE_2 + bool "Select external module 2" + depends on TEST_KCONFIG diff --git a/tests/nimble_autoconn_gnrc_ext/Makefile b/tests/nimble_autoconn_gnrc_ext/Makefile new file mode 100644 index 0000000000..d63fd5a7e7 --- /dev/null +++ b/tests/nimble_autoconn_gnrc_ext/Makefile @@ -0,0 +1,24 @@ +BOARD ?= nrf52dk +include ../Makefile.tests_common + +# include shell support +USEMODULE += shell +USEMODULE += shell_commands +USEMODULE += ps + +# Include GNRC and RPL +USEMODULE += auto_init_gnrc_netif +USEMODULE += gnrc_ipv6_router_default +USEMODULE += gnrc_icmpv6_echo +USEMODULE += auto_init_gnrc_rpl +USEMODULE += gnrc_rpl + +# Setup Nimble +USEMODULE += nimble_autoconn_ipsp +USEMODULE += nimble_autoconn_ext +FEATURES_OPTIONAL += ble_phy_2mbit +FEATURES_OPTIONAL += ble_phy_coded + +TEST_ON_CI_WHITELIST += nrf52dk nrf52840dk + +include $(RIOTBASE)/Makefile.include diff --git a/tests/nimble_autoconn_gnrc_ext/Makefile.ci b/tests/nimble_autoconn_gnrc_ext/Makefile.ci new file mode 100644 index 0000000000..4079597a0f --- /dev/null +++ b/tests/nimble_autoconn_gnrc_ext/Makefile.ci @@ -0,0 +1,4 @@ +BOARD_INSUFFICIENT_MEMORY := \ + e104-bt5010a-tb \ + e104-bt5011a-tb \ + # diff --git a/tests/nimble_autoconn_gnrc_ext/main.c b/tests/nimble_autoconn_gnrc_ext/main.c new file mode 100644 index 0000000000..cbbac5bfca --- /dev/null +++ b/tests/nimble_autoconn_gnrc_ext/main.c @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2019 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup examples + * @{ + * + * @file + * @brief Run IP-over-BLE using the 'autoconn' BLE connection manager + * + * @author Hauke Petersen + * + * @} + */ + +#include + +#include "shell.h" +#include "msg.h" + +#define MAIN_QUEUE_SIZE (8) +static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; + +int main(void) +{ + /* we need a message queue for the thread running the shell in order to + * receive potentially fast incoming networking packets */ + msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE); + puts("IPv6-over-BLE with autoconn BLE connection manager"); + + /* start shell */ + puts("All up, running the shell now"); + char line_buf[SHELL_DEFAULT_BUFSIZE]; + shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); + + /* should never be reached */ + return 0; +} diff --git a/tests/nimble_ext_adv/Makefile b/tests/nimble_ext_adv/Makefile index 42cd1b0c77..8d6e5107e2 100644 --- a/tests/nimble_ext_adv/Makefile +++ b/tests/nimble_ext_adv/Makefile @@ -8,11 +8,8 @@ USEMODULE += shell_commands USEMODULE += nimble_scanner USEMODULE += nimble_scanlist USEMODULE += nimble_adv_ext -USEMODULE += nimble_phy_2mbit - -ifneq (,$(filter nrf52840dk nrf52840dongle,$(BOARD))) - USEMODULE += nimble_phy_coded -endif +FEATURES_OPTIONAL += ble_phy_2mbit +FEATURES_OPTIONAL += ble_phy_coded # Comment this out to disable code in RIOT that does safety checking # which is not needed in a production environment but helps in the diff --git a/tests/nimble_netif_ext/Makefile b/tests/nimble_netif_ext/Makefile new file mode 100644 index 0000000000..744dc8e258 --- /dev/null +++ b/tests/nimble_netif_ext/Makefile @@ -0,0 +1,24 @@ +BOARD ?= nrf52dk +include ../Makefile.tests_common + +# include shell support +USEMODULE += shell +USEMODULE += shell_commands +USEMODULE += ps + +# Include GNRC and RPL +USEMODULE += netdev_default +USEMODULE += auto_init_gnrc_netif +USEMODULE += gnrc_ipv6_router_default +USEMODULE += auto_init_gnrc_rpl +USEMODULE += gnrc_rpl +USEMODULE += gnrc_icmpv6_echo + +# Setup Nimble +USEMODULE += nimble_netif_ext +FEATURES_OPTIONAL += ble_phy_2mbit +FEATURES_OPTIONAL += ble_phy_coded + +TEST_ON_CI_WHITELIST += nrf52dk nrf52840dk + +include $(RIOTBASE)/Makefile.include diff --git a/tests/nimble_netif_ext/Makefile.ci b/tests/nimble_netif_ext/Makefile.ci new file mode 100644 index 0000000000..4079597a0f --- /dev/null +++ b/tests/nimble_netif_ext/Makefile.ci @@ -0,0 +1,4 @@ +BOARD_INSUFFICIENT_MEMORY := \ + e104-bt5010a-tb \ + e104-bt5011a-tb \ + # diff --git a/tests/nimble_netif_ext/main.c b/tests/nimble_netif_ext/main.c new file mode 100644 index 0000000000..84b13d0531 --- /dev/null +++ b/tests/nimble_netif_ext/main.c @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2021 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup examples + * @{ + * + * @file + * @brief Test extended advertising and additional PHY modes with + * nimble_netif + * + * @author Hauke Petersen + * + * @} + */ + +#include + +#include "shell.h" +#include "msg.h" + +#define MAIN_QUEUE_SIZE (8) +static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; + +int main(void) +{ + puts("Extended PHY mode test for IP over BLE"); + + /* we need a message queue for the thread running the shell in order to + * receive potentially fast incoming networking packets */ + msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE); + + /* start shell */ + puts("All up, running the shell now"); + char line_buf[SHELL_DEFAULT_BUFSIZE]; + shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); + + /* should never be reached */ + return 0; +} diff --git a/tests/nimble_rpble_gnrc/Makefile b/tests/nimble_rpble_gnrc/Makefile index bb23b35c4c..b57fffb558 100644 --- a/tests/nimble_rpble_gnrc/Makefile +++ b/tests/nimble_rpble_gnrc/Makefile @@ -17,7 +17,7 @@ USEMODULE += auto_init_gnrc_rpl # configure and use Nimble USEMODULE += bluetil_addr USEMODULE += nimble_rpble -NIMBLE_MAX_CONN := 3 +NIMBLE_MAX_CONN = 3 DEVELHELP = 0 diff --git a/tests/nimble_rpble_gnrc_ext/Makefile b/tests/nimble_rpble_gnrc_ext/Makefile new file mode 100644 index 0000000000..d7b7d01194 --- /dev/null +++ b/tests/nimble_rpble_gnrc_ext/Makefile @@ -0,0 +1,30 @@ +BOARD ?= nrf52dk +include ../Makefile.tests_common + +# include shell support +USEMODULE += shell +USEMODULE += shell_commands +USEMODULE += ps + +# Enable single interface optimization. +# Remove this if more than one interface is present +USEMODULE += gnrc_netif_single +# Include GNRC and RPL +USEMODULE += auto_init_gnrc_netif +USEMODULE += gnrc_ipv6_router_default +USEMODULE += gnrc_icmpv6_echo +USEMODULE += gnrc_rpl +USEMODULE += auto_init_gnrc_rpl + +# configure and use Nimble +USEMODULE += bluetil_addr +USEMODULE += nimble_rpble_ext +FEATURES_OPTIONAL += ble_phy_2mbit +FEATURES_OPTIONAL += ble_phy_coded +NIMBLE_MAX_CONN = 3 + +DEVELHELP = 0 + +TEST_ON_CI_WHITELIST += nrf52dk nrf52840dk + +include $(RIOTBASE)/Makefile.include diff --git a/tests/nimble_rpble_gnrc_ext/Makefile.ci b/tests/nimble_rpble_gnrc_ext/Makefile.ci new file mode 100644 index 0000000000..4079597a0f --- /dev/null +++ b/tests/nimble_rpble_gnrc_ext/Makefile.ci @@ -0,0 +1,4 @@ +BOARD_INSUFFICIENT_MEMORY := \ + e104-bt5010a-tb \ + e104-bt5011a-tb \ + # diff --git a/tests/nimble_rpble_gnrc_ext/main.c b/tests/nimble_rpble_gnrc_ext/main.c new file mode 100644 index 0000000000..7428966008 --- /dev/null +++ b/tests/nimble_rpble_gnrc_ext/main.c @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2021 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup examples + * @{ + * + * @file + * @brief Test for using rpble in its extended mode + * + * @author Hauke Petersen + * + * @} + */ + +#include +#include + +#include "msg.h" +#include "shell.h" +#include "nimble_rpble.h" +#include "net/bluetil/addr.h" + +#define MAIN_QUEUE_SIZE (8) +static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; + +static void _dump_evt(const char *text, const uint8_t *addr) +{ + printf("[ble_event] %s (", text); + bluetil_addr_print(addr); + printf(")\n"); +} + +static void _on_rpble_event(int handle, nimble_netif_event_t event, + const uint8_t *addr) +{ + (void)handle; + + switch (event) { + case NIMBLE_NETIF_CONNECTED_MASTER: + _dump_evt("parent selected", addr); + break; + case NIMBLE_NETIF_CONNECTED_SLAVE: + _dump_evt("child added", addr); + break; + case NIMBLE_NETIF_CLOSED_MASTER: + _dump_evt("parent lost", addr); + break; + case NIMBLE_NETIF_CLOSED_SLAVE: + _dump_evt("child lost", addr); + break; + default: + /* not interested in any other BLE events here */ + break; + } + +} + +int main(void) +{ + puts("RPL-over-BLE Example Application"); + + /* register the custom event handler */ + nimble_rpble_eventcb(_on_rpble_event); + + /* we need a message queue for the thread running the shell in order to + * receive potentially fast incoming networking packets (ping) */ + msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE); + + /* start shell */ + char line_buf[SHELL_DEFAULT_BUFSIZE]; + shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); + + return 0; +} diff --git a/tests/nimble_statconn_gnrc_ext/Makefile b/tests/nimble_statconn_gnrc_ext/Makefile new file mode 100644 index 0000000000..c0a373c6dc --- /dev/null +++ b/tests/nimble_statconn_gnrc_ext/Makefile @@ -0,0 +1,23 @@ +BOARD ?= nrf52dk +include ../Makefile.tests_common + +# include shell support +USEMODULE += shell +USEMODULE += shell_commands +USEMODULE += ps + +# Include GNRC and RPL +USEMODULE += auto_init_gnrc_netif +USEMODULE += gnrc_ipv6_router_default +USEMODULE += auto_init_gnrc_rpl +USEMODULE += gnrc_rpl +USEMODULE += gnrc_icmpv6_echo + +# Setup Nimble +USEMODULE += nimble_statconn_ext +FEATURES_OPTIONAL += ble_phy_2mbit +FEATURES_OPTIONAL += ble_phy_coded + +TEST_ON_CI_WHITELIST += nrf52dk nrf52840dk + +include $(RIOTBASE)/Makefile.include diff --git a/tests/nimble_statconn_gnrc_ext/Makefile.ci b/tests/nimble_statconn_gnrc_ext/Makefile.ci new file mode 100644 index 0000000000..4079597a0f --- /dev/null +++ b/tests/nimble_statconn_gnrc_ext/Makefile.ci @@ -0,0 +1,4 @@ +BOARD_INSUFFICIENT_MEMORY := \ + e104-bt5010a-tb \ + e104-bt5011a-tb \ + # diff --git a/tests/nimble_statconn_gnrc_ext/main.c b/tests/nimble_statconn_gnrc_ext/main.c new file mode 100644 index 0000000000..ffc45a567f --- /dev/null +++ b/tests/nimble_statconn_gnrc_ext/main.c @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2020 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup examples + * @{ + * + * @file + * @brief Run IP-over-BLE using the 'statconn' BLE connection manager + * + * @author Hauke Petersen + * + * @} + */ + +#include + +#include "shell.h" +#include "msg.h" +#include "nimble_statconn.h" +#include "net/bluetil/addr.h" + +#define MAIN_QUEUE_SIZE (8) +static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; + +static void _print_evt(const char *msg, int handle, const uint8_t *addr) +{ + printf("[ble] %s (%i|", msg, handle); + if (addr) { + bluetil_addr_print(addr); + } + else { + printf("n/a"); + } + puts(")"); +} + +static void _on_ble_evt(int handle, nimble_netif_event_t event, + const uint8_t *addr) +{ + switch (event) { + case NIMBLE_NETIF_CONNECTED_MASTER: + _print_evt("CONNECTED master", handle, addr); + break; + case NIMBLE_NETIF_CONNECTED_SLAVE: + _print_evt("CONNECTED slave", handle, addr); + break; + case NIMBLE_NETIF_CLOSED_MASTER: + _print_evt("CLOSED master", handle, addr); + break; + case NIMBLE_NETIF_CLOSED_SLAVE: + _print_evt("CLOSED slave", handle, addr); + break; + case NIMBLE_NETIF_CONN_UPDATED: + _print_evt("UPDATED", handle, addr); + break; + default: + /* do nothing */ + return; + } +} + +int main(void) +{ + puts("IPv6-over-BLE with statconn BLE connection manager"); + + /* we need a message queue for the thread running the shell in order to + * receive potentially fast incoming networking packets */ + msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE); + + /* register for BLE events */ + nimble_statconn_eventcb(_on_ble_evt); + + /* start shell */ + puts("All up, running the shell now"); + char line_buf[SHELL_DEFAULT_BUFSIZE]; + shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); + + /* should never be reached */ + return 0; +} diff --git a/tests/phydat_dump/main.c b/tests/phydat_dump/main.c index b0c73f04a9..8ce6d1ff22 100644 --- a/tests/phydat_dump/main.c +++ b/tests/phydat_dump/main.c @@ -45,6 +45,7 @@ _phydat_test_t _test_vector[] = { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_V, .scale = 6 } }, { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_W, .scale = 7 } }, { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_GS, .scale = -1 } }, + { .dim = 3, .dat = { .val = { 123, 456, 789 }, .unit = UNIT_T, .scale = -9 } }, { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_DBM, .scale = -3 } }, { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_COULOMB, .scale = 0 } }, { .dim = 1, .dat = { .val = { 12345 }, .unit = UNIT_F, .scale = -6 } }, diff --git a/tests/phydat_dump/tests/01-run.py b/tests/phydat_dump/tests/01-run.py index 39a781702f..670c589e06 100755 --- a/tests/phydat_dump/tests/01-run.py +++ b/tests/phydat_dump/tests/01-run.py @@ -44,6 +44,9 @@ def testfunc(child): child.expect(r'Data:\t 12345 MV\r\n') child.expect(r'Data:\t 12345e7 W\r\n') child.expect(r'Data:\t 1234.5 Gs\r\n') + child.expect(r'Data:\t\[0\] 123 nT\r\n') + child.expect(r'\t\[1\] 456 nT\r\n') + child.expect(r'\t\[2\] 789 nT\r\n') child.expect(r'Data:\t 12.345 dBm\r\n') child.expect(r'Data:\t 12345 C\r\n') child.expect(r'Data:\t 12345 uF\r\n') diff --git a/tests/pkg_edhoc_c/Makefile b/tests/pkg_edhoc_c/Makefile index 657147abe8..4fd47ac3c6 100644 --- a/tests/pkg_edhoc_c/Makefile +++ b/tests/pkg_edhoc_c/Makefile @@ -6,6 +6,9 @@ BOARD_WHITELIST += $(BOARD_PROVIDES_NETIF) # open(/dev/net/tun): No such file or directory TEST_ON_CI_BLACKLIST += native +# Test fails pretty regularly on CI +TEST_ON_CI_BLACKLIST += esp32-wroom-32 + # Edhoc related packages USEPKG += edhoc-c USEMODULE += edhoc-c_crypto_tinycrypt diff --git a/tests/pkg_mbedtls/Makefile b/tests/pkg_mbedtls/Makefile index 5634c3938c..033d86178a 100644 --- a/tests/pkg_mbedtls/Makefile +++ b/tests/pkg_mbedtls/Makefile @@ -3,6 +3,9 @@ include ../Makefile.tests_common USEPKG += mbedtls USEMODULE += mbedtls_entropy +# entropy test keeps failing on this board due to low entropy +TEST_ON_CI_BLACKLIST += samr21-xpro + # Increase stack size of main thread. CFLAGS += -DTHREAD_STACKSIZE_MAIN=THREAD_STACKSIZE_LARGE diff --git a/tests/sched_change_priority/Makefile b/tests/sched_change_priority/Makefile new file mode 100644 index 0000000000..a39f492c4a --- /dev/null +++ b/tests/sched_change_priority/Makefile @@ -0,0 +1,13 @@ +include ../Makefile.tests_common + +USEMODULE += nice +USEMODULE += ps +USEMODULE += shell +USEMODULE += shell_commands + +# Use a terminal that does not introduce extra characters into the stream. +RIOT_TERMINAL ?= socat + +APP_SHELL_FMT ?= NONE + +include $(RIOTBASE)/Makefile.include diff --git a/tests/sched_change_priority/Makefile.ci b/tests/sched_change_priority/Makefile.ci new file mode 100644 index 0000000000..b5de876337 --- /dev/null +++ b/tests/sched_change_priority/Makefile.ci @@ -0,0 +1,9 @@ +BOARD_INSUFFICIENT_MEMORY := \ + arduino-duemilanove \ + arduino-leonardo \ + arduino-nano \ + arduino-uno \ + atmega328p \ + atmega328p-xplained-mini \ + nucleo-l011k4 \ + # diff --git a/tests/sched_change_priority/main.c b/tests/sched_change_priority/main.c new file mode 100644 index 0000000000..68a9dd7a6e --- /dev/null +++ b/tests/sched_change_priority/main.c @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2019 Otto-von-Guericke-Universität Magdeburg + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief Test application for sched_change_priority / nice + * + * @author Marian Buschsieweke + * + * @} + */ + +#include +#include + +#include "architecture.h" +#include "sched.h" +#include "shell.h" +#include "shell_commands.h" +#include "thread.h" + +static int sc_hint(int argc, char **argv); + +static WORD_ALIGNED char t2_stack[THREAD_STACKSIZE_TINY]; +static WORD_ALIGNED char t3_stack[THREAD_STACKSIZE_DEFAULT]; +static kernel_pid_t t3_pid; + +static const shell_command_t cmds[] = { + { "hint", "Display the correct invocation of nice for this teset", sc_hint }, + { NULL, NULL, NULL } +}; + +/* + * Note: An extra shell command just for displaying this hint is very much of + * an overkill for a human being, especially since the ps command already + * provides all the details. However, for automatic testing this makes it + * easy to extract the pid of t3 and the numeric value of + * THREAD_PRIORITY_MAIN - 1, resulting in more robust automatic testing. + * A shell command also has the convenient side effect of synchronizing + * with the shell. + */ +static int sc_hint(int argc, char **argv) +{ + (void)argc; + (void)argv; + + printf("Run \"nice %" PRIkernel_pid " %u\"\n", + t3_pid, (unsigned)THREAD_PRIORITY_MAIN - 1); + + return EXIT_SUCCESS; +} + +static void *t2_func(void *unused) +{ + (void)unused; + + while (1) { + /* blocking t3 from running with busy loop while t3 has lower prio than me */ + } + + return NULL; +} + +static void *t3_func(void *unused) +{ + (void)unused; + + while (1) { + uint8_t prio = THREAD_PRIORITY_MAIN + 2; + printf("[t3] Setting my priority to THREAD_PRIORITY_MAIN + 2 = %u\n", + (unsigned)prio); + sched_change_priority(thread_get_active(), prio); + puts("[t3] Running again."); + } + + return NULL; +} + +int main(void) +{ + thread_create(t2_stack, sizeof(t2_stack), THREAD_PRIORITY_MAIN + 1, + THREAD_CREATE_STACKTEST, t2_func, NULL, "t2"); + + t3_pid = thread_create(t3_stack, sizeof(t3_stack), THREAD_PRIORITY_MAIN - 1, + THREAD_CREATE_STACKTEST, t3_func, NULL, "t3"); + + puts("[main] Use shell command \"nice\" to increase prio of t3.\n" + "[main] If it works, it will run again. The \"hint\" cmd can be useful."); + + char line_buf[SHELL_DEFAULT_BUFSIZE]; + shell_run(cmds, line_buf, SHELL_DEFAULT_BUFSIZE); + + return 0; +} diff --git a/tests/sched_change_priority/tests/01-run.py b/tests/sched_change_priority/tests/01-run.py new file mode 100755 index 0000000000..c6ebaf4aee --- /dev/null +++ b/tests/sched_change_priority/tests/01-run.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 + +import sys +from testrunner import run + + +def testfunc(child): + child.sendline("hint") + child.expect(r"Run \"nice (\d+) (\d+)\"\r\n") + pid = int(child.match.group(1)) + prio = int(child.match.group(2)) + child.sendline("nice {} {}".format(pid, prio)) + child.expect_exact('[t3] Running again.') + + +if __name__ == "__main__": + sys.exit(run(testfunc)) diff --git a/tests/shell/tests/01-run.py b/tests/shell/tests/01-run.py index a4b423ad8d..86bf96e43b 100755 --- a/tests/shell/tests/01-run.py +++ b/tests/shell/tests/01-run.py @@ -32,6 +32,8 @@ EXPECTED_PS = ( RIOT_TERMINAL = os.environ.get('RIOT_TERMINAL') CLEANTERMS = {"socat"} +TESTRUNNER_SHELL_SKIP_REBOOT = bool(int(os.environ.get('TESTRUNNER_SHELL_SKIP_REBOOT') or 0)) + # In native we are directly executing the binary (no terminal program). We must # therefore use Ctrl-V (DLE or "data link escape") before Ctrl-C to send a # literal ETX instead of SIGINT. @@ -220,6 +222,10 @@ def testfunc(child): # loop other defined commands and expected output for cmd, expected in CMDS: + + if cmd == "reboot" and TESTRUNNER_SHELL_SKIP_REBOOT: + continue + check_cmd(child, cmd, expected) if RIOT_TERMINAL in CLEANTERMS: diff --git a/tests/shell_ble/Makefile b/tests/shell_ble/Makefile new file mode 100644 index 0000000000..652e0d0e05 --- /dev/null +++ b/tests/shell_ble/Makefile @@ -0,0 +1,42 @@ +DEVELHELP = 0 +BOARD ?= nrf52dk +include ../Makefile.tests_common + +USEMODULE += app_metadata +USEMODULE += shell +USEMODULE += shell_commands +USEMODULE += ps + +USEMODULE += stdio_nimble stdio_nimble_debug +USEMODULE += nimble_autoadv +CFLAGS += -DNIMBLE_AUTOADV_DEVICE_NAME='"tests/shell_ble"' + +TESTRUNNER_SHELL_SKIP_REBOOT = 1 +TESTRUNNER_RESET_BOARD_ON_STARTUP = 0 + +ifneq (,$(filter term,$(MAKECMDGOALS))) + # for z1, socat doesn't work (unknown reason) + ifeq (z1, $(BOARD)) + RIOT_TERMINAL ?= pyterm + endif + + # Use a terminal that does not introduce extra characters into the stream. + RIOT_TERMINAL ?= socat +else ifneq (,$(filter test,$(MAKECMDGOALS))) + # Use the virtual serial port created by ble-serial + RIOT_TERMINAL = picocom +endif + +# The test requires some setup so it cannot currently be run +TEST_ON_CI_BLACKLIST += all + +APP_SHELL_FMT ?= NONE + +include $(RIOTBASE)/Makefile.include + +# the test script skips tests if socat is not used +$(call target-export-variables,$(RIOT_TERMINAL),RIOT_TERMINAL) + +# a reboot or a reset would disconnect the device from bluetooth and break the test +$(call target-export-variables,$(TESTRUNNER_SHELL_SKIP_REBOOT),TESTRUNNER_SHELL_SKIP_REBOOT) +$(call target-export-variables,$(TESTRUNNER_RESET_BOARD_ON_STARTUP),TESTRUNNER_RESET_BOARD_ON_STARTUP) diff --git a/tests/shell_ble/README.md b/tests/shell_ble/README.md new file mode 100644 index 0000000000..b5e694e2bb --- /dev/null +++ b/tests/shell_ble/README.md @@ -0,0 +1,22 @@ +This is basically the same tests as for the normal shell, but here we are +testing via blueooth instead of UART. You have to set up a virtual serial port +manually. + +For instructions on how to open a virtual serial port to your bluetooth device +see `sys/stdio_nimble/README`. + +**Note:** `make term` and `make test-with-config` will open two different types of terminals. +- When calling `make term` then a terminal will communicate with the board +via UART. Due to the nature of `stdio_nimble` the board won't respond to input +coming from here) +- When calling `make test-with-config` then picocom will communicate with the board via the +given virtual serial port + +So a procedure to run this test could be: +0. Make sure that the current test application instance is fresh and no test was +run on it before. Otherwise your test might fail, because the test case +`check_control_d` only works once per run. +1. Execute `make flash term` +2. Open a virtual serial port with `ble-serial` and note the virtual serial port +that was created (search for `Slave created on /tmp/dev_riot_ble -> /dev/pts/25`) +3. Execute `PORT=/dev/pts/25 make test-with-config` diff --git a/tests/shell_ble/main.c b/tests/shell_ble/main.c new file mode 120000 index 0000000000..c541a5892a --- /dev/null +++ b/tests/shell_ble/main.c @@ -0,0 +1 @@ +../shell/main.c \ No newline at end of file diff --git a/tests/shell_ble/tests-with-config/01-run.py b/tests/shell_ble/tests-with-config/01-run.py new file mode 120000 index 0000000000..b3e9bd6b21 --- /dev/null +++ b/tests/shell_ble/tests-with-config/01-run.py @@ -0,0 +1 @@ +../../shell/tests/01-run.py \ No newline at end of file diff --git a/tests/sys_fido2_ctap/app.config.test b/tests/sys_fido2_ctap/app.config.test new file mode 100644 index 0000000000..5d3f10b646 --- /dev/null +++ b/tests/sys_fido2_ctap/app.config.test @@ -0,0 +1,13 @@ +CONFIG_MODULE_AUTO_INIT_USBUS=n +CONFIG_MODULE_USBUS=y +CONFIG_MODULE_FIDO2=y +CONFIG_MODULE_FIDO2_CTAP=y +CONFIG_MODULE_FIDO2_CTAP_TRANSPORT=y +CONFIG_MODULE_FIDO2_CTAP_TRANSPORT_HID=y + +CONFIG_PACKAGE_FIDO2_TESTS=y + +# Should be autoselecting the MODULE_PRNG_HWRNG if possible +# Since the makefile cannot we have to override until end of migration +# Remove when TEST_KCONFIG is complete +CONFIG_MODULE_PRNG_MUSL_LCG=y diff --git a/tests/unittests/tests-phydat/tests-phydat.c b/tests/unittests/tests-phydat/tests-phydat.c index de5cce7408..504f029db5 100644 --- a/tests/unittests/tests-phydat/tests-phydat.c +++ b/tests/unittests/tests-phydat/tests-phydat.c @@ -212,6 +212,7 @@ static void test_unitstr__success(void) TEST_ASSERT_EQUAL_STRING("W", phydat_unit_to_str_verbose(UNIT_W)); TEST_ASSERT_EQUAL_STRING("dBm", phydat_unit_to_str_verbose(UNIT_DBM)); TEST_ASSERT_EQUAL_STRING("Gs", phydat_unit_to_str_verbose(UNIT_GS)); + TEST_ASSERT_EQUAL_STRING("T", phydat_unit_to_str_verbose(UNIT_T)); TEST_ASSERT_EQUAL_STRING("Bar", phydat_unit_to_str_verbose(UNIT_BAR)); TEST_ASSERT_EQUAL_STRING("Pa", phydat_unit_to_str_verbose(UNIT_PA)); TEST_ASSERT_EQUAL_STRING("permille", phydat_unit_to_str_verbose(UNIT_PERMILL)); diff --git a/tests/xtimer_rmutex_lock_timeout/main.c b/tests/xtimer_rmutex_lock_timeout/main.c index 8cac5b0fda..35ad64e51e 100644 --- a/tests/xtimer_rmutex_lock_timeout/main.c +++ b/tests/xtimer_rmutex_lock_timeout/main.c @@ -20,11 +20,13 @@ #include #include -#include "shell.h" -#include "xtimer.h" -#include "thread.h" -#include "msg.h" + +#include "atomic_utils.h" #include "irq.h" +#include "msg.h" +#include "shell.h" +#include "thread.h" +#include "xtimer.h" /* XTIMER_SHIFT can be undefined when using xtimer_on_ztimer on boards * incompatible with xtimers tick conversion, e.g. the waspmote-pro @@ -155,8 +157,7 @@ static int cmd_test_xtimer_rmutex_lock_timeout_long_unlocked(int argc, if (xtimer_rmutex_lock_timeout(&test_rmutex, LONG_RMUTEX_TIMEOUT) == 0) { /* rmutex has to be locked once */ - if (atomic_load_explicit(&test_rmutex.owner, - memory_order_relaxed) == thread_getpid() && + if (atomic_load_kernel_pid(&test_rmutex.owner) == thread_getpid() && test_rmutex.refcount == 1 && mutex_trylock(&test_rmutex.mutex) == 0) { puts("OK"); @@ -209,8 +210,7 @@ static int cmd_test_xtimer_rmutex_lock_timeout_long_locked(int argc, } else { /* rmutex has to be locked once */ - if (atomic_load_explicit(&test_rmutex.owner, - memory_order_relaxed) == second_t_pid && + if (atomic_load_kernel_pid(&test_rmutex.owner) == second_t_pid && test_rmutex.refcount == 1 && mutex_trylock(&test_rmutex.mutex) == 0) { puts("OK"); @@ -261,8 +261,7 @@ static int cmd_test_xtimer_rmutex_lock_timeout_low_prio_thread( if (xtimer_rmutex_lock_timeout(&test_rmutex, LONG_RMUTEX_TIMEOUT) == 0) { /* rmutex has to be locked once */ - if (atomic_load_explicit(&test_rmutex.owner, - memory_order_relaxed) == thread_getpid() && + if (atomic_load_kernel_pid(&test_rmutex.owner) == thread_getpid() && test_rmutex.refcount == 1 && mutex_trylock(&test_rmutex.mutex) == 0) { puts("OK"); @@ -317,8 +316,7 @@ static int cmd_test_xtimer_rmutex_lock_timeout_short_locked(int argc, } else { /* rmutex has to be locked once */ - if (atomic_load_explicit(&test_rmutex.owner, - memory_order_relaxed) == second_t_pid && + if (atomic_load_kernel_pid(&test_rmutex.owner) == second_t_pid && test_rmutex.refcount == 1 && mutex_trylock(&test_rmutex.mutex) == 0) { puts("OK"); @@ -355,8 +353,7 @@ static int cmd_test_xtimer_rmutex_lock_timeout_short_unlocked(int argc, if (xtimer_rmutex_lock_timeout(&test_rmutex, SHORT_RMUTEX_TIMEOUT) == 0) { /* rmutex has to be locked once */ - if (atomic_load_explicit(&test_rmutex.owner, - memory_order_relaxed) == thread_getpid() && + if (atomic_load_kernel_pid(&test_rmutex.owner) == thread_getpid() && test_rmutex.refcount == 1 && mutex_trylock(&test_rmutex.mutex) == 0) { puts("OK"); diff --git a/tests/ztimer_rmutex_lock_timeout/main.c b/tests/ztimer_rmutex_lock_timeout/main.c index 48c6bf49d7..fb063c53e4 100644 --- a/tests/ztimer_rmutex_lock_timeout/main.c +++ b/tests/ztimer_rmutex_lock_timeout/main.c @@ -20,11 +20,13 @@ #include #include -#include "shell.h" -#include "ztimer.h" -#include "thread.h" -#include "msg.h" + +#include "atomic_utils.h" #include "irq.h" +#include "msg.h" +#include "shell.h" +#include "thread.h" +#include "ztimer.h" /* timeout at one millisecond (1000 us) to make sure it does not spin. */ #define LONG_RMUTEX_TIMEOUT 1000 @@ -148,8 +150,7 @@ static int cmd_test_ztimer_rmutex_lock_timeout_long_unlocked(int argc, if (ztimer_rmutex_lock_timeout(ZTIMER_USEC, &test_rmutex, LONG_RMUTEX_TIMEOUT) == 0) { /* rmutex has to be locked once */ - if (atomic_load_explicit(&test_rmutex.owner, - memory_order_relaxed) == thread_getpid() && + if (atomic_load_kernel_pid(&test_rmutex.owner) == thread_getpid() && test_rmutex.refcount == 1 && mutex_trylock(&test_rmutex.mutex) == 0) { puts("OK"); @@ -202,8 +203,7 @@ static int cmd_test_ztimer_rmutex_lock_timeout_long_locked(int argc, } else { /* rmutex has to be locked once */ - if (atomic_load_explicit(&test_rmutex.owner, - memory_order_relaxed) == second_t_pid && + if (atomic_load_kernel_pid(&test_rmutex.owner) == second_t_pid && test_rmutex.refcount == 1 && mutex_trylock(&test_rmutex.mutex) == 0) { puts("OK"); @@ -254,8 +254,7 @@ static int cmd_test_ztimer_rmutex_lock_timeout_low_prio_thread( if (ztimer_rmutex_lock_timeout(ZTIMER_USEC, &test_rmutex, LONG_RMUTEX_TIMEOUT) == 0) { /* rmutex has to be locked once */ - if (atomic_load_explicit(&test_rmutex.owner, - memory_order_relaxed) == thread_getpid() && + if (atomic_load_kernel_pid(&test_rmutex.owner) == thread_getpid() && test_rmutex.refcount == 1 && mutex_trylock(&test_rmutex.mutex) == 0) { puts("OK"); @@ -310,8 +309,7 @@ static int cmd_test_ztimer_rmutex_lock_timeout_short_locked(int argc, } else { /* rmutex has to be locked once */ - if (atomic_load_explicit(&test_rmutex.owner, - memory_order_relaxed) == second_t_pid && + if (atomic_load_kernel_pid(&test_rmutex.owner) == second_t_pid && test_rmutex.refcount == 1 && mutex_trylock(&test_rmutex.mutex) == 0) { puts("OK"); @@ -348,8 +346,7 @@ static int cmd_test_ztimer_rmutex_lock_timeout_short_unlocked(int argc, if (ztimer_rmutex_lock_timeout(ZTIMER_USEC, &test_rmutex, SHORT_RMUTEX_TIMEOUT) == 0) { /* rmutex has to be locked once */ - if (atomic_load_explicit(&test_rmutex.owner, - memory_order_relaxed) == thread_getpid() && + if (atomic_load_kernel_pid(&test_rmutex.owner) == thread_getpid() && test_rmutex.refcount == 1 && mutex_trylock(&test_rmutex.mutex) == 0) { puts("OK");