Skip to content

Commit ae36da5

Browse files
Bjarki Arge Andreasencarlescufi
authored andcommitted
boards/posix/native_posix: Add emulated RTC device driver
The emulated RTC device driver is used to emulate a real RTC device. Note that it is not a replacement for the native_rtc module, which is used to control simulated time, get time from the host system, etc. Signed-off-by: Bjarki Arge Andreasen <baa@trackunit.com>
1 parent ac697d1 commit ae36da5

File tree

8 files changed

+601
-33
lines changed

8 files changed

+601
-33
lines changed

boards/posix/native_posix/native_posix.dts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
spi-0 = &spi0;
3232
led0 = &led0;
3333
kscan0 = &sdl_kscan;
34+
rtc = &rtc;
3435
};
3536

3637
leds {
@@ -200,4 +201,10 @@
200201
sample-point = <875>;
201202
bus-speed = <125000>;
202203
};
204+
205+
rtc: rtc {
206+
status = "okay";
207+
compatible = "zephyr,rtc-emul";
208+
alarms-count = <2>;
209+
};
203210
};

doc/hardware/peripherals/rtc.rst

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,52 @@ API Reference
6363
RTC device driver test suite
6464
****************************
6565

66-
See :ref:`rtc_api_test`
66+
The test suite validates the behavior of the RTC device driver. It
67+
is designed to be portable between boards. It uses the device tree
68+
alias ``rtc`` to designate the RTC device to test.
69+
70+
This test suite tests the following:
71+
72+
* Setting and getting the time.
73+
* RTC Time incrementing correctly.
74+
* Alarms if supported by hardware, with and without callback enabled
75+
* Calibration if supported by hardware.
76+
77+
The calibration test tests a range of values which are printed to the
78+
console to be manually compared. The user must review the set and
79+
gotten values to ensure they are valid.
80+
81+
By default, only the mandatory Setting and getting time is enabled
82+
for testing. To test the optional alarms, update event callback
83+
and clock calibration, these must be enabled by selecting
84+
``CONFIG_RTC_ALARM``, ``CONFIG_RTC_UPDATE`` and
85+
``CONFIG_RTC_CALIBRATION``.
86+
87+
To build the test application with default settings for a board which
88+
contains the device tree alias ``rtc``, the following command can be used
89+
for reference:
90+
91+
::
92+
93+
$ west build -p -b <your board> zephyr/tests/drivers/rtc/rtc_api/
94+
95+
To build the test with additional RTC features enabled, use menuconfig
96+
to enable the additional features. The following command can be used
97+
for reference:
98+
99+
::
100+
101+
$ west build -p -b <your board> -t menuconfig zephyr/tests/drivers/rtc/rtc_api/
102+
103+
Then build the test application using the following command
104+
105+
::
106+
107+
$ west build
108+
109+
To run the test suite, flash and run the application on your board, the output will
110+
be printed to the console.
111+
112+
.. note::
113+
114+
The tests take up to 30 seconds each if they are testing real hardware.

drivers/rtc/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ zephyr_library()
55

66
zephyr_library_sources_ifdef(CONFIG_USERSPACE rtc_handlers.c)
77
zephyr_library_sources_ifdef(CONFIG_RTC_EMUL rtc_emul.c)
8-

drivers/rtc/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ config RTC_CALIBRATION
2323
This is an option which enables driver support for RTC clock
2424
calibration.
2525

26+
source "drivers/rtc/Kconfig.emul"
27+
2628
endif # RTC

drivers/rtc/Kconfig.emul

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2022 Bjarki Arge Andreasen
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config RTC_EMUL
5+
bool "Emulated RTC driver"
6+
default y
7+
depends on DT_HAS_ZEPHYR_RTC_EMUL_ENABLED
8+
help
9+
Enable emulated Real-Time Clock (RTC) driver.

0 commit comments

Comments
 (0)