author | Florian Pose <fp@igh-essen.com> |
Fri, 12 Jan 2007 12:10:09 +0000 | |
changeset 531 | 8d9339e7453f |
parent 530 | 3e0611dfe020 |
child 538 | 84beb49d1b11 |
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" |
528
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
44 |
#include "fsm_master.h" |
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
|
45 |
|
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
46 |
/*****************************************************************************/ |
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
47 |
|
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
48 |
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
|
49 |
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
|
50 |
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
|
51 |
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
|
52 |
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
|
53 |
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
|
54 |
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
|
55 |
void ec_fsm_master_state_configure_slave(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_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
|
57 |
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
|
58 |
void ec_fsm_master_state_sdodict(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
|
59 |
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
|
60 |
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
|
61 |
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
|
62 |
|
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
63 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
64 |
|
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
65 |
/** |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
66 |
Constructor. |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
67 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
68 |
|
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
|
69 |
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
|
70 |
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
|
71 |
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
|
72 |
) |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
73 |
{ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
74 |
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
|
75 |
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
|
76 |
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
|
77 |
fsm->slaves_responding = 0; |
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
|
78 |
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
|
79 |
fsm->validate = 0; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
80 |
|
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
81 |
// 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
|
82 |
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
|
83 |
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
|
84 |
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
|
85 |
ec_fsm_coe_init(&fsm->fsm_coe, fsm->datagram); |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
86 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
87 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
88 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
89 |
|
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
90 |
/** |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
91 |
Destructor. |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
92 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
93 |
|
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
|
94 |
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
|
95 |
{ |
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
96 |
// 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
|
97 |
ec_fsm_slave_clear(&fsm->fsm_slave); |
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
98 |
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
|
99 |
ec_fsm_change_clear(&fsm->fsm_change); |
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
100 |
ec_fsm_coe_clear(&fsm->fsm_coe); |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
101 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
102 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
103 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
104 |
|
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
105 |
/** |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
106 |
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
|
107 |
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
|
108 |
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
|
109 |
\return false, if state machine has terminated |
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
434
diff
changeset
|
110 |
*/ |
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
434
diff
changeset
|
111 |
|
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
|
112 |
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
|
113 |
{ |
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
|
114 |
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
|
115 |
|| 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
|
116 |
// 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
|
117 |
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
|
118 |
} |
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
|
119 |
|
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
|
120 |
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
|
121 |
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
|
122 |
} |
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
|
123 |
|
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
|
124 |
/*****************************************************************************/ |
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
|
125 |
|
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
|
126 |
/** |
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
|
127 |
\return false, if state machine has terminated |
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
|
128 |
*/ |
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
|
129 |
|
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
|
130 |
int ec_fsm_master_running(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
|
131 |
{ |
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
|
132 |
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
|
133 |
&& fsm->state != ec_fsm_master_state_error; |
446 | 134 |
} |
135 |
||
136 |
/*****************************************************************************/ |
|
137 |
||
138 |
/** |
|
139 |
\return true, if the master state machine terminated gracefully |
|
140 |
*/ |
|
141 |
||
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
|
142 |
int ec_fsm_master_success(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
|
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; |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
145 |
} |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
146 |
|
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
147 |
/****************************************************************************** |
446 | 148 |
* operation/idle state machine |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
149 |
*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
150 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
151 |
/** |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
152 |
Master state: START. |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
153 |
Starts with getting slave count and slave states. |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
154 |
*/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
155 |
|
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
|
156 |
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
|
157 |
{ |
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
|
158 |
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
|
159 |
ec_master_queue_datagram(fsm->master, 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
|
160 |
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
|
161 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
162 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
163 |
/*****************************************************************************/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
164 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
165 |
/** |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
166 |
Master state: BROADCAST. |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
167 |
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
|
168 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
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_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
|
171 |
{ |
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
172 |
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
|
173 |
unsigned int topology_change, states_change, i; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
174 |
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
|
175 |
ec_master_t *master = fsm->master; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
176 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
177 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
178 |
// always retry |
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
|
179 |
ec_master_queue_datagram(fsm->master, fsm->datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
180 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
181 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
182 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
183 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { // EC_DATAGRAM_ERROR |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
184 |
// 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
|
185 |
fsm->slaves_responding = 0; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
186 |
list_for_each_entry(slave, &master->slaves, list) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
187 |
slave->online = 0; |
446 | 188 |
} |
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
|
189 |
fsm->state = ec_fsm_master_state_error; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
190 |
return; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
191 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
192 |
|
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
193 |
topology_change = (datagram->working_counter != |
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
|
194 |
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
|
195 |
states_change = (EC_READ_U8(datagram->data) != fsm->slave_states); |
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
|
196 |
|
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
|
197 |
fsm->slave_states = EC_READ_U8(datagram->data); |
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
|
198 |
fsm->slaves_responding = datagram->working_counter; |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
199 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
200 |
if (topology_change) { |
262
636d43737371
Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents:
260
diff
changeset
|
201 |
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
|
202 |
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
|
203 |
fsm->slaves_responding == 1 ? "" : "s"); |
262
636d43737371
Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents:
260
diff
changeset
|
204 |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
205 |
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
|
206 |
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
|
207 |
fsm->validate = 1; // start validation later |
262
636d43737371
Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents:
260
diff
changeset
|
208 |
} |
636d43737371
Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents:
260
diff
changeset
|
209 |
else { |
636d43737371
Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents:
260
diff
changeset
|
210 |
EC_WARN("Invalid slave count. Bus in tainted state.\n"); |
636d43737371
Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents:
260
diff
changeset
|
211 |
} |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
212 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
213 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
214 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
215 |
if (states_change) { |
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
|
216 |
char states[EC_STATE_STRING_SIZE]; |
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
|
217 |
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
|
218 |
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
|
219 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
220 |
|
306
45886de3db87
Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents:
304
diff
changeset
|
221 |
// topology change in idle mode: clear all slaves and scan the bus |
45886de3db87
Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents:
304
diff
changeset
|
222 |
if (topology_change && master->mode == EC_MASTER_MODE_IDLE) { |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
223 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
224 |
ec_master_eoe_stop(master); |
448
e4b76dc7910c
FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents:
446
diff
changeset
|
225 |
ec_master_destroy_slaves(master); |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
226 |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
227 |
master->slave_count = datagram->working_counter; |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
228 |
|
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
229 |
if (!master->slave_count) { |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
230 |
// no slaves present -> finish state machine. |
528
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
231 |
fsm->state = ec_fsm_master_state_end; |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
232 |
return; |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
233 |
} |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
234 |
|
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
235 |
// init slaves |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
236 |
for (i = 0; i < master->slave_count; i++) { |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
237 |
if (!(slave = (ec_slave_t *) kmalloc(sizeof(ec_slave_t), |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
238 |
GFP_ATOMIC))) { |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
239 |
EC_ERR("Failed to allocate slave %i!\n", i); |
448
e4b76dc7910c
FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents:
446
diff
changeset
|
240 |
ec_master_destroy_slaves(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
|
241 |
fsm->state = ec_fsm_master_state_error; |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
242 |
return; |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
243 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
244 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
245 |
if (ec_slave_init(slave, master, i, i + 1)) { |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
246 |
// freeing of "slave" already done |
448
e4b76dc7910c
FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents:
446
diff
changeset
|
247 |
ec_master_destroy_slaves(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
|
248 |
fsm->state = ec_fsm_master_state_error; |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
249 |
return; |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
250 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
251 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
252 |
list_add_tail(&slave->list, &master->slaves); |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
253 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
254 |
|
446 | 255 |
EC_INFO("Scanning bus.\n"); |
256 |
||
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
257 |
// begin scanning of slaves |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
258 |
fsm->slave = list_entry(master->slaves.next, ec_slave_t, list); |
530
3e0611dfe020
Fixed bug in master state machine that came up in r745.
Florian Pose <fp@igh-essen.com>
parents:
528
diff
changeset
|
259 |
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
|
260 |
ec_fsm_slave_exec(&fsm->fsm_slave); // execute immediately |
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
|
261 |
fsm->state = ec_fsm_master_state_scan_slaves; |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
262 |
return; |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
263 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
264 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
265 |
// 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
|
266 |
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
|
267 |
ec_datagram_nprd(fsm->datagram, fsm->slave->station_address, 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
|
268 |
ec_master_queue_datagram(master, fsm->datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
269 |
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
|
270 |
fsm->state = ec_fsm_master_state_read_states; |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
271 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
272 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
273 |
/*****************************************************************************/ |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
274 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
275 |
/** |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
276 |
Master action: PROC_STATES. |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
277 |
Processes the slave states. |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
278 |
*/ |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
279 |
|
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
|
280 |
void ec_fsm_master_action_process_states(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
|
281 |
/**< master state machine */ |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
282 |
) |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
283 |
{ |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
284 |
ec_master_t *master = fsm->master; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
285 |
ec_slave_t *slave; |
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
|
286 |
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
|
287 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
288 |
// check if any slaves are not in the state, they're supposed to be |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
289 |
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
|
290 |
if (slave->error_flag |
2b3ce4f51bd6
Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents:
420
diff
changeset
|
291 |
|| !slave->online |
2b3ce4f51bd6
Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents:
420
diff
changeset
|
292 |
|| slave->requested_state == EC_SLAVE_STATE_UNKNOWN |
523
584a4f60b067
Re-added slave.configured flag as slave.self_configured.
Florian Pose <fp@igh-essen.com>
parents:
522
diff
changeset
|
293 |
|| (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
|
294 |
&& 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
|
295 |
|
446 | 296 |
if (master->debug_level) { |
297 |
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
|
298 |
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
|
299 |
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
|
300 |
EC_DBG("Changing state of slave %i (%s -> %s).\n", |
584a4f60b067
Re-added slave.configured flag as slave.self_configured.
Florian Pose <fp@igh-essen.com>
parents:
522
diff
changeset
|
301 |
slave->ring_position, old_state, new_state); |
584a4f60b067
Re-added slave.configured flag as slave.self_configured.
Florian Pose <fp@igh-essen.com>
parents:
522
diff
changeset
|
302 |
} |
584a4f60b067
Re-added slave.configured flag as slave.self_configured.
Florian Pose <fp@igh-essen.com>
parents:
522
diff
changeset
|
303 |
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
|
304 |
EC_DBG("Reconfiguring slave %i (%s).\n", |
584a4f60b067
Re-added slave.configured flag as slave.self_configured.
Florian Pose <fp@igh-essen.com>
parents:
522
diff
changeset
|
305 |
slave->ring_position, old_state); |
584a4f60b067
Re-added slave.configured flag as slave.self_configured.
Florian Pose <fp@igh-essen.com>
parents:
522
diff
changeset
|
306 |
} |
421
2b3ce4f51bd6
Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents:
420
diff
changeset
|
307 |
} |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
308 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
309 |
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
|
310 |
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
|
311 |
ec_fsm_slave_exec(&fsm->fsm_slave); // execute immediately |
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
|
312 |
fsm->state = ec_fsm_master_state_configure_slave; |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
313 |
return; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
314 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
315 |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
316 |
// Check, if EoE processing has to be started |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
317 |
ec_master_eoe_start(master); |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
318 |
|
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
|
319 |
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
|
320 |
|
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
321 |
// Check for a pending SDO request |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
322 |
if (master->sdo_seq_master != master->sdo_seq_user) { |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
323 |
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
|
324 |
EC_DBG("Processing SDO request...\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
|
325 |
slave = master->sdo_request->sdo->slave; |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
326 |
if (slave->current_state == EC_SLAVE_STATE_INIT |
475
e712a42446af
Allow CoE requests, even if slave has error flag set.
Florian Pose <fp@igh-essen.com>
parents:
470
diff
changeset
|
327 |
|| !slave->online) { |
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
|
328 |
EC_ERR("Failed to process SDO request, slave %i not ready.\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
|
329 |
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
|
330 |
master->sdo_request->return_code = -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
|
331 |
master->sdo_seq_master++; |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
332 |
} |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
333 |
else { |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
334 |
// start uploading SDO |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
335 |
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
|
336 |
fsm->state = ec_fsm_master_state_sdo_request; |
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
|
337 |
fsm->sdo_request = master->sdo_request; |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
338 |
ec_fsm_coe_upload(&fsm->fsm_coe, slave, fsm->sdo_request); |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
339 |
ec_fsm_coe_exec(&fsm->fsm_coe); // execute immediately |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
340 |
return; |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
341 |
} |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
342 |
} |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
343 |
|
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
344 |
// 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
|
345 |
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
|
346 |
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
|
347 |
|| 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
|
348 |
|| 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
|
349 |
|| jiffies - slave->jiffies_preop < EC_WAIT_SDO_DICT * HZ |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
350 |
|| !slave->online |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
351 |
|| 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
|
352 |
|
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
353 |
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
|
354 |
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
|
355 |
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
|
356 |
} |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
357 |
|
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
358 |
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
|
359 |
|
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
360 |
// start fetching SDO dictionary |
441
ffa13db95e10
SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents:
437
diff
changeset
|
361 |
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
|
362 |
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
|
363 |
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
|
364 |
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
|
365 |
return; |
ffa13db95e10
SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents:
437
diff
changeset
|
366 |
} |
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
|
367 |
|
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
368 |
// check for pending EEPROM write operations. |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
369 |
list_for_each_entry(slave, &master->slaves, list) { |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
370 |
if (!slave->new_eeprom_data) continue; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
371 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
372 |
if (!slave->online || slave->error_flag) { |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
373 |
kfree(slave->new_eeprom_data); |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
374 |
slave->new_eeprom_data = NULL; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
375 |
EC_ERR("Discarding EEPROM data, slave %i not ready.\n", |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
376 |
slave->ring_position); |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
377 |
continue; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
378 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
379 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
380 |
// found pending EEPROM write operation. execute it! |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
381 |
EC_INFO("Writing EEPROM of slave %i...\n", slave->ring_position); |
470 | 382 |
fsm->slave = slave; |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
383 |
fsm->sii_offset = 0x0000; |
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
384 |
ec_fsm_sii_write(&fsm->fsm_sii, slave, fsm->sii_offset, |
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
385 |
slave->new_eeprom_data, EC_FSM_SII_NODE); |
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
|
386 |
fsm->state = ec_fsm_master_state_write_eeprom; |
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
|
387 |
fsm->state(fsm); // execute immediately |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
388 |
return; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
389 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
390 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
391 |
|
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
|
392 |
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
|
393 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
394 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
395 |
/*****************************************************************************/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
396 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
397 |
/** |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
398 |
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
|
399 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
400 |
|
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
|
401 |
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
|
402 |
/**< master state machine */) |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
403 |
{ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
404 |
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
|
405 |
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
|
406 |
|
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
407 |
// 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
|
408 |
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
|
409 |
// process next slave |
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
410 |
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
|
411 |
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
|
412 |
0x0130, 2); |
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
|
413 |
ec_master_queue_datagram(master, fsm->datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
414 |
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
|
415 |
fsm->state = ec_fsm_master_state_read_states; |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
416 |
return; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
417 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
418 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
419 |
// all slave states read |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
420 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
421 |
// 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
|
422 |
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
|
423 |
fsm->validate = 0; |
292
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
424 |
list_for_each_entry(slave, &master->slaves, list) { |
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
425 |
if (slave->online) continue; |
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
426 |
|
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
427 |
// 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
|
428 |
EC_INFO("Validating bus.\n"); |
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
429 |
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
|
430 |
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
|
431 |
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
|
432 |
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
|
433 |
return; |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
434 |
} |
292
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
435 |
} |
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
436 |
|
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
437 |
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
|
438 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
439 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
440 |
/*****************************************************************************/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
441 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
442 |
/** |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
443 |
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
|
444 |
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
|
445 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
446 |
|
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
|
447 |
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
|
448 |
{ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
449 |
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
|
450 |
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
|
451 |
uint8_t new_state; |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
452 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
453 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && 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
|
454 |
ec_master_queue_datagram(fsm->master, fsm->datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
455 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
456 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
457 |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
458 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
446 | 459 |
EC_ERR("Failed to receive AL state datagram for slave %i!\n", |
460 |
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
|
461 |
fsm->state = ec_fsm_master_state_error; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
462 |
return; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
463 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
464 |
|
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
465 |
// did the slave not respond to its station address? |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
466 |
if (datagram->working_counter != 1) { |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
467 |
if (slave->online) { |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
468 |
slave->online = 0; |
461
b9eda9235173
Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
459
diff
changeset
|
469 |
if (slave->master->debug_level) |
459
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
456
diff
changeset
|
470 |
EC_DBG("Slave %i: offline.\n", slave->ring_position); |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
471 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
472 |
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
|
473 |
return; |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
474 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
475 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
476 |
// slave responded |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
477 |
new_state = EC_READ_U8(datagram->data); |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
478 |
if (!slave->online) { // slave was offline before |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
479 |
slave->online = 1; |
291
0b1f877cf3f1
Slave: state_error -> error_flag, error_flag only in slave state machine.
Florian Pose <fp@igh-essen.com>
parents:
290
diff
changeset
|
480 |
slave->error_flag = 0; // clear error flag |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
481 |
slave->current_state = new_state; |
461
b9eda9235173
Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
459
diff
changeset
|
482 |
if (slave->master->debug_level) { |
459
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
456
diff
changeset
|
483 |
char cur_state[EC_STATE_STRING_SIZE]; |
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
456
diff
changeset
|
484 |
ec_state_string(slave->current_state, cur_state); |
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
456
diff
changeset
|
485 |
EC_DBG("Slave %i: online (%s).\n", |
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
456
diff
changeset
|
486 |
slave->ring_position, cur_state); |
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
456
diff
changeset
|
487 |
} |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
488 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
489 |
else if (new_state != slave->current_state) { |
461
b9eda9235173
Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
459
diff
changeset
|
490 |
if (slave->master->debug_level) { |
459
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
456
diff
changeset
|
491 |
char old_state[EC_STATE_STRING_SIZE], |
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
456
diff
changeset
|
492 |
cur_state[EC_STATE_STRING_SIZE]; |
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
456
diff
changeset
|
493 |
ec_state_string(slave->current_state, old_state); |
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
456
diff
changeset
|
494 |
ec_state_string(new_state, cur_state); |
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
456
diff
changeset
|
495 |
EC_DBG("Slave %i: %s -> %s.\n", |
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
456
diff
changeset
|
496 |
slave->ring_position, old_state, cur_state); |
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
456
diff
changeset
|
497 |
} |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
498 |
slave->current_state = new_state; |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
499 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
500 |
|
454
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
501 |
// 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
|
502 |
if (slave->current_state & EC_SLAVE_STATE_ACK_ERR && !slave->error_flag) { |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
503 |
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
|
504 |
ec_fsm_change_exec(&fsm->fsm_change); |
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
|
505 |
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
|
506 |
return; |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
507 |
} |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
508 |
|
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
509 |
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
|
510 |
} |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
511 |
|
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
512 |
/*****************************************************************************/ |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
513 |
|
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
514 |
/** |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
515 |
Master state: ACKNOWLEDGE |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
516 |
*/ |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
517 |
|
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
|
518 |
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
|
519 |
{ |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
520 |
ec_slave_t *slave = fsm->slave; |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
521 |
|
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
522 |
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
|
523 |
|
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
524 |
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
|
525 |
fsm->slave->error_flag = 1; |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
526 |
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
|
527 |
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
|
528 |
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
|
529 |
return; |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
530 |
} |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
531 |
|
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
532 |
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
|
533 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
534 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
535 |
/*****************************************************************************/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
536 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
537 |
/** |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
538 |
Master state: VALIDATE_VENDOR. |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
539 |
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
|
540 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
541 |
|
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
|
542 |
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
|
543 |
{ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
544 |
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
|
545 |
|
435
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
434
diff
changeset
|
546 |
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
|
547 |
|
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
548 |
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
|
549 |
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
|
550 |
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
|
551 |
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
|
552 |
fsm->state = ec_fsm_master_state_error; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
553 |
return; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
554 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
555 |
|
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
556 |
if (EC_READ_U32(fsm->fsm_sii.value) != slave->sii_vendor_id) { |
446 | 557 |
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
|
558 |
fsm->state = ec_fsm_master_state_error; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
559 |
return; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
560 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
561 |
|
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
562 |
// 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
|
563 |
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
|
564 |
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
|
565 |
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
|
566 |
} |
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 |
/*****************************************************************************/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
569 |
|
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 |
Master action: ADDRESS. |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
572 |
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
|
573 |
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
|
574 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
575 |
|
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 |
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
|
577 |
{ |
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
|
578 |
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
|
579 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
580 |
while (fsm->slave->online) { |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
581 |
if (fsm->slave->list.next == &fsm->master->slaves) { // last 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
|
582 |
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
|
583 |
fsm->state(fsm); // execute immediately |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
584 |
return; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
585 |
} |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
586 |
// check next slave |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
587 |
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
|
588 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
589 |
|
446 | 590 |
if (fsm->master->debug_level) |
591 |
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
|
592 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
593 |
// write station address |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
594 |
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
|
595 |
EC_WRITE_U16(datagram->data, fsm->slave->station_address); |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
596 |
ec_master_queue_datagram(fsm->master, datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
597 |
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
|
598 |
fsm->state = ec_fsm_master_state_rewrite_addresses; |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
599 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
600 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
601 |
/*****************************************************************************/ |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
602 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
603 |
/** |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
604 |
Master state: VALIDATE_PRODUCT. |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
605 |
Validates the product ID of a slave. |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
606 |
*/ |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
607 |
|
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
|
608 |
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
|
609 |
{ |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
610 |
ec_slave_t *slave = fsm->slave; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
611 |
|
435
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
434
diff
changeset
|
612 |
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
|
613 |
|
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
614 |
if (!ec_fsm_sii_success(&fsm->fsm_sii)) { |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
615 |
fsm->slave->error_flag = 1; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
616 |
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
|
617 |
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
|
618 |
fsm->state = ec_fsm_master_state_error; |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
619 |
return; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
620 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
621 |
|
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
622 |
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
|
623 |
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
|
624 |
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
|
625 |
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
|
626 |
fsm->state = ec_fsm_master_state_error; |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
627 |
return; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
628 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
629 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
630 |
// have all states been validated? |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
631 |
if (slave->list.next == &fsm->master->slaves) { |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
632 |
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
|
633 |
// start writing addresses to offline slaves |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
634 |
ec_fsm_master_action_addresses(fsm); |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
635 |
return; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
636 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
637 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
638 |
// validate next slave |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
639 |
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
|
640 |
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
|
641 |
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
|
642 |
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
|
643 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
644 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
645 |
/*****************************************************************************/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
646 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
647 |
/** |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
648 |
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
|
649 |
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
|
650 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
651 |
|
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
|
652 |
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
|
653 |
/**< master state machine */ |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
654 |
) |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
655 |
{ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
656 |
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
|
657 |
ec_datagram_t *datagram = fsm->datagram; |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
658 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
659 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && 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
|
660 |
ec_master_queue_datagram(fsm->master, fsm->datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
661 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
662 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
663 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
664 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
665 |
EC_ERR("Failed to receive address datagram for slave %i.\n", |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
666 |
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
|
667 |
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
|
668 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
669 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
670 |
|
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
671 |
if (datagram->working_counter != 1) { |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
672 |
EC_ERR("Failed to write station address - slave %i did not respond.\n", |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
484
diff
changeset
|
673 |
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
|
674 |
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
|
675 |
return; |
260
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 |
if (fsm->slave->list.next == &fsm->master->slaves) { // last 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
|
679 |
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
|
680 |
fsm->state(fsm); // execute immediately |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
681 |
return; |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
682 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
683 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
684 |
// check next slave |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
685 |
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
|
686 |
// Write new station address to slave |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
687 |
ec_fsm_master_action_addresses(fsm); |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
688 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
689 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
690 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
691 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
692 |
/** |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
693 |
Master state: SCAN SLAVES. |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
694 |
Executes the sub-statemachine for the scanning of a slave. |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
695 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
696 |
|
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
|
697 |
void ec_fsm_master_state_scan_slaves(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
|
698 |
{ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
699 |
ec_master_t *master = fsm->master; |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
700 |
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
|
701 |
|
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
|
702 |
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
|
703 |
return; |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
704 |
|
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
705 |
// another slave to fetch? |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
706 |
if (slave->list.next != &master->slaves) { |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
707 |
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
|
708 |
ec_fsm_slave_start_scan(&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
|
709 |
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
|
710 |
return; |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
711 |
} |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
712 |
|
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
713 |
EC_INFO("Bus scanning completed.\n"); |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
714 |
|
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
715 |
ec_master_calc_addressing(master); |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
716 |
|
428
2731a2fcc18d
Set initial state of all slaves to PREOP.
Florian Pose <fp@igh-essen.com>
parents:
427
diff
changeset
|
717 |
// set initial states of all slaves to PREOP to make mailbox |
2731a2fcc18d
Set initial state of all slaves to PREOP.
Florian Pose <fp@igh-essen.com>
parents:
427
diff
changeset
|
718 |
// communication possible |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
719 |
list_for_each_entry(slave, &master->slaves, list) { |
446 | 720 |
ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP); |
721 |
} |
|
722 |
||
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
|
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 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
725 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
726 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
727 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
728 |
/** |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
729 |
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
|
730 |
Starts configuring a slave. |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
731 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
732 |
|
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
|
733 |
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
|
734 |
/**< master state machine */ |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
735 |
) |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
736 |
{ |
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 |
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
|
738 |
return; |
304
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 |
ec_fsm_master_action_process_states(fsm); |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
741 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
742 |
|
269 | 743 |
/*****************************************************************************/ |
744 |
||
745 |
/** |
|
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
746 |
Master state: WRITE EEPROM. |
269 | 747 |
*/ |
748 |
||
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
|
749 |
void ec_fsm_master_state_write_eeprom(ec_fsm_master_t *fsm /**< master state machine */) |
269 | 750 |
{ |
751 |
ec_slave_t *slave = fsm->slave; |
|
752 |
||
435
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
434
diff
changeset
|
753 |
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
|
754 |
|
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
755 |
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
|
756 |
fsm->slave->error_flag = 1; |
269 | 757 |
EC_ERR("Failed to write EEPROM contents to slave %i.\n", |
758 |
slave->ring_position); |
|
759 |
kfree(slave->new_eeprom_data); |
|
760 |
slave->new_eeprom_data = NULL; |
|
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
|
761 |
fsm->state = ec_fsm_master_state_error; |
269 | 762 |
return; |
763 |
} |
|
764 |
||
765 |
fsm->sii_offset++; |
|
766 |
if (fsm->sii_offset < slave->new_eeprom_size) { |
|
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
767 |
ec_fsm_sii_write(&fsm->fsm_sii, slave, fsm->sii_offset, |
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
768 |
slave->new_eeprom_data + fsm->sii_offset, |
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
769 |
EC_FSM_SII_NODE); |
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
770 |
ec_fsm_sii_exec(&fsm->fsm_sii); // execute immediately |
269 | 771 |
return; |
772 |
} |
|
773 |
||
774 |
// finished writing EEPROM |
|
775 |
EC_INFO("Finished writing EEPROM of slave %i.\n", slave->ring_position); |
|
776 |
kfree(slave->new_eeprom_data); |
|
777 |
slave->new_eeprom_data = NULL; |
|
778 |
||
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
779 |
// 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
|
780 |
|
269 | 781 |
// restart master state machine. |
528
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
782 |
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
|
783 |
fsm->state(fsm); // execute immediately |
419
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
784 |
} |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
785 |
|
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
786 |
/*****************************************************************************/ |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
787 |
|
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
788 |
/** |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
789 |
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
|
790 |
*/ |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
791 |
|
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
|
792 |
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
|
793 |
{ |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
794 |
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
|
795 |
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
|
796 |
|
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
797 |
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
|
798 |
|
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
799 |
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
|
800 |
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
|
801 |
return; |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
802 |
} |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
803 |
|
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
804 |
// 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
|
805 |
|
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
806 |
if (master->debug_level) { |
423
862ff892cf18
Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents:
422
diff
changeset
|
807 |
unsigned int sdo_count, entry_count; |
862ff892cf18
Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents:
422
diff
changeset
|
808 |
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
|
809 |
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
|
810 |
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
|
811 |
} |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
812 |
|
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
813 |
// restart master state machine. |
528
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
814 |
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
|
815 |
fsm->state(fsm); // execute immediately |
269 | 816 |
} |
817 |
||
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
818 |
/*****************************************************************************/ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
819 |
|
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
820 |
/** |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
821 |
Master state: SDO REQUEST. |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
822 |
*/ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
823 |
|
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
|
824 |
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
|
825 |
{ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
826 |
ec_master_t *master = fsm->master; |
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
827 |
ec_sdo_request_t *request = fsm->sdo_request; |
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
828 |
|
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
829 |
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
|
830 |
|
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
831 |
if (!ec_fsm_coe_success(&fsm->fsm_coe)) { |
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
832 |
request->return_code = -1; |
441
ffa13db95e10
SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents:
437
diff
changeset
|
833 |
master->sdo_seq_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
|
834 |
fsm->state = ec_fsm_master_state_error; |
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
835 |
return; |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
836 |
} |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
837 |
|
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
838 |
// SDO dictionary fetching finished |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
839 |
|
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
840 |
request->return_code = 1; |
441
ffa13db95e10
SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents:
437
diff
changeset
|
841 |
master->sdo_seq_master++; |
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
842 |
|
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
843 |
// restart master state machine. |
528
f789bdd78b54
Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents:
523
diff
changeset
|
844 |
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
|
845 |
fsm->state(fsm); // execute immediately |
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
846 |
} |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
847 |
|
446 | 848 |
/*****************************************************************************/ |
849 |
||
850 |
/** |
|
851 |
State: ERROR. |
|
852 |
*/ |
|
853 |
||
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
|
854 |
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
|
855 |
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
|
856 |
) |
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
|
857 |
{ |
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
|
858 |
fsm->state = ec_fsm_master_state_start; |
446 | 859 |
} |
860 |
||
861 |
/*****************************************************************************/ |
|
862 |
||
863 |
/** |
|
864 |
State: END. |
|
865 |
*/ |
|
866 |
||
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
|
867 |
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
|
868 |
{ |
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
|
869 |
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
|
870 |
} |
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
|
871 |
|
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
|
872 |
/*****************************************************************************/ |
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
|
873 |