# HG changeset patch # User Martin Troxler # Date 1268596030 -3600 # Node ID d9b6e641eaeb89338fd65331c11d4596f77a9c78 # Parent 23d4e121faafad464d3a5eccc1b9774986ad952b added API ecrt_master_configured_slaves_state use this function instead of ecrt_master_state() if there are unused slaves on the bus diff -r 23d4e121faaf -r d9b6e641eaeb include/ecrt.h --- a/include/ecrt.h Thu Mar 11 16:50:27 2010 +0100 +++ b/include/ecrt.h Sun Mar 14 20:47:10 2010 +0100 @@ -748,6 +748,18 @@ ec_master_state_t *state /**< Structure to store the information. */ ); +/** Reads the current master state and the al_state of all configured slaves. + * + * use this function instead of ecrt_master_state if there are unused + * slaves on the bus + * Stores the master state information in the given \a state structure. + * \see ecrt_master_state() + */ +void ecrt_master_configured_slaves_state( + const ec_master_t *master, /**< EtherCAT master. */ + ec_master_state_t *state /**< Structure to store the information. */ + ); + /** Sets the application time. * * The master has to know the application's time when operating slaves with diff -r 23d4e121faaf -r d9b6e641eaeb lib/master.c --- a/lib/master.c Thu Mar 11 16:50:27 2010 +0100 +++ b/lib/master.c Sun Mar 14 20:47:10 2010 +0100 @@ -388,6 +388,16 @@ /*****************************************************************************/ +void ecrt_master_configured_slaves_state(const ec_master_t *master, + ec_master_state_t *state) +{ + if (ioctl(master->fd, EC_IOCTL_MASTER_SC_STATE, state) == -1) { + fprintf(stderr, "Failed to get master state: %s\n", strerror(errno)); + } +} + +/*****************************************************************************/ + void ecrt_master_application_time(ec_master_t *master, uint64_t app_time) { ec_ioctl_app_time_t data; diff -r 23d4e121faaf -r d9b6e641eaeb master/cdev.c --- a/master/cdev.c Thu Mar 11 16:50:27 2010 +0100 +++ b/master/cdev.c Sun Mar 14 20:47:10 2010 +0100 @@ -1811,6 +1811,29 @@ /*****************************************************************************/ +/** Get the master state of all configured slaves. + */ +int ec_cdev_ioctl_master_sc_state( + ec_master_t *master, /**< EtherCAT master. */ + unsigned long arg, /**< ioctl() argument. */ + ec_cdev_priv_t *priv /**< Private data structure of file handle. */ + ) +{ + ec_master_state_t data; + + if (unlikely(!priv->requested)) + return -EPERM; + + ecrt_master_configured_slaves_state(master, &data); + + if (copy_to_user((void __user *) arg, &data, sizeof(data))) + return -EFAULT; + + return 0; +} + +/*****************************************************************************/ + /** Get the master state. */ int ec_cdev_ioctl_app_time( @@ -3672,6 +3695,8 @@ return ec_cdev_ioctl_receive(master, arg, priv); case EC_IOCTL_MASTER_STATE: return ec_cdev_ioctl_master_state(master, arg, priv); + case EC_IOCTL_MASTER_SC_STATE: + return ec_cdev_ioctl_master_sc_state(master, arg, priv); case EC_IOCTL_APP_TIME: if (!(filp->f_mode & FMODE_WRITE)) return -EPERM; diff -r 23d4e121faaf -r d9b6e641eaeb master/ioctl.h --- a/master/ioctl.h Thu Mar 11 16:50:27 2010 +0100 +++ b/master/ioctl.h Sun Mar 14 20:47:10 2010 +0100 @@ -134,6 +134,7 @@ #define EC_IOCTL_VOE_EXEC EC_IOWR(0x44, ec_ioctl_voe_t) #define EC_IOCTL_VOE_DATA EC_IOWR(0x45, ec_ioctl_voe_t) #define EC_IOCTL_SET_SEND_INTERVAL EC_IOW(0x46, size_t) +#define EC_IOCTL_MASTER_SC_STATE EC_IOR(0x47, ec_master_state_t) /*****************************************************************************/ diff -r 23d4e121faaf -r d9b6e641eaeb master/master.c --- a/master/master.c Thu Mar 11 16:50:27 2010 +0100 +++ b/master/master.c Sun Mar 14 20:47:10 2010 +0100 @@ -2296,6 +2296,25 @@ /*****************************************************************************/ +void ecrt_master_configured_slaves_state(const ec_master_t *master, ec_master_state_t *state) +{ + const ec_slave_config_t *sc; + ec_slave_config_state_t sc_state; + + // collect al_states of all configured online slaves + state->al_states = 0; + list_for_each_entry(sc, &master->configs, list) { + ecrt_slave_config_state(sc,&sc_state); + if (sc_state.online) + state->al_states |= sc_state.al_state; + } + + state->slaves_responding = master->fsm.slaves_responding; + state->link_up = master->main_device.link_state; +} + +/*****************************************************************************/ + void ecrt_master_application_time(ec_master_t *master, uint64_t app_time) { master->app_time = app_time;