author | Florian Pose <fp@igh-essen.com> |
Mon, 06 Mar 2006 16:18:01 +0000 | |
changeset 99 | 72e375b0b308 |
parent 98 | f564d0929292 |
child 101 | b0c19892145a |
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 |
|
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
|
15 |
#include "../include/EtherCAT_si.h" |
64 | 16 |
#include "master.h" |
17 |
||
18 |
/*****************************************************************************/ |
|
19 |
||
73
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
66
diff
changeset
|
20 |
/** |
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
66
diff
changeset
|
21 |
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
|
22 |
*/ |
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
66
diff
changeset
|
23 |
|
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
|
24 |
int EtherCAT_rt_canopen_sdo_write(ec_slave_t *slave, /**< EtherCAT-Slave */ |
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
|
25 |
uint16_t sdo_index, /**< 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
|
26 |
uint8_t sdo_subindex, /**< SDO-Subindex */ |
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
|
27 |
uint32_t value, /**< Neuer Wert */ |
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
|
28 |
size_t size /**< Größe des Datenfeldes */ |
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
|
29 |
) |
64 | 30 |
{ |
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
31 |
uint8_t data[0xF6]; |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
32 |
ec_command_t command; |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
33 |
unsigned int i; |
73
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
66
diff
changeset
|
34 |
ec_master_t *master; |
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
35 |
cycles_t start, end, timeout; |
64 | 36 |
|
73
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
66
diff
changeset
|
37 |
memset(data, 0x00, 0xF6); |
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
66
diff
changeset
|
38 |
|
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
66
diff
changeset
|
39 |
master = slave->master; |
64 | 40 |
|
41 |
if (size == 0 || size > 4) { |
|
84
b4ae98855cea
printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents:
80
diff
changeset
|
42 |
EC_ERR("Illegal SDO data size: %i!\n", size); |
64 | 43 |
return -1; |
44 |
} |
|
45 |
||
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
|
46 |
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
|
47 |
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
|
48 |
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
|
49 |
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
|
50 |
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
|
51 |
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
|
52 |
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
|
53 |
EC_WRITE_U8 (data + 11, sdo_subindex); |
64 | 54 |
|
55 |
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
|
56 |
EC_WRITE_U8(data + 12 + i, value & 0xFF); |
64 | 57 |
value >>= 8; |
58 |
} |
|
59 |
||
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
60 |
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
|
61 |
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
|
62 |
EC_ERR("Mailbox sending failed on slave %i!\n", slave->ring_position); |
64 | 63 |
return -1; |
64 |
} |
|
65 |
||
66 |
// 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
|
67 |
start = get_cycles(); |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
68 |
timeout = cpu_khz; // 1ms |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
69 |
|
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
70 |
do |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
71 |
{ |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
72 |
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
|
73 |
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
|
74 |
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
|
75 |
slave->ring_position); |
64 | 76 |
return -1; |
77 |
} |
|
78 |
||
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
79 |
end = get_cycles(); |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
80 |
|
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
81 |
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
|
82 |
} |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
83 |
while ((end - start) < timeout); |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
84 |
|
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
85 |
if ((end - start) >= timeout) { |
84
b4ae98855cea
printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents:
80
diff
changeset
|
86 |
EC_ERR("Mailbox check - Slave %i timed out.\n", slave->ring_position); |
64 | 87 |
return -1; |
88 |
} |
|
89 |
||
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
90 |
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
|
91 |
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
|
92 |
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
|
93 |
slave->ring_position); |
64 | 94 |
return -1; |
95 |
} |
|
96 |
||
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
97 |
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
|
98 |
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
|
99 |
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
|
100 |
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
|
101 |
EC_READ_U8 (command.data + 11) != sdo_subindex) // Subindex |
64 | 102 |
{ |
84
b4ae98855cea
printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents:
80
diff
changeset
|
103 |
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
|
104 |
slave->ring_position); |
64 | 105 |
return -1; |
106 |
} |
|
107 |
||
108 |
return 0; |
|
109 |
} |
|
110 |
||
111 |
/*****************************************************************************/ |
|
112 |
||
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
113 |
/** |
91
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
114 |
Liest ein CANopen-SDO (service data object). |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
115 |
*/ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
116 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
117 |
int EtherCAT_rt_canopen_sdo_read(ec_slave_t *slave, /**< EtherCAT-Slave */ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
118 |
uint16_t sdo_index, /**< SDO-Index */ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
119 |
uint8_t sdo_subindex, /**< SDO-Subindex */ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
120 |
uint32_t *value /**< Speicher für gel. Wert */ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
121 |
) |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
122 |
{ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
123 |
unsigned char data[0xF6]; |
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
124 |
ec_command_t command; |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
125 |
ec_master_t *master; |
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
126 |
cycles_t start, end, timeout; |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
127 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
128 |
memset(data, 0x00, 0xF6); |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
129 |
master = slave->master; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
130 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
131 |
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
|
132 |
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
|
133 |
EC_WRITE_U8 (data + 4, 0x00); // Channel & priority |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
134 |
EC_WRITE_U8 (data + 5, 0x03); // CANopen over EtherCAT |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
135 |
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
|
136 |
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
|
137 |
EC_WRITE_U16(data + 9, sdo_index); |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
138 |
EC_WRITE_U8 (data + 11, sdo_subindex); |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
139 |
|
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
140 |
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
|
141 |
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
|
142 |
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
|
143 |
return -1; |
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 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
146 |
// Read "written bit" of Sync-Manager |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
147 |
|
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
148 |
start = get_cycles(); |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
149 |
timeout = cpu_khz; // 1ms |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
150 |
|
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
151 |
do |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
152 |
{ |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
153 |
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
|
154 |
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
|
155 |
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
|
156 |
slave->ring_position); |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
157 |
return -1; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
158 |
} |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
159 |
|
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
160 |
end = get_cycles(); |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
161 |
|
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
162 |
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
|
163 |
break; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
164 |
} |
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
165 |
} |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
166 |
while (likely((end - start) < timeout)); |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
167 |
|
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
168 |
if (unlikely((end - start) >= timeout)) { |
84
b4ae98855cea
printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents:
80
diff
changeset
|
169 |
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
|
170 |
return -1; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
171 |
} |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
172 |
|
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
173 |
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
|
174 |
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
|
175 |
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
|
176 |
slave->ring_position); |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
177 |
return -1; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
178 |
} |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
179 |
|
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
180 |
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
|
181 |
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
|
182 |
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
|
183 |
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
|
184 |
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
|
185 |
{ |
84
b4ae98855cea
printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents:
80
diff
changeset
|
186 |
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
|
187 |
slave->ring_position); |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
188 |
return -1; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
189 |
} |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
190 |
|
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
191 |
*value = EC_READ_U32(command.data + 12); |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
192 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
193 |
return 0; |
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 |
/*****************************************************************************/ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
197 |
|
91
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
198 |
/** |
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
199 |
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
|
200 |
|
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
201 |
Siehe EtherCAT_rt_canopen_sdo_write() |
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
202 |
|
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
203 |
\return 0 wenn alles ok, < 0 bei Fehler |
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
204 |
*/ |
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
205 |
|
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
206 |
int EtherCAT_rt_canopen_sdo_addr_write(ec_master_t *master, |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
207 |
/**< EtherCAT-Master */ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
208 |
const char *addr, |
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
209 |
/**< Addresse, siehe |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
210 |
ec_master_slave_address() */ |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
211 |
uint16_t index, |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
212 |
/**< SDO-Index */ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
213 |
uint8_t subindex, |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
214 |
/**< SDO-Subindex */ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
215 |
uint32_t value, |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
216 |
/**< Neuer Wert */ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
217 |
size_t size |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
218 |
/**< Größe des Datenfeldes */ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
219 |
) |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
220 |
{ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
221 |
ec_slave_t *slave; |
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
222 |
if (!(slave = ec_master_slave_address(master, addr))) return -1; |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
223 |
return EtherCAT_rt_canopen_sdo_write(slave, index, subindex, value, size); |
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 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
226 |
/*****************************************************************************/ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
227 |
|
91
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
228 |
/** |
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
229 |
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
|
230 |
|
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
231 |
Siehe EtherCAT_rt_canopen_sdo_read() |
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 |
\return 0 wenn alles ok, < 0 bei Fehler |
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
234 |
*/ |
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
235 |
|
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
236 |
int EtherCAT_rt_canopen_sdo_addr_read(ec_master_t *master, |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
237 |
/**< EtherCAT-Slave */ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
238 |
const char *addr, |
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
239 |
/**< Addresse, siehe |
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
240 |
ec_master_slave_address() */ |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
241 |
uint16_t index, |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
242 |
/**< SDO-Index */ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
243 |
uint8_t subindex, |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
244 |
/**< SDO-Subindex */ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
245 |
uint32_t *value |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
246 |
/**< Speicher für gel. Wert */ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
247 |
) |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
248 |
{ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
249 |
ec_slave_t *slave; |
98
f564d0929292
MERGE branches/async 222:233 -> trunk (Kommando-Warteschlangen).
Florian Pose <fp@igh-essen.com>
parents:
91
diff
changeset
|
250 |
if (!(slave = ec_master_slave_address(master, addr))) return -1; |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
251 |
return EtherCAT_rt_canopen_sdo_read(slave, index, subindex, value); |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
252 |
} |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
253 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
254 |
/*****************************************************************************/ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
255 |
|
64 | 256 |
EXPORT_SYMBOL(EtherCAT_rt_canopen_sdo_write); |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
257 |
EXPORT_SYMBOL(EtherCAT_rt_canopen_sdo_read); |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
258 |
EXPORT_SYMBOL(EtherCAT_rt_canopen_sdo_addr_write); |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
259 |
EXPORT_SYMBOL(EtherCAT_rt_canopen_sdo_addr_read); |
64 | 260 |
|
261 |
/*****************************************************************************/ |
|
262 |
||
263 |
/* Emacs-Konfiguration |
|
264 |
;;; Local Variables: *** |
|
265 |
;;; c-basic-offset:4 *** |
|
266 |
;;; End: *** |
|
267 |
*/ |