Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
authorFlorian Pose <fp@igh-essen.com>
Thu, 09 Apr 2009 10:21:47 +0000
changeset 1394 e77728ddf0f9
parent 1393 979a7b26036d
child 1395 e9fe40c458cc
Introduced ecrt_master_sync() for synchronizing slave clocks to reference clock.
include/ecrt.h
master/master.c
master/master.h
--- a/include/ecrt.h	Thu Apr 09 10:18:27 2009 +0000
+++ b/include/ecrt.h	Thu Apr 09 10:21:47 2009 +0000
@@ -44,7 +44,7 @@
  * - Added the distributed clocks feature and the respective methods
  *   ecrt_slave_config_dc_assign_activate() and
  *   ecrt_slave_config_dc_sync_cycle_times() to configure a slave for cyclic
- *   operation.
+ *   operation, and ecrt_master_sync() for drift compensation.
  * - Changed the meaning of the negative return values of
  *   ecrt_slave_config_reg_pdo_entry() and ecrt_slave_config_sdo*().
  * - Imlemented the Vendor-specific over EtherCAT mailbox protocol. See
@@ -504,6 +504,12 @@
         ec_master_state_t *state /**< Structure to store the information. */
         );
 
+/** Queues the DC drift compensation datagram for sending.
+ */
+void ecrt_master_sync(
+        ec_master_t *master /**< EtherCAT master. */
+        );
+
 /******************************************************************************
  * Slave configuration methods
  *****************************************************************************/
--- a/master/master.c	Thu Apr 09 10:18:27 2009 +0000
+++ b/master/master.c	Thu Apr 09 10:21:47 2009 +0000
@@ -190,6 +190,7 @@
     snprintf(master->fsm_datagram.name, EC_DATAGRAM_NAME_SIZE, "master-fsm");
     ret = ec_datagram_prealloc(&master->fsm_datagram, EC_MAX_DATA_SIZE);
     if (ret < 0) {
+        ec_datagram_clear(&master->fsm_datagram);
         EC_ERR("Failed to allocate FSM datagram.\n");
         goto out_clear_backup;
     }
@@ -197,10 +198,20 @@
     // create state machine object
     ec_fsm_master_init(&master->fsm, master, &master->fsm_datagram);
 
+    // init sync datagram
+    ec_datagram_init(&master->sync_datagram);
+    snprintf(master->sync_datagram.name, EC_DATAGRAM_NAME_SIZE, "sync");
+    ret = ec_datagram_armw(&master->sync_datagram, 0 /* FIXME */, 0x0910, 4);
+    if (ret < 0) {
+        ec_datagram_clear(&master->sync_datagram);
+        EC_ERR("Failed to allocate synchronisation datagram.\n");
+        goto out_clear_fsm;
+    }
+
     // init character device
     ret = ec_cdev_init(&master->cdev, master, device_number);
     if (ret)
-        goto out_clear_fsm;
+        goto out_clear_sync;
     
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
     master->class_device = device_create(class, NULL,
@@ -229,6 +240,8 @@
 
 out_clear_cdev:
     ec_cdev_clear(&master->cdev);
+out_clear_sync:
+    ec_datagram_clear(&master->sync_datagram);
 out_clear_fsm:
     ec_fsm_master_clear(&master->fsm);
     ec_datagram_clear(&master->fsm_datagram);
@@ -253,13 +266,17 @@
 #else
     class_device_unregister(master->class_device);
 #endif
+
     ec_cdev_clear(&master->cdev);
+    
 #ifdef EC_EOE
     ec_master_clear_eoe_handlers(master);
 #endif
     ec_master_clear_domains(master);
     ec_master_clear_slave_configs(master);
     ec_master_clear_slaves(master);
+
+    ec_datagram_clear(&master->sync_datagram);
     ec_fsm_master_clear(&master->fsm);
     ec_datagram_clear(&master->fsm_datagram);
     ec_device_clear(&master->backup_device);
@@ -1314,7 +1331,7 @@
 }
 
 /******************************************************************************
- *  Realtime interface
+ *  Application interface
  *****************************************************************************/
 
 /** Same as ecrt_master_create_domain(), but with ERR_PTR() return value.
@@ -1590,6 +1607,14 @@
 
 /*****************************************************************************/
 
+void ecrt_master_sync(ec_master_t *master)
+{
+    ec_datagram_zero(&master->sync_datagram);
+    ec_master_queue_datagram(master, &master->sync_datagram);
+}
+
+/*****************************************************************************/
+
 /** \cond */
 
 EXPORT_SYMBOL(ecrt_master_create_domain);
@@ -1599,6 +1624,7 @@
 EXPORT_SYMBOL(ecrt_master_callbacks);
 EXPORT_SYMBOL(ecrt_master_slave_config);
 EXPORT_SYMBOL(ecrt_master_state);
+EXPORT_SYMBOL(ecrt_master_sync);
 
 /** \endcond */
 
--- a/master/master.h	Thu Apr 09 10:18:27 2009 +0000
+++ b/master/master.h	Thu Apr 09 10:21:47 2009 +0000
@@ -117,6 +117,9 @@
 
     struct list_head configs; /**< List of slave configurations. */
     
+    ec_datagram_t sync_datagram; /**< Datagram used for DC drift
+                                   compensation. */
+    
     unsigned int scan_busy; /**< Current scan state. */
     unsigned int allow_scan; /**< \a True, if slave scanning is allowed. */
     struct semaphore scan_sem; /**< Semaphore protecting the \a scan_busy