mini/ec_mini.c
branchkernel2.6
changeset 36 6e9de6fbf74c
parent 33 f4171b8aadf8
child 42 a22a202d0f42
--- a/mini/ec_mini.c	Fri Dec 16 15:23:56 2005 +0000
+++ b/mini/ec_mini.c	Fri Dec 16 15:25:13 2005 +0000
@@ -228,47 +228,51 @@
 
 int __init init_module()
 {
-  printk(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n");
-
-  if ((ecat_master = EtherCAT_request(0)) == NULL)
-  {
-    printk(KERN_ERR "EtherCAT master 0 not available!\n");
-    return -1;
-  }
-
-  printk("Checking EtherCAT slaves.\n");
-
-  if (EtherCAT_check_slaves(ecat_master, ecat_slaves, ECAT_SLAVES_COUNT) != 0)
-  {
-    printk(KERN_ERR "EtherCAT: Could not init slaves!\n");
-    return -1;
-  }
-
-  printk("Activating all EtherCAT slaves.\n");
-
-  if (EtherCAT_activate_all_slaves(ecat_master) != 0)
-  {
-    printk(KERN_ERR "EtherCAT: Could not activate slaves!\n");
-    return -1;
-  }
-
-#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
-  last_start_jiffies = timer.expires;
-  add_timer(&timer);
-
-  printk("Initialised sample thread.\n");
-#endif
-
-  printk(KERN_INFO "=== Minimal EtherCAT environment started. ===\n");
-
-  return 0;
+    printk(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n");
+
+    if ((ecat_master = EtherCAT_request(0)) == NULL) {
+        printk(KERN_ERR "EtherCAT master 0 not available!\n");
+        goto out_return;
+    }
+
+    printk("Checking EtherCAT slaves.\n");
+
+    if (EtherCAT_check_slaves(ecat_master, ecat_slaves, ECAT_SLAVES_COUNT) != 0) {
+        printk(KERN_ERR "EtherCAT: Could not init slaves!\n");
+        goto out_release_master;
+    }
+
+    printk("Activating all EtherCAT slaves.\n");
+
+    if (EtherCAT_activate_all_slaves(ecat_master) != 0)
+    {
+        printk(KERN_ERR "EtherCAT: Could not activate slaves!\n");
+        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
+    last_start_jiffies = timer.expires;
+    add_timer(&timer);
+
+    printk("Initialised sample thread.\n");
+#endif
+
+    printk(KERN_INFO "=== Minimal EtherCAT environment started. ===\n");
+
+    return 0;
+
+ out_release_master:
+  EtherCAT_release(ecat_master);
+
+ out_return:
+  return -1;
 }
 
 /******************************************************************************
@@ -284,14 +288,14 @@
     if (ecat_master)
     {
 #ifdef ECAT_CYCLIC_DATA
-      del_timer_sync(&timer);
-      EtherCAT_clear_process_data(ecat_master);
+        del_timer_sync(&timer);
+        EtherCAT_clear_process_data(ecat_master);
 #endif // ECAT_CYCLIC_DATA
 
-      printk(KERN_INFO "Deactivating slaves.\n");
-      EtherCAT_deactivate_all_slaves(ecat_master);
-
-      EtherCAT_release(ecat_master);
+        printk(KERN_INFO "Deactivating slaves.\n");
+        EtherCAT_deactivate_all_slaves(ecat_master);
+
+        EtherCAT_release(ecat_master);
     }
 
     printk(KERN_INFO "=== Minimal EtherCAT environment stopped. ===\n");