Firmware
|
High-resolution timer with callouts and timekeeping. More...
#include <sys/ioctl.h>
#include <sys/types.h>
#include <stdbool.h>
#include <inttypes.h>
#include <px4_time.h>
#include <queue.h>
Go to the source code of this file.
Classes | |
struct | hrt_call |
Callout record. More... | |
Typedefs | |
typedef void(* | hrt_callout) (void *arg) |
Callout function type. More... | |
typedef struct hrt_call * | hrt_call_t |
Callout record. | |
Functions | |
__EXPORT hrt_abstime | hrt_absolute_time (void) |
Get absolute time in [us] (does not wrap). | |
__EXPORT hrt_abstime | ts_to_abstime (const struct timespec *ts) |
Convert a timespec to absolute time. | |
__EXPORT void | abstime_to_ts (struct timespec *ts, hrt_abstime abstime) |
Convert absolute time to a timespec. | |
__EXPORT hrt_abstime | hrt_elapsed_time_atomic (const volatile hrt_abstime *then) |
Compute the delta between a timestamp taken in the past and now. More... | |
__EXPORT hrt_abstime | hrt_store_absolute_time (volatile hrt_abstime *now) |
Store the absolute time in an interrupt-safe fashion. More... | |
__EXPORT void | hrt_call_after (struct hrt_call *entry, hrt_abstime delay, hrt_callout callout, void *arg) |
Call callout(arg) after delay has elapsed. More... | |
__EXPORT void | hrt_call_at (struct hrt_call *entry, hrt_abstime calltime, hrt_callout callout, void *arg) |
Call callout(arg) at absolute time calltime. | |
__EXPORT void | hrt_call_every (struct hrt_call *entry, hrt_abstime delay, hrt_abstime interval, hrt_callout callout, void *arg) |
Call callout(arg) after delay, and then after every interval. More... | |
__EXPORT bool | hrt_called (struct hrt_call *entry) |
If this returns true, the entry has been invoked and removed from the callout list, or it has never been entered. More... | |
__EXPORT void | hrt_cancel (struct hrt_call *entry) |
Remove the entry from the callout list. | |
__EXPORT void | hrt_call_init (struct hrt_call *entry) |
Initialise a hrt_call structure. | |
__EXPORT void | hrt_call_delay (struct hrt_call *entry, hrt_abstime delay) |
__EXPORT void | hrt_init (void) |
Variables | |
__BEGIN_DECLS typedef uint64_t | hrt_abstime |
Absolute time, in microsecond units. More... | |
High-resolution timer with callouts and timekeeping.
typedef void(* hrt_callout) (void *arg) |
Callout function type.
Note that callouts run in the timer interrupt context, so they are serialised with respect to each other, and must not block.
__EXPORT void hrt_call_after | ( | struct hrt_call * | entry, |
hrt_abstime | delay, | ||
hrt_callout | callout, | ||
void * | arg | ||
) |
Call callout(arg) after delay has elapsed.
If callout is NULL, this can be used to implement a timeout by testing the call with hrt_called().
__EXPORT void hrt_call_every | ( | struct hrt_call * | entry, |
hrt_abstime | delay, | ||
hrt_abstime | interval, | ||
hrt_callout | callout, | ||
void * | arg | ||
) |
Call callout(arg) after delay, and then after every interval.
Note thet the interval is timed between scheduled, not actual, call times, so the call rate may jitter but should not drift.
__EXPORT bool hrt_called | ( | struct hrt_call * | entry | ) |
If this returns true, the entry has been invoked and removed from the callout list, or it has never been entered.
Always returns false for repeating callouts.
__EXPORT hrt_abstime hrt_elapsed_time_atomic | ( | const volatile hrt_abstime * | then | ) |
Compute the delta between a timestamp taken in the past and now.
This function is safe to use even if the timestamp is updated by an interrupt during execution.
__EXPORT hrt_abstime hrt_store_absolute_time | ( | volatile hrt_abstime * | now | ) |
Store the absolute time in an interrupt-safe fashion.
This function ensures that the timestamp cannot be seen half-written by an interrupt handler.
__BEGIN_DECLS typedef uint64_t hrt_abstime |
Absolute time, in microsecond units.
Absolute time is measured from some arbitrary epoch shortly after system startup. It should never wrap or go backwards.