author | Florian Pose <fp@igh-essen.com> |
Fri, 25 Apr 2008 12:04:23 +0000 | |
changeset 900 | f8b5c6d21705 |
parent 880 | f6212c54a5e3 |
child 909 | 3b3087d4cdc5 |
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 |
|
820 | 42 |
/*****************************************************************************/ |
43 |
||
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
44 |
// Module parameters |
220 | 45 |
#define FREQUENCY 100 |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
46 |
|
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
47 |
// Optional features |
879
9b395c5646ab
Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents:
878
diff
changeset
|
48 |
#define CONFIGURE_PDOS |
809 | 49 |
#define EXTERNAL_MEMORY |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
50 |
#define SDO_ACCESS |
457
2b4ba84b6058
Minor changes to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
454
diff
changeset
|
51 |
|
820 | 52 |
#define PFX "ec_mini: " |
53 |
||
54 |
/*****************************************************************************/ |
|
220 | 55 |
|
56 |
// EtherCAT |
|
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
57 |
static ec_master_t *master = NULL; |
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
58 |
static ec_master_state_t master_state = {}; |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
59 |
spinlock_t master_lock = SPIN_LOCK_UNLOCKED; |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
60 |
|
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
61 |
static ec_domain_t *domain1 = NULL; |
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
62 |
static ec_domain_state_t domain1_state = {}; |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
63 |
|
820 | 64 |
static struct timer_list timer; |
65 |
static unsigned int counter = 0; |
|
66 |
||
67 |
/*****************************************************************************/ |
|
68 |
||
69 |
// process data |
|
70 |
static uint8_t *domain1_pd; // process data memory |
|
71 |
||
72 |
static unsigned int off_ana_in; // offsets for Pdo entries |
|
73 |
static unsigned int off_dig_out; |
|
74 |
||
75 |
static unsigned int blink = 0; |
|
76 |
||
77 |
const static ec_pdo_entry_reg_t domain1_regs[] = { |
|
78 |
{0, 1, Beckhoff_EL3162, 0x3101, 2, &off_ana_in}, |
|
79 |
{0, 3, Beckhoff_EL2004, 0x3001, 1, &off_dig_out}, |
|
80 |
{} |
|
81 |
}; |
|
82 |
||
83 |
/*****************************************************************************/ |
|
84 |
||
879
9b395c5646ab
Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents:
878
diff
changeset
|
85 |
#ifdef CONFIGURE_PDOS |
851
2bb18adcd204
Removed 'const' from Pdo configuration entries.
Florian Pose <fp@igh-essen.com>
parents:
846
diff
changeset
|
86 |
static ec_pdo_entry_info_t el3162_channel1[] = { |
793
3b297ff8284f
Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents:
792
diff
changeset
|
87 |
{0x3101, 1, 8}, // status |
3b297ff8284f
Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents:
792
diff
changeset
|
88 |
{0x3101, 2, 16} // value |
3b297ff8284f
Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents:
792
diff
changeset
|
89 |
}; |
3b297ff8284f
Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents:
792
diff
changeset
|
90 |
|
851
2bb18adcd204
Removed 'const' from Pdo configuration entries.
Florian Pose <fp@igh-essen.com>
parents:
846
diff
changeset
|
91 |
static ec_pdo_entry_info_t el3162_channel2[] = { |
793
3b297ff8284f
Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents:
792
diff
changeset
|
92 |
{0x3102, 1, 8}, // status |
3b297ff8284f
Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents:
792
diff
changeset
|
93 |
{0x3102, 2, 16} // value |
3b297ff8284f
Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents:
792
diff
changeset
|
94 |
}; |
3b297ff8284f
Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents:
792
diff
changeset
|
95 |
|
879
9b395c5646ab
Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents:
878
diff
changeset
|
96 |
static ec_pdo_info_t el3162_pdos[] = { |
793
3b297ff8284f
Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents:
792
diff
changeset
|
97 |
{EC_DIR_INPUT, 0x1A00, 2, el3162_channel1}, |
3b297ff8284f
Fixed Pdo configuration information providing.
Florian Pose <fp@igh-essen.com>
parents:
792
diff
changeset
|
98 |
{EC_DIR_INPUT, 0x1A01, 2, el3162_channel2}, |
879
9b395c5646ab
Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents:
878
diff
changeset
|
99 |
{EC_END} |
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
100 |
}; |
809 | 101 |
|
851
2bb18adcd204
Removed 'const' from Pdo configuration entries.
Florian Pose <fp@igh-essen.com>
parents:
846
diff
changeset
|
102 |
static ec_pdo_entry_info_t el2004_channels[] = { |
809 | 103 |
{0x3001, 1, 1}, // Value 1 |
104 |
{0x3001, 2, 1}, // Value 2 |
|
105 |
{0x3001, 3, 1}, // Value 3 |
|
106 |
{0x3001, 4, 1} // Value 4 |
|
107 |
}; |
|
108 |
||
879
9b395c5646ab
Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents:
878
diff
changeset
|
109 |
static ec_pdo_info_t el2004_pdos[] = { |
809 | 110 |
{EC_DIR_OUTPUT, 0x1600, 1, &el2004_channels[0]}, |
111 |
{EC_DIR_OUTPUT, 0x1601, 1, &el2004_channels[1]}, |
|
112 |
{EC_DIR_OUTPUT, 0x1602, 1, &el2004_channels[2]}, |
|
113 |
{EC_DIR_OUTPUT, 0x1603, 1, &el2004_channels[3]}, |
|
114 |
}; |
|
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
115 |
#endif |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
116 |
|
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
117 |
/*****************************************************************************/ |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
118 |
|
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
119 |
#ifdef SDO_ACCESS |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
120 |
static ec_sdo_request_t *sdo; |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
121 |
#endif |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
122 |
|
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
123 |
/*****************************************************************************/ |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
124 |
|
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
125 |
void check_domain1_state(void) |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
126 |
{ |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
127 |
ec_domain_state_t ds; |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
128 |
|
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
129 |
ecrt_domain_state(domain1, &ds); |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
130 |
if (ds.working_counter != domain1_state.working_counter) |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
131 |
printk(KERN_INFO PFX "domain1 working_counter changed to %u.\n", |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
132 |
ds.working_counter); |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
133 |
|
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
134 |
if (ds.wc_state != domain1_state.wc_state) |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
135 |
printk(KERN_INFO PFX "domain1 wc_state changed to %u.\n", |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
136 |
ds.wc_state); |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
137 |
|
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
138 |
domain1_state = ds; |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
139 |
} |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
140 |
|
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
141 |
/*****************************************************************************/ |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
142 |
|
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
143 |
void check_master_state(void) |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
144 |
{ |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
145 |
ec_master_state_t ms; |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
146 |
|
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
147 |
spin_lock(&master_lock); |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
148 |
ecrt_master_state(master, &ms); |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
149 |
spin_unlock(&master_lock); |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
150 |
|
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
151 |
if (ms.bus_state != master_state.bus_state) { |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
152 |
printk(KERN_INFO PFX "bus state changed to %i.\n", ms.bus_state); |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
153 |
} |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
154 |
if (ms.bus_tainted != master_state.bus_tainted) { |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
155 |
printk(KERN_INFO PFX "tainted flag changed to %u.\n", |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
156 |
ms.bus_tainted); |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
157 |
} |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
158 |
if (ms.slaves_responding != master_state.slaves_responding) { |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
159 |
printk(KERN_INFO PFX "slaves_responding changed to %u.\n", |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
160 |
ms.slaves_responding); |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
161 |
} |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
162 |
|
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
163 |
master_state = ms; |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
164 |
} |
220 | 165 |
|
166 |
/*****************************************************************************/ |
|
167 |
||
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
168 |
#ifdef SDO_ACCESS |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
169 |
void read_sdo(void) |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
170 |
{ |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
171 |
switch (ecrt_sdo_request_state(sdo)) { |
861
6e3de145421a
Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents:
858
diff
changeset
|
172 |
case EC_SDO_REQUEST_UNUSED: // request was not used yet |
880 | 173 |
ecrt_sdo_request_timeout(sdo, 500); // ms |
867 | 174 |
ecrt_sdo_request_read(sdo); // trigger first read |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
175 |
break; |
861
6e3de145421a
Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents:
858
diff
changeset
|
176 |
case EC_SDO_REQUEST_BUSY: |
6e3de145421a
Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents:
858
diff
changeset
|
177 |
printk(KERN_INFO PFX "Still busy...\n"); |
6e3de145421a
Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents:
858
diff
changeset
|
178 |
break; |
6e3de145421a
Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents:
858
diff
changeset
|
179 |
case EC_SDO_REQUEST_SUCCESS: |
6e3de145421a
Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents:
858
diff
changeset
|
180 |
printk(KERN_INFO PFX "Sdo value: 0x%04X\n", |
6e3de145421a
Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents:
858
diff
changeset
|
181 |
EC_READ_U16(ecrt_sdo_request_data(sdo))); |
867 | 182 |
ecrt_sdo_request_read(sdo); // trigger next read |
861
6e3de145421a
Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents:
858
diff
changeset
|
183 |
break; |
6e3de145421a
Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents:
858
diff
changeset
|
184 |
case EC_SDO_REQUEST_ERROR: |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
185 |
printk(KERN_INFO PFX "Failed to read Sdo!\n"); |
867 | 186 |
ecrt_sdo_request_read(sdo); // retry reading |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
187 |
break; |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
188 |
} |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
189 |
} |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
190 |
#endif |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
191 |
|
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
192 |
/*****************************************************************************/ |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
193 |
|
820 | 194 |
void cyclic_task(unsigned long data) |
195 |
{ |
|
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
196 |
// receive process data |
220 | 197 |
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
|
198 |
ecrt_master_receive(master); |
220 | 199 |
ecrt_domain_process(domain1); |
512
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
200 |
spin_unlock(&master_lock); |
220 | 201 |
|
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
202 |
// check process data state (optional) |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
203 |
check_domain1_state(); |
512
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
204 |
|
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
205 |
if (counter) { |
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
206 |
counter--; |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
207 |
} else { // do this at 1 Hz |
512
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
208 |
counter = FREQUENCY; |
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
209 |
|
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
210 |
// calculate new process data |
512
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
211 |
blink = !blink; |
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
212 |
|
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
213 |
// check for master state (optional) |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
214 |
check_master_state(); |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
215 |
|
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
216 |
#ifdef SDO_ACCESS |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
217 |
// read process data Sdo |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
218 |
read_sdo(); |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
219 |
#endif |
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
220 |
} |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
221 |
|
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
222 |
// write process data |
846 | 223 |
EC_WRITE_U8(domain1_pd + off_dig_out, blink ? 0x06 : 0x09); |
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
224 |
|
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
225 |
// send process data |
512
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
226 |
spin_lock(&master_lock); |
509
87baea61d0c7
Adjusted examples to 1.2.0 interface changes.
Florian Pose <fp@igh-essen.com>
parents:
472
diff
changeset
|
227 |
ecrt_domain_queue(domain1); |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
280
diff
changeset
|
228 |
ecrt_master_send(master); |
220 | 229 |
spin_unlock(&master_lock); |
230 |
||
231 |
// restart timer |
|
232 |
timer.expires += HZ / FREQUENCY; |
|
233 |
add_timer(&timer); |
|
234 |
} |
|
235 |
||
236 |
/*****************************************************************************/ |
|
237 |
||
238 |
int request_lock(void *data) |
|
239 |
{ |
|
516
f703e33ee395
Adjusted examples to EtherLab starter kit hardware.
Florian Pose <fp@igh-essen.com>
parents:
513
diff
changeset
|
240 |
spin_lock(&master_lock); |
226
07247920a7ba
EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
241 |
return 0; // access allowed |
220 | 242 |
} |
243 |
||
244 |
/*****************************************************************************/ |
|
245 |
||
246 |
void release_lock(void *data) |
|
247 |
{ |
|
516
f703e33ee395
Adjusted examples to EtherLab starter kit hardware.
Florian Pose <fp@igh-essen.com>
parents:
513
diff
changeset
|
248 |
spin_unlock(&master_lock); |
220 | 249 |
} |
250 |
||
251 |
/*****************************************************************************/ |
|
252 |
||
253 |
int __init init_mini_module(void) |
|
254 |
{ |
|
879
9b395c5646ab
Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents:
878
diff
changeset
|
255 |
#ifdef CONFIGURE_PDOS |
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
256 |
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
|
257 |
#endif |
809 | 258 |
#ifdef EXTERNAL_MEMORY |
259 |
unsigned int size; |
|
260 |
#endif |
|
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
261 |
|
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
262 |
printk(KERN_INFO PFX "Starting...\n"); |
220 | 263 |
|
509
87baea61d0c7
Adjusted examples to 1.2.0 interface changes.
Florian Pose <fp@igh-essen.com>
parents:
472
diff
changeset
|
264 |
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
|
265 |
printk(KERN_ERR PFX "Requesting master 0 failed!\n"); |
220 | 266 |
goto out_return; |
267 |
} |
|
268 |
||
269 |
ecrt_master_callbacks(master, request_lock, release_lock, NULL); |
|
270 |
||
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
271 |
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
|
272 |
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
|
273 |
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
|
274 |
goto out_release_master; |
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
275 |
} |
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
276 |
|
879
9b395c5646ab
Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents:
878
diff
changeset
|
277 |
#ifdef CONFIGURE_PDOS |
9b395c5646ab
Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents:
878
diff
changeset
|
278 |
printk(KERN_INFO PFX "Configuring Pdos...\n"); |
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
279 |
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
|
280 |
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
|
281 |
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
|
282 |
} |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
283 |
|
879
9b395c5646ab
Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents:
878
diff
changeset
|
284 |
if (ecrt_slave_config_pdos(sc, EC_END, el3162_pdos)) { |
9b395c5646ab
Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents:
878
diff
changeset
|
285 |
printk(KERN_ERR PFX "Failed to configure Pdos.\n"); |
809 | 286 |
goto out_release_master; |
287 |
} |
|
288 |
||
289 |
if (!(sc = ecrt_master_slave_config(master, 0, 3, Beckhoff_EL2004))) { |
|
290 |
printk(KERN_ERR PFX "Failed to get slave configuration.\n"); |
|
291 |
goto out_release_master; |
|
292 |
} |
|
293 |
||
879
9b395c5646ab
Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents:
878
diff
changeset
|
294 |
if (ecrt_slave_config_pdos(sc, 4, el2004_pdos)) { |
9b395c5646ab
Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents:
878
diff
changeset
|
295 |
printk(KERN_ERR PFX "Failed to configure Pdos.\n"); |
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
296 |
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
|
297 |
} |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
298 |
#endif |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
299 |
|
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
300 |
#ifdef SDO_ACCESS |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
301 |
printk(KERN_INFO PFX "Creating Sdo requests...\n"); |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
302 |
if (!(sc = ecrt_master_slave_config(master, 0, 1, Beckhoff_EL3162))) { |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
303 |
printk(KERN_ERR PFX "Failed to get slave configuration.\n"); |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
304 |
goto out_release_master; |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
305 |
} |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
306 |
|
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
307 |
if (!(sdo = ecrt_slave_config_create_sdo_request(sc, 0x3102, 2, 2))) { |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
308 |
printk(KERN_ERR PFX "Failed to create Sdo request.\n"); |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
309 |
goto out_release_master; |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
310 |
} |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
311 |
#endif |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
312 |
|
814 | 313 |
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
|
314 |
if (ecrt_domain_reg_pdo_entry_list(domain1, domain1_regs)) { |
814 | 315 |
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
|
316 |
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
|
317 |
} |
635
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
318 |
|
809 | 319 |
#ifdef EXTERNAL_MEMORY |
320 |
if ((size = ecrt_domain_size(domain1))) { |
|
820 | 321 |
if (!(domain1_pd = (uint8_t *) kmalloc(size, GFP_KERNEL))) { |
809 | 322 |
printk(KERN_ERR PFX "Failed to allocate %u bytes of process data" |
323 |
" memory!\n", size); |
|
324 |
goto out_release_master; |
|
325 |
} |
|
820 | 326 |
ecrt_domain_external_memory(domain1, domain1_pd); |
809 | 327 |
} |
328 |
#endif |
|
329 |
||
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
330 |
printk(KERN_INFO PFX "Activating master...\n"); |
220 | 331 |
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
|
332 |
printk(KERN_ERR PFX "Failed to activate master!\n"); |
809 | 333 |
#ifdef EXTERNAL_MEMORY |
334 |
goto out_free_process_data; |
|
335 |
#else |
|
336 |
goto out_release_master; |
|
337 |
#endif |
|
338 |
} |
|
339 |
||
340 |
#ifndef EXTERNAL_MEMORY |
|
341 |
// Get internal process data for domain |
|
820 | 342 |
domain1_pd = ecrt_domain_data(domain1); |
809 | 343 |
#endif |
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
344 |
|
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
345 |
printk(KERN_INFO PFX "Starting cyclic sample thread.\n"); |
220 | 346 |
init_timer(&timer); |
820 | 347 |
timer.function = cyclic_task; |
220 | 348 |
timer.expires = jiffies + 10; |
349 |
add_timer(&timer); |
|
350 |
||
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
351 |
printk(KERN_INFO PFX "Started.\n"); |
220 | 352 |
return 0; |
353 |
||
809 | 354 |
#ifdef EXTERNAL_MEMORY |
355 |
out_free_process_data: |
|
820 | 356 |
kfree(domain1_pd); |
809 | 357 |
#endif |
358 |
out_release_master: |
|
654
8278e1e27010
Minor changes in minimal example.
Florian Pose <fp@igh-essen.com>
parents:
643
diff
changeset
|
359 |
printk(KERN_ERR PFX "Releasing master...\n"); |
220 | 360 |
ecrt_release_master(master); |
809 | 361 |
out_return: |
654
8278e1e27010
Minor changes in minimal example.
Florian Pose <fp@igh-essen.com>
parents:
643
diff
changeset
|
362 |
printk(KERN_ERR PFX "Failed to load. Aborting.\n"); |
220 | 363 |
return -1; |
364 |
} |
|
365 |
||
366 |
/*****************************************************************************/ |
|
367 |
||
368 |
void __exit cleanup_mini_module(void) |
|
369 |
{ |
|
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
370 |
printk(KERN_INFO PFX "Stopping...\n"); |
220 | 371 |
|
449
3caf8ff4d8a2
Moved functionality of ecrt_master_deactivate() (now deprecated) to ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents:
446
diff
changeset
|
372 |
del_timer_sync(&timer); |
809 | 373 |
|
374 |
#ifdef EXTERNAL_MEMORY |
|
820 | 375 |
kfree(domain1_pd); |
809 | 376 |
#endif |
377 |
||
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
378 |
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
|
379 |
ecrt_release_master(master); |
220 | 380 |
|
654
8278e1e27010
Minor changes in minimal example.
Florian Pose <fp@igh-essen.com>
parents:
643
diff
changeset
|
381 |
printk(KERN_INFO PFX "Unloading.\n"); |
220 | 382 |
} |
383 |
||
384 |
/*****************************************************************************/ |
|
385 |
||
386 |
MODULE_LICENSE("GPL"); |
|
512
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
387 |
MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>"); |
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
388 |
MODULE_DESCRIPTION("EtherCAT minimal test environment"); |
220 | 389 |
|
390 |
module_init(init_mini_module); |
|
391 |
module_exit(cleanup_mini_module); |
|
392 |
||
393 |
/*****************************************************************************/ |