Closed KevinOConnor closed 1 year ago
Since can2040_stop()
is implied to be the inverse of the start function, would it make sense to clear the pio's instruction memory as well?
Thanks for reviewing. The current implementation of can2040_stop()
on this PR just disables the PIO irq and makes sure the CAN Tx line is high (it doesn't even stop the PIO). The goal is to provide a mechanism to safely stop processing CAN messages (safe with respect to race conditions with irq handling) while also keeping the code simple.
It is possible to write code that would fully stop the PIO and clear the PIO state, but I'm not sure what value that would provide. If some other code wants to use the PIO it can perform a hardware reset on the PIO itself.
Cheers, -Kevin
Hey! Thanks for the added context. I went ahead and tested the code and it appears to be correctly working as your described.
Thanks for testing. I committed this PR.
-Kevin
This adds an API function to stop CAN bus processing. The new
can2040_stop()
effectively does the inverse ofcan2040_start()
. After stopping, one may callcan2040_start()
again, or fully clear the transmit queue and restart by redoing the init starting fromcan2040_setup()
. See the updated API documentation on this branch for further details.I don't have a good way to test this code right now. I'm posting it in case others are looking for this functionality.
-Kevin