pico-sdk
pico-sdk copied to clipboard
Improve best_effort_wfe_or_timeout
Fix some parts of #1812
The problem with the rewrite of the alarm pool code is that adding an alarm forces an IRQ which cases a SEV. We attempted to fix this in best_effort_wfe_or_timeout
by consuming the event then doing a WFE again. This is clearly wrong if the event was set prior to the call.
The best we can do (since we cant tell whether an WFE will block) is to only add the alarm if there isn't an IRQ (we only check this alarm pool alarm) already set to happen on or before the target time (which will cause a SEV). This means that the first call will to this method will always return, but when used in a loop, the second will do the right thing.
This is OK as the prescribed behavior is to use the method in a polling loop