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