mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 10:47:19 +02:00
Merge branch 'fix/printf_va_list_cross_function_pass' into 'master'
fix(ble): fixed spi ble log bugs Closes BLERP-1920, BLERP-1923, BLERP-1926, and BLERP-1928 See merge request espressif/esp-idf!39384
This commit is contained in:
@ -183,7 +183,7 @@ static void spi_out_log_flush(void);
|
|||||||
static int spi_out_ul_log_init(void);
|
static int spi_out_ul_log_init(void);
|
||||||
static void spi_out_ul_log_deinit(void);
|
static void spi_out_ul_log_deinit(void);
|
||||||
static void spi_out_ul_log_write(uint8_t source, const uint8_t *addr, uint16_t len, bool with_ts);
|
static void spi_out_ul_log_write(uint8_t source, const uint8_t *addr, uint16_t len, bool with_ts);
|
||||||
static bool spi_out_ul_log_printf(uint8_t source, const char *format, va_list args);
|
static bool spi_out_ul_log_printf(uint8_t source, const char *format, va_list args, int offset);
|
||||||
|
|
||||||
#if SPI_OUT_LL_ENABLED
|
#if SPI_OUT_LL_ENABLED
|
||||||
static int spi_out_ll_log_init(void);
|
static int spi_out_ll_log_init(void);
|
||||||
@ -589,12 +589,14 @@ static void spi_out_ul_log_write(uint8_t source, const uint8_t *addr, uint16_t l
|
|||||||
spi_out_log_cb_write_loss(ul_log_cb);
|
spi_out_log_cb_write_loss(ul_log_cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool spi_out_ul_log_printf(uint8_t source, const char *format, va_list args)
|
static bool spi_out_ul_log_printf(uint8_t source, const char *format, va_list args, int offset)
|
||||||
{
|
{
|
||||||
int len = vsnprintf((char *)ul_log_str_buf, SPI_OUT_UL_LOG_STR_BUF_SIZE, format, args);
|
int len = vsnprintf((char *)(ul_log_str_buf + offset),
|
||||||
|
SPI_OUT_UL_LOG_STR_BUF_SIZE - offset, format, args);
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
len += offset;
|
||||||
|
|
||||||
// Truncate string if overflowed
|
// Truncate string if overflowed
|
||||||
if (len >= SPI_OUT_UL_LOG_STR_BUF_SIZE) {
|
if (len >= SPI_OUT_UL_LOG_STR_BUF_SIZE) {
|
||||||
@ -745,10 +747,6 @@ static void spi_out_ts_sync_deinit(void)
|
|||||||
|
|
||||||
static void spi_out_ts_sync_enable(bool enable)
|
static void spi_out_ts_sync_enable(bool enable)
|
||||||
{
|
{
|
||||||
// Reset ts sync io
|
|
||||||
ts_sync_data.io_level = false;
|
|
||||||
gpio_set_level(SPI_OUT_SYNC_IO_NUM, (uint32_t)ts_sync_data.io_level);
|
|
||||||
|
|
||||||
// Update ts sync status
|
// Update ts sync status
|
||||||
ts_sync_enabled = enable;
|
ts_sync_enabled = enable;
|
||||||
if (enable) {
|
if (enable) {
|
||||||
@ -769,7 +767,12 @@ static void spi_out_ts_sync_enable(bool enable)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // !SPI_OUT_TS_SYNC_SLEEP_SUPPORT
|
#endif // !SPI_OUT_TS_SYNC_SLEEP_SUPPORT
|
||||||
|
if (!ts_sync_data.io_level) {
|
||||||
|
gpio_set_level(SPI_OUT_SYNC_IO_NUM, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
ts_sync_data.io_level = 0;
|
||||||
|
gpio_set_level(SPI_OUT_SYNC_IO_NUM, (uint32_t)ts_sync_data.io_level);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void spi_out_ts_sync_toggle(void)
|
static void spi_out_ts_sync_toggle(void)
|
||||||
@ -1051,7 +1054,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 - ts_sync_data.esp_ts) >= SPI_OUT_TS_SYNC_TIMEOUT) {
|
if (last_tx_done_ts >= (SPI_OUT_TS_SYNC_TIMEOUT + ts_sync_data.esp_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,
|
||||||
@ -1103,16 +1106,23 @@ int ble_log_spi_out_printf(uint8_t source, const char *format, ...)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!format) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// Get arguments
|
// Get arguments
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
|
|
||||||
|
va_list args_copy;
|
||||||
|
va_copy(args_copy, args);
|
||||||
|
|
||||||
xSemaphoreTake(ul_log_mutex, portMAX_DELAY);
|
xSemaphoreTake(ul_log_mutex, portMAX_DELAY);
|
||||||
bool ret = spi_out_ul_log_printf(source, format, args);
|
bool ret = spi_out_ul_log_printf(source, format, args_copy, 0);
|
||||||
xSemaphoreGive(ul_log_mutex);
|
xSemaphoreGive(ul_log_mutex);
|
||||||
|
|
||||||
|
va_end(args_copy);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
return ret? 0: -1;
|
return ret? 0: -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1122,18 +1132,29 @@ int ble_log_spi_out_printf_enh(uint8_t source, uint8_t level, const char *tag, c
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!tag || !format) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
|
|
||||||
|
va_list args_copy;
|
||||||
|
va_copy(args_copy, args);
|
||||||
|
|
||||||
// Create log prefix in the format: "[level][tag] "
|
// Create log prefix in the format: "[level][tag] "
|
||||||
|
bool ret = false;
|
||||||
xSemaphoreTake(ul_log_mutex, portMAX_DELAY);
|
xSemaphoreTake(ul_log_mutex, portMAX_DELAY);
|
||||||
snprintf((char *)ul_log_str_buf, SPI_OUT_UL_LOG_STR_BUF_SIZE,
|
int prefix_len = snprintf((char *)ul_log_str_buf, SPI_OUT_UL_LOG_STR_BUF_SIZE,
|
||||||
"[%d][%s] %s", level, tag? tag: "NULL", format);
|
"[%d][%s]", level, tag? tag: "NULL");
|
||||||
bool ret = spi_out_ul_log_printf(source, (const char *)ul_log_str_buf, args);
|
if ((prefix_len < 0) || (prefix_len >= SPI_OUT_UL_LOG_STR_BUF_SIZE)) {
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
ret = spi_out_ul_log_printf(source, format, args_copy, prefix_len);
|
||||||
|
exit:
|
||||||
xSemaphoreGive(ul_log_mutex);
|
xSemaphoreGive(ul_log_mutex);
|
||||||
|
va_end(args_copy);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
return ret? 0: -1;
|
return ret? 0: -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1701,6 +1701,7 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
|
|||||||
#if CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED
|
#if CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED
|
||||||
if (ble_log_spi_out_init() != 0) {
|
if (ble_log_spi_out_init() != 0) {
|
||||||
ESP_LOGE(BTDM_LOG_TAG, "BLE Log SPI output init failed");
|
ESP_LOGE(BTDM_LOG_TAG, "BLE Log SPI output init failed");
|
||||||
|
err = ESP_ERR_NO_MEM;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
#endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED
|
#endif // CONFIG_BT_BLE_LOG_SPI_OUT_ENABLED
|
||||||
|
Reference in New Issue
Block a user