Closed ids1024 closed 9 months ago
I don't object to this, but I also have never heard of this crate before. I guess this is just a commonly used utility crate?
Interrupts actually happen with interrupts disabled (in the program status register) by default, and then our asm interrupt handler re-enabled interrupts as part of switching to System mode for the Rust interrupt handler to run.
I coulda sworn we had a utility fn to cleanly do a swp
instruction, but I don't see it anywhere, if we did have it.
Yeah, it seems to be commonly provided by basically all the hal crates (or one of their dependencies, anyway).
It sounds useful for creating portable abstractions, and in particular I see embassy-executor and embassy-time seem to use it, so presumably a backend like this would be needed to use those with gba
.
Looking at git log -G swp
, there were a couple swp
related functions before bf853b71d6628bc659270a4b2ea317bf4f103b2f.
This is similar to the single-threaded bare metal implementations in
cortex-m
andriscv
.In theory there could be a race condition in
acquire
if an interrupt occurs between theread
andwrite
, and the interrupt disablesIME
. But it's probably not sensible to have an interrupt disable interrupts, so I don't think it's necessarily to complicate things with inline assembly usingswp
.