This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 73f9ef00e2 net/can: fix timestamp
73f9ef00e2 is described below

commit 73f9ef00e2e887e056d3779ffed04fc122853fc9
Author: Javier Casas <javierca...@geotab.com>
AuthorDate: Fri Mar 7 09:40:59 2025 +0100

    net/can: fix timestamp
    
    Fix timestamp in socket CAN. Right now the timestamp is only generated
    if there is no reader and the frame is stored in the read ahead list.
    This is solved by moving the timestamp generation before the code flow
    branch.
    
    Signed-off-by: Javier Casas <javierca...@geotab.com>
---
 net/can/can_callback.c | 37 ++++++++++++++++---------------------
 1 file changed, 16 insertions(+), 21 deletions(-)

diff --git a/net/can/can_callback.c b/net/can/can_callback.c
index cc32cfd156..745c010a31 100644
--- a/net/can/can_callback.c
+++ b/net/can/can_callback.c
@@ -119,20 +119,6 @@ uint16_t can_callback(FAR struct net_driver_s *dev,
 
   if (conn)
     {
-      /* Try to lock the network when successful send data to the listener */
-
-      if (net_trylock() == OK)
-        {
-          flags = devif_conn_event(dev, flags, conn->sconn.list);
-          net_unlock();
-        }
-
-      /* Either we did not get the lock or there is no application listening
-       * If we did not get a lock we store the frame in the read-ahead buffer
-       */
-
-      if ((flags & CAN_NEWDATA) != 0)
-        {
 #ifdef CONFIG_NET_TIMESTAMP
           /* TIMESTAMP sockopt is activated,
            * create timestamp and copy to iob
@@ -150,18 +136,27 @@ uint16_t can_callback(FAR struct net_driver_s *dev,
               len = iob_trycopyin(dev->d_iob, (FAR uint8_t *)&tv,
                                   sizeof(struct timeval),
                                   -CONFIG_NET_LL_GUARDSIZE, false);
-              if (len != sizeof(struct timeval))
-                {
-                  dev->d_len = 0;
-                  return flags & ~CAN_NEWDATA;
-                }
-              else
+              if (len == sizeof(struct timeval))
                 {
                   dev->d_len += len;
                 }
             }
-
 #endif
+
+      /* Try to lock the network when successful send data to the listener */
+
+      if (net_trylock() == OK)
+        {
+          flags = devif_conn_event(dev, flags, conn->sconn.list);
+          net_unlock();
+        }
+
+      /* Either we did not get the lock or there is no application listening
+       * If we did not get a lock we store the frame in the read-ahead buffer
+       */
+
+      if ((flags & CAN_NEWDATA) != 0)
+        {
           /* Data was not handled.. dispose of it appropriately */
 
           flags = can_data_event(dev, conn, flags);

Reply via email to