Skip to main content

<alp/rtc.h> — Real-Time Clock

Wall-clock time in a struct tm-shaped calendar struct, so applications can print it without a conversion step.

#include <alp/rtc.h>

Set and read​

alp_rtc_t *rtc = alp_rtc_open(0);
if (rtc == NULL) return alp_last_error();

alp_rtc_time_t now = {
.year = 2026, .month = 5, .day = 13,
.hour = 22, .minute = 28, .second = 0,
};
alp_rtc_set_time(rtc, &now);

alp_rtc_get_time(rtc, &now);
printf("%04u-%02u-%02u %02u:%02u:%02u\n",
now.year, now.month, now.day, now.hour, now.minute, now.second);

alp_rtc_close(rtc);

Functions​

CallNotes
alp_rtc_open(uint32_t rtc_id)Most SoMs expose one RTC — pass 0. Multi-RTC SoMs map higher ids (0..1) via the alp-rtc<N> devicetree alias. Returns NULL on resolution failure.
alp_rtc_set_time(rtc, &time)Every field is validated; an out-of-range value returns ALP_ERR_INVAL without touching the RTC.
alp_rtc_get_time(rtc, &time)Reads the current time.
alp_rtc_close(rtc)Releases the handle.
alp_rtc_capabilities(rtc)Per-instance capability descriptor; NULL handle → NULL.

alp_rtc_set_time() and alp_rtc_get_time() return ALP_OK, ALP_ERR_NOT_READY, ALP_ERR_INVAL, ALP_ERR_IO, or — since v0.17.0 — ALP_ERR_NOSUPPORT when the backend has no working RTC path.

alp_rtc_time_t​

FieldTypeRange
yearuint16_tFull year, e.g. 2026.
monthuint8_t1..12
dayuint8_t1..31
weekdayuint8_t0..6, 0 = Sunday. 0 also means "unknown".
houruint8_t0..23
minuteuint8_t0..59
seconduint8_t0..59
milliseconduint16_t0..999; 0 if the RTC has 1 s resolution.

There is no timezone — wall clock only.

Backends​

  • Zephyr — the Zephyr rtc_* driver class.
  • Yocto / Linux — clock_gettime(CLOCK_REALTIME) plus /dev/rtc0.
  • Baremetal — no backend: the build links a stub that returns ALP_ERR_NOSUPPORT.

<alp/rtc.h> has no alarm or wake API. To wake from a low-power mode on an RTC event, use <alp/power.h> with ALP_POWER_WAKE_RTC.

On-module RTC chip​

Every current Alp Lab SoM populates a Micro Crystal RV-3028-C7 RTC. Its chip driver, <alp/chips/rv3028c7.h>, also exposes the part's own features beyond the portable surface. v0.17.0 added a countdown timer (rv3028c7_timer_start() / _stop() / _read()), alarm arm and clear (rv3028c7_alarm_arm() / rv3028c7_alarm_clear()), a wake-flag service (rv3028c7_wake_service()), and rv3028c7_was_cold_start(). The Alif STOP power backend uses them for timed wakes from STOP.

See also​

Questions about this page? Email contact@alplab.ai