master/master.c
changeset 1000 5746fdd1ca2e
parent 997 652180478e95
child 1004 990b89d8ad03
equal deleted inserted replaced
999:14307580deb6 1000:5746fdd1ca2e
    90 
    90 
    91     master->mode = EC_MASTER_MODE_ORPHANED;
    91     master->mode = EC_MASTER_MODE_ORPHANED;
    92     master->injection_seq_fsm = 0;
    92     master->injection_seq_fsm = 0;
    93     master->injection_seq_rt = 0;
    93     master->injection_seq_rt = 0;
    94 
    94 
    95     INIT_LIST_HEAD(&master->slaves);
    95     master->slaves = NULL;
    96     master->slave_count = 0;
    96     master->slave_count = 0;
    97     
    97     
    98     INIT_LIST_HEAD(&master->configs);
    98     INIT_LIST_HEAD(&master->configs);
    99 
    99 
   100     master->scan_busy = 0;
   100     master->scan_busy = 0;
   243 
   243 
   244 /** Clear all slaves.
   244 /** Clear all slaves.
   245  */
   245  */
   246 void ec_master_clear_slaves(ec_master_t *master)
   246 void ec_master_clear_slaves(ec_master_t *master)
   247 {
   247 {
   248     ec_slave_t *slave, *next;
   248     ec_slave_t *slave;
   249 
   249 
   250     list_for_each_entry_safe(slave, next, &master->slaves, list) {
   250     for (slave = master->slaves;
   251         list_del(&slave->list);
   251             slave < master->slaves + master->slave_count;
       
   252             slave++) {
   252         ec_slave_clear(slave);
   253         ec_slave_clear(slave);
   253         kfree(slave);
   254         kfree(slave);
   254     }
   255     }
   255 
   256 
   256     master->slave_count = 0;
   257     if (master->slave_count) {
       
   258         kfree(master->slaves);
       
   259         master->slaves = NULL;
       
   260         master->slave_count = 0;
       
   261     }
   257 }
   262 }
   258 
   263 
   259 /*****************************************************************************/
   264 /*****************************************************************************/
   260 
   265 
   261 /** Clear all domains.
   266 /** Clear all domains.
   411         if (master->debug_level)
   416         if (master->debug_level)
   412             EC_DBG("Waiting for pending slave scan returned.\n");
   417             EC_DBG("Waiting for pending slave scan returned.\n");
   413     }
   418     }
   414 
   419 
   415     // set states for all slaves
   420     // set states for all slaves
   416     list_for_each_entry(slave, &master->slaves, list) {
   421     for (slave = master->slaves;
       
   422             slave < master->slaves + master->slave_count;
       
   423             slave++) {
   417         ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP);
   424         ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP);
   418     }
   425     }
   419 #ifdef EC_EOE
   426 #ifdef EC_EOE
   420     // ... but set EoE slaves to OP
   427     // ... but set EoE slaves to OP
   421     list_for_each_entry(eoe, &master->eoe_handlers, list) {
   428     list_for_each_entry(eoe, &master->eoe_handlers, list) {
   464     
   471     
   465     ec_master_clear_domains(master);
   472     ec_master_clear_domains(master);
   466     ec_master_clear_slave_configs(master);
   473     ec_master_clear_slave_configs(master);
   467 
   474 
   468     // set states for all slaves
   475     // set states for all slaves
   469     list_for_each_entry(slave, &master->slaves, list) {
   476     for (slave = master->slaves;
       
   477             slave < master->slaves + master->slave_count;
       
   478             slave++) {
   470         ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP);
   479         ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP);
   471     }
   480     }
   472 #ifdef EC_EOE
   481 #ifdef EC_EOE
   473     // ... but leave EoE slaves in OP
   482     // ... but leave EoE slaves in OP
   474     list_for_each_entry(eoe, &master->eoe_handlers, list) {
   483     list_for_each_entry(eoe, &master->eoe_handlers, list) {
  1011         ec_master_t *master, /**< EtherCAT master. */
  1020         ec_master_t *master, /**< EtherCAT master. */
  1012         uint16_t alias, /**< Slave alias. */
  1021         uint16_t alias, /**< Slave alias. */
  1013         uint16_t position /**< Slave position. */
  1022         uint16_t position /**< Slave position. */
  1014         )
  1023         )
  1015 {
  1024 {
  1016     ec_slave_t *slave;
  1025     ec_slave_t *slave = master->slaves;
  1017     unsigned int alias_found = 0, relative_position = 0;
  1026 
  1018 
  1027     if (alias) {
  1019 	list_for_each_entry(slave, &master->slaves, list) {
  1028         // find slave with the given alias
  1020         if (!alias_found) {
  1029         for (; slave < master->slaves + master->slave_count;
  1021 			if (alias && slave->sii.alias != alias)
  1030                 slave++) {
       
  1031 			if (slave->sii.alias != alias)
  1022 				continue;
  1032 				continue;
  1023 			alias_found = 1;
       
  1024 			relative_position = 0;
       
  1025 		}
  1033 		}
  1026 		if (relative_position == position) {
  1034         if (slave == master->slaves + master->slave_count)
  1027             return slave;
  1035             return NULL;
  1028         }
       
  1029 		relative_position++;
       
  1030 	}
  1036 	}
  1031 
  1037 
  1032     return NULL;
  1038     slave += position;
       
  1039     if (slave < master->slaves + master->slave_count) {
       
  1040         return slave;
       
  1041     } else {
       
  1042         return NULL;
       
  1043     }
  1033 }
  1044 }
  1034 
  1045 
  1035 /*****************************************************************************/
  1046 /*****************************************************************************/
  1036 
  1047 
  1037 unsigned int ec_master_config_count(
  1048 unsigned int ec_master_config_count(