Infuse-IoT SDK API 0.0.1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Epoch APIs

epoch_time API More...

Data Structures

struct  epoch_time_cb
 epoch time event callback structure. More...
 

Macros

#define SECONDS_PER_MINUTE   (60)
 
#define SECONDS_PER_HOUR   (60 * SECONDS_PER_MINUTE)
 
#define SECONDS_PER_DAY   (24 * SECONDS_PER_HOUR)
 
#define SECONDS_PER_WEEK   (7 * SECONDS_PER_DAY)
 
#define INFUSE_EPOCH_TIME_GPS_UNIX_OFFSET_SECONDS_LEAP   18
 Current offset between GPS and UNIX timestamps.
 
#define INFUSE_EPOCH_TIME_GPS_UNIX_OFFSET_SECONDS_BASE   315964800
 Unix time at the instant of the GPS epoch.
 
#define INFUSE_EPOCH_TIME_TICKS_PER_SEC   (UINT16_MAX + 1)
 Base tick rate of Infuse-IoT epoch time.
 

Enumerations

enum  epoch_time_source {
  TIME_SOURCE_NONE = 0 , TIME_SOURCE_GNSS , TIME_SOURCE_NTP , TIME_SOURCE_RPC ,
  TIME_SOURCE_INVALID , TIME_SOURCE_RECOVERED = 0x80
}
 

Functions

void epoch_time_register_callback (struct epoch_time_cb *cb)
 Register to be notified of epoch time events.
 
static bool epoch_time_trusted_source (enum epoch_time_source source, bool recovered_ok)
 Determine whether a given time source should be trusted.
 
static uint64_t epoch_time_seconds (uint64_t epoch_time)
 Extracts epoch seconds from a complete epoch time.
 
static uint16_t epoch_time_subseconds (uint64_t epoch_time)
 Extracts epoch subseconds from a complete epoch time.
 
static uint16_t epoch_time_milliseconds (uint64_t epoch_time)
 Extracts epoch milliseconds from a complete epoch time.
 
static uint64_t epoch_time_from (uint64_t seconds, uint16_t subseconds)
 Convert seconds and subseconds to complete epoch time.
 
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.
 
static uint32_t unix_time_from_epoch (uint64_t epoch_time)
 Convert epoch time to current unix time.
 
static uint64_t epoch_time_from_unix (uint32_t unix_time, uint16_t subseconds)
 Convert unix time to current epoch time.
 
uint64_t ticks_from_epoch_time (uint64_t epoch_time)
 Get a tick count associated with a epoch time.
 
uint64_t epoch_time_from_ticks (uint64_t ticks)
 Get the epoch time associated with a local uptime.
 
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 uint64_t epoch_time_now (void)
 Get the current epoch time.
 
void epoch_time_unix_calendar (uint64_t epoch_time, struct tm *calendar)
 Convert a epoch time to a unix time calendar.
 
enum epoch_time_source epoch_time_get_source (void)
 Get the current source of epoch time knowledge.
 
int epoch_time_set_reference (enum epoch_time_source source, struct timeutil_sync_instant *reference)
 Set the local to epoch time reference instant.
 
uint32_t epoch_time_reference_age (void)
 Query how many seconds ago the reference instant was set.
 
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.
 

Detailed Description

epoch_time API

Macro Definition Documentation

◆ INFUSE_EPOCH_TIME_GPS_UNIX_OFFSET_SECONDS_BASE

#define INFUSE_EPOCH_TIME_GPS_UNIX_OFFSET_SECONDS_BASE   315964800

#include <infuse/time/epoch.h>

Unix time at the instant of the GPS epoch.

◆ INFUSE_EPOCH_TIME_GPS_UNIX_OFFSET_SECONDS_LEAP

#define INFUSE_EPOCH_TIME_GPS_UNIX_OFFSET_SECONDS_LEAP   18

#include <infuse/time/epoch.h>

Current offset between GPS and UNIX timestamps.

Warning
This value will be incorrect after the next leap-second

◆ INFUSE_EPOCH_TIME_TICKS_PER_SEC

#define INFUSE_EPOCH_TIME_TICKS_PER_SEC   (UINT16_MAX + 1)

#include <infuse/time/epoch.h>

Base tick rate of Infuse-IoT epoch time.

◆ SECONDS_PER_DAY

#define SECONDS_PER_DAY   (24 * SECONDS_PER_HOUR)

#include <infuse/time/epoch.h>

◆ SECONDS_PER_HOUR

#define SECONDS_PER_HOUR   (60 * SECONDS_PER_MINUTE)

#include <infuse/time/epoch.h>

◆ SECONDS_PER_MINUTE

#define SECONDS_PER_MINUTE   (60)

#include <infuse/time/epoch.h>

◆ SECONDS_PER_WEEK

#define SECONDS_PER_WEEK   (7 * SECONDS_PER_DAY)

#include <infuse/time/epoch.h>

Enumeration Type Documentation

◆ epoch_time_source

#include <infuse/time/epoch.h>

Enumerator
TIME_SOURCE_NONE 
TIME_SOURCE_GNSS 
TIME_SOURCE_NTP 
TIME_SOURCE_RPC 
TIME_SOURCE_INVALID 
TIME_SOURCE_RECOVERED 

Function Documentation

◆ epoch_period_from_array_ticks()

uint32_t epoch_period_from_array_ticks ( uint64_t array_ticks,
uint16_t array_num )

#include <infuse/time/epoch.h>

Get the epoch time period associated with an array.

Parameters
array_ticksTicks between first and last sample in array
array_numNumber of samples in array
Returns
uint32_t Equivalent period in epoch time units

◆ epoch_time_from()

static uint64_t epoch_time_from ( uint64_t seconds,
uint16_t subseconds )
inlinestatic

#include <infuse/time/epoch.h>

Convert seconds and subseconds to complete epoch time.

Parameters
secondsNumber of seconds since GPS epoch
subsecondsFractional component of time since GPS epoch
Return values
epoch_timeComplete epoch time

◆ epoch_time_from_gps()

static uint64_t epoch_time_from_gps ( uint16_t week,
uint32_t week_seconds,
uint16_t subseconds )
inlinestatic

#include <infuse/time/epoch.h>

Convert GPS time format to complete epoch time.

Parameters
weekGPS week counter
week_secondsGPS seconds of week
subsecondsFractional component of time since GPS epoch
Return values
epoch_timeComplete epoch time

◆ epoch_time_from_ticks()

uint64_t epoch_time_from_ticks ( uint64_t ticks)

#include <infuse/time/epoch.h>

Get the epoch time associated with a local uptime.

Parameters
ticksKernel tick count
Returns
uint64_t Equivalent time in epoch time

◆ epoch_time_from_unix()

static uint64_t epoch_time_from_unix ( uint32_t unix_time,
uint16_t subseconds )
inlinestatic

#include <infuse/time/epoch.h>

Convert unix time to current epoch time.

Warning
To simplify the implementation, this function is only guaranteed to be correct for times since the last leap second (31st December 2016) until the next leap second (unknown).
Parameters
unix_timeCurrent unix time
subsecondsFractional component of unix time
Return values
epoch_timeComplete epoch time

◆ epoch_time_get_source()

enum epoch_time_source epoch_time_get_source ( void )

#include <infuse/time/epoch.h>

Get the current source of epoch time knowledge.

Returns
enum epoch_time_source Current time source

◆ epoch_time_milliseconds()

static uint16_t epoch_time_milliseconds ( uint64_t epoch_time)
inlinestatic

#include <infuse/time/epoch.h>

Extracts epoch milliseconds from a complete epoch time.

Parameters
epoch_timeComplete epoch time
Return values
millisecondsFractional component of time since GPS epoch

◆ epoch_time_now()

static uint64_t epoch_time_now ( void )
inlinestatic

#include <infuse/time/epoch.h>

Get the current epoch time.

Return values
epoch_timeComplete epoch time

◆ epoch_time_reference_age()

uint32_t epoch_time_reference_age ( void )

#include <infuse/time/epoch.h>

Query how many seconds ago the reference instant was set.

Return values
UINT32_MAXif not yet set
secondssince reference instant was set

◆ epoch_time_reference_shift()

int epoch_time_reference_shift ( const struct timeutil_sync_instant * ref_a,
const struct timeutil_sync_instant * ref_b,
int64_t * epoch_shift )

#include <infuse/time/epoch.h>

Determine the epoch time shift due to moving from ref_a to ref_b.

Parameters
ref_aOriginal reference point
ref_bUpdated reference point
epoch_shiftTime shift from updating reference points
Return values
0On success
-EINVALIf either sync instant is invalid

◆ epoch_time_register_callback()

void epoch_time_register_callback ( struct epoch_time_cb * cb)

#include <infuse/time/epoch.h>

Register to be notified of epoch time events.

Parameters
cbCallback struct to register

◆ epoch_time_seconds()

static uint64_t epoch_time_seconds ( uint64_t epoch_time)
inlinestatic

#include <infuse/time/epoch.h>

Extracts epoch seconds from a complete epoch time.

Parameters
epoch_timeComplete epoch time
Return values
secondsNumber of seconds since GPS epoch

◆ epoch_time_set_reference()

int epoch_time_set_reference ( enum epoch_time_source source,
struct timeutil_sync_instant * reference )

#include <infuse/time/epoch.h>

Set the local to epoch time reference instant.

Parameters
sourceSource of the reference instant
referenceSame instant in local and epoch time bases
Return values
0on success
-EINVALif reference instant is invalid

◆ epoch_time_subseconds()

static uint16_t epoch_time_subseconds ( uint64_t epoch_time)
inlinestatic

#include <infuse/time/epoch.h>

Extracts epoch subseconds from a complete epoch time.

Parameters
epoch_timeComplete epoch time
Return values
subsecondsFractional component of time since GPS epoch

◆ epoch_time_trusted_source()

static bool epoch_time_trusted_source ( enum epoch_time_source source,
bool recovered_ok )
inlinestatic

#include <infuse/time/epoch.h>

Determine whether a given time source should be trusted.

Parameters
sourceTime source
recovered_okShould a time source recovered across a reboot be trusted
Returns
true Time source can be trusted
false Time source should not be trusted

◆ epoch_time_unix_calendar()

void epoch_time_unix_calendar ( uint64_t epoch_time,
struct tm * calendar )

#include <infuse/time/epoch.h>

Convert a epoch time to a unix time calendar.

Note
Output depends on current leap seconds count, and is therefore only valid until the next leap second change.
Parameters
epoch_timeComplete epoch time
calendarOutput calendar

◆ ticks_from_epoch_time()

uint64_t ticks_from_epoch_time ( uint64_t epoch_time)

#include <infuse/time/epoch.h>

Get a tick count associated with a epoch time.

Parameters
epoch_timeepoch time
Returns
uint64_t Equivalent time in ticks

◆ unix_time_from_epoch()

static uint32_t unix_time_from_epoch ( uint64_t epoch_time)
inlinestatic

#include <infuse/time/epoch.h>

Convert epoch time to current unix time.

Warning
To simplify the implementation, this function is only guaranteed to be correct for times since the last leap second (31st December 2016) until the next leap second (unknown).
Parameters
epoch_timeComplete epoch time
Return values
unix_timeCurrent unix time