|
1 /****************************************************************************** |
|
2 * |
|
3 * c o m m a n d . c |
|
4 * |
|
5 * Methoden für ein EtherCAT-Kommando. |
|
6 * |
|
7 * $Id$ |
|
8 * |
|
9 *****************************************************************************/ |
|
10 |
|
11 #include <linux/slab.h> |
|
12 #include <linux/delay.h> |
|
13 |
|
14 #include "../include/EtherCAT_si.h" |
|
15 #include "command.h" |
|
16 #include "master.h" |
|
17 |
|
18 /*****************************************************************************/ |
|
19 |
|
20 #define EC_FUNC_HEADER \ |
|
21 command->index = 0; \ |
|
22 command->working_counter = 0; \ |
|
23 command->state = EC_CMD_INIT; |
|
24 |
|
25 #define EC_FUNC_WRITE_FOOTER \ |
|
26 command->data_size = data_size; \ |
|
27 memcpy(command->data, data, data_size); |
|
28 |
|
29 #define EC_FUNC_READ_FOOTER \ |
|
30 command->data_size = data_size; \ |
|
31 memset(command->data, 0x00, data_size); |
|
32 |
|
33 /*****************************************************************************/ |
|
34 |
|
35 /** |
|
36 Initialisiert ein EtherCAT-NPRD-Kommando. |
|
37 |
|
38 Node-adressed physical read. |
|
39 */ |
|
40 |
|
41 void ec_command_init_nprd(ec_command_t *command, |
|
42 /**< EtherCAT-Rahmen */ |
|
43 uint16_t node_address, |
|
44 /**< Adresse des Knotens (Slaves) */ |
|
45 uint16_t offset, |
|
46 /**< Physikalische Speicheradresse im Slave */ |
|
47 size_t data_size |
|
48 /**< Länge der zu lesenden Daten */ |
|
49 ) |
|
50 { |
|
51 if (unlikely(node_address == 0x0000)) |
|
52 EC_WARN("Using node address 0x0000!\n"); |
|
53 |
|
54 EC_FUNC_HEADER; |
|
55 |
|
56 command->type = EC_CMD_NPRD; |
|
57 command->address.physical.slave = node_address; |
|
58 command->address.physical.mem = offset; |
|
59 |
|
60 EC_FUNC_READ_FOOTER; |
|
61 } |
|
62 |
|
63 /*****************************************************************************/ |
|
64 |
|
65 /** |
|
66 Initialisiert ein EtherCAT-NPWR-Kommando. |
|
67 |
|
68 Node-adressed physical write. |
|
69 */ |
|
70 |
|
71 void ec_command_init_npwr(ec_command_t *command, |
|
72 /**< EtherCAT-Rahmen */ |
|
73 uint16_t node_address, |
|
74 /**< Adresse des Knotens (Slaves) */ |
|
75 uint16_t offset, |
|
76 /**< Physikalische Speicheradresse im Slave */ |
|
77 size_t data_size, |
|
78 /**< Länge der zu schreibenden Daten */ |
|
79 const uint8_t *data |
|
80 /**< Zeiger auf Speicher mit zu schreibenden Daten */ |
|
81 ) |
|
82 { |
|
83 if (unlikely(node_address == 0x0000)) |
|
84 EC_WARN("Using node address 0x0000!\n"); |
|
85 |
|
86 EC_FUNC_HEADER; |
|
87 |
|
88 command->type = EC_CMD_NPWR; |
|
89 command->address.physical.slave = node_address; |
|
90 command->address.physical.mem = offset; |
|
91 |
|
92 EC_FUNC_WRITE_FOOTER; |
|
93 } |
|
94 |
|
95 /*****************************************************************************/ |
|
96 |
|
97 /** |
|
98 Initialisiert ein EtherCAT-APRD-Kommando. |
|
99 |
|
100 Autoincrement physical read. |
|
101 */ |
|
102 |
|
103 void ec_command_init_aprd(ec_command_t *command, |
|
104 /**< EtherCAT-Rahmen */ |
|
105 uint16_t ring_position, |
|
106 /**< Position des Slaves im Bus */ |
|
107 uint16_t offset, |
|
108 /**< Physikalische Speicheradresse im Slave */ |
|
109 size_t data_size |
|
110 /**< Länge der zu lesenden Daten */ |
|
111 ) |
|
112 { |
|
113 EC_FUNC_HEADER; |
|
114 |
|
115 command->type = EC_CMD_APRD; |
|
116 command->address.physical.slave = (int16_t) ring_position * (-1); |
|
117 command->address.physical.mem = offset; |
|
118 |
|
119 EC_FUNC_READ_FOOTER; |
|
120 } |
|
121 |
|
122 /*****************************************************************************/ |
|
123 |
|
124 /** |
|
125 Initialisiert ein EtherCAT-APWR-Kommando. |
|
126 |
|
127 Autoincrement physical write. |
|
128 */ |
|
129 |
|
130 void ec_command_init_apwr(ec_command_t *command, |
|
131 /**< EtherCAT-Rahmen */ |
|
132 uint16_t ring_position, |
|
133 /**< Position des Slaves im Bus */ |
|
134 uint16_t offset, |
|
135 /**< Physikalische Speicheradresse im Slave */ |
|
136 size_t data_size, |
|
137 /**< Länge der zu schreibenden Daten */ |
|
138 const uint8_t *data |
|
139 /**< Zeiger auf Speicher mit zu schreibenden Daten */ |
|
140 ) |
|
141 { |
|
142 EC_FUNC_HEADER; |
|
143 |
|
144 command->type = EC_CMD_APWR; |
|
145 command->address.physical.slave = (int16_t) ring_position * (-1); |
|
146 command->address.physical.mem = offset; |
|
147 |
|
148 EC_FUNC_WRITE_FOOTER; |
|
149 } |
|
150 |
|
151 /*****************************************************************************/ |
|
152 |
|
153 /** |
|
154 Initialisiert ein EtherCAT-BRD-Kommando. |
|
155 |
|
156 Broadcast read. |
|
157 */ |
|
158 |
|
159 void ec_command_init_brd(ec_command_t *command, |
|
160 /**< EtherCAT-Rahmen */ |
|
161 uint16_t offset, |
|
162 /**< Physikalische Speicheradresse im Slave */ |
|
163 size_t data_size |
|
164 /**< Länge der zu lesenden Daten */ |
|
165 ) |
|
166 { |
|
167 EC_FUNC_HEADER; |
|
168 |
|
169 command->type = EC_CMD_BRD; |
|
170 command->address.physical.slave = 0x0000; |
|
171 command->address.physical.mem = offset; |
|
172 |
|
173 EC_FUNC_READ_FOOTER; |
|
174 } |
|
175 |
|
176 /*****************************************************************************/ |
|
177 |
|
178 /** |
|
179 Initialisiert ein EtherCAT-BWR-Kommando. |
|
180 |
|
181 Broadcast write. |
|
182 */ |
|
183 |
|
184 void ec_command_init_bwr(ec_command_t *command, |
|
185 /**< EtherCAT-Rahmen */ |
|
186 uint16_t offset, |
|
187 /**< Physikalische Speicheradresse im Slave */ |
|
188 size_t data_size, |
|
189 /**< Länge der zu schreibenden Daten */ |
|
190 const uint8_t *data |
|
191 /**< Zeiger auf Speicher mit zu schreibenden Daten */ |
|
192 ) |
|
193 { |
|
194 EC_FUNC_HEADER; |
|
195 |
|
196 command->type = EC_CMD_BWR; |
|
197 command->address.physical.slave = 0x0000; |
|
198 command->address.physical.mem = offset; |
|
199 |
|
200 EC_FUNC_WRITE_FOOTER; |
|
201 } |
|
202 |
|
203 /*****************************************************************************/ |
|
204 |
|
205 /** |
|
206 Initialisiert ein EtherCAT-LRW-Kommando. |
|
207 |
|
208 Logical read write. |
|
209 */ |
|
210 |
|
211 void ec_command_init_lrw(ec_command_t *command, |
|
212 /**< EtherCAT-Rahmen */ |
|
213 uint32_t offset, |
|
214 /**< Logische Startadresse */ |
|
215 size_t data_size, |
|
216 /**< Länge der zu lesenden/schreibenden Daten */ |
|
217 uint8_t *data |
|
218 /**< Zeiger auf die Daten */ |
|
219 ) |
|
220 { |
|
221 EC_FUNC_HEADER; |
|
222 |
|
223 command->type = EC_CMD_LRW; |
|
224 command->address.logical = offset; |
|
225 |
|
226 EC_FUNC_WRITE_FOOTER; |
|
227 } |
|
228 |
|
229 /*****************************************************************************/ |
|
230 |
|
231 /* Emacs-Konfiguration |
|
232 ;;; Local Variables: *** |
|
233 ;;; c-basic-offset:4 *** |
|
234 ;;; End: *** |
|
235 */ |