author | Florian Pose <fp@igh-essen.com> |
Tue, 27 Apr 2010 10:13:31 +0200 | |
changeset 1910 | 9a741a3d01bb |
parent 1613 | 070b4b420ab1 |
child 2024 | 96e2ae6cce95 |
child 2421 | bc2d4bf9cbe5 |
permissions | -rw-r--r-- |
220 | 1 |
/****************************************************************************** |
2 |
* |
|
3 |
* $Id$ |
|
4 |
* |
|
1326
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1239
diff
changeset
|
5 |
* Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH |
220 | 6 |
* |
7 |
* This file is part of the IgH EtherCAT Master. |
|
8 |
* |
|
1326
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1239
diff
changeset
|
9 |
* The IgH EtherCAT Master is free software; you can redistribute it and/or |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1239
diff
changeset
|
10 |
* modify it under the terms of the GNU General Public License version 2, as |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1239
diff
changeset
|
11 |
* published by the Free Software Foundation. |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1239
diff
changeset
|
12 |
* |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1239
diff
changeset
|
13 |
* The IgH EtherCAT Master is distributed in the hope that it will be useful, |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1239
diff
changeset
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1239
diff
changeset
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1239
diff
changeset
|
16 |
* Public License for more details. |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1239
diff
changeset
|
17 |
* |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1239
diff
changeset
|
18 |
* You should have received a copy of the GNU General Public License along |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1239
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 |
* |
|
1363
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
22 |
* --- |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
23 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
24 |
* The license mentioned above concerns the source code only. Using the |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
25 |
* EtherCAT technology and brand is only permitted in compliance with the |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
26 |
* 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
|
27 |
* |
220 | 28 |
*****************************************************************************/ |
29 |
||
1501
59990318c95b
Added semaphore header distinction in minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1500
diff
changeset
|
30 |
#include <linux/version.h> |
220 | 31 |
#include <linux/module.h> |
32 |
#include <linux/timer.h> |
|
33 |
#include <linux/interrupt.h> |
|
1239
b50b93faaf3e
Used ERR_PTR() macro for return value of ecrt_request_master().
Florian Pose <fp@igh-essen.com>
parents:
1212
diff
changeset
|
34 |
#include <linux/err.h> |
220 | 35 |
|
1501
59990318c95b
Added semaphore header distinction in minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1500
diff
changeset
|
36 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27) |
59990318c95b
Added semaphore header distinction in minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1500
diff
changeset
|
37 |
#include <linux/semaphore.h> |
59990318c95b
Added semaphore header distinction in minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1500
diff
changeset
|
38 |
#else |
59990318c95b
Added semaphore header distinction in minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1500
diff
changeset
|
39 |
#include <asm/semaphore.h> |
59990318c95b
Added semaphore header distinction in minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1500
diff
changeset
|
40 |
#endif |
59990318c95b
Added semaphore header distinction in minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1500
diff
changeset
|
41 |
|
223
daa5e5656b35
Applied new path information to example modules.
Florian Pose <fp@igh-essen.com>
parents:
220
diff
changeset
|
42 |
#include "../../include/ecrt.h" // EtherCAT realtime interface |
1613
070b4b420ab1
TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
1581
diff
changeset
|
43 |
|
070b4b420ab1
TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
1581
diff
changeset
|
44 |
#include "serial.h" |
220 | 45 |
|
820 | 46 |
/*****************************************************************************/ |
47 |
||
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
48 |
// Module parameters |
220 | 49 |
#define FREQUENCY 100 |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
50 |
|
1171
de880622f253
Alternative Pdo assignment for el3162.
Florian Pose <fp@igh-essen.com>
parents:
1082
diff
changeset
|
51 |
// Optional features |
1567 | 52 |
|
53 |
#define PFX "ec_tty_example: " |
|
820 | 54 |
|
55 |
/*****************************************************************************/ |
|
220 | 56 |
|
57 |
// EtherCAT |
|
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
58 |
static ec_master_t *master = NULL; |
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
59 |
static ec_master_state_t master_state = {}; |
1500
ed1a733efbc5
Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents:
1378
diff
changeset
|
60 |
struct semaphore master_sem; |
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
61 |
|
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
62 |
static ec_domain_t *domain1 = NULL; |
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
63 |
static ec_domain_state_t domain1_state = {}; |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
64 |
|
1080
088a61306930
Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents:
1061
diff
changeset
|
65 |
// Timer |
820 | 66 |
static struct timer_list timer; |
67 |
||
68 |
/*****************************************************************************/ |
|
69 |
||
70 |
// process data |
|
71 |
static uint8_t *domain1_pd; // process data memory |
|
72 |
||
1567 | 73 |
#define BusCouplerPos 0, 0 |
74 |
||
75 |
#define Beckhoff_EK1100 0x00000002, 0x044c2c52 |
|
1080
088a61306930
Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents:
1061
diff
changeset
|
76 |
|
088a61306930
Removed MSR example; adapted RTAI example; README files for examples.
Florian Pose <fp@igh-essen.com>
parents:
1061
diff
changeset
|
77 |
static unsigned int counter = 0; |
1567 | 78 |
|
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
79 |
/*****************************************************************************/ |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
80 |
|
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
81 |
void check_domain1_state(void) |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
82 |
{ |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
83 |
ec_domain_state_t ds; |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
84 |
|
1500
ed1a733efbc5
Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents:
1378
diff
changeset
|
85 |
down(&master_sem); |
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
86 |
ecrt_domain_state(domain1, &ds); |
1500
ed1a733efbc5
Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents:
1378
diff
changeset
|
87 |
up(&master_sem); |
1022
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
88 |
|
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
89 |
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
|
90 |
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
|
91 |
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
|
92 |
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
|
93 |
|
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
94 |
domain1_state = ds; |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
95 |
} |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
96 |
|
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
97 |
/*****************************************************************************/ |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
98 |
|
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
99 |
void check_master_state(void) |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
100 |
{ |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
101 |
ec_master_state_t ms; |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
102 |
|
1500
ed1a733efbc5
Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents:
1378
diff
changeset
|
103 |
down(&master_sem); |
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
104 |
ecrt_master_state(master, &ms); |
1500
ed1a733efbc5
Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents:
1378
diff
changeset
|
105 |
up(&master_sem); |
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
106 |
|
1022
8e49b519e6ba
Implemented ecrt_slave_config_state(); minor changes in
Florian Pose <fp@igh-essen.com>
parents:
909
diff
changeset
|
107 |
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
|
108 |
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
|
109 |
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
|
110 |
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
|
111 |
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
|
112 |
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
|
113 |
|
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
114 |
master_state = ms; |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
115 |
} |
220 | 116 |
|
117 |
/*****************************************************************************/ |
|
118 |
||
820 | 119 |
void cyclic_task(unsigned long data) |
120 |
{ |
|
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
121 |
// receive process data |
1500
ed1a733efbc5
Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents:
1378
diff
changeset
|
122 |
down(&master_sem); |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
280
diff
changeset
|
123 |
ecrt_master_receive(master); |
220 | 124 |
ecrt_domain_process(domain1); |
1500
ed1a733efbc5
Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents:
1378
diff
changeset
|
125 |
up(&master_sem); |
220 | 126 |
|
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
127 |
// check process data state (optional) |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
128 |
check_domain1_state(); |
512
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
129 |
|
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
130 |
if (counter) { |
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
131 |
counter--; |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
851
diff
changeset
|
132 |
} else { // do this at 1 Hz |
512
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
133 |
counter = FREQUENCY; |
818
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
134 |
|
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
135 |
// check for master state (optional) |
b6c87ae254c9
Calculate expected working counter for domains.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
136 |
check_master_state(); |
1567 | 137 |
} |
138 |
||
1613
070b4b420ab1
TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
1581
diff
changeset
|
139 |
run_serial_devices(domain1_pd); |
818
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 |
// send process data |
1500
ed1a733efbc5
Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents:
1378
diff
changeset
|
142 |
down(&master_sem); |
509
87baea61d0c7
Adjusted examples to 1.2.0 interface changes.
Florian Pose <fp@igh-essen.com>
parents:
472
diff
changeset
|
143 |
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
|
144 |
ecrt_master_send(master); |
1500
ed1a733efbc5
Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents:
1378
diff
changeset
|
145 |
up(&master_sem); |
220 | 146 |
|
147 |
// restart timer |
|
148 |
timer.expires += HZ / FREQUENCY; |
|
149 |
add_timer(&timer); |
|
150 |
} |
|
151 |
||
152 |
/*****************************************************************************/ |
|
153 |
||
1513
60ca68d853b8
Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents:
1501
diff
changeset
|
154 |
void send_callback(void *cb_data) |
60ca68d853b8
Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents:
1501
diff
changeset
|
155 |
{ |
60ca68d853b8
Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents:
1501
diff
changeset
|
156 |
ec_master_t *m = (ec_master_t *) cb_data; |
60ca68d853b8
Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents:
1501
diff
changeset
|
157 |
down(&master_sem); |
60ca68d853b8
Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents:
1501
diff
changeset
|
158 |
ecrt_master_send_ext(m); |
60ca68d853b8
Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents:
1501
diff
changeset
|
159 |
up(&master_sem); |
60ca68d853b8
Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents:
1501
diff
changeset
|
160 |
} |
60ca68d853b8
Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents:
1501
diff
changeset
|
161 |
|
60ca68d853b8
Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents:
1501
diff
changeset
|
162 |
/*****************************************************************************/ |
60ca68d853b8
Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents:
1501
diff
changeset
|
163 |
|
60ca68d853b8
Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents:
1501
diff
changeset
|
164 |
void receive_callback(void *cb_data) |
60ca68d853b8
Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents:
1501
diff
changeset
|
165 |
{ |
60ca68d853b8
Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents:
1501
diff
changeset
|
166 |
ec_master_t *m = (ec_master_t *) cb_data; |
60ca68d853b8
Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents:
1501
diff
changeset
|
167 |
down(&master_sem); |
60ca68d853b8
Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents:
1501
diff
changeset
|
168 |
ecrt_master_receive(m); |
1500
ed1a733efbc5
Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents:
1378
diff
changeset
|
169 |
up(&master_sem); |
220 | 170 |
} |
171 |
||
172 |
/*****************************************************************************/ |
|
173 |
||
174 |
int __init init_mini_module(void) |
|
175 |
{ |
|
1239
b50b93faaf3e
Used ERR_PTR() macro for return value of ecrt_request_master().
Florian Pose <fp@igh-essen.com>
parents:
1212
diff
changeset
|
176 |
int ret = -1; |
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
654
diff
changeset
|
177 |
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
|
178 |
|
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
179 |
printk(KERN_INFO PFX "Starting...\n"); |
220 | 180 |
|
1239
b50b93faaf3e
Used ERR_PTR() macro for return value of ecrt_request_master().
Florian Pose <fp@igh-essen.com>
parents:
1212
diff
changeset
|
181 |
master = ecrt_request_master(0); |
1378
1853f6c0b9b2
Removed IS_ERR() from minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
182 |
if (!master) { |
1613
070b4b420ab1
TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
1581
diff
changeset
|
183 |
printk(KERN_ERR PFX "Requesting master 0 failed.\n"); |
1378
1853f6c0b9b2
Removed IS_ERR() from minimal example.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
184 |
ret = -EBUSY; |
1613
070b4b420ab1
TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
1581
diff
changeset
|
185 |
goto out_return; |
220 | 186 |
} |
187 |
||
1579
326d47aa986c
applied komax patch to version r1822
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1501
diff
changeset
|
188 |
sema_init(&master_sem, 1); |
1513
60ca68d853b8
Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents:
1501
diff
changeset
|
189 |
ecrt_master_callbacks(master, send_callback, receive_callback, master); |
220 | 190 |
|
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
191 |
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
|
192 |
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
|
193 |
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
|
194 |
goto out_release_master; |
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
195 |
} |
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
196 |
|
1567 | 197 |
// Create configuration for bus coupler |
198 |
sc = ecrt_master_slave_config(master, BusCouplerPos, Beckhoff_EK1100); |
|
1613
070b4b420ab1
TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
1581
diff
changeset
|
199 |
if (!sc) { |
070b4b420ab1
TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
1581
diff
changeset
|
200 |
printk(KERN_ERR PFX "Failed to create slave config.\n"); |
070b4b420ab1
TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
1581
diff
changeset
|
201 |
ret = -ENOMEM; |
070b4b420ab1
TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
1581
diff
changeset
|
202 |
goto out_release_master; |
070b4b420ab1
TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
1581
diff
changeset
|
203 |
} |
070b4b420ab1
TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
1581
diff
changeset
|
204 |
|
070b4b420ab1
TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
1581
diff
changeset
|
205 |
create_serial_devices(master, domain1); |
809 | 206 |
|
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
207 |
printk(KERN_INFO PFX "Activating master...\n"); |
220 | 208 |
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
|
209 |
printk(KERN_ERR PFX "Failed to activate master!\n"); |
1613
070b4b420ab1
TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
1581
diff
changeset
|
210 |
goto out_free_serial; |
1567 | 211 |
} |
212 |
||
809 | 213 |
// Get internal process data for domain |
820 | 214 |
domain1_pd = ecrt_domain_data(domain1); |
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
215 |
|
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
216 |
printk(KERN_INFO PFX "Starting cyclic sample thread.\n"); |
220 | 217 |
init_timer(&timer); |
820 | 218 |
timer.function = cyclic_task; |
220 | 219 |
timer.expires = jiffies + 10; |
220 |
add_timer(&timer); |
|
221 |
||
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
222 |
printk(KERN_INFO PFX "Started.\n"); |
220 | 223 |
return 0; |
224 |
||
1613
070b4b420ab1
TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
1581
diff
changeset
|
225 |
out_free_serial: |
070b4b420ab1
TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
1581
diff
changeset
|
226 |
free_serial_devices(); |
809 | 227 |
out_release_master: |
654
8278e1e27010
Minor changes in minimal example.
Florian Pose <fp@igh-essen.com>
parents:
643
diff
changeset
|
228 |
printk(KERN_ERR PFX "Releasing master...\n"); |
220 | 229 |
ecrt_release_master(master); |
809 | 230 |
out_return: |
654
8278e1e27010
Minor changes in minimal example.
Florian Pose <fp@igh-essen.com>
parents:
643
diff
changeset
|
231 |
printk(KERN_ERR PFX "Failed to load. Aborting.\n"); |
1239
b50b93faaf3e
Used ERR_PTR() macro for return value of ecrt_request_master().
Florian Pose <fp@igh-essen.com>
parents:
1212
diff
changeset
|
232 |
return ret; |
220 | 233 |
} |
234 |
||
235 |
/*****************************************************************************/ |
|
236 |
||
237 |
void __exit cleanup_mini_module(void) |
|
238 |
{ |
|
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
239 |
printk(KERN_INFO PFX "Stopping...\n"); |
220 | 240 |
|
449
3caf8ff4d8a2
Moved functionality of ecrt_master_deactivate() (now deprecated) to ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents:
446
diff
changeset
|
241 |
del_timer_sync(&timer); |
809 | 242 |
|
1613
070b4b420ab1
TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
1581
diff
changeset
|
243 |
free_serial_devices(); |
070b4b420ab1
TTY: Sourced serial device functions out into serial.c/serial.h.
Florian Pose <fp@igh-essen.com>
parents:
1581
diff
changeset
|
244 |
|
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
551
diff
changeset
|
245 |
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
|
246 |
ecrt_release_master(master); |
220 | 247 |
|
654
8278e1e27010
Minor changes in minimal example.
Florian Pose <fp@igh-essen.com>
parents:
643
diff
changeset
|
248 |
printk(KERN_INFO PFX "Unloading.\n"); |
220 | 249 |
} |
250 |
||
251 |
/*****************************************************************************/ |
|
252 |
||
253 |
MODULE_LICENSE("GPL"); |
|
512
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
254 |
MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>"); |
24292123d174
Shorter critical sections in examples.
Florian Pose <fp@igh-essen.com>
parents:
509
diff
changeset
|
255 |
MODULE_DESCRIPTION("EtherCAT minimal test environment"); |
220 | 256 |
|
257 |
module_init(init_mini_module); |
|
258 |
module_exit(cleanup_mini_module); |
|
259 |
||
260 |
/*****************************************************************************/ |