diff --git a/Makefile.include b/Makefile.include index 1838f5a6a5500..993edd8e34136 100644 --- a/Makefile.include +++ b/Makefile.include @@ -493,7 +493,7 @@ ifneq ($(RIOT_CI_BUILD),1) ifneq (iotlab,$(PROGRAMMER)) ifneq (,$(PROGRAMMERS_SUPPORTED)) ifeq (,$(filter $(PROGRAMMER),$(PROGRAMMERS_SUPPORTED))) - $(info '$(PROGRAMMER)' programmer is not supported by this board. \ + $(warning '$(PROGRAMMER)' programmer is not supported by this board. \ Supported programmers: '$(PROGRAMMERS_SUPPORTED)') endif endif @@ -523,10 +523,6 @@ include $(RIOTMAKE)/ubsan.inc.mk # For more information, see http://petereisentraut.blogspot.com/2011/09/ccache-and-clang-part-2.html export CCACHE_CPP2=yes -ifeq ($(strip $(MCU)),) - MCU = $(CPU) -endif - # set some settings useful for continuous integration builds ifeq ($(RIOT_CI_BUILD),1) RIOT_VERSION ?= buildtest @@ -548,11 +544,9 @@ endif # if you want to publish the board into the sources as an uppercase #define BOARDDEF = $(call uppercase_and_underscore,$(BOARD)) CPUDEF = $(call uppercase_and_underscore,$(CPU)) -MCUDEF = $(call uppercase_and_underscore,$(MCU)) CFLAGS += -DRIOT_APPLICATION=\"$(APPLICATION)\" CFLAGS += -DBOARD_$(BOARDDEF)=\"$(BOARD)\" -DRIOT_BOARD=BOARD_$(BOARDDEF) CFLAGS += -DCPU_$(CPUDEF)=\"$(CPU)\" -DRIOT_CPU=CPU_$(CPUDEF) -CFLAGS += -DMCU_$(MCUDEF)=\"$(MCU)\" -DRIOT_MCU=MCU_$(MCUDEF) # Feature test default CFLAGS and LINKFLAGS for the set compiled. include $(RIOTMAKE)/cflags.inc.mk @@ -812,7 +806,7 @@ endif $(call check_cmd,$(CC),Compiler) ..build-message: $(if $(SHOULD_RUN_KCONFIG), check-kconfig-errors) - @$(COLOR_ECHO) '$(COLOR_GREEN)Building application "$(APPLICATION)" for "$(BOARD)" with MCU "$(MCU)".$(COLOR_RESET)' + @$(COLOR_ECHO) '$(COLOR_GREEN)Building application "$(APPLICATION)" for "$(BOARD)" with CPU "$(CPU)".$(COLOR_RESET)' @$(COLOR_ECHO) # The `clean` needs to be serialized before everything else. diff --git a/README.md b/README.md index 14b1c4ee061f6..374e2ee28d965 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ indirect business models around the free open-source software platform provided by RIOT, e.g. it is possible to link closed-source code with the LGPL code. -## FEATURES +## Features RIOT provides features including, but not limited to: @@ -81,7 +81,7 @@ RIOT provides features including, but not limited to: * UWB * Bluetooth (BLE) via [NimBLE](https://github.com/apache/mynewt-nimble) -## GETTING RIOT +## Getting RIOT The most convenient way to get RIOT is to clone it via Git @@ -106,7 +106,7 @@ For more details on our release cycle, check our [documentation][release cycle]. [releases]: https://github.com/RIOT-OS/RIOT/releases [release cycle]: https://doc.riot-os.org/release-cycle.html -## GETTING STARTED +## Getting Started * You want to start the RIOT? Just follow our [quickstart guide](https://doc.riot-os.org/index.html#the-quickest-start) or try this @@ -117,23 +117,23 @@ For specific toolchain installation, follow instructions in the version of the documentation is uploaded daily to [doc.riot-os.org](https://doc.riot-os.org). -## FORUM +## Forum Do you have a question, want to discuss a new feature, or just want to present your latest project using RIOT? Come over to our [forum] and post to your hearts content. [forum]: https://forum.riot-os.org -## CONTRIBUTE +## Contribute To contribute something to RIOT, please refer to our [contributing document](CONTRIBUTING.md). -## MAILING LISTS +## Mailing Lists * RIOT commits: [commits@riot-os.org](https://lists.riot-os.org/mailman/listinfo/commits) * Github notifications: [notifications@riot-os.org](https://lists.riot-os.org/mailman/listinfo/notifications) -## LICENSE +## License * Most of 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. diff --git a/boards/common/makefiles/stdio_cdc_acm.dep.mk b/boards/common/makefiles/stdio_cdc_acm.dep.mk index 140bf7114a08b..1bbdcdf911a2e 100644 --- a/boards/common/makefiles/stdio_cdc_acm.dep.mk +++ b/boards/common/makefiles/stdio_cdc_acm.dep.mk @@ -1,5 +1,5 @@ ifeq (,$(filter-out stdio_cdc_acm,$(filter stdio_% slipdev_stdio,$(USEMODULE)))) - ifneq (,$(filter tinyusb_device,$(USEMODULE))) + ifneq (,$(filter tinyusb_device,$(USEMODULE))$(filter tinyusb,$(USEPKG))) # Use stdio_tinyusb_cdc_acm only if no other stdio is requested explicitly # and tinyusb_device is used for any other reason USEMODULE += stdio_tinyusb_cdc_acm diff --git a/core/lib/init.c b/core/lib/init.c index d45ddc15c87bb..6b3cccd3e4beb 100644 --- a/core/lib/init.c +++ b/core/lib/init.c @@ -90,6 +90,13 @@ static void *idle_thread(void *arg) void kernel_init(void) { + if (!IS_USED(MODULE_CORE_THREAD)) { + /* RIOT without threads */ + main_trampoline(NULL); + while (1) {} + return; + } + irq_disable(); if (IS_USED(MODULE_CORE_IDLE_THREAD)) { @@ -99,19 +106,10 @@ void kernel_init(void) idle_thread, NULL, "idle"); } - if (IS_USED(MODULE_CORE_THREAD)) { - thread_create(main_stack, sizeof(main_stack), - THREAD_PRIORITY_MAIN, - THREAD_CREATE_WOUT_YIELD | THREAD_CREATE_STACKTEST, - main_trampoline, NULL, "main"); - } - else { - /* RIOT without threads */ - irq_enable(); - main_trampoline(NULL); - while (1) {} - return; - } + thread_create(main_stack, sizeof(main_stack), + THREAD_PRIORITY_MAIN, + THREAD_CREATE_WOUT_YIELD | THREAD_CREATE_STACKTEST, + main_trampoline, NULL, "main"); cpu_switch_context_exit(); } diff --git a/cpu/esp8266/startup.c b/cpu/esp8266/startup.c index 113bb04214457..ef809cf104d91 100644 --- a/cpu/esp8266/startup.c +++ b/cpu/esp8266/startup.c @@ -66,7 +66,7 @@ void esp_riot_init(void) /* initialize the ISR stack for usage measurements */ thread_isr_stack_init(); -#ifndef MCU_ESP8266 +#ifndef CPU_ESP8266 /* initialize newlib system calls */ syscalls_init (); #endif diff --git a/cpu/esp_common/esp-now/esp_now_netdev.c b/cpu/esp_common/esp-now/esp_now_netdev.c index 428881953a0af..881f4d7b1b4b7 100644 --- a/cpu/esp_common/esp-now/esp_now_netdev.c +++ b/cpu/esp_common/esp-now/esp_now_netdev.c @@ -28,7 +28,7 @@ #include "esp_common.h" #include "esp_attr.h" -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 #include "esp_event_loop.h" #else #include "esp_event.h" @@ -314,11 +314,11 @@ esp_now_netdev_t *netdev_esp_now_setup(void) /* set the event handler */ esp_system_event_add_handler(_esp_system_event_handler, NULL); -#ifdef MCU_ESP32 +#ifdef CPU_ESP32 /* init the WiFi driver */ extern portMUX_TYPE g_intr_lock_mux; mutex_init(&g_intr_lock_mux); -#endif /* MCU_ESP32 */ +#endif /* CPU_ESP32 */ esp_err_t result; diff --git a/cpu/esp_common/esp-wifi/esp_wifi_netdev.c b/cpu/esp_common/esp-wifi/esp_wifi_netdev.c index c84e0d03827dd..4c65968d94a7c 100644 --- a/cpu/esp_common/esp-wifi/esp_wifi_netdev.c +++ b/cpu/esp_common/esp-wifi/esp_wifi_netdev.c @@ -28,7 +28,7 @@ #include "esp_common.h" #include "esp_attr.h" -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 #include "esp_event_loop.h" #else #include "esp_event.h" @@ -38,7 +38,7 @@ #endif #include "esp_system.h" #include "esp_wifi.h" -#ifndef MCU_ESP8266 +#ifndef CPU_ESP8266 #include "esp_private/wifi.h" #endif #include "irq_arch.h" @@ -71,7 +71,7 @@ #define MAC_STR "%02x:%02x:%02x:%02x:%02x:%02x" #define MAC_STR_ARG(m) m[0], m[1], m[2], m[3], m[4], m[5] -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 #include "esp_socket.h" #include "net/sockio.h" @@ -99,7 +99,7 @@ #include "lwip/pbuf.h" -#endif /* MCU_ESP8266 */ +#endif /* CPU_ESP8266 */ #define ENABLE_DEBUG_HEXDUMP 0 #define ENABLE_DEBUG 0 @@ -123,7 +123,7 @@ static bool _esp_wifi_rx_in_progress = false; extern esp_err_t esp_system_event_add_handler (system_event_cb_t handler, void *arg); -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 /** * The low level WiFi driver function expects a lwIP pbuf data structure as @@ -302,9 +302,9 @@ esp_err_t esp_wifi_internal_reg_rxcb(wifi_interface_t ifx, wifi_rxcb_t fn) return ESP_OK; } -#endif /* MCU_ESP8266 */ +#endif /* CPU_ESP8266 */ -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 /* Prolog for source code compatibility with ESP-IDF for ESP32 */ static int _esp_wifi_rx_cb(struct esp_aio *aio) @@ -315,11 +315,11 @@ static int _esp_wifi_rx_cb(struct esp_aio *aio) const char *buffer = aio->pbuf; uint16_t len = aio->len; -#else /* MCU_ESP8266 */ +#else /* CPU_ESP8266 */ esp_err_t _esp_wifi_rx_cb(void *buffer, uint16_t len, void *eb) { -#endif /* MCU_ESP8266 */ +#endif /* CPU_ESP8266 */ /* * This callback function is not executed in interrupt context but in the @@ -666,7 +666,7 @@ static int _esp_wifi_send(netdev_t *netdev, const iolist_t *iolist) /* send the the packet to the peer(s) mac address */ if (esp_wifi_internal_tx(WIFI_IF_STA, dev->tx_buf, dev->tx_len) == ESP_OK) { #endif -#ifndef MCU_ESP8266 +#ifndef CPU_ESP8266 /* for ESP8266 it is done in _esp_wifi_tx_cb */ _esp_wifi_send_is_in = false; netdev->event_callback(netdev, NETDEV_EVENT_TX_COMPLETE); @@ -860,7 +860,7 @@ static wifi_config_t wifi_config_sta = { }; #endif /* MODULE_ESP_WIFI_AP */ -#if (defined(MCU_ESP8266) && !defined(MODULE_ESP_NOW)) || defined(MODULE_ESP_WIFI_AP) +#if (defined(CPU_ESP8266) && !defined(MODULE_ESP_NOW)) || defined(MODULE_ESP_WIFI_AP) /** * Static configuration for the SoftAP interface if ESP-NOW is not enabled. * @@ -901,7 +901,7 @@ static wifi_config_t wifi_config_ap = { #endif } }; -#endif /* (defined(MCU_ESP8266) && !defined(MODULE_ESP_NOW)) || defined(MODULE_ESP_WIFI_AP) */ +#endif /* (defined(CPU_ESP8266) && !defined(MODULE_ESP_NOW)) || defined(MODULE_ESP_WIFI_AP) */ void esp_wifi_setup (esp_wifi_netdev_t* dev) { @@ -922,7 +922,7 @@ void esp_wifi_setup (esp_wifi_netdev_t* dev) #ifndef MODULE_ESP_NOW /* if module esp_now is used, the following part is already done */ -#ifndef MCU_ESP8266 +#ifndef CPU_ESP8266 extern portMUX_TYPE g_intr_lock_mux; mutex_init(&g_intr_lock_mux); #endif @@ -949,7 +949,7 @@ void esp_wifi_setup (esp_wifi_netdev_t* dev) #ifdef MODULE_ESP_WIFI_AP /* Activate the SoftAP interface */ result = esp_wifi_set_mode(WIFI_MODE_AP); -#elif defined(MCU_ESP8266) +#elif defined(CPU_ESP8266) /* * Although only the Station interface is needed, the SoftAP interface must * also be enabled on ESP8266 for stability reasons to prevent the Station @@ -959,16 +959,16 @@ void esp_wifi_setup (esp_wifi_netdev_t* dev) */ /* activate the Station and the SoftAP interface */ result = esp_wifi_set_mode(WIFI_MODE_APSTA); -#else /* defined(MCU_ESP8266) */ +#else /* defined(CPU_ESP8266) */ /* activate only the Station interface */ result = esp_wifi_set_mode(WIFI_MODE_STA); -#endif /* defined(MCU_ESP8266) */ +#endif /* defined(CPU_ESP8266) */ if (result != ESP_OK) { ESP_WIFI_LOG_ERROR("esp_wifi_set_mode failed with return value %d", result); return; } -#if defined(MCU_ESP8266) || defined(MODULE_ESP_WIFI_AP) +#if defined(CPU_ESP8266) || defined(MODULE_ESP_WIFI_AP) #if IS_ACTIVE(ESP_WIFI_SSID_DYNAMIC) uint8_t mac[ETHERNET_ADDR_LEN]; esp_wifi_get_mac(WIFI_IF_AP, mac); @@ -982,7 +982,7 @@ void esp_wifi_setup (esp_wifi_netdev_t* dev) ESP_WIFI_LOG_ERROR("esp_wifi_set_config softap failed with return value %d", result); return; } -#endif /* defined(MCU_ESP8266) || defined(MODULE_ESP_WIFI_AP) */ +#endif /* defined(CPU_ESP8266) || defined(MODULE_ESP_WIFI_AP) */ #endif /* MODULE_ESP_NOW */ diff --git a/cpu/esp_common/esp-xtensa/thread_arch.c b/cpu/esp_common/esp-xtensa/thread_arch.c index ce1d3b579fb44..59ab91d57ba09 100644 --- a/cpu/esp_common/esp-xtensa/thread_arch.c +++ b/cpu/esp_common/esp-xtensa/thread_arch.c @@ -69,13 +69,13 @@ #define ENABLE_DEBUG 0 #include "debug.h" -#if defined(MCU_ESP32) +#if defined(CPU_ESP32) #include "soc/dport_access.h" #include "soc/dport_reg.h" -#elif defined(MCU_ESP8266) +#elif defined(CPU_ESP8266) #include "esp8266/rom_functions.h" #include "sdk/sdk.h" -#endif /* MCU_ESP32 */ +#endif /* CPU_ESP32 */ #include "esp/xtensa_ops.h" #include "xtensa/xtensa_context.h" @@ -215,7 +215,7 @@ char* thread_stack_init(thread_task_func_t task_func, void *arg, void *stack_sta return (char*)sp; } -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 extern int MacIsrSigPostDefHdl(void); unsigned int ets_soft_int_type = ETS_SOFT_INT_NONE; #endif @@ -227,7 +227,7 @@ unsigned int ets_soft_int_type = ETS_SOFT_INT_NONE; */ void IRAM_ATTR thread_yield_isr(void* arg) { -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 ETS_NMI_LOCK(); if (ets_soft_int_type == ETS_SOFT_INT_HDL_MAC) { @@ -281,7 +281,7 @@ void IRAM_ATTR thread_yield_higher(void) } #endif if (!irq_is_in()) { -#if defined(MCU_ESP8266) +#if defined(CPU_ESP8266) critical_enter(); ets_soft_int_type = ETS_SOFT_INT_YIELD; WSR(BIT(ETS_SOFT_INUM), interrupt); @@ -292,7 +292,7 @@ void IRAM_ATTR thread_yield_higher(void) #else /* generate the software interrupt to switch the context */ DPORT_WRITE_PERI_REG(SYSTEM_CPU_INTR_FROM_CPU_0_REG, SYSTEM_CPU_INTR_FROM_CPU_0); -#endif /* MCU_ESP8266 */ +#endif /* CPU_ESP8266 */ } else { /* set the context switch flag */ diff --git a/cpu/esp_common/esp_events.c b/cpu/esp_common/esp_events.c index d969f717bdcf4..831fd20dc294f 100644 --- a/cpu/esp_common/esp_events.c +++ b/cpu/esp_common/esp_events.c @@ -28,7 +28,7 @@ #include "log.h" #include "esp_attr.h" -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 #include "esp_event_loop.h" #else #include "esp_eth_com.h" @@ -91,7 +91,7 @@ esp_err_t esp_system_event_del_handler (system_event_cb_t handler) return ESP_OK; } -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 static esp_err_t esp_system_event_handler(void *ctx, system_event_t *event) { for (int i = 0; i < MAX_HANDLER_NUM; i++) { @@ -101,7 +101,7 @@ static esp_err_t esp_system_event_handler(void *ctx, system_event_t *event) } return ESP_OK; } -#else /* MCU_ESP8266 */ +#else /* CPU_ESP8266 */ /* The event loop API of newer ESP-IDF versions split system events into * different event bases types. For code compatibility, we have to map * new event base types to the former system events */ @@ -236,13 +236,13 @@ static void esp_system_event_handler(void* arg, } } } -#endif /* MCU_ESP8266 */ +#endif /* CPU_ESP8266 */ #endif /* IS_USED(MODULE_ESP_WIFI_ANY) || IS_USED(MODULE_ESP_ETH) */ void esp_event_handler_init(void) { #if IS_USED(MODULE_ESP_WIFI_ANY) || IS_USED(MODULE_ESP_ETH) -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 esp_event_loop_init(esp_system_event_handler, NULL); #else /* newer ESP-IDF versions use another event loop API that have to be used */ diff --git a/cpu/esp_common/freertos/task.c b/cpu/esp_common/freertos/task.c index 1914504f90f60..2c3c8b12a59bc 100644 --- a/cpu/esp_common/freertos/task.c +++ b/cpu/esp_common/freertos/task.c @@ -33,7 +33,7 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 #include "rom/ets_sys.h" #endif @@ -231,12 +231,12 @@ TickType_t xTaskGetTickCount (void) void vTaskEnterCritical( portMUX_TYPE *mux ) { -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 /* we have to return on NMI */ if (NMIIrqIsOn) { return; } -#endif /* MCU_ESP8266 */ +#endif /* CPU_ESP8266 */ /* disable interrupts */ uint32_t state = irq_disable(); @@ -268,12 +268,12 @@ void vTaskEnterCritical( portMUX_TYPE *mux ) void vTaskExitCritical( portMUX_TYPE *mux ) { -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 /* we have to return on NMI */ if (NMIIrqIsOn) { return; } -#endif /* MCU_ESP8266 */ +#endif /* CPU_ESP8266 */ /* determine calling thread pid (can't fail) */ kernel_pid_t my_pid = thread_getpid(); diff --git a/cpu/esp_common/include/esp_common.h b/cpu/esp_common/include/esp_common.h index 6b3d9beafccf2..931cdadd98df8 100644 --- a/cpu/esp_common/include/esp_common.h +++ b/cpu/esp_common/include/esp_common.h @@ -46,7 +46,7 @@ extern "C" { #define RTC_BSS_ATTR __attribute__((section(".rtc.bss"))) #endif -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 #ifndef RTC_DATA_ATTR #define RTC_DATA_ATTR __attribute__((section(".rtc.data"))) #endif @@ -98,7 +98,7 @@ extern "C" { * @brief function name mappings for source code compatibility with ESP8266 port * @{ */ -#ifdef MCU_ESP32 +#ifdef CPU_ESP32 #define system_get_cpu_freq ets_get_cpu_frequency #define system_update_cpu_freq ets_update_cpu_frequency #endif /* CPU_FAM_ESP32 */ diff --git a/cpu/esp_common/include/esp_common_log.h b/cpu/esp_common/include/esp_common_log.h index defdb8a316735..b8179feab1f49 100644 --- a/cpu/esp_common/include/esp_common_log.h +++ b/cpu/esp_common/include/esp_common_log.h @@ -126,7 +126,7 @@ extern int ets_printf(const char *fmt, ...); #define ESP_EARLY_LOGD(tag, format, ...) LOG_TAG_EARLY(LOG_DEBUG, D, tag, format "\n", ##__VA_ARGS__) #define ESP_EARLY_LOGV(tag, format, ...) LOG_TAG_EARLY(LOG_ALL, V, tag, format "\n", ##__VA_ARGS__) -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 #define ESP_LOGE(tag, format, ...) LOG_TAG(LOG_ERROR, E, tag, format "\n", ##__VA_ARGS__) #define ESP_LOGW(tag, format, ...) LOG_TAG(LOG_WARNING, W, tag, format "\n", ##__VA_ARGS__) #define ESP_LOGI(tag, format, ...) LOG_TAG(LOG_INFO, I, tag, format "\n", ##__VA_ARGS__) diff --git a/cpu/esp_common/include/freertos/portmacro.h b/cpu/esp_common/include/freertos/portmacro.h index de946baf8cc40..6a7a74ad665eb 100644 --- a/cpu/esp_common/include/freertos/portmacro.h +++ b/cpu/esp_common/include/freertos/portmacro.h @@ -16,7 +16,7 @@ #include "stdbool.h" #include "stdint.h" -#ifndef MCU_ESP8266 +#ifndef CPU_ESP8266 #include "esp_heap_caps.h" #include "esp_timer.h" #endif diff --git a/cpu/esp_common/include/gpio_arch_common.h b/cpu/esp_common/include/gpio_arch_common.h index 3bdbed000b296..19dd77f20e2be 100644 --- a/cpu/esp_common/include/gpio_arch_common.h +++ b/cpu/esp_common/include/gpio_arch_common.h @@ -38,12 +38,12 @@ extern "C" { */ typedef enum { _GPIO = 0, /**< pin used as standard GPIO */ -#ifndef MCU_ESP8266 +#ifndef CPU_ESP8266 _ADC, /**< pin is used as ADC input */ _CAN, /**< pin is used as CAN signal */ _DAC, /**< pin is used as DAC output */ _EMAC, /**< pin is used as EMAC signal */ -#endif /* !MCU_ESP8266 */ +#endif /* !CPU_ESP8266 */ _I2C, /**< pin is used as I2C signal */ _PWM, /**< pin is used as PWM output */ _SPI, /**< pin is used as SPI interface */ diff --git a/cpu/esp_common/periph/flash.c b/cpu/esp_common/periph/flash.c index 6bb9daf9f0a09..d760b071295cc 100644 --- a/cpu/esp_common/periph/flash.c +++ b/cpu/esp_common/periph/flash.c @@ -33,7 +33,7 @@ #include "esp_partition.h" -#ifndef MCU_ESP8266 +#ifndef CPU_ESP8266 #include "esp_flash_partitions.h" #include "esp_spi_flash.h" @@ -41,13 +41,13 @@ #include "rom/spi_flash.h" #include "soc/soc.h" -#else /* !MCU_ESP8266 */ +#else /* !CPU_ESP8266 */ #include "esp_flash_data_types.h" #include "rom_functions.h" #include "spi_flash.h" -#endif /* !MCU_ESP8266 */ +#endif /* !CPU_ESP8266 */ #define ENABLE_DEBUG 0 #include "debug.h" @@ -68,7 +68,7 @@ MTD_XFA_ADD(_flash_dev, 0); VFS_AUTO_MOUNT(littlefs2, { .dev = &_flash_dev }, VFS_DEFAULT_NVM(0), 0); #endif -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 /* for source code compatibility with ESP32 SDK */ #define esp_rom_spiflash_chip_t esp_spi_flash_chip_t @@ -78,7 +78,7 @@ VFS_AUTO_MOUNT(littlefs2, { .dev = &_flash_dev }, VFS_DEFAULT_NVM(0), 0); extern esp_spi_flash_chip_t flashchip; extern uint32_t spi_flash_get_id(void); -#endif /* MCU_ESP8266 */ +#endif /* CPU_ESP8266 */ /* forward declaration of mtd functions */ static int _flash_init(mtd_dev_t *dev); @@ -94,7 +94,7 @@ static uint32_t _flash_size; /* resulting size of the flash drive in SPI flash * static esp_rom_spiflash_chip_t* _flashchip = NULL; -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 /* flash_id determines the flash size in kByte */ static const uint32_t flash_sizes[] = { 256, /* last byte of id is 0x12 */ @@ -114,7 +114,7 @@ void spi_flash_drive_init(void) _flashchip = &g_rom_flashchip; assert(_flashchip); -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 _flashchip->deviceId = spi_flash_get_id(); uint8_t devid_lb = _flashchip->deviceId >> 16 & 0xff; if (devid_lb >= 0x12 && devid_lb <= 0x18) { @@ -125,7 +125,7 @@ void spi_flash_drive_init(void) "4 MBytes are used as default size\n"); _flashchip->chip_size = 4 << 20; } -#endif /* MCU_ESP8266 */ +#endif /* CPU_ESP8266 */ _flash_driver.init = &_flash_init; _flash_driver.read = &_flash_read; @@ -164,13 +164,13 @@ void spi_flash_drive_init(void) } } -#ifndef MCU_ESP8266 +#ifndef CPU_ESP8266 /* map the partition top address to next higher multiple of 0x100000 (1 MB) */ part_top = (part_top + 0x100000) & ~0xfffff; -#else /* !MCU_ESP8266 */ +#else /* !CPU_ESP8266 */ /* map the partition top address to next higher multiple of 0x80000 (512 kB) */ part_top = (part_top + 0x80000) & ~0x7ffff; -#endif /* !MCU_ESP8266 */ +#endif /* !CPU_ESP8266 */ /* * if flash drive start address is not configured, use the determined @@ -219,7 +219,7 @@ void spi_flash_drive_init(void) DEBUG("\n"); } -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 const esp_partition_t* esp_partition_find_first(esp_partition_type_t type, esp_partition_subtype_t subtype, const char* label) @@ -276,7 +276,7 @@ esp_err_t esp_partition_erase_range(const esp_partition_t* part, return spi_flash_erase_range(part->address + addr, size); } -#endif /* MCU_ESP8266 */ +#endif /* CPU_ESP8266 */ static int _flash_init(mtd_dev_t *dev) { diff --git a/cpu/esp_common/periph/i2c_sw.c b/cpu/esp_common/periph/i2c_sw.c index c011aec316236..51acce914ea0a 100644 --- a/cpu/esp_common/periph/i2c_sw.c +++ b/cpu/esp_common/periph/i2c_sw.c @@ -43,13 +43,13 @@ #include "esp_attr.h" #include "esp_common.h" -#if !defined(MCU_ESP8266) +#if !defined(CPU_ESP8266) #include "esp_private/esp_clk.h" #endif #include "gpio_arch.h" #include "rom/ets_sys.h" -#ifndef MCU_ESP8266 +#ifndef CPU_ESP8266 #include "hal/cpu_hal.h" #include "soc/gpio_reg.h" @@ -69,7 +69,7 @@ #error "Platform implementation is missing" #endif -#else /* MCU_ESP8266 */ +#else /* CPU_ESP8266 */ #include "esp/gpio_regs.h" #include "sdk/ets.h" @@ -91,7 +91,7 @@ extern uint8_t system_get_cpu_freq(void); extern bool system_update_cpu_freq(uint8_t freq); -#endif /* MCU_ESP8266 */ +#endif /* CPU_ESP8266 */ typedef struct { i2c_speed_t speed; @@ -123,7 +123,7 @@ static _i2c_bus_t _i2c_bus[I2C_NUMOF] = {}; #define I2C_CLK_CAL 82 /* clock calibration offset */ #elif defined(CPU_FAM_ESP32S3) #define I2C_CLK_CAL 82 /* clock calibration offset */ -#elif defined(MCU_ESP8266) +#elif defined(CPU_ESP8266) #define I2C_CLK_CAL 47 /* clock calibration offset */ #else #error "Platform implementation is missing" @@ -156,7 +156,7 @@ static int _i2c_arbitration_lost(_i2c_bus_t* bus, const char* func); static void _i2c_abort(_i2c_bus_t* bus, const char* func); static void _i2c_clear(_i2c_bus_t* bus); -#if defined(MCU_ESP8266) +#if defined(CPU_ESP8266) static inline int esp_clk_cpu_freq(void) { return ets_get_cpu_frequency() * MHZ(1); @@ -201,7 +201,7 @@ void i2c_init(i2c_t dev) } /* Configure and initialize SDA and SCL pin. */ -#ifndef MCU_ESP8266 +#ifndef CPU_ESP8266 /* * ESP32 pins are used in input/output mode with open-drain output driver. * Signal levels are then realized as following: @@ -223,7 +223,7 @@ void i2c_init(i2c_t dev) } gpio_set(i2c_config[dev].sda); -#else /* !MCU_ESP8266 */ +#else /* !CPU_ESP8266 */ /* * Due to critical timing required by the I2C software implementation, * the ESP8266 GPIOs can not be used directly in GPIO_OD_PU mode. @@ -243,7 +243,7 @@ void i2c_init(i2c_t dev) gpio_init(_i2c_bus[dev].sda, GPIO_IN_PU)) { return; } -#endif /* !MCU_ESP8266 */ +#endif /* !CPU_ESP8266 */ /* store the usage type in GPIO table */ gpio_set_pin_usage(_i2c_bus[dev].scl, _I2C); @@ -416,7 +416,7 @@ static inline void _i2c_delay(_i2c_bus_t* bus) /* produces a delay */ uint32_t cycles = bus->delay; if (cycles) { -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 uint32_t ccount; __asm__ __volatile__("rsr %0,ccount":"=a" (ccount)); uint32_t wait_until = ccount + cycles; @@ -446,29 +446,29 @@ static inline void _i2c_delay(_i2c_bus_t* bus) static inline bool _i2c_scl_read(_i2c_bus_t* bus) { /* read SCL status (pin is in open-drain mode and set) */ -#ifndef MCU_ESP8266 +#ifndef CPU_ESP8266 return GPIO_GET(in, in1, bus->scl); -#else /* !MCU_ESP8266 */ +#else /* !CPU_ESP8266 */ return GPIO.IN & bus->scl_bit; -#endif /* !MCU_ESP8266 */ +#endif /* !CPU_ESP8266 */ } static inline bool _i2c_sda_read(_i2c_bus_t* bus) { /* read SDA status (pin is in open-drain mode and set) */ -#ifndef MCU_ESP8266 +#ifndef CPU_ESP8266 return GPIO_GET(in, in1, bus->sda); -#else /* !MCU_ESP8266 */ +#else /* !CPU_ESP8266 */ return GPIO.IN & bus->sda_bit; -#endif /* !MCU_ESP8266 */ +#endif /* !CPU_ESP8266 */ } static inline void _i2c_scl_high(_i2c_bus_t* bus) { -#ifndef MCU_ESP8266 +#ifndef CPU_ESP8266 /* set SCL signal high (pin is in open-drain mode and pulled-up) */ GPIO_SET(out_w1ts, out1_w1ts, bus->scl); -#else /* !MCU_ESP8266 */ +#else /* !CPU_ESP8266 */ #if I2C_CLOCK_STRETCH > 0 /* * set SCL signal high (switch back to GPIO_IN_PU mode, that is the pin is @@ -479,15 +479,15 @@ static inline void _i2c_scl_high(_i2c_bus_t* bus) /* No clock stretching supported, always drive the SCL pin. */ GPIO.OUT_SET = bus->scl_bit; #endif /* I2C_CLOCK_STRETCH > 0 */ -#endif /* !MCU_ESP8266 */ +#endif /* !CPU_ESP8266 */ } static inline void _i2c_scl_low(_i2c_bus_t* bus) { -#ifndef MCU_ESP8266 +#ifndef CPU_ESP8266 /* set SCL signal low (actively driven to low) */ GPIO_SET(out_w1tc, out1_w1tc, bus->scl); -#else /* !MCU_ESP8266 */ +#else /* !CPU_ESP8266 */ #if I2C_CLOCK_STRETCH > 0 /* * set SCL signal low (switch temporarily to GPIO_OD_PU where the @@ -498,35 +498,35 @@ static inline void _i2c_scl_low(_i2c_bus_t* bus) /* No clock stretching supported, always drive the SCL pin. */ GPIO.OUT_CLEAR = bus->scl_bit; #endif /* I2C_CLOCK_STRETCH > 0 */ -#endif /* !MCU_ESP8266 */ +#endif /* !CPU_ESP8266 */ } static inline void _i2c_sda_high(_i2c_bus_t* bus) { -#ifndef MCU_ESP8266 +#ifndef CPU_ESP8266 /* set SDA signal high (pin is in open-drain mode and pulled-up) */ GPIO_SET(out_w1ts, out1_w1ts, bus->sda); -#else /* !MCU_ESP8266 */ +#else /* !CPU_ESP8266 */ /* * set SDA signal high (switch back to GPIO_IN_PU mode, that is the pin is * in open-drain mode and pulled-up to high) */ GPIO.ENABLE_OUT_CLEAR = bus->sda_bit; -#endif /* !MCU_ESP8266 */ +#endif /* !CPU_ESP8266 */ } static inline void _i2c_sda_low(_i2c_bus_t* bus) { -#ifndef MCU_ESP8266 +#ifndef CPU_ESP8266 /* set SDA signal low (actively driven to low) */ GPIO_SET(out_w1tc, out1_w1tc, bus->sda); -#else /* !MCU_ESP8266 */ +#else /* !CPU_ESP8266 */ /* * set SDA signal low (switch temporarily to GPIO_OD_PU where the * written output value 0 drives the pin actively to low) */ GPIO.ENABLE_OUT_SET = bus->sda_bit; -#endif /* !MCU_ESP8266 */ +#endif /* !CPU_ESP8266 */ } static void _i2c_clear(_i2c_bus_t* bus) diff --git a/cpu/esp_common/periph/uart.c b/cpu/esp_common/periph/uart.c index 1d320cc372851..117aa91180d0f 100644 --- a/cpu/esp_common/periph/uart.c +++ b/cpu/esp_common/periph/uart.c @@ -44,7 +44,7 @@ #define ENABLE_DEBUG 0 #include "debug.h" -#if defined(MCU_ESP8266) +#if defined(CPU_ESP8266) #include "esp/iomux_regs.h" #include "esp8266/uart_struct.h" @@ -57,7 +57,7 @@ #define UART1 uart1 #define CPU_INUM_UART ETS_UART_INUM -#else /* defined(MCU_ESP8266) */ +#else /* defined(CPU_ESP8266) */ #include "driver/periph_ctrl.h" #include "esp_rom_gpio.h" @@ -77,7 +77,7 @@ #undef UART_CLK_FREQ #define UART_CLK_FREQ rtc_clk_apb_freq_get() /* APB_CLK is used */ -#endif /* defined(MCU_ESP8266) */ +#endif /* defined(CPU_ESP8266) */ struct uart_hw_t { uart_dev_t* regs; /* pointer to register data struct of the UART device */ @@ -87,7 +87,7 @@ struct uart_hw_t { uart_stop_bits_t stop; /* used stop bits */ uart_parity_t parity; /* used parity bits */ uart_isr_ctx_t isr_ctx; /* callback functions */ -#if !defined(MCU_ESP8266) +#if !defined(CPU_ESP8266) uint8_t mod; /* peripheral hardware module of the UART interface */ uint8_t signal_txd; /* TxD signal from the controller */ uint8_t signal_rxd; /* RxD signal to the controller */ @@ -104,15 +104,15 @@ static struct uart_hw_t _uarts[] = { .data = UART_DATA_BITS_8, .stop = UART_STOP_BITS_1, .parity = UART_PARITY_NONE, -#if !defined(MCU_ESP8266) +#if !defined(CPU_ESP8266) .mod = PERIPH_UART0_MODULE, .signal_txd = U0TXD_OUT_IDX, .signal_rxd = U0RXD_IN_IDX, .int_src = ETS_UART0_INTR_SOURCE -#endif /* !definedMCU_ESP8266 */ +#endif /* !defined CPU_ESP8266 */ }, -#if !defined(MCU_ESP8266) +#if !defined(CPU_ESP8266) #if defined(UART1_TXD) && defined(UART1_RXD) && (SOC_UART_NUM > 1) { .regs = &UART1, @@ -142,7 +142,7 @@ static struct uart_hw_t _uarts[] = { .int_src = ETS_UART2_INTR_SOURCE }, #endif /* defined(UART2_TXD) && defined(UART2_RXD) && (SOC_UART_NUM > 2) */ -#endif /* !defined(MCU_ESP8266) */ +#endif /* !defined(CPU_ESP8266) */ }; /* declaration of external functions */ @@ -166,7 +166,7 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg) assert(uart < UART_NUMOF_MAX); assert(uart < UART_NUMOF); -#ifndef MCU_ESP8266 +#ifndef CPU_ESP8266 assert(uart_config[uart].txd != GPIO_UNDEF); assert(uart_config[uart].rxd != GPIO_UNDEF); @@ -195,7 +195,7 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg) esp_rom_gpio_connect_in_signal(uart_config[uart].rxd, _uarts[uart].signal_rxd, false); } -#endif /* MCU_ESP8266 */ +#endif /* CPU_ESP8266 */ _uarts[uart].baudrate = baudrate; @@ -230,7 +230,7 @@ void uart_poweron(uart_t uart) { assert(uart < UART_NUMOF); -#ifndef MCU_ESP8266 +#ifndef CPU_ESP8266 periph_module_enable(_uarts[uart].mod); #endif _uart_config(uart); @@ -240,7 +240,7 @@ void uart_poweroff(uart_t uart) { assert(uart < UART_NUMOF); -#ifndef MCU_ESP8266 +#ifndef CPU_ESP8266 periph_module_disable(_uarts[uart].mod); #endif } @@ -252,7 +252,7 @@ void uart_system_init(void) /* reset all UART interrupt status registers */ _uarts[uart].regs->int_clr.val = ~0; } -#ifndef MCU_ESP8266 +#ifndef CPU_ESP8266 /* reset the pin usage of the default UART0 pins to GPIO to allow * reinitialization and usage for other purposes */ gpio_set_pin_usage(U0TXD_GPIO_NUM, _GPIO); @@ -321,7 +321,7 @@ static void IRAM _uart_intr_handler(void *arg) /* receive one data byte with wait */ static uint8_t IRAM _uart_rx_one_char(uart_t uart) { -#if defined(MODULE_ESP_QEMU) && defined(MCU_ESP8266) +#if defined(MODULE_ESP_QEMU) && defined(CPU_ESP8266) /* wait until at least von byte is in RX FIFO */ while (!FIELD2VAL(UART_STATUS_RXFIFO_COUNT, UART(uart).STATUS)) {} @@ -331,7 +331,7 @@ static uint8_t IRAM _uart_rx_one_char(uart_t uart) /* wait until at least von byte is in RX FIFO */ while (!_uarts[uart].regs->status.rxfifo_cnt) {} -#if defined(CPU_FAM_ESP32) || defined(MCU_ESP8266) +#if defined(CPU_FAM_ESP32) || defined(CPU_ESP8266) /* read the lowest byte from RX FIFO register */ return _uarts[uart].regs->fifo.rw_byte; #elif defined(CPU_FAM_ESP32S3) @@ -354,15 +354,15 @@ static void _uart_tx_one_char(uart_t uart, uint8_t data) while (_uarts[uart].regs->status.txfifo_cnt >= UART_FIFO_MAX) {} /* send the byte by placing it in the TX FIFO using MPU */ -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 #ifdef MODULE_ESP_QEMU UART(uart).FIFO = data; #else /* MODULE_ESP_QEMU */ _uarts[uart].regs->fifo.rw_byte = data; #endif /* MODULE_ESP_QEMU */ -#else /* MCU_ESP8266 */ +#else /* CPU_ESP8266 */ WRITE_PERI_REG(UART_FIFO_AHB_REG(uart), data); -#endif /* MCU_ESP8266 */ +#endif /* CPU_ESP8266 */ } static void _uart_intr_enable(uart_t uart) @@ -408,11 +408,11 @@ static void _uart_config(uart_t uart) /* enable the RX FIFO FULL interrupt */ _uart_intr_enable(uart); -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 /* we have to enable therefore the CPU interrupt here */ xt_set_interrupt_handler(CPU_INUM_UART, _uart_intr_handler, NULL); xt_ints_on(BIT(CPU_INUM_UART)); -#else /* MCU_ESP8266 */ +#else /* CPU_ESP8266 */ /* route all UART interrupt sources to same the CPU interrupt */ intr_matrix_set(PRO_CPU_NUM, _uarts[uart].int_src, CPU_INUM_UART); /* we have to enable therefore the CPU interrupt here */ @@ -422,7 +422,7 @@ static void _uart_config(uart_t uart) /* set interrupt level */ intr_cntrl_ll_set_int_level(CPU_INUM_UART, 1); #endif -#endif /* MCU_ESP8266 */ +#endif /* CPU_ESP8266 */ } } @@ -439,7 +439,7 @@ static int _uart_set_baudrate(uart_t uart, uint32_t baudrate) _uarts[uart].baudrate = baudrate; -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 /* compute and set clock divider */ uint32_t clk_div = UART_CLK_FREQ / _uarts[uart].baudrate; @@ -496,7 +496,7 @@ static int _uart_set_mode(uart_t uart, uart_data_bits_t data_bits, _uarts[uart].data = data_bits; /* set number of stop bits */ -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 switch (stop_bits) { case UART_STOP_BITS_1: _uarts[uart].regs->conf0.stop_bit_num = 1; break; case UART_STOP_BITS_2: _uarts[uart].regs->conf0.stop_bit_num = 3; break; diff --git a/cpu/esp_common/syscalls.c b/cpu/esp_common/syscalls.c index 2924a904361ae..4caa9b19da32c 100644 --- a/cpu/esp_common/syscalls.c +++ b/cpu/esp_common/syscalls.c @@ -62,7 +62,7 @@ int pthread_setcancelstate(int state, int *oldstate) * Following functions implement the locking mechanism for newlib. */ -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 /** * _malloc_rmtx is defined as static variable to avoid recursive calls of * malloc when _malloc_r tries to lock __malloc_lock_object the first @@ -111,7 +111,7 @@ void IRAM_ATTR _lock_init_recursive(_lock_t *lock) { assert(lock != NULL); /* lock must not be NULL */ -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 /* _malloc_rmtx is static and has not to be allocated */ if (lock == __malloc_static_object) { return; @@ -135,7 +135,7 @@ void IRAM_ATTR _lock_close(_lock_t *lock) { /* locking variable has to be valid and initialized */ assert(lock != NULL && *lock != 0); -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 assert(lock != __malloc_static_object); #endif @@ -152,7 +152,7 @@ void IRAM_ATTR _lock_close_recursive(_lock_t *lock) { /* locking variable has to be valid and initialized */ assert(lock != NULL && *lock != 0); -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 assert(lock != __malloc_static_object); #endif @@ -190,7 +190,7 @@ void IRAM_ATTR _lock_acquire_recursive(_lock_t *lock) assert(lock != NULL); /* lock must not be NULL */ assert(!irq_is_in()); /* _lock_acquire must not be called in interrupt context */ -#ifdef MCU_ESP8266 +#ifdef CPU_ESP8266 /** * Since we don't have direct access to newlib's static variable * __malloc_lock_object, we have to rely on the fact that function @@ -424,7 +424,7 @@ void* IRAM_ATTR __wrap__calloc_r(struct _reent *r, size_t nmemb, size_t size) /* for compatibility with ESP-IDF heap functions */ -#ifndef MCU_ESP8266 +#ifndef CPU_ESP8266 void* heap_caps_malloc(size_t size, uint32_t caps, const char *file, size_t line) __attribute__((alias("_heap_caps_malloc"))); void* heap_caps_calloc(size_t n, size_t size, uint32_t caps, const char *file, size_t line) diff --git a/cpu/esp_common/thread_arch.c b/cpu/esp_common/thread_arch.c index e2a1f0fa69235..d9bb7d4c37e0c 100644 --- a/cpu/esp_common/thread_arch.c +++ b/cpu/esp_common/thread_arch.c @@ -71,11 +71,11 @@ extern uint8_t port_IntStackTop; void thread_isr_stack_init(void) { /* code from thread.c, please see the copyright notice there */ -#ifndef MCU_ESP8266 +#ifndef CPU_ESP8266 #define sp (&port_IntStackTop) -#else /* !MCU_ESP8266 */ +#else /* !CPU_ESP8266 */ register uint32_t *sp __asm__ ("a1"); -#endif /* !MCU_ESP8266 */ +#endif /* !CPU_ESP8266 */ /* assign each int of the stack the value of it's address. We can safely * cast, as stack is aligned. Use an intermediate cast to uintptr_t to diff --git a/cpu/esp_common/vendor/esp/common_macros.h b/cpu/esp_common/vendor/esp/common_macros.h index cca23c921f97e..b8c9a7c5920b0 100644 --- a/cpu/esp_common/vendor/esp/common_macros.h +++ b/cpu/esp_common/vendor/esp/common_macros.h @@ -33,7 +33,7 @@ extern "C" { #define UNUSED __attributed((unused)) -#if defined(MCU_ESP8266) && !defined(BIT) +#if defined(CPU_ESP8266) && !defined(BIT) #define BIT(X) (1<<(X)) #endif diff --git a/cpu/native/async_read.c b/cpu/native/async_read.c index 5705535406519..5aed77739e768 100644 --- a/cpu/native/async_read.c +++ b/cpu/native/async_read.c @@ -97,6 +97,34 @@ void native_async_read_add_handler(int fd, void *arg, native_async_read_callback _next_index++; } +void native_async_read_remove_handler(int fd) +{ + int res = real_fcntl(fd, F_GETFL); + if (res < 0) { + err(EXIT_FAILURE, "native_async_read_remove_handler(): fcntl(F_GETFL)"); + } + unsigned flags = (unsigned)res & ~O_ASYNC; + res = real_fcntl(fd, F_SETFL, flags); + if (res < 0) { + err(EXIT_FAILURE, "native_async_read_remove_handler(): fcntl(F_SETFL)"); + } + + unsigned i; + for (i = 0; (i < (unsigned)_next_index) && (_fds[i].fd != fd); i++) { }; + if (i == (unsigned)_next_index) { + return; + } + + unregister_interrupt(SIGIO); + for (; i < (unsigned)_next_index - 1; i++) { + _fds[i] = _fds[i + 1]; + } + _next_index--; + register_interrupt(SIGIO, _async_io_isr); + + _fds[_next_index] = (struct pollfd){ 0 }; +} + void native_async_read_add_int_handler(int fd, void *arg, native_async_read_callback_t handler) { if (_next_index >= ASYNC_READ_NUMOF) { err(EXIT_FAILURE, "native_async_read_add_int_handler(): too many callbacks"); diff --git a/cpu/native/include/async_read.h b/cpu/native/include/async_read.h index 1c2edd9a5639d..3f36ab1af563c 100644 --- a/cpu/native/include/async_read.h +++ b/cpu/native/include/async_read.h @@ -80,6 +80,13 @@ void native_async_read_continue(int fd); */ void native_async_read_add_handler(int fd, void *arg, native_async_read_callback_t handler); +/** + * @brief stop monitoring of file descriptor + * + * @param[in] fd The file descriptor to stop monitoring + */ +void native_async_read_remove_handler(int fd); + /** * @brief start monitoring of file descriptor as interrupt * diff --git a/cpu/native/periph/uart.c b/cpu/native/periph/uart.c index 5584ba5c474bd..c3bd7ea0bcf1b 100644 --- a/cpu/native/periph/uart.c +++ b/cpu/native/periph/uart.c @@ -134,7 +134,20 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg) case 38400: speed = B38400; break; case 57600: speed = B57600; break; case 115200: speed = B115200; break; - case 230400: speed = B230400 ; break; + case 230400: speed = B230400; break; + case 460800 : speed = B460800; break; + case 500000 : speed = B500000; break; + case 576000 : speed = B576000; break; + case 921600 : speed = B921600; break; + case 1000000: speed = B1000000; break; + case 1152000: speed = B1152000; break; + case 1500000: speed = B1500000; break; + case 2000000: speed = B2000000; break; + case 2500000: speed = B2500000; break; + case 3000000: speed = B3000000; break; + case 3500000: speed = B3500000; break; + case 4000000: speed = B4000000; break; + default: return UART_NOBAUD; break; @@ -175,7 +188,9 @@ void uart_write(uart_t uart, const uint8_t *data, size_t len) DEBUG("\n"); - _native_write(tty_fds[uart], data, len); + if (tty_fds[uart] >= 0) { + _native_write(tty_fds[uart], data, len); + } } void uart_poweron(uart_t uart) @@ -186,6 +201,9 @@ void uart_poweron(uart_t uart) void uart_poweroff(uart_t uart) { - (void)uart; - /* not implemented (yet) */ + if (tty_fds[uart] >= 0) { + native_async_read_remove_handler(tty_fds[uart]); + real_close(tty_fds[uart]); + tty_fds[uart] = -1; + } } diff --git a/cpu/stm32/Makefile.features b/cpu/stm32/Makefile.features index 314e36380af7b..4757210cf392f 100644 --- a/cpu/stm32/Makefile.features +++ b/cpu/stm32/Makefile.features @@ -7,11 +7,6 @@ endif FEATURES_PROVIDED += cpu_stm32$(CPU_FAM) FEATURES_PROVIDED += periph_cpuid FEATURES_PROVIDED += periph_gpio periph_gpio_irq -FEATURES_PROVIDED += periph_timer_periodic -FEATURES_PROVIDED += periph_timer_query_freqs -FEATURES_PROVIDED += periph_rtt_overflow -FEATURES_PROVIDED += periph_uart_modecfg -FEATURES_PROVIDED += periph_uart_nonblocking FEATURES_PROVIDED += periph_gpio_ll FEATURES_PROVIDED += periph_gpio_ll_disconnect FEATURES_PROVIDED += periph_gpio_ll_input_pull_down @@ -20,6 +15,12 @@ FEATURES_PROVIDED += periph_gpio_ll_irq FEATURES_PROVIDED += periph_gpio_ll_irq_level_triggered_high FEATURES_PROVIDED += periph_gpio_ll_irq_level_triggered_low FEATURES_PROVIDED += periph_gpio_ll_open_drain +FEATURES_PROVIDED += periph_rtt_overflow +FEATURES_PROVIDED += periph_spi_reconfigure +FEATURES_PROVIDED += periph_timer_periodic +FEATURES_PROVIDED += periph_timer_query_freqs +FEATURES_PROVIDED += periph_uart_modecfg +FEATURES_PROVIDED += periph_uart_nonblocking ifneq (f1,$(CPU_FAM)) FEATURES_PROVIDED += periph_gpio_ll_open_drain_pull_up diff --git a/cpu/stm32/include/periph/cpu_spi.h b/cpu/stm32/include/periph/cpu_spi.h index 2ead5233e00e6..5d8c1a675de8e 100644 --- a/cpu/stm32/include/periph/cpu_spi.h +++ b/cpu/stm32/include/periph/cpu_spi.h @@ -32,6 +32,12 @@ extern "C" { #endif +#ifndef DOXYGEN +/* resolve circular dependency by declaring spi_t here */ +#define HAVE_SPI_T +typedef uint_fast8_t spi_t; +#endif + /** * @brief Define a magic number that tells us to use hardware chip select * @@ -119,6 +125,12 @@ typedef struct { #endif } spi_conf_t; +#ifndef DOXYGEN +gpio_t spi_pin_miso(spi_t bus); +gpio_t spi_pin_mosi(spi_t bus); +gpio_t spi_pin_clk(spi_t bus); +#endif + #ifdef __cplusplus } #endif diff --git a/cpu/stm32/periph/eeprom.c b/cpu/stm32/periph/eeprom.c index 1be989de0afc7..0a2e58902424c 100644 --- a/cpu/stm32/periph/eeprom.c +++ b/cpu/stm32/periph/eeprom.c @@ -95,7 +95,7 @@ size_t eeprom_read(uint32_t pos, void *data, size_t len) for (size_t i = 0; i < len; i++) { _wait_for_pending_operations(); *p++ = *(__IO uint8_t *)(EEPROM_START_ADDR + pos++); - DEBUG("0x%02X ", *p); + DEBUG("0x%02X ", *(p-1)); } DEBUG("\n"); @@ -110,8 +110,10 @@ size_t eeprom_write(uint32_t pos, const void *data, size_t len) _unlock(); + DEBUG("Writing data to EEPROM at pos %" PRIu32 ": ", pos); for (size_t i = 0; i < len; i++) { _write_byte((EEPROM_START_ADDR + pos++), *p++); + DEBUG("0x%02X ", *(p-1)); } _lock(); diff --git a/cpu/stm32/periph/spi.c b/cpu/stm32/periph/spi.c index 408243b1c1f78..d5ee2edd0e8fd 100644 --- a/cpu/stm32/periph/spi.c +++ b/cpu/stm32/periph/spi.c @@ -28,6 +28,7 @@ #include +#include "compiler_hints.h" #include "mutex.h" #include "periph/gpio.h" #include "periph/spi.h" @@ -94,17 +95,17 @@ static uint8_t _get_prescaler(const spi_conf_t *conf, uint32_t clock) * happen if this cannot be met. So let's have a blown assertion * rather than runtime failures that require a logic analyzer to * debug. */ - assert(prescaled_clock <= clock); + assume(prescaled_clock <= clock); return prescaler; } void spi_init(spi_t bus) { - assert(bus < SPI_NUMOF); + assume(bus < SPI_NUMOF); - /* initialize device lock */ - mutex_init(&locks[bus]); + /* initialize device lock (as locked, spi_init_pins() will unlock it */ + locks[bus] = (mutex_t)MUTEX_INIT_LOCKED; /* trigger pin initialization */ spi_init_pins(bus); @@ -120,6 +121,7 @@ void spi_init(spi_t bus) void spi_init_pins(spi_t bus) { + assume(bus < SPI_NUMOF); #ifdef CPU_FAM_STM32F1 if (gpio_is_valid(spi_config[bus].sclk_pin)) { @@ -149,6 +151,43 @@ void spi_init_pins(spi_t bus) gpio_init_af(spi_config[bus].sclk_pin, spi_config[bus].sclk_af); } #endif + mutex_unlock(&locks[bus]); +} + +void spi_deinit_pins(spi_t bus) +{ + assume(bus < SPI_NUMOF); + mutex_lock(&locks[bus]); + + if (gpio_is_valid(spi_config[bus].sclk_pin)) { + gpio_init(spi_config[bus].sclk_pin, GPIO_IN); + } + + if (gpio_is_valid(spi_config[bus].mosi_pin)) { + gpio_init(spi_config[bus].mosi_pin, GPIO_IN); + } + + if (gpio_is_valid(spi_config[bus].miso_pin)) { + gpio_init(spi_config[bus].miso_pin, GPIO_IN); + } +} + +gpio_t spi_pin_miso(spi_t bus) +{ + assume(bus < SPI_NUMOF); + return spi_config[bus].miso_pin; +} + +gpio_t spi_pin_mosi(spi_t bus) +{ + assume(bus < SPI_NUMOF); + return spi_config[bus].mosi_pin; +} + +gpio_t spi_pin_clk(spi_t bus) +{ + assume(bus < SPI_NUMOF); + return spi_config[bus].sclk_pin; } int spi_init_cs(spi_t bus, spi_cs_t cs) @@ -183,7 +222,7 @@ int spi_init_cs(spi_t bus, spi_cs_t cs) #ifdef MODULE_PERIPH_SPI_GPIO_MODE int spi_init_with_gpio_mode(spi_t bus, const spi_gpio_mode_t* mode) { - assert(bus < SPI_NUMOF); + assume(bus < SPI_NUMOF); int ret = 0; @@ -212,7 +251,7 @@ int spi_init_with_gpio_mode(spi_t bus, const spi_gpio_mode_t* mode) void spi_acquire(spi_t bus, spi_cs_t cs, spi_mode_t mode, spi_clk_t clk) { - assert((unsigned)bus < SPI_NUMOF); + assume((unsigned)bus < SPI_NUMOF); /* lock bus */ mutex_lock(&locks[bus]); @@ -379,7 +418,7 @@ void spi_transfer_bytes(spi_t bus, spi_cs_t cs, bool cont, const void *out, void *in, size_t len) { /* make sure at least one input or one output buffer is given */ - assert(out || in); + assume(out || in); /* active the given chip select line */ if ((cs != SPI_HWCS_MASK) && gpio_is_valid(cs)) { diff --git a/dist/tools/ci/print_toolchain_versions.sh b/dist/tools/ci/print_toolchain_versions.sh index f52fc44b4c088..0453f70dfad36 100755 --- a/dist/tools/ci/print_toolchain_versions.sh +++ b/dist/tools/ci/print_toolchain_versions.sh @@ -128,7 +128,6 @@ for p in \ msp430-elf \ riscv-none-elf \ riscv64-unknown-elf \ - riscv-none-embed \ riscv32-esp-elf \ xtensa-esp32-elf \ xtensa-esp32s2-elf \ @@ -147,7 +146,6 @@ for p in \ msp430-elf \ riscv-none-elf \ riscv64-unknown-elf \ - riscv-none-embed \ riscv32-esp-elf \ xtensa-esp32-elf \ xtensa-esp32s2-elf \ diff --git a/dist/tools/insufficient_memory/create_makefile.ci.sh b/dist/tools/insufficient_memory/create_makefile.ci.sh index 54bf3b2040097..7f2c0e257b799 100755 --- a/dist/tools/insufficient_memory/create_makefile.ci.sh +++ b/dist/tools/insufficient_memory/create_makefile.ci.sh @@ -56,6 +56,7 @@ for BOARD in $(EXTERNAL_BOARD_DIRS="" make --no-print-directory info-boards-sup if grep -e overflowed \ -e "not within region" \ -e "wraps around address space" \ + -e "overlaps section" \ "$TMPFILE" > /dev/null; then printf "${CBIG}%s${CRESET}\n" "too big" BOARDS="${BOARDS} ${BOARD}" diff --git a/dist/tools/insufficient_memory/update_insufficient_memory_board.sh b/dist/tools/insufficient_memory/update_insufficient_memory_board.sh index 66f8644bd2a7e..20a90527170e4 100755 --- a/dist/tools/insufficient_memory/update_insufficient_memory_board.sh +++ b/dist/tools/insufficient_memory/update_insufficient_memory_board.sh @@ -64,6 +64,7 @@ for application in ${APPLICATIONS}; do if grep -e overflowed \ -e "not within region" \ -e "wraps around address space" \ + -e "overlaps section" \ "$TMPFILE" > /dev/null; then printf "${CBIG}%s${CRESET}\n" "too big" make -f "$(dirname "$0")"/Makefile.for_sh DIR="${RIOTBASE}/${application}" ADD_BOARDS="${BOARD}" Makefile.ci > /dev/null diff --git a/doc/doxygen/src/roadmap.md b/doc/doxygen/src/roadmap.md index b35b73ddea7ca..b88db039b69cb 100644 --- a/doc/doxygen/src/roadmap.md +++ b/doc/doxygen/src/roadmap.md @@ -11,8 +11,11 @@ The text and items below are tentative, up for discussion, to be updated by regu - ICN stack support clean-up - discuss mid- and long-term plans for network stack maintenance & development (GNRC vs other supported stacks) - revisit network time synchronization - - +- Provide a border router into 6LoWPANs (a 6LBR) that works out of the box in common scenarios: + - [x] in IPv6 networks with working Prefix Delegation (PD) + - [ ] in IPv6 networks without working Prefix Delegation (eg. by means of ND Proxying) + - [ ] in legacy networks (eg. by means of tunneling) + - [ ] with configurable on-by-default fallbacks # Network Stack Low layers (contact/steering: [Peter](https://github.com/PeterKietzmann)) @@ -20,9 +23,14 @@ The text and items below are tentative, up for discussion, to be updated by regu - Point-to-Point Protocol (PPP): finalize and merge `gnrc_ppp` +# Integrations +(contact/steering: [Teufelchen](https://github.com/teufelchen1)) + +- [Home-Assistant](https://www.home-assistant.io/) BTHome integration +- [Home-Assistant](https://www.home-assistant.io/) integration via [MQTT Discovery](https://www.home-assistant.io/integrations/mqtt#mqtt-discovery) # Power Modes -(contact/steering: [Hauke](https://github.com/haukepetersen)) +(contact/steering: [benpicco](https://github.com/benpicco)) - concept to fix shell usage issue while LPM activated - integrate generic power management functions in device driver APIs (netdev, SAUL, ...) @@ -32,7 +40,7 @@ The text and items below are tentative, up for discussion, to be updated by regu # Peripheral drivers -(contact/steering: [Hauke](https://github.com/haukepetersen)) +(contact/steering: [maribu](https://github.com/maribu)) ## Timers diff --git a/drivers/include/periph/spi.h b/drivers/include/periph/spi.h index 85d7d6d91f350..98680671eece9 100644 --- a/drivers/include/periph/spi.h +++ b/drivers/include/periph/spi.h @@ -66,8 +66,8 @@ #ifndef PERIPH_SPI_H #define PERIPH_SPI_H +#include #include -#include #include #include #include @@ -430,6 +430,25 @@ uint8_t spi_transfer_reg(spi_t bus, spi_cs_t cs, uint8_t reg, uint8_t out); void spi_transfer_regs(spi_t bus, spi_cs_t cs, uint8_t reg, const void *out, void *in, size_t len); +/** + * @brief Transfer a 16 bit number in big endian byte order + * + * @param[in] bus SPI device to use + * @param[in] cs chip select pin/line to use, set to + * SPI_CS_UNDEF if chip select should not be + * handled by the SPI driver + * @param[in] cont if true, keep device selected after transfer + * @param[in] host_number number to transfer in host byte order + * @return The 16 bit number received in host byte order + */ +static inline uint16_t spi_transfer_u16_be(spi_t bus, spi_cs_t cs, bool cont, uint16_t host_number) +{ + const uint16_t send = htobe16(host_number); + uint16_t receive; + spi_transfer_bytes(bus, cs, cont, &send, &receive, sizeof(receive)); + return be16toh(receive); +} + #ifdef __cplusplus } #endif diff --git a/drivers/include/usbdev_synopsys_dwc2.h b/drivers/include/usbdev_synopsys_dwc2.h index 819a1276025e2..20985f949469d 100644 --- a/drivers/include/usbdev_synopsys_dwc2.h +++ b/drivers/include/usbdev_synopsys_dwc2.h @@ -96,7 +96,7 @@ typedef struct { gpio_t ulpi_nxt; /**< ULPI NXT gpio */ gpio_af_t ulpi_af; /**< Alternative function for ULPI */ #endif -#if defined(MCU_STM32) || DOXYGEN +#if defined(CPU_STM32) || DOXYGEN uint32_t rcc_mask; /**< bit in clock enable register */ uint8_t irqn; /**< IRQ channel */ uint8_t ahb; /**< AHB bus */ @@ -108,8 +108,8 @@ typedef struct { * value (STM32-specific), see USBPHYC_TUNE * register in STM32 Reference Manual */ #endif /* defined(MODULE_PERIPH_USBDEV_HS_UTMI) */ -#endif /* defined(MCU_STM32) || DOXYGEN */ -#if defined(MCU_GD32V) +#endif /* defined(CPU_STM32) || DOXYGEN */ +#if defined(CPU_GD32V) uint32_t rcu_mask; /**< bit in clock enable register */ uint8_t irqn; /**< IRQ channel */ uint8_t bus; /**< Peripheral bus */ diff --git a/drivers/sdmmc/sdmmc_sdhc.c b/drivers/sdmmc/sdmmc_sdhc.c index e193ab5803a9f..5f883f70ff8f5 100644 --- a/drivers/sdmmc/sdmmc_sdhc.c +++ b/drivers/sdmmc/sdmmc_sdhc.c @@ -46,7 +46,7 @@ #define ENABLE_DEBUG 0 #include "debug.h" -#if defined(MCU_SAMD5X) || defined(MCU_SAME5X) +#if defined(CPU_SAMD5X) || defined(CPU_SAME5X) #ifndef SDHC_CLOCK #define SDHC_CLOCK SAM0_GCLK_MAIN @@ -57,7 +57,7 @@ #endif #else -#error "MCU not supported" +#error "CPU not supported" #endif /* limit the Default and High Speed clock rates for debugging */ @@ -295,7 +295,7 @@ static int _send_cmd(sdmmc_dev_t *dev, uint8_t cmd_idx, uint32_t arg, sdhc->BCR.reg = 0; } -#if defined(MCU_SAMD5X) || defined(MCU_SAME5X) +#if defined(CPU_SAMD5X) || defined(CPU_SAME5X) Sdhc *sam0_sdhc = (Sdhc *)sdhc; /* CMD0, CMD1, CMD2, CMD3 and CMD8 are broadcast commands */ if ((cmd_idx <= SDMMC_CMD3) || (cmd_idx == SDMMC_CMD8)) { @@ -422,7 +422,7 @@ static int _set_clock_rate(sdmmc_dev_t *dev, sdmmc_clock_rate_t rate) uint32_t base_clk = sdhc->CA0R.bit.BASECLKF; uint32_t clk_mult = sdhc->CA1R.bit.CLKMULT; -#if defined(MCU_SAMD5X) || defined(MCU_SAME5X) +#if defined(CPU_SAMD5X) || defined(CPU_SAME5X) /* if CA1R.CLKMULT is 0, programmable clock is not supported */ assert(clk_mult); base_clk = (base_clk == 0) ? sam0_gclk_freq(SDHC_CLOCK) / 2 : MHZ(base_clk); @@ -610,7 +610,7 @@ static int _xfer_finish(sdmmc_dev_t *dev, sdmmc_xfer_desc_t *xfer) } /* Internal functions */ -#if defined(MCU_SAMD5X) || defined(MCU_SAME5X) +#if defined(CPU_SAMD5X) || defined(CPU_SAME5X) void _core_init(sdhc_dev_t *sdhc_dev) { @@ -675,7 +675,7 @@ static void _init_pins(sdhc_dev_t *sdhc_dev) sdhc_dev->sdmmc_dev.bus_width = SDMMC_BUS_WIDTH_4BIT; } -#endif /* defined(MCU_SAMD5X) || defined(MCU_SAME5X) */ +#endif /* defined(CPU_SAMD5X) || defined(CPU_SAME5X) */ /** * @brief Reset the entire SDHC peripheral or a part of it @@ -744,11 +744,11 @@ static bool _wait_for_event(sdhc_dev_t *sdhc_dev, /* block IDLE so that the CPU clock does not stop */ -#if defined(MCU_SAMD5X) || defined(MCU_SAME5X) +#if defined(CPU_SAMD5X) || defined(CPU_SAME5X) pm_block(SAM0_PM_IDLE); #endif mutex_lock(&sdhc_dev->irq_wait); -#if defined(MCU_SAMD5X) || defined(MCU_SAME5X) +#if defined(CPU_SAMD5X) || defined(CPU_SAME5X) pm_unblock(SAM0_PM_IDLE); #endif diff --git a/drivers/usbdev_synopsys_dwc2/usbdev_synopsys_dwc2.c b/drivers/usbdev_synopsys_dwc2/usbdev_synopsys_dwc2.c index ec194667170fc..65feddaa2d6f8 100644 --- a/drivers/usbdev_synopsys_dwc2/usbdev_synopsys_dwc2.c +++ b/drivers/usbdev_synopsys_dwc2/usbdev_synopsys_dwc2.c @@ -19,7 +19,7 @@ #define USB_H_USER_IS_RIOT_INTERNAL -#ifdef MCU_ESP32 +#ifdef CPU_ESP32 #if !defined(CPU_FAM_ESP32S2) && !defined(CPU_FAM_ESP32S3) #error "ESP32x SoC family not supported" @@ -43,13 +43,13 @@ #include "pm_layered.h" #include "ztimer.h" -#if defined(MCU_STM32) +#if defined(CPU_STM32) #include "usbdev_stm32.h" -#elif defined(MCU_ESP32) +#elif defined(CPU_ESP32) #include "usbdev_esp32.h" -#elif defined(MCU_EFM32) +#elif defined(CPU_EFM32) #include "usbdev_efm32.h" -#elif defined(MCU_GD32V) +#elif defined(CPU_GD32V) #include "vendor/usbdev_gd32v.h" #else #error "MCU not supported" @@ -63,7 +63,7 @@ #define ENABLE_DEBUG 0 #include "debug.h" -#ifdef MCU_ESP32 +#ifdef CPU_ESP32 #include "esp_err.h" #include "esp_intr_alloc.h" @@ -72,7 +72,7 @@ #endif -#ifdef MCU_GD32V +#ifdef CPU_GD32V #define RCU_CFG0_SCS_PLL (2UL << RCU_CFG0_SCS_Pos) /* PLL used */ @@ -635,7 +635,7 @@ static void _flush_rx_fifo(const dwc2_usb_otg_fshs_config_t *conf) static void _sleep_periph(const dwc2_usb_otg_fshs_config_t *conf) { *_pcgcctl_reg(conf) |= USB_OTG_PCGCCTL_STOPCLK; -#if defined(MCU_STM32) +#if defined(CPU_STM32) /* Unblocking STM32_PM_STOP during suspend on the stm32f446 breaks while * (un)blocking works on the stm32f401, needs more investigation. * Works with: @@ -649,22 +649,22 @@ static void _sleep_periph(const dwc2_usb_otg_fshs_config_t *conf) * stm32f767zi FS CID: 2000, HWREV: 4f54320a, HWCFG: 229ed520 */ pm_unblock(STM32_PM_STOP); -#elif defined(MCU_EFM32) +#elif defined(CPU_EFM32) /* switch USB core clock source either to LFXO or LFRCO */ CMU_ClockSelectSet(cmuClock_USB, CLOCK_LFA); pm_unblock(EFM32_PM_MODE_EM2); -#elif defined(MCU_ESP32) +#elif defined(CPU_ESP32) pm_unblock(ESP_PM_LIGHT_SLEEP); -#elif defined(MCU_GD32V) +#elif defined(CPU_GD32V) pm_unblock(GD32V_PM_DEEPSLEEP); #endif } static void _wake_periph(const dwc2_usb_otg_fshs_config_t *conf) { -#if defined(MCU_STM32) +#if defined(CPU_STM32) pm_block(STM32_PM_STOP); -#elif defined(MCU_EFM32) +#elif defined(CPU_EFM32) pm_block(EFM32_PM_MODE_EM2); /* switch USB core clock source either to USHFRCO or HFCLK */ #if defined(CPU_FAM_EFM32GG12B) || defined(CPU_FAM_EFM32GG11B) @@ -674,9 +674,9 @@ static void _wake_periph(const dwc2_usb_otg_fshs_config_t *conf) #else #error "EFM32 family not yet supported" #endif /* defined(CPU_FAM_EFM32GG12B) || defined(CPU_FAM_EFM32GG11B) */ -#elif defined(MCU_ESP32) +#elif defined(CPU_ESP32) pm_block(ESP_PM_LIGHT_SLEEP); -#elif defined(MCU_GD32V) +#elif defined(CPU_GD32V) pm_block(GD32V_PM_DEEPSLEEP); #endif *_pcgcctl_reg(conf) &= ~USB_OTG_PCGCCTL_STOPCLK; @@ -707,7 +707,7 @@ static void _reset_periph(dwc2_usb_otg_fshs_t *usbdev) while (_global_regs(conf)->GRSTCTL & USB_OTG_GRSTCTL_CSRST) {} } -#ifdef MCU_STM32 +#ifdef CPU_STM32 static void _enable_gpio(const dwc2_usb_otg_fshs_config_t *conf) { (void)conf; @@ -720,7 +720,7 @@ static void _enable_gpio(const dwc2_usb_otg_fshs_config_t *conf) gpio_init_af(conf->dm, conf->af); #endif /* MODULE_PERIPH_USBDEV_HS_ULPI */ } -#endif /* MCU_STM32 */ +#endif /* CPU_STM32 */ static void _set_mode_device(dwc2_usb_otg_fshs_t *usbdev) { @@ -738,7 +738,7 @@ static void _usbdev_init(usbdev_t *dev) dwc2_usb_otg_fshs_t *usbdev = (dwc2_usb_otg_fshs_t *)dev; const dwc2_usb_otg_fshs_config_t *conf = usbdev->config; -#if defined(MCU_STM32) +#if defined(CPU_STM32) /* Block both STOP and STANDBY, STOP is unblocked during USB suspend * status */ @@ -760,7 +760,7 @@ static void _usbdev_init(usbdev_t *dev) _enable_gpio(conf); -#elif defined(MCU_ESP32) +#elif defined(CPU_ESP32) pm_block(ESP_PM_DEEP_SLEEP); pm_block(ESP_PM_LIGHT_SLEEP); @@ -777,7 +777,7 @@ static void _usbdev_init(usbdev_t *dev) LOG_ERROR("usbdev: Install USB PHY failed\n"); } -#elif defined(MCU_EFM32) +#elif defined(CPU_EFM32) /* Block EM2 and EM3. In EM2, most USB core registers are reset and the * FIFO content is lost. EM2 is unblocked during USB suspend */ @@ -812,7 +812,7 @@ static void _usbdev_init(usbdev_t *dev) /* USB VBUSEN pin is not yet used */ /* USB_ROUTELOC0 = location */ -#elif defined(MCU_GD32V) +#elif defined(CPU_GD32V) /* Block both DEEP_SLEEP and STANDBY, TODO DEEP_SLEEP is unblocked during * USB suspend status */ @@ -1005,7 +1005,7 @@ static void _usbdev_init(usbdev_t *dev) /* Force the peripheral to device mode */ _set_mode_device(usbdev); -#if defined(MCU_STM32) +#if defined(CPU_STM32) /* Disable Vbus detection and force the pull-up on, GCCFG is STM32 specific */ #if defined(STM32_USB_OTG_CID_1x) @@ -1033,14 +1033,14 @@ static void _usbdev_init(usbdev_t *dev) _global_regs(usbdev->config)->GCCFG &= ~USB_OTG_GCCFG_PWRDWN; } -#elif defined(MCU_ESP32) || defined(MCU_EFM32) +#elif defined(CPU_ESP32) || defined(CPU_EFM32) /* Force Vbus Detect values and ID detect values to device mode */ _global_regs(usbdev->config)->GOTGCTL |= USB_OTG_GOTGCTL_VBVALOVAL | USB_OTG_GOTGCTL_VBVALOEN | USB_OTG_GOTGCTL_BVALOEN | USB_OTG_GOTGCTL_BVALOVAL; -#elif defined(MCU_GD32V) +#elif defined(CPU_GD32V) /* disable Vbus sensing */ _global_regs(usbdev->config)->GCCFG |= USB_OTG_GCCFG_PWRON | USB_OTG_GCCFG_VBUSIG | @@ -1116,17 +1116,17 @@ static void _usbdev_init(usbdev_t *dev) /* Enable interrupts */ _global_regs(conf)->GAHBCFG |= USB_OTG_GAHBCFG_GINT; -#if defined(MCU_STM32) +#if defined(CPU_STM32) /* Unmask the interrupt in the NVIC */ NVIC_EnableIRQ(conf->irqn); -#elif defined(MCU_EFM32) +#elif defined(CPU_EFM32) /* Unmask the interrupt in the NVIC */ NVIC_EnableIRQ(USB_IRQn); -#elif defined(MCU_ESP32) +#elif defined(CPU_ESP32) void isr_otg_fs(void *arg); /* Allocate the interrupt and connect it with USB interrupt source */ esp_intr_alloc(ETS_USB_INTR_SOURCE, ESP_INTR_FLAG_LOWMED, isr_otg_fs, NULL, NULL); -#elif defined(MCU_GD32V) +#elif defined(CPU_GD32V) void isr_otg_fs(unsigned irq); clic_set_handler(conf->irqn, isr_otg_fs); clic_enable_interrupt(conf->irqn, CPU_DEFAULT_IRQ_PRIO); @@ -1642,7 +1642,7 @@ void _isr_common(dwc2_usb_otg_fshs_t *usbdev) #endif } -#if defined(MCU_STM32) +#if defined(CPU_STM32) #ifdef DWC2_USB_OTG_FS_ENABLED void isr_otg_fs(void) @@ -1664,7 +1664,7 @@ void isr_otg_hs(void) } #endif /* DWC2_USB_OTG_HS_ENABLED */ -#elif defined(MCU_ESP32) +#elif defined(CPU_ESP32) void isr_otg_fs(void *arg) { @@ -1676,7 +1676,7 @@ void isr_otg_fs(void *arg) _isr_common(usbdev); } -#elif defined(MCU_EFM32) +#elif defined(CPU_EFM32) void isr_usb(void) { @@ -1686,7 +1686,7 @@ void isr_usb(void) _isr_common(usbdev); } -#elif defined(MCU_GD32V) +#elif defined(CPU_GD32V) void isr_otg_fs(unsigned irq) { @@ -1699,7 +1699,7 @@ void isr_otg_fs(unsigned irq) } #else -#error "MCU not supported" +#error "CPU not supported" #endif const usbdev_driver_t driver = { diff --git a/drivers/w5100/w5100.c b/drivers/w5100/w5100.c index 50be845460290..8ca58b8e5d11a 100644 --- a/drivers/w5100/w5100.c +++ b/drivers/w5100/w5100.c @@ -47,13 +47,7 @@ static const netdev_driver_t netdev_driver_w5100; static inline void send_addr(w5100_t *dev, uint16_t addr) { -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - spi_transfer_byte(dev->p.spi, dev->p.cs, true, (addr >> 8)); - spi_transfer_byte(dev->p.spi, dev->p.cs, true, (addr & 0xff)); -#else - spi_transfer_byte(dev->p.spi, dev->p.cs, true, (addr & 0xff)); - spi_transfer_byte(dev->p.spi, dev->p.cs, true, (addr >> 8)); -#endif + spi_transfer_u16_be(dev->p.spi, dev->p.cs, true, addr); } static uint8_t rreg(w5100_t *dev, uint16_t reg) diff --git a/examples/asymcute_mqttsn/Makefile.ci b/examples/asymcute_mqttsn/Makefile.ci index 32a4b17d1e2de..674f786b3d94a 100644 --- a/examples/asymcute_mqttsn/Makefile.ci +++ b/examples/asymcute_mqttsn/Makefile.ci @@ -12,8 +12,6 @@ BOARD_INSUFFICIENT_MEMORY := \ bluepill-stm32f030c8 \ calliope-mini \ derfmega128 \ - hifive1 \ - hifive1b \ i-nucleo-lrwan1 \ im880b \ microbit \ diff --git a/examples/cord_ep/Makefile.ci b/examples/cord_ep/Makefile.ci index e5d03bc296240..33e490f2ff39a 100644 --- a/examples/cord_ep/Makefile.ci +++ b/examples/cord_ep/Makefile.ci @@ -10,8 +10,6 @@ BOARD_INSUFFICIENT_MEMORY := \ atxmega-a3bu-xplained \ bluepill-stm32f030c8 \ derfmega128 \ - hifive1 \ - hifive1b \ i-nucleo-lrwan1 \ im880b \ microduino-corerf \ diff --git a/examples/cord_epsim/Makefile.ci b/examples/cord_epsim/Makefile.ci index b135ba2e43f59..2f6c0fe55e802 100644 --- a/examples/cord_epsim/Makefile.ci +++ b/examples/cord_epsim/Makefile.ci @@ -8,8 +8,6 @@ BOARD_INSUFFICIENT_MEMORY := \ atmega328p-xplained-mini \ atmega8 \ bluepill-stm32f030c8 \ - hifive1 \ - hifive1b \ i-nucleo-lrwan1 \ msb-430 \ msb-430h \ diff --git a/examples/cord_lc/Makefile.ci b/examples/cord_lc/Makefile.ci index c66a88c7ab964..5021256da2ef2 100644 --- a/examples/cord_lc/Makefile.ci +++ b/examples/cord_lc/Makefile.ci @@ -10,8 +10,6 @@ BOARD_INSUFFICIENT_MEMORY := \ atxmega-a3bu-xplained \ bluepill-stm32f030c8 \ chronos \ - hifive1 \ - hifive1b \ i-nucleo-lrwan1 \ im880b \ msb-430 \ diff --git a/examples/dtls-sock/Makefile b/examples/dtls-sock/Makefile index 91fa5b9907eab..19c63b3f630a8 100644 --- a/examples/dtls-sock/Makefile +++ b/examples/dtls-sock/Makefile @@ -61,3 +61,8 @@ ifeq (,$(filter arch_avr8,$(FEATURES_USED))) else CFLAGS += -DTHREAD_STACKSIZE_MAIN=\(4*THREAD_STACKSIZE_LARGE\) endif + +# We have two credentials for client and server, each. If we are to run both +# server and client, we need four slots in total. The default (2) would be +# sufficient if only client or server is ever run. +CFLAGS += -DCONFIG_CREDMAN_MAX_CREDENTIALS=4 diff --git a/examples/emcute_mqttsn/Makefile.ci b/examples/emcute_mqttsn/Makefile.ci index 5ee8cd4cfa68a..db3117542b9e0 100644 --- a/examples/emcute_mqttsn/Makefile.ci +++ b/examples/emcute_mqttsn/Makefile.ci @@ -10,8 +10,6 @@ BOARD_INSUFFICIENT_MEMORY := \ atxmega-a3bu-xplained \ bluepill-stm32f030c8 \ derfmega128 \ - hifive1 \ - hifive1b \ i-nucleo-lrwan1 \ im880b \ microduino-corerf \ diff --git a/examples/gcoap/client.c b/examples/gcoap/client.c index 491a905ef8c23..8f4039baefa82 100644 --- a/examples/gcoap/client.c +++ b/examples/gcoap/client.c @@ -52,6 +52,15 @@ static char proxy_uri[64]; #define _LAST_REQ_PATH_MAX (64) static char _last_req_path[_LAST_REQ_PATH_MAX]; +/* whether this node is currently observing a resource as a client */ +static bool observing = false; + +/* the token used for observing a remote resource */ +static uint8_t obs_req_token[GCOAP_TOKENLEN_MAX]; + +/* actual length of above token */ +static size_t obs_req_tkl = 0; + uint16_t req_count = 0; /* @@ -145,31 +154,9 @@ static void _resp_handler(const gcoap_request_memo_t *memo, coap_pkt_t* pdu, } } -static size_t _send(uint8_t *buf, size_t len, char *addr_str) +static size_t _send(uint8_t *buf, size_t len, sock_udp_ep_t *remote) { size_t bytes_sent; - sock_udp_ep_t *remote; - sock_udp_ep_t new_remote; - - if (_proxied) { - remote = &_proxy_remote; - } - else { - if (sock_udp_name2ep(&new_remote, addr_str) != 0) { - return 0; - } - - if (new_remote.port == 0) { - if (IS_USED(MODULE_GCOAP_DTLS)) { - new_remote.port = CONFIG_GCOAPS_PORT; - } - else { - new_remote.port = CONFIG_GCOAP_PORT; - } - } - - remote = &new_remote; - } bytes_sent = gcoap_req_send(buf, len, remote, _resp_handler, NULL); if (bytes_sent > 0) { @@ -180,10 +167,27 @@ static size_t _send(uint8_t *buf, size_t len, char *addr_str) static int _print_usage(char **argv) { - printf("usage: %s \n", argv[0]); + printf("usage: %s \n", argv[0]); return 1; } +static int _addrstr2remote(const char *addr_str, sock_udp_ep_t *remote) +{ + if (sock_udp_name2ep(remote, addr_str) != 0) { + return -1; + } + + if (remote->port == 0) { + if (IS_USED(MODULE_GCOAP_DTLS)) { + remote->port = CONFIG_GCOAPS_PORT; + } + else { + remote->port = CONFIG_GCOAP_PORT; + } + } + return 0; +} + int gcoap_cli_cmd(int argc, char **argv) { /* Ordered like the RFC method code numbers, but off by 1. GET is code 0. */ @@ -191,6 +195,9 @@ int gcoap_cli_cmd(int argc, char **argv) uint8_t buf[CONFIG_GCOAP_PDU_BUF_SIZE]; coap_pkt_t pdu; size_t len; + unsigned observe = false; + uint32_t obs_value = COAP_OBS_REGISTER; + sock_udp_ep_t remote; if (argc == 1) { /* show help for main commands */ @@ -275,6 +282,30 @@ int gcoap_cli_cmd(int argc, char **argv) /* parse options */ int apos = 2; /* position of address argument */ + + /* For GET requests additional switches allow for registering and + * deregistering an observe. This example only supports one observe. */ + if (code_pos == COAP_METHOD_GET) { + if (argc > apos) { + if (strcmp(argv[apos], "-o") == 0) { + if (observing) { + puts("Only one observe supported"); + return 1; + } + observe = true; + apos++; + } else if (strcmp(argv[apos], "-d") == 0) { + if (!observing) { + puts("Not observing"); + return 1; + } + observe = true; + apos++; + obs_value = COAP_OBS_DEREGISTER; + } + } + } + /* ping must be confirmable */ unsigned msg_type = (!code_pos ? COAP_TYPE_CON : COAP_TYPE_NON); if (argc > apos && strcmp(argv[apos], "-c") == 0) { @@ -287,6 +318,12 @@ int gcoap_cli_cmd(int argc, char **argv) ((argc == apos + 2 || argc == apos + 3) && (code_pos > 1))) { /* post or put */ + /* get unproxied endpoint from address string */ + if (_addrstr2remote(argv[apos], &remote)) { + printf("'%s' is not a valid address\n", argv[apos]); + return _print_usage(argv); + } + char *uri = NULL; int uri_len = 0; if (code_pos) { @@ -300,43 +337,52 @@ int gcoap_cli_cmd(int argc, char **argv) } if (_proxied) { - sock_udp_ep_t tmp_remote; - if (sock_udp_name2ep(&tmp_remote, argv[apos]) != 0) { - return _print_usage(argv); - } - - if (tmp_remote.port == 0) { - if (IS_USED(MODULE_GCOAP_DTLS)) { - tmp_remote.port = CONFIG_GCOAPS_PORT; - } - else { - tmp_remote.port = CONFIG_GCOAP_PORT; - } - } - #ifdef SOCK_HAS_IPV6 char addrstr[IPV6_ADDR_MAX_STR_LEN]; #else char addrstr[IPV4_ADDR_MAX_STR_LEN]; #endif - inet_ntop(tmp_remote.family, &tmp_remote.addr, addrstr, sizeof(addrstr)); + inet_ntop(remote.family, &remote.addr, addrstr, sizeof(addrstr)); - if (tmp_remote.family == AF_INET6) { + if (remote.family == AF_INET6) { uri_len = snprintf(proxy_uri, sizeof(proxy_uri), "coap://[%s]:%d%s", - addrstr, tmp_remote.port, uri); + addrstr, remote.port, uri); } else { uri_len = snprintf(proxy_uri, sizeof(proxy_uri), "coap://%s:%d%s", - addrstr, tmp_remote.port, uri); + addrstr, remote.port, uri); } uri = proxy_uri; + } + + gcoap_req_init(&pdu, buf, CONFIG_GCOAP_PDU_BUF_SIZE, code_pos, NULL); + + if (observe) { + uint8_t *token = coap_get_token(&pdu); + if (obs_value == COAP_OBS_REGISTER) { + obs_req_tkl = coap_get_token_len(&pdu); + /* backup the token of the initial observe registration */ + memcpy(obs_req_token, token, obs_req_tkl); + } else { + /* use the token of the registration for deregistration + * (manually replace the token set by gcoap_req_init) */ + memcpy(token, obs_req_token, obs_req_tkl); + if (gcoap_obs_req_forget(&remote, obs_req_token, obs_req_tkl)) { + printf("could not remove observe request\n"); + return 1; + } + } - gcoap_req_init(&pdu, &buf[0], CONFIG_GCOAP_PDU_BUF_SIZE, code_pos, NULL); + coap_opt_add_uint(&pdu, COAP_OPT_OBSERVE, obs_value); } - else { - gcoap_req_init(&pdu, &buf[0], CONFIG_GCOAP_PDU_BUF_SIZE, code_pos, uri); + + if (!_proxied) { + /* add uri path option separately + * (options must be added in order) */ + coap_opt_add_uri_path(&pdu, uri); } + coap_hdr_set_type(pdu.hdr, msg_type); memset(_last_req_path, 0, _LAST_REQ_PATH_MAX); @@ -369,18 +415,23 @@ int gcoap_cli_cmd(int argc, char **argv) } printf("gcoap_cli: sending msg ID %u, %" PRIuSIZE " bytes\n", - coap_get_id(&pdu), len); - if (!_send(&buf[0], len, argv[apos])) { + coap_get_id(&pdu), len); + if (!_send(&buf[0], len, _proxied ? &_proxy_remote : &remote)) { puts("gcoap_cli: msg send failed"); } else { + if (observe) { + /* on successful observe request, store that this node is + * observing / not observing anymore */ + observing = obs_value == COAP_OBS_REGISTER; + } /* send Observe notification for /cli/stats */ notify_observers(); } return 0; } else { - printf("usage: %s [-c] [:port] [data]\n", + printf("usage: %s [-c] [:port] [data]\n", argv[0]); printf(" %s ping [:port]\n", argv[0]); printf("Options\n"); diff --git a/examples/gcoap_block_server/gcoap_block.c b/examples/gcoap_block_server/gcoap_block.c index 5aece7bde6b4d..cee4a7bd6a95f 100644 --- a/examples/gcoap_block_server/gcoap_block.c +++ b/examples/gcoap_block_server/gcoap_block.c @@ -65,7 +65,7 @@ static ssize_t _riot_block2_handler(coap_pkt_t *pdu, uint8_t *buf, size_t len, c plen += coap_blockwise_put_bytes(&slicer, buf+plen, block2_board, sizeof(block2_board)-1); plen += coap_blockwise_put_bytes(&slicer, buf+plen, (uint8_t*)RIOT_BOARD, strlen(RIOT_BOARD)); plen += coap_blockwise_put_bytes(&slicer, buf+plen, block2_mcu, sizeof(block2_mcu)-1); - plen += coap_blockwise_put_bytes(&slicer, buf+plen, (uint8_t*)RIOT_MCU, strlen(RIOT_MCU)); + plen += coap_blockwise_put_bytes(&slicer, buf+plen, (uint8_t*)RIOT_CPU, strlen(RIOT_CPU)); /* To demonstrate individual chars */ plen += coap_blockwise_put_char(&slicer, buf+plen, ' '); plen += coap_blockwise_put_char(&slicer, buf+plen, 'M'); diff --git a/examples/hello-world/main.c b/examples/hello-world/main.c index f51bf8c0a0ffb..213128ac64e8d 100644 --- a/examples/hello-world/main.c +++ b/examples/hello-world/main.c @@ -26,7 +26,7 @@ int main(void) puts("Hello World!"); printf("You are running RIOT on a(n) %s board.\n", RIOT_BOARD); - printf("This board features a(n) %s MCU.\n", RIOT_MCU); + printf("This board features a(n) %s CPU.\n", RIOT_CPU); return 0; } diff --git a/examples/javascript/Makefile.ci b/examples/javascript/Makefile.ci index 064f53dcca194..71a46135b928a 100644 --- a/examples/javascript/Makefile.ci +++ b/examples/javascript/Makefile.ci @@ -47,7 +47,6 @@ BOARD_INSUFFICIENT_MEMORY := \ samd10-xmini \ saml10-xpro \ saml11-xpro \ - seeedstudio-gd32 \ sipeed-longan-nano \ sipeed-longan-nano-tft \ slstk3400a \ diff --git a/examples/javascript/main.c b/examples/javascript/main.c index 27939eeb34643..33568df7181a8 100644 --- a/examples/javascript/main.c +++ b/examples/javascript/main.c @@ -69,7 +69,7 @@ int js_run(const jerry_char_t *script, size_t script_size) int main(void) { printf("You are running RIOT on a(n) %s board.\n", RIOT_BOARD); - printf("This board features a(n) %s MCU.\n", RIOT_MCU); + printf("This board features a(n) %s CPU.\n", RIOT_CPU); printf("Executing main.js:\n"); diff --git a/examples/micropython/Makefile b/examples/micropython/Makefile index e5e7829693ef4..f337823456a97 100644 --- a/examples/micropython/Makefile +++ b/examples/micropython/Makefile @@ -32,7 +32,7 @@ FEATURES_OPTIONAL += periph_spi TESTRUNNER_RESET_AFTER_TERM ?= 1 # failing on native with floating point exception (#15870) -TEST_ON_CI_BLACKLIST = native +TEST_ON_CI_BLACKLIST += native native64 # avoid running Kconfig by default SHOULD_RUN_KCONFIG ?= diff --git a/examples/nanocoap_server/coap_handler.c b/examples/nanocoap_server/coap_handler.c index 2a04452b9fdfd..fd214ea90abf2 100644 --- a/examples/nanocoap_server/coap_handler.c +++ b/examples/nanocoap_server/coap_handler.c @@ -64,7 +64,7 @@ static ssize_t _riot_block2_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len, c bufpos += coap_blockwise_put_bytes(&slicer, bufpos, block2_board, sizeof(block2_board)-1); bufpos += coap_blockwise_put_bytes(&slicer, bufpos, (uint8_t*)RIOT_BOARD, strlen(RIOT_BOARD)); bufpos += coap_blockwise_put_bytes(&slicer, bufpos, block2_mcu, sizeof(block2_mcu)-1); - bufpos += coap_blockwise_put_bytes(&slicer, bufpos, (uint8_t*)RIOT_MCU, strlen(RIOT_MCU)); + bufpos += coap_blockwise_put_bytes(&slicer, bufpos, (uint8_t*)RIOT_CPU, strlen(RIOT_CPU)); /* To demonstrate individual chars */ bufpos += coap_blockwise_put_char(&slicer, bufpos, ' '); bufpos += coap_blockwise_put_char(&slicer, bufpos, 'M'); diff --git a/examples/nimble_gatt/main.c b/examples/nimble_gatt/main.c index 12394afe718c4..441a7e4b55570 100644 --- a/examples/nimble_gatt/main.c +++ b/examples/nimble_gatt/main.c @@ -162,7 +162,7 @@ static int gatt_svr_chr_access_device_info_model( snprintf(str_answer, STR_ANSWER_BUFFER_SIZE, "You are running RIOT on a(n) %s board, " - "which features a(n) %s MCU.", RIOT_BOARD, RIOT_MCU); + "which features a(n) %s CPU.", RIOT_BOARD, RIOT_CPU); puts(str_answer); int rc = os_mbuf_append(ctxt->om, str_answer, strlen(str_answer)); diff --git a/examples/rust-hello-world/Cargo.toml b/examples/rust-hello-world/Cargo.toml index 62fb856159a7f..215d2fe63bfa4 100644 --- a/examples/rust-hello-world/Cargo.toml +++ b/examples/rust-hello-world/Cargo.toml @@ -17,7 +17,7 @@ panic = "abort" [dependencies] riot-wrappers = { version = "0.8", features = [ "set_panic_handler" ] } -# While currently this exmple does not use any RIOT modules implemented in +# While currently this example does not use any RIOT modules implemented in # Rust, that may change; it is best practice for any RIOT application that has # its own top-level Rust crate to include rust_riotmodules from inside # RIOTBASE. diff --git a/examples/suit_update/Makefile b/examples/suit_update/Makefile index 3ca57555d7f66..9ceef160040d0 100644 --- a/examples/suit_update/Makefile +++ b/examples/suit_update/Makefile @@ -38,6 +38,7 @@ QUIET ?= 1 # USEMODULE += suit suit_transport_coap +USEMODULE += nanocoap_server_auto_init # enable VFS transport (only works on boards with external storage) USEMODULE += suit_transport_vfs diff --git a/examples/suit_update/coap_handler.c b/examples/suit_update/coap_handler.c index 5d31e76fa8df1..0c15aac7a40bd 100644 --- a/examples/suit_update/coap_handler.c +++ b/examples/suit_update/coap_handler.c @@ -22,13 +22,8 @@ static ssize_t _riot_board_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len, COAP_FORMAT_TEXT, (uint8_t*)RIOT_BOARD, strlen(RIOT_BOARD)); } -/* must be sorted by path (ASCII order) */ -const coap_resource_t coap_resources[] = { - COAP_WELL_KNOWN_CORE_DEFAULT_HANDLER, - { "/riot/board", COAP_GET, _riot_board_handler, NULL }, - - /* this line adds the whole "/suit"-subtree */ - SUIT_COAP_SUBTREE, +NANOCOAP_RESOURCE(board) { + .path = "/riot/board", .methods = COAP_GET, .handler = _riot_board_handler, }; -const unsigned coap_resources_numof = ARRAY_SIZE(coap_resources); +NANOCOAP_RESOURCE(suit) SUIT_COAP_SUBTREE; diff --git a/examples/suit_update/main.c b/examples/suit_update/main.c index a2995d2ae2d03..9fbc99063b8ca 100644 --- a/examples/suit_update/main.c +++ b/examples/suit_update/main.c @@ -44,13 +44,6 @@ #include "periph/gpio.h" #endif -#define COAP_INBUF_SIZE (256U) - -/* Extend stacksize of nanocoap server thread */ -static char _nanocoap_server_stack[THREAD_STACKSIZE_DEFAULT + THREAD_EXTRA_STACKSIZE_PRINTF]; -#define NANOCOAP_SERVER_QUEUE_SIZE (8) -static msg_t _nanocoap_server_msg_queue[NANOCOAP_SERVER_QUEUE_SIZE]; - #define MAIN_QUEUE_SIZE (8) static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; @@ -63,21 +56,6 @@ XFA(suit_storage_files_reg, 1) char* _slot1 = VFS_DEFAULT_DATA "/SLOT1.txt"; #endif #endif -static void *_nanocoap_server_thread(void *arg) -{ - (void)arg; - - /* nanocoap_server uses gnrc sock which uses gnrc which needs a msg queue */ - msg_init_queue(_nanocoap_server_msg_queue, NANOCOAP_SERVER_QUEUE_SIZE); - - /* initialize nanocoap server instance */ - uint8_t buf[COAP_INBUF_SIZE]; - sock_udp_ep_t local = { .port=COAP_PORT, .family=AF_INET6 }; - nanocoap_server(&local, buf, sizeof(buf)); - - return NULL; -} - /* assuming that first button is always BTN0 */ #if defined(MODULE_PERIPH_GPIO_IRQ) && defined(BTN0_PIN) static void cb(void *arg) @@ -213,12 +191,6 @@ int main(void) /* initialize suit storage */ suit_storage_init_all(); - /* start nanocoap server thread */ - thread_create(_nanocoap_server_stack, sizeof(_nanocoap_server_stack), - THREAD_PRIORITY_MAIN - 1, - THREAD_CREATE_STACKTEST, - _nanocoap_server_thread, NULL, "nanocoap server"); - /* the shell contains commands that receive packets via GNRC and thus needs a msg queue */ msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE); diff --git a/makefiles/arch/riscv.inc.mk b/makefiles/arch/riscv.inc.mk index ebe62eddbd1a6..675c7737e08fe 100644 --- a/makefiles/arch/riscv.inc.mk +++ b/makefiles/arch/riscv.inc.mk @@ -8,12 +8,9 @@ # Ubuntu uses "riscv64-unknown-elf" despite being able to produce both 32 and # 64 bit binaries. We'll test all possible combinations from the most correct # triple to the least correct triple all that might be able to produce our -# binaries. Finally, "riscv-none-embed" is also tested for compatibility with -# an previously popular legacy toolchain. -# For a CI transition period, it is tested first. +# binaries. _TRIPLES_TO_TEST := \ - riscv-none-embed \ riscv32-none-elf \ riscv32-unknown-elf \ riscv32-elf \ @@ -27,7 +24,7 @@ _TRIPLES_TO_TEST := \ # Do not test at run time if building with docker: The host may have no # RISC-V toolchain installed or a different one ifeq (1,$(BUILD_IN_DOCKER)) - TARGET_ARCH_RISCV := riscv-none-embed + TARGET_ARCH_RISCV := riscv-none-elf endif TARGET_ARCH_RISCV ?= \ diff --git a/makefiles/cargo-targets.inc.mk b/makefiles/cargo-targets.inc.mk index 47fa12214e9e2..de45a0c7c1f61 100644 --- a/makefiles/cargo-targets.inc.mk +++ b/makefiles/cargo-targets.inc.mk @@ -37,7 +37,6 @@ $(CARGO_COMPILE_COMMANDS): $(BUILDDEPS) -e 's/"riscv64-none-elf"/"riscv32"/g' \ -e 's/"riscv64-unknown-elf"/"riscv32"/g' \ -e 's/"riscv64-elf"/"riscv32"/g' \ - -e 's/"riscv-none-embed"/"riscv32"/g' \ | $(LAZYSPONGE) $@ diff --git a/makefiles/info.inc.mk b/makefiles/info.inc.mk index fdaff029e07e2..a7b19dc405e98 100644 --- a/makefiles/info.inc.mk +++ b/makefiles/info.inc.mk @@ -39,7 +39,6 @@ info-build: @echo '' @echo 'BOARD: $(BOARD)' @echo 'CPU: $(CPU)' - @echo 'MCU: $(MCU)' @echo '' @echo 'RIOTBASE: $(RIOTBASE)' @echo 'BOARDDIR: $(BOARDDIR)' @@ -153,7 +152,6 @@ info-build-json: @echo '"APPDIR": "$(APPDIR)",' @echo '"BOARD": "$(BOARD)",' @echo '"CPU": "$(CPU)",' - @echo '"MCU": "$(MCU)",' @echo '"RIOTBASE": "$(RIOTBASE)",' @echo '"BOARDDIR": "$(BOARDDIR)",' @echo '"RIOTCPU": "$(RIOTCPU)",' diff --git a/makefiles/vars.inc.mk b/makefiles/vars.inc.mk index 42992202a3ef2..ce6c4e15b2fc8 100644 --- a/makefiles/vars.inc.mk +++ b/makefiles/vars.inc.mk @@ -17,7 +17,6 @@ export CPU_MODEL # The specific identifier of the used CPU, used for export CPU_CORE # The specific identifier of the core present in the CPU. Needed for depency resolution. export CPU_ARCH # The specific identifier of the architecture of the core defined in CPU_CORE. export CPU_FAM # An intermediate identifier between CPU and CPU_MODEL that represents a sub-group of a Manufacturers CPU's. -export MCU # The MCU, set by the board's Makefile.include, or defaulted to the same value as CPU. export INCLUDES # The extra include paths, set by the various Makefile.include files. export CXXINCLUDES # The extra include paths for c++, set by the various Makefile.include files. export NATIVEINCLUDES # The native include paths, set by the various native Makefile.include files. @@ -59,7 +58,7 @@ export FEATURES_REQUIRED # List of required features by the application export FEATURES_PROVIDED # List of provided features by the board export FEATURES_OPTIONAL # List of nice to have features export FEATURES_USED # List of features used -# TOOLCHAINS_SUPPORTED # List of supported toolchains by an MCU (gnu/llvm/...). +# TOOLCHAINS_SUPPORTED # List of supported toolchains by a CPU (gnu/llvm/...). # TOOLCHAINS_BLACKLISTED # List of unspported toolchains for a module or an application. export TOOLCHAIN # Base build toolchain, i.e. GNU or LLVM diff --git a/pkg/flashdb/Kconfig b/pkg/flashdb/Kconfig index 8d66a50be0a5a..0d9fdef41cf3d 100644 --- a/pkg/flashdb/Kconfig +++ b/pkg/flashdb/Kconfig @@ -41,6 +41,15 @@ config MODULE_FLASHDB_KVDB_AUTO_UPDATE database. If the version changes, it will automatically trigger an upgrade action and update the new default KV collection to the current database. +config FLASHDB_MIN_SECTOR_SIZE_DEFAULT_KiB + int "Minimal virtual sector size in KiB for FlashDB" + default 4 + help + By default, KVDB will use 1 times the block size as the sector size, that is, 4096. + At this time, the KVDB cannot store a KV longer than 4096. If you want to save, for example, + a KV with a length of 10K, you can use the control function to set the sector size to 12K or + larger. + config MODULE_FLASHDB_MTD endif # PACKAGE_FLASHDB diff --git a/pkg/flashdb/include/fal_cfg.h b/pkg/flashdb/include/fal_cfg.h index 557b28658eb00..8f960e95880fe 100644 --- a/pkg/flashdb/include/fal_cfg.h +++ b/pkg/flashdb/include/fal_cfg.h @@ -26,11 +26,40 @@ #define FAL_CFG_H #include "board.h" +#include "macros/units.h" +#include "mtd_default.h" #ifdef __cplusplus extern "C" { #endif +#if !defined(CONFIG_FLASHDB_MIN_SECTOR_SIZE_DEFAULT_KiB) || defined(DOXYGEN) +/** + * @brief Minimal virtual sector size in KiB for FlashDB + * + * This is just a reasonable default for an automatic partition configuration, hence "DEFAULT". + * The "MIN" stands for a required minimum to guarantee an expected size of key value pairs. + * The actually acceptable sector size must be a multiple of the physical sector size though. + * Thus, it can be larger than the minimum required size. + * + * The default is 4 (4096). + * FlashDB sector size is different from MTD sector size as it is a + * virtual measure of granularity and not a device property. + * The virtual sector size must be a multiple of the physical sector size. + * + * From the documentation of FLashDB: + * The internal storage structure of FlashDB is composed of N sectors, and each formatting takes + * sector as the smallest unit. A sector is usually N times the size of the Flash block. + * For example, the block size of Nor Flash is generally 4096. + * + * By default, KVDB will use 1 times the block size as the sector size, that is, 4096. + * At this time, the KVDB cannot store a KV longer than 4096. If you want to save, for example, + * a KV with a length of 10K, you can use the control function to set the sector size to 12K or larger. + * + */ +#define CONFIG_FLASHDB_MIN_SECTOR_SIZE_DEFAULT_KiB 4 +#endif + /** * @brief Partition table is defined at compile time (not read from flash) */ @@ -49,12 +78,48 @@ extern struct fal_flash_dev mtd_flash0; &mtd_flash0, \ } +#if !defined(FAL_MTD) || defined(DOXYGEN) +/** + * @brief Default MTD to use for flashdb + */ +#define FAL_MTD mtd_default_get_dev(0) +#endif + +#if !defined(FAL_PART0_LABEL) || defined(DOXYGEN) +/** + * @brief Have at least the label of partition 0 defined + */ +#define FAL_PART0_LABEL "part0" +#endif + +#if !defined(FAL_PART0_LENGTH) || defined(DOXYGEN) +/** + * @brief Have at least the length of partition 0 defined, which must be at least two sectors + * and a multiple of the virtual sector size. + * + * The virtual sector size is however bound to the physical sector size of @ref FAL_MTD. + * So make sure that @ref CONFIG_FLASHDB_MIN_SECTOR_SIZE_DEFAULT_KiB times 1024 is a multiple of the MTD sector size. + * For example if the MTD sector size is 4KiB, then @ref CONFIG_FLASHDB_MIN_SECTOR_SIZE_DEFAULT_KiB must be a multiple of 4. + * If the MTD sector size is 1KiB, then you have all options for @ref CONFIG_FLASHDB_MIN_SECTOR_SIZE_DEFAULT_KiB. + */ +#define FAL_PART0_LENGTH (2 * (CONFIG_FLASHDB_MIN_SECTOR_SIZE_DEFAULT_KiB * KiB(1))) +#endif + /** * @brief Partition 0 */ -#ifdef FAL_PART0_LABEL +#if defined(FAL_PART0_LABEL) || defined(DOXYGEN) +#if !defined(FAL_PART0_OFFSET) || defined(DOXYGEN) +/** + * @brief Offset of partition 0 + */ +#define FAL_PART0_OFFSET 0 +#endif +/** + * @brief Partition 0 compound definition + */ #define FAL_ROW_PART0 { FAL_PART_MAGIC_WORD, FAL_PART0_LABEL, "fal_mtd", \ - 0, FAL_PART0_LENGTH, 0 }, + FAL_PART0_OFFSET, FAL_PART0_LENGTH, 0 }, #else #define FAL_ROW_PART0 #endif @@ -62,9 +127,18 @@ extern struct fal_flash_dev mtd_flash0; /** * @brief Partition 1 */ -#ifdef FAL_PART1_LABEL +#if defined(FAL_PART1_LABEL) || defined(DOXYGEN) +#if !defined(FAL_PART1_OFFSET) || defined(DOXYGEN) +/** + * @brief Offset of partition 1 + */ +#define FAL_PART1_OFFSET (FAL_PART0_OFFSET + FAL_PART0_LENGTH) +#endif +/** + * @brief Partition 1 compound definition + */ #define FAL_ROW_PART1 { FAL_PART_MAGIC_WORD, FAL_PART1_LABEL, "fal_mtd", \ - FAL_PART0_LENGTH, FAL_PART1_LENGTH, 0 }, + FAL_PART1_OFFSET, FAL_PART1_LENGTH, 0 }, #else #define FAL_ROW_PART1 #endif @@ -72,9 +146,18 @@ extern struct fal_flash_dev mtd_flash0; /** * @brief Partition 2 */ -#ifdef FAL_PART2_LABEL -#define FAL_ROW_PART2 { FAL_PART_MAGIC_WORD, FAL_PART2_LABEL, "fal_mtd", - FAL_PART1_LENGTH, FAL_PART2_LENGTH, 0 }, +#if defined(FAL_PART2_LABEL) || defined(DOXYGEN) +#if !defined(FAL_PART2_OFFSET) || defined(DOXYGEN) +/** + * @brief Offset of partition 2 + */ +#define FAL_PART2_OFFSET (FAL_PART1_OFFSET + FAL_PART1_LENGTH) +#endif +/** + * @brief Partition 2 compound definition + */ +#define FAL_ROW_PART2 { FAL_PART_MAGIC_WORD, FAL_PART2_LABEL, "fal_mtd", \ + FAL_PART2_OFFSET, FAL_PART2_LENGTH, 0 }, #else #define FAL_ROW_PART2 #endif @@ -82,9 +165,18 @@ extern struct fal_flash_dev mtd_flash0; /** * @brief Partition 3 */ -#ifdef FAL_PART3_LABEL -#define FAL_ROW_PART3 { FAL_PART_MAGIC_WORD, FAL_PART2_LABEL, "fal_mtd", - FAL_PART2_LENGTH, FAL_PART3_LENGTH, 0 }, +#if defined(FAL_PART3_LABEL) || defined(DOXYGEN) +#if !defined(FAL_PART3_OFFSET) || defined(DOXYGEN) +/** + * @brief Offset of partition 3 + */ +#define FAL_PART3_OFFSET (FAL_PART2_OFFSET + FAL_PART2_LENGTH) +#endif +/** + * @brief Partition 3 compound definition + */ +#define FAL_ROW_PART3 { FAL_PART_MAGIC_WORD, FAL_PART3_LABEL, "fal_mtd", \ + FAL_PART3_OFFSET, FAL_PART3_LENGTH, 0 }, #else #define FAL_ROW_PART3 #endif diff --git a/pkg/flashdb/mtd/fal_mtd_port.c b/pkg/flashdb/mtd/fal_mtd_port.c index 0d50448fca77e..14e23ae82599a 100644 --- a/pkg/flashdb/mtd/fal_mtd_port.c +++ b/pkg/flashdb/mtd/fal_mtd_port.c @@ -75,7 +75,9 @@ struct fal_flash_dev mtd_flash0 = { void fdb_mtd_init(mtd_dev_t *mtd) { unsigned sector_size; - + if (_mtd) { + return; + } mtd_init(mtd); _mtd = mtd; diff --git a/pkg/micropython/Makefile b/pkg/micropython/Makefile index 75e1ac7a185b8..caec04b6aeafe 100644 --- a/pkg/micropython/Makefile +++ b/pkg/micropython/Makefile @@ -1,6 +1,6 @@ PKG_NAME=micropython PKG_URL=https://github.com/kaspar030/micropython -PKG_VERSION=0e9a7e5d67873125cceb0d02faaf40c80730ac33 +PKG_VERSION=4ff7897215b9f8d65e147935949e88cb7cc28652 PKG_LICENSE=MIT CFLAGS += -Wno-implicit-fallthrough -Wno-unused-parameter -Wno-error diff --git a/pkg/openthread/doc.txt b/pkg/openthread/doc.txt index 4c04a6737ad80..bc35d7f961e0c 100644 --- a/pkg/openthread/doc.txt +++ b/pkg/openthread/doc.txt @@ -4,7 +4,8 @@ * @ingroup net * @brief Provides a RIOT adaption of the OpenThread network stack * @see https://github.com/openthread/openthread - * @note Currently there's only support for @ref drivers_at86rf2xx. - * There's a work in progress to support more radio drivers - * (see [this issue](https://github.com/RIOT-OS/RIOT/issues/10045)) + * @note A good technical introduction to how Thread works is available in + * the [thread primer] of OpenThread. + * + * [thread primer]: https://openthread.io/guides/thread-primer */ diff --git a/pkg/wakaama/contrib/objects/common.c b/pkg/wakaama/contrib/objects/common.c index 4fd97c970abf7..88ec3511e37b4 100644 --- a/pkg/wakaama/contrib/objects/common.c +++ b/pkg/wakaama/contrib/objects/common.c @@ -246,6 +246,8 @@ static int _set_resource_data(lwm2m_client_data_t *client_data, const lwm2m_uri_ /* write the resource of the specified instance */ uint8_t res = object->writeFunc(uri->instanceId, 1, data, object); + lwm2m_resource_value_changed(client_data->lwm2m_ctx, uri); + if (res != COAP_204_CHANGED) { result = -EINVAL; } diff --git a/pkg/wakaama/patches/0021-core-registration-cast-to-time.patch b/pkg/wakaama/patches/0022-core-registration-cast-to-time.patch similarity index 100% rename from pkg/wakaama/patches/0021-core-registration-cast-to-time.patch rename to pkg/wakaama/patches/0022-core-registration-cast-to-time.patch diff --git a/pkg/wakaama/patches/0023-Add-const-modifier-to-URI-on-lwm2m_resource_value_ch.patch b/pkg/wakaama/patches/0023-Add-const-modifier-to-URI-on-lwm2m_resource_value_ch.patch new file mode 100644 index 0000000000000..85a875c7c4587 --- /dev/null +++ b/pkg/wakaama/patches/0023-Add-const-modifier-to-URI-on-lwm2m_resource_value_ch.patch @@ -0,0 +1,39 @@ +From 4cf9ceba3052b385eb2378e474307e1eb4b90aac Mon Sep 17 00:00:00 2001 +From: Leandro Lanzieri +Date: Thu, 1 Feb 2024 10:23:27 +0100 +Subject: [PATCH 1/1] Add const modifier to URI on lwm2m_resource_value_changed + +--- + core/liblwm2m.h | 2 +- + core/observe.c | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/core/liblwm2m.h b/core/liblwm2m.h +index 15fac32..4a439b7 100644 +--- a/core/liblwm2m.h ++++ b/core/liblwm2m.h +@@ -696,7 +696,7 @@ int lwm2m_remove_object(lwm2m_context_t * contextP, uint16_t id); + // If withObjects is true, the registration update contains the object list. + int lwm2m_update_registration(lwm2m_context_t * contextP, uint16_t shortServerID, bool withObjects); + +-void lwm2m_resource_value_changed(lwm2m_context_t * contextP, lwm2m_uri_t * uriP); ++void lwm2m_resource_value_changed(lwm2m_context_t * contextP, const lwm2m_uri_t * uriP); + #endif + + #ifdef LWM2M_SERVER_MODE +diff --git a/core/observe.c b/core/observe.c +index 308448d..3494799 100644 +--- a/core/observe.c ++++ b/core/observe.c +@@ -445,7 +445,7 @@ lwm2m_observed_t * observe_findByUri(lwm2m_context_t * contextP, + } + + void lwm2m_resource_value_changed(lwm2m_context_t * contextP, +- lwm2m_uri_t * uriP) ++ const lwm2m_uri_t * uriP) + { + lwm2m_observed_t * targetP; + +-- +2.43.0 + diff --git a/sys/app_metadata/app_metadata.c b/sys/app_metadata/app_metadata.c index af3fef960d71e..e7c14068553ce 100644 --- a/sys/app_metadata/app_metadata.c +++ b/sys/app_metadata/app_metadata.c @@ -24,7 +24,6 @@ void app_metadata_print_json(void) #ifdef APP_SHELL_FMT printf("{\"data\": {\"APP_SHELL_FMT\": \"%s\"}}\n", APP_SHELL_FMT); #endif - printf("{\"data\": {\"MCU\": \"%s\"}}\n", RIOT_MCU); printf("{\"data\": {\"OS_VERSION\": \"%s\"}}\n", RIOT_VERSION); printf("{\"result\": \"SUCCESS\"}\n"); diff --git a/sys/include/net/gcoap.h b/sys/include/net/gcoap.h index 96f7229312489..8c6370949178d 100644 --- a/sys/include/net/gcoap.h +++ b/sys/include/net/gcoap.h @@ -371,7 +371,8 @@ * - Message Type: Supports non-confirmable (NON) messaging. Additionally * provides a callback on timeout. Provides piggybacked ACK response to a * confirmable (CON) request. - * - Observe extension: Provides server-side registration and notifications. + * - Observe extension: Provides server-side registration and notifications + * and client-side observe. * - Server and Client provide helper functions for writing the * response/request. See the CoAP topic in the source documentation for * details. See the gcoap example for sample implementations. @@ -837,6 +838,7 @@ typedef struct { sock_udp_ep_t *observer; /**< Client endpoint; unused if null */ const coap_resource_t *resource; /**< Entity being observed */ uint8_t token[GCOAP_TOKENLEN_MAX]; /**< Client token for notifications */ + uint16_t last_msgid; /**< Message ID of last notification */ unsigned token_len; /**< Actual length of token attribute */ gcoap_socket_t socket; /**< Transport type to observer */ } gcoap_observe_memo_t; @@ -1074,6 +1076,37 @@ int gcoap_obs_init(coap_pkt_t *pdu, uint8_t *buf, size_t len, size_t gcoap_obs_send(const uint8_t *buf, size_t len, const coap_resource_t *resource); +/** + * @brief Forgets (invalidates) an existing observe request. + * + * This invalidates the internal (local) observe request state without actually + * sending a deregistration request to the server. Ths mechanism may be referred + * to as passive deregistration, as it does not send a deregistration request. + * This is implemented according to the description in RFC 7641, + * Section 3.6 (Cancellation): 'A client that is no longer interested in + * receiving notifications for a resource can simply "forget" the observation.' + * Successfully invalidating the request by calling this function guarantees + * that the corresponding observe response handler will not be called anymore. + * + * NOTE: There are cases were active deregistration is preferred instead. + * A server may continue sending notifications if it chooses to ignore the RST + * which is meant to indicate the client did not recognize the notification. + * For such server implementations this function must be called *before* + * sending an explicit deregister request (i.e., a GET request with the token + * of the registration and the observe option set to COAP_OBS_DEREGISTER). + * This will instruct the server to stop sending further notifications. + * + * @param[in] remote remote endpoint that hosts the observed resource + * @param[in] token token of the original GET request used for registering + * an observe + * @param[in] tokenlen the length of the token in bytes + * + * @return 0 on success + * @return < 0 on error + */ +int gcoap_obs_req_forget(const sock_udp_ep_t *remote, const uint8_t *token, + size_t tokenlen); + /** * @brief Provides important operational statistics * diff --git a/sys/include/net/nanocoap.h b/sys/include/net/nanocoap.h index 3655fd7bd2a97..d0c86e863d2cd 100644 --- a/sys/include/net/nanocoap.h +++ b/sys/include/net/nanocoap.h @@ -1780,6 +1780,7 @@ static inline size_t coap_opt_put_uri_query(uint8_t *buf, uint16_t lastonum, * @param[out] buf buffer to write to * @param[in,out] lastonum number of previous option (for delta calculation), * or 0 if first option + * May be NULL, then previous option is assumed to be 0. * @param[in] uri ptr into a source URI, to the first character after * the authority component * diff --git a/sys/include/net/nanocoap/cache.h b/sys/include/net/nanocoap/cache.h index 4f9744fb39294..8583b8c52702e 100644 --- a/sys/include/net/nanocoap/cache.h +++ b/sys/include/net/nanocoap/cache.h @@ -220,6 +220,26 @@ int nanocoap_cache_del(const nanocoap_cache_entry_t *ce); */ void nanocoap_cache_key_generate(const coap_pkt_t *req, uint8_t *cache_key); +/** + * @brief Generates a cache key based on only the options in @p req + * + * @param[in] req The request to generate the cache key from + * @param[out] cache_key The generated cache key of SHA256_DIGEST_LENGTH bytes + */ +void nanocoap_cache_key_options_generate(const coap_pkt_t *req, void *cache_key); + +/** + * @brief Generates a cache key based on only the options in @p req without + * any of the blockwise options included in the key + * + * This function can be used to correlate individual requests that are part of a + * blockwise transfer with each other. + * + * @param[in] req The request to generate the cache key from + * @param[out] cache_key The generated cache key of SHA256_DIGEST_LENGTH bytes + */ +void nanocoap_cache_key_blockreq_options_generate(const coap_pkt_t *req, void *cache_key); + /** * @brief Compares two cache keys. * diff --git a/sys/include/net/nanocoap_sock.h b/sys/include/net/nanocoap_sock.h index d1e668cd20c46..55b6881c04bb6 100644 --- a/sys/include/net/nanocoap_sock.h +++ b/sys/include/net/nanocoap_sock.h @@ -318,7 +318,7 @@ static inline void nanocoap_sock_close(nanocoap_sock_t *sock) * @brief Simple synchronous CoAP (confirmable) GET * * @param[in] sock socket to use for the request - * @param[in] path remote path + * @param[in] path remote path and query * @param[out] buf buffer to write response to * @param[in] len length of @p buffer * @@ -332,7 +332,7 @@ ssize_t nanocoap_sock_get(nanocoap_sock_t *sock, const char *path, void *buf, * @brief Simple synchronous CoAP (confirmable) PUT * * @param[in] sock socket to use for the request - * @param[in] path remote path + * @param[in] path remote path and query * @param[in] request buffer containing the payload * @param[in] len length of the payload to send * @param[out] response buffer for the response, may be NULL @@ -349,7 +349,7 @@ ssize_t nanocoap_sock_put(nanocoap_sock_t *sock, const char *path, * @brief Simple non-confirmable PUT * * @param[in] sock socket to use for the request - * @param[in] path remote path + * @param[in] path remote path and query * @param[in] request buffer containing the payload * @param[in] len length of the payload to send * @param[out] response buffer for the response, may be NULL @@ -384,7 +384,7 @@ ssize_t nanocoap_sock_put_url(const char *url, * @brief Simple synchronous CoAP (confirmable) POST * * @param[in] sock socket to use for the request - * @param[in] path remote path + * @param[in] path remote path and query * @param[in] request buffer containing the payload * @param[in] len length of the payload to send * @param[out] response buffer for the response, may be NULL @@ -401,7 +401,7 @@ ssize_t nanocoap_sock_post(nanocoap_sock_t *sock, const char *path, * @brief Simple non-confirmable POST * * @param[in] sock socket to use for the request - * @param[in] path remote path + * @param[in] path remote path and query * @param[in] request buffer containing the payload * @param[in] len length of the payload to send * @param[out] response buffer for the response, may be NULL @@ -437,7 +437,7 @@ ssize_t nanocoap_sock_post_url(const char *url, * ([RFC 8132](https://datatracker.ietf.org/doc/html/rfc8132)) * * @param[in] sock socket to use for the request - * @param[in] path remote path + * @param[in] path remote path and query * @param[in] request buffer containing the payload * @param[in] len length of the payload to send * @param[out] response buffer for the response, may be NULL @@ -455,7 +455,7 @@ ssize_t nanocoap_sock_fetch(nanocoap_sock_t *sock, const char *path, * ([RFC 8132](https://datatracker.ietf.org/doc/html/rfc8132)) * * @param[in] sock socket to use for the request - * @param[in] path remote path + * @param[in] path remote path and query * @param[in] request buffer containing the payload * @param[in] len length of the payload to send * @param[out] response buffer for the response, may be NULL @@ -491,7 +491,7 @@ ssize_t nanocoap_sock_fetch_url(const char *url, * @brief Simple synchronous CoAP (confirmable) DELETE * * @param[in] sock socket to use for the request - * @param[in] path remote path to delete + * @param[in] path remote path (with query) to delete * * @returns 0 on success * @returns <0 on error diff --git a/sys/include/string_utils.h b/sys/include/string_utils.h index 004e284aaf3de..4a6c71ac9f434 100644 --- a/sys/include/string_utils.h +++ b/sys/include/string_utils.h @@ -48,7 +48,7 @@ extern "C" { */ #if !defined(CPU_NATIVE) \ && !(IS_USED(MODULE_PICOLIBC) && __BSD_VISIBLE) \ - && !(IS_USED(MODULE_NEWLIB) && __BSD_VISIBLE && !defined(MCU_ESP8266)) + && !(IS_USED(MODULE_NEWLIB) && __BSD_VISIBLE && !defined(CPU_ESP8266)) /** * @brief Like `memset(dest, 0, n_bytes)`, but secure diff --git a/sys/net/application_layer/gcoap/gcoap.c b/sys/net/application_layer/gcoap/gcoap.c index 1aa0431032780..dae1a3e7fd7f7 100644 --- a/sys/net/application_layer/gcoap/gcoap.c +++ b/sys/net/application_layer/gcoap/gcoap.c @@ -68,8 +68,12 @@ static void _cease_retransmission(gcoap_request_memo_t *memo); static size_t _handle_req(gcoap_socket_t *sock, coap_pkt_t *pdu, uint8_t *buf, size_t len, sock_udp_ep_t *remote); static void _expire_request(gcoap_request_memo_t *memo); -static void _find_req_memo(gcoap_request_memo_t **memo_ptr, coap_pkt_t *pdu, - const sock_udp_ep_t *remote, bool by_mid); +static gcoap_request_memo_t* _find_req_memo_by_mid(const sock_udp_ep_t *remote, + uint16_t mid); +static gcoap_request_memo_t* _find_req_memo_by_token(const sock_udp_ep_t *remote, + const uint8_t *token, size_t tkl); +static gcoap_request_memo_t* _find_req_memo_by_pdu_token(const coap_pkt_t *src_pdu, + const sock_udp_ep_t *remote); static int _find_resource(gcoap_socket_type_t tl_type, coap_pkt_t *pdu, const coap_resource_t **resource_ptr, @@ -79,6 +83,10 @@ static int _find_obs_memo(gcoap_observe_memo_t **memo, sock_udp_ep_t *remote, coap_pkt_t *pdu); static void _find_obs_memo_resource(gcoap_observe_memo_t **memo, const coap_resource_t *resource); + +static void _check_and_expire_obs_memo_last_mid(sock_udp_ep_t *remote, + uint16_t last_notify_mid); + static nanocoap_cache_entry_t *_cache_lookup_memo(gcoap_request_memo_t *cache_key); static void _cache_process(gcoap_request_memo_t *memo, coap_pkt_t *pdu); @@ -401,15 +409,20 @@ static void _process_coap_pdu(gcoap_socket_t *sock, sock_udp_ep_t *remote, sock_ if (coap_get_type(&pdu) == COAP_TYPE_RST) { DEBUG("gcoap: received RST, expiring potentially existing memo\n"); - _find_req_memo(&memo, &pdu, remote, true); + memo = _find_req_memo_by_mid(remote, pdu.hdr->id); if (memo) { event_timeout_clear(&memo->resp_evt_tmout); _expire_request(memo); } + + /* check if this RST is due to the client not being interested + * in receiving observe notifications anymore. */ + _check_and_expire_obs_memo_last_mid(remote, coap_get_id(&pdu)); } /* validate class and type for incoming */ - switch (coap_get_code_class(&pdu)) { + unsigned code_class = coap_get_code_class(&pdu); + switch (code_class) { /* incoming request or empty */ case COAP_CLASS_REQ: if (coap_get_code_raw(&pdu) == COAP_CODE_EMPTY) { @@ -418,7 +431,7 @@ static void _process_coap_pdu(gcoap_socket_t *sock, sock_udp_ep_t *remote, sock_ messagelayer_emptyresponse_type = COAP_TYPE_RST; DEBUG("gcoap: Answering empty CON request with RST\n"); } else if (coap_get_type(&pdu) == COAP_TYPE_ACK) { - _find_req_memo(&memo, &pdu, remote, true); + memo = _find_req_memo_by_mid(remote, pdu.hdr->id); if ((memo != NULL) && (memo->send_limit != GCOAP_SEND_LIMIT_NON)) { DEBUG("gcoap: empty ACK processed, stopping retransmissions\n"); _cease_retransmission(memo); @@ -459,7 +472,7 @@ static void _process_coap_pdu(gcoap_socket_t *sock, sock_udp_ep_t *remote, sock_ case COAP_CLASS_SUCCESS: case COAP_CLASS_CLIENT_FAILURE: case COAP_CLASS_SERVER_FAILURE: - _find_req_memo(&memo, &pdu, remote, false); + memo = _find_req_memo_by_pdu_token(&pdu, remote); if (memo) { switch (coap_get_type(&pdu)) { case COAP_TYPE_CON: @@ -498,6 +511,9 @@ static void _process_coap_pdu(gcoap_socket_t *sock, sock_udp_ep_t *remote, sock_ _cache_process(memo, &pdu); } } + + bool observe_notification = coap_has_observe(&pdu); + if (memo->resp_handler) { memo->resp_handler(memo, &pdu, remote); } @@ -505,7 +521,15 @@ static void _process_coap_pdu(gcoap_socket_t *sock, sock_udp_ep_t *remote, sock_ if (memo->send_limit >= 0) { /* if confirmable */ *memo->msg.data.pdu_buf = 0; /* clear resend PDU buffer */ } - memo->state = GCOAP_MEMO_UNUSED; + + /* The memo must be kept if the response is an observe notification. + * Non-2.xx notifications indicate that the associated observe entry + * was removed on the server side. Then also free the memo here. */ + if (!observe_notification || (code_class != COAP_CLASS_SUCCESS)) { + /* setting the state to unused frees (drops) the memo entry */ + memo->state = GCOAP_MEMO_UNUSED; + } + break; default: DEBUG("gcoap: illegal response type: %u\n", coap_get_type(&pdu)); @@ -520,6 +544,13 @@ static void _process_coap_pdu(gcoap_socket_t *sock, sock_udp_ep_t *remote, sock_ messagelayer_emptyresponse_type = COAP_TYPE_RST; DEBUG("gcoap: Answering unknown CON response with RST to " "shut up sender\n"); + } else { + /* if the response was a (NON) observe notification and there is no + * matching request, the server must be informed that this node is + * no longer interested in this notification. */ + if (coap_has_observe(&pdu)) { + messagelayer_emptyresponse_type = COAP_TYPE_RST; + } } } break; @@ -848,20 +879,18 @@ static int _find_resource(gcoap_socket_type_t tl_type, * Finds the memo for an outstanding request within the _coap_state.open_reqs * array. Matches on remote endpoint and token. * - * memo_ptr[out] -- Registered request memo, or NULL if not found - * src_pdu[in] -- PDU for token to match - * remote[in] -- Remote endpoint to match - * by_mid[in] -- true if matches are to be done based on Message ID, otherwise they are done by - * token + * remote[in] Remote endpoint to match + * token[in] Token to match + * tkl[in] Length of the token in bytes + * + * return Registered request memo, or NULL if not found */ -static void _find_req_memo(gcoap_request_memo_t **memo_ptr, coap_pkt_t *src_pdu, - const sock_udp_ep_t *remote, bool by_mid) +static gcoap_request_memo_t* _find_req_memo_by_token(const sock_udp_ep_t *remote, + const uint8_t *token, size_t tkl) { - *memo_ptr = NULL; /* no need to initialize struct; we only care about buffer contents below */ coap_pkt_t memo_pdu_data; coap_pkt_t *memo_pdu = &memo_pdu_data; - unsigned cmplen = coap_get_token_len(src_pdu); for (int i = 0; i < CONFIG_GCOAP_REQ_WAITING_MAX; i++) { if (_coap_state.open_reqs[i].state == GCOAP_MEMO_UNUSED) { @@ -869,25 +898,64 @@ static void _find_req_memo(gcoap_request_memo_t **memo_ptr, coap_pkt_t *src_pdu, } gcoap_request_memo_t *memo = &_coap_state.open_reqs[i]; - memo_pdu->hdr = gcoap_request_memo_get_hdr(memo); - if (by_mid) { - if ((src_pdu->hdr->id == memo_pdu->hdr->id) - && sock_udp_ep_equal(&memo->remote_ep, remote)) { - *memo_ptr = memo; - break; - } - } else if (coap_get_token_len(memo_pdu) == cmplen) { - if ((memcmp(coap_get_token(src_pdu), coap_get_token(memo_pdu), cmplen) == 0) + + if (coap_get_token_len(memo_pdu) == tkl) { + if ((memcmp(token, coap_get_token(memo_pdu), tkl) == 0) && (sock_udp_ep_equal(&memo->remote_ep, remote) /* Multicast addresses are not considered in matching responses */ || sock_udp_ep_is_multicast(&memo->remote_ep) )) { - *memo_ptr = memo; - break; + return memo; } } } + return NULL; +} + +/* + * Utility wrapper for _find_req_memo_by_token(), using the pdu token. + * Finds the memo for an outstanding request within the _coap_state.open_reqs + * array. Matches on remote endpoint and token of the pdu. + * + * src_pdu[in] PDU which holds the token for matching + * remote[in] Remote endpoint to match + * + * return Registered request memo, or NULL if not found + */ +static gcoap_request_memo_t* _find_req_memo_by_pdu_token( + const coap_pkt_t *src_pdu, + const sock_udp_ep_t *remote) +{ + unsigned tkl = coap_get_token_len(src_pdu); + uint8_t *token = coap_get_token(src_pdu); + return _find_req_memo_by_token(remote, token, tkl); +} + +/* + * Finds the memo for an outstanding request within the _coap_state.open_reqs + * array. Matches on remote endpoint and message ID. + * + * remote[in] Remote endpoint to match + * mid[in] Message ID to match + * + * return Registered request memo, or NULL if not found + */ +static gcoap_request_memo_t* _find_req_memo_by_mid(const sock_udp_ep_t *remote, uint16_t mid) +{ + for (int i = 0; i < CONFIG_GCOAP_REQ_WAITING_MAX; i++) { + if (_coap_state.open_reqs[i].state == GCOAP_MEMO_UNUSED) { + continue; + } + + gcoap_request_memo_t *memo = &_coap_state.open_reqs[i]; + + if ((mid == gcoap_request_memo_get_hdr(memo)->id) && + sock_udp_ep_equal(&memo->remote_ep, remote)) { + return memo; + } + } + return NULL; } /* Calls handler callback on receipt of a timeout message. */ @@ -1003,6 +1071,51 @@ static int _find_obs_memo(gcoap_observe_memo_t **memo, sock_udp_ep_t *remote, return empty_slot; } +/* + * Checks if an observe memo exists for which a notification with the given + * msg ID was sent out. If so, it expires the memo and frees up the + * observer entry if needed. + * + * remote[in] The remote to check for a stale observe memo. + * last_notify_mid[in] The message ID of the last notification send to the + * given remote. + */ +static void _check_and_expire_obs_memo_last_mid(sock_udp_ep_t *remote, + uint16_t last_notify_mid) +{ + /* find observer entry from remote */ + sock_udp_ep_t *observer; + _find_observer(&observer, remote); + + if (observer) { + gcoap_observe_memo_t *stale_obs_memo = NULL; + /* get the observe memo corresponding to the notification with the + * given msg ID. */ + for (unsigned i = 0; i < CONFIG_GCOAP_OBS_REGISTRATIONS_MAX; i++) { + if (_coap_state.observe_memos[i].observer == NULL) { + continue; + } + if ((_coap_state.observe_memos[i].observer == observer) && + (last_notify_mid == _coap_state.observe_memos[i].last_msgid)) { + stale_obs_memo = &_coap_state.observe_memos[i]; + break; + } + } + + if (stale_obs_memo) { + stale_obs_memo->observer = NULL; /* clear memo */ + + /* check if the observer has more observe memos registered... */ + stale_obs_memo = NULL; + _find_obs_memo(&stale_obs_memo, observer, NULL); + if (stale_obs_memo == NULL) { + /* ... if not -> also free the observer entry */ + observer->family = AF_UNSPEC; + } + } + } +} + /* * Find registered observe memo for a resource. * @@ -1482,6 +1595,23 @@ int gcoap_req_init_path_buffer(coap_pkt_t *pdu, uint8_t *buf, size_t len, return (res > 0) ? 0 : res; } +int gcoap_obs_req_forget(const sock_udp_ep_t *remote, const uint8_t *token, + size_t tokenlen) { + int res = -ENOENT; + gcoap_request_memo_t *obs_req_memo; + mutex_lock(&_coap_state.lock); + /* Find existing request memo of the observe */ + obs_req_memo = _find_req_memo_by_token(remote, token, tokenlen); + if (obs_req_memo) { + /* forget the existing observe memo. */ + obs_req_memo->state = GCOAP_MEMO_UNUSED; + res = 0; + } + + mutex_unlock(&_coap_state.lock); + return res; +} + ssize_t gcoap_req_send_tl(const uint8_t *buf, size_t len, const sock_udp_ep_t *remote, gcoap_resp_handler_t resp_handler, void *context, @@ -1678,6 +1808,10 @@ int gcoap_obs_init(coap_pkt_t *pdu, uint8_t *buf, size_t len, coap_pkt_init(pdu, buf, len, hdrlen); _add_generated_observe_option(pdu); + /* Store message ID of the last notification sent. This is needed + * to match a potential RST returned by a client in order to signal + * it does not recognize this notification. */ + memo->last_msgid = msgid; return GCOAP_OBS_INIT_OK; } @@ -1806,7 +1940,7 @@ void gcoap_forward_proxy_find_req_memo(gcoap_request_memo_t **memo_ptr, coap_pkt_t *src_pdu, const sock_udp_ep_t *remote) { - _find_req_memo(memo_ptr, src_pdu, remote, false); + *memo_ptr = _find_req_memo_by_pdu_token(src_pdu, remote); } void gcoap_forward_proxy_post_event(void *arg) diff --git a/sys/net/application_layer/nanocoap/cache.c b/sys/net/application_layer/nanocoap/cache.c index 329b68a7a50e3..6cff2552a6c7a 100644 --- a/sys/net/application_layer/nanocoap/cache.c +++ b/sys/net/application_layer/nanocoap/cache.c @@ -83,11 +83,10 @@ size_t nanocoap_cache_free_count(void) return clist_count(&_empty_list_head); } -void nanocoap_cache_key_generate(const coap_pkt_t *req, uint8_t *cache_key) +static void _cache_key_digest_opts(const coap_pkt_t *req, sha256_context_t *ctx, + bool include_etag, + bool include_blockwise) { - sha256_context_t ctx; - sha256_init(&ctx); - coap_optpos_t opt = {0, 0}; uint8_t *value; @@ -96,7 +95,7 @@ void nanocoap_cache_key_generate(const coap_pkt_t *req, uint8_t *cache_key) if (optlen >= 0) { /* gCoAP forward proxy is ETag-aware, so skip ETag option, * see https://datatracker.ietf.org/doc/html/rfc7252#section-5.4.2 */ - if (IS_USED(MODULE_GCOAP_FORWARD_PROXY) && (opt.opt_num == COAP_OPT_ETAG)) { + if ((!include_etag) && (opt.opt_num == COAP_OPT_ETAG)) { continue; } /* skip NoCacheKey, @@ -104,9 +103,42 @@ void nanocoap_cache_key_generate(const coap_pkt_t *req, uint8_t *cache_key) if ((opt.opt_num & 0x1E) == 0x1C) { continue; } - sha256_update(&ctx, value, optlen); + /* Don't include blockwise (on request) so matching between + * blockwise parts is possible */ + if ((!include_blockwise) && ( + (opt.opt_num == COAP_OPT_BLOCK2) || + (opt.opt_num == COAP_OPT_BLOCK1) + )) { + continue; + } + sha256_update(ctx, &opt.opt_num, sizeof(opt.opt_num)); + sha256_update(ctx, value, optlen); } } +} + +void nanocoap_cache_key_options_generate(const coap_pkt_t *req, void *cache_key) +{ + sha256_context_t ctx; + sha256_init(&ctx); + _cache_key_digest_opts(req, &ctx, true, true); + sha256_final(&ctx, cache_key); +} + +void nanocoap_cache_key_blockreq_options_generate(const coap_pkt_t *req, void *cache_key) +{ + sha256_context_t ctx; + sha256_init(&ctx); + _cache_key_digest_opts(req, &ctx, true, false); + sha256_final(&ctx, cache_key); +} + +void nanocoap_cache_key_generate(const coap_pkt_t *req, uint8_t *cache_key) +{ + sha256_context_t ctx; + sha256_init(&ctx); + + _cache_key_digest_opts(req, &ctx, !(IS_USED(MODULE_GCOAP_FORWARD_PROXY)), true); switch (req->hdr->code) { case COAP_METHOD_FETCH: sha256_update(&ctx, req->payload, req->payload_len); diff --git a/sys/net/application_layer/nanocoap/nanocoap.c b/sys/net/application_layer/nanocoap/nanocoap.c index 86ea74019f8e0..0636ba3fde728 100644 --- a/sys/net/application_layer/nanocoap/nanocoap.c +++ b/sys/net/application_layer/nanocoap/nanocoap.c @@ -999,6 +999,7 @@ size_t coap_opt_put_uri_pathquery(uint8_t *buf, uint16_t *lastonum, const char * { size_t len; const char *query = strchr(uri, '?'); + uint16_t _lastonum = lastonum ? *lastonum : 0; if (query) { len = (query == uri) ? 0 : (query - uri - 1); @@ -1006,16 +1007,20 @@ size_t coap_opt_put_uri_pathquery(uint8_t *buf, uint16_t *lastonum, const char * len = strlen(uri); } - size_t bytes_out = coap_opt_put_string_with_len(buf, *lastonum, + size_t bytes_out = coap_opt_put_string_with_len(buf, _lastonum, COAP_OPT_URI_PATH, uri, len, '/'); if (query) { buf += bytes_out; bytes_out += coap_opt_put_uri_query(buf, COAP_OPT_URI_PATH, query + 1); - *lastonum = COAP_OPT_URI_QUERY; + _lastonum = COAP_OPT_URI_QUERY; } else if (bytes_out) { - *lastonum = COAP_OPT_URI_PATH; + _lastonum = COAP_OPT_URI_PATH; + } + + if (lastonum) { + *lastonum = _lastonum; } return bytes_out; diff --git a/sys/net/application_layer/nanocoap/sock.c b/sys/net/application_layer/nanocoap/sock.c index 892c977498e6f..e9fe5dfd1df95 100644 --- a/sys/net/application_layer/nanocoap/sock.c +++ b/sys/net/application_layer/nanocoap/sock.c @@ -384,7 +384,7 @@ ssize_t nanocoap_sock_get(nanocoap_sock_t *sock, const char *path, void *buf, si pktpos += coap_build_hdr(pkt.hdr, COAP_TYPE_CON, NULL, 0, COAP_METHOD_GET, nanocoap_sock_next_msg_id(sock)); - pktpos += coap_opt_put_uri_path(pktpos, 0, path); + pktpos += coap_opt_put_uri_pathquery(pktpos, NULL, path); pkt.payload = pktpos; pkt.payload_len = 0; @@ -415,12 +415,13 @@ ssize_t _sock_put_post(nanocoap_sock_t *sock, const char *path, unsigned code, .iov_len = max_len, }; + uint16_t lastonum = 0; pktpos += coap_build_hdr(pkt.hdr, type, NULL, 0, code, nanocoap_sock_next_msg_id(sock)); - pktpos += coap_opt_put_uri_path(pktpos, 0, path); + pktpos += coap_opt_put_uri_pathquery(pktpos, &lastonum, path); if (response == NULL && type == COAP_TYPE_NON) { /* all responses (2.xx, 4.xx and 5.xx) are ignored */ - pktpos += coap_opt_put_uint(pktpos, COAP_OPT_URI_PATH, + pktpos += coap_opt_put_uint(pktpos, lastonum, COAP_OPT_NO_RESPONSE, 26); } @@ -533,7 +534,7 @@ ssize_t nanocoap_sock_delete(nanocoap_sock_t *sock, const char *path) pktpos += coap_build_hdr(pkt.hdr, COAP_TYPE_CON, NULL, 0, COAP_METHOD_DELETE, nanocoap_sock_next_msg_id(sock)); - pktpos += coap_opt_put_uri_path(pktpos, 0, path); + pktpos += coap_opt_put_uri_pathquery(pktpos, NULL, path); pkt.payload = pktpos; diff --git a/sys/net/ieee802154.txt b/sys/net/ieee802154.txt index 930e61c532239..b9c58031b10eb 100644 --- a/sys/net/ieee802154.txt +++ b/sys/net/ieee802154.txt @@ -66,9 +66,11 @@ * protocols used on top of it, applications always need to pick their * components; that selection is often guided by standards or organizations * that pick an interoperable set of components (higher-level protocol, MAC, - * band and others), like Thread (6LoWPAN, nonbeacon-enabled, 2.4GHz), + * band and others), like [Thread] \(6LoWPAN, nonbeacon-enabled, 2.4GHz), * WirelessHART (HART, TSCH, 2.4GHz) or 6TiSCH (6LoWPAN, TSCH). * + * [Thread]: https://openthread.io/guides/thread-primer + * * Availability in RIOT * -------------------- * diff --git a/sys/newlib_syscalls_default/syscalls.c b/sys/newlib_syscalls_default/syscalls.c index a5d59eca38430..322957ed12b12 100644 --- a/sys/newlib_syscalls_default/syscalls.c +++ b/sys/newlib_syscalls_default/syscalls.c @@ -24,32 +24,27 @@ * @} */ -#include -#include #include #include +#include +#include #include -#include -#include #include +#include #include -#include +#include -#include "cpu.h" -#include "board.h" -#include "sched.h" -#include "thread.h" -#include "irq.h" #include "log.h" +#include "modules.h" #include "periph/pm.h" +#include "sched.h" +#include "stdio_base.h" +#include "thread.h" + #if MODULE_VFS #include "vfs.h" #endif -#include "stdio_base.h" - -#include - #ifdef MODULE_XTIMER #include #include "div.h" @@ -149,7 +144,23 @@ static const struct heap heaps[NUM_HEAPS] = { */ void _init(void) { - /* nothing to do here */ + /* Definition copied from newlib/libc/stdio/local.h */ + extern void __sinit (struct _reent *); + + /* When running multiple threads: Initialize reentrant structure before the + * scheduler starts. This normally happens upon the first stdio function + * called. However, if no boot message happens this can result in two + * concurrent "first calls" to stdio in data corruption, if no locking is + * used. Except for ESP (which is using its own syscalls.c anyway), this + * currently is the case in RIOT. */ + if (MAXTHREADS > 1) { + /* Also, make an exception for riotboot, which does not use stdio + * at all. This would pull in stdio and increase .text size + * significantly there */ + if (!IS_USED(MODULE_RIOTBOOT)) { + __sinit(_REENT); + } + } } /** diff --git a/tests/build_system/external_board_dirs/main.c b/tests/build_system/external_board_dirs/main.c index f51bf8c0a0ffb..213128ac64e8d 100644 --- a/tests/build_system/external_board_dirs/main.c +++ b/tests/build_system/external_board_dirs/main.c @@ -26,7 +26,7 @@ int main(void) puts("Hello World!"); printf("You are running RIOT on a(n) %s board.\n", RIOT_BOARD); - printf("This board features a(n) %s MCU.\n", RIOT_MCU); + printf("This board features a(n) %s CPU.\n", RIOT_CPU); return 0; } diff --git a/tests/mcuboot/main.c b/tests/mcuboot/main.c index 1a392a5776e9b..150c459378a13 100644 --- a/tests/mcuboot/main.c +++ b/tests/mcuboot/main.c @@ -26,7 +26,7 @@ int main(void) puts("Hello MCUBoot!"); printf("You are running RIOT on a(n) %s board.\n", RIOT_BOARD); - printf("This board features a(n) %s MCU.\n", RIOT_MCU); + printf("This board features a(n) %s CPU.\n", RIOT_CPU); printf("The startup address is: %p\n", (void*)SCB->VTOR); return 0; diff --git a/tests/net/gcoap_dns/Makefile.ci b/tests/net/gcoap_dns/Makefile.ci index 59a516611e2cf..76ab898bcdbcf 100644 --- a/tests/net/gcoap_dns/Makefile.ci +++ b/tests/net/gcoap_dns/Makefile.ci @@ -17,6 +17,8 @@ BOARD_INSUFFICIENT_MEMORY := \ bluepill-stm32f103c8 \ calliope-mini \ derfmega128 \ + hifive1 \ + hifive1b \ i-nucleo-lrwan1 \ im880b \ mega-xplained \ diff --git a/tests/net/gnrc_dhcpv6_relay/Makefile.ci b/tests/net/gnrc_dhcpv6_relay/Makefile.ci index ccbb1ec43b43b..c9899509d64fa 100644 --- a/tests/net/gnrc_dhcpv6_relay/Makefile.ci +++ b/tests/net/gnrc_dhcpv6_relay/Makefile.ci @@ -9,8 +9,6 @@ BOARD_INSUFFICIENT_MEMORY := \ atmega8 \ atxmega-a3bu-xplained \ bluepill-stm32f030c8 \ - hifive1 \ - hifive1b \ i-nucleo-lrwan1 \ im880b \ msb-430 \ diff --git a/tests/net/gnrc_ipv6_ext/Makefile.ci b/tests/net/gnrc_ipv6_ext/Makefile.ci index 050ceb03d7aad..ebe384147a542 100644 --- a/tests/net/gnrc_ipv6_ext/Makefile.ci +++ b/tests/net/gnrc_ipv6_ext/Makefile.ci @@ -9,8 +9,6 @@ BOARD_INSUFFICIENT_MEMORY := \ atmega8 \ atxmega-a3bu-xplained \ bluepill-stm32f030c8 \ - hifive1 \ - hifive1b \ i-nucleo-lrwan1 \ im880b \ msb-430 \ diff --git a/tests/net/gnrc_netif_ipv6_wait_for_global_address/Makefile.ci b/tests/net/gnrc_netif_ipv6_wait_for_global_address/Makefile.ci index 383a0cb827945..9398e7e42fc11 100644 --- a/tests/net/gnrc_netif_ipv6_wait_for_global_address/Makefile.ci +++ b/tests/net/gnrc_netif_ipv6_wait_for_global_address/Makefile.ci @@ -8,6 +8,8 @@ BOARD_INSUFFICIENT_MEMORY := \ atmega328p-xplained-mini \ atmega8 \ bluepill-stm32f030c8 \ + hifive1 \ + hifive1b \ i-nucleo-lrwan1 \ msb-430 \ msb-430h \ diff --git a/tests/net/gnrc_rpl/Makefile b/tests/net/gnrc_rpl/Makefile index 41022218ff2cf..572bb53ba95fd 100644 --- a/tests/net/gnrc_rpl/Makefile +++ b/tests/net/gnrc_rpl/Makefile @@ -27,7 +27,7 @@ host-tools: TEST_DEPS += host-tools -include $(RIOTBASE)/Makefile.include - # Test is flaky and regularly derails unrelated merge trains TEST_ON_CI_BLACKLIST += native native64 + +include $(RIOTBASE)/Makefile.include diff --git a/tests/net/gnrc_rpl_srh/Makefile.ci b/tests/net/gnrc_rpl_srh/Makefile.ci index 050ceb03d7aad..ebe384147a542 100644 --- a/tests/net/gnrc_rpl_srh/Makefile.ci +++ b/tests/net/gnrc_rpl_srh/Makefile.ci @@ -9,8 +9,6 @@ BOARD_INSUFFICIENT_MEMORY := \ atmega8 \ atxmega-a3bu-xplained \ bluepill-stm32f030c8 \ - hifive1 \ - hifive1b \ i-nucleo-lrwan1 \ im880b \ msb-430 \ diff --git a/tests/net/gnrc_sock_dns/Makefile.ci b/tests/net/gnrc_sock_dns/Makefile.ci index 5f0e51735e853..7887a45e86242 100644 --- a/tests/net/gnrc_sock_dns/Makefile.ci +++ b/tests/net/gnrc_sock_dns/Makefile.ci @@ -9,8 +9,6 @@ BOARD_INSUFFICIENT_MEMORY := \ atmega8 \ atxmega-a3bu-xplained \ bluepill-stm32f030c8 \ - hifive1 \ - hifive1b \ i-nucleo-lrwan1 \ msb-430 \ msb-430h \ diff --git a/tests/periph/gpio_ll/Makefile b/tests/periph/gpio_ll/Makefile index eec61d6f1bb3d..d713b1082c8fc 100644 --- a/tests/periph/gpio_ll/Makefile +++ b/tests/periph/gpio_ll/Makefile @@ -46,7 +46,7 @@ CFLAGS += -DPIN_OUT_0=$(PIN_OUT_0) CFLAGS += -DPIN_OUT_1=$(PIN_OUT_1) CFLAGS += -DLOW_ROM=$(LOW_ROM) -ifneq ($(MCU),esp32) +ifneq ($(CPU),esp32) # We only need 1 thread (+ the Idle thread on some platforms) and we really # want this app working on all boards. CFLAGS += -DMAXTHREADS=2 diff --git a/tests/periph/selftest_shield/Makefile b/tests/periph/selftest_shield/Makefile index 06de04b29a235..a67bc8f58a8ab 100644 --- a/tests/periph/selftest_shield/Makefile +++ b/tests/periph/selftest_shield/Makefile @@ -27,7 +27,7 @@ DETAILED_OUTPUT ?= 0 include $(RIOTBASE)/Makefile.include -ifneq ($(MCU),esp32) +ifneq ($(CPU),esp32) # We only need 1 thread (+ the Idle thread on some platforms) and we really # want this app working on as many boards as possible CFLAGS += -DMAXTHREADS=2 diff --git a/tests/periph/spi_dma/Makefile.ci b/tests/periph/spi_dma/Makefile.ci deleted file mode 100644 index df2e10ce92b7b..0000000000000 --- a/tests/periph/spi_dma/Makefile.ci +++ /dev/null @@ -1,6 +0,0 @@ -# Boards not able to accomodate the regular SPI test will not be able to link -# this test. -include ../spi/Makefile.ci -BOARD_INSUFFICIENT_MEMORY += \ - samd10-xmini \ - # diff --git a/tests/pkg/edhoc_c/Makefile b/tests/pkg/edhoc_c/Makefile index 5d6b52fb75833..bc29f9879893f 100644 --- a/tests/pkg/edhoc_c/Makefile +++ b/tests/pkg/edhoc_c/Makefile @@ -35,6 +35,7 @@ USEMODULE += xtimer # This is an optimized stack value based on testing, if you observe # a segmentation fault please increase this stack size. CFLAGS += -DTHREAD_STACKSIZE_MAIN=3*THREAD_STACKSIZE_LARGE +CFLAGS += -DCONFIG_NANOCOAP_SERVER_STACK_SIZE=3*THREAD_STACKSIZE_LARGE # Include responder code CONFIG_INITIATOR ?= 1 @@ -43,5 +44,11 @@ CFLAGS += -DCONFIG_INITIATOR=$(CONFIG_INITIATOR) CONFIG_RESPONDER ?= 1 CFLAGS += -DCONFIG_RESPONDER=$(CONFIG_RESPONDER) + +ifeq (1, $(CONFIG_RESPONDER)) + USEMODULE += nanocoap_server_auto_init + CFLAGS += -DCONFIG_NANOCOAP_SERVER_BUF_SIZE=512 +endif + include $(RIOTBASE)/Makefile.include include $(RIOTMAKE)/default-radio-settings.inc.mk diff --git a/tests/pkg/edhoc_c/Makefile.ci b/tests/pkg/edhoc_c/Makefile.ci index 900df29449908..89ef9b6b2a821 100644 --- a/tests/pkg/edhoc_c/Makefile.ci +++ b/tests/pkg/edhoc_c/Makefile.ci @@ -12,8 +12,6 @@ BOARD_INSUFFICIENT_MEMORY := \ cc2650stk \ e104-bt5010a-tb \ e104-bt5011a-tb \ - hifive1 \ - hifive1b \ i-nucleo-lrwan1 \ im880b \ lsn50 \ diff --git a/tests/pkg/edhoc_c/main.c b/tests/pkg/edhoc_c/main.c index fa478b43bbae1..a87583a6e1c67 100644 --- a/tests/pkg/edhoc_c/main.c +++ b/tests/pkg/edhoc_c/main.c @@ -30,10 +30,6 @@ static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; #if IS_ACTIVE(CONFIG_RESPONDER) -static char _nanocoap_server_stack[THREAD_STACKSIZE_MAIN]; -#define NANOCOAP_SERVER_QUEUE_SIZE (4) -static msg_t _nanocoap_server_msg_queue[NANOCOAP_SERVER_QUEUE_SIZE]; -#define NANOCOAP_BUF_SIZE (512U) extern int responder_cli_init(void); extern int responder_cmd(int argc, char **argv); #endif @@ -54,23 +50,6 @@ static const shell_command_t shell_commands[] = { { NULL, NULL, NULL } }; -#if IS_ACTIVE(CONFIG_RESPONDER) -static void *_nanocoap_server_thread(void *arg) -{ - (void)arg; - - /* nanocoap_server uses gnrc sock which uses gnrc which needs a msg queue */ - msg_init_queue(_nanocoap_server_msg_queue, NANOCOAP_SERVER_QUEUE_SIZE); - - /* initialize nanocoap server instance */ - uint8_t buf[NANOCOAP_BUF_SIZE]; - sock_udp_ep_t local = { .port = COAP_PORT, .family = AF_INET6 }; - nanocoap_server(&local, buf, sizeof(buf)); - - return NULL; -} -#endif - int main(void) { #if IS_ACTIVE(CONFIG_INITIATOR) @@ -82,12 +61,6 @@ int main(void) if (responder_cli_init()) { return -1; } - - /* start nanocoap server thread */ - thread_create(_nanocoap_server_stack, sizeof(_nanocoap_server_stack), - THREAD_PRIORITY_MAIN - 1, - THREAD_CREATE_STACKTEST, - _nanocoap_server_thread, NULL, "nanocoap server"); #endif /* the shell contains commands that receive packets via GNRC and thus diff --git a/tests/pkg/edhoc_c/responder.c b/tests/pkg/edhoc_c/responder.c index 11a59ebea01b4..537737c20b00c 100644 --- a/tests/pkg/edhoc_c/responder.c +++ b/tests/pkg/edhoc_c/responder.c @@ -98,14 +98,10 @@ ssize_t _edhoc_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len, coap_request_c return msg_len; } -/* must be sorted by path (ASCII order) */ -const coap_resource_t coap_resources[] = { - COAP_WELL_KNOWN_CORE_DEFAULT_HANDLER, - { "/.well-known/edhoc", COAP_POST, _edhoc_handler, NULL }, +NANOCOAP_RESOURCE(edhoc) { + .path = "/.well-known/edhoc", .methods = COAP_POST, .handler = _edhoc_handler }; -const unsigned coap_resources_numof = ARRAY_SIZE(coap_resources); - int responder_cmd(int argc, char **argv) { if (argc < 2) { diff --git a/tests/pkg/fff/Makefile b/tests/pkg/fff/Makefile index 84463a0f9cd60..f730ce533344f 100644 --- a/tests/pkg/fff/Makefile +++ b/tests/pkg/fff/Makefile @@ -5,7 +5,7 @@ FEATURES_BLACKLIST += periph_i2c include $(RIOTBASE)/Makefile.include -ifneq ($(MCU),esp32) +ifneq ($(CPU),esp32) # only two threads used CFLAGS += -DMAXTHREADS=2 else diff --git a/tests/pkg/flashdb_fal_cfg/Makefile b/tests/pkg/flashdb_fal_cfg/Makefile new file mode 100644 index 0000000000000..b9730327a0154 --- /dev/null +++ b/tests/pkg/flashdb_fal_cfg/Makefile @@ -0,0 +1,29 @@ +include ../Makefile.pkg_common + +# select the MTD backend +USEMODULE += flashdb_mtd +# enable key-value database +USEMODULE += flashdb_kvdb +# enable time series database +USEMODULE += flashdb_tsdb +# rtc_localtime() +USEMODULE += rtc_utils + +# prefer periph_rtc over periph_rtt +FEATURES_OPTIONAL += periph_rtc +FEATURES_REQUIRED_ANY += periph_rtc|periph_rtt + +CFLAGS += -DFAL_PART1_LABEL=\"part1\" +CFLAGS += -DFAL_PART1_LENGTH=FAL_PART0_LENGTH +CFLAGS += -DFAL_PART2_LABEL=\"part2\" +CFLAGS += -DFAL_PART2_LENGTH=FAL_PART0_LENGTH +CFLAGS += -DFAL_PART3_LABEL=\"part3\" +CFLAGS += -DFAL_PART3_LENGTH=FAL_PART0_LENGTH + +include $(RIOTBASE)/Makefile.include + +# handle RTC backend after inclusion of $(RIOTBASE)/Makefile.include +ifeq (,$(filter periph_rtc,$(FEATURES_USED))) + USEMODULE += rtt_rtc + USEMODULE += ztimer_no_periph_rtt +endif diff --git a/tests/pkg/flashdb_fal_cfg/Makefile.ci b/tests/pkg/flashdb_fal_cfg/Makefile.ci new file mode 100644 index 0000000000000..d55826c7bf3ed --- /dev/null +++ b/tests/pkg/flashdb_fal_cfg/Makefile.ci @@ -0,0 +1,7 @@ +BOARD_INSUFFICIENT_MEMORY := \ + nucleo-f031k6 \ + nucleo-l011k4 \ + samd10-xmini \ + stk3200 \ + stm32f030f4-demo \ + # diff --git a/tests/pkg/flashdb_fal_cfg/main.c b/tests/pkg/flashdb_fal_cfg/main.c new file mode 100644 index 0000000000000..1d7e2b3336258 --- /dev/null +++ b/tests/pkg/flashdb_fal_cfg/main.c @@ -0,0 +1,149 @@ +/* + * Copyright (C) 2023 ML!PA Consulting Gmbh + * + * 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 Short test for the FlashDB FAL configuration initialization + * + * @author Fabian Hüßler + * + * @} + */ + +#include + +#include "container.h" +#include "fal.h" +#include "macros/math.h" +#include "mutex.h" +#include "periph/rtc.h" + +#include + +/** + * @brief FlashDB Magic Word + * + * The value here is not relevant but it must be defined. + */ +#define FAL_PART_MAGIC_WORD 0x45503130 + +/** + * @brief Number of FAL partitions + */ +#define FAL_PART_TABLE_NUMOF ARRAY_SIZE(((const struct fal_partition[])FAL_PART_TABLE)) + +#if !defined(FAL_TSDB_MAX) || defined(DOXYGEN) +/** + * @brief Maximum length of a TSDB entry + */ +#define FAL_TSDB_MAX 128 +#endif + +#if !defined(FAL_PART_TABLE_KVDB) || defined(DOXYGEN) +/** + * @brief Indices of partitions in @ref FAL_PART_TABLE that can be initialized as a Key-Value-DB + */ +#define FAL_PART_TABLE_KVDB \ +{ \ + 0, \ + 1, \ +} +#endif + +#if !defined(FAL_PART_TABLE_TSDB) || defined(DOXYGEN) +/** + * @brief Indices of partitions in @ref FAL_PART_TABLE that can be initialized as a Time-Series-DB + */ +#define FAL_PART_TABLE_TSDB \ +{ \ + 2, \ + 3, \ +} +#endif + +extern void fdb_mtd_init(mtd_dev_t *mtd); + +static mutex_t _locker = MUTEX_INIT; +static const unsigned _fdb_part_kvdb[] = FAL_PART_TABLE_KVDB; +static const unsigned _fdb_part_tsdb[] = FAL_PART_TABLE_TSDB; +static struct fdb_kvdb _kvdb[ARRAY_SIZE(_fdb_part_kvdb)]; +static struct fdb_tsdb _tsdb[ARRAY_SIZE(_fdb_part_tsdb)]; + +/** + * @brief Select MTD device to use for FlashDB + */ +#if !defined(FDB_MTD) +#define FDB_MTD FAL_MTD +#endif + +static void _lock(fdb_db_t db) +{ + mutex_lock(db->user_data); +} + +static void _unlock(fdb_db_t db) +{ + mutex_unlock(db->user_data); +} + +static fdb_time_t _get_time(void) +{ + struct tm now; + rtc_get_time(&now); + return mktime(&now); +} + +int main(void) +{ + int init_failed; + fdb_mtd_init(FDB_MTD); + size_t size = FDB_MTD->pages_per_sector * FDB_MTD->page_size; + /* scale hardware sector size to minimum required virtual sector size */ + size = DIV_ROUND_UP((CONFIG_FLASHDB_MIN_SECTOR_SIZE_DEFAULT_KiB * KiB(1)), size) * size; + printf("Informational: Make sure the following requirements are fulfilled for a successful initialization:\n"); + printf("The virtual sector size is a multiple of the physical sector size: %lu %% %lu == 0\n", + (unsigned long)size, (unsigned long)FDB_MTD->pages_per_sector * FDB_MTD->page_size); + printf("The maximum partition size is a multiple of the virtual sector size: %lu %% %lu == 0\n", + (unsigned long)FAL_PART0_LENGTH, (unsigned long)size); + + for (unsigned i = 0; i < ARRAY_SIZE(_fdb_part_kvdb); i++) { + unsigned part = _fdb_part_kvdb[i]; + if (part >= FAL_PART_TABLE_NUMOF) { + continue; + } + fdb_kvdb_control(&_kvdb[i], FDB_KVDB_CTRL_SET_SEC_SIZE, &size); + fdb_kvdb_control(&_kvdb[i], FDB_KVDB_CTRL_SET_LOCK, (void *)(uintptr_t)_lock); + fdb_kvdb_control(&_kvdb[i], FDB_KVDB_CTRL_SET_UNLOCK, (void *)(uintptr_t)_unlock); + const char *spart = ((const struct fal_partition[])FAL_PART_TABLE)[part].name; + printf("Initializing FlashDB KVDB partition %s\n", spart); + if ((init_failed = fdb_kvdb_init(&_kvdb[i], "kvdb", spart, NULL, &_locker)) != FDB_NO_ERR) { + printf("Failed to initialize FlashDB KVDB partition %s (%d)\n", spart, init_failed); + return 1; + } + } + for (unsigned i = 0; i < ARRAY_SIZE(_fdb_part_tsdb); i++) { + unsigned part = _fdb_part_tsdb[i]; + if (part >= FAL_PART_TABLE_NUMOF) { + continue; + } + fdb_tsdb_control(&_tsdb[i], FDB_TSDB_CTRL_SET_LOCK, (void *)(uintptr_t)_lock); + fdb_tsdb_control(&_tsdb[i], FDB_TSDB_CTRL_SET_UNLOCK, (void *)(uintptr_t)_unlock); + fdb_tsdb_control(&_tsdb[i], FDB_TSDB_CTRL_SET_SEC_SIZE, &size); + const char *spart = ((const struct fal_partition[])FAL_PART_TABLE)[part].name; + printf("Initializing FlashDB TSDB partition %s\n", spart); + if ((init_failed = fdb_tsdb_init(&_tsdb[i], "tsdb", spart, _get_time, FAL_TSDB_MAX, &_locker)) != FDB_NO_ERR) { + printf("Failed to initialize FlashDB TSDB partition %s (%d)\n", spart, init_failed); + return 1; + } + } + puts("SUCCESS"); + return 0; +} diff --git a/tests/pkg/flashdb_mtd/Makefile.ci b/tests/pkg/flashdb_mtd/Makefile.ci new file mode 100644 index 0000000000000..d55826c7bf3ed --- /dev/null +++ b/tests/pkg/flashdb_mtd/Makefile.ci @@ -0,0 +1,7 @@ +BOARD_INSUFFICIENT_MEMORY := \ + nucleo-f031k6 \ + nucleo-l011k4 \ + samd10-xmini \ + stk3200 \ + stm32f030f4-demo \ + # diff --git a/tests/pkg/flashdb_vfs/main.c b/tests/pkg/flashdb_vfs/main.c index 8d2dbd223b18c..e8e8c1a92880b 100644 --- a/tests/pkg/flashdb_vfs/main.c +++ b/tests/pkg/flashdb_vfs/main.c @@ -9,6 +9,7 @@ #include #include +#include "fal_cfg.h" #include "board.h" #include "mutex.h" #ifdef MODULE_VFS @@ -20,8 +21,8 @@ /** * @brief Select MTD device to use for FlashDB */ -#if !defined(FDB_MTD) && defined(MTD_0) -#define FDB_MTD MTD_0 +#if !defined(FDB_MTD) +#define FDB_MTD FAL_MTD #endif #define FDB_LOG_TAG "[main]" diff --git a/tests/pkg/lwip/Makefile.ci b/tests/pkg/lwip/Makefile.ci index 344bce718dc81..bca4d0c08d00f 100644 --- a/tests/pkg/lwip/Makefile.ci +++ b/tests/pkg/lwip/Makefile.ci @@ -3,8 +3,6 @@ BOARD_INSUFFICIENT_MEMORY := \ blackpill-stm32f103c8 \ bluepill-stm32f030c8 \ bluepill-stm32f103c8 \ - hifive1 \ - hifive1b \ i-nucleo-lrwan1 \ nrf6310 \ nucleo-c031c6 \ diff --git a/tests/pkg/openwsn/main.c b/tests/pkg/openwsn/main.c index 2597279214c92..cf79aaaf0614b 100644 --- a/tests/pkg/openwsn/main.c +++ b/tests/pkg/openwsn/main.c @@ -36,7 +36,7 @@ int main(void) puts("OpenWSN UDP 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); + printf("This board features a(n) %s CPU.\n", RIOT_CPU); udp_cli_init(); diff --git a/tests/pkg/wolfcrypt-ed25519-verify/main.c b/tests/pkg/wolfcrypt-ed25519-verify/main.c index 3646c34d008c6..e6c9e33264083 100644 --- a/tests/pkg/wolfcrypt-ed25519-verify/main.c +++ b/tests/pkg/wolfcrypt-ed25519-verify/main.c @@ -49,7 +49,7 @@ int main(void) int ret; ed25519_key key; LOG_INFO("You are running RIOT on a(n) %s board.\n", RIOT_BOARD); - LOG_INFO("This board features a(n) %s MCU.\n", RIOT_MCU); + LOG_INFO("This board features a(n) %s CPU.\n", RIOT_CPU); wc_ed25519_init(&key); LOG_INFO("Starting ed25519 test.\n"); diff --git a/tests/riotboot/main.c b/tests/riotboot/main.c index 8064b41d2bb57..802d50671c01e 100644 --- a/tests/riotboot/main.c +++ b/tests/riotboot/main.c @@ -80,7 +80,7 @@ int main(void) puts("Hello riotboot!"); printf("You are running RIOT on a(n) %s board.\n", RIOT_BOARD); - printf("This board features a(n) %s MCU.\n", RIOT_MCU); + printf("This board features a(n) %s CPU.\n", RIOT_CPU); /* print some information about the running image */ current_slot = riotboot_slot_current(); diff --git a/tests/riotboot_flashwrite/Makefile b/tests/riotboot_flashwrite/Makefile index 739f759942b4d..d28d27c14e62e 100644 --- a/tests/riotboot_flashwrite/Makefile +++ b/tests/riotboot_flashwrite/Makefile @@ -11,8 +11,8 @@ USEMODULE += sock_udp # Additional networking modules that can be dropped if not needed USEMODULE += gnrc_icmpv6_echo -# Required for nanocoap server -USEMODULE += nanocoap_sock +# Enable nanocoap server +USEMODULE += nanocoap_server_auto_init # include this for printing IP addresses USEMODULE += shell_cmds_default diff --git a/tests/riotboot_flashwrite/coap_handler.c b/tests/riotboot_flashwrite/coap_handler.c index 4a892e10c703a..12a09de839163 100644 --- a/tests/riotboot_flashwrite/coap_handler.c +++ b/tests/riotboot_flashwrite/coap_handler.c @@ -78,10 +78,9 @@ ssize_t _flashwrite_handler(coap_pkt_t* pkt, uint8_t *buf, size_t len, coap_requ return pkt_pos - (uint8_t*)pkt->hdr; } -/* must be sorted by path (ASCII order) */ -const coap_resource_t coap_resources[] = { - COAP_WELL_KNOWN_CORE_DEFAULT_HANDLER, - { "/flashwrite", COAP_POST, _flashwrite_handler, &_writer }, +NANOCOAP_RESOURCE(flashwrite) { + .path = "/flashwrite", + .methods = COAP_POST, + .handler = _flashwrite_handler, + .context = &_writer }; - -const unsigned coap_resources_numof = ARRAY_SIZE(coap_resources); diff --git a/tests/riotboot_flashwrite/main.c b/tests/riotboot_flashwrite/main.c index ebf6144f01a9b..56b14268cdb2a 100644 --- a/tests/riotboot_flashwrite/main.c +++ b/tests/riotboot_flashwrite/main.c @@ -28,31 +28,9 @@ #include "riotboot/slot.h" #include "riotboot/flashwrite.h" -#define COAP_INBUF_SIZE (256U) - -/* Extend stacksize of nanocoap server thread */ -static char _nanocoap_server_stack[THREAD_STACKSIZE_DEFAULT + THREAD_EXTRA_STACKSIZE_PRINTF]; -#define NANOCOAP_SERVER_QUEUE_SIZE (8) -static msg_t _nanocoap_server_msg_queue[NANOCOAP_SERVER_QUEUE_SIZE]; - #define MAIN_QUEUE_SIZE (8) static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; -static void *_nanocoap_server_thread(void *arg) -{ - (void)arg; - - /* nanocoap_server uses gnrc sock which uses gnrc which needs a msg queue */ - msg_init_queue(_nanocoap_server_msg_queue, NANOCOAP_SERVER_QUEUE_SIZE); - - /* initialize nanocoap server instance */ - uint8_t buf[COAP_INBUF_SIZE]; - sock_udp_ep_t local = { .port=COAP_PORT, .family=AF_INET6 }; - nanocoap_server(&local, buf, sizeof(buf)); - - return NULL; -} - static int cmd_print_riotboot_hdr(int argc, char **argv) { (void)argc; @@ -111,12 +89,6 @@ int main(void) cmd_print_current_slot(0, NULL); cmd_print_riotboot_hdr(0, NULL); - /* start nanocoap server thread */ - thread_create(_nanocoap_server_stack, sizeof(_nanocoap_server_stack), - THREAD_PRIORITY_MAIN - 1, - THREAD_CREATE_STACKTEST, - _nanocoap_server_thread, NULL, "nanocoap server"); - /* the shell contains commands that receive packets via GNRC and thus needs a msg queue */ msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE); diff --git a/tests/sys/conn_can/Makefile.ci b/tests/sys/conn_can/Makefile.ci index 6b710e80c9ef7..49a4de5da5b8d 100644 --- a/tests/sys/conn_can/Makefile.ci +++ b/tests/sys/conn_can/Makefile.ci @@ -1,8 +1,6 @@ BOARD_INSUFFICIENT_MEMORY := \ airfy-beacon \ calliope-mini \ - hifive1 \ - hifive1b \ i-nucleo-lrwan1 \ im880b \ microbit \ diff --git a/tests/sys/posix_semaphore/Makefile b/tests/sys/posix_semaphore/Makefile index 6bf4619e6ad1b..5d6c34b46c46f 100644 --- a/tests/sys/posix_semaphore/Makefile +++ b/tests/sys/posix_semaphore/Makefile @@ -7,4 +7,8 @@ USEMODULE += ztimer64_usec # microbit qemu failing currently TEST_ON_CI_BLACKLIST += microbit +# native / native64 may fail under load with: +# first: waited too long usec => FAILED +TEST_ON_CI_BLACKLIST += native native64 + include $(RIOTBASE)/Makefile.include diff --git a/tests/sys/pthread_cooperation/Makefile.ci b/tests/sys/pthread_cooperation/Makefile.ci index b34ba98ab5473..f6e8321a7837a 100644 --- a/tests/sys/pthread_cooperation/Makefile.ci +++ b/tests/sys/pthread_cooperation/Makefile.ci @@ -1,7 +1,5 @@ BOARD_INSUFFICIENT_MEMORY := \ atmega8 \ - hifive1 \ - hifive1b \ i-nucleo-lrwan1 \ im880b \ nucleo-f031k6 \ diff --git a/tests/sys/ztimer_msg/Makefile b/tests/sys/ztimer_msg/Makefile index afc279c503e97..35ea81565311c 100644 --- a/tests/sys/ztimer_msg/Makefile +++ b/tests/sys/ztimer_msg/Makefile @@ -8,4 +8,8 @@ USEMODULE += ztimer_usec # uncomment this to test using ztimer sec #USEMODULE += ztimer_sec +# The test is sensitive to background CPU load. On the CI workers a lot of +# compilation tasks are run in parallel, making this test randomly fail. +TEST_ON_CI_BLACKLIST += native native64 + include $(RIOTBASE)/Makefile.include diff --git a/tests/unittests/tests-nanocoap_cache/tests-nanocoap_cache.c b/tests/unittests/tests-nanocoap_cache/tests-nanocoap_cache.c index b2b02576834e1..c8d96b7c6e2e3 100644 --- a/tests/unittests/tests-nanocoap_cache/tests-nanocoap_cache.c +++ b/tests/unittests/tests-nanocoap_cache/tests-nanocoap_cache.c @@ -74,6 +74,60 @@ static void test_nanocoap_cache__cachekey(void) /* compare 3. and 1. packet */ TEST_ASSERT(nanocoap_cache_key_compare(digest2, digest1) > 0); } + +static void test_nanocoap_cache__cachekey_blockwise(void) +{ + uint8_t digest1[SHA256_DIGEST_LENGTH]; + uint8_t digest2[SHA256_DIGEST_LENGTH]; + uint8_t buf1[_BUF_SIZE]; + uint8_t buf2[_BUF_SIZE]; + coap_pkt_t pkt1; + coap_pkt_t pkt2; + uint16_t msgid = 0xABCD; + uint8_t token[2] = {0xDA, 0xEC}; + char path[] = "/time"; + size_t len; + coap_block1_t blockopt = { + .offset = 0, + .blknum = 0, + .szx = 2, + .more = 1, + }; + + /* 1. packet */ + len = coap_build_hdr((coap_hdr_t *)&buf1[0], COAP_TYPE_NON, + &token[0], 2, COAP_METHOD_GET, msgid); + coap_pkt_init(&pkt1, &buf1[0], sizeof(buf1), len); + coap_opt_add_string(&pkt1, COAP_OPT_URI_PATH, &path[0], '/'); + coap_opt_add_block1_control(&pkt1, &blockopt); + coap_opt_finish(&pkt1, COAP_OPT_FINISH_NONE); + + + blockopt.offset = 128; + blockopt.blknum = 2; + + /* 2. packet */ + len = coap_build_hdr((coap_hdr_t *)&buf2[0], COAP_TYPE_NON, + &token[0], 2, COAP_METHOD_GET, msgid); + coap_pkt_init(&pkt2, &buf2[0], sizeof(buf2), len); + coap_opt_add_string(&pkt2, COAP_OPT_URI_PATH, &path[0], '/'); + coap_opt_add_block1_control(&pkt1, &blockopt); + coap_opt_finish(&pkt2, COAP_OPT_FINISH_NONE); + + nanocoap_cache_key_blockreq_options_generate((const coap_pkt_t *) &pkt1, digest1); + nanocoap_cache_key_blockreq_options_generate((const coap_pkt_t *) &pkt2, digest2); + + /* compare 1. and 2. packet. Should be equal except for blockwise */ + TEST_ASSERT_EQUAL_INT(0, nanocoap_cache_key_compare(digest1, digest2)); + + /* Now with the blockwise option in the digest */ + nanocoap_cache_key_options_generate((const coap_pkt_t *) &pkt1, digest1); + nanocoap_cache_key_options_generate((const coap_pkt_t *) &pkt2, digest2); + + /* compare 1. and 2. packet. Should no longer be equal */ + TEST_ASSERT(nanocoap_cache_key_compare(digest2, digest1) != 0); +} + static void test_nanocoap_cache__add(void) { uint8_t buf[_BUF_SIZE]; @@ -263,6 +317,7 @@ Test *tests_nanocoap_cache_tests(void) new_TestFixture(test_nanocoap_cache__add), new_TestFixture(test_nanocoap_cache__del), new_TestFixture(test_nanocoap_cache__cachekey), + new_TestFixture(test_nanocoap_cache__cachekey_blockwise), new_TestFixture(test_nanocoap_cache__max_age), };