Skip to content

Commit b144337

Browse files
author
Zhou Xiao
committed
fix(ble): fix flushout and sync issues
1 parent efdce75 commit b144337

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

components/bt/common/ble_log/ble_log_spi_out.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,10 @@ IRAM_ATTR static void esp_timer_cb_flushout(void)
176176
if (trans_head->trans.length) {
177177
spi_out_append_trans();
178178
}
179-
} else {
180-
// Restart flushout timer
179+
}
180+
181+
// Restart flushout timer if not active
182+
if (!esp_timer_is_active(flushout_timer_handle)) {
181183
esp_timer_start_once(flushout_timer_handle, SPI_OUT_FLUSHOUT_TIMEOUT);
182184
}
183185

@@ -193,6 +195,9 @@ IRAM_ATTR static void esp_timer_cb_ts_sync(void)
193195
uint32_t lc_ts = 0;
194196
uint32_t esp_ts = 0;
195197

198+
// Toggle sync IO
199+
sync_io_level = !sync_io_level;
200+
196201
// Enter critical
197202
portMUX_TYPE spinlock = portMUX_INITIALIZER_UNLOCKED;
198203
portENTER_CRITICAL_SAFE(&spinlock);
@@ -205,7 +210,7 @@ IRAM_ATTR static void esp_timer_cb_ts_sync(void)
205210
lc_ts = r_os_cputime_get32();
206211
#endif // CONFIG_IDF_TARGET_ESP32C2
207212

208-
// Toggle Sync IO
213+
// Set sync IO level
209214
gpio_set_level(CONFIG_BT_BLE_LOG_SPI_OUT_SYNC_IO_NUM, (uint32_t)sync_io_level);
210215

211216
// Get ESP timestamp
@@ -219,9 +224,6 @@ IRAM_ATTR static void esp_timer_cb_ts_sync(void)
219224
memcpy(sync_frame + 1, &lc_ts, sizeof(lc_ts));
220225
memcpy(sync_frame + 5, &esp_ts, sizeof(esp_ts));
221226
ble_log_spi_out_write(BLE_LOG_SPI_OUT_SOURCE_SYNC, sync_frame, 9);
222-
223-
// Update IO level
224-
sync_io_level = !sync_io_level;
225227
}
226228
#endif // CONFIG_BT_BLE_LOG_SPI_OUT_TS_SYNC_ENABLED
227229

@@ -351,6 +353,10 @@ void ble_log_spi_out_ts_sync_stop(void)
351353
if (esp_timer_is_active(ts_sync_timer_handle)) {
352354
esp_timer_stop(ts_sync_timer_handle);
353355
}
356+
357+
// Set sync IO to low level
358+
sync_io_level = 0;
359+
gpio_set_level(CONFIG_BT_BLE_LOG_SPI_OUT_SYNC_IO_NUM, (uint32_t)sync_io_level);
354360
}
355361
}
356362
#endif // CONFIG_BT_BLE_LOG_SPI_OUT_TS_SYNC_ENABLED

components/bt/common/ble_log/include/ble_log/ble_log_spi_out.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#ifndef __BT_SPI_OUT_H__
77
#define __BT_SPI_OUT_H__
88

9+
#include <stdarg.h>
910
#include <string.h>
1011
#include "driver/spi_master.h"
1112
#include "driver/gpio.h"
@@ -19,6 +20,7 @@
1920
#define BLE_LOG_SPI_OUT_SOURCE_NIMBLE 3
2021
#define BLE_LOG_SPI_OUT_SOURCE_HCI_UPSTREAM 4
2122
#define BLE_LOG_SPI_OUT_SOURCE_HCI_DOWNSTREAM 5
23+
#define BLE_LOG_SPI_OUT_SOURCE_USER 0x10
2224
#define BLE_LOG_SPI_OUT_SOURCE_SYNC 0xFE
2325
#define BLE_LOG_SPI_OUT_SOURCE_LOSS 0xFF
2426

0 commit comments

Comments
 (0)