master/fsm_slave_scan.c
changeset 1995 7d748d9cf9e8
parent 1958 7dceb43bd855
child 2044 1ae0491b2f6b
child 2498 9cdd7669dc0b
equal deleted inserted replaced
1994:b369f3f92eb8 1995:7d748d9cf9e8
    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 #ifdef EC_REGALIAS
    55 void ec_fsm_slave_scan_state_regalias(ec_fsm_slave_scan_t *);
    56 void ec_fsm_slave_scan_state_regalias(ec_fsm_slave_scan_t *);
       
    57 #endif
    56 void ec_fsm_slave_scan_state_preop(ec_fsm_slave_scan_t *);
    58 void ec_fsm_slave_scan_state_preop(ec_fsm_slave_scan_t *);
    57 void ec_fsm_slave_scan_state_sync(ec_fsm_slave_scan_t *);
    59 void ec_fsm_slave_scan_state_sync(ec_fsm_slave_scan_t *);
    58 void ec_fsm_slave_scan_state_pdos(ec_fsm_slave_scan_t *);
    60 void ec_fsm_slave_scan_state_pdos(ec_fsm_slave_scan_t *);
    59 
    61 
    60 void ec_fsm_slave_scan_state_end(ec_fsm_slave_scan_t *);
    62 void ec_fsm_slave_scan_state_end(ec_fsm_slave_scan_t *);
    61 void ec_fsm_slave_scan_state_error(ec_fsm_slave_scan_t *);
    63 void ec_fsm_slave_scan_state_error(ec_fsm_slave_scan_t *);
    62 
    64 
    63 void ec_fsm_slave_scan_enter_datalink(ec_fsm_slave_scan_t *);
    65 void ec_fsm_slave_scan_enter_datalink(ec_fsm_slave_scan_t *);
       
    66 #ifdef EC_REGALIAS
    64 void ec_fsm_slave_scan_enter_regalias(ec_fsm_slave_scan_t *);
    67 void ec_fsm_slave_scan_enter_regalias(ec_fsm_slave_scan_t *);
       
    68 #endif
    65 void ec_fsm_slave_scan_enter_preop(ec_fsm_slave_scan_t *);
    69 void ec_fsm_slave_scan_enter_preop(ec_fsm_slave_scan_t *);
    66 void ec_fsm_slave_scan_enter_pdos(ec_fsm_slave_scan_t *);
    70 void ec_fsm_slave_scan_enter_pdos(ec_fsm_slave_scan_t *);
    67 
    71 
    68 /*****************************************************************************/
    72 /*****************************************************************************/
    69 
    73 
   492 void ec_fsm_slave_scan_state_sii_size(ec_fsm_slave_scan_t *fsm /**< slave state machine */)
   496 void ec_fsm_slave_scan_state_sii_size(ec_fsm_slave_scan_t *fsm /**< slave state machine */)
   493 {
   497 {
   494     ec_slave_t *slave = fsm->slave;
   498     ec_slave_t *slave = fsm->slave;
   495     uint16_t cat_type, cat_size;
   499     uint16_t cat_type, cat_size;
   496 
   500 
   497     if (ec_fsm_sii_exec(&fsm->fsm_sii)) return;
   501     if (ec_fsm_sii_exec(&fsm->fsm_sii))
       
   502         return;
   498 
   503 
   499     if (!ec_fsm_sii_success(&fsm->fsm_sii)) {
   504     if (!ec_fsm_sii_success(&fsm->fsm_sii)) {
   500         fsm->slave->error_flag = 1;
   505         fsm->slave->error_flag = 1;
   501         fsm->state = ec_fsm_slave_scan_state_error;
   506         fsm->state = ec_fsm_slave_scan_state_error;
   502         EC_SLAVE_ERR(slave, "Failed to read SII size.\n");
   507         EC_SLAVE_ERR(slave, "Failed to determine SII content size:"
   503         return;
   508                 " Reading word offset 0x%04x failed. Assuming %u words.\n",
       
   509                 fsm->sii_offset, EC_FIRST_SII_CATEGORY_OFFSET);
       
   510         slave->sii_nwords = EC_FIRST_SII_CATEGORY_OFFSET;
       
   511         goto alloc_sii;
   504     }
   512     }
   505 
   513 
   506     cat_type = EC_READ_U16(fsm->fsm_sii.value);
   514     cat_type = EC_READ_U16(fsm->fsm_sii.value);
   507     cat_size = EC_READ_U16(fsm->fsm_sii.value + 2);
   515     cat_size = EC_READ_U16(fsm->fsm_sii.value + 2);
   508 
   516 
   692                     " Next category header missing.\n");
   700                     " Next category header missing.\n");
   693             goto end;
   701             goto end;
   694         }
   702         }
   695     }
   703     }
   696 
   704 
       
   705 #ifdef EC_REGALIAS
   697     ec_fsm_slave_scan_enter_regalias(fsm);
   706     ec_fsm_slave_scan_enter_regalias(fsm);
       
   707 #else
       
   708     if (slave->sii.mailbox_protocols & EC_MBOX_COE) {
       
   709         ec_fsm_slave_scan_enter_preop(fsm);
       
   710     } else {
       
   711         fsm->state = ec_fsm_slave_scan_state_end;
       
   712     }
       
   713 #endif
   698     return;
   714     return;
   699 
   715 
   700 end:
   716 end:
   701     EC_SLAVE_ERR(slave, "Failed to analyze category data.\n");
   717     EC_SLAVE_ERR(slave, "Failed to analyze category data.\n");
   702     fsm->slave->error_flag = 1;
   718     fsm->slave->error_flag = 1;
   703     fsm->state = ec_fsm_slave_scan_state_error;
   719     fsm->state = ec_fsm_slave_scan_state_error;
   704 }
   720 }
   705 
   721 
   706 
   722 /*****************************************************************************/
   707 /*****************************************************************************/
   723 
   708 
   724 #ifdef EC_REGALIAS
   709 /**
   725 
   710    Slave scan entry function: REGALIAS.
   726 /** Slave scan entry function: REGALIAS.
   711 */
   727  */
   712 
       
   713 void ec_fsm_slave_scan_enter_regalias(
   728 void ec_fsm_slave_scan_enter_regalias(
   714         ec_fsm_slave_scan_t *fsm /**< slave state machine */
   729         ec_fsm_slave_scan_t *fsm /**< slave state machine */
   715         )
   730         )
   716 {
   731 {
   717     ec_datagram_t *datagram = fsm->datagram;
   732     ec_datagram_t *datagram = fsm->datagram;
   725     fsm->state = ec_fsm_slave_scan_state_regalias;
   740     fsm->state = ec_fsm_slave_scan_state_regalias;
   726 }
   741 }
   727 
   742 
   728 /*****************************************************************************/
   743 /*****************************************************************************/
   729 
   744 
   730 /**
   745 /** Slave scan state: REGALIAS.
   731    Slave scan state: REGALIAS.
   746  */
   732 */
       
   733 void ec_fsm_slave_scan_state_regalias(
   747 void ec_fsm_slave_scan_state_regalias(
   734         ec_fsm_slave_scan_t *fsm /**< slave state machine */
   748         ec_fsm_slave_scan_t *fsm /**< slave state machine */
   735         )
   749         )
   736 {
   750 {
   737     ec_datagram_t *datagram = fsm->datagram;
   751     ec_datagram_t *datagram = fsm->datagram;
   752     } else {
   766     } else {
   753         slave->effective_alias = EC_READ_U16(datagram->data);
   767         slave->effective_alias = EC_READ_U16(datagram->data);
   754         EC_SLAVE_DBG(slave, 1, "Read alias %u from register.\n",
   768         EC_SLAVE_DBG(slave, 1, "Read alias %u from register.\n",
   755                 slave->effective_alias);
   769                 slave->effective_alias);
   756     }
   770     }
       
   771 
   757     if (slave->sii.mailbox_protocols & EC_MBOX_COE) {
   772     if (slave->sii.mailbox_protocols & EC_MBOX_COE) {
   758         ec_fsm_slave_scan_enter_preop(fsm);
   773         ec_fsm_slave_scan_enter_preop(fsm);
   759     } else {
   774     } else {
   760         fsm->state = ec_fsm_slave_scan_state_end;
   775         fsm->state = ec_fsm_slave_scan_state_end;
   761     }
   776     }
   762 }
   777 }
       
   778 
       
   779 #endif // defined EC_REGALIAS
   763 
   780 
   764 /*****************************************************************************/
   781 /*****************************************************************************/
   765 
   782 
   766 /** Enter slave scan state PREOP.
   783 /** Enter slave scan state PREOP.
   767  */
   784  */