218 /*****************************************************************************/ |
218 /*****************************************************************************/ |
219 |
219 |
220 /** Direction type for Pdo assignment functions. |
220 /** Direction type for Pdo assignment functions. |
221 */ |
221 */ |
222 typedef enum { |
222 typedef enum { |
|
223 EC_DIR_INVALID, /**< Invalid direction. Do not use this value. */ |
223 EC_DIR_OUTPUT, /**< Values written by the master. */ |
224 EC_DIR_OUTPUT, /**< Values written by the master. */ |
224 EC_DIR_INPUT /**< Values read by the master. */ |
225 EC_DIR_INPUT, /**< Values read by the master. */ |
|
226 EC_DIR_COUNT /**< Number of directions. For internal use only. */ |
225 } ec_direction_t; |
227 } ec_direction_t; |
226 |
228 |
227 /*****************************************************************************/ |
229 /*****************************************************************************/ |
228 |
230 |
229 /** Pdo entry information. |
231 /** Pdo entry configuration information. |
230 * |
232 * |
231 * This can be used to map multiple Pdo entries into a given Pdo using |
233 * This is the data type of the \a entries field in ec_pdo_info_t. |
232 * ecrt_slave_config_pdos(). |
234 * |
|
235 * \see ecrt_slave_config_sync_managers(). |
233 */ |
236 */ |
234 typedef struct { |
237 typedef struct { |
235 uint16_t index; /**< Index of the Pdo entry to add to the Pdo |
238 uint16_t index; /**< Pdo entry index. */ |
236 mapping. */ |
239 uint8_t subindex; /**< Pdo entry subindex. */ |
237 uint8_t subindex; /**< Subindex of the Pdo entry. */ |
|
238 uint8_t bit_length; /**< Size of the Pdo entry in bit. */ |
240 uint8_t bit_length; /**< Size of the Pdo entry in bit. */ |
239 } ec_pdo_entry_info_t; |
241 } ec_pdo_entry_info_t; |
240 |
242 |
241 /*****************************************************************************/ |
243 /*****************************************************************************/ |
242 |
244 |
243 /** Pdo information. |
245 /** Pdo configuration information. |
244 * |
246 * |
245 * This can be use to assign multiple Pdos to a sync manager using |
247 * This is the data type of the \a pdos field in ec_sync_info_t. |
246 * ecrt_slave_config_pdos(). |
248 * |
|
249 * \see ecrt_slave_config_sync_managers(). |
247 */ |
250 */ |
248 typedef struct { |
251 typedef struct { |
249 ec_direction_t dir; /**< Pdo direction (input/output). */ |
252 uint16_t index; /**< Pdo index. */ |
250 uint16_t index; /**< Index of the Pdo to assign. */ |
253 uint8_t n_entries; /**< Number of Pdo entries in \a entries to map. |
251 unsigned int n_entries; /**< Number of Pdo entries in \a entries to map. |
|
252 Zero means, that the default mapping shall be |
254 Zero means, that the default mapping shall be |
253 used (this can only be done if the slave is |
255 used (this can only be done if the slave is |
254 present at bus configuration time). */ |
256 present at bus configuration time). */ |
255 ec_pdo_entry_info_t *entries; /**< Array of Pdo entries to map. This must |
257 ec_pdo_entry_info_t *entries; /**< Array of Pdo entries to map. Can either |
256 contain at least \a n_entries values. */ |
258 be \a NULL, or must contain at |
|
259 least \a n_entries values. */ |
257 } ec_pdo_info_t; |
260 } ec_pdo_info_t; |
|
261 |
|
262 /*****************************************************************************/ |
|
263 |
|
264 /** Sync manager configuration information. |
|
265 * |
|
266 * This can be use to configure multiple sync managers including the Pdo |
|
267 * assignment and Pdo mapping. It is used as an input parameter type in |
|
268 * ecrt_slave_config_sync_managers(). |
|
269 */ |
|
270 typedef struct { |
|
271 uint8_t index; /**< Sync manager index. */ |
|
272 ec_direction_t dir; /**< Sync manager direction. */ |
|
273 uint16_t n_pdos; /**< Number of Pdos in \a pdos. */ |
|
274 ec_pdo_info_t *pdos; /**< Array with Pdos to assign. This must contain |
|
275 at least \a n_pdos Pdos. */ |
|
276 } ec_sync_info_t; |
258 |
277 |
259 /*****************************************************************************/ |
278 /*****************************************************************************/ |
260 |
279 |
261 /** List record type for Pdo entry mass-registration. |
280 /** List record type for Pdo entry mass-registration. |
262 * |
281 * |
424 |
443 |
425 /****************************************************************************** |
444 /****************************************************************************** |
426 * Slave configuration methods |
445 * Slave configuration methods |
427 *****************************************************************************/ |
446 *****************************************************************************/ |
428 |
447 |
|
448 /** Configure a sync manager. |
|
449 * |
|
450 * Sets the direction of a sync manager. The direction bits from the default |
|
451 * control register from SII will be overriden, when this function is called. |
|
452 * |
|
453 * \return zero on success, else non-zero |
|
454 */ |
|
455 int ecrt_slave_config_sync_manager( |
|
456 ec_slave_config_t *sc, /**< Slave configuration. */ |
|
457 uint8_t sync_index, /**< Sync manager index. */ |
|
458 ec_direction_t dir /**< Input/Output. */ |
|
459 ); |
|
460 |
429 /** Add a Pdo to a sync manager's Pdo assignment. |
461 /** Add a Pdo to a sync manager's Pdo assignment. |
430 * |
462 * |
431 * \see ecrt_slave_config_pdos() |
463 * \see ecrt_slave_config_sync_managers() |
432 * \return zero on success, else non-zero |
464 * \return zero on success, else non-zero |
433 */ |
465 */ |
434 int ecrt_slave_config_pdo_assign_add( |
466 int ecrt_slave_config_pdo_assign_add( |
435 ec_slave_config_t *sc, /**< Slave configuration. */ |
467 ec_slave_config_t *sc, /**< Slave configuration. */ |
436 ec_direction_t dir, /**< Sync manager direction (input/output). */ |
468 uint8_t sync_index, /**< Sync manager index. */ |
437 uint16_t index /**< Index of the Pdo to assign. */ |
469 uint16_t index /**< Index of the Pdo to assign. */ |
438 ); |
470 ); |
439 |
471 |
440 /** Clear a sync manager's Pdo assignment. |
472 /** Clear a sync manager's Pdo assignment. |
441 * |
473 * |
442 * This can be called before assigning Pdos via |
474 * This can be called before assigning Pdos via |
443 * ecrt_slave_config_pdo_assign_add(), to clear the default assignment. |
475 * ecrt_slave_config_pdo_assign_add(), to clear the default assignment of a |
|
476 * sync manager. |
|
477 * |
|
478 * \see ecrt_slave_config_sync_managers() |
444 */ |
479 */ |
445 void ecrt_slave_config_pdo_assign_clear( |
480 void ecrt_slave_config_pdo_assign_clear( |
446 ec_slave_config_t *sc, /**< Slave configuration. */ |
481 ec_slave_config_t *sc, /**< Slave configuration. */ |
447 ec_direction_t dir /**< Sync manager direction (input/output). */ |
482 uint8_t sync_index /**< Sync manager index. */ |
448 ); |
483 ); |
449 |
484 |
450 /** Add a Pdo entry to the given Pdo's mapping. |
485 /** Add a Pdo entry to the given Pdo's mapping. |
451 * |
486 * |
452 * \see ecrt_slave_config_pdos() |
487 * \see ecrt_slave_config_sync_managers() |
453 * \return zero on success, else non-zero |
488 * \return zero on success, else non-zero |
454 */ |
489 */ |
455 int ecrt_slave_config_pdo_mapping_add( |
490 int ecrt_slave_config_pdo_mapping_add( |
456 ec_slave_config_t *sc, /**< Slave configuration. */ |
491 ec_slave_config_t *sc, /**< Slave configuration. */ |
457 uint16_t pdo_index, /**< Index of the Pdo. */ |
492 uint16_t pdo_index, /**< Index of the Pdo. */ |
464 |
499 |
465 /** Clear the mapping of a given Pdo. |
500 /** Clear the mapping of a given Pdo. |
466 * |
501 * |
467 * This can be called before mapping Pdo entries via |
502 * This can be called before mapping Pdo entries via |
468 * ecrt_slave_config_pdo_mapping_add(), to clear the default mapping. |
503 * ecrt_slave_config_pdo_mapping_add(), to clear the default mapping. |
|
504 * |
|
505 * \see ecrt_slave_config_sync_managers() |
469 */ |
506 */ |
470 void ecrt_slave_config_pdo_mapping_clear( |
507 void ecrt_slave_config_pdo_mapping_clear( |
471 ec_slave_config_t *sc, /**< Slave configuration. */ |
508 ec_slave_config_t *sc, /**< Slave configuration. */ |
472 uint16_t pdo_index /**< Index of the Pdo. */ |
509 uint16_t pdo_index /**< Index of the Pdo. */ |
473 ); |
510 ); |
474 |
511 |
475 /** Specify the Pdo assignment and (optionally) the Pdo mappings. |
512 /** Specify a complete Pdo configuration. |
476 * |
513 * |
477 * This function is a convenience wrapper for the functions |
514 * This function is a convenience wrapper for the functions |
478 * ecrt_slave_config_pdo_assign_clear(), ecrt_slave_config_pdo_assign_add(), |
515 * ecrt_slave_config_sync_manager(), ecrt_slave_config_pdo_assign_clear(), |
479 * ecrt_slave_config_pdo_mapping_clear() and |
516 * ecrt_slave_config_pdo_assign_add(), ecrt_slave_config_pdo_mapping_clear() |
480 * ecrt_slave_config_pdo_mapping_add(), that are better suitable for automatic |
517 * and ecrt_slave_config_pdo_mapping_add(), that are better suitable for |
481 * code generation. |
518 * automatic code generation. |
482 * |
519 * |
483 * The following example shows, how to specify a complete Pdo assignment |
520 * The following example shows, how to specify a complete configuration, |
484 * including the Pdo mappings. With this information, the master is able to |
521 * including the Pdo mappings. With this information, the master is able to |
485 * reserve the complete process data, even if the slave is not present at |
522 * reserve the complete process data, even if the slave is not present at |
486 * configuration time: |
523 * configuration time: |
487 * |
524 * |
488 * \code |
525 * \code |
495 * {0x3102, 1, 8}, // status |
532 * {0x3102, 1, 8}, // status |
496 * {0x3102, 2, 16} // value |
533 * {0x3102, 2, 16} // value |
497 * }; |
534 * }; |
498 * |
535 * |
499 * const ec_pdo_info_t el3162_pdos[] = { |
536 * const ec_pdo_info_t el3162_pdos[] = { |
500 * {EC_DIR_INPUT, 0x1A00, 2, el3162_channel1}, |
537 * {0x1A00, 2, el3162_channel1}, |
501 * {EC_DIR_INPUT, 0x1A01, 2, el3162_channel2}, |
538 * {0x1A01, 2, el3162_channel2}, |
502 * }; |
539 * }; |
503 * |
540 * |
504 * if (ecrt_slave_config_pdos(sc, 2, el3162_pdos)) |
541 * const ec_pdo_info_t el3162_syncs[] = { |
|
542 * {2, EC_DIR_INPUT, 2, el3162_el3162_pdos}, |
|
543 * }; |
|
544 * |
|
545 * if (ecrt_slave_config_syncs(sc, 1, el3162_syncs)) |
505 * return -1; // error |
546 * return -1; // error |
506 * \endcode |
547 * \endcode |
507 * |
548 * |
508 * The next example shows, how to configure only the Pdo assignment. The |
549 * The next example shows, how to configure the Pdo assignment only. The |
509 * entries for each assigned Pdo are taken from the Pdo's default mapping. |
550 * entries for each assigned Pdo are taken from the Pdo's default mapping. |
510 * Please note, that Pdo entry registration will fail, if the Pdo |
551 * Please note, that Pdo entry registration will fail, if the Pdo |
511 * configuration is left empty and the slave is offline. |
552 * configuration is left empty and the slave is offline. |
512 * |
553 * |
513 * \code |
554 * \code |
514 * const ec_pdo_info_t pdos[] = { |
555 * const ec_pdo_info_t pdos[] = { |
515 * {EC_DIR_INPUT, 0x1600}, // Channel 1 |
556 * {0x1600}, // Channel 1 |
516 * {EC_DIR_INPUT, 0x1601} // Channel 2 |
557 * {0x1601} // Channel 2 |
517 * }; |
558 * }; |
518 * |
559 * |
519 * if (ecrt_slave_config_pdos(slave_config_ana_in, 2, pdos)) |
560 * const ec_sync_info_t syncs[] = { |
|
561 * {2, EC_DIR_INPUT, 2, pdos}, |
|
562 * }; |
|
563 * |
|
564 * if (ecrt_slave_config_pdos(slave_config_ana_in, 2, syncs)) |
520 * return -1; // error |
565 * return -1; // error |
521 * \endcode |
566 * \endcode |
522 * |
567 * |
523 * Processing of \a pdo_infos will stop, if |
568 * Processing of \a syncs will stop, if |
524 * - the number of processed items reaches \a n_infos, or |
569 * - the number of processed items reaches \a n_syncs, or |
525 * - the \a dir member of an ec_pdo_info_t item is EC_END. In this case, |
570 * - the \a index member of an ec_sync_info_t item is 0xff. In this case, |
526 * \a n_infos should set to a number greater than the number of list items; |
571 * \a n_syncs should set to a number greater than the number of list items; |
527 * using EC_END is recommended. |
572 * using EC_END is recommended. |
528 * |
573 * |
529 * \return zero on success, else non-zero |
574 * \return zero on success, else non-zero |
530 */ |
575 */ |
531 int ecrt_slave_config_pdos( |
576 int ecrt_slave_config_sync_managers( |
532 ec_slave_config_t *sc, /**< Slave configuration. */ |
577 ec_slave_config_t *sc, /**< Slave configuration. */ |
533 unsigned int n_infos, /**< Number of Pdo infos in \a pdo_infos. */ |
578 unsigned int n_syncs, /**< Number of sync manager configurations in |
534 const ec_pdo_info_t pdo_infos[] /**< List with Pdos. */ |
579 \a syncs. */ |
|
580 const ec_sync_info_t syncs[] /**< Array of sync manager |
|
581 configurations. */ |
535 ); |
582 ); |
536 |
583 |
537 /** Registers a Pdo entry for process data exchange in a domain. |
584 /** Registers a Pdo entry for process data exchange in a domain. |
538 * |
585 * |
539 * Searches the assigned Pdos for the given Pdo entry. An error is raised, if |
586 * Searches the assigned Pdos for the given Pdo entry. An error is raised, if |