author | Florian Pose <fp@igh-essen.com> |
Fri, 05 Mar 2010 17:48:50 +0100 | |
changeset 1842 | 6d3190b9d464 |
parent 1840 | 06fcb795525b |
child 1864 | 0a6b3aacc847 |
permissions | -rw-r--r-- |
1831
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1 |
/****************************************************************************** |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2 |
* |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
3 |
* $Id$ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
4 |
* |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
5 |
* Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
6 |
* |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
7 |
* This file is part of the IgH EtherCAT Master. |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
8 |
* |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
9 |
* The IgH EtherCAT Master is free software; you can redistribute it and/or |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
10 |
* modify it under the terms of the GNU General Public License version 2, as |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
11 |
* published by the Free Software Foundation. |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
12 |
* |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
13 |
* The IgH EtherCAT Master is distributed in the hope that it will be useful, |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
16 |
* Public License for more details. |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
17 |
* |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
18 |
* You should have received a copy of the GNU General Public License along |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
19 |
* with the IgH EtherCAT Master; if not, write to the Free Software |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
20 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
21 |
* |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
22 |
* --- |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
23 |
* |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
24 |
* The license mentioned above concerns the source code only. Using the |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
25 |
* EtherCAT technology and brand is only permitted in compliance with the |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
26 |
* industrial property and similar rights of Beckhoff Automation GmbH. |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
27 |
* |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
28 |
*****************************************************************************/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
29 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
30 |
/** |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
31 |
\file |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
32 |
EtherCAT SoE state machines. |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
33 |
*/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
34 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
35 |
/*****************************************************************************/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
36 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
37 |
#include "globals.h" |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
38 |
#include "master.h" |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
39 |
#include "mailbox.h" |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
40 |
#include "fsm_soe.h" |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
41 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
42 |
/*****************************************************************************/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
43 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
44 |
/** Mailbox type for SoE. |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
45 |
*/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
46 |
#define EC_MBOX_TYPE_SOE 0x05 |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
47 |
|
1837
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
48 |
#define EC_SOE_OPCODE_READ_REQUEST 0x01 |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
49 |
#define EC_SOE_OPCODE_READ_RESPONSE 0x02 |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
50 |
#define EC_SOE_OPCODE_WRITE_REQUEST 0x03 |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
51 |
#define EC_SOE_OPCODE_WRITE_RESPONSE 0x04 |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
52 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
53 |
#define EC_SOE_READ_REQUEST_SIZE 0x04 |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
54 |
#define EC_SOE_READ_RESPONSE_SIZE 0x04 |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
55 |
#define EC_SOE_WRITE_REQUEST_SIZE 0x04 |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
56 |
#define EC_SOE_WRITE_RESPONSE_SIZE 0x04 |
1831
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
57 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
58 |
#define EC_SOE_RESPONSE_TIMEOUT 1000 |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
59 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
60 |
/*****************************************************************************/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
61 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
62 |
void ec_fsm_soe_read_start(ec_fsm_soe_t *); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
63 |
void ec_fsm_soe_read_request(ec_fsm_soe_t *); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
64 |
void ec_fsm_soe_read_check(ec_fsm_soe_t *); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
65 |
void ec_fsm_soe_read_response(ec_fsm_soe_t *); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
66 |
|
1837
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
67 |
void ec_fsm_soe_write_start(ec_fsm_soe_t *); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
68 |
void ec_fsm_soe_write_request(ec_fsm_soe_t *); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
69 |
void ec_fsm_soe_write_check(ec_fsm_soe_t *); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
70 |
void ec_fsm_soe_write_response(ec_fsm_soe_t *); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
71 |
|
1831
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
72 |
void ec_fsm_soe_end(ec_fsm_soe_t *); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
73 |
void ec_fsm_soe_error(ec_fsm_soe_t *); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
74 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
75 |
/*****************************************************************************/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
76 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
77 |
/** Constructor. |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
78 |
*/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
79 |
void ec_fsm_soe_init( |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
80 |
ec_fsm_soe_t *fsm, /**< finite state machine */ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
81 |
ec_datagram_t *datagram /**< datagram */ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
82 |
) |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
83 |
{ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
84 |
fsm->state = NULL; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
85 |
fsm->datagram = datagram; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
86 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
87 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
88 |
/*****************************************************************************/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
89 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
90 |
/** Destructor. |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
91 |
*/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
92 |
void ec_fsm_soe_clear( |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
93 |
ec_fsm_soe_t *fsm /**< finite state machine */ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
94 |
) |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
95 |
{ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
96 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
97 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
98 |
/*****************************************************************************/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
99 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
100 |
/** Starts to transfer an IDN to/from a slave. |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
101 |
*/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
102 |
void ec_fsm_soe_transfer( |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
103 |
ec_fsm_soe_t *fsm, /**< State machine. */ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
104 |
ec_slave_t *slave, /**< EtherCAT slave. */ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
105 |
ec_soe_request_t *request /**< SoE request. */ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
106 |
) |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
107 |
{ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
108 |
fsm->slave = slave; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
109 |
fsm->request = request; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
110 |
if (request->dir == EC_DIR_OUTPUT) { |
1837
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
111 |
fsm->state = ec_fsm_soe_write_start; |
1831
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
112 |
} else { |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
113 |
fsm->state = ec_fsm_soe_read_start; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
114 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
115 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
116 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
117 |
/*****************************************************************************/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
118 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
119 |
/** |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
120 |
Executes the current state of the state machine. |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
121 |
\return false, if state machine has terminated |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
122 |
*/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
123 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
124 |
int ec_fsm_soe_exec(ec_fsm_soe_t *fsm /**< finite state machine */) |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
125 |
{ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
126 |
fsm->state(fsm); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
127 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
128 |
return fsm->state != ec_fsm_soe_end && fsm->state != ec_fsm_soe_error; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
129 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
130 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
131 |
/*****************************************************************************/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
132 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
133 |
/** |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
134 |
Returns, if the state machine terminated with success. |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
135 |
\return non-zero if successful. |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
136 |
*/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
137 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
138 |
int ec_fsm_soe_success(ec_fsm_soe_t *fsm /**< Finite state machine */) |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
139 |
{ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
140 |
return fsm->state == ec_fsm_soe_end; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
141 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
142 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
143 |
/****************************************************************************** |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
144 |
* SoE read state machine |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
145 |
*****************************************************************************/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
146 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
147 |
/** SoE state: READ START. |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
148 |
*/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
149 |
void ec_fsm_soe_read_start(ec_fsm_soe_t *fsm /**< finite state machine */) |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
150 |
{ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
151 |
ec_datagram_t *datagram = fsm->datagram; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
152 |
ec_slave_t *slave = fsm->slave; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
153 |
ec_master_t *master = slave->master; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
154 |
ec_soe_request_t *request = fsm->request; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
155 |
uint8_t *data; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
156 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
157 |
if (master->debug_level) |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
158 |
EC_DBG("Reading IDN 0x%04X from slave %u.\n", |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
159 |
request->idn, slave->ring_position); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
160 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
161 |
if (!(slave->sii.mailbox_protocols & EC_MBOX_SOE)) { |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
162 |
EC_ERR("Slave %u does not support SoE!\n", slave->ring_position); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
163 |
fsm->state = ec_fsm_soe_error; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
164 |
return; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
165 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
166 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
167 |
data = ec_slave_mbox_prepare_send(slave, datagram, EC_MBOX_TYPE_SOE, |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
168 |
EC_SOE_READ_REQUEST_SIZE); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
169 |
if (IS_ERR(data)) { |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
170 |
fsm->state = ec_fsm_soe_error; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
171 |
return; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
172 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
173 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
174 |
EC_WRITE_U8(data, EC_SOE_OPCODE_READ_REQUEST); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
175 |
EC_WRITE_U8(data + 1, 1 << 6); // request value |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
176 |
EC_WRITE_U16(data + 2, request->idn); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
177 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
178 |
if (master->debug_level) { |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
179 |
EC_DBG("SCC read request:\n"); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
180 |
ec_print_data(data, EC_SOE_READ_REQUEST_SIZE); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
181 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
182 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
183 |
fsm->request->jiffies_sent = jiffies; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
184 |
fsm->retries = EC_FSM_RETRIES; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
185 |
fsm->state = ec_fsm_soe_read_request; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
186 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
187 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
188 |
/*****************************************************************************/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
189 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
190 |
/** SoE state: READ REQUEST. |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
191 |
*/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
192 |
void ec_fsm_soe_read_request(ec_fsm_soe_t *fsm /**< finite state machine */) |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
193 |
{ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
194 |
ec_datagram_t *datagram = fsm->datagram; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
195 |
ec_slave_t *slave = fsm->slave; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
196 |
unsigned long diff_ms; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
197 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
198 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
199 |
return; // FIXME: check for response first? |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
200 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
201 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
202 |
fsm->state = ec_fsm_soe_error; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
203 |
EC_ERR("Failed to receive SoE read request for slave %u: ", |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
204 |
slave->ring_position); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
205 |
ec_datagram_print_state(datagram); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
206 |
return; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
207 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
208 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
209 |
diff_ms = (jiffies - fsm->request->jiffies_sent) * 1000 / HZ; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
210 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
211 |
if (datagram->working_counter != 1) { |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
212 |
if (!datagram->working_counter) { |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
213 |
if (diff_ms < EC_SOE_RESPONSE_TIMEOUT) { |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
214 |
// no response; send request datagram again |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
215 |
return; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
216 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
217 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
218 |
fsm->state = ec_fsm_soe_error; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
219 |
EC_ERR("Reception of SoE read request for IDN 0x%04x failed" |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
220 |
" after %u ms on slave %u: ", |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
221 |
fsm->request->idn, (u32) diff_ms, |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
222 |
fsm->slave->ring_position); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
223 |
ec_datagram_print_wc_error(datagram); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
224 |
return; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
225 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
226 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
227 |
fsm->jiffies_start = datagram->jiffies_sent; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
228 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
229 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
230 |
fsm->retries = EC_FSM_RETRIES; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
231 |
fsm->state = ec_fsm_soe_read_check; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
232 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
233 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
234 |
/*****************************************************************************/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
235 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
236 |
/** CoE state: READ CHECK. |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
237 |
*/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
238 |
void ec_fsm_soe_read_check(ec_fsm_soe_t *fsm /**< finite state machine */) |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
239 |
{ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
240 |
ec_datagram_t *datagram = fsm->datagram; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
241 |
ec_slave_t *slave = fsm->slave; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
242 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
243 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
244 |
return; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
245 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
246 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
247 |
fsm->state = ec_fsm_soe_error; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
248 |
EC_ERR("Failed to receive SoE mailbox check datagram from slave %u: ", |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
249 |
slave->ring_position); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
250 |
ec_datagram_print_state(datagram); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
251 |
return; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
252 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
253 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
254 |
if (datagram->working_counter != 1) { |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
255 |
fsm->state = ec_fsm_soe_error; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
256 |
EC_ERR("Reception of SoE mailbox check datagram failed on slave %u: ", |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
257 |
slave->ring_position); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
258 |
ec_datagram_print_wc_error(datagram); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
259 |
return; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
260 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
261 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
262 |
if (!ec_slave_mbox_check(datagram)) { |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
263 |
unsigned long diff_ms = |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
264 |
(datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
265 |
if (diff_ms >= EC_SOE_RESPONSE_TIMEOUT) { |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
266 |
fsm->state = ec_fsm_soe_error; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
267 |
EC_ERR("Timeout after %u ms while waiting for IDN 0x%04x" |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
268 |
" read response on slave %u.\n", (u32) diff_ms, |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
269 |
fsm->request->idn, slave->ring_position); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
270 |
return; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
271 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
272 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
273 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
274 |
fsm->retries = EC_FSM_RETRIES; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
275 |
return; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
276 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
277 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
278 |
// Fetch response |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
279 |
ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail. |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
280 |
fsm->retries = EC_FSM_RETRIES; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
281 |
fsm->state = ec_fsm_soe_read_response; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
282 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
283 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
284 |
/*****************************************************************************/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
285 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
286 |
/** SoE state: READ RESPONSE. |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
287 |
*/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
288 |
void ec_fsm_soe_read_response(ec_fsm_soe_t *fsm /**< finite state machine */) |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
289 |
{ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
290 |
ec_datagram_t *datagram = fsm->datagram; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
291 |
ec_slave_t *slave = fsm->slave; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
292 |
ec_master_t *master = slave->master; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
293 |
uint8_t *data, mbox_prot, opcode, error_flag, value_included; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
294 |
size_t rec_size, data_size; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
295 |
ec_soe_request_t *req = fsm->request; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
296 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
297 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
298 |
return; // FIXME: request again? |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
299 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
300 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
301 |
fsm->state = ec_fsm_soe_error; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
302 |
EC_ERR("Failed to receive SoE read response datagram for" |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
303 |
" slave %u: ", slave->ring_position); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
304 |
ec_datagram_print_state(datagram); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
305 |
return; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
306 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
307 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
308 |
if (datagram->working_counter != 1) { |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
309 |
fsm->state = ec_fsm_soe_error; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
310 |
EC_ERR("Reception of SoE read response failed on slave %u: ", |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
311 |
slave->ring_position); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
312 |
ec_datagram_print_wc_error(datagram); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
313 |
return; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
314 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
315 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
316 |
data = ec_slave_mbox_fetch(slave, datagram, &mbox_prot, &rec_size); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
317 |
if (IS_ERR(data)) { |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
318 |
fsm->state = ec_fsm_soe_error; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
319 |
return; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
320 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
321 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
322 |
if (master->debug_level) { |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
323 |
EC_DBG("SCC read response:\n"); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
324 |
ec_print_data(data, rec_size); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
325 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
326 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
327 |
if (mbox_prot != EC_MBOX_TYPE_SOE) { |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
328 |
fsm->state = ec_fsm_soe_error; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
329 |
EC_WARN("Received mailbox protocol 0x%02X as response.\n", mbox_prot); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
330 |
return; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
331 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
332 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
333 |
if (rec_size < EC_SOE_READ_RESPONSE_SIZE) { |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
334 |
fsm->state = ec_fsm_soe_error; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
335 |
EC_ERR("Received currupted SoE read response (%zu bytes)!\n", |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
336 |
rec_size); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
337 |
ec_print_data(data, rec_size); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
338 |
return; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
339 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
340 |
|
1838
1fca55f14b06
Fixed SoE opcode determination.
Florian Pose <fp@igh-essen.com>
parents:
1837
diff
changeset
|
341 |
opcode = EC_READ_U8(data) & 0x7; |
1831
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
342 |
if (opcode != EC_SOE_OPCODE_READ_RESPONSE) { |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
343 |
EC_ERR("Received no read response (opcode %x).\n", opcode); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
344 |
ec_print_data(data, rec_size); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
345 |
fsm->state = ec_fsm_soe_error; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
346 |
return; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
347 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
348 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
349 |
error_flag = (EC_READ_U8(data) >> 4) & 1; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
350 |
if (error_flag) { |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
351 |
req->error_code = EC_READ_U16(data + rec_size - 2); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
352 |
EC_ERR("Received error response: 0x%04x.\n", |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
353 |
req->error_code); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
354 |
fsm->state = ec_fsm_soe_error; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
355 |
return; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
356 |
} else { |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
357 |
req->error_code = 0x0000; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
358 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
359 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
360 |
value_included = (EC_READ_U8(data + 1) >> 6) & 1; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
361 |
if (!value_included) { |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
362 |
EC_ERR("No value included!\n"); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
363 |
fsm->state = ec_fsm_soe_error; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
364 |
return; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
365 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
366 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
367 |
data_size = rec_size - EC_SOE_READ_RESPONSE_SIZE; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
368 |
if (ec_soe_request_copy_data(req, |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
369 |
data + EC_SOE_READ_RESPONSE_SIZE, data_size)) { |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
370 |
fsm->state = ec_fsm_soe_error; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
371 |
return; |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
372 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
373 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
374 |
if (master->debug_level) { |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
375 |
EC_DBG("IDN data:\n"); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
376 |
ec_print_data(req->data, req->data_size); |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
377 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
378 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
379 |
fsm->state = ec_fsm_soe_end; // success |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
380 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
381 |
|
1837
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
382 |
/****************************************************************************** |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
383 |
* SoE write state machine |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
384 |
*****************************************************************************/ |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
385 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
386 |
/** SoE state: WRITE START. |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
387 |
*/ |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
388 |
void ec_fsm_soe_write_start(ec_fsm_soe_t *fsm /**< finite state machine */) |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
389 |
{ |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
390 |
ec_datagram_t *datagram = fsm->datagram; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
391 |
ec_slave_t *slave = fsm->slave; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
392 |
ec_master_t *master = slave->master; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
393 |
ec_soe_request_t *request = fsm->request; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
394 |
uint8_t *data; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
395 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
396 |
if (master->debug_level) |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
397 |
EC_DBG("Writing IDN 0x%04X to slave %u.\n", |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
398 |
request->idn, slave->ring_position); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
399 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
400 |
if (!(slave->sii.mailbox_protocols & EC_MBOX_SOE)) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
401 |
EC_ERR("Slave %u does not support SoE!\n", slave->ring_position); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
402 |
fsm->state = ec_fsm_soe_error; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
403 |
return; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
404 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
405 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
406 |
data = ec_slave_mbox_prepare_send(slave, datagram, EC_MBOX_TYPE_SOE, |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
407 |
EC_SOE_WRITE_REQUEST_SIZE + request->data_size); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
408 |
if (IS_ERR(data)) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
409 |
fsm->state = ec_fsm_soe_error; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
410 |
return; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
411 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
412 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
413 |
EC_WRITE_U8(data, EC_SOE_OPCODE_WRITE_REQUEST); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
414 |
EC_WRITE_U8(data + 1, 1 << 6); // only value included |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
415 |
EC_WRITE_U16(data + 2, request->idn); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
416 |
memcpy(data + 4, request->data, request->data_size); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
417 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
418 |
if (master->debug_level) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
419 |
EC_DBG("SCC write request:\n"); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
420 |
ec_print_data(data, EC_SOE_WRITE_REQUEST_SIZE + request->data_size); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
421 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
422 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
423 |
fsm->request->jiffies_sent = jiffies; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
424 |
fsm->retries = EC_FSM_RETRIES; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
425 |
fsm->state = ec_fsm_soe_write_request; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
426 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
427 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
428 |
/*****************************************************************************/ |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
429 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
430 |
/** SoE state: WRITE REQUEST. |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
431 |
*/ |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
432 |
void ec_fsm_soe_write_request(ec_fsm_soe_t *fsm /**< finite state machine */) |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
433 |
{ |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
434 |
ec_datagram_t *datagram = fsm->datagram; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
435 |
ec_slave_t *slave = fsm->slave; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
436 |
unsigned long diff_ms; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
437 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
438 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
439 |
return; // FIXME: check for response first? |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
440 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
441 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
442 |
fsm->state = ec_fsm_soe_error; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
443 |
EC_ERR("Failed to receive SoE write request for slave %u: ", |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
444 |
slave->ring_position); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
445 |
ec_datagram_print_state(datagram); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
446 |
return; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
447 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
448 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
449 |
diff_ms = (jiffies - fsm->request->jiffies_sent) * 1000 / HZ; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
450 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
451 |
if (datagram->working_counter != 1) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
452 |
if (!datagram->working_counter) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
453 |
if (diff_ms < EC_SOE_RESPONSE_TIMEOUT) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
454 |
// no response; send request datagram again |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
455 |
return; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
456 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
457 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
458 |
fsm->state = ec_fsm_soe_error; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
459 |
EC_ERR("Reception of SoE write request for IDN 0x%04x failed" |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
460 |
" after %u ms on slave %u: ", |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
461 |
fsm->request->idn, (u32) diff_ms, |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
462 |
fsm->slave->ring_position); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
463 |
ec_datagram_print_wc_error(datagram); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
464 |
return; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
465 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
466 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
467 |
fsm->jiffies_start = datagram->jiffies_sent; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
468 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
469 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
470 |
fsm->retries = EC_FSM_RETRIES; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
471 |
fsm->state = ec_fsm_soe_write_check; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
472 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
473 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
474 |
/*****************************************************************************/ |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
475 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
476 |
/** CoE state: WRITE CHECK. |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
477 |
*/ |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
478 |
void ec_fsm_soe_write_check(ec_fsm_soe_t *fsm /**< finite state machine */) |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
479 |
{ |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
480 |
ec_datagram_t *datagram = fsm->datagram; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
481 |
ec_slave_t *slave = fsm->slave; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
482 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
483 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
484 |
return; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
485 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
486 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
487 |
fsm->state = ec_fsm_soe_error; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
488 |
EC_ERR("Failed to receive SoE mailbox check datagram from slave %u: ", |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
489 |
slave->ring_position); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
490 |
ec_datagram_print_state(datagram); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
491 |
return; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
492 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
493 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
494 |
if (datagram->working_counter != 1) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
495 |
fsm->state = ec_fsm_soe_error; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
496 |
EC_ERR("Reception of SoE mailbox check datagram failed on slave %u: ", |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
497 |
slave->ring_position); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
498 |
ec_datagram_print_wc_error(datagram); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
499 |
return; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
500 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
501 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
502 |
if (!ec_slave_mbox_check(datagram)) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
503 |
unsigned long diff_ms = |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
504 |
(datagram->jiffies_received - fsm->jiffies_start) * 1000 / HZ; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
505 |
if (diff_ms >= EC_SOE_RESPONSE_TIMEOUT) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
506 |
fsm->state = ec_fsm_soe_error; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
507 |
EC_ERR("Timeout after %u ms while waiting for IDN 0x%04x" |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
508 |
" write response on slave %u.\n", (u32) diff_ms, |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
509 |
fsm->request->idn, slave->ring_position); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
510 |
return; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
511 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
512 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
513 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
514 |
fsm->retries = EC_FSM_RETRIES; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
515 |
return; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
516 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
517 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
518 |
// Fetch response |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
519 |
ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail. |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
520 |
fsm->retries = EC_FSM_RETRIES; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
521 |
fsm->state = ec_fsm_soe_write_response; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
522 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
523 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
524 |
/*****************************************************************************/ |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
525 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
526 |
/** SoE state: WRITE RESPONSE. |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
527 |
*/ |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
528 |
void ec_fsm_soe_write_response(ec_fsm_soe_t *fsm /**< finite state machine */) |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
529 |
{ |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
530 |
ec_datagram_t *datagram = fsm->datagram; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
531 |
ec_slave_t *slave = fsm->slave; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
532 |
ec_master_t *master = slave->master; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
533 |
uint8_t *data, mbox_prot, opcode, error_flag; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
534 |
uint16_t idn; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
535 |
size_t rec_size; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
536 |
ec_soe_request_t *req = fsm->request; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
537 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
538 |
if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
539 |
return; // FIXME: request again? |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
540 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
541 |
if (datagram->state != EC_DATAGRAM_RECEIVED) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
542 |
fsm->state = ec_fsm_soe_error; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
543 |
EC_ERR("Failed to receive SoE write response datagram for" |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
544 |
" slave %u: ", slave->ring_position); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
545 |
ec_datagram_print_state(datagram); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
546 |
return; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
547 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
548 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
549 |
if (datagram->working_counter != 1) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
550 |
fsm->state = ec_fsm_soe_error; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
551 |
EC_ERR("Reception of SoE write response failed on slave %u: ", |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
552 |
slave->ring_position); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
553 |
ec_datagram_print_wc_error(datagram); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
554 |
return; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
555 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
556 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
557 |
data = ec_slave_mbox_fetch(slave, datagram, &mbox_prot, &rec_size); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
558 |
if (IS_ERR(data)) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
559 |
fsm->state = ec_fsm_soe_error; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
560 |
return; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
561 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
562 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
563 |
if (master->debug_level) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
564 |
EC_DBG("SCC write response:\n"); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
565 |
ec_print_data(data, rec_size); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
566 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
567 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
568 |
if (mbox_prot != EC_MBOX_TYPE_SOE) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
569 |
fsm->state = ec_fsm_soe_error; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
570 |
EC_WARN("Received mailbox protocol 0x%02X as response.\n", mbox_prot); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
571 |
return; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
572 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
573 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
574 |
if (rec_size < EC_SOE_WRITE_RESPONSE_SIZE) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
575 |
fsm->state = ec_fsm_soe_error; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
576 |
EC_ERR("Received currupted SoE write response (%zu bytes)!\n", |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
577 |
rec_size); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
578 |
ec_print_data(data, rec_size); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
579 |
return; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
580 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
581 |
|
1838
1fca55f14b06
Fixed SoE opcode determination.
Florian Pose <fp@igh-essen.com>
parents:
1837
diff
changeset
|
582 |
opcode = EC_READ_U8(data) & 0x7; |
1837
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
583 |
if (opcode != EC_SOE_OPCODE_WRITE_RESPONSE) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
584 |
EC_ERR("Received no write response (opcode %x).\n", opcode); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
585 |
ec_print_data(data, rec_size); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
586 |
fsm->state = ec_fsm_soe_error; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
587 |
return; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
588 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
589 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
590 |
idn = EC_READ_U16(data + 2); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
591 |
if (idn != req->idn) { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
592 |
EC_ERR("Received response for wrong IDN 0x%04x.\n", idn); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
593 |
ec_print_data(data, rec_size); |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
594 |
fsm->state = ec_fsm_soe_error; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
595 |
return; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
596 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
597 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
598 |
error_flag = (EC_READ_U8(data) >> 4) & 1; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
599 |
if (error_flag) { |
1840
06fcb795525b
Fixed reading error code from write response.
Florian Pose <fp@igh-essen.com>
parents:
1838
diff
changeset
|
600 |
if (rec_size < EC_SOE_WRITE_RESPONSE_SIZE + 2) { |
06fcb795525b
Fixed reading error code from write response.
Florian Pose <fp@igh-essen.com>
parents:
1838
diff
changeset
|
601 |
EC_ERR("Received corrupted error response - error flag set," |
06fcb795525b
Fixed reading error code from write response.
Florian Pose <fp@igh-essen.com>
parents:
1838
diff
changeset
|
602 |
" but received size is %zu.\n", rec_size); |
06fcb795525b
Fixed reading error code from write response.
Florian Pose <fp@igh-essen.com>
parents:
1838
diff
changeset
|
603 |
} else { |
06fcb795525b
Fixed reading error code from write response.
Florian Pose <fp@igh-essen.com>
parents:
1838
diff
changeset
|
604 |
req->error_code = EC_READ_U16(data + EC_SOE_WRITE_RESPONSE_SIZE); |
06fcb795525b
Fixed reading error code from write response.
Florian Pose <fp@igh-essen.com>
parents:
1838
diff
changeset
|
605 |
EC_ERR("Received error response: 0x%04x.\n", |
06fcb795525b
Fixed reading error code from write response.
Florian Pose <fp@igh-essen.com>
parents:
1838
diff
changeset
|
606 |
req->error_code); |
06fcb795525b
Fixed reading error code from write response.
Florian Pose <fp@igh-essen.com>
parents:
1838
diff
changeset
|
607 |
} |
06fcb795525b
Fixed reading error code from write response.
Florian Pose <fp@igh-essen.com>
parents:
1838
diff
changeset
|
608 |
ec_print_data(data, rec_size); |
06fcb795525b
Fixed reading error code from write response.
Florian Pose <fp@igh-essen.com>
parents:
1838
diff
changeset
|
609 |
fsm->state = ec_fsm_soe_error; |
1837
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
610 |
return; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
611 |
} else { |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
612 |
req->error_code = 0x0000; |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
613 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
614 |
|
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
615 |
fsm->state = ec_fsm_soe_end; // success |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
616 |
} |
32136215c1fa
Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
617 |
|
1831
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
618 |
/*****************************************************************************/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
619 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
620 |
/** State: ERROR. |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
621 |
*/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
622 |
void ec_fsm_soe_error(ec_fsm_soe_t *fsm /**< finite state machine */) |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
623 |
{ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
624 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
625 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
626 |
/*****************************************************************************/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
627 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
628 |
/** State: END. |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
629 |
*/ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
630 |
void ec_fsm_soe_end(ec_fsm_soe_t *fsm /**< finite state machine */) |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
631 |
{ |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
632 |
} |
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
633 |
|
1875b9fea0ba
Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
634 |
/*****************************************************************************/ |