diff options
| author | robert-hh <robert@hammelrath.com> | 2021-06-12 08:45:01 +0200 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2021-06-12 23:20:12 +1000 |
| commit | 3ab8806c0d2fe77e9785216563b419cfadff71b0 (patch) | |
| tree | 3fe3465eb26310eca2932d39a52b59badad0d45d | |
| parent | fd4eec5555f93950ee14a45851d13ab7b781077e (diff) | |
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.
| -rw-r--r-- | ports/mimxrt/machine_rtc.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/ports/mimxrt/machine_rtc.c b/ports/mimxrt/machine_rtc.c index 4c88466cf..4de3419c1 100644 --- a/ports/mimxrt/machine_rtc.c +++ b/ports/mimxrt/machine_rtc.c @@ -37,6 +37,7 @@ 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; // Calculate the weekday from the date. // 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) 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() % 1000000), + mp_obj_new_int((ticks_us64() + us_offset) % 1000000), }; return mp_obj_new_tuple(8, tuple); } else { @@ -91,6 +92,7 @@ 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; } |
