Neue Schnittstellen in Mini ?bertragen.
authorFlorian Pose <fp@igh-essen.com>
Thu, 26 Jan 2006 11:06:56 +0000
changeset 60 2d2b120ba734
parent 59 c8bd4fe3b38c
child 61 cd014255f94f
Neue Schnittstellen in Mini ?bertragen.
mini/mini.c
--- a/mini/mini.c	Thu Jan 26 10:48:26 2006 +0000
+++ b/mini/mini.c	Thu Jan 26 11:06:56 2006 +0000
@@ -13,17 +13,12 @@
 #include <linux/timer.h>
 
 #include "../include/EtherCAT_rt.h"
-
-/*****************************************************************************/
-
-// Auskommentieren, wenn keine zyklischen Daten erwuenscht
-#define ECAT_CYCLIC_DATA
+#include "../include/EtherCAT_si.h"
 
 /*****************************************************************************/
 
 ec_master_t *master = NULL;
-
-#ifdef ECAT_CYCLIC_DATA
+ec_slave_t *s_in, *s_out;
 
 int value;
 int dig1;
@@ -31,31 +26,28 @@
 struct timer_list timer;
 unsigned long last_start_jiffies;
 
-#endif // ECAT_CYCLIC_DATA
+/*****************************************************************************/
 
-/******************************************************************************
- *
- * Function: run
- *
- * Beschreibung: Zyklischer Prozess
- *
- *****************************************************************************/
+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);
 
-#ifdef ECAT_CYCLIC_DATA
+    return s_in && s_out;
+}
 
-static void run(unsigned long data)
+/*****************************************************************************/
+
+void run(unsigned long data)
 {
-  static int ms = 0;
+    static int ms = 0;
     static unsigned long int k = 0;
     static int firstrun = 1;
 
     ms++;
     ms %= 1000;
 
-#if 0
-    if (klemme >= 0)
-        EtherCAT_write_value(&ecat_slaves[klemme], kanal, up_down);
-#endif
+    EC_WRITE_EL20XX(s_out, 3, EC_READ_EL31XX(s_in, 0) < 0);
 
     // Prozessdaten lesen und schreiben
     rdtscl(k);
@@ -66,13 +58,7 @@
     add_timer(&timer);
 }
 
-#endif // ECAT_CYCLIC_DATA
-
-/******************************************************************************
- *
- * Function: init
- *
- *****************************************************************************/
+/*****************************************************************************/
 
 int __init init_mini_module(void)
 {
@@ -83,7 +69,10 @@
         goto out_return;
     }
 
-    //check_slaves();
+    if (!check_slaves()) {
+        printk(KERN_ERR "Could not register slaves!\n");
+        goto out_release_master;
+    }
 
     printk("Activating all EtherCAT slaves.\n");
 
@@ -92,19 +81,17 @@
         goto out_release_master;
     }
 
-#ifdef ECAT_CYCLIC_DATA
     printk("Starting cyclic sample thread.\n");
 
     init_timer(&timer);
 
     timer.function = run;
     timer.data = 0;
-    timer.expires = jiffies+10; // Das erste Mal sofort feuern
+    timer.expires = jiffies + 10; // Das erste Mal sofort feuern
     last_start_jiffies = timer.expires;
     add_timer(&timer);
 
     printk("Initialised sample thread.\n");
-#endif
 
     printk(KERN_INFO "=== Minimal EtherCAT environment started. ===\n");
 
@@ -117,11 +104,7 @@
   return -1;
 }
 
-/******************************************************************************
- *
- * Function: cleanup
- *
- *****************************************************************************/
+/*****************************************************************************/
 
 void __exit cleanup_mini_module(void)
 {
@@ -129,9 +112,7 @@
 
     if (master)
     {
-#ifdef ECAT_CYCLIC_DATA
         del_timer_sync(&timer);
-#endif // ECAT_CYCLIC_DATA
 
         printk(KERN_INFO "Deactivating slaves.\n");