equal
deleted
inserted
replaced
26 *****************************************************************************/ |
26 *****************************************************************************/ |
27 |
27 |
28 #include <linux/module.h> |
28 #include <linux/module.h> |
29 #include <linux/delay.h> |
29 #include <linux/delay.h> |
30 #include <linux/timer.h> |
30 #include <linux/timer.h> |
|
31 #include <linux/spinlock.h> |
|
32 #include <linux/interrupt.h> |
31 |
33 |
32 #include "../include/ecrt.h" // EtherCAT realtime interface |
34 #include "../include/ecrt.h" // EtherCAT realtime interface |
33 |
35 |
34 #define ASYNC |
36 #define ASYNC |
35 #define FREQUENCY 100 |
37 #define FREQUENCY 100 |
39 struct timer_list timer; |
41 struct timer_list timer; |
40 |
42 |
41 // EtherCAT |
43 // EtherCAT |
42 ec_master_t *master = NULL; |
44 ec_master_t *master = NULL; |
43 ec_domain_t *domain1 = NULL; |
45 ec_domain_t *domain1 = NULL; |
|
46 spinlock_t master_lock = SPIN_LOCK_UNLOCKED; |
44 |
47 |
45 // data fields |
48 // data fields |
46 //void *r_ssi_input, *r_ssi_status, *r_4102[3]; |
49 //void *r_ssi_input, *r_ssi_status, *r_4102[3]; |
47 |
50 |
48 // channels |
51 // channels |
58 /*****************************************************************************/ |
61 /*****************************************************************************/ |
59 |
62 |
60 void run(unsigned long data) |
63 void run(unsigned long data) |
61 { |
64 { |
62 static unsigned int counter = 0; |
65 static unsigned int counter = 0; |
|
66 |
|
67 spin_lock(&master_lock); |
63 |
68 |
64 #ifdef ASYNC |
69 #ifdef ASYNC |
65 // receive |
70 // receive |
66 ecrt_master_async_receive(master); |
71 ecrt_master_async_receive(master); |
67 ecrt_domain_process(domain1); |
72 ecrt_domain_process(domain1); |
81 ecrt_domain_queue(domain1); |
86 ecrt_domain_queue(domain1); |
82 ecrt_master_run(master); |
87 ecrt_master_run(master); |
83 ecrt_master_async_send(master); |
88 ecrt_master_async_send(master); |
84 #endif |
89 #endif |
85 |
90 |
|
91 spin_unlock(&master_lock); |
|
92 |
86 if (counter) { |
93 if (counter) { |
87 counter--; |
94 counter--; |
88 } |
95 } |
89 else { |
96 else { |
90 counter = FREQUENCY; |
97 counter = FREQUENCY; |
99 |
106 |
100 /*****************************************************************************/ |
107 /*****************************************************************************/ |
101 |
108 |
102 int request_lock(void *data) |
109 int request_lock(void *data) |
103 { |
110 { |
104 return 0; |
111 unsigned int tries = 0; |
|
112 while (1) { |
|
113 if (spin_trylock(&master_lock)) { |
|
114 if (tries) printk(KERN_INFO "lock: %i tries needed.\n", tries); |
|
115 return 1; |
|
116 } |
|
117 tries++; |
|
118 } |
105 } |
119 } |
106 |
120 |
107 /*****************************************************************************/ |
121 /*****************************************************************************/ |
108 |
122 |
109 void release_lock(void *data) |
123 void release_lock(void *data) |
110 { |
124 { |
|
125 spin_unlock(&master_lock); |
111 } |
126 } |
112 |
127 |
113 /*****************************************************************************/ |
128 /*****************************************************************************/ |
114 |
129 |
115 int __init init_mini_module(void) |
130 int __init init_mini_module(void) |
148 goto out_deactivate; |
163 goto out_deactivate; |
149 } |
164 } |
150 ecrt_master_print(master, 2); |
165 ecrt_master_print(master, 2); |
151 #else |
166 #else |
152 ecrt_master_print(master, 0); |
167 ecrt_master_print(master, 0); |
153 #endif |
|
154 |
|
155 #if 1 |
|
156 if (ecrt_master_start_eoe(master)) { |
|
157 printk(KERN_ERR "Failed to start EoE processing!\n"); |
|
158 goto out_deactivate; |
|
159 } |
|
160 #endif |
168 #endif |
161 |
169 |
162 #if 0 |
170 #if 0 |
163 if (!(slave = ecrt_master_get_slave(master, "5"))) { |
171 if (!(slave = ecrt_master_get_slave(master, "5"))) { |
164 printk(KERN_ERR "Failed to get slave 5!\n"); |
172 printk(KERN_ERR "Failed to get slave 5!\n"); |
190 #ifdef ASYNC |
198 #ifdef ASYNC |
191 // send once and wait... |
199 // send once and wait... |
192 ecrt_master_prepare_async_io(master); |
200 ecrt_master_prepare_async_io(master); |
193 #endif |
201 #endif |
194 |
202 |
|
203 #if 1 |
|
204 if (ecrt_master_start_eoe(master)) { |
|
205 printk(KERN_ERR "Failed to start EoE processing!\n"); |
|
206 goto out_deactivate; |
|
207 } |
|
208 #endif |
|
209 |
195 printk("Starting cyclic sample thread.\n"); |
210 printk("Starting cyclic sample thread.\n"); |
196 init_timer(&timer); |
211 init_timer(&timer); |
197 timer.function = run; |
212 timer.function = run; |
198 timer.expires = jiffies + 10; |
213 timer.expires = jiffies + 10; |
199 add_timer(&timer); |
214 add_timer(&timer); |