mini/ec_mini.c
branchkernel2.6
changeset 26 60435f959e5c
parent 24 d417dd9bdc2f
child 27 d75ef6b46e33
equal deleted inserted replaced
25:7d124bfba3ce 26:60435f959e5c
     7  * $Id$
     7  * $Id$
     8  *
     8  *
     9  ******************************************************************************/
     9  ******************************************************************************/
    10 
    10 
    11 #include <linux/module.h>
    11 #include <linux/module.h>
    12 //#include <linux/slab.h>
       
    13 #include <linux/delay.h>
    12 #include <linux/delay.h>
    14 #include <linux/timer.h>
    13 #include <linux/timer.h>
    15 
    14 
    16 #include "../drivers/ec_master.h"
    15 #include "../drivers/ec_master.h"
    17 #include "../drivers/ec_device.h"
    16 #include "../drivers/ec_device.h"
    18 #include "../drivers/ec_types.h"
    17 #include "../drivers/ec_types.h"
    19 #include "../drivers/ec_dbg.h"
       
    20 
    18 
    21 /******************************************************************************/
    19 /******************************************************************************/
    22 
    20 
    23 #define ECAT
    21 #define ECAT
    24 
    22 
   252 #ifdef ECAT_OPEN
   250 #ifdef ECAT_OPEN
   253     int rv = -1;
   251     int rv = -1;
   254 #endif
   252 #endif
   255 #endif
   253 #endif
   256 
   254 
   257     EC_DBG(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n");
   255     printk(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n");
   258 
   256 
   259 #ifdef ECAT
   257 #ifdef ECAT
   260 
   258 
   261     EtherCAT_device_debug(&rtl_ecat_dev);
   259     EtherCAT_device_debug(&rtl_ecat_dev);
   262 
   260 
   263 #ifdef ECAT_OPEN
   261 #ifdef ECAT_OPEN
   264     EC_DBG("Opening EtherCAT device.\n");
   262     printk("Opening EtherCAT device.\n");
   265 
   263 
   266     // HIER PASSIERT DER FEHLER:
   264     // HIER PASSIERT DER FEHLER:
   267     if (EtherCAT_device_open(&rtl_ecat_dev) < 0)
   265     if (EtherCAT_device_open(&rtl_ecat_dev) < 0)
   268     {
   266     {
   269         EC_DBG(KERN_ERR "msr_modul: Could not initialize EtherCAT NIC.\n");
   267         printk(KERN_ERR "msr_modul: Could not initialize EtherCAT NIC.\n");
   270         goto out_nothing;
   268         goto out_nothing;
   271     }
   269     }
   272 
   270 
   273     if (!rtl_ecat_dev.dev) // Es gibt kein EtherCAT-Device
   271     if (!rtl_ecat_dev.dev) // Es gibt kein EtherCAT-Device
   274     {
   272     {
   275         EC_DBG(KERN_ERR "msr_modul: No EtherCAT device!\n");
   273         printk(KERN_ERR "msr_modul: No EtherCAT device!\n");
   276         goto out_close;
   274         goto out_close;
   277     }
   275     }
   278 #endif // ECAT_OPEN
   276 #endif // ECAT_OPEN
   279 
   277 
   280 #ifdef ECAT_MASTER
   278 #ifdef ECAT_MASTER
   281     EC_DBG("Initialising EtherCAT master\n");
   279     printk("Initialising EtherCAT master\n");
   282 
   280 
   283     if ((ecat_master = (EtherCAT_master_t *) kmalloc(sizeof(EtherCAT_master_t), GFP_KERNEL)) == 0)
   281     if ((ecat_master = (EtherCAT_master_t *) kmalloc(sizeof(EtherCAT_master_t), GFP_KERNEL)) == 0)
   284     {
   282     {
   285         EC_DBG(KERN_ERR "msr_modul: Could not alloc memory for EtherCAT master!\n");
   283         printk(KERN_ERR "msr_modul: Could not alloc memory for EtherCAT master!\n");
   286         goto out_close;
   284         goto out_close;
   287     }
   285     }
   288 
   286 
   289     if (EtherCAT_master_init(ecat_master, &rtl_ecat_dev) < 0)
   287     if (EtherCAT_master_init(ecat_master, &rtl_ecat_dev) < 0)
   290     {
   288     {
   291         EC_DBG(KERN_ERR "EtherCAT could not init master!\n");
   289         printk(KERN_ERR "EtherCAT could not init master!\n");
   292         goto out_master;
   290         goto out_master;
   293     }
   291     }
   294 
   292 
   295     //ecat_master->debug_level = 1;
   293     //ecat_master->debug_level = 1;
   296 
   294 
   297 #endif // ECAT_MASTER
   295 #endif // ECAT_MASTER
   298 
   296 
   299 #ifdef ECAT_SLAVES
   297 #ifdef ECAT_SLAVES
   300     EC_DBG("Checking EtherCAT slaves.\n");
   298     printk("Checking EtherCAT slaves.\n");
   301 
   299 
   302     if (EtherCAT_check_slaves(ecat_master, ecat_slaves, ECAT_SLAVES_COUNT) != 0)
   300     if (EtherCAT_check_slaves(ecat_master, ecat_slaves, ECAT_SLAVES_COUNT) != 0)
   303     {
   301     {
   304         EC_DBG(KERN_ERR "EtherCAT: Could not init slaves!\n");
   302         printk(KERN_ERR "EtherCAT: Could not init slaves!\n");
   305         goto out_masterclear;
   303         goto out_masterclear;
   306     }
   304     }
   307 
   305 
   308     EC_DBG("Activating all EtherCAT slaves.\n");
   306     printk("Activating all EtherCAT slaves.\n");
   309 
   307 
   310     if (EtherCAT_activate_all_slaves(ecat_master) != 0)
   308     if (EtherCAT_activate_all_slaves(ecat_master) != 0)
   311     {
   309     {
   312         EC_DBG(KERN_ERR "EtherCAT: Could not activate slaves!\n");
   310         printk(KERN_ERR "EtherCAT: Could not activate slaves!\n");
   313         goto out_masterclear;
   311         goto out_masterclear;
   314     }
   312     }
   315 #endif
   313 #endif
   316 
   314 
   317 #endif // ECAT
   315 #endif // ECAT
   318 
   316 
   319 #ifdef ECAT_CYCLIC_DATA
   317 #ifdef ECAT_CYCLIC_DATA
   320     EC_DBG("Starting cyclic sample thread.\n");
   318     printk("Starting cyclic sample thread.\n");
   321 
   319 
   322     schedule();
   320     schedule();
   323     mdelay(1000);
   321     mdelay(1000);
   324     schedule();
   322     schedule();
   325     init_timer(&timer);
   323     init_timer(&timer);
   328     timer.data = 0;
   326     timer.data = 0;
   329     timer.expires = jiffies+10; // Das erste Mal sofort feuern
   327     timer.expires = jiffies+10; // Das erste Mal sofort feuern
   330     last_start_jiffies = timer.expires;
   328     last_start_jiffies = timer.expires;
   331     add_timer(&timer);
   329     add_timer(&timer);
   332 
   330 
   333     EC_DBG("Initialised sample thread.\n");
   331     printk("Initialised sample thread.\n");
   334 #endif
   332 #endif
   335 
   333 
   336     EC_DBG(KERN_INFO "=== Minimal EtherCAT environment started. ===\n");
   334     printk(KERN_INFO "=== Minimal EtherCAT environment started. ===\n");
   337 
   335 
   338     return 0;
   336     return 0;
   339 
   337 
   340 #ifdef ECAT
   338 #ifdef ECAT
   341 
   339 
   342 #ifdef ECAT_SLAVES
   340 #ifdef ECAT_SLAVES
   343  out_masterclear:
   341  out_masterclear:
   344     EC_DBG(KERN_INFO "Clearing EtherCAT master.\n");
   342     printk(KERN_INFO "Clearing EtherCAT master.\n");
   345     EtherCAT_master_clear(ecat_master);
   343     EtherCAT_master_clear(ecat_master);
   346 #endif
   344 #endif
   347 
   345 
   348 #ifdef ECAT_MASTER
   346 #ifdef ECAT_MASTER
   349  out_master:
   347  out_master:
   350     EC_DBG(KERN_INFO "Freeing EtherCAT master.\n");
   348     printk(KERN_INFO "Freeing EtherCAT master.\n");
   351     kfree(ecat_master);
   349     kfree(ecat_master);
   352 #endif
   350 #endif
   353 
   351 
   354 #ifdef ECAT_OPEN
   352 #ifdef ECAT_OPEN
   355  out_close:
   353  out_close:
   356     EC_DBG(KERN_INFO "Closing device.\n");
   354     printk(KERN_INFO "Closing device.\n");
   357     EtherCAT_device_close(&rtl_ecat_dev);
   355     EtherCAT_device_close(&rtl_ecat_dev);
   358 
   356 
   359  out_nothing:
   357  out_nothing:
   360     return rv;
   358     return rv;
   361 #endif
   359 #endif
   369  *
   367  *
   370  ******************************************************************************/
   368  ******************************************************************************/
   371 
   369 
   372 void __exit cleanup_module()
   370 void __exit cleanup_module()
   373 {
   371 {
   374     EC_DBG(KERN_INFO "=== Stopping Minimal EtherCAT environment... ===\n");
   372     printk(KERN_INFO "=== Stopping Minimal EtherCAT environment... ===\n");
   375 
   373 
   376 #ifdef ECAT_MASTER
   374 #ifdef ECAT_MASTER
   377 
   375 
   378 #ifdef ECAT
   376 #ifdef ECAT
   379     if (ecat_master)
   377     if (ecat_master)
   392 #endif // ECAT_CYCLIC_DATA
   390 #endif // ECAT_CYCLIC_DATA
   393 
   391 
   394 #ifdef ECAT
   392 #ifdef ECAT
   395 
   393 
   396 #ifdef ECAT_SLAVES
   394 #ifdef ECAT_SLAVES
   397         EC_DBG(KERN_INFO "Deactivating slaves.\n");
   395         printk(KERN_INFO "Deactivating slaves.\n");
   398         EtherCAT_deactivate_all_slaves(ecat_master);
   396         EtherCAT_deactivate_all_slaves(ecat_master);
   399 #endif
   397 #endif
   400 
   398 
   401         EC_DBG(KERN_INFO "Clearing EtherCAT master.\n");
   399         printk(KERN_INFO "Clearing EtherCAT master.\n");
   402         EtherCAT_master_clear(ecat_master);
   400         EtherCAT_master_clear(ecat_master);
   403 
   401 
   404         EC_DBG(KERN_INFO "Freeing EtherCAT master.\n");
   402         printk(KERN_INFO "Freeing EtherCAT master.\n");
   405         kfree(ecat_master);
   403         kfree(ecat_master);
   406         ecat_master = NULL;
   404         ecat_master = NULL;
   407     }
   405     }
   408 #endif // ECAT
   406 #endif // ECAT
   409 
   407 
   410 #endif // ECAT_MASTER
   408 #endif // ECAT_MASTER
   411 
   409 
   412 #ifdef ECAT
   410 #ifdef ECAT
   413 #ifdef ECAT_OPEN
   411 #ifdef ECAT_OPEN
   414     EC_DBG(KERN_INFO "Closing device.\n");
   412     printk(KERN_INFO "Closing device.\n");
   415     EtherCAT_device_close(&rtl_ecat_dev);
   413     EtherCAT_device_close(&rtl_ecat_dev);
   416 #endif
   414 #endif
   417 #endif
   415 #endif
   418 
   416 
   419     EC_DBG(KERN_INFO "=== Minimal EtherCAT environment stopped. ===\n");
   417     printk(KERN_INFO "=== Minimal EtherCAT environment stopped. ===\n");
   420 }
   418 }
   421 
   419 
   422 /*****************************************************************************/
   420 /*****************************************************************************/
   423 
   421 
   424 MODULE_LICENSE("GPL");
   422 MODULE_LICENSE("GPL");