author | Florian Pose <fp@igh-essen.com> |
Fri, 01 Feb 2008 20:26:13 +0000 | |
changeset 778 | 7fc85507f49a |
parent 758 | 8fa6f825eb7d |
child 792 | 3778920f61e4 |
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 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
34 |
/** |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
35 |
\file |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
36 |
EtherCAT finite state machines. |
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 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
41 |
#include "globals.h" |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
42 |
#include "master.h" |
329
d004349777fc
SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
43 |
#include "mailbox.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 |
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
|
47 |
#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
|
48 |
|
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 |
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
|
52 |
void ec_fsm_master_state_broadcast(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_read_states(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
|
54 |
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
|
55 |
void ec_fsm_master_state_validate_vendor(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_validate_product(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
|
57 |
void ec_fsm_master_state_rewrite_addresses(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
|
58 |
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
|
59 |
void ec_fsm_master_state_clear_addresses(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
|
60 |
void ec_fsm_master_state_scan_slaves(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
|
61 |
void ec_fsm_master_state_write_eeprom(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_sdodict(ec_fsm_master_t *); |
741
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
63 |
void ec_fsm_master_state_pdomap(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
|
64 |
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
|
65 |
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
|
66 |
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
|
67 |
|
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
68 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
69 |
|
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
70 |
/** |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
71 |
Constructor. |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
72 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
73 |
|
528
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
74 |
void ec_fsm_master_init(ec_fsm_master_t *fsm, /**< master state machine */ |
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
|
75 |
ec_master_t *master, /**< EtherCAT master */ |
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 |
ec_datagram_t *datagram /**< datagram object to use */ |
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 |
) |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
78 |
{ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
79 |
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
|
80 |
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
|
81 |
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
|
82 |
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
|
83 |
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
|
84 |
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
|
85 |
fsm->slave_states = EC_SLAVE_STATE_UNKNOWN; |
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
|
86 |
fsm->validate = 0; |
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
610
diff
changeset
|
87 |
fsm->tainted = 0; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
88 |
|
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
89 |
// init sub-state-machines |
528
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
90 |
ec_fsm_slave_init(&fsm->fsm_slave, 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
|
91 |
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
|
92 |
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
|
93 |
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
|
94 |
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
|
95 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
96 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
97 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
98 |
|
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
99 |
/** |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
100 |
Destructor. |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
101 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
102 |
|
528
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
103 |
void ec_fsm_master_clear(ec_fsm_master_t *fsm /**< master state machine */) |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
104 |
{ |
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
105 |
// clear sub-state machines |
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
|
106 |
ec_fsm_slave_clear(&fsm->fsm_slave); |
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
107 |
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
|
108 |
ec_fsm_change_clear(&fsm->fsm_change); |
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
109 |
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
|
110 |
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
|
111 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
112 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
113 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
114 |
|
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
115 |
/** |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
116 |
Executes the current state of the state machine. |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
117 |
If the state machine's datagram is not sent or received yet, the execution |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
118 |
of the state machine is delayed to the next cycle. |
435
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
434
diff
changeset
|
119 |
\return false, if state machine has terminated |
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
434
diff
changeset
|
120 |
*/ |
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
434
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 |
int ec_fsm_master_exec(ec_fsm_master_t *fsm /**< master state machine */) |
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 |
{ |
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 |
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
|
125 |
|| 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
|
126 |
// 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
|
127 |
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
|
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 |
|
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 |
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
|
131 |
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
|
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 |
|
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
|
136 |
/** |
650
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
137 |
* \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
|
138 |
*/ |
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
139 |
|
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
140 |
int ec_fsm_master_running( |
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
141 |
const ec_fsm_master_t *fsm /**< master state machine */ |
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
142 |
) |
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
|
143 |
{ |
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
|
144 |
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
|
145 |
&& fsm->state != ec_fsm_master_state_error; |
446 | 146 |
} |
147 |
||
650
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 |
|
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 |
* \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
|
152 |
*/ |
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 |
int ec_fsm_master_idle( |
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
155 |
const ec_fsm_master_t *fsm /**< master state machine */ |
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 |
{ |
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
158 |
return fsm->idle; |
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
159 |
} |
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
160 |
|
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
161 |
/****************************************************************************** |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
162 |
* master state machine |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
163 |
*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
164 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
165 |
/** |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
166 |
Master state: START. |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
167 |
Starts with getting slave count and slave states. |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
168 |
*/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
169 |
|
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
|
170 |
void ec_fsm_master_state_start(ec_fsm_master_t *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
|
171 |
{ |
650
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
172 |
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
|
173 |
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
|
174 |
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
|
175 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
176 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
177 |
/*****************************************************************************/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
178 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
179 |
/** |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
180 |
Master state: BROADCAST. |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
181 |
Processes the broadcast read slave count and slaves states. |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
182 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
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 |
void ec_fsm_master_state_broadcast(ec_fsm_master_t *fsm /**< master state machine */) |
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 |
{ |
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
|
186 |
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
|
187 |
unsigned int i; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
188 |
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
|
189 |
ec_master_t *master = fsm->master; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
190 |
|
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
191 |
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
|
192 |
return; // always retry |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
193 |
|
650
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
194 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { // link is down |
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
|
195 |
fsm->slaves_responding = 0; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
196 |
list_for_each_entry(slave, &master->slaves, list) { |
610
29489a43ecee
Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents:
607
diff
changeset
|
197 |
ec_slave_set_online_state(slave, EC_SLAVE_OFFLINE); |
446 | 198 |
} |
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
|
199 |
fsm->state = ec_fsm_master_state_error; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
200 |
return; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
201 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
202 |
|
553
a4e0267825e3
Introduced topology_change_pending to delay bus scanning until IDLE mode
Florian Pose <fp@igh-essen.com>
parents:
538
diff
changeset
|
203 |
// 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
|
204 |
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
|
205 |
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
|
206 |
fsm->slaves_responding = datagram->working_counter; |
a4e0267825e3
Introduced topology_change_pending to delay bus scanning until IDLE mode
Florian Pose <fp@igh-essen.com>
parents:
538
diff
changeset
|
207 |
|
262
636d43737371
Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents:
260
diff
changeset
|
208 |
EC_INFO("%i slave%s responding.\n", |
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 |
fsm->slaves_responding, |
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
|
210 |
fsm->slaves_responding == 1 ? "" : "s"); |
262
636d43737371
Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents:
260
diff
changeset
|
211 |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
212 |
if (master->mode == EC_MASTER_MODE_OPERATION) { |
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
|
213 |
if (fsm->slaves_responding == master->slave_count) { |
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
|
214 |
fsm->validate = 1; // start validation later |
262
636d43737371
Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents:
260
diff
changeset
|
215 |
} |
636d43737371
Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents:
260
diff
changeset
|
216 |
else { |
636d43737371
Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents:
260
diff
changeset
|
217 |
EC_WARN("Invalid slave count. Bus in tainted state.\n"); |
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
610
diff
changeset
|
218 |
fsm->tainted = 1; |
262
636d43737371
Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents:
260
diff
changeset
|
219 |
} |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
220 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
221 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
222 |
|
553
a4e0267825e3
Introduced topology_change_pending to delay bus scanning until IDLE mode
Florian Pose <fp@igh-essen.com>
parents:
538
diff
changeset
|
223 |
// 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
|
224 |
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
|
225 |
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
|
226 |
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
|
227 |
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
|
228 |
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
|
229 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
230 |
|
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
231 |
if (fsm->topology_change_pending) { |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
232 |
down(&master->scan_sem); |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
233 |
if (!master->allow_scan) { |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
234 |
up(&master->scan_sem); |
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 |
else { |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
237 |
master->scan_state = EC_REQUEST_IN_PROGRESS; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
238 |
up(&master->scan_sem); |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
239 |
|
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
240 |
// topology change when scan is allowed: |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
241 |
// 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
|
242 |
fsm->topology_change_pending = 0; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
243 |
fsm->tainted = 0; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
244 |
fsm->idle = 0; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
245 |
fsm->scan_jiffies = jiffies; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
246 |
|
715
f12ff7c08623
Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
247 |
#ifdef EC_EOE |
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
248 |
ec_master_eoe_stop(master); |
661
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
249 |
ec_master_clear_eoe_handlers(master); |
715
f12ff7c08623
Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
250 |
#endif |
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
251 |
ec_master_destroy_slaves(master); |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
252 |
|
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
253 |
master->slave_count = datagram->working_counter; |
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 |
if (!master->slave_count) { |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
256 |
// no slaves present -> finish state machine. |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
257 |
master->scan_state = EC_REQUEST_COMPLETE; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
258 |
wake_up_interruptible(&master->scan_queue); |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
259 |
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
|
260 |
return; |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
261 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
262 |
|
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
263 |
// init slaves |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
264 |
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
|
265 |
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
|
266 |
GFP_ATOMIC))) { |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
267 |
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
|
268 |
ec_master_destroy_slaves(master); |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
269 |
master->scan_state = EC_REQUEST_FAILURE; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
270 |
wake_up_interruptible(&master->scan_queue); |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
271 |
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
|
272 |
return; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
273 |
} |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
274 |
|
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
275 |
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
|
276 |
// freeing of "slave" already done |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
277 |
ec_master_destroy_slaves(master); |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
278 |
master->scan_state = EC_REQUEST_FAILURE; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
279 |
wake_up_interruptible(&master->scan_queue); |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
280 |
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
|
281 |
return; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
282 |
} |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
283 |
|
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
284 |
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
|
285 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
286 |
|
717
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
287 |
if (master->debug_level) |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
288 |
EC_DBG("Clearing station addresses...\n"); |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
289 |
|
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
290 |
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
|
291 |
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
|
292 |
fsm->retries = EC_FSM_RETRIES; |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
293 |
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
|
294 |
return; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
295 |
} |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
296 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
297 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
298 |
// fetch state from each slave |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
299 |
fsm->slave = list_entry(master->slaves.next, ec_slave_t, list); |
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
|
300 |
ec_datagram_nprd(fsm->datagram, fsm->slave->station_address, 0x0130, 2); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
301 |
fsm->retries = EC_FSM_RETRIES; |
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
|
302 |
fsm->state = ec_fsm_master_state_read_states; |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
303 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
304 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
305 |
/*****************************************************************************/ |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
306 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
307 |
/** |
601
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
308 |
* Check for pending EEPROM write requests and process one. |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
309 |
* \return non-zero, if an EEPROM write request is processed. |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
310 |
*/ |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
311 |
|
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
312 |
int ec_fsm_master_action_process_eeprom( |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
313 |
ec_fsm_master_t *fsm /**< master state machine */ |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
314 |
) |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
315 |
{ |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
316 |
ec_master_t *master = fsm->master; |
604
74ceacf42710
Fixed possible race with next request pointer again.
Florian Pose <fp@igh-essen.com>
parents:
603
diff
changeset
|
317 |
ec_eeprom_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
|
318 |
ec_slave_t *slave; |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
319 |
|
604
74ceacf42710
Fixed possible race with next request pointer again.
Florian Pose <fp@igh-essen.com>
parents:
603
diff
changeset
|
320 |
// 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
|
321 |
while (1) { |
74ceacf42710
Fixed possible race with next request pointer again.
Florian Pose <fp@igh-essen.com>
parents:
603
diff
changeset
|
322 |
down(&master->eeprom_sem); |
74ceacf42710
Fixed possible race with next request pointer again.
Florian Pose <fp@igh-essen.com>
parents:
603
diff
changeset
|
323 |
if (list_empty(&master->eeprom_requests)) { |
74ceacf42710
Fixed possible race with next request pointer again.
Florian Pose <fp@igh-essen.com>
parents:
603
diff
changeset
|
324 |
up(&master->eeprom_sem); |
74ceacf42710
Fixed possible race with next request pointer again.
Florian Pose <fp@igh-essen.com>
parents:
603
diff
changeset
|
325 |
break; |
74ceacf42710
Fixed possible race with next request pointer again.
Florian Pose <fp@igh-essen.com>
parents:
603
diff
changeset
|
326 |
} |
74ceacf42710
Fixed possible race with next request pointer again.
Florian Pose <fp@igh-essen.com>
parents:
603
diff
changeset
|
327 |
// get first request |
74ceacf42710
Fixed possible race with next request pointer again.
Florian Pose <fp@igh-essen.com>
parents:
603
diff
changeset
|
328 |
request = list_entry(master->eeprom_requests.next, |
74ceacf42710
Fixed possible race with next request pointer again.
Florian Pose <fp@igh-essen.com>
parents:
603
diff
changeset
|
329 |
ec_eeprom_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
|
330 |
list_del_init(&request->list); // dequeue |
649
a4d3fffdaed7
Renamed names of enum type ec_request_state_t.
Florian Pose <fp@igh-essen.com>
parents:
646
diff
changeset
|
331 |
request->state = EC_REQUEST_IN_PROGRESS; |
601
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
332 |
up(&master->eeprom_sem); |
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 |
slave = request->slave; |
729
3aed091b2663
Allow EEPROM writing when slave has error flag set.
Florian Pose <fp@igh-essen.com>
parents:
717
diff
changeset
|
335 |
if (slave->online_state == EC_SLAVE_OFFLINE) { |
3aed091b2663
Allow EEPROM writing when slave has error flag set.
Florian Pose <fp@igh-essen.com>
parents:
717
diff
changeset
|
336 |
EC_ERR("Discarding EEPROM data, slave %i offline.\n", |
601
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
337 |
slave->ring_position); |
649
a4d3fffdaed7
Renamed names of enum type ec_request_state_t.
Florian Pose <fp@igh-essen.com>
parents:
646
diff
changeset
|
338 |
request->state = EC_REQUEST_FAILURE; |
605
96a894895999
Fixed signal issue in EEPROM writing code.
Florian Pose <fp@igh-essen.com>
parents:
604
diff
changeset
|
339 |
wake_up(&master->eeprom_queue); |
601
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
340 |
continue; |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
341 |
} |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
342 |
|
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
343 |
// found pending EEPROM write operation. execute it! |
607
7b1daa325c5f
Implemented alias reading/writing via sysfs.
Florian Pose <fp@igh-essen.com>
parents:
605
diff
changeset
|
344 |
if (master->debug_level) |
7b1daa325c5f
Implemented alias reading/writing via sysfs.
Florian Pose <fp@igh-essen.com>
parents:
605
diff
changeset
|
345 |
EC_DBG("Writing EEPROM data to slave %i...\n", |
7b1daa325c5f
Implemented alias reading/writing via sysfs.
Florian Pose <fp@igh-essen.com>
parents:
605
diff
changeset
|
346 |
slave->ring_position); |
601
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
347 |
fsm->eeprom_request = request; |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
348 |
fsm->eeprom_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
|
349 |
ec_fsm_sii_write(&fsm->fsm_sii, request->slave, request->word_offset, |
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
743
diff
changeset
|
350 |
request->data, EC_FSM_SII_NODE); |
601
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
351 |
fsm->state = ec_fsm_master_state_write_eeprom; |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
352 |
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
|
353 |
return 1; |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
354 |
} |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
355 |
|
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
356 |
return 0; |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
357 |
} |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
358 |
|
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
359 |
/*****************************************************************************/ |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
360 |
|
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
361 |
/** |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
362 |
* Check for pending SDO requests and process one. |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
363 |
* \return non-zero, if an SDO request is processed. |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
364 |
*/ |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
365 |
|
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
366 |
int ec_fsm_master_action_process_sdo( |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
367 |
ec_fsm_master_t *fsm /**< master state machine */ |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
368 |
) |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
369 |
{ |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
370 |
ec_master_t *master = fsm->master; |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
371 |
ec_sdo_request_t *request; |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
372 |
ec_slave_t *slave; |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
373 |
|
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
374 |
// search the first request to be processed |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
375 |
while (1) { |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
376 |
down(&master->sdo_sem); |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
377 |
if (list_empty(&master->sdo_requests)) { |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
378 |
up(&master->sdo_sem); |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
379 |
break; |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
380 |
} |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
381 |
// get first request |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
382 |
request = |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
383 |
list_entry(master->sdo_requests.next, ec_sdo_request_t, list); |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
384 |
list_del_init(&request->list); // dequeue |
649
a4d3fffdaed7
Renamed names of enum type ec_request_state_t.
Florian Pose <fp@igh-essen.com>
parents:
646
diff
changeset
|
385 |
request->state = EC_REQUEST_IN_PROGRESS; |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
386 |
up(&master->sdo_sem); |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
387 |
|
739
4a02162a6301
Removed 'sdo' field from ec_sdo_request_t; Exported
Florian Pose <fp@igh-essen.com>
parents:
729
diff
changeset
|
388 |
slave = request->entry->sdo->slave; |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
389 |
if (slave->current_state == EC_SLAVE_STATE_INIT || |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
390 |
slave->online_state == EC_SLAVE_OFFLINE || |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
391 |
slave->error_flag) { |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
392 |
EC_ERR("Discarding SDO request, slave %i not ready.\n", |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
393 |
slave->ring_position); |
649
a4d3fffdaed7
Renamed names of enum type ec_request_state_t.
Florian Pose <fp@igh-essen.com>
parents:
646
diff
changeset
|
394 |
request->state = EC_REQUEST_FAILURE; |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
395 |
wake_up(&master->sdo_queue); |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
396 |
continue; |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
397 |
} |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
398 |
|
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
399 |
// found pending SDO request. execute it! |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
400 |
if (master->debug_level) |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
401 |
EC_DBG("Processing SDO request for slave %i...\n", |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
402 |
slave->ring_position); |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
403 |
|
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
404 |
// start uploading SDO |
650
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
405 |
fsm->idle = 0; |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
406 |
fsm->slave = slave; |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
407 |
fsm->sdo_request = request; |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
408 |
fsm->state = ec_fsm_master_state_sdo_request; |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
409 |
ec_fsm_coe_upload(&fsm->fsm_coe, slave, fsm->sdo_request); |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
410 |
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
|
411 |
return 1; |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
412 |
} |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
413 |
|
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
414 |
return 0; |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
415 |
} |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
416 |
|
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
417 |
/*****************************************************************************/ |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
418 |
|
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
419 |
/** |
758
8fa6f825eb7d
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
420 |
* Check for slaves that are not configured and configure them. |
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
421 |
*/ |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
422 |
|
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
423 |
int ec_fsm_master_action_configure( |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
424 |
ec_fsm_master_t *fsm /**< master state machine */ |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
425 |
) |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
426 |
{ |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
427 |
ec_slave_t *slave; |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
428 |
ec_master_t *master = fsm->master; |
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
|
429 |
char old_state[EC_STATE_STRING_SIZE], new_state[EC_STATE_STRING_SIZE]; |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
430 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
431 |
// check if any slaves are not in the state, they're supposed to be |
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
432 |
// FIXME do not check all slaves in every cycle... |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
433 |
list_for_each_entry(slave, &master->slaves, list) { |
421
2b3ce4f51bd6
Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents:
420
diff
changeset
|
434 |
if (slave->error_flag |
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
435 |
|| slave->online_state == EC_SLAVE_OFFLINE |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
436 |
|| slave->requested_state == EC_SLAVE_STATE_UNKNOWN |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
437 |
|| (slave->current_state == slave->requested_state |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
438 |
&& slave->self_configured)) continue; |
421
2b3ce4f51bd6
Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents:
420
diff
changeset
|
439 |
|
446 | 440 |
if (master->debug_level) { |
441 |
ec_state_string(slave->current_state, old_state); |
|
523
584a4f60b067
Re-added slave.configured flag as slave.self_configured.
Florian Pose <fp@igh-essen.com>
parents:
522
diff
changeset
|
442 |
if (slave->current_state != slave->requested_state) { |
584a4f60b067
Re-added slave.configured flag as slave.self_configured.
Florian Pose <fp@igh-essen.com>
parents:
522
diff
changeset
|
443 |
ec_state_string(slave->requested_state, new_state); |
584a4f60b067
Re-added slave.configured flag as slave.self_configured.
Florian Pose <fp@igh-essen.com>
parents:
522
diff
changeset
|
444 |
EC_DBG("Changing state of slave %i (%s -> %s).\n", |
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
445 |
slave->ring_position, old_state, new_state); |
523
584a4f60b067
Re-added slave.configured flag as slave.self_configured.
Florian Pose <fp@igh-essen.com>
parents:
522
diff
changeset
|
446 |
} |
584a4f60b067
Re-added slave.configured flag as slave.self_configured.
Florian Pose <fp@igh-essen.com>
parents:
522
diff
changeset
|
447 |
else if (!slave->self_configured) { |
584a4f60b067
Re-added slave.configured flag as slave.self_configured.
Florian Pose <fp@igh-essen.com>
parents:
522
diff
changeset
|
448 |
EC_DBG("Reconfiguring slave %i (%s).\n", |
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
449 |
slave->ring_position, old_state); |
523
584a4f60b067
Re-added slave.configured flag as slave.self_configured.
Florian Pose <fp@igh-essen.com>
parents:
522
diff
changeset
|
450 |
} |
421
2b3ce4f51bd6
Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents:
420
diff
changeset
|
451 |
} |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
452 |
|
650
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
453 |
fsm->idle = 0; |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
454 |
fsm->slave = slave; |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
455 |
fsm->state = ec_fsm_master_state_configure_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
|
456 |
ec_fsm_slave_start_conf(&fsm->fsm_slave, slave); |
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
|
457 |
ec_fsm_slave_exec(&fsm->fsm_slave); // execute immediately |
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
458 |
return 1; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
459 |
} |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
460 |
|
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
461 |
if (fsm->config_error) |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
462 |
master->config_state = EC_REQUEST_FAILURE; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
463 |
else |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
464 |
master->config_state = EC_REQUEST_COMPLETE; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
465 |
wake_up_interruptible(&master->config_queue); |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
466 |
return 0; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
467 |
} |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
468 |
|
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
469 |
/*****************************************************************************/ |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
470 |
|
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
471 |
/** |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
472 |
Master action: PROC_STATES. |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
473 |
Processes the slave states. |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
474 |
*/ |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
475 |
|
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
476 |
void ec_fsm_master_action_process_states(ec_fsm_master_t *fsm |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
477 |
/**< master state machine */ |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
478 |
) |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
479 |
{ |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
480 |
ec_master_t *master = fsm->master; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
481 |
ec_slave_t *slave; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
482 |
|
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
483 |
down(&master->config_sem); |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
484 |
if (!master->allow_config) { |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
485 |
up(&master->config_sem); |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
486 |
} |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
487 |
else { |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
488 |
master->config_state = EC_REQUEST_IN_PROGRESS; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
489 |
fsm->config_error = 0; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
490 |
up(&master->config_sem); |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
491 |
|
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
492 |
// check for pending slave configurations |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
493 |
if (ec_fsm_master_action_configure(fsm)) |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
494 |
return; |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
495 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
496 |
|
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
497 |
// Check for a pending SDO request |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
498 |
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
|
499 |
return; |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
500 |
|
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
|
501 |
if (master->mode == EC_MASTER_MODE_IDLE) { |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
502 |
|
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
503 |
// check, if slaves have an SDO dictionary to read out. |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
504 |
list_for_each_entry(slave, &master->slaves, list) { |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
505 |
if (!(slave->sii_mailbox_protocols & EC_MBOX_COE) |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
506 |
|| 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
|
507 |
|| 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
|
508 |
|| jiffies - slave->jiffies_preop < EC_WAIT_SDO_DICT * HZ |
610
29489a43ecee
Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents:
607
diff
changeset
|
509 |
|| slave->online_state == EC_SLAVE_OFFLINE |
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
|
510 |
|| 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
|
511 |
|
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
512 |
if (master->debug_level) { |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
513 |
EC_DBG("Fetching SDO dictionary from slave %i.\n", |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
514 |
slave->ring_position); |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
515 |
} |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
516 |
|
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
517 |
slave->sdo_dictionary_fetched = 1; |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
518 |
|
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
519 |
// start fetching SDO dictionary |
650
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
520 |
fsm->idle = 0; |
441
ffa13db95e10
SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents:
437
diff
changeset
|
521 |
fsm->slave = 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
|
522 |
fsm->state = ec_fsm_master_state_sdodict; |
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
|
523 |
ec_fsm_coe_dictionary(&fsm->fsm_coe, slave); |
441
ffa13db95e10
SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents:
437
diff
changeset
|
524 |
ec_fsm_coe_exec(&fsm->fsm_coe); // execute immediately |
ffa13db95e10
SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents:
437
diff
changeset
|
525 |
return; |
ffa13db95e10
SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents:
437
diff
changeset
|
526 |
} |
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
|
527 |
|
741
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
528 |
// check, if slaves have their PDO mapping to be read. |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
529 |
list_for_each_entry(slave, &master->slaves, list) { |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
530 |
if (!(slave->sii_mailbox_protocols & EC_MBOX_COE) |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
531 |
|| slave->pdo_mapping_fetched |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
532 |
|| !slave->sdo_dictionary_fetched |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
533 |
|| slave->current_state == EC_SLAVE_STATE_INIT |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
534 |
|| slave->online_state == EC_SLAVE_OFFLINE) continue; |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
535 |
|
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
536 |
if (master->debug_level) { |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
537 |
EC_DBG("Fetching PDO mapping from slave %i via CoE.\n", |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
538 |
slave->ring_position); |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
539 |
} |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
540 |
|
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
541 |
slave->pdo_mapping_fetched = 1; |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
542 |
|
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
543 |
// start fetching PDO mapping |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
544 |
fsm->idle = 0; |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
545 |
fsm->state = ec_fsm_master_state_pdomap; |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
546 |
ec_fsm_coe_map_start(&fsm->fsm_coe_map, slave); |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
547 |
ec_fsm_coe_map_exec(&fsm->fsm_coe_map); // execute immediately |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
548 |
return; |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
549 |
} |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
550 |
|
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
|
551 |
// check for pending EEPROM write operations. |
601
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
552 |
if (ec_fsm_master_action_process_eeprom(fsm)) |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
553 |
return; // EEPROM write request found |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
554 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
555 |
|
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
|
556 |
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
|
557 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
558 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
559 |
/*****************************************************************************/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
560 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
561 |
/** |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
562 |
Master action: Get state of next slave. |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
563 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
564 |
|
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
|
565 |
void ec_fsm_master_action_next_slave_state(ec_fsm_master_t *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
|
566 |
/**< master state machine */) |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
567 |
{ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
568 |
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
|
569 |
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
|
570 |
|
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
571 |
// 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
|
572 |
if (slave->list.next != &master->slaves) { |
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
573 |
// process next slave |
650
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
574 |
fsm->idle = 1; |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
575 |
fsm->slave = list_entry(slave->list.next, ec_slave_t, list); |
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
|
576 |
ec_datagram_nprd(fsm->datagram, fsm->slave->station_address, |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
577 |
0x0130, 2); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
578 |
fsm->retries = EC_FSM_RETRIES; |
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
|
579 |
fsm->state = ec_fsm_master_state_read_states; |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
580 |
return; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
581 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
582 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
583 |
// all slave states read |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
584 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
585 |
// check, if a bus validation has to be done |
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
|
586 |
if (fsm->validate) { |
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
|
587 |
fsm->validate = 0; |
292
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
588 |
list_for_each_entry(slave, &master->slaves, list) { |
610
29489a43ecee
Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents:
607
diff
changeset
|
589 |
if (slave->online_state == EC_SLAVE_ONLINE) continue; |
292
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
590 |
|
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
591 |
// At least one slave is offline. validate! |
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
592 |
EC_INFO("Validating bus.\n"); |
650
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
593 |
fsm->idle = 0; |
292
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
594 |
fsm->slave = list_entry(master->slaves.next, ec_slave_t, list); |
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
|
595 |
fsm->state = ec_fsm_master_state_validate_vendor; |
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
596 |
ec_fsm_sii_read(&fsm->fsm_sii, slave, 0x0008, EC_FSM_SII_POSITION); |
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
597 |
ec_fsm_sii_exec(&fsm->fsm_sii); // execute immediately |
292
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
598 |
return; |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
599 |
} |
292
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
600 |
} |
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
601 |
|
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
602 |
ec_fsm_master_action_process_states(fsm); |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
603 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
604 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
605 |
/*****************************************************************************/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
606 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
607 |
/** |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
608 |
Master state: READ STATES. |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
609 |
Fetches the AL- and online state of a slave. |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
610 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
611 |
|
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
|
612 |
void ec_fsm_master_state_read_states(ec_fsm_master_t *fsm /**< master state machine */) |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
613 |
{ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
614 |
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
|
615 |
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
|
616 |
|
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
617 |
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
|
618 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
619 |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
620 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
594
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
553
diff
changeset
|
621 |
EC_ERR("Failed to receive AL state datagram for slave %i" |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
661
diff
changeset
|
622 |
" (datagram state %i)\n", |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
661
diff
changeset
|
623 |
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
|
624 |
fsm->state = ec_fsm_master_state_error; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
625 |
return; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
626 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
627 |
|
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
628 |
// did the slave not respond to its station address? |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
661
diff
changeset
|
629 |
if (datagram->working_counter == 0) { |
610
29489a43ecee
Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents:
607
diff
changeset
|
630 |
ec_slave_set_online_state(slave, EC_SLAVE_OFFLINE); |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
631 |
ec_fsm_master_action_next_slave_state(fsm); |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
632 |
return; |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
633 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
634 |
|
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
661
diff
changeset
|
635 |
// FIXME what to to on multiple response? |
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
661
diff
changeset
|
636 |
|
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
637 |
// slave responded |
610
29489a43ecee
Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents:
607
diff
changeset
|
638 |
ec_slave_set_state(slave, EC_READ_U8(datagram->data)); // set app state first |
29489a43ecee
Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents:
607
diff
changeset
|
639 |
ec_slave_set_online_state(slave, EC_SLAVE_ONLINE); |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
640 |
|
454
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
641 |
// check, if new slave state has to be acknowledged |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
642 |
if (slave->current_state & EC_SLAVE_STATE_ACK_ERR && !slave->error_flag) { |
650
c68995623e94
Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
649
diff
changeset
|
643 |
fsm->idle = 0; |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
644 |
fsm->state = ec_fsm_master_state_acknowledge; |
454
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
645 |
ec_fsm_change_ack(&fsm->fsm_change, slave); |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
646 |
ec_fsm_change_exec(&fsm->fsm_change); |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
647 |
return; |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
648 |
} |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
649 |
|
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
650 |
ec_fsm_master_action_next_slave_state(fsm); |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
651 |
} |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
652 |
|
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
653 |
/*****************************************************************************/ |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
654 |
|
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
655 |
/** |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
656 |
Master state: ACKNOWLEDGE |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
657 |
*/ |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
658 |
|
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
|
659 |
void ec_fsm_master_state_acknowledge(ec_fsm_master_t *fsm /**< master state machine */) |
454
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
660 |
{ |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
661 |
ec_slave_t *slave = fsm->slave; |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
662 |
|
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
663 |
if (ec_fsm_change_exec(&fsm->fsm_change)) return; |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
664 |
|
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
665 |
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
|
666 |
fsm->slave->error_flag = 1; |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
667 |
EC_ERR("Failed to acknowledge state change on slave %i.\n", |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
668 |
slave->ring_position); |
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
|
669 |
fsm->state = ec_fsm_master_state_error; |
454
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
670 |
return; |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
671 |
} |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
672 |
|
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
673 |
ec_fsm_master_action_next_slave_state(fsm); |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
674 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
675 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
676 |
/*****************************************************************************/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
677 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
678 |
/** |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
679 |
Master state: VALIDATE_VENDOR. |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
680 |
Validates the vendor ID of a slave. |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
681 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
682 |
|
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
|
683 |
void ec_fsm_master_state_validate_vendor(ec_fsm_master_t *fsm /**< master state machine */) |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
684 |
{ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
685 |
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
|
686 |
|
435
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
434
diff
changeset
|
687 |
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
|
688 |
|
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
689 |
if (!ec_fsm_sii_success(&fsm->fsm_sii)) { |
292
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
690 |
fsm->slave->error_flag = 1; |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
691 |
EC_ERR("Failed to validate vendor ID of slave %i.\n", |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
692 |
slave->ring_position); |
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
|
693 |
fsm->state = ec_fsm_master_state_error; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
694 |
return; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
695 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
696 |
|
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
697 |
if (EC_READ_U32(fsm->fsm_sii.value) != slave->sii_vendor_id) { |
446 | 698 |
EC_ERR("Slave %i has an invalid vendor ID!\n", slave->ring_position); |
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
|
699 |
fsm->state = ec_fsm_master_state_error; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
700 |
return; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
701 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
702 |
|
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
703 |
// vendor ID is ok. check product code. |
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
|
704 |
fsm->state = ec_fsm_master_state_validate_product; |
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
705 |
ec_fsm_sii_read(&fsm->fsm_sii, slave, 0x000A, EC_FSM_SII_POSITION); |
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
706 |
ec_fsm_sii_exec(&fsm->fsm_sii); // execute immediately |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
707 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
708 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
709 |
/*****************************************************************************/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
710 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
711 |
/** |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
712 |
Master action: ADDRESS. |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
713 |
Looks for slave, that have lost their configuration and writes |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
714 |
their station address, so that they can be reconfigured later. |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
715 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
716 |
|
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
|
717 |
void ec_fsm_master_action_addresses(ec_fsm_master_t *fsm /**< master state machine */) |
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
|
718 |
{ |
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
|
719 |
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
|
720 |
|
610
29489a43ecee
Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents:
607
diff
changeset
|
721 |
while (fsm->slave->online_state == EC_SLAVE_ONLINE) { |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
722 |
if (fsm->slave->list.next == &fsm->master->slaves) { // last slave? |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
723 |
fsm->state = ec_fsm_master_state_end; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
724 |
return; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
725 |
} |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
726 |
// check next slave |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
727 |
fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list); |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
728 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
729 |
|
446 | 730 |
if (fsm->master->debug_level) |
731 |
EC_DBG("Reinitializing slave %i.\n", fsm->slave->ring_position); |
|
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
732 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
733 |
// write station address |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
734 |
ec_datagram_apwr(datagram, fsm->slave->ring_position, 0x0010, 2); |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
735 |
EC_WRITE_U16(datagram->data, fsm->slave->station_address); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
736 |
fsm->retries = EC_FSM_RETRIES; |
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
|
737 |
fsm->state = ec_fsm_master_state_rewrite_addresses; |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
738 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
739 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
740 |
/*****************************************************************************/ |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
741 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
742 |
/** |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
743 |
Master state: VALIDATE_PRODUCT. |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
744 |
Validates the product ID of a slave. |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
745 |
*/ |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
746 |
|
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
|
747 |
void ec_fsm_master_state_validate_product(ec_fsm_master_t *fsm /**< master state machine */) |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
748 |
{ |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
749 |
ec_slave_t *slave = fsm->slave; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
750 |
|
435
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
434
diff
changeset
|
751 |
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
|
752 |
|
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
753 |
if (!ec_fsm_sii_success(&fsm->fsm_sii)) { |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
754 |
fsm->slave->error_flag = 1; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
755 |
EC_ERR("Failed to validate product code of slave %i.\n", |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
756 |
slave->ring_position); |
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
|
757 |
fsm->state = ec_fsm_master_state_error; |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
758 |
return; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
759 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
760 |
|
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
761 |
if (EC_READ_U32(fsm->fsm_sii.value) != slave->sii_product_code) { |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
762 |
EC_ERR("Slave %i: invalid product code!\n", slave->ring_position); |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
763 |
EC_ERR("expected 0x%08X, got 0x%08X.\n", slave->sii_product_code, |
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
764 |
EC_READ_U32(fsm->fsm_sii.value)); |
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
|
765 |
fsm->state = ec_fsm_master_state_error; |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
766 |
return; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
767 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
768 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
769 |
// have all states been validated? |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
770 |
if (slave->list.next == &fsm->master->slaves) { |
642
3ed80c8ed616
Correctted resetting topology_change_pending and tainted flags.
Florian Pose <fp@igh-essen.com>
parents:
637
diff
changeset
|
771 |
fsm->topology_change_pending = 0; |
612
aede068f9a74
Introduced master status, ecrt_master_get_status(), tainted flag,
Florian Pose <fp@igh-essen.com>
parents:
610
diff
changeset
|
772 |
fsm->tainted = 0; |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
773 |
fsm->slave = list_entry(fsm->master->slaves.next, ec_slave_t, list); |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
774 |
// start writing addresses to offline slaves |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
775 |
ec_fsm_master_action_addresses(fsm); |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
776 |
return; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
777 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
778 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
779 |
// validate next slave |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
780 |
fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list); |
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
|
781 |
fsm->state = ec_fsm_master_state_validate_vendor; |
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
782 |
ec_fsm_sii_read(&fsm->fsm_sii, slave, 0x0008, EC_FSM_SII_POSITION); |
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
783 |
ec_fsm_sii_exec(&fsm->fsm_sii); // execute immediately |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
784 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
785 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
786 |
/*****************************************************************************/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
787 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
788 |
/** |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
789 |
Master state: REWRITE ADDRESS. |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
790 |
Checks, if the new station address has been written to the slave. |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
791 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
792 |
|
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
|
793 |
void ec_fsm_master_state_rewrite_addresses(ec_fsm_master_t *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
|
794 |
/**< master state machine */ |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
795 |
) |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
796 |
{ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
797 |
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
|
798 |
ec_datagram_t *datagram = fsm->datagram; |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
799 |
|
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
800 |
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
|
801 |
return; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
802 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
803 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
594
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
553
diff
changeset
|
804 |
EC_ERR("Failed to receive address datagram for slave %i" |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
553
diff
changeset
|
805 |
" (datagram state %i).\n", |
07dd2a7df66e
Added datagram state to "Failed to receive..." messages.
Florian Pose <fp@igh-essen.com>
parents:
553
diff
changeset
|
806 |
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
|
807 |
fsm->state = ec_fsm_master_state_error; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
808 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
809 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
810 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
811 |
if (datagram->working_counter != 1) { |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
661
diff
changeset
|
812 |
EC_ERR("Failed to write station address of slave %i: ", |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
813 |
slave->ring_position); |
713
ae41cadd25b6
Better handling of unexpected working counters; introduced
Florian Pose <fp@igh-essen.com>
parents:
661
diff
changeset
|
814 |
ec_datagram_print_wc_error(datagram); |
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
|
815 |
fsm->state = ec_fsm_master_state_error; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
816 |
return; |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
817 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
818 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
819 |
if (fsm->slave->list.next == &fsm->master->slaves) { // last slave? |
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
820 |
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
|
821 |
return; |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
822 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
823 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
824 |
// check next slave |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
825 |
fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list); |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
826 |
// Write new station address to slave |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
827 |
ec_fsm_master_action_addresses(fsm); |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
828 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
829 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
830 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
831 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
832 |
/** |
717
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
833 |
* Master state: CLEAR ADDRESSES. |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
834 |
*/ |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
835 |
|
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
836 |
void ec_fsm_master_state_clear_addresses( |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
837 |
ec_fsm_master_t *fsm /**< master state machine */ |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
838 |
) |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
839 |
{ |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
840 |
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
|
841 |
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
|
842 |
|
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
843 |
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
|
844 |
return; |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
845 |
|
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
846 |
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
|
847 |
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
|
848 |
datagram->state); |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
849 |
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
|
850 |
return; |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
851 |
} |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
852 |
|
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
853 |
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
|
854 |
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
|
855 |
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
|
856 |
} |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
857 |
|
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
858 |
EC_INFO("Scanning bus.\n"); |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
859 |
|
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
860 |
// begin scanning of slaves |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
861 |
fsm->slave = list_entry(master->slaves.next, ec_slave_t, list); |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
862 |
fsm->state = ec_fsm_master_state_scan_slaves; |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
863 |
ec_fsm_slave_start_scan(&fsm->fsm_slave, fsm->slave); |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
864 |
ec_fsm_slave_exec(&fsm->fsm_slave); // execute immediately |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
865 |
} |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
866 |
|
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
867 |
/*****************************************************************************/ |
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
868 |
|
87abf1166e88
Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents:
716
diff
changeset
|
869 |
/** |
652 | 870 |
* Master state: SCAN SLAVES. |
871 |
* Executes the sub-statemachine for the scanning of a slave. |
|
872 |
*/ |
|
873 |
||
874 |
void ec_fsm_master_state_scan_slaves( |
|
875 |
ec_fsm_master_t *fsm /**< master state machine */ |
|
876 |
) |
|
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
877 |
{ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
878 |
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
|
879 |
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
|
880 |
|
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
|
881 |
if (ec_fsm_slave_exec(&fsm->fsm_slave)) // execute slave state machine |
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
|
882 |
return; |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
883 |
|
715
f12ff7c08623
Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
884 |
#ifdef EC_EOE |
661
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
885 |
if (slave->sii_mailbox_protocols & EC_MBOX_EOE) { |
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
886 |
// create EoE handler for this slave |
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
887 |
ec_eoe_t *eoe; |
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
888 |
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
|
889 |
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
|
890 |
slave->ring_position); |
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
891 |
} |
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
892 |
else if (ec_eoe_init(eoe, slave)) { |
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
893 |
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
|
894 |
slave->ring_position); |
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
895 |
kfree(eoe); |
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
896 |
} |
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
897 |
else { |
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
898 |
list_add_tail(&eoe->list, &master->eoe_handlers); |
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
899 |
} |
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
900 |
} |
715
f12ff7c08623
Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
901 |
#endif |
661
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
902 |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
903 |
// 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
|
904 |
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
|
905 |
fsm->slave = list_entry(slave->list.next, ec_slave_t, list); |
538
84beb49d1b11
Fixed bug that caused the last slave not to be scanned.
Florian Pose <fp@igh-essen.com>
parents:
530
diff
changeset
|
906 |
ec_fsm_slave_start_scan(&fsm->fsm_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
|
907 |
ec_fsm_slave_exec(&fsm->fsm_slave); // execute immediately |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
908 |
return; |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
909 |
} |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
910 |
|
652 | 911 |
EC_INFO("Bus scanning completed in %u ms.\n", |
912 |
(u32) (jiffies - fsm->scan_jiffies) * 1000 / HZ); |
|
661
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
913 |
|
716 | 914 |
#ifdef EC_EOE |
661
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
915 |
// check if EoE processing has to be started |
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
916 |
ec_master_eoe_start(master); |
715
f12ff7c08623
Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents:
713
diff
changeset
|
917 |
#endif |
661
bc1de1362efb
Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
656
diff
changeset
|
918 |
|
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
919 |
master->scan_state = EC_REQUEST_COMPLETE; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
920 |
wake_up_interruptible(&master->scan_queue); |
446 | 921 |
|
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
|
922 |
fsm->state = ec_fsm_master_state_end; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
923 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
924 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
925 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
926 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
927 |
/** |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
928 |
Master state: CONFIGURE SLAVES. |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
929 |
Starts configuring a slave. |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
930 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
931 |
|
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
|
932 |
void ec_fsm_master_state_configure_slave(ec_fsm_master_t *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
|
933 |
/**< master state machine */ |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
934 |
) |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
935 |
{ |
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
|
936 |
if (ec_fsm_slave_exec(&fsm->fsm_slave)) // execute slave's state machine |
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
|
937 |
return; |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
938 |
|
656
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
939 |
if (!ec_fsm_slave_success(&fsm->fsm_slave)) |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
940 |
fsm->config_error = 1; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
941 |
|
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
942 |
// configure next slave, if necessary |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
943 |
if (ec_fsm_master_action_configure(fsm)) |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
944 |
return; |
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
945 |
|
370aa8c2d1b1
Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents:
652
diff
changeset
|
946 |
fsm->state = ec_fsm_master_state_end; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
947 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
948 |
|
269 | 949 |
/*****************************************************************************/ |
950 |
||
951 |
/** |
|
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
952 |
Master state: WRITE EEPROM. |
269 | 953 |
*/ |
954 |
||
607
7b1daa325c5f
Implemented alias reading/writing via sysfs.
Florian Pose <fp@igh-essen.com>
parents:
605
diff
changeset
|
955 |
void ec_fsm_master_state_write_eeprom( |
7b1daa325c5f
Implemented alias reading/writing via sysfs.
Florian Pose <fp@igh-essen.com>
parents:
605
diff
changeset
|
956 |
ec_fsm_master_t *fsm /**< master state machine */) |
269 | 957 |
{ |
601
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
958 |
ec_master_t *master = fsm->master; |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
959 |
ec_eeprom_write_request_t *request = fsm->eeprom_request; |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
960 |
ec_slave_t *slave = request->slave; |
269 | 961 |
|
435
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
434
diff
changeset
|
962 |
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
|
963 |
|
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
964 |
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
|
965 |
slave->error_flag = 1; |
607
7b1daa325c5f
Implemented alias reading/writing via sysfs.
Florian Pose <fp@igh-essen.com>
parents:
605
diff
changeset
|
966 |
EC_ERR("Failed to write EEPROM data to slave %i.\n", |
7b1daa325c5f
Implemented alias reading/writing via sysfs.
Florian Pose <fp@igh-essen.com>
parents:
605
diff
changeset
|
967 |
slave->ring_position); |
649
a4d3fffdaed7
Renamed names of enum type ec_request_state_t.
Florian Pose <fp@igh-essen.com>
parents:
646
diff
changeset
|
968 |
request->state = EC_REQUEST_FAILURE; |
605
96a894895999
Fixed signal issue in EEPROM writing code.
Florian Pose <fp@igh-essen.com>
parents:
604
diff
changeset
|
969 |
wake_up(&master->eeprom_queue); |
601
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
970 |
fsm->state = ec_fsm_master_state_error; |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
971 |
return; |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
972 |
} |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
973 |
|
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
974 |
fsm->eeprom_index++; |
754
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
743
diff
changeset
|
975 |
if (fsm->eeprom_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
|
976 |
ec_fsm_sii_write(&fsm->fsm_sii, slave, |
754
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
743
diff
changeset
|
977 |
request->word_offset + fsm->eeprom_index, |
0b47b49c5976
Changed unit of ec_eeprom_write_request_t from word to byte.
Florian Pose <fp@igh-essen.com>
parents:
743
diff
changeset
|
978 |
request->data + fsm->eeprom_index * 2, |
601
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
979 |
EC_FSM_SII_NODE); |
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
980 |
ec_fsm_sii_exec(&fsm->fsm_sii); // execute immediately |
269 | 981 |
return; |
982 |
} |
|
983 |
||
984 |
// finished writing EEPROM |
|
607
7b1daa325c5f
Implemented alias reading/writing via sysfs.
Florian Pose <fp@igh-essen.com>
parents:
605
diff
changeset
|
985 |
if (master->debug_level) |
743
5ee2c5ce9cca
Minor debugging output changes.
Florian Pose <fp@igh-essen.com>
parents:
741
diff
changeset
|
986 |
EC_DBG("Finished writing %u words of EEPROM 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
|
987 |
request->word_size, slave->ring_position); |
649
a4d3fffdaed7
Renamed names of enum type ec_request_state_t.
Florian Pose <fp@igh-essen.com>
parents:
646
diff
changeset
|
988 |
request->state = EC_REQUEST_COMPLETE; |
605
96a894895999
Fixed signal issue in EEPROM writing code.
Florian Pose <fp@igh-essen.com>
parents:
604
diff
changeset
|
989 |
wake_up(&master->eeprom_queue); |
269 | 990 |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
991 |
// TODO: Evaluate new EEPROM contents! |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
992 |
|
601
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
993 |
// check for another EEPROM write request |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
994 |
if (ec_fsm_master_action_process_eeprom(fsm)) |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
995 |
return; // processing another request |
d6d951b766e3
Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents:
594
diff
changeset
|
996 |
|
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
997 |
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
|
998 |
} |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
999 |
|
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1000 |
/*****************************************************************************/ |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1001 |
|
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1002 |
/** |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1003 |
Master state: SDODICT. |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1004 |
*/ |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1005 |
|
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
|
1006 |
void ec_fsm_master_state_sdodict(ec_fsm_master_t *fsm /**< master state machine */) |
419
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1007 |
{ |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1008 |
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
|
1009 |
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
|
1010 |
|
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
1011 |
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
|
1012 |
|
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
1013 |
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
|
1014 |
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
|
1015 |
return; |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1016 |
} |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1017 |
|
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1018 |
// SDO dictionary fetching finished |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1019 |
|
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1020 |
if (master->debug_level) { |
423
862ff892cf18
Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents:
422
diff
changeset
|
1021 |
unsigned int sdo_count, entry_count; |
862ff892cf18
Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents:
422
diff
changeset
|
1022 |
ec_slave_sdo_dict_info(slave, &sdo_count, &entry_count); |
862ff892cf18
Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents:
422
diff
changeset
|
1023 |
EC_DBG("Fetched %i SDOs and %i entries from slave %i.\n", |
862ff892cf18
Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents:
422
diff
changeset
|
1024 |
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
|
1025 |
} |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1026 |
|
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
1027 |
fsm->state = ec_fsm_master_state_end; |
269 | 1028 |
} |
1029 |
||
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
1030 |
/*****************************************************************************/ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
1031 |
|
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
1032 |
/** |
758
8fa6f825eb7d
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
754
diff
changeset
|
1033 |
* Scan the PDO mapping of a slave. |
741
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1034 |
*/ |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1035 |
|
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1036 |
void ec_fsm_master_state_pdomap( |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1037 |
ec_fsm_master_t *fsm /**< master state machine */ |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1038 |
) |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1039 |
{ |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1040 |
if (ec_fsm_coe_map_exec(&fsm->fsm_coe_map)) return; |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1041 |
|
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1042 |
if (!ec_fsm_coe_map_success(&fsm->fsm_coe_map)) { |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1043 |
fsm->state = ec_fsm_master_state_error; |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1044 |
return; |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1045 |
} |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1046 |
|
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1047 |
// fetching of PDO mapping finished |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1048 |
fsm->state = ec_fsm_master_state_end; |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1049 |
} |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1050 |
|
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1051 |
/*****************************************************************************/ |
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1052 |
|
aece53f82df3
Read PDO mapping from SDO dictionary (working, not finished yet).
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
1053 |
/** |
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
1054 |
Master state: SDO REQUEST. |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
1055 |
*/ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
1056 |
|
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
|
1057 |
void ec_fsm_master_state_sdo_request(ec_fsm_master_t *fsm /**< master state machine */) |
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
1058 |
{ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
1059 |
ec_master_t *master = fsm->master; |
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
1060 |
ec_sdo_request_t *request = fsm->sdo_request; |
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
1061 |
|
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
1062 |
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
|
1063 |
|
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
1064 |
if (!ec_fsm_coe_success(&fsm->fsm_coe)) { |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
1065 |
EC_DBG("Failed to process SDO request for slave %i.\n", |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
1066 |
fsm->slave->ring_position); |
649
a4d3fffdaed7
Renamed names of enum type ec_request_state_t.
Florian Pose <fp@igh-essen.com>
parents:
646
diff
changeset
|
1067 |
request->state = EC_REQUEST_FAILURE; |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
1068 |
wake_up(&master->sdo_queue); |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
1069 |
fsm->state = ec_fsm_master_state_error; |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
1070 |
return; |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
1071 |
} |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
1072 |
|
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
1073 |
// SDO request finished |
649
a4d3fffdaed7
Renamed names of enum type ec_request_state_t.
Florian Pose <fp@igh-essen.com>
parents:
646
diff
changeset
|
1074 |
request->state = EC_REQUEST_COMPLETE; |
646
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
1075 |
wake_up(&master->sdo_queue); |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
1076 |
|
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
1077 |
if (master->debug_level) |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
1078 |
EC_DBG("Finished SDO request for slave %i.\n", |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
1079 |
fsm->slave->ring_position); |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
1080 |
|
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
1081 |
// check for another SDO request |
fbbd4e54e031
Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents:
645
diff
changeset
|
1082 |
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
|
1083 |
return; // processing another request |
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
1084 |
|
637
d5d04c868e0e
Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents:
612
diff
changeset
|
1085 |
fsm->state = ec_fsm_master_state_end; |
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
1086 |
} |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
1087 |
|
446 | 1088 |
/*****************************************************************************/ |
1089 |
||
1090 |
/** |
|
1091 |
State: ERROR. |
|
1092 |
*/ |
|
1093 |
||
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
|
1094 |
void ec_fsm_master_state_error( |
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
|
1095 |
ec_fsm_master_t *fsm /**< master state machine */ |
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
|
1096 |
) |
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
|
1097 |
{ |
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
|
1098 |
fsm->state = ec_fsm_master_state_start; |
446 | 1099 |
} |
1100 |
||
1101 |
/*****************************************************************************/ |
|
1102 |
||
1103 |
/** |
|
1104 |
State: END. |
|
1105 |
*/ |
|
1106 |
||
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
|
1107 |
void ec_fsm_master_state_end(ec_fsm_master_t *fsm /**< master state machine */) |
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
|
1108 |
{ |
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
|
1109 |
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
|
1110 |
} |
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
|
1111 |
|
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
|
1112 |
/*****************************************************************************/ |
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
|
1113 |