diff -r e62b492aab51 -r c95cd717b852 master/master.c --- a/master/master.c Tue Jul 01 15:41:52 2008 +0000 +++ b/master/master.c Wed Jul 02 08:14:47 2008 +0000 @@ -1023,6 +1023,29 @@ /*****************************************************************************/ +/** Common implementation for ec_master_find_slave() + * and ec_master_find_slave_const(). + */ +#define EC_FIND_SLAVE \ + do { \ + if (alias) { \ + for (; slave < master->slaves + master->slave_count; \ + slave++) { \ + if (slave->sii.alias == alias) \ + break; \ + } \ + if (slave == master->slaves + master->slave_count) \ + return NULL; \ + } \ + \ + slave += position; \ + if (slave < master->slaves + master->slave_count) { \ + return slave; \ + } else { \ + return NULL; \ + } \ + } while (0) + /** Finds a slave in the bus, given the alias and position. */ ec_slave_t *ec_master_find_slave( @@ -1032,24 +1055,21 @@ ) { ec_slave_t *slave = master->slaves; - - if (alias) { - // find slave with the given alias - for (; slave < master->slaves + master->slave_count; - slave++) { - if (slave->sii.alias == alias) - break; - } - if (slave == master->slaves + master->slave_count) - return NULL; - } - - slave += position; - if (slave < master->slaves + master->slave_count) { - return slave; - } else { - return NULL; - } + EC_FIND_SLAVE; +} + +/** Finds a slave in the bus, given the alias and position. + * + * Const version. + */ +const ec_slave_t *ec_master_find_slave_const( + const ec_master_t *master, /**< EtherCAT master. */ + uint16_t alias, /**< Slave alias. */ + uint16_t position /**< Slave position. */ + ) +{ + const ec_slave_t *slave = master->slaves; + EC_FIND_SLAVE; } /*****************************************************************************/