Skip to content

Commit 5e8a378

Browse files
committed
esp108/apptrace: Makes SystemView tracing 'stop' command waiting for 'STOP' target message
1 parent 42d824d commit 5e8a378

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/target/esp108_apptrace.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ struct esp_apptrace_cmd_data {
409409
uint32_t poll_period;
410410
uint32_t sv_acc_time_delta;
411411
int sv_last_core_id;
412+
int sv_trace_running;
412413
uint32_t max_len;
413414
uint32_t skip_len;
414415
bool wait4halt;
@@ -1311,6 +1312,7 @@ static int esp_sysview_start(struct esp_apptrace_cmd_ctx *ctx)
13111312
uint8_t cmds[] = {SEGGER_SYSVIEW_COMMAND_ID_START};
13121313
uint32_t fired_target_num = 0;
13131314
struct esp108_apptrace_target_state target_state[ESP_APPTRACE_TARGETS_NUM_MAX];
1315+
struct esp_apptrace_cmd_data *cmd_data =(struct esp_apptrace_cmd_data *)ctx->cmd_priv;
13141316

13151317
// get current block id
13161318
int res = esp_apptrace_get_data_info(ctx, target_state, &fired_target_num);
@@ -1330,16 +1332,17 @@ static int esp_sysview_start(struct esp_apptrace_cmd_ctx *ctx)
13301332
LOG_ERROR("SEGGER: Failed to start tracing!");
13311333
return res;
13321334
}
1335+
cmd_data->sv_trace_running = 1;
13331336
return res;
13341337
}
13351338

13361339
static int esp_sysview_stop(struct esp_apptrace_cmd_ctx *ctx)
13371340
{
13381341
uint32_t old_block_id, fired_target_num = 0, empty_target_num = 0;
13391342
struct esp108_apptrace_target_state target_state[ESP_APPTRACE_TARGETS_NUM_MAX];
1343+
struct esp_apptrace_cmd_data *cmd_data =(struct esp_apptrace_cmd_data *)ctx->cmd_priv;
13401344
uint8_t cmds[] = {SEGGER_SYSVIEW_COMMAND_ID_STOP};
13411345
struct duration wait_time;
1342-
int last_blocks_num = 0;
13431346

13441347
struct esp_apptrace_block *block = esp_apptrace_free_block_get(ctx);
13451348
if (!block) {
@@ -1358,8 +1361,6 @@ static int esp_sysview_stop(struct esp_apptrace_cmd_ctx *ctx)
13581361
// in this case block_ids on both CPUs are equal, so the first one will be selected
13591362
for (int k = 0; k < ctx->cores_num; k++) {
13601363
if (target_state[k].data_len) {
1361-
// data_len = target_state[k].data_len;
1362-
// block_id = target_state[k].block_id;
13631364
fired_target_num = k;
13641365
break;
13651366
}
@@ -1400,21 +1401,20 @@ static int esp_sysview_stop(struct esp_apptrace_cmd_ctx *ctx)
14001401
}
14011402
// resume targets to allow command processing
14021403
LOG_INFO("Resume targets");
1403-
for (int k = 0; k < ctx->cores_num; k++) {
1404-
if (!ctx->esp32_target) {
1405-
res = target_resume(ctx->cpus[k], 1, 0, 1, 0);
1406-
if (res != ERROR_OK) {
1407-
LOG_ERROR("SEGGER: Failed to resume target '%s' (%d)!", target_name(ctx->cpus[k]), res);
1408-
return res;
1409-
}
1410-
}
1411-
}
14121404
if (ctx->esp32_target) {
14131405
res = target_resume(ctx->esp32_target, 1, 0, 1, 0);
14141406
if (res != ERROR_OK) {
14151407
LOG_ERROR("SEGGER: Failed to resume target '%s' (%d)!", target_name(ctx->esp32_target), res);
14161408
return res;
14171409
}
1410+
} else {
1411+
for (int k = 0; k < ctx->cores_num; k++) {
1412+
res = target_resume(ctx->cpus[k], 1, 0, 1, 0);
1413+
if (res != ERROR_OK) {
1414+
LOG_ERROR("SEGGER: Failed to resume target '%s' (%d)!", target_name(ctx->cpus[k]), res);
1415+
return res;
1416+
}
1417+
}
14181418
}
14191419
// wait for block switch (command sent), so we can disconnect from targets
14201420
old_block_id = target_state[fired_target_num].block_id;
@@ -1423,8 +1423,8 @@ static int esp_sysview_stop(struct esp_apptrace_cmd_ctx *ctx)
14231423
return ERROR_FAIL;
14241424
}
14251425
// we are waiting for the last data from TRAX block and also there can be data in the pended data buffer
1426-
// so we are expectign two TRX block switches at most or stopping due to timeout
1427-
while (last_blocks_num < 2) {
1426+
// so we are expecting two TRX block switches at most or stopping due to timeout
1427+
while (cmd_data->sv_trace_running) {
14281428
res = esp_apptrace_get_data_info(ctx, target_state, &fired_target_num);
14291429
if (res != ERROR_OK) {
14301430
LOG_ERROR("SEGGER: Failed to read targets data info!");
@@ -1463,14 +1463,13 @@ static int esp_sysview_stop(struct esp_apptrace_cmd_ctx *ctx)
14631463
}
14641464
}
14651465
old_block_id = target_state[fired_target_num].block_id;
1466-
last_blocks_num++;
14671466
}
14681467
}
14691468
if (duration_measure(&wait_time) != 0) {
14701469
LOG_ERROR("Failed to start trace stop timeout measurement!");
14711470
return ERROR_FAIL;
14721471
}
1473-
if (duration_elapsed(&wait_time) >= 0.1) {
1472+
if (duration_elapsed(&wait_time) >= 0.5) {
14741473
LOG_INFO("Stop waiting for the last data due to timeout.");
14751474
break;
14761475
}
@@ -1845,6 +1844,9 @@ static int esp_sysview_process_data(struct esp_apptrace_cmd_ctx *ctx, int core_i
18451844
break;
18461845
}
18471846
}
1847+
if (event_id == SYSVIEW_EVTID_TRACE_STOP) {
1848+
cmd_data->sv_trace_running = 0;
1849+
}
18481850
ctx->tot_len += pkt_len;
18491851
processed += pkt_len;
18501852
}

0 commit comments

Comments
 (0)