No kernel handles in userspace; Domain creation.

This commit is contained in:
Florian Pose 2008-10-02 10:19:02 +00:00
parent 6c484fa19a
commit cd4bb0a38b
9 changed files with 247 additions and 32 deletions

View File

@ -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);
}

View File

@ -367,6 +367,8 @@ void ecrt_release_master(
* Master methods
*****************************************************************************/
#ifdef __KERNEL__
/** Sets the locking callbacks.
*
* For concurrent master access, the application has to provide a locking
@ -386,6 +388,8 @@ void ecrt_master_callbacks(
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.

View File

@ -40,6 +40,11 @@ lib_LTLIBRARIES = libethercat.la
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
#------------------------------------------------------------------------------

View File

@ -38,14 +38,17 @@
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/ioctl.h>
#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 @@ ec_master_t *ecrt_request_master(unsigned int master_index)
{
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 @@ ec_master_t *ecrt_request_master(unsigned int master_index)
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 @@ ec_master_t *ecrt_request_master(unsigned int master_index)
return 0;
}
master->handle = data.handle;
return master;
}
@ -93,10 +94,3 @@ void ecrt_release_master(ec_master_t *master)
}
/*****************************************************************************/
unsigned int ecrt_version_magic(void)
{
return ECRT_VERSION_MAGIC;
}
/*****************************************************************************/

42
lib/domain.h Normal file
View File

@ -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;
};
/*****************************************************************************/

103
lib/master.c Normal file
View File

@ -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 <stdlib.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#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)
{
}
/*****************************************************************************/

42
lib/master.h Normal file
View File

@ -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;
};
/*****************************************************************************/

View File

@ -1373,22 +1373,41 @@ int ec_cdev_ioctl_request(
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 @@ long eccdev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
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;
}

View File

@ -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 {
/*****************************************************************************/
typedef struct {
ec_master_t *handle;
} ec_ioctl_request_t;
/*****************************************************************************/
/** \endcond */
#endif