examples/msr/msr_sample.c
author Florian Pose <fp@igh-essen.com>
Wed, 03 Oct 2007 09:08:00 +0000
branchstable-1.3
changeset 1747 b6f23874f8d5
parent 1739 5fcbd29151d2
permissions -rw-r--r--
Added fsm_coe_map.[ch] to dist.
232
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  and/or modify it under the terms of the GNU General Public License
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 240
diff changeset
    11
 *  as published by the Free Software Foundation; either version 2 of the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 240
diff changeset
    12
 *  License, or (at your option) any later version.
232
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  The IgH EtherCAT Master is distributed in the hope that it will be
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *  GNU General Public License for more details.
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  You should have received a copy of the GNU General Public License
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 240
diff changeset
    23
 *  The right to use EtherCAT Technology is granted and comes free of
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 240
diff changeset
    24
 *  charge under condition of compatibility of product made by
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 240
diff changeset
    25
 *  Licensee. People intending to distribute/sell products based on the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 240
diff changeset
    26
 *  code, have to sign an agreement to guarantee that products using
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 240
diff changeset
    27
 *  software based on IgH EtherCAT master stay compatible with the actual
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 240
diff changeset
    28
 *  EtherCAT specification (which are released themselves as an open
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 240
diff changeset
    29
 *  standard) as the (only) precondition to have the right to use EtherCAT
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 240
diff changeset
    30
 *  Technology, IP and trade marks.
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 240
diff changeset
    31
 *
232
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
 *****************************************************************************/
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
// Linux
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
#include <linux/module.h>
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
// RTAI
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
#include "rtai_sched.h"
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
#include "rtai_sem.h"
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
// RT_lib
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include <msr_main.h>
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#include <msr_reg.h>
234
fd04cfde1c4b Corrected MSR example.
Florian Pose <fp@igh-essen.com>
parents: 232
diff changeset
    44
#include <msr_time.h>
232
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
// EtherCAT
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
#include "../../include/ecrt.h"
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    48
#include "../../include/ecdb.h"
232
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
1732
1cc865ba17c2 MERGE trunk -r588:681 -> branches/stable-1.1 (Bugfixes, Ack behaviour, CoE via Sysfs, PDO ranges, 2.6.17 support, improved autotools, documentation)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
    50
#define MSR_ABTASTFREQUENZ 1000
1cc865ba17c2 MERGE trunk -r588:681 -> branches/stable-1.1 (Bugfixes, Ack behaviour, CoE via Sysfs, PDO ranges, 2.6.17 support, improved autotools, documentation)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
    51
232
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
#define HZREDUCTION (MSR_ABTASTFREQUENZ / HZ)
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
#define TIMERTICKS (1000000000 / MSR_ABTASTFREQUENZ)
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
/*****************************************************************************/
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
// RTAI
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
RT_TASK task;
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
SEM master_sem;
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
cycles_t t_start = 0, t_critical;
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
// EtherCAT
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
ec_master_t *master = NULL;
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
ec_domain_t *domain1 = NULL;
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
234
fd04cfde1c4b Corrected MSR example.
Florian Pose <fp@igh-essen.com>
parents: 232
diff changeset
    66
// raw process data
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    67
void *r_ana_out;
232
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
1739
5fcbd29151d2 MERGE -r688:759 trunk -> branches/stable-1.2 (release 1.2, part one).
Florian Pose <fp@igh-essen.com>
parents: 1732
diff changeset
    69
// channels
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    70
double k_ana_out;
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    71
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    72
ec_pdo_reg_t domain1_pdos[] = {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    73
    {"3", Beckhoff_EL4132_Output1, &r_ana_out},
232
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
    {}
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
};
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
/*****************************************************************************/
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
234
fd04cfde1c4b Corrected MSR example.
Florian Pose <fp@igh-essen.com>
parents: 232
diff changeset
    79
void msr_controller_run(void)
fd04cfde1c4b Corrected MSR example.
Florian Pose <fp@igh-essen.com>
parents: 232
diff changeset
    80
{
1739
5fcbd29151d2 MERGE -r688:759 trunk -> branches/stable-1.2 (release 1.2, part one).
Florian Pose <fp@igh-essen.com>
parents: 1732
diff changeset
    81
    // receive
234
fd04cfde1c4b Corrected MSR example.
Florian Pose <fp@igh-essen.com>
parents: 232
diff changeset
    82
    rt_sem_wait(&master_sem);
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    83
    ecrt_master_receive(master);
234
fd04cfde1c4b Corrected MSR example.
Florian Pose <fp@igh-essen.com>
parents: 232
diff changeset
    84
    ecrt_domain_process(domain1);
1739
5fcbd29151d2 MERGE -r688:759 trunk -> branches/stable-1.2 (release 1.2, part one).
Florian Pose <fp@igh-essen.com>
parents: 1732
diff changeset
    85
    rt_sem_signal(&master_sem);
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    86
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    87
    // Process data
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    88
    EC_WRITE_S16(r_ana_out, k_ana_out / 10.0 * 0x7FFF);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    89
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    90
    // Send
1739
5fcbd29151d2 MERGE -r688:759 trunk -> branches/stable-1.2 (release 1.2, part one).
Florian Pose <fp@igh-essen.com>
parents: 1732
diff changeset
    91
    rt_sem_wait(&master_sem);
5fcbd29151d2 MERGE -r688:759 trunk -> branches/stable-1.2 (release 1.2, part one).
Florian Pose <fp@igh-essen.com>
parents: 1732
diff changeset
    92
    ecrt_domain_queue(domain1);
234
fd04cfde1c4b Corrected MSR example.
Florian Pose <fp@igh-essen.com>
parents: 232
diff changeset
    93
    ecrt_master_run(master);
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    94
    ecrt_master_send(master);
234
fd04cfde1c4b Corrected MSR example.
Florian Pose <fp@igh-essen.com>
parents: 232
diff changeset
    95
    rt_sem_signal(&master_sem);
fd04cfde1c4b Corrected MSR example.
Florian Pose <fp@igh-essen.com>
parents: 232
diff changeset
    96
fd04cfde1c4b Corrected MSR example.
Florian Pose <fp@igh-essen.com>
parents: 232
diff changeset
    97
    msr_write_kanal_list();
fd04cfde1c4b Corrected MSR example.
Florian Pose <fp@igh-essen.com>
parents: 232
diff changeset
    98
}
fd04cfde1c4b Corrected MSR example.
Florian Pose <fp@igh-essen.com>
parents: 232
diff changeset
    99
fd04cfde1c4b Corrected MSR example.
Florian Pose <fp@igh-essen.com>
parents: 232
diff changeset
   100
/*****************************************************************************/
fd04cfde1c4b Corrected MSR example.
Florian Pose <fp@igh-essen.com>
parents: 232
diff changeset
   101
232
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
void msr_run(long data)
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
{
234
fd04cfde1c4b Corrected MSR example.
Florian Pose <fp@igh-essen.com>
parents: 232
diff changeset
   104
    while (1) {
232
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
        t_start = get_cycles();
234
fd04cfde1c4b Corrected MSR example.
Florian Pose <fp@igh-essen.com>
parents: 232
diff changeset
   106
        MSR_RTAITHREAD_CODE(msr_controller_run(););
232
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
        rt_task_wait_period();
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
    }
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
}
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
/*****************************************************************************/
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
int msr_reg(void)
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
{
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   115
    msr_reg_kanal("/ana_out", "", &k_ana_out, TDBL);
232
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
    return 0;
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
}
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
/*****************************************************************************/
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
int request_lock(void *data)
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
{
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
    // too close to the next RT cycle: deny access...
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
    if (get_cycles() - t_start > t_critical) return -1;
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
    // allow access
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
    rt_sem_wait(&master_sem);
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
    return 0;
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
}
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
/*****************************************************************************/
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
void release_lock(void *data)
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
{
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
    rt_sem_signal(&master_sem);
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
}
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
/*****************************************************************************/
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
int __init init_mod(void)
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
{
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
    RTIME ticks;
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
    printk(KERN_INFO "=== Starting EtherCAT RTAI MSR sample module... ===\n");
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
    rt_sem_init(&master_sem, 1);
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
    t_critical = cpu_khz * 800 / MSR_ABTASTFREQUENZ; // ticks for 80%
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
    if (msr_rtlib_init(1, MSR_ABTASTFREQUENZ, 10, &msr_reg) < 0) {
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
        printk(KERN_ERR "Failed to initialize rtlib!\n");
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
        goto out_return;
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
    }
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   154
    if (!(master = ecrt_request_master(0))) {
232
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
        printk(KERN_ERR "Failed to request master 0!\n");
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
        goto out_msr_cleanup;
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
    }
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
    ecrt_master_callbacks(master, request_lock, release_lock, NULL);
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
    printk(KERN_INFO "Creating domains...\n");
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
    if (!(domain1 = ecrt_master_create_domain(master))) {
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
        printk(KERN_ERR "Failed to create domains!\n");
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
        goto out_release_master;
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
    }
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   167
    printk(KERN_INFO "Registering PDOs...\n");
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   168
    if (ecrt_domain_register_pdo_list(domain1, domain1_pdos)) {
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   169
        printk(KERN_ERR "Failed to register PDOs.\n");
232
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
        goto out_release_master;
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
    }
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
    printk(KERN_INFO "Activating master...\n");
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
    if (ecrt_master_activate(master)) {
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
        printk(KERN_ERR "Could not activate master!\n");
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
        goto out_release_master;
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
    }
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
    printk("Starting cyclic sample thread...\n");
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
    ticks = start_rt_timer(nano2count(TIMERTICKS));
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
    if (rt_task_init(&task, msr_run, 0, 2000, 0, 1, NULL)) {
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
        printk(KERN_ERR "Failed to init RTAI task!\n");
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
        goto out_stop_timer;
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
    }
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
    if (rt_task_make_periodic(&task, rt_get_time() + ticks, ticks)) {
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
        printk(KERN_ERR "Failed to run RTAI task!\n");
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
        goto out_stop_task;
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
    }
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
    printk(KERN_INFO "=== EtherCAT RTAI MSR sample module started. ===\n");
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
    return 0;
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
 out_stop_task:
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
    rt_task_delete(&task);
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
 out_stop_timer:
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
    stop_rt_timer();
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
 out_release_master:
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
    ecrt_release_master(master);
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
 out_msr_cleanup:
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
    msr_rtlib_cleanup();
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
 out_return:
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
    rt_sem_delete(&master_sem);
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
    return -1;
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
}
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
/*****************************************************************************/
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
void __exit cleanup_mod(void)
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
{
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
    printk(KERN_INFO "=== Unloading EtherCAT RTAI MSR sample module... ===\n");
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   212
    rt_task_delete(&task);
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
    stop_rt_timer();
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   214
    ecrt_release_master(master);
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   215
    rt_sem_delete(&master_sem);
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
    msr_rtlib_cleanup();
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   217
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   218
    printk(KERN_INFO "=== EtherCAT RTAI MSR sample module unloaded. ===\n");
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   219
}
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   221
/*****************************************************************************/
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   222
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
MODULE_LICENSE("GPL");
1739
5fcbd29151d2 MERGE -r688:759 trunk -> branches/stable-1.2 (release 1.2, part one).
Florian Pose <fp@igh-essen.com>
parents: 1732
diff changeset
   224
MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>");
5fcbd29151d2 MERGE -r688:759 trunk -> branches/stable-1.2 (release 1.2, part one).
Florian Pose <fp@igh-essen.com>
parents: 1732
diff changeset
   225
MODULE_DESCRIPTION("EtherCAT RTAI MSR sample module");
232
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
module_init(init_mod);
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
module_exit(cleanup_mod);
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   229
f6594a07cdda MSR example finished.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
/*****************************************************************************/