mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 18:57:19 +02:00
sleep retention: implement the extra linked list retention for modules with retention clock bugs
This commit is contained in:
@ -101,6 +101,16 @@ void * sleep_retention_find_link_by_id(int id);
|
|||||||
*/
|
*/
|
||||||
void sleep_retention_entries_get(sleep_retention_entries_t *entries);
|
void sleep_retention_entries_get(sleep_retention_entries_t *entries);
|
||||||
|
|
||||||
|
#if SOC_PM_RETENTION_HAS_CLOCK_BUG
|
||||||
|
/**
|
||||||
|
* @brief Software trigger REGDMA to do extra linked list retention
|
||||||
|
*
|
||||||
|
* @param backup_or_restore true for backup register context to memory
|
||||||
|
* or false for restore to register from memory
|
||||||
|
*/
|
||||||
|
void sleep_retention_do_extra_retention(bool backup_or_restore);
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get all registered modules that require sleep retention
|
* @brief Get all registered modules that require sleep retention
|
||||||
*
|
*
|
||||||
|
@ -41,15 +41,21 @@ typedef struct {
|
|||||||
* The PMU module triggers REGDMA to use the corresponding linked list when
|
* The PMU module triggers REGDMA to use the corresponding linked list when
|
||||||
* swtiching between different power states. For example:
|
* swtiching between different power states. For example:
|
||||||
*
|
*
|
||||||
* Current power state Next power state This entry will be used by REGDMA
|
* +---------------+---------------+-------------------+-----------+
|
||||||
* PMU_HP_ACTIVE PMU_HP_SLEEP entry0
|
* | Current | The next | The entry will be | Retention |
|
||||||
* PMU_HP_SLEEP PMU_HP_ACTIVE entry0
|
* | PMU state | PMU state | used by REGDMA | clock |
|
||||||
* PMU_HP_MODEM PMU_HP_SLEEP entry1
|
* +---------------+---------------+-------------------+-----------+
|
||||||
* PMU_HP_SLEEP PMU_HP_MODEM entry1
|
* | PMU_HP_ACTIVE | PMU_HP_SLEEP | entry0 | XTAL |
|
||||||
* PMU_HP_MODEM PMU_HP_ACTIVE entry2
|
* | PMU_HP_SLEEP | PMU_HP_ACTIVE | entry0 | XTAL |
|
||||||
|
* | PMU_HP_MODEM | PMU_HP_SLEEP | ------ | XTAL |
|
||||||
|
* | PMU_HP_SLEEP | PMU_HP_MODEM | entry1 | XTAL |
|
||||||
|
* | PMU_HP_MODEM | PMU_HP_ACTIVE | entry2 | PLL |
|
||||||
|
* |---------------------------------------------------------------|
|
||||||
|
* | PMU_HP_ACTIVE | PMU_HP_ACTIVE | entry3 | PLL | (Clock BUG)
|
||||||
|
* +---------------+---------------+-------------------+-----------+
|
||||||
*
|
*
|
||||||
* +--------+ +-------------------------+ +-------------+ +-----------+ +--------+ +-----+
|
* +--------+ +-------------------------+ +-------------+ +-----------+ +--------+ +-----+
|
||||||
* entry2 -> | | -> | WiFi MAC Minimum System | -> | | -------------------------> | | -> | | -> | End |
|
* entry2 -> | | -> | WiFi MAC Minimum System | -> | | -------------------------> | ######### | -> | ###### | -> | End |
|
||||||
* | SOC | +-------------------------+ | Digital | | Bluetooth | | Zigbee | +-----+
|
* | SOC | +-------------------------+ | Digital | | Bluetooth | | Zigbee | +-----+
|
||||||
* | System | +--------+ | Peripherals | +------+ +------+ | / BLE | | | +-----+
|
* | System | +--------+ | Peripherals | +------+ +------+ | / BLE | | | +-----+
|
||||||
* entry0 -> | | ----------> | | ---------> | | -> | | -> | | -> | | -> | | -> | End |
|
* entry0 -> | | ----------> | | ---------> | | -> | | -> | | -> | | -> | | -> | End |
|
||||||
@ -57,6 +63,22 @@ typedef struct {
|
|||||||
* | System | | MAC | | BB | +-----+
|
* | System | | MAC | | BB | +-----+
|
||||||
* entry1 ------------------------> | |-----------------------------> | | -> | | -> | End |
|
* entry1 ------------------------> | |-----------------------------> | | -> | | -> | End |
|
||||||
* +--------+ +------+ +------+ +-----+
|
* +--------+ +------+ +------+ +-----+
|
||||||
|
*
|
||||||
|
* The entry3 (alias: extra linked list) is used for backup and restore of
|
||||||
|
* modules (such as BLE or 15.4 modules) with retention clock bugs.
|
||||||
|
*
|
||||||
|
* +---------+ +----------+ +-------------+ +-----+
|
||||||
|
* entry3 -> | BLE MAC | -> | 15.4 MAC | -> | BLE/15.4 BB | -> | End |
|
||||||
|
* +---------+ +----------+ +-------------+ +-----+
|
||||||
|
*
|
||||||
|
* Using it (extra linked list) for retention has the following constraints:
|
||||||
|
* 1. The PLL clock must be enabled (can be done with esp_pm_lock_acquire()
|
||||||
|
* interface to acquire a pm lock of type ESP_PM_APB_FREQ_MAX.
|
||||||
|
* 2. When using the sleep_retention_entries_create() interface to create an
|
||||||
|
* extra linked list, the node owner must be equal to BIT(3).
|
||||||
|
* 3. Use the sleep_retention_do_extra_retention() interface to backup or
|
||||||
|
* restore the register context, which ensures only one backup or restore
|
||||||
|
* when multiple modules (BLE and 15.4) exists.
|
||||||
*/
|
*/
|
||||||
#define SLEEP_RETENTION_REGDMA_LINK_NR_PRIORITIES (8u)
|
#define SLEEP_RETENTION_REGDMA_LINK_NR_PRIORITIES (8u)
|
||||||
#define SLEEP_RETENTION_REGDMA_LINK_HIGHEST_PRIORITY (0)
|
#define SLEEP_RETENTION_REGDMA_LINK_HIGHEST_PRIORITY (0)
|
||||||
@ -71,9 +93,18 @@ typedef struct {
|
|||||||
_lock_t lock;
|
_lock_t lock;
|
||||||
regdma_link_priority_t highpri;
|
regdma_link_priority_t highpri;
|
||||||
uint32_t modules;
|
uint32_t modules;
|
||||||
|
#if SOC_PM_RETENTION_HAS_CLOCK_BUG
|
||||||
|
#define EXTRA_LINK_NUM (REGDMA_LINK_ENTRY_NUM - 1)
|
||||||
|
int extra_refs;
|
||||||
|
#endif
|
||||||
} sleep_retention_t;
|
} sleep_retention_t;
|
||||||
|
|
||||||
static DRAM_ATTR __attribute__((unused)) sleep_retention_t s_retention = { .highpri = (uint8_t)-1, .modules = 0 };
|
static DRAM_ATTR __attribute__((unused)) sleep_retention_t s_retention = {
|
||||||
|
.highpri = (uint8_t)-1, .modules = 0
|
||||||
|
#if SOC_PM_RETENTION_HAS_CLOCK_BUG
|
||||||
|
, .extra_refs = 0
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
#define SLEEP_RETENTION_ENTRY_BITMAP_MASK (BIT(REGDMA_LINK_ENTRY_NUM) - 1)
|
#define SLEEP_RETENTION_ENTRY_BITMAP_MASK (BIT(REGDMA_LINK_ENTRY_NUM) - 1)
|
||||||
#define SLEEP_RETENTION_ENTRY_BITMAP(bitmap) ((bitmap) & SLEEP_RETENTION_ENTRY_BITMAP_MASK)
|
#define SLEEP_RETENTION_ENTRY_BITMAP(bitmap) ((bitmap) & SLEEP_RETENTION_ENTRY_BITMAP_MASK)
|
||||||
@ -358,6 +389,13 @@ static esp_err_t sleep_retention_entries_create_impl(const sleep_retention_entri
|
|||||||
{
|
{
|
||||||
_lock_acquire_recursive(&s_retention.lock);
|
_lock_acquire_recursive(&s_retention.lock);
|
||||||
for (int i = num - 1; i >= 0; i--) {
|
for (int i = num - 1; i >= 0; i--) {
|
||||||
|
#if SOC_PM_RETENTION_HAS_CLOCK_BUG
|
||||||
|
if ((retent[i].owner > BIT(EXTRA_LINK_NUM)) && (retent[i].config.id != 0xffff)) {
|
||||||
|
_lock_release_recursive(&s_retention.lock);
|
||||||
|
sleep_retention_entries_do_destroy(module);
|
||||||
|
return ESP_ERR_NOT_SUPPORTED;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
void *link = sleep_retention_entries_try_create(&retent[i].config, retent[i].owner, priority, module);
|
void *link = sleep_retention_entries_try_create(&retent[i].config, retent[i].owner, priority, module);
|
||||||
if (link == NULL) {
|
if (link == NULL) {
|
||||||
_lock_release_recursive(&s_retention.lock);
|
_lock_release_recursive(&s_retention.lock);
|
||||||
@ -464,3 +502,31 @@ uint32_t IRAM_ATTR sleep_retention_get_modules(void)
|
|||||||
{
|
{
|
||||||
return s_retention.modules;
|
return s_retention.modules;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if SOC_PM_RETENTION_HAS_CLOCK_BUG
|
||||||
|
void sleep_retention_do_extra_retention(bool backup_or_restore)
|
||||||
|
{
|
||||||
|
_lock_acquire_recursive(&s_retention.lock);
|
||||||
|
if (s_retention.highpri < SLEEP_RETENTION_REGDMA_LINK_HIGHEST_PRIORITY ||
|
||||||
|
s_retention.highpri > SLEEP_RETENTION_REGDMA_LINK_LOWEST_PRIORITY) {
|
||||||
|
_lock_release_recursive(&s_retention.lock);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const uint32_t clk_bug_modules = SLEEP_RETENTION_MODULE_BLE_MAC | SLEEP_RETENTION_MODULE_802154_MAC;
|
||||||
|
const int cnt_modules = __builtin_popcount(clk_bug_modules & s_retention.modules);
|
||||||
|
// Set extra linked list head pointer to hardware
|
||||||
|
pau_regdma_set_extra_link_addr(s_retention.lists[s_retention.highpri].entries[EXTRA_LINK_NUM]);
|
||||||
|
if (backup_or_restore) {
|
||||||
|
if (s_retention.extra_refs++ == (cnt_modules - 1)) {
|
||||||
|
pau_regdma_trigger_extra_link_backup();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (--s_retention.extra_refs == (cnt_modules - 1)) {
|
||||||
|
pau_regdma_trigger_extra_link_restore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int refs = s_retention.extra_refs;
|
||||||
|
_lock_release_recursive(&s_retention.lock);
|
||||||
|
assert(refs >= 0 && refs <= cnt_modules);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@ -1147,6 +1147,10 @@ config SOC_PM_MODEM_RETENTION_BY_REGDMA
|
|||||||
bool
|
bool
|
||||||
default y
|
default y
|
||||||
|
|
||||||
|
config SOC_PM_RETENTION_HAS_CLOCK_BUG
|
||||||
|
bool
|
||||||
|
default y
|
||||||
|
|
||||||
config SOC_PM_PAU_LINK_NUM
|
config SOC_PM_PAU_LINK_NUM
|
||||||
int
|
int
|
||||||
default 4
|
default 4
|
||||||
|
@ -475,6 +475,7 @@
|
|||||||
|
|
||||||
#define SOC_PM_CPU_RETENTION_BY_SW (1)
|
#define SOC_PM_CPU_RETENTION_BY_SW (1)
|
||||||
#define SOC_PM_MODEM_RETENTION_BY_REGDMA (1)
|
#define SOC_PM_MODEM_RETENTION_BY_REGDMA (1)
|
||||||
|
#define SOC_PM_RETENTION_HAS_CLOCK_BUG (1)
|
||||||
|
|
||||||
#define SOC_PM_PAU_LINK_NUM (4)
|
#define SOC_PM_PAU_LINK_NUM (4)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user