Skip to content

File syn_rtc.c

FileList > drivers > syn_rtc.c

Go to the source code of this file

RTC driver implementation — port delegation + epoch math.

  • #include "../util/syn_assert.h"
  • #include "syn_rtc.h"

Public Static Attributes

Type Name
const uint8_t s_days_in_month = /* multi line expression */
Days per month (non-leap year).
int32_t s_drift_ppm = 0
Calibrated clock drift compensation in parts-per-million (PPM).

Public Functions

Type Name
void syn_rtc_from_epoch (uint32_t epoch, SYN_RTC_DateTime * dt)
Convert a Unix epoch timestamp to a date/time.
SYN_Status syn_rtc_get (SYN_RTC_DateTime * dt)
Read the current date/time.
SYN_Status syn_rtc_init (void)
Initialize the RTC peripheral.
bool syn_rtc_is_valid (const SYN_RTC_DateTime * dt)
Check whether all fields of a SYN_RTC_DateTime are in range.
SYN_Status syn_rtc_schedule_alarm_seconds (uint32_t seconds_from_now, SYN_RTC_DateTime * alarm_dt)
Schedule an alarm relative to current time by seconds.
SYN_Status syn_rtc_set (const SYN_RTC_DateTime * dt)
Set the RTC to a new date/time.
SYN_Status syn_rtc_set_alarm (const SYN_RTC_DateTime * dt)
Set the target alarm date/time on the RTC.
void syn_rtc_set_drift_ppm (int32_t drift_ppm)
Set the RTC clock drift compensation in Parts-Per-Million (PPM).
uint32_t syn_rtc_to_epoch (const SYN_RTC_DateTime * dt)
Convert a date/time to a Unix epoch timestamp.

Public Static Functions

Type Name
uint8_t rtc_days_in_month (uint8_t month, uint16_t year)
Get days in a given month.
bool rtc_is_leap (uint16_t year)
Test if a year is a leap year.

Public Static Attributes Documentation

variable s_days_in_month

Days per month (non-leap year).

const uint8_t s_days_in_month[12];


variable s_drift_ppm

Calibrated clock drift compensation in parts-per-million (PPM).

int32_t s_drift_ppm;


Public Functions Documentation

function syn_rtc_from_epoch

Convert a Unix epoch timestamp to a date/time.

void syn_rtc_from_epoch (
    uint32_t epoch,
    SYN_RTC_DateTime * dt
) 

Parameters:

  • epoch Seconds since 1970-01-01 00:00:00 UTC.
  • dt Output. Must not be NULL.

function syn_rtc_get

Read the current date/time.

SYN_Status syn_rtc_get (
    SYN_RTC_DateTime * dt
) 

Parameters:

  • dt Output, must not be NULL.

Returns:

SYN_OK on success, SYN_ERROR on hardware failure.


function syn_rtc_init

Initialize the RTC peripheral.

SYN_Status syn_rtc_init (
    void
) 

Returns:

SYN_OK on success, SYN_ERROR on failure.


function syn_rtc_is_valid

Check whether all fields of a SYN_RTC_DateTime are in range.

bool syn_rtc_is_valid (
    const SYN_RTC_DateTime * dt
) 

Parameters:

  • dt Date/time to validate. Must not be NULL.

Returns:

true if valid, false if any field is out of range.


function syn_rtc_schedule_alarm_seconds

Schedule an alarm relative to current time by seconds.

SYN_Status syn_rtc_schedule_alarm_seconds (
    uint32_t seconds_from_now,
    SYN_RTC_DateTime * alarm_dt
) 

Parameters:

  • seconds_from_now Seconds to add to current time.
  • alarm_dt Output target alarm date/time structure.

Returns:

SYN_OK on success, error code otherwise.


function syn_rtc_set

Set the RTC to a new date/time.

SYN_Status syn_rtc_set (
    const SYN_RTC_DateTime * dt
) 

Validates all fields before writing to hardware.

Parameters:

Returns:

SYN_OK on success, SYN_INVALID_PARAM if fields are out of range, SYN_ERROR on hardware failure.


function syn_rtc_set_alarm

Set the target alarm date/time on the RTC.

SYN_Status syn_rtc_set_alarm (
    const SYN_RTC_DateTime * dt
) 

Parameters:

  • dt Target alarm date/time. Must be valid.

Returns:

SYN_OK on success, error code otherwise.


function syn_rtc_set_drift_ppm

Set the RTC clock drift compensation in Parts-Per-Million (PPM).

void syn_rtc_set_drift_ppm (
    int32_t drift_ppm
) 

Parameters:

  • drift_ppm Drift in Parts-Per-Million (+ = fast, - = slow).

function syn_rtc_to_epoch

Convert a date/time to a Unix epoch timestamp.

uint32_t syn_rtc_to_epoch (
    const SYN_RTC_DateTime * dt
) 

Epoch = seconds since 1970-01-01 00:00:00 UTC. Leap seconds are not accounted for (standard POSIX convention).

Parameters:

  • dt Date/time to convert. Must be valid.

Returns:

Seconds since Unix epoch.


Public Static Functions Documentation

function rtc_days_in_month

Get days in a given month.

static uint8_t rtc_days_in_month (
    uint8_t month,
    uint16_t year
) 

Parameters:

  • month Month (1–12).
  • year Gregorian year.

Returns:

Day count.


function rtc_is_leap

Test if a year is a leap year.

static bool rtc_is_leap (
    uint16_t year
) 

Parameters:

  • year Gregorian year.

Returns:

true if leap year.



The documentation for this class was generated from the following file src/syntropic/drivers/syn_rtc.c