Skip to content

Commit bc09833

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

File tree

1 file changed

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

1 file changed

+23
-2
lines changed

components/bt/controller/esp32c6/bt.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ enum {
125125
};
126126
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
127127

128+
typedef union {
129+
struct {
130+
uint32_t rtc_freq:20;
131+
uint32_t rsv:11;
132+
uint32_t bt_wakeup:1;
133+
};
134+
uint32_t val;
135+
} bt_wakeup_params_t;
136+
128137
/* External functions or variables
129138
************************************************************************
130139
*/
@@ -221,6 +230,9 @@ static void esp_bt_ctrl_log_partition_get_and_erase_first_block(void);
221230
#endif // CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE
222231
#endif /* !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */
223232
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
233+
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
234+
static bool esp_bt_check_wakeup_by_bt(void);
235+
#endif // CONFIG_FREERTOS_USE_TICKLESS_IDLE
224236
/* Local variable definition
225237
***************************************************************************
226238
*/
@@ -759,6 +771,7 @@ IRAM_ATTR void controller_sleep_cb(uint32_t enable_tick, void *arg)
759771

760772
IRAM_ATTR void controller_wakeup_cb(void *arg)
761773
{
774+
bt_wakeup_params_t *params;
762775
if (s_ble_active) {
763776
return;
764777
}
@@ -769,15 +782,23 @@ IRAM_ATTR void controller_wakeup_cb(void *arg)
769782
assert(esp_rom_get_cpu_ticks_per_us() == pm_config.max_freq_mhz);
770783
r_ble_rtc_wake_up_state_clr();
771784
#endif //CONFIG_PM_ENABLE
785+
params = (bt_wakeup_params_t *)arg;
772786
esp_phy_enable(PHY_MODEM_BT);
773787
if (s_bt_lpclk_src == MODEM_CLOCK_LPCLK_SRC_RC_SLOW) {
774-
uint32_t *clk_freq = (uint32_t *)arg;
775-
*clk_freq = esp_clk_tree_lp_slow_get_freq_hz(ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED) / 5;
788+
params->rtc_freq = esp_clk_tree_lp_slow_get_freq_hz(ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED) / 5;
776789
}
790+
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
791+
params->bt_wakeup = esp_bt_check_wakeup_by_bt();
792+
#endif // CONFIG_FREERTOS_USE_TICKLESS_IDLE
777793
s_ble_active = true;
778794
}
779795

780796
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
797+
static bool esp_bt_check_wakeup_by_bt(void)
798+
{
799+
return (esp_sleep_get_wakeup_causes() & ESP_SLEEP_WAKEUP_BT);
800+
}
801+
781802
static esp_err_t sleep_modem_ble_mac_retention_init(void *arg)
782803
{
783804
uint8_t size;

0 commit comments

Comments
 (0)