Firmware
Functions
drv_hrt.cpp File Reference

High-resolution timer with callouts and timekeeping. More...

#include <px4_time.h>
#include <px4_posix.h>
#include <px4_defines.h>
#include <px4_workqueue.h>
#include <px4_tasks.h>
#include <drivers/drv_hrt.h>
#include <semaphore.h>
#include <time.h>
#include <string.h>
#include <errno.h>
#include "hrt_work.h"

Functions

hrt_abstime hrt_absolute_time_offset ()
 
__EXPORT hrt_abstime hrt_reset ()
 
uint64_t hrt_system_time ()
 
hrt_abstime hrt_absolute_time ()
 Get absolute time in [us] (does not wrap).
 
hrt_abstime ts_to_abstime (const struct timespec *ts)
 Convert a timespec to absolute time.
 
hrt_abstime hrt_elapsed_time_atomic (const volatile hrt_abstime *then)
 Compute the delta between a timestamp taken in the past and now. More...
 
hrt_abstime hrt_store_absolute_time (volatile hrt_abstime *now)
 Store the absolute time in an interrupt-safe fashion. More...
 
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...
 
void hrt_cancel (struct hrt_call *entry)
 Remove the entry from the callout list.
 
void hrt_call_init (struct hrt_call *entry)
 Initialise a hrt_call structure.
 
void hrt_call_delay (struct hrt_call *entry, hrt_abstime delay)
 
void hrt_init ()
 
void hrt_call_after (struct hrt_call *entry, hrt_abstime delay, hrt_callout callout, void *arg)
 Call callout(arg) after delay has elapsed. More...
 
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...
 
void hrt_call_at (struct hrt_call *entry, hrt_abstime calltime, hrt_callout callout, void *arg)
 Call callout(arg) at absolute time calltime.
 
void abstime_to_ts (struct timespec *ts, hrt_abstime abstime)
 Convert absolute time to a timespec.
 
int px4_clock_gettime (clockid_t clk_id, struct timespec *tp)
 

Detailed Description

High-resolution timer with callouts and timekeeping.

Function Documentation

§ hrt_call_after()

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().

§ hrt_call_every()

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.

§ hrt_called()

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.

§ hrt_elapsed_time_atomic()

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.

§ hrt_store_absolute_time()

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.