1 /*
2  * SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #include <stdio.h>
7 #include <stdarg.h>
8 #include <sdkconfig.h>
9 #include "SEGGER_SYSVIEW_Int.h"
10 #include "freertos/FreeRTOS.h"
11 
12 static portMUX_TYPE s_log_mutex = portMUX_INITIALIZER_UNLOCKED;
13 
esp_sysview_vprintf(const char * format,va_list args)14 int esp_sysview_vprintf(const char * format, va_list args)
15 {
16     static char log_buffer[SEGGER_SYSVIEW_MAX_STRING_LEN];
17 
18     portENTER_CRITICAL(&s_log_mutex);
19     size_t len = vsnprintf(log_buffer, sizeof(log_buffer), format, args);
20     if (len > sizeof(log_buffer) - 1) {
21         log_buffer[sizeof(log_buffer - 1)] = 0;
22     }
23     SEGGER_SYSVIEW_Print(log_buffer);
24     portEXIT_CRITICAL(&s_log_mutex);
25     return len;
26 }
27