Skip to content

Commit

Permalink
mimxrt/machine_rtc: Set the microsecond value to 0.
Browse files Browse the repository at this point in the history
Set the subsecond value reported by rtc.datetime() and rtc.now() to 0.
Synchronizing the roll-over with the second change was not precise.
  • Loading branch information
robert-hh authored and dpgeorge committed Dec 14, 2022
1 parent 17ab2f6 commit 913f9ad
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions ports/mimxrt/machine_rtc.c
Expand Up @@ -38,7 +38,6 @@ typedef struct _machine_rtc_obj_t {

// Singleton RTC object.
STATIC const machine_rtc_obj_t machine_rtc_obj = {{&machine_rtc_type}};
uint32_t us_offset = 0;

// Start the RTC Timer.
void machine_rtc_start(void) {
Expand Down Expand Up @@ -83,7 +82,7 @@ STATIC mp_obj_t machine_rtc_datetime_helper(size_t n_args, const mp_obj_t *args)
mp_obj_new_int(srtc_date.hour),
mp_obj_new_int(srtc_date.minute),
mp_obj_new_int(srtc_date.second),
mp_obj_new_int((ticks_us64() + us_offset) % 1000000),
mp_obj_new_int(0),
};
return mp_obj_new_tuple(8, tuple);
} else {
Expand All @@ -104,7 +103,6 @@ STATIC mp_obj_t machine_rtc_datetime_helper(size_t n_args, const mp_obj_t *args)
if (SNVS_LP_SRTC_SetDatetime(SNVS, &srtc_date) != kStatus_Success) {
mp_raise_ValueError(NULL);
}
us_offset = (1000000 + mp_obj_get_int(items[7]) - ticks_us64() % 1000000) % 1000000;

return mp_const_none;
}
Expand All @@ -127,7 +125,7 @@ STATIC mp_obj_t machine_rtc_now(mp_obj_t self_in) {
mp_obj_new_int(srtc_date.hour),
mp_obj_new_int(srtc_date.minute),
mp_obj_new_int(srtc_date.second),
mp_obj_new_int((ticks_us64() + us_offset) % 1000000),
mp_obj_new_int(0),
mp_const_none,
};
return mp_obj_new_tuple(8, tuple);
Expand Down

0 comments on commit 913f9ad

Please sign in to comment.