author | Patrick Bruenn <p.bruenn@beckhoff.com> |
Thu, 05 Jun 2014 16:14:13 +0200 | |
branch | stable-1.5 |
changeset 2568 | 2f3078ec9ffb |
parent 2522 | ec403cf308eb |
permissions | -rw-r--r-- |
436 | 1 |
/****************************************************************************** |
2 |
* |
|
3 |
* $Id$ |
|
4 |
* |
|
1326
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
5 |
* Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH |
436 | 6 |
* |
7 |
* This file is part of the IgH EtherCAT Master. |
|
8 |
* |
|
1326
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
9 |
* The IgH EtherCAT Master is free software; you can redistribute it and/or |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
10 |
* modify it under the terms of the GNU General Public License version 2, as |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
11 |
* published by the Free Software Foundation. |
436 | 12 |
* |
1326
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
13 |
* The IgH EtherCAT Master is distributed in the hope that it will be useful, |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
16 |
* Public License for more details. |
436 | 17 |
* |
1326
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
18 |
* You should have received a copy of the GNU General Public License along |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
19 |
* with the IgH EtherCAT Master; if not, write to the Free Software |
436 | 20 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
21 |
* |
|
1363
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1339
diff
changeset
|
22 |
* --- |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1339
diff
changeset
|
23 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1339
diff
changeset
|
24 |
* The license mentioned above concerns the source code only. Using the |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1339
diff
changeset
|
25 |
* EtherCAT technology and brand is only permitted in compliance with the |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1339
diff
changeset
|
26 |
* industrial property and similar rights of Beckhoff Automation GmbH. |
436 | 27 |
* |
28 |
*****************************************************************************/ |
|
29 |
||
2522
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2498
diff
changeset
|
30 |
/** \file |
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2498
diff
changeset
|
31 |
* EtherCAT CoE state machines. |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
32 |
*/ |
436 | 33 |
|
34 |
/*****************************************************************************/ |
|
35 |
||
36 |
#include "globals.h" |
|
37 |
#include "master.h" |
|
38 |
#include "mailbox.h" |
|
39 |
#include "fsm_coe.h" |
|
2438
9c3e629a220c
Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents:
2197
diff
changeset
|
40 |
#include "slave_config.h" |
436 | 41 |
|
42 |
/*****************************************************************************/ |
|
43 |
||
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
44 |
/** Maximum time in ms to wait for responses when reading out the dictionary. |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
45 |
*/ |
1794
94e0e1756dec
Reduced CoE timeouts to 1000 ms.
Florian Pose <fp@igh-essen.com>
parents:
1793
diff
changeset
|
46 |
#define EC_FSM_COE_DICT_TIMEOUT 1000 |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
47 |
|
1907
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
48 |
/** CoE download request header size. |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
49 |
*/ |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
50 |
#define EC_COE_DOWN_REQ_HEADER_SIZE 10 |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
51 |
|
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
52 |
/** CoE download segment request header size. |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
53 |
*/ |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
54 |
#define EC_COE_DOWN_SEG_REQ_HEADER_SIZE 3 |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
55 |
|
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
56 |
/** Minimum size of download segment. |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
57 |
*/ |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
58 |
#define EC_COE_DOWN_SEG_MIN_DATA_SIZE 7 |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
59 |
|
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
60 |
/** Enable debug output for CoE retries. |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
61 |
*/ |
1791
27030c6b2de3
Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents:
1563
diff
changeset
|
62 |
#define DEBUG_RETRIES 0 |
1907
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
63 |
|
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
64 |
/** Enable warning output if transfers take too long. |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
65 |
*/ |
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
66 |
#define DEBUG_LONG 0 |
1791
27030c6b2de3
Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents:
1563
diff
changeset
|
67 |
|
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
68 |
/*****************************************************************************/ |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
69 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
70 |
void ec_fsm_coe_dict_start(ec_fsm_coe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
71 |
void ec_fsm_coe_dict_request(ec_fsm_coe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
72 |
void ec_fsm_coe_dict_check(ec_fsm_coe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
73 |
void ec_fsm_coe_dict_response(ec_fsm_coe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
74 |
void ec_fsm_coe_dict_desc_request(ec_fsm_coe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
75 |
void ec_fsm_coe_dict_desc_check(ec_fsm_coe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
76 |
void ec_fsm_coe_dict_desc_response(ec_fsm_coe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
77 |
void ec_fsm_coe_dict_entry_request(ec_fsm_coe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
78 |
void ec_fsm_coe_dict_entry_check(ec_fsm_coe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
79 |
void ec_fsm_coe_dict_entry_response(ec_fsm_coe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
80 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
81 |
void ec_fsm_coe_down_start(ec_fsm_coe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
82 |
void ec_fsm_coe_down_request(ec_fsm_coe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
83 |
void ec_fsm_coe_down_check(ec_fsm_coe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
84 |
void ec_fsm_coe_down_response(ec_fsm_coe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
85 |
void ec_fsm_coe_down_seg_check(ec_fsm_coe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
86 |
void ec_fsm_coe_down_seg_response(ec_fsm_coe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
87 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
88 |
void ec_fsm_coe_up_start(ec_fsm_coe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
89 |
void ec_fsm_coe_up_request(ec_fsm_coe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
90 |
void ec_fsm_coe_up_check(ec_fsm_coe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
91 |
void ec_fsm_coe_up_response(ec_fsm_coe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
92 |
void ec_fsm_coe_up_seg_request(ec_fsm_coe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
93 |
void ec_fsm_coe_up_seg_check(ec_fsm_coe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
94 |
void ec_fsm_coe_up_seg_response(ec_fsm_coe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
95 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
96 |
void ec_fsm_coe_end(ec_fsm_coe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
97 |
void ec_fsm_coe_error(ec_fsm_coe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
98 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
99 |
/*****************************************************************************/ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
100 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
101 |
/** SDO abort messages. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
102 |
* |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
103 |
* The "abort SDO transfer request" supplies an abort code, which can be |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
104 |
* translated to clear text. This table does the mapping of the codes and |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
105 |
* messages. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
106 |
*/ |
436 | 107 |
const ec_code_msg_t sdo_abort_messages[] = { |
108 |
{0x05030000, "Toggle bit not changed"}, |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
109 |
{0x05040000, "SDO protocol timeout"}, |
436 | 110 |
{0x05040001, "Client/Server command specifier not valid or unknown"}, |
111 |
{0x05040005, "Out of memory"}, |
|
112 |
{0x06010000, "Unsupported access to an object"}, |
|
113 |
{0x06010001, "Attempt to read a write-only object"}, |
|
114 |
{0x06010002, "Attempt to write a read-only object"}, |
|
115 |
{0x06020000, "This object does not exist in the object directory"}, |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
116 |
{0x06040041, "The object cannot be mapped into the PDO"}, |
436 | 117 |
{0x06040042, "The number and length of the objects to be mapped would" |
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
118 |
" exceed the PDO length"}, |
436 | 119 |
{0x06040043, "General parameter incompatibility reason"}, |
120 |
{0x06040047, "Gerneral internal incompatibility in device"}, |
|
121 |
{0x06060000, "Access failure due to a hardware error"}, |
|
122 |
{0x06070010, "Data type does not match, length of service parameter does" |
|
123 |
" not match"}, |
|
124 |
{0x06070012, "Data type does not match, length of service parameter too" |
|
125 |
" high"}, |
|
126 |
{0x06070013, "Data type does not match, length of service parameter too" |
|
127 |
" low"}, |
|
128 |
{0x06090011, "Subindex does not exist"}, |
|
129 |
{0x06090030, "Value range of parameter exceeded"}, |
|
130 |
{0x06090031, "Value of parameter written too high"}, |
|
131 |
{0x06090032, "Value of parameter written too low"}, |
|
132 |
{0x06090036, "Maximum value is less than minimum value"}, |
|
133 |
{0x08000000, "General error"}, |
|
134 |
{0x08000020, "Data cannot be transferred or stored to the application"}, |
|
135 |
{0x08000021, "Data cannot be transferred or stored to the application" |
|
136 |
" because of local control"}, |
|
137 |
{0x08000022, "Data cannot be transferred or stored to the application" |
|
138 |
" because of the present device state"}, |
|
139 |
{0x08000023, "Object dictionary dynamic generation fails or no object" |
|
140 |
" dictionary is present"}, |
|
141 |
{} |
|
142 |
}; |
|
143 |
||
144 |
/*****************************************************************************/ |
|
145 |
||
1921 | 146 |
/** Outputs an SDO abort message. |
147 |
*/ |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
148 |
void ec_canopen_abort_msg( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
149 |
const ec_slave_t *slave, /**< Slave. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
150 |
uint32_t abort_code /**< Abort code to search for. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
151 |
) |
436 | 152 |
{ |
153 |
const ec_code_msg_t *abort_msg; |
|
154 |
||
155 |
for (abort_msg = sdo_abort_messages; abort_msg->code; abort_msg++) { |
|
156 |
if (abort_msg->code == abort_code) { |
|
1921 | 157 |
EC_SLAVE_ERR(slave, "SDO abort message 0x%08X: \"%s\".\n", |
436 | 158 |
abort_msg->code, abort_msg->message); |
159 |
return; |
|
160 |
} |
|
161 |
} |
|
162 |
||
1921 | 163 |
EC_SLAVE_ERR(slave, "Unknown SDO abort code 0x%08X.\n", abort_code); |
436 | 164 |
} |
165 |
||
166 |
/*****************************************************************************/ |
|
167 |
||
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
168 |
/** Constructor. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
169 |
*/ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
170 |
void ec_fsm_coe_init( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
171 |
ec_fsm_coe_t *fsm /**< Finite state machine */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
172 |
) |
436 | 173 |
{ |
174 |
fsm->state = NULL; |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
175 |
fsm->datagram = NULL; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
176 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
177 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
178 |
/*****************************************************************************/ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
179 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
180 |
/** Destructor. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
181 |
*/ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
182 |
void ec_fsm_coe_clear( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
183 |
ec_fsm_coe_t *fsm /**< Finite state machine */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
184 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
185 |
{ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
186 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
187 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
188 |
/*****************************************************************************/ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
189 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
190 |
/** Starts reading a slaves' SDO dictionary. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
191 |
*/ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
192 |
void ec_fsm_coe_dictionary( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
193 |
ec_fsm_coe_t *fsm, /**< Finite state machine */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
194 |
ec_slave_t *slave /**< EtherCAT slave */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
195 |
) |
436 | 196 |
{ |
197 |
fsm->slave = slave; |
|
198 |
fsm->state = ec_fsm_coe_dict_start; |
|
199 |
} |
|
200 |
||
201 |
/*****************************************************************************/ |
|
202 |
||
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
203 |
/** Starts to transfer an SDO to/from a slave. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
204 |
*/ |
859
233e32f428e1
Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents:
854
diff
changeset
|
205 |
void ec_fsm_coe_transfer( |
854
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
206 |
ec_fsm_coe_t *fsm, /**< State machine. */ |
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
207 |
ec_slave_t *slave, /**< EtherCAT slave. */ |
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
208 |
ec_sdo_request_t *request /**< SDO request. */ |
854
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
209 |
) |
436 | 210 |
{ |
211 |
fsm->slave = slave; |
|
854
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
212 |
fsm->request = request; |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
213 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
214 |
if (request->dir == EC_DIR_OUTPUT) { |
859
233e32f428e1
Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents:
854
diff
changeset
|
215 |
fsm->state = ec_fsm_coe_down_start; |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
216 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
217 |
else { |
859
233e32f428e1
Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents:
854
diff
changeset
|
218 |
fsm->state = ec_fsm_coe_up_start; |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
219 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
220 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
221 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
222 |
/*****************************************************************************/ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
223 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
224 |
/** Executes the current state of the state machine. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
225 |
* |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
226 |
* \return 1 if the datagram was used, else 0. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
227 |
*/ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
228 |
int ec_fsm_coe_exec( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
229 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
230 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
231 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
232 |
{ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
233 |
int datagram_used = 0; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
234 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
235 |
if (fsm->datagram && |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
236 |
(fsm->datagram->state == EC_DATAGRAM_INIT || |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
237 |
fsm->datagram->state == EC_DATAGRAM_QUEUED || |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
238 |
fsm->datagram->state == EC_DATAGRAM_SENT)) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
239 |
// datagram not received yet |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
240 |
return datagram_used; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
241 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
242 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
243 |
fsm->state(fsm, datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
244 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
245 |
datagram_used = |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
246 |
fsm->state != ec_fsm_coe_end && fsm->state != ec_fsm_coe_error; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
247 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
248 |
if (datagram_used) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
249 |
fsm->datagram = datagram; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
250 |
} else { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
251 |
fsm->datagram = NULL; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
252 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
253 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
254 |
return datagram_used; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
255 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
256 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
257 |
/*****************************************************************************/ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
258 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
259 |
/** Returns, if the state machine terminated with success. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
260 |
* \return non-zero if successful. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
261 |
*/ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
262 |
int ec_fsm_coe_success( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
263 |
const ec_fsm_coe_t *fsm /**< Finite state machine */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
264 |
) |
436 | 265 |
{ |
266 |
return fsm->state == ec_fsm_coe_end; |
|
267 |
} |
|
268 |
||
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
269 |
/*****************************************************************************/ |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
270 |
|
1092 | 271 |
/** Check if the received data are a CoE emergency request. |
272 |
* |
|
273 |
* If the check is positive, the emergency request is output. |
|
274 |
* |
|
275 |
* \return The data were an emergency request. |
|
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
276 |
*/ |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
277 |
int ec_fsm_coe_check_emergency( |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
278 |
ec_fsm_coe_t *fsm, /**< Finite state machine */ |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
279 |
const uint8_t *data, /**< CoE mailbox data. */ |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
280 |
size_t size /**< CoE mailbox data size. */ |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
281 |
) |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
282 |
{ |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
283 |
if (size < 2 || ((EC_READ_U16(data) >> 12) & 0x0F) != 0x01) |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
284 |
return 0; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
285 |
|
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
286 |
if (size < 10) { |
1921 | 287 |
EC_SLAVE_WARN(fsm->slave, "Received incomplete CoE Emergency" |
288 |
" request:\n"); |
|
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
289 |
ec_print_data(data, size); |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
290 |
return 1; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
291 |
} |
2196
6b481c7b3b34
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
1948
diff
changeset
|
292 |
|
2438
9c3e629a220c
Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents:
2197
diff
changeset
|
293 |
{ |
9c3e629a220c
Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents:
2197
diff
changeset
|
294 |
ec_slave_config_t *sc = fsm->slave->config; |
9c3e629a220c
Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents:
2197
diff
changeset
|
295 |
if (sc) { |
9c3e629a220c
Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents:
2197
diff
changeset
|
296 |
ec_coe_emerg_ring_push(&sc->emerg_ring, data + 2); |
9c3e629a220c
Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents:
2197
diff
changeset
|
297 |
} |
9c3e629a220c
Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents:
2197
diff
changeset
|
298 |
} |
9c3e629a220c
Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents:
2197
diff
changeset
|
299 |
|
1921 | 300 |
EC_SLAVE_WARN(fsm->slave, "CoE Emergency Request received:\n" |
301 |
"Error code 0x%04X, Error register 0x%02X, data:\n", |
|
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
302 |
EC_READ_U16(data + 2), EC_READ_U8(data + 4)); |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
303 |
ec_print_data(data + 5, 5); |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
304 |
return 1; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
305 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
306 |
|
436 | 307 |
/****************************************************************************** |
308 |
* CoE dictionary state machine |
|
309 |
*****************************************************************************/ |
|
310 |
||
2522
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2498
diff
changeset
|
311 |
/** Prepare a dictionary request. |
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2498
diff
changeset
|
312 |
* |
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2498
diff
changeset
|
313 |
* \return Zero on success, otherwise a negative error code. |
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2498
diff
changeset
|
314 |
*/ |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
315 |
int ec_fsm_coe_prepare_dict( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
316 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
317 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
318 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
319 |
{ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
320 |
ec_slave_t *slave = fsm->slave; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
321 |
uint8_t *data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 8); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
322 |
if (IS_ERR(data)) { |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
323 |
return PTR_ERR(data); |
436 | 324 |
} |
325 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
326 |
EC_WRITE_U16(data, 0x8 << 12); // SDO information |
436 | 327 |
EC_WRITE_U8 (data + 2, 0x01); // Get OD List Request |
328 |
EC_WRITE_U8 (data + 3, 0x00); |
|
329 |
EC_WRITE_U16(data + 4, 0x0000); |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
330 |
EC_WRITE_U16(data + 6, 0x0001); // deliver all SDOs! |
436 | 331 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
332 |
fsm->state = ec_fsm_coe_dict_request; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
333 |
return 0; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
334 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
335 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
336 |
/*****************************************************************************/ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
337 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
338 |
/** CoE state: DICT START. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
339 |
*/ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
340 |
void ec_fsm_coe_dict_start( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
341 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
342 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
343 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
344 |
{ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
345 |
ec_slave_t *slave = fsm->slave; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
346 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
347 |
if (!(slave->sii.mailbox_protocols & EC_MBOX_COE)) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
348 |
EC_SLAVE_ERR(slave, "Slave does not support CoE!\n"); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
349 |
fsm->state = ec_fsm_coe_error; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
350 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
351 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
352 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
353 |
if (slave->sii.has_general && !slave->sii.coe_details.enable_sdo_info) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
354 |
EC_SLAVE_ERR(slave, "Slave does not support" |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
355 |
" SDO information service!\n"); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
356 |
fsm->state = ec_fsm_coe_error; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
357 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
358 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
359 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
360 |
fsm->retries = EC_FSM_RETRIES; |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
361 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
362 |
if (ec_fsm_coe_prepare_dict(fsm, datagram)) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
363 |
fsm->state = ec_fsm_coe_error; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
364 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
365 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
366 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
367 |
/*****************************************************************************/ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
368 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
369 |
/** CoE state: DICT REQUEST. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
370 |
* \todo Timeout behavior |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
371 |
*/ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
372 |
void ec_fsm_coe_dict_request( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
373 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
374 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
375 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
376 |
{ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
377 |
ec_slave_t *slave = fsm->slave; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
378 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
379 |
if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
380 |
if (ec_fsm_coe_prepare_dict(fsm, datagram)) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
381 |
fsm->state = ec_fsm_coe_error; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
382 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
383 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
384 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
385 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
386 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
387 |
fsm->state = ec_fsm_coe_error; |
1921 | 388 |
EC_SLAVE_ERR(slave, "Failed to receive CoE dictionary" |
389 |
" request datagram: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
390 |
ec_datagram_print_state(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
391 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
392 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
393 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
394 |
if (fsm->datagram->working_counter != 1) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
395 |
fsm->state = ec_fsm_coe_error; |
1921 | 396 |
EC_SLAVE_ERR(slave, "Reception of CoE dictionary request failed: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
397 |
ec_datagram_print_wc_error(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
398 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
399 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
400 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
401 |
fsm->jiffies_start = fsm->datagram->jiffies_sent; |
436 | 402 |
|
403 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
404 |
fsm->retries = EC_FSM_RETRIES; |
436 | 405 |
fsm->state = ec_fsm_coe_dict_check; |
406 |
} |
|
407 |
||
408 |
/*****************************************************************************/ |
|
409 |
||
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
410 |
/** CoE state: DICT CHECK. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
411 |
*/ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
412 |
void ec_fsm_coe_dict_check( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
413 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
414 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
415 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
416 |
{ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
417 |
ec_slave_t *slave = fsm->slave; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
418 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
419 |
if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
420 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
421 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
422 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
423 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
424 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
425 |
fsm->state = ec_fsm_coe_error; |
1921 | 426 |
EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check datagram: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
427 |
ec_datagram_print_state(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
428 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
429 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
430 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
431 |
if (fsm->datagram->working_counter != 1) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
432 |
fsm->state = ec_fsm_coe_error; |
1921 | 433 |
EC_SLAVE_ERR(slave,"Reception of CoE mailbox check" |
434 |
" datagram failed: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
435 |
ec_datagram_print_wc_error(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
436 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
437 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
438 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
439 |
if (!ec_slave_mbox_check(fsm->datagram)) { |
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
440 |
unsigned long diff_ms = |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
441 |
(fsm->datagram->jiffies_received - fsm->jiffies_start) * |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
442 |
1000 / HZ; |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
443 |
if (diff_ms >= EC_FSM_COE_DICT_TIMEOUT) { |
436 | 444 |
fsm->state = ec_fsm_coe_error; |
1921 | 445 |
EC_SLAVE_ERR(slave, "Timeout while waiting for" |
446 |
" SDO dictionary list response.\n"); |
|
436 | 447 |
return; |
448 |
} |
|
449 |
||
450 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
451 |
fsm->retries = EC_FSM_RETRIES; |
436 | 452 |
return; |
453 |
} |
|
454 |
||
455 |
// Fetch response |
|
456 |
ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
457 |
fsm->retries = EC_FSM_RETRIES; |
436 | 458 |
fsm->state = ec_fsm_coe_dict_response; |
459 |
} |
|
460 |
||
461 |
/*****************************************************************************/ |
|
462 |
||
2522
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2498
diff
changeset
|
463 |
/** Prepare an object description request. |
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2498
diff
changeset
|
464 |
* |
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2498
diff
changeset
|
465 |
* \return Zero on success, otherwise a negative error code. |
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2498
diff
changeset
|
466 |
*/ |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
467 |
int ec_fsm_coe_dict_prepare_desc( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
468 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
469 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
470 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
471 |
{ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
472 |
ec_slave_t *slave = fsm->slave; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
473 |
u8 *data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 8); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
474 |
if (IS_ERR(data)) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
475 |
return PTR_ERR(data); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
476 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
477 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
478 |
EC_WRITE_U16(data, 0x8 << 12); // SDO information |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
479 |
EC_WRITE_U8 (data + 2, 0x03); // Get object description request |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
480 |
EC_WRITE_U8 (data + 3, 0x00); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
481 |
EC_WRITE_U16(data + 4, 0x0000); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
482 |
EC_WRITE_U16(data + 6, fsm->sdo->index); // SDO index |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
483 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
484 |
fsm->state = ec_fsm_coe_dict_desc_request; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
485 |
return 0; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
486 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
487 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
488 |
/*****************************************************************************/ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
489 |
|
436 | 490 |
/** |
491 |
CoE state: DICT RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
492 |
\todo Timeout behavior |
436 | 493 |
*/ |
494 |
||
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
495 |
void ec_fsm_coe_dict_response( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
496 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
497 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
498 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
499 |
{ |
436 | 500 |
ec_slave_t *slave = fsm->slave; |
501 |
uint8_t *data, mbox_prot; |
|
502 |
size_t rec_size; |
|
503 |
unsigned int sdo_count, i; |
|
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
504 |
uint16_t sdo_index, fragments_left; |
436 | 505 |
ec_sdo_t *sdo; |
2196
6b481c7b3b34
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
1948
diff
changeset
|
506 |
bool first_segment; |
6b481c7b3b34
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
1948
diff
changeset
|
507 |
size_t index_list_offset; |
436 | 508 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
509 |
if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
510 |
ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
511 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
512 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
513 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
514 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
515 |
fsm->state = ec_fsm_coe_error; |
1921 | 516 |
EC_SLAVE_ERR(slave, "Failed to receive CoE dictionary" |
517 |
" response datagram: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
518 |
ec_datagram_print_state(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
519 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
520 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
521 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
522 |
if (fsm->datagram->working_counter != 1) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
523 |
fsm->state = ec_fsm_coe_error; |
1921 | 524 |
EC_SLAVE_ERR(slave, "Reception of CoE dictionary response failed: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
525 |
ec_datagram_print_wc_error(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
526 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
527 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
528 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
529 |
data = ec_slave_mbox_fetch(slave, fsm->datagram, &mbox_prot, &rec_size); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
530 |
if (IS_ERR(data)) { |
436 | 531 |
fsm->state = ec_fsm_coe_error; |
532 |
return; |
|
533 |
} |
|
534 |
||
535 |
if (mbox_prot != 0x03) { // CoE |
|
1921 | 536 |
EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n", |
537 |
mbox_prot); |
|
436 | 538 |
fsm->state = ec_fsm_coe_error; |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
539 |
return; |
436 | 540 |
} |
541 |
||
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
542 |
if (ec_fsm_coe_check_emergency(fsm, data, rec_size)) { |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
543 |
// check for CoE response again |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
544 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
545 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
546 |
fsm->state = ec_fsm_coe_dict_check; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
547 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
548 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
549 |
|
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
550 |
if (rec_size < 3) { |
1921 | 551 |
EC_SLAVE_ERR(slave, "Received corrupted SDO dictionary response" |
552 |
" (size %zu).\n", rec_size); |
|
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
553 |
fsm->state = ec_fsm_coe_error; |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
554 |
return; |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
555 |
} |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
556 |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
557 |
if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information |
436 | 558 |
(EC_READ_U8(data + 2) & 0x7F) == 0x07) { // error response |
1921 | 559 |
EC_SLAVE_ERR(slave, "SDO information error response!\n"); |
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
560 |
if (rec_size < 10) { |
1921 | 561 |
EC_SLAVE_ERR(slave, "Incomplete SDO information" |
562 |
" error response:\n"); |
|
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
563 |
ec_print_data(data, rec_size); |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
564 |
} else { |
1921 | 565 |
ec_canopen_abort_msg(slave, EC_READ_U32(data + 6)); |
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
566 |
} |
436 | 567 |
fsm->state = ec_fsm_coe_error; |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
568 |
return; |
436 | 569 |
} |
570 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
571 |
if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information |
436 | 572 |
(EC_READ_U8 (data + 2) & 0x7F) != 0x02) { // Get OD List response |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
573 |
if (fsm->slave->master->debug_level) { |
1921 | 574 |
EC_SLAVE_DBG(slave, 1, "Invalid SDO list response!" |
575 |
" Retrying...\n"); |
|
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
576 |
ec_print_data(data, rec_size); |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
577 |
} |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
578 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
579 |
fsm->retries = EC_FSM_RETRIES; |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
580 |
fsm->state = ec_fsm_coe_dict_check; |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
581 |
return; |
436 | 582 |
} |
583 |
||
2196
6b481c7b3b34
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
1948
diff
changeset
|
584 |
first_segment = list_empty(&slave->sdo_dictionary) ? true : false; |
6b481c7b3b34
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
1948
diff
changeset
|
585 |
index_list_offset = first_segment ? 8 : 6; |
6b481c7b3b34
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
1948
diff
changeset
|
586 |
|
6b481c7b3b34
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
1948
diff
changeset
|
587 |
if (rec_size < index_list_offset || rec_size % 2) { |
1921 | 588 |
EC_SLAVE_ERR(slave, "Invalid data size %zu!\n", rec_size); |
436 | 589 |
ec_print_data(data, rec_size); |
590 |
fsm->state = ec_fsm_coe_error; |
|
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
591 |
return; |
436 | 592 |
} |
593 |
||
2196
6b481c7b3b34
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
1948
diff
changeset
|
594 |
sdo_count = (rec_size - index_list_offset) / 2; |
436 | 595 |
|
596 |
for (i = 0; i < sdo_count; i++) { |
|
2196
6b481c7b3b34
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
1948
diff
changeset
|
597 |
sdo_index = EC_READ_U16(data + index_list_offset + i * 2); |
436 | 598 |
if (!sdo_index) { |
1921 | 599 |
EC_SLAVE_DBG(slave, 1, "SDO dictionary contains index 0x0000.\n"); |
436 | 600 |
continue; |
601 |
} |
|
602 |
||
998
05a24788f3b2
Replaced a few GFP_ATOMIC allocations with GFP_KERNEL ones.
Florian Pose <fp@igh-essen.com>
parents:
992
diff
changeset
|
603 |
if (!(sdo = (ec_sdo_t *) kmalloc(sizeof(ec_sdo_t), GFP_KERNEL))) { |
1921 | 604 |
EC_SLAVE_ERR(slave, "Failed to allocate memory for SDO!\n"); |
436 | 605 |
fsm->state = ec_fsm_coe_error; |
606 |
return; |
|
607 |
} |
|
608 |
||
992
50a44cbd30af
Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents:
991
diff
changeset
|
609 |
ec_sdo_init(sdo, slave, sdo_index); |
436 | 610 |
list_add_tail(&sdo->list, &slave->sdo_dictionary); |
611 |
} |
|
612 |
||
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
613 |
fragments_left = EC_READ_U16(data + 4); |
1923 | 614 |
if (fragments_left) { |
1921 | 615 |
EC_SLAVE_DBG(slave, 1, "SDO list fragments left: %u\n", |
616 |
fragments_left); |
|
617 |
} |
|
618 |
||
619 |
if (EC_READ_U8(data + 2) & 0x80 || fragments_left) { |
|
620 |
// more messages waiting. check again. |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
621 |
fsm->jiffies_start = fsm->datagram->jiffies_sent; |
436 | 622 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
623 |
fsm->retries = EC_FSM_RETRIES; |
436 | 624 |
fsm->state = ec_fsm_coe_dict_check; |
625 |
return; |
|
626 |
} |
|
627 |
||
628 |
if (list_empty(&slave->sdo_dictionary)) { |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
629 |
// no SDOs in dictionary. finished. |
436 | 630 |
fsm->state = ec_fsm_coe_end; // success |
631 |
return; |
|
632 |
} |
|
633 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
634 |
// fetch SDO descriptions |
436 | 635 |
fsm->sdo = list_entry(slave->sdo_dictionary.next, ec_sdo_t, list); |
636 |
||
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
637 |
fsm->retries = EC_FSM_RETRIES; |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
638 |
if (ec_fsm_coe_dict_prepare_desc(fsm, datagram)) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
639 |
fsm->state = ec_fsm_coe_error; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
640 |
} |
436 | 641 |
} |
642 |
||
643 |
/*****************************************************************************/ |
|
644 |
||
645 |
/** |
|
646 |
CoE state: DICT DESC REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
647 |
\todo Timeout behavior |
436 | 648 |
*/ |
649 |
||
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
650 |
void ec_fsm_coe_dict_desc_request( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
651 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
652 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
653 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
654 |
{ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
655 |
ec_slave_t *slave = fsm->slave; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
656 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
657 |
if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
658 |
if (ec_fsm_coe_dict_prepare_desc(fsm, datagram)) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
659 |
fsm->state = ec_fsm_coe_error; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
660 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
661 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
662 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
663 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
664 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
665 |
fsm->state = ec_fsm_coe_error; |
1921 | 666 |
EC_SLAVE_ERR(slave, "Failed to receive CoE SDO" |
667 |
" description request datagram: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
668 |
ec_datagram_print_state(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
669 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
670 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
671 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
672 |
if (fsm->datagram->working_counter != 1) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
673 |
fsm->state = ec_fsm_coe_error; |
1921 | 674 |
EC_SLAVE_ERR(slave, "Reception of CoE SDO description" |
675 |
" request failed: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
676 |
ec_datagram_print_wc_error(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
677 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
678 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
679 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
680 |
fsm->jiffies_start = fsm->datagram->jiffies_sent; |
436 | 681 |
|
682 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
683 |
fsm->retries = EC_FSM_RETRIES; |
436 | 684 |
fsm->state = ec_fsm_coe_dict_desc_check; |
685 |
} |
|
686 |
||
687 |
/*****************************************************************************/ |
|
688 |
||
689 |
/** |
|
690 |
CoE state: DICT DESC CHECK. |
|
691 |
*/ |
|
692 |
||
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
693 |
void ec_fsm_coe_dict_desc_check( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
694 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
695 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
696 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
697 |
{ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
698 |
ec_slave_t *slave = fsm->slave; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
699 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
700 |
if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
701 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
702 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
703 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
704 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
705 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
706 |
fsm->state = ec_fsm_coe_error; |
1921 | 707 |
EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check datagram: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
708 |
ec_datagram_print_state(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
709 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
710 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
711 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
712 |
if (fsm->datagram->working_counter != 1) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
713 |
fsm->state = ec_fsm_coe_error; |
1921 | 714 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox check" |
715 |
" datagram failed: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
716 |
ec_datagram_print_wc_error(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
717 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
718 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
719 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
720 |
if (!ec_slave_mbox_check(fsm->datagram)) { |
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
721 |
unsigned long diff_ms = |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
722 |
(fsm->datagram->jiffies_received - fsm->jiffies_start) * |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
723 |
1000 / HZ; |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
724 |
if (diff_ms >= EC_FSM_COE_DICT_TIMEOUT) { |
436 | 725 |
fsm->state = ec_fsm_coe_error; |
1921 | 726 |
EC_SLAVE_ERR(slave, "Timeout while waiting for" |
727 |
" SDO 0x%04x object description response.\n", |
|
728 |
fsm->sdo->index); |
|
436 | 729 |
return; |
730 |
} |
|
731 |
||
732 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
733 |
fsm->retries = EC_FSM_RETRIES; |
436 | 734 |
return; |
735 |
} |
|
736 |
||
737 |
// Fetch response |
|
738 |
ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
739 |
fsm->retries = EC_FSM_RETRIES; |
436 | 740 |
fsm->state = ec_fsm_coe_dict_desc_response; |
741 |
} |
|
742 |
||
743 |
/*****************************************************************************/ |
|
744 |
||
2522
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2498
diff
changeset
|
745 |
/** Prepare an entry description request. |
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2498
diff
changeset
|
746 |
* |
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2498
diff
changeset
|
747 |
* \return Zero on success, otherwise a negative error code. |
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2498
diff
changeset
|
748 |
*/ |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
749 |
int ec_fsm_coe_dict_prepare_entry( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
750 |
ec_fsm_coe_t *fsm, /**< Finite state machine */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
751 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
752 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
753 |
{ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
754 |
ec_slave_t *slave = fsm->slave; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
755 |
u8 *data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 10); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
756 |
if (IS_ERR(data)) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
757 |
return PTR_ERR(data); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
758 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
759 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
760 |
EC_WRITE_U16(data, 0x8 << 12); // SDO information |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
761 |
EC_WRITE_U8 (data + 2, 0x05); // Get entry description request |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
762 |
EC_WRITE_U8 (data + 3, 0x00); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
763 |
EC_WRITE_U16(data + 4, 0x0000); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
764 |
EC_WRITE_U16(data + 6, fsm->sdo->index); // SDO index |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
765 |
EC_WRITE_U8 (data + 8, fsm->subindex); // SDO subindex |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
766 |
EC_WRITE_U8 (data + 9, 0x01); // value info (access rights only) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
767 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
768 |
fsm->state = ec_fsm_coe_dict_entry_request; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
769 |
return 0; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
770 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
771 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
772 |
/*****************************************************************************/ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
773 |
|
436 | 774 |
/** |
775 |
CoE state: DICT DESC RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
776 |
\todo Timeout behavior |
436 | 777 |
*/ |
778 |
||
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
779 |
void ec_fsm_coe_dict_desc_response( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
780 |
ec_fsm_coe_t *fsm, /**< Finite state machine */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
781 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
782 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
783 |
{ |
436 | 784 |
ec_slave_t *slave = fsm->slave; |
785 |
ec_sdo_t *sdo = fsm->sdo; |
|
786 |
uint8_t *data, mbox_prot; |
|
787 |
size_t rec_size, name_size; |
|
788 |
||
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
789 |
if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
790 |
ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
791 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
792 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
793 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
794 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
795 |
fsm->state = ec_fsm_coe_error; |
1921 | 796 |
EC_SLAVE_ERR(slave, "Failed to receive CoE SDO description" |
797 |
" response datagram: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
798 |
ec_datagram_print_state(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
799 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
800 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
801 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
802 |
if (fsm->datagram->working_counter != 1) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
803 |
fsm->state = ec_fsm_coe_error; |
1921 | 804 |
EC_SLAVE_ERR(slave, "Reception of CoE SDO description" |
805 |
" response failed: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
806 |
ec_datagram_print_wc_error(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
807 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
808 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
809 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
810 |
data = ec_slave_mbox_fetch(slave, fsm->datagram, &mbox_prot, &rec_size); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
811 |
if (IS_ERR(data)) { |
436 | 812 |
fsm->state = ec_fsm_coe_error; |
813 |
return; |
|
814 |
} |
|
815 |
||
816 |
if (mbox_prot != 0x03) { // CoE |
|
1921 | 817 |
EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n", |
818 |
mbox_prot); |
|
436 | 819 |
fsm->state = ec_fsm_coe_error; |
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
820 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
821 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
822 |
|
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
823 |
if (ec_fsm_coe_check_emergency(fsm, data, rec_size)) { |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
824 |
// check for CoE response again |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
825 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
826 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
827 |
fsm->state = ec_fsm_coe_dict_desc_check; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
828 |
return; |
436 | 829 |
} |
830 |
||
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
831 |
if (rec_size < 3) { |
1921 | 832 |
EC_SLAVE_ERR(slave, "Received corrupted SDO description response" |
833 |
" (size %zu).\n", rec_size); |
|
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
834 |
fsm->state = ec_fsm_coe_error; |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
835 |
return; |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
836 |
} |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
837 |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
838 |
if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information |
436 | 839 |
(EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // error response |
1921 | 840 |
EC_SLAVE_ERR(slave, "SDO information error response while" |
841 |
" fetching SDO 0x%04X!\n", sdo->index); |
|
842 |
ec_canopen_abort_msg(slave, EC_READ_U32(data + 6)); |
|
436 | 843 |
fsm->state = ec_fsm_coe_error; |
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
844 |
return; |
436 | 845 |
} |
846 |
||
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
847 |
if (rec_size < 8) { |
1921 | 848 |
EC_SLAVE_ERR(slave, "Received corrupted SDO" |
849 |
" description response (size %zu).\n", rec_size); |
|
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
850 |
fsm->state = ec_fsm_coe_error; |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
851 |
return; |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
852 |
} |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
853 |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
854 |
if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information |
436 | 855 |
(EC_READ_U8 (data + 2) & 0x7F) != 0x04 || // Object desc. response |
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
856 |
EC_READ_U16(data + 6) != sdo->index) { // SDO index |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
857 |
if (fsm->slave->master->debug_level) { |
1921 | 858 |
EC_SLAVE_DBG(slave, 1, "Invalid object description response while" |
859 |
" fetching SDO 0x%04X!\n", sdo->index); |
|
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
860 |
ec_print_data(data, rec_size); |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
861 |
} |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
862 |
// check for CoE response again |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
863 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
864 |
fsm->retries = EC_FSM_RETRIES; |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
865 |
fsm->state = ec_fsm_coe_dict_desc_check; |
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
866 |
return; |
436 | 867 |
} |
868 |
||
869 |
if (rec_size < 12) { |
|
1921 | 870 |
EC_SLAVE_ERR(slave, "Invalid data size!\n"); |
436 | 871 |
ec_print_data(data, rec_size); |
872 |
fsm->state = ec_fsm_coe_error; |
|
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
873 |
return; |
436 | 874 |
} |
875 |
||
962
ea83a7aab57a
Renamed subindices to max_subindex.
Florian Pose <fp@igh-essen.com>
parents:
926
diff
changeset
|
876 |
sdo->max_subindex = EC_READ_U8(data + 10); |
436 | 877 |
sdo->object_code = EC_READ_U8(data + 11); |
878 |
||
879 |
name_size = rec_size - 12; |
|
880 |
if (name_size) { |
|
998
05a24788f3b2
Replaced a few GFP_ATOMIC allocations with GFP_KERNEL ones.
Florian Pose <fp@igh-essen.com>
parents:
992
diff
changeset
|
881 |
if (!(sdo->name = kmalloc(name_size + 1, GFP_KERNEL))) { |
1921 | 882 |
EC_SLAVE_ERR(slave, "Failed to allocate SDO name!\n"); |
436 | 883 |
fsm->state = ec_fsm_coe_error; |
884 |
return; |
|
885 |
} |
|
886 |
||
887 |
memcpy(sdo->name, data + 12, name_size); |
|
888 |
sdo->name[name_size] = 0; |
|
889 |
} |
|
890 |
||
891 |
if (EC_READ_U8(data + 2) & 0x80) { |
|
1921 | 892 |
EC_SLAVE_ERR(slave, "Fragment follows (not implemented)!\n"); |
436 | 893 |
fsm->state = ec_fsm_coe_error; |
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
894 |
return; |
436 | 895 |
} |
896 |
||
897 |
// start fetching entries |
|
898 |
||
899 |
fsm->subindex = 0; |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
900 |
fsm->retries = EC_FSM_RETRIES; |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
901 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
902 |
if (ec_fsm_coe_dict_prepare_entry(fsm, datagram)) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
903 |
fsm->state = ec_fsm_coe_error; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
904 |
} |
436 | 905 |
} |
906 |
||
907 |
/*****************************************************************************/ |
|
908 |
||
909 |
/** |
|
910 |
CoE state: DICT ENTRY REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
911 |
\todo Timeout behavior |
436 | 912 |
*/ |
913 |
||
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
914 |
void ec_fsm_coe_dict_entry_request( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
915 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
916 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
917 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
918 |
{ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
919 |
ec_slave_t *slave = fsm->slave; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
920 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
921 |
if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
922 |
if (ec_fsm_coe_dict_prepare_entry(fsm, datagram)) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
923 |
fsm->state = ec_fsm_coe_error; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
924 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
925 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
926 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
927 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
928 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
929 |
fsm->state = ec_fsm_coe_error; |
1921 | 930 |
EC_SLAVE_ERR(slave, "Failed to receive CoE SDO entry" |
931 |
" request datagram: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
932 |
ec_datagram_print_state(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
933 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
934 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
935 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
936 |
if (fsm->datagram->working_counter != 1) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
937 |
fsm->state = ec_fsm_coe_error; |
1921 | 938 |
EC_SLAVE_ERR(slave, "Reception of CoE SDO entry request failed: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
939 |
ec_datagram_print_wc_error(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
940 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
941 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
942 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
943 |
fsm->jiffies_start = fsm->datagram->jiffies_sent; |
436 | 944 |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
945 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
946 |
fsm->retries = EC_FSM_RETRIES; |
436 | 947 |
fsm->state = ec_fsm_coe_dict_entry_check; |
948 |
} |
|
949 |
||
950 |
/*****************************************************************************/ |
|
951 |
||
952 |
/** |
|
953 |
CoE state: DICT ENTRY CHECK. |
|
954 |
*/ |
|
955 |
||
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
956 |
void ec_fsm_coe_dict_entry_check( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
957 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
958 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
959 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
960 |
{ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
961 |
ec_slave_t *slave = fsm->slave; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
962 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
963 |
if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
964 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
965 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
966 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
967 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
968 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
969 |
fsm->state = ec_fsm_coe_error; |
1921 | 970 |
EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check datagram: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
971 |
ec_datagram_print_state(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
972 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
973 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
974 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
975 |
if (fsm->datagram->working_counter != 1) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
976 |
fsm->state = ec_fsm_coe_error; |
1921 | 977 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox check" |
978 |
" datagram failed: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
979 |
ec_datagram_print_wc_error(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
980 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
981 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
982 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
983 |
if (!ec_slave_mbox_check(fsm->datagram)) { |
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
984 |
unsigned long diff_ms = |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
985 |
(fsm->datagram->jiffies_received - fsm->jiffies_start) * |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
986 |
1000 / HZ; |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
987 |
if (diff_ms >= EC_FSM_COE_DICT_TIMEOUT) { |
436 | 988 |
fsm->state = ec_fsm_coe_error; |
1921 | 989 |
EC_SLAVE_ERR(slave, "Timeout while waiting for" |
990 |
" SDO entry 0x%04x:%x description response.\n", |
|
991 |
fsm->sdo->index, fsm->subindex); |
|
436 | 992 |
return; |
993 |
} |
|
994 |
||
995 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
996 |
fsm->retries = EC_FSM_RETRIES; |
436 | 997 |
return; |
998 |
} |
|
999 |
||
1000 |
// Fetch response |
|
1001 |
ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1002 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1003 |
fsm->state = ec_fsm_coe_dict_entry_response; |
1004 |
} |
|
1005 |
||
1006 |
/*****************************************************************************/ |
|
1007 |
||
1008 |
/** |
|
1009 |
CoE state: DICT ENTRY RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1010 |
\todo Timeout behavior |
436 | 1011 |
*/ |
1012 |
||
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1013 |
void ec_fsm_coe_dict_entry_response( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1014 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1015 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1016 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1017 |
{ |
436 | 1018 |
ec_slave_t *slave = fsm->slave; |
1019 |
ec_sdo_t *sdo = fsm->sdo; |
|
1020 |
uint8_t *data, mbox_prot; |
|
1021 |
size_t rec_size, data_size; |
|
1022 |
ec_sdo_entry_t *entry; |
|
1382
cb2188d111f3
Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
1023 |
u16 word; |
436 | 1024 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1025 |
if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1026 |
ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1027 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1028 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1029 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1030 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1031 |
fsm->state = ec_fsm_coe_error; |
1921 | 1032 |
EC_SLAVE_ERR(slave, "Failed to receive CoE SDO" |
1033 |
" description response datagram: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1034 |
ec_datagram_print_state(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1035 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1036 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1037 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1038 |
if (fsm->datagram->working_counter != 1) { |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1039 |
fsm->state = ec_fsm_coe_error; |
1921 | 1040 |
EC_SLAVE_ERR(slave, "Reception of CoE SDO description" |
1041 |
" response failed: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1042 |
ec_datagram_print_wc_error(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1043 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1044 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1045 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1046 |
data = ec_slave_mbox_fetch(slave, fsm->datagram, &mbox_prot, &rec_size); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1047 |
if (IS_ERR(data)) { |
436 | 1048 |
fsm->state = ec_fsm_coe_error; |
1049 |
return; |
|
1050 |
} |
|
1051 |
||
1052 |
if (mbox_prot != 0x03) { // CoE |
|
1921 | 1053 |
EC_SLAVE_ERR(slave, "Received mailbox protocol" |
1054 |
" 0x%02X as response.\n", mbox_prot); |
|
436 | 1055 |
fsm->state = ec_fsm_coe_error; |
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1056 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1057 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1058 |
|
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1059 |
if (ec_fsm_coe_check_emergency(fsm, data, rec_size)) { |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1060 |
// check for CoE response again |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1061 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1062 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1063 |
fsm->state = ec_fsm_coe_dict_entry_check; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1064 |
return; |
436 | 1065 |
} |
1066 |
||
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
1067 |
if (rec_size < 3) { |
1921 | 1068 |
EC_SLAVE_ERR(slave, "Received corrupted SDO entry" |
1069 |
" description response (size %zu).\n", rec_size); |
|
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
1070 |
fsm->state = ec_fsm_coe_error; |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
1071 |
return; |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
1072 |
} |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
1073 |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1074 |
if (EC_READ_U16(data) >> 12 == 0x8 && // SDO information |
436 | 1075 |
(EC_READ_U8 (data + 2) & 0x7F) == 0x07) { // error response |
2197
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1076 |
EC_SLAVE_WARN(slave, "SDO information error response while" |
1921 | 1077 |
" fetching SDO entry 0x%04X:%02X!\n", |
436 | 1078 |
sdo->index, fsm->subindex); |
1921 | 1079 |
ec_canopen_abort_msg(slave, EC_READ_U32(data + 6)); |
2197
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1080 |
|
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1081 |
/* There may be gaps in the subindices, so try to continue with next |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1082 |
* subindex. */ |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1083 |
|
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1084 |
} else { |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1085 |
|
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1086 |
if (rec_size < 9) { |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1087 |
EC_SLAVE_ERR(slave, "Received corrupted SDO entry" |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1088 |
" description response (size %zu).\n", rec_size); |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1089 |
fsm->state = ec_fsm_coe_error; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1090 |
return; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1091 |
} |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1092 |
|
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1093 |
if (EC_READ_U16(data) >> 12 != 0x8 || // SDO information |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1094 |
(EC_READ_U8(data + 2) & 0x7F) != 0x06 || // Entry desc. response |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1095 |
EC_READ_U16(data + 6) != sdo->index || // SDO index |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1096 |
EC_READ_U8(data + 8) != fsm->subindex) { // SDO subindex |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1097 |
if (fsm->slave->master->debug_level) { |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1098 |
EC_SLAVE_DBG(slave, 1, "Invalid entry description response" |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1099 |
" while fetching SDO entry 0x%04X:%02X!\n", |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1100 |
sdo->index, fsm->subindex); |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1101 |
ec_print_data(data, rec_size); |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1102 |
} |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1103 |
// check for CoE response again |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1104 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1105 |
fsm->retries = EC_FSM_RETRIES; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1106 |
fsm->state = ec_fsm_coe_dict_entry_check; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1107 |
return; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1108 |
} |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1109 |
|
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1110 |
if (rec_size < 16) { |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1111 |
EC_SLAVE_ERR(slave, "Invalid data size %zu!\n", rec_size); |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1112 |
ec_print_data(data, rec_size); |
436 | 1113 |
fsm->state = ec_fsm_coe_error; |
1114 |
return; |
|
1115 |
} |
|
2197
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1116 |
|
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1117 |
data_size = rec_size - 16; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1118 |
|
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1119 |
if (!(entry = (ec_sdo_entry_t *) |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1120 |
kmalloc(sizeof(ec_sdo_entry_t), GFP_KERNEL))) { |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1121 |
EC_SLAVE_ERR(slave, "Failed to allocate entry!\n"); |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1122 |
fsm->state = ec_fsm_coe_error; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1123 |
return; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1124 |
} |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1125 |
|
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1126 |
ec_sdo_entry_init(entry, sdo, fsm->subindex); |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1127 |
entry->data_type = EC_READ_U16(data + 10); |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1128 |
entry->bit_length = EC_READ_U16(data + 12); |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1129 |
|
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1130 |
// read access rights |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1131 |
word = EC_READ_U16(data + 14); |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1132 |
entry->read_access[EC_SDO_ENTRY_ACCESS_PREOP] = word & 0x0001; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1133 |
entry->read_access[EC_SDO_ENTRY_ACCESS_SAFEOP] = |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1134 |
(word >> 1) & 0x0001; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1135 |
entry->read_access[EC_SDO_ENTRY_ACCESS_OP] = (word >> 2) & 0x0001; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1136 |
entry->write_access[EC_SDO_ENTRY_ACCESS_PREOP] = (word >> 3) & 0x0001; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1137 |
entry->write_access[EC_SDO_ENTRY_ACCESS_SAFEOP] = |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1138 |
(word >> 4) & 0x0001; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1139 |
entry->write_access[EC_SDO_ENTRY_ACCESS_OP] = (word >> 5) & 0x0001; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1140 |
|
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1141 |
if (data_size) { |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1142 |
uint8_t *desc; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1143 |
if (!(desc = kmalloc(data_size + 1, GFP_KERNEL))) { |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1144 |
EC_SLAVE_ERR(slave, "Failed to allocate SDO entry name!\n"); |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1145 |
fsm->state = ec_fsm_coe_error; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1146 |
return; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1147 |
} |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1148 |
memcpy(desc, data + 16, data_size); |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1149 |
desc[data_size] = 0; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1150 |
entry->description = desc; |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1151 |
} |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1152 |
|
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1153 |
list_add_tail(&entry->list, &sdo->entries); |
53b92e797e64
Allow gaps between SDO subindices when fetching dictionary.
Florian Pose <fp@igh-essen.com>
parents:
2196
diff
changeset
|
1154 |
} |
436 | 1155 |
|
962
ea83a7aab57a
Renamed subindices to max_subindex.
Florian Pose <fp@igh-essen.com>
parents:
926
diff
changeset
|
1156 |
if (fsm->subindex < sdo->max_subindex) { |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1157 |
|
436 | 1158 |
fsm->subindex++; |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1159 |
fsm->retries = EC_FSM_RETRIES; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1160 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1161 |
if (ec_fsm_coe_dict_prepare_entry(fsm, datagram)) { |
436 | 1162 |
fsm->state = ec_fsm_coe_error; |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1163 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1164 |
|
436 | 1165 |
return; |
1166 |
} |
|
1167 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1168 |
// another SDO description to fetch? |
436 | 1169 |
if (fsm->sdo->list.next != &slave->sdo_dictionary) { |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1170 |
|
436 | 1171 |
fsm->sdo = list_entry(fsm->sdo->list.next, ec_sdo_t, list); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1172 |
fsm->retries = EC_FSM_RETRIES; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1173 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1174 |
if (ec_fsm_coe_dict_prepare_desc(fsm, datagram)) { |
436 | 1175 |
fsm->state = ec_fsm_coe_error; |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1176 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1177 |
|
436 | 1178 |
return; |
1179 |
} |
|
1180 |
||
1181 |
fsm->state = ec_fsm_coe_end; |
|
1182 |
} |
|
1183 |
||
1184 |
/****************************************************************************** |
|
1185 |
* CoE state machine |
|
1186 |
*****************************************************************************/ |
|
1187 |
||
2522
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2498
diff
changeset
|
1188 |
/** Prepare a donwnload request. |
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2498
diff
changeset
|
1189 |
* |
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2498
diff
changeset
|
1190 |
* \return Zero on success, otherwise a negative error code. |
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2498
diff
changeset
|
1191 |
*/ |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1192 |
int ec_fsm_coe_prepare_down_start( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1193 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1194 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1195 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1196 |
{ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1197 |
u8 *data; |
436 | 1198 |
ec_slave_t *slave = fsm->slave; |
854
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
1199 |
ec_sdo_request_t *request = fsm->request; |
1562 | 1200 |
uint8_t data_set_size; |
436 | 1201 |
|
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1202 |
if (request->data_size <= 4) { // use expedited transfer type |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1203 |
data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1204 |
EC_COE_DOWN_REQ_HEADER_SIZE); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1205 |
if (IS_ERR(data)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1206 |
request->errno = PTR_ERR(data); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1207 |
return PTR_ERR(data); |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1208 |
} |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1209 |
|
1562 | 1210 |
fsm->remaining = 0; |
1211 |
||
1212 |
data_set_size = 4 - request->data_size; |
|
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1213 |
|
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1214 |
EC_WRITE_U16(data, 0x2 << 12); // SDO request |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1215 |
EC_WRITE_U8 (data + 2, (0x3 // size specified, expedited |
1562 | 1216 |
| data_set_size << 2 |
2196
6b481c7b3b34
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
1948
diff
changeset
|
1217 |
| ((request->complete_access ? 1 : 0) << 4) |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1218 |
| 0x1 << 5)); // Download request |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1219 |
EC_WRITE_U16(data + 3, request->index); |
1526
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1220 |
EC_WRITE_U8 (data + 5, |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1221 |
request->complete_access ? 0x00 : request->subindex); |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1222 |
memcpy(data + 6, request->data, request->data_size); |
1457
ec3ad6641d65
Slightly improved CoE download expedited request.
Florian Pose <fp@igh-essen.com>
parents:
1382
diff
changeset
|
1223 |
memset(data + 6 + request->data_size, 0x00, 4 - request->data_size); |
1169
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1224 |
|
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1225 |
if (slave->master->debug_level) { |
1921 | 1226 |
EC_SLAVE_DBG(slave, 1, "Expedited download request:\n"); |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1227 |
ec_print_data(data, EC_COE_DOWN_REQ_HEADER_SIZE); |
1169
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1228 |
} |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1229 |
} |
1169
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1230 |
else { // request->data_size > 4, use normal transfer type |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1231 |
size_t data_size, |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1232 |
max_data_size = |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1233 |
slave->configured_rx_mailbox_size - EC_MBOX_HEADER_SIZE, |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1234 |
required_data_size = |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1235 |
EC_COE_DOWN_REQ_HEADER_SIZE + request->data_size; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1236 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1237 |
if (max_data_size < required_data_size) { |
1562 | 1238 |
// segmenting needed |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1239 |
data_size = max_data_size; |
1562 | 1240 |
} else { |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1241 |
data_size = required_data_size; |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1242 |
} |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1243 |
|
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1244 |
data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, |
1562 | 1245 |
data_size); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1246 |
if (IS_ERR(data)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1247 |
request->errno = PTR_ERR(data); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1248 |
return PTR_ERR(data); |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1249 |
} |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1250 |
|
1562 | 1251 |
fsm->offset = 0; |
1252 |
fsm->remaining = request->data_size; |
|
1253 |
||
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1254 |
EC_WRITE_U16(data, 0x2 << 12); // SDO request |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1255 |
EC_WRITE_U8(data + 2, |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1256 |
0x1 // size indicator, normal |
2196
6b481c7b3b34
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
1948
diff
changeset
|
1257 |
| ((request->complete_access ? 1 : 0) << 4) |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1258 |
| 0x1 << 5); // Download request |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1259 |
EC_WRITE_U16(data + 3, request->index); |
1526
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1260 |
EC_WRITE_U8 (data + 5, |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1261 |
request->complete_access ? 0x00 : request->subindex); |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1262 |
EC_WRITE_U32(data + 6, request->data_size); |
1562 | 1263 |
|
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1264 |
if (data_size > EC_COE_DOWN_REQ_HEADER_SIZE) { |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1265 |
size_t segment_size = data_size - EC_COE_DOWN_REQ_HEADER_SIZE; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1266 |
memcpy(data + EC_COE_DOWN_REQ_HEADER_SIZE, |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1267 |
request->data, segment_size); |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1268 |
fsm->offset += segment_size; |
1562 | 1269 |
fsm->remaining -= segment_size; |
1270 |
} |
|
1169
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1271 |
|
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1272 |
if (slave->master->debug_level) { |
1921 | 1273 |
EC_SLAVE_DBG(slave, 1, "Normal download request:\n"); |
1562 | 1274 |
ec_print_data(data, data_size); |
1169
cf0b5293eea6
Use expedited transfer type for Sdos <= 4 byte.
Florian Pose <fp@igh-essen.com>
parents:
1112
diff
changeset
|
1275 |
} |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1498
diff
changeset
|
1276 |
} |
975
dae04112bcc7
Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents:
962
diff
changeset
|
1277 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1278 |
fsm->state = ec_fsm_coe_down_request; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1279 |
return 0; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1280 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1281 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1282 |
/****************************************************************************/ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1283 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1284 |
/** CoE state: DOWN START. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1285 |
*/ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1286 |
void ec_fsm_coe_down_start( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1287 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1288 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1289 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1290 |
{ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1291 |
ec_slave_t *slave = fsm->slave; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1292 |
ec_sdo_request_t *request = fsm->request; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1293 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1294 |
if (fsm->slave->master->debug_level) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1295 |
char subidxstr[10]; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1296 |
if (request->complete_access) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1297 |
subidxstr[0] = 0x00; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1298 |
} else { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1299 |
sprintf(subidxstr, ":%02X", request->subindex); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1300 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1301 |
EC_SLAVE_DBG(slave, 1, "Downloading SDO 0x%04X%s.\n", |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1302 |
request->index, subidxstr); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1303 |
ec_print_data(request->data, request->data_size); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1304 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1305 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1306 |
if (!(slave->sii.mailbox_protocols & EC_MBOX_COE)) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1307 |
EC_SLAVE_ERR(slave, "Slave does not support CoE!\n"); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1308 |
request->errno = EPROTONOSUPPORT; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1309 |
fsm->state = ec_fsm_coe_error; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1310 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1311 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1312 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1313 |
if (slave->configured_rx_mailbox_size < |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1314 |
EC_MBOX_HEADER_SIZE + EC_COE_DOWN_REQ_HEADER_SIZE) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1315 |
EC_SLAVE_ERR(slave, "Mailbox too small!\n"); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1316 |
request->errno = EOVERFLOW; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1317 |
fsm->state = ec_fsm_coe_error; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1318 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1319 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1320 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1321 |
|
1035
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1322 |
fsm->request->jiffies_sent = jiffies; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1323 |
fsm->retries = EC_FSM_RETRIES; |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1324 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1325 |
if (ec_fsm_coe_prepare_down_start(fsm, datagram)) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1326 |
fsm->state = ec_fsm_coe_error; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1327 |
} |
436 | 1328 |
} |
1329 |
||
1330 |
/*****************************************************************************/ |
|
1331 |
||
1332 |
/** |
|
1333 |
CoE state: DOWN REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1334 |
\todo Timeout behavior |
436 | 1335 |
*/ |
1336 |
||
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1337 |
void ec_fsm_coe_down_request( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1338 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1339 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1340 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1341 |
{ |
436 | 1342 |
ec_slave_t *slave = fsm->slave; |
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1343 |
unsigned long diff_ms; |
436 | 1344 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1345 |
if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1346 |
if (ec_fsm_coe_prepare_down_start(fsm, datagram)) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1347 |
fsm->state = ec_fsm_coe_error; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1348 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1349 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1350 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1351 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1352 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1353 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1354 |
fsm->state = ec_fsm_coe_error; |
1921 | 1355 |
EC_SLAVE_ERR(slave, "Failed to receive CoE download" |
1356 |
" request datagram: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1357 |
ec_datagram_print_state(fsm->datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1358 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1359 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1360 |
|
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1361 |
diff_ms = (jiffies - fsm->request->jiffies_sent) * 1000 / HZ; |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1362 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1363 |
if (fsm->datagram->working_counter != 1) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1364 |
if (!fsm->datagram->working_counter) { |
1035
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1365 |
if (diff_ms < fsm->request->response_timeout) { |
1791
27030c6b2de3
Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents:
1563
diff
changeset
|
1366 |
#if DEBUG_RETRIES |
1931 | 1367 |
EC_SLAVE_DBG(slave, 1, "Slave did not respond to SDO" |
1368 |
" download request. Retrying after %lu ms...\n", |
|
1369 |
diff_ms); |
|
1791
27030c6b2de3
Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents:
1563
diff
changeset
|
1370 |
#endif |
1112
d11661e1f4de
Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents:
1111
diff
changeset
|
1371 |
// no response; send request datagram again |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1372 |
if (ec_fsm_coe_prepare_down_start(fsm, datagram)) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1373 |
fsm->state = ec_fsm_coe_error; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1374 |
} |
1112
d11661e1f4de
Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents:
1111
diff
changeset
|
1375 |
return; |
1035
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1376 |
} |
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1377 |
} |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1378 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1379 |
fsm->state = ec_fsm_coe_error; |
1921 | 1380 |
EC_SLAVE_ERR(slave, "Reception of CoE download request" |
1931 | 1381 |
" for SDO 0x%04x:%x failed with timeout after %lu ms: ", |
1382 |
fsm->request->index, fsm->request->subindex, diff_ms); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1383 |
ec_datagram_print_wc_error(fsm->datagram); |
436 | 1384 |
return; |
1385 |
} |
|
1386 |
||
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1387 |
#if DEBUG_LONG |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1388 |
if (diff_ms > 200) { |
1931 | 1389 |
EC_SLAVE_WARN(slave, "SDO 0x%04x:%x download took %lu ms.\n", |
1390 |
fsm->request->index, fsm->request->subindex, diff_ms); |
|
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1391 |
} |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1392 |
#endif |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1393 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1394 |
fsm->jiffies_start = fsm->datagram->jiffies_sent; |
436 | 1395 |
|
1396 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1397 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1398 |
fsm->state = ec_fsm_coe_down_check; |
1399 |
} |
|
1400 |
||
1401 |
/*****************************************************************************/ |
|
1402 |
||
1907
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
1403 |
/** CoE state: DOWN CHECK. |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
1404 |
*/ |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1405 |
void ec_fsm_coe_down_check( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1406 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1407 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1408 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1409 |
{ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1410 |
ec_slave_t *slave = fsm->slave; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1411 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1412 |
if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1413 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1414 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1415 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1416 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1417 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1418 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1419 |
fsm->state = ec_fsm_coe_error; |
1921 | 1420 |
EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check" |
1421 |
" datagram: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1422 |
ec_datagram_print_state(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1423 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1424 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1425 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1426 |
if (fsm->datagram->working_counter != 1) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1427 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1428 |
fsm->state = ec_fsm_coe_error; |
1921 | 1429 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox check" |
1430 |
" datagram failed: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1431 |
ec_datagram_print_wc_error(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1432 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1433 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1434 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1435 |
if (!ec_slave_mbox_check(fsm->datagram)) { |
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
1436 |
unsigned long diff_ms = |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1437 |
(fsm->datagram->jiffies_received - fsm->jiffies_start) * |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1438 |
1000 / HZ; |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1439 |
if (diff_ms >= fsm->request->response_timeout) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1440 |
fsm->request->errno = EIO; |
436 | 1441 |
fsm->state = ec_fsm_coe_error; |
1931 | 1442 |
EC_SLAVE_ERR(slave, "Timeout after %lu ms while waiting" |
1443 |
" for SDO 0x%04x:%x download response.\n", diff_ms, |
|
1921 | 1444 |
fsm->request->index, fsm->request->subindex); |
436 | 1445 |
return; |
1446 |
} |
|
1447 |
||
1448 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1449 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1450 |
return; |
1451 |
} |
|
1452 |
||
1453 |
// Fetch response |
|
1454 |
ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1455 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1456 |
fsm->state = ec_fsm_coe_down_response; |
1457 |
} |
|
1458 |
||
1459 |
/*****************************************************************************/ |
|
1460 |
||
1907
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
1461 |
/** Prepare a download segment request. |
dd276ae226b4
Added missing code documentation.
Florian Pose <fp@igh-essen.com>
parents:
1831
diff
changeset
|
1462 |
*/ |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1463 |
void ec_fsm_coe_down_prepare_segment_request( |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1464 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1465 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1466 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1467 |
{ |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1468 |
ec_slave_t *slave = fsm->slave; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1469 |
ec_sdo_request_t *request = fsm->request; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1470 |
size_t max_segment_size = |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1471 |
slave->configured_rx_mailbox_size |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1472 |
- EC_MBOX_HEADER_SIZE |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1473 |
- EC_COE_DOWN_SEG_REQ_HEADER_SIZE; |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1474 |
size_t data_size; |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1475 |
uint8_t last_segment, seg_data_size, *data; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1476 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1477 |
if (fsm->remaining > max_segment_size) { |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1478 |
fsm->segment_size = max_segment_size; |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1479 |
last_segment = 0; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1480 |
} else { |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1481 |
fsm->segment_size = fsm->remaining; |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1482 |
last_segment = 1; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1483 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1484 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1485 |
if (fsm->segment_size > EC_COE_DOWN_SEG_MIN_DATA_SIZE) { |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1486 |
seg_data_size = 0x00; |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1487 |
data_size = EC_COE_DOWN_SEG_REQ_HEADER_SIZE + fsm->segment_size; |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1488 |
} else { |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1489 |
seg_data_size = EC_COE_DOWN_SEG_MIN_DATA_SIZE - fsm->segment_size; |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1490 |
data_size = EC_COE_DOWN_SEG_REQ_HEADER_SIZE |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1491 |
+ EC_COE_DOWN_SEG_MIN_DATA_SIZE; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1492 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1493 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1494 |
data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1495 |
data_size); |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1496 |
if (IS_ERR(data)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1497 |
request->errno = PTR_ERR(data); |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1498 |
fsm->state = ec_fsm_coe_error; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1499 |
return; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1500 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1501 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1502 |
EC_WRITE_U16(data, 0x2 << 12); // SDO request |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1503 |
EC_WRITE_U8(data + 2, (last_segment ? 1 : 0) |
2196
6b481c7b3b34
Allow CoE OD List Segments to have 6 bytes instead of 8.
Florian Pose <fp@igh-essen.com>
parents:
1948
diff
changeset
|
1504 |
| (seg_data_size << 1) |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1505 |
| (fsm->toggle << 4) |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1506 |
| (0x00 << 5)); // Download segment request |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1507 |
memcpy(data + EC_COE_DOWN_SEG_REQ_HEADER_SIZE, |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1508 |
request->data + fsm->offset, fsm->segment_size); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1509 |
if (fsm->segment_size < EC_COE_DOWN_SEG_MIN_DATA_SIZE) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1510 |
memset(data + EC_COE_DOWN_SEG_REQ_HEADER_SIZE + fsm->segment_size, |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1511 |
0x00, EC_COE_DOWN_SEG_MIN_DATA_SIZE - fsm->segment_size); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1512 |
} |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1513 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1514 |
if (slave->master->debug_level) { |
1921 | 1515 |
EC_SLAVE_DBG(slave, 1, "Download segment request:\n"); |
1563
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1516 |
ec_print_data(data, data_size); |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1517 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1518 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1519 |
fsm->state = ec_fsm_coe_down_seg_check; |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1520 |
} |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1521 |
|
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1522 |
/*****************************************************************************/ |
ddedb71b3a85
Introduced mailbox/CoE defines; avoided duplicate code in CoE segmented
Florian Pose <fp@igh-essen.com>
parents:
1562
diff
changeset
|
1523 |
|
436 | 1524 |
/** |
1525 |
CoE state: DOWN RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1526 |
\todo Timeout behavior |
436 | 1527 |
*/ |
1528 |
||
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1529 |
void ec_fsm_coe_down_response( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1530 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1531 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1532 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1533 |
{ |
436 | 1534 |
ec_slave_t *slave = fsm->slave; |
1535 |
uint8_t *data, mbox_prot; |
|
1536 |
size_t rec_size; |
|
854
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
1537 |
ec_sdo_request_t *request = fsm->request; |
436 | 1538 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1539 |
if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1540 |
ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1541 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1542 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1543 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1544 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1545 |
request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1546 |
fsm->state = ec_fsm_coe_error; |
1921 | 1547 |
EC_SLAVE_ERR(slave, "Failed to receive CoE download" |
1548 |
" response datagram: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1549 |
ec_datagram_print_state(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1550 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1551 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1552 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1553 |
if (fsm->datagram->working_counter != 1) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1554 |
request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1555 |
fsm->state = ec_fsm_coe_error; |
1921 | 1556 |
EC_SLAVE_ERR(slave, "Reception of CoE download response failed: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1557 |
ec_datagram_print_wc_error(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1558 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1559 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1560 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1561 |
data = ec_slave_mbox_fetch(slave, fsm->datagram, &mbox_prot, &rec_size); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1562 |
if (IS_ERR(data)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1563 |
request->errno = PTR_ERR(data); |
436 | 1564 |
fsm->state = ec_fsm_coe_error; |
1565 |
return; |
|
1566 |
} |
|
1567 |
||
1568 |
if (mbox_prot != 0x03) { // CoE |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1569 |
request->errno = EIO; |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1570 |
fsm->state = ec_fsm_coe_error; |
1921 | 1571 |
EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n", |
1572 |
mbox_prot); |
|
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
1573 |
return; |
436 | 1574 |
} |
1575 |
||
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1576 |
if (ec_fsm_coe_check_emergency(fsm, data, rec_size)) { |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1577 |
// check for CoE response again |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1578 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1579 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1580 |
fsm->state = ec_fsm_coe_down_check; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1581 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1582 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
1583 |
|
975
dae04112bcc7
Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents:
962
diff
changeset
|
1584 |
if (slave->master->debug_level) { |
1921 | 1585 |
EC_SLAVE_DBG(slave, 1, "Download response:\n"); |
975
dae04112bcc7
Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents:
962
diff
changeset
|
1586 |
ec_print_data(data, rec_size); |
dae04112bcc7
Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents:
962
diff
changeset
|
1587 |
} |
dae04112bcc7
Added debugging for sdo download.
Florian Pose <fp@igh-essen.com>
parents:
962
diff
changeset
|
1588 |
|
436 | 1589 |
if (rec_size < 6) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1590 |
request->errno = EIO; |
436 | 1591 |
fsm->state = ec_fsm_coe_error; |
1921 | 1592 |
EC_SLAVE_ERR(slave, "Received data are too small (%zu bytes):\n", |
1593 |
rec_size); |
|
436 | 1594 |
ec_print_data(data, rec_size); |
1595 |
return; |
|
1596 |
} |
|
1597 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1598 |
if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request |
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1599 |
EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request |
1526
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1600 |
char subidxstr[10]; |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1601 |
request->errno = EIO; |
1526
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1602 |
fsm->state = ec_fsm_coe_error; |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1603 |
if (request->complete_access) { |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1604 |
subidxstr[0] = 0x00; |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1605 |
} else { |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1606 |
sprintf(subidxstr, ":%02X", request->subindex); |
66edd310830c
Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents:
1507
diff
changeset
|
1607 |
} |
1921 | 1608 |
EC_SLAVE_ERR(slave, "SDO download 0x%04X%s (%zu bytes) aborted.\n", |
1609 |
request->index, subidxstr, request->data_size); |
|
436 | 1610 |
if (rec_size < 10) { |
1921 | 1611 |
EC_SLAVE_ERR(slave, "Incomplete abort command:\n"); |
436 | 1612 |
ec_print_data(data, rec_size); |
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
1613 |
} else { |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
1614 |
fsm->request->abort_code = EC_READ_U32(data + 6); |
1921 | 1615 |
ec_canopen_abort_msg(slave, fsm->request->abort_code); |
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
1616 |
} |
436 | 1617 |
return; |
1618 |
} |
|
1619 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1620 |
if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response |
436 | 1621 |
EC_READ_U8 (data + 2) >> 5 != 0x3 || // Download response |
854
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
1622 |
EC_READ_U16(data + 3) != request->index || // index |
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
1623 |
EC_READ_U8 (data + 5) != request->subindex) { // subindex |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1624 |
if (slave->master->debug_level) { |
1921 | 1625 |
EC_SLAVE_DBG(slave, 1, "Invalid SDO download response!" |
1626 |
" Retrying...\n"); |
|
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1627 |
ec_print_data(data, rec_size); |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1628 |
} |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1629 |
// check for CoE response again |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1630 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1631 |
fsm->retries = EC_FSM_RETRIES; |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
1632 |
fsm->state = ec_fsm_coe_down_check; |
436 | 1633 |
return; |
1634 |
} |
|
1635 |
||
1562 | 1636 |
if (fsm->remaining) { // more segments to download |
1637 |
fsm->toggle = 0; |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1638 |
ec_fsm_coe_down_prepare_segment_request(fsm, datagram); |
1562 | 1639 |
} else { |
1640 |
fsm->state = ec_fsm_coe_end; // success |
|
1641 |
} |
|
1642 |
} |
|
1643 |
||
1644 |
/*****************************************************************************/ |
|
1645 |
||
1646 |
/** |
|
1647 |
CoE state: DOWN SEG CHECK. |
|
1648 |
*/ |
|
1649 |
||
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1650 |
void ec_fsm_coe_down_seg_check( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1651 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1652 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1653 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1654 |
{ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1655 |
ec_slave_t *slave = fsm->slave; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1656 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1657 |
if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1658 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1659 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1660 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1661 |
fsm->request->errno = EIO; |
1562 | 1662 |
fsm->state = ec_fsm_coe_error; |
1921 | 1663 |
EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check datagram: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1664 |
ec_datagram_print_state(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1665 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1666 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1667 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1668 |
if (fsm->datagram->working_counter != 1) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1669 |
fsm->request->errno = EIO; |
1562 | 1670 |
fsm->state = ec_fsm_coe_error; |
1921 | 1671 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox segment check" |
1672 |
" datagram failed: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1673 |
ec_datagram_print_wc_error(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1674 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1675 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1676 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1677 |
if (!ec_slave_mbox_check(fsm->datagram)) { |
1562 | 1678 |
unsigned long diff_ms = |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1679 |
(fsm->datagram->jiffies_received - fsm->jiffies_start) * |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1680 |
1000 / HZ; |
1562 | 1681 |
if (diff_ms >= fsm->request->response_timeout) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1682 |
fsm->request->errno = EIO; |
1562 | 1683 |
fsm->state = ec_fsm_coe_error; |
1921 | 1684 |
EC_SLAVE_ERR(slave, "Timeout while waiting for SDO download" |
1685 |
" segment response.\n"); |
|
1562 | 1686 |
return; |
1687 |
} |
|
1688 |
||
1689 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
1690 |
fsm->retries = EC_FSM_RETRIES; |
|
1691 |
return; |
|
1692 |
} |
|
1693 |
||
1694 |
// Fetch response |
|
1695 |
ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail. |
|
1696 |
fsm->retries = EC_FSM_RETRIES; |
|
1697 |
fsm->state = ec_fsm_coe_down_seg_response; |
|
1698 |
} |
|
1699 |
||
1700 |
/*****************************************************************************/ |
|
1701 |
||
1702 |
/** |
|
1703 |
CoE state: DOWN SEG RESPONSE. |
|
1704 |
\todo Timeout behavior |
|
1705 |
*/ |
|
1706 |
||
1707 |
void ec_fsm_coe_down_seg_response( |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1708 |
ec_fsm_coe_t *fsm, /**< Finite state machine */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1709 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1710 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1711 |
{ |
1562 | 1712 |
ec_slave_t *slave = fsm->slave; |
1713 |
uint8_t *data, mbox_prot; |
|
1714 |
size_t rec_size; |
|
1715 |
ec_sdo_request_t *request = fsm->request; |
|
1716 |
||
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1717 |
if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1718 |
ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1719 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1720 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1721 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1722 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1723 |
request->errno = EIO; |
1562 | 1724 |
fsm->state = ec_fsm_coe_error; |
1921 | 1725 |
EC_SLAVE_ERR(slave, "Failed to receive CoE download response" |
1726 |
" datagram: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1727 |
ec_datagram_print_state(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1728 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1729 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1730 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1731 |
if (fsm->datagram->working_counter != 1) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1732 |
request->errno = EIO; |
1562 | 1733 |
fsm->state = ec_fsm_coe_error; |
1921 | 1734 |
EC_SLAVE_ERR(slave, "Reception of CoE download response failed: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1735 |
ec_datagram_print_wc_error(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1736 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1737 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1738 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1739 |
data = ec_slave_mbox_fetch(slave, fsm->datagram, &mbox_prot, &rec_size); |
1562 | 1740 |
if (IS_ERR(data)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1741 |
request->errno = PTR_ERR(data); |
1562 | 1742 |
fsm->state = ec_fsm_coe_error; |
1743 |
return; |
|
1744 |
} |
|
1745 |
||
1746 |
if (mbox_prot != 0x03) { // CoE |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1747 |
request->errno = EIO; |
1562 | 1748 |
fsm->state = ec_fsm_coe_error; |
1921 | 1749 |
EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n", |
1750 |
mbox_prot); |
|
1562 | 1751 |
return; |
1752 |
} |
|
1753 |
||
1754 |
if (ec_fsm_coe_check_emergency(fsm, data, rec_size)) { |
|
1755 |
// check for CoE response again |
|
1756 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
1757 |
fsm->retries = EC_FSM_RETRIES; |
|
1758 |
fsm->state = ec_fsm_coe_down_check; |
|
1759 |
return; |
|
1760 |
} |
|
1761 |
||
1762 |
if (slave->master->debug_level) { |
|
1921 | 1763 |
EC_SLAVE_DBG(slave, 1, "Download response:\n"); |
1562 | 1764 |
ec_print_data(data, rec_size); |
1765 |
} |
|
1766 |
||
1767 |
if (rec_size < 6) { |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1768 |
request->errno = EIO; |
1562 | 1769 |
fsm->state = ec_fsm_coe_error; |
1921 | 1770 |
EC_SLAVE_ERR(slave, "Received data are too small (%zu bytes):\n", |
1771 |
rec_size); |
|
1562 | 1772 |
ec_print_data(data, rec_size); |
1773 |
return; |
|
1774 |
} |
|
1775 |
||
1776 |
if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request |
|
1777 |
EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request |
|
1778 |
char subidxstr[10]; |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1779 |
request->errno = EIO; |
1562 | 1780 |
fsm->state = ec_fsm_coe_error; |
1781 |
if (request->complete_access) { |
|
1782 |
subidxstr[0] = 0x00; |
|
1783 |
} else { |
|
1784 |
sprintf(subidxstr, ":%02X", request->subindex); |
|
1785 |
} |
|
1921 | 1786 |
EC_SLAVE_ERR(slave, "SDO download 0x%04X%s (%zu bytes) aborted.\n", |
1787 |
request->index, subidxstr, request->data_size); |
|
1562 | 1788 |
if (rec_size < 10) { |
1921 | 1789 |
EC_SLAVE_ERR(slave, "Incomplete abort command:\n"); |
1562 | 1790 |
ec_print_data(data, rec_size); |
1791 |
} else { |
|
1792 |
fsm->request->abort_code = EC_READ_U32(data + 6); |
|
1921 | 1793 |
ec_canopen_abort_msg(slave, fsm->request->abort_code); |
1562 | 1794 |
} |
1795 |
return; |
|
1796 |
} |
|
1797 |
||
1798 |
if (EC_READ_U16(data) >> 12 != 0x3 || |
|
1799 |
((EC_READ_U8(data + 2) >> 5) != 0x01)) { // segment response |
|
1800 |
if (slave->master->debug_level) { |
|
1921 | 1801 |
EC_SLAVE_DBG(slave, 1, "Invalid SDO download response!" |
1802 |
" Retrying...\n"); |
|
1562 | 1803 |
ec_print_data(data, rec_size); |
1804 |
} |
|
1805 |
// check for CoE response again |
|
1806 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
1807 |
fsm->retries = EC_FSM_RETRIES; |
|
1808 |
fsm->state = ec_fsm_coe_down_seg_check; |
|
1809 |
return; |
|
1810 |
} |
|
1811 |
||
1812 |
if (((EC_READ_U8(data + 2) >> 4) & 0x01) != fsm->toggle) { |
|
1921 | 1813 |
EC_SLAVE_ERR(slave, "Invalid toggle received during" |
1814 |
" segmented download:\n"); |
|
1562 | 1815 |
ec_print_data(data, rec_size); |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1816 |
request->errno = EIO; |
1562 | 1817 |
fsm->state = ec_fsm_coe_error; |
1818 |
return; |
|
1819 |
} |
|
1820 |
||
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1821 |
fsm->offset += fsm->segment_size; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1822 |
fsm->remaining -= fsm->segment_size; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1823 |
|
1562 | 1824 |
if (fsm->remaining) { // more segments to download |
1825 |
fsm->toggle = !fsm->toggle; |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1826 |
ec_fsm_coe_down_prepare_segment_request(fsm, datagram); |
1562 | 1827 |
} else { |
1828 |
fsm->state = ec_fsm_coe_end; // success |
|
1829 |
} |
|
436 | 1830 |
} |
1831 |
||
1832 |
/*****************************************************************************/ |
|
1833 |
||
2522
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2498
diff
changeset
|
1834 |
/** Prepare an upload request. |
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2498
diff
changeset
|
1835 |
* |
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2498
diff
changeset
|
1836 |
* \return Zero on success, otherwise a negative error code. |
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2498
diff
changeset
|
1837 |
*/ |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1838 |
int ec_fsm_coe_prepare_up( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1839 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1840 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1841 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1842 |
{ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1843 |
ec_slave_t *slave = fsm->slave; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1844 |
ec_sdo_request_t *request = fsm->request; |
436 | 1845 |
ec_master_t *master = slave->master; |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1846 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1847 |
u8 *data = ec_slave_mbox_prepare_send(slave, datagram, 0x03, 10); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
1848 |
if (IS_ERR(data)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1849 |
request->errno = PTR_ERR(data); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1850 |
return PTR_ERR(data); |
436 | 1851 |
} |
1852 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
1853 |
EC_WRITE_U16(data, 0x2 << 12); // SDO request |
436 | 1854 |
EC_WRITE_U8 (data + 2, 0x2 << 5); // initiate upload request |
831
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
825
diff
changeset
|
1855 |
EC_WRITE_U16(data + 3, request->index); |
ded9519c8d6e
Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents:
825
diff
changeset
|
1856 |
EC_WRITE_U8 (data + 5, request->subindex); |
476
fd7c0ee645f8
Fixed CoE Upload Request, now 10 bytes of Mailbox Service Data.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1857 |
memset(data + 6, 0x00, 4); |
436 | 1858 |
|
1859 |
if (master->debug_level) { |
|
1921 | 1860 |
EC_SLAVE_DBG(slave, 1, "Upload request:\n"); |
476
fd7c0ee645f8
Fixed CoE Upload Request, now 10 bytes of Mailbox Service Data.
Florian Pose <fp@igh-essen.com>
parents:
461
diff
changeset
|
1861 |
ec_print_data(data, 10); |
436 | 1862 |
} |
1863 |
||
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1864 |
fsm->state = ec_fsm_coe_up_request; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1865 |
return 0; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1866 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1867 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1868 |
/*****************************************************************************/ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1869 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1870 |
/** |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1871 |
CoE state: UP START. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1872 |
*/ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1873 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1874 |
void ec_fsm_coe_up_start( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1875 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1876 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1877 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1878 |
{ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1879 |
ec_slave_t *slave = fsm->slave; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1880 |
ec_sdo_request_t *request = fsm->request; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1881 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1882 |
EC_SLAVE_DBG(slave, 1, "Uploading SDO 0x%04X:%02X.\n", |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1883 |
request->index, request->subindex); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1884 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1885 |
if (!(slave->sii.mailbox_protocols & EC_MBOX_COE)) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1886 |
EC_SLAVE_ERR(slave, "Slave does not support CoE!\n"); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1887 |
request->errno = EPROTONOSUPPORT; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1888 |
fsm->state = ec_fsm_coe_error; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1889 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1890 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1891 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1892 |
fsm->retries = EC_FSM_RETRIES; |
1035
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1893 |
fsm->request->jiffies_sent = jiffies; |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1894 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1895 |
if (ec_fsm_coe_prepare_up(fsm, datagram)) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1896 |
fsm->state = ec_fsm_coe_error; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1897 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1898 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1899 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1900 |
/*****************************************************************************/ |
436 | 1901 |
/** |
1902 |
CoE state: UP REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1903 |
\todo Timeout behavior |
436 | 1904 |
*/ |
1905 |
||
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1906 |
void ec_fsm_coe_up_request( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1907 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1908 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1909 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1910 |
{ |
436 | 1911 |
ec_slave_t *slave = fsm->slave; |
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1912 |
unsigned long diff_ms; |
436 | 1913 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1914 |
if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1915 |
if (ec_fsm_coe_prepare_up(fsm, datagram)) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1916 |
fsm->state = ec_fsm_coe_error; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1917 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1918 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1919 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1920 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1921 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1922 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1923 |
fsm->state = ec_fsm_coe_error; |
1921 | 1924 |
EC_SLAVE_ERR(slave, "Failed to receive CoE upload request: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1925 |
ec_datagram_print_state(fsm->datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1926 |
return; |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1927 |
} |
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1928 |
|
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1929 |
diff_ms = (jiffies - fsm->request->jiffies_sent) * 1000 / HZ; |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1930 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1931 |
if (fsm->datagram->working_counter != 1) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1932 |
if (!fsm->datagram->working_counter) { |
1035
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1933 |
if (diff_ms < fsm->request->response_timeout) { |
1791
27030c6b2de3
Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents:
1563
diff
changeset
|
1934 |
#if DEBUG_RETRIES |
1921 | 1935 |
EC_SLAVE_DBG(slave, 1, "Slave did not respond to" |
1931 | 1936 |
" SDO upload request. Retrying after %lu ms...\n", |
1937 |
diff_ms); |
|
1791
27030c6b2de3
Do not output CoE retries.
Florian Pose <fp@igh-essen.com>
parents:
1563
diff
changeset
|
1938 |
#endif |
1112
d11661e1f4de
Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents:
1111
diff
changeset
|
1939 |
// no response; send request datagram again |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1940 |
if (ec_fsm_coe_prepare_up(fsm, datagram)) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1941 |
fsm->state = ec_fsm_coe_error; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1942 |
} |
1112
d11661e1f4de
Fixed CoE transfer timeout bug.
Florian Pose <fp@igh-essen.com>
parents:
1111
diff
changeset
|
1943 |
return; |
1035
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1944 |
} |
7fafc1a7451e
Added response timeout to sdo_request; removed timout from fsm_coe_map.
Florian Pose <fp@igh-essen.com>
parents:
998
diff
changeset
|
1945 |
} |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1946 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1947 |
fsm->state = ec_fsm_coe_error; |
1921 | 1948 |
EC_SLAVE_ERR(slave, "Reception of CoE upload request for" |
1931 | 1949 |
" SDO 0x%04x:%x failed with timeout after %lu ms: ", |
1950 |
fsm->request->index, fsm->request->subindex, diff_ms); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1951 |
ec_datagram_print_wc_error(fsm->datagram); |
436 | 1952 |
return; |
1953 |
} |
|
1954 |
||
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1955 |
#if DEBUG_LONG |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1956 |
if (diff_ms > 200) { |
1931 | 1957 |
EC_SLAVE_WARN(slave, "SDO 0x%04x:%x upload took %lu ms.\n", |
1958 |
fsm->request->index, fsm->request->subindex, diff_ms); |
|
1792
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1959 |
} |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1960 |
#endif |
3eb466e9bad5
Improved CoE error messages.
Florian Pose <fp@igh-essen.com>
parents:
1791
diff
changeset
|
1961 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1962 |
fsm->jiffies_start = fsm->datagram->jiffies_sent; |
436 | 1963 |
|
1964 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1965 |
fsm->retries = EC_FSM_RETRIES; |
436 | 1966 |
fsm->state = ec_fsm_coe_up_check; |
1967 |
} |
|
1968 |
||
1969 |
/*****************************************************************************/ |
|
1970 |
||
1971 |
/** |
|
1972 |
CoE state: UP CHECK. |
|
1973 |
*/ |
|
1974 |
||
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1975 |
void ec_fsm_coe_up_check( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1976 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1977 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1978 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1979 |
{ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1980 |
ec_slave_t *slave = fsm->slave; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1981 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1982 |
if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1983 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1984 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1985 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1986 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1987 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1988 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1989 |
fsm->state = ec_fsm_coe_error; |
1921 | 1990 |
EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check datagram: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1991 |
ec_datagram_print_state(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1992 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1993 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1994 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
1995 |
if (fsm->datagram->working_counter != 1) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
1996 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
1997 |
fsm->state = ec_fsm_coe_error; |
1921 | 1998 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox check" |
1999 |
" datagram failed: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2000 |
ec_datagram_print_wc_error(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2001 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2002 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2003 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2004 |
if (!ec_slave_mbox_check(fsm->datagram)) { |
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
2005 |
unsigned long diff_ms = |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2006 |
(fsm->datagram->jiffies_received - fsm->jiffies_start) * |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2007 |
1000 / HZ; |
1043
2abea4233a6d
Response timeout for checking Sdo upload.
Florian Pose <fp@igh-essen.com>
parents:
1038
diff
changeset
|
2008 |
if (diff_ms >= fsm->request->response_timeout) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2009 |
fsm->request->errno = EIO; |
436 | 2010 |
fsm->state = ec_fsm_coe_error; |
1931 | 2011 |
EC_SLAVE_ERR(slave, "Timeout after %lu ms while waiting for" |
2012 |
" SDO 0x%04x:%x upload response.\n", diff_ms, |
|
1921 | 2013 |
fsm->request->index, fsm->request->subindex); |
436 | 2014 |
return; |
2015 |
} |
|
2016 |
||
2017 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2018 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2019 |
return; |
2020 |
} |
|
2021 |
||
2022 |
// Fetch response |
|
2023 |
ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2024 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2025 |
fsm->state = ec_fsm_coe_up_response; |
2026 |
} |
|
2027 |
||
2028 |
/*****************************************************************************/ |
|
2029 |
||
1498
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2030 |
/** Prepare an SDO upload segment request. |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2031 |
*/ |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2032 |
void ec_fsm_coe_up_prepare_segment_request( |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2033 |
ec_fsm_coe_t *fsm, /**< Finite state machine */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2034 |
ec_datagram_t *datagram /**< Datagram to use. */ |
1498
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2035 |
) |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2036 |
{ |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2037 |
uint8_t *data = |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2038 |
ec_slave_mbox_prepare_send(fsm->slave, datagram, 0x03, 10); |
1498
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2039 |
if (IS_ERR(data)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2040 |
fsm->request->errno = PTR_ERR(data); |
1498
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2041 |
fsm->state = ec_fsm_coe_error; |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2042 |
return; |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2043 |
} |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2044 |
|
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2045 |
EC_WRITE_U16(data, 0x2 << 12); // SDO request |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2046 |
EC_WRITE_U8 (data + 2, (fsm->toggle << 4 // toggle |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2047 |
| 0x3 << 5)); // upload segment request |
1550
81a16ba13ae6
Avoid zeroing mailbox datagram because of VoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
1544
diff
changeset
|
2048 |
memset(data + 3, 0x00, 7); |
1498
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2049 |
|
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2050 |
if (fsm->slave->master->debug_level) { |
1921 | 2051 |
EC_SLAVE_DBG(fsm->slave, 1, "Upload segment request:\n"); |
1498
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2052 |
ec_print_data(data, 10); |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2053 |
} |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2054 |
} |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2055 |
|
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2056 |
/*****************************************************************************/ |
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2057 |
|
436 | 2058 |
/** |
2059 |
CoE state: UP RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2060 |
\todo Timeout behavior |
436 | 2061 |
*/ |
2062 |
||
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2063 |
void ec_fsm_coe_up_response( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2064 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2065 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2066 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2067 |
{ |
436 | 2068 |
ec_slave_t *slave = fsm->slave; |
2069 |
ec_master_t *master = slave->master; |
|
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2070 |
uint16_t rec_index; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2071 |
uint8_t *data, mbox_prot, rec_subindex; |
436 | 2072 |
size_t rec_size, data_size; |
2073 |
ec_sdo_request_t *request = fsm->request; |
|
2074 |
unsigned int expedited, size_specified; |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2075 |
int ret; |
436 | 2076 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2077 |
if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2078 |
ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2079 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2080 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2081 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2082 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2083 |
request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2084 |
fsm->state = ec_fsm_coe_error; |
1921 | 2085 |
EC_SLAVE_ERR(slave, "Failed to receive CoE upload response" |
2086 |
" datagram: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2087 |
ec_datagram_print_state(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2088 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2089 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2090 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2091 |
if (fsm->datagram->working_counter != 1) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2092 |
request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2093 |
fsm->state = ec_fsm_coe_error; |
1921 | 2094 |
EC_SLAVE_ERR(slave, "Reception of CoE upload response failed: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2095 |
ec_datagram_print_wc_error(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2096 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2097 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2098 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2099 |
data = ec_slave_mbox_fetch(slave, fsm->datagram, &mbox_prot, &rec_size); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
2100 |
if (IS_ERR(data)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2101 |
request->errno = PTR_ERR(data); |
436 | 2102 |
fsm->state = ec_fsm_coe_error; |
2103 |
return; |
|
2104 |
} |
|
2105 |
||
2106 |
if (master->debug_level) { |
|
1921 | 2107 |
EC_SLAVE_DBG(slave, 1, "Upload response:\n"); |
436 | 2108 |
ec_print_data(data, rec_size); |
2109 |
} |
|
2110 |
||
2111 |
if (mbox_prot != 0x03) { // CoE |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2112 |
request->errno = EIO; |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
2113 |
fsm->state = ec_fsm_coe_error; |
1921 | 2114 |
EC_SLAVE_WARN(slave, "Received mailbox protocol 0x%02X" |
2115 |
" as response.\n", mbox_prot); |
|
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2116 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2117 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2118 |
|
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2119 |
if (ec_fsm_coe_check_emergency(fsm, data, rec_size)) { |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2120 |
// check for CoE response again |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2121 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2122 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2123 |
fsm->state = ec_fsm_coe_up_check; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2124 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2125 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2126 |
|
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2127 |
if (rec_size < 6) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2128 |
request->errno = EIO; |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
2129 |
fsm->state = ec_fsm_coe_error; |
1921 | 2130 |
EC_SLAVE_ERR(slave, "Received currupted SDO upload response" |
2131 |
" (%zu bytes)!\n", rec_size); |
|
436 | 2132 |
ec_print_data(data, rec_size); |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2133 |
return; |
436 | 2134 |
} |
2135 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
2136 |
if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request |
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2137 |
EC_READ_U8(data + 2) >> 5 == 0x4) { // abort SDO transfer request |
1921 | 2138 |
EC_SLAVE_ERR(slave, "SDO upload 0x%04X:%02X aborted.\n", |
2139 |
request->index, request->subindex); |
|
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
2140 |
if (rec_size >= 10) { |
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
2141 |
request->abort_code = EC_READ_U32(data + 6); |
1921 | 2142 |
ec_canopen_abort_msg(slave, request->abort_code); |
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
2143 |
} else { |
1921 | 2144 |
EC_SLAVE_ERR(slave, "No abort message.\n"); |
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
2145 |
} |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2146 |
request->errno = EIO; |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2147 |
fsm->state = ec_fsm_coe_error; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2148 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2149 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2150 |
|
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2151 |
if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2152 |
EC_READ_U8(data + 2) >> 5 != 0x2) { // upload response |
1921 | 2153 |
EC_SLAVE_ERR(slave, "Received unknown response while" |
2154 |
" uploading SDO 0x%04X:%02X.\n", |
|
2155 |
request->index, request->subindex); |
|
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2156 |
ec_print_data(data, rec_size); |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2157 |
request->errno = EIO; |
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2158 |
fsm->state = ec_fsm_coe_error; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2159 |
return; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2160 |
} |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2161 |
|
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2162 |
rec_index = EC_READ_U16(data + 3); |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2163 |
rec_subindex = EC_READ_U8(data + 5); |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2164 |
|
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2165 |
if (rec_index != request->index || rec_subindex != request->subindex) { |
1921 | 2166 |
EC_SLAVE_ERR(slave, "Received upload response for wrong SDO" |
2167 |
" (0x%04X:%02X, requested: 0x%04X:%02X).\n", |
|
2168 |
rec_index, rec_subindex, request->index, request->subindex); |
|
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2169 |
ec_print_data(data, rec_size); |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2170 |
|
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2171 |
// check for CoE response again |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2172 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2173 |
fsm->retries = EC_FSM_RETRIES; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2174 |
fsm->state = ec_fsm_coe_up_check; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2175 |
return; |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2176 |
} |
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2177 |
|
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2178 |
// normal or expedited? |
436 | 2179 |
expedited = EC_READ_U8(data + 2) & 0x02; |
2180 |
||
2181 |
if (expedited) { |
|
2182 |
size_specified = EC_READ_U8(data + 2) & 0x01; |
|
2183 |
if (size_specified) { |
|
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2184 |
fsm->complete_size = 4 - ((EC_READ_U8(data + 2) & 0x0C) >> 2); |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2185 |
} else { |
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2186 |
fsm->complete_size = 4; |
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2187 |
} |
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2188 |
|
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2189 |
if (rec_size < 6 + fsm->complete_size) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2190 |
request->errno = EIO; |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
2191 |
fsm->state = ec_fsm_coe_error; |
1921 | 2192 |
EC_SLAVE_ERR(slave, "Received corrupted SDO expedited upload" |
1543
373cd456dc26
Avoid warnings on x86_64 platform. Thanks to Thomas Elste.
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
2193 |
" response (only %zu bytes)!\n", rec_size); |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2194 |
ec_print_data(data, rec_size); |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2195 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2196 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2197 |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2198 |
ret = ec_sdo_request_copy_data(request, data + 6, fsm->complete_size); |
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2199 |
if (ret) { |
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2200 |
request->errno = -ret; |
854
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
2201 |
fsm->state = ec_fsm_coe_error; |
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
2202 |
return; |
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
2203 |
} |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2204 |
} else { // normal |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2205 |
if (rec_size < 10) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2206 |
request->errno = EIO; |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
2207 |
fsm->state = ec_fsm_coe_error; |
1921 | 2208 |
EC_SLAVE_ERR(slave, "Received currupted SDO normal upload" |
1543
373cd456dc26
Avoid warnings on x86_64 platform. Thanks to Thomas Elste.
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
2209 |
" response (only %zu bytes)!\n", rec_size); |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2210 |
ec_print_data(data, rec_size); |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2211 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2212 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2213 |
|
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2214 |
data_size = rec_size - 10; |
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2215 |
fsm->complete_size = EC_READ_U32(data + 6); |
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2216 |
|
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2217 |
if (!fsm->complete_size) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2218 |
request->errno = EIO; |
860
ba5c38f0bb30
Minor change: Moved state assign to beginning.
Florian Pose <fp@igh-essen.com>
parents:
859
diff
changeset
|
2219 |
fsm->state = ec_fsm_coe_error; |
1921 | 2220 |
EC_SLAVE_ERR(slave, "No complete size supplied!\n"); |
769
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2221 |
ec_print_data(data, rec_size); |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2222 |
return; |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2223 |
} |
2195c2ea37b4
Fixed normal/expedited bug at CoE upload; more robust behaviour, when
Florian Pose <fp@igh-essen.com>
parents:
739
diff
changeset
|
2224 |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2225 |
ret = ec_sdo_request_alloc(request, fsm->complete_size); |
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2226 |
if (ret) { |
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2227 |
request->errno = -ret; |
854
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
2228 |
fsm->state = ec_fsm_coe_error; |
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
2229 |
return; |
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
2230 |
} |
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
2231 |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2232 |
ret = ec_sdo_request_copy_data(request, data + 10, data_size); |
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2233 |
if (ret) { |
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2234 |
request->errno = -ret; |
854
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
2235 |
fsm->state = ec_fsm_coe_error; |
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
2236 |
return; |
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
2237 |
} |
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
2238 |
|
436 | 2239 |
fsm->toggle = 0; |
2240 |
||
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2241 |
if (data_size < fsm->complete_size) { |
1921 | 2242 |
EC_SLAVE_DBG(slave, 1, "SDO data incomplete (%zu / %u)." |
2243 |
" Segmenting...\n", data_size, fsm->complete_size); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2244 |
ec_fsm_coe_up_prepare_segment_request(fsm, datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2245 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2246 |
fsm->state = ec_fsm_coe_up_seg_request; |
2247 |
return; |
|
2248 |
} |
|
2249 |
} |
|
2250 |
||
874 | 2251 |
if (master->debug_level) { |
1921 | 2252 |
EC_SLAVE_DBG(slave, 1, "Uploaded data:\n"); |
874 | 2253 |
ec_print_data(request->data, request->data_size); |
2254 |
} |
|
2255 |
||
436 | 2256 |
fsm->state = ec_fsm_coe_end; // success |
2257 |
} |
|
2258 |
||
2259 |
/*****************************************************************************/ |
|
2260 |
||
2261 |
/** |
|
2262 |
CoE state: UP REQUEST. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2263 |
\todo Timeout behavior |
436 | 2264 |
*/ |
2265 |
||
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2266 |
void ec_fsm_coe_up_seg_request( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2267 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2268 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2269 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2270 |
{ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2271 |
ec_slave_t *slave = fsm->slave; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2272 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2273 |
if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2274 |
ec_fsm_coe_up_prepare_segment_request(fsm, datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2275 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2276 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2277 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2278 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2279 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2280 |
fsm->state = ec_fsm_coe_error; |
1921 | 2281 |
EC_SLAVE_ERR(slave, "Failed to receive CoE upload segment" |
2282 |
" request datagram: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2283 |
ec_datagram_print_state(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2284 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2285 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2286 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2287 |
if (fsm->datagram->working_counter != 1) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2288 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2289 |
fsm->state = ec_fsm_coe_error; |
1921 | 2290 |
EC_SLAVE_ERR(slave, "Reception of CoE upload segment" |
2291 |
" request failed: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2292 |
ec_datagram_print_wc_error(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2293 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2294 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2295 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2296 |
fsm->jiffies_start = fsm->datagram->jiffies_sent; |
436 | 2297 |
|
2298 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2299 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2300 |
fsm->state = ec_fsm_coe_up_seg_check; |
2301 |
} |
|
2302 |
||
2303 |
/*****************************************************************************/ |
|
2304 |
||
2305 |
/** |
|
2306 |
CoE state: UP CHECK. |
|
2307 |
*/ |
|
2308 |
||
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2309 |
void ec_fsm_coe_up_seg_check( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2310 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2311 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2312 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2313 |
{ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2314 |
ec_slave_t *slave = fsm->slave; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2315 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2316 |
if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2317 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2318 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2319 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2320 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2321 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2322 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2323 |
fsm->state = ec_fsm_coe_error; |
1921 | 2324 |
EC_SLAVE_ERR(slave, "Failed to receive CoE mailbox check" |
2325 |
" datagram: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2326 |
ec_datagram_print_state(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2327 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2328 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2329 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2330 |
if (fsm->datagram->working_counter != 1) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2331 |
fsm->request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2332 |
fsm->state = ec_fsm_coe_error; |
1921 | 2333 |
EC_SLAVE_ERR(slave, "Reception of CoE mailbox check datagram" |
2334 |
" failed: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2335 |
ec_datagram_print_wc_error(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2336 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2337 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2338 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2339 |
if (!ec_slave_mbox_check(fsm->datagram)) { |
1038
7ca4103ba170
Use jiffies instead of cycles in CoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1037
diff
changeset
|
2340 |
unsigned long diff_ms = |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2341 |
(fsm->datagram->jiffies_received - fsm->jiffies_start) * |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2342 |
1000 / HZ; |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
2343 |
if (diff_ms >= fsm->request->response_timeout) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2344 |
fsm->request->errno = EIO; |
436 | 2345 |
fsm->state = ec_fsm_coe_error; |
1921 | 2346 |
EC_SLAVE_ERR(slave, "Timeout while waiting for SDO upload" |
2347 |
" segment response.\n"); |
|
436 | 2348 |
return; |
2349 |
} |
|
2350 |
||
2351 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2352 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2353 |
return; |
2354 |
} |
|
2355 |
||
2356 |
// Fetch response |
|
2357 |
ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2358 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2359 |
fsm->state = ec_fsm_coe_up_seg_response; |
2360 |
} |
|
2361 |
||
2362 |
/*****************************************************************************/ |
|
2363 |
||
2364 |
/** |
|
2365 |
CoE state: UP RESPONSE. |
|
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2366 |
\todo Timeout behavior |
436 | 2367 |
*/ |
2368 |
||
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2369 |
void ec_fsm_coe_up_seg_response( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2370 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2371 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2372 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2373 |
{ |
436 | 2374 |
ec_slave_t *slave = fsm->slave; |
2375 |
ec_master_t *master = slave->master; |
|
2376 |
uint8_t *data, mbox_prot; |
|
2377 |
size_t rec_size, data_size; |
|
2378 |
ec_sdo_request_t *request = fsm->request; |
|
2379 |
unsigned int last_segment; |
|
2380 |
||
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2381 |
if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2382 |
ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail. |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2383 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2384 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2385 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2386 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2387 |
request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2388 |
fsm->state = ec_fsm_coe_error; |
1921 | 2389 |
EC_SLAVE_ERR(slave, "Failed to receive CoE upload segment" |
2390 |
" response datagram: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2391 |
ec_datagram_print_state(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2392 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2393 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2394 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2395 |
if (fsm->datagram->working_counter != 1) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2396 |
request->errno = EIO; |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2397 |
fsm->state = ec_fsm_coe_error; |
1921 | 2398 |
EC_SLAVE_ERR(slave, "Reception of CoE upload segment" |
2399 |
" response failed: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2400 |
ec_datagram_print_wc_error(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2401 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2402 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2403 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2404 |
data = ec_slave_mbox_fetch(slave, fsm->datagram, &mbox_prot, &rec_size); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1310
diff
changeset
|
2405 |
if (IS_ERR(data)) { |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2406 |
request->errno = PTR_ERR(data); |
436 | 2407 |
fsm->state = ec_fsm_coe_error; |
2408 |
return; |
|
2409 |
} |
|
2410 |
||
2411 |
if (master->debug_level) { |
|
1921 | 2412 |
EC_SLAVE_DBG(slave, 1, "Upload segment response:\n"); |
436 | 2413 |
ec_print_data(data, rec_size); |
2414 |
} |
|
2415 |
||
2416 |
if (mbox_prot != 0x03) { // CoE |
|
1921 | 2417 |
EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n", |
2418 |
mbox_prot); |
|
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2419 |
request->errno = EIO; |
436 | 2420 |
fsm->state = ec_fsm_coe_error; |
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2421 |
return; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2422 |
} |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2423 |
|
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2424 |
if (ec_fsm_coe_check_emergency(fsm, data, rec_size)) { |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2425 |
// check for CoE response again |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2426 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2427 |
fsm->retries = EC_FSM_RETRIES; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2428 |
fsm->state = ec_fsm_coe_up_seg_check; |
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2429 |
return; |
436 | 2430 |
} |
2431 |
||
2432 |
if (rec_size < 10) { |
|
1921 | 2433 |
EC_SLAVE_ERR(slave, "Received currupted SDO upload" |
2434 |
" segment response!\n"); |
|
436 | 2435 |
ec_print_data(data, rec_size); |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2436 |
request->errno = EIO; |
436 | 2437 |
fsm->state = ec_fsm_coe_error; |
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2438 |
return; |
436 | 2439 |
} |
2440 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
2441 |
if (EC_READ_U16(data) >> 12 == 0x2 && // SDO request |
1468
0a804ddbaf93
Improved error checking on SDO upload.
Florian Pose <fp@igh-essen.com>
parents:
1457
diff
changeset
|
2442 |
EC_READ_U8 (data + 2) >> 5 == 0x4) { // abort SDO transfer request |
1921 | 2443 |
EC_SLAVE_ERR(slave, "SDO upload 0x%04X:%02X aborted.\n", |
2444 |
request->index, request->subindex); |
|
1037
59f191c9185b
Store abort code in sdo request; output it in user space; added some
Florian Pose <fp@igh-essen.com>
parents:
1035
diff
changeset
|
2445 |
request->abort_code = EC_READ_U32(data + 6); |
1921 | 2446 |
ec_canopen_abort_msg(slave, request->abort_code); |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2447 |
request->errno = EIO; |
436 | 2448 |
fsm->state = ec_fsm_coe_error; |
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2449 |
return; |
436 | 2450 |
} |
2451 |
||
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
2452 |
if (EC_READ_U16(data) >> 12 != 0x3 || // SDO response |
436 | 2453 |
EC_READ_U8 (data + 2) >> 5 != 0x0) { // upload segment response |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
2454 |
if (fsm->slave->master->debug_level) { |
1921 | 2455 |
EC_SLAVE_DBG(slave, 1, "Invalid SDO upload segment response!\n"); |
1053
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
2456 |
ec_print_data(data, rec_size); |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
2457 |
} |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
2458 |
// check for CoE response again |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
2459 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
2460 |
fsm->retries = EC_FSM_RETRIES; |
0cb9604cbaa7
Central CoE timeouts; retry on CoE response mismatch.
Florian Pose <fp@igh-essen.com>
parents:
1043
diff
changeset
|
2461 |
fsm->state = ec_fsm_coe_up_seg_check; |
895
5c2125247dde
Check for emergency requests during CoE transfers.
Florian Pose <fp@igh-essen.com>
parents:
874
diff
changeset
|
2462 |
return; |
436 | 2463 |
} |
2464 |
||
1533
bd150d066ea2
Fixed SDO upload segment response for 10 bytes mailbox length (thanks to Joerg
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
2465 |
data_size = rec_size - 3; /* Header of segment upload is smaller than |
bd150d066ea2
Fixed SDO upload segment response for 10 bytes mailbox length (thanks to Joerg
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
2466 |
normal upload */ |
bd150d066ea2
Fixed SDO upload segment response for 10 bytes mailbox length (thanks to Joerg
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
2467 |
if (rec_size == 10) { |
bd150d066ea2
Fixed SDO upload segment response for 10 bytes mailbox length (thanks to Joerg
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
2468 |
uint8_t seg_size = (EC_READ_U8(data + 2) & 0xE) >> 1; |
bd150d066ea2
Fixed SDO upload segment response for 10 bytes mailbox length (thanks to Joerg
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
2469 |
data_size -= seg_size; |
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2470 |
} |
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2471 |
|
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2472 |
if (request->data_size + data_size > fsm->complete_size) { |
1921 | 2473 |
EC_SLAVE_ERR(slave, "SDO upload 0x%04X:%02X failed: Fragment" |
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2474 |
" exceeding complete size!\n", |
1921 | 2475 |
request->index, request->subindex); |
1948
fa1c4fb0a8da
Output correct errno when transferring SDOs via command-line interface.
Florian Pose <fp@igh-essen.com>
parents:
1931
diff
changeset
|
2476 |
request->errno = EOVERFLOW; |
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2477 |
fsm->state = ec_fsm_coe_error; |
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2478 |
return; |
436 | 2479 |
} |
2480 |
||
1498
58532f81a456
Fixed SDO upload segment response (thanks to Christoph Peter).
Florian Pose <fp@igh-essen.com>
parents:
1495
diff
changeset
|
2481 |
memcpy(request->data + request->data_size, data + 3, data_size); |
854
f4f53be425ac
Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents:
834
diff
changeset
|
2482 |
request->data_size += data_size; |
436 | 2483 |
|
1533
bd150d066ea2
Fixed SDO upload segment response for 10 bytes mailbox length (thanks to Joerg
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
2484 |
last_segment = EC_READ_U8(data + 2) & 0x01; |
436 | 2485 |
if (!last_segment) { |
2486 |
fsm->toggle = !fsm->toggle; |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2487 |
ec_fsm_coe_up_prepare_segment_request(fsm, datagram); |
505
bc443ca0077f
State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents:
501
diff
changeset
|
2488 |
fsm->retries = EC_FSM_RETRIES; |
436 | 2489 |
fsm->state = ec_fsm_coe_up_seg_request; |
2490 |
return; |
|
2491 |
} |
|
2492 |
||
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2493 |
if (request->data_size != fsm->complete_size) { |
1921 | 2494 |
EC_SLAVE_WARN(slave, "SDO upload 0x%04X:%02X: Assembled data" |
1543
373cd456dc26
Avoid warnings on x86_64 platform. Thanks to Thomas Elste.
Florian Pose <fp@igh-essen.com>
parents:
1526
diff
changeset
|
2495 |
" size (%zu) does not match complete size (%u)!\n", |
1921 | 2496 |
request->index, request->subindex, |
1339
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2497 |
request->data_size, fsm->complete_size); |
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2498 |
} |
3483999e1aba
merge -c1622 branches/1.4-foe: Fixed seg_size parameter when processing an CoE Upload Segment Response.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
2499 |
|
874 | 2500 |
if (master->debug_level) { |
1921 | 2501 |
EC_SLAVE_DBG(slave, 1, "Uploaded data:\n"); |
874 | 2502 |
ec_print_data(request->data, request->data_size); |
2503 |
} |
|
2504 |
||
436 | 2505 |
fsm->state = ec_fsm_coe_end; // success |
2506 |
} |
|
2507 |
||
2508 |
/*****************************************************************************/ |
|
2509 |
||
2510 |
/** |
|
2511 |
State: ERROR. |
|
2512 |
*/ |
|
2513 |
||
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2514 |
void ec_fsm_coe_error( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2515 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2516 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2517 |
) |
436 | 2518 |
{ |
2519 |
} |
|
2520 |
||
2521 |
/*****************************************************************************/ |
|
2522 |
||
2523 |
/** |
|
2524 |
State: END. |
|
2525 |
*/ |
|
2526 |
||
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2527 |
void ec_fsm_coe_end( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2528 |
ec_fsm_coe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2529 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2530 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2531 |
{ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2532 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2533 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2438
diff
changeset
|
2534 |
/*****************************************************************************/ |