mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
fix: add reference count control for modem clock devices
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -51,8 +51,9 @@ typedef struct modem_clock_context {
|
|||||||
modem_clock_hal_context_t *hal;
|
modem_clock_hal_context_t *hal;
|
||||||
portMUX_TYPE lock;
|
portMUX_TYPE lock;
|
||||||
struct {
|
struct {
|
||||||
int16_t refs;
|
int16_t refs; /* Reference count for this device, if with_refcnt is enabled */
|
||||||
uint16_t reserved; /* reserved for 4 bytes aligned */
|
uint16_t with_refcnt : 1; /* Enable reference count management (true=use refs, false=ignore refs) */
|
||||||
|
uint16_t reserved : 15; /* reserved for 15 bits aligned */
|
||||||
void (*configure)(struct modem_clock_context *, bool);
|
void (*configure)(struct modem_clock_context *, bool);
|
||||||
} dev[MODEM_CLOCK_DEVICE_MAX];
|
} dev[MODEM_CLOCK_DEVICE_MAX];
|
||||||
/* the low-power clock source for each module */
|
/* the low-power clock source for each module */
|
||||||
@@ -141,25 +142,25 @@ modem_clock_context_t * __attribute__((weak)) IRAM_ATTR MODEM_CLOCK_instance(voi
|
|||||||
static DRAM_ATTR modem_clock_context_t modem_clock_context = {
|
static DRAM_ATTR modem_clock_context_t modem_clock_context = {
|
||||||
.hal = &modem_clock_hal, .lock = portMUX_INITIALIZER_UNLOCKED,
|
.hal = &modem_clock_hal, .lock = portMUX_INITIALIZER_UNLOCKED,
|
||||||
.dev = {
|
.dev = {
|
||||||
[MODEM_CLOCK_MODEM_ADC_COMMON_FE] = { .refs = 0, .configure = modem_clock_modem_adc_common_fe_configure },
|
[MODEM_CLOCK_MODEM_ADC_COMMON_FE] = { .refs = 0, .with_refcnt = true, .configure = modem_clock_modem_adc_common_fe_configure },
|
||||||
[MODEM_CLOCK_MODEM_PRIVATE_FE] = { .refs = 0, .configure = modem_clock_modem_private_fe_configure },
|
[MODEM_CLOCK_MODEM_PRIVATE_FE] = { .refs = 0, .with_refcnt = true, .configure = modem_clock_modem_private_fe_configure },
|
||||||
[MODEM_CLOCK_COEXIST] = { .refs = 0, .configure = modem_clock_coex_configure },
|
[MODEM_CLOCK_COEXIST] = { .refs = 0, .with_refcnt = true, .configure = modem_clock_coex_configure },
|
||||||
[MODEM_CLOCK_I2C_MASTER] = { .refs = 0, .configure = modem_clock_i2c_master_configure },
|
[MODEM_CLOCK_I2C_MASTER] = { .refs = 0, .with_refcnt = true, .configure = modem_clock_i2c_master_configure },
|
||||||
#if SOC_WIFI_SUPPORTED
|
#if SOC_WIFI_SUPPORTED
|
||||||
[MODEM_CLOCK_WIFI_MAC] = { .refs = 0, .configure = modem_clock_wifi_mac_configure },
|
[MODEM_CLOCK_WIFI_MAC] = { .refs = 0, .with_refcnt = true, .configure = modem_clock_wifi_mac_configure },
|
||||||
[MODEM_CLOCK_WIFI_BB] = { .refs = 0, .configure = modem_clock_wifi_bb_configure },
|
[MODEM_CLOCK_WIFI_BB] = { .refs = 0, .with_refcnt = true, .configure = modem_clock_wifi_bb_configure },
|
||||||
#endif
|
#endif
|
||||||
[MODEM_CLOCK_ETM] = { .refs = 0, .configure = modem_clock_etm_configure },
|
[MODEM_CLOCK_ETM] = { .refs = 0, .with_refcnt = true, .configure = modem_clock_etm_configure },
|
||||||
#if SOC_BT_SUPPORTED
|
#if SOC_BT_SUPPORTED
|
||||||
[MODEM_CLOCK_BLE_MAC] = { .refs = 0, .configure = modem_clock_ble_mac_configure },
|
[MODEM_CLOCK_BLE_MAC] = { .refs = 0, .with_refcnt = true, .configure = modem_clock_ble_mac_configure },
|
||||||
#endif
|
#endif
|
||||||
#if SOC_IEEE802154_SUPPORTED || SOC_BT_SUPPORTED
|
#if SOC_IEEE802154_SUPPORTED || SOC_BT_SUPPORTED
|
||||||
[MODEM_CLOCK_BT_I154_COMMON_BB] = { .refs = 0, .configure = modem_clock_ble_i154_bb_configure },
|
[MODEM_CLOCK_BT_I154_COMMON_BB] = { .refs = 0, .with_refcnt = true, .configure = modem_clock_ble_i154_bb_configure },
|
||||||
#endif
|
#endif
|
||||||
#if SOC_IEEE802154_SUPPORTED
|
#if SOC_IEEE802154_SUPPORTED
|
||||||
[MODEM_CLOCK_802154_MAC] = { .refs = 0, .configure = modem_clock_ieee802154_mac_configure },
|
[MODEM_CLOCK_802154_MAC] = { .refs = 0, .with_refcnt = true, .configure = modem_clock_ieee802154_mac_configure },
|
||||||
#endif
|
#endif
|
||||||
[MODEM_CLOCK_DATADUMP] = { .refs = 0, .configure = modem_clock_data_dump_configure }
|
[MODEM_CLOCK_DATADUMP] = { .refs = 0, .with_refcnt = true, .configure = modem_clock_data_dump_configure }
|
||||||
},
|
},
|
||||||
.lpclk_src = { [0 ... PERIPH_MODEM_MODULE_NUM - 1] = MODEM_CLOCK_LPCLK_SRC_INVALID }
|
.lpclk_src = { [0 ... PERIPH_MODEM_MODULE_NUM - 1] = MODEM_CLOCK_LPCLK_SRC_INVALID }
|
||||||
};
|
};
|
||||||
@@ -202,11 +203,14 @@ esp_err_t modem_clock_domain_clk_gate_disable(modem_clock_domain_t domain, pmu_h
|
|||||||
|
|
||||||
static void IRAM_ATTR modem_clock_device_enable(modem_clock_context_t *ctx, uint32_t dev_map)
|
static void IRAM_ATTR modem_clock_device_enable(modem_clock_context_t *ctx, uint32_t dev_map)
|
||||||
{
|
{
|
||||||
|
int16_t refs = 0;
|
||||||
portENTER_CRITICAL_SAFE(&ctx->lock);
|
portENTER_CRITICAL_SAFE(&ctx->lock);
|
||||||
for (int i = 0; dev_map; dev_map >>= 1, i++) {
|
for (int i = 0; dev_map; dev_map >>= 1, i++) {
|
||||||
if (dev_map & BIT(0)) {
|
if (dev_map & BIT(0)) {
|
||||||
ctx->dev[i].refs++;
|
refs = ctx->dev[i].with_refcnt ? ctx->dev[i].refs++ : refs;
|
||||||
(*ctx->dev[i].configure)(ctx, true);
|
if (refs == 0 || !ctx->dev[i].with_refcnt) {
|
||||||
|
(*ctx->dev[i].configure)(ctx, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
portEXIT_CRITICAL_SAFE(&ctx->lock);
|
portEXIT_CRITICAL_SAFE(&ctx->lock);
|
||||||
@@ -218,10 +222,13 @@ static void IRAM_ATTR modem_clock_device_disable(modem_clock_context_t *ctx, uin
|
|||||||
portENTER_CRITICAL_SAFE(&ctx->lock);
|
portENTER_CRITICAL_SAFE(&ctx->lock);
|
||||||
for (int i = 0; dev_map; dev_map >>= 1, i++) {
|
for (int i = 0; dev_map; dev_map >>= 1, i++) {
|
||||||
if (dev_map & BIT(0)) {
|
if (dev_map & BIT(0)) {
|
||||||
refs = --ctx->dev[i].refs;
|
refs = ctx->dev[i].with_refcnt ? --ctx->dev[i].refs : refs;
|
||||||
if (refs == 0) {
|
if (refs == 0 || !ctx->dev[i].with_refcnt) {
|
||||||
(*ctx->dev[i].configure)(ctx, false);
|
(*ctx->dev[i].configure)(ctx, false);
|
||||||
}
|
}
|
||||||
|
if (ctx->dev[i].with_refcnt) {
|
||||||
|
assert(refs >= 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
portEXIT_CRITICAL_SAFE(&ctx->lock);
|
portEXIT_CRITICAL_SAFE(&ctx->lock);
|
||||||
|
|||||||
Reference in New Issue
Block a user