11 #include <linux/module.h> |
11 #include <linux/module.h> |
12 #include <linux/delay.h> |
12 #include <linux/delay.h> |
13 #include <linux/timer.h> |
13 #include <linux/timer.h> |
14 |
14 |
15 #include "../include/EtherCAT_rt.h" |
15 #include "../include/EtherCAT_rt.h" |
16 |
16 #include "../include/EtherCAT_si.h" |
17 /*****************************************************************************/ |
|
18 |
|
19 // Auskommentieren, wenn keine zyklischen Daten erwuenscht |
|
20 #define ECAT_CYCLIC_DATA |
|
21 |
17 |
22 /*****************************************************************************/ |
18 /*****************************************************************************/ |
23 |
19 |
24 ec_master_t *master = NULL; |
20 ec_master_t *master = NULL; |
25 |
21 ec_slave_t *s_in, *s_out; |
26 #ifdef ECAT_CYCLIC_DATA |
|
27 |
22 |
28 int value; |
23 int value; |
29 int dig1; |
24 int dig1; |
30 |
25 |
31 struct timer_list timer; |
26 struct timer_list timer; |
32 unsigned long last_start_jiffies; |
27 unsigned long last_start_jiffies; |
33 |
28 |
34 #endif // ECAT_CYCLIC_DATA |
29 /*****************************************************************************/ |
35 |
30 |
36 /****************************************************************************** |
31 int __init check_slaves(void) |
37 * |
32 { |
38 * Function: run |
33 s_in = EtherCAT_rt_register_slave(master, 1, "Beckhoff", "EL3102", 1); |
39 * |
34 s_out = EtherCAT_rt_register_slave(master, 9, "Beckhoff", "EL2004", 1); |
40 * Beschreibung: Zyklischer Prozess |
|
41 * |
|
42 *****************************************************************************/ |
|
43 |
35 |
44 #ifdef ECAT_CYCLIC_DATA |
36 return s_in && s_out; |
|
37 } |
45 |
38 |
46 static void run(unsigned long data) |
39 /*****************************************************************************/ |
|
40 |
|
41 void run(unsigned long data) |
47 { |
42 { |
48 static int ms = 0; |
43 static int ms = 0; |
49 static unsigned long int k = 0; |
44 static unsigned long int k = 0; |
50 static int firstrun = 1; |
45 static int firstrun = 1; |
51 |
46 |
52 ms++; |
47 ms++; |
53 ms %= 1000; |
48 ms %= 1000; |
54 |
49 |
55 #if 0 |
50 EC_WRITE_EL20XX(s_out, 3, EC_READ_EL31XX(s_in, 0) < 0); |
56 if (klemme >= 0) |
|
57 EtherCAT_write_value(&ecat_slaves[klemme], kanal, up_down); |
|
58 #endif |
|
59 |
51 |
60 // Prozessdaten lesen und schreiben |
52 // Prozessdaten lesen und schreiben |
61 rdtscl(k); |
53 rdtscl(k); |
62 EtherCAT_rt_domain_xio(master, 1, 100); |
54 EtherCAT_rt_domain_xio(master, 1, 100); |
63 firstrun = 0; |
55 firstrun = 0; |
64 |
56 |
65 timer.expires += HZ / 1000; |
57 timer.expires += HZ / 1000; |
66 add_timer(&timer); |
58 add_timer(&timer); |
67 } |
59 } |
68 |
60 |
69 #endif // ECAT_CYCLIC_DATA |
61 /*****************************************************************************/ |
70 |
|
71 /****************************************************************************** |
|
72 * |
|
73 * Function: init |
|
74 * |
|
75 *****************************************************************************/ |
|
76 |
62 |
77 int __init init_mini_module(void) |
63 int __init init_mini_module(void) |
78 { |
64 { |
79 printk(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n"); |
65 printk(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n"); |
80 |
66 |
81 if ((master = EtherCAT_rt_request_master(0)) == NULL) { |
67 if ((master = EtherCAT_rt_request_master(0)) == NULL) { |
82 printk(KERN_ERR "EtherCAT master 0 not available!\n"); |
68 printk(KERN_ERR "EtherCAT master 0 not available!\n"); |
83 goto out_return; |
69 goto out_return; |
84 } |
70 } |
85 |
71 |
86 //check_slaves(); |
72 if (!check_slaves()) { |
|
73 printk(KERN_ERR "Could not register slaves!\n"); |
|
74 goto out_release_master; |
|
75 } |
87 |
76 |
88 printk("Activating all EtherCAT slaves.\n"); |
77 printk("Activating all EtherCAT slaves.\n"); |
89 |
78 |
90 if (EtherCAT_rt_activate_slaves(master) != 0) { |
79 if (EtherCAT_rt_activate_slaves(master) != 0) { |
91 printk(KERN_ERR "EtherCAT: Could not activate slaves!\n"); |
80 printk(KERN_ERR "EtherCAT: Could not activate slaves!\n"); |
92 goto out_release_master; |
81 goto out_release_master; |
93 } |
82 } |
94 |
83 |
95 #ifdef ECAT_CYCLIC_DATA |
|
96 printk("Starting cyclic sample thread.\n"); |
84 printk("Starting cyclic sample thread.\n"); |
97 |
85 |
98 init_timer(&timer); |
86 init_timer(&timer); |
99 |
87 |
100 timer.function = run; |
88 timer.function = run; |
101 timer.data = 0; |
89 timer.data = 0; |
102 timer.expires = jiffies+10; // Das erste Mal sofort feuern |
90 timer.expires = jiffies + 10; // Das erste Mal sofort feuern |
103 last_start_jiffies = timer.expires; |
91 last_start_jiffies = timer.expires; |
104 add_timer(&timer); |
92 add_timer(&timer); |
105 |
93 |
106 printk("Initialised sample thread.\n"); |
94 printk("Initialised sample thread.\n"); |
107 #endif |
|
108 |
95 |
109 printk(KERN_INFO "=== Minimal EtherCAT environment started. ===\n"); |
96 printk(KERN_INFO "=== Minimal EtherCAT environment started. ===\n"); |
110 |
97 |
111 return 0; |
98 return 0; |
112 |
99 |