FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
|
API to handle a real-time timer. More...
#include <fastarduino/realtime_timer.h>
Public Types | |
using | RAW_TIME = RTTRawTime< TYPE > |
The adequate RTTRawTime type for this RTT . More... | |
Public Member Functions | |
RTT () | |
Construct a new real-time timer handler and initializes its current time to 0ms. More... | |
uint32_t | millis () const |
Elapsed time, in milliseconds, since this timer has started. More... | |
uint32_t | millis_ () const |
Elapsed time, in milliseconds, since this timer has started. More... | |
void | delay (uint32_t ms) const |
Delay program execution for the given amount of milliseconds. More... | |
uint16_t | micros () const |
Compute the microseconds part (from 0 to 999 ) of the time that has elapsed, since this timer has started. More... | |
uint16_t | micros_ () const |
Compute the microseconds part (from 0 to 999 ) of the time that has elapsed, since this timer has started. More... | |
time::RTTTime | time () const |
Elapsed time, in milliseconds and microseconds, since this timer has started. More... | |
time::RTTTime | time_ () const |
Elapsed time, in milliseconds and microseconds, since this timer has started. More... | |
RAW_TIME | raw_time () const |
Elapsed time, in raw representation, since this timer has started. More... | |
RAW_TIME | raw_time_ () const |
Elapsed time, in raw representation, since this timer has started. More... | |
void | millis (uint32_t ms) |
Reset the current milliseconds count of this RTT to the given value. More... | |
void | begin () |
Start this real-time timer, hence elapsed time starts getting counted from then. More... | |
void | begin_ () |
Start this real-time timer, hence elapsed time starts getting counted from then. More... | |
void | end () |
Stop this real-time timer, hence time gets not counted anymore. More... | |
void | end_ () |
Stop this real-time timer, hence time gets not counted anymore. More... | |
Timer< NTIMER > & | timer () |
Get a reference to the underlying Timer of this RTT . More... | |
Static Public Attributes | |
static constexpr const board::Timer | NTIMER = NTIMER_ |
The AVR timer used by this RTT. More... | |
Friends | |
struct | isr_handler_rtt |
API to handle a real-time timer.
A real-time timer keeps track of time with micro-second precision. In order to perform properly, an appropriate ISR must be registered for it.
A real-time timer can be used to:
NTIMER_ | the AVR timer used by this RTT |
Definition at line 205 of file realtime_timer.h.
using timer::RTT< NTIMER_ >::RAW_TIME = RTTRawTime<TYPE> |
The adequate RTTRawTime
type for this RTT
.
Definition at line 221 of file realtime_timer.h.
|
inline |
Construct a new real-time timer handler and initializes its current time to 0ms.
Note that this constructor does not start the timer.
Definition at line 230 of file realtime_timer.h.
|
inline |
Elapsed time, in milliseconds, since this timer has started.
If millis(uint32_t)
is called, this sets a new time reference point to count elapsed time from. If you want to get more precision about the elpased time, you can get the number of microsecond elapsed, in addition to millis()
, by calling micros()
. Note that this method is synchronized, i.e. it disables interrupts during its call and restores interrupts on return. If you do not need synchronization, then you should better use millis_()
instead.
Definition at line 251 of file realtime_timer.h.
|
inline |
Elapsed time, in milliseconds, since this timer has started.
If millis(uint32_t)
is called, this sets a new time reference point to count elapsed time from. If you want to get more precision about the elpased time, you can get the number of microsecond elapsed, in addition to millis()
, by calling micros()
. Note that this method is not synchronized, hence you should ensure it is called only while interrupts are not enabled. If you need synchronization, then you should better use millis()
instead.
Definition at line 272 of file realtime_timer.h.
|
inline |
Delay program execution for the given amount of milliseconds.
Contrarily to time::delay_ms()
, this method does not perform a busy loop, but it calls time::yield()
which will put the MCU in sleep mode but will be awakened every ms (by a timer interrupt) and check if required delay has elapsed already.
ms | the number of milliseconds to hold program execution |
Definition at line 287 of file realtime_timer.h.
|
inline |
Compute the microseconds part (from 0
to 999
) of the time that has elapsed, since this timer has started.
The milliseconds part is provided by millis()
. In general, you will not call this method unless you are sure the elapsed time is strictly less than 1ms. If you need the elapsed time with microsecond precision, then you should call time()
which returns an time::RTTTime
structure that contains both milliseconds and microseconds. Note that this method is synchronized, i.e. it disables interrupts during its call and restores interrupts on return. If you do not need synchronization, then you should better use micros_()
instead.
Definition at line 311 of file realtime_timer.h.
|
inline |
Compute the microseconds part (from 0
to 999
) of the time that has elapsed, since this timer has started.
The milliseconds part is provided by millis()
. In general, you will not call this method unless you are sure the elapsed time is strictly less than 1ms. If you need the elapsed time with microsecond precision, then you should call time()
which returns an time::RTTTime
structure that contains both milliseconds and microseconds. Note that this method is not synchronized, hence you should ensure it is called only while interrupts are not enabled. If you need synchronization, then you should better use micros()
instead.
Definition at line 334 of file realtime_timer.h.
|
inline |
Elapsed time, in milliseconds and microseconds, since this timer has started.
If you do not need microsecond precision, you should instead use millis()
. Note that this method is synchronized, i.e. it disables interrupts during its call and restores interrupts on return. If you do not need synchronization, then you should better use time_()
instead.
Definition at line 353 of file realtime_timer.h.
|
inline |
Elapsed time, in milliseconds and microseconds, since this timer has started.
If you do not need microsecond precision, you should instead use millis()
. Note that this method is not synchronized, hence you should ensure it is called only while interrupts are not enabled. If you need synchronization, then you should better use time()
instead.
Definition at line 372 of file realtime_timer.h.
|
inline |
Elapsed time, in raw representation, since this timer has started.
This method is a fast substitute for time()
; instead of returning a time::RTTTime
which takes longer to instantiate, it returns a simpler, faster RTTRawTime
which contains the same information but unprocessed yet. Note that this method is synchronized, i.e. it disables interrupts during its call and restores interrupts on return. If you do not need synchronization, then you should better use raw_time_()
instead.
Definition at line 393 of file realtime_timer.h.
|
inline |
Elapsed time, in raw representation, since this timer has started.
This method is a fast substitute for time_()
; instead of returning a time::RTTTime
which takes longer to instantiate, it returns a simpler, faster RTTRawTime
which contains the same information but unprocessed yet. Note that this method is not synchronized, hence you should ensure it is called only while interrupts are not enabled. If you need synchronization, then you should better use raw_time()
instead.
Definition at line 414 of file realtime_timer.h.
|
inline |
Reset the current milliseconds count of this RTT to the given value.
Evey elapsed millisecond will then be added to this new value.
ms | the new millisecond start |
Definition at line 424 of file realtime_timer.h.
|
inline |
Start this real-time timer, hence elapsed time starts getting counted from then.
Note that this method is synchronized, i.e. it disables interrupts during its call and restores interrupts on return. If you do not need synchronization, then you should better use begin_()
instead.
Definition at line 444 of file realtime_timer.h.
|
inline |
Start this real-time timer, hence elapsed time starts getting counted from then.
Note that this method is not synchronized, hence you should ensure it is called only while interrupts are not enabled. If you need synchronization, then you should better use begin()
instead.
Definition at line 459 of file realtime_timer.h.
|
inline |
Stop this real-time timer, hence time gets not counted anymore.
Note that this method is synchronized, i.e. it disables interrupts during its call and restores interrupts on return. If you do not need synchronization, then you should better use end_()
instead.
Definition at line 474 of file realtime_timer.h.
|
inline |
Stop this real-time timer, hence time gets not counted anymore.
Note that this method is synchronized, i.e. it disables interrupts during its call and restores interrupts on return. Note that this method is not synchronized, hence you should ensure it is called only while interrupts are not enabled. If you need synchronization, then you should better use end()
instead.
Definition at line 490 of file realtime_timer.h.
|
inline |
Get a reference to the underlying Timer
of this RTT
.
Definition at line 498 of file realtime_timer.h.
|
friend |
Definition at line 520 of file realtime_timer.h.
|
staticconstexpr |
The AVR timer used by this RTT.
Definition at line 209 of file realtime_timer.h.