master/fsm_foe.c
author Florian Pose <fp@igh-essen.com>
Tue, 06 Jul 2010 17:40:20 +0200
changeset 1948 fa1c4fb0a8da
parent 1921 d9cf40facbc4
child 2045 ff2a13a4603c
child 2235 cd49c2c31dcb
permissions -rw-r--r--
Output correct errno when transferring SDOs via command-line interface.
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);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   291
        EC_SLAVE_ERR(slave, "Slave does not support FoE!\n");
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   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);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   320
        EC_SLAVE_ERR(slave, "Failed to receive FoE mailbox check datagram: ");
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
   321
        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
   322
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   323
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   324
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   325
    if (datagram->working_counter != 1) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   326
        // 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
   327
        ec_foe_set_rx_error(fsm, FOE_WC_ERROR);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   328
        EC_SLAVE_ERR(slave, "Reception of FoE mailbox check datagram"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   329
                " failed: ");
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   330
        ec_datagram_print_wc_error(datagram);
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   331
        return;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   332
    }
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   333
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   334
    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
   335
        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
   336
            (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
   337
        if (diff_ms >= EC_FSM_FOE_TIMEOUT) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   338
            ec_foe_set_tx_error(fsm, FOE_TIMEOUT_ERROR);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   339
            EC_SLAVE_ERR(slave, "Timeout while waiting for ack response.\n");
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   340
            return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   341
        }
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   342
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   343
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   344
        fsm->retries = EC_FSM_RETRIES;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   345
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   346
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   347
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   348
    // Fetch response
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   349
    ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail.
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   350
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   351
    fsm->retries = EC_FSM_RETRIES;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   352
    fsm->state = ec_fsm_foe_state_ack_read;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   353
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   354
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   355
/*****************************************************************************/
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   356
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   357
/** Acknowledge a read operation.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   358
 */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   359
void ec_fsm_foe_state_ack_read(
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   360
        ec_fsm_foe_t *fsm /**< FoE statemachine. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   361
        )
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   362
{
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   363
    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
   364
    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
   365
    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
   366
    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
   367
    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
   368
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   369
#ifdef DEBUG_FOE
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   370
    printk("ec_fsm_foe_ack_read()\n");
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   371
#endif
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   372
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   373
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   374
        ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   375
        EC_SLAVE_ERR(slave, "Failed to receive FoE ack response datagram: ");
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
   376
        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
   377
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   378
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   379
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   380
    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
   381
        ec_foe_set_rx_error(fsm, FOE_WC_ERROR);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   382
        EC_SLAVE_ERR(slave, "Reception of FoE ack response failed: ");
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   383
        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
   384
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   385
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   386
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   387
    if (!(data = ec_slave_mbox_fetch(fsm->slave, datagram,
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   388
                    &mbox_prot, &rec_size))) {
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   389
        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
   390
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   391
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   392
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   393
    if (mbox_prot != EC_MBOX_TYPE_FILEACCESS) { // FoE
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   394
        ec_foe_set_tx_error(fsm, FOE_MBOX_PROT_ERROR);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   395
        EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   396
                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
   397
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   398
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   399
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   400
    opCode = EC_READ_U8(data);
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   401
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   402
    if (opCode == EC_FOE_OPCODE_BUSY) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   403
        // 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
   404
        if (ec_foe_prepare_data_send(fsm)) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   405
            ec_foe_set_tx_error(fsm, FOE_PROT_ERROR);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   406
            EC_SLAVE_ERR(slave, "Slave is busy.\n");
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   407
            return;
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   408
        }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   409
        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
   410
        return;
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
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   413
    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
   414
        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
   415
        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
   416
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   417
        if (fsm->tx_last_packet) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   418
            fsm->state = ec_fsm_foe_end;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   419
            return;
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   420
        }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   421
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   422
        if (ec_foe_prepare_data_send(fsm)) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   423
            ec_foe_set_tx_error(fsm, FOE_PROT_ERROR);
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   424
            return;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   425
        }
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   426
        fsm->state = ec_fsm_foe_state_data_sent;
1343
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
    }
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   429
    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
   430
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   431
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   432
/*****************************************************************************/
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   433
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   434
/** State: WRQ SENT.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   435
 *
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   436
 * Checks is the previous transmit datagram succeded and sends the next
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   437
 * fragment, if necessary.
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
void ec_fsm_foe_state_wrq_sent(
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   440
        ec_fsm_foe_t *fsm /**< FoE statemachine. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   441
        )
1446
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   442
{
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   443
    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
   444
    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
   445
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   446
#ifdef DEBUG_FOE
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   447
    printk("ec_foe_state_sent_wrq()\n");
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   448
#endif
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   449
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   450
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   451
        ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   452
        EC_SLAVE_ERR(slave, "Failed to send FoE WRQ: ");
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
   453
        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
   454
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   455
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   456
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   457
    if (datagram->working_counter != 1) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   458
        // 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
   459
        ec_foe_set_rx_error(fsm, FOE_WC_ERROR);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   460
        EC_SLAVE_ERR(slave, "Reception of FoE WRQ failed: ");
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   461
        ec_datagram_print_wc_error(datagram);
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   462
        return;
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   463
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   464
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   465
    fsm->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
   466
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   467
    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
   468
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   469
    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
   470
    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
   471
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   472
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   473
/*****************************************************************************/
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   474
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   475
/** State: WRQ SENT.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   476
 *
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   477
 * Checks is the previous transmit datagram succeded and sends the next
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   478
 * fragment, if necessary.
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
void ec_fsm_foe_state_data_sent(
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   481
        ec_fsm_foe_t *fsm /**< Foe statemachine. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   482
        )
1446
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   483
{
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   484
    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
   485
    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
   486
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   487
#ifdef DEBUG_FOE
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   488
    printk("ec_fsm_foe_state_data_sent()\n");
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   489
#endif
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   490
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   491
    if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   492
        ec_foe_set_tx_error(fsm, FOE_RECEIVE_ERROR);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   493
        EC_SLAVE_ERR(slave, "Failed to receive FoE ack response datagram: ");
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
   494
        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
   495
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   496
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   497
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   498
    if (fsm->datagram->working_counter != 1) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   499
        ec_foe_set_tx_error(fsm, FOE_WC_ERROR);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   500
        EC_SLAVE_ERR(slave, "Reception of FoE data send failed: ");
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   501
        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
   502
        return;
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
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   505
    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
   506
    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
   507
    fsm->retries = EC_FSM_RETRIES;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   508
    fsm->state = ec_fsm_foe_state_ack_check;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   509
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   510
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   511
/*****************************************************************************/
1901
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   512
2a1106b1d863 Documented fsm_foe members and removed unused variables.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   513
/** 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
   514
 */
1446
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   515
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
   516
{
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   517
    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
   518
    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
   519
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   520
    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
   521
1446
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   522
    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
   523
            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
   524
    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
   525
        return -1;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   526
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   527
    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
   528
    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
   529
    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
   530
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   531
    if (fsm->slave->master->debug_level) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   532
        EC_SLAVE_DBG(fsm->slave, 1, "FoE Read Request:\n");
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   533
        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
   534
    }
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   535
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   536
    return 0;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   537
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   538
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   539
/*****************************************************************************/
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   540
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   541
/** Prepare to send an acknowledge.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   542
 */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   543
int ec_foe_prepare_send_ack(
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   544
        ec_fsm_foe_t *foe /**< FoE statemachine. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   545
        )
1446
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   546
{
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   547
    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
   548
1446
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   549
    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
   550
            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
   551
    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
   552
        return -1;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   553
1446
85ea5af50175 Fixed usage of IS_ERR() in FoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 1416
diff changeset
   554
    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
   555
    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
   556
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   557
    return 0;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   558
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   559
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   560
/*****************************************************************************/
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   561
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   562
/** State: RRQ SENT.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   563
 *
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   564
 * Checks is the previous transmit datagram succeded and sends the next
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   565
 * fragment, if necessary.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   566
 */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   567
void ec_fsm_foe_state_rrq_sent(
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   568
        ec_fsm_foe_t *fsm /**< FoE statemachine. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   569
        )
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   570
{
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   571
    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
   572
    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
   573
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   574
#ifdef DEBUG_FOE
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   575
    printk("ec_foe_state_rrq_sent()\n");
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   576
#endif
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
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
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   579
        ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   580
        EC_SLAVE_ERR(slave, "Failed to send FoE RRQ: ");
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
   581
        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
   582
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   583
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   584
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->working_counter != 1) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   586
        // 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
   587
        ec_foe_set_rx_error(fsm, FOE_WC_ERROR);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   588
        EC_SLAVE_ERR(slave, "Reception of FoE RRQ failed: ");
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   589
        ec_datagram_print_wc_error(datagram);
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   590
        return;
1335
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
    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
   594
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   595
    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
   596
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   597
    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
   598
    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
   599
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   600
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   601
/*****************************************************************************/
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   602
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   603
/** Start a read operation.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   604
 */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   605
void ec_fsm_foe_read(
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   606
        ec_fsm_foe_t *fsm /**< FoE state machine. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   607
        )
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   608
{
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   609
    fsm->state = ec_fsm_foe_read_start;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   610
    fsm->rx_filename = fsm->request->file_name;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   611
    fsm->rx_filename_len = strlen(fsm->rx_filename);
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   612
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   613
    fsm->rx_buffer = fsm->request->buffer;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   614
    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
   615
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   616
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   617
/*****************************************************************************/
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   618
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   619
/** Starting state for read operations.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   620
 */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   621
void ec_fsm_foe_read_start(
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   622
        ec_fsm_foe_t *fsm /**< FoE statemachine. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   623
        )
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   624
{
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   625
    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
   626
    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
   627
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   628
    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
   629
    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
   630
    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
   631
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   632
    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
   633
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   634
#ifdef DEBUG_FOE
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   635
    printk("ec_fsm_foe_read_start()\n");
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   636
#endif
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   637
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   638
    if (!(slave->sii.mailbox_protocols & EC_MBOX_FOE)) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   639
        ec_foe_set_tx_error(fsm, FOE_MBOX_PROT_ERROR);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   640
        EC_SLAVE_ERR(slave, "Slave does not support FoE!\n");
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   641
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   642
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   643
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   644
    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
   645
        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
   646
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   647
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   648
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   649
    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
   650
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   651
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   652
/*****************************************************************************/
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   653
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   654
/** Check for data.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   655
 */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   656
void ec_fsm_foe_state_data_check(
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   657
        ec_fsm_foe_t *fsm /**< FoE statemachine. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   658
        )
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   659
{
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   660
    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
   661
    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
   662
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   663
#ifdef DEBUG_FOE
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   664
    printk("ec_fsm_foe_state_data_check()\n");
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   665
#endif
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   666
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   667
    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
   668
        ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   669
        EC_SLAVE_ERR(slave, "Failed to send FoE DATA READ: ");
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
   670
        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
   671
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   672
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   673
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   674
    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
   675
        ec_foe_set_rx_error(fsm, FOE_WC_ERROR);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   676
        EC_SLAVE_ERR(slave, "Reception of FoE DATA READ: ");
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_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
   678
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   679
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   680
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   681
    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
   682
        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
   683
            (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
   684
        if (diff_ms >= EC_FSM_FOE_TIMEOUT) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   685
            ec_foe_set_tx_error(fsm, FOE_TIMEOUT_ERROR);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   686
            EC_SLAVE_ERR(slave, "Timeout while waiting for ack response.\n");
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   687
            return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   688
        }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   689
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   690
        ec_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
   691
        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
   692
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   693
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   694
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   695
    // Fetch response
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   696
    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
   697
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   698
    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
   699
    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
   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
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   703
/*****************************************************************************/
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   704
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   705
/** Start reading data.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   706
 */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   707
void ec_fsm_foe_state_data_read(
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   708
        ec_fsm_foe_t *fsm /**< FoE statemachine. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   709
        )
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   710
{
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   711
    size_t rec_size;
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   712
    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
   713
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   714
    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
   715
    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
   716
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   717
#ifdef DEBUG_FOE
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   718
    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
   719
#endif
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   720
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   721
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   722
        ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   723
        EC_SLAVE_ERR(slave, "Failed to receive FoE DATA READ datagram: ");
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
   724
        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
   725
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   726
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   727
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   728
    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
   729
        ec_foe_set_rx_error(fsm, FOE_WC_ERROR);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   730
        EC_SLAVE_ERR(slave, "Reception of FoE DATA READ failed: ");
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   731
        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
   732
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   733
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   734
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   735
    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
   736
        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
   737
        return;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   738
    }
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   739
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   740
    if (mbox_prot != EC_MBOX_TYPE_FILEACCESS) { // FoE
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   741
        EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   742
                mbox_prot);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   743
        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
   744
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   745
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   746
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   747
    opCode = EC_READ_U8(data);
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   748
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   749
    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
   750
        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
   751
            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
   752
        }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   753
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   754
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   755
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   756
    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
   757
        fsm->request->error_code = EC_READ_U32(data + 2);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   758
        EC_SLAVE_ERR(slave, "Received FoE Error Request (code 0x%08x).\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   759
                fsm->request->error_code);
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   760
        if (rec_size > 6) {
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   761
            uint8_t text[1024];
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   762
            strncpy(text, data + 6, min(rec_size - 6, sizeof(text)));
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   763
            EC_SLAVE_ERR(slave, "FoE Error Text: %s\n", text);
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   764
        }
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   765
        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
   766
        return;
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   767
    }
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   768
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_DATA) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   770
        EC_SLAVE_ERR(slave, "Received OPCODE %x, expected %x.\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   771
                opCode, EC_FOE_OPCODE_DATA);
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   772
        fsm->request->error_code = 0x00000000;
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   773
        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
   774
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   775
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   776
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   777
    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
   778
    if (packet_no != fsm->rx_expected_packet_no) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   779
        EC_SLAVE_ERR(slave, "Received unexpected packet number.\n");
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   780
        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
   781
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   782
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   783
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   784
    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
   785
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   786
    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
   787
        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
   788
                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
   789
        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
   790
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   791
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   792
    fsm->rx_last_packet =
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   793
        (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
   794
         != 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
   795
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   796
    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
   797
            (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
   798
             - EC_FOE_HEADER_SIZE + fsm->rx_buffer_offset)
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   799
            <= fsm->rx_buffer_size) {
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   800
        // 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
   801
        // delivered buffer
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   802
#ifdef DEBUG_FOE
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   803
        printk ("last_packet=true\n");
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   804
#endif
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   805
        if (ec_foe_prepare_send_ack(fsm)) {
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   806
            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
   807
            return;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   808
        }
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   809
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   810
        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
   811
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   812
    else {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   813
        // no more data fits into the delivered buffer
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   814
        // ... wait for new read request
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   815
        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
   816
        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
   817
        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
   818
        printk ("       rec_size        = %zd\n", rec_size);
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   819
        printk ("       rx_mailbox_size = %d\n",
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   820
                slave->configured_rx_mailbox_size);
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   821
        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
   822
        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
   823
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   824
}
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
/*****************************************************************************/
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   827
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   828
/** Sent an acknowledge.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   829
 */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   830
void ec_fsm_foe_state_sent_ack(
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   831
        ec_fsm_foe_t *fsm /**< FoE statemachine. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   832
        )
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   833
{
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   834
    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
   835
    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
   836
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   837
#ifdef DEBUG_FOE
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   838
    printk("ec_foe_state_sent_ack()\n");
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   839
#endif
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   840
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   841
    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
   842
        ec_foe_set_rx_error(fsm, FOE_RECEIVE_ERROR);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   843
        EC_SLAVE_ERR(slave, "Failed to send FoE ACK: ");
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
   844
        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
   845
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   846
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   847
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   848
    if (datagram->working_counter != 1) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   849
        // 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
   850
        ec_foe_set_rx_error(fsm, FOE_WC_ERROR);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1901
diff changeset
   851
        EC_SLAVE_ERR(slave, "Reception of FoE ACK failed: ");
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   852
        ec_datagram_print_wc_error(datagram);
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   853
        return;
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   854
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   855
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   856
    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
   857
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   858
    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
   859
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   860
    if (fsm->rx_last_packet) {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   861
        fsm->rx_expected_packet_no = 0;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   862
        fsm->request->data_size = fsm->rx_buffer_offset;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   863
        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
   864
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   865
    else {
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   866
        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
   867
        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
   868
        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
   869
    }
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
/*****************************************************************************/
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   873
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   874
/** Set an error code and go to the send error state.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   875
 */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   876
void ec_foe_set_tx_error(
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   877
        ec_fsm_foe_t *fsm, /**< FoE statemachine. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   878
        uint32_t errorcode /**< FoE error code. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   879
        )
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   880
{
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   881
    fsm->request->result = errorcode;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   882
    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
   883
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   884
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
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   887
/** Set an error code and go to the receive error state.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   888
 */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   889
void ec_foe_set_rx_error(
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   890
        ec_fsm_foe_t *fsm, /**< FoE statemachine. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   891
        uint32_t errorcode /**< FoE error code. */
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1446
diff changeset
   892
        )
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   893
{
1343
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   894
    fsm->request->result = errorcode;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   895
    fsm->state = ec_fsm_foe_error;
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   896
}
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   897
6628cd694cba Fixed spacing and comments.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   898
/*****************************************************************************/