2020-12-21 12:17:42 -05:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2017-01-25 11:35:28 -05:00
|
|
|
|
|
|
|
#include <string.h>
|
2020-12-21 12:17:42 -05:00
|
|
|
#include "esp_log.h"
|
2017-01-25 11:35:28 -05:00
|
|
|
#include "esp_app_trace.h"
|
2020-12-21 12:17:42 -05:00
|
|
|
#include "esp_app_trace_port.h"
|
2017-01-25 11:35:28 -05:00
|
|
|
|
|
|
|
#define ESP_APPTRACE_MAX_VPRINTF_ARGS 256
|
2017-03-21 23:07:37 -04:00
|
|
|
#define ESP_APPTRACE_HOST_BUF_SIZE 256
|
2017-01-25 11:35:28 -05:00
|
|
|
|
2017-03-21 23:07:37 -04:00
|
|
|
#define ESP_APPTRACE_PRINT_LOCK 0
|
2017-01-25 11:35:28 -05:00
|
|
|
|
|
|
|
const static char *TAG = "esp_apptrace";
|
|
|
|
|
|
|
|
/** tracing module internal data */
|
|
|
|
typedef struct {
|
2020-12-21 12:17:42 -05:00
|
|
|
esp_apptrace_hw_t * hw;
|
|
|
|
void * hw_data;
|
|
|
|
} esp_apptrace_channel_t;
|
2017-08-16 19:36:00 -04:00
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
static esp_apptrace_channel_t s_trace_channels[ESP_APPTRACE_DEST_NUM];
|
|
|
|
static bool s_inited;
|
2017-01-25 11:35:28 -05:00
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
esp_err_t esp_apptrace_init(void)
|
2017-01-25 11:35:28 -05:00
|
|
|
{
|
|
|
|
int res;
|
2020-12-21 12:17:42 -05:00
|
|
|
esp_apptrace_hw_t *hw = NULL;
|
|
|
|
void *hw_data = NULL;
|
|
|
|
|
|
|
|
// 'esp_apptrace_init()' is called on every core, so ensure to do main initialization only once
|
|
|
|
if (cpu_hal_get_core_id() == 0) {
|
|
|
|
memset(&s_trace_channels, 0, sizeof(s_trace_channels));
|
|
|
|
hw = esp_apptrace_jtag_hw_get(&hw_data);
|
|
|
|
ESP_APPTRACE_LOGD("HW interface %p", hw);
|
|
|
|
if (hw != NULL) {
|
|
|
|
s_trace_channels[ESP_APPTRACE_DEST_JTAG].hw = hw;
|
|
|
|
s_trace_channels[ESP_APPTRACE_DEST_JTAG].hw_data = hw_data;
|
|
|
|
}
|
|
|
|
hw = esp_apptrace_uart_hw_get(0, &hw_data);
|
|
|
|
if (hw != NULL) {
|
|
|
|
s_trace_channels[ESP_APPTRACE_DEST_UART0].hw = hw;
|
|
|
|
s_trace_channels[ESP_APPTRACE_DEST_UART0].hw_data = hw_data;
|
2017-01-25 11:35:28 -05:00
|
|
|
}
|
2020-12-21 12:17:42 -05:00
|
|
|
s_inited = true;
|
2017-01-25 11:35:28 -05:00
|
|
|
}
|
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
// esp_apptrace_init() is called on every core, so initialize trace channel on every core
|
|
|
|
for (int i = 0; i < sizeof(s_trace_channels)/sizeof(s_trace_channels[0]); i++) {
|
|
|
|
esp_apptrace_channel_t *ch = &s_trace_channels[i];
|
|
|
|
if (ch->hw) {
|
|
|
|
res = ch->hw->init(ch->hw_data);
|
2017-07-24 12:57:44 -04:00
|
|
|
if (res != ESP_OK) {
|
2020-12-21 12:17:42 -05:00
|
|
|
ESP_APPTRACE_LOGE("Failed to init trace channel HW interface (%d)!", res);
|
|
|
|
return res;
|
2017-07-24 12:57:44 -04:00
|
|
|
}
|
2017-01-25 11:35:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-21 23:07:37 -04:00
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
void esp_apptrace_down_buffer_config(uint8_t *buf, uint32_t size)
|
2017-03-21 23:07:37 -04:00
|
|
|
{
|
2020-12-21 12:17:42 -05:00
|
|
|
esp_apptrace_channel_t *ch;
|
2017-07-24 12:57:44 -04:00
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
if (!s_inited) {
|
|
|
|
return;
|
2017-03-21 23:07:37 -04:00
|
|
|
}
|
2020-12-21 12:17:42 -05:00
|
|
|
// currently down buffer is supported for JTAG interface only
|
|
|
|
// TODO: one more argument should be added to this function to specify HW inteface: JTAG, UART0 etc
|
|
|
|
ch = &s_trace_channels[ESP_APPTRACE_DEST_JTAG];
|
|
|
|
if (ch->hw == NULL) {
|
|
|
|
ESP_APPTRACE_LOGE("Trace destination not supported!");
|
|
|
|
return;
|
2017-03-21 23:07:37 -04:00
|
|
|
}
|
2020-12-21 12:17:42 -05:00
|
|
|
if (ch->hw->down_buffer_config == NULL) {
|
|
|
|
return;
|
2017-01-25 11:35:28 -05:00
|
|
|
}
|
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
ch->hw->down_buffer_config(ch->hw_data, buf, size);
|
2017-03-21 23:07:37 -04:00
|
|
|
}
|
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
uint8_t *esp_apptrace_down_buffer_get(esp_apptrace_dest_t dest, uint32_t *size, uint32_t user_tmo)
|
2017-03-21 23:07:37 -04:00
|
|
|
{
|
2020-12-21 12:17:42 -05:00
|
|
|
esp_apptrace_tmo_t tmo;
|
|
|
|
esp_apptrace_channel_t *ch;
|
2017-01-25 11:35:28 -05:00
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
ESP_APPTRACE_LOGV("%s(): enter", __func__);
|
|
|
|
if (dest >= ESP_APPTRACE_DEST_MAX) {
|
2017-03-21 23:07:37 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
2020-12-21 12:17:42 -05:00
|
|
|
if (size == NULL || *size == 0) {
|
2017-03-21 23:07:37 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
2020-12-21 12:17:42 -05:00
|
|
|
if (!s_inited) {
|
|
|
|
return NULL;
|
2017-03-21 23:07:37 -04:00
|
|
|
}
|
2020-12-21 12:17:42 -05:00
|
|
|
ch = &s_trace_channels[dest];
|
|
|
|
if (ch->hw == NULL) {
|
|
|
|
ESP_APPTRACE_LOGE("Trace destination %d not supported!", dest);
|
|
|
|
return NULL;
|
2017-03-21 23:07:37 -04:00
|
|
|
}
|
2020-12-21 12:17:42 -05:00
|
|
|
if (ch->hw->get_down_buffer == NULL) {
|
|
|
|
return NULL;
|
2017-01-25 11:35:28 -05:00
|
|
|
}
|
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
esp_apptrace_tmo_init(&tmo, user_tmo);
|
|
|
|
return ch->hw->get_down_buffer(ch->hw_data, size, &tmo);
|
2017-01-25 11:35:28 -05:00
|
|
|
}
|
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
esp_err_t esp_apptrace_down_buffer_put(esp_apptrace_dest_t dest, uint8_t *ptr, uint32_t user_tmo)
|
2017-01-25 11:35:28 -05:00
|
|
|
{
|
2020-12-21 12:17:42 -05:00
|
|
|
esp_apptrace_tmo_t tmo;
|
|
|
|
esp_apptrace_channel_t *ch;
|
2017-01-25 11:35:28 -05:00
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
ESP_APPTRACE_LOGV("%s(): enter", __func__);
|
|
|
|
if (dest >= ESP_APPTRACE_DEST_MAX) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
2017-03-21 23:07:37 -04:00
|
|
|
}
|
2020-12-21 12:17:42 -05:00
|
|
|
if (ptr == NULL) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
2017-01-25 11:35:28 -05:00
|
|
|
}
|
2020-12-21 12:17:42 -05:00
|
|
|
if (!s_inited) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
2017-01-25 11:35:28 -05:00
|
|
|
}
|
2020-12-21 12:17:42 -05:00
|
|
|
ch = &s_trace_channels[dest];
|
|
|
|
if (ch->hw == NULL) {
|
|
|
|
ESP_APPTRACE_LOGE("Trace destination %d not supported!", dest);
|
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
if (ch->hw->get_down_buffer == NULL) {
|
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2017-01-25 11:35:28 -05:00
|
|
|
}
|
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
esp_apptrace_tmo_init(&tmo, user_tmo);
|
|
|
|
return ch->hw->put_down_buffer(ch->hw_data, ptr, &tmo);
|
2017-07-24 12:57:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_apptrace_read(esp_apptrace_dest_t dest, void *buf, uint32_t *size, uint32_t user_tmo)
|
2017-03-21 23:07:37 -04:00
|
|
|
{
|
|
|
|
int res = ESP_OK;
|
2017-07-24 12:57:44 -04:00
|
|
|
esp_apptrace_tmo_t tmo;
|
2020-12-21 12:17:42 -05:00
|
|
|
esp_apptrace_channel_t *ch;
|
2017-03-21 23:07:37 -04:00
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
ESP_APPTRACE_LOGV("%s(): enter", __func__);
|
|
|
|
if (dest >= ESP_APPTRACE_DEST_MAX) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
2017-03-21 23:07:37 -04:00
|
|
|
}
|
2018-12-26 07:42:07 -05:00
|
|
|
if (buf == NULL || size == NULL || *size == 0) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
2020-12-21 12:17:42 -05:00
|
|
|
if (!s_inited) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
}
|
|
|
|
ch = &s_trace_channels[dest];
|
|
|
|
if (ch->hw == NULL) {
|
|
|
|
ESP_APPTRACE_LOGE("Trace destination %d not supported!", dest);
|
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
if (ch->hw->get_down_buffer == NULL || ch->hw->put_down_buffer == NULL) {
|
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
|
|
|
}
|
2017-03-21 23:07:37 -04:00
|
|
|
|
|
|
|
//TODO: callback system
|
2017-07-24 12:57:44 -04:00
|
|
|
esp_apptrace_tmo_init(&tmo, user_tmo);
|
2017-03-21 23:07:37 -04:00
|
|
|
uint32_t act_sz = *size;
|
2017-07-24 12:57:44 -04:00
|
|
|
*size = 0;
|
2020-12-21 12:17:42 -05:00
|
|
|
uint8_t * ptr = ch->hw->get_down_buffer(ch->hw_data, &act_sz, &tmo);
|
2017-03-21 23:07:37 -04:00
|
|
|
if (ptr && act_sz > 0) {
|
|
|
|
ESP_APPTRACE_LOGD("Read %d bytes from host", act_sz);
|
|
|
|
memcpy(buf, ptr, act_sz);
|
2020-12-21 12:17:42 -05:00
|
|
|
res = ch->hw->put_down_buffer(ch->hw_data, ptr, &tmo);
|
2017-03-21 23:07:37 -04:00
|
|
|
*size = act_sz;
|
2017-08-16 19:36:00 -04:00
|
|
|
} else {
|
|
|
|
res = ESP_ERR_TIMEOUT;
|
2017-03-21 23:07:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
uint8_t *esp_apptrace_buffer_get(esp_apptrace_dest_t dest, uint32_t size, uint32_t user_tmo)
|
2017-07-24 12:57:44 -04:00
|
|
|
{
|
|
|
|
esp_apptrace_tmo_t tmo;
|
2020-12-21 12:17:42 -05:00
|
|
|
esp_apptrace_channel_t *ch;
|
2017-07-24 12:57:44 -04:00
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
ESP_APPTRACE_LOGV("%s(): enter", __func__);
|
|
|
|
if (dest >= ESP_APPTRACE_DEST_MAX) {
|
2017-07-24 12:57:44 -04:00
|
|
|
return NULL;
|
2020-12-21 12:17:42 -05:00
|
|
|
}
|
|
|
|
if (size == 0) {
|
2017-07-24 12:57:44 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
2020-12-21 12:17:42 -05:00
|
|
|
if (!s_inited) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ch = &s_trace_channels[dest];
|
|
|
|
if (ch->hw == NULL) {
|
|
|
|
ESP_APPTRACE_LOGE("Trace destination %d not supported!", dest);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (ch->hw->get_up_buffer == NULL) {
|
2018-12-26 07:42:07 -05:00
|
|
|
return NULL;
|
|
|
|
}
|
2017-07-24 12:57:44 -04:00
|
|
|
|
|
|
|
esp_apptrace_tmo_init(&tmo, user_tmo);
|
2020-12-21 12:17:42 -05:00
|
|
|
return ch->hw->get_up_buffer(ch->hw_data, size, &tmo);
|
2017-07-24 12:57:44 -04:00
|
|
|
}
|
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
esp_err_t esp_apptrace_buffer_put(esp_apptrace_dest_t dest, uint8_t *ptr, uint32_t user_tmo)
|
2017-07-24 12:57:44 -04:00
|
|
|
{
|
|
|
|
esp_apptrace_tmo_t tmo;
|
2020-12-21 12:17:42 -05:00
|
|
|
esp_apptrace_channel_t *ch;
|
2017-07-24 12:57:44 -04:00
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
ESP_APPTRACE_LOGV("%s(): enter", __func__);
|
|
|
|
if (dest >= ESP_APPTRACE_DEST_MAX) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
2017-07-24 12:57:44 -04:00
|
|
|
}
|
2018-12-26 07:42:07 -05:00
|
|
|
if (ptr == NULL) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
2020-12-21 12:17:42 -05:00
|
|
|
if (!s_inited) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
}
|
|
|
|
ch = &s_trace_channels[dest];
|
|
|
|
if (ch->hw == NULL) {
|
|
|
|
ESP_APPTRACE_LOGE("Trace destination %d not supported!", dest);
|
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
if (ch->hw->put_up_buffer == NULL) {
|
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
|
|
|
}
|
2017-07-24 12:57:44 -04:00
|
|
|
|
|
|
|
esp_apptrace_tmo_init(&tmo, user_tmo);
|
2020-12-21 12:17:42 -05:00
|
|
|
return ch->hw->put_up_buffer(ch->hw_data, ptr, &tmo);
|
2017-07-24 12:57:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_apptrace_write(esp_apptrace_dest_t dest, const void *data, uint32_t size, uint32_t user_tmo)
|
2017-01-25 11:35:28 -05:00
|
|
|
{
|
|
|
|
uint8_t *ptr = NULL;
|
2017-07-24 12:57:44 -04:00
|
|
|
esp_apptrace_tmo_t tmo;
|
2020-12-21 12:17:42 -05:00
|
|
|
esp_apptrace_channel_t *ch;
|
2017-01-25 11:35:28 -05:00
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
ESP_APPTRACE_LOGV("%s(): enter", __func__);
|
|
|
|
if (dest >= ESP_APPTRACE_DEST_MAX) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
2017-01-25 11:35:28 -05:00
|
|
|
}
|
2018-12-26 07:42:07 -05:00
|
|
|
if (data == NULL || size == 0) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
2020-12-21 12:17:42 -05:00
|
|
|
if (!s_inited) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
}
|
|
|
|
ch = &s_trace_channels[dest];
|
|
|
|
if (ch->hw == NULL) {
|
|
|
|
ESP_APPTRACE_LOGE("Trace destination %d not supported!", dest);
|
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
if (ch->hw->get_up_buffer == NULL || ch->hw->put_up_buffer == NULL) {
|
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
|
|
|
}
|
2017-01-25 11:35:28 -05:00
|
|
|
|
2017-07-24 12:57:44 -04:00
|
|
|
esp_apptrace_tmo_init(&tmo, user_tmo);
|
2020-12-21 12:17:42 -05:00
|
|
|
ptr = ch->hw->get_up_buffer(ch->hw_data, size, &tmo);
|
2017-01-25 11:35:28 -05:00
|
|
|
if (ptr == NULL) {
|
|
|
|
return ESP_ERR_NO_MEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
// actually can be suspended here by higher prio tasks/ISRs
|
2017-03-21 23:07:37 -04:00
|
|
|
//TODO: use own memcpy with dead trace calls kick-off algo and tmo expiration check
|
2017-01-25 11:35:28 -05:00
|
|
|
memcpy(ptr, data, size);
|
|
|
|
|
|
|
|
// now indicate that this buffer is ready to be sent off to host
|
2020-12-21 12:17:42 -05:00
|
|
|
return ch->hw->put_up_buffer(ch->hw_data, ptr, &tmo);
|
2017-01-25 11:35:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int esp_apptrace_vprintf_to(esp_apptrace_dest_t dest, uint32_t user_tmo, const char *fmt, va_list ap)
|
|
|
|
{
|
|
|
|
uint16_t nargs = 0;
|
|
|
|
uint8_t *pout, *p = (uint8_t *)fmt;
|
2017-07-24 12:57:44 -04:00
|
|
|
esp_apptrace_tmo_t tmo;
|
2020-12-21 12:17:42 -05:00
|
|
|
esp_apptrace_channel_t *ch;
|
2017-01-25 11:35:28 -05:00
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
ESP_APPTRACE_LOGV("%s(): enter", __func__);
|
|
|
|
if (dest >= ESP_APPTRACE_DEST_MAX) {
|
|
|
|
return -1;
|
2017-01-25 11:35:28 -05:00
|
|
|
}
|
2018-12-26 07:42:07 -05:00
|
|
|
if (fmt == NULL) {
|
2020-12-21 12:17:42 -05:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!s_inited) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ch = &s_trace_channels[dest];
|
|
|
|
if (ch->hw == NULL) {
|
|
|
|
ESP_APPTRACE_LOGE("Trace destination %d not supported!", dest);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (ch->hw->get_up_buffer == NULL || ch->hw->put_up_buffer == NULL) {
|
|
|
|
return -1;
|
2018-12-26 07:42:07 -05:00
|
|
|
}
|
2017-01-25 11:35:28 -05:00
|
|
|
|
2017-07-24 12:57:44 -04:00
|
|
|
esp_apptrace_tmo_init(&tmo, user_tmo);
|
2017-03-21 23:07:37 -04:00
|
|
|
ESP_APPTRACE_LOGD("fmt %x", fmt);
|
2017-01-25 11:35:28 -05:00
|
|
|
while ((p = (uint8_t *)strchr((char *)p, '%')) && nargs < ESP_APPTRACE_MAX_VPRINTF_ARGS) {
|
|
|
|
p++;
|
|
|
|
if (*p != '%' && *p != 0) {
|
|
|
|
nargs++;
|
|
|
|
}
|
|
|
|
}
|
2017-03-21 23:07:37 -04:00
|
|
|
ESP_APPTRACE_LOGD("nargs = %d", nargs);
|
2017-01-25 11:35:28 -05:00
|
|
|
if (p) {
|
|
|
|
ESP_APPTRACE_LOGE("Failed to store all printf args!");
|
|
|
|
}
|
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
pout = ch->hw->get_up_buffer(ch->hw_data, 1 + sizeof(char *) + nargs * sizeof(uint32_t), &tmo);
|
2017-01-25 11:35:28 -05:00
|
|
|
if (pout == NULL) {
|
|
|
|
ESP_APPTRACE_LOGE("Failed to get buffer!");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
p = pout;
|
|
|
|
*pout = nargs;
|
|
|
|
pout++;
|
|
|
|
*(const char **)pout = fmt;
|
|
|
|
pout += sizeof(char *);
|
|
|
|
while (nargs-- > 0) {
|
|
|
|
uint32_t arg = va_arg(ap, uint32_t);
|
|
|
|
*(uint32_t *)pout = arg;
|
|
|
|
pout += sizeof(uint32_t);
|
2017-03-21 23:07:37 -04:00
|
|
|
ESP_APPTRACE_LOGD("arg %x", arg);
|
2017-01-25 11:35:28 -05:00
|
|
|
}
|
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
int ret = ch->hw->put_up_buffer(ch->hw_data, p, &tmo);
|
2017-01-25 11:35:28 -05:00
|
|
|
if (ret != ESP_OK) {
|
|
|
|
ESP_APPTRACE_LOGE("Failed to put printf buf (%d)!", ret);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (pout - p);
|
|
|
|
}
|
|
|
|
|
|
|
|
int esp_apptrace_vprintf(const char *fmt, va_list ap)
|
|
|
|
{
|
2020-12-21 12:17:42 -05:00
|
|
|
return esp_apptrace_vprintf_to(ESP_APPTRACE_DEST_JTAG, 0, fmt, ap);
|
2017-01-25 11:35:28 -05:00
|
|
|
}
|
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
esp_err_t esp_apptrace_flush_nolock(esp_apptrace_dest_t dest, uint32_t min_sz, uint32_t usr_tmo)
|
2017-01-25 11:35:28 -05:00
|
|
|
{
|
2017-07-24 12:57:44 -04:00
|
|
|
esp_apptrace_tmo_t tmo;
|
2020-12-21 12:17:42 -05:00
|
|
|
esp_apptrace_channel_t *ch;
|
2017-01-25 11:35:28 -05:00
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
ESP_APPTRACE_LOGV("%s(): enter", __func__);
|
|
|
|
if (dest >= ESP_APPTRACE_DEST_MAX) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
2017-01-25 11:35:28 -05:00
|
|
|
}
|
2020-12-21 12:17:42 -05:00
|
|
|
if (!s_inited) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
2018-12-26 07:42:07 -05:00
|
|
|
}
|
2020-12-21 12:17:42 -05:00
|
|
|
ch = &s_trace_channels[dest];
|
|
|
|
if (ch->hw == NULL) {
|
|
|
|
ESP_APPTRACE_LOGE("Trace destination %d not supported!", dest);
|
2017-01-25 11:35:28 -05:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
|
|
|
}
|
2020-12-21 12:17:42 -05:00
|
|
|
if (ch->hw->flush_up_buffer_nolock == NULL) {
|
2017-01-25 11:35:28 -05:00
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
2017-07-24 12:57:44 -04:00
|
|
|
esp_apptrace_tmo_init(&tmo, usr_tmo);
|
2020-12-21 12:17:42 -05:00
|
|
|
return ch->hw->flush_up_buffer_nolock(ch->hw_data, min_sz, &tmo);
|
2017-01-25 11:35:28 -05:00
|
|
|
}
|
|
|
|
|
2017-07-24 12:57:44 -04:00
|
|
|
esp_err_t esp_apptrace_flush(esp_apptrace_dest_t dest, uint32_t usr_tmo)
|
2017-01-25 11:35:28 -05:00
|
|
|
{
|
2017-07-24 12:57:44 -04:00
|
|
|
esp_apptrace_tmo_t tmo;
|
2020-12-21 12:17:42 -05:00
|
|
|
esp_apptrace_channel_t *ch;
|
2017-01-25 11:35:28 -05:00
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
ESP_APPTRACE_LOGV("%s(): enter", __func__);
|
|
|
|
if (dest >= ESP_APPTRACE_DEST_MAX) {
|
|
|
|
return ESP_ERR_INVALID_ARG;
|
2017-01-25 11:35:28 -05:00
|
|
|
}
|
2020-12-21 12:17:42 -05:00
|
|
|
if (!s_inited) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
2017-01-25 11:35:28 -05:00
|
|
|
}
|
2020-12-21 12:17:42 -05:00
|
|
|
ch = &s_trace_channels[dest];
|
|
|
|
if (ch->hw == NULL) {
|
|
|
|
ESP_APPTRACE_LOGE("Trace destination %d not supported!", dest);
|
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
if (ch->hw->flush_up_buffer == NULL) {
|
|
|
|
return ESP_ERR_NOT_SUPPORTED;
|
2017-01-25 11:35:28 -05:00
|
|
|
}
|
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
esp_apptrace_tmo_init(&tmo, usr_tmo);
|
|
|
|
return ch->hw->flush_up_buffer(ch->hw_data, &tmo);
|
2017-01-25 11:35:28 -05:00
|
|
|
}
|
2017-08-16 19:36:00 -04:00
|
|
|
|
|
|
|
bool esp_apptrace_host_is_connected(esp_apptrace_dest_t dest)
|
|
|
|
{
|
2020-12-21 12:17:42 -05:00
|
|
|
esp_apptrace_channel_t *ch;
|
2017-08-16 19:36:00 -04:00
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
ESP_APPTRACE_LOGV("%s(): enter", __func__);
|
|
|
|
if (dest >= ESP_APPTRACE_DEST_MAX) {
|
2018-02-15 12:09:03 -05:00
|
|
|
return false;
|
2020-12-21 12:17:42 -05:00
|
|
|
}
|
|
|
|
if (!s_inited) {
|
2018-02-15 12:09:03 -05:00
|
|
|
return false;
|
|
|
|
}
|
2020-12-21 12:17:42 -05:00
|
|
|
ch = &s_trace_channels[dest];
|
|
|
|
if (ch->hw == NULL) {
|
|
|
|
ESP_APPTRACE_LOGE("Trace destination %d not supported!", dest);
|
|
|
|
return false;
|
2017-08-16 19:36:00 -04:00
|
|
|
}
|
2020-12-21 12:17:42 -05:00
|
|
|
if (ch->hw->host_is_connected == NULL) {
|
|
|
|
return false;
|
2018-02-15 12:09:03 -05:00
|
|
|
}
|
2017-08-16 19:36:00 -04:00
|
|
|
|
2020-12-21 12:17:42 -05:00
|
|
|
return ch->hw->host_is_connected(ch->hw_data);
|
|
|
|
}
|