KevinOConnor / can2040

Software CAN bus implementation for rp2040 micro-controllers
GNU General Public License v3.0
667 stars 66 forks source link

Fix check for "tx_conflict" #36

Closed KevinOConnor closed 1 year ago

KevinOConnor commented 1 year ago

The code was not properly detecting a "tx conflict" condition on transmits. As a result, the code may not reattempt a failed transmission until some other node on the canbus initiates a transmit. If no other node attempts a transmit for an extended period of time it could result in can2040 "locking up" for that extended duration.

The error was due to the PIO hardware reporting of the active instruction address. On an "irq wait" command it was reporting the address of the next instruction.

Update the PIO tx state machine to use the PIO "address wrap" system so that the address is reported as the "tx_conflict" address before and after the "irq wait" instruction. Update the PIO tx state machine to loop on the "tx_conflict" address. This allows the host software to correctly identify if the tx state machine has observed a transmit bit conflict.

-Kevin

EDIT: Minor change to the implementation of the fix.