modem_clock: rename modem_clock_lp_timer to ble_rtc_timer

This commit is contained in:
wuzhenghui 2023-03-22 21:50:04 +08:00
parent 43a9456243
commit 485f2882d1
8 changed files with 106 additions and 91 deletions

View File

@ -10,6 +10,7 @@
#include "sdkconfig.h"
#include "esp_attr.h"
#include "soc/soc.h"
#include "soc/soc_caps.h"
#include "freertos/FreeRTOS.h"
#include "hal/clk_gate_ll.h"
#include "esp_private/esp_modem_clock.h"
@ -46,6 +47,7 @@ typedef struct modem_clock_context {
} modem_clock_context_t;
#if SOC_WIFI_SUPPORTED
static void IRAM_ATTR modem_clock_wifi_mac_configure(modem_clock_context_t *ctx, bool enable)
{
if (enable) {
@ -60,7 +62,9 @@ static void IRAM_ATTR modem_clock_wifi_bb_configure(modem_clock_context_t *ctx,
modem_syscon_ll_clk_wifibb_configure(ctx->hal->syscon_dev, enable);
}
}
#endif // SOC_WIFI_SUPPORTED
#if SOC_BT_SUPPORTED
static void IRAM_ATTR modem_clock_ble_mac_configure(modem_clock_context_t *ctx, bool enable)
{
modem_syscon_ll_enable_etm_clock(ctx->hal->syscon_dev, enable);
@ -74,11 +78,15 @@ static void IRAM_ATTR modem_clock_ble_bb_configure(modem_clock_context_t *ctx, b
modem_syscon_ll_enable_bt_clock(ctx->hal->syscon_dev, enable);
}
#endif // SOC_BT_SUPPORTED
#if SOC_IEEE802154_SUPPORTED
static void IRAM_ATTR modem_clock_ieee802154_mac_configure(modem_clock_context_t *ctx, bool enable)
{
modem_syscon_ll_enable_ieee802154_apb_clock(ctx->hal->syscon_dev, enable);
modem_syscon_ll_enable_ieee802154_mac_clock(ctx->hal->syscon_dev, enable);
}
#endif // SOC_IEEE802154_SUPPORTED
static void IRAM_ATTR modem_clock_coex_configure(modem_clock_context_t *ctx, bool enable)
{
@ -121,12 +129,18 @@ modem_clock_context_t * __attribute__((weak)) IRAM_ATTR MODEM_CLOCK_instance(voi
{ .refs = 0, .configure = modem_clock_fe_configure },
{ .refs = 0, .configure = modem_clock_coex_configure },
{ .refs = 0, .configure = modem_clock_i2c_master_configure },
#if SOC_WIFI_SUPPORTED
{ .refs = 0, .configure = modem_clock_wifi_mac_configure },
{ .refs = 0, .configure = modem_clock_wifi_bb_configure },
#endif // SOC_WIFI_SUPPORTED
{ .refs = 0, .configure = modem_clock_etm_configure },
#if SOC_BT_SUPPORTED
{ .refs = 0, .configure = modem_clock_ble_mac_configure },
{ .refs = 0, .configure = modem_clock_ble_bb_configure },
#endif // SOC_BT_SUPPORTED
#if SOC_IEEE802154_SUPPORTED
{ .refs = 0, .configure = modem_clock_ieee802154_mac_configure },
#endif // SOC_IEEE802154_SUPPORTED
{ .refs = 0, .configure = modem_clock_data_dump_configure }
},
.lpclk_src = { [0 ... PERIPH_MODEM_MODULE_NUM - 1] = MODEM_CLOCK_LPCLK_SRC_INVALID }
@ -134,6 +148,7 @@ modem_clock_context_t * __attribute__((weak)) IRAM_ATTR MODEM_CLOCK_instance(voi
return &modem_clock_context;
}
#if SOC_PM_SUPPORT_PMU_MODEM_STATE
static void IRAM_ATTR modem_clock_domain_power_state_icg_map_init(modem_clock_context_t *ctx)
{
#define ICG_NOGATING_SLEEP (BIT(PMU_HP_ICG_MODEM_CODE_SLEEP))
@ -159,11 +174,11 @@ static void IRAM_ATTR modem_clock_domain_power_state_icg_map_init(modem_clock_co
}
}
void modem_clock_domain_pmu_state_icg_map_init(void)
{
modem_clock_domain_power_state_icg_map_init(MODEM_CLOCK_instance());
}
#endif // #if SOC_PM_SUPPORT_PMU_MODEM_STATE
static void IRAM_ATTR modem_clock_device_enable(modem_clock_context_t *ctx, uint32_t dev_map)
{
@ -203,27 +218,34 @@ static void IRAM_ATTR modem_clock_device_disable(modem_clock_context_t *ctx, uin
#define COEXIST_CLOCK_DEPS (MODEM_CLOCK_COEXIST)
#define PHY_CLOCK_DEPS (MODEM_CLOCK_I2C_MASTER | MODEM_CLOCK_FE)
static inline uint32_t modem_clock_get_module_deps(periph_module_t module)
{
uint32_t deps = 0;
if (module == PERIPH_PHY_MODULE) {deps = PHY_CLOCK_DEPS;}
else if (module == PERIPH_COEX_MODULE) { deps = COEXIST_CLOCK_DEPS; }
#if SOC_WIFI_SUPPORTED
else if (module == PERIPH_WIFI_MODULE) { deps = WIFI_CLOCK_DEPS; }
#endif
#if SOC_BT_SUPPORTED
else if (module == PERIPH_BT_MODULE) { deps = BLE_CLOCK_DEPS; }
#endif
#if SOC_IEEE802154_SUPPORTED
else if (module == PERIPH_IEEE802154_MODULE) { deps = IEEE802154_CLOCK_DEPS; }
#endif
return deps;
}
void IRAM_ATTR modem_clock_module_enable(periph_module_t module)
{
assert(IS_MODEM_MODULE(module));
const int deps = (module == PERIPH_WIFI_MODULE) ? WIFI_CLOCK_DEPS \
: (module == PERIPH_BT_MODULE) ? BLE_CLOCK_DEPS \
: (module == PERIPH_IEEE802154_MODULE) ? IEEE802154_CLOCK_DEPS \
: (module == PERIPH_COEX_MODULE) ? COEXIST_CLOCK_DEPS \
: (module == PERIPH_PHY_MODULE) ? PHY_CLOCK_DEPS \
: 0;
uint32_t deps = modem_clock_get_module_deps(module);
modem_clock_device_enable(MODEM_CLOCK_instance(), deps);
}
void IRAM_ATTR modem_clock_module_disable(periph_module_t module)
{
assert(IS_MODEM_MODULE(module));
const int deps = (module == PERIPH_WIFI_MODULE) ? WIFI_CLOCK_DEPS \
: (module == PERIPH_BT_MODULE) ? BLE_CLOCK_DEPS \
: (module == PERIPH_IEEE802154_MODULE) ? IEEE802154_CLOCK_DEPS \
: (module == PERIPH_COEX_MODULE) ? COEXIST_CLOCK_DEPS \
: (module == PERIPH_PHY_MODULE) ? PHY_CLOCK_DEPS \
: 0;
uint32_t deps = modem_clock_get_module_deps(module);
modem_clock_device_disable(MODEM_CLOCK_instance(), deps);
}
@ -233,18 +255,24 @@ void modem_clock_select_lp_clock_source(periph_module_t module, modem_clock_lpcl
portENTER_CRITICAL_SAFE(&MODEM_CLOCK_instance()->lock);
switch (module)
{
#if SOC_WIFI_SUPPORTED
case PERIPH_WIFI_MODULE:
modem_clock_hal_deselect_all_wifi_lpclk_source(MODEM_CLOCK_instance()->hal);
modem_clock_hal_select_wifi_lpclk_source(MODEM_CLOCK_instance()->hal, src);
modem_lpcon_ll_set_wifi_lpclk_divisor_value(MODEM_CLOCK_instance()->hal->lpcon_dev, divider);
modem_lpcon_ll_enable_wifipwr_clock(MODEM_CLOCK_instance()->hal->lpcon_dev, true);
break;
#endif // SOC_WIFI_SUPPORTED
#if SOC_BT_SUPPORTED
case PERIPH_BT_MODULE:
modem_clock_hal_deselect_all_lp_timer_lpclk_source(MODEM_CLOCK_instance()->hal);
modem_clock_hal_select_lp_timer_lpclk_source(MODEM_CLOCK_instance()->hal, src);
modem_lpcon_ll_set_lp_timer_divisor_value(MODEM_CLOCK_instance()->hal->lpcon_dev, divider);
modem_lpcon_ll_enable_lp_timer_clock(MODEM_CLOCK_instance()->hal->lpcon_dev, true);
modem_clock_hal_deselect_all_ble_rtc_timer_lpclk_source(MODEM_CLOCK_instance()->hal);
modem_clock_hal_select_ble_rtc_timer_lpclk_source(MODEM_CLOCK_instance()->hal, src);
modem_clock_hal_set_ble_rtc_timer_divisor_value(MODEM_CLOCK_instance()->hal, divider);
modem_clock_hal_enable_ble_rtc_timer_clock(MODEM_CLOCK_instance()->hal, true);
break;
#endif // SOC_BT_SUPPORTED
case PERIPH_COEX_MODULE:
modem_clock_hal_deselect_all_coex_lpclk_source(MODEM_CLOCK_instance()->hal);
modem_clock_hal_select_coex_lpclk_source(MODEM_CLOCK_instance()->hal, src);
@ -282,14 +310,19 @@ void modem_clock_deselect_lp_clock_source(periph_module_t module)
portENTER_CRITICAL_SAFE(&MODEM_CLOCK_instance()->lock);
switch (module)
{
#if SOC_WIFI_SUPPORTED
case PERIPH_WIFI_MODULE:
modem_clock_hal_deselect_all_wifi_lpclk_source(MODEM_CLOCK_instance()->hal);
modem_lpcon_ll_enable_wifipwr_clock(MODEM_CLOCK_instance()->hal->lpcon_dev, false);
break;
#endif // SOC_WIFI_SUPPORTED
#if SOC_BT_SUPPORTED
case PERIPH_BT_MODULE:
modem_clock_hal_deselect_all_lp_timer_lpclk_source(MODEM_CLOCK_instance()->hal);
modem_lpcon_ll_enable_lp_timer_clock(MODEM_CLOCK_instance()->hal->lpcon_dev, false);
modem_clock_hal_deselect_all_ble_rtc_timer_lpclk_source(MODEM_CLOCK_instance()->hal);
modem_clock_hal_enable_ble_rtc_timer_clock(MODEM_CLOCK_instance()->hal, false);
break;
#endif // SOC_BT_SUPPORTED
case PERIPH_COEX_MODULE:
modem_clock_hal_deselect_all_coex_lpclk_source(MODEM_CLOCK_instance()->hal);
// modem_lpcon_ll_enable_coex_clock(MODEM_CLOCK_instance()->hal->lpcon_dev, false); // TODO: IDF-5727

View File

@ -1,40 +0,0 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
// The HAL layer for MODEM CLOCK
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "hal/modem_syscon_ll.h"
#include "hal/modem_lpcon_ll.h"
#include "hal/modem_clock_types.h"
typedef struct {
modem_syscon_dev_t *syscon_dev;
modem_lpcon_dev_t *lpcon_dev;
} modem_clock_hal_context_t;
void modem_clock_hal_set_clock_domain_icg_bitmap(modem_clock_hal_context_t *hal, modem_clock_domain_t domain, uint32_t bitmap);
void modem_clock_hal_select_lp_timer_lpclk_source(modem_clock_hal_context_t *hal, modem_clock_lpclk_src_t src);
void modem_clock_hal_deselect_all_lp_timer_lpclk_source(modem_clock_hal_context_t *hal);
void modem_clock_hal_select_coex_lpclk_source(modem_clock_hal_context_t *hal, modem_clock_lpclk_src_t src);
void modem_clock_hal_deselect_all_coex_lpclk_source(modem_clock_hal_context_t *hal);
void modem_clock_hal_select_wifi_lpclk_source(modem_clock_hal_context_t *hal, modem_clock_lpclk_src_t src);
void modem_clock_hal_deselect_all_wifi_lpclk_source(modem_clock_hal_context_t *hal);
#ifdef __cplusplus
}
#endif

View File

@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
// The LL layer for ESP32-C6 MODEM SYSCON register operations
// The LL layer for ESP32-C6 MODEM LPCON register operations
#pragma once
@ -25,37 +25,37 @@ static inline void modem_lpcon_ll_enable_test_clk(modem_lpcon_dev_t *hw, bool en
}
__attribute__((always_inline))
static inline void modem_lpcon_ll_enable_lp_timer_slow_osc(modem_lpcon_dev_t *hw, bool en)
static inline void modem_lpcon_ll_enable_ble_rtc_timer_slow_osc(modem_lpcon_dev_t *hw, bool en)
{
hw->lp_timer_conf.clk_lp_timer_sel_osc_slow = en;
}
__attribute__((always_inline))
static inline void modem_lpcon_ll_enable_lp_timer_fast_osc(modem_lpcon_dev_t *hw, bool en)
static inline void modem_lpcon_ll_enable_ble_rtc_timer_fast_osc(modem_lpcon_dev_t *hw, bool en)
{
hw->lp_timer_conf.clk_lp_timer_sel_osc_fast = en;
}
__attribute__((always_inline))
static inline void modem_lpcon_ll_enable_lp_timer_main_xtal(modem_lpcon_dev_t *hw, bool en)
static inline void modem_lpcon_ll_enable_ble_rtc_timer_main_xtal(modem_lpcon_dev_t *hw, bool en)
{
hw->lp_timer_conf.clk_lp_timer_sel_xtal = en;
}
__attribute__((always_inline))
static inline void modem_lpcon_ll_enable_lp_timer_32k_xtal(modem_lpcon_dev_t *hw, bool en)
static inline void modem_lpcon_ll_enable_ble_rtc_timer_32k_xtal(modem_lpcon_dev_t *hw, bool en)
{
hw->lp_timer_conf.clk_lp_timer_sel_xtal32k = en;
}
__attribute__((always_inline))
static inline void modem_lpcon_ll_set_lp_timer_divisor_value(modem_lpcon_dev_t *hw, uint32_t value)
static inline void modem_lpcon_ll_set_ble_rtc_timer_divisor_value(modem_lpcon_dev_t *hw, uint32_t value)
{
hw->lp_timer_conf.clk_lp_timer_div_num = value;
}
__attribute__((always_inline))
static inline uint32_t modem_lpcon_ll_get_lp_timer_divisor_value(modem_lpcon_dev_t *hw)
static inline uint32_t modem_lpcon_ll_get_ble_rtc_timer_divisor_value(modem_lpcon_dev_t *hw)
{
return hw->lp_timer_conf.clk_lp_timer_div_num;
}
@ -163,7 +163,7 @@ static inline void modem_lpcon_ll_enable_i2c_master_clock(modem_lpcon_dev_t *hw,
}
__attribute__((always_inline))
static inline void modem_lpcon_ll_enable_lp_timer_clock(modem_lpcon_dev_t *hw, bool en)
static inline void modem_lpcon_ll_enable_ble_rtc_timer_clock(modem_lpcon_dev_t *hw, bool en)
{
hw->clk_conf.clk_lp_timer_en = en;
}
@ -187,7 +187,7 @@ static inline void modem_lpcon_ll_enable_i2c_master_force_clock(modem_lpcon_dev_
}
__attribute__((always_inline))
static inline void modem_lpcon_ll_enable_lp_timer_force_clock(modem_lpcon_dev_t *hw, bool en)
static inline void modem_lpcon_ll_enable_ble_rtc_timer_force_clock(modem_lpcon_dev_t *hw, bool en)
{
hw->clk_conf_force_on.clk_lp_timer_fo = en;
}

View File

@ -68,39 +68,49 @@ void modem_clock_hal_enable_fe_clock(modem_clock_hal_context_t *hal, bool enable
}
}
void modem_clock_hal_deselect_all_lp_timer_lpclk_source(modem_clock_hal_context_t *hal)
void modem_clock_hal_set_ble_rtc_timer_divisor_value(modem_clock_hal_context_t *hal, uint32_t divider)
{
modem_lpcon_ll_enable_lp_timer_slow_osc(hal->lpcon_dev, false);
modem_lpcon_ll_enable_lp_timer_fast_osc(hal->lpcon_dev, false);
modem_lpcon_ll_enable_lp_timer_32k_xtal(hal->lpcon_dev, false);
modem_lpcon_ll_enable_lp_timer_main_xtal(hal->lpcon_dev, false);
modem_lpcon_ll_set_ble_rtc_timer_divisor_value(hal->lpcon_dev, divider);
}
void modem_clock_hal_select_lp_timer_lpclk_source(modem_clock_hal_context_t *hal, modem_clock_lpclk_src_t src)
void modem_clock_hal_enable_ble_rtc_timer_clock(modem_clock_hal_context_t *hal, bool enable)
{
modem_lpcon_ll_enable_ble_rtc_timer_clock(hal->lpcon_dev, enable);
}
void modem_clock_hal_deselect_all_ble_rtc_timer_lpclk_source(modem_clock_hal_context_t *hal)
{
modem_lpcon_ll_enable_ble_rtc_timer_slow_osc(hal->lpcon_dev, false);
modem_lpcon_ll_enable_ble_rtc_timer_fast_osc(hal->lpcon_dev, false);
modem_lpcon_ll_enable_ble_rtc_timer_32k_xtal(hal->lpcon_dev, false);
modem_lpcon_ll_enable_ble_rtc_timer_main_xtal(hal->lpcon_dev, false);
}
void modem_clock_hal_select_ble_rtc_timer_lpclk_source(modem_clock_hal_context_t *hal, modem_clock_lpclk_src_t src)
{
HAL_ASSERT(src < MODEM_CLOCK_LPCLK_SRC_MAX);
switch (src)
{
case MODEM_CLOCK_LPCLK_SRC_RC_SLOW:
modem_lpcon_ll_enable_lp_timer_slow_osc(hal->lpcon_dev, true);
modem_lpcon_ll_enable_ble_rtc_timer_slow_osc(hal->lpcon_dev, true);
break;
case MODEM_CLOCK_LPCLK_SRC_RC_FAST:
modem_lpcon_ll_enable_lp_timer_fast_osc(hal->lpcon_dev, true);
modem_lpcon_ll_enable_ble_rtc_timer_fast_osc(hal->lpcon_dev, true);
break;
case MODEM_CLOCK_LPCLK_SRC_MAIN_XTAL:
modem_lpcon_ll_enable_lp_timer_main_xtal(hal->lpcon_dev, true);
modem_lpcon_ll_enable_ble_rtc_timer_main_xtal(hal->lpcon_dev, true);
break;
case MODEM_CLOCK_LPCLK_SRC_RC32K:
modem_lpcon_ll_enable_lp_timer_32k_xtal(hal->lpcon_dev, true);
modem_lpcon_ll_enable_ble_rtc_timer_32k_xtal(hal->lpcon_dev, true);
modem_lpcon_ll_select_modem_32k_clock_source(hal->lpcon_dev, MODEM_CLOCK_RC32K_CODE);
break;
case MODEM_CLOCK_LPCLK_SRC_XTAL32K:
modem_lpcon_ll_enable_lp_timer_32k_xtal(hal->lpcon_dev, true);
modem_lpcon_ll_enable_ble_rtc_timer_32k_xtal(hal->lpcon_dev, true);
modem_lpcon_ll_select_modem_32k_clock_source(hal->lpcon_dev, MODEM_CLOCK_XTAL32K_CODE);
break;
case MODEM_CLOCK_LPCLK_SRC_EXT32K:
modem_lpcon_ll_enable_lp_timer_32k_xtal(hal->lpcon_dev, true);
modem_lpcon_ll_enable_ble_rtc_timer_32k_xtal(hal->lpcon_dev, true);
modem_lpcon_ll_select_modem_32k_clock_source(hal->lpcon_dev, MODEM_CLOCK_EXT32K_CODE);
break;
default:

View File

@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
// The HAL layer for MODEM CLOCK (ESP32-C6 specific part)
// The HAL layer for MODEM CLOCK (ESP32-H2 specific part)
#include <stdbool.h>
#include "esp_attr.h"
#include "soc/soc.h"

View File

@ -12,6 +12,7 @@
extern "C" {
#endif
#include "soc/soc_caps.h"
#include "hal/modem_syscon_ll.h"
#include "hal/modem_lpcon_ll.h"
#include "hal/modem_clock_types.h"
@ -21,22 +22,27 @@ typedef struct {
modem_lpcon_dev_t *lpcon_dev;
} modem_clock_hal_context_t;
#if MAC_SUPPORT_PMU_MODEM_STATE
void modem_clock_hal_set_clock_domain_icg_bitmap(modem_clock_hal_context_t *hal, modem_clock_domain_t domain, uint32_t bitmap);
#endif
void modem_clock_hal_enable_fe_clock(modem_clock_hal_context_t *hal, bool enable);
void modem_clock_hal_set_ble_rtc_timer_divisor_value(modem_clock_hal_context_t *hal, uint32_t divider);
#if SOC_BT_SUPPORTED
void modem_clock_hal_set_ble_rtc_timer_divisor_value(modem_clock_hal_context_t *hal, uint32_t divider);
void modem_clock_hal_enable_ble_rtc_timer_clock(modem_clock_hal_context_t *hal, bool enable);
void modem_clock_hal_select_ble_rtc_timer_lpclk_source(modem_clock_hal_context_t *hal, modem_clock_lpclk_src_t src);
void modem_clock_hal_deselect_all_ble_rtc_timer_lpclk_source(modem_clock_hal_context_t *hal);
#endif
void modem_clock_hal_select_coex_lpclk_source(modem_clock_hal_context_t *hal, modem_clock_lpclk_src_t src);
void modem_clock_hal_deselect_all_coex_lpclk_source(modem_clock_hal_context_t *hal);
#if SOC_WIFI_SUPPORTED
void modem_clock_hal_select_wifi_lpclk_source(modem_clock_hal_context_t *hal, modem_clock_lpclk_src_t src);
void modem_clock_hal_deselect_all_wifi_lpclk_source(modem_clock_hal_context_t *hal);
#endif
#ifdef __cplusplus
}
#endif

View File

@ -42,6 +42,7 @@ typedef enum {
PERIPH_SARADC_MODULE,
PERIPH_TEMPSENSOR_MODULE,
PERIPH_REGDMA_MODULE,
/* Peripherals clock managed by the modem_clock driver must be listed last in the enumeration */
PERIPH_WIFI_MODULE,
PERIPH_BT_MODULE,
PERIPH_IEEE802154_MODULE,

View File

@ -27,11 +27,6 @@ typedef enum {
PERIPH_SPI2_MODULE, //SPI2
PERIPH_TWAI0_MODULE,
PERIPH_RNG_MODULE,
PERIPH_WIFI_MODULE,
PERIPH_BT_MODULE,
PERIPH_WIFI_BT_COMMON_MODULE,
PERIPH_BT_BASEBAND_MODULE,
PERIPH_BT_LC_MODULE,
PERIPH_RSA_MODULE,
PERIPH_AES_MODULE,
PERIPH_SHA_MODULE,
@ -45,9 +40,19 @@ typedef enum {
PERIPH_SYSTIMER_MODULE,
PERIPH_SARADC_MODULE,
PERIPH_TEMPSENSOR_MODULE,
/* Peripherals clock managed by the modem_clock driver must be listed last in the enumeration */
PERIPH_BT_MODULE,
PERIPH_IEEE802154_MODULE,
PERIPH_COEX_MODULE,
PERIPH_PHY_MODULE,
PERIPH_MODULE_MAX
} periph_module_t;
#define PERIPH_MODEM_MODULE_MIN PERIPH_BT_MODULE
#define PERIPH_MODEM_MODULE_MAX PERIPH_PHY_MODULE
#define PERIPH_MODEM_MODULE_NUM (PERIPH_MODEM_MODULE_MAX - PERIPH_MODEM_MODULE_MIN + 1)
#define IS_MODEM_MODULE(periph) ((periph>=PERIPH_MODEM_MODULE_MIN) && (periph<=PERIPH_MODEM_MODULE_MAX))
typedef enum {
ETS_PMU_INTR_SOURCE = 0,
ETS_EFUSE_INTR_SOURCE, /**< interrupt of efuse, level, not likely to use*/