16#ifndef INFUSE_SDK_INCLUDE_INFUSE_TIME_EPOCH_H_
17#define INFUSE_SDK_INCLUDE_INFUSE_TIME_EPOCH_H_
23#include <zephyr/kernel.h>
24#include <zephyr/toolchain.h>
25#include <zephyr/sys/timeutil.h>
40#define SECONDS_PER_MINUTE (60)
41#define SECONDS_PER_HOUR (60 * SECONDS_PER_MINUTE)
42#define SECONDS_PER_DAY (24 * SECONDS_PER_HOUR)
43#define SECONDS_PER_WEEK (7 * SECONDS_PER_DAY)
50#define INFUSE_EPOCH_TIME_GPS_UNIX_OFFSET_SECONDS_LEAP 18
55#define INFUSE_EPOCH_TIME_GPS_UNIX_OFFSET_SECONDS_BASE 315964800
60#define INFUSE_EPOCH_TIME_TICKS_PER_SEC (UINT16_MAX + 1)
88 struct timeutil_sync_instant old,
89 struct timeutil_sync_instant new, void *
user_ctx);
118 return base_good && (!recovered || recovered_ok);
129 return epoch_time >> 16;
140 return epoch_time & 0xFFFF;
163 return (seconds << 16) | subseconds;
283 struct timeutil_sync_instant *reference);
304 const struct timeutil_sync_instant *ref_b, int64_t *epoch_shift);
311void epoch_time_reset(
void);
Conversion between epoch ticks and other units.
#define k_epoch_to_ms_near32(t)
Convert epoch ticks to milliseconds.
Definition epoch_units.h:564
void epoch_time_unix_calendar(uint64_t epoch_time, struct tm *calendar)
Convert a epoch time to a unix time calendar.
epoch_time_source
Definition epoch.h:63
uint32_t epoch_period_from_array_ticks(uint64_t array_ticks, uint16_t array_num)
Get the epoch time period associated with an array.
static bool epoch_time_trusted_source(enum epoch_time_source source, bool recovered_ok)
Determine whether a given time source should be trusted.
Definition epoch.h:112
static uint64_t epoch_time_from(uint64_t seconds, uint16_t subseconds)
Convert seconds and subseconds to complete epoch time.
Definition epoch.h:161
uint64_t epoch_time_from_ticks(uint64_t ticks)
Get the epoch time associated with a local uptime.
static uint16_t epoch_time_subseconds(uint64_t epoch_time)
Extracts epoch subseconds from a complete epoch time.
Definition epoch.h:138
int epoch_time_reference_shift(const struct timeutil_sync_instant *ref_a, const struct timeutil_sync_instant *ref_b, int64_t *epoch_shift)
Determine the epoch time shift due to moving from ref_a to ref_b.
static uint16_t epoch_time_milliseconds(uint64_t epoch_time)
Extracts epoch milliseconds from a complete epoch time.
Definition epoch.h:149
static uint32_t unix_time_from_epoch(uint64_t epoch_time)
Convert epoch time to current unix time.
Definition epoch.h:192
int epoch_time_set_reference(enum epoch_time_source source, struct timeutil_sync_instant *reference)
Set the local to epoch time reference instant.
void epoch_time_register_callback(struct epoch_time_cb *cb)
Register to be notified of epoch time events.
uint32_t epoch_time_reference_age(void)
Query how many seconds ago the reference instant was set.
#define INFUSE_EPOCH_TIME_GPS_UNIX_OFFSET_SECONDS_LEAP
Current offset between GPS and UNIX timestamps.
Definition epoch.h:50
#define INFUSE_EPOCH_TIME_GPS_UNIX_OFFSET_SECONDS_BASE
Unix time at the instant of the GPS epoch.
Definition epoch.h:55
#define SECONDS_PER_WEEK
Definition epoch.h:43
enum epoch_time_source epoch_time_get_source(void)
Get the current source of epoch time knowledge.
uint64_t ticks_from_epoch_time(uint64_t epoch_time)
Get a tick count associated with a epoch time.
static uint64_t epoch_time_seconds(uint64_t epoch_time)
Extracts epoch seconds from a complete epoch time.
Definition epoch.h:127
static uint64_t epoch_time_from_gps(uint16_t week, uint32_t week_seconds, uint16_t subseconds)
Convert GPS time format to complete epoch time.
Definition epoch.h:174
static uint64_t epoch_time_now(void)
Get the current epoch time.
Definition epoch.h:250
static uint64_t epoch_time_from_unix(uint32_t unix_time, uint16_t subseconds)
Convert unix time to current epoch time.
Definition epoch.h:209
@ TIME_SOURCE_RECOVERED
Definition epoch.h:75
@ TIME_SOURCE_INVALID
Definition epoch.h:73
@ TIME_SOURCE_RPC
Definition epoch.h:71
@ TIME_SOURCE_NONE
Definition epoch.h:65
@ TIME_SOURCE_GNSS
Definition epoch.h:67
@ TIME_SOURCE_NTP
Definition epoch.h:69
epoch time event callback structure.
Definition epoch.h:79
void(* reference_time_updated)(enum epoch_time_source source, struct timeutil_sync_instant old, struct timeutil_sync_instant new, void *user_ctx)
The local reference instant has been updated.
Definition epoch.h:87
sys_snode_t node
Definition epoch.h:94
void * user_ctx
Definition epoch.h:92