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