Skip to content

Commit

Permalink
Merge branch 'feat/sleep_retention_depends_power_state_management_v5.…
Browse files Browse the repository at this point in the history
…2' into 'release/v5.2'

backport v5.2: sleep retention multiple modules initialization and dependency management

See merge request espressif/esp-idf!30344
  • Loading branch information
jack0c committed Apr 22, 2024
2 parents b0eef7f + f20186f commit 470d540
Show file tree
Hide file tree
Showing 28 changed files with 950 additions and 350 deletions.
23 changes: 21 additions & 2 deletions components/bt/controller/esp32c6/bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,10 @@ IRAM_ATTR void controller_wakeup_cb(void *arg)
}

#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
static esp_err_t sleep_modem_ble_mac_modem_state_init(uint8_t extra)
static esp_err_t sleep_modem_ble_mac_retention_init(void *arg)
{
uint8_t size;
int extra = *(int *)arg;
const sleep_retention_entries_config_t *ble_mac_modem_config = esp_ble_mac_retention_link_get(&size, extra);
esp_err_t err = sleep_retention_entries_create(ble_mac_modem_config, size, REGDMA_LINK_PRI_5, SLEEP_RETENTION_MODULE_BLE_MAC);
if (err == ESP_OK) {
Expand All @@ -523,9 +524,27 @@ static esp_err_t sleep_modem_ble_mac_modem_state_init(uint8_t extra)
return err;
}

static esp_err_t sleep_modem_ble_mac_modem_state_init(uint8_t extra)
{
int retention_args = extra;
sleep_retention_module_init_param_t init_param = {
.cbs = { .create = { .handle = sleep_modem_ble_mac_retention_init, .arg = &retention_args } },
.depends = BIT(SLEEP_RETENTION_MODULE_BT_BB)
};
esp_err_t err = sleep_retention_module_init(SLEEP_RETENTION_MODULE_BLE_MAC, &init_param);
if (err == ESP_OK) {
err = sleep_retention_module_allocate(SLEEP_RETENTION_MODULE_BLE_MAC);
}
return err;
}

static void sleep_modem_ble_mac_modem_state_deinit(void)
{
sleep_retention_entries_destroy(SLEEP_RETENTION_MODULE_BLE_MAC);
esp_err_t err = sleep_retention_module_free(SLEEP_RETENTION_MODULE_BLE_MAC);
if (err == ESP_OK) {
err = sleep_retention_module_deinit(SLEEP_RETENTION_MODULE_BLE_MAC);
assert(err == ESP_OK);
}
}

void sleep_modem_light_sleep_overhead_set(uint32_t overhead)
Expand Down
23 changes: 21 additions & 2 deletions components/bt/controller/esp32h2/bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,10 @@ IRAM_ATTR void controller_wakeup_cb(void *arg)
}

#ifdef CONFIG_FREERTOS_USE_TICKLESS_IDLE
static esp_err_t sleep_modem_ble_mac_modem_state_init(uint8_t extra)
static esp_err_t sleep_modem_ble_mac_retention_init(void *arg)
{
uint8_t size;
int extra = *(int *)arg;
const sleep_retention_entries_config_t *ble_mac_modem_config = esp_ble_mac_retention_link_get(&size, extra);
esp_err_t err = sleep_retention_entries_create(ble_mac_modem_config, size, REGDMA_LINK_PRI_5, SLEEP_RETENTION_MODULE_BLE_MAC);
if (err == ESP_OK) {
Expand All @@ -512,9 +513,27 @@ static esp_err_t sleep_modem_ble_mac_modem_state_init(uint8_t extra)
return err;
}

static esp_err_t sleep_modem_ble_mac_modem_state_init(uint8_t extra)
{
int retention_args = extra;
sleep_retention_module_init_param_t init_param = {
.cbs = { .create = { .handle = sleep_modem_ble_mac_retention_init, .arg = &retention_args } },
.depends = BIT(SLEEP_RETENTION_MODULE_BT_BB)
};
esp_err_t err = sleep_retention_module_init(SLEEP_RETENTION_MODULE_BLE_MAC, &init_param);
if (err == ESP_OK) {
err = sleep_retention_module_allocate(SLEEP_RETENTION_MODULE_BLE_MAC);
}
return err;
}

static void sleep_modem_ble_mac_modem_state_deinit(void)
{
sleep_retention_entries_destroy(SLEEP_RETENTION_MODULE_BLE_MAC);
esp_err_t err = sleep_retention_module_free(SLEEP_RETENTION_MODULE_BLE_MAC);
if (err == ESP_OK) {
err = sleep_retention_module_deinit(SLEEP_RETENTION_MODULE_BLE_MAC);
assert(err == ESP_OK);
}
}

void sleep_modem_light_sleep_overhead_set(uint32_t overhead)
Expand Down
64 changes: 50 additions & 14 deletions components/esp_hw_support/dma/gdma_sleep_retention.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,75 @@
#include "soc/soc_caps.h"

#include "esp_err.h"
#include "esp_check.h"
#if CONFIG_GDMA_ENABLE_DEBUG_LOG
// The local log level must be defined before including esp_log.h
// Set the maximum log level for this source file
#define LOG_LOCAL_LEVEL ESP_LOG_DEBUG
#endif
#include "esp_log.h"
#include "esp_check.h"
#include "esp_private/sleep_retention.h"
#include "esp_private/esp_regdma.h"

#include "sleep_gdma_retention_context.inc"
#include "hal/gdma_ll.h"

static const char *TAG = "gdma";

#define SLEEP_RETENTION_MODULE_GDMA_CH(group_id, pair_id) (SLEEP_RETENTION_MODULE_GDMA_CH0 << (SOC_GDMA_PAIRS_PER_GROUP_MAX * group_id) << pair_id)
typedef struct {
int group_id;
int pair_id;
} gdma_channel_retention_arg_t;

typedef struct gdma_chx_reg_ctx_link {
const sleep_retention_entries_config_t *link_list;
uint32_t link_num;
} gdma_chx_reg_ctx_link_t;

static esp_err_t sleep_modem_gdma_channel_retention_init(sleep_retention_module_bitmap_t module)
#include "sleep_gdma_retention_context.inc"

static esp_err_t sleep_gdma_channel_retention_init(void *arg)
{
uint32_t id = __builtin_ctz(module / SLEEP_RETENTION_MODULE_GDMA_CH0);
esp_err_t err = sleep_retention_entries_create(gdma_chx_regs_retention[id].link_list, gdma_chx_regs_retention[id].link_num, REGDMA_LINK_PRI_7, module);
gdma_channel_retention_arg_t *parg = (gdma_channel_retention_arg_t *)arg;
int group_id = parg->group_id;
int pair_id = parg->pair_id;

sleep_retention_module_bitmap_t module = GDMA_CH_RETENTION_GET_MODULE_ID(group_id, pair_id);
esp_err_t err = sleep_retention_entries_create(gdma_chx_regs_retention[group_id][pair_id].link_list, gdma_chx_regs_retention[group_id][pair_id].link_num, REGDMA_LINK_PRI_7, module);
if (err == ESP_OK) {
int group_id = id / SOC_GDMA_PAIRS_PER_GROUP_MAX;
int pair_id = id % SOC_GDMA_PAIRS_PER_GROUP_MAX;
ESP_LOGI(TAG, "GDMA pair (%d, %d) retention initialization", group_id, pair_id);
ESP_LOGD(TAG, "GDMA pair (%d, %d) retention initialization", group_id, pair_id);
}

ESP_RETURN_ON_ERROR(err, TAG, "Failed to create sleep retention linked list for GDMA pair (%d, %d) retention", group_id, pair_id);
return err;
}

esp_err_t gdma_sleep_retention_init(int group_id, int pair_id)
{
esp_err_t err = ESP_OK;
err = sleep_modem_gdma_channel_retention_init(SLEEP_RETENTION_MODULE_GDMA_CH(group_id, pair_id));
ESP_RETURN_ON_ERROR(err, TAG, "Failed to create sleep retention linked list for GDMA pair (%d, %d) retention", group_id, pair_id);
gdma_channel_retention_arg_t arg = { .group_id = group_id, .pair_id = pair_id };
sleep_retention_module_init_param_t init_param = {
.cbs = { .create = { .handle = sleep_gdma_channel_retention_init, .arg = &arg } },
.depends = BIT(SLEEP_RETENTION_MODULE_CLOCK_SYSTEM)
};
sleep_retention_module_bitmap_t module = GDMA_CH_RETENTION_GET_MODULE_ID(group_id, pair_id);
esp_err_t err = sleep_retention_module_init(module, &init_param);
if (err == ESP_OK) {
err = sleep_retention_module_allocate(module);
if (err != ESP_OK) {
ESP_LOGW(TAG, "Failed to allocate sleep retention linked list for GDMA retention");
}
}
return err;
}

esp_err_t gdma_sleep_retention_deinit(int group_id, int pair_id)
{
sleep_retention_entries_destroy(SLEEP_RETENTION_MODULE_GDMA_CH(group_id, pair_id));
return ESP_OK;;
esp_err_t err = sleep_retention_module_free(GDMA_CH_RETENTION_GET_MODULE_ID(group_id, pair_id));
if (err != ESP_OK) {
ESP_LOGW(TAG, "GDMA pair (%d, %d) retention destroy failed", group_id, pair_id);
}
err = sleep_retention_module_deinit(GDMA_CH_RETENTION_GET_MODULE_ID(group_id, pair_id));
if (err != ESP_OK) {
ESP_LOGW(TAG, "GDMA pair (%d, %d) retention deinit failed", group_id, pair_id);
}
return err;
}
8 changes: 4 additions & 4 deletions components/esp_hw_support/include/esp_private/esp_regdma.h
Original file line number Diff line number Diff line change
Expand Up @@ -578,11 +578,11 @@ void regdma_link_stats(void *link, int entry);
void regdma_link_set_write_wait_content(void *link, uint32_t value, uint32_t mask);

/**
* @brief Print all node information of the REGDMA linked list indicated by the entry argument
* @brief Dump all node information of the REGDMA linked list indicated by the entry argument
* @param link The REGDMA linkded list head pointer
* @param entry For nodes that support branching, use the branch specified by entry argument recursively
*/
void regdma_link_show_memories(void *link, int entry);
void regdma_link_dump(FILE *out, void *link, int entry);

/**
* @brief Update REGDMA linked list node next pointers
Expand Down Expand Up @@ -625,7 +625,7 @@ void *regdma_find_module_link_tail(void *link, void *tail, int entry, uint32_t m

/**
* @brief Find the tail node of the previous module of the specified module in the REGDMA linked list
* indicated by the entry argument starting from the link argment to the end of the tail argument
* indicated by the entry argument starting from the link argument to the end of the tail argument
* @param link The REGDMA linkded list head pointer
* @param tail The REGDMA linkded list tail pointer
* @param entry For nodes that support branching, use the branch specified by entry argument recursively
Expand All @@ -636,7 +636,7 @@ void *regdma_find_prev_module_link_tail(void *link, void *tail, int entry, uint3

/**
* @brief Find the head node of the next module of the specified module in the REGDMA linked list
* indicated by the entry argument starting from the link argment to the end of the tail argument
* indicated by the entry argument starting from the link argument to the end of the tail argument
* @param link The REGDMA linkded list head pointer
* @param tail The REGDMA linkded list tail pointer
* @param entry For nodes that support branching, use the branch specified by entry argument recursively
Expand Down
30 changes: 1 addition & 29 deletions components/esp_hw_support/include/esp_private/sleep_clock.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -31,34 +31,6 @@ extern "C" {
*/
bool clock_domain_pd_allowed(void);

/**
* @brief PCR module power down initialize
*
* @return ESP_OK on success
* ESP_ERR_INVALID_ARG on invalid sleep_retention_entries_create args
* No memory for the retention link
*/
esp_err_t sleep_clock_system_retention_init(void);

/**
* @brief PCR module power down deinitialize
*/
void sleep_clock_system_retention_deinit(void);

/**
* @brief Modem syscon module power down initialize
*
* @return ESP_OK on success
* ESP_ERR_INVALID_ARG on invalid sleep_retention_entries_create args
* No memory for the retention link
*/
esp_err_t sleep_clock_modem_retention_init(void);

/**
* @brief Modem syscon module power down deinitialize
*/
void sleep_clock_modem_retention_deinit(void);

#ifdef __cplusplus
}
#endif

0 comments on commit 470d540

Please sign in to comment.