KevinOConnor / can2040

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

Reduce tx scheduling latency in some cases #17

Closed KevinOConnor closed 1 year ago

KevinOConnor commented 1 year ago

Currently, if there are no tx messages pending after an rx or tx notify callback is processed, then the next time the code will check for a new transmit is after the line goes idle. If a user notification callback sets a flag in memory, processes the notification outside the irq handler (which is recommended), and schedules a transmission as a result, then that transmit will only occur after the bus goes idle. If the bus has high utilization, then it is possible a lower priority message may get access to the bus before the local message (with potentially higher priority) can be transmitted.

Similarly, if the code goes into a DISCARD state (eg, because of a CANFD transmission from some other node to some other node) then it will currently only schedule a tx message after the bus goes idle.

This PR changes can2040 so that it can respond with lower latency in the above "corner cases".

Although the code changes in this PR are modest, the increase in complexity of the report_state tracking is notable. I'm not sure it is worthwhile. I'm providing this PR for those interested in testing.

This PR is based on top of PR #15 and PR #16 for ease of testing. It is not related to those PRs.

-Kevin

KevinOConnor commented 1 year ago

I made some changes to report_state to make its handling a little more transparent (commit e509ac03). I think those changes help alleviate the complexity introduced by this PR. As a result, I'm inclined to merge this PR.

-Kevin