change(ble): updated ble log spi out ts sync module

* use freertos ts instead of esp ts for better performance
* enable ts sync sleep support by default
* use esp ts as fallback of lc time getter
This commit is contained in:
Zhou Xiao
2025-06-17 17:22:14 +08:00
parent adbec6eda2
commit 56e42be859
2 changed files with 13 additions and 10 deletions

View File

@@ -105,7 +105,7 @@ config BT_BLE_LOG_SPI_OUT_SYNC_IO_NUM
config BT_BLE_LOG_SPI_OUT_TS_SYNC_SLEEP_SUPPORT config BT_BLE_LOG_SPI_OUT_TS_SYNC_SLEEP_SUPPORT
bool "Enable ble log & logic analyzer log time sync sleep support" bool "Enable ble log & logic analyzer log time sync sleep support"
depends on BT_BLE_LOG_SPI_OUT_LL_ENABLED depends on BT_BLE_LOG_SPI_OUT_LL_ENABLED
default n default y
help help
Enable ble log & logic analyzer log time sync sleep support Enable ble log & logic analyzer log time sync sleep support

View File

@@ -40,7 +40,8 @@
#define SPI_OUT_MALLOC(size) heap_caps_malloc(size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT) #define SPI_OUT_MALLOC(size) heap_caps_malloc(size, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT)
#if SPI_OUT_TS_SYNC_ENABLED #if SPI_OUT_TS_SYNC_ENABLED
#define SPI_OUT_TS_SYNC_TIMEOUT (1000 * 1000) #define SPI_OUT_TS_SYNC_TIMEOUT_MS (1000)
#define SPI_OUT_TS_SYNC_TIMEOUT_US (SPI_OUT_TS_SYNC_TIMEOUT_MS * 1000)
#endif // SPI_OUT_TS_SYNC_ENABLED #endif // SPI_OUT_TS_SYNC_ENABLED
// Queue size defines // Queue size defines
@@ -90,7 +91,7 @@ typedef struct {
typedef struct { typedef struct {
uint8_t io_level; uint8_t io_level;
uint32_t lc_ts; uint32_t lc_ts;
uint32_t esp_ts; uint32_t os_ts;
} __attribute__((packed)) ts_sync_data_t; } __attribute__((packed)) ts_sync_data_t;
// Private enums // Private enums
@@ -127,6 +128,7 @@ static bool spi_out_inited = false;
static bool spi_out_enabled = false; static bool spi_out_enabled = false;
static spi_device_handle_t spi_handle = NULL; static spi_device_handle_t spi_handle = NULL;
static uint32_t last_tx_done_ts = 0; static uint32_t last_tx_done_ts = 0;
static uint32_t last_tx_done_os_ts = 0;
static bool ul_log_inited = false; static bool ul_log_inited = false;
static SemaphoreHandle_t ul_log_mutex = NULL; static SemaphoreHandle_t ul_log_mutex = NULL;
@@ -217,7 +219,7 @@ extern uint32_t r_ble_lll_timer_current_tick_get(void);
extern uint32_t r_os_cputime_get32(void); extern uint32_t r_os_cputime_get32(void);
#define SPI_OUT_GET_LC_TIME r_os_cputime_get32() #define SPI_OUT_GET_LC_TIME r_os_cputime_get32()
#else #else
#define SPI_OUT_GET_LC_TIME 0 #define SPI_OUT_GET_LC_TIME esp_timer_get_time()
#endif #endif
#if !SPI_OUT_TS_SYNC_SLEEP_SUPPORT #if !SPI_OUT_TS_SYNC_SLEEP_SUPPORT
@@ -272,6 +274,7 @@ static void spi_out_deinit_trans(spi_out_trans_cb_t **trans_cb)
IRAM_ATTR static void spi_out_tx_done_cb(spi_transaction_t *ret_trans) IRAM_ATTR static void spi_out_tx_done_cb(spi_transaction_t *ret_trans)
{ {
last_tx_done_ts = esp_timer_get_time(); last_tx_done_ts = esp_timer_get_time();
last_tx_done_os_ts = pdTICKS_TO_MS(xTaskGetTickCountFromISR());
spi_out_trans_cb_t *trans_cb = (spi_out_trans_cb_t *)ret_trans->user; spi_out_trans_cb_t *trans_cb = (spi_out_trans_cb_t *)ret_trans->user;
trans_cb->length = 0; trans_cb->length = 0;
trans_cb->flag = TRANS_CB_FLAG_AVAILABLE; trans_cb->flag = TRANS_CB_FLAG_AVAILABLE;
@@ -577,8 +580,8 @@ static void spi_out_ul_log_write(uint8_t source, const uint8_t *addr, uint16_t l
bool need_append; bool need_append;
if (spi_out_log_cb_check_trans(ul_log_cb, total_len, &need_append)) { if (spi_out_log_cb_check_trans(ul_log_cb, total_len, &need_append)) {
if (with_ts) { if (with_ts) {
uint32_t esp_ts = esp_timer_get_time(); uint32_t os_ts = pdTICKS_TO_MS(xTaskGetTickCount());
need_append |= spi_out_log_cb_write(ul_log_cb, (const uint8_t *)&esp_ts, need_append |= spi_out_log_cb_write(ul_log_cb, (const uint8_t *)&os_ts,
sizeof(uint32_t), addr, len, source, true); sizeof(uint32_t), addr, len, source, true);
} else { } else {
need_append |= spi_out_log_cb_write(ul_log_cb, addr, len, NULL, 0, source, true); need_append |= spi_out_log_cb_write(ul_log_cb, addr, len, NULL, 0, source, true);
@@ -757,7 +760,7 @@ static void spi_out_ts_sync_enable(bool enable)
// Start timestamp sync timer // Start timestamp sync timer
if (ts_sync_timer) { if (ts_sync_timer) {
if (!esp_timer_is_active(ts_sync_timer)) { if (!esp_timer_is_active(ts_sync_timer)) {
esp_timer_start_periodic(ts_sync_timer, SPI_OUT_TS_SYNC_TIMEOUT); esp_timer_start_periodic(ts_sync_timer, SPI_OUT_TS_SYNC_TIMEOUT_US);
} }
} }
#endif // !SPI_OUT_TS_SYNC_SLEEP_SUPPORT #endif // !SPI_OUT_TS_SYNC_SLEEP_SUPPORT
@@ -793,8 +796,8 @@ static void spi_out_ts_sync_toggle(void)
// Set sync IO level // Set sync IO level
gpio_set_level(SPI_OUT_SYNC_IO_NUM, (uint32_t)ts_sync_data.io_level); gpio_set_level(SPI_OUT_SYNC_IO_NUM, (uint32_t)ts_sync_data.io_level);
// Get ESP timestamp // Get OS timestamp
ts_sync_data.esp_ts = esp_timer_get_time(); ts_sync_data.os_ts = pdTICKS_TO_MS(xTaskGetTickCountFromISR());
portEXIT_CRITICAL(&spinlock); portEXIT_CRITICAL(&spinlock);
// Exit critical // Exit critical
} }
@@ -1058,7 +1061,7 @@ IRAM_ATTR void ble_log_spi_out_ll_write(uint32_t len, const uint8_t *addr, uint3
#if SPI_OUT_TS_SYNC_SLEEP_SUPPORT #if SPI_OUT_TS_SYNC_SLEEP_SUPPORT
if (ts_sync_inited && ts_sync_enabled) { if (ts_sync_inited && ts_sync_enabled) {
if (last_tx_done_ts >= (SPI_OUT_TS_SYNC_TIMEOUT + ts_sync_data.esp_ts)) { if (last_tx_done_os_ts >= (SPI_OUT_TS_SYNC_TIMEOUT_MS + ts_sync_data.os_ts)) {
if (spi_out_log_cb_check_trans(ll_task_log_cb, sizeof(ts_sync_data_t), &need_append)) { if (spi_out_log_cb_check_trans(ll_task_log_cb, sizeof(ts_sync_data_t), &need_append)) {
spi_out_ts_sync_toggle(); spi_out_ts_sync_toggle();
spi_out_log_cb_write(ll_task_log_cb, (const uint8_t *)&ts_sync_data, spi_out_log_cb_write(ll_task_log_cb, (const uint8_t *)&ts_sync_data,