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

   ## Summary
   
   Add a synchronous receive callback for SocketCAN connections and two         
                                                                                
                                               
   CAN ioctl commands, ported from a downstream branch onto the current         
                                                                                
                                               
   SocketCAN architecture.                                                      
                         
                                                                                
                         
   - **net/can: add rx sync callback support**                                  
                                                                                
                                               
     Add an optional per-connection synchronous receive callback                
                         
     (`can_set_rx_callback()` / `can_rx_cb_t`).  When registered,               
                         
     `can_input()` delivers each received frame to the callback directly;       
                         
     returning OK consumes the frame so it is not queued to the read-ahead      
                                                                                
                                               
     path.  Otherwise the normal per-protocol `conn->input()` hook runs as      
                         
     before.                                                                    
                         
                                                                                
                         
   - **net/can: fix the problem of nested tx in the rxcb process**              
                                                                                
                                               
     If the callback transmits from inside `can_input()`, the nested send
     would reuse `dev->d_iob`/`dev->d_buf`.  Detach the buffer before the
     callback and restore it with `netdev_iob_replace()` afterwards.
   
   - **net/can: add can ioctl cmd SIOCCANOFLUSH**
     Flush data written but not yet transmitted.
   
   - **net/can: add can transceiver state ioctl cmd**
     `SIOCGCANTRSVSTATE` / `SIOCSCANTRSVSTATE` get and set the CAN/LIN
     transceiver state (sleep/standby/normal), carried in a new
     `can_ioctl_transv_state_s` member of the ifreq/lifreq union.
   
   ## Impact
   
   - No change for connections that do not register a callback
     (`rxcb == NULL` runs the existing `conn->input()` path).
   - Adds three ioctl commands; `struct ifreq`/`struct lifreq` gain one new
     union member (`ifru_can_transv_state`).
   
   ## Testing
   
   Built and run on the simulator (flat build).
   
   Build / style:
   - `./tools/configure.sh sim:lely-sock` + `NET_CAN_RAW` + `NET_CAN_ISOTP`
     — make and link succeed.
   - `./tools/checkpatch.sh -c -m -g HEAD~4..HEAD` — passes (no style issues).
   
   Runtime (sim:lely-sock, SIM_CANDEV_SOCK bridged to a host vcan "can0"):
   
       nsh> ifup can0
       nsh> canloop
       canloop: looped id=0x321 data=cafebabe PASS
   
   This exercises the normal CAN raw TX/RX path (write + loopback read) to
   confirm the `conn->input()` dispatch is unchanged when no rx callback is
   registered.
   
   


-- 
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