Creating slave configurations.
--- a/examples/user/main.c Thu Oct 02 10:44:43 2008 +0000
+++ b/examples/user/main.c Thu Oct 02 10:45:40 2008 +0000
@@ -12,6 +12,7 @@
{
ec_master_t *master;
ec_domain_t *domain;
+ ec_slave_config_t *sc;
master = ecrt_request_master(0);
if (!master)
@@ -21,6 +22,10 @@
if (!domain)
return -1;
+ sc = ecrt_master_slave_config(master, 0, 0, 0x00000002, 0x044C2C52);
+ if (!sc)
+ return -1;
+
while (1) {
sleep(1);
}
--- a/lib/Makefile.am Thu Oct 02 10:44:43 2008 +0000
+++ b/lib/Makefile.am Thu Oct 02 10:45:40 2008 +0000
@@ -45,6 +45,7 @@
noinst_HEADERS = \
domain.h \
- master.h
+ master.h \
+ slave_config.h
#------------------------------------------------------------------------------
--- a/lib/master.c Thu Oct 02 10:44:43 2008 +0000
+++ b/lib/master.c Thu Oct 02 10:45:40 2008 +0000
@@ -39,6 +39,7 @@
#include "master.h"
#include "domain.h"
+#include "slave_config.h"
#include "master/ioctl.h"
/*****************************************************************************/
@@ -71,7 +72,30 @@
uint16_t alias, uint16_t position, uint32_t vendor_id,
uint32_t product_code)
{
- return 0;
+ ec_ioctl_config_t data;
+ ec_slave_config_t *sc;
+ int index;
+
+ sc = malloc(sizeof(ec_slave_config_t));
+ if (!sc) {
+ fprintf(stderr, "Failed to allocate memory.\n");
+ return 0;
+ }
+
+ data.alias = alias;
+ data.position = position;
+ data.vendor_id = vendor_id;
+ data.product_code = product_code;
+
+ if (ioctl(master->fd, EC_IOCTL_CREATE_SLAVE_CONFIG, &data) == -1) {
+ fprintf(stderr, "Failed to create slave config: %s\n",
+ strerror(errno));
+ free(sc);
+ return 0;
+ }
+
+ sc->index = data.config_index;
+ return sc;
}
/*****************************************************************************/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/slave_config.h Thu Oct 02 10:45:40 2008 +0000
@@ -0,0 +1,42 @@
+/******************************************************************************
+ *
+ * $Id$
+ *
+ * Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH
+ *
+ * This file is part of the IgH EtherCAT Master.
+ *
+ * The IgH EtherCAT Master is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * The IgH EtherCAT Master is distributed in the hope that it will be
+ * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with the IgH EtherCAT Master; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * The right to use EtherCAT Technology is granted and comes free of
+ * charge under condition of compatibility of product made by
+ * Licensee. People intending to distribute/sell products based on the
+ * code, have to sign an agreement to guarantee that products using
+ * software based on IgH EtherCAT master stay compatible with the actual
+ * EtherCAT specification (which are released themselves as an open
+ * standard) as the (only) precondition to have the right to use EtherCAT
+ * Technology, IP and trade marks.
+ *
+ *****************************************************************************/
+
+#include "include/ecrt.h"
+
+/*****************************************************************************/
+
+struct ec_slave_config {
+ unsigned int index;
+};
+
+/*****************************************************************************/
--- a/master/cdev.c Thu Oct 02 10:44:43 2008 +0000
+++ b/master/cdev.c Thu Oct 02 10:45:40 2008 +0000
@@ -1408,6 +1408,50 @@
return domain->index;
}
+/*****************************************************************************/
+
+/** Create a slave configuration.
+ */
+int ec_cdev_ioctl_create_slave_config(
+ ec_master_t *master, /**< EtherCAT master. */
+ unsigned long arg, /**< ioctl() argument. */
+ ec_cdev_priv_t *priv /**< Private data structure of file handle. */
+ )
+{
+ ec_ioctl_config_t data;
+ ec_slave_config_t *sc, *entry;
+
+ if (unlikely(!priv->requested))
+ return -EPERM;
+
+ if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+ return -EFAULT;
+ }
+
+ sc = ecrt_master_slave_config(master, data.alias, data.position,
+ data.vendor_id, data.product_code);
+ if (!sc)
+ return -ENODEV; // FIXME
+
+ data.config_index = 0;
+
+ if (down_interruptible(&master->master_sem))
+ return -EINTR;
+
+ list_for_each_entry(entry, &master->configs, list) {
+ if (entry == sc)
+ break;
+ data.config_index++;
+ }
+
+ up(&master->master_sem);
+
+ if (copy_to_user((void __user *) arg, &data, sizeof(data)))
+ return -EFAULT;
+
+ return 0;
+}
+
/******************************************************************************
* File operations
*****************************************************************************/
@@ -1529,6 +1573,10 @@
if (!(filp->f_mode & FMODE_WRITE))
return -EPERM;
return ec_cdev_ioctl_create_domain(master, arg, priv);
+ case EC_IOCTL_CREATE_SLAVE_CONFIG:
+ if (!(filp->f_mode & FMODE_WRITE))
+ return -EPERM;
+ return ec_cdev_ioctl_create_slave_config(master, arg, priv);
default:
return -ENOTTY;
}
--- a/master/ioctl.h Thu Oct 02 10:44:43 2008 +0000
+++ b/master/ioctl.h Thu Oct 02 10:45:40 2008 +0000
@@ -81,6 +81,7 @@
#define EC_IOCTL_REQUEST EC_IO(0x16)
#define EC_IOCTL_CREATE_DOMAIN EC_IO(0x17)
+#define EC_IOCTL_CREATE_SLAVE_CONFIG EC_IOWR(0x18, ec_ioctl_config_t)
#define EC_IOCTL_STRING_SIZE 64