master/fsm_slave_scan.c
author Florian Pose <fp@igh-essen.com>
Mon, 04 May 2009 12:46:30 +0000
changeset 1438 1d30b96bb04f
parent 1425 c1322a8793c0
child 1470 cb424feef942
permissions -rw-r--r--
Replaced ecrt_slave_config_dc_cycle_times() and ecrt_slave_config_dc_shift_times() by ecrt_slave_config_dc_sync_signals().
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: 1225
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: 1225
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: 1225
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: 1225
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: 1225
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: 1225
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: 1225
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: 1225
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: 1225
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: 1225
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: 1225
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: 1225
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: 1338
diff changeset
    22
 *  ---
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1338
diff changeset
    23
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1338
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: 1338
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: 1338
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
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
/**
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
   \file
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
   EtherCAT slave state machines.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
*/
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
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#include "globals.h"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
#include "master.h"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
#include "mailbox.h"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#include "slave_config.h"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include "fsm_slave_scan.h"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
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
void ec_fsm_slave_scan_state_start(ec_fsm_slave_scan_t *);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
void ec_fsm_slave_scan_state_address(ec_fsm_slave_scan_t *);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
void ec_fsm_slave_scan_state_state(ec_fsm_slave_scan_t *);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
void ec_fsm_slave_scan_state_base(ec_fsm_slave_scan_t *);
1419
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
    50
void ec_fsm_slave_scan_state_dc_cap(ec_fsm_slave_scan_t *);
1420
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
    51
void ec_fsm_slave_scan_state_dc_times(ec_fsm_slave_scan_t *);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
void ec_fsm_slave_scan_state_datalink(ec_fsm_slave_scan_t *);
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
    53
void ec_fsm_slave_scan_state_sii_size(ec_fsm_slave_scan_t *);
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
    54
void ec_fsm_slave_scan_state_sii_data(ec_fsm_slave_scan_t *);
831
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
    55
void ec_fsm_slave_scan_state_preop(ec_fsm_slave_scan_t *);
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
    56
void ec_fsm_slave_scan_state_sync(ec_fsm_slave_scan_t *);
831
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
    57
void ec_fsm_slave_scan_state_pdos(ec_fsm_slave_scan_t *);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
void ec_fsm_slave_scan_state_end(ec_fsm_slave_scan_t *);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
void ec_fsm_slave_scan_state_error(ec_fsm_slave_scan_t *);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
1419
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
    62
void ec_fsm_slave_scan_enter_datalink(ec_fsm_slave_scan_t *);
831
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
    63
void ec_fsm_slave_scan_enter_preop(ec_fsm_slave_scan_t *);
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
    64
void ec_fsm_slave_scan_enter_pdos(ec_fsm_slave_scan_t *);
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
    65
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
/** Constructor.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
 */
831
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
    70
void ec_fsm_slave_scan_init(
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
    71
        ec_fsm_slave_scan_t *fsm, /**< Slave scanning state machine. */
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
    72
        ec_datagram_t *datagram, /**< Datagram to use. */
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
    73
        ec_fsm_slave_config_t *fsm_slave_config, /**< Slave configuration
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
    74
                                                  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
    75
        ec_fsm_pdo_t *fsm_pdo /**< PDO configuration machine to use. */
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
        )
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
    fsm->datagram = datagram;
831
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
    79
    fsm->fsm_slave_config = fsm_slave_config;
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
    80
    fsm->fsm_pdo = fsm_pdo;
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
    // init sub state machines
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
    ec_fsm_sii_init(&fsm->fsm_sii, fsm->datagram);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
/** Destructor.
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_scan_clear(ec_fsm_slave_scan_t *fsm /**< slave state machine */)
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
    // clear sub state machines
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
    ec_fsm_sii_clear(&fsm->fsm_sii);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
}
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
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
/**
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
 * Start slave scan state machine.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
 */
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
void ec_fsm_slave_scan_start(
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
        ec_fsm_slave_scan_t *fsm, /**< slave state machine */
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
        ec_slave_t *slave /**< slave to configure */
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
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
    fsm->slave = slave;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
    fsm->state = ec_fsm_slave_scan_state_start;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
/**
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
   \return false, if state machine has terminated
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
int ec_fsm_slave_scan_running(const ec_fsm_slave_scan_t *fsm /**< slave state machine */)
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
    return fsm->state != ec_fsm_slave_scan_state_end
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
        && fsm->state != ec_fsm_slave_scan_state_error;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
/**
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
   Executes the current state of the state machine.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
   If the state machine's datagram is not sent or received yet, the execution
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
   of the state machine is delayed to the next cycle.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
   \return false, if state machine has terminated
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
*/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
int ec_fsm_slave_scan_exec(ec_fsm_slave_scan_t *fsm /**< slave state machine */)
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
    if (fsm->datagram->state == EC_DATAGRAM_SENT
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
        || fsm->datagram->state == EC_DATAGRAM_QUEUED) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
        // datagram was not sent or received yet.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
        return ec_fsm_slave_scan_running(fsm);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
    fsm->state(fsm);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
    return ec_fsm_slave_scan_running(fsm);
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
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
/**
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
   \return true, if the state machine terminated gracefully
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
*/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
int ec_fsm_slave_scan_success(const ec_fsm_slave_scan_t *fsm /**< slave state machine */)
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
    return fsm->state == ec_fsm_slave_scan_state_end;
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
/******************************************************************************
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
 *  slave scan state machine
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
 *****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
/**
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
   Slave scan state: START.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
   First state of the slave state machine. Writes the station address to the
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
   slave, according to its ring position.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
*/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
void ec_fsm_slave_scan_state_start(ec_fsm_slave_scan_t *fsm /**< slave state machine */)
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
    // write station address
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
    ec_datagram_apwr(fsm->datagram, fsm->slave->ring_position, 0x0010, 2);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
    EC_WRITE_U16(fsm->datagram->data, fsm->slave->station_address);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
    fsm->retries = EC_FSM_RETRIES;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
    fsm->state = ec_fsm_slave_scan_state_address;
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
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
/*****************************************************************************/
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
   Slave scan state: ADDRESS.
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
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
void ec_fsm_slave_scan_state_address(ec_fsm_slave_scan_t *fsm /**< slave state machine */)
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
    ec_datagram_t *datagram = fsm->datagram;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
        fsm->state = ec_fsm_slave_scan_state_error;
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 977
diff changeset
   189
        EC_ERR("Failed to receive station address datagram for slave %u"
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 977
diff changeset
   190
                " (datagram state %u)\n",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
                fsm->slave->ring_position, datagram->state);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
    if (datagram->working_counter != 1) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
        fsm->slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
        fsm->state = ec_fsm_slave_scan_state_error;
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 977
diff changeset
   198
        EC_ERR("Failed to write station address on slave %u: ",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
               fsm->slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
        ec_datagram_print_wc_error(datagram);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
    // Read AL state
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
    ec_datagram_fprd(datagram, fsm->slave->station_address, 0x0130, 2);
1225
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   206
    ec_datagram_zero(datagram);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
    fsm->retries = EC_FSM_RETRIES;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
    fsm->state = ec_fsm_slave_scan_state_state;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   212
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
/**
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   214
   Slave scan state: STATE.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   215
*/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   217
void ec_fsm_slave_scan_state_state(
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   218
        ec_fsm_slave_scan_t *fsm /**< slave state machine */
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
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   221
    ec_datagram_t *datagram = fsm->datagram;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   222
    ec_slave_t *slave = fsm->slave;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
        return;
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
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
        fsm->state = ec_fsm_slave_scan_state_error;
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 977
diff changeset
   229
        EC_ERR("Failed to receive AL state datagram from slave %u"
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 977
diff changeset
   230
                " (datagram state %u).\n",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   231
               fsm->slave->ring_position, datagram->state);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   232
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   233
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
    if (datagram->working_counter != 1) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
        fsm->slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
        fsm->state = ec_fsm_slave_scan_state_error;
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 977
diff changeset
   238
        EC_ERR("Failed to read AL state of slave %u: ",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   239
               fsm->slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   240
        ec_datagram_print_wc_error(datagram);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   241
        return;
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
    slave->current_state = EC_READ_U8(datagram->data);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   245
    if (slave->current_state & EC_SLAVE_STATE_ACK_ERR) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   246
        char state_str[EC_STATE_STRING_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
   247
        ec_state_string(slave->current_state, state_str, 0);
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 977
diff changeset
   248
        EC_WARN("Slave %u has state error bit set (%s)!\n",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   249
                slave->ring_position, state_str);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   250
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   251
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   252
    // read base data
1379
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   253
    ec_datagram_fprd(datagram, fsm->slave->station_address, 0x0000, 12);
1225
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   254
    ec_datagram_zero(datagram);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   255
    fsm->retries = EC_FSM_RETRIES;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   256
    fsm->state = ec_fsm_slave_scan_state_base;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   258
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   259
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   260
1420
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   261
/** Slave scan state: BASE.
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   262
 */
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   263
void ec_fsm_slave_scan_state_base(
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   264
        ec_fsm_slave_scan_t *fsm /**< slave state machine */
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   265
        )
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   266
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   267
    ec_datagram_t *datagram = fsm->datagram;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   268
    ec_slave_t *slave = fsm->slave;
1379
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   269
    u8 octet;
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   270
    int i;
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   271
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   272
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   273
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   274
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   275
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   276
        fsm->state = ec_fsm_slave_scan_state_error;
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 977
diff changeset
   277
        EC_ERR("Failed to receive base data datagram for slave %u"
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 977
diff changeset
   278
                " (datagram state %u).\n",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   279
               slave->ring_position, datagram->state);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   280
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   281
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   282
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   283
    if (datagram->working_counter != 1) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   284
        fsm->slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   285
        fsm->state = ec_fsm_slave_scan_state_error;
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 977
diff changeset
   286
        EC_ERR("Failed to read base data from slave %u: ",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   287
               slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   288
        ec_datagram_print_wc_error(datagram);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   289
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   290
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   291
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   292
    slave->base_type       = EC_READ_U8 (datagram->data);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   293
    slave->base_revision   = EC_READ_U8 (datagram->data + 1);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   294
    slave->base_build      = EC_READ_U16(datagram->data + 2);
1379
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   295
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   296
    slave->base_fmmu_count = EC_READ_U8 (datagram->data + 4);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   297
    if (slave->base_fmmu_count > EC_MAX_FMMUS) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   298
        EC_WARN("Slave %u has more FMMUs (%u) than the master can"
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   299
                " handle (%u).\n", slave->ring_position,
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   300
                slave->base_fmmu_count, EC_MAX_FMMUS);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   301
        slave->base_fmmu_count = EC_MAX_FMMUS;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   302
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   303
1379
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   304
    slave->base_sync_count = EC_READ_U8 (datagram->data + 5);
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   305
    if (slave->base_sync_count > EC_MAX_SYNC_MANAGERS) {
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   306
        EC_WARN("Slave %u provides more sync managers (%u) than the master can"
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   307
                " handle (%u).\n", slave->ring_position,
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   308
                slave->base_sync_count, EC_MAX_SYNC_MANAGERS);
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   309
        slave->base_sync_count = EC_MAX_SYNC_MANAGERS;
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   310
    }
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   311
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   312
    octet = EC_READ_U8(datagram->data + 7);
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   313
    for (i = 0; i < EC_MAX_PORTS; i++) {
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1420
diff changeset
   314
        slave->ports[i].desc = (octet >> (2 * i)) & 0x03;
1379
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   315
    }
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   316
    
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   317
    octet = EC_READ_U8(datagram->data + 8);
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   318
    slave->base_fmmu_bit_operation = octet & 0x01;
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   319
    slave->base_dc_supported = (octet >> 2) & 0x01;
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   320
    slave->base_dc_range = ((octet >> 3) & 0x01) ? EC_DC_64 : EC_DC_32;
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   321
1419
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   322
    if (slave->base_dc_supported) {
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   323
        // read DC capabilities
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   324
        ec_datagram_fprd(datagram, slave->station_address, 0x0910,
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   325
                slave->base_dc_range == EC_DC_64 ? 8 : 4);
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   326
        ec_datagram_zero(datagram);
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   327
        fsm->retries = EC_FSM_RETRIES;
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   328
        fsm->state = ec_fsm_slave_scan_state_dc_cap;
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   329
    } else {
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   330
        ec_fsm_slave_scan_enter_datalink(fsm);
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   331
    }
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   332
}
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   333
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   334
/*****************************************************************************/
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   335
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   336
/**
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   337
   Slave scan state: DC CAPABILITIES.
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   338
*/
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   339
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   340
void ec_fsm_slave_scan_state_dc_cap(
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   341
        ec_fsm_slave_scan_t *fsm /**< slave state machine */
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   342
        )
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   343
{
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   344
    ec_datagram_t *datagram = fsm->datagram;
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   345
    ec_slave_t *slave = fsm->slave;
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   346
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   347
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   348
        return;
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   349
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   350
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   351
        fsm->state = ec_fsm_slave_scan_state_error;
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   352
        EC_ERR("Failed to receive system time datagram for slave %u"
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   353
                " (datagram state %u).\n",
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   354
               slave->ring_position, datagram->state);
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   355
        return;
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   356
    }
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   357
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   358
    if (datagram->working_counter == 1) {
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   359
        slave->has_dc_system_time = 1;
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   360
        if (slave->master->debug_level) {
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   361
            EC_DBG("Slave %u has the System Time register.\n",
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   362
                    slave->ring_position);
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   363
        }
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   364
    } else if (datagram->working_counter == 0) {
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   365
        if (slave->master->debug_level) {
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   366
            EC_DBG("Slave %u has no System Time register; delay "
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   367
                    "measurement only.\n", slave->ring_position);
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   368
        }
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   369
    } else {
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   370
        fsm->slave->error_flag = 1;
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   371
        fsm->state = ec_fsm_slave_scan_state_error;
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   372
        EC_ERR("Failed to determine, if system time register is "
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   373
                "supported by slave %u: ", slave->ring_position);
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   374
        ec_datagram_print_wc_error(datagram);
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   375
        return;
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   376
    }
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   377
1420
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   378
    // read DC port receive times
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   379
    ec_datagram_fprd(datagram, slave->station_address, 0x0900, 16);
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   380
    ec_datagram_zero(datagram);
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   381
    fsm->retries = EC_FSM_RETRIES;
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   382
    fsm->state = ec_fsm_slave_scan_state_dc_times;
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   383
}
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   384
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   385
/*****************************************************************************/
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   386
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   387
/**
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   388
   Slave scan state: DC TIMES.
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   389
*/
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   390
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   391
void ec_fsm_slave_scan_state_dc_times(
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   392
        ec_fsm_slave_scan_t *fsm /**< slave state machine */
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   393
        )
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   394
{
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   395
    ec_datagram_t *datagram = fsm->datagram;
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   396
    ec_slave_t *slave = fsm->slave;
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   397
    int i;
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   398
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   399
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   400
        return;
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   401
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   402
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   403
        fsm->state = ec_fsm_slave_scan_state_error;
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   404
        EC_ERR("Failed to receive system time datagram for slave %u"
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   405
                " (datagram state %u).\n",
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   406
               slave->ring_position, datagram->state);
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   407
        return;
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   408
    }
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   409
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   410
    if (datagram->working_counter != 1) {
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   411
        fsm->slave->error_flag = 1;
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   412
        fsm->state = ec_fsm_slave_scan_state_error;
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   413
        EC_ERR("Failed to get DC receive times of slave %u: ",
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   414
                slave->ring_position);
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   415
        ec_datagram_print_wc_error(datagram);
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   416
        return;
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   417
    }
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   418
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   419
    for (i = 0; i < EC_MAX_PORTS; i++) {
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1420
diff changeset
   420
        slave->ports[i].receive_time = EC_READ_U32(datagram->data + 4 * i);
1420
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   421
    }
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1419
diff changeset
   422
1419
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   423
    ec_fsm_slave_scan_enter_datalink(fsm);
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   424
}
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   425
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   426
/*****************************************************************************/
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   427
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   428
/**
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   429
   Slave scan entry function: DATALINK.
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   430
*/
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   431
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   432
void ec_fsm_slave_scan_enter_datalink(
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   433
        ec_fsm_slave_scan_t *fsm /**< slave state machine */
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   434
        )
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   435
{
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   436
    ec_datagram_t *datagram = fsm->datagram;
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   437
    ec_slave_t *slave = fsm->slave;
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
   438
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   439
    // read data link status
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   440
    ec_datagram_fprd(datagram, slave->station_address, 0x0110, 2);
1225
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   441
    ec_datagram_zero(datagram);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   442
    fsm->retries = EC_FSM_RETRIES;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   443
    fsm->state = ec_fsm_slave_scan_state_datalink;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   444
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   445
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   446
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   447
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   448
/**
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   449
   Slave scan state: DATALINK.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   450
*/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   451
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   452
void ec_fsm_slave_scan_state_datalink(ec_fsm_slave_scan_t *fsm /**< slave state machine */)
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   453
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   454
    ec_datagram_t *datagram = fsm->datagram;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   455
    ec_slave_t *slave = fsm->slave;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   456
    uint16_t dl_status;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   457
    unsigned int i;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   458
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   459
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   460
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   461
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   462
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   463
        fsm->state = ec_fsm_slave_scan_state_error;
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 977
diff changeset
   464
        EC_ERR("Failed to receive DL status datagram from slave %u"
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 977
diff changeset
   465
                " (datagram state %u).\n",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   466
               slave->ring_position, datagram->state);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   467
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   468
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   469
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   470
    if (datagram->working_counter != 1) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   471
        fsm->slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   472
        fsm->state = ec_fsm_slave_scan_state_error;
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 977
diff changeset
   473
        EC_ERR("Failed to read DL status from slave %u: ",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   474
               slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   475
        ec_datagram_print_wc_error(datagram);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   476
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   477
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   478
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   479
    dl_status = EC_READ_U16(datagram->data);
1055
2be8918682fa Store sync manager configurations in ec_slave_config_t instead of Pdo
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   480
    for (i = 0; i < EC_MAX_PORTS; i++) {
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1420
diff changeset
   481
        slave->ports[i].link.link_up = dl_status & (1 << (4 + i)) ? 1 : 0;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1420
diff changeset
   482
        slave->ports[i].link.loop_closed = dl_status & (1 << (8 + i * 2)) ? 1 : 0;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1420
diff changeset
   483
        slave->ports[i].link.signal_detected = dl_status & (1 << (9 + i * 2)) ? 1 : 0;
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   484
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   485
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
   486
    // Start fetching SII size
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
   487
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
   488
    fsm->sii_offset = EC_FIRST_SII_CATEGORY_OFFSET; // first category header
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   489
    ec_fsm_sii_read(&fsm->fsm_sii, slave, fsm->sii_offset,
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   490
            EC_FSM_SII_USE_CONFIGURED_ADDRESS);
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
   491
    fsm->state = ec_fsm_slave_scan_state_sii_size;
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   492
    fsm->state(fsm); // execute state immediately
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   493
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   494
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   495
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   496
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   497
/**
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
   498
   Slave scan state: SII SIZE.
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
   499
*/
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
   500
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
   501
void ec_fsm_slave_scan_state_sii_size(ec_fsm_slave_scan_t *fsm /**< slave state machine */)
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   502
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   503
    ec_slave_t *slave = fsm->slave;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   504
    uint16_t cat_type, cat_size;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   505
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   506
    if (ec_fsm_sii_exec(&fsm->fsm_sii)) return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   507
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   508
    if (!ec_fsm_sii_success(&fsm->fsm_sii)) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   509
        fsm->slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   510
        fsm->state = ec_fsm_slave_scan_state_error;
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 977
diff changeset
   511
        EC_ERR("Failed to read SII size of slave %u.\n",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   512
               slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   513
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   514
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   515
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   516
    cat_type = EC_READ_U16(fsm->fsm_sii.value);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   517
    cat_size = EC_READ_U16(fsm->fsm_sii.value + 2);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   518
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   519
    if (cat_type != 0xFFFF) { // not the last category
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   520
        off_t next_offset = 2UL + fsm->sii_offset + cat_size;
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
   521
        if (next_offset >= EC_MAX_SII_SIZE) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 977
diff changeset
   522
            EC_WARN("SII size of slave %u exceeds"
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   523
                    " %u words (0xffff limiter missing?).\n",
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
   524
                    slave->ring_position, EC_MAX_SII_SIZE);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   525
            // cut off category data...
977
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   526
            slave->sii_nwords = EC_FIRST_SII_CATEGORY_OFFSET;
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
   527
            goto alloc_sii;
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   528
        }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   529
        fsm->sii_offset = next_offset;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   530
        ec_fsm_sii_read(&fsm->fsm_sii, slave, fsm->sii_offset,
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   531
                        EC_FSM_SII_USE_CONFIGURED_ADDRESS);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   532
        ec_fsm_sii_exec(&fsm->fsm_sii); // execute state immediately
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   533
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   534
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   535
977
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   536
    slave->sii_nwords = fsm->sii_offset + 1;
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
   537
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
   538
alloc_sii:
977
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   539
    if (slave->sii_words) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 977
diff changeset
   540
        EC_WARN("Freeing old SII data on slave %u...\n",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   541
                slave->ring_position);
977
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   542
        kfree(slave->sii_words);
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   543
    }
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   544
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   545
    if (!(slave->sii_words =
998
05a24788f3b2 Replaced a few GFP_ATOMIC allocations with GFP_KERNEL ones.
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   546
                (uint16_t *) kmalloc(slave->sii_nwords * 2, GFP_KERNEL))) {
977
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   547
        EC_ERR("Failed to allocate %u words of SII data for slave %u.\n",
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   548
               slave->sii_nwords, slave->ring_position);
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   549
        slave->sii_nwords = 0;
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   550
        slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   551
        fsm->state = ec_fsm_slave_scan_state_error;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   552
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   553
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   554
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
   555
    // Start fetching SII contents
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
   556
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
   557
    fsm->state = ec_fsm_slave_scan_state_sii_data;
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   558
    fsm->sii_offset = 0x0000;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   559
    ec_fsm_sii_read(&fsm->fsm_sii, slave, fsm->sii_offset,
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   560
            EC_FSM_SII_USE_CONFIGURED_ADDRESS);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   561
    ec_fsm_sii_exec(&fsm->fsm_sii); // execute state immediately
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   562
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   563
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   564
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   565
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   566
/**
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
   567
   Slave scan state: SII DATA.
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
   568
*/
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
   569
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
   570
void ec_fsm_slave_scan_state_sii_data(ec_fsm_slave_scan_t *fsm /**< slave state machine */)
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   571
{
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   572
    ec_slave_t *slave = fsm->slave;
977
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   573
    uint16_t *cat_word, cat_type, cat_size;
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   574
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   575
    if (ec_fsm_sii_exec(&fsm->fsm_sii)) return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   576
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   577
    if (!ec_fsm_sii_success(&fsm->fsm_sii)) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   578
        fsm->slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   579
        fsm->state = ec_fsm_slave_scan_state_error;
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 977
diff changeset
   580
        EC_ERR("Failed to fetch SII contents of slave %u.\n",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   581
               slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   582
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   583
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   584
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   585
    // 2 words fetched
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   586
977
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   587
    if (fsm->sii_offset + 2 <= slave->sii_nwords) { // 2 words fit
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   588
        memcpy(slave->sii_words + fsm->sii_offset, fsm->fsm_sii.value, 4);
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   589
    } else { // copy the last word
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   590
        memcpy(slave->sii_words + fsm->sii_offset, fsm->fsm_sii.value, 2);
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   591
    }
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   592
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   593
    if (fsm->sii_offset + 2 < slave->sii_nwords) {
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   594
        // fetch the next 2 words
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   595
        fsm->sii_offset += 2;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   596
        ec_fsm_sii_read(&fsm->fsm_sii, slave, fsm->sii_offset,
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   597
                        EC_FSM_SII_USE_CONFIGURED_ADDRESS);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   598
        ec_fsm_sii_exec(&fsm->fsm_sii); // execute state immediately
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   599
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   600
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   601
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
   602
    // Evaluate SII contents
870
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 841
diff changeset
   603
    
fbd5924690ee Allow multiple sync manager categories.
Florian Pose <fp@igh-essen.com>
parents: 841
diff changeset
   604
    ec_slave_clear_sync_managers(slave);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   605
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   606
    slave->sii.alias =
977
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   607
        EC_READ_U16(slave->sii_words + 0x0004);
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   608
    slave->sii.vendor_id =
977
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   609
        EC_READ_U32(slave->sii_words + 0x0008);
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   610
    slave->sii.product_code =
977
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   611
        EC_READ_U32(slave->sii_words + 0x000A);
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   612
    slave->sii.revision_number =
977
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   613
        EC_READ_U32(slave->sii_words + 0x000C);
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   614
    slave->sii.serial_number =
977
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   615
        EC_READ_U32(slave->sii_words + 0x000E);
1337
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   616
    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
   617
        EC_READ_U16(slave->sii_words + 0x0014);
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   618
    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
   619
        EC_READ_U16(slave->sii_words + 0x0015);
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   620
    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
   621
        EC_READ_U16(slave->sii_words + 0x0016);
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   622
    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
   623
        EC_READ_U16(slave->sii_words + 0x0017);
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   624
    slave->sii.std_rx_mailbox_offset =
977
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   625
        EC_READ_U16(slave->sii_words + 0x0018);
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
    slave->sii.std_rx_mailbox_size =
977
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   627
        EC_READ_U16(slave->sii_words + 0x0019);
1337
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   628
    slave->sii.std_tx_mailbox_offset =
977
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   629
        EC_READ_U16(slave->sii_words + 0x001A);
1337
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   630
    slave->sii.std_tx_mailbox_size =
977
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   631
        EC_READ_U16(slave->sii_words + 0x001B);
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   632
    slave->sii.mailbox_protocols =
977
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   633
        EC_READ_U16(slave->sii_words + 0x001C);
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   634
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   635
    if (slave->sii_nwords == EC_FIRST_SII_CATEGORY_OFFSET) {
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
   636
        // sii does not contain category data
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   637
        fsm->state = ec_fsm_slave_scan_state_end;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   638
        return;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   639
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   640
977
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   641
    if (slave->sii_nwords < EC_FIRST_SII_CATEGORY_OFFSET + 1) {
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
   642
        EC_ERR("Unexpected end of SII data in slave %u:"
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   643
                " First category header missing.\n",
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   644
                slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   645
        goto end;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   646
    }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   647
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   648
    // evaluate category data
977
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   649
    cat_word = slave->sii_words + EC_FIRST_SII_CATEGORY_OFFSET;
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   650
    while (EC_READ_U16(cat_word) != 0xFFFF) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   651
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   652
        // type and size words must fit
977
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   653
        if (cat_word + 2 - slave->sii_words > slave->sii_nwords) {
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
   654
            EC_ERR("Unexpected end of SII data in slave %u:"
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   655
                    " Category header incomplete.\n",
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   656
                    slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   657
            goto end;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   658
        }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   659
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   660
        cat_type = EC_READ_U16(cat_word) & 0x7FFF;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   661
        cat_size = EC_READ_U16(cat_word + 1);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   662
        cat_word += 2;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   663
977
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   664
        if (cat_word + cat_size - slave->sii_words > slave->sii_nwords) {
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
   665
            EC_WARN("Unexpected end of SII data in slave %u:"
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   666
                    " Category data incomplete.\n",
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   667
                    slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   668
            goto end;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   669
        }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   670
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   671
        switch (cat_type) {
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   672
            case 0x000A:
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   673
                if (ec_slave_fetch_sii_strings(slave, (uint8_t *) cat_word,
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   674
                            cat_size * 2))
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   675
                    goto end;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   676
                break;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   677
            case 0x001E:
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   678
                if (ec_slave_fetch_sii_general(slave, (uint8_t *) cat_word,
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   679
                            cat_size * 2))
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   680
                    goto end;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   681
                break;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   682
            case 0x0028:
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   683
                break;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   684
            case 0x0029:
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   685
                if (ec_slave_fetch_sii_syncs(slave, (uint8_t *) cat_word,
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   686
                            cat_size * 2))
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   687
                    goto end;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   688
                break;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   689
            case 0x0032:
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   690
                if (ec_slave_fetch_sii_pdos( slave, (uint8_t *) cat_word,
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   691
                            cat_size * 2, EC_DIR_INPUT)) // TxPDO
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   692
                    goto end;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   693
                break;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   694
            case 0x0033:
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   695
                if (ec_slave_fetch_sii_pdos( slave, (uint8_t *) cat_word,
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   696
                            cat_size * 2, EC_DIR_OUTPUT)) // RxPDO
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   697
                    goto end;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   698
                break;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   699
            default:
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   700
                if (fsm->slave->master->debug_level)
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 977
diff changeset
   701
                    EC_WARN("Unknown category type 0x%04X in slave %u.\n",
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   702
                            cat_type, slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   703
        }
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   704
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   705
        cat_word += cat_size;
977
167ae3e76cc7 Moved sii to words.
Florian Pose <fp@igh-essen.com>
parents: 903
diff changeset
   706
        if (cat_word - slave->sii_words >= slave->sii_nwords) {
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 870
diff changeset
   707
            EC_WARN("Unexpected end of SII data in slave %u:"
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   708
                    " Next category header missing.\n",
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   709
                    slave->ring_position);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   710
            goto end;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   711
        }
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
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   714
    if (slave->sii.mailbox_protocols & EC_MBOX_COE) {
831
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   715
        ec_fsm_slave_scan_enter_preop(fsm);
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   716
    } else {
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   717
        fsm->state = ec_fsm_slave_scan_state_end;
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   718
    }
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   719
    return;
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
end:
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   722
    EC_ERR("Failed to analyze category data.\n");
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   723
    fsm->slave->error_flag = 1;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   724
    fsm->state = ec_fsm_slave_scan_state_error;
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   725
}
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   726
831
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   727
/*****************************************************************************/
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   728
841
6f0cf00d7107 Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   729
/** Enter slave scan state PREOP.
6f0cf00d7107 Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   730
 */
831
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   731
void ec_fsm_slave_scan_enter_preop(
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   732
        ec_fsm_slave_scan_t *fsm /**< slave state machine */
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   733
        )
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   734
{
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   735
    ec_slave_t *slave = fsm->slave;
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
   736
    uint8_t current_state = slave->current_state & EC_SLAVE_STATE_MASK;
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
   737
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
   738
    if (current_state != EC_SLAVE_STATE_PREOP
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
   739
            && current_state != EC_SLAVE_STATE_SAFEOP
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
   740
            && current_state != EC_SLAVE_STATE_OP) {
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
   741
        if (slave->master->debug_level) {
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
   742
            char str[EC_STATE_STRING_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
   743
            ec_state_string(current_state, str, 0);
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
   744
            EC_DBG("Slave %u is not in the state to do mailbox com (%s),"
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
   745
                    " setting to PREOP.\n", slave->ring_position, str);
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
   746
        }
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
   747
831
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   748
        fsm->state = ec_fsm_slave_scan_state_preop;
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   749
        ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP);
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   750
        ec_fsm_slave_config_start(fsm->fsm_slave_config, slave);
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   751
        ec_fsm_slave_config_exec(fsm->fsm_slave_config);
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   752
    } else {
1338
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   753
        if (slave->master->debug_level)
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
   754
            EC_DBG("Reading mailbox syncmanager configuration of slave %u.\n",
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
   755
                    slave->ring_position);
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
   756
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
   757
        /* Scan current sync manager configuration to get configured mailbox
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
   758
         * sizes. */
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
   759
        ec_datagram_fprd(fsm->datagram, slave->station_address, 0x0800,
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
   760
                EC_SYNC_PAGE_SIZE * 2);
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
   761
        fsm->retries = EC_FSM_RETRIES;
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
   762
        fsm->state = ec_fsm_slave_scan_state_sync;
831
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   763
    }
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   764
}
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   765
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   766
/*****************************************************************************/
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   767
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   768
/** Slave scan state: PREOP.
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   769
 */
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   770
void ec_fsm_slave_scan_state_preop(
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   771
        ec_fsm_slave_scan_t *fsm /**< slave state machine */
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   772
        )
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   773
{
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   774
    if (ec_fsm_slave_config_exec(fsm->fsm_slave_config))
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   775
        return;
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   776
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   777
    if (!ec_fsm_slave_config_success(fsm->fsm_slave_config)) {
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   778
        fsm->state = ec_fsm_slave_scan_state_error;
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   779
        return;
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   780
    }
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   781
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   782
    ec_fsm_slave_scan_enter_pdos(fsm);
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   783
}
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   784
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   785
/*****************************************************************************/
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   786
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
   787
/** Slave scan state: SYNC.
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
   788
 */
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
   789
void ec_fsm_slave_scan_state_sync(
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
   790
        ec_fsm_slave_scan_t *fsm /**< slave state machine */
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
   791
        )
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
   792
{
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
   793
    ec_datagram_t *datagram = fsm->datagram;
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
   794
    ec_slave_t *slave = fsm->slave;
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
   795
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
   796
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
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
   797
        return;
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
   798
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
   799
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
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
   800
        fsm->state = ec_fsm_slave_scan_state_error;
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
   801
        EC_ERR("Failed to receive sync manager configuration datagram"
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
   802
                " from slave %u (datagram state %u).\n",
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
   803
               slave->ring_position, datagram->state);
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
   804
        return;
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
   805
    }
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
   806
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
   807
    if (datagram->working_counter != 1) {
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
   808
        fsm->slave->error_flag = 1;
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
   809
        fsm->state = ec_fsm_slave_scan_state_error;
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
   810
        EC_ERR("Failed to read DL status from slave %u: ",
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
   811
               slave->ring_position);
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
   812
        ec_datagram_print_wc_error(datagram);
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
   813
        return;
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
   814
    }
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
   815
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
   816
    slave->configured_rx_mailbox_offset = EC_READ_U16(datagram->data);
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
   817
    slave->configured_rx_mailbox_size = EC_READ_U16(datagram->data + 2);
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
   818
    slave->configured_tx_mailbox_offset = EC_READ_U16(datagram->data + 8);
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
   819
    slave->configured_tx_mailbox_size = EC_READ_U16(datagram->data + 10);
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
   820
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
   821
    if (slave->master->debug_level) {
eb31b5a135da merge -c1621 branches/1.4-foe: Introduced configured_[tr]x_mailbox(size|offset) members of slave.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   822
        EC_DBG("Mailbox configuration of slave %u:\n", slave->ring_position);
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
   823
        EC_DBG(" RX offset=0x%04x size=%u\n",
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
   824
                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
   825
                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
   826
        EC_DBG(" TX offset=0x%04x size=%u\n",
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
   827
                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
   828
                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
   829
    }
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
   830
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
   831
    ec_fsm_slave_scan_enter_pdos(fsm);
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
   832
}
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
   833
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
   834
/*****************************************************************************/
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
   835
841
6f0cf00d7107 Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   836
/** Enter slave scan state PDOS.
6f0cf00d7107 Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   837
 */
831
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   838
void ec_fsm_slave_scan_enter_pdos(
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   839
        ec_fsm_slave_scan_t *fsm /**< slave state machine */
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   840
        )
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   841
{
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   842
    ec_slave_t *slave = fsm->slave;
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   843
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   844
    if (slave->master->debug_level)
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   845
        EC_DBG("Scanning PDO assignment and mapping of slave %u.\n",
831
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   846
                slave->ring_position);
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   847
    fsm->state = ec_fsm_slave_scan_state_pdos;
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   848
    ec_fsm_pdo_start_reading(fsm->fsm_pdo, slave);
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   849
    ec_fsm_pdo_exec(fsm->fsm_pdo); // execute immediately
831
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   850
}
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   851
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   852
/*****************************************************************************/
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   853
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   854
/** Slave scan state: PDOS.
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   855
 */
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   856
void ec_fsm_slave_scan_state_pdos(
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   857
        ec_fsm_slave_scan_t *fsm /**< slave state machine */
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   858
        )
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   859
{
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   860
    if (ec_fsm_pdo_exec(fsm->fsm_pdo))
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   861
        return;
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   862
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   863
    if (!ec_fsm_pdo_success(fsm->fsm_pdo)) {
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   864
        fsm->state = ec_fsm_slave_scan_state_error;
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   865
        return;
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   866
    }
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1055
diff changeset
   867
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   868
    // reading PDO configuration finished
831
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   869
    fsm->state = ec_fsm_slave_scan_state_end;
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   870
}
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   871
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   872
/******************************************************************************
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   873
 * Common state functions
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
/** State: ERROR.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   877
 */
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   878
void ec_fsm_slave_scan_state_error(
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   879
        ec_fsm_slave_scan_t *fsm /**< slave state machine */
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   880
        )
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   881
{
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
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   884
/*****************************************************************************/
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   885
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   886
/** State: END.
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   887
 */
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   888
void ec_fsm_slave_scan_state_end(
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   889
        ec_fsm_slave_scan_t *fsm /**< slave state machine */
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   890
        )
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   891
{
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
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   894
/*****************************************************************************/