master/fsm.c
author Florian Pose <fp@igh-essen.com>
Mon, 01 Jan 2007 14:58:55 +0000
changeset 506 ca528bb97448
parent 505 bc443ca0077f
child 520 d778acff9592
permissions -rw-r--r--
Made it possible to configure under kernel 2.6.18.
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.
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   142
   If the state machine's datagram is not sent or received yet, the execution
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   143
   of the state machine is delayed to the next cycle.
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
   144
   \return false, if state machine has terminated
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
   145
*/
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
   146
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
   147
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
   148
{
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   149
    if (fsm->datagram.state == EC_DATAGRAM_SENT
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   150
        || fsm->datagram.state == EC_DATAGRAM_QUEUED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   151
        // datagram was not sent or received yet.
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   152
        return ec_fsm_running(fsm);
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   153
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   154
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
    fsm->master_state(fsm);
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
   156
    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
   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
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
/*****************************************************************************/
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
   160
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
   161
/**
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
   162
   \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
   163
*/
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
   164
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
   165
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
   166
{
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   167
    return fsm->master_state != ec_fsm_master_end
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   168
        && fsm->master_state != ec_fsm_master_error;
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
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
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   173
/**
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   174
   \return true, if the master state machine terminated gracefully
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   175
*/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   176
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   177
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
   178
{
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   179
    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
   180
}
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   181
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
/******************************************************************************
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   183
 *  operation/idle state machine
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
 *****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
/**
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   187
   Master state: START.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
   Starts with getting slave count and slave states.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
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
   192
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   193
    ec_datagram_brd(&fsm->datagram, 0x0130, 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   194
    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
   195
    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
   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
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   199
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   200
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   201
   Master state: BROADCAST.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   202
   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
   203
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   204
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   205
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
   206
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   207
    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
   208
    unsigned int topology_change, states_change, i;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
    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
   210
    ec_master_t *master = fsm->master;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   212
    if (datagram->state == EC_DATAGRAM_TIMED_OUT) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   213
        // always retry
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   214
        ec_master_queue_datagram(fsm->master, &fsm->datagram);
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   215
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   216
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   217
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   218
    if (datagram->state != EC_DATAGRAM_RECEIVED) { // EC_DATAGRAM_ERROR
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   219
        // link is down
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   220
        fsm->master_slaves_responding = 0;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   221
        list_for_each_entry(slave, &master->slaves, list) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   222
            slave->online = 0;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   223
        }
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   224
        fsm->master_state = ec_fsm_master_error;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   228
    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
   229
                       fsm->master_slaves_responding);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   230
    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
   231
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   232
    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
   233
    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
   234
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   235
    if (topology_change) {
262
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   236
        EC_INFO("%i slave%s responding.\n",
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   237
                fsm->master_slaves_responding,
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   238
                fsm->master_slaves_responding == 1 ? "" : "s");
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   239
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   240
        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
   241
            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
   242
                fsm->master_validation = 1; // start validation later
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   243
            }
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   244
            else {
636d43737371 Corrected output at slave count change.
Florian Pose <fp@igh-essen.com>
parents: 260
diff changeset
   245
                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
   246
            }
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   247
        }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   248
    }
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
    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
   251
        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
   252
        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
   253
        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
   254
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   255
306
45886de3db87 Renamed FREERUN mode to IDLE mode.
Florian Pose <fp@igh-essen.com>
parents: 304
diff changeset
   256
    // 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
   257
    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
   258
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   259
        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
   260
        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
   261
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   262
        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
   263
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   264
        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
   265
            // no slaves present -> finish state machine.
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   266
            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
   267
            return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   268
        }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   269
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   270
        // init slaves
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   271
        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
   272
            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
   273
                                                 GFP_ATOMIC))) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   274
                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
   275
                ec_master_destroy_slaves(master);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   276
                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
   277
                return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   278
            }
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
            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
   281
                // 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
   282
                ec_master_destroy_slaves(master);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   283
                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
   284
                return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   285
            }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   286
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   287
            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
   288
        }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   289
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   290
        EC_INFO("Scanning bus.\n");
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   291
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   292
        // begin scanning of slaves
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   293
        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
   294
        fsm->slave_state = ec_fsm_slavescan_start;
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   295
        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
   296
        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
   297
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   298
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   299
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   300
    // 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
   301
    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
   302
    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
   303
    ec_master_queue_datagram(master, &fsm->datagram);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   304
    fsm->retries = EC_FSM_RETRIES;
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   305
    fsm->master_state = ec_fsm_master_read_states;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   306
}
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
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   310
/**
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   311
   Master action: PROC_STATES.
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   312
   Processes the slave states.
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   313
*/
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   314
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   315
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
   316
                                         /**< finite state machine */
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   317
                                         )
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   318
{
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   319
    ec_master_t *master = fsm->master;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   320
    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
   321
    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
   322
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   323
    // 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
   324
    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
   325
        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
   326
            || !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
   327
            || 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
   328
            || (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
   329
                && 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
   330
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   331
        if (master->debug_level) {
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   332
            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
   333
            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
   334
                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
   335
                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
   336
                       slave->ring_position, old_state, new_state);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   337
            }
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
   338
            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
   339
                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
   340
                       slave->ring_position, old_state);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   341
            }
421
2b3ce4f51bd6 Reconfiguration of slaves, though they are in the correct state at startup.
Florian Pose <fp@igh-essen.com>
parents: 420
diff changeset
   342
        }
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   343
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
   344
        fsm->master_state = ec_fsm_master_configure_slave;
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   345
        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
   346
        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
   347
        fsm->slave_state(fsm); // execute immediately
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   348
        return;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   349
    }
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   350
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   351
    // 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
   352
    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
   353
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
   354
    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
   355
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
        // 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
   357
        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
   358
            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
   359
                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
   360
            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
   361
            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
   362
                || !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
   363
                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
   364
                       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
   365
                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
   366
                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
   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
            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
   369
                // 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
   370
                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
   371
                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
   372
                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
   373
                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
   374
                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
   375
                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
   376
            }
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
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
        // 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
   380
        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
   381
            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
   382
                || 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
   383
                || 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
   384
                || 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
   385
                || !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
   386
                || 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
   387
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
            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
   389
                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
   390
                       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
   391
            }
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
            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
   394
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   395
            // 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
   396
            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
   397
            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
   398
            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
   399
            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
   400
            return;
ffa13db95e10 SDO uploading via Sysfs without master FSM calling wake_up().
Florian Pose <fp@igh-essen.com>
parents: 437
diff changeset
   401
        }
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
   402
6607875255d9 SDO dictionary and SDO access only in IDLE mode, because of kmalloc()s.
Florian Pose <fp@igh-essen.com>
parents: 441
diff changeset
   403
        // check for pending EEPROM write operations.
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   404
        list_for_each_entry(slave, &master->slaves, list) {
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   405
            if (!slave->new_eeprom_data) continue;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   406
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   407
            if (!slave->online || slave->error_flag) {
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   408
                kfree(slave->new_eeprom_data);
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   409
                slave->new_eeprom_data = NULL;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   410
                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
   411
                       slave->ring_position);
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   412
                continue;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   413
            }
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
            // found pending EEPROM write operation. execute it!
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   416
            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
   417
            fsm->slave = slave;
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   418
            fsm->sii_offset = 0x0000;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   419
            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
   420
                             slave->new_eeprom_data, EC_FSM_SII_NODE);
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   421
            fsm->master_state = ec_fsm_master_write_eeprom;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   422
            fsm->master_state(fsm); // execute immediately
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   423
            return;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   424
        }
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   425
    }
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   426
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   427
    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
   428
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   429
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   430
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   431
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   432
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   433
   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
   434
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   435
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   436
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
   437
                                           /**< finite state machine */)
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   438
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   439
    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
   440
    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
   441
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   442
    // 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
   443
    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
   444
        // process next slave
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   445
        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
   446
        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
   447
                         0x0130, 2);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   448
        ec_master_queue_datagram(master, &fsm->datagram);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   449
        fsm->retries = EC_FSM_RETRIES;
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   450
        fsm->master_state = ec_fsm_master_read_states;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   451
        return;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   452
    }
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   453
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   454
    // all slave states read
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   455
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   456
    // 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
   457
    if (fsm->master_validation) {
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   458
        fsm->master_validation = 0;
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   459
        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
   460
            if (slave->online) continue;
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   461
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   462
            // 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
   463
            EC_INFO("Validating bus.\n");
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   464
            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
   465
            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
   466
            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
   467
            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
   468
            return;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   469
        }
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   470
    }
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   471
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   472
    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
   473
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   474
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   475
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   476
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   477
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   478
   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
   479
   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
   480
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   481
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   482
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
   483
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   484
    ec_slave_t *slave = fsm->slave;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   485
    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
   486
    uint8_t new_state;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   487
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   488
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   489
        ec_master_queue_datagram(fsm->master, &fsm->datagram);
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   490
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   491
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   492
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   493
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   494
        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
   495
               slave->ring_position);
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   496
        fsm->master_state = ec_fsm_master_error;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   497
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   498
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   499
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   500
    // 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
   501
    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
   502
        if (slave->online) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   503
            slave->online = 0;
461
b9eda9235173 Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 459
diff changeset
   504
            if (slave->master->debug_level)
459
f0da52cf6b5b Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 456
diff changeset
   505
                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
   506
        }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   507
        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
   508
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   509
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   510
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   511
    // slave responded
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   512
    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
   513
    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
   514
        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
   515
        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
   516
        slave->current_state = new_state;
461
b9eda9235173 Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 459
diff changeset
   517
        if (slave->master->debug_level) {
459
f0da52cf6b5b Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 456
diff changeset
   518
            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
   519
            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
   520
            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
   521
                   slave->ring_position, cur_state);
f0da52cf6b5b Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 456
diff changeset
   522
        }
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   523
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   524
    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
   525
        if (slave->master->debug_level) {
459
f0da52cf6b5b Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 456
diff changeset
   526
            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
   527
                cur_state[EC_STATE_STRING_SIZE];
f0da52cf6b5b Print certain logs only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 456
diff changeset
   528
            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
   529
            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
   530
            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
   531
                   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
   532
        }
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   533
        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
   534
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   535
454
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   536
    // 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
   537
    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
   538
        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
   539
        ec_fsm_change_exec(&fsm->fsm_change);
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   540
        fsm->master_state = ec_fsm_master_acknowledge;
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   541
        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
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   544
    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
   545
}
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   546
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   547
/*****************************************************************************/
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   548
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
   Master state: ACKNOWLEDGE
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   551
*/
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   552
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   553
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
   554
{
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   555
    ec_slave_t *slave = fsm->slave;
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   556
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   557
    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
   558
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   559
    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
   560
        fsm->slave->error_flag = 1;
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   561
        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
   562
               slave->ring_position);
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   563
        fsm->master_state = ec_fsm_master_error;
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   564
        return;
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   565
    }
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
   566
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   567
    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
   568
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   569
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   570
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   571
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   572
/**
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   573
   Master state: VALIDATE_VENDOR.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   574
   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
   575
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   576
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   577
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
   578
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   579
    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
   580
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
   581
    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
   582
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   583
    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
   584
        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
   585
        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
   586
               slave->ring_position);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   587
        fsm->master_state = ec_fsm_master_error;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   588
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   589
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   590
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   591
    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
   592
        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
   593
        fsm->master_state = ec_fsm_master_error;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   594
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   595
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   596
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   597
    // 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
   598
    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
   599
    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
   600
    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
   601
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   602
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   603
/*****************************************************************************/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   604
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   605
/**
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   606
   Master action: ADDRESS.
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   607
   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
   608
   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
   609
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   610
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   611
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
   612
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   613
    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
   614
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   615
    while (fsm->slave->online) {
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   616
        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
   617
            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
   618
            fsm->master_state(fsm); // execute immediately
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   619
            return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   620
        }
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   621
        // check next slave
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   622
        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
   623
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   624
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   625
    if (fsm->master->debug_level)
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   626
        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
   627
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   628
    // write station address
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   629
    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
   630
    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
   631
    ec_master_queue_datagram(fsm->master, datagram);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   632
    fsm->retries = EC_FSM_RETRIES;
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   633
    fsm->master_state = ec_fsm_master_rewrite_addresses;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   634
}
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   635
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   636
/*****************************************************************************/
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   637
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
   Master state: VALIDATE_PRODUCT.
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   640
   Validates the product ID of a slave.
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   641
*/
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   642
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   643
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
   644
{
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   645
    ec_slave_t *slave = fsm->slave;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   646
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
   647
    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
   648
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   649
    if (!ec_fsm_sii_success(&fsm->fsm_sii)) {
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   650
        fsm->slave->error_flag = 1;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   651
        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
   652
               slave->ring_position);
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   653
        fsm->master_state = ec_fsm_master_error;
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   654
        return;
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
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   657
    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
   658
        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
   659
        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
   660
               EC_READ_U32(fsm->fsm_sii.value));
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   661
        fsm->master_state = ec_fsm_master_error;
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   662
        return;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   663
    }
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   664
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   665
    // have all states been validated?
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   666
    if (slave->list.next == &fsm->master->slaves) {
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   667
        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
   668
        // start writing addresses to offline slaves
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   669
        ec_fsm_master_action_addresses(fsm);
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   670
        return;
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   671
    }
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   672
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   673
    // validate next slave
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   674
    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
   675
    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
   676
    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
   677
    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
   678
}
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   679
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   680
/*****************************************************************************/
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
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   683
   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
   684
   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
   685
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   686
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   687
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
   688
                                     /**< finite state machine */
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   689
                                     )
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   690
{
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   691
    ec_slave_t *slave = fsm->slave;
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   692
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   693
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   694
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   695
        ec_master_queue_datagram(fsm->master, &fsm->datagram);
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   696
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   697
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   698
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   699
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   700
        EC_ERR("Failed to receive address datagram for slave %i.\n",
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   701
               slave->ring_position);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   702
        fsm->master_state = ec_fsm_master_error;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   703
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   704
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   705
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   706
    if (datagram->working_counter != 1) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   707
        EC_ERR("Failed to write station address - slave %i did not respond.\n",
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   708
               slave->ring_position);
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   709
        fsm->master_state = ec_fsm_master_error;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   710
        return;
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   711
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   712
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   713
    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
   714
        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
   715
        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
   716
        return;
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   717
    }
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   718
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   719
    // check next slave
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   720
    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
   721
    // Write new station address to slave
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   722
    ec_fsm_master_action_addresses(fsm);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   723
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   724
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   725
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   726
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   727
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   728
   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
   729
   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
   730
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   731
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   732
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
   733
{
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   734
    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
   735
    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
   736
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   737
    fsm->slave_state(fsm); // execute slave state machine
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   738
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   739
    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
   740
        && 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
   741
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   742
    // another slave to fetch?
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   743
    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
   744
        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
   745
        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
   746
        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
   747
        return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   748
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   749
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   750
    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
   751
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   752
    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
   753
428
2731a2fcc18d Set initial state of all slaves to PREOP.
Florian Pose <fp@igh-essen.com>
parents: 427
diff changeset
   754
    // 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
   755
    // communication possible
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   756
    list_for_each_entry(slave, &master->slaves, list) {
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   757
        ec_slave_request_state(slave, EC_SLAVE_STATE_PREOP);
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   758
    }
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   759
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   760
    fsm->master_state = ec_fsm_master_end;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   761
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   762
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   763
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   764
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   765
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   766
   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
   767
   Starts configuring a slave.
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   768
*/
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   769
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   770
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
   771
                                   /**< finite state machine */
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   772
                                   )
260
5fe7df7f2433 Correct behaviour of master state machine in RT mode.
Florian Pose <fp@igh-essen.com>
parents: 259
diff changeset
   773
{
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   774
    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
   775
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
   776
    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
   777
        && 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
   778
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   779
    ec_fsm_master_action_process_states(fsm);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   780
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   781
269
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
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   784
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   785
   Master state: WRITE EEPROM.
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   786
*/
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   787
304
558a6669da90 Better master state machines.
Florian Pose <fp@igh-essen.com>
parents: 301
diff changeset
   788
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
   789
{
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   790
    ec_slave_t *slave = fsm->slave;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   791
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
   792
    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
   793
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   794
    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
   795
        fsm->slave->error_flag = 1;
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   796
        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
   797
               slave->ring_position);
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   798
        kfree(slave->new_eeprom_data);
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   799
        slave->new_eeprom_data = NULL;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   800
        fsm->master_state = ec_fsm_master_error;
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   801
        return;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   802
    }
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   803
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   804
    fsm->sii_offset++;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   805
    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
   806
        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
   807
                         slave->new_eeprom_data + fsm->sii_offset,
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   808
                         EC_FSM_SII_NODE);
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
   809
        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
   810
        return;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   811
    }
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   812
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   813
    // finished writing EEPROM
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   814
    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
   815
    kfree(slave->new_eeprom_data);
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   816
    slave->new_eeprom_data = NULL;
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   817
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
   818
    // 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
   819
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   820
    // 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
   821
    fsm->master_state = ec_fsm_master_start;
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   822
    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
   823
}
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   824
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   825
/*****************************************************************************/
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   826
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   827
/**
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   828
   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
   829
*/
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   830
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   831
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
   832
{
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   833
    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
   834
    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
   835
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   836
    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
   837
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   838
    if (!ec_fsm_coe_success(&fsm->fsm_coe)) {
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   839
        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
   840
        return;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   841
    }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   842
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   843
    // 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
   844
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   845
    if (master->debug_level) {
423
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
   846
        unsigned int sdo_count, entry_count;
862ff892cf18 Better debugging output for SDO dictionaries.
Florian Pose <fp@igh-essen.com>
parents: 422
diff changeset
   847
        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
   848
        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
   849
               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
   850
    }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   851
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
   852
    // 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
   853
    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
   854
    fsm->master_state(fsm); // execute immediately
269
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   855
}
a03be9a6fed6 EEPROM writing via SysFS.
Florian Pose <fp@igh-essen.com>
parents: 266
diff changeset
   856
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   857
/*****************************************************************************/
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   858
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   859
/**
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   860
   Master state: SDO REQUEST.
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   861
*/
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   862
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   863
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
   864
{
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   865
    ec_master_t *master = fsm->master;
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   866
    ec_sdo_request_t *request = fsm->sdo_request;
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   867
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   868
    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
   869
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
   870
    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
   871
        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
   872
        master->sdo_seq_master++;
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   873
        fsm->master_state = ec_fsm_master_error;
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   874
        return;
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   875
    }
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   876
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   877
    // SDO dictionary fetching finished
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   878
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   879
    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
   880
    master->sdo_seq_master++;
430
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   881
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   882
    // restart master state machine.
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   883
    fsm->master_state = ec_fsm_master_start;
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   884
    fsm->master_state(fsm); // execute immediately
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   885
}
74754f45d5fa Implemented SDO reading via Sysfs.
Florian Pose <fp@igh-essen.com>
parents: 429
diff changeset
   886
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   887
/*****************************************************************************/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   888
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   889
/**
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   890
   State: ERROR.
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   891
*/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   892
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   893
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
   894
{
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   895
    fsm->master_state = ec_fsm_master_start;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   896
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   897
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   898
/*****************************************************************************/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   899
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   900
/**
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   901
   State: END.
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   902
*/
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   903
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   904
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
   905
{
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   906
    fsm->master_state = ec_fsm_master_start;
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   907
}
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 442
diff changeset
   908
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
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
 *  slave scan state machine
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   911
 *****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   912
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   913
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   914
   Slave scan state: START.
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   915
   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
   916
   slave, according to its ring position.
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   917
*/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   918
308
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
   919
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
   920
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   921
    ec_datagram_t *datagram = &fsm->datagram;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   922
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   923
    // write station address
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   924
    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
   925
    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
   926
    ec_master_queue_datagram(fsm->master, datagram);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   927
    fsm->retries = EC_FSM_RETRIES;
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   928
    fsm->slave_state = ec_fsm_slavescan_address;
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
/*****************************************************************************/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   932
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   933
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   934
   Slave scan state: ADDRESS.
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   935
*/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   936
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   937
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
   938
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   939
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   940
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   941
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   942
        ec_master_queue_datagram(fsm->master, &fsm->datagram);
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   943
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   944
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   945
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   946
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   947
        fsm->slave_state = ec_fsm_slave_state_error;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   948
        EC_ERR("Failed to receive station address datagram for slave %i.\n",
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   949
               fsm->slave->ring_position);
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   950
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   951
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   952
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   953
    if (datagram->working_counter != 1) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   954
        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
   955
        fsm->slave_state = ec_fsm_slave_state_error;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   956
        EC_ERR("Failed to write station address - slave %i did not respond.\n",
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   957
               fsm->slave->ring_position);
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   958
        return;
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   959
    }
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   960
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   961
    // Read AL state
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   962
    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
   963
    ec_master_queue_datagram(fsm->master, datagram);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   964
    fsm->retries = EC_FSM_RETRIES;
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   965
    fsm->slave_state = ec_fsm_slavescan_state;
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   966
}
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   967
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   968
/*****************************************************************************/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   969
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   970
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
   971
   Slave scan state: STATE.
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   972
*/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   973
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
   974
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
   975
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   976
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   977
    ec_slave_t *slave = fsm->slave;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   978
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   979
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   980
        ec_master_queue_datagram(fsm->master, datagram);
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   981
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   982
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   983
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   984
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   985
        fsm->slave_state = ec_fsm_slave_state_error;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   986
        EC_ERR("Failed to receive AL state datagram from slave %i.\n",
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   987
               fsm->slave->ring_position);
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   988
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   989
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   990
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   991
    if (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
   992
        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
   993
        fsm->slave_state = ec_fsm_slave_state_error;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
   994
        EC_ERR("Failed to read AL state - slave %i did not respond.\n",
255
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   995
               fsm->slave->ring_position);
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   996
        return;
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   997
    }
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
   998
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
   999
    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
  1000
    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
  1001
        char state_str[EC_STATE_STRING_SIZE];
25cc4a3b9e0a State acknowledgement in master state machine.
Florian Pose <fp@igh-essen.com>
parents: 448
diff changeset
  1002
        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
  1003
        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
  1004
                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
  1005
    }
6b916cce7f27 Read current AL status of slaves while scanning bus.
Florian Pose <fp@igh-essen.com>
parents: 254
diff changeset
  1006
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1007
    // read base data
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1008
    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
  1009
    ec_master_queue_datagram(fsm->master, datagram);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1010
    fsm->retries = EC_FSM_RETRIES;
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1011
    fsm->slave_state = ec_fsm_slavescan_base;
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1012
}
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1013
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1014
/*****************************************************************************/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1015
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1016
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1017
   Slave scan state: BASE.
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1018
*/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1019
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1020
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
  1021
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1022
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1023
    ec_slave_t *slave = fsm->slave;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1024
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1025
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1026
        ec_master_queue_datagram(fsm->master, datagram);
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1027
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1028
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1029
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1030
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1031
        fsm->slave_state = ec_fsm_slave_state_error;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1032
        EC_ERR("Failed to receive base data datagram for slave %i.\n",
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1033
               slave->ring_position);
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1034
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1035
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1036
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1037
    if (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
  1038
        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
  1039
        fsm->slave_state = ec_fsm_slave_state_error;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1040
        EC_ERR("Failed to read base data - slave %i did not respond.\n",
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1041
               slave->ring_position);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1042
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1043
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1044
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1045
    slave->base_type       = EC_READ_U8 (datagram->data);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1046
    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
  1047
    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
  1048
    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
  1049
    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
  1050
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1051
    if (slave->base_fmmu_count > EC_MAX_FMMUS)
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1052
        slave->base_fmmu_count = EC_MAX_FMMUS;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1053
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1054
    // read data link status
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1055
    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
  1056
    ec_master_queue_datagram(slave->master, datagram);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1057
    fsm->retries = EC_FSM_RETRIES;
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1058
    fsm->slave_state = ec_fsm_slavescan_datalink;
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1059
}
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1060
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1061
/*****************************************************************************/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1062
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1063
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1064
   Slave scan state: DATALINK.
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1065
*/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1066
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1067
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
  1068
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1069
    ec_datagram_t *datagram = &fsm->datagram;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1070
    ec_slave_t *slave = fsm->slave;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1071
    uint16_t dl_status;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1072
    unsigned int i;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1073
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1074
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1075
        ec_master_queue_datagram(fsm->master, datagram);
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1076
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1077
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1078
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1079
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1080
        fsm->slave_state = ec_fsm_slave_state_error;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1081
        EC_ERR("Failed to receive DL status datagram from slave %i.\n",
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1082
               slave->ring_position);
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1083
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1084
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1085
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1086
    if (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
  1087
        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
  1088
        fsm->slave_state = ec_fsm_slave_state_error;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1089
        EC_ERR("Failed to read DL status - slave %i did not respond.\n",
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1090
               slave->ring_position);
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1091
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1092
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1093
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1094
    dl_status = EC_READ_U16(datagram->data);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1095
    for (i = 0; i < 4; i++) {
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1096
        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
  1097
        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
  1098
        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
  1099
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1100
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1101
    // 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
  1102
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1103
    fsm->sii_offset = 0x0040; // first category header
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1104
    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
  1105
    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
  1106
    fsm->slave_state(fsm); // execute state immediately
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
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1109
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1110
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1111
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1112
   Slave scan state: EEPROM SIZE.
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1113
*/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1114
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1115
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
  1116
{
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1117
    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
  1118
    uint16_t cat_type, cat_size;
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1119
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
  1120
    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
  1121
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1122
    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
  1123
        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
  1124
        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
  1125
        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
  1126
               slave->ring_position);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1127
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1128
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1129
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1130
    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
  1131
    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
  1132
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1133
    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
  1134
        fsm->sii_offset += cat_size + 2;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1135
        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
  1136
                        EC_FSM_SII_NODE);
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1137
        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
  1138
        return;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1139
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1140
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1141
    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
  1142
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1143
    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
  1144
        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
  1145
                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
  1146
        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
  1147
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1148
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1149
    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
  1150
          (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
  1151
        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
  1152
        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
  1153
        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
  1154
               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
  1155
        return;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1156
    }
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
    // 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
  1159
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1160
    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
  1161
    fsm->sii_offset = 0x0000;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1162
    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
  1163
    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
  1164
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1165
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1166
/*****************************************************************************/
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1167
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1168
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1169
   Slave scan state: EEPROM DATA.
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1170
*/
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1171
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1172
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
  1173
{
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1174
    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
  1175
    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
  1176
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
  1177
    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
  1178
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1179
    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
  1180
        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
  1181
        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
  1182
        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
  1183
               slave->ring_position);
238
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1184
        return;
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1185
    }
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1186
266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1187
    // 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
  1188
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1189
    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
  1190
        memcpy(slave->eeprom_data + fsm->sii_offset * 2,
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1191
               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
  1192
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1193
    else { // copy the last word
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1194
        memcpy(slave->eeprom_data + fsm->sii_offset * 2,
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1195
               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
  1196
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1197
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1198
    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
  1199
        // 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
  1200
        fsm->sii_offset += 2;
433
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1201
        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
  1202
                        EC_FSM_SII_NODE);
100f51f28cf2 Layed out SII state machine.
Florian Pose <fp@igh-essen.com>
parents: 430
diff changeset
  1203
        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
  1204
        return;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1205
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1206
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1207
    // 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
  1208
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1209
    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
  1210
        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
  1211
    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
  1212
        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
  1213
    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
  1214
        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
  1215
    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
  1216
        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
  1217
    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
  1218
        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
  1219
    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
  1220
        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
  1221
    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
  1222
        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
  1223
    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
  1224
        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
  1225
    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
  1226
        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
  1227
    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
  1228
        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
  1229
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1230
    // 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
  1231
    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
  1232
    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
  1233
        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
  1234
        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
  1235
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1236
        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
  1237
            case 0x000A:
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1238
                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
  1239
                    goto end;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1240
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1241
            case 0x001E:
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1242
                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
  1243
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1244
            case 0x0028:
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1245
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1246
            case 0x0029:
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1247
                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
  1248
                                        cat_size))
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1249
                    goto end;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1250
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1251
            case 0x0032:
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1252
                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
  1253
                                       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
  1254
                    goto end;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1255
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1256
            case 0x0033:
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1257
                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
  1258
                                       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
  1259
                    goto end;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1260
                break;
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1261
            default:
461
b9eda9235173 Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 459
diff changeset
  1262
                if (fsm->master->debug_level)
b9eda9235173 Print certain warnings only at debug_level.
Florian Pose <fp@igh-essen.com>
parents: 459
diff changeset
  1263
                    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
  1264
                            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
  1265
        }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1266
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1267
        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
  1268
    }
0234b0c26c52 Read complete eeprom data from slave and map it into SysFS.
Florian Pose <fp@igh-essen.com>
parents: 262
diff changeset
  1269
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1270
    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
  1271
    return;
310
b7e7709fd40e Better slave scan sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 309
diff changeset
  1272
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1273
end:
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1274
    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
  1275
    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
  1276
    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
  1277
}
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
  1278
d50b139c8601 Separated slave scan sub state machine and slave configuration sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 306
diff changeset
  1279
/******************************************************************************
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1280
 *  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
  1281
 *****************************************************************************/
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1282
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1283
/**
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
  1284
   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
  1285
*/
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
  1286
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1287
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
  1288
{
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
  1289
    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
  1290
        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
  1291
    }
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
  1292
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
  1293
    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
  1294
    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
  1295
    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
  1296
}
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
  1297
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
  1298
/*****************************************************************************/
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
  1299
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
  1300
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1301
   Slave configuration state: INIT.
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1302
*/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1303
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1304
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
  1305
{
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1306
    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
  1307
    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
  1308
    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
  1309
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1310
    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
  1311
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1312
    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
  1313
        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
  1314
        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
  1315
        return;
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1316
    }
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1317
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1318
    slave->configured = 1;
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1319
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1320
    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
  1321
        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
  1322
    }
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1323
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1324
    // 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
  1325
    //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
  1326
    // 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
  1327
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1328
    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
  1329
        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
  1330
        return;
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1331
    }
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1332
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1333
    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
  1334
        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
  1335
               slave->ring_position);
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1336
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1337
    // clear FMMU configurations
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1338
    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
  1339
                     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
  1340
    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
  1341
    ec_master_queue_datagram(master, datagram);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1342
    fsm->retries = EC_FSM_RETRIES;
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1343
    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
  1344
}
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1345
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1346
/*****************************************************************************/
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1347
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1348
/**
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1349
   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
  1350
*/
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1351
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1352
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
  1353
                                        /**< finite state machine */)
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1354
{
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1355
    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
  1356
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1357
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1358
        ec_master_queue_datagram(fsm->master, datagram);
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1359
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1360
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1361
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1362
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1363
        fsm->slave_state = ec_fsm_slave_state_error;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1364
        EC_ERR("Failed receive FMMU clearing datagram for slave %i.\n",
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1365
               fsm->slave->ring_position);
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1366
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1367
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1368
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1369
    if (datagram->working_counter != 1) {
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1370
        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
  1371
        fsm->slave_state = ec_fsm_slave_state_error;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1372
        EC_ERR("Failed to clear FMMUs - slave %i did not respond.\n",
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1373
               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
  1374
        return;
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1375
    }
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1376
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1377
    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
  1378
}
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1379
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1380
/*****************************************************************************/
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1381
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1382
/**
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1383
*/
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1384
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1385
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
  1386
{
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1387
    ec_master_t *master = fsm->master;
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1388
    ec_slave_t *slave = fsm->slave;
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1389
    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
  1390
    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
  1391
    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
  1392
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1393
    // 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
  1394
    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
  1395
        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
  1396
        if (master->debug_level) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1397
            EC_DBG("Finished configuration of slave %i.\n",
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1398
                   slave->ring_position);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1399
        }
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1400
        return;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1401
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1402
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1403
    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
  1404
        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
  1405
        return;
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
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1408
    if (master->debug_level) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1409
        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
  1410
               slave->ring_position);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1411
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1412
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1413
    // configure sync managers
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1414
    ec_datagram_npwr(datagram, slave->station_address, 0x0800,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1415
                     EC_SYNC_SIZE * slave->base_sync_count);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1416
    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
  1417
420
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1418
    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
  1419
        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
  1420
            if (slave->master->debug_level)
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1421
                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
  1422
                       slave->ring_position);
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1423
            mbox_sync.index = 0;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1424
            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
  1425
            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
  1426
            mbox_sync.control_register = 0x26;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1427
            mbox_sync.enable = 0x01;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1428
            mbox_sync.est_length = 0;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1429
            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
  1430
                           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
  1431
            mbox_sync.index = 1;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1432
            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
  1433
            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
  1434
            mbox_sync.control_register = 0x22;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1435
            mbox_sync.enable = 0x01;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1436
            mbox_sync.est_length = 0;
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1437
            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
  1438
                           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
  1439
        }
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1440
    }
478
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1441
    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
  1442
        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
  1443
            // 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
  1444
            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
  1445
            ec_sync_config(sync, slave,
0ae52c37179b Guess sync manager settings if mailbox information available.
Florian Pose <fp@igh-essen.com>
parents: 419
diff changeset
  1446
                           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
  1447
        }
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1448
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1449
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1450
    ec_master_queue_datagram(fsm->master, datagram);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1451
    fsm->retries = EC_FSM_RETRIES;
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1452
    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
  1453
}
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1454
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1455
/*****************************************************************************/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1456
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1457
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1458
   Slave configuration state: SYNC.
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1459
*/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1460
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1461
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
  1462
{
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1463
    ec_datagram_t *datagram = &fsm->datagram;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1464
    ec_slave_t *slave = fsm->slave;
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1465
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1466
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1467
        ec_master_queue_datagram(fsm->master, datagram);
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1468
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1469
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1470
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1471
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1472
        fsm->slave_state = ec_fsm_slave_state_error;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1473
        EC_ERR("Failed to receive sync manager configuration datagram for"
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1474
               " slave %i.\n", slave->ring_position);
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1475
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1476
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1477
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1478
    if (datagram->working_counter != 1) {
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1479
        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
  1480
        fsm->slave_state = ec_fsm_slave_state_error;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1481
        EC_ERR("Failed to set sync managers - slave %i did not respond.\n",
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1482
               slave->ring_position);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1483
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1484
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1485
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1486
    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
  1487
}
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1488
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1489
/*****************************************************************************/
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1490
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1491
/**
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1492
 */
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1493
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1494
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
  1495
{
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1496
    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
  1497
    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
  1498
    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
  1499
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1500
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1501
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1502
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1503
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1504
   Slave configuration state: PREOP.
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1505
*/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1506
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1507
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
  1508
{
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1509
    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
  1510
    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
  1511
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
  1512
    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
  1513
0180d8277311 Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
  1514
    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
  1515
        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
  1516
        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
  1517
        return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1518
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1519
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1520
    // 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
  1521
    slave->jiffies_preop = fsm->datagram.jiffies_received;
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1522
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1523
    if (master->debug_level) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1524
        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
  1525
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1526
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1527
    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
  1528
        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
  1529
        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
  1530
            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
  1531
                   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
  1532
        }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1533
        return;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1534
    }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1535
478
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1536
    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
  1537
}
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1538
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1539
/*****************************************************************************/
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1540
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1541
/**
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1542
*/
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1543
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1544
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
  1545
{
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1546
    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
  1547
    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
  1548
    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
  1549
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1550
    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
  1551
        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
  1552
        return;
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1553
    }
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1554
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1555
    // 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
  1556
    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
  1557
                     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
  1558
    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
  1559
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1560
    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
  1561
        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
  1562
                       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
  1563
    }
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1564
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1565
    ec_master_queue_datagram(fsm->master, datagram);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1566
    fsm->retries = EC_FSM_RETRIES;
478
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1567
    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
  1568
}
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1569
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1570
/*****************************************************************************/
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1571
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1572
/**
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1573
   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
  1574
*/
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1575
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1576
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
  1577
{
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1578
    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
  1579
    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
  1580
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1581
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1582
        ec_master_queue_datagram(fsm->master, datagram);
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1583
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1584
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1585
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1586
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1587
        fsm->slave_state = ec_fsm_slave_state_error;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1588
        EC_ERR("Failed to receive process data sync manager configuration"
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1589
               " datagram for slave %i.\n",
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1590
               slave->ring_position);
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1591
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1592
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1593
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1594
    if (datagram->working_counter != 1) {
478
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1595
        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
  1596
        fsm->slave_state = ec_fsm_slave_state_error;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1597
        EC_ERR("Failed to set process data sync managers - slave %i did not"
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1598
               " respond.\n", slave->ring_position);
478
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1599
        return;
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1600
    }
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1601
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1602
    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
  1603
}
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1604
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1605
/*****************************************************************************/
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1606
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1607
/**
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1608
*/
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1609
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1610
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
  1611
{
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1612
    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
  1613
    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
  1614
    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
  1615
    unsigned int j;
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1616
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1617
    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
  1618
        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
  1619
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1620
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1621
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1622
    // configure FMMUs
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1623
    ec_datagram_npwr(datagram, slave->station_address,
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1624
                     0x0600, EC_FMMU_SIZE * slave->base_fmmu_count);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1625
    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
  1626
    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
  1627
        ec_fmmu_config(&slave->fmmus[j], slave,
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1628
                       datagram->data + EC_FMMU_SIZE * j);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1629
    }
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1630
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 292
diff changeset
  1631
    ec_master_queue_datagram(master, datagram);
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1632
    fsm->retries = EC_FSM_RETRIES;
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1633
    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
  1634
}
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1635
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1636
/*****************************************************************************/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1637
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1638
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1639
   Slave configuration state: FMMU.
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1640
*/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1641
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1642
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
  1643
{
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1644
    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
  1645
    ec_slave_t *slave = fsm->slave;
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1646
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1647
    if (datagram->state == EC_DATAGRAM_TIMED_OUT && fsm->retries--) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1648
        ec_master_queue_datagram(fsm->master, datagram);
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1649
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1650
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1651
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1652
    if (datagram->state != EC_DATAGRAM_RECEIVED) {
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1653
        fsm->slave_state = ec_fsm_slave_state_error;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1654
        EC_ERR("Failed to receive FMMUs datagram for slave %i.\n",
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1655
               fsm->slave->ring_position);
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1656
        return;
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1657
    }
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1658
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1659
    if (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
  1660
        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
  1661
        fsm->slave_state = ec_fsm_slave_state_error;
505
bc443ca0077f State machines re-send datagrams on timeout.
Florian Pose <fp@igh-essen.com>
parents: 484
diff changeset
  1662
        EC_ERR("Failed to set FMMUs - slave %i did not respond.\n",
292
2cf6ae0a2419 Minor changes in fsm.c and slave.c
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
  1663
               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
  1664
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1665
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1666
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1667
    // 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
  1668
    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
  1669
        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
  1670
        return;
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1671
    }
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1672
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1673
    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
  1674
}
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1675
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1676
/*****************************************************************************/
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1677
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1678
/**
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1679
 */
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1680
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1681
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
  1682
{
478
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1683
    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
  1684
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1685
    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
  1686
        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
  1687
        return;
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1688
    }
322fab6b085b Fix: Configuration of process data sync managers now in PREOP.
Florian Pose <fp@igh-essen.com>
parents: 475
diff changeset
  1689
419
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1690
    // 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
  1691
    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
  1692
    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
  1693
    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
  1694
    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
  1695
}
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1696
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1697
/*****************************************************************************/
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1698
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1699
/**
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1700
   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
  1701
*/
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1702
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1703
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
  1704
{
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1705
    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
  1706
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1707
    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
  1708
        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
  1709
        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
  1710
        return;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1711
    }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1712
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1713
    // Another SDO to configure?
436
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1714
    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
  1715
        fsm->sdodata = list_entry(fsm->sdodata->list.next,
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1716
                                  ec_sdo_data_t, list);
63214beb641d Layed out CoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 435
diff changeset
  1717
        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
  1718
        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
  1719
        return;
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1720
    }
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1721
cf724fc82a00 Moved SDO dictionary fetching to master FSMs; added SDO parent kobj.
Florian Pose <fp@igh-essen.com>
parents: 411
diff changeset
  1722
    // 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
  1723
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1724
    // 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
  1725
    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
  1726
}
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1727
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1728
/*****************************************************************************/
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1729
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1730
/**
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1731
 */
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1732
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1733
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
  1734
{
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1735
    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
  1736
    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
  1737
    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
  1738
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1739
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1740
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1741
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1742
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1743
   Slave configuration state: SAVEOP.
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1744
*/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1745
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1746
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
  1747
{
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1748
    ec_master_t *master = fsm->master;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1749
    ec_slave_t *slave = fsm->slave;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1750
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
  1751
    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
  1752
0180d8277311 Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
  1753
    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
  1754
        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
  1755
        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
  1756
        return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1757
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1758
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1759
    // slave is now in SAVEOP
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1760
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1761
    if (master->debug_level) {
411
42d239bab6ae Fixed typo.
Florian Pose <fp@igh-essen.com>
parents: 409
diff changeset
  1762
        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
  1763
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1764
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1765
    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
  1766
        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
  1767
        if (master->debug_level) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1768
            EC_DBG("Finished configuration of slave %i.\n",
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1769
                   slave->ring_position);
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1770
        }
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1771
        return;
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1772
    }
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1773
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1774
    // 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
  1775
    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
  1776
    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
  1777
    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
  1778
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1779
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1780
/*****************************************************************************/
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1781
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1782
/**
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1783
   Slave configuration state: OP
309
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1784
*/
42e69cf31495 Better slaveconf sub state machine.
Florian Pose <fp@igh-essen.com>
parents: 308
diff changeset
  1785
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1786
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
  1787
{
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1788
    ec_master_t *master = fsm->master;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1789
    ec_slave_t *slave = fsm->slave;
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1790
435
779a18d12e6c Removed state machine running() methods.
Florian Pose <fp@igh-essen.com>
parents: 434
diff changeset
  1791
    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
  1792
0180d8277311 Layed out state change state machine.
Florian Pose <fp@igh-essen.com>
parents: 433
diff changeset
  1793
    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
  1794
        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
  1795
        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
  1796
        return;
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1797
    }
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1798
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
  1799
    // slave is now in OP
409
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1800
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1801
    if (master->debug_level) {
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1802
        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
  1803
        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
  1804
    }
bc4c852e1b93 Implemented fetching of SDO dictionary.
Florian Pose <fp@igh-essen.com>
parents: 407
diff changeset
  1805
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1806
    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
  1807
}
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1808
b4960499098f Added finite state machine (FSM) processing.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1809
/******************************************************************************
329
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  1810
 *  Common state functions
d004349777fc SDO configuration interface, SDO download state machine.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
  1811
 *****************************************************************************/
286
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1812
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 275
diff changeset
  1813
/**
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1814
   State: ERROR.
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1815
*/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1816
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1817
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
  1818
{
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1819
}
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1820
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1821
/*****************************************************************************/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1822
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1823
/**
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1824
   State: END.
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1825
*/
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 312
diff changeset
  1826
462
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1827
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
  1828
{
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1829
}
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1830
e6fac0c8bc92 New state in slaveconf FSM: Clear FMMU configurations after INIT.
Florian Pose <fp@igh-essen.com>
parents: 461
diff changeset
  1831
/*****************************************************************************/