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