author | Patrick Bruenn <p.bruenn@beckhoff.com> |
Thu, 05 Jun 2014 18:12:30 +0200 | |
branch | stable-1.5 |
changeset 2575 | bf5a90b3dd05 |
parent 2528 | 8bb574da5da2 |
permissions | -rw-r--r-- |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1 |
/****************************************************************************** |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2 |
* |
1336
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
3 |
* $Id$ |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
4 |
* |
1363
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1343
diff
changeset
|
5 |
* Copyright (C) 2008 Olav Zarges, imc Messsysteme GmbH |
2527
f51f3ef3260d
Improved FoE debug messages.
Florian Pose <fp@igh-essen.com>
parents:
2522
diff
changeset
|
6 |
* 2013 Florian Pose <fp@igh-essen.com> |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
7 |
* |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
8 |
* This file is part of the IgH EtherCAT Master. |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
9 |
* |
1363
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1343
diff
changeset
|
10 |
* The IgH EtherCAT Master is free software; you can redistribute it and/or |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1343
diff
changeset
|
11 |
* modify it under the terms of the GNU General Public License version 2, as |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1343
diff
changeset
|
12 |
* published by the Free Software Foundation. |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
13 |
* |
1363
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1343
diff
changeset
|
14 |
* The IgH EtherCAT Master is distributed in the hope that it will be useful, |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1343
diff
changeset
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1343
diff
changeset
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1343
diff
changeset
|
17 |
* Public License for more details. |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
18 |
* |
1363
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1343
diff
changeset
|
19 |
* You should have received a copy of the GNU General Public License along |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1343
diff
changeset
|
20 |
* with the IgH EtherCAT Master; if not, write to the Free Software |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
21 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
22 |
* |
1363
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1343
diff
changeset
|
23 |
* --- |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1343
diff
changeset
|
24 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1343
diff
changeset
|
25 |
* The license mentioned above concerns the source code only. Using the |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1343
diff
changeset
|
26 |
* EtherCAT technology and brand is only permitted in compliance with the |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1343
diff
changeset
|
27 |
* industrial property and similar rights of Beckhoff Automation GmbH. |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
28 |
* |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
29 |
*****************************************************************************/ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
30 |
|
2527
f51f3ef3260d
Improved FoE debug messages.
Florian Pose <fp@igh-essen.com>
parents:
2522
diff
changeset
|
31 |
/** \file |
f51f3ef3260d
Improved FoE debug messages.
Florian Pose <fp@igh-essen.com>
parents:
2522
diff
changeset
|
32 |
* EtherCAT FoE state machines. |
f51f3ef3260d
Improved FoE debug messages.
Florian Pose <fp@igh-essen.com>
parents:
2522
diff
changeset
|
33 |
*/ |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
34 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
35 |
/*****************************************************************************/ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
36 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
37 |
#include "globals.h" |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
38 |
#include "master.h" |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
39 |
#include "mailbox.h" |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
40 |
#include "fsm_foe.h" |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
41 |
#include "foe.h" |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
42 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
43 |
/*****************************************************************************/ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
44 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
45 |
/** Maximum time in ms to wait for responses when reading out the dictionary. |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
46 |
*/ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
47 |
#define EC_FSM_FOE_TIMEOUT 3000 |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
48 |
|
1465 | 49 |
/** Mailbox type FoE. |
50 |
*/ |
|
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
51 |
#define EC_MBOX_TYPE_FILEACCESS 0x04 |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
52 |
|
1465 | 53 |
/** Size of the FoE header. |
54 |
*/ |
|
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
55 |
#define EC_FOE_HEADER_SIZE 6 |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
56 |
// uint8_t OpCode |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
57 |
// uint8_t reserved |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
58 |
// uint32_t PacketNo, Password, ErrorCode |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
59 |
|
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
60 |
//#define DEBUG_FOE |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
61 |
|
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
62 |
/*****************************************************************************/ |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
63 |
|
1416 | 64 |
/** FoE OpCodes. |
65 |
*/ |
|
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
66 |
enum { |
1416 | 67 |
EC_FOE_OPCODE_RRQ = 1, /**< Read request. */ |
68 |
EC_FOE_OPCODE_WRQ = 2, /**< Write request. */ |
|
69 |
EC_FOE_OPCODE_DATA = 3, /**< Data. */ |
|
70 |
EC_FOE_OPCODE_ACK = 4, /**< Acknowledge. */ |
|
71 |
EC_FOE_OPCODE_ERR = 5, /**< Error. */ |
|
72 |
EC_FOE_OPCODE_BUSY = 6 /**< Busy. */ |
|
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
73 |
} ec_foe_opcode_t; |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
74 |
|
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
75 |
/*****************************************************************************/ |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
76 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
77 |
int ec_foe_prepare_data_send(ec_fsm_foe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
78 |
int ec_foe_prepare_wrq_send(ec_fsm_foe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
79 |
int ec_foe_prepare_rrq_send(ec_fsm_foe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
80 |
int ec_foe_prepare_send_ack(ec_fsm_foe_t *, ec_datagram_t *); |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
81 |
|
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
82 |
void ec_foe_set_tx_error(ec_fsm_foe_t *, uint32_t); |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
83 |
void ec_foe_set_rx_error(ec_fsm_foe_t *, uint32_t); |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
84 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
85 |
void ec_fsm_foe_end(ec_fsm_foe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
86 |
void ec_fsm_foe_error(ec_fsm_foe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
87 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
88 |
void ec_fsm_foe_state_wrq_sent(ec_fsm_foe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
89 |
void ec_fsm_foe_state_rrq_sent(ec_fsm_foe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
90 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
91 |
void ec_fsm_foe_state_ack_check(ec_fsm_foe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
92 |
void ec_fsm_foe_state_ack_read(ec_fsm_foe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
93 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
94 |
void ec_fsm_foe_state_data_sent(ec_fsm_foe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
95 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
96 |
void ec_fsm_foe_state_data_check(ec_fsm_foe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
97 |
void ec_fsm_foe_state_data_read(ec_fsm_foe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
98 |
void ec_fsm_foe_state_sent_ack(ec_fsm_foe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
99 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
100 |
void ec_fsm_foe_write_start(ec_fsm_foe_t *, ec_datagram_t *); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
101 |
void ec_fsm_foe_read_start(ec_fsm_foe_t *, ec_datagram_t *); |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
102 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
103 |
/*****************************************************************************/ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
104 |
|
1901
2a1106b1d863
Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents:
1822
diff
changeset
|
105 |
/** Constructor. |
2a1106b1d863
Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents:
1822
diff
changeset
|
106 |
*/ |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
107 |
void ec_fsm_foe_init( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
108 |
ec_fsm_foe_t *fsm /**< finite state machine */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
109 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
110 |
{ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
111 |
fsm->state = NULL; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
112 |
fsm->datagram = NULL; |
1901
2a1106b1d863
Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents:
1822
diff
changeset
|
113 |
} |
2a1106b1d863
Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents:
1822
diff
changeset
|
114 |
|
2a1106b1d863
Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents:
1822
diff
changeset
|
115 |
/*****************************************************************************/ |
2a1106b1d863
Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents:
1822
diff
changeset
|
116 |
|
2a1106b1d863
Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents:
1822
diff
changeset
|
117 |
/** Destructor. |
2a1106b1d863
Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents:
1822
diff
changeset
|
118 |
*/ |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
119 |
void ec_fsm_foe_clear(ec_fsm_foe_t *fsm /**< finite state machine */) |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
120 |
{ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
121 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
122 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
123 |
/*****************************************************************************/ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
124 |
|
1901
2a1106b1d863
Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents:
1822
diff
changeset
|
125 |
/** Executes the current state of the state machine. |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
126 |
* |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
127 |
* \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:
2257
diff
changeset
|
128 |
*/ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
129 |
int ec_fsm_foe_exec( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
130 |
ec_fsm_foe_t *fsm, /**< finite state machine */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
131 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
132 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
133 |
{ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
134 |
int datagram_used = 0; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
135 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
136 |
if (fsm->datagram && |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
137 |
(fsm->datagram->state == EC_DATAGRAM_INIT || |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
138 |
fsm->datagram->state == EC_DATAGRAM_QUEUED || |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
139 |
fsm->datagram->state == EC_DATAGRAM_SENT)) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
140 |
// datagram not received yet |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
141 |
return datagram_used; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
142 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
143 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
144 |
fsm->state(fsm, datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
145 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
146 |
datagram_used = |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
147 |
fsm->state != ec_fsm_foe_end && fsm->state != ec_fsm_foe_error; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
148 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
149 |
if (datagram_used) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
150 |
fsm->datagram = datagram; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
151 |
} else { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
152 |
fsm->datagram = NULL; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
153 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
154 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
155 |
return datagram_used; |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
156 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
157 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
158 |
/*****************************************************************************/ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
159 |
|
1901
2a1106b1d863
Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents:
1822
diff
changeset
|
160 |
/** Returns, if the state machine terminated with success. |
2a1106b1d863
Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents:
1822
diff
changeset
|
161 |
* \return non-zero if successful. |
2a1106b1d863
Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents:
1822
diff
changeset
|
162 |
*/ |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
163 |
int ec_fsm_foe_success(const ec_fsm_foe_t *fsm /**< Finite state machine */) |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
164 |
{ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
165 |
return fsm->state == ec_fsm_foe_end; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
166 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
167 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
168 |
/*****************************************************************************/ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
169 |
|
1465 | 170 |
/** Prepares an FoE transfer. |
171 |
*/ |
|
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
172 |
void ec_fsm_foe_transfer( |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
173 |
ec_fsm_foe_t *fsm, /**< State machine. */ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
174 |
ec_slave_t *slave, /**< EtherCAT slave. */ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
175 |
ec_foe_request_t *request /**< Sdo request. */ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
176 |
) |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
177 |
{ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
178 |
fsm->slave = slave; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
179 |
fsm->request = request; |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
180 |
|
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
181 |
if (request->dir == EC_DIR_OUTPUT) { |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
182 |
fsm->tx_buffer = fsm->request->buffer; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
183 |
fsm->tx_buffer_size = fsm->request->data_size; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
184 |
fsm->tx_buffer_offset = 0; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
185 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
186 |
fsm->tx_filename = fsm->request->file_name; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
187 |
fsm->tx_filename_len = strlen(fsm->tx_filename); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
188 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
189 |
fsm->state = ec_fsm_foe_write_start; |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
190 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
191 |
else { |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
192 |
fsm->rx_buffer = fsm->request->buffer; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
193 |
fsm->rx_buffer_size = fsm->request->buffer_size; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
194 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
195 |
fsm->rx_filename = fsm->request->file_name; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
196 |
fsm->rx_filename_len = strlen(fsm->rx_filename); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
197 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
198 |
fsm->state = ec_fsm_foe_read_start; |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
199 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
200 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
201 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
202 |
/*****************************************************************************/ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
203 |
|
1901
2a1106b1d863
Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents:
1822
diff
changeset
|
204 |
/** State: ERROR. |
2a1106b1d863
Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents:
1822
diff
changeset
|
205 |
*/ |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
206 |
void ec_fsm_foe_error( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
207 |
ec_fsm_foe_t *fsm, /**< finite state machine */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
208 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
209 |
) |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
210 |
{ |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
211 |
#ifdef DEBUG_FOE |
2527
f51f3ef3260d
Improved FoE debug messages.
Florian Pose <fp@igh-essen.com>
parents:
2522
diff
changeset
|
212 |
EC_SLAVE_DBG(fsm->slave, 0, "%s()\n", __func__); |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
213 |
#endif |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
214 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
215 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
216 |
/*****************************************************************************/ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
217 |
|
1901
2a1106b1d863
Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents:
1822
diff
changeset
|
218 |
/** State: END. |
2a1106b1d863
Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents:
1822
diff
changeset
|
219 |
*/ |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
220 |
void ec_fsm_foe_end( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
221 |
ec_fsm_foe_t *fsm, /**< finite state machine */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
222 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
223 |
) |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
224 |
{ |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
225 |
#ifdef DEBUG_FOE |
2527
f51f3ef3260d
Improved FoE debug messages.
Florian Pose <fp@igh-essen.com>
parents:
2522
diff
changeset
|
226 |
EC_SLAVE_DBG(fsm->slave, 0, "%s()\n", __func__); |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
227 |
#endif |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
228 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
229 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
230 |
/*****************************************************************************/ |
1901
2a1106b1d863
Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents:
1822
diff
changeset
|
231 |
|
2a1106b1d863
Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents:
1822
diff
changeset
|
232 |
/** Sends a file or the next fragment. |
2522
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2502
diff
changeset
|
233 |
* |
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2502
diff
changeset
|
234 |
* \return Zero on success, otherwise a negative error code. |
1901
2a1106b1d863
Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents:
1822
diff
changeset
|
235 |
*/ |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
236 |
int ec_foe_prepare_data_send( |
2522
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2502
diff
changeset
|
237 |
ec_fsm_foe_t *fsm, /**< Finite state machine. */ |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
238 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
239 |
) |
1446
85ea5af50175
Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1416
diff
changeset
|
240 |
{ |
85ea5af50175
Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1416
diff
changeset
|
241 |
size_t remaining_size, current_size; |
85ea5af50175
Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1416
diff
changeset
|
242 |
uint8_t *data; |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
243 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
244 |
remaining_size = fsm->tx_buffer_size - fsm->tx_buffer_offset; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
245 |
|
1338
eb31b5a135da
merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents:
1337
diff
changeset
|
246 |
if (remaining_size < fsm->slave->configured_tx_mailbox_size |
1337
0253c74d0940
merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents:
1336
diff
changeset
|
247 |
- EC_MBOX_HEADER_SIZE - EC_FOE_HEADER_SIZE) { |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
248 |
current_size = remaining_size; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
249 |
fsm->tx_last_packet = 1; |
1337
0253c74d0940
merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents:
1336
diff
changeset
|
250 |
} else { |
1338
eb31b5a135da
merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents:
1337
diff
changeset
|
251 |
current_size = fsm->slave->configured_tx_mailbox_size |
1337
0253c74d0940
merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents:
1336
diff
changeset
|
252 |
- EC_MBOX_HEADER_SIZE - EC_FOE_HEADER_SIZE; |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
253 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
254 |
|
1446
85ea5af50175
Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1416
diff
changeset
|
255 |
data = ec_slave_mbox_prepare_send(fsm->slave, |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
256 |
datagram, EC_MBOX_TYPE_FILEACCESS, |
1446
85ea5af50175
Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1416
diff
changeset
|
257 |
current_size + EC_FOE_HEADER_SIZE); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
258 |
if (IS_ERR(data)) { |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
259 |
return -1; |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
260 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
261 |
|
2501
64cdc3b59d25
Fixed FoE data opcode, thanks to R. Roesch.
Florian Pose <fp@igh-essen.com>
parents:
2498
diff
changeset
|
262 |
EC_WRITE_U16(data, EC_FOE_OPCODE_DATA); // OpCode = DataBlock req. |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
263 |
EC_WRITE_U32(data + 2, fsm->tx_packet_no); // PacketNo, Password |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
264 |
|
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
265 |
memcpy(data + EC_FOE_HEADER_SIZE, |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
266 |
fsm->tx_buffer + fsm->tx_buffer_offset, current_size); |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
267 |
fsm->tx_current_size = current_size; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
268 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
269 |
return 0; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
270 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
271 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
272 |
/*****************************************************************************/ |
1901
2a1106b1d863
Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents:
1822
diff
changeset
|
273 |
|
2a1106b1d863
Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents:
1822
diff
changeset
|
274 |
/** Prepare a write request (WRQ) with filename |
2522
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2502
diff
changeset
|
275 |
* |
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2502
diff
changeset
|
276 |
* \return Zero on success, otherwise a negative error code. |
1901
2a1106b1d863
Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents:
1822
diff
changeset
|
277 |
*/ |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
278 |
int ec_foe_prepare_wrq_send( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
279 |
ec_fsm_foe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
280 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
281 |
) |
1446
85ea5af50175
Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1416
diff
changeset
|
282 |
{ |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
283 |
size_t current_size; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
284 |
uint8_t *data; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
285 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
286 |
fsm->tx_buffer_offset = 0; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
287 |
fsm->tx_current_size = 0; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
288 |
fsm->tx_packet_no = 0; |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
289 |
fsm->tx_last_packet = 0; |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
290 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
291 |
current_size = fsm->tx_filename_len; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
292 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
293 |
data = ec_slave_mbox_prepare_send(fsm->slave, datagram, |
1446
85ea5af50175
Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1416
diff
changeset
|
294 |
EC_MBOX_TYPE_FILEACCESS, current_size + EC_FOE_HEADER_SIZE); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
295 |
if (IS_ERR(data)) { |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
296 |
return -1; |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
297 |
} |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
298 |
|
1336
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
299 |
EC_WRITE_U16( data, EC_FOE_OPCODE_WRQ); // fsm write request |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
300 |
EC_WRITE_U32( data + 2, fsm->tx_packet_no ); |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
301 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
302 |
memcpy(data + EC_FOE_HEADER_SIZE, fsm->tx_filename, current_size); |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
303 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
304 |
return 0; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
305 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
306 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
307 |
/*****************************************************************************/ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
308 |
|
1465 | 309 |
/** Initializes the FoE write state machine. |
310 |
*/ |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
311 |
void ec_fsm_foe_write_start( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
312 |
ec_fsm_foe_t *fsm, /**< finite state machine */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
313 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
314 |
) |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
315 |
{ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
316 |
ec_slave_t *slave = fsm->slave; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
317 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
318 |
fsm->tx_buffer_offset = 0; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
319 |
fsm->tx_current_size = 0; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
320 |
fsm->tx_packet_no = 0; |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
321 |
fsm->tx_last_packet = 0; |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
322 |
|
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
323 |
#ifdef DEBUG_FOE |
2527
f51f3ef3260d
Improved FoE debug messages.
Florian Pose <fp@igh-essen.com>
parents:
2522
diff
changeset
|
324 |
EC_SLAVE_DBG(fsm->slave, 0, "%s()\n", __func__); |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
325 |
#endif |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
326 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
327 |
if (!(slave->sii.mailbox_protocols & EC_MBOX_FOE)) { |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
328 |
ec_foe_set_tx_error(fsm, FOE_MBOX_PROT_ERROR); |
1921 | 329 |
EC_SLAVE_ERR(slave, "Slave does not support FoE!\n"); |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
330 |
return; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
331 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
332 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
333 |
if (ec_foe_prepare_wrq_send(fsm, datagram)) { |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
334 |
ec_foe_set_tx_error(fsm, FOE_PROT_ERROR); |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
335 |
return; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
336 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
337 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
338 |
fsm->state = ec_fsm_foe_state_wrq_sent; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
339 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
340 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
341 |
/*****************************************************************************/ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
342 |
|
1465 | 343 |
/** Check for acknowledge. |
344 |
*/ |
|
345 |
void ec_fsm_foe_state_ack_check( |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
346 |
ec_fsm_foe_t *fsm, /**< FoE statemachine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
347 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
348 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
349 |
{ |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
350 |
ec_slave_t *slave = fsm->slave; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
351 |
|
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
352 |
#ifdef DEBUG_FOE |
2527
f51f3ef3260d
Improved FoE debug messages.
Florian Pose <fp@igh-essen.com>
parents:
2522
diff
changeset
|
353 |
EC_SLAVE_DBG(fsm->slave, 0, "%s()\n", __func__); |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
354 |
#endif |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
355 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
356 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
357 |
ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR); |
1921 | 358 |
EC_SLAVE_ERR(slave, "Failed to receive FoE mailbox check datagram: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
359 |
ec_datagram_print_state(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
360 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
361 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
362 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
363 |
if (fsm->datagram->working_counter != 1) { |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
364 |
ec_foe_set_rx_error(fsm, FOE_WC_ERROR); |
1921 | 365 |
EC_SLAVE_ERR(slave, "Reception of FoE mailbox check datagram" |
366 |
" failed: "); |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
367 |
ec_datagram_print_wc_error(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
368 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
369 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
370 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
371 |
if (!ec_slave_mbox_check(fsm->datagram)) { |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
372 |
// slave did not put anything in the mailbox yet |
2528
8bb574da5da2
Fixed FoE timeout calculation bug.
Florian Pose <fp@igh-essen.com>
parents:
2527
diff
changeset
|
373 |
unsigned long diff_ms = (fsm->datagram->jiffies_received - |
8bb574da5da2
Fixed FoE timeout calculation bug.
Florian Pose <fp@igh-essen.com>
parents:
2527
diff
changeset
|
374 |
fsm->jiffies_start) * 1000 / HZ; |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
375 |
if (diff_ms >= EC_FSM_FOE_TIMEOUT) { |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
376 |
ec_foe_set_tx_error(fsm, FOE_TIMEOUT_ERROR); |
1921 | 377 |
EC_SLAVE_ERR(slave, "Timeout while waiting for ack response.\n"); |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
378 |
return; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
379 |
} |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
380 |
|
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
381 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
382 |
fsm->retries = EC_FSM_RETRIES; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
383 |
return; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
384 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
385 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
386 |
// Fetch response |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
387 |
ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail. |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
388 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
389 |
fsm->retries = EC_FSM_RETRIES; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
390 |
fsm->state = ec_fsm_foe_state_ack_read; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
391 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
392 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
393 |
/*****************************************************************************/ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
394 |
|
1465 | 395 |
/** Acknowledge a read operation. |
396 |
*/ |
|
397 |
void ec_fsm_foe_state_ack_read( |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
398 |
ec_fsm_foe_t *fsm, /**< FoE statemachine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
399 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
400 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
401 |
{ |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
402 |
ec_slave_t *slave = fsm->slave; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
403 |
uint8_t *data, mbox_prot; |
1336
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
404 |
uint8_t opCode; |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
405 |
size_t rec_size; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
406 |
|
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
407 |
#ifdef DEBUG_FOE |
2527
f51f3ef3260d
Improved FoE debug messages.
Florian Pose <fp@igh-essen.com>
parents:
2522
diff
changeset
|
408 |
EC_SLAVE_DBG(fsm->slave, 0, "%s()\n", __func__); |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
409 |
#endif |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
410 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
411 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
412 |
ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR); |
1921 | 413 |
EC_SLAVE_ERR(slave, "Failed to receive FoE ack response datagram: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
414 |
ec_datagram_print_state(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
415 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
416 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
417 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
418 |
if (fsm->datagram->working_counter != 1) { |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
419 |
ec_foe_set_rx_error(fsm, FOE_WC_ERROR); |
1921 | 420 |
EC_SLAVE_ERR(slave, "Reception of FoE ack response failed: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
421 |
ec_datagram_print_wc_error(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
422 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
423 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
424 |
|
2502
906ef8b1c0ec
FoE datagram / fsm->datagram bugfix, thanks to R. Roesch.
Florian Pose <fp@igh-essen.com>
parents:
2501
diff
changeset
|
425 |
data = ec_slave_mbox_fetch(slave, fsm->datagram, &mbox_prot, &rec_size); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
426 |
if (IS_ERR(data)) { |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
427 |
ec_foe_set_tx_error(fsm, FOE_PROT_ERROR); |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
428 |
return; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
429 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
430 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
431 |
if (mbox_prot != EC_MBOX_TYPE_FILEACCESS) { // FoE |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
432 |
ec_foe_set_tx_error(fsm, FOE_MBOX_PROT_ERROR); |
1921 | 433 |
EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n", |
434 |
mbox_prot); |
|
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
435 |
return; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
436 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
437 |
|
1336
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
438 |
opCode = EC_READ_U8(data); |
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
439 |
|
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
440 |
if (opCode == EC_FOE_OPCODE_BUSY) { |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
441 |
// slave not ready |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
442 |
if (ec_foe_prepare_data_send(fsm, datagram)) { |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
443 |
ec_foe_set_tx_error(fsm, FOE_PROT_ERROR); |
1921 | 444 |
EC_SLAVE_ERR(slave, "Slave is busy.\n"); |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
445 |
return; |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
446 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
447 |
fsm->state = ec_fsm_foe_state_data_sent; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
448 |
return; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
449 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
450 |
|
1336
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
451 |
if (opCode == EC_FOE_OPCODE_ACK) { |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
452 |
fsm->tx_packet_no++; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
453 |
fsm->tx_buffer_offset += fsm->tx_current_size; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
454 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
455 |
if (fsm->tx_last_packet) { |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
456 |
fsm->state = ec_fsm_foe_end; |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
457 |
return; |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
458 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
459 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
460 |
if (ec_foe_prepare_data_send(fsm, datagram)) { |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
461 |
ec_foe_set_tx_error(fsm, FOE_PROT_ERROR); |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
462 |
return; |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
463 |
} |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
464 |
fsm->state = ec_fsm_foe_state_data_sent; |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
465 |
return; |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
466 |
} |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
467 |
ec_foe_set_tx_error(fsm, FOE_ACK_ERROR); |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
468 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
469 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
470 |
/*****************************************************************************/ |
1465 | 471 |
|
472 |
/** State: WRQ SENT. |
|
473 |
* |
|
474 |
* Checks is the previous transmit datagram succeded and sends the next |
|
475 |
* fragment, if necessary. |
|
476 |
*/ |
|
477 |
void ec_fsm_foe_state_wrq_sent( |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
478 |
ec_fsm_foe_t *fsm, /**< FoE statemachine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
479 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
480 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
481 |
{ |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
482 |
ec_slave_t *slave = fsm->slave; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
483 |
|
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
484 |
#ifdef DEBUG_FOE |
2527
f51f3ef3260d
Improved FoE debug messages.
Florian Pose <fp@igh-essen.com>
parents:
2522
diff
changeset
|
485 |
EC_SLAVE_DBG(fsm->slave, 0, "%s()\n", __func__); |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
486 |
#endif |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
487 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
488 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
489 |
ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR); |
1921 | 490 |
EC_SLAVE_ERR(slave, "Failed to send FoE WRQ: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
491 |
ec_datagram_print_state(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
492 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
493 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
494 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
495 |
if (fsm->datagram->working_counter != 1) { |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
496 |
// slave did not put anything in the mailbox yet |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
497 |
ec_foe_set_rx_error(fsm, FOE_WC_ERROR); |
1921 | 498 |
EC_SLAVE_ERR(slave, "Reception of FoE WRQ failed: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
499 |
ec_datagram_print_wc_error(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
500 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
501 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
502 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
503 |
fsm->jiffies_start = fsm->datagram->jiffies_sent; |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
504 |
|
2502
906ef8b1c0ec
FoE datagram / fsm->datagram bugfix, thanks to R. Roesch.
Florian Pose <fp@igh-essen.com>
parents:
2501
diff
changeset
|
505 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
506 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
507 |
fsm->retries = EC_FSM_RETRIES; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
508 |
fsm->state = ec_fsm_foe_state_ack_check; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
509 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
510 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
511 |
/*****************************************************************************/ |
1465 | 512 |
|
513 |
/** State: WRQ SENT. |
|
514 |
* |
|
515 |
* Checks is the previous transmit datagram succeded and sends the next |
|
516 |
* fragment, if necessary. |
|
517 |
*/ |
|
518 |
void ec_fsm_foe_state_data_sent( |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
519 |
ec_fsm_foe_t *fsm, /**< Foe statemachine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
520 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
521 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
522 |
{ |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
523 |
ec_slave_t *slave = fsm->slave; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
524 |
|
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
525 |
#ifdef DEBUG_FOE |
2527
f51f3ef3260d
Improved FoE debug messages.
Florian Pose <fp@igh-essen.com>
parents:
2522
diff
changeset
|
526 |
EC_SLAVE_DBG(fsm->slave, 0, "%s()\n", __func__); |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
527 |
#endif |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
528 |
|
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
529 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
530 |
ec_foe_set_tx_error(fsm, FOE_RECEIVE_ERROR); |
1921 | 531 |
EC_SLAVE_ERR(slave, "Failed to receive FoE ack response datagram: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
532 |
ec_datagram_print_state(fsm->datagram); |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
533 |
return; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
534 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
535 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
536 |
if (fsm->datagram->working_counter != 1) { |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
537 |
ec_foe_set_tx_error(fsm, FOE_WC_ERROR); |
1921 | 538 |
EC_SLAVE_ERR(slave, "Reception of FoE data send failed: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
539 |
ec_datagram_print_wc_error(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
540 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
541 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
542 |
|
2502
906ef8b1c0ec
FoE datagram / fsm->datagram bugfix, thanks to R. Roesch.
Florian Pose <fp@igh-essen.com>
parents:
2501
diff
changeset
|
543 |
ec_slave_mbox_prepare_check(slave, datagram); |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
544 |
fsm->jiffies_start = jiffies; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
545 |
fsm->retries = EC_FSM_RETRIES; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
546 |
fsm->state = ec_fsm_foe_state_ack_check; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
547 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
548 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
549 |
/*****************************************************************************/ |
1901
2a1106b1d863
Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents:
1822
diff
changeset
|
550 |
|
2a1106b1d863
Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents:
1822
diff
changeset
|
551 |
/** Prepare a read request (RRQ) with filename |
2522
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2502
diff
changeset
|
552 |
* |
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2502
diff
changeset
|
553 |
* \return Zero on success, otherwise a negative error code. |
1901
2a1106b1d863
Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents:
1822
diff
changeset
|
554 |
*/ |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
555 |
int ec_foe_prepare_rrq_send( |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
556 |
ec_fsm_foe_t *fsm, /**< Finite state machine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
557 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
558 |
) |
1446
85ea5af50175
Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1416
diff
changeset
|
559 |
{ |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
560 |
size_t current_size; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
561 |
uint8_t *data; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
562 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
563 |
current_size = fsm->rx_filename_len; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
564 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
565 |
data = ec_slave_mbox_prepare_send(fsm->slave, datagram, |
1446
85ea5af50175
Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1416
diff
changeset
|
566 |
EC_MBOX_TYPE_FILEACCESS, current_size + EC_FOE_HEADER_SIZE); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
567 |
if (IS_ERR(data)) { |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
568 |
return -1; |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
569 |
} |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
570 |
|
1336
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
571 |
EC_WRITE_U16(data, EC_FOE_OPCODE_RRQ); // fsm read request |
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
572 |
EC_WRITE_U32(data + 2, 0x00000000); // no passwd |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
573 |
memcpy(data + EC_FOE_HEADER_SIZE, fsm->rx_filename, current_size); |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
574 |
|
1336
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
575 |
if (fsm->slave->master->debug_level) { |
1921 | 576 |
EC_SLAVE_DBG(fsm->slave, 1, "FoE Read Request:\n"); |
1336
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
577 |
ec_print_data(data, current_size + EC_FOE_HEADER_SIZE); |
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
578 |
} |
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
579 |
|
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
580 |
return 0; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
581 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
582 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
583 |
/*****************************************************************************/ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
584 |
|
1465 | 585 |
/** Prepare to send an acknowledge. |
2522
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2502
diff
changeset
|
586 |
* |
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2502
diff
changeset
|
587 |
* \return Zero on success, otherwise a negative error code. |
1465 | 588 |
*/ |
589 |
int ec_foe_prepare_send_ack( |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
590 |
ec_fsm_foe_t *fsm, /**< FoE statemachine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
591 |
ec_datagram_t *datagram /**< Datagram to use. */ |
1465 | 592 |
) |
1446
85ea5af50175
Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1416
diff
changeset
|
593 |
{ |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
594 |
uint8_t *data; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
595 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
596 |
data = ec_slave_mbox_prepare_send(fsm->slave, datagram, |
1446
85ea5af50175
Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1416
diff
changeset
|
597 |
EC_MBOX_TYPE_FILEACCESS, EC_FOE_HEADER_SIZE); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
598 |
if (IS_ERR(data)) { |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
599 |
return -1; |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
600 |
} |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
601 |
|
1446
85ea5af50175
Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents:
1416
diff
changeset
|
602 |
EC_WRITE_U16(data, EC_FOE_OPCODE_ACK); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
603 |
EC_WRITE_U32(data + 2, fsm->rx_expected_packet_no); |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
604 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
605 |
return 0; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
606 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
607 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
608 |
/*****************************************************************************/ |
1465 | 609 |
|
610 |
/** State: RRQ SENT. |
|
611 |
* |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
612 |
* Checks is the previous transmit datagram succeeded and sends the next |
1465 | 613 |
* fragment, if necessary. |
614 |
*/ |
|
615 |
void ec_fsm_foe_state_rrq_sent( |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
616 |
ec_fsm_foe_t *fsm, /**< FoE statemachine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
617 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
618 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
619 |
{ |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
620 |
ec_slave_t *slave = fsm->slave; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
621 |
|
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
622 |
#ifdef DEBUG_FOE |
2527
f51f3ef3260d
Improved FoE debug messages.
Florian Pose <fp@igh-essen.com>
parents:
2522
diff
changeset
|
623 |
EC_SLAVE_DBG(fsm->slave, 0, "%s()\n", __func__); |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
624 |
#endif |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
625 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
626 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
627 |
ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR); |
1921 | 628 |
EC_SLAVE_ERR(slave, "Failed to send FoE RRQ: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
629 |
ec_datagram_print_state(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
630 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
631 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
632 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
633 |
if (fsm->datagram->working_counter != 1) { |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
634 |
// slave did not put anything in the mailbox yet |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
635 |
ec_foe_set_rx_error(fsm, FOE_WC_ERROR); |
1921 | 636 |
EC_SLAVE_ERR(slave, "Reception of FoE RRQ failed: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
637 |
ec_datagram_print_wc_error(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
638 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
639 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
640 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
641 |
fsm->jiffies_start = fsm->datagram->jiffies_sent; |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
642 |
|
2502
906ef8b1c0ec
FoE datagram / fsm->datagram bugfix, thanks to R. Roesch.
Florian Pose <fp@igh-essen.com>
parents:
2501
diff
changeset
|
643 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
644 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
645 |
fsm->retries = EC_FSM_RETRIES; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
646 |
fsm->state = ec_fsm_foe_state_data_check; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
647 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
648 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
649 |
/*****************************************************************************/ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
650 |
|
1465 | 651 |
/** Starting state for read operations. |
652 |
*/ |
|
653 |
void ec_fsm_foe_read_start( |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
654 |
ec_fsm_foe_t *fsm, /**< FoE statemachine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
655 |
ec_datagram_t *datagram /**< Datagram to use. */ |
1465 | 656 |
) |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
657 |
{ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
658 |
ec_slave_t *slave = fsm->slave; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
659 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
660 |
fsm->rx_buffer_offset = 0; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
661 |
fsm->rx_expected_packet_no = 1; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
662 |
fsm->rx_last_packet = 0; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
663 |
|
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
664 |
#ifdef DEBUG_FOE |
2527
f51f3ef3260d
Improved FoE debug messages.
Florian Pose <fp@igh-essen.com>
parents:
2522
diff
changeset
|
665 |
EC_SLAVE_DBG(fsm->slave, 0, "%s()\n", __func__); |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
666 |
#endif |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
667 |
|
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
668 |
if (!(slave->sii.mailbox_protocols & EC_MBOX_FOE)) { |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
669 |
ec_foe_set_tx_error(fsm, FOE_MBOX_PROT_ERROR); |
1921 | 670 |
EC_SLAVE_ERR(slave, "Slave does not support FoE!\n"); |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
671 |
return; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
672 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
673 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
674 |
if (ec_foe_prepare_rrq_send(fsm, datagram)) { |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
675 |
ec_foe_set_rx_error(fsm, FOE_PROT_ERROR); |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
676 |
return; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
677 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
678 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
679 |
fsm->state = ec_fsm_foe_state_rrq_sent; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
680 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
681 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
682 |
/*****************************************************************************/ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
683 |
|
1465 | 684 |
/** Check for data. |
685 |
*/ |
|
686 |
void ec_fsm_foe_state_data_check( |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
687 |
ec_fsm_foe_t *fsm, /**< FoE statemachine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
688 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
689 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
690 |
{ |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
691 |
ec_slave_t *slave = fsm->slave; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
692 |
|
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
693 |
#ifdef DEBUG_FOE |
2527
f51f3ef3260d
Improved FoE debug messages.
Florian Pose <fp@igh-essen.com>
parents:
2522
diff
changeset
|
694 |
EC_SLAVE_DBG(fsm->slave, 0, "%s()\n", __func__); |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
695 |
#endif |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
696 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
697 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
698 |
ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR); |
1921 | 699 |
EC_SLAVE_ERR(slave, "Failed to send FoE DATA READ: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
700 |
ec_datagram_print_state(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
701 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
702 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
703 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
704 |
if (fsm->datagram->working_counter != 1) { |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
705 |
ec_foe_set_rx_error(fsm, FOE_WC_ERROR); |
1921 | 706 |
EC_SLAVE_ERR(slave, "Reception of FoE DATA READ: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
707 |
ec_datagram_print_wc_error(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
708 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
709 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
710 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
711 |
if (!ec_slave_mbox_check(fsm->datagram)) { |
2528
8bb574da5da2
Fixed FoE timeout calculation bug.
Florian Pose <fp@igh-essen.com>
parents:
2527
diff
changeset
|
712 |
unsigned long diff_ms = (fsm->datagram->jiffies_received - |
8bb574da5da2
Fixed FoE timeout calculation bug.
Florian Pose <fp@igh-essen.com>
parents:
2527
diff
changeset
|
713 |
fsm->jiffies_start) * 1000 / HZ; |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
714 |
if (diff_ms >= EC_FSM_FOE_TIMEOUT) { |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
715 |
ec_foe_set_tx_error(fsm, FOE_TIMEOUT_ERROR); |
1921 | 716 |
EC_SLAVE_ERR(slave, "Timeout while waiting for ack response.\n"); |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
717 |
return; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
718 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
719 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
720 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
721 |
fsm->retries = EC_FSM_RETRIES; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
722 |
return; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
723 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
724 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
725 |
// Fetch response |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
726 |
ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail. |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
727 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
728 |
fsm->retries = EC_FSM_RETRIES; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
729 |
fsm->state = ec_fsm_foe_state_data_read; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
730 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
731 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
732 |
/*****************************************************************************/ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
733 |
|
1465 | 734 |
/** Start reading data. |
735 |
*/ |
|
736 |
void ec_fsm_foe_state_data_read( |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
737 |
ec_fsm_foe_t *fsm, /**< FoE statemachine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
738 |
ec_datagram_t *datagram /**< Datagram to use. */ |
1465 | 739 |
) |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
740 |
{ |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
741 |
size_t rec_size; |
1336
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
742 |
uint8_t *data, opCode, packet_no, mbox_prot; |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
743 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
744 |
ec_slave_t *slave = fsm->slave; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
745 |
|
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
746 |
#ifdef DEBUG_FOE |
2527
f51f3ef3260d
Improved FoE debug messages.
Florian Pose <fp@igh-essen.com>
parents:
2522
diff
changeset
|
747 |
EC_SLAVE_DBG(fsm->slave, 0, "%s()\n", __func__); |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
748 |
#endif |
1336
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
749 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
750 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
751 |
ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR); |
1921 | 752 |
EC_SLAVE_ERR(slave, "Failed to receive FoE DATA READ datagram: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
753 |
ec_datagram_print_state(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
754 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
755 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
756 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
757 |
if (fsm->datagram->working_counter != 1) { |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
758 |
ec_foe_set_rx_error(fsm, FOE_WC_ERROR); |
1921 | 759 |
EC_SLAVE_ERR(slave, "Reception of FoE DATA READ failed: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
760 |
ec_datagram_print_wc_error(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
761 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
762 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
763 |
|
2502
906ef8b1c0ec
FoE datagram / fsm->datagram bugfix, thanks to R. Roesch.
Florian Pose <fp@igh-essen.com>
parents:
2501
diff
changeset
|
764 |
data = ec_slave_mbox_fetch(slave, fsm->datagram, &mbox_prot, &rec_size); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
765 |
if (IS_ERR(data)) { |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
766 |
ec_foe_set_rx_error(fsm, FOE_MBOX_FETCH_ERROR); |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
767 |
return; |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
768 |
} |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
769 |
|
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
770 |
if (mbox_prot != EC_MBOX_TYPE_FILEACCESS) { // FoE |
1921 | 771 |
EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n", |
772 |
mbox_prot); |
|
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
773 |
ec_foe_set_rx_error(fsm, FOE_PROT_ERROR); |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
774 |
return; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
775 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
776 |
|
1336
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
777 |
opCode = EC_READ_U8(data); |
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
778 |
|
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
779 |
if (opCode == EC_FOE_OPCODE_BUSY) { |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
780 |
if (ec_foe_prepare_send_ack(fsm, datagram)) { |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
781 |
ec_foe_set_rx_error(fsm, FOE_PROT_ERROR); |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
782 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
783 |
return; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
784 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
785 |
|
1336
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
786 |
if (opCode == EC_FOE_OPCODE_ERR) { |
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
787 |
fsm->request->error_code = EC_READ_U32(data + 2); |
1921 | 788 |
EC_SLAVE_ERR(slave, "Received FoE Error Request (code 0x%08x).\n", |
789 |
fsm->request->error_code); |
|
1336
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
790 |
if (rec_size > 6) { |
2257
a2a675601c98
Decreased maximum length of error message to avoid stack warning.
Florian Pose <fp@igh-essen.com>
parents:
2235
diff
changeset
|
791 |
uint8_t text[256]; |
1336
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
792 |
strncpy(text, data + 6, min(rec_size - 6, sizeof(text))); |
1921 | 793 |
EC_SLAVE_ERR(slave, "FoE Error Text: %s\n", text); |
1336
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
794 |
} |
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
795 |
ec_foe_set_rx_error(fsm, FOE_OPCODE_ERROR); |
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
796 |
return; |
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
797 |
} |
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
798 |
|
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
799 |
if (opCode != EC_FOE_OPCODE_DATA) { |
1921 | 800 |
EC_SLAVE_ERR(slave, "Received OPCODE %x, expected %x.\n", |
801 |
opCode, EC_FOE_OPCODE_DATA); |
|
1336
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
802 |
fsm->request->error_code = 0x00000000; |
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
803 |
ec_foe_set_rx_error(fsm, FOE_OPCODE_ERROR); |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
804 |
return; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
805 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
806 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
807 |
packet_no = EC_READ_U16(data + 2); |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
808 |
if (packet_no != fsm->rx_expected_packet_no) { |
1921 | 809 |
EC_SLAVE_ERR(slave, "Received unexpected packet number.\n"); |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
810 |
ec_foe_set_rx_error(fsm, FOE_PACKETNO_ERROR); |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
811 |
return; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
812 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
813 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
814 |
rec_size -= EC_FOE_HEADER_SIZE; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
815 |
|
1336
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
816 |
if (fsm->rx_buffer_size >= fsm->rx_buffer_offset + rec_size) { |
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
817 |
memcpy(fsm->rx_buffer + fsm->rx_buffer_offset, |
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
818 |
data + EC_FOE_HEADER_SIZE, rec_size); |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
819 |
fsm->rx_buffer_offset += rec_size; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
820 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
821 |
|
1336
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
822 |
fsm->rx_last_packet = |
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
823 |
(rec_size + EC_MBOX_HEADER_SIZE + EC_FOE_HEADER_SIZE |
2502
906ef8b1c0ec
FoE datagram / fsm->datagram bugfix, thanks to R. Roesch.
Florian Pose <fp@igh-essen.com>
parents:
2501
diff
changeset
|
824 |
!= slave->configured_rx_mailbox_size); |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
825 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
826 |
if (fsm->rx_last_packet || |
1338
eb31b5a135da
merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents:
1337
diff
changeset
|
827 |
(slave->configured_rx_mailbox_size - EC_MBOX_HEADER_SIZE |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
828 |
- EC_FOE_HEADER_SIZE + fsm->rx_buffer_offset) |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
829 |
<= fsm->rx_buffer_size) { |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
830 |
// either it was the last packet or a new packet will fit into the |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
831 |
// delivered buffer |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
832 |
#ifdef DEBUG_FOE |
2527
f51f3ef3260d
Improved FoE debug messages.
Florian Pose <fp@igh-essen.com>
parents:
2522
diff
changeset
|
833 |
EC_SLAVE_DBG(fsm->slave, 0, "last_packet=true\n"); |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
834 |
#endif |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
835 |
if (ec_foe_prepare_send_ack(fsm, datagram)) { |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
836 |
ec_foe_set_rx_error(fsm, FOE_RX_DATA_ACK_ERROR); |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
837 |
return; |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
838 |
} |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
839 |
|
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
840 |
fsm->state = ec_fsm_foe_state_sent_ack; |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
841 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
842 |
else { |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
843 |
// no more data fits into the delivered buffer |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
844 |
// ... wait for new read request |
2527
f51f3ef3260d
Improved FoE debug messages.
Florian Pose <fp@igh-essen.com>
parents:
2522
diff
changeset
|
845 |
EC_SLAVE_ERR(slave, "Data do not fit in receive buffer!\n"); |
f51f3ef3260d
Improved FoE debug messages.
Florian Pose <fp@igh-essen.com>
parents:
2522
diff
changeset
|
846 |
printk(" rx_buffer_size = %d\n", fsm->rx_buffer_size); |
f51f3ef3260d
Improved FoE debug messages.
Florian Pose <fp@igh-essen.com>
parents:
2522
diff
changeset
|
847 |
printk("rx_buffer_offset = %d\n", fsm->rx_buffer_offset); |
f51f3ef3260d
Improved FoE debug messages.
Florian Pose <fp@igh-essen.com>
parents:
2522
diff
changeset
|
848 |
printk(" rec_size = %zd\n", rec_size); |
f51f3ef3260d
Improved FoE debug messages.
Florian Pose <fp@igh-essen.com>
parents:
2522
diff
changeset
|
849 |
printk(" rx_mailbox_size = %d\n", slave->configured_rx_mailbox_size); |
f51f3ef3260d
Improved FoE debug messages.
Florian Pose <fp@igh-essen.com>
parents:
2522
diff
changeset
|
850 |
printk(" rx_last_packet = %d\n", fsm->rx_last_packet); |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
851 |
fsm->request->result = FOE_READY; |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
852 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
853 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
854 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
855 |
/*****************************************************************************/ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
856 |
|
1465 | 857 |
/** Sent an acknowledge. |
858 |
*/ |
|
859 |
void ec_fsm_foe_state_sent_ack( |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
860 |
ec_fsm_foe_t *fsm, /**< FoE statemachine. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
861 |
ec_datagram_t *datagram /**< Datagram to use. */ |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
862 |
) |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
863 |
{ |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
864 |
ec_slave_t *slave = fsm->slave; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
865 |
|
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
866 |
#ifdef DEBUG_FOE |
2527
f51f3ef3260d
Improved FoE debug messages.
Florian Pose <fp@igh-essen.com>
parents:
2522
diff
changeset
|
867 |
EC_SLAVE_DBG(fsm->slave, 0, "%s()\n", __func__); |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
868 |
#endif |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
869 |
|
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
870 |
if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) { |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
871 |
ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR); |
1921 | 872 |
EC_SLAVE_ERR(slave, "Failed to send FoE ACK: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
873 |
ec_datagram_print_state(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
874 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
875 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
876 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
877 |
if (fsm->datagram->working_counter != 1) { |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
878 |
// slave did not put anything into the mailbox yet |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
879 |
ec_foe_set_rx_error(fsm, FOE_WC_ERROR); |
1921 | 880 |
EC_SLAVE_ERR(slave, "Reception of FoE ACK failed: "); |
2498
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
881 |
ec_datagram_print_wc_error(fsm->datagram); |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
882 |
return; |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
883 |
} |
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
884 |
|
9cdd7669dc0b
Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents:
2257
diff
changeset
|
885 |
fsm->jiffies_start = fsm->datagram->jiffies_sent; |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
886 |
|
2502
906ef8b1c0ec
FoE datagram / fsm->datagram bugfix, thanks to R. Roesch.
Florian Pose <fp@igh-essen.com>
parents:
2501
diff
changeset
|
887 |
ec_slave_mbox_prepare_check(slave, datagram); // can not fail. |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
888 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
889 |
if (fsm->rx_last_packet) { |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
890 |
fsm->rx_expected_packet_no = 0; |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
891 |
fsm->request->data_size = fsm->rx_buffer_offset; |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
892 |
fsm->state = ec_fsm_foe_end; |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
893 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
894 |
else { |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
895 |
fsm->rx_expected_packet_no++; |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
896 |
fsm->retries = EC_FSM_RETRIES; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
897 |
fsm->state = ec_fsm_foe_state_data_check; |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
898 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
899 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
900 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
901 |
/*****************************************************************************/ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
902 |
|
1465 | 903 |
/** Set an error code and go to the send error state. |
904 |
*/ |
|
905 |
void ec_foe_set_tx_error( |
|
906 |
ec_fsm_foe_t *fsm, /**< FoE statemachine. */ |
|
907 |
uint32_t errorcode /**< FoE error code. */ |
|
908 |
) |
|
1336
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
909 |
{ |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
910 |
fsm->request->result = errorcode; |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
911 |
fsm->state = ec_fsm_foe_error; |
1335
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
912 |
} |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
913 |
|
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
914 |
/*****************************************************************************/ |
09c6fce1ae45
merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
915 |
|
1465 | 916 |
/** Set an error code and go to the receive error state. |
917 |
*/ |
|
918 |
void ec_foe_set_rx_error( |
|
919 |
ec_fsm_foe_t *fsm, /**< FoE statemachine. */ |
|
920 |
uint32_t errorcode /**< FoE error code. */ |
|
921 |
) |
|
1336
e27b37e80a99
merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents:
1335
diff
changeset
|
922 |
{ |
1343
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
923 |
fsm->request->result = errorcode; |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
924 |
fsm->state = ec_fsm_foe_error; |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
925 |
} |
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
926 |
|
6628cd694cba
Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents:
1338
diff
changeset
|
927 |
/*****************************************************************************/ |