--- a/include/ecrt.h Tue Apr 27 13:40:44 2010 +0200
+++ b/include/ecrt.h Thu Apr 29 14:05:15 2010 +0200
@@ -788,6 +788,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
--- a/lib/master.c Tue Apr 27 13:40:44 2010 +0200
+++ b/lib/master.c Thu Apr 29 14:05:15 2010 +0200
@@ -432,6 +432,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;
--- a/master/cdev.c Tue Apr 27 13:40:44 2010 +0200
+++ b/master/cdev.c Thu Apr 29 14:05:15 2010 +0200
@@ -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;
--- a/master/ioctl.h Tue Apr 27 13:40:44 2010 +0200
+++ b/master/ioctl.h Thu Apr 29 14:05:15 2010 +0200
@@ -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)
/*****************************************************************************/
--- a/master/master.c Tue Apr 27 13:40:44 2010 +0200
+++ b/master/master.c Thu Apr 29 14:05:15 2010 +0200
@@ -2316,6 +2316,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;