Skip to content

It's not clear why is the cur_count guard is needed in the count-debounce example in ch. 15 #108

Description

@vittorius

The main loop in the count-debounce example looks like the following:

let mut cur_count = 0;
loop {
    // "wait for interrupt": CPU goes to sleep until an interrupt.
    asm::wfi();
    let count = COUNTER.load(Acquire);
    if count > cur_count {
        rprintln!("ouch {}", count);
        cur_count = count;
    }
}

There is no explanation for the role of the cur_count. When I try to remove it, it seems that the timer is not enough to "synchronize" the main loop with the interrupt handler: pressing the Button A gives 2 prints of the counter sometimes. If I try to increase the debounce timer interval, it's still 2 prints but with the same counter value. And wrapping rprintln! into the GPIOTE peripheral mutex lock doesn't help either. I'm curious about what's happening there and if we can improve the explanation.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions