PM5: read a coherent RTC snapshot in GetTickCount
Read SBS before TIME/DATE to latch a coherent snapshot in synchronous ERTC mode. A rollover between the previous calendar and subsecond reads could move the tick count backwards and cause false receive timeouts. Preserve millisecond conversion and shared delta-helper semantics. Add actual-source rollover, conversion and register-locking coverage. Leave acquisition limits and RF timing unchanged. Co-Authored-By: OpenAI coding assistant <noreply@openai.com> Signed-off-by: nip <182409448+nip-was-here@users.noreply.github.com>
This commit is contained in:
1 parent
e519c1af94
commit
5f54706c18
4 files changed
+205
-1
No files matched your search
@@ -148,6 +148,8 @@ void StartTickCount(void) {
|
||||
// Get the current count.
|
||||
uint32_t RAMFUNC GetTickCount(void) {
|
||||
ertc_time_type time;
|
||||
// Read SBS first to latch TIME/DATE until the calendar getter reads DATE.
|
||||
uint32_t subsecond = ERTC->sbs;
|
||||
ertc_calendar_get(&time);
|
||||
return mktime_utc_fast(
|
||||
// time.year is short length, not full, so 2025 is 25.
|
||||
@@ -156,7 +158,7 @@ uint32_t RAMFUNC GetTickCount(void) {
|
||||
time.month, time.day, time.hour, time.min, time.sec,
|
||||
// this ms is from 0 -> 1000 of second, not timestamp value
|
||||
// ms = ((divb + 1) - subsecond * 1000) / (divb + 1)
|
||||
(3125 - ertc_sub_second_get()) * 1000 / 3125) - tick_start_val; // current - start = tick
|
||||
(3125 - subsecond) * 1000 / 3125) - tick_start_val; // current - start = tick
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user