author | Florian Pose <fp@igh-essen.com> |
Fri, 17 Mar 2006 16:25:02 +0000 | |
changeset 106 | d6679c77ad3f |
parent 104 | 052bc82d5442 |
child 111 | 9963537ec776 |
permissions | -rw-r--r-- |
64 | 1 |
/****************************************************************************** |
2 |
* |
|
3 |
* c a n o p e n . c |
|
4 |
* |
|
5 |
* CANopen over EtherCAT |
|
6 |
* |
|
7 |
* $Id$ |
|
8 |
* |
|
9 |
*****************************************************************************/ |
|
10 |
||
11 |
#include <linux/delay.h> |
|
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
12 |
#include <linux/slab.h> |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
13 |
#include <linux/module.h> |
64 | 14 |
|
15 |
#include "master.h" |
|
16 |
||
17 |
/*****************************************************************************/ |
|
18 |
||
73
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
66
diff
changeset
|
19 |
/** |
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
66
diff
changeset
|
20 |
Schreibt ein CANopen-SDO (service data object). |
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
66
diff
changeset
|
21 |
*/ |
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
66
diff
changeset
|
22 |
|
104
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
23 |
int ecrt_slave_sdo_write(ec_slave_t *slave, /**< EtherCAT-Slave */ |
101
b0c19892145a
MERGE branches/async -r243:244 -> trunk (intypes).
Florian Pose <fp@igh-essen.com>
parents:
98
diff
changeset
|
24 |
uint16_t sdo_index, /**< SDO-Index */ |
b0c19892145a
MERGE branches/async -r243:244 -> trunk (intypes).
Florian Pose <fp@igh-essen.com>
parents:
98
diff
changeset
|
25 |
uint8_t sdo_subindex, /**< SDO-Subindex */ |
b0c19892145a
MERGE branches/async -r243:244 -> trunk (intypes).
Florian Pose <fp@igh-essen.com>
parents:
98
diff
changeset
|
26 |
uint32_t value, /**< Neuer Wert */ |
b0c19892145a
MERGE branches/async -r243:244 -> trunk (intypes).
Florian Pose <fp@igh-essen.com>
parents:
98
diff
changeset
|
27 |
size_t size /**< Größe des Datenfeldes */ |
b0c19892145a
MERGE branches/async -r243:244 -> trunk (intypes).
Florian Pose <fp@igh-essen.com>
parents:
98
diff
changeset
|
28 |
) |
64 | 29 |
{ |
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
30 |
uint8_t data[0xF6]; |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
31 |
ec_command_t command; |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
32 |
unsigned int i; |
73
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
66
diff
changeset
|
33 |
ec_master_t *master; |
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
34 |
cycles_t start, end, timeout; |
64 | 35 |
|
73
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
66
diff
changeset
|
36 |
memset(data, 0x00, 0xF6); |
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
66
diff
changeset
|
37 |
|
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
66
diff
changeset
|
38 |
master = slave->master; |
64 | 39 |
|
40 |
if (size == 0 || size > 4) { |
|
84
b4ae98855cea
printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents:
80
diff
changeset
|
41 |
EC_ERR("Illegal SDO data size: %i!\n", size); |
64 | 42 |
return -1; |
43 |
} |
|
44 |
||
77
677967864795
EC_READ/WRITE-Makros verwenden Makros aud asm/byteorder.h und werden konsequent verwendet.
Florian Pose <fp@igh-essen.com>
parents:
73
diff
changeset
|
45 |
EC_WRITE_U16(data, 0x000A); // Length of the Mailbox service data |
677967864795
EC_READ/WRITE-Makros verwenden Makros aud asm/byteorder.h und werden konsequent verwendet.
Florian Pose <fp@igh-essen.com>
parents:
73
diff
changeset
|
46 |
EC_WRITE_U16(data + 2, slave->station_address); // Station address |
677967864795
EC_READ/WRITE-Makros verwenden Makros aud asm/byteorder.h und werden konsequent verwendet.
Florian Pose <fp@igh-essen.com>
parents:
73
diff
changeset
|
47 |
EC_WRITE_U8 (data + 4, 0x00); // Channel & priority |
677967864795
EC_READ/WRITE-Makros verwenden Makros aud asm/byteorder.h und werden konsequent verwendet.
Florian Pose <fp@igh-essen.com>
parents:
73
diff
changeset
|
48 |
EC_WRITE_U8 (data + 5, 0x03); // CANopen over EtherCAT |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
49 |
EC_WRITE_U16(data + 6, 0x2000); // Number (0), Service (SDO request) |
77
677967864795
EC_READ/WRITE-Makros verwenden Makros aud asm/byteorder.h und werden konsequent verwendet.
Florian Pose <fp@igh-essen.com>
parents:
73
diff
changeset
|
50 |
EC_WRITE_U8 (data + 8, 0x13 | ((4 - size) << 2)); // Spec., exp., init. |
677967864795
EC_READ/WRITE-Makros verwenden Makros aud asm/byteorder.h und werden konsequent verwendet.
Florian Pose <fp@igh-essen.com>
parents:
73
diff
changeset
|
51 |
EC_WRITE_U16(data + 9, sdo_index); |
677967864795
EC_READ/WRITE-Makros verwenden Makros aud asm/byteorder.h und werden konsequent verwendet.
Florian Pose <fp@igh-essen.com>
parents:
73
diff
changeset
|
52 |
EC_WRITE_U8 (data + 11, sdo_subindex); |
64 | 53 |
|
54 |
for (i = 0; i < size; i++) { |
|
77
677967864795
EC_READ/WRITE-Makros verwenden Makros aud asm/byteorder.h und werden konsequent verwendet.
Florian Pose <fp@igh-essen.com>
parents:
73
diff
changeset
|
55 |
EC_WRITE_U8(data + 12 + i, value & 0xFF); |
64 | 56 |
value >>= 8; |
57 |
} |
|
58 |
||
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
59 |
ec_command_init_npwr(&command, slave->station_address, 0x1800, 0xF6, data); |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
60 |
if (unlikely(ec_master_simple_io(master, &command))) { |
89
e91ef35c36db
Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
61 |
EC_ERR("Mailbox sending failed on slave %i!\n", slave->ring_position); |
64 | 62 |
return -1; |
63 |
} |
|
64 |
||
65 |
// Read "written bit" of Sync-Manager |
|
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
66 |
start = get_cycles(); |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
67 |
timeout = cpu_khz; // 1ms |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
68 |
|
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
69 |
do |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
70 |
{ |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
71 |
ec_command_init_nprd(&command, slave->station_address, 0x808, 8); |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
72 |
if (unlikely(ec_master_simple_io(master, &command))) { |
89
e91ef35c36db
Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
73 |
EC_ERR("Mailbox checking failed on slave %i!\n", |
84
b4ae98855cea
printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents:
80
diff
changeset
|
74 |
slave->ring_position); |
64 | 75 |
return -1; |
76 |
} |
|
77 |
||
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
78 |
end = get_cycles(); |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
79 |
|
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
80 |
if (EC_READ_U8(command.data + 5) & 8) break; // Written bit is high |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
81 |
} |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
82 |
while ((end - start) < timeout); |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
83 |
|
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
84 |
if ((end - start) >= timeout) { |
84
b4ae98855cea
printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents:
80
diff
changeset
|
85 |
EC_ERR("Mailbox check - Slave %i timed out.\n", slave->ring_position); |
64 | 86 |
return -1; |
87 |
} |
|
88 |
||
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
89 |
ec_command_init_nprd(&command, slave->station_address, 0x18F6, 0xF6); |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
90 |
if (unlikely(ec_master_simple_io(master, &command))) { |
89
e91ef35c36db
Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
91 |
EC_ERR("Mailbox receiving failed on slave %i!\n", |
84
b4ae98855cea
printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents:
80
diff
changeset
|
92 |
slave->ring_position); |
64 | 93 |
return -1; |
94 |
} |
|
95 |
||
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
96 |
if (EC_READ_U8 (command.data + 5) != 0x03 || // COE |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
97 |
EC_READ_U16(command.data + 6) != 0x3000 || // SDO response |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
98 |
EC_READ_U8 (command.data + 8) >> 5 != 0x03 || // Download response |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
99 |
EC_READ_U16(command.data + 9) != sdo_index || // Index |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
100 |
EC_READ_U8 (command.data + 11) != sdo_subindex) // Subindex |
64 | 101 |
{ |
84
b4ae98855cea
printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents:
80
diff
changeset
|
102 |
EC_ERR("Illegal mailbox response at slave %i!\n", |
73
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
66
diff
changeset
|
103 |
slave->ring_position); |
64 | 104 |
return -1; |
105 |
} |
|
106 |
||
107 |
return 0; |
|
108 |
} |
|
109 |
||
110 |
/*****************************************************************************/ |
|
111 |
||
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
112 |
/** |
91
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
113 |
Liest ein CANopen-SDO (service data object). |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
114 |
*/ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
115 |
|
104
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
116 |
int ecrt_slave_sdo_read(ec_slave_t *slave, /**< EtherCAT-Slave */ |
101
b0c19892145a
MERGE branches/async -r243:244 -> trunk (intypes).
Florian Pose <fp@igh-essen.com>
parents:
98
diff
changeset
|
117 |
uint16_t sdo_index, /**< SDO-Index */ |
b0c19892145a
MERGE branches/async -r243:244 -> trunk (intypes).
Florian Pose <fp@igh-essen.com>
parents:
98
diff
changeset
|
118 |
uint8_t sdo_subindex, /**< SDO-Subindex */ |
b0c19892145a
MERGE branches/async -r243:244 -> trunk (intypes).
Florian Pose <fp@igh-essen.com>
parents:
98
diff
changeset
|
119 |
uint32_t *value /**< Speicher für gel. Wert */ |
b0c19892145a
MERGE branches/async -r243:244 -> trunk (intypes).
Florian Pose <fp@igh-essen.com>
parents:
98
diff
changeset
|
120 |
) |
b0c19892145a
MERGE branches/async -r243:244 -> trunk (intypes).
Florian Pose <fp@igh-essen.com>
parents:
98
diff
changeset
|
121 |
{ |
b0c19892145a
MERGE branches/async -r243:244 -> trunk (intypes).
Florian Pose <fp@igh-essen.com>
parents:
98
diff
changeset
|
122 |
uint8_t data[0xF6]; |
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
123 |
ec_command_t command; |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
124 |
ec_master_t *master; |
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
125 |
cycles_t start, end, timeout; |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
126 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
127 |
memset(data, 0x00, 0xF6); |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
128 |
master = slave->master; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
129 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
130 |
EC_WRITE_U16(data, 0x0006); // Length of the Mailbox service data |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
131 |
EC_WRITE_U16(data + 2, slave->station_address); // Station address |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
132 |
EC_WRITE_U8 (data + 4, 0x00); // Channel & priority |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
133 |
EC_WRITE_U8 (data + 5, 0x03); // CANopen over EtherCAT |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
134 |
EC_WRITE_U16(data + 6, 0x2000); // Number (0), Service (SDO request) |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
135 |
EC_WRITE_U8 (data + 8, 0x1 << 1 | 0x2 << 5); // Exp., Upload request |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
136 |
EC_WRITE_U16(data + 9, sdo_index); |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
137 |
EC_WRITE_U8 (data + 11, sdo_subindex); |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
138 |
|
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
139 |
ec_command_init_npwr(&command, slave->station_address, 0x1800, 0xF6, data); |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
140 |
if (unlikely(ec_master_simple_io(master, &command))) { |
89
e91ef35c36db
Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
141 |
EC_ERR("Mailbox sending failed on slave %i!\n", slave->ring_position); |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
142 |
return -1; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
143 |
} |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
144 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
145 |
// Read "written bit" of Sync-Manager |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
146 |
|
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
147 |
start = get_cycles(); |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
148 |
timeout = cpu_khz; // 1ms |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
149 |
|
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
150 |
do |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
151 |
{ |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
152 |
ec_command_init_nprd(&command, slave->station_address, 0x808, 8); |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
153 |
if (unlikely(ec_master_simple_io(master, &command))) { |
89
e91ef35c36db
Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
154 |
EC_ERR("Mailbox checking failed on slave %i!\n", |
84
b4ae98855cea
printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents:
80
diff
changeset
|
155 |
slave->ring_position); |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
156 |
return -1; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
157 |
} |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
158 |
|
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
159 |
end = get_cycles(); |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
160 |
|
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
161 |
if (EC_READ_U8(command.data + 5) & 8) { // Written bit is high |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
162 |
break; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
163 |
} |
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
164 |
} |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
165 |
while (likely((end - start) < timeout)); |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
166 |
|
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
167 |
if (unlikely((end - start) >= timeout)) { |
84
b4ae98855cea
printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents:
80
diff
changeset
|
168 |
EC_ERR("Mailbox check - Slave %i timed out.\n", slave->ring_position); |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
169 |
return -1; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
170 |
} |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
171 |
|
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
172 |
ec_command_init_nprd(&command, slave->station_address, 0x18F6, 0xF6); |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
173 |
if (unlikely(ec_master_simple_io(master, &command))) { |
89
e91ef35c36db
Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
174 |
EC_ERR("Mailbox receiving failed on slave %i!\n", |
84
b4ae98855cea
printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents:
80
diff
changeset
|
175 |
slave->ring_position); |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
176 |
return -1; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
177 |
} |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
178 |
|
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
179 |
if (EC_READ_U8 (command.data + 5) != 0x03 || // COE |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
180 |
EC_READ_U16(command.data + 6) != 0x3000 || // SDO response |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
181 |
EC_READ_U8 (command.data + 8) >> 5 != 0x02 || // Upload response |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
182 |
EC_READ_U16(command.data + 9) != sdo_index || // Index |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
183 |
EC_READ_U8 (command.data + 11) != sdo_subindex) // Subindex |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
184 |
{ |
84
b4ae98855cea
printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents:
80
diff
changeset
|
185 |
EC_ERR("Illegal mailbox response at slave %i!\n", |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
186 |
slave->ring_position); |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
187 |
return -1; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
188 |
} |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
189 |
|
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
190 |
*value = EC_READ_U32(command.data + 12); |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
191 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
192 |
return 0; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
193 |
} |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
194 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
195 |
/*****************************************************************************/ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
196 |
|
91
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
197 |
/** |
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
198 |
Schweibt ein CANopen-SDO (Variante mit Angabe des Masters und der Adresse). |
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
199 |
|
104
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
200 |
Siehe ecrt_slave_sdo_write() |
91
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
201 |
|
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
202 |
\return 0 wenn alles ok, < 0 bei Fehler |
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
203 |
*/ |
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
204 |
|
104
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
205 |
int ecrt_master_sdo_write(ec_master_t *master, |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
206 |
/**< EtherCAT-Master */ |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
207 |
const char *addr, |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
208 |
/**< Addresse, siehe ec_master_slave_address() */ |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
209 |
uint16_t index, |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
210 |
/**< SDO-Index */ |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
211 |
uint8_t subindex, |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
212 |
/**< SDO-Subindex */ |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
213 |
uint32_t value, |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
214 |
/**< Neuer Wert */ |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
215 |
size_t size |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
216 |
/**< Größe des Datenfeldes */ |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
217 |
) |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
218 |
{ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
219 |
ec_slave_t *slave; |
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
220 |
if (!(slave = ec_master_slave_address(master, addr))) return -1; |
104
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
221 |
return ecrt_slave_sdo_write(slave, index, subindex, value, size); |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
222 |
} |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
223 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
224 |
/*****************************************************************************/ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
225 |
|
91
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
226 |
/** |
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
227 |
Liest ein CANopen-SDO (Variante mit Angabe des Masters und der Adresse). |
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
228 |
|
104
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
229 |
Siehe ecrt_slave_sdo_read() |
91
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
230 |
|
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
231 |
\return 0 wenn alles ok, < 0 bei Fehler |
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
232 |
*/ |
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
233 |
|
104
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
234 |
int ecrt_master_sdo_read(ec_master_t *master, |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
235 |
/**< EtherCAT-Slave */ |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
236 |
const char *addr, |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
237 |
/**< Addresse, siehe ec_master_slave_address() */ |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
238 |
uint16_t index, |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
239 |
/**< SDO-Index */ |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
240 |
uint8_t subindex, |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
241 |
/**< SDO-Subindex */ |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
242 |
uint32_t *value |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
243 |
/**< Speicher für gel. Wert */ |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
244 |
) |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
245 |
{ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
246 |
ec_slave_t *slave; |
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
247 |
if (!(slave = ec_master_slave_address(master, addr))) return -1; |
104
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
248 |
return ecrt_slave_sdo_read(slave, index, subindex, value); |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
249 |
} |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
250 |
|
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
251 |
/*****************************************************************************/ |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
252 |
|
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
253 |
EXPORT_SYMBOL(ecrt_slave_sdo_write); |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
254 |
EXPORT_SYMBOL(ecrt_slave_sdo_read); |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
255 |
EXPORT_SYMBOL(ecrt_master_sdo_write); |
052bc82d5442
MERGE branches/async -> trunk (alle Unterschiede ?bernommen)
Florian Pose <fp@igh-essen.com>
parents:
101
diff
changeset
|
256 |
EXPORT_SYMBOL(ecrt_master_sdo_read); |
64 | 257 |
|
258 |
/*****************************************************************************/ |
|
259 |
||
260 |
/* Emacs-Konfiguration |
|
261 |
;;; Local Variables: *** |
|
262 |
;;; c-basic-offset:4 *** |
|
263 |
;;; End: *** |
|
264 |
*/ |