Skip to content

Commit c5e3208

Browse files
committed
Merge branch 'feat/support_wakeup_causes_in_bt_wakeup' into 'release/v5.4'
Feat/support wakeup causes in bt wakeup See merge request espressif/esp-idf!42064
2 parents df2c123 + 32b71fa commit c5e3208

File tree

4 files changed

+95
-8
lines changed

4 files changed

+95
-8
lines changed

components/bt/controller/esp32c2/bt.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ enum {
130130
};
131131
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
132132

133+
typedef union {
134+
struct {
135+
uint32_t rtc_freq:20;
136+
uint32_t rsv:11;
137+
uint32_t bt_wakeup:1;
138+
};
139+
uint32_t val;
140+
} bt_wakeup_params_t;
141+
133142
/* External functions or variables
134143
************************************************************************
135144
*/
@@ -220,6 +229,9 @@ static void esp_bt_ctrl_log_partition_get_and_erase_first_block(void);
220229
#endif // CONFIG_BT_LE_CONTROLLER_LOG_STORAGE_ENABLE
221230
#endif /* !CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2 */
222231
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
232+
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
233+
static bool esp_bt_check_wakeup_by_bt(void);
234+
#endif // CONFIG_FREERTOS_USE_TICKLESS_IDLE
223235
/* Local variable definition
224236
***************************************************************************
225237
*/
@@ -712,6 +724,7 @@ void controller_sleep_cb(uint32_t enable_tick, void *arg)
712724

713725
void controller_wakeup_cb(void *arg)
714726
{
727+
bt_wakeup_params_t *params;
715728
if (s_ble_active) {
716729
return;
717730
}
@@ -721,15 +734,25 @@ void controller_wakeup_cb(void *arg)
721734
esp_pm_get_configuration(&pm_config);
722735
assert(esp_rom_get_cpu_ticks_per_us() == pm_config.max_freq_mhz);
723736
#endif //CONFIG_PM_ENABLE
737+
params = (bt_wakeup_params_t *)arg;
724738
esp_phy_enable(PHY_MODEM_BT);
725739
if (s_bt_lpclk_src == MODEM_CLOCK_LPCLK_SRC_RC_SLOW) {
726-
uint32_t *clk_freq = (uint32_t *)arg;
727-
*clk_freq = esp_clk_tree_lp_slow_get_freq_hz(ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED) / 5;
740+
params->rtc_freq = esp_clk_tree_lp_slow_get_freq_hz(ESP_CLK_TREE_SRC_FREQ_PRECISION_CACHED) / 5;
728741
}
742+
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
743+
params->bt_wakeup = esp_bt_check_wakeup_by_bt();
744+
#endif // CONFIG_FREERTOS_USE_TICKLESS_IDLE
729745
// need to check if need to call pm lock here
730746
s_ble_active = true;
731747
}
732748

749+
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
750+
static bool esp_bt_check_wakeup_by_bt(void)
751+
{
752+
return (esp_sleep_get_wakeup_causes() & ESP_SLEEP_WAKEUP_BT);
753+
}
754+
#endif // CONFIG_FREERTOS_USE_TICKLESS_IDLE
755+
733756
esp_err_t controller_sleep_init(modem_clock_lpclk_src_t slow_clk_src)
734757
{
735758
esp_err_t rc = 0;

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;

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;

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)