author | Florian Pose <fp@igh-essen.com> |
Fri, 22 Feb 2008 16:04:23 +0000 | |
changeset 817 | 118dea2fa505 |
parent 814 | a51f857b1b2d |
child 818 | b6c87ae254c9 |
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/timer.h> |
|
36 |
#include <linux/spinlock.h> |
|
37 |
#include <linux/interrupt.h> |
|
38 |
||
223
daa5e5656b35
Applied new path information to example modules.
Florian Pose <fp@igh-essen.com>
parents:
220
diff
changeset
|
39 |
#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
|
40 |
#include "../../include/ecdb.h" // EtherCAT slave database |
220 | 41 |
|
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
42 |
#define PFX "ec_mini: " |
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
43 |
|
220 | 44 |
#define FREQUENCY 100 |
45 |
||
516
f703e33ee395
Adjusted examples to EtherLab starter kit hardware.
Florian Pose <fp@igh-essen.com>
parents:
513
diff
changeset
|
46 |
//#define KBUS |
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
47 |
#define PDOS |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
48 |
#define MAPPING |
809 | 49 |
#define EXTERNAL_MEMORY |
457
2b4ba84b6058
Minor changes to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
454
diff
changeset
|
50 |
|
220 | 51 |
/*****************************************************************************/ |
52 |
||
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
53 |
static struct timer_list timer; |
220 | 54 |
|
55 |
// EtherCAT |
|
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
56 |
static ec_master_t *master = NULL; |
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
57 |
static ec_domain_t *domain1 = NULL; |
220 | 58 |
spinlock_t master_lock = SPIN_LOCK_UNLOCKED; |
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
59 |
static ec_master_state_t master_state, old_state = {}; |
220 | 60 |
|
61 |
// data fields |
|
457
2b4ba84b6058
Minor changes to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
454
diff
changeset
|
62 |
#ifdef KBUS |
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
63 |
static void *r_inputs; |
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
64 |
static void *r_outputs; |
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
65 |
#endif |
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
66 |
|
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
67 |
#ifdef MAPPING |
793
3b297ff8284f
Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents:
792
diff
changeset
|
68 |
const ec_pdo_entry_info_t el3162_channel1[] = { |
3b297ff8284f
Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents:
792
diff
changeset
|
69 |
{0x3101, 1, 8}, // status |
3b297ff8284f
Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents:
792
diff
changeset
|
70 |
{0x3101, 2, 16} // value |
3b297ff8284f
Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents:
792
diff
changeset
|
71 |
}; |
3b297ff8284f
Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents:
792
diff
changeset
|
72 |
|
3b297ff8284f
Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents:
792
diff
changeset
|
73 |
const ec_pdo_entry_info_t el3162_channel2[] = { |
3b297ff8284f
Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents:
792
diff
changeset
|
74 |
{0x3102, 1, 8}, // status |
3b297ff8284f
Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents:
792
diff
changeset
|
75 |
{0x3102, 2, 16} // value |
3b297ff8284f
Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents:
792
diff
changeset
|
76 |
}; |
3b297ff8284f
Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents:
792
diff
changeset
|
77 |
|
809 | 78 |
const ec_pdo_info_t el3162_mapping[] = { |
793
3b297ff8284f
Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents:
792
diff
changeset
|
79 |
{EC_DIR_INPUT, 0x1A00, 2, el3162_channel1}, |
3b297ff8284f
Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents:
792
diff
changeset
|
80 |
{EC_DIR_INPUT, 0x1A01, 2, el3162_channel2}, |
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
81 |
}; |
809 | 82 |
|
83 |
const ec_pdo_entry_info_t el2004_channels[] = { |
|
84 |
{0x3001, 1, 1}, // Value 1 |
|
85 |
{0x3001, 2, 1}, // Value 2 |
|
86 |
{0x3001, 3, 1}, // Value 3 |
|
87 |
{0x3001, 4, 1} // Value 4 |
|
88 |
}; |
|
89 |
||
90 |
const ec_pdo_info_t el2004_mapping[] = { |
|
91 |
{EC_DIR_OUTPUT, 0x1600, 1, &el2004_channels[0]}, |
|
92 |
{EC_DIR_OUTPUT, 0x1601, 1, &el2004_channels[1]}, |
|
93 |
{EC_DIR_OUTPUT, 0x1602, 1, &el2004_channels[2]}, |
|
94 |
{EC_DIR_OUTPUT, 0x1603, 1, &el2004_channels[3]}, |
|
95 |
}; |
|
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
96 |
#endif |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
97 |
|
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
98 |
#ifdef PDOS |
809 | 99 |
static uint8_t *pd; /**< Process data. */ |
100 |
static unsigned int off_ana_in; |
|
101 |
static unsigned int off_dig_out; |
|
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
102 |
|
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
103 |
const static ec_pdo_entry_reg_t domain1_regs[] = { |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
104 |
{0, 1, Beckhoff_EL3162, 0x3101, 2, &off_ana_in}, |
809 | 105 |
{0, 3, Beckhoff_EL2004, 0x3001, 1, &off_dig_out}, |
220 | 106 |
{} |
107 |
}; |
|
416
4f007cd2a79d
ecrt_domain_register_pdo_range() implemented.
Florian Pose <fp@igh-essen.com>
parents:
348
diff
changeset
|
108 |
#endif |
220 | 109 |
|
110 |
/*****************************************************************************/ |
|
111 |
||
112 |
void run(unsigned long data) |
|
113 |
{ |
|
114 |
static unsigned int counter = 0; |
|
512
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
115 |
static unsigned int blink = 0; |
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
116 |
|
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
117 |
// receive |
220 | 118 |
spin_lock(&master_lock); |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
280
diff
changeset
|
119 |
ecrt_master_receive(master); |
220 | 120 |
ecrt_domain_process(domain1); |
512
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
121 |
spin_unlock(&master_lock); |
220 | 122 |
|
123 |
// process data |
|
809 | 124 |
EC_WRITE_U8(pd + off_dig_out, blink ? 0x0F : 0x00); |
512
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
125 |
|
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
126 |
if (counter) { |
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
127 |
counter--; |
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
128 |
} |
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
129 |
else { |
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
130 |
counter = FREQUENCY; |
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
131 |
blink = !blink; |
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
132 |
|
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
133 |
spin_lock(&master_lock); |
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
134 |
ecrt_master_state(master, &master_state); |
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
135 |
spin_unlock(&master_lock); |
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
136 |
|
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
137 |
if (master_state.bus_state != old_state.bus_state) { |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
138 |
printk(KERN_INFO PFX "bus state changed to %i.\n", |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
139 |
master_state.bus_state); |
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
140 |
} |
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
141 |
if (master_state.bus_tainted != old_state.bus_tainted) { |
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
142 |
printk(KERN_INFO PFX "tainted flag changed to %u.\n", |
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
143 |
master_state.bus_tainted); |
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
144 |
} |
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
145 |
if (master_state.slaves_responding != |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
146 |
old_state.slaves_responding) { |
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
147 |
printk(KERN_INFO PFX "slaves_responding changed to %u.\n", |
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
148 |
master_state.slaves_responding); |
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
149 |
} |
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
150 |
|
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
151 |
old_state = master_state; |
512
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
152 |
} |
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
153 |
|
457
2b4ba84b6058
Minor changes to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
454
diff
changeset
|
154 |
#ifdef KBUS |
512
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
155 |
EC_WRITE_U8(r_outputs + 2, blink ? 0xFF : 0x00); |
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
156 |
#endif |
513
d91976aea8c8
Minor changes in minimal example.
Florian Pose <fp@igh-essen.com>
parents:
512
diff
changeset
|
157 |
|
220 | 158 |
// send |
512
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
159 |
spin_lock(&master_lock); |
509
87baea61d0c7
Adjusted examples to 1.2.0 interface changes.
Florian Pose <fp@igh-essen.com>
parents:
472
diff
changeset
|
160 |
ecrt_domain_queue(domain1); |
516
f703e33ee395
Adjusted examples to EtherLab starter kit hardware.
Florian Pose <fp@igh-essen.com>
parents:
513
diff
changeset
|
161 |
spin_unlock(&master_lock); |
f703e33ee395
Adjusted examples to EtherLab starter kit hardware.
Florian Pose <fp@igh-essen.com>
parents:
513
diff
changeset
|
162 |
|
f703e33ee395
Adjusted examples to EtherLab starter kit hardware.
Florian Pose <fp@igh-essen.com>
parents:
513
diff
changeset
|
163 |
spin_lock(&master_lock); |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
280
diff
changeset
|
164 |
ecrt_master_send(master); |
220 | 165 |
spin_unlock(&master_lock); |
166 |
||
167 |
// restart timer |
|
168 |
timer.expires += HZ / FREQUENCY; |
|
169 |
add_timer(&timer); |
|
170 |
} |
|
171 |
||
172 |
/*****************************************************************************/ |
|
173 |
||
174 |
int request_lock(void *data) |
|
175 |
{ |
|
516
f703e33ee395
Adjusted examples to EtherLab starter kit hardware.
Florian Pose <fp@igh-essen.com>
parents:
513
diff
changeset
|
176 |
spin_lock(&master_lock); |
226
07247920a7ba
EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
177 |
return 0; // access allowed |
220 | 178 |
} |
179 |
||
180 |
/*****************************************************************************/ |
|
181 |
||
182 |
void release_lock(void *data) |
|
183 |
{ |
|
516
f703e33ee395
Adjusted examples to EtherLab starter kit hardware.
Florian Pose <fp@igh-essen.com>
parents:
513
diff
changeset
|
184 |
spin_unlock(&master_lock); |
220 | 185 |
} |
186 |
||
187 |
/*****************************************************************************/ |
|
188 |
||
189 |
int __init init_mini_module(void) |
|
190 |
{ |
|
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
191 |
#ifdef MAPPING |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
192 |
ec_slave_config_t *sc; |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
193 |
#endif |
809 | 194 |
#ifdef EXTERNAL_MEMORY |
195 |
unsigned int size; |
|
196 |
#endif |
|
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
197 |
|
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
198 |
printk(KERN_INFO PFX "Starting...\n"); |
220 | 199 |
|
509
87baea61d0c7
Adjusted examples to 1.2.0 interface changes.
Florian Pose <fp@igh-essen.com>
parents:
472
diff
changeset
|
200 |
if (!(master = ecrt_request_master(0))) { |
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
201 |
printk(KERN_ERR PFX "Requesting master 0 failed!\n"); |
220 | 202 |
goto out_return; |
203 |
} |
|
204 |
||
205 |
ecrt_master_callbacks(master, request_lock, release_lock, NULL); |
|
206 |
||
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
207 |
printk(KERN_INFO PFX "Registering domain...\n"); |
509
87baea61d0c7
Adjusted examples to 1.2.0 interface changes.
Florian Pose <fp@igh-essen.com>
parents:
472
diff
changeset
|
208 |
if (!(domain1 = ecrt_master_create_domain(master))) { |
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
209 |
printk(KERN_ERR PFX "Domain creation failed!\n"); |
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
210 |
goto out_release_master; |
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
211 |
} |
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
212 |
|
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
213 |
#ifdef MAPPING |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
214 |
printk(KERN_INFO PFX "Configuring Pdo mapping...\n"); |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
215 |
if (!(sc = ecrt_master_slave_config(master, 0, 1, Beckhoff_EL3162))) { |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
216 |
printk(KERN_ERR PFX "Failed to get slave configuration.\n"); |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
217 |
goto out_release_master; |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
218 |
} |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
219 |
|
809 | 220 |
if (ecrt_slave_config_mapping(sc, 2, el3162_mapping)) { |
221 |
printk(KERN_ERR PFX "Failed to configure Pdo mapping.\n"); |
|
222 |
goto out_release_master; |
|
223 |
} |
|
224 |
||
225 |
if (!(sc = ecrt_master_slave_config(master, 0, 3, Beckhoff_EL2004))) { |
|
226 |
printk(KERN_ERR PFX "Failed to get slave configuration.\n"); |
|
227 |
goto out_release_master; |
|
228 |
} |
|
229 |
||
230 |
if (ecrt_slave_config_mapping(sc, 4, el2004_mapping)) { |
|
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
231 |
printk(KERN_ERR PFX "Failed to configure Pdo mapping.\n"); |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
232 |
goto out_release_master; |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
233 |
} |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
234 |
#endif |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
235 |
|
814 | 236 |
printk(KERN_INFO PFX "Registering Pdo entries...\n"); |
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
237 |
#ifdef PDOS |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
238 |
if (ecrt_domain_reg_pdo_entry_list(domain1, domain1_regs)) { |
814 | 239 |
printk(KERN_ERR PFX "Pdo entry registration failed!\n"); |
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
240 |
goto out_release_master; |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
241 |
} |
635
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
242 |
#endif |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
243 |
|
809 | 244 |
#ifdef EXTERNAL_MEMORY |
245 |
if ((size = ecrt_domain_size(domain1))) { |
|
246 |
if (!(pd = (uint8_t *) kmalloc(size, GFP_KERNEL))) { |
|
247 |
printk(KERN_ERR PFX "Failed to allocate %u bytes of process data" |
|
248 |
" memory!\n", size); |
|
249 |
goto out_release_master; |
|
250 |
} |
|
251 |
ecrt_domain_external_memory(domain1, pd); |
|
252 |
} |
|
253 |
#endif |
|
254 |
||
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
255 |
printk(KERN_INFO PFX "Activating master...\n"); |
220 | 256 |
if (ecrt_master_activate(master)) { |
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
257 |
printk(KERN_ERR PFX "Failed to activate master!\n"); |
809 | 258 |
#ifdef EXTERNAL_MEMORY |
259 |
goto out_free_process_data; |
|
260 |
#else |
|
261 |
goto out_release_master; |
|
262 |
#endif |
|
263 |
} |
|
264 |
||
265 |
#ifndef EXTERNAL_MEMORY |
|
266 |
// Get internal process data for domain |
|
267 |
pd = ecrt_domain_data(domain1); |
|
268 |
#endif |
|
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
269 |
|
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
270 |
printk(KERN_INFO PFX "Starting cyclic sample thread.\n"); |
220 | 271 |
init_timer(&timer); |
272 |
timer.function = run; |
|
273 |
timer.expires = jiffies + 10; |
|
274 |
add_timer(&timer); |
|
275 |
||
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
276 |
printk(KERN_INFO PFX "Started.\n"); |
220 | 277 |
return 0; |
278 |
||
809 | 279 |
#ifdef EXTERNAL_MEMORY |
280 |
out_free_process_data: |
|
281 |
kfree(pd); |
|
282 |
#endif |
|
283 |
out_release_master: |
|
654
8278e1e27010
Minor changes in minimal example.
Florian Pose <fp@igh-essen.com>
parents:
643
diff
changeset
|
284 |
printk(KERN_ERR PFX "Releasing master...\n"); |
220 | 285 |
ecrt_release_master(master); |
809 | 286 |
out_return: |
654
8278e1e27010
Minor changes in minimal example.
Florian Pose <fp@igh-essen.com>
parents:
643
diff
changeset
|
287 |
printk(KERN_ERR PFX "Failed to load. Aborting.\n"); |
220 | 288 |
return -1; |
289 |
} |
|
290 |
||
291 |
/*****************************************************************************/ |
|
292 |
||
293 |
void __exit cleanup_mini_module(void) |
|
294 |
{ |
|
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
295 |
printk(KERN_INFO PFX "Stopping...\n"); |
220 | 296 |
|
449
3caf8ff4d8a2
Moved functionality of ecrt_master_deactivate() (now deprecated) to ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents:
446
diff
changeset
|
297 |
del_timer_sync(&timer); |
809 | 298 |
|
299 |
#ifdef EXTERNAL_MEMORY |
|
300 |
kfree(pd); |
|
301 |
#endif |
|
302 |
||
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
303 |
printk(KERN_INFO PFX "Releasing master...\n"); |
449
3caf8ff4d8a2
Moved functionality of ecrt_master_deactivate() (now deprecated) to ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents:
446
diff
changeset
|
304 |
ecrt_release_master(master); |
220 | 305 |
|
654
8278e1e27010
Minor changes in minimal example.
Florian Pose <fp@igh-essen.com>
parents:
643
diff
changeset
|
306 |
printk(KERN_INFO PFX "Unloading.\n"); |
220 | 307 |
} |
308 |
||
309 |
/*****************************************************************************/ |
|
310 |
||
311 |
MODULE_LICENSE("GPL"); |
|
512
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
312 |
MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>"); |
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
313 |
MODULE_DESCRIPTION("EtherCAT minimal test environment"); |
220 | 314 |
|
315 |
module_init(init_mini_module); |
|
316 |
module_exit(cleanup_mini_module); |
|
317 |
||
318 |
/*****************************************************************************/ |