mirror of
https://github.com/espressif/esp-idf
synced 2025-03-10 01:29:21 -04:00
72 lines
3.9 KiB
C
72 lines
3.9 KiB
C
/*
|
|
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include "esp_private/sleep_clock.h"
|
|
|
|
bool clock_domain_pd_allowed(void)
|
|
{
|
|
const sleep_retention_module_bitmap_t inited_modules = sleep_retention_get_inited_modules();
|
|
const sleep_retention_module_bitmap_t created_modules = sleep_retention_get_created_modules();
|
|
const sleep_retention_module_bitmap_t sys_clk_dep_modules = (sleep_retention_module_bitmap_t){ .bitmap[SLEEP_RETENTION_MODULE_SYS_PERIPH >> 5] = BIT(SLEEP_RETENTION_MODULE_SYS_PERIPH % 32) };
|
|
|
|
/* The clock and reset of MODEM (WiFi, BLE and 15.4) modules are managed
|
|
* through MODEM_SYSCON, when one or more MODEMs are initialized, it is
|
|
* necessary to check the state of CLOCK_MODEM to determine MODEM domain on
|
|
* or off. The clock and reset of digital peripherals are managed through
|
|
* PCR, with TOP domain similar to MODEM domain. */
|
|
#if SOC_WIFI_SUPPORTED || SOC_BT_SUPPORTED || SOC_IEEE802154_SUPPORTED
|
|
sleep_retention_module_bitmap_t modem_clk_dep_modules = (sleep_retention_module_bitmap_t){ .bitmap = { 0 } };
|
|
#endif
|
|
#if SOC_WIFI_SUPPORTED
|
|
modem_clk_dep_modules.bitmap[SLEEP_RETENTION_MODULE_WIFI_MAC >> 5] |= BIT(SLEEP_RETENTION_MODULE_WIFI_MAC % 32);
|
|
modem_clk_dep_modules.bitmap[SLEEP_RETENTION_MODULE_WIFI_BB >> 5] |= BIT(SLEEP_RETENTION_MODULE_WIFI_BB % 32);
|
|
#endif
|
|
#if SOC_BT_SUPPORTED
|
|
modem_clk_dep_modules.bitmap[SLEEP_RETENTION_MODULE_BLE_MAC >> 5] |= BIT(SLEEP_RETENTION_MODULE_BLE_MAC % 32);
|
|
modem_clk_dep_modules.bitmap[SLEEP_RETENTION_MODULE_BT_BB >> 5] |= BIT(SLEEP_RETENTION_MODULE_BT_BB % 32);
|
|
#endif
|
|
#if SOC_IEEE802154_SUPPORTED
|
|
modem_clk_dep_modules.bitmap[SLEEP_RETENTION_MODULE_802154_MAC >> 5] |= BIT(SLEEP_RETENTION_MODULE_802154_MAC % 32);
|
|
modem_clk_dep_modules.bitmap[SLEEP_RETENTION_MODULE_BT_BB >> 5] |= BIT(SLEEP_RETENTION_MODULE_BT_BB % 32);
|
|
#endif
|
|
|
|
const sleep_retention_module_bitmap_t null_module = (sleep_retention_module_bitmap_t){ .bitmap = { 0 } };
|
|
|
|
sleep_retention_module_bitmap_t mask = (sleep_retention_module_bitmap_t){ .bitmap = { 0 } };
|
|
const sleep_retention_module_bitmap_t system_modules = sleep_retention_module_bitmap_and(inited_modules, sys_clk_dep_modules);
|
|
if (!sleep_retention_module_bitmap_eq(system_modules, null_module)) {
|
|
mask.bitmap[SLEEP_RETENTION_MODULE_CLOCK_SYSTEM >> 5] |= BIT(SLEEP_RETENTION_MODULE_CLOCK_SYSTEM % 32);
|
|
}
|
|
#if SOC_WIFI_SUPPORTED || SOC_BT_SUPPORTED || SOC_IEEE802154_SUPPORTED
|
|
const sleep_retention_module_bitmap_t modem_modules = sleep_retention_module_bitmap_and(inited_modules, modem_clk_dep_modules);
|
|
if (!sleep_retention_module_bitmap_eq(modem_modules, null_module)) {
|
|
mask.bitmap[SLEEP_RETENTION_MODULE_CLOCK_MODEM >> 5] |= BIT(SLEEP_RETENTION_MODULE_CLOCK_MODEM % 32);
|
|
}
|
|
#endif
|
|
|
|
const sleep_retention_module_bitmap_t clock_domain_inited_modules = sleep_retention_module_bitmap_and(inited_modules, mask);
|
|
const sleep_retention_module_bitmap_t clock_domain_created_modules = sleep_retention_module_bitmap_and(created_modules, mask);
|
|
return sleep_retention_module_bitmap_eq(clock_domain_inited_modules, clock_domain_created_modules);
|
|
}
|
|
|
|
ESP_SYSTEM_INIT_FN(sleep_clock_startup_init, SECONDARY, BIT(0), 106)
|
|
{
|
|
sleep_retention_module_init_param_t init_param = {
|
|
.cbs = { .create = { .handle = sleep_clock_system_retention_init, .arg = NULL } },
|
|
.attribute = SLEEP_RETENTION_MODULE_ATTR_PASSIVE
|
|
};
|
|
sleep_retention_module_init(SLEEP_RETENTION_MODULE_CLOCK_SYSTEM, &init_param);
|
|
|
|
#if CONFIG_MAC_BB_PD || CONFIG_BT_LE_SLEEP_ENABLE || CONFIG_IEEE802154_SLEEP_ENABLE
|
|
init_param = (sleep_retention_module_init_param_t) {
|
|
.cbs = { .create = { .handle = sleep_clock_modem_retention_init, .arg = NULL } },
|
|
.attribute = SLEEP_RETENTION_MODULE_ATTR_PASSIVE
|
|
};
|
|
sleep_retention_module_init(SLEEP_RETENTION_MODULE_CLOCK_MODEM, &init_param);
|
|
#endif
|
|
return ESP_OK;
|
|
}
|