@page page_device_clock_boottime Clock Boottime Helpers
Boottime helpers convert the clock_time monotonic counter into standard time formats. The resulting values represent time since boot and do not depend on RTC or wall-clock settings.
rt_err_t rt_clock_boottime_get_us(struct timeval *tv);
rt_err_t rt_clock_boottime_get_s(time_t *t);
rt_err_t rt_clock_boottime_get_ns(struct timespec *ts);
All functions return RT_EOK on success or -RT_ERROR if the clock source is unavailable. The returned values are monotonic and suitable for measuring elapsed time.
rt_err_t rt_clock_boottime_get_us(struct timeval *tv);
tv must be a valid pointer to struct timeval.tv.tv_usec is derived from the clock_time resolution and may not be exact
microseconds if the underlying counter does not align to 1 us.rt_err_t rt_clock_boottime_get_s(time_t *t);
t must be a valid pointer to time_t.*t updated.rt_clock_boottime_get_us() or
rt_clock_boottime_get_ns() if needed.rt_err_t rt_clock_boottime_get_ns(struct timespec *ts);
ts must be a valid pointer to struct timespec.ts.tv_nsec reflects the clock_time resolution; it may not be 1 ns granularity
if the counter frequency is lower.#include <drivers/clock_time.h>
static void demo_boottime(void)
{
struct timespec ts;
if (rt_clock_boottime_get_ns(&ts) == RT_EOK)
{
rt_kprintf("boottime: %ld.%09ld\n", (long)ts.tv_sec, ts.tv_nsec);
}
}