Introduced ec_master_find_slave().
This commit is contained in:
parent
85e8f72c68
commit
8b8b470eaa
|
|
@ -1276,6 +1276,35 @@ int ec_master_attach_slave_configs(
|
|||
return errors ? -1 : 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/** Finds a slave in the bus, given the alias and position.
|
||||
*/
|
||||
ec_slave_t *ec_master_find_slave(
|
||||
ec_master_t *master, /**< EtherCAT master. */
|
||||
uint16_t alias, /**< Slave alias. */
|
||||
uint16_t position /**< Slave position. */
|
||||
)
|
||||
{
|
||||
ec_slave_t *slave;
|
||||
unsigned int alias_found = 0, relative_position = 0;
|
||||
|
||||
list_for_each_entry(slave, &master->slaves, list) {
|
||||
if (!alias_found) {
|
||||
if (alias && slave->sii.alias != alias)
|
||||
continue;
|
||||
alias_found = 1;
|
||||
relative_position = 0;
|
||||
}
|
||||
if (relative_position == position) {
|
||||
return slave;
|
||||
}
|
||||
relative_position++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Realtime interface
|
||||
*****************************************************************************/
|
||||
|
|
|
|||
|
|
@ -190,6 +190,7 @@ void ec_master_queue_datagram(ec_master_t *, ec_datagram_t *);
|
|||
|
||||
// misc.
|
||||
int ec_master_attach_slave_configs(ec_master_t *);
|
||||
ec_slave_t *ec_master_find_slave(ec_master_t *, uint16_t, uint16_t);
|
||||
void ec_master_output_stats(ec_master_t *);
|
||||
#ifdef EC_EOE
|
||||
void ec_master_clear_eoe_handlers(ec_master_t *);
|
||||
|
|
|
|||
|
|
@ -333,28 +333,17 @@ int ec_slave_config_attach(
|
|||
)
|
||||
{
|
||||
ec_slave_t *slave;
|
||||
unsigned int alias_found = 0, relative_position = 0;
|
||||
|
||||
if (sc->slave)
|
||||
return 0; // already attached
|
||||
|
||||
list_for_each_entry(slave, &sc->master->slaves, list) {
|
||||
if (!alias_found) {
|
||||
if (sc->alias && slave->sii.alias != sc->alias)
|
||||
continue;
|
||||
alias_found = 1;
|
||||
relative_position = 0;
|
||||
}
|
||||
if (relative_position == sc->position)
|
||||
goto found;
|
||||
relative_position++;
|
||||
}
|
||||
if (!(slave = ec_master_find_slave(
|
||||
sc->master, sc->alias, sc->position))) {
|
||||
EC_WARN("Failed to find slave for configuration %u:%u.\n",
|
||||
sc->alias, sc->position);
|
||||
return -1;
|
||||
}
|
||||
|
||||
EC_WARN("Failed to find slave for configuration %u:%u.\n",
|
||||
sc->alias, sc->position);
|
||||
return -1;
|
||||
|
||||
found:
|
||||
if (slave->config) {
|
||||
EC_ERR("Failed to attach slave configuration %u:%u. Slave %u"
|
||||
" already has a configuration!\n", sc->alias,
|
||||
|
|
|
|||
Loading…
Reference in New Issue