examples/rtai/rtai_sample.c
author Florian Pose <fp@igh-essen.com>
Tue, 13 Feb 2007 13:27:44 +0000
branchstable-1.2
changeset 1737 97c5595db11b
parent 1732 1cc865ba17c2
child 509 87baea61d0c7
child 1739 5fcbd29151d2
permissions -rw-r--r--
Temporarily removed sysconfig script.
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
     3
 *  RTAI sample for the IgH EtherCAT master.
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  $Id$
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  This file is part of the IgH EtherCAT Master.
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  The IgH EtherCAT Master is free software; you can redistribute it
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *  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: 233
diff changeset
    13
 *  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: 233
diff changeset
    14
 *  License, or (at your option) any later version.
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  The IgH EtherCAT Master is distributed in the hope that it will be
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  GNU General Public License for more details.
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *  You should have received a copy of the GNU General Public License
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 233
diff changeset
    25
 *  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: 233
diff changeset
    26
 *  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: 233
diff changeset
    27
 *  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: 233
diff changeset
    28
 *  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: 233
diff changeset
    29
 *  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: 233
diff changeset
    30
 *  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: 233
diff changeset
    31
 *  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: 233
diff changeset
    32
 *  Technology, IP and trade marks.
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 233
diff changeset
    33
 *
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
 *****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
233
31d327ce38d3 Smaller fixes on RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 230
diff changeset
    36
// Linux
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#include <linux/module.h>
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
230
382bdb9138ec RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents: 227
diff changeset
    39
// RTAI
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
    40
#include "rtai_sched.h"
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
    41
#include "rtai_sem.h"
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
    42
233
31d327ce38d3 Smaller fixes on RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 230
diff changeset
    43
// EtherCAT
230
382bdb9138ec RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents: 227
diff changeset
    44
#include "../../include/ecrt.h"
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    45
#include "../../include/ecdb.h"
230
382bdb9138ec RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents: 227
diff changeset
    46
382bdb9138ec RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents: 227
diff changeset
    47
/*****************************************************************************/
382bdb9138ec RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents: 227
diff changeset
    48
259
87b20532872b Added some documentation.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    49
MODULE_LICENSE("GPL");
87b20532872b Added some documentation.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    50
MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>");
87b20532872b Added some documentation.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    51
MODULE_DESCRIPTION("EtherCAT RTAI sample module");
87b20532872b Added some documentation.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    52
87b20532872b Added some documentation.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    53
/*****************************************************************************/
87b20532872b Added some documentation.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    54
230
382bdb9138ec RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents: 227
diff changeset
    55
// RTAI task frequency in Hz
382bdb9138ec RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents: 227
diff changeset
    56
#define FREQUENCY 10000
1716
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
    57
#define INHIBIT_TIME 20
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
    58
230
382bdb9138ec RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents: 227
diff changeset
    59
#define TIMERTICKS (1000000000 / FREQUENCY)
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
    60
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
    61
/*****************************************************************************/
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
    62
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
    63
// RTAI
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
    64
RT_TASK task;
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
    65
SEM master_sem;
1716
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
    66
cycles_t t_last_cycle = 0, t_critical;
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
// EtherCAT
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
ec_master_t *master = NULL;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
ec_domain_t *domain1 = NULL;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
// data fields
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    73
void *r_ana_out;
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
// channels
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
uint32_t k_pos;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    78
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: 259
diff changeset
    79
    {"2", Beckhoff_EL4132_Output1, &r_ana_out},
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
    {}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
};
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
    85
void run(long data)
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
    86
{
230
382bdb9138ec RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents: 227
diff changeset
    87
    while (1)
382bdb9138ec RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents: 227
diff changeset
    88
    {
1716
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
    89
        t_last_cycle = get_cycles();
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
    90
        rt_sem_wait(&master_sem);
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    92
        ecrt_master_receive(master);
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
    93
        ecrt_domain_process(domain1);
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    94
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    95
        // process data
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    96
        //k_pos = EC_READ_U32(r_ssi_input);
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    97
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
    98
        ecrt_master_run(master);
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    99
        ecrt_master_send(master);
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   100
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   101
        rt_sem_signal(&master_sem);
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   102
        rt_task_wait_period();
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   103
    }
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
int request_lock(void *data)
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
{
230
382bdb9138ec RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents: 227
diff changeset
   110
    // too close to the next RT cycle: deny access...
1716
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
   111
    if (get_cycles() - t_last_cycle > t_critical) return -1;
230
382bdb9138ec RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents: 227
diff changeset
   112
382bdb9138ec RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents: 227
diff changeset
   113
    // allow access
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   114
    rt_sem_wait(&master_sem);
230
382bdb9138ec RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents: 227
diff changeset
   115
    return 0;
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
void release_lock(void *data)
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
{
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   122
    rt_sem_signal(&master_sem);
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   123
}
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   124
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   125
/*****************************************************************************/
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   126
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   127
int __init init_mod(void)
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   128
{
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   129
    RTIME tick_period, requested_ticks, now;
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   130
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   131
    printk(KERN_INFO "=== Starting EtherCAT RTAI sample module... ===\n");
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   132
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   133
    rt_sem_init(&master_sem, 1);
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
1716
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
   135
    t_critical = cpu_khz * 1000 / FREQUENCY - cpu_khz * INHIBIT_TIME / 1000;
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
   136
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
   137
    if (!(master = ecrt_request_master(0))) {
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
        printk(KERN_ERR "Requesting master 0 failed!\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
        goto out_return;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
    }
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
1716
9440f4ff25c7 MERGE trunk -r494:513 -> branches/stable-1.1 (SDO configuration, bugfixes, EoE frame rates)
Florian Pose <fp@igh-essen.com>
parents: 1715
diff changeset
   142
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
    ecrt_master_callbacks(master, request_lock, release_lock, NULL);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
    printk(KERN_INFO "Registering domain...\n");
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   146
    if (!(domain1 = ecrt_master_create_domain(master))) {
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
        printk(KERN_ERR "Domain creation failed!\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
        goto out_release_master;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
    }
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   151
    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: 259
diff changeset
   152
    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: 259
diff changeset
   153
        printk(KERN_ERR "PDO registration failed!\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
        goto out_release_master;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
    }
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
    printk(KERN_INFO "Activating master...\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
    if (ecrt_master_activate(master)) {
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
        printk(KERN_ERR "Failed to activate master!\n");
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
        goto out_release_master;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
    }
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
1715
e675450f2174 MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   163
    ecrt_master_prepare(master);
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   165
    printk("Starting cyclic sample thread...\n");
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   166
    requested_ticks = nano2count(TIMERTICKS);
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   167
    tick_period = start_rt_timer(requested_ticks);
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   168
    printk(KERN_INFO "RT timer started with %i/%i ticks.\n",
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   169
           (int) tick_period, (int) requested_ticks);
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   170
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   171
    if (rt_task_init(&task, run, 0, 2000, 0, 1, NULL)) {
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   172
        printk(KERN_ERR "Failed to init RTAI task!\n");
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   173
        goto out_stop_timer;
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   174
    }
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   175
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   176
    now = rt_get_time();
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   177
    if (rt_task_make_periodic(&task, now + tick_period, tick_period)) {
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   178
        printk(KERN_ERR "Failed to run RTAI task!\n");
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   179
        goto out_stop_task;
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   180
    }
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   181
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   182
    printk(KERN_INFO "=== EtherCAT RTAI sample module started. ===\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
    return 0;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   185
 out_stop_task:
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   186
    rt_task_delete(&task);
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   187
 out_stop_timer:
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   188
    stop_rt_timer();
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
    ecrt_master_deactivate(master);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
 out_release_master:
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
    ecrt_release_master(master);
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
 out_return:
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   193
    rt_sem_delete(&master_sem);
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
    return -1;
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   199
void __exit cleanup_mod(void)
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   200
{
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   201
    printk(KERN_INFO "=== Stopping EtherCAT RTAI sample module... ===\n");
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   202
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   203
    rt_task_delete(&task);
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   204
    stop_rt_timer();
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   205
    ecrt_release_master(master);
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   206
    rt_sem_delete(&master_sem);
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   207
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   208
    printk(KERN_INFO "=== EtherCAT RTAI sample module stopped. ===\n");
220
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
}
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
/*****************************************************************************/
342ad851ec78 Added examples directory.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   212
225
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   213
module_init(init_mod);
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   214
module_exit(cleanup_mod);
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   215
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   216
/*****************************************************************************/
9e8150db6fc8 Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents: 223
diff changeset
   217