Skip to content

Commit f8dc824

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

File tree

1 file changed

+24
-2
lines changed
  • components/bt/controller/esp32c5

1 file changed

+24
-2
lines changed

components/bt/controller/esp32c5/bt.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ enum {
109109
BLE_LOG_INTERFACE_FLAG_END,
110110
};
111111
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
112+
113+
typedef union {
114+
struct {
115+
uint32_t rtc_freq:20;
116+
uint32_t rsv:11;
117+
uint32_t bt_wakeup:1;
118+
};
119+
uint32_t val;
120+
} bt_wakeup_params_t;
121+
112122
/* External functions or variables
113123
************************************************************************
114124
*/
@@ -196,6 +206,9 @@ static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, u
196206
static void esp_bt_ctrl_log_partition_get_and_erase_first_block(void);
197207
#endif // CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE
198208
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
209+
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
210+
static bool esp_bt_check_wakeup_by_bt(void);
211+
#endif // CONFIG_FREERTOS_USE_TICKLESS_IDLE
199212
/* Local variable definition
200213
***************************************************************************
201214
*/
@@ -628,6 +641,7 @@ IRAM_ATTR void controller_sleep_cb(uint32_t enable_tick, void *arg)
628641

629642
IRAM_ATTR void controller_wakeup_cb(void *arg)
630643
{
644+
bt_wakeup_params_t *params;
631645
if (s_ble_active) {
632646
return;
633647
}
@@ -638,15 +652,23 @@ IRAM_ATTR void controller_wakeup_cb(void *arg)
638652
assert(esp_rom_get_cpu_ticks_per_us() == pm_config.max_freq_mhz);
639653
r_ble_rtc_wake_up_state_clr();
640654
#endif //CONFIG_PM_ENABLE
655+
params = (bt_wakeup_params_t *)arg;
641656
esp_phy_enable(PHY_MODEM_BT);
642657
if (s_bt_lpclk_src == MODEM_CLOCK_LPCLK_SRC_RC_SLOW) {
643-
uint32_t *clk_freq = (uint32_t *)arg;
644-
*clk_freq = esp_clk_tree_lp_slow_get_freq_hz(ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED) / 5;
658+
params->rtc_freq = esp_clk_tree_lp_slow_get_freq_hz(ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED) / 5;
645659
}
660+
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
661+
params->bt_wakeup = esp_bt_check_wakeup_by_bt();
662+
#endif // CONFIG_FREERTOS_USE_TICKLESS_IDLE
646663
s_ble_active = true;
647664
}
648665

649666
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
667+
static bool esp_bt_check_wakeup_by_bt(void)
668+
{
669+
return (esp_sleep_get_wakeup_causes() & ESP_SLEEP_WAKEUP_BT);
670+
}
671+
650672
static esp_err_t sleep_modem_ble_mac_retention_init(void *arg)
651673
{
652674
uint8_t size;

0 commit comments

Comments
 (0)