Separated application time from synchronizing reference clock.
authorFlorian Pose <fp@igh-essen.com>
Mon, 04 May 2009 10:05:55 +0000
changeset 1434 4c6fe0ae37f1
parent 1433 a7320cd4ede6
child 1435 f1df39224f49
Separated application time from synchronizing reference clock.
examples/dc_rtai/dc_rtai_sample.c
examples/dc_user/main.c
include/ecrt.h
lib/master.c
master/cdev.c
master/ioctl.h
master/master.c
--- a/examples/dc_rtai/dc_rtai_sample.c	Mon May 04 10:05:02 2009 +0000
+++ b/examples/dc_rtai/dc_rtai_sample.c	Mon May 04 10:05:55 2009 +0000
@@ -51,7 +51,7 @@
 
 #define NUM_DIG_OUT 1
 
-#define PFX "ec_dc_sample: "
+#define PFX "ec_dc_rtai_sample: "
 
 /*****************************************************************************/
 
@@ -220,16 +220,13 @@
             tv.tv_usec -= 1000000;
             tv.tv_sec++;
         }
+        ecrt_master_application_time(master, EC_TIMEVAL2NANO(&tv));
             
         if (sync_ref_counter) {
             sync_ref_counter--;
         } else {
             sync_ref_counter = 9;
-#if 0
-            printk(KERN_INFO PFX "ref: %u %u %llu\n",
-                    (u32) tv.tv_sec, (u32) tv.tv_usec, EC_TIMEVAL2NANO(&tv));
-#endif
-            ecrt_master_sync_reference_clock(master, EC_TIMEVAL2NANO(&tv));
+            ecrt_master_sync_reference_clock(master);
         }
 		ecrt_master_sync_slave_clocks(master);
         ecrt_domain_queue(domain1);
--- a/examples/dc_user/main.c	Mon May 04 10:05:02 2009 +0000
+++ b/examples/dc_user/main.c	Mon May 04 10:05:55 2009 +0000
@@ -164,12 +164,13 @@
         app_time.tv_usec -= 1000000;
         app_time.tv_sec++;
     }
+    ecrt_master_application_time(master, EC_TIMEVAL2NANO(&app_time));
 
     if (sync_ref_counter) {
         sync_ref_counter--;
     } else {
         sync_ref_counter = 9;
-        ecrt_master_sync_reference_clock(master, EC_TIMEVAL2NANO(&app_time));
+        ecrt_master_sync_reference_clock(master);
     }
     ecrt_master_sync_slave_clocks(master);
 
--- a/include/ecrt.h	Mon May 04 10:05:02 2009 +0000
+++ b/include/ecrt.h	Mon May 04 10:05:55 2009 +0000
@@ -520,17 +520,29 @@
         ec_master_state_t *state /**< Structure to store the information. */
         );
 
-/** Queues the DC reference clock drift compensation datagram for sending.
- *
- * The reference clock will by synchronized to the \a app_time. The time is
- * defined as nanoseconds from 2000-01-01 00:00. Converting an epoch time can
- * be done with the EC_TIMEVAL2NANO() macro.
- */
-void ecrt_master_sync_reference_clock(
+/** Sets the application time.
+ *
+ * The master has to know the application time when operation slaves with
+ * distributed clocks. The time is not incremented by the master, so this
+ * method has to be called cyclically.
+ * 
+ * The time is defined as nanoseconds from 2000-01-01 00:00. Converting an
+ * epoch time can be done with the EC_TIMEVAL2NANO() macro.
+ */
+void ecrt_master_application_time(
         ec_master_t *master, /**< EtherCAT master. */
         uint64_t app_time /**< Application time. */
         );
 
+/** Queues the DC reference clock drift compensation datagram for sending.
+ *
+ * The reference clock will by synchronized to the application time provided
+ * by the last call off ecrt_master_application_time().
+ */
+void ecrt_master_sync_reference_clock(
+        ec_master_t *master /**< EtherCAT master. */
+        );
+
 /** Queues the DC clock drift compensation datagram for sending.
  *
  * All slave clocks synchronized to the reference clock.
--- a/lib/master.c	Mon May 04 10:05:02 2009 +0000
+++ b/lib/master.c	Mon May 04 10:05:55 2009 +0000
@@ -190,13 +190,23 @@
 
 /*****************************************************************************/
 
-void ecrt_master_sync_reference_clock(ec_master_t *master, uint64_t app_time)
-{
-    ec_ioctl_dc_t data;
+void ecrt_master_application_time(ec_master_t *master, uint64_t app_time)
+{
+    ec_ioctl_app_time_t data;
 
     data.app_time = app_time;
 
-    if (ioctl(master->fd, EC_IOCTL_SYNC_REF, &data) == -1) {
+    if (ioctl(master->fd, EC_IOCTL_APP_TIME, &data) == -1) {
+        fprintf(stderr, "Failed to set application time: %s\n",
+                strerror(errno));
+    }
+}
+
+/*****************************************************************************/
+
+void ecrt_master_sync_reference_clock(ec_master_t *master)
+{
+    if (ioctl(master->fd, EC_IOCTL_SYNC_REF, NULL) == -1) {
         fprintf(stderr, "Failed to sync reference clock: %s\n",
                 strerror(errno));
     }
--- a/master/cdev.c	Mon May 04 10:05:02 2009 +0000
+++ b/master/cdev.c	Mon May 04 10:05:55 2009 +0000
@@ -1650,16 +1650,11 @@
         ec_cdev_priv_t *priv /**< Private data structure of file handle. */
         )
 {
-    ec_ioctl_dc_t data;
-    
 	if (unlikely(!priv->requested))
 		return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
-        return -EFAULT;
-
     spin_lock_bh(&master->internal_lock);
-    ecrt_master_sync_reference_clock(master, data.app_time);
+    ecrt_master_sync_reference_clock(master);
     spin_unlock_bh(&master->internal_lock);
     return 0;
 }
--- a/master/ioctl.h	Mon May 04 10:05:02 2009 +0000
+++ b/master/ioctl.h	Mon May 04 10:05:55 2009 +0000
@@ -86,37 +86,38 @@
 #define EC_IOCTL_SEND                   EC_IO(0x1c)
 #define EC_IOCTL_RECEIVE                EC_IO(0x1d)
 #define EC_IOCTL_MASTER_STATE          EC_IOR(0x1e, ec_master_state_t)
-#define EC_IOCTL_SYNC_REF              EC_IOW(0x1f, ec_ioctl_dc_t)
-#define EC_IOCTL_SYNC_SLAVES           EC_IOW(0x20, ec_ioctl_dc_t)
-#define EC_IOCTL_SC_SYNC               EC_IOW(0x21, ec_ioctl_config_t)
-#define EC_IOCTL_SC_ADD_PDO            EC_IOW(0x22, ec_ioctl_config_pdo_t)
-#define EC_IOCTL_SC_CLEAR_PDOS         EC_IOW(0x23, ec_ioctl_config_pdo_t)
-#define EC_IOCTL_SC_ADD_ENTRY          EC_IOW(0x24, ec_ioctl_add_pdo_entry_t)
-#define EC_IOCTL_SC_CLEAR_ENTRIES      EC_IOW(0x25, ec_ioctl_config_pdo_t)
-#define EC_IOCTL_SC_REG_PDO_ENTRY     EC_IOWR(0x26, ec_ioctl_reg_pdo_entry_t)
-#define EC_IOCTL_SC_DC_ASSIGN          EC_IOW(0x27, ec_ioctl_sc_dc_t)
-#define EC_IOCTL_SC_DC_CYCLE           EC_IOW(0x28, ec_ioctl_sc_dc_t)
-#define EC_IOCTL_SC_DC_SHIFT           EC_IOW(0x29, ec_ioctl_sc_dc_t)
-#define EC_IOCTL_SC_SDO                EC_IOW(0x2a, ec_ioctl_sc_sdo_t)
-#define EC_IOCTL_SC_SDO_REQUEST       EC_IOWR(0x2b, ec_ioctl_sdo_request_t)
-#define EC_IOCTL_SC_VOE               EC_IOWR(0x2c, ec_ioctl_voe_t)
-#define EC_IOCTL_SC_STATE             EC_IOWR(0x2d, ec_ioctl_sc_state_t)
-#define EC_IOCTL_DOMAIN_OFFSET          EC_IO(0x2e)
-#define EC_IOCTL_DOMAIN_PROCESS         EC_IO(0x2f)
-#define EC_IOCTL_DOMAIN_QUEUE           EC_IO(0x30)
-#define EC_IOCTL_DOMAIN_STATE         EC_IOWR(0x31, ec_ioctl_domain_state_t)
-#define EC_IOCTL_SDO_REQUEST_TIMEOUT  EC_IOWR(0x32, ec_ioctl_sdo_request_t)
-#define EC_IOCTL_SDO_REQUEST_STATE    EC_IOWR(0x33, ec_ioctl_sdo_request_t)
-#define EC_IOCTL_SDO_REQUEST_READ     EC_IOWR(0x34, ec_ioctl_sdo_request_t)
-#define EC_IOCTL_SDO_REQUEST_WRITE    EC_IOWR(0x35, ec_ioctl_sdo_request_t)
-#define EC_IOCTL_SDO_REQUEST_DATA     EC_IOWR(0x36, ec_ioctl_sdo_request_t)
-#define EC_IOCTL_VOE_SEND_HEADER       EC_IOW(0x37, ec_ioctl_voe_t)
-#define EC_IOCTL_VOE_REC_HEADER       EC_IOWR(0x38, ec_ioctl_voe_t)
-#define EC_IOCTL_VOE_READ              EC_IOW(0x39, ec_ioctl_voe_t)
-#define EC_IOCTL_VOE_READ_NOSYNC       EC_IOW(0x3a, ec_ioctl_voe_t)
-#define EC_IOCTL_VOE_WRITE            EC_IOWR(0x3b, ec_ioctl_voe_t)
-#define EC_IOCTL_VOE_EXEC             EC_IOWR(0x3c, ec_ioctl_voe_t)
-#define EC_IOCTL_VOE_DATA             EC_IOWR(0x3d, ec_ioctl_voe_t)
+#define EC_IOCTL_APP_TIME              EC_IOW(0x1f, ec_ioctl_app_time_t)
+#define EC_IOCTL_SYNC_REF               EC_IO(0x20)
+#define EC_IOCTL_SYNC_SLAVES            EC_IO(0x21)
+#define EC_IOCTL_SC_SYNC               EC_IOW(0x22, ec_ioctl_config_t)
+#define EC_IOCTL_SC_ADD_PDO            EC_IOW(0x23, ec_ioctl_config_pdo_t)
+#define EC_IOCTL_SC_CLEAR_PDOS         EC_IOW(0x24, ec_ioctl_config_pdo_t)
+#define EC_IOCTL_SC_ADD_ENTRY          EC_IOW(0x25, ec_ioctl_add_pdo_entry_t)
+#define EC_IOCTL_SC_CLEAR_ENTRIES      EC_IOW(0x26, ec_ioctl_config_pdo_t)
+#define EC_IOCTL_SC_REG_PDO_ENTRY     EC_IOWR(0x27, ec_ioctl_reg_pdo_entry_t)
+#define EC_IOCTL_SC_DC_ASSIGN          EC_IOW(0x28, ec_ioctl_sc_dc_t)
+#define EC_IOCTL_SC_DC_CYCLE           EC_IOW(0x29, ec_ioctl_sc_dc_t)
+#define EC_IOCTL_SC_DC_SHIFT           EC_IOW(0x2a, ec_ioctl_sc_dc_t)
+#define EC_IOCTL_SC_SDO                EC_IOW(0x2b, ec_ioctl_sc_sdo_t)
+#define EC_IOCTL_SC_SDO_REQUEST       EC_IOWR(0x2c, ec_ioctl_sdo_request_t)
+#define EC_IOCTL_SC_VOE               EC_IOWR(0x2d, ec_ioctl_voe_t)
+#define EC_IOCTL_SC_STATE             EC_IOWR(0x2e, ec_ioctl_sc_state_t)
+#define EC_IOCTL_DOMAIN_OFFSET          EC_IO(0x2f)
+#define EC_IOCTL_DOMAIN_PROCESS         EC_IO(0x30)
+#define EC_IOCTL_DOMAIN_QUEUE           EC_IO(0x31)
+#define EC_IOCTL_DOMAIN_STATE         EC_IOWR(0x32, ec_ioctl_domain_state_t)
+#define EC_IOCTL_SDO_REQUEST_TIMEOUT  EC_IOWR(0x33, ec_ioctl_sdo_request_t)
+#define EC_IOCTL_SDO_REQUEST_STATE    EC_IOWR(0x34, ec_ioctl_sdo_request_t)
+#define EC_IOCTL_SDO_REQUEST_READ     EC_IOWR(0x35, ec_ioctl_sdo_request_t)
+#define EC_IOCTL_SDO_REQUEST_WRITE    EC_IOWR(0x36, ec_ioctl_sdo_request_t)
+#define EC_IOCTL_SDO_REQUEST_DATA     EC_IOWR(0x37, ec_ioctl_sdo_request_t)
+#define EC_IOCTL_VOE_SEND_HEADER       EC_IOW(0x38, ec_ioctl_voe_t)
+#define EC_IOCTL_VOE_REC_HEADER       EC_IOWR(0x39, ec_ioctl_voe_t)
+#define EC_IOCTL_VOE_READ              EC_IOW(0x3a, ec_ioctl_voe_t)
+#define EC_IOCTL_VOE_READ_NOSYNC       EC_IOW(0x3b, ec_ioctl_voe_t)
+#define EC_IOCTL_VOE_WRITE            EC_IOWR(0x3c, ec_ioctl_voe_t)
+#define EC_IOCTL_VOE_EXEC             EC_IOWR(0x3d, ec_ioctl_voe_t)
+#define EC_IOCTL_VOE_DATA             EC_IOWR(0x3e, ec_ioctl_voe_t)
 
 /*****************************************************************************/
 
@@ -398,7 +399,7 @@
 typedef struct {
     // inputs
     uint64_t app_time;
-} ec_ioctl_dc_t;
+} ec_ioctl_app_time_t;
 
 /*****************************************************************************/
 
--- a/master/master.c	Mon May 04 10:05:02 2009 +0000
+++ b/master/master.c	Mon May 04 10:05:55 2009 +0000
@@ -1745,10 +1745,15 @@
 
 /*****************************************************************************/
 
-void ecrt_master_sync_reference_clock(ec_master_t *master,
-        uint64_t app_time)
+void ecrt_master_application_time(ec_master_t *master, uint64_t app_time)
 {
     master->app_time = app_time;
+}
+
+/*****************************************************************************/
+
+void ecrt_master_sync_reference_clock(ec_master_t *master)
+{
     EC_WRITE_U32(master->ref_sync_datagram.data, master->app_time);
     ec_master_queue_datagram(master, &master->ref_sync_datagram);
 }
@@ -1772,6 +1777,7 @@
 EXPORT_SYMBOL(ecrt_master_callbacks);
 EXPORT_SYMBOL(ecrt_master_slave_config);
 EXPORT_SYMBOL(ecrt_master_state);
+EXPORT_SYMBOL(ecrt_master_application_time);
 EXPORT_SYMBOL(ecrt_master_sync_reference_clock);
 EXPORT_SYMBOL(ecrt_master_sync_slave_clocks);