# HG changeset patch # User Florian Pose # Date 1214986487 0 # Node ID c95cd717b85275659873f20be6ecf062b3da23e4 # Parent e62b492aab51bdc072c37c51abf3e1e4479a144a Added ec_master_find_slave_const(). 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; } /*****************************************************************************/ diff -r e62b492aab51 -r c95cd717b852 master/master.h --- a/master/master.h Tue Jul 01 15:41:52 2008 +0000 +++ b/master/master.h Wed Jul 02 08:14:47 2008 +0000 @@ -190,6 +190,8 @@ // misc. void ec_master_attach_slave_configs(ec_master_t *); ec_slave_t *ec_master_find_slave(ec_master_t *, uint16_t, uint16_t); +const ec_slave_t *ec_master_find_slave_const(const 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 *);