added API ecrt_master_configured_slaves_state

use this function instead of ecrt_master_state() if there are unused slaves on the bus
This commit is contained in:
Martin Troxler 2010-03-14 20:47:10 +01:00
parent 2a30af31c4
commit 20d8691f5f
5 changed files with 67 additions and 0 deletions

View File

@ -748,6 +748,18 @@ void ecrt_master_state(
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

View File

@ -388,6 +388,16 @@ void ecrt_master_state(const ec_master_t *master, ec_master_state_t *state)
/*****************************************************************************/
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;

View File

@ -1811,6 +1811,29 @@ int ec_cdev_ioctl_master_state(
/*****************************************************************************/
/** 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 @@ long eccdev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
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;

View File

@ -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)
/*****************************************************************************/

View File

@ -2296,6 +2296,25 @@ void ecrt_master_state(const ec_master_t *master, ec_master_state_t *state)
/*****************************************************************************/
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;