Replaced longer cycle timestamps with jiffies.
authorFlorian Pose <fp@igh-essen.com>
Tue, 15 Aug 2006 08:09:18 +0000
changeset 344 5d8281f1aa2a
parent 343 b3858d25ba4b
child 345 beb0a77d73c0
Replaced longer cycle timestamps with jiffies.
master/datagram.c
master/datagram.h
master/domain.c
master/domain.h
master/ethernet.c
master/ethernet.h
master/fsm.c
master/fsm.h
master/master.c
master/master.h
--- a/master/datagram.c	Wed Aug 09 15:00:20 2006 +0000
+++ b/master/datagram.c	Tue Aug 15 08:09:18 2006 +0000
@@ -77,7 +77,7 @@
     datagram->index = 0x00;
     datagram->working_counter = 0x00;
     datagram->state = EC_DATAGRAM_INIT;
-    datagram->t_sent = 0;
+    datagram->cycles_sent = 0;
 }
 
 /*****************************************************************************/
--- a/master/datagram.h	Wed Aug 09 15:00:20 2006 +0000
+++ b/master/datagram.h	Tue Aug 15 08:09:18 2006 +0000
@@ -118,7 +118,7 @@
     uint8_t index; /**< datagram index (set by master) */
     uint16_t working_counter; /**< working counter */
     ec_datagram_state_t state; /**< datagram state */
-    cycles_t t_sent; /**< time, the datagrams was sent */
+    cycles_t cycles_sent; /**< time, the datagram was sent */
 }
 ec_datagram_t;
 
--- a/master/domain.c	Wed Aug 09 15:00:20 2006 +0000
+++ b/master/domain.c	Tue Aug 15 08:09:18 2006 +0000
@@ -106,7 +106,7 @@
     domain->data_size = 0;
     domain->base_address = 0;
     domain->response_count = 0xFFFFFFFF;
-    domain->t_last = 0;
+    domain->notify_jiffies = 0;
     domain->working_counter_changes = 0;
 
     INIT_LIST_HEAD(&domain->data_regs);
@@ -513,7 +513,6 @@
 {
     unsigned int working_counter_sum;
     ec_datagram_t *datagram;
-    cycles_t t_now = get_cycles();
 
     working_counter_sum = 0;
     list_for_each_entry(datagram, &domain->datagrams, list) {
@@ -528,8 +527,8 @@
     }
 
     if (domain->working_counter_changes &&
-        (u32) (t_now - domain->t_last) / cpu_khz > 1000) {
-        domain->t_last = t_now;
+        jiffies - domain->notify_jiffies > HZ) {
+        domain->notify_jiffies = jiffies;
         if (domain->working_counter_changes == 1) {
             EC_INFO("Domain %i working counter change: %i\n", domain->index,
                     domain->response_count);
--- a/master/domain.h	Wed Aug 09 15:00:20 2006 +0000
+++ b/master/domain.h	Tue Aug 15 08:09:18 2006 +0000
@@ -69,7 +69,7 @@
     struct list_head data_regs; /**< PDO data registrations */
     unsigned int working_counter_changes; /**< working counter changes
                                              since last notification */
-    cycles_t t_last; /**< time of last notification */
+    unsigned long notify_jiffies; /**< time of last notification */
 };
 
 /*****************************************************************************/
--- a/master/ethernet.c	Wed Aug 09 15:00:20 2006 +0000
+++ b/master/ethernet.c	Tue Aug 15 08:09:18 2006 +0000
@@ -105,7 +105,7 @@
     eoe->tx_counter = 0;
     eoe->rx_rate = 0;
     eoe->tx_rate = 0;
-    eoe->t_last = 0;
+    eoe->rate_jiffies = 0;
 
     if (!(eoe->dev =
           alloc_netdev(sizeof(ec_eoe_t *), "eoe%d", ether_setup))) {
@@ -278,21 +278,18 @@
 
 void ec_eoe_run(ec_eoe_t *eoe /**< EoE handler */)
 {
-    cycles_t t_now;
-
     if (!eoe->opened) return;
 
     // call state function
     eoe->state(eoe);
 
     // update statistics
-    t_now = get_cycles();
-    if ((u32) (t_now - eoe->t_last) > cpu_khz * 1000) {
+    if (jiffies - eoe->rate_jiffies > HZ) {
         eoe->rx_rate = eoe->rx_counter * 8;
         eoe->tx_rate = eoe->tx_counter * 8;
         eoe->rx_counter = 0;
         eoe->tx_counter = 0;
-        eoe->t_last = t_now;
+        eoe->rate_jiffies = jiffies;
     }
 }
 
--- a/master/ethernet.h	Wed Aug 09 15:00:20 2006 +0000
+++ b/master/ethernet.h	Tue Aug 15 08:09:18 2006 +0000
@@ -78,7 +78,7 @@
     struct net_device *dev; /**< net_device for virtual ethernet device */
     struct net_device_stats stats; /**< device statistics */
     unsigned int opened; /**< net_device is opened */
-    cycles_t t_last; /**< time of last rate output */
+    unsigned long rate_jiffies; /**< time of last rate output */
     struct sk_buff *rx_skb; /**< current rx socket buffer */
     off_t rx_skb_offset; /**< current write pointer in the socket buffer */
     size_t rx_skb_size; /**< size of the allocated socket buffer memory */
--- a/master/fsm.c	Wed Aug 09 15:00:20 2006 +0000
+++ b/master/fsm.c	Tue Aug 15 08:09:18 2006 +0000
@@ -1779,7 +1779,7 @@
     ec_datagram_t *datagram = &fsm->datagram;
     ec_slave_t *slave = fsm->slave;
 
-    fsm->change_start = get_cycles();
+    fsm->change_jiffies = jiffies;
 
     // write new state to slave
     ec_datagram_npwr(datagram, slave->station_address, 0x0120, 2);
@@ -1807,7 +1807,7 @@
     }
 
     if (datagram->working_counter != 1) {
-        if (get_cycles() - fsm->change_start >= (cycles_t) 100 * cpu_khz) {
+        if (jiffies - fsm->change_jiffies >= 3 * HZ) {
             fsm->change_state = ec_fsm_error;
             EC_ERR("Failed to set state 0x%02X on slave %i: Slave did not"
                    " respond.\n", fsm->change_new, fsm->slave->ring_position);
@@ -1821,7 +1821,7 @@
         return;
     }
 
-    fsm->change_start = get_cycles();
+    fsm->change_jiffies = jiffies;
 
     // read AL status from slave
     ec_datagram_nprd(datagram, slave->station_address, 0x0130, 2);
@@ -1869,7 +1869,7 @@
         return;
     }
 
-    if (get_cycles() - fsm->change_start >= (cycles_t) 10 * cpu_khz) {
+    if (jiffies - fsm->change_jiffies >= 100 * HZ / 1000) { // 100ms
         // timeout while checking
         fsm->change_state = ec_fsm_error;
         EC_ERR("Timeout while setting state 0x%02X on slave %i.\n",
@@ -1978,7 +1978,7 @@
         return;
     }
 
-    fsm->change_start = get_cycles();
+    fsm->change_jiffies = jiffies;
 
     // read new AL status
     ec_datagram_nprd(datagram, slave->station_address, 0x0130, 2);
@@ -2014,7 +2014,7 @@
         return;
     }
 
-    if (get_cycles() - fsm->change_start >= (cycles_t) 100 * cpu_khz) {
+    if (jiffies - fsm->change_jiffies >= 100 * HZ / 1000) { // 100ms
         // timeout while checking
         slave->current_state = EC_SLAVE_STATE_UNKNOWN;
         fsm->change_state = ec_fsm_error;
--- a/master/fsm.h	Wed Aug 09 15:00:20 2006 +0000
+++ b/master/fsm.h	Tue Aug 15 08:09:18 2006 +0000
@@ -75,7 +75,7 @@
 
     void (*change_state)(ec_fsm_t *); /**< slave state change state function */
     ec_slave_state_t change_new; /**< input: new state */
-    cycles_t change_start; /**< change start */
+    unsigned long change_jiffies; /**< change timer */
 
     void (*coe_state)(ec_fsm_t *); /**< CoE state function */
     ec_sdo_data_t *sdodata; /**< input/output: SDO data object */
--- a/master/master.c	Wed Aug 09 15:00:20 2006 +0000
+++ b/master/master.c	Tue Aug 15 08:09:18 2006 +0000
@@ -246,7 +246,7 @@
     master->stats.corrupted = 0;
     master->stats.skipped = 0;
     master->stats.unmatched = 0;
-    master->stats.t_last = 0;
+    master->stats.output_jiffies = 0;
 
     master->mode = EC_MASTER_MODE_ORPHANED;
 
@@ -316,11 +316,11 @@
     size_t datagram_size;
     uint8_t *frame_data, *cur_data;
     void *follows_word;
-    cycles_t t_start, t_end;
+    cycles_t cycles_start, cycles_end;
     unsigned int frame_count, more_datagrams_waiting;
 
     frame_count = 0;
-    t_start = get_cycles();
+    cycles_start = get_cycles();
 
     if (unlikely(master->debug_level > 1))
         EC_DBG("ec_master_send_datagrams\n");
@@ -345,7 +345,7 @@
             }
 
             datagram->state = EC_DATAGRAM_SENT;
-            datagram->t_sent = t_start;
+            datagram->cycles_sent = cycles_start;
             datagram->index = master->datagram_index++;
 
             if (unlikely(master->debug_level > 1))
@@ -397,9 +397,10 @@
     while (more_datagrams_waiting);
 
     if (unlikely(master->debug_level > 1)) {
-        t_end = get_cycles();
+        cycles_end = get_cycles();
         EC_DBG("ec_master_send_datagrams sent %i frames in %ius.\n",
-               frame_count, (unsigned int) (t_end - t_start) * 1000 / cpu_khz);
+               frame_count,
+               (unsigned int) (cycles_end - cycles_start) * 1000 / cpu_khz);
     }
 }
 
@@ -528,9 +529,9 @@
 
 void ec_master_output_stats(ec_master_t *master /**< EtherCAT master */)
 {
-    cycles_t t_now = get_cycles();
-
-    if (unlikely((u32) (t_now - master->stats.t_last) / cpu_khz > 1000)) {
+    if (unlikely(jiffies - master->stats.output_jiffies >= HZ)) {
+        master->stats.output_jiffies = jiffies;
+
         if (master->stats.timeouts) {
             EC_WARN("%i datagrams TIMED OUT!\n", master->stats.timeouts);
             master->stats.timeouts = 0;
@@ -551,7 +552,6 @@
             EC_WARN("%i datagram(s) UNMATCHED!\n", master->stats.unmatched);
             master->stats.unmatched = 0;
         }
-        master->stats.t_last = t_now;
     }
 }
 
@@ -610,25 +610,25 @@
 void ec_master_idle_run(void *data /**< master pointer */)
 {
     ec_master_t *master = (ec_master_t *) data;
-    cycles_t start, end;
+    cycles_t cycles_start, cycles_end;
 
     // aquire master lock
     spin_lock_bh(&master->internal_lock);
 
-    start = get_cycles();
+    cycles_start = get_cycles();
     ecrt_master_receive(master);
 
     // execute master state machine
     ec_fsm_execute(&master->fsm);
 
     ecrt_master_send(master);
-    end = get_cycles();
+    cycles_end = get_cycles();
 
     // release master lock
     spin_unlock_bh(&master->internal_lock);
 
     master->idle_cycle_times[master->idle_cycle_time_pos]
-        = (u32) (end - start) * 1000 / cpu_khz;
+        = (u32) (cycles_end - cycles_start) * 1000 / cpu_khz;
     master->idle_cycle_time_pos++;
     master->idle_cycle_time_pos %= HZ;
 
@@ -958,7 +958,8 @@
     ec_master_t *master = (ec_master_t *) data;
     ec_eoe_t *eoe;
     unsigned int active = 0;
-    cycles_t start, end;
+    cycles_t cycles_start, cycles_end;
+    unsigned long restart_jiffies;
 
     list_for_each_entry(eoe, &master->eoe_handlers, list) {
         if (ec_eoe_active(eoe)) active++;
@@ -977,8 +978,8 @@
     else
         goto queue_timer;
 
-    // actual EoE stuff
-    start = get_cycles();
+    // actual EoE processing
+    cycles_start = get_cycles();
     ecrt_master_receive(master);
 
     list_for_each_entry(eoe, &master->eoe_handlers, list) {
@@ -986,7 +987,7 @@
     }
 
     ecrt_master_send(master);
-    end = get_cycles();
+    cycles_end = get_cycles();
 
     // release lock...
     if (master->mode == EC_MASTER_MODE_OPERATION) {
@@ -997,12 +998,14 @@
     }
 
     master->eoe_cycle_times[master->eoe_cycle_time_pos]
-        = (u32) (end - start) * 1000 / cpu_khz;
+        = (u32) (cycles_end - cycles_start) * 1000 / cpu_khz;
     master->eoe_cycle_time_pos++;
     master->eoe_cycle_time_pos %= HZ;
 
  queue_timer:
-    master->eoe_timer.expires += HZ / EC_EOE_FREQUENCY;
+    restart_jiffies = HZ / EC_EOE_FREQUENCY;
+    if (!restart_jiffies) restart_jiffies = 1;
+    master->eoe_timer.expires += restart_jiffies;
     add_timer(&master->eoe_timer);
 }
 
@@ -1047,7 +1050,7 @@
 void ec_master_measure_bus_time(ec_master_t *master)
 {
     ec_datagram_t datagram;
-    cycles_t t_start, t_end, t_timeout;
+    cycles_t cycles_start, cycles_end, cycles_timeout;
     uint32_t times[100], sum, min, max, i;
 
     ec_datagram_init(&datagram);
@@ -1058,7 +1061,7 @@
         return;
     }
 
-    t_timeout = (cycles_t) EC_IO_TIMEOUT * (cpu_khz / 1000);
+    cycles_timeout = (cycles_t) EC_IO_TIMEOUT * (cpu_khz / 1000);
 
     sum = 0;
     min = 0xFFFFFFFF;
@@ -1067,11 +1070,11 @@
     for (i = 0; i < 100; i++) {
         ec_master_queue_datagram(master, &datagram);
         ecrt_master_send(master);
-        t_start = get_cycles();
+        cycles_start = get_cycles();
 
         while (1) { // active waiting
             ec_device_call_isr(master->device);
-            t_end = get_cycles(); // take current time
+            cycles_end = get_cycles(); // take current time
 
             if (datagram.state == EC_DATAGRAM_RECEIVED) {
                 break;
@@ -1080,13 +1083,13 @@
                 EC_WARN("Failed to measure bus time.\n");
                 goto error;
             }
-            else if (t_end - t_start >= t_timeout) {
+            else if (cycles_end - cycles_start >= cycles_timeout) {
                 EC_WARN("Timeout while measuring bus time.\n");
                 goto error;
             }
         }
 
-        times[i] = (unsigned int) (t_end - t_start) * 1000 / cpu_khz;
+        times[i] = (unsigned int) (cycles_end - cycles_start) * 1000 / cpu_khz;
         sum += times[i];
         if (times[i] > max) max = times[i];
         if (times[i] < min) min = times[i];
@@ -1236,19 +1239,19 @@
 {
     ec_datagram_t *datagram, *n;
     unsigned int datagrams_sent;
-    cycles_t t_start, t_end, t_timeout;
+    cycles_t cycles_start, cycles_end, cycles_timeout;
 
     // send datagrams
     ecrt_master_send(master);
 
-    t_start = get_cycles(); // measure io time
-    t_timeout = (cycles_t) EC_IO_TIMEOUT * (cpu_khz / 1000);
+    cycles_start = get_cycles(); // measure io time
+    cycles_timeout = (cycles_t) EC_IO_TIMEOUT * (cpu_khz / 1000);
 
     while (1) { // active waiting
         ec_device_call_isr(master->device);
 
-        t_end = get_cycles(); // take current time
-        if (t_end - t_start >= t_timeout) break; // timeout!
+        cycles_end = get_cycles(); // take current time
+        if (cycles_end - cycles_start >= cycles_timeout) break; // timeout!
 
         datagrams_sent = 0;
         list_for_each_entry_safe(datagram, n, &master->datagram_queue, queue) {
@@ -1318,12 +1321,12 @@
 void ecrt_master_receive(ec_master_t *master /**< EtherCAT master */)
 {
     ec_datagram_t *datagram, *next;
-    cycles_t t_received, t_timeout;
+    cycles_t cycles_received, cycles_timeout;
 
     ec_device_call_isr(master->device);
 
-    t_received = get_cycles();
-    t_timeout = EC_IO_TIMEOUT * cpu_khz / 1000;
+    cycles_received = get_cycles();
+    cycles_timeout = EC_IO_TIMEOUT * cpu_khz / 1000;
 
     // dequeue all received datagrams
     list_for_each_entry_safe(datagram, next, &master->datagram_queue, queue)
@@ -1335,7 +1338,7 @@
         switch (datagram->state) {
             case EC_DATAGRAM_SENT:
             case EC_DATAGRAM_QUEUED:
-                if (t_received - datagram->t_sent > t_timeout) {
+                if (cycles_received - datagram->cycles_sent > cycles_timeout) {
                     list_del_init(&datagram->queue);
                     datagram->state = EC_DATAGRAM_TIMED_OUT;
                     master->stats.timeouts++;
@@ -1360,7 +1363,7 @@
 void ecrt_master_prepare(ec_master_t *master /**< EtherCAT master */)
 {
     ec_domain_t *domain;
-    cycles_t t_start, t_end, t_timeout;
+    cycles_t cycles_start, cycles_end, cycles_timeout;
 
     // queue datagrams of all domains
     list_for_each_entry(domain, &master->domains, list)
@@ -1368,13 +1371,13 @@
 
     ecrt_master_send(master);
 
-    t_start = get_cycles(); // take sending time
-    t_timeout = (cycles_t) EC_IO_TIMEOUT * (cpu_khz / 1000);
+    cycles_start = get_cycles(); // take sending time
+    cycles_timeout = (cycles_t) EC_IO_TIMEOUT * (cpu_khz / 1000);
 
     // active waiting
     while (1) {
-        t_end = get_cycles();
-        if (t_end - t_start >= t_timeout) break;
+        cycles_end = get_cycles();
+        if (cycles_end - cycles_start >= cycles_timeout) break;
     }
 }
 
--- a/master/master.h	Wed Aug 09 15:00:20 2006 +0000
+++ b/master/master.h	Tue Aug 15 08:09:18 2006 +0000
@@ -78,7 +78,7 @@
                              requeued when not yet received) */
     unsigned int unmatched; /**< unmatched datagrams (received, but not
                                queued any longer) */
-    cycles_t t_last; /**< time of last output */
+    unsigned long output_jiffies; /**< time of last output */
 }
 ec_stats_t;