master/fsm_foe.c
author Florian Pose <fp@igh-essen.com>
Tue, 20 Apr 2010 11:21:43 +0200
changeset 1908 666ad3a50f9f
parent 1901 2a1106b1d863
child 1921 d9cf40facbc4
permissions -rw-r--r--
Removed TIOCSSERIAL because it doesn't make sense for virtual tty interfaces.
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
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
    49
/** Mailbox type FoE.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
    50
 */
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
#define EC_MBOX_TYPE_FILEACCESS 0x04
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
    53
/** Size of the FoE header.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
    54
 */
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    55
#define EC_FOE_HEADER_SIZE 6
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    56
// uint8_t  OpCode
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    57
// uint8_t  reserved
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    58
// uint32_t PacketNo, Password, ErrorCode
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    59
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    60
//#define DEBUG_FOE
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    61
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    62
/*****************************************************************************/
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    63
1416
85d20ae6736e Added missing doc.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    64
/** FoE OpCodes.
85d20ae6736e Added missing doc.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    65
 */
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    66
enum {
1416
85d20ae6736e Added missing doc.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    67
    EC_FOE_OPCODE_RRQ  = 1, /**< Read request. */
85d20ae6736e Added missing doc.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    68
    EC_FOE_OPCODE_WRQ  = 2, /**< Write request. */
85d20ae6736e Added missing doc.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    69
    EC_FOE_OPCODE_DATA = 3, /**< Data. */
85d20ae6736e Added missing doc.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    70
    EC_FOE_OPCODE_ACK  = 4, /**< Acknowledge. */
85d20ae6736e Added missing doc.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    71
    EC_FOE_OPCODE_ERR  = 5, /**< Error. */
85d20ae6736e Added missing doc.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    72
    EC_FOE_OPCODE_BUSY = 6  /**< Busy. */
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    73
} ec_foe_opcode_t;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    74
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    75
/*****************************************************************************/
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    76
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    77
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
    78
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
    79
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
    80
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
    81
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    82
void ec_foe_set_tx_error(ec_fsm_foe_t *, uint32_t);
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    83
void ec_foe_set_rx_error(ec_fsm_foe_t *, uint32_t);
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    84
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    85
void ec_fsm_foe_write(ec_fsm_foe_t *);
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    86
void ec_fsm_foe_read(ec_fsm_foe_t *);
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    87
void ec_fsm_foe_end(ec_fsm_foe_t *);
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    88
void ec_fsm_foe_error(ec_fsm_foe_t *);
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    89
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    90
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
    91
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
    92
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    93
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
    94
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
    95
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    96
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
    97
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    98
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
    99
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
   100
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
   101
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   102
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
   103
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
   104
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
1901
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   107
/** Constructor.
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   108
 */
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
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
   110
                     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
   111
                     )
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
{
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
    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
   114
    fsm->datagram  = datagram;
1901
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   115
}
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   116
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   117
/*****************************************************************************/
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   118
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   119
/** Destructor.
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   120
 */
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
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
   122
{
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
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
1901
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   127
/** Executes the current state of the state machine.
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   128
 * \return false, if state machine has terminated
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   129
 */
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
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
   131
{
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
    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
   133
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
    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
   135
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
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
1901
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   139
/** Returns, if the state machine terminated with success.
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   140
 * \return non-zero if successful.
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   141
 */
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
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
   143
{
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
    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
   145
}
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
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   149
/** Prepares an FoE transfer.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   150
 */
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
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
   152
        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
   153
        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
   154
        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
   155
        )
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
{
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
    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
   158
    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
   159
    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
   160
        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
   161
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
    else {
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
        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
   164
    }
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
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
/*****************************************************************************/
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
1901
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   169
/** State: ERROR.
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   170
 */
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
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
   172
{
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   173
#ifdef DEBUG_FOE
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   174
    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
   175
#endif
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
/*****************************************************************************/
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
1901
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   180
/** State: END.
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   181
 */
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
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
   183
{
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   184
#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
   185
    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
   186
#endif
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
}
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
/*****************************************************************************/
1901
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   190
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   191
/** Sends a file or the next fragment.
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   192
 */
1446
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   193
int ec_foe_prepare_data_send(ec_fsm_foe_t *fsm)
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   194
{
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   195
    size_t remaining_size, current_size;
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   196
    uint8_t *data;
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
    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
   199
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
   200
    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
   201
            - 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
   202
        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
   203
        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
   204
    } 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
   205
        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
   206
            - 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
   207
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
1446
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   209
    data = ec_slave_mbox_prepare_send(fsm->slave,
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   210
            fsm->datagram, EC_MBOX_TYPE_FILEACCESS,
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   211
            current_size + EC_FOE_HEADER_SIZE);
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   212
    if (IS_ERR(data))
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
        return -1;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   214
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   215
    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
   216
    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
   217
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   218
    memcpy(data + EC_FOE_HEADER_SIZE,
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   219
            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
   220
    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
   221
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   222
    return 0;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
/*****************************************************************************/
1901
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   226
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   227
/** Prepare a write request (WRQ) with filename
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   228
 */
1446
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   229
int ec_foe_prepare_wrq_send(ec_fsm_foe_t *fsm)
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   230
{
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   231
    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
   232
    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
   233
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
    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
   235
    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
   236
    fsm->tx_packet_no = 0;
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   237
    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
   238
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   239
    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
   240
1446
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   241
    data = ec_slave_mbox_prepare_send(fsm->slave, fsm->datagram,
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   242
            EC_MBOX_TYPE_FILEACCESS, current_size + EC_FOE_HEADER_SIZE);
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   243
    if (IS_ERR(data))
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   244
        return -1;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   245
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   246
    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
   247
    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
   248
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   249
    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
   250
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   251
    return 0;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   252
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   253
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   254
/*****************************************************************************/
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   255
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   256
/** Start a write operation.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   257
 */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   258
void ec_fsm_foe_write(
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   259
        ec_fsm_foe_t *fsm /**< FoE statemachine. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   260
        )
1335
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
    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
   263
    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
   264
    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
   265
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   266
    fsm->tx_filename = fsm->request->file_name;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   267
    fsm->tx_filename_len = strlen(fsm->tx_filename);
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   268
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   269
    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
   270
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   271
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   272
/*****************************************************************************/
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   273
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   274
/** Initializes the FoE write state machine.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   275
 */
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   276
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
   277
{
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   278
    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
   279
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   280
    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
   281
    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
   282
    fsm->tx_packet_no = 0;
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   283
    fsm->tx_last_packet = 0;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   284
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   285
#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
   286
    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
   287
#endif
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   288
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   289
    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
   290
        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
   291
        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
   292
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   293
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   294
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   295
    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
   296
        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
   297
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   298
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   299
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   300
    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
   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
/*****************************************************************************/
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   304
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   305
/** Check for acknowledge.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   306
 */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   307
void ec_fsm_foe_state_ack_check(
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   308
        ec_fsm_foe_t *fsm /**< FoE statemachine. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   309
        )
1446
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   310
{
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   311
    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
   312
    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
   313
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   314
#ifdef DEBUG_FOE
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   315
    printk("ec_fsm_foe_ack_check()\n");
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   316
#endif
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   317
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   318
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   319
        ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR);
1822
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   320
        EC_ERR("Failed to receive FoE mailbox check datagram for slave %u: ",
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   321
               slave->ring_position);
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   322
        ec_datagram_print_state(datagram);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   323
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   324
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   325
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   326
    if (datagram->working_counter != 1) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   327
        // 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
   328
        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
   329
        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
   330
               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
   331
        ec_datagram_print_wc_error(datagram);
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   332
        return;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   333
    }
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   334
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   335
    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
   336
        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
   337
            (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
   338
        if (diff_ms >= EC_FSM_FOE_TIMEOUT) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   339
            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
   340
            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
   341
                    "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
   342
            return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   343
        }
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   344
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   345
        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
   346
        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
   347
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   348
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   349
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   350
    // Fetch response
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   351
    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
   352
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   353
    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
   354
    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
   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
/*****************************************************************************/
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   358
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   359
/** Acknowledge a read operation.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   360
 */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   361
void ec_fsm_foe_state_ack_read(
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   362
        ec_fsm_foe_t *fsm /**< FoE statemachine. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   363
        )
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   364
{
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   365
    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
   366
    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
   367
    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
   368
    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
   369
    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
   370
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   371
#ifdef DEBUG_FOE
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   372
    printk("ec_fsm_foe_ack_read()\n");
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   373
#endif
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   374
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   375
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   376
        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
   377
        EC_ERR("Failed to receive FoE ack response datagram for"
1822
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   378
               " slave %u: ", slave->ring_position);
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   379
        ec_datagram_print_state(datagram);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   380
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   381
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   382
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   383
    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
   384
        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
   385
        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
   386
                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
   387
        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
   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
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   391
    if (!(data = ec_slave_mbox_fetch(fsm->slave, datagram,
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   392
                    &mbox_prot, &rec_size))) {
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   393
        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
   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
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   397
    if (mbox_prot != EC_MBOX_TYPE_FILEACCESS) { // FoE
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   398
        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
   399
        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
   400
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   401
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   402
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   403
    opCode = EC_READ_U8(data);
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   404
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   405
    if (opCode == EC_FOE_OPCODE_BUSY) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   406
        // 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
   407
        if (ec_foe_prepare_data_send(fsm)) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   408
            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
   409
            EC_ERR("Slave is busy.\n");
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   410
            return;
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   411
        }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   412
        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
   413
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   414
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   415
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   416
    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
   417
        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
   418
        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
   419
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   420
        if (fsm->tx_last_packet) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   421
            fsm->state = ec_fsm_foe_end;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   422
            return;
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   423
        }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   424
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   425
        if (ec_foe_prepare_data_send(fsm)) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   426
            ec_foe_set_tx_error(fsm, FOE_PROT_ERROR);
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   427
            return;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   428
        }
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   429
        fsm->state = ec_fsm_foe_state_data_sent;
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   430
        return;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   431
    }
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   432
    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
   433
}
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
/*****************************************************************************/
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   436
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   437
/** State: WRQ SENT.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   438
 *
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   439
 * Checks is the previous transmit datagram succeded and sends the next
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   440
 * fragment, if necessary.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   441
 */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   442
void ec_fsm_foe_state_wrq_sent(
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   443
        ec_fsm_foe_t *fsm /**< FoE statemachine. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   444
        )
1446
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   445
{
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_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
   447
    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
   448
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   449
#ifdef DEBUG_FOE
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   450
    printk("ec_foe_state_sent_wrq()\n");
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   451
#endif
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   452
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   453
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   454
        ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR);
1822
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   455
        EC_ERR("Failed to send FoE WRQ for slave %u: ",
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   456
                slave->ring_position);
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   457
        ec_datagram_print_state(datagram);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   458
        return;
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
    if (datagram->working_counter != 1) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   462
        // 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
   463
        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
   464
        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
   465
                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
   466
        ec_datagram_print_wc_error(datagram);
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   467
        return;
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   468
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   469
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   470
    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
   471
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   472
    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
   473
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   474
    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
   475
    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
   476
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   477
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   478
/*****************************************************************************/
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   479
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   480
/** State: WRQ SENT.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   481
 *
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   482
 * Checks is the previous transmit datagram succeded and sends the next
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   483
 * fragment, if necessary.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   484
 */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   485
void ec_fsm_foe_state_data_sent(
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   486
        ec_fsm_foe_t *fsm /**< Foe statemachine. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   487
        )
1446
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   488
{
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   489
    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
   490
    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
   491
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   492
#ifdef DEBUG_FOE
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   493
    printk("ec_fsm_foe_state_data_sent()\n");
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   494
#endif
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   495
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   496
    if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   497
        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
   498
        EC_ERR("Failed to receive FoE ack response datagram for"
1822
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   499
               " slave %u: ", slave->ring_position);
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   500
        ec_datagram_print_state(datagram);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   501
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   502
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   503
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   504
    if (fsm->datagram->working_counter != 1) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   505
        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
   506
        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
   507
                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
   508
        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
   509
        return;
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
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   512
    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
   513
    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
   514
    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
   515
    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
   516
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   517
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   518
/*****************************************************************************/
1901
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   519
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   520
/** Prepare a read request (RRQ) with filename
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   521
 */
1446
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   522
int ec_foe_prepare_rrq_send(ec_fsm_foe_t *fsm)
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   523
{
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   524
    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
   525
    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
   526
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   527
    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
   528
1446
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   529
    data = ec_slave_mbox_prepare_send(fsm->slave, fsm->datagram,
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   530
            EC_MBOX_TYPE_FILEACCESS, current_size + EC_FOE_HEADER_SIZE);
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   531
    if (IS_ERR(data))
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   532
        return -1;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   533
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   534
    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
   535
    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
   536
    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
   537
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   538
    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
   539
        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
   540
        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
   541
    }
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   542
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   543
    return 0;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   544
}
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
/*****************************************************************************/
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   547
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   548
/** Prepare to send an acknowledge.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   549
 */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   550
int ec_foe_prepare_send_ack(
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   551
        ec_fsm_foe_t *foe /**< FoE statemachine. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   552
        )
1446
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   553
{
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   554
    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
   555
1446
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   556
    data = ec_slave_mbox_prepare_send(foe->slave, foe->datagram,
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   557
            EC_MBOX_TYPE_FILEACCESS, EC_FOE_HEADER_SIZE);
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   558
    if (IS_ERR(data))
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   559
        return -1;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   560
1446
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   561
    EC_WRITE_U16(data, EC_FOE_OPCODE_ACK);
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   562
    EC_WRITE_U32(data + 2, foe->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
   563
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   564
    return 0;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   565
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   566
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   567
/*****************************************************************************/
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   568
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   569
/** State: RRQ SENT.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   570
 *
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   571
 * Checks is the previous transmit datagram succeded and sends the next
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   572
 * fragment, if necessary.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   573
 */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   574
void ec_fsm_foe_state_rrq_sent(
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   575
        ec_fsm_foe_t *fsm /**< FoE statemachine. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   576
        )
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   577
{
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   578
    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
   579
    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
   580
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   581
#ifdef DEBUG_FOE
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   582
    printk("ec_foe_state_rrq_sent()\n");
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   583
#endif
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   584
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   585
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   586
        ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR);
1822
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   587
        EC_ERR("Failed to send FoE RRQ for slave %u" ": ",
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   588
                slave->ring_position);
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   589
        ec_datagram_print_state(datagram);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   590
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   591
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   592
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   593
    if (datagram->working_counter != 1) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   594
        // 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
   595
        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
   596
        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
   597
                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
   598
        ec_datagram_print_wc_error(datagram);
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   599
        return;
1335
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
    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
   603
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   604
    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
   605
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   606
    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
   607
    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
   608
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   609
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   610
/*****************************************************************************/
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   611
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   612
/** Start a read operation.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   613
 */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   614
void ec_fsm_foe_read(
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   615
        ec_fsm_foe_t *fsm /**< FoE state machine. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   616
        )
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   617
{
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   618
    fsm->state = ec_fsm_foe_read_start;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   619
    fsm->rx_filename = fsm->request->file_name;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   620
    fsm->rx_filename_len = strlen(fsm->rx_filename);
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   621
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   622
    fsm->rx_buffer = fsm->request->buffer;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   623
    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
   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
/*****************************************************************************/
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   627
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   628
/** Starting state for read operations.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   629
 */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   630
void ec_fsm_foe_read_start(
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   631
        ec_fsm_foe_t *fsm /**< FoE statemachine. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   632
        )
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   633
{
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   634
    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
   635
    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
   636
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   637
    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
   638
    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
   639
    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
   640
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   641
    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
   642
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   643
#ifdef DEBUG_FOE
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   644
    printk("ec_fsm_foe_read_start()\n");
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   645
#endif
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   646
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   647
    if (!(slave->sii.mailbox_protocols & EC_MBOX_FOE)) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   648
        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
   649
        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
   650
        return;
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
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   653
    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
   654
        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
   655
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   656
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   657
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   658
    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
   659
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   660
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   661
/*****************************************************************************/
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   662
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   663
/** Check for data.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   664
 */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   665
void ec_fsm_foe_state_data_check(
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   666
        ec_fsm_foe_t *fsm /**< FoE statemachine. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   667
        )
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   668
{
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   669
    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
   670
    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
   671
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   672
#ifdef DEBUG_FOE
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   673
    printk("ec_fsm_foe_state_data_check()\n");
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   674
#endif
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   675
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   676
    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
   677
        ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR);
1822
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   678
        EC_ERR("Failed to send FoE DATA READ for slave %u: ",
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   679
                slave->ring_position);
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   680
        ec_datagram_print_state(datagram);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   681
        return;
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
    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
   685
        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
   686
        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
   687
                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
   688
        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
   689
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   690
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   691
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   692
    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
   693
        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
   694
            (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
   695
        if (diff_ms >= EC_FSM_FOE_TIMEOUT) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   696
            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
   697
            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
   698
                    "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
   699
            return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   700
        }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   701
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   702
        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
   703
        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
   704
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   705
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   706
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   707
    // Fetch response
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   708
    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
   709
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   710
    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
   711
    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
   712
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   713
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   714
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   715
/*****************************************************************************/
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   716
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   717
/** Start reading data.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   718
 */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   719
void ec_fsm_foe_state_data_read(
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   720
        ec_fsm_foe_t *fsm /**< FoE statemachine. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   721
        )
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   722
{
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   723
    size_t rec_size;
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   724
    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
   725
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   726
    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
   727
    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
   728
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   729
#ifdef DEBUG_FOE
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   730
    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
   731
#endif
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   732
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   733
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   734
        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
   735
        EC_ERR("Failed to receive FoE DATA READ datagram for"
1822
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   736
               " slave %u: ", slave->ring_position);
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   737
        ec_datagram_print_state(datagram);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   738
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   739
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   740
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   741
    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
   742
        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
   743
        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
   744
                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
   745
        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
   746
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   747
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   748
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   749
    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
   750
        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
   751
        return;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   752
    }
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   753
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   754
    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
   755
        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
   756
        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
   757
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   758
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   759
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   760
    opCode = EC_READ_U8(data);
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   761
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   762
    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
   763
        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
   764
            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
   765
        }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   766
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   767
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   768
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   769
    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
   770
        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
   771
        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
   772
                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
   773
        if (rec_size > 6) {
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   774
            uint8_t text[1024];
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   775
            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
   776
            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
   777
        }
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   778
        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
   779
        return;
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   780
    }
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   781
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   782
    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
   783
        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
   784
                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
   785
        fsm->request->error_code = 0x00000000;
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   786
        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
   787
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   788
    }
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
    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
   791
    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
   792
        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
   793
                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
   794
        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
   795
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   796
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   797
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   798
    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
   799
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   800
    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
   801
        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
   802
                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
   803
        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
   804
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   805
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   806
    fsm->rx_last_packet =
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   807
        (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
   808
         != 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
   809
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   810
    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
   811
            (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
   812
             - EC_FOE_HEADER_SIZE + fsm->rx_buffer_offset)
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   813
            <= fsm->rx_buffer_size) {
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   814
        // 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
   815
        // delivered buffer
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   816
#ifdef DEBUG_FOE
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   817
        printk ("last_packet=true\n");
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   818
#endif
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   819
        if (ec_foe_prepare_send_ack(fsm)) {
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   820
            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
   821
            return;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   822
        }
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   823
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   824
        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
   825
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   826
    else {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   827
        // no more data fits into the delivered buffer
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   828
        // ... wait for new read request
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   829
        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
   830
        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
   831
        printk ("       rx_buffer_offset= %d\n", fsm->rx_buffer_offset);
1543
373cd456dc26 Avoid warnings on x86_64 platform. Thanks to Thomas Elste.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
   832
        printk ("       rec_size        = %zd\n", rec_size);
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   833
        printk ("       rx_mailbox_size = %d\n",
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   834
                slave->configured_rx_mailbox_size);
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   835
        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
   836
        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
   837
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   838
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   839
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
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   842
/** Sent an acknowledge.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   843
 */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   844
void ec_fsm_foe_state_sent_ack(
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   845
        ec_fsm_foe_t *fsm /**< FoE statemachine. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   846
        )
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   847
{
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   848
    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
   849
    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
   850
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   851
#ifdef DEBUG_FOE
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   852
    printk("ec_foe_state_sent_ack()\n");
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   853
#endif
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   854
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   855
    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
   856
        ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR);
1822
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   857
        EC_ERR("Failed to send FoE ACK for slave %u: ",
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   858
                slave->ring_position);
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1543
diff changeset
   859
        ec_datagram_print_state(datagram);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   860
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   861
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   862
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   863
    if (datagram->working_counter != 1) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   864
        // 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
   865
        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
   866
        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
   867
                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
   868
        ec_datagram_print_wc_error(datagram);
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   869
        return;
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   870
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   871
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   872
    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
   873
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   874
    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
   875
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   876
    if (fsm->rx_last_packet) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   877
        fsm->rx_expected_packet_no = 0;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   878
        fsm->request->data_size = fsm->rx_buffer_offset;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   879
        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
   880
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   881
    else {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   882
        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
   883
        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
   884
        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
   885
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   886
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   887
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   888
/*****************************************************************************/
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   889
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   890
/** Set an error code and go to the send error state.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   891
 */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   892
void ec_foe_set_tx_error(
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   893
        ec_fsm_foe_t *fsm, /**< FoE statemachine. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   894
        uint32_t errorcode /**< FoE error code. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   895
        )
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   896
{
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   897
    fsm->request->result = errorcode;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   898
    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
   899
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   900
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   901
/*****************************************************************************/
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   902
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   903
/** Set an error code and go to the receive error state.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   904
 */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   905
void ec_foe_set_rx_error(
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   906
        ec_fsm_foe_t *fsm, /**< FoE statemachine. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   907
        uint32_t errorcode /**< FoE error code. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   908
        )
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   909
{
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   910
    fsm->request->result = errorcode;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   911
    fsm->state = ec_fsm_foe_error;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   912
}
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   913
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   914
/*****************************************************************************/