52 void ec_fsm_slave_scan_state_state(ec_fsm_slave_scan_t *); |
52 void ec_fsm_slave_scan_state_state(ec_fsm_slave_scan_t *); |
53 void ec_fsm_slave_scan_state_base(ec_fsm_slave_scan_t *); |
53 void ec_fsm_slave_scan_state_base(ec_fsm_slave_scan_t *); |
54 void ec_fsm_slave_scan_state_datalink(ec_fsm_slave_scan_t *); |
54 void ec_fsm_slave_scan_state_datalink(ec_fsm_slave_scan_t *); |
55 void ec_fsm_slave_scan_state_eeprom_size(ec_fsm_slave_scan_t *); |
55 void ec_fsm_slave_scan_state_eeprom_size(ec_fsm_slave_scan_t *); |
56 void ec_fsm_slave_scan_state_eeprom_data(ec_fsm_slave_scan_t *); |
56 void ec_fsm_slave_scan_state_eeprom_data(ec_fsm_slave_scan_t *); |
|
57 void ec_fsm_slave_scan_state_preop(ec_fsm_slave_scan_t *); |
|
58 void ec_fsm_slave_scan_state_pdos(ec_fsm_slave_scan_t *); |
57 |
59 |
58 void ec_fsm_slave_scan_state_end(ec_fsm_slave_scan_t *); |
60 void ec_fsm_slave_scan_state_end(ec_fsm_slave_scan_t *); |
59 void ec_fsm_slave_scan_state_error(ec_fsm_slave_scan_t *); |
61 void ec_fsm_slave_scan_state_error(ec_fsm_slave_scan_t *); |
60 |
62 |
|
63 void ec_fsm_slave_scan_enter_preop(ec_fsm_slave_scan_t *); |
|
64 void ec_fsm_slave_scan_enter_pdos(ec_fsm_slave_scan_t *); |
|
65 |
61 /*****************************************************************************/ |
66 /*****************************************************************************/ |
62 |
67 |
63 /** Constructor. |
68 /** Constructor. |
64 */ |
69 */ |
65 void ec_fsm_slave_scan_init(ec_fsm_slave_scan_t *fsm, /**< slave state machine */ |
70 void ec_fsm_slave_scan_init( |
66 ec_datagram_t *datagram /**< datagram structure to use */ |
71 ec_fsm_slave_scan_t *fsm, /**< Slave scanning state machine. */ |
|
72 ec_datagram_t *datagram, /**< Datagram to use. */ |
|
73 ec_fsm_slave_config_t *fsm_slave_config, /**< Slave configuration |
|
74 state machine to use. */ |
|
75 ec_fsm_coe_map_t *fsm_coe_map /**< Pdo mapping state machine to use. |
|
76 */ |
67 ) |
77 ) |
68 { |
78 { |
69 fsm->datagram = datagram; |
79 fsm->datagram = datagram; |
|
80 fsm->fsm_slave_config = fsm_slave_config; |
|
81 fsm->fsm_coe_map = fsm_coe_map; |
70 |
82 |
71 // init sub state machines |
83 // init sub state machines |
72 ec_fsm_sii_init(&fsm->fsm_sii, fsm->datagram); |
84 ec_fsm_sii_init(&fsm->fsm_sii, fsm->datagram); |
73 } |
85 } |
74 |
86 |
554 slave->ring_position); |
566 slave->ring_position); |
555 goto end; |
567 goto end; |
556 } |
568 } |
557 } |
569 } |
558 |
570 |
559 fsm->state = ec_fsm_slave_scan_state_end; |
571 if (slave->sii_mailbox_protocols & EC_MBOX_COE) { |
|
572 ec_fsm_slave_scan_enter_preop(fsm); |
|
573 } else { |
|
574 fsm->state = ec_fsm_slave_scan_state_end; |
|
575 } |
560 return; |
576 return; |
561 |
577 |
562 end: |
578 end: |
563 EC_ERR("Failed to analyze category data.\n"); |
579 EC_ERR("Failed to analyze category data.\n"); |
564 fsm->slave->error_flag = 1; |
580 fsm->slave->error_flag = 1; |
565 fsm->state = ec_fsm_slave_scan_state_error; |
581 fsm->state = ec_fsm_slave_scan_state_error; |
566 } |
582 } |
567 |
583 |
|
584 /*****************************************************************************/ |
|
585 |
|
586 void ec_fsm_slave_scan_enter_preop( |
|
587 ec_fsm_slave_scan_t *fsm /**< slave state machine */ |
|
588 ) |
|
589 { |
|
590 ec_slave_t *slave = fsm->slave; |
|
591 |
|
592 if ((slave->current_state & EC_SLAVE_STATE_MASK) < EC_SLAVE_STATE_PREOP) { |
|
593 if (slave->master->debug_level) |
|
594 EC_DBG("Slave %u is not in the state to do mailbox com, setting" |
|
595 " to PREOP.\n", slave->ring_position); |
|
596 fsm->state = ec_fsm_slave_scan_state_preop; |
|
597 ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP); |
|
598 ec_fsm_slave_config_start(fsm->fsm_slave_config, slave); |
|
599 ec_fsm_slave_config_exec(fsm->fsm_slave_config); |
|
600 } else { |
|
601 ec_fsm_slave_scan_enter_pdos(fsm); |
|
602 } |
|
603 } |
|
604 |
|
605 /*****************************************************************************/ |
|
606 |
|
607 /** Slave scan state: PREOP. |
|
608 */ |
|
609 void ec_fsm_slave_scan_state_preop( |
|
610 ec_fsm_slave_scan_t *fsm /**< slave state machine */ |
|
611 ) |
|
612 { |
|
613 if (ec_fsm_slave_config_exec(fsm->fsm_slave_config)) |
|
614 return; |
|
615 |
|
616 if (!ec_fsm_slave_config_success(fsm->fsm_slave_config)) { |
|
617 fsm->state = ec_fsm_slave_scan_state_error; |
|
618 return; |
|
619 } |
|
620 |
|
621 ec_fsm_slave_scan_enter_pdos(fsm); |
|
622 } |
|
623 |
|
624 /*****************************************************************************/ |
|
625 |
|
626 void ec_fsm_slave_scan_enter_pdos( |
|
627 ec_fsm_slave_scan_t *fsm /**< slave state machine */ |
|
628 ) |
|
629 { |
|
630 ec_slave_t *slave = fsm->slave; |
|
631 |
|
632 if (slave->master->debug_level) |
|
633 EC_DBG("Scanning Pdo mapping/configuration of slave %u.\n", |
|
634 slave->ring_position); |
|
635 fsm->state = ec_fsm_slave_scan_state_pdos; |
|
636 ec_fsm_coe_map_start(fsm->fsm_coe_map, slave); |
|
637 ec_fsm_coe_map_exec(fsm->fsm_coe_map); // execute immediately |
|
638 } |
|
639 |
|
640 /*****************************************************************************/ |
|
641 |
|
642 /** Slave scan state: PDOS. |
|
643 */ |
|
644 void ec_fsm_slave_scan_state_pdos( |
|
645 ec_fsm_slave_scan_t *fsm /**< slave state machine */ |
|
646 ) |
|
647 { |
|
648 if (ec_fsm_coe_map_exec(fsm->fsm_coe_map)) |
|
649 return; |
|
650 |
|
651 if (!ec_fsm_coe_map_success(fsm->fsm_coe_map)) { |
|
652 fsm->state = ec_fsm_slave_scan_state_error; |
|
653 return; |
|
654 } |
|
655 |
|
656 // fetching of Pdo mapping finished |
|
657 fsm->state = ec_fsm_slave_scan_state_end; |
|
658 } |
|
659 |
568 /****************************************************************************** |
660 /****************************************************************************** |
569 * Common state functions |
661 * Common state functions |
570 *****************************************************************************/ |
662 *****************************************************************************/ |
571 |
663 |
572 /** State: ERROR. |
664 /** State: ERROR. |