mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
refactor(ble_log): simplify timestamp sync scheduling
This commit is contained in:
@@ -143,7 +143,9 @@ if BLE_LOG_ENABLED
|
||||
bool "Enable BLE Log Timestamp Synchronization (TS)"
|
||||
default n
|
||||
help
|
||||
Enable BLE Log TS with external logging module
|
||||
Enable BLE Log TS with external logging module. Synchronization is
|
||||
triggered periodically by an ESP Timer using task dispatch. The
|
||||
timer does not wake the system from light sleep.
|
||||
|
||||
if BLE_LOG_TS_ENABLED
|
||||
config BLE_LOG_SYNC_IO_NUM
|
||||
@@ -152,38 +154,6 @@ if BLE_LOG_ENABLED
|
||||
default 0
|
||||
help
|
||||
GPIO number for TS toggle output
|
||||
|
||||
config BLE_LOG_TS_TRIGGER_TIMEOUT_MS
|
||||
int "Timeout (ms) for Timestamp Synchronization toggle"
|
||||
default 1000
|
||||
help
|
||||
Timeout (ms) for Timestamp Synchronization toggle
|
||||
|
||||
choice BLE_LOG_TS_TRIGGER_CHOICE
|
||||
prompt "BLE Log Timestamp Synchronization trigger choice"
|
||||
default BLE_LOG_TS_TRIGGER_TASK_EVENT
|
||||
help
|
||||
Choose BLE Log Timestamp Synchronization trigger
|
||||
|
||||
config BLE_LOG_TS_TRIGGER_ESP_TIMER
|
||||
bool "BLE Log Timestamp Synchronization trigger - ESP Timer"
|
||||
help
|
||||
ESP Timer based periodic TS trigger
|
||||
|
||||
config BLE_LOG_TS_TRIGGER_TASK_EVENT
|
||||
bool "BLE Log Timestamp Synchronization trigger - Task Event"
|
||||
help
|
||||
Task Event based TS trigger (Light Sleep Test Compatibility)
|
||||
endchoice
|
||||
|
||||
config BLE_LOG_TS_TRIGGER_ESP_TIMER_ISR_DISPATCH_METHOD
|
||||
bool "Utilize ISR dispatch method for ESP Timer as Timestamp Synchronization trigger"
|
||||
default n
|
||||
select ESP_TIMER_SUPPORTS_ISR_DISPATCH_METHOD
|
||||
select GPIO_CTRL_FUNC_IN_IRAM
|
||||
depends on BLE_LOG_TS_TRIGGER_ESP_TIMER
|
||||
help
|
||||
Utilize ISR dispatch method for ESP Timer as Timestamp Synchronization trigger
|
||||
endif
|
||||
|
||||
choice BLE_LOG_PRPH_CHOICE
|
||||
@@ -288,6 +258,31 @@ if BLE_LOG_ENABLED
|
||||
config BLE_LOG_LBM_LL_TRANS_SIZE
|
||||
int
|
||||
default 512
|
||||
|
||||
config BLE_LOG_TS_TRIGGER_TIMEOUT_MS
|
||||
int
|
||||
depends on BLE_LOG_TS_ENABLED
|
||||
default 1000
|
||||
|
||||
config BLE_LOG_TS_TRIGGER_CHOICE
|
||||
bool
|
||||
depends on BLE_LOG_TS_ENABLED
|
||||
default y
|
||||
|
||||
config BLE_LOG_TS_TRIGGER_ESP_TIMER
|
||||
bool
|
||||
depends on BLE_LOG_TS_ENABLED
|
||||
default y
|
||||
|
||||
config BLE_LOG_TS_TRIGGER_TASK_EVENT
|
||||
bool
|
||||
depends on BLE_LOG_TS_ENABLED
|
||||
default n
|
||||
|
||||
config BLE_LOG_TS_TRIGGER_ESP_TIMER_ISR_DISPATCH_METHOD
|
||||
bool
|
||||
depends on BLE_LOG_TS_ENABLED
|
||||
default n
|
||||
endif
|
||||
|
||||
menu "Legacy SPI Log Output (Deprecated - use BT Log Async Output instead)"
|
||||
|
||||
@@ -25,9 +25,7 @@ BLE_LOG_STATIC TaskHandle_t rt_task_handle = NULL;
|
||||
BLE_LOG_STATIC BLE_LOG_DRAM_ATTR QueueHandle_t rt_queue_handle = NULL;
|
||||
#if CONFIG_BLE_LOG_TS_ENABLED
|
||||
BLE_LOG_STATIC BLE_LOG_DRAM_ATTR uint32_t rt_ts_enabled = 0;
|
||||
#if CONFIG_BLE_LOG_TS_TRIGGER_ESP_TIMER
|
||||
BLE_LOG_STATIC esp_timer_handle_t rt_ts_timer = NULL;
|
||||
#endif /* CONFIG_BLE_LOG_TS_TRIGGER_ESP_TIMER */
|
||||
#endif /* CONFIG_BLE_LOG_TS_ENABLED */
|
||||
|
||||
/* PRIVATE FUNCTION DECLARATION */
|
||||
@@ -53,7 +51,7 @@ BLE_LOG_STATIC void ble_log_rt_task(void *pvParameters)
|
||||
|
||||
/* Task hook */
|
||||
curr_os_ts = pdTICKS_TO_MS(xTaskGetTickCount());
|
||||
if ((curr_os_ts - last_hook_os_ts) < BLE_LOG_TASK_HOOK_TIMEOUT_MS) {
|
||||
if ((curr_os_ts - last_hook_os_ts) < BLE_LOG_TS_TRIGGER_TIMEOUT_MS) {
|
||||
continue;
|
||||
}
|
||||
last_hook_os_ts = curr_os_ts;
|
||||
@@ -65,19 +63,12 @@ BLE_LOG_STATIC void ble_log_rt_task(void *pvParameters)
|
||||
};
|
||||
ble_log_write_hex(BLE_LOG_SRC_INTERNAL, (const uint8_t *)&ble_log_info, sizeof(ble_log_info_t));
|
||||
|
||||
#if CONFIG_BLE_LOG_TS_TRIGGER_TASK_EVENT
|
||||
ble_log_rt_ts_trigger(NULL);
|
||||
#endif /* CONFIG_BLE_LOG_TS_TRIGGER_TASK_EVENT */
|
||||
|
||||
ble_log_write_enh_stat();
|
||||
ble_log_write_buf_util();
|
||||
}
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_LOG_TS_ENABLED
|
||||
#if CONFIG_BLE_LOG_TS_TRIGGER_ESP_TIMER_ISR_DISPATCH_METHOD
|
||||
BLE_LOG_IRAM_ATTR
|
||||
#endif /* CONFIG_BLE_LOG_TS_TRIGGER_ESP_TIMER_ISR_DISPATCH_METHOD */
|
||||
BLE_LOG_STATIC void ble_log_rt_ts_trigger(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
@@ -115,23 +106,19 @@ bool ble_log_rt_init(void)
|
||||
|
||||
#if CONFIG_BLE_LOG_TS_ENABLED
|
||||
BLE_LOG_ATOMIC_STORE_RELAXED(rt_ts_enabled, false);
|
||||
#if CONFIG_BLE_LOG_TS_TRIGGER_ESP_TIMER
|
||||
/* Initialize ESP Timer Trigger */
|
||||
esp_timer_create_args_t ts_timer_args = {
|
||||
.callback = ble_log_rt_ts_trigger,
|
||||
.arg = NULL,
|
||||
#if CONFIG_BLE_LOG_TS_TRIGGER_ESP_TIMER_ISR_DISPATCH_METHOD
|
||||
.dispatch_method = ESP_TIMER_ISR,
|
||||
#endif /* CONFIG_BLE_LOG_TS_TRIGGER_ESP_TIMER_ISR_DISPATCH_METHOD */
|
||||
.name = "ble_log_ts_timer",
|
||||
.skip_unhandled_events = true,
|
||||
};
|
||||
if (esp_timer_create(&ts_timer_args, &rt_ts_timer) != ESP_OK) {
|
||||
goto exit;
|
||||
}
|
||||
if (esp_timer_start_periodic(rt_ts_timer, BLE_LOG_TS_TRIGGER_TIMEOUT_US) != ESP_OK) {
|
||||
if (esp_timer_start_periodic(rt_ts_timer, BLE_LOG_TS_TRIGGER_TIMEOUT_MS * 1000) != ESP_OK) {
|
||||
goto exit;
|
||||
}
|
||||
#endif /* CONFIG_BLE_LOG_TS_TRIGGER_ESP_TIMER */
|
||||
#endif /* CONFIG_BLE_LOG_TS_ENABLED */
|
||||
|
||||
BLE_LOG_ATOMIC_STORE_RELEASE(rt_inited, true);
|
||||
@@ -154,13 +141,11 @@ void ble_log_rt_deinit(void)
|
||||
}
|
||||
#if CONFIG_BLE_LOG_TS_ENABLED
|
||||
BLE_LOG_ATOMIC_STORE_RELEASE(rt_ts_enabled, false);
|
||||
#if CONFIG_BLE_LOG_TS_TRIGGER_ESP_TIMER
|
||||
if (rt_ts_timer) {
|
||||
esp_timer_stop_blocking(rt_ts_timer, portMAX_DELAY);
|
||||
esp_timer_delete(rt_ts_timer);
|
||||
rt_ts_timer = NULL;
|
||||
}
|
||||
#endif /* CONFIG_BLE_LOG_TS_TRIGGER_ESP_TIMER */
|
||||
#endif /* CONFIG_BLE_LOG_TS_ENABLED */
|
||||
|
||||
/* CRITICAL:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -61,9 +61,6 @@ void ble_log_ts_deinit(void)
|
||||
gpio_reset_pin(CONFIG_BLE_LOG_SYNC_IO_NUM);
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_LOG_TS_TRIGGER_ESP_TIMER_ISR_DISPATCH_METHOD
|
||||
BLE_LOG_IRAM_ATTR
|
||||
#endif /* CONFIG_BLE_LOG_TS_TRIGGER_ESP_TIMER_ISR_DISPATCH_METHOD */
|
||||
void ble_log_ts_info_update(ble_log_ts_info_t **info)
|
||||
{
|
||||
if (!ts_inited) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -22,12 +22,7 @@
|
||||
/* MACRO */
|
||||
#define BLE_LOG_TASK_PRIO (ESP_TASK_PRIO_MAX - 1)
|
||||
#define BLE_LOG_TASK_STACK_SIZE CONFIG_BLE_LOG_TASK_STACK_SIZE
|
||||
#if CONFIG_BLE_LOG_TS_ENABLED
|
||||
#define BLE_LOG_TS_TRIGGER_TIMEOUT_US (CONFIG_BLE_LOG_TS_TRIGGER_TIMEOUT_MS * 1000)
|
||||
#define BLE_LOG_TASK_HOOK_TIMEOUT_MS CONFIG_BLE_LOG_TS_TRIGGER_TIMEOUT_MS
|
||||
#else /* !CONFIG_BLE_LOG_TS_ENABLED */
|
||||
#define BLE_LOG_TASK_HOOK_TIMEOUT_MS (1000)
|
||||
#endif /* CONFIG_BLE_LOG_TS_ENABLED */
|
||||
#define BLE_LOG_TS_TRIGGER_TIMEOUT_MS (1000)
|
||||
|
||||
/* INTERFACE */
|
||||
bool ble_log_rt_init(void);
|
||||
|
||||
Reference in New Issue
Block a user