fp@42: /****************************************************************************** fp@42: * fp@42: * msr_module.c fp@42: * fp@42: * Kernelmodul für 2.6 Kernel zur Meßdatenerfassung, Steuerung und Regelung. fp@47: * fp@47: * Autor: Wilhelm Hagemeister, Florian Pose fp@42: * fp@42: * (C) Copyright IgH 2002 fp@42: * Ingenieurgemeinschaft IgH fp@42: * Heinz-Bäcker Str. 34 fp@42: * D-45356 Essen fp@42: * Tel.: +49 201/61 99 31 fp@42: * Fax.: +49 201/61 98 36 fp@42: * E-mail: hm@igh-essen.com fp@42: * fp@42: * $Id$ fp@42: * fp@42: *****************************************************************************/ hm@28: fp@45: // Linux hm@28: #include hm@28: #include fp@73: #include fp@73: #include hm@28: fp@45: // RT_lib fp@45: #include fp@45: #include fp@45: #include fp@45: #include hm@28: #include fp@73: #include fp@45: #include "msr_param.h" fp@45: fp@45: // EtherCAT fp@54: #include "../include/EtherCAT_rt.h" fp@59: #include "../include/EtherCAT_si.h" hm@28: fp@45: // Defines/Makros fp@47: #define HZREDUCTION (MSR_ABTASTFREQUENZ / HZ) hm@28: fp@45: /*****************************************************************************/ fp@45: /* Globale Variablen */ fp@45: fp@45: // Adeos hm@28: static struct ipipe_domain this_domain; hm@28: static struct ipipe_sysinfo sys_info; hm@28: fp@45: // EtherCAT fp@54: ec_master_t *master = NULL; fp@73: ec_domain_t *domain1 = NULL; fp@73: fp@73: // Prozessdaten fp@82: void *r_ssi; fp@82: void *r_inc; fp@82: fp@82: uint32_t k_angle; fp@82: uint32_t k_pos; fp@73: fp@73: ec_field_init_t domain1_fields[] = { fp@83: {&r_ssi, "1", "Beckhoff", "EL5001", ec_ipvalue, 0, 1}, fp@83: {&r_inc, "0:3", "Beckhoff", "EL5101", ec_ipvalue, 0, 1}, fp@73: {} fp@61: }; fp@61: fp@73: /*****************************************************************************/ hm@28: hm@28: static void msr_controller_run(void) hm@28: { fp@68: // Prozessdaten lesen und schreiben fp@73: EtherCAT_rt_domain_xio(domain1); fp@73: fp@82: k_angle = EC_READ_U16(r_inc); fp@82: k_pos = EC_READ_U32(r_ssi); fp@82: } fp@82: fp@82: /*****************************************************************************/ fp@82: fp@82: int msr_globals_register(void) fp@82: { fp@82: msr_reg_kanal("/angle0", "", &k_angle, TUINT); fp@82: msr_reg_kanal("/pos0", "", &k_pos, TUINT); fp@82: fp@82: return 0; fp@73: } fp@73: fp@73: /*****************************************************************************/ hm@28: hm@28: void msr_run(unsigned irq) hm@28: { fp@45: static int counter = 0; fp@45: fp@45: MSR_ADEOS_INTERRUPT_CODE(msr_controller_run(); msr_write_kanal_list();); hm@28: fp@73: ipipe_control_irq(irq, 0, IPIPE_ENABLE_MASK); // Interrupt bestŽätigen fp@73: if (++counter >= HZREDUCTION) { fp@73: ipipe_propagate_irq(irq); // und weiterreichen hm@28: counter = 0; hm@28: } fp@42: } fp@42: fp@45: /*****************************************************************************/ fp@45: fp@45: void domain_entry(void) fp@42: { fp@42: printk("Domain %s started.\n", ipipe_current_domain->name); hm@28: hm@28: ipipe_get_sysinfo(&sys_info); hm@28: ipipe_virtualize_irq(ipipe_current_domain,sys_info.archdep.tmirq, hm@28: &msr_run, NULL, IPIPE_HANDLE_MASK); hm@28: fp@68: ipipe_tune_timer(1000000000UL / MSR_ABTASTFREQUENZ, 0); fp@42: } fp@42: fp@73: /*****************************************************************************/ hm@28: fp@54: int __init init_rt_module(void) fp@54: { hm@28: struct ipipe_domain_attr attr; //ipipe fp@73: const ec_field_init_t *field; fp@80: uint32_t version; hm@28: fp@36: // Als allererstes die RT-lib initialisieren fp@73: if (msr_rtlib_init(1, MSR_ABTASTFREQUENZ, 10, &msr_globals_register) < 0) { hm@28: msr_print_warn("msr_modul: can't initialize rtlib!"); fp@36: goto out_return; hm@28: } hm@28: fp@54: if ((master = EtherCAT_rt_request_master(0)) == NULL) { fp@55: printk(KERN_ERR "Error requesting master 0!\n"); fp@36: goto out_msr_cleanup; fp@36: } fp@36: fp@73: EtherCAT_rt_master_print(master); fp@73: fp@73: printk(KERN_INFO "Registering domain...\n"); fp@73: fp@73: if (!(domain1 = EtherCAT_rt_master_register_domain(master, ec_sync, 100))) fp@73: { fp@73: printk(KERN_ERR "EtherCAT: Could not register domain!\n"); fp@73: goto out_release_master; fp@73: } fp@73: fp@73: printk(KERN_INFO "Registering domain fields...\n"); fp@73: fp@73: for (field = domain1_fields; field->data; field++) fp@73: { fp@73: if (!EtherCAT_rt_register_slave_field(domain1, fp@73: field->address, fp@73: field->vendor, fp@73: field->product, fp@73: field->data, fp@73: field->field_type, fp@73: field->field_index, fp@73: field->field_count)) { fp@80: printk(KERN_ERR "Could not register field!\n"); fp@73: goto out_release_master; fp@73: } fp@73: } fp@73: fp@73: printk(KERN_INFO "Activating master...\n"); fp@73: fp@73: if (EtherCAT_rt_master_activate(master)) { fp@80: printk(KERN_ERR "Could not activate master!\n"); fp@73: goto out_release_master; fp@73: } fp@73: fp@81: #if 1 fp@81: if (EtherCAT_rt_canopen_sdo_addr_read(master, "1", 0x100A, 1, fp@80: &version)) { fp@80: printk(KERN_ERR "Could not read SSI version!\n"); fp@68: goto out_release_master; fp@68: } fp@83: printk(KERN_INFO "Software-version: %u\n", version); fp@81: #endif fp@61: fp@61: ipipe_init_attr(&attr); fp@61: attr.name = "IPIPE-MSR-MODULE"; hm@28: attr.priority = IPIPE_ROOT_PRIO + 1; fp@61: attr.entry = &domain_entry; fp@61: ipipe_register_domain(&this_domain, &attr); hm@28: fp@36: return 0; fp@36: fp@36: out_release_master: fp@54: EtherCAT_rt_release_master(master); fp@36: fp@36: out_msr_cleanup: fp@36: msr_rtlib_cleanup(); fp@36: fp@36: out_return: fp@36: return -1; hm@28: } hm@28: fp@42: /*****************************************************************************/ fp@42: fp@54: void __exit cleanup_rt_module(void) fp@54: { hm@28: msr_print_info("msk_modul: unloading..."); hm@28: fp@45: ipipe_tune_timer(1000000000UL / HZ, 0); //alten Timertakt wieder herstellen hm@28: ipipe_unregister_domain(&this_domain); hm@28: fp@54: if (master) hm@28: { fp@43: printk(KERN_INFO "=== Stopping EtherCAT environment... ===\n"); fp@43: fp@73: printk(KERN_INFO "Deactivating master...\n"); fp@73: fp@73: if (EtherCAT_rt_master_deactivate(master) < 0) { fp@73: printk(KERN_WARNING "Warning - Could not deactivate master!\n"); fp@42: } fp@42: fp@54: EtherCAT_rt_release_master(master); fp@43: fp@43: printk(KERN_INFO "=== EtherCAT environment stopped. ===\n"); fp@43: } hm@28: fp@36: msr_rtlib_cleanup(); hm@28: } hm@28: fp@42: /*****************************************************************************/ fp@42: hm@28: MODULE_LICENSE("GPL"); fp@73: MODULE_AUTHOR ("Florian Pose "); fp@73: MODULE_DESCRIPTION ("EtherCAT real-time test environment"); hm@28: fp@54: module_init(init_rt_module); fp@54: module_exit(cleanup_rt_module); fp@54: fp@54: /*****************************************************************************/ fp@55: fp@55: /* Emacs-Konfiguration fp@55: ;;; Local Variables: *** fp@55: ;;; c-basic-offset:4 *** fp@55: ;;; End: *** fp@55: */