Fixed name of byte transmission time define; changed coding style.
authorFlorian Pose <fp@igh-essen.com>
Tue, 19 Jan 2010 17:57:46 +0100
changeset 1774 a9143f82c7c5
parent 1773 5371f3e5f6a1
child 1777 a93fc03eeb06
Fixed name of byte transmission time define; changed coding style.
master/globals.h
master/master.c
--- a/master/globals.h	Tue Jan 19 15:15:57 2010 +0100
+++ b/master/globals.h	Tue Jan 19 17:57:46 2010 +0100
@@ -51,8 +51,11 @@
 /** SDO injection timeout in microseconds. */
 #define EC_SDO_INJECTION_TIMEOUT 10000
 
-/** time to send a byte in nanoseconds. */
-#define EC_BYTE_TRANSMITION_TIME 80
+/** Time to send a byte in nanoseconds.
+ *
+ * t_ns = 1 / (100 MBit/s / 8 bit/byte) = 80 ns/byte
+ */
+#define EC_BYTE_TRANSMISSION_TIME_NS 80
 
 /** Number of state machine retries on datagram timeout. */
 #define EC_FSM_RETRIES 3
--- a/master/master.c	Tue Jan 19 15:15:57 2010 +0100
+++ b/master/master.c	Tue Jan 19 17:57:46 2010 +0100
@@ -691,7 +691,7 @@
 
 /*****************************************************************************/
 
-/** Injects external datagrams that fit into the datagram queue
+/** Injects external datagrams that fit into the datagram queue.
  */
 void ec_master_inject_external_datagrams(
         ec_master_t *master /**< EtherCAT master */
@@ -699,10 +699,13 @@
 {
     ec_datagram_t *datagram, *n;
     size_t queue_size = 0;
+
     list_for_each_entry(datagram, &master->datagram_queue, queue) {
         queue_size += datagram->data_size;
     }
-    list_for_each_entry_safe(datagram, n, &master->external_datagram_queue, queue) {
+
+    list_for_each_entry_safe(datagram, n, &master->external_datagram_queue,
+            queue) {
         queue_size += datagram->data_size;
         if (queue_size <= master->max_queue_size) {
             list_del_init(&datagram->queue);
@@ -723,54 +726,65 @@
             if (datagram->data_size > master->max_queue_size) {
                 list_del_init(&datagram->queue);
                 datagram->state = EC_DATAGRAM_ERROR;
-                EC_ERR("External datagram %08x is too large, size=%u, max_queue_size=%u\n",(unsigned int)datagram,datagram->data_size,master->max_queue_size);
-            }
-            else {
+                EC_ERR("External datagram %p is too large,"
+                        " size=%u, max_queue_size=%u\n",
+                        datagram, datagram->data_size,
+                        master->max_queue_size);
+            } else {
 #ifdef EC_HAVE_CYCLES
                 cycles_t cycles_now = get_cycles();
+
                 if (cycles_now - datagram->cycles_sent
-                        > sdo_injection_timeout_cycles) {
+                        > sdo_injection_timeout_cycles)
 #else
-                    if (jiffies - datagram->jiffies_sent
-                            > sdo_injection_timeout_jiffies) {
-#endif
-                        unsigned int time_us;
-                        list_del_init(&datagram->queue);
-                        datagram->state = EC_DATAGRAM_ERROR;
+                if (jiffies - datagram->jiffies_sent
+                        > sdo_injection_timeout_jiffies)
+#endif
+                {
+                    unsigned int time_us;
+
+                    list_del_init(&datagram->queue);
+                    datagram->state = EC_DATAGRAM_ERROR;
 #ifdef EC_HAVE_CYCLES
-                        time_us = (unsigned int) ((cycles_now - datagram->cycles_sent) * 1000LL) / cpu_khz;
+                    time_us = (unsigned int)
+                        ((cycles_now - datagram->cycles_sent) * 1000LL)
+                        / cpu_khz;
 #else
-                        time_us = (unsigned int) ((jiffies - datagram->jiffies_sent) * 1000000 / HZ);
-#endif
-                        EC_ERR("Timeout %u us: injecting external datagram %08x size=%u, max_queue_size=%u\n",time_us,(unsigned int)datagram,datagram->data_size,master->max_queue_size);
-                    }
-                    else  {
+                    time_us = (unsigned int)
+                        ((jiffies - datagram->jiffies_sent) * 1000000 / HZ);
+#endif
+                    EC_ERR("Timeout %u us: injecting external datagram %p"
+                            " size=%u, max_queue_size=%u\n",
+                            time_us, datagram,
+                            datagram->data_size, master->max_queue_size);
+                }
 #if DEBUG_INJECT
-                        if (master->debug_level) {
-                            EC_DBG("Deferred injecting of external datagram %08x size=%u, queue_size=%u\n",(unsigned int)datagram,datagram->data_size,queue_size);
-                        }
-#endif
-                    }
+                else if (master->debug_level) {
+                    EC_DBG("Deferred injecting of external datagram %p"
+                            " size=%u, queue_size=%u\n",
+                            datagram, datagram->data_size, queue_size);
                 }
+#endif
             }
         }
     }
-
-/*****************************************************************************/
-
-/** sets the expected interval between calls to ecrt_master_send
-  and calculates the maximum amount of data to queue
- */
-    void ec_master_set_send_interval(
-            ec_master_t *master, /**< EtherCAT master */
-            size_t send_interval /**< send interval */
-            )
-    {
-        master->send_interval = send_interval;
-        master->max_queue_size = (send_interval * 1000) / EC_BYTE_TRANSMITION_TIME;
-        master->max_queue_size -= master->max_queue_size / 10;
-}
-
+}
+
+/*****************************************************************************/
+
+/** Sets the expected interval between calls to ecrt_master_send
+ * and calculates the maximum amount of data to queue.
+ */
+void ec_master_set_send_interval(
+        ec_master_t *master, /**< EtherCAT master */
+        size_t send_interval /**< Send interval */
+        )
+{
+    master->send_interval = send_interval;
+    master->max_queue_size =
+        (send_interval * 1000) / EC_BYTE_TRANSMISSION_TIME_NS;
+    master->max_queue_size -= master->max_queue_size / 10;
+}
 
 /*****************************************************************************/
 
@@ -784,18 +798,23 @@
 	ec_datagram_t *queued_datagram;
 
     down(&master->io_sem);
+
 	// check, if the datagram is already queued
-	list_for_each_entry(queued_datagram, &master->external_datagram_queue, queue) {
+	list_for_each_entry(queued_datagram, &master->external_datagram_queue,
+            queue) {
 		if (queued_datagram == datagram) {
 			datagram->state = EC_DATAGRAM_QUEUED;
 			return;
 		}
 	}
+
 #if DEBUG_INJECT
 	if (master->debug_level) {
-		EC_DBG("Requesting external datagram %08x size=%u\n",(unsigned int)datagram,datagram->data_size);
+		EC_DBG("Requesting external datagram %p size=%u\n",
+                datagram, datagram->data_size);
 	}
 #endif
+
 	list_add_tail(&datagram->queue, &master->external_datagram_queue);
 	datagram->state = EC_DATAGRAM_QUEUED;
 #ifdef EC_HAVE_CYCLES
@@ -1204,9 +1223,14 @@
     ec_slave_t *slave = NULL;
     int fsm_exec;
 	size_t sent_bytes;
-	ec_master_set_send_interval(master,1000000 / HZ); // send interval in IDLE phase
+
+    // send interval in IDLE phase
+	ec_master_set_send_interval(master, 1000000 / HZ); 
+
 	if (master->debug_level)
-		EC_DBG("Idle thread running with send interval = %d us, max data size=%d\n",master->send_interval,master->max_queue_size);
+		EC_DBG("Idle thread running with send interval = %d us,"
+                " max data size=%d\n", master->send_interval,
+                master->max_queue_size);
 
     while (!kthread_should_stop()) {
         ec_datagram_output_stats(&master->fsm_datagram);
@@ -1235,7 +1259,8 @@
         }
         ec_master_inject_external_datagrams(master);
         ecrt_master_send(master);
-		sent_bytes = master->main_device.tx_skb[master->main_device.tx_ring_index]->len;
+		sent_bytes = master->main_device.tx_skb[
+            master->main_device.tx_ring_index]->len;
         up(&master->io_sem);
 
 		if (ec_fsm_master_idle(&master->fsm)) {
@@ -1247,7 +1272,7 @@
 #endif
         } else {
 #ifdef EC_USE_HRTIMER
-			ec_master_nanosleep(sent_bytes * EC_BYTE_TRANSMITION_TIME);
+			ec_master_nanosleep(sent_bytes * EC_BYTE_TRANSMISSION_TIME_NS);
 #else
             schedule();
 #endif
@@ -1256,6 +1281,7 @@
     
     if (master->debug_level)
         EC_DBG("Master IDLE thread exiting...\n");
+
     return 0;
 }