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@60: ec_slave_t *s_in, *s_out; fp@22: fp@24: int value; fp@0: int dig1; fp@22: fp@22: struct timer_list timer; fp@22: unsigned long last_start_jiffies; fp@22: fp@61: ec_slave_init_t slaves[] = { fp@61: // Zeiger, Index, Herstellername, Produktname, Domäne fp@61: { &s_out, 9, "Beckhoff", "EL2004", 1 }, fp@61: { &s_in, 1, "Beckhoff", "EL3102", 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@60: static int ms = 0; fp@22: static unsigned long int k = 0; fp@22: static int firstrun = 1; fp@22: fp@22: ms++; fp@22: ms %= 1000; fp@0: fp@60: EC_WRITE_EL20XX(s_out, 3, EC_READ_EL31XX(s_in, 0) < 0); fp@42: fp@42: // Prozessdaten lesen und schreiben fp@22: rdtscl(k); fp@57: EtherCAT_rt_domain_xio(master, 1, 100); fp@22: firstrun = 0; fp@22: 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: //EtherCAT_rt_debug_level(master, 2); fp@61: 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@36: printk("Starting cyclic sample thread.\n"); fp@36: fp@36: init_timer(&timer); fp@36: fp@36: timer.function = run; fp@36: timer.data = 0; fp@60: timer.expires = jiffies + 10; // Das erste Mal sofort feuern fp@36: last_start_jiffies = timer.expires; fp@36: add_timer(&timer); fp@36: fp@36: printk("Initialised sample thread.\n"); 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: */