Skip to content

Commit 32b71fa

Browse files
feat(ble): get wakeup cause when wake up on ESP32-H2
1 parent f8dc824 commit 32b71fa

File tree

1 file changed

+23
-2
lines changed
  • components/bt/controller/esp32h2

1 file changed

+23
-2
lines changed

components/bt/controller/esp32h2/bt.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ enum {
117117
BLE_LOG_INTERFACE_FLAG_END,
118118
};
119119
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
120+
121+
typedef union {
122+
struct {
123+
uint32_t rtc_freq:20;
124+
uint32_t rsv:11;
125+
uint32_t bt_wakeup:1;
126+
};
127+
uint32_t val;
128+
} bt_wakeup_params_t;
120129
/* External functions or variables
121130
************************************************************************
122131
*/
@@ -214,6 +223,9 @@ static void esp_bt_ctrl_log_partition_get_and_erase_first_block(void);
214223
#endif // CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE
215224
#endif /* !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */
216225
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
226+
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
227+
static bool esp_bt_check_wakeup_by_bt(void);
228+
#endif // CONFIG_FREERTOS_USE_TICKLESS_IDLE
217229
/* Local variable definition
218230
***************************************************************************
219231
*/
@@ -727,6 +739,7 @@ IRAM_ATTR void controller_sleep_cb(uint32_t enable_tick, void *arg)
727739

728740
IRAM_ATTR void controller_wakeup_cb(void *arg)
729741
{
742+
bt_wakeup_params_t *params;
730743
if (s_ble_active) {
731744
return;
732745
}
@@ -737,15 +750,23 @@ IRAM_ATTR void controller_wakeup_cb(void *arg)
737750
assert(esp_rom_get_cpu_ticks_per_us() == pm_config.max_freq_mhz);
738751
r_ble_rtc_wake_up_state_clr();
739752
#endif //CONFIG_PM_ENABLE
753+
params = (bt_wakeup_params_t *)arg;
740754
esp_phy_enable(PHY_MODEM_BT);
741755
if (s_bt_lpclk_src == MODEM_CLOCK_LPCLK_SRC_RC_SLOW) {
742-
uint32_t *clk_freq = (uint32_t *)arg;
743-
*clk_freq = esp_clk_tree_lp_slow_get_freq_hz(ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED) / 5;
756+
params->rtc_freq = esp_clk_tree_lp_slow_get_freq_hz(ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED) / 5;
744757
}
758+
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
759+
params->bt_wakeup = esp_bt_check_wakeup_by_bt();
760+
#endif // CONFIG_FREERTOS_USE_TICKLESS_IDLE
745761
s_ble_active = true;
746762
}
747763

748764
#ifdef CONFIG_FREERTOS_USE_TICKLESS_IDLE
765+
static bool esp_bt_check_wakeup_by_bt(void)
766+
{
767+
return (esp_sleep_get_wakeup_causes() & ESP_SLEEP_WAKEUP_BT);
768+
}
769+
749770
static esp_err_t sleep_modem_ble_mac_retention_init(void *arg)
750771
{
751772
uint8_t size;

0 commit comments

Comments
 (0)