From 2e5a194f62c5a6e755f7df27c72aeb5be7cfa6e1 Mon Sep 17 00:00:00 2001 From: wuzhenghui Date: Mon, 5 Jun 2023 10:31:00 +0800 Subject: [PATCH 1/2] esp_hw_support: add modem module mac reset api --- .../include/esp_private/esp_modem_clock.h | 28 +++++++++++++ components/esp_hw_support/modem_clock.c | 29 +++++++++++--- .../hal/esp32c6/include/hal/clk_gate_ll.h | 40 ++----------------- .../hal/esp32c6/include/hal/modem_lpcon_ll.h | 28 +++++++++++++ .../hal/esp32c6/include/hal/modem_syscon_ll.h | 23 ++--------- .../hal/esp32h2/include/hal/modem_lpcon_ll.h | 14 +++++++ .../hal/esp32h2/include/hal/modem_syscon_ll.h | 23 ++--------- 7 files changed, 106 insertions(+), 79 deletions(-) diff --git a/components/esp_hw_support/include/esp_private/esp_modem_clock.h b/components/esp_hw_support/include/esp_private/esp_modem_clock.h index 109b2e8f2be6..e01f912d838e 100644 --- a/components/esp_hw_support/include/esp_private/esp_modem_clock.h +++ b/components/esp_hw_support/include/esp_private/esp_modem_clock.h @@ -29,6 +29,16 @@ extern "C" { * module depends on the wifi mac, wifi baseband and FE, when wifi module * clock is enabled, the wifi MAC, baseband and FE clocks will be enabled * + * This interface and modem_clock_module_disable will jointly maintain the + * ref_cnt of each device clock source. The ref_cnt indicates how many modules + * are relying on the clock source. Each enable ops will add 1 to the ref_cnt of + * the clock source that the module depends on, and only when the ref_cnt of + * the module is from 0 to 1 will the clock enable be actually configured. + * + * !!! Do not use the hal/ll layer interface to configure the clock for the + * consistency of the hardware state maintained in the driver and the hardware + * actual state. + * * @param module modem module */ void modem_clock_module_enable(periph_module_t module); @@ -36,10 +46,28 @@ void modem_clock_module_enable(periph_module_t module); /** * @brief Disable the clock of modem module * + * This interface and modem_clock_module_enable will jointly maintain the ref_cnt + * of each device clock source. The ref_cnt indicates how many modules are relying + * on the clock source. Each disable ops will minus 1 to the ref_cnt of the clock + * source that the module depends on, and only when the ref_cnt of the module is + * from 1 to 0 will the clock disable be actually configured. + * + * !!! Do not use the hal/ll layer interface to configure the clock for the + * consistency of the hardware state maintained in the driver and the hardware + * actual state. + * * @param module modem module */ void modem_clock_module_disable(periph_module_t module); +/** + * @brief Reset the mac of modem module + * + * @param module modem module, must be one of + * PERIPH_WIFI_MODULE / PERIPH_BT_MODULE /PERIPH_IEEE802154_MODULE + */ +void modem_clock_module_mac_reset(periph_module_t module); + /** * @brief Initialize the clock gating control signal of each clock domain of the modem * diff --git a/components/esp_hw_support/modem_clock.c b/components/esp_hw_support/modem_clock.c index 6b90984a3544..fdb0319826a1 100644 --- a/components/esp_hw_support/modem_clock.c +++ b/components/esp_hw_support/modem_clock.c @@ -214,15 +214,34 @@ static void IRAM_ATTR modem_clock_device_disable(modem_clock_context_t *ctx, uin assert(refs >= 0); } -void IRAM_ATTR modem_clock_wifi_mac_reset(void) +void IRAM_ATTR modem_clock_module_mac_reset(periph_module_t module) { -#if SOC_WIFI_SUPPORTED modem_clock_context_t *ctx = MODEM_CLOCK_instance(); portENTER_CRITICAL_SAFE(&ctx->lock); - //TODO: IDF-5713 - modem_syscon_ll_reset_wifimac(ctx->hal->syscon_dev); - portEXIT_CRITICAL_SAFE(&ctx->lock); + switch (module) + { +#if SOC_WIFI_SUPPORTED + case PERIPH_WIFI_MODULE: + modem_syscon_ll_reset_wifimac(ctx->hal->syscon_dev); + break; #endif +#if SOC_BT_SUPPORTED + case PERIPH_BT_MODULE: + modem_syscon_ll_reset_btmac(ctx->hal->syscon_dev); + modem_syscon_ll_reset_btmac_apb(ctx->hal->syscon_dev); + modem_syscon_ll_reset_ble_timer(ctx->hal->syscon_dev); + modem_syscon_ll_reset_modem_sec(ctx->hal->syscon_dev); + break; +#endif +#if SOC_IEEE802154_SUPPORTED + case PERIPH_IEEE802154_MODULE: + modem_syscon_ll_reset_zbmac(ctx->hal->syscon_dev); + break; + default: +#endif + assert(0); + } + portEXIT_CRITICAL_SAFE(&ctx->lock); } #define WIFI_CLOCK_DEPS (BIT(MODEM_CLOCK_WIFI_MAC) | BIT(MODEM_CLOCK_FE) | BIT(MODEM_CLOCK_WIFI_BB) | BIT(MODEM_CLOCK_COEXIST)) diff --git a/components/hal/esp32c6/include/hal/clk_gate_ll.h b/components/hal/esp32c6/include/hal/clk_gate_ll.h index 448a3489cf39..c8f9f87e1957 100644 --- a/components/hal/esp32c6/include/hal/clk_gate_ll.h +++ b/components/hal/esp32c6/include/hal/clk_gate_ll.h @@ -19,7 +19,7 @@ extern "C" { #endif static inline uint32_t periph_ll_get_clk_en_mask(periph_module_t periph) -{ // TODO: IDF-5713 +{ switch (periph) { case PERIPH_SARADC_MODULE: return PCR_SARADC_CLK_EN; @@ -82,25 +82,13 @@ static inline uint32_t periph_ll_get_clk_en_mask(periph_module_t periph) //TODO: LP_PERIPH modules are added temporarily and will be moved to a separate API (IDF-7374). case PERIPH_LP_I2C0_MODULE: return LPPERI_LP_EXT_I2C_CK_EN; - // case PERIPH_RNG_MODULE: - // return PCR_WIFI_CLK_RNG_EN; - // case PERIPH_WIFI_MODULE: - // return PCR_WIFI_CLK_WIFI_EN_M; - // case PERIPH_BT_MODULE: - // return PCR_WIFI_CLK_BT_EN_M; - // case PERIPH_WIFI_BT_COMMON_MODULE: - // return PCR_WIFI_CLK_WIFI_BT_COMMON_M; - // case PERIPH_BT_BASEBAND_MODULE: - // return PCR_BT_BASEBAND_EN; - // case PERIPH_BT_LC_MODULE: - // return PCR_BT_LC_EN; default: return 0; } } static inline uint32_t periph_ll_get_rst_en_mask(periph_module_t periph, bool enable) -{ // TODO: IDF-5713 +{ (void)enable; // unused switch (periph) { @@ -178,34 +166,14 @@ static inline uint32_t periph_ll_get_rst_en_mask(periph_module_t periph, bool en //TODO: LP_PERIPH modules are added temporarily and will be moved to a separate API (IDF-7374). case PERIPH_LP_I2C0_MODULE: return LPPERI_LP_EXT_I2C_RESET_EN; - // case PERIPH_RNG_MODULE: - // return PCR_WIFI_CLK_RNG_EN; - // case PERIPH_WIFI_MODULE: - // return PCR_WIFI_CLK_WIFI_EN_M; - // case PERIPH_BT_MODULE: - // return PCR_WIFI_CLK_BT_EN_M; - // case PERIPH_WIFI_BT_COMMON_MODULE: - // return PCR_WIFI_CLK_WIFI_BT_COMMON_M; - // case PERIPH_BT_BASEBAND_MODULE: - // return PCR_BT_BASEBAND_EN; - // case PERIPH_BT_LC_MODULE: - // return PCR_BT_LC_EN; default: return 0; } } static uint32_t periph_ll_get_clk_en_reg(periph_module_t periph) -{ // TODO: IDF-5713 +{ switch (periph) { - // case PERIPH_RNG_MODULE: - // case PERIPH_WIFI_MODULE: - // case PERIPH_BT_MODULE: - // case PERIPH_WIFI_BT_COMMON_MODULE: - // case PERIPH_BT_BASEBAND_MODULE: - // case PERIPH_BT_LC_MODULE: - // return SYSTEM_WIFI_CLK_EN_REG; - case PERIPH_SARADC_MODULE: return PCR_SARADC_CONF_REG; case PERIPH_RMT_MODULE: @@ -273,7 +241,7 @@ static uint32_t periph_ll_get_clk_en_reg(periph_module_t periph) } static uint32_t periph_ll_get_rst_en_reg(periph_module_t periph) -{ // TODO: IDF-5713 +{ switch (periph) { case PERIPH_SARADC_MODULE: return PCR_SARADC_CONF_REG; diff --git a/components/hal/esp32c6/include/hal/modem_lpcon_ll.h b/components/hal/esp32c6/include/hal/modem_lpcon_ll.h index e6c754005d10..3374defb42b3 100644 --- a/components/hal/esp32c6/include/hal/modem_lpcon_ll.h +++ b/components/hal/esp32c6/include/hal/modem_lpcon_ll.h @@ -216,6 +216,34 @@ static inline void modem_lpcon_ll_set_lp_apb_icg_bitmap(modem_lpcon_dev_t *hw, u hw->clk_conf_power_st.clk_lp_apb_st_map = bitmap; } +__attribute__((always_inline)) +static inline void modem_lpcon_ll_reset_wifipwr(modem_lpcon_dev_t *hw) +{ + hw->rst_conf.rst_wifipwr = 1; + hw->rst_conf.rst_wifipwr = 0; +} + +__attribute__((always_inline)) +static inline void modem_lpcon_ll_reset_coex(modem_lpcon_dev_t *hw) +{ + hw->rst_conf.rst_coex = 1; + hw->rst_conf.rst_coex = 0; +} + +__attribute__((always_inline)) +static inline void modem_lpcon_ll_reset_i2c_master(modem_lpcon_dev_t *hw) +{ + hw->rst_conf.rst_i2c_mst = 1; + hw->rst_conf.rst_i2c_mst = 0; +} + +__attribute__((always_inline)) +static inline void modem_lpcon_ll_reset_ble_rtc_timer(modem_lpcon_dev_t *hw) +{ + hw->rst_conf.rst_lp_timer = 1; + hw->rst_conf.rst_lp_timer = 0; +} + __attribute__((always_inline)) static inline void modem_lpcon_ll_reset_all(modem_lpcon_dev_t *hw) { diff --git a/components/hal/esp32c6/include/hal/modem_syscon_ll.h b/components/hal/esp32c6/include/hal/modem_syscon_ll.h index 563ee1f84e37..9fc2b50a3e4c 100644 --- a/components/hal/esp32c6/include/hal/modem_syscon_ll.h +++ b/components/hal/esp32c6/include/hal/modem_syscon_ll.h @@ -205,30 +205,15 @@ static inline void modem_syscon_ll_reset_zbmac(modem_syscon_dev_t *hw) } __attribute__((always_inline)) -static inline void modem_syscon_ll_reset_modem_ecb(modem_syscon_dev_t *hw) +static inline void modem_syscon_ll_reset_modem_sec(modem_syscon_dev_t *hw) { hw->modem_rst_conf.rst_modem_ecb = 1; - hw->modem_rst_conf.rst_modem_ecb = 0; -} - -__attribute__((always_inline)) -static inline void modem_syscon_ll_reset_modem_ccm(modem_syscon_dev_t *hw) -{ hw->modem_rst_conf.rst_modem_ccm = 1; - hw->modem_rst_conf.rst_modem_ccm = 0; -} - -__attribute__((always_inline)) -static inline void modem_syscon_ll_reset_modem_bah(modem_syscon_dev_t *hw) -{ hw->modem_rst_conf.rst_modem_bah = 1; - hw->modem_rst_conf.rst_modem_bah = 0; -} - -__attribute__((always_inline)) -static inline void modem_syscon_ll_reset_modem_sec(modem_syscon_dev_t *hw) -{ hw->modem_rst_conf.rst_modem_sec = 1; + hw->modem_rst_conf.rst_modem_ecb = 0; + hw->modem_rst_conf.rst_modem_ccm = 0; + hw->modem_rst_conf.rst_modem_bah = 0; hw->modem_rst_conf.rst_modem_sec = 0; } diff --git a/components/hal/esp32h2/include/hal/modem_lpcon_ll.h b/components/hal/esp32h2/include/hal/modem_lpcon_ll.h index 78956cfbb610..33977bb12e7b 100644 --- a/components/hal/esp32h2/include/hal/modem_lpcon_ll.h +++ b/components/hal/esp32h2/include/hal/modem_lpcon_ll.h @@ -96,6 +96,20 @@ static inline void modem_lpcon_ll_enable_fe_mem_force_clock(modem_lpcon_dev_t *h hw->clk_conf_force_on.clk_fe_mem_fo = en; } +__attribute__((always_inline)) +static inline void modem_lpcon_ll_reset_coex(modem_lpcon_dev_t *hw) +{ + hw->rst_conf.rst_coex = 1; + hw->rst_conf.rst_coex = 0; +} + +__attribute__((always_inline)) +static inline void modem_lpcon_ll_reset_i2c_master(modem_lpcon_dev_t *hw) +{ + hw->rst_conf.rst_i2c_mst = 1; + hw->rst_conf.rst_i2c_mst = 0; +} + __attribute__((always_inline)) static inline void modem_lpcon_ll_reset_all(modem_lpcon_dev_t *hw) { diff --git a/components/hal/esp32h2/include/hal/modem_syscon_ll.h b/components/hal/esp32h2/include/hal/modem_syscon_ll.h index 618e88f95db5..c367c3b194f7 100644 --- a/components/hal/esp32h2/include/hal/modem_syscon_ll.h +++ b/components/hal/esp32h2/include/hal/modem_syscon_ll.h @@ -151,30 +151,15 @@ static inline void modem_syscon_ll_reset_zbmac(modem_syscon_dev_t *hw) } __attribute__((always_inline)) -static inline void modem_syscon_ll_reset_modem_ecb(modem_syscon_dev_t *hw) +static inline void modem_syscon_ll_reset_modem_sec(modem_syscon_dev_t *hw) { hw->modem_rst_conf.rst_modem_ecb = 1; - hw->modem_rst_conf.rst_modem_ecb = 0; -} - -__attribute__((always_inline)) -static inline void modem_syscon_ll_reset_modem_ccm(modem_syscon_dev_t *hw) -{ hw->modem_rst_conf.rst_modem_ccm = 1; - hw->modem_rst_conf.rst_modem_ccm = 0; -} - -__attribute__((always_inline)) -static inline void modem_syscon_ll_reset_modem_bah(modem_syscon_dev_t *hw) -{ hw->modem_rst_conf.rst_modem_bah = 1; - hw->modem_rst_conf.rst_modem_bah = 0; -} - -__attribute__((always_inline)) -static inline void modem_syscon_ll_reset_modem_sec(modem_syscon_dev_t *hw) -{ hw->modem_rst_conf.rst_modem_sec = 1; + hw->modem_rst_conf.rst_modem_ecb = 0; + hw->modem_rst_conf.rst_modem_ccm = 0; + hw->modem_rst_conf.rst_modem_bah = 0; hw->modem_rst_conf.rst_modem_sec = 0; } From afc889e9347a21e81ada0d9f483ce63a843d78f4 Mon Sep 17 00:00:00 2001 From: wuzhenghui Date: Mon, 5 Jun 2023 10:31:49 +0800 Subject: [PATCH 2/2] esp_wifi: implement wifi_reset_mac_wrapper --- components/esp_wifi/esp32c6/esp_adapter.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/components/esp_wifi/esp32c6/esp_adapter.c b/components/esp_wifi/esp32c6/esp_adapter.c index 0583835f3945..942664e72869 100644 --- a/components/esp_wifi/esp32c6/esp_adapter.c +++ b/components/esp_wifi/esp32c6/esp_adapter.c @@ -28,6 +28,7 @@ #include "esp_event.h" #include "esp_heap_caps.h" #include "esp_timer.h" +#include "esp_private/esp_modem_clock.h" #include "esp_private/wifi_os_adapter.h" #include "esp_private/wifi.h" #include "esp_phy_init.h" @@ -297,9 +298,7 @@ static void IRAM_ATTR timer_arm_wrapper(void *timer, uint32_t tmout, bool repeat static void wifi_reset_mac_wrapper(void) { - // TODO: IDF-5713 - modem_clock_wifi_mac_reset(); - ESP_LOGW(TAG, "wifi_reset_mac_wrapper() has not been implemented yet"); + modem_clock_module_mac_reset(PERIPH_WIFI_MODULE); } static void wifi_clock_enable_wrapper(void)