# HG changeset patch # User Florian Pose # Date 1222942742 0 # Node ID 0b70040d3daaa338f4392bb1b9d880cd6ebfe02f # Parent 13cb18b91627e7975c28359e06c5868af52a55b6 No kernel handles in userspace; Domain creation. diff -r 13cb18b91627 -r 0b70040d3daa examples/user/main.c --- a/examples/user/main.c Thu Oct 02 07:14:00 2008 +0000 +++ b/examples/user/main.c Thu Oct 02 10:19:02 2008 +0000 @@ -10,11 +10,17 @@ int main(int argc, char **argv) { - ec_master_t *master = ecrt_request_master(0); - + ec_master_t *master; + ec_domain_t *domain; + + master = ecrt_request_master(0); if (!master) return -1; + domain = ecrt_master_create_domain(master); + if (!domain) + return -1; + while (1) { sleep(1); } diff -r 13cb18b91627 -r 0b70040d3daa include/ecrt.h --- a/include/ecrt.h Thu Oct 02 07:14:00 2008 +0000 +++ b/include/ecrt.h Thu Oct 02 10:19:02 2008 +0000 @@ -367,6 +367,8 @@ * Master methods *****************************************************************************/ +#ifdef __KERNEL__ + /** Sets the locking callbacks. * * For concurrent master access, the application has to provide a locking @@ -386,6 +388,8 @@ void *cb_data /**< Arbitrary user data. */ ); +#endif /* __KERNEL__ */ + /** Creates a new process data domain. * * For process data exchange, at least one process data domain is needed. diff -r 13cb18b91627 -r 0b70040d3daa lib/Makefile.am --- a/lib/Makefile.am Thu Oct 02 07:14:00 2008 +0000 +++ b/lib/Makefile.am Thu Oct 02 10:19:02 2008 +0000 @@ -40,6 +40,11 @@ libethercat_la_LDFLAGS = -version-info 1:0:0 libethercat_la_CFLAGS = -I$(srcdir)/.. libethercat_la_SOURCES = \ - common.c + common.c \ + master.c + +noinst_HEADERS = \ + domain.h \ + master.h #------------------------------------------------------------------------------ diff -r 13cb18b91627 -r 0b70040d3daa lib/common.c --- a/lib/common.c Thu Oct 02 07:14:00 2008 +0000 +++ b/lib/common.c Thu Oct 02 10:19:02 2008 +0000 @@ -38,14 +38,17 @@ #include #include #include +#include -#include "include/ecrt.h" +#include "master.h" #include "master/ioctl.h" -struct ec_master { - int fd; - void *handle; -}; +/*****************************************************************************/ + +unsigned int ecrt_version_magic(void) +{ + return ECRT_VERSION_MAGIC; +} /*****************************************************************************/ @@ -55,7 +58,6 @@ { char path[MAX_PATH_LEN]; ec_master_t *master; - ec_ioctl_request_t data; master = malloc(sizeof(ec_master_t)); if (!master) { @@ -72,7 +74,7 @@ return 0; } - if (ioctl(master->fd, EC_IOCTL_REQUEST, &data) == -1) { + if (ioctl(master->fd, EC_IOCTL_REQUEST, NULL) == -1) { fprintf(stderr, "Failed to request master %u: %s\n", master_index, strerror(errno)); close(master->fd); @@ -80,7 +82,6 @@ return 0; } - master->handle = data.handle; return master; } @@ -93,10 +94,3 @@ } /*****************************************************************************/ - -unsigned int ecrt_version_magic(void) -{ - return ECRT_VERSION_MAGIC; -} - -/*****************************************************************************/ diff -r 13cb18b91627 -r 0b70040d3daa lib/domain.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/domain.h Thu Oct 02 10:19:02 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_domain { + unsigned int index; +}; + +/*****************************************************************************/ diff -r 13cb18b91627 -r 0b70040d3daa lib/master.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/master.c Thu Oct 02 10:19:02 2008 +0000 @@ -0,0 +1,103 @@ +/****************************************************************************** + * + * $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 +#include +#include +#include + +#include "master.h" +#include "domain.h" +#include "master/ioctl.h" + +/*****************************************************************************/ + +ec_domain_t *ecrt_master_create_domain(ec_master_t *master) +{ + ec_domain_t *domain; + int index; + + domain = malloc(sizeof(ec_domain_t)); + if (!domain) { + fprintf(stderr, "Failed to allocate memory.\n"); + return 0; + } + + index = ioctl(master->fd, EC_IOCTL_CREATE_DOMAIN, NULL); + if (index == -1) { + fprintf(stderr, "Failed to create domain: %s\n", strerror(errno)); + free(domain); + return 0; + } + + domain->index = (unsigned int) index; + return domain; +} + +/*****************************************************************************/ + +ec_slave_config_t *ecrt_master_slave_config(ec_master_t *master, + uint16_t alias, uint16_t position, uint32_t vendor_id, + uint32_t product_code) +{ + return 0; +} + +/*****************************************************************************/ + +int ecrt_master_activate(ec_master_t *master) +{ + return 0; +} + +/*****************************************************************************/ + +void ecrt_master_send(ec_master_t *master) +{ +} + +/*****************************************************************************/ + +void ecrt_master_receive(ec_master_t *master) +{ +} + +/*****************************************************************************/ + +void ecrt_master_state(const ec_master_t *master, ec_master_state_t *state) +{ +} + + +/*****************************************************************************/ diff -r 13cb18b91627 -r 0b70040d3daa lib/master.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/master.h Thu Oct 02 10:19:02 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_master { + int fd; +}; + +/*****************************************************************************/ diff -r 13cb18b91627 -r 0b70040d3daa master/cdev.c --- a/master/cdev.c Thu Oct 02 07:14:00 2008 +0000 +++ b/master/cdev.c Thu Oct 02 10:19:02 2008 +0000 @@ -1373,22 +1373,41 @@ ec_cdev_priv_t *priv /**< Private data structure of file handle. */ ) { - ec_ioctl_request_t data; + ec_master_t *m; int ret = 0; - data.handle = ecrt_request_master(master->index); - - if (IS_ERR(data.handle)) { - ret = PTR_ERR(data.handle); + m = ecrt_request_master(master->index); + if (IS_ERR(m)) { + ret = PTR_ERR(m); } else { priv->requested = 1; - if (copy_to_user((void __user *) arg, &data, sizeof(data))) - ret = -EFAULT; } return ret; } +/*****************************************************************************/ + +/** Create a domain. + */ +int ec_cdev_ioctl_create_domain( + ec_master_t *master, /**< EtherCAT master. */ + unsigned long arg, /**< ioctl() argument. */ + ec_cdev_priv_t *priv /**< Private data structure of file handle. */ + ) +{ + ec_domain_t *domain; + + if (unlikely(!priv->requested)) + return -EPERM; + + domain = ecrt_master_create_domain(master); + if (!domain) + return -ENOMEM; + + return domain->index; +} + /****************************************************************************** * File operations *****************************************************************************/ @@ -1506,6 +1525,10 @@ if (!(filp->f_mode & FMODE_WRITE)) return -EPERM; return ec_cdev_ioctl_request(master, arg, priv); + case EC_IOCTL_CREATE_DOMAIN: + if (!(filp->f_mode & FMODE_WRITE)) + return -EPERM; + return ec_cdev_ioctl_create_domain(master, arg, priv); default: return -ENOTTY; } diff -r 13cb18b91627 -r 0b70040d3daa master/ioctl.h --- a/master/ioctl.h Thu Oct 02 07:14:00 2008 +0000 +++ b/master/ioctl.h Thu Oct 02 10:19:02 2008 +0000 @@ -78,7 +78,9 @@ #define EC_IOCTL_CONFIG_PDO EC_IOWR(0x13, ec_ioctl_config_pdo_t) #define EC_IOCTL_CONFIG_PDO_ENTRY EC_IOWR(0x14, ec_ioctl_config_pdo_entry_t) #define EC_IOCTL_CONFIG_SDO EC_IOWR(0x15, ec_ioctl_config_sdo_t) -#define EC_IOCTL_REQUEST EC_IOR(0x16, ec_ioctl_request_t) + +#define EC_IOCTL_REQUEST EC_IO(0x16) +#define EC_IOCTL_CREATE_DOMAIN EC_IO(0x17) #define EC_IOCTL_STRING_SIZE 64 @@ -362,12 +364,6 @@ /*****************************************************************************/ -typedef struct { - ec_master_t *handle; -} ec_ioctl_request_t; - -/*****************************************************************************/ - /** \endcond */ #endif