83 ec_datagram_t *datagram /**< Datagram object to use. */ |
83 ec_datagram_t *datagram /**< Datagram object to use. */ |
84 ) |
84 ) |
85 { |
85 { |
86 fsm->master = master; |
86 fsm->master = master; |
87 fsm->datagram = datagram; |
87 fsm->datagram = datagram; |
|
88 fsm->mbox = &master->fsm_mbox; |
88 fsm->state = ec_fsm_master_state_start; |
89 fsm->state = ec_fsm_master_state_start; |
89 fsm->idle = 0; |
90 fsm->idle = 0; |
90 fsm->link_state = 0; |
91 fsm->link_state = 0; |
91 fsm->slaves_responding = 0; |
92 fsm->slaves_responding = 0; |
92 fsm->rescan_required = 0; |
93 fsm->rescan_required = 0; |
93 fsm->slave_states = EC_SLAVE_STATE_UNKNOWN; |
94 fsm->slave_states = EC_SLAVE_STATE_UNKNOWN; |
94 |
95 |
95 // init sub-state-machines |
96 // init sub-state-machines |
96 ec_fsm_coe_init(&fsm->fsm_coe, fsm->datagram); |
97 ec_fsm_coe_init(&fsm->fsm_coe, fsm->mbox); |
97 ec_fsm_pdo_init(&fsm->fsm_pdo, &fsm->fsm_coe); |
98 ec_fsm_pdo_init(&fsm->fsm_pdo, &fsm->fsm_coe); |
98 ec_fsm_change_init(&fsm->fsm_change, fsm->datagram); |
99 ec_fsm_change_init(&fsm->fsm_change, fsm->datagram); |
99 ec_fsm_slave_config_init(&fsm->fsm_slave_config, fsm->datagram, |
100 ec_fsm_slave_config_init(&fsm->fsm_slave_config, fsm->datagram, |
100 &fsm->fsm_change, &fsm->fsm_coe, &fsm->fsm_pdo); |
101 &fsm->fsm_change, &fsm->fsm_coe, &fsm->fsm_pdo); |
101 ec_fsm_slave_scan_init(&fsm->fsm_slave_scan, fsm->datagram, |
102 ec_fsm_slave_scan_init(&fsm->fsm_slave_scan, fsm->datagram, |
131 */ |
132 */ |
132 int ec_fsm_master_exec( |
133 int ec_fsm_master_exec( |
133 ec_fsm_master_t *fsm /**< Master state machine. */ |
134 ec_fsm_master_t *fsm /**< Master state machine. */ |
134 ) |
135 ) |
135 { |
136 { |
136 if (fsm->datagram->state == EC_DATAGRAM_SENT |
137 if (ec_mbox_is_datagram_state(fsm->mbox,EC_DATAGRAM_QUEUED) |
137 || fsm->datagram->state == EC_DATAGRAM_QUEUED) { |
138 || ec_mbox_is_datagram_state(fsm->mbox,EC_DATAGRAM_SENT)) { |
138 // datagram was not sent or received yet. |
139 // datagram was not sent or received yet. |
139 return 0; |
140 return 0; |
140 } |
141 } |
141 |
|
142 fsm->state(fsm); |
142 fsm->state(fsm); |
143 return 1; |
143 return 1; |
144 } |
144 } |
145 |
145 |
146 /*****************************************************************************/ |
146 /*****************************************************************************/ |