rt/msr_module.c
changeset 54 7506e67dd122
parent 51 b3beaa00640f
child 55 059a9e712aa7
equal deleted inserted replaced
53:6b3b8acb71b5 54:7506e67dd122
    30 #include <msr_reg.h>
    30 #include <msr_reg.h>
    31 #include "msr_param.h"
    31 #include "msr_param.h"
    32 #include "msr_jitter.h"
    32 #include "msr_jitter.h"
    33 
    33 
    34 // EtherCAT
    34 // EtherCAT
    35 #include "../drivers/ec_master.h"
    35 #include "../include/EtherCAT_rt.h"
    36 #include "../drivers/ec_device.h"
       
    37 #include "../drivers/ec_types.h"
       
    38 #include "../drivers/ec_module.h"
       
    39 
    36 
    40 // Defines/Makros
    37 // Defines/Makros
    41 #define TSC2US(T1, T2) ((T2 - T1) * 1000UL / cpu_khz)
    38 #define TSC2US(T1, T2) ((T2 - T1) * 1000UL / cpu_khz)
    42 #define HZREDUCTION (MSR_ABTASTFREQUENZ / HZ)
    39 #define HZREDUCTION (MSR_ABTASTFREQUENZ / HZ)
    43 
    40 
    52 static struct ipipe_domain this_domain;
    49 static struct ipipe_domain this_domain;
    53 static struct ipipe_sysinfo sys_info;
    50 static struct ipipe_sysinfo sys_info;
    54 
    51 
    55 // EtherCAT
    52 // EtherCAT
    56 
    53 
    57 static EtherCAT_master_t *ecat_master = NULL;
    54 ec_master_t *master = NULL;
    58 static unsigned int ecat_bus_time = 0;
    55 static unsigned int ecat_bus_time = 0;
    59 static unsigned int ecat_timeouts = 0;
    56 static unsigned int ecat_timeouts = 0;
    60 
    57 
    61 static EtherCAT_slave_t ecat_slaves[] =
    58 #if 0
       
    59 static ec_slave_t slaves[] =
    62 {
    60 {
    63     // Block 1
    61     // Block 1
    64     ECAT_INIT_SLAVE(Beckhoff_EK1100, 0),
    62     ECAT_INIT_SLAVE(Beckhoff_EK1100, 0),
    65     ECAT_INIT_SLAVE(Beckhoff_EL3102, 0)
    63     ECAT_INIT_SLAVE(Beckhoff_EL3102, 0)
    66 };
    64 };
       
    65 #endif
    67 
    66 
    68 #define ECAT_SLAVES_COUNT (sizeof(ecat_slaves) / sizeof(EtherCAT_slave_t))
    67 #define ECAT_SLAVES_COUNT (sizeof(ecat_slaves) / sizeof(EtherCAT_slave_t))
    69 
    68 
    70 #define USE_MSR_LIB
    69 #define USE_MSR_LIB
    71 
    70 
    85     static unsigned int debug_counter = 0;
    84     static unsigned int debug_counter = 0;
    86 
    85 
    87     // Prozessdaten lesen
    86     // Prozessdaten lesen
    88     msr_jitter_run(MSR_ABTASTFREQUENZ);
    87     msr_jitter_run(MSR_ABTASTFREQUENZ);
    89 
    88 
       
    89 #if 0
    90     if (debug_counter == 0) {
    90     if (debug_counter == 0) {
    91         ecat_master->debug_level = 2;
    91         master->debug_level = 2;
    92     }
    92     }
    93 
    93 #endif
    94     // Prozessdaten schreiben
    94 
    95 
    95     // Prozessdaten lesen und schreiben
    96     if (EtherCAT_process_data_cycle(ecat_master, 0, 40) < 0)
    96     EtherCAT_rt_domain_cycle(master, 0, 40);
    97         ecat_timeouts++;
    97 
    98 
    98 #if 0
    99     if (debug_counter == 0) {
    99     if (debug_counter == 0) {
   100         ecat_master->debug_level = 0;
   100         master->debug_level = 0;
   101     }
   101     }
   102 
   102 #endif
   103     value = EtherCAT_read_value(&ecat_slaves[1], 0);
   103 
       
   104     //    value = EtherCAT_read_value(&ecat_slaves[1], 0);
   104 
   105 
   105     debug_counter++;
   106     debug_counter++;
   106     if (debug_counter >= MSR_ABTASTFREQUENZ * 5) debug_counter = 0;
   107     if (debug_counter >= MSR_ABTASTFREQUENZ * 5) debug_counter = 0;
   107 }
   108 }
   108 
   109 
   181 
   182 
   182 /******************************************************************************
   183 /******************************************************************************
   183  * the init/clean material
   184  * the init/clean material
   184  *****************************************************************************/
   185  *****************************************************************************/
   185 
   186 
   186 int __init init_module()
   187 int __init init_rt_module(void)
   187 {
   188 {
   188     unsigned int i;
       
   189     struct ipipe_domain_attr attr; //ipipe
   189     struct ipipe_domain_attr attr; //ipipe
   190 
   190 
   191     // Als allererstes die RT-lib initialisieren
   191     // Als allererstes die RT-lib initialisieren
   192 #ifdef USE_MSR_LIB
   192 #ifdef USE_MSR_LIB
   193     if (msr_rtlib_init(1,MSR_ABTASTFREQUENZ,10,&msr_globals_register) < 0) {
   193     if (msr_rtlib_init(1,MSR_ABTASTFREQUENZ,10,&msr_globals_register) < 0) {
   198 
   198 
   199     msr_jitter_init();
   199     msr_jitter_init();
   200 
   200 
   201     printk(KERN_INFO "=== Starting EtherCAT environment... ===\n");
   201     printk(KERN_INFO "=== Starting EtherCAT environment... ===\n");
   202 
   202 
   203     if ((ecat_master = EtherCAT_request(0)) == NULL) {
   203     if ((master = EtherCAT_rt_request_master(0)) == NULL) {
   204         printk(KERN_ERR "EtherCAT master 0 not available!\n");
   204         printk(KERN_ERR "EtherCAT master 0 not available!\n");
   205         goto out_msr_cleanup;
   205         goto out_msr_cleanup;
   206     }
   206     }
   207 
   207 
       
   208 #if 0
   208     printk("Checking EtherCAT slaves.\n");
   209     printk("Checking EtherCAT slaves.\n");
   209 
   210     if (EtherCAT_check_slaves(master, ecat_slaves, ECAT_SLAVES_COUNT) != 0) {
   210     if (EtherCAT_check_slaves(ecat_master, ecat_slaves, ECAT_SLAVES_COUNT) != 0) {
       
   211         printk(KERN_ERR "EtherCAT: Could not init slaves!\n");
   211         printk(KERN_ERR "EtherCAT: Could not init slaves!\n");
   212         goto out_release_master;
   212         goto out_release_master;
   213     }
   213     }
       
   214 #endif
   214 
   215 
   215     printk("Activating all EtherCAT slaves.\n");
   216     printk("Activating all EtherCAT slaves.\n");
   216 
   217 
   217     for (i = 0; i < ECAT_SLAVES_COUNT; i++) {
   218     if (EtherCAT_rt_activate_slaves(master) < 0) {
   218         if (EtherCAT_activate_slave(ecat_master, ecat_slaves + i) < 0) {
   219       printk(KERN_ERR "EtherCAT: Could not activate slaves!\n");
   219             printk(KERN_ERR "EtherCAT: Could not activate slave %i!\n", i);
   220       goto out_release_master;
   220             goto out_release_master;
       
   221         }
       
   222     }
   221     }
   223 
   222 
   224     do_gettimeofday(&process_time);
   223     do_gettimeofday(&process_time);
   225     msr_time_increment.tv_sec=0;
   224     msr_time_increment.tv_sec=0;
   226     msr_time_increment.tv_usec=(unsigned int)(1000000/MSR_ABTASTFREQUENZ);
   225     msr_time_increment.tv_usec=(unsigned int)(1000000/MSR_ABTASTFREQUENZ);
   232     ipipe_register_domain(&this_domain,&attr);
   231     ipipe_register_domain(&this_domain,&attr);
   233 
   232 
   234     return 0;
   233     return 0;
   235 
   234 
   236  out_release_master:
   235  out_release_master:
   237     EtherCAT_release(ecat_master);
   236     EtherCAT_rt_release_master(master);
   238 
   237 
   239  out_msr_cleanup:
   238  out_msr_cleanup:
   240     msr_rtlib_cleanup();
   239     msr_rtlib_cleanup();
   241 
   240 
   242  out_return:
   241  out_return:
   243     return -1;
   242     return -1;
   244 }
   243 }
   245 
   244 
   246 /*****************************************************************************/
   245 /*****************************************************************************/
   247 
   246 
   248 void __exit cleanup_module()
   247 void __exit cleanup_rt_module(void)
   249 {
   248 {
   250     unsigned int i;
       
   251 
       
   252     msr_print_info("msk_modul: unloading...");
   249     msr_print_info("msk_modul: unloading...");
   253 
   250 
   254     ipipe_tune_timer(1000000000UL / HZ, 0); //alten Timertakt wieder herstellen
   251     ipipe_tune_timer(1000000000UL / HZ, 0); //alten Timertakt wieder herstellen
   255     ipipe_unregister_domain(&this_domain);
   252     ipipe_unregister_domain(&this_domain);
   256 
   253 
   257     if (ecat_master)
   254     if (master)
   258     {
   255     {
   259         printk(KERN_INFO "=== Stopping EtherCAT environment... ===\n");
   256         printk(KERN_INFO "=== Stopping EtherCAT environment... ===\n");
   260 
   257 
   261         printk(KERN_INFO "Deactivating slaves.\n");
   258         printk(KERN_INFO "Deactivating slaves.\n");
   262 
   259 
   263         for (i = 0; i < ECAT_SLAVES_COUNT; i++) {
   260         if (EtherCAT_rt_deactivate_slaves(master) < 0) {
   264             if (EtherCAT_deactivate_slave(ecat_master, ecat_slaves + i) < 0) {
   261           printk(KERN_WARNING "Warning - Could not deactivate slaves!\n");
   265                 printk(KERN_WARNING "Warning - Could not deactivate slave!\n");
       
   266             }
       
   267         }
   262         }
   268 
   263 
   269         EtherCAT_release(ecat_master);
   264         EtherCAT_rt_release_master(master);
   270 
   265 
   271         printk(KERN_INFO "=== EtherCAT environment stopped. ===\n");
   266         printk(KERN_INFO "=== EtherCAT environment stopped. ===\n");
   272     }
   267     }
   273 
   268 
   274 #ifdef USE_MSR_LIB
   269 #ifdef USE_MSR_LIB
   280 
   275 
   281 MODULE_LICENSE("GPL");
   276 MODULE_LICENSE("GPL");
   282 MODULE_AUTHOR ("Wilhelm Hagemeister <hm@igh-essen.com>");
   277 MODULE_AUTHOR ("Wilhelm Hagemeister <hm@igh-essen.com>");
   283 MODULE_DESCRIPTION ("EtherCAT test environment");
   278 MODULE_DESCRIPTION ("EtherCAT test environment");
   284 
   279 
   285 module_init(init_module);
   280 module_init(init_rt_module);
   286 module_exit(cleanup_module);
   281 module_exit(cleanup_rt_module);
   287 
   282 
   288 /*****************************************************************************/
   283 /*****************************************************************************/