Reset master state machine when going to orphaned phase.
--- a/master/fsm_master.c Tue Dec 04 11:54:13 2012 +0100
+++ b/master/fsm_master.c Tue Dec 04 11:57:55 2012 +0100
@@ -79,20 +79,10 @@
ec_datagram_t *datagram /**< Datagram object to use. */
)
{
- ec_device_index_t dev_idx;
-
fsm->master = master;
fsm->datagram = datagram;
- fsm->state = ec_fsm_master_state_start;
- fsm->idle = 0;
- fsm->dev_idx = EC_DEVICE_MAIN;
- for (dev_idx = EC_DEVICE_MAIN; dev_idx < ec_master_num_devices(master);
- dev_idx++) {
- fsm->link_state[dev_idx] = 0;
- fsm->slaves_responding[dev_idx] = 0;
- fsm->slave_states[dev_idx] = EC_SLAVE_STATE_UNKNOWN;
- }
- fsm->rescan_required = 0;
+
+ ec_fsm_master_reset(fsm);
// init sub-state-machines
ec_fsm_coe_init(&fsm->fsm_coe, fsm->datagram);
@@ -124,6 +114,30 @@
/*****************************************************************************/
+/** Reset state machine.
+ */
+void ec_fsm_master_reset(
+ ec_fsm_master_t *fsm /**< Master state machine. */
+ )
+{
+ ec_device_index_t dev_idx;
+
+ fsm->state = ec_fsm_master_state_start;
+ fsm->idle = 0;
+ fsm->dev_idx = EC_DEVICE_MAIN;
+
+ for (dev_idx = EC_DEVICE_MAIN;
+ dev_idx < ec_master_num_devices(fsm->master); dev_idx++) {
+ fsm->link_state[dev_idx] = 0;
+ fsm->slaves_responding[dev_idx] = 0;
+ fsm->slave_states[dev_idx] = EC_SLAVE_STATE_UNKNOWN;
+ }
+
+ fsm->rescan_required = 0;
+}
+
+/*****************************************************************************/
+
/** Executes the current state of the state machine.
*
* If the state machine's datagram is not sent or received yet, the execution
@@ -611,8 +625,9 @@
ec_slave_t *slave = fsm->slave;
ec_datagram_t *datagram = fsm->datagram;
- if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
- return;
+ if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
+ return;
+ }
if (datagram->state != EC_DATAGRAM_RECEIVED) {
EC_SLAVE_ERR(slave, "Failed to receive AL state datagram: ");
@@ -747,8 +762,9 @@
ec_master_t *master = fsm->master;
ec_datagram_t *datagram = fsm->datagram;
- if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
- return;
+ if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
+ return;
+ }
if (datagram->state != EC_DATAGRAM_RECEIVED) {
EC_MASTER_ERR(master, "Failed to receive delay measuring datagram"
--- a/master/fsm_master.h Tue Dec 04 11:54:13 2012 +0100
+++ b/master/fsm_master.h Tue Dec 04 11:57:55 2012 +0100
@@ -132,6 +132,8 @@
void ec_fsm_master_init(ec_fsm_master_t *, ec_master_t *, ec_datagram_t *);
void ec_fsm_master_clear(ec_fsm_master_t *);
+void ec_fsm_master_reset(ec_fsm_master_t *);
+
int ec_fsm_master_exec(ec_fsm_master_t *);
int ec_fsm_master_idle(const ec_fsm_master_t *);
--- a/master/master.c Tue Dec 04 11:54:13 2012 +0100
+++ b/master/master.c Tue Dec 04 11:57:55 2012 +0100
@@ -625,6 +625,8 @@
down(&master->master_sem);
ec_master_clear_slaves(master);
up(&master->master_sem);
+
+ ec_fsm_master_reset(&master->fsm);
}
/*****************************************************************************/