From 20d8691f5f0a6deef279abf3a231832654c4ccd8 Mon Sep 17 00:00:00 2001 From: Martin Troxler Date: Sun, 14 Mar 2010 20:47:10 +0100 Subject: [PATCH] added API ecrt_master_configured_slaves_state use this function instead of ecrt_master_state() if there are unused slaves on the bus --- include/ecrt.h | 12 ++++++++++++ lib/master.c | 10 ++++++++++ master/cdev.c | 25 +++++++++++++++++++++++++ master/ioctl.h | 1 + master/master.c | 19 +++++++++++++++++++ 5 files changed, 67 insertions(+) diff --git a/include/ecrt.h b/include/ecrt.h index bb5d0990..c774413c 100644 --- a/include/ecrt.h +++ b/include/ecrt.h @@ -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 diff --git a/lib/master.c b/lib/master.c index fba004cd..85edd463 100644 --- a/lib/master.c +++ b/lib/master.c @@ -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; diff --git a/master/cdev.c b/master/cdev.c index 0ca0e99a..c72ff409 100644 --- a/master/cdev.c +++ b/master/cdev.c @@ -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; diff --git a/master/ioctl.h b/master/ioctl.h index e0b621bb..99168cc9 100644 --- a/master/ioctl.h +++ b/master/ioctl.h @@ -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 --git a/master/master.c b/master/master.c index 3b38af0e..8483507b 100644 --- a/master/master.c +++ b/master/master.c @@ -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;