18 #define ESP32_SYSVIEW_USER_BLOCK_CORE(_v_) (0)
19 #define ESP32_SYSVIEW_USER_BLOCK_LEN(_v_) (_v_)
20 #define ESP32_SYSVIEW_USER_BLOCK_HDR_SZ 2
26 #define SYSVIEW_BLOCK_SIZE_OFFSET 0
27 #define SYSVIEW_WR_SIZE_OFFSET 1
54 command_print(
cmd,
"Not enough args! Need %d trace data destinations!", core_num);
59 cmd_data = calloc(1,
sizeof(*cmd_data));
71 command_print(
cmd,
"Not enough args! Need %d trace data destinations!", core_num);
79 if (argc > dests_num) {
86 LOG_USER(
"App trace params: from %d cores, size %u bytes, stop_tmo %g s, "
87 "poll period %u ms, wait_rst %d, skip %u bytes",
145 "; Author Espressif Inc\n"
151 "; Author Espressif Inc\n"
157 int hdr_len = strlen(hdr_str);
158 for (
int i = 0; i < dests_num; i++) {
163 LOG_ERROR(
"sysview: Failed to write %u bytes to dest %d!", hdr_len, i);
172 uint8_t *sv_ptr = *dest;
174 *sv_ptr++ = (uint8_t)(val | 0x80);
177 *sv_ptr++ = (uint8_t)val;
184 for (
int k = 0;; k++, (*ptr)++) {
186 val |= (uint32_t)(**ptr & ~0x80) << 7 * k;
188 val |= (uint32_t)**ptr << 7 * k;
198 uint16_t payload_len = 0;
202 payload_len = *(p + 1);
203 payload_len = (payload_len << 7) | (*p & ~0x80);
250 len = ptr - pkt + *ptr + 1;
272 LOG_ERROR(
"sysview: Unsupported predef event %d!",
id);
280 unsigned int *pkt_core_id,
285 uint8_t *pkt = pkt_buf;
286 uint16_t event_id = 0, payload_len = 0;
292 if (*(pkt + 1) & (1 << 6)) {
294 *(pkt + 1) &= ~(1 << 6);
297 event_id = *(pkt + 1) & ~(1 << 6);
298 event_id = (event_id << 7) | (*pkt & ~0x80);
303 if (*pkt & (1 << 6)) {
309 event_id = *pkt & ~(1 << 6);
317 uint8_t *delta_start = pkt;
319 *delta_len = pkt - delta_start;
320 *pkt_len = pkt - pkt_buf;
321 LOG_DEBUG(
"sysview: evt %d len %d plen %d dlen %d",
330 int pkt_core_id, uint32_t pkt_len, uint8_t *pkt_buf, uint32_t delta_len, uint8_t *delta_buf)
338 LOG_ERROR(
"sysview: Failed to write %u bytes to dest %d!", pkt_len, pkt_core_id);
345 LOG_ERROR(
"sysview: Failed to write %u bytes of delta to dest %d!", delta_len, pkt_core_id);
353 unsigned int pkt_core_id, uint16_t event_id, uint32_t delta, uint32_t delta_len,
354 uint32_t pkt_len, uint8_t *pkt_buf)
357 int pkt_core_changed = 0;
358 uint32_t new_delta_len = 0;
359 uint8_t new_delta_buf[10];
360 uint32_t wr_len = pkt_len;
368 uint8_t *delta_ptr = new_delta_buf;
372 new_delta_len = delta_ptr - new_delta_buf;
373 pkt_core_changed = 1;
378 LOG_WARNING(
"sysview: invalid core ID in packet %d, must be less then %d! Event id %d",
392 for (
unsigned int i = 0; i < ctx->
cores_num; i++) {
393 if (pkt_core_id == i)
411 if (pkt_core_changed) {
416 uint8_t *delta_ptr = new_delta_buf;
419 new_delta_len = delta_ptr - new_delta_buf;
421 LOG_DEBUG(
"sysview: Redirect %d bytes of event %d to dest %d", wr_len, event_id, i);
443 unsigned int core_id,
449 LOG_DEBUG(
"sysview: Read from target %d bytes [%x %x %x %x]",
456 uint32_t processed = 0;
458 LOG_ERROR(
"sysview: Invalid core id %d in user block!", core_id);
466 LOG_ERROR(
"sysview: Invalid init seq len %d!", data_len);
470 uint8_t sync_seq[
SYSVIEW_SYNC_LEN] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
472 LOG_ERROR(
"sysview: Invalid init seq [%x %x %x %x %x %x %x %x %x %x]",
473 data[0], data[1], data[2], data[3], data[4], data[5], data[6],
474 data[7], data[8], data[9]);
481 LOG_ERROR(
"sysview: Failed to write %u sync bytes to dest %d!",
487 for (
unsigned int i = 0; i < ctx->
cores_num; i++) {
503 while (processed < data_len) {
504 unsigned int pkt_core_id;
505 uint32_t delta_len = 0;
506 uint32_t pkt_len = 0, delta = 0;
513 LOG_DEBUG(
"sysview: Process packet: core %d, %d id, %d bytes [%x %x %x %x]",
520 data[processed + 3]);
534 LOG_ERROR(
"sysview: Failed to write %u bytes to dest %d!", pkt_len, 0);
541 processed += pkt_len;
549 LOG_ERROR(
"Failed to stop trace read time measure!");
void command_print(struct command_invocation *cmd, const char *format,...)
void esp32_apptrace_cmd_args_parse(struct esp32_apptrace_cmd_ctx *cmd_ctx, struct esp32_apptrace_cmd_data *cmd_data, const char **argv, int argc)
int esp32_apptrace_dest_cleanup(struct esp32_apptrace_dest dest[], unsigned int max_dests)
int esp32_apptrace_dest_init(struct esp32_apptrace_dest dest[], const char *dest_paths[], unsigned int max_dests)
int esp32_apptrace_cmd_ctx_init(struct esp32_apptrace_cmd_ctx *cmd_ctx, struct command_invocation *cmd, int mode)
int esp32_apptrace_cmd_ctx_cleanup(struct esp32_apptrace_cmd_ctx *cmd_ctx)
static void sysview_encode_u32(uint8_t **dest, uint32_t val)
static int esp32_sysview_write_packet(struct esp32_sysview_cmd_data *cmd_data, int pkt_core_id, uint32_t pkt_len, uint8_t *pkt_buf, uint32_t delta_len, uint8_t *delta_buf)
static uint32_t esp_sysview_decode_u32(uint8_t **ptr)
#define SYSVIEW_BLOCK_SIZE_OFFSET
static int esp32_sysview_core_id_get(struct target *target, uint8_t *hdr_buf)
int esp32_sysview_cmd_init(struct esp32_apptrace_cmd_ctx *cmd_ctx, struct command_invocation *cmd, int mode, bool mcore_format, const char **argv, int argc)
int esp32_sysview_process_data(struct esp32_apptrace_cmd_ctx *ctx, unsigned int core_id, uint8_t *data, uint32_t data_len)
static uint16_t esp_sysview_get_predef_payload_len(uint16_t id, uint8_t *pkt)
static int esp_sysview_trace_header_write(struct esp32_apptrace_cmd_ctx *ctx, bool mcore_format)
static uint16_t esp_sysview_decode_plen(uint8_t **ptr)
#define SYSVIEW_WR_SIZE_OFFSET
static uint16_t esp_sysview_parse_packet(uint8_t *pkt_buf, uint32_t *pkt_len, unsigned int *pkt_core_id, uint32_t *delta, uint32_t *delta_len, bool clear_core_bit)
static int esp32_sysview_process_packet(struct esp32_apptrace_cmd_ctx *ctx, unsigned int pkt_core_id, uint16_t event_id, uint32_t delta, uint32_t delta_len, uint32_t pkt_len, uint8_t *pkt_buf)
static uint32_t esp32_sysview_usr_block_len_get(struct target *target, uint8_t *hdr_buf, uint32_t *wr_len)
int esp32_sysview_cmd_cleanup(struct esp32_apptrace_cmd_ctx *cmd_ctx)
#define ESP32_SYSVIEW_USER_BLOCK_LEN(_v_)
#define ESP32_SYSVIEW_USER_BLOCK_HDR_SZ
#define LOG_USER(expr ...)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_DEBUG(expr ...)
#define SYSVIEW_EVTID_TASK_STOP_EXEC
#define SYSVIEW_EVTID_NUMMODULES
#define SYSVIEW_EVTID_STACK_INFO
#define SYSVIEW_EVTID_ISR_ENTER
#define SYSVIEW_EVTID_OVERFLOW
#define SYSVIEW_EVTID_IDLE
#define SYSVIEW_EVTID_SYSTIME_US
#define SYSVIEW_EVTID_TASK_START_EXEC
#define SYSVIEW_EVTID_TRACE_STOP
#define SYSVIEW_EVTID_TASK_START_READY
#define SYSVIEW_EVTID_USER_START
#define SYSVIEW_EVTID_TRACE_START
#define SYSVIEW_MIN_VER_STRING
#define SYSVIEW_EVTID_USER_STOP
#define SYSVIEW_EVTID_TIMER_ENTER
#define SYSVIEW_EVTID_INIT
#define SYSVIEW_EVTID_SYSTIME_CYCLES
#define SYSVIEW_EVTID_MODULEDESC
#define SYSVIEW_EVTID_TIMER_EXIT
#define SYSVIEW_EVTID_TASK_STOP_READY
#define SYSVIEW_EVTID_SYSDESC
#define SYSVIEW_EVTID_ISR_EXIT
#define SYSVIEW_EVTID_TASK_INFO
#define SYSVIEW_EVTID_TASK_CREATE
#define SYSVIEW_EVTID_ISR_TO_SCHEDULER
When run_command is called, a new instance will be created on the stack, filled with the proper value...
struct duration read_time
struct esp32_apptrace_format trace_format
int(* write)(void *priv, uint8_t *data, int size)
unsigned int sv_last_core_id
struct esp32_apptrace_cmd_data apptrace
uint32_t sv_acc_time_delta
struct esp32_apptrace_dest data_dests[ESP32_APPTRACE_MAX_CORES_NUM]
int duration_measure(struct duration *duration)
Update the duration->elapsed field to finish the duration measurement.