Output reference clock and application time in 'ethercat Master'.
authorFlorian Pose <fp@igh-essen.com>
Fri, 24 Apr 2009 08:39:20 +0000
changeset 1415 9d1cdbf41247
parent 1414 0037a63d3cc5
child 1416 85d20ae6736e
Output reference clock and application time in 'ethercat Master'.
TODO
master/cdev.c
master/ioctl.h
master/master.c
tool/CommandMaster.cpp
--- a/TODO	Thu Apr 23 14:50:23 2009 +0000
+++ b/TODO	Fri Apr 24 08:39:20 2009 +0000
@@ -12,8 +12,13 @@
 
 * Distributed clocks:
     - Delay calculation.
-	- Output reference clock and application time in 'ethercat master'.
     - User same application time offset when setting start times.
+    - Replace timeval by uint64 EtherCAT time.
+* Fix arguments of reg_read.
+* Sign/Abs type for reg_ commands?
+* Number layout for reg_read.
+* Show Record / Array / List type of SDOs.
+* Limit bandwidth of state machine datagram.
 * Read alias from register 0x0012 instead of SII.
 * Finish library implementation.
 * Re-work EoE code.
--- a/master/cdev.c	Thu Apr 23 14:50:23 2009 +0000
+++ b/master/cdev.c	Fri Apr 24 08:39:20 2009 +0000
@@ -173,6 +173,7 @@
 
     if (down_interruptible(&master->device_sem))
         return -EINTR;
+
     if (master->main_device.dev) {
         memcpy(data.devices[0].address,
                 master->main_device.dev->dev_addr, ETH_ALEN);
@@ -194,8 +195,16 @@
     data.devices[1].link_state = master->backup_device.link_state ? 1 : 0;
     data.devices[1].tx_count = master->backup_device.tx_count;
     data.devices[1].rx_count = master->backup_device.rx_count;
+
     up(&master->device_sem);
 
+    data.app_time = master->app_time;
+    data.ref_clock = EC_READ_U16(master->sync_datagram.address);
+    if (data.ref_clock < 0xffff) {
+        // ref_clock address is station_address, output ring position
+        data.ref_clock--;
+    }
+
     if (copy_to_user((void __user *) arg, &data, sizeof(data)))
         return -EFAULT;
 
--- a/master/ioctl.h	Thu Apr 23 14:50:23 2009 +0000
+++ b/master/ioctl.h	Fri Apr 24 08:39:20 2009 +0000
@@ -136,6 +136,8 @@
         uint32_t tx_count;
         uint32_t rx_count;
     } devices[2];
+    uint64_t app_time;
+    uint16_t ref_clock;
 } ec_ioctl_master_t;
 
 /*****************************************************************************/
--- a/master/master.c	Thu Apr 23 14:50:23 2009 +0000
+++ b/master/master.c	Fri Apr 24 08:39:20 2009 +0000
@@ -622,6 +622,8 @@
     }
 #endif
 
+    master->app_time = 0ULL;
+
     if (ec_master_thread_start(master, ec_master_idle_thread,
                 "EtherCAT-IDLE"))
         EC_WARN("Failed to restart master thread!\n");
--- a/tool/CommandMaster.cpp	Thu Apr 23 14:50:23 2009 +0000
+++ b/tool/CommandMaster.cpp	Fri Apr 24 08:39:20 2009 +0000
@@ -33,6 +33,8 @@
 
 #include "CommandMaster.h"
 
+#define MAX_TIME_STR_SIZE 50
+
 /*****************************************************************************/
 
 CommandMaster::CommandMaster():
@@ -65,6 +67,9 @@
     ec_ioctl_master_t data;
     stringstream err;
     unsigned int i;
+    time_t epoch;
+    char time_str[MAX_TIME_STR_SIZE + 1];
+    size_t time_str_size;
     
     if (args.size()) {
         err << "'" << getName() << "' takes no arguments!";
@@ -86,10 +91,11 @@
     }
 
     cout << endl
-        << "  Slaves: " << data.slave_count << endl;
+        << "  Slaves: " << data.slave_count << endl
+        << "  Ethernet devices:" << endl;
 
     for (i = 0; i < 2; i++) {
-        cout << "  Device" << i << ": ";
+        cout << "    " << (i == 0 ? "Main" : "Backup") << ": ";
         if (data.devices[i].address[0] == 0x00
                 && data.devices[i].address[1] == 0x00
                 && data.devices[i].address[2] == 0x00
@@ -107,12 +113,29 @@
                 << setw(2) << (unsigned int) data.devices[i].address[5] << " ("
                 << (data.devices[i].attached ? "attached" : "waiting...")
                 << ")" << endl << dec
-                << "    Link: " << (data.devices[i].link_state ? "UP" : "DOWN") << endl
-                << "    Tx count: " << data.devices[i].tx_count << endl
-                << "    Rx count: " << data.devices[i].rx_count;
+                << "      Link: " << (data.devices[i].link_state ? "UP" : "DOWN") << endl
+                << "      Tx count: " << data.devices[i].tx_count << endl
+                << "      Rx count: " << data.devices[i].rx_count;
         }
         cout << endl;
     }
+
+    cout << "  Distributed clocks:" << endl
+        << "    Reference clock: ";
+    if (data.ref_clock != 0xffff) {
+        cout << "Slave " << dec << data.ref_clock;
+    } else {
+        cout << "None";
+    }
+    cout << endl
+        << "    Application time: " << data.app_time << endl
+        << "                      ";
+
+    epoch = data.app_time / 1000000000 + 946684800ULL;
+    time_str_size = strftime(time_str, MAX_TIME_STR_SIZE,
+            "%Y-%m-%d %H:%M:%S", gmtime(&epoch));
+    cout << string(time_str, time_str_size) << "."
+        << setfill('0') << setw(9) << data.app_time % 1000000000 << endl;
 }
 
 /*****************************************************************************/