1 /****************************************************************************** |
1 /****************************************************************************** |
2 * |
2 * |
3 * m o d u l e . c |
3 * m o d u l e . c |
4 * |
4 * |
5 * EtherCAT-Master-Treiber |
5 * EtherCAT master driver module. |
6 * |
6 * |
7 * Autoren: Wilhelm Hagemeister, Florian Pose |
7 * Author: Florian Pose <fp@igh-essen.com> |
8 * |
8 * |
9 * $Id$ |
9 * $Id$ |
10 * |
10 * |
11 * (C) Copyright IgH 2005 |
11 * (C) Copyright IgH 2005 |
12 * Ingenieurgemeinschaft IgH |
12 * Ingenieurgemeinschaft IgH |
48 MODULE_DESCRIPTION ("EtherCAT master driver module"); |
48 MODULE_DESCRIPTION ("EtherCAT master driver module"); |
49 MODULE_LICENSE("GPL"); |
49 MODULE_LICENSE("GPL"); |
50 MODULE_VERSION(COMPILE_INFO); |
50 MODULE_VERSION(COMPILE_INFO); |
51 |
51 |
52 module_param(ec_master_count, int, 1); |
52 module_param(ec_master_count, int, 1); |
53 MODULE_PARM_DESC(ec_master_count, "Number of EtherCAT master to initialize."); |
53 MODULE_PARM_DESC(ec_master_count, "number of EtherCAT masters to initialize"); |
54 |
54 |
55 /*****************************************************************************/ |
55 /*****************************************************************************/ |
56 |
56 |
57 /** |
57 /** |
58 Init-Funktion des EtherCAT-Master-Treibermodules |
58 Module initialization. |
59 |
59 Initializes \a ec_master_count masters. |
60 Initialisiert soviele Master, wie im Parameter ec_master_count |
60 \return 0 on success, else < 0 |
61 angegeben wurde (Default ist 1). |
|
62 |
|
63 \return 0 wenn alles ok, < 0 bei ungültiger Anzahl Master |
|
64 oder zu wenig Speicher. |
|
65 */ |
61 */ |
66 |
62 |
67 int __init ec_init_module(void) |
63 int __init ec_init_module(void) |
68 { |
64 { |
69 unsigned int i; |
65 unsigned int i; |
113 } |
109 } |
114 |
110 |
115 /*****************************************************************************/ |
111 /*****************************************************************************/ |
116 |
112 |
117 /** |
113 /** |
118 Cleanup-Funktion des EtherCAT-Master-Treibermoduls |
114 Module cleanup. |
119 |
115 Clears all master instances. |
120 Entfernt alle Master-Instanzen. |
|
121 */ |
116 */ |
122 |
117 |
123 void __exit ec_cleanup_module(void) |
118 void __exit ec_cleanup_module(void) |
124 { |
119 { |
125 ec_master_t *master, *next; |
120 ec_master_t *master, *next; |
140 /** |
135 /** |
141 Gets a handle to a certain master. |
136 Gets a handle to a certain master. |
142 \returns pointer to master |
137 \returns pointer to master |
143 */ |
138 */ |
144 |
139 |
145 ec_master_t *ec_find_master(unsigned int master_index) |
140 ec_master_t *ec_find_master(unsigned int master_index /**< master index */) |
146 { |
141 { |
147 ec_master_t *master; |
142 ec_master_t *master; |
148 |
143 |
149 list_for_each_entry(master, &ec_masters, list) { |
144 list_for_each_entry(master, &ec_masters, list) { |
150 if (master->index == master_index) return master; |
145 if (master->index == master_index) return master; |
153 EC_ERR("Master %i does not exist!\n", master_index); |
148 EC_ERR("Master %i does not exist!\n", master_index); |
154 return NULL; |
149 return NULL; |
155 } |
150 } |
156 |
151 |
157 /****************************************************************************** |
152 /****************************************************************************** |
158 * |
153 * Device interface |
159 * Treiberschnittstelle |
|
160 * |
|
161 *****************************************************************************/ |
154 *****************************************************************************/ |
162 |
155 |
163 /** |
156 /** |
164 Registeriert das EtherCAT-Geraet fuer einen EtherCAT-Master. |
157 Registeres an EtherCAT device for a certain master. |
165 |
158 \return 0 on success, else < 0 |
166 \return 0 wenn alles ok, oder < 0 wenn bereits ein Gerät registriert |
159 */ |
167 oder das Geraet nicht geöffnet werden konnte. |
160 |
168 */ |
161 ec_device_t *ecdev_register(unsigned int master_index, /**< master index */ |
169 |
162 struct net_device *net_dev, /**< net_device of |
170 ec_device_t *ecdev_register(unsigned int master_index, |
163 the device */ |
171 /**< Index des EtherCAT-Masters */ |
164 ec_isr_t isr, /**< interrupt service routine */ |
172 struct net_device *net_dev, |
165 struct module *module /**< pointer to the module */ |
173 /**< net_device des EtherCAT-Gerätes */ |
|
174 ec_isr_t isr, |
|
175 /**< Interrupt-Service-Routine */ |
|
176 struct module *module |
|
177 /**< Zeiger auf das Modul */ |
|
178 ) |
166 ) |
179 { |
167 { |
180 ec_master_t *master; |
168 ec_master_t *master; |
181 |
169 |
182 if (!net_dev) { |
170 if (!net_dev) { |
216 } |
204 } |
217 |
205 |
218 /*****************************************************************************/ |
206 /*****************************************************************************/ |
219 |
207 |
220 /** |
208 /** |
221 Hebt die Registrierung eines EtherCAT-Gerätes auf. |
209 Unregisteres an EtherCAT device. |
222 */ |
210 */ |
223 |
211 |
224 void ecdev_unregister(unsigned int master_index, |
212 void ecdev_unregister(unsigned int master_index, /**< master index */ |
225 /**< Index des EtherCAT-Masters */ |
213 ec_device_t *device /**< EtherCAT device */ |
226 ec_device_t *device |
|
227 /**< EtherCAT-Geraet */ |
|
228 ) |
214 ) |
229 { |
215 { |
230 ec_master_t *master; |
216 ec_master_t *master; |
231 |
217 |
232 if (!(master = ec_find_master(master_index))) return; |
218 if (!(master = ec_find_master(master_index))) return; |
242 } |
228 } |
243 |
229 |
244 /*****************************************************************************/ |
230 /*****************************************************************************/ |
245 |
231 |
246 /** |
232 /** |
247 Starts the master. |
233 Starts the master associated with the device. |
248 */ |
234 */ |
249 |
235 |
250 int ecdev_start(unsigned int master_index |
236 int ecdev_start(unsigned int master_index /**< master index */) |
251 /**< Index des EtherCAT-Masters */ |
|
252 ) |
|
253 { |
237 { |
254 ec_master_t *master; |
238 ec_master_t *master; |
255 if (!(master = ec_find_master(master_index))) return -1; |
239 if (!(master = ec_find_master(master_index))) return -1; |
256 |
240 |
257 if (ec_device_open(master->device)) { |
241 if (ec_device_open(master->device)) { |
264 } |
248 } |
265 |
249 |
266 /*****************************************************************************/ |
250 /*****************************************************************************/ |
267 |
251 |
268 /** |
252 /** |
269 Stops the master. |
253 Stops the master associated with the device. |
270 */ |
254 */ |
271 |
255 |
272 void ecdev_stop(unsigned int master_index |
256 void ecdev_stop(unsigned int master_index /**< master index */) |
273 /**< Index des EtherCAT-Masters */ |
|
274 ) |
|
275 { |
257 { |
276 ec_master_t *master; |
258 ec_master_t *master; |
277 if (!(master = ec_find_master(master_index))) return; |
259 if (!(master = ec_find_master(master_index))) return; |
278 |
260 |
279 ec_master_freerun_stop(master); |
261 ec_master_freerun_stop(master); |
281 if (ec_device_close(master->device)) |
263 if (ec_device_close(master->device)) |
282 EC_WARN("Failed to close device!\n"); |
264 EC_WARN("Failed to close device!\n"); |
283 } |
265 } |
284 |
266 |
285 /****************************************************************************** |
267 /****************************************************************************** |
286 * |
268 * Realtime interface |
287 * Echtzeitschnittstelle |
|
288 * |
|
289 *****************************************************************************/ |
269 *****************************************************************************/ |
290 |
270 |
291 /** |
271 /** |
292 Reserviert einen bestimmten EtherCAT-Master und das zugehörige Gerät. |
272 Reserves an EtherCAT master for realtime operation. |
293 |
273 \return pointer to reserved master, or NULL on error |
294 Gibt einen Zeiger auf den reservierten EtherCAT-Master zurueck. |
|
295 |
|
296 \return Zeiger auf EtherCAT-Master oder NULL, wenn Parameter ungueltig. |
|
297 */ |
274 */ |
298 |
275 |
299 ec_master_t *ecrt_request_master(unsigned int master_index |
276 ec_master_t *ecrt_request_master(unsigned int master_index |
300 /**< EtherCAT-Master-Index */ |
277 /**< master index */ |
301 ) |
278 ) |
302 { |
279 { |
303 ec_master_t *master; |
280 ec_master_t *master; |
304 |
281 |
305 EC_INFO("Requesting master %i...\n", master_index); |
282 EC_INFO("Requesting master %i...\n", master_index); |
349 } |
326 } |
350 |
327 |
351 /*****************************************************************************/ |
328 /*****************************************************************************/ |
352 |
329 |
353 /** |
330 /** |
354 Gibt einen zuvor angeforderten EtherCAT-Master wieder frei. |
331 Releases a reserved EtherCAT master. |
355 */ |
332 */ |
356 |
333 |
357 void ecrt_release_master(ec_master_t *master /**< EtherCAT-Master */) |
334 void ecrt_release_master(ec_master_t *master /**< EtherCAT master */) |
358 { |
335 { |
359 EC_INFO("Releasing master %i...\n", master->index); |
336 EC_INFO("Releasing master %i...\n", master->index); |
360 |
337 |
361 if (!master->reserved) { |
338 if (!master->reserved) { |
362 EC_ERR("Master %i was never requested!\n", master->index); |
339 EC_ERR("Master %i was never requested!\n", master->index); |
376 } |
353 } |
377 |
354 |
378 /*****************************************************************************/ |
355 /*****************************************************************************/ |
379 |
356 |
380 /** |
357 /** |
381 Gibt Frame-Inhalte zwecks Debugging aus. |
358 Outputs frame contents for debugging purposes. |
382 */ |
359 */ |
383 |
360 |
384 void ec_print_data(const uint8_t *data, size_t size) |
361 void ec_print_data(const uint8_t *data, /**< pointer to data */ |
|
362 size_t size /**< number of bytes to output */ |
|
363 ) |
385 { |
364 { |
386 unsigned int i; |
365 unsigned int i; |
387 |
366 |
388 EC_DBG(""); |
367 EC_DBG(""); |
389 for (i = 0; i < size; i++) { |
368 for (i = 0; i < size; i++) { |
397 } |
376 } |
398 |
377 |
399 /*****************************************************************************/ |
378 /*****************************************************************************/ |
400 |
379 |
401 /** |
380 /** |
402 Gibt Frame-Inhalte zwecks Debugging aus, differentiell. |
381 Outputs frame contents and differences for debugging purposes. |
403 */ |
382 */ |
404 |
383 |
405 void ec_print_data_diff(const uint8_t *d1, /**< Daten 1 */ |
384 void ec_print_data_diff(const uint8_t *d1, /**< first data */ |
406 const uint8_t *d2, /**< Daten 2 */ |
385 const uint8_t *d2, /**< second data */ |
407 size_t size /** Anzahl Bytes */ |
386 size_t size /** number of bytes to output */ |
408 ) |
387 ) |
409 { |
388 { |
410 unsigned int i; |
389 unsigned int i; |
411 |
390 |
412 EC_DBG(""); |
391 EC_DBG(""); |
432 EXPORT_SYMBOL(ecdev_stop); |
411 EXPORT_SYMBOL(ecdev_stop); |
433 EXPORT_SYMBOL(ecrt_request_master); |
412 EXPORT_SYMBOL(ecrt_request_master); |
434 EXPORT_SYMBOL(ecrt_release_master); |
413 EXPORT_SYMBOL(ecrt_release_master); |
435 |
414 |
436 /*****************************************************************************/ |
415 /*****************************************************************************/ |
437 |
|
438 /* Emacs-Konfiguration |
|
439 ;;; Local Variables: *** |
|
440 ;;; c-basic-offset:4 *** |
|
441 ;;; End: *** |
|
442 */ |
|