Skip to content

File syn_rtc.h

FileList > drivers > syn_rtc.h

Go to the source code of this file

RTC (Real-Time Clock) driver. More...

  • #include "../port/syn_port_rtc.h"

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.

Detailed Description

Thin wrapper over syn_port_rtc.h that adds input validation and Unix-epoch conversion utilities. No heap allocation; no state struct is required — calls delegate directly to the port layer.

Epoch base: 1970-01-01 00:00:00 UTC (standard Unix time). Valid date range: 1970-01-01 through 2105-12-31.

Usage:

SYN_RTC_DateTime dt = { .year=2025, .month=6, .day=1,
                         .hour=12, .minute=0, .second=0 };
syn_rtc_init();
syn_rtc_set(&dt);
// ... later ...
syn_rtc_get(&dt);
uint32_t t = syn_rtc_to_epoch(&dt);

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.



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