---
title: "RTC"
description: "Wall-clock time in a struct tm-shaped calendar struct, so applications can print it without a conversion step."
source: https://docs.alplab.ai/sdk/api/rtc
---

# `<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.

## Header

```c
#include <alp/rtc.h>
```

## Set and read

```c
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

| Call | Notes |
|------|-------|
| `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](https://docs.alplab.ai/sdk/api/capabilities#instance-level-what-can-this-handle-do); `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`

| Field | Type | Range |
|-------|------|-------|
| `year` | `uint16_t` | Full year, e.g. `2026`. |
| `month` | `uint8_t` | `1..12` |
| `day` | `uint8_t` | `1..31` |
| `weekday` | `uint8_t` | `0..6`, `0` = Sunday. `0` also means "unknown". |
| `hour` | `uint8_t` | `0..23` |
| `minute` | `uint8_t` | `0..59` |
| `second` | `uint8_t` | `0..59` |
| `millisecond` | `uint16_t` | `0..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>`](https://docs.alplab.ai/sdk/api/power) 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>`](https://docs.alplab.ai/sdk/chips), 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

- [Examples: rtc-clock](https://docs.alplab.ai/sdk/examples/rtc-clock)
- [`<alp/power.h>`](https://docs.alplab.ai/sdk/api/power) — RTC wake from sleep / STOP
- [Chip catalogue: rv3028c7](https://docs.alplab.ai/sdk/chips)
