author | Florian Pose <fp@igh-essen.com> |
Fri, 11 Nov 2005 10:55:22 +0000 | |
changeset 10 | 67c739ece5d5 |
parent 8 | f2ebe943c686 |
child 11 | e58d78234412 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************** |
2 |
* |
|
3 |
* e c _ m a s t e r . c |
|
4 |
* |
|
5 |
* Methoden für einen EtherCAT-Master. |
|
6 |
* |
|
7 |
* $Date$ |
|
8 |
* $Author$ |
|
9 |
* |
|
10 |
***************************************************************/ |
|
11 |
||
12 |
#include <linux/kernel.h> |
|
13 |
#include <linux/string.h> |
|
14 |
#include <linux/slab.h> |
|
15 |
#include <linux/delay.h> |
|
16 |
||
17 |
#include "ec_globals.h" |
|
18 |
#include "ec_master.h" |
|
19 |
#include "ec_dbg.h" |
|
20 |
||
21 |
/***************************************************************/ |
|
22 |
||
23 |
/** |
|
24 |
Konstruktor des EtherCAT-Masters. |
|
25 |
||
26 |
@param master Zeiger auf den zu initialisierenden |
|
27 |
EtherCAT-Master |
|
28 |
@param dev Zeiger auf das EtherCAT-gerät, mit dem der |
|
29 |
Master arbeiten soll |
|
30 |
||
31 |
@return 0 bei Erfolg, sonst < 0 (= dev ist NULL) |
|
32 |
*/ |
|
33 |
||
34 |
int EtherCAT_master_init(EtherCAT_master_t *master, |
|
35 |
EtherCAT_device_t *dev) |
|
36 |
{ |
|
37 |
unsigned int i; |
|
38 |
||
39 |
if (!dev) |
|
40 |
{ |
|
41 |
EC_DBG(KERN_ERR "EtherCAT: Master init without device!\n"); |
|
42 |
return -1; |
|
43 |
} |
|
44 |
||
45 |
master->slaves = NULL; |
|
46 |
master->slave_count = 0; |
|
47 |
master->first_command = NULL; |
|
48 |
master->process_data_command = NULL; |
|
49 |
master->dev = dev; |
|
50 |
master->command_index = 0x00; |
|
51 |
master->tx_data_length = 0; |
|
52 |
master->process_data = NULL; |
|
53 |
master->process_data_length = 0; |
|
54 |
master->cmd_ring_index = 0; |
|
2
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
55 |
master->debug_level = 0; |
0 | 56 |
|
57 |
for (i = 0; i < ECAT_COMMAND_RING_SIZE; i++) |
|
58 |
{ |
|
59 |
EtherCAT_command_init(&master->cmd_ring[i]); |
|
2
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
60 |
master->cmd_reserved[i] = 0; |
0 | 61 |
} |
62 |
||
63 |
return 0; |
|
64 |
} |
|
65 |
||
66 |
/***************************************************************/ |
|
67 |
||
68 |
/** |
|
69 |
Destruktor eines EtherCAT-Masters. |
|
70 |
||
71 |
Entfernt alle Kommandos aus der Liste, löscht den Zeiger |
|
72 |
auf das Slave-Array und gibt die Prozessdaten frei. |
|
73 |
||
74 |
@param master Zeiger auf den zu löschenden Master |
|
75 |
*/ |
|
76 |
||
77 |
void EtherCAT_master_clear(EtherCAT_master_t *master) |
|
78 |
{ |
|
79 |
// Remove all pending commands |
|
80 |
while (master->first_command) |
|
81 |
{ |
|
82 |
EtherCAT_remove_command(master, master->first_command); |
|
83 |
} |
|
84 |
||
85 |
// Remove all slaves |
|
86 |
EtherCAT_clear_slaves(master); |
|
87 |
||
88 |
if (master->process_data) |
|
89 |
{ |
|
90 |
kfree(master->process_data); |
|
91 |
master->process_data = NULL; |
|
92 |
} |
|
93 |
||
94 |
master->process_data_length = 0; |
|
95 |
} |
|
96 |
||
97 |
/***************************************************************/ |
|
98 |
||
99 |
/** |
|
100 |
Überprüft die angeschlossenen Slaves. |
|
101 |
||
102 |
Vergleicht die an den Bus angeschlossenen Slaves mit |
|
103 |
den im statischen-Slave-Array vorgegebenen Konfigurationen. |
|
104 |
Stimmen Anzahl oder Typen nicht überein, gibt diese |
|
105 |
Methode einen Fehler aus. |
|
106 |
||
107 |
@param master Der EtherCAT-Master |
|
108 |
@param slaves Zeiger auf ein statisches Slave-Array |
|
109 |
@param slave_count Anzahl der Slaves im Array |
|
110 |
||
111 |
@return 0 bei Erfolg, sonst < 0 |
|
112 |
*/ |
|
113 |
||
114 |
int EtherCAT_check_slaves(EtherCAT_master_t *master, |
|
115 |
EtherCAT_slave_t *slaves, |
|
116 |
unsigned int slave_count) |
|
117 |
{ |
|
118 |
EtherCAT_command_t *cmd; |
|
119 |
EtherCAT_slave_t *cur; |
|
120 |
unsigned int i, j, found, length, pos; |
|
121 |
unsigned char data[2]; |
|
122 |
||
123 |
// EtherCAT_clear_slaves() must be called before! |
|
124 |
if (master->slaves || master->slave_count) |
|
125 |
{ |
|
126 |
EC_DBG(KERN_ERR "EtherCAT duplicate slave check!"); |
|
127 |
return -1; |
|
128 |
} |
|
129 |
||
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
130 |
// No slaves. |
0 | 131 |
if (slave_count == 0) |
132 |
{ |
|
133 |
EC_DBG(KERN_ERR "EtherCAT: No slaves in list!"); |
|
134 |
return -1; |
|
135 |
} |
|
136 |
||
137 |
// Determine number of slaves on bus |
|
138 |
||
139 |
if ((cmd = EtherCAT_broadcast_read(master, 0x0000, 4)) == NULL) |
|
140 |
{ |
|
141 |
return -1; |
|
142 |
} |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
143 |
|
0 | 144 |
if (EtherCAT_async_send_receive(master) != 0) |
145 |
{ |
|
146 |
return -1; |
|
147 |
} |
|
148 |
||
149 |
if (cmd->working_counter != slave_count) |
|
150 |
{ |
|
151 |
EC_DBG(KERN_ERR "EtherCAT: Wrong number of slaves on bus: %i / %i\n", |
|
152 |
cmd->working_counter, slave_count); |
|
153 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
154 |
|
0 | 155 |
return -1; |
156 |
} |
|
157 |
else |
|
158 |
{ |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
159 |
EC_DBG("EtherCAT: Found all %i slaves.\n", slave_count); |
0 | 160 |
} |
161 |
||
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
162 |
EtherCAT_remove_command(master, cmd); |
0 | 163 |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
164 |
// For every slave in the list |
0 | 165 |
for (i = 0; i < slave_count; i++) |
166 |
{ |
|
167 |
cur = &slaves[i]; |
|
168 |
||
169 |
if (!cur->desc) |
|
170 |
{ |
|
171 |
EC_DBG(KERN_ERR "EtherCAT: Slave %i has no description.\n", i); |
|
172 |
return -1; |
|
173 |
} |
|
174 |
||
175 |
// Set ring position |
|
176 |
cur->ring_position = -i; |
|
177 |
cur->station_address = i + 1; |
|
178 |
||
179 |
// Write station address |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
180 |
|
0 | 181 |
data[0] = cur->station_address & 0x00FF; |
182 |
data[1] = (cur->station_address & 0xFF00) >> 8; |
|
183 |
||
184 |
if ((cmd = EtherCAT_position_write(master, cur->ring_position, 0x0010, 2, data)) == NULL) |
|
185 |
{ |
|
186 |
return -1; |
|
187 |
} |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
188 |
|
0 | 189 |
if (EtherCAT_async_send_receive(master) != 0) |
190 |
{ |
|
191 |
return -1; |
|
192 |
} |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
193 |
|
0 | 194 |
if (cmd->working_counter != 1) |
195 |
{ |
|
196 |
EC_DBG(KERN_ERR "EtherCAT: Slave %i did not repond while writing station address!\n", i); |
|
197 |
return -1; |
|
198 |
} |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
199 |
|
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
200 |
EtherCAT_remove_command(master, cmd); |
0 | 201 |
|
202 |
// Read base data |
|
203 |
||
204 |
if ((cmd = EtherCAT_read(master, cur->station_address, 0x0000, 4)) == NULL) |
|
205 |
{ |
|
206 |
EC_DBG(KERN_ERR "EtherCAT: Could not create command!\n"); |
|
207 |
return -1; |
|
208 |
} |
|
209 |
||
210 |
if (EtherCAT_async_send_receive(master) != 0) |
|
211 |
{ |
|
212 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
213 |
|
0 | 214 |
EC_DBG(KERN_ERR "EtherCAT: Could not send command!\n"); |
215 |
return -1; |
|
216 |
} |
|
217 |
||
218 |
if (cmd->working_counter != 1) |
|
219 |
{ |
|
220 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
221 |
|
0 | 222 |
EC_DBG(KERN_ERR "EtherCAT: Slave %i did not respond while reading base data!\n", i); |
223 |
return -1; |
|
224 |
} |
|
225 |
||
226 |
// Get base data |
|
227 |
cur->type = cmd->data[0]; |
|
228 |
cur->revision = cmd->data[1]; |
|
229 |
cur->build = cmd->data[2] | (cmd->data[3] << 8); |
|
230 |
||
231 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
232 |
|
0 | 233 |
// Read identification from "Slave Information Interface" (SII) |
234 |
||
235 |
if (EtherCAT_read_slave_information(master, cur->station_address, |
|
236 |
0x0008, &cur->vendor_id) != 0) |
|
237 |
{ |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
238 |
EC_DBG(KERN_ERR "EtherCAT: Could not read SII vendor id!\n"); |
0 | 239 |
return -1; |
240 |
} |
|
241 |
||
242 |
if (EtherCAT_read_slave_information(master, cur->station_address, |
|
243 |
0x000A, &cur->product_code) != 0) |
|
244 |
{ |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
245 |
EC_DBG(KERN_ERR "EtherCAT: Could not read SII product code!\n"); |
0 | 246 |
return -1; |
247 |
} |
|
248 |
||
249 |
if (EtherCAT_read_slave_information(master, cur->station_address, |
|
250 |
0x000E, &cur->revision_number) != 0) |
|
251 |
{ |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
252 |
EC_DBG(KERN_ERR "EtherCAT: Could not read SII revision number!\n"); |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
253 |
return -1; |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
254 |
} |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
255 |
|
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
256 |
if (EtherCAT_read_slave_information(master, cur->station_address, |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
257 |
0x0012, &cur->serial_number) != 0) |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
258 |
{ |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
259 |
EC_DBG(KERN_ERR "EtherCAT: Could not read SII serial number!\n"); |
0 | 260 |
return -1; |
261 |
} |
|
262 |
||
263 |
// Search for identification in "database" |
|
264 |
||
265 |
found = 0; |
|
266 |
||
267 |
for (j = 0; j < slave_idents_count; j++) |
|
268 |
{ |
|
269 |
if (slave_idents[j].vendor_id == cur->vendor_id |
|
270 |
&& slave_idents[j].product_code == cur->product_code) |
|
271 |
{ |
|
272 |
found = 1; |
|
273 |
||
274 |
if (cur->desc != slave_idents[j].desc) |
|
275 |
{ |
|
276 |
EC_DBG(KERN_ERR "EtherCAT: Unexpected slave device \"%s %s\"" |
|
277 |
" at position %i. Expected: \"%s %s\"\n", |
|
278 |
slave_idents[j].desc->vendor_name, |
|
279 |
slave_idents[j].desc->product_name, i, |
|
280 |
cur->desc->vendor_name, cur->desc->product_name); |
|
281 |
return -1; |
|
282 |
} |
|
283 |
||
284 |
break; |
|
285 |
} |
|
286 |
} |
|
287 |
||
288 |
if (!found) |
|
289 |
{ |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
290 |
EC_DBG(KERN_ERR "EtherCAT: Unknown slave device" |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
291 |
" (vendor %X, code %X) at position %i.\n", |
0 | 292 |
i, cur->vendor_id, cur->product_code); |
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
293 |
return -1; |
0 | 294 |
} |
295 |
} |
|
296 |
||
297 |
length = 0; |
|
298 |
for (i = 0; i < slave_count; i++) |
|
299 |
{ |
|
300 |
length += slaves[i].desc->data_length; |
|
301 |
} |
|
302 |
||
303 |
if ((master->process_data = (unsigned char *) |
|
304 |
kmalloc(sizeof(unsigned char) * length, GFP_KERNEL)) == NULL) |
|
305 |
{ |
|
306 |
EC_DBG(KERN_ERR "EtherCAT: Could not allocate %i bytes for process data.\n", length); |
|
307 |
return -1; |
|
308 |
} |
|
309 |
||
310 |
master->process_data_length = length; |
|
311 |
memset(master->process_data, 0x00, length); |
|
312 |
||
313 |
pos = 0; |
|
314 |
for (i = 0; i < slave_count; i++) |
|
315 |
{ |
|
316 |
slaves[i].process_data = master->process_data + pos; |
|
317 |
slaves[i].logical_address0 = pos; |
|
318 |
||
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
319 |
EC_DBG(KERN_DEBUG "EtherCAT: Slave %i - Address 0x%X, \"%s %s\", s/n %u\n", |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
320 |
i, pos, slaves[i].desc->vendor_name, slaves[i].desc->product_name, |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
321 |
slaves[i].serial_number); |
0 | 322 |
|
323 |
pos += slaves[i].desc->data_length; |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
324 |
} |
0 | 325 |
|
326 |
master->slaves = slaves; |
|
327 |
master->slave_count = slave_count; |
|
328 |
||
329 |
return 0; |
|
330 |
} |
|
331 |
||
332 |
/***************************************************************/ |
|
333 |
||
334 |
/** |
|
335 |
Entfernt den Zeiger auf das Slave-Array. |
|
336 |
||
337 |
@param master EtherCAT-Master |
|
338 |
*/ |
|
339 |
||
340 |
void EtherCAT_clear_slaves(EtherCAT_master_t *master) |
|
341 |
{ |
|
342 |
master->slaves = NULL; |
|
343 |
master->slave_count = 0; |
|
344 |
} |
|
345 |
||
346 |
/***************************************************************/ |
|
347 |
||
348 |
/** |
|
349 |
Liest Daten aus dem Slave-Information-Interface |
|
350 |
eines EtherCAT-Slaves. |
|
351 |
||
352 |
@param master EtherCAT-Master |
|
353 |
@param node_address Knotenadresse des Slaves |
|
354 |
@param offset Adresse des zu lesenden SII-Registers |
|
355 |
@param target Zeiger auf einen 4 Byte großen Speicher |
|
356 |
zum Ablegen der Daten |
|
357 |
||
358 |
@return 0 bei Erfolg, sonst < 0 |
|
359 |
*/ |
|
360 |
||
361 |
int EtherCAT_read_slave_information(EtherCAT_master_t *master, |
|
362 |
unsigned short int node_address, |
|
363 |
unsigned short int offset, |
|
364 |
unsigned int *target) |
|
365 |
{ |
|
366 |
EtherCAT_command_t *cmd; |
|
367 |
unsigned char data[10]; |
|
368 |
unsigned int tries_left; |
|
369 |
||
370 |
// Initiate read operation |
|
371 |
||
372 |
data[0] = 0x00; |
|
373 |
data[1] = 0x01; |
|
374 |
data[2] = offset & 0xFF; |
|
375 |
data[3] = (offset & 0xFF00) >> 8; |
|
376 |
data[4] = 0x00; |
|
377 |
data[5] = 0x00; |
|
378 |
||
379 |
if ((cmd = EtherCAT_write(master, node_address, 0x502, 6, data)) == NULL) |
|
380 |
return -2; |
|
381 |
||
382 |
if (EtherCAT_async_send_receive(master) != 0) |
|
383 |
{ |
|
384 |
EtherCAT_remove_command(master, cmd); |
|
385 |
return -3; |
|
386 |
} |
|
387 |
||
388 |
if (cmd->working_counter != 1) |
|
389 |
{ |
|
390 |
EtherCAT_remove_command(master, cmd); |
|
391 |
EC_DBG(KERN_ERR "EtherCAT: SII-read - Slave %04X did not respond!\n", |
|
392 |
node_address); |
|
393 |
return -4; |
|
394 |
} |
|
395 |
||
396 |
EtherCAT_remove_command(master, cmd); |
|
397 |
||
398 |
// Get status of read operation |
|
399 |
||
400 |
// ?? FIXME warum hier tries ?? Hm |
|
401 |
||
402 |
// Der Slave legt die Informationen des Slave-Information-Interface |
|
403 |
// in das Datenregister und löscht daraufhin ein Busy-Bit. Solange |
|
404 |
// den Status auslesen, bis das Bit weg ist. fp |
|
405 |
||
406 |
tries_left = 1000; |
|
407 |
while (tries_left) |
|
408 |
{ |
|
409 |
udelay(10); |
|
410 |
||
411 |
if ((cmd = EtherCAT_read(master, node_address, 0x502, 10)) == NULL) |
|
412 |
return -2; |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
413 |
|
0 | 414 |
if (EtherCAT_async_send_receive(master) != 0) |
415 |
{ |
|
416 |
EtherCAT_remove_command(master, cmd); |
|
417 |
return -3; |
|
418 |
} |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
419 |
|
0 | 420 |
if (cmd->working_counter != 1) |
421 |
{ |
|
422 |
EtherCAT_remove_command(master, cmd); |
|
423 |
EC_DBG(KERN_ERR "EtherCAT: SII-read status - Slave %04X did not respond!\n", |
|
424 |
node_address); |
|
425 |
return -4; |
|
426 |
} |
|
427 |
||
428 |
if ((cmd->data[1] & 0x81) == 0) |
|
429 |
{ |
|
430 |
memcpy(target, cmd->data + 6, 4); |
|
431 |
EtherCAT_remove_command(master, cmd); |
|
432 |
break; |
|
433 |
} |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
434 |
|
0 | 435 |
EtherCAT_remove_command(master, cmd); |
436 |
||
437 |
tries_left--; |
|
438 |
} |
|
439 |
||
440 |
if (!tries_left) |
|
441 |
{ |
|
442 |
EC_DBG(KERN_WARNING "EtherCAT: SSI-read. Slave %04X timed out!\n", |
|
443 |
node_address); |
|
444 |
return -1; |
|
445 |
} |
|
446 |
||
447 |
return 0; |
|
448 |
} |
|
449 |
||
450 |
/***************************************************************/ |
|
451 |
||
452 |
/** |
|
453 |
Führt ein asynchrones Senden und Empfangen aus. |
|
454 |
||
455 |
Sendet alle wartenden Kommandos und wartet auf die |
|
456 |
entsprechenden Antworten. |
|
457 |
||
458 |
@param master EtherCAT-Master |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
459 |
|
0 | 460 |
@return 0 bei Erfolg, sonst < 0 |
461 |
*/ |
|
462 |
||
463 |
int EtherCAT_async_send_receive(EtherCAT_master_t *master) |
|
464 |
{ |
|
465 |
unsigned int wait_cycles; |
|
466 |
int i; |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
467 |
|
0 | 468 |
// Send all commands |
469 |
||
470 |
for (i = 0; i < ECAT_NUM_RETRIES; i++) |
|
471 |
{ |
|
2
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
472 |
if (EtherCAT_send(master) < 0) |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
473 |
{ |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
474 |
return -1; |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
475 |
} |
0 | 476 |
|
477 |
// Wait until something is received or an error has occurred |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
478 |
|
0 | 479 |
wait_cycles = 10; |
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
480 |
EtherCAT_device_call_isr(master->dev); |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
481 |
|
0 | 482 |
while (master->dev->state == ECAT_DS_SENT && wait_cycles) |
483 |
{ |
|
484 |
udelay(1000); |
|
485 |
wait_cycles--; |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
486 |
EtherCAT_device_call_isr(master->dev); |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
487 |
} |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
488 |
|
0 | 489 |
//EC_DBG("Master async send: tries %d",tries_left); |
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
490 |
|
0 | 491 |
if (!wait_cycles) |
492 |
{ |
|
493 |
EC_DBG(KERN_ERR "EtherCAT: Asynchronous receive timeout.\n"); |
|
494 |
continue; |
|
495 |
} |
|
496 |
||
497 |
if (master->dev->state != ECAT_DS_RECEIVED) |
|
498 |
{ |
|
499 |
EC_DBG(KERN_ERR "EtherCAT: Asyncronous send error. State %i\n", master->dev->state); |
|
500 |
continue; |
|
501 |
} |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
502 |
|
0 | 503 |
// Receive all commands |
504 |
if (EtherCAT_receive(master) < 0) |
|
505 |
{ |
|
506 |
// Noch mal versuchen |
|
507 |
master->dev->state = ECAT_DS_READY; |
|
508 |
EC_DBG("Retry Asynchronous send/recieve: %d", i); |
|
509 |
continue; |
|
510 |
} |
|
511 |
||
512 |
return 0; // Erfolgreich |
|
513 |
} |
|
514 |
||
515 |
return -1; |
|
516 |
} |
|
517 |
||
518 |
/***************************************************************/ |
|
519 |
||
520 |
/** |
|
521 |
Sendet alle wartenden Kommandos. |
|
522 |
||
523 |
Errechnet erst die benötigte Gesamt-Rahmenlänge, und erstellt |
|
524 |
dann alle Kommando-Bytefolgen im statischen Sendespeicher. |
|
525 |
Danach wird die Sendefunktion des EtherCAT-Gerätes aufgerufen. |
|
526 |
||
527 |
@param master EtherCAT-Master |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
528 |
|
0 | 529 |
@return 0 bei Erfolg, sonst < 0 |
530 |
*/ |
|
531 |
||
532 |
int EtherCAT_send(EtherCAT_master_t *master) |
|
533 |
{ |
|
534 |
unsigned int i, length, framelength, pos; |
|
535 |
EtherCAT_command_t *cmd; |
|
536 |
int cmdcnt = 0; |
|
537 |
||
2
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
538 |
if (master->debug_level > 0) |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
539 |
{ |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
540 |
EC_DBG(KERN_DEBUG "EtherCAT_send, first_command = %X\n", (int) master->first_command); |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
541 |
} |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
542 |
|
0 | 543 |
length = 0; |
544 |
for (cmd = master->first_command; cmd != NULL; cmd = cmd->next) |
|
545 |
{ |
|
546 |
if (cmd->state != ECAT_CS_READY) continue; |
|
547 |
length += cmd->data_length + 12; |
|
548 |
cmdcnt++; |
|
549 |
} |
|
550 |
||
2
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
551 |
if (master->debug_level > 0) |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
552 |
{ |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
553 |
EC_DBG(KERN_DEBUG "%i commands to send.\n", cmdcnt); |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
554 |
} |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
555 |
|
0 | 556 |
if (length == 0) |
557 |
{ |
|
558 |
EC_DBG(KERN_WARNING "EtherCAT: Nothing to send...\n"); |
|
559 |
return 0; |
|
560 |
} |
|
561 |
||
562 |
framelength = length + 2; |
|
563 |
if (framelength < 46) framelength = 46; |
|
564 |
||
2
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
565 |
if (master->debug_level > 0) |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
566 |
{ |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
567 |
EC_DBG(KERN_DEBUG "framelength: %i\n", framelength); |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
568 |
} |
0 | 569 |
|
570 |
master->tx_data[0] = length & 0xFF; |
|
571 |
master->tx_data[1] = ((length & 0x700) >> 8) | 0x10; |
|
572 |
pos = 2; |
|
573 |
||
574 |
for (cmd = master->first_command; cmd != NULL; cmd = cmd->next) |
|
575 |
{ |
|
576 |
if (cmd->state != ECAT_CS_READY) continue; |
|
577 |
||
578 |
cmd->index = master->command_index; |
|
579 |
master->command_index = (master->command_index + 1) % 0x0100; |
|
580 |
||
2
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
581 |
if (master->debug_level > 0) |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
582 |
{ |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
583 |
EC_DBG(KERN_DEBUG "Sending command index %i\n", cmd->index); |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
584 |
} |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
585 |
|
0 | 586 |
cmd->state = ECAT_CS_SENT; |
587 |
||
588 |
master->tx_data[pos + 0] = cmd->type; |
|
589 |
master->tx_data[pos + 1] = cmd->index; |
|
590 |
||
591 |
master->tx_data[pos + 2] = cmd->address.raw[0]; |
|
592 |
master->tx_data[pos + 3] = cmd->address.raw[1]; |
|
593 |
master->tx_data[pos + 4] = cmd->address.raw[2]; |
|
594 |
master->tx_data[pos + 5] = cmd->address.raw[3]; |
|
595 |
||
596 |
master->tx_data[pos + 6] = cmd->data_length & 0xFF; |
|
597 |
master->tx_data[pos + 7] = (cmd->data_length & 0x700) >> 8; |
|
598 |
||
599 |
if (cmd->next) master->tx_data[pos + 7] |= 0x80; |
|
600 |
||
601 |
master->tx_data[pos + 8] = 0x00; |
|
602 |
master->tx_data[pos + 9] = 0x00; |
|
603 |
||
604 |
if (cmd->type == ECAT_CMD_APWR |
|
605 |
|| cmd->type == ECAT_CMD_NPWR |
|
606 |
|| cmd->type == ECAT_CMD_BWR |
|
607 |
|| cmd->type == ECAT_CMD_LRW) // Write |
|
608 |
{ |
|
609 |
for (i = 0; i < cmd->data_length; i++) master->tx_data[pos + 10 + i] = cmd->data[i]; |
|
610 |
} |
|
611 |
else // Read |
|
612 |
{ |
|
613 |
for (i = 0; i < cmd->data_length; i++) master->tx_data[pos + 10 + i] = 0x00; |
|
614 |
} |
|
615 |
||
616 |
master->tx_data[pos + 10 + cmd->data_length] = 0x00; |
|
617 |
master->tx_data[pos + 11 + cmd->data_length] = 0x00; |
|
618 |
||
619 |
pos += 12 + cmd->data_length; |
|
620 |
} |
|
621 |
||
622 |
// Pad with zeros |
|
623 |
while (pos < 46) master->tx_data[pos++] = 0x00; |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
624 |
|
0 | 625 |
master->tx_data_length = framelength; |
626 |
||
627 |
#ifdef DEBUG_SEND_RECEIVE |
|
628 |
EC_DBG(KERN_DEBUG "\n"); |
|
629 |
EC_DBG(KERN_DEBUG ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"); |
|
630 |
EC_DBG(KERN_DEBUG); |
|
631 |
for (i = 0; i < framelength; i++) |
|
632 |
{ |
|
633 |
EC_DBG("%02X ", master->tx_data[i]); |
|
634 |
||
635 |
if ((i + 1) % 16 == 0) EC_DBG("\n" KERN_DEBUG); |
|
636 |
} |
|
637 |
EC_DBG("\n"); |
|
638 |
EC_DBG(KERN_DEBUG "-----------------------------------------------\n"); |
|
639 |
#endif |
|
2
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
640 |
|
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
641 |
if (master->debug_level > 0) |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
642 |
{ |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
643 |
EC_DBG(KERN_DEBUG "device send...\n"); |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
644 |
} |
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
645 |
|
0 | 646 |
// Send frame |
647 |
if (EtherCAT_device_send(master->dev, master->tx_data, framelength) != 0) |
|
648 |
{ |
|
649 |
EC_DBG(KERN_ERR "EtherCAT: Could not send!\n"); |
|
650 |
EC_DBG(KERN_DEBUG "EtherCAT: tx_data content:\n"); |
|
651 |
EC_DBG(KERN_DEBUG); |
|
652 |
for (i = 0; i < framelength; i++) |
|
653 |
{ |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
654 |
EC_DBG("%02X ", master->tx_data[i]); |
0 | 655 |
if ((i + 1) % 16 == 0) EC_DBG("\n" KERN_DEBUG); |
656 |
} |
|
657 |
EC_DBG("\n"); |
|
658 |
return -1; |
|
659 |
} |
|
660 |
||
2
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
661 |
if (master->debug_level > 0) |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
662 |
{ |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
663 |
EC_DBG(KERN_DEBUG "EtherCAT_send done.\n"); |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
664 |
} |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
665 |
|
0 | 666 |
return 0; |
667 |
} |
|
668 |
||
669 |
/***************************************************************/ |
|
670 |
||
671 |
/** |
|
672 |
Holt alle empfangenen Kommandos vom EtherCAT-Gerät. |
|
673 |
||
674 |
Kopiert einen empfangenen Rahmen vom EtherCAT-Gerät |
|
675 |
in den Statischen Empfangsspeicher und ordnet dann |
|
676 |
allen gesendeten Kommandos ihre Antworten zu. |
|
677 |
||
678 |
@param master EtherCAT-Master |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
2
diff
changeset
|
679 |
|
0 | 680 |
@return 0 bei Erfolg, sonst < 0 |
681 |
*/ |
|
682 |
||
683 |
int EtherCAT_receive(EtherCAT_master_t *master) |
|
684 |
{ |
|
685 |
EtherCAT_command_t *cmd; |
|
686 |
unsigned int length, pos, found, rx_data_length; |
|
687 |
unsigned int command_follows, command_type, command_index; |
|
688 |
unsigned int i; |
|
689 |
||
690 |
// Copy received data into master buffer (with locking) |
|
691 |
rx_data_length = EtherCAT_device_receive(master->dev, master->rx_data, |
|
692 |
ECAT_FRAME_BUFFER_SIZE); |
|
693 |
||
694 |
#ifdef DEBUG_SEND_RECEIVE |
|
695 |
for (i = 0; i < rx_data_length; i++) |
|
696 |
{ |
|
697 |
if (master->rx_data[i] == master->tx_data[i]) EC_DBG(" "); |
|
698 |
else EC_DBG("%02X ", master->rx_data[i]); |
|
699 |
if ((i + 1) % 16 == 0) EC_DBG("\n" KERN_DEBUG); |
|
700 |
} |
|
701 |
EC_DBG("\n"); |
|
702 |
EC_DBG(KERN_DEBUG "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"); |
|
703 |
EC_DBG(KERN_DEBUG "\n"); |
|
704 |
#endif |
|
705 |
||
706 |
if (rx_data_length < 2) |
|
707 |
{ |
|
708 |
EC_DBG(KERN_ERR "EtherCAT: Received corrupted frame (illegal length)!\n"); |
|
709 |
EC_DBG(KERN_DEBUG "EtherCAT: tx_data content:\n"); |
|
710 |
EC_DBG(KERN_DEBUG); |
|
711 |
for (i = 0; i < master->tx_data_length; i++) |
|
712 |
{ |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
713 |
EC_DBG("%02X ", master->tx_data[i]); |
0 | 714 |
if ((i + 1) % 16 == 0) EC_DBG("\n" KERN_DEBUG); |
715 |
} |
|
716 |
EC_DBG("\n"); |
|
717 |
EC_DBG(KERN_DEBUG "EtherCAT: rx_data content:\n"); |
|
718 |
EC_DBG(KERN_DEBUG); |
|
719 |
for (i = 0; i < rx_data_length; i++) |
|
720 |
{ |
|
721 |
EC_DBG("%02X ", master->rx_data[i]); |
|
722 |
if ((i + 1) % 16 == 0) EC_DBG("\n" KERN_DEBUG); |
|
723 |
} |
|
724 |
EC_DBG("\n"); |
|
725 |
return -1; |
|
726 |
} |
|
727 |
||
728 |
// Länge des gesamten Frames prüfen |
|
729 |
length = ((master->rx_data[1] & 0x07) << 8) | (master->rx_data[0] & 0xFF); |
|
730 |
||
731 |
if (length > rx_data_length) |
|
732 |
{ |
|
733 |
EC_DBG(KERN_ERR "EtherCAT: Received corrupted frame (length does not match)!\n"); |
|
734 |
EC_DBG(KERN_DEBUG "EtherCAT: tx_data content:\n"); |
|
735 |
EC_DBG(KERN_DEBUG); |
|
736 |
for (i = 0; i < master->tx_data_length; i++) |
|
737 |
{ |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
738 |
EC_DBG("%02X ", master->tx_data[i]); |
0 | 739 |
if ((i + 1) % 16 == 0) EC_DBG("\n" KERN_DEBUG); |
740 |
} |
|
741 |
EC_DBG("\n"); |
|
742 |
EC_DBG(KERN_DEBUG "EtherCAT: rx_data content:\n"); |
|
743 |
EC_DBG(KERN_DEBUG); |
|
744 |
for (i = 0; i < rx_data_length; i++) |
|
745 |
{ |
|
746 |
EC_DBG("%02X ", master->rx_data[i]); |
|
747 |
if ((i + 1) % 16 == 0) EC_DBG("\n" KERN_DEBUG); |
|
748 |
} |
|
749 |
EC_DBG("\n"); |
|
750 |
return -1; |
|
751 |
} |
|
752 |
||
753 |
pos = 2; // LibPCAP: 16 |
|
754 |
command_follows = 1; |
|
755 |
while (command_follows) |
|
756 |
{ |
|
757 |
if (pos + 10 > rx_data_length) |
|
758 |
{ |
|
759 |
EC_DBG(KERN_ERR "EtherCAT: Received frame with incomplete command header!\n"); |
|
760 |
EC_DBG(KERN_DEBUG "EtherCAT: tx_data content:\n"); |
|
761 |
EC_DBG(KERN_DEBUG); |
|
762 |
for (i = 0; i < master->tx_data_length; i++) |
|
763 |
{ |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
764 |
EC_DBG("%02X ", master->tx_data[i]); |
0 | 765 |
if ((i + 1) % 16 == 0) EC_DBG("\n" KERN_DEBUG); |
766 |
} |
|
767 |
EC_DBG("\n"); |
|
768 |
EC_DBG(KERN_DEBUG "EtherCAT: rx_data content:\n"); |
|
769 |
EC_DBG(KERN_DEBUG); |
|
770 |
for (i = 0; i < rx_data_length; i++) |
|
771 |
{ |
|
772 |
EC_DBG("%02X ", master->rx_data[i]); |
|
773 |
if ((i + 1) % 16 == 0) EC_DBG("\n" KERN_DEBUG); |
|
774 |
} |
|
775 |
EC_DBG("\n"); |
|
776 |
return -1; |
|
777 |
} |
|
778 |
||
779 |
command_type = master->rx_data[pos]; |
|
780 |
command_index = master->rx_data[pos + 1]; |
|
781 |
length = (master->rx_data[pos + 6] & 0xFF) |
|
782 |
| ((master->rx_data[pos + 7] & 0x07) << 8); |
|
783 |
command_follows = master->rx_data[pos + 7] & 0x80; |
|
784 |
||
785 |
if (pos + length + 12 > rx_data_length) |
|
786 |
{ |
|
787 |
EC_DBG(KERN_ERR "EtherCAT: Received frame with incomplete command data!\n"); |
|
788 |
EC_DBG(KERN_DEBUG "EtherCAT: tx_data content:\n"); |
|
789 |
EC_DBG(KERN_DEBUG); |
|
790 |
for (i = 0; i < master->tx_data_length; i++) |
|
791 |
{ |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
792 |
EC_DBG("%02X ", master->tx_data[i]); |
0 | 793 |
if ((i + 1) % 16 == 0) EC_DBG("\n" KERN_DEBUG); |
794 |
} |
|
795 |
EC_DBG("\n"); |
|
796 |
EC_DBG(KERN_DEBUG "EtherCAT: rx_data content:\n"); |
|
797 |
EC_DBG(KERN_DEBUG); |
|
798 |
for (i = 0; i < rx_data_length; i++) |
|
799 |
{ |
|
800 |
EC_DBG("%02X ", master->rx_data[i]); |
|
801 |
if ((i + 1) % 16 == 0) EC_DBG("\n" KERN_DEBUG); |
|
802 |
} |
|
803 |
EC_DBG("\n"); |
|
804 |
return -1; |
|
805 |
} |
|
806 |
||
807 |
found = 0; |
|
808 |
||
809 |
for (cmd = master->first_command; cmd != NULL; cmd = cmd->next) |
|
810 |
{ |
|
811 |
if (cmd->state == ECAT_CS_SENT |
|
812 |
&& cmd->type == command_type |
|
813 |
&& cmd->index == command_index |
|
814 |
&& cmd->data_length == length) |
|
815 |
{ |
|
816 |
found = 1; |
|
817 |
cmd->state = ECAT_CS_RECEIVED; |
|
818 |
||
819 |
// Empfangene Daten in Kommandodatenspeicher kopieren |
|
820 |
memcpy(cmd->data, master->rx_data + pos + 10, length); |
|
821 |
||
822 |
// Working-Counter setzen |
|
823 |
cmd->working_counter = (master->rx_data[pos + length + 10] & 0xFF) |
|
824 |
| ((master->rx_data[pos + length + 11] & 0xFF) << 8); |
|
825 |
} |
|
826 |
} |
|
827 |
||
828 |
if (!found) |
|
829 |
{ |
|
830 |
EC_DBG(KERN_WARNING "EtherCAT: WARNING - Command not assigned!\n"); |
|
831 |
} |
|
832 |
||
833 |
pos += length + 12; |
|
834 |
} |
|
835 |
||
836 |
for (cmd = master->first_command; cmd != NULL; cmd = cmd->next) |
|
837 |
{ |
|
838 |
if (cmd->state == ECAT_CS_SENT) |
|
839 |
{ |
|
840 |
EC_DBG(KERN_WARNING "EtherCAT: WARNING - One command received no response!\n"); |
|
841 |
} |
|
842 |
} |
|
843 |
||
844 |
master->dev->state = ECAT_DS_READY; |
|
845 |
||
846 |
return 0; |
|
847 |
} |
|
848 |
||
849 |
/***************************************************************/ |
|
850 |
||
851 |
#define ECAT_FUNC_HEADER \ |
|
852 |
EtherCAT_command_t *cmd; \ |
|
853 |
if ((cmd = alloc_cmd(master)) == NULL) \ |
|
854 |
{ \ |
|
855 |
EC_DBG(KERN_ERR "EtherCAT: Out of memory while creating command!\n"); \ |
|
856 |
return NULL; \ |
|
857 |
} \ |
|
858 |
EtherCAT_command_init(cmd) |
|
859 |
||
860 |
#define ECAT_FUNC_WRITE_FOOTER \ |
|
861 |
cmd->data_length = length; \ |
|
862 |
memcpy(cmd->data, data, length); \ |
|
2
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
863 |
if (add_command(master, cmd) < 0) return NULL; \ |
0 | 864 |
return cmd |
865 |
||
866 |
#define ECAT_FUNC_READ_FOOTER \ |
|
867 |
cmd->data_length = length; \ |
|
2
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
868 |
if (add_command(master, cmd) < 0) return NULL; \ |
0 | 869 |
return cmd |
870 |
||
871 |
/***************************************************************/ |
|
872 |
||
873 |
/** |
|
874 |
Erstellt ein EtherCAT-NPRD-Kommando. |
|
875 |
||
876 |
Alloziert ein "node-adressed physical read"-Kommando |
|
877 |
und fügt es in die Liste des Masters ein. |
|
878 |
||
879 |
@param master EtherCAT-Master |
|
880 |
@param node_address Adresse des Knotens (Slaves) |
|
881 |
@param offset Physikalische Speicheradresse im Slave |
|
882 |
@param length Länge der zu lesenden Daten |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
883 |
|
0 | 884 |
@return Adresse des Kommandos bei Erfolg, sonst NULL |
885 |
*/ |
|
886 |
||
887 |
EtherCAT_command_t *EtherCAT_read(EtherCAT_master_t *master, |
|
888 |
unsigned short node_address, |
|
889 |
unsigned short offset, |
|
890 |
unsigned int length) |
|
891 |
{ |
|
892 |
if (node_address == 0x0000) |
|
893 |
EC_DBG(KERN_WARNING "EtherCAT: Using node address 0x0000!\n"); |
|
894 |
||
895 |
ECAT_FUNC_HEADER; |
|
896 |
||
897 |
cmd->type = ECAT_CMD_NPRD; |
|
898 |
cmd->address.phy.dev.node = node_address; |
|
899 |
cmd->address.phy.mem = offset; |
|
900 |
||
901 |
ECAT_FUNC_READ_FOOTER; |
|
902 |
} |
|
903 |
||
904 |
/***************************************************************/ |
|
905 |
||
906 |
/** |
|
907 |
Erstellt ein EtherCAT-NPWR-Kommando. |
|
908 |
||
909 |
Alloziert ein "node-adressed physical write"-Kommando |
|
910 |
und fügt es in die Liste des Masters ein. |
|
911 |
||
912 |
@param master EtherCAT-Master |
|
913 |
@param node_address Adresse des Knotens (Slaves) |
|
914 |
@param offset Physikalische Speicheradresse im Slave |
|
915 |
@param length Länge der zu schreibenden Daten |
|
916 |
@param data Zeiger auf Speicher mit zu schreibenden Daten |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
917 |
|
0 | 918 |
@return Adresse des Kommandos bei Erfolg, sonst NULL |
919 |
*/ |
|
920 |
||
921 |
EtherCAT_command_t *EtherCAT_write(EtherCAT_master_t *master, |
|
922 |
unsigned short node_address, |
|
923 |
unsigned short offset, |
|
924 |
unsigned int length, |
|
925 |
const unsigned char *data) |
|
926 |
{ |
|
927 |
if (node_address == 0x0000) |
|
928 |
EC_DBG(KERN_WARNING "WARNING: Using node address 0x0000!\n"); |
|
929 |
||
930 |
ECAT_FUNC_HEADER; |
|
931 |
||
932 |
cmd->type = ECAT_CMD_NPWR; |
|
933 |
cmd->address.phy.dev.node = node_address; |
|
934 |
cmd->address.phy.mem = offset; |
|
935 |
||
936 |
ECAT_FUNC_WRITE_FOOTER; |
|
937 |
} |
|
938 |
||
939 |
/***************************************************************/ |
|
940 |
||
941 |
/** |
|
942 |
Erstellt ein EtherCAT-APRD-Kommando. |
|
943 |
||
944 |
Alloziert ein "autoincerement physical read"-Kommando |
|
945 |
und fügt es in die Liste des Masters ein. |
|
946 |
||
947 |
@param master EtherCAT-Master |
|
948 |
@param ring_position (Negative) Position des Slaves im Bus |
|
949 |
@param offset Physikalische Speicheradresse im Slave |
|
950 |
@param length Länge der zu lesenden Daten |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
951 |
|
0 | 952 |
@return Adresse des Kommandos bei Erfolg, sonst NULL |
953 |
*/ |
|
954 |
||
955 |
EtherCAT_command_t *EtherCAT_position_read(EtherCAT_master_t *master, |
|
956 |
short ring_position, |
|
957 |
unsigned short offset, |
|
958 |
unsigned int length) |
|
959 |
{ |
|
960 |
ECAT_FUNC_HEADER; |
|
961 |
||
962 |
cmd->type = ECAT_CMD_APRD; |
|
963 |
cmd->address.phy.dev.pos = ring_position; |
|
964 |
cmd->address.phy.mem = offset; |
|
965 |
||
966 |
ECAT_FUNC_READ_FOOTER; |
|
967 |
} |
|
968 |
||
969 |
/***************************************************************/ |
|
970 |
||
971 |
/** |
|
972 |
Erstellt ein EtherCAT-APWR-Kommando. |
|
973 |
||
974 |
Alloziert ein "autoincrement physical write"-Kommando |
|
975 |
und fügt es in die Liste des Masters ein. |
|
976 |
||
977 |
@param master EtherCAT-Master |
|
978 |
@param ring_position (Negative) Position des Slaves im Bus |
|
979 |
@param offset Physikalische Speicheradresse im Slave |
|
980 |
@param length Länge der zu schreibenden Daten |
|
981 |
@param data Zeiger auf Speicher mit zu schreibenden Daten |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
982 |
|
0 | 983 |
@return Adresse des Kommandos bei Erfolg, sonst NULL |
984 |
*/ |
|
985 |
||
986 |
EtherCAT_command_t *EtherCAT_position_write(EtherCAT_master_t *master, |
|
987 |
short ring_position, |
|
988 |
unsigned short offset, |
|
989 |
unsigned int length, |
|
990 |
const unsigned char *data) |
|
991 |
{ |
|
992 |
ECAT_FUNC_HEADER; |
|
993 |
||
994 |
cmd->type = ECAT_CMD_APWR; |
|
995 |
cmd->address.phy.dev.pos = ring_position; |
|
996 |
cmd->address.phy.mem = offset; |
|
997 |
||
998 |
ECAT_FUNC_WRITE_FOOTER; |
|
999 |
} |
|
1000 |
||
1001 |
/***************************************************************/ |
|
1002 |
||
1003 |
/** |
|
1004 |
Erstellt ein EtherCAT-BRD-Kommando. |
|
1005 |
||
1006 |
Alloziert ein "broadcast read"-Kommando |
|
1007 |
und fügt es in die Liste des Masters ein. |
|
1008 |
||
1009 |
@param master EtherCAT-Master |
|
1010 |
@param offset Physikalische Speicheradresse im Slave |
|
1011 |
@param length Länge der zu lesenden Daten |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1012 |
|
0 | 1013 |
@return Adresse des Kommandos bei Erfolg, sonst NULL |
1014 |
*/ |
|
1015 |
||
1016 |
EtherCAT_command_t *EtherCAT_broadcast_read(EtherCAT_master_t *master, |
|
1017 |
unsigned short offset, |
|
1018 |
unsigned int length) |
|
1019 |
{ |
|
1020 |
ECAT_FUNC_HEADER; |
|
1021 |
||
1022 |
cmd->type = ECAT_CMD_BRD; |
|
1023 |
cmd->address.phy.dev.node = 0x0000; |
|
1024 |
cmd->address.phy.mem = offset; |
|
1025 |
||
1026 |
ECAT_FUNC_READ_FOOTER; |
|
1027 |
} |
|
1028 |
||
1029 |
/***************************************************************/ |
|
1030 |
||
1031 |
/** |
|
1032 |
Erstellt ein EtherCAT-BWR-Kommando. |
|
1033 |
||
1034 |
Alloziert ein "broadcast write"-Kommando |
|
1035 |
und fügt es in die Liste des Masters ein. |
|
1036 |
||
1037 |
@param master EtherCAT-Master |
|
1038 |
@param offset Physikalische Speicheradresse im Slave |
|
1039 |
@param length Länge der zu schreibenden Daten |
|
1040 |
@param data Zeiger auf Speicher mit zu schreibenden Daten |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1041 |
|
0 | 1042 |
@return Adresse des Kommandos bei Erfolg, sonst NULL |
1043 |
*/ |
|
1044 |
||
1045 |
EtherCAT_command_t *EtherCAT_broadcast_write(EtherCAT_master_t *master, |
|
1046 |
unsigned short offset, |
|
1047 |
unsigned int length, |
|
1048 |
const unsigned char *data) |
|
1049 |
{ |
|
1050 |
ECAT_FUNC_HEADER; |
|
1051 |
||
1052 |
cmd->type = ECAT_CMD_BWR; |
|
1053 |
cmd->address.phy.dev.node = 0x0000; |
|
1054 |
cmd->address.phy.mem = offset; |
|
1055 |
||
1056 |
ECAT_FUNC_WRITE_FOOTER; |
|
1057 |
} |
|
1058 |
||
1059 |
/***************************************************************/ |
|
1060 |
||
1061 |
/** |
|
1062 |
Erstellt ein EtherCAT-LRW-Kommando. |
|
1063 |
||
1064 |
Alloziert ein "logical read write"-Kommando |
|
1065 |
und fügt es in die Liste des Masters ein. |
|
1066 |
||
1067 |
@param master EtherCAT-Master |
|
1068 |
@param offset Logische Speicheradresse |
|
1069 |
@param length Länge der zu lesenden/schreibenden Daten |
|
1070 |
@param data Zeiger auf Speicher mit zu lesenden/schreibenden Daten |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1071 |
|
0 | 1072 |
@return Adresse des Kommandos bei Erfolg, sonst NULL |
1073 |
*/ |
|
1074 |
||
1075 |
EtherCAT_command_t *EtherCAT_logical_read_write(EtherCAT_master_t *master, |
|
1076 |
unsigned int offset, |
|
1077 |
unsigned int length, |
|
1078 |
unsigned char *data) |
|
1079 |
{ |
|
1080 |
ECAT_FUNC_HEADER; |
|
1081 |
||
1082 |
cmd->type = ECAT_CMD_LRW; |
|
1083 |
cmd->address.logical = offset; |
|
1084 |
||
1085 |
ECAT_FUNC_WRITE_FOOTER; |
|
1086 |
} |
|
1087 |
||
1088 |
/***************************************************************/ |
|
1089 |
||
1090 |
/** |
|
1091 |
Alloziert ein neues Kommando aus dem Kommandoring. |
|
1092 |
||
1093 |
Durchsucht den Kommandoring nach einem freien Kommando, |
|
1094 |
reserviert es und gibt dessen Adresse zurück. |
|
1095 |
||
1096 |
@param master EtherCAT-Master |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1097 |
|
0 | 1098 |
@return Adresse des Kommandos bei Erfolg, sonst NULL |
1099 |
*/ |
|
1100 |
||
1101 |
EtherCAT_command_t *alloc_cmd(EtherCAT_master_t *master) |
|
1102 |
{ |
|
1103 |
int j; |
|
1104 |
||
1105 |
for (j = 0; j < ECAT_COMMAND_RING_SIZE; j++) // Einmal rum suchen |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1106 |
{ |
0 | 1107 |
// Solange suchen, bis freies Kommando gefunden |
2
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1108 |
if (master->cmd_reserved[master->cmd_ring_index] == 0) |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1109 |
{ |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1110 |
master->cmd_reserved[master->cmd_ring_index] = 1; // Belegen |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1111 |
|
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1112 |
if (master->debug_level) |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1113 |
{ |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1114 |
EC_DBG(KERN_DEBUG "Allocating command %i (addr %X).\n", |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1115 |
master->cmd_ring_index, |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1116 |
(int) &master->cmd_ring[master->cmd_ring_index]); |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1117 |
} |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1118 |
|
0 | 1119 |
return &master->cmd_ring[master->cmd_ring_index]; |
1120 |
} |
|
1121 |
||
2
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1122 |
if (master->debug_level) |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1123 |
{ |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1124 |
EC_DBG(KERN_DEBUG "Command %i (addr %X) is reserved...\n", |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1125 |
master->cmd_ring_index, |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1126 |
(int) &master->cmd_ring[master->cmd_ring_index]); |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1127 |
} |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1128 |
|
0 | 1129 |
master->cmd_ring_index++; |
1130 |
master->cmd_ring_index %= ECAT_COMMAND_RING_SIZE; |
|
1131 |
} |
|
1132 |
||
1133 |
EC_DBG(KERN_WARNING "EtherCAT: Command ring full!\n"); |
|
1134 |
||
1135 |
return NULL; // Nix gefunden |
|
1136 |
} |
|
1137 |
||
1138 |
/***************************************************************/ |
|
1139 |
||
1140 |
/** |
|
1141 |
Fügt ein Kommando in die Liste des Masters ein. |
|
1142 |
||
1143 |
@param master EtherCAT-Master |
|
1144 |
@param cmd Zeiger auf das einzufügende Kommando |
|
1145 |
*/ |
|
1146 |
||
2
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1147 |
int add_command(EtherCAT_master_t *master, |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1148 |
EtherCAT_command_t *new_cmd) |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1149 |
{ |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1150 |
EtherCAT_command_t *cmd, **last_cmd; |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1151 |
|
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1152 |
for (cmd = master->first_command; cmd != NULL; cmd = cmd->next) |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1153 |
{ |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1154 |
if (cmd == new_cmd) |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1155 |
{ |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1156 |
EC_DBG(KERN_WARNING "EtherCAT: Trying to add a command" |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1157 |
" that is already in the list!\n"); |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1158 |
return -1; |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1159 |
} |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1160 |
} |
0 | 1161 |
|
1162 |
// Find the address of the last pointer in the list |
|
1163 |
last_cmd = &(master->first_command); |
|
1164 |
while (*last_cmd) last_cmd = &(*last_cmd)->next; |
|
1165 |
||
1166 |
// Let this pointer point to the new command |
|
2
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1167 |
*last_cmd = new_cmd; |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1168 |
|
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1169 |
return 0; |
0 | 1170 |
} |
1171 |
||
1172 |
/***************************************************************/ |
|
1173 |
||
1174 |
/** |
|
1175 |
Entfernt ein Kommando aus der Liste und gibt es frei. |
|
1176 |
||
1177 |
Prüft erst, ob das Kommando in der Liste des Masters |
|
1178 |
ist. Wenn ja, wird es entfernt und die Reservierung wird |
|
1179 |
aufgehoben. |
|
1180 |
||
1181 |
@param master EtherCAT-Master |
|
1182 |
@param rem_cmd Zeiger auf das zu entfernende Kommando |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1183 |
|
0 | 1184 |
@return 0 bei Erfolg, sonst < 0 |
1185 |
*/ |
|
1186 |
||
1187 |
void EtherCAT_remove_command(EtherCAT_master_t *master, |
|
1188 |
EtherCAT_command_t *rem_cmd) |
|
1189 |
{ |
|
1190 |
EtherCAT_command_t **last_cmd; |
|
2
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1191 |
int i; |
0 | 1192 |
|
1193 |
last_cmd = &master->first_command; |
|
1194 |
while (*last_cmd) |
|
1195 |
{ |
|
1196 |
if (*last_cmd == rem_cmd) |
|
1197 |
{ |
|
1198 |
*last_cmd = rem_cmd->next; |
|
1199 |
EtherCAT_command_clear(rem_cmd); |
|
1200 |
||
2
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1201 |
// Reservierung des Kommandos aufheben |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1202 |
for (i = 0; i < ECAT_COMMAND_RING_SIZE; i++) |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1203 |
{ |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1204 |
if (&master->cmd_ring[i] == rem_cmd) |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1205 |
{ |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1206 |
master->cmd_reserved[i] = 0; |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1207 |
return; |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1208 |
} |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1209 |
} |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1210 |
|
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1211 |
EC_DBG(KERN_WARNING "EtherCAT: Could not remove command reservation!\n"); |
0 | 1212 |
return; |
1213 |
} |
|
1214 |
||
1215 |
last_cmd = &(*last_cmd)->next; |
|
1216 |
} |
|
1217 |
||
1218 |
EC_DBG(KERN_WARNING "EtherCAT: Trying to remove non-existent command!\n"); |
|
1219 |
} |
|
1220 |
||
1221 |
/***************************************************************/ |
|
1222 |
||
1223 |
/** |
|
1224 |
Ändert den Zustand eines Slaves (asynchron). |
|
1225 |
||
1226 |
Führt eine (asynchrone) Zustandsänderung bei einem Slave durch. |
|
1227 |
||
1228 |
@param master EtherCAT-Master |
|
1229 |
@param slave Slave, dessen Zustand geändert werden soll |
|
1230 |
@param state_and_ack Neuer Zustand, evtl. mit gesetztem |
|
1231 |
Acknowledge-Flag |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1232 |
|
0 | 1233 |
@return 0 bei Erfolg, sonst < 0 |
1234 |
*/ |
|
1235 |
||
1236 |
int EtherCAT_state_change(EtherCAT_master_t *master, |
|
1237 |
EtherCAT_slave_t *slave, |
|
1238 |
unsigned char state_and_ack) |
|
1239 |
{ |
|
1240 |
EtherCAT_command_t *cmd; |
|
1241 |
unsigned char data[2]; |
|
1242 |
unsigned int tries_left; |
|
1243 |
||
1244 |
data[0] = state_and_ack; |
|
1245 |
data[1] = 0x00; |
|
1246 |
||
1247 |
if ((cmd = EtherCAT_write(master, slave->station_address, |
|
1248 |
0x0120, 2, data)) == NULL) |
|
1249 |
{ |
|
1250 |
EC_DBG(KERN_ERR "EtherCAT: Could not set state %02X - Out of memory!\n", state_and_ack); |
|
1251 |
return -1; |
|
1252 |
} |
|
1253 |
||
1254 |
if (EtherCAT_async_send_receive(master) != 0) |
|
1255 |
{ |
|
1256 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1257 |
|
0 | 1258 |
EC_DBG(KERN_ERR "EtherCAT: Could not set state %02X - Unable to send!\n", state_and_ack); |
1259 |
return -2; |
|
1260 |
} |
|
1261 |
||
1262 |
if (cmd->working_counter != 1) |
|
1263 |
{ |
|
1264 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1265 |
|
0 | 1266 |
EC_DBG(KERN_ERR "EtherCAT: Could not set state %02X - Device did not respond!\n", state_and_ack); |
1267 |
return -3; |
|
1268 |
} |
|
1269 |
||
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1270 |
EtherCAT_remove_command(master, cmd); |
0 | 1271 |
|
1272 |
slave->requested_state = state_and_ack & 0x0F; |
|
1273 |
||
1274 |
tries_left = 1000; |
|
1275 |
||
1276 |
while (tries_left) |
|
1277 |
{ |
|
1278 |
udelay(10); |
|
1279 |
||
1280 |
if ((cmd = EtherCAT_read(master, slave->station_address, |
|
1281 |
0x0130, 2)) == NULL) |
|
1282 |
{ |
|
1283 |
EC_DBG(KERN_ERR "EtherCAT: Could not check state %02X - Out of memory!\n", state_and_ack); |
|
1284 |
return -1; |
|
1285 |
} |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1286 |
|
0 | 1287 |
if (EtherCAT_async_send_receive(master) != 0) |
1288 |
{ |
|
1289 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1290 |
|
0 | 1291 |
EC_DBG(KERN_ERR "EtherCAT: Could not check state %02X - Unable to send!\n", state_and_ack); |
1292 |
return -2; |
|
1293 |
} |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1294 |
|
0 | 1295 |
if (cmd->working_counter != 1) |
1296 |
{ |
|
1297 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1298 |
|
0 | 1299 |
EC_DBG(KERN_ERR "EtherCAT: Could not check state %02X - Device did not respond!\n", state_and_ack); |
1300 |
return -3; |
|
1301 |
} |
|
1302 |
||
1303 |
if (cmd->data[0] & 0x10) // State change error |
|
1304 |
{ |
|
1305 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1306 |
|
0 | 1307 |
EC_DBG(KERN_ERR "EtherCAT: Could not set state %02X - Device refused state change (code %02X)!\n", state_and_ack, cmd->data[0]); |
1308 |
return -4; |
|
1309 |
} |
|
1310 |
||
1311 |
if (cmd->data[0] == (state_and_ack & 0x0F)) // State change successful |
|
1312 |
{ |
|
1313 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1314 |
|
0 | 1315 |
break; |
1316 |
} |
|
1317 |
||
1318 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1319 |
|
0 | 1320 |
tries_left--; |
1321 |
} |
|
1322 |
||
1323 |
if (!tries_left) |
|
1324 |
{ |
|
1325 |
EC_DBG(KERN_ERR "EtherCAT: Could not check state %02X - Timeout while checking!\n", state_and_ack); |
|
1326 |
return -5; |
|
1327 |
} |
|
1328 |
||
1329 |
slave->current_state = state_and_ack & 0x0F; |
|
1330 |
||
1331 |
return 0; |
|
1332 |
} |
|
1333 |
||
1334 |
/***************************************************************/ |
|
1335 |
||
1336 |
/** |
|
1337 |
Konfiguriert einen Slave und setzt den Operational-Zustand. |
|
1338 |
||
1339 |
Führt eine komplette Konfiguration eines Slaves durch, |
|
1340 |
setzt Sync-Manager und FMMU's, führt die entsprechenden |
|
1341 |
Zustandsübergänge durch, bis der Slave betriebsbereit ist. |
|
1342 |
||
1343 |
@param master EtherCAT-Master |
|
1344 |
@param slave Zu aktivierender Slave |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1345 |
|
0 | 1346 |
@return 0 bei Erfolg, sonst < 0 |
1347 |
*/ |
|
1348 |
||
1349 |
int EtherCAT_activate_slave(EtherCAT_master_t *master, |
|
1350 |
EtherCAT_slave_t *slave) |
|
1351 |
{ |
|
1352 |
EtherCAT_command_t *cmd; |
|
1353 |
const EtherCAT_slave_desc_t *desc; |
|
1354 |
unsigned char fmmu[16]; |
|
1355 |
unsigned char data[256]; |
|
1356 |
||
1357 |
desc = slave->desc; |
|
1358 |
||
1359 |
if (EtherCAT_state_change(master, slave, ECAT_STATE_INIT) != 0) |
|
1360 |
{ |
|
1361 |
return -1; |
|
1362 |
} |
|
1363 |
||
1364 |
// Resetting FMMU's |
|
1365 |
||
1366 |
memset(data, 0x00, 256); |
|
1367 |
||
1368 |
if ((cmd = EtherCAT_write(master, slave->station_address, 0x0600, 256, data)) == NULL) |
|
1369 |
return -1; |
|
1370 |
||
1371 |
if (EtherCAT_async_send_receive(master) < 0) |
|
1372 |
{ |
|
1373 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1374 |
|
0 | 1375 |
return -1; |
1376 |
} |
|
1377 |
||
1378 |
if (cmd->working_counter != 1) |
|
1379 |
{ |
|
1380 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1381 |
|
0 | 1382 |
EC_DBG(KERN_ERR "EtherCAT: Resetting FMMUs - Slave %04X did not respond!\n", |
1383 |
slave->station_address); |
|
1384 |
return -2; |
|
1385 |
} |
|
1386 |
||
1387 |
EtherCAT_remove_command(master, cmd); |
|
1388 |
||
1389 |
// Resetting Sync Manager channels |
|
1390 |
||
1391 |
if (desc->type != ECAT_ST_SIMPLE_NOSYNC) |
|
1392 |
{ |
|
1393 |
memset(data, 0x00, 256); |
|
1394 |
||
1395 |
if ((cmd = EtherCAT_write(master, slave->station_address, 0x0800, 256, data)) == NULL) |
|
1396 |
return -1; |
|
1397 |
||
1398 |
if (EtherCAT_async_send_receive(master) < 0) |
|
1399 |
{ |
|
1400 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1401 |
|
0 | 1402 |
return -1; |
1403 |
} |
|
1404 |
||
1405 |
if (cmd->working_counter != 1) |
|
1406 |
{ |
|
1407 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1408 |
|
0 | 1409 |
EC_DBG(KERN_ERR "EtherCAT: Resetting SMs - Slave %04X did not respond!\n", |
1410 |
slave->station_address); |
|
1411 |
return -2; |
|
1412 |
} |
|
1413 |
||
1414 |
EtherCAT_remove_command(master, cmd); |
|
1415 |
} |
|
1416 |
||
1417 |
// Init Mailbox communication |
|
1418 |
||
1419 |
if (desc->type == ECAT_ST_MAILBOX) |
|
1420 |
{ |
|
1421 |
if (desc->sm0) |
|
1422 |
{ |
|
1423 |
if ((cmd = EtherCAT_write(master, slave->station_address, 0x0800, 8, desc->sm0)) == NULL) |
|
1424 |
return -1; |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1425 |
|
0 | 1426 |
if (EtherCAT_async_send_receive(master) < 0) |
1427 |
{ |
|
1428 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1429 |
|
0 | 1430 |
return -1; |
1431 |
} |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1432 |
|
0 | 1433 |
if (cmd->working_counter != 1) |
1434 |
{ |
|
1435 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1436 |
|
0 | 1437 |
EC_DBG(KERN_ERR "EtherCAT: Setting SM0 - Slave %04X did not respond!\n", |
1438 |
slave->station_address); |
|
1439 |
return -3; |
|
1440 |
} |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1441 |
|
0 | 1442 |
EtherCAT_remove_command(master, cmd); |
1443 |
} |
|
1444 |
||
1445 |
if (desc->sm1) |
|
1446 |
{ |
|
1447 |
if ((cmd = EtherCAT_write(master, slave->station_address, 0x0808, 8, desc->sm1)) == NULL) |
|
1448 |
return -1; |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1449 |
|
0 | 1450 |
if (EtherCAT_async_send_receive(master) < 0) |
1451 |
{ |
|
1452 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1453 |
|
0 | 1454 |
return -1; |
1455 |
} |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1456 |
|
0 | 1457 |
if (cmd->working_counter != 1) |
1458 |
{ |
|
1459 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1460 |
|
0 | 1461 |
EC_DBG(KERN_ERR "EtherCAT: Setting SM1 - Slave %04X did not respond!\n", |
1462 |
slave->station_address); |
|
1463 |
return -2; |
|
1464 |
} |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1465 |
|
0 | 1466 |
EtherCAT_remove_command(master, cmd); |
1467 |
} |
|
1468 |
} |
|
1469 |
||
1470 |
// Change state to PREOP |
|
1471 |
||
1472 |
if (EtherCAT_state_change(master, slave, ECAT_STATE_PREOP) != 0) |
|
1473 |
{ |
|
1474 |
return -5; |
|
1475 |
} |
|
1476 |
||
1477 |
// Set FMMU's |
|
1478 |
||
1479 |
if (desc->fmmu0) |
|
1480 |
{ |
|
1481 |
memcpy(fmmu, desc->fmmu0, 16); |
|
1482 |
||
1483 |
fmmu[0] = slave->logical_address0 & 0x000000FF; |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1484 |
fmmu[1] = (slave->logical_address0 & 0x0000FF00) >> 8; |
0 | 1485 |
fmmu[2] = (slave->logical_address0 & 0x00FF0000) >> 16; |
1486 |
fmmu[3] = (slave->logical_address0 & 0xFF000000) >> 24; |
|
1487 |
||
1488 |
if ((cmd = EtherCAT_write(master, slave->station_address, 0x0600, 16, fmmu)) == NULL) |
|
1489 |
return -1; |
|
1490 |
||
1491 |
if (EtherCAT_async_send_receive(master) < 0) |
|
1492 |
{ |
|
1493 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1494 |
|
0 | 1495 |
return -1; |
1496 |
} |
|
1497 |
||
1498 |
if (cmd->working_counter != 1) |
|
1499 |
{ |
|
1500 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1501 |
|
0 | 1502 |
EC_DBG(KERN_ERR "EtherCAT: Setting FMMU0 - Slave %04X did not respond!\n", |
1503 |
slave->station_address); |
|
1504 |
return -2; |
|
1505 |
} |
|
1506 |
||
1507 |
EtherCAT_remove_command(master, cmd); |
|
1508 |
} |
|
1509 |
||
1510 |
// Set Sync Managers |
|
1511 |
||
1512 |
if (desc->type != ECAT_ST_MAILBOX) |
|
1513 |
{ |
|
1514 |
if (desc->sm0) |
|
1515 |
{ |
|
1516 |
if ((cmd = EtherCAT_write(master, slave->station_address, 0x0800, 8, desc->sm0)) == NULL) |
|
1517 |
return -1; |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1518 |
|
0 | 1519 |
if (EtherCAT_async_send_receive(master) < 0) |
1520 |
{ |
|
1521 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1522 |
|
0 | 1523 |
return -1; |
1524 |
} |
|
1525 |
||
1526 |
if (cmd->working_counter != 1) |
|
1527 |
{ |
|
1528 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1529 |
|
0 | 1530 |
EC_DBG(KERN_ERR "EtherCAT: Setting SM0 - Slave %04X did not respond!\n", |
1531 |
slave->station_address); |
|
1532 |
return -3; |
|
1533 |
} |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1534 |
|
0 | 1535 |
EtherCAT_remove_command(master, cmd); |
1536 |
} |
|
1537 |
||
1538 |
if (desc->sm1) |
|
1539 |
{ |
|
1540 |
if ((cmd = EtherCAT_write(master, slave->station_address, 0x0808, 8, desc->sm1)) == NULL) |
|
1541 |
return -1; |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1542 |
|
0 | 1543 |
if (EtherCAT_async_send_receive(master) < 0) |
1544 |
{ |
|
1545 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1546 |
|
0 | 1547 |
return -1; |
1548 |
} |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1549 |
|
0 | 1550 |
if (cmd->working_counter != 1) |
1551 |
{ |
|
1552 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1553 |
|
0 | 1554 |
EC_DBG(KERN_ERR "EtherCAT: Setting SM1 - Slave %04X did not respond!\n", |
1555 |
slave->station_address); |
|
1556 |
return -3; |
|
1557 |
} |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1558 |
|
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1559 |
EtherCAT_remove_command(master, cmd); |
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1560 |
} |
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1561 |
} |
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1562 |
|
0 | 1563 |
if (desc->sm2) |
1564 |
{ |
|
1565 |
if ((cmd = EtherCAT_write(master, slave->station_address, 0x0810, 8, desc->sm2)) == NULL) |
|
1566 |
return -1; |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1567 |
|
0 | 1568 |
if (EtherCAT_async_send_receive(master) < 0) |
1569 |
{ |
|
1570 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1571 |
|
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1572 |
return -1; |
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1573 |
} |
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1574 |
|
0 | 1575 |
if (cmd->working_counter != 1) |
1576 |
{ |
|
1577 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1578 |
|
0 | 1579 |
EC_DBG(KERN_ERR "EtherCAT: Setting SM2 - Slave %04X did not respond!\n", |
1580 |
slave->station_address); |
|
1581 |
return -3; |
|
1582 |
} |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1583 |
|
0 | 1584 |
EtherCAT_remove_command(master, cmd); |
1585 |
} |
|
1586 |
||
1587 |
if (desc->sm3) |
|
1588 |
{ |
|
1589 |
if ((cmd = EtherCAT_write(master, slave->station_address, 0x0818, 8, desc->sm3)) == NULL) |
|
1590 |
return -1; |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1591 |
|
0 | 1592 |
if (EtherCAT_async_send_receive(master) < 0) |
1593 |
{ |
|
1594 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1595 |
|
0 | 1596 |
return -1; |
1597 |
} |
|
1598 |
||
1599 |
if (cmd->working_counter != 1) |
|
1600 |
{ |
|
1601 |
EtherCAT_remove_command(master, cmd); |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1602 |
|
0 | 1603 |
EC_DBG(KERN_ERR "EtherCAT: Setting SM3 - Slave %04X did not respond!\n", |
1604 |
slave->station_address); |
|
1605 |
return -3; |
|
1606 |
} |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1607 |
|
0 | 1608 |
EtherCAT_remove_command(master, cmd); |
1609 |
} |
|
1610 |
||
1611 |
// Change state to SAVEOP |
|
1612 |
if (EtherCAT_state_change(master, slave, ECAT_STATE_SAVEOP) != 0) |
|
1613 |
{ |
|
1614 |
return -12; |
|
1615 |
} |
|
1616 |
||
1617 |
// Change state to OP |
|
1618 |
if (EtherCAT_state_change(master, slave, ECAT_STATE_OP) != 0) |
|
1619 |
{ |
|
1620 |
return -13; |
|
1621 |
} |
|
1622 |
||
1623 |
return 0; |
|
1624 |
} |
|
1625 |
||
1626 |
/***************************************************************/ |
|
1627 |
||
1628 |
/** |
|
1629 |
Setzt einen Slave zurück in den Init-Zustand. |
|
1630 |
||
1631 |
@param master EtherCAT-Master |
|
1632 |
@param slave Zu deaktivierender Slave |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1633 |
|
0 | 1634 |
@return 0 bei Erfolg, sonst < 0 |
1635 |
*/ |
|
1636 |
||
1637 |
int EtherCAT_deactivate_slave(EtherCAT_master_t *master, |
|
1638 |
EtherCAT_slave_t *slave) |
|
1639 |
{ |
|
1640 |
if (EtherCAT_state_change(master, slave, ECAT_STATE_INIT) != 0) |
|
1641 |
{ |
|
1642 |
return -1; |
|
1643 |
} |
|
1644 |
||
1645 |
return 0; |
|
1646 |
} |
|
1647 |
||
1648 |
/***************************************************************/ |
|
1649 |
||
1650 |
/** |
|
1651 |
Aktiviert alle Slaves. |
|
1652 |
||
1653 |
@see EtherCAT_activate_slave |
|
1654 |
||
1655 |
@param master EtherCAT-Master |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1656 |
|
0 | 1657 |
@return 0 bei Erfolg, sonst < 0 |
1658 |
*/ |
|
1659 |
||
1660 |
int EtherCAT_activate_all_slaves(EtherCAT_master_t *master) |
|
1661 |
{ |
|
1662 |
unsigned int i; |
|
1663 |
||
1664 |
for (i = 0; i < master->slave_count; i++) |
|
1665 |
{ |
|
1666 |
if (EtherCAT_activate_slave(master, &master->slaves[i]) < 0) |
|
1667 |
{ |
|
1668 |
return -1; |
|
1669 |
} |
|
1670 |
} |
|
1671 |
||
1672 |
return 0; |
|
1673 |
} |
|
1674 |
||
1675 |
/***************************************************************/ |
|
1676 |
||
1677 |
/** |
|
1678 |
Deaktiviert alle Slaves. |
|
1679 |
||
1680 |
@see EtherCAT_deactivate_slave |
|
1681 |
||
1682 |
@param master EtherCAT-Master |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1683 |
|
0 | 1684 |
@return 0 bei Erfolg, sonst < 0 |
1685 |
*/ |
|
1686 |
||
1687 |
int EtherCAT_deactivate_all_slaves(EtherCAT_master_t *master) |
|
1688 |
{ |
|
1689 |
unsigned int i; |
|
1690 |
int ret = 0; |
|
1691 |
||
1692 |
for (i = 0; i < master->slave_count; i++) |
|
1693 |
{ |
|
1694 |
if (EtherCAT_deactivate_slave(master, &master->slaves[i]) < 0) |
|
1695 |
{ |
|
1696 |
ret = -1; |
|
1697 |
} |
|
1698 |
} |
|
1699 |
||
1700 |
return ret; |
|
1701 |
} |
|
1702 |
||
1703 |
/***************************************************************/ |
|
1704 |
||
1705 |
/** |
|
1706 |
Sendet alle Prozessdaten an die Slaves. |
|
1707 |
||
1708 |
Erstellt ein "logical read write"-Kommando mit den |
|
1709 |
Prozessdaten des Masters und sendet es an den Bus. |
|
1710 |
||
1711 |
@param master EtherCAT-Master |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1712 |
|
0 | 1713 |
@return 0 bei Erfolg, sonst < 0 |
1714 |
*/ |
|
1715 |
||
1716 |
int EtherCAT_write_process_data(EtherCAT_master_t *master) |
|
1717 |
{ |
|
1718 |
if (master->process_data_command) |
|
1719 |
{ |
|
1720 |
EtherCAT_remove_command(master, master->process_data_command); |
|
1721 |
EtherCAT_command_clear(master->process_data_command); |
|
1722 |
master->process_data_command = NULL; |
|
1723 |
} |
|
1724 |
||
1725 |
if ((master->process_data_command |
|
2
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1726 |
= EtherCAT_logical_read_write(master, |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1727 |
0, master->process_data_length, |
0 | 1728 |
master->process_data)) == NULL) |
1729 |
{ |
|
1730 |
EC_DBG(KERN_ERR "EtherCAT: Could not allocate process data command!\n"); |
|
1731 |
return -1; |
|
1732 |
} |
|
1733 |
||
1734 |
if (EtherCAT_send(master) < 0) |
|
1735 |
{ |
|
1736 |
EtherCAT_remove_command(master, master->process_data_command); |
|
1737 |
EtherCAT_command_clear(master->process_data_command); |
|
1738 |
master->process_data_command = NULL; |
|
1739 |
EC_DBG(KERN_ERR "EtherCAT: Could not send process data command!\n"); |
|
1740 |
return -1; |
|
1741 |
} |
|
1742 |
||
1743 |
return 0; |
|
1744 |
} |
|
1745 |
||
1746 |
/***************************************************************/ |
|
1747 |
||
1748 |
/** |
|
1749 |
Empfängt alle Prozessdaten von den Slaves. |
|
1750 |
||
1751 |
Empfängt ein zuvor gesendetes "logical read write"-Kommando |
|
1752 |
und kopiert die empfangenen daten in den Prozessdatenspeicher |
|
1753 |
des Masters. |
|
1754 |
||
1755 |
@param master EtherCAT-Master |
|
8
f2ebe943c686
Spaces am Zeilenende entfernt.
Florian Pose <fp@igh-essen.com>
parents:
6
diff
changeset
|
1756 |
|
0 | 1757 |
@return 0 bei Erfolg, sonst < 0 |
1758 |
*/ |
|
1759 |
||
1760 |
int EtherCAT_read_process_data(EtherCAT_master_t *master) |
|
1761 |
{ |
|
1762 |
int ret = -1; |
|
1763 |
||
1764 |
if (!master->process_data_command) |
|
1765 |
{ |
|
1766 |
EC_DBG(KERN_WARNING "EtherCAT: No process data command available!\n"); |
|
1767 |
return -1; |
|
1768 |
} |
|
1769 |
||
6
e36a85dc2730
ISR-Aufruf in read_process_data
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
5
diff
changeset
|
1770 |
EtherCAT_device_call_isr(master->dev); |
e36a85dc2730
ISR-Aufruf in read_process_data
Wilhelm Hagemeister <hm@igh-essen.com>
parents:
5
diff
changeset
|
1771 |
|
0 | 1772 |
if (EtherCAT_receive(master) < 0) |
1773 |
{ |
|
1774 |
EC_DBG(KERN_ERR "EtherCAT: Could not receive cyclic command!\n"); |
|
1775 |
} |
|
1776 |
else if (master->process_data_command->state != ECAT_CS_RECEIVED) |
|
1777 |
{ |
|
1778 |
EC_DBG(KERN_WARNING "EtherCAT: Process data command not received!\n"); |
|
1779 |
} |
|
1780 |
else |
|
1781 |
{ |
|
1782 |
// Daten von Kommando in Prozessdaten des Master kopieren |
|
1783 |
memcpy(master->process_data, master->process_data_command->data, master->process_data_length); |
|
1784 |
ret = 0; |
|
1785 |
} |
|
1786 |
||
1787 |
EtherCAT_remove_command(master, master->process_data_command); |
|
1788 |
EtherCAT_command_clear(master->process_data_command); |
|
1789 |
master->process_data_command = NULL; |
|
1790 |
||
1791 |
return ret; |
|
1792 |
} |
|
1793 |
||
1794 |
/***************************************************************/ |
|
1795 |
||
1796 |
/** |
|
2
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1797 |
Verwirft ein zuvor gesendetes Prozessdatenkommando. |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1798 |
|
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1799 |
Diese Funktion sollte nach Ende des zyklischen Betriebes |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1800 |
aufgerufen werden, um das noch wartende Prozessdaten-Kommando |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1801 |
zu entfernen. |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1802 |
|
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1803 |
@param master EtherCAT-Master |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1804 |
*/ |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1805 |
|
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1806 |
void EtherCAT_clear_process_data(EtherCAT_master_t *master) |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1807 |
{ |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1808 |
if (!master->process_data_command) return; |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1809 |
|
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1810 |
EtherCAT_remove_command(master, master->process_data_command); |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1811 |
EtherCAT_command_clear(master->process_data_command); |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1812 |
master->process_data_command = NULL; |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1813 |
} |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1814 |
|
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1815 |
/***************************************************************/ |
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1816 |
|
b0a7a4745bf9
?nderungen an no_rtai r110:110 in drivers gemergt.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1817 |
/** |
0 | 1818 |
Setzt einen Byte-Wert im Speicher. |
1819 |
||
1820 |
@param data Startadresse |
|
1821 |
@param offset Byte-Offset |
|
1822 |
@param value Wert |
|
1823 |
*/ |
|
1824 |
||
1825 |
void set_byte(unsigned char *data, |
|
1826 |
unsigned int offset, |
|
1827 |
unsigned char value) |
|
1828 |
{ |
|
1829 |
data[offset] = value; |
|
1830 |
} |
|
1831 |
||
1832 |
/***************************************************************/ |
|
1833 |
||
1834 |
/** |
|
1835 |
Setzt einen Word-Wert im Speicher. |
|
1836 |
||
1837 |
@param data Startadresse |
|
1838 |
@param offset Byte-Offset |
|
1839 |
@param value Wert |
|
1840 |
*/ |
|
1841 |
||
1842 |
void set_word(unsigned char *data, |
|
1843 |
unsigned int offset, |
|
1844 |
unsigned int value) |
|
1845 |
{ |
|
1846 |
data[offset] = value & 0xFF; |
|
1847 |
data[offset + 1] = (value & 0xFF00) >> 8; |
|
1848 |
} |
|
1849 |
||
1850 |
/***************************************************************/ |