Skip to content

rtc: write the RTC time only for years 2000-2099 - #105

Merged
liquidraver merged 1 commit into
liquidraver:devfrom
ptr727:rtc-year-range
Oct 7, 2026
Merged

liquidraver merged 1 commit into
liquidraver:devfrom
ptr727:rtc-year-range

Conversation

@ptr727

@ptr727 ptr727 commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Replaces #103, cut down to the year-range check as asked in #103 (comment). #103 stays as the record of the version coordinated with Zephyr and MeshCore.

The defect. ZephCore writes the RTC year as two BCD digits with no century, as y % 100. A time before 2000, accepted by a node whose clock had no time yet, was stored as a year near the end of the century and came back at the next boot above the 2025 floor: time 900000000 (1998) was restored as 2098.

The fix.

  • rtc_time_block() returns false outside 2000-2099.
  • zephcore_rtc_save() then logs time outside 2000-2099 not written and writes no time, for every chip, rv3028-eeprom-config included. The chip keeps the time it has.
  • rv3028_save_retry_fn() stops if its run-on time leaves the range.
  • One-line updates to the Kconfig help, the header, the zephcore,rtc-i2c binding and docs/ARCHITECTURE.md.

The RV3028 write sequence is unchanged: year 00h, then 00h-05h, then the year.

Other projects. Zephyr (zephyrproject-rtos/zephyr#121389) and MeshCore (meshcore-dev/MeshCore#3421) take the same 2000-2099 write range. They also write the RV3028 with an A0h year mark and one burst, which ZephCore does not take: its 2025 restore floor already rejects the year 2000 that a cut write leaves (the last test below). A mark left by either reads here as a non-BCD year, so it gives no time.

Testing. RAK4631 + RAK12002, repeater debug builds.

  • This commit, exact build: the boot restored 2026-10-07 14:17:31 UTC, and a CLI time then reboot restored the set time.
  • A test-only harness on this commit, which calls zephcore_rtc_save()/zephcore_rtc_restore() and writes the chip's registers, 14/14 PASS:
    • 500 restores, none failed or went backwards. 100 random save and restore pairs, exact to the second.
    • 2000-01-01 is written and gives no time (the floor). 2099-12-31 23:59:59 is written and restored.
    • 2100-01-01 and 1999-12-31 23:59:59 are not written: the chip kept 2030-01-01 00:00:00, and that was restored.
    • All FFh, year FFh, seconds 5Ah, month 13h, year A0h: no time.
    • The current write, its burst cut after three bytes by the chip's 950 ms bus timeout: year 00, no time at the next restore. A normal save recovers.

🤖 Generated with Claude Code

ZephCore writes the year as two BCD digits with no century, as y % 100.
A time before 2000, accepted by a node whose clock had no time yet, was
stored as a year near the end of the century and restored at the next
boot above the 2025 floor: `time 900000000` (1998) came back as 2098.

rtc_time_block() now fails outside 2000-2099, and zephcore_rtc_save()
then logs and writes no time, for every chip; the chip keeps the time it
has. An RV3028 write retry stops if its run-on time leaves the range.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Cancel pending RV3028 retries for out-of-range epochs to prevent stale time writes.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
What changed in this PR

Restricts RTC writes to years 2000–2099 to prevent century aliasing.

Changes:

  • Adds year-range validation for RTC writes and retries.
  • Updates RTC configuration, API, binding, and architecture documentation.
File Summary
zephcore/​Kconfig Documents the supported RTC write range.
zephcore/​dts/​bindings/​rtc/​zephcore,rtc-i2c.yaml Updates RTC behavior documentation.
zephcore/​adapters/​clock/​ZephyrRTCDiscover.h Documents the range-limited RTC persistence contract.
zephcore/​adapters/​clock/​ZephyrRTCDiscover.c Validates years and manages RTC writes and retries.
docs/​ARCHITECTURE.md Documents the RTC write restriction.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +686 to +689
if (!rtc_time_block(d, epoch, blk)) {
LOG_WRN("RTC %s: time outside 2000-2099 not written", d->name);
return;
}
@liquidraver
liquidraver merged commit 5dd3308 into liquidraver:dev Oct 7, 2026
1 check passed
@ptr727
ptr727 deleted the rtc-year-range branch October 8, 2026 20:56
ptr727 added a commit to ptr727/liquidraver-ZephCore that referenced this pull request Oct 10, 2026
Conflicts in ZephyrRTCDiscover.c/.h, from liquidraver#105 and liquidraver#106:
- the restore and rtc_identify() doc comments take dev's trimmed text; the
  identify comment keeps one clause for RTC_UNREAD versus -EIO;
- rtc_probe_run() records PRESENT, then runs dev's 12-hour clear, so a failed
  clear is still reported as present.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants