fp@0: /****************************************************************************** fp@0: * fp@54: * m i n i . c fp@0: * fp@0: * Minimalmodul für EtherCAT fp@13: * fp@0: * $Id$ fp@0: * fp@42: *****************************************************************************/ fp@0: fp@0: #include fp@24: #include fp@22: #include fp@0: fp@61: #include "../include/EtherCAT_rt.h" // Echtzeitschnittstelle fp@61: #include "../include/EtherCAT_si.h" // Slave-Interface-Makros fp@5: fp@42: /*****************************************************************************/ fp@5: fp@73: #define ABTASTFREQUENZ 1000 fp@22: fp@22: struct timer_list timer; fp@22: fp@73: /*****************************************************************************/ fp@73: fp@73: // EtherCAT fp@73: ec_master_t *master = NULL; fp@73: ec_domain_t *domain1 = NULL; fp@73: fp@73: // Prozessdaten fp@73: uint8_t *dig_out1; fp@73: uint16_t *ssi_value; fp@73: uint16_t *inc_value; fp@73: fp@73: uint32_t angle0; fp@73: fp@73: ec_field_init_t domain1_fields[] = { fp@73: {(void **) &dig_out1, "2", "Beckhoff", "EL2004", ec_opvalue, 0, 1}, fp@73: {(void **) &ssi_value, "3", "Beckhoff", "EL5001", ec_ipvalue, 0, 1}, fp@73: {(void **) &inc_value, "0:4", "Beckhoff", "EL5101", ec_ipvalue, 0, 1}, fp@73: {} fp@61: }; fp@0: fp@60: /*****************************************************************************/ fp@60: fp@60: void run(unsigned long data) fp@5: { fp@73: static unsigned int counter = 0; fp@68: fp@42: // Prozessdaten lesen und schreiben fp@73: EtherCAT_rt_domain_xio(domain1); fp@73: fp@73: angle0 = (uint32_t) *inc_value; fp@22: fp@68: if (counter) { fp@68: counter--; fp@68: } fp@68: else { fp@73: counter = ABTASTFREQUENZ; fp@73: printk(KERN_INFO "angle0 = %i\n", angle0); fp@68: } fp@68: fp@62: // Timer neu starten fp@73: timer.expires += HZ / ABTASTFREQUENZ; fp@22: add_timer(&timer); fp@0: } fp@22: fp@60: /*****************************************************************************/ fp@22: fp@54: int __init init_mini_module(void) fp@5: { fp@73: const ec_field_init_t *field; fp@73: fp@36: printk(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n"); fp@36: fp@54: if ((master = EtherCAT_rt_request_master(0)) == NULL) { fp@73: printk(KERN_ERR "Error requesting master 0!\n"); fp@36: goto out_return; 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@60: goto out_release_master; fp@60: } fp@36: fp@73: printk(KERN_INFO "Registering domain fields...\n"); fp@36: 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@73: printk(KERN_ERR "EtherCAT: Could not register field!\n"); fp@73: goto out_release_master; fp@73: } fp@36: } fp@36: fp@73: printk(KERN_INFO "Activating master...\n"); fp@64: fp@73: if (EtherCAT_rt_master_activate(master)) { fp@73: printk(KERN_ERR "EtherCAT: Could not activate master!\n"); fp@68: goto out_release_master; fp@68: } fp@64: fp@36: printk("Starting cyclic sample thread.\n"); fp@36: fp@36: init_timer(&timer); fp@36: timer.function = run; fp@60: timer.expires = jiffies + 10; // Das erste Mal sofort feuern fp@36: add_timer(&timer); fp@36: fp@36: printk(KERN_INFO "=== Minimal EtherCAT environment started. ===\n"); fp@36: fp@36: return 0; fp@36: fp@36: out_release_master: fp@54: EtherCAT_rt_release_master(master); fp@36: fp@36: out_return: fp@36: return -1; fp@0: } fp@0: fp@60: /*****************************************************************************/ fp@22: fp@54: void __exit cleanup_mini_module(void) fp@0: { fp@26: printk(KERN_INFO "=== Stopping Minimal EtherCAT environment... ===\n"); fp@0: fp@54: if (master) fp@22: { fp@36: del_timer_sync(&timer); fp@22: fp@73: printk(KERN_INFO "Deactivating master...\n"); fp@42: fp@73: EtherCAT_rt_master_deactivate(master); fp@54: EtherCAT_rt_release_master(master); fp@27: } fp@22: fp@26: printk(KERN_INFO "=== Minimal EtherCAT environment stopped. ===\n"); fp@0: } fp@0: fp@0: /*****************************************************************************/ fp@0: fp@0: MODULE_LICENSE("GPL"); fp@0: MODULE_AUTHOR ("Florian Pose "); fp@73: MODULE_DESCRIPTION ("EtherCAT minimal test environment"); fp@0: fp@54: module_init(init_mini_module); fp@54: module_exit(cleanup_mini_module); fp@0: fp@0: /*****************************************************************************/ fp@42: fp@42: /* Emacs-Konfiguration fp@42: ;;; Local Variables: *** fp@42: ;;; c-basic-offset:4 *** fp@42: ;;; End: *** fp@42: */