rtdm/module.c
author Florian Pose <fp@igh-essen.com>
Wed, 06 Jul 2011 16:37:40 +0200
changeset 2076 1baafcd263cc
parent 2058 543c4ce9e86e
child 2071 e797dc47018b
permissions -rw-r--r--
Added e1000e driver for 2.6.34. Thanks to Siwei Zhuang.
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
     2
 *
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
     4
 *
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
     5
 *  ec_rtdm.c	Copyright (C) 2009-2010  Moehwald GmbH B.Benner
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
     6
 *                            2011       IgH Andreas Stewering-Bone
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
     7
 *								  
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
     8
 *								  
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
     9
 *  This file is part of the IgH EtherCAT master 
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    10
 *  
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
    11
 *  The IgH EtherCAT master is free software; you can
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    12
 *  redistribute it and/or modify it under the terms of the GNU Lesser General
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    13
 *  Public License as published by the Free Software Foundation; version 2.1
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    14
 *  of the License.
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    15
 *
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    16
 *  The IgH EtherCAT master userspace library is distributed in the hope that
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    17
 *  it will be useful, but WITHOUT ANY WARRANTY; without even the implied
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    18
 *  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    19
 *  GNU Lesser General Public License for more details.
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    20
 *
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    21
 *  You should have received a copy of the GNU Lesser General Public License
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    22
 *  along with the IgH EtherCAT master userspace library. If not, see
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    23
 *  <http://www.gnu.org/licenses/>.
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    24
 *  
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    25
 *  The license mentioned above concerns the source code only. Using the
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    26
 *  EtherCAT technology and brand is only permitted in compliance with the
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    27
 *  industrial property and similar rights of Beckhoff Automation GmbH.
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    28
 *
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    29
 *****************************************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    30
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    31
#include <linux/module.h>
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    32
#include <linux/mman.h>
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    33
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    34
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    35
#ifdef ENABLE_XENOMAI
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    36
#include <native/task.h>
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    37
#include <native/sem.h>
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    38
#include <native/mutex.h>
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    39
#include <native/timer.h>
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    40
#endif
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    41
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    42
#ifdef ENABLE_RTAI
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    43
#include <rtai_sched.h>
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    44
#include <rtai_sem.h>
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    45
#endif
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    46
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    47
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    48
#include <rtdm/rtdm_driver.h>
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    49
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    50
#include "../include/ecrt.h"
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    51
#include "../include/ec_rtdm.h"
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    52
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    53
#ifdef ENABLE_XENOMAI
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    54
#define my_mutex_create(X,Y)  rt_mutex_create(X, Y)
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    55
#define my_mutex_acquire(X,Y) rt_mutex_acquire(X,Y)
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    56
#define my_mutex_release(X)   rt_mutex_release(X)
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    57
#define my_mutex_delete(X)    rt_mutex_delete(X)
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    58
#endif
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    59
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    60
#ifdef ENABLE_RTAI
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    61
#define my_mutex_create(X,Y)  rt_sem_init(X, 1)
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    62
#define my_mutex_acquire(X,Y) rt_sem_wait(X)
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    63
#define my_mutex_release(X)   rt_sem_signal(X)
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    64
#define my_mutex_delete(X)    rt_sem_delete(X)
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    65
#define TM_INFINITE
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    66
#endif
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    67
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    68
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    69
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    70
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    71
#define EC_RTDM_MAX_MASTERS 5 /**< Maximum number of masters. */
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    72
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    73
#define EC_RTDM_GINFO(fmt, args...) \
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
    74
    rtdm_printk(KERN_INFO "EtherCATrtdm: " fmt,  ##args)
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    75
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    76
#define EC_RTDM_GERR(fmt, args...) \
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
    77
    rtdm_printk(KERN_ERR "EtherCATrtdm ERROR: " fmt, ##args)
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    78
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    79
#define EC_RTDM_GWARN(fmt, args...) \
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
    80
    rtdm_printk(KERN_WARNING "EtherCATrtdm WARNING: " fmt, ##args)
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    81
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    82
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    83
#define EC_RTDM_INFO(devno, fmt, args...) \
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
    84
    rtdm_printk(KERN_INFO "EtherCATrtdm %u: " fmt, devno, ##args)
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    85
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    86
#define EC_RTDM_ERR(devno, fmt, args...) \
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
    87
    rtdm_printk(KERN_ERR "EtherCATrtdm %u ERROR: " fmt, devno, ##args)
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    88
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    89
#define EC_RTDM_WARN(devno, fmt, args...) \
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
    90
    rtdm_printk(KERN_WARNING "EtherCATrtdm %u WARNING: " fmt, devno, ##args)
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    91
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    92
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    93
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    94
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    95
typedef struct _EC_RTDM_DRV_STRUCT {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    96
    unsigned int	    isattached;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    97
    ec_master_t *	    master;
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    98
    ec_domain_t *	    domain;	
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
    99
#ifdef ENABLE_XENOMAI			   
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   100
    RT_MUTEX           masterlock;
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   101
#endif
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   102
#ifdef ENABLE_RTAI
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   103
    SEM                masterlock;
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   104
#endif
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   105
    unsigned int	    sendcnt;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   106
    unsigned int	    reccnt;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   107
    unsigned int	    sendcntlv;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   108
    unsigned int	    reccntlv;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   109
    char                    mutexname[64];
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   110
    unsigned int            masterno;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   111
} EC_RTDM_DRV_STRUCT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   112
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   113
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   114
static EC_RTDM_DRV_STRUCT ec_rtdm_masterintf[EC_RTDM_MAX_MASTERS];
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   115
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   116
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   117
/* import from ethercat */
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   118
ec_master_t *ecrt_attach_master(unsigned int master_index /**< Index of the master to request. */
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   119
        );
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   120
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   121
// driver context struct: used for storing various information
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   122
typedef struct _EC_RTDM_DRV_CONTEXT {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   123
    int                       dev_id;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   124
    EC_RTDM_DRV_STRUCT*  pdrvstruc;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   125
} EC_RTDM_DRV_CONTEXT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   126
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   127
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   128
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   129
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   130
/*            Utilities                                   */
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   131
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   132
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   133
static int _atoi(const char* text)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   134
{
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   135
  char  b;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   136
  int wd=-1;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   137
  int nfak=1;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   138
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   139
  wd=0;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   140
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   141
  while ((*text==' ') || (*text=='\t')) text++;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   142
  if (*text=='-') 
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   143
    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   144
      nfak=-1;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   145
	  text++;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   146
    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   147
  if (*text=='+') 
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   148
    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   149
      text++;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   150
    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   151
  while (*text!=0)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   152
    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   153
 	  b = *text;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   154
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   155
	  if ( (b>='0') && (b<='9') )
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   156
		{
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   157
		   b=b-'0';
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   158
		   wd=wd*10+b;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   159
		}
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   160
	  text++;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   161
	}
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   162
  return (nfak*wd);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   163
}
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   164
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   165
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   166
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   167
/*            DRIVER sendcallback                         */
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   168
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   169
void send_callback(void *cb_data)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   170
{
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   171
    EC_RTDM_DRV_STRUCT * pdrvstruc;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   172
    
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   173
    pdrvstruc = (EC_RTDM_DRV_STRUCT*)cb_data;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   174
    if (pdrvstruc->master)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   175
        {
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   176
            my_mutex_acquire(&pdrvstruc->masterlock,TM_INFINITE);
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   177
            ecrt_master_send_ext(pdrvstruc->master);
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   178
            my_mutex_release(&pdrvstruc->masterlock);
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   179
      }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   180
}
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   181
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   182
/*****************************************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   183
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   184
void receive_callback(void *cb_data)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   185
{
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   186
    EC_RTDM_DRV_STRUCT * pdrvstruc;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   187
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   188
    pdrvstruc = (EC_RTDM_DRV_STRUCT*)cb_data;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   189
    if (pdrvstruc->master)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   190
      {
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   191
          my_mutex_acquire(&pdrvstruc->masterlock,TM_INFINITE);
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   192
          ecrt_master_receive(pdrvstruc->master);
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   193
          my_mutex_release(&pdrvstruc->masterlock);      
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   194
    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   195
}
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   196
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   197
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   198
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   199
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   200
void detach_master(EC_RTDM_DRV_STRUCT * pdrvstruc)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   201
{
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   202
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   203
  if (pdrvstruc->isattached)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   204
      {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   205
          EC_RTDM_INFO(pdrvstruc->masterno,"reseting callbacks!\n");
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   206
          ecrt_master_callbacks(pdrvstruc->master,NULL,NULL,NULL);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   207
          EC_RTDM_INFO(pdrvstruc->masterno,"deleting mutex!\n");
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   208
          my_mutex_delete(&pdrvstruc->masterlock);
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   209
          pdrvstruc->master = NULL;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   210
          pdrvstruc->isattached=0;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   211
          EC_RTDM_INFO(pdrvstruc->masterno,"master detach done!\n");
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   212
      }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   213
}
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   214
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   215
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   216
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   217
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   218
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   219
/*            DRIVER OPEN                                 */
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   220
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   221
int ec_rtdm_open_rt(struct rtdm_dev_context    *context,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   222
                 rtdm_user_info_t           *user_info,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   223
                 int                        oflags)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   224
{
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   225
    EC_RTDM_DRV_CONTEXT* my_context;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   226
    EC_RTDM_DRV_STRUCT * pdrvstruc;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   227
    const char * p;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   228
    int dev_no;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   229
    unsigned int namelen;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   230
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   231
    //int ret;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   232
    int dev_id;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   233
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   234
    // get the context for our driver - used to store driver info
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   235
    my_context = (EC_RTDM_DRV_CONTEXT*)context->dev_private;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   236
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   237
    dev_no = -1;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   238
    namelen   = strlen(context->device->driver_name);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   239
    p = &context->device->driver_name[namelen-1];
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   240
    if (p!=&context->device->driver_name[0])
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   241
      {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   242
	  while ((*p>='0') && (*p<='9')) 
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   243
	    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   244
	       p--;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   245
	       if (p==&context->device->driver_name[0]) break;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   246
   	    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   247
	  dev_no=_atoi(p);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   248
	  if  ((dev_no!=-1) && (dev_no<EC_RTDM_MAX_MASTERS))
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   249
	    { 
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   250
		dev_id    = context->device->device_id;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   251
    		pdrvstruc = (EC_RTDM_DRV_STRUCT*)&ec_rtdm_masterintf[dev_no];
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   252
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   253
    		my_context->dev_id         = dev_id;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   254
    		my_context->pdrvstruc      = pdrvstruc;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   255
		 
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   256
    		// enable interrupt in RTDM
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   257
    		return 0;	
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   258
	    }	
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   259
      }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   260
   EC_RTDM_GERR("open - Cannot detect master device no\n");
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   261
   return -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   262
}
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   263
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   264
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   265
/*            DRIVER CLOSE                                */
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   266
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   267
int ec_rtdm_close_rt(struct rtdm_dev_context   *context,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   268
                  rtdm_user_info_t          *user_info)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   269
{
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   270
    EC_RTDM_DRV_CONTEXT* my_context;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   271
    EC_RTDM_DRV_STRUCT * pdrvstruc;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   272
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   273
    // get the context
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   274
    my_context = (EC_RTDM_DRV_CONTEXT*)context->dev_private;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   275
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   276
    pdrvstruc =  my_context->pdrvstruc;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   277
    EC_RTDM_INFO(pdrvstruc->masterno,"close called!\n");
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   278
    detach_master(pdrvstruc);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   279
    return 0;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   280
	
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   281
}
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   282
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   283
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   284
/*            DRIVER IOCTL                                */
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   285
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   286
int ec_rtdm_ioctl_rt(struct rtdm_dev_context   *context,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   287
                  rtdm_user_info_t          *user_info,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   288
                  int                       request,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   289
                  void                      *arg)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   290
{
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   291
    EC_RTDM_DRV_CONTEXT* my_context;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   292
    EC_RTDM_DRV_STRUCT * pdrvstruc;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   293
    int ret;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   294
    unsigned int l_ioctlvalue[]={0,0,0,0,0,0,0,0};
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   295
    ec_domain_state_t ds;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   296
    ec_master_state_t ms;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   297
    uint64_t app_time;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   298
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   299
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   300
    ret = 0;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   301
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   302
    // get the context
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   303
    my_context = (EC_RTDM_DRV_CONTEXT*)context->dev_private;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   304
    pdrvstruc =  my_context->pdrvstruc;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   305
    
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   306
    switch (request) {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   307
    case EC_RTDM_MASTERSTATE:
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   308
    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   309
		if (!pdrvstruc->isattached)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   310
            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   311
                return -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   312
            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   313
		if (pdrvstruc->master)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   314
            {
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   315
                my_mutex_acquire(&pdrvstruc->masterlock,TM_INFINITE);
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   316
                
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   317
                ecrt_master_state(pdrvstruc->master, &ms);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   318
                
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   319
                my_mutex_release(&pdrvstruc->masterlock);
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   320
                
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   321
            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   322
        if  (rtdm_rw_user_ok(user_info, arg, sizeof(ms)))
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   323
            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   324
                // copy data to user
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   325
                if (rtdm_copy_to_user(user_info, arg, &ms,sizeof(ms)))
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   326
                    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   327
                        return -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   328
                    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   329
            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   330
        
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   331
    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   332
    break;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   333
    case EC_RTDM_DOMAINSTATE:
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   334
    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   335
		if (!pdrvstruc->isattached)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   336
            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   337
                return -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   338
            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   339
	   	if (pdrvstruc->domain)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   340
            {
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   341
                my_mutex_acquire(&pdrvstruc->masterlock,TM_INFINITE);
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   342
                
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   343
                ecrt_domain_state(pdrvstruc->domain, &ds);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   344
                
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   345
                my_mutex_release(&pdrvstruc->masterlock);
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   346
            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   347
        if  (rtdm_rw_user_ok(user_info, arg, sizeof(ds)))
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   348
            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   349
                // copy data to user
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   350
                if (rtdm_copy_to_user(user_info, arg, &ds,sizeof(ds)))
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   351
                    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   352
                        return -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   353
                    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   354
            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   355
    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   356
    break;
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   357
    case EC_RTDM_MASTER_RECEIVE:
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   358
    {	       
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   359
        if (pdrvstruc->isattached)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   360
            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   361
                if (pdrvstruc->master)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   362
                    {
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   363
                        my_mutex_acquire(&pdrvstruc->masterlock,TM_INFINITE);
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   364
                        ecrt_master_receive(pdrvstruc->master);
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   365
                        pdrvstruc->reccnt++;
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   366
                        my_mutex_release(&pdrvstruc->masterlock);
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   367
                    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   368
            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   369
    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   370
    break;
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   371
    case EC_RTDM_DOMAIN_PROCESS:
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   372
    {	       
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   373
        if (pdrvstruc->isattached)
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   374
            {
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   375
                my_mutex_acquire(&pdrvstruc->masterlock,TM_INFINITE);
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   376
                ecrt_domain_process(pdrvstruc->domain);
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   377
                my_mutex_release(&pdrvstruc->masterlock);
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   378
            }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   379
    }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   380
    break;
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   381
    case EC_RTDM_MASTER_SEND:
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   382
    {
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   383
        
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   384
        if (pdrvstruc->isattached)
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   385
            {
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   386
                if (pdrvstruc->master)
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   387
                    {
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   388
                        my_mutex_acquire(&pdrvstruc->masterlock,TM_INFINITE);
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   389
                        ecrt_master_send(pdrvstruc->master);
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   390
                        pdrvstruc->sendcnt++;
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   391
                        my_mutex_release(&pdrvstruc->masterlock);
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   392
                    }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   393
            }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   394
    }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   395
    break;
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   396
    case EC_RTDM_DOMAIN_QUEQUE:
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   397
    {	       
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   398
        if (pdrvstruc->isattached)
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   399
            {
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   400
                my_mutex_acquire(&pdrvstruc->masterlock,TM_INFINITE);
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   401
                ecrt_domain_queue(pdrvstruc->domain);
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   402
                my_mutex_release(&pdrvstruc->masterlock);
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   403
            }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   404
    }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   405
    break;
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   406
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   407
    case EC_RTDM_MASTER_APP_TIME:
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   408
    {
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   409
		if (!pdrvstruc->isattached)
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   410
            {
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   411
                rtdm_printk("ERROR : No Master attached\n");
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   412
                return -EFAULT;
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   413
            }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   414
        if (rtdm_safe_copy_from_user(user_info, &app_time, arg, sizeof(app_time)))
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   415
            {
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   416
                rtdm_printk("ERROR : can't copy data to driver\n");
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   417
                return -EFAULT;
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   418
            }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   419
            
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   420
        if (pdrvstruc->master)
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   421
            {
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   422
                my_mutex_acquire(&pdrvstruc->masterlock,TM_INFINITE);
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   423
                
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   424
                ecrt_master_application_time(pdrvstruc->master, app_time);
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   425
                my_mutex_release(&pdrvstruc->masterlock);
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   426
                
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   427
            }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   428
    }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   429
    break;
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   430
    case EC_RTDM_SYNC_REF_CLOCK:
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   431
    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   432
		if (!pdrvstruc->isattached)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   433
            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   434
                return -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   435
            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   436
        if (pdrvstruc->master)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   437
            {
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   438
                my_mutex_acquire(&pdrvstruc->masterlock,TM_INFINITE);
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   439
                
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   440
                ecrt_master_sync_reference_clock(pdrvstruc->master);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   441
                
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   442
                my_mutex_release(&pdrvstruc->masterlock);
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   443
                
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   444
            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   445
    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   446
    break;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   447
    case EC_RTDM_SYNC_SLAVE_CLOCK:
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   448
    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   449
		if (!pdrvstruc->isattached)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   450
            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   451
                return -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   452
            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   453
        if (pdrvstruc->master)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   454
            {
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   455
                my_mutex_acquire(&pdrvstruc->masterlock,TM_INFINITE);
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   456
                
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   457
                ecrt_master_sync_slave_clocks(pdrvstruc->master);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   458
                
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   459
                my_mutex_release(&pdrvstruc->masterlock);
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   460
                
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   461
            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   462
    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   463
    break;
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   464
    case EC_RTDM_MASTER_SYNC_MONITOR_QUEQUE:
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   465
    {
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   466
		if (!pdrvstruc->isattached)
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   467
            {
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   468
                return -EFAULT;
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   469
            }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   470
        if (pdrvstruc->master)
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   471
            {
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   472
                my_mutex_acquire(&pdrvstruc->masterlock,TM_INFINITE);
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   473
                ecrt_master_sync_monitor_queue(pdrvstruc->master);
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   474
                my_mutex_release(&pdrvstruc->masterlock);
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   475
            }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   476
    }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   477
    break;
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   478
    case EC_RTDM_MASTER_SYNC_MONITOR_PROCESS:
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   479
    {
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   480
        uint32_t ret;
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   481
		if (!pdrvstruc->isattached)
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   482
            {
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   483
                return -EFAULT;
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   484
            }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   485
        if (pdrvstruc->master)
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   486
            {
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   487
                my_mutex_acquire(&pdrvstruc->masterlock,TM_INFINITE);
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   488
                ret = ecrt_master_sync_monitor_process(pdrvstruc->master);
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   489
                my_mutex_release(&pdrvstruc->masterlock);
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   490
                if (rtdm_safe_copy_to_user(user_info, arg, &ret, sizeof(ret)))
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   491
                    {
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   492
                        EC_RTDM_ERR(pdrvstruc->masterno,"copy to user param failed!\n");
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   493
                        ret=-EFAULT;
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   494
                    }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   495
            }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   496
    }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   497
    break;
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   498
    case EC_RTDM_MSTRATTACH:
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   499
    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   500
        unsigned int mstridx;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   501
        
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   502
        mstridx = 0;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   503
        ret = 0;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   504
        
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   505
        EC_RTDM_INFO(pdrvstruc->masterno,"Master attach start!\n");
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   506
        if (user_info) 
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   507
            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   508
                if (rtdm_read_user_ok(user_info, arg, sizeof(unsigned int)))
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   509
                    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   510
                        if (rtdm_copy_from_user(user_info, &l_ioctlvalue[0], arg,sizeof(unsigned int))==0)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   511
                            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   512
                                pdrvstruc->domain = (ec_domain_t*)l_ioctlvalue[0];
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   513
                            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   514
                        else
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   515
                            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   516
                                EC_RTDM_ERR(pdrvstruc->masterno,"copy user param failed!\n");
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   517
                                ret=-EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   518
                            }		
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   519
                    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   520
                else
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   521
                    { 
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   522
                        EC_RTDM_ERR(pdrvstruc->masterno,"user parameter domain missing!\n");
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   523
                        ret=-EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   524
                    }	
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   525
            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   526
		if (ret!=0) 
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   527
            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   528
                return ret;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   529
            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   530
        
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   531
		if ( (pdrvstruc->master) && (pdrvstruc->isattached))
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   532
            // master is allready attached
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   533
            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   534
                // master is allready attached
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   535
                EC_RTDM_ERR(pdrvstruc->masterno,"Master is allready attached!\n");
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   536
                ret = -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   537
            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   538
	    else
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   539
            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   540
                //mstr=ecrt_request_master(0);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   541
                mstridx = pdrvstruc->masterno;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   542
	        	
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   543
                pdrvstruc->master=ecrt_attach_master(mstridx);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   544
                
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   545
                if (pdrvstruc->master)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   546
                    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   547
                        // Ok
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   548
                        EC_RTDM_INFO(pdrvstruc->masterno,"Master searching for domain!\n");
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   549
                        pdrvstruc->domain = ecrt_master_find_domain(pdrvstruc->master,l_ioctlvalue[0]);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   550
                        if (!pdrvstruc->domain)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   551
                            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   552
                                //
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   553
                                EC_RTDM_ERR(pdrvstruc->masterno,"Cannot find domain from index %u!\n",l_ioctlvalue[0]);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   554
                                ret = -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   555
                            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   556
                        else
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   557
                            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   558
                                
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   559
                                // set device name
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   560
                                snprintf(&pdrvstruc->mutexname[0],sizeof(pdrvstruc->mutexname)-1,"ETHrtdmLOCK%d",pdrvstruc->masterno);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   561
                                EC_RTDM_INFO(pdrvstruc->masterno,"Creating Master mutex %s!\n",&pdrvstruc->mutexname[0]);
2058
543c4ce9e86e Working RTAI RTDM module
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2055
diff changeset
   562
                                my_mutex_create(&pdrvstruc->masterlock,&pdrvstruc->mutexname[0]);
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   563
                                //ecrt_release_master(mstr);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   564
                                ecrt_master_callbacks(pdrvstruc->master, send_callback, receive_callback, pdrvstruc);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   565
                                EC_RTDM_INFO(pdrvstruc->masterno,"MSTR ATTACH done domain=%u!\n",(unsigned int)pdrvstruc->domain);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   566
                                pdrvstruc->isattached=1;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   567
                                ret = 0;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   568
                            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   569
                        
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   570
                    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   571
                else
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   572
                    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   573
                        EC_RTDM_ERR(pdrvstruc->masterno,"Master attach failed!\n");
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   574
                        pdrvstruc->master = NULL;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   575
                        ret = -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   576
                    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   577
            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   578
    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   579
    break;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   580
    default:
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   581
        ret = -ENOTTY;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   582
    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   583
    return ret;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   584
}
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   585
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   586
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   587
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   588
/*            DRIVER READ                                 */
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   589
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   590
int ec_rtdm_read_rt(struct rtdm_dev_context *context,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   591
                    rtdm_user_info_t *user_info, void *buf, size_t nbyte)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   592
{
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   593
    int                     ret;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   594
#if defined(USE_THIS)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   595
    EC_RTDM_DRV_CONTEXT* my_context;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   596
    char                    *out_pos;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   597
    int                     dev_id;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   598
    rtdm_toseq_t            timeout_seq;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   599
    int                     ret;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   600
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   601
    out_pos = (char *)buf;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   602
    
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   603
    my_context = (EC_RTDM_DRV_CONTEXT*)context->dev_private;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   604
    
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   605
    // zero bytes requested ? return!
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   606
    if (nbyte == 0)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   607
        return 0;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   608
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   609
    // check if R/W actions to user-space are allowed
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   610
    if (user_info && !rtdm_rw_user_ok(user_info, buf, nbyte))
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   611
        return -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   612
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   613
    dev_id = my_context->dev_id;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   614
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   615
    // in case we need to check if reading is allowed (locking)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   616
/*    if (test_and_set_bit(0, &ctx->in_lock))
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   617
        return -EBUSY;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   618
*/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   619
/*  // if we need to do some stuff with preemption disabled:
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   620
    rtdm_lock_get_irqsave(&ctx->lock, lock_ctx);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   621
    // stuff here
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   622
    rtdm_lock_put_irqrestore(&ctx->lock, lock_ctx);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   623
*/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   624
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   625
    // wait: if ctx->timeout = 0, it will block infintely until
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   626
    //       rtdm_event_signal(&ctx->irq_event); is called from our
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   627
    //       interrupt routine
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   628
    //ret = rtdm_event_timedwait(&ctx->irq_event, ctx->timeout, &timeout_seq);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   629
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   630
    // now write the requested stuff to user-space
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   631
    if (rtdm_copy_to_user(user_info, out_pos,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   632
                          dummy_buffer, BUFSIZE) != 0) {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   633
        ret = -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   634
    } else {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   635
        ret = BUFSIZE;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   636
    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   637
#else
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   638
    ret = -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   639
#endif
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   640
    return ret;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   641
}
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   642
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   643
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   644
/*            DRIVER WRITE                                */
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   645
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   646
int ec_rtdm_write_rt(struct rtdm_dev_context *context,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   647
                   rtdm_user_info_t *user_info,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   648
                   const void *buf, size_t nbyte)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   649
{
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   650
    int                     ret;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   651
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   652
#if defined(USE_THIS)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   653
    int                     dev_id;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   654
    char                    *in_pos = (char *)buf;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   655
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   656
    EC_RTDM_DRV_CONTEXT* my_context;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   657
    
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   658
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   659
    my_context = (EC_RTDM_DRV_CONTEXT*)context->dev_private;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   660
    
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   661
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   662
    if (nbyte == 0)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   663
        return 0;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   664
    if (user_info && !rtdm_read_user_ok(user_info, buf, nbyte))
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   665
        return -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   666
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   667
    dev_id = my_context->dev_id;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   668
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   669
    if (rtdm_copy_from_user(user_info, dummy_buffer,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   670
                             in_pos, BUFSIZE) != 0) {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   671
        ret = -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   672
    } else {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   673
       ret = BUFSIZE;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   674
    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   675
#else
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   676
    ret = -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   677
#endif
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   678
    // used when it is atomic
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   679
//   rtdm_mutex_unlock(&ctx->out_lock);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   680
    return ret;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   681
}
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   682
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   683
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   684
/*            DRIVER OPERATIONS                           */
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   685
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   686
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   687
// Template
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   688
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   689
static struct rtdm_device ec_rtdm_device_t = {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   690
    struct_version:     RTDM_DEVICE_STRUCT_VER,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   691
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   692
    device_flags:       RTDM_NAMED_DEVICE,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   693
    context_size:   	sizeof(EC_RTDM_DRV_CONTEXT),
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   694
    device_name:        EC_RTDM_DEV_FILE_NAME,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   695
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   696
/* open and close functions are not real-time safe due kmalloc
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   697
   and kfree. If you do not use kmalloc and kfree, and you made
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   698
   sure that there is no syscall in the open/close handler, you
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   699
   can declare the open_rt and close_rt handler.
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   700
*/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   701
    open_rt:            NULL,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   702
    open_nrt:           ec_rtdm_open_rt,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   703
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   704
    ops: {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   705
        close_rt:       NULL,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   706
        close_nrt:      ec_rtdm_close_rt,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   707
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   708
        ioctl_rt:       ec_rtdm_ioctl_rt,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   709
        ioctl_nrt:      ec_rtdm_ioctl_rt, // rtdm_mmap_to_user is not RT safe
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   710
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   711
        read_rt:        ec_rtdm_read_rt,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   712
        read_nrt:       NULL,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   713
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   714
        write_rt:       ec_rtdm_write_rt,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   715
        write_nrt:      NULL,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   716
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   717
        recvmsg_rt:     NULL,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   718
        recvmsg_nrt:    NULL,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   719
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   720
        sendmsg_rt:     NULL,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   721
        sendmsg_nrt:    NULL,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   722
    },
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   723
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   724
    device_class:       RTDM_CLASS_EXPERIMENTAL,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   725
    device_sub_class:   222,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   726
    driver_name:        EC_RTDM_DEV_FILE_NAME,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   727
    driver_version:     RTDM_DRIVER_VER(1,0,1),
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   728
    peripheral_name:    EC_RTDM_DEV_FILE_NAME,
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   729
    provider_name:      "EtherLab Community",
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   730
//    proc_name:          ethcatrtdm_device.device_name,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   731
};
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   732
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   733
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   734
static struct rtdm_device ec_rtdm_devices[EC_RTDM_MAX_MASTERS];
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   735
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   736
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   737
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   738
/*            INIT DRIVER                                 */
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   739
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   740
int init_module(void)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   741
{
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   742
	unsigned int i;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   743
    int ret;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   744
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   745
    ret = 0; 	
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   746
    
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   747
    EC_RTDM_GINFO("Initlializing EtherCAT RTDM Interface to Igh EtherCAT Master\n");
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   748
    memset(&ec_rtdm_masterintf[0],0,sizeof(ec_rtdm_masterintf));
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   749
    for (i=0;( (i<EC_RTDM_MAX_MASTERS) && (ret==0) ) ;i++)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   750
      {	 
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   751
    	// master no to struct
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   752
    	ec_rtdm_masterintf[i].masterno = i;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   753
        // copy from template
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   754
        memcpy(&ec_rtdm_devices[i],&ec_rtdm_device_t,sizeof(ec_rtdm_devices[0]));
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   755
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   756
        // set device name
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   757
        snprintf(&ec_rtdm_devices[i].device_name[0],RTDM_MAX_DEVNAME_LEN,"%s%d",EC_RTDM_DEV_FILE_NAME,i);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   758
        // set proc_name
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   759
	    ec_rtdm_devices[i].proc_name = &ec_rtdm_devices[i].device_name[0];
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   760
	    ec_rtdm_devices[i].driver_name = &ec_rtdm_devices[i].device_name[0];
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   761
		ec_rtdm_devices[i].peripheral_name = &ec_rtdm_devices[i].device_name[0];
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   762
	
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   763
		EC_RTDM_GINFO("Registering device %s!\n",ec_rtdm_devices[i].driver_name);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   764
		ret = rtdm_dev_register(&ec_rtdm_devices[i]);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   765
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   766
      }	
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   767
    if (ret!=0)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   768
      {	
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   769
    	// register m
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   770
        EC_RTDM_GERR("Initialization of EtherCAT RTDM Interface failed\n");
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   771
      }		
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   772
    return ret;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   773
}
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   774
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   775
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   776
/*            CLEANUP DRIVER                              */
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   777
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   778
void cleanup_module(void)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   779
{
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   780
    unsigned int i;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   781
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   782
    EC_RTDM_GINFO("Cleanup EtherCAT RTDM Interface \n");
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   783
    for (i=0;i<EC_RTDM_MAX_MASTERS;i++)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   784
      {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   785
         if (ec_rtdm_masterintf[i].isattached)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   786
           {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   787
	          detach_master(&ec_rtdm_masterintf[i]);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   788
	       }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   789
 		 EC_RTDM_GINFO("Unregistering device %s!\n",ec_rtdm_devices[i].driver_name);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   790
         rtdm_dev_unregister(&ec_rtdm_devices[i],1000);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   791
    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   792
}
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   793
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   794
MODULE_LICENSE("GPL");
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   795
MODULE_DESCRIPTION("EtherCAT RTDM Interface");