author | Florian Pose <fp@igh-essen.com> |
Mon, 09 Jun 2008 10:27:56 +0000 | |
changeset 971 | d169890332fe |
parent 969 | e259df107c92 |
child 979 | 405cc2d033e0 |
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 |
* |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
3 |
* $Id$ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
4 |
* |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
5 |
* Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH |
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 |
* |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
9 |
* The IgH EtherCAT Master is free software; you can redistribute it |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
10 |
* and/or modify it under the terms of the GNU General Public License |
246
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
238
diff
changeset
|
11 |
* as published by the Free Software Foundation; either version 2 of the |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
238
diff
changeset
|
12 |
* License, or (at your option) any later version. |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
13 |
* |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
14 |
* The IgH EtherCAT Master is distributed in the hope that it will be |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
15 |
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
17 |
* GNU General Public License for more details. |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
18 |
* |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
19 |
* You should have received a copy of the GNU General Public License |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
20 |
* along with the IgH EtherCAT Master; if not, write to the Free Software |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
21 |
* 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
|
22 |
* |
246
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
238
diff
changeset
|
23 |
* The right to use EtherCAT Technology is granted and comes free of |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
238
diff
changeset
|
24 |
* charge under condition of compatibility of product made by |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
238
diff
changeset
|
25 |
* Licensee. People intending to distribute/sell products based on the |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
238
diff
changeset
|
26 |
* code, have to sign an agreement to guarantee that products using |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
238
diff
changeset
|
27 |
* software based on IgH EtherCAT master stay compatible with the actual |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
238
diff
changeset
|
28 |
* EtherCAT specification (which are released themselves as an open |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
238
diff
changeset
|
29 |
* standard) as the (only) precondition to have the right to use EtherCAT |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
238
diff
changeset
|
30 |
* Technology, IP and trade marks. |
0bf7c769de06
Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents:
238
diff
changeset
|
31 |
* |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
32 |
*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
33 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
34 |
/** \file |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
35 |
* EtherCAT master state machine. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
36 |
*/ |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
37 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
38 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
39 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
40 |
#include "globals.h" |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
41 |
#include "master.h" |
329
d004349777fc
SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
42 |
#include "mailbox.h" |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
43 |
#include "slave_config.h" |
715
f12ff7c08623
Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
44 |
#ifdef EC_EOE |
661
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
45 |
#include "ethernet.h" |
715
f12ff7c08623
Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
46 |
#endif |
849
4b712ec8929d
Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
47 |
|
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
|
48 |
#include "fsm_master.h" |
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
|
49 |
|
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
|
50 |
/*****************************************************************************/ |
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
|
51 |
|
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
|
52 |
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
|
53 |
void ec_fsm_master_state_broadcast(ec_fsm_master_t *); |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
54 |
void ec_fsm_master_state_read_state(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
|
55 |
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
|
56 |
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
|
57 |
void ec_fsm_master_state_clear_addresses(ec_fsm_master_t *); |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
58 |
void ec_fsm_master_state_scan_slave(ec_fsm_master_t *); |
872 | 59 |
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
|
60 |
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
|
61 |
void ec_fsm_master_state_sdo_request(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
|
62 |
void ec_fsm_master_state_end(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_error(ec_fsm_master_t *); |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
64 |
|
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
65 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
66 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
67 |
/** Constructor. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
68 |
*/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
69 |
void ec_fsm_master_init( |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
70 |
ec_fsm_master_t *fsm, /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
71 |
ec_master_t *master, /**< EtherCAT master. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
72 |
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
|
73 |
) |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
74 |
{ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
75 |
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
|
76 |
fsm->datagram = datagram; |
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
|
77 |
fsm->state = ec_fsm_master_state_start; |
650
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
78 |
fsm->idle = 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
|
79 |
fsm->slaves_responding = 0; |
553
a4e0267825e3
Introduced topology_change_pending to delay bus scanning until IDLE mode
Florian Pose <fp@igh-essen.com>
parents:
538
diff
changeset
|
80 |
fsm->topology_change_pending = 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
|
81 |
fsm->slave_states = EC_SLAVE_STATE_UNKNOWN; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
82 |
|
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
83 |
// init sub-state-machines |
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
84 |
ec_fsm_slave_config_init(&fsm->fsm_slave_config, fsm->datagram); |
831
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
85 |
ec_fsm_slave_scan_init(&fsm->fsm_slave_scan, fsm->datagram, |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
86 |
&fsm->fsm_slave_config, &fsm->fsm_coe_map); |
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 |
ec_fsm_sii_init(&fsm->fsm_sii, fsm->datagram); |
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
|
88 |
ec_fsm_change_init(&fsm->fsm_change, fsm->datagram); |
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
|
89 |
ec_fsm_coe_init(&fsm->fsm_coe, fsm->datagram); |
741
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
90 |
ec_fsm_coe_map_init(&fsm->fsm_coe_map, &fsm->fsm_coe); |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
91 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
92 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
93 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
94 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
95 |
/** Destructor. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
96 |
*/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
97 |
void ec_fsm_master_clear( |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
98 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
99 |
) |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
100 |
{ |
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
101 |
// clear sub-state machines |
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
102 |
ec_fsm_slave_config_clear(&fsm->fsm_slave_config); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
103 |
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
|
104 |
ec_fsm_sii_clear(&fsm->fsm_sii); |
434
0180d8277311
Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents:
433
diff
changeset
|
105 |
ec_fsm_change_clear(&fsm->fsm_change); |
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
106 |
ec_fsm_coe_clear(&fsm->fsm_coe); |
741
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
107 |
ec_fsm_coe_map_clear(&fsm->fsm_coe_map); |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
108 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
109 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
110 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
111 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
112 |
/** Executes the current state of the state machine. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
113 |
* |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
114 |
* 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
|
115 |
* of the state machine is delayed to the next cycle. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
116 |
* |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
117 |
* \return false, if state machine has terminated |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
118 |
*/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
119 |
int ec_fsm_master_exec( |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
120 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
121 |
) |
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
|
122 |
{ |
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
|
123 |
if (fsm->datagram->state == EC_DATAGRAM_SENT |
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
|
124 |
|| 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
|
125 |
// datagram was not sent or received yet. |
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
|
126 |
return ec_fsm_master_running(fsm); |
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
|
127 |
} |
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
|
128 |
|
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
|
129 |
fsm->state(fsm); |
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
|
130 |
return ec_fsm_master_running(fsm); |
456
dea14706efc2
Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents:
454
diff
changeset
|
131 |
} |
dea14706efc2
Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents:
454
diff
changeset
|
132 |
|
dea14706efc2
Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents:
454
diff
changeset
|
133 |
/*****************************************************************************/ |
dea14706efc2
Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents:
454
diff
changeset
|
134 |
|
dea14706efc2
Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents:
454
diff
changeset
|
135 |
/** |
650
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
136 |
* \return false, if state machine has terminated |
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
137 |
*/ |
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
138 |
int ec_fsm_master_running( |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
139 |
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
|
140 |
) |
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
|
141 |
{ |
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
|
142 |
return fsm->state != ec_fsm_master_state_end |
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
|
143 |
&& fsm->state != ec_fsm_master_state_error; |
446 | 144 |
} |
145 |
||
650
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
146 |
/*****************************************************************************/ |
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
147 |
|
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
148 |
/** |
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
149 |
* \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
|
150 |
*/ |
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
151 |
int ec_fsm_master_idle( |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
152 |
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
|
153 |
) |
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
154 |
{ |
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
155 |
return fsm->idle; |
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
156 |
} |
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
157 |
|
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
158 |
/****************************************************************************** |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
159 |
* Master state machine |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
160 |
*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
161 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
162 |
/** Master state: START. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
163 |
* |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
164 |
* Starts with getting slave count and slave states. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
165 |
*/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
166 |
void ec_fsm_master_state_start( |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
167 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
168 |
) |
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
|
169 |
{ |
650
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
170 |
fsm->idle = 1; |
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
|
171 |
ec_datagram_brd(fsm->datagram, 0x0130, 2); |
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
|
172 |
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
|
173 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
174 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
175 |
/*****************************************************************************/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
176 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
177 |
/** Master state: BROADCAST. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
178 |
* |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
179 |
* Processes the broadcast read slave count and slaves states. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
180 |
*/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
181 |
void ec_fsm_master_state_broadcast( |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
182 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
183 |
) |
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
|
184 |
{ |
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
|
185 |
ec_datagram_t *datagram = fsm->datagram; |
553
a4e0267825e3
Introduced topology_change_pending to delay bus scanning until IDLE mode
Florian Pose <fp@igh-essen.com>
parents:
538
diff
changeset
|
186 |
unsigned int i; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
187 |
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
|
188 |
ec_master_t *master = fsm->master; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
189 |
|
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
190 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT) |
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
191 |
return; // always retry |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
192 |
|
553
a4e0267825e3
Introduced topology_change_pending to delay bus scanning until IDLE mode
Florian Pose <fp@igh-essen.com>
parents:
538
diff
changeset
|
193 |
// bus topology change? |
a4e0267825e3
Introduced topology_change_pending to delay bus scanning until IDLE mode
Florian Pose <fp@igh-essen.com>
parents:
538
diff
changeset
|
194 |
if (datagram->working_counter != fsm->slaves_responding) { |
a4e0267825e3
Introduced topology_change_pending to delay bus scanning until IDLE mode
Florian Pose <fp@igh-essen.com>
parents:
538
diff
changeset
|
195 |
fsm->topology_change_pending = 1; |
a4e0267825e3
Introduced topology_change_pending to delay bus scanning until IDLE mode
Florian Pose <fp@igh-essen.com>
parents:
538
diff
changeset
|
196 |
fsm->slaves_responding = datagram->working_counter; |
906 | 197 |
EC_INFO("%u slave(s) responding.\n", fsm->slaves_responding); |
198 |
} |
|
199 |
||
200 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { // link is down |
|
201 |
fsm->state = ec_fsm_master_state_error; |
|
202 |
return; |
|
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
203 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
204 |
|
553
a4e0267825e3
Introduced topology_change_pending to delay bus scanning until IDLE mode
Florian Pose <fp@igh-essen.com>
parents:
538
diff
changeset
|
205 |
// slave states changed? |
a4e0267825e3
Introduced topology_change_pending to delay bus scanning until IDLE mode
Florian Pose <fp@igh-essen.com>
parents:
538
diff
changeset
|
206 |
if (EC_READ_U8(datagram->data) != fsm->slave_states) { |
403
7bb931deccd9
Added EC_SLAVE_STATE_ACK_ERR to ec_state_string(); added EC_STATE_STRING_SIZE
Florian Pose <fp@igh-essen.com>
parents:
402
diff
changeset
|
207 |
char states[EC_STATE_STRING_SIZE]; |
553
a4e0267825e3
Introduced topology_change_pending to delay bus scanning until IDLE mode
Florian Pose <fp@igh-essen.com>
parents:
538
diff
changeset
|
208 |
fsm->slave_states = EC_READ_U8(datagram->data); |
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
|
209 |
ec_state_string(fsm->slave_states, states); |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
210 |
EC_INFO("Slave states: %s.\n", states); |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
211 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
212 |
|
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
213 |
if (fsm->topology_change_pending) { |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
214 |
down(&master->scan_sem); |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
215 |
if (!master->allow_scan) { |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
216 |
up(&master->scan_sem); |
900
f8b5c6d21705
Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents:
880
diff
changeset
|
217 |
} else { |
f8b5c6d21705
Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents:
880
diff
changeset
|
218 |
master->scan_busy = 1; |
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
219 |
up(&master->scan_sem); |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
220 |
|
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
221 |
// topology change when scan is allowed: |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
222 |
// clear all slaves and scan the bus |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
223 |
fsm->topology_change_pending = 0; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
224 |
fsm->idle = 0; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
225 |
fsm->scan_jiffies = jiffies; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
226 |
|
715
f12ff7c08623
Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
227 |
#ifdef EC_EOE |
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
228 |
ec_master_eoe_stop(master); |
661
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
229 |
ec_master_clear_eoe_handlers(master); |
715
f12ff7c08623
Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
230 |
#endif |
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
231 |
ec_master_destroy_slaves(master); |
930 | 232 |
master->configs_attached = 0; |
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
233 |
|
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
234 |
master->slave_count = datagram->working_counter; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
235 |
|
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
236 |
if (!master->slave_count) { |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
237 |
// 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
|
238 |
master->scan_busy = 0; |
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
239 |
wake_up_interruptible(&master->scan_queue); |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
240 |
fsm->state = ec_fsm_master_state_end; |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
241 |
return; |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
242 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
243 |
|
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
244 |
// init slaves |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
245 |
for (i = 0; i < master->slave_count; i++) { |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
246 |
if (!(slave = (ec_slave_t *) kmalloc(sizeof(ec_slave_t), |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
247 |
GFP_ATOMIC))) { |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
248 |
EC_ERR("Failed to allocate slave %i!\n", i); |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
249 |
ec_master_destroy_slaves(master); |
900
f8b5c6d21705
Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents:
880
diff
changeset
|
250 |
master->scan_busy = 0; |
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
251 |
wake_up_interruptible(&master->scan_queue); |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
252 |
fsm->state = ec_fsm_master_state_error; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
253 |
return; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
254 |
} |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
255 |
|
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
256 |
if (ec_slave_init(slave, master, i, i + 1)) { |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
257 |
// freeing of "slave" already done |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
258 |
ec_master_destroy_slaves(master); |
900
f8b5c6d21705
Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents:
880
diff
changeset
|
259 |
master->scan_busy = 0; |
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
260 |
wake_up_interruptible(&master->scan_queue); |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
261 |
fsm->state = ec_fsm_master_state_error; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
262 |
return; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
263 |
} |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
264 |
|
908
386b908033be
Replaced self_configured flag with force_config flag.
Florian Pose <fp@igh-essen.com>
parents:
907
diff
changeset
|
265 |
// do not force reconfiguration in operation mode to avoid |
386b908033be
Replaced self_configured flag with force_config flag.
Florian Pose <fp@igh-essen.com>
parents:
907
diff
changeset
|
266 |
// unnecesssary process data interruptions |
386b908033be
Replaced self_configured flag with force_config flag.
Florian Pose <fp@igh-essen.com>
parents:
907
diff
changeset
|
267 |
if (master->mode != EC_MASTER_MODE_OPERATION) |
386b908033be
Replaced self_configured flag with force_config flag.
Florian Pose <fp@igh-essen.com>
parents:
907
diff
changeset
|
268 |
slave->force_config = 1; |
386b908033be
Replaced self_configured flag with force_config flag.
Florian Pose <fp@igh-essen.com>
parents:
907
diff
changeset
|
269 |
|
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
270 |
list_add_tail(&slave->list, &master->slaves); |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
271 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
272 |
|
904 | 273 |
// broadcast clear all station addresses |
717
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
274 |
ec_datagram_bwr(datagram, 0x0010, 2); |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
275 |
EC_WRITE_U16(datagram->data, 0x0000); |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
276 |
fsm->retries = EC_FSM_RETRIES; |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
277 |
fsm->state = ec_fsm_master_state_clear_addresses; |
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
278 |
return; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
279 |
} |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
280 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
281 |
|
853
726326d0aef4
Fixed bug if scanning is not allowed when link goes up.
Florian Pose <fp@igh-essen.com>
parents:
849
diff
changeset
|
282 |
if (list_empty(&master->slaves)) { |
726326d0aef4
Fixed bug if scanning is not allowed when link goes up.
Florian Pose <fp@igh-essen.com>
parents:
849
diff
changeset
|
283 |
fsm->state = ec_fsm_master_state_end; |
726326d0aef4
Fixed bug if scanning is not allowed when link goes up.
Florian Pose <fp@igh-essen.com>
parents:
849
diff
changeset
|
284 |
} else { |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
285 |
// fetch state from first slave |
853
726326d0aef4
Fixed bug if scanning is not allowed when link goes up.
Florian Pose <fp@igh-essen.com>
parents:
849
diff
changeset
|
286 |
fsm->slave = list_entry(master->slaves.next, ec_slave_t, list); |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
287 |
ec_datagram_fprd(fsm->datagram, fsm->slave->station_address, |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
288 |
0x0130, 2); |
853
726326d0aef4
Fixed bug if scanning is not allowed when link goes up.
Florian Pose <fp@igh-essen.com>
parents:
849
diff
changeset
|
289 |
fsm->retries = EC_FSM_RETRIES; |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
290 |
fsm->state = ec_fsm_master_state_read_state; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
291 |
} |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
292 |
} |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
293 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
294 |
/*****************************************************************************/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
295 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
296 |
/** Check for pending SII write requests and process one. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
297 |
* |
872 | 298 |
* \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
|
299 |
*/ |
872 | 300 |
int ec_fsm_master_action_process_sii( |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
301 |
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
|
302 |
) |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
303 |
{ |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
304 |
ec_master_t *master = fsm->master; |
872 | 305 |
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
|
306 |
|
604
74ceacf42710
Fixed possible race with next request pointer again.
Florian Pose <fp@igh-essen.com>
parents:
603
diff
changeset
|
307 |
// 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
|
308 |
while (1) { |
872 | 309 |
down(&master->sii_sem); |
310 |
if (list_empty(&master->sii_requests)) { |
|
311 |
up(&master->sii_sem); |
|
604
74ceacf42710
Fixed possible race with next request pointer again.
Florian Pose <fp@igh-essen.com>
parents:
603
diff
changeset
|
312 |
break; |
74ceacf42710
Fixed possible race with next request pointer again.
Florian Pose <fp@igh-essen.com>
parents:
603
diff
changeset
|
313 |
} |
74ceacf42710
Fixed possible race with next request pointer again.
Florian Pose <fp@igh-essen.com>
parents:
603
diff
changeset
|
314 |
// get first request |
872 | 315 |
request = list_entry(master->sii_requests.next, |
316 |
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
|
317 |
list_del_init(&request->list); // dequeue |
861
6e3de145421a
Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
318 |
request->state = EC_REQUEST_BUSY; |
872 | 319 |
up(&master->sii_sem); |
601
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
320 |
|
872 | 321 |
// found pending SII write operation. execute it! |
607
7b1daa325c5f
Implemented alias reading/writing via sysfs.
Florian Pose <fp@igh-essen.com>
parents:
605
diff
changeset
|
322 |
if (master->debug_level) |
906 | 323 |
EC_DBG("Writing SII data to slave %u...\n", |
324 |
request->slave->ring_position); |
|
872 | 325 |
fsm->sii_request = request; |
326 |
fsm->sii_index = 0; |
|
754
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
743
diff
changeset
|
327 |
ec_fsm_sii_write(&fsm->fsm_sii, request->slave, request->word_offset, |
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
328 |
request->data, EC_FSM_SII_USE_CONFIGURED_ADDRESS); |
872 | 329 |
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
|
330 |
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
|
331 |
return 1; |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
332 |
} |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
333 |
|
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
334 |
return 0; |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
335 |
} |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
336 |
|
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
337 |
/*****************************************************************************/ |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
338 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
339 |
/** Check for pending Sdo requests and process one. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
340 |
* |
814 | 341 |
* \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
|
342 |
*/ |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
343 |
int ec_fsm_master_action_process_sdo( |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
344 |
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
|
345 |
) |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
346 |
{ |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
347 |
ec_master_t *master = fsm->master; |
849
4b712ec8929d
Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
348 |
ec_master_sdo_request_t *request; |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
349 |
ec_sdo_request_t *req; |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
350 |
ec_slave_t *slave; |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
351 |
|
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
352 |
// search for internal requests to be processed |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
353 |
list_for_each_entry(slave, &master->slaves, list) { |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
354 |
if (!slave->config) |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
355 |
continue; |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
356 |
list_for_each_entry(req, &slave->config->sdo_requests, list) { |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
357 |
if (req->state == EC_REQUEST_QUEUED) { |
880 | 358 |
|
359 |
if (ec_sdo_request_timed_out(req)) { |
|
360 |
req->state = EC_REQUEST_FAILURE; |
|
361 |
if (master->debug_level) |
|
362 |
EC_DBG("Sdo request for slave %u timed out...\n", |
|
363 |
slave->ring_position); |
|
364 |
continue; |
|
365 |
} |
|
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
366 |
|
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
367 |
if (slave->current_state == EC_SLAVE_STATE_INIT || |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
368 |
slave->error_flag) { |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
369 |
req->state = EC_REQUEST_FAILURE; |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
370 |
continue; |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
371 |
} |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
372 |
|
880 | 373 |
req->state = EC_REQUEST_BUSY; |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
374 |
if (master->debug_level) |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
375 |
EC_DBG("Processing Sdo request for slave %u...\n", |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
376 |
slave->ring_position); |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
377 |
|
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
378 |
fsm->idle = 0; |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
379 |
fsm->sdo_request = req; |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
380 |
fsm->slave = slave; |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
381 |
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
|
382 |
ec_fsm_coe_transfer(&fsm->fsm_coe, slave, req); |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
383 |
ec_fsm_coe_exec(&fsm->fsm_coe); // execute immediately |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
384 |
return 1; |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
385 |
} |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
386 |
} |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
387 |
} |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
388 |
|
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
389 |
// search the first external request to be processed |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
390 |
while (1) { |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
391 |
down(&master->sdo_sem); |
849
4b712ec8929d
Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
392 |
if (list_empty(&master->slave_sdo_requests)) { |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
393 |
up(&master->sdo_sem); |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
394 |
break; |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
395 |
} |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
396 |
// get first request |
849
4b712ec8929d
Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
397 |
request = list_entry(master->slave_sdo_requests.next, |
4b712ec8929d
Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
398 |
ec_master_sdo_request_t, list); |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
399 |
list_del_init(&request->list); // dequeue |
861
6e3de145421a
Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
400 |
request->req.state = EC_REQUEST_BUSY; |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
401 |
up(&master->sdo_sem); |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
402 |
|
831
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
403 |
slave = request->slave; |
969
e259df107c92
process Sdo requests even with error_flag set.
Florian Pose <fp@igh-essen.com>
parents:
930
diff
changeset
|
404 |
if (slave->current_state == EC_SLAVE_STATE_INIT) { |
e259df107c92
process Sdo requests even with error_flag set.
Florian Pose <fp@igh-essen.com>
parents:
930
diff
changeset
|
405 |
EC_ERR("Discarding Sdo request, slave %u is in INIT.\n", |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
406 |
slave->ring_position); |
849
4b712ec8929d
Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
407 |
request->req.state = EC_REQUEST_FAILURE; |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
408 |
wake_up(&master->sdo_queue); |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
409 |
continue; |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
410 |
} |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
411 |
|
849
4b712ec8929d
Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
412 |
// Found pending Sdo request. Execute it! |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
413 |
if (master->debug_level) |
906 | 414 |
EC_DBG("Processing Sdo request for slave %u...\n", |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
415 |
slave->ring_position); |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
416 |
|
849
4b712ec8929d
Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
417 |
// Start uploading Sdo |
650
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
418 |
fsm->idle = 0; |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
419 |
fsm->sdo_request = &request->req; |
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
420 |
fsm->slave = slave; |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
421 |
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
|
422 |
ec_fsm_coe_transfer(&fsm->fsm_coe, slave, &request->req); |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
423 |
ec_fsm_coe_exec(&fsm->fsm_coe); // execute immediately |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
424 |
return 1; |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
425 |
} |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
426 |
|
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
427 |
return 0; |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
428 |
} |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
429 |
|
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
430 |
/*****************************************************************************/ |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
431 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
432 |
/** Master action: IDLE. |
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 |
* Does secondary work. |
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 |
void ec_fsm_master_action_idle( |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
437 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
438 |
) |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
439 |
{ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
440 |
ec_master_t *master = fsm->master; |
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
441 |
ec_slave_t *slave; |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
442 |
|
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
443 |
// Check for pending Sdo requests |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
444 |
if (ec_fsm_master_action_process_sdo(fsm)) |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
445 |
return; |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
446 |
|
910
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
447 |
// check, if slaves have an Sdo dictionary to read out. |
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
448 |
list_for_each_entry(slave, &master->slaves, list) { |
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
449 |
if (!(slave->sii.mailbox_protocols & EC_MBOX_COE) |
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
|
450 |
|| 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
|
451 |
|| slave->current_state == EC_SLAVE_STATE_INIT |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
452 |
|| jiffies - slave->jiffies_preop < EC_WAIT_SDO_DICT * HZ |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
453 |
|| slave->error_flag) continue; |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
454 |
|
910
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
455 |
if (master->debug_level) { |
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
456 |
EC_DBG("Fetching Sdo dictionary from slave %u.\n", |
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
457 |
slave->ring_position); |
441
ffa13db95e10
SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents:
437
diff
changeset
|
458 |
} |
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
|
459 |
|
910
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
460 |
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
|
461 |
|
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
462 |
// start fetching Sdo dictionary |
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
463 |
fsm->idle = 0; |
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
464 |
fsm->slave = slave; |
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
465 |
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
|
466 |
ec_fsm_coe_dictionary(&fsm->fsm_coe, slave); |
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
467 |
ec_fsm_coe_exec(&fsm->fsm_coe); // execute immediately |
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
468 |
return; |
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
469 |
} |
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
470 |
|
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
471 |
// check for pending SII write operations. |
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
472 |
if (ec_fsm_master_action_process_sii(fsm)) |
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
473 |
return; // SII write request found |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
474 |
|
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
|
475 |
fsm->state = ec_fsm_master_state_end; |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
476 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
477 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
478 |
/*****************************************************************************/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
479 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
480 |
/** Master action: Get state of next slave. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
481 |
*/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
482 |
void ec_fsm_master_action_next_slave_state( |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
483 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
484 |
) |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
485 |
{ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
486 |
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
|
487 |
ec_slave_t *slave = fsm->slave; |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
488 |
|
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
489 |
// is there another slave to query? |
292
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
490 |
if (slave->list.next != &master->slaves) { |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
491 |
// fetch state from next slave |
650
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
492 |
fsm->idle = 1; |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
493 |
fsm->slave = list_entry(slave->list.next, ec_slave_t, list); |
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
494 |
ec_datagram_fprd(fsm->datagram, fsm->slave->station_address, |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
495 |
0x0130, 2); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
496 |
fsm->retries = EC_FSM_RETRIES; |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
497 |
fsm->state = ec_fsm_master_state_read_state; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
498 |
return; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
499 |
} |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
500 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
501 |
// all slaves processed |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
502 |
ec_fsm_master_action_idle(fsm); |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
503 |
} |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
504 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
505 |
/*****************************************************************************/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
506 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
507 |
/** Master action: Configure. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
508 |
*/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
509 |
void ec_fsm_master_action_configure( |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
510 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
511 |
) |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
512 |
{ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
513 |
ec_master_t *master = fsm->master; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
514 |
ec_slave_t *slave = fsm->slave; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
515 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
516 |
// Does the slave have to be configured? |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
517 |
if (!slave->error_flag |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
518 |
&& (slave->current_state != slave->requested_state |
908
386b908033be
Replaced self_configured flag with force_config flag.
Florian Pose <fp@igh-essen.com>
parents:
907
diff
changeset
|
519 |
|| slave->force_config)) { |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
520 |
// Start slave configuration, if it is allowed. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
521 |
down(&master->config_sem); |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
522 |
if (!master->allow_config) { |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
523 |
up(&master->config_sem); |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
524 |
} else { |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
525 |
master->config_busy = 1; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
526 |
up(&master->config_sem); |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
527 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
528 |
if (master->debug_level) { |
908
386b908033be
Replaced self_configured flag with force_config flag.
Florian Pose <fp@igh-essen.com>
parents:
907
diff
changeset
|
529 |
char old_state[EC_STATE_STRING_SIZE], |
386b908033be
Replaced self_configured flag with force_config flag.
Florian Pose <fp@igh-essen.com>
parents:
907
diff
changeset
|
530 |
new_state[EC_STATE_STRING_SIZE]; |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
531 |
ec_state_string(slave->current_state, old_state); |
908
386b908033be
Replaced self_configured flag with force_config flag.
Florian Pose <fp@igh-essen.com>
parents:
907
diff
changeset
|
532 |
ec_state_string(slave->requested_state, new_state); |
386b908033be
Replaced self_configured flag with force_config flag.
Florian Pose <fp@igh-essen.com>
parents:
907
diff
changeset
|
533 |
EC_DBG("Changing state of slave %u from %s to %s%s.\n", |
386b908033be
Replaced self_configured flag with force_config flag.
Florian Pose <fp@igh-essen.com>
parents:
907
diff
changeset
|
534 |
slave->ring_position, old_state, new_state, |
386b908033be
Replaced self_configured flag with force_config flag.
Florian Pose <fp@igh-essen.com>
parents:
907
diff
changeset
|
535 |
slave->force_config ? " (forced)" : ""); |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
536 |
} |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
537 |
|
908
386b908033be
Replaced self_configured flag with force_config flag.
Florian Pose <fp@igh-essen.com>
parents:
907
diff
changeset
|
538 |
// configuration will be done immediately; therefore reset the |
386b908033be
Replaced self_configured flag with force_config flag.
Florian Pose <fp@igh-essen.com>
parents:
907
diff
changeset
|
539 |
// force flag |
386b908033be
Replaced self_configured flag with force_config flag.
Florian Pose <fp@igh-essen.com>
parents:
907
diff
changeset
|
540 |
slave->force_config = 0; |
386b908033be
Replaced self_configured flag with force_config flag.
Florian Pose <fp@igh-essen.com>
parents:
907
diff
changeset
|
541 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
542 |
fsm->idle = 0; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
543 |
fsm->state = ec_fsm_master_state_configure_slave; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
544 |
ec_fsm_slave_config_start(&fsm->fsm_slave_config, slave); |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
545 |
fsm->state(fsm); // execute immediately |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
546 |
return; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
547 |
} |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
548 |
} |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
549 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
550 |
// slave has error flag set; process next one |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
551 |
ec_fsm_master_action_next_slave_state(fsm); |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
552 |
} |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
553 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
554 |
/*****************************************************************************/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
555 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
556 |
/** Master action: Acknowledge. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
557 |
*/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
558 |
void ec_fsm_master_action_acknowledge( |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
559 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
560 |
) |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
561 |
{ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
562 |
ec_slave_t *slave = fsm->slave; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
563 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
564 |
if (!slave->error_flag) { |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
565 |
// Check, if new slave state has to be acknowledged |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
566 |
if (slave->current_state & EC_SLAVE_STATE_ACK_ERR) { |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
567 |
fsm->idle = 0; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
568 |
fsm->state = ec_fsm_master_state_acknowledge; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
569 |
ec_fsm_change_ack(&fsm->fsm_change, slave); |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
570 |
fsm->state(fsm); // execute immediately |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
571 |
return; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
572 |
} |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
573 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
574 |
// No acknowlegde necessary; check for configuration |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
575 |
ec_fsm_master_action_configure(fsm); |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
576 |
return; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
577 |
} |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
578 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
579 |
// slave has error flag set; process next one |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
580 |
ec_fsm_master_action_next_slave_state(fsm); |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
581 |
} |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
582 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
583 |
/*****************************************************************************/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
584 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
585 |
/** Master state: READ STATE. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
586 |
* |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
587 |
* Fetches the AL state of a slave. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
588 |
*/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
589 |
void ec_fsm_master_state_read_state( |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
590 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
591 |
) |
260
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 |
ec_slave_t *slave = fsm->slave; |
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
|
594 |
ec_datagram_t *datagram = fsm->datagram; |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
595 |
|
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
596 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
597 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
598 |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
599 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
600 |
EC_ERR("Failed to receive AL state datagram for slave %u" |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
661
diff
changeset
|
601 |
" (datagram state %i)\n", |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
661
diff
changeset
|
602 |
slave->ring_position, datagram->state); |
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
|
603 |
fsm->state = ec_fsm_master_state_error; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
604 |
return; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
605 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
606 |
|
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
607 |
// did the slave not respond to its station address? |
906 | 608 |
if (datagram->working_counter != 1) { |
609 |
if (!slave->error_flag) { |
|
610 |
slave->error_flag = 1; |
|
611 |
if (fsm->master->debug_level) |
|
612 |
EC_DBG("Slave %u did not respond to state query.\n", |
|
613 |
fsm->slave->ring_position); |
|
614 |
} |
|
615 |
fsm->topology_change_pending = 1; |
|
616 |
fsm->state = ec_fsm_master_state_error; |
|
617 |
return; |
|
618 |
} |
|
619 |
||
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
620 |
// A single slave responded |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
621 |
ec_slave_set_state(slave, EC_READ_U8(datagram->data)); |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
622 |
ec_fsm_master_action_acknowledge(fsm); |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
623 |
} |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
624 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
625 |
/*****************************************************************************/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
626 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
627 |
/** Master state: ACKNOWLEDGE. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
628 |
*/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
629 |
void ec_fsm_master_state_acknowledge( |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
630 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
631 |
) |
454
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
632 |
{ |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
633 |
ec_slave_t *slave = fsm->slave; |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
634 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
635 |
if (ec_fsm_change_exec(&fsm->fsm_change)) |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
636 |
return; |
454
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
637 |
|
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
638 |
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
|
639 |
fsm->slave->error_flag = 1; |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
640 |
EC_ERR("Failed to acknowledge state change on slave %u.\n", |
454
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
641 |
slave->ring_position); |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
642 |
} |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
643 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
644 |
ec_fsm_master_action_configure(fsm); |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
645 |
} |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
646 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
647 |
/*****************************************************************************/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
648 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
649 |
/** Master state: CLEAR ADDRESSES. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
650 |
*/ |
717
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
651 |
void ec_fsm_master_state_clear_addresses( |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
652 |
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
|
653 |
) |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
654 |
{ |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
655 |
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
|
656 |
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
|
657 |
|
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
658 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
659 |
return; |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
660 |
|
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
661 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
662 |
EC_ERR("Failed to receive address clearing datagram (state %i).\n", |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
663 |
datagram->state); |
900
f8b5c6d21705
Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents:
880
diff
changeset
|
664 |
master->scan_busy = 0; |
794
684dea874956
Allow bus configuration when link is down.
Florian Pose <fp@igh-essen.com>
parents:
792
diff
changeset
|
665 |
wake_up_interruptible(&master->scan_queue); |
717
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
666 |
fsm->state = ec_fsm_master_state_error; |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
667 |
return; |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
668 |
} |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
669 |
|
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
670 |
if (datagram->working_counter != master->slave_count) { |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
671 |
EC_WARN("Failed to clear all station addresses: Cleared %u of %u", |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
672 |
datagram->working_counter, master->slave_count); |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
673 |
} |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
674 |
|
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
675 |
EC_INFO("Scanning bus.\n"); |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
676 |
|
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
677 |
// begin scanning of slaves |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
678 |
fsm->slave = list_entry(master->slaves.next, ec_slave_t, list); |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
679 |
fsm->state = ec_fsm_master_state_scan_slave; |
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
680 |
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
|
681 |
ec_fsm_slave_scan_exec(&fsm->fsm_slave_scan); // execute immediately |
717
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
682 |
} |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
683 |
|
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
684 |
/*****************************************************************************/ |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
685 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
686 |
/** Master state: SCAN SLAVE. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
687 |
* |
652 | 688 |
* Executes the sub-statemachine for the scanning of a slave. |
689 |
*/ |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
690 |
void ec_fsm_master_state_scan_slave( |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
691 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
652 | 692 |
) |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
693 |
{ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
694 |
ec_master_t *master = fsm->master; |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
695 |
ec_slave_t *slave = fsm->slave; |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
696 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
697 |
if (ec_fsm_slave_scan_exec(&fsm->fsm_slave_scan)) |
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
|
698 |
return; |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
699 |
|
715
f12ff7c08623
Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
700 |
#ifdef EC_EOE |
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
701 |
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
|
702 |
// create EoE handler for this slave |
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
703 |
ec_eoe_t *eoe; |
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
704 |
if (!(eoe = kmalloc(sizeof(ec_eoe_t), GFP_KERNEL))) { |
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
705 |
EC_ERR("Failed to allocate EoE handler memory for slave %u!\n", |
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
706 |
slave->ring_position); |
900
f8b5c6d21705
Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents:
880
diff
changeset
|
707 |
} else if (ec_eoe_init(eoe, slave)) { |
661
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
708 |
EC_ERR("Failed to init EoE handler for slave %u!\n", |
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
709 |
slave->ring_position); |
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
710 |
kfree(eoe); |
900
f8b5c6d21705
Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents:
880
diff
changeset
|
711 |
} else { |
661
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
712 |
list_add_tail(&eoe->list, &master->eoe_handlers); |
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
713 |
} |
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
714 |
} |
715
f12ff7c08623
Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
715 |
#endif |
661
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
716 |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
717 |
// another slave to fetch? |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
718 |
if (slave->list.next != &master->slaves) { |
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
719 |
fsm->slave = list_entry(slave->list.next, ec_slave_t, list); |
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
720 |
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
|
721 |
ec_fsm_slave_scan_exec(&fsm->fsm_slave_scan); // execute immediately |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
722 |
return; |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
723 |
} |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
724 |
|
652 | 725 |
EC_INFO("Bus scanning completed in %u ms.\n", |
726 |
(u32) (jiffies - fsm->scan_jiffies) * 1000 / HZ); |
|
661
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
727 |
|
900
f8b5c6d21705
Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents:
880
diff
changeset
|
728 |
master->scan_busy = 0; |
f8b5c6d21705
Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents:
880
diff
changeset
|
729 |
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
|
730 |
|
792
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
758
diff
changeset
|
731 |
// Attach slave configurations |
3778920f61e4
Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents:
758
diff
changeset
|
732 |
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
|
733 |
|
716 | 734 |
#ifdef EC_EOE |
661
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
735 |
// check if EoE processing has to be started |
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
736 |
ec_master_eoe_start(master); |
715
f12ff7c08623
Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
737 |
#endif |
661
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
738 |
|
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
|
739 |
fsm->state = ec_fsm_master_state_end; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
740 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
741 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
742 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
743 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
744 |
/** Master state: CONFIGURE SLAVE. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
745 |
* |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
746 |
* Starts configuring a slave. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
747 |
*/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
748 |
void ec_fsm_master_state_configure_slave( |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
749 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
750 |
) |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
751 |
{ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
752 |
ec_master_t *master = fsm->master; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
753 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
754 |
if (ec_fsm_slave_config_exec(&fsm->fsm_slave_config)) |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
755 |
return; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
756 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
757 |
// configuration finished |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
758 |
master->config_busy = 0; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
759 |
wake_up_interruptible(&master->config_queue); |
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
815
diff
changeset
|
760 |
|
900
f8b5c6d21705
Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents:
880
diff
changeset
|
761 |
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
|
762 |
// 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
|
763 |
} |
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
764 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
765 |
fsm->idle = 1; |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
766 |
ec_fsm_master_action_next_slave_state(fsm); |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
767 |
} |
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 |
/*****************************************************************************/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
770 |
|
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
771 |
/** Master state: WRITE SII. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
772 |
*/ |
872 | 773 |
void ec_fsm_master_state_write_sii( |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
774 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
775 |
) |
269 | 776 |
{ |
601
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
777 |
ec_master_t *master = fsm->master; |
872 | 778 |
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
|
779 |
ec_slave_t *slave = request->slave; |
269 | 780 |
|
435
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
434
diff
changeset
|
781 |
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
|
782 |
|
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
783 |
if (!ec_fsm_sii_success(&fsm->fsm_sii)) { |
601
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
784 |
slave->error_flag = 1; |
872 | 785 |
EC_ERR("Failed to write SII data to slave %i.\n", |
607
7b1daa325c5f
Implemented alias reading/writing via sysfs.
Florian Pose <fp@igh-essen.com>
parents:
605
diff
changeset
|
786 |
slave->ring_position); |
649
a4d3fffdaed7
Renamed names of enum type ec_request_state_t.
Florian Pose <fp@igh-essen.com>
parents:
646
diff
changeset
|
787 |
request->state = EC_REQUEST_FAILURE; |
872 | 788 |
wake_up(&master->sii_queue); |
789 |
fsm->state = ec_fsm_master_state_error; |
|
790 |
return; |
|
791 |
} |
|
792 |
||
793 |
fsm->sii_index++; |
|
794 |
if (fsm->sii_index < request->word_size) { |
|
601
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
795 |
ec_fsm_sii_write(&fsm->fsm_sii, slave, |
872 | 796 |
request->word_offset + fsm->sii_index, |
797 |
request->data + fsm->sii_index * 2, |
|
815
002fe9ec778f
Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents:
814
diff
changeset
|
798 |
EC_FSM_SII_USE_CONFIGURED_ADDRESS); |
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
799 |
ec_fsm_sii_exec(&fsm->fsm_sii); // execute immediately |
269 | 800 |
return; |
801 |
} |
|
802 |
||
872 | 803 |
// finished writing SII |
607
7b1daa325c5f
Implemented alias reading/writing via sysfs.
Florian Pose <fp@igh-essen.com>
parents:
605
diff
changeset
|
804 |
if (master->debug_level) |
872 | 805 |
EC_DBG("Finished writing %u words of SII data to slave %u.\n", |
754
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
743
diff
changeset
|
806 |
request->word_size, slave->ring_position); |
861
6e3de145421a
Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
807 |
request->state = EC_REQUEST_SUCCESS; |
872 | 808 |
wake_up(&master->sii_queue); |
809 |
||
810 |
// TODO: Evaluate new SII contents! |
|
811 |
||
812 |
// check for another SII write request |
|
813 |
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
|
814 |
return; // processing another request |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
815 |
|
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
816 |
fsm->state = ec_fsm_master_state_end; |
419
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
817 |
} |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
818 |
|
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
819 |
/*****************************************************************************/ |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
820 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
821 |
/** Master state: SDO DICTIONARY. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
822 |
*/ |
905
6d74ebc603ee
Renamed state sdodict to sdo_dictionary.
Florian Pose <fp@igh-essen.com>
parents:
904
diff
changeset
|
823 |
void ec_fsm_master_state_sdo_dictionary( |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
824 |
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
|
825 |
) |
419
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
826 |
{ |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
827 |
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
|
828 |
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
|
829 |
|
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
830 |
if (ec_fsm_coe_exec(&fsm->fsm_coe)) return; |
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
831 |
|
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
832 |
if (!ec_fsm_coe_success(&fsm->fsm_coe)) { |
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
|
833 |
fsm->state = ec_fsm_master_state_error; |
419
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
834 |
return; |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
835 |
} |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
836 |
|
814 | 837 |
// 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
|
838 |
|
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
839 |
if (master->debug_level) { |
423
862ff892cf18
Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents:
422
diff
changeset
|
840 |
unsigned int sdo_count, entry_count; |
862ff892cf18
Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents:
422
diff
changeset
|
841 |
ec_slave_sdo_dict_info(slave, &sdo_count, &entry_count); |
910
9fd31755f576
Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents:
908
diff
changeset
|
842 |
EC_DBG("Fetched %u Sdos and %u entries from slave %u.\n", |
423
862ff892cf18
Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents:
422
diff
changeset
|
843 |
sdo_count, entry_count, slave->ring_position); |
419
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
844 |
} |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
845 |
|
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
846 |
fsm->state = ec_fsm_master_state_end; |
269 | 847 |
} |
848 |
||
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
849 |
/*****************************************************************************/ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
850 |
|
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
851 |
/** Master state: SDO REQUEST. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
852 |
*/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
853 |
void ec_fsm_master_state_sdo_request( |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
854 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
855 |
) |
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
856 |
{ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
857 |
ec_master_t *master = fsm->master; |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
858 |
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
|
859 |
|
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
860 |
if (ec_fsm_coe_exec(&fsm->fsm_coe)) return; |
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
861 |
|
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
862 |
if (!ec_fsm_coe_success(&fsm->fsm_coe)) { |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
863 |
EC_DBG("Failed to process Sdo request for slave %u.\n", |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
864 |
fsm->slave->ring_position); |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
865 |
request->state = EC_REQUEST_FAILURE; |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
866 |
wake_up(&master->sdo_queue); |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
867 |
fsm->state = ec_fsm_master_state_error; |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
868 |
return; |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
869 |
} |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
870 |
|
814 | 871 |
// Sdo request finished |
861
6e3de145421a
Introduced ec_sdo_request_state_t, making ec_request_t private again;
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
872 |
request->state = EC_REQUEST_SUCCESS; |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
873 |
wake_up(&master->sdo_queue); |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
874 |
|
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
875 |
if (master->debug_level) |
858
69122084d066
Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents:
853
diff
changeset
|
876 |
EC_DBG("Finished Sdo request for slave %u.\n", |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
877 |
fsm->slave->ring_position); |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
878 |
|
814 | 879 |
// check for another Sdo request |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
880 |
if (ec_fsm_master_action_process_sdo(fsm)) |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
881 |
return; // processing another request |
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
882 |
|
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
883 |
fsm->state = ec_fsm_master_state_end; |
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
884 |
} |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
885 |
|
446 | 886 |
/*****************************************************************************/ |
887 |
||
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
888 |
/** State: ERROR. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
889 |
*/ |
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
|
890 |
void ec_fsm_master_state_error( |
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
891 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
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
|
892 |
) |
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
|
893 |
{ |
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
|
894 |
fsm->state = ec_fsm_master_state_start; |
446 | 895 |
} |
896 |
||
897 |
/*****************************************************************************/ |
|
898 |
||
907
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
899 |
/** State: END. |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
900 |
*/ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
901 |
void ec_fsm_master_state_end( |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
902 |
ec_fsm_master_t *fsm /**< Master state machine. */ |
570ae1c64465
Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents:
906
diff
changeset
|
903 |
) |
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
|
904 |
{ |
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
|
905 |
fsm->state = ec_fsm_master_state_start; |
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
|
906 |
} |
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
|
907 |
|
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
|
908 |
/*****************************************************************************/ |