author | Florian Pose <fp@igh-essen.com> |
Thu, 02 Nov 2006 14:20:24 +0000 | |
changeset 472 | bd2e0f220289 |
parent 470 | 4ec31555832b |
child 475 | e712a42446af |
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 "fsm.h" |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
43 |
#include "master.h" |
329
d004349777fc
SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
44 |
#include "mailbox.h" |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
45 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
46 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
47 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
48 |
void ec_fsm_master_start(ec_fsm_t *); |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
49 |
void ec_fsm_master_broadcast(ec_fsm_t *); |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
50 |
void ec_fsm_master_read_states(ec_fsm_t *); |
454
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
51 |
void ec_fsm_master_acknowledge(ec_fsm_t *); |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
52 |
void ec_fsm_master_validate_vendor(ec_fsm_t *); |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
53 |
void ec_fsm_master_validate_product(ec_fsm_t *); |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
54 |
void ec_fsm_master_rewrite_addresses(ec_fsm_t *); |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
55 |
void ec_fsm_master_configure_slave(ec_fsm_t *); |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
56 |
void ec_fsm_master_scan_slaves(ec_fsm_t *); |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
57 |
void ec_fsm_master_write_eeprom(ec_fsm_t *); |
419
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
58 |
void ec_fsm_master_sdodict(ec_fsm_t *); |
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
59 |
void ec_fsm_master_sdo_request(ec_fsm_t *); |
446 | 60 |
void ec_fsm_master_end(ec_fsm_t *); |
61 |
void ec_fsm_master_error(ec_fsm_t *); |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
62 |
|
308
d50b139c8601
Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
306
diff
changeset
|
63 |
void ec_fsm_slavescan_start(ec_fsm_t *); |
310
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
64 |
void ec_fsm_slavescan_address(ec_fsm_t *); |
308
d50b139c8601
Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
306
diff
changeset
|
65 |
void ec_fsm_slavescan_state(ec_fsm_t *); |
d50b139c8601
Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
306
diff
changeset
|
66 |
void ec_fsm_slavescan_base(ec_fsm_t *); |
d50b139c8601
Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
306
diff
changeset
|
67 |
void ec_fsm_slavescan_datalink(ec_fsm_t *); |
d50b139c8601
Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
306
diff
changeset
|
68 |
void ec_fsm_slavescan_eeprom_size(ec_fsm_t *); |
d50b139c8601
Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
306
diff
changeset
|
69 |
void ec_fsm_slavescan_eeprom_data(ec_fsm_t *); |
d50b139c8601
Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
306
diff
changeset
|
70 |
|
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
71 |
void ec_fsm_slaveconf_state_start(ec_fsm_t *); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
72 |
void ec_fsm_slaveconf_state_init(ec_fsm_t *); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
73 |
void ec_fsm_slaveconf_state_clear_fmmus(ec_fsm_t *); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
74 |
void ec_fsm_slaveconf_state_sync(ec_fsm_t *); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
75 |
void ec_fsm_slaveconf_state_preop(ec_fsm_t *); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
76 |
void ec_fsm_slaveconf_state_fmmu(ec_fsm_t *); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
77 |
void ec_fsm_slaveconf_state_sdoconf(ec_fsm_t *); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
78 |
void ec_fsm_slaveconf_state_saveop(ec_fsm_t *); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
79 |
void ec_fsm_slaveconf_state_op(ec_fsm_t *); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
80 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
81 |
void ec_fsm_slaveconf_enter_sync(ec_fsm_t *); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
82 |
void ec_fsm_slaveconf_enter_preop(ec_fsm_t *); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
83 |
void ec_fsm_slaveconf_enter_sdoconf(ec_fsm_t *); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
84 |
void ec_fsm_slaveconf_enter_saveop(ec_fsm_t *); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
85 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
86 |
void ec_fsm_slave_state_end(ec_fsm_t *); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
87 |
void ec_fsm_slave_state_error(ec_fsm_t *); |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
88 |
|
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
89 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
90 |
|
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
91 |
/** |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
92 |
Constructor. |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
93 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
94 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
95 |
int ec_fsm_init(ec_fsm_t *fsm, /**< finite state machine */ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
96 |
ec_master_t *master /**< EtherCAT master */ |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
97 |
) |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
98 |
{ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
99 |
fsm->master = master; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
100 |
fsm->master_state = ec_fsm_master_start; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
101 |
fsm->master_slaves_responding = 0; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
102 |
fsm->master_slave_states = EC_SLAVE_STATE_UNKNOWN; |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
103 |
fsm->master_validation = 0; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
104 |
|
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
105 |
ec_datagram_init(&fsm->datagram); |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
106 |
if (ec_datagram_prealloc(&fsm->datagram, EC_MAX_DATA_SIZE)) { |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
107 |
EC_ERR("Failed to allocate FSM datagram.\n"); |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
108 |
return -1; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
109 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
110 |
|
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
111 |
// init sub-state-machines |
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
112 |
ec_fsm_sii_init(&fsm->fsm_sii, &fsm->datagram); |
434
0180d8277311
Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents:
433
diff
changeset
|
113 |
ec_fsm_change_init(&fsm->fsm_change, &fsm->datagram); |
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
114 |
ec_fsm_coe_init(&fsm->fsm_coe, &fsm->datagram); |
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
115 |
|
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
116 |
return 0; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
117 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
118 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
119 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
120 |
|
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
121 |
/** |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
122 |
Destructor. |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
123 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
124 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
125 |
void ec_fsm_clear(ec_fsm_t *fsm /**< finite state machine */) |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
126 |
{ |
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
127 |
// clear sub-state machines |
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
128 |
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
|
129 |
ec_fsm_change_clear(&fsm->fsm_change); |
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
130 |
ec_fsm_coe_clear(&fsm->fsm_coe); |
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
131 |
|
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
132 |
ec_datagram_clear(&fsm->datagram); |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
133 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
134 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
135 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
136 |
|
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
137 |
/** |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
138 |
Executes the current state of the state machine. |
435
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
434
diff
changeset
|
139 |
\return false, if state machine has terminated |
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
434
diff
changeset
|
140 |
*/ |
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
434
diff
changeset
|
141 |
|
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
434
diff
changeset
|
142 |
int ec_fsm_exec(ec_fsm_t *fsm /**< finite state machine */) |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
143 |
{ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
144 |
fsm->master_state(fsm); |
435
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
434
diff
changeset
|
145 |
|
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
|
146 |
return ec_fsm_running(fsm); |
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
|
147 |
} |
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
|
148 |
|
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
|
149 |
/*****************************************************************************/ |
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
|
150 |
|
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
|
151 |
/** |
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
|
152 |
\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
|
153 |
*/ |
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
|
154 |
|
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
|
155 |
int ec_fsm_running(ec_fsm_t *fsm /**< finite state machine */) |
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
|
156 |
{ |
446 | 157 |
return fsm->master_state != ec_fsm_master_end |
158 |
&& fsm->master_state != ec_fsm_master_error; |
|
159 |
} |
|
160 |
||
161 |
/*****************************************************************************/ |
|
162 |
||
163 |
/** |
|
164 |
\return true, if the master state machine terminated gracefully |
|
165 |
*/ |
|
166 |
||
167 |
int ec_fsm_success(ec_fsm_t *fsm /**< finite state machine */) |
|
168 |
{ |
|
169 |
return fsm->master_state == ec_fsm_master_end; |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
170 |
} |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
171 |
|
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
172 |
/****************************************************************************** |
446 | 173 |
* operation/idle state machine |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
174 |
*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
175 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
176 |
/** |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
177 |
Master state: START. |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
178 |
Starts with getting slave count and slave states. |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
179 |
*/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
180 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
181 |
void ec_fsm_master_start(ec_fsm_t *fsm) |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
182 |
{ |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
183 |
ec_datagram_brd(&fsm->datagram, 0x0130, 2); |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
184 |
ec_master_queue_datagram(fsm->master, &fsm->datagram); |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
185 |
fsm->master_state = ec_fsm_master_broadcast; |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
186 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
187 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
188 |
/*****************************************************************************/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
189 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
190 |
/** |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
191 |
Master state: BROADCAST. |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
192 |
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
|
193 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
194 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
195 |
void ec_fsm_master_broadcast(ec_fsm_t *fsm /**< finite state machine */) |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
196 |
{ |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
197 |
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
|
198 |
unsigned int topology_change, states_change, i; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
199 |
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
|
200 |
ec_master_t *master = fsm->master; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
201 |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
202 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
203 |
if (!master->device->link_state) { |
254
986afccca9ea
Link down treated as topology change in state machine.
Florian Pose <fp@igh-essen.com>
parents:
251
diff
changeset
|
204 |
fsm->master_slaves_responding = 0; |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
205 |
list_for_each_entry(slave, &master->slaves, list) { |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
206 |
slave->online = 0; |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
207 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
208 |
} |
446 | 209 |
else { |
210 |
EC_ERR("Failed to receive broadcast datagram.\n"); |
|
211 |
} |
|
212 |
fsm->master_state = ec_fsm_master_error; |
|
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
213 |
return; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
214 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
215 |
|
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
216 |
topology_change = (datagram->working_counter != |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
217 |
fsm->master_slaves_responding); |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
218 |
states_change = (EC_READ_U8(datagram->data) != fsm->master_slave_states); |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
219 |
|
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
220 |
fsm->master_slave_states = EC_READ_U8(datagram->data); |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
221 |
fsm->master_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
|
222 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
223 |
if (topology_change) { |
262
636d43737371
Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents:
260
diff
changeset
|
224 |
EC_INFO("%i slave%s responding.\n", |
636d43737371
Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents:
260
diff
changeset
|
225 |
fsm->master_slaves_responding, |
636d43737371
Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents:
260
diff
changeset
|
226 |
fsm->master_slaves_responding == 1 ? "" : "s"); |
636d43737371
Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents:
260
diff
changeset
|
227 |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
228 |
if (master->mode == EC_MASTER_MODE_OPERATION) { |
262
636d43737371
Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents:
260
diff
changeset
|
229 |
if (fsm->master_slaves_responding == master->slave_count) { |
636d43737371
Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents:
260
diff
changeset
|
230 |
fsm->master_validation = 1; // start validation later |
636d43737371
Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents:
260
diff
changeset
|
231 |
} |
636d43737371
Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents:
260
diff
changeset
|
232 |
else { |
636d43737371
Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents:
260
diff
changeset
|
233 |
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
|
234 |
} |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
235 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
236 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
237 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
238 |
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
|
239 |
char states[EC_STATE_STRING_SIZE]; |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
240 |
ec_state_string(fsm->master_slave_states, states); |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
241 |
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
|
242 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
243 |
|
306
45886de3db87
Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents:
304
diff
changeset
|
244 |
// 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
|
245 |
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
|
246 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
247 |
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
|
248 |
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
|
249 |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
250 |
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
|
251 |
|
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
252 |
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
|
253 |
// no slaves present -> finish state machine. |
446 | 254 |
fsm->master_state = ec_fsm_master_end; |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
255 |
return; |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
256 |
} |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
257 |
|
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
258 |
// init slaves |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
259 |
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
|
260 |
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
|
261 |
GFP_ATOMIC))) { |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
262 |
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
|
263 |
ec_master_destroy_slaves(master); |
446 | 264 |
fsm->master_state = ec_fsm_master_error; |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
265 |
return; |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
266 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
267 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
268 |
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
|
269 |
// 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
|
270 |
ec_master_destroy_slaves(master); |
446 | 271 |
fsm->master_state = ec_fsm_master_error; |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
272 |
return; |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
273 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
274 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
275 |
if (kobject_add(&slave->kobj)) { |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
276 |
EC_ERR("Failed to add kobject.\n"); |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
277 |
kobject_put(&slave->kobj); // free |
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
|
278 |
ec_master_destroy_slaves(master); |
446 | 279 |
fsm->master_state = ec_fsm_master_error; |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
280 |
return; |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
281 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
282 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
283 |
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
|
284 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
285 |
|
446 | 286 |
EC_INFO("Scanning bus.\n"); |
287 |
||
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
288 |
// begin scanning of slaves |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
289 |
fsm->slave = list_entry(master->slaves.next, ec_slave_t, list); |
308
d50b139c8601
Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
306
diff
changeset
|
290 |
fsm->slave_state = ec_fsm_slavescan_start; |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
291 |
fsm->master_state = ec_fsm_master_scan_slaves; |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
292 |
fsm->master_state(fsm); // execute immediately |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
293 |
return; |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
294 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
295 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
296 |
// 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
|
297 |
fsm->slave = list_entry(master->slaves.next, ec_slave_t, list); |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
298 |
ec_datagram_nprd(&fsm->datagram, fsm->slave->station_address, 0x0130, 2); |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
299 |
ec_master_queue_datagram(master, &fsm->datagram); |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
300 |
fsm->master_state = ec_fsm_master_read_states; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
301 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
302 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
303 |
/*****************************************************************************/ |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
304 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
305 |
/** |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
306 |
Master action: PROC_STATES. |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
307 |
Processes the slave states. |
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 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
310 |
void ec_fsm_master_action_process_states(ec_fsm_t *fsm |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
311 |
/**< finite state machine */ |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
312 |
) |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
313 |
{ |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
314 |
ec_master_t *master = fsm->master; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
315 |
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
|
316 |
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
|
317 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
318 |
// 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
|
319 |
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
|
320 |
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
|
321 |
|| !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
|
322 |
|| slave->requested_state == EC_SLAVE_STATE_UNKNOWN |
2b3ce4f51bd6
Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents:
420
diff
changeset
|
323 |
|| (slave->current_state == slave->requested_state |
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
|
324 |
&& slave->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
|
325 |
|
446 | 326 |
if (master->debug_level) { |
327 |
ec_state_string(slave->current_state, old_state); |
|
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
|
328 |
if (slave->current_state != slave->requested_state) { |
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
|
329 |
ec_state_string(slave->requested_state, new_state); |
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
|
330 |
EC_DBG("Changing state of slave %i (%s -> %s).\n", |
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
|
331 |
slave->ring_position, old_state, new_state); |
446 | 332 |
} |
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
|
333 |
else if (!slave->configured) { |
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
|
334 |
EC_DBG("Reconfiguring slave %i (%s).\n", |
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
|
335 |
slave->ring_position, old_state); |
446 | 336 |
} |
421
2b3ce4f51bd6
Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents:
420
diff
changeset
|
337 |
} |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
338 |
|
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
|
339 |
fsm->master_state = ec_fsm_master_configure_slave; |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
340 |
fsm->slave = slave; |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
341 |
fsm->slave_state = ec_fsm_slaveconf_state_start; |
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
|
342 |
fsm->slave_state(fsm); // execute immediately |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
343 |
return; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
344 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
345 |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
346 |
// 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
|
347 |
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
|
348 |
|
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
|
349 |
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
|
350 |
|
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 |
// 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
|
352 |
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
|
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("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
|
355 |
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
|
356 |
if (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
|
357 |
|| !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
|
358 |
|| slave->error_flag) { |
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 |
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
|
360 |
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
|
361 |
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
|
362 |
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
|
363 |
} |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
364 |
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
|
365 |
// 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
|
366 |
fsm->slave = 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
|
367 |
fsm->master_state = ec_fsm_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
|
368 |
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
|
369 |
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
|
370 |
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
|
371 |
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
|
372 |
} |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
373 |
} |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
374 |
|
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
375 |
// 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
|
376 |
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
|
377 |
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
|
378 |
|| 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
|
379 |
|| 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
|
380 |
|| 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
|
381 |
|| !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
|
382 |
|| 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
|
383 |
|
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
384 |
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
|
385 |
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
|
386 |
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
|
387 |
} |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
388 |
|
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
389 |
if (kobject_add(&slave->sdo_kobj)) { |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
390 |
EC_ERR("Failed to add SDO kobj of 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
|
391 |
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
|
392 |
slave->error_flag = 1; |
446 | 393 |
fsm->master_state = ec_fsm_master_error; |
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
|
394 |
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
|
395 |
} |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
396 |
|
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
397 |
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
|
398 |
|
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
399 |
// 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
|
400 |
fsm->slave = slave; |
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
|
401 |
fsm->master_state = ec_fsm_master_sdodict; |
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
402 |
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
|
403 |
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
|
404 |
return; |
ffa13db95e10
SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents:
437
diff
changeset
|
405 |
} |
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
|
406 |
|
6607875255d9
SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents:
441
diff
changeset
|
407 |
// check for pending EEPROM write operations. |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
408 |
list_for_each_entry(slave, &master->slaves, list) { |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
409 |
if (!slave->new_eeprom_data) continue; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
410 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
411 |
if (!slave->online || slave->error_flag) { |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
412 |
kfree(slave->new_eeprom_data); |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
413 |
slave->new_eeprom_data = NULL; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
414 |
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
|
415 |
slave->ring_position); |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
416 |
continue; |
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 |
// found pending EEPROM write operation. execute it! |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
420 |
EC_INFO("Writing EEPROM of slave %i...\n", slave->ring_position); |
470 | 421 |
fsm->slave = slave; |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
422 |
fsm->sii_offset = 0x0000; |
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
423 |
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
|
424 |
slave->new_eeprom_data, EC_FSM_SII_NODE); |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
425 |
fsm->master_state = ec_fsm_master_write_eeprom; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
426 |
fsm->master_state(fsm); // execute immediately |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
427 |
return; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
428 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
429 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
430 |
|
446 | 431 |
fsm->master_state = ec_fsm_master_end; |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
432 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
433 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
434 |
/*****************************************************************************/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
435 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
436 |
/** |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
437 |
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
|
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 |
void ec_fsm_master_action_next_slave_state(ec_fsm_t *fsm |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
441 |
/**< finite state machine */) |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
442 |
{ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
443 |
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
|
444 |
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
|
445 |
|
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
446 |
// 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
|
447 |
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
|
448 |
// process next slave |
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
449 |
fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list); |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
450 |
ec_datagram_nprd(&fsm->datagram, fsm->slave->station_address, |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
451 |
0x0130, 2); |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
452 |
ec_master_queue_datagram(master, &fsm->datagram); |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
453 |
fsm->master_state = ec_fsm_master_read_states; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
454 |
return; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
455 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
456 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
457 |
// all slave states read |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
458 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
459 |
// check, if a bus validation has to be done |
292
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
460 |
if (fsm->master_validation) { |
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
461 |
fsm->master_validation = 0; |
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
462 |
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
|
463 |
if (slave->online) continue; |
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
464 |
|
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
465 |
// 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
|
466 |
EC_INFO("Validating bus.\n"); |
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
467 |
fsm->slave = list_entry(master->slaves.next, ec_slave_t, list); |
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
468 |
fsm->master_state = ec_fsm_master_validate_vendor; |
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
469 |
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
|
470 |
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
|
471 |
return; |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
472 |
} |
292
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
473 |
} |
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
474 |
|
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
475 |
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
|
476 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
477 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
478 |
/*****************************************************************************/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
479 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
480 |
/** |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
481 |
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
|
482 |
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
|
483 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
484 |
|
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
485 |
void ec_fsm_master_read_states(ec_fsm_t *fsm /**< finite state machine */) |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
486 |
{ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
487 |
ec_slave_t *slave = fsm->slave; |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
488 |
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
|
489 |
uint8_t new_state; |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
490 |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
491 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
446 | 492 |
EC_ERR("Failed to receive AL state datagram for slave %i!\n", |
493 |
slave->ring_position); |
|
494 |
fsm->master_state = ec_fsm_master_error; |
|
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
495 |
return; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
496 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
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 |
// 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
|
499 |
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
|
500 |
if (slave->online) { |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
501 |
slave->online = 0; |
461
b9eda9235173
Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
459
diff
changeset
|
502 |
if (slave->master->debug_level) |
459
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
456
diff
changeset
|
503 |
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
|
504 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
505 |
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
|
506 |
return; |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
507 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
508 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
509 |
// slave responded |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
510 |
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
|
511 |
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
|
512 |
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
|
513 |
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
|
514 |
slave->current_state = new_state; |
461
b9eda9235173
Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
459
diff
changeset
|
515 |
if (slave->master->debug_level) { |
459
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
456
diff
changeset
|
516 |
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
|
517 |
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
|
518 |
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
|
519 |
slave->ring_position, cur_state); |
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
456
diff
changeset
|
520 |
} |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
521 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
522 |
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
|
523 |
if (slave->master->debug_level) { |
459
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
456
diff
changeset
|
524 |
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
|
525 |
cur_state[EC_STATE_STRING_SIZE]; |
f0da52cf6b5b
Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
456
diff
changeset
|
526 |
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
|
527 |
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
|
528 |
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
|
529 |
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
|
530 |
} |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
531 |
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
|
532 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
533 |
|
454
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
534 |
// 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
|
535 |
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
|
536 |
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
|
537 |
ec_fsm_change_exec(&fsm->fsm_change); |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
538 |
fsm->master_state = ec_fsm_master_acknowledge; |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
539 |
return; |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
540 |
} |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
541 |
|
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
542 |
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
|
543 |
} |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
544 |
|
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
545 |
/*****************************************************************************/ |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
546 |
|
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
547 |
/** |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
548 |
Master state: ACKNOWLEDGE |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
549 |
*/ |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
550 |
|
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
551 |
void ec_fsm_master_acknowledge(ec_fsm_t *fsm /**< finite state machine */) |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
552 |
{ |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
553 |
ec_slave_t *slave = fsm->slave; |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
554 |
|
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
555 |
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
|
556 |
|
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
557 |
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
|
558 |
fsm->slave->error_flag = 1; |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
559 |
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
|
560 |
slave->ring_position); |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
561 |
fsm->master_state = ec_fsm_master_error; |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
562 |
return; |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
563 |
} |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
564 |
|
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
565 |
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
|
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 |
/** |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
571 |
Master state: VALIDATE_VENDOR. |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
572 |
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
|
573 |
*/ |
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 |
void ec_fsm_master_validate_vendor(ec_fsm_t *fsm /**< finite state machine */) |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
576 |
{ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
577 |
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
|
578 |
|
435
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
434
diff
changeset
|
579 |
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
|
580 |
|
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
581 |
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
|
582 |
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
|
583 |
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
|
584 |
slave->ring_position); |
446 | 585 |
fsm->master_state = ec_fsm_master_error; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
586 |
return; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
587 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
588 |
|
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
589 |
if (EC_READ_U32(fsm->fsm_sii.value) != slave->sii_vendor_id) { |
446 | 590 |
EC_ERR("Slave %i has an invalid vendor ID!\n", slave->ring_position); |
591 |
fsm->master_state = ec_fsm_master_error; |
|
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
592 |
return; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
593 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
594 |
|
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
595 |
// vendor ID is ok. check product code. |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
596 |
fsm->master_state = ec_fsm_master_validate_product; |
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
597 |
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
|
598 |
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
|
599 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
600 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
601 |
/*****************************************************************************/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
602 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
603 |
/** |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
604 |
Master action: ADDRESS. |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
605 |
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
|
606 |
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
|
607 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
608 |
|
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
609 |
void ec_fsm_master_action_addresses(ec_fsm_t *fsm /**< finite state machine */) |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
610 |
{ |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
611 |
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
|
612 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
613 |
while (fsm->slave->online) { |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
614 |
if (fsm->slave->list.next == &fsm->master->slaves) { // last slave? |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
615 |
fsm->master_state = ec_fsm_master_start; |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
616 |
fsm->master_state(fsm); // execute immediately |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
617 |
return; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
618 |
} |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
619 |
// check next slave |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
620 |
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
|
621 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
622 |
|
446 | 623 |
if (fsm->master->debug_level) |
624 |
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
|
625 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
626 |
// write station address |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
627 |
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
|
628 |
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
|
629 |
ec_master_queue_datagram(fsm->master, datagram); |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
630 |
fsm->master_state = ec_fsm_master_rewrite_addresses; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
631 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
632 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
633 |
/*****************************************************************************/ |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
634 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
635 |
/** |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
636 |
Master state: VALIDATE_PRODUCT. |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
637 |
Validates the product ID of a slave. |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
638 |
*/ |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
639 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
640 |
void ec_fsm_master_validate_product(ec_fsm_t *fsm /**< finite state machine */) |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
641 |
{ |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
642 |
ec_slave_t *slave = fsm->slave; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
643 |
|
435
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
434
diff
changeset
|
644 |
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
|
645 |
|
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
646 |
if (!ec_fsm_sii_success(&fsm->fsm_sii)) { |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
647 |
fsm->slave->error_flag = 1; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
648 |
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
|
649 |
slave->ring_position); |
446 | 650 |
fsm->master_state = ec_fsm_master_error; |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
651 |
return; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
652 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
653 |
|
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
654 |
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
|
655 |
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
|
656 |
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
|
657 |
EC_READ_U32(fsm->fsm_sii.value)); |
446 | 658 |
fsm->master_state = ec_fsm_master_error; |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
659 |
return; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
660 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
661 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
662 |
// have all states been validated? |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
663 |
if (slave->list.next == &fsm->master->slaves) { |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
664 |
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
|
665 |
// start writing addresses to offline slaves |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
666 |
ec_fsm_master_action_addresses(fsm); |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
667 |
return; |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
668 |
} |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
669 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
670 |
// validate next slave |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
671 |
fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list); |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
672 |
fsm->master_state = ec_fsm_master_validate_vendor; |
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
673 |
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
|
674 |
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
|
675 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
676 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
677 |
/*****************************************************************************/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
678 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
679 |
/** |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
680 |
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
|
681 |
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
|
682 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
683 |
|
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
684 |
void ec_fsm_master_rewrite_addresses(ec_fsm_t *fsm |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
685 |
/**< finite state machine */ |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
686 |
) |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
687 |
{ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
688 |
ec_slave_t *slave = fsm->slave; |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
689 |
ec_datagram_t *datagram = &fsm->datagram; |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
690 |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
691 |
if (datagram->state != EC_DATAGRAM_RECEIVED |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
692 |
|| 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
|
693 |
EC_ERR("Failed to write station address on slave %i.\n", |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
694 |
slave->ring_position); |
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 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
697 |
if (fsm->slave->list.next == &fsm->master->slaves) { // last slave? |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
698 |
fsm->master_state = ec_fsm_master_start; |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
699 |
fsm->master_state(fsm); // execute immediately |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
700 |
return; |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
701 |
} |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
702 |
|
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
703 |
// check next slave |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
704 |
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
|
705 |
// Write new station address to slave |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
706 |
ec_fsm_master_action_addresses(fsm); |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
707 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
708 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
709 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
710 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
711 |
/** |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
712 |
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
|
713 |
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
|
714 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
715 |
|
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
716 |
void ec_fsm_master_scan_slaves(ec_fsm_t *fsm /**< finite state machine */) |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
717 |
{ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
718 |
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
|
719 |
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
|
720 |
|
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
721 |
fsm->slave_state(fsm); // execute slave state machine |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
722 |
|
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
723 |
if (fsm->slave_state != ec_fsm_slave_state_end |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
724 |
&& fsm->slave_state != ec_fsm_slave_state_error) return; |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
725 |
|
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
726 |
// another slave to fetch? |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
727 |
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
|
728 |
fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list); |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
729 |
fsm->slave_state = ec_fsm_slavescan_start; |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
730 |
fsm->slave_state(fsm); // execute immediately |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
731 |
return; |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
732 |
} |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
733 |
|
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
734 |
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
|
735 |
|
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
736 |
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
|
737 |
|
428
2731a2fcc18d
Set initial state of all slaves to PREOP.
Florian Pose <fp@igh-essen.com>
parents:
427
diff
changeset
|
738 |
// 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
|
739 |
// communication possible |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
740 |
list_for_each_entry(slave, &master->slaves, list) { |
446 | 741 |
ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP); |
742 |
} |
|
743 |
||
744 |
fsm->master_state = ec_fsm_master_end; |
|
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
745 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
746 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
747 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
748 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
749 |
/** |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
750 |
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
|
751 |
Starts configuring a slave. |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
752 |
*/ |
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
753 |
|
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
754 |
void ec_fsm_master_configure_slave(ec_fsm_t *fsm |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
755 |
/**< finite state machine */ |
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
756 |
) |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
757 |
{ |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
758 |
fsm->slave_state(fsm); // execute slave's state machine |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
759 |
|
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
760 |
if (fsm->slave_state != ec_fsm_slave_state_end |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
761 |
&& fsm->slave_state != ec_fsm_slave_state_error) return; |
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
762 |
|
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
763 |
ec_fsm_master_action_process_states(fsm); |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
764 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
765 |
|
269 | 766 |
/*****************************************************************************/ |
767 |
||
768 |
/** |
|
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
769 |
Master state: WRITE EEPROM. |
269 | 770 |
*/ |
771 |
||
304
558a6669da90
Better master state machines.
Florian Pose <fp@igh-essen.com>
parents:
301
diff
changeset
|
772 |
void ec_fsm_master_write_eeprom(ec_fsm_t *fsm /**< finite state machine */) |
269 | 773 |
{ |
774 |
ec_slave_t *slave = fsm->slave; |
|
775 |
||
435
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
434
diff
changeset
|
776 |
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
|
777 |
|
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
778 |
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
|
779 |
fsm->slave->error_flag = 1; |
269 | 780 |
EC_ERR("Failed to write EEPROM contents to slave %i.\n", |
781 |
slave->ring_position); |
|
782 |
kfree(slave->new_eeprom_data); |
|
783 |
slave->new_eeprom_data = NULL; |
|
446 | 784 |
fsm->master_state = ec_fsm_master_error; |
269 | 785 |
return; |
786 |
} |
|
787 |
||
788 |
fsm->sii_offset++; |
|
789 |
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
|
790 |
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
|
791 |
slave->new_eeprom_data + fsm->sii_offset, |
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
792 |
EC_FSM_SII_NODE); |
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
793 |
ec_fsm_sii_exec(&fsm->fsm_sii); // execute immediately |
269 | 794 |
return; |
795 |
} |
|
796 |
||
797 |
// finished writing EEPROM |
|
798 |
EC_INFO("Finished writing EEPROM of slave %i.\n", slave->ring_position); |
|
799 |
kfree(slave->new_eeprom_data); |
|
800 |
slave->new_eeprom_data = NULL; |
|
801 |
||
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
802 |
// 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
|
803 |
|
269 | 804 |
// restart master state machine. |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
805 |
fsm->master_state = ec_fsm_master_start; |
269 | 806 |
fsm->master_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
|
807 |
} |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
808 |
|
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
809 |
/*****************************************************************************/ |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
810 |
|
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 |
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
|
813 |
*/ |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
814 |
|
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
815 |
void ec_fsm_master_sdodict(ec_fsm_t *fsm /**< finite state machine */) |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
816 |
{ |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
817 |
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
|
818 |
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
|
819 |
|
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
820 |
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
|
821 |
|
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
822 |
if (!ec_fsm_coe_success(&fsm->fsm_coe)) { |
446 | 823 |
fsm->master_state = ec_fsm_master_error; |
419
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
824 |
return; |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
825 |
} |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
826 |
|
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
827 |
// 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
|
828 |
|
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
829 |
if (master->debug_level) { |
423
862ff892cf18
Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents:
422
diff
changeset
|
830 |
unsigned int sdo_count, entry_count; |
862ff892cf18
Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents:
422
diff
changeset
|
831 |
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
|
832 |
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
|
833 |
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
|
834 |
} |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
835 |
|
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
836 |
// restart master state machine. |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
837 |
fsm->master_state = ec_fsm_master_start; |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
838 |
fsm->master_state(fsm); // execute immediately |
269 | 839 |
} |
840 |
||
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
841 |
/*****************************************************************************/ |
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 |
/** |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
844 |
Master state: SDO REQUEST. |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
845 |
*/ |
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 |
void ec_fsm_master_sdo_request(ec_fsm_t *fsm /**< finite state machine */) |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
848 |
{ |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
849 |
ec_master_t *master = fsm->master; |
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
850 |
ec_sdo_request_t *request = fsm->sdo_request; |
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
851 |
|
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
852 |
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
|
853 |
|
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
854 |
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
|
855 |
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
|
856 |
master->sdo_seq_master++; |
446 | 857 |
fsm->master_state = ec_fsm_master_error; |
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
858 |
return; |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
859 |
} |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
860 |
|
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
861 |
// SDO dictionary fetching finished |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
862 |
|
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
863 |
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
|
864 |
master->sdo_seq_master++; |
430
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
865 |
|
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
866 |
// restart master state machine. |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
867 |
fsm->master_state = ec_fsm_master_start; |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
868 |
fsm->master_state(fsm); // execute immediately |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
869 |
} |
74754f45d5fa
Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents:
429
diff
changeset
|
870 |
|
446 | 871 |
/*****************************************************************************/ |
872 |
||
873 |
/** |
|
874 |
State: ERROR. |
|
875 |
*/ |
|
876 |
||
877 |
void ec_fsm_master_error(ec_fsm_t *fsm /**< finite state machine */) |
|
878 |
{ |
|
879 |
fsm->master_state = ec_fsm_master_start; |
|
880 |
} |
|
881 |
||
882 |
/*****************************************************************************/ |
|
883 |
||
884 |
/** |
|
885 |
State: END. |
|
886 |
*/ |
|
887 |
||
888 |
void ec_fsm_master_end(ec_fsm_t *fsm /**< finite state machine */) |
|
889 |
{ |
|
890 |
fsm->master_state = ec_fsm_master_start; |
|
891 |
} |
|
892 |
||
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
893 |
/****************************************************************************** |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
894 |
* slave scan state machine |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
895 |
*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
896 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
897 |
/** |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
898 |
Slave scan state: START. |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
899 |
First state of the slave state machine. Writes the station address to the |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
900 |
slave, according to its ring position. |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
901 |
*/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
902 |
|
308
d50b139c8601
Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
306
diff
changeset
|
903 |
void ec_fsm_slavescan_start(ec_fsm_t *fsm /**< finite state machine */) |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
904 |
{ |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
905 |
ec_datagram_t *datagram = &fsm->datagram; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
906 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
907 |
// write station address |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
908 |
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
|
909 |
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
|
910 |
ec_master_queue_datagram(fsm->master, datagram); |
310
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
911 |
fsm->slave_state = ec_fsm_slavescan_address; |
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
912 |
} |
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
913 |
|
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
914 |
/*****************************************************************************/ |
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
915 |
|
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
916 |
/** |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
917 |
Slave scan state: ADDRESS. |
310
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
918 |
*/ |
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
919 |
|
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
920 |
void ec_fsm_slavescan_address(ec_fsm_t *fsm /**< finite state machine */) |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
921 |
{ |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
922 |
ec_datagram_t *datagram = &fsm->datagram; |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
923 |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
924 |
if (datagram->state != EC_DATAGRAM_RECEIVED |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
925 |
|| datagram->working_counter != 1) { |
292
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
926 |
fsm->slave->error_flag = 1; |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
927 |
fsm->slave_state = ec_fsm_slave_state_error; |
292
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
928 |
EC_ERR("Failed to write station address of slave %i.\n", |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
929 |
fsm->slave->ring_position); |
292
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
930 |
return; |
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
931 |
} |
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
932 |
|
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
933 |
// Read AL state |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
934 |
ec_datagram_nprd(datagram, fsm->slave->station_address, 0x0130, 2); |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
935 |
ec_master_queue_datagram(fsm->master, datagram); |
310
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
936 |
fsm->slave_state = ec_fsm_slavescan_state; |
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
937 |
} |
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
938 |
|
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
939 |
/*****************************************************************************/ |
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
940 |
|
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
941 |
/** |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
942 |
Slave scan state: STATE. |
310
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
943 |
*/ |
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
944 |
|
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
945 |
void ec_fsm_slavescan_state(ec_fsm_t *fsm /**< finite state machine */) |
255
6b916cce7f27
Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents:
254
diff
changeset
|
946 |
{ |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
947 |
ec_datagram_t *datagram = &fsm->datagram; |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
948 |
ec_slave_t *slave = fsm->slave; |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
949 |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
950 |
if (datagram->state != EC_DATAGRAM_RECEIVED |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
951 |
|| datagram->working_counter != 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
|
952 |
fsm->slave->error_flag = 1; |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
953 |
fsm->slave_state = ec_fsm_slave_state_error; |
292
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
954 |
EC_ERR("Failed to read AL state of slave %i.\n", |
255
6b916cce7f27
Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents:
254
diff
changeset
|
955 |
fsm->slave->ring_position); |
6b916cce7f27
Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents:
254
diff
changeset
|
956 |
return; |
6b916cce7f27
Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents:
254
diff
changeset
|
957 |
} |
6b916cce7f27
Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents:
254
diff
changeset
|
958 |
|
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
959 |
slave->current_state = EC_READ_U8(datagram->data); |
402
03e31ac14047
Renamed EC_ACK to EC_SLAVE_STATE_ACK_ERR
Florian Pose <fp@igh-essen.com>
parents:
398
diff
changeset
|
960 |
if (slave->current_state & EC_SLAVE_STATE_ACK_ERR) { |
454
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
961 |
char state_str[EC_STATE_STRING_SIZE]; |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
962 |
ec_state_string(slave->current_state, state_str); |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
963 |
EC_WARN("Slave %i has state error bit set (%s)!\n", |
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
964 |
slave->ring_position, state_str); |
255
6b916cce7f27
Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents:
254
diff
changeset
|
965 |
} |
6b916cce7f27
Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents:
254
diff
changeset
|
966 |
|
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
967 |
// read base data |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
968 |
ec_datagram_nprd(datagram, fsm->slave->station_address, 0x0000, 6); |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
969 |
ec_master_queue_datagram(fsm->master, datagram); |
310
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
970 |
fsm->slave_state = ec_fsm_slavescan_base; |
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
971 |
} |
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
972 |
|
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
973 |
/*****************************************************************************/ |
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
974 |
|
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
975 |
/** |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
976 |
Slave scan state: BASE. |
310
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
977 |
*/ |
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
978 |
|
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
979 |
void ec_fsm_slavescan_base(ec_fsm_t *fsm /**< finite state machine */) |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
980 |
{ |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
981 |
ec_datagram_t *datagram = &fsm->datagram; |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
982 |
ec_slave_t *slave = fsm->slave; |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
983 |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
984 |
if (datagram->state != EC_DATAGRAM_RECEIVED |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
985 |
|| datagram->working_counter != 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
|
986 |
fsm->slave->error_flag = 1; |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
987 |
fsm->slave_state = ec_fsm_slave_state_error; |
292
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
988 |
EC_ERR("Failed to read base data of slave %i.\n", |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
989 |
slave->ring_position); |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
990 |
return; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
991 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
992 |
|
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
993 |
slave->base_type = EC_READ_U8 (datagram->data); |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
994 |
slave->base_revision = EC_READ_U8 (datagram->data + 1); |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
995 |
slave->base_build = EC_READ_U16(datagram->data + 2); |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
996 |
slave->base_fmmu_count = EC_READ_U8 (datagram->data + 4); |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
997 |
slave->base_sync_count = EC_READ_U8 (datagram->data + 5); |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
998 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
999 |
if (slave->base_fmmu_count > EC_MAX_FMMUS) |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1000 |
slave->base_fmmu_count = EC_MAX_FMMUS; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1001 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1002 |
// read data link status |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
1003 |
ec_datagram_nprd(datagram, slave->station_address, 0x0110, 2); |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
1004 |
ec_master_queue_datagram(slave->master, datagram); |
310
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
1005 |
fsm->slave_state = ec_fsm_slavescan_datalink; |
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
1006 |
} |
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
1007 |
|
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
1008 |
/*****************************************************************************/ |
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
1009 |
|
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
1010 |
/** |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1011 |
Slave scan state: DATALINK. |
310
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
1012 |
*/ |
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
1013 |
|
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
1014 |
void ec_fsm_slavescan_datalink(ec_fsm_t *fsm /**< finite state machine */) |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1015 |
{ |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
1016 |
ec_datagram_t *datagram = &fsm->datagram; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1017 |
ec_slave_t *slave = fsm->slave; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1018 |
uint16_t dl_status; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1019 |
unsigned int i; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1020 |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1021 |
if (datagram->state != EC_DATAGRAM_RECEIVED |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1022 |
|| datagram->working_counter != 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
|
1023 |
fsm->slave->error_flag = 1; |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1024 |
fsm->slave_state = ec_fsm_slave_state_error; |
292
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
1025 |
EC_ERR("Failed to read DL status of slave %i.\n", |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1026 |
slave->ring_position); |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1027 |
return; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1028 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1029 |
|
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
1030 |
dl_status = EC_READ_U16(datagram->data); |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1031 |
for (i = 0; i < 4; i++) { |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1032 |
slave->dl_link[i] = dl_status & (1 << (4 + i)) ? 1 : 0; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1033 |
slave->dl_loop[i] = dl_status & (1 << (8 + i * 2)) ? 1 : 0; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1034 |
slave->dl_signal[i] = dl_status & (1 << (9 + i * 2)) ? 1 : 0; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1035 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1036 |
|
266
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1037 |
// Start fetching EEPROM size |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1038 |
|
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1039 |
fsm->sii_offset = 0x0040; // first category header |
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
1040 |
ec_fsm_sii_read(&fsm->fsm_sii, slave, fsm->sii_offset, EC_FSM_SII_NODE); |
310
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
1041 |
fsm->slave_state = ec_fsm_slavescan_eeprom_size; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1042 |
fsm->slave_state(fsm); // execute state immediately |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1043 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1044 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1045 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1046 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1047 |
/** |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1048 |
Slave scan state: EEPROM SIZE. |
310
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
1049 |
*/ |
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
1050 |
|
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
1051 |
void ec_fsm_slavescan_eeprom_size(ec_fsm_t *fsm /**< finite state machine */) |
266
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1052 |
{ |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1053 |
ec_slave_t *slave = fsm->slave; |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1054 |
uint16_t cat_type, cat_size; |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1055 |
|
435
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
434
diff
changeset
|
1056 |
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
|
1057 |
|
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
1058 |
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
|
1059 |
fsm->slave->error_flag = 1; |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1060 |
fsm->slave_state = ec_fsm_slave_state_error; |
266
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1061 |
EC_ERR("Failed to read EEPROM size of slave %i.\n", |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1062 |
slave->ring_position); |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1063 |
return; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1064 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1065 |
|
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
1066 |
cat_type = EC_READ_U16(fsm->fsm_sii.value); |
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
1067 |
cat_size = EC_READ_U16(fsm->fsm_sii.value + 2); |
266
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1068 |
|
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1069 |
if (cat_type != 0xFFFF) { // not the last category |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1070 |
fsm->sii_offset += cat_size + 2; |
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
1071 |
ec_fsm_sii_read(&fsm->fsm_sii, slave, fsm->sii_offset, |
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
1072 |
EC_FSM_SII_NODE); |
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
1073 |
ec_fsm_sii_exec(&fsm->fsm_sii); // execute state immediately |
266
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1074 |
return; |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1075 |
} |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1076 |
|
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1077 |
slave->eeprom_size = (fsm->sii_offset + 1) * 2; |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1078 |
|
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1079 |
if (slave->eeprom_data) { |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1080 |
EC_INFO("Freeing old EEPROM data on slave %i...\n", |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1081 |
slave->ring_position); |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1082 |
kfree(slave->eeprom_data); |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1083 |
} |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1084 |
|
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1085 |
if (!(slave->eeprom_data = |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1086 |
(uint8_t *) kmalloc(slave->eeprom_size, GFP_ATOMIC))) { |
291
0b1f877cf3f1
Slave: state_error -> error_flag, error_flag only in slave state machine.
Florian Pose <fp@igh-essen.com>
parents:
290
diff
changeset
|
1087 |
fsm->slave->error_flag = 1; |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1088 |
fsm->slave_state = ec_fsm_slave_state_error; |
266
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1089 |
EC_ERR("Failed to allocate EEPROM data on slave %i.\n", |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1090 |
slave->ring_position); |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1091 |
return; |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1092 |
} |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1093 |
|
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1094 |
// Start fetching EEPROM contents |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1095 |
|
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
1096 |
fsm->slave_state = ec_fsm_slavescan_eeprom_data; |
266
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1097 |
fsm->sii_offset = 0x0000; |
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
1098 |
ec_fsm_sii_read(&fsm->fsm_sii, slave, fsm->sii_offset, EC_FSM_SII_NODE); |
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
1099 |
ec_fsm_sii_exec(&fsm->fsm_sii); // execute state immediately |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1100 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1101 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1102 |
/*****************************************************************************/ |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1103 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1104 |
/** |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1105 |
Slave scan state: EEPROM DATA. |
310
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
1106 |
*/ |
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
1107 |
|
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
1108 |
void ec_fsm_slavescan_eeprom_data(ec_fsm_t *fsm /**< finite state machine */) |
266
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1109 |
{ |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1110 |
ec_slave_t *slave = fsm->slave; |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1111 |
uint16_t *cat_word, cat_type, cat_size; |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1112 |
|
435
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
434
diff
changeset
|
1113 |
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
|
1114 |
|
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
1115 |
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
|
1116 |
fsm->slave->error_flag = 1; |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1117 |
fsm->slave_state = ec_fsm_slave_state_error; |
266
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1118 |
EC_ERR("Failed to fetch EEPROM contents of slave %i.\n", |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1119 |
slave->ring_position); |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1120 |
return; |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1121 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1122 |
|
266
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1123 |
// 2 words fetched |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1124 |
|
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1125 |
if (fsm->sii_offset + 2 <= slave->eeprom_size / 2) { // 2 words fit |
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
1126 |
memcpy(slave->eeprom_data + fsm->sii_offset * 2, |
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
1127 |
fsm->fsm_sii.value, 4); |
266
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1128 |
} |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1129 |
else { // copy the last word |
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
1130 |
memcpy(slave->eeprom_data + fsm->sii_offset * 2, |
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
1131 |
fsm->fsm_sii.value, 2); |
266
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1132 |
} |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1133 |
|
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1134 |
if (fsm->sii_offset + 2 < slave->eeprom_size / 2) { |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1135 |
// fetch the next 2 words |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1136 |
fsm->sii_offset += 2; |
433
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
1137 |
ec_fsm_sii_read(&fsm->fsm_sii, slave, fsm->sii_offset, |
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
1138 |
EC_FSM_SII_NODE); |
100f51f28cf2
Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents:
430
diff
changeset
|
1139 |
ec_fsm_sii_exec(&fsm->fsm_sii); // execute state immediately |
266
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1140 |
return; |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1141 |
} |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1142 |
|
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1143 |
// Evaluate EEPROM contents |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1144 |
|
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1145 |
slave->sii_alias = |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1146 |
EC_READ_U16(slave->eeprom_data + 2 * 0x0004); |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1147 |
slave->sii_vendor_id = |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1148 |
EC_READ_U32(slave->eeprom_data + 2 * 0x0008); |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1149 |
slave->sii_product_code = |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1150 |
EC_READ_U32(slave->eeprom_data + 2 * 0x000A); |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1151 |
slave->sii_revision_number = |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1152 |
EC_READ_U32(slave->eeprom_data + 2 * 0x000C); |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1153 |
slave->sii_serial_number = |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1154 |
EC_READ_U32(slave->eeprom_data + 2 * 0x000E); |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1155 |
slave->sii_rx_mailbox_offset = |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1156 |
EC_READ_U16(slave->eeprom_data + 2 * 0x0018); |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1157 |
slave->sii_rx_mailbox_size = |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1158 |
EC_READ_U16(slave->eeprom_data + 2 * 0x0019); |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1159 |
slave->sii_tx_mailbox_offset = |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1160 |
EC_READ_U16(slave->eeprom_data + 2 * 0x001A); |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1161 |
slave->sii_tx_mailbox_size = |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1162 |
EC_READ_U16(slave->eeprom_data + 2 * 0x001B); |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1163 |
slave->sii_mailbox_protocols = |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1164 |
EC_READ_U16(slave->eeprom_data + 2 * 0x001C); |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1165 |
|
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1166 |
// evaluate category data |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1167 |
cat_word = (uint16_t *) slave->eeprom_data + 0x0040; |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1168 |
while (EC_READ_U16(cat_word) != 0xFFFF) { |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1169 |
cat_type = EC_READ_U16(cat_word) & 0x7FFF; |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1170 |
cat_size = EC_READ_U16(cat_word + 1); |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1171 |
|
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1172 |
switch (cat_type) { |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1173 |
case 0x000A: |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1174 |
if (ec_slave_fetch_strings(slave, (uint8_t *) (cat_word + 2))) |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1175 |
goto end; |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1176 |
break; |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1177 |
case 0x001E: |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1178 |
ec_slave_fetch_general(slave, (uint8_t *) (cat_word + 2)); |
266
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1179 |
break; |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1180 |
case 0x0028: |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1181 |
break; |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1182 |
case 0x0029: |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1183 |
if (ec_slave_fetch_sync(slave, (uint8_t *) (cat_word + 2), |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1184 |
cat_size)) |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1185 |
goto end; |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1186 |
break; |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1187 |
case 0x0032: |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1188 |
if (ec_slave_fetch_pdo(slave, (uint8_t *) (cat_word + 2), |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1189 |
cat_size, EC_TX_PDO)) |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1190 |
goto end; |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1191 |
break; |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1192 |
case 0x0033: |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1193 |
if (ec_slave_fetch_pdo(slave, (uint8_t *) (cat_word + 2), |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1194 |
cat_size, EC_RX_PDO)) |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1195 |
goto end; |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1196 |
break; |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1197 |
default: |
461
b9eda9235173
Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
459
diff
changeset
|
1198 |
if (fsm->master->debug_level) |
b9eda9235173
Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
459
diff
changeset
|
1199 |
EC_WARN("Unknown category type 0x%04X in slave %i.\n", |
b9eda9235173
Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents:
459
diff
changeset
|
1200 |
cat_type, slave->ring_position); |
266
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1201 |
} |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1202 |
|
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1203 |
cat_word += cat_size + 2; |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1204 |
} |
0234b0c26c52
Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents:
262
diff
changeset
|
1205 |
|
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1206 |
fsm->slave_state = ec_fsm_slave_state_end; |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1207 |
return; |
310
b7e7709fd40e
Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
309
diff
changeset
|
1208 |
|
292
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
1209 |
end: |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1210 |
EC_ERR("Failed to analyze category data.\n"); |
291
0b1f877cf3f1
Slave: state_error -> error_flag, error_flag only in slave state machine.
Florian Pose <fp@igh-essen.com>
parents:
290
diff
changeset
|
1211 |
fsm->slave->error_flag = 1; |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1212 |
fsm->slave_state = ec_fsm_slave_state_error; |
308
d50b139c8601
Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
306
diff
changeset
|
1213 |
} |
d50b139c8601
Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
306
diff
changeset
|
1214 |
|
d50b139c8601
Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
306
diff
changeset
|
1215 |
/****************************************************************************** |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1216 |
* slave configuration state machine |
308
d50b139c8601
Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
306
diff
changeset
|
1217 |
*****************************************************************************/ |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1218 |
|
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1219 |
/** |
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
|
1220 |
Slave configuration state: START. |
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
|
1221 |
*/ |
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
|
1222 |
|
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1223 |
void ec_fsm_slaveconf_state_start(ec_fsm_t *fsm /**< finite state machine */) |
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
|
1224 |
{ |
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
|
1225 |
if (fsm->master->debug_level) { |
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
|
1226 |
EC_DBG("Configuring slave %i...\n", fsm->slave->ring_position); |
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
|
1227 |
} |
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
|
1228 |
|
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
|
1229 |
ec_fsm_change_start(&fsm->fsm_change, fsm->slave, EC_SLAVE_STATE_INIT); |
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
|
1230 |
ec_fsm_change_exec(&fsm->fsm_change); |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1231 |
fsm->slave_state = ec_fsm_slaveconf_state_init; |
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
|
1232 |
} |
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
|
1233 |
|
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
|
1234 |
/*****************************************************************************/ |
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
|
1235 |
|
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
|
1236 |
/** |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1237 |
Slave configuration state: INIT. |
309
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1238 |
*/ |
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1239 |
|
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1240 |
void ec_fsm_slaveconf_state_init(ec_fsm_t *fsm /**< finite state machine */) |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1241 |
{ |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1242 |
ec_master_t *master = fsm->master; |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1243 |
ec_slave_t *slave = fsm->slave; |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1244 |
ec_datagram_t *datagram = &fsm->datagram; |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1245 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1246 |
if (ec_fsm_change_exec(&fsm->fsm_change)) return; |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1247 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1248 |
if (!ec_fsm_change_success(&fsm->fsm_change)) { |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1249 |
slave->error_flag = 1; |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1250 |
fsm->slave_state = ec_fsm_slave_state_error; |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1251 |
return; |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1252 |
} |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1253 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1254 |
slave->configured = 1; |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1255 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1256 |
if (master->debug_level) { |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1257 |
EC_DBG("Slave %i is now in INIT.\n", slave->ring_position); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1258 |
} |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1259 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1260 |
// check and reset CRC fault counters |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1261 |
//ec_slave_check_crc(slave); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1262 |
// TODO: Implement state machine for CRC checking. |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1263 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1264 |
if (!slave->base_fmmu_count) { // skip FMMU configuration |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1265 |
ec_fsm_slaveconf_enter_sync(fsm); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1266 |
return; |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1267 |
} |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1268 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1269 |
if (master->debug_level) |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1270 |
EC_DBG("Clearing FMMU configurations of slave %i...\n", |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1271 |
slave->ring_position); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1272 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1273 |
// clear FMMU configurations |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1274 |
ec_datagram_npwr(datagram, slave->station_address, |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1275 |
0x0600, EC_FMMU_SIZE * slave->base_fmmu_count); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1276 |
memset(datagram->data, 0x00, EC_FMMU_SIZE * slave->base_fmmu_count); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1277 |
ec_master_queue_datagram(master, datagram); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1278 |
fsm->slave_state = ec_fsm_slaveconf_state_clear_fmmus; |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1279 |
} |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1280 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1281 |
/*****************************************************************************/ |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1282 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1283 |
/** |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1284 |
Slave configuration state: CLEAR FMMU. |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1285 |
*/ |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1286 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1287 |
void ec_fsm_slaveconf_state_clear_fmmus(ec_fsm_t *fsm |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1288 |
/**< finite state machine */) |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1289 |
{ |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1290 |
ec_datagram_t *datagram = &fsm->datagram; |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1291 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1292 |
if (datagram->state != EC_DATAGRAM_RECEIVED |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1293 |
|| datagram->working_counter != 1) { |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1294 |
fsm->slave->error_flag = 1; |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1295 |
fsm->slave_state = ec_fsm_slave_state_error; |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1296 |
EC_ERR("Failed to clear FMMUs on slave %i.\n", |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1297 |
fsm->slave->ring_position); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1298 |
return; |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1299 |
} |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1300 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1301 |
ec_fsm_slaveconf_enter_sync(fsm); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1302 |
} |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1303 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1304 |
/*****************************************************************************/ |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1305 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1306 |
/** |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1307 |
*/ |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1308 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1309 |
void ec_fsm_slaveconf_enter_sync(ec_fsm_t *fsm /**< finite state machine */) |
309
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1310 |
{ |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1311 |
ec_master_t *master = fsm->master; |
309
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1312 |
ec_slave_t *slave = fsm->slave; |
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1313 |
ec_datagram_t *datagram = &fsm->datagram; |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1314 |
const ec_sii_sync_t *sync; |
420
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1315 |
ec_sii_sync_t mbox_sync; |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1316 |
|
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1317 |
// slave is now in INIT |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1318 |
if (slave->current_state == slave->requested_state) { |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1319 |
fsm->slave_state = ec_fsm_slave_state_end; // successful |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1320 |
if (master->debug_level) { |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1321 |
EC_DBG("Finished configuration of slave %i.\n", |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1322 |
slave->ring_position); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1323 |
} |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1324 |
return; |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1325 |
} |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1326 |
|
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1327 |
if (!slave->base_sync_count) { // no sync managers |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1328 |
ec_fsm_slaveconf_enter_preop(fsm); |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1329 |
return; |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1330 |
} |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1331 |
|
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1332 |
if (master->debug_level) { |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1333 |
EC_DBG("Configuring sync managers of slave %i.\n", |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1334 |
slave->ring_position); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1335 |
} |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1336 |
|
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1337 |
// configure sync managers |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
1338 |
ec_datagram_npwr(datagram, slave->station_address, 0x0800, |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
1339 |
EC_SYNC_SIZE * slave->base_sync_count); |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
1340 |
memset(datagram->data, 0x00, EC_SYNC_SIZE * slave->base_sync_count); |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1341 |
|
420
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1342 |
if (list_empty(&slave->sii_syncs)) { |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1343 |
if (slave->sii_rx_mailbox_offset && slave->sii_tx_mailbox_offset) { |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1344 |
if (slave->master->debug_level) |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1345 |
EC_DBG("Guessing sync manager settings for slave %i.\n", |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1346 |
slave->ring_position); |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1347 |
mbox_sync.index = 0; |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1348 |
mbox_sync.physical_start_address = slave->sii_tx_mailbox_offset; |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1349 |
mbox_sync.length = slave->sii_tx_mailbox_size; |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1350 |
mbox_sync.control_register = 0x26; |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1351 |
mbox_sync.enable = 0x01; |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1352 |
mbox_sync.est_length = 0; |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1353 |
ec_sync_config(&mbox_sync, slave, |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1354 |
datagram->data + EC_SYNC_SIZE * mbox_sync.index); |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1355 |
mbox_sync.index = 1; |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1356 |
mbox_sync.physical_start_address = slave->sii_rx_mailbox_offset; |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1357 |
mbox_sync.length = slave->sii_rx_mailbox_size; |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1358 |
mbox_sync.control_register = 0x22; |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1359 |
mbox_sync.enable = 0x01; |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1360 |
mbox_sync.est_length = 0; |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1361 |
ec_sync_config(&mbox_sync, slave, |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1362 |
datagram->data + EC_SYNC_SIZE * mbox_sync.index); |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1363 |
} |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1364 |
} |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1365 |
else { |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1366 |
list_for_each_entry(sync, &slave->sii_syncs, list) { |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1367 |
if (sync->index >= slave->base_sync_count) { |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1368 |
EC_ERR("Invalid sync manager configuration found!"); |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1369 |
fsm->slave->error_flag = 1; |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1370 |
fsm->slave_state = ec_fsm_slave_state_error; |
420
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1371 |
return; |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1372 |
} |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1373 |
ec_sync_config(sync, slave, |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1374 |
datagram->data + EC_SYNC_SIZE * sync->index); |
0ae52c37179b
Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents:
419
diff
changeset
|
1375 |
} |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1376 |
} |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1377 |
|
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
1378 |
ec_master_queue_datagram(fsm->master, datagram); |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1379 |
fsm->slave_state = ec_fsm_slaveconf_state_sync; |
309
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1380 |
} |
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1381 |
|
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1382 |
/*****************************************************************************/ |
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1383 |
|
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1384 |
/** |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1385 |
Slave configuration state: SYNC. |
309
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1386 |
*/ |
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1387 |
|
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1388 |
void ec_fsm_slaveconf_state_sync(ec_fsm_t *fsm /**< finite state machine */) |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1389 |
{ |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
1390 |
ec_datagram_t *datagram = &fsm->datagram; |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
1391 |
ec_slave_t *slave = fsm->slave; |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
1392 |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1393 |
if (datagram->state != EC_DATAGRAM_RECEIVED |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1394 |
|| datagram->working_counter != 1) { |
292
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
1395 |
slave->error_flag = 1; |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1396 |
fsm->slave_state = ec_fsm_slave_state_error; |
260
5fe7df7f2433
Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents:
259
diff
changeset
|
1397 |
EC_ERR("Failed to set sync managers on slave %i.\n", |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1398 |
slave->ring_position); |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1399 |
return; |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1400 |
} |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1401 |
|
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1402 |
ec_fsm_slaveconf_enter_preop(fsm); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1403 |
} |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1404 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1405 |
/*****************************************************************************/ |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1406 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1407 |
/** |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1408 |
*/ |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1409 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1410 |
void ec_fsm_slaveconf_enter_preop(ec_fsm_t *fsm /**< finite state machine */) |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1411 |
{ |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1412 |
fsm->slave_state = ec_fsm_slaveconf_state_preop; |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1413 |
ec_fsm_change_start(&fsm->fsm_change, fsm->slave, EC_SLAVE_STATE_PREOP); |
434
0180d8277311
Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents:
433
diff
changeset
|
1414 |
ec_fsm_change_exec(&fsm->fsm_change); // execute immediately |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1415 |
} |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1416 |
|
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1417 |
/*****************************************************************************/ |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1418 |
|
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1419 |
/** |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1420 |
Slave configuration state: PREOP. |
309
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1421 |
*/ |
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1422 |
|
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1423 |
void ec_fsm_slaveconf_state_preop(ec_fsm_t *fsm /**< finite state machine */) |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1424 |
{ |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1425 |
ec_slave_t *slave = fsm->slave; |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1426 |
ec_master_t *master = fsm->master; |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
1427 |
ec_datagram_t *datagram = &fsm->datagram; |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1428 |
unsigned int j; |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1429 |
|
435
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
434
diff
changeset
|
1430 |
if (ec_fsm_change_exec(&fsm->fsm_change)) return; |
434
0180d8277311
Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents:
433
diff
changeset
|
1431 |
|
0180d8277311
Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents:
433
diff
changeset
|
1432 |
if (!ec_fsm_change_success(&fsm->fsm_change)) { |
292
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
1433 |
slave->error_flag = 1; |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1434 |
fsm->slave_state = ec_fsm_slave_state_error; |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1435 |
return; |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1436 |
} |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1437 |
|
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1438 |
// slave is now in PREOP |
419
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1439 |
slave->jiffies_preop = fsm->datagram.jiffies_received; |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1440 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1441 |
if (master->debug_level) { |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1442 |
EC_DBG("Slave %i is now in PREOP.\n", slave->ring_position); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1443 |
} |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1444 |
|
419
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1445 |
if (slave->current_state == slave->requested_state) { |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1446 |
fsm->slave_state = ec_fsm_slave_state_end; // successful |
419
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1447 |
if (master->debug_level) { |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1448 |
EC_DBG("Finished configuration of slave %i.\n", |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1449 |
slave->ring_position); |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1450 |
} |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1451 |
return; |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1452 |
} |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1453 |
|
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1454 |
if (!slave->base_fmmu_count) { // skip FMMU configuration |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1455 |
if (list_empty(&slave->sdo_confs)) { // skip SDO configuration |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1456 |
ec_fsm_slaveconf_enter_saveop(fsm); |
338
469369417422
New transition in slave conf state machine: Skip fmmu and SDO configuration.
Florian Pose <fp@igh-essen.com>
parents:
329
diff
changeset
|
1457 |
return; |
469369417422
New transition in slave conf state machine: Skip fmmu and SDO configuration.
Florian Pose <fp@igh-essen.com>
parents:
329
diff
changeset
|
1458 |
} |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1459 |
|
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1460 |
ec_fsm_slaveconf_enter_sdoconf(fsm); |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1461 |
return; |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1462 |
} |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1463 |
|
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1464 |
// configure FMMUs |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
1465 |
ec_datagram_npwr(datagram, slave->station_address, |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
1466 |
0x0600, EC_FMMU_SIZE * slave->base_fmmu_count); |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
1467 |
memset(datagram->data, 0x00, EC_FMMU_SIZE * slave->base_fmmu_count); |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1468 |
for (j = 0; j < slave->fmmu_count; j++) { |
275
ba51285d4ef6
Variable-sized data fields, BK1120.
Florian Pose <fp@igh-essen.com>
parents:
269
diff
changeset
|
1469 |
ec_fmmu_config(&slave->fmmus[j], slave, |
293
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
1470 |
datagram->data + EC_FMMU_SIZE * j); |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
1471 |
} |
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
1472 |
|
14aeb79aa992
Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents:
292
diff
changeset
|
1473 |
ec_master_queue_datagram(master, datagram); |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1474 |
fsm->slave_state = ec_fsm_slaveconf_state_fmmu; |
309
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1475 |
} |
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1476 |
|
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1477 |
/*****************************************************************************/ |
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1478 |
|
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1479 |
/** |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1480 |
Slave configuration state: FMMU. |
309
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1481 |
*/ |
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1482 |
|
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1483 |
void ec_fsm_slaveconf_state_fmmu(ec_fsm_t *fsm /**< finite state machine */) |
309
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1484 |
{ |
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1485 |
ec_datagram_t *datagram = &fsm->datagram; |
419
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1486 |
ec_slave_t *slave = fsm->slave; |
309
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1487 |
|
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1488 |
if (datagram->state != EC_DATAGRAM_RECEIVED |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1489 |
|| datagram->working_counter != 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
|
1490 |
fsm->slave->error_flag = 1; |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1491 |
fsm->slave_state = ec_fsm_slave_state_error; |
292
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
1492 |
EC_ERR("Failed to set FMMUs on slave %i.\n", |
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
1493 |
fsm->slave->ring_position); |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1494 |
return; |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1495 |
} |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1496 |
|
419
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1497 |
// No CoE configuration to be applied? Jump to SAVEOP state. |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1498 |
if (list_empty(&slave->sdo_confs)) { // skip SDO configuration |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1499 |
ec_fsm_slaveconf_enter_saveop(fsm); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1500 |
return; |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1501 |
} |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1502 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1503 |
ec_fsm_slaveconf_enter_sdoconf(fsm); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1504 |
} |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1505 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1506 |
/*****************************************************************************/ |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1507 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1508 |
/** |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1509 |
*/ |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1510 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1511 |
void ec_fsm_slaveconf_enter_sdoconf(ec_fsm_t *fsm /**< finite state machine */) |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1512 |
{ |
419
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1513 |
// start SDO configuration |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1514 |
fsm->slave_state = ec_fsm_slaveconf_state_sdoconf; |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1515 |
fsm->sdodata = list_entry(fsm->slave->sdo_confs.next, ec_sdo_data_t, list); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1516 |
ec_fsm_coe_download(&fsm->fsm_coe, fsm->slave, fsm->sdodata); |
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
1517 |
ec_fsm_coe_exec(&fsm->fsm_coe); // 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
|
1518 |
} |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1519 |
|
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1520 |
/*****************************************************************************/ |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1521 |
|
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1522 |
/** |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1523 |
Slave configuration state: SDOCONF. |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1524 |
*/ |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1525 |
|
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1526 |
void ec_fsm_slaveconf_state_sdoconf(ec_fsm_t *fsm /**< finite 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
|
1527 |
{ |
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
1528 |
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
|
1529 |
|
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
1530 |
if (!ec_fsm_coe_success(&fsm->fsm_coe)) { |
419
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1531 |
fsm->slave->error_flag = 1; |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1532 |
fsm->slave_state = ec_fsm_slave_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
|
1533 |
return; |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1534 |
} |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1535 |
|
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1536 |
// Another SDO to configure? |
436
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
1537 |
if (fsm->sdodata->list.next != &fsm->slave->sdo_confs) { |
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
1538 |
fsm->sdodata = list_entry(fsm->sdodata->list.next, |
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
1539 |
ec_sdo_data_t, list); |
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
1540 |
ec_fsm_coe_download(&fsm->fsm_coe, fsm->slave, fsm->sdodata); |
63214beb641d
Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
435
diff
changeset
|
1541 |
ec_fsm_coe_exec(&fsm->fsm_coe); // 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
|
1542 |
return; |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1543 |
} |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1544 |
|
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1545 |
// All SDOs are now configured. |
cf724fc82a00
Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents:
411
diff
changeset
|
1546 |
|
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1547 |
// set state to SAVEOP |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1548 |
ec_fsm_slaveconf_enter_saveop(fsm); |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1549 |
} |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1550 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1551 |
/*****************************************************************************/ |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1552 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1553 |
/** |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1554 |
*/ |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1555 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1556 |
void ec_fsm_slaveconf_enter_saveop(ec_fsm_t *fsm /**< finite state machine */) |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1557 |
{ |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1558 |
fsm->slave_state = ec_fsm_slaveconf_state_saveop; |
454
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
1559 |
ec_fsm_change_start(&fsm->fsm_change, fsm->slave, EC_SLAVE_STATE_SAVEOP); |
434
0180d8277311
Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents:
433
diff
changeset
|
1560 |
ec_fsm_change_exec(&fsm->fsm_change); // execute immediately |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1561 |
} |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1562 |
|
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1563 |
/*****************************************************************************/ |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1564 |
|
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1565 |
/** |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1566 |
Slave configuration state: SAVEOP. |
309
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1567 |
*/ |
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1568 |
|
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1569 |
void ec_fsm_slaveconf_state_saveop(ec_fsm_t *fsm /**< finite state machine */) |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1570 |
{ |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1571 |
ec_master_t *master = fsm->master; |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1572 |
ec_slave_t *slave = fsm->slave; |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1573 |
|
435
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
434
diff
changeset
|
1574 |
if (ec_fsm_change_exec(&fsm->fsm_change)) return; |
434
0180d8277311
Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents:
433
diff
changeset
|
1575 |
|
0180d8277311
Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents:
433
diff
changeset
|
1576 |
if (!ec_fsm_change_success(&fsm->fsm_change)) { |
292
2cf6ae0a2419
Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents:
291
diff
changeset
|
1577 |
fsm->slave->error_flag = 1; |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1578 |
fsm->slave_state = ec_fsm_slave_state_error; |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1579 |
return; |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1580 |
} |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1581 |
|
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1582 |
// slave is now in SAVEOP |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1583 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1584 |
if (master->debug_level) { |
411 | 1585 |
EC_DBG("Slave %i is now in SAVEOP.\n", slave->ring_position); |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1586 |
} |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1587 |
|
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1588 |
if (fsm->slave->current_state == fsm->slave->requested_state) { |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1589 |
fsm->slave_state = ec_fsm_slave_state_end; // successful |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1590 |
if (master->debug_level) { |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1591 |
EC_DBG("Finished configuration of slave %i.\n", |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1592 |
slave->ring_position); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1593 |
} |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1594 |
return; |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1595 |
} |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1596 |
|
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1597 |
// set state to OP |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1598 |
fsm->slave_state = ec_fsm_slaveconf_state_op; |
454
25cc4a3b9e0a
State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents:
448
diff
changeset
|
1599 |
ec_fsm_change_start(&fsm->fsm_change, slave, EC_SLAVE_STATE_OP); |
434
0180d8277311
Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents:
433
diff
changeset
|
1600 |
ec_fsm_change_exec(&fsm->fsm_change); // execute immediately |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1601 |
} |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1602 |
|
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1603 |
/*****************************************************************************/ |
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1604 |
|
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1605 |
/** |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1606 |
Slave configuration state: OP |
309
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1607 |
*/ |
42e69cf31495
Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents:
308
diff
changeset
|
1608 |
|
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1609 |
void ec_fsm_slaveconf_state_op(ec_fsm_t *fsm /**< finite state machine */) |
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1610 |
{ |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1611 |
ec_master_t *master = fsm->master; |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1612 |
ec_slave_t *slave = fsm->slave; |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1613 |
|
435
779a18d12e6c
Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents:
434
diff
changeset
|
1614 |
if (ec_fsm_change_exec(&fsm->fsm_change)) return; |
434
0180d8277311
Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents:
433
diff
changeset
|
1615 |
|
0180d8277311
Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents:
433
diff
changeset
|
1616 |
if (!ec_fsm_change_success(&fsm->fsm_change)) { |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1617 |
slave->error_flag = 1; |
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1618 |
fsm->slave_state = ec_fsm_slave_state_error; |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1619 |
return; |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1620 |
} |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1621 |
|
251
c1d0b63a9302
EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents:
246
diff
changeset
|
1622 |
// slave is now in OP |
409
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1623 |
|
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1624 |
if (master->debug_level) { |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1625 |
EC_DBG("Slave %i is now in OP.\n", slave->ring_position); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1626 |
EC_DBG("Finished configuration of slave %i.\n", slave->ring_position); |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1627 |
} |
bc4c852e1b93
Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents:
407
diff
changeset
|
1628 |
|
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1629 |
fsm->slave_state = ec_fsm_slave_state_end; // successful |
238
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1630 |
} |
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1631 |
|
b4960499098f
Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1632 |
/****************************************************************************** |
329
d004349777fc
SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
1633 |
* Common state functions |
d004349777fc
SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents:
325
diff
changeset
|
1634 |
*****************************************************************************/ |
286
f3352378b4d4
Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents:
275
diff
changeset
|
1635 |
|
f3352378b4d4
Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents:
275
diff
changeset
|
1636 |
/** |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1637 |
State: ERROR. |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1638 |
*/ |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1639 |
|
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1640 |
void ec_fsm_slave_state_error(ec_fsm_t *fsm /**< finite state machine */) |
325
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1641 |
{ |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1642 |
} |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1643 |
|
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1644 |
/*****************************************************************************/ |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1645 |
|
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1646 |
/** |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1647 |
State: END. |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1648 |
*/ |
7833cf70c4f2
VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents:
312
diff
changeset
|
1649 |
|
462
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1650 |
void ec_fsm_slave_state_end(ec_fsm_t *fsm /**< finite state machine */) |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1651 |
{ |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1652 |
} |
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1653 |
|
e6fac0c8bc92
New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1654 |
/*****************************************************************************/ |