author | Martin Troxler <ch1010277@ch10lt194> |
Mon, 14 Mar 2011 16:57:47 +0100 | |
changeset 2046 | 4cf0161c445a |
parent 2045 | ff2a13a4603c |
child 2589 | 2b9c78543663 |
permissions | -rw-r--r-- |
1209 | 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:
1315
diff
changeset
|
5 |
* Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH |
1209 | 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:
1315
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:
1315
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:
1315
diff
changeset
|
11 |
* published by the Free Software Foundation. |
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:
1315
diff
changeset
|
12 |
* |
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:
1315
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:
1315
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:
1315
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:
1315
diff
changeset
|
16 |
* Public License for more details. |
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:
1315
diff
changeset
|
17 |
* |
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:
1315
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:
1315
diff
changeset
|
19 |
* with the IgH EtherCAT Master; if not, write to the Free Software |
1209 | 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:
1348
diff
changeset
|
22 |
* --- |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1348
diff
changeset
|
23 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1348
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:
1348
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:
1348
diff
changeset
|
26 |
* industrial property and similar rights of Beckhoff Automation GmbH. |
1209 | 27 |
* |
28 |
*****************************************************************************/ |
|
29 |
||
30 |
/** \file |
|
1327
4d179b06dd3c
merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents:
1326
diff
changeset
|
31 |
* Vendor specific over EtherCAT protocol handler functions. |
1209 | 32 |
*/ |
33 |
||
34 |
/*****************************************************************************/ |
|
35 |
||
36 |
#include <linux/module.h> |
|
37 |
||
38 |
#include "master.h" |
|
39 |
#include "slave_config.h" |
|
40 |
#include "mailbox.h" |
|
41 |
#include "voe_handler.h" |
|
42 |
||
1216
e70c4d71cebd
Changed VoE mailbox type to 0xff.
Florian Pose <fp@igh-essen.com>
parents:
1209
diff
changeset
|
43 |
/** VoE mailbox type. |
e70c4d71cebd
Changed VoE mailbox type to 0xff.
Florian Pose <fp@igh-essen.com>
parents:
1209
diff
changeset
|
44 |
*/ |
1224 | 45 |
#define EC_MBOX_TYPE_VOE 0x0f |
1216
e70c4d71cebd
Changed VoE mailbox type to 0xff.
Florian Pose <fp@igh-essen.com>
parents:
1209
diff
changeset
|
46 |
|
1218 | 47 |
/** VoE header size. |
48 |
*/ |
|
49 |
#define EC_VOE_HEADER_SIZE 6 |
|
50 |
||
1209 | 51 |
/** VoE response timeout in [ms]. |
52 |
*/ |
|
53 |
#define EC_VOE_RESPONSE_TIMEOUT 500 |
|
54 |
||
55 |
/*****************************************************************************/ |
|
56 |
||
57 |
void ec_voe_handler_state_write_start(ec_voe_handler_t *); |
|
58 |
void ec_voe_handler_state_write_response(ec_voe_handler_t *); |
|
59 |
||
60 |
void ec_voe_handler_state_read_start(ec_voe_handler_t *); |
|
61 |
void ec_voe_handler_state_read_check(ec_voe_handler_t *); |
|
62 |
void ec_voe_handler_state_read_response(ec_voe_handler_t *); |
|
63 |
||
1314
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
64 |
void ec_voe_handler_state_read_nosync_start(ec_voe_handler_t *); |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
65 |
void ec_voe_handler_state_read_nosync_response(ec_voe_handler_t *); |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
66 |
|
1209 | 67 |
void ec_voe_handler_state_end(ec_voe_handler_t *); |
68 |
void ec_voe_handler_state_error(ec_voe_handler_t *); |
|
69 |
||
70 |
/*****************************************************************************/ |
|
71 |
||
72 |
/** VoE handler constructor. |
|
1312
74853e018898
Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
73 |
* |
74853e018898
Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
74 |
* \return Return value of ec_datagram_prealloc(). |
1209 | 75 |
*/ |
76 |
int ec_voe_handler_init( |
|
77 |
ec_voe_handler_t *voe, /**< VoE handler. */ |
|
78 |
ec_slave_config_t *sc, /**< Parent slave configuration. */ |
|
79 |
size_t size /**< Size of memory to reserve. */ |
|
80 |
) |
|
81 |
{ |
|
82 |
voe->config = sc; |
|
1218 | 83 |
voe->vendor_id = 0x00000000; |
84 |
voe->vendor_type = 0x0000; |
|
1209 | 85 |
voe->data_size = 0; |
86 |
voe->dir = EC_DIR_INVALID; |
|
87 |
voe->state = ec_voe_handler_state_error; |
|
88 |
voe->request_state = EC_INT_REQUEST_INIT; |
|
89 |
||
90 |
ec_datagram_init(&voe->datagram); |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
91 |
ec_mbox_init(&voe->mbox,&voe->datagram); |
1312
74853e018898
Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
92 |
return ec_datagram_prealloc(&voe->datagram, |
74853e018898
Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
93 |
size + EC_MBOX_HEADER_SIZE + EC_VOE_HEADER_SIZE); |
1209 | 94 |
} |
95 |
||
96 |
/*****************************************************************************/ |
|
97 |
||
98 |
/** VoE handler destructor. |
|
99 |
*/ |
|
100 |
void ec_voe_handler_clear( |
|
101 |
ec_voe_handler_t *voe /**< VoE handler. */ |
|
102 |
) |
|
103 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
104 |
ec_mbox_clear(&voe->mbox); |
1209 | 105 |
ec_datagram_clear(&voe->datagram); |
106 |
} |
|
107 |
||
1264
e7882f246d7a
Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1226
diff
changeset
|
108 |
/*****************************************************************************/ |
e7882f246d7a
Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1226
diff
changeset
|
109 |
|
e7882f246d7a
Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1226
diff
changeset
|
110 |
/** Get usable memory size. |
e7882f246d7a
Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1226
diff
changeset
|
111 |
*/ |
e7882f246d7a
Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1226
diff
changeset
|
112 |
size_t ec_voe_handler_mem_size( |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
113 |
const ec_voe_handler_t *voe /**< VoE handler. */ |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
114 |
) |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
115 |
{ |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
116 |
if (voe->datagram.mem_size >= EC_MBOX_HEADER_SIZE + EC_VOE_HEADER_SIZE) |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
117 |
return voe->datagram.mem_size - |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
118 |
(EC_MBOX_HEADER_SIZE + EC_VOE_HEADER_SIZE); |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
119 |
else |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
120 |
return 0; |
1264
e7882f246d7a
Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1226
diff
changeset
|
121 |
} |
e7882f246d7a
Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1226
diff
changeset
|
122 |
|
1209 | 123 |
/***************************************************************************** |
124 |
* Application interface. |
|
125 |
****************************************************************************/ |
|
126 |
||
1226
afb189516fcf
Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents:
1224
diff
changeset
|
127 |
void ecrt_voe_handler_send_header(ec_voe_handler_t *voe, uint32_t vendor_id, |
1218 | 128 |
uint16_t vendor_type) |
129 |
{ |
|
130 |
voe->vendor_id = vendor_id; |
|
131 |
voe->vendor_type = vendor_type; |
|
132 |
} |
|
133 |
||
134 |
/*****************************************************************************/ |
|
135 |
||
1226
afb189516fcf
Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents:
1224
diff
changeset
|
136 |
void ecrt_voe_handler_received_header(const ec_voe_handler_t *voe, |
afb189516fcf
Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents:
1224
diff
changeset
|
137 |
uint32_t *vendor_id, uint16_t *vendor_type) |
afb189516fcf
Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents:
1224
diff
changeset
|
138 |
{ |
afb189516fcf
Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents:
1224
diff
changeset
|
139 |
uint8_t *header = voe->datagram.data + EC_MBOX_HEADER_SIZE; |
afb189516fcf
Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents:
1224
diff
changeset
|
140 |
|
afb189516fcf
Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents:
1224
diff
changeset
|
141 |
if (vendor_id) |
afb189516fcf
Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents:
1224
diff
changeset
|
142 |
*vendor_id = EC_READ_U32(header); |
afb189516fcf
Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents:
1224
diff
changeset
|
143 |
if (vendor_type) |
afb189516fcf
Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents:
1224
diff
changeset
|
144 |
*vendor_type = EC_READ_U16(header + 4); |
afb189516fcf
Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents:
1224
diff
changeset
|
145 |
} |
afb189516fcf
Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents:
1224
diff
changeset
|
146 |
|
afb189516fcf
Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents:
1224
diff
changeset
|
147 |
/*****************************************************************************/ |
afb189516fcf
Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents:
1224
diff
changeset
|
148 |
|
1209 | 149 |
uint8_t *ecrt_voe_handler_data(ec_voe_handler_t *voe) |
150 |
{ |
|
1218 | 151 |
return voe->datagram.data + EC_MBOX_HEADER_SIZE + EC_VOE_HEADER_SIZE; |
1209 | 152 |
} |
153 |
||
154 |
/*****************************************************************************/ |
|
155 |
||
156 |
size_t ecrt_voe_handler_data_size(const ec_voe_handler_t *voe) |
|
157 |
{ |
|
158 |
return voe->data_size; |
|
159 |
} |
|
160 |
||
161 |
/*****************************************************************************/ |
|
162 |
||
163 |
void ecrt_voe_handler_read(ec_voe_handler_t *voe) |
|
164 |
{ |
|
165 |
voe->dir = EC_DIR_INPUT; |
|
166 |
voe->state = ec_voe_handler_state_read_start; |
|
1348
8db0f72ace11
Fixed usage of internal request states.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
167 |
voe->request_state = EC_INT_REQUEST_BUSY; |
1209 | 168 |
} |
169 |
||
170 |
/*****************************************************************************/ |
|
171 |
||
1314
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
172 |
void ecrt_voe_handler_read_nosync(ec_voe_handler_t *voe) |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
173 |
{ |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
174 |
voe->dir = EC_DIR_INPUT; |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
175 |
voe->state = ec_voe_handler_state_read_nosync_start; |
1348
8db0f72ace11
Fixed usage of internal request states.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
176 |
voe->request_state = EC_INT_REQUEST_BUSY; |
1314
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
177 |
} |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
178 |
|
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
179 |
/*****************************************************************************/ |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
180 |
|
1209 | 181 |
void ecrt_voe_handler_write(ec_voe_handler_t *voe, size_t size) |
182 |
{ |
|
183 |
voe->dir = EC_DIR_OUTPUT; |
|
1218 | 184 |
voe->data_size = size; |
1209 | 185 |
voe->state = ec_voe_handler_state_write_start; |
1348
8db0f72ace11
Fixed usage of internal request states.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
186 |
voe->request_state = EC_INT_REQUEST_BUSY; |
1209 | 187 |
} |
188 |
||
189 |
/*****************************************************************************/ |
|
190 |
||
191 |
ec_request_state_t ecrt_voe_handler_execute(ec_voe_handler_t *voe) |
|
192 |
{ |
|
1348
8db0f72ace11
Fixed usage of internal request states.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
193 |
if (voe->config->slave) { // FIXME locking? |
1209 | 194 |
voe->state(voe); |
1348
8db0f72ace11
Fixed usage of internal request states.
Florian Pose <fp@igh-essen.com>
parents:
1327
diff
changeset
|
195 |
if (voe->request_state == EC_INT_REQUEST_BUSY) |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
196 |
ec_slave_mbox_queue_datagrams(voe->config->slave,&voe->mbox); |
1209 | 197 |
} else { |
198 |
voe->state = ec_voe_handler_state_error; |
|
199 |
voe->request_state = EC_INT_REQUEST_FAILURE; |
|
200 |
} |
|
201 |
||
202 |
return ec_request_state_translation_table[voe->request_state]; |
|
203 |
} |
|
204 |
||
205 |
/****************************************************************************** |
|
206 |
* State functions. |
|
207 |
*****************************************************************************/ |
|
208 |
||
1268 | 209 |
/** Start writing VoE data. |
210 |
*/ |
|
1209 | 211 |
void ec_voe_handler_state_write_start(ec_voe_handler_t *voe) |
212 |
{ |
|
213 |
ec_slave_t *slave = voe->config->slave; |
|
214 |
uint8_t *data; |
|
215 |
||
216 |
if (slave->master->debug_level) { |
|
1921 | 217 |
EC_SLAVE_DBG(slave, 0, "Writing %zu bytes of VoE data.\n", |
218 |
voe->data_size); |
|
1209 | 219 |
ec_print_data(ecrt_voe_handler_data(voe), voe->data_size); |
220 |
} |
|
221 |
||
222 |
if (!(slave->sii.mailbox_protocols & EC_MBOX_VOE)) { |
|
1921 | 223 |
EC_SLAVE_ERR(slave, "Slave does not support VoE!\n"); |
1209 | 224 |
voe->state = ec_voe_handler_state_error; |
225 |
voe->request_state = EC_INT_REQUEST_FAILURE; |
|
226 |
return; |
|
227 |
} |
|
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
228 |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
229 |
data = ec_slave_mbox_prepare_send(slave, &voe->mbox, |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1312
diff
changeset
|
230 |
EC_MBOX_TYPE_VOE, EC_VOE_HEADER_SIZE + voe->data_size); |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1312
diff
changeset
|
231 |
if (IS_ERR(data)) { |
1218 | 232 |
voe->state = ec_voe_handler_state_error; |
233 |
voe->request_state = EC_INT_REQUEST_FAILURE; |
|
234 |
return; |
|
235 |
} |
|
236 |
||
237 |
EC_WRITE_U32(data, voe->vendor_id); |
|
238 |
EC_WRITE_U16(data + 4, voe->vendor_type); |
|
1550
81a16ba13ae6
Avoid zeroing mailbox datagram because of VoE handlers.
Florian Pose <fp@igh-essen.com>
parents:
1543
diff
changeset
|
239 |
/* data already in datagram */ |
1209 | 240 |
|
241 |
voe->retries = EC_FSM_RETRIES; |
|
242 |
voe->jiffies_start = jiffies; |
|
243 |
voe->state = ec_voe_handler_state_write_response; |
|
244 |
} |
|
245 |
||
246 |
/*****************************************************************************/ |
|
247 |
||
1268 | 248 |
/** Wait for the mailbox response. |
249 |
*/ |
|
1209 | 250 |
void ec_voe_handler_state_write_response(ec_voe_handler_t *voe) |
251 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
252 |
ec_mailbox_t *mbox = &voe->mbox; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
253 |
ec_slave_t *slave = voe->config->slave; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
254 |
|
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
255 |
if (ec_mbox_is_datagram_state(mbox,EC_DATAGRAM_TIMED_OUT) && voe->retries--) |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
256 |
return; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
257 |
|
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
258 |
if (!ec_mbox_is_datagram_state(mbox,EC_DATAGRAM_RECEIVED)) { |
1209 | 259 |
voe->state = ec_voe_handler_state_error; |
260 |
voe->request_state = EC_INT_REQUEST_FAILURE; |
|
1921 | 261 |
EC_SLAVE_ERR(slave, "Failed to receive VoE write request datagram: "); |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
262 |
ec_datagram_print_state(mbox->datagram); |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
263 |
return; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
264 |
} |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
265 |
|
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
266 |
if (!ec_mbox_is_datagram_wc(mbox,1)) { |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
267 |
if (ec_mbox_is_datagram_wc(mbox,0)) { |
1209 | 268 |
unsigned long diff_ms = |
269 |
(jiffies - voe->jiffies_start) * 1000 / HZ; |
|
270 |
if (diff_ms < EC_VOE_RESPONSE_TIMEOUT) { |
|
1921 | 271 |
EC_SLAVE_DBG(slave, 1, "Slave did not respond to" |
1931 | 272 |
" VoE write request. Retrying after %lu ms...\n", |
273 |
diff_ms); |
|
1209 | 274 |
// no response; send request datagram again |
275 |
return; |
|
276 |
} |
|
277 |
} |
|
278 |
voe->state = ec_voe_handler_state_error; |
|
279 |
voe->request_state = EC_INT_REQUEST_FAILURE; |
|
1921 | 280 |
EC_SLAVE_ERR(slave, "Reception of VoE write request failed: "); |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
281 |
ec_datagram_print_wc_error(mbox->datagram); |
1209 | 282 |
return; |
283 |
} |
|
284 |
||
1921 | 285 |
EC_CONFIG_DBG(voe->config, 1, "VoE write request successful.\n"); |
1209 | 286 |
|
287 |
voe->request_state = EC_INT_REQUEST_SUCCESS; |
|
288 |
voe->state = ec_voe_handler_state_end; |
|
289 |
} |
|
290 |
||
291 |
/*****************************************************************************/ |
|
292 |
||
1268 | 293 |
/** Start reading VoE data. |
294 |
*/ |
|
1209 | 295 |
void ec_voe_handler_state_read_start(ec_voe_handler_t *voe) |
296 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
297 |
ec_mailbox_t *mbox = &voe->mbox; |
1209 | 298 |
ec_slave_t *slave = voe->config->slave; |
299 |
||
1921 | 300 |
EC_SLAVE_DBG(slave, 1, "Reading VoE data.\n"); |
1209 | 301 |
|
302 |
if (!(slave->sii.mailbox_protocols & EC_MBOX_VOE)) { |
|
1921 | 303 |
EC_SLAVE_ERR(slave, "Slave does not support VoE!\n"); |
1209 | 304 |
voe->state = ec_voe_handler_state_error; |
305 |
voe->request_state = EC_INT_REQUEST_FAILURE; |
|
306 |
return; |
|
307 |
} |
|
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
308 |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
309 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
1209 | 310 |
|
311 |
voe->jiffies_start = jiffies; |
|
312 |
voe->retries = EC_FSM_RETRIES; |
|
313 |
voe->state = ec_voe_handler_state_read_check; |
|
314 |
} |
|
315 |
||
316 |
/*****************************************************************************/ |
|
317 |
||
1268 | 318 |
/** Check for new data in the mailbox. |
319 |
*/ |
|
1209 | 320 |
void ec_voe_handler_state_read_check(ec_voe_handler_t *voe) |
321 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
322 |
ec_mailbox_t *mbox = &voe->mbox; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
323 |
ec_slave_t *slave = voe->config->slave; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
324 |
|
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
325 |
if (ec_mbox_is_datagram_state(mbox,EC_DATAGRAM_TIMED_OUT) && voe->retries--) |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
326 |
return; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
327 |
|
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
328 |
if (!ec_mbox_is_datagram_state(mbox,EC_DATAGRAM_RECEIVED)) { |
1209 | 329 |
voe->state = ec_voe_handler_state_error; |
330 |
voe->request_state = EC_INT_REQUEST_FAILURE; |
|
1921 | 331 |
EC_SLAVE_ERR(slave, "Failed to receive VoE mailbox check datagram: "); |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
332 |
ec_datagram_print_state(mbox->datagram); |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
333 |
return; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
334 |
} |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
335 |
|
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
336 |
if (!ec_mbox_is_datagram_wc(mbox,1)) { |
1209 | 337 |
voe->state = ec_voe_handler_state_error; |
338 |
voe->request_state = EC_INT_REQUEST_FAILURE; |
|
1921 | 339 |
EC_SLAVE_ERR(slave, "Reception of VoE mailbox check" |
340 |
" datagram failed: "); |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
341 |
ec_datagram_print_wc_error(mbox->datagram); |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
342 |
return; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
343 |
} |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
344 |
|
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
345 |
if (!ec_slave_mbox_check(mbox)) { |
1209 | 346 |
unsigned long diff_ms = |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
347 |
(mbox->datagram->jiffies_received - voe->jiffies_start) * 1000 / HZ; |
1209 | 348 |
if (diff_ms >= EC_VOE_RESPONSE_TIMEOUT) { |
349 |
voe->state = ec_voe_handler_state_error; |
|
350 |
voe->request_state = EC_INT_REQUEST_FAILURE; |
|
1921 | 351 |
EC_SLAVE_ERR(slave, "Timeout while waiting for VoE data.\n"); |
1209 | 352 |
return; |
353 |
} |
|
354 |
||
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
355 |
ec_slave_mbox_prepare_check(slave, mbox); // can not fail. |
1209 | 356 |
voe->retries = EC_FSM_RETRIES; |
357 |
return; |
|
358 |
} |
|
359 |
||
360 |
// Fetch response |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
361 |
ec_slave_mbox_prepare_fetch(slave, mbox); // can not fail. |
1209 | 362 |
voe->retries = EC_FSM_RETRIES; |
363 |
voe->state = ec_voe_handler_state_read_response; |
|
364 |
} |
|
365 |
||
366 |
/*****************************************************************************/ |
|
367 |
||
1268 | 368 |
/** Read the pending mailbox data. |
369 |
*/ |
|
1209 | 370 |
void ec_voe_handler_state_read_response(ec_voe_handler_t *voe) |
371 |
{ |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
372 |
ec_mailbox_t *mbox = &voe->mbox; |
1209 | 373 |
ec_slave_t *slave = voe->config->slave; |
374 |
ec_master_t *master = voe->config->master; |
|
375 |
uint8_t *data, mbox_prot; |
|
376 |
size_t rec_size; |
|
377 |
||
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
378 |
if (ec_mbox_is_datagram_state(mbox,EC_DATAGRAM_TIMED_OUT) && voe->retries--) |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
379 |
return; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
380 |
|
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
381 |
if (!ec_mbox_is_datagram_state(mbox,EC_DATAGRAM_RECEIVED)) { |
1209 | 382 |
voe->state = ec_voe_handler_state_error; |
383 |
voe->request_state = EC_INT_REQUEST_FAILURE; |
|
1921 | 384 |
EC_SLAVE_ERR(slave, "Failed to receive VoE read datagram: "); |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
385 |
ec_datagram_print_state(mbox->datagram); |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
386 |
return; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
387 |
} |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
388 |
|
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
389 |
if (!ec_mbox_is_datagram_wc(mbox,1)) { |
1209 | 390 |
voe->state = ec_voe_handler_state_error; |
391 |
voe->request_state = EC_INT_REQUEST_FAILURE; |
|
1921 | 392 |
EC_SLAVE_ERR(slave, "Reception of VoE read response failed: "); |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
393 |
ec_datagram_print_wc_error(mbox->datagram); |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
394 |
return; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
395 |
} |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
396 |
|
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
397 |
data = ec_slave_mbox_fetch(slave, mbox, &mbox_prot, &rec_size); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1312
diff
changeset
|
398 |
if (IS_ERR(data)) { |
1209 | 399 |
voe->state = ec_voe_handler_state_error; |
400 |
voe->request_state = EC_INT_REQUEST_FAILURE; |
|
401 |
return; |
|
402 |
} |
|
403 |
||
1216
e70c4d71cebd
Changed VoE mailbox type to 0xff.
Florian Pose <fp@igh-essen.com>
parents:
1209
diff
changeset
|
404 |
if (mbox_prot != EC_MBOX_TYPE_VOE) { |
1209 | 405 |
voe->state = ec_voe_handler_state_error; |
406 |
voe->request_state = EC_INT_REQUEST_FAILURE; |
|
1921 | 407 |
EC_SLAVE_WARN(slave, "Received mailbox protocol 0x%02X" |
408 |
" as response.\n", mbox_prot); |
|
1209 | 409 |
ec_print_data(data, rec_size); |
410 |
return; |
|
411 |
} |
|
412 |
||
1218 | 413 |
if (rec_size < EC_VOE_HEADER_SIZE) { |
414 |
voe->state = ec_voe_handler_state_error; |
|
415 |
voe->request_state = EC_INT_REQUEST_FAILURE; |
|
1921 | 416 |
EC_SLAVE_ERR(slave, "Received VoE header is" |
417 |
" incomplete (%zu bytes)!\n", rec_size); |
|
1218 | 418 |
return; |
419 |
} |
|
420 |
||
1209 | 421 |
if (master->debug_level) { |
1921 | 422 |
EC_CONFIG_DBG(voe->config, 0, "VoE data:\n"); |
1209 | 423 |
ec_print_data(data, rec_size); |
424 |
} |
|
425 |
||
1218 | 426 |
voe->data_size = rec_size - EC_VOE_HEADER_SIZE; |
1209 | 427 |
voe->request_state = EC_INT_REQUEST_SUCCESS; |
428 |
voe->state = ec_voe_handler_state_end; // success |
|
429 |
} |
|
430 |
||
431 |
/*****************************************************************************/ |
|
432 |
||
1314
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
433 |
/** Start reading VoE data without sending a sync message before. |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
434 |
*/ |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
435 |
void ec_voe_handler_state_read_nosync_start(ec_voe_handler_t *voe) |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
436 |
{ |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
437 |
ec_mailbox_t *mbox = &voe->mbox; |
1314
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
438 |
ec_slave_t *slave = voe->config->slave; |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
439 |
|
1921 | 440 |
EC_SLAVE_DBG(slave, 1, "Reading VoE data.\n"); |
1314
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
441 |
|
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
442 |
if (!(slave->sii.mailbox_protocols & EC_MBOX_VOE)) { |
1921 | 443 |
EC_SLAVE_ERR(slave, "Slave does not support VoE!\n"); |
1314
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
444 |
voe->state = ec_voe_handler_state_error; |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
445 |
voe->request_state = EC_INT_REQUEST_FAILURE; |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
446 |
return; |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
447 |
} |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
448 |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
449 |
ec_slave_mbox_prepare_fetch(slave, mbox); // can not fail. |
1314
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
450 |
|
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
451 |
voe->jiffies_start = jiffies; |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
452 |
voe->retries = EC_FSM_RETRIES; |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
453 |
voe->state = ec_voe_handler_state_read_nosync_response; |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
454 |
} |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
455 |
|
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
456 |
/*****************************************************************************/ |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
457 |
|
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
458 |
/** Read the pending mailbox data without sending a sync message before. This |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
459 |
* might lead to an empty reponse from the client. |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
460 |
*/ |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
461 |
void ec_voe_handler_state_read_nosync_response(ec_voe_handler_t *voe) |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
462 |
{ |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
463 |
ec_mailbox_t *mbox = &voe->mbox; |
1314
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
464 |
ec_slave_t *slave = voe->config->slave; |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
465 |
ec_master_t *master = voe->config->master; |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
466 |
uint8_t *data, mbox_prot; |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
467 |
size_t rec_size; |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
468 |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
469 |
if (ec_mbox_is_datagram_state(mbox,EC_DATAGRAM_TIMED_OUT) && voe->retries--) |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
470 |
return; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
471 |
|
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
472 |
if (!ec_mbox_is_datagram_state(mbox,EC_DATAGRAM_RECEIVED)) { |
1314
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
473 |
voe->state = ec_voe_handler_state_error; |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
474 |
voe->request_state = EC_INT_REQUEST_FAILURE; |
1921 | 475 |
EC_SLAVE_ERR(slave, "Failed to receive VoE read datagram: "); |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
476 |
ec_datagram_print_state(mbox->datagram); |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
477 |
return; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
478 |
} |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
479 |
|
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
480 |
if (ec_mbox_is_datagram_wc(mbox,0)) { |
1314
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
481 |
voe->state = ec_voe_handler_state_error; |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
482 |
voe->request_state = EC_INT_REQUEST_FAILURE; |
1921 | 483 |
EC_SLAVE_DBG(slave, 1, "Slave did not send VoE data.\n"); |
1314
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
484 |
return; |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
485 |
} |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
486 |
|
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
487 |
if (!ec_mbox_is_datagram_wc(mbox,1)) { |
1314
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
488 |
voe->state = ec_voe_handler_state_error; |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
489 |
voe->request_state = EC_INT_REQUEST_FAILURE; |
1921 | 490 |
EC_SLAVE_WARN(slave, "Reception of VoE read response failed: "); |
2045
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
491 |
ec_datagram_print_wc_error(mbox->datagram); |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
492 |
return; |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
493 |
} |
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
494 |
|
ff2a13a4603c
Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents:
1931
diff
changeset
|
495 |
if (!(data = ec_slave_mbox_fetch(slave, mbox, |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1363
diff
changeset
|
496 |
&mbox_prot, &rec_size))) { |
1314
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
497 |
voe->state = ec_voe_handler_state_error; |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
498 |
voe->request_state = EC_INT_REQUEST_FAILURE; |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
499 |
return; |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
500 |
} |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
501 |
|
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
502 |
if (mbox_prot != EC_MBOX_TYPE_VOE) { |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
503 |
voe->state = ec_voe_handler_state_error; |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
504 |
voe->request_state = EC_INT_REQUEST_FAILURE; |
1921 | 505 |
EC_SLAVE_WARN(slave, "Received mailbox protocol 0x%02X" |
506 |
" as response.\n", mbox_prot); |
|
1314
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
507 |
ec_print_data(data, rec_size); |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
508 |
return; |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
509 |
} |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
510 |
|
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
511 |
if (rec_size < EC_VOE_HEADER_SIZE) { |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
512 |
voe->state = ec_voe_handler_state_error; |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
513 |
voe->request_state = EC_INT_REQUEST_FAILURE; |
1921 | 514 |
EC_SLAVE_ERR(slave, "Received VoE header is" |
515 |
" incomplete (%zu bytes)!\n", rec_size); |
|
1314
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
516 |
return; |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
517 |
} |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
518 |
|
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
519 |
if (master->debug_level) { |
1921 | 520 |
EC_CONFIG_DBG(voe->config, 1, "VoE data:\n"); |
1314
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
521 |
ec_print_data(data, rec_size); |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
522 |
} |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
523 |
|
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
524 |
voe->data_size = rec_size - EC_VOE_HEADER_SIZE; |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
525 |
voe->request_state = EC_INT_REQUEST_SUCCESS; |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
526 |
voe->state = ec_voe_handler_state_end; // success |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
527 |
} |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
528 |
|
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
529 |
/*****************************************************************************/ |
b3d06a8807b3
Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents:
1313
diff
changeset
|
530 |
|
1268 | 531 |
/** Successful termination state function. |
532 |
*/ |
|
1209 | 533 |
void ec_voe_handler_state_end(ec_voe_handler_t *voe) |
534 |
{ |
|
535 |
} |
|
536 |
||
537 |
/*****************************************************************************/ |
|
538 |
||
1268 | 539 |
/** Failure termination state function. |
540 |
*/ |
|
1209 | 541 |
void ec_voe_handler_state_error(ec_voe_handler_t *voe) |
542 |
{ |
|
543 |
} |
|
544 |
||
545 |
/*****************************************************************************/ |
|
546 |
||
547 |
/** \cond */ |
|
548 |
||
1226
afb189516fcf
Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents:
1224
diff
changeset
|
549 |
EXPORT_SYMBOL(ecrt_voe_handler_send_header); |
afb189516fcf
Introduced ecrt_voe_handler_received_header(); renamed
Florian Pose <fp@igh-essen.com>
parents:
1224
diff
changeset
|
550 |
EXPORT_SYMBOL(ecrt_voe_handler_received_header); |
1209 | 551 |
EXPORT_SYMBOL(ecrt_voe_handler_data); |
552 |
EXPORT_SYMBOL(ecrt_voe_handler_data_size); |
|
553 |
EXPORT_SYMBOL(ecrt_voe_handler_read); |
|
554 |
EXPORT_SYMBOL(ecrt_voe_handler_write); |
|
555 |
EXPORT_SYMBOL(ecrt_voe_handler_execute); |
|
556 |
||
557 |
/** \endcond */ |
|
558 |
||
559 |
/*****************************************************************************/ |