equal
deleted
inserted
replaced
3 * c o m m a n d . c |
3 * c o m m a n d . c |
4 * |
4 * |
5 * Methods of an EtherCAT command. |
5 * Methods of an EtherCAT command. |
6 * |
6 * |
7 * $Id$ |
7 * $Id$ |
|
8 * |
|
9 * Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH |
|
10 * |
|
11 * This file is part of the IgH EtherCAT Master. |
|
12 * |
|
13 * The IgH EtherCAT Master is free software; you can redistribute it |
|
14 * and/or modify it under the terms of the GNU General Public License |
|
15 * as published by the Free Software Foundation; version 2 of the License. |
|
16 * |
|
17 * The IgH EtherCAT Master is distributed in the hope that it will be |
|
18 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20 * GNU General Public License for more details. |
|
21 * |
|
22 * You should have received a copy of the GNU General Public License |
|
23 * along with the IgH EtherCAT Master; if not, write to the Free Software |
|
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
8 * |
25 * |
9 *****************************************************************************/ |
26 *****************************************************************************/ |
10 |
27 |
11 #include <linux/slab.h> |
28 #include <linux/slab.h> |
12 #include <linux/delay.h> |
29 #include <linux/delay.h> |
30 |
47 |
31 /*****************************************************************************/ |
48 /*****************************************************************************/ |
32 |
49 |
33 /** |
50 /** |
34 Command constructor. |
51 Command constructor. |
35 */ |
52 \ingroup Command |
36 |
53 */ |
37 void ec_command_init(ec_command_t *command) |
54 |
|
55 void ec_command_init(ec_command_t *command /**< EtherCAT command */) |
38 { |
56 { |
39 command->type = EC_CMD_NONE; |
57 command->type = EC_CMD_NONE; |
40 command->address.logical = 0x00000000; |
58 command->address.logical = 0x00000000; |
41 command->data = NULL; |
59 command->data = NULL; |
42 command->mem_size = 0; |
60 command->mem_size = 0; |
48 |
66 |
49 /*****************************************************************************/ |
67 /*****************************************************************************/ |
50 |
68 |
51 /** |
69 /** |
52 Command destructor. |
70 Command destructor. |
53 */ |
71 \ingroup Command |
54 |
72 */ |
55 void ec_command_clear(ec_command_t *command) |
73 |
|
74 void ec_command_clear(ec_command_t *command /**< EtherCAT command */) |
56 { |
75 { |
57 if (command->data) kfree(command->data); |
76 if (command->data) kfree(command->data); |
58 } |
77 } |
59 |
78 |
60 /*****************************************************************************/ |
79 /*****************************************************************************/ |
61 |
80 |
62 /** |
81 /** |
63 Allocates command data memory. |
82 Allocates command data memory. |
64 \return 0 in case of success, else < 0 |
83 If the allocated memory is already larger than requested, nothing ist done. |
65 */ |
84 \return 0 in case of success, else < 0 |
66 |
85 \ingroup Command |
67 int ec_command_prealloc(ec_command_t *command, size_t size) |
86 */ |
|
87 |
|
88 int ec_command_prealloc(ec_command_t *command, /**< EtherCAT command */ |
|
89 size_t size /**< New size in bytes */ |
|
90 ) |
68 { |
91 { |
69 if (size <= command->mem_size) return 0; |
92 if (size <= command->mem_size) return 0; |
70 |
93 |
71 if (command->data) { |
94 if (command->data) { |
72 kfree(command->data); |
95 kfree(command->data); |
87 |
110 |
88 /** |
111 /** |
89 Initializes an EtherCAT NPRD command. |
112 Initializes an EtherCAT NPRD command. |
90 Node-adressed physical read. |
113 Node-adressed physical read. |
91 \return 0 in case of success, else < 0 |
114 \return 0 in case of success, else < 0 |
|
115 \ingroup Command |
92 */ |
116 */ |
93 |
117 |
94 int ec_command_nprd(ec_command_t *command, |
118 int ec_command_nprd(ec_command_t *command, |
95 /**< EtherCAT command */ |
119 /**< EtherCAT command */ |
96 uint16_t node_address, |
120 uint16_t node_address, |
115 |
139 |
116 /** |
140 /** |
117 Initializes an EtherCAT NPWR command. |
141 Initializes an EtherCAT NPWR command. |
118 Node-adressed physical write. |
142 Node-adressed physical write. |
119 \return 0 in case of success, else < 0 |
143 \return 0 in case of success, else < 0 |
|
144 \ingroup Command |
120 */ |
145 */ |
121 |
146 |
122 int ec_command_npwr(ec_command_t *command, |
147 int ec_command_npwr(ec_command_t *command, |
123 /**< EtherCAT command */ |
148 /**< EtherCAT command */ |
124 uint16_t node_address, |
149 uint16_t node_address, |
143 |
168 |
144 /** |
169 /** |
145 Initializes an EtherCAT APRD command. |
170 Initializes an EtherCAT APRD command. |
146 Autoincrement physical read. |
171 Autoincrement physical read. |
147 \return 0 in case of success, else < 0 |
172 \return 0 in case of success, else < 0 |
|
173 \ingroup Command |
148 */ |
174 */ |
149 |
175 |
150 int ec_command_aprd(ec_command_t *command, |
176 int ec_command_aprd(ec_command_t *command, |
151 /**< EtherCAT command */ |
177 /**< EtherCAT command */ |
152 uint16_t ring_position, |
178 uint16_t ring_position, |
168 |
194 |
169 /** |
195 /** |
170 Initializes an EtherCAT APWR command. |
196 Initializes an EtherCAT APWR command. |
171 Autoincrement physical write. |
197 Autoincrement physical write. |
172 \return 0 in case of success, else < 0 |
198 \return 0 in case of success, else < 0 |
|
199 \ingroup Command |
173 */ |
200 */ |
174 |
201 |
175 int ec_command_apwr(ec_command_t *command, |
202 int ec_command_apwr(ec_command_t *command, |
176 /**< EtherCAT command */ |
203 /**< EtherCAT command */ |
177 uint16_t ring_position, |
204 uint16_t ring_position, |
193 |
220 |
194 /** |
221 /** |
195 Initializes an EtherCAT BRD command. |
222 Initializes an EtherCAT BRD command. |
196 Broadcast read. |
223 Broadcast read. |
197 \return 0 in case of success, else < 0 |
224 \return 0 in case of success, else < 0 |
|
225 \ingroup Command |
198 */ |
226 */ |
199 |
227 |
200 int ec_command_brd(ec_command_t *command, |
228 int ec_command_brd(ec_command_t *command, |
201 /**< EtherCAT command */ |
229 /**< EtherCAT command */ |
202 uint16_t offset, |
230 uint16_t offset, |
216 |
244 |
217 /** |
245 /** |
218 Initializes an EtherCAT BWR command. |
246 Initializes an EtherCAT BWR command. |
219 Broadcast write. |
247 Broadcast write. |
220 \return 0 in case of success, else < 0 |
248 \return 0 in case of success, else < 0 |
|
249 \ingroup Command |
221 */ |
250 */ |
222 |
251 |
223 int ec_command_bwr(ec_command_t *command, |
252 int ec_command_bwr(ec_command_t *command, |
224 /**< EtherCAT command */ |
253 /**< EtherCAT command */ |
225 uint16_t offset, |
254 uint16_t offset, |
239 |
268 |
240 /** |
269 /** |
241 Initializes an EtherCAT LRW command. |
270 Initializes an EtherCAT LRW command. |
242 Logical read write. |
271 Logical read write. |
243 \return 0 in case of success, else < 0 |
272 \return 0 in case of success, else < 0 |
|
273 \ingroup Command |
244 */ |
274 */ |
245 |
275 |
246 int ec_command_lrw(ec_command_t *command, |
276 int ec_command_lrw(ec_command_t *command, |
247 /**< EtherCAT command */ |
277 /**< EtherCAT command */ |
248 uint32_t offset, |
278 uint32_t offset, |