EtcPal
HEAD (unstable)
ETC Platform Abstraction Layer (EtcPal)
|
View other versions:
|
Platform-neutral system timers.
WARNING: This module must be explicitly initialized before use. Initialize the module by calling etcpal_init() with the relevant feature mask:
Provides an implementation of a passive monotonic timer, as well as a way to get monotonic time points. Time points and intervals are represented in milliseconds by a 32-bit unsigned int. To get a time point, use etcpal_getms().
A time point represents the time elapsed in milliseconds since an arbitrary fixed point in the past, independent of any changes in system "wall clock" time. Time points provided by this module wrap every 4,294,967,295 milliseconds, or approximately 49.7 days. Because of this, it's recommended to only use this module to time events which occur on time scales which are shorter than that by at least an order of magnitude. This reduces the likelihood that wrapping will be an issue.
Note that this problem only applies to wraparound past an original time point; absolute wraparound of the integer type is handled. For example, using an EtcPalTimer to time a 10-millisecond interval that begins at time point 4,294,967,290 and ends at time point 5 will work as expected.
Use the ETCPAL_TIME_ELAPSED_SINCE() macro to determine how much time has elapsed since a time point.
To time an interval, use an EtcPalTimer.
Data Structures | |
struct | EtcPalTimer |
A millisecond-resolution timer. More... | |
Macros | |
#define | ETCPAL_TIME_ELAPSED_SINCE(start_time) (uint32_t)(etcpal_getms() - (uint32_t)start_time) |
Get the amount of time elapsed since the given time point in milliseconds. More... | |
Typedefs | |
typedef struct EtcPalTimer | EtcPalTimer |
A millisecond-resolution timer. More... | |
Functions | |
uint32_t | etcpal_getms (void) |
Get a monotonically-increasing millisecond value. More... | |
void | etcpal_timer_start (EtcPalTimer *timer, uint32_t interval) |
Start a timer. More... | |
void | etcpal_timer_reset (EtcPalTimer *timer) |
Reset a timer while keeping the same interval. More... | |
uint32_t | etcpal_timer_elapsed (const EtcPalTimer *timer) |
Get the time since a timer was reset. More... | |
bool | etcpal_timer_is_expired (const EtcPalTimer *timer) |
Check to see if a timer is expired. More... | |
uint32_t | etcpal_timer_remaining (const EtcPalTimer *timer) |
Get the amount of time remaining in a timer. More... | |
#define ETCPAL_TIME_ELAPSED_SINCE | ( | start_time | ) | (uint32_t)(etcpal_getms() - (uint32_t)start_time) |
Get the amount of time elapsed since the given time point in milliseconds.
start_time | (uint32_t) The start time to measure against. |
typedef struct EtcPalTimer EtcPalTimer |
A millisecond-resolution timer.
The times are represented in milliseconds by a 32-bit unsigned integer. Since the timer is monotonically-increasing, wraparound is handled by doing comparisons of the form
rather than
.
uint32_t etcpal_getms | ( | void | ) |
Get a monotonically-increasing millisecond value.
uint32_t etcpal_timer_elapsed | ( | const EtcPalTimer * | timer | ) |
Get the time since a timer was reset.
timer | Pointer to the EtcPalTimer of which to get the elapsed time. |
bool etcpal_timer_is_expired | ( | const EtcPalTimer * | timer | ) |
Check to see if a timer is expired.
timer | Pointer to the EtcPalTimer of which to check the expiration. |
uint32_t etcpal_timer_remaining | ( | const EtcPalTimer * | timer | ) |
Get the amount of time remaining in a timer.
timer | Pointer to the EtcPalTimer of which to get the remaining time. |
void etcpal_timer_reset | ( | EtcPalTimer * | timer | ) |
Reset a timer while keeping the same interval.
timer | Pointer to the EtcPalTimer to reset. |
void etcpal_timer_start | ( | EtcPalTimer * | timer, |
uint32_t | interval | ||
) |
Start a timer.
timer | Pointer to the EtcPalTimer to start. |
interval | Timer interval in milliseconds. An interval of 0 will result in a timer that is always expired. |