master/fsm_slave_scan.c
branch1.4-foe
changeset 1711 2b017fcc1c6d
parent 1709 63e4bc918640
equal deleted inserted replaced
1710:4522459bb5a4 1711:2b017fcc1c6d
    46 void ec_fsm_slave_scan_state_base(ec_fsm_slave_scan_t *);
    46 void ec_fsm_slave_scan_state_base(ec_fsm_slave_scan_t *);
    47 void ec_fsm_slave_scan_state_datalink(ec_fsm_slave_scan_t *);
    47 void ec_fsm_slave_scan_state_datalink(ec_fsm_slave_scan_t *);
    48 void ec_fsm_slave_scan_state_sii_size(ec_fsm_slave_scan_t *);
    48 void ec_fsm_slave_scan_state_sii_size(ec_fsm_slave_scan_t *);
    49 void ec_fsm_slave_scan_state_sii_data(ec_fsm_slave_scan_t *);
    49 void ec_fsm_slave_scan_state_sii_data(ec_fsm_slave_scan_t *);
    50 void ec_fsm_slave_scan_state_preop(ec_fsm_slave_scan_t *);
    50 void ec_fsm_slave_scan_state_preop(ec_fsm_slave_scan_t *);
       
    51 void ec_fsm_slave_scan_state_sync(ec_fsm_slave_scan_t *);
    51 void ec_fsm_slave_scan_state_pdos(ec_fsm_slave_scan_t *);
    52 void ec_fsm_slave_scan_state_pdos(ec_fsm_slave_scan_t *);
    52 
    53 
    53 void ec_fsm_slave_scan_state_end(ec_fsm_slave_scan_t *);
    54 void ec_fsm_slave_scan_state_end(ec_fsm_slave_scan_t *);
    54 void ec_fsm_slave_scan_state_error(ec_fsm_slave_scan_t *);
    55 void ec_fsm_slave_scan_state_error(ec_fsm_slave_scan_t *);
    55 
    56 
   584 void ec_fsm_slave_scan_enter_preop(
   585 void ec_fsm_slave_scan_enter_preop(
   585         ec_fsm_slave_scan_t *fsm /**< slave state machine */
   586         ec_fsm_slave_scan_t *fsm /**< slave state machine */
   586         )
   587         )
   587 {
   588 {
   588     ec_slave_t *slave = fsm->slave;
   589     ec_slave_t *slave = fsm->slave;
   589 
   590     uint8_t current_state = slave->current_state & EC_SLAVE_STATE_MASK;
   590     if ((slave->current_state & EC_SLAVE_STATE_MASK) < EC_SLAVE_STATE_PREOP) {
   591 
   591         if (slave->master->debug_level)
   592     if (current_state != EC_SLAVE_STATE_PREOP
   592             EC_DBG("Slave %u is not in the state to do mailbox com, setting"
   593             && current_state != EC_SLAVE_STATE_SAFEOP
   593                     " to PREOP.\n", slave->ring_position);
   594             && current_state != EC_SLAVE_STATE_OP) {
       
   595         if (slave->master->debug_level) {
       
   596             char str[EC_STATE_STRING_SIZE];
       
   597             ec_state_string(current_state, str, 0);
       
   598             EC_DBG("Slave %u is not in the state to do mailbox com (%s),"
       
   599                     " setting to PREOP.\n", slave->ring_position, str);
       
   600         }
       
   601 
   594         fsm->state = ec_fsm_slave_scan_state_preop;
   602         fsm->state = ec_fsm_slave_scan_state_preop;
   595         ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP);
   603         ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP);
   596         ec_fsm_slave_config_start(fsm->fsm_slave_config, slave);
   604         ec_fsm_slave_config_start(fsm->fsm_slave_config, slave);
   597         ec_fsm_slave_config_exec(fsm->fsm_slave_config);
   605         ec_fsm_slave_config_exec(fsm->fsm_slave_config);
   598     } else {
   606     } else {
   599         ec_fsm_slave_scan_enter_pdos(fsm);
   607         if (slave->master->debug_level)
       
   608             EC_DBG("Reading mailbox syncmanager configuration of slave %u.\n",
       
   609                     slave->ring_position);
       
   610 
       
   611         /* Scan current sync manager configuration to get configured mailbox
       
   612          * sizes. */
       
   613         ec_datagram_fprd(fsm->datagram, slave->station_address, 0x0800,
       
   614                 EC_SYNC_PAGE_SIZE * 2);
       
   615         fsm->retries = EC_FSM_RETRIES;
       
   616         fsm->state = ec_fsm_slave_scan_state_sync;
   600     }
   617     }
   601 }
   618 }
   602 
   619 
   603 /*****************************************************************************/
   620 /*****************************************************************************/
   604 
   621 
   612         return;
   629         return;
   613 
   630 
   614     if (!ec_fsm_slave_config_success(fsm->fsm_slave_config)) {
   631     if (!ec_fsm_slave_config_success(fsm->fsm_slave_config)) {
   615         fsm->state = ec_fsm_slave_scan_state_error;
   632         fsm->state = ec_fsm_slave_scan_state_error;
   616         return;
   633         return;
       
   634     }
       
   635 
       
   636     ec_fsm_slave_scan_enter_pdos(fsm);
       
   637 }
       
   638 
       
   639 /*****************************************************************************/
       
   640 
       
   641 /** Slave scan state: SYNC.
       
   642  */
       
   643 void ec_fsm_slave_scan_state_sync(
       
   644         ec_fsm_slave_scan_t *fsm /**< slave state machine */
       
   645         )
       
   646 {
       
   647     ec_datagram_t *datagram = fsm->datagram;
       
   648     ec_slave_t *slave = fsm->slave;
       
   649 
       
   650     if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
       
   651         return;
       
   652 
       
   653     if (datagram->state != EC_DATAGRAM_RECEIVED) {
       
   654         fsm->state = ec_fsm_slave_scan_state_error;
       
   655         EC_ERR("Failed to receive sync manager configuration datagram"
       
   656                 " from slave %u (datagram state %u).\n",
       
   657                slave->ring_position, datagram->state);
       
   658         return;
       
   659     }
       
   660 
       
   661     if (datagram->working_counter != 1) {
       
   662         fsm->slave->error_flag = 1;
       
   663         fsm->state = ec_fsm_slave_scan_state_error;
       
   664         EC_ERR("Failed to read DL status from slave %u: ",
       
   665                slave->ring_position);
       
   666         ec_datagram_print_wc_error(datagram);
       
   667         return;
       
   668     }
       
   669 
       
   670     slave->configured_rx_mailbox_offset = EC_READ_U16(datagram->data);
       
   671     slave->configured_rx_mailbox_size = EC_READ_U16(datagram->data + 2);
       
   672     slave->configured_tx_mailbox_offset = EC_READ_U16(datagram->data + 8);
       
   673     slave->configured_tx_mailbox_size = EC_READ_U16(datagram->data + 10);
       
   674 
       
   675     if (slave->master->debug_level) {
       
   676         EC_DBG("Mailbox configuration of slave %u:\n", slave->ring_position);
       
   677         EC_DBG(" RX offset=0x%04x size=%u\n",
       
   678                 slave->configured_rx_mailbox_offset,
       
   679                 slave->configured_rx_mailbox_size);
       
   680         EC_DBG(" TX offset=0x%04x size=%u\n",
       
   681                 slave->configured_tx_mailbox_offset,
       
   682                 slave->configured_tx_mailbox_size);
   617     }
   683     }
   618 
   684 
   619     ec_fsm_slave_scan_enter_pdos(fsm);
   685     ec_fsm_slave_scan_enter_pdos(fsm);
   620 }
   686 }
   621 
   687