darrylring opened a new pull request, #21020:
URL: https://github.com/apache/nuttx/pull/21020

   ## Summary
   
   Add support for the CANIOC_SET_NART ioctl which controls whether or not the 
FDCAN peripheral automatically resends frames that lose arbitration or hit bus 
errors. On the STM32H5's FDCAN peripheral (M_CAN) this is DAR (disable 
automatic retry) mode.
   
   Frames dropped in DAR mode don't trigger TC (transmit complete) or TCF 
(transmit cancellation finished) interrupts, but they do empty the TX FIFO and 
trigger TFE (transmit FIFO empty). Currently `can_txdone` is only called on TC 
interrupts, so the transmit queue fills up and eventually `write` blocks. They 
also don't set TXBTO (transmission occurred) so the existing logic still 
wouldn't work.
   
   Instead, keep track of busy transmit buffers and ensure they are marked done 
when transmit is complete, manually cancelled, or automatically cancelled.
   
   ## Impact
   
   The existing transmit completion handling has been modified:
   
   1. Transmit completion is now tracked by the driver instead of relying on 
the TXBTO register.
   2. Interrupts are enabled on all transmit buffers on each send.
   3. Transmit complete interrupt handler runs for TFE, but does not enable 
error interrupts on TFE only.
   4. `fdcan_txready` returns false if a buffer is still in `txbusy` because 
hardware can free a buffer before its completion.
   5. `fdcan_txempty` only returns true if `txbusy == 0` which (due to the 
previous note) may mean slightly more time before reporting empty (actual 
completion, not reported completion).
   
   ## Testing
   
   ### The basic functionality
   
   Sending a frame on an empty bus (no ACK) - before
   
   <img width="1024" height="600" alt="image" 
src="https://github.com/user-attachments/assets/96bdffd6-9d01-4c96-944a-632c51afeb67";
 />
   
   Sending a frame on an empty bus (no ACK) - after
   
   <img width="1024" height="600" alt="image" 
src="https://github.com/user-attachments/assets/9734cde1-d26a-4694-8431-664d8c31cbe0";
 />
   
   ### Stress testing
   
   A simple NSH app sends frames as quickly as possible with and without 
automatic resends and measure how long `write` takes to run. A CAN-USB adapter 
is used to record the traffic and also to send frames to cause the board to 
lose arbitration periodically. The goal here is to ensure that `write` never 
blocks, frames don't arrive out of order, and `close` never hangs.
   
   Cases:
   
   * A: send 100,000 frames, receive with candump, automatic resend ON
   * B: send 100,000 frames, receive with candump, cangen sending higher 
priority traffic, automatic resend ON
   * B: send 100,000 frames, receive with candump, cangen sending higher 
priority traffic, automatic resend OFF
   
   
[candump_logs.zip](https://github.com/user-attachments/files/33982689/candump_logs.zip)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to