# HG changeset patch # User Florian Pose # Date 1324032175 -3600 # Node ID f056e31f1a288f217d3efb5861b6f46ca31f6ea6 # Parent 4ef1481573819d92b98560988282b912b7d2c0f9 Read AL status code before acknowledging spontaneous state change. diff -r 4ef148157381 -r f056e31f1a28 master/fsm_change.c --- a/master/fsm_change.c Wed Dec 14 16:47:28 2011 +0100 +++ b/master/fsm_change.c Fri Dec 16 11:42:55 2011 +0100 @@ -49,8 +49,8 @@ void ec_fsm_change_state_start(ec_fsm_change_t *); void ec_fsm_change_state_check(ec_fsm_change_t *); void ec_fsm_change_state_status(ec_fsm_change_t *); +void ec_fsm_change_state_start_code(ec_fsm_change_t *); void ec_fsm_change_state_code(ec_fsm_change_t *); -void ec_fsm_change_state_start_ack(ec_fsm_change_t *); void ec_fsm_change_state_ack(ec_fsm_change_t *); void ec_fsm_change_state_check_ack(ec_fsm_change_t *); void ec_fsm_change_state_end(ec_fsm_change_t *); @@ -111,7 +111,7 @@ fsm->mode = EC_FSM_CHANGE_MODE_ACK_ONLY; fsm->slave = slave; fsm->requested_state = EC_SLAVE_STATE_UNKNOWN; - fsm->state = ec_fsm_change_state_start_ack; + fsm->state = ec_fsm_change_state_start_code; } /*****************************************************************************/ @@ -295,11 +295,8 @@ EC_SLAVE_ERR(slave, "Failed to set %s state, slave refused state" " change (%s).\n", req_state, cur_state); - // fetch AL status error code - ec_datagram_fprd(datagram, slave->station_address, 0x0134, 2); - ec_datagram_zero(datagram); - fsm->retries = EC_FSM_RETRIES; - fsm->state = ec_fsm_change_state_code; + + ec_fsm_change_state_start_code(fsm); return; } @@ -324,6 +321,24 @@ /*****************************************************************************/ +/** Enter reading AL status code. + */ +void ec_fsm_change_state_start_code( + ec_fsm_change_t *fsm /**< finite state machine */ + ) +{ + ec_slave_t *slave = fsm->slave; + ec_datagram_t *datagram = fsm->datagram; + + // fetch AL status error code + ec_datagram_fprd(datagram, slave->station_address, 0x0134, 2); + ec_datagram_zero(datagram); + fsm->retries = EC_FSM_RETRIES; + fsm->state = ec_fsm_change_state_code; +} + +/*****************************************************************************/ + /** Application layer status messages. */ @@ -424,23 +439,8 @@ } // acknowledge "old" slave state - ec_fsm_change_state_start_ack(fsm); // execute immediately -} - -/*****************************************************************************/ - -/** - Change state: START ACK. -*/ - -void ec_fsm_change_state_start_ack(ec_fsm_change_t *fsm - /**< finite state machine */) -{ - ec_slave_t *slave = fsm->slave; - ec_datagram_t *datagram = fsm->datagram; - - ec_datagram_fpwr(datagram, slave->station_address, 0x0120, 2); - EC_WRITE_U16(datagram->data, slave->current_state); + ec_datagram_fpwr(datagram, fsm->slave->station_address, 0x0120, 2); + EC_WRITE_U16(datagram->data, fsm->slave->current_state); fsm->retries = EC_FSM_RETRIES; fsm->state = ec_fsm_change_state_ack; }