rt/msr_module.c
branchkernel2.6
changeset 36 6e9de6fbf74c
parent 33 f4171b8aadf8
child 38 3213cbbd58b7
equal deleted inserted replaced
35:ed834aa98f89 36:6e9de6fbf74c
    29 *
    29 *
    30 *           Revision 1.13  2005/06/17 11:35:13  hm
    30 *           Revision 1.13  2005/06/17 11:35:13  hm
    31 *           *** empty log message ***
    31 *           *** empty log message ***
    32 *
    32 *
    33 *
    33 *
    34 *
    34 *           Hello Emacs: -*- c-basic-offset: 2; -*-
    35 *
    35 *
    36 **************************************************************************************************/
    36 **************************************************************************************************/
    37 
    37 
    38 
    38 
    39 /*--includes-------------------------------------------------------------------------------------*/
    39 /*--includes-------------------------------------------------------------------------------------*/
   161     ECAT_INIT_SLAVE(Beckhoff_EL3102),
   161     ECAT_INIT_SLAVE(Beckhoff_EL3102),
   162 
   162 
   163     ECAT_INIT_SLAVE(Beckhoff_EL4102),
   163     ECAT_INIT_SLAVE(Beckhoff_EL4102),
   164     ECAT_INIT_SLAVE(Beckhoff_EL4102),
   164     ECAT_INIT_SLAVE(Beckhoff_EL4102),
   165     ECAT_INIT_SLAVE(Beckhoff_EL4102),
   165     ECAT_INIT_SLAVE(Beckhoff_EL4102),
   166     ECAT_INIT_SLAVE(Beckhoff_EL4102)
   166     ECAT_INIT_SLAVE(Beckhoff_EL4102),
       
   167     ECAT_INIT_SLAVE(Beckhoff_EL4132)
   167 
   168 
   168 
   169 
   169 #endif
   170 #endif
   170 };
   171 };
   171 
   172 
   292 * Beschreibung: Routine wird zyklisch im Timerinterrupt ausgeführt
   293 * Beschreibung: Routine wird zyklisch im Timerinterrupt ausgeführt
   293 *               (hier muß alles rein, was Echtzeit ist ...)
   294 *               (hier muß alles rein, was Echtzeit ist ...)
   294 *
   295 *
   295 * Parameter: Zeiger auf msr_data
   296 * Parameter: Zeiger auf msr_data
   296 *
   297 *
   297 * Rückgabe: 
   298 * Rückgabe:
   298 *               
   299 *
   299 * Status: exp
   300 * Status: exp
   300 *
   301 *
   301 ***************************************************************************************************
   302 ***************************************************************************************************
   302 */
   303 */
   303 
   304 
   304 
   305 
   305 void msr_run(unsigned irq)
   306 void msr_run(unsigned irq)
   306 {
   307 {
   307 
   308 
   308     static int counter = 0;
   309   static int counter = 0;
   309 #ifdef USE_MSR_LIB
   310 #ifdef USE_MSR_LIB
   310 
   311 
   311     timeval_add(&process_time,&process_time,&msr_time_increment); 
   312     timeval_add(&process_time,&process_time,&msr_time_increment);
   312 
   313 
   313     MSR_ADEOS_INTERRUPT_CODE(
   314     MSR_ADEOS_INTERRUPT_CODE(
   314 	msr_controller_run();
   315 	msr_controller_run();
   315 	msr_write_kanal_list();
   316 	msr_write_kanal_list();
   316 	);
   317 	);
   317 #else
   318 #else
   318     msr_controller_run();
   319     msr_controller_run();
   319 #endif
   320 #endif
   320     /* und wieder in die Timerliste eintragen */
   321     /* und wieder in die Timerliste eintragen */
   321     /* und neu in die Taskqueue eintragen */    
   322     /* und neu in die Taskqueue eintragen */
   322 //    timer.expires += 1;
   323 //    timer.expires += 1;
   323 //    add_timer(&timer);
   324 //    add_timer(&timer);
   324 
   325 
   325     ipipe_control_irq(irq,0,IPIPE_ENABLE_MASK);  //nicht weiterreichen
   326     ipipe_control_irq(irq,0,IPIPE_ENABLE_MASK);  //nicht weiterreichen
   326     if(counter++ > HZREDUCTION) {
   327     if(counter++ > HZREDUCTION) {
   380  ****************************************************************************************************/
   381  ****************************************************************************************************/
   381 
   382 
   382 
   383 
   383 int __init init_module()
   384 int __init init_module()
   384 {
   385 {
   385     int result = 0;
       
   386 
       
   387     struct ipipe_domain_attr attr; //ipipe
   386     struct ipipe_domain_attr attr; //ipipe
   388 
   387 
   389     //als allererstes die RT-lib initialisieren    
   388     // Als allererstes die RT-lib initialisieren
   390 #ifdef USE_MSR_LIB
   389 #ifdef USE_MSR_LIB
   391     result = msr_rtlib_init(1,MSR_ABTASTFREQUENZ,10,&msr_globals_register); 
   390     if (msr_rtlib_init(1,MSR_ABTASTFREQUENZ,10,&msr_globals_register) < 0) {
   392 
       
   393     if (result < 0) {
       
   394         msr_print_warn("msr_modul: can't initialize rtlib!");
   391         msr_print_warn("msr_modul: can't initialize rtlib!");
   395         return result;
   392         goto out_return;
   396     }
   393     }
   397 #endif
   394 #endif
   398 
   395 
   399     msr_jitter_init();
   396     msr_jitter_init();
   400   printk(KERN_INFO "=== Starting EtherCAT environment... ===\n");
   397 
   401 
   398     printk(KERN_INFO "=== Starting EtherCAT environment... ===\n");
   402   if ((ecat_master = EtherCAT_request(0)) == NULL)
   399 
   403   {
   400     if ((ecat_master = EtherCAT_request(0)) == NULL) {
   404     printk(KERN_ERR "EtherCAT master 0 not available!\n");
   401         printk(KERN_ERR "EtherCAT master 0 not available!\n");
   405     msr_rtlib_cleanup();    
   402         goto out_msr_cleanup;
   406     return -1;
   403     }
   407   }
   404 
   408 
   405     printk("Checking EtherCAT slaves.\n");
   409   printk("Checking EtherCAT slaves.\n");
   406 
   410 
   407     if (EtherCAT_check_slaves(ecat_master, ecat_slaves, ECAT_SLAVES_COUNT) != 0) {
   411   if (EtherCAT_check_slaves(ecat_master, ecat_slaves, ECAT_SLAVES_COUNT) != 0)
   408         printk(KERN_ERR "EtherCAT: Could not init slaves!\n");
   412   {
   409         goto out_release_master;
   413     printk(KERN_ERR "EtherCAT: Could not init slaves!\n");
   410     }
   414     msr_rtlib_cleanup();    
   411 
   415     return -1;
   412     printk("Activating all EtherCAT slaves.\n");
   416   }
   413 
   417 
   414     if (EtherCAT_activate_all_slaves(ecat_master) != 0) {
   418   printk("Activating all EtherCAT slaves.\n");
   415         printk(KERN_ERR "EtherCAT: Could not activate slaves!\n");
   419 
   416         goto out_release_master;
   420   if (EtherCAT_activate_all_slaves(ecat_master) != 0)
   417     }
   421   {
   418 
   422     printk(KERN_ERR "EtherCAT: Could not activate slaves!\n");
   419     do_gettimeofday(&process_time);
   423     msr_rtlib_cleanup();    
   420     msr_time_increment.tv_sec=0;
   424     return -1;
   421     msr_time_increment.tv_usec=(unsigned int)(1000000/MSR_ABTASTFREQUENZ);
   425   }
       
   426 
       
   427 
       
   428   do_gettimeofday(&process_time);			       
       
   429   msr_time_increment.tv_sec=0;
       
   430   msr_time_increment.tv_usec=(unsigned int)(1000000/MSR_ABTASTFREQUENZ);
       
   431 
   422 
   432     ipipe_init_attr (&attr);
   423     ipipe_init_attr (&attr);
   433     attr.name     = "IPIPE-MSR-MODULE";
   424     attr.name     = "IPIPE-MSR-MODULE";
   434     attr.priority = IPIPE_ROOT_PRIO + 1;
   425     attr.priority = IPIPE_ROOT_PRIO + 1;
   435     attr.entry    = &domain_entry;
   426     attr.entry    = &domain_entry;
   436     ipipe_register_domain(&this_domain,&attr);
   427     ipipe_register_domain(&this_domain,&attr);
   437 
   428 
   438     //den Timertakt
   429     return 0;
   439 /*
   430 
   440   init_timer(&timer);
   431  out_release_master:
   441 
   432     EtherCAT_release(ecat_master);
   442   timer.function = msr_run;
   433 
   443   timer.data = 0;
   434  out_msr_cleanup:
   444   timer.expires = jiffies+10; // Das erste Mal sofort feuern
   435     msr_rtlib_cleanup();
   445   add_timer(&timer);
   436 
   446 */
   437  out_return:
   447   return 0; /* succeed */
   438     return -1;
   448 }
   439 }
   449 
   440 
   450 
   441 
   451 //****************************************************************************
   442 //****************************************************************************
   452 void __exit cleanup_module()
   443 void __exit cleanup_module()
   453 
   444 
   454 {
   445 {
   455     msr_print_info("msk_modul: unloading...");
   446     msr_print_info("msk_modul: unloading...");
   456 
   447 
   457 
       
   458 //    del_timer_sync(&timer);
       
   459     ipipe_tune_timer(1000000000UL/HZ,0); //alten Timertakt wieder herstellen
   448     ipipe_tune_timer(1000000000UL/HZ,0); //alten Timertakt wieder herstellen
   460 
       
   461     ipipe_unregister_domain(&this_domain);
   449     ipipe_unregister_domain(&this_domain);
   462 
       
   463 
       
   464 
   450 
   465     printk(KERN_INFO "=== Stopping EtherCAT environment... ===\n");
   451     printk(KERN_INFO "=== Stopping EtherCAT environment... ===\n");
   466 
   452 
   467     if (ecat_master)
   453     if (ecat_master)
   468     {
   454     {
   469       EtherCAT_clear_process_data(ecat_master);
   455         EtherCAT_clear_process_data(ecat_master);
   470       printk(KERN_INFO "Deactivating slaves.\n");
   456         printk(KERN_INFO "Deactivating slaves.\n");
   471       EtherCAT_deactivate_all_slaves(ecat_master);
   457         EtherCAT_deactivate_all_slaves(ecat_master);
   472 
   458         EtherCAT_release(ecat_master);
   473       EtherCAT_release(ecat_master);
       
   474     }
   459     }
   475 
   460 
   476     printk(KERN_INFO "=== EtherCAT environment stopped. ===\n");
   461     printk(KERN_INFO "=== EtherCAT environment stopped. ===\n");
   477 
   462 
   478 //    msr_controller_cleanup(); 
   463 #ifdef USE_MSR_LIB
   479 #ifdef USE_MSR_LIB
   464     msr_rtlib_cleanup();
   480     msr_rtlib_cleanup();    
       
   481 #endif
   465 #endif
   482 }
   466 }
   483 
   467 
   484 MODULE_LICENSE("GPL");
   468 MODULE_LICENSE("GPL");
   485 MODULE_AUTHOR ("Wilhelm Hagemeister <hm@igh-essen.com>");
   469 MODULE_AUTHOR ("Wilhelm Hagemeister <hm@igh-essen.com>");
   486 MODULE_DESCRIPTION ("EtherCAT test environment");
   470 MODULE_DESCRIPTION ("EtherCAT test environment");
   487 
   471 
   488 module_init(init_module);
   472 module_init(init_module);
   489 module_exit(cleanup_module);
   473 module_exit(cleanup_module);
   490  
   474 
   491 
   475 
   492 
   476 
   493 
   477 
   494 
   478 
   495 
   479 
   496 
   480 
   497 
   481 
   498 
   482 
   499 
   483 
   500 
   484 
   501 
   485 
   502 
   486 
   503 
   487 
   504 
   488 
   505 
   489