master/fsm_master.c
author Florian Pose <fp@igh-essen.com>
Wed, 08 Apr 2009 09:29:01 +0000
changeset 1383 0c88c50c31e3
parent 1380 c2b0ef67e829
child 1385 241a7511eee9
permissions -rw-r--r--
Fixed phy_write usage.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
b4960499098f Added finite state machine (FSM) processing.
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: 1277
diff changeset
     5
 *  Copyright (C) 2006-2008  Florian Pose, Ingenieurgemeinschaft IgH
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
b4960499098f Added finite state machine (FSM) processing.
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: 1277
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: 1277
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: 1277
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: 1277
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: 1277
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: 1277
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: 1277
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: 1277
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: 1277
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: 1277
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: 1277
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1349
diff changeset
    22
 *  ---
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1349
diff changeset
    23
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1349
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: 1349
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: 1349
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    27
 *
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
    30
/** \file
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
    31
 * EtherCAT master state machine.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
    32
 */
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
#include "globals.h"
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#include "master.h"
329
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    38
#include "mailbox.h"
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
    39
#include "slave_config.h"
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
    40
#ifdef EC_EOE
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
    41
#include "ethernet.h"
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
    42
#endif
849
4b712ec8929d Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
    43
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    44
#include "fsm_master.h"
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    45
#include "fsm_foe.h"
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    46
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    47
/*****************************************************************************/
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    48
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    49
void ec_fsm_master_state_start(ec_fsm_master_t *);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    50
void ec_fsm_master_state_broadcast(ec_fsm_master_t *);
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
    51
void ec_fsm_master_state_read_state(ec_fsm_master_t *);
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    52
void ec_fsm_master_state_acknowledge(ec_fsm_master_t *);
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    53
void ec_fsm_master_state_configure_slave(ec_fsm_master_t *);
717
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
    54
void ec_fsm_master_state_clear_addresses(ec_fsm_master_t *);
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
    55
void ec_fsm_master_state_scan_slave(ec_fsm_master_t *);
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
    56
void ec_fsm_master_state_write_sii(ec_fsm_master_t *);
905
6d74ebc603ee Renamed state sdodict to sdo_dictionary.
Florian Pose <fp@igh-essen.com>
parents: 904
diff changeset
    57
void ec_fsm_master_state_sdo_dictionary(ec_fsm_master_t *);
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    58
void ec_fsm_master_state_sdo_request(ec_fsm_master_t *);
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
    59
void ec_fsm_master_state_phy_request(ec_fsm_master_t *);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    60
void ec_fsm_master_state_foe_request(ec_fsm_master_t *);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    61
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
    64
/** Constructor.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
    65
 */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
    66
void ec_fsm_master_init(
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
    67
        ec_fsm_master_t *fsm, /**< Master state machine. */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
    68
        ec_master_t *master, /**< EtherCAT master. */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
    69
        ec_datagram_t *datagram /**< Datagram object to use. */
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    70
        )
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
    fsm->master = master;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    73
    fsm->datagram = datagram;
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    74
    fsm->state = ec_fsm_master_state_start;
650
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
    75
    fsm->idle = 0;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    76
    fsm->slaves_responding = 0;
553
a4e0267825e3 Introduced topology_change_pending to delay bus scanning until IDLE mode
Florian Pose <fp@igh-essen.com>
parents: 538
diff changeset
    77
    fsm->topology_change_pending = 0;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    78
    fsm->slave_states = EC_SLAVE_STATE_UNKNOWN;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
    80
    // init sub-state-machines
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1079
diff changeset
    81
    ec_fsm_coe_init(&fsm->fsm_coe, fsm->datagram);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
    82
    ec_fsm_foe_init(&fsm->fsm_foe, fsm->datagram);
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1079
diff changeset
    83
    ec_fsm_pdo_init(&fsm->fsm_pdo, &fsm->fsm_coe);
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1079
diff changeset
    84
    ec_fsm_change_init(&fsm->fsm_change, fsm->datagram);
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1079
diff changeset
    85
    ec_fsm_slave_config_init(&fsm->fsm_slave_config, fsm->datagram,
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1079
diff changeset
    86
            &fsm->fsm_change, &fsm->fsm_coe, &fsm->fsm_pdo);
831
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
    87
    ec_fsm_slave_scan_init(&fsm->fsm_slave_scan, fsm->datagram,
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1079
diff changeset
    88
            &fsm->fsm_slave_config, &fsm->fsm_pdo);
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
    89
    ec_fsm_sii_init(&fsm->fsm_sii, fsm->datagram);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
    94
/** Destructor.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
    95
 */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
    96
void ec_fsm_master_clear(
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
    97
        ec_fsm_master_t *fsm /**< Master state machine. */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
    98
        )
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
{
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   100
    // clear sub-state machines
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1079
diff changeset
   101
    ec_fsm_coe_clear(&fsm->fsm_coe);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   102
    ec_fsm_foe_clear(&fsm->fsm_foe);
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1079
diff changeset
   103
    ec_fsm_pdo_clear(&fsm->fsm_pdo);
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1079
diff changeset
   104
    ec_fsm_change_clear(&fsm->fsm_change);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   105
    ec_fsm_slave_config_clear(&fsm->fsm_slave_config);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   106
    ec_fsm_slave_scan_clear(&fsm->fsm_slave_scan);
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   107
    ec_fsm_sii_clear(&fsm->fsm_sii);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   112
/** Executes the current state of the state machine.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   113
 *
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   114
 * If the state machine's datagram is not sent or received yet, the execution
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   115
 * of the state machine is delayed to the next cycle.
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   116
 */
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   117
void ec_fsm_master_exec(
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   118
        ec_fsm_master_t *fsm /**< Master state machine. */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   119
        )
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   120
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   121
    if (fsm->datagram->state == EC_DATAGRAM_SENT
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   122
        || fsm->datagram->state == EC_DATAGRAM_QUEUED) {
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   123
        // datagram was not sent or received yet.
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   124
        return;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   125
    }
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   126
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   127
    fsm->state(fsm);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   128
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   129
650
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   130
/*****************************************************************************/
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   131
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   132
/**
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   133
 * \return true, if the state machine is in an idle phase
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   134
 */
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   135
int ec_fsm_master_idle(
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   136
        const ec_fsm_master_t *fsm /**< Master state machine. */
650
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   137
        )
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   138
{
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   139
    return fsm->idle;
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   140
}
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   141
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   142
/*****************************************************************************/
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   143
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   144
/** Restarts the master state machine.
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   145
 */
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   146
void ec_fsm_master_restart(
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   147
        ec_fsm_master_t *fsm /**< Master state machine. */
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   148
        )
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   149
{
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   150
    fsm->state = ec_fsm_master_state_start;
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   151
    fsm->state(fsm); // execute immediately
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   152
}
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   153
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
/******************************************************************************
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   155
 * Master state machine
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
 *****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   158
/** Master state: START.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   159
 *
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   160
 * Starts with getting slave count and slave states.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   161
 */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   162
void ec_fsm_master_state_start(
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   163
        ec_fsm_master_t *fsm /**< Master state machine. */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   164
        )
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   165
{
650
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   166
    fsm->idle = 1;
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   167
    ec_datagram_brd(fsm->datagram, 0x0130, 2);
1225
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1219
diff changeset
   168
    ec_datagram_zero(fsm->datagram);
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   169
    fsm->state = ec_fsm_master_state_broadcast;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   170
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   171
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   172
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   173
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   174
/** Master state: BROADCAST.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   175
 *
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   176
 * Processes the broadcast read slave count and slaves states.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   177
 */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   178
void ec_fsm_master_state_broadcast(
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   179
        ec_fsm_master_t *fsm /**< Master state machine. */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   180
        )
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   181
{
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   182
    ec_datagram_t *datagram = fsm->datagram;
1005
5af7ab9a98b1 Minor change.
Florian Pose <fp@igh-essen.com>
parents: 1003
diff changeset
   183
    unsigned int i, size;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
    ec_slave_t *slave;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   185
    ec_master_t *master = fsm->master;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   187
    if (datagram->state == EC_DATAGRAM_TIMED_OUT)
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   188
        return; // always retry
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   189
553
a4e0267825e3 Introduced topology_change_pending to delay bus scanning until IDLE mode
Florian Pose <fp@igh-essen.com>
parents: 538
diff changeset
   190
    // bus topology change?
a4e0267825e3 Introduced topology_change_pending to delay bus scanning until IDLE mode
Florian Pose <fp@igh-essen.com>
parents: 538
diff changeset
   191
    if (datagram->working_counter != fsm->slaves_responding) {
a4e0267825e3 Introduced topology_change_pending to delay bus scanning until IDLE mode
Florian Pose <fp@igh-essen.com>
parents: 538
diff changeset
   192
        fsm->topology_change_pending = 1;
a4e0267825e3 Introduced topology_change_pending to delay bus scanning until IDLE mode
Florian Pose <fp@igh-essen.com>
parents: 538
diff changeset
   193
        fsm->slaves_responding = datagram->working_counter;
906
f95e3e33c0cf Removed slave online flag.
Florian Pose <fp@igh-essen.com>
parents: 905
diff changeset
   194
        EC_INFO("%u slave(s) responding.\n", fsm->slaves_responding);
f95e3e33c0cf Removed slave online flag.
Florian Pose <fp@igh-essen.com>
parents: 905
diff changeset
   195
    }
f95e3e33c0cf Removed slave online flag.
Florian Pose <fp@igh-essen.com>
parents: 905
diff changeset
   196
f95e3e33c0cf Removed slave online flag.
Florian Pose <fp@igh-essen.com>
parents: 905
diff changeset
   197
    if (datagram->state != EC_DATAGRAM_RECEIVED) { // link is down
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   198
        ec_fsm_master_restart(fsm);
906
f95e3e33c0cf Removed slave online flag.
Florian Pose <fp@igh-essen.com>
parents: 905
diff changeset
   199
        return;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   200
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   201
1021
fa5cf205f4f0 Set slave_states to 0x00 when no slaves are present.
Florian Pose <fp@igh-essen.com>
parents: 1005
diff changeset
   202
    if (fsm->slaves_responding) {
fa5cf205f4f0 Set slave_states to 0x00 when no slaves are present.
Florian Pose <fp@igh-essen.com>
parents: 1005
diff changeset
   203
        uint8_t states = EC_READ_U8(datagram->data);
fa5cf205f4f0 Set slave_states to 0x00 when no slaves are present.
Florian Pose <fp@igh-essen.com>
parents: 1005
diff changeset
   204
        if (states != fsm->slave_states) { // slave states changed?
fa5cf205f4f0 Set slave_states to 0x00 when no slaves are present.
Florian Pose <fp@igh-essen.com>
parents: 1005
diff changeset
   205
            char state_str[EC_STATE_STRING_SIZE];
fa5cf205f4f0 Set slave_states to 0x00 when no slaves are present.
Florian Pose <fp@igh-essen.com>
parents: 1005
diff changeset
   206
            fsm->slave_states = states;
1337
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1336
diff changeset
   207
            ec_state_string(fsm->slave_states, state_str, 1);
1021
fa5cf205f4f0 Set slave_states to 0x00 when no slaves are present.
Florian Pose <fp@igh-essen.com>
parents: 1005
diff changeset
   208
            EC_INFO("Slave states: %s.\n", state_str);
fa5cf205f4f0 Set slave_states to 0x00 when no slaves are present.
Florian Pose <fp@igh-essen.com>
parents: 1005
diff changeset
   209
        }
fa5cf205f4f0 Set slave_states to 0x00 when no slaves are present.
Florian Pose <fp@igh-essen.com>
parents: 1005
diff changeset
   210
    } else {
fa5cf205f4f0 Set slave_states to 0x00 when no slaves are present.
Florian Pose <fp@igh-essen.com>
parents: 1005
diff changeset
   211
        fsm->slave_states = 0x00;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   212
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   213
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   214
    if (fsm->topology_change_pending) {
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   215
        down(&master->scan_sem);
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   216
        if (!master->allow_scan) {
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   217
            up(&master->scan_sem);
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 880
diff changeset
   218
        } else {
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 880
diff changeset
   219
            master->scan_busy = 1;
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   220
            up(&master->scan_sem);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   221
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   222
            // topology change when scan is allowed:
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   223
            // clear all slaves and scan the bus
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   224
            fsm->topology_change_pending = 0;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   225
            fsm->idle = 0;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   226
            fsm->scan_jiffies = jiffies;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   227
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   228
#ifdef EC_EOE
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   229
            ec_master_eoe_stop(master);
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   230
            ec_master_clear_eoe_handlers(master);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   231
#endif
992
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   232
            ec_master_clear_slaves(master);
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   233
1003
f7cf194d6979 Minor change.
Florian Pose <fp@igh-essen.com>
parents: 1002
diff changeset
   234
            master->slave_count = fsm->slaves_responding;
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   235
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   236
            if (!master->slave_count) {
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   237
                // no slaves present -> finish state machine.
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 880
diff changeset
   238
                master->scan_busy = 0;
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   239
                wake_up_interruptible(&master->scan_queue);
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   240
                ec_fsm_master_restart(fsm);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   241
                return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   242
            }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   243
1005
5af7ab9a98b1 Minor change.
Florian Pose <fp@igh-essen.com>
parents: 1003
diff changeset
   244
            size = sizeof(ec_slave_t) * master->slave_count;
5af7ab9a98b1 Minor change.
Florian Pose <fp@igh-essen.com>
parents: 1003
diff changeset
   245
            if (!(master->slaves = (ec_slave_t *) kmalloc(size, GFP_KERNEL))) {
5af7ab9a98b1 Minor change.
Florian Pose <fp@igh-essen.com>
parents: 1003
diff changeset
   246
                EC_ERR("Failed to allocate %u bytes of slave memory!\n",
5af7ab9a98b1 Minor change.
Florian Pose <fp@igh-essen.com>
parents: 1003
diff changeset
   247
                        size);
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
   248
                master->slave_count = 0; // TODO avoid retrying scan!
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   249
                master->scan_busy = 0;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   250
                wake_up_interruptible(&master->scan_queue);
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   251
                ec_fsm_master_restart(fsm);
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   252
                return;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   253
            }
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   254
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   255
            // init slaves
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   256
            for (i = 0; i < master->slave_count; i++) {
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   257
                slave = master->slaves + i;
992
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   258
                ec_slave_init(slave, master, i, i + 1);
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   259
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   260
                // do not force reconfiguration in operation phase to avoid
908
386b908033be Replaced self_configured flag with force_config flag.
Florian Pose <fp@igh-essen.com>
parents: 907
diff changeset
   261
                // unnecesssary process data interruptions
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   262
                if (master->phase != EC_OPERATION)
908
386b908033be Replaced self_configured flag with force_config flag.
Florian Pose <fp@igh-essen.com>
parents: 907
diff changeset
   263
                    slave->force_config = 1;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   264
            }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   265
904
ba6f222aa06e Removed some debugging.
Florian Pose <fp@igh-essen.com>
parents: 900
diff changeset
   266
            // broadcast clear all station addresses
717
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   267
            ec_datagram_bwr(datagram, 0x0010, 2);
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   268
            EC_WRITE_U16(datagram->data, 0x0000);
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   269
            fsm->retries = EC_FSM_RETRIES;
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   270
            fsm->state = ec_fsm_master_state_clear_addresses;
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   271
            return;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   272
        }
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   273
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   274
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   275
    if (master->slave_count) {
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   276
        // fetch state from first slave
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   277
        fsm->slave = master->slaves;
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   278
        ec_datagram_fprd(fsm->datagram, fsm->slave->station_address,
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   279
                0x0130, 2);
1225
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1219
diff changeset
   280
        ec_datagram_zero(datagram);
853
726326d0aef4 Fixed bug if scanning is not allowed when link goes up.
Florian Pose <fp@igh-essen.com>
parents: 849
diff changeset
   281
        fsm->retries = EC_FSM_RETRIES;
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   282
        fsm->state = ec_fsm_master_state_read_state;
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   283
    } else {
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   284
        ec_fsm_master_restart(fsm);
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   285
    }
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   286
}
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   287
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   288
/*****************************************************************************/
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   289
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   290
/** Check for pending SII write requests and process one.
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   291
 *
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   292
 * \return non-zero, if an SII write request is processed.
601
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   293
 */
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   294
int ec_fsm_master_action_process_sii(
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   295
        ec_fsm_master_t *fsm /**< Master state machine. */
601
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   296
        )
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   297
{
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   298
    ec_master_t *master = fsm->master;
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   299
    ec_sii_write_request_t *request;
601
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   300
604
74ceacf42710 Fixed possible race with next request pointer again.
Florian Pose <fp@igh-essen.com>
parents: 603
diff changeset
   301
    // search the first request to be processed
74ceacf42710 Fixed possible race with next request pointer again.
Florian Pose <fp@igh-essen.com>
parents: 603
diff changeset
   302
    while (1) {
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1064
diff changeset
   303
        if (list_empty(&master->sii_requests))
604
74ceacf42710 Fixed possible race with next request pointer again.
Florian Pose <fp@igh-essen.com>
parents: 603
diff changeset
   304
            break;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1064
diff changeset
   305
604
74ceacf42710 Fixed possible race with next request pointer again.
Florian Pose <fp@igh-essen.com>
parents: 603
diff changeset
   306
        // get first request
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   307
        request = list_entry(master->sii_requests.next,
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   308
                ec_sii_write_request_t, list);
601
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   309
        list_del_init(&request->list); // dequeue
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   310
        request->state = EC_INT_REQUEST_BUSY;
601
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   311
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   312
        // found pending SII write operation. execute it!
607
7b1daa325c5f Implemented alias reading/writing via sysfs.
Florian Pose <fp@igh-essen.com>
parents: 605
diff changeset
   313
        if (master->debug_level)
906
f95e3e33c0cf Removed slave online flag.
Florian Pose <fp@igh-essen.com>
parents: 905
diff changeset
   314
            EC_DBG("Writing SII data to slave %u...\n",
f95e3e33c0cf Removed slave online flag.
Florian Pose <fp@igh-essen.com>
parents: 905
diff changeset
   315
                    request->slave->ring_position);
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   316
        fsm->sii_request = request;
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   317
        fsm->sii_index = 0;
979
405cc2d033e0 Renamed some fields in ec_sii_request_t to word addressing.
Florian Pose <fp@igh-essen.com>
parents: 969
diff changeset
   318
        ec_fsm_sii_write(&fsm->fsm_sii, request->slave, request->offset,
405cc2d033e0 Renamed some fields in ec_sii_request_t to word addressing.
Florian Pose <fp@igh-essen.com>
parents: 969
diff changeset
   319
                request->words, EC_FSM_SII_USE_CONFIGURED_ADDRESS);
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   320
        fsm->state = ec_fsm_master_state_write_sii;
601
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   321
        fsm->state(fsm); // execute immediately
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   322
        return 1;
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   323
    }
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   324
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   325
    return 0;
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   326
}
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   327
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   328
/*****************************************************************************/
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   329
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   330
/** Check for pending phy requests and process one.
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   331
 * 
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   332
 * \return non-zero, if a phy request is processed.
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   333
 */
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   334
int ec_fsm_master_action_process_phy(
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   335
        ec_fsm_master_t *fsm /**< Master state machine. */
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   336
        )
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   337
{
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   338
    ec_master_t *master = fsm->master;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   339
    ec_phy_request_t *request;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   340
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   341
    // search the first request to be processed
1380
c2b0ef67e829 Improved phy debugging.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   342
    while (!list_empty(&master->phy_requests)) {
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   343
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   344
        // get first request
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   345
        request = list_entry(master->phy_requests.next,
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   346
                ec_phy_request_t, list);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   347
        list_del_init(&request->list); // dequeue
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   348
        request->state = EC_INT_REQUEST_BUSY;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   349
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   350
        // found pending request; process it!
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   351
        if (master->debug_level)
1380
c2b0ef67e829 Improved phy debugging.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   352
            EC_DBG("Processing phy request for slave %u, "
c2b0ef67e829 Improved phy debugging.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   353
                    "offset 0x%04x, length %u...\n",
c2b0ef67e829 Improved phy debugging.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   354
                    request->slave->ring_position,
c2b0ef67e829 Improved phy debugging.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   355
                    request->offset, request->length);
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   356
        fsm->phy_request = request;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   357
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   358
        if (request->dir == EC_DIR_INPUT) {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   359
            ec_datagram_fprd(fsm->datagram, request->slave->station_address,
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   360
                    request->offset, request->length);
1225
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1219
diff changeset
   361
            ec_datagram_zero(fsm->datagram);
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   362
        } else {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   363
            if (request->length > fsm->datagram->mem_size) {
1380
c2b0ef67e829 Improved phy debugging.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   364
                EC_ERR("Request length (%u) exceeds maximum "
c2b0ef67e829 Improved phy debugging.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   365
                        "datagram size (%u)!\n", request->length,
c2b0ef67e829 Improved phy debugging.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   366
                        fsm->datagram->mem_size);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   367
                request->state = EC_INT_REQUEST_FAILURE;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   368
                wake_up(&master->phy_queue);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   369
                continue;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   370
            }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   371
            ec_datagram_fpwr(fsm->datagram, request->slave->station_address,
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   372
                    request->offset, request->length);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   373
            memcpy(fsm->datagram->data, request->data, request->length);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   374
        }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   375
        fsm->retries = EC_FSM_RETRIES;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   376
        fsm->state = ec_fsm_master_state_phy_request;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   377
        return 1;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   378
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   379
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   380
    return 0;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   381
}
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   382
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   383
/*****************************************************************************/
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   384
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   385
/** Check for pending SDO requests and process one.
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   386
 *
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   387
 * \return non-zero, if an SDO request is processed.
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   388
 */
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   389
int ec_fsm_master_action_process_sdo(
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   390
        ec_fsm_master_t *fsm /**< Master state machine. */
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   391
        )
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   392
{
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   393
    ec_master_t *master = fsm->master;
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   394
    ec_slave_t *slave;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   395
    ec_sdo_request_t *req;
849
4b712ec8929d Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   396
    ec_master_sdo_request_t *request;
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   397
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   398
    // search for internal requests to be processed
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   399
    for (slave = master->slaves;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   400
            slave < master->slaves + master->slave_count;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   401
            slave++) {
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   402
        if (!slave->config)
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   403
            continue;
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   404
        list_for_each_entry(req, &slave->config->sdo_requests, list) {
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   405
            if (req->state == EC_INT_REQUEST_QUEUED) {
880
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
   406
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
   407
                if (ec_sdo_request_timed_out(req)) {
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   408
                    req->state = EC_INT_REQUEST_FAILURE;
880
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
   409
                    if (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
   410
                        EC_DBG("SDO request for slave %u timed out...\n",
880
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
   411
                                slave->ring_position);
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
   412
                    continue;
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
   413
                }
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   414
987
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   415
                if (slave->current_state == EC_SLAVE_STATE_INIT) {
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   416
                    req->state = EC_INT_REQUEST_FAILURE;
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   417
                    continue;
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   418
                }
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   419
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   420
                req->state = EC_INT_REQUEST_BUSY;
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   421
                if (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
   422
                    EC_DBG("Processing SDO request for slave %u...\n",
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   423
                            slave->ring_position);
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   424
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   425
                fsm->idle = 0;
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   426
                fsm->sdo_request = req;
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   427
                fsm->slave = slave;
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   428
                fsm->state = ec_fsm_master_state_sdo_request;
859
233e32f428e1 Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents: 858
diff changeset
   429
                ec_fsm_coe_transfer(&fsm->fsm_coe, slave, req);
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   430
                ec_fsm_coe_exec(&fsm->fsm_coe); // execute immediately
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   431
                return 1;
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   432
            }
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   433
        }
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   434
    }
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   435
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   436
    // search the first external request to be processed
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   437
    while (1) {
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1064
diff changeset
   438
        if (list_empty(&master->slave_sdo_requests))
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   439
            break;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1064
diff changeset
   440
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   441
        // get first request
849
4b712ec8929d Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   442
        request = list_entry(master->slave_sdo_requests.next,
4b712ec8929d Removed slave pointer from ec_sdo_request_t class.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   443
                ec_master_sdo_request_t, list);
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   444
        list_del_init(&request->list); // dequeue
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   445
        request->req.state = EC_INT_REQUEST_BUSY;
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   446
831
ded9519c8d6e Reading of Pdo mapping via CoE during scan.
Florian Pose <fp@igh-essen.com>
parents: 830
diff changeset
   447
        slave = request->slave;
969
e259df107c92 process Sdo requests even with error_flag set.
Florian Pose <fp@igh-essen.com>
parents: 930
diff changeset
   448
        if (slave->current_state == EC_SLAVE_STATE_INIT) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   449
            EC_ERR("Discarding SDO request, slave %u is in INIT.\n",
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   450
                    slave->ring_position);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   451
            request->req.state = EC_INT_REQUEST_FAILURE;
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   452
            wake_up(&master->sdo_queue);
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   453
            continue;
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   454
        }
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   455
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   456
        // Found pending SDO request. Execute it!
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   457
        if (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
   458
            EC_DBG("Processing SDO request for slave %u...\n",
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   459
                    slave->ring_position);
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   460
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   461
        // Start uploading SDO
650
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   462
        fsm->idle = 0;
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   463
        fsm->sdo_request = &request->req;
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   464
        fsm->slave = slave;
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   465
        fsm->state = ec_fsm_master_state_sdo_request;
859
233e32f428e1 Replaced ec_fsm_coe_\(upload\|download\)() with ec_fsm_coe_transfer();
Florian Pose <fp@igh-essen.com>
parents: 858
diff changeset
   466
        ec_fsm_coe_transfer(&fsm->fsm_coe, slave, &request->req);
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   467
        ec_fsm_coe_exec(&fsm->fsm_coe); // execute immediately
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   468
        return 1;
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   469
    }
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   470
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   471
    return 0;
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   472
}
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   473
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   474
/*****************************************************************************/
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   475
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   476
/** Check for pending FoE requests and process one.
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   477
 *
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   478
 * \return non-zero, if an FoE request is processed.
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   479
 */
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   480
int ec_fsm_master_action_process_foe(
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   481
        ec_fsm_master_t *fsm /**< Master state machine. */
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   482
        )
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   483
{
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   484
    ec_master_t *master = fsm->master;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   485
    ec_slave_t *slave;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   486
    ec_master_foe_request_t *request;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   487
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   488
    // search the first request to be processed
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   489
    while (1) {
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   490
        if (list_empty(&master->foe_requests))
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   491
            break;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   492
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   493
        // get first request
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   494
        request = list_entry(master->foe_requests.next,
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   495
                ec_master_foe_request_t, list);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   496
        list_del_init(&request->list); // dequeue
1349
9baba3568df4 Fixed FoE request states.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
   497
        request->req.state = EC_INT_REQUEST_BUSY;
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   498
        slave = request->slave;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   499
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   500
        if (master->debug_level)
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   501
            EC_DBG("Processing FoE request for slave %u.\n",
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   502
                    slave->ring_position);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   503
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   504
        fsm->foe_request = &request->req;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   505
        fsm->slave = slave;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   506
        fsm->state = ec_fsm_master_state_foe_request;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   507
        ec_fsm_foe_transfer(&fsm->fsm_foe, slave, &request->req);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   508
        ec_fsm_foe_exec(&fsm->fsm_foe);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   509
        return 1;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   510
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   511
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   512
    return 0;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   513
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   514
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   515
/*****************************************************************************/
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   516
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   517
/** Master action: IDLE.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   518
 *
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   519
 * Does secondary work.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   520
 */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   521
void ec_fsm_master_action_idle(
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   522
        ec_fsm_master_t *fsm /**< Master state machine. */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   523
        )
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   524
{
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   525
    ec_master_t *master = fsm->master;
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   526
    ec_slave_t *slave;
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   527
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   528
    // Check for pending SDO requests
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   529
    if (ec_fsm_master_action_process_sdo(fsm))
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   530
        return;
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   531
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   532
    // Check for pending FoE requests
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   533
    if (ec_fsm_master_action_process_foe(fsm))
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   534
        return;
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   535
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   536
    // check, if slaves have an SDO dictionary to read out.
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   537
    for (slave = master->slaves;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   538
            slave < master->slaves + master->slave_count;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   539
            slave++) {
910
9fd31755f576 Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   540
        if (!(slave->sii.mailbox_protocols & EC_MBOX_COE)
1219
aa030fb1e980 Only query Sdo information service, if slave supports it.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   541
                || (slave->sii.has_general
aa030fb1e980 Only query Sdo information service, if slave supports it.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   542
                    && !slave->sii.coe_details.enable_sdo_info)
442
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   543
                || slave->sdo_dictionary_fetched
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   544
                || slave->current_state == EC_SLAVE_STATE_INIT
1219
aa030fb1e980 Only query Sdo information service, if slave supports it.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   545
                || slave->current_state == EC_SLAVE_STATE_UNKNOWN
442
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   546
                || jiffies - slave->jiffies_preop < EC_WAIT_SDO_DICT * HZ
987
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   547
                ) continue;
442
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   548
910
9fd31755f576 Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   549
        if (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
   550
            EC_DBG("Fetching SDO dictionary from slave %u.\n",
910
9fd31755f576 Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   551
                    slave->ring_position);
441
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 437
diff changeset
   552
        }
442
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   553
910
9fd31755f576 Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   554
        slave->sdo_dictionary_fetched = 1;
9fd31755f576 Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   555
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   556
        // start fetching SDO dictionary
910
9fd31755f576 Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   557
        fsm->idle = 0;
9fd31755f576 Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   558
        fsm->slave = slave;
9fd31755f576 Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   559
        fsm->state = ec_fsm_master_state_sdo_dictionary;
9fd31755f576 Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   560
        ec_fsm_coe_dictionary(&fsm->fsm_coe, slave);
9fd31755f576 Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   561
        ec_fsm_coe_exec(&fsm->fsm_coe); // execute immediately
9fd31755f576 Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   562
        return;
9fd31755f576 Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   563
    }
9fd31755f576 Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   564
9fd31755f576 Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   565
    // check for pending SII write operations.
9fd31755f576 Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   566
    if (ec_fsm_master_action_process_sii(fsm))
9fd31755f576 Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   567
        return; // SII write request found
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   568
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   569
    // check for pending phy requests.
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   570
    if (ec_fsm_master_action_process_phy(fsm))
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   571
        return; // phy request processing
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   572
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   573
    ec_fsm_master_restart(fsm);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   574
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   575
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   576
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   577
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   578
/** Master action: Get state of next slave.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   579
 */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   580
void ec_fsm_master_action_next_slave_state(
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   581
        ec_fsm_master_t *fsm /**< Master state machine. */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   582
        )
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   583
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   584
    ec_master_t *master = fsm->master;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   585
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   586
    // is there another slave to query?
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   587
    fsm->slave++;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   588
    if (fsm->slave < master->slaves + master->slave_count) {
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   589
        // fetch state from next slave
650
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   590
        fsm->idle = 1;
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   591
        ec_datagram_fprd(fsm->datagram,
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   592
                fsm->slave->station_address, 0x0130, 2);
1225
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1219
diff changeset
   593
        ec_datagram_zero(fsm->datagram);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   594
        fsm->retries = EC_FSM_RETRIES;
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   595
        fsm->state = ec_fsm_master_state_read_state;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   596
        return;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   597
    }
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   598
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   599
    // all slaves processed
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   600
    ec_fsm_master_action_idle(fsm);
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   601
}
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   602
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   603
/*****************************************************************************/
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   604
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   605
/** Master action: Configure.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   606
 */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   607
void ec_fsm_master_action_configure(
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   608
        ec_fsm_master_t *fsm /**< Master state machine. */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   609
        )
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   610
{
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   611
    ec_master_t *master = fsm->master;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   612
    ec_slave_t *slave = fsm->slave;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   613
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   614
    // Does the slave have to be configured?
987
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   615
    if ((slave->current_state != slave->requested_state
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   616
                || slave->force_config) && !slave->error_flag) {
1177
03d9640c9ce4 Minor change.
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   617
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   618
        // Start slave configuration, if it is allowed.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   619
        down(&master->config_sem);
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   620
        if (!master->allow_config) {
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   621
            up(&master->config_sem);
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   622
        } else {
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   623
            master->config_busy = 1;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   624
            up(&master->config_sem);
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   625
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   626
            if (master->debug_level) {
908
386b908033be Replaced self_configured flag with force_config flag.
Florian Pose <fp@igh-essen.com>
parents: 907
diff changeset
   627
                char old_state[EC_STATE_STRING_SIZE],
386b908033be Replaced self_configured flag with force_config flag.
Florian Pose <fp@igh-essen.com>
parents: 907
diff changeset
   628
                     new_state[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: 1336
diff changeset
   629
                ec_state_string(slave->current_state, old_state, 0);
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1336
diff changeset
   630
                ec_state_string(slave->requested_state, new_state, 0);
908
386b908033be Replaced self_configured flag with force_config flag.
Florian Pose <fp@igh-essen.com>
parents: 907
diff changeset
   631
                EC_DBG("Changing state of slave %u from %s to %s%s.\n",
386b908033be Replaced self_configured flag with force_config flag.
Florian Pose <fp@igh-essen.com>
parents: 907
diff changeset
   632
                        slave->ring_position, old_state, new_state,
386b908033be Replaced self_configured flag with force_config flag.
Florian Pose <fp@igh-essen.com>
parents: 907
diff changeset
   633
                        slave->force_config ? " (forced)" : "");
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   634
            }
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   635
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   636
            fsm->idle = 0;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   637
            fsm->state = ec_fsm_master_state_configure_slave;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   638
            ec_fsm_slave_config_start(&fsm->fsm_slave_config, slave);
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   639
            fsm->state(fsm); // execute immediately
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   640
            return;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   641
        }
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   642
    }
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   643
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   644
    // slave has error flag set; process next one
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   645
    ec_fsm_master_action_next_slave_state(fsm);
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   646
}
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   647
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   648
/*****************************************************************************/
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   649
987
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   650
/** Master state: READ STATE.
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   651
 *
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   652
 * Fetches the AL state of a slave.
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   653
 */
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   654
void ec_fsm_master_state_read_state(
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   655
        ec_fsm_master_t *fsm /**< Master state machine. */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   656
        )
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   657
{
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   658
    ec_slave_t *slave = fsm->slave;
987
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   659
    ec_datagram_t *datagram = fsm->datagram;
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   660
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   661
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   662
        return;
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   663
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   664
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   665
        EC_ERR("Failed to receive AL state datagram for slave %u"
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   666
                " (datagram state %u)\n",
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   667
                slave->ring_position, datagram->state);
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   668
        ec_fsm_master_restart(fsm);
987
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   669
        return;
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   670
    }
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   671
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   672
    // did the slave not respond to its station address?
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   673
    if (datagram->working_counter != 1) {
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   674
        if (!slave->error_flag) {
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   675
            slave->error_flag = 1;
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   676
            if (fsm->master->debug_level)
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   677
                EC_DBG("Slave %u did not respond to state query.\n",
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   678
                        fsm->slave->ring_position);
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   679
        }
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   680
        fsm->topology_change_pending = 1;
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   681
        ec_fsm_master_restart(fsm);
987
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   682
        return;
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   683
    }
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   684
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   685
    // A single slave responded
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   686
    ec_slave_set_state(slave, EC_READ_U8(datagram->data));
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   687
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   688
    if (!slave->error_flag) {
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   689
        // Check, if new slave state has to be acknowledged
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   690
        if (slave->current_state & EC_SLAVE_STATE_ACK_ERR) {
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   691
            fsm->idle = 0;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   692
            fsm->state = ec_fsm_master_state_acknowledge;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   693
            ec_fsm_change_ack(&fsm->fsm_change, slave);
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   694
            fsm->state(fsm); // execute immediately
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   695
            return;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   696
        }
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   697
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   698
        // No acknowlegde necessary; check for configuration
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   699
        ec_fsm_master_action_configure(fsm);
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   700
        return;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   701
    }
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   702
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   703
    // slave has error flag set; process next one
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   704
    ec_fsm_master_action_next_slave_state(fsm);
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   705
}
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   706
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   707
/*****************************************************************************/
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   708
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   709
/** Master state: ACKNOWLEDGE.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   710
 */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   711
void ec_fsm_master_state_acknowledge(
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   712
        ec_fsm_master_t *fsm /**< Master state machine. */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   713
        )
454
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   714
{
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   715
    ec_slave_t *slave = fsm->slave;
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   716
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   717
    if (ec_fsm_change_exec(&fsm->fsm_change))
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   718
        return;
454
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   719
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   720
    if (!ec_fsm_change_success(&fsm->fsm_change)) {
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   721
        fsm->slave->error_flag = 1;
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   722
        EC_ERR("Failed to acknowledge state change on slave %u.\n",
454
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   723
               slave->ring_position);
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   724
    }
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   725
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   726
    ec_fsm_master_action_configure(fsm);
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   727
}
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   728
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   729
/*****************************************************************************/
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   730
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   731
/** Master state: CLEAR ADDRESSES.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   732
 */
717
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   733
void ec_fsm_master_state_clear_addresses(
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   734
        ec_fsm_master_t *fsm /**< Master state machine. */
717
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   735
        )
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   736
{
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   737
    ec_master_t *master = fsm->master;
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   738
    ec_datagram_t *datagram = fsm->datagram;
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   739
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   740
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   741
        return;
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   742
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   743
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 979
diff changeset
   744
        EC_ERR("Failed to receive address clearing datagram (state %u).\n",
717
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   745
                datagram->state);
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 880
diff changeset
   746
        master->scan_busy = 0;
794
684dea874956 Allow bus configuration when link is down.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   747
        wake_up_interruptible(&master->scan_queue);
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   748
        ec_fsm_master_restart(fsm);
717
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   749
        return;
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   750
    }
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   751
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   752
    if (datagram->working_counter != master->slave_count) {
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   753
        EC_WARN("Failed to clear all station addresses: Cleared %u of %u",
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   754
                datagram->working_counter, master->slave_count);
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   755
    }
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   756
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   757
    EC_INFO("Scanning bus.\n");
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   758
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   759
    // begin scanning of slaves
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   760
    fsm->slave = master->slaves;
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   761
    fsm->state = ec_fsm_master_state_scan_slave;
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   762
    ec_fsm_slave_scan_start(&fsm->fsm_slave_scan, fsm->slave);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   763
    ec_fsm_slave_scan_exec(&fsm->fsm_slave_scan); // execute immediately
717
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   764
}
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   765
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   766
/*****************************************************************************/
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   767
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   768
/** Master state: SCAN SLAVE.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   769
 *
652
15cff76b66c7 Added scan time output.
Florian Pose <fp@igh-essen.com>
parents: 650
diff changeset
   770
 * Executes the sub-statemachine for the scanning of a slave.
15cff76b66c7 Added scan time output.
Florian Pose <fp@igh-essen.com>
parents: 650
diff changeset
   771
 */
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   772
void ec_fsm_master_state_scan_slave(
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   773
        ec_fsm_master_t *fsm /**< Master state machine. */
652
15cff76b66c7 Added scan time output.
Florian Pose <fp@igh-essen.com>
parents: 650
diff changeset
   774
        )
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   775
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   776
    ec_master_t *master = fsm->master;
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   777
#ifdef EC_EOE
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   778
    ec_slave_t *slave = fsm->slave;
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   779
#endif
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   780
    if (ec_fsm_slave_scan_exec(&fsm->fsm_slave_scan))
528
f789bdd78b54 Layed out slave state machines in own files fsm_slave.[ch]; renamed fsm.[ch] to fsm_master.[ch]
Florian Pose <fp@igh-essen.com>
parents: 523
diff changeset
   781
        return;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   782
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   783
#ifdef EC_EOE
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   784
    if (slave->sii.mailbox_protocols & EC_MBOX_EOE) {
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   785
        // create EoE handler for this slave
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   786
        ec_eoe_t *eoe;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   787
        if (!(eoe = kmalloc(sizeof(ec_eoe_t), GFP_KERNEL))) {
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   788
            EC_ERR("Failed to allocate EoE handler memory for slave %u!\n",
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   789
                    slave->ring_position);
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 880
diff changeset
   790
        } else if (ec_eoe_init(eoe, slave)) {
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   791
            EC_ERR("Failed to init EoE handler for slave %u!\n",
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   792
                    slave->ring_position);
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   793
            kfree(eoe);
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 880
diff changeset
   794
        } else {
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   795
            list_add_tail(&eoe->list, &master->eoe_handlers);
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   796
        }
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   797
    }
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   798
#endif
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   799
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   800
    // another slave to fetch?
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   801
    fsm->slave++;
1002
0e1aaeb3540d Fixed bug in slave scanning, causing a segmentation fault.
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   802
    if (fsm->slave < master->slaves + master->slave_count) {
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   803
        ec_fsm_slave_scan_start(&fsm->fsm_slave_scan, fsm->slave);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   804
        ec_fsm_slave_scan_exec(&fsm->fsm_slave_scan); // execute immediately
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   805
        return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   806
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   807
652
15cff76b66c7 Added scan time output.
Florian Pose <fp@igh-essen.com>
parents: 650
diff changeset
   808
    EC_INFO("Bus scanning completed in %u ms.\n",
15cff76b66c7 Added scan time output.
Florian Pose <fp@igh-essen.com>
parents: 650
diff changeset
   809
            (u32) (jiffies - fsm->scan_jiffies) * 1000 / HZ);
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   810
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 880
diff changeset
   811
    master->scan_busy = 0;
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 880
diff changeset
   812
    wake_up_interruptible(&master->scan_queue);
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 880
diff changeset
   813
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   814
    // Attach slave configurations
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   815
    ec_master_attach_slave_configs(master);
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   816
716
ac2a81a33d3d Minor fix.
Florian Pose <fp@igh-essen.com>
parents: 715
diff changeset
   817
#ifdef EC_EOE
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   818
    // check if EoE processing has to be started
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   819
    ec_master_eoe_start(master);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   820
#endif
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   821
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   822
    ec_fsm_master_restart(fsm);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   823
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   824
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   825
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   826
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   827
/** Master state: CONFIGURE SLAVE.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   828
 *
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   829
 * Starts configuring a slave.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   830
 */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   831
void ec_fsm_master_state_configure_slave(
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   832
        ec_fsm_master_t *fsm /**< Master state machine. */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   833
        )
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   834
{
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   835
    ec_master_t *master = fsm->master;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   836
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   837
    if (ec_fsm_slave_config_exec(&fsm->fsm_slave_config))
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   838
        return;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   839
1277
1189e040fe12 merge -c1521 branches/stable-1.4: Fixed race concerning ec_slave_config_state->operational.
Florian Pose <fp@igh-essen.com>
parents: 1225
diff changeset
   840
    fsm->slave->force_config = 0;
1189e040fe12 merge -c1521 branches/stable-1.4: Fixed race concerning ec_slave_config_state->operational.
Florian Pose <fp@igh-essen.com>
parents: 1225
diff changeset
   841
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   842
    // configuration finished
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   843
    master->config_busy = 0;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   844
    wake_up_interruptible(&master->config_queue);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   845
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 880
diff changeset
   846
    if (!ec_fsm_slave_config_success(&fsm->fsm_slave_config)) {
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 880
diff changeset
   847
        // TODO: mark slave_config as failed.
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 880
diff changeset
   848
    }
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   849
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   850
    fsm->idle = 1;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   851
    ec_fsm_master_action_next_slave_state(fsm);
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   852
}
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   853
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   854
/*****************************************************************************/
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   855
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   856
/** Master state: WRITE SII.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   857
 */
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   858
void ec_fsm_master_state_write_sii(
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   859
        ec_fsm_master_t *fsm /**< Master state machine. */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   860
        )
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   861
{
601
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   862
    ec_master_t *master = fsm->master;
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   863
    ec_sii_write_request_t *request = fsm->sii_request;
601
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   864
    ec_slave_t *slave = request->slave;
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   865
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
   866
    if (ec_fsm_sii_exec(&fsm->fsm_sii)) return;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   867
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   868
    if (!ec_fsm_sii_success(&fsm->fsm_sii)) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 979
diff changeset
   869
        EC_ERR("Failed to write SII data to slave %u.\n",
607
7b1daa325c5f Implemented alias reading/writing via sysfs.
Florian Pose <fp@igh-essen.com>
parents: 605
diff changeset
   870
                slave->ring_position);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   871
        request->state = EC_INT_REQUEST_FAILURE;
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   872
        wake_up(&master->sii_queue);
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   873
        ec_fsm_master_restart(fsm);
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   874
        return;
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   875
    }
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   876
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   877
    fsm->sii_index++;
979
405cc2d033e0 Renamed some fields in ec_sii_request_t to word addressing.
Florian Pose <fp@igh-essen.com>
parents: 969
diff changeset
   878
    if (fsm->sii_index < request->nwords) {
601
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   879
        ec_fsm_sii_write(&fsm->fsm_sii, slave,
979
405cc2d033e0 Renamed some fields in ec_sii_request_t to word addressing.
Florian Pose <fp@igh-essen.com>
parents: 969
diff changeset
   880
                request->offset + fsm->sii_index,
405cc2d033e0 Renamed some fields in ec_sii_request_t to word addressing.
Florian Pose <fp@igh-essen.com>
parents: 969
diff changeset
   881
                request->words + fsm->sii_index,
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
   882
                EC_FSM_SII_USE_CONFIGURED_ADDRESS);
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   883
        ec_fsm_sii_exec(&fsm->fsm_sii); // execute immediately
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   884
        return;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   885
    }
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   886
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   887
    // finished writing SII
607
7b1daa325c5f Implemented alias reading/writing via sysfs.
Florian Pose <fp@igh-essen.com>
parents: 605
diff changeset
   888
    if (master->debug_level)
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   889
        EC_DBG("Finished writing %u words of SII data to slave %u.\n",
979
405cc2d033e0 Renamed some fields in ec_sii_request_t to word addressing.
Florian Pose <fp@igh-essen.com>
parents: 969
diff changeset
   890
                request->nwords, slave->ring_position);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1064
diff changeset
   891
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1064
diff changeset
   892
    if (request->offset <= 4 && request->offset + request->nwords > 4) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1064
diff changeset
   893
        // alias was written
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1064
diff changeset
   894
        slave->sii.alias = EC_READ_U16(request->words + 4);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1064
diff changeset
   895
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1064
diff changeset
   896
    // TODO: Evaluate other SII contents!
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   897
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   898
    request->state = EC_INT_REQUEST_SUCCESS;
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   899
    wake_up(&master->sii_queue);
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   900
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   901
    // check for another SII write request
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   902
    if (ec_fsm_master_action_process_sii(fsm))
601
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   903
        return; // processing another request
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   904
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   905
    ec_fsm_master_restart(fsm);
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   906
}
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   907
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   908
/*****************************************************************************/
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   909
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   910
/** Master state: WRITE FOE.
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   911
 */
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   912
void ec_fsm_master_state_foe_request(
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   913
		ec_fsm_master_t *fsm /**< Master state machine. */
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   914
        )
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   915
{
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   916
    ec_master_t *master = fsm->master;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   917
    ec_foe_request_t *request = fsm->foe_request;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   918
    ec_slave_t *slave = fsm->slave;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   919
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   920
    if (ec_fsm_foe_exec(&fsm->fsm_foe))
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   921
        return;
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   922
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   923
    if (!ec_fsm_foe_success(&fsm->fsm_foe)) {
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   924
        EC_ERR("Failed to handle FoE request to slave %u.\n",
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   925
                slave->ring_position);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   926
        request->state = EC_INT_REQUEST_FAILURE;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   927
        wake_up(&master->foe_queue);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   928
        ec_fsm_master_restart(fsm);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   929
        return;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   930
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   931
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   932
    // finished transferring FoE
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   933
    if (master->debug_level)
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   934
        EC_DBG("Successfully transferred %u bytes of FoE data from/to"
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
   935
                " slave %u.\n", request->data_size, slave->ring_position);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   936
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   937
    request->state = EC_INT_REQUEST_SUCCESS;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   938
    wake_up(&master->foe_queue);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   939
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   940
    ec_fsm_master_restart(fsm);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   941
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   942
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   943
/*****************************************************************************/
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   944
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   945
/** Master state: SDO DICTIONARY.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   946
 */
905
6d74ebc603ee Renamed state sdodict to sdo_dictionary.
Florian Pose <fp@igh-essen.com>
parents: 904
diff changeset
   947
void ec_fsm_master_state_sdo_dictionary(
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   948
        ec_fsm_master_t *fsm /**< Master state machine. */
905
6d74ebc603ee Renamed state sdodict to sdo_dictionary.
Florian Pose <fp@igh-essen.com>
parents: 904
diff changeset
   949
        )
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   950
{
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   951
    ec_slave_t *slave = fsm->slave;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   952
    ec_master_t *master = fsm->master;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   953
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   954
    if (ec_fsm_coe_exec(&fsm->fsm_coe)) return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   955
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   956
    if (!ec_fsm_coe_success(&fsm->fsm_coe)) {
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   957
        ec_fsm_master_restart(fsm);
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   958
        return;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   959
    }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   960
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   961
    // SDO dictionary fetching finished
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   962
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   963
    if (master->debug_level) {
423
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
   964
        unsigned int sdo_count, entry_count;
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
   965
        ec_slave_sdo_dict_info(slave, &sdo_count, &entry_count);
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   966
        EC_DBG("Fetched %u SDOs and %u entries from slave %u.\n",
423
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
   967
               sdo_count, entry_count, slave->ring_position);
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   968
    }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   969
1186
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1177
diff changeset
   970
    // attach pdo names from dictionary
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1177
diff changeset
   971
    ec_slave_attach_pdo_names(slave);
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1177
diff changeset
   972
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   973
    ec_fsm_master_restart(fsm);
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   974
}
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   975
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   976
/*****************************************************************************/
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   977
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   978
/** Master state: SDO REQUEST.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   979
 */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   980
void ec_fsm_master_state_sdo_request(
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   981
        ec_fsm_master_t *fsm /**< Master state machine. */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   982
        )
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   983
{
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   984
    ec_master_t *master = fsm->master;
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   985
    ec_sdo_request_t *request = fsm->sdo_request;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   986
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   987
    if (ec_fsm_coe_exec(&fsm->fsm_coe)) return;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   988
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   989
    if (!ec_fsm_coe_success(&fsm->fsm_coe)) {
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   990
        EC_DBG("Failed to process SDO request for slave %u.\n",
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   991
                fsm->slave->ring_position);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   992
        request->state = EC_INT_REQUEST_FAILURE;
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   993
        wake_up(&master->sdo_queue);
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   994
        ec_fsm_master_restart(fsm);
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   995
        return;
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   996
    }
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   997
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   998
    // SDO request finished
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   999
    request->state = EC_INT_REQUEST_SUCCESS;
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
  1000
    wake_up(&master->sdo_queue);
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
  1001
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
  1002
    if (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
  1003
        EC_DBG("Finished SDO request for slave %u.\n",
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
  1004
                fsm->slave->ring_position);
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
  1005
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1006
    // check for another SDO request
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
  1007
    if (ec_fsm_master_action_process_sdo(fsm))
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
  1008
        return; // processing another request
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
  1009
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
  1010
    ec_fsm_master_restart(fsm);
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
  1011
}
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
  1012
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
  1013
/*****************************************************************************/
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1014
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1015
/** Master state: PHY.
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1016
 */
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1017
void ec_fsm_master_state_phy_request(
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1018
        ec_fsm_master_t *fsm /**< Master state machine. */
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1019
        )
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1020
{
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1021
    ec_master_t *master = fsm->master;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1022
    ec_datagram_t *datagram = fsm->datagram;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1023
    ec_phy_request_t *request = fsm->phy_request;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1024
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1025
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1026
        EC_ERR("Failed to receive phy request datagram (state %u).\n",
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1027
                datagram->state);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1028
        request->state = EC_INT_REQUEST_FAILURE;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1029
        wake_up(&master->phy_queue);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1030
        ec_fsm_master_restart(fsm);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1031
        return;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1032
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1033
    
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1034
    if (request->dir == EC_DIR_INPUT) { // read request
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1035
        if (request->data)
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1036
            kfree(request->data);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1037
        request->data = kmalloc(request->length, GFP_KERNEL);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1038
        if (!request->data) {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1039
            EC_ERR("Failed to allocate %u bytes of memory for phy request.\n",
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1040
                    request->length);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1041
            request->state = EC_INT_REQUEST_FAILURE;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1042
            wake_up(&master->phy_queue);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1043
            ec_fsm_master_restart(fsm);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1044
            return;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1045
        }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1046
        memcpy(request->data, datagram->data, request->length);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1047
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1048
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1049
    request->state = EC_INT_REQUEST_SUCCESS;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1050
    wake_up(&master->phy_queue);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1051
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1052
    // check for another PHY request
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1053
    if (ec_fsm_master_action_process_phy(fsm))
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1054
        return; // processing another request
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1055
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1056
    ec_fsm_master_restart(fsm);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1057
}
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1058
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1059
/*****************************************************************************/