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