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 = 0Calibrated 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).
variable s_drift_ppm¶
Calibrated clock drift compensation in parts-per-million (PPM).
Public Functions Documentation¶
function syn_rtc_from_epoch¶
Convert a Unix epoch timestamp to a date/time.
Parameters:
epochSeconds since 1970-01-01 00:00:00 UTC.dtOutput. Must not be NULL.
function syn_rtc_get¶
Read the current date/time.
Parameters:
dtOutput, must not be NULL.
Returns:
SYN_OK on success, SYN_ERROR on hardware failure.
function syn_rtc_init¶
Initialize the RTC peripheral.
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.
Parameters:
dtDate/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_nowSeconds to add to current time.alarm_dtOutput 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.
Validates all fields before writing to hardware.
Parameters:
dtNew time. Must not be NULL and must pass syn_rtc_is_valid().
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.
Parameters:
dtTarget 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).
Parameters:
drift_ppmDrift in Parts-Per-Million (+ = fast, - = slow).
function syn_rtc_to_epoch¶
Convert a date/time to a Unix epoch timestamp.
Epoch = seconds since 1970-01-01 00:00:00 UTC. Leap seconds are not accounted for (standard POSIX convention).
Parameters:
dtDate/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.
Parameters:
monthMonth (1–12).yearGregorian year.
Returns:
Day count.
function rtc_is_leap¶
Test if a year is a leap year.
Parameters:
yearGregorian year.
Returns:
true if leap year.
The documentation for this class was generated from the following file src/syntropic/drivers/syn_rtc.c