From 29e9b5b46aad857624f21b3d2331055a8891c439 Mon Sep 17 00:00:00 2001 From: morris Date: Thu, 24 Mar 2022 21:33:36 +0800 Subject: [PATCH 1/2] hw_support: move periph_ctrl from driver to hw_support --- components/driver/CMakeLists.txt | 1 - components/driver/Kconfig | 1 + components/driver/linker.lf | 6 ------ components/esp_hw_support/CMakeLists.txt | 1 + components/esp_hw_support/Kconfig | 9 +++++++++ .../include/esp_private/periph_ctrl.h | 0 components/esp_hw_support/linker.lf | 4 ++++ components/{driver => esp_hw_support}/periph_ctrl.c | 0 components/esp_phy/CMakeLists.txt | 5 ++--- components/esp_system/CMakeLists.txt | 1 - components/esp_wifi/Kconfig | 1 + components/esp_wifi/linker.lf | 7 ------- components/usb/CMakeLists.txt | 3 +-- 13 files changed, 19 insertions(+), 20 deletions(-) rename components/{driver => esp_hw_support}/include/esp_private/periph_ctrl.h (100%) rename components/{driver => esp_hw_support}/periph_ctrl.c (100%) diff --git a/components/driver/CMakeLists.txt b/components/driver/CMakeLists.txt index 676831fe98..d5ff096253 100644 --- a/components/driver/CMakeLists.txt +++ b/components/driver/CMakeLists.txt @@ -6,7 +6,6 @@ set(srcs "i2c.c" "ledc.c" "legacy_new_driver_coexist.c" - "periph_ctrl.c" "rtc_io.c" "rtc_module.c" "sdspi_crc.c" diff --git a/components/driver/Kconfig b/components/driver/Kconfig index 42308eced6..aa93ed6ad0 100644 --- a/components/driver/Kconfig +++ b/components/driver/Kconfig @@ -90,6 +90,7 @@ menu "Driver configurations" config TWAI_ISR_IN_IRAM bool "Place TWAI ISR function into IRAM" default n + select PERIPH_CTRL_FUNC_IN_IRAM if TWAI_ERRATA_FIX_RX_FRAME_INVALID || TWAI_ERRATA_FIX_RX_FIFO_CORRUPT help Place the TWAI ISR in to IRAM. This will allow the ISR to avoid cache misses, and also be able to run whilst the cache is disabled diff --git a/components/driver/linker.lf b/components/driver/linker.lf index 554b843a70..9e118f876e 100644 --- a/components/driver/linker.lf +++ b/components/driver/linker.lf @@ -1,12 +1,6 @@ - [mapping:driver] archive: libdriver.a entries: - # TWAI workarounds that require periph_module_reset() won't work if cache is disabled due to the use of switch jump - # tables in periph_module_reset(). We prevent any part of periph_module_reset() (either text or RO data) from being - # placed in flash. - if TWAI_ISR_IN_IRAM = y && (TWAI_ERRATA_FIX_RX_FRAME_INVALID = y || TWAI_ERRATA_FIX_RX_FIFO_CORRUPT = y): - periph_ctrl: periph_module_reset (noflash) if GPTIMER_CTRL_FUNC_IN_IRAM = y: gptimer: gptimer_set_raw_count (noflash) gptimer: gptimer_get_raw_count (noflash) diff --git a/components/esp_hw_support/CMakeLists.txt b/components/esp_hw_support/CMakeLists.txt index fc8703e797..912906ab1c 100644 --- a/components/esp_hw_support/CMakeLists.txt +++ b/components/esp_hw_support/CMakeLists.txt @@ -11,6 +11,7 @@ if(NOT BOOTLOADER_BUILD) "hw_random.c" "intr_alloc.c" "mac_addr.c" + "periph_ctrl.c" "sleep_modes.c" "sleep_gpio.c" "sleep_mac_bb.c" diff --git a/components/esp_hw_support/Kconfig b/components/esp_hw_support/Kconfig index da6fc41ab4..a302974dcd 100644 --- a/components/esp_hw_support/Kconfig +++ b/components/esp_hw_support/Kconfig @@ -85,4 +85,13 @@ menu "Hardware Settings" If you want to use USB_SERIAL_JTAG under sw_reset case or sleep-wakeup case, you shoule select this option. But be aware that this might increase the power consumption. endmenu + + menu "Peripheral Control" + config PERIPH_CTRL_FUNC_IN_IRAM + bool "Place peripheral control functions into IRAM" + default n + help + Place peripheral control functions (e.g. periph_module_reset) into IRAM, + so that these functions can be IRAM-safe and able to be called in the other IRAM interrupt context. + endmenu endmenu diff --git a/components/driver/include/esp_private/periph_ctrl.h b/components/esp_hw_support/include/esp_private/periph_ctrl.h similarity index 100% rename from components/driver/include/esp_private/periph_ctrl.h rename to components/esp_hw_support/include/esp_private/periph_ctrl.h diff --git a/components/esp_hw_support/linker.lf b/components/esp_hw_support/linker.lf index 66a6fa247f..10a4d6f5d4 100644 --- a/components/esp_hw_support/linker.lf +++ b/components/esp_hw_support/linker.lf @@ -16,3 +16,7 @@ entries: opiram_psram (noflash) if IDF_TARGET_ESP32S2 = y: mmu_psram (noflash) + if PERIPH_CTRL_FUNC_IN_IRAM = y: + periph_ctrl: periph_module_reset (noflash) + periph_ctrl: wifi_module_enable (noflash) + periph_ctrl: wifi_module_disable (noflash) diff --git a/components/driver/periph_ctrl.c b/components/esp_hw_support/periph_ctrl.c similarity index 100% rename from components/driver/periph_ctrl.c rename to components/esp_hw_support/periph_ctrl.c diff --git a/components/esp_phy/CMakeLists.txt b/components/esp_phy/CMakeLists.txt index 68012a000d..25b776b86c 100644 --- a/components/esp_phy/CMakeLists.txt +++ b/components/esp_phy/CMakeLists.txt @@ -28,18 +28,17 @@ if(CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN) endif() endif() -# [refactor-todo]: requires "driver" component for periph_ctrl header file if(CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN_EMBED) idf_component_register(SRCS "${srcs}" INCLUDE_DIRS "include" "${idf_target}/include" - PRIV_REQUIRES nvs_flash driver + PRIV_REQUIRES nvs_flash LDFRAGMENTS "${ldfragments}" EMBED_FILES "${build_dir}/phy_multiple_init_data.bin" ) else() idf_component_register(SRCS "${srcs}" INCLUDE_DIRS "include" "${idf_target}/include" - PRIV_REQUIRES nvs_flash driver + PRIV_REQUIRES nvs_flash LDFRAGMENTS "${ldfragments}" ) endif() diff --git a/components/esp_system/CMakeLists.txt b/components/esp_system/CMakeLists.txt index 3747cbd10e..fd584dec19 100644 --- a/components/esp_system/CMakeLists.txt +++ b/components/esp_system/CMakeLists.txt @@ -41,7 +41,6 @@ else() # should be removable once using component init functions # link-time registration is used. # [refactor-todo] requires "driver" for headers: - # - periph_ctrl.h # - rtc_cntl.h # - spi_common_internal.h pthread bootloader_support efuse driver diff --git a/components/esp_wifi/Kconfig b/components/esp_wifi/Kconfig index bca2badcc7..44e3ea16b8 100644 --- a/components/esp_wifi/Kconfig +++ b/components/esp_wifi/Kconfig @@ -254,6 +254,7 @@ menu "Wi-Fi" config ESP_WIFI_SLP_IRAM_OPT bool "WiFi SLP IRAM speed optimization" select PM_SLP_DEFAULT_PARAMS_OPT + select PERIPH_CTRL_FUNC_IN_IRAM help Select this option to place called Wi-Fi library TBTT process and receive beacon functions in IRAM. Some functions can be put in IRAM either by ESP32_WIFI_IRAM_OPT and ESP32_WIFI_RX_IRAM_OPT, or this one. diff --git a/components/esp_wifi/linker.lf b/components/esp_wifi/linker.lf index 39a203f63b..b0b239d925 100644 --- a/components/esp_wifi/linker.lf +++ b/components/esp_wifi/linker.lf @@ -150,13 +150,6 @@ entries: wifi_init:wifi_apb80m_request (noflash) wifi_init:wifi_apb80m_release (noflash) -[mapping:driver_wifi_pm] -archive: libdriver.a -entries: - if ESP_WIFI_SLP_IRAM_OPT =y: - periph_ctrl:wifi_module_enable (noflash) - periph_ctrl:wifi_module_disable (noflash) - [mapping:esp_timer_wifi_pm] archive: libesp_timer.a entries: diff --git a/components/usb/CMakeLists.txt b/components/usb/CMakeLists.txt index bb89fdd6db..35f5d24277 100644 --- a/components/usb/CMakeLists.txt +++ b/components/usb/CMakeLists.txt @@ -4,8 +4,7 @@ set(priv_include) # As CONFIG_USB_OTG_SUPPORTED comes from Kconfig, it is not evaluated yet # when components are being registered. # Thus, always add the (private) requirements, regardless of Kconfig -# [refactor-todo]: requires "driver" because "periph_ctrl.h" is used in "hcd.c" -set(priv_require hal driver) +set(priv_require driver) # usb_phy driver relies on gpio driver API if(CONFIG_USB_OTG_SUPPORTED) list(APPEND srcs "hcd.c" From bf677182a69b3999c536a177062a86c86cfee5bd Mon Sep 17 00:00:00 2001 From: morris Date: Sat, 26 Mar 2022 16:50:35 +0800 Subject: [PATCH 2/2] sigmadelta: change gpio number from u8 to int Fix the issue that macro compares unsigned to 0 --- components/driver/include/driver/gpio.h | 4 ---- components/driver/include/driver/sigmadelta.h | 11 ++++++----- components/esp_pm/pm_trace.c | 2 +- .../common_components/light_driver/iot_led.c | 1 + 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/components/driver/include/driver/gpio.h b/components/driver/include/driver/gpio.h index f71f47aa0c..fe01ee74d5 100644 --- a/components/driver/include/driver/gpio.h +++ b/components/driver/include/driver/gpio.h @@ -10,11 +10,7 @@ #include "sdkconfig.h" #include "esp_err.h" #include "esp_intr_alloc.h" -#if !CONFIG_IDF_TARGET_LINUX -#include "esp_attr.h" -#include "esp_types.h" #include "soc/soc_caps.h" -#endif // !CONFIG_IDF_TARGET_LINUX #include "hal/gpio_types.h" #include "esp_rom_gpio.h" diff --git a/components/driver/include/driver/sigmadelta.h b/components/driver/include/driver/sigmadelta.h index 7f7c715953..eaecead4d9 100644 --- a/components/driver/include/driver/sigmadelta.h +++ b/components/driver/include/driver/sigmadelta.h @@ -6,7 +6,8 @@ #pragma once -#include "esp_types.h" +#include +#include "esp_err.h" #include "driver/gpio.h" #include "hal/sigmadelta_types.h" @@ -18,10 +19,10 @@ extern "C" { * @brief Sigma-delta configure struct */ typedef struct { - sigmadelta_channel_t channel; /*!< Sigma-delta channel number */ - int8_t sigmadelta_duty; /*!< Sigma-delta duty, duty ranges from -128 to 127. */ - uint8_t sigmadelta_prescale; /*!< Sigma-delta prescale, prescale ranges from 0 to 255. */ - uint8_t sigmadelta_gpio; /*!< Sigma-delta output io number, refer to gpio.h for more details. */ + sigmadelta_channel_t channel; /*!< Sigma-delta channel number */ + int8_t sigmadelta_duty; /*!< Sigma-delta duty, duty ranges from -128 to 127. */ + uint8_t sigmadelta_prescale; /*!< Sigma-delta prescale, prescale ranges from 0 to 255. */ + gpio_num_t sigmadelta_gpio; /*!< Sigma-delta output io number, refer to gpio.h for more details. */ } sigmadelta_config_t; /** diff --git a/components/esp_pm/pm_trace.c b/components/esp_pm/pm_trace.c index a3dd7ed81d..3e3ab3050d 100644 --- a/components/esp_pm/pm_trace.c +++ b/components/esp_pm/pm_trace.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ - +#include "esp_attr.h" #include "esp_private/pm_trace.h" #include "driver/gpio.h" #include "soc/soc.h" diff --git a/examples/bluetooth/esp_ble_mesh/common_components/light_driver/iot_led.c b/examples/bluetooth/esp_ble_mesh/common_components/light_driver/iot_led.c index fc58015ca8..17f1831524 100644 --- a/examples/bluetooth/esp_ble_mesh/common_components/light_driver/iot_led.c +++ b/examples/bluetooth/esp_ble_mesh/common_components/light_driver/iot_led.c @@ -14,6 +14,7 @@ #include "soc/ledc_struct.h" #include "driver/gptimer.h" #include "driver/ledc.h" +#include "esp_attr.h" #include "iot_led.h" #include "esp_log.h"