author | Florian Pose <fp@igh-essen.com> |
Wed, 13 Jan 2010 00:04:47 +0100 | |
branch | stable-1.4 |
changeset 1769 | 5c317e78a5ef |
parent 1686 | e206f4485f60 |
permissions | -rw-r--r-- |
220 | 1 |
/****************************************************************************** |
2 |
* |
|
3 |
* $Id$ |
|
4 |
* |
|
1685
399ef727bf62
Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1179
diff
changeset
|
5 |
* Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH |
220 | 6 |
* |
7 |
* This file is part of the IgH EtherCAT Master. |
|
8 |
* |
|
1685
399ef727bf62
Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1179
diff
changeset
|
9 |
* The IgH EtherCAT Master is free software; you can redistribute it and/or |
399ef727bf62
Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1179
diff
changeset
|
10 |
* modify it under the terms of the GNU General Public License version 2, as |
399ef727bf62
Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1179
diff
changeset
|
11 |
* published by the Free Software Foundation. |
399ef727bf62
Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1179
diff
changeset
|
12 |
* |
399ef727bf62
Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1179
diff
changeset
|
13 |
* The IgH EtherCAT Master is distributed in the hope that it will be useful, |
399ef727bf62
Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1179
diff
changeset
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
399ef727bf62
Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1179
diff
changeset
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
399ef727bf62
Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1179
diff
changeset
|
16 |
* Public License for more details. |
399ef727bf62
Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1179
diff
changeset
|
17 |
* |
399ef727bf62
Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1179
diff
changeset
|
18 |
* You should have received a copy of the GNU General Public License along |
399ef727bf62
Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1179
diff
changeset
|
19 |
* with the IgH EtherCAT Master; if not, write to the Free Software |
220 | 20 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
21 |
* |
|
1685
399ef727bf62
Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1179
diff
changeset
|
22 |
* Using the EtherCAT technology and brand is permitted in compliance with |
399ef727bf62
Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1179
diff
changeset
|
23 |
* the industrial property and similar rights of Beckhoff Automation GmbH. |
246
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
226
diff
changeset
|
24 |
* |
220 | 25 |
*****************************************************************************/ |
26 |
||
27 |
#include <linux/module.h> |
|
28 |
#include <linux/timer.h> |
|
29 |
#include <linux/spinlock.h> |
|
30 |
#include <linux/interrupt.h> |
|
31 |
||
223
daa5e5656b35
Applied new path information to example modules.
Florian Pose <fp@igh-essen.com>
parents:
220
diff
changeset
|
32 |
#include "../../include/ecrt.h" // EtherCAT realtime interface |
220 | 33 |
|
820 | 34 |
/*****************************************************************************/ |
35 |
||
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
36 |
// Module parameters |
220 | 37 |
#define FREQUENCY 100 |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
38 |
|
1171
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
39 |
// Optional features |
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
40 |
#define CONFIGURE_PDOS 1 |
1179
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
41 |
#define EL3152_ALT_PDOS 0 |
1171
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
42 |
#define EXTERNAL_MEMORY 1 |
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
43 |
#define SDO_ACCESS 0 |
457
2b4ba84b6058
Minor changes to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
454
diff
changeset
|
44 |
|
820 | 45 |
#define PFX "ec_mini: " |
46 |
||
47 |
/*****************************************************************************/ |
|
220 | 48 |
|
49 |
// EtherCAT |
|
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
50 |
static ec_master_t *master = NULL; |
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
51 |
static ec_master_state_t master_state = {}; |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
52 |
spinlock_t master_lock = SPIN_LOCK_UNLOCKED; |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
53 |
|
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
54 |
static ec_domain_t *domain1 = NULL; |
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
55 |
static ec_domain_state_t domain1_state = {}; |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
56 |
|
1022
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
57 |
static ec_slave_config_t *sc_ana_in = NULL; |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
58 |
static ec_slave_config_state_t sc_ana_in_state = {}; |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
59 |
|
1080
088a61306930
Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents:
1061
diff
changeset
|
60 |
// Timer |
820 | 61 |
static struct timer_list timer; |
62 |
||
63 |
/*****************************************************************************/ |
|
64 |
||
65 |
// process data |
|
66 |
static uint8_t *domain1_pd; // process data memory |
|
67 |
||
1080
088a61306930
Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents:
1061
diff
changeset
|
68 |
#define AnaInSlavePos 0, 1 |
1179
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
69 |
#define AnaOutSlavePos 0, 2 |
1080
088a61306930
Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents:
1061
diff
changeset
|
70 |
#define DigOutSlavePos 0, 3 |
088a61306930
Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents:
1061
diff
changeset
|
71 |
|
088a61306930
Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents:
1061
diff
changeset
|
72 |
#define Beckhoff_EL2004 0x00000002, 0x07D43052 |
1179
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
73 |
#define Beckhoff_EL3152 0x00000002, 0x0c503052 |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
74 |
#define Beckhoff_EL4102 0x00000002, 0x10063052 |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
75 |
|
1686
e206f4485f60
Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1685
diff
changeset
|
76 |
// offsets for PDO entries |
1179
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
77 |
static unsigned int off_ana_in; |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
78 |
static unsigned int off_ana_out; |
820 | 79 |
static unsigned int off_dig_out; |
80 |
||
1080
088a61306930
Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents:
1061
diff
changeset
|
81 |
const static ec_pdo_entry_reg_t domain1_regs[] = { |
1179
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
82 |
#if EL3152_ALT_PDOS |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
83 |
{AnaInSlavePos, Beckhoff_EL3152, 0x6401, 1, &off_ana_in}, |
1171
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
84 |
#else |
1179
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
85 |
{AnaInSlavePos, Beckhoff_EL3152, 0x3101, 2, &off_ana_in}, |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
86 |
#endif |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
87 |
{AnaOutSlavePos, Beckhoff_EL4102, 0x3001, 1, &off_ana_out}, |
1080
088a61306930
Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents:
1061
diff
changeset
|
88 |
{DigOutSlavePos, Beckhoff_EL2004, 0x3001, 1, &off_dig_out}, |
088a61306930
Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents:
1061
diff
changeset
|
89 |
{} |
088a61306930
Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents:
1061
diff
changeset
|
90 |
}; |
088a61306930
Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents:
1061
diff
changeset
|
91 |
|
088a61306930
Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents:
1061
diff
changeset
|
92 |
static unsigned int counter = 0; |
820 | 93 |
static unsigned int blink = 0; |
94 |
||
95 |
/*****************************************************************************/ |
|
96 |
||
1171
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
97 |
#if CONFIGURE_PDOS |
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
98 |
|
1179
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
99 |
// Analog in -------------------------- |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
100 |
|
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
101 |
static ec_pdo_entry_info_t el3152_pdo_entries[] = { |
1171
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
102 |
{0x3101, 1, 8}, // channel 1 status |
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
103 |
{0x3101, 2, 16}, // channel 1 value |
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
104 |
{0x3102, 1, 8}, // channel 2 status |
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
105 |
{0x3102, 2, 16}, // channel 2 value |
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
106 |
{0x6401, 1, 16}, // channel 1 value (alt.) |
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
107 |
{0x6401, 2, 16} // channel 2 value (alt.) |
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
108 |
}; |
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
109 |
|
1179
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
110 |
#if EL3152_ALT_PDOS |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
111 |
static ec_pdo_info_t el3152_pdos[] = { |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
112 |
{0x1A10, 2, el3152_pdo_entries + 4}, |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
113 |
}; |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
114 |
|
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
115 |
static ec_sync_info_t el3152_syncs[] = { |
1171
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
116 |
{2, EC_DIR_OUTPUT}, |
1179
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
117 |
{3, EC_DIR_INPUT, 1, el3152_pdos}, |
1171
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
118 |
{0xff} |
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
119 |
}; |
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
120 |
#else |
1179
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
121 |
static ec_pdo_info_t el3152_pdos[] = { |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
122 |
{0x1A00, 2, el3152_pdo_entries}, |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
123 |
{0x1A01, 2, el3152_pdo_entries + 2} |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
124 |
}; |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
125 |
|
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
126 |
static ec_sync_info_t el3152_syncs[] = { |
1061
90c3d75057e4
Adapted minimal example to sync manager configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
1027
diff
changeset
|
127 |
{2, EC_DIR_OUTPUT}, |
1179
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
128 |
{3, EC_DIR_INPUT, 1, el3152_pdos}, |
1061
90c3d75057e4
Adapted minimal example to sync manager configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
1027
diff
changeset
|
129 |
{0xff} |
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
130 |
}; |
1171
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
131 |
#endif |
809 | 132 |
|
1179
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
133 |
// Analog out ------------------------- |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
134 |
|
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
135 |
static ec_pdo_entry_info_t el4102_pdo_entries[] = { |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
136 |
{0x3001, 1, 16}, // channel 1 value |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
137 |
{0x3002, 1, 16}, // channel 2 value |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
138 |
}; |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
139 |
|
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
140 |
static ec_pdo_info_t el4102_pdos[] = { |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
141 |
{0x1600, 1, el4102_pdo_entries}, |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
142 |
{0x1601, 1, el4102_pdo_entries + 1} |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
143 |
}; |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
144 |
|
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
145 |
static ec_sync_info_t el4102_syncs[] = { |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
146 |
{2, EC_DIR_OUTPUT, 2, el4102_pdos}, |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
147 |
{3, EC_DIR_INPUT}, |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
148 |
{0xff} |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
149 |
}; |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
150 |
|
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
151 |
// Digital out ------------------------ |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
152 |
|
851
2bb18adcd204
Removed 'const' from Pdo configuration entries.
Florian Pose <fp@igh-essen.com>
parents:
846
diff
changeset
|
153 |
static ec_pdo_entry_info_t el2004_channels[] = { |
809 | 154 |
{0x3001, 1, 1}, // Value 1 |
155 |
{0x3001, 2, 1}, // Value 2 |
|
156 |
{0x3001, 3, 1}, // Value 3 |
|
157 |
{0x3001, 4, 1} // Value 4 |
|
158 |
}; |
|
159 |
||
879
9b395c5646ab
Changed terms "Pdo mapping" -> "Pdo assignment" and "Pdo configuration"
Florian Pose <fp@igh-essen.com>
parents:
878
diff
changeset
|
160 |
static ec_pdo_info_t el2004_pdos[] = { |
1061
90c3d75057e4
Adapted minimal example to sync manager configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
1027
diff
changeset
|
161 |
{0x1600, 1, &el2004_channels[0]}, |
90c3d75057e4
Adapted minimal example to sync manager configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
1027
diff
changeset
|
162 |
{0x1601, 1, &el2004_channels[1]}, |
90c3d75057e4
Adapted minimal example to sync manager configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
1027
diff
changeset
|
163 |
{0x1602, 1, &el2004_channels[2]}, |
90c3d75057e4
Adapted minimal example to sync manager configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
1027
diff
changeset
|
164 |
{0x1603, 1, &el2004_channels[3]} |
90c3d75057e4
Adapted minimal example to sync manager configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
1027
diff
changeset
|
165 |
}; |
90c3d75057e4
Adapted minimal example to sync manager configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
1027
diff
changeset
|
166 |
|
90c3d75057e4
Adapted minimal example to sync manager configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
1027
diff
changeset
|
167 |
static ec_sync_info_t el2004_syncs[] = { |
90c3d75057e4
Adapted minimal example to sync manager configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
1027
diff
changeset
|
168 |
{0, EC_DIR_OUTPUT, 4, el2004_pdos}, |
90c3d75057e4
Adapted minimal example to sync manager configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
1027
diff
changeset
|
169 |
{1, EC_DIR_INPUT}, |
90c3d75057e4
Adapted minimal example to sync manager configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
1027
diff
changeset
|
170 |
{0xff} |
809 | 171 |
}; |
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
172 |
#endif |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
173 |
|
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
174 |
/*****************************************************************************/ |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
175 |
|
1171
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
176 |
#if SDO_ACCESS |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
177 |
static ec_sdo_request_t *sdo; |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
178 |
#endif |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
179 |
|
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
180 |
/*****************************************************************************/ |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
181 |
|
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
182 |
void check_domain1_state(void) |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
183 |
{ |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
184 |
ec_domain_state_t ds; |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
185 |
|
1022
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
186 |
spin_lock(&master_lock); |
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
187 |
ecrt_domain_state(domain1, &ds); |
1022
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
188 |
spin_unlock(&master_lock); |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
189 |
|
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
190 |
if (ds.working_counter != domain1_state.working_counter) |
1022
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
191 |
printk(KERN_INFO PFX "Domain1: WC %u.\n", ds.working_counter); |
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
192 |
if (ds.wc_state != domain1_state.wc_state) |
1022
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
193 |
printk(KERN_INFO PFX "Domain1: State %u.\n", ds.wc_state); |
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
194 |
|
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
195 |
domain1_state = ds; |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
196 |
} |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
197 |
|
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
198 |
/*****************************************************************************/ |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
199 |
|
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
200 |
void check_master_state(void) |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
201 |
{ |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
202 |
ec_master_state_t ms; |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
203 |
|
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
204 |
spin_lock(&master_lock); |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
205 |
ecrt_master_state(master, &ms); |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
206 |
spin_unlock(&master_lock); |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
207 |
|
1022
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
208 |
if (ms.slaves_responding != master_state.slaves_responding) |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
209 |
printk(KERN_INFO PFX "%u slave(s).\n", ms.slaves_responding); |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
210 |
if (ms.al_states != master_state.al_states) |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
211 |
printk(KERN_INFO PFX "AL states: 0x%02X.\n", ms.al_states); |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
212 |
if (ms.link_up != master_state.link_up) |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
213 |
printk(KERN_INFO PFX "Link is %s.\n", ms.link_up ? "up" : "down"); |
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
214 |
|
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
215 |
master_state = ms; |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
216 |
} |
220 | 217 |
|
218 |
/*****************************************************************************/ |
|
219 |
||
1022
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
220 |
void check_slave_config_states(void) |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
221 |
{ |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
222 |
ec_slave_config_state_t s; |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
223 |
|
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
224 |
spin_lock(&master_lock); |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
225 |
ecrt_slave_config_state(sc_ana_in, &s); |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
226 |
spin_unlock(&master_lock); |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
227 |
|
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
228 |
if (s.al_state != sc_ana_in_state.al_state) |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
229 |
printk(KERN_INFO PFX "AnaIn: State 0x%02X.\n", s.al_state); |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
230 |
if (s.online != sc_ana_in_state.online) |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
231 |
printk(KERN_INFO PFX "AnaIn: %s.\n", s.online ? "online" : "offline"); |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
232 |
if (s.operational != sc_ana_in_state.operational) |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
233 |
printk(KERN_INFO PFX "AnaIn: %soperational.\n", |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
234 |
s.operational ? "" : "Not "); |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
235 |
|
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
236 |
sc_ana_in_state = s; |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
237 |
} |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
238 |
|
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
239 |
/*****************************************************************************/ |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
240 |
|
1171
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
241 |
#if SDO_ACCESS |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
242 |
void read_sdo(void) |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
243 |
{ |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
244 |
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
|
245 |
case EC_SDO_REQUEST_UNUSED: // request was not used yet |
867 | 246 |
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
|
247 |
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
|
248 |
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
|
249 |
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
|
250 |
break; |
6e3de145421a
Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents:
858
diff
changeset
|
251 |
case EC_SDO_REQUEST_SUCCESS: |
1686
e206f4485f60
Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1685
diff
changeset
|
252 |
printk(KERN_INFO PFX "SDO value: 0x%04X\n", |
861
6e3de145421a
Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents:
858
diff
changeset
|
253 |
EC_READ_U16(ecrt_sdo_request_data(sdo))); |
867 | 254 |
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
|
255 |
break; |
6e3de145421a
Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents:
858
diff
changeset
|
256 |
case EC_SDO_REQUEST_ERROR: |
1686
e206f4485f60
Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1685
diff
changeset
|
257 |
printk(KERN_INFO PFX "Failed to read SDO!\n"); |
867 | 258 |
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
|
259 |
break; |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
260 |
} |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
261 |
} |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
262 |
#endif |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
263 |
|
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
264 |
/*****************************************************************************/ |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
265 |
|
820 | 266 |
void cyclic_task(unsigned long data) |
267 |
{ |
|
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
268 |
// receive process data |
220 | 269 |
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
|
270 |
ecrt_master_receive(master); |
220 | 271 |
ecrt_domain_process(domain1); |
512
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
272 |
spin_unlock(&master_lock); |
220 | 273 |
|
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
274 |
// check process data state (optional) |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
275 |
check_domain1_state(); |
512
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
276 |
|
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
277 |
if (counter) { |
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
278 |
counter--; |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
279 |
} else { // do this at 1 Hz |
512
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
280 |
counter = FREQUENCY; |
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
281 |
|
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
282 |
// calculate new process data |
512
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
283 |
blink = !blink; |
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
284 |
|
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
285 |
// check for master state (optional) |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
286 |
check_master_state(); |
1022
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
287 |
|
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
288 |
// check for islave configuration state(s) (optional) |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
289 |
check_slave_config_states(); |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
290 |
|
1171
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
291 |
#if SDO_ACCESS |
1686
e206f4485f60
Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1685
diff
changeset
|
292 |
// read process data SDO |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
293 |
read_sdo(); |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
294 |
#endif |
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
295 |
} |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
296 |
|
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
297 |
// write process data |
846 | 298 |
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
|
299 |
|
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
300 |
// send process data |
512
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
301 |
spin_lock(&master_lock); |
509
87baea61d0c7
Adjusted examples to 1.2.0 interface changes.
Florian Pose <fp@igh-essen.com>
parents:
472
diff
changeset
|
302 |
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
|
303 |
ecrt_master_send(master); |
220 | 304 |
spin_unlock(&master_lock); |
305 |
||
306 |
// restart timer |
|
307 |
timer.expires += HZ / FREQUENCY; |
|
308 |
add_timer(&timer); |
|
309 |
} |
|
310 |
||
311 |
/*****************************************************************************/ |
|
312 |
||
313 |
int request_lock(void *data) |
|
314 |
{ |
|
516
f703e33ee395
Adjusted examples to EtherLab starter kit hardware.
Florian Pose <fp@igh-essen.com>
parents:
513
diff
changeset
|
315 |
spin_lock(&master_lock); |
226
07247920a7ba
EoE with workqueue; bugfix in ec_master_init()
Florian Pose <fp@igh-essen.com>
parents:
223
diff
changeset
|
316 |
return 0; // access allowed |
220 | 317 |
} |
318 |
||
319 |
/*****************************************************************************/ |
|
320 |
||
321 |
void release_lock(void *data) |
|
322 |
{ |
|
516
f703e33ee395
Adjusted examples to EtherLab starter kit hardware.
Florian Pose <fp@igh-essen.com>
parents:
513
diff
changeset
|
323 |
spin_unlock(&master_lock); |
220 | 324 |
} |
325 |
||
326 |
/*****************************************************************************/ |
|
327 |
||
328 |
int __init init_mini_module(void) |
|
329 |
{ |
|
1171
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
330 |
#if CONFIGURE_PDOS |
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
331 |
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
|
332 |
#endif |
1171
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
333 |
#if EXTERNAL_MEMORY |
809 | 334 |
unsigned int size; |
335 |
#endif |
|
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
336 |
|
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
337 |
printk(KERN_INFO PFX "Starting...\n"); |
220 | 338 |
|
509
87baea61d0c7
Adjusted examples to 1.2.0 interface changes.
Florian Pose <fp@igh-essen.com>
parents:
472
diff
changeset
|
339 |
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
|
340 |
printk(KERN_ERR PFX "Requesting master 0 failed!\n"); |
220 | 341 |
goto out_return; |
342 |
} |
|
343 |
||
344 |
ecrt_master_callbacks(master, request_lock, release_lock, NULL); |
|
345 |
||
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
346 |
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
|
347 |
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
|
348 |
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
|
349 |
goto out_release_master; |
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
350 |
} |
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
351 |
|
1022
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
352 |
if (!(sc_ana_in = ecrt_master_slave_config( |
1179
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
353 |
master, AnaInSlavePos, Beckhoff_EL3152))) { |
1022
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
354 |
printk(KERN_ERR PFX "Failed to get slave configuration.\n"); |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
355 |
goto out_release_master; |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
356 |
} |
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
357 |
|
1171
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
358 |
#if CONFIGURE_PDOS |
1686
e206f4485f60
Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1685
diff
changeset
|
359 |
printk(KERN_INFO PFX "Configuring PDOs...\n"); |
1179
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
360 |
if (ecrt_slave_config_pdos(sc_ana_in, EC_END, el3152_syncs)) { |
1686
e206f4485f60
Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1685
diff
changeset
|
361 |
printk(KERN_ERR PFX "Failed to configure PDOs.\n"); |
1179
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
362 |
goto out_release_master; |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
363 |
} |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
364 |
|
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
365 |
if (!(sc = ecrt_master_slave_config( |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
366 |
master, AnaOutSlavePos, Beckhoff_EL4102))) { |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
367 |
printk(KERN_ERR PFX "Failed to get slave configuration.\n"); |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
368 |
goto out_release_master; |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
369 |
} |
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
370 |
|
c0e6adec1aee
Added analog output to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1171
diff
changeset
|
371 |
if (ecrt_slave_config_pdos(sc, EC_END, el4102_syncs)) { |
1686
e206f4485f60
Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1685
diff
changeset
|
372 |
printk(KERN_ERR PFX "Failed to configure PDOs.\n"); |
809 | 373 |
goto out_release_master; |
374 |
} |
|
375 |
||
1080
088a61306930
Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents:
1061
diff
changeset
|
376 |
if (!(sc = ecrt_master_slave_config( |
088a61306930
Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents:
1061
diff
changeset
|
377 |
master, DigOutSlavePos, Beckhoff_EL2004))) { |
809 | 378 |
printk(KERN_ERR PFX "Failed to get slave configuration.\n"); |
379 |
goto out_release_master; |
|
380 |
} |
|
381 |
||
1082
ff06c58e269c
Renamed ecrt_slave_config_sync_managers() to ecrt_slave_config_pdos();
Florian Pose <fp@igh-essen.com>
parents:
1080
diff
changeset
|
382 |
if (ecrt_slave_config_pdos(sc, EC_END, el2004_syncs)) { |
1686
e206f4485f60
Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1685
diff
changeset
|
383 |
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
|
384 |
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
|
385 |
} |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
386 |
#endif |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
387 |
|
1171
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
388 |
#if SDO_ACCESS |
1686
e206f4485f60
Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1685
diff
changeset
|
389 |
printk(KERN_INFO PFX "Creating SDO requests...\n"); |
1026
021b8cdeb384
Minor changes to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1022
diff
changeset
|
390 |
if (!(sdo = ecrt_slave_config_create_sdo_request(sc_ana_in, 0x3102, 2, 2))) { |
1686
e206f4485f60
Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1685
diff
changeset
|
391 |
printk(KERN_ERR PFX "Failed to create SDO request.\n"); |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
392 |
goto out_release_master; |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
393 |
} |
1026
021b8cdeb384
Minor changes to minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1022
diff
changeset
|
394 |
ecrt_sdo_request_timeout(sdo, 500); // ms |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
395 |
#endif |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
396 |
|
1686
e206f4485f60
Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1685
diff
changeset
|
397 |
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
|
398 |
if (ecrt_domain_reg_pdo_entry_list(domain1, domain1_regs)) { |
1686
e206f4485f60
Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1685
diff
changeset
|
399 |
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
|
400 |
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
|
401 |
} |
635
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
402 |
|
1171
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
403 |
#if EXTERNAL_MEMORY |
809 | 404 |
if ((size = ecrt_domain_size(domain1))) { |
820 | 405 |
if (!(domain1_pd = (uint8_t *) kmalloc(size, GFP_KERNEL))) { |
809 | 406 |
printk(KERN_ERR PFX "Failed to allocate %u bytes of process data" |
407 |
" memory!\n", size); |
|
408 |
goto out_release_master; |
|
409 |
} |
|
820 | 410 |
ecrt_domain_external_memory(domain1, domain1_pd); |
809 | 411 |
} |
412 |
#endif |
|
413 |
||
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
414 |
printk(KERN_INFO PFX "Activating master...\n"); |
220 | 415 |
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
|
416 |
printk(KERN_ERR PFX "Failed to activate master!\n"); |
1171
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
417 |
#if EXTERNAL_MEMORY |
809 | 418 |
goto out_free_process_data; |
419 |
#else |
|
420 |
goto out_release_master; |
|
421 |
#endif |
|
422 |
} |
|
423 |
||
1171
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
424 |
#if !EXTERNAL_MEMORY |
809 | 425 |
// Get internal process data for domain |
820 | 426 |
domain1_pd = ecrt_domain_data(domain1); |
809 | 427 |
#endif |
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
428 |
|
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
429 |
printk(KERN_INFO PFX "Starting cyclic sample thread.\n"); |
220 | 430 |
init_timer(&timer); |
820 | 431 |
timer.function = cyclic_task; |
220 | 432 |
timer.expires = jiffies + 10; |
433 |
add_timer(&timer); |
|
434 |
||
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
435 |
printk(KERN_INFO PFX "Started.\n"); |
220 | 436 |
return 0; |
437 |
||
1171
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
438 |
#if EXTERNAL_MEMORY |
809 | 439 |
out_free_process_data: |
820 | 440 |
kfree(domain1_pd); |
809 | 441 |
#endif |
442 |
out_release_master: |
|
654
8278e1e27010
Minor changes in minimal example.
Florian Pose <fp@igh-essen.com>
parents:
643
diff
changeset
|
443 |
printk(KERN_ERR PFX "Releasing master...\n"); |
220 | 444 |
ecrt_release_master(master); |
809 | 445 |
out_return: |
654
8278e1e27010
Minor changes in minimal example.
Florian Pose <fp@igh-essen.com>
parents:
643
diff
changeset
|
446 |
printk(KERN_ERR PFX "Failed to load. Aborting.\n"); |
220 | 447 |
return -1; |
448 |
} |
|
449 |
||
450 |
/*****************************************************************************/ |
|
451 |
||
452 |
void __exit cleanup_mini_module(void) |
|
453 |
{ |
|
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
454 |
printk(KERN_INFO PFX "Stopping...\n"); |
220 | 455 |
|
449
3caf8ff4d8a2
Moved functionality of ecrt_master_deactivate() (now deprecated) to ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents:
446
diff
changeset
|
456 |
del_timer_sync(&timer); |
809 | 457 |
|
1171
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
458 |
#if EXTERNAL_MEMORY |
820 | 459 |
kfree(domain1_pd); |
809 | 460 |
#endif |
461 |
||
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
462 |
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
|
463 |
ecrt_release_master(master); |
220 | 464 |
|
654
8278e1e27010
Minor changes in minimal example.
Florian Pose <fp@igh-essen.com>
parents:
643
diff
changeset
|
465 |
printk(KERN_INFO PFX "Unloading.\n"); |
220 | 466 |
} |
467 |
||
468 |
/*****************************************************************************/ |
|
469 |
||
470 |
MODULE_LICENSE("GPL"); |
|
512
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
471 |
MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>"); |
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
472 |
MODULE_DESCRIPTION("EtherCAT minimal test environment"); |
220 | 473 |
|
474 |
module_init(init_mini_module); |
|
475 |
module_exit(cleanup_mini_module); |
|
476 |
||
477 |
/*****************************************************************************/ |