master/fsm_slave_config.c
author Florian Pose <fp@igh-essen.com>
Wed, 01 Oct 2008 08:45:16 +0000
changeset 1238 02711963a059
parent 1225 4d5b739edcb5
child 1277 1189e040fe12
permissions -rw-r--r--
Added missing header.
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  and/or modify it under the terms of the GNU General Public License
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  as published by the Free Software Foundation; either version 2 of the
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *  License, or (at your option) any later version.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  The IgH EtherCAT Master is distributed in the hope that it will be
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *  GNU General Public License for more details.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  You should have received a copy of the GNU General Public License
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *  The right to use EtherCAT Technology is granted and comes free of
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  charge under condition of compatibility of product made by
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  Licensee. People intending to distribute/sell products based on the
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *  code, have to sign an agreement to guarantee that products using
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *  software based on IgH EtherCAT master stay compatible with the actual
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *  EtherCAT specification (which are released themselves as an open
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
 *  standard) as the (only) precondition to have the right to use EtherCAT
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
 *  Technology, IP and trade marks.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
 *
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
 *****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
    34
/** \file
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
    35
 *
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
    36
 * EtherCAT slave configuration state machine.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
    37
 */
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include "globals.h"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include "master.h"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#include "mailbox.h"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
#include "slave_config.h"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
#include "fsm_slave_config.h"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
void ec_fsm_slave_config_state_start(ec_fsm_slave_config_t *);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
void ec_fsm_slave_config_state_init(ec_fsm_slave_config_t *);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
void ec_fsm_slave_config_state_clear_fmmus(ec_fsm_slave_config_t *);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
void ec_fsm_slave_config_state_mbox_sync(ec_fsm_slave_config_t *);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
void ec_fsm_slave_config_state_preop(ec_fsm_slave_config_t *);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
void ec_fsm_slave_config_state_sdo_conf(ec_fsm_slave_config_t *);
888
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
    55
void ec_fsm_slave_config_state_pdo_sync(ec_fsm_slave_config_t *);
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
    56
void ec_fsm_slave_config_state_pdo_conf(ec_fsm_slave_config_t *);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
void ec_fsm_slave_config_state_fmmu(ec_fsm_slave_config_t *);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
void ec_fsm_slave_config_state_safeop(ec_fsm_slave_config_t *);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
void ec_fsm_slave_config_state_op(ec_fsm_slave_config_t *);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
void ec_fsm_slave_config_enter_mbox_sync(ec_fsm_slave_config_t *);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
void ec_fsm_slave_config_enter_preop(ec_fsm_slave_config_t *);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
void ec_fsm_slave_config_enter_sdo_conf(ec_fsm_slave_config_t *);
1180
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
    64
void ec_fsm_slave_config_enter_pdo_conf(ec_fsm_slave_config_t *);
888
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
    65
void ec_fsm_slave_config_enter_pdo_sync(ec_fsm_slave_config_t *);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
void ec_fsm_slave_config_enter_fmmu(ec_fsm_slave_config_t *);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
void ec_fsm_slave_config_enter_safeop(ec_fsm_slave_config_t *);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
void ec_fsm_slave_config_state_end(ec_fsm_slave_config_t *);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
void ec_fsm_slave_config_state_error(ec_fsm_slave_config_t *);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
/** Constructor.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
 */
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
    76
void ec_fsm_slave_config_init(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
    77
        ec_fsm_slave_config_t *fsm, /**< slave state machine */
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
    78
        ec_datagram_t *datagram, /**< datagram structure to use */
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
    79
        ec_fsm_change_t *fsm_change, /**< State change state machine to use. */
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
    80
        ec_fsm_coe_t *fsm_coe, /**< CoE state machine to use. */
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
    81
        ec_fsm_pdo_t *fsm_pdo /**< Pdo configuration state machine to use. */
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
        )
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
    fsm->datagram = datagram;
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
    85
    fsm->fsm_change = fsm_change;
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
    86
    fsm->fsm_coe = fsm_coe;
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
    87
    fsm->fsm_pdo = fsm_pdo;
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
/** Destructor.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
 */
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
    94
void ec_fsm_slave_config_clear(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
    95
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
    96
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   102
/** Start slave configuration state machine.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   103
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   104
void ec_fsm_slave_config_start(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   105
        ec_fsm_slave_config_t *fsm, /**< slave state machine */
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
        ec_slave_t *slave /**< slave to configure */
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
        )
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
    fsm->slave = slave;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
    fsm->state = ec_fsm_slave_config_state_start;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
/**
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   116
 * \return false, if state machine has terminated
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   117
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   118
int ec_fsm_slave_config_running(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   119
        const ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   120
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
    return fsm->state != ec_fsm_slave_config_state_end
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
        && fsm->state != ec_fsm_slave_config_state_error;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   128
/** Executes the current state of the state machine.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   129
 *
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   130
 * If the state machine's datagram is not sent or received yet, the execution
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   131
 * of the state machine is delayed to the next cycle.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   132
 *
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   133
 * \return false, if state machine has terminated
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   134
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   135
int ec_fsm_slave_config_exec(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   136
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   137
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
    if (fsm->datagram->state == EC_DATAGRAM_SENT
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
        || fsm->datagram->state == EC_DATAGRAM_QUEUED) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
        // datagram was not sent or received yet.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
        return ec_fsm_slave_config_running(fsm);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
    fsm->state(fsm);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
    return ec_fsm_slave_config_running(fsm);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
/**
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   152
 * \return true, if the state machine terminated gracefully
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   153
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   154
int ec_fsm_slave_config_success(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   155
        const ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   156
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
    return fsm->state == ec_fsm_slave_config_state_end;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
/******************************************************************************
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
 * Slave configuration state machine
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
 *****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   165
/** Slave configuration state: START.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   166
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   167
void ec_fsm_slave_config_state_start(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   168
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   169
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
    if (fsm->slave->master->debug_level) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   172
        EC_DBG("Configuring slave %u...\n", fsm->slave->ring_position);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
    }
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   174
    
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   175
    // configuration will be done immediately; therefore reset the
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   176
    // force flag
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   177
    fsm->slave->force_config = 0;
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   179
    ec_fsm_change_start(fsm->fsm_change, fsm->slave, EC_SLAVE_STATE_INIT);
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   180
    ec_fsm_change_exec(fsm->fsm_change);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
    fsm->state = ec_fsm_slave_config_state_init;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   186
/** Slave configuration state: INIT.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   187
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   188
void ec_fsm_slave_config_state_init(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   189
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   190
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
    ec_master_t *master = fsm->slave->master;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
    ec_slave_t *slave = fsm->slave;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
    ec_datagram_t *datagram = fsm->datagram;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   196
    if (ec_fsm_change_exec(fsm->fsm_change)) return;
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   197
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   198
    if (!ec_fsm_change_success(fsm->fsm_change)) {
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   199
        if (!fsm->fsm_change->spontaneous_change)
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
            slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
        fsm->state = ec_fsm_slave_config_state_error;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
    if (master->debug_level) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   206
        EC_DBG("Slave %u is now in INIT.\n", slave->ring_position);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
    if (!slave->base_fmmu_count) { // skip FMMU configuration
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
        ec_fsm_slave_config_enter_mbox_sync(fsm);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   212
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   214
    if (master->debug_level)
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   215
        EC_DBG("Clearing FMMU configurations of slave %u...\n",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
               slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   217
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   218
    // clear FMMU configurations
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   219
    ec_datagram_fpwr(datagram, slave->station_address,
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
            0x0600, EC_FMMU_PAGE_SIZE * slave->base_fmmu_count);
1225
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1180
diff changeset
   221
    ec_datagram_zero(datagram);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   222
    fsm->retries = EC_FSM_RETRIES;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
    fsm->state = ec_fsm_slave_config_state_clear_fmmus;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   228
/** Slave configuration state: CLEAR FMMU.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   229
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   230
void ec_fsm_slave_config_state_clear_fmmus(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   231
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   232
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   233
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
    ec_datagram_t *datagram = fsm->datagram;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   239
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   240
        fsm->state = ec_fsm_slave_config_state_error;
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   241
        EC_ERR("Failed receive FMMU clearing datagram for slave %u.\n",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   242
               fsm->slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   243
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   244
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   245
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   246
    if (datagram->working_counter != 1) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   247
        fsm->slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   248
        fsm->state = ec_fsm_slave_config_state_error;
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   249
        EC_ERR("Failed to clear FMMUs of slave %u: ",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   250
               fsm->slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   251
        ec_datagram_print_wc_error(datagram);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   252
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   253
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   254
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   255
    ec_fsm_slave_config_enter_mbox_sync(fsm);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   256
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   258
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   259
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   260
/** Check for mailbox sync managers to be configured.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   261
 */
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   262
void ec_fsm_slave_config_enter_mbox_sync(
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   263
        ec_fsm_slave_config_t *fsm /**< slave state machine */
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   264
        )
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   265
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   266
    ec_master_t *master = fsm->slave->master;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   267
    ec_slave_t *slave = fsm->slave;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   268
    ec_datagram_t *datagram = fsm->datagram;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   269
    unsigned int i;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   270
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   271
    // slave is now in INIT
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   272
    if (slave->current_state == slave->requested_state) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   273
        fsm->state = ec_fsm_slave_config_state_end; // successful
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   274
        if (master->debug_level) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   275
            EC_DBG("Finished configuration of slave %u.\n",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   276
                   slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   277
        }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   278
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   279
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   280
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   281
    if (!slave->sii.mailbox_protocols) {
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   282
        // no mailbox protocols supported
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   283
        if (master->debug_level)
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   284
            EC_DBG("Slave %u does not support mailbox communication.\n",
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   285
                    slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   286
        ec_fsm_slave_config_enter_preop(fsm);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   287
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   288
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   289
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   290
    if (master->debug_level) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   291
        EC_DBG("Configuring mailbox sync managers of slave %u.\n",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   292
               slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   293
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   294
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   295
    if (slave->sii.sync_count >= 2) { // mailbox configuration provided
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   296
        ec_datagram_fpwr(datagram, slave->station_address, 0x0800,
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   297
                EC_SYNC_PAGE_SIZE * slave->sii.sync_count);
1225
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1180
diff changeset
   298
        ec_datagram_zero(datagram);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   299
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   300
        for (i = 0; i < 2; i++) {
1055
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   301
            ec_sync_page(&slave->sii.syncs[i], i,
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   302
                    slave->sii.syncs[i].default_length,
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   303
                    EC_DIR_INVALID, // use default direction
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   304
                    datagram->data + EC_SYNC_PAGE_SIZE * i);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   305
        }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   306
    } else { // no mailbox sync manager configurations provided
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   307
        ec_sync_t sync;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   308
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   309
        if (master->debug_level)
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   310
            EC_DBG("Slave %u does not provide"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   311
                    " mailbox sync manager configurations.\n",
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   312
                    slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   313
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   314
        ec_datagram_fpwr(datagram, slave->station_address, 0x0800,
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   315
                EC_SYNC_PAGE_SIZE * 2);
1225
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1180
diff changeset
   316
        ec_datagram_zero(datagram);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   317
1055
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   318
        ec_sync_init(&sync, slave);
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   319
        sync.physical_start_address = slave->sii.rx_mailbox_offset;
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   320
        sync.control_register = 0x26;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   321
        sync.enable = 1;
1055
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   322
        ec_sync_page(&sync, 0, slave->sii.rx_mailbox_size,
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   323
                EC_DIR_INVALID, // use default direction
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   324
                datagram->data);
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   325
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   326
        ec_sync_init(&sync, slave);
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   327
        sync.physical_start_address = slave->sii.tx_mailbox_offset;
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   328
        sync.control_register = 0x22;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   329
        sync.enable = 1;
1055
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   330
        ec_sync_page(&sync, 1, slave->sii.tx_mailbox_size,
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   331
                EC_DIR_INVALID, // use default direction
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   332
                datagram->data + EC_SYNC_PAGE_SIZE);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   333
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   334
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   335
    fsm->retries = EC_FSM_RETRIES;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   336
    fsm->state = ec_fsm_slave_config_state_mbox_sync;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   337
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   338
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   339
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   340
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   341
/** Slave configuration state: SYNC.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   342
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   343
void ec_fsm_slave_config_state_mbox_sync(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   344
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   345
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   346
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   347
    ec_datagram_t *datagram = fsm->datagram;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   348
    ec_slave_t *slave = fsm->slave;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   349
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   350
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   351
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   352
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   353
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   354
        fsm->state = ec_fsm_slave_config_state_error;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   355
        EC_ERR("Failed to receive sync manager configuration datagram for"
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   356
               " slave %u (datagram state %u).\n",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   357
               slave->ring_position, datagram->state);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   358
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   359
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   360
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   361
    if (datagram->working_counter != 1) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   362
        slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   363
        fsm->state = ec_fsm_slave_config_state_error;
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   364
        EC_ERR("Failed to set sync managers of slave %u: ",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   365
               slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   366
        ec_datagram_print_wc_error(datagram);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   367
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   368
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   369
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   370
    ec_fsm_slave_config_enter_preop(fsm);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   371
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   372
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   373
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   374
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   375
/** Request PREOP state.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   376
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   377
void ec_fsm_slave_config_enter_preop(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   378
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   379
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   380
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   381
    fsm->state = ec_fsm_slave_config_state_preop;
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   382
    ec_fsm_change_start(fsm->fsm_change, fsm->slave, EC_SLAVE_STATE_PREOP);
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   383
    ec_fsm_change_exec(fsm->fsm_change); // execute immediately
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   384
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   385
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   386
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   387
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   388
/** Slave configuration state: PREOP.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   389
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   390
void ec_fsm_slave_config_state_preop(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   391
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   392
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   393
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   394
    ec_slave_t *slave = fsm->slave;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   395
    ec_master_t *master = fsm->slave->master;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   396
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   397
    if (ec_fsm_change_exec(fsm->fsm_change)) return;
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   398
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   399
    if (!ec_fsm_change_success(fsm->fsm_change)) {
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   400
        if (!fsm->fsm_change->spontaneous_change)
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   401
            slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   402
        fsm->state = ec_fsm_slave_config_state_error;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   403
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   404
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   405
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   406
    // slave is now in PREOP
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   407
    slave->jiffies_preop = fsm->datagram->jiffies_received;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   408
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   409
    if (master->debug_level) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   410
        EC_DBG("Slave %u is now in PREOP.\n", slave->ring_position);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   411
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   412
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   413
    if (slave->current_state == slave->requested_state) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   414
        fsm->state = ec_fsm_slave_config_state_end; // successful
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   415
        if (master->debug_level) {
888
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   416
            EC_DBG("Finished configuration of slave %u.\n",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   417
                   slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   418
        }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   419
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   420
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   421
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   422
    if (!slave->config) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   423
        EC_DBG("Slave %u is not configured.\n", slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   424
        ec_fsm_slave_config_enter_safeop(fsm);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   425
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   426
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   427
888
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   428
    ec_fsm_slave_config_enter_sdo_conf(fsm);
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   429
}
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   430
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   431
/*****************************************************************************/
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   432
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   433
/** Check for Sdo configurations to be applied.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   434
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   435
void ec_fsm_slave_config_enter_sdo_conf(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   436
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   437
        )
888
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   438
{
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   439
    ec_slave_t *slave = fsm->slave;
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   440
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   441
    // No CoE configuration to be applied?
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   442
    if (list_empty(&slave->config->sdo_configs)) { // skip Sdo configuration
1180
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   443
        ec_fsm_slave_config_enter_pdo_conf(fsm);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   444
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   445
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   446
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   447
    // start Sdo configuration
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   448
    fsm->state = ec_fsm_slave_config_state_sdo_conf;
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   449
    fsm->request = list_entry(fsm->slave->config->sdo_configs.next,
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   450
            ec_sdo_request_t, list);
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   451
    ecrt_sdo_request_write(fsm->request);
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   452
    ec_fsm_coe_transfer(fsm->fsm_coe, fsm->slave, fsm->request);
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   453
    ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   454
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   455
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   456
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   457
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   458
/** Slave configuration state: SDO_CONF.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   459
 */
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   460
void ec_fsm_slave_config_state_sdo_conf(
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   461
        ec_fsm_slave_config_t *fsm /**< slave state machine */
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   462
        )
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   463
{
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   464
    if (ec_fsm_coe_exec(fsm->fsm_coe)) return;
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   465
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   466
    if (!ec_fsm_coe_success(fsm->fsm_coe)) {
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   467
        EC_ERR("Sdo configuration failed for slave %u.\n",
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   468
                fsm->slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   469
        fsm->slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   470
        fsm->state = ec_fsm_slave_config_state_error;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   471
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   472
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   473
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   474
    // Another Sdo to configure?
854
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   475
    if (fsm->request->list.next != &fsm->slave->config->sdo_configs) {
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   476
        fsm->request = list_entry(fsm->request->list.next, ec_sdo_request_t,
f4f53be425ac Removed ec_sdodata_t; CoE state machines work on ec_sdo_request_t.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   477
                list);
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 854
diff changeset
   478
        ecrt_sdo_request_write(fsm->request);
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   479
        ec_fsm_coe_transfer(fsm->fsm_coe, fsm->slave, fsm->request);
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   480
        ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   481
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   482
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   483
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   484
    // All Sdos are now configured.
1180
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   485
    ec_fsm_slave_config_enter_pdo_conf(fsm);
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   486
}
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   487
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   488
/*****************************************************************************/
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   489
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   490
/** PDO_CONF entry function.
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   491
 */
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   492
void ec_fsm_slave_config_enter_pdo_conf(
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   493
        ec_fsm_slave_config_t *fsm /**< slave state machine */
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   494
        )
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   495
{
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   496
    // Start configuring Pdos
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   497
    ec_fsm_pdo_start_configuration(fsm->fsm_pdo, fsm->slave);
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   498
    fsm->state = ec_fsm_slave_config_state_pdo_conf;
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   499
    fsm->state(fsm); // execute immediately
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   500
}
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   501
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   502
/*****************************************************************************/
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   503
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   504
/** Slave configuration state: PDO_CONF.
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   505
 */
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   506
void ec_fsm_slave_config_state_pdo_conf(
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   507
        ec_fsm_slave_config_t *fsm /**< slave state machine */
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   508
        )
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   509
{
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   510
    if (ec_fsm_pdo_exec(fsm->fsm_pdo))
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   511
        return;
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   512
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   513
    if (!ec_fsm_pdo_success(fsm->fsm_pdo)) {
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   514
        EC_WARN("Pdo configuration failed on slave %u.\n",
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   515
                fsm->slave->ring_position);
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   516
    }
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   517
888
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   518
    ec_fsm_slave_config_enter_pdo_sync(fsm);
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   519
}
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   520
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   521
/*****************************************************************************/
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   522
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   523
/** Check for Pdo sync managers to be configured.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   524
 */
888
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   525
void ec_fsm_slave_config_enter_pdo_sync(
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   526
        ec_fsm_slave_config_t *fsm /**< slave state machine */
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   527
        )
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   528
{
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   529
    ec_slave_t *slave = fsm->slave;
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   530
    ec_datagram_t *datagram = fsm->datagram;
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   531
    unsigned int i, offset, num_pdo_syncs;
1055
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   532
    uint8_t sync_index;
888
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   533
    const ec_sync_t *sync;
1055
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   534
    const ec_sync_config_t *sync_config;
888
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   535
    uint16_t size;
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   536
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   537
    if (slave->sii.mailbox_protocols) {
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   538
        offset = 2; // slave has mailboxes
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   539
    } else {
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   540
        offset = 0;
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   541
    }
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   542
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   543
    if (slave->sii.sync_count <= offset) {
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   544
        // no Pdo sync managers to configure
1180
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   545
        ec_fsm_slave_config_enter_fmmu(fsm);
888
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   546
        return;
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   547
    }
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   548
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   549
    num_pdo_syncs = slave->sii.sync_count - offset;
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   550
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   551
    // configure sync managers for process data
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   552
    ec_datagram_fpwr(datagram, slave->station_address,
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   553
            0x0800 + EC_SYNC_PAGE_SIZE * offset,
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   554
            EC_SYNC_PAGE_SIZE * num_pdo_syncs);
1225
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1180
diff changeset
   555
    ec_datagram_zero(datagram);
888
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   556
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   557
    for (i = 0; i < num_pdo_syncs; i++) {
1055
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   558
        sync_index = i + offset;
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   559
        sync = &slave->sii.syncs[sync_index];
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   560
        sync_config = &slave->config->sync_configs[sync_index];
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   561
        size = ec_pdo_list_total_size(&sync_config->pdos);
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   562
        ec_sync_page(sync, sync_index, size, sync_config->dir,
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   563
                datagram->data + EC_SYNC_PAGE_SIZE * i);
888
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   564
    }
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   565
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   566
    fsm->retries = EC_FSM_RETRIES;
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   567
    fsm->state = ec_fsm_slave_config_state_pdo_sync;
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   568
}
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   569
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   570
/*****************************************************************************/
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   571
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   572
/** Configure Pdo sync managers.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   573
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   574
void ec_fsm_slave_config_state_pdo_sync(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   575
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   576
        )
888
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   577
{
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   578
    ec_datagram_t *datagram = fsm->datagram;
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   579
    ec_slave_t *slave = fsm->slave;
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   580
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   581
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   582
        return;
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   583
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   584
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   585
        fsm->state = ec_fsm_slave_config_state_error;
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   586
        EC_ERR("Failed to receive process data sync manager configuration"
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   587
               " datagram for slave %u (datagram state %u).\n",
888
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   588
               slave->ring_position, datagram->state);
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   589
        return;
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   590
    }
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   591
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   592
    if (datagram->working_counter != 1) {
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   593
        slave->error_flag = 1;
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   594
        fsm->state = ec_fsm_slave_config_state_error;
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   595
        EC_ERR("Failed to set process data sync managers of slave %u: ",
888
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   596
                slave->ring_position);
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   597
        ec_datagram_print_wc_error(datagram);
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   598
        return;
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   599
    }
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   600
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   601
    ec_fsm_slave_config_enter_fmmu(fsm);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   602
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   603
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   604
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   605
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   606
/** Check for FMMUs to be configured.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   607
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   608
void ec_fsm_slave_config_enter_fmmu(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   609
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   610
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   611
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   612
    ec_slave_t *slave = fsm->slave;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   613
    ec_datagram_t *datagram = fsm->datagram;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   614
    unsigned int i;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   615
    const ec_fmmu_config_t *fmmu;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   616
    const ec_sync_t *sync;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   617
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   618
    if (slave->base_fmmu_count < slave->config->used_fmmus) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   619
        slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   620
        fsm->state = ec_fsm_slave_config_state_error;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   621
        EC_ERR("Slave %u has less FMMUs (%u) than requested (%u).\n",
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   622
                slave->ring_position, slave->base_fmmu_count,
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   623
                slave->config->used_fmmus);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   624
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   625
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   626
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   627
    if (!slave->base_fmmu_count) { // skip FMMU configuration
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   628
        ec_fsm_slave_config_enter_safeop(fsm);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   629
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   630
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   631
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   632
    // configure FMMUs
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   633
    ec_datagram_fpwr(datagram, slave->station_address,
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   634
                     0x0600, EC_FMMU_PAGE_SIZE * slave->base_fmmu_count);
1225
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1180
diff changeset
   635
    ec_datagram_zero(datagram);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   636
    for (i = 0; i < slave->config->used_fmmus; i++) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   637
        fmmu = &slave->config->fmmu_configs[i];
1055
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   638
        if (!(sync = ec_slave_get_sync(slave, fmmu->sync_index))) {
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   639
            slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   640
            fsm->state = ec_fsm_slave_config_state_error;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   641
            EC_ERR("Failed to determine Pdo sync manager for FMMU on slave"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   642
                    " %u!\n", slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   643
            return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   644
        }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   645
        ec_fmmu_config_page(fmmu, sync,
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   646
                datagram->data + EC_FMMU_PAGE_SIZE * i);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   647
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   648
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   649
    fsm->retries = EC_FSM_RETRIES;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   650
    fsm->state = ec_fsm_slave_config_state_fmmu;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   651
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   652
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   653
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   654
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   655
/** Slave configuration state: FMMU.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   656
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   657
void ec_fsm_slave_config_state_fmmu(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   658
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   659
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   660
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   661
    ec_datagram_t *datagram = fsm->datagram;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   662
    ec_slave_t *slave = fsm->slave;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   663
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   664
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   665
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   666
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   667
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   668
        fsm->state = ec_fsm_slave_config_state_error;
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   669
        EC_ERR("Failed to receive FMMUs datagram for slave %u"
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   670
                " (datagram state %u).\n",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   671
               slave->ring_position, datagram->state);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   672
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   673
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   674
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   675
    if (datagram->working_counter != 1) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   676
        slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   677
        fsm->state = ec_fsm_slave_config_state_error;
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   678
        EC_ERR("Failed to set FMMUs of slave %u: ",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   679
               slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   680
        ec_datagram_print_wc_error(datagram);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   681
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   682
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   683
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   684
    ec_fsm_slave_config_enter_safeop(fsm);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   685
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   686
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   687
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   688
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   689
/** Request SAFEOP state.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   690
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   691
void ec_fsm_slave_config_enter_safeop(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   692
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   693
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   694
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   695
    fsm->state = ec_fsm_slave_config_state_safeop;
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   696
    ec_fsm_change_start(fsm->fsm_change, fsm->slave, EC_SLAVE_STATE_SAFEOP);
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   697
    ec_fsm_change_exec(fsm->fsm_change); // execute immediately
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   698
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   699
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   700
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   701
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   702
/** Slave configuration state: SAFEOP.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   703
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   704
void ec_fsm_slave_config_state_safeop(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   705
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   706
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   707
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   708
    ec_master_t *master = fsm->slave->master;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   709
    ec_slave_t *slave = fsm->slave;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   710
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   711
    if (ec_fsm_change_exec(fsm->fsm_change)) return;
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   712
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   713
    if (!ec_fsm_change_success(fsm->fsm_change)) {
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   714
        if (!fsm->fsm_change->spontaneous_change)
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   715
            fsm->slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   716
        fsm->state = ec_fsm_slave_config_state_error;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   717
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   718
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   719
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   720
    // slave is now in SAFEOP
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   721
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   722
    if (master->debug_level) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   723
        EC_DBG("Slave %u is now in SAFEOP.\n", slave->ring_position);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   724
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   725
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   726
    if (fsm->slave->current_state == fsm->slave->requested_state) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   727
        fsm->state = ec_fsm_slave_config_state_end; // successful
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   728
        if (master->debug_level) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   729
            EC_DBG("Finished configuration of slave %u.\n",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   730
                   slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   731
        }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   732
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   733
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   734
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   735
    // set state to OP
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   736
    fsm->state = ec_fsm_slave_config_state_op;
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   737
    ec_fsm_change_start(fsm->fsm_change, slave, EC_SLAVE_STATE_OP);
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   738
    ec_fsm_change_exec(fsm->fsm_change); // execute immediately
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   739
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   740
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   741
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   742
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   743
/** Slave configuration state: OP
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   744
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   745
void ec_fsm_slave_config_state_op(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   746
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   747
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   748
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   749
    ec_master_t *master = fsm->slave->master;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   750
    ec_slave_t *slave = fsm->slave;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   751
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   752
    if (ec_fsm_change_exec(fsm->fsm_change)) return;
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   753
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   754
    if (!ec_fsm_change_success(fsm->fsm_change)) {
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   755
        if (!fsm->fsm_change->spontaneous_change)
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   756
            slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   757
        fsm->state = ec_fsm_slave_config_state_error;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   758
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   759
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   760
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   761
    // slave is now in OP
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   762
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   763
    if (master->debug_level) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   764
        EC_DBG("Slave %u is now in OP.\n", slave->ring_position);
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   765
        EC_DBG("Finished configuration of slave %u.\n", slave->ring_position);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   766
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   767
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   768
    fsm->state = ec_fsm_slave_config_state_end; // successful
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   769
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   770
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   771
/******************************************************************************
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   772
 *  Common state functions
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   773
 *****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   774
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   775
/** State: ERROR.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   776
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   777
void ec_fsm_slave_config_state_error(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   778
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   779
        )
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   780
{
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   781
}
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   782
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   783
/*****************************************************************************/
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   784
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   785
/** State: END.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   786
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   787
void ec_fsm_slave_config_state_end(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   788
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   789
        )
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   790
{
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   791
}
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   792
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   793
/*****************************************************************************/