File tree Expand file tree Collapse file tree 2 files changed +12
-11
lines changed Expand file tree Collapse file tree 2 files changed +12
-11
lines changed Original file line number Diff line number Diff line change @@ -45,30 +45,27 @@ void Timer::stop() {
45
45
}
46
46
47
47
int Timer::read_us () {
48
- core_util_critical_section_enter ();
49
- us_timestamp_t time = _time + slicetime ();
50
- core_util_critical_section_exit ();
51
- return time;
48
+ return read_high_resolution_us ();
52
49
}
53
50
54
51
float Timer::read () {
55
- core_util_critical_section_enter ();
56
- us_timestamp_t time = _time + slicetime ();
57
- core_util_critical_section_exit ();
58
- time = time / 1000 ;
59
- return (float )read_ms () / 1000 .0f ;
52
+ return (float )read_us () / 1000000 .0f ;
60
53
}
61
54
62
55
int Timer::read_ms () {
56
+ return read_high_resolution_us () / 1000 ;
57
+ }
58
+
59
+ us_timestamp_t Timer::read_high_resolution_us () {
63
60
core_util_critical_section_enter ();
64
61
us_timestamp_t time = _time + slicetime ();
65
62
core_util_critical_section_exit ();
66
- return time / 1000 ;
63
+ return time;
67
64
}
68
65
69
66
us_timestamp_t Timer::slicetime () {
70
- core_util_critical_section_enter ();
71
67
us_timestamp_t ret = 0 ;
68
+ core_util_critical_section_enter ();
72
69
if (_running) {
73
70
ret = ticker_read_us (_ticker_data) - _start;
74
71
}
Original file line number Diff line number Diff line change @@ -82,6 +82,10 @@ class Timer {
82
82
*/
83
83
operator float ();
84
84
85
+ /* * Get in a high resolution type the time passed in micro-seconds.
86
+ */
87
+ us_timestamp_t read_high_resolution_us ();
88
+
85
89
protected:
86
90
us_timestamp_t slicetime ();
87
91
int _running; // whether the timer is running
You can’t perform that action at this time.
0 commit comments