Skip to content

EventLoop receives callbacks one event late when setting FuriEventFlag from interrupts  #4336

@sorgloomer

Description

@sorgloomer

Describe the bug.

I have created a FAP app that handles GPIO interrupts by delegating the events to an FuriEventLoop with furi_event_loop_subscribe_event_flag.

Interestingly, it seems that every furi_event_flag_set event is delayed, and is delivered after the very next set to the same FuriEventFlag. I only call furi_event_flag_set methods from interrupts.

After the very first interrupt the FuriEventLoop does not wake up, and then somehow on every subsequent set it wakes up, and when the handler runs and attempts to get the new flag value, it receives exactly the previous value.

I have created an example to demonstrate the issue.

The application sets interrupts for the left and right input GPIOs. When a button is pressed, the interrupt writes the L or R letters into a buffer„and calls furi_event_loop_set. Then the handler in the event loop gets the flags with either furi_event_flag_get or furi_event_flag_clear, and based on the received flags, it appends the same L or R character to another buffer. These buffers are printed to the gui. I have the same problem with other interrupts too.

Image

https://github.com/sorgloomer/flipper_eventflag_demo

I am using a periodic timer to redraw the text unconditionally to make sure the problem is not in my gui programming.

Reproduction

  1. Instantiate FuriEventLoop and FuriEventFlag
  2. Subscribe to the event with furi_event_loop_subscribe_event_flag
  3. Subscribe to an interrupt with furi_event_loop_subscribe_event_flag
  4. Use furi_event_flag_set in the interrupt handler
  5. Use furi_event_flag_wait in the event handler to get and reset the flags
  6. Observe that the individual events arrive late to the interrupts, one interrupt late, in lockstep.

Target

No response

Logs


Anything else?

No response

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