Select one of the symbols to view example projects that use it.
 
Outline
#include "config.h"
#include <helper/log.h>
#include "esp32_apptrace.h"
#include "esp32_sysview.h"
#include "segger_sysview.h"
#define ESP32_SYSVIEW_USER_BLOCK_CORE
#define ESP32_SYSVIEW_USER_BLOCK_LEN
#define ESP32_SYSVIEW_USER_BLOCK_HDR_SZ
esp_sysview_target2host_hdr
#define SYSVIEW_BLOCK_SIZE_OFFSET
#define SYSVIEW_WR_SIZE_OFFSET
esp32_sysview_cmd_init(struct esp32_apptrace_cmd_ctx *, struct command_invocation *, int, bool, const char **, int)
esp32_sysview_cmd_cleanup(struct esp32_apptrace_cmd_ctx *)
esp32_sysview_core_id_get(struct target *, uint8_t *)
esp32_sysview_usr_block_len_get(struct target *, uint8_t *, uint32_t *)
esp_sysview_trace_header_write(struct esp32_apptrace_cmd_ctx *, bool)
sysview_encode_u32(uint8_t **, uint32_t)
esp_sysview_decode_u32(uint8_t **)
esp_sysview_decode_plen(uint8_t **)
esp_sysview_get_predef_payload_len(uint16_t, uint8_t *)
esp_sysview_parse_packet(uint8_t *, uint32_t *, unsigned int *, uint32_t *, uint32_t *, bool)
esp32_sysview_write_packet(struct esp32_sysview_cmd_data *, int, uint32_t, uint8_t *, uint32_t, uint8_t *)
esp32_sysview_process_packet(struct esp32_apptrace_cmd_ctx *, unsigned int, uint16_t, uint32_t, uint32_t, uint32_t, uint8_t *)
esp32_sysview_process_data(struct esp32_apptrace_cmd_ctx *, unsigned int, uint8_t *, uint32_t)
Files
loading...
SourceVuDevelopment ToolsOpenOCDsrc/target/espressif/esp32_sysview.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
// SPDX-License-Identifier: GPL-2.0-or-later /*************************************************************************** * ESP32 sysview tracing module * * Copyright (C) 2020 Espressif Systems Ltd. * ***************************************************************************//* ... */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <helper/log.h> #include "esp32_apptrace.h" #include "esp32_sysview.h" #include "segger_sysview.h" /* in SystemView mode core ID is passed in event ID field */ #define ESP32_SYSVIEW_USER_BLOCK_CORE(_v_) (0) /* not used */ #define ESP32_SYSVIEW_USER_BLOCK_LEN(_v_) (_v_) #define ESP32_SYSVIEW_USER_BLOCK_HDR_SZ 2 struct esp_sysview_target2host_hdr { uint8_t block_sz; uint8_t wr_sz; ...}; #define SYSVIEW_BLOCK_SIZE_OFFSET 0 #define SYSVIEW_WR_SIZE_OFFSET 1 static int esp_sysview_trace_header_write(struct esp32_apptrace_cmd_ctx *ctx, bool mcore_format); static int esp32_sysview_core_id_get(struct target *target, uint8_t *hdr_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_init(struct esp32_apptrace_cmd_ctx *cmd_ctx, struct command_invocation *cmd, int mode, bool mcore_format, const char **argv, int argc) { struct esp32_sysview_cmd_data *cmd_data; if (argc < 1) { command_print(cmd, "Not enough args! Need trace data destination!"); return ERROR_FAIL; }if (argc < 1) { ... } int res = esp32_apptrace_cmd_ctx_init(cmd_ctx, cmd, mode); if (res != ERROR_OK) return res; int core_num = cmd_ctx->cores_num; if (!mcore_format && argc < core_num) { command_print(cmd, "Not enough args! Need %d trace data destinations!", core_num); res = ERROR_FAIL; goto on_error; }if (!mcore_format && argc < core_num) { ... } cmd_data = calloc(1, sizeof(*cmd_data)); if (!cmd_data) { command_print(cmd, "No memory for command data!"); res = ERROR_FAIL; goto on_error; }if (!cmd_data) { ... } cmd_ctx->cmd_priv = cmd_data; cmd_data->mcore_format = mcore_format; /*outfile1 [outfile2] [poll_period [trace_size [stop_tmo [wait4halt [skip_size]]]]] */ int dests_num = esp32_apptrace_dest_init(cmd_data->data_dests, argv, !mcore_format ? core_num : 1); if (!mcore_format && dests_num < core_num) { command_print(cmd, "Not enough args! Need %d trace data destinations!", core_num); free(cmd_data); res = ERROR_FAIL; goto on_error; }if (!mcore_format && dests_num < core_num) { ... } cmd_data->apptrace.max_len = UINT32_MAX; cmd_data->apptrace.poll_period = 0 /*ms*/; cmd_ctx->stop_tmo = -1.0; /* infinite */ if (argc > dests_num) { /* parse remaining args */ esp32_apptrace_cmd_args_parse(cmd_ctx, &cmd_data->apptrace, &argv[dests_num], argc - dests_num); }if (argc > dests_num) { ... } LOG_USER("App trace params: from %d cores, size %u bytes, stop_tmo %g s, " "poll period %u ms, wait_rst %d, skip %u bytes", cmd_ctx->cores_num, cmd_data->apptrace.max_len, cmd_ctx->stop_tmo, cmd_data->apptrace.poll_period, cmd_data->apptrace.wait4halt, cmd_data->apptrace.skip_len); cmd_ctx->trace_format.hdr_sz = ESP32_SYSVIEW_USER_BLOCK_HDR_SZ; cmd_ctx->trace_format.core_id_get = esp32_sysview_core_id_get; cmd_ctx->trace_format.usr_block_len_get = esp32_sysview_usr_block_len_get; res = esp_sysview_trace_header_write(cmd_ctx, mcore_format); if (res != ERROR_OK) { command_print(cmd, "Failed to write trace header (%d)!", res); esp32_apptrace_dest_cleanup(cmd_data->data_dests, core_num); free(cmd_data); return res; }if (res != ERROR_OK) { ... } return ERROR_OK; on_error: cmd_ctx->running = 0; esp32_apptrace_cmd_ctx_cleanup(cmd_ctx); return res; }{ ... } int esp32_sysview_cmd_cleanup(struct esp32_apptrace_cmd_ctx *cmd_ctx) { struct esp32_sysview_cmd_data *cmd_data = cmd_ctx->cmd_priv; esp32_apptrace_dest_cleanup(cmd_data->data_dests, cmd_ctx->cores_num); free(cmd_data); cmd_ctx->cmd_priv = NULL; esp32_apptrace_cmd_ctx_cleanup(cmd_ctx); return ERROR_OK; }{ ... } static int esp32_sysview_core_id_get(struct target *target, uint8_t *hdr_buf) { /* for sysview compressed apptrace header is used, so core id is encoded in sysview packet */ return 0; }{ ... } static uint32_t esp32_sysview_usr_block_len_get(struct target *target, uint8_t *hdr_buf, uint32_t *wr_len) { *wr_len = ESP32_SYSVIEW_USER_BLOCK_LEN(hdr_buf[SYSVIEW_WR_SIZE_OFFSET]); return ESP32_SYSVIEW_USER_BLOCK_LEN(hdr_buf[SYSVIEW_BLOCK_SIZE_OFFSET]); }{ ... } static int esp_sysview_trace_header_write(struct esp32_apptrace_cmd_ctx *ctx, bool mcore_format) { struct esp32_sysview_cmd_data *cmd_data = ctx->cmd_priv; char *hdr_str; int dests_num; if (!mcore_format) { hdr_str = ";\n" "; Version " SYSVIEW_MIN_VER_STRING "\n" "; Author Espressif Inc\n" ";\n"; dests_num = ctx->cores_num; }if (!mcore_format) { ... } else { hdr_str = ";\n" "; Version " SYSVIEW_MIN_VER_STRING "\n" "; Author Espressif Inc\n" "; ESP_Extension\n" ";\n"; dests_num = 1; }else { ... } int hdr_len = strlen(hdr_str); for (int i = 0; i < dests_num; i++) { int res = cmd_data->data_dests[i].write(cmd_data->data_dests[i].priv, (uint8_t *)hdr_str, hdr_len); if (res != ERROR_OK) { LOG_ERROR("sysview: Failed to write %u bytes to dest %d!", hdr_len, i); return ERROR_FAIL; }if (res != ERROR_OK) { ... } }for (int i = 0; i < dests_num; i++) { ... } return ERROR_OK; }{ ... } static void sysview_encode_u32(uint8_t **dest, uint32_t val) { uint8_t *sv_ptr = *dest; while (val > 0x7F) { *sv_ptr++ = (uint8_t)(val | 0x80); val >>= 7; }while (val > 0x7F) { ... } *sv_ptr++ = (uint8_t)val; *dest = sv_ptr; }{ ... } static uint32_t esp_sysview_decode_u32(uint8_t **ptr) { uint32_t val = 0; for (int k = 0;; k++, (*ptr)++) { if (**ptr & 0x80) { val |= (uint32_t)(**ptr & ~0x80) << 7 * k; }if (**ptr & 0x80) { ... } else { val |= (uint32_t)**ptr << 7 * k; (*ptr)++; break; }else { ... } }for (int k = 0;; k++, (*ptr)++) { ... } return val; }{ ... } static uint16_t esp_sysview_decode_plen(uint8_t **ptr) { uint16_t payload_len = 0; uint8_t *p = *ptr; /* here pkt points to encoded payload length */ if (*p & 0x80) { payload_len = *(p + 1); /* higher part */ payload_len = (payload_len << 7) | (*p & ~0x80);/* lower 7 bits */ p += 2; /* payload len (2 bytes) */ }if (*p & 0x80) { ... } else { payload_len = *p; p++; /* payload len (1 byte) */ }else { ... } *ptr = p; return payload_len; }{ ... } static uint16_t esp_sysview_get_predef_payload_len(uint16_t id, uint8_t *pkt) { uint16_t len; uint8_t *ptr = pkt; switch (id) { case SYSVIEW_EVTID_OVERFLOW: case SYSVIEW_EVTID_ISR_ENTER: case SYSVIEW_EVTID_TASK_START_EXEC: case SYSVIEW_EVTID_TASK_START_READY: case SYSVIEW_EVTID_TASK_CREATE: case SYSVIEW_EVTID_SYSTIME_CYCLES: case SYSVIEW_EVTID_USER_START: case SYSVIEW_EVTID_USER_STOP: case SYSVIEW_EVTID_TIMER_ENTER: /*ENCODE_U32 */ esp_sysview_decode_u32(&ptr); len = ptr - pkt; break;case SYSVIEW_EVTID_TIMER_ENTER: case SYSVIEW_EVTID_TASK_STOP_READY: case SYSVIEW_EVTID_SYSTIME_US: /*2*ENCODE_U32 */ esp_sysview_decode_u32(&ptr); esp_sysview_decode_u32(&ptr); len = ptr - pkt; break;case SYSVIEW_EVTID_SYSTIME_US: case SYSVIEW_EVTID_SYSDESC: /*str(128 + 1) */ len = *ptr + 1; break;case SYSVIEW_EVTID_SYSDESC: case SYSVIEW_EVTID_TASK_INFO: case SYSVIEW_EVTID_MODULEDESC: /*2*ENCODE_U32 + str */ esp_sysview_decode_u32(&ptr); esp_sysview_decode_u32(&ptr); /* TODO: add support for strings longer then 255 bytes */ len = ptr - pkt + *ptr + 1; break;case SYSVIEW_EVTID_MODULEDESC: case SYSVIEW_EVTID_STACK_INFO: /*4*ENCODE_U32 */ esp_sysview_decode_u32(&ptr); esp_sysview_decode_u32(&ptr); esp_sysview_decode_u32(&ptr); esp_sysview_decode_u32(&ptr); len = ptr - pkt; break;case SYSVIEW_EVTID_STACK_INFO: case SYSVIEW_EVTID_ISR_EXIT: case SYSVIEW_EVTID_TASK_STOP_EXEC: case SYSVIEW_EVTID_TRACE_START: case SYSVIEW_EVTID_TRACE_STOP: case SYSVIEW_EVTID_IDLE: case SYSVIEW_EVTID_ISR_TO_SCHEDULER: case SYSVIEW_EVTID_TIMER_EXIT: len = 0; break; /*case SYSVIEW_EVTID_NOP: */case SYSVIEW_EVTID_TIMER_EXIT: default: LOG_ERROR("sysview: Unsupported predef event %d!", id); len = 0;default }switch (id) { ... } return len; }{ ... } 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) { uint8_t *pkt = pkt_buf; uint16_t event_id = 0, payload_len = 0; *pkt_core_id = 0; *pkt_len = 0; /* 1-2 byte of message type, 0-2 byte of payload length, payload, 1-5 bytes of timestamp. */ if (*pkt & 0x80) { if (*(pkt + 1) & (1 << 6)) { if (clear_core_bit) *(pkt + 1) &= ~(1 << 6); /* clear core_id bit */ *pkt_core_id = 1; }if (*(pkt + 1) & (1 << 6)) { ... } event_id = *(pkt + 1) & ~(1 << 6); /* higher part */ event_id = (event_id << 7) | (*pkt & ~0x80); /* lower 7 bits */ pkt += 2; /* event_id (2 bytes) */ /* here pkt points to encoded payload length */ payload_len = esp_sysview_decode_plen(&pkt); }if (*pkt & 0x80) { ... } else { if (*pkt & (1 << 6)) { if (clear_core_bit) *pkt &= ~(1 << 6); /* clear core_id bit */ *pkt_core_id = 1; }if (*pkt & (1 << 6)) { ... } /* event_id (1 byte) */ event_id = *pkt & ~(1 << 6); pkt++; if (event_id < 24) payload_len = esp_sysview_get_predef_payload_len(event_id, pkt); else payload_len = esp_sysview_decode_plen(&pkt); }else { ... } pkt += payload_len; uint8_t *delta_start = pkt; *delta = esp_sysview_decode_u32(&pkt); *delta_len = pkt - delta_start; *pkt_len = pkt - pkt_buf; LOG_DEBUG("sysview: evt %d len %d plen %d dlen %d", event_id, *pkt_len, payload_len, *delta_len); return event_id; }{ ... } 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) { if (!cmd_data->data_dests[pkt_core_id].write) return ERROR_FAIL; int res = cmd_data->data_dests[pkt_core_id].write(cmd_data->data_dests[pkt_core_id].priv, pkt_buf, pkt_len); if (res != ERROR_OK) { LOG_ERROR("sysview: Failed to write %u bytes to dest %d!", pkt_len, pkt_core_id); return res; }if (res != ERROR_OK) { ... } if (delta_len) { /* write packet with modified delta */ res = cmd_data->data_dests[pkt_core_id].write(cmd_data->data_dests[pkt_core_id].priv, delta_buf, delta_len); if (res != ERROR_OK) { LOG_ERROR("sysview: Failed to write %u bytes of delta to dest %d!", delta_len, pkt_core_id); return res; }if (res != ERROR_OK) { ... } }if (delta_len) { ... } return ERROR_OK; }{ ... } 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) { struct esp32_sysview_cmd_data *cmd_data = ctx->cmd_priv; int pkt_core_changed = 0; uint32_t new_delta_len = 0; uint8_t new_delta_buf[10]; uint32_t wr_len = pkt_len; if (ctx->cores_num > 1) { if (cmd_data->sv_last_core_id == pkt_core_id) { /* if this packet is for the same core as the prev one acc delta and write packet unmodified */ cmd_data->sv_acc_time_delta += delta; }if (cmd_data->sv_last_core_id == pkt_core_id) { ... } else { /* if this packet is for another core then prev one set acc delta to the packet's delta */ uint8_t *delta_ptr = new_delta_buf; sysview_encode_u32(&delta_ptr, delta + cmd_data->sv_acc_time_delta); cmd_data->sv_acc_time_delta = delta; wr_len -= delta_len; new_delta_len = delta_ptr - new_delta_buf; pkt_core_changed = 1; }else { ... } cmd_data->sv_last_core_id = pkt_core_id; }if (ctx->cores_num > 1) { ... } if (pkt_core_id >= ctx->cores_num) { LOG_WARNING("sysview: invalid core ID in packet %d, must be less then %d! Event id %d", pkt_core_id, ctx->cores_num, event_id); return ERROR_FAIL; }if (pkt_core_id >= ctx->cores_num) { ... } int res = esp32_sysview_write_packet(cmd_data, pkt_core_id, wr_len, pkt_buf, new_delta_len, new_delta_buf); if (res != ERROR_OK) return res; for (unsigned int i = 0; i < ctx->cores_num; i++) { if (pkt_core_id == i) continue; switch (event_id) { /* messages below should be sent to trace destinations for all cores */ case SYSVIEW_EVTID_TRACE_START: case SYSVIEW_EVTID_TRACE_STOP: case SYSVIEW_EVTID_SYSTIME_CYCLES: case SYSVIEW_EVTID_SYSTIME_US: case SYSVIEW_EVTID_SYSDESC: case SYSVIEW_EVTID_TASK_INFO: case SYSVIEW_EVTID_STACK_INFO: case SYSVIEW_EVTID_MODULEDESC: case SYSVIEW_EVTID_INIT: case SYSVIEW_EVTID_NUMMODULES: case SYSVIEW_EVTID_OVERFLOW: case SYSVIEW_EVTID_TASK_START_READY: /* if packet's source core has changed */ wr_len = pkt_len; if (pkt_core_changed) { /* clone packet with unmodified delta */ new_delta_len = 0; }if (pkt_core_changed) { ... } else { /* clone packet with modified delta */ uint8_t *delta_ptr = new_delta_buf; sysview_encode_u32(&delta_ptr, cmd_data->sv_acc_time_delta /*delta has been accumulated above*/); wr_len -= delta_len; new_delta_len = delta_ptr - new_delta_buf; }else { ... } LOG_DEBUG("sysview: Redirect %d bytes of event %d to dest %d", wr_len, event_id, i); res = esp32_sysview_write_packet(cmd_data, i, wr_len, pkt_buf, new_delta_len, new_delta_buf); if (res != ERROR_OK) return res; /* messages above are cloned to trace files for both cores, * so reset acc time delta, both files have actual delta * info *//* ... */ cmd_data->sv_acc_time_delta = 0; break;case SYSVIEW_EVTID_TASK_START_READY: default: break;default }switch (event_id) { ... } }for (unsigned int i = 0; i < ctx->cores_num; i++) { ... } return ERROR_OK; }{ ... } int esp32_sysview_process_data(struct esp32_apptrace_cmd_ctx *ctx, unsigned int core_id, uint8_t *data, uint32_t data_len) { struct esp32_sysview_cmd_data *cmd_data = ctx->cmd_priv; LOG_DEBUG("sysview: Read from target %d bytes [%x %x %x %x]", data_len, data[0], data[1], data[2], data[3]); int res; uint32_t processed = 0; if (core_id >= ctx->cores_num) { LOG_ERROR("sysview: Invalid core id %d in user block!", core_id); return ERROR_FAIL; }if (core_id >= ctx->cores_num) { ... } if (cmd_data->mcore_format) core_id = 0; if (ctx->tot_len == 0) { /* handle sync seq */ if (data_len < SYSVIEW_SYNC_LEN) { LOG_ERROR("sysview: Invalid init seq len %d!", data_len); return ERROR_FAIL; }if (data_len < SYSVIEW_SYNC_LEN) { ... } LOG_DEBUG("sysview: Process %d sync bytes", SYSVIEW_SYNC_LEN); uint8_t sync_seq[SYSVIEW_SYNC_LEN] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; if (memcmp(data, sync_seq, SYSVIEW_SYNC_LEN) != 0) { LOG_ERROR("sysview: Invalid init seq [%x %x %x %x %x %x %x %x %x %x]", data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9]); return ERROR_FAIL; }if (memcmp(data, sync_seq, SYSVIEW_SYNC_LEN) != 0) { ... } res = cmd_data->data_dests[core_id].write(cmd_data->data_dests[core_id].priv, data, SYSVIEW_SYNC_LEN); if (res != ERROR_OK) { LOG_ERROR("sysview: Failed to write %u sync bytes to dest %d!", SYSVIEW_SYNC_LEN, core_id); return res; }if (res != ERROR_OK) { ... } if (!cmd_data->mcore_format) { for (unsigned int i = 0; i < ctx->cores_num; i++) { if (core_id == i) continue; res = cmd_data->data_dests[i].write(cmd_data->data_dests[i].priv, data, SYSVIEW_SYNC_LEN); if (res != ERROR_OK) { LOG_ERROR("sysview: Failed to write %u sync bytes to dest %d!", SYSVIEW_SYNC_LEN, core_id ? 0 : 1); return res; }if (res != ERROR_OK) { ... } }for (unsigned int i = 0; i < ctx->cores_num; i++) { ... } }if (!cmd_data->mcore_format) { ... } ctx->tot_len += SYSVIEW_SYNC_LEN; processed += SYSVIEW_SYNC_LEN; }if (ctx->tot_len == 0) { ... } while (processed < data_len) { unsigned int pkt_core_id; uint32_t delta_len = 0; uint32_t pkt_len = 0, delta = 0; uint16_t event_id = esp_sysview_parse_packet(data + processed, &pkt_len, &pkt_core_id, &delta, &delta_len, !cmd_data->mcore_format); LOG_DEBUG("sysview: Process packet: core %d, %d id, %d bytes [%x %x %x %x]", pkt_core_id, event_id, pkt_len, data[processed + 0], data[processed + 1], data[processed + 2], data[processed + 3]); if (!cmd_data->mcore_format) { res = esp32_sysview_process_packet(ctx, pkt_core_id, event_id, delta, delta_len, pkt_len, data + processed); if (res != ERROR_OK) return res; }if (!cmd_data->mcore_format) { ... } else { res = cmd_data->data_dests[0].write(cmd_data->data_dests[0].priv, data + processed, pkt_len); if (res != ERROR_OK) { LOG_ERROR("sysview: Failed to write %u bytes to dest %d!", pkt_len, 0); return res; }if (res != ERROR_OK) { ... } }else { ... } if (event_id == SYSVIEW_EVTID_TRACE_STOP) cmd_data->sv_trace_running = 0; ctx->tot_len += pkt_len; processed += pkt_len; }while (processed < data_len) { ... } LOG_USER("%u ", ctx->tot_len); /* check for stop condition */ if (ctx->tot_len > cmd_data->apptrace.skip_len && (ctx->tot_len - cmd_data->apptrace.skip_len >= cmd_data->apptrace.max_len)) { ctx->running = 0; if (duration_measure(&ctx->read_time) != 0) { LOG_ERROR("Failed to stop trace read time measure!"); return ERROR_FAIL; }if (duration_measure(&ctx->read_time) != 0) { ... } }if (ctx->tot_len > cmd_data->apptrace.skip_len && (ctx->tot_len - cmd_data->apptrace.skip_len >= cmd_data->apptrace.max_len)) { ... } return ERROR_OK; }{ ... }
Details
Show:
from
Types: Columns:
Click anywhere in the source to view detailed information here...