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

michallenc 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 6cd82dfe29f arch/sim: Fill in the CAN RX timestamp in sim_canchar.
6cd82dfe29f is described below

commit 6cd82dfe29f3645f3e3e3b57b43c0cb2379cc843
Author: raiden00pl <[email protected]>
AuthorDate: Sat Oct 10 15:40:07 2026 +0200

    arch/sim: Fill in the CAN RX timestamp in sim_canchar.
    
    With CONFIG_CAN_TIMESTAMP, can_hdr_s.ch_ts is a struct timeval and
    "hdr.ch_ts = 0" does not compile.  Stamp received frames with
    CLOCK_MONOTONIC instead.
    
    Assisted-by: Claude:claude-opus-5-5
    Signed-off-by: raiden00pl <[email protected]>
---
 arch/sim/src/sim/sim_canchar.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/sim/src/sim/sim_canchar.c b/arch/sim/src/sim/sim_canchar.c
index 572922a0cba..49c574c7ecd 100644
--- a/arch/sim/src/sim/sim_canchar.c
+++ b/arch/sim/src/sim/sim_canchar.c
@@ -26,7 +26,9 @@
 
 #include <nuttx/debug.h>
 #include <stdio.h>
+#include <time.h>
 
+#include <nuttx/clock.h>
 #include <nuttx/kmalloc.h>
 #include <nuttx/wqueue.h>
 
@@ -290,6 +292,9 @@ static void sim_can_work(void *arg)
   struct sim_canchar_s *priv = arg;
   struct canfd_frame    frame;
   struct can_hdr_s      hdr;
+#ifdef CONFIG_CAN_TIMESTAMP
+  struct timespec       ts;
+#endif
   int                   ret;
 
   /* Drain all frames queued on the host socket, otherwise only one frame
@@ -325,7 +330,9 @@ static void sim_can_work(void *arg)
 #endif
       hdr.ch_tcf   = 0;
 #ifdef CONFIG_CAN_TIMESTAMP
-      hdr.ch_ts    = 0;
+      clock_gettime(CLOCK_MONOTONIC, &ts);
+      hdr.ch_ts.tv_sec  = ts.tv_sec;
+      hdr.ch_ts.tv_usec = ts.tv_nsec / NSEC_PER_USEC;
 #endif
 
       /* Notify upper-half */

Reply via email to