author | Florian Pose <fp@igh-essen.com> |
Tue, 28 Feb 2006 11:14:49 +0000 | |
changeset 92 | a9f92d42cbb0 |
parent 91 | 0120d6214948 |
child 98 | f564d0929292 |
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 |
{ |
31 |
unsigned char data[0xF6]; |
|
73
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
66
diff
changeset
|
32 |
ec_frame_t frame; |
64 | 33 |
unsigned int tries_left, 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; |
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 |
||
89
e91ef35c36db
Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
59 |
ec_frame_init_npwr(&frame, master, slave->station_address, |
e91ef35c36db
Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
60 |
0x1800, 0xF6, data); |
e91ef35c36db
Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
61 |
|
90 | 62 |
if (unlikely(ec_frame_send_receive(&frame))) { |
89
e91ef35c36db
Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
63 |
EC_ERR("Mailbox sending failed on slave %i!\n", slave->ring_position); |
64 | 64 |
return -1; |
65 |
} |
|
66 |
||
67 |
// Read "written bit" of Sync-Manager |
|
68 |
||
69 |
tries_left = 10; |
|
70 |
while (tries_left) |
|
71 |
{ |
|
73
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
66
diff
changeset
|
72 |
ec_frame_init_nprd(&frame, master, slave->station_address, 0x808, 8); |
64 | 73 |
|
89
e91ef35c36db
Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
74 |
if (unlikely(ec_frame_send_receive(&frame) < 0)) { |
e91ef35c36db
Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
75 |
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
|
76 |
slave->ring_position); |
64 | 77 |
return -1; |
78 |
} |
|
79 |
||
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
|
80 |
if (EC_READ_U8(frame.data + 5) & 8) { // Written bit is high |
64 | 81 |
break; |
82 |
} |
|
83 |
||
84 |
udelay(1000); |
|
85 |
tries_left--; |
|
86 |
} |
|
87 |
||
88 |
if (!tries_left) { |
|
84
b4ae98855cea
printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents:
80
diff
changeset
|
89 |
EC_ERR("Mailbox check - Slave %i timed out.\n", slave->ring_position); |
64 | 90 |
return -1; |
91 |
} |
|
92 |
||
73
9f4ea66d89a3
Dynamische FMMU-Konfiguration, zwei Kopieroperationen eingespart, Einr?ckungen angepasst.
Florian Pose <fp@igh-essen.com>
parents:
66
diff
changeset
|
93 |
ec_frame_init_nprd(&frame, master, slave->station_address, 0x18F6, 0xF6); |
64 | 94 |
|
89
e91ef35c36db
Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
95 |
if (unlikely(ec_frame_send_receive(&frame) < 0)) { |
e91ef35c36db
Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
96 |
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
|
97 |
slave->ring_position); |
64 | 98 |
return -1; |
99 |
} |
|
100 |
||
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
|
101 |
if (EC_READ_U8 (frame.data + 5) != 0x03 || // COE |
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
|
102 |
EC_READ_U16(frame.data + 6) != 0x3000 || // SDO response |
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
|
103 |
EC_READ_U8 (frame.data + 8) >> 5 != 0x03 || // Download response |
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
|
104 |
EC_READ_U16(frame.data + 9) != sdo_index || // 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
|
105 |
EC_READ_U8 (frame.data + 11) != sdo_subindex) // Subindex |
64 | 106 |
{ |
84
b4ae98855cea
printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents:
80
diff
changeset
|
107 |
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
|
108 |
slave->ring_position); |
64 | 109 |
return -1; |
110 |
} |
|
111 |
||
112 |
return 0; |
|
113 |
} |
|
114 |
||
115 |
/*****************************************************************************/ |
|
116 |
||
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
117 |
/** |
91
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
118 |
Liest ein CANopen-SDO (service data object). |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
119 |
*/ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
120 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
121 |
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
|
122 |
uint16_t sdo_index, /**< SDO-Index */ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
123 |
uint8_t sdo_subindex, /**< SDO-Subindex */ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
124 |
uint32_t *value /**< Speicher für gel. Wert */ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
125 |
) |
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 |
unsigned char data[0xF6]; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
128 |
ec_frame_t frame; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
129 |
unsigned int tries_left; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
130 |
ec_master_t *master; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
131 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
132 |
memset(data, 0x00, 0xF6); |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
133 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
134 |
master = slave->master; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
135 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
136 |
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
|
137 |
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
|
138 |
EC_WRITE_U8 (data + 4, 0x00); // Channel & priority |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
139 |
EC_WRITE_U8 (data + 5, 0x03); // CANopen over EtherCAT |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
140 |
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
|
141 |
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
|
142 |
EC_WRITE_U16(data + 9, sdo_index); |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
143 |
EC_WRITE_U8 (data + 11, sdo_subindex); |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
144 |
|
89
e91ef35c36db
Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
145 |
ec_frame_init_npwr(&frame, master, slave->station_address, |
e91ef35c36db
Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
146 |
0x1800, 0xF6, data); |
e91ef35c36db
Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
147 |
|
e91ef35c36db
Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
148 |
if (unlikely(ec_frame_send_receive(&frame) < 0)) { |
e91ef35c36db
Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
149 |
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
|
150 |
return -1; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
151 |
} |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
152 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
153 |
// Read "written bit" of Sync-Manager |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
154 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
155 |
tries_left = 10; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
156 |
while (tries_left) |
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 |
ec_frame_init_nprd(&frame, master, slave->station_address, 0x808, 8); |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
159 |
|
89
e91ef35c36db
Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
160 |
if (unlikely(ec_frame_send_receive(&frame) < 0)) { |
e91ef35c36db
Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
161 |
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
|
162 |
slave->ring_position); |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
163 |
return -1; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
164 |
} |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
165 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
166 |
if (EC_READ_U8(frame.data + 5) & 8) { // Written bit is high |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
167 |
break; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
168 |
} |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
169 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
170 |
udelay(1000); |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
171 |
tries_left--; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
172 |
} |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
173 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
174 |
if (!tries_left) { |
84
b4ae98855cea
printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents:
80
diff
changeset
|
175 |
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
|
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 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
179 |
ec_frame_init_nprd(&frame, master, slave->station_address, 0x18F6, 0xF6); |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
180 |
|
89
e91ef35c36db
Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
181 |
if (unlikely(ec_frame_send_receive(&frame) < 0)) { |
e91ef35c36db
Wiederholtes Senden, wenn keine Antwort.
Florian Pose <fp@igh-essen.com>
parents:
84
diff
changeset
|
182 |
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
|
183 |
slave->ring_position); |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
184 |
return -1; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
185 |
} |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
186 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
187 |
if (EC_READ_U8 (frame.data + 5) != 0x03 || // COE |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
188 |
EC_READ_U16(frame.data + 6) != 0x3000 || // SDO response |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
189 |
EC_READ_U8 (frame.data + 8) >> 5 != 0x02 || // Upload response |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
190 |
EC_READ_U16(frame.data + 9) != sdo_index || // Index |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
191 |
EC_READ_U8 (frame.data + 11) != sdo_subindex) // Subindex |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
192 |
{ |
84
b4ae98855cea
printk durch Makros ersetzt.
Florian Pose <fp@igh-essen.com>
parents:
80
diff
changeset
|
193 |
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
|
194 |
slave->ring_position); |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
195 |
return -1; |
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 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
198 |
*value = EC_READ_U32(frame.data + 12); |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
199 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
200 |
return 0; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
201 |
} |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
202 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
203 |
/*****************************************************************************/ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
204 |
|
91
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
205 |
/** |
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
206 |
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
|
207 |
|
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
208 |
Siehe EtherCAT_rt_canopen_sdo_write() |
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
209 |
|
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
210 |
\return 0 wenn alles ok, < 0 bei Fehler |
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
211 |
*/ |
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
212 |
|
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
213 |
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
|
214 |
/**< EtherCAT-Master */ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
215 |
const char *addr, |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
216 |
/**< Addresse, siehe ec_address() */ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
217 |
uint16_t index, |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
218 |
/**< SDO-Index */ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
219 |
uint8_t subindex, |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
220 |
/**< SDO-Subindex */ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
221 |
uint32_t value, |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
222 |
/**< Neuer Wert */ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
223 |
size_t size |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
224 |
/**< Größe des Datenfeldes */ |
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 |
ec_slave_t *slave; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
228 |
if (!(slave = ec_address(master, addr))) return -1; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
229 |
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
|
230 |
} |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
231 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
232 |
/*****************************************************************************/ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
233 |
|
91
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 |
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
|
236 |
|
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
237 |
Siehe EtherCAT_rt_canopen_sdo_read() |
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
238 |
|
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
239 |
\return 0 wenn alles ok, < 0 bei Fehler |
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
240 |
*/ |
0120d6214948
Code-Dokumentation angepasst.
Florian Pose <fp@igh-essen.com>
parents:
90
diff
changeset
|
241 |
|
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
242 |
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
|
243 |
/**< EtherCAT-Slave */ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
244 |
const char *addr, |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
245 |
/**< Addresse, siehe ec_address() */ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
246 |
uint16_t index, |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
247 |
/**< SDO-Index */ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
248 |
uint8_t subindex, |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
249 |
/**< SDO-Subindex */ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
250 |
uint32_t *value |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
251 |
/**< Speicher für gel. Wert */ |
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 |
ec_slave_t *slave; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
255 |
if (!(slave = ec_address(master, addr))) return -1; |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
256 |
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
|
257 |
} |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
258 |
|
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
259 |
/*****************************************************************************/ |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
260 |
|
64 | 261 |
EXPORT_SYMBOL(EtherCAT_rt_canopen_sdo_write); |
80
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
262 |
EXPORT_SYMBOL(EtherCAT_rt_canopen_sdo_read); |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
263 |
EXPORT_SYMBOL(EtherCAT_rt_canopen_sdo_addr_write); |
8cd08d73b560
CANopen SDO read implementiert.
Florian Pose <fp@igh-essen.com>
parents:
77
diff
changeset
|
264 |
EXPORT_SYMBOL(EtherCAT_rt_canopen_sdo_addr_read); |
64 | 265 |
|
266 |
/*****************************************************************************/ |
|
267 |
||
268 |
/* Emacs-Konfiguration |
|
269 |
;;; Local Variables: *** |
|
270 |
;;; c-basic-offset:4 *** |
|
271 |
;;; End: *** |
|
272 |
*/ |