mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
feat(ble): supported placing bt function in iram on esp32-h4 and esp32-s31
This commit is contained in:
@@ -37,15 +37,26 @@
|
||||
*/
|
||||
#define BTDM_LOG_TAG "BTDM_SLEEP"
|
||||
|
||||
#define BTDM_RTC_DELAY_US_LIGHT_SLEEP (2000)
|
||||
#define BTDM_RTC_DELAY_US_LIGHT_SLEEP (1800)
|
||||
#define BTDM_RTC_DELAY_US_MODEM_SLEEP (1500)
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint32_t rsv:31;
|
||||
uint32_t bt_wakeup:1;
|
||||
};
|
||||
uint32_t val;
|
||||
} btdm_lp_wakeup_params_t;
|
||||
|
||||
/*
|
||||
***************************************************************************************************
|
||||
* External Functions
|
||||
***************************************************************************************************
|
||||
*/
|
||||
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
|
||||
#if UC_BT_CTRL_SLEEP_ENABLE
|
||||
static bool btdm_lp_check_wakeup_by_bt(void);
|
||||
#endif // UC_BT_CTRL_SLEEP_ENABLE
|
||||
extern bool r_btdm_sleep_should_skip_light_sleep_check(void);
|
||||
extern const sleep_retention_entries_config_t *r_btdm_mac_retention_link_get(uint8_t *size);
|
||||
extern void r_btdm_sleep_wake_up_overhead_set(uint32_t overhead);
|
||||
@@ -73,6 +84,7 @@ static DRAM_ATTR esp_pm_lock_handle_t s_pm_lock = NULL;
|
||||
#endif // CONFIG_PM_ENABLE
|
||||
static uint32_t s_bt_xtal_lpclk_freq = 100000;
|
||||
static uint32_t s_bt_lpclk_freq = 0;
|
||||
static uint8_t s_btdm_lp_modem_clk_en = 0;
|
||||
|
||||
/*
|
||||
***************************************************************************************************
|
||||
@@ -197,6 +209,21 @@ btdm_lp_timer_clk_deinit(void)
|
||||
modem_clock_deselect_lp_clock_source(PERIPH_BT_MODULE);
|
||||
}
|
||||
|
||||
void IRAM_ATTR e_btdm_lp_modem_clock_set(bool enable)
|
||||
{
|
||||
if (enable) {
|
||||
if (!s_btdm_lp_modem_clk_en) {
|
||||
modem_clock_module_enable(PERIPH_BT_MODULE);
|
||||
s_btdm_lp_modem_clk_en = 1;
|
||||
}
|
||||
} else {
|
||||
if (!s_bt_active && s_btdm_lp_modem_clk_en) {
|
||||
modem_clock_module_disable(PERIPH_BT_MODULE);
|
||||
s_btdm_lp_modem_clk_en = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
btdm_lp_sleep_cb(uint32_t enable_tick, void *arg)
|
||||
{
|
||||
@@ -213,17 +240,33 @@ btdm_lp_sleep_cb(uint32_t enable_tick, void *arg)
|
||||
void
|
||||
btdm_lp_wake_up_cb(void *arg)
|
||||
{
|
||||
btdm_lp_wakeup_params_t *params;
|
||||
|
||||
if (s_bt_active) {
|
||||
return;
|
||||
}
|
||||
#ifdef CONFIG_PM_ENABLE
|
||||
esp_pm_lock_acquire(s_pm_lock);
|
||||
#endif // CONFIG_PM_ENABLE
|
||||
params = (btdm_lp_wakeup_params_t *)arg;
|
||||
if (params) {
|
||||
params->bt_wakeup = 0;
|
||||
}
|
||||
esp_phy_enable(PHY_MODEM_BT);
|
||||
#if UC_BT_CTRL_SLEEP_ENABLE && CONFIG_FREERTOS_USE_TICKLESS_IDLE
|
||||
if (params) {
|
||||
params->bt_wakeup = btdm_lp_check_wakeup_by_bt();
|
||||
}
|
||||
#endif // UC_BT_CTRL_SLEEP_ENABLE && CONFIG_FREERTOS_USE_TICKLESS_IDLE
|
||||
s_bt_active = true;
|
||||
}
|
||||
|
||||
#if UC_BT_CTRL_SLEEP_ENABLE && CONFIG_FREERTOS_USE_TICKLESS_IDLE
|
||||
static bool btdm_lp_check_wakeup_by_bt(void)
|
||||
{
|
||||
return (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_BT));
|
||||
}
|
||||
|
||||
static esp_err_t
|
||||
btdm_lp_modem_retention_create(void)
|
||||
{
|
||||
@@ -307,7 +350,11 @@ btdm_lp_modem_state_deinit(void)
|
||||
void
|
||||
btdm_lp_enable_clock(esp_btdm_controller_config_t *cfg)
|
||||
{
|
||||
modem_clock_module_enable(PERIPH_BT_MODULE);
|
||||
if (!s_btdm_lp_modem_clk_en) {
|
||||
modem_clock_module_enable(PERIPH_BT_MODULE);
|
||||
s_btdm_lp_modem_clk_en = 1;
|
||||
}
|
||||
modem_clock_module_enable(PERIPH_BT_APB_MODULE);
|
||||
modem_clock_module_mac_reset(PERIPH_BT_MODULE);
|
||||
btdm_lp_timer_clk_init(cfg);
|
||||
}
|
||||
@@ -316,7 +363,11 @@ void
|
||||
btdm_lp_disable_clock(void)
|
||||
{
|
||||
btdm_lp_timer_clk_deinit();
|
||||
modem_clock_module_disable(PERIPH_BT_MODULE);
|
||||
modem_clock_module_disable(PERIPH_BT_APB_MODULE);
|
||||
if (s_btdm_lp_modem_clk_en) {
|
||||
modem_clock_module_disable(PERIPH_BT_MODULE);
|
||||
s_btdm_lp_modem_clk_en = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
Reference in New Issue
Block a user