master/master.c
changeset 1077 c95cd717b852
parent 1075 94c6e36e0f8d
child 1078 fce58ba8a912
equal deleted inserted replaced
1076:e62b492aab51 1077:c95cd717b852
  1021     }
  1021     }
  1022 }
  1022 }
  1023 
  1023 
  1024 /*****************************************************************************/
  1024 /*****************************************************************************/
  1025 
  1025 
       
  1026 /** Common implementation for ec_master_find_slave()
       
  1027  * and ec_master_find_slave_const().
       
  1028  */
       
  1029 #define EC_FIND_SLAVE \
       
  1030     do { \
       
  1031         if (alias) { \
       
  1032             for (; slave < master->slaves + master->slave_count; \
       
  1033                     slave++) { \
       
  1034                 if (slave->sii.alias == alias) \
       
  1035                 break; \
       
  1036             } \
       
  1037             if (slave == master->slaves + master->slave_count) \
       
  1038             return NULL; \
       
  1039         } \
       
  1040         \
       
  1041         slave += position; \
       
  1042         if (slave < master->slaves + master->slave_count) { \
       
  1043             return slave; \
       
  1044         } else { \
       
  1045             return NULL; \
       
  1046         } \
       
  1047     } while (0)
       
  1048 
  1026 /** Finds a slave in the bus, given the alias and position.
  1049 /** Finds a slave in the bus, given the alias and position.
  1027  */
  1050  */
  1028 ec_slave_t *ec_master_find_slave(
  1051 ec_slave_t *ec_master_find_slave(
  1029         ec_master_t *master, /**< EtherCAT master. */
  1052         ec_master_t *master, /**< EtherCAT master. */
  1030         uint16_t alias, /**< Slave alias. */
  1053         uint16_t alias, /**< Slave alias. */
  1031         uint16_t position /**< Slave position. */
  1054         uint16_t position /**< Slave position. */
  1032         )
  1055         )
  1033 {
  1056 {
  1034     ec_slave_t *slave = master->slaves;
  1057     ec_slave_t *slave = master->slaves;
  1035 
  1058     EC_FIND_SLAVE;
  1036     if (alias) {
  1059 }
  1037         // find slave with the given alias
  1060 
  1038         for (; slave < master->slaves + master->slave_count;
  1061 /** Finds a slave in the bus, given the alias and position.
  1039                 slave++) {
  1062  *
  1040 			if (slave->sii.alias == alias)
  1063  * Const version.
  1041                 break;
  1064  */
  1042 		}
  1065 const ec_slave_t *ec_master_find_slave_const(
  1043         if (slave == master->slaves + master->slave_count)
  1066         const ec_master_t *master, /**< EtherCAT master. */
  1044             return NULL;
  1067         uint16_t alias, /**< Slave alias. */
  1045 	}
  1068         uint16_t position /**< Slave position. */
  1046 
  1069         )
  1047     slave += position;
  1070 {
  1048     if (slave < master->slaves + master->slave_count) {
  1071     const ec_slave_t *slave = master->slaves;
  1049         return slave;
  1072     EC_FIND_SLAVE;
  1050     } else {
       
  1051         return NULL;
       
  1052     }
       
  1053 }
  1073 }
  1054 
  1074 
  1055 /*****************************************************************************/
  1075 /*****************************************************************************/
  1056 
  1076 
  1057 unsigned int ec_master_config_count(
  1077 unsigned int ec_master_config_count(