]> rtime.felk.cvut.cz Git - can-utils.git/commitdiff
candump: Enable HW timestamping before using it master
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 26 Aug 2016 13:08:20 +0000 (15:08 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 26 Aug 2016 13:08:20 +0000 (15:08 +0200)
If HW timestamping is not supported by the driver, candump exits with
an error message.

Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>
candump.c

index bd9a3cdab6bdc4316d32504060dc6d66b34331b4..c983b71186eaaef1e8b896b96443e4edf611e8b1 100644 (file)
--- a/candump.c
+++ b/candump.c
 #include "terminal.h"
 #include "lib.h"
 
+#ifndef SIOCSHWTSTAMP
+# define SIOCSHWTSTAMP 0x89b0
+#endif
+
 #define MAXSOCK 16    /* max. number of CAN interfaces given on the cmdline */
 #define MAXIFNAMES 30 /* size of receive name index to omit ioctls */
 #define MAXCOL 6      /* number of different colors for colorized output */
@@ -564,6 +568,21 @@ int main(int argc, char **argv)
                                        return 1;
                                }
                        } else {
+                               struct ifreq hwtstamp;
+                               struct hwtstamp_config hwconfig;
+
+                               memset(&hwtstamp, 0, sizeof(hwtstamp));
+                               strncpy(hwtstamp.ifr_name, ifr.ifr_name, sizeof(hwtstamp.ifr_name));
+                               hwtstamp.ifr_data = (void *)&hwconfig;
+                               memset(&hwconfig, 0, sizeof(hwconfig));
+                               hwconfig.tx_type = HWTSTAMP_TX_OFF;
+                               hwconfig.rx_filter = HWTSTAMP_FILTER_ALL;
+
+                               if (ioctl(s[i], SIOCSHWTSTAMP, &hwtstamp) < 0) {
+                                       perror("SIOCSHWTSTAMP");
+                                       return 1;
+                               }
+
                                const int so_timestamping_flags = SOF_TIMESTAMPING_RAW_HARDWARE;
 
                                if (setsockopt(s[i], SOL_SOCKET, SO_TIMESTAMPING,