master/fsm_master.c
author Florian Pose <fp@igh-essen.com>
Mon, 05 Dec 2011 11:29:28 +0100
changeset 2164 cf4db3c282d2
parent 2146 05c6ddef33ab
child 2166 1d5a5303f15c
permissions -rw-r--r--
Fixed compiler error in master.c; thanks to Jun Yuan.
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
 *
2145
a63ed5513117 Fixed typo.
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
     3
 *  $Id: fsm_master.c,v afb40fd6018e 2011/09/16 12:10:23 fp $
238
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
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
    49
/** Time difference [ns] to tolerate without setting a new system time offset.
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
    50
 */
1998
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1995
diff changeset
    51
#ifdef EC_HAVE_CYCLES
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1995
diff changeset
    52
#define EC_SYSTEM_TIME_TOLERANCE_NS 10000
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1995
diff changeset
    53
#else
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
    54
#define EC_SYSTEM_TIME_TOLERANCE_NS 100000000
1998
0330fdcbdd1f Use ESC port order (0-3-1-2) for bus topology and DC delay calculation
Martin Troxler <ch1010277@ch10pc446>
parents: 1995
diff changeset
    55
#endif
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
    56
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
    57
/*****************************************************************************/
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
    58
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
    59
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
    60
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
    61
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
    62
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
    63
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
    64
void ec_fsm_master_state_clear_addresses(ec_fsm_master_t *);
1420
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
    65
void ec_fsm_master_state_dc_measure_delays(ec_fsm_master_t *);
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
    66
void ec_fsm_master_state_scan_slave(ec_fsm_master_t *);
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
    67
void ec_fsm_master_state_dc_read_offset(ec_fsm_master_t *);
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
    68
void ec_fsm_master_state_dc_write_offset(ec_fsm_master_t *);
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
    69
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
    70
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
    71
void ec_fsm_master_state_sdo_request(ec_fsm_master_t *);
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
    72
void ec_fsm_master_state_reg_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
    73
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
    74
void ec_fsm_master_enter_write_system_times(ec_fsm_master_t *);
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1579
diff changeset
    75
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
    78
/** Constructor.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
    79
 */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
    80
void ec_fsm_master_init(
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
    81
        ec_fsm_master_t *fsm, /**< Master state machine. */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
    82
        ec_master_t *master, /**< EtherCAT master. */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
    83
        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
    84
        )
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
    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
    87
    fsm->datagram = datagram;
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 2044
diff changeset
    88
    fsm->mbox = &master->fsm_mbox;
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
    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
    90
    fsm->idle = 0;
1400
3c4923051e43 Clear slave list on link down.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
    91
    fsm->link_state = 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
    92
    fsm->slaves_responding = 0;
1961
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
    93
    fsm->rescan_required = 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
    94
    fsm->slave_states = EC_SLAVE_STATE_UNKNOWN;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
    96
    // init sub-state-machines
2045
ff2a13a4603c Reduced frame size when sending to mailbox, uses 2 datagrams. Enabled with configure option --enable-mboxframesize
Martin Troxler <ch1010277@ch10pc446>
parents: 2044
diff changeset
    97
    ec_fsm_coe_init(&fsm->fsm_coe, fsm->mbox);
1174
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1079
diff changeset
    98
    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
    99
    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
   100
    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
   101
            &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
   102
    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
   103
            &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
   104
    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
   105
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   109
/** Destructor.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   110
 */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   111
void ec_fsm_master_clear(
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   112
        ec_fsm_master_t *fsm /**< Master state machine. */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   113
        )
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
{
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   115
    // 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
   116
    ec_fsm_coe_clear(&fsm->fsm_coe);
235f34ca50e2 Major Pdo configuration change: Read mapping of unknown Pdos during
Florian Pose <fp@igh-essen.com>
parents: 1079
diff changeset
   117
    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
   118
    ec_fsm_change_clear(&fsm->fsm_change);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   119
    ec_fsm_slave_config_clear(&fsm->fsm_slave_config);
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   120
    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
   121
    ec_fsm_sii_clear(&fsm->fsm_sii);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   126
/** Executes the current state of the state machine.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   127
 *
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   128
 * 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
   129
 * of the state machine is delayed to the next cycle.
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1579
diff changeset
   130
 *
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1579
diff changeset
   131
 * \return true, if the state machine was executed
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1579
diff changeset
   132
 */
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1579
diff changeset
   133
int ec_fsm_master_exec(
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   134
        ec_fsm_master_t *fsm /**< Master state machine. */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   135
        )
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
   136
{
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   137
    if (ec_mbox_is_datagram_state(fsm->mbox, EC_DATAGRAM_QUEUED)
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   138
        || ec_mbox_is_datagram_state(fsm->mbox, EC_DATAGRAM_SENT)) {
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   139
        // datagram was not sent or received yet.
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1579
diff changeset
   140
        return 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
   141
    }
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   142
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
   143
    fsm->state(fsm);
1583
017fa8fd9ac1 Each slave got its own SDO state machine (faster handling of external SDO requests)
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1579
diff changeset
   144
    return 1;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   145
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   146
650
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   147
/*****************************************************************************/
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   148
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   149
/**
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   150
 * \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
   151
 */
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   152
int ec_fsm_master_idle(
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   153
        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
   154
        )
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   155
{
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   156
    return fsm->idle;
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   157
}
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   158
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   159
/*****************************************************************************/
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   160
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   161
/** 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
   162
 */
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   163
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
   164
        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
   165
        )
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   166
{
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   167
    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
   168
    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
   169
}
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   170
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
/******************************************************************************
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   172
 * Master state machine
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
 *****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   175
/** Master state: START.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   176
 *
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   177
 * Starts with getting slave count and slave states.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   178
 */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   179
void ec_fsm_master_state_start(
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   180
        ec_fsm_master_t *fsm /**< Master state machine. */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   181
        )
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
   182
{
650
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   183
    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
   184
    ec_datagram_brd(fsm->datagram, 0x0130, 2);
1225
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1219
diff changeset
   185
    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
   186
    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
   187
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   188
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   189
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   190
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   191
/** Master state: BROADCAST.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   192
 *
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   193
 * Processes the broadcast read slave count and slaves states.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   194
 */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   195
void ec_fsm_master_state_broadcast(
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   196
        ec_fsm_master_t *fsm /**< Master state machine. */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   197
        )
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
   198
{
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
   199
    ec_datagram_t *datagram = fsm->datagram;
1005
5af7ab9a98b1 Minor change.
Florian Pose <fp@igh-essen.com>
parents: 1003
diff changeset
   200
    unsigned int i, size;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
    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
   202
    ec_master_t *master = fsm->master;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   204
    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
   205
        return; // always retry
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   206
553
a4e0267825e3 Introduced topology_change_pending to delay bus scanning until IDLE mode
Florian Pose <fp@igh-essen.com>
parents: 538
diff changeset
   207
    // 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
   208
    if (datagram->working_counter != fsm->slaves_responding) {
1961
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
   209
        fsm->rescan_required = 1;
553
a4e0267825e3 Introduced topology_change_pending to delay bus scanning until IDLE mode
Florian Pose <fp@igh-essen.com>
parents: 538
diff changeset
   210
        fsm->slaves_responding = datagram->working_counter;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   211
        EC_MASTER_INFO(master, "%u slave(s) responding.\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   212
                fsm->slaves_responding);
906
f95e3e33c0cf Removed slave online flag.
Florian Pose <fp@igh-essen.com>
parents: 905
diff changeset
   213
    }
f95e3e33c0cf Removed slave online flag.
Florian Pose <fp@igh-essen.com>
parents: 905
diff changeset
   214
2146
05c6ddef33ab Fixed missing return causing slaves not going to OP.
Florian Pose <fp@igh-essen.com>
parents: 2145
diff changeset
   215
    if (fsm->link_state && !master->main_device.link_state) {
05c6ddef33ab Fixed missing return causing slaves not going to OP.
Florian Pose <fp@igh-essen.com>
parents: 2145
diff changeset
   216
        // link went down
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   217
        EC_MASTER_DBG(master, 1, "Master state machine detected "
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   218
                "link down. Clearing slave list.\n");
1402
4c1203ec569d Tested clearing slave list after link down; minor changes.
Florian Pose <fp@igh-essen.com>
parents: 1400
diff changeset
   219
1400
3c4923051e43 Clear slave list on link down.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   220
        ec_master_clear_slaves(master);
1830
ef09f0ea0c4c Reset AL states on link down.
Florian Pose <fp@igh-essen.com>
parents: 1822
diff changeset
   221
        fsm->slave_states = 0x00;
1400
3c4923051e43 Clear slave list on link down.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   222
    }
3c4923051e43 Clear slave list on link down.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   223
    fsm->link_state = master->main_device.link_state;
3c4923051e43 Clear slave list on link down.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
   224
1402
4c1203ec569d Tested clearing slave list after link down; minor changes.
Florian Pose <fp@igh-essen.com>
parents: 1400
diff changeset
   225
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   226
        ec_fsm_master_restart(fsm);
906
f95e3e33c0cf Removed slave online flag.
Florian Pose <fp@igh-essen.com>
parents: 905
diff changeset
   227
        return;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   228
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   229
1021
fa5cf205f4f0 Set slave_states to 0x00 when no slaves are present.
Florian Pose <fp@igh-essen.com>
parents: 1005
diff changeset
   230
    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
   231
        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
   232
        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
   233
            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
   234
            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
   235
            ec_state_string(fsm->slave_states, state_str, 1);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   236
            EC_MASTER_INFO(master, "Slave states: %s.\n", state_str);
1021
fa5cf205f4f0 Set slave_states to 0x00 when no slaves are present.
Florian Pose <fp@igh-essen.com>
parents: 1005
diff changeset
   237
        }
fa5cf205f4f0 Set slave_states to 0x00 when no slaves are present.
Florian Pose <fp@igh-essen.com>
parents: 1005
diff changeset
   238
    } else {
fa5cf205f4f0 Set slave_states to 0x00 when no slaves are present.
Florian Pose <fp@igh-essen.com>
parents: 1005
diff changeset
   239
        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
   240
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   241
1961
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
   242
    if (fsm->rescan_required) {
2028
55854f070c4a use rt_mutex instead of semaphore for mutual exclusion (use --enable-mutex)
Martin Troxler <ch1010277@ch10pc446>
parents: 2027
diff changeset
   243
        ec_mutex_lock(&master->scan_mutex);
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   244
        if (!master->allow_scan) {
2028
55854f070c4a use rt_mutex instead of semaphore for mutual exclusion (use --enable-mutex)
Martin Troxler <ch1010277@ch10pc446>
parents: 2027
diff changeset
   245
            ec_mutex_unlock(&master->scan_mutex);
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 880
diff changeset
   246
        } else {
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 880
diff changeset
   247
            master->scan_busy = 1;
2028
55854f070c4a use rt_mutex instead of semaphore for mutual exclusion (use --enable-mutex)
Martin Troxler <ch1010277@ch10pc446>
parents: 2027
diff changeset
   248
            ec_mutex_unlock(&master->scan_mutex);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   249
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   250
            // clear all slaves and scan the bus
1961
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
   251
            fsm->rescan_required = 0;
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   252
            fsm->idle = 0;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   253
            fsm->scan_jiffies = jiffies;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   254
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   255
#ifdef EC_EOE
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   256
            ec_master_clear_eoe_handlers(master);
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   257
#endif
992
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   258
            ec_master_clear_slaves(master);
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   259
1003
f7cf194d6979 Minor change.
Florian Pose <fp@igh-essen.com>
parents: 1002
diff changeset
   260
            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
   261
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   262
            if (!master->slave_count) {
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   263
                // 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
   264
                master->scan_busy = 0;
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   265
                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
   266
                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
   267
                return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   268
            }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   269
1005
5af7ab9a98b1 Minor change.
Florian Pose <fp@igh-essen.com>
parents: 1003
diff changeset
   270
            size = sizeof(ec_slave_t) * master->slave_count;
2146
05c6ddef33ab Fixed missing return causing slaves not going to OP.
Florian Pose <fp@igh-essen.com>
parents: 2145
diff changeset
   271
            if (!(master->slaves =
05c6ddef33ab Fixed missing return causing slaves not going to OP.
Florian Pose <fp@igh-essen.com>
parents: 2145
diff changeset
   272
                        (ec_slave_t *) kmalloc(size, GFP_KERNEL))) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   273
                EC_MASTER_ERR(master, "Failed to allocate %u bytes"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   274
                        " of slave memory!\n", size);
1064
5f27403587a8 Avoid duplicate reconfiguration.
Florian Pose <fp@igh-essen.com>
parents: 1031
diff changeset
   275
                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
   276
                master->scan_busy = 0;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   277
                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
   278
                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
   279
                return;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   280
            }
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   281
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   282
            // init slaves
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   283
            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
   284
                slave = master->slaves + i;
992
50a44cbd30af Removed kobjects from sdo and slave.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   285
                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
   286
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   287
                // 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
   288
                // unnecesssary process data interruptions
1029
61ffe5f22306 Renamed master 'mode' to 'phase'.
Florian Pose <fp@igh-essen.com>
parents: 1028
diff changeset
   289
                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
   290
                    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
   291
            }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   292
904
ba6f222aa06e Removed some debugging.
Florian Pose <fp@igh-essen.com>
parents: 900
diff changeset
   293
            // 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
   294
            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
   295
            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
   296
            fsm->retries = EC_FSM_RETRIES;
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   297
            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
   298
            return;
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   299
        }
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   300
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   301
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   302
    if (master->slave_count) {
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   303
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   304
        // application applied configurations
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   305
        if (master->config_changed) {
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   306
            master->config_changed = 0;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   307
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   308
            EC_MASTER_DBG(master, 1, "Configuration changed.\n");
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   309
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   310
            fsm->slave = master->slaves; // begin with first slave
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   311
            ec_fsm_master_enter_write_system_times(fsm);
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   312
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   313
        } else {
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   314
            // fetch state from first slave
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   315
            fsm->slave = master->slaves;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   316
            ec_datagram_fprd(fsm->datagram, fsm->slave->station_address,
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   317
                    0x0130, 2);
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   318
            ec_datagram_zero(datagram);
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   319
            fsm->retries = EC_FSM_RETRIES;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   320
            fsm->state = ec_fsm_master_state_read_state;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   321
        }
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   322
    } else {
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   323
        ec_fsm_master_restart(fsm);
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   324
    }
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   325
}
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   326
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   327
/*****************************************************************************/
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   328
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   329
/** 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
   330
 *
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   331
 * \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
   332
 */
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   333
int ec_fsm_master_action_process_sii(
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   334
        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
   335
        )
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   336
{
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   337
    ec_master_t *master = fsm->master;
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   338
    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
   339
604
74ceacf42710 Fixed possible race with next request pointer again.
Florian Pose <fp@igh-essen.com>
parents: 603
diff changeset
   340
    // 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
   341
    while (1) {
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1064
diff changeset
   342
        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
   343
            break;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1064
diff changeset
   344
604
74ceacf42710 Fixed possible race with next request pointer again.
Florian Pose <fp@igh-essen.com>
parents: 603
diff changeset
   345
        // get first request
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   346
        request = list_entry(master->sii_requests.next,
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   347
                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
   348
        list_del_init(&request->list); // dequeue
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   349
        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
   350
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   351
        // found pending SII write operation. execute it!
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   352
        EC_SLAVE_DBG(request->slave, 1, "Writing SII data...\n");
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   353
        fsm->sii_request = request;
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   354
        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
   355
        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
   356
                request->words, EC_FSM_SII_USE_CONFIGURED_ADDRESS);
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
   357
        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
   358
        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
   359
        return 1;
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   360
    }
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   361
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   362
    return 0;
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   363
}
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   364
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   365
/*****************************************************************************/
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
   366
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
   367
/** Check for pending register requests and process one.
1579
326d47aa986c applied komax patch to version r1822
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1507
diff changeset
   368
 *
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
   369
 * \return non-zero, if a register request is processed.
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
   370
 */
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
   371
int ec_fsm_master_action_process_register(
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
   372
        ec_fsm_master_t *fsm /**< Master state machine. */
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
   373
        )
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
   374
{
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
   375
    ec_master_t *master = fsm->master;
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
   376
    ec_reg_request_t *request;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   377
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   378
    // search the first request to be processed
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
   379
    while (!list_empty(&master->reg_requests)) {
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   380
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   381
        // get first request
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
   382
        request = list_entry(master->reg_requests.next,
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
   383
                ec_reg_request_t, list);
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   384
        list_del_init(&request->list); // dequeue
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   385
        request->state = EC_INT_REQUEST_BUSY;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   386
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   387
        // found pending request; process it!
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   388
        EC_SLAVE_DBG(request->slave, 1, "Processing register request, "
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   389
                "offset 0x%04x, length %zu...\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   390
                request->offset, request->length);
1386
95ec1e9bcb53 Check phy_request length for read operations, too!
Florian Pose <fp@igh-essen.com>
parents: 1385
diff changeset
   391
95ec1e9bcb53 Check phy_request length for read operations, too!
Florian Pose <fp@igh-essen.com>
parents: 1385
diff changeset
   392
        if (request->length > fsm->datagram->mem_size) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   393
            EC_MASTER_ERR(master, "Request length (%zu) exceeds maximum "
1543
373cd456dc26 Avoid warnings on x86_64 platform. Thanks to Thomas Elste.
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
   394
                    "datagram size (%zu)!\n", request->length,
1386
95ec1e9bcb53 Check phy_request length for read operations, too!
Florian Pose <fp@igh-essen.com>
parents: 1385
diff changeset
   395
                    fsm->datagram->mem_size);
95ec1e9bcb53 Check phy_request length for read operations, too!
Florian Pose <fp@igh-essen.com>
parents: 1385
diff changeset
   396
            request->state = EC_INT_REQUEST_FAILURE;
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
   397
            kref_put(&request->refcount, ec_master_reg_request_release);
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
   398
            wake_up(&master->reg_queue);
1386
95ec1e9bcb53 Check phy_request length for read operations, too!
Florian Pose <fp@igh-essen.com>
parents: 1385
diff changeset
   399
            continue;
95ec1e9bcb53 Check phy_request length for read operations, too!
Florian Pose <fp@igh-essen.com>
parents: 1385
diff changeset
   400
        }
95ec1e9bcb53 Check phy_request length for read operations, too!
Florian Pose <fp@igh-essen.com>
parents: 1385
diff changeset
   401
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
   402
        fsm->reg_request = request;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   403
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   404
        if (request->dir == EC_DIR_INPUT) {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   405
            ec_datagram_fprd(fsm->datagram, request->slave->station_address,
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   406
                    request->offset, request->length);
1225
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1219
diff changeset
   407
            ec_datagram_zero(fsm->datagram);
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   408
        } else {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   409
            ec_datagram_fpwr(fsm->datagram, request->slave->station_address,
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   410
                    request->offset, request->length);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   411
            memcpy(fsm->datagram->data, request->data, request->length);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   412
        }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   413
        fsm->retries = EC_FSM_RETRIES;
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
   414
        fsm->state = ec_fsm_master_state_reg_request;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   415
        return 1;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   416
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   417
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   418
    return 0;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   419
}
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   420
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   421
/*****************************************************************************/
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   422
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   423
/** 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
   424
 *
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   425
 * \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
   426
 */
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   427
int ec_fsm_master_action_process_sdo(
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   428
        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
   429
        )
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   430
{
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   431
    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
   432
    ec_slave_t *slave;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   433
    ec_sdo_request_t *req;
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   434
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   435
    // 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
   436
    for (slave = master->slaves;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   437
            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
   438
            slave++) {
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   439
        if (!slave->config)
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   440
            continue;
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   441
        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
   442
            if (req->state == EC_INT_REQUEST_QUEUED) {
880
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
   443
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
   444
                if (ec_sdo_request_timed_out(req)) {
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   445
                    req->state = EC_INT_REQUEST_FAILURE;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   446
                    EC_SLAVE_DBG(slave, 1, "Internal SDO request"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   447
                            " timed out.\n");
880
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
   448
                    continue;
f6212c54a5e3 Implemented Sdo timeout.
Florian Pose <fp@igh-essen.com>
parents: 872
diff changeset
   449
                }
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   450
987
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   451
                if (slave->current_state == EC_SLAVE_STATE_INIT) {
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   452
                    req->state = EC_INT_REQUEST_FAILURE;
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   453
                    continue;
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   454
                }
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   455
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   456
                req->state = EC_INT_REQUEST_BUSY;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   457
                EC_SLAVE_DBG(slave, 1, "Processing internal"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   458
                        " SDO request...\n");
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   459
                fsm->idle = 0;
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   460
                fsm->sdo_request = req;
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   461
                fsm->slave = slave;
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   462
                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
   463
                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
   464
                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
   465
                return 1;
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   466
            }
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   467
        }
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
   468
    }
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   469
    return 0;
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
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   472
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   473
/*****************************************************************************/
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   474
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   475
/** Master action: IDLE.
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   476
 *
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   477
 * Does secondary work.
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   478
 */
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   479
void ec_fsm_master_action_idle(
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
   480
        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
   481
        )
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
    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
   484
    ec_slave_t *slave;
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   485
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
   486
    // Check for pending internal SDO requests
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   487
    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
   488
        return;
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
   489
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1830
diff changeset
   490
    // enable processing of requests
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1606
diff changeset
   491
    for (slave = master->slaves;
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1606
diff changeset
   492
            slave < master->slaves + master->slave_count;
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1606
diff changeset
   493
            slave++) {
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1606
diff changeset
   494
        ec_fsm_slave_ready(&slave->fsm);
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1606
diff changeset
   495
    }
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1606
diff changeset
   496
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1606
diff changeset
   497
    // 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
   498
    for (slave = master->slaves;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   499
            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
   500
            slave++) {
910
9fd31755f576 Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   501
        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
   502
                || (slave->sii.has_general
aa030fb1e980 Only query Sdo information service, if slave supports it.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   503
                    && !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
   504
                || 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
   505
                || 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
   506
                || 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
   507
                || 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
   508
                ) 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
   509
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   510
        EC_SLAVE_DBG(slave, 1, "Fetching SDO dictionary.\n");
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
   511
910
9fd31755f576 Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   512
        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
   513
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   514
        // 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
   515
        fsm->idle = 0;
9fd31755f576 Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   516
        fsm->slave = slave;
9fd31755f576 Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   517
        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
   518
        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
   519
        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
   520
        return;
9fd31755f576 Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   521
    }
9fd31755f576 Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   522
9fd31755f576 Fetch Sdo dictionaries and process SII requests in operation mode.
Florian Pose <fp@igh-essen.com>
parents: 908
diff changeset
   523
    // 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
   524
    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
   525
        return; // SII write request found
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   526
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
   527
    // check for pending register requests.
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
   528
    if (ec_fsm_master_action_process_register(fsm))
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
   529
        return; // register request processing
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
   530
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   531
    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
   532
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   533
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   534
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   535
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   536
/** Master action: Get state of next slave.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   537
 */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   538
void ec_fsm_master_action_next_slave_state(
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   539
        ec_fsm_master_t *fsm /**< Master state machine. */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   540
        )
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   541
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   542
    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
   543
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   544
    // 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
   545
    fsm->slave++;
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   546
    if (fsm->slave < master->slaves + master->slave_count) {
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   547
        // fetch state from next slave
650
c68995623e94 Introduced idle flag in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 649
diff changeset
   548
        fsm->idle = 1;
1000
5746fdd1ca2e Store slaves in an array instead of a list.
Florian Pose <fp@igh-essen.com>
parents: 998
diff changeset
   549
        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
   550
                fsm->slave->station_address, 0x0130, 2);
1225
4d5b739edcb5 Introduced ec_datagram_zero().
Florian Pose <fp@igh-essen.com>
parents: 1219
diff changeset
   551
        ec_datagram_zero(fsm->datagram);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   552
        fsm->retries = EC_FSM_RETRIES;
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   553
        fsm->state = ec_fsm_master_state_read_state;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   554
        return;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   555
    }
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   556
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   557
    // all slaves processed
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   558
    ec_fsm_master_action_idle(fsm);
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   559
}
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   560
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   561
/*****************************************************************************/
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   562
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   563
/** Master action: Configure.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   564
 */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   565
void ec_fsm_master_action_configure(
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   566
        ec_fsm_master_t *fsm /**< Master state machine. */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   567
        )
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   568
{
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   569
    ec_master_t *master = fsm->master;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   570
    ec_slave_t *slave = fsm->slave;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   571
2098
0ce254664c81 Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents: 2094
diff changeset
   572
    if (master->config_changed) {
2112
70afe990c10e Bugfix: Reset config_changed flag when aborting state check.
Florian Pose <fp@igh-essen.com>
parents: 2098
diff changeset
   573
        master->config_changed = 0;
70afe990c10e Bugfix: Reset config_changed flag when aborting state check.
Florian Pose <fp@igh-essen.com>
parents: 2098
diff changeset
   574
2098
0ce254664c81 Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents: 2094
diff changeset
   575
        // abort iterating through slaves,
0ce254664c81 Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents: 2094
diff changeset
   576
        // first compensate DC system time offsets,
0ce254664c81 Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents: 2094
diff changeset
   577
        // then begin configuring at slave 0
0ce254664c81 Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents: 2094
diff changeset
   578
        EC_MASTER_DBG(master, 1, "Configuration changed"
0ce254664c81 Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents: 2094
diff changeset
   579
                " (aborting state check).\n");
0ce254664c81 Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents: 2094
diff changeset
   580
0ce254664c81 Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents: 2094
diff changeset
   581
        fsm->slave = master->slaves; // begin with first slave
0ce254664c81 Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents: 2094
diff changeset
   582
        ec_fsm_master_enter_write_system_times(fsm);
2146
05c6ddef33ab Fixed missing return causing slaves not going to OP.
Florian Pose <fp@igh-essen.com>
parents: 2145
diff changeset
   583
        return;
2098
0ce254664c81 Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents: 2094
diff changeset
   584
    }
0ce254664c81 Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents: 2094
diff changeset
   585
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   586
    // 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
   587
    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
   588
                || slave->force_config) && !slave->error_flag) {
1177
03d9640c9ce4 Minor change.
Florian Pose <fp@igh-essen.com>
parents: 1174
diff changeset
   589
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   590
        // Start slave configuration, if it is allowed.
2028
55854f070c4a use rt_mutex instead of semaphore for mutual exclusion (use --enable-mutex)
Martin Troxler <ch1010277@ch10pc446>
parents: 2027
diff changeset
   591
        ec_mutex_lock(&master->config_mutex);
2117
afb40fd6018e Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents: 2113
diff changeset
   592
        master->config_busy = 1;
afb40fd6018e Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents: 2113
diff changeset
   593
        ec_mutex_unlock(&master->config_mutex);
afb40fd6018e Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents: 2113
diff changeset
   594
afb40fd6018e Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents: 2113
diff changeset
   595
        if (master->debug_level) {
afb40fd6018e Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents: 2113
diff changeset
   596
            char old_state[EC_STATE_STRING_SIZE],
afb40fd6018e Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents: 2113
diff changeset
   597
                 new_state[EC_STATE_STRING_SIZE];
afb40fd6018e Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents: 2113
diff changeset
   598
            ec_state_string(slave->current_state, old_state, 0);
afb40fd6018e Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents: 2113
diff changeset
   599
            ec_state_string(slave->requested_state, new_state, 0);
afb40fd6018e Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents: 2113
diff changeset
   600
            EC_SLAVE_DBG(slave, 1, "Changing state from %s to %s%s.\n",
afb40fd6018e Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents: 2113
diff changeset
   601
                    old_state, new_state,
afb40fd6018e Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents: 2113
diff changeset
   602
                    slave->force_config ? " (forced)" : "");
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   603
        }
2117
afb40fd6018e Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents: 2113
diff changeset
   604
afb40fd6018e Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents: 2113
diff changeset
   605
        fsm->idle = 0;
afb40fd6018e Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents: 2113
diff changeset
   606
        fsm->state = ec_fsm_master_state_configure_slave;
afb40fd6018e Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents: 2113
diff changeset
   607
        ec_fsm_slave_config_start(&fsm->fsm_slave_config, slave);
afb40fd6018e Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents: 2113
diff changeset
   608
        fsm->state(fsm); // execute immediately
afb40fd6018e Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents: 2113
diff changeset
   609
        return;
907
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
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   612
    // slave has error flag set; process next one
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   613
    ec_fsm_master_action_next_slave_state(fsm);
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   614
}
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   615
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   616
/*****************************************************************************/
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   617
987
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   618
/** 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
   619
 *
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   620
 * 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
   621
 */
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   622
void ec_fsm_master_state_read_state(
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   623
        ec_fsm_master_t *fsm /**< Master state machine. */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   624
        )
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
    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
   627
    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
   628
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   629
    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
   630
        return;
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   631
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   632
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   633
        EC_SLAVE_ERR(slave, "Failed to receive AL state datagram: ");
1822
74e6ac2369f4 Introduced ec_datagram_print_state() method and used it at all places where
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   634
        ec_datagram_print_state(datagram);
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   635
        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
   636
        return;
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   637
    }
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   638
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   639
    // 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
   640
    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
   641
        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
   642
            slave->error_flag = 1;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   643
            EC_SLAVE_DBG(slave, 1, "Slave did not respond to state query.\n");
987
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   644
        }
1961
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents: 1931
diff changeset
   645
        fsm->rescan_required = 1;
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
   646
        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
   647
        return;
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   648
    }
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   649
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 986
diff changeset
   650
    // 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
   651
    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
   652
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   653
    if (!slave->error_flag) {
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   654
        // Check, if new slave state has to be acknowledged
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   655
        if (slave->current_state & EC_SLAVE_STATE_ACK_ERR) {
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   656
            fsm->idle = 0;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   657
            fsm->state = ec_fsm_master_state_acknowledge;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   658
            ec_fsm_change_ack(&fsm->fsm_change, slave);
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   659
            fsm->state(fsm); // execute immediately
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   660
            return;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   661
        }
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   662
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   663
        // No acknowlegde necessary; check for configuration
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   664
        ec_fsm_master_action_configure(fsm);
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   665
        return;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   666
    }
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   667
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   668
    // slave has error flag set; process next one
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   669
    ec_fsm_master_action_next_slave_state(fsm);
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   670
}
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   671
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   672
/*****************************************************************************/
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   673
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   674
/** Master state: ACKNOWLEDGE.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   675
 */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   676
void ec_fsm_master_state_acknowledge(
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   677
        ec_fsm_master_t *fsm /**< Master state machine. */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   678
        )
454
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   679
{
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   680
    ec_slave_t *slave = fsm->slave;
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   681
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   682
    if (ec_fsm_change_exec(&fsm->fsm_change))
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   683
        return;
454
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   684
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   685
    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
   686
        fsm->slave->error_flag = 1;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   687
        EC_SLAVE_ERR(slave, "Failed to acknowledge state change.\n");
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   688
    }
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   689
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   690
    ec_fsm_master_action_configure(fsm);
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   691
}
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   692
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   693
/*****************************************************************************/
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   694
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   695
/** Master state: CLEAR ADDRESSES.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   696
 */
717
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   697
void ec_fsm_master_state_clear_addresses(
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   698
        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
   699
        )
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   700
{
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   701
    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
   702
    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
   703
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   704
    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
   705
        return;
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   706
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   707
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   708
        EC_MASTER_ERR(master, "Failed to receive address"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   709
                " clearing datagram: ");
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   710
        ec_datagram_print_state(datagram);
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 880
diff changeset
   711
        master->scan_busy = 0;
794
684dea874956 Allow bus configuration when link is down.
Florian Pose <fp@igh-essen.com>
parents: 792
diff changeset
   712
        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
   713
        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
   714
        return;
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   715
    }
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   716
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   717
    if (datagram->working_counter != master->slave_count) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   718
        EC_MASTER_WARN(master, "Failed to clear all station addresses:"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   719
                " Cleared %u of %u",
717
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   720
                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
   721
    }
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   722
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   723
    EC_MASTER_DBG(master, 1, "Sending broadcast-write"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   724
            " to measure transmission delays.\n");
1420
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   725
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   726
    ec_datagram_bwr(datagram, 0x0900, 1);
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   727
    ec_datagram_zero(datagram);
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   728
    fsm->retries = EC_FSM_RETRIES;
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   729
    fsm->state = ec_fsm_master_state_dc_measure_delays;
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   730
}
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   731
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   732
/*****************************************************************************/
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   733
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   734
/** Master state: DC MEASURE DELAYS.
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   735
 */
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   736
void ec_fsm_master_state_dc_measure_delays(
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   737
        ec_fsm_master_t *fsm /**< Master state machine. */
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   738
        )
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   739
{
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   740
    ec_master_t *master = fsm->master;
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   741
    ec_datagram_t *datagram = fsm->datagram;
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   742
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   743
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   744
        return;
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   745
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   746
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   747
        EC_MASTER_ERR(master, "Failed to receive delay measuring datagram: ");
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   748
        ec_datagram_print_state(datagram);
1420
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   749
        master->scan_busy = 0;
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   750
        wake_up_interruptible(&master->scan_queue);
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   751
        ec_fsm_master_restart(fsm);
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   752
        return;
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   753
    }
5eb814732c46 Measure port receive times.
Florian Pose <fp@igh-essen.com>
parents: 1408
diff changeset
   754
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   755
    EC_MASTER_DBG(master, 1, "%u slaves responded to delay measuring.\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   756
            datagram->working_counter);
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   757
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   758
    EC_MASTER_INFO(master, "Scanning bus.\n");
717
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   759
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   760
    // 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
   761
    fsm->slave = master->slaves;
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   762
    fsm->state = ec_fsm_master_state_scan_slave;
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   763
    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
   764
    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
   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
/*****************************************************************************/
87abf1166e88 Clear station addresses with broadcast before setting them.
Florian Pose <fp@igh-essen.com>
parents: 716
diff changeset
   768
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   769
/** Master state: SCAN SLAVE.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   770
 *
652
15cff76b66c7 Added scan time output.
Florian Pose <fp@igh-essen.com>
parents: 650
diff changeset
   771
 * 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
   772
 */
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   773
void ec_fsm_master_state_scan_slave(
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   774
        ec_fsm_master_t *fsm /**< Master state machine. */
652
15cff76b66c7 Added scan time output.
Florian Pose <fp@igh-essen.com>
parents: 650
diff changeset
   775
        )
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   776
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   777
    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
   778
#ifdef EC_EOE
637
d5d04c868e0e Removed ecrt_master_run(), removed datagram queueing from state
Florian Pose <fp@igh-essen.com>
parents: 612
diff changeset
   779
    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
   780
#endif
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   781
    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
   782
        return;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   783
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   784
#ifdef EC_EOE
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 831
diff changeset
   785
    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
   786
        // create EoE handler for this slave
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   787
        ec_eoe_t *eoe;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   788
        if (!(eoe = kmalloc(sizeof(ec_eoe_t), GFP_KERNEL))) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   789
            EC_SLAVE_ERR(slave, "Failed to allocate EoE handler memory!\n");
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)) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   791
            EC_SLAVE_ERR(slave, "Failed to init EoE handler!\n");
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   792
            kfree(eoe);
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 880
diff changeset
   793
        } else {
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   794
            list_add_tail(&eoe->list, &master->eoe_handlers);
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   795
        }
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   796
    }
715
f12ff7c08623 Added --enable-eoe conditional.
Florian Pose <fp@igh-essen.com>
parents: 713
diff changeset
   797
#endif
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   798
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   799
    // 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
   800
    fsm->slave++;
1002
0e1aaeb3540d Fixed bug in slave scanning, causing a segmentation fault.
Florian Pose <fp@igh-essen.com>
parents: 1000
diff changeset
   801
    if (fsm->slave < master->slaves + master->slave_count) {
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   802
        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
   803
        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
   804
        return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   805
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   806
1931
831f2d34664c Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 1927
diff changeset
   807
    EC_MASTER_INFO(master, "Bus scanning completed in %lu ms.\n",
831f2d34664c Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 1927
diff changeset
   808
            (jiffies - fsm->scan_jiffies) * 1000 / HZ);
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 656
diff changeset
   809
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 880
diff changeset
   810
    master->scan_busy = 0;
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 880
diff changeset
   811
    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
   812
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   813
    ec_master_calc_dc(master);
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1444
diff changeset
   814
792
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   815
    // Attach slave configurations
3778920f61e4 Implemented most realtime interface changes for version 1.4, improved
Florian Pose <fp@igh-essen.com>
parents: 758
diff changeset
   816
    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
   817
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   818
    if (master->slave_count) {
2112
70afe990c10e Bugfix: Reset config_changed flag when aborting state check.
Florian Pose <fp@igh-essen.com>
parents: 2098
diff changeset
   819
        master->config_changed = 0;
70afe990c10e Bugfix: Reset config_changed flag when aborting state check.
Florian Pose <fp@igh-essen.com>
parents: 2098
diff changeset
   820
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   821
        fsm->slave = master->slaves; // begin with first slave
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   822
        ec_fsm_master_enter_write_system_times(fsm);
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   823
    } else {
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   824
        ec_fsm_master_restart(fsm);
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   825
    }
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   826
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   827
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   828
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   829
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   830
/** Master state: CONFIGURE SLAVE.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   831
 *
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   832
 * Starts configuring a slave.
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
void ec_fsm_master_state_configure_slave(
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   835
        ec_fsm_master_t *fsm /**< Master state machine. */
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
{
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   838
    ec_master_t *master = fsm->master;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   839
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   840
    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
   841
        return;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   842
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
   843
    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
   844
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   845
    // configuration finished
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   846
    master->config_busy = 0;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   847
    wake_up_interruptible(&master->config_queue);
830
d83d92e1a919 Separated slave state machines.
Florian Pose <fp@igh-essen.com>
parents: 815
diff changeset
   848
900
f8b5c6d21705 Removed bus validation; slave configuration during realtime operation;
Florian Pose <fp@igh-essen.com>
parents: 880
diff changeset
   849
    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
   850
        // 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
   851
    }
656
370aa8c2d1b1 Slave configuration exclusively from master thread; removed
Florian Pose <fp@igh-essen.com>
parents: 652
diff changeset
   852
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   853
    fsm->idle = 1;
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   854
    ec_fsm_master_action_next_slave_state(fsm);
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
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   857
/*****************************************************************************/
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   858
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   859
/** Start writing DC system times.
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   860
 */
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   861
void ec_fsm_master_enter_write_system_times(
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   862
        ec_fsm_master_t *fsm /**< Master state machine. */
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   863
        )
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   864
{
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   865
    ec_master_t *master = fsm->master;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   866
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   867
    EC_MASTER_DBG(master, 1, "Writing system time offsets...\n");
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   868
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   869
    if (master->has_app_time) {
2098
0ce254664c81 Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents: 2094
diff changeset
   870
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   871
        while (fsm->slave < master->slaves + master->slave_count) {
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   872
            if (!fsm->slave->base_dc_supported
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   873
                    || !fsm->slave->has_dc_system_time) {
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   874
                fsm->slave++;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   875
                continue;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   876
            }
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   877
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   878
            // read DC system time (0x0910, 64 bit)
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   879
            //                         gap (64 bit)
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   880
            //     and time offset (0x0920, 64 bit)
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   881
            ec_datagram_fprd(fsm->datagram, fsm->slave->station_address,
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   882
                    0x0910, 24);
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   883
            fsm->retries = EC_FSM_RETRIES;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   884
            fsm->state = ec_fsm_master_state_dc_read_offset;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   885
            return;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   886
        }
2098
0ce254664c81 Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents: 2094
diff changeset
   887
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   888
    } else {
2098
0ce254664c81 Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents: 2094
diff changeset
   889
        if (master->active) {
0ce254664c81 Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents: 2094
diff changeset
   890
            EC_MASTER_ERR(master, "No app_time received up to now,"
2145
a63ed5513117 Fixed typo.
Florian Pose <fp@igh-essen.com>
parents: 2117
diff changeset
   891
                    " but master already active.\n");
2098
0ce254664c81 Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents: 2094
diff changeset
   892
        } else {
0ce254664c81 Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents: 2094
diff changeset
   893
            EC_MASTER_DBG(master, 1, "No app_time received up to now.\n");
0ce254664c81 Improved DC sync at startup: Abort iterating though slaves and first correct
Florian Pose <fp@igh-essen.com>
parents: 2094
diff changeset
   894
        }
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   895
    }
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   896
2117
afb40fd6018e Removed allow_config flag and obsolete request to OP.
Florian Pose <fp@igh-essen.com>
parents: 2113
diff changeset
   897
    // scanning and setting system times complete
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   898
    ec_master_request_op(master);
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   899
    ec_fsm_master_restart(fsm);
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   900
}
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   901
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   902
/*****************************************************************************/
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   903
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   904
/** Configure 32 bit time offset.
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   905
 */
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   906
u64 ec_fsm_master_dc_offset32(
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   907
        ec_fsm_master_t *fsm, /**< Master state machine. */
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   908
        u64 system_time, /**< System time register. */
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   909
        u64 old_offset, /**< Time offset register. */
1989
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
   910
		u64 correction /**< Correction. */
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   911
        )
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   912
{
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   913
    ec_slave_t *slave = fsm->slave;
1989
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
   914
	u32 correction32, system_time32, old_offset32, new_offset;
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   915
    s32 time_diff;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   916
1989
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
   917
	system_time32 = (u32) system_time;
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
   918
	// correct read system time by elapsed time between read operation
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
   919
	// and app_time set time
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
   920
	correction32 = (u32)correction;
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
   921
	system_time32 -= correction32;
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
   922
	old_offset32 = (u32) old_offset;
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
   923
1999
5f1269a71588 use app_start_time for initial DC offset calculation because app_time might be overwritten while calculating the offsets.
Martin Troxler <ch1010277@ch10pc446>
parents: 1998
diff changeset
   924
    time_diff = (u32) slave->master->app_start_time - system_time32;
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   926
    EC_SLAVE_DBG(slave, 1, "DC system time offset calculation:"
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   927
            " system_time=%u (corrected with %u),"
1999
5f1269a71588 use app_start_time for initial DC offset calculation because app_time might be overwritten while calculating the offsets.
Martin Troxler <ch1010277@ch10pc446>
parents: 1998
diff changeset
   928
            " app_start_time=%llu, diff=%i\n",
1989
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
   929
			system_time32, correction32,
1999
5f1269a71588 use app_start_time for initial DC offset calculation because app_time might be overwritten while calculating the offsets.
Martin Troxler <ch1010277@ch10pc446>
parents: 1998
diff changeset
   930
            slave->master->app_start_time, time_diff);
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   931
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   932
    if (EC_ABS(time_diff) > EC_SYSTEM_TIME_TOLERANCE_NS) {
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   933
        new_offset = time_diff + old_offset32;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   934
        EC_SLAVE_DBG(slave, 1, "Setting time offset to %u (was %u)\n",
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   935
                new_offset, old_offset32);
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   936
        return (u64) new_offset;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   937
    } else {
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   938
        EC_SLAVE_DBG(slave, 1, "Not touching time offset.\n");
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   939
        return old_offset;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   940
    }
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   941
}
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   942
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   943
/*****************************************************************************/
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   944
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   945
/** Configure 64 bit time offset.
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   946
 */
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   947
u64 ec_fsm_master_dc_offset64(
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   948
        ec_fsm_master_t *fsm, /**< Master state machine. */
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   949
        u64 system_time, /**< System time register. */
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   950
        u64 old_offset, /**< Time offset register. */
1989
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
   951
		u64 correction /**< Correction. */
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   952
        )
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   953
{
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   954
    ec_slave_t *slave = fsm->slave;
1989
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
   955
	u64 new_offset;
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   956
    s64 time_diff;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   957
1989
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
   958
	// correct read system time by elapsed time between read operation
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
   959
	// and app_time set time
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
   960
	system_time -= correction;
1999
5f1269a71588 use app_start_time for initial DC offset calculation because app_time might be overwritten while calculating the offsets.
Martin Troxler <ch1010277@ch10pc446>
parents: 1998
diff changeset
   961
    time_diff = fsm->slave->master->app_start_time - system_time;
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   962
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   963
    EC_SLAVE_DBG(slave, 1, "DC system time offset calculation:"
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   964
            " system_time=%llu (corrected with %llu),"
1999
5f1269a71588 use app_start_time for initial DC offset calculation because app_time might be overwritten while calculating the offsets.
Martin Troxler <ch1010277@ch10pc446>
parents: 1998
diff changeset
   965
            " app_start_time=%llu, diff=%lli\n",
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   966
            system_time, correction,
1999
5f1269a71588 use app_start_time for initial DC offset calculation because app_time might be overwritten while calculating the offsets.
Martin Troxler <ch1010277@ch10pc446>
parents: 1998
diff changeset
   967
            slave->master->app_start_time, time_diff);
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   968
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   969
    if (EC_ABS(time_diff) > EC_SYSTEM_TIME_TOLERANCE_NS) {
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   970
        new_offset = time_diff + old_offset;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   971
        EC_SLAVE_DBG(slave, 1, "Setting time offset to %llu (was %llu)\n",
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   972
                new_offset, old_offset);
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   973
    } else {
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   974
        new_offset = old_offset;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   975
        EC_SLAVE_DBG(slave, 1, "Not touching time offset.\n");
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   976
    }
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   977
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   978
    return new_offset;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   979
}
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   980
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   981
/*****************************************************************************/
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   982
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   983
/** Master state: DC READ OFFSET.
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   984
 */
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   985
void ec_fsm_master_state_dc_read_offset(
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   986
        ec_fsm_master_t *fsm /**< Master state machine. */
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   987
        )
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   988
{
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   989
    ec_datagram_t *datagram = fsm->datagram;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   990
    ec_slave_t *slave = fsm->slave;
1989
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
   991
	u64 system_time, old_offset, new_offset, correction;
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   992
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   993
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   994
        return;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   995
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   996
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   997
        EC_SLAVE_ERR(slave, "Failed to receive DC times datagram: ");
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   998
        ec_datagram_print_state(datagram);
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
   999
        fsm->slave++;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1000
        ec_fsm_master_enter_write_system_times(fsm);
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1001
        return;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1002
    }
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1003
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1004
    if (datagram->working_counter != 1) {
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1005
        EC_SLAVE_WARN(slave, "Failed to get DC times: ");
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1006
        ec_datagram_print_wc_error(datagram);
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1007
        fsm->slave++;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1008
        ec_fsm_master_enter_write_system_times(fsm);
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1009
        return;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1010
    }
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1011
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1012
    system_time = EC_READ_U64(datagram->data);     // 0x0910
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1013
    old_offset = EC_READ_U64(datagram->data + 16); // 0x0920
1989
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
  1014
	/* correct read system time by elapsed time since read operation
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
  1015
	   and the app_time set time */
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
  1016
#ifdef EC_HAVE_CYCLES
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
  1017
	correction =
2001
2e05246f3b00 renamed dc_cycles_app_time -> dc_cycles_app_start_time & dc_jiffies_app_time -> dc_jiffies_app_start_time
Martin Troxler <ch1010277@ch10pc446>
parents: 1999
diff changeset
  1018
            (datagram->cycles_sent - slave->master->dc_cycles_app_start_time)
1989
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
  1019
			* 1000000LL;
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1020
	do_div(correction, cpu_khz);
1989
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
  1021
#else
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
  1022
	correction =
2007
5da31ecf3a87 fixed compiling without EC_HAVE_CYCLES (dc_jiffies_app_start_time)
Martin Troxler <ch1010277@ch10pc446>
parents: 2001
diff changeset
  1023
			(u64) ((datagram->jiffies_sent-slave->master->dc_jiffies_app_start_time) * 1000 / HZ)
1989
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
  1024
			* 1000000;
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
  1025
#endif
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1026
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1027
    if (slave->base_dc_range == EC_DC_32) {
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1028
        new_offset = ec_fsm_master_dc_offset32(fsm,
1989
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
  1029
				system_time, old_offset, correction);
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1030
    } else {
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1031
        new_offset = ec_fsm_master_dc_offset64(fsm,
1989
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1927
diff changeset
  1032
				system_time, old_offset, correction);
1925
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1033
    }
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1034
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1035
    // set DC system time offset and transmission delay
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1036
    ec_datagram_fpwr(datagram, slave->station_address, 0x0920, 12);
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1037
    EC_WRITE_U64(datagram->data, new_offset);
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1038
    EC_WRITE_U32(datagram->data + 8, slave->transmission_delay);
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1039
    fsm->retries = EC_FSM_RETRIES;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1040
    fsm->state = ec_fsm_master_state_dc_write_offset;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1041
}
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1042
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1043
/*****************************************************************************/
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1044
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1045
/** Master state: DC WRITE OFFSET.
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1046
 */
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1047
void ec_fsm_master_state_dc_write_offset(
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1048
        ec_fsm_master_t *fsm /**< Master state machine. */
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1049
        )
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1050
{
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1051
    ec_datagram_t *datagram = fsm->datagram;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1052
    ec_slave_t *slave = fsm->slave;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1053
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1054
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--)
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1055
        return;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1056
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1057
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1058
        EC_SLAVE_ERR(slave,
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1059
                "Failed to receive DC system time offset datagram: ");
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1060
        ec_datagram_print_state(datagram);
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1061
        fsm->slave++;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1062
        ec_fsm_master_enter_write_system_times(fsm);
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1063
        return;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1064
    }
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1065
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1066
    if (datagram->working_counter != 1) {
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1067
        EC_SLAVE_ERR(slave, "Failed to set DC system time offset: ");
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1068
        ec_datagram_print_wc_error(datagram);
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1069
        fsm->slave++;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1070
        ec_fsm_master_enter_write_system_times(fsm);
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1071
        return;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1072
    }
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1073
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1074
    fsm->slave++;
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1075
    ec_fsm_master_enter_write_system_times(fsm);
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1076
}
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1077
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1078
/*****************************************************************************/
29161abef052 Write DC system time offsets right after slave scan / config change. Wait for DC clock discipline.
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  1079
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
  1080
/** Master state: WRITE SII.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
  1081
 */
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
  1082
void ec_fsm_master_state_write_sii(
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
  1083
        ec_fsm_master_t *fsm /**< Master state machine. */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
  1084
        )
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1085
{
601
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
  1086
    ec_master_t *master = fsm->master;
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
  1087
    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
  1088
    ec_slave_t *slave = request->slave;
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1089
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
  1090
    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
  1091
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1092
    if (!ec_fsm_sii_success(&fsm->fsm_sii)) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1093
        EC_SLAVE_ERR(slave, "Failed to write SII data.\n");
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1094
        request->state = EC_INT_REQUEST_FAILURE;
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1095
        kref_put(&request->refcount, ec_master_sii_write_request_release);
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
  1096
        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
  1097
        ec_fsm_master_restart(fsm);
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
  1098
        return;
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
  1099
    }
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
  1100
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
  1101
    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
  1102
    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
  1103
        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
  1104
                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
  1105
                request->words + fsm->sii_index,
815
002fe9ec778f Implemented missing datagram types.
Florian Pose <fp@igh-essen.com>
parents: 814
diff changeset
  1106
                EC_FSM_SII_USE_CONFIGURED_ADDRESS);
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1107
        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
  1108
        return;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1109
    }
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1110
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
  1111
    // finished writing SII
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1112
    EC_SLAVE_DBG(slave, 1, "Finished writing %zu words of SII data.\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1113
            request->nwords);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1064
diff changeset
  1114
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1064
diff changeset
  1115
    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
  1116
        // alias was written
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1064
diff changeset
  1117
        slave->sii.alias = EC_READ_U16(request->words + 4);
1579
326d47aa986c applied komax patch to version r1822
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1507
diff changeset
  1118
        // TODO: read alias from register 0x0012
1909
ea3eb4c74c1b Introduced effective_alias variable to separate reg12 alias from SII alias.
Florian Pose <fp@igh-essen.com>
parents: 1892
diff changeset
  1119
        slave->effective_alias = slave->sii.alias;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1064
diff changeset
  1120
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1064
diff changeset
  1121
    // 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
  1122
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1123
    request->state = EC_INT_REQUEST_SUCCESS;
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1124
    kref_put(&request->refcount, ec_master_sii_write_request_release);
872
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
  1125
    wake_up(&master->sii_queue);
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
  1126
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
  1127
    // check for another SII write request
d4e0380d63b3 Renamed EEPROM to SII.
Florian Pose <fp@igh-essen.com>
parents: 861
diff changeset
  1128
    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
  1129
        return; // processing another request
d6d951b766e3 Introduced EEPROM write requests: EEPROM write operations from user
Florian Pose <fp@igh-essen.com>
parents: 594
diff changeset
  1130
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
  1131
    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
  1132
}
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1133
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1134
/*****************************************************************************/
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1135
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
  1136
/** Master state: SDO DICTIONARY.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
  1137
 */
905
6d74ebc603ee Renamed state sdodict to sdo_dictionary.
Florian Pose <fp@igh-essen.com>
parents: 904
diff changeset
  1138
void ec_fsm_master_state_sdo_dictionary(
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
  1139
        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
  1140
        )
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1141
{
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1142
    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
  1143
    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
  1144
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1145
    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
  1146
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1147
    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
  1148
        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
  1149
        return;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1150
    }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1151
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1152
    // 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
  1153
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1154
    if (master->debug_level) {
423
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
  1155
        unsigned int sdo_count, entry_count;
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
  1156
        ec_slave_sdo_dict_info(slave, &sdo_count, &entry_count);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1157
        EC_SLAVE_DBG(slave, 1, "Fetched %u SDOs and %u entries.\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1158
               sdo_count, entry_count);
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1159
    }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1160
1186
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1177
diff changeset
  1161
    // attach pdo names from dictionary
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1177
diff changeset
  1162
    ec_slave_attach_pdo_names(slave);
ff481f097c97 Attach Pdo names from dictionary.
Florian Pose <fp@igh-essen.com>
parents: 1177
diff changeset
  1163
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
  1164
    ec_fsm_master_restart(fsm);
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1165
}
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
  1166
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
  1167
/*****************************************************************************/
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
  1168
907
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
  1169
/** Master state: SDO REQUEST.
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
  1170
 */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
  1171
void ec_fsm_master_state_sdo_request(
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
  1172
        ec_fsm_master_t *fsm /**< Master state machine. */
570ae1c64465 Improved master state machine.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
  1173
        )
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
  1174
{
858
69122084d066 Basic reading realtime Sdo access working.
Florian Pose <fp@igh-essen.com>
parents: 853
diff changeset
  1175
    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
  1176
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1177
    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
  1178
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1179
    if (!ec_fsm_coe_success(&fsm->fsm_coe)) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1180
        EC_SLAVE_DBG(fsm->slave, 1,
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1181
                "Failed to process internal SDO request.\n");
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1182
        request->state = EC_INT_REQUEST_FAILURE;
1596
ea8d2b4ee742 Moved sdo request queue to slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1583
diff changeset
  1183
        wake_up(&fsm->slave->sdo_queue);
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
  1184
        ec_fsm_master_restart(fsm);
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
  1185
        return;
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
  1186
    }
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
  1187
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1327
diff changeset
  1188
    // SDO request finished
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1189
    request->state = EC_INT_REQUEST_SUCCESS;
1596
ea8d2b4ee742 Moved sdo request queue to slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1583
diff changeset
  1190
    wake_up(&fsm->slave->sdo_queue);
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
  1191
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1192
    EC_SLAVE_DBG(fsm->slave, 1, "Finished internal SDO request.\n");
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
  1193
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1194
    // check for another SDO request
646
fbbd4e54e031 Implemented SDO reading with wait queues.
Florian Pose <fp@igh-essen.com>
parents: 645
diff changeset
  1195
    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
  1196
        return; // processing another request
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
  1197
1031
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
  1198
    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
  1199
}
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
  1200
000593b576dd Removed 'end' and 'error' states from master state machine.
Florian Pose <fp@igh-essen.com>
parents: 1029
diff changeset
  1201
/*****************************************************************************/
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1202
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
  1203
/** Master state: REG REQUEST.
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
  1204
 */
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
  1205
void ec_fsm_master_state_reg_request(
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1206
        ec_fsm_master_t *fsm /**< Master state machine. */
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1207
        )
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1208
{
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1209
    ec_master_t *master = fsm->master;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1210
    ec_datagram_t *datagram = fsm->datagram;
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
  1211
    ec_reg_request_t *request = fsm->reg_request;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1212
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1213
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1214
        EC_MASTER_ERR(master, "Failed to receive register"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1215
                " request datagram: ");
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1216
        ec_datagram_print_state(datagram);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1217
        request->state = EC_INT_REQUEST_FAILURE;
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1218
        kref_put(&request->refcount, ec_master_reg_request_release);
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
  1219
        wake_up(&master->reg_queue);
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1220
        ec_fsm_master_restart(fsm);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1221
        return;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1222
    }
1579
326d47aa986c applied komax patch to version r1822
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1507
diff changeset
  1223
1385
241a7511eee9 Process working counter of phy_* commands.
Florian Pose <fp@igh-essen.com>
parents: 1380
diff changeset
  1224
    if (datagram->working_counter == 1) {
241a7511eee9 Process working counter of phy_* commands.
Florian Pose <fp@igh-essen.com>
parents: 1380
diff changeset
  1225
        if (request->dir == EC_DIR_INPUT) { // read request
241a7511eee9 Process working counter of phy_* commands.
Florian Pose <fp@igh-essen.com>
parents: 1380
diff changeset
  1226
            if (request->data)
241a7511eee9 Process working counter of phy_* commands.
Florian Pose <fp@igh-essen.com>
parents: 1380
diff changeset
  1227
                kfree(request->data);
241a7511eee9 Process working counter of phy_* commands.
Florian Pose <fp@igh-essen.com>
parents: 1380
diff changeset
  1228
            request->data = kmalloc(request->length, GFP_KERNEL);
241a7511eee9 Process working counter of phy_* commands.
Florian Pose <fp@igh-essen.com>
parents: 1380
diff changeset
  1229
            if (!request->data) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1230
                EC_MASTER_ERR(master, "Failed to allocate %zu bytes"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1231
                        " of memory for register data.\n", request->length);
1385
241a7511eee9 Process working counter of phy_* commands.
Florian Pose <fp@igh-essen.com>
parents: 1380
diff changeset
  1232
                request->state = EC_INT_REQUEST_FAILURE;
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1233
                kref_put(&request->refcount, ec_master_reg_request_release);
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
  1234
                wake_up(&master->reg_queue);
1385
241a7511eee9 Process working counter of phy_* commands.
Florian Pose <fp@igh-essen.com>
parents: 1380
diff changeset
  1235
                ec_fsm_master_restart(fsm);
241a7511eee9 Process working counter of phy_* commands.
Florian Pose <fp@igh-essen.com>
parents: 1380
diff changeset
  1236
                return;
241a7511eee9 Process working counter of phy_* commands.
Florian Pose <fp@igh-essen.com>
parents: 1380
diff changeset
  1237
            }
241a7511eee9 Process working counter of phy_* commands.
Florian Pose <fp@igh-essen.com>
parents: 1380
diff changeset
  1238
            memcpy(request->data, datagram->data, request->length);
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1239
        }
1385
241a7511eee9 Process working counter of phy_* commands.
Florian Pose <fp@igh-essen.com>
parents: 1380
diff changeset
  1240
241a7511eee9 Process working counter of phy_* commands.
Florian Pose <fp@igh-essen.com>
parents: 1380
diff changeset
  1241
        request->state = EC_INT_REQUEST_SUCCESS;
1927
365a90e93161 Fixed NULL pointer dereference caused by wrong usage of DBG macro.
Florian Pose <fp@igh-essen.com>
parents: 1925
diff changeset
  1242
        EC_SLAVE_DBG(request->slave, 1, "Register request successful.\n");
1385
241a7511eee9 Process working counter of phy_* commands.
Florian Pose <fp@igh-essen.com>
parents: 1380
diff changeset
  1243
    } else {
241a7511eee9 Process working counter of phy_* commands.
Florian Pose <fp@igh-essen.com>
parents: 1380
diff changeset
  1244
        request->state = EC_INT_REQUEST_FAILURE;
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1245
        EC_MASTER_ERR(master, "Register request failed.\n");
1385
241a7511eee9 Process working counter of phy_* commands.
Florian Pose <fp@igh-essen.com>
parents: 1380
diff changeset
  1246
    }
241a7511eee9 Process working counter of phy_* commands.
Florian Pose <fp@igh-essen.com>
parents: 1380
diff changeset
  1247
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1248
    kref_put(&request->refcount, ec_master_reg_request_release);
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
  1249
    wake_up(&master->reg_queue);
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
  1250
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
  1251
    // check for another register request
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1386
diff changeset
  1252
    if (ec_fsm_master_action_process_register(fsm))
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1253
        return; // processing another request
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1254
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1255
    ec_fsm_master_restart(fsm);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1256
}
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1257
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1186
diff changeset
  1258
/*****************************************************************************/
2027
ac35f4d38a31 SDO wait_event() deadlock fixed: refcount ec_master_sdo_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2020
diff changeset
  1259
2030
2bd8ad8bf41f Sii write wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_sii_write_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2029
diff changeset
  1260
/** called by kref_put if the SII write request's refcount becomes zero.
2bd8ad8bf41f Sii write wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_sii_write_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2029
diff changeset
  1261
 *
2bd8ad8bf41f Sii write wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_sii_write_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2029
diff changeset
  1262
 */
2bd8ad8bf41f Sii write wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_sii_write_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2029
diff changeset
  1263
void ec_master_sii_write_request_release(struct kref *ref)
2bd8ad8bf41f Sii write wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_sii_write_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2029
diff changeset
  1264
{
2bd8ad8bf41f Sii write wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_sii_write_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2029
diff changeset
  1265
    ec_sii_write_request_t *request = container_of(ref, ec_sii_write_request_t, refcount);
2034
ca03a6737cb7 releasing of refcounted requests fixed: do not call EC_SLAVE_DBG without valid slave
Martin Troxler <ch1010277@ch10pc446>
parents: 2032
diff changeset
  1266
    if (request->slave)
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1267
        EC_SLAVE_DBG(request->slave, 1, "Releasing SII write request %p.\n",
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1268
                request);
2030
2bd8ad8bf41f Sii write wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_sii_write_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2029
diff changeset
  1269
    kfree(request->words);
2bd8ad8bf41f Sii write wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_sii_write_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2029
diff changeset
  1270
    kfree(request);
2bd8ad8bf41f Sii write wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_sii_write_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2029
diff changeset
  1271
}
2bd8ad8bf41f Sii write wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_sii_write_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2029
diff changeset
  1272
2bd8ad8bf41f Sii write wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_sii_write_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2029
diff changeset
  1273
/*****************************************************************************/
2bd8ad8bf41f Sii write wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_sii_write_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2029
diff changeset
  1274
2031
7a025a9e192d Register read/write wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_reg_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2030
diff changeset
  1275
/** called by kref_put if the reg request's refcount becomes zero.
7a025a9e192d Register read/write wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_reg_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2030
diff changeset
  1276
 *
7a025a9e192d Register read/write wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_reg_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2030
diff changeset
  1277
 */
7a025a9e192d Register read/write wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_reg_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2030
diff changeset
  1278
void ec_master_reg_request_release(struct kref *ref)
7a025a9e192d Register read/write wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_reg_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2030
diff changeset
  1279
{
7a025a9e192d Register read/write wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_reg_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2030
diff changeset
  1280
    ec_reg_request_t *request = container_of(ref, ec_reg_request_t, refcount);
2034
ca03a6737cb7 releasing of refcounted requests fixed: do not call EC_SLAVE_DBG without valid slave
Martin Troxler <ch1010277@ch10pc446>
parents: 2032
diff changeset
  1281
    if (request->slave)
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1282
        EC_SLAVE_DBG(request->slave, 1, "Releasing reg request %p.\n",
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1283
                request);
2031
7a025a9e192d Register read/write wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_reg_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2030
diff changeset
  1284
    if (request->data)
7a025a9e192d Register read/write wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_reg_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2030
diff changeset
  1285
        kfree(request->data);
7a025a9e192d Register read/write wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_reg_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2030
diff changeset
  1286
    kfree(request);
7a025a9e192d Register read/write wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_reg_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2030
diff changeset
  1287
}
7a025a9e192d Register read/write wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_reg_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2030
diff changeset
  1288
7a025a9e192d Register read/write wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_reg_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2030
diff changeset
  1289
/*****************************************************************************/
7a025a9e192d Register read/write wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_reg_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2030
diff changeset
  1290
2029
5ef6507fc77a FoE wait_event() deadlock fixed: refcount ec_master_foe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2028
diff changeset
  1291
/** called by kref_put if the SDO request's refcount becomes zero.
2027
ac35f4d38a31 SDO wait_event() deadlock fixed: refcount ec_master_sdo_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2020
diff changeset
  1292
 *
ac35f4d38a31 SDO wait_event() deadlock fixed: refcount ec_master_sdo_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2020
diff changeset
  1293
 */
ac35f4d38a31 SDO wait_event() deadlock fixed: refcount ec_master_sdo_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2020
diff changeset
  1294
void ec_master_sdo_request_release(struct kref *ref)
ac35f4d38a31 SDO wait_event() deadlock fixed: refcount ec_master_sdo_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2020
diff changeset
  1295
{
ac35f4d38a31 SDO wait_event() deadlock fixed: refcount ec_master_sdo_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2020
diff changeset
  1296
    ec_master_sdo_request_t *request = container_of(ref, ec_master_sdo_request_t, refcount);
2034
ca03a6737cb7 releasing of refcounted requests fixed: do not call EC_SLAVE_DBG without valid slave
Martin Troxler <ch1010277@ch10pc446>
parents: 2032
diff changeset
  1297
    if (request->slave)
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1298
        EC_SLAVE_DBG(request->slave, 1, "Releasing SDO request %p.\n",
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1299
                request);
2027
ac35f4d38a31 SDO wait_event() deadlock fixed: refcount ec_master_sdo_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2020
diff changeset
  1300
    ec_sdo_request_clear(&request->req);
ac35f4d38a31 SDO wait_event() deadlock fixed: refcount ec_master_sdo_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2020
diff changeset
  1301
    kfree(request);
ac35f4d38a31 SDO wait_event() deadlock fixed: refcount ec_master_sdo_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2020
diff changeset
  1302
}
2029
5ef6507fc77a FoE wait_event() deadlock fixed: refcount ec_master_foe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2028
diff changeset
  1303
5ef6507fc77a FoE wait_event() deadlock fixed: refcount ec_master_foe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2028
diff changeset
  1304
/*****************************************************************************/
5ef6507fc77a FoE wait_event() deadlock fixed: refcount ec_master_foe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2028
diff changeset
  1305
5ef6507fc77a FoE wait_event() deadlock fixed: refcount ec_master_foe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2028
diff changeset
  1306
/** called by kref_put if the FoE request's refcount becomes zero.
5ef6507fc77a FoE wait_event() deadlock fixed: refcount ec_master_foe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2028
diff changeset
  1307
 *
5ef6507fc77a FoE wait_event() deadlock fixed: refcount ec_master_foe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2028
diff changeset
  1308
 */
5ef6507fc77a FoE wait_event() deadlock fixed: refcount ec_master_foe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2028
diff changeset
  1309
void ec_master_foe_request_release(struct kref *ref)
5ef6507fc77a FoE wait_event() deadlock fixed: refcount ec_master_foe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2028
diff changeset
  1310
{
5ef6507fc77a FoE wait_event() deadlock fixed: refcount ec_master_foe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2028
diff changeset
  1311
    ec_master_foe_request_t *request = container_of(ref, ec_master_foe_request_t, refcount);
2034
ca03a6737cb7 releasing of refcounted requests fixed: do not call EC_SLAVE_DBG without valid slave
Martin Troxler <ch1010277@ch10pc446>
parents: 2032
diff changeset
  1312
    if (request->slave)
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1313
        EC_SLAVE_DBG(request->slave, 1, "Releasing FoE request %p.\n",
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1314
                request);
2029
5ef6507fc77a FoE wait_event() deadlock fixed: refcount ec_master_foe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2028
diff changeset
  1315
    ec_foe_request_clear(&request->req);
5ef6507fc77a FoE wait_event() deadlock fixed: refcount ec_master_foe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2028
diff changeset
  1316
    kfree(request);
5ef6507fc77a FoE wait_event() deadlock fixed: refcount ec_master_foe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2028
diff changeset
  1317
}
2032
57c618557912 SoE request wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_soe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2031
diff changeset
  1318
57c618557912 SoE request wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_soe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2031
diff changeset
  1319
/*****************************************************************************/
57c618557912 SoE request wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_soe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2031
diff changeset
  1320
57c618557912 SoE request wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_soe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2031
diff changeset
  1321
/** called by kref_put if the SoE request's refcount becomes zero.
57c618557912 SoE request wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_soe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2031
diff changeset
  1322
 *
57c618557912 SoE request wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_soe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2031
diff changeset
  1323
 */
57c618557912 SoE request wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_soe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2031
diff changeset
  1324
void ec_master_soe_request_release(struct kref *ref)
57c618557912 SoE request wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_soe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2031
diff changeset
  1325
{
57c618557912 SoE request wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_soe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2031
diff changeset
  1326
    ec_master_soe_request_t *request = container_of(ref, ec_master_soe_request_t, refcount);
2034
ca03a6737cb7 releasing of refcounted requests fixed: do not call EC_SLAVE_DBG without valid slave
Martin Troxler <ch1010277@ch10pc446>
parents: 2032
diff changeset
  1327
    if (request->slave)
2094
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1328
        EC_SLAVE_DBG(request->slave, 1, "Releasing SoE request %p.\n",
83e9160319ec Minor: Fixed line wraps and spacing.
Florian Pose <fp@igh-essen.com>
parents: 2045
diff changeset
  1329
                request);
2032
57c618557912 SoE request wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_soe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2031
diff changeset
  1330
    ec_soe_request_clear(&request->req);
57c618557912 SoE request wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_soe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2031
diff changeset
  1331
    kfree(request);
57c618557912 SoE request wait_event() deadlock fixed: use wait_event_interruptible and refcount ec_master_soe_request_t objects with kref
Martin Troxler <ch1010277@ch10pc446>
parents: 2031
diff changeset
  1332
}