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@54: ec_master_t *master = NULL; fp@64: ec_slave_t *s_in, *s_out, *s_ssi; fp@22: fp@22: struct timer_list timer; fp@22: fp@61: ec_slave_init_t slaves[] = { fp@61: // Zeiger, Index, Herstellername, Produktname, Domäne fp@64: { &s_out, 2, "Beckhoff", "EL2004", 1 }, fp@64: { &s_in, 1, "Beckhoff", "EL3102", 1 }, fp@64: { &s_ssi, 7, "Beckhoff", "EL5001", 1 } fp@61: }; fp@0: fp@61: #define SLAVE_COUNT (sizeof(slaves) / sizeof(ec_slave_init_t)) fp@22: fp@60: /*****************************************************************************/ fp@60: fp@60: void run(unsigned long data) fp@5: { fp@62: // Klemmen-IO fp@60: EC_WRITE_EL20XX(s_out, 3, EC_READ_EL31XX(s_in, 0) < 0); fp@42: fp@42: // Prozessdaten lesen und schreiben fp@57: EtherCAT_rt_domain_xio(master, 1, 100); fp@22: fp@62: // Timer neu starten fp@24: timer.expires += HZ / 1000; fp@22: add_timer(&timer); fp@0: } fp@22: fp@60: /*****************************************************************************/ fp@22: fp@54: int __init init_mini_module(void) fp@5: { fp@36: printk(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n"); fp@36: fp@54: if ((master = EtherCAT_rt_request_master(0)) == NULL) { fp@36: printk(KERN_ERR "EtherCAT master 0 not available!\n"); fp@36: goto out_return; fp@36: } fp@36: fp@61: if (EtherCAT_rt_register_slave_list(master, slaves, SLAVE_COUNT)) { fp@60: printk(KERN_ERR "Could not register slaves!\n"); fp@60: goto out_release_master; fp@60: } fp@36: fp@36: printk("Activating all EtherCAT slaves.\n"); fp@36: fp@61: if (EtherCAT_rt_activate_slaves(master)) { fp@54: printk(KERN_ERR "EtherCAT: Could not activate slaves!\n"); fp@54: goto out_release_master; fp@36: } fp@36: fp@64: printk("Configuring EtherCAT slaves.\n"); fp@64: fp@64: EtherCAT_rt_debug_level(master, 2); fp@64: fp@64: if (EtherCAT_rt_canopen_sdo_write(master, s_ssi, 0x4067, 2, 2)) { fp@64: printk(KERN_ERR "EtherCAT: Could not set SSI baud rate!\n"); fp@64: goto out_release_master; fp@64: } fp@64: fp@64: EtherCAT_rt_debug_level(master, 0); fp@64: fp@36: printk("Starting cyclic sample thread.\n"); fp@36: fp@36: init_timer(&timer); fp@36: 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@36: printk(KERN_INFO "Deactivating slaves.\n"); fp@42: fp@54: EtherCAT_rt_deactivate_slaves(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@0: MODULE_DESCRIPTION ("Minimal EtherCAT 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: */