master/fsm_slave_scan.c
changeset 1581 e51cf2af3ff9
parent 1543 373cd456dc26
parent 1579 326d47aa986c
child 1775 576c400d74d5
equal deleted inserted replaced
1578:30f065ea5271 1581:e51cf2af3ff9
    50 void ec_fsm_slave_scan_state_dc_cap(ec_fsm_slave_scan_t *);
    50 void ec_fsm_slave_scan_state_dc_cap(ec_fsm_slave_scan_t *);
    51 void ec_fsm_slave_scan_state_dc_times(ec_fsm_slave_scan_t *);
    51 void ec_fsm_slave_scan_state_dc_times(ec_fsm_slave_scan_t *);
    52 void ec_fsm_slave_scan_state_datalink(ec_fsm_slave_scan_t *);
    52 void ec_fsm_slave_scan_state_datalink(ec_fsm_slave_scan_t *);
    53 void ec_fsm_slave_scan_state_sii_size(ec_fsm_slave_scan_t *);
    53 void ec_fsm_slave_scan_state_sii_size(ec_fsm_slave_scan_t *);
    54 void ec_fsm_slave_scan_state_sii_data(ec_fsm_slave_scan_t *);
    54 void ec_fsm_slave_scan_state_sii_data(ec_fsm_slave_scan_t *);
       
    55 void ec_fsm_slave_scan_state_regalias(ec_fsm_slave_scan_t *);
    55 void ec_fsm_slave_scan_state_preop(ec_fsm_slave_scan_t *);
    56 void ec_fsm_slave_scan_state_preop(ec_fsm_slave_scan_t *);
    56 void ec_fsm_slave_scan_state_sync(ec_fsm_slave_scan_t *);
    57 void ec_fsm_slave_scan_state_sync(ec_fsm_slave_scan_t *);
    57 void ec_fsm_slave_scan_state_pdos(ec_fsm_slave_scan_t *);
    58 void ec_fsm_slave_scan_state_pdos(ec_fsm_slave_scan_t *);
    58 
    59 
    59 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 *);
    60 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 *);
    61 
    62 
    62 void ec_fsm_slave_scan_enter_datalink(ec_fsm_slave_scan_t *);
    63 void ec_fsm_slave_scan_enter_datalink(ec_fsm_slave_scan_t *);
       
    64 void ec_fsm_slave_scan_enter_regalias(ec_fsm_slave_scan_t *);
    63 void ec_fsm_slave_scan_enter_preop(ec_fsm_slave_scan_t *);
    65 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 *);
    66 void ec_fsm_slave_scan_enter_pdos(ec_fsm_slave_scan_t *);
    65 
    67 
    66 /*****************************************************************************/
    68 /*****************************************************************************/
    67 
    69 
   311 
   313 
   312     octet = EC_READ_U8(datagram->data + 7);
   314     octet = EC_READ_U8(datagram->data + 7);
   313     for (i = 0; i < EC_MAX_PORTS; i++) {
   315     for (i = 0; i < EC_MAX_PORTS; i++) {
   314         slave->ports[i].desc = (octet >> (2 * i)) & 0x03;
   316         slave->ports[i].desc = (octet >> (2 * i)) & 0x03;
   315     }
   317     }
   316     
   318 
   317     octet = EC_READ_U8(datagram->data + 8);
   319     octet = EC_READ_U8(datagram->data + 8);
   318     slave->base_fmmu_bit_operation = octet & 0x01;
   320     slave->base_fmmu_bit_operation = octet & 0x01;
   319     slave->base_dc_supported = (octet >> 2) & 0x01;
   321     slave->base_dc_supported = (octet >> 2) & 0x01;
   320     slave->base_dc_range = ((octet >> 3) & 0x01) ? EC_DC_64 : EC_DC_32;
   322     slave->base_dc_range = ((octet >> 3) & 0x01) ? EC_DC_64 : EC_DC_32;
   321 
   323 
   598         ec_fsm_sii_exec(&fsm->fsm_sii); // execute state immediately
   600         ec_fsm_sii_exec(&fsm->fsm_sii); // execute state immediately
   599         return;
   601         return;
   600     }
   602     }
   601 
   603 
   602     // Evaluate SII contents
   604     // Evaluate SII contents
   603     
   605 
   604     ec_slave_clear_sync_managers(slave);
   606     ec_slave_clear_sync_managers(slave);
   605 
   607 
   606     slave->sii.alias =
   608     slave->sii.alias =
   607         EC_READ_U16(slave->sii_words + 0x0004);
   609         EC_READ_U16(slave->sii_words + 0x0004);
   608     slave->sii.vendor_id =
   610     slave->sii.vendor_id =
   709                     slave->ring_position);
   711                     slave->ring_position);
   710             goto end;
   712             goto end;
   711         }
   713         }
   712     }
   714     }
   713 
   715 
       
   716     ec_fsm_slave_scan_enter_regalias(fsm);
       
   717     return;
       
   718 
       
   719 end:
       
   720     EC_ERR("Failed to analyze category data.\n");
       
   721     fsm->slave->error_flag = 1;
       
   722     fsm->state = ec_fsm_slave_scan_state_error;
       
   723 }
       
   724 
       
   725 
       
   726 /*****************************************************************************/
       
   727 
       
   728 /**
       
   729    Slave scan entry function: REGALIAS.
       
   730 */
       
   731 
       
   732 void ec_fsm_slave_scan_enter_regalias(
       
   733         ec_fsm_slave_scan_t *fsm /**< slave state machine */
       
   734         )
       
   735 {
       
   736     ec_datagram_t *datagram = fsm->datagram;
       
   737     ec_slave_t *slave = fsm->slave;
       
   738 
       
   739     // read alias from register 0x0012
       
   740     if (slave->master->debug_level)
       
   741          EC_DBG("Reading alias from register 0x0012 of slave %u.\n",
       
   742                  slave->ring_position);
       
   743     ec_datagram_fprd(datagram, slave->station_address, 0x0012, 2);
       
   744     ec_datagram_zero(datagram);
       
   745     fsm->retries = EC_FSM_RETRIES;
       
   746     fsm->state = ec_fsm_slave_scan_state_regalias;
       
   747 }
       
   748 
       
   749 /*****************************************************************************/
       
   750 
       
   751 /**
       
   752    Slave scan state: REGALIAS.
       
   753 */
       
   754 void ec_fsm_slave_scan_state_regalias(
       
   755         ec_fsm_slave_scan_t *fsm /**< slave state machine */
       
   756 		)
       
   757 {
       
   758     ec_datagram_t *datagram = fsm->datagram;
       
   759     ec_slave_t *slave = fsm->slave;
       
   760 
       
   761     if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
       
   762         return;
       
   763 
       
   764     if (datagram->state != EC_DATAGRAM_RECEIVED) {
       
   765         fsm->state = ec_fsm_slave_scan_state_error;
       
   766         EC_ERR("Failed to receive get reg alias datagram from slave %u"
       
   767                 " (datagram state %u).\n",
       
   768                fsm->slave->ring_position, datagram->state);
       
   769         return;
       
   770     }
       
   771 
       
   772     if (datagram->working_counter != 1) {
       
   773         fsm->slave->error_flag = 1;
       
   774         fsm->state = ec_fsm_slave_scan_state_error;
       
   775         EC_ERR("Failed to read reg alias of slave %u: ",
       
   776                fsm->slave->ring_position);
       
   777         ec_datagram_print_wc_error(datagram);
       
   778         return;
       
   779     }
       
   780 
       
   781     slave->sii.alias = EC_READ_U16(datagram->data);
       
   782     if (slave->master->debug_level)
       
   783          EC_DBG("Alias of slave %u is %u.\n",
       
   784                  slave->ring_position,slave->sii.alias);
       
   785 
   714     if (slave->sii.mailbox_protocols & EC_MBOX_COE) {
   786     if (slave->sii.mailbox_protocols & EC_MBOX_COE) {
   715         ec_fsm_slave_scan_enter_preop(fsm);
   787         ec_fsm_slave_scan_enter_preop(fsm);
   716     } else {
   788     } else {
   717         fsm->state = ec_fsm_slave_scan_state_end;
   789         fsm->state = ec_fsm_slave_scan_state_end;
   718     }
   790     }
   719     return;
       
   720 
       
   721 end:
       
   722     EC_ERR("Failed to analyze category data.\n");
       
   723     fsm->slave->error_flag = 1;
       
   724     fsm->state = ec_fsm_slave_scan_state_error;
       
   725 }
   791 }
   726 
   792 
   727 /*****************************************************************************/
   793 /*****************************************************************************/
   728 
   794 
   729 /** Enter slave scan state PREOP.
   795 /** Enter slave scan state PREOP.