icyphy / lf-buckler

Programming an nRF embedded board with a Berkeley Buckler daughter card using Lingua Franca.
BSD 2-Clause "Simplified" License
7 stars 0 forks source link

Mutexes to support asychronous calls to lf_schedule #12

Closed edwardalee closed 2 years ago

edwardalee commented 2 years ago

PR #11 gave us a stopgap solution towards enabling interrupt service routines to call lf_schedule by disabling all application interrupts except during calls to nanosleep. But this may lead to excessively coarse timing. It would be better if the unthreaded runtime of reactor-c supported "critical sections" and this lf-buckler repo provided an implementation that disables interrupts. See https://github.com/lf-lang/reactor-c/issues/104

edwardalee commented 2 years ago

The problem with this solution is not just coarse timing, but there are certain functions that need to be called in reactions that need for interrupts to be enabled. An example is in the library reactor src/lib/IMU.lf, which now has a (dangerous) temporary workaround pending the right fix with critical sections. The IMU.lf reactor enables interrupts, makes a blocking call to read I/O, then disables interrupts. This opens up the possibility of another ISR getting invoked and the event queue getting corrupted, so this needs to be fixed soon.