master/cdev.c
author Florian Pose <fp@igh-essen.com>
Mon, 02 Jun 2008 10:51:31 +0000
changeset 935 b954e9d91ea5
parent 922 fede1d8f5b71
child 938 5b936e8e39fa
permissions -rw-r--r--
Added 'pdos' command to ethercat tool.
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  and/or modify it under the terms of the GNU General Public License
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  as published by the Free Software Foundation; either version 2 of the
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *  License, or (at your option) any later version.
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  The IgH EtherCAT Master is distributed in the hope that it will be
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *  GNU General Public License for more details.
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  You should have received a copy of the GNU General Public License
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *  The right to use EtherCAT Technology is granted and comes free of
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  charge under condition of compatibility of product made by
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  Licensee. People intending to distribute/sell products based on the
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *  code, have to sign an agreement to guarantee that products using
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *  software based on IgH EtherCAT master stay compatible with the actual
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *  EtherCAT specification (which are released themselves as an open
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
 *  standard) as the (only) precondition to have the right to use EtherCAT
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
 *  Technology, IP and trade marks.
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
 *
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
 *****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
/**
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
   \file
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
   EtherCAT master character device.
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
*/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include <linux/module.h>
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#include "cdev.h"
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
#include "master.h"
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
#include "ioctl.h"
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
/** \cond */
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
int eccdev_open(struct inode *, struct file *);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
int eccdev_release(struct inode *, struct file *);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
ssize_t eccdev_read(struct file *, char __user *, size_t, loff_t *);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
ssize_t eccdev_write(struct file *, const char __user *, size_t, loff_t *);
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
    55
long eccdev_ioctl(struct file *, unsigned int, unsigned long);
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
static struct file_operations eccdev_fops = {
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
    60
    .owner          = THIS_MODULE,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
    61
    .open           = eccdev_open,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
    62
    .release        = eccdev_release,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
    63
    .unlocked_ioctl = eccdev_ioctl
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
};
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
/** \endcond */
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
/** Constructor.
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
 * 
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
 * \return 0 in case of success, else < 0
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
 */
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
int ec_cdev_init(
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
		ec_cdev_t *cdev, /**< EtherCAT master character device. */
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
		ec_master_t *master, /**< Parent master. */
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
		dev_t dev_num /**< Device number. */
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
		)
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
{
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
    cdev->master = master;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
    cdev_init(&cdev->cdev, &eccdev_fops);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
    cdev->cdev.owner = THIS_MODULE;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
    if (cdev_add(&cdev->cdev,
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
		 MKDEV(MAJOR(dev_num), master->index), 1)) {
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
		EC_ERR("Failed to add character device!\n");
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
		return -1;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
    }
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
    return 0;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
/** Destructor.
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
 */
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
void ec_cdev_clear(ec_cdev_t *cdev /**< EtherCAT XML device */)
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
{
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
    cdev_del(&cdev->cdev);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
/******************************************************************************
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
 * File operations
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
 *****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
int eccdev_open(struct inode *inode, struct file *filp)
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
{
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
    ec_cdev_t *cdev = container_of(inode->i_cdev, ec_cdev_t, cdev);
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   110
    ec_master_t *master = cdev->master;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
    filp->private_data = cdev;
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   113
    if (master->debug_level)
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   114
        EC_DBG("File opened.\n");
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
    return 0;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
int eccdev_release(struct inode *inode, struct file *filp)
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
{
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   122
    ec_cdev_t *cdev = (ec_cdev_t *) filp->private_data;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   123
    ec_master_t *master = cdev->master;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   124
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   125
    if (master->debug_level)
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   126
        EC_DBG("File closed.\n");
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
    return 0;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   132
long eccdev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   133
{
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   134
    ec_cdev_t *cdev = (ec_cdev_t *) filp->private_data;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
    ec_master_t *master = cdev->master;
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   136
    long retval = 0;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
    if (master->debug_level)
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   139
        EC_DBG("ioctl(filp = %x, cmd = %u, arg = %u)\n",
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   140
                (u32) filp, (u32) cmd, (u32) arg);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   141
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   142
    // FIXME lock
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   143
    
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
    switch (cmd) {
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
        case EC_IOCTL_SLAVE_COUNT:
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   146
            retval = master->slave_count;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   147
            break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   148
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   149
        case EC_IOCTL_SLAVE:
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
            {
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   151
                ec_ioctl_slave_t data;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   152
                const ec_slave_t *slave;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   153
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   154
                if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   155
                    retval = -EFAULT;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   156
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   157
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   158
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   159
                if (!(slave = ec_master_find_slave(
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   160
                                master, 0, data.position))) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   161
                    EC_ERR("Slave %u does not exist!\n", data.position);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   162
                    retval = -EINVAL;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   163
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   164
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   165
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   166
                data.vendor_id = slave->sii.vendor_id;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   167
                data.product_code = slave->sii.product_code;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   168
                data.alias = slave->sii.alias;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   169
                data.state = slave->current_state;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   170
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   171
                data.sync_count = slave->sii.sync_count;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   172
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   173
                if (slave->sii.name) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   174
                    strncpy(data.name, slave->sii.name,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   175
                            EC_IOCTL_SLAVE_NAME_SIZE);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   176
                    data.name[EC_IOCTL_SLAVE_NAME_SIZE - 1] = 0;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   177
                } else {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   178
                    data.name[0] = 0;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   179
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   180
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   181
                if (copy_to_user((void __user *) arg, &data, sizeof(data))) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   182
                    retval = -EFAULT;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   183
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   184
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   185
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   186
                break;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
            }
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   189
        case EC_IOCTL_SYNC:
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
            {
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   191
                ec_ioctl_sync_t data;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
                const ec_slave_t *slave;
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   193
                const ec_sync_t *sync;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   194
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   195
                if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   196
                    retval = -EFAULT;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   197
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   198
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   199
                
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   200
                if (!(slave = ec_master_find_slave(
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   201
                                master, 0, data.slave_position))) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   202
                    EC_ERR("Slave %u does not exist!\n", data.slave_position);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   203
                    retval = -EINVAL;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   204
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   205
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   206
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   207
                if (data.sync_index >= slave->sii.sync_count) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   208
                    EC_ERR("Sync manager %u does not exist in slave %u!\n",
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   209
                            data.sync_index, data.slave_position);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   210
                    retval = -EINVAL;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   211
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   212
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   213
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   214
                sync = &slave->sii.syncs[data.sync_index];
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   215
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   216
                data.physical_start_address = sync->physical_start_address;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   217
                data.default_size = sync->length;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   218
                data.control_register = sync->control_register;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   219
                data.enable = sync->enable;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   220
                data.assign_source = sync->assign_source;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   221
                data.pdo_count = ec_pdo_list_count(&sync->pdos);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   222
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   223
                if (copy_to_user((void __user *) arg, &data, sizeof(data))) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   224
                    retval = -EFAULT;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   225
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   226
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   227
                break;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
            }
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   229
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   230
        case EC_IOCTL_PDO:
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   231
            {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   232
                ec_ioctl_pdo_t data;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   233
                const ec_slave_t *slave;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   234
                const ec_sync_t *sync;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   235
                const ec_pdo_t *pdo;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   236
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   237
                if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   238
                    retval = -EFAULT;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   239
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   240
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   241
                
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   242
                if (!(slave = ec_master_find_slave(
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   243
                                master, 0, data.slave_position))) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   244
                    EC_ERR("Slave %u does not exist!\n", data.slave_position);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   245
                    retval = -EINVAL;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   246
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   247
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   248
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   249
                if (data.sync_index >= slave->sii.sync_count) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   250
                    EC_ERR("Sync manager %u does not exist in slave %u!\n",
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   251
                            data.sync_index, data.slave_position);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   252
                    retval = -EINVAL;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   253
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   254
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   255
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   256
                sync = &slave->sii.syncs[data.sync_index];
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   257
                if (!(pdo = ec_pdo_list_find_pdo_by_pos_const(
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   258
                                &sync->pdos, data.pdo_pos))) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   259
                    EC_ERR("Sync manager %u does not contain a Pdo with "
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   260
                            "position %u in slave %u!\n", data.sync_index,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   261
                            data.pdo_pos, data.slave_position);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   262
                    retval = -EINVAL;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   263
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   264
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   265
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   266
                data.dir = pdo->dir;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   267
                data.index = pdo->index;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   268
                data.entry_count = ec_pdo_entry_count(pdo);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   269
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   270
                if (pdo->name) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   271
                    strncpy(data.name, pdo->name, EC_IOCTL_PDO_NAME_SIZE);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   272
                    data.name[EC_IOCTL_PDO_NAME_SIZE - 1] = 0;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   273
                } else {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   274
                    data.name[0] = 0;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   275
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   276
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   277
                if (copy_to_user((void __user *) arg, &data, sizeof(data))) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   278
                    retval = -EFAULT;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   279
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   280
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   281
                break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   282
            }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   283
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   284
        case EC_IOCTL_PDO_ENTRY:
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   285
            {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   286
                ec_ioctl_pdo_entry_t data;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   287
                const ec_slave_t *slave;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   288
                const ec_sync_t *sync;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   289
                const ec_pdo_t *pdo;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   290
                const ec_pdo_entry_t *entry;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   291
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   292
                if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   293
                    retval = -EFAULT;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   294
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   295
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   296
                
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   297
                if (!(slave = ec_master_find_slave(
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   298
                                master, 0, data.slave_position))) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   299
                    EC_ERR("Slave %u does not exist!\n", data.slave_position);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   300
                    retval = -EINVAL;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   301
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   302
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   303
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   304
                if (data.sync_index >= slave->sii.sync_count) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   305
                    EC_ERR("Sync manager %u does not exist in slave %u!\n",
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   306
                            data.sync_index, data.slave_position);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   307
                    retval = -EINVAL;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   308
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   309
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   310
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   311
                sync = &slave->sii.syncs[data.sync_index];
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   312
                if (!(pdo = ec_pdo_list_find_pdo_by_pos_const(
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   313
                                &sync->pdos, data.pdo_pos))) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   314
                    EC_ERR("Sync manager %u does not contain a Pdo with "
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   315
                            "position %u in slave %u!\n", data.sync_index,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   316
                            data.pdo_pos, data.slave_position);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   317
                    retval = -EINVAL;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   318
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   319
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   320
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   321
                if (!(entry = ec_pdo_find_entry_by_pos_const(
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   322
                                pdo, data.entry_pos))) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   323
                    EC_ERR("Pdo 0x%04X does not contain an entry with "
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   324
                            "position %u in slave %u!\n", data.pdo_pos,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   325
                            data.entry_pos, data.slave_position);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   326
                    retval = -EINVAL;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   327
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   328
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   329
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   330
                data.index = entry->index;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   331
                data.subindex = entry->subindex;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   332
                data.bit_length = entry->bit_length;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   333
                if (entry->name) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   334
                    strncpy(data.name, entry->name,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   335
                            EC_IOCTL_PDO_ENTRY_NAME_SIZE);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   336
                    data.name[EC_IOCTL_PDO_ENTRY_NAME_SIZE - 1] = 0;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   337
                } else {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   338
                    data.name[0] = 0;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   339
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   340
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   341
                if (copy_to_user((void __user *) arg, &data, sizeof(data))) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   342
                    retval = -EFAULT;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   343
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   344
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   345
                break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   346
            }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   347
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   348
        default:
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   349
            retval = -ENOIOCTLCMD;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   350
    }
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   351
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   352
    return retval;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   353
}
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   354
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   355
/*****************************************************************************/