master/fsm_slave_config.c
author Florian Pose <fp@igh-essen.com>
Tue, 27 Apr 2010 13:40:44 +0200
changeset 1914 da7adbde2625
parent 1904 2fadf016d9be
child 1921 d9cf40facbc4
child 1987 f452c93f7723
permissions -rw-r--r--
Fixed possible bug in EoE code: Only restart EoE process, when it was running
before (not while scanning).
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
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1318
diff changeset
     5
 *  Copyright (C) 2006-2008  Florian Pose, Ingenieurgemeinschaft IgH
830
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
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1318
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1318
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1318
diff changeset
    11
 *  published by the Free Software Foundation.
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1318
diff changeset
    12
 *
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1318
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1318
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1318
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1318
diff changeset
    16
 *  Public License for more details.
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1318
diff changeset
    17
 *
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1318
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1318
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  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
    21
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1347
diff changeset
    22
 *  ---
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1347
diff changeset
    23
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1347
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1347
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1347
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
    30
/** \file
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
    31
 *
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
    32
 * EtherCAT slave configuration state machine.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
    33
 */
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
1436
08eaf72409bb Use application start time as a common reference for cyclic generation
Florian Pose <fp@igh-essen.com>
parents: 1430
diff changeset
    37
#include <asm/div64.h>
08eaf72409bb Use application start time as a common reference for cyclic generation
Florian Pose <fp@igh-essen.com>
parents: 1430
diff changeset
    38
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
#include "globals.h"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#include "master.h"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include "mailbox.h"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include "slave_config.h"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#include "fsm_slave_config.h"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
1889
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
    47
/** Time difference [ns] to tolerate without setting a new system time offset.
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
    48
 */
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
    49
#define EC_SYSTEM_TIME_TOLERANCE_NS 100000000
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
    50
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
    51
/*****************************************************************************/
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
    52
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
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
    54
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
    55
void ec_fsm_slave_config_state_clear_fmmus(ec_fsm_slave_config_t *);
1342
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    56
void ec_fsm_slave_config_state_clear_sync(ec_fsm_slave_config_t *);
1407
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
    57
void ec_fsm_slave_config_state_dc_clear_assign(ec_fsm_slave_config_t *);
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
    58
void ec_fsm_slave_config_state_dc_read_offset(ec_fsm_slave_config_t *);
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
    59
void ec_fsm_slave_config_state_dc_write_offset(ec_fsm_slave_config_t *);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
void ec_fsm_slave_config_state_mbox_sync(ec_fsm_slave_config_t *);
1337
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    61
void ec_fsm_slave_config_state_boot_preop(ec_fsm_slave_config_t *);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
void ec_fsm_slave_config_state_sdo_conf(ec_fsm_slave_config_t *);
1844
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
    63
void ec_fsm_slave_config_state_soe_conf(ec_fsm_slave_config_t *);
1509
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
    64
void ec_fsm_slave_config_state_watchdog_divider(ec_fsm_slave_config_t *);
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
    65
void ec_fsm_slave_config_state_watchdog(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
    66
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
    67
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
    68
void ec_fsm_slave_config_state_fmmu(ec_fsm_slave_config_t *);
1392
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
    69
void ec_fsm_slave_config_state_dc_cycle(ec_fsm_slave_config_t *);
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
    70
void ec_fsm_slave_config_state_dc_start(ec_fsm_slave_config_t *);
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
    71
void ec_fsm_slave_config_state_dc_assign(ec_fsm_slave_config_t *);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
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
    73
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
    74
1318
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
    75
void ec_fsm_slave_config_enter_init(ec_fsm_slave_config_t *);
1342
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    76
void ec_fsm_slave_config_enter_clear_sync(ec_fsm_slave_config_t *);
1407
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
    77
void ec_fsm_slave_config_enter_dc_clear_assign(ec_fsm_slave_config_t *);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
void ec_fsm_slave_config_enter_mbox_sync(ec_fsm_slave_config_t *);
1337
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    79
void ec_fsm_slave_config_enter_boot_preop(ec_fsm_slave_config_t *);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
void ec_fsm_slave_config_enter_sdo_conf(ec_fsm_slave_config_t *);
1844
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
    81
void ec_fsm_slave_config_enter_soe_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
    82
void ec_fsm_slave_config_enter_pdo_conf(ec_fsm_slave_config_t *);
1509
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
    83
void ec_fsm_slave_config_enter_watchdog_divider(ec_fsm_slave_config_t *);
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
    84
void ec_fsm_slave_config_enter_watchdog(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
    85
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
    86
void ec_fsm_slave_config_enter_fmmu(ec_fsm_slave_config_t *);
1407
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
    87
void ec_fsm_slave_config_enter_dc_cycle(ec_fsm_slave_config_t *);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
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
    89
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
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
    91
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
    92
1318
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
    93
void ec_fsm_slave_config_reconfigure(ec_fsm_slave_config_t *);
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
    94
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
/** Constructor.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
 */
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
    99
void ec_fsm_slave_config_init(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   100
        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
   101
        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
   102
        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
   103
        ec_fsm_coe_t *fsm_coe, /**< CoE state machine to use. */
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   104
        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
   105
        )
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
{
1318
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   107
    ec_sdo_request_init(&fsm->request_copy);
1849
0a660edc7180 Fixed segfault - Initialize SoE request properly.
Florian Pose <fp@igh-essen.com>
parents: 1844
diff changeset
   108
    ec_soe_request_init(&fsm->soe_request_copy);
1318
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   109
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
    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
   111
    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
   112
    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
   113
    fsm->fsm_pdo = fsm_pdo;
830
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
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
/** Destructor.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
 */
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   120
void ec_fsm_slave_config_clear(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   121
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   122
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
{
1318
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   124
    ec_sdo_request_clear(&fsm->request_copy);
1844
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   125
    ec_soe_request_clear(&fsm->soe_request_copy);
830
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
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   130
/** Start slave configuration state machine.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   131
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   132
void ec_fsm_slave_config_start(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   133
        ec_fsm_slave_config_t *fsm, /**< slave state machine */
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
        ec_slave_t *slave /**< slave to configure */
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
        )
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
    fsm->slave = slave;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
    fsm->state = ec_fsm_slave_config_state_start;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
/**
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   144
 * \return false, if state machine has terminated
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   145
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   146
int ec_fsm_slave_config_running(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   147
        const ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   148
        )
830
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
    return fsm->state != ec_fsm_slave_config_state_end
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
        && fsm->state != ec_fsm_slave_config_state_error;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   156
/** Executes the current state of the state machine.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   157
 *
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   158
 * 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
   159
 * of the state machine is delayed to the next cycle.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   160
 *
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   161
 * \return false, if state machine has terminated
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   162
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   163
int ec_fsm_slave_config_exec(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   164
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   165
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
    if (fsm->datagram->state == EC_DATAGRAM_SENT
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
        || fsm->datagram->state == EC_DATAGRAM_QUEUED) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
        // datagram was not sent or received yet.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
        return ec_fsm_slave_config_running(fsm);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
    fsm->state(fsm);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
    return ec_fsm_slave_config_running(fsm);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
/**
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   180
 * \return true, if the state machine terminated gracefully
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   181
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   182
int ec_fsm_slave_config_success(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   183
        const ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   184
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
    return fsm->state == ec_fsm_slave_config_state_end;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
/******************************************************************************
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
 * Slave configuration state machine
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
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   193
/** Slave configuration state: START.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   194
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   195
void ec_fsm_slave_config_state_start(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   196
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   197
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
    if (fsm->slave->master->debug_level) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   200
        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
   201
    }
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   202
    
1318
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   203
    ec_fsm_slave_config_enter_init(fsm);
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   204
}
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   205
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   206
/*****************************************************************************/
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   207
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   208
/** Start state change to INIT.
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   209
 */
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   210
void ec_fsm_slave_config_enter_init(
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   211
        ec_fsm_slave_config_t *fsm /**< slave state machine */
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   212
        )
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   213
{
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   214
    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
   215
    ec_fsm_change_exec(fsm->fsm_change);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
    fsm->state = ec_fsm_slave_config_state_init;
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
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   219
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   221
/** Slave configuration state: INIT.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   222
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   223
void ec_fsm_slave_config_state_init(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   224
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   225
        )
830
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
    ec_master_t *master = fsm->slave->master;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
    ec_slave_t *slave = fsm->slave;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   229
    ec_datagram_t *datagram = fsm->datagram;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   231
    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
   232
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   233
    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
   234
        if (!fsm->fsm_change->spontaneous_change)
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
            slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
        fsm->state = ec_fsm_slave_config_state_error;
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
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   240
    if (master->debug_level) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   241
        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
   242
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   243
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   244
    if (!slave->base_fmmu_count) { // skip FMMU configuration
1342
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   245
        ec_fsm_slave_config_enter_clear_sync(fsm);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   246
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   247
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   248
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   249
    if (master->debug_level)
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   250
        EC_DBG("Clearing FMMU configurations of slave %u...\n",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   251
               slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   252
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   253
    // clear FMMU configurations
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   254
    ec_datagram_fpwr(datagram, slave->station_address,
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   255
            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
   256
    ec_datagram_zero(datagram);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
    fsm->retries = EC_FSM_RETRIES;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   258
    fsm->state = ec_fsm_slave_config_state_clear_fmmus;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   259
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   260
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   261
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   262
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   263
/** Slave configuration state: CLEAR FMMU.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   264
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   265
void ec_fsm_slave_config_state_clear_fmmus(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   266
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   267
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   268
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   269
    ec_datagram_t *datagram = fsm->datagram;
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
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   272
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   273
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   274
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   275
        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
   276
        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
   277
               fsm->slave->ring_position);
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
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   281
    if (datagram->working_counter != 1) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   282
        fsm->slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   283
        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
   284
        EC_ERR("Failed to clear FMMUs of slave %u: ",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   285
               fsm->slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   286
        ec_datagram_print_wc_error(datagram);
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
1342
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   290
    ec_fsm_slave_config_enter_clear_sync(fsm);
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   291
}
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   292
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   293
/*****************************************************************************/
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   294
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   295
/** Clear the sync manager configurations.
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   296
 */
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   297
void ec_fsm_slave_config_enter_clear_sync(
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   298
        ec_fsm_slave_config_t *fsm /**< slave state machine */
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   299
        )
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   300
{
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   301
    ec_slave_t *slave = fsm->slave;
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   302
    ec_datagram_t *datagram = fsm->datagram;
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   303
    size_t sync_size;
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   304
1471
2ec173081b7f Fixed mailbox usage for slaves that do not provide sync manager
Florian Pose <fp@igh-essen.com>
parents: 1458
diff changeset
   305
    if (!slave->base_sync_count) {
1404
b7ea043d5081 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 1396
diff changeset
   306
        // no sync managers
1407
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   307
        ec_fsm_slave_config_enter_dc_clear_assign(fsm);
1342
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   308
        return;
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   309
    }
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   310
1344
e5756d4ed12c Debug message.
Florian Pose <fp@igh-essen.com>
parents: 1342
diff changeset
   311
    if (slave->master->debug_level)
e5756d4ed12c Debug message.
Florian Pose <fp@igh-essen.com>
parents: 1342
diff changeset
   312
        EC_DBG("Clearing sync manager configurations of slave %u...\n",
e5756d4ed12c Debug message.
Florian Pose <fp@igh-essen.com>
parents: 1342
diff changeset
   313
                slave->ring_position);
e5756d4ed12c Debug message.
Florian Pose <fp@igh-essen.com>
parents: 1342
diff changeset
   314
1471
2ec173081b7f Fixed mailbox usage for slaves that do not provide sync manager
Florian Pose <fp@igh-essen.com>
parents: 1458
diff changeset
   315
    sync_size = EC_SYNC_PAGE_SIZE * slave->base_sync_count;
1342
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   316
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   317
    // clear sync manager configurations
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   318
    ec_datagram_fpwr(datagram, slave->station_address, 0x0800, sync_size);
1896
1d4bca6ba543 Use ec_datagram_zero() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1889
diff changeset
   319
    ec_datagram_zero(datagram);
1342
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   320
    fsm->retries = EC_FSM_RETRIES;
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   321
    fsm->state = ec_fsm_slave_config_state_clear_sync;
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   322
}
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   323
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   324
/*****************************************************************************/
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   325
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   326
/** Slave configuration state: CLEAR SYNC.
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   327
 */
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   328
void ec_fsm_slave_config_state_clear_sync(
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   329
        ec_fsm_slave_config_t *fsm /**< slave state machine */
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   330
        )
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   331
{
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   332
    ec_datagram_t *datagram = fsm->datagram;
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   333
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   334
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   335
        return;
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   336
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   337
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   338
        fsm->state = ec_fsm_slave_config_state_error;
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   339
        EC_ERR("Failed receive sync manager clearing datagram"
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   340
                " for slave %u.\n", fsm->slave->ring_position);
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   341
        return;
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   342
    }
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   343
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   344
    if (datagram->working_counter != 1) {
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   345
        fsm->slave->error_flag = 1;
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   346
        fsm->state = ec_fsm_slave_config_state_error;
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   347
        EC_ERR("Failed to clear sync manager configurations of slave %u: ",
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   348
               fsm->slave->ring_position);
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   349
        ec_datagram_print_wc_error(datagram);
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   350
        return;
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   351
    }
a72b9b370277 Clear sync managers before configuration.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
   352
1407
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   353
    ec_fsm_slave_config_enter_dc_clear_assign(fsm);
1406
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   354
}
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   355
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   356
/*****************************************************************************/
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   357
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   358
/** Clear the DC assignment.
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   359
 */
1407
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   360
void ec_fsm_slave_config_enter_dc_clear_assign(
1406
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   361
        ec_fsm_slave_config_t *fsm /**< slave state machine */
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   362
        )
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   363
{
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   364
    ec_slave_t *slave = fsm->slave;
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   365
    ec_datagram_t *datagram = fsm->datagram;
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   366
1419
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1412
diff changeset
   367
    if (!slave->base_dc_supported || !slave->has_dc_system_time) {
1406
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   368
        ec_fsm_slave_config_enter_mbox_sync(fsm);
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   369
        return;
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   370
    }
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   371
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   372
    if (slave->master->debug_level)
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   373
        EC_DBG("Clearing DC assignment of slave %u...\n",
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   374
                slave->ring_position);
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   375
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   376
    ec_datagram_fpwr(datagram, slave->station_address, 0x0980, 2);
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   377
    ec_datagram_zero(datagram);
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   378
    fsm->retries = EC_FSM_RETRIES;
1407
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   379
    fsm->state = ec_fsm_slave_config_state_dc_clear_assign;
1406
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   380
}
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   381
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   382
/*****************************************************************************/
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   383
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   384
/** Slave configuration state: CLEAR DC ASSIGN.
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   385
 */
1407
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   386
void ec_fsm_slave_config_state_dc_clear_assign(
1406
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   387
        ec_fsm_slave_config_t *fsm /**< slave state machine */
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   388
        )
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   389
{
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   390
    ec_datagram_t *datagram = fsm->datagram;
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   391
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   392
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   393
        return;
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   394
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   395
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   396
        fsm->state = ec_fsm_slave_config_state_error;
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   397
        EC_ERR("Failed receive DC assignment clearing datagram"
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   398
                " for slave %u.\n", fsm->slave->ring_position);
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   399
        return;
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   400
    }
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   401
1407
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   402
    if (fsm->slave->master->debug_level && datagram->working_counter != 1) {
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   403
        // clearing the DC assignment does not succeed on simple slaves
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   404
        EC_DBG("Failed to clear DC assignment of slave %u: ",
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   405
               fsm->slave->ring_position);
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   406
        ec_datagram_print_wc_error(datagram);
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   407
    }
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   408
1889
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   409
    // read DC system time (0x0910, 64 bit)
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   410
    //                         gap (64 bit)
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   411
    //     and time offset (0x0920, 64 bit)
1407
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   412
    ec_datagram_fprd(fsm->datagram, fsm->slave->station_address, 0x0910, 24);
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   413
    fsm->retries = EC_FSM_RETRIES;
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   414
    fsm->state = ec_fsm_slave_config_state_dc_read_offset;
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   415
}
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   416
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   417
/*****************************************************************************/
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   418
1889
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   419
/** Configure 32 bit time offset.
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   420
 */
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   421
u64 ec_fsm_slave_config_dc_offset32(
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   422
        ec_fsm_slave_config_t *fsm, /**< slave state machine */
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   423
        u64 system_time, /**< System time register. */
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   424
        u64 old_offset, /**< Time offset register. */
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   425
        unsigned long jiffies_since_read /**< Jiffies for correction. */
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   426
        )
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   427
{
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   428
    ec_slave_t *slave = fsm->slave;
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   429
    u32 correction, system_time32, old_offset32, new_offset;
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   430
    s32 time_diff;
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   431
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   432
    system_time32 = (u32) system_time;
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   433
    old_offset32 = (u32) old_offset;
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   434
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   435
    // correct read system time by elapsed time since read operation
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   436
    correction = jiffies_since_read * 1000 / HZ * 1000000;
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   437
    system_time32 += correction;
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   438
    time_diff = (u32) slave->master->app_time - system_time32;
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   439
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   440
    if (slave->master->debug_level)
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   441
        EC_DBG("Slave %u: system_time=%u (corrected with %u),"
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   442
                " app_time=%u, diff=%i\n",
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   443
                slave->ring_position, system_time32, correction,
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   444
                (u32) slave->master->app_time, time_diff);
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   445
1904
2fadf016d9be Moved ABS() macro to globals.
Florian Pose <fp@igh-essen.com>
parents: 1896
diff changeset
   446
    if (EC_ABS(time_diff) > EC_SYSTEM_TIME_TOLERANCE_NS) {
1889
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   447
        new_offset = time_diff + old_offset32;
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   448
        if (slave->master->debug_level)
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   449
            EC_DBG("Slave %u: Setting time offset to %u (was %u)\n",
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   450
                    slave->ring_position, new_offset, old_offset32);
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   451
        return (u64) new_offset;
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   452
    } else {
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   453
        if (slave->master->debug_level)
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   454
            EC_DBG("Slave %u: Not touching time offset.\n",
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   455
                    slave->ring_position);
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   456
        return old_offset;
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   457
    }
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   458
}
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   459
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   460
/*****************************************************************************/
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   461
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   462
/** Configure 64 bit time offset.
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   463
 */
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   464
u64 ec_fsm_slave_config_dc_offset64(
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   465
        ec_fsm_slave_config_t *fsm, /**< slave state machine */
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   466
        u64 system_time, /**< System time register. */
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   467
        u64 old_offset, /**< Time offset register. */
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   468
        unsigned long jiffies_since_read /**< Jiffies for correction. */
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   469
        )
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   470
{
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   471
    ec_slave_t *slave = fsm->slave;
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   472
    u64 new_offset, correction;
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   473
    s64 time_diff;
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   474
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   475
    // correct read system time by elapsed time since read operation
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   476
    correction = (u64) (jiffies_since_read * 1000 / HZ) * 1000000;
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   477
    system_time += correction;
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   478
    time_diff = fsm->slave->master->app_time - system_time;
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   479
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   480
    if (slave->master->debug_level)
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   481
        EC_DBG("Slave %u: system_time=%llu (corrected with %llu),"
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   482
                " app_time=%llu, diff=%lli\n",
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   483
                slave->ring_position, system_time, correction,
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   484
                slave->master->app_time, time_diff);
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   485
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   486
1904
2fadf016d9be Moved ABS() macro to globals.
Florian Pose <fp@igh-essen.com>
parents: 1896
diff changeset
   487
    if (EC_ABS(time_diff) > EC_SYSTEM_TIME_TOLERANCE_NS) {
1889
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   488
        new_offset = time_diff + old_offset;
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   489
        if (slave->master->debug_level)
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   490
            EC_DBG("Slave %u: Setting time offset to %llu (was %llu)\n",
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   491
                    slave->ring_position, new_offset, old_offset);
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   492
    } else {
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   493
        new_offset = old_offset;
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   494
        if (slave->master->debug_level)
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   495
            EC_DBG("Slave %u: Not touching time offset.\n",
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   496
                    slave->ring_position);
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   497
    }
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   498
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   499
    return new_offset;
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   500
}
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   501
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   502
/*****************************************************************************/
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   503
1407
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   504
/** Slave configuration state: DC READ OFFSET.
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   505
 */
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   506
void ec_fsm_slave_config_state_dc_read_offset(
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   507
        ec_fsm_slave_config_t *fsm /**< slave state machine */
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   508
        )
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   509
{
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   510
    ec_datagram_t *datagram = fsm->datagram;
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   511
    ec_slave_t *slave = fsm->slave;
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   512
    u64 system_time, old_offset, new_offset;
1889
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   513
    unsigned long jiffies_since_read;
1407
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   514
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   515
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   516
        return;
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   517
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   518
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   519
        fsm->state = ec_fsm_slave_config_state_error;
1822
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1520
diff changeset
   520
        EC_ERR("Failed to receive DC times datagram for slave %u: ",
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1520
diff changeset
   521
                slave->ring_position);
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1520
diff changeset
   522
        ec_datagram_print_state(datagram);
1407
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   523
        return;
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   524
    }
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   525
1406
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   526
    if (datagram->working_counter != 1) {
1407
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   527
        slave->error_flag = 1;
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   528
        fsm->state = ec_fsm_slave_config_state_error;
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   529
        EC_ERR("Failed to get DC times of slave %u: ",
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   530
                slave->ring_position);
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   531
        ec_datagram_print_wc_error(datagram);
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   532
        return;
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   533
    }
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   534
1889
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   535
    system_time = EC_READ_U64(datagram->data);     // 0x0910
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   536
    old_offset = EC_READ_U64(datagram->data + 16); // 0x0920
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   537
    jiffies_since_read = jiffies - datagram->jiffies_sent;
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   538
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   539
    if (slave->base_dc_range == EC_DC_32) {
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   540
        new_offset = ec_fsm_slave_config_dc_offset32(fsm,
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   541
                system_time, old_offset, jiffies_since_read);
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   542
    } else {
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   543
        new_offset = ec_fsm_slave_config_dc_offset64(fsm,
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   544
                system_time, old_offset, jiffies_since_read);
131f655c03d3 Improved DC tome offset calculation:
Florian Pose <fp@igh-essen.com>
parents: 1873
diff changeset
   545
    }
1407
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   546
1430
97ab86a9b1d7 Set system time transmission delay during config.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   547
    // set DC system time offset and transmission delay
97ab86a9b1d7 Set system time transmission delay during config.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   548
    ec_datagram_fpwr(datagram, slave->station_address, 0x0920, 12);
1407
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   549
    EC_WRITE_U64(datagram->data, new_offset);
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1491
diff changeset
   550
    EC_WRITE_U32(datagram->data + 8, slave->transmission_delay);
1407
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   551
    fsm->retries = EC_FSM_RETRIES;
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   552
    fsm->state = ec_fsm_slave_config_state_dc_write_offset;
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   553
}
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   554
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   555
/*****************************************************************************/
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   556
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   557
/** Slave configuration state: DC WRITE OFFSET.
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   558
 */
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   559
void ec_fsm_slave_config_state_dc_write_offset(
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   560
        ec_fsm_slave_config_t *fsm /**< slave state machine */
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   561
        )
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   562
{
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   563
    ec_datagram_t *datagram = fsm->datagram;
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   564
    ec_slave_t *slave = fsm->slave;
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   565
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   566
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   567
        return;
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   568
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   569
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   570
        fsm->state = ec_fsm_slave_config_state_error;
1822
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1520
diff changeset
   571
        EC_ERR("Failed to receive DC system time offset datagram for"
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1520
diff changeset
   572
                " slave %u: ", slave->ring_position);
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1520
diff changeset
   573
        ec_datagram_print_state(datagram);
1407
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   574
        return;
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   575
    }
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   576
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   577
    if (datagram->working_counter != 1) {
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   578
        slave->error_flag = 1;
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   579
        fsm->state = ec_fsm_slave_config_state_error;
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   580
        EC_ERR("Failed to set DC system time offset of slave %u: ",
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
   581
                slave->ring_position);
1406
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   582
        ec_datagram_print_wc_error(datagram);
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   583
        return;
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   584
    }
8686c5b3d14b Clear DC assignment after going to INIT.
Florian Pose <fp@igh-essen.com>
parents: 1404
diff changeset
   585
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   586
    ec_fsm_slave_config_enter_mbox_sync(fsm);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   587
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   588
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   589
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   590
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   591
/** Check for mailbox sync managers to be configured.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   592
 */
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   593
void ec_fsm_slave_config_enter_mbox_sync(
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   594
        ec_fsm_slave_config_t *fsm /**< slave state machine */
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   595
        )
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   596
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   597
    ec_master_t *master = fsm->slave->master;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   598
    ec_slave_t *slave = fsm->slave;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   599
    ec_datagram_t *datagram = fsm->datagram;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   600
    unsigned int i;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   601
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   602
    // slave is now in INIT
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   603
    if (slave->current_state == slave->requested_state) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   604
        fsm->state = ec_fsm_slave_config_state_end; // successful
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   605
        if (master->debug_level) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   606
            EC_DBG("Finished configuration of slave %u.\n",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   607
                   slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   608
        }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   609
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   610
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   611
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   612
    if (!slave->sii.mailbox_protocols) {
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   613
        // no mailbox protocols supported
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   614
        if (master->debug_level)
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   615
            EC_DBG("Slave %u does not support mailbox communication.\n",
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   616
                    slave->ring_position);
1337
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   617
        ec_fsm_slave_config_enter_boot_preop(fsm);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   618
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   619
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   620
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   621
    if (master->debug_level) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   622
        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
   623
               slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   624
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   625
1337
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   626
    if (slave->requested_state == EC_SLAVE_STATE_BOOT) {
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   627
        ec_sync_t sync;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   628
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   629
        ec_datagram_fpwr(datagram, slave->station_address, 0x0800,
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   630
                EC_SYNC_PAGE_SIZE * 2);
1896
1d4bca6ba543 Use ec_datagram_zero() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1889
diff changeset
   631
        ec_datagram_zero(datagram);
1337
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   632
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   633
        ec_sync_init(&sync, slave);
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   634
        sync.physical_start_address = slave->sii.boot_rx_mailbox_offset;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   635
        sync.control_register = 0x26;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   636
        sync.enable = 1;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   637
        ec_sync_page(&sync, 0, slave->sii.boot_rx_mailbox_size,
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   638
                EC_DIR_INVALID, // use default direction
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   639
                datagram->data);
1338
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   640
        slave->configured_rx_mailbox_offset =
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   641
            slave->sii.boot_rx_mailbox_offset;
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   642
        slave->configured_rx_mailbox_size =
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   643
            slave->sii.boot_rx_mailbox_size;
1337
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   644
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   645
        ec_sync_init(&sync, slave);
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   646
        sync.physical_start_address = slave->sii.boot_tx_mailbox_offset;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   647
        sync.control_register = 0x22;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   648
        sync.enable = 1;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   649
        ec_sync_page(&sync, 1, slave->sii.boot_tx_mailbox_size,
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   650
                EC_DIR_INVALID, // use default direction
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   651
                datagram->data + EC_SYNC_PAGE_SIZE);
1338
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   652
        slave->configured_tx_mailbox_offset =
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   653
            slave->sii.boot_tx_mailbox_offset;
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   654
        slave->configured_tx_mailbox_size =
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   655
            slave->sii.boot_tx_mailbox_size;
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   656
1337
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   657
    } else if (slave->sii.sync_count >= 2) { // mailbox configuration provided
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   658
        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
   659
                EC_SYNC_PAGE_SIZE * slave->sii.sync_count);
1225
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1180
diff changeset
   660
        ec_datagram_zero(datagram);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   661
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   662
        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
   663
            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
   664
                    slave->sii.syncs[i].default_length,
1509
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
   665
                    NULL, // use default sync manager configuration
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   666
                    datagram->data + EC_SYNC_PAGE_SIZE * i);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   667
        }
1338
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   668
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   669
        slave->configured_rx_mailbox_offset =
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   670
            slave->sii.syncs[0].physical_start_address;
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   671
        slave->configured_rx_mailbox_size =
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   672
            slave->sii.syncs[0].default_length;
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   673
        slave->configured_tx_mailbox_offset =
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   674
            slave->sii.syncs[1].physical_start_address;
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   675
        slave->configured_tx_mailbox_size =
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   676
            slave->sii.syncs[1].default_length;
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   677
    } else { // no mailbox sync manager configurations provided
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   678
        ec_sync_t sync;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   679
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   680
        if (master->debug_level)
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   681
            EC_DBG("Slave %u does not provide"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   682
                    " mailbox sync manager configurations.\n",
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   683
                    slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   684
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   685
        ec_datagram_fpwr(datagram, slave->station_address, 0x0800,
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   686
                EC_SYNC_PAGE_SIZE * 2);
1225
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1180
diff changeset
   687
        ec_datagram_zero(datagram);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   688
1055
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   689
        ec_sync_init(&sync, slave);
1337
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   690
        sync.physical_start_address = slave->sii.std_rx_mailbox_offset;
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   691
        sync.control_register = 0x26;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   692
        sync.enable = 1;
1337
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   693
        ec_sync_page(&sync, 0, slave->sii.std_rx_mailbox_size,
1509
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
   694
                NULL, // use default sync manager configuration
1055
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   695
                datagram->data);
1338
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   696
        slave->configured_rx_mailbox_offset =
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   697
            slave->sii.std_rx_mailbox_offset;
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   698
        slave->configured_rx_mailbox_size =
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   699
            slave->sii.std_rx_mailbox_size;
1055
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   700
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   701
        ec_sync_init(&sync, slave);
1337
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   702
        sync.physical_start_address = slave->sii.std_tx_mailbox_offset;
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   703
        sync.control_register = 0x22;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   704
        sync.enable = 1;
1337
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   705
        ec_sync_page(&sync, 1, slave->sii.std_tx_mailbox_size,
1509
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
   706
                NULL, // use default sync manager configuration
1055
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
   707
                datagram->data + EC_SYNC_PAGE_SIZE);
1338
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   708
        slave->configured_tx_mailbox_offset =
1471
2ec173081b7f Fixed mailbox usage for slaves that do not provide sync manager
Florian Pose <fp@igh-essen.com>
parents: 1458
diff changeset
   709
            slave->sii.std_tx_mailbox_offset;
1338
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   710
        slave->configured_tx_mailbox_size =
1471
2ec173081b7f Fixed mailbox usage for slaves that do not provide sync manager
Florian Pose <fp@igh-essen.com>
parents: 1458
diff changeset
   711
            slave->sii.std_tx_mailbox_size;
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   712
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   713
1347
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   714
    fsm->take_time = 1;
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   715
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   716
    fsm->retries = EC_FSM_RETRIES;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   717
    fsm->state = ec_fsm_slave_config_state_mbox_sync;
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
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   721
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   722
/** Slave configuration state: SYNC.
1345
Florian Pose <fp@igh-essen.com>
parents: 1344
diff changeset
   723
 *
Florian Pose <fp@igh-essen.com>
parents: 1344
diff changeset
   724
 * \todo Timeout for response.
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   725
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   726
void ec_fsm_slave_config_state_mbox_sync(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   727
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   728
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   729
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   730
    ec_datagram_t *datagram = fsm->datagram;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   731
    ec_slave_t *slave = fsm->slave;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   732
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   733
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   734
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   735
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   736
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   737
        fsm->state = ec_fsm_slave_config_state_error;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   738
        EC_ERR("Failed to receive sync manager configuration datagram for"
1822
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1520
diff changeset
   739
               " slave %u: ", slave->ring_position);
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1520
diff changeset
   740
        ec_datagram_print_state(datagram);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   741
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   742
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   743
1347
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   744
    if (fsm->take_time) {
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   745
        fsm->take_time = 0;
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   746
        fsm->jiffies_start = datagram->jiffies_sent;
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   747
    }
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   748
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   749
    /* Because the sync manager configurations are cleared during the last
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   750
     * cycle, some slaves do not immediately respond to the mailbox sync
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   751
     * manager configuration datagram. Therefore, resend the datagram for
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   752
     * a certain time, if the slave does not respond.
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   753
     */
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   754
    if (datagram->working_counter == 0) {
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   755
        unsigned long diff = datagram->jiffies_received - fsm->jiffies_start;
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   756
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   757
        if (diff >= HZ) {
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   758
            slave->error_flag = 1;
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   759
            fsm->state = ec_fsm_slave_config_state_error;
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   760
            EC_ERR("Timeout while configuring mailbox sync managers of"
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   761
                    " slave %u.\n", slave->ring_position);
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   762
            return;
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   763
        }
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   764
        else if (slave->master->debug_level) {
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   765
            EC_DBG("Resending after %u ms...\n",
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   766
                    (unsigned int) diff * 1000 / HZ);
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   767
        }
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   768
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   769
        // send configuration datagram again
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   770
        fsm->retries = EC_FSM_RETRIES;
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   771
        return;
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   772
    }
41360ffdcb14 Allow the slave to not respond to the mailbox sync manager configuration
Florian Pose <fp@igh-essen.com>
parents: 1345
diff changeset
   773
    else if (datagram->working_counter != 1) {
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   774
        slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   775
        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
   776
        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
   777
               slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   778
        ec_datagram_print_wc_error(datagram);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   779
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   780
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   781
1337
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   782
    ec_fsm_slave_config_enter_boot_preop(fsm);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   783
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   784
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   785
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   786
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   787
/** Request PREOP state.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   788
 */
1337
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   789
void ec_fsm_slave_config_enter_boot_preop(
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   790
        ec_fsm_slave_config_t *fsm /**< slave state machine */
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   791
        )
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   792
{
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   793
    fsm->state = ec_fsm_slave_config_state_boot_preop;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   794
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   795
    if (fsm->slave->requested_state != EC_SLAVE_STATE_BOOT) {
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   796
        ec_fsm_change_start(fsm->fsm_change, fsm->slave, EC_SLAVE_STATE_PREOP);
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   797
    } else { // BOOT
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   798
        ec_fsm_change_start(fsm->fsm_change, fsm->slave, EC_SLAVE_STATE_BOOT);
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   799
    }
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   800
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   801
    ec_fsm_change_exec(fsm->fsm_change); // execute immediately
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   802
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   803
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   804
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   805
1337
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   806
/** Slave configuration state: BOOT/PREOP.
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   807
 */
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   808
void ec_fsm_slave_config_state_boot_preop(
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   809
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   810
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   811
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   812
    ec_slave_t *slave = fsm->slave;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   813
    ec_master_t *master = fsm->slave->master;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   814
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   815
    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
   816
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   817
    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
   818
        if (!fsm->fsm_change->spontaneous_change)
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   819
            slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   820
        fsm->state = ec_fsm_slave_config_state_error;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   821
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   822
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   823
1404
b7ea043d5081 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 1396
diff changeset
   824
    // slave is now in BOOT or PREOP
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   825
    slave->jiffies_preop = fsm->datagram->jiffies_received;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   826
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   827
    if (master->debug_level) {
1337
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   828
        EC_DBG("Slave %u is now in %s.\n", slave->ring_position,
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   829
                slave->requested_state != EC_SLAVE_STATE_BOOT
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   830
                ? "PREOP" : "BOOT");
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   831
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   832
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   833
    if (slave->current_state == slave->requested_state) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   834
        fsm->state = ec_fsm_slave_config_state_end; // successful
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   835
        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
   836
            EC_DBG("Finished configuration of slave %u.\n",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   837
                   slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   838
        }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   839
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   840
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   841
1491
40529f2f60bd Configure PDO sync managers even if no configuration has been applied.
Florian Pose <fp@igh-essen.com>
parents: 1471
diff changeset
   842
    ec_fsm_slave_config_enter_sdo_conf(fsm);
40529f2f60bd Configure PDO sync managers even if no configuration has been applied.
Florian Pose <fp@igh-essen.com>
parents: 1471
diff changeset
   843
}
40529f2f60bd Configure PDO sync managers even if no configuration has been applied.
Florian Pose <fp@igh-essen.com>
parents: 1471
diff changeset
   844
40529f2f60bd Configure PDO sync managers even if no configuration has been applied.
Florian Pose <fp@igh-essen.com>
parents: 1471
diff changeset
   845
/*****************************************************************************/
40529f2f60bd Configure PDO sync managers even if no configuration has been applied.
Florian Pose <fp@igh-essen.com>
parents: 1471
diff changeset
   846
40529f2f60bd Configure PDO sync managers even if no configuration has been applied.
Florian Pose <fp@igh-essen.com>
parents: 1471
diff changeset
   847
/** Check for SDO configurations to be applied.
40529f2f60bd Configure PDO sync managers even if no configuration has been applied.
Florian Pose <fp@igh-essen.com>
parents: 1471
diff changeset
   848
 */
40529f2f60bd Configure PDO sync managers even if no configuration has been applied.
Florian Pose <fp@igh-essen.com>
parents: 1471
diff changeset
   849
void ec_fsm_slave_config_enter_sdo_conf(
40529f2f60bd Configure PDO sync managers even if no configuration has been applied.
Florian Pose <fp@igh-essen.com>
parents: 1471
diff changeset
   850
        ec_fsm_slave_config_t *fsm /**< slave state machine */
40529f2f60bd Configure PDO sync managers even if no configuration has been applied.
Florian Pose <fp@igh-essen.com>
parents: 1471
diff changeset
   851
        )
40529f2f60bd Configure PDO sync managers even if no configuration has been applied.
Florian Pose <fp@igh-essen.com>
parents: 1471
diff changeset
   852
{
40529f2f60bd Configure PDO sync managers even if no configuration has been applied.
Florian Pose <fp@igh-essen.com>
parents: 1471
diff changeset
   853
    ec_slave_t *slave = fsm->slave;
40529f2f60bd Configure PDO sync managers even if no configuration has been applied.
Florian Pose <fp@igh-essen.com>
parents: 1471
diff changeset
   854
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   855
    if (!slave->config) {
1491
40529f2f60bd Configure PDO sync managers even if no configuration has been applied.
Florian Pose <fp@igh-essen.com>
parents: 1471
diff changeset
   856
        ec_fsm_slave_config_enter_pdo_sync(fsm);
40529f2f60bd Configure PDO sync managers even if no configuration has been applied.
Florian Pose <fp@igh-essen.com>
parents: 1471
diff changeset
   857
        return;
40529f2f60bd Configure PDO sync managers even if no configuration has been applied.
Florian Pose <fp@igh-essen.com>
parents: 1471
diff changeset
   858
    }
888
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
   859
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   860
    // No CoE configuration to be applied?
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   861
    if (list_empty(&slave->config->sdo_configs)) { // skip SDO configuration
1844
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   862
        ec_fsm_slave_config_enter_soe_conf(fsm);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   863
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   864
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   865
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   866
    // start SDO configuration
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   867
    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
   868
    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
   869
            ec_sdo_request_t, list);
1318
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   870
    ec_sdo_request_copy(&fsm->request_copy, fsm->request);
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   871
    ecrt_sdo_request_write(&fsm->request_copy);
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   872
    ec_fsm_coe_transfer(fsm->fsm_coe, fsm->slave, &fsm->request_copy);
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   873
    ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   874
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   875
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   876
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   877
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   878
/** Slave configuration state: SDO_CONF.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   879
 */
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   880
void ec_fsm_slave_config_state_sdo_conf(
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   881
        ec_fsm_slave_config_t *fsm /**< slave state machine */
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   882
        )
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   883
{
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   884
    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
   885
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   886
    if (!ec_fsm_coe_success(fsm->fsm_coe)) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   887
        EC_ERR("SDO configuration failed for slave %u.\n",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   888
                fsm->slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   889
        fsm->slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   890
        fsm->state = ec_fsm_slave_config_state_error;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   891
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   892
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   893
1318
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   894
    if (!fsm->slave->config) { // config removed in the meantime
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   895
        ec_fsm_slave_config_reconfigure(fsm);
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   896
        return;
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   897
    }
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   898
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   899
    // 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
   900
    if (fsm->request->list.next != &fsm->slave->config->sdo_configs) {
1318
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   901
        fsm->request = list_entry(fsm->request->list.next,
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   902
                ec_sdo_request_t, list);
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   903
        ec_sdo_request_copy(&fsm->request_copy, fsm->request);
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   904
        ecrt_sdo_request_write(&fsm->request_copy);
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
   905
        ec_fsm_coe_transfer(fsm->fsm_coe, fsm->slave, &fsm->request_copy);
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
   906
        ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   907
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   908
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   909
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   910
    // All SDOs are now configured.
1873
219be3742274 Added missing queue_external_datagram(); removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1849
diff changeset
   911
    ec_fsm_slave_config_enter_soe_conf(fsm);
1844
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   912
}
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   913
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   914
/*****************************************************************************/
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   915
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   916
/** Check for SoE configurations to be applied.
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   917
 */
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   918
void ec_fsm_slave_config_enter_soe_conf(
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   919
        ec_fsm_slave_config_t *fsm /**< slave state machine */
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   920
        )
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   921
{
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   922
    ec_slave_t *slave = fsm->slave;
1873
219be3742274 Added missing queue_external_datagram(); removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1849
diff changeset
   923
    ec_fsm_soe_t *fsm_soe = &slave->fsm.fsm_soe;
1844
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   924
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   925
    if (!slave->config) {
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   926
        ec_fsm_slave_config_enter_pdo_sync(fsm);
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   927
        return;
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   928
    }
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   929
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   930
    // No SoE configuration to be applied?
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   931
    if (list_empty(&slave->config->soe_configs)) { // skip configuration
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   932
        ec_fsm_slave_config_enter_pdo_conf(fsm);
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   933
        return;
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   934
    }
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   935
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   936
    // start SoE configuration
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   937
    fsm->state = ec_fsm_slave_config_state_soe_conf;
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   938
    fsm->soe_request = list_entry(fsm->slave->config->soe_configs.next,
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   939
            ec_soe_request_t, list);
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   940
    ec_soe_request_copy(&fsm->soe_request_copy, fsm->soe_request);
1873
219be3742274 Added missing queue_external_datagram(); removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1849
diff changeset
   941
    ec_soe_request_write(&fsm->soe_request_copy);
1844
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   942
    ec_fsm_soe_transfer(fsm_soe, fsm->slave, &fsm->soe_request_copy);
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   943
    ec_fsm_soe_exec(fsm_soe); // execute immediately
1873
219be3742274 Added missing queue_external_datagram(); removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1849
diff changeset
   944
    ec_master_queue_external_datagram(slave->master, fsm_soe->datagram);
1844
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   945
}
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   946
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   947
/*****************************************************************************/
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   948
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   949
/** Slave configuration state: SOE_CONF.
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   950
 */
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   951
void ec_fsm_slave_config_state_soe_conf(
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   952
        ec_fsm_slave_config_t *fsm /**< slave state machine */
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   953
        )
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   954
{
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   955
    ec_slave_t *slave = fsm->slave;
1873
219be3742274 Added missing queue_external_datagram(); removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1849
diff changeset
   956
    ec_fsm_soe_t *fsm_soe = &slave->fsm.fsm_soe;
1844
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   957
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   958
    if (ec_fsm_soe_exec(fsm_soe)) {
1873
219be3742274 Added missing queue_external_datagram(); removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1849
diff changeset
   959
        ec_master_queue_external_datagram(slave->master, fsm_soe->datagram);
219be3742274 Added missing queue_external_datagram(); removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1849
diff changeset
   960
        return;
219be3742274 Added missing queue_external_datagram(); removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1849
diff changeset
   961
    }
1844
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   962
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   963
    if (!ec_fsm_soe_success(fsm_soe)) {
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   964
        EC_ERR("SoE configuration failed for slave %u.\n",
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   965
                fsm->slave->ring_position);
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   966
        fsm->slave->error_flag = 1;
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   967
        fsm->state = ec_fsm_slave_config_state_error;
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   968
        return;
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   969
    }
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   970
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   971
    if (!fsm->slave->config) { // config removed in the meantime
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   972
        ec_fsm_slave_config_reconfigure(fsm);
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   973
        return;
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   974
    }
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   975
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   976
    // Another IDN to configure?
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   977
    if (fsm->soe_request->list.next != &fsm->slave->config->soe_configs) {
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   978
        fsm->soe_request = list_entry(fsm->soe_request->list.next,
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   979
                ec_soe_request_t, list);
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   980
        ec_soe_request_copy(&fsm->soe_request_copy, fsm->soe_request);
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   981
        ec_soe_request_write(&fsm->soe_request_copy);
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   982
        ec_fsm_soe_transfer(fsm_soe, fsm->slave, &fsm->soe_request_copy);
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   983
        ec_fsm_soe_exec(fsm_soe); // execute immediately
1873
219be3742274 Added missing queue_external_datagram(); removed tabs.
Florian Pose <fp@igh-essen.com>
parents: 1849
diff changeset
   984
        ec_master_queue_external_datagram(slave->master, fsm_soe->datagram);
1844
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   985
        return;
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   986
    }
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   987
b6bd88d4806b Added ecrt_slave_config_idn() method to store SoE IDN configurations.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   988
    // 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
   989
    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
   990
}
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   991
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   992
/*****************************************************************************/
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   993
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   994
/** PDO_CONF entry function.
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   995
 */
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   996
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
   997
        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
   998
        )
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   999
{
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1000
    // Start configuring PDOs
1180
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
  1001
    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
  1002
    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
  1003
    fsm->state(fsm); // execute immediately
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
  1004
}
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
  1005
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
  1006
/*****************************************************************************/
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
  1007
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
  1008
/** Slave configuration state: PDO_CONF.
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
  1009
 */
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
  1010
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
  1011
        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
  1012
        )
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
  1013
{
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1491
diff changeset
  1014
    // TODO check for config here
1407
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1015
1180
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
  1016
    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
  1017
        return;
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
  1018
1318
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
  1019
    if (!fsm->slave->config) { // config removed in the meantime
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
  1020
        ec_fsm_slave_config_reconfigure(fsm);
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
  1021
        return;
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
  1022
    }
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
  1023
1180
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
  1024
    if (!ec_fsm_pdo_success(fsm->fsm_pdo)) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1025
        EC_WARN("PDO configuration failed on slave %u.\n",
1180
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
  1026
                fsm->slave->ring_position);
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
  1027
    }
846907b8cc4b Configure Pdos before configuring the Pdo sync managers,
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
  1028
1509
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1029
    ec_fsm_slave_config_enter_watchdog_divider(fsm);
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1030
}
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1031
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1032
/*****************************************************************************/
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1033
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1034
/** WATCHDOG_DIVIDER entry function.
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1035
 */
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1036
void ec_fsm_slave_config_enter_watchdog_divider(
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1037
        ec_fsm_slave_config_t *fsm /**< slave state machine */
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1038
        )
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1039
{
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1040
    ec_slave_t *slave = fsm->slave;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1041
    ec_datagram_t *datagram = fsm->datagram;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1042
    ec_master_t *master = slave->master;    
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1043
    ec_slave_config_t *config = slave->config;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1044
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1045
    if (config && config->watchdog_divider) {
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1046
        if (master->debug_level)
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1047
            EC_DBG("Setting watchdog divider to %u.\n",
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1048
                    config->watchdog_divider);
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1049
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1050
        ec_datagram_fpwr(datagram, slave->station_address, 0x0400, 2);
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1051
        EC_WRITE_U16(datagram->data, config->watchdog_divider);
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1052
        fsm->retries = EC_FSM_RETRIES;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1053
        fsm->state = ec_fsm_slave_config_state_watchdog_divider;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1054
    } else {
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1055
        ec_fsm_slave_config_enter_watchdog(fsm);
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1056
    }
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1057
}
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1058
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1059
/*****************************************************************************/
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1060
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1061
/** Slave configuration state: WATCHDOG_DIVIDER.
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1062
 */
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1063
void ec_fsm_slave_config_state_watchdog_divider(
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1064
        ec_fsm_slave_config_t *fsm /**< slave state machine */
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1065
        )
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1066
{
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1067
    ec_datagram_t *datagram = fsm->datagram;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1068
    ec_slave_t *slave = fsm->slave;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1069
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1070
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1071
        return;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1072
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1073
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1074
        fsm->state = ec_fsm_slave_config_state_error;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1075
        EC_ERR("Failed to receive watchdog divider configuration datagram for"
1822
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1520
diff changeset
  1076
               " slave %u: ", slave->ring_position);
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1520
diff changeset
  1077
        ec_datagram_print_state(datagram);
1509
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1078
        return;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1079
    }
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1080
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1081
    if (datagram->working_counter != 1) {
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1082
        slave->error_flag = 1;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1083
        EC_WARN("Failed to set watchdog divider of slave %u: ",
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1084
               slave->ring_position);
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1085
        ec_datagram_print_wc_error(datagram);
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1086
        return;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1087
    }
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1088
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1089
    ec_fsm_slave_config_enter_watchdog(fsm);
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1090
}
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1091
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1092
/*****************************************************************************/
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1093
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1094
/** WATCHDOG entry function
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1095
 */
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1096
void ec_fsm_slave_config_enter_watchdog(
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1097
        ec_fsm_slave_config_t *fsm /**< slave state machine */
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1098
        )
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1099
{
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1100
    ec_datagram_t *datagram = fsm->datagram;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1101
    ec_slave_t *slave = fsm->slave;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1102
    ec_slave_config_t *config = slave->config;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1103
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1104
    if (config && config->watchdog_intervals) {
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1105
        if (slave->master->debug_level)
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1106
            EC_DBG("Setting process data watchdog intervals to %u.\n",
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1107
                    config->watchdog_intervals);
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1108
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1109
        ec_datagram_fpwr(datagram, slave->station_address, 0x0420, 2);
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1110
        EC_WRITE_U16(datagram->data, config->watchdog_intervals);
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1111
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1112
        fsm->retries = EC_FSM_RETRIES;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1113
        fsm->state = ec_fsm_slave_config_state_watchdog;
1520
09cf61d61af0 Fixed setting watchdog intervals.
Florian Pose <fp@igh-essen.com>
parents: 1509
diff changeset
  1114
    } else {
09cf61d61af0 Fixed setting watchdog intervals.
Florian Pose <fp@igh-essen.com>
parents: 1509
diff changeset
  1115
        ec_fsm_slave_config_enter_pdo_sync(fsm);
09cf61d61af0 Fixed setting watchdog intervals.
Florian Pose <fp@igh-essen.com>
parents: 1509
diff changeset
  1116
    }
1509
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1117
}
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1118
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1119
/*****************************************************************************/
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1120
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1121
/** Slave configuration state: WATCHDOG.
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1122
 */
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1123
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1124
void ec_fsm_slave_config_state_watchdog(
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1125
        ec_fsm_slave_config_t *fsm /**< slave state machine */
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1126
        )
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1127
{
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1128
    ec_datagram_t *datagram = fsm->datagram;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1129
    ec_slave_t *slave = fsm->slave;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1130
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1131
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1132
        return;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1133
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1134
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1135
        fsm->state = ec_fsm_slave_config_state_error;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1136
        EC_ERR("Failed to receive sync manager watchdog configuration "
1822
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1520
diff changeset
  1137
                "datagram for slave %u: ", slave->ring_position);
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1520
diff changeset
  1138
        ec_datagram_print_state(datagram);
1509
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1139
        return;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1140
    }
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1141
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1142
    if (datagram->working_counter != 1) {
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1143
        EC_WARN("Failed to set process data watchdog intervals of slave %u: ",
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1144
               slave->ring_position);
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1145
        ec_datagram_print_wc_error(datagram);
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1146
    }
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1147
888
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1148
    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
  1149
}
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1150
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1151
/*****************************************************************************/
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1152
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1153
/** Check for PDO sync managers to be configured.
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1154
 */
888
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1155
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
  1156
        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
  1157
        )
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1158
{
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1159
    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
  1160
    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
  1161
    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
  1162
    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
  1163
    const ec_sync_t *sync;
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1164
    uint16_t size;
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1165
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1166
    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
  1167
        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
  1168
    } else {
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1169
        offset = 0;
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1170
    }
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1171
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1172
    if (slave->sii.sync_count <= offset) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1173
        // 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
  1174
        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
  1175
        return;
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1176
    }
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1177
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1178
    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
  1179
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1180
    // 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
  1181
    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
  1182
            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
  1183
            EC_SYNC_PAGE_SIZE * num_pdo_syncs);
1225
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1180
diff changeset
  1184
    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
  1185
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1186
    for (i = 0; i < num_pdo_syncs; i++) {
1509
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1187
        const ec_sync_config_t *sync_config;
1055
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1053
diff changeset
  1188
        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
  1189
        sync = &slave->sii.syncs[sync_index];
1491
40529f2f60bd Configure PDO sync managers even if no configuration has been applied.
Florian Pose <fp@igh-essen.com>
parents: 1471
diff changeset
  1190
40529f2f60bd Configure PDO sync managers even if no configuration has been applied.
Florian Pose <fp@igh-essen.com>
parents: 1471
diff changeset
  1191
        if (slave->config) {
40529f2f60bd Configure PDO sync managers even if no configuration has been applied.
Florian Pose <fp@igh-essen.com>
parents: 1471
diff changeset
  1192
            sync_config = &slave->config->sync_configs[sync_index];
40529f2f60bd Configure PDO sync managers even if no configuration has been applied.
Florian Pose <fp@igh-essen.com>
parents: 1471
diff changeset
  1193
            size = ec_pdo_list_total_size(&sync_config->pdos);
40529f2f60bd Configure PDO sync managers even if no configuration has been applied.
Florian Pose <fp@igh-essen.com>
parents: 1471
diff changeset
  1194
        } else {
1509
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1195
            sync_config = NULL;
1491
40529f2f60bd Configure PDO sync managers even if no configuration has been applied.
Florian Pose <fp@igh-essen.com>
parents: 1471
diff changeset
  1196
            size = sync->default_length;
40529f2f60bd Configure PDO sync managers even if no configuration has been applied.
Florian Pose <fp@igh-essen.com>
parents: 1471
diff changeset
  1197
        }
40529f2f60bd Configure PDO sync managers even if no configuration has been applied.
Florian Pose <fp@igh-essen.com>
parents: 1471
diff changeset
  1198
1509
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1199
        ec_sync_page(sync, sync_index, size, sync_config,
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1200
                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
  1201
    }
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1202
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1203
    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
  1204
    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
  1205
}
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1206
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1207
/*****************************************************************************/
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1208
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1209
/** Configure PDO sync managers.
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1210
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1211
void ec_fsm_slave_config_state_pdo_sync(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1212
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1213
        )
888
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1214
{
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1215
    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
  1216
    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
  1217
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1218
    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
  1219
        return;
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1220
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1221
    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
  1222
        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
  1223
        EC_ERR("Failed to receive process data sync manager configuration"
1822
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1520
diff changeset
  1224
               " datagram for slave %u: ", slave->ring_position);
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1520
diff changeset
  1225
        ec_datagram_print_state(datagram);
888
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1226
        return;
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1227
    }
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1228
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1229
    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
  1230
        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
  1231
        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
  1232
        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
  1233
                slave->ring_position);
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1234
        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
  1235
        return;
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1236
    }
f0db19108bba Moved Pdo sync manager configuration before Pdo assignment in slave
Florian Pose <fp@igh-essen.com>
parents: 879
diff changeset
  1237
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1238
    ec_fsm_slave_config_enter_fmmu(fsm);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1239
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1240
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1241
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1242
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1243
/** Check for FMMUs to be configured.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1244
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1245
void ec_fsm_slave_config_enter_fmmu(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1246
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1247
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1248
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1249
    ec_slave_t *slave = fsm->slave;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1250
    ec_datagram_t *datagram = fsm->datagram;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1251
    unsigned int i;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1252
    const ec_fmmu_config_t *fmmu;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1253
    const ec_sync_t *sync;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1254
1491
40529f2f60bd Configure PDO sync managers even if no configuration has been applied.
Florian Pose <fp@igh-essen.com>
parents: 1471
diff changeset
  1255
    if (!slave->config) {
40529f2f60bd Configure PDO sync managers even if no configuration has been applied.
Florian Pose <fp@igh-essen.com>
parents: 1471
diff changeset
  1256
        ec_fsm_slave_config_enter_safeop(fsm);
1407
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1257
        return;
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1258
    }
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1259
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1260
    if (slave->base_fmmu_count < slave->config->used_fmmus) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1261
        slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1262
        fsm->state = ec_fsm_slave_config_state_error;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1263
        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
  1264
                slave->ring_position, slave->base_fmmu_count,
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1265
                slave->config->used_fmmus);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1266
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1267
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1268
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1269
    if (!slave->base_fmmu_count) { // skip FMMU configuration
1407
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1270
        ec_fsm_slave_config_enter_dc_cycle(fsm);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1271
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1272
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1273
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1274
    // configure FMMUs
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1275
    ec_datagram_fpwr(datagram, slave->station_address,
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1276
                     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
  1277
    ec_datagram_zero(datagram);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1278
    for (i = 0; i < slave->config->used_fmmus; i++) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1279
        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
  1280
        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
  1281
            slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1282
            fsm->state = ec_fsm_slave_config_state_error;
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1283
            EC_ERR("Failed to determine PDO sync manager for FMMU on slave"
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1284
                    " %u!\n", slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1285
            return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1286
        }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1287
        ec_fmmu_config_page(fmmu, sync,
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1288
                datagram->data + EC_FMMU_PAGE_SIZE * i);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1289
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1290
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1291
    fsm->retries = EC_FSM_RETRIES;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1292
    fsm->state = ec_fsm_slave_config_state_fmmu;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1293
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1294
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1295
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1296
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1297
/** Slave configuration state: FMMU.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1298
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1299
void ec_fsm_slave_config_state_fmmu(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1300
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1301
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1302
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1303
    ec_datagram_t *datagram = fsm->datagram;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1304
    ec_slave_t *slave = fsm->slave;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1305
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1306
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1307
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1308
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1309
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1310
        fsm->state = ec_fsm_slave_config_state_error;
1822
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1520
diff changeset
  1311
        EC_ERR("Failed to receive FMMUs datagram for slave %u: ",
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1520
diff changeset
  1312
               slave->ring_position);
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1520
diff changeset
  1313
        ec_datagram_print_state(datagram);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1314
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1315
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1316
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1317
    if (datagram->working_counter != 1) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1318
        slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1319
        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
  1320
        EC_ERR("Failed to set FMMUs of slave %u: ",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1321
               slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1322
        ec_datagram_print_wc_error(datagram);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1323
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1324
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1325
1407
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1326
    ec_fsm_slave_config_enter_dc_cycle(fsm);
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1327
}
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1328
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1329
/*****************************************************************************/
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1330
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1331
/** Check for DC to be configured.
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1332
 */
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1333
void ec_fsm_slave_config_enter_dc_cycle(
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1334
        ec_fsm_slave_config_t *fsm /**< slave state machine */
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1335
        )
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1336
{
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1337
    ec_datagram_t *datagram = fsm->datagram;
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1338
    ec_slave_t *slave = fsm->slave;
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1339
    ec_slave_config_t *config = slave->config;
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1340
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1341
    if (!config) { // config removed in the meantime
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1342
        ec_fsm_slave_config_reconfigure(fsm);
1396
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1392
diff changeset
  1343
        return;
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1392
diff changeset
  1344
    }
1392
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1345
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1346
    if (config->dc_assign_activate) {
1419
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1412
diff changeset
  1347
        if (!slave->base_dc_supported || !slave->has_dc_system_time) {
1407
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1348
            EC_WARN("Slave %u seems not to support distributed clocks!\n",
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1349
                    slave->ring_position);
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1350
        }
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1351
1458
bba02b6a4492 Debugging output.
Florian Pose <fp@igh-essen.com>
parents: 1438
diff changeset
  1352
        if (slave->master->debug_level)
bba02b6a4492 Debugging output.
Florian Pose <fp@igh-essen.com>
parents: 1438
diff changeset
  1353
            EC_DBG("Slave %u: Setting DC cycle times to %u / %u.\n",
bba02b6a4492 Debugging output.
Florian Pose <fp@igh-essen.com>
parents: 1438
diff changeset
  1354
                    slave->ring_position,
bba02b6a4492 Debugging output.
Florian Pose <fp@igh-essen.com>
parents: 1438
diff changeset
  1355
                    config->dc_sync[0].cycle_time,
bba02b6a4492 Debugging output.
Florian Pose <fp@igh-essen.com>
parents: 1438
diff changeset
  1356
                    config->dc_sync[1].cycle_time);
bba02b6a4492 Debugging output.
Florian Pose <fp@igh-essen.com>
parents: 1438
diff changeset
  1357
1392
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1358
        // set DC cycle times
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1359
        ec_datagram_fpwr(datagram, slave->station_address, 0x09A0, 8);
1438
1d30b96bb04f Replaced ecrt_slave_config_dc_cycle_times() and ecrt_slave_config_dc_shift_times() by ecrt_slave_config_dc_sync_signals().
Florian Pose <fp@igh-essen.com>
parents: 1436
diff changeset
  1360
        EC_WRITE_U32(datagram->data, config->dc_sync[0].cycle_time);
1d30b96bb04f Replaced ecrt_slave_config_dc_cycle_times() and ecrt_slave_config_dc_shift_times() by ecrt_slave_config_dc_sync_signals().
Florian Pose <fp@igh-essen.com>
parents: 1436
diff changeset
  1361
        EC_WRITE_U32(datagram->data + 4, config->dc_sync[1].cycle_time);
1392
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1362
        fsm->retries = EC_FSM_RETRIES;
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1363
        fsm->state = ec_fsm_slave_config_state_dc_cycle;
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1364
    } else {
1404
b7ea043d5081 Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 1396
diff changeset
  1365
        // DC are unused
1396
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1392
diff changeset
  1366
        ec_fsm_slave_config_enter_safeop(fsm);
1392
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1367
    }
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1368
}
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1369
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1370
/*****************************************************************************/
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1371
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1372
/** Slave configuration state: DC CYCLE.
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1373
 */
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1374
void ec_fsm_slave_config_state_dc_cycle(
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1375
        ec_fsm_slave_config_t *fsm /**< slave state machine */
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1376
        )
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1377
{
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1378
    ec_datagram_t *datagram = fsm->datagram;
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1379
    ec_slave_t *slave = fsm->slave;
1436
08eaf72409bb Use application start time as a common reference for cyclic generation
Florian Pose <fp@igh-essen.com>
parents: 1430
diff changeset
  1380
    ec_master_t *master = slave->master;
1412
8f7bbbd3b7ac DC shift time working.
Florian Pose <fp@igh-essen.com>
parents: 1407
diff changeset
  1381
    ec_slave_config_t *config = slave->config;
1438
1d30b96bb04f Replaced ecrt_slave_config_dc_cycle_times() and ecrt_slave_config_dc_shift_times() by ecrt_slave_config_dc_sync_signals().
Florian Pose <fp@igh-essen.com>
parents: 1436
diff changeset
  1382
    ec_sync_signal_t *sync0 = &config->dc_sync[0];
1396
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1392
diff changeset
  1383
    u64 start_time;
1392
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1384
1412
8f7bbbd3b7ac DC shift time working.
Florian Pose <fp@igh-essen.com>
parents: 1407
diff changeset
  1385
    if (!config) { // config removed in the meantime
8f7bbbd3b7ac DC shift time working.
Florian Pose <fp@igh-essen.com>
parents: 1407
diff changeset
  1386
        ec_fsm_slave_config_reconfigure(fsm);
8f7bbbd3b7ac DC shift time working.
Florian Pose <fp@igh-essen.com>
parents: 1407
diff changeset
  1387
        return;
8f7bbbd3b7ac DC shift time working.
Florian Pose <fp@igh-essen.com>
parents: 1407
diff changeset
  1388
    }
8f7bbbd3b7ac DC shift time working.
Florian Pose <fp@igh-essen.com>
parents: 1407
diff changeset
  1389
1392
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1390
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1391
        return;
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1392
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1393
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1394
        fsm->state = ec_fsm_slave_config_state_error;
1822
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1520
diff changeset
  1395
        EC_ERR("Failed to receive DC cycle times datagram for slave %u: ",
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1520
diff changeset
  1396
                slave->ring_position);
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1520
diff changeset
  1397
        ec_datagram_print_state(datagram);
1392
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1398
        return;
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1399
    }
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1400
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1401
    if (datagram->working_counter != 1) {
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1402
        slave->error_flag = 1;
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1403
        fsm->state = ec_fsm_slave_config_state_error;
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1404
        EC_ERR("Failed to set DC cycle times of slave %u: ",
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1405
                slave->ring_position);
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1406
        ec_datagram_print_wc_error(datagram);
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1407
        return;
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1408
    }
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1409
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1410
    // set DC start time
1436
08eaf72409bb Use application start time as a common reference for cyclic generation
Florian Pose <fp@igh-essen.com>
parents: 1430
diff changeset
  1411
    start_time = master->app_time + 100000000ULL; // now + X ns
08eaf72409bb Use application start time as a common reference for cyclic generation
Florian Pose <fp@igh-essen.com>
parents: 1430
diff changeset
  1412
    // FIXME use slave's local system time here?
08eaf72409bb Use application start time as a common reference for cyclic generation
Florian Pose <fp@igh-essen.com>
parents: 1430
diff changeset
  1413
1438
1d30b96bb04f Replaced ecrt_slave_config_dc_cycle_times() and ecrt_slave_config_dc_shift_times() by ecrt_slave_config_dc_sync_signals().
Florian Pose <fp@igh-essen.com>
parents: 1436
diff changeset
  1414
    if (sync0->cycle_time) {
1436
08eaf72409bb Use application start time as a common reference for cyclic generation
Florian Pose <fp@igh-essen.com>
parents: 1430
diff changeset
  1415
        // find correct phase
08eaf72409bb Use application start time as a common reference for cyclic generation
Florian Pose <fp@igh-essen.com>
parents: 1430
diff changeset
  1416
        if (master->has_start_time) {
1438
1d30b96bb04f Replaced ecrt_slave_config_dc_cycle_times() and ecrt_slave_config_dc_shift_times() by ecrt_slave_config_dc_sync_signals().
Florian Pose <fp@igh-essen.com>
parents: 1436
diff changeset
  1417
            u64 diff, start;
1d30b96bb04f Replaced ecrt_slave_config_dc_cycle_times() and ecrt_slave_config_dc_shift_times() by ecrt_slave_config_dc_sync_signals().
Florian Pose <fp@igh-essen.com>
parents: 1436
diff changeset
  1418
            u32 remainder;
1d30b96bb04f Replaced ecrt_slave_config_dc_cycle_times() and ecrt_slave_config_dc_shift_times() by ecrt_slave_config_dc_sync_signals().
Florian Pose <fp@igh-essen.com>
parents: 1436
diff changeset
  1419
1436
08eaf72409bb Use application start time as a common reference for cyclic generation
Florian Pose <fp@igh-essen.com>
parents: 1430
diff changeset
  1420
            diff = start_time - master->app_start_time;
1438
1d30b96bb04f Replaced ecrt_slave_config_dc_cycle_times() and ecrt_slave_config_dc_shift_times() by ecrt_slave_config_dc_sync_signals().
Florian Pose <fp@igh-essen.com>
parents: 1436
diff changeset
  1421
            remainder = do_div(diff, sync0->cycle_time);
1d30b96bb04f Replaced ecrt_slave_config_dc_cycle_times() and ecrt_slave_config_dc_shift_times() by ecrt_slave_config_dc_sync_signals().
Florian Pose <fp@igh-essen.com>
parents: 1436
diff changeset
  1422
1d30b96bb04f Replaced ecrt_slave_config_dc_cycle_times() and ecrt_slave_config_dc_shift_times() by ecrt_slave_config_dc_sync_signals().
Florian Pose <fp@igh-essen.com>
parents: 1436
diff changeset
  1423
            start = start_time +
1d30b96bb04f Replaced ecrt_slave_config_dc_cycle_times() and ecrt_slave_config_dc_shift_times() by ecrt_slave_config_dc_sync_signals().
Florian Pose <fp@igh-essen.com>
parents: 1436
diff changeset
  1424
                sync0->cycle_time - remainder + sync0->shift_time;
1436
08eaf72409bb Use application start time as a common reference for cyclic generation
Florian Pose <fp@igh-essen.com>
parents: 1430
diff changeset
  1425
08eaf72409bb Use application start time as a common reference for cyclic generation
Florian Pose <fp@igh-essen.com>
parents: 1430
diff changeset
  1426
            if (master->debug_level) {
08eaf72409bb Use application start time as a common reference for cyclic generation
Florian Pose <fp@igh-essen.com>
parents: 1430
diff changeset
  1427
                EC_DBG("app_start_time=%llu\n", master->app_start_time);
08eaf72409bb Use application start time as a common reference for cyclic generation
Florian Pose <fp@igh-essen.com>
parents: 1430
diff changeset
  1428
                EC_DBG("    start_time=%llu\n", start_time);
1438
1d30b96bb04f Replaced ecrt_slave_config_dc_cycle_times() and ecrt_slave_config_dc_shift_times() by ecrt_slave_config_dc_sync_signals().
Florian Pose <fp@igh-essen.com>
parents: 1436
diff changeset
  1429
                EC_DBG("    cycle_time=%u\n", sync0->cycle_time);
1d30b96bb04f Replaced ecrt_slave_config_dc_cycle_times() and ecrt_slave_config_dc_shift_times() by ecrt_slave_config_dc_sync_signals().
Florian Pose <fp@igh-essen.com>
parents: 1436
diff changeset
  1430
                EC_DBG("    shift_time=%u\n", sync0->shift_time);
1436
08eaf72409bb Use application start time as a common reference for cyclic generation
Florian Pose <fp@igh-essen.com>
parents: 1430
diff changeset
  1431
                EC_DBG("     remainder=%u\n", remainder);
08eaf72409bb Use application start time as a common reference for cyclic generation
Florian Pose <fp@igh-essen.com>
parents: 1430
diff changeset
  1432
                EC_DBG("         start=%llu\n", start);
08eaf72409bb Use application start time as a common reference for cyclic generation
Florian Pose <fp@igh-essen.com>
parents: 1430
diff changeset
  1433
            }
08eaf72409bb Use application start time as a common reference for cyclic generation
Florian Pose <fp@igh-essen.com>
parents: 1430
diff changeset
  1434
            start_time = start;
08eaf72409bb Use application start time as a common reference for cyclic generation
Florian Pose <fp@igh-essen.com>
parents: 1430
diff changeset
  1435
        } else {
08eaf72409bb Use application start time as a common reference for cyclic generation
Florian Pose <fp@igh-essen.com>
parents: 1430
diff changeset
  1436
            EC_WARN("No application time supplied. Cyclic start time will "
1458
bba02b6a4492 Debugging output.
Florian Pose <fp@igh-essen.com>
parents: 1438
diff changeset
  1437
                    "not be in phase for slave %u.\n", slave->ring_position);
1436
08eaf72409bb Use application start time as a common reference for cyclic generation
Florian Pose <fp@igh-essen.com>
parents: 1430
diff changeset
  1438
        }
08eaf72409bb Use application start time as a common reference for cyclic generation
Florian Pose <fp@igh-essen.com>
parents: 1430
diff changeset
  1439
    }
08eaf72409bb Use application start time as a common reference for cyclic generation
Florian Pose <fp@igh-essen.com>
parents: 1430
diff changeset
  1440
08eaf72409bb Use application start time as a common reference for cyclic generation
Florian Pose <fp@igh-essen.com>
parents: 1430
diff changeset
  1441
    if (master->debug_level)
1396
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1392
diff changeset
  1442
        EC_DBG("Slave %u: Setting DC cyclic operation start time to %llu.\n",
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1392
diff changeset
  1443
                slave->ring_position, start_time);
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1392
diff changeset
  1444
1392
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1445
    ec_datagram_fpwr(datagram, slave->station_address, 0x0990, 8);
1396
9d04cc08f40f DC sync reference clock to application time. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1392
diff changeset
  1446
    EC_WRITE_U64(datagram->data, start_time);
1392
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1447
    fsm->retries = EC_FSM_RETRIES;
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1448
    fsm->state = ec_fsm_slave_config_state_dc_start;
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1449
}
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1450
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1451
/*****************************************************************************/
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1452
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1453
/** Slave configuration state: DC START.
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1454
 */
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1455
void ec_fsm_slave_config_state_dc_start(
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1456
        ec_fsm_slave_config_t *fsm /**< slave state machine */
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1457
        )
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1458
{
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1459
    ec_datagram_t *datagram = fsm->datagram;
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1460
    ec_slave_t *slave = fsm->slave;
1407
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1461
    ec_slave_config_t *config = slave->config;
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1462
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1463
    if (!config) { // config removed in the meantime
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1464
        ec_fsm_slave_config_reconfigure(fsm);
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1465
        return;
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1466
    }
1392
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1467
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1468
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1469
        return;
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1470
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1471
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1472
        fsm->state = ec_fsm_slave_config_state_error;
1822
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1520
diff changeset
  1473
        EC_ERR("Failed to receive DC start time datagram for slave %u: ",
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1520
diff changeset
  1474
                slave->ring_position);
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1520
diff changeset
  1475
        ec_datagram_print_state(datagram);
1392
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1476
        return;
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1477
    }
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1478
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1479
    if (datagram->working_counter != 1) {
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1480
        slave->error_flag = 1;
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1481
        fsm->state = ec_fsm_slave_config_state_error;
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1482
        EC_ERR("Failed to set DC start time of slave %u: ",
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1483
                slave->ring_position);
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1484
        ec_datagram_print_wc_error(datagram);
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1485
        return;
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1486
    }
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1487
1458
bba02b6a4492 Debugging output.
Florian Pose <fp@igh-essen.com>
parents: 1438
diff changeset
  1488
    if (slave->master->debug_level)
bba02b6a4492 Debugging output.
Florian Pose <fp@igh-essen.com>
parents: 1438
diff changeset
  1489
        EC_DBG("Slave %u: Setting DC AssignActivate to 0x%04x.\n",
bba02b6a4492 Debugging output.
Florian Pose <fp@igh-essen.com>
parents: 1438
diff changeset
  1490
                slave->ring_position, config->dc_assign_activate);
bba02b6a4492 Debugging output.
Florian Pose <fp@igh-essen.com>
parents: 1438
diff changeset
  1491
1392
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1492
    // assign sync unit to EtherCAT or PDI
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1493
    ec_datagram_fpwr(datagram, slave->station_address, 0x0980, 2);
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1494
    EC_WRITE_U16(datagram->data, config->dc_assign_activate);
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1495
    fsm->retries = EC_FSM_RETRIES;
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1496
    fsm->state = ec_fsm_slave_config_state_dc_assign;
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1497
}
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1498
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1499
/*****************************************************************************/
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1500
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1501
/** Slave configuration state: DC ASSIGN.
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1502
 */
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1503
void ec_fsm_slave_config_state_dc_assign(
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1504
        ec_fsm_slave_config_t *fsm /**< slave state machine */
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1505
        )
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1506
{
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1507
    ec_datagram_t *datagram = fsm->datagram;
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1508
    ec_slave_t *slave = fsm->slave;
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1509
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1510
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1511
        return;
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1512
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1513
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1514
        fsm->state = ec_fsm_slave_config_state_error;
1822
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1520
diff changeset
  1515
        EC_ERR("Failed to receive DC activation datagram for slave %u: ",
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1520
diff changeset
  1516
                slave->ring_position);
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1520
diff changeset
  1517
        ec_datagram_print_state(datagram);
1392
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1518
        return;
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1519
    }
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1520
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1521
    if (datagram->working_counter != 1) {
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1522
        slave->error_flag = 1;
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1523
        fsm->state = ec_fsm_slave_config_state_error;
1407
e3974f72d31e Improved DC configuration.
Florian Pose <fp@igh-essen.com>
parents: 1406
diff changeset
  1524
        EC_ERR("Failed to set DC cyclic operation state of slave %u: ",
1392
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1525
                slave->ring_position);
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1526
        ec_datagram_print_wc_error(datagram);
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1527
        return;
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1528
    }
8fcc1d0987c1 DC cyclic operation and slave configuration. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1374
diff changeset
  1529
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1530
    ec_fsm_slave_config_enter_safeop(fsm);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1531
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1532
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1533
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1534
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1535
/** Request SAFEOP state.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1536
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1537
void ec_fsm_slave_config_enter_safeop(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1538
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1539
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1540
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1541
    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
  1542
    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
  1543
    ec_fsm_change_exec(fsm->fsm_change); // execute immediately
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1544
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1545
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1546
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1547
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1548
/** Slave configuration state: SAFEOP.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1549
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1550
void ec_fsm_slave_config_state_safeop(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1551
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1552
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1553
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1554
    ec_master_t *master = fsm->slave->master;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1555
    ec_slave_t *slave = fsm->slave;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1556
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
  1557
    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
  1558
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
  1559
    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
  1560
        if (!fsm->fsm_change->spontaneous_change)
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1561
            fsm->slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1562
        fsm->state = ec_fsm_slave_config_state_error;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1563
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1564
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1565
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1566
    // slave is now in SAFEOP
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1567
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1568
    if (master->debug_level) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
  1569
        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
  1570
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1571
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1572
    if (fsm->slave->current_state == fsm->slave->requested_state) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1573
        fsm->state = ec_fsm_slave_config_state_end; // successful
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1574
        if (master->debug_level) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
  1575
            EC_DBG("Finished configuration of slave %u.\n",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1576
                   slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1577
        }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1578
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1579
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1580
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1581
    // set state to OP
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1582
    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
  1583
    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
  1584
    ec_fsm_change_exec(fsm->fsm_change); // execute immediately
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1585
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1586
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1587
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1588
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1589
/** Slave configuration state: OP
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1590
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1591
void ec_fsm_slave_config_state_op(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1592
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1593
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1594
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1595
    ec_master_t *master = fsm->slave->master;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1596
    ec_slave_t *slave = fsm->slave;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1597
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
  1598
    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
  1599
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1173
diff changeset
  1600
    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
  1601
        if (!fsm->fsm_change->spontaneous_change)
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1602
            slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1603
        fsm->state = ec_fsm_slave_config_state_error;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1604
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1605
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1606
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1607
    // slave is now in OP
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1608
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1609
    if (master->debug_level) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
  1610
        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
  1611
        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
  1612
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1613
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1614
    fsm->state = ec_fsm_slave_config_state_end; // successful
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1615
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1616
1318
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
  1617
/*****************************************************************************/
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
  1618
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
  1619
/** Reconfigure the slave starting at INIT.
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
  1620
 */
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
  1621
void ec_fsm_slave_config_reconfigure(
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
  1622
        ec_fsm_slave_config_t *fsm /**< slave state machine */
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
  1623
        )
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
  1624
{
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
  1625
    if (fsm->slave->master->debug_level) {
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
  1626
        EC_DBG("Slave configuration for slave %u detached during "
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
  1627
                "configuration. Reconfiguring.", fsm->slave->ring_position);
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
  1628
    }
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
  1629
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
  1630
    ec_fsm_slave_config_enter_init(fsm); // reconfigure
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
  1631
}
76b4014391bd merge -r1583:1593 branches/stable-1.4: Fixed detaching oops.
Florian Pose <fp@igh-essen.com>
parents: 1277
diff changeset
  1632
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1633
/******************************************************************************
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1634
 *  Common state functions
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1635
 *****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1636
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1637
/** State: ERROR.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1638
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1639
void ec_fsm_slave_config_state_error(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1640
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1641
        )
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1642
{
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1643
}
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1644
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1645
/*****************************************************************************/
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1646
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1647
/** State: END.
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1648
 */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1649
void ec_fsm_slave_config_state_end(
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1650
        ec_fsm_slave_config_t *fsm /**< slave state machine */
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1651
        )
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1652
{
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1653
}
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1654
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
  1655
/*****************************************************************************/