author | Florian Pose <fp@igh-essen.com> |
Fri, 03 Mar 2017 17:08:39 +0100 | |
changeset 2678 | f5ffd1875da1 |
parent 2629 | a2701af27fde |
permissions | -rw-r--r-- |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1 |
/****************************************************************************** |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2 |
* |
2414
f35c7c8e6591
Replaced all mangled hg keywords.
Florian Pose <fp@igh-essen.com>
parents:
2166
diff
changeset
|
3 |
* $Id$ |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
4 |
* |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
5 |
* Copyright (C) 2006-2012 Florian Pose, Ingenieurgemeinschaft IgH |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
6 |
* |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
7 |
* This file is part of the IgH EtherCAT Master. |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
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:
1277
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:
1277
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:
1277
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:
1277
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:
1277
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:
1277
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:
1277
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:
1277
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:
1277
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:
1277
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:
1277
diff
changeset
|
19 |
* with the IgH EtherCAT Master; if not, write to the Free Software |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
20 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
21 |
* |
1363
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1349
diff
changeset
|
22 |
* --- |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1349
diff
changeset
|
23 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1349
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:
1349
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:
1349
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:
238
diff
changeset
|
27 |
* |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
28 |
*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
29 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
30 |
/** \file |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
31 |
* EtherCAT master state machine. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
32 |
*/ |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
33 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
34 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
35 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
36 |
#include "globals.h" |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
37 |
#include "master.h" |
329
d004349777fc
SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
38 |
#include "mailbox.h" |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
39 |
#include "slave_config.h" |
715
f12ff7c08623
Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
40 |
#ifdef EC_EOE |
661
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
41 |
#include "ethernet.h" |
715
f12ff7c08623
Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
42 |
#endif |
849
4b712ec8929d
Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
43 |
|
528
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
44 |
#include "fsm_master.h" |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
45 |
#include "fsm_foe.h" |
528
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
46 |
|
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
47 |
/*****************************************************************************/ |
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
48 |
|
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
49 |
/** Time difference [ns] to tolerate without setting a new system time offset. |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
50 |
*/ |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
51 |
#define EC_SYSTEM_TIME_TOLERANCE_NS 1000000 |
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
52 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
53 |
/*****************************************************************************/ |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
54 |
|
528
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
55 |
void ec_fsm_master_state_start(ec_fsm_master_t *); |
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
56 |
void ec_fsm_master_state_broadcast(ec_fsm_master_t *); |
2600
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
57 |
void ec_fsm_master_state_read_al_status(ec_fsm_master_t *); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
58 |
#ifdef EC_LOOP_CONTROL |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
59 |
void ec_fsm_master_state_read_dl_status(ec_fsm_master_t *); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
60 |
void ec_fsm_master_state_open_port(ec_fsm_master_t *); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
61 |
#endif |
528
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
62 |
void ec_fsm_master_state_acknowledge(ec_fsm_master_t *); |
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
63 |
void ec_fsm_master_state_configure_slave(ec_fsm_master_t *); |
717
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
64 |
void ec_fsm_master_state_clear_addresses(ec_fsm_master_t *); |
2600
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
65 |
#ifdef EC_LOOP_CONTROL |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
66 |
void ec_fsm_master_state_loop_control(ec_fsm_master_t *); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
67 |
#endif |
1420
5eb814732c46
Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents:
1408
diff
changeset
|
68 |
void ec_fsm_master_state_dc_measure_delays(ec_fsm_master_t *); |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
69 |
void ec_fsm_master_state_scan_slave(ec_fsm_master_t *); |
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
70 |
void ec_fsm_master_state_dc_read_offset(ec_fsm_master_t *); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
71 |
void ec_fsm_master_state_dc_write_offset(ec_fsm_master_t *); |
872 | 72 |
void ec_fsm_master_state_write_sii(ec_fsm_master_t *); |
905
6d74ebc603ee
Renamed state sdodict to sdo_dictionary.
Florian Pose <fp@igh-essen.com>
parents:
904
diff
changeset
|
73 |
void ec_fsm_master_state_sdo_dictionary(ec_fsm_master_t *); |
528
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
74 |
void ec_fsm_master_state_sdo_request(ec_fsm_master_t *); |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
75 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
76 |
void ec_fsm_master_enter_clear_addresses(ec_fsm_master_t *); |
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
77 |
void ec_fsm_master_enter_write_system_times(ec_fsm_master_t *); |
1583
017fa8fd9ac1
Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1579
diff
changeset
|
78 |
|
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
79 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
80 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
81 |
/** Constructor. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
82 |
*/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
83 |
void ec_fsm_master_init( |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
84 |
ec_fsm_master_t *fsm, /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
85 |
ec_master_t *master, /**< EtherCAT master. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
86 |
ec_datagram_t *datagram /**< Datagram object to use. */ |
528
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
87 |
) |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
88 |
{ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
89 |
fsm->master = master; |
528
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
90 |
fsm->datagram = datagram; |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
91 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
92 |
ec_fsm_master_reset(fsm); |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
93 |
|
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
94 |
// init sub-state-machines |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
95 |
ec_fsm_coe_init(&fsm->fsm_coe); |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
96 |
ec_fsm_soe_init(&fsm->fsm_soe); |
1174
235f34ca50e2
Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents:
1079
diff
changeset
|
97 |
ec_fsm_pdo_init(&fsm->fsm_pdo, &fsm->fsm_coe); |
235f34ca50e2
Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents:
1079
diff
changeset
|
98 |
ec_fsm_change_init(&fsm->fsm_change, fsm->datagram); |
235f34ca50e2
Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents:
1079
diff
changeset
|
99 |
ec_fsm_slave_config_init(&fsm->fsm_slave_config, fsm->datagram, |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
100 |
&fsm->fsm_change, &fsm->fsm_coe, &fsm->fsm_soe, &fsm->fsm_pdo); |
831
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
101 |
ec_fsm_slave_scan_init(&fsm->fsm_slave_scan, fsm->datagram, |
1174
235f34ca50e2
Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents:
1079
diff
changeset
|
102 |
&fsm->fsm_slave_config, &fsm->fsm_pdo); |
528
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
103 |
ec_fsm_sii_init(&fsm->fsm_sii, fsm->datagram); |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
104 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
105 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
106 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
107 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
108 |
/** Destructor. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
109 |
*/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
110 |
void ec_fsm_master_clear( |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
111 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
112 |
) |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
113 |
{ |
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
114 |
// clear sub-state machines |
1174
235f34ca50e2
Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents:
1079
diff
changeset
|
115 |
ec_fsm_coe_clear(&fsm->fsm_coe); |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
116 |
ec_fsm_soe_clear(&fsm->fsm_soe); |
1174
235f34ca50e2
Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents:
1079
diff
changeset
|
117 |
ec_fsm_pdo_clear(&fsm->fsm_pdo); |
235f34ca50e2
Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents:
1079
diff
changeset
|
118 |
ec_fsm_change_clear(&fsm->fsm_change); |
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
119 |
ec_fsm_slave_config_clear(&fsm->fsm_slave_config); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
120 |
ec_fsm_slave_scan_clear(&fsm->fsm_slave_scan); |
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
121 |
ec_fsm_sii_clear(&fsm->fsm_sii); |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
122 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
123 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
124 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
125 |
|
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
126 |
/** Reset state machine. |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
127 |
*/ |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
128 |
void ec_fsm_master_reset( |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
129 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
130 |
) |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
131 |
{ |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
132 |
ec_device_index_t dev_idx; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
133 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
134 |
fsm->state = ec_fsm_master_state_start; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
135 |
fsm->idle = 0; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
136 |
fsm->dev_idx = EC_DEVICE_MAIN; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
137 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
138 |
for (dev_idx = EC_DEVICE_MAIN; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
139 |
dev_idx < ec_master_num_devices(fsm->master); dev_idx++) { |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
140 |
fsm->link_state[dev_idx] = 0; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
141 |
fsm->slaves_responding[dev_idx] = 0; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
142 |
fsm->slave_states[dev_idx] = EC_SLAVE_STATE_UNKNOWN; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
143 |
} |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
144 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
145 |
fsm->rescan_required = 0; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
146 |
} |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
147 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
148 |
/*****************************************************************************/ |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
149 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
150 |
/** Executes the current state of the state machine. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
151 |
* |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
152 |
* If the state machine's datagram is not sent or received yet, the execution |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
153 |
* of the state machine is delayed to the next cycle. |
1583
017fa8fd9ac1
Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1579
diff
changeset
|
154 |
* |
017fa8fd9ac1
Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1579
diff
changeset
|
155 |
* \return true, if the state machine was executed |
017fa8fd9ac1
Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1579
diff
changeset
|
156 |
*/ |
017fa8fd9ac1
Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1579
diff
changeset
|
157 |
int ec_fsm_master_exec( |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
158 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
159 |
) |
528
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
160 |
{ |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
161 |
if (fsm->datagram->state == EC_DATAGRAM_SENT |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
162 |
|| fsm->datagram->state == EC_DATAGRAM_QUEUED) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
163 |
// datagram was not sent or received yet. |
1583
017fa8fd9ac1
Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1579
diff
changeset
|
164 |
return 0; |
528
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
165 |
} |
2094
83e9160319ec
Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents:
2045
diff
changeset
|
166 |
|
528
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
167 |
fsm->state(fsm); |
1583
017fa8fd9ac1
Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1579
diff
changeset
|
168 |
return 1; |
446 | 169 |
} |
170 |
||
650
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
171 |
/*****************************************************************************/ |
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
172 |
|
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
173 |
/** |
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
174 |
* \return true, if the state machine is in an idle phase |
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
175 |
*/ |
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
176 |
int ec_fsm_master_idle( |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
177 |
const ec_fsm_master_t *fsm /**< Master state machine. */ |
650
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
178 |
) |
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
179 |
{ |
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
180 |
return fsm->idle; |
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
181 |
} |
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
182 |
|
1031
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
183 |
/*****************************************************************************/ |
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
184 |
|
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
185 |
/** Restarts the master state machine. |
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
186 |
*/ |
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
187 |
void ec_fsm_master_restart( |
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
188 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
189 |
) |
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
190 |
{ |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
191 |
fsm->dev_idx = EC_DEVICE_MAIN; |
1031
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
192 |
fsm->state = ec_fsm_master_state_start; |
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
193 |
fsm->state(fsm); // execute immediately |
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
194 |
} |
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
195 |
|
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
196 |
/****************************************************************************** |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
197 |
* Master state machine |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
198 |
*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
199 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
200 |
/** Master state: START. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
201 |
* |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
202 |
* Starts with getting slave count and slave states. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
203 |
*/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
204 |
void ec_fsm_master_state_start( |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
205 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
206 |
) |
528
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
207 |
{ |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
208 |
ec_master_t *master = fsm->master; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
209 |
|
650
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
210 |
fsm->idle = 1; |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
211 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
212 |
// check for emergency requests |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
213 |
if (!list_empty(&master->emerg_reg_requests)) { |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
214 |
ec_reg_request_t *request; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
215 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
216 |
// get first request |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
217 |
request = list_entry(master->emerg_reg_requests.next, |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
218 |
ec_reg_request_t, list); |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
219 |
list_del_init(&request->list); // dequeue |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
220 |
request->state = EC_INT_REQUEST_BUSY; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
221 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
222 |
if (request->transfer_size > fsm->datagram->mem_size) { |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
223 |
EC_MASTER_ERR(master, "Emergency request data too large!\n"); |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
224 |
request->state = EC_INT_REQUEST_FAILURE; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
225 |
wake_up_all(&master->request_queue); |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
226 |
fsm->state(fsm); // continue |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
227 |
return; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
228 |
} |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
229 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
230 |
if (request->dir != EC_DIR_OUTPUT) { |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
231 |
EC_MASTER_ERR(master, "Emergency requests must be" |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
232 |
" write requests!\n"); |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
233 |
request->state = EC_INT_REQUEST_FAILURE; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
234 |
wake_up_all(&master->request_queue); |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
235 |
fsm->state(fsm); // continue |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
236 |
return; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
237 |
} |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
238 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
239 |
EC_MASTER_DBG(master, 1, "Writing emergency register request...\n"); |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
240 |
ec_datagram_apwr(fsm->datagram, request->ring_position, |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
241 |
request->address, request->transfer_size); |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
242 |
memcpy(fsm->datagram->data, request->data, request->transfer_size); |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
243 |
fsm->datagram->device_index = EC_DEVICE_MAIN; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
244 |
request->state = EC_INT_REQUEST_SUCCESS; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
245 |
wake_up_all(&master->request_queue); |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
246 |
return; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
247 |
} |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
248 |
|
2620
0e4d098db815
Abort requests started for slave_configs that don't have any actual slaves.
Gavin Lambert <gavinl@compacsort.com>
parents:
2600
diff
changeset
|
249 |
// check for detached config requests |
0e4d098db815
Abort requests started for slave_configs that don't have any actual slaves.
Gavin Lambert <gavinl@compacsort.com>
parents:
2600
diff
changeset
|
250 |
ec_master_expire_slave_config_requests(fsm->master); |
0e4d098db815
Abort requests started for slave_configs that don't have any actual slaves.
Gavin Lambert <gavinl@compacsort.com>
parents:
2600
diff
changeset
|
251 |
|
528
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
252 |
ec_datagram_brd(fsm->datagram, 0x0130, 2); |
1225
4d5b739edcb5
Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents:
1219
diff
changeset
|
253 |
ec_datagram_zero(fsm->datagram); |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
254 |
fsm->datagram->device_index = fsm->dev_idx; |
528
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
255 |
fsm->state = ec_fsm_master_state_broadcast; |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
256 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
257 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
258 |
/*****************************************************************************/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
259 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
260 |
/** Master state: BROADCAST. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
261 |
* |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
262 |
* Processes the broadcast read slave count and slaves states. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
263 |
*/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
264 |
void ec_fsm_master_state_broadcast( |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
265 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
266 |
) |
528
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
267 |
{ |
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
268 |
ec_datagram_t *datagram = fsm->datagram; |
1005 | 269 |
unsigned int i, size; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
270 |
ec_slave_t *slave; |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
271 |
ec_master_t *master = fsm->master; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
272 |
|
553
a4e0267825e3
Introduced topology_change_pending to delay bus scanning until IDLE mode
Florian Pose <fp@igh-essen.com>
parents:
538
diff
changeset
|
273 |
// bus topology change? |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
274 |
if (datagram->working_counter != fsm->slaves_responding[fsm->dev_idx]) { |
1961 | 275 |
fsm->rescan_required = 1; |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
276 |
fsm->slaves_responding[fsm->dev_idx] = datagram->working_counter; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
277 |
EC_MASTER_INFO(master, "%u slave(s) responding on %s device.\n", |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
278 |
fsm->slaves_responding[fsm->dev_idx], |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
279 |
ec_device_names[fsm->dev_idx != 0]); |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
280 |
} |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
281 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
282 |
if (fsm->link_state[fsm->dev_idx] && |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
283 |
!master->devices[fsm->dev_idx].link_state) { |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
284 |
ec_device_index_t dev_idx; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
285 |
|
1921 | 286 |
EC_MASTER_DBG(master, 1, "Master state machine detected " |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
287 |
"link down on %s device. Clearing slave list.\n", |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
288 |
ec_device_names[fsm->dev_idx != 0]); |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
289 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
290 |
#ifdef EC_EOE |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
291 |
ec_master_eoe_stop(master); |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
292 |
ec_master_clear_eoe_handlers(master); |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
293 |
#endif |
1400
3c4923051e43
Clear slave list on link down.
Florian Pose <fp@igh-essen.com>
parents:
1388
diff
changeset
|
294 |
ec_master_clear_slaves(master); |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
295 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
296 |
for (dev_idx = EC_DEVICE_MAIN; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
297 |
dev_idx < ec_master_num_devices(master); dev_idx++) { |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
298 |
fsm->slave_states[dev_idx] = 0x00; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
299 |
fsm->slaves_responding[dev_idx] = 0; /* Reset to trigger rescan on |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
300 |
next link up. */ |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
301 |
} |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
302 |
} |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
303 |
fsm->link_state[fsm->dev_idx] = master->devices[fsm->dev_idx].link_state; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
304 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
305 |
if (datagram->state == EC_DATAGRAM_RECEIVED && |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
306 |
fsm->slaves_responding[fsm->dev_idx]) { |
1021
fa5cf205f4f0
Set slave_states to 0x00 when no slaves are present.
Florian Pose <fp@igh-essen.com>
parents:
1005
diff
changeset
|
307 |
uint8_t states = EC_READ_U8(datagram->data); |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
308 |
if (states != fsm->slave_states[fsm->dev_idx]) { |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
309 |
// slave states changed |
1021
fa5cf205f4f0
Set slave_states to 0x00 when no slaves are present.
Florian Pose <fp@igh-essen.com>
parents:
1005
diff
changeset
|
310 |
char state_str[EC_STATE_STRING_SIZE]; |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
311 |
fsm->slave_states[fsm->dev_idx] = states; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
312 |
ec_state_string(states, state_str, 1); |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
313 |
EC_MASTER_INFO(master, "Slave states on %s device: %s.\n", |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
314 |
ec_device_names[fsm->dev_idx != 0], state_str); |
1021
fa5cf205f4f0
Set slave_states to 0x00 when no slaves are present.
Florian Pose <fp@igh-essen.com>
parents:
1005
diff
changeset
|
315 |
} |
fa5cf205f4f0
Set slave_states to 0x00 when no slaves are present.
Florian Pose <fp@igh-essen.com>
parents:
1005
diff
changeset
|
316 |
} else { |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
317 |
fsm->slave_states[fsm->dev_idx] = 0x00; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
318 |
} |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
319 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
320 |
fsm->dev_idx++; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
321 |
if (fsm->dev_idx < ec_master_num_devices(master)) { |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
322 |
// check number of responding slaves on next device |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
323 |
fsm->state = ec_fsm_master_state_start; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
324 |
fsm->state(fsm); // execute immediately |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
325 |
return; |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
326 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
327 |
|
1961 | 328 |
if (fsm->rescan_required) { |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
329 |
down(&master->scan_sem); |
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
330 |
if (!master->allow_scan) { |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
331 |
up(&master->scan_sem); |
900
f8b5c6d21705
Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents:
880
diff
changeset
|
332 |
} else { |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
333 |
unsigned int count = 0, next_dev_slave, ring_position; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
334 |
ec_device_index_t dev_idx; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
335 |
|
900
f8b5c6d21705
Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents:
880
diff
changeset
|
336 |
master->scan_busy = 1; |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
337 |
up(&master->scan_sem); |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
338 |
|
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
339 |
// clear all slaves and scan the bus |
1961 | 340 |
fsm->rescan_required = 0; |
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
341 |
fsm->idle = 0; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
342 |
fsm->scan_jiffies = jiffies; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
343 |
|
715
f12ff7c08623
Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
344 |
#ifdef EC_EOE |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
345 |
ec_master_eoe_stop(master); |
661
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
346 |
ec_master_clear_eoe_handlers(master); |
715
f12ff7c08623
Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
347 |
#endif |
992
50a44cbd30af
Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents:
987
diff
changeset
|
348 |
ec_master_clear_slaves(master); |
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
349 |
|
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
350 |
for (dev_idx = EC_DEVICE_MAIN; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
351 |
dev_idx < ec_master_num_devices(master); dev_idx++) { |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
352 |
count += fsm->slaves_responding[dev_idx]; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
353 |
} |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
354 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
355 |
if (!count) { |
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
356 |
// no slaves present -> finish state machine. |
900
f8b5c6d21705
Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents:
880
diff
changeset
|
357 |
master->scan_busy = 0; |
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
358 |
wake_up_interruptible(&master->scan_queue); |
1031
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
359 |
ec_fsm_master_restart(fsm); |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
360 |
return; |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
361 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
362 |
|
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
363 |
size = sizeof(ec_slave_t) * count; |
2146
05c6ddef33ab
Fixed missing return causing slaves not going to OP.
Florian Pose <fp@igh-essen.com>
parents:
2145
diff
changeset
|
364 |
if (!(master->slaves = |
05c6ddef33ab
Fixed missing return causing slaves not going to OP.
Florian Pose <fp@igh-essen.com>
parents:
2145
diff
changeset
|
365 |
(ec_slave_t *) kmalloc(size, GFP_KERNEL))) { |
1921 | 366 |
EC_MASTER_ERR(master, "Failed to allocate %u bytes" |
367 |
" of slave memory!\n", size); |
|
1000
5746fdd1ca2e
Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
368 |
master->scan_busy = 0; |
5746fdd1ca2e
Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
369 |
wake_up_interruptible(&master->scan_queue); |
1031
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
370 |
ec_fsm_master_restart(fsm); |
1000
5746fdd1ca2e
Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
371 |
return; |
5746fdd1ca2e
Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
372 |
} |
5746fdd1ca2e
Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
373 |
|
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
374 |
// init slaves |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
375 |
dev_idx = EC_DEVICE_MAIN; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
376 |
next_dev_slave = fsm->slaves_responding[dev_idx]; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
377 |
ring_position = 0; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
378 |
for (i = 0; i < count; i++, ring_position++) { |
1000
5746fdd1ca2e
Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
379 |
slave = master->slaves + i; |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
380 |
while (i >= next_dev_slave) { |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
381 |
dev_idx++; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
382 |
next_dev_slave += fsm->slaves_responding[dev_idx]; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
383 |
ring_position = 0; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
384 |
} |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
385 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
386 |
ec_slave_init(slave, master, dev_idx, ring_position, i + 1); |
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
387 |
|
1029
61ffe5f22306
Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents:
1028
diff
changeset
|
388 |
// do not force reconfiguration in operation phase to avoid |
908
386b908033be
Replaced self_configured flag with force_config flag.
Florian Pose <fp@igh-essen.com>
parents:
907
diff
changeset
|
389 |
// unnecesssary process data interruptions |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
390 |
if (master->phase != EC_OPERATION) { |
908
386b908033be
Replaced self_configured flag with force_config flag.
Florian Pose <fp@igh-essen.com>
parents:
907
diff
changeset
|
391 |
slave->force_config = 1; |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
392 |
} |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
393 |
} |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
394 |
master->slave_count = count; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
395 |
master->fsm_slave = master->slaves; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
396 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
397 |
/* start with first device with slaves responding; at least one |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
398 |
* has responding slaves, otherwise count would be zero. */ |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
399 |
fsm->dev_idx = EC_DEVICE_MAIN; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
400 |
while (!fsm->slaves_responding[fsm->dev_idx]) { |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
401 |
fsm->dev_idx++; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
402 |
} |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
403 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
404 |
ec_fsm_master_enter_clear_addresses(fsm); |
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
405 |
return; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
406 |
} |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
407 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
408 |
|
1000
5746fdd1ca2e
Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
409 |
if (master->slave_count) { |
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
410 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
411 |
// application applied configurations |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
412 |
if (master->config_changed) { |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
413 |
master->config_changed = 0; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
414 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
415 |
EC_MASTER_DBG(master, 1, "Configuration changed.\n"); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
416 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
417 |
fsm->slave = master->slaves; // begin with first slave |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
418 |
ec_fsm_master_enter_write_system_times(fsm); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
419 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
420 |
} else { |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
421 |
// fetch state from first slave |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
422 |
fsm->slave = master->slaves; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
423 |
ec_datagram_fprd(fsm->datagram, fsm->slave->station_address, |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
424 |
0x0130, 2); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
425 |
ec_datagram_zero(datagram); |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
426 |
fsm->datagram->device_index = fsm->slave->device_index; |
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
427 |
fsm->retries = EC_FSM_RETRIES; |
2600
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
428 |
fsm->state = ec_fsm_master_state_read_al_status; |
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
429 |
} |
1000
5746fdd1ca2e
Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
430 |
} else { |
1031
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
431 |
ec_fsm_master_restart(fsm); |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
432 |
} |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
433 |
} |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
434 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
435 |
/*****************************************************************************/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
436 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
437 |
/** Check for pending SII write requests and process one. |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
438 |
* |
872 | 439 |
* \return non-zero, if an SII write request is processed. |
601
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
440 |
*/ |
872 | 441 |
int ec_fsm_master_action_process_sii( |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
442 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
601
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
443 |
) |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
444 |
{ |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
445 |
ec_master_t *master = fsm->master; |
872 | 446 |
ec_sii_write_request_t *request; |
601
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
447 |
|
604
74ceacf42710
Fixed possible race with next request pointer again.
Florian Pose <fp@igh-essen.com>
parents:
603
diff
changeset
|
448 |
// search the first request to be processed |
74ceacf42710
Fixed possible race with next request pointer again.
Florian Pose <fp@igh-essen.com>
parents:
603
diff
changeset
|
449 |
while (1) { |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1064
diff
changeset
|
450 |
if (list_empty(&master->sii_requests)) |
604
74ceacf42710
Fixed possible race with next request pointer again.
Florian Pose <fp@igh-essen.com>
parents:
603
diff
changeset
|
451 |
break; |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1064
diff
changeset
|
452 |
|
604
74ceacf42710
Fixed possible race with next request pointer again.
Florian Pose <fp@igh-essen.com>
parents:
603
diff
changeset
|
453 |
// get first request |
872 | 454 |
request = list_entry(master->sii_requests.next, |
455 |
ec_sii_write_request_t, list); |
|
601
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
456 |
list_del_init(&request->list); // dequeue |
1209 | 457 |
request->state = EC_INT_REQUEST_BUSY; |
601
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
458 |
|
872 | 459 |
// found pending SII write operation. execute it! |
1921 | 460 |
EC_SLAVE_DBG(request->slave, 1, "Writing SII data...\n"); |
872 | 461 |
fsm->sii_request = request; |
462 |
fsm->sii_index = 0; |
|
979
405cc2d033e0
Renamed some fields in ec_sii_request_t to word addressing.
Florian Pose <fp@igh-essen.com>
parents:
969
diff
changeset
|
463 |
ec_fsm_sii_write(&fsm->fsm_sii, request->slave, request->offset, |
405cc2d033e0
Renamed some fields in ec_sii_request_t to word addressing.
Florian Pose <fp@igh-essen.com>
parents:
969
diff
changeset
|
464 |
request->words, EC_FSM_SII_USE_CONFIGURED_ADDRESS); |
872 | 465 |
fsm->state = ec_fsm_master_state_write_sii; |
601
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
466 |
fsm->state(fsm); // execute immediately |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
467 |
return 1; |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
468 |
} |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
469 |
|
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
470 |
return 0; |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
471 |
} |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
472 |
|
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
473 |
/*****************************************************************************/ |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
474 |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
475 |
/** Check for pending SDO requests and process one. |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
476 |
* |
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
477 |
* \return non-zero, if an SDO request is processed. |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
478 |
*/ |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
479 |
int ec_fsm_master_action_process_sdo( |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
480 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
481 |
) |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
482 |
{ |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
483 |
ec_master_t *master = fsm->master; |
1000
5746fdd1ca2e
Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
484 |
ec_slave_t *slave; |
5746fdd1ca2e
Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
485 |
ec_sdo_request_t *req; |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
486 |
|
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
487 |
// search for internal requests to be processed |
1000
5746fdd1ca2e
Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
488 |
for (slave = master->slaves; |
5746fdd1ca2e
Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
489 |
slave < master->slaves + master->slave_count; |
5746fdd1ca2e
Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
490 |
slave++) { |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
491 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
492 |
if (!slave->config) { |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
493 |
continue; |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
494 |
} |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
495 |
|
2629
a2701af27fde
Internal SDO requests now synchronized with external requests.
Knud Baastrup <kba@deif.com>
parents:
2620
diff
changeset
|
496 |
if (!ec_fsm_slave_is_ready(&slave->fsm)) { |
a2701af27fde
Internal SDO requests now synchronized with external requests.
Knud Baastrup <kba@deif.com>
parents:
2620
diff
changeset
|
497 |
EC_SLAVE_DBG(slave, 1, "Busy - processing external request!\n"); |
a2701af27fde
Internal SDO requests now synchronized with external requests.
Knud Baastrup <kba@deif.com>
parents:
2620
diff
changeset
|
498 |
continue; |
a2701af27fde
Internal SDO requests now synchronized with external requests.
Knud Baastrup <kba@deif.com>
parents:
2620
diff
changeset
|
499 |
} |
a2701af27fde
Internal SDO requests now synchronized with external requests.
Knud Baastrup <kba@deif.com>
parents:
2620
diff
changeset
|
500 |
|
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
501 |
list_for_each_entry(req, &slave->config->sdo_requests, list) { |
1209 | 502 |
if (req->state == EC_INT_REQUEST_QUEUED) { |
880 | 503 |
|
504 |
if (ec_sdo_request_timed_out(req)) { |
|
1209 | 505 |
req->state = EC_INT_REQUEST_FAILURE; |
1921 | 506 |
EC_SLAVE_DBG(slave, 1, "Internal SDO request" |
507 |
" timed out.\n"); |
|
880 | 508 |
continue; |
509 |
} |
|
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
510 |
|
987
3c9090138140
Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
511 |
if (slave->current_state == EC_SLAVE_STATE_INIT) { |
1209 | 512 |
req->state = EC_INT_REQUEST_FAILURE; |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
513 |
continue; |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
514 |
} |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
515 |
|
1209 | 516 |
req->state = EC_INT_REQUEST_BUSY; |
1921 | 517 |
EC_SLAVE_DBG(slave, 1, "Processing internal" |
518 |
" SDO request...\n"); |
|
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
519 |
fsm->idle = 0; |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
520 |
fsm->sdo_request = req; |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
521 |
fsm->slave = slave; |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
522 |
fsm->state = ec_fsm_master_state_sdo_request; |
859
233e32f428e1
Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents:
858
diff
changeset
|
523 |
ec_fsm_coe_transfer(&fsm->fsm_coe, slave, req); |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
524 |
ec_fsm_coe_exec(&fsm->fsm_coe, fsm->datagram); |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
525 |
return 1; |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
526 |
} |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
527 |
} |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
528 |
} |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
529 |
return 0; |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
530 |
} |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
531 |
|
1597
491dea6f4fd7
Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1596
diff
changeset
|
532 |
/*****************************************************************************/ |
491dea6f4fd7
Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1596
diff
changeset
|
533 |
|
491dea6f4fd7
Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1596
diff
changeset
|
534 |
/** Master action: IDLE. |
491dea6f4fd7
Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1596
diff
changeset
|
535 |
* |
491dea6f4fd7
Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1596
diff
changeset
|
536 |
* Does secondary work. |
491dea6f4fd7
Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1596
diff
changeset
|
537 |
*/ |
491dea6f4fd7
Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1596
diff
changeset
|
538 |
void ec_fsm_master_action_idle( |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
539 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
540 |
) |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
541 |
{ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
542 |
ec_master_t *master = fsm->master; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
543 |
ec_slave_t *slave; |
1597
491dea6f4fd7
Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1596
diff
changeset
|
544 |
|
491dea6f4fd7
Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1596
diff
changeset
|
545 |
// Check for pending internal SDO requests |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
546 |
if (ec_fsm_master_action_process_sdo(fsm)) { |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
547 |
return; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
548 |
} |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
549 |
|
1831
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
1830
diff
changeset
|
550 |
// enable processing of requests |
1804 | 551 |
for (slave = master->slaves; |
552 |
slave < master->slaves + master->slave_count; |
|
553 |
slave++) { |
|
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
554 |
ec_fsm_slave_set_ready(&slave->fsm); |
1804 | 555 |
} |
556 |
||
557 |
// check, if slaves have an SDO dictionary to read out. |
|
1000
5746fdd1ca2e
Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
558 |
for (slave = master->slaves; |
5746fdd1ca2e
Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
559 |
slave < master->slaves + master->slave_count; |
5746fdd1ca2e
Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
560 |
slave++) { |
910
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
561 |
if (!(slave->sii.mailbox_protocols & EC_MBOX_COE) |
1219
aa030fb1e980
Only query Sdo information service, if slave supports it.
Florian Pose <fp@igh-essen.com>
parents:
1209
diff
changeset
|
562 |
|| (slave->sii.has_general |
aa030fb1e980
Only query Sdo information service, if slave supports it.
Florian Pose <fp@igh-essen.com>
parents:
1209
diff
changeset
|
563 |
&& !slave->sii.coe_details.enable_sdo_info) |
442
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
564 |
|| slave->sdo_dictionary_fetched |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
565 |
|| slave->current_state == EC_SLAVE_STATE_INIT |
1219
aa030fb1e980
Only query Sdo information service, if slave supports it.
Florian Pose <fp@igh-essen.com>
parents:
1209
diff
changeset
|
566 |
|| slave->current_state == EC_SLAVE_STATE_UNKNOWN |
442
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
567 |
|| jiffies - slave->jiffies_preop < EC_WAIT_SDO_DICT * HZ |
987
3c9090138140
Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
568 |
) continue; |
442
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
569 |
|
1921 | 570 |
EC_SLAVE_DBG(slave, 1, "Fetching SDO dictionary.\n"); |
442
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
571 |
|
910
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
572 |
slave->sdo_dictionary_fetched = 1; |
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
573 |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
574 |
// start fetching SDO dictionary |
910
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
575 |
fsm->idle = 0; |
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
576 |
fsm->slave = slave; |
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
577 |
fsm->state = ec_fsm_master_state_sdo_dictionary; |
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
578 |
ec_fsm_coe_dictionary(&fsm->fsm_coe, slave); |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
579 |
ec_fsm_coe_exec(&fsm->fsm_coe, fsm->datagram); // execute immediately |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
580 |
fsm->datagram->device_index = fsm->slave->device_index; |
910
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
581 |
return; |
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
582 |
} |
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
583 |
|
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
584 |
// check for pending SII write operations. |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
585 |
if (ec_fsm_master_action_process_sii(fsm)) { |
910
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
586 |
return; // SII write request found |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
587 |
} |
1200 | 588 |
|
1031
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
589 |
ec_fsm_master_restart(fsm); |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
590 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
591 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
592 |
/*****************************************************************************/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
593 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
594 |
/** Master action: Get state of next slave. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
595 |
*/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
596 |
void ec_fsm_master_action_next_slave_state( |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
597 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
598 |
) |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
599 |
{ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
600 |
ec_master_t *master = fsm->master; |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
601 |
|
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
602 |
// is there another slave to query? |
1000
5746fdd1ca2e
Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
603 |
fsm->slave++; |
5746fdd1ca2e
Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
604 |
if (fsm->slave < master->slaves + master->slave_count) { |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
605 |
// fetch state from next slave |
650
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
606 |
fsm->idle = 1; |
1000
5746fdd1ca2e
Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
607 |
ec_datagram_fprd(fsm->datagram, |
5746fdd1ca2e
Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
608 |
fsm->slave->station_address, 0x0130, 2); |
1225
4d5b739edcb5
Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents:
1219
diff
changeset
|
609 |
ec_datagram_zero(fsm->datagram); |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
610 |
fsm->datagram->device_index = fsm->slave->device_index; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
611 |
fsm->retries = EC_FSM_RETRIES; |
2600
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
612 |
fsm->state = ec_fsm_master_state_read_al_status; |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
613 |
return; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
614 |
} |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
615 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
616 |
// all slaves processed |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
617 |
ec_fsm_master_action_idle(fsm); |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
618 |
} |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
619 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
620 |
/*****************************************************************************/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
621 |
|
2600
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
622 |
#ifdef EC_LOOP_CONTROL |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
623 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
624 |
/** Master action: Read DL status of current slave. |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
625 |
*/ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
626 |
void ec_fsm_master_action_read_dl_status( |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
627 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
628 |
) |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
629 |
{ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
630 |
ec_datagram_fprd(fsm->datagram, fsm->slave->station_address, 0x0110, 2); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
631 |
ec_datagram_zero(fsm->datagram); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
632 |
fsm->datagram->device_index = fsm->slave->device_index; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
633 |
fsm->retries = EC_FSM_RETRIES; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
634 |
fsm->state = ec_fsm_master_state_read_dl_status; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
635 |
} |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
636 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
637 |
/*****************************************************************************/ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
638 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
639 |
/** Master action: Open slave port. |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
640 |
*/ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
641 |
void ec_fsm_master_action_open_port( |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
642 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
643 |
) |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
644 |
{ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
645 |
EC_SLAVE_INFO(fsm->slave, "Opening ports.\n"); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
646 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
647 |
ec_datagram_fpwr(fsm->datagram, fsm->slave->station_address, 0x0101, 1); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
648 |
EC_WRITE_U8(fsm->datagram->data, 0x54); // port 0 auto, 1-3 auto-close |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
649 |
fsm->datagram->device_index = fsm->slave->device_index; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
650 |
fsm->retries = EC_FSM_RETRIES; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
651 |
fsm->state = ec_fsm_master_state_open_port; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
652 |
} |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
653 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
654 |
/*****************************************************************************/ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
655 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
656 |
/** Master state: READ DL STATUS. |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
657 |
* |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
658 |
* Fetches the DL state of a slave. |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
659 |
*/ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
660 |
void ec_fsm_master_state_read_dl_status( |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
661 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
662 |
) |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
663 |
{ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
664 |
ec_slave_t *slave = fsm->slave; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
665 |
ec_datagram_t *datagram = fsm->datagram; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
666 |
unsigned int i; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
667 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
668 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
669 |
return; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
670 |
} |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
671 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
672 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
673 |
EC_SLAVE_ERR(slave, "Failed to receive AL state datagram: "); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
674 |
ec_datagram_print_state(datagram); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
675 |
ec_fsm_master_restart(fsm); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
676 |
return; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
677 |
} |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
678 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
679 |
// did the slave not respond to its station address? |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
680 |
if (datagram->working_counter != 1) { |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
681 |
// try again next time |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
682 |
ec_fsm_master_action_next_slave_state(fsm); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
683 |
return; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
684 |
} |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
685 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
686 |
ec_slave_set_dl_status(slave, EC_READ_U16(datagram->data)); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
687 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
688 |
// process port state machines |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
689 |
for (i = 0; i < EC_MAX_PORTS; i++) { |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
690 |
ec_slave_port_t *port = &slave->ports[i]; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
691 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
692 |
switch (port->state) { |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
693 |
case EC_SLAVE_PORT_DOWN: |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
694 |
if (port->link.loop_closed) { |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
695 |
if (port->link.link_up) { |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
696 |
port->link_detection_jiffies = jiffies; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
697 |
port->state = EC_SLAVE_PORT_WAIT; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
698 |
} |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
699 |
} |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
700 |
else { // loop open |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
701 |
port->state = EC_SLAVE_PORT_UP; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
702 |
} |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
703 |
break; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
704 |
case EC_SLAVE_PORT_WAIT: |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
705 |
if (port->link.link_up) { |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
706 |
if (jiffies - port->link_detection_jiffies > |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
707 |
HZ * EC_PORT_WAIT_MS / 1000) { |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
708 |
port->state = EC_SLAVE_PORT_UP; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
709 |
ec_fsm_master_action_open_port(fsm); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
710 |
return; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
711 |
} |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
712 |
} |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
713 |
else { // link down |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
714 |
port->state = EC_SLAVE_PORT_DOWN; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
715 |
} |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
716 |
break; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
717 |
default: // EC_SLAVE_PORT_UP |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
718 |
if (!port->link.link_up) { |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
719 |
port->state = EC_SLAVE_PORT_DOWN; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
720 |
} |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
721 |
break; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
722 |
} |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
723 |
} |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
724 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
725 |
// process next slave |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
726 |
ec_fsm_master_action_next_slave_state(fsm); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
727 |
} |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
728 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
729 |
/*****************************************************************************/ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
730 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
731 |
/** Master state: OPEN_PORT. |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
732 |
* |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
733 |
* Opens slave ports. |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
734 |
*/ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
735 |
void ec_fsm_master_state_open_port( |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
736 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
737 |
) |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
738 |
{ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
739 |
ec_slave_t *slave = fsm->slave; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
740 |
ec_datagram_t *datagram = fsm->datagram; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
741 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
742 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
743 |
return; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
744 |
} |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
745 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
746 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
747 |
EC_SLAVE_ERR(slave, "Failed to receive port open datagram: "); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
748 |
ec_datagram_print_state(datagram); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
749 |
ec_fsm_master_restart(fsm); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
750 |
return; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
751 |
} |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
752 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
753 |
// did the slave not respond to its station address? |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
754 |
if (datagram->working_counter != 1) { |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
755 |
EC_SLAVE_ERR(slave, "Did not respond to port open command!\n"); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
756 |
return; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
757 |
} |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
758 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
759 |
// process next slave |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
760 |
ec_fsm_master_action_next_slave_state(fsm); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
761 |
} |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
762 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
763 |
#endif |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
764 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
765 |
/*****************************************************************************/ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
766 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
767 |
/** Master action: Configure. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
768 |
*/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
769 |
void ec_fsm_master_action_configure( |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
770 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
771 |
) |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
772 |
{ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
773 |
ec_master_t *master = fsm->master; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
774 |
ec_slave_t *slave = fsm->slave; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
775 |
|
2098
0ce254664c81
Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents:
2094
diff
changeset
|
776 |
if (master->config_changed) { |
2112
70afe990c10e
Bugfix: Reset config_changed flag when aborting state check.
Florian Pose <fp@igh-essen.com>
parents:
2098
diff
changeset
|
777 |
master->config_changed = 0; |
70afe990c10e
Bugfix: Reset config_changed flag when aborting state check.
Florian Pose <fp@igh-essen.com>
parents:
2098
diff
changeset
|
778 |
|
2098
0ce254664c81
Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents:
2094
diff
changeset
|
779 |
// abort iterating through slaves, |
0ce254664c81
Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents:
2094
diff
changeset
|
780 |
// first compensate DC system time offsets, |
0ce254664c81
Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents:
2094
diff
changeset
|
781 |
// then begin configuring at slave 0 |
0ce254664c81
Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents:
2094
diff
changeset
|
782 |
EC_MASTER_DBG(master, 1, "Configuration changed" |
0ce254664c81
Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents:
2094
diff
changeset
|
783 |
" (aborting state check).\n"); |
0ce254664c81
Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents:
2094
diff
changeset
|
784 |
|
0ce254664c81
Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents:
2094
diff
changeset
|
785 |
fsm->slave = master->slaves; // begin with first slave |
0ce254664c81
Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents:
2094
diff
changeset
|
786 |
ec_fsm_master_enter_write_system_times(fsm); |
2146
05c6ddef33ab
Fixed missing return causing slaves not going to OP.
Florian Pose <fp@igh-essen.com>
parents:
2145
diff
changeset
|
787 |
return; |
2098
0ce254664c81
Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents:
2094
diff
changeset
|
788 |
} |
0ce254664c81
Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents:
2094
diff
changeset
|
789 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
790 |
// Does the slave have to be configured? |
987
3c9090138140
Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
791 |
if ((slave->current_state != slave->requested_state |
3c9090138140
Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
792 |
|| slave->force_config) && !slave->error_flag) { |
1177 | 793 |
|
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
794 |
// Start slave configuration |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
795 |
down(&master->config_sem); |
2117
afb40fd6018e
Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents:
2113
diff
changeset
|
796 |
master->config_busy = 1; |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
797 |
up(&master->config_sem); |
2117
afb40fd6018e
Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents:
2113
diff
changeset
|
798 |
|
afb40fd6018e
Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents:
2113
diff
changeset
|
799 |
if (master->debug_level) { |
afb40fd6018e
Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents:
2113
diff
changeset
|
800 |
char old_state[EC_STATE_STRING_SIZE], |
afb40fd6018e
Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents:
2113
diff
changeset
|
801 |
new_state[EC_STATE_STRING_SIZE]; |
afb40fd6018e
Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents:
2113
diff
changeset
|
802 |
ec_state_string(slave->current_state, old_state, 0); |
afb40fd6018e
Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents:
2113
diff
changeset
|
803 |
ec_state_string(slave->requested_state, new_state, 0); |
afb40fd6018e
Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents:
2113
diff
changeset
|
804 |
EC_SLAVE_DBG(slave, 1, "Changing state from %s to %s%s.\n", |
afb40fd6018e
Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents:
2113
diff
changeset
|
805 |
old_state, new_state, |
afb40fd6018e
Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents:
2113
diff
changeset
|
806 |
slave->force_config ? " (forced)" : ""); |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
807 |
} |
2117
afb40fd6018e
Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents:
2113
diff
changeset
|
808 |
|
afb40fd6018e
Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents:
2113
diff
changeset
|
809 |
fsm->idle = 0; |
afb40fd6018e
Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents:
2113
diff
changeset
|
810 |
fsm->state = ec_fsm_master_state_configure_slave; |
afb40fd6018e
Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents:
2113
diff
changeset
|
811 |
ec_fsm_slave_config_start(&fsm->fsm_slave_config, slave); |
afb40fd6018e
Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents:
2113
diff
changeset
|
812 |
fsm->state(fsm); // execute immediately |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
813 |
fsm->datagram->device_index = fsm->slave->device_index; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
814 |
return; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
815 |
} |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
816 |
|
2600
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
817 |
#ifdef EC_LOOP_CONTROL |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
818 |
// read DL status |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
819 |
ec_fsm_master_action_read_dl_status(fsm); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
820 |
#else |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
821 |
// process next slave |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
822 |
ec_fsm_master_action_next_slave_state(fsm); |
2600
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
823 |
#endif |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
824 |
} |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
825 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
826 |
/*****************************************************************************/ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
827 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
828 |
/** Master state: READ AL STATUS. |
987
3c9090138140
Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
829 |
* |
3c9090138140
Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
830 |
* Fetches the AL state of a slave. |
3c9090138140
Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
831 |
*/ |
2600
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
832 |
void ec_fsm_master_state_read_al_status( |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
833 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
834 |
) |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
835 |
{ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
836 |
ec_slave_t *slave = fsm->slave; |
987
3c9090138140
Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
837 |
ec_datagram_t *datagram = fsm->datagram; |
3c9090138140
Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
838 |
|
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
839 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
840 |
return; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
841 |
} |
987
3c9090138140
Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
842 |
|
3c9090138140
Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
843 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
1921 | 844 |
EC_SLAVE_ERR(slave, "Failed to receive AL state datagram: "); |
1822
74e6ac2369f4
Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents:
1804
diff
changeset
|
845 |
ec_datagram_print_state(datagram); |
1031
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
846 |
ec_fsm_master_restart(fsm); |
987
3c9090138140
Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
847 |
return; |
3c9090138140
Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
848 |
} |
3c9090138140
Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
849 |
|
3c9090138140
Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
850 |
// did the slave not respond to its station address? |
3c9090138140
Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
851 |
if (datagram->working_counter != 1) { |
3c9090138140
Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
852 |
if (!slave->error_flag) { |
3c9090138140
Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
853 |
slave->error_flag = 1; |
1921 | 854 |
EC_SLAVE_DBG(slave, 1, "Slave did not respond to state query.\n"); |
987
3c9090138140
Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
855 |
} |
1961 | 856 |
fsm->rescan_required = 1; |
1031
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
857 |
ec_fsm_master_restart(fsm); |
987
3c9090138140
Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
858 |
return; |
3c9090138140
Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
859 |
} |
3c9090138140
Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
860 |
|
3c9090138140
Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents:
986
diff
changeset
|
861 |
// A single slave responded |
2600
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
862 |
ec_slave_set_al_status(slave, EC_READ_U8(datagram->data)); |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
863 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
864 |
if (!slave->error_flag) { |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
865 |
// Check, if new slave state has to be acknowledged |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
866 |
if (slave->current_state & EC_SLAVE_STATE_ACK_ERR) { |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
867 |
fsm->idle = 0; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
868 |
fsm->state = ec_fsm_master_state_acknowledge; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
869 |
ec_fsm_change_ack(&fsm->fsm_change, slave); |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
870 |
fsm->state(fsm); // execute immediately |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
871 |
return; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
872 |
} |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
873 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
874 |
// No acknowlegde necessary; check for configuration |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
875 |
ec_fsm_master_action_configure(fsm); |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
876 |
return; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
877 |
} |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
878 |
|
2600
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
879 |
#ifdef EC_LOOP_CONTROL |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
880 |
// read DL status |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
881 |
ec_fsm_master_action_read_dl_status(fsm); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
882 |
#else |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
883 |
// process next slave |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
884 |
ec_fsm_master_action_next_slave_state(fsm); |
2600
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
885 |
#endif |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
886 |
} |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
887 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
888 |
/*****************************************************************************/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
889 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
890 |
/** Master state: ACKNOWLEDGE. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
891 |
*/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
892 |
void ec_fsm_master_state_acknowledge( |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
893 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
894 |
) |
454
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
895 |
{ |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
896 |
ec_slave_t *slave = fsm->slave; |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
897 |
|
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
898 |
if (ec_fsm_change_exec(&fsm->fsm_change)) { |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
899 |
return; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
900 |
} |
454
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
901 |
|
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
902 |
if (!ec_fsm_change_success(&fsm->fsm_change)) { |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
903 |
fsm->slave->error_flag = 1; |
1921 | 904 |
EC_SLAVE_ERR(slave, "Failed to acknowledge state change.\n"); |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
905 |
} |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
906 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
907 |
ec_fsm_master_action_configure(fsm); |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
908 |
} |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
909 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
910 |
/*****************************************************************************/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
911 |
|
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
912 |
/** Start clearing slave addresses. |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
913 |
*/ |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
914 |
void ec_fsm_master_enter_clear_addresses( |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
915 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
916 |
) |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
917 |
{ |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
918 |
// broadcast clear all station addresses |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
919 |
ec_datagram_bwr(fsm->datagram, 0x0010, 2); |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
920 |
EC_WRITE_U16(fsm->datagram->data, 0x0000); |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
921 |
fsm->datagram->device_index = fsm->dev_idx; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
922 |
fsm->retries = EC_FSM_RETRIES; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
923 |
fsm->state = ec_fsm_master_state_clear_addresses; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
924 |
} |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
925 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
926 |
/*****************************************************************************/ |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
927 |
|
2600
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
928 |
/** Start measuring DC delays. |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
929 |
*/ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
930 |
void ec_fsm_master_enter_dc_measure_delays( |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
931 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
932 |
) |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
933 |
{ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
934 |
EC_MASTER_DBG(fsm->master, 1, "Sending broadcast-write" |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
935 |
" to measure transmission delays on %s link.\n", |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
936 |
ec_device_names[fsm->dev_idx != 0]); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
937 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
938 |
ec_datagram_bwr(fsm->datagram, 0x0900, 1); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
939 |
ec_datagram_zero(fsm->datagram); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
940 |
fsm->datagram->device_index = fsm->dev_idx; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
941 |
fsm->retries = EC_FSM_RETRIES; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
942 |
fsm->state = ec_fsm_master_state_dc_measure_delays; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
943 |
} |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
944 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
945 |
/*****************************************************************************/ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
946 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
947 |
#ifdef EC_LOOP_CONTROL |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
948 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
949 |
/** Start writing loop control registers. |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
950 |
*/ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
951 |
void ec_fsm_master_enter_loop_control( |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
952 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
953 |
) |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
954 |
{ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
955 |
EC_MASTER_DBG(fsm->master, 1, "Broadcast-writing" |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
956 |
" loop control registers on %s link.\n", |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
957 |
ec_device_names[fsm->dev_idx != 0]); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
958 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
959 |
ec_datagram_bwr(fsm->datagram, 0x0101, 1); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
960 |
EC_WRITE_U8(fsm->datagram->data, 0x54); // port 0 auto, 1-3 auto-close |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
961 |
fsm->datagram->device_index = fsm->dev_idx; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
962 |
fsm->retries = EC_FSM_RETRIES; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
963 |
fsm->state = ec_fsm_master_state_loop_control; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
964 |
} |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
965 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
966 |
/*****************************************************************************/ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
967 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
968 |
/** Master state: LOOP CONTROL. |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
969 |
*/ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
970 |
void ec_fsm_master_state_loop_control( |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
971 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
972 |
) |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
973 |
{ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
974 |
ec_master_t *master = fsm->master; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
975 |
ec_datagram_t *datagram = fsm->datagram; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
976 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
977 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
978 |
return; |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
979 |
} |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
980 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
981 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
982 |
EC_MASTER_ERR(master, "Failed to receive loop control" |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
983 |
" datagram on %s link: ", |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
984 |
ec_device_names[fsm->dev_idx != 0]); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
985 |
ec_datagram_print_state(datagram); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
986 |
} |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
987 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
988 |
ec_fsm_master_enter_dc_measure_delays(fsm); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
989 |
} |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
990 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
991 |
#endif |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
992 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
993 |
/*****************************************************************************/ |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
994 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
995 |
/** Master state: CLEAR ADDRESSES. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
996 |
*/ |
717
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
997 |
void ec_fsm_master_state_clear_addresses( |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
998 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
717
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
999 |
) |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
1000 |
{ |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
1001 |
ec_master_t *master = fsm->master; |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
1002 |
ec_datagram_t *datagram = fsm->datagram; |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
1003 |
|
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1004 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1005 |
return; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1006 |
} |
717
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
1007 |
|
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
1008 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
1921 | 1009 |
EC_MASTER_ERR(master, "Failed to receive address" |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1010 |
" clearing datagram on %s link: ", |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1011 |
ec_device_names[fsm->dev_idx != 0]); |
1921 | 1012 |
ec_datagram_print_state(datagram); |
900
f8b5c6d21705
Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents:
880
diff
changeset
|
1013 |
master->scan_busy = 0; |
794
684dea874956
Allow bus configuration when link is down.
Florian Pose <fp@igh-essen.com>
parents:
792
diff
changeset
|
1014 |
wake_up_interruptible(&master->scan_queue); |
1031
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
1015 |
ec_fsm_master_restart(fsm); |
717
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
1016 |
return; |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
1017 |
} |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
1018 |
|
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1019 |
if (datagram->working_counter != fsm->slaves_responding[fsm->dev_idx]) { |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1020 |
EC_MASTER_WARN(master, "Failed to clear station addresses on %s link:" |
1921 | 1021 |
" Cleared %u of %u", |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1022 |
ec_device_names[fsm->dev_idx != 0], datagram->working_counter, |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1023 |
fsm->slaves_responding[fsm->dev_idx]); |
717
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
1024 |
} |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
1025 |
|
2600
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
1026 |
#ifdef EC_LOOP_CONTROL |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
1027 |
ec_fsm_master_enter_loop_control(fsm); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
1028 |
#else |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
1029 |
ec_fsm_master_enter_dc_measure_delays(fsm); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
1030 |
#endif |
1420
5eb814732c46
Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents:
1408
diff
changeset
|
1031 |
} |
5eb814732c46
Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents:
1408
diff
changeset
|
1032 |
|
5eb814732c46
Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents:
1408
diff
changeset
|
1033 |
/*****************************************************************************/ |
5eb814732c46
Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents:
1408
diff
changeset
|
1034 |
|
5eb814732c46
Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents:
1408
diff
changeset
|
1035 |
/** Master state: DC MEASURE DELAYS. |
5eb814732c46
Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents:
1408
diff
changeset
|
1036 |
*/ |
5eb814732c46
Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents:
1408
diff
changeset
|
1037 |
void ec_fsm_master_state_dc_measure_delays( |
5eb814732c46
Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents:
1408
diff
changeset
|
1038 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
5eb814732c46
Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents:
1408
diff
changeset
|
1039 |
) |
5eb814732c46
Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents:
1408
diff
changeset
|
1040 |
{ |
5eb814732c46
Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents:
1408
diff
changeset
|
1041 |
ec_master_t *master = fsm->master; |
5eb814732c46
Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents:
1408
diff
changeset
|
1042 |
ec_datagram_t *datagram = fsm->datagram; |
5eb814732c46
Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents:
1408
diff
changeset
|
1043 |
|
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1044 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1045 |
return; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1046 |
} |
1420
5eb814732c46
Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents:
1408
diff
changeset
|
1047 |
|
5eb814732c46
Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents:
1408
diff
changeset
|
1048 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1049 |
EC_MASTER_ERR(master, "Failed to receive delay measuring datagram" |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1050 |
" on %s link: ", ec_device_names[fsm->dev_idx != 0]); |
1921 | 1051 |
ec_datagram_print_state(datagram); |
1420
5eb814732c46
Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents:
1408
diff
changeset
|
1052 |
master->scan_busy = 0; |
5eb814732c46
Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents:
1408
diff
changeset
|
1053 |
wake_up_interruptible(&master->scan_queue); |
5eb814732c46
Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents:
1408
diff
changeset
|
1054 |
ec_fsm_master_restart(fsm); |
5eb814732c46
Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents:
1408
diff
changeset
|
1055 |
return; |
5eb814732c46
Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents:
1408
diff
changeset
|
1056 |
} |
5eb814732c46
Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents:
1408
diff
changeset
|
1057 |
|
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1058 |
EC_MASTER_DBG(master, 1, "%u slaves responded to delay measuring" |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1059 |
" on %s link.\n", |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1060 |
datagram->working_counter, ec_device_names[fsm->dev_idx != 0]); |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1061 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1062 |
do { |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1063 |
fsm->dev_idx++; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1064 |
} while (fsm->dev_idx < ec_master_num_devices(master) && |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1065 |
!fsm->slaves_responding[fsm->dev_idx]); |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1066 |
if (fsm->dev_idx < ec_master_num_devices(master)) { |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1067 |
ec_fsm_master_enter_clear_addresses(fsm); |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1068 |
return; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1069 |
} |
1921 | 1070 |
|
1071 |
EC_MASTER_INFO(master, "Scanning bus.\n"); |
|
717
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
1072 |
|
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
1073 |
// begin scanning of slaves |
1000
5746fdd1ca2e
Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1074 |
fsm->slave = master->slaves; |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1075 |
EC_MASTER_DBG(master, 1, "Scanning slave %u on %s link.\n", |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1076 |
fsm->slave->ring_position, |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1077 |
ec_device_names[fsm->slave->device_index != 0]); |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1078 |
fsm->state = ec_fsm_master_state_scan_slave; |
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
1079 |
ec_fsm_slave_scan_start(&fsm->fsm_slave_scan, fsm->slave); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
1080 |
ec_fsm_slave_scan_exec(&fsm->fsm_slave_scan); // execute immediately |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1081 |
fsm->datagram->device_index = fsm->slave->device_index; |
717
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
1082 |
} |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
1083 |
|
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
1084 |
/*****************************************************************************/ |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
1085 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1086 |
/** Master state: SCAN SLAVE. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1087 |
* |
652 | 1088 |
* Executes the sub-statemachine for the scanning of a slave. |
1089 |
*/ |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1090 |
void ec_fsm_master_state_scan_slave( |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1091 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
652 | 1092 |
) |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1093 |
{ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1094 |
ec_master_t *master = fsm->master; |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
1095 |
#ifdef EC_EOE |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
1096 |
ec_slave_t *slave = fsm->slave; |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
1097 |
#endif |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1098 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1099 |
if (ec_fsm_slave_scan_exec(&fsm->fsm_slave_scan)) { |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1100 |
return; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1101 |
} |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1102 |
|
715
f12ff7c08623
Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
1103 |
#ifdef EC_EOE |
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
1104 |
if (slave->sii.mailbox_protocols & EC_MBOX_EOE) { |
661
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
1105 |
// create EoE handler for this slave |
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
1106 |
ec_eoe_t *eoe; |
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
1107 |
if (!(eoe = kmalloc(sizeof(ec_eoe_t), GFP_KERNEL))) { |
1921 | 1108 |
EC_SLAVE_ERR(slave, "Failed to allocate EoE handler memory!\n"); |
900
f8b5c6d21705
Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents:
880
diff
changeset
|
1109 |
} else if (ec_eoe_init(eoe, slave)) { |
1921 | 1110 |
EC_SLAVE_ERR(slave, "Failed to init EoE handler!\n"); |
661
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
1111 |
kfree(eoe); |
900
f8b5c6d21705
Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents:
880
diff
changeset
|
1112 |
} else { |
661
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
1113 |
list_add_tail(&eoe->list, &master->eoe_handlers); |
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
1114 |
} |
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
1115 |
} |
715
f12ff7c08623
Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
1116 |
#endif |
661
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
1117 |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1118 |
// another slave to fetch? |
1000
5746fdd1ca2e
Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1119 |
fsm->slave++; |
1002
0e1aaeb3540d
Fixed bug in slave scanning, causing a segmentation fault.
Florian Pose <fp@igh-essen.com>
parents:
1000
diff
changeset
|
1120 |
if (fsm->slave < master->slaves + master->slave_count) { |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1121 |
EC_MASTER_DBG(master, 1, "Scanning slave %u on %s link.\n", |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1122 |
fsm->slave->ring_position, |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1123 |
ec_device_names[fsm->slave->device_index != 0]); |
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
1124 |
ec_fsm_slave_scan_start(&fsm->fsm_slave_scan, fsm->slave); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
1125 |
ec_fsm_slave_scan_exec(&fsm->fsm_slave_scan); // execute immediately |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1126 |
fsm->datagram->device_index = fsm->slave->device_index; |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1127 |
return; |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1128 |
} |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1129 |
|
1931 | 1130 |
EC_MASTER_INFO(master, "Bus scanning completed in %lu ms.\n", |
1131 |
(jiffies - fsm->scan_jiffies) * 1000 / HZ); |
|
661
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
1132 |
|
900
f8b5c6d21705
Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents:
880
diff
changeset
|
1133 |
master->scan_busy = 0; |
f8b5c6d21705
Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents:
880
diff
changeset
|
1134 |
wake_up_interruptible(&master->scan_queue); |
f8b5c6d21705
Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents:
880
diff
changeset
|
1135 |
|
1425
c1322a8793c0
Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents:
1421
diff
changeset
|
1136 |
ec_master_calc_dc(master); |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1444
diff
changeset
|
1137 |
|
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
758
diff
changeset
|
1138 |
// Attach slave configurations |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
758
diff
changeset
|
1139 |
ec_master_attach_slave_configs(master); |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
758
diff
changeset
|
1140 |
|
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1141 |
#ifdef EC_EOE |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1142 |
// check if EoE processing has to be started |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1143 |
ec_master_eoe_start(master); |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1144 |
#endif |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1145 |
|
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1146 |
if (master->slave_count) { |
2112
70afe990c10e
Bugfix: Reset config_changed flag when aborting state check.
Florian Pose <fp@igh-essen.com>
parents:
2098
diff
changeset
|
1147 |
master->config_changed = 0; |
70afe990c10e
Bugfix: Reset config_changed flag when aborting state check.
Florian Pose <fp@igh-essen.com>
parents:
2098
diff
changeset
|
1148 |
|
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1149 |
fsm->slave = master->slaves; // begin with first slave |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1150 |
ec_fsm_master_enter_write_system_times(fsm); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1151 |
} else { |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1152 |
ec_fsm_master_restart(fsm); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1153 |
} |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1154 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1155 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1156 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1157 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1158 |
/** Master state: CONFIGURE SLAVE. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1159 |
* |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1160 |
* Starts configuring a slave. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1161 |
*/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1162 |
void ec_fsm_master_state_configure_slave( |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1163 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1164 |
) |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1165 |
{ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1166 |
ec_master_t *master = fsm->master; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1167 |
|
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1168 |
if (ec_fsm_slave_config_exec(&fsm->fsm_slave_config)) { |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1169 |
return; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1170 |
} |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1171 |
|
1277
1189e040fe12
merge -c1521 branches/stable-1.4: Fixed race concerning ec_slave_config_state->operational.
Florian Pose <fp@igh-essen.com>
parents:
1225
diff
changeset
|
1172 |
fsm->slave->force_config = 0; |
1189e040fe12
merge -c1521 branches/stable-1.4: Fixed race concerning ec_slave_config_state->operational.
Florian Pose <fp@igh-essen.com>
parents:
1225
diff
changeset
|
1173 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1174 |
// configuration finished |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1175 |
master->config_busy = 0; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1176 |
wake_up_interruptible(&master->config_queue); |
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
1177 |
|
900
f8b5c6d21705
Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents:
880
diff
changeset
|
1178 |
if (!ec_fsm_slave_config_success(&fsm->fsm_slave_config)) { |
f8b5c6d21705
Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents:
880
diff
changeset
|
1179 |
// TODO: mark slave_config as failed. |
f8b5c6d21705
Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents:
880
diff
changeset
|
1180 |
} |
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
1181 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1182 |
fsm->idle = 1; |
2600
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
1183 |
|
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
1184 |
#ifdef EC_LOOP_CONTROL |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
1185 |
// read DL status |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
1186 |
ec_fsm_master_action_read_dl_status(fsm); |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
1187 |
#else |
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
1188 |
// process next slave |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1189 |
ec_fsm_master_action_next_slave_state(fsm); |
2600
1a969896d52e
Added --enable-loop-control to make use of the loop control registers.
Florian Pose <fp@igh-essen.com>
parents:
2589
diff
changeset
|
1190 |
#endif |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1191 |
} |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1192 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1193 |
/*****************************************************************************/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1194 |
|
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1195 |
/** Start writing DC system times. |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1196 |
*/ |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1197 |
void ec_fsm_master_enter_write_system_times( |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1198 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1199 |
) |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1200 |
{ |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1201 |
ec_master_t *master = fsm->master; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1202 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1203 |
if (master->has_app_time) { |
2098
0ce254664c81
Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents:
2094
diff
changeset
|
1204 |
|
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1205 |
while (fsm->slave < master->slaves + master->slave_count) { |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1206 |
if (!fsm->slave->base_dc_supported |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1207 |
|| !fsm->slave->has_dc_system_time) { |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1208 |
fsm->slave++; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1209 |
continue; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1210 |
} |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1211 |
|
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1212 |
EC_SLAVE_DBG(fsm->slave, 1, "Checking system time offset.\n"); |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1213 |
|
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1214 |
// read DC system time (0x0910, 64 bit) |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1215 |
// gap (64 bit) |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1216 |
// and time offset (0x0920, 64 bit) |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1217 |
ec_datagram_fprd(fsm->datagram, fsm->slave->station_address, |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1218 |
0x0910, 24); |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1219 |
fsm->datagram->device_index = fsm->slave->device_index; |
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1220 |
fsm->retries = EC_FSM_RETRIES; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1221 |
fsm->state = ec_fsm_master_state_dc_read_offset; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1222 |
return; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1223 |
} |
2098
0ce254664c81
Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents:
2094
diff
changeset
|
1224 |
|
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1225 |
} else { |
2098
0ce254664c81
Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents:
2094
diff
changeset
|
1226 |
if (master->active) { |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1227 |
EC_MASTER_WARN(master, "No app_time received up to now," |
2145 | 1228 |
" but master already active.\n"); |
2098
0ce254664c81
Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents:
2094
diff
changeset
|
1229 |
} else { |
0ce254664c81
Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents:
2094
diff
changeset
|
1230 |
EC_MASTER_DBG(master, 1, "No app_time received up to now.\n"); |
0ce254664c81
Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents:
2094
diff
changeset
|
1231 |
} |
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1232 |
} |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1233 |
|
2117
afb40fd6018e
Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents:
2113
diff
changeset
|
1234 |
// scanning and setting system times complete |
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1235 |
ec_master_request_op(master); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1236 |
ec_fsm_master_restart(fsm); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1237 |
} |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1238 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1239 |
/*****************************************************************************/ |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1240 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1241 |
/** Configure 32 bit time offset. |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1242 |
* |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1243 |
* \return New offset. |
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1244 |
*/ |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1245 |
u64 ec_fsm_master_dc_offset32( |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1246 |
ec_fsm_master_t *fsm, /**< Master state machine. */ |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1247 |
u64 system_time, /**< System time register. */ |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1248 |
u64 old_offset, /**< Time offset register. */ |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1249 |
unsigned long jiffies_since_read /**< Jiffies for correction. */ |
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1250 |
) |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1251 |
{ |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1252 |
ec_slave_t *slave = fsm->slave; |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1253 |
u32 correction, system_time32, old_offset32, new_offset; |
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1254 |
s32 time_diff; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1255 |
|
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1256 |
system_time32 = (u32) system_time; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1257 |
old_offset32 = (u32) old_offset; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1258 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1259 |
// correct read system time by elapsed time since read operation |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1260 |
correction = jiffies_since_read * 1000 / HZ * 1000000; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1261 |
system_time32 += correction; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1262 |
time_diff = (u32) slave->master->app_time - system_time32; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1263 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1264 |
EC_SLAVE_DBG(slave, 1, "DC 32 bit system time offset calculation:" |
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1265 |
" system_time=%u (corrected with %u)," |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1266 |
" app_time=%llu, diff=%i\n", |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1267 |
system_time32, correction, |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1268 |
slave->master->app_time, time_diff); |
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1269 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1270 |
if (EC_ABS(time_diff) > EC_SYSTEM_TIME_TOLERANCE_NS) { |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1271 |
new_offset = time_diff + old_offset32; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1272 |
EC_SLAVE_DBG(slave, 1, "Setting time offset to %u (was %u)\n", |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1273 |
new_offset, old_offset32); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1274 |
return (u64) new_offset; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1275 |
} else { |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1276 |
EC_SLAVE_DBG(slave, 1, "Not touching time offset.\n"); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1277 |
return old_offset; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1278 |
} |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1279 |
} |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1280 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1281 |
/*****************************************************************************/ |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1282 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1283 |
/** Configure 64 bit time offset. |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1284 |
* |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1285 |
* \return New offset. |
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1286 |
*/ |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1287 |
u64 ec_fsm_master_dc_offset64( |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1288 |
ec_fsm_master_t *fsm, /**< Master state machine. */ |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1289 |
u64 system_time, /**< System time register. */ |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1290 |
u64 old_offset, /**< Time offset register. */ |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1291 |
unsigned long jiffies_since_read /**< Jiffies for correction. */ |
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1292 |
) |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1293 |
{ |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1294 |
ec_slave_t *slave = fsm->slave; |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1295 |
u64 new_offset, correction; |
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1296 |
s64 time_diff; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1297 |
|
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1298 |
// correct read system time by elapsed time since read operation |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1299 |
correction = (u64) (jiffies_since_read * 1000 / HZ) * 1000000; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1300 |
system_time += correction; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1301 |
time_diff = fsm->slave->master->app_time - system_time; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1302 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1303 |
EC_SLAVE_DBG(slave, 1, "DC 64 bit system time offset calculation:" |
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1304 |
" system_time=%llu (corrected with %llu)," |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1305 |
" app_time=%llu, diff=%lli\n", |
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1306 |
system_time, correction, |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1307 |
slave->master->app_time, time_diff); |
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1308 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1309 |
if (EC_ABS(time_diff) > EC_SYSTEM_TIME_TOLERANCE_NS) { |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1310 |
new_offset = time_diff + old_offset; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1311 |
EC_SLAVE_DBG(slave, 1, "Setting time offset to %llu (was %llu)\n", |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1312 |
new_offset, old_offset); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1313 |
} else { |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1314 |
new_offset = old_offset; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1315 |
EC_SLAVE_DBG(slave, 1, "Not touching time offset.\n"); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1316 |
} |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1317 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1318 |
return new_offset; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1319 |
} |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1320 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1321 |
/*****************************************************************************/ |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1322 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1323 |
/** Master state: DC READ OFFSET. |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1324 |
*/ |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1325 |
void ec_fsm_master_state_dc_read_offset( |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1326 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1327 |
) |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1328 |
{ |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1329 |
ec_datagram_t *datagram = fsm->datagram; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1330 |
ec_slave_t *slave = fsm->slave; |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1331 |
u64 system_time, old_offset, new_offset; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1332 |
unsigned long jiffies_since_read; |
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1333 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1334 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1335 |
return; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1336 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1337 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1338 |
EC_SLAVE_ERR(slave, "Failed to receive DC times datagram: "); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1339 |
ec_datagram_print_state(datagram); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1340 |
fsm->slave++; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1341 |
ec_fsm_master_enter_write_system_times(fsm); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1342 |
return; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1343 |
} |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1344 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1345 |
if (datagram->working_counter != 1) { |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1346 |
EC_SLAVE_WARN(slave, "Failed to get DC times: "); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1347 |
ec_datagram_print_wc_error(datagram); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1348 |
fsm->slave++; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1349 |
ec_fsm_master_enter_write_system_times(fsm); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1350 |
return; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1351 |
} |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1352 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1353 |
system_time = EC_READ_U64(datagram->data); // 0x0910 |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1354 |
old_offset = EC_READ_U64(datagram->data + 16); // 0x0920 |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1355 |
jiffies_since_read = jiffies - datagram->jiffies_sent; |
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1356 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1357 |
if (slave->base_dc_range == EC_DC_32) { |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1358 |
new_offset = ec_fsm_master_dc_offset32(fsm, |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1359 |
system_time, old_offset, jiffies_since_read); |
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1360 |
} else { |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1361 |
new_offset = ec_fsm_master_dc_offset64(fsm, |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1362 |
system_time, old_offset, jiffies_since_read); |
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1363 |
} |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1364 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1365 |
// set DC system time offset and transmission delay |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1366 |
ec_datagram_fpwr(datagram, slave->station_address, 0x0920, 12); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1367 |
EC_WRITE_U64(datagram->data, new_offset); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1368 |
EC_WRITE_U32(datagram->data + 8, slave->transmission_delay); |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1369 |
fsm->datagram->device_index = slave->device_index; |
1925
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1370 |
fsm->retries = EC_FSM_RETRIES; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1371 |
fsm->state = ec_fsm_master_state_dc_write_offset; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1372 |
} |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1373 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1374 |
/*****************************************************************************/ |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1375 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1376 |
/** Master state: DC WRITE OFFSET. |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1377 |
*/ |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1378 |
void ec_fsm_master_state_dc_write_offset( |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1379 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1380 |
) |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1381 |
{ |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1382 |
ec_datagram_t *datagram = fsm->datagram; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1383 |
ec_slave_t *slave = fsm->slave; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1384 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1385 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1386 |
return; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1387 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1388 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1389 |
EC_SLAVE_ERR(slave, |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1390 |
"Failed to receive DC system time offset datagram: "); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1391 |
ec_datagram_print_state(datagram); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1392 |
fsm->slave++; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1393 |
ec_fsm_master_enter_write_system_times(fsm); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1394 |
return; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1395 |
} |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1396 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1397 |
if (datagram->working_counter != 1) { |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1398 |
EC_SLAVE_ERR(slave, "Failed to set DC system time offset: "); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1399 |
ec_datagram_print_wc_error(datagram); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1400 |
fsm->slave++; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1401 |
ec_fsm_master_enter_write_system_times(fsm); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1402 |
return; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1403 |
} |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1404 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1405 |
fsm->slave++; |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1406 |
ec_fsm_master_enter_write_system_times(fsm); |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1407 |
} |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1408 |
|
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1409 |
/*****************************************************************************/ |
29161abef052
Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents:
1921
diff
changeset
|
1410 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1411 |
/** Master state: WRITE SII. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1412 |
*/ |
872 | 1413 |
void ec_fsm_master_state_write_sii( |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1414 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1415 |
) |
269 | 1416 |
{ |
601
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1417 |
ec_master_t *master = fsm->master; |
872 | 1418 |
ec_sii_write_request_t *request = fsm->sii_request; |
601
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1419 |
ec_slave_t *slave = request->slave; |
269 | 1420 |
|
435
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
434
diff
changeset
|
1421 |
if (ec_fsm_sii_exec(&fsm->fsm_sii)) return; |
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
1422 |
|
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
1423 |
if (!ec_fsm_sii_success(&fsm->fsm_sii)) { |
1921 | 1424 |
EC_SLAVE_ERR(slave, "Failed to write SII data.\n"); |
1209 | 1425 |
request->state = EC_INT_REQUEST_FAILURE; |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1426 |
wake_up_all(&master->request_queue); |
1031
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
1427 |
ec_fsm_master_restart(fsm); |
872 | 1428 |
return; |
1429 |
} |
|
1430 |
||
1431 |
fsm->sii_index++; |
|
979
405cc2d033e0
Renamed some fields in ec_sii_request_t to word addressing.
Florian Pose <fp@igh-essen.com>
parents:
969
diff
changeset
|
1432 |
if (fsm->sii_index < request->nwords) { |
601
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1433 |
ec_fsm_sii_write(&fsm->fsm_sii, slave, |
979
405cc2d033e0
Renamed some fields in ec_sii_request_t to word addressing.
Florian Pose <fp@igh-essen.com>
parents:
969
diff
changeset
|
1434 |
request->offset + fsm->sii_index, |
405cc2d033e0
Renamed some fields in ec_sii_request_t to word addressing.
Florian Pose <fp@igh-essen.com>
parents:
969
diff
changeset
|
1435 |
request->words + fsm->sii_index, |
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
1436 |
EC_FSM_SII_USE_CONFIGURED_ADDRESS); |
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
1437 |
ec_fsm_sii_exec(&fsm->fsm_sii); // execute immediately |
269 | 1438 |
return; |
1439 |
} |
|
1440 |
||
872 | 1441 |
// finished writing SII |
1921 | 1442 |
EC_SLAVE_DBG(slave, 1, "Finished writing %zu words of SII data.\n", |
1443 |
request->nwords); |
|
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1064
diff
changeset
|
1444 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1064
diff
changeset
|
1445 |
if (request->offset <= 4 && request->offset + request->nwords > 4) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1064
diff
changeset
|
1446 |
// alias was written |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1064
diff
changeset
|
1447 |
slave->sii.alias = EC_READ_U16(request->words + 4); |
1579
326d47aa986c
applied komax patch to version r1822
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1507
diff
changeset
|
1448 |
// TODO: read alias from register 0x0012 |
1909
ea3eb4c74c1b
Introduced effective_alias variable to separate reg12 alias from SII alias.
Florian Pose <fp@igh-essen.com>
parents:
1892
diff
changeset
|
1449 |
slave->effective_alias = slave->sii.alias; |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1064
diff
changeset
|
1450 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1064
diff
changeset
|
1451 |
// TODO: Evaluate other SII contents! |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
1452 |
|
1209 | 1453 |
request->state = EC_INT_REQUEST_SUCCESS; |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1454 |
wake_up_all(&master->request_queue); |
872 | 1455 |
|
1456 |
// check for another SII write request |
|
1457 |
if (ec_fsm_master_action_process_sii(fsm)) |
|
601
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1458 |
return; // processing another request |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
1459 |
|
1031
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
1460 |
ec_fsm_master_restart(fsm); |
419
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1461 |
} |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1462 |
|
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1463 |
/*****************************************************************************/ |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1464 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1465 |
/** Master state: SDO DICTIONARY. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1466 |
*/ |
905
6d74ebc603ee
Renamed state sdodict to sdo_dictionary.
Florian Pose <fp@igh-essen.com>
parents:
904
diff
changeset
|
1467 |
void ec_fsm_master_state_sdo_dictionary( |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1468 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
905
6d74ebc603ee
Renamed state sdodict to sdo_dictionary.
Florian Pose <fp@igh-essen.com>
parents:
904
diff
changeset
|
1469 |
) |
419
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1470 |
{ |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1471 |
ec_slave_t *slave = fsm->slave; |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1472 |
ec_master_t *master = fsm->master; |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1473 |
|
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1474 |
if (ec_fsm_coe_exec(&fsm->fsm_coe, fsm->datagram)) { |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1475 |
return; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1476 |
} |
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
1477 |
|
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
1478 |
if (!ec_fsm_coe_success(&fsm->fsm_coe)) { |
1031
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
1479 |
ec_fsm_master_restart(fsm); |
419
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1480 |
return; |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1481 |
} |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1482 |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1483 |
// SDO dictionary fetching finished |
419
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1484 |
|
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1485 |
if (master->debug_level) { |
423
862ff892cf18
Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents:
422
diff
changeset
|
1486 |
unsigned int sdo_count, entry_count; |
862ff892cf18
Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents:
422
diff
changeset
|
1487 |
ec_slave_sdo_dict_info(slave, &sdo_count, &entry_count); |
1921 | 1488 |
EC_SLAVE_DBG(slave, 1, "Fetched %u SDOs and %u entries.\n", |
1489 |
sdo_count, entry_count); |
|
419
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1490 |
} |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1491 |
|
1186
ff481f097c97
Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents:
1177
diff
changeset
|
1492 |
// attach pdo names from dictionary |
ff481f097c97
Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents:
1177
diff
changeset
|
1493 |
ec_slave_attach_pdo_names(slave); |
ff481f097c97
Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents:
1177
diff
changeset
|
1494 |
|
1031
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
1495 |
ec_fsm_master_restart(fsm); |
269 | 1496 |
} |
1497 |
||
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
1498 |
/*****************************************************************************/ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
1499 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1500 |
/** Master state: SDO REQUEST. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1501 |
*/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1502 |
void ec_fsm_master_state_sdo_request( |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1503 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
1504 |
) |
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
1505 |
{ |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
1506 |
ec_sdo_request_t *request = fsm->sdo_request; |
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
1507 |
|
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1508 |
if (!request) { |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1509 |
// configuration was cleared in the meantime |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1510 |
ec_fsm_master_restart(fsm); |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1511 |
return; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1512 |
} |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1513 |
|
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1514 |
if (ec_fsm_coe_exec(&fsm->fsm_coe, fsm->datagram)) { |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1515 |
return; |
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1516 |
} |
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
1517 |
|
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
1518 |
if (!ec_fsm_coe_success(&fsm->fsm_coe)) { |
1921 | 1519 |
EC_SLAVE_DBG(fsm->slave, 1, |
1520 |
"Failed to process internal SDO request.\n"); |
|
1209 | 1521 |
request->state = EC_INT_REQUEST_FAILURE; |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1522 |
wake_up_all(&fsm->master->request_queue); |
1031
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
1523 |
ec_fsm_master_restart(fsm); |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
1524 |
return; |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
1525 |
} |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
1526 |
|
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
1527 |
// SDO request finished |
1209 | 1528 |
request->state = EC_INT_REQUEST_SUCCESS; |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1529 |
wake_up_all(&fsm->master->request_queue); |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
1530 |
|
1921 | 1531 |
EC_SLAVE_DBG(fsm->slave, 1, "Finished internal SDO request.\n"); |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
1532 |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1533 |
// check for another SDO request |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1534 |
if (ec_fsm_master_action_process_sdo(fsm)) { |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
1535 |
return; // processing another request |
2589
2b9c78543663
Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents:
2414
diff
changeset
|
1536 |
} |
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
1537 |
|
1031
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
1538 |
ec_fsm_master_restart(fsm); |
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
1539 |
} |
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
1540 |
|
000593b576dd
Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents:
1029
diff
changeset
|
1541 |
/*****************************************************************************/ |