429 for (dir = EC_DIR_OUTPUT; dir <= EC_DIR_INPUT; dir++) { |
429 for (dir = EC_DIR_OUTPUT; dir <= EC_DIR_INPUT; dir++) { |
430 map = &sc->mapping[dir]; |
430 map = &sc->mapping[dir]; |
431 if (!(sync = ec_slave_get_pdo_sync(sc->slave, dir))) |
431 if (!(sync = ec_slave_get_pdo_sync(sc->slave, dir))) |
432 continue; |
432 continue; |
433 ec_pdo_mapping_copy(map, &sync->mapping); |
433 ec_pdo_mapping_copy(map, &sync->mapping); |
|
434 map->default_mapping = 1; |
|
435 } |
|
436 } |
|
437 |
|
438 /*****************************************************************************/ |
|
439 |
|
440 /** Loads the default configuration for a Pdo from the slave object. |
|
441 */ |
|
442 void ec_slave_config_load_default_pdo_config( |
|
443 const ec_slave_config_t *sc, |
|
444 ec_pdo_t *pdo |
|
445 ) |
|
446 { |
|
447 const ec_sync_t *sync; |
|
448 const ec_pdo_t *default_pdo; |
|
449 |
|
450 pdo->default_config = 1; |
|
451 |
|
452 if (!sc->slave) { |
|
453 EC_WARN("Failed to load default Pdo configuration for %u:%u:" |
|
454 " Slave not found.\n", sc->alias, sc->position); |
|
455 return; |
|
456 } |
|
457 |
|
458 if (!(sync = ec_slave_get_pdo_sync(sc->slave, pdo->dir))) { |
|
459 EC_WARN("Slave %u does not provide a default Pdo" |
|
460 " configuration!\n", sc->slave->ring_position); |
|
461 return; |
|
462 } |
|
463 |
|
464 list_for_each_entry(default_pdo, &sync->mapping.pdos, list) { |
|
465 if (default_pdo->index != pdo->index) |
|
466 continue; |
|
467 |
|
468 if (sc->master->debug_level) |
|
469 EC_DBG(" Found Pdo name \"%s\".\n", |
|
470 default_pdo->name); |
|
471 |
|
472 // try to take Pdo name from mapped one |
|
473 ec_pdo_set_name(pdo, default_pdo->name); |
|
474 |
|
475 // copy entries (= default Pdo configuration) |
|
476 if (ec_pdo_copy_entries(pdo, default_pdo)) |
|
477 return; |
|
478 |
|
479 if (sc->master->debug_level) { |
|
480 const ec_pdo_entry_t *entry; |
|
481 list_for_each_entry(entry, &pdo->entries, list) { |
|
482 EC_DBG(" Entry 0x%04X:%u.\n", |
|
483 entry->index, entry->subindex); |
|
484 } |
|
485 } |
434 } |
486 } |
435 } |
487 } |
436 |
488 |
437 /****************************************************************************** |
489 /****************************************************************************** |
438 * Realtime interface |
490 * Realtime interface |
439 *****************************************************************************/ |
491 *****************************************************************************/ |
440 |
492 |
|
493 int ecrt_slave_config_pdo(ec_slave_config_t *sc, ec_direction_t dir, |
|
494 uint16_t index) |
|
495 { |
|
496 ec_pdo_mapping_t *pm = &sc->mapping[dir]; |
|
497 ec_pdo_t *pdo; |
|
498 |
|
499 if (pm->default_mapping) { |
|
500 pm->default_mapping = 0; |
|
501 ec_pdo_mapping_clear_pdos(pm); |
|
502 } |
|
503 |
|
504 if (!(pdo = ec_pdo_mapping_add_pdo(pm, index, dir))) |
|
505 return -1; |
|
506 |
|
507 ec_slave_config_load_default_pdo_config(sc, pdo); |
|
508 return 0; |
|
509 } |
|
510 |
|
511 /*****************************************************************************/ |
|
512 |
|
513 int ecrt_slave_config_pdo_entry(ec_slave_config_t *sc, uint16_t pdo_index, |
|
514 uint16_t entry_index, uint8_t entry_subindex, |
|
515 uint8_t entry_bit_length) |
|
516 { |
|
517 ec_direction_t dir; |
|
518 ec_pdo_t *pdo; |
|
519 |
|
520 for (dir = EC_DIR_OUTPUT; dir <= EC_DIR_INPUT; dir++) |
|
521 if ((pdo = ec_pdo_mapping_find_pdo(&sc->mapping[dir], pdo_index))) |
|
522 break; |
|
523 |
|
524 if (pdo->default_config) { |
|
525 pdo->default_config = 0; |
|
526 ec_pdo_clear_entries(pdo); |
|
527 } |
|
528 |
|
529 return ec_pdo_add_entry(pdo, entry_index, entry_subindex, |
|
530 entry_bit_length) ? 0 : -1; |
|
531 } |
|
532 |
|
533 /*****************************************************************************/ |
|
534 |
441 int ecrt_slave_config_mapping(ec_slave_config_t *sc, unsigned int n_entries, |
535 int ecrt_slave_config_mapping(ec_slave_config_t *sc, unsigned int n_entries, |
442 const ec_pdo_info_t pdo_infos[]) |
536 const ec_pdo_info_t pdo_infos[]) |
443 { |
537 { |
444 unsigned int i; |
538 unsigned int i; |
445 |
539 const ec_pdo_info_t *pi; |
446 for (i = 0; i < n_entries; i++) |
540 ec_pdo_mapping_t *pm; |
447 if (ec_pdo_mapping_add_pdo_info(&sc->mapping[pdo_infos[i].dir], |
541 ec_pdo_t *pdo; |
448 &pdo_infos[i], sc)) |
542 const ec_pdo_entry_info_t *ei; |
|
543 |
|
544 for (i = 0; i < n_entries; i++) { |
|
545 pi = &pdo_infos[i]; |
|
546 pm = &sc->mapping[pi->dir]; |
|
547 |
|
548 if (pm->default_mapping) { |
|
549 pm->default_mapping = 0; |
|
550 ec_pdo_mapping_clear_pdos(pm); |
|
551 } |
|
552 |
|
553 if (sc->master->debug_level) |
|
554 EC_INFO("Adding Pdo 0x%04X to mapping.\n", pi->index); |
|
555 |
|
556 if (!(pdo = ec_pdo_mapping_add_pdo(pm, pi->dir, pi->index))) |
449 return -1; |
557 return -1; |
|
558 |
|
559 if (pi->n_entries && pi->entries) { // configuration provided |
|
560 if (sc->master->debug_level) |
|
561 EC_DBG(" Pdo configuration information provided.\n"); |
|
562 |
|
563 for (i = 0; i < pi->n_entries; i++) { |
|
564 ei = &pi->entries[i]; |
|
565 if (!ec_pdo_add_entry(pdo, ei->index, ei->subindex, |
|
566 ei->bit_length)) |
|
567 return -1; |
|
568 } |
|
569 } else { // use default Pdo configuration |
|
570 if (sc->master->debug_level) |
|
571 EC_DBG(" Using default Pdo configuration.\n"); |
|
572 ec_slave_config_load_default_pdo_config(sc, pdo); |
|
573 } |
|
574 } |
450 |
575 |
451 return 0; |
576 return 0; |
452 } |
577 } |
453 |
578 |
454 /*****************************************************************************/ |
579 /*****************************************************************************/ |