master/fsm.c
author Florian Pose <fp@igh-essen.com>
Fri, 08 Dec 2006 11:52:33 +0000
changeset 499 fb005e975181
parent 484 9fde4a17b820
child 505 bc443ca0077f
permissions -rw-r--r--
Current consumption in sysfs; "lsec -c" shows current consumption and remaining current.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
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
 *
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  and/or modify it under the terms of the GNU General Public License
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    11
 *  as published by the Free Software Foundation; either version 2 of the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    12
 *  License, or (at your option) any later version.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  The IgH EtherCAT Master is distributed in the hope that it will be
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *  GNU General Public License for more details.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  You should have received a copy of the GNU General Public License
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *  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
    22
 *
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    23
 *  The right to use EtherCAT Technology is granted and comes free of
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    24
 *  charge under condition of compatibility of product made by
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    25
 *  Licensee. People intending to distribute/sell products based on the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    26
 *  code, have to sign an agreement to guarantee that products using
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    27
 *  software based on IgH EtherCAT master stay compatible with the actual
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    28
 *  EtherCAT specification (which are released themselves as an open
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    29
 *  standard) as the (only) precondition to have the right to use EtherCAT
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    30
 *  Technology, IP and trade marks.
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 238
diff changeset
    31
 *
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
 *****************************************************************************/
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
   \file
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
   EtherCAT finite state machines.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include "globals.h"
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include "fsm.h"
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#include "master.h"
329
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    44
#include "mailbox.h"
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
void ec_fsm_master_start(ec_fsm_t *);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    49
void ec_fsm_master_broadcast(ec_fsm_t *);
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
    50
void ec_fsm_master_read_states(ec_fsm_t *);
454
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
    51
void ec_fsm_master_acknowledge(ec_fsm_t *);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    52
void ec_fsm_master_validate_vendor(ec_fsm_t *);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    53
void ec_fsm_master_validate_product(ec_fsm_t *);
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
    54
void ec_fsm_master_rewrite_addresses(ec_fsm_t *);
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
    55
void ec_fsm_master_configure_slave(ec_fsm_t *);
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
    56
void ec_fsm_master_scan_slaves(ec_fsm_t *);
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
    57
void ec_fsm_master_write_eeprom(ec_fsm_t *);
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
    58
void ec_fsm_master_sdodict(ec_fsm_t *);
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
    59
void ec_fsm_master_sdo_request(ec_fsm_t *);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
    60
void ec_fsm_master_end(ec_fsm_t *);
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
    61
void ec_fsm_master_error(ec_fsm_t *);
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
    62
308
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
    63
void ec_fsm_slavescan_start(ec_fsm_t *);
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
    64
void ec_fsm_slavescan_address(ec_fsm_t *);
308
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
    65
void ec_fsm_slavescan_state(ec_fsm_t *);
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
    66
void ec_fsm_slavescan_base(ec_fsm_t *);
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
    67
void ec_fsm_slavescan_datalink(ec_fsm_t *);
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
    68
void ec_fsm_slavescan_eeprom_size(ec_fsm_t *);
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
    69
void ec_fsm_slavescan_eeprom_data(ec_fsm_t *);
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
    70
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
    71
void ec_fsm_slaveconf_state_start(ec_fsm_t *);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
    72
void ec_fsm_slaveconf_state_init(ec_fsm_t *);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
    73
void ec_fsm_slaveconf_state_clear_fmmus(ec_fsm_t *);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
    74
void ec_fsm_slaveconf_state_sync(ec_fsm_t *);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
    75
void ec_fsm_slaveconf_state_preop(ec_fsm_t *);
478
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
    76
void ec_fsm_slaveconf_state_sync2(ec_fsm_t *);
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
    77
void ec_fsm_slaveconf_state_fmmu(ec_fsm_t *);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
    78
void ec_fsm_slaveconf_state_sdoconf(ec_fsm_t *);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
    79
void ec_fsm_slaveconf_state_saveop(ec_fsm_t *);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
    80
void ec_fsm_slaveconf_state_op(ec_fsm_t *);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
    81
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
    82
void ec_fsm_slaveconf_enter_sync(ec_fsm_t *);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
    83
void ec_fsm_slaveconf_enter_preop(ec_fsm_t *);
478
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
    84
void ec_fsm_slaveconf_enter_sync2(ec_fsm_t *);
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
    85
void ec_fsm_slaveconf_enter_fmmu(ec_fsm_t *);
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
    86
void ec_fsm_slaveconf_enter_sdoconf(ec_fsm_t *);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
    87
void ec_fsm_slaveconf_enter_saveop(ec_fsm_t *);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
    88
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
    89
void ec_fsm_slave_state_end(ec_fsm_t *);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
    90
void ec_fsm_slave_state_error(ec_fsm_t *);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    91
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    94
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    95
   Constructor.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    96
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    97
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    98
int ec_fsm_init(ec_fsm_t *fsm, /**< finite state machine */
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
    99
                ec_master_t *master /**< EtherCAT master */
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   100
                )
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
    fsm->master = master;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
    fsm->master_state = ec_fsm_master_start;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
    fsm->master_slaves_responding = 0;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
    fsm->master_slave_states = EC_SLAVE_STATE_UNKNOWN;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   106
    fsm->master_validation = 0;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   108
    ec_datagram_init(&fsm->datagram);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   109
    if (ec_datagram_prealloc(&fsm->datagram, EC_MAX_DATA_SIZE)) {
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   110
        EC_ERR("Failed to allocate FSM datagram.\n");
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
        return -1;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   114
    // init sub-state-machines
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   115
    ec_fsm_sii_init(&fsm->fsm_sii, &fsm->datagram);
434
0180d8277311 Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
   116
    ec_fsm_change_init(&fsm->fsm_change, &fsm->datagram);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   117
    ec_fsm_coe_init(&fsm->fsm_coe, &fsm->datagram);
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   118
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
    return 0;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
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
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   124
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   125
   Destructor.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   126
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   127
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   128
void ec_fsm_clear(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
{
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   130
    // clear sub-state machines
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   131
    ec_fsm_sii_clear(&fsm->fsm_sii);
434
0180d8277311 Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
   132
    ec_fsm_change_clear(&fsm->fsm_change);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   133
    ec_fsm_coe_clear(&fsm->fsm_coe);
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   134
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   135
    ec_datagram_clear(&fsm->datagram);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   140
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   141
   Executes the current state of the state machine.
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
   142
   \return false, if state machine has terminated
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
   143
*/
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
   144
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
   145
int ec_fsm_exec(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
    fsm->master_state(fsm);
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
   148
456
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   149
    return ec_fsm_running(fsm);
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   150
}
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   151
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   152
/*****************************************************************************/
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   153
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   154
/**
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   155
   \return false, if state machine has terminated
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   156
*/
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   157
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   158
int ec_fsm_running(ec_fsm_t *fsm /**< finite state machine */)
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   159
{
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   160
    return fsm->master_state != ec_fsm_master_end
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   161
        && fsm->master_state != ec_fsm_master_error;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   162
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   163
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   164
/*****************************************************************************/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   165
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   166
/**
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   167
   \return true, if the master state machine terminated gracefully
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   168
*/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   169
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   170
int ec_fsm_success(ec_fsm_t *fsm /**< finite state machine */)
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   171
{
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   172
    return fsm->master_state == ec_fsm_master_end;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   173
}
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   174
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
/******************************************************************************
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   176
 *  operation/idle state machine
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
 *****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   180
   Master state: START.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
   Starts with getting slave count and slave states.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
void ec_fsm_master_start(ec_fsm_t *fsm)
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   186
    ec_datagram_brd(&fsm->datagram, 0x0130, 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   187
    ec_master_queue_datagram(fsm->master, &fsm->datagram);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   188
    fsm->master_state = ec_fsm_master_broadcast;
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
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   191
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   192
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   193
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   194
   Master state: BROADCAST.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   195
   Processes the broadcast read slave count and slaves states.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   196
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   197
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   198
void ec_fsm_master_broadcast(ec_fsm_t *fsm /**< finite state machine */)
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   199
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   200
    ec_datagram_t *datagram = &fsm->datagram;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   201
    unsigned int topology_change, states_change, i;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
    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
   203
    ec_master_t *master = fsm->master;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   205
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   206
        if (!master->device->link_state) {
254
986afccca9ea Link down treated as topology change in state machine.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
   207
            fsm->master_slaves_responding = 0;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   208
            list_for_each_entry(slave, &master->slaves, list) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   209
                slave->online = 0;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   210
            }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   211
        }
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   212
        else {
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   213
            EC_ERR("Failed to receive broadcast datagram.\n");
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   214
        }
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   215
        fsm->master_state = ec_fsm_master_error;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   217
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   218
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   219
    topology_change = (datagram->working_counter !=
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   220
                       fsm->master_slaves_responding);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   221
    states_change = (EC_READ_U8(datagram->data) != fsm->master_slave_states);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   222
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   223
    fsm->master_slave_states = EC_READ_U8(datagram->data);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   224
    fsm->master_slaves_responding = datagram->working_counter;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   225
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   226
    if (topology_change) {
262
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   227
        EC_INFO("%i slave%s responding.\n",
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   228
                fsm->master_slaves_responding,
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   229
                fsm->master_slaves_responding == 1 ? "" : "s");
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   230
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   231
        if (master->mode == EC_MASTER_MODE_OPERATION) {
262
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   232
            if (fsm->master_slaves_responding == master->slave_count) {
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   233
                fsm->master_validation = 1; // start validation later
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   234
            }
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   235
            else {
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   236
                EC_WARN("Invalid slave count. Bus in tainted state.\n");
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   237
            }
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   238
        }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   239
    }
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
    if (states_change) {
403
7bb931deccd9 Added EC_SLAVE_STATE_ACK_ERR to ec_state_string(); added EC_STATE_STRING_SIZE
Florian Pose <fp@igh-essen.com>
parents: 402
diff changeset
   242
        char states[EC_STATE_STRING_SIZE];
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   243
        ec_state_string(fsm->master_slave_states, states);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   244
        EC_INFO("Slave states: %s.\n", states);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   245
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   246
306
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 304
diff changeset
   247
    // topology change in idle mode: clear all slaves and scan the bus
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 304
diff changeset
   248
    if (topology_change && master->mode == EC_MASTER_MODE_IDLE) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   249
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   250
        ec_master_eoe_stop(master);
448
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   251
        ec_master_destroy_slaves(master);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   252
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   253
        master->slave_count = datagram->working_counter;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   254
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   255
        if (!master->slave_count) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   256
            // no slaves present -> finish state machine.
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   257
            fsm->master_state = ec_fsm_master_end;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   258
            return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   259
        }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   260
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   261
        // init slaves
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   262
        for (i = 0; i < master->slave_count; i++) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   263
            if (!(slave = (ec_slave_t *) kmalloc(sizeof(ec_slave_t),
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   264
                                                 GFP_ATOMIC))) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   265
                EC_ERR("Failed to allocate slave %i!\n", i);
448
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   266
                ec_master_destroy_slaves(master);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   267
                fsm->master_state = ec_fsm_master_error;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   268
                return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   269
            }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   270
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   271
            if (ec_slave_init(slave, master, i, i + 1)) {
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   272
                // freeing of "slave" already done
448
e4b76dc7910c FIX: Introduced destroy() functions for kobject-derived classes and thus fixed memory leak.
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   273
                ec_master_destroy_slaves(master);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   274
                fsm->master_state = ec_fsm_master_error;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   275
                return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   276
            }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   277
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   278
            list_add_tail(&slave->list, &master->slaves);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   279
        }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   280
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   281
        EC_INFO("Scanning bus.\n");
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   282
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   283
        // begin scanning of slaves
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   284
        fsm->slave = list_entry(master->slaves.next, ec_slave_t, list);
308
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
   285
        fsm->slave_state = ec_fsm_slavescan_start;
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   286
        fsm->master_state = ec_fsm_master_scan_slaves;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   287
        fsm->master_state(fsm); // execute immediately
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   288
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   289
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   290
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   291
    // fetch state from each slave
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   292
    fsm->slave = list_entry(master->slaves.next, ec_slave_t, list);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   293
    ec_datagram_nprd(&fsm->datagram, fsm->slave->station_address, 0x0130, 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   294
    ec_master_queue_datagram(master, &fsm->datagram);
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   295
    fsm->master_state = ec_fsm_master_read_states;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   296
}
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   297
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   298
/*****************************************************************************/
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   299
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   300
/**
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   301
   Master action: PROC_STATES.
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   302
   Processes the slave states.
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   303
*/
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   305
void ec_fsm_master_action_process_states(ec_fsm_t *fsm
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   306
                                         /**< finite state machine */
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   307
                                         )
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   308
{
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   309
    ec_master_t *master = fsm->master;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   310
    ec_slave_t *slave;
403
7bb931deccd9 Added EC_SLAVE_STATE_ACK_ERR to ec_state_string(); added EC_STATE_STRING_SIZE
Florian Pose <fp@igh-essen.com>
parents: 402
diff changeset
   311
    char old_state[EC_STATE_STRING_SIZE], new_state[EC_STATE_STRING_SIZE];
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   312
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   313
    // check if any slaves are not in the state, they're supposed to be
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   314
    list_for_each_entry(slave, &master->slaves, list) {
421
2b3ce4f51bd6 Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents: 420
diff changeset
   315
        if (slave->error_flag
2b3ce4f51bd6 Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents: 420
diff changeset
   316
            || !slave->online
2b3ce4f51bd6 Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents: 420
diff changeset
   317
            || slave->requested_state == EC_SLAVE_STATE_UNKNOWN
2b3ce4f51bd6 Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents: 420
diff changeset
   318
            || (slave->current_state == slave->requested_state
456
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   319
                && slave->configured)) continue;
421
2b3ce4f51bd6 Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents: 420
diff changeset
   320
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   321
        if (master->debug_level) {
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   322
            ec_state_string(slave->current_state, old_state);
456
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   323
            if (slave->current_state != slave->requested_state) {
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   324
                ec_state_string(slave->requested_state, new_state);
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   325
                EC_DBG("Changing state of slave %i (%s -> %s).\n",
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   326
                       slave->ring_position, old_state, new_state);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   327
            }
456
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   328
            else if (!slave->configured) {
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   329
                EC_DBG("Reconfiguring slave %i (%s).\n",
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   330
                       slave->ring_position, old_state);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   331
            }
421
2b3ce4f51bd6 Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents: 420
diff changeset
   332
        }
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   333
456
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   334
        fsm->master_state = ec_fsm_master_configure_slave;
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   335
        fsm->slave = slave;
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   336
        fsm->slave_state = ec_fsm_slaveconf_state_start;
456
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
   337
        fsm->slave_state(fsm); // execute immediately
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   338
        return;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   339
    }
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   340
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   341
    // Check, if EoE processing has to be started
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   342
    ec_master_eoe_start(master);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   343
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
   344
    if (master->mode == EC_MASTER_MODE_IDLE) {
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   345
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   346
        // Check for a pending SDO request
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   347
        if (master->sdo_seq_master != master->sdo_seq_user) {
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   348
            if (master->debug_level)
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   349
                EC_DBG("Processing SDO request...\n");
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   350
            slave = master->sdo_request->sdo->slave;
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   351
            if (slave->current_state == EC_SLAVE_STATE_INIT
475
e712a42446af Allow CoE requests, even if slave has error flag set.
Florian Pose <fp@igh-essen.com>
parents: 470
diff changeset
   352
                || !slave->online) {
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
   353
                EC_ERR("Failed to process SDO request, slave %i not ready.\n",
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   354
                       slave->ring_position);
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   355
                master->sdo_request->return_code = -1;
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   356
                master->sdo_seq_master++;
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   357
            }
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   358
            else {
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   359
                // start uploading SDO
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   360
                fsm->slave = slave;
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   361
                fsm->master_state = ec_fsm_master_sdo_request;
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   362
                fsm->sdo_request = master->sdo_request;
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   363
                ec_fsm_coe_upload(&fsm->fsm_coe, slave, fsm->sdo_request);
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   364
                ec_fsm_coe_exec(&fsm->fsm_coe); // execute immediately
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   365
                return;
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   366
            }
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   367
        }
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   368
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   369
        // check, if slaves have an SDO dictionary to read out.
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   370
        list_for_each_entry(slave, &master->slaves, list) {
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   371
            if (!(slave->sii_mailbox_protocols & EC_MBOX_COE)
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   372
                || 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
   373
                || slave->current_state == EC_SLAVE_STATE_INIT
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   374
                || jiffies - slave->jiffies_preop < EC_WAIT_SDO_DICT * HZ
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   375
                || !slave->online
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   376
                || slave->error_flag) continue;
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   377
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   378
            if (master->debug_level) {
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   379
                EC_DBG("Fetching SDO dictionary from slave %i.\n",
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   380
                       slave->ring_position);
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   381
            }
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   382
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   383
            slave->sdo_dictionary_fetched = 1;
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   384
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   385
            // start fetching SDO dictionary
441
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 437
diff changeset
   386
            fsm->slave = slave;
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
   387
            fsm->master_state = ec_fsm_master_sdodict;
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   388
            ec_fsm_coe_dictionary(&fsm->fsm_coe, slave);
441
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 437
diff changeset
   389
            ec_fsm_coe_exec(&fsm->fsm_coe); // execute immediately
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 437
diff changeset
   390
            return;
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 437
diff changeset
   391
        }
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
   392
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   393
        // check for pending EEPROM write operations.
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   394
        list_for_each_entry(slave, &master->slaves, list) {
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   395
            if (!slave->new_eeprom_data) continue;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   396
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   397
            if (!slave->online || slave->error_flag) {
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   398
                kfree(slave->new_eeprom_data);
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   399
                slave->new_eeprom_data = NULL;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   400
                EC_ERR("Discarding EEPROM data, slave %i not ready.\n",
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   401
                       slave->ring_position);
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   402
                continue;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   403
            }
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   404
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   405
            // found pending EEPROM write operation. execute it!
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   406
            EC_INFO("Writing EEPROM of slave %i...\n", slave->ring_position);
470
4ec31555832b Fixed EEPROM writing.
Florian Pose <fp@igh-essen.com>
parents: 462
diff changeset
   407
            fsm->slave = slave;
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   408
            fsm->sii_offset = 0x0000;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   409
            ec_fsm_sii_write(&fsm->fsm_sii, slave, fsm->sii_offset,
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   410
                             slave->new_eeprom_data, EC_FSM_SII_NODE);
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   411
            fsm->master_state = ec_fsm_master_write_eeprom;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   412
            fsm->master_state(fsm); // execute immediately
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   413
            return;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   414
        }
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   415
    }
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   416
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   417
    fsm->master_state = ec_fsm_master_end;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   418
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   419
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   420
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   421
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   422
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   423
   Master action: Get state of next slave.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   424
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   425
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   426
void ec_fsm_master_action_next_slave_state(ec_fsm_t *fsm
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   427
                                           /**< finite state machine */)
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   428
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   429
    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
   430
    ec_slave_t *slave = fsm->slave;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   431
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   432
    // is there another slave to query?
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   433
    if (slave->list.next != &master->slaves) {
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   434
        // process next slave
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   435
        fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   436
        ec_datagram_nprd(&fsm->datagram, fsm->slave->station_address,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   437
                         0x0130, 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   438
        ec_master_queue_datagram(master, &fsm->datagram);
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   439
        fsm->master_state = ec_fsm_master_read_states;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   440
        return;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   441
    }
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   442
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   443
    // all slave states read
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   444
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   445
    // check, if a bus validation has to be done
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   446
    if (fsm->master_validation) {
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   447
        fsm->master_validation = 0;
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   448
        list_for_each_entry(slave, &master->slaves, list) {
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   449
            if (slave->online) continue;
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   450
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   451
            // At least one slave is offline. validate!
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   452
            EC_INFO("Validating bus.\n");
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   453
            fsm->slave = list_entry(master->slaves.next, ec_slave_t, list);
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   454
            fsm->master_state = ec_fsm_master_validate_vendor;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   455
            ec_fsm_sii_read(&fsm->fsm_sii, slave, 0x0008, EC_FSM_SII_POSITION);
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   456
            ec_fsm_sii_exec(&fsm->fsm_sii); // execute immediately
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   457
            return;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   458
        }
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   459
    }
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   460
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   461
    ec_fsm_master_action_process_states(fsm);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   462
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   463
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   464
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   465
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   466
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   467
   Master state: READ STATES.
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   468
   Fetches the AL- and online state of a slave.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   469
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   470
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   471
void ec_fsm_master_read_states(ec_fsm_t *fsm /**< finite state machine */)
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   472
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   473
    ec_slave_t *slave = fsm->slave;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   474
    ec_datagram_t *datagram = &fsm->datagram;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   475
    uint8_t new_state;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   476
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   477
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   478
        EC_ERR("Failed to receive AL state datagram for slave %i!\n",
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   479
               slave->ring_position);
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   480
        fsm->master_state = ec_fsm_master_error;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   481
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   482
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   483
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   484
    // did the slave not respond to its station address?
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   485
    if (datagram->working_counter != 1) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   486
        if (slave->online) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   487
            slave->online = 0;
461
b9eda9235173 Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 459
diff changeset
   488
            if (slave->master->debug_level)
459
f0da52cf6b5b Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 456
diff changeset
   489
                EC_DBG("Slave %i: offline.\n", slave->ring_position);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   490
        }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   491
        ec_fsm_master_action_next_slave_state(fsm);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   492
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   493
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   494
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   495
    // slave responded
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   496
    new_state = EC_READ_U8(datagram->data);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   497
    if (!slave->online) { // slave was offline before
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   498
        slave->online = 1;
291
0b1f877cf3f1 Slave: state_error -> error_flag, error_flag only in slave state machine.
Florian Pose <fp@igh-essen.com>
parents: 290
diff changeset
   499
        slave->error_flag = 0; // clear error flag
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   500
        slave->current_state = new_state;
461
b9eda9235173 Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 459
diff changeset
   501
        if (slave->master->debug_level) {
459
f0da52cf6b5b Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 456
diff changeset
   502
            char cur_state[EC_STATE_STRING_SIZE];
f0da52cf6b5b Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 456
diff changeset
   503
            ec_state_string(slave->current_state, cur_state);
f0da52cf6b5b Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 456
diff changeset
   504
            EC_DBG("Slave %i: online (%s).\n",
f0da52cf6b5b Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 456
diff changeset
   505
                   slave->ring_position, cur_state);
f0da52cf6b5b Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 456
diff changeset
   506
        }
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   507
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   508
    else if (new_state != slave->current_state) {
461
b9eda9235173 Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 459
diff changeset
   509
        if (slave->master->debug_level) {
459
f0da52cf6b5b Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 456
diff changeset
   510
            char old_state[EC_STATE_STRING_SIZE],
f0da52cf6b5b Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 456
diff changeset
   511
                cur_state[EC_STATE_STRING_SIZE];
f0da52cf6b5b Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 456
diff changeset
   512
            ec_state_string(slave->current_state, old_state);
f0da52cf6b5b Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 456
diff changeset
   513
            ec_state_string(new_state, cur_state);
f0da52cf6b5b Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 456
diff changeset
   514
            EC_DBG("Slave %i: %s -> %s.\n",
f0da52cf6b5b Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 456
diff changeset
   515
                   slave->ring_position, old_state, cur_state);
f0da52cf6b5b Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 456
diff changeset
   516
        }
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   517
        slave->current_state = new_state;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   518
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   519
454
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   520
    // check, if new slave state has to be acknowledged
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   521
    if (slave->current_state & EC_SLAVE_STATE_ACK_ERR && !slave->error_flag) {
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   522
        ec_fsm_change_ack(&fsm->fsm_change, slave);
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   523
        ec_fsm_change_exec(&fsm->fsm_change);
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   524
        fsm->master_state = ec_fsm_master_acknowledge;
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   525
        return;
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   526
    }
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   527
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   528
    ec_fsm_master_action_next_slave_state(fsm);
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   529
}
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   530
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   531
/*****************************************************************************/
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   532
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   533
/**
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   534
   Master state: ACKNOWLEDGE
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   535
*/
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   536
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   537
void ec_fsm_master_acknowledge(ec_fsm_t *fsm /**< finite state machine */)
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   538
{
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   539
    ec_slave_t *slave = fsm->slave;
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   540
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   541
    if (ec_fsm_change_exec(&fsm->fsm_change)) return;
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   542
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   543
    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
   544
        fsm->slave->error_flag = 1;
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   545
        EC_ERR("Failed to acknowledge state change on slave %i.\n",
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   546
               slave->ring_position);
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   547
        fsm->master_state = ec_fsm_master_error;
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   548
        return;
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   549
    }
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   550
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   551
    ec_fsm_master_action_next_slave_state(fsm);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   552
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   553
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   554
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   555
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   556
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   557
   Master state: VALIDATE_VENDOR.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   558
   Validates the vendor ID of a slave.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   559
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   560
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   561
void ec_fsm_master_validate_vendor(ec_fsm_t *fsm /**< finite state machine */)
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   562
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   563
    ec_slave_t *slave = fsm->slave;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   564
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
   565
    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
   566
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   567
    if (!ec_fsm_sii_success(&fsm->fsm_sii)) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   568
        fsm->slave->error_flag = 1;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   569
        EC_ERR("Failed to validate vendor ID of slave %i.\n",
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   570
               slave->ring_position);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   571
        fsm->master_state = ec_fsm_master_error;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   572
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   573
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   574
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   575
    if (EC_READ_U32(fsm->fsm_sii.value) != slave->sii_vendor_id) {
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   576
        EC_ERR("Slave %i has an invalid vendor ID!\n", slave->ring_position);
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   577
        fsm->master_state = ec_fsm_master_error;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   578
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   579
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   580
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   581
    // vendor ID is ok. check product code.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   582
    fsm->master_state = ec_fsm_master_validate_product;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   583
    ec_fsm_sii_read(&fsm->fsm_sii, slave, 0x000A, EC_FSM_SII_POSITION);
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   584
    ec_fsm_sii_exec(&fsm->fsm_sii); // execute immediately
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   585
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   586
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   587
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   588
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   589
/**
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   590
   Master action: ADDRESS.
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   591
   Looks for slave, that have lost their configuration and writes
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   592
   their station address, so that they can be reconfigured later.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   593
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   594
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   595
void ec_fsm_master_action_addresses(ec_fsm_t *fsm /**< finite state machine */)
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   596
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   597
    ec_datagram_t *datagram = &fsm->datagram;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   598
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   599
    while (fsm->slave->online) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   600
        if (fsm->slave->list.next == &fsm->master->slaves) { // last slave?
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   601
            fsm->master_state = ec_fsm_master_start;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   602
            fsm->master_state(fsm); // execute immediately
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   603
            return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   604
        }
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   605
        // check next slave
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   606
        fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   607
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   608
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   609
    if (fsm->master->debug_level)
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   610
        EC_DBG("Reinitializing slave %i.\n", fsm->slave->ring_position);
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   611
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   612
    // write station address
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   613
    ec_datagram_apwr(datagram, fsm->slave->ring_position, 0x0010, 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   614
    EC_WRITE_U16(datagram->data, fsm->slave->station_address);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   615
    ec_master_queue_datagram(fsm->master, datagram);
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   616
    fsm->master_state = ec_fsm_master_rewrite_addresses;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   617
}
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   618
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   619
/*****************************************************************************/
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   620
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   621
/**
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   622
   Master state: VALIDATE_PRODUCT.
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   623
   Validates the product ID of a slave.
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   624
*/
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   625
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   626
void ec_fsm_master_validate_product(ec_fsm_t *fsm /**< finite state machine */)
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   627
{
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   628
    ec_slave_t *slave = fsm->slave;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   629
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
   630
    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
   631
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   632
    if (!ec_fsm_sii_success(&fsm->fsm_sii)) {
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   633
        fsm->slave->error_flag = 1;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   634
        EC_ERR("Failed to validate product code of slave %i.\n",
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   635
               slave->ring_position);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   636
        fsm->master_state = ec_fsm_master_error;
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   637
        return;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   638
    }
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   639
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   640
    if (EC_READ_U32(fsm->fsm_sii.value) != slave->sii_product_code) {
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   641
        EC_ERR("Slave %i: invalid product code!\n", slave->ring_position);
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   642
        EC_ERR("expected 0x%08X, got 0x%08X.\n", slave->sii_product_code,
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   643
               EC_READ_U32(fsm->fsm_sii.value));
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   644
        fsm->master_state = ec_fsm_master_error;
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   645
        return;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   646
    }
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   647
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   648
    // have all states been validated?
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   649
    if (slave->list.next == &fsm->master->slaves) {
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   650
        fsm->slave = list_entry(fsm->master->slaves.next, ec_slave_t, list);
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   651
        // start writing addresses to offline slaves
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   652
        ec_fsm_master_action_addresses(fsm);
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   653
        return;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   654
    }
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   655
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   656
    // validate next slave
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   657
    fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list);
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   658
    fsm->master_state = ec_fsm_master_validate_vendor;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   659
    ec_fsm_sii_read(&fsm->fsm_sii, slave, 0x0008, EC_FSM_SII_POSITION);
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   660
    ec_fsm_sii_exec(&fsm->fsm_sii); // execute immediately
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   661
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   662
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   663
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   664
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   665
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   666
   Master state: REWRITE ADDRESS.
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   667
   Checks, if the new station address has been written to the slave.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   668
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   669
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   670
void ec_fsm_master_rewrite_addresses(ec_fsm_t *fsm
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   671
                                     /**< finite state machine */
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   672
                                     )
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   673
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   674
    ec_slave_t *slave = fsm->slave;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   675
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   676
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   677
    if (datagram->state != EC_DATAGRAM_RECEIVED
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   678
        || datagram->working_counter != 1) {
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   679
        EC_ERR("Failed to write station address on slave %i.\n",
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   680
               slave->ring_position);
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   681
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   682
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   683
    if (fsm->slave->list.next == &fsm->master->slaves) { // last slave?
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   684
        fsm->master_state = ec_fsm_master_start;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   685
        fsm->master_state(fsm); // execute immediately
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   686
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   687
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   688
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   689
    // check next slave
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   690
    fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list);
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   691
    // Write new station address to slave
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   692
    ec_fsm_master_action_addresses(fsm);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   693
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   694
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   695
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   696
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   697
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   698
   Master state: SCAN SLAVES.
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   699
   Executes the sub-statemachine for the scanning of a slave.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   700
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   701
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   702
void ec_fsm_master_scan_slaves(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   703
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   704
    ec_master_t *master = fsm->master;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   705
    ec_slave_t *slave = fsm->slave;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   706
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   707
    fsm->slave_state(fsm); // execute slave state machine
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   708
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   709
    if (fsm->slave_state != ec_fsm_slave_state_end
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   710
        && fsm->slave_state != ec_fsm_slave_state_error) return;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   711
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   712
    // another slave to fetch?
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   713
    if (slave->list.next != &master->slaves) {
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   714
        fsm->slave = list_entry(fsm->slave->list.next, ec_slave_t, list);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   715
        fsm->slave_state = ec_fsm_slavescan_start;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   716
        fsm->slave_state(fsm); // execute immediately
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   717
        return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   718
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   719
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   720
    EC_INFO("Bus scanning completed.\n");
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   721
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   722
    ec_master_calc_addressing(master);
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   723
428
2731a2fcc18d Set initial state of all slaves to PREOP.
Florian Pose <fp@igh-essen.com>
parents: 427
diff changeset
   724
    // set initial states of all slaves to PREOP to make mailbox
2731a2fcc18d Set initial state of all slaves to PREOP.
Florian Pose <fp@igh-essen.com>
parents: 427
diff changeset
   725
    // communication possible
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   726
    list_for_each_entry(slave, &master->slaves, list) {
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   727
        ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP);
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   728
    }
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   729
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   730
    fsm->master_state = ec_fsm_master_end;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   731
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   732
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   733
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   734
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   735
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   736
   Master state: CONFIGURE SLAVES.
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   737
   Starts configuring a slave.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   738
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   739
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   740
void ec_fsm_master_configure_slave(ec_fsm_t *fsm
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   741
                                   /**< finite state machine */
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   742
                                   )
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   743
{
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   744
    fsm->slave_state(fsm); // execute slave's state machine
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   745
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   746
    if (fsm->slave_state != ec_fsm_slave_state_end
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   747
        && fsm->slave_state != ec_fsm_slave_state_error) return;
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   748
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   749
    ec_fsm_master_action_process_states(fsm);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   750
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   751
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   752
/*****************************************************************************/
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   753
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   754
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   755
   Master state: WRITE EEPROM.
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   756
*/
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   757
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   758
void ec_fsm_master_write_eeprom(ec_fsm_t *fsm /**< finite state machine */)
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   759
{
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   760
    ec_slave_t *slave = fsm->slave;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   761
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
   762
    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
   763
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   764
    if (!ec_fsm_sii_success(&fsm->fsm_sii)) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   765
        fsm->slave->error_flag = 1;
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   766
        EC_ERR("Failed to write EEPROM contents to slave %i.\n",
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   767
               slave->ring_position);
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   768
        kfree(slave->new_eeprom_data);
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   769
        slave->new_eeprom_data = NULL;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   770
        fsm->master_state = ec_fsm_master_error;
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   771
        return;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   772
    }
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   773
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   774
    fsm->sii_offset++;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   775
    if (fsm->sii_offset < slave->new_eeprom_size) {
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   776
        ec_fsm_sii_write(&fsm->fsm_sii, slave, fsm->sii_offset,
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   777
                         slave->new_eeprom_data + fsm->sii_offset,
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   778
                         EC_FSM_SII_NODE);
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   779
        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
   780
        return;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   781
    }
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   782
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   783
    // finished writing EEPROM
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   784
    EC_INFO("Finished writing EEPROM of slave %i.\n", slave->ring_position);
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   785
    kfree(slave->new_eeprom_data);
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   786
    slave->new_eeprom_data = NULL;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   787
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   788
    // TODO: Evaluate new EEPROM contents!
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   789
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   790
    // restart master state machine.
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   791
    fsm->master_state = ec_fsm_master_start;
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   792
    fsm->master_state(fsm); // execute immediately
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   793
}
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   794
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   795
/*****************************************************************************/
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   796
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   797
/**
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   798
   Master state: SDODICT.
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   799
*/
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   800
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   801
void ec_fsm_master_sdodict(ec_fsm_t *fsm /**< finite state machine */)
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   802
{
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   803
    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
   804
    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
   805
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   806
    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
   807
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   808
    if (!ec_fsm_coe_success(&fsm->fsm_coe)) {
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   809
        fsm->master_state = ec_fsm_master_error;
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   810
        return;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   811
    }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   812
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   813
    // SDO dictionary fetching finished
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   814
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   815
    if (master->debug_level) {
423
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
   816
        unsigned int sdo_count, entry_count;
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
   817
        ec_slave_sdo_dict_info(slave, &sdo_count, &entry_count);
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
   818
        EC_DBG("Fetched %i SDOs and %i entries from slave %i.\n",
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
   819
               sdo_count, entry_count, slave->ring_position);
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   820
    }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   821
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   822
    // restart master state machine.
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   823
    fsm->master_state = ec_fsm_master_start;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   824
    fsm->master_state(fsm); // execute immediately
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   825
}
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   826
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   827
/*****************************************************************************/
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   828
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   829
/**
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   830
   Master state: SDO REQUEST.
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   831
*/
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   832
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   833
void ec_fsm_master_sdo_request(ec_fsm_t *fsm /**< finite state machine */)
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   834
{
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   835
    ec_master_t *master = fsm->master;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   836
    ec_sdo_request_t *request = fsm->sdo_request;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   837
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   838
    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
   839
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   840
    if (!ec_fsm_coe_success(&fsm->fsm_coe)) {
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   841
        request->return_code = -1;
441
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 437
diff changeset
   842
        master->sdo_seq_master++;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   843
        fsm->master_state = ec_fsm_master_error;
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   844
        return;
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   845
    }
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   846
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   847
    // SDO dictionary fetching finished
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   848
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   849
    request->return_code = 1;
441
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 437
diff changeset
   850
    master->sdo_seq_master++;
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   851
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   852
    // restart master state machine.
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   853
    fsm->master_state = ec_fsm_master_start;
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   854
    fsm->master_state(fsm); // execute immediately
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   855
}
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   856
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   857
/*****************************************************************************/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   858
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   859
/**
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   860
   State: ERROR.
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   861
*/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   862
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   863
void ec_fsm_master_error(ec_fsm_t *fsm /**< finite state machine */)
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   864
{
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   865
    fsm->master_state = ec_fsm_master_start;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   866
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   867
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   868
/*****************************************************************************/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   869
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   870
/**
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   871
   State: END.
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   872
*/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   873
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   874
void ec_fsm_master_end(ec_fsm_t *fsm /**< finite state machine */)
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   875
{
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   876
    fsm->master_state = ec_fsm_master_start;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   877
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   878
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   879
/******************************************************************************
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   880
 *  slave scan state machine
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   881
 *****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   882
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   883
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   884
   Slave scan state: START.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   885
   First state of the slave state machine. Writes the station address to the
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   886
   slave, according to its ring position.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   887
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   888
308
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
   889
void ec_fsm_slavescan_start(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   890
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   891
    ec_datagram_t *datagram = &fsm->datagram;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   892
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   893
    // write station address
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   894
    ec_datagram_apwr(datagram, fsm->slave->ring_position, 0x0010, 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   895
    EC_WRITE_U16(datagram->data, fsm->slave->station_address);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   896
    ec_master_queue_datagram(fsm->master, datagram);
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   897
    fsm->slave_state = ec_fsm_slavescan_address;
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   898
}
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   899
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   900
/*****************************************************************************/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   901
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   902
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   903
   Slave scan state: ADDRESS.
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   904
*/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   905
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   906
void ec_fsm_slavescan_address(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   907
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   908
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   909
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   910
    if (datagram->state != EC_DATAGRAM_RECEIVED
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   911
        || datagram->working_counter != 1) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   912
        fsm->slave->error_flag = 1;
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   913
        fsm->slave_state = ec_fsm_slave_state_error;
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   914
        EC_ERR("Failed to write station address of slave %i.\n",
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   915
               fsm->slave->ring_position);
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   916
        return;
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   917
    }
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   918
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   919
    // Read AL state
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   920
    ec_datagram_nprd(datagram, fsm->slave->station_address, 0x0130, 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   921
    ec_master_queue_datagram(fsm->master, datagram);
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   922
    fsm->slave_state = ec_fsm_slavescan_state;
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   923
}
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   924
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   925
/*****************************************************************************/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   926
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   927
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   928
   Slave scan state: STATE.
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   929
*/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   930
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   931
void ec_fsm_slavescan_state(ec_fsm_t *fsm /**< finite state machine */)
255
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   932
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   933
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   934
    ec_slave_t *slave = fsm->slave;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   935
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   936
    if (datagram->state != EC_DATAGRAM_RECEIVED
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   937
        || datagram->working_counter != 1) {
291
0b1f877cf3f1 Slave: state_error -> error_flag, error_flag only in slave state machine.
Florian Pose <fp@igh-essen.com>
parents: 290
diff changeset
   938
        fsm->slave->error_flag = 1;
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   939
        fsm->slave_state = ec_fsm_slave_state_error;
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   940
        EC_ERR("Failed to read AL state of slave %i.\n",
255
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   941
               fsm->slave->ring_position);
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   942
        return;
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   943
    }
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   944
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   945
    slave->current_state = EC_READ_U8(datagram->data);
402
03e31ac14047 Renamed EC_ACK to EC_SLAVE_STATE_ACK_ERR
Florian Pose <fp@igh-essen.com>
parents: 398
diff changeset
   946
    if (slave->current_state & EC_SLAVE_STATE_ACK_ERR) {
454
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   947
        char state_str[EC_STATE_STRING_SIZE];
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   948
        ec_state_string(slave->current_state, state_str);
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   949
        EC_WARN("Slave %i has state error bit set (%s)!\n",
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   950
                slave->ring_position, state_str);
255
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   951
    }
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   952
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   953
    // read base data
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   954
    ec_datagram_nprd(datagram, fsm->slave->station_address, 0x0000, 6);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   955
    ec_master_queue_datagram(fsm->master, datagram);
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   956
    fsm->slave_state = ec_fsm_slavescan_base;
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   957
}
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   958
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   959
/*****************************************************************************/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   960
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   961
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   962
   Slave scan state: BASE.
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   963
*/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   964
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   965
void ec_fsm_slavescan_base(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   966
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   967
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   968
    ec_slave_t *slave = fsm->slave;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   969
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   970
    if (datagram->state != EC_DATAGRAM_RECEIVED
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   971
        || datagram->working_counter != 1) {
291
0b1f877cf3f1 Slave: state_error -> error_flag, error_flag only in slave state machine.
Florian Pose <fp@igh-essen.com>
parents: 290
diff changeset
   972
        fsm->slave->error_flag = 1;
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   973
        fsm->slave_state = ec_fsm_slave_state_error;
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   974
        EC_ERR("Failed to read base data of slave %i.\n",
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   975
               slave->ring_position);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   976
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   977
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   978
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   979
    slave->base_type       = EC_READ_U8 (datagram->data);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   980
    slave->base_revision   = EC_READ_U8 (datagram->data + 1);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   981
    slave->base_build      = EC_READ_U16(datagram->data + 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   982
    slave->base_fmmu_count = EC_READ_U8 (datagram->data + 4);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   983
    slave->base_sync_count = EC_READ_U8 (datagram->data + 5);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   984
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   985
    if (slave->base_fmmu_count > EC_MAX_FMMUS)
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   986
        slave->base_fmmu_count = EC_MAX_FMMUS;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   987
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   988
    // read data link status
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   989
    ec_datagram_nprd(datagram, slave->station_address, 0x0110, 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   990
    ec_master_queue_datagram(slave->master, datagram);
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   991
    fsm->slave_state = ec_fsm_slavescan_datalink;
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   992
}
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   993
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   994
/*****************************************************************************/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   995
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   996
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   997
   Slave scan state: DATALINK.
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   998
*/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   999
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1000
void ec_fsm_slavescan_datalink(ec_fsm_t *fsm /**< finite state machine */)
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1001
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1002
    ec_datagram_t *datagram = &fsm->datagram;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1003
    ec_slave_t *slave = fsm->slave;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1004
    uint16_t dl_status;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1005
    unsigned int i;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1006
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1007
    if (datagram->state != EC_DATAGRAM_RECEIVED
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1008
        || datagram->working_counter != 1) {
291
0b1f877cf3f1 Slave: state_error -> error_flag, error_flag only in slave state machine.
Florian Pose <fp@igh-essen.com>
parents: 290
diff changeset
  1009
        fsm->slave->error_flag = 1;
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1010
        fsm->slave_state = ec_fsm_slave_state_error;
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1011
        EC_ERR("Failed to read DL status of slave %i.\n",
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1012
               slave->ring_position);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1013
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1014
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1015
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1016
    dl_status = EC_READ_U16(datagram->data);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1017
    for (i = 0; i < 4; i++) {
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1018
        slave->dl_link[i] = dl_status & (1 << (4 + i)) ? 1 : 0;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1019
        slave->dl_loop[i] = dl_status & (1 << (8 + i * 2)) ? 1 : 0;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1020
        slave->dl_signal[i] = dl_status & (1 << (9 + i * 2)) ? 1 : 0;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1021
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1022
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1023
    // Start fetching EEPROM size
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1024
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1025
    fsm->sii_offset = 0x0040; // first category header
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1026
    ec_fsm_sii_read(&fsm->fsm_sii, slave, fsm->sii_offset, EC_FSM_SII_NODE);
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1027
    fsm->slave_state = ec_fsm_slavescan_eeprom_size;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1028
    fsm->slave_state(fsm); // execute state immediately
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1029
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1030
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1031
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1032
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1033
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1034
   Slave scan state: EEPROM SIZE.
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1035
*/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1036
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1037
void ec_fsm_slavescan_eeprom_size(ec_fsm_t *fsm /**< finite state machine */)
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1038
{
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1039
    ec_slave_t *slave = fsm->slave;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1040
    uint16_t cat_type, cat_size;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1041
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
  1042
    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
  1043
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1044
    if (!ec_fsm_sii_success(&fsm->fsm_sii)) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1045
        fsm->slave->error_flag = 1;
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1046
        fsm->slave_state = ec_fsm_slave_state_error;
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1047
        EC_ERR("Failed to read EEPROM size of slave %i.\n",
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1048
               slave->ring_position);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1049
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1050
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1051
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1052
    cat_type = EC_READ_U16(fsm->fsm_sii.value);
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1053
    cat_size = EC_READ_U16(fsm->fsm_sii.value + 2);
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1054
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1055
    if (cat_type != 0xFFFF) { // not the last category
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1056
        fsm->sii_offset += cat_size + 2;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1057
        ec_fsm_sii_read(&fsm->fsm_sii, slave, fsm->sii_offset,
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1058
                        EC_FSM_SII_NODE);
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1059
        ec_fsm_sii_exec(&fsm->fsm_sii); // execute state immediately
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1060
        return;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1061
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1062
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1063
    slave->eeprom_size = (fsm->sii_offset + 1) * 2;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1064
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1065
    if (slave->eeprom_data) {
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1066
        EC_INFO("Freeing old EEPROM data on slave %i...\n",
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1067
                slave->ring_position);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1068
        kfree(slave->eeprom_data);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1069
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1070
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1071
    if (!(slave->eeprom_data =
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1072
          (uint8_t *) kmalloc(slave->eeprom_size, GFP_ATOMIC))) {
291
0b1f877cf3f1 Slave: state_error -> error_flag, error_flag only in slave state machine.
Florian Pose <fp@igh-essen.com>
parents: 290
diff changeset
  1073
        fsm->slave->error_flag = 1;
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1074
        fsm->slave_state = ec_fsm_slave_state_error;
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1075
        EC_ERR("Failed to allocate EEPROM data on slave %i.\n",
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1076
               slave->ring_position);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1077
        return;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1078
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1079
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1080
    // Start fetching EEPROM contents
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1081
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1082
    fsm->slave_state = ec_fsm_slavescan_eeprom_data;
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1083
    fsm->sii_offset = 0x0000;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1084
    ec_fsm_sii_read(&fsm->fsm_sii, slave, fsm->sii_offset, EC_FSM_SII_NODE);
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1085
    ec_fsm_sii_exec(&fsm->fsm_sii); // execute state immediately
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1086
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1087
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1088
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1089
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1090
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1091
   Slave scan state: EEPROM DATA.
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1092
*/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1093
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1094
void ec_fsm_slavescan_eeprom_data(ec_fsm_t *fsm /**< finite state machine */)
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1095
{
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1096
    ec_slave_t *slave = fsm->slave;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1097
    uint16_t *cat_word, cat_type, cat_size;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1098
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
  1099
    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
  1100
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1101
    if (!ec_fsm_sii_success(&fsm->fsm_sii)) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1102
        fsm->slave->error_flag = 1;
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1103
        fsm->slave_state = ec_fsm_slave_state_error;
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1104
        EC_ERR("Failed to fetch EEPROM contents of slave %i.\n",
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1105
               slave->ring_position);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1106
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1107
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1108
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1109
    // 2 words fetched
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1110
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1111
    if (fsm->sii_offset + 2 <= slave->eeprom_size / 2) { // 2 words fit
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1112
        memcpy(slave->eeprom_data + fsm->sii_offset * 2,
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1113
               fsm->fsm_sii.value, 4);
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1114
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1115
    else { // copy the last word
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1116
        memcpy(slave->eeprom_data + fsm->sii_offset * 2,
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1117
               fsm->fsm_sii.value, 2);
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1118
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1119
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1120
    if (fsm->sii_offset + 2 < slave->eeprom_size / 2) {
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1121
        // fetch the next 2 words
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1122
        fsm->sii_offset += 2;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1123
        ec_fsm_sii_read(&fsm->fsm_sii, slave, fsm->sii_offset,
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1124
                        EC_FSM_SII_NODE);
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1125
        ec_fsm_sii_exec(&fsm->fsm_sii); // execute state immediately
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1126
        return;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1127
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1128
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1129
    // Evaluate EEPROM contents
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1130
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1131
    slave->sii_alias =
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1132
        EC_READ_U16(slave->eeprom_data + 2 * 0x0004);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1133
    slave->sii_vendor_id =
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1134
        EC_READ_U32(slave->eeprom_data + 2 * 0x0008);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1135
    slave->sii_product_code =
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1136
        EC_READ_U32(slave->eeprom_data + 2 * 0x000A);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1137
    slave->sii_revision_number =
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1138
        EC_READ_U32(slave->eeprom_data + 2 * 0x000C);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1139
    slave->sii_serial_number =
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1140
        EC_READ_U32(slave->eeprom_data + 2 * 0x000E);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1141
    slave->sii_rx_mailbox_offset =
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1142
        EC_READ_U16(slave->eeprom_data + 2 * 0x0018);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1143
    slave->sii_rx_mailbox_size =
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1144
        EC_READ_U16(slave->eeprom_data + 2 * 0x0019);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1145
    slave->sii_tx_mailbox_offset =
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1146
        EC_READ_U16(slave->eeprom_data + 2 * 0x001A);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1147
    slave->sii_tx_mailbox_size =
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1148
        EC_READ_U16(slave->eeprom_data + 2 * 0x001B);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1149
    slave->sii_mailbox_protocols =
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1150
        EC_READ_U16(slave->eeprom_data + 2 * 0x001C);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1151
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1152
    // evaluate category data
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1153
    cat_word = (uint16_t *) slave->eeprom_data + 0x0040;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1154
    while (EC_READ_U16(cat_word) != 0xFFFF) {
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1155
        cat_type = EC_READ_U16(cat_word) & 0x7FFF;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1156
        cat_size = EC_READ_U16(cat_word + 1);
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1157
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1158
        switch (cat_type) {
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1159
            case 0x000A:
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1160
                if (ec_slave_fetch_strings(slave, (uint8_t *) (cat_word + 2)))
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1161
                    goto end;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1162
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1163
            case 0x001E:
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1164
                ec_slave_fetch_general(slave, (uint8_t *) (cat_word + 2));
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1165
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1166
            case 0x0028:
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1167
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1168
            case 0x0029:
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1169
                if (ec_slave_fetch_sync(slave, (uint8_t *) (cat_word + 2),
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1170
                                        cat_size))
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1171
                    goto end;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1172
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1173
            case 0x0032:
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1174
                if (ec_slave_fetch_pdo(slave, (uint8_t *) (cat_word + 2),
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1175
                                       cat_size, EC_TX_PDO))
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1176
                    goto end;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1177
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1178
            case 0x0033:
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1179
                if (ec_slave_fetch_pdo(slave, (uint8_t *) (cat_word + 2),
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1180
                                       cat_size, EC_RX_PDO))
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1181
                    goto end;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1182
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1183
            default:
461
b9eda9235173 Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 459
diff changeset
  1184
                if (fsm->master->debug_level)
b9eda9235173 Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 459
diff changeset
  1185
                    EC_WARN("Unknown category type 0x%04X in slave %i.\n",
b9eda9235173 Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 459
diff changeset
  1186
                            cat_type, slave->ring_position);
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1187
        }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1188
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1189
        cat_word += cat_size + 2;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1190
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1191
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1192
    fsm->slave_state = ec_fsm_slave_state_end;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1193
    return;
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1194
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1195
end:
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1196
    EC_ERR("Failed to analyze category data.\n");
291
0b1f877cf3f1 Slave: state_error -> error_flag, error_flag only in slave state machine.
Florian Pose <fp@igh-essen.com>
parents: 290
diff changeset
  1197
    fsm->slave->error_flag = 1;
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1198
    fsm->slave_state = ec_fsm_slave_state_error;
308
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
  1199
}
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
  1200
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
  1201
/******************************************************************************
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1202
 *  slave configuration state machine
308
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
  1203
 *****************************************************************************/
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1204
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1205
/**
456
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
  1206
   Slave configuration state: START.
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
  1207
*/
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
  1208
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1209
void ec_fsm_slaveconf_state_start(ec_fsm_t *fsm /**< finite state machine */)
456
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
  1210
{
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
  1211
    if (fsm->master->debug_level) {
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
  1212
        EC_DBG("Configuring slave %i...\n", fsm->slave->ring_position);
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
  1213
    }
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
  1214
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
  1215
    ec_fsm_change_start(&fsm->fsm_change, fsm->slave, EC_SLAVE_STATE_INIT);
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
  1216
    ec_fsm_change_exec(&fsm->fsm_change);
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1217
    fsm->slave_state = ec_fsm_slaveconf_state_init;
456
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
  1218
}
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
  1219
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
  1220
/*****************************************************************************/
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
  1221
dea14706efc2 Explicit use of slave configuration FSM in ecrt_master_activate() and ecrt_master_release().
Florian Pose <fp@igh-essen.com>
parents: 454
diff changeset
  1222
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1223
   Slave configuration state: INIT.
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1224
*/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1225
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1226
void ec_fsm_slaveconf_state_init(ec_fsm_t *fsm /**< finite state machine */)
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1227
{
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1228
    ec_master_t *master = fsm->master;
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1229
    ec_slave_t *slave = fsm->slave;
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1230
    ec_datagram_t *datagram = &fsm->datagram;
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1231
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1232
    if (ec_fsm_change_exec(&fsm->fsm_change)) return;
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1233
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1234
    if (!ec_fsm_change_success(&fsm->fsm_change)) {
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1235
        slave->error_flag = 1;
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1236
        fsm->slave_state = ec_fsm_slave_state_error;
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1237
        return;
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1238
    }
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1239
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1240
    slave->configured = 1;
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1241
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1242
    if (master->debug_level) {
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1243
        EC_DBG("Slave %i is now in INIT.\n", slave->ring_position);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1244
    }
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1245
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1246
    // check and reset CRC fault counters
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1247
    //ec_slave_check_crc(slave);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1248
    // TODO: Implement state machine for CRC checking.
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1249
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1250
    if (!slave->base_fmmu_count) { // skip FMMU configuration
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1251
        ec_fsm_slaveconf_enter_sync(fsm);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1252
        return;
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1253
    }
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1254
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1255
    if (master->debug_level)
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1256
        EC_DBG("Clearing FMMU configurations of slave %i...\n",
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1257
               slave->ring_position);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1258
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1259
    // clear FMMU configurations
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1260
    ec_datagram_npwr(datagram, slave->station_address,
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1261
                     0x0600, EC_FMMU_SIZE * slave->base_fmmu_count);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1262
    memset(datagram->data, 0x00, EC_FMMU_SIZE * slave->base_fmmu_count);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1263
    ec_master_queue_datagram(master, datagram);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1264
    fsm->slave_state = ec_fsm_slaveconf_state_clear_fmmus;
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1265
}
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1266
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1267
/*****************************************************************************/
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1268
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1269
/**
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1270
   Slave configuration state: CLEAR FMMU.
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1271
*/
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1272
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1273
void ec_fsm_slaveconf_state_clear_fmmus(ec_fsm_t *fsm
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1274
                                        /**< finite state machine */)
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1275
{
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1276
    ec_datagram_t *datagram = &fsm->datagram;
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1277
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1278
    if (datagram->state != EC_DATAGRAM_RECEIVED
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1279
        || datagram->working_counter != 1) {
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1280
        fsm->slave->error_flag = 1;
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1281
        fsm->slave_state = ec_fsm_slave_state_error;
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1282
        EC_ERR("Failed to clear FMMUs on slave %i.\n",
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1283
               fsm->slave->ring_position);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1284
        return;
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1285
    }
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1286
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1287
    ec_fsm_slaveconf_enter_sync(fsm);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1288
}
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1289
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1290
/*****************************************************************************/
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1291
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1292
/**
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1293
*/
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1294
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1295
void ec_fsm_slaveconf_enter_sync(ec_fsm_t *fsm /**< finite state machine */)
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1296
{
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1297
    ec_master_t *master = fsm->master;
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1298
    ec_slave_t *slave = fsm->slave;
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1299
    ec_datagram_t *datagram = &fsm->datagram;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1300
    const ec_sii_sync_t *sync;
420
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1301
    ec_sii_sync_t mbox_sync;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1302
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1303
    // slave is now in INIT
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1304
    if (slave->current_state == slave->requested_state) {
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1305
        fsm->slave_state = ec_fsm_slave_state_end; // successful
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1306
        if (master->debug_level) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1307
            EC_DBG("Finished configuration of slave %i.\n",
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1308
                   slave->ring_position);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1309
        }
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1310
        return;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1311
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1312
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1313
    if (!slave->base_sync_count) { // no sync managers
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1314
        ec_fsm_slaveconf_enter_preop(fsm);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1315
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1316
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1317
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1318
    if (master->debug_level) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1319
        EC_DBG("Configuring sync managers of slave %i.\n",
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1320
               slave->ring_position);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1321
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1322
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1323
    // configure sync managers
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1324
    ec_datagram_npwr(datagram, slave->station_address, 0x0800,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1325
                     EC_SYNC_SIZE * slave->base_sync_count);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1326
    memset(datagram->data, 0x00, EC_SYNC_SIZE * slave->base_sync_count);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1327
420
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1328
    if (list_empty(&slave->sii_syncs)) {
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1329
        if (slave->sii_rx_mailbox_offset && slave->sii_tx_mailbox_offset) {
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1330
            if (slave->master->debug_level)
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1331
                EC_DBG("Guessing sync manager settings for slave %i.\n",
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1332
                       slave->ring_position);
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1333
            mbox_sync.index = 0;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1334
            mbox_sync.physical_start_address = slave->sii_tx_mailbox_offset;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1335
            mbox_sync.length = slave->sii_tx_mailbox_size;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1336
            mbox_sync.control_register = 0x26;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1337
            mbox_sync.enable = 0x01;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1338
            mbox_sync.est_length = 0;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1339
            ec_sync_config(&mbox_sync, slave,
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1340
                           datagram->data + EC_SYNC_SIZE * mbox_sync.index);
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1341
            mbox_sync.index = 1;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1342
            mbox_sync.physical_start_address = slave->sii_rx_mailbox_offset;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1343
            mbox_sync.length = slave->sii_rx_mailbox_size;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1344
            mbox_sync.control_register = 0x22;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1345
            mbox_sync.enable = 0x01;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1346
            mbox_sync.est_length = 0;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1347
            ec_sync_config(&mbox_sync, slave,
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1348
                           datagram->data + EC_SYNC_SIZE * mbox_sync.index);
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1349
        }
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1350
    }
478
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1351
    else if (slave->sii_mailbox_protocols) { // mailboxes present
420
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1352
        list_for_each_entry(sync, &slave->sii_syncs, list) {
478
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1353
            // only configure mailbox sync-managers
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1354
            if (sync->index != 0 && sync->index != 1) continue;
420
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1355
            ec_sync_config(sync, slave,
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1356
                           datagram->data + EC_SYNC_SIZE * sync->index);
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1357
        }
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1358
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1359
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1360
    ec_master_queue_datagram(fsm->master, datagram);
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1361
    fsm->slave_state = ec_fsm_slaveconf_state_sync;
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1362
}
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1363
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1364
/*****************************************************************************/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1365
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1366
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1367
   Slave configuration state: SYNC.
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1368
*/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1369
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1370
void ec_fsm_slaveconf_state_sync(ec_fsm_t *fsm /**< finite state machine */)
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1371
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1372
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1373
    ec_slave_t *slave = fsm->slave;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1374
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1375
    if (datagram->state != EC_DATAGRAM_RECEIVED
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1376
        || datagram->working_counter != 1) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1377
        slave->error_flag = 1;
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1378
        fsm->slave_state = ec_fsm_slave_state_error;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
  1379
        EC_ERR("Failed to set sync managers on slave %i.\n",
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1380
               slave->ring_position);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1381
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1382
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1383
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1384
    ec_fsm_slaveconf_enter_preop(fsm);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1385
}
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1386
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1387
/*****************************************************************************/
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1388
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1389
/**
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1390
 */
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1391
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1392
void ec_fsm_slaveconf_enter_preop(ec_fsm_t *fsm /**< finite state machine */)
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1393
{
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1394
    fsm->slave_state = ec_fsm_slaveconf_state_preop;
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1395
    ec_fsm_change_start(&fsm->fsm_change, fsm->slave, EC_SLAVE_STATE_PREOP);
434
0180d8277311 Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
  1396
    ec_fsm_change_exec(&fsm->fsm_change); // execute immediately
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1397
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1398
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1399
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1400
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1401
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1402
   Slave configuration state: PREOP.
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1403
*/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1404
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1405
void ec_fsm_slaveconf_state_preop(ec_fsm_t *fsm /**< finite state machine */)
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1406
{
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1407
    ec_slave_t *slave = fsm->slave;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1408
    ec_master_t *master = fsm->master;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1409
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
  1410
    if (ec_fsm_change_exec(&fsm->fsm_change)) return;
434
0180d8277311 Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
  1411
0180d8277311 Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
  1412
    if (!ec_fsm_change_success(&fsm->fsm_change)) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1413
        slave->error_flag = 1;
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1414
        fsm->slave_state = ec_fsm_slave_state_error;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1415
        return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1416
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1417
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1418
    // slave is now in PREOP
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1419
    slave->jiffies_preop = fsm->datagram.jiffies_received;
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1420
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1421
    if (master->debug_level) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1422
        EC_DBG("Slave %i is now in PREOP.\n", slave->ring_position);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1423
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1424
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1425
    if (slave->current_state == slave->requested_state) {
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1426
        fsm->slave_state = ec_fsm_slave_state_end; // successful
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1427
        if (master->debug_level) {
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1428
            EC_DBG("Finished configuration of slave %i.\n",
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1429
                   slave->ring_position);
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1430
        }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1431
        return;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1432
    }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1433
478
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1434
    ec_fsm_slaveconf_enter_sync2(fsm);
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1435
}
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1436
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1437
/*****************************************************************************/
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1438
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1439
/**
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1440
*/
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1441
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1442
void ec_fsm_slaveconf_enter_sync2(ec_fsm_t *fsm /**< finite state machine */)
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1443
{
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1444
    ec_slave_t *slave = fsm->slave;
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1445
    ec_datagram_t *datagram = &fsm->datagram;
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1446
    ec_sii_sync_t *sync;
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1447
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1448
    if (list_empty(&slave->sii_syncs)) {
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1449
        ec_fsm_slaveconf_enter_fmmu(fsm);
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1450
        return;
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1451
    }
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1452
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1453
    // configure sync managers for process data
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1454
    ec_datagram_npwr(datagram, slave->station_address, 0x0800,
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1455
                     EC_SYNC_SIZE * slave->base_sync_count);
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1456
    memset(datagram->data, 0x00, EC_SYNC_SIZE * slave->base_sync_count);
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1457
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1458
    list_for_each_entry(sync, &slave->sii_syncs, list) {
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1459
        ec_sync_config(sync, slave,
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1460
                       datagram->data + EC_SYNC_SIZE * sync->index);
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1461
    }
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1462
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1463
    ec_master_queue_datagram(fsm->master, datagram);
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1464
    fsm->slave_state = ec_fsm_slaveconf_state_sync2;
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1465
}
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1466
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1467
/*****************************************************************************/
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1468
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1469
/**
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1470
   Slave configuration state: SYNC2.
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1471
*/
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1472
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1473
void ec_fsm_slaveconf_state_sync2(ec_fsm_t *fsm /**< finite state machine */)
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1474
{
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1475
    ec_datagram_t *datagram = &fsm->datagram;
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1476
    ec_slave_t *slave = fsm->slave;
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1477
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1478
    if (datagram->state != EC_DATAGRAM_RECEIVED
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1479
        || datagram->working_counter != 1) {
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1480
        slave->error_flag = 1;
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1481
        fsm->slave_state = ec_fsm_slave_state_error;
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1482
        EC_ERR("Failed to set process data sync managers on slave %i.\n",
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1483
               slave->ring_position);
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1484
        return;
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1485
    }
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1486
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1487
    ec_fsm_slaveconf_enter_fmmu(fsm);
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1488
}
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1489
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1490
/*****************************************************************************/
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1491
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1492
/**
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1493
*/
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1494
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1495
void ec_fsm_slaveconf_enter_fmmu(ec_fsm_t *fsm /**< finite state machine */)
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1496
{
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1497
    ec_slave_t *slave = fsm->slave;
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1498
    ec_master_t *master = slave->master;
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1499
    ec_datagram_t *datagram = &fsm->datagram;
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1500
    unsigned int j;
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1501
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1502
    if (!slave->base_fmmu_count) { // skip FMMU configuration
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1503
        ec_fsm_slaveconf_enter_sdoconf(fsm);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1504
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1505
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1506
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1507
    // configure FMMUs
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1508
    ec_datagram_npwr(datagram, slave->station_address,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1509
                     0x0600, EC_FMMU_SIZE * slave->base_fmmu_count);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1510
    memset(datagram->data, 0x00, EC_FMMU_SIZE * slave->base_fmmu_count);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1511
    for (j = 0; j < slave->fmmu_count; j++) {
275
ba51285d4ef6 Variable-sized data fields, BK1120.
Florian Pose <fp@igh-essen.com>
parents: 269
diff changeset
  1512
        ec_fmmu_config(&slave->fmmus[j], slave,
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1513
                       datagram->data + EC_FMMU_SIZE * j);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1514
    }
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1515
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1516
    ec_master_queue_datagram(master, datagram);
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1517
    fsm->slave_state = ec_fsm_slaveconf_state_fmmu;
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1518
}
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1519
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1520
/*****************************************************************************/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1521
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1522
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1523
   Slave configuration state: FMMU.
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1524
*/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1525
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1526
void ec_fsm_slaveconf_state_fmmu(ec_fsm_t *fsm /**< finite state machine */)
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1527
{
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1528
    ec_datagram_t *datagram = &fsm->datagram;
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1529
    ec_slave_t *slave = fsm->slave;
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1530
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1531
    if (datagram->state != EC_DATAGRAM_RECEIVED
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1532
        || datagram->working_counter != 1) {
291
0b1f877cf3f1 Slave: state_error -> error_flag, error_flag only in slave state machine.
Florian Pose <fp@igh-essen.com>
parents: 290
diff changeset
  1533
        fsm->slave->error_flag = 1;
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1534
        fsm->slave_state = ec_fsm_slave_state_error;
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1535
        EC_ERR("Failed to set FMMUs on slave %i.\n",
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1536
               fsm->slave->ring_position);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1537
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1538
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1539
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1540
    // No CoE configuration to be applied? Jump to SAVEOP state.
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1541
    if (list_empty(&slave->sdo_confs)) { // skip SDO configuration
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1542
        ec_fsm_slaveconf_enter_saveop(fsm);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1543
        return;
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1544
    }
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1545
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1546
    ec_fsm_slaveconf_enter_sdoconf(fsm);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1547
}
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1548
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1549
/*****************************************************************************/
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1550
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1551
/**
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1552
 */
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1553
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1554
void ec_fsm_slaveconf_enter_sdoconf(ec_fsm_t *fsm /**< finite state machine */)
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1555
{
478
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1556
    ec_slave_t *slave = fsm->slave;
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1557
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1558
    if (list_empty(&slave->sdo_confs)) { // skip SDO configuration
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1559
        ec_fsm_slaveconf_enter_saveop(fsm);
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1560
        return;
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1561
    }
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1562
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1563
    // start SDO configuration
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1564
    fsm->slave_state = ec_fsm_slaveconf_state_sdoconf;
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1565
    fsm->sdodata = list_entry(fsm->slave->sdo_confs.next, ec_sdo_data_t, list);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1566
    ec_fsm_coe_download(&fsm->fsm_coe, fsm->slave, fsm->sdodata);
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1567
    ec_fsm_coe_exec(&fsm->fsm_coe); // execute immediately
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1568
}
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1569
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1570
/*****************************************************************************/
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1571
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1572
/**
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1573
   Slave configuration state: SDOCONF.
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1574
*/
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1575
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1576
void ec_fsm_slaveconf_state_sdoconf(ec_fsm_t *fsm /**< finite state machine */)
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1577
{
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1578
    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
  1579
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1580
    if (!ec_fsm_coe_success(&fsm->fsm_coe)) {
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1581
        fsm->slave->error_flag = 1;
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1582
        fsm->slave_state = ec_fsm_slave_state_error;
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1583
        return;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1584
    }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1585
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1586
    // Another SDO to configure?
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1587
    if (fsm->sdodata->list.next != &fsm->slave->sdo_confs) {
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1588
        fsm->sdodata = list_entry(fsm->sdodata->list.next,
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1589
                                  ec_sdo_data_t, list);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1590
        ec_fsm_coe_download(&fsm->fsm_coe, fsm->slave, fsm->sdodata);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1591
        ec_fsm_coe_exec(&fsm->fsm_coe); // execute immediately
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1592
        return;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1593
    }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1594
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1595
    // All SDOs are now configured.
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1596
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1597
    // set state to SAVEOP
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1598
    ec_fsm_slaveconf_enter_saveop(fsm);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1599
}
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1600
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1601
/*****************************************************************************/
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1602
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1603
/**
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1604
 */
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1605
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1606
void ec_fsm_slaveconf_enter_saveop(ec_fsm_t *fsm /**< finite state machine */)
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1607
{
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1608
    fsm->slave_state = ec_fsm_slaveconf_state_saveop;
454
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
  1609
    ec_fsm_change_start(&fsm->fsm_change, fsm->slave, EC_SLAVE_STATE_SAVEOP);
434
0180d8277311 Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
  1610
    ec_fsm_change_exec(&fsm->fsm_change); // execute immediately
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1611
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1612
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1613
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1614
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1615
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1616
   Slave configuration state: SAVEOP.
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1617
*/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1618
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1619
void ec_fsm_slaveconf_state_saveop(ec_fsm_t *fsm /**< finite state machine */)
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1620
{
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1621
    ec_master_t *master = fsm->master;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1622
    ec_slave_t *slave = fsm->slave;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1623
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
  1624
    if (ec_fsm_change_exec(&fsm->fsm_change)) return;
434
0180d8277311 Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
  1625
0180d8277311 Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
  1626
    if (!ec_fsm_change_success(&fsm->fsm_change)) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1627
        fsm->slave->error_flag = 1;
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1628
        fsm->slave_state = ec_fsm_slave_state_error;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1629
        return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1630
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1631
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1632
    // slave is now in SAVEOP
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1633
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1634
    if (master->debug_level) {
411
42d239bab6ae Fixed typo.
Florian Pose <fp@igh-essen.com>
parents: 409
diff changeset
  1635
        EC_DBG("Slave %i is now in SAVEOP.\n", slave->ring_position);
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1636
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1637
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1638
    if (fsm->slave->current_state == fsm->slave->requested_state) {
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1639
        fsm->slave_state = ec_fsm_slave_state_end; // successful
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1640
        if (master->debug_level) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1641
            EC_DBG("Finished configuration of slave %i.\n",
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1642
                   slave->ring_position);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1643
        }
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1644
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1645
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1646
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1647
    // set state to OP
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1648
    fsm->slave_state = ec_fsm_slaveconf_state_op;
454
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
  1649
    ec_fsm_change_start(&fsm->fsm_change, slave, EC_SLAVE_STATE_OP);
434
0180d8277311 Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
  1650
    ec_fsm_change_exec(&fsm->fsm_change); // execute immediately
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1651
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1652
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1653
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1654
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1655
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1656
   Slave configuration state: OP
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1657
*/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1658
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1659
void ec_fsm_slaveconf_state_op(ec_fsm_t *fsm /**< finite state machine */)
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1660
{
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1661
    ec_master_t *master = fsm->master;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1662
    ec_slave_t *slave = fsm->slave;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1663
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
  1664
    if (ec_fsm_change_exec(&fsm->fsm_change)) return;
434
0180d8277311 Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
  1665
0180d8277311 Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
  1666
    if (!ec_fsm_change_success(&fsm->fsm_change)) {
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1667
        slave->error_flag = 1;
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1668
        fsm->slave_state = ec_fsm_slave_state_error;
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1669
        return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1670
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1671
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1672
    // slave is now in OP
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1673
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1674
    if (master->debug_level) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1675
        EC_DBG("Slave %i is now in OP.\n", slave->ring_position);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1676
        EC_DBG("Finished configuration of slave %i.\n", slave->ring_position);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1677
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1678
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1679
    fsm->slave_state = ec_fsm_slave_state_end; // successful
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1680
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1681
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1682
/******************************************************************************
329
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  1683
 *  Common state functions
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  1684
 *****************************************************************************/
286
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1685
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1686
/**
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1687
   State: ERROR.
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1688
*/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1689
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1690
void ec_fsm_slave_state_error(ec_fsm_t *fsm /**< finite state machine */)
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1691
{
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1692
}
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1693
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1694
/*****************************************************************************/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1695
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1696
/**
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1697
   State: END.
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1698
*/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1699
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1700
void ec_fsm_slave_state_end(ec_fsm_t *fsm /**< finite state machine */)
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1701
{
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1702
}
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1703
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1704
/*****************************************************************************/