Infuse-IoT SDK API 0.0.1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
epoch.h File Reference

Infuse-IoT time based on the GPS epoch. More...

#include <stdint.h>
#include <stdbool.h>
#include <time.h>
#include <zephyr/kernel.h>
#include <zephyr/toolchain.h>
#include <zephyr/sys/timeutil.h>
#include "epoch_units.h"

Go to the source code of this file.

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

Infuse-IoT time based on the GPS epoch.

Author
Jordan Yates jorda.nosp@m.n@em.nosp@m.beint.nosp@m..com

SPDX-License-Identifier: FSL-1.1-ALv2

Infuse-IoT uses the GPS epoch for local timekeeping. For simplicity, seconds and subseconds are encoded into a single uint64_t. The top 48 bits are the number of seconds elapsed since the GPS epoch (00:00:00 06/01/1980 UTC). The bottom 16 bits are in units of (1/65536) seconds.