master/fsm_eoe.c
author "Dave Page <dave.page@gleeble.com>"
Wed, 22 Jan 2014 13:01:45 +1300
changeset 2604 8476f196755b
parent 2597 0e145bb05859
child 2642 9dc0b2262f90
permissions -rw-r--r--
[etherlab-dev] [PATCH] FoE: fix read packet number check
2597
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006-2014  Florian Pose, Ingenieurgemeinschaft IgH
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  published by the Free Software Foundation.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  Public License for more details.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *  ---
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *****************************************************************************/
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
/**
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
   \file
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
   EtherCAT EoE state machines.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
*/
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
/*****************************************************************************/
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#include "globals.h"
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
#include "master.h"
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
#include "mailbox.h"
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#include "fsm_eoe.h"
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
/*****************************************************************************/
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
/** Maximum time to wait for a set IP parameter response.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
 */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
#define EC_EOE_RESPONSE_TIMEOUT 3000 // [ms]
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
/*****************************************************************************/
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
void ec_fsm_eoe_set_ip_start(ec_fsm_eoe_t *, ec_datagram_t *);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
void ec_fsm_eoe_set_ip_request(ec_fsm_eoe_t *, ec_datagram_t *);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
void ec_fsm_eoe_set_ip_check(ec_fsm_eoe_t *, ec_datagram_t *);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
void ec_fsm_eoe_set_ip_response(ec_fsm_eoe_t *, ec_datagram_t *);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
void ec_fsm_eoe_end(ec_fsm_eoe_t *, ec_datagram_t *);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
void ec_fsm_eoe_error(ec_fsm_eoe_t *, ec_datagram_t *);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
/*****************************************************************************/
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
/** Constructor.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
 */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
void ec_fsm_eoe_init(
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
        ec_fsm_eoe_t *fsm /**< finite state machine */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
        )
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
{
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
    fsm->slave = NULL;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
    fsm->retries = 0;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
    fsm->state = NULL;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
    fsm->datagram = NULL;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
    fsm->jiffies_start = 0;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
    fsm->request = NULL;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
}
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
/*****************************************************************************/
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
/** Destructor.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
 */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
void ec_fsm_eoe_clear(
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
        ec_fsm_eoe_t *fsm /**< finite state machine */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
        )
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
{
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
}
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
/*****************************************************************************/
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
/** Starts to set the EoE IP partameters of a slave.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
 */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
void ec_fsm_eoe_set_ip_param(
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
        ec_fsm_eoe_t *fsm, /**< State machine. */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
        ec_slave_t *slave, /**< EtherCAT slave. */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
        ec_eoe_request_t *request /**< EoE request. */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
        )
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
{
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
    fsm->slave = slave;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
    fsm->request = request;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
    fsm->state = ec_fsm_eoe_set_ip_start;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
}
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
/*****************************************************************************/
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
/** Executes the current state of the state machine.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
 *
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
 * \return 1 if the datagram was used, else 0.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
 */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
int ec_fsm_eoe_exec(
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
        ec_fsm_eoe_t *fsm, /**< finite state machine */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
        ec_datagram_t *datagram /**< Datagram to use. */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
        )
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
{
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
    int datagram_used = 0;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
    if (fsm->datagram &&
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
            (fsm->datagram->state == EC_DATAGRAM_INIT ||
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
             fsm->datagram->state == EC_DATAGRAM_QUEUED ||
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
             fsm->datagram->state == EC_DATAGRAM_SENT)) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
        // datagram not received yet
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
        return datagram_used;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
    fsm->state(fsm, datagram);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
    datagram_used =
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
        fsm->state != ec_fsm_eoe_end && fsm->state != ec_fsm_eoe_error;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
    if (datagram_used) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
        fsm->datagram = datagram;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
    } else {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
        fsm->datagram = NULL;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
    return datagram_used;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
}
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
/*****************************************************************************/
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
/** Returns, if the state machine terminated with success.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
 *
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
 * \return non-zero if successful.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
 */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
int ec_fsm_eoe_success(const ec_fsm_eoe_t *fsm /**< Finite state machine */)
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
{
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
    return fsm->state == ec_fsm_eoe_end;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
}
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
/******************************************************************************
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
 * EoE set IP parameter state machine
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
 *****************************************************************************/
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
/** Prepare a set IP parameters operation.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
 *
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
 * \return 0 on success, otherwise a negative error code.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
 */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
int ec_fsm_eoe_prepare_set(
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
        ec_fsm_eoe_t *fsm, /**< finite state machine */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
        ec_datagram_t *datagram /**< Datagram to use. */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
        )
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
{
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
    uint8_t *data, *cur;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
    ec_slave_t *slave = fsm->slave;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
    ec_master_t *master = slave->master;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
    ec_eoe_request_t *req = fsm->request;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
    size_t size = 8;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
    if (req->mac_address_included) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
        size += ETH_ALEN;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
    if (req->ip_address_included) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
        size += 4;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
    if (req->subnet_mask_included) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
        size += 4;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
    if (req->gateway_included) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
        size += 4;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
    if (req->dns_included) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
        size += 4;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
    if (req->name_included) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
        size += EC_MAX_HOSTNAME_SIZE;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
    data = ec_slave_mbox_prepare_send(slave, datagram, EC_MBOX_TYPE_EOE,
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
            size);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
    if (IS_ERR(data)) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
        return PTR_ERR(data);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
    EC_WRITE_U8(data, EC_EOE_FRAMETYPE_SET_IP_REQ); // Set IP parameter req.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
    EC_WRITE_U8(data + 1, 0x01); // last fragment, no timestamps
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
    EC_WRITE_U16(data + 2, 0x0000); // fragment no., offset, frame no.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
    EC_WRITE_U32(data + 4,
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
            ((req->mac_address_included != 0) << 0) |
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
            ((req->ip_address_included != 0) << 1) |
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
            ((req->subnet_mask_included != 0) << 2) |
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
            ((req->gateway_included != 0) << 3) |
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
            ((req->dns_included != 0) << 4) |
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
            ((req->name_included != 0) << 5)
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
            );
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
    cur = data + 8;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
    if (req->mac_address_included) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
        memcpy(cur, req->mac_address, ETH_ALEN);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
        cur += ETH_ALEN;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   212
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   214
    if (req->ip_address_included) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   215
        memcpy(cur, &req->ip_address, 4);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
        cur += 4;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   217
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   218
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   219
    if (req->subnet_mask_included) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
        memcpy(cur, &req->subnet_mask, 4);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   221
        cur += 4;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   222
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
    if (req->gateway_included) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
        memcpy(cur, &req->gateway, 4);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
        cur += 4;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   229
    if (req->dns_included) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
        memcpy(cur, &req->dns, 4);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   231
        cur += 4;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   232
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   233
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
    if (req->name_included) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
        memcpy(cur, req->name, EC_MAX_HOSTNAME_SIZE);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
        cur += EC_MAX_HOSTNAME_SIZE;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   239
    if (master->debug_level) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   240
        EC_SLAVE_DBG(slave, 0, "Set IP parameter request:\n");
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   241
        ec_print_data(data, cur - data);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   242
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   243
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   244
    fsm->request->jiffies_sent = jiffies;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   245
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   246
    return 0;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   247
}
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   248
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   249
/*****************************************************************************/
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   250
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   251
/** EoE state: SET IP START.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   252
 */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   253
void ec_fsm_eoe_set_ip_start(
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   254
        ec_fsm_eoe_t *fsm, /**< finite state machine */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   255
        ec_datagram_t *datagram /**< Datagram to use. */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   256
        )
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
{
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   258
    ec_slave_t *slave = fsm->slave;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   259
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   260
    EC_SLAVE_DBG(slave, 1, "Setting IP parameters.\n");
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   261
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   262
    if (!(slave->sii.mailbox_protocols & EC_MBOX_EOE)) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   263
        EC_SLAVE_ERR(slave, "Slave does not support EoE!\n");
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   264
        fsm->state = ec_fsm_eoe_error;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   265
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   266
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   267
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   268
    if (ec_fsm_eoe_prepare_set(fsm, datagram)) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   269
        fsm->state = ec_fsm_eoe_error;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   270
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   271
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   272
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   273
    fsm->retries = EC_FSM_RETRIES;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   274
    fsm->state = ec_fsm_eoe_set_ip_request;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   275
}
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   276
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   277
/*****************************************************************************/
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   278
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   279
/** EoE state: SET IP REQUEST.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   280
 */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   281
void ec_fsm_eoe_set_ip_request(
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   282
        ec_fsm_eoe_t *fsm, /**< finite state machine */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   283
        ec_datagram_t *datagram /**< Datagram to use. */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   284
        )
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   285
{
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   286
    ec_slave_t *slave = fsm->slave;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   287
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   288
    if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   289
        if (ec_fsm_eoe_prepare_set(fsm, datagram)) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   290
            fsm->state = ec_fsm_eoe_error;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   291
        }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   292
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   293
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   294
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   295
    if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   296
        fsm->state = ec_fsm_eoe_error;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   297
        EC_SLAVE_ERR(slave, "Failed to receive EoE set IP parameter"
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   298
                " request: ");
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   299
        ec_datagram_print_state(fsm->datagram);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   300
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   301
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   302
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   303
    if (fsm->datagram->working_counter != 1) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   304
        unsigned long diff_ms =
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   305
            (jiffies - fsm->request->jiffies_sent) * 1000 / HZ;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   306
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   307
        if (!fsm->datagram->working_counter) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   308
            if (diff_ms < EC_EOE_RESPONSE_TIMEOUT) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   309
                // no response; send request datagram again
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   310
                if (ec_fsm_eoe_prepare_set(fsm, datagram)) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   311
                    fsm->state = ec_fsm_eoe_error;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   312
                }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   313
                return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   314
            }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   315
        }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   316
        fsm->state = ec_fsm_eoe_error;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   317
        EC_SLAVE_ERR(slave, "Reception of EoE set IP parameter request"
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   318
                " failed after %lu ms: ", diff_ms);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   319
        ec_datagram_print_wc_error(fsm->datagram);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   320
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   321
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   322
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   323
    fsm->jiffies_start = fsm->datagram->jiffies_sent;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   324
    ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   325
    fsm->retries = EC_FSM_RETRIES;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   326
    fsm->state = ec_fsm_eoe_set_ip_check;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   327
}
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   328
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   329
/*****************************************************************************/
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   330
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   331
/** EoE state: SET IP CHECK.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   332
 */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   333
void ec_fsm_eoe_set_ip_check(
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   334
        ec_fsm_eoe_t *fsm, /**< finite state machine */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   335
        ec_datagram_t *datagram /**< Datagram to use. */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   336
        )
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   337
{
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   338
    ec_slave_t *slave = fsm->slave;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   339
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   340
    if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   341
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   342
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   343
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   344
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   345
    if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   346
        fsm->state = ec_fsm_eoe_error;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   347
        EC_SLAVE_ERR(slave, "Failed to receive EoE mailbox check datagram: ");
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   348
        ec_datagram_print_state(fsm->datagram);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   349
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   350
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   351
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   352
    if (fsm->datagram->working_counter != 1) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   353
        fsm->state = ec_fsm_eoe_error;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   354
        EC_SLAVE_ERR(slave, "Reception of EoE mailbox check"
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   355
                " datagram failed: ");
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   356
        ec_datagram_print_wc_error(fsm->datagram);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   357
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   358
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   359
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   360
    if (!ec_slave_mbox_check(fsm->datagram)) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   361
        unsigned long diff_ms =
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   362
            (fsm->datagram->jiffies_received - fsm->jiffies_start) *
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   363
            1000 / HZ;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   364
        if (diff_ms >= EC_EOE_RESPONSE_TIMEOUT) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   365
            fsm->state = ec_fsm_eoe_error;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   366
            EC_SLAVE_ERR(slave, "Timeout after %lu ms while waiting for"
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   367
                    " set IP parameter response.\n", diff_ms);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   368
            return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   369
        }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   370
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   371
        ec_slave_mbox_prepare_check(slave, datagram); // can not fail.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   372
        fsm->retries = EC_FSM_RETRIES;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   373
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   374
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   375
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   376
    // fetch response
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   377
    ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   378
    fsm->retries = EC_FSM_RETRIES;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   379
    fsm->state = ec_fsm_eoe_set_ip_response;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   380
}
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   381
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   382
/*****************************************************************************/
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   383
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   384
/** EoE state: SET IP RESPONSE.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   385
 */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   386
void ec_fsm_eoe_set_ip_response(
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   387
        ec_fsm_eoe_t *fsm, /**< finite state machine */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   388
        ec_datagram_t *datagram /**< Datagram to use. */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   389
        )
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   390
{
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   391
    ec_slave_t *slave = fsm->slave;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   392
    ec_master_t *master = slave->master;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   393
    uint8_t *data, mbox_prot, frame_type;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   394
    size_t rec_size;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   395
    ec_eoe_request_t *req = fsm->request;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   396
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   397
    if (fsm->datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   398
        ec_slave_mbox_prepare_fetch(slave, datagram); // can not fail.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   399
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   400
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   401
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   402
    if (fsm->datagram->state != EC_DATAGRAM_RECEIVED) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   403
        fsm->state = ec_fsm_eoe_error;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   404
        EC_SLAVE_ERR(slave, "Failed to receive EoE read response datagram: ");
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   405
        ec_datagram_print_state(fsm->datagram);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   406
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   407
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   408
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   409
    if (fsm->datagram->working_counter != 1) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   410
        fsm->state = ec_fsm_eoe_error;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   411
        EC_SLAVE_ERR(slave, "Reception of EoE read response failed: ");
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   412
        ec_datagram_print_wc_error(fsm->datagram);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   413
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   414
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   415
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   416
    data = ec_slave_mbox_fetch(slave, fsm->datagram, &mbox_prot, &rec_size);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   417
    if (IS_ERR(data)) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   418
        fsm->state = ec_fsm_eoe_error;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   419
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   420
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   421
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   422
    if (master->debug_level) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   423
        EC_SLAVE_DBG(slave, 0, "Set IP parameter response:\n");
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   424
        ec_print_data(data, rec_size);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   425
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   426
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   427
    if (mbox_prot != EC_MBOX_TYPE_EOE) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   428
        fsm->state = ec_fsm_eoe_error;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   429
        EC_SLAVE_ERR(slave, "Received mailbox protocol 0x%02X as response.\n",
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   430
                mbox_prot);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   431
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   432
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   433
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   434
    if (rec_size < 4) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   435
        fsm->state = ec_fsm_eoe_error;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   436
        EC_SLAVE_ERR(slave, "Received currupted EoE set IP parameter response"
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   437
                " (%zu bytes)!\n", rec_size);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   438
        ec_print_data(data, rec_size);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   439
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   440
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   441
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   442
    frame_type = EC_READ_U8(data) & 0x0f;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   443
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   444
    if (frame_type != EC_EOE_FRAMETYPE_SET_IP_RES) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   445
        EC_SLAVE_ERR(slave, "Received no set IP parameter response"
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   446
                " (frame type %x).\n", frame_type);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   447
        ec_print_data(data, rec_size);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   448
        fsm->state = ec_fsm_eoe_error;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   449
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   450
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   451
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   452
    req->result = EC_READ_U16(data + 2);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   453
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   454
    if (req->result) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   455
        fsm->state = ec_fsm_eoe_error;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   456
        EC_SLAVE_DBG(slave, 1, "EoE set IP parameters failed with result code"
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   457
                " 0x%04X.\n", req->result);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   458
    } else {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   459
        fsm->state = ec_fsm_eoe_end; // success
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   460
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   461
}
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   462
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   463
/*****************************************************************************/
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   464
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   465
/** State: ERROR.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   466
 */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   467
void ec_fsm_eoe_error(
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   468
        ec_fsm_eoe_t *fsm, /**< finite state machine */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   469
        ec_datagram_t *datagram /**< Datagram to use. */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   470
        )
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   471
{
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   472
}
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   473
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   474
/*****************************************************************************/
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   475
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   476
/** State: END.
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   477
 */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   478
void ec_fsm_eoe_end(
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   479
        ec_fsm_eoe_t *fsm, /**< finite state machine */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   480
        ec_datagram_t *datagram /**< Datagram to use. */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   481
        )
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   482
{
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   483
}
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   484
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   485
/*****************************************************************************/