master/fsm_eoe.c
author Florian Pose <fp@igh-essen.com>
Fri, 16 Sep 2016 12:35:09 +0200
changeset 2663 b101637f503c
parent 2642 9dc0b2262f90
permissions -rw-r--r--
Use SYNC0 + SYNC1 cycle times for cyclic start time generation.
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) {
2642
9dc0b2262f90 Fixed endianess of EoE parameters.
Florian Pose <fp@gh.de>
parents: 2597
diff changeset
   215
        uint32_t swapped = htonl(req->ip_address);
9dc0b2262f90 Fixed endianess of EoE parameters.
Florian Pose <fp@gh.de>
parents: 2597
diff changeset
   216
        memcpy(cur, &swapped, 4);
2597
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   217
        cur += 4;
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
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
    if (req->subnet_mask_included) {
2642
9dc0b2262f90 Fixed endianess of EoE parameters.
Florian Pose <fp@gh.de>
parents: 2597
diff changeset
   221
        uint32_t swapped = htonl(req->subnet_mask);
9dc0b2262f90 Fixed endianess of EoE parameters.
Florian Pose <fp@gh.de>
parents: 2597
diff changeset
   222
        memcpy(cur, &swapped, 4);
2597
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
        cur += 4;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
    if (req->gateway_included) {
2642
9dc0b2262f90 Fixed endianess of EoE parameters.
Florian Pose <fp@gh.de>
parents: 2597
diff changeset
   227
        uint32_t swapped = htonl(req->gateway);
9dc0b2262f90 Fixed endianess of EoE parameters.
Florian Pose <fp@gh.de>
parents: 2597
diff changeset
   228
        memcpy(cur, &swapped, 4);
2597
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   229
        cur += 4;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   231
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   232
    if (req->dns_included) {
2642
9dc0b2262f90 Fixed endianess of EoE parameters.
Florian Pose <fp@gh.de>
parents: 2597
diff changeset
   233
        uint32_t swapped = htonl(req->dns);
9dc0b2262f90 Fixed endianess of EoE parameters.
Florian Pose <fp@gh.de>
parents: 2597
diff changeset
   234
        memcpy(cur, &swapped, 4);
2597
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
        cur += 4;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
    }
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
    if (req->name_included) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   239
        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
   240
        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
   241
    }
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
    if (master->debug_level) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   244
        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
   245
        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
   246
    }
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
    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
   249
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   250
    return 0;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   251
}
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
/*****************************************************************************/
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   254
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   255
/** 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
   256
 */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
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
   258
        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
   259
        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
   260
        )
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
    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
   263
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   264
    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
   265
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   266
    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
   267
        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
   268
        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
   269
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   270
    }
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
    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
   273
        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
   274
        return;
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
    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
   278
    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
   279
}
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
/*****************************************************************************/
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   282
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   283
/** 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
   284
 */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   285
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
   286
        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
   287
        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
   288
        )
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   289
{
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   290
    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
   291
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   292
    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
   293
        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
   294
            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
   295
        }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   296
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   297
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   298
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   299
    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
   300
        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
   301
        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
   302
                " request: ");
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   303
        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
   304
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   305
    }
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 != 1) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   308
        unsigned long diff_ms =
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   309
            (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
   310
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   311
        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
   312
            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
   313
                // 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
   314
                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
   315
                    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
   316
                }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   317
                return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   318
            }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   319
        }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   320
        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
   321
        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
   322
                " 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
   323
        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
   324
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   325
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   326
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   327
    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
   328
    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
   329
    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
   330
    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
   331
}
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
/*****************************************************************************/
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   334
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   335
/** 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
   336
 */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   337
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
   338
        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
   339
        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
   340
        )
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   341
{
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   342
    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
   343
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   344
    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
   345
        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
   346
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   347
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   348
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   349
    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
   350
        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
   351
        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
   352
        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
   353
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   354
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   355
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   356
    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
   357
        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
   358
        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
   359
                " datagram failed: ");
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   360
        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
   361
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   362
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   363
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   364
    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
   365
        unsigned long diff_ms =
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   366
            (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
   367
            1000 / HZ;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   368
        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
   369
            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
   370
            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
   371
                    " 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
   372
            return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   373
        }
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
        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
   376
        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
   377
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   378
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   379
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   380
    // fetch response
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   381
    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
   382
    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
   383
    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
   384
}
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
/*****************************************************************************/
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   387
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   388
/** 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
   389
 */
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   390
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
   391
        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
   392
        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
   393
        )
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   394
{
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   395
    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
   396
    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
   397
    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
   398
    size_t rec_size;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   399
    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
   400
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   401
    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
   402
        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
   403
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   404
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   405
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   406
    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
   407
        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
   408
        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
   409
        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
   410
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   411
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   412
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   413
    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
   414
        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
   415
        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
   416
        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
   417
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   418
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   419
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   420
    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
   421
    if (IS_ERR(data)) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   422
        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
   423
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   424
    }
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
    if (master->debug_level) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   427
        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
   428
        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
   429
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   430
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   431
    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
   432
        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
   433
        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
   434
                mbox_prot);
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   435
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   436
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   437
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   438
    if (rec_size < 4) {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   439
        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
   440
        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
   441
                " (%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
   442
        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
   443
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   444
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   445
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   446
    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
   447
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   448
    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
   449
        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
   450
                " (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
   451
        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
   452
        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
   453
        return;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   454
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   455
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   456
    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
   457
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   458
    if (req->result) {
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_error;
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   460
        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
   461
                " 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
   462
    } else {
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   463
        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
   464
    }
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   465
}
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
/*****************************************************************************/
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   468
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   469
/** State: ERROR.
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
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
   472
        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
   473
        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
   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
}
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
/*****************************************************************************/
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   479
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   480
/** State: END.
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
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
   483
        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
   484
        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
   485
        )
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   486
{
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   487
}
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   488
0e145bb05859 Implemented EoE Set IP parameter request via command-line tool.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   489
/*****************************************************************************/