Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix uptime: RTC overflow is counted twice #190

Open
eflukx opened this issue Sep 26, 2022 · 0 comments
Open

Fix uptime: RTC overflow is counted twice #190

eflukx opened this issue Sep 26, 2022 · 0 comments

Comments

@eflukx
Copy link

eflukx commented Sep 26, 2022

I noticed the 'DK' board implementation uptime function is broken and the uptime runs in double time. This is caused by the overflow interrupt being triggered twice. Here's a proposed patch that fixes it for me:

old handler:

#[interrupt]
fn RTC0() {
    let curr = OVERFLOWS.load(Ordering::Relaxed);
    OVERFLOWS.store(curr + 1, Ordering::Relaxed);

    // clear the EVENT register
    unsafe { core::mem::transmute::<_, RTC0>(()).events_ovrflw.reset() }
}

my replacement code (that checks whether the overflow bit is set):

#[interrupt]
fn RTC0() {
    unsafe {
        let rtc = core::mem::transmute::<_, RTC0>(());

        if rtc.events_ovrflw.read().events_ovrflw().bit_is_set() {
            OVERFLOWS.fetch_add(1, Ordering::Relaxed);
            rtc.events_ovrflw.reset()
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant