Skip to content

Commit 3ab8806

Browse files
robert-hhdpgeorge
authored andcommitted
mimxrt/machine_rtc: Maintain microsecond offset.
The supplied value for microseconds in datetime() will be treated as a starting value for the reported microseconds. Due to internal processing in setting the time, there is an offset about 1 ms.
1 parent fd4eec5 commit 3ab8806

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

ports/mimxrt/machine_rtc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ typedef struct _machine_rtc_obj_t {
3737

3838
// Singleton RTC object.
3939
STATIC const machine_rtc_obj_t machine_rtc_obj = {{&machine_rtc_type}};
40+
uint32_t us_offset = 0;
4041

4142
// Calculate the weekday from the date.
4243
// The result is zero based with 0 = Monday.
@@ -70,7 +71,7 @@ STATIC mp_obj_t machine_rtc_datetime_helper(size_t n_args, const mp_obj_t *args)
7071
mp_obj_new_int(srtc_date.hour),
7172
mp_obj_new_int(srtc_date.minute),
7273
mp_obj_new_int(srtc_date.second),
73-
mp_obj_new_int(ticks_us64() % 1000000),
74+
mp_obj_new_int((ticks_us64() + us_offset) % 1000000),
7475
};
7576
return mp_obj_new_tuple(8, tuple);
7677
} else {
@@ -91,6 +92,7 @@ STATIC mp_obj_t machine_rtc_datetime_helper(size_t n_args, const mp_obj_t *args)
9192
if (SNVS_LP_SRTC_SetDatetime(SNVS, &srtc_date) != kStatus_Success) {
9293
mp_raise_ValueError(NULL);
9394
}
95+
us_offset = (1000000 + mp_obj_get_int(items[7]) - ticks_us64() % 1000000) % 1000000;
9496

9597
return mp_const_none;
9698
}

0 commit comments

Comments
 (0)