author | Florian Pose <fp@igh-essen.com> |
Tue, 13 May 2008 16:07:06 +0000 | |
changeset 912 | 6630f4dbcfd2 |
parent 903 | d13004440b6d |
child 977 | 167ae3e76cc7 |
permissions | -rw-r--r-- |
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1 |
/****************************************************************************** |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2 |
* |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
3 |
* $Id$ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
4 |
* |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
5 |
* Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
6 |
* |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
7 |
* This file is part of the IgH EtherCAT Master. |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
8 |
* |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
9 |
* The IgH EtherCAT Master is free software; you can redistribute it |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
10 |
* and/or modify it under the terms of the GNU General Public License |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
11 |
* as published by the Free Software Foundation; either version 2 of the |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
12 |
* License, or (at your option) any later version. |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
13 |
* |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
14 |
* The IgH EtherCAT Master is distributed in the hope that it will be |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
15 |
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
17 |
* GNU General Public License for more details. |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
18 |
* |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
19 |
* You should have received a copy of the GNU General Public License |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
20 |
* along with the IgH EtherCAT Master; if not, write to the Free Software |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
21 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
22 |
* |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
23 |
* The right to use EtherCAT Technology is granted and comes free of |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
24 |
* charge under condition of compatibility of product made by |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
25 |
* Licensee. People intending to distribute/sell products based on the |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
26 |
* code, have to sign an agreement to guarantee that products using |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
27 |
* software based on IgH EtherCAT master stay compatible with the actual |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
28 |
* EtherCAT specification (which are released themselves as an open |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
29 |
* standard) as the (only) precondition to have the right to use EtherCAT |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
30 |
* Technology, IP and trade marks. |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
31 |
* |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
32 |
*****************************************************************************/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
33 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
34 |
/** |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
35 |
\file |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
36 |
EtherCAT slave state machines. |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
37 |
*/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
38 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
39 |
/*****************************************************************************/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
40 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
41 |
#include "globals.h" |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
42 |
#include "master.h" |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
43 |
#include "mailbox.h" |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
44 |
#include "slave_config.h" |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
45 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
46 |
#include "fsm_slave_scan.h" |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
47 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
48 |
/*****************************************************************************/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
49 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
50 |
void ec_fsm_slave_scan_state_start(ec_fsm_slave_scan_t *); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
51 |
void ec_fsm_slave_scan_state_address(ec_fsm_slave_scan_t *); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
52 |
void ec_fsm_slave_scan_state_state(ec_fsm_slave_scan_t *); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
53 |
void ec_fsm_slave_scan_state_base(ec_fsm_slave_scan_t *); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
54 |
void ec_fsm_slave_scan_state_datalink(ec_fsm_slave_scan_t *); |
872 | 55 |
void ec_fsm_slave_scan_state_sii_size(ec_fsm_slave_scan_t *); |
56 |
void ec_fsm_slave_scan_state_sii_data(ec_fsm_slave_scan_t *); |
|
831
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
57 |
void ec_fsm_slave_scan_state_preop(ec_fsm_slave_scan_t *); |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
58 |
void ec_fsm_slave_scan_state_pdos(ec_fsm_slave_scan_t *); |
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
59 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
60 |
void ec_fsm_slave_scan_state_end(ec_fsm_slave_scan_t *); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
61 |
void ec_fsm_slave_scan_state_error(ec_fsm_slave_scan_t *); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
62 |
|
831
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
63 |
void ec_fsm_slave_scan_enter_preop(ec_fsm_slave_scan_t *); |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
64 |
void ec_fsm_slave_scan_enter_pdos(ec_fsm_slave_scan_t *); |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
65 |
|
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
66 |
/*****************************************************************************/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
67 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
68 |
/** Constructor. |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
69 |
*/ |
831
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
70 |
void ec_fsm_slave_scan_init( |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
71 |
ec_fsm_slave_scan_t *fsm, /**< Slave scanning state machine. */ |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
72 |
ec_datagram_t *datagram, /**< Datagram to use. */ |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
73 |
ec_fsm_slave_config_t *fsm_slave_config, /**< Slave configuration |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
74 |
state machine to use. */ |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
75 |
ec_fsm_coe_map_t *fsm_coe_map /**< Pdo mapping state machine to use. |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
76 |
*/ |
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
77 |
) |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
78 |
{ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
79 |
fsm->datagram = datagram; |
831
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
80 |
fsm->fsm_slave_config = fsm_slave_config; |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
81 |
fsm->fsm_coe_map = fsm_coe_map; |
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
82 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
83 |
// init sub state machines |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
84 |
ec_fsm_sii_init(&fsm->fsm_sii, fsm->datagram); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
85 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
86 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
87 |
/*****************************************************************************/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
88 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
89 |
/** Destructor. |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
90 |
*/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
91 |
void ec_fsm_slave_scan_clear(ec_fsm_slave_scan_t *fsm /**< slave state machine */) |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
92 |
{ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
93 |
// clear sub state machines |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
94 |
ec_fsm_sii_clear(&fsm->fsm_sii); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
95 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
96 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
97 |
/*****************************************************************************/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
98 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
99 |
/** |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
100 |
* Start slave scan state machine. |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
101 |
*/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
102 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
103 |
void ec_fsm_slave_scan_start( |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
104 |
ec_fsm_slave_scan_t *fsm, /**< slave state machine */ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
105 |
ec_slave_t *slave /**< slave to configure */ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
106 |
) |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
107 |
{ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
108 |
fsm->slave = slave; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
109 |
fsm->state = ec_fsm_slave_scan_state_start; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
110 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
111 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
112 |
/*****************************************************************************/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
113 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
114 |
/** |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
115 |
\return false, if state machine has terminated |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
116 |
*/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
117 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
118 |
int ec_fsm_slave_scan_running(const ec_fsm_slave_scan_t *fsm /**< slave state machine */) |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
119 |
{ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
120 |
return fsm->state != ec_fsm_slave_scan_state_end |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
121 |
&& fsm->state != ec_fsm_slave_scan_state_error; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
122 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
123 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
124 |
/*****************************************************************************/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
125 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
126 |
/** |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
127 |
Executes the current state of the state machine. |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
128 |
If the state machine's datagram is not sent or received yet, the execution |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
129 |
of the state machine is delayed to the next cycle. |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
130 |
\return false, if state machine has terminated |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
131 |
*/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
132 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
133 |
int ec_fsm_slave_scan_exec(ec_fsm_slave_scan_t *fsm /**< slave state machine */) |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
134 |
{ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
135 |
if (fsm->datagram->state == EC_DATAGRAM_SENT |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
136 |
|| fsm->datagram->state == EC_DATAGRAM_QUEUED) { |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
137 |
// datagram was not sent or received yet. |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
138 |
return ec_fsm_slave_scan_running(fsm); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
139 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
140 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
141 |
fsm->state(fsm); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
142 |
return ec_fsm_slave_scan_running(fsm); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
143 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
144 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
145 |
/*****************************************************************************/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
146 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
147 |
/** |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
148 |
\return true, if the state machine terminated gracefully |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
149 |
*/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
150 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
151 |
int ec_fsm_slave_scan_success(const ec_fsm_slave_scan_t *fsm /**< slave state machine */) |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
152 |
{ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
153 |
return fsm->state == ec_fsm_slave_scan_state_end; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
154 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
155 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
156 |
/****************************************************************************** |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
157 |
* slave scan state machine |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
158 |
*****************************************************************************/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
159 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
160 |
/** |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
161 |
Slave scan state: START. |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
162 |
First state of the slave state machine. Writes the station address to the |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
163 |
slave, according to its ring position. |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
164 |
*/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
165 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
166 |
void ec_fsm_slave_scan_state_start(ec_fsm_slave_scan_t *fsm /**< slave state machine */) |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
167 |
{ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
168 |
// write station address |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
169 |
ec_datagram_apwr(fsm->datagram, fsm->slave->ring_position, 0x0010, 2); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
170 |
EC_WRITE_U16(fsm->datagram->data, fsm->slave->station_address); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
171 |
fsm->retries = EC_FSM_RETRIES; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
172 |
fsm->state = ec_fsm_slave_scan_state_address; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
173 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
174 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
175 |
/*****************************************************************************/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
176 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
177 |
/** |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
178 |
Slave scan state: ADDRESS. |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
179 |
*/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
180 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
181 |
void ec_fsm_slave_scan_state_address(ec_fsm_slave_scan_t *fsm /**< slave state machine */) |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
182 |
{ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
183 |
ec_datagram_t *datagram = fsm->datagram; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
184 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
185 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
186 |
return; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
187 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
188 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
189 |
fsm->state = ec_fsm_slave_scan_state_error; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
190 |
EC_ERR("Failed to receive station address datagram for slave %i" |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
191 |
" (datagram state %i)\n", |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
192 |
fsm->slave->ring_position, datagram->state); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
193 |
return; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
194 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
195 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
196 |
if (datagram->working_counter != 1) { |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
197 |
fsm->slave->error_flag = 1; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
198 |
fsm->state = ec_fsm_slave_scan_state_error; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
199 |
EC_ERR("Failed to write station address on slave %i: ", |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
200 |
fsm->slave->ring_position); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
201 |
ec_datagram_print_wc_error(datagram); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
202 |
return; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
203 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
204 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
205 |
// Read AL state |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
206 |
ec_datagram_fprd(datagram, fsm->slave->station_address, 0x0130, 2); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
207 |
fsm->retries = EC_FSM_RETRIES; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
208 |
fsm->state = ec_fsm_slave_scan_state_state; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
209 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
210 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
211 |
/*****************************************************************************/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
212 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
213 |
/** |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
214 |
Slave scan state: STATE. |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
215 |
*/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
216 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
217 |
void ec_fsm_slave_scan_state_state( |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
218 |
ec_fsm_slave_scan_t *fsm /**< slave state machine */ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
219 |
) |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
220 |
{ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
221 |
ec_datagram_t *datagram = fsm->datagram; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
222 |
ec_slave_t *slave = fsm->slave; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
223 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
224 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
225 |
return; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
226 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
227 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
228 |
fsm->state = ec_fsm_slave_scan_state_error; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
229 |
EC_ERR("Failed to receive AL state datagram from slave %i" |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
230 |
" (datagram state %i).\n", |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
231 |
fsm->slave->ring_position, datagram->state); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
232 |
return; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
233 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
234 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
235 |
if (datagram->working_counter != 1) { |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
236 |
fsm->slave->error_flag = 1; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
237 |
fsm->state = ec_fsm_slave_scan_state_error; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
238 |
EC_ERR("Failed to read AL state of slave %i: ", |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
239 |
fsm->slave->ring_position); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
240 |
ec_datagram_print_wc_error(datagram); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
241 |
return; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
242 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
243 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
244 |
slave->current_state = EC_READ_U8(datagram->data); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
245 |
if (slave->current_state & EC_SLAVE_STATE_ACK_ERR) { |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
246 |
char state_str[EC_STATE_STRING_SIZE]; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
247 |
ec_state_string(slave->current_state, state_str); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
248 |
EC_WARN("Slave %i has state error bit set (%s)!\n", |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
249 |
slave->ring_position, state_str); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
250 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
251 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
252 |
// read base data |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
253 |
ec_datagram_fprd(datagram, fsm->slave->station_address, 0x0000, 6); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
254 |
fsm->retries = EC_FSM_RETRIES; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
255 |
fsm->state = ec_fsm_slave_scan_state_base; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
256 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
257 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
258 |
/*****************************************************************************/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
259 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
260 |
/** |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
261 |
Slave scan state: BASE. |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
262 |
*/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
263 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
264 |
void ec_fsm_slave_scan_state_base(ec_fsm_slave_scan_t *fsm /**< slave state machine */) |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
265 |
{ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
266 |
ec_datagram_t *datagram = fsm->datagram; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
267 |
ec_slave_t *slave = fsm->slave; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
268 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
269 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
270 |
return; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
271 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
272 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
273 |
fsm->state = ec_fsm_slave_scan_state_error; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
274 |
EC_ERR("Failed to receive base data datagram for slave %i" |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
275 |
" (datagram state %i).\n", |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
276 |
slave->ring_position, datagram->state); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
277 |
return; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
278 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
279 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
280 |
if (datagram->working_counter != 1) { |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
281 |
fsm->slave->error_flag = 1; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
282 |
fsm->state = ec_fsm_slave_scan_state_error; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
283 |
EC_ERR("Failed to read base data from slave %i: ", |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
284 |
slave->ring_position); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
285 |
ec_datagram_print_wc_error(datagram); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
286 |
return; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
287 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
288 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
289 |
slave->base_type = EC_READ_U8 (datagram->data); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
290 |
slave->base_revision = EC_READ_U8 (datagram->data + 1); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
291 |
slave->base_build = EC_READ_U16(datagram->data + 2); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
292 |
slave->base_fmmu_count = EC_READ_U8 (datagram->data + 4); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
293 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
294 |
if (slave->base_fmmu_count > EC_MAX_FMMUS) { |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
295 |
EC_WARN("Slave %u has more FMMUs (%u) than the master can" |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
296 |
" handle (%u).\n", slave->ring_position, |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
297 |
slave->base_fmmu_count, EC_MAX_FMMUS); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
298 |
slave->base_fmmu_count = EC_MAX_FMMUS; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
299 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
300 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
301 |
// read data link status |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
302 |
ec_datagram_fprd(datagram, slave->station_address, 0x0110, 2); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
303 |
fsm->retries = EC_FSM_RETRIES; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
304 |
fsm->state = ec_fsm_slave_scan_state_datalink; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
305 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
306 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
307 |
/*****************************************************************************/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
308 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
309 |
/** |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
310 |
Slave scan state: DATALINK. |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
311 |
*/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
312 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
313 |
void ec_fsm_slave_scan_state_datalink(ec_fsm_slave_scan_t *fsm /**< slave state machine */) |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
314 |
{ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
315 |
ec_datagram_t *datagram = fsm->datagram; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
316 |
ec_slave_t *slave = fsm->slave; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
317 |
uint16_t dl_status; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
318 |
unsigned int i; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
319 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
320 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
321 |
return; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
322 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
323 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
324 |
fsm->state = ec_fsm_slave_scan_state_error; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
325 |
EC_ERR("Failed to receive DL status datagram from slave %i" |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
326 |
" (datagram state %i).\n", |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
327 |
slave->ring_position, datagram->state); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
328 |
return; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
329 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
330 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
331 |
if (datagram->working_counter != 1) { |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
332 |
fsm->slave->error_flag = 1; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
333 |
fsm->state = ec_fsm_slave_scan_state_error; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
334 |
EC_ERR("Failed to read DL status from slave %i: ", |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
335 |
slave->ring_position); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
336 |
ec_datagram_print_wc_error(datagram); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
337 |
return; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
338 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
339 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
340 |
dl_status = EC_READ_U16(datagram->data); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
341 |
for (i = 0; i < 4; i++) { |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
342 |
slave->dl_link[i] = dl_status & (1 << (4 + i)) ? 1 : 0; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
343 |
slave->dl_loop[i] = dl_status & (1 << (8 + i * 2)) ? 1 : 0; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
344 |
slave->dl_signal[i] = dl_status & (1 << (9 + i * 2)) ? 1 : 0; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
345 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
346 |
|
872 | 347 |
// Start fetching SII size |
348 |
||
349 |
fsm->sii_offset = EC_FIRST_SII_CATEGORY_OFFSET; // first category header |
|
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
350 |
ec_fsm_sii_read(&fsm->fsm_sii, slave, fsm->sii_offset, |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
351 |
EC_FSM_SII_USE_CONFIGURED_ADDRESS); |
872 | 352 |
fsm->state = ec_fsm_slave_scan_state_sii_size; |
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
353 |
fsm->state(fsm); // execute state immediately |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
354 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
355 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
356 |
/*****************************************************************************/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
357 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
358 |
/** |
872 | 359 |
Slave scan state: SII SIZE. |
360 |
*/ |
|
361 |
||
362 |
void ec_fsm_slave_scan_state_sii_size(ec_fsm_slave_scan_t *fsm /**< slave state machine */) |
|
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
363 |
{ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
364 |
ec_slave_t *slave = fsm->slave; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
365 |
uint16_t cat_type, cat_size; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
366 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
367 |
if (ec_fsm_sii_exec(&fsm->fsm_sii)) return; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
368 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
369 |
if (!ec_fsm_sii_success(&fsm->fsm_sii)) { |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
370 |
fsm->slave->error_flag = 1; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
371 |
fsm->state = ec_fsm_slave_scan_state_error; |
872 | 372 |
EC_ERR("Failed to read SII size of slave %i.\n", |
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
373 |
slave->ring_position); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
374 |
return; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
375 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
376 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
377 |
cat_type = EC_READ_U16(fsm->fsm_sii.value); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
378 |
cat_size = EC_READ_U16(fsm->fsm_sii.value + 2); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
379 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
380 |
if (cat_type != 0xFFFF) { // not the last category |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
381 |
off_t next_offset = 2UL + fsm->sii_offset + cat_size; |
872 | 382 |
if (next_offset >= EC_MAX_SII_SIZE) { |
383 |
EC_WARN("SII size of slave %i exceeds" |
|
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
384 |
" %u words (0xffff limiter missing?).\n", |
872 | 385 |
slave->ring_position, EC_MAX_SII_SIZE); |
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
386 |
// cut off category data... |
872 | 387 |
slave->sii_size = EC_FIRST_SII_CATEGORY_OFFSET * 2; |
388 |
goto alloc_sii; |
|
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
389 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
390 |
fsm->sii_offset = next_offset; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
391 |
ec_fsm_sii_read(&fsm->fsm_sii, slave, fsm->sii_offset, |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
392 |
EC_FSM_SII_USE_CONFIGURED_ADDRESS); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
393 |
ec_fsm_sii_exec(&fsm->fsm_sii); // execute state immediately |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
394 |
return; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
395 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
396 |
|
872 | 397 |
slave->sii_size = (fsm->sii_offset + 1) * 2; |
398 |
||
399 |
alloc_sii: |
|
400 |
if (slave->sii_data) { |
|
401 |
EC_WARN("Freeing old SII data on slave %i...\n", |
|
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
402 |
slave->ring_position); |
872 | 403 |
kfree(slave->sii_data); |
404 |
} |
|
405 |
||
406 |
if (!(slave->sii_data = |
|
407 |
(uint8_t *) kmalloc(slave->sii_size, GFP_ATOMIC))) { |
|
408 |
EC_ERR("Failed to allocate %u bytes of SII data for slave %u.\n", |
|
409 |
slave->sii_size, slave->ring_position); |
|
410 |
slave->sii_size = 0; |
|
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
411 |
slave->error_flag = 1; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
412 |
fsm->state = ec_fsm_slave_scan_state_error; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
413 |
return; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
414 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
415 |
|
872 | 416 |
// Start fetching SII contents |
417 |
||
418 |
fsm->state = ec_fsm_slave_scan_state_sii_data; |
|
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
419 |
fsm->sii_offset = 0x0000; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
420 |
ec_fsm_sii_read(&fsm->fsm_sii, slave, fsm->sii_offset, |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
421 |
EC_FSM_SII_USE_CONFIGURED_ADDRESS); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
422 |
ec_fsm_sii_exec(&fsm->fsm_sii); // execute state immediately |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
423 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
424 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
425 |
/*****************************************************************************/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
426 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
427 |
/** |
872 | 428 |
Slave scan state: SII DATA. |
429 |
*/ |
|
430 |
||
431 |
void ec_fsm_slave_scan_state_sii_data(ec_fsm_slave_scan_t *fsm /**< slave state machine */) |
|
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
432 |
{ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
433 |
ec_slave_t *slave = fsm->slave; |
872 | 434 |
uint16_t *cat_word, cat_type, cat_size, sii_word_size = slave->sii_size / 2; |
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
435 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
436 |
if (ec_fsm_sii_exec(&fsm->fsm_sii)) return; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
437 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
438 |
if (!ec_fsm_sii_success(&fsm->fsm_sii)) { |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
439 |
fsm->slave->error_flag = 1; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
440 |
fsm->state = ec_fsm_slave_scan_state_error; |
872 | 441 |
EC_ERR("Failed to fetch SII contents of slave %i.\n", |
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
442 |
slave->ring_position); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
443 |
return; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
444 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
445 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
446 |
// 2 words fetched |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
447 |
|
872 | 448 |
if (fsm->sii_offset + 2 <= sii_word_size) { // 2 words fit |
449 |
memcpy(slave->sii_data + fsm->sii_offset * 2, |
|
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
450 |
fsm->fsm_sii.value, 4); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
451 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
452 |
else { // copy the last word |
872 | 453 |
memcpy(slave->sii_data + fsm->sii_offset * 2, |
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
454 |
fsm->fsm_sii.value, 2); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
455 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
456 |
|
872 | 457 |
if (fsm->sii_offset + 2 < sii_word_size) { |
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
458 |
// fetch the next 2 words |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
459 |
fsm->sii_offset += 2; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
460 |
ec_fsm_sii_read(&fsm->fsm_sii, slave, fsm->sii_offset, |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
461 |
EC_FSM_SII_USE_CONFIGURED_ADDRESS); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
462 |
ec_fsm_sii_exec(&fsm->fsm_sii); // execute state immediately |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
463 |
return; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
464 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
465 |
|
872 | 466 |
// Evaluate SII contents |
870
fbd5924690ee
Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents:
841
diff
changeset
|
467 |
|
fbd5924690ee
Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents:
841
diff
changeset
|
468 |
ec_slave_clear_sync_managers(slave); |
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
469 |
|
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
470 |
slave->sii.alias = |
872 | 471 |
EC_READ_U16(slave->sii_data + 2 * 0x0004); |
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
472 |
slave->sii.vendor_id = |
872 | 473 |
EC_READ_U32(slave->sii_data + 2 * 0x0008); |
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
474 |
slave->sii.product_code = |
872 | 475 |
EC_READ_U32(slave->sii_data + 2 * 0x000A); |
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
476 |
slave->sii.revision_number = |
872 | 477 |
EC_READ_U32(slave->sii_data + 2 * 0x000C); |
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
478 |
slave->sii.serial_number = |
872 | 479 |
EC_READ_U32(slave->sii_data + 2 * 0x000E); |
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
480 |
slave->sii.rx_mailbox_offset = |
872 | 481 |
EC_READ_U16(slave->sii_data + 2 * 0x0018); |
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
482 |
slave->sii.rx_mailbox_size = |
872 | 483 |
EC_READ_U16(slave->sii_data + 2 * 0x0019); |
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
484 |
slave->sii.tx_mailbox_offset = |
872 | 485 |
EC_READ_U16(slave->sii_data + 2 * 0x001A); |
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
486 |
slave->sii.tx_mailbox_size = |
872 | 487 |
EC_READ_U16(slave->sii_data + 2 * 0x001B); |
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
488 |
slave->sii.mailbox_protocols = |
872 | 489 |
EC_READ_U16(slave->sii_data + 2 * 0x001C); |
490 |
||
491 |
if (sii_word_size == EC_FIRST_SII_CATEGORY_OFFSET) { |
|
492 |
// sii does not contain category data |
|
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
493 |
fsm->state = ec_fsm_slave_scan_state_end; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
494 |
return; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
495 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
496 |
|
872 | 497 |
if (sii_word_size < EC_FIRST_SII_CATEGORY_OFFSET + 1) { |
498 |
EC_ERR("Unexpected end of SII data in slave %u:" |
|
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
499 |
" First category header missing.\n", |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
500 |
slave->ring_position); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
501 |
goto end; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
502 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
503 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
504 |
// evaluate category data |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
505 |
cat_word = |
872 | 506 |
(uint16_t *) slave->sii_data + EC_FIRST_SII_CATEGORY_OFFSET; |
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
507 |
while (EC_READ_U16(cat_word) != 0xFFFF) { |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
508 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
509 |
// type and size words must fit |
872 | 510 |
if (cat_word + 2 - (uint16_t *) slave->sii_data |
511 |
> sii_word_size) { |
|
512 |
EC_ERR("Unexpected end of SII data in slave %u:" |
|
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
513 |
" Category header incomplete.\n", |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
514 |
slave->ring_position); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
515 |
goto end; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
516 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
517 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
518 |
cat_type = EC_READ_U16(cat_word) & 0x7FFF; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
519 |
cat_size = EC_READ_U16(cat_word + 1); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
520 |
cat_word += 2; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
521 |
|
872 | 522 |
if (cat_word + cat_size - (uint16_t *) slave->sii_data |
523 |
> sii_word_size) { |
|
524 |
EC_WARN("Unexpected end of SII data in slave %u:" |
|
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
525 |
" Category data incomplete.\n", |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
526 |
slave->ring_position); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
527 |
goto end; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
528 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
529 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
530 |
switch (cat_type) { |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
531 |
case 0x000A: |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
532 |
if (ec_slave_fetch_sii_strings(slave, (uint8_t *) cat_word, |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
533 |
cat_size * 2)) |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
534 |
goto end; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
535 |
break; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
536 |
case 0x001E: |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
537 |
if (ec_slave_fetch_sii_general(slave, (uint8_t *) cat_word, |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
538 |
cat_size * 2)) |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
539 |
goto end; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
540 |
break; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
541 |
case 0x0028: |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
542 |
break; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
543 |
case 0x0029: |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
544 |
if (ec_slave_fetch_sii_syncs(slave, (uint8_t *) cat_word, |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
545 |
cat_size * 2)) |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
546 |
goto end; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
547 |
break; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
548 |
case 0x0032: |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
549 |
if (ec_slave_fetch_sii_pdos( slave, (uint8_t *) cat_word, |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
550 |
cat_size * 2, EC_DIR_INPUT)) // TxPdo |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
551 |
goto end; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
552 |
break; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
553 |
case 0x0033: |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
554 |
if (ec_slave_fetch_sii_pdos( slave, (uint8_t *) cat_word, |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
555 |
cat_size * 2, EC_DIR_OUTPUT)) // RxPdo |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
556 |
goto end; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
557 |
break; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
558 |
default: |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
559 |
if (fsm->slave->master->debug_level) |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
560 |
EC_WARN("Unknown category type 0x%04X in slave %i.\n", |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
561 |
cat_type, slave->ring_position); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
562 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
563 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
564 |
cat_word += cat_size; |
872 | 565 |
if (cat_word - (uint16_t *) slave->sii_data >= sii_word_size) { |
566 |
EC_WARN("Unexpected end of SII data in slave %u:" |
|
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
567 |
" Next category header missing.\n", |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
568 |
slave->ring_position); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
569 |
goto end; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
570 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
571 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
572 |
|
834
0791aac03180
Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents:
831
diff
changeset
|
573 |
if (slave->sii.mailbox_protocols & EC_MBOX_COE) { |
831
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
574 |
ec_fsm_slave_scan_enter_preop(fsm); |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
575 |
} else { |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
576 |
fsm->state = ec_fsm_slave_scan_state_end; |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
577 |
} |
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
578 |
return; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
579 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
580 |
end: |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
581 |
EC_ERR("Failed to analyze category data.\n"); |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
582 |
fsm->slave->error_flag = 1; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
583 |
fsm->state = ec_fsm_slave_scan_state_error; |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
584 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
585 |
|
831
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
586 |
/*****************************************************************************/ |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
587 |
|
841 | 588 |
/** Enter slave scan state PREOP. |
589 |
*/ |
|
831
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
590 |
void ec_fsm_slave_scan_enter_preop( |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
591 |
ec_fsm_slave_scan_t *fsm /**< slave state machine */ |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
592 |
) |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
593 |
{ |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
594 |
ec_slave_t *slave = fsm->slave; |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
595 |
|
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
596 |
if ((slave->current_state & EC_SLAVE_STATE_MASK) < EC_SLAVE_STATE_PREOP) { |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
597 |
if (slave->master->debug_level) |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
598 |
EC_DBG("Slave %u is not in the state to do mailbox com, setting" |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
599 |
" to PREOP.\n", slave->ring_position); |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
600 |
fsm->state = ec_fsm_slave_scan_state_preop; |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
601 |
ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP); |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
602 |
ec_fsm_slave_config_start(fsm->fsm_slave_config, slave); |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
603 |
ec_fsm_slave_config_exec(fsm->fsm_slave_config); |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
604 |
} else { |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
605 |
ec_fsm_slave_scan_enter_pdos(fsm); |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
606 |
} |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
607 |
} |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
608 |
|
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
609 |
/*****************************************************************************/ |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
610 |
|
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
611 |
/** Slave scan state: PREOP. |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
612 |
*/ |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
613 |
void ec_fsm_slave_scan_state_preop( |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
614 |
ec_fsm_slave_scan_t *fsm /**< slave state machine */ |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
615 |
) |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
616 |
{ |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
617 |
if (ec_fsm_slave_config_exec(fsm->fsm_slave_config)) |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
618 |
return; |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
619 |
|
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
620 |
if (!ec_fsm_slave_config_success(fsm->fsm_slave_config)) { |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
621 |
fsm->state = ec_fsm_slave_scan_state_error; |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
622 |
return; |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
623 |
} |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
624 |
|
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
625 |
ec_fsm_slave_scan_enter_pdos(fsm); |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
626 |
} |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
627 |
|
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
628 |
/*****************************************************************************/ |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
629 |
|
841 | 630 |
/** Enter slave scan state PDOS. |
631 |
*/ |
|
831
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
632 |
void ec_fsm_slave_scan_enter_pdos( |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
633 |
ec_fsm_slave_scan_t *fsm /**< slave state machine */ |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
634 |
) |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
635 |
{ |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
636 |
ec_slave_t *slave = fsm->slave; |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
637 |
|
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
638 |
if (slave->master->debug_level) |
903
d13004440b6d
Improved a few debugging outputs.
Florian Pose <fp@igh-essen.com>
parents:
872
diff
changeset
|
639 |
EC_DBG("Scanning Pdo assignment and mapping of slave %u.\n", |
831
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
640 |
slave->ring_position); |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
641 |
fsm->state = ec_fsm_slave_scan_state_pdos; |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
642 |
ec_fsm_coe_map_start(fsm->fsm_coe_map, slave); |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
643 |
ec_fsm_coe_map_exec(fsm->fsm_coe_map); // execute immediately |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
644 |
} |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
645 |
|
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
646 |
/*****************************************************************************/ |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
647 |
|
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
648 |
/** Slave scan state: PDOS. |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
649 |
*/ |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
650 |
void ec_fsm_slave_scan_state_pdos( |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
651 |
ec_fsm_slave_scan_t *fsm /**< slave state machine */ |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
652 |
) |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
653 |
{ |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
654 |
if (ec_fsm_coe_map_exec(fsm->fsm_coe_map)) |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
655 |
return; |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
656 |
|
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
657 |
if (!ec_fsm_coe_map_success(fsm->fsm_coe_map)) { |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
658 |
fsm->state = ec_fsm_slave_scan_state_error; |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
659 |
return; |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
660 |
} |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
661 |
|
903
d13004440b6d
Improved a few debugging outputs.
Florian Pose <fp@igh-essen.com>
parents:
872
diff
changeset
|
662 |
// fetching of Pdo assignment/mapping finished |
831
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
663 |
fsm->state = ec_fsm_slave_scan_state_end; |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
664 |
} |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
830
diff
changeset
|
665 |
|
830
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
666 |
/****************************************************************************** |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
667 |
* Common state functions |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
668 |
*****************************************************************************/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
669 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
670 |
/** State: ERROR. |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
671 |
*/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
672 |
void ec_fsm_slave_scan_state_error( |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
673 |
ec_fsm_slave_scan_t *fsm /**< slave state machine */ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
674 |
) |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
675 |
{ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
676 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
677 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
678 |
/*****************************************************************************/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
679 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
680 |
/** State: END. |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
681 |
*/ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
682 |
void ec_fsm_slave_scan_state_end( |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
683 |
ec_fsm_slave_scan_t *fsm /**< slave state machine */ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
684 |
) |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
685 |
{ |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
686 |
} |
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
687 |
|
d83d92e1a919
Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
688 |
/*****************************************************************************/ |