224
224
#define ESP_APPTRACE_BLOCK_ID_MSK 0x7FUL
225
225
#define ESP_APPTRACE_BLOCK_ID (_id_ ) (((_id_) & ESP_APPTRACE_BLOCK_ID_MSK) << 15)
226
226
#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
227
228
#define ESP_APPTRACE_HOST_DATA (1 << 22)
228
229
#define ESP_APPTRACE_HOST_CONNECT (1 << 23)
229
230
@@ -388,6 +389,7 @@ struct esp_apptrace_cmd_ctx {
388
389
struct target * esp32_target ;
389
390
struct target * cpus [ESP_APPTRACE_TARGETS_NUM_MAX ];
390
391
int cores_num ;
392
+ uint32_t last_blk_id ;
391
393
pthread_mutex_t trax_blocks_mux ;
392
394
struct hlist_head free_trax_blocks ;
393
395
struct hlist_head ready_trax_blocks ;
@@ -1054,6 +1056,7 @@ static int esp_apptrace_cmd_cleanup(struct esp_apptrace_cmd_ctx *cmd_ctx)
1054
1056
esp_apptrace_dest_cleanup (cmd_data -> data_dests , cmd_ctx -> cores_num );
1055
1057
free (cmd_data );
1056
1058
esp_apptrace_cmd_ctx_cleanup (cmd_ctx );
1059
+ memset (cmd_ctx , 0 , sizeof (* cmd_ctx ));
1057
1060
return ERROR_OK ;
1058
1061
}
1059
1062
@@ -1941,6 +1944,28 @@ static int esp_apptrace_poll(void *priv)
1941
1944
return res ;
1942
1945
}
1943
1946
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
+ }
1944
1969
if (ctx -> stop_tmo != -1.0 ) {
1945
1970
if (duration_measure (& ctx -> idle_time ) != 0 ) {
1946
1971
ctx -> running = 0 ;
@@ -1990,6 +2015,7 @@ static int esp_apptrace_poll(void *priv)
1990
2015
LOG_ERROR ("Failed to read data on (%s)!" , target_name (ctx -> cpus [fired_target_num ]));
1991
2016
return res ;
1992
2017
}
2018
+ ctx -> last_blk_id = target_state [fired_target_num ].block_id ;
1993
2019
#if ESP_APPTRACE_TIME_STATS_ENABLE
1994
2020
if (duration_measure (& blk_proc_time ) != 0 ) {
1995
2021
ctx -> running = 0 ;
@@ -2010,14 +2036,14 @@ static int esp_apptrace_poll(void *priv)
2010
2036
}
2011
2037
#endif
2012
2038
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 ,
2014
2040
0 /*all read*/ , 1 /*host connected*/ , 0 /*no host data*/ );
2015
2041
if (res != ERROR_OK ) {
2016
2042
ctx -> running = 0 ;
2017
2043
LOG_ERROR ("Failed to ack data on (%s)!" , target_name (ctx -> cpus [fired_target_num ? 0 : 1 ]));
2018
2044
return res ;
2019
2045
}
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 ]));
2021
2047
}
2022
2048
ctx -> raw_tot_len += target_state [fired_target_num ].data_len ;
2023
2049
@@ -2186,18 +2212,20 @@ int esp_cmd_apptrace_generic(struct target *target, int mode, const char **argv,
2186
2212
}
2187
2213
}
2188
2214
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 ) ;
2200
2226
}
2227
+ // signal thread to stop
2228
+ s_at_cmd_ctx .running = 0 ;
2201
2229
res = target_unregister_timer_callback (esp_apptrace_poll , & s_at_cmd_ctx );
2202
2230
if (res != ERROR_OK ) {
2203
2231
LOG_ERROR ("Failed to unregister target timer handler (%d)!" , res );
0 commit comments