rtdm/module.c
author Andreas Stewering-Bone <ab@igh-essen.com>
Mon, 21 Mar 2011 21:07:38 +0100
changeset 2057 23fca60b7ca2
parent 2055 d246ab6b50d2
child 2058 543c4ce9e86e
permissions -rw-r--r--
Working Xenomai Posix example
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>
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    33
#include <rtdm/rtdm_driver.h>
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    34
#include <native/task.h>
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    35
#include <native/sem.h>
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    36
#include <native/mutex.h>
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    37
#include <native/timer.h>
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    38
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    39
#include "../include/ecrt.h"
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    40
#include "../include/ec_rtdm.h"
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    41
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    42
#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
    43
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    44
#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
    45
    rtdm_printk(KERN_INFO "EtherCATrtdm: " fmt,  ##args)
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    46
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    47
#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
    48
    rtdm_printk(KERN_ERR "EtherCATrtdm ERROR: " fmt, ##args)
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
#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
    51
    rtdm_printk(KERN_WARNING "EtherCATrtdm WARNING: " fmt, ##args)
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    52
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    53
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    54
#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
    55
    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
    56
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    57
#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
    58
    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
    59
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    60
#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
    61
    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
    62
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    63
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    64
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    65
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    66
typedef struct _EC_RTDM_DRV_STRUCT {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    67
    unsigned int	    isattached;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    68
    ec_master_t *	    master;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    69
    ec_domain_t *	    domain;				   
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    70
    RT_MUTEX                masterlock;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    71
    unsigned int	    sendcnt;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    72
    unsigned int	    reccnt;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    73
    unsigned int	    sendcntlv;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    74
    unsigned int	    reccntlv;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    75
    char                    mutexname[64];
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    76
    unsigned int            masterno;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    77
} EC_RTDM_DRV_STRUCT;
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
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    80
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
    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
/* import from ethercat */
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    84
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
    85
        );
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    86
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    87
// driver context struct: used for storing various information
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    88
typedef struct _EC_RTDM_DRV_CONTEXT {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    89
    int                       dev_id;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    90
    EC_RTDM_DRV_STRUCT*  pdrvstruc;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    91
} EC_RTDM_DRV_CONTEXT;
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
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    96
/*            Utilities                                   */
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    97
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    98
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
    99
static int _atoi(const char* text)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   100
{
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   101
  char  b;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   102
  int wd=-1;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   103
  int nfak=1;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   104
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   105
  wd=0;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   106
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   107
  while ((*text==' ') || (*text=='\t')) text++;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   108
  if (*text=='-') 
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   109
    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   110
      nfak=-1;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   111
	  text++;
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
  if (*text=='+') 
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   114
    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   115
      text++;
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
  while (*text!=0)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   118
    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   119
 	  b = *text;
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
	  if ( (b>='0') && (b<='9') )
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   122
		{
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   123
		   b=b-'0';
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   124
		   wd=wd*10+b;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   125
		}
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   126
	  text++;
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
  return (nfak*wd);
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
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
/*            DRIVER sendcallback                         */
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
void send_callback(void *cb_data)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   136
{
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   137
    EC_RTDM_DRV_STRUCT * pdrvstruc;
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
    pdrvstruc = (EC_RTDM_DRV_STRUCT*)cb_data;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   140
    if (pdrvstruc->master)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   141
        {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   142
            rt_mutex_acquire(&pdrvstruc->masterlock,TM_INFINITE);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   143
            ecrt_master_send_ext(pdrvstruc->master);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   144
            rt_mutex_release(&pdrvstruc->masterlock);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   145
      }
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
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
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   150
void receive_callback(void *cb_data)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   151
{
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   152
    EC_RTDM_DRV_STRUCT * pdrvstruc;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   153
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   154
    pdrvstruc = (EC_RTDM_DRV_STRUCT*)cb_data;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   155
    if (pdrvstruc->master)
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
          rt_mutex_acquire(&pdrvstruc->masterlock,TM_INFINITE);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   158
          ecrt_master_receive(pdrvstruc->master);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   159
          rt_mutex_release(&pdrvstruc->masterlock);      
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   160
    }
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
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   163
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   164
2054
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
void detach_master(EC_RTDM_DRV_STRUCT * pdrvstruc)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   167
{
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
  if (pdrvstruc->isattached)
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_INFO(pdrvstruc->masterno,"reseting callbacks!\n");
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   172
          ecrt_master_callbacks(pdrvstruc->master,NULL,NULL,NULL);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   173
          EC_RTDM_INFO(pdrvstruc->masterno,"deleting mutex!\n");
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   174
          rt_mutex_delete(&pdrvstruc->masterlock);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   175
          pdrvstruc->master = NULL;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   176
          pdrvstruc->isattached=0;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   177
          EC_RTDM_INFO(pdrvstruc->masterno,"master detach done!\n");
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   178
      }
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
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   185
/*            DRIVER OPEN                                 */
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   186
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   187
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
   188
                 rtdm_user_info_t           *user_info,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   189
                 int                        oflags)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   190
{
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   191
    EC_RTDM_DRV_CONTEXT* my_context;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   192
    EC_RTDM_DRV_STRUCT * pdrvstruc;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   193
    const char * p;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   194
    int dev_no;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   195
    unsigned int namelen;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   196
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   197
    //int ret;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   198
    int dev_id;
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
    // 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
   201
    my_context = (EC_RTDM_DRV_CONTEXT*)context->dev_private;
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
    dev_no = -1;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   204
    namelen   = strlen(context->device->driver_name);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   205
    p = &context->device->driver_name[namelen-1];
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   206
    if (p!=&context->device->driver_name[0])
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   207
      {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   208
	  while ((*p>='0') && (*p<='9')) 
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   209
	    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   210
	       p--;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   211
	       if (p==&context->device->driver_name[0]) break;
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
	  dev_no=_atoi(p);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   214
	  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
   215
	    { 
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   216
		dev_id    = context->device->device_id;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   217
    		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
   218
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   219
    		my_context->dev_id         = dev_id;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   220
    		my_context->pdrvstruc      = pdrvstruc;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   221
		 
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   222
    		// enable interrupt in RTDM
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   223
    		return 0;	
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
      }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   226
   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
   227
   return -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   228
}
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   229
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
/*            DRIVER CLOSE                                */
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   232
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   233
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
   234
                  rtdm_user_info_t          *user_info)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   235
{
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   236
    EC_RTDM_DRV_CONTEXT* my_context;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   237
    EC_RTDM_DRV_STRUCT * pdrvstruc;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   238
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   239
    // get the context
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   240
    my_context = (EC_RTDM_DRV_CONTEXT*)context->dev_private;
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
    pdrvstruc =  my_context->pdrvstruc;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   243
    EC_RTDM_INFO(pdrvstruc->masterno,"close called!\n");
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   244
    detach_master(pdrvstruc);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   245
    return 0;
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
}
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   248
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
/*            DRIVER IOCTL                                */
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   251
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   252
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
   253
                  rtdm_user_info_t          *user_info,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   254
                  int                       request,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   255
                  void                      *arg)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   256
{
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   257
    EC_RTDM_DRV_CONTEXT* my_context;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   258
    EC_RTDM_DRV_STRUCT * pdrvstruc;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   259
    int ret;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   260
    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
   261
    ec_domain_state_t ds;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   262
    ec_master_state_t ms;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   263
    uint64_t app_time;
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
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   266
    ret = 0;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   267
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   268
    // get the context
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   269
    my_context = (EC_RTDM_DRV_CONTEXT*)context->dev_private;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   270
    pdrvstruc =  my_context->pdrvstruc;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   271
    
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   272
    switch (request) {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   273
    case EC_RTDM_MASTERSTATE:
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   274
    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   275
		if (!pdrvstruc->isattached)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   276
            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   277
                return -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   278
            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   279
		if (pdrvstruc->master)
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
                rt_mutex_acquire(&pdrvstruc->masterlock,TM_INFINITE);
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
                ecrt_master_state(pdrvstruc->master, &ms);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   284
                
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   285
                rt_mutex_release(&pdrvstruc->masterlock);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   286
                
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   287
            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   288
        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
   289
            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   290
                // copy data to user
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   291
                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
   292
                    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   293
                        return -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   294
                    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   295
            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   296
        
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   297
    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   298
    break;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   299
    case EC_RTDM_DOMAINSTATE:
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   300
    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   301
		if (!pdrvstruc->isattached)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   302
            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   303
                return -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   304
            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   305
	   	if (pdrvstruc->domain)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   306
            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   307
                rt_mutex_acquire(&pdrvstruc->masterlock,TM_INFINITE);
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
                ecrt_domain_state(pdrvstruc->domain, &ds);
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
                rt_mutex_release(&pdrvstruc->masterlock);
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  (rtdm_rw_user_ok(user_info, arg, sizeof(ds)))
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   314
            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   315
                // copy data to user
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   316
                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
   317
                    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   318
                        return -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   319
                    }
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
    break;
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   323
    case EC_RTDM_MASTER_RECEIVE:
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   324
    {	       
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   325
        if (pdrvstruc->isattached)
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
                if (pdrvstruc->master)
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
                        rt_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
   330
                        ecrt_master_receive(pdrvstruc->master);
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   331
                        pdrvstruc->reccnt++;
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   332
                        rt_mutex_release(&pdrvstruc->masterlock);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   333
                    }
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
    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   336
    break;
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   337
    case EC_RTDM_DOMAIN_PROCESS:
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   338
    {	       
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   339
        if (pdrvstruc->isattached)
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   340
            {
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   341
                rt_mutex_acquire(&pdrvstruc->masterlock,TM_INFINITE);
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   342
                ecrt_domain_process(pdrvstruc->domain);
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   343
                rt_mutex_release(&pdrvstruc->masterlock);
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   344
            }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   345
    }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   346
    break;
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   347
    case EC_RTDM_MASTER_SEND:
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   348
    {
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   349
        
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   350
        if (pdrvstruc->isattached)
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   351
            {
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   352
                if (pdrvstruc->master)
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   353
                    {
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   354
                        rt_mutex_acquire(&pdrvstruc->masterlock,TM_INFINITE);
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   355
                        ecrt_master_send(pdrvstruc->master);
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   356
                        pdrvstruc->sendcnt++;
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   357
                        rt_mutex_release(&pdrvstruc->masterlock);
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   358
                    }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   359
            }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   360
    }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   361
    break;
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   362
    case EC_RTDM_DOMAIN_QUEQUE:
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   363
    {	       
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   364
        if (pdrvstruc->isattached)
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   365
            {
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   366
                rt_mutex_acquire(&pdrvstruc->masterlock,TM_INFINITE);
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   367
                ecrt_domain_queue(pdrvstruc->domain);
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   368
                rt_mutex_release(&pdrvstruc->masterlock);
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   369
            }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   370
    }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   371
    break;
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
    case EC_RTDM_MASTER_APP_TIME:
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   374
    {
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   375
		if (!pdrvstruc->isattached)
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   376
            {
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   377
                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
   378
                return -EFAULT;
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
        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
   381
            {
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   382
                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
   383
                return -EFAULT;
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   384
            }
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
            {
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   388
                rt_mutex_acquire(&pdrvstruc->masterlock,TM_INFINITE);
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   389
                
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   390
                ecrt_master_application_time(pdrvstruc->master, app_time);
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   391
                rt_mutex_release(&pdrvstruc->masterlock);
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;
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   396
    case EC_RTDM_SYNC_REF_CLOCK:
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   397
    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   398
		if (!pdrvstruc->isattached)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   399
            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   400
                return -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   401
            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   402
        if (pdrvstruc->master)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   403
            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   404
                rt_mutex_acquire(&pdrvstruc->masterlock,TM_INFINITE);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   405
                
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   406
                ecrt_master_sync_reference_clock(pdrvstruc->master);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   407
                
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   408
                rt_mutex_release(&pdrvstruc->masterlock);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   409
                
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   410
            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   411
    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   412
    break;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   413
    case EC_RTDM_SYNC_SLAVE_CLOCK:
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   414
    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   415
		if (!pdrvstruc->isattached)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   416
            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   417
                return -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   418
            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   419
        if (pdrvstruc->master)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   420
            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   421
                rt_mutex_acquire(&pdrvstruc->masterlock,TM_INFINITE);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   422
                
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   423
                ecrt_master_sync_slave_clocks(pdrvstruc->master);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   424
                
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   425
                rt_mutex_release(&pdrvstruc->masterlock);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   426
                
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   427
            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   428
    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   429
    break;
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   430
    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
   431
    {
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   432
		if (!pdrvstruc->isattached)
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   433
            {
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   434
                return -EFAULT;
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   435
            }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   436
        if (pdrvstruc->master)
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   437
            {
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   438
                rt_mutex_acquire(&pdrvstruc->masterlock,TM_INFINITE);
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   439
                ecrt_master_sync_monitor_queue(pdrvstruc->master);
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   440
                rt_mutex_release(&pdrvstruc->masterlock);
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   441
            }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   442
    }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   443
    break;
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   444
    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
   445
    {
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   446
        uint32_t ret;
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   447
		if (!pdrvstruc->isattached)
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   448
            {
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   449
                return -EFAULT;
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   450
            }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   451
        if (pdrvstruc->master)
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   452
            {
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   453
                rt_mutex_acquire(&pdrvstruc->masterlock,TM_INFINITE);
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   454
                ret = ecrt_master_sync_monitor_process(pdrvstruc->master);
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   455
                rt_mutex_release(&pdrvstruc->masterlock);
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   456
                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
   457
                    {
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   458
                        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
   459
                        ret=-EFAULT;
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   460
                    }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   461
            }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   462
    }
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   463
    break;
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   464
    case EC_RTDM_MSTRATTACH:
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   465
    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   466
        unsigned int mstridx;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   467
        
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   468
        mstridx = 0;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   469
        ret = 0;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   470
        
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   471
        EC_RTDM_INFO(pdrvstruc->masterno,"Master attach start!\n");
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   472
        if (user_info) 
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   473
            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   474
                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
   475
                    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   476
                        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
   477
                            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   478
                                pdrvstruc->domain = (ec_domain_t*)l_ioctlvalue[0];
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   479
                            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   480
                        else
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   481
                            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   482
                                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
   483
                                ret=-EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   484
                            }		
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   485
                    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   486
                else
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   487
                    { 
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   488
                        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
   489
                        ret=-EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   490
                    }	
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   491
            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   492
		if (ret!=0) 
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   493
            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   494
                return ret;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   495
            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   496
        
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   497
		if ( (pdrvstruc->master) && (pdrvstruc->isattached))
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   498
            // master is allready attached
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
                // master is allready attached
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   501
                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
   502
                ret = -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   503
            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   504
	    else
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   505
            {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   506
                //mstr=ecrt_request_master(0);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   507
                mstridx = pdrvstruc->masterno;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   508
	        	
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   509
                pdrvstruc->master=ecrt_attach_master(mstridx);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   510
                
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   511
                if (pdrvstruc->master)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   512
                    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   513
                        // Ok
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   514
                        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
   515
                        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
   516
                        if (!pdrvstruc->domain)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   517
                            {
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
                                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
   520
                                ret = -EFAULT;
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
                        else
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   523
                            {
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
                                // set device name
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   526
                                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
   527
                                EC_RTDM_INFO(pdrvstruc->masterno,"Creating Master mutex %s!\n",&pdrvstruc->mutexname[0]);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   528
                                rt_mutex_create(&pdrvstruc->masterlock,&pdrvstruc->mutexname[0]);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   529
                                //ecrt_release_master(mstr);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   530
                                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
   531
                                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
   532
                                pdrvstruc->isattached=1;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   533
                                ret = 0;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   534
                            }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   535
                        
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   536
                    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   537
                else
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   538
                    {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   539
                        EC_RTDM_ERR(pdrvstruc->masterno,"Master attach failed!\n");
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   540
                        pdrvstruc->master = NULL;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   541
                        ret = -EFAULT;
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
            }
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
    break;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   546
    default:
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   547
        ret = -ENOTTY;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   548
    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   549
    return ret;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   550
}
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
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   554
/*            DRIVER READ                                 */
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
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
   557
                    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
   558
{
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   559
    int                     ret;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   560
#if defined(USE_THIS)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   561
    EC_RTDM_DRV_CONTEXT* my_context;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   562
    char                    *out_pos;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   563
    int                     dev_id;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   564
    rtdm_toseq_t            timeout_seq;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   565
    int                     ret;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   566
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   567
    out_pos = (char *)buf;
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
    my_context = (EC_RTDM_DRV_CONTEXT*)context->dev_private;
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
    // zero bytes requested ? return!
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   572
    if (nbyte == 0)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   573
        return 0;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   574
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   575
    // 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
   576
    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
   577
        return -EFAULT;
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
    dev_id = my_context->dev_id;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   580
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   581
    // 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
   582
/*    if (test_and_set_bit(0, &ctx->in_lock))
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   583
        return -EBUSY;
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
/*  // 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
   586
    rtdm_lock_get_irqsave(&ctx->lock, lock_ctx);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   587
    // stuff here
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   588
    rtdm_lock_put_irqrestore(&ctx->lock, lock_ctx);
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
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   591
    // 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
   592
    //       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
   593
    //       interrupt routine
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   594
    //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
   595
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   596
    // now write the requested stuff to user-space
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   597
    if (rtdm_copy_to_user(user_info, out_pos,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   598
                          dummy_buffer, BUFSIZE) != 0) {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   599
        ret = -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   600
    } else {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   601
        ret = BUFSIZE;
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
#else
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   604
    ret = -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   605
#endif
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   606
    return ret;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   607
}
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
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   610
/*            DRIVER WRITE                                */
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   611
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   612
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
   613
                   rtdm_user_info_t *user_info,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   614
                   const void *buf, size_t nbyte)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   615
{
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   616
    int                     ret;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   617
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   618
#if defined(USE_THIS)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   619
    int                     dev_id;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   620
    char                    *in_pos = (char *)buf;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   621
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   622
    EC_RTDM_DRV_CONTEXT* my_context;
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
    my_context = (EC_RTDM_DRV_CONTEXT*)context->dev_private;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   626
    
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   627
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   628
    if (nbyte == 0)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   629
        return 0;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   630
    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
   631
        return -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   632
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   633
    dev_id = my_context->dev_id;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   634
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   635
    if (rtdm_copy_from_user(user_info, dummy_buffer,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   636
                             in_pos, BUFSIZE) != 0) {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   637
        ret = -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   638
    } else {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   639
       ret = BUFSIZE;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   640
    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   641
#else
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   642
    ret = -EFAULT;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   643
#endif
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   644
    // used when it is atomic
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   645
//   rtdm_mutex_unlock(&ctx->out_lock);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   646
    return ret;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   647
}
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   648
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
/*            DRIVER OPERATIONS                           */
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
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   653
// Template
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   654
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   655
static struct rtdm_device ec_rtdm_device_t = {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   656
    struct_version:     RTDM_DEVICE_STRUCT_VER,
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
    device_flags:       RTDM_NAMED_DEVICE,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   659
    context_size:   	sizeof(EC_RTDM_DRV_CONTEXT),
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   660
    device_name:        EC_RTDM_DEV_FILE_NAME,
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
/* 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
   663
   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
   664
   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
   665
   can declare the open_rt and close_rt handler.
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
    open_rt:            NULL,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   668
    open_nrt:           ec_rtdm_open_rt,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   669
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   670
    ops: {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   671
        close_rt:       NULL,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   672
        close_nrt:      ec_rtdm_close_rt,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   673
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   674
        ioctl_rt:       ec_rtdm_ioctl_rt,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   675
        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
   676
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   677
        read_rt:        ec_rtdm_read_rt,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   678
        read_nrt:       NULL,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   679
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   680
        write_rt:       ec_rtdm_write_rt,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   681
        write_nrt:      NULL,
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
        recvmsg_rt:     NULL,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   684
        recvmsg_nrt:    NULL,
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
        sendmsg_rt:     NULL,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   687
        sendmsg_nrt:    NULL,
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
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   690
    device_class:       RTDM_CLASS_EXPERIMENTAL,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   691
    device_sub_class:   222,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   692
    driver_name:        EC_RTDM_DEV_FILE_NAME,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   693
    driver_version:     RTDM_DRIVER_VER(1,0,1),
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   694
    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
   695
    provider_name:      "EtherLab Community",
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   696
//    proc_name:          ethcatrtdm_device.device_name,
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   697
};
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   698
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   699
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   700
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
   701
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   702
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
/*            INIT DRIVER                                 */
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   705
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   706
int init_module(void)
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
	unsigned int i;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   709
    int ret;
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
    ret = 0; 	
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   712
    
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   713
    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
   714
    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
   715
    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
   716
      {	 
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   717
    	// master no to struct
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   718
    	ec_rtdm_masterintf[i].masterno = i;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   719
        // copy from template
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   720
        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
   721
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   722
        // set device name
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   723
        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
   724
        // set proc_name
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   725
	    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
   726
	    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
   727
		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
   728
	
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   729
		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
   730
		ret = rtdm_dev_register(&ec_rtdm_devices[i]);
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
    if (ret!=0)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   734
      {	
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   735
    	// register m
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   736
        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
   737
      }		
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   738
    return ret;
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
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
/*            CLEANUP DRIVER                              */
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   743
/**********************************************************/
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   744
void cleanup_module(void)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   745
{
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   746
    unsigned int i;
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   747
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   748
    EC_RTDM_GINFO("Cleanup EtherCAT RTDM Interface \n");
2054
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   749
    for (i=0;i<EC_RTDM_MAX_MASTERS;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
         if (ec_rtdm_masterintf[i].isattached)
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   752
           {
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   753
	          detach_master(&ec_rtdm_masterintf[i]);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   754
	       }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   755
 		 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
   756
         rtdm_dev_unregister(&ec_rtdm_devices[i],1000);
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   757
    }
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   758
}
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   759
3417bbc4ad2f First working RTDM Version,
Andreas Stewering-Bone <ab@igh-essen.com>
parents:
diff changeset
   760
MODULE_LICENSE("GPL");
2055
d246ab6b50d2 Fix application time for RTDM interface
Andreas Stewering-Bone <ab@igh-essen.com>
parents: 2054
diff changeset
   761
MODULE_DESCRIPTION("EtherCAT RTDM Interface");