author | Florian Pose <fp@igh-essen.com> |
Tue, 02 Jan 2007 13:27:03 +0000 | |
changeset 510 | 0d0c6fe0e3b2 |
parent 509 | 87baea61d0c7 |
child 512 | 24292123d174 |
permissions | -rw-r--r-- |
220 | 1 |
/****************************************************************************** |
2 |
* |
|
3 |
* $Id$ |
|
4 |
* |
|
5 |
* Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH |
|
6 |
* |
|
7 |
* This file is part of the IgH EtherCAT Master. |
|
8 |
* |
|
9 |
* The IgH EtherCAT Master is free software; you can redistribute it |
|
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:
226
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:
226
diff
changeset
|
12 |
* License, or (at your option) any later version. |
220 | 13 |
* |
14 |
* The IgH EtherCAT Master is distributed in the hope that it will be |
|
15 |
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
* GNU General Public License for more details. |
|
18 |
* |
|
19 |
* You should have received a copy of the GNU General Public License |
|
20 |
* along with the IgH EtherCAT Master; if not, write to the Free Software |
|
21 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
22 |
* |
|
246
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
226
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:
226
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:
226
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:
226
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:
226
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:
226
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:
226
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:
226
diff
changeset
|
30 |
* Technology, IP and trade marks. |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
226
diff
changeset
|
31 |
* |
220 | 32 |
*****************************************************************************/ |
33 |
||
34 |
#include <linux/module.h> |
|
35 |
#include <linux/delay.h> |
|
36 |
#include <linux/timer.h> |
|
37 |
#include <linux/spinlock.h> |
|
38 |
#include <linux/interrupt.h> |
|
39 |
||
223
daa5e5656b35
Applied new path information to example modules.
Florian Pose <fp@igh-essen.com>
parents:
220
diff
changeset
|
40 |
#include "../../include/ecrt.h" // EtherCAT realtime interface |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
280
diff
changeset
|
41 |
#include "../../include/ecdb.h" // EtherCAT slave database |
220 | 42 |
|
43 |
#define FREQUENCY 100 |
|
44 |
||
472
bd2e0f220289
Mini example with KBUS again.
Florian Pose <fp@igh-essen.com>
parents:
463
diff
changeset
|
45 |
#define KBUS |
457
2b4ba84b6058
Minor changes to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
454
diff
changeset
|
46 |
|
220 | 47 |
/*****************************************************************************/ |
48 |
||
49 |
struct timer_list timer; |
|
50 |
||
51 |
// EtherCAT |
|
52 |
ec_master_t *master = NULL; |
|
53 |
ec_domain_t *domain1 = NULL; |
|
54 |
spinlock_t master_lock = SPIN_LOCK_UNLOCKED; |
|
55 |
||
56 |
// data fields |
|
457
2b4ba84b6058
Minor changes to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
454
diff
changeset
|
57 |
#ifdef KBUS |
416
4f007cd2a79d
ecrt_domain_register_pdo_range() implemented.
Florian Pose <fp@igh-essen.com>
parents:
348
diff
changeset
|
58 |
void *r_inputs; |
4f007cd2a79d
ecrt_domain_register_pdo_range() implemented.
Florian Pose <fp@igh-essen.com>
parents:
348
diff
changeset
|
59 |
void *r_outputs; |
446 | 60 |
#endif |
61 |
||
62 |
void *r_ana_in; |
|
63 |
||
64 |
#if 1 |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
280
diff
changeset
|
65 |
ec_pdo_reg_t domain1_pdos[] = { |
446 | 66 |
{"2", Beckhoff_EL3102_Input1, &r_ana_in}, |
220 | 67 |
{} |
68 |
}; |
|
416
4f007cd2a79d
ecrt_domain_register_pdo_range() implemented.
Florian Pose <fp@igh-essen.com>
parents:
348
diff
changeset
|
69 |
#endif |
220 | 70 |
|
71 |
/*****************************************************************************/ |
|
72 |
||
73 |
void run(unsigned long data) |
|
74 |
{ |
|
75 |
static unsigned int counter = 0; |
|
416
4f007cd2a79d
ecrt_domain_register_pdo_range() implemented.
Florian Pose <fp@igh-essen.com>
parents:
348
diff
changeset
|
76 |
static unsigned int einaus = 0; |
220 | 77 |
|
78 |
spin_lock(&master_lock); |
|
79 |
||
80 |
// receive |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
280
diff
changeset
|
81 |
ecrt_master_receive(master); |
220 | 82 |
ecrt_domain_process(domain1); |
83 |
||
84 |
// process data |
|
85 |
//k_pos = EC_READ_U32(r_ssi); |
|
457
2b4ba84b6058
Minor changes to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
454
diff
changeset
|
86 |
#ifdef KBUS |
454
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
452
diff
changeset
|
87 |
EC_WRITE_U8(r_outputs + 2, einaus ? 0xFF : 0x00); |
457
2b4ba84b6058
Minor changes to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
454
diff
changeset
|
88 |
#endif |
220 | 89 |
|
90 |
// send |
|
509
87baea61d0c7
Adjusted examples to 1.2.0 interface changes.
Florian Pose <fp@igh-essen.com>
parents:
472
diff
changeset
|
91 |
ecrt_domain_queue(domain1); |
220 | 92 |
ecrt_master_run(master); |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
280
diff
changeset
|
93 |
ecrt_master_send(master); |
220 | 94 |
|
95 |
spin_unlock(&master_lock); |
|
96 |
||
97 |
if (counter) { |
|
98 |
counter--; |
|
99 |
} |
|
100 |
else { |
|
101 |
counter = FREQUENCY; |
|
416
4f007cd2a79d
ecrt_domain_register_pdo_range() implemented.
Florian Pose <fp@igh-essen.com>
parents:
348
diff
changeset
|
102 |
einaus = !einaus; |
220 | 103 |
} |
104 |
||
105 |
// restart timer |
|
106 |
timer.expires += HZ / FREQUENCY; |
|
107 |
add_timer(&timer); |
|
108 |
} |
|
109 |
||
110 |
/*****************************************************************************/ |
|
111 |
||
112 |
int request_lock(void *data) |
|
113 |
{ |
|
226
07247920a7ba
EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
114 |
spin_lock_bh(&master_lock); |
07247920a7ba
EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
115 |
return 0; // access allowed |
220 | 116 |
} |
117 |
||
118 |
/*****************************************************************************/ |
|
119 |
||
120 |
void release_lock(void *data) |
|
121 |
{ |
|
226
07247920a7ba
EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
122 |
spin_unlock_bh(&master_lock); |
220 | 123 |
} |
124 |
||
125 |
/*****************************************************************************/ |
|
126 |
||
127 |
int __init init_mini_module(void) |
|
128 |
{ |
|
463
938de5ebe1ca
minimal example with SDO configs.
Florian Pose <fp@igh-essen.com>
parents:
457
diff
changeset
|
129 |
#if 1 |
454
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
452
diff
changeset
|
130 |
ec_slave_t *slave; |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
452
diff
changeset
|
131 |
#endif |
329
d004349777fc
SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
132 |
|
220 | 133 |
printk(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n"); |
134 |
||
509
87baea61d0c7
Adjusted examples to 1.2.0 interface changes.
Florian Pose <fp@igh-essen.com>
parents:
472
diff
changeset
|
135 |
if (!(master = ecrt_request_master(0))) { |
220 | 136 |
printk(KERN_ERR "Requesting master 0 failed!\n"); |
137 |
goto out_return; |
|
138 |
} |
|
139 |
||
140 |
ecrt_master_callbacks(master, request_lock, release_lock, NULL); |
|
141 |
||
142 |
printk(KERN_INFO "Registering domain...\n"); |
|
509
87baea61d0c7
Adjusted examples to 1.2.0 interface changes.
Florian Pose <fp@igh-essen.com>
parents:
472
diff
changeset
|
143 |
if (!(domain1 = ecrt_master_create_domain(master))) { |
220 | 144 |
printk(KERN_ERR "Domain creation failed!\n"); |
145 |
goto out_release_master; |
|
146 |
} |
|
147 |
||
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
280
diff
changeset
|
148 |
printk(KERN_INFO "Registering PDOs...\n"); |
446 | 149 |
#if 1 |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
280
diff
changeset
|
150 |
if (ecrt_domain_register_pdo_list(domain1, domain1_pdos)) { |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
280
diff
changeset
|
151 |
printk(KERN_ERR "PDO registration failed!\n"); |
220 | 152 |
goto out_release_master; |
153 |
} |
|
416
4f007cd2a79d
ecrt_domain_register_pdo_range() implemented.
Florian Pose <fp@igh-essen.com>
parents:
348
diff
changeset
|
154 |
#endif |
446 | 155 |
|
457
2b4ba84b6058
Minor changes to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
454
diff
changeset
|
156 |
#ifdef KBUS |
416
4f007cd2a79d
ecrt_domain_register_pdo_range() implemented.
Florian Pose <fp@igh-essen.com>
parents:
348
diff
changeset
|
157 |
if (!ecrt_domain_register_pdo_range(domain1, "0", Beckhoff_BK1120, |
4f007cd2a79d
ecrt_domain_register_pdo_range() implemented.
Florian Pose <fp@igh-essen.com>
parents:
348
diff
changeset
|
158 |
EC_DIR_OUTPUT, 0, 4, &r_outputs)) { |
4f007cd2a79d
ecrt_domain_register_pdo_range() implemented.
Florian Pose <fp@igh-essen.com>
parents:
348
diff
changeset
|
159 |
printk(KERN_ERR "PDO registration failed!\n"); |
4f007cd2a79d
ecrt_domain_register_pdo_range() implemented.
Florian Pose <fp@igh-essen.com>
parents:
348
diff
changeset
|
160 |
goto out_release_master; |
4f007cd2a79d
ecrt_domain_register_pdo_range() implemented.
Florian Pose <fp@igh-essen.com>
parents:
348
diff
changeset
|
161 |
} |
4f007cd2a79d
ecrt_domain_register_pdo_range() implemented.
Florian Pose <fp@igh-essen.com>
parents:
348
diff
changeset
|
162 |
if (!ecrt_domain_register_pdo_range(domain1, "0", Beckhoff_BK1120, |
4f007cd2a79d
ecrt_domain_register_pdo_range() implemented.
Florian Pose <fp@igh-essen.com>
parents:
348
diff
changeset
|
163 |
EC_DIR_INPUT, 0, 4, &r_inputs)) { |
4f007cd2a79d
ecrt_domain_register_pdo_range() implemented.
Florian Pose <fp@igh-essen.com>
parents:
348
diff
changeset
|
164 |
printk(KERN_ERR "PDO registration failed!\n"); |
4f007cd2a79d
ecrt_domain_register_pdo_range() implemented.
Florian Pose <fp@igh-essen.com>
parents:
348
diff
changeset
|
165 |
goto out_release_master; |
4f007cd2a79d
ecrt_domain_register_pdo_range() implemented.
Florian Pose <fp@igh-essen.com>
parents:
348
diff
changeset
|
166 |
} |
446 | 167 |
#endif |
416
4f007cd2a79d
ecrt_domain_register_pdo_range() implemented.
Florian Pose <fp@igh-essen.com>
parents:
348
diff
changeset
|
168 |
|
463
938de5ebe1ca
minimal example with SDO configs.
Florian Pose <fp@igh-essen.com>
parents:
457
diff
changeset
|
169 |
#if 1 |
938de5ebe1ca
minimal example with SDO configs.
Florian Pose <fp@igh-essen.com>
parents:
457
diff
changeset
|
170 |
if (!(slave = ecrt_master_get_slave(master, "2"))) |
329
d004349777fc
SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
171 |
goto out_release_master; |
d004349777fc
SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
172 |
|
d004349777fc
SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
173 |
if (ecrt_slave_conf_sdo8(slave, 0x4061, 1, 0)) |
d004349777fc
SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
174 |
goto out_release_master; |
416
4f007cd2a79d
ecrt_domain_register_pdo_range() implemented.
Florian Pose <fp@igh-essen.com>
parents:
348
diff
changeset
|
175 |
#endif |
329
d004349777fc
SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
176 |
|
220 | 177 |
printk(KERN_INFO "Activating master...\n"); |
178 |
if (ecrt_master_activate(master)) { |
|
179 |
printk(KERN_ERR "Failed to activate master!\n"); |
|
180 |
goto out_release_master; |
|
181 |
} |
|
182 |
||
183 |
printk("Starting cyclic sample thread.\n"); |
|
184 |
init_timer(&timer); |
|
185 |
timer.function = run; |
|
186 |
timer.expires = jiffies + 10; |
|
187 |
add_timer(&timer); |
|
188 |
||
189 |
printk(KERN_INFO "=== Minimal EtherCAT environment started. ===\n"); |
|
190 |
return 0; |
|
191 |
||
192 |
out_release_master: |
|
193 |
ecrt_release_master(master); |
|
194 |
out_return: |
|
195 |
return -1; |
|
196 |
} |
|
197 |
||
198 |
/*****************************************************************************/ |
|
199 |
||
200 |
void __exit cleanup_mini_module(void) |
|
201 |
{ |
|
202 |
printk(KERN_INFO "=== Stopping Minimal EtherCAT environment... ===\n"); |
|
203 |
||
449
3caf8ff4d8a2
Moved functionality of ecrt_master_deactivate() (now deprecated) to ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents:
446
diff
changeset
|
204 |
del_timer_sync(&timer); |
3caf8ff4d8a2
Moved functionality of ecrt_master_deactivate() (now deprecated) to ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents:
446
diff
changeset
|
205 |
printk(KERN_INFO "Releasing master...\n"); |
3caf8ff4d8a2
Moved functionality of ecrt_master_deactivate() (now deprecated) to ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents:
446
diff
changeset
|
206 |
ecrt_release_master(master); |
220 | 207 |
|
208 |
printk(KERN_INFO "=== Minimal EtherCAT environment stopped. ===\n"); |
|
209 |
} |
|
210 |
||
211 |
/*****************************************************************************/ |
|
212 |
||
213 |
MODULE_LICENSE("GPL"); |
|
214 |
MODULE_AUTHOR ("Florian Pose <fp@igh-essen.com>"); |
|
215 |
MODULE_DESCRIPTION ("EtherCAT minimal test environment"); |
|
216 |
||
217 |
module_init(init_mini_module); |
|
218 |
module_exit(cleanup_mini_module); |
|
219 |
||
220 |
/*****************************************************************************/ |