Bugfix im Master, ec_master_reset() und laufendes Beispiel in rt.
authorFlorian Pose <fp@igh-essen.com>
Fri, 20 Jan 2006 16:04:10 +0000
changeset 56 36d1fa37f5e1
parent 55 059a9e712aa7
child 57 bae4965439b8
Bugfix im Master, ec_master_reset() und laufendes Beispiel in rt.
include/EtherCAT_rt.h
master/domain.c
master/domain.h
master/master.c
master/master.h
master/module.c
rt/Makefile
rt/msr_module.c
--- a/include/EtherCAT_rt.h	Fri Jan 20 13:32:31 2006 +0000
+++ b/include/EtherCAT_rt.h	Fri Jan 20 16:04:10 2006 +0000
@@ -30,14 +30,16 @@
                                        unsigned int slave_index,
                                        const char *vendor_name,
                                        const char *product_name,
-                                       unsigned int domain);
+                                       int domain);
 
 int EtherCAT_rt_activate_slaves(ec_master_t *master);
 
 int EtherCAT_rt_deactivate_slaves(ec_master_t *master);
 
-int EtherCAT_rt_exchange_io(ec_master_t *master, unsigned int domain,
-                            unsigned int timeout_us);
+int EtherCAT_rt_domain_xio(ec_master_t *master, unsigned int domain,
+                           unsigned int timeout_us);
+
+void EtherCAT_rt_debug_level(ec_master_t *master, int level);
 
 /*****************************************************************************/
 
--- a/master/domain.c	Fri Jan 20 13:32:31 2006 +0000
+++ b/master/domain.c	Fri Jan 20 16:04:10 2006 +0000
@@ -23,10 +23,10 @@
 
 void ec_domain_init(ec_domain_t *dom)
 {
-  dom->number = 0;
+  dom->number = -1;
   dom->data_size = 0;
   dom->logical_offset = 0;
-  dom->response_count = 0;
+  dom->response_count = 0xFFFFFFFF;
 
   memset(dom->data, 0x00, EC_FRAME_SIZE);
 }
--- a/master/domain.h	Fri Jan 20 13:32:31 2006 +0000
+++ b/master/domain.h	Fri Jan 20 16:04:10 2006 +0000
@@ -26,7 +26,7 @@
 
 typedef struct ec_domain
 {
-  unsigned int number; /*<< Domänen-Identifikation */
+  int number; /*<< Domänen-Identifikation */
   ec_command_t command; /**< Kommando zum Senden und Empfangen der
                            Prozessdaten */
   unsigned char data[EC_FRAME_SIZE]; /**< Prozessdaten-Array */
--- a/master/master.c	Fri Jan 20 13:32:31 2006 +0000
+++ b/master/master.c	Fri Jan 20 16:04:10 2006 +0000
@@ -81,6 +81,35 @@
 /*****************************************************************************/
 
 /**
+   Setzt den Master in den Ausgangszustand.
+
+   Bei einem "release" sollte immer diese Funktion aufgerufen werden,
+   da sonst Slave-Liste, Domains, etc. weiter existieren.
+
+   @param master Zeiger auf den zurückzusetzenden Master
+*/
+
+void ec_master_reset(ec_master_t *master)
+{
+  if (master->bus_slaves) {
+    kfree(master->bus_slaves);
+    master->bus_slaves = NULL;
+  }
+
+  master->bus_slaves_count = 0;
+  master->command_index = 0;
+  master->tx_data_length = 0;
+  master->rx_data_length = 0;
+  master->domain_count = 0;
+  master->debug_level = 0;
+  master->bus_time = 0;
+  master->frames_lost = 0;
+  master->t_lost_output = 0;
+}
+
+/*****************************************************************************/
+
+/**
    Öffnet das EtherCAT-Geraet des Masters.
 
    @param master Der EtherCAT-Master
@@ -710,13 +739,18 @@
                                        unsigned int bus_index,
                                        const char *vendor_name,
                                        const char *product_name,
-                                       unsigned int domain)
+                                       int domain)
 {
   ec_slave_t *slave;
   const ec_slave_type_t *type;
   ec_domain_t *dom;
   unsigned int j;
 
+  if (domain < 0) {
+    printk(KERN_ERR "EtherCAT: Invalid domain: %i\n", domain);
+    return NULL;
+  }
+
   if (bus_index >= master->bus_slaves_count) {
     printk(KERN_ERR "EtherCAT: Illegal bus index! (%i / %i)\n", bus_index,
            master->bus_slaves_count);
@@ -734,7 +768,7 @@
 
   if (strcmp(vendor_name, type->vendor_name) ||
       strcmp(product_name, type->product_name)) {
-    printk(KERN_ERR "Invalid Slave Type! Requested: \"%s %s\", present: \"%s"
+    printk(KERN_ERR "Invalid Slave Type! Requested: \"%s %s\", found: \"%s"
            " %s\".\n", vendor_name, product_name, type->vendor_name,
            type->product_name);
     return NULL;
@@ -745,6 +779,7 @@
   for (j = 0; j < master->domain_count; j++) {
     if (domain == master->domains[j].number) {
       dom = master->domains + j;
+      break;
     }
   }
 
@@ -770,8 +805,10 @@
   }
 
   slave->process_data = dom->data + dom->data_size;
+  slave->logical_address = dom->data_size;
+  slave->registered = 1;
+
   dom->data_size += type->process_data_size;
-  slave->registered = 1;
 
   return slave;
 }
@@ -1029,8 +1066,8 @@
    @return 0 bei Erfolg, sonst < 0
 */
 
-int EtherCAT_rt_exchange_io(ec_master_t *master, unsigned int domain,
-                            unsigned int timeout_us)
+int EtherCAT_rt_domain_xio(ec_master_t *master, unsigned int domain,
+                           unsigned int timeout_us)
 {
   unsigned int i;
   ec_domain_t *dom;
@@ -1105,10 +1142,22 @@
 
 /*****************************************************************************/
 
+/**
+   Setzt die Debug-Ebene des Masters.
+*/
+
+void EtherCAT_rt_debug_level(ec_master_t *master, int level)
+{
+  master->debug_level = level;
+}
+
+/*****************************************************************************/
+
 EXPORT_SYMBOL(EtherCAT_rt_register_slave);
 EXPORT_SYMBOL(EtherCAT_rt_activate_slaves);
 EXPORT_SYMBOL(EtherCAT_rt_deactivate_slaves);
-EXPORT_SYMBOL(EtherCAT_rt_exchange_io);
+EXPORT_SYMBOL(EtherCAT_rt_domain_xio);
+EXPORT_SYMBOL(EtherCAT_rt_debug_level);
 
 /*****************************************************************************/
 
--- a/master/master.h	Fri Jan 20 13:32:31 2006 +0000
+++ b/master/master.h	Fri Jan 20 16:04:10 2006 +0000
@@ -55,6 +55,7 @@
 // Master creation and deletion
 void ec_master_init(ec_master_t *);
 void ec_master_clear(ec_master_t *);
+void ec_master_reset(ec_master_t *);
 
 // Registration of devices
 int ec_master_open(ec_master_t *);
--- a/master/module.c	Fri Jan 20 13:32:31 2006 +0000
+++ b/master/module.c	Fri Jan 20 16:04:10 2006 +0000
@@ -324,6 +324,8 @@
       }
 
       ec_master_close(master);
+      ec_master_reset(master);
+
       module_put(master->device.module);
       ec_masters_reserved[i] = 0;
 
--- a/rt/Makefile	Fri Jan 20 13:32:31 2006 +0000
+++ b/rt/Makefile	Fri Jan 20 16:04:10 2006 +0000
@@ -11,7 +11,7 @@
 #------------------------------------------------------------------------------
 # Kbuild-Abschnitt
 
-obj-m	:= msr_modul.o
+obj-m := msr_modul.o
 
 msr_modul-objs := msr_module.o \
 		msr_jitter.o \
--- a/rt/msr_module.c	Fri Jan 20 13:32:31 2006 +0000
+++ b/rt/msr_module.c	Fri Jan 20 16:04:10 2006 +0000
@@ -33,6 +33,7 @@
 
 // EtherCAT
 #include "../include/EtherCAT_rt.h"
+#include "../eclib/eclib.h"
 
 // Defines/Makros
 #define TSC2US(T1, T2) ((T2 - T1) * 1000UL / cpu_khz)
@@ -55,8 +56,7 @@
 static unsigned int ecat_bus_time = 0;
 static unsigned int ecat_timeouts = 0;
 
-ec_slave_t *s_controller;
-ec_slave_t *s_analog_in;
+ec_slave_t *s_in1, *s_out1, *s_out2, *s_out3;
 
 double value;
 int dig1;
@@ -65,12 +65,12 @@
 
 static int register_slaves(void)
 {
-    s_controller = EtherCAT_rt_register_slave(master, 0,
-                                              "Beckhoff", "EK1100", 0);
-    s_analog_in = EtherCAT_rt_register_slave(master, 1,
-                                             "Beckhoff", "EL3102", 0);
-
-    return !s_controller || !s_analog_in;
+    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;
 }
 
 /******************************************************************************
@@ -81,30 +81,30 @@
 
 static void msr_controller_run(void)
 {
-    static unsigned int debug_counter = 0;
-
-    // Prozessdaten lesen
+    static unsigned int counter = 0;
+
     msr_jitter_run(MSR_ABTASTFREQUENZ);
 
-#if 0
-    if (debug_counter == 0) {
-        master->debug_level = 2;
-    }
-#endif
+    if (counter) {
+        counter--;
+    }
+    else {
+        // "Star Trek"-Effekte
+        *((unsigned char *) s_out1->process_data) = jiffies;
+        *((unsigned char *) s_out2->process_data) = jiffies >> 4;
+        *((unsigned char *) s_out3->process_data) = jiffies >> 8;
+
+        counter = MSR_ABTASTFREQUENZ / 4;
+    }
+
+    if (((char *) s_in1->process_data)[2] < 0)
+        ((unsigned char *) s_out3->process_data)[0] |= 8;
+    else
+        ((unsigned char *) s_out3->process_data)[0] &= ~8;
+
 
     // Prozessdaten lesen und schreiben
-    EtherCAT_rt_exchange_io(master, 0, 40);
-
-#if 0
-    if (debug_counter == 0) {
-        master->debug_level = 0;
-    }
-#endif
-
-    //    value = EtherCAT_read_value(&ecat_slaves[1], 0);
-
-    debug_counter++;
-    if (debug_counter >= MSR_ABTASTFREQUENZ * 5) debug_counter = 0;
+    EtherCAT_rt_domain_xio(master, 0, 40);
 }
 
 /******************************************************************************
@@ -126,8 +126,6 @@
 {
     static int counter = 0;
 
-    // Schreibe Kanal1 von Klemme X auf 1
-
     timeval_add(&process_time, &process_time, &msr_time_increment);
     MSR_ADEOS_INTERRUPT_CODE(msr_controller_run(); msr_write_kanal_list(););