author | Florian Pose <fp@igh-essen.com> |
Thu, 18 May 2006 12:47:01 +0000 | |
changeset 248 | f5e94773472d |
parent 246 | 0bf7c769de06 |
child 259 | 87b20532872b |
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" |
382bdb9138ec
RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents:
227
diff
changeset
|
45 |
|
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 |
// comment this for synchronous IO |
220 | 49 |
#define ASYNC |
230
382bdb9138ec
RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents:
227
diff
changeset
|
50 |
|
382bdb9138ec
RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents:
227
diff
changeset
|
51 |
// RTAI task frequency in Hz |
382bdb9138ec
RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents:
227
diff
changeset
|
52 |
#define FREQUENCY 10000 |
382bdb9138ec
RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents:
227
diff
changeset
|
53 |
|
382bdb9138ec
RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents:
227
diff
changeset
|
54 |
#define TIMERTICKS (1000000000 / FREQUENCY) |
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
55 |
|
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
56 |
/*****************************************************************************/ |
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 |
// RTAI |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
59 |
RT_TASK task; |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
60 |
SEM master_sem; |
230
382bdb9138ec
RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents:
227
diff
changeset
|
61 |
cycles_t t_last_start = 0; |
382bdb9138ec
RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents:
227
diff
changeset
|
62 |
cycles_t t_critical; |
220 | 63 |
|
64 |
// EtherCAT |
|
65 |
ec_master_t *master = NULL; |
|
66 |
ec_domain_t *domain1 = NULL; |
|
67 |
||
68 |
// data fields |
|
230
382bdb9138ec
RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents:
227
diff
changeset
|
69 |
void *r_ssi_input; |
220 | 70 |
|
71 |
// channels |
|
72 |
uint32_t k_pos; |
|
73 |
||
74 |
ec_field_init_t domain1_fields[] = { |
|
230
382bdb9138ec
RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents:
227
diff
changeset
|
75 |
{&r_ssi_input, "3", "Beckhoff", "EL5001", "InputValue", 0}, |
382bdb9138ec
RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents:
227
diff
changeset
|
76 |
{NULL, "2", "Beckhoff", "EL4132", "OutputValue", 0}, |
220 | 77 |
{} |
78 |
}; |
|
79 |
||
80 |
/*****************************************************************************/ |
|
81 |
||
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
82 |
void run(long data) |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
83 |
{ |
230
382bdb9138ec
RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents:
227
diff
changeset
|
84 |
while (1) |
382bdb9138ec
RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents:
227
diff
changeset
|
85 |
{ |
382bdb9138ec
RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents:
227
diff
changeset
|
86 |
t_last_start = get_cycles(); |
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
87 |
rt_sem_wait(&master_sem); |
220 | 88 |
|
89 |
#ifdef ASYNC |
|
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
90 |
// receive |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
91 |
ecrt_master_async_receive(master); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
92 |
ecrt_domain_process(domain1); |
220 | 93 |
#else |
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
94 |
// send and receive |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
95 |
ecrt_domain_queue(domain1); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
96 |
ecrt_master_run(master); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
97 |
ecrt_master_sync_io(master); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
98 |
ecrt_domain_process(domain1); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
99 |
#endif |
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 |
// process data |
230
382bdb9138ec
RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents:
227
diff
changeset
|
102 |
k_pos = EC_READ_U32(r_ssi_input); |
220 | 103 |
|
104 |
#ifdef ASYNC |
|
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
105 |
// send |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
106 |
ecrt_domain_queue(domain1); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
107 |
ecrt_master_run(master); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
108 |
ecrt_master_async_send(master); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
109 |
#endif |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
110 |
|
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
111 |
rt_sem_signal(&master_sem); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
112 |
rt_task_wait_period(); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
113 |
} |
220 | 114 |
} |
115 |
||
116 |
/*****************************************************************************/ |
|
117 |
||
118 |
int request_lock(void *data) |
|
119 |
{ |
|
230
382bdb9138ec
RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents:
227
diff
changeset
|
120 |
// too close to the next RT cycle: deny access... |
382bdb9138ec
RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents:
227
diff
changeset
|
121 |
if (get_cycles() - t_last_start > t_critical) return -1; |
382bdb9138ec
RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents:
227
diff
changeset
|
122 |
|
382bdb9138ec
RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents:
227
diff
changeset
|
123 |
// allow access |
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
124 |
rt_sem_wait(&master_sem); |
230
382bdb9138ec
RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents:
227
diff
changeset
|
125 |
return 0; |
220 | 126 |
} |
127 |
||
128 |
/*****************************************************************************/ |
|
129 |
||
130 |
void release_lock(void *data) |
|
131 |
{ |
|
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
132 |
rt_sem_signal(&master_sem); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
133 |
} |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
134 |
|
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
135 |
/*****************************************************************************/ |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
136 |
|
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
137 |
int __init init_mod(void) |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
138 |
{ |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
139 |
RTIME tick_period, requested_ticks, now; |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
140 |
|
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
141 |
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
|
142 |
|
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
143 |
rt_sem_init(&master_sem, 1); |
220 | 144 |
|
230
382bdb9138ec
RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents:
227
diff
changeset
|
145 |
t_critical = cpu_khz * 800 / FREQUENCY; // ticks for 80% |
382bdb9138ec
RTAI sample with optimized jitter.
Florian Pose <fp@igh-essen.com>
parents:
227
diff
changeset
|
146 |
|
220 | 147 |
if ((master = ecrt_request_master(0)) == NULL) { |
148 |
printk(KERN_ERR "Requesting master 0 failed!\n"); |
|
149 |
goto out_return; |
|
150 |
} |
|
151 |
||
152 |
ecrt_master_callbacks(master, request_lock, release_lock, NULL); |
|
153 |
||
154 |
printk(KERN_INFO "Registering domain...\n"); |
|
155 |
if (!(domain1 = ecrt_master_create_domain(master))) |
|
156 |
{ |
|
157 |
printk(KERN_ERR "Domain creation failed!\n"); |
|
158 |
goto out_release_master; |
|
159 |
} |
|
160 |
||
161 |
printk(KERN_INFO "Registering domain fields...\n"); |
|
162 |
if (ecrt_domain_register_field_list(domain1, domain1_fields)) { |
|
163 |
printk(KERN_ERR "Field registration failed!\n"); |
|
164 |
goto out_release_master; |
|
165 |
} |
|
166 |
||
167 |
printk(KERN_INFO "Activating master...\n"); |
|
168 |
if (ecrt_master_activate(master)) { |
|
169 |
printk(KERN_ERR "Failed to activate master!\n"); |
|
170 |
goto out_release_master; |
|
171 |
} |
|
172 |
||
173 |
#if 0 |
|
174 |
if (ecrt_master_fetch_sdo_lists(master)) { |
|
175 |
printk(KERN_ERR "Failed to fetch SDO lists!\n"); |
|
176 |
goto out_deactivate; |
|
177 |
} |
|
178 |
ecrt_master_print(master, 2); |
|
179 |
#else |
|
180 |
ecrt_master_print(master, 0); |
|
181 |
#endif |
|
182 |
||
183 |
#if 0 |
|
184 |
if (!(slave = ecrt_master_get_slave(master, "5"))) { |
|
185 |
printk(KERN_ERR "Failed to get slave 5!\n"); |
|
186 |
goto out_deactivate; |
|
187 |
} |
|
188 |
||
189 |
if (ecrt_slave_sdo_write_exp8(slave, 0x4061, 1, 0) || |
|
190 |
ecrt_slave_sdo_write_exp8(slave, 0x4061, 2, 1) || |
|
191 |
ecrt_slave_sdo_write_exp8(slave, 0x4061, 3, 1) || |
|
192 |
ecrt_slave_sdo_write_exp8(slave, 0x4066, 0, 0) || |
|
193 |
ecrt_slave_sdo_write_exp8(slave, 0x4067, 0, 4) || |
|
194 |
ecrt_slave_sdo_write_exp8(slave, 0x4068, 0, 0) || |
|
195 |
ecrt_slave_sdo_write_exp8(slave, 0x4069, 0, 25) || |
|
196 |
ecrt_slave_sdo_write_exp8(slave, 0x406A, 0, 25) || |
|
197 |
ecrt_slave_sdo_write_exp8(slave, 0x406B, 0, 50)) { |
|
198 |
printk(KERN_ERR "Failed to configure SSI slave!\n"); |
|
199 |
goto out_deactivate; |
|
200 |
} |
|
201 |
#endif |
|
202 |
||
203 |
#if 0 |
|
204 |
printk(KERN_INFO "Writing alias...\n"); |
|
205 |
if (ecrt_slave_sdo_write_exp16(slave, 0xBEEF)) { |
|
206 |
printk(KERN_ERR "Failed to write alias!\n"); |
|
207 |
goto out_deactivate; |
|
208 |
} |
|
209 |
#endif |
|
210 |
||
211 |
#ifdef ASYNC |
|
212 |
// send once and wait... |
|
213 |
ecrt_master_prepare_async_io(master); |
|
214 |
#endif |
|
215 |
||
216 |
if (ecrt_master_start_eoe(master)) { |
|
217 |
printk(KERN_ERR "Failed to start EoE processing!\n"); |
|
218 |
goto out_deactivate; |
|
219 |
} |
|
220 |
||
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
221 |
printk("Starting cyclic sample thread...\n"); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
222 |
requested_ticks = nano2count(TIMERTICKS); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
223 |
tick_period = start_rt_timer(requested_ticks); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
224 |
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
|
225 |
(int) tick_period, (int) requested_ticks); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
226 |
|
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
227 |
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
|
228 |
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
|
229 |
goto out_stop_timer; |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
230 |
} |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
231 |
|
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
232 |
now = rt_get_time(); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
233 |
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
|
234 |
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
|
235 |
goto out_stop_task; |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
236 |
} |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
237 |
|
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
238 |
printk(KERN_INFO "=== EtherCAT RTAI sample module started. ===\n"); |
220 | 239 |
return 0; |
240 |
||
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
241 |
out_stop_task: |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
242 |
rt_task_delete(&task); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
243 |
out_stop_timer: |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
244 |
stop_rt_timer(); |
220 | 245 |
out_deactivate: |
246 |
ecrt_master_deactivate(master); |
|
247 |
out_release_master: |
|
248 |
ecrt_release_master(master); |
|
249 |
out_return: |
|
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
250 |
rt_sem_delete(&master_sem); |
220 | 251 |
return -1; |
252 |
} |
|
253 |
||
254 |
/*****************************************************************************/ |
|
255 |
||
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
256 |
void __exit cleanup_mod(void) |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
257 |
{ |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
258 |
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
|
259 |
|
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
260 |
rt_task_delete(&task); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
261 |
stop_rt_timer(); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
262 |
ecrt_master_deactivate(master); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
263 |
ecrt_release_master(master); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
264 |
rt_sem_delete(&master_sem); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
265 |
|
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
266 |
printk(KERN_INFO "=== EtherCAT RTAI sample module stopped. ===\n"); |
220 | 267 |
} |
268 |
||
269 |
/*****************************************************************************/ |
|
270 |
||
271 |
MODULE_LICENSE("GPL"); |
|
272 |
MODULE_AUTHOR ("Florian Pose <fp@igh-essen.com>"); |
|
225
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
273 |
MODULE_DESCRIPTION ("EtherCAT RTAI sample module"); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
274 |
|
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
275 |
module_init(init_mod); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
276 |
module_exit(cleanup_mod); |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
277 |
|
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
278 |
/*****************************************************************************/ |
9e8150db6fc8
Applied RTAI interface to RTAI example.
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
279 |