Skip to content

Time going backwards: aon_timer_get_time() [SDK 2.1.1] #2374

@tjko

Description

@tjko

After upgrading from SDK version 2.1.0 to 2.1.1, I noticed weird behavior with aon_timer_get_time() on RP2040 (pico_w).
Time returned seems to randomly go backwards (and forwards) 1 hour.

I have a project that displays clock (among other things) on OLED panel, and after upgrading to new SDK (2.1.1), I noticed hour digit was randomly toggling back and forth.

So I added some 'debug' output in the function that gets the current (RTC) time:

time went backwards: 1743055938 -> 1743052339 (delta=3599)
time went backwards: 1743055948 -> 1743052349 (delta=3599)
time went backwards: 1743055953 -> 1743052354 (delta=3599)
time went backwards: 1743055970 -> 1743052371 (delta=3599)
time went backwards: 1743055973 -> 1743052374 (delta=3599)
time went backwards: 1743055990 -> 1743052391 (delta=3599)
time went backwards: 1743056009 -> 1743052410 (delta=3599)
time went backwards: 1743056041 -> 1743052442 (delta=3599)
time went backwards: 1743056082 -> 1743052483 (delta=3599)
time went backwards: 1743056116 -> 1743052517 (delta=3599)
time went backwards: 1743056123 -> 1743052524 (delta=3599)
time went backwards: 1743056126 -> 1743052527 (delta=3599)
time went backwards: 1743056148 -> 1743052549 (delta=3599)
time went backwards: 1743056156 -> 1743052557 (delta=3599)

This is from the function shown below (that gets called about once a second):

bool rtc_get_time(time_t *t)
{
        static time_t old_t = 0;
        struct timespec ts;
        time_t new_t;

        if (!t || !aon_timer_is_running())
                return false;

        if (!aon_timer_get_time(&ts))
                return false;
        new_t = ts.tv_sec;

        if (old_t > new_t) {
                printf("time went backwards: %lld -> %lld (delta=%lld)\n", old_t, new_t, old_t - new_t);
        }
        old_t = new_t;

        *t = new_t;

        return true;
}

(switching back to SDK 2.1.0 seems to "fix" the issue)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions