Skip to content

Commit 4f45efa

Browse files
committed
esp108/apptrace: Fixes data block acknowledgement in dual core mode
Fixes data block acknowledgement in dual core mode after host data are read by target and there is no data are sent from target to host.
1 parent 5e8a378 commit 4f45efa

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

src/target/esp108_apptrace.c

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@
224224
#define ESP_APPTRACE_BLOCK_ID_MSK 0x7FUL
225225
#define ESP_APPTRACE_BLOCK_ID(_id_) (((_id_) & ESP_APPTRACE_BLOCK_ID_MSK) << 15)
226226
#define ESP_APPTRACE_BLOCK_ID_GET(_v_) (((_v_) >> 15) & ESP_APPTRACE_BLOCK_ID_MSK)
227+
#define ESP_APPTRACE_BLOCK_ID_MAX ESP_APPTRACE_BLOCK_ID_MSK
227228
#define ESP_APPTRACE_HOST_DATA (1 << 22)
228229
#define ESP_APPTRACE_HOST_CONNECT (1 << 23)
229230

@@ -388,6 +389,7 @@ struct esp_apptrace_cmd_ctx {
388389
struct target * esp32_target;
389390
struct target * cpus[ESP_APPTRACE_TARGETS_NUM_MAX];
390391
int cores_num;
392+
uint32_t last_blk_id;
391393
pthread_mutex_t trax_blocks_mux;
392394
struct hlist_head free_trax_blocks;
393395
struct hlist_head ready_trax_blocks;
@@ -1054,6 +1056,7 @@ static int esp_apptrace_cmd_cleanup(struct esp_apptrace_cmd_ctx *cmd_ctx)
10541056
esp_apptrace_dest_cleanup(cmd_data->data_dests, cmd_ctx->cores_num);
10551057
free(cmd_data);
10561058
esp_apptrace_cmd_ctx_cleanup(cmd_ctx);
1059+
memset(cmd_ctx, 0, sizeof(*cmd_ctx));
10571060
return ERROR_OK;
10581061
}
10591062

@@ -1941,6 +1944,28 @@ static int esp_apptrace_poll(void *priv)
19411944
return res;
19421945
}
19431946
if (fired_target_num == (uint32_t)-1) {
1947+
// no data has been received, but block could be switched due to the data transfered from host to target
1948+
if (ctx->cores_num > 1) {
1949+
uint32_t max_block_id = 0;
1950+
for (int i = 0; i < ctx->cores_num; i++) {
1951+
if (max_block_id < target_state[i].block_id) {
1952+
max_block_id = target_state[i].block_id;
1953+
}
1954+
}
1955+
for (int i = 0; i < ctx->cores_num; i++) {
1956+
if (max_block_id != target_state[i].block_id) {
1957+
LOG_DEBUG("Ack empty block %d on target (%s)!", max_block_id, target_name(ctx->cpus[i]));
1958+
res = esp108_apptrace_write_ctrl_reg(ctx->cpus[i], max_block_id,
1959+
0/*all read*/, 1/*host connected*/, 0/*no host data*/);
1960+
if (res != ERROR_OK) {
1961+
ctx->running = 0;
1962+
LOG_ERROR("Failed to ack empty data block on (%s)!", target_name(ctx->cpus[i]));
1963+
return res;
1964+
}
1965+
}
1966+
}
1967+
ctx->last_blk_id = max_block_id;
1968+
}
19441969
if (ctx->stop_tmo != -1.0) {
19451970
if (duration_measure(&ctx->idle_time) != 0) {
19461971
ctx->running = 0;
@@ -1990,6 +2015,7 @@ static int esp_apptrace_poll(void *priv)
19902015
LOG_ERROR("Failed to read data on (%s)!", target_name(ctx->cpus[fired_target_num]));
19912016
return res;
19922017
}
2018+
ctx->last_blk_id = target_state[fired_target_num].block_id;
19932019
#if ESP_APPTRACE_TIME_STATS_ENABLE
19942020
if (duration_measure(&blk_proc_time) != 0) {
19952021
ctx->running = 0;
@@ -2010,14 +2036,14 @@ static int esp_apptrace_poll(void *priv)
20102036
}
20112037
#endif
20122038
if (ctx->cores_num > 1) {
2013-
res = esp108_apptrace_write_ctrl_reg(ctx->cpus[fired_target_num ? 0 : 1], target_state[fired_target_num].block_id,
2039+
res = esp108_apptrace_write_ctrl_reg(ctx->cpus[fired_target_num ? 0 : 1], ctx->last_blk_id,
20142040
0/*all read*/, 1/*host connected*/, 0/*no host data*/);
20152041
if (res != ERROR_OK) {
20162042
ctx->running = 0;
20172043
LOG_ERROR("Failed to ack data on (%s)!", target_name(ctx->cpus[fired_target_num ? 0 : 1]));
20182044
return res;
20192045
}
2020-
LOG_DEBUG("Ack block %d target (%s)!", target_state[fired_target_num].block_id, target_name(ctx->cpus[fired_target_num ? 0 : 1]));
2046+
LOG_DEBUG("Ack block %d target (%s)!", ctx->last_blk_id, target_name(ctx->cpus[fired_target_num ? 0 : 1]));
20212047
}
20222048
ctx->raw_tot_len += target_state[fired_target_num].data_len;
20232049

@@ -2186,18 +2212,20 @@ int esp_cmd_apptrace_generic(struct target *target, int mode, const char **argv,
21862212
}
21872213
}
21882214
else if (strcmp(argv[0], "stop") == 0) {
2189-
if (s_at_cmd_ctx.running) {
2190-
if (duration_measure(&s_at_cmd_ctx.read_time) != 0) {
2191-
LOG_ERROR("Failed to stop trace read time measurement!");
2192-
}
2193-
// data processor is alive, so wait for all received blocks to be processed
2194-
res = esp_apptrace_wait_pended_blocks(&s_at_cmd_ctx);
2195-
if (res != ERROR_OK) {
2196-
LOG_ERROR("Failed to wait for pended blocks (%d)!", res);
2197-
}
2198-
// signal thread to stop
2199-
s_at_cmd_ctx.running = 0;
2215+
if (!s_at_cmd_ctx.running) {
2216+
LOG_WARNING("Tracing is not running!");
2217+
return ERROR_FAIL;
2218+
}
2219+
if (duration_measure(&s_at_cmd_ctx.read_time) != 0) {
2220+
LOG_ERROR("Failed to stop trace read time measurement!");
2221+
}
2222+
// data processor is alive, so wait for all received blocks to be processed
2223+
res = esp_apptrace_wait_pended_blocks(&s_at_cmd_ctx);
2224+
if (res != ERROR_OK) {
2225+
LOG_ERROR("Failed to wait for pended blocks (%d)!", res);
22002226
}
2227+
// signal thread to stop
2228+
s_at_cmd_ctx.running = 0;
22012229
res = target_unregister_timer_callback(esp_apptrace_poll, &s_at_cmd_ctx);
22022230
if (res != ERROR_OK) {
22032231
LOG_ERROR("Failed to unregister target timer handler (%d)!", res);

0 commit comments

Comments
 (0)