arch/arm/ameba: add shared RTC driver for RTL8721Dx / RTL8720F / RTL8721F - #19945
Open
dcgong2917 wants to merge 3 commits into
Open
arch/arm/ameba: add shared RTC driver for RTL8721Dx / RTL8720F / RTL8721F#19945dcgong2917 wants to merge 3 commits into
dcgong2917 wants to merge 3 commits into
Conversation
Expose the Ameba on-chip RTC as a NuttX date/time RTC at /dev/rtc0 (rdtime/settime) with a single one-shot alarm (setalarm/rdalarm/ cancelalarm/setrelative) that fires the RTC interrupt and the upper-half callback. The same hardware also backs the arch date/time RTC hooks (up_rtc_initialize/getdatetime/settime, g_rtc_enabled) so the NuttX system time is seeded from it. The driver sits on the SDK fwlib RTC API (mirrored structures + local externs, no vendor headers pulled into the NuttX include world). The fwlib RTC API lives in the RAM source ameba_rtc.c, so it is added to the board fwlib build under CONFIG_AMEBA_RTC. The hardware keeps a year plus a day-of-year (no month/day register); the driver bridges that to the NuttX month/day calendar with the libc UTC routines (timegm/gmtime_r), which is exact and reversible. The only per-chip fact -- the RTC interrupt vector -- lives in the per-chip ameba_rtc_chip.h; the shared driver is never edited for a new Ameba chip. A configs/rtc profile (examples/alarm) is added for verification. Signed-off-by: dechao_gong <dechao_gong@realsil.com.cn> Assisted-by: Claude <noreply@anthropic.com>
Wire the shared Ameba RTC driver (arch/arm/src/common/ameba/ameba_rtc.c) into RTL8720F. The driver is chip-agnostic and reads only per-chip macros from ameba_rtc_chip.h; RTL8720F differs from amebadplus only in the RTC interrupt vector (RTL8720F_IRQ_RTC, vector 33). The APBPeriph_RTC masks and RTC_BASE_YEAR (1900) are identical across all current Ameba chips. - ameba_rtc_chip.h: per-chip RTC IRQ / clock masks / base year - Make.defs, ameba_board.mk: compile ameba_rtc.c and the fwlib RAM RTC source when CONFIG_AMEBA_RTC=y - board: rtl8720f_rtc.c registers /dev/rtc0 from bringup - configs/rtc: examples/alarm profile Signed-off-by: dechao_gong <dechao_gong@realsil.com.cn> Assisted-by: Claude <noreply@anthropic.com>
Wire the shared Ameba RTC driver (arch/arm/src/common/ameba/ameba_rtc.c) into RTL8721F (amebagreen2). The driver is chip-agnostic and reads only per-chip macros from ameba_rtc_chip.h; RTL8721F differs from amebadplus only in the RTC interrupt vector (RTL8721F_IRQ_RTC, vector 41). The APBPeriph_RTC masks and RTC_BASE_YEAR (1900) are identical across all current Ameba chips. - ameba_rtc_chip.h: per-chip RTC IRQ / clock masks / base year - Make.defs, ameba_board.mk: compile ameba_rtc.c and the fwlib RAM RTC source when CONFIG_AMEBA_RTC=y - board: rtl8721f_rtc.c registers /dev/rtc0 from bringup - configs/rtc: examples/alarm profile Signed-off-by: dechao_gong <dechao_gong@realsil.com.cn> Assisted-by: Claude <noreply@anthropic.com>
xiaoxiang781216
approved these changes
Aug 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an on-chip RTC driver for the Realtek Ameba family, exposed as a
/dev/rtc0date/time character device with alarm support. The driver lives inthe shared layer
arch/arm/src/common/ameba/ameba_rtc.cand is wired into threeICs — rtl8721dx , rtl8720f and rtl8721f — reusing the common code unchanged.
Design notes:
headers pulled into the NuttX include world). The fwlib RTC API lives in the
RAM source
ameba_rtc.c, added to the fwlib build underCONFIG_AMEBA_RTC.ameba_rtc_lowerhalf; alarmset/cancel/relative + upper-half callback) and the arch date/time hooks
(
up_rtc_initialize/getdatetime/settime,g_rtc_enabled), so NuttXsystem time is seeded from the RTC.
driver bridges that to the NuttX calendar with the libc UTC routines
(
timegm/gmtime_r), which is exact and reversible. Cold start seeds thebuild date when the stored year predates
CONFIG_START_YEAR.ameba_rtc_chip.h(46 / 33 / 41); the shared driver is never edited for a newAmeba chip.
A
rtcboard profile (examples/alarm) is added to each board for verification,and the board documentation is updated.
Impact
CONFIG_AMEBA_RTC(default n). No impact onexisting configs.
Testing
tools/checkpatch.sh -g master..HEAD: all checks pass.Builds and links cleanly on all three ICs (rtl8721dx, rtl8720f, rtl8721f).
Hardware: verified on all three EVBs (rtl8721dx, rtl8720f, rtl8721f)
with the
rtcconfig, exercising every driver path:build date instead of a pre-epoch value, so
dateis valid immediately.RTC_RD_TIME/RTC_SET_TIMEvia NSHdate): theyear/day-of-year hardware model is correctly bridged to the full
month/day calendar in both directions.
datereads show the clock advancing in realtime.
RTC_SET_ALARM+ IRQ callback viaalarmexample): a one-shotalarm fires once at the requested offset and does not re-fire.
Representative NSH session (rtl8721dx):