Wiederholtes Senden, wenn keine Antwort.
authorFlorian Pose <fp@igh-essen.com>
Tue, 28 Feb 2006 09:09:08 +0000
changeset 89 e91ef35c36db
parent 88 98335157e54e
child 90 044e97bce4bd
Wiederholtes Senden, wenn keine Antwort.
master/canopen.c
master/frame.c
master/master.c
master/slave.c
--- a/master/canopen.c	Sun Feb 26 12:26:23 2006 +0000
+++ b/master/canopen.c	Tue Feb 28 09:09:08 2006 +0000
@@ -56,14 +56,11 @@
         value >>= 8;
     }
 
-    ec_frame_init_npwr(&frame, master, slave->station_address, 0x1800, 0xF6,
-                       data);
-
-    if (unlikely(ec_frame_send_receive(&frame) < 0)) return -1;
-
-    if (unlikely(frame.working_counter != 1)) {
-        EC_ERR("Mailbox send - Slave %i did not respond!\n",
-               slave->ring_position);
+    ec_frame_init_npwr(&frame, master, slave->station_address,
+                       0x1800, 0xF6, data);
+
+    if (unlikely(ec_frame_send_receive(&frame) < 0)) {
+        EC_ERR("Mailbox sending failed on slave %i!\n", slave->ring_position);
         return -1;
     }
 
@@ -74,10 +71,8 @@
     {
         ec_frame_init_nprd(&frame, master, slave->station_address, 0x808, 8);
 
-        if (unlikely(ec_frame_send_receive(&frame) < 0)) return -1;
-
-        if (unlikely(frame.working_counter != 1)) {
-            EC_ERR("Mailbox check - Slave %i did not respond!\n",
+        if (unlikely(ec_frame_send_receive(&frame) < 0)) {
+            EC_ERR("Mailbox checking failed on slave %i!\n",
                    slave->ring_position);
             return -1;
         }
@@ -97,10 +92,8 @@
 
     ec_frame_init_nprd(&frame, master, slave->station_address, 0x18F6, 0xF6);
 
-    if (unlikely(ec_frame_send_receive(&frame) < 0)) return -1;
-
-    if (unlikely(frame.working_counter != 1)) {
-        EC_ERR("Mailbox receive - Slave %i did not respond!\n",
+    if (unlikely(ec_frame_send_receive(&frame) < 0)) {
+        EC_ERR("Mailbox receiving failed on slave %i!\n",
                slave->ring_position);
         return -1;
     }
@@ -149,14 +142,11 @@
     EC_WRITE_U16(data + 9,  sdo_index);
     EC_WRITE_U8 (data + 11, sdo_subindex);
 
-    ec_frame_init_npwr(&frame, master, slave->station_address, 0x1800, 0xF6,
-                       data);
-
-    if (unlikely(ec_frame_send_receive(&frame) < 0)) return -1;
-
-    if (unlikely(frame.working_counter != 1)) {
-        EC_ERR("Mailbox send - Slave %i did not respond!\n",
-               slave->ring_position);
+    ec_frame_init_npwr(&frame, master, slave->station_address,
+                       0x1800, 0xF6, data);
+
+    if (unlikely(ec_frame_send_receive(&frame) < 0)) {
+        EC_ERR("Mailbox sending failed on slave %i!\n", slave->ring_position);
         return -1;
     }
 
@@ -167,10 +157,8 @@
     {
         ec_frame_init_nprd(&frame, master, slave->station_address, 0x808, 8);
 
-        if (unlikely(ec_frame_send_receive(&frame) < 0)) return -1;
-
-        if (unlikely(frame.working_counter != 1)) {
-            EC_ERR("Mailbox check - Slave %i did not respond!\n",
+        if (unlikely(ec_frame_send_receive(&frame) < 0)) {
+            EC_ERR("Mailbox checking failed on slave %i!\n",
                    slave->ring_position);
             return -1;
         }
@@ -190,10 +178,8 @@
 
     ec_frame_init_nprd(&frame, master, slave->station_address, 0x18F6, 0xF6);
 
-    if (unlikely(ec_frame_send_receive(&frame) < 0)) return -1;
-
-    if (unlikely(frame.working_counter != 1)) {
-        EC_ERR("Mailbox receive - Slave %i did not respond!\n",
+    if (unlikely(ec_frame_send_receive(&frame) < 0)) {
+        EC_ERR("Mailbox receiving failed on slave %i!\n",
                slave->ring_position);
         return -1;
     }
--- a/master/frame.c	Sun Feb 26 12:26:23 2006 +0000
+++ b/master/frame.c	Tue Feb 28 09:09:08 2006 +0000
@@ -405,6 +405,12 @@
 /**
    Sendet einen einzeln Rahmen und wartet auf dessen Empfang.
 
+   Wenn der Working-Counter nicht gesetzt wurde, wird der Rahmen
+   nochmals gesendet.
+
+   \todo Das ist noch nicht schön, da hier zwei Protokollschichten
+   vermischt werden.
+
    \return 0 bei Erfolg, sonst < 0
 */
 
@@ -412,32 +418,49 @@
                           /**< Rahmen zum Senden/Empfangen */
                           )
 {
-    unsigned int tries_left;
-
-    if (unlikely(ec_frame_send(frame) < 0)) {
-        EC_ERR("Frame sending failed!\n");
-        return -1;
-    }
-
-    tries_left = 20;
+    unsigned int timeout_tries_left, response_tries_left;
+    unsigned int tries;
+
+    tries = 0;
+    response_tries_left = 10;
     do
     {
-        udelay(1);
-        ec_device_call_isr(&frame->master->device);
-        tries_left--;
-    }
-    while (unlikely(!ec_device_received(&frame->master->device)
-                    && tries_left));
-
-    if (unlikely(!tries_left)) {
-        EC_ERR("Frame timeout!\n");
-        return -1;
-    }
-
-    if (unlikely(ec_frame_receive(frame) < 0)) {
-        EC_ERR("Frame receiving failed!\n");
-        return -1;
-    }
+        tries++;
+        if (unlikely(ec_frame_send(frame) < 0)) {
+            EC_ERR("Frame sending failed!\n");
+            return -1;
+        }
+
+        timeout_tries_left = 20;
+        do
+        {
+            udelay(1);
+            ec_device_call_isr(&frame->master->device);
+            timeout_tries_left--;
+        }
+        while (unlikely(!ec_device_received(&frame->master->device)
+                        && timeout_tries_left));
+
+        if (unlikely(!timeout_tries_left)) {
+            EC_ERR("Frame timeout!\n");
+            return -1;
+        }
+
+        if (unlikely(ec_frame_receive(frame) < 0)) {
+            EC_ERR("Frame receiving failed!\n");
+            return -1;
+        }
+
+        response_tries_left--;
+    }
+    while (unlikely(!frame->working_counter && response_tries_left));
+
+    if (unlikely(!response_tries_left)) {
+        EC_ERR("No response!");
+        return -1;
+    }
+
+    if (tries > 1) EC_WARN("%i tries necessary...\n", tries);
 
     return 0;
 }
--- a/master/master.c	Sun Feb 26 12:26:23 2006 +0000
+++ b/master/master.c	Tue Feb 28 09:09:08 2006 +0000
@@ -204,11 +204,8 @@
         ec_frame_init_apwr(&frame, master, slave->ring_position, 0x0010,
                            sizeof(uint16_t), data);
 
-        if (unlikely(ec_frame_send_receive(&frame) < 0)) return -1;
-
-        if (unlikely(frame.working_counter != 1)) {
-            EC_ERR("Slave %i did not repond while writing station address!\n",
-                   i);
+        if (unlikely(ec_frame_send_receive(&frame) < 0)) {
+            EC_ERR("Writing station address failed on slave %i!\n", i);
             return -1;
         }
 
@@ -489,9 +486,8 @@
             memset(data, 0x00, EC_FMMU_SIZE * slave->base_fmmu_count);
             ec_frame_init_npwr(&frame, master, slave->station_address, 0x0600,
                                EC_FMMU_SIZE * slave->base_fmmu_count, data);
-            if (unlikely(ec_frame_send_receive(&frame) < 0)) return -1;
-            if (unlikely(frame.working_counter != 1)) {
-                EC_ERR("Resetting FMMUs - Slave %i did not respond!\n",
+            if (unlikely(ec_frame_send_receive(&frame) < 0)) {
+                EC_ERR("Resetting FMMUs failed on slave %i!\n",
                        slave->ring_position);
                 return -1;
             }
@@ -502,9 +498,8 @@
             memset(data, 0x00, EC_SYNC_SIZE * slave->base_sync_count);
             ec_frame_init_npwr(&frame, master, slave->station_address, 0x0800,
                                EC_SYNC_SIZE * slave->base_sync_count, data);
-            if (unlikely(ec_frame_send_receive(&frame) < 0)) return -1;
-            if (unlikely(frame.working_counter != 1)) {
-                EC_ERR("Resetting SMs - Slave %i did not respond!\n",
+            if (unlikely(ec_frame_send_receive(&frame) < 0)) {
+                EC_ERR("Resetting sync managers failed on slave %i!\n",
                        slave->ring_position);
                 return -1;
             }
@@ -519,10 +514,8 @@
             ec_frame_init_npwr(&frame, master, slave->station_address,
                                0x0800 + j * EC_SYNC_SIZE, EC_SYNC_SIZE, data);
 
-            if (unlikely(ec_frame_send_receive(&frame))) return -1;
-
-            if (unlikely(frame.working_counter != 1)) {
-                EC_ERR("Setting sync manager %i - Slave %i did not respond!\n",
+            if (unlikely(ec_frame_send_receive(&frame))) {
+                EC_ERR("Setting sync manager %i failed on slave %i!\n",
                        j, slave->ring_position);
                 return -1;
             }
@@ -548,11 +541,9 @@
             ec_frame_init_npwr(&frame, master, slave->station_address,
                                0x0600 + j * EC_FMMU_SIZE, EC_FMMU_SIZE, data);
 
-            if (unlikely(ec_frame_send_receive(&frame))) return -1;
-
-            if (unlikely(frame.working_counter != 1)) {
-                EC_ERR("Setting FMMU %i - Slave %i did not respond!\n", j,
-                       slave->ring_position);
+            if (unlikely(ec_frame_send_receive(&frame))) {
+                EC_ERR("Setting FMMU %i failed on slave %i!\n",
+                       j, slave->ring_position);
                 return -1;
             }
         }
--- a/master/slave.c	Sun Feb 26 12:26:23 2006 +0000
+++ b/master/slave.c	Tue Feb 28 09:09:08 2006 +0000
@@ -68,10 +68,8 @@
     ec_frame_init_nprd(&frame, slave->master, slave->station_address,
                        0x0000, 6);
 
-    if (unlikely(ec_frame_send_receive(&frame))) return -1;
-
-    if (unlikely(frame.working_counter != 1)) {
-        EC_ERR("Slave %i did not respond while reading base data!\n",
+    if (unlikely(ec_frame_send_receive(&frame))) {
+        EC_ERR("Reading base datafrom slave %i failed!\n",
                slave->ring_position);
         return -1;
     }
@@ -141,13 +139,11 @@
     EC_WRITE_U16(data + 2, offset);
     EC_WRITE_U16(data + 4, 0x0000);
 
-    ec_frame_init_npwr(&frame, slave->master, slave->station_address, 0x502, 6,
-                       data);
-
-    if (unlikely(ec_frame_send_receive(&frame))) return -1;
-
-    if (unlikely(frame.working_counter != 1)) {
-        EC_ERR("SII-read - Slave %i did not respond!\n", slave->ring_position);
+    ec_frame_init_npwr(&frame, slave->master, slave->station_address,
+                       0x502, 6, data);
+
+    if (unlikely(ec_frame_send_receive(&frame))) {
+        EC_ERR("SII-read failed on slave %i!\n", slave->ring_position);
         return -1;
     }
 
@@ -160,13 +156,11 @@
     {
         udelay(10);
 
-        ec_frame_init_nprd(&frame, slave->master, slave->station_address, 0x502,
-                           10);
-
-        if (unlikely(ec_frame_send_receive(&frame))) return -1;
-
-        if (unlikely(frame.working_counter != 1)) {
-            EC_ERR("SII-read status - Slave %i did not respond!\n",
+        ec_frame_init_nprd(&frame, slave->master, slave->station_address,
+                           0x502, 10);
+
+        if (unlikely(ec_frame_send_receive(&frame))) {
+            EC_ERR("Getting SII-read status failed on slave %i!\n",
                    slave->ring_position);
             return -1;
         }
@@ -207,17 +201,12 @@
 
     EC_WRITE_U16(data, state | EC_ACK);
 
-    ec_frame_init_npwr(&frame, slave->master, slave->station_address, 0x0120,
-                       2, data);
-
-    if (unlikely(ec_frame_send_receive(&frame) != 0)) {
-        EC_WARN("Could no acknowledge state %02X - Unable to send!\n", state);
-        return;
-    }
-
-    if (unlikely(frame.working_counter != 1)) {
-        EC_WARN("Could not acknowledge state %02X - Slave %i did not"
-                " respond!\n", state, slave->ring_position);
+    ec_frame_init_npwr(&frame, slave->master, slave->station_address,
+                       0x0120, 2, data);
+
+    if (unlikely(ec_frame_send_receive(&frame))) {
+        EC_WARN("State %02X acknowledge failed on slave %i!\n",
+                state, slave->ring_position);
         return;
     }
 
@@ -229,15 +218,9 @@
         ec_frame_init_nprd(&frame, slave->master, slave->station_address,
                            0x0130, 2);
 
-        if (unlikely(ec_frame_send_receive(&frame) != 0)) {
-            EC_WARN("Could not check state acknowledgement %02X - Unable to"
-                    " send!\n", state);
-            return;
-        }
-
-        if (unlikely(frame.working_counter != 1)) {
-            EC_WARN("Could not check state acknowledgement %02X - Slave %i did"
-                    " not respond!\n", state, slave->ring_position);
+        if (unlikely(ec_frame_send_receive(&frame))) {
+            EC_WARN("State %02X acknowledge checking failed on slave %i!\n",
+                    state, slave->ring_position);
             return;
         }
 
@@ -284,17 +267,12 @@
 
     EC_WRITE_U16(data, state);
 
-    ec_frame_init_npwr(&frame, slave->master, slave->station_address, 0x0120,
-                       2, data);
-
-    if (unlikely(ec_frame_send_receive(&frame) != 0)) {
-        EC_ERR("Could not set state %02X - Unable to send!\n", state);
-        return -1;
-    }
-
-    if (unlikely(frame.working_counter != 1)) {
-        EC_ERR("Could not set state %02X - Slave %i did not respond!\n", state,
-               slave->ring_position);
+    ec_frame_init_npwr(&frame, slave->master, slave->station_address,
+                       0x0120, 2, data);
+
+    if (unlikely(ec_frame_send_receive(&frame))) {
+        EC_ERR("Failed to set state %02X on slave %i!\n",
+               state, slave->ring_position);
         return -1;
     }
 
@@ -306,13 +284,8 @@
         ec_frame_init_nprd(&frame, slave->master, slave->station_address,
                            0x0130, 2);
 
-        if (unlikely(ec_frame_send_receive(&frame) != 0)) {
-            EC_ERR("Could not check state %02X - Unable to send!\n", state);
-            return -1;
-        }
-
-        if (unlikely(frame.working_counter != 1)) {
-            EC_ERR("Could not check state %02X - Slave %i did not respond!\n",
+        if (unlikely(ec_frame_send_receive(&frame))) {
+            EC_ERR("Failed to check state %02X on slave %i!\n",
                    state, slave->ring_position);
             return -1;
         }
@@ -431,17 +404,11 @@
     ec_frame_t frame;
     uint8_t data[4];
 
-    ec_frame_init_nprd(&frame, slave->master, slave->station_address, 0x0300,
-                       4);
-
-    if (unlikely(ec_frame_send_receive(&frame))) {
-        EC_WARN("Reading CRC fault counters failed on slave %i - Could not"
-                " send command!\n", slave->ring_position);
-        return -1;
-    }
-
-    if (unlikely(frame.working_counter != 1)) {
-        EC_WARN("Reading CRC fault counters - Slave %i did not respond!\n",
+    ec_frame_init_nprd(&frame, slave->master, slave->station_address,
+                       0x0300, 4);
+
+    if (unlikely(ec_frame_send_receive(&frame))) {
+        EC_WARN("Reading CRC fault counters failed on slave %i!\n",
                 slave->ring_position);
         return -1;
     }
@@ -455,13 +422,11 @@
     // Reset CRC counters
     EC_WRITE_U16(data,     0x0000);
     EC_WRITE_U16(data + 2, 0x0000);
-    ec_frame_init_npwr(&frame, slave->master, slave->station_address, 0x0300,
-                       4, data);
-
-    if (unlikely(ec_frame_send_receive(&frame))) return -1;
-
-    if (unlikely(frame.working_counter != 1)) {
-        EC_WARN("Resetting CRC fault counters - Slave %i did not respond!\n",
+    ec_frame_init_npwr(&frame, slave->master, slave->station_address,
+                       0x0300, 4, data);
+
+    if (unlikely(ec_frame_send_receive(&frame))) {
+        EC_WARN("Resetting CRC fault counters failed on slave %i!\n",
                 slave->ring_position);
         return -1;
     }