20 #include "platform/platform.h" 21 #include "drivers/TickerDataClock.h" 22 #include "platform/NonCopyable.h" 26 class CriticalSectionLock;
78 MBED_DEPRECATED_SINCE(
"mbed-os-6.0.0",
"Floating point operators should normally be avoided for code size. If really needed, you can use `duration<float>{elapsed_time()}.count()`")
85 MBED_DEPRECATED_SINCE("
mbed-os-6.0.0", "Use the Chrono-based elapsed_time method. If integer milliseconds are needed, you can use `duration_cast<milliseconds>(elapsed_time()).count()`")
92 MBED_DEPRECATED_SINCE("
mbed-os-6.0.0", "Use the Chrono-based elapsed_time method. If integer microseconds are needed, you can use `elapsed_time().count()`")
97 MBED_DEPRECATED_SINCE("
mbed-os-6.0.0", "Floating point operators should normally be avoided for code size. If really needed, you can use `duration<
float>{elapsed_time()}.count()`
") 98 operator float() const; 103 MBED_DEPRECATED_SINCE("
mbed-os-6.0.0
", "Use the Chrono-based elapsed_time method. If integer microseconds are needed, you can use `elapsed_time().count()`
") 104 us_timestamp_t read_high_resolution_us() const; 109 std::chrono::microseconds elapsed_time() const;
111 #if !defined(DOXYGEN_ONLY)
113 TimerBase(const ticker_data_t *data);
114 TimerBase(const ticker_data_t *data, bool lock_deepsleep);
115 TimerBase(const TimerBase &t);
116 TimerBase(TimerBase &&t);
119 const TimerBase &operator=(const TimerBase &) = delete;
121 std::chrono::microseconds slicetime() const;
122 TickerDataClock::time_point _start{}; // the start time of the latest slice
123 std::chrono::microseconds _time{}; // any accumulated time from previous slices
124 TickerDataClock _ticker_data;
125 bool _lock_deepsleep; // flag that indicates if deep sleep should be disabled
126 bool _running = false; // whether the timer is running
129 // Copy storage while a lock is held
130 TimerBase(const TimerBase &t, const CriticalSectionLock &) : TimerBase(t, false) {}
131 // Copy storage only - used by delegating constructors
132 TimerBase(const TimerBase &t, bool) : _start(t._start), _time(t._time), _ticker_data(t._ticker_data), _lock_deepsleep(t._lock_deepsleep), _running(t._running) {}
136 class Timer : public TimerBase {