dcgong2917 opened a new pull request, #19945:
URL: https://github.com/apache/nuttx/pull/19945

    ## Summary
   
     Adds an on-chip RTC driver for the Realtek Ameba family, exposed as a
     `/dev/rtc0` date/time character device with alarm support. The driver 
lives in
     the shared layer `arch/arm/src/common/ameba/ameba_rtc.c` and is wired into 
three
     ICs — rtl8721dx , rtl8720f and rtl8721f — reusing the common code 
unchanged.
   
     Design notes:
     - 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`, added to the fwlib build under 
`CONFIG_AMEBA_RTC`
       (both Make and CMake).
     - Provides both the lower-half RTC (`ameba_rtc_lowerhalf`; alarm
       set/cancel/relative + upper-half callback) and the arch date/time hooks
       (`up_rtc_initialize`/`getdatetime`/`settime`, `g_rtc_enabled`), so NuttX
       system time is seeded from the RTC.
     - The hardware keeps a year plus a day-of-year (no month/day register); the
       driver bridges that to the NuttX calendar with the libc UTC routines
       (`timegm`/`gmtime_r`), which is exact and reversible. Cold start seeds 
the
       build date when the stored year predates `CONFIG_START_YEAR`.
     - The only per-chip fact — the RTC interrupt vector — lives in the per-chip
       `ameba_rtc_chip.h` (46 / 33 / 41); the shared driver is never edited for 
a new
       Ameba chip.
   
     A `rtc` board profile (examples/alarm) is added to each board for 
verification,
     and the board documentation is updated.
   
     ## Impact
   
     - New peripheral, opt-in via `CONFIG_AMEBA_RTC` (default n). No impact on
       existing configs.
     - Affects rtl8721dx / rtl8720f / rtl8721f only.
   
     ## 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 `rtc` config, exercising every driver path:
   
       - **Cold start / seeding**: on first power-up the RTC reads back the 
seeded
         build date instead of a pre-epoch value, so `date` is valid 
immediately.
       - **Read / set (`RTC_RD_TIME` / `RTC_SET_TIME` via NSH `date`)**: the
         year/day-of-year hardware model is correctly bridged to the full
         month/day calendar in both directions.
       - **Timekeeping**: consecutive `date` reads show the clock advancing in 
real
         time.
       - **Alarm (`RTC_SET_ALARM` + IRQ callback via `alarm` example)**: a 
one-shot
         alarm fires once at the requested offset and does not re-fire.
   
       Representative NSH session (rtl8721dx):
   
       nsh> date
       Tue, Jun 16 00:00:07 2026            # seeded build date after cold start
       nsh> date -s "Jun 16 12:00:00 2026"
       nsh> date
       Tue, Jun 16 12:00:06 2026            # set time read back (+ elapsed 
seconds)
       nsh> date
       Tue, Jun 16 12:00:09 2026            # clock advancing
       nsh> alarm 5
       alarm_daemon: Running
       Opening /dev/rtc0
       Alarm 0 set in 5 seconds
       alarm_daemon: alarm 0 received       # fires once, 5 s later


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to