hardware/peripherals/rtc.html · hardware/peripherals/rtc.rst 공식 원문 ↗

Zephyr 3.7.0 · Hardware · Peripherals · RTC

Real-Time Clock(RTC)

Broken-down time을 추적하는 low-power clock의 API와 실제·emulated driver 검증 방법을 설명합니다.

Official pathhardware/peripherals/rtc.html
Source filehardware/peripherals/rtc.rst
Source versionZephyr 3.7.0
TranslationFull · reviewed

본문 기준: Zephyr 3.7.0 LTS3 · 이후 유지보수 패치는 별도입니다.

Part 1

요약·해설

RTC와 real-time counter의 차이, low-power wake alarm, portable test suite와 emulator 제한을 다룹니다.

Time model

broken-down time

Optional

alarm · update · calibration

Testing

native_sim · real hardware

Part 2

접을 수 있는 영어 원문 전체

영어 원문 전체 펼치기
원문 SHA-256 72400D86E7B05DD11B4C6570B8DA2599760783876EDF1BF561D0CD91B9D23989
.. _rtc_api:

Real-Time Clock (RTC)
#####################

Overview
********

.. list-table:: **Glossary**
    :widths: 30 80
    :header-rows: 1

    * - Word
      - Definition
    * - Real-time clock
      - Low power device tracking time using broken-down time
    * - Real-time counter
      - Low power counter which can be used to track time
    * - RTC
      - Acronym for real-time clock

An RTC is a low power device which tracks time using broken-down time.
It should not be confused with low-power counters which sometimes share
the same name, acronym, or both.

RTCs are usually optimized for low energy consumption and are usually
kept running even when the system is in a low power state.

RTCs usually contain one or more alarms which can be configured to
trigger at a given time. These alarms are commonly used to wake up the
system from a low power state.

History of RTCs in Zephyr
*************************

RTCs have been supported before this API was created, using the
:ref:`counter_api` API. The unix timestamp was used to convert
between broken-down time and the unix timestamp within the RTC
drivers, which internally used the broken-down time representation.

The disadvantages of this approach were that hardware counters could
not be set to a specific count, requiring all RTCs to use device
specific APIs to set the time, converting from unix time to
broken-down time, unnecessarily in some cases, and some common
features missing, like input clock calibration and the update
callback.

Configuration Options
*********************

Related configuration options:

* :kconfig:option:`CONFIG_RTC`
* :kconfig:option:`CONFIG_RTC_ALARM`
* :kconfig:option:`CONFIG_RTC_UPDATE`
* :kconfig:option:`CONFIG_RTC_CALIBRATION`

API Reference
*************

.. doxygengroup:: rtc_interface

RTC device driver test suite
****************************

The test suite validates the behavior of the RTC device driver. It
is designed to be portable between boards. It uses the device tree
alias ``rtc`` to designate the RTC device to test.

This test suite tests the following:

* Setting and getting the time.
* RTC Time incrementing correctly.
* Alarms if supported by hardware, with and without callback enabled
* Calibration if supported by hardware.

The calibration test tests a range of values which are printed to the
console to be manually compared. The user must review the set and
gotten values to ensure they are valid.

By default, only the mandatory setting and getting of time is enabled
for testing. To test the optional alarms, update event callback
and clock calibration, these must be enabled by selecting
:kconfig:option:`CONFIG_RTC_ALARM`, :kconfig:option:`CONFIG_RTC_UPDATE`
and :kconfig:option:`CONFIG_RTC_CALIBRATION`.

The following examples build the test suite for the ``native_sim``
board. To build the test suite for a different board, replace the
``native_sim`` board with your board.

To build the test application with the default configuration, testing
only the mandatory features, the following command can be used for
reference:

.. zephyr-app-commands::
   :tool: west
   :host-os: unix
   :board: native_sim
   :zephyr-app: tests/drivers/rtc/rtc_api
   :goals: build

To build the test with additional RTC features enabled, use menuconfig
to enable the additional features by updating the configuration. The
following command can be used for reference:

.. zephyr-app-commands::
   :tool: west
   :host-os: unix
   :board: native_sim
   :zephyr-app: tests/drivers/rtc/rtc_api
   :goals: menuconfig

Then build the test application using the following command:

.. zephyr-app-commands::
   :tool: west
   :host-os: unix
   :board: native_sim
   :zephyr-app: tests/drivers/rtc/rtc_api
   :maybe-skip-config:
   :goals: build

To run the test suite, flash and run the application on your board, the output will
be printed to the console.

.. note::

    The tests take up to 30 seconds each if they are testing real hardware.

.. _rtc_api_emul_dev:

RTC emulated device
*******************

The emulated RTC device fully implements the RTC API, and will behave like a real
RTC device, with the following limitations:

* RTC time is not persistent across application initialization.
* RTC alarms are not persistent across application initialization.
* RTC time will drift over time.

Every time an application is initialized, the RTC's time and alarms are reset. Reading
the time using :c:func:`rtc_get_time` will return ``-ENODATA``, until the time is
set using :c:func:`rtc_set_time`. The RTC will then behave as a real RTC, until the
application is reset.

The emulated RTC device driver is built for the compatible
:dtcompatible:`zephyr,rtc-emul` and will be included if :kconfig:option:`CONFIG_RTC`
is selected.

Part 3

한국어 전문 번역

Overview

Glossary
WordDefinition
Real-time clockBroken-down time을 사용해 시간을 추적하는 low-power device
Real-time counter시간 추적에 사용할 수 있는 low-power counter
RTCReal-time clock의 약어

RTC는 broken-down time을 사용해 시간을 추적하는 low-power device입니다. 이름이나 약어 또는 둘 다 같을 수 있는 low-power counter와 혼동해서는 안 됩니다.

RTC는 보통 low-energy consumption에 최적화되며 system이 low-power state에 있어도 계속 실행됩니다.

RTC에는 보통 지정한 time에 trigger되도록 구성할 수 있는 alarm이 하나 이상 있습니다. 이 alarm은 system을 low-power state에서 깨우는 데 흔히 사용합니다.

History of RTCs in Zephyr

이 RTC API가 만들어지기 전에는 Counter API로 RTC를 지원했습니다. 내부적으로 broken-down time representation을 쓰는 RTC driver 안에서 Unix timestamp와 broken-down time 사이를 변환하는 데 Unix timestamp를 사용했습니다.

이 접근에는 여러 단점이 있었습니다. Hardware counter를 특정 count로 설정할 수 없어 모든 RTC가 time 설정에 device-specific API를 사용해야 했고, 경우에 따라 불필요하게 Unix time을 broken-down time으로 변환했습니다. Input clock calibration과 update callback 같은 공통 기능도 빠져 있었습니다.

Configuration Options

관련 configuration option은 다음과 같습니다.

  • CONFIG_RTC
  • CONFIG_RTC_ALARM
  • CONFIG_RTC_UPDATE
  • CONFIG_RTC_CALIBRATION

API Reference

rtc_interface Doxygen group이 RTC interface의 공식 API reference를 제공합니다.

RTC device driver test suite

Test suite는 RTC device driver의 동작을 검증하며 board 사이에서 portable하도록 설계됐습니다. Devicetree alias rtc로 시험할 RTC device를 지정합니다.

이 test suite가 검사하는 항목은 다음과 같습니다.

  • Time 설정과 조회
  • RTC time이 올바르게 증가하는지 여부
  • Hardware가 지원할 경우 callback enable·disable 상태 모두의 alarm
  • Hardware가 지원할 경우 calibration

Calibration test는 값의 범위를 시험해 console에 출력하며 수동 비교가 필요합니다. 사용자는 설정한 값과 다시 읽은 값이 유효한지 검토해야 합니다.

CONFIG_RTC_ALARM, CONFIG_RTC_UPDATE, CONFIG_RTC_CALIBRATION을 선택하지 않은 기본 상태에서는 mandatory time 설정·조회만 시험합니다. Optional alarm, update event callback, clock calibration을 시험하려면 해당 option을 enable해야 합니다.

native_sim board용 test suite build 예는 다음과 같습니다. 다른 board를 시험하려면 native_sim을 대상 board로 바꿉니다.

Mandatory 기능만 시험하는 default configuration으로 test application을 build합니다.

# From the root of the zephyr repository
west build -b native_sim tests/drivers/rtc/rtc_api

추가 RTC 기능을 enable한 test는 menuconfig에서 configuration을 갱신합니다.

# From the root of the zephyr repository
west build -b native_sim tests/drivers/rtc/rtc_api
west build -t menuconfig

그다음 test application을 build합니다.

# From the root of the zephyr repository
west build -b native_sim tests/drivers/rtc/rtc_api

Test suite를 실행하려면 application을 board에 flash하고 실행합니다. Output은 console에 표시됩니다.

RTC emulated device

Emulated RTC device는 RTC API를 완전히 구현하며 실제 RTC device처럼 동작하지만 다음 제한이 있습니다.

  • RTC time은 application initialization을 넘어 persistent하지 않습니다.
  • RTC alarm은 application initialization을 넘어 persistent하지 않습니다.
  • RTC time은 시간이 지나면서 drift합니다.

Application을 초기화할 때마다 RTC time과 alarm이 reset됩니다. rtc_set_time()으로 time을 설정하기 전 rtc_get_time()을 호출하면 -ENODATA를 반환합니다. Time을 설정한 뒤에는 application을 reset할 때까지 실제 RTC처럼 동작합니다.

Emulated RTC driver는 compatible zephyr,rtc-emul을 위해 build되며 CONFIG_RTC를 선택하면 포함됩니다.

Source

출처

영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.