Use jiffies instead of cycles in SII state machine.
authorFlorian Pose <fp@igh-essen.com>
Thu, 19 Jun 2008 10:18:18 +0000
changeset 1039 2881a83d084f
parent 1038 7ca4103ba170
child 1040 d2527675cdd5
Use jiffies instead of cycles in SII state machine.
master/fsm_sii.c
master/fsm_sii.h
--- a/master/fsm_sii.c	Thu Jun 19 10:17:52 2008 +0000
+++ b/master/fsm_sii.c	Thu Jun 19 10:18:18 2008 +0000
@@ -225,7 +225,7 @@
         return;
     }
 
-    fsm->cycles_start = datagram->cycles_sent;
+    fsm->jiffies_start = datagram->jiffies_sent;
     fsm->check_once_more = 1;
 
     // issue check/fetch datagram
@@ -289,8 +289,9 @@
     if (EC_READ_U8(datagram->data + 1) & 0x81) { // busy bit or
 												 // read operation busy
         // still busy... timeout?
-        if (datagram->cycles_received
-            - fsm->cycles_start >= (cycles_t) SII_TIMEOUT * cpu_khz) {
+        unsigned long diff_ms =
+            (datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ;
+        if (diff_ms >= SII_TIMEOUT) {
             if (fsm->check_once_more) {
 				fsm->check_once_more = 0;
 			} else {
@@ -372,7 +373,7 @@
         return;
     }
 
-    fsm->cycles_start = datagram->cycles_sent;
+    fsm->jiffies_start = datagram->jiffies_sent;
     fsm->check_once_more = 1;
 
     // issue check datagram
@@ -392,6 +393,7 @@
 		)
 {
     ec_datagram_t *datagram = fsm->datagram;
+    unsigned long diff_ms;
 
     if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
         return;
@@ -425,8 +427,8 @@
 
 	/* FIXME: some slaves never answer with the busy flag set...
 	 * wait a few ms for the write operation to complete. */
-	if (datagram->cycles_received - fsm->cycles_start
-			< (cycles_t) SII_INHIBIT * cpu_khz) {
+    diff_ms = (datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ;
+    if (diff_ms < SII_INHIBIT) {
 #ifdef SII_DEBUG
 		EC_DBG("too early.\n");
 #endif
@@ -438,8 +440,7 @@
     if (EC_READ_U8(datagram->data + 1) & 0x82) { // busy bit or
 												 // write operation busy bit
         // still busy... timeout?
-        if (datagram->cycles_received
-            - fsm->cycles_start >= (cycles_t) SII_TIMEOUT * cpu_khz) {
+        if (diff_ms >= SII_TIMEOUT) {
             if (fsm->check_once_more) {
 				fsm->check_once_more = 0;
 			} else {
--- a/master/fsm_sii.h	Thu Jun 19 10:17:52 2008 +0000
+++ b/master/fsm_sii.h	Thu Jun 19 10:18:18 2008 +0000
@@ -73,7 +73,7 @@
     uint16_t word_offset; /**< input: word offset in SII */
     ec_fsm_sii_addressing_t mode; /**< reading via APRD or NPRD */
     uint8_t value[4]; /**< raw SII value (32bit) */
-    cycles_t cycles_start; /**< start timestamp */
+    unsigned long jiffies_start; /**< Start timestamp. */
     uint8_t check_once_more; /**< one more try after timeout */
 };