master/master.c
changeset 130 69c2645300ee
parent 129 67b6e534db4b
child 133 b36d187ecc0b
--- a/master/master.c	Fri Mar 24 08:56:16 2006 +0000
+++ b/master/master.c	Mon Mar 27 09:53:59 2006 +0000
@@ -101,6 +101,10 @@
     master->command_index = 0;
     master->debug_level = 0;
     master->timeout = 100; // us
+
+    master->slaves_responding = 0;
+    master->slave_states = EC_SLAVE_STATE_UNKNOWN;
+
     master->stats.timeouts = 0;
     master->stats.delayed = 0;
     master->stats.corrupted = 0;
@@ -389,7 +393,7 @@
         }
 
         // Keine direkte Antwort. Dem Slave Zeit lassen...
-        udelay(10);
+        udelay(100);
 
         if (unlikely(--response_tries_left)) {
             EC_ERR("No response in simple-IO!\n");
@@ -679,6 +683,58 @@
     EC_WRITE_U16(data + 14, 0x0000); // res.
 }
 
+/*****************************************************************************/
+
+/**
+   Gibt Überwachungsinformationen aus.
+*/
+
+void ec_master_process_watch_command(ec_master_t *master
+                                     /**< EtherCAT-Master */
+                                     )
+{
+    unsigned int first;
+
+    first = 1;
+
+    if (master->watch_command.working_counter != master->slaves_responding ||
+        master->watch_command.data[0] != master->slave_states)
+    {
+        master->slaves_responding = master->watch_command.working_counter;
+        master->slave_states = master->watch_command.data[0];
+
+        EC_INFO("%i slave%s responding (", master->slaves_responding,
+                master->slaves_responding == 1 ? "" : "s");
+
+        if (master->slave_states & EC_SLAVE_STATE_INIT) {
+            printk("INIT");
+            first = 0;
+        }
+        if (master->slave_states & EC_SLAVE_STATE_PREOP) {
+            if (!first) {
+                printk(", ");
+                first = 0;
+            }
+            printk("PREOP");
+        }
+        if (master->slave_states & EC_SLAVE_STATE_SAVEOP) {
+            if (!first) {
+                printk(", ");
+                first = 0;
+            }
+            printk("SAVEOP");
+        }
+        if (master->slave_states & EC_SLAVE_STATE_OP) {
+            if (!first) {
+                printk(", ");
+                first = 0;
+            }
+            printk("OP");
+        }
+        printk(")\n");
+    }
+}
+
 /******************************************************************************
  *
  * Echtzeitschnittstelle
@@ -836,6 +892,9 @@
             return -1;
     }
 
+    master->slaves_responding = master->slave_count;
+    master->slave_states = EC_SLAVE_STATE_OP;
+
     return 0;
 }
 
@@ -952,6 +1011,10 @@
         return;
     }
 
+    // Watch-Kommando hinzufügen
+    ec_command_init_brd(&master->watch_command, 0x130, 2);
+    ec_master_queue_command(master, &master->watch_command);
+
     // Rahmen senden
     ec_master_send_commands(master);
 }
@@ -966,8 +1029,6 @@
 {
     ec_command_t *command, *next;
 
-    ec_master_output_stats(master);
-
     ec_device_call_isr(master->device);
 
     // Alle empfangenen Kommandos aus der Liste entfernen
@@ -989,6 +1050,12 @@
         }
         list_del_init(&command->list);
     }
+
+    // Watch-Kommando verarbeiten
+    ec_master_process_watch_command(master);
+
+    // Statistiken ausgeben
+    ec_master_output_stats(master);
 }
 
 /*****************************************************************************/