mini/ec_mini.c
branchkernel2.6
changeset 22 e8c2cd004e0b
parent 13 db0742533c10
child 23 39364fbcd069
equal deleted inserted replaced
21:ec912b010528 22:e8c2cd004e0b
     7  * $Id$
     7  * $Id$
     8  *
     8  *
     9  ******************************************************************************/
     9  ******************************************************************************/
    10 
    10 
    11 #include <linux/module.h>
    11 #include <linux/module.h>
    12 #include <linux/tqueue.h>
    12 //#include <linux/slab.h>
    13 #include <linux/slab.h>
    13 //#include <linux/delay.h>
    14 #include <linux/delay.h>
    14 #include <linux/timer.h>
    15 #include <linux/completion.h>
       
    16 
    15 
    17 #include "../drivers/ec_master.h"
    16 #include "../drivers/ec_master.h"
    18 #include "../drivers/ec_device.h"
    17 #include "../drivers/ec_device.h"
    19 #include "../drivers/ec_types.h"
    18 #include "../drivers/ec_types.h"
    20 #include "../drivers/ec_dbg.h"
    19 #include "../drivers/ec_dbg.h"
    21 
    20 
    22 /******************************************************************************/
    21 /******************************************************************************/
    23 
    22 
       
    23 #define ECAT
       
    24 
    24 #define ECAT_OPEN
    25 #define ECAT_OPEN
    25 #define ECAT_MASTER
    26 #define ECAT_MASTER
    26 #define ECAT_SLAVES
    27 #define ECAT_SLAVES
    27 #define ECAT_CYCLIC_DATA
    28 #define ECAT_CYCLIC_DATA
    28 
    29 
    29 /******************************************************************************/
    30 /******************************************************************************/
    30 
    31 
       
    32 #ifdef ECAT
       
    33 
    31 extern EtherCAT_device_t rtl_ecat_dev;
    34 extern EtherCAT_device_t rtl_ecat_dev;
    32 
    35 
    33 #ifdef ECAT_MASTER
    36 #ifdef ECAT_MASTER
    34 static EtherCAT_master_t *ecat_master = NULL;
    37 static EtherCAT_master_t *ecat_master = NULL;
    35 #endif
    38 #endif
    36 
    39 
    37 #ifdef ECAT_SLAVES
    40 #ifdef ECAT_SLAVES
    38 static EtherCAT_slave_t ecat_slaves[] =
    41 static EtherCAT_slave_t ecat_slaves[] =
    39 {
    42 {
    40 #if 0
    43 #if 0
    41   // Block 1
    44     // Block 1
    42   ECAT_INIT_SLAVE(Beckhoff_EK1100),
    45     ECAT_INIT_SLAVE(Beckhoff_EK1100),
    43   ECAT_INIT_SLAVE(Beckhoff_EL4102),
    46     ECAT_INIT_SLAVE(Beckhoff_EL4102),
    44   ECAT_INIT_SLAVE(Beckhoff_EL3162),
    47     ECAT_INIT_SLAVE(Beckhoff_EL3162),
    45   ECAT_INIT_SLAVE(Beckhoff_EL1014),
    48     ECAT_INIT_SLAVE(Beckhoff_EL1014),
    46   ECAT_INIT_SLAVE(Beckhoff_EL2004),
    49     ECAT_INIT_SLAVE(Beckhoff_EL2004),
    47   ECAT_INIT_SLAVE(Beckhoff_EL3102),
    50     ECAT_INIT_SLAVE(Beckhoff_EL3102),
    48   ECAT_INIT_SLAVE(Beckhoff_EL4102),
    51     ECAT_INIT_SLAVE(Beckhoff_EL4102),
    49   ECAT_INIT_SLAVE(Beckhoff_EL4102),
    52     ECAT_INIT_SLAVE(Beckhoff_EL4102),
    50   ECAT_INIT_SLAVE(Beckhoff_EL4102),
    53     ECAT_INIT_SLAVE(Beckhoff_EL4102),
    51   ECAT_INIT_SLAVE(Beckhoff_EL3162),
    54     ECAT_INIT_SLAVE(Beckhoff_EL3162),
    52   ECAT_INIT_SLAVE(Beckhoff_EL3162),
    55     ECAT_INIT_SLAVE(Beckhoff_EL3162),
    53   ECAT_INIT_SLAVE(Beckhoff_EL3162),
    56     ECAT_INIT_SLAVE(Beckhoff_EL3162),
    54   ECAT_INIT_SLAVE(Beckhoff_EL3102),
    57     ECAT_INIT_SLAVE(Beckhoff_EL3102),
    55   ECAT_INIT_SLAVE(Beckhoff_EL3102),
    58     ECAT_INIT_SLAVE(Beckhoff_EL3102),
    56   ECAT_INIT_SLAVE(Beckhoff_EL2004),
    59     ECAT_INIT_SLAVE(Beckhoff_EL2004),
    57   ECAT_INIT_SLAVE(Beckhoff_EL2004),
    60     ECAT_INIT_SLAVE(Beckhoff_EL2004),
    58   ECAT_INIT_SLAVE(Beckhoff_EL2004),
    61     ECAT_INIT_SLAVE(Beckhoff_EL2004),
    59   ECAT_INIT_SLAVE(Beckhoff_EL2004),
    62     ECAT_INIT_SLAVE(Beckhoff_EL2004),
    60 #endif
    63 #endif
    61 
    64 
    62   // Block 2
    65     // Block 2
    63   ECAT_INIT_SLAVE(Beckhoff_EK1100),
    66     ECAT_INIT_SLAVE(Beckhoff_EK1100),
    64   ECAT_INIT_SLAVE(Beckhoff_EL4102),
    67     ECAT_INIT_SLAVE(Beckhoff_EL4102),
    65   ECAT_INIT_SLAVE(Beckhoff_EL1014),
    68     ECAT_INIT_SLAVE(Beckhoff_EL1014),
    66   ECAT_INIT_SLAVE(Beckhoff_EL3162),
    69     ECAT_INIT_SLAVE(Beckhoff_EL3162),
    67   ECAT_INIT_SLAVE(Beckhoff_EL2004),
    70     ECAT_INIT_SLAVE(Beckhoff_EL2004),
    68   ECAT_INIT_SLAVE(Beckhoff_EL3102),
    71     ECAT_INIT_SLAVE(Beckhoff_EL3102),
    69 
    72 
    70   // Block 3
    73     // Block 3
    71   ECAT_INIT_SLAVE(Beckhoff_EK1100),
    74     ECAT_INIT_SLAVE(Beckhoff_EK1100),
    72   ECAT_INIT_SLAVE(Beckhoff_EL1014),
    75     ECAT_INIT_SLAVE(Beckhoff_EL1014),
    73   ECAT_INIT_SLAVE(Beckhoff_EL1014),
    76     ECAT_INIT_SLAVE(Beckhoff_EL1014),
    74   ECAT_INIT_SLAVE(Beckhoff_EL1014),
    77     ECAT_INIT_SLAVE(Beckhoff_EL1014),
    75   ECAT_INIT_SLAVE(Beckhoff_EL1014),
    78     ECAT_INIT_SLAVE(Beckhoff_EL1014),
    76   ECAT_INIT_SLAVE(Beckhoff_EL1014),
    79     ECAT_INIT_SLAVE(Beckhoff_EL1014),
    77   ECAT_INIT_SLAVE(Beckhoff_EL2004),
    80     ECAT_INIT_SLAVE(Beckhoff_EL2004),
    78   ECAT_INIT_SLAVE(Beckhoff_EL2004),
    81     ECAT_INIT_SLAVE(Beckhoff_EL2004),
    79   ECAT_INIT_SLAVE(Beckhoff_EL2004),
    82     ECAT_INIT_SLAVE(Beckhoff_EL2004),
    80   ECAT_INIT_SLAVE(Beckhoff_EL2004),
    83     ECAT_INIT_SLAVE(Beckhoff_EL2004),
    81   ECAT_INIT_SLAVE(Beckhoff_EL1014),
    84     ECAT_INIT_SLAVE(Beckhoff_EL1014),
    82   ECAT_INIT_SLAVE(Beckhoff_EL1014),
    85     ECAT_INIT_SLAVE(Beckhoff_EL1014),
    83   ECAT_INIT_SLAVE(Beckhoff_EL1014)
    86     ECAT_INIT_SLAVE(Beckhoff_EL1014)
    84 };
    87 };
    85 
    88 
    86 #define ECAT_SLAVES_COUNT (sizeof(ecat_slaves) / sizeof(EtherCAT_slave_t))
    89 #define ECAT_SLAVES_COUNT (sizeof(ecat_slaves) / sizeof(EtherCAT_slave_t))
    87 #endif
    90 
       
    91 #endif // ECAT_SLAVES
       
    92 
       
    93 #endif // ECAT
    88 
    94 
    89 #ifdef ECAT_CYCLIC_DATA
    95 #ifdef ECAT_CYCLIC_DATA
       
    96 
    90 double value;
    97 double value;
    91 int dig1;
    98 int dig1;
    92 struct tq_struct cyclic_task;
    99 
    93 struct clientdata {task_queue *queue;} cyclic_data;
   100 struct timer_list timer;
    94 static DECLARE_COMPLETION(on_exit);
   101 unsigned long last_start_jiffies;
    95 #endif
   102 
       
   103 #endif // ECAT_CYCLIC_DATA
    96 
   104 
    97 /******************************************************************************
   105 /******************************************************************************
    98  *
   106  *
    99  * Function: next2004
   107  * Function: next2004
   100  *
   108  *
   101  *****************************************************************************/
   109  *****************************************************************************/
   102 
   110 
       
   111 #ifdef ECAT
   103 #ifdef ECAT_CYCLIC_DATA
   112 #ifdef ECAT_CYCLIC_DATA
       
   113 
   104 static int next2004(int *wrap)
   114 static int next2004(int *wrap)
   105 {
   115 {
   106   static int i = 0;
   116     static int i = 0;
   107   unsigned int j = 0;
   117     unsigned int j = 0;
   108 
   118 
   109   *wrap = 0;
   119     *wrap = 0;
   110 
   120 
   111   for (j = 0; j < ECAT_SLAVES_COUNT; j++)
   121     for (j = 0; j < ECAT_SLAVES_COUNT; j++)
   112   {
   122     {
   113     i++;
   123         i++;
   114 
   124 
   115     i %= ECAT_SLAVES_COUNT;
   125         i %= ECAT_SLAVES_COUNT;
   116 
   126 
   117     if (i == 0) *wrap = 1;
   127         if (i == 0) *wrap = 1;
   118 
   128 
   119     if (ecat_slaves[i].desc == Beckhoff_EL2004)
   129         if (ecat_slaves[i].desc == Beckhoff_EL2004)
   120     {
   130         {
   121       return i;
   131             return i;
   122     }
   132         }
   123   }
   133     }
   124 
   134 
   125   return -1;
   135     return -1;
   126 }
   136 }
   127 #endif
   137 #endif
       
   138 #endif
   128 
   139 
   129 /******************************************************************************
   140 /******************************************************************************
   130  *
   141  *
   131  * Function: run
   142  * Function: run
   132  *
   143  *
   133  * Beschreibung: Zyklischer Prozess
   144  * Beschreibung: Zyklischer Prozess
   134  *
   145  *
   135  *****************************************************************************/
   146  *****************************************************************************/
   136 
   147 
   137 #ifdef ECAT_CYCLIC_DATA
   148 #ifdef ECAT_CYCLIC_DATA
   138 void run(void *ptr)
   149 
       
   150 static void run(unsigned long data)
   139 {
   151 {
   140   struct clientdata *data = (struct clientdata *) ptr;
   152 #ifdef ECAT
   141 
   153     static int ms = 0;
   142 #if 1
   154     static int cnt = 0;
   143   static int ms = 0;
   155     static unsigned long int k = 0;
   144   static int cnt = 0;
   156     static int firstrun = 1;
   145   static unsigned long int k = 0;
   157 
   146   static int firstrun = 1;
   158     static int klemme = 12;
   147 
   159     static int kanal = 0;
   148   static int klemme = 12;
   160     static int up_down = 0;
   149   static int kanal = 0;
   161     int wrap = 0;
   150   static int up_down = 0;
   162 
   151   int wrap = 0;
   163     ms++;
   152 
   164     ms %= 1000;
   153   ms++;
       
   154   ms %= 1000;
       
   155 
   165 
   156 #if 0
   166 #if 0
   157   ecat_tx_delay = ((unsigned int) (100000 / HZ) * (ecat_master->dev->tx_time-k))
   167     ecat_tx_delay = ((unsigned int) (100000 / HZ) * (ecat_master->dev->tx_time-k))
   158     / (current_cpu_data.loops_per_jiffy / 10);
   168         / (current_cpu_data.loops_per_jiffy / 10);
   159   ecat_rx_delay = ((unsigned int) (100000 / HZ) * (ecat_master->dev->rx_time-k))
   169     ecat_rx_delay = ((unsigned int) (100000 / HZ) * (ecat_master->dev->rx_time-k))
   160     / (current_cpu_data.loops_per_jiffy / 10);
   170         / (current_cpu_data.loops_per_jiffy / 10);
   161 
   171 
   162   rx_intr = ecat_master->dev->rx_intr_cnt;
   172     rx_intr = ecat_master->dev->rx_intr_cnt;
   163   tx_intr = ecat_master->dev->tx_intr_cnt;
   173     tx_intr = ecat_master->dev->tx_intr_cnt;
   164   total_intr = ecat_master->dev->intr_cnt;
   174     total_intr = ecat_master->dev->intr_cnt;
   165 #endif
   175 #endif
   166 
   176 
   167   // Prozessdaten lesen
   177     // Prozessdaten lesen
   168   if (!firstrun)
   178     if (!firstrun)
   169   {
   179     {
   170     klemme = next2004(&wrap);
   180         klemme = next2004(&wrap);
   171 
   181 
   172     EtherCAT_read_process_data(ecat_master);
   182         EtherCAT_read_process_data(ecat_master);
   173 
   183 
   174     // Daten lesen und skalieren
   184         // Daten lesen und skalieren
   175     value = EtherCAT_read_value(&ecat_master->slaves[5], 0) / 3276.7;
   185         value = EtherCAT_read_value(&ecat_master->slaves[5], 0) / 3276.7;
   176     dig1 = EtherCAT_read_value(&ecat_master->slaves[3], 0);
   186         dig1 = EtherCAT_read_value(&ecat_master->slaves[3], 0);
   177   }
   187     }
   178 
   188 
   179 #if 0
   189 #if 0
   180   // Daten schreiben
   190     // Daten schreiben
   181   EtherCAT_write_value(&ecat_master->slaves[4], 0, ms > 500 ? 1 : 0);
   191     EtherCAT_write_value(&ecat_master->slaves[4], 0, ms > 500 ? 1 : 0);
   182   EtherCAT_write_value(&ecat_master->slaves[4], 1, ms > 500 ? 0 : 1);
   192     EtherCAT_write_value(&ecat_master->slaves[4], 1, ms > 500 ? 0 : 1);
   183   EtherCAT_write_value(&ecat_master->slaves[4], 2, ms > 500 ? 0 : 1);
   193     EtherCAT_write_value(&ecat_master->slaves[4], 2, ms > 500 ? 0 : 1);
   184   EtherCAT_write_value(&ecat_master->slaves[4], 3, ms > 500 ? 1 : 0);
   194     EtherCAT_write_value(&ecat_master->slaves[4], 3, ms > 500 ? 1 : 0);
   185 #endif
   195 #endif
   186 
   196 
   187   if (cnt++ > 20)
   197     if (cnt++ > 20)
   188   {
   198     {
   189     cnt = 0;
   199         cnt = 0;
   190 
   200 
   191     if (++kanal > 3)
   201         if (++kanal > 3)
   192     {
   202         {
   193       kanal = 0;
   203             kanal = 0;
   194       klemme = next2004(&wrap);
   204             klemme = next2004(&wrap);
   195 
   205 
   196       if (wrap == 1)
   206             if (wrap == 1)
   197       {
   207             {
   198         if (up_down == 1) up_down = 0;
   208                 if (up_down == 1) up_down = 0;
   199         else up_down = 1;
   209                 else up_down = 1;
   200       }
   210             }
   201     }
   211         }
   202   }
   212     }
   203 
   213 
   204   if (klemme >= 0)
   214     if (klemme >= 0)
   205     EtherCAT_write_value(&ecat_master->slaves[klemme], kanal,up_down);
   215         EtherCAT_write_value(&ecat_master->slaves[klemme], kanal,up_down);
   206 
   216 
   207 #if 0
   217 #if 0
   208   EtherCAT_write_value(&ecat_master->slaves[13], 1, ms > 500 ? 0 : 1);
   218     EtherCAT_write_value(&ecat_master->slaves[13], 1, ms > 500 ? 0 : 1);
   209   EtherCAT_write_value(&ecat_master->slaves[14], 2, ms > 500 ? 0 : 1);
   219     EtherCAT_write_value(&ecat_master->slaves[14], 2, ms > 500 ? 0 : 1);
   210   EtherCAT_write_value(&ecat_master->slaves[15], 3, ms > 500 ? 1 : 0);
   220     EtherCAT_write_value(&ecat_master->slaves[15], 3, ms > 500 ? 1 : 0);
   211 #endif
   221 #endif
   212 
   222 
   213   // Prozessdaten schreiben
   223     // Prozessdaten schreiben
   214   rdtscl(k);
   224     rdtscl(k);
   215   EtherCAT_write_process_data(ecat_master);
   225     EtherCAT_write_process_data(ecat_master);
   216   firstrun = 0;
   226     firstrun = 0;
   217 #endif
   227 #endif
   218 
   228 
   219   if (data->queue)
   229     timer.expires += HZ / 100;
   220   {
   230     add_timer(&timer);
   221     // Neu in die Taskqueue eintragen
       
   222     queue_task(&cyclic_task, data->queue);
       
   223   }
       
   224   else
       
   225   {
       
   226     //last_queue_finished = 0;
       
   227     complete(&on_exit);
       
   228   }
       
   229 }
   231 }
   230 #endif
   232 
       
   233 #endif // ECAT_CYCLIC_DATA
   231 
   234 
   232 /******************************************************************************
   235 /******************************************************************************
   233 *
   236  *
   234 * Function: init
   237  * Function: init
   235 *
   238  *
   236 ******************************************************************************/
   239  ******************************************************************************/
   237 
   240 
   238 int init()
   241 int __init init_module()
   239 {
   242 {
       
   243 #ifdef ECAT
   240 #ifdef ECAT_OPEN
   244 #ifdef ECAT_OPEN
   241   int rv = -1;
   245     int rv = -1;
   242 #endif
   246 #endif
   243 
   247 #endif
   244   EC_DBG(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n");
   248 
   245 
   249     EC_DBG(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n");
   246   EtherCAT_device_debug(&rtl_ecat_dev);
   250 
   247   //mdelay(5000);
   251 #ifdef ECAT
       
   252 
       
   253     EtherCAT_device_debug(&rtl_ecat_dev);
   248 
   254 
   249 #ifdef ECAT_OPEN
   255 #ifdef ECAT_OPEN
   250   EC_DBG("Opening EtherCAT device.\n");
   256     EC_DBG("Opening EtherCAT device.\n");
   251 
   257 
   252   // HIER PASSIERT DER FEHLER:
   258     // HIER PASSIERT DER FEHLER:
   253   if (EtherCAT_device_open(&rtl_ecat_dev) < 0)
   259     if (EtherCAT_device_open(&rtl_ecat_dev) < 0)
   254   {
   260     {
   255     EC_DBG(KERN_ERR "msr_modul: Could not initialize EtherCAT NIC.\n");
   261         EC_DBG(KERN_ERR "msr_modul: Could not initialize EtherCAT NIC.\n");
   256     goto out_nothing;
   262         goto out_nothing;
   257   }
   263     }
   258 
   264 
   259   if (!rtl_ecat_dev.dev) // Es gibt kein EtherCAT-Device
   265     if (!rtl_ecat_dev.dev) // Es gibt kein EtherCAT-Device
   260   {
   266     {
   261     EC_DBG(KERN_ERR "msr_modul: No EtherCAT device!\n");
   267         EC_DBG(KERN_ERR "msr_modul: No EtherCAT device!\n");
   262     goto out_close;
   268         goto out_close;
   263   }
   269     }
   264 #endif
   270 #endif // ECAT_OPEN
   265 
   271 
   266 #ifdef ECAT_MASTER
   272 #ifdef ECAT_MASTER
   267   EC_DBG("Initialising EtherCAT master\n");
   273     EC_DBG("Initialising EtherCAT master\n");
   268 
   274 
   269   if ((ecat_master = (EtherCAT_master_t *) kmalloc(sizeof(EtherCAT_master_t), GFP_KERNEL)) == 0)
   275     if ((ecat_master = (EtherCAT_master_t *) kmalloc(sizeof(EtherCAT_master_t), GFP_KERNEL)) == 0)
   270   {
   276     {
   271     EC_DBG(KERN_ERR "msr_modul: Could not alloc memory for EtherCAT master!\n");
   277         EC_DBG(KERN_ERR "msr_modul: Could not alloc memory for EtherCAT master!\n");
   272     goto out_close;
   278         goto out_close;
   273   }
   279     }
   274 
   280 
   275   if (EtherCAT_master_init(ecat_master, &rtl_ecat_dev) < 0)
   281     if (EtherCAT_master_init(ecat_master, &rtl_ecat_dev) < 0)
   276   {
   282     {
   277     EC_DBG(KERN_ERR "EtherCAT could not init master!\n");
   283         EC_DBG(KERN_ERR "EtherCAT could not init master!\n");
   278     goto out_master;
   284         goto out_master;
   279   }
   285     }
   280 
   286 
   281   //ecat_master->debug_level = 1;
   287     //ecat_master->debug_level = 1;
   282 #endif
   288 
       
   289 #endif // ECAT_MASTER
   283 
   290 
   284 #ifdef ECAT_SLAVES
   291 #ifdef ECAT_SLAVES
   285   EC_DBG("Checking EtherCAT slaves.\n");
   292     EC_DBG("Checking EtherCAT slaves.\n");
   286 
   293 
   287   if (EtherCAT_check_slaves(ecat_master, ecat_slaves, ECAT_SLAVES_COUNT) != 0)
   294     if (EtherCAT_check_slaves(ecat_master, ecat_slaves, ECAT_SLAVES_COUNT) != 0)
   288   {
   295     {
   289     EC_DBG(KERN_ERR "EtherCAT: Could not init slaves!\n");
   296         EC_DBG(KERN_ERR "EtherCAT: Could not init slaves!\n");
   290     goto out_masterclear;
   297         goto out_masterclear;
   291   }
   298     }
   292 
   299 
   293   EC_DBG("Activating all EtherCAT slaves.\n");
   300     EC_DBG("Activating all EtherCAT slaves.\n");
   294 
   301 
   295   if (EtherCAT_activate_all_slaves(ecat_master) != 0)
   302     if (EtherCAT_activate_all_slaves(ecat_master) != 0)
   296   {
   303     {
   297     EC_DBG(KERN_ERR "EtherCAT: Could not activate slaves!\n");
   304         EC_DBG(KERN_ERR "EtherCAT: Could not activate slaves!\n");
   298     goto out_masterclear;
   305         goto out_masterclear;
   299   }
   306     }
   300 #endif
   307 #endif
       
   308 
       
   309 #endif // ECAT
   301 
   310 
   302 #ifdef ECAT_CYCLIC_DATA
   311 #ifdef ECAT_CYCLIC_DATA
   303   EC_DBG("Starting cyclic sample thread.\n");
   312     EC_DBG("Starting cyclic sample thread.\n");
   304 
   313 
   305   cyclic_task.routine = run;
   314     init_timer(&timer);
   306   cyclic_task.data = (void *) &cyclic_data;
   315 
   307   cyclic_data.queue = &tq_timer;
   316     timer.function = run;
   308   queue_task(&cyclic_task, &tq_timer);
   317     timer.data = 0;
   309 
   318     timer.expires = jiffies; // Das erste Mal sofort feuern
   310   EC_DBG("Initialised sample thread.\n");
   319     last_start_jiffies = timer.expires;
   311 #endif
   320     add_timer(&timer);
   312 
   321 
   313   EC_DBG(KERN_INFO "=== Minimal EtherCAT environment started. ===\n");
   322     EC_DBG("Initialised sample thread.\n");
   314 
   323 #endif
   315   return 0;
   324 
       
   325     EC_DBG(KERN_INFO "=== Minimal EtherCAT environment started. ===\n");
       
   326 
       
   327     return 0;
       
   328 
       
   329 #ifdef ECAT
   316 
   330 
   317 #ifdef ECAT_SLAVES
   331 #ifdef ECAT_SLAVES
   318  out_masterclear:
   332  out_masterclear:
   319   EC_DBG(KERN_INFO "Clearing EtherCAT master.\n");
   333     EC_DBG(KERN_INFO "Clearing EtherCAT master.\n");
   320   EtherCAT_master_clear(ecat_master);
   334     EtherCAT_master_clear(ecat_master);
   321 #endif
   335 #endif
   322 
   336 
   323 #ifdef ECAT_MASTER
   337 #ifdef ECAT_MASTER
   324  out_master:
   338  out_master:
   325   EC_DBG(KERN_INFO "Freeing EtherCAT master.\n");
   339     EC_DBG(KERN_INFO "Freeing EtherCAT master.\n");
   326   kfree(ecat_master);
   340     kfree(ecat_master);
   327 #endif
   341 #endif
   328 
   342 
   329 #ifdef ECAT_OPEN
   343 #ifdef ECAT_OPEN
   330  out_close:
   344  out_close:
   331   EC_DBG(KERN_INFO "Closing device.\n");
   345     EC_DBG(KERN_INFO "Closing device.\n");
   332   EtherCAT_device_close(&rtl_ecat_dev);
   346     EtherCAT_device_close(&rtl_ecat_dev);
   333 
   347 
   334  out_nothing:
   348  out_nothing:
   335   return rv;
   349     return rv;
   336 #endif
   350 #endif
       
   351 
       
   352 #endif // ECAT
   337 }
   353 }
   338 
   354 
   339 /******************************************************************************
   355 /******************************************************************************
   340 *
   356  *
   341 * Function: cleanup
   357  * Function: cleanup
   342 *
   358  *
   343 ******************************************************************************/
   359  ******************************************************************************/
   344 
   360 
   345 void cleanup()
   361 void __exit cleanup_module()
   346 {
   362 {
   347   EC_DBG(KERN_INFO "=== Stopping Minimal EtherCAT environment... ===\n");
   363     EC_DBG(KERN_INFO "=== Stopping Minimal EtherCAT environment... ===\n");
   348 
   364 
   349 #ifdef ECAT_MASTER
   365 #ifdef ECAT_MASTER
   350   if (ecat_master)
   366 
   351   {
   367 #ifdef ECAT
   352     //ecat_master->debug_level = 1;
   368     if (ecat_master)
       
   369     {
       
   370 #endif
       
   371         //ecat_master->debug_level = 1;
   353 
   372 
   354 #ifdef ECAT_CYCLIC_DATA
   373 #ifdef ECAT_CYCLIC_DATA
   355     cyclic_data.queue = NULL;
   374 
   356     wait_for_completion(&on_exit);
   375         del_timer_sync(&timer);
   357     EtherCAT_clear_process_data(ecat_master);
   376 
   358 #endif
   377 #ifdef ECAT
       
   378         EtherCAT_clear_process_data(ecat_master);
       
   379 #endif
       
   380 
       
   381 #endif // ECAT_CYCLIC_DATA
       
   382 
       
   383 #ifdef ECAT
   359 
   384 
   360 #ifdef ECAT_SLAVES
   385 #ifdef ECAT_SLAVES
   361     EC_DBG(KERN_INFO "Deactivating slaves.\n");
   386         EC_DBG(KERN_INFO "Deactivating slaves.\n");
   362     EtherCAT_deactivate_all_slaves(ecat_master);
   387         EtherCAT_deactivate_all_slaves(ecat_master);
   363 #endif
   388 #endif
   364 
   389 
   365     EC_DBG(KERN_INFO "Clearing EtherCAT master.\n");
   390         EC_DBG(KERN_INFO "Clearing EtherCAT master.\n");
   366     EtherCAT_master_clear(ecat_master);
   391         EtherCAT_master_clear(ecat_master);
   367 
   392 
   368     EC_DBG(KERN_INFO "Freeing EtherCAT master.\n");
   393         EC_DBG(KERN_INFO "Freeing EtherCAT master.\n");
   369     kfree(ecat_master);
   394         kfree(ecat_master);
   370     ecat_master = NULL;
   395         ecat_master = NULL;
   371   }
   396     }
   372 #endif
   397 #endif // ECAT
   373 
   398 
       
   399 #endif // ECAT_MASTER
       
   400 
       
   401 #ifdef ECAT
   374 #ifdef ECAT_OPEN
   402 #ifdef ECAT_OPEN
   375   EC_DBG(KERN_INFO "Closing device.\n");
   403     EC_DBG(KERN_INFO "Closing device.\n");
   376   EtherCAT_device_close(&rtl_ecat_dev);
   404     EtherCAT_device_close(&rtl_ecat_dev);
   377 #endif
   405 #endif
   378 
   406 #endif
   379   EC_DBG(KERN_INFO "=== Minimal EtherCAT environment stopped. ===\n");
   407 
       
   408     EC_DBG(KERN_INFO "=== Minimal EtherCAT environment stopped. ===\n");
   380 }
   409 }
   381 
   410 
   382 /*****************************************************************************/
   411 /*****************************************************************************/
   383 
   412 
   384 MODULE_LICENSE("GPL");
   413 MODULE_LICENSE("GPL");
   385 MODULE_AUTHOR ("Florian Pose <fp@igh-essen.com>");
   414 MODULE_AUTHOR ("Florian Pose <fp@igh-essen.com>");
   386 MODULE_DESCRIPTION ("Minimal EtherCAT environment");
   415 MODULE_DESCRIPTION ("Minimal EtherCAT environment");
   387 
   416 
   388 module_init(init);
   417 module_init(init_module);
   389 module_exit(cleanup);
   418 module_exit(cleanup_module);
   390 
   419 
   391 /*****************************************************************************/
   420 /*****************************************************************************/