Skip to content

Commit c3d8215

Browse files
committed
sysview: fix compilation in 1 core mode, refactor timer choices
Changes related to DFS have broken compilation of sysview code in 1 core mode. This change fixes this, and moves choice of the timer used for timestamp into Kconfig. CCOUNT timer is only available as an option if 1 core mode is used. esp_timer is added as a new option, and is the only available option if DFS is enabled.
1 parent 1c3dd23 commit c3d8215

File tree

2 files changed

+80
-52
lines changed

2 files changed

+80
-52
lines changed

components/app_trace/Kconfig

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,33 +64,37 @@ config SYSVIEW_ENABLE
6464
Enables supporrt for SEGGER SystemView tracing functionality.
6565

6666
choice SYSVIEW_TS_SOURCE
67-
prompt "ESP32 timer to use as SystemView timestamp source"
67+
prompt "Timer to use as timestamp source"
6868
depends on SYSVIEW_ENABLE
69-
default SYSVIEW_TS_SOURCE_TIMER_00
69+
default SYSVIEW_TS_SOURCE_CCOUNT if FREERTOS_UNICORE && !PM_ENABLE
70+
default SYSVIEW_TS_SOURCE_TIMER_00 if !FREERTOS_UNICORE && !PM_ENABLE
71+
default SYSVIEW_TS_SOURCE_ESP_TIMER if PM_ENABLE
7072
help
7173
SystemView needs to use a hardware timer as the source of timestamps
72-
when tracing
73-
This option selects HW timer for it.
74+
when tracing. This option selects the timer for it.
75+
76+
config SYSVIEW_TS_SOURCE_CCOUNT
77+
bool "CPU cycle counter (CCOUNT)"
78+
depends on FREERTOS_UNICORE && !PM_ENABLE
7479

7580
config SYSVIEW_TS_SOURCE_TIMER_00
7681
bool "Timer 0, Group 0"
77-
help
78-
Select this to use timer 0 of group 0
82+
depends on !PM_ENABLE
7983

8084
config SYSVIEW_TS_SOURCE_TIMER_01
8185
bool "Timer 1, Group 0"
82-
help
83-
Select this to use timer 1 of group 0
86+
depends on !PM_ENABLE
8487

8588
config SYSVIEW_TS_SOURCE_TIMER_10
8689
bool "Timer 0, Group 1"
87-
help
88-
Select this to use timer 0 of group 1
90+
depends on !PM_ENABLE
8991

9092
config SYSVIEW_TS_SOURCE_TIMER_11
9193
bool "Timer 1, Group 1"
92-
help
93-
Select this to use timer 1 of group 1
94+
depends on !PM_ENABLE
95+
96+
config SYSVIEW_TS_SOURCE_ESP_TIMER
97+
bool "esp_timer high resolution timer"
9498

9599
endchoice
96100

components/app_trace/sys_view/Sample/Config/SEGGER_SYSVIEW_Config_FreeRTOS.c

Lines changed: 64 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ Revision: $Rev: 3734 $
6464
#include "freertos/FreeRTOS.h"
6565
#include "SEGGER_SYSVIEW.h"
6666
#include "rom/ets_sys.h"
67-
#if CONFIG_FREERTOS_UNICORE == 0
68-
#include "driver/timer.h"
69-
#endif
7067
#include "esp_app_trace.h"
7168
#include "esp_app_trace_util.h"
7269
#include "esp_intr_alloc.h"
@@ -86,10 +83,49 @@ extern const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI;
8683
// The target device name
8784
#define SYSVIEW_DEVICE_NAME "ESP32"
8885

86+
// Determine which timer to use as timestamp source
87+
#if CONFIG_SYSVIEW_TS_SOURCE_CCOUNT
88+
#define TS_USE_CCOUNT 1
89+
#elif CONFIG_SYSVIEW_TS_SOURCE_ESP_TIMER
90+
#define TS_USE_ESP_TIMER 1
91+
#else
92+
#define TS_USE_TIMERGROUP 1
93+
#endif
94+
95+
#if TS_USE_TIMERGROUP
96+
#include "driver/timer.h"
97+
8998
// Timer group timer divisor
9099
#define SYSVIEW_TIMER_DIV 2
100+
91101
// Frequency of the timestamp.
92102
#define SYSVIEW_TIMESTAMP_FREQ (esp_clk_apb_freq() / SYSVIEW_TIMER_DIV)
103+
104+
// Timer ID and group ID
105+
#if defined(CONFIG_SYSVIEW_TS_SOURCE_TIMER_00) || defined(CONFIG_SYSVIEW_TS_SOURCE_TIMER_01)
106+
#define TS_TIMER_ID 0
107+
#else
108+
#define TS_TIMER_ID 1
109+
#endif // TIMER_00 || TIMER_01
110+
111+
#if defined(CONFIG_SYSVIEW_TS_SOURCE_TIMER_00) || defined(CONFIG_SYSVIEW_TS_SOURCE_TIMER_10)
112+
#define TS_TIMER_GROUP 0
113+
#else
114+
#define TS_TIMER_GROUP 1
115+
#endif // TIMER_00 || TIMER_10
116+
117+
#endif // TS_USE_TIMERGROUP
118+
119+
#if TS_USE_ESP_TIMER
120+
// esp_timer provides 1us resolution
121+
#define SYSVIEW_TIMESTAMP_FREQ (1000000)
122+
#endif // TS_USE_ESP_TIMER
123+
124+
#if TS_USE_CCOUNT
125+
// CCOUNT is incremented at CPU frequency
126+
#define SYSVIEW_TIMESTAMP_FREQ (CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ * 1000000)
127+
#endif // TS_USE_CCOUNT
128+
93129
// System Frequency.
94130
#define SYSVIEW_CPU_FREQ (esp_clk_cpu_freq())
95131

@@ -103,11 +139,8 @@ extern const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI;
103139
#define SYSTICK_INTR_ID (ETS_INTERNAL_TIMER1_INTR_SOURCE+ETS_INTERNAL_INTR_SOURCE_OFF)
104140
#endif
105141

106-
static timer_idx_t s_ts_timer_idx;
107-
static timer_group_t s_ts_timer_group;
108-
109142
// SystemView is single core specific: it implies that SEGGER_SYSVIEW_LOCK()
110-
// disables IRQs (disables rescheduling globaly). So we can not use finite timeouts for locks and return error
143+
// disables IRQs (disables rescheduling globally). So we can not use finite timeouts for locks and return error
111144
// in case of expiration, because error will not be handled and SEGGER's code will go further implying that
112145
// everything is fine, so for multi-core env we have to wait on underlying lock forever
113146
#define SEGGER_LOCK_WAIT_TMO ESP_APPTRACE_TMO_INFINITE
@@ -213,35 +246,24 @@ static void _cbSendSystemDesc(void) {
213246
*/
214247
static void SEGGER_SYSVIEW_TS_Init()
215248
{
216-
timer_config_t config;
217-
218-
#if CONFIG_SYSVIEW_TS_SOURCE_TIMER_00
219-
s_ts_timer_group = TIMER_GROUP_0;
220-
s_ts_timer_idx = TIMER_0;
221-
#endif
222-
#if CONFIG_SYSVIEW_TS_SOURCE_TIMER_01
223-
s_ts_timer_group = TIMER_GROUP_0;
224-
s_ts_timer_idx = TIMER_1;
225-
#endif
226-
#if CONFIG_SYSVIEW_TS_SOURCE_TIMER_10
227-
s_ts_timer_group = TIMER_GROUP_1;
228-
s_ts_timer_idx = TIMER_0;
229-
#endif
230-
#if CONFIG_SYSVIEW_TS_SOURCE_TIMER_11
231-
s_ts_timer_group = TIMER_GROUP_1;
232-
s_ts_timer_idx = TIMER_1;
233-
#endif
234-
config.alarm_en = 0;
235-
config.auto_reload = 0;
236-
config.counter_dir = TIMER_COUNT_UP;
237-
config.divider = SYSVIEW_TIMER_DIV;
238-
config.counter_en = 0;
239-
/*Configure timer*/
240-
timer_init(s_ts_timer_group, s_ts_timer_idx, &config);
241-
/*Load counter value */
242-
timer_set_counter_value(s_ts_timer_group, s_ts_timer_idx, 0x00000000ULL);
243-
/*Enable timer interrupt*/
244-
timer_start(s_ts_timer_group, s_ts_timer_idx);
249+
/* We only need to initialize something if we use Timer Group.
250+
* esp_timer and ccount can be used as is.
251+
*/
252+
#if TS_USE_TIMERGROUP
253+
timer_config_t config = {
254+
.alarm_en = 0,
255+
.auto_reload = 0,
256+
.counter_dir = TIMER_COUNT_UP,
257+
.divider = SYSVIEW_TIMER_DIV,
258+
.counter_en = 0
259+
};
260+
/* Configure timer */
261+
timer_init(TS_TIMER_GROUP, TS_TIMER_ID, &config);
262+
/* Load counter value */
263+
timer_set_counter_value(TS_TIMER_GROUP, TS_TIMER_ID, 0x00000000ULL);
264+
/* Start counting */
265+
timer_start(TS_TIMER_GROUP, TS_TIMER_ID);
266+
#endif // TS_USE_TIMERGROUP
245267
}
246268

247269
void SEGGER_SYSVIEW_Conf(void) {
@@ -296,12 +318,14 @@ void SEGGER_SYSVIEW_Conf(void) {
296318

297319
U32 SEGGER_SYSVIEW_X_GetTimestamp()
298320
{
299-
#if CONFIG_FREERTOS_UNICORE == 0
321+
#if TS_USE_TIMERGROUP
300322
uint64_t ts = 0;
301-
timer_get_counter_value(s_ts_timer_group, s_ts_timer_idx, &ts);
302-
return (U32)ts; // return lower part of counter value
303-
#else
323+
timer_get_counter_value(TS_TIMER_GROUP, TS_TIMER_ID, &ts);
324+
return (U32) ts; // return lower part of counter value
325+
#elif TS_USE_CCOUNT
304326
return portGET_RUN_TIME_COUNTER_VALUE();
327+
#elif TS_USE_ESP_TIMER
328+
return (U32) esp_timer_get_time(); // return lower part of counter value
305329
#endif
306330
}
307331

0 commit comments

Comments
 (0)