master/rtdm.c
author Edouard Tisserant <edouard.tisserant@gmail.com>
Mon, 10 Sep 2018 22:40:27 +0200
branchstable-1.5
changeset 2705 c6e3c6d66af0
parent 2700 93ef210e9b56
child 2706 43f8e40a183d
permissions -rw-r--r--
migrate posix xenomai example to Xenomai3
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/*****************************************************************************
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2009-2010  Moehwald GmbH B. Benner
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *                     2011  IgH Andreas Stewering-Bone
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *                     2012  Florian Pose <fp@igh-essen.com>
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  This file is part of the IgH EtherCAT master.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  The IgH EtherCAT master is free software; you can redistribute it and/or
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *  modify it under the terms of the GNU General Public License as published
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *  by the Free Software Foundation; version 2 of the License.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  The IgH EtherCAT master is distributed in the hope that it will be useful,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *  Public License for more details.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  You should have received a copy of the GNU General Public License along
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *  with the IgH EtherCAT master. If not, see <http://www.gnu.org/licenses/>.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *  The license mentioned above concerns the source code only. Using the
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  EtherCAT technology and brand is only permitted in compliance with the
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  industrial property and similar rights of Beckhoff Automation GmbH.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 ****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
2524
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
    29
/** \file
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
    30
 * RTDM interface.
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
    31
 */
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
    32
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
#include <linux/module.h>
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
#include <linux/slab.h>
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
#include <linux/mman.h>
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
2700
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    37
#include <rtdm/driver.h>
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
#include "master.h"
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#include "ioctl.h"
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include "rtdm.h"
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
/** Set to 1 to enable device operations debugging.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
 */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
#define DEBUG 0
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
/****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
/** Context structure for an open RTDM file handle.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
 */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
typedef struct {
2524
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
    52
    rtdm_user_info_t *user_info; /**< RTDM user data. */
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
    53
    ec_ioctl_context_t ioctl_ctx; /**< Context structure. */
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
} ec_rtdm_context_t;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
/****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
int ec_rtdm_open(struct rtdm_dev_context *, rtdm_user_info_t *, int);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
int ec_rtdm_close(struct rtdm_dev_context *, rtdm_user_info_t *);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
int ec_rtdm_ioctl(struct rtdm_dev_context *, rtdm_user_info_t *,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
        unsigned int, void __user *);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
/****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
2700
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    65
static struct rtdm_driver ec_rtdm_driver = {
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    66
	.profile_info		=	RTDM_PROFILE_INFO(foo,
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    67
							  RTDM_CLASS_EXPERIMENTAL,
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    68
							  222,
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    69
							  1),
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    70
	.device_flags		=	RTDM_NAMED_DEVICE,
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    71
	.device_count		=	1,
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    72
	.context_size		=	sizeof(ec_rtdm_context_t).
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    73
	.ops = {
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    74
        .open      = ec_rtdm_open;
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    75
        .close_nrt = ec_rtdm_close,
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    76
        .ioctl_rt  = ec_rtdm_ioctl,
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    77
        .ioctl_nrt = ec_rtdm_ioctl
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    78
	},
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    79
};
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    80
2524
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
    81
/** Initialize an RTDM device.
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
    82
 *
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
    83
 * \return Zero on success, otherwise a negative error code.
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
    84
 */
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
int ec_rtdm_dev_init(
2524
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
    86
        ec_rtdm_dev_t *rtdm_dev, /**< EtherCAT RTDM device. */
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
    87
        ec_master_t *master /**< EtherCAT master. */
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
    int ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
2700
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    92
    MODULE_VERSION
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    93
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
    rtdm_dev->master = master;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
    rtdm_dev->dev = kzalloc(sizeof(struct rtdm_device), GFP_KERNEL);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
    if (!rtdm_dev->dev) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
        EC_MASTER_ERR(master, "Failed to reserve memory for RTDM device.\n");
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
        return -ENOMEM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
    }
2700
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
   101
    
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
   102
    rtdm_dev->dev->label = kzalloc(RTDM_MAX_DEVNAME_LEN+1, GFP_KERNEL);
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
   103
    if (!rtdm_dev->dev->label) {
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
   104
        EC_MASTER_ERR(master, "Failed to reserve memory for RTDM device name.\n");
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
   105
        return -ENOMEM;
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
   106
        kfree(rtdm_dev->dev);
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
   107
    }
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
   108
    
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
   109
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
   110
    rtdm_dev->dev->driver = &ec_rtdm_driver;
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
   111
    snprintf(rtdm_dev->dev->label, RTDM_MAX_DEVNAME_LEN,
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
            "EtherCAT%u", master->index);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
    rtdm_dev->dev->device_data = rtdm_dev; /* pointer to parent */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
2700
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
   115
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
    EC_MASTER_INFO(master, "Registering RTDM device %s.\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
            rtdm_dev->dev->driver_name);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
    ret = rtdm_dev_register(rtdm_dev->dev);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
    if (ret) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
        EC_MASTER_ERR(master, "Initialization of RTDM interface failed"
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
                " (return value %i).\n", ret);
2700
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
   122
        kfree(rtdm_dev->dev->label);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
        kfree(rtdm_dev->dev);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
    return ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
/****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
2524
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   131
/** Clear an RTDM device.
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   132
 */
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
void ec_rtdm_dev_clear(
2524
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   134
        ec_rtdm_dev_t *rtdm_dev /**< EtherCAT RTDM device. */
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
    int ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
    EC_MASTER_INFO(rtdm_dev->master, "Unregistering RTDM device %s.\n",
2700
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
   140
            rtdm_dev->dev->label);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
    ret = rtdm_dev_unregister(rtdm_dev->dev, 1000 /* poll delay [ms] */);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
    if (ret < 0) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
        EC_MASTER_WARN(rtdm_dev->master,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
                "Failed to unregister RTDM device (code %i).\n", ret);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
2700
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
   147
    kfree(rtdm_dev->dev->label);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
    kfree(rtdm_dev->dev);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
/****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
/** Driver open.
2524
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   154
 *
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   155
 * \return Always zero (success).
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
 */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
int ec_rtdm_open(
2524
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   158
        struct rtdm_dev_context *context, /**< Context. */
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   159
        rtdm_user_info_t *user_info, /**< User data. */
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   160
        int oflags /**< Open flags. */
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
    ec_rtdm_context_t *ctx = (ec_rtdm_context_t *) context->dev_private;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
#if DEBUG
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
    ec_rtdm_dev_t *rtdm_dev = (ec_rtdm_dev_t *) context->device->device_data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
#endif
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
    ctx->user_info = user_info;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
    ctx->ioctl_ctx.writable = oflags & O_WRONLY || oflags & O_RDWR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
    ctx->ioctl_ctx.requested = 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
    ctx->ioctl_ctx.process_data = NULL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
    ctx->ioctl_ctx.process_data_size = 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
#if DEBUG
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
    EC_MASTER_INFO(rtdm_dev->master, "RTDM device %s opened.\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
            context->device->device_name);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
#endif
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
/****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
/** Driver close.
2524
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   184
 *
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   185
 * \return Always zero (success).
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   186
 */
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   187
int ec_rtdm_close(
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   188
        struct rtdm_dev_context *context, /**< Context. */
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   189
        rtdm_user_info_t *user_info /**< User data. */
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   190
        )
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
    ec_rtdm_context_t *ctx = (ec_rtdm_context_t *) context->dev_private;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
    ec_rtdm_dev_t *rtdm_dev = (ec_rtdm_dev_t *) context->device->device_data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
    if (ctx->ioctl_ctx.requested) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
        ecrt_release_master(rtdm_dev->master);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
	}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
#if DEBUG
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
    EC_MASTER_INFO(rtdm_dev->master, "RTDM device %s closed.\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
            context->device->device_name);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
#endif
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
/****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
/** Driver ioctl.
2524
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   209
 *
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   210
 * \return ioctl() return code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
 */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   212
int ec_rtdm_ioctl(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
        struct rtdm_dev_context *context, /**< Context. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   214
        rtdm_user_info_t *user_info, /**< User data. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   215
        unsigned int request, /**< Request. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
        void __user *arg /**< Argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   217
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   218
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   219
    ec_rtdm_context_t *ctx = (ec_rtdm_context_t *) context->dev_private;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
    ec_rtdm_dev_t *rtdm_dev = (ec_rtdm_dev_t *) context->device->device_data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   221
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   222
#if DEBUG
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
    EC_MASTER_INFO(rtdm_dev->master, "ioctl(request = %u, ctl = %02x)"
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
            " on RTDM device %s.\n", request, _IOC_NR(request),
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
            context->device->device_name);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
#endif
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
    return ec_ioctl_rtdm(rtdm_dev->master, &ctx->ioctl_ctx, request, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   229
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
/****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   231
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   232
/** Memory-map process data to user space.
2524
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   233
 *
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   234
 * \return Zero on success, otherwise a negative error code.
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   235
 */
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   236
int ec_rtdm_mmap(
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   237
        ec_ioctl_context_t *ioctl_ctx, /**< Context. */
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   238
        void **user_address /**< Userspace address. */
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   239
        )
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   240
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   241
    ec_rtdm_context_t *ctx =
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   242
        container_of(ioctl_ctx, ec_rtdm_context_t, ioctl_ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   243
    int ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   244
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   245
    ret = rtdm_mmap_to_user(ctx->user_info,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   246
            ioctl_ctx->process_data, ioctl_ctx->process_data_size,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   247
            PROT_READ | PROT_WRITE,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   248
            user_address,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   249
            NULL, NULL);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   250
    if (ret < 0) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   251
        return ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   252
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   253
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   254
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   255
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   256
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
/****************************************************************************/