register_slave_list() und Bugfix in deactivate_slaves()
authorFlorian Pose <fp@igh-essen.com>
Thu, 26 Jan 2006 13:41:47 +0000
changeset 61 cd014255f94f
parent 60 2d2b120ba734
child 62 0fb2a690f4d0
register_slave_list() und Bugfix in deactivate_slaves()
include/EtherCAT_rt.h
master/master.c
master/types.h
mini/mini.c
rt/msr_module.c
--- a/include/EtherCAT_rt.h	Thu Jan 26 11:06:56 2006 +0000
+++ b/include/EtherCAT_rt.h	Thu Jan 26 13:41:47 2006 +0000
@@ -20,6 +20,9 @@
 struct ec_slave;
 typedef struct ec_slave ec_slave_t;
 
+struct ec_slave_init;
+typedef struct ec_slave_init ec_slave_init_t;
+
 /*****************************************************************************/
 
 ec_master_t *EtherCAT_rt_request_master(unsigned int master_index);
@@ -32,6 +35,10 @@
                                        const char *product_name,
                                        int domain);
 
+int EtherCAT_rt_register_slave_list(ec_master_t *master,
+                                    const ec_slave_init_t *slaves,
+                                    unsigned int count);
+
 int EtherCAT_rt_activate_slaves(ec_master_t *master);
 
 int EtherCAT_rt_deactivate_slaves(ec_master_t *master);
@@ -84,4 +91,24 @@
 
 /*****************************************************************************/
 
+/**
+   Beschreibung eines EtherCAT-Slave-Typs.
+
+   Diese Beschreibung dient zur Konfiguration einer bestimmten
+   Slave-Art. Sie enthält die Konfigurationsdaten für die
+   Slave-internen Sync-Manager und FMMU's.
+*/
+
+struct ec_slave_init
+{
+    ec_slave_t **slave_ptr; /**< Zeiger auf den Slave-Zeiger, der mit der
+                               Adresse des Slaves belegt werden soll. */
+    unsigned int bus_index; /**< Bus-Index des zu registrierenden Slaves */
+    const char *vendor_name; /**< Name des Herstellers */
+    const char *product_name; /**< Name des Slaves-Typs */
+    unsigned int domain; /**< Domäne, in der registriert werden soll. */
+};
+
+/*****************************************************************************/
+
 #endif
--- a/master/master.c	Thu Jan 26 11:06:56 2006 +0000
+++ b/master/master.c	Thu Jan 26 13:41:47 2006 +0000
@@ -615,7 +615,7 @@
   }
 
   if (unlikely(cmd.working_counter != 1)) {
-    printk(KERN_ERR "EtherCAT: Could not set state %02X - Device %i (%s %s)"
+    printk(KERN_ERR "EtherCAT: Could not set state %02X - Slave %i (%s %s)"
            " did not respond!\n", state_and_ack, slave->ring_position * (-1),
            slave->type->vendor_name, slave->type->product_name);
     return -1;
@@ -735,7 +735,7 @@
    @param product_name String mit dem Produktnamen
    @param domain Domäne, in der der Slave sein soll
 
-   @return 0 bei Erfolg, sonst < 0
+   @return Zeiger auf den Slave bei Erfolg, sonst NULL
 */
 
 ec_slave_t *EtherCAT_rt_register_slave(ec_master_t *master,
@@ -819,6 +819,37 @@
 /*****************************************************************************/
 
 /**
+   Registriert eine ganze Liste von Slaves beim Master.
+
+   @param master Der EtherCAT-Master
+   @param slaves Array von Slave-Initialisierungsstrukturen
+   @param count Anzahl der Strukturen in "slaves"
+
+   @return 0 bei Erfolg, sonst < 0
+*/
+
+int EtherCAT_rt_register_slave_list(ec_master_t *master,
+                                    const ec_slave_init_t *slaves,
+                                    unsigned int count)
+{
+  unsigned int i;
+
+  for (i = 0; i < count; i++)
+  {
+    if ((*(slaves[i].slave_ptr) =
+         EtherCAT_rt_register_slave(master, slaves[i].bus_index,
+                                    slaves[i].vendor_name,
+                                    slaves[i].product_name,
+                                    slaves[i].domain)) == NULL)
+      return -1;
+  }
+
+  return 0;
+}
+
+/*****************************************************************************/
+
+/**
    Konfiguriert alle Slaves und setzt den Operational-Zustand.
 
    Führt die komplette Konfiguration und Aktivierunge aller registrierten
@@ -1046,7 +1077,7 @@
 
   for (i = 0; i < master->bus_slaves_count; i++)
   {
-    slave = master->bus_slaves + 1;
+    slave = master->bus_slaves + i;
 
     if (unlikely(ec_state_change(master, slave, EC_SLAVE_STATE_INIT) != 0))
       return -1;
@@ -1155,6 +1186,7 @@
 /*****************************************************************************/
 
 EXPORT_SYMBOL(EtherCAT_rt_register_slave);
+EXPORT_SYMBOL(EtherCAT_rt_register_slave_list);
 EXPORT_SYMBOL(EtherCAT_rt_activate_slaves);
 EXPORT_SYMBOL(EtherCAT_rt_deactivate_slaves);
 EXPORT_SYMBOL(EtherCAT_rt_domain_xio);
--- a/master/types.h	Thu Jan 26 11:06:56 2006 +0000
+++ b/master/types.h	Thu Jan 26 13:41:47 2006 +0000
@@ -25,7 +25,7 @@
 
 typedef enum
 {
-  EC_SIMPLE_SLAVE, EC_MAILBOX_SLAVE, EC_NOSYNC_SLAVE
+    EC_SIMPLE_SLAVE, EC_MAILBOX_SLAVE, EC_NOSYNC_SLAVE
 }
 ec_slave_features_t;
 
@@ -41,25 +41,25 @@
 
 struct ec_slave_type
 {
-  const char *vendor_name; /**< Name des Herstellers */
-  const char *product_name; /**< Name des Slaves-Typs */
-  const char *product_desc; /**< Genauere Beschreibung des Slave-Typs */
+    const char *vendor_name; /**< Name des Herstellers */
+    const char *product_name; /**< Name des Slaves-Typs */
+    const char *product_desc; /**< Genauere Beschreibung des Slave-Typs */
 
-  ec_slave_features_t features; /**< Features des Slave-Typs */
+    ec_slave_features_t features; /**< Features des Slave-Typs */
 
-  const unsigned char *sm0; /**< Konfigurationsdaten des
-                               ersten Sync-Managers */
-  const unsigned char *sm1; /**< Konfigurationsdaten des
-                               zweiten Sync-Managers */
-  const unsigned char *sm2; /**< Konfigurationsdaten des
-                               dritten Sync-Managers */
-  const unsigned char *sm3; /**< Konfigurationsdaten des
-                               vierten Sync-Managers */
+    const unsigned char *sm0; /**< Konfigurationsdaten des
+                                 ersten Sync-Managers */
+    const unsigned char *sm1; /**< Konfigurationsdaten des
+                                 zweiten Sync-Managers */
+    const unsigned char *sm2; /**< Konfigurationsdaten des
+                                 dritten Sync-Managers */
+    const unsigned char *sm3; /**< Konfigurationsdaten des
+                                 vierten Sync-Managers */
 
-  const unsigned char *fmmu0; /**< Konfigurationsdaten
-                                 der ersten FMMU */
+    const unsigned char *fmmu0; /**< Konfigurationsdaten
+                                   der ersten FMMU */
 
-  unsigned int process_data_size; /**< Länge der Prozessdaten in Bytes */
+    unsigned int process_data_size; /**< Länge der Prozessdaten in Bytes */
 };
 
 /*****************************************************************************/
@@ -73,9 +73,9 @@
 
 typedef struct slave_ident
 {
-  unsigned int vendor_id; /**< Hersteller-Code */
-  unsigned int product_code; /**< Herstellerspezifischer Produktcode */
-  const ec_slave_type_t *type; /**< Zeiger auf den entsprechenden Slave-Typ */
+    unsigned int vendor_id; /**< Hersteller-Code */
+    unsigned int product_code; /**< Herstellerspezifischer Produktcode */
+    const ec_slave_type_t *type; /**< Zeiger auf den entsprechenden Typ */
 }
 ec_slave_ident_t;
 
--- a/mini/mini.c	Thu Jan 26 11:06:56 2006 +0000
+++ b/mini/mini.c	Thu Jan 26 13:41:47 2006 +0000
@@ -12,8 +12,8 @@
 #include <linux/delay.h>
 #include <linux/timer.h>
 
-#include "../include/EtherCAT_rt.h"
-#include "../include/EtherCAT_si.h"
+#include "../include/EtherCAT_rt.h" // Echtzeitschnittstelle
+#include "../include/EtherCAT_si.h" // Slave-Interface-Makros
 
 /*****************************************************************************/
 
@@ -26,15 +26,13 @@
 struct timer_list timer;
 unsigned long last_start_jiffies;
 
-/*****************************************************************************/
+ec_slave_init_t slaves[] = {
+    // Zeiger, Index, Herstellername, Produktname, Domäne
+    {  &s_out, 9,     "Beckhoff",     "EL2004",    1      },
+    {  &s_in,  1,     "Beckhoff",     "EL3102",    1      }
+};
 
-int __init check_slaves(void)
-{
-    s_in = EtherCAT_rt_register_slave(master, 1, "Beckhoff", "EL3102", 1);
-    s_out = EtherCAT_rt_register_slave(master, 9, "Beckhoff", "EL2004", 1);
-
-    return s_in && s_out;
-}
+#define SLAVE_COUNT (sizeof(slaves) / sizeof(ec_slave_init_t))
 
 /*****************************************************************************/
 
@@ -69,14 +67,16 @@
         goto out_return;
     }
 
-    if (!check_slaves()) {
+    //EtherCAT_rt_debug_level(master, 2);
+
+    if (EtherCAT_rt_register_slave_list(master, slaves, SLAVE_COUNT)) {
         printk(KERN_ERR "Could not register slaves!\n");
         goto out_release_master;
     }
 
     printk("Activating all EtherCAT slaves.\n");
 
-    if (EtherCAT_rt_activate_slaves(master) != 0) {
+    if (EtherCAT_rt_activate_slaves(master)) {
         printk(KERN_ERR "EtherCAT: Could not activate slaves!\n");
         goto out_release_master;
     }
--- a/rt/msr_module.c	Thu Jan 26 11:06:56 2006 +0000
+++ b/rt/msr_module.c	Thu Jan 26 13:41:47 2006 +0000
@@ -57,17 +57,14 @@
 double value;
 int dig1;
 
-/*****************************************************************************/
-
-static int register_slaves(void)
-{
-    s_in1 = EtherCAT_rt_register_slave(master, 1, "Beckhoff", "EL3102", 0);
-    s_out1 = EtherCAT_rt_register_slave(master, 8, "Beckhoff", "EL2004", 0);
-    s_out2 = EtherCAT_rt_register_slave(master, 9, "Beckhoff", "EL2004", 0);
-    s_out3 = EtherCAT_rt_register_slave(master, 10, "Beckhoff", "EL2004", 0);
-
-    return !s_in1 || !s_out1 || !s_out2 || !s_out3;
-}
+ec_slave_init_t slaves[] = {
+    {&s_in1, 1, "Beckhoff", "EL3102", 0},
+    {&s_out1, 8, "Beckhoff", "EL2004", 0},
+    {&s_out2, 9, "Beckhoff", "EL2004", 0},
+    {&s_out3, 10, "Beckhoff", "EL2004", 0}
+};
+
+#define SLAVE_COUNT (sizeof(slaves) / sizeof(ec_slave_init_t))
 
 /******************************************************************************
  *
@@ -194,28 +191,25 @@
         goto out_msr_cleanup;
     }
 
-    printk("Registering EtherCAT slaves.\n");
-    if (register_slaves()) {
-        printk(KERN_ERR "EtherCAT: Could not init slaves!\n");
+    if (EtherCAT_rt_register_slave_list(master, slaves, SLAVE_COUNT)) {
+        printk(KERN_ERR "EtherCAT: Could not register slaves!\n");
         goto out_release_master;
     }
 
-    printk("Activating all EtherCAT slaves.\n");
-
     if (EtherCAT_rt_activate_slaves(master) < 0) {
-      printk(KERN_ERR "EtherCAT: Could not activate slaves!\n");
-      goto out_release_master;
+        printk(KERN_ERR "EtherCAT: Could not activate slaves!\n");
+        goto out_release_master;
     }
 
     do_gettimeofday(&process_time);
-    msr_time_increment.tv_sec=0;
-    msr_time_increment.tv_usec=(unsigned int)(1000000/MSR_ABTASTFREQUENZ);
-
-    ipipe_init_attr (&attr);
-    attr.name     = "IPIPE-MSR-MODULE";
+    msr_time_increment.tv_sec = 0;
+    msr_time_increment.tv_usec = (unsigned int) (1000000 / MSR_ABTASTFREQUENZ);
+
+    ipipe_init_attr(&attr);
+    attr.name = "IPIPE-MSR-MODULE";
     attr.priority = IPIPE_ROOT_PRIO + 1;
-    attr.entry    = &domain_entry;
-    ipipe_register_domain(&this_domain,&attr);
+    attr.entry = &domain_entry;
+    ipipe_register_domain(&this_domain, &attr);
 
     return 0;