author | Florian Pose <fp@igh-essen.com> |
Mon, 28 Jul 2008 08:30:44 +0000 | |
branch | stable-1.3 |
changeset 1757 | c5757cebfaea |
parent 1744 | 7bc131b92039 |
permissions | -rw-r--r-- |
220 | 1 |
/****************************************************************************** |
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 | 4 |
* |
5 |
* $Id$ |
|
6 |
* |
|
7 |
* Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH |
|
8 |
* |
|
9 |
* This file is part of the IgH EtherCAT Master. |
|
10 |
* |
|
11 |
* The IgH EtherCAT Master is free software; you can redistribute it |
|
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 | 15 |
* |
16 |
* The IgH EtherCAT Master is distributed in the hope that it will be |
|
17 |
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 |
* GNU General Public License for more details. |
|
20 |
* |
|
21 |
* You should have received a copy of the GNU General Public License |
|
22 |
* along with the IgH EtherCAT Master; if not, write to the Free Software |
|
23 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
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 | 34 |
*****************************************************************************/ |
35 |
||
233
31d327ce38d3
Smaller fixes on RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
230
diff
changeset
|
36 |
// Linux |
220 | 37 |
#include <linux/module.h> |
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 |
|
382bdb9138ec
RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents:
227
diff
changeset
|
49 |
// RTAI task frequency in Hz |
1744
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
50 |
#define FREQUENCY 2000 |
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
|
51 |
#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
|
52 |
|
230
382bdb9138ec
RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents:
227
diff
changeset
|
53 |
#define TIMERTICKS (1000000000 / FREQUENCY) |
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
54 |
|
1744
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
55 |
#define PFX "ec_rtai_sample: " |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
56 |
|
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
57 |
/*****************************************************************************/ |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
58 |
|
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
59 |
// RTAI |
1744
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
60 |
static RT_TASK task; |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
61 |
static SEM master_sem; |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
62 |
static cycles_t t_last_cycle = 0, t_critical; |
220 | 63 |
|
64 |
// EtherCAT |
|
1744
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
65 |
static ec_master_t *master = NULL; |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
66 |
static ec_domain_t *domain1 = NULL; |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
67 |
static ec_master_status_t master_status, old_status = {}; |
220 | 68 |
|
69 |
// data fields |
|
1744
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
70 |
static void *r_dig_out; |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
71 |
static void *r_ana_out; |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
72 |
static void *r_count; |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
73 |
//static void *r_freq; |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
74 |
|
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
75 |
const static ec_pdo_reg_t domain1_pdo_regs[] = { |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
76 |
{"2", Beckhoff_EL2004_Outputs, &r_dig_out}, |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
77 |
{"3", Beckhoff_EL4132_Output1, &r_ana_out}, |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
78 |
{"#888:1", Beckhoff_EL5101_Value, &r_count}, |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
79 |
//{"4", Beckhoff_EL5101_Frequency, &r_freq}, |
220 | 80 |
{} |
81 |
}; |
|
82 |
||
83 |
/*****************************************************************************/ |
|
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 |
{ |
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
|
87 |
static unsigned int blink = 0; |
5fcbd29151d2
MERGE -r688:759 trunk -> branches/stable-1.2 (release 1.2, part one).
Florian Pose <fp@igh-essen.com>
parents:
1732
diff
changeset
|
88 |
static unsigned int counter = 0; |
5fcbd29151d2
MERGE -r688:759 trunk -> branches/stable-1.2 (release 1.2, part one).
Florian Pose <fp@igh-essen.com>
parents:
1732
diff
changeset
|
89 |
|
5fcbd29151d2
MERGE -r688:759 trunk -> branches/stable-1.2 (release 1.2, part one).
Florian Pose <fp@igh-essen.com>
parents:
1732
diff
changeset
|
90 |
while (1) { |
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
|
91 |
t_last_cycle = get_cycles(); |
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
|
92 |
|
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
93 |
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:
259
diff
changeset
|
94 |
ecrt_master_receive(master); |
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
95 |
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
|
96 |
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:
259
diff
changeset
|
97 |
|
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
98 |
// process data |
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
|
99 |
EC_WRITE_U8(r_dig_out, blink ? 0x0F : 0x00); |
5fcbd29151d2
MERGE -r688:759 trunk -> branches/stable-1.2 (release 1.2, part one).
Florian Pose <fp@igh-essen.com>
parents:
1732
diff
changeset
|
100 |
|
5fcbd29151d2
MERGE -r688:759 trunk -> branches/stable-1.2 (release 1.2, part one).
Florian Pose <fp@igh-essen.com>
parents:
1732
diff
changeset
|
101 |
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
|
102 |
ecrt_domain_queue(domain1); |
1715
e675450f2174
MERGE trunk -r463:494 -> branches/stable-1.1 (Version 1.1)
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
103 |
ecrt_master_send(master); |
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
104 |
rt_sem_signal(&master_sem); |
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
|
105 |
|
5fcbd29151d2
MERGE -r688:759 trunk -> branches/stable-1.2 (release 1.2, part one).
Florian Pose <fp@igh-essen.com>
parents:
1732
diff
changeset
|
106 |
if (counter) { |
5fcbd29151d2
MERGE -r688:759 trunk -> branches/stable-1.2 (release 1.2, part one).
Florian Pose <fp@igh-essen.com>
parents:
1732
diff
changeset
|
107 |
counter--; |
5fcbd29151d2
MERGE -r688:759 trunk -> branches/stable-1.2 (release 1.2, part one).
Florian Pose <fp@igh-essen.com>
parents:
1732
diff
changeset
|
108 |
} |
5fcbd29151d2
MERGE -r688:759 trunk -> branches/stable-1.2 (release 1.2, part one).
Florian Pose <fp@igh-essen.com>
parents:
1732
diff
changeset
|
109 |
else { |
5fcbd29151d2
MERGE -r688:759 trunk -> branches/stable-1.2 (release 1.2, part one).
Florian Pose <fp@igh-essen.com>
parents:
1732
diff
changeset
|
110 |
counter = FREQUENCY; |
5fcbd29151d2
MERGE -r688:759 trunk -> branches/stable-1.2 (release 1.2, part one).
Florian Pose <fp@igh-essen.com>
parents:
1732
diff
changeset
|
111 |
blink = !blink; |
1744
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
112 |
|
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
113 |
rt_sem_wait(&master_sem); |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
114 |
ecrt_master_get_status(master, &master_status); |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
115 |
rt_sem_signal(&master_sem); |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
116 |
|
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
117 |
if (master_status.bus_status != old_status.bus_status) { |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
118 |
printk(KERN_INFO PFX "bus status changed to %i.\n", |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
119 |
master_status.bus_status); |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
120 |
} |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
121 |
if (master_status.bus_tainted != old_status.bus_tainted) { |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
122 |
printk(KERN_INFO PFX "tainted flag changed to %u.\n", |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
123 |
master_status.bus_tainted); |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
124 |
} |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
125 |
if (master_status.slaves_responding != |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
126 |
old_status.slaves_responding) { |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
127 |
printk(KERN_INFO PFX "slaves_responding changed to %u.\n", |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
128 |
master_status.slaves_responding); |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
129 |
} |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
130 |
|
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
131 |
old_status = master_status; |
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
|
132 |
} |
5fcbd29151d2
MERGE -r688:759 trunk -> branches/stable-1.2 (release 1.2, part one).
Florian Pose <fp@igh-essen.com>
parents:
1732
diff
changeset
|
133 |
|
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
134 |
rt_task_wait_period(); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
135 |
} |
220 | 136 |
} |
137 |
||
138 |
/*****************************************************************************/ |
|
139 |
||
140 |
int request_lock(void *data) |
|
141 |
{ |
|
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
|
142 |
// too close to the next real time 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
|
143 |
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
|
144 |
|
382bdb9138ec
RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents:
227
diff
changeset
|
145 |
// allow access |
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
146 |
rt_sem_wait(&master_sem); |
230
382bdb9138ec
RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents:
227
diff
changeset
|
147 |
return 0; |
220 | 148 |
} |
149 |
||
150 |
/*****************************************************************************/ |
|
151 |
||
152 |
void release_lock(void *data) |
|
153 |
{ |
|
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
154 |
rt_sem_signal(&master_sem); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
155 |
} |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
156 |
|
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
157 |
/*****************************************************************************/ |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
158 |
|
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
159 |
int __init init_mod(void) |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
160 |
{ |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
161 |
RTIME tick_period, requested_ticks, now; |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
162 |
|
1744
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
163 |
printk(KERN_INFO PFX "Starting...\n"); |
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
164 |
|
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
165 |
rt_sem_init(&master_sem, 1); |
220 | 166 |
|
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
|
167 |
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
|
168 |
|
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
|
169 |
if (!(master = ecrt_request_master(0))) { |
1744
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
170 |
printk(KERN_ERR PFX "Requesting master 0 failed!\n"); |
220 | 171 |
goto out_return; |
172 |
} |
|
173 |
||
174 |
ecrt_master_callbacks(master, request_lock, release_lock, NULL); |
|
175 |
||
1744
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
176 |
printk(KERN_INFO PFX "Creating 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
|
177 |
if (!(domain1 = ecrt_master_create_domain(master))) { |
1744
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
178 |
printk(KERN_ERR PFX "Domain creation failed!\n"); |
220 | 179 |
goto out_release_master; |
180 |
} |
|
181 |
||
1744
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
182 |
printk(KERN_INFO PFX "Registering PDOs...\n"); |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
183 |
if (ecrt_domain_register_pdo_list(domain1, domain1_pdo_regs)) { |
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
184 |
printk(KERN_ERR PFX "PDO registration failed!\n"); |
220 | 185 |
goto out_release_master; |
186 |
} |
|
187 |
||
1744
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
188 |
printk(KERN_INFO PFX "Activating master...\n"); |
220 | 189 |
if (ecrt_master_activate(master)) { |
1744
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
190 |
printk(KERN_ERR PFX "Failed to activate master!\n"); |
220 | 191 |
goto out_release_master; |
192 |
} |
|
193 |
||
1744
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
194 |
printk(KERN_INFO PFX "Starting cyclic sample thread...\n"); |
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
195 |
requested_ticks = nano2count(TIMERTICKS); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
196 |
tick_period = start_rt_timer(requested_ticks); |
1744
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
197 |
printk(KERN_INFO PFX "RT timer started with %i/%i ticks.\n", |
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
198 |
(int) tick_period, (int) requested_ticks); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
199 |
|
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
200 |
if (rt_task_init(&task, run, 0, 2000, 0, 1, NULL)) { |
1744
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
201 |
printk(KERN_ERR PFX "Failed to init RTAI task!\n"); |
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
202 |
goto out_stop_timer; |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
203 |
} |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
204 |
|
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
205 |
now = rt_get_time(); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
206 |
if (rt_task_make_periodic(&task, now + tick_period, tick_period)) { |
1744
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
207 |
printk(KERN_ERR PFX "Failed to run RTAI task!\n"); |
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
208 |
goto out_stop_task; |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
209 |
} |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
210 |
|
1744
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
211 |
printk(KERN_INFO PFX "Initialized.\n"); |
220 | 212 |
return 0; |
213 |
||
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
214 |
out_stop_task: |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
215 |
rt_task_delete(&task); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
216 |
out_stop_timer: |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
217 |
stop_rt_timer(); |
220 | 218 |
out_release_master: |
1744
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
219 |
printk(KERN_ERR PFX "Releasing master...\n"); |
220 | 220 |
ecrt_release_master(master); |
221 |
out_return: |
|
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
222 |
rt_sem_delete(&master_sem); |
1744
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
223 |
printk(KERN_ERR PFX "Failed to load. Aborting.\n"); |
220 | 224 |
return -1; |
225 |
} |
|
226 |
||
227 |
/*****************************************************************************/ |
|
228 |
||
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
229 |
void __exit cleanup_mod(void) |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
230 |
{ |
1744
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
231 |
printk(KERN_INFO PFX "Stopping...\n"); |
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
232 |
|
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
233 |
rt_task_delete(&task); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
234 |
stop_rt_timer(); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
235 |
ecrt_release_master(master); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
236 |
rt_sem_delete(&master_sem); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
237 |
|
1744
7bc131b92039
MERGE trunk -r770:907 -> branches-1.3 (1.3 changes)
Florian Pose <fp@igh-essen.com>
parents:
1739
diff
changeset
|
238 |
printk(KERN_INFO PFX "Unloading.\n"); |
220 | 239 |
} |
240 |
||
241 |
/*****************************************************************************/ |
|
242 |
||
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
|
243 |
MODULE_LICENSE("GPL"); |
5fcbd29151d2
MERGE -r688:759 trunk -> branches/stable-1.2 (release 1.2, part one).
Florian Pose <fp@igh-essen.com>
parents:
1732
diff
changeset
|
244 |
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
|
245 |
MODULE_DESCRIPTION("EtherCAT RTAI sample module"); |
5fcbd29151d2
MERGE -r688:759 trunk -> branches/stable-1.2 (release 1.2, part one).
Florian Pose <fp@igh-essen.com>
parents:
1732
diff
changeset
|
246 |
|
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
247 |
module_init(init_mod); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
248 |
module_exit(cleanup_mod); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
249 |
|
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
250 |
/*****************************************************************************/ |